xref: /petsc/src/sys/objects/aoptions.c (revision d52bd9f3ee665b897a5f0dc75d2f9f8201159d66) !
1 
2 /*
3    Implements the higher-level options database querying methods. These are self-documenting and can attach at runtime to
4    GUI code to display the options and get values from the users.
5 
6 */
7 
8 #include <petscsys.h>        /*I  "petscsys.h"   I*/
9 #if defined(PETSC_HAVE_STDLIB_H)
10 #include <stdlib.h>
11 #endif
12 
13 #define ManSection(str) ((str)?(str):"None")
14 
15 /*
16     Keep a linked list of options that have been posted and we are waiting for
17    user selection. See the manual page for PetscOptionsBegin()
18 
19     Eventually we'll attach this beast to a MPI_Comm
20 */
21 PetscOptionsObjectType PetscOptionsObject;
22 PetscInt               PetscOptionsPublishCount = 0;
23 
24 #undef __FUNCT__
25 #define __FUNCT__ "PetscOptionsBegin_Private"
26 /*
27     Handles setting up the data structure in a call to PetscOptionsBegin()
28 */
29 PetscErrorCode PetscOptionsBegin_Private(MPI_Comm comm,const char prefix[],const char title[],const char mansec[])
30 {
31   PetscErrorCode ierr;
32 
33   PetscFunctionBegin;
34   PetscOptionsObject.next          = 0;
35   PetscOptionsObject.comm          = comm;
36   PetscOptionsObject.changedmethod = PETSC_FALSE;
37   ierr = PetscFree(PetscOptionsObject.prefix);CHKERRQ(ierr);
38   ierr = PetscStrallocpy(prefix,&PetscOptionsObject.prefix);CHKERRQ(ierr);
39   ierr = PetscFree(PetscOptionsObject.title);CHKERRQ(ierr);
40   ierr = PetscStrallocpy(title,&PetscOptionsObject.title);CHKERRQ(ierr);
41 
42   ierr = PetscOptionsHasName(PETSC_NULL,"-help",&PetscOptionsObject.printhelp);CHKERRQ(ierr);
43   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) {
44     if (!PetscOptionsObject.alreadyprinted) {
45       ierr = (*PetscHelpPrintf)(comm,"%s -------------------------------------------------\n",title);CHKERRQ(ierr);
46     }
47   }
48   PetscFunctionReturn(0);
49 }
50 
51 /*
52      Handles adding another option to the list of options within this particular PetscOptionsBegin() PetscOptionsEnd()
53 */
54 #undef __FUNCT__
55 #define __FUNCT__ "PetscOptionsCreate_Private"
56 static int PetscOptionsCreate_Private(const char opt[],const char text[],const char man[],PetscOptionType t,PetscOptions *amsopt)
57 {
58   int          ierr;
59   PetscOptions next;
60   PetscBool    valid;
61 
62   PetscFunctionBegin;
63   ierr = PetscOptionsValidKey(opt,&valid);CHKERRQ(ierr);
64   if (!valid) SETERRQ1(PETSC_COMM_WORLD,PETSC_ERR_ARG_INCOMP,"The option '%s' is not a valid key",opt);
65 
66   ierr             = PetscNew(struct _n_PetscOptions,amsopt);CHKERRQ(ierr);
67   (*amsopt)->next  = 0;
68   (*amsopt)->set   = PETSC_FALSE;
69   (*amsopt)->type  = t;
70   (*amsopt)->data  = 0;
71 
72   ierr             = PetscStrallocpy(text,&(*amsopt)->text);CHKERRQ(ierr);
73   ierr             = PetscStrallocpy(opt,&(*amsopt)->option);CHKERRQ(ierr);
74   ierr             = PetscStrallocpy(man,&(*amsopt)->man);CHKERRQ(ierr);
75 
76   if (!PetscOptionsObject.next) {
77     PetscOptionsObject.next = *amsopt;
78   } else {
79     next = PetscOptionsObject.next;
80     while (next->next) next = next->next;
81     next->next = *amsopt;
82   }
83   PetscFunctionReturn(0);
84 }
85 
86 #undef __FUNCT__
87 #define __FUNCT__ "PetscScanString"
88 /*
89     PetscScanString -  Gets user input via stdin from process and broadcasts to all processes
90 
91     Collective on MPI_Comm
92 
93    Input Parameters:
94 +     commm - communicator for the broadcast, must be PETSC_COMM_WORLD
95 .     n - length of the string, must be the same on all processes
96 -     str - location to store input
97 
98     Bugs:
99 .   Assumes process 0 of the given communicator has access to stdin
100 
101 */
102 static PetscErrorCode PetscScanString(MPI_Comm comm,size_t n,char str[])
103 {
104   size_t         i;
105   char           c;
106   PetscMPIInt    rank,nm;
107   PetscErrorCode ierr;
108 
109   PetscFunctionBegin;
110   ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr);
111   if (!rank) {
112     c = (char) getchar();
113     i = 0;
114     while ( c != '\n' && i < n-1) {
115       str[i++] = c;
116       c = (char) getchar();
117     }
118     str[i] = 0;
119   }
120   nm   = PetscMPIIntCast(n);
121   ierr = MPI_Bcast(str,nm,MPI_CHAR,0,comm);CHKERRQ(ierr);
122   PetscFunctionReturn(0);
123 }
124 
125 #undef __FUNCT__
126 #define __FUNCT__ "PetscOptionsGetFromTextInput"
127 /*
128     PetscOptionsGetFromTextInput - Presents all the PETSc Options processed by the program so the user may change them at runtime
129 
130     Notes: this isn't really practical, it is just to demonstrate the principle
131 
132     Bugs:
133 +    All processes must traverse through the exact same set of option queries do to the call to PetscScanString()
134 .    Internal strings have arbitrary length and string copies are not checked that they fit into string space
135 -    Only works for PetscInt == int, PetscReal == double etc
136 
137     Developer Notes: Normally the GUI that presents the options the user and retrieves the values would be running in a different
138      address space and communicating with the PETSc program
139 
140 */
141 PetscErrorCode PetscOptionsGetFromTextInput()
142 {
143   PetscErrorCode ierr;
144   PetscOptions   next = PetscOptionsObject.next;
145   char           str[512];
146   PetscInt       id;
147   PetscReal      ir,*valr;
148   PetscInt       *vald;
149   size_t         i;
150 
151   ierr = (*PetscPrintf)(PETSC_COMM_WORLD,"%s -------------------------------------------------\n",PetscOptionsObject.title);CHKERRQ(ierr);
152   while (next) {
153     switch (next->type) {
154       case OPTION_HEAD:
155         break;
156       case OPTION_INT_ARRAY:
157         ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",next->option+1);CHKERRQ(ierr);
158         vald = (PetscInt*) next->data;
159         for (i=0; i<next->arraylength; i++) {
160           ierr = PetscPrintf(PETSC_COMM_WORLD,"%d",vald[i]);CHKERRQ(ierr);
161           if (i < next->arraylength-1) {
162             ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr);
163           }
164         }
165         ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s)",next->text,next->man);CHKERRQ(ierr);
166         ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
167         if (str[0]) {
168           PetscToken token;
169           PetscInt   n=0,nmax = next->arraylength,*dvalue = (PetscInt*)next->data,start,end;
170           size_t     len;
171           char*      value;
172           PetscBool  foundrange;
173 
174           next->set = PETSC_TRUE;
175           value = str;
176 	  ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr);
177 	  ierr = PetscTokenFind(token,&value);CHKERRQ(ierr);
178 	  while (n < nmax) {
179 	    if (!value) break;
180 
181 	    /* look for form  d-D where d and D are integers */
182 	    foundrange = PETSC_FALSE;
183 	    ierr      = PetscStrlen(value,&len);CHKERRQ(ierr);
184 	    if (value[0] == '-') i=2;
185 	    else i=1;
186 	    for (;i<len; i++) {
187 	      if (value[i] == '-') {
188 		if (i == len-1) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"Error in %D-th array entry %s\n",n,value);
189 		value[i] = 0;
190 		ierr     = PetscOptionsStringToInt(value,&start);CHKERRQ(ierr);
191 		ierr     = PetscOptionsStringToInt(value+i+1,&end);CHKERRQ(ierr);
192 		if (end <= start) SETERRQ3(PETSC_COMM_SELF,PETSC_ERR_USER,"Error in %D-th array entry, %s-%s cannot have decreasing list",n,value,value+i+1);
193 		if (n + end - start - 1 >= nmax) SETERRQ4(PETSC_COMM_SELF,PETSC_ERR_USER,"Error in %D-th array entry, not enough space in left in array (%D) to contain entire range from %D to %D",n,nmax-n,start,end);
194 		for (;start<end; start++) {
195 		  *dvalue = start; dvalue++;n++;
196 		}
197 		foundrange = PETSC_TRUE;
198 		break;
199 	      }
200 	    }
201 	    if (!foundrange) {
202 	      ierr      = PetscOptionsStringToInt(value,dvalue);CHKERRQ(ierr);
203 	      dvalue++;
204 	      n++;
205 	    }
206 	    ierr = PetscTokenFind(token,&value);CHKERRQ(ierr);
207 	  }
208 	  ierr = PetscTokenDestroy(token);CHKERRQ(ierr);
209         }
210         break;
211       case OPTION_REAL_ARRAY:
212         ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",next->option+1);CHKERRQ(ierr);
213         valr = (PetscReal*) next->data;
214         for (i=0; i<next->arraylength; i++) {
215           ierr = PetscPrintf(PETSC_COMM_WORLD,"%g",valr[i]);CHKERRQ(ierr);
216           if (i < next->arraylength-1) {
217             ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr);
218           }
219         }
220         ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s)",next->text,next->man);CHKERRQ(ierr);
221         ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
222         if (str[0]) {
223           PetscToken token;
224           PetscInt   n=0,nmax = next->arraylength;
225           PetscReal   *dvalue = (PetscReal*)next->data;
226           char*      value;
227 
228           next->set = PETSC_TRUE;
229           value = str;
230 	  ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr);
231 	  ierr = PetscTokenFind(token,&value);CHKERRQ(ierr);
232 	  while (n < nmax) {
233 	    if (!value) break;
234             ierr      = PetscOptionsStringToReal(value,dvalue);CHKERRQ(ierr);
235 	    dvalue++;
236 	    n++;
237 	    ierr = PetscTokenFind(token,&value);CHKERRQ(ierr);
238 	  }
239 	  ierr = PetscTokenDestroy(token);CHKERRQ(ierr);
240         }
241         break;
242       case OPTION_INT:
243         ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <%d>: %s (%s)",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",next->option+1,*(int*)next->data,next->text,next->man);CHKERRQ(ierr);
244         ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
245         if (str[0]) {
246 #if defined(PETSC_USE_64BIT_INDICES)
247           sscanf(str,"%lld",&id);
248 #else
249           sscanf(str,"%d",&id);
250 #endif
251           next->set = PETSC_TRUE;
252           *((PetscInt*)next->data) = id;
253         }
254         break;
255       case OPTION_REAL:
256         ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <%g>: %s (%s)",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",next->option+1,*(double*)next->data,next->text,next->man);CHKERRQ(ierr);
257         ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
258         if (str[0]) {
259 #if defined(PETSC_USE_REAL_SINGLE)
260           sscanf(str,"%e",&ir);
261 #elif defined(PETSC_USE_REAL_DOUBLE)
262           sscanf(str,"%le",&ir);
263 #elif defined(PETSC_USE_REAL_LONG_DOUBLE)
264           sscanf(str,"%Le",&ir);
265 #elif defined(PETSC_USE_REAL___FLOAT128)
266           ir = strtoflt128(str,0);
267 #else
268           SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Unknown scalar type");
269 #endif
270           next->set = PETSC_TRUE;
271           *((PetscReal*)next->data) = ir;
272         }
273         break;
274       case OPTION_LOGICAL:
275       case OPTION_STRING:
276         ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <%s>: %s (%s)",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",next->option+1,(char*)next->data,next->text,next->man);CHKERRQ(ierr);
277         ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
278         if (str[0]) {
279           next->set = PETSC_TRUE;
280           ierr = PetscStrcpy((char*)next->data,str);CHKERRQ(ierr);
281         }
282         break;
283       case OPTION_LIST:
284         ierr = PetscFListPrintTypes(PETSC_COMM_WORLD,stdout,PetscOptionsObject.prefix,next->option,next->text,next->man,next->flist,(char*)next->data);CHKERRQ(ierr);
285         ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
286         if (str[0]) {
287 	  PetscOptionsObject.changedmethod = PETSC_TRUE;
288           next->set = PETSC_TRUE;
289           ierr = PetscStrcpy((char*)next->data,str);CHKERRQ(ierr);
290         }
291         break;
292     default:
293       break;
294     }
295     next = next->next;
296   }
297   PetscFunctionReturn(0);
298 }
299 
300 #if defined(PETSC_HAVE_AMS)
301 #define CHKERRAMS(err)  if (err) {char *msg; AMS_Explain_error((err), &(msg)); SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"AMS Error: %s",msg);}
302 #define CHKERRAMSFieldName(err,fn)  if (err) {char *msg; AMS_Explain_error((err), &(msg)); SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_LIB,"Fieldname %s, AMS Error: %s",fn,msg);}
303 
304 static int  count = 0;
305 
306 #undef __FUNCT__
307 #define __FUNCT__ "PetscOptionsAMSDestroy"
308 PetscErrorCode PetscOptionsAMSDestroy(void)
309 {
310   PetscErrorCode ierr;
311   AMS_Comm       acomm = -1;
312   AMS_Memory     amem = -1;
313   char           options[16];
314   const char     *string = "Exit";
315 
316   /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */
317   ierr = PetscViewerAMSGetAMSComm(PETSC_VIEWER_AMS_(PETSC_COMM_WORLD),&acomm);CHKERRQ(ierr);
318   sprintf(options,"Options_%d",count++);
319   ierr = AMS_Memory_create(acomm,options,&amem);CHKERRAMS(ierr);
320   ierr = AMS_Memory_add_field(amem,"Exit",&string,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,"Exit");
321 
322   ierr = AMS_Memory_take_access(amem);CHKERRAMS(ierr);
323   ierr = AMS_Memory_publish(amem);CHKERRAMS(ierr);
324   ierr = AMS_Memory_grant_access(amem);CHKERRAMS(ierr);
325   /* wait until accessor has unlocked the memory */
326   ierr = AMS_Memory_lock(amem,0);CHKERRAMS(ierr);
327   ierr = AMS_Memory_take_access(amem);CHKERRAMS(ierr);
328   ierr = AMS_Memory_grant_access(amem);CHKERRAMS(ierr);
329   ierr = AMS_Memory_destroy(amem);CHKERRAMS(ierr);
330   PetscFunctionReturn(0);
331 }
332 
333 #undef __FUNCT__
334 #define __FUNCT__ "PetscOptionsAMSInput"
335 /*
336     PetscOptionsAMSInput - Presents all the PETSc Options processed by the program so the user may change them at runtime using the AMS
337 
338     Bugs:
339 +    All processes must traverse through the exact same set of option queries do to the call to PetscScanString()
340 .    Internal strings have arbitrary length and string copies are not checked that they fit into string space
341 -    Only works for PetscInt == int, PetscReal == double etc
342 
343 
344 */
345 PetscErrorCode PetscOptionsAMSInput()
346 {
347   PetscErrorCode ierr;
348   PetscOptions   next = PetscOptionsObject.next;
349   static int     mancount = 0;
350   char           options[16];
351   AMS_Comm       acomm = -1;
352   AMS_Memory     amem = -1;
353   PetscBool      changedmethod = PETSC_FALSE;
354   char           manname[16];
355 
356   /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */
357   ierr = PetscViewerAMSGetAMSComm(PETSC_VIEWER_AMS_(PETSC_COMM_WORLD),&acomm);CHKERRQ(ierr);
358   sprintf(options,"Options_%d",count++);
359   ierr = AMS_Memory_create(acomm,options,&amem);CHKERRAMS(ierr);
360   ierr = AMS_Memory_take_access(amem);CHKERRAMS(ierr);
361   PetscOptionsObject.pprefix = PetscOptionsObject.prefix; /* AMS will change this, so cannot pass prefix directly */
362 
363   ierr = AMS_Memory_add_field(amem,PetscOptionsObject.title,&PetscOptionsObject.pprefix,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,PetscOptionsObject.title);
364   //  ierr = AMS_Memory_add_field(amem,"mansec",&PetscOptionsObject.pprefix,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMS(ierr);
365   ierr = AMS_Memory_add_field(amem,"ChangedMethod",&changedmethod,1,AMS_BOOLEAN,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,"ChangedMethod");
366 
367   while (next) {
368     ierr = AMS_Memory_add_field(amem,next->option,&next->set,1,AMS_INT,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->option);
369     ierr =  PetscMalloc(sizeof(char*),&next->pman);CHKERRQ(ierr);
370     *(char **)next->pman = next->man;
371     sprintf(manname,"man_%d",mancount++);
372     ierr = AMS_Memory_add_field(amem,manname,next->pman,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,manname);
373 
374     switch (next->type) {
375       case OPTION_HEAD:
376         break;
377       case OPTION_INT_ARRAY:
378         ierr = AMS_Memory_add_field(amem,next->text,next->data,next->arraylength,AMS_INT,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
379         break;
380       case OPTION_REAL_ARRAY:
381         ierr = AMS_Memory_add_field(amem,next->text,next->data,next->arraylength,AMS_DOUBLE,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
382         break;
383       case OPTION_INT:
384 	ierr = AMS_Memory_add_field(amem,next->text,next->data,1,AMS_INT,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
385         break;
386       case OPTION_REAL:
387 	ierr = AMS_Memory_add_field(amem,next->text,next->data,1,AMS_DOUBLE,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
388         break;
389       case OPTION_LOGICAL:
390 	ierr = AMS_Memory_add_field(amem,next->text,next->data,1,AMS_BOOLEAN,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
391         break;
392       case OPTION_LOGICAL_ARRAY:
393 	ierr = AMS_Memory_add_field(amem,next->text,next->data,next->arraylength,AMS_BOOLEAN,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
394         break;
395       case OPTION_STRING:
396 	ierr = AMS_Memory_add_field(amem,next->text,next->data,1,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
397         break;
398       case OPTION_STRING_ARRAY:
399 	ierr = AMS_Memory_add_field(amem,next->text,next->data,next->arraylength,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
400         break;
401       case OPTION_LIST:
402         {PetscInt  ntext;
403         char       ldefault[128];
404 	ierr = PetscStrcpy(ldefault,"DEFAULT:");CHKERRQ(ierr);
405 	ierr = PetscStrcat(ldefault,next->text);CHKERRQ(ierr);
406 	ierr = AMS_Memory_add_field(amem,ldefault,next->data,1,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,ldefault);
407 	ierr = PetscFListGet(next->flist,(char***)&next->edata,&ntext);CHKERRQ(ierr);
408 	ierr = AMS_Memory_add_field(amem,next->text,next->edata,ntext-1,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
409         break;}
410       case OPTION_ELIST:
411         {PetscInt  ntext = next->nlist;
412         char       ldefault[128];
413 	ierr = PetscStrcpy(ldefault,"DEFAULT:");CHKERRQ(ierr);
414 	ierr = PetscStrcat(ldefault,next->text);CHKERRQ(ierr);
415 	ierr = AMS_Memory_add_field(amem,ldefault,next->data,1,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,ldefault);
416 	ierr = PetscMalloc((ntext+1)*sizeof(char**),&next->edata);CHKERRQ(ierr);
417         ierr = PetscMemcpy(next->edata,next->list,ntext*sizeof(char*));CHKERRQ(ierr);
418 	ierr = AMS_Memory_add_field(amem,next->text,next->edata,ntext,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
419         break;}
420     default:
421       break;
422     }
423     next = next->next;
424   }
425 
426   ierr = AMS_Memory_publish(amem);CHKERRAMS(ierr);
427   ierr = AMS_Memory_grant_access(amem);CHKERRAMS(ierr);
428   /* wait until accessor has unlocked the memory */
429   ierr = AMS_Memory_lock(amem,0);CHKERRAMS(ierr);
430   ierr = AMS_Memory_take_access(amem);CHKERRAMS(ierr);
431 
432   /* reset counter to -2; this updates the screen with the new options for the selected method */
433   if (changedmethod) PetscOptionsPublishCount = -2;
434 
435   ierr = AMS_Memory_grant_access(amem);CHKERRAMS(ierr);
436   ierr = AMS_Memory_destroy(amem);CHKERRAMS(ierr);
437   PetscFunctionReturn(0);
438 }
439 #endif
440 
441 #undef __FUNCT__
442 #define __FUNCT__ "PetscOptionsEnd_Private"
443 PetscErrorCode PetscOptionsEnd_Private(void)
444 {
445   PetscErrorCode ierr;
446   PetscOptions   last;
447   char           option[256],value[1024],tmp[32];
448   size_t         j;
449 
450   PetscFunctionBegin;
451 
452   CHKMEMQ;
453   if (PetscOptionsObject.next) {
454     if (!PetscOptionsPublishCount) {
455 #if defined(PETSC_HAVE_AMS)
456       ierr = PetscOptionsAMSInput();CHKERRQ(ierr);
457 #else
458       ierr = PetscOptionsGetFromTextInput();CHKERRQ(ierr);
459 #endif
460     }
461   }
462 
463   ierr = PetscFree(PetscOptionsObject.title);CHKERRQ(ierr);
464   ierr = PetscFree(PetscOptionsObject.prefix);CHKERRQ(ierr);
465 
466   /* reset counter to -2; this updates the screen with the new options for the selected method */
467   if (PetscOptionsObject.changedmethod) PetscOptionsPublishCount = -2;
468   /* reset alreadyprinted flag */
469   PetscOptionsObject.alreadyprinted = PETSC_FALSE;
470 
471   while (PetscOptionsObject.next) {
472     if (PetscOptionsObject.next->set) {
473       if (PetscOptionsObject.prefix) {
474         ierr = PetscStrcpy(option,"-");CHKERRQ(ierr);
475         ierr = PetscStrcat(option,PetscOptionsObject.prefix);CHKERRQ(ierr);
476         ierr = PetscStrcat(option,PetscOptionsObject.next->option+1);CHKERRQ(ierr);
477       } else {
478         ierr = PetscStrcpy(option,PetscOptionsObject.next->option);CHKERRQ(ierr);
479       }
480 
481       switch (PetscOptionsObject.next->type) {
482         case OPTION_HEAD:
483           break;
484         case OPTION_INT_ARRAY:
485           sprintf(value,"%d",(int)((PetscInt*)PetscOptionsObject.next->data)[0]);
486           for (j=1; j<PetscOptionsObject.next->arraylength; j++) {
487             sprintf(tmp,"%d",(int)((PetscInt*)PetscOptionsObject.next->data)[j]);
488             ierr = PetscStrcat(value,",");CHKERRQ(ierr);
489             ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
490           }
491           break;
492         case OPTION_INT:
493           sprintf(value,"%d",(int) *(PetscInt*)PetscOptionsObject.next->data);
494           break;
495         case OPTION_REAL:
496           sprintf(value,"%g",(double) *(PetscReal*)PetscOptionsObject.next->data);
497           break;
498         case OPTION_REAL_ARRAY:
499           sprintf(value,"%g",(double)((PetscReal*)PetscOptionsObject.next->data)[0]);
500           for (j=1; j<PetscOptionsObject.next->arraylength; j++) {
501             sprintf(tmp,"%g",(double)((PetscReal*)PetscOptionsObject.next->data)[j]);
502             ierr = PetscStrcat(value,",");CHKERRQ(ierr);
503             ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
504           }
505           break;
506         case OPTION_LOGICAL:
507           sprintf(value,"%d",*(int*)PetscOptionsObject.next->data);
508           break;
509       case OPTION_LOGICAL_ARRAY:
510           sprintf(value,"%d",(int)((PetscBool*)PetscOptionsObject.next->data)[0]);
511           for (j=1; j<PetscOptionsObject.next->arraylength; j++) {
512             sprintf(tmp,"%d",(int)((PetscBool*)PetscOptionsObject.next->data)[j]);
513             ierr = PetscStrcat(value,",");CHKERRQ(ierr);
514             ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
515           }
516           break;
517         case OPTION_LIST:
518         case OPTION_ELIST:
519           ierr = PetscStrcpy(value,*(char**)PetscOptionsObject.next->data);CHKERRQ(ierr);
520           break;
521         case OPTION_STRING:
522           ierr = PetscStrcpy(value,*(char**)PetscOptionsObject.next->data);CHKERRQ(ierr);
523         case OPTION_STRING_ARRAY:
524           sprintf(value,"%s",((char**)PetscOptionsObject.next->data)[0]);
525           for (j=1; j<PetscOptionsObject.next->arraylength; j++) {
526             sprintf(tmp,"%s",((char**)PetscOptionsObject.next->data)[j]);
527             ierr = PetscStrcat(value,",");CHKERRQ(ierr);
528             ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
529           }
530           break;
531       }
532       ierr = PetscOptionsSetValue(option,value);CHKERRQ(ierr);
533     }
534     ierr   = PetscFree(PetscOptionsObject.next->text);CHKERRQ(ierr);
535     ierr   = PetscFree(PetscOptionsObject.next->option);CHKERRQ(ierr);
536     ierr   = PetscFree(PetscOptionsObject.next->man);CHKERRQ(ierr);
537     ierr   = PetscFree(PetscOptionsObject.next->data);CHKERRQ(ierr);
538     ierr   = PetscFree(PetscOptionsObject.next->edata);CHKERRQ(ierr);
539     last                    = PetscOptionsObject.next;
540     PetscOptionsObject.next = PetscOptionsObject.next->next;
541     ierr                    = PetscFree(last);CHKERRQ(ierr);
542     CHKMEMQ;
543   }
544   CHKMEMQ;
545   PetscOptionsObject.next = 0;
546   PetscFunctionReturn(0);
547 }
548 
549 #undef __FUNCT__
550 #define __FUNCT__ "PetscOptionsEnum"
551 /*@C
552    PetscOptionsEnum - Gets the enum value for a particular option in the database.
553 
554    Logically Collective on the communicator passed in PetscOptionsBegin()
555 
556    Input Parameters:
557 +  opt - option name
558 .  text - short string that describes the option
559 .  man - manual page with additional information on option
560 .  list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null
561 -  defaultv - the default (current) value
562 
563    Output Parameter:
564 +  value - the  value to return
565 -  flg - PETSC_TRUE if found, else PETSC_FALSE
566 
567    Level: beginner
568 
569    Concepts: options database
570 
571    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
572 
573           list is usually something like PCASMTypes or some other predefined list of enum names
574 
575 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
576           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
577           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
578           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
579           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
580           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
581           PetscOptionsList(), PetscOptionsEList()
582 @*/
583 PetscErrorCode  PetscOptionsEnum(const char opt[],const char text[],const char man[],const char *const*list,PetscEnum defaultv,PetscEnum *value,PetscBool  *set)
584 {
585   PetscErrorCode ierr;
586   PetscInt       ntext = 0;
587   PetscInt       tval;
588   PetscBool      tflg;
589 
590   PetscFunctionBegin;
591   while (list[ntext++]) {
592     if (ntext > 50) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries");
593   }
594   if (ntext < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix");
595   ntext -= 3;
596   ierr = PetscOptionsEList(opt,text,man,list,ntext,list[defaultv],&tval,&tflg);CHKERRQ(ierr);
597   /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */
598   if (tflg) *value = (PetscEnum)tval;
599   if (set)  *set   = tflg;
600   PetscFunctionReturn(0);
601 }
602 
603 /* -------------------------------------------------------------------------------------------------------------*/
604 #undef __FUNCT__
605 #define __FUNCT__ "PetscOptionsInt"
606 /*@C
607    PetscOptionsInt - Gets the integer value for a particular option in the database.
608 
609    Logically Collective on the communicator passed in PetscOptionsBegin()
610 
611    Input Parameters:
612 +  opt - option name
613 .  text - short string that describes the option
614 .  man - manual page with additional information on option
615 -  defaultv - the default (current) value
616 
617    Output Parameter:
618 +  value - the integer value to return
619 -  flg - PETSC_TRUE if found, else PETSC_FALSE
620 
621    Level: beginner
622 
623    Concepts: options database^has int
624 
625    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
626 
627 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
628           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
629           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
630           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
631           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
632           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
633           PetscOptionsList(), PetscOptionsEList()
634 @*/
635 PetscErrorCode  PetscOptionsInt(const char opt[],const char text[],const char man[],PetscInt defaultv,PetscInt *value,PetscBool  *set)
636 {
637   PetscErrorCode ierr;
638   PetscOptions   amsopt;
639 
640   PetscFunctionBegin;
641   if (!PetscOptionsPublishCount) {
642     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_INT,&amsopt);CHKERRQ(ierr);
643     ierr = PetscMalloc(sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr);
644     *(PetscInt*)amsopt->data = defaultv;
645   }
646   ierr = PetscOptionsGetInt(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
647   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
648     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%d>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,ManSection(man));CHKERRQ(ierr);
649   }
650   PetscFunctionReturn(0);
651 }
652 
653 #undef __FUNCT__
654 #define __FUNCT__ "PetscOptionsString"
655 /*@C
656    PetscOptionsString - Gets the string value for a particular option in the database.
657 
658    Logically Collective on the communicator passed in PetscOptionsBegin()
659 
660    Input Parameters:
661 +  opt - option name
662 .  text - short string that describes the option
663 .  man - manual page with additional information on option
664 .  defaultv - the default (current) value
665 -  len - length of the result string including null terminator
666 
667    Output Parameter:
668 +  value - the value to return
669 -  flg - PETSC_TRUE if found, else PETSC_FALSE
670 
671    Level: beginner
672 
673    Concepts: options database^has int
674 
675    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
676 
677    Even if the user provided no string (for example -optionname -someotheroption) the flag is set to PETSC_TRUE (and the string is fulled with nulls).
678 
679 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
680           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
681           PetscOptionsInt(), PetscOptionsReal(), PetscOptionsBool(),
682           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
683           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
684           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
685           PetscOptionsList(), PetscOptionsEList()
686 @*/
687 PetscErrorCode  PetscOptionsString(const char opt[],const char text[],const char man[],const char defaultv[],char value[],size_t len,PetscBool  *set)
688 {
689   PetscErrorCode ierr;
690   PetscOptions   amsopt;
691 
692   PetscFunctionBegin;
693   if (!PetscOptionsPublishCount) {
694     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr);
695     ierr = PetscMalloc(sizeof(char*),&amsopt->data);CHKERRQ(ierr);
696     *(const char**)amsopt->data = defaultv;
697   }
698   ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr);
699   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
700     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%s>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,ManSection(man));CHKERRQ(ierr);
701   }
702   PetscFunctionReturn(0);
703 }
704 
705 #undef __FUNCT__
706 #define __FUNCT__ "PetscOptionsReal"
707 /*@C
708    PetscOptionsReal - Gets the PetscReal value for a particular option in the database.
709 
710    Logically Collective on the communicator passed in PetscOptionsBegin()
711 
712    Input Parameters:
713 +  opt - option name
714 .  text - short string that describes the option
715 .  man - manual page with additional information on option
716 -  defaultv - the default (current) value
717 
718    Output Parameter:
719 +  value - the value to return
720 -  flg - PETSC_TRUE if found, else PETSC_FALSE
721 
722    Level: beginner
723 
724    Concepts: options database^has int
725 
726    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
727 
728 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
729           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
730           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
731           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
732           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
733           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
734           PetscOptionsList(), PetscOptionsEList()
735 @*/
736 PetscErrorCode  PetscOptionsReal(const char opt[],const char text[],const char man[],PetscReal defaultv,PetscReal *value,PetscBool  *set)
737 {
738   PetscErrorCode ierr;
739   PetscOptions   amsopt;
740 
741   PetscFunctionBegin;
742   if (!PetscOptionsPublishCount) {
743     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_REAL,&amsopt);CHKERRQ(ierr);
744     ierr = PetscMalloc(sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr);
745     *(PetscReal*)amsopt->data = defaultv;
746   }
747   ierr = PetscOptionsGetReal(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
748   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
749     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%G>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,ManSection(man));CHKERRQ(ierr);
750   }
751   PetscFunctionReturn(0);
752 }
753 
754 #undef __FUNCT__
755 #define __FUNCT__ "PetscOptionsScalar"
756 /*@C
757    PetscOptionsScalar - Gets the scalar value for a particular option in the database.
758 
759    Logically Collective on the communicator passed in PetscOptionsBegin()
760 
761    Input Parameters:
762 +  opt - option name
763 .  text - short string that describes the option
764 .  man - manual page with additional information on option
765 -  defaultv - the default (current) value
766 
767    Output Parameter:
768 +  value - the value to return
769 -  flg - PETSC_TRUE if found, else PETSC_FALSE
770 
771    Level: beginner
772 
773    Concepts: options database^has int
774 
775    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
776 
777 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
778           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
779           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
780           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
781           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
782           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
783           PetscOptionsList(), PetscOptionsEList()
784 @*/
785 PetscErrorCode  PetscOptionsScalar(const char opt[],const char text[],const char man[],PetscScalar defaultv,PetscScalar *value,PetscBool  *set)
786 {
787   PetscErrorCode ierr;
788 
789   PetscFunctionBegin;
790 #if !defined(PETSC_USE_COMPLEX)
791   ierr = PetscOptionsReal(opt,text,man,defaultv,value,set);CHKERRQ(ierr);
792 #else
793   ierr = PetscOptionsGetScalar(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
794 #endif
795   PetscFunctionReturn(0);
796 }
797 
798 #undef __FUNCT__
799 #define __FUNCT__ "PetscOptionsName"
800 /*@C
801    PetscOptionsName - Determines if a particular option has been set in the database. This returns true whether the option is a number, string or boolean, even
802                       its value is set to false.
803 
804    Logically Collective on the communicator passed in PetscOptionsBegin()
805 
806    Input Parameters:
807 +  opt - option name
808 .  text - short string that describes the option
809 -  man - manual page with additional information on option
810 
811    Output Parameter:
812 .  flg - PETSC_TRUE if found, else PETSC_FALSE
813 
814    Level: beginner
815 
816    Concepts: options database^has int
817 
818    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
819 
820 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
821           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
822           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
823           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
824           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
825           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
826           PetscOptionsList(), PetscOptionsEList()
827 @*/
828 PetscErrorCode  PetscOptionsName(const char opt[],const char text[],const char man[],PetscBool  *flg)
829 {
830   PetscErrorCode ierr;
831   PetscOptions   amsopt;
832 
833   PetscFunctionBegin;
834   if (!PetscOptionsPublishCount) {
835     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
836     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
837     *(PetscBool*)amsopt->data = PETSC_FALSE;
838   }
839   ierr = PetscOptionsHasName(PetscOptionsObject.prefix,opt,flg);CHKERRQ(ierr);
840   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
841     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,ManSection(man));CHKERRQ(ierr);
842   }
843   PetscFunctionReturn(0);
844 }
845 
846 #undef __FUNCT__
847 #define __FUNCT__ "PetscOptionsList"
848 /*@C
849      PetscOptionsList - Puts a list of option values that a single one may be selected from
850 
851    Logically Collective on the communicator passed in PetscOptionsBegin()
852 
853    Input Parameters:
854 +  opt - option name
855 .  text - short string that describes the option
856 .  man - manual page with additional information on option
857 .  list - the possible choices
858 .  defaultv - the default (current) value
859 -  len - the length of the character array value
860 
861    Output Parameter:
862 +  value - the value to return
863 -  set - PETSC_TRUE if found, else PETSC_FALSE
864 
865    Level: intermediate
866 
867    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
868 
869    See PetscOptionsEList() for when the choices are given in a string array
870 
871    To get a listing of all currently specified options,
872     see PetscOptionsView() or PetscOptionsGetAll()
873 
874    Concepts: options database^list
875 
876 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
877            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
878           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
879           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
880           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
881           PetscOptionsList(), PetscOptionsEList()
882 @*/
883 PetscErrorCode  PetscOptionsList(const char opt[],const char ltext[],const char man[],PetscFList list,const char defaultv[],char value[],size_t len,PetscBool  *set)
884 {
885   PetscErrorCode ierr;
886   PetscOptions   amsopt;
887 
888   PetscFunctionBegin;
889   if (!PetscOptionsPublishCount) {
890     ierr = PetscOptionsCreate_Private(opt,ltext,man,OPTION_LIST,&amsopt);CHKERRQ(ierr);
891     ierr = PetscMalloc(sizeof(char*),&amsopt->data);CHKERRQ(ierr);
892     *(const char**)amsopt->data = defaultv;
893     amsopt->flist = list;
894   }
895   ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr);
896   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
897     ierr = PetscFListPrintTypes(PetscOptionsObject.comm,stdout,PetscOptionsObject.prefix,opt,ltext,man,list,defaultv);CHKERRQ(ierr);CHKERRQ(ierr);
898   }
899   PetscFunctionReturn(0);
900 }
901 
902 #undef __FUNCT__
903 #define __FUNCT__ "PetscOptionsEList"
904 /*@C
905      PetscOptionsEList - Puts a list of option values that a single one may be selected from
906 
907    Logically Collective on the communicator passed in PetscOptionsBegin()
908 
909    Input Parameters:
910 +  opt - option name
911 .  ltext - short string that describes the option
912 .  man - manual page with additional information on option
913 .  list - the possible choices
914 .  ntext - number of choices
915 -  defaultv - the default (current) value
916 
917    Output Parameter:
918 +  value - the index of the value to return
919 -  set - PETSC_TRUE if found, else PETSC_FALSE
920 
921    Level: intermediate
922 
923    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
924 
925    See PetscOptionsList() for when the choices are given in a PetscFList()
926 
927    Concepts: options database^list
928 
929 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
930            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
931           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
932           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
933           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
934           PetscOptionsList(), PetscOptionsEList()
935 @*/
936 PetscErrorCode  PetscOptionsEList(const char opt[],const char ltext[],const char man[],const char *const*list,PetscInt ntext,const char defaultv[],PetscInt *value,PetscBool  *set)
937 {
938   PetscErrorCode ierr;
939   PetscInt       i;
940   PetscOptions   amsopt;
941 
942   PetscFunctionBegin;
943   if (!PetscOptionsPublishCount) {
944     ierr = PetscOptionsCreate_Private(opt,ltext,man,OPTION_ELIST,&amsopt);CHKERRQ(ierr);
945     ierr = PetscMalloc(sizeof(char*),&amsopt->data);CHKERRQ(ierr);
946     *(const char**)amsopt->data = defaultv;
947     amsopt->list  = list;
948     amsopt->nlist = ntext;
949   }
950   ierr = PetscOptionsGetEList(PetscOptionsObject.prefix,opt,list,ntext,value,set);CHKERRQ(ierr);
951   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
952     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%s> (choose one of)",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv);CHKERRQ(ierr);
953     for (i=0; i<ntext; i++){
954       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," %s",list[i]);CHKERRQ(ierr);
955     }
956     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," (%s)\n",ManSection(man));CHKERRQ(ierr);
957   }
958   PetscFunctionReturn(0);
959 }
960 
961 #undef __FUNCT__
962 #define __FUNCT__ "PetscOptionsBoolGroupBegin"
963 /*@C
964      PetscOptionsBoolGroupBegin - First in a series of logical queries on the options database for
965        which at most a single value can be true.
966 
967    Logically Collective on the communicator passed in PetscOptionsBegin()
968 
969    Input Parameters:
970 +  opt - option name
971 .  text - short string that describes the option
972 -  man - manual page with additional information on option
973 
974    Output Parameter:
975 .  flg - whether that option was set or not
976 
977    Level: intermediate
978 
979    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
980 
981    Must be followed by 0 or more PetscOptionsBoolGroup()s and PetscOptionsBoolGroupEnd()
982 
983     Concepts: options database^logical group
984 
985 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
986            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
987           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
988           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
989           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
990           PetscOptionsList(), PetscOptionsEList()
991 @*/
992 PetscErrorCode  PetscOptionsBoolGroupBegin(const char opt[],const char text[],const char man[],PetscBool  *flg)
993 {
994   PetscErrorCode ierr;
995   PetscOptions   amsopt;
996 
997   PetscFunctionBegin;
998   if (!PetscOptionsPublishCount) {
999     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
1000     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1001     *(PetscBool*)amsopt->data = PETSC_FALSE;
1002   }
1003   *flg = PETSC_FALSE;
1004   ierr = PetscOptionsGetBool(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr);
1005   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1006     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  Pick at most one of -------------\n");CHKERRQ(ierr);
1007     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,ManSection(man));CHKERRQ(ierr);
1008   }
1009   PetscFunctionReturn(0);
1010 }
1011 
1012 #undef __FUNCT__
1013 #define __FUNCT__ "PetscOptionsBoolGroup"
1014 /*@C
1015      PetscOptionsBoolGroup - One in a series of logical queries on the options database for
1016        which at most a single value can be true.
1017 
1018    Logically Collective on the communicator passed in PetscOptionsBegin()
1019 
1020    Input Parameters:
1021 +  opt - option name
1022 .  text - short string that describes the option
1023 -  man - manual page with additional information on option
1024 
1025    Output Parameter:
1026 .  flg - PETSC_TRUE if found, else PETSC_FALSE
1027 
1028    Level: intermediate
1029 
1030    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1031 
1032    Must follow a PetscOptionsBoolGroupBegin() and preceded a PetscOptionsBoolGroupEnd()
1033 
1034     Concepts: options database^logical group
1035 
1036 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1037            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1038           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1039           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1040           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1041           PetscOptionsList(), PetscOptionsEList()
1042 @*/
1043 PetscErrorCode  PetscOptionsBoolGroup(const char opt[],const char text[],const char man[],PetscBool  *flg)
1044 {
1045   PetscErrorCode ierr;
1046   PetscOptions   amsopt;
1047 
1048   PetscFunctionBegin;
1049   if (!PetscOptionsPublishCount) {
1050     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
1051     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1052     *(PetscBool*)amsopt->data = PETSC_FALSE;
1053   }
1054   *flg = PETSC_FALSE;
1055   ierr = PetscOptionsGetBool(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr);
1056   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1057     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,ManSection(man));CHKERRQ(ierr);
1058   }
1059   PetscFunctionReturn(0);
1060 }
1061 
1062 #undef __FUNCT__
1063 #define __FUNCT__ "PetscOptionsBoolGroupEnd"
1064 /*@C
1065      PetscOptionsBoolGroupEnd - Last in a series of logical queries on the options database for
1066        which at most a single value can be true.
1067 
1068    Logically Collective on the communicator passed in PetscOptionsBegin()
1069 
1070    Input Parameters:
1071 +  opt - option name
1072 .  text - short string that describes the option
1073 -  man - manual page with additional information on option
1074 
1075    Output Parameter:
1076 .  flg - PETSC_TRUE if found, else PETSC_FALSE
1077 
1078    Level: intermediate
1079 
1080    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1081 
1082    Must follow a PetscOptionsBoolGroupBegin()
1083 
1084     Concepts: options database^logical group
1085 
1086 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1087            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1088           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1089           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1090           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1091           PetscOptionsList(), PetscOptionsEList()
1092 @*/
1093 PetscErrorCode  PetscOptionsBoolGroupEnd(const char opt[],const char text[],const char man[],PetscBool  *flg)
1094 {
1095   PetscErrorCode ierr;
1096   PetscOptions   amsopt;
1097 
1098   PetscFunctionBegin;
1099   if (!PetscOptionsPublishCount) {
1100     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
1101     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1102     *(PetscBool*)amsopt->data = PETSC_FALSE;
1103   }
1104   *flg = PETSC_FALSE;
1105   ierr = PetscOptionsGetBool(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr);
1106   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1107     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,ManSection(man));CHKERRQ(ierr);
1108   }
1109   PetscFunctionReturn(0);
1110 }
1111 
1112 #undef __FUNCT__
1113 #define __FUNCT__ "PetscOptionsBool"
1114 /*@C
1115    PetscOptionsBool - Determines if a particular option is in the database with a true or false
1116 
1117    Logically Collective on the communicator passed in PetscOptionsBegin()
1118 
1119    Input Parameters:
1120 +  opt - option name
1121 .  text - short string that describes the option
1122 -  man - manual page with additional information on option
1123 
1124    Output Parameter:
1125 .  flg - PETSC_TRUE or PETSC_FALSE
1126 .  set - PETSC_TRUE if found, else PETSC_FALSE
1127 
1128    Level: beginner
1129 
1130    Concepts: options database^logical
1131 
1132    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1133 
1134 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
1135           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
1136           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
1137           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1138           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1139           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1140           PetscOptionsList(), PetscOptionsEList()
1141 @*/
1142 PetscErrorCode  PetscOptionsBool(const char opt[],const char text[],const char man[],PetscBool  deflt,PetscBool  *flg,PetscBool  *set)
1143 {
1144   PetscErrorCode ierr;
1145   PetscBool      iset;
1146   PetscOptions   amsopt;
1147 
1148   PetscFunctionBegin;
1149   if (!PetscOptionsPublishCount) {
1150     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
1151     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1152     *(PetscBool*)amsopt->data = deflt;
1153   }
1154   ierr = PetscOptionsGetBool(PetscOptionsObject.prefix,opt,flg,&iset);CHKERRQ(ierr);
1155   if (!iset) {
1156     if (flg) *flg = deflt;
1157   }
1158   if (set) *set = iset;
1159   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1160     const char *v = PetscBools[deflt];
1161     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s: <%s> %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,v,text,ManSection(man));CHKERRQ(ierr);
1162   }
1163   PetscFunctionReturn(0);
1164 }
1165 
1166 #undef __FUNCT__
1167 #define __FUNCT__ "PetscOptionsRealArray"
1168 /*@C
1169    PetscOptionsRealArray - Gets an array of double values for a particular
1170    option in the database. The values must be separated with commas with
1171    no intervening spaces.
1172 
1173    Logically Collective on the communicator passed in PetscOptionsBegin()
1174 
1175    Input Parameters:
1176 +  opt - the option one is seeking
1177 .  text - short string describing option
1178 .  man - manual page for option
1179 -  nmax - maximum number of values
1180 
1181    Output Parameter:
1182 +  value - location to copy values
1183 .  nmax - actual number of values found
1184 -  set - PETSC_TRUE if found, else PETSC_FALSE
1185 
1186    Level: beginner
1187 
1188    Notes:
1189    The user should pass in an array of doubles
1190 
1191    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1192 
1193    Concepts: options database^array of strings
1194 
1195 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1196            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1197           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1198           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1199           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1200           PetscOptionsList(), PetscOptionsEList()
1201 @*/
1202 PetscErrorCode  PetscOptionsRealArray(const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscBool  *set)
1203 {
1204   PetscErrorCode ierr;
1205   PetscInt       i;
1206   PetscOptions   amsopt;
1207 
1208   PetscFunctionBegin;
1209   if (!PetscOptionsPublishCount) {
1210     PetscReal *vals;
1211 
1212     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_REAL_ARRAY,&amsopt);CHKERRQ(ierr);
1213     ierr = PetscMalloc((*n)*sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr);
1214     vals = (PetscReal*)amsopt->data;
1215     for (i=0; i<*n; i++) vals[i] = value[i];
1216     amsopt->arraylength = *n;
1217   }
1218   ierr = PetscOptionsGetRealArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr);
1219   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1220     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%G",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr);
1221     for (i=1; i<*n; i++) {
1222       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%G",value[i]);CHKERRQ(ierr);
1223     }
1224     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
1225   }
1226   PetscFunctionReturn(0);
1227 }
1228 
1229 
1230 #undef __FUNCT__
1231 #define __FUNCT__ "PetscOptionsIntArray"
1232 /*@C
1233    PetscOptionsIntArray - Gets an array of integers for a particular
1234    option in the database. The values must be separated with commas with
1235    no intervening spaces.
1236 
1237    Logically Collective on the communicator passed in PetscOptionsBegin()
1238 
1239    Input Parameters:
1240 +  opt - the option one is seeking
1241 .  text - short string describing option
1242 .  man - manual page for option
1243 -  n - maximum number of values
1244 
1245    Output Parameter:
1246 +  value - location to copy values
1247 .  n - actual number of values found
1248 -  set - PETSC_TRUE if found, else PETSC_FALSE
1249 
1250    Level: beginner
1251 
1252    Notes:
1253    The user should pass in an array of integers
1254 
1255    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1256 
1257    Concepts: options database^array of strings
1258 
1259 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1260            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1261           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1262           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1263           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1264           PetscOptionsList(), PetscOptionsEList(), PetscOptionsRealArray()
1265 @*/
1266 PetscErrorCode  PetscOptionsIntArray(const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscBool  *set)
1267 {
1268   PetscErrorCode ierr;
1269   PetscInt       i;
1270   PetscOptions   amsopt;
1271 
1272   PetscFunctionBegin;
1273   if (!PetscOptionsPublishCount) {
1274     PetscInt *vals;
1275 
1276     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_INT_ARRAY,&amsopt);CHKERRQ(ierr);
1277     ierr = PetscMalloc((*n)*sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr);
1278     vals = (PetscInt*)amsopt->data;
1279     for (i=0; i<*n; i++) vals[i] = value[i];
1280     amsopt->arraylength = *n;
1281   }
1282   ierr = PetscOptionsGetIntArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr);
1283   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1284     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%d",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr);
1285     for (i=1; i<*n; i++) {
1286       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr);
1287     }
1288     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
1289   }
1290   PetscFunctionReturn(0);
1291 }
1292 
1293 #undef __FUNCT__
1294 #define __FUNCT__ "PetscOptionsStringArray"
1295 /*@C
1296    PetscOptionsStringArray - Gets an array of string values for a particular
1297    option in the database. The values must be separated with commas with
1298    no intervening spaces.
1299 
1300    Logically Collective on the communicator passed in PetscOptionsBegin()
1301 
1302    Input Parameters:
1303 +  opt - the option one is seeking
1304 .  text - short string describing option
1305 .  man - manual page for option
1306 -  nmax - maximum number of strings
1307 
1308    Output Parameter:
1309 +  value - location to copy strings
1310 .  nmax - actual number of strings found
1311 -  set - PETSC_TRUE if found, else PETSC_FALSE
1312 
1313    Level: beginner
1314 
1315    Notes:
1316    The user should pass in an array of pointers to char, to hold all the
1317    strings returned by this function.
1318 
1319    The user is responsible for deallocating the strings that are
1320    returned. The Fortran interface for this routine is not supported.
1321 
1322    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1323 
1324    Concepts: options database^array of strings
1325 
1326 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1327            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1328           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1329           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1330           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1331           PetscOptionsList(), PetscOptionsEList()
1332 @*/
1333 PetscErrorCode  PetscOptionsStringArray(const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscBool  *set)
1334 {
1335   PetscErrorCode ierr;
1336   PetscOptions   amsopt;
1337 
1338   PetscFunctionBegin;
1339   if (!PetscOptionsPublishCount) {
1340     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING_ARRAY,&amsopt);CHKERRQ(ierr);
1341     ierr = PetscMalloc((*nmax)*sizeof(char*),&amsopt->data);CHKERRQ(ierr);
1342     amsopt->arraylength = *nmax;
1343   }
1344   ierr = PetscOptionsGetStringArray(PetscOptionsObject.prefix,opt,value,nmax,set);CHKERRQ(ierr);
1345   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1346     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <string1,string2,...>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,ManSection(man));CHKERRQ(ierr);
1347   }
1348   PetscFunctionReturn(0);
1349 }
1350 
1351 #undef __FUNCT__
1352 #define __FUNCT__ "PetscOptionsBoolArray"
1353 /*@C
1354    PetscOptionsBoolArray - Gets an array of logical values (true or false) for a particular
1355    option in the database. The values must be separated with commas with
1356    no intervening spaces.
1357 
1358    Logically Collective on the communicator passed in PetscOptionsBegin()
1359 
1360    Input Parameters:
1361 +  opt - the option one is seeking
1362 .  text - short string describing option
1363 .  man - manual page for option
1364 -  nmax - maximum number of values
1365 
1366    Output Parameter:
1367 +  value - location to copy values
1368 .  nmax - actual number of values found
1369 -  set - PETSC_TRUE if found, else PETSC_FALSE
1370 
1371    Level: beginner
1372 
1373    Notes:
1374    The user should pass in an array of doubles
1375 
1376    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1377 
1378    Concepts: options database^array of strings
1379 
1380 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1381            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1382           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1383           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1384           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1385           PetscOptionsList(), PetscOptionsEList()
1386 @*/
1387 PetscErrorCode  PetscOptionsBoolArray(const char opt[],const char text[],const char man[],PetscBool  value[],PetscInt *n,PetscBool  *set)
1388 {
1389   PetscErrorCode ierr;
1390   PetscInt       i;
1391   PetscOptions   amsopt;
1392 
1393   PetscFunctionBegin;
1394   if (!PetscOptionsPublishCount) {
1395     PetscBool  *vals;
1396 
1397     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL_ARRAY,&amsopt);CHKERRQ(ierr);
1398     ierr = PetscMalloc((*n)*sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1399     vals = (PetscBool*)amsopt->data;
1400     for (i=0; i<*n; i++) vals[i] = value[i];
1401     amsopt->arraylength = *n;
1402   }
1403   ierr = PetscOptionsGetBoolArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr);
1404   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1405     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%d",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr);
1406     for (i=1; i<*n; i++) {
1407       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr);
1408     }
1409     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
1410   }
1411   PetscFunctionReturn(0);
1412 }
1413 
1414 
1415 #undef __FUNCT__
1416 #define __FUNCT__ "PetscOptionsHead"
1417 /*@C
1418      PetscOptionsHead - Puts a heading before listing any more published options. Used, for example,
1419             in KSPSetFromOptions_GMRES().
1420 
1421    Logically Collective on the communicator passed in PetscOptionsBegin()
1422 
1423    Input Parameter:
1424 .   head - the heading text
1425 
1426 
1427    Level: intermediate
1428 
1429    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1430 
1431           Can be followed by a call to PetscOptionsTail() in the same function.
1432 
1433    Concepts: options database^subheading
1434 
1435 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1436            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1437           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1438           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1439           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1440           PetscOptionsList(), PetscOptionsEList()
1441 @*/
1442 PetscErrorCode  PetscOptionsHead(const char head[])
1443 {
1444   PetscErrorCode ierr;
1445 
1446   PetscFunctionBegin;
1447   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1448     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  %s\n",head);CHKERRQ(ierr);
1449   }
1450   PetscFunctionReturn(0);
1451 }
1452 
1453 
1454 
1455 
1456 
1457 
1458