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