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 62c8e378dSBarry Smith #include <petscsys.h> 7c619b03eSJed Brown #include <petscviewertypes.h> 83a3b2205SBarry Smith 9014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsHasName(const char[],const char[],PetscBool *); 10014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsGetInt(const char[],const char [],PetscInt *,PetscBool *); 11014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsGetBool(const char[],const char [],PetscBool *,PetscBool *); 12014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsGetReal(const char[],const char[],PetscReal *,PetscBool *); 13014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsGetScalar(const char[],const char[],PetscScalar *,PetscBool *); 14014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsGetIntArray(const char[],const char[],PetscInt[],PetscInt *,PetscBool *); 15014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsGetRealArray(const char[],const char[],PetscReal[],PetscInt *,PetscBool *); 16eb4ae41dSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsGetScalarArray(const char[],const char[],PetscScalar[],PetscInt *,PetscBool *); 17014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsGetBoolArray(const char[],const char[],PetscBool [],PetscInt *,PetscBool *); 18014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsGetString(const char[],const char[],char[],size_t,PetscBool *); 19014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsGetStringArray(const char[],const char[],char*[],PetscInt*,PetscBool *); 20014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsGetEList(const char[],const char[],const char*const*,PetscInt,PetscInt*,PetscBool *); 21014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsGetEnum(const char[],const char[],const char*const*,PetscEnum*,PetscBool *); 22014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsValidKey(const char[],PetscBool *); 233a3b2205SBarry Smith 24014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsSetAlias(const char[],const char[]); 25014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsSetValue(const char[],const char[]); 26014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsClearValue(const char[]); 273a3b2205SBarry Smith 28014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsAllUsed(PetscInt*); 29014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsUsed(const char *,PetscBool*); 30014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsLeft(void); 31014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsView(PetscViewer); 324b0e389bSBarry Smith 33014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsCreate(void); 34014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsInsert(int*,char ***,const char[]); 35014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsInsertFile(MPI_Comm,const char[],PetscBool ); 363bcbd388SSean Farley #if defined(PETSC_HAVE_YAML) 37826011d7SBlaise Bourdin PETSC_EXTERN PetscErrorCode PetscOptionsInsertFileYAML(MPI_Comm,const char[],PetscBool); 383bcbd388SSean Farley #endif 39014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsInsertString(const char[]); 40014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsDestroy(void); 41014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsClear(void); 42014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsPrefixPush(const char[]); 43014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsPrefixPop(void); 445d0dffe5SBarry Smith 45014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsReject(const char[],const char[]); 46014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsGetAll(char*[]); 475d0dffe5SBarry Smith 48014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsGetenv(MPI_Comm,const char[],char[],size_t,PetscBool *); 49014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsStringToInt(const char[],PetscInt*); 50014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsStringToReal(const char[],PetscReal*); 51014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsStringToBool(const char[],PetscBool*); 522e8a6d31SBarry Smith 53014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsMonitorSet(PetscErrorCode (*)(const char[], const char[], void*), void *, PetscErrorCode (*)(void**)); 54014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsMonitorCancel(void); 55014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsMonitorDefault(const char[], const char[], void *); 56081c24baSBoyana Norris 57014dd563SJed Brown PETSC_EXTERN PetscBool PetscOptionsPublish; 58014dd563SJed Brown PETSC_EXTERN PetscInt PetscOptionsPublishCount; 5930de9b25SBarry Smith 6030de9b25SBarry Smith /*MC 6130de9b25SBarry Smith PetscOptionsBegin - Begins a set of queries on the options database that are related and should be 62*1957e957SBarry Smith displayed on the same window of a GUI that allows the user to set the options interactively. Often one should 63*1957e957SBarry Smith use PetscObjectOptionsBegin() rather than this call. 6430de9b25SBarry Smith 65f2ba6396SBarry Smith Synopsis: 66aaa7dc30SBarry Smith #include <petscoptions.h> 67f2ba6396SBarry Smith PetscErrorCode PetscOptionsBegin(MPI_Comm comm,const char prefix[],const char title[],const char mansec[]) 6830de9b25SBarry Smith 6930de9b25SBarry Smith Collective on MPI_Comm 7030de9b25SBarry Smith 7130de9b25SBarry Smith Input Parameters: 7230de9b25SBarry Smith + comm - communicator that shares GUI 7330de9b25SBarry Smith . prefix - options prefix for all options displayed on window 7430de9b25SBarry Smith . title - short descriptive text, for example "Krylov Solver Options" 7530de9b25SBarry Smith - mansec - section of manual pages for options, for example KSP 7630de9b25SBarry Smith 7730de9b25SBarry Smith Level: intermediate 7830de9b25SBarry Smith 7930de9b25SBarry Smith Notes: Needs to be ended by a call the PetscOptionsEnd() 8030de9b25SBarry Smith Can add subheadings with PetscOptionsHead() 8130de9b25SBarry Smith 82e78c4b8cSBarry Smith Developer notes: PetscOptionsPublish is set in PetscOptionsCheckInitial_Private() with -saws_options. When PetscOptionsPublish is set the 83aee2cecaSBarry Smith $ loop between PetscOptionsBegin() and PetscOptionsEnd() is run THREE times with PetscOptionsPublishCount of values -1,0,1 otherwise 84aee2cecaSBarry Smith $ the loop is run ONCE with a PetscOptionsPublishCount of 1. 85aee2cecaSBarry Smith $ = -1 : The PetscOptionsInt() etc just call the PetscOptionsGetInt() etc 86aee2cecaSBarry Smith $ = 0 : The GUI objects are created in PetscOptionsInt() etc and displayed in PetscOptionsEnd() and the options 87c8e70145SBarry Smith $ database updated updated with user changes; PetscOptionsGetInt() etc are also called 88c8e70145SBarry Smith $ = 1 : The PetscOptionsInt() etc again call the PetscOptionsGetInt() etc (possibly getting new values), in addition the help message and 89c8e70145SBarry Smith $ default values are printed if -help was given. 90538aa990SBarry Smith $ When PetscOptionsObject.changedmethod is set this causes PetscOptionsPublishCount to be reset to -2 (so in the next loop iteration it is -1) 91538aa990SBarry Smith $ and the whole process is repeated. This is to handle when, for example, the KSPType is changed thus changing the list of 92538aa990SBarry Smith $ options available so they need to be redisplayed so the user can change the. Chaning PetscOptionsObjects.changedmethod is never 93538aa990SBarry Smith $ currently set. 94aee2cecaSBarry Smith 95aee2cecaSBarry Smith 9630de9b25SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 97acfcf0e5SJed Brown PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 98acfcf0e5SJed Brown PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 9930de9b25SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 10030de9b25SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 101acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 102a264d7a6SBarry Smith PetscOptionsFList(), PetscOptionsEList(), PetscObjectOptionsBegin() 10330de9b25SBarry Smith 10430de9b25SBarry Smith M*/ 1053194b578SJed Brown #define PetscOptionsBegin(comm,prefix,mess,sec) 0; do {\ 106b0a32e0cSBarry Smith for (PetscOptionsPublishCount=(PetscOptionsPublish?-1:1); PetscOptionsPublishCount<2; PetscOptionsPublishCount++) {\ 1077c307921SBarry Smith PetscErrorCode _5_ierr = PetscOptionsBegin_Private(comm,prefix,mess,sec);CHKERRQ(_5_ierr); 10830de9b25SBarry Smith 1095fefd1ebSJed Brown /*MC 1105fefd1ebSJed Brown PetscObjectOptionsBegin - Begins a set of queries on the options database that are related and should be 1115fefd1ebSJed Brown displayed on the same window of a GUI that allows the user to set the options interactively. 1125fefd1ebSJed Brown 113f2ba6396SBarry Smith Synopsis: 114aaa7dc30SBarry Smith #include <petscoptions.h> 115f2ba6396SBarry Smith PetscErrorCode PetscObjectOptionsBegin(PetscObject obj) 1165fefd1ebSJed Brown 1175fefd1ebSJed Brown Collective on PetscObject 1185fefd1ebSJed Brown 1195fefd1ebSJed Brown Input Parameters: 1205fefd1ebSJed Brown . obj - object to set options for 1215fefd1ebSJed Brown 1225fefd1ebSJed Brown Level: intermediate 1235fefd1ebSJed Brown 1245fefd1ebSJed Brown Notes: Needs to be ended by a call the PetscOptionsEnd() 1255fefd1ebSJed Brown Can add subheadings with PetscOptionsHead() 1265fefd1ebSJed Brown 1275fefd1ebSJed Brown .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 1285fefd1ebSJed Brown PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 1295fefd1ebSJed Brown PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 1305fefd1ebSJed Brown PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1315fefd1ebSJed Brown PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1325fefd1ebSJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 133a264d7a6SBarry Smith PetscOptionsFList(), PetscOptionsEList() 1345fefd1ebSJed Brown 1355fefd1ebSJed Brown M*/ 1363194b578SJed Brown #define PetscObjectOptionsBegin(obj) 0; do { \ 1373194b578SJed Brown for (PetscOptionsPublishCount=(PetscOptionsPublish?-1:1); PetscOptionsPublishCount<2; PetscOptionsPublishCount++) { \ 1383194b578SJed Brown PetscErrorCode _5_ierr = PetscObjectOptionsBegin_Private(obj);CHKERRQ(_5_ierr); 1393194b578SJed Brown 14030de9b25SBarry Smith /*MC 14130de9b25SBarry Smith PetscOptionsEnd - Ends a set of queries on the options database that are related and should be 14230de9b25SBarry Smith displayed on the same window of a GUI that allows the user to set the options interactively. 14330de9b25SBarry Smith 14430de9b25SBarry Smith Collective on the MPI_Comm used in PetscOptionsBegin() 14530de9b25SBarry Smith 146f2ba6396SBarry Smith Synopsis: 147aaa7dc30SBarry Smith #include <petscoptions.h> 148f2ba6396SBarry Smith PetscErrorCode PetscOptionsEnd(void) 14930de9b25SBarry Smith 15030de9b25SBarry Smith Level: intermediate 15130de9b25SBarry Smith 152*1957e957SBarry Smith Notes: Needs to be preceded by a call to PetscOptionsBegin() or PetscObjectOptionsBegin() 15330de9b25SBarry Smith 15430de9b25SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 155acfcf0e5SJed Brown PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 156acfcf0e5SJed Brown PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 15730de9b25SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 15830de9b25SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 159acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 160a264d7a6SBarry Smith PetscOptionsFList(), PetscOptionsEList(), PetscObjectOptionsBegin() 16130de9b25SBarry Smith 16230de9b25SBarry Smith M*/ 1633194b578SJed Brown #define PetscOptionsEnd() _5_ierr = PetscOptionsEnd_Private();CHKERRQ(_5_ierr);}} while (0) 16430de9b25SBarry Smith 165014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsBegin_Private(MPI_Comm,const char[],const char[],const char[]); 166014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectOptionsBegin_Private(PetscObject); 167014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsEnd_Private(void); 168014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsHead(const char[]); 16930de9b25SBarry Smith 17030de9b25SBarry Smith /*MC 17130de9b25SBarry Smith PetscOptionsTail - Ends a section of options begun with PetscOptionsHead() 17230de9b25SBarry Smith See, for example, KSPSetFromOptions_GMRES(). 17330de9b25SBarry Smith 17430de9b25SBarry Smith Collective on the communicator passed in PetscOptionsBegin() 17530de9b25SBarry Smith 176f2ba6396SBarry Smith Synopsis: 177aaa7dc30SBarry Smith #include <petscoptions.h> 178f2ba6396SBarry Smith PetscErrorCode PetscOptionsTail(void) 17930de9b25SBarry Smith 18030de9b25SBarry Smith Level: intermediate 18130de9b25SBarry Smith 182*1957e957SBarry Smith Notes: Must be between a PetscOptionsBegin()/PetscObjectOptionsBegin() and a PetscOptionsEnd() 18330de9b25SBarry Smith 18430de9b25SBarry Smith Must be preceded by a call to PetscOptionsHead() in the same function. 18530de9b25SBarry Smith 186b52f573bSBarry Smith This needs to be used only if the code below PetscOptionsTail() can be run ONLY once. 187b52f573bSBarry Smith See, for example, PCSetFromOptions_Composite(). This is a return(0) in it for early exit 188b52f573bSBarry Smith from the function. 189b52f573bSBarry Smith 190b52f573bSBarry Smith This is only for use with the PETSc options GUI; which does not currently exist. 191b52f573bSBarry Smith 19230de9b25SBarry Smith Concepts: options database^subheading 19330de9b25SBarry Smith 19430de9b25SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 195acfcf0e5SJed Brown PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 19630de9b25SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 19730de9b25SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 198acfcf0e5SJed Brown PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 199a264d7a6SBarry Smith PetscOptionsFList(), PetscOptionsEList(), PetscOptionsEnum() 20030de9b25SBarry Smith M*/ 201b0a32e0cSBarry Smith #define PetscOptionsTail() 0; {if (PetscOptionsPublishCount != 1) PetscFunctionReturn(0);} 202186905e3SBarry Smith 203014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsEnum(const char[],const char[],const char[],const char *const*,PetscEnum,PetscEnum*,PetscBool *); 204014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsInt(const char[],const char[],const char[],PetscInt,PetscInt*,PetscBool *); 205014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsReal(const char[],const char[],const char[],PetscReal,PetscReal*,PetscBool *); 206014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsScalar(const char[],const char[],const char[],PetscScalar,PetscScalar*,PetscBool *); 207014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsName(const char[],const char[],const char[],PetscBool *); 208014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsString(const char[],const char[],const char[],const char[],char*,size_t,PetscBool *); 209014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsBool(const char[],const char[],const char[],PetscBool ,PetscBool *,PetscBool *); 210014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsBoolGroupBegin(const char[],const char[],const char[],PetscBool *); 211014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsBoolGroup(const char[],const char[],const char[],PetscBool *); 212014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsBoolGroupEnd(const char[],const char[],const char[],PetscBool *); 213a264d7a6SBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsFList(const char[],const char[],const char[],PetscFunctionList,const char[],char[],size_t,PetscBool *); 214014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsEList(const char[],const char[],const char[],const char*const*,PetscInt,const char[],PetscInt*,PetscBool *); 215014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsRealArray(const char[],const char[],const char[],PetscReal[],PetscInt*,PetscBool *); 216014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsIntArray(const char[],const char[],const char[],PetscInt[],PetscInt*,PetscBool *); 217014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsStringArray(const char[],const char[],const char[],char*[],PetscInt*,PetscBool *); 218014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsBoolArray(const char[],const char[],const char[],PetscBool [],PetscInt*,PetscBool *); 219cffb1e40SBarry Smith 220e9fa29b7SSatish Balay 221014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsSetFromOptions(void); 222e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsSAWsDestroy(void); 223f8d0b74dSMatthew Knepley 224e26ddf31SBarry Smith /* 225e26ddf31SBarry Smith See manual page for PetscOptionsBegin() 226e26ddf31SBarry Smith */ 227a264d7a6SBarry Smith typedef enum {OPTION_INT,OPTION_BOOL,OPTION_REAL,OPTION_FLIST,OPTION_STRING,OPTION_REAL_ARRAY,OPTION_HEAD,OPTION_INT_ARRAY,OPTION_ELIST,OPTION_BOOL_ARRAY,OPTION_STRING_ARRAY} PetscOptionType; 2286e655a9bSJed Brown typedef struct _n_PetscOptions* PetscOptions; 2296e655a9bSJed Brown struct _n_PetscOptions { 230f8d0b74dSMatthew Knepley char *option; 231f8d0b74dSMatthew Knepley char *text; 2323cc1e11dSBarry Smith void *data; /* used to hold the default value and then any value it is changed to by GUI */ 233a264d7a6SBarry Smith PetscFunctionList flist; /* used for available values for PetscOptionsFList() */ 2341ae3d29cSBarry Smith const char *const *list; /* used for available values for PetscOptionsEList() */ 2351ae3d29cSBarry Smith char nlist; /* number of entries in list */ 236f8d0b74dSMatthew Knepley char *man; 2373cc1e11dSBarry Smith size_t arraylength; /* number of entries in data in the case that it is an array (of PetscInt etc) */ 23888a9752cSBarry Smith int set; /* the user has changed this value in the GUI */ 239e3ed6ec8SBarry Smith PetscOptionType type; 240f8d0b74dSMatthew Knepley PetscOptions next; 2411bc75a8dSBarry Smith char *pman; 24271f08665SBarry Smith void *edata; 243f8d0b74dSMatthew Knepley }; 244f8d0b74dSMatthew Knepley 245f8d0b74dSMatthew Knepley typedef struct { 246f8d0b74dSMatthew Knepley PetscOptions next; 2471bc75a8dSBarry Smith char *prefix,*pprefix; 248f8d0b74dSMatthew Knepley char *title; 249f8d0b74dSMatthew Knepley MPI_Comm comm; 250ace3abfcSBarry Smith PetscBool printhelp,changedmethod,alreadyprinted; 2513194b578SJed Brown PetscObject object; 252f8d0b74dSMatthew Knepley } PetscOptionsObjectType; 2533a3b2205SBarry Smith #endif 254