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