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