xref: /petsc/src/sys/objects/aoptions.c (revision 77070f38be97ee027c72f2be8d844d65b3f2cef5)
1 #define PETSC_DLL
2 /*
3    These routines simplify the use of command line, file options, etc.,
4    and are used to manipulate the options database.
5 
6   This file uses regular malloc and free because it cannot know
7   what malloc is being used until it has already processed the input.
8 */
9 
10 #include "petsc.h"        /*I  "petsc.h"   I*/
11 #include "petscsys.h"
12 #if defined(PETSC_HAVE_STDLIB_H)
13 #include <stdlib.h>
14 #endif
15 
16 /*
17     Keep a linked list of options that have been posted and we are waiting for
18    user selection
19 
20     Eventually we'll attach this beast to a MPI_Comm
21 */
22 typedef enum {OPTION_INT,OPTION_LOGICAL,OPTION_REAL,OPTION_LIST,OPTION_STRING,OPTION_REAL_ARRAY,OPTION_HEAD} OptionType;
23 typedef struct _p_Options* PetscOptions;
24 struct _p_Options {
25   char         *option;
26   char         *text;
27   void         *data;
28   void         *edata;
29   int          arraylength;
30   PetscTruth   set;
31   OptionType   type;
32   PetscOptions next;
33   char         *man;
34 };
35 
36 static struct {
37   PetscOptions    next;
38   char            *prefix,*mprefix;
39   char            *title;
40   MPI_Comm        comm;
41   PetscTruth      printhelp;
42 }                                   PetscOptionsObject;
43 PetscInt                            PetscOptionsPublishCount = 0;
44 
45 #undef __FUNCT__
46 #define __FUNCT__ "PetscOptionsBegin_Private"
47 /*
48     Handles setting up the data structure in a call to PetscOptionsBegin()
49 */
50 PetscErrorCode PetscOptionsBegin_Private(MPI_Comm comm,const char prefix[],const char title[],const char mansec[])
51 {
52   PetscErrorCode ierr;
53 
54   PetscFunctionBegin;
55   PetscOptionsObject.next = 0;
56   PetscOptionsObject.comm  = comm;
57   ierr = PetscStrallocpy(prefix,&PetscOptionsObject.prefix);CHKERRQ(ierr);
58   ierr = PetscStrallocpy(title,&PetscOptionsObject.title);CHKERRQ(ierr);
59 
60   ierr = PetscOptionsHasName(PETSC_NULL,"-help",&PetscOptionsObject.printhelp);CHKERRQ(ierr);
61   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) {
62     ierr = (*PetscHelpPrintf)(comm,"%s -------------------------------------------------\n",title);CHKERRQ(ierr);
63   }
64   PetscFunctionReturn(0);
65 }
66 
67 /*
68      Handles adding another option to the list of options within this particular PetscOptionsBegin() PetscOptionsEnd()
69 */
70 #undef __FUNCT__
71 #define __FUNCT__ "PetscOptionsCreate_Private"
72 static int PetscOptionsCreate_Private(const char opt[],const char text[],const char man[],PetscOptions *amsopt)
73 {
74   int          ierr;
75   PetscOptions next;
76 
77   PetscFunctionBegin;
78   ierr             = PetscNew(struct _p_Options,amsopt);CHKERRQ(ierr);
79   (*amsopt)->next  = 0;
80   (*amsopt)->set   = PETSC_FALSE;
81   (*amsopt)->data  = 0;
82   (*amsopt)->edata = 0;
83   ierr             = PetscStrallocpy(text,&(*amsopt)->text);CHKERRQ(ierr);
84   ierr             = PetscStrallocpy(opt,&(*amsopt)->option);CHKERRQ(ierr);
85   ierr             = PetscStrallocpy(opt,&(*amsopt)->man);CHKERRQ(ierr);
86 
87   if (!PetscOptionsObject.next) {
88     PetscOptionsObject.next = *amsopt;
89   } else {
90     next = PetscOptionsObject.next;
91     while (next->next) next = next->next;
92     next->next = *amsopt;
93   }
94   PetscFunctionReturn(0);
95 }
96 
97 #undef __FUNCT__
98 #define __FUNCT__ "PetscOptionsEnd_Private"
99 PetscErrorCode PetscOptionsEnd_Private(void)
100 {
101   PetscErrorCode ierr;
102 
103   PetscFunctionBegin;
104   ierr = PetscStrfree(PetscOptionsObject.title);CHKERRQ(ierr); PetscOptionsObject.title  = 0;
105   ierr = PetscStrfree(PetscOptionsObject.prefix);CHKERRQ(ierr); PetscOptionsObject.prefix = 0;
106   PetscFunctionReturn(0);
107 }
108 
109 #undef __FUNCT__
110 #define __FUNCT__ "PetscOptionsEnum"
111 /*@C
112    PetscOptionsEnum - Gets the enum value for a particular option in the database.
113 
114    Collective on the communicator passed in PetscOptionsBegin()
115 
116    Input Parameters:
117 +  opt - option name
118 .  text - short string that describes the option
119 .  man - manual page with additional information on option
120 .  list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null
121 -  defaultv - the default (current) value
122 
123    Output Parameter:
124 +  value - the  value to return
125 -  flg - PETSC_TRUE if found, else PETSC_FALSE
126 
127    Level: beginner
128 
129    Concepts: options database
130 
131    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
132 
133           list is usually something like PCASMTypes or some other predefined list of enum names
134 
135 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
136           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
137           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
138           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
139           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
140           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
141           PetscOptionsList(), PetscOptionsEList()
142 @*/
143 PetscErrorCode PETSC_DLLEXPORT PetscOptionsEnum(const char opt[],const char text[],const char man[],const char **list,PetscEnum defaultv,PetscEnum *value,PetscTruth *set)
144 {
145   PetscErrorCode ierr;
146   PetscInt       ntext = 0;
147 
148   PetscFunctionBegin;
149   while (list[ntext++]) {
150     if (ntext > 50) SETERRQ(PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries");
151   }
152   if (ntext < 3) SETERRQ(PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix");
153   ntext -= 3;
154   ierr = PetscOptionsEList(opt,text,man,list,ntext,list[defaultv],(PetscInt*)value,set);CHKERRQ(ierr);
155   PetscFunctionReturn(0);
156 }
157 
158 /* -------------------------------------------------------------------------------------------------------------*/
159 #undef __FUNCT__
160 #define __FUNCT__ "PetscOptionsInt"
161 /*@C
162    PetscOptionsInt - Gets the integer value for a particular option in the database.
163 
164    Collective on the communicator passed in PetscOptionsBegin()
165 
166    Input Parameters:
167 +  opt - option name
168 .  text - short string that describes the option
169 .  man - manual page with additional information on option
170 -  defaultv - the default (current) value
171 
172    Output Parameter:
173 +  value - the integer value to return
174 -  flg - PETSC_TRUE if found, else PETSC_FALSE
175 
176    Level: beginner
177 
178    Concepts: options database^has int
179 
180    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
181 
182 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
183           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
184           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
185           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
186           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
187           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
188           PetscOptionsList(), PetscOptionsEList()
189 @*/
190 PetscErrorCode PETSC_DLLEXPORT PetscOptionsInt(const char opt[],const char text[],const char man[],PetscInt defaultv,PetscInt *value,PetscTruth *set)
191 {
192   PetscErrorCode ierr;
193 
194   PetscFunctionBegin;
195   ierr = PetscOptionsGetInt(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
196   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) {
197     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%d>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,man);CHKERRQ(ierr);
198   }
199   PetscFunctionReturn(0);
200 }
201 
202 #undef __FUNCT__
203 #define __FUNCT__ "PetscOptionsString"
204 /*@C
205    PetscOptionsString - Gets the string value for a particular option in the database.
206 
207    Collective on the communicator passed in PetscOptionsBegin()
208 
209    Input Parameters:
210 +  opt - option name
211 .  text - short string that describes the option
212 .  man - manual page with additional information on option
213 -  defaultv - the default (current) value
214 
215    Output Parameter:
216 +  value - the value to return
217 -  flg - PETSC_TRUE if found, else PETSC_FALSE
218 
219    Level: beginner
220 
221    Concepts: options database^has int
222 
223    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
224 
225 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
226           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
227           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
228           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
229           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
230           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
231           PetscOptionsList(), PetscOptionsEList()
232 @*/
233 PetscErrorCode PETSC_DLLEXPORT PetscOptionsString(const char opt[],const char text[],const char man[],const char defaultv[],char value[],size_t len,PetscTruth *set)
234 {
235   PetscErrorCode ierr;
236 
237   PetscFunctionBegin;
238   ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr);
239   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) {
240     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%s>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,man);CHKERRQ(ierr);
241   }
242   PetscFunctionReturn(0);
243 }
244 
245 /*
246      Publishes an AMS double field (with the default value in it) and with a name
247    given by the text string
248 */
249 #undef __FUNCT__
250 #define __FUNCT__ "PetscOptionsReal"
251 /*@C
252    PetscOptionsReal - Gets the PetscReal value for a particular option in the database.
253 
254    Collective on the communicator passed in PetscOptionsBegin()
255 
256    Input Parameters:
257 +  opt - option name
258 .  text - short string that describes the option
259 .  man - manual page with additional information on option
260 -  defaultv - the default (current) value
261 
262    Output Parameter:
263 +  value - the value to return
264 -  flg - PETSC_TRUE if found, else PETSC_FALSE
265 
266    Level: beginner
267 
268    Concepts: options database^has int
269 
270    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
271 
272 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
273           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
274           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
275           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
276           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
277           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
278           PetscOptionsList(), PetscOptionsEList()
279 @*/
280 PetscErrorCode PETSC_DLLEXPORT PetscOptionsReal(const char opt[],const char text[],const char man[],PetscReal defaultv,PetscReal *value,PetscTruth *set)
281 {
282   PetscErrorCode ierr;
283 
284   PetscFunctionBegin;
285   ierr = PetscOptionsGetReal(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
286   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) {
287     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%g>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,man);CHKERRQ(ierr);
288   }
289   PetscFunctionReturn(0);
290 }
291 
292 #undef __FUNCT__
293 #define __FUNCT__ "PetscOptionsScalar"
294 /*@C
295    PetscOptionsScalar - Gets the scalar value for a particular option in the database.
296 
297    Collective on the communicator passed in PetscOptionsBegin()
298 
299    Input Parameters:
300 +  opt - option name
301 .  text - short string that describes the option
302 .  man - manual page with additional information on option
303 -  defaultv - the default (current) value
304 
305    Output Parameter:
306 +  value - the value to return
307 -  flg - PETSC_TRUE if found, else PETSC_FALSE
308 
309    Level: beginner
310 
311    Concepts: options database^has int
312 
313    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
314 
315 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
316           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
317           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
318           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
319           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
320           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
321           PetscOptionsList(), PetscOptionsEList()
322 @*/
323 PetscErrorCode PETSC_DLLEXPORT PetscOptionsScalar(const char opt[],const char text[],const char man[],PetscScalar defaultv,PetscScalar *value,PetscTruth *set)
324 {
325   PetscErrorCode ierr;
326 
327   PetscFunctionBegin;
328 #if !defined(PETSC_USE_COMPLEX)
329   ierr = PetscOptionsReal(opt,text,man,defaultv,value,set);CHKERRQ(ierr);
330 #else
331   ierr = PetscOptionsGetScalar(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
332 #endif
333   PetscFunctionReturn(0);
334 }
335 
336 /*
337      Publishes an AMS logical field (with the default value in it) and with a name
338    given by the text string
339 */
340 #undef __FUNCT__
341 #define __FUNCT__ "PetscOptionsName"
342 /*@C
343    PetscOptionsName - Determines if a particular option is in the database
344 
345    Collective on the communicator passed in PetscOptionsBegin()
346 
347    Input Parameters:
348 +  opt - option name
349 .  text - short string that describes the option
350 -  man - manual page with additional information on option
351 
352    Output Parameter:
353 .  flg - PETSC_TRUE if found, else PETSC_FALSE
354 
355    Level: beginner
356 
357    Concepts: options database^has int
358 
359    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
360 
361 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
362           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
363           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
364           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
365           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
366           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
367           PetscOptionsList(), PetscOptionsEList()
368 @*/
369 PetscErrorCode PETSC_DLLEXPORT PetscOptionsName(const char opt[],const char text[],const char man[],PetscTruth *flg)
370 {
371   PetscErrorCode ierr;
372 
373   PetscFunctionBegin;
374   ierr = PetscOptionsHasName(PetscOptionsObject.prefix,opt,flg);CHKERRQ(ierr);
375   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) {
376     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr);
377   }
378   PetscFunctionReturn(0);
379 }
380 
381 #undef __FUNCT__
382 #define __FUNCT__ "PetscOptionsList"
383 /*@C
384      PetscOptionsList - Puts a list of option values that a single one may be selected from
385 
386    Collective on the communicator passed in PetscOptionsBegin()
387 
388    Input Parameters:
389 +  opt - option name
390 .  text - short string that describes the option
391 .  man - manual page with additional information on option
392 .  list - the possible choices
393 -  defaultv - the default (current) value
394 
395    Output Parameter:
396 +  value - the value to return
397 -  set - PETSC_TRUE if found, else PETSC_FALSE
398 
399    Level: intermediate
400 
401    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
402 
403    See PetscOptionsEList() for when the choices are given in a string array
404 
405    To get a listing of all currently specified options,
406     see PetscOptionsPrint() or PetscOptionsGetAll()
407 
408    Concepts: options database^list
409 
410 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
411            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
412           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
413           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
414           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
415           PetscOptionsList(), PetscOptionsEList()
416 @*/
417 PetscErrorCode PETSC_DLLEXPORT PetscOptionsList(const char opt[],const char ltext[],const char man[],PetscFList list,const char defaultv[],char value[],PetscInt len,PetscTruth *set)
418 {
419   PetscErrorCode ierr;
420 
421   PetscFunctionBegin;
422   ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr);
423   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) {
424     ierr = PetscFListPrintTypes(PetscOptionsObject.comm,stdout,PetscOptionsObject.prefix,opt,ltext,man,list);CHKERRQ(ierr);CHKERRQ(ierr);
425   }
426   PetscFunctionReturn(0);
427 }
428 
429 #undef __FUNCT__
430 #define __FUNCT__ "PetscOptionsEList"
431 /*@C
432      PetscOptionsEList - Puts a list of option values that a single one may be selected from
433 
434    Collective on the communicator passed in PetscOptionsBegin()
435 
436    Input Parameters:
437 +  opt - option name
438 .  ltext - short string that describes the option
439 .  man - manual page with additional information on option
440 .  list - the possible choices
441 .  ntext - number of choices
442 -  defaultv - the default (current) value
443 
444    Output Parameter:
445 +  value - the index of the value to return
446 -  set - PETSC_TRUE if found, else PETSC_FALSE
447 
448    Level: intermediate
449 
450    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
451 
452    See PetscOptionsList() for when the choices are given in a PetscFList()
453 
454    Concepts: options database^list
455 
456 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
457            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
458           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
459           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
460           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
461           PetscOptionsList(), PetscOptionsEList()
462 @*/
463 PetscErrorCode PETSC_DLLEXPORT PetscOptionsEList(const char opt[],const char ltext[],const char man[],const char **list,PetscInt ntext,const char defaultv[],PetscInt *value,PetscTruth *set)
464 {
465   PetscErrorCode ierr;
466   PetscInt       i;
467 
468   PetscFunctionBegin;
469   ierr = PetscOptionsGetEList(PetscOptionsObject.prefix,opt,list,ntext,value,set);CHKERRQ(ierr);
470   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) {
471     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%s> (choose one of)",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv);CHKERRQ(ierr);
472     for (i=0; i<ntext; i++){
473       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," %s",list[i]);CHKERRQ(ierr);
474     }
475     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"\n");CHKERRQ(ierr);
476   }
477   PetscFunctionReturn(0);
478 }
479 
480 #undef __FUNCT__
481 #define __FUNCT__ "PetscOptionsTruthGroupBegin"
482 /*@C
483      PetscOptionsTruthGroupBegin - First in a series of logical queries on the options database for
484        which only a single value can be true.
485 
486    Collective on the communicator passed in PetscOptionsBegin()
487 
488    Input Parameters:
489 +  opt - option name
490 .  text - short string that describes the option
491 -  man - manual page with additional information on option
492 
493    Output Parameter:
494 .  flg - whether that option was set or not
495 
496    Level: intermediate
497 
498    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
499 
500    Must be followed by 0 or more PetscOptionsTruthGroup()s and PetscOptionsTruthGroupEnd()
501 
502     Concepts: options database^logical group
503 
504 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
505            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
506           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
507           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
508           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
509           PetscOptionsList(), PetscOptionsEList()
510 @*/
511 PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroupBegin(const char opt[],const char text[],const char man[],PetscTruth *flg)
512 {
513   PetscErrorCode ierr;
514 
515   PetscFunctionBegin;
516   ierr = PetscOptionsHasName(PetscOptionsObject.prefix,opt,flg);CHKERRQ(ierr);
517   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) {
518     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  Pick at most one of -------------\n");CHKERRQ(ierr);
519     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr);
520   }
521   PetscFunctionReturn(0);
522 }
523 
524 #undef __FUNCT__
525 #define __FUNCT__ "PetscOptionsTruthGroup"
526 /*@C
527      PetscOptionsTruthGroup - One in a series of logical queries on the options database for
528        which only a single value can be true.
529 
530    Collective on the communicator passed in PetscOptionsBegin()
531 
532    Input Parameters:
533 +  opt - option name
534 .  text - short string that describes the option
535 -  man - manual page with additional information on option
536 
537    Output Parameter:
538 .  flg - PETSC_TRUE if found, else PETSC_FALSE
539 
540    Level: intermediate
541 
542    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
543 
544    Must follow a PetscOptionsTruthGroupBegin() and preceded a PetscOptionsTruthGroupEnd()
545 
546     Concepts: options database^logical group
547 
548 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
549            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
550           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
551           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
552           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
553           PetscOptionsList(), PetscOptionsEList()
554 @*/
555 PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroup(const char opt[],const char text[],const char man[],PetscTruth *flg)
556 {
557   PetscErrorCode ierr;
558 
559   PetscFunctionBegin;
560   ierr = PetscOptionsHasName(PetscOptionsObject.prefix,opt,flg);CHKERRQ(ierr);
561   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) {
562     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr);
563   }
564   PetscFunctionReturn(0);
565 }
566 
567 #undef __FUNCT__
568 #define __FUNCT__ "PetscOptionsTruthGroupEnd"
569 /*@C
570      PetscOptionsTruthGroupEnd - Last in a series of logical queries on the options database for
571        which only a single value can be true.
572 
573    Collective on the communicator passed in PetscOptionsBegin()
574 
575    Input Parameters:
576 +  opt - option name
577 .  text - short string that describes the option
578 -  man - manual page with additional information on option
579 
580    Output Parameter:
581 .  flg - PETSC_TRUE if found, else PETSC_FALSE
582 
583    Level: intermediate
584 
585    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
586 
587    Must follow a PetscOptionsTruthGroupBegin()
588 
589     Concepts: options database^logical group
590 
591 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
592            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
593           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
594           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
595           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
596           PetscOptionsList(), PetscOptionsEList()
597 @*/
598 PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroupEnd(const char opt[],const char text[],const char man[],PetscTruth *flg)
599 {
600   PetscErrorCode ierr;
601 
602   PetscFunctionBegin;
603   ierr = PetscOptionsHasName(PetscOptionsObject.prefix,opt,flg);CHKERRQ(ierr);
604   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) {
605     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr);
606   }
607   PetscFunctionReturn(0);
608 }
609 
610 #undef __FUNCT__
611 #define __FUNCT__ "PetscOptionsTruth"
612 /*@C
613    PetscOptionsTruth - Determines if a particular option is in the database with a true or false
614 
615    Collective on the communicator passed in PetscOptionsBegin()
616 
617    Input Parameters:
618 +  opt - option name
619 .  text - short string that describes the option
620 -  man - manual page with additional information on option
621 
622    Output Parameter:
623 .  flg - PETSC_TRUE or PETSC_FALSE
624 .  set - PETSC_TRUE if found, else PETSC_FALSE
625 
626    Level: beginner
627 
628    Concepts: options database^logical
629 
630    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
631 
632 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
633           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
634           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
635           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
636           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
637           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
638           PetscOptionsList(), PetscOptionsEList()
639 @*/
640 PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruth(const char opt[],const char text[],const char man[],PetscTruth deflt,PetscTruth *flg,PetscTruth *set)
641 {
642   PetscErrorCode ierr;
643   PetscTruth     iset;
644 
645   PetscFunctionBegin;
646   ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,&iset);CHKERRQ(ierr);
647   if (!iset) {
648     if (flg) *flg = deflt;
649   }
650   if (set) *set = iset;
651   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) {
652     const char *v = PetscTruths[deflt];
653     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s: <%s> %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,v,text,man);CHKERRQ(ierr);
654   }
655   PetscFunctionReturn(0);
656 }
657 
658 #undef __FUNCT__
659 #define __FUNCT__ "PetscOptionsRealArray"
660 /*@C
661    PetscOptionsRealArray - Gets an array of double values for a particular
662    option in the database. The values must be separated with commas with
663    no intervening spaces.
664 
665    Collective on the communicator passed in PetscOptionsBegin()
666 
667    Input Parameters:
668 +  opt - the option one is seeking
669 .  text - short string describing option
670 .  man - manual page for option
671 -  nmax - maximum number of values
672 
673    Output Parameter:
674 +  value - location to copy values
675 .  nmax - actual number of values found
676 -  set - PETSC_TRUE if found, else PETSC_FALSE
677 
678    Level: beginner
679 
680    Notes:
681    The user should pass in an array of doubles
682 
683    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
684 
685    Concepts: options database^array of strings
686 
687 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
688            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
689           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
690           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
691           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
692           PetscOptionsList(), PetscOptionsEList()
693 @*/
694 PetscErrorCode PETSC_DLLEXPORT PetscOptionsRealArray(const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscTruth *set)
695 {
696   PetscErrorCode ierr;
697   PetscInt       i;
698 
699   PetscFunctionBegin;
700   ierr = PetscOptionsGetRealArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr);
701   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) {
702     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%g",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr);
703     for (i=1; i<*n; i++) {
704       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%g",value[i]);CHKERRQ(ierr);
705     }
706     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,man);CHKERRQ(ierr);
707   }
708   PetscFunctionReturn(0);
709 }
710 
711 
712 #undef __FUNCT__
713 #define __FUNCT__ "PetscOptionsIntArray"
714 /*@C
715    PetscOptionsIntArray - Gets an array of integers for a particular
716    option in the database. The values must be separated with commas with
717    no intervening spaces.
718 
719    Collective on the communicator passed in PetscOptionsBegin()
720 
721    Input Parameters:
722 +  opt - the option one is seeking
723 .  text - short string describing option
724 .  man - manual page for option
725 -  nmax - maximum number of values
726 
727    Output Parameter:
728 +  value - location to copy values
729 .  nmax - actual number of values found
730 -  set - PETSC_TRUE if found, else PETSC_FALSE
731 
732    Level: beginner
733 
734    Notes:
735    The user should pass in an array of integers
736 
737    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
738 
739    Concepts: options database^array of strings
740 
741 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
742            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
743           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
744           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
745           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
746           PetscOptionsList(), PetscOptionsEList(), PetscOptionsRealArray()
747 @*/
748 PetscErrorCode PETSC_DLLEXPORT PetscOptionsIntArray(const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscTruth *set)
749 {
750   PetscErrorCode ierr;
751   PetscInt       i;
752 
753   PetscFunctionBegin;
754   ierr = PetscOptionsGetIntArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr);
755   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) {
756     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%d",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr);
757     for (i=1; i<*n; i++) {
758       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr);
759     }
760     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,man);CHKERRQ(ierr);
761   }
762   PetscFunctionReturn(0);
763 }
764 
765 #undef __FUNCT__
766 #define __FUNCT__ "PetscOptionsStringArray"
767 /*@C
768    PetscOptionsStringArray - Gets an array of string values for a particular
769    option in the database. The values must be separated with commas with
770    no intervening spaces.
771 
772    Collective on the communicator passed in PetscOptionsBegin()
773 
774    Input Parameters:
775 +  opt - the option one is seeking
776 .  text - short string describing option
777 .  man - manual page for option
778 -  nmax - maximum number of strings
779 
780    Output Parameter:
781 +  value - location to copy strings
782 .  nmax - actual number of strings found
783 -  set - PETSC_TRUE if found, else PETSC_FALSE
784 
785    Level: beginner
786 
787    Notes:
788    The user should pass in an array of pointers to char, to hold all the
789    strings returned by this function.
790 
791    The user is responsible for deallocating the strings that are
792    returned. The Fortran interface for this routine is not supported.
793 
794    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
795 
796    Concepts: options database^array of strings
797 
798 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
799            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
800           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
801           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
802           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
803           PetscOptionsList(), PetscOptionsEList()
804 @*/
805 PetscErrorCode PETSC_DLLEXPORT PetscOptionsStringArray(const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscTruth *set)
806 {
807   PetscErrorCode ierr;
808 
809   PetscFunctionBegin;
810   ierr = PetscOptionsGetStringArray(PetscOptionsObject.prefix,opt,value,nmax,set);CHKERRQ(ierr);
811   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) {
812     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <string1,string2,...>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr);
813   }
814   PetscFunctionReturn(0);
815 }
816 
817 
818 #undef __FUNCT__
819 #define __FUNCT__ "PetscOptionsHead"
820 /*@C
821      PetscOptionsHead - Puts a heading before list any more published options. Used, for example,
822             in KSPSetFromOptions_GMRES().
823 
824    Collective on the communicator passed in PetscOptionsBegin()
825 
826    Input Parameter:
827 .   head - the heading text
828 
829 
830    Level: intermediate
831 
832    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
833 
834           Must be followed by a call to PetscOptionsTail() in the same function.
835 
836    Concepts: options database^subheading
837 
838 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
839            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
840           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
841           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
842           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
843           PetscOptionsList(), PetscOptionsEList()
844 @*/
845 PetscErrorCode PETSC_DLLEXPORT PetscOptionsHead(const char head[])
846 {
847   PetscErrorCode ierr;
848 
849   PetscFunctionBegin;
850   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) {
851     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  %s\n",head);CHKERRQ(ierr);
852   }
853   PetscFunctionReturn(0);
854 }
855 
856 
857 
858 
859 
860 
861