xref: /petsc/include/petscoptions.h (revision f08646a875d6c8bb0dc8fb3d7c6d74e67952873a)
1 /*
2    Routines to determine options set in the options database.
3 */
4 #if !defined(__PETSCOPTIONS_H)
5 #define __PETSCOPTIONS_H
6 #include "petscsys.h"
7 PETSC_EXTERN_CXX_BEGIN
8 
9 extern PetscErrorCode   PetscOptionsHasName(const char[],const char[],PetscBool *);
10 PetscPolymorphicSubroutine(PetscOptionsHasName,(const char b[],PetscBool  *f),(PETSC_NULL,b,f))
11 extern PetscErrorCode   PetscOptionsGetInt(const char[],const char [],PetscInt *,PetscBool *);
12 PetscPolymorphicSubroutine(PetscOptionsGetInt,(const char b[],PetscInt *i,PetscBool  *f),(PETSC_NULL,b,i,f))
13 extern PetscErrorCode   PetscOptionsGetBool(const char[],const char [],PetscBool  *,PetscBool *);
14 PetscPolymorphicSubroutine(PetscOptionsGetBool,(const char b[],PetscBool  *i,PetscBool  *f),(PETSC_NULL,b,i,f))
15 extern PetscErrorCode   PetscOptionsGetReal(const char[],const char[],PetscReal *,PetscBool *);
16 PetscPolymorphicSubroutine(PetscOptionsGetReal,(const char b[],PetscReal *i,PetscBool  *f),(PETSC_NULL,b,i,f))
17 extern PetscErrorCode   PetscOptionsGetScalar(const char[],const char[],PetscScalar *,PetscBool *);
18 PetscPolymorphicSubroutine(PetscOptionsGetScalar,(const char b[],PetscScalar i[],PetscBool  *f),(PETSC_NULL,b,i,f))
19 extern PetscErrorCode   PetscOptionsGetIntArray(const char[],const char[],PetscInt[],PetscInt *,PetscBool *);
20 PetscPolymorphicSubroutine(PetscOptionsGetIntArray,(const char b[],PetscInt i[],PetscInt *ii,PetscBool  *f),(PETSC_NULL,b,i,ii,f))
21 extern PetscErrorCode   PetscOptionsGetRealArray(const char[],const char[],PetscReal[],PetscInt *,PetscBool *);
22 PetscPolymorphicSubroutine(PetscOptionsGetRealArray,(const char b[],PetscReal i[],PetscInt *ii,PetscBool  *f),(PETSC_NULL,b,i,ii,f))
23 extern PetscErrorCode   PetscOptionsGetBoolArray(const char[],const char[],PetscBool [],PetscInt *,PetscBool *);
24 PetscPolymorphicSubroutine(PetscOptionsGetBoolArray,(const char b[],PetscBool  i[],PetscInt *ii,PetscBool  *f),(PETSC_NULL,b,i,ii,f))
25 extern PetscErrorCode   PetscOptionsGetString(const char[],const char[],char[],size_t,PetscBool *);
26 PetscPolymorphicSubroutine(PetscOptionsGetString,(const char b[],char i[],size_t s,PetscBool  *f),(PETSC_NULL,b,i,s,f))
27 extern PetscErrorCode   PetscOptionsGetStringArray(const char[],const char[],char*[],PetscInt*,PetscBool *);
28 PetscPolymorphicSubroutine(PetscOptionsGetStringArray,(const char b[],char *i[],PetscInt *ii,PetscBool  *f),(PETSC_NULL,b,i,ii,f))
29 extern PetscErrorCode  PetscOptionsGetEList(const char[],const char[],const char*const*,PetscInt,PetscInt*,PetscBool *);
30 extern PetscErrorCode  PetscOptionsGetEnum(const char[],const char[],const char*const*,PetscEnum*,PetscBool *);
31 extern PetscErrorCode  PetscOptionsValidKey(const char[],PetscBool *);
32 
33 extern PetscErrorCode   PetscOptionsSetAlias(const char[],const char[]);
34 extern PetscErrorCode   PetscOptionsSetValue(const char[],const char[]);
35 extern PetscErrorCode   PetscOptionsClearValue(const char[]);
36 
37 extern PetscErrorCode   PetscOptionsAllUsed(PetscInt*);
38 extern PetscErrorCode   PetscOptionsUsed(const char *,PetscBool*);
39 extern PetscErrorCode   PetscOptionsLeft(void);
40 extern PetscErrorCode   PetscOptionsView(PetscViewer);
41 
42 extern PetscErrorCode   PetscOptionsCreate(void);
43 extern PetscErrorCode   PetscOptionsInsert(int*,char ***,const char[]);
44 extern PetscErrorCode   PetscOptionsInsertFile(MPI_Comm,const char[],PetscBool );
45 #if defined(PETSC_HAVE_YAML)
46 extern PetscErrorCode   PetscOptionsInsertFile_YAML(MPI_Comm,const char[],PetscBool);
47 #endif
48 extern PetscErrorCode   PetscOptionsInsertString(const char[]);
49 extern PetscErrorCode   PetscOptionsDestroy(void);
50 extern PetscErrorCode   PetscOptionsClear(void);
51 extern PetscErrorCode   PetscOptionsPrefixPush(const char[]);
52 extern PetscErrorCode   PetscOptionsPrefixPop(void);
53 
54 extern PetscErrorCode   PetscOptionsReject(const char[],const char[]);
55 extern PetscErrorCode   PetscOptionsGetAll(char*[]);
56 
57 extern PetscErrorCode   PetscOptionsGetenv(MPI_Comm,const char[],char[],size_t,PetscBool  *);
58 extern PetscErrorCode   PetscOptionsStringToInt(const char[],PetscInt*);
59 extern PetscErrorCode   PetscOptionsStringToReal(const char[],PetscReal*);
60 extern PetscErrorCode   PetscOptionsStringToBool(const char[],PetscBool*);
61 
62 extern PetscErrorCode  PetscOptionsMonitorSet(PetscErrorCode (*)(const char[], const char[], void*), void *, PetscErrorCode (*)(void**));
63 extern PetscErrorCode  PetscOptionsMonitorCancel(void);
64 extern PetscErrorCode  PetscOptionsMonitorDefault(const char[], const char[], void *);
65 
66 extern  PetscBool  PetscOptionsPublish;
67 extern  PetscInt   PetscOptionsPublishCount;
68 
69 /*MC
70     PetscOptionsBegin - Begins a set of queries on the options database that are related and should be
71      displayed on the same window of a GUI that allows the user to set the options interactively.
72 
73    Synopsis: PetscErrorCode PetscOptionsBegin(MPI_Comm comm,const char prefix[],const char title[],const char mansec[])
74 
75     Collective on MPI_Comm
76 
77   Input Parameters:
78 +   comm - communicator that shares GUI
79 .   prefix - options prefix for all options displayed on window
80 .   title - short descriptive text, for example "Krylov Solver Options"
81 -   mansec - section of manual pages for options, for example KSP
82 
83   Level: intermediate
84 
85   Notes: Needs to be ended by a call the PetscOptionsEnd()
86          Can add subheadings with PetscOptionsHead()
87 
88   Developer notes: PetscOptionsPublish is set in PetscOptionsCheckInitial_Private() with -options_gui. When PetscOptionsPublish is set the
89 $             loop between PetscOptionsBegin() and PetscOptionsEnd() is run THREE times with PetscOptionsPublishCount of values -1,0,1 otherwise
90 $             the loop is run ONCE with a PetscOptionsPublishCount of 1.
91 $             = -1 : The PetscOptionsInt() etc just call the PetscOptionsGetInt() etc
92 $             = 0  : The GUI objects are created in PetscOptionsInt() etc and displayed in PetscOptionsEnd() and the options
93 $                    database updated updated with user changes; PetscOptionsGetInt() etc are also called
94 $             = 1 : The PetscOptionsInt() etc again call the PetscOptionsGetInt() etc (possibly getting new values), in addition the help message and
95 $                   default values are printed if -help was given.
96 $           When PetscOptionsObject.changedmethod is set this causes PetscOptionsPublishCount to be reset to -2 (so in the next loop iteration it is -1)
97 $           and the whole process is repeated. This is to handle when, for example, the KSPType is changed thus changing the list of
98 $           options available so they need to be redisplayed so the user can change the. Chaning PetscOptionsObjects.changedmethod is never
99 $           currently set.
100 
101 
102 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
103           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
104           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
105           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
106           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
107           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
108           PetscOptionsList(), PetscOptionsEList(), PetscObjectOptionsBegin()
109 
110 M*/
111 #define    PetscOptionsBegin(comm,prefix,mess,sec) 0; do {\
112              for (PetscOptionsPublishCount=(PetscOptionsPublish?-1:1); PetscOptionsPublishCount<2; PetscOptionsPublishCount++) {\
113              PetscErrorCode _5_ierr = PetscOptionsBegin_Private(comm,prefix,mess,sec);CHKERRQ(_5_ierr);
114 
115 /*MC
116     PetscObjectOptionsBegin - Begins a set of queries on the options database that are related and should be
117      displayed on the same window of a GUI that allows the user to set the options interactively.
118 
119    Synopsis: PetscErrorCode PetscObjectOptionsBegin(PetscObject obj)
120 
121     Collective on PetscObject
122 
123   Input Parameters:
124 .   obj - object to set options for
125 
126   Level: intermediate
127 
128   Notes: Needs to be ended by a call the PetscOptionsEnd()
129          Can add subheadings with PetscOptionsHead()
130 
131 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
132           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
133           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
134           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
135           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
136           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
137           PetscOptionsList(), PetscOptionsEList()
138 
139 M*/
140 #define PetscObjectOptionsBegin(obj) 0; do {                            \
141   for (PetscOptionsPublishCount=(PetscOptionsPublish?-1:1); PetscOptionsPublishCount<2; PetscOptionsPublishCount++) { \
142   PetscErrorCode _5_ierr = PetscObjectOptionsBegin_Private(obj);CHKERRQ(_5_ierr);
143 
144 /*MC
145     PetscOptionsEnd - Ends a set of queries on the options database that are related and should be
146      displayed on the same window of a GUI that allows the user to set the options interactively.
147 
148     Collective on the MPI_Comm used in PetscOptionsBegin()
149 
150    Synopsis: PetscErrorCode PetscOptionsEnd(void)
151 
152   Level: intermediate
153 
154   Notes: Needs to be preceded by a call to PetscOptionsBegin()
155 
156 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
157           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
158           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
159           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
160           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
161           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
162           PetscOptionsList(), PetscOptionsEList(), PetscObjectOptionsBegin()
163 
164 M*/
165 #define    PetscOptionsEnd() _5_ierr = PetscOptionsEnd_Private();CHKERRQ(_5_ierr);}} while (0)
166 
167 extern PetscErrorCode  PetscOptionsBegin_Private(MPI_Comm,const char[],const char[],const char[]);
168 extern PetscErrorCode  PetscObjectOptionsBegin_Private(PetscObject);
169 extern PetscErrorCode  PetscOptionsEnd_Private(void);
170 extern PetscErrorCode  PetscOptionsHead(const char[]);
171 
172 /*MC
173      PetscOptionsTail - Ends a section of options begun with PetscOptionsHead()
174             See, for example, KSPSetFromOptions_GMRES().
175 
176    Collective on the communicator passed in PetscOptionsBegin()
177 
178    Synopsis: PetscErrorCode PetscOptionsTail(void)
179 
180   Level: intermediate
181 
182    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
183 
184           Must be preceded by a call to PetscOptionsHead() in the same function.
185 
186           This needs to be used only if the code below PetscOptionsTail() can be run ONLY once.
187       See, for example, PCSetFromOptions_Composite(). This is a return(0) in it for early exit
188       from the function.
189 
190           This is only for use with the PETSc options GUI; which does not currently exist.
191 
192    Concepts: options database^subheading
193 
194 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
195            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
196           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
197           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
198           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
199           PetscOptionsList(), PetscOptionsEList(), PetscOptionsEnum()
200 M*/
201 #define    PetscOptionsTail() 0; {if (PetscOptionsPublishCount != 1) PetscFunctionReturn(0);}
202 
203 extern PetscErrorCode  PetscOptionsEnum(const char[],const char[],const char[],const char *const*,PetscEnum,PetscEnum*,PetscBool *);
204 extern PetscErrorCode  PetscOptionsInt(const char[],const char[],const char[],PetscInt,PetscInt*,PetscBool *);
205 extern PetscErrorCode  PetscOptionsReal(const char[],const char[],const char[],PetscReal,PetscReal*,PetscBool *);
206 extern PetscErrorCode  PetscOptionsScalar(const char[],const char[],const char[],PetscScalar,PetscScalar*,PetscBool *);
207 extern PetscErrorCode  PetscOptionsName(const char[],const char[],const char[],PetscBool *);
208 extern PetscErrorCode  PetscOptionsString(const char[],const char[],const char[],const char[],char*,size_t,PetscBool *);
209 extern PetscErrorCode  PetscOptionsBool(const char[],const char[],const char[],PetscBool ,PetscBool *,PetscBool *);
210 extern PetscErrorCode  PetscOptionsBoolGroupBegin(const char[],const char[],const char[],PetscBool *);
211 extern PetscErrorCode  PetscOptionsBoolGroup(const char[],const char[],const char[],PetscBool *);
212 extern PetscErrorCode  PetscOptionsBoolGroupEnd(const char[],const char[],const char[],PetscBool *);
213 extern PetscErrorCode  PetscOptionsList(const char[],const char[],const char[],PetscFList,const char[],char[],size_t,PetscBool *);
214 extern PetscErrorCode  PetscOptionsEList(const char[],const char[],const char[],const char*const*,PetscInt,const char[],PetscInt*,PetscBool *);
215 extern PetscErrorCode  PetscOptionsRealArray(const char[],const char[],const char[],PetscReal[],PetscInt*,PetscBool *);
216 extern PetscErrorCode  PetscOptionsIntArray(const char[],const char[],const char[],PetscInt[],PetscInt*,PetscBool *);
217 extern PetscErrorCode  PetscOptionsStringArray(const char[],const char[],const char[],char*[],PetscInt*,PetscBool *);
218 extern PetscErrorCode  PetscOptionsBoolArray(const char[],const char[],const char[],PetscBool [],PetscInt*,PetscBool *);
219 
220 extern PetscErrorCode  PetscOptionsSetFromOptions(void);
221 extern PetscErrorCode  PetscOptionsAMSDestroy(void);
222 PETSC_EXTERN_CXX_END
223 
224 /*
225     See manual page for PetscOptionsBegin()
226 */
227 typedef enum {OPTION_INT,OPTION_LOGICAL,OPTION_REAL,OPTION_LIST,OPTION_STRING,OPTION_REAL_ARRAY,OPTION_HEAD,OPTION_INT_ARRAY,OPTION_ELIST,OPTION_LOGICAL_ARRAY,OPTION_STRING_ARRAY} PetscOptionType;
228 typedef struct _n_PetscOptions* PetscOptions;
229 struct _n_PetscOptions {
230   char              *option;
231   char              *text;
232   void              *data;         /* used to hold the default value and then any value it is changed to by GUI */
233   PetscFList        flist;         /* used for available values for PetscOptionsList() */
234   const char *const *list;        /* used for available values for PetscOptionsEList() */
235   char              nlist;         /* number of entries in list */
236   char              *man;
237   size_t            arraylength;   /* number of entries in data in the case that it is an array (of PetscInt etc) */
238   PetscBool         set;           /* the user has changed this value in the GUI */
239   PetscOptionType   type;
240   PetscOptions      next;
241   char              *pman;
242   void              *edata;
243 };
244 
245 typedef struct {
246   PetscOptions     next;
247   char             *prefix,*pprefix;
248   char             *title;
249   MPI_Comm         comm;
250   PetscBool        printhelp,changedmethod,alreadyprinted;
251   PetscObject      object;
252 } PetscOptionsObjectType;
253 #endif
254