xref: /petsc/include/petscoptions.h (revision 2ae9f97c2b3342c7fa240ee3f9868a1cbf4cbe21)
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"
7e9fa29b7SSatish Balay PETSC_EXTERN_CXX_BEGIN
83a3b2205SBarry Smith 
9ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscOptionsHasName(const char[],const char[],PetscTruth*);
10045ff3e0SBarry Smith PetscPolymorphicSubroutine(PetscOptionsHasName,(const char b[],PetscTruth *f),(PETSC_NULL,b,f))
11ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscOptionsGetInt(const char[],const char [],PetscInt *,PetscTruth*);
12045ff3e0SBarry Smith PetscPolymorphicSubroutine(PetscOptionsGetInt,(const char b[],PetscInt *i,PetscTruth *f),(PETSC_NULL,b,i,f))
134dc4c822SBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscOptionsGetTruth(const char[],const char [],PetscTruth *,PetscTruth*);
144dc4c822SBarry Smith PetscPolymorphicSubroutine(PetscOptionsGetTruth,(const char b[],PetscTruth *i,PetscTruth *f),(PETSC_NULL,b,i,f))
15ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscOptionsGetReal(const char[],const char[],PetscReal *,PetscTruth*);
16045ff3e0SBarry Smith PetscPolymorphicSubroutine(PetscOptionsGetReal,(const char b[],PetscReal *i,PetscTruth *f),(PETSC_NULL,b,i,f))
17ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscOptionsGetScalar(const char[],const char[],PetscScalar *,PetscTruth*);
18045ff3e0SBarry Smith PetscPolymorphicSubroutine(PetscOptionsGetScalar,(const char b[],PetscScalar i[],PetscTruth *f),(PETSC_NULL,b,i,f))
19ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscOptionsGetIntArray(const char[],const char[],PetscInt[],PetscInt *,PetscTruth*);
20045ff3e0SBarry Smith PetscPolymorphicSubroutine(PetscOptionsGetIntArray,(const char b[],PetscInt i[],PetscInt *ii,PetscTruth *f),(PETSC_NULL,b,i,ii,f))
21ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscOptionsGetRealArray(const char[],const char[],PetscReal[],PetscInt *,PetscTruth*);
22045ff3e0SBarry Smith PetscPolymorphicSubroutine(PetscOptionsGetRealArray,(const char b[],PetscReal i[],PetscInt *ii,PetscTruth *f),(PETSC_NULL,b,i,ii,f))
23e2446a98SMatthew Knepley EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscOptionsGetTruthArray(const char[],const char[],PetscTruth[],PetscInt *,PetscTruth*);
24e2446a98SMatthew Knepley PetscPolymorphicSubroutine(PetscOptionsGetTruthArray,(const char b[],PetscTruth i[],PetscInt *ii,PetscTruth *f),(PETSC_NULL,b,i,ii,f))
25ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscOptionsGetString(const char[],const char[],char[],size_t,PetscTruth*);
26045ff3e0SBarry Smith PetscPolymorphicSubroutine(PetscOptionsGetString,(const char b[],char i[],size_t s,PetscTruth *f),(PETSC_NULL,b,i,s,f))
27ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscOptionsGetStringArray(const char[],const char[],char*[],PetscInt*,PetscTruth*);
28045ff3e0SBarry Smith PetscPolymorphicSubroutine(PetscOptionsGetStringArray,(const char b[],char *i[],PetscInt *ii,PetscTruth *f),(PETSC_NULL,b,i,ii,f))
29*2ae9f97cSJed Brown EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOptionsGetEList(const char[],const char[],const char*const*,PetscInt,PetscInt*,PetscTruth*);
30*2ae9f97cSJed Brown EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOptionsGetEnum(const char[],const char[],const char*const*,PetscEnum*,PetscTruth*);
31330cf3c9SBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOptionsValidKey(const char[],PetscTruth*);
323a3b2205SBarry Smith 
33ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscOptionsSetAlias(const char[],const char[]);
34ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscOptionsSetValue(const char[],const char[]);
35ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscOptionsClearValue(const char[]);
363a3b2205SBarry Smith 
37ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscOptionsAllUsed(int*);
38ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscOptionsLeft(void);
39ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscOptionsPrint(FILE *);
404b0e389bSBarry Smith 
41ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscOptionsCreate(void);
42ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscOptionsInsert(int*,char ***,const char[]);
439b754dc9SBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscOptionsInsertFile(MPI_Comm,const char[],PetscTruth);
44ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscOptionsInsertString(const char[]);
45ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscOptionsDestroy(void);
46a542b6e8SBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscOptionsClear(void);
475d0dffe5SBarry Smith 
48ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscOptionsReject(const char[],const char[]);
49ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscOptionsGetAll(char*[]);
505d0dffe5SBarry Smith 
51ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscOptionsGetenv(MPI_Comm,const char[],char[],size_t,PetscTruth *);
52ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscOptionsAtoi(const char[],PetscInt*);
53ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscOptionsAtod(const char[],PetscReal*);
542e8a6d31SBarry Smith 
55a6570f20SBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOptionsMonitorSet(PetscErrorCode (*)(const char[], const char[], void*), void *, PetscErrorCode (*)(void*));
5695abf9c0SSatish Balay EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOptionsMonitorCancel(void);
57a6570f20SBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOptionsMonitorDefault(const char[], const char[], void *);
58081c24baSBoyana Norris 
59ff73aad6SKris Buschelman extern PETSC_DLLEXPORT PetscTruth PetscOptionsPublish;
607c307921SBarry Smith extern PETSC_DLLEXPORT PetscInt   PetscOptionsPublishCount;
6130de9b25SBarry Smith 
6230de9b25SBarry Smith /*MC
6330de9b25SBarry Smith     PetscOptionsBegin - Begins a set of queries on the options database that are related and should be
6430de9b25SBarry Smith      displayed on the same window of a GUI that allows the user to set the options interactively.
6530de9b25SBarry Smith 
66d360dc6fSBarry Smith    Synopsis: PetscErrorCode PetscOptionsBegin(MPI_Comm comm,const char prefix[],const char title[],const char mansec[])
6730de9b25SBarry Smith 
6830de9b25SBarry Smith     Collective on MPI_Comm
6930de9b25SBarry Smith 
7030de9b25SBarry Smith   Input Parameters:
7130de9b25SBarry Smith +   comm - communicator that shares GUI
7230de9b25SBarry Smith .   prefix - options prefix for all options displayed on window
7330de9b25SBarry Smith .   title - short descriptive text, for example "Krylov Solver Options"
7430de9b25SBarry Smith -   mansec - section of manual pages for options, for example KSP
7530de9b25SBarry Smith 
7630de9b25SBarry Smith   Level: intermediate
7730de9b25SBarry Smith 
7830de9b25SBarry Smith   Notes: Needs to be ended by a call the PetscOptionsEnd()
7930de9b25SBarry Smith          Can add subheadings with PetscOptionsHead()
8030de9b25SBarry Smith 
81aee2cecaSBarry Smith   Developer notes: PetscOptionsPublish is set in PetscOptionsCheckInitial_Private() with -options_gui. When PetscOptionsPublish is set the
82aee2cecaSBarry Smith $             loop between PetscOptionsBegin() and PetscOptionsEnd() is run THREE times with PetscOptionsPublishCount of values -1,0,1 otherwise
83aee2cecaSBarry Smith $             the loop is run ONCE with a PetscOptionsPublishCount of 1.
84aee2cecaSBarry Smith $             = -1 : The PetscOptionsInt() etc just call the PetscOptionsGetInt() etc
85aee2cecaSBarry Smith $             = 0  : The GUI objects are created in PetscOptionsInt() etc and displayed in PetscOptionsEnd() and the options
86c8e70145SBarry Smith $                    database updated updated with user changes; PetscOptionsGetInt() etc are also called
87c8e70145SBarry Smith $             = 1 : The PetscOptionsInt() etc again call the PetscOptionsGetInt() etc (possibly getting new values), in addition the help message and
88c8e70145SBarry Smith $                   default values are printed if -help was given.
89538aa990SBarry Smith $           When PetscOptionsObject.changedmethod is set this causes PetscOptionsPublishCount to be reset to -2 (so in the next loop iteration it is -1)
90538aa990SBarry Smith $           and the whole process is repeated. This is to handle when, for example, the KSPType is changed thus changing the list of
91538aa990SBarry Smith $           options available so they need to be redisplayed so the user can change the. Chaning PetscOptionsObjects.changedmethod is never
92538aa990SBarry Smith $           currently set.
93aee2cecaSBarry Smith 
94aee2cecaSBarry Smith 
9530de9b25SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
964dc4c822SBarry Smith           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
974dc4c822SBarry Smith           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
9830de9b25SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
9930de9b25SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1004dc4c822SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
10130de9b25SBarry Smith           PetscOptionsList(), PetscOptionsEList()
10230de9b25SBarry Smith 
10330de9b25SBarry Smith M*/
104b0a32e0cSBarry Smith #define    PetscOptionsBegin(comm,prefix,mess,sec) 0; {\
105b0a32e0cSBarry Smith              for (PetscOptionsPublishCount=(PetscOptionsPublish?-1:1); PetscOptionsPublishCount<2; PetscOptionsPublishCount++) {\
1067c307921SBarry Smith              PetscErrorCode _5_ierr = PetscOptionsBegin_Private(comm,prefix,mess,sec);CHKERRQ(_5_ierr);
10730de9b25SBarry Smith 
10830de9b25SBarry Smith /*MC
10930de9b25SBarry Smith     PetscOptionsEnd - Ends a set of queries on the options database that are related and should be
11030de9b25SBarry Smith      displayed on the same window of a GUI that allows the user to set the options interactively.
11130de9b25SBarry Smith 
11230de9b25SBarry Smith     Collective on the MPI_Comm used in PetscOptionsBegin()
11330de9b25SBarry Smith 
114d360dc6fSBarry Smith    Synopsis: PetscErrorCode PetscOptionsEnd(void)
11530de9b25SBarry Smith 
11630de9b25SBarry Smith   Level: intermediate
11730de9b25SBarry Smith 
11830de9b25SBarry Smith   Notes: Needs to be preceded by a call to PetscOptionsBegin()
11930de9b25SBarry Smith 
12030de9b25SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
1214dc4c822SBarry Smith           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
1224dc4c822SBarry Smith           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
12330de9b25SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
12430de9b25SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1254dc4c822SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
12630de9b25SBarry Smith           PetscOptionsList(), PetscOptionsEList()
12730de9b25SBarry Smith 
12830de9b25SBarry Smith M*/
129ef66eb69SBarry Smith #define    PetscOptionsEnd() _5_ierr = PetscOptionsEnd_Private();CHKERRQ(_5_ierr);}}
13030de9b25SBarry Smith 
131ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOptionsBegin_Private(MPI_Comm,const char[],const char[],const char[]);
132ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOptionsEnd_Private(void);
133ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOptionsHead(const char[]);
13430de9b25SBarry Smith 
13530de9b25SBarry Smith /*MC
13630de9b25SBarry Smith      PetscOptionsTail - Ends a section of options begun with PetscOptionsHead()
13730de9b25SBarry Smith             See, for example, KSPSetFromOptions_GMRES().
13830de9b25SBarry Smith 
13930de9b25SBarry Smith    Collective on the communicator passed in PetscOptionsBegin()
14030de9b25SBarry Smith 
141d360dc6fSBarry Smith    Synopsis: PetscErrorCode PetscOptionsTail(void)
14230de9b25SBarry Smith 
14330de9b25SBarry Smith   Level: intermediate
14430de9b25SBarry Smith 
14530de9b25SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
14630de9b25SBarry Smith 
14730de9b25SBarry Smith           Must be preceded by a call to PetscOptionsHead() in the same function.
14830de9b25SBarry Smith 
149b52f573bSBarry Smith           This needs to be used only if the code below PetscOptionsTail() can be run ONLY once.
150b52f573bSBarry Smith       See, for example, PCSetFromOptions_Composite(). This is a return(0) in it for early exit
151b52f573bSBarry Smith       from the function.
152b52f573bSBarry Smith 
153b52f573bSBarry Smith           This is only for use with the PETSc options GUI; which does not currently exist.
154b52f573bSBarry Smith 
15530de9b25SBarry Smith    Concepts: options database^subheading
15630de9b25SBarry Smith 
15730de9b25SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1584dc4c822SBarry Smith            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
15930de9b25SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
16030de9b25SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1614dc4c822SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
1629dcbbd2bSBarry Smith           PetscOptionsList(), PetscOptionsEList(), PetscOptionsEnum()
16330de9b25SBarry Smith M*/
164b0a32e0cSBarry Smith #define    PetscOptionsTail() 0; {if (PetscOptionsPublishCount != 1) PetscFunctionReturn(0);}
165186905e3SBarry Smith 
166*2ae9f97cSJed Brown EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOptionsEnum(const char[],const char[],const char[],const char *const*,PetscEnum,PetscEnum*,PetscTruth*);
167ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOptionsInt(const char[],const char[],const char[],PetscInt,PetscInt*,PetscTruth*);
168ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOptionsReal(const char[],const char[],const char[],PetscReal,PetscReal*,PetscTruth*);
169ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOptionsScalar(const char[],const char[],const char[],PetscScalar,PetscScalar*,PetscTruth*);
170ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOptionsName(const char[],const char[],const char[],PetscTruth*);
171ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOptionsString(const char[],const char[],const char[],const char[],char*,size_t,PetscTruth*);
1724dc4c822SBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruth(const char[],const char[],const char[],PetscTruth,PetscTruth*,PetscTruth*);
1734dc4c822SBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroupBegin(const char[],const char[],const char[],PetscTruth*);
1744dc4c822SBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroup(const char[],const char[],const char[],PetscTruth*);
1754dc4c822SBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroupEnd(const char[],const char[],const char[],PetscTruth*);
1763cc1e11dSBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOptionsList(const char[],const char[],const char[],PetscFList,const char[],char[],size_t,PetscTruth*);
177*2ae9f97cSJed Brown EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOptionsEList(const char[],const char[],const char[],const char*const*,PetscInt,const char[],PetscInt*,PetscTruth*);
178ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOptionsRealArray(const char[],const char[],const char[],PetscReal[],PetscInt*,PetscTruth*);
179ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOptionsIntArray(const char[],const char[],const char[],PetscInt[],PetscInt*,PetscTruth*);
180ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOptionsStringArray(const char[],const char[],const char[],char*[],PetscInt*,PetscTruth*);
181e2446a98SMatthew Knepley EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthArray(const char[],const char[],const char[],PetscTruth[],PetscInt*,PetscTruth*);
182e9fa29b7SSatish Balay 
183b0a8bb96SLisandro Dalcin EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOptionsSetFromOptions(void);
184e9fa29b7SSatish Balay PETSC_EXTERN_CXX_END
185f8d0b74dSMatthew Knepley 
186e26ddf31SBarry Smith /*
187e26ddf31SBarry Smith     See manual page for PetscOptionsBegin()
188e26ddf31SBarry Smith */
189e26ddf31SBarry Smith typedef enum {OPTION_INT,OPTION_LOGICAL,OPTION_REAL,OPTION_LIST,OPTION_STRING,OPTION_REAL_ARRAY,OPTION_HEAD,OPTION_INT_ARRAY} PetscOptionType;
190e3ed6ec8SBarry Smith typedef struct _p_PetscOptions* PetscOptions;
191e3ed6ec8SBarry Smith struct _p_PetscOptions {
192f8d0b74dSMatthew Knepley   char            *option;
193f8d0b74dSMatthew Knepley   char            *text;
1943cc1e11dSBarry Smith   void            *data;         /* used to hold the default value and then any value it is changed to by GUI */
1953cc1e11dSBarry Smith   PetscFList      flist;         /* used for available values for PetscOptionsList() */
196f8d0b74dSMatthew Knepley   char            *man;
1973cc1e11dSBarry Smith   size_t          arraylength;   /* number of entries in data in the case that it is an array (of PetscInt etc) */
1983cc1e11dSBarry Smith   PetscTruth      set;           /* the user has changed this value in the GUI */
199e3ed6ec8SBarry Smith   PetscOptionType type;
200f8d0b74dSMatthew Knepley   PetscOptions    next;
201f8d0b74dSMatthew Knepley };
202f8d0b74dSMatthew Knepley 
203f8d0b74dSMatthew Knepley typedef struct {
204f8d0b74dSMatthew Knepley   PetscOptions     next;
205f8d0b74dSMatthew Knepley   char             *prefix,*mprefix;
206f8d0b74dSMatthew Knepley   char             *title;
207f8d0b74dSMatthew Knepley   MPI_Comm         comm;
208f8d0b74dSMatthew Knepley   PetscTruth       printhelp,changedmethod,alreadyprinted;
209f8d0b74dSMatthew Knepley } PetscOptionsObjectType;
2103a3b2205SBarry Smith #endif
211