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