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