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 #include <petscviewertypes.h> 8 9 PETSC_EXTERN PetscErrorCode PetscOptionsHasName(const char[],const char[],PetscBool *); 10 PETSC_EXTERN PetscErrorCode PetscOptionsGetInt(const char[],const char [],PetscInt *,PetscBool *); 11 PETSC_EXTERN PetscErrorCode PetscOptionsGetBool(const char[],const char [],PetscBool *,PetscBool *); 12 PETSC_EXTERN PetscErrorCode PetscOptionsGetReal(const char[],const char[],PetscReal *,PetscBool *); 13 PETSC_EXTERN PetscErrorCode PetscOptionsGetScalar(const char[],const char[],PetscScalar *,PetscBool *); 14 PETSC_EXTERN PetscErrorCode PetscOptionsGetIntArray(const char[],const char[],PetscInt[],PetscInt *,PetscBool *); 15 PETSC_EXTERN PetscErrorCode PetscOptionsGetRealArray(const char[],const char[],PetscReal[],PetscInt *,PetscBool *); 16 PETSC_EXTERN PetscErrorCode PetscOptionsGetScalarArray(const char[],const char[],PetscScalar[],PetscInt *,PetscBool *); 17 PETSC_EXTERN PetscErrorCode PetscOptionsGetBoolArray(const char[],const char[],PetscBool [],PetscInt *,PetscBool *); 18 PETSC_EXTERN PetscErrorCode PetscOptionsGetString(const char[],const char[],char[],size_t,PetscBool *); 19 PETSC_EXTERN PetscErrorCode PetscOptionsGetStringArray(const char[],const char[],char*[],PetscInt*,PetscBool *); 20 PETSC_EXTERN PetscErrorCode PetscOptionsGetEList(const char[],const char[],const char*const*,PetscInt,PetscInt*,PetscBool *); 21 PETSC_EXTERN PetscErrorCode PetscOptionsGetEnum(const char[],const char[],const char*const*,PetscEnum*,PetscBool *); 22 PETSC_EXTERN PetscErrorCode PetscOptionsValidKey(const char[],PetscBool *); 23 24 PETSC_EXTERN PetscErrorCode PetscOptionsSetAlias(const char[],const char[]); 25 PETSC_EXTERN PetscErrorCode PetscOptionsSetValue(const char[],const char[]); 26 PETSC_EXTERN PetscErrorCode PetscOptionsClearValue(const char[]); 27 28 PETSC_EXTERN PetscErrorCode PetscOptionsAllUsed(PetscInt*); 29 PETSC_EXTERN PetscErrorCode PetscOptionsUsed(const char *,PetscBool*); 30 PETSC_EXTERN PetscErrorCode PetscOptionsLeft(void); 31 PETSC_EXTERN PetscErrorCode PetscOptionsView(PetscViewer); 32 33 PETSC_EXTERN PetscErrorCode PetscOptionsCreate(void); 34 PETSC_EXTERN PetscErrorCode PetscOptionsInsert(int*,char ***,const char[]); 35 PETSC_EXTERN PetscErrorCode PetscOptionsInsertFile(MPI_Comm,const char[],PetscBool ); 36 #if defined(PETSC_HAVE_YAML) 37 PETSC_EXTERN PetscErrorCode PetscOptionsInsertFileYAML(MPI_Comm,const char[],PetscBool); 38 #endif 39 PETSC_EXTERN PetscErrorCode PetscOptionsInsertString(const char[]); 40 PETSC_EXTERN PetscErrorCode PetscOptionsDestroy(void); 41 PETSC_EXTERN PetscErrorCode PetscOptionsClear(void); 42 PETSC_EXTERN PetscErrorCode PetscOptionsPrefixPush(const char[]); 43 PETSC_EXTERN PetscErrorCode PetscOptionsPrefixPop(void); 44 45 PETSC_EXTERN PetscErrorCode PetscOptionsReject(const char[],const char[]); 46 PETSC_EXTERN PetscErrorCode PetscOptionsGetAll(char*[]); 47 48 PETSC_EXTERN PetscErrorCode PetscOptionsGetenv(MPI_Comm,const char[],char[],size_t,PetscBool *); 49 PETSC_EXTERN PetscErrorCode PetscOptionsStringToInt(const char[],PetscInt*); 50 PETSC_EXTERN PetscErrorCode PetscOptionsStringToReal(const char[],PetscReal*); 51 PETSC_EXTERN PetscErrorCode PetscOptionsStringToBool(const char[],PetscBool*); 52 53 PETSC_EXTERN PetscErrorCode PetscOptionsMonitorSet(PetscErrorCode (*)(const char[], const char[], void*), void *, PetscErrorCode (*)(void**)); 54 PETSC_EXTERN PetscErrorCode PetscOptionsMonitorCancel(void); 55 PETSC_EXTERN PetscErrorCode PetscOptionsMonitorDefault(const char[], const char[], void *); 56 57 PETSC_EXTERN PetscBool PetscOptionsPublish; 58 59 60 /* 61 See manual page for PetscOptionsBegin() 62 */ 63 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; 64 typedef struct _n_PetscOption* PetscOption; 65 struct _n_PetscOption{ 66 char *option; 67 char *text; 68 void *data; /* used to hold the default value and then any value it is changed to by GUI */ 69 PetscFunctionList flist; /* used for available values for PetscOptionsList() */ 70 const char *const *list; /* used for available values for PetscOptionsEList() */ 71 char nlist; /* number of entries in list */ 72 char *man; 73 size_t arraylength; /* number of entries in data in the case that it is an array (of PetscInt etc) */ 74 PetscBool set; /* the user has changed this value in the GUI */ 75 PetscOptionType type; 76 PetscOption next; 77 char *pman; 78 void *edata; 79 }; 80 81 typedef struct _p_PetscOptions { 82 PetscInt count; 83 PetscOption next; 84 char *prefix,*pprefix; 85 char *title; 86 MPI_Comm comm; 87 PetscBool printhelp,changedmethod,alreadyprinted; 88 PetscObject object; 89 } PetscOptions; 90 91 /*MC 92 PetscOptionsBegin - Begins a set of queries on the options database that are related and should be 93 displayed on the same window of a GUI that allows the user to set the options interactively. Often one should 94 use PetscObjectOptionsBegin() rather than this call. 95 96 Synopsis: 97 #include <petscoptions.h> 98 PetscErrorCode PetscOptionsBegin(MPI_Comm comm,const char prefix[],const char title[],const char mansec[]) 99 100 Collective on MPI_Comm 101 102 Input Parameters: 103 + comm - communicator that shares GUI 104 . prefix - options prefix for all options displayed on window 105 . title - short descriptive text, for example "Krylov Solver Options" 106 - mansec - section of manual pages for options, for example KSP 107 108 Level: intermediate 109 110 Notes: Needs to be ended by a call the PetscOptionsEnd() 111 Can add subheadings with PetscOptionsHead() 112 113 Developer notes: PetscOptionsPublish is set in PetscOptionsCheckInitial_Private() with -saws_options. When PetscOptionsPublish is set the 114 $ loop between PetscOptionsBegin() and PetscOptionsEnd() is run THREE times with PetscOptionsPublishCount of values -1,0,1 otherwise 115 $ the loop is run ONCE with a PetscOptionsPublishCount of 1. 116 $ = -1 : The PetscOptionsInt() etc just call the PetscOptionsGetInt() etc 117 $ = 0 : The GUI objects are created in PetscOptionsInt() etc and displayed in PetscOptionsEnd() and the options 118 $ database updated updated with user changes; PetscOptionsGetInt() etc are also called 119 $ = 1 : The PetscOptionsInt() etc again call the PetscOptionsGetInt() etc (possibly getting new values), in addition the help message and 120 $ default values are printed if -help was given. 121 $ When PetscOptionsObject.changedmethod is set this causes PetscOptionsPublishCount to be reset to -2 (so in the next loop iteration it is -1) 122 $ and the whole process is repeated. This is to handle when, for example, the KSPType is changed thus changing the list of 123 $ options available so they need to be redisplayed so the user can change the. Chaning PetscOptionsObjects.changedmethod is never 124 $ currently set. 125 126 127 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 128 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 129 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 130 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 131 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 132 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 133 PetscOptionsFList(), PetscOptionsEList(), PetscObjectOptionsBegin() 134 135 M*/ 136 #define PetscOptionsBegin(comm,prefix,mess,sec) 0; do {\ 137 PetscOptions PetscOptionsObjectBase;\ 138 PetscOptions *PetscOptionsObject = &PetscOptionsObjectBase; \ 139 PetscMemzero(PetscOptionsObject,sizeof(PetscOptions)); \ 140 for (PetscOptionsObject->count=(PetscOptionsPublish?-1:1); PetscOptionsObject->count<2; PetscOptionsObject->count++) {\ 141 PetscErrorCode _5_ierr = PetscOptionsBegin_Private(PetscOptionsObject,comm,prefix,mess,sec);CHKERRQ(_5_ierr); 142 143 extern PetscClassId KSP_CLASSID,PC_CLASSID; 144 /*MC 145 PetscObjectOptionsBegin - Begins a set of queries on the options database that are related and should be 146 displayed on the same window of a GUI that allows the user to set the options interactively. 147 148 Synopsis: 149 #include <petscoptions.h> 150 PetscErrorCode PetscObjectOptionsBegin(PetscObject obj) 151 152 Collective on PetscObject 153 154 Input Parameters: 155 . obj - object to set options for 156 157 Level: intermediate 158 159 Notes: Needs to be ended by a call the PetscOptionsEnd() 160 Can add subheadings with PetscOptionsHead() 161 162 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 163 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 164 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 165 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 166 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 167 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 168 PetscOptionsFList(), PetscOptionsEList() 169 170 M*/ 171 #define PetscObjectOptionsBegin(obj) 0; do { \ 172 PetscOptions PetscOptionsObjectBase;\ 173 PetscOptions *PetscOptionsObject = &PetscOptionsObjectBase; \ 174 for (PetscOptionsObject->count=(PetscOptionsPublish?-1:1); PetscOptionsObject->count<2; PetscOptionsObject->count++) {\ 175 PetscErrorCode _5_ierr = PetscObjectOptionsBegin_Private(PetscOptionsObject,obj);CHKERRQ(_5_ierr); 176 177 /*MC 178 PetscOptionsEnd - Ends a set of queries on the options database that are related and should be 179 displayed on the same window of a GUI that allows the user to set the options interactively. 180 181 Collective on the MPI_Comm used in PetscOptionsBegin() 182 183 Synopsis: 184 #include <petscoptions.h> 185 PetscErrorCode PetscOptionsEnd(void) 186 187 Level: intermediate 188 189 Notes: Needs to be preceded by a call to PetscOptionsBegin() or PetscObjectOptionsBegin() 190 191 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 192 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 193 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 194 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 195 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 196 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 197 PetscOptionsFList(), PetscOptionsEList(), PetscObjectOptionsBegin() 198 199 M*/ 200 #define PetscOptionsEnd() _5_ierr = PetscOptionsEnd_Private(PetscOptionsObject);CHKERRQ(_5_ierr);}} while (0) 201 202 PETSC_EXTERN PetscErrorCode PetscOptionsBegin_Private(PetscOptions *,MPI_Comm,const char[],const char[],const char[]); 203 PETSC_EXTERN PetscErrorCode PetscObjectOptionsBegin_Private(PetscOptions *,PetscObject); 204 PETSC_EXTERN PetscErrorCode PetscOptionsEnd_Private(PetscOptions *); 205 PETSC_EXTERN PetscErrorCode PetscOptionsHead(PetscOptions *,const char[]); 206 207 /*MC 208 PetscOptionsTail - Ends a section of options begun with PetscOptionsHead() 209 See, for example, KSPSetFromOptions_GMRES(). 210 211 Collective on the communicator passed in PetscOptionsBegin() 212 213 Synopsis: 214 #include <petscoptions.h> 215 PetscErrorCode PetscOptionsTail(void) 216 217 Level: intermediate 218 219 Notes: Must be between a PetscOptionsBegin()/PetscObjectOptionsBegin() and a PetscOptionsEnd() 220 221 Must be preceded by a call to PetscOptionsHead() in the same function. 222 223 This needs to be used only if the code below PetscOptionsTail() can be run ONLY once. 224 See, for example, PCSetFromOptions_Composite(). This is a return(0) in it for early exit 225 from the function. 226 227 This is only for use with the PETSc options GUI; which does not currently exist. 228 229 Concepts: options database^subheading 230 231 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 232 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 233 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 234 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 235 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 236 PetscOptionsFList(), PetscOptionsEList(), PetscOptionsEnum() 237 M*/ 238 #define PetscOptionsTail() 0; {if (PetscOptionsObject->count != 1) PetscFunctionReturn(0);} 239 240 #define PetscOptionsEnum(a,b,c,d,e,f,g) PetscOptionsEnum_Private(PetscOptionsObject,a,b,c,d,e,f,g) 241 #define PetscOptionsInt(a,b,c,d,e,f) PetscOptionsInt_Private(PetscOptionsObject,a,b,c,d,e,f) 242 #define PetscOptionsReal(a,b,c,d,e,f) PetscOptionsReal_Private(PetscOptionsObject,a,b,c,d,e,f) 243 #define PetscOptionsScalar(a,b,c,d,e,f) PetscOptionsScalar_Private(PetscOptionsObject,a,b,c,d,e,f) 244 #define PetscOptionsName(a,b,c,d) PetscOptionsName_Private(PetscOptionsObject,a,b,c,d) 245 #define PetscOptionsString(a,b,c,d,e,f,g) PetscOptionsString_Private(PetscOptionsObject,a,b,c,d,e,f,g) 246 #define PetscOptionsBool(a,b,c,d,e,f) PetscOptionsBool_Private(PetscOptionsObject,a,b,c,d,e,f) 247 #define PetscOptionsBoolGroupBegin(a,b,c,d) PetscOptionsBoolGroupBegin_Private(PetscOptionsObject,a,b,c,d) 248 #define PetscOptionsBoolGroup(a,b,c,d) PetscOptionsBoolGroup_Private(PetscOptionsObject,a,b,c,d) 249 #define PetscOptionsBoolGroupEnd(a,b,c,d) PetscOptionsBoolGroupEnd_Private(PetscOptionsObject,a,b,c,d) 250 #define PetscOptionsFList(a,b,c,d,e,f,g,h) PetscOptionsFList_Private(PetscOptionsObject,a,b,c,d,e,f,g,h) 251 #define PetscOptionsEList(a,b,c,d,e,f,g,h) PetscOptionsEList_Private(PetscOptionsObject,a,b,c,d,e,f,g,h) 252 #define PetscOptionsRealArray(a,b,c,d,e,f) PetscOptionsRealArray_Private(PetscOptionsObject,a,b,c,d,e,f) 253 #define PetscOptionsIntArray(a,b,c,d,e,f) PetscOptionsIntArray_Private(PetscOptionsObject,a,b,c,d,e,f) 254 #define PetscOptionsStringArray(a,b,c,d,e,f) PetscOptionsStringArray_Private(PetscOptionsObject,a,b,c,d,e,f) 255 #define PetscOptionsBoolArray(a,b,c,d,e,f) PetscOptionsBoolArray_Private(PetscOptionsObject,a,b,c,d,e,f) 256 257 258 PETSC_EXTERN PetscErrorCode PetscOptionsEnum_Private(PetscOptions *,const char[],const char[],const char[],const char *const*,PetscEnum,PetscEnum*,PetscBool *); 259 PETSC_EXTERN PetscErrorCode PetscOptionsInt_Private(PetscOptions *,const char[],const char[],const char[],PetscInt,PetscInt*,PetscBool *); 260 PETSC_EXTERN PetscErrorCode PetscOptionsReal_Private(PetscOptions *,const char[],const char[],const char[],PetscReal,PetscReal*,PetscBool *); 261 PETSC_EXTERN PetscErrorCode PetscOptionsScalar_Private(PetscOptions *,const char[],const char[],const char[],PetscScalar,PetscScalar*,PetscBool *); 262 PETSC_EXTERN PetscErrorCode PetscOptionsName_Private(PetscOptions *,const char[],const char[],const char[],PetscBool *); 263 PETSC_EXTERN PetscErrorCode PetscOptionsString_Private(PetscOptions *,const char[],const char[],const char[],const char[],char*,size_t,PetscBool *); 264 PETSC_EXTERN PetscErrorCode PetscOptionsBool_Private(PetscOptions *,const char[],const char[],const char[],PetscBool ,PetscBool *,PetscBool *); 265 PETSC_EXTERN PetscErrorCode PetscOptionsBoolGroupBegin_Private(PetscOptions *,const char[],const char[],const char[],PetscBool *); 266 PETSC_EXTERN PetscErrorCode PetscOptionsBoolGroup_Private(PetscOptions *,const char[],const char[],const char[],PetscBool *); 267 PETSC_EXTERN PetscErrorCode PetscOptionsBoolGroupEnd_Private(PetscOptions *,const char[],const char[],const char[],PetscBool *); 268 PETSC_EXTERN PetscErrorCode PetscOptionsFList_Private(PetscOptions *,const char[],const char[],const char[],PetscFunctionList,const char[],char[],size_t,PetscBool *); 269 PETSC_EXTERN PetscErrorCode PetscOptionsEList_Private(PetscOptions *,const char[],const char[],const char[],const char*const*,PetscInt,const char[],PetscInt*,PetscBool *); 270 PETSC_EXTERN PetscErrorCode PetscOptionsRealArray_Private(PetscOptions *,const char[],const char[],const char[],PetscReal[],PetscInt*,PetscBool *); 271 PETSC_EXTERN PetscErrorCode PetscOptionsIntArray_Private(PetscOptions *,const char[],const char[],const char[],PetscInt[],PetscInt*,PetscBool *); 272 PETSC_EXTERN PetscErrorCode PetscOptionsStringArray_Private(PetscOptions *,const char[],const char[],const char[],char*[],PetscInt*,PetscBool *); 273 PETSC_EXTERN PetscErrorCode PetscOptionsBoolArray_Private(PetscOptions *,const char[],const char[],const char[],PetscBool [],PetscInt*,PetscBool *); 274 275 276 PETSC_EXTERN PetscErrorCode PetscOptionsSetFromOptions(void); 277 PETSC_EXTERN PetscErrorCode PetscOptionsSAWsDestroy(void); 278 279 #endif 280