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