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