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