xref: /petsc/src/sys/objects/aoptions.c (revision 1bc75a8d26e8519bdcc1e898658b3cd7d159a1af)
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,mancount = 0;
315   char           options[16];
316   AMS_Comm       acomm = -1;
317   AMS_Memory     amem = -1;
318   PetscTruth     changedmethod = PETSC_FALSE;
319   char           manname[16];
320 
321   /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */
322   ierr = PetscViewerAMSGetAMSComm(PETSC_VIEWER_AMS_(PETSC_COMM_WORLD),&acomm);CHKERRQ(ierr);
323   sprintf(options,"Options_%d",count++);
324   ierr = AMS_Memory_create(acomm,options,&amem);CHKERRQ(ierr);
325   ierr = AMS_Memory_take_access(amem);CHKERRQ(ierr);
326   PetscOptionsObject.pprefix = PetscOptionsObject.prefix; /* AMS will change this, so cannot pass prefix directly */
327 
328   ierr = AMS_Memory_add_field(amem,PetscOptionsObject.title,&PetscOptionsObject.pprefix,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRQ(ierr);
329   ierr = AMS_Memory_add_field(amem,"mansec",&PetscOptionsObject.pprefix,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRQ(ierr);
330   ierr = AMS_Memory_add_field(amem,"ChangedMethod",&changedmethod,1,AMS_BOOLEAN,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRQ(ierr);
331 
332   while (next) {
333     ierr = AMS_Memory_add_field(amem,next->option,&next->set,1,AMS_INT,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRQ(ierr);
334     ierr =  PetscMalloc(sizeof(char*),&next->pman);CHKERRQ(ierr);
335     *(char **)next->pman = next->man;
336     sprintf(manname,"man_%d",mancount++);
337     ierr = AMS_Memory_add_field(amem,manname,next->pman,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRQ(ierr);
338 
339     switch (next->type) {
340       case OPTION_HEAD:
341         break;
342       case OPTION_INT_ARRAY:
343         break;
344       case OPTION_REAL_ARRAY:
345         break;
346       case OPTION_INT:
347 	ierr = AMS_Memory_add_field(amem,next->text,next->data,1,AMS_INT,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRQ(ierr);
348         break;
349       case OPTION_REAL:
350         break;
351       case OPTION_LOGICAL:
352       case OPTION_STRING:
353         break;
354       case OPTION_LIST:
355         break;
356     default:
357       break;
358     }
359     next = next->next;
360   }
361 
362   ierr = AMS_Memory_publish(amem);CHKERRQ(ierr);
363   ierr = AMS_Memory_grant_access(amem);CHKERRQ(ierr);
364   /* wait until accessor has unlocked the memory */
365   ierr = AMS_Memory_lock(amem,0);CHKERRQ(ierr);
366   ierr = AMS_Memory_take_access(amem);CHKERRQ(ierr);
367 
368   /* reset counter to -2; this updates the screen with the new options for the selected method */
369   if (changedmethod) PetscOptionsPublishCount = -2;
370 
371   ierr = AMS_Memory_grant_access(amem);CHKERRQ(ierr);
372   ierr = AMS_Memory_destroy(amem);CHKERRQ(ierr);
373   PetscFunctionReturn(0);
374 }
375 #endif
376 
377 #undef __FUNCT__
378 #define __FUNCT__ "PetscOptionsEnd_Private"
379 PetscErrorCode PetscOptionsEnd_Private(void)
380 {
381   PetscErrorCode ierr;
382   PetscOptions   last;
383   char           option[256],value[1024],tmp[32];
384   size_t         j;
385 
386   PetscFunctionBegin;
387 
388   CHKMEMQ;
389   if (PetscOptionsObject.next) {
390     if (!PetscOptionsPublishCount) {
391 #if defined(PETSC_HAVE_AMS)
392       ierr = PetscOptionsGetFromAMSInput();
393 #else
394       ierr = PetscOptionsGetFromTextInput();
395 #endif
396     }
397   }
398 
399   ierr = PetscFree(PetscOptionsObject.title);CHKERRQ(ierr); PetscOptionsObject.title  = 0;
400   ierr = PetscFree(PetscOptionsObject.prefix);CHKERRQ(ierr); PetscOptionsObject.prefix = 0;
401 
402   /* reset counter to -2; this updates the screen with the new options for the selected method */
403   if (PetscOptionsObject.changedmethod) PetscOptionsPublishCount = -2;
404   /* reset alreadyprinted flag */
405   PetscOptionsObject.alreadyprinted = PETSC_FALSE;
406 
407   while (PetscOptionsObject.next) {
408     if (PetscOptionsObject.next->set) {
409       if (PetscOptionsObject.prefix) {
410         ierr = PetscStrcpy(option,"-");CHKERRQ(ierr);
411         ierr = PetscStrcat(option,PetscOptionsObject.prefix);CHKERRQ(ierr);
412         ierr = PetscStrcat(option,PetscOptionsObject.next->option+1);CHKERRQ(ierr);
413       } else {
414         ierr = PetscStrcpy(option,PetscOptionsObject.next->option);CHKERRQ(ierr);
415       }
416 
417       switch (PetscOptionsObject.next->type) {
418         case OPTION_HEAD:
419           break;
420         case OPTION_INT_ARRAY:
421           sprintf(value,"%d",(int)((PetscInt*)PetscOptionsObject.next->data)[0]);
422           for (j=1; j<PetscOptionsObject.next->arraylength; j++) {
423             sprintf(tmp,"%d",(int)((PetscInt*)PetscOptionsObject.next->data)[j]);
424             ierr = PetscStrcat(value,",");CHKERRQ(ierr);
425             ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
426           }
427           break;
428         case OPTION_INT:
429           sprintf(value,"%d",(int) *(PetscInt*)PetscOptionsObject.next->data);
430           break;
431         case OPTION_REAL:
432           sprintf(value,"%g",(double) *(PetscReal*)PetscOptionsObject.next->data);
433           break;
434         case OPTION_REAL_ARRAY:
435           sprintf(value,"%g",(double)((PetscReal*)PetscOptionsObject.next->data)[0]);
436           for (j=1; j<PetscOptionsObject.next->arraylength; j++) {
437             sprintf(tmp,"%g",(double)((PetscReal*)PetscOptionsObject.next->data)[j]);
438             ierr = PetscStrcat(value,",");CHKERRQ(ierr);
439             ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
440           }
441           break;
442         case OPTION_LOGICAL:
443           ierr = PetscStrcpy(value,(char*)PetscOptionsObject.next->data);CHKERRQ(ierr);
444           break;
445         case OPTION_LIST:
446           ierr = PetscStrcpy(value,(char*)PetscOptionsObject.next->data);CHKERRQ(ierr);
447           break;
448         case OPTION_STRING: /* also handles string arrays */
449           ierr = PetscStrcpy(value,(char*)PetscOptionsObject.next->data);CHKERRQ(ierr);
450           break;
451       }
452       ierr = PetscOptionsSetValue(option,value);CHKERRQ(ierr);
453     }
454     ierr   = PetscFree(PetscOptionsObject.next->text);CHKERRQ(ierr);
455     ierr   = PetscFree(PetscOptionsObject.next->option);CHKERRQ(ierr);
456     ierr   = PetscFree(PetscOptionsObject.next->man);CHKERRQ(ierr);
457     ierr   = PetscFree(PetscOptionsObject.next->data);CHKERRQ(ierr);
458     last                    = PetscOptionsObject.next;
459     PetscOptionsObject.next = PetscOptionsObject.next->next;
460     ierr                    = PetscFree(last);CHKERRQ(ierr);
461     CHKMEMQ;
462   }
463   CHKMEMQ;
464   PetscOptionsObject.next = 0;
465   PetscFunctionReturn(0);
466 }
467 
468 #undef __FUNCT__
469 #define __FUNCT__ "PetscOptionsEnum"
470 /*@C
471    PetscOptionsEnum - Gets the enum value for a particular option in the database.
472 
473    Collective on the communicator passed in PetscOptionsBegin()
474 
475    Input Parameters:
476 +  opt - option name
477 .  text - short string that describes the option
478 .  man - manual page with additional information on option
479 .  list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null
480 -  defaultv - the default (current) value
481 
482    Output Parameter:
483 +  value - the  value to return
484 -  flg - PETSC_TRUE if found, else PETSC_FALSE
485 
486    Level: beginner
487 
488    Concepts: options database
489 
490    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
491 
492           list is usually something like PCASMTypes or some other predefined list of enum names
493 
494 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
495           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
496           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
497           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
498           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
499           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
500           PetscOptionsList(), PetscOptionsEList()
501 @*/
502 PetscErrorCode PETSC_DLLEXPORT PetscOptionsEnum(const char opt[],const char text[],const char man[],const char *const*list,PetscEnum defaultv,PetscEnum *value,PetscTruth *set)
503 {
504   PetscErrorCode ierr;
505   PetscInt       ntext = 0;
506   PetscInt       tval;
507   PetscTruth     tflg;
508 
509   PetscFunctionBegin;
510   while (list[ntext++]) {
511     if (ntext > 50) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries");
512   }
513   if (ntext < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix");
514   ntext -= 3;
515   ierr = PetscOptionsEList(opt,text,man,list,ntext,list[defaultv],&tval,&tflg);CHKERRQ(ierr);
516   /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */
517   if (tflg) *value = (PetscEnum)tval;
518   if (set)  *set   = tflg;
519   PetscFunctionReturn(0);
520 }
521 
522 /* -------------------------------------------------------------------------------------------------------------*/
523 #undef __FUNCT__
524 #define __FUNCT__ "PetscOptionsInt"
525 /*@C
526    PetscOptionsInt - Gets the integer value for a particular option in the database.
527 
528    Collective on the communicator passed in PetscOptionsBegin()
529 
530    Input Parameters:
531 +  opt - option name
532 .  text - short string that describes the option
533 .  man - manual page with additional information on option
534 -  defaultv - the default (current) value
535 
536    Output Parameter:
537 +  value - the integer value to return
538 -  flg - PETSC_TRUE if found, else PETSC_FALSE
539 
540    Level: beginner
541 
542    Concepts: options database^has int
543 
544    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
545 
546 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
547           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
548           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
549           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
550           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
551           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
552           PetscOptionsList(), PetscOptionsEList()
553 @*/
554 PetscErrorCode PETSC_DLLEXPORT PetscOptionsInt(const char opt[],const char text[],const char man[],PetscInt defaultv,PetscInt *value,PetscTruth *set)
555 {
556   PetscErrorCode ierr;
557   PetscOptions   amsopt;
558 
559   PetscFunctionBegin;
560   if (!PetscOptionsPublishCount) {
561     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_INT,&amsopt);CHKERRQ(ierr);
562     ierr = PetscMalloc(sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr);
563     *(PetscInt*)amsopt->data = defaultv;
564   }
565   ierr = PetscOptionsGetInt(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
566   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
567     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%d>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,man);CHKERRQ(ierr);
568   }
569   PetscFunctionReturn(0);
570 }
571 
572 #undef __FUNCT__
573 #define __FUNCT__ "PetscOptionsString"
574 /*@C
575    PetscOptionsString - Gets the string value for a particular option in the database.
576 
577    Collective on the communicator passed in PetscOptionsBegin()
578 
579    Input Parameters:
580 +  opt - option name
581 .  text - short string that describes the option
582 .  man - manual page with additional information on option
583 -  defaultv - the default (current) value
584 
585    Output Parameter:
586 +  value - the value to return
587 -  flg - PETSC_TRUE if found, else PETSC_FALSE
588 
589    Level: beginner
590 
591    Concepts: options database^has int
592 
593    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
594 
595 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
596           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
597           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
598           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
599           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
600           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
601           PetscOptionsList(), PetscOptionsEList()
602 @*/
603 PetscErrorCode PETSC_DLLEXPORT PetscOptionsString(const char opt[],const char text[],const char man[],const char defaultv[],char value[],size_t len,PetscTruth *set)
604 {
605   PetscErrorCode ierr;
606   PetscOptions   amsopt;
607 
608   PetscFunctionBegin;
609   if (!PetscOptionsPublishCount) {
610     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr);
611     ierr = PetscMalloc(len*sizeof(char),&amsopt->data);CHKERRQ(ierr);
612     ierr = PetscStrncpy((char*)amsopt->data,defaultv,len);CHKERRQ(ierr);
613   }
614   ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr);
615   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
616     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%s>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,man);CHKERRQ(ierr);
617   }
618   PetscFunctionReturn(0);
619 }
620 
621 #undef __FUNCT__
622 #define __FUNCT__ "PetscOptionsReal"
623 /*@C
624    PetscOptionsReal - Gets the PetscReal value for a particular option in the database.
625 
626    Collective on the communicator passed in PetscOptionsBegin()
627 
628    Input Parameters:
629 +  opt - option name
630 .  text - short string that describes the option
631 .  man - manual page with additional information on option
632 -  defaultv - the default (current) value
633 
634    Output Parameter:
635 +  value - the value to return
636 -  flg - PETSC_TRUE if found, else PETSC_FALSE
637 
638    Level: beginner
639 
640    Concepts: options database^has int
641 
642    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
643 
644 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
645           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
646           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
647           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
648           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
649           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
650           PetscOptionsList(), PetscOptionsEList()
651 @*/
652 PetscErrorCode PETSC_DLLEXPORT PetscOptionsReal(const char opt[],const char text[],const char man[],PetscReal defaultv,PetscReal *value,PetscTruth *set)
653 {
654   PetscErrorCode ierr;
655   PetscOptions   amsopt;
656 
657   PetscFunctionBegin;
658   if (!PetscOptionsPublishCount) {
659     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_REAL,&amsopt);CHKERRQ(ierr);
660     ierr = PetscMalloc(sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr);
661     *(PetscReal*)amsopt->data = defaultv;
662   }
663   ierr = PetscOptionsGetReal(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
664   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
665     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%G>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,man);CHKERRQ(ierr);
666   }
667   PetscFunctionReturn(0);
668 }
669 
670 #undef __FUNCT__
671 #define __FUNCT__ "PetscOptionsScalar"
672 /*@C
673    PetscOptionsScalar - Gets the scalar value for a particular option in the database.
674 
675    Collective on the communicator passed in PetscOptionsBegin()
676 
677    Input Parameters:
678 +  opt - option name
679 .  text - short string that describes the option
680 .  man - manual page with additional information on option
681 -  defaultv - the default (current) value
682 
683    Output Parameter:
684 +  value - the value to return
685 -  flg - PETSC_TRUE if found, else PETSC_FALSE
686 
687    Level: beginner
688 
689    Concepts: options database^has int
690 
691    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
692 
693 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
694           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
695           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
696           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
697           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
698           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
699           PetscOptionsList(), PetscOptionsEList()
700 @*/
701 PetscErrorCode PETSC_DLLEXPORT PetscOptionsScalar(const char opt[],const char text[],const char man[],PetscScalar defaultv,PetscScalar *value,PetscTruth *set)
702 {
703   PetscErrorCode ierr;
704 
705   PetscFunctionBegin;
706 #if !defined(PETSC_USE_COMPLEX)
707   ierr = PetscOptionsReal(opt,text,man,defaultv,value,set);CHKERRQ(ierr);
708 #else
709   ierr = PetscOptionsGetScalar(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
710 #endif
711   PetscFunctionReturn(0);
712 }
713 
714 #undef __FUNCT__
715 #define __FUNCT__ "PetscOptionsName"
716 /*@C
717    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
718                       its value is set to false.
719 
720    Collective on the communicator passed in PetscOptionsBegin()
721 
722    Input Parameters:
723 +  opt - option name
724 .  text - short string that describes the option
725 -  man - manual page with additional information on option
726 
727    Output Parameter:
728 .  flg - PETSC_TRUE if found, else PETSC_FALSE
729 
730    Level: beginner
731 
732    Concepts: options database^has int
733 
734    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
735 
736 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
737           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
738           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
739           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
740           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
741           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
742           PetscOptionsList(), PetscOptionsEList()
743 @*/
744 PetscErrorCode PETSC_DLLEXPORT PetscOptionsName(const char opt[],const char text[],const char man[],PetscTruth *flg)
745 {
746   PetscErrorCode ierr;
747 
748   PetscFunctionBegin;
749   ierr = PetscOptionsHasName(PetscOptionsObject.prefix,opt,flg);CHKERRQ(ierr);
750   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
751     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr);
752   }
753   PetscFunctionReturn(0);
754 }
755 
756 #undef __FUNCT__
757 #define __FUNCT__ "PetscOptionsList"
758 /*@C
759      PetscOptionsList - Puts a list of option values that a single one may be selected from
760 
761    Collective on the communicator passed in PetscOptionsBegin()
762 
763    Input Parameters:
764 +  opt - option name
765 .  text - short string that describes the option
766 .  man - manual page with additional information on option
767 .  list - the possible choices
768 .  defaultv - the default (current) value
769 -  len - the length of the character array value
770 
771    Output Parameter:
772 +  value - the value to return
773 -  set - PETSC_TRUE if found, else PETSC_FALSE
774 
775    Level: intermediate
776 
777    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
778 
779    See PetscOptionsEList() for when the choices are given in a string array
780 
781    To get a listing of all currently specified options,
782     see PetscOptionsPrint() or PetscOptionsGetAll()
783 
784    Concepts: options database^list
785 
786 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
787            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
788           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
789           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
790           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
791           PetscOptionsList(), PetscOptionsEList()
792 @*/
793 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)
794 {
795   PetscErrorCode ierr;
796   PetscOptions   amsopt;
797 
798   PetscFunctionBegin;
799   if (!PetscOptionsPublishCount) {
800     ierr = PetscOptionsCreate_Private(opt,ltext,man,OPTION_LIST,&amsopt);CHKERRQ(ierr);
801     ierr = PetscMalloc(1024*sizeof(char),&amsopt->data);CHKERRQ(ierr);
802     ierr = PetscStrcpy((char*)amsopt->data,defaultv);CHKERRQ(ierr);
803     amsopt->flist = list;
804   }
805   ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr);
806   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
807     ierr = PetscFListPrintTypes(PetscOptionsObject.comm,stdout,PetscOptionsObject.prefix,opt,ltext,man,list,defaultv);CHKERRQ(ierr);CHKERRQ(ierr);
808   }
809   PetscFunctionReturn(0);
810 }
811 
812 #undef __FUNCT__
813 #define __FUNCT__ "PetscOptionsEList"
814 /*@C
815      PetscOptionsEList - Puts a list of option values that a single one may be selected from
816 
817    Collective on the communicator passed in PetscOptionsBegin()
818 
819    Input Parameters:
820 +  opt - option name
821 .  ltext - short string that describes the option
822 .  man - manual page with additional information on option
823 .  list - the possible choices
824 .  ntext - number of choices
825 -  defaultv - the default (current) value
826 
827    Output Parameter:
828 +  value - the index of the value to return
829 -  set - PETSC_TRUE if found, else PETSC_FALSE
830 
831    Level: intermediate
832 
833    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
834 
835    See PetscOptionsList() for when the choices are given in a PetscFList()
836 
837    Concepts: options database^list
838 
839 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
840            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
841           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
842           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
843           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
844           PetscOptionsList(), PetscOptionsEList()
845 @*/
846 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)
847 {
848   PetscErrorCode ierr;
849   PetscInt       i;
850 
851   PetscFunctionBegin;
852   ierr = PetscOptionsGetEList(PetscOptionsObject.prefix,opt,list,ntext,value,set);CHKERRQ(ierr);
853   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
854     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%s> (choose one of)",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv);CHKERRQ(ierr);
855     for (i=0; i<ntext; i++){
856       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," %s",list[i]);CHKERRQ(ierr);
857     }
858     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"\n");CHKERRQ(ierr);
859   }
860   PetscFunctionReturn(0);
861 }
862 
863 #undef __FUNCT__
864 #define __FUNCT__ "PetscOptionsTruthGroupBegin"
865 /*@C
866      PetscOptionsTruthGroupBegin - First in a series of logical queries on the options database for
867        which only a single value can be true.
868 
869    Collective on the communicator passed in PetscOptionsBegin()
870 
871    Input Parameters:
872 +  opt - option name
873 .  text - short string that describes the option
874 -  man - manual page with additional information on option
875 
876    Output Parameter:
877 .  flg - whether that option was set or not
878 
879    Level: intermediate
880 
881    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
882 
883    Must be followed by 0 or more PetscOptionsTruthGroup()s and PetscOptionsTruthGroupEnd()
884 
885     Concepts: options database^logical group
886 
887 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
888            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
889           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
890           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
891           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
892           PetscOptionsList(), PetscOptionsEList()
893 @*/
894 PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroupBegin(const char opt[],const char text[],const char man[],PetscTruth *flg)
895 {
896   PetscErrorCode ierr;
897 
898   PetscFunctionBegin;
899   *flg = PETSC_FALSE;
900   ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr);
901   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
902     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  Pick at most one of -------------\n");CHKERRQ(ierr);
903     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr);
904   }
905   PetscFunctionReturn(0);
906 }
907 
908 #undef __FUNCT__
909 #define __FUNCT__ "PetscOptionsTruthGroup"
910 /*@C
911      PetscOptionsTruthGroup - One in a series of logical queries on the options database for
912        which only a single value can be true.
913 
914    Collective on the communicator passed in PetscOptionsBegin()
915 
916    Input Parameters:
917 +  opt - option name
918 .  text - short string that describes the option
919 -  man - manual page with additional information on option
920 
921    Output Parameter:
922 .  flg - PETSC_TRUE if found, else PETSC_FALSE
923 
924    Level: intermediate
925 
926    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
927 
928    Must follow a PetscOptionsTruthGroupBegin() and preceded a PetscOptionsTruthGroupEnd()
929 
930     Concepts: options database^logical group
931 
932 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
933            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
934           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
935           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
936           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
937           PetscOptionsList(), PetscOptionsEList()
938 @*/
939 PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroup(const char opt[],const char text[],const char man[],PetscTruth *flg)
940 {
941   PetscErrorCode ierr;
942 
943   PetscFunctionBegin;
944   *flg = PETSC_FALSE;
945   ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr);
946   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
947     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr);
948   }
949   PetscFunctionReturn(0);
950 }
951 
952 #undef __FUNCT__
953 #define __FUNCT__ "PetscOptionsTruthGroupEnd"
954 /*@C
955      PetscOptionsTruthGroupEnd - Last in a series of logical queries on the options database for
956        which only a single value can be true.
957 
958    Collective on the communicator passed in PetscOptionsBegin()
959 
960    Input Parameters:
961 +  opt - option name
962 .  text - short string that describes the option
963 -  man - manual page with additional information on option
964 
965    Output Parameter:
966 .  flg - PETSC_TRUE if found, else PETSC_FALSE
967 
968    Level: intermediate
969 
970    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
971 
972    Must follow a PetscOptionsTruthGroupBegin()
973 
974     Concepts: options database^logical group
975 
976 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
977            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
978           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
979           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
980           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
981           PetscOptionsList(), PetscOptionsEList()
982 @*/
983 PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroupEnd(const char opt[],const char text[],const char man[],PetscTruth *flg)
984 {
985   PetscErrorCode ierr;
986 
987   PetscFunctionBegin;
988   *flg = PETSC_FALSE;
989   ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr);
990   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
991     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr);
992   }
993   PetscFunctionReturn(0);
994 }
995 
996 #undef __FUNCT__
997 #define __FUNCT__ "PetscOptionsTruth"
998 /*@C
999    PetscOptionsTruth - Determines if a particular option is in the database with a true or false
1000 
1001    Collective on the communicator passed in PetscOptionsBegin()
1002 
1003    Input Parameters:
1004 +  opt - option name
1005 .  text - short string that describes the option
1006 -  man - manual page with additional information on option
1007 
1008    Output Parameter:
1009 .  flg - PETSC_TRUE or PETSC_FALSE
1010 .  set - PETSC_TRUE if found, else PETSC_FALSE
1011 
1012    Level: beginner
1013 
1014    Concepts: options database^logical
1015 
1016    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1017 
1018 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
1019           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
1020           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
1021           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1022           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1023           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
1024           PetscOptionsList(), PetscOptionsEList()
1025 @*/
1026 PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruth(const char opt[],const char text[],const char man[],PetscTruth deflt,PetscTruth *flg,PetscTruth *set)
1027 {
1028   PetscErrorCode ierr;
1029   PetscTruth     iset;
1030   PetscOptions   amsopt;
1031 
1032   PetscFunctionBegin;
1033   if (!PetscOptionsPublishCount) {
1034     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
1035     ierr = PetscMalloc(16*sizeof(char),&amsopt->data);CHKERRQ(ierr);
1036     ierr = PetscStrcpy((char*)amsopt->data,deflt ? "true" : "false");CHKERRQ(ierr);
1037   }
1038   ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,&iset);CHKERRQ(ierr);
1039   if (!iset) {
1040     if (flg) *flg = deflt;
1041   }
1042   if (set) *set = iset;
1043   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1044     const char *v = PetscTruths[deflt];
1045     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s: <%s> %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,v,text,man);CHKERRQ(ierr);
1046   }
1047   PetscFunctionReturn(0);
1048 }
1049 
1050 #undef __FUNCT__
1051 #define __FUNCT__ "PetscOptionsRealArray"
1052 /*@C
1053    PetscOptionsRealArray - Gets an array of double values for a particular
1054    option in the database. The values must be separated with commas with
1055    no intervening spaces.
1056 
1057    Collective on the communicator passed in PetscOptionsBegin()
1058 
1059    Input Parameters:
1060 +  opt - the option one is seeking
1061 .  text - short string describing option
1062 .  man - manual page for option
1063 -  nmax - maximum number of values
1064 
1065    Output Parameter:
1066 +  value - location to copy values
1067 .  nmax - actual number of values found
1068 -  set - PETSC_TRUE if found, else PETSC_FALSE
1069 
1070    Level: beginner
1071 
1072    Notes:
1073    The user should pass in an array of doubles
1074 
1075    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1076 
1077    Concepts: options database^array of strings
1078 
1079 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1080            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
1081           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1082           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1083           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
1084           PetscOptionsList(), PetscOptionsEList()
1085 @*/
1086 PetscErrorCode PETSC_DLLEXPORT PetscOptionsRealArray(const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscTruth *set)
1087 {
1088   PetscErrorCode ierr;
1089   PetscInt       i;
1090   PetscOptions   amsopt;
1091 
1092   PetscFunctionBegin;
1093   if (!PetscOptionsPublishCount) {
1094     PetscReal *vals;
1095 
1096     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_REAL_ARRAY,&amsopt);CHKERRQ(ierr);
1097     ierr = PetscMalloc((*n)*sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr);
1098     vals = (PetscReal*)amsopt->data;
1099     for (i=0; i<*n; i++) vals[i] = value[i];
1100     amsopt->arraylength = *n;
1101   }
1102   ierr = PetscOptionsGetRealArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr);
1103   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1104     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%G",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr);
1105     for (i=1; i<*n; i++) {
1106       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%G",value[i]);CHKERRQ(ierr);
1107     }
1108     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,man);CHKERRQ(ierr);
1109   }
1110   PetscFunctionReturn(0);
1111 }
1112 
1113 
1114 #undef __FUNCT__
1115 #define __FUNCT__ "PetscOptionsIntArray"
1116 /*@C
1117    PetscOptionsIntArray - Gets an array of integers for a particular
1118    option in the database. The values must be separated with commas with
1119    no intervening spaces.
1120 
1121    Collective on the communicator passed in PetscOptionsBegin()
1122 
1123    Input Parameters:
1124 +  opt - the option one is seeking
1125 .  text - short string describing option
1126 .  man - manual page for option
1127 -  n - maximum number of values
1128 
1129    Output Parameter:
1130 +  value - location to copy values
1131 .  n - actual number of values found
1132 -  set - PETSC_TRUE if found, else PETSC_FALSE
1133 
1134    Level: beginner
1135 
1136    Notes:
1137    The user should pass in an array of integers
1138 
1139    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1140 
1141    Concepts: options database^array of strings
1142 
1143 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1144            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
1145           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1146           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1147           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
1148           PetscOptionsList(), PetscOptionsEList(), PetscOptionsRealArray()
1149 @*/
1150 PetscErrorCode PETSC_DLLEXPORT PetscOptionsIntArray(const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscTruth *set)
1151 {
1152   PetscErrorCode ierr;
1153   PetscInt       i;
1154   PetscOptions   amsopt;
1155 
1156   PetscFunctionBegin;
1157   if (!PetscOptionsPublishCount) {
1158     PetscInt *vals;
1159 
1160     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_INT_ARRAY,&amsopt);CHKERRQ(ierr);
1161     ierr = PetscMalloc((*n)*sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr);
1162     vals = (PetscInt*)amsopt->data;
1163     for (i=0; i<*n; i++) vals[i] = value[i];
1164     amsopt->arraylength = *n;
1165   }
1166   ierr = PetscOptionsGetIntArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr);
1167   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1168     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%d",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr);
1169     for (i=1; i<*n; i++) {
1170       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr);
1171     }
1172     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,man);CHKERRQ(ierr);
1173   }
1174   PetscFunctionReturn(0);
1175 }
1176 
1177 #undef __FUNCT__
1178 #define __FUNCT__ "PetscOptionsStringArray"
1179 /*@C
1180    PetscOptionsStringArray - Gets an array of string values for a particular
1181    option in the database. The values must be separated with commas with
1182    no intervening spaces.
1183 
1184    Collective on the communicator passed in PetscOptionsBegin()
1185 
1186    Input Parameters:
1187 +  opt - the option one is seeking
1188 .  text - short string describing option
1189 .  man - manual page for option
1190 -  nmax - maximum number of strings
1191 
1192    Output Parameter:
1193 +  value - location to copy strings
1194 .  nmax - actual number of strings found
1195 -  set - PETSC_TRUE if found, else PETSC_FALSE
1196 
1197    Level: beginner
1198 
1199    Notes:
1200    The user should pass in an array of pointers to char, to hold all the
1201    strings returned by this function.
1202 
1203    The user is responsible for deallocating the strings that are
1204    returned. The Fortran interface for this routine is not supported.
1205 
1206    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1207 
1208    Concepts: options database^array of strings
1209 
1210 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1211            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
1212           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1213           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1214           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
1215           PetscOptionsList(), PetscOptionsEList()
1216 @*/
1217 PetscErrorCode PETSC_DLLEXPORT PetscOptionsStringArray(const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscTruth *set)
1218 {
1219   PetscErrorCode ierr;
1220 
1221   PetscFunctionBegin;
1222   ierr = PetscOptionsGetStringArray(PetscOptionsObject.prefix,opt,value,nmax,set);CHKERRQ(ierr);
1223   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1224     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <string1,string2,...>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr);
1225   }
1226   PetscFunctionReturn(0);
1227 }
1228 
1229 #undef __FUNCT__
1230 #define __FUNCT__ "PetscOptionsTruthArray"
1231 /*@C
1232    PetscOptionsTruthArray - Gets an array of logical values (true or false) for a particular
1233    option in the database. The values must be separated with commas with
1234    no intervening spaces.
1235 
1236    Collective on the communicator passed in PetscOptionsBegin()
1237 
1238    Input Parameters:
1239 +  opt - the option one is seeking
1240 .  text - short string describing option
1241 .  man - manual page for option
1242 -  nmax - maximum number of values
1243 
1244    Output Parameter:
1245 +  value - location to copy values
1246 .  nmax - actual number of values found
1247 -  set - PETSC_TRUE if found, else PETSC_FALSE
1248 
1249    Level: beginner
1250 
1251    Notes:
1252    The user should pass in an array of doubles
1253 
1254    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1255 
1256    Concepts: options database^array of strings
1257 
1258 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1259            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
1260           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1261           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1262           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
1263           PetscOptionsList(), PetscOptionsEList()
1264 @*/
1265 PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthArray(const char opt[],const char text[],const char man[],PetscTruth value[],PetscInt *n,PetscTruth *set)
1266 {
1267   PetscErrorCode ierr;
1268   PetscInt       i;
1269 
1270   PetscFunctionBegin;
1271   ierr = PetscOptionsGetTruthArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr);
1272   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1273     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%d",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr);
1274     for (i=1; i<*n; i++) {
1275       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr);
1276     }
1277     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,man);CHKERRQ(ierr);
1278   }
1279   PetscFunctionReturn(0);
1280 }
1281 
1282 
1283 #undef __FUNCT__
1284 #define __FUNCT__ "PetscOptionsHead"
1285 /*@C
1286      PetscOptionsHead - Puts a heading before listing any more published options. Used, for example,
1287             in KSPSetFromOptions_GMRES().
1288 
1289    Collective on the communicator passed in PetscOptionsBegin()
1290 
1291    Input Parameter:
1292 .   head - the heading text
1293 
1294 
1295    Level: intermediate
1296 
1297    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1298 
1299           Can be followed by a call to PetscOptionsTail() in the same function.
1300 
1301    Concepts: options database^subheading
1302 
1303 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1304            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
1305           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1306           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1307           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
1308           PetscOptionsList(), PetscOptionsEList()
1309 @*/
1310 PetscErrorCode PETSC_DLLEXPORT PetscOptionsHead(const char head[])
1311 {
1312   PetscErrorCode ierr;
1313 
1314   PetscFunctionBegin;
1315   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1316     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  %s\n",head);CHKERRQ(ierr);
1317   }
1318   PetscFunctionReturn(0);
1319 }
1320 
1321 
1322 
1323 
1324 
1325 
1326