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