xref: /petsc/include/petscoptions.h (revision 014dd563d73e9fc78d056590fa6cf997782bf92d)
1f26ada1bSBarry Smith /*
237f753daSBarry Smith    Routines to determine options set in the options database.
3f26ada1bSBarry Smith */
40a835dfdSSatish Balay #if !defined(__PETSCOPTIONS_H)
50a835dfdSSatish Balay #define __PETSCOPTIONS_H
6d382aafbSBarry Smith #include "petscsys.h"
73a3b2205SBarry Smith 
8*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsHasName(const char[],const char[],PetscBool *);
9*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsGetInt(const char[],const char [],PetscInt *,PetscBool *);
10*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsGetBool(const char[],const char [],PetscBool  *,PetscBool *);
11*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsGetReal(const char[],const char[],PetscReal *,PetscBool *);
12*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsGetScalar(const char[],const char[],PetscScalar *,PetscBool *);
13*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsGetIntArray(const char[],const char[],PetscInt[],PetscInt *,PetscBool *);
14*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsGetRealArray(const char[],const char[],PetscReal[],PetscInt *,PetscBool *);
15*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsGetBoolArray(const char[],const char[],PetscBool [],PetscInt *,PetscBool *);
16*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsGetString(const char[],const char[],char[],size_t,PetscBool *);
17*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsGetStringArray(const char[],const char[],char*[],PetscInt*,PetscBool *);
18*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsGetEList(const char[],const char[],const char*const*,PetscInt,PetscInt*,PetscBool *);
19*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsGetEnum(const char[],const char[],const char*const*,PetscEnum*,PetscBool *);
20*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsValidKey(const char[],PetscBool *);
213a3b2205SBarry Smith 
22*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsSetAlias(const char[],const char[]);
23*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsSetValue(const char[],const char[]);
24*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsClearValue(const char[]);
253a3b2205SBarry Smith 
26*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsAllUsed(PetscInt*);
27*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsUsed(const char *,PetscBool*);
28*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsLeft(void);
29*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsView(PetscViewer);
304b0e389bSBarry Smith 
31*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsCreate(void);
32*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsInsert(int*,char ***,const char[]);
33*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsInsertFile(MPI_Comm,const char[],PetscBool );
343bcbd388SSean Farley #if defined(PETSC_HAVE_YAML)
35*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsInsertFile_YAML(MPI_Comm,const char[],PetscBool);
363bcbd388SSean Farley #endif
37*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsInsertString(const char[]);
38*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsDestroy(void);
39*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsClear(void);
40*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsPrefixPush(const char[]);
41*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsPrefixPop(void);
425d0dffe5SBarry Smith 
43*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsReject(const char[],const char[]);
44*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsGetAll(char*[]);
455d0dffe5SBarry Smith 
46*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsGetenv(MPI_Comm,const char[],char[],size_t,PetscBool  *);
47*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsStringToInt(const char[],PetscInt*);
48*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsStringToReal(const char[],PetscReal*);
49*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsStringToBool(const char[],PetscBool*);
502e8a6d31SBarry Smith 
51*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsMonitorSet(PetscErrorCode (*)(const char[], const char[], void*), void *, PetscErrorCode (*)(void**));
52*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsMonitorCancel(void);
53*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsMonitorDefault(const char[], const char[], void *);
54081c24baSBoyana Norris 
55*014dd563SJed Brown PETSC_EXTERN PetscBool PetscOptionsPublish;
56*014dd563SJed Brown PETSC_EXTERN PetscInt PetscOptionsPublishCount;
5730de9b25SBarry Smith 
5830de9b25SBarry Smith /*MC
5930de9b25SBarry Smith     PetscOptionsBegin - Begins a set of queries on the options database that are related and should be
6030de9b25SBarry Smith      displayed on the same window of a GUI that allows the user to set the options interactively.
6130de9b25SBarry Smith 
62d360dc6fSBarry Smith    Synopsis: PetscErrorCode PetscOptionsBegin(MPI_Comm comm,const char prefix[],const char title[],const char mansec[])
6330de9b25SBarry Smith 
6430de9b25SBarry Smith     Collective on MPI_Comm
6530de9b25SBarry Smith 
6630de9b25SBarry Smith   Input Parameters:
6730de9b25SBarry Smith +   comm - communicator that shares GUI
6830de9b25SBarry Smith .   prefix - options prefix for all options displayed on window
6930de9b25SBarry Smith .   title - short descriptive text, for example "Krylov Solver Options"
7030de9b25SBarry Smith -   mansec - section of manual pages for options, for example KSP
7130de9b25SBarry Smith 
7230de9b25SBarry Smith   Level: intermediate
7330de9b25SBarry Smith 
7430de9b25SBarry Smith   Notes: Needs to be ended by a call the PetscOptionsEnd()
7530de9b25SBarry Smith          Can add subheadings with PetscOptionsHead()
7630de9b25SBarry Smith 
77aee2cecaSBarry Smith   Developer notes: PetscOptionsPublish is set in PetscOptionsCheckInitial_Private() with -options_gui. When PetscOptionsPublish is set the
78aee2cecaSBarry Smith $             loop between PetscOptionsBegin() and PetscOptionsEnd() is run THREE times with PetscOptionsPublishCount of values -1,0,1 otherwise
79aee2cecaSBarry Smith $             the loop is run ONCE with a PetscOptionsPublishCount of 1.
80aee2cecaSBarry Smith $             = -1 : The PetscOptionsInt() etc just call the PetscOptionsGetInt() etc
81aee2cecaSBarry Smith $             = 0  : The GUI objects are created in PetscOptionsInt() etc and displayed in PetscOptionsEnd() and the options
82c8e70145SBarry Smith $                    database updated updated with user changes; PetscOptionsGetInt() etc are also called
83c8e70145SBarry Smith $             = 1 : The PetscOptionsInt() etc again call the PetscOptionsGetInt() etc (possibly getting new values), in addition the help message and
84c8e70145SBarry Smith $                   default values are printed if -help was given.
85538aa990SBarry Smith $           When PetscOptionsObject.changedmethod is set this causes PetscOptionsPublishCount to be reset to -2 (so in the next loop iteration it is -1)
86538aa990SBarry Smith $           and the whole process is repeated. This is to handle when, for example, the KSPType is changed thus changing the list of
87538aa990SBarry Smith $           options available so they need to be redisplayed so the user can change the. Chaning PetscOptionsObjects.changedmethod is never
88538aa990SBarry Smith $           currently set.
89aee2cecaSBarry Smith 
90aee2cecaSBarry Smith 
9130de9b25SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
92acfcf0e5SJed Brown           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
93acfcf0e5SJed Brown           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
9430de9b25SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
9530de9b25SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
96acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
975fefd1ebSJed Brown           PetscOptionsList(), PetscOptionsEList(), PetscObjectOptionsBegin()
9830de9b25SBarry Smith 
9930de9b25SBarry Smith M*/
1003194b578SJed Brown #define    PetscOptionsBegin(comm,prefix,mess,sec) 0; do {\
101b0a32e0cSBarry Smith              for (PetscOptionsPublishCount=(PetscOptionsPublish?-1:1); PetscOptionsPublishCount<2; PetscOptionsPublishCount++) {\
1027c307921SBarry Smith              PetscErrorCode _5_ierr = PetscOptionsBegin_Private(comm,prefix,mess,sec);CHKERRQ(_5_ierr);
10330de9b25SBarry Smith 
1045fefd1ebSJed Brown /*MC
1055fefd1ebSJed Brown     PetscObjectOptionsBegin - Begins a set of queries on the options database that are related and should be
1065fefd1ebSJed Brown      displayed on the same window of a GUI that allows the user to set the options interactively.
1075fefd1ebSJed Brown 
1085fefd1ebSJed Brown    Synopsis: PetscErrorCode PetscObjectOptionsBegin(PetscObject obj)
1095fefd1ebSJed Brown 
1105fefd1ebSJed Brown     Collective on PetscObject
1115fefd1ebSJed Brown 
1125fefd1ebSJed Brown   Input Parameters:
1135fefd1ebSJed Brown .   obj - object to set options for
1145fefd1ebSJed Brown 
1155fefd1ebSJed Brown   Level: intermediate
1165fefd1ebSJed Brown 
1175fefd1ebSJed Brown   Notes: Needs to be ended by a call the PetscOptionsEnd()
1185fefd1ebSJed Brown          Can add subheadings with PetscOptionsHead()
1195fefd1ebSJed Brown 
1205fefd1ebSJed Brown .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
1215fefd1ebSJed Brown           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
1225fefd1ebSJed Brown           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
1235fefd1ebSJed Brown           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1245fefd1ebSJed Brown           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1255fefd1ebSJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1265fefd1ebSJed Brown           PetscOptionsList(), PetscOptionsEList()
1275fefd1ebSJed Brown 
1285fefd1ebSJed Brown M*/
1293194b578SJed Brown #define PetscObjectOptionsBegin(obj) 0; do {                            \
1303194b578SJed Brown   for (PetscOptionsPublishCount=(PetscOptionsPublish?-1:1); PetscOptionsPublishCount<2; PetscOptionsPublishCount++) { \
1313194b578SJed Brown   PetscErrorCode _5_ierr = PetscObjectOptionsBegin_Private(obj);CHKERRQ(_5_ierr);
1323194b578SJed Brown 
13330de9b25SBarry Smith /*MC
13430de9b25SBarry Smith     PetscOptionsEnd - Ends a set of queries on the options database that are related and should be
13530de9b25SBarry Smith      displayed on the same window of a GUI that allows the user to set the options interactively.
13630de9b25SBarry Smith 
13730de9b25SBarry Smith     Collective on the MPI_Comm used in PetscOptionsBegin()
13830de9b25SBarry Smith 
139d360dc6fSBarry Smith    Synopsis: PetscErrorCode PetscOptionsEnd(void)
14030de9b25SBarry Smith 
14130de9b25SBarry Smith   Level: intermediate
14230de9b25SBarry Smith 
14330de9b25SBarry Smith   Notes: Needs to be preceded by a call to PetscOptionsBegin()
14430de9b25SBarry Smith 
14530de9b25SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
146acfcf0e5SJed Brown           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
147acfcf0e5SJed Brown           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
14830de9b25SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
14930de9b25SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
150acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1515fefd1ebSJed Brown           PetscOptionsList(), PetscOptionsEList(), PetscObjectOptionsBegin()
15230de9b25SBarry Smith 
15330de9b25SBarry Smith M*/
1543194b578SJed Brown #define    PetscOptionsEnd() _5_ierr = PetscOptionsEnd_Private();CHKERRQ(_5_ierr);}} while (0)
15530de9b25SBarry Smith 
156*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsBegin_Private(MPI_Comm,const char[],const char[],const char[]);
157*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectOptionsBegin_Private(PetscObject);
158*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsEnd_Private(void);
159*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsHead(const char[]);
16030de9b25SBarry Smith 
16130de9b25SBarry Smith /*MC
16230de9b25SBarry Smith      PetscOptionsTail - Ends a section of options begun with PetscOptionsHead()
16330de9b25SBarry Smith             See, for example, KSPSetFromOptions_GMRES().
16430de9b25SBarry Smith 
16530de9b25SBarry Smith    Collective on the communicator passed in PetscOptionsBegin()
16630de9b25SBarry Smith 
167d360dc6fSBarry Smith    Synopsis: PetscErrorCode PetscOptionsTail(void)
16830de9b25SBarry Smith 
16930de9b25SBarry Smith   Level: intermediate
17030de9b25SBarry Smith 
17130de9b25SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
17230de9b25SBarry Smith 
17330de9b25SBarry Smith           Must be preceded by a call to PetscOptionsHead() in the same function.
17430de9b25SBarry Smith 
175b52f573bSBarry Smith           This needs to be used only if the code below PetscOptionsTail() can be run ONLY once.
176b52f573bSBarry Smith       See, for example, PCSetFromOptions_Composite(). This is a return(0) in it for early exit
177b52f573bSBarry Smith       from the function.
178b52f573bSBarry Smith 
179b52f573bSBarry Smith           This is only for use with the PETSc options GUI; which does not currently exist.
180b52f573bSBarry Smith 
18130de9b25SBarry Smith    Concepts: options database^subheading
18230de9b25SBarry Smith 
18330de9b25SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
184acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
18530de9b25SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
18630de9b25SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
187acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1889dcbbd2bSBarry Smith           PetscOptionsList(), PetscOptionsEList(), PetscOptionsEnum()
18930de9b25SBarry Smith M*/
190b0a32e0cSBarry Smith #define    PetscOptionsTail() 0; {if (PetscOptionsPublishCount != 1) PetscFunctionReturn(0);}
191186905e3SBarry Smith 
192*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsEnum(const char[],const char[],const char[],const char *const*,PetscEnum,PetscEnum*,PetscBool *);
193*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsInt(const char[],const char[],const char[],PetscInt,PetscInt*,PetscBool *);
194*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsReal(const char[],const char[],const char[],PetscReal,PetscReal*,PetscBool *);
195*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsScalar(const char[],const char[],const char[],PetscScalar,PetscScalar*,PetscBool *);
196*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsName(const char[],const char[],const char[],PetscBool *);
197*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsString(const char[],const char[],const char[],const char[],char*,size_t,PetscBool *);
198*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsBool(const char[],const char[],const char[],PetscBool ,PetscBool *,PetscBool *);
199*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsBoolGroupBegin(const char[],const char[],const char[],PetscBool *);
200*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsBoolGroup(const char[],const char[],const char[],PetscBool *);
201*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsBoolGroupEnd(const char[],const char[],const char[],PetscBool *);
202*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsList(const char[],const char[],const char[],PetscFList,const char[],char[],size_t,PetscBool *);
203*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsEList(const char[],const char[],const char[],const char*const*,PetscInt,const char[],PetscInt*,PetscBool *);
204*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsRealArray(const char[],const char[],const char[],PetscReal[],PetscInt*,PetscBool *);
205*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsIntArray(const char[],const char[],const char[],PetscInt[],PetscInt*,PetscBool *);
206*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsStringArray(const char[],const char[],const char[],char*[],PetscInt*,PetscBool *);
207*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsBoolArray(const char[],const char[],const char[],PetscBool [],PetscInt*,PetscBool *);
208e9fa29b7SSatish Balay 
209*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsSetFromOptions(void);
210*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsAMSDestroy(void);
211f8d0b74dSMatthew Knepley 
212e26ddf31SBarry Smith /*
213e26ddf31SBarry Smith     See manual page for PetscOptionsBegin()
214e26ddf31SBarry Smith */
2151ae3d29cSBarry Smith 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;
2166e655a9bSJed Brown typedef struct _n_PetscOptions* PetscOptions;
2176e655a9bSJed Brown struct _n_PetscOptions {
218f8d0b74dSMatthew Knepley   char              *option;
219f8d0b74dSMatthew Knepley   char              *text;
2203cc1e11dSBarry Smith   void              *data;         /* used to hold the default value and then any value it is changed to by GUI */
2213cc1e11dSBarry Smith   PetscFList        flist;         /* used for available values for PetscOptionsList() */
2221ae3d29cSBarry Smith   const char *const *list;        /* used for available values for PetscOptionsEList() */
2231ae3d29cSBarry Smith   char              nlist;         /* number of entries in list */
224f8d0b74dSMatthew Knepley   char              *man;
2253cc1e11dSBarry Smith   size_t            arraylength;   /* number of entries in data in the case that it is an array (of PetscInt etc) */
226ace3abfcSBarry Smith   PetscBool         set;           /* the user has changed this value in the GUI */
227e3ed6ec8SBarry Smith   PetscOptionType   type;
228f8d0b74dSMatthew Knepley   PetscOptions      next;
2291bc75a8dSBarry Smith   char              *pman;
23071f08665SBarry Smith   void              *edata;
231f8d0b74dSMatthew Knepley };
232f8d0b74dSMatthew Knepley 
233f8d0b74dSMatthew Knepley typedef struct {
234f8d0b74dSMatthew Knepley   PetscOptions     next;
2351bc75a8dSBarry Smith   char             *prefix,*pprefix;
236f8d0b74dSMatthew Knepley   char             *title;
237f8d0b74dSMatthew Knepley   MPI_Comm         comm;
238ace3abfcSBarry Smith   PetscBool        printhelp,changedmethod,alreadyprinted;
2393194b578SJed Brown   PetscObject      object;
240f8d0b74dSMatthew Knepley } PetscOptionsObjectType;
2413a3b2205SBarry Smith #endif
242