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