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