153acd3b1SBarry Smith /* 23fc1eb6aSBarry Smith Implements the higher-level options database querying methods. These are self-documenting and can attach at runtime to 33fc1eb6aSBarry Smith GUI code to display the options and get values from the users. 453acd3b1SBarry Smith 553acd3b1SBarry Smith */ 653acd3b1SBarry Smith 7af0996ceSBarry Smith #include <petsc/private/petscimpl.h> /*I "petscsys.h" I*/ 8665c2dedSJed Brown #include <petscviewer.h> 953acd3b1SBarry Smith 10*10c654e6SJacob Faibussowitsch static const char *ManSection(const char *str) 11*10c654e6SJacob Faibussowitsch { 12*10c654e6SJacob Faibussowitsch return str ? str : "None"; 13*10c654e6SJacob Faibussowitsch } 14*10c654e6SJacob Faibussowitsch 15*10c654e6SJacob Faibussowitsch static const char *Prefix(const char *str) 16*10c654e6SJacob Faibussowitsch { 17*10c654e6SJacob Faibussowitsch return str ? str : ""; 18*10c654e6SJacob Faibussowitsch } 19*10c654e6SJacob Faibussowitsch 20*10c654e6SJacob Faibussowitsch static int ShouldPrintHelp(const PetscOptionItems *opts) 21*10c654e6SJacob Faibussowitsch { 22*10c654e6SJacob Faibussowitsch return opts->printhelp && opts->count == 1 && !opts->alreadyprinted; 23*10c654e6SJacob Faibussowitsch } 242aa6d131SJed Brown 2553acd3b1SBarry Smith /* 2653acd3b1SBarry Smith Keep a linked list of options that have been posted and we are waiting for 273fc1eb6aSBarry Smith user selection. See the manual page for PetscOptionsBegin() 2853acd3b1SBarry Smith 2953acd3b1SBarry Smith Eventually we'll attach this beast to a MPI_Comm 3053acd3b1SBarry Smith */ 31e55864a3SBarry Smith 3253acd3b1SBarry Smith /* 3353acd3b1SBarry Smith Handles setting up the data structure in a call to PetscOptionsBegin() 3453acd3b1SBarry Smith */ 35d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsBegin_Private(PetscOptionItems *PetscOptionsObject, MPI_Comm comm, const char prefix[], const char title[], const char mansec[]) 36d71ae5a4SJacob Faibussowitsch { 3753acd3b1SBarry Smith PetscFunctionBegin; 38064a246eSJacob Faibussowitsch if (prefix) PetscValidCharPointer(prefix, 3); 39064a246eSJacob Faibussowitsch PetscValidCharPointer(title, 4); 40064a246eSJacob Faibussowitsch if (mansec) PetscValidCharPointer(mansec, 5); 410eb63584SBarry Smith if (!PetscOptionsObject->alreadyprinted) { 429566063dSJacob Faibussowitsch if (!PetscOptionsHelpPrintedSingleton) PetscCall(PetscOptionsHelpPrintedCreate(&PetscOptionsHelpPrintedSingleton)); 439566063dSJacob Faibussowitsch PetscCall(PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrintedSingleton, prefix, title, &PetscOptionsObject->alreadyprinted)); 440eb63584SBarry Smith } 4502c9f0b5SLisandro Dalcin PetscOptionsObject->next = NULL; 46e55864a3SBarry Smith PetscOptionsObject->comm = comm; 47e55864a3SBarry Smith PetscOptionsObject->changedmethod = PETSC_FALSE; 48a297a907SKarl Rupp 499566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(prefix, &PetscOptionsObject->prefix)); 509566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(title, &PetscOptionsObject->title)); 5153acd3b1SBarry Smith 529566063dSJacob Faibussowitsch PetscCall(PetscOptionsHasHelp(PetscOptionsObject->options, &PetscOptionsObject->printhelp)); 53*10c654e6SJacob Faibussowitsch if (ShouldPrintHelp(PetscOptionsObject)) PetscCall((*PetscHelpPrintf)(comm, "----------------------------------------\n%s:\n", title)); 543ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 5553acd3b1SBarry Smith } 5653acd3b1SBarry Smith 573194b578SJed Brown /* 583194b578SJed Brown Handles setting up the data structure in a call to PetscObjectOptionsBegin() 593194b578SJed Brown */ 60d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscObjectOptionsBegin_Private(PetscObject obj, PetscOptionItems *PetscOptionsObject) 61d71ae5a4SJacob Faibussowitsch { 623194b578SJed Brown char title[256]; 633194b578SJed Brown PetscBool flg; 643194b578SJed Brown 653194b578SJed Brown PetscFunctionBegin; 66dbbe0bcdSBarry Smith PetscValidPointer(PetscOptionsObject, 2); 67dbbe0bcdSBarry Smith PetscValidHeader(obj, 1); 68e55864a3SBarry Smith PetscOptionsObject->object = obj; 69e55864a3SBarry Smith PetscOptionsObject->alreadyprinted = obj->optionsprinted; 70a297a907SKarl Rupp 719566063dSJacob Faibussowitsch PetscCall(PetscStrcmp(obj->description, obj->class_name, &flg)); 729566063dSJacob Faibussowitsch if (flg) PetscCall(PetscSNPrintf(title, sizeof(title), "%s options", obj->class_name)); 739566063dSJacob Faibussowitsch else PetscCall(PetscSNPrintf(title, sizeof(title), "%s (%s) options", obj->description, obj->class_name)); 749566063dSJacob Faibussowitsch PetscCall(PetscOptionsBegin_Private(PetscOptionsObject, obj->comm, obj->prefix, title, obj->mansec)); 753ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 763194b578SJed Brown } 773194b578SJed Brown 7853acd3b1SBarry Smith /* 7953acd3b1SBarry Smith Handles adding another option to the list of options within this particular PetscOptionsBegin() PetscOptionsEnd() 8053acd3b1SBarry Smith */ 813ba16761SJacob Faibussowitsch static PetscErrorCode PetscOptionItemCreate_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscOptionType t, PetscOptionItem *amsopt) 82d71ae5a4SJacob Faibussowitsch { 833be6e4c3SJed Brown PetscBool valid; 8453acd3b1SBarry Smith 8553acd3b1SBarry Smith PetscFunctionBegin; 869566063dSJacob Faibussowitsch PetscCall(PetscOptionsValidKey(opt, &valid)); 875f80ce2aSJacob Faibussowitsch PetscCheck(valid, PETSC_COMM_WORLD, PETSC_ERR_ARG_INCOMP, "The option '%s' is not a valid key", opt); 883be6e4c3SJed Brown 899566063dSJacob Faibussowitsch PetscCall(PetscNew(amsopt)); 9002c9f0b5SLisandro Dalcin (*amsopt)->next = NULL; 9153acd3b1SBarry Smith (*amsopt)->set = PETSC_FALSE; 926356e834SBarry Smith (*amsopt)->type = t; 9302c9f0b5SLisandro Dalcin (*amsopt)->data = NULL; 9461b37b28SSatish Balay 959566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(text, &(*amsopt)->text)); 969566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(opt, &(*amsopt)->option)); 979566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(man, &(*amsopt)->man)); 9853acd3b1SBarry Smith 99*10c654e6SJacob Faibussowitsch { 100*10c654e6SJacob Faibussowitsch PetscOptionItem cur = PetscOptionsObject->next; 101*10c654e6SJacob Faibussowitsch 102*10c654e6SJacob Faibussowitsch while (cur->next) cur = cur->next; 103*10c654e6SJacob Faibussowitsch cur->next = *amsopt; 10453acd3b1SBarry Smith } 1053ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 10653acd3b1SBarry Smith } 10753acd3b1SBarry Smith 108aee2cecaSBarry Smith /* 1093fc1eb6aSBarry Smith PetscScanString - Gets user input via stdin from process and broadcasts to all processes 1103fc1eb6aSBarry Smith 111d083f849SBarry Smith Collective 1123fc1eb6aSBarry Smith 1133fc1eb6aSBarry Smith Input Parameters: 1143fc1eb6aSBarry Smith + commm - communicator for the broadcast, must be PETSC_COMM_WORLD 1153fc1eb6aSBarry Smith . n - length of the string, must be the same on all processes 1163fc1eb6aSBarry Smith - str - location to store input 117aee2cecaSBarry Smith 118aee2cecaSBarry Smith Bugs: 119aee2cecaSBarry Smith . Assumes process 0 of the given communicator has access to stdin 120aee2cecaSBarry Smith 121aee2cecaSBarry Smith */ 122d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscScanString(MPI_Comm comm, size_t n, char str[]) 123d71ae5a4SJacob Faibussowitsch { 1243fc1eb6aSBarry Smith PetscMPIInt rank, nm; 125aee2cecaSBarry Smith 126aee2cecaSBarry Smith PetscFunctionBegin; 1279566063dSJacob Faibussowitsch PetscCallMPI(MPI_Comm_rank(comm, &rank)); 128dd400576SPatrick Sanan if (rank == 0) { 1295f80ce2aSJacob Faibussowitsch char c = (char)getchar(); 1305f80ce2aSJacob Faibussowitsch size_t i = 0; 1315f80ce2aSJacob Faibussowitsch 132aee2cecaSBarry Smith while (c != '\n' && i < n - 1) { 133aee2cecaSBarry Smith str[i++] = c; 134aee2cecaSBarry Smith c = (char)getchar(); 135aee2cecaSBarry Smith } 136*10c654e6SJacob Faibussowitsch str[i] = '\0'; 137aee2cecaSBarry Smith } 1389566063dSJacob Faibussowitsch PetscCall(PetscMPIIntCast(n, &nm)); 1399566063dSJacob Faibussowitsch PetscCallMPI(MPI_Bcast(str, nm, MPI_CHAR, 0, comm)); 1403ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 141aee2cecaSBarry Smith } 142aee2cecaSBarry Smith 1435b02f95dSBarry Smith /* 1445b02f95dSBarry Smith This is needed because certain strings may be freed by SAWs, hence we cannot use PetscStrallocpy() 1455b02f95dSBarry Smith */ 146d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscStrdup(const char s[], char *t[]) 147d71ae5a4SJacob Faibussowitsch { 14802c9f0b5SLisandro Dalcin char *tmp = NULL; 1495b02f95dSBarry Smith 1505b02f95dSBarry Smith PetscFunctionBegin; 1515b02f95dSBarry Smith if (s) { 1525f80ce2aSJacob Faibussowitsch size_t len; 1535f80ce2aSJacob Faibussowitsch 1549566063dSJacob Faibussowitsch PetscCall(PetscStrlen(s, &len)); 1555f80ce2aSJacob Faibussowitsch tmp = (char *)malloc((len + 1) * sizeof(*tmp)); 1565f80ce2aSJacob Faibussowitsch PetscCheck(tmp, PETSC_COMM_SELF, PETSC_ERR_MEM, "No memory to duplicate string"); 157363da2dcSJacob Faibussowitsch PetscCall(PetscArraycpy(tmp, s, len + 1)); 1585b02f95dSBarry Smith } 1595b02f95dSBarry Smith *t = tmp; 1603ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1615b02f95dSBarry Smith } 1625b02f95dSBarry Smith 163aee2cecaSBarry Smith /* 1643cc1e11dSBarry Smith PetscOptionsGetFromTextInput - Presents all the PETSc Options processed by the program so the user may change them at runtime 165aee2cecaSBarry Smith 16695452b02SPatrick Sanan Notes: 16795452b02SPatrick Sanan this isn't really practical, it is just to demonstrate the principle 168aee2cecaSBarry Smith 1697781c08eSBarry Smith A carriage return indicates no change from the default; but this like -ksp_monitor <stdout> the default is actually not stdout the default 1707781c08eSBarry Smith is to do nothing so to get it to use stdout you need to type stdout. This is kind of bug? 1717781c08eSBarry Smith 172aee2cecaSBarry Smith Bugs: 1737781c08eSBarry Smith + All processes must traverse through the exact same set of option queries due to the call to PetscScanString() 1743cc1e11dSBarry Smith . Internal strings have arbitrary length and string copies are not checked that they fit into string space 175aee2cecaSBarry Smith - Only works for PetscInt == int, PetscReal == double etc 176aee2cecaSBarry Smith 177811af0c4SBarry Smith Developer Note: 17895452b02SPatrick Sanan Normally the GUI that presents the options the user and retrieves the values would be running in a different 1793cc1e11dSBarry Smith address space and communicating with the PETSc program 1803cc1e11dSBarry Smith 181aee2cecaSBarry Smith */ 182d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsGetFromTextInput(PetscOptionItems *PetscOptionsObject) 183d71ae5a4SJacob Faibussowitsch { 1844416b707SBarry Smith PetscOptionItem next = PetscOptionsObject->next; 1856356e834SBarry Smith char str[512]; 1867781c08eSBarry Smith PetscBool bid; 187a4404d99SBarry Smith PetscReal ir, *valr; 188330cf3c9SBarry Smith PetscInt *vald; 189330cf3c9SBarry Smith size_t i; 1906356e834SBarry Smith 1912a409bb0SBarry Smith PetscFunctionBegin; 1929566063dSJacob Faibussowitsch PetscCall((*PetscPrintf)(PETSC_COMM_WORLD, "%s --------------------\n", PetscOptionsObject->title)); 1936356e834SBarry Smith while (next) { 1946356e834SBarry Smith switch (next->type) { 195d71ae5a4SJacob Faibussowitsch case OPTION_HEAD: 196d71ae5a4SJacob Faibussowitsch break; 197e26ddf31SBarry Smith case OPTION_INT_ARRAY: 1984bb2516aSBarry Smith PetscCall(PetscPrintf(PETSC_COMM_WORLD, "-%s%s: <", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1)); 199e26ddf31SBarry Smith vald = (PetscInt *)next->data; 200e26ddf31SBarry Smith for (i = 0; i < next->arraylength; i++) { 2019566063dSJacob Faibussowitsch PetscCall(PetscPrintf(PETSC_COMM_WORLD, "%" PetscInt_FMT, vald[i])); 20248a46eb9SPierre Jolivet if (i < next->arraylength - 1) PetscCall(PetscPrintf(PETSC_COMM_WORLD, ",")); 203e26ddf31SBarry Smith } 2049566063dSJacob Faibussowitsch PetscCall(PetscPrintf(PETSC_COMM_WORLD, ">: %s (%s) ", next->text, next->man)); 2059566063dSJacob Faibussowitsch PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str)); 206e26ddf31SBarry Smith if (str[0]) { 207e26ddf31SBarry Smith PetscToken token; 208e26ddf31SBarry Smith PetscInt n = 0, nmax = next->arraylength, *dvalue = (PetscInt *)next->data, start, end; 209e26ddf31SBarry Smith size_t len; 210e26ddf31SBarry Smith char *value; 211ace3abfcSBarry Smith PetscBool foundrange; 212e26ddf31SBarry Smith 213e26ddf31SBarry Smith next->set = PETSC_TRUE; 214e26ddf31SBarry Smith value = str; 2159566063dSJacob Faibussowitsch PetscCall(PetscTokenCreate(value, ',', &token)); 2169566063dSJacob Faibussowitsch PetscCall(PetscTokenFind(token, &value)); 217e26ddf31SBarry Smith while (n < nmax) { 218e26ddf31SBarry Smith if (!value) break; 219e26ddf31SBarry Smith 220e26ddf31SBarry Smith /* look for form d-D where d and D are integers */ 221e26ddf31SBarry Smith foundrange = PETSC_FALSE; 2229566063dSJacob Faibussowitsch PetscCall(PetscStrlen(value, &len)); 223e26ddf31SBarry Smith if (value[0] == '-') i = 2; 224e26ddf31SBarry Smith else i = 1; 225330cf3c9SBarry Smith for (; i < len; i++) { 226e26ddf31SBarry Smith if (value[i] == '-') { 22708401ef6SPierre Jolivet PetscCheck(i != len - 1, PETSC_COMM_SELF, PETSC_ERR_USER, "Error in %" PetscInt_FMT "-th array entry %s", n, value); 228e26ddf31SBarry Smith value[i] = 0; 2299566063dSJacob Faibussowitsch PetscCall(PetscOptionsStringToInt(value, &start)); 2309566063dSJacob Faibussowitsch PetscCall(PetscOptionsStringToInt(value + i + 1, &end)); 23108401ef6SPierre Jolivet PetscCheck(end > start, PETSC_COMM_SELF, PETSC_ERR_USER, "Error in %" PetscInt_FMT "-th array entry, %s-%s cannot have decreasing list", n, value, value + i + 1); 232cc73adaaSBarry Smith PetscCheck(n + end - start - 1 < nmax, PETSC_COMM_SELF, PETSC_ERR_USER, "Error in %" PetscInt_FMT "-th array entry, not enough space in left in array (%" PetscInt_FMT ") to contain entire range from %" PetscInt_FMT " to %" PetscInt_FMT, n, nmax - n, start, end); 233e26ddf31SBarry Smith for (; start < end; start++) { 2349371c9d4SSatish Balay *dvalue = start; 2359371c9d4SSatish Balay dvalue++; 2369371c9d4SSatish Balay n++; 237e26ddf31SBarry Smith } 238e26ddf31SBarry Smith foundrange = PETSC_TRUE; 239e26ddf31SBarry Smith break; 240e26ddf31SBarry Smith } 241e26ddf31SBarry Smith } 242e26ddf31SBarry Smith if (!foundrange) { 2439566063dSJacob Faibussowitsch PetscCall(PetscOptionsStringToInt(value, dvalue)); 244e26ddf31SBarry Smith dvalue++; 245e26ddf31SBarry Smith n++; 246e26ddf31SBarry Smith } 2479566063dSJacob Faibussowitsch PetscCall(PetscTokenFind(token, &value)); 248e26ddf31SBarry Smith } 2499566063dSJacob Faibussowitsch PetscCall(PetscTokenDestroy(&token)); 250e26ddf31SBarry Smith } 251e26ddf31SBarry Smith break; 252e26ddf31SBarry Smith case OPTION_REAL_ARRAY: 2534bb2516aSBarry Smith PetscCall(PetscPrintf(PETSC_COMM_WORLD, "-%s%s: <", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1)); 254e26ddf31SBarry Smith valr = (PetscReal *)next->data; 255e26ddf31SBarry Smith for (i = 0; i < next->arraylength; i++) { 2569566063dSJacob Faibussowitsch PetscCall(PetscPrintf(PETSC_COMM_WORLD, "%g", (double)valr[i])); 25748a46eb9SPierre Jolivet if (i < next->arraylength - 1) PetscCall(PetscPrintf(PETSC_COMM_WORLD, ",")); 258e26ddf31SBarry Smith } 2599566063dSJacob Faibussowitsch PetscCall(PetscPrintf(PETSC_COMM_WORLD, ">: %s (%s) ", next->text, next->man)); 2609566063dSJacob Faibussowitsch PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str)); 261e26ddf31SBarry Smith if (str[0]) { 262e26ddf31SBarry Smith PetscToken token; 263e26ddf31SBarry Smith PetscInt n = 0, nmax = next->arraylength; 264e26ddf31SBarry Smith PetscReal *dvalue = (PetscReal *)next->data; 265e26ddf31SBarry Smith char *value; 266e26ddf31SBarry Smith 267e26ddf31SBarry Smith next->set = PETSC_TRUE; 268e26ddf31SBarry Smith value = str; 2699566063dSJacob Faibussowitsch PetscCall(PetscTokenCreate(value, ',', &token)); 2709566063dSJacob Faibussowitsch PetscCall(PetscTokenFind(token, &value)); 271e26ddf31SBarry Smith while (n < nmax) { 272e26ddf31SBarry Smith if (!value) break; 2739566063dSJacob Faibussowitsch PetscCall(PetscOptionsStringToReal(value, dvalue)); 274e26ddf31SBarry Smith dvalue++; 275e26ddf31SBarry Smith n++; 2769566063dSJacob Faibussowitsch PetscCall(PetscTokenFind(token, &value)); 277e26ddf31SBarry Smith } 2789566063dSJacob Faibussowitsch PetscCall(PetscTokenDestroy(&token)); 279e26ddf31SBarry Smith } 280e26ddf31SBarry Smith break; 2816356e834SBarry Smith case OPTION_INT: 2824bb2516aSBarry Smith PetscCall(PetscPrintf(PETSC_COMM_WORLD, "-%s%s: <%d>: %s (%s) ", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1, *(int *)next->data, next->text, next->man)); 2839566063dSJacob Faibussowitsch PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str)); 2843fc1eb6aSBarry Smith if (str[0]) { 285d25d7f95SJed Brown #if defined(PETSC_SIZEOF_LONG_LONG) 286d25d7f95SJed Brown long long lid; 287d25d7f95SJed Brown sscanf(str, "%lld", &lid); 288cc73adaaSBarry Smith PetscCheck(lid <= PETSC_MAX_INT && lid >= PETSC_MIN_INT, PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE, "Argument: -%s%s %lld", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1, lid); 289c272547aSJed Brown #else 290d25d7f95SJed Brown long lid; 291d25d7f95SJed Brown sscanf(str, "%ld", &lid); 292cc73adaaSBarry Smith PetscCheck(lid <= PETSC_MAX_INT && lid >= PETSC_MIN_INT, PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE, "Argument: -%s%s %ld", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1, lid); 293c272547aSJed Brown #endif 294a297a907SKarl Rupp 295d25d7f95SJed Brown next->set = PETSC_TRUE; 296d25d7f95SJed Brown *((PetscInt *)next->data) = (PetscInt)lid; 297aee2cecaSBarry Smith } 298aee2cecaSBarry Smith break; 299aee2cecaSBarry Smith case OPTION_REAL: 3004bb2516aSBarry Smith PetscCall(PetscPrintf(PETSC_COMM_WORLD, "-%s%s: <%g>: %s (%s) ", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1, *(double *)next->data, next->text, next->man)); 3019566063dSJacob Faibussowitsch PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str)); 3023fc1eb6aSBarry Smith if (str[0]) { 303ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE) 304a4404d99SBarry Smith sscanf(str, "%e", &ir); 305570b7f6dSBarry Smith #elif defined(PETSC_USE_REAL___FP16) 306570b7f6dSBarry Smith float irtemp; 307570b7f6dSBarry Smith sscanf(str, "%e", &irtemp); 308570b7f6dSBarry Smith ir = irtemp; 309ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE) 310aee2cecaSBarry Smith sscanf(str, "%le", &ir); 311ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL___FLOAT128) 312d9822059SBarry Smith ir = strtoflt128(str, 0); 313d9822059SBarry Smith #else 314513dbe71SLisandro Dalcin SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, "Unknown scalar type"); 315a4404d99SBarry Smith #endif 316aee2cecaSBarry Smith next->set = PETSC_TRUE; 317aee2cecaSBarry Smith *((PetscReal *)next->data) = ir; 318aee2cecaSBarry Smith } 319aee2cecaSBarry Smith break; 3207781c08eSBarry Smith case OPTION_BOOL: 3214bb2516aSBarry Smith PetscCall(PetscPrintf(PETSC_COMM_WORLD, "-%s%s: <%s>: %s (%s) ", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1, *(PetscBool *)next->data ? "true" : "false", next->text, next->man)); 3229566063dSJacob Faibussowitsch PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str)); 3237781c08eSBarry Smith if (str[0]) { 3249566063dSJacob Faibussowitsch PetscCall(PetscOptionsStringToBool(str, &bid)); 3257781c08eSBarry Smith next->set = PETSC_TRUE; 3267781c08eSBarry Smith *((PetscBool *)next->data) = bid; 3277781c08eSBarry Smith } 3287781c08eSBarry Smith break; 329aee2cecaSBarry Smith case OPTION_STRING: 3304bb2516aSBarry Smith PetscCall(PetscPrintf(PETSC_COMM_WORLD, "-%s%s: <%s>: %s (%s) ", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1, (char *)next->data, next->text, next->man)); 3319566063dSJacob Faibussowitsch PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str)); 3323fc1eb6aSBarry Smith if (str[0]) { 333aee2cecaSBarry Smith next->set = PETSC_TRUE; 33464facd6cSBarry Smith /* must use system malloc since SAWs may free this */ 3359566063dSJacob Faibussowitsch PetscCall(PetscStrdup(str, (char **)&next->data)); 3366356e834SBarry Smith } 3376356e834SBarry Smith break; 338a264d7a6SBarry Smith case OPTION_FLIST: 3399566063dSJacob Faibussowitsch PetscCall(PetscFunctionListPrintTypes(PETSC_COMM_WORLD, stdout, PetscOptionsObject->prefix, next->option, next->text, next->man, next->flist, (char *)next->data, (char *)next->data)); 3409566063dSJacob Faibussowitsch PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str)); 3413cc1e11dSBarry Smith if (str[0]) { 342e55864a3SBarry Smith PetscOptionsObject->changedmethod = PETSC_TRUE; 3433cc1e11dSBarry Smith next->set = PETSC_TRUE; 34464facd6cSBarry Smith /* must use system malloc since SAWs may free this */ 3459566063dSJacob Faibussowitsch PetscCall(PetscStrdup(str, (char **)&next->data)); 3463cc1e11dSBarry Smith } 3473cc1e11dSBarry Smith break; 348d71ae5a4SJacob Faibussowitsch default: 349d71ae5a4SJacob Faibussowitsch break; 3506356e834SBarry Smith } 3516356e834SBarry Smith next = next->next; 3526356e834SBarry Smith } 3533ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3546356e834SBarry Smith } 3556356e834SBarry Smith 356e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 357e04113cfSBarry Smith #include <petscviewersaws.h> 358d5649816SBarry Smith 359d5649816SBarry Smith static int count = 0; 360d5649816SBarry Smith 361d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsSAWsDestroy(void) 362d71ae5a4SJacob Faibussowitsch { 3632657e9d9SBarry Smith PetscFunctionBegin; 3643ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 365d5649816SBarry Smith } 366d5649816SBarry Smith 3679c1e0ce8SBarry Smith static const char *OptionsHeader = "<head>\n" 368a8d69d7bSBarry Smith "<script type=\"text/javascript\" src=\"https://www.mcs.anl.gov/research/projects/saws/js/jquery-1.9.1.js\"></script>\n" 369a8d69d7bSBarry Smith "<script type=\"text/javascript\" src=\"https://www.mcs.anl.gov/research/projects/saws/js/SAWs.js\"></script>\n" 370d1fc0251SBarry Smith "<script type=\"text/javascript\" src=\"js/PETSc.js\"></script>\n" 37164bbc9efSBarry Smith "<script>\n" 37264bbc9efSBarry Smith "jQuery(document).ready(function() {\n" 37364bbc9efSBarry Smith "PETSc.getAndDisplayDirectory(null,\"#variablesInfo\")\n" 37464bbc9efSBarry Smith "})\n" 37564bbc9efSBarry Smith "</script>\n" 37664bbc9efSBarry Smith "</head>\n"; 3771423471aSBarry Smith 3781423471aSBarry Smith /* Determines the size and style of the scroll region where PETSc options selectable from users are displayed */ 3791423471aSBarry Smith static const char *OptionsBodyBottom = "<div id=\"variablesInfo\" style=\"background-color:lightblue;height:auto;max-height:500px;overflow:scroll;\"></div>\n<br>\n</body>"; 38064bbc9efSBarry Smith 381b3506946SBarry Smith /* 3827781c08eSBarry Smith PetscOptionsSAWsInput - Presents all the PETSc Options processed by the program so the user may change them at runtime using the SAWs 383b3506946SBarry Smith 384b3506946SBarry Smith Bugs: 385bf31d2d3SBarry Smith + All processes must traverse through the exact same set of option queries due to the call to PetscScanString() 386b3506946SBarry Smith . Internal strings have arbitrary length and string copies are not checked that they fit into string space 387b3506946SBarry Smith - Only works for PetscInt == int, PetscReal == double etc 388b3506946SBarry Smith 389b3506946SBarry Smith */ 390d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsSAWsInput(PetscOptionItems *PetscOptionsObject) 391d71ae5a4SJacob Faibussowitsch { 3924416b707SBarry Smith PetscOptionItem next = PetscOptionsObject->next; 393d5649816SBarry Smith static int mancount = 0; 394b3506946SBarry Smith char options[16]; 3957aab2a10SBarry Smith PetscBool changedmethod = PETSC_FALSE; 396a23eb982SSurtai Han PetscBool stopasking = PETSC_FALSE; 39788a9752cSBarry Smith char manname[16], textname[16]; 3982657e9d9SBarry Smith char dir[1024]; 399b3506946SBarry Smith 4002a409bb0SBarry Smith PetscFunctionBegin; 401b3506946SBarry Smith /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */ 402a364092eSJacob Faibussowitsch PetscCall(PetscSNPrintf(options, PETSC_STATIC_ARRAY_LENGTH(options), "Options_%d", count++)); 403a297a907SKarl Rupp 4047325c4a4SBarry Smith PetscOptionsObject->pprefix = PetscOptionsObject->prefix; /* SAWs will change this, so cannot pass prefix directly */ 4051bc75a8dSBarry Smith 4069566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", "_title")); 407792fecdfSBarry Smith PetscCallSAWs(SAWs_Register, (dir, &PetscOptionsObject->title, 1, SAWs_READ, SAWs_STRING)); 4089566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", "prefix")); 409792fecdfSBarry Smith PetscCallSAWs(SAWs_Register, (dir, &PetscOptionsObject->pprefix, 1, SAWs_READ, SAWs_STRING)); 410792fecdfSBarry Smith PetscCallSAWs(SAWs_Register, ("/PETSc/Options/ChangedMethod", &changedmethod, 1, SAWs_WRITE, SAWs_BOOLEAN)); 411792fecdfSBarry Smith PetscCallSAWs(SAWs_Register, ("/PETSc/Options/StopAsking", &stopasking, 1, SAWs_WRITE, SAWs_BOOLEAN)); 412b3506946SBarry Smith 413b3506946SBarry Smith while (next) { 414a364092eSJacob Faibussowitsch PetscCall(PetscSNPrintf(manname, PETSC_STATIC_ARRAY_LENGTH(manname), "_man_%d", mancount)); 4159566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", manname)); 416792fecdfSBarry Smith PetscCallSAWs(SAWs_Register, (dir, &next->man, 1, SAWs_READ, SAWs_STRING)); 417a364092eSJacob Faibussowitsch PetscCall(PetscSNPrintf(textname, PETSC_STATIC_ARRAY_LENGTH(textname), "_text_%d", mancount++)); 4189566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", textname)); 419792fecdfSBarry Smith PetscCallSAWs(SAWs_Register, (dir, &next->text, 1, SAWs_READ, SAWs_STRING)); 4209f32e415SBarry Smith 421b3506946SBarry Smith switch (next->type) { 422d71ae5a4SJacob Faibussowitsch case OPTION_HEAD: 423d71ae5a4SJacob Faibussowitsch break; 424b3506946SBarry Smith case OPTION_INT_ARRAY: 4259566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option)); 426792fecdfSBarry Smith PetscCallSAWs(SAWs_Register, (dir, next->data, next->arraylength, SAWs_WRITE, SAWs_INT)); 427b3506946SBarry Smith break; 428b3506946SBarry Smith case OPTION_REAL_ARRAY: 4299566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option)); 430792fecdfSBarry Smith PetscCallSAWs(SAWs_Register, (dir, next->data, next->arraylength, SAWs_WRITE, SAWs_DOUBLE)); 431b3506946SBarry Smith break; 432b3506946SBarry Smith case OPTION_INT: 4339566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option)); 434792fecdfSBarry Smith PetscCallSAWs(SAWs_Register, (dir, next->data, 1, SAWs_WRITE, SAWs_INT)); 435b3506946SBarry Smith break; 436b3506946SBarry Smith case OPTION_REAL: 4379566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option)); 438792fecdfSBarry Smith PetscCallSAWs(SAWs_Register, (dir, next->data, 1, SAWs_WRITE, SAWs_DOUBLE)); 439b3506946SBarry Smith break; 4407781c08eSBarry Smith case OPTION_BOOL: 4419566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option)); 442792fecdfSBarry Smith PetscCallSAWs(SAWs_Register, (dir, next->data, 1, SAWs_WRITE, SAWs_BOOLEAN)); 4431ae3d29cSBarry Smith break; 4447781c08eSBarry Smith case OPTION_BOOL_ARRAY: 4459566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option)); 446792fecdfSBarry Smith PetscCallSAWs(SAWs_Register, (dir, next->data, next->arraylength, SAWs_WRITE, SAWs_BOOLEAN)); 44771f08665SBarry Smith break; 448b3506946SBarry Smith case OPTION_STRING: 4499566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option)); 450792fecdfSBarry Smith PetscCallSAWs(SAWs_Register, (dir, &next->data, 1, SAWs_WRITE, SAWs_STRING)); 4511ae3d29cSBarry Smith break; 4521ae3d29cSBarry Smith case OPTION_STRING_ARRAY: 4539566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option)); 454792fecdfSBarry Smith PetscCallSAWs(SAWs_Register, (dir, next->data, next->arraylength, SAWs_WRITE, SAWs_STRING)); 455b3506946SBarry Smith break; 4569371c9d4SSatish Balay case OPTION_FLIST: { 457a264d7a6SBarry Smith PetscInt ntext; 4589566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option)); 459792fecdfSBarry Smith PetscCallSAWs(SAWs_Register, (dir, &next->data, 1, SAWs_WRITE, SAWs_STRING)); 4609566063dSJacob Faibussowitsch PetscCall(PetscFunctionListGet(next->flist, (const char ***)&next->edata, &ntext)); 461792fecdfSBarry Smith PetscCallSAWs(SAWs_Set_Legal_Variable_Values, (dir, ntext, next->edata)); 4629371c9d4SSatish Balay } break; 4639371c9d4SSatish Balay case OPTION_ELIST: { 464a264d7a6SBarry Smith PetscInt ntext = next->nlist; 4659566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option)); 466792fecdfSBarry Smith PetscCallSAWs(SAWs_Register, (dir, &next->data, 1, SAWs_WRITE, SAWs_STRING)); 4679566063dSJacob Faibussowitsch PetscCall(PetscMalloc1((ntext + 1), (char ***)&next->edata)); 4689566063dSJacob Faibussowitsch PetscCall(PetscMemcpy(next->edata, next->list, ntext * sizeof(char *))); 469792fecdfSBarry Smith PetscCallSAWs(SAWs_Set_Legal_Variable_Values, (dir, ntext, next->edata)); 4709371c9d4SSatish Balay } break; 471d71ae5a4SJacob Faibussowitsch default: 472d71ae5a4SJacob Faibussowitsch break; 473b3506946SBarry Smith } 474b3506946SBarry Smith next = next->next; 475b3506946SBarry Smith } 476b3506946SBarry Smith 477b3506946SBarry Smith /* wait until accessor has unlocked the memory */ 478792fecdfSBarry Smith PetscCallSAWs(SAWs_Push_Header, ("index.html", OptionsHeader)); 479792fecdfSBarry Smith PetscCallSAWs(SAWs_Push_Body, ("index.html", 2, OptionsBodyBottom)); 4809566063dSJacob Faibussowitsch PetscCall(PetscSAWsBlock()); 481792fecdfSBarry Smith PetscCallSAWs(SAWs_Pop_Header, ("index.html")); 482792fecdfSBarry Smith PetscCallSAWs(SAWs_Pop_Body, ("index.html", 2)); 483b3506946SBarry Smith 48488a9752cSBarry Smith /* determine if any values have been set in GUI */ 48583355fc5SBarry Smith next = PetscOptionsObject->next; 48688a9752cSBarry Smith while (next) { 4879566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option)); 488792fecdfSBarry Smith PetscCallSAWs(SAWs_Selected, (dir, (int *)&next->set)); 48988a9752cSBarry Smith next = next->next; 49088a9752cSBarry Smith } 49188a9752cSBarry Smith 492b3506946SBarry Smith /* reset counter to -2; this updates the screen with the new options for the selected method */ 493f7b25cf6SBarry Smith if (changedmethod) PetscOptionsObject->count = -2; 494b3506946SBarry Smith 495a23eb982SSurtai Han if (stopasking) { 496a23eb982SSurtai Han PetscOptionsPublish = PETSC_FALSE; 49712655325SBarry Smith PetscOptionsObject->count = 0; //do not ask for same thing again 498a23eb982SSurtai Han } 499a23eb982SSurtai Han 500792fecdfSBarry Smith PetscCallSAWs(SAWs_Delete, ("/PETSc/Options")); 5013ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 502b3506946SBarry Smith } 503b3506946SBarry Smith #endif 504b3506946SBarry Smith 505d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsEnd_Private(PetscOptionItems *PetscOptionsObject) 506d71ae5a4SJacob Faibussowitsch { 507*10c654e6SJacob Faibussowitsch PetscOptionItem next, last; 50853acd3b1SBarry Smith 50953acd3b1SBarry Smith PetscFunctionBegin; 51083355fc5SBarry Smith if (PetscOptionsObject->next) { 51183355fc5SBarry Smith if (!PetscOptionsObject->count) { 512a264d7a6SBarry Smith #if defined(PETSC_HAVE_SAWS) 5139566063dSJacob Faibussowitsch PetscCall(PetscOptionsSAWsInput(PetscOptionsObject)); 514b3506946SBarry Smith #else 5159566063dSJacob Faibussowitsch PetscCall(PetscOptionsGetFromTextInput(PetscOptionsObject)); 516b3506946SBarry Smith #endif 517aee2cecaSBarry Smith } 518aee2cecaSBarry Smith } 5196356e834SBarry Smith 5209566063dSJacob Faibussowitsch PetscCall(PetscFree(PetscOptionsObject->title)); 5216356e834SBarry Smith 522e26ddf31SBarry Smith /* reset counter to -2; this updates the screen with the new options for the selected method */ 523e55864a3SBarry Smith if (PetscOptionsObject->changedmethod) PetscOptionsObject->count = -2; 5247a72a596SBarry Smith /* reset alreadyprinted flag */ 525e55864a3SBarry Smith PetscOptionsObject->alreadyprinted = PETSC_FALSE; 526e55864a3SBarry Smith if (PetscOptionsObject->object) PetscOptionsObject->object->optionsprinted = PETSC_TRUE; 527e55864a3SBarry Smith PetscOptionsObject->object = NULL; 52853acd3b1SBarry Smith 529*10c654e6SJacob Faibussowitsch while ((next = PetscOptionsObject->next)) { 530*10c654e6SJacob Faibussowitsch const PetscOptionType type = next->type; 531*10c654e6SJacob Faibussowitsch const size_t arraylength = next->arraylength; 532*10c654e6SJacob Faibussowitsch void *data = next->data; 533*10c654e6SJacob Faibussowitsch 534*10c654e6SJacob Faibussowitsch if (next->set) { 535*10c654e6SJacob Faibussowitsch char option[256], value[1024], tmp[32]; 536*10c654e6SJacob Faibussowitsch 537e55864a3SBarry Smith if (PetscOptionsObject->prefix) { 538c6a7a370SJeremy L Thompson PetscCall(PetscStrncpy(option, "-", sizeof(option))); 539c6a7a370SJeremy L Thompson PetscCall(PetscStrlcat(option, PetscOptionsObject->prefix, sizeof(option))); 540*10c654e6SJacob Faibussowitsch PetscCall(PetscStrlcat(option, next->option + 1, sizeof(option))); 541*10c654e6SJacob Faibussowitsch } else { 542*10c654e6SJacob Faibussowitsch PetscCall(PetscStrncpy(option, next->option, sizeof(option))); 543*10c654e6SJacob Faibussowitsch } 5446356e834SBarry Smith 545*10c654e6SJacob Faibussowitsch switch (type) { 546d71ae5a4SJacob Faibussowitsch case OPTION_HEAD: 547d71ae5a4SJacob Faibussowitsch break; 5486356e834SBarry Smith case OPTION_INT_ARRAY: 549*10c654e6SJacob Faibussowitsch PetscCall(PetscSNPrintf(value, PETSC_STATIC_ARRAY_LENGTH(value), "%d", (int)((PetscInt *)data)[0])); 550*10c654e6SJacob Faibussowitsch for (size_t j = 1; j < arraylength; ++j) { 551*10c654e6SJacob Faibussowitsch PetscCall(PetscSNPrintf(tmp, PETSC_STATIC_ARRAY_LENGTH(tmp), "%d", (int)((PetscInt *)data)[j])); 552c6a7a370SJeremy L Thompson PetscCall(PetscStrlcat(value, ",", sizeof(value))); 553c6a7a370SJeremy L Thompson PetscCall(PetscStrlcat(value, tmp, sizeof(value))); 5546356e834SBarry Smith } 5556356e834SBarry Smith break; 556d71ae5a4SJacob Faibussowitsch case OPTION_INT: 557*10c654e6SJacob Faibussowitsch PetscCall(PetscSNPrintf(value, PETSC_STATIC_ARRAY_LENGTH(value), "%d", (int)*(PetscInt *)data)); 558d71ae5a4SJacob Faibussowitsch break; 559d71ae5a4SJacob Faibussowitsch case OPTION_REAL: 560*10c654e6SJacob Faibussowitsch PetscCall(PetscSNPrintf(value, PETSC_STATIC_ARRAY_LENGTH(value), "%g", (double)*(PetscReal *)data)); 561d71ae5a4SJacob Faibussowitsch break; 5626356e834SBarry Smith case OPTION_REAL_ARRAY: 563*10c654e6SJacob Faibussowitsch PetscCall(PetscSNPrintf(value, PETSC_STATIC_ARRAY_LENGTH(value), "%g", (double)((PetscReal *)data)[0])); 564*10c654e6SJacob Faibussowitsch for (size_t j = 1; j < arraylength; ++j) { 565*10c654e6SJacob Faibussowitsch PetscCall(PetscSNPrintf(tmp, PETSC_STATIC_ARRAY_LENGTH(tmp), "%g", (double)((PetscReal *)data)[j])); 566c6a7a370SJeremy L Thompson PetscCall(PetscStrlcat(value, ",", sizeof(value))); 567c6a7a370SJeremy L Thompson PetscCall(PetscStrlcat(value, tmp, sizeof(value))); 5686356e834SBarry Smith } 5696356e834SBarry Smith break; 570050cccc3SHong Zhang case OPTION_SCALAR_ARRAY: 571*10c654e6SJacob Faibussowitsch PetscCall(PetscSNPrintf(value, PETSC_STATIC_ARRAY_LENGTH(value), "%g+%gi", (double)PetscRealPart(((PetscScalar *)data)[0]), (double)PetscImaginaryPart(((PetscScalar *)data)[0]))); 572*10c654e6SJacob Faibussowitsch for (size_t j = 1; j < arraylength; ++j) { 573*10c654e6SJacob Faibussowitsch PetscCall(PetscSNPrintf(tmp, PETSC_STATIC_ARRAY_LENGTH(tmp), "%g+%gi", (double)PetscRealPart(((PetscScalar *)data)[j]), (double)PetscImaginaryPart(((PetscScalar *)data)[j]))); 574c6a7a370SJeremy L Thompson PetscCall(PetscStrlcat(value, ",", sizeof(value))); 575c6a7a370SJeremy L Thompson PetscCall(PetscStrlcat(value, tmp, sizeof(value))); 576050cccc3SHong Zhang } 577050cccc3SHong Zhang break; 578d71ae5a4SJacob Faibussowitsch case OPTION_BOOL: 579*10c654e6SJacob Faibussowitsch PetscCall(PetscSNPrintf(value, PETSC_STATIC_ARRAY_LENGTH(value), "%d", *(int *)data)); 580d71ae5a4SJacob Faibussowitsch break; 5817781c08eSBarry Smith case OPTION_BOOL_ARRAY: 582*10c654e6SJacob Faibussowitsch PetscCall(PetscSNPrintf(value, PETSC_STATIC_ARRAY_LENGTH(value), "%d", (int)((PetscBool *)data)[0])); 583*10c654e6SJacob Faibussowitsch for (size_t j = 1; j < arraylength; ++j) { 584*10c654e6SJacob Faibussowitsch PetscCall(PetscSNPrintf(tmp, PETSC_STATIC_ARRAY_LENGTH(tmp), "%d", (int)((PetscBool *)data)[j])); 585c6a7a370SJeremy L Thompson PetscCall(PetscStrlcat(value, ",", sizeof(value))); 586c6a7a370SJeremy L Thompson PetscCall(PetscStrlcat(value, tmp, sizeof(value))); 5871ae3d29cSBarry Smith } 5881ae3d29cSBarry Smith break; 589*10c654e6SJacob Faibussowitsch case OPTION_FLIST: // fall-through 590*10c654e6SJacob Faibussowitsch case OPTION_ELIST: // fall-through 591d71ae5a4SJacob Faibussowitsch case OPTION_STRING: 592*10c654e6SJacob Faibussowitsch PetscCall(PetscStrncpy(value, (char *)data, sizeof(value))); 593d71ae5a4SJacob Faibussowitsch break; 5941ae3d29cSBarry Smith case OPTION_STRING_ARRAY: 595*10c654e6SJacob Faibussowitsch PetscCall(PetscSNPrintf(value, PETSC_STATIC_ARRAY_LENGTH(value), "%s", ((char **)data)[0])); 596*10c654e6SJacob Faibussowitsch for (size_t j = 1; j < arraylength; j++) { 597*10c654e6SJacob Faibussowitsch PetscCall(PetscSNPrintf(tmp, PETSC_STATIC_ARRAY_LENGTH(tmp), "%s", ((char **)data)[j])); 598c6a7a370SJeremy L Thompson PetscCall(PetscStrlcat(value, ",", sizeof(value))); 599c6a7a370SJeremy L Thompson PetscCall(PetscStrlcat(value, tmp, sizeof(value))); 6001ae3d29cSBarry Smith } 6016356e834SBarry Smith break; 6026356e834SBarry Smith } 6039566063dSJacob Faibussowitsch PetscCall(PetscOptionsSetValue(PetscOptionsObject->options, option, value)); 6046356e834SBarry Smith } 605*10c654e6SJacob Faibussowitsch if (type == OPTION_ELIST) PetscCall(PetscStrNArrayDestroy(next->nlist, (char ***)&next->list)); 606*10c654e6SJacob Faibussowitsch PetscCall(PetscFree(next->text)); 607*10c654e6SJacob Faibussowitsch PetscCall(PetscFree(next->option)); 608*10c654e6SJacob Faibussowitsch PetscCall(PetscFree(next->man)); 609*10c654e6SJacob Faibussowitsch PetscCall(PetscFree(next->edata)); 610c979a496SBarry Smith 611*10c654e6SJacob Faibussowitsch if (type == OPTION_STRING || type == OPTION_FLIST || type == OPTION_ELIST) { 612*10c654e6SJacob Faibussowitsch free(data); 613c979a496SBarry Smith } else { 614*10c654e6SJacob Faibussowitsch // use next->data instead of data because PetscFree() sets it to NULL 615*10c654e6SJacob Faibussowitsch PetscCall(PetscFree(next->data)); 616c979a496SBarry Smith } 6177781c08eSBarry Smith 618*10c654e6SJacob Faibussowitsch last = next; 619*10c654e6SJacob Faibussowitsch PetscOptionsObject->next = next->next; 6209566063dSJacob Faibussowitsch PetscCall(PetscFree(last)); 6216356e834SBarry Smith } 6229566063dSJacob Faibussowitsch PetscCall(PetscFree(PetscOptionsObject->prefix)); 62302c9f0b5SLisandro Dalcin PetscOptionsObject->next = NULL; 6243ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 62553acd3b1SBarry Smith } 62653acd3b1SBarry Smith 627*10c654e6SJacob Faibussowitsch static PetscErrorCode GetListLength(const char *const *list, PetscInt *len) 628*10c654e6SJacob Faibussowitsch { 629*10c654e6SJacob Faibussowitsch PetscInt retlen = 0; 630*10c654e6SJacob Faibussowitsch 631*10c654e6SJacob Faibussowitsch PetscFunctionBegin; 632*10c654e6SJacob Faibussowitsch PetscValidIntPointer(len, 2); 633*10c654e6SJacob Faibussowitsch while (list[retlen]) { 634*10c654e6SJacob Faibussowitsch PetscValidCharPointer(list[retlen], 1); 635*10c654e6SJacob Faibussowitsch PetscCheck(++retlen < 50, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "List argument appears to be wrong or have more than 50 entries"); 636*10c654e6SJacob Faibussowitsch } 637*10c654e6SJacob Faibussowitsch PetscCheck(retlen > 2, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "List argument must have at least 2 entries: typename and type prefix"); 638*10c654e6SJacob Faibussowitsch /* drop item name and prefix*/ 639*10c654e6SJacob Faibussowitsch *len = retlen - 2; 640*10c654e6SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 641*10c654e6SJacob Faibussowitsch } 642*10c654e6SJacob Faibussowitsch 64388aa4217SBarry Smith /*MC 64453acd3b1SBarry Smith PetscOptionsEnum - Gets the enum value for a particular option in the database. 64553acd3b1SBarry Smith 64688aa4217SBarry Smith Synopsis: 64788aa4217SBarry Smith #include "petscsys.h" 6483a89f35bSSatish Balay PetscErrorCode PetscOptionsEnum(const char opt[],const char text[],const char man[],const char *const *list,PetscEnum currentvalue,PetscEnum *value,PetscBool *set) 64988aa4217SBarry Smith 6507cdbe19fSJose E. Roman Logically Collective on the communicator passed in `PetscOptionsBegin()` 6517cdbe19fSJose E. Roman 65253acd3b1SBarry Smith Input Parameters: 65353acd3b1SBarry Smith + opt - option name 65453acd3b1SBarry Smith . text - short string that describes the option 65553acd3b1SBarry Smith . man - manual page with additional information on option 65653acd3b1SBarry Smith . list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null 6570fdccdaeSBarry Smith - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either 6582fe279fdSBarry Smith .vb 6592fe279fdSBarry Smith PetscOptionsEnum(..., obj->value,&object->value,...) or 6602fe279fdSBarry Smith value = defaultvalue 6612fe279fdSBarry Smith PetscOptionsEnum(..., value,&value,&flg); 6622fe279fdSBarry Smith if (flg) { 6632fe279fdSBarry Smith .ve 66453acd3b1SBarry Smith 665d8d19677SJose E. Roman Output Parameters: 66653acd3b1SBarry Smith + value - the value to return 667811af0c4SBarry Smith - set - `PETSC_TRUE` if found, else `PETSC_FALSE` 66853acd3b1SBarry Smith 66953acd3b1SBarry Smith Level: beginner 67053acd3b1SBarry Smith 67195452b02SPatrick Sanan Notes: 672811af0c4SBarry Smith Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()` 67353acd3b1SBarry Smith 674811af0c4SBarry Smith list is usually something like `PCASMTypes` or some other predefined list of enum names 67553acd3b1SBarry Smith 67630bab8dbSBarry Smith If the user does not supply the option at all `value` is NOT changed. Thus 67730bab8dbSBarry Smith you should ALWAYS initialize `value` if you access it without first checking if `set` is `PETSC_TRUE`. 6782efd9cb1SBarry Smith 67930bab8dbSBarry Smith The `currentvalue` passed into this routine does not get transferred to the output `value` variable automatically. 680989712b9SBarry Smith 681db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`, 682db781477SPatrick Sanan `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`, 683db781477SPatrick Sanan `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`, 684db781477SPatrick Sanan `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`, 685c2e3fba1SPatrick Sanan `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`, 686db781477SPatrick Sanan `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`, 687db781477SPatrick Sanan `PetscOptionsFList()`, `PetscOptionsEList()` 68888aa4217SBarry Smith M*/ 68988aa4217SBarry Smith 690d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsEnum_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], const char *const *list, PetscEnum currentvalue, PetscEnum *value, PetscBool *set) 691d71ae5a4SJacob Faibussowitsch { 69253acd3b1SBarry Smith PetscInt ntext = 0; 693aa5bb8c0SSatish Balay PetscInt tval; 694ace3abfcSBarry Smith PetscBool tflg; 69553acd3b1SBarry Smith 69653acd3b1SBarry Smith PetscFunctionBegin; 697*10c654e6SJacob Faibussowitsch PetscValidCharPointer(opt, 2); 698*10c654e6SJacob Faibussowitsch PetscValidPointer(list, 5); 699*10c654e6SJacob Faibussowitsch PetscValidPointer(value, 7); 700*10c654e6SJacob Faibussowitsch if (set) PetscValidBoolPointer(set, 8); 701*10c654e6SJacob Faibussowitsch PetscCall(GetListLength(list, &ntext)); 7029566063dSJacob Faibussowitsch PetscCall(PetscOptionsEList_Private(PetscOptionsObject, opt, text, man, list, ntext, list[currentvalue], &tval, &tflg)); 703aa5bb8c0SSatish Balay /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */ 704aa5bb8c0SSatish Balay if (tflg) *value = (PetscEnum)tval; 705aa5bb8c0SSatish Balay if (set) *set = tflg; 7063ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 70753acd3b1SBarry Smith } 70853acd3b1SBarry Smith 70988aa4217SBarry Smith /*MC 710d3e47460SLisandro Dalcin PetscOptionsEnumArray - Gets an array of enum values for a particular 711d3e47460SLisandro Dalcin option in the database. 712d3e47460SLisandro Dalcin 71388aa4217SBarry Smith Synopsis: 71488aa4217SBarry Smith #include "petscsys.h" 7153a89f35bSSatish Balay PetscErrorCode PetscOptionsEnumArray(const char opt[],const char text[],const char man[],const char *const *list,PetscEnum value[],PetscInt *n,PetscBool *set) 71688aa4217SBarry Smith 7177cdbe19fSJose E. Roman Logically Collective on the communicator passed in `PetscOptionsBegin()` 7187cdbe19fSJose E. Roman 719d3e47460SLisandro Dalcin Input Parameters: 720d3e47460SLisandro Dalcin + opt - the option one is seeking 721d3e47460SLisandro Dalcin . text - short string describing option 722d3e47460SLisandro Dalcin . man - manual page for option 72322d58ec6SMatthew G. Knepley . list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null 724c89788bdSBarry Smith - n - maximum number of values allowed in the value array 725d3e47460SLisandro Dalcin 726d8d19677SJose E. Roman Output Parameters: 727d3e47460SLisandro Dalcin + value - location to copy values 728d3e47460SLisandro Dalcin . n - actual number of values found 729811af0c4SBarry Smith - set - `PETSC_TRUE` if found, else `PETSC_FALSE` 730d3e47460SLisandro Dalcin 731d3e47460SLisandro Dalcin Level: beginner 732d3e47460SLisandro Dalcin 733d3e47460SLisandro Dalcin Notes: 734d3e47460SLisandro Dalcin The array must be passed as a comma separated list. 735d3e47460SLisandro Dalcin 736d3e47460SLisandro Dalcin There must be no intervening spaces between the values. 737d3e47460SLisandro Dalcin 738811af0c4SBarry Smith Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()` 739d3e47460SLisandro Dalcin 740db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`, 741db781477SPatrick Sanan `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`, 742db781477SPatrick Sanan `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`, 743c2e3fba1SPatrick Sanan `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`, 744db781477SPatrick Sanan `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`, 745db781477SPatrick Sanan `PetscOptionsFList()`, `PetscOptionsEList()`, `PetscOptionsRealArray()` 74688aa4217SBarry Smith M*/ 74788aa4217SBarry Smith 748d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsEnumArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], const char *const *list, PetscEnum value[], PetscInt *n, PetscBool *set) 749d71ae5a4SJacob Faibussowitsch { 750*10c654e6SJacob Faibussowitsch PetscInt nlist = 0; 751*10c654e6SJacob Faibussowitsch const char *prefix = PetscOptionsObject->prefix; 752d3e47460SLisandro Dalcin 753d3e47460SLisandro Dalcin PetscFunctionBegin; 754*10c654e6SJacob Faibussowitsch PetscValidCharPointer(opt, 2); 755*10c654e6SJacob Faibussowitsch PetscValidPointer(list, 5); 756*10c654e6SJacob Faibussowitsch PetscValidPointer(value, 6); 757*10c654e6SJacob Faibussowitsch PetscValidIntPointer(n, 7); 758*10c654e6SJacob Faibussowitsch PetscCheck(*n > 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "n (%" PetscInt_FMT ") must be > 0", *n); 759*10c654e6SJacob Faibussowitsch if (set) PetscValidBoolPointer(set, 8); 760*10c654e6SJacob Faibussowitsch PetscCall(GetListLength(list, &nlist)); 761*10c654e6SJacob Faibussowitsch PetscCall(PetscOptionsGetEnumArray(PetscOptionsObject->options, prefix, opt, list, value, n, set)); 762*10c654e6SJacob Faibussowitsch if (ShouldPrintHelp(PetscOptionsObject)) { 763*10c654e6SJacob Faibussowitsch const MPI_Comm comm = PetscOptionsObject->comm; 764*10c654e6SJacob Faibussowitsch const PetscInt nv = *n; 765*10c654e6SJacob Faibussowitsch 766*10c654e6SJacob Faibussowitsch PetscCall((*PetscHelpPrintf)(comm, " -%s%s: <%s", Prefix(prefix), opt + 1, list[value[0]])); 767*10c654e6SJacob Faibussowitsch for (PetscInt i = 1; i < nv; ++i) PetscCall((*PetscHelpPrintf)(comm, ",%s", list[value[i]])); 768*10c654e6SJacob Faibussowitsch PetscCall((*PetscHelpPrintf)(comm, ">: %s (choose from)", text)); 769*10c654e6SJacob Faibussowitsch for (PetscInt i = 0; i < nlist; ++i) PetscCall((*PetscHelpPrintf)(comm, " %s", list[i])); 770*10c654e6SJacob Faibussowitsch PetscCall((*PetscHelpPrintf)(comm, " (%s)\n", ManSection(man))); 771d3e47460SLisandro Dalcin } 7723ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 773d3e47460SLisandro Dalcin } 774d3e47460SLisandro Dalcin 77588aa4217SBarry Smith /*MC 7765a856986SBarry Smith PetscOptionsBoundedInt - Gets an integer value greater than or equal a given bound for a particular option in the database. 7775a856986SBarry Smith 77888aa4217SBarry Smith Synopsis: 77988aa4217SBarry Smith #include "petscsys.h" 78069d47153SPierre Jolivet PetscErrorCode PetscOptionsBoundedInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg,PetscInt bound) 78188aa4217SBarry Smith 7827cdbe19fSJose E. Roman Logically Collective on the communicator passed in `PetscOptionsBegin()` 7837cdbe19fSJose E. Roman 7845a856986SBarry Smith Input Parameters: 7855a856986SBarry Smith + opt - option name 7865a856986SBarry Smith . text - short string that describes the option 7875a856986SBarry Smith . man - manual page with additional information on option 7885a856986SBarry Smith . currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either 78969d47153SPierre Jolivet .vb 79069d47153SPierre Jolivet PetscOptionsInt(..., obj->value,&obj->value,...) 79169d47153SPierre Jolivet .ve 79269d47153SPierre Jolivet or 79369d47153SPierre Jolivet .vb 79469d47153SPierre Jolivet value = defaultvalue 79569d47153SPierre Jolivet PetscOptionsInt(..., value,&value,&flg); 79669d47153SPierre Jolivet if (flg) { 79769d47153SPierre Jolivet .ve 79888aa4217SBarry Smith - bound - the requested value should be greater than or equal this bound or an error is generated 7995a856986SBarry Smith 800d8d19677SJose E. Roman Output Parameters: 8015a856986SBarry Smith + value - the integer value to return 802811af0c4SBarry Smith - flg - `PETSC_TRUE` if found, else `PETSC_FALSE` 8035a856986SBarry Smith 8042fe279fdSBarry Smith Level: beginner 8052fe279fdSBarry Smith 8065a856986SBarry Smith Notes: 80730bab8dbSBarry Smith If the user does not supply the option at all `value` is NOT changed. Thus 80830bab8dbSBarry Smith you should ALWAYS initialize `value` if you access it without first checking if `flg` is `PETSC_TRUE`. 8095a856986SBarry Smith 81030bab8dbSBarry Smith The `currentvalue` passed into this routine does not get transferred to the output `value` variable automatically. 8115a856986SBarry Smith 812811af0c4SBarry Smith Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()` 8135a856986SBarry Smith 814db781477SPatrick Sanan .seealso: `PetscOptionsInt()`, `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`, 815db781477SPatrick Sanan `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`, `PetscOptionsRangeInt()` 816db781477SPatrick Sanan `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`, 817db781477SPatrick Sanan `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`, 818c2e3fba1SPatrick Sanan `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`, 819db781477SPatrick Sanan `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`, 820db781477SPatrick Sanan `PetscOptionsFList()`, `PetscOptionsEList()` 82188aa4217SBarry Smith M*/ 8225a856986SBarry Smith 82388aa4217SBarry Smith /*MC 8245a856986SBarry Smith PetscOptionsRangeInt - Gets an integer value within a range of values for a particular option in the database. 8255a856986SBarry Smith 82688aa4217SBarry Smith Synopsis: 82788aa4217SBarry Smith #include "petscsys.h" 8283a89f35bSSatish Balay PetscErrorCode PetscOptionsRangeInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg,PetscInt lb,PetscInt ub) 82988aa4217SBarry Smith 8307cdbe19fSJose E. Roman Logically Collective on the communicator passed in `PetscOptionsBegin()` 8317cdbe19fSJose E. Roman 8325a856986SBarry Smith Input Parameters: 8335a856986SBarry Smith + opt - option name 8345a856986SBarry Smith . text - short string that describes the option 8355a856986SBarry Smith . man - manual page with additional information on option 8365a856986SBarry Smith . currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either 8372fe279fdSBarry Smith .vb 8382fe279fdSBarry Smith PetscOptionsInt(..., obj->value,&obj->value,...) or 8392fe279fdSBarry Smith value = defaultvalue 8402fe279fdSBarry Smith PetscOptionsInt(..., value,&value,&flg); 8412fe279fdSBarry Smith if (flg) { 8422fe279fdSBarry Smith .ve 84388aa4217SBarry Smith . lb - the lower bound, provided value must be greater than or equal to this value or an error is generated 84488aa4217SBarry Smith - ub - the upper bound, provided value must be less than or equal to this value or an error is generated 8455a856986SBarry Smith 846d8d19677SJose E. Roman Output Parameters: 8475a856986SBarry Smith + value - the integer value to return 848811af0c4SBarry Smith - flg - `PETSC_TRUE` if found, else `PETSC_FALSE` 8495a856986SBarry Smith 8502fe279fdSBarry Smith Level: beginner 8512fe279fdSBarry Smith 8525a856986SBarry Smith Notes: 85330bab8dbSBarry Smith If the user does not supply the option at all `value` is NOT changed. Thus 85430bab8dbSBarry Smith you should ALWAYS initialize `value` if you access it without first checking if `flg` is `PETSC_TRUE`. 8555a856986SBarry Smith 85630bab8dbSBarry Smith The `currentvalue` passed into this routine does not get transferred to the output `value` variable automatically. 8575a856986SBarry Smith 858811af0c4SBarry Smith Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()` 8595a856986SBarry Smith 860db781477SPatrick Sanan .seealso: `PetscOptionsInt()`, `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`, 861db781477SPatrick Sanan `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`, `PetscOptionsBoundedInt()` 862db781477SPatrick Sanan `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`, 863db781477SPatrick Sanan `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`, 864c2e3fba1SPatrick Sanan `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`, 865db781477SPatrick Sanan `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`, 866db781477SPatrick Sanan `PetscOptionsFList()`, `PetscOptionsEList()` 86788aa4217SBarry Smith M*/ 8685a856986SBarry Smith 86988aa4217SBarry Smith /*MC 87053acd3b1SBarry Smith PetscOptionsInt - Gets the integer value for a particular option in the database. 87153acd3b1SBarry Smith 87288aa4217SBarry Smith Synopsis: 87388aa4217SBarry Smith #include "petscsys.h" 8746eeb591dSVaclav Hapla PetscErrorCode PetscOptionsInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg)) 87588aa4217SBarry Smith 8767cdbe19fSJose E. Roman Logically Collective on the communicator passed in `PetscOptionsBegin()` 8777cdbe19fSJose E. Roman 87853acd3b1SBarry Smith Input Parameters: 87953acd3b1SBarry Smith + opt - option name 88053acd3b1SBarry Smith . text - short string that describes the option 88153acd3b1SBarry Smith . man - manual page with additional information on option 8820fdccdaeSBarry Smith - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either 8832fe279fdSBarry Smith .vb 8842fe279fdSBarry Smith PetscOptionsInt(..., obj->value,&obj->value,...) or 8852fe279fdSBarry Smith value = defaultvalue 8862fe279fdSBarry Smith PetscOptionsInt(..., value,&value,&flg); 8872fe279fdSBarry Smith if (flg) { 8882fe279fdSBarry Smith .ve 88953acd3b1SBarry Smith 890d8d19677SJose E. Roman Output Parameters: 89153acd3b1SBarry Smith + value - the integer value to return 892811af0c4SBarry Smith - flg - `PETSC_TRUE` if found, else `PETSC_FALSE` 89353acd3b1SBarry Smith 89430bab8dbSBarry Smith Level: beginner 8952efd9cb1SBarry Smith 89630bab8dbSBarry Smith Notes: 89730bab8dbSBarry Smith If the user does not supply the option at all `value` is NOT changed. Thus 89830bab8dbSBarry Smith you should ALWAYS initialize `value` if you access it without first checking if `flg` is `PETSC_TRUE`. 89930bab8dbSBarry Smith 90030bab8dbSBarry Smith The `currentvalue` passed into this routine does not get transferred to the output `value` variable automatically. 901989712b9SBarry Smith 902811af0c4SBarry Smith Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()` 90353acd3b1SBarry Smith 904db781477SPatrick Sanan .seealso: `PetscOptionsBoundedInt()`, `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`, 905db781477SPatrick Sanan `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`, `PetscOptionsRangeInt()` 906db781477SPatrick Sanan `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`, 907db781477SPatrick Sanan `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`, 908c2e3fba1SPatrick Sanan `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`, 909db781477SPatrick Sanan `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`, 910db781477SPatrick Sanan `PetscOptionsFList()`, `PetscOptionsEList()` 91188aa4217SBarry Smith M*/ 91288aa4217SBarry Smith 913d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsInt_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscInt currentvalue, PetscInt *value, PetscBool *set, PetscInt lb, PetscInt ub) 914d71ae5a4SJacob Faibussowitsch { 915*10c654e6SJacob Faibussowitsch const char *prefix = PetscOptionsObject->prefix; 916*10c654e6SJacob Faibussowitsch const PetscOptions options = PetscOptionsObject->options; 91712655325SBarry Smith PetscBool wasset; 91853acd3b1SBarry Smith 91953acd3b1SBarry Smith PetscFunctionBegin; 920*10c654e6SJacob Faibussowitsch PetscValidCharPointer(opt, 2); 921*10c654e6SJacob Faibussowitsch PetscValidIntPointer(value, 6); 922*10c654e6SJacob Faibussowitsch if (set) PetscValidBoolPointer(set, 7); 92308401ef6SPierre Jolivet PetscCheck(currentvalue >= lb, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Current value %" PetscInt_FMT " less than allowed bound %" PetscInt_FMT, currentvalue, lb); 92408401ef6SPierre Jolivet PetscCheck(currentvalue <= ub, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Current value %" PetscInt_FMT " greater than allowed bound %" PetscInt_FMT, currentvalue, ub); 925e55864a3SBarry Smith if (!PetscOptionsObject->count) { 926*10c654e6SJacob Faibussowitsch PetscOptionItem amsopt; 927*10c654e6SJacob Faibussowitsch 9289566063dSJacob Faibussowitsch PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_INT, &amsopt)); 9299566063dSJacob Faibussowitsch PetscCall(PetscMalloc(sizeof(PetscInt), &amsopt->data)); 93012655325SBarry Smith *(PetscInt *)amsopt->data = currentvalue; 9313e211508SBarry Smith 932*10c654e6SJacob Faibussowitsch PetscCall(PetscOptionsGetInt(options, prefix, opt, ¤tvalue, &wasset)); 933ad540459SPierre Jolivet if (wasset) *(PetscInt *)amsopt->data = currentvalue; 934af6d86caSBarry Smith } 935*10c654e6SJacob Faibussowitsch PetscCall(PetscOptionsGetInt(options, prefix, opt, value, &wasset)); 936cc73adaaSBarry Smith PetscCheck(!wasset || *value >= lb, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Newly set value %" PetscInt_FMT " less than allowed bound %" PetscInt_FMT, *value, lb); 937cc73adaaSBarry Smith PetscCheck(!wasset || *value <= ub, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Newly set value %" PetscInt_FMT " greater than allowed bound %" PetscInt_FMT, *value, ub); 93844ef3d73SBarry Smith if (set) *set = wasset; 939*10c654e6SJacob Faibussowitsch if (ShouldPrintHelp(PetscOptionsObject)) { 940*10c654e6SJacob Faibussowitsch PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, " -%s%s: <now %" PetscInt_FMT " : formerly %" PetscInt_FMT ">: %s (%s)\n", Prefix(prefix), opt + 1, wasset ? *value : currentvalue, currentvalue, text, ManSection(man))); 94153acd3b1SBarry Smith } 9423ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 94353acd3b1SBarry Smith } 94453acd3b1SBarry Smith 94588aa4217SBarry Smith /*MC 94653acd3b1SBarry Smith PetscOptionsString - Gets the string value for a particular option in the database. 94753acd3b1SBarry Smith 94888aa4217SBarry Smith Synopsis: 94988aa4217SBarry Smith #include "petscsys.h" 9503a89f35bSSatish Balay PetscErrorCode PetscOptionsString(const char opt[],const char text[],const char man[],const char currentvalue[],char value[],size_t len,PetscBool *set) 95188aa4217SBarry Smith 9527cdbe19fSJose E. Roman Logically Collective on the communicator passed in `PetscOptionsBegin()` 9537cdbe19fSJose E. Roman 95453acd3b1SBarry Smith Input Parameters: 95553acd3b1SBarry Smith + opt - option name 95653acd3b1SBarry Smith . text - short string that describes the option 95753acd3b1SBarry Smith . man - manual page with additional information on option 9580fdccdaeSBarry Smith . currentvalue - the current value; caller is responsible for setting this value correctly. This is not used to set value 959bcbf2dc5SJed Brown - len - length of the result string including null terminator 96053acd3b1SBarry Smith 961d8d19677SJose E. Roman Output Parameters: 96253acd3b1SBarry Smith + value - the value to return 963811af0c4SBarry Smith - flg - `PETSC_TRUE` if found, else `PETSC_FALSE` 96453acd3b1SBarry Smith 96553acd3b1SBarry Smith Level: beginner 96653acd3b1SBarry Smith 96795452b02SPatrick Sanan Notes: 968811af0c4SBarry Smith Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()` 96953acd3b1SBarry Smith 97030bab8dbSBarry Smith If the user provided no string (for example `-optionname` `-someotheroption`) `flg` is set to `PETSC_TRUE` (and the string is filled with nulls). 9717fccdfe4SBarry Smith 97230bab8dbSBarry Smith If the user does not supply the option at all `value` is NOT changed. Thus 97330bab8dbSBarry Smith you should ALWAYS initialize `value` if you access it without first checking if `flg` is `PETSC_TRUE`. 9742efd9cb1SBarry Smith 97530bab8dbSBarry Smith The `currentvalue` passed into this routine does not get transferred to the output `value` variable automatically. 976989712b9SBarry Smith 977db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`, 978db781477SPatrick Sanan `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`, 979db781477SPatrick Sanan `PetscOptionsInt()`, `PetscOptionsReal()`, `PetscOptionsBool()`, 980db781477SPatrick Sanan `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`, 981c2e3fba1SPatrick Sanan `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`, 982db781477SPatrick Sanan `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`, 983db781477SPatrick Sanan `PetscOptionsFList()`, `PetscOptionsEList()` 98488aa4217SBarry Smith M*/ 98588aa4217SBarry Smith 986d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsString_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], const char currentvalue[], char value[], size_t len, PetscBool *set) 987d71ae5a4SJacob Faibussowitsch { 988*10c654e6SJacob Faibussowitsch const char *prefix = PetscOptionsObject->prefix; 98944ef3d73SBarry Smith PetscBool lset; 99053acd3b1SBarry Smith 99153acd3b1SBarry Smith PetscFunctionBegin; 992*10c654e6SJacob Faibussowitsch PetscValidCharPointer(opt, 2); 993*10c654e6SJacob Faibussowitsch PetscValidCharPointer(value, 6); 994*10c654e6SJacob Faibussowitsch if (set) PetscValidBoolPointer(set, 8); 9951a1499c8SBarry Smith if (!PetscOptionsObject->count) { 996*10c654e6SJacob Faibussowitsch PetscOptionItem amsopt; 997*10c654e6SJacob Faibussowitsch 9989566063dSJacob Faibussowitsch PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_STRING, &amsopt)); 99964facd6cSBarry Smith /* must use system malloc since SAWs may free this */ 10009566063dSJacob Faibussowitsch PetscCall(PetscStrdup(currentvalue ? currentvalue : "", (char **)&amsopt->data)); 1001af6d86caSBarry Smith } 1002*10c654e6SJacob Faibussowitsch PetscCall(PetscOptionsGetString(PetscOptionsObject->options, prefix, opt, value, len, &lset)); 100344ef3d73SBarry Smith if (set) *set = lset; 1004*10c654e6SJacob Faibussowitsch if (ShouldPrintHelp(PetscOptionsObject)) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, " -%s%s: <now %s : formerly %s>: %s (%s)\n", Prefix(prefix), opt + 1, lset ? value : currentvalue, currentvalue, text, ManSection(man))); 10053ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 100653acd3b1SBarry Smith } 100753acd3b1SBarry Smith 100888aa4217SBarry Smith /*MC 1009811af0c4SBarry Smith PetscOptionsReal - Gets the `PetscReal` value for a particular option in the database. 101053acd3b1SBarry Smith 101188aa4217SBarry Smith Synopsis: 101288aa4217SBarry Smith #include "petscsys.h" 10133a89f35bSSatish Balay PetscErrorCode PetscOptionsReal(const char opt[],const char text[],const char man[],PetscReal currentvalue,PetscReal *value,PetscBool *set) 101488aa4217SBarry Smith 10157cdbe19fSJose E. Roman Logically Collective on the communicator passed in `PetscOptionsBegin()` 10167cdbe19fSJose E. Roman 101753acd3b1SBarry Smith Input Parameters: 101853acd3b1SBarry Smith + opt - option name 101953acd3b1SBarry Smith . text - short string that describes the option 102053acd3b1SBarry Smith . man - manual page with additional information on option 10210fdccdaeSBarry Smith - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either 10222fe279fdSBarry Smith .vb 10232fe279fdSBarry Smith PetscOptionsReal(..., obj->value,&obj->value,...) or 10242fe279fdSBarry Smith value = defaultvalue 10252fe279fdSBarry Smith PetscOptionsReal(..., value,&value,&flg); 10262fe279fdSBarry Smith if (flg) { 10272fe279fdSBarry Smith .ve 102853acd3b1SBarry Smith 1029d8d19677SJose E. Roman Output Parameters: 103053acd3b1SBarry Smith + value - the value to return 1031811af0c4SBarry Smith - flg - `PETSC_TRUE` if found, else `PETSC_FALSE` 103253acd3b1SBarry Smith 103330bab8dbSBarry Smith Level: beginner 10342efd9cb1SBarry Smith 103530bab8dbSBarry Smith Notes: 103630bab8dbSBarry Smith If the user does not supply the option at all `value` is NOT changed. Thus 103730bab8dbSBarry Smith you should ALWAYS initialize `value` if you access it without first checking if `flg` is `PETSC_TRUE`. 103830bab8dbSBarry Smith 103930bab8dbSBarry Smith The `currentvalue` passed into this routine does not get transferred to the output `value` variable automatically. 1040989712b9SBarry Smith 1041811af0c4SBarry Smith Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()` 104253acd3b1SBarry Smith 1043db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`, 1044db781477SPatrick Sanan `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`, 1045db781477SPatrick Sanan `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`, 1046db781477SPatrick Sanan `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`, 1047c2e3fba1SPatrick Sanan `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`, 1048db781477SPatrick Sanan `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`, 1049db781477SPatrick Sanan `PetscOptionsFList()`, `PetscOptionsEList()` 105088aa4217SBarry Smith M*/ 105188aa4217SBarry Smith 1052d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsReal_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscReal currentvalue, PetscReal *value, PetscBool *set) 1053d71ae5a4SJacob Faibussowitsch { 1054*10c654e6SJacob Faibussowitsch const char *prefix = PetscOptionsObject->prefix; 105544ef3d73SBarry Smith PetscBool lset; 105653acd3b1SBarry Smith 105753acd3b1SBarry Smith PetscFunctionBegin; 1058*10c654e6SJacob Faibussowitsch PetscValidCharPointer(opt, 2); 1059*10c654e6SJacob Faibussowitsch PetscValidRealPointer(value, 6); 1060*10c654e6SJacob Faibussowitsch if (set) PetscValidBoolPointer(set, 7); 1061e55864a3SBarry Smith if (!PetscOptionsObject->count) { 1062*10c654e6SJacob Faibussowitsch PetscOptionItem amsopt; 1063*10c654e6SJacob Faibussowitsch 10649566063dSJacob Faibussowitsch PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_REAL, &amsopt)); 10659566063dSJacob Faibussowitsch PetscCall(PetscMalloc(sizeof(PetscReal), &amsopt->data)); 1066a297a907SKarl Rupp 10670fdccdaeSBarry Smith *(PetscReal *)amsopt->data = currentvalue; 1068538aa990SBarry Smith } 1069*10c654e6SJacob Faibussowitsch PetscCall(PetscOptionsGetReal(PetscOptionsObject->options, prefix, opt, value, &lset)); 107044ef3d73SBarry Smith if (set) *set = lset; 1071*10c654e6SJacob Faibussowitsch if (ShouldPrintHelp(PetscOptionsObject)) { 1072*10c654e6SJacob Faibussowitsch PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, " -%s%s: <now %g : formerly %g>: %s (%s)\n", Prefix(prefix), opt + 1, lset ? (double)*value : (double)currentvalue, (double)currentvalue, text, ManSection(man))); 107353acd3b1SBarry Smith } 10743ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 107553acd3b1SBarry Smith } 107653acd3b1SBarry Smith 107788aa4217SBarry Smith /*MC 1078811af0c4SBarry Smith PetscOptionsScalar - Gets the `PetscScalar` value for a particular option in the database. 107953acd3b1SBarry Smith 108088aa4217SBarry Smith Synopsis: 108188aa4217SBarry Smith #include "petscsys.h" 10823a89f35bSSatish Balay PetscErrorCode PetscOptionsScalar(const char opt[],const char text[],const char man[],PetscScalar currentvalue,PetscScalar *value,PetscBool *set) 108388aa4217SBarry Smith 10847cdbe19fSJose E. Roman Logically Collective on the communicator passed in `PetscOptionsBegin()` 10857cdbe19fSJose E. Roman 108653acd3b1SBarry Smith Input Parameters: 108753acd3b1SBarry Smith + opt - option name 108853acd3b1SBarry Smith . text - short string that describes the option 108953acd3b1SBarry Smith . man - manual page with additional information on option 10900fdccdaeSBarry Smith - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either 10912fe279fdSBarry Smith .vb 10922fe279fdSBarry Smith PetscOptionsScalar(..., obj->value,&obj->value,...) or 10932fe279fdSBarry Smith value = defaultvalue 10942fe279fdSBarry Smith PetscOptionsScalar(..., value,&value,&flg); 10952fe279fdSBarry Smith if (flg) { 10962fe279fdSBarry Smith .ve 10970fdccdaeSBarry Smith 1098d8d19677SJose E. Roman Output Parameters: 109953acd3b1SBarry Smith + value - the value to return 1100811af0c4SBarry Smith - flg - `PETSC_TRUE` if found, else `PETSC_FALSE` 110153acd3b1SBarry Smith 110230bab8dbSBarry Smith Level: beginner 11032efd9cb1SBarry Smith 110430bab8dbSBarry Smith Notes: 110530bab8dbSBarry Smith If the user does not supply the option at all `value` is NOT changed. Thus 110630bab8dbSBarry Smith you should ALWAYS initialize `value` if you access it without first checking if `flg` is `PETSC_TRUE`. 110730bab8dbSBarry Smith 110830bab8dbSBarry Smith The `currentvalue` passed into this routine does not get transferred to the output `value` variable automatically. 1109989712b9SBarry Smith 1110811af0c4SBarry Smith Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()` 111153acd3b1SBarry Smith 1112db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`, 1113db781477SPatrick Sanan `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`, 1114db781477SPatrick Sanan `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`, 1115db781477SPatrick Sanan `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`, 1116c2e3fba1SPatrick Sanan `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`, 1117db781477SPatrick Sanan `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`, 1118db781477SPatrick Sanan `PetscOptionsFList()`, `PetscOptionsEList()` 111988aa4217SBarry Smith M*/ 112088aa4217SBarry Smith 1121d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsScalar_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscScalar currentvalue, PetscScalar *value, PetscBool *set) 1122d71ae5a4SJacob Faibussowitsch { 112353acd3b1SBarry Smith PetscFunctionBegin; 112453acd3b1SBarry Smith #if !defined(PETSC_USE_COMPLEX) 11259566063dSJacob Faibussowitsch PetscCall(PetscOptionsReal(opt, text, man, currentvalue, value, set)); 112653acd3b1SBarry Smith #else 11279566063dSJacob Faibussowitsch PetscCall(PetscOptionsGetScalar(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, set)); 112853acd3b1SBarry Smith #endif 11293ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 113053acd3b1SBarry Smith } 113153acd3b1SBarry Smith 113288aa4217SBarry Smith /*MC 113390d69ab7SBarry Smith PetscOptionsName - Determines if a particular option has been set in the database. This returns true whether the option is a number, string or boolean, even 113490d69ab7SBarry Smith its value is set to false. 113553acd3b1SBarry Smith 113688aa4217SBarry Smith Synopsis: 113788aa4217SBarry Smith #include "petscsys.h" 11383a89f35bSSatish Balay PetscErrorCode PetscOptionsName(const char opt[],const char text[],const char man[],PetscBool *flg) 113988aa4217SBarry Smith 11407cdbe19fSJose E. Roman Logically Collective on the communicator passed in `PetscOptionsBegin()` 11417cdbe19fSJose E. Roman 114253acd3b1SBarry Smith Input Parameters: 114353acd3b1SBarry Smith + opt - option name 114453acd3b1SBarry Smith . text - short string that describes the option 114553acd3b1SBarry Smith - man - manual page with additional information on option 114653acd3b1SBarry Smith 114753acd3b1SBarry Smith Output Parameter: 1148811af0c4SBarry Smith . flg - `PETSC_TRUE` if found, else `PETSC_FALSE` 114953acd3b1SBarry Smith 115053acd3b1SBarry Smith Level: beginner 115153acd3b1SBarry Smith 1152811af0c4SBarry Smith Note: 1153811af0c4SBarry Smith Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()` 115453acd3b1SBarry Smith 1155db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`, 1156db781477SPatrick Sanan `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`, 1157db781477SPatrick Sanan `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`, 1158db781477SPatrick Sanan `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`, 1159c2e3fba1SPatrick Sanan `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`, 1160db781477SPatrick Sanan `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`, 1161db781477SPatrick Sanan `PetscOptionsFList()`, `PetscOptionsEList()` 116288aa4217SBarry Smith M*/ 116388aa4217SBarry Smith 1164d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsName_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool *flg) 1165d71ae5a4SJacob Faibussowitsch { 1166*10c654e6SJacob Faibussowitsch const char *prefix = PetscOptionsObject->prefix; 116753acd3b1SBarry Smith 116853acd3b1SBarry Smith PetscFunctionBegin; 1169*10c654e6SJacob Faibussowitsch PetscValidCharPointer(opt, 2); 1170*10c654e6SJacob Faibussowitsch PetscValidBoolPointer(flg, 5); 1171e55864a3SBarry Smith if (!PetscOptionsObject->count) { 1172*10c654e6SJacob Faibussowitsch PetscOptionItem amsopt; 1173*10c654e6SJacob Faibussowitsch 11749566063dSJacob Faibussowitsch PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt)); 11759566063dSJacob Faibussowitsch PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data)); 1176a297a907SKarl Rupp 1177ace3abfcSBarry Smith *(PetscBool *)amsopt->data = PETSC_FALSE; 11781ae3d29cSBarry Smith } 1179*10c654e6SJacob Faibussowitsch PetscCall(PetscOptionsHasName(PetscOptionsObject->options, prefix, opt, flg)); 1180*10c654e6SJacob Faibussowitsch if (ShouldPrintHelp(PetscOptionsObject)) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, " -%s%s: %s (%s)\n", Prefix(prefix), opt + 1, text, ManSection(man))); 11813ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 118253acd3b1SBarry Smith } 118353acd3b1SBarry Smith 118488aa4217SBarry Smith /*MC 1185a264d7a6SBarry Smith PetscOptionsFList - Puts a list of option values that a single one may be selected from 118653acd3b1SBarry Smith 118788aa4217SBarry Smith Synopsis: 118888aa4217SBarry Smith #include "petscsys.h" 11893a89f35bSSatish Balay PetscErrorCode PetscOptionsFList(const char opt[],const char ltext[],const char man[],PetscFunctionList list,const char currentvalue[],char value[],size_t len,PetscBool *set) 119088aa4217SBarry Smith 11917cdbe19fSJose E. Roman Logically Collective on the communicator passed in `PetscOptionsBegin()` 11927cdbe19fSJose E. Roman 119353acd3b1SBarry Smith Input Parameters: 119453acd3b1SBarry Smith + opt - option name 119553acd3b1SBarry Smith . text - short string that describes the option 119653acd3b1SBarry Smith . man - manual page with additional information on option 119753acd3b1SBarry Smith . list - the possible choices 11980fdccdaeSBarry Smith . currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with 11992fe279fdSBarry Smith .vb 12002fe279fdSBarry Smith PetscOptionsFlist(..., obj->value,value,len,&flg); 12012fe279fdSBarry Smith if (flg) { 12022fe279fdSBarry Smith .ve 12033cc1e11dSBarry Smith - len - the length of the character array value 120453acd3b1SBarry Smith 1205d8d19677SJose E. Roman Output Parameters: 120653acd3b1SBarry Smith + value - the value to return 1207811af0c4SBarry Smith - set - `PETSC_TRUE` if found, else `PETSC_FALSE` 120853acd3b1SBarry Smith 120953acd3b1SBarry Smith Level: intermediate 121053acd3b1SBarry Smith 121195452b02SPatrick Sanan Notes: 1212811af0c4SBarry Smith Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()` 121353acd3b1SBarry Smith 121430bab8dbSBarry Smith If the user does not supply the option at all `value` is NOT changed. Thus 121530bab8dbSBarry Smith you should ALWAYS initialize `value` if you access it without first checking if the `set` flag is `PETSC_TRUE`. 12162efd9cb1SBarry Smith 121730bab8dbSBarry Smith The `currentvalue` passed into this routine does not get transferred to the output `value` variable automatically. 1218989712b9SBarry Smith 1219811af0c4SBarry Smith See `PetscOptionsEList()` for when the choices are given in a string array 122053acd3b1SBarry Smith 122153acd3b1SBarry Smith To get a listing of all currently specified options, 1222811af0c4SBarry Smith see `PetscOptionsView()` or `PetscOptionsGetAll()` 122353acd3b1SBarry Smith 1224811af0c4SBarry Smith Developer Note: 1225811af0c4SBarry Smith This cannot check for invalid selection because of things like `MATAIJ` that are not included in the list 1226eabe10d7SBarry Smith 1227db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`, 1228db781477SPatrick Sanan `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`, 1229db781477SPatrick Sanan `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`, 1230c2e3fba1SPatrick Sanan `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`, 1231db781477SPatrick Sanan `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`, 1232db781477SPatrick Sanan `PetscOptionsFList()`, `PetscOptionsEList()`, `PetscOptionsEnum()` 123388aa4217SBarry Smith M*/ 123488aa4217SBarry Smith 1235d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsFList_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char ltext[], const char man[], PetscFunctionList list, const char currentvalue[], char value[], size_t len, PetscBool *set) 1236d71ae5a4SJacob Faibussowitsch { 1237*10c654e6SJacob Faibussowitsch const char *prefix = PetscOptionsObject->prefix; 123844ef3d73SBarry Smith PetscBool lset; 123953acd3b1SBarry Smith 124053acd3b1SBarry Smith PetscFunctionBegin; 1241*10c654e6SJacob Faibussowitsch PetscValidCharPointer(opt, 2); 1242*10c654e6SJacob Faibussowitsch PetscValidCharPointer(value, 7); 1243*10c654e6SJacob Faibussowitsch if (set) PetscValidBoolPointer(set, 9); 12441a1499c8SBarry Smith if (!PetscOptionsObject->count) { 1245*10c654e6SJacob Faibussowitsch PetscOptionItem amsopt; 1246*10c654e6SJacob Faibussowitsch 12479566063dSJacob Faibussowitsch PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, ltext, man, OPTION_FLIST, &amsopt)); 124864facd6cSBarry Smith /* must use system malloc since SAWs may free this */ 12499566063dSJacob Faibussowitsch PetscCall(PetscStrdup(currentvalue ? currentvalue : "", (char **)&amsopt->data)); 12503cc1e11dSBarry Smith amsopt->flist = list; 12513cc1e11dSBarry Smith } 1252*10c654e6SJacob Faibussowitsch PetscCall(PetscOptionsGetString(PetscOptionsObject->options, prefix, opt, value, len, &lset)); 125344ef3d73SBarry Smith if (set) *set = lset; 1254*10c654e6SJacob Faibussowitsch if (ShouldPrintHelp(PetscOptionsObject)) PetscCall(PetscFunctionListPrintTypes(PetscOptionsObject->comm, stdout, Prefix(prefix), opt, ltext, man, list, currentvalue, lset ? value : currentvalue)); 12553ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 125653acd3b1SBarry Smith } 125753acd3b1SBarry Smith 1258*10c654e6SJacob Faibussowitsch #ifdef __cplusplus 1259*10c654e6SJacob Faibussowitsch #include <type_traits> 1260*10c654e6SJacob Faibussowitsch #endif 1261*10c654e6SJacob Faibussowitsch 126288aa4217SBarry Smith /*MC 126353acd3b1SBarry Smith PetscOptionsEList - Puts a list of option values that a single one may be selected from 126453acd3b1SBarry Smith 126588aa4217SBarry Smith Synopsis: 126688aa4217SBarry Smith #include "petscsys.h" 12673a89f35bSSatish Balay PetscErrorCode PetscOptionsEList(const char opt[],const char ltext[],const char man[],const char *const *list,PetscInt ntext,const char currentvalue[],PetscInt *value,PetscBool *set) 126888aa4217SBarry Smith 12697cdbe19fSJose E. Roman Logically Collective on the communicator passed in `PetscOptionsBegin()` 12707cdbe19fSJose E. Roman 127153acd3b1SBarry Smith Input Parameters: 127253acd3b1SBarry Smith + opt - option name 127353acd3b1SBarry Smith . ltext - short string that describes the option 127453acd3b1SBarry Smith . man - manual page with additional information on option 1275a264d7a6SBarry Smith . list - the possible choices (one of these must be selected, anything else is invalid) 127653acd3b1SBarry Smith . ntext - number of choices 12770fdccdaeSBarry Smith - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with 12782fe279fdSBarry Smith .vb 12792fe279fdSBarry Smith PetscOptionsEList(..., obj->value,&value,&flg); 12802fe279fdSBarry Smith .ve if (flg) { 12810fdccdaeSBarry Smith 1282d8d19677SJose E. Roman Output Parameters: 128353acd3b1SBarry Smith + value - the index of the value to return 1284811af0c4SBarry Smith - set - `PETSC_TRUE` if found, else `PETSC_FALSE` 128553acd3b1SBarry Smith 128653acd3b1SBarry Smith Level: intermediate 128753acd3b1SBarry Smith 128895452b02SPatrick Sanan Notes: 1289811af0c4SBarry Smith Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()` 129053acd3b1SBarry Smith 129130bab8dbSBarry Smith If the user does not supply the option at all `value` is NOT changed. Thus 129230bab8dbSBarry Smith you should ALWAYS initialize `value` if you access it without first checking if the `set` flag is `PETSC_TRUE`. 12932efd9cb1SBarry Smith 1294811af0c4SBarry Smith See `PetscOptionsFList()` for when the choices are given in a `PetscFunctionList()` 129553acd3b1SBarry Smith 1296db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`, 1297db781477SPatrick Sanan `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`, 1298db781477SPatrick Sanan `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`, 1299c2e3fba1SPatrick Sanan `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`, 1300db781477SPatrick Sanan `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`, 1301db781477SPatrick Sanan `PetscOptionsFList()`, `PetscOptionsEnum()` 130288aa4217SBarry Smith M*/ 130388aa4217SBarry Smith 1304d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsEList_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char ltext[], const char man[], const char *const *list, PetscInt ntext, const char currentvalue[], PetscInt *value, PetscBool *set) 1305d71ae5a4SJacob Faibussowitsch { 1306*10c654e6SJacob Faibussowitsch const char *prefix = PetscOptionsObject->prefix; 130744ef3d73SBarry Smith PetscBool lset; 130853acd3b1SBarry Smith 130953acd3b1SBarry Smith PetscFunctionBegin; 1310*10c654e6SJacob Faibussowitsch PetscValidCharPointer(opt, 2); 1311*10c654e6SJacob Faibussowitsch PetscValidIntPointer(value, 8); 1312*10c654e6SJacob Faibussowitsch if (set) PetscValidBoolPointer(set, 9); 13131a1499c8SBarry Smith if (!PetscOptionsObject->count) { 1314*10c654e6SJacob Faibussowitsch PetscOptionItem amsopt; 1315*10c654e6SJacob Faibussowitsch 13169566063dSJacob Faibussowitsch PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, ltext, man, OPTION_ELIST, &amsopt)); 131764facd6cSBarry Smith /* must use system malloc since SAWs may free this */ 13189566063dSJacob Faibussowitsch PetscCall(PetscStrdup(currentvalue ? currentvalue : "", (char **)&amsopt->data)); 13199566063dSJacob Faibussowitsch PetscCall(PetscStrNArrayallocpy(ntext, list, (char ***)&amsopt->list)); 1320*10c654e6SJacob Faibussowitsch PetscCheck(ntext <= CHAR_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Number of list entries %" PetscInt_FMT " > %d", ntext, CHAR_MAX); 1321*10c654e6SJacob Faibussowitsch #ifdef __cplusplus 1322*10c654e6SJacob Faibussowitsch static_assert(std::is_same<typename std::decay<decltype(amsopt->nlist)>::type, char>::value, ""); 1323*10c654e6SJacob Faibussowitsch #endif 1324*10c654e6SJacob Faibussowitsch amsopt->nlist = (char)ntext; 13251ae3d29cSBarry Smith } 1326*10c654e6SJacob Faibussowitsch PetscCall(PetscOptionsGetEList(PetscOptionsObject->options, prefix, opt, list, ntext, value, &lset)); 132744ef3d73SBarry Smith if (set) *set = lset; 1328*10c654e6SJacob Faibussowitsch if (ShouldPrintHelp(PetscOptionsObject)) { 1329*10c654e6SJacob Faibussowitsch const MPI_Comm comm = PetscOptionsObject->comm; 1330*10c654e6SJacob Faibussowitsch 1331*10c654e6SJacob Faibussowitsch PetscCall((*PetscHelpPrintf)(comm, " -%s%s: <now %s : formerly %s> %s (choose one of)", Prefix(prefix), opt + 1, lset ? list[*value] : currentvalue, currentvalue, ltext)); 1332*10c654e6SJacob Faibussowitsch for (PetscInt i = 0; i < ntext; ++i) PetscCall((*PetscHelpPrintf)(comm, " %s", list[i])); 1333*10c654e6SJacob Faibussowitsch PetscCall((*PetscHelpPrintf)(comm, " (%s)\n", ManSection(man))); 133453acd3b1SBarry Smith } 13353ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 133653acd3b1SBarry Smith } 133753acd3b1SBarry Smith 133888aa4217SBarry Smith /*MC 1339acfcf0e5SJed Brown PetscOptionsBoolGroupBegin - First in a series of logical queries on the options database for 1340d5649816SBarry Smith which at most a single value can be true. 134153acd3b1SBarry Smith 134288aa4217SBarry Smith Synopsis: 134388aa4217SBarry Smith #include "petscsys.h" 13443a89f35bSSatish Balay PetscErrorCode PetscOptionsBoolGroupBegin(const char opt[],const char text[],const char man[],PetscBool *flg) 134588aa4217SBarry Smith 13467cdbe19fSJose E. Roman Logically Collective on the communicator passed in `PetscOptionsBegin()` 13477cdbe19fSJose E. Roman 134853acd3b1SBarry Smith Input Parameters: 134953acd3b1SBarry Smith + opt - option name 135053acd3b1SBarry Smith . text - short string that describes the option 135153acd3b1SBarry Smith - man - manual page with additional information on option 135253acd3b1SBarry Smith 135353acd3b1SBarry Smith Output Parameter: 135453acd3b1SBarry Smith . flg - whether that option was set or not 135553acd3b1SBarry Smith 135653acd3b1SBarry Smith Level: intermediate 135753acd3b1SBarry Smith 135895452b02SPatrick Sanan Notes: 1359811af0c4SBarry Smith Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()` 136053acd3b1SBarry Smith 136130bab8dbSBarry Smith Must be followed by 0 or more `PetscOptionsBoolGroup()`s and `PetscOptionsBoolGroupEnd()` 136253acd3b1SBarry Smith 1363db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`, 1364db781477SPatrick Sanan `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`, 1365db781477SPatrick Sanan `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`, 1366c2e3fba1SPatrick Sanan `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`, 1367db781477SPatrick Sanan `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`, 1368db781477SPatrick Sanan `PetscOptionsFList()`, `PetscOptionsEList()` 136988aa4217SBarry Smith M*/ 137088aa4217SBarry Smith 1371d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsBoolGroupBegin_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool *flg) 1372d71ae5a4SJacob Faibussowitsch { 1373*10c654e6SJacob Faibussowitsch const char *prefix = PetscOptionsObject->prefix; 137453acd3b1SBarry Smith 137553acd3b1SBarry Smith PetscFunctionBegin; 1376*10c654e6SJacob Faibussowitsch PetscValidCharPointer(opt, 2); 1377*10c654e6SJacob Faibussowitsch PetscValidBoolPointer(flg, 5); 1378e55864a3SBarry Smith if (!PetscOptionsObject->count) { 1379*10c654e6SJacob Faibussowitsch PetscOptionItem amsopt; 1380*10c654e6SJacob Faibussowitsch 13819566063dSJacob Faibussowitsch PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt)); 13829566063dSJacob Faibussowitsch PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data)); 1383a297a907SKarl Rupp 1384ace3abfcSBarry Smith *(PetscBool *)amsopt->data = PETSC_FALSE; 13851ae3d29cSBarry Smith } 138668b16fdaSBarry Smith *flg = PETSC_FALSE; 1387*10c654e6SJacob Faibussowitsch PetscCall(PetscOptionsGetBool(PetscOptionsObject->options, prefix, opt, flg, NULL)); 1388*10c654e6SJacob Faibussowitsch if (ShouldPrintHelp(PetscOptionsObject)) { 1389*10c654e6SJacob Faibussowitsch const MPI_Comm comm = PetscOptionsObject->comm; 1390*10c654e6SJacob Faibussowitsch 1391*10c654e6SJacob Faibussowitsch PetscCall((*PetscHelpPrintf)(comm, " Pick at most one of -------------\n")); 1392*10c654e6SJacob Faibussowitsch PetscCall((*PetscHelpPrintf)(comm, " -%s%s: %s (%s)\n", Prefix(prefix), opt + 1, text, ManSection(man))); 139353acd3b1SBarry Smith } 13943ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 139553acd3b1SBarry Smith } 139653acd3b1SBarry Smith 139788aa4217SBarry Smith /*MC 1398acfcf0e5SJed Brown PetscOptionsBoolGroup - One in a series of logical queries on the options database for 1399d5649816SBarry Smith which at most a single value can be true. 140053acd3b1SBarry Smith 140188aa4217SBarry Smith Synopsis: 140288aa4217SBarry Smith #include "petscsys.h" 14033a89f35bSSatish Balay PetscErrorCode PetscOptionsBoolGroup(const char opt[],const char text[],const char man[],PetscBool *flg) 140488aa4217SBarry Smith 14057cdbe19fSJose E. Roman Logically Collective on the communicator passed in `PetscOptionsBegin()` 14067cdbe19fSJose E. Roman 140753acd3b1SBarry Smith Input Parameters: 140853acd3b1SBarry Smith + opt - option name 140953acd3b1SBarry Smith . text - short string that describes the option 141053acd3b1SBarry Smith - man - manual page with additional information on option 141153acd3b1SBarry Smith 141253acd3b1SBarry Smith Output Parameter: 1413811af0c4SBarry Smith . flg - `PETSC_TRUE` if found, else `PETSC_FALSE` 141453acd3b1SBarry Smith 141553acd3b1SBarry Smith Level: intermediate 141653acd3b1SBarry Smith 141795452b02SPatrick Sanan Notes: 1418811af0c4SBarry Smith Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()` 141953acd3b1SBarry Smith 1420811af0c4SBarry Smith Must follow a `PetscOptionsBoolGroupBegin()` and preceded a `PetscOptionsBoolGroupEnd()` 142153acd3b1SBarry Smith 1422db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`, 1423db781477SPatrick Sanan `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`, 1424db781477SPatrick Sanan `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`, 1425c2e3fba1SPatrick Sanan `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`, 1426db781477SPatrick Sanan `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`, 1427db781477SPatrick Sanan `PetscOptionsFList()`, `PetscOptionsEList()` 142888aa4217SBarry Smith M*/ 142988aa4217SBarry Smith 1430d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsBoolGroup_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool *flg) 1431d71ae5a4SJacob Faibussowitsch { 1432*10c654e6SJacob Faibussowitsch const char *prefix = PetscOptionsObject->prefix; 143353acd3b1SBarry Smith 143453acd3b1SBarry Smith PetscFunctionBegin; 1435*10c654e6SJacob Faibussowitsch PetscValidCharPointer(opt, 2); 1436*10c654e6SJacob Faibussowitsch PetscValidBoolPointer(flg, 5); 1437e55864a3SBarry Smith if (!PetscOptionsObject->count) { 1438*10c654e6SJacob Faibussowitsch PetscOptionItem amsopt; 1439*10c654e6SJacob Faibussowitsch 14409566063dSJacob Faibussowitsch PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt)); 14419566063dSJacob Faibussowitsch PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data)); 1442a297a907SKarl Rupp 1443ace3abfcSBarry Smith *(PetscBool *)amsopt->data = PETSC_FALSE; 14441ae3d29cSBarry Smith } 144517326d04SJed Brown *flg = PETSC_FALSE; 1446*10c654e6SJacob Faibussowitsch PetscCall(PetscOptionsGetBool(PetscOptionsObject->options, prefix, opt, flg, NULL)); 1447*10c654e6SJacob Faibussowitsch if (ShouldPrintHelp(PetscOptionsObject)) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, " -%s%s: %s (%s)\n", Prefix(prefix), opt + 1, text, ManSection(man))); 14483ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 144953acd3b1SBarry Smith } 145053acd3b1SBarry Smith 145188aa4217SBarry Smith /*MC 1452acfcf0e5SJed Brown PetscOptionsBoolGroupEnd - Last in a series of logical queries on the options database for 1453d5649816SBarry Smith which at most a single value can be true. 145453acd3b1SBarry Smith 145588aa4217SBarry Smith Synopsis: 145688aa4217SBarry Smith #include "petscsys.h" 14573a89f35bSSatish Balay PetscErrorCode PetscOptionsBoolGroupEnd(const char opt[],const char text[],const char man[],PetscBool *flg) 145888aa4217SBarry Smith 14597cdbe19fSJose E. Roman Logically Collective on the communicator passed in `PetscOptionsBegin()` 14607cdbe19fSJose E. Roman 146153acd3b1SBarry Smith Input Parameters: 146253acd3b1SBarry Smith + opt - option name 146353acd3b1SBarry Smith . text - short string that describes the option 146453acd3b1SBarry Smith - man - manual page with additional information on option 146553acd3b1SBarry Smith 146653acd3b1SBarry Smith Output Parameter: 1467811af0c4SBarry Smith . flg - `PETSC_TRUE` if found, else `PETSC_FALSE` 146853acd3b1SBarry Smith 146953acd3b1SBarry Smith Level: intermediate 147053acd3b1SBarry Smith 147195452b02SPatrick Sanan Notes: 1472811af0c4SBarry Smith Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()` 147353acd3b1SBarry Smith 1474811af0c4SBarry Smith Must follow a `PetscOptionsBoolGroupBegin()` 147553acd3b1SBarry Smith 1476db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`, 1477db781477SPatrick Sanan `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`, 1478db781477SPatrick Sanan `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`, 1479c2e3fba1SPatrick Sanan `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`, 1480db781477SPatrick Sanan `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`, 1481db781477SPatrick Sanan `PetscOptionsFList()`, `PetscOptionsEList()` 148288aa4217SBarry Smith M*/ 148388aa4217SBarry Smith 1484d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsBoolGroupEnd_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool *flg) 1485d71ae5a4SJacob Faibussowitsch { 1486*10c654e6SJacob Faibussowitsch const char *prefix = PetscOptionsObject->prefix; 148753acd3b1SBarry Smith 148853acd3b1SBarry Smith PetscFunctionBegin; 1489*10c654e6SJacob Faibussowitsch PetscValidCharPointer(opt, 2); 1490*10c654e6SJacob Faibussowitsch PetscValidBoolPointer(flg, 5); 1491e55864a3SBarry Smith if (!PetscOptionsObject->count) { 1492*10c654e6SJacob Faibussowitsch PetscOptionItem amsopt; 1493*10c654e6SJacob Faibussowitsch 14949566063dSJacob Faibussowitsch PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt)); 14959566063dSJacob Faibussowitsch PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data)); 1496a297a907SKarl Rupp 1497ace3abfcSBarry Smith *(PetscBool *)amsopt->data = PETSC_FALSE; 14981ae3d29cSBarry Smith } 149917326d04SJed Brown *flg = PETSC_FALSE; 1500*10c654e6SJacob Faibussowitsch PetscCall(PetscOptionsGetBool(PetscOptionsObject->options, prefix, opt, flg, NULL)); 1501*10c654e6SJacob Faibussowitsch if (ShouldPrintHelp(PetscOptionsObject)) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, " -%s%s: %s (%s)\n", Prefix(prefix), opt + 1, text, ManSection(man))); 15023ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 150353acd3b1SBarry Smith } 150453acd3b1SBarry Smith 150588aa4217SBarry Smith /*MC 1506acfcf0e5SJed Brown PetscOptionsBool - Determines if a particular option is in the database with a true or false 150753acd3b1SBarry Smith 150888aa4217SBarry Smith Synopsis: 150988aa4217SBarry Smith #include "petscsys.h" 15103a89f35bSSatish Balay PetscErrorCode PetscOptionsBool(const char opt[],const char text[],const char man[],PetscBool currentvalue,PetscBool *flg,PetscBool *set) 151188aa4217SBarry Smith 15127cdbe19fSJose E. Roman Logically Collective on the communicator passed in `PetscOptionsBegin()` 15137cdbe19fSJose E. Roman 151453acd3b1SBarry Smith Input Parameters: 151553acd3b1SBarry Smith + opt - option name 151653acd3b1SBarry Smith . text - short string that describes the option 1517868c398cSBarry Smith . man - manual page with additional information on option 151894ae4db5SBarry Smith - currentvalue - the current value 151953acd3b1SBarry Smith 1520d8d19677SJose E. Roman Output Parameters: 1521811af0c4SBarry Smith + flg -` PETSC_TRUE` or `PETSC_FALSE` 1522811af0c4SBarry Smith - set - `PETSC_TRUE` if found, else `PETSC_FALSE` 152353acd3b1SBarry Smith 152430bab8dbSBarry Smith Level: beginner 152530bab8dbSBarry Smith 15262efd9cb1SBarry Smith Notes: 1527811af0c4SBarry Smith TRUE, true, YES, yes, nostring, and 1 all translate to `PETSC_TRUE` 1528811af0c4SBarry Smith FALSE, false, NO, no, and 0 all translate to `PETSC_FALSE` 15292efd9cb1SBarry Smith 153030bab8dbSBarry Smith If the option is given, but no value is provided, then flg and set are both given the value `PETSC_TRUE`. That is `-requested_bool` 153130bab8dbSBarry Smith is equivalent to `-requested_bool true` 15322efd9cb1SBarry Smith 153330bab8dbSBarry Smith If the user does not supply the option at all `flg` is NOT changed. Thus 153430bab8dbSBarry Smith you should ALWAYS initialize the `flg` variable if you access it without first checking if the `set` flag is `PETSC_TRUE`. 15352efd9cb1SBarry Smith 1536811af0c4SBarry Smith Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()` 153753acd3b1SBarry Smith 1538db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`, 1539db781477SPatrick Sanan `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`, 1540db781477SPatrick Sanan `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, 1541db781477SPatrick Sanan `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`, 1542c2e3fba1SPatrick Sanan `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`, 1543db781477SPatrick Sanan `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`, 1544db781477SPatrick Sanan `PetscOptionsFList()`, `PetscOptionsEList()` 154588aa4217SBarry Smith M*/ 154688aa4217SBarry Smith 1547d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsBool_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool currentvalue, PetscBool *flg, PetscBool *set) 1548d71ae5a4SJacob Faibussowitsch { 1549*10c654e6SJacob Faibussowitsch const char *prefix = PetscOptionsObject->prefix; 1550ace3abfcSBarry Smith PetscBool iset; 155153acd3b1SBarry Smith 155253acd3b1SBarry Smith PetscFunctionBegin; 1553*10c654e6SJacob Faibussowitsch PetscValidCharPointer(opt, 2); 1554*10c654e6SJacob Faibussowitsch PetscValidBoolPointer(flg, 6); 1555*10c654e6SJacob Faibussowitsch if (set) PetscValidBoolPointer(set, 7); 1556e55864a3SBarry Smith if (!PetscOptionsObject->count) { 1557*10c654e6SJacob Faibussowitsch PetscOptionItem amsopt; 1558*10c654e6SJacob Faibussowitsch 15599566063dSJacob Faibussowitsch PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt)); 15609566063dSJacob Faibussowitsch PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data)); 1561a297a907SKarl Rupp 156294ae4db5SBarry Smith *(PetscBool *)amsopt->data = currentvalue; 1563af6d86caSBarry Smith } 1564*10c654e6SJacob Faibussowitsch PetscCall(PetscOptionsGetBool(PetscOptionsObject->options, prefix, opt, flg, &iset)); 156553acd3b1SBarry Smith if (set) *set = iset; 1566*10c654e6SJacob Faibussowitsch if (ShouldPrintHelp(PetscOptionsObject)) { 1567*10c654e6SJacob Faibussowitsch const char *curvalue = PetscBools[currentvalue]; 1568*10c654e6SJacob Faibussowitsch 1569*10c654e6SJacob Faibussowitsch PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, " -%s%s: <now %s : formerly %s> %s (%s)\n", Prefix(prefix), opt + 1, iset ? PetscBools[*flg] : curvalue, curvalue, text, ManSection(man))); 157053acd3b1SBarry Smith } 15713ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 157253acd3b1SBarry Smith } 157353acd3b1SBarry Smith 157488aa4217SBarry Smith /*MC 157553acd3b1SBarry Smith PetscOptionsRealArray - Gets an array of double values for a particular 157653acd3b1SBarry Smith option in the database. The values must be separated with commas with 157753acd3b1SBarry Smith no intervening spaces. 157853acd3b1SBarry Smith 157988aa4217SBarry Smith Synopsis: 158088aa4217SBarry Smith #include "petscsys.h" 15813a89f35bSSatish Balay PetscErrorCode PetscOptionsRealArray(const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscBool *set) 158288aa4217SBarry Smith 15837cdbe19fSJose E. Roman Logically Collective on the communicator passed in `PetscOptionsBegin()` 15847cdbe19fSJose E. Roman 158553acd3b1SBarry Smith Input Parameters: 158653acd3b1SBarry Smith + opt - the option one is seeking 158753acd3b1SBarry Smith . text - short string describing option 158853acd3b1SBarry Smith . man - manual page for option 1589c89788bdSBarry Smith - n - maximum number of values that value has room for 159053acd3b1SBarry Smith 1591d8d19677SJose E. Roman Output Parameters: 159253acd3b1SBarry Smith + value - location to copy values 1593c89788bdSBarry Smith . n - actual number of values found 1594811af0c4SBarry Smith - set - `PETSC_TRUE` if found, else `PETSC_FALSE` 159553acd3b1SBarry Smith 159653acd3b1SBarry Smith Level: beginner 159753acd3b1SBarry Smith 159830bab8dbSBarry Smith Note: 1599811af0c4SBarry Smith Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()` 160053acd3b1SBarry Smith 1601db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`, 1602db781477SPatrick Sanan `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`, 1603db781477SPatrick Sanan `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`, 1604c2e3fba1SPatrick Sanan `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`, 1605db781477SPatrick Sanan `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`, 1606db781477SPatrick Sanan `PetscOptionsFList()`, `PetscOptionsEList()` 160788aa4217SBarry Smith M*/ 160888aa4217SBarry Smith 1609d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsRealArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscReal value[], PetscInt *n, PetscBool *set) 1610d71ae5a4SJacob Faibussowitsch { 1611*10c654e6SJacob Faibussowitsch const char *prefix = PetscOptionsObject->prefix; 161253acd3b1SBarry Smith 161353acd3b1SBarry Smith PetscFunctionBegin; 1614*10c654e6SJacob Faibussowitsch PetscValidCharPointer(opt, 2); 1615*10c654e6SJacob Faibussowitsch PetscValidIntPointer(n, 6); 1616*10c654e6SJacob Faibussowitsch PetscCheck(*n >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "n (%" PetscInt_FMT ") cannot be negative", *n); 1617*10c654e6SJacob Faibussowitsch if (*n) PetscValidRealPointer(value, 5); 1618*10c654e6SJacob Faibussowitsch if (set) PetscValidBoolPointer(set, 7); 1619e55864a3SBarry Smith if (!PetscOptionsObject->count) { 1620*10c654e6SJacob Faibussowitsch const PetscInt nv = *n; 1621e26ddf31SBarry Smith PetscReal *vals; 1622*10c654e6SJacob Faibussowitsch PetscOptionItem amsopt; 1623e26ddf31SBarry Smith 16249566063dSJacob Faibussowitsch PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_REAL_ARRAY, &amsopt)); 1625*10c654e6SJacob Faibussowitsch PetscCall(PetscMalloc(nv * sizeof(*vals), &vals)); 1626*10c654e6SJacob Faibussowitsch for (PetscInt i = 0; i < nv; ++i) vals[i] = value[i]; 1627*10c654e6SJacob Faibussowitsch amsopt->arraylength = nv; 1628*10c654e6SJacob Faibussowitsch amsopt->data = vals; 1629e26ddf31SBarry Smith } 1630*10c654e6SJacob Faibussowitsch PetscCall(PetscOptionsGetRealArray(PetscOptionsObject->options, prefix, opt, value, n, set)); 1631*10c654e6SJacob Faibussowitsch if (ShouldPrintHelp(PetscOptionsObject)) { 1632*10c654e6SJacob Faibussowitsch const PetscInt nv = *n; 1633*10c654e6SJacob Faibussowitsch const MPI_Comm comm = PetscOptionsObject->comm; 1634*10c654e6SJacob Faibussowitsch 1635*10c654e6SJacob Faibussowitsch PetscCall((*PetscHelpPrintf)(comm, " -%s%s: <%g", Prefix(prefix), opt + 1, (double)value[0])); 1636*10c654e6SJacob Faibussowitsch for (PetscInt i = 1; i < nv; ++i) PetscCall((*PetscHelpPrintf)(comm, ",%g", (double)value[i])); 1637*10c654e6SJacob Faibussowitsch PetscCall((*PetscHelpPrintf)(comm, ">: %s (%s)\n", text, ManSection(man))); 163853acd3b1SBarry Smith } 16393ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 164053acd3b1SBarry Smith } 164153acd3b1SBarry Smith 164288aa4217SBarry Smith /*MC 1643811af0c4SBarry Smith PetscOptionsScalarArray - Gets an array of `PetscScalar` values for a particular 1644050cccc3SHong Zhang option in the database. The values must be separated with commas with 1645050cccc3SHong Zhang no intervening spaces. 1646050cccc3SHong Zhang 164788aa4217SBarry Smith Synopsis: 164888aa4217SBarry Smith #include "petscsys.h" 16493a89f35bSSatish Balay PetscErrorCode PetscOptionsScalarArray(const char opt[],const char text[],const char man[],PetscScalar value[],PetscInt *n,PetscBool *set) 165088aa4217SBarry Smith 16517cdbe19fSJose E. Roman Logically Collective on the communicator passed in `PetscOptionsBegin()` 16527cdbe19fSJose E. Roman 1653050cccc3SHong Zhang Input Parameters: 1654050cccc3SHong Zhang + opt - the option one is seeking 1655050cccc3SHong Zhang . text - short string describing option 1656050cccc3SHong Zhang . man - manual page for option 1657c89788bdSBarry Smith - n - maximum number of values allowed in the value array 1658050cccc3SHong Zhang 1659d8d19677SJose E. Roman Output Parameters: 1660050cccc3SHong Zhang + value - location to copy values 1661c89788bdSBarry Smith . n - actual number of values found 1662811af0c4SBarry Smith - set - `PETSC_TRUE` if found, else `PETSC_FALSE` 1663050cccc3SHong Zhang 1664050cccc3SHong Zhang Level: beginner 1665050cccc3SHong Zhang 166630bab8dbSBarry Smith Note: 1667811af0c4SBarry Smith Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()` 1668050cccc3SHong Zhang 1669db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`, 1670db781477SPatrick Sanan `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`, 1671db781477SPatrick Sanan `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`, 1672c2e3fba1SPatrick Sanan `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`, 1673db781477SPatrick Sanan `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`, 1674db781477SPatrick Sanan `PetscOptionsFList()`, `PetscOptionsEList()` 167588aa4217SBarry Smith M*/ 167688aa4217SBarry Smith 1677d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsScalarArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscScalar value[], PetscInt *n, PetscBool *set) 1678d71ae5a4SJacob Faibussowitsch { 1679*10c654e6SJacob Faibussowitsch const char *prefix = PetscOptionsObject->prefix; 1680050cccc3SHong Zhang 1681050cccc3SHong Zhang PetscFunctionBegin; 1682*10c654e6SJacob Faibussowitsch PetscValidCharPointer(opt, 2); 1683*10c654e6SJacob Faibussowitsch PetscValidIntPointer(n, 6); 1684*10c654e6SJacob Faibussowitsch PetscCheck(*n >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "n (%" PetscInt_FMT ") cannot be negative", *n); 1685*10c654e6SJacob Faibussowitsch if (*n) PetscValidScalarPointer(value, 5); 1686*10c654e6SJacob Faibussowitsch if (set) PetscValidBoolPointer(set, 7); 1687050cccc3SHong Zhang if (!PetscOptionsObject->count) { 1688*10c654e6SJacob Faibussowitsch const PetscInt nv = *n; 1689*10c654e6SJacob Faibussowitsch PetscOptionItem amsopt; 1690050cccc3SHong Zhang PetscScalar *vals; 1691050cccc3SHong Zhang 16929566063dSJacob Faibussowitsch PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_SCALAR_ARRAY, &amsopt)); 1693*10c654e6SJacob Faibussowitsch PetscCall(PetscMalloc(nv * sizeof(*vals), &vals)); 1694*10c654e6SJacob Faibussowitsch for (PetscInt i = 0; i < nv; ++i) vals[i] = value[i]; 1695*10c654e6SJacob Faibussowitsch amsopt->arraylength = nv; 1696*10c654e6SJacob Faibussowitsch amsopt->data = vals; 1697050cccc3SHong Zhang } 1698*10c654e6SJacob Faibussowitsch PetscCall(PetscOptionsGetScalarArray(PetscOptionsObject->options, prefix, opt, value, n, set)); 1699*10c654e6SJacob Faibussowitsch if (ShouldPrintHelp(PetscOptionsObject)) { 1700*10c654e6SJacob Faibussowitsch const PetscInt nv = *n; 1701*10c654e6SJacob Faibussowitsch const MPI_Comm comm = PetscOptionsObject->comm; 1702*10c654e6SJacob Faibussowitsch 1703*10c654e6SJacob Faibussowitsch PetscCall((*PetscHelpPrintf)(comm, " -%s%s: <%g+%gi", Prefix(prefix), opt + 1, (double)PetscRealPart(value[0]), (double)PetscImaginaryPart(value[0]))); 1704*10c654e6SJacob Faibussowitsch for (PetscInt i = 1; i < nv; ++i) PetscCall((*PetscHelpPrintf)(comm, ",%g+%gi", (double)PetscRealPart(value[i]), (double)PetscImaginaryPart(value[i]))); 1705*10c654e6SJacob Faibussowitsch PetscCall((*PetscHelpPrintf)(comm, ">: %s (%s)\n", text, ManSection(man))); 1706050cccc3SHong Zhang } 17073ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1708050cccc3SHong Zhang } 170953acd3b1SBarry Smith 171088aa4217SBarry Smith /*MC 171153acd3b1SBarry Smith PetscOptionsIntArray - Gets an array of integers for a particular 1712b32a342fSShri Abhyankar option in the database. 171353acd3b1SBarry Smith 171488aa4217SBarry Smith Synopsis: 171588aa4217SBarry Smith #include "petscsys.h" 17163a89f35bSSatish Balay PetscErrorCode PetscOptionsIntArray(const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscBool *set) 171788aa4217SBarry Smith 17187cdbe19fSJose E. Roman Logically Collective on the communicator passed in `PetscOptionsBegin()` 17197cdbe19fSJose E. Roman 172053acd3b1SBarry Smith Input Parameters: 172153acd3b1SBarry Smith + opt - the option one is seeking 172253acd3b1SBarry Smith . text - short string describing option 172353acd3b1SBarry Smith . man - manual page for option 1724f8a50e2bSBarry Smith - n - maximum number of values 172553acd3b1SBarry Smith 1726d8d19677SJose E. Roman Output Parameters: 172753acd3b1SBarry Smith + value - location to copy values 1728f8a50e2bSBarry Smith . n - actual number of values found 1729811af0c4SBarry Smith - set - `PETSC_TRUE` if found, else `PETSC_FALSE` 173053acd3b1SBarry Smith 173153acd3b1SBarry Smith Level: beginner 173253acd3b1SBarry Smith 173353acd3b1SBarry Smith Notes: 1734b32a342fSShri Abhyankar The array can be passed as 1735811af0c4SBarry Smith + a comma separated list - 0,1,2,3,4,5,6,7 1736811af0c4SBarry Smith . a range (start\-end+1) - 0-8 1737811af0c4SBarry Smith . a range with given increment (start\-end+1:inc) - 0-7:2 1738811af0c4SBarry Smith - a combination of values and ranges separated by commas - 0,1-8,8-15:2 1739b32a342fSShri Abhyankar 1740b32a342fSShri Abhyankar There must be no intervening spaces between the values. 174153acd3b1SBarry Smith 1742811af0c4SBarry Smith Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()` 174353acd3b1SBarry Smith 1744db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`, 1745db781477SPatrick Sanan `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`, 1746db781477SPatrick Sanan `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`, 1747c2e3fba1SPatrick Sanan `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`, 1748db781477SPatrick Sanan `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`, 1749db781477SPatrick Sanan `PetscOptionsFList()`, `PetscOptionsEList()`, `PetscOptionsRealArray()` 175088aa4217SBarry Smith M*/ 175188aa4217SBarry Smith 1752d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsIntArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscInt value[], PetscInt *n, PetscBool *set) 1753d71ae5a4SJacob Faibussowitsch { 1754*10c654e6SJacob Faibussowitsch const char *prefix = PetscOptionsObject->prefix; 175553acd3b1SBarry Smith 175653acd3b1SBarry Smith PetscFunctionBegin; 1757*10c654e6SJacob Faibussowitsch PetscValidCharPointer(opt, 2); 1758*10c654e6SJacob Faibussowitsch PetscValidIntPointer(n, 6); 1759*10c654e6SJacob Faibussowitsch PetscCheck(*n >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "n (%" PetscInt_FMT ") cannot be negative", *n); 1760*10c654e6SJacob Faibussowitsch if (*n) PetscValidIntPointer(value, 5); 1761*10c654e6SJacob Faibussowitsch if (set) PetscValidBoolPointer(set, 7); 1762e55864a3SBarry Smith if (!PetscOptionsObject->count) { 1763*10c654e6SJacob Faibussowitsch const PetscInt nv = *n; 1764e26ddf31SBarry Smith PetscInt *vals; 1765*10c654e6SJacob Faibussowitsch PetscOptionItem amsopt; 1766e26ddf31SBarry Smith 17679566063dSJacob Faibussowitsch PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_INT_ARRAY, &amsopt)); 1768*10c654e6SJacob Faibussowitsch PetscCall(PetscMalloc1(nv, &vals)); 1769*10c654e6SJacob Faibussowitsch for (PetscInt i = 0; i < nv; ++i) vals[i] = value[i]; 1770*10c654e6SJacob Faibussowitsch amsopt->arraylength = nv; 1771*10c654e6SJacob Faibussowitsch amsopt->data = vals; 1772e26ddf31SBarry Smith } 1773*10c654e6SJacob Faibussowitsch PetscCall(PetscOptionsGetIntArray(PetscOptionsObject->options, prefix, opt, value, n, set)); 1774*10c654e6SJacob Faibussowitsch if (ShouldPrintHelp(PetscOptionsObject)) { 1775*10c654e6SJacob Faibussowitsch const PetscInt nv = *n; 1776*10c654e6SJacob Faibussowitsch const MPI_Comm comm = PetscOptionsObject->comm; 1777*10c654e6SJacob Faibussowitsch 1778*10c654e6SJacob Faibussowitsch PetscCall((*PetscHelpPrintf)(comm, " -%s%s: <%" PetscInt_FMT, Prefix(prefix), opt + 1, value[0])); 1779*10c654e6SJacob Faibussowitsch for (PetscInt i = 1; i < nv; ++i) PetscCall((*PetscHelpPrintf)(comm, ",%" PetscInt_FMT, value[i])); 1780*10c654e6SJacob Faibussowitsch PetscCall((*PetscHelpPrintf)(comm, ">: %s (%s)\n", text, ManSection(man))); 178153acd3b1SBarry Smith } 17823ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 178353acd3b1SBarry Smith } 178453acd3b1SBarry Smith 178588aa4217SBarry Smith /*MC 178653acd3b1SBarry Smith PetscOptionsStringArray - Gets an array of string values for a particular 178753acd3b1SBarry Smith option in the database. The values must be separated with commas with 178853acd3b1SBarry Smith no intervening spaces. 178953acd3b1SBarry Smith 179088aa4217SBarry Smith Synopsis: 179188aa4217SBarry Smith #include "petscsys.h" 17923a89f35bSSatish Balay PetscErrorCode PetscOptionsStringArray(const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscBool *set) 179388aa4217SBarry Smith 17947cdbe19fSJose E. Roman Logically Collective on the communicator passed in `PetscOptionsBegin()`; No Fortran Support 17957cdbe19fSJose E. Roman 179653acd3b1SBarry Smith Input Parameters: 179753acd3b1SBarry Smith + opt - the option one is seeking 179853acd3b1SBarry Smith . text - short string describing option 179953acd3b1SBarry Smith . man - manual page for option 180053acd3b1SBarry Smith - nmax - maximum number of strings 180153acd3b1SBarry Smith 1802d8d19677SJose E. Roman Output Parameters: 180353acd3b1SBarry Smith + value - location to copy strings 180453acd3b1SBarry Smith . nmax - actual number of strings found 1805811af0c4SBarry Smith - set - `PETSC_TRUE` if found, else `PETSC_FALSE` 180653acd3b1SBarry Smith 180753acd3b1SBarry Smith Level: beginner 180853acd3b1SBarry Smith 180953acd3b1SBarry Smith Notes: 181053acd3b1SBarry Smith The user should pass in an array of pointers to char, to hold all the 181153acd3b1SBarry Smith strings returned by this function. 181253acd3b1SBarry Smith 181353acd3b1SBarry Smith The user is responsible for deallocating the strings that are 1814cf53795eSBarry Smith returned. 181553acd3b1SBarry Smith 1816811af0c4SBarry Smith Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()` 181753acd3b1SBarry Smith 1818db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`, 1819db781477SPatrick Sanan `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`, 1820db781477SPatrick Sanan `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`, 1821c2e3fba1SPatrick Sanan `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`, 1822db781477SPatrick Sanan `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`, 1823db781477SPatrick Sanan `PetscOptionsFList()`, `PetscOptionsEList()` 182488aa4217SBarry Smith M*/ 182588aa4217SBarry Smith 1826d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsStringArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], char *value[], PetscInt *nmax, PetscBool *set) 1827d71ae5a4SJacob Faibussowitsch { 1828*10c654e6SJacob Faibussowitsch const char *prefix = PetscOptionsObject->prefix; 182953acd3b1SBarry Smith 183053acd3b1SBarry Smith PetscFunctionBegin; 1831*10c654e6SJacob Faibussowitsch PetscValidCharPointer(opt, 2); 1832*10c654e6SJacob Faibussowitsch PetscValidIntPointer(nmax, 6); 1833*10c654e6SJacob Faibussowitsch PetscCheck(*nmax >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "n (%" PetscInt_FMT ") cannot be negative", *nmax); 1834*10c654e6SJacob Faibussowitsch if (*nmax) PetscValidPointer(value, 5); 1835*10c654e6SJacob Faibussowitsch if (set) PetscValidBoolPointer(set, 7); 1836e55864a3SBarry Smith if (!PetscOptionsObject->count) { 1837*10c654e6SJacob Faibussowitsch const PetscInt nmaxv = *nmax; 1838*10c654e6SJacob Faibussowitsch PetscOptionItem amsopt; 1839a297a907SKarl Rupp 1840*10c654e6SJacob Faibussowitsch PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_STRING_ARRAY, &amsopt)); 1841*10c654e6SJacob Faibussowitsch PetscCall(PetscMalloc1(nmaxv, (char **)&amsopt->data)); 1842*10c654e6SJacob Faibussowitsch amsopt->arraylength = nmaxv; 18431ae3d29cSBarry Smith } 1844*10c654e6SJacob Faibussowitsch PetscCall(PetscOptionsGetStringArray(PetscOptionsObject->options, prefix, opt, value, nmax, set)); 1845*10c654e6SJacob Faibussowitsch if (ShouldPrintHelp(PetscOptionsObject)) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, " -%s%s: <string1,string2,...>: %s (%s)\n", Prefix(prefix), opt + 1, text, ManSection(man))); 18463ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 184753acd3b1SBarry Smith } 184853acd3b1SBarry Smith 184988aa4217SBarry Smith /*MC 1850acfcf0e5SJed Brown PetscOptionsBoolArray - Gets an array of logical values (true or false) for a particular 1851e2446a98SMatthew Knepley option in the database. The values must be separated with commas with 1852e2446a98SMatthew Knepley no intervening spaces. 1853e2446a98SMatthew Knepley 185488aa4217SBarry Smith Synopsis: 185588aa4217SBarry Smith #include "petscsys.h" 18563a89f35bSSatish Balay PetscErrorCode PetscOptionsBoolArray(const char opt[],const char text[],const char man[],PetscBool value[],PetscInt *n,PetscBool *set) 185788aa4217SBarry Smith 18587cdbe19fSJose E. Roman Logically Collective on the communicator passed in `PetscOptionsBegin()` 18597cdbe19fSJose E. Roman 1860e2446a98SMatthew Knepley Input Parameters: 1861e2446a98SMatthew Knepley + opt - the option one is seeking 1862e2446a98SMatthew Knepley . text - short string describing option 1863e2446a98SMatthew Knepley . man - manual page for option 1864c89788bdSBarry Smith - n - maximum number of values allowed in the value array 1865e2446a98SMatthew Knepley 1866d8d19677SJose E. Roman Output Parameters: 1867e2446a98SMatthew Knepley + value - location to copy values 1868c89788bdSBarry Smith . n - actual number of values found 1869811af0c4SBarry Smith - set - `PETSC_TRUE` if found, else `PETSC_FALSE` 1870e2446a98SMatthew Knepley 1871e2446a98SMatthew Knepley Level: beginner 1872e2446a98SMatthew Knepley 1873e2446a98SMatthew Knepley Notes: 187430bab8dbSBarry Smith The user should pass in an array of `PetscBool` 1875e2446a98SMatthew Knepley 1876811af0c4SBarry Smith Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()` 1877e2446a98SMatthew Knepley 1878db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`, 1879db781477SPatrick Sanan `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`, 1880db781477SPatrick Sanan `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`, 1881c2e3fba1SPatrick Sanan `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`, 1882db781477SPatrick Sanan `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`, 1883db781477SPatrick Sanan `PetscOptionsFList()`, `PetscOptionsEList()` 188488aa4217SBarry Smith M*/ 188588aa4217SBarry Smith 1886d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsBoolArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool value[], PetscInt *n, PetscBool *set) 1887d71ae5a4SJacob Faibussowitsch { 1888*10c654e6SJacob Faibussowitsch const char *prefix = PetscOptionsObject->prefix; 1889e2446a98SMatthew Knepley 1890e2446a98SMatthew Knepley PetscFunctionBegin; 1891*10c654e6SJacob Faibussowitsch PetscValidCharPointer(opt, 2); 1892*10c654e6SJacob Faibussowitsch PetscValidIntPointer(n, 6); 1893*10c654e6SJacob Faibussowitsch PetscCheck(*n >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "n (%" PetscInt_FMT ") cannot be negative", *n); 1894*10c654e6SJacob Faibussowitsch if (*n) PetscValidBoolPointer(value, 5); 1895*10c654e6SJacob Faibussowitsch if (set) PetscValidBoolPointer(set, 7); 1896e55864a3SBarry Smith if (!PetscOptionsObject->count) { 1897*10c654e6SJacob Faibussowitsch const PetscInt nv = *n; 1898ace3abfcSBarry Smith PetscBool *vals; 1899*10c654e6SJacob Faibussowitsch PetscOptionItem amsopt; 19001ae3d29cSBarry Smith 19019566063dSJacob Faibussowitsch PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL_ARRAY, &amsopt)); 1902*10c654e6SJacob Faibussowitsch PetscCall(PetscMalloc1(nv, &vals)); 1903*10c654e6SJacob Faibussowitsch for (PetscInt i = 0; i < nv; ++i) vals[i] = value[i]; 1904*10c654e6SJacob Faibussowitsch amsopt->arraylength = nv; 1905*10c654e6SJacob Faibussowitsch amsopt->data = vals; 19061ae3d29cSBarry Smith } 1907*10c654e6SJacob Faibussowitsch PetscCall(PetscOptionsGetBoolArray(PetscOptionsObject->options, prefix, opt, value, n, set)); 1908*10c654e6SJacob Faibussowitsch if (ShouldPrintHelp(PetscOptionsObject)) { 1909*10c654e6SJacob Faibussowitsch const PetscInt nv = *n; 1910*10c654e6SJacob Faibussowitsch const MPI_Comm comm = PetscOptionsObject->comm; 1911*10c654e6SJacob Faibussowitsch 1912*10c654e6SJacob Faibussowitsch PetscCall((*PetscHelpPrintf)(comm, " -%s%s: <%d", Prefix(prefix), opt + 1, value[0])); 1913*10c654e6SJacob Faibussowitsch for (PetscInt i = 1; i < nv; ++i) PetscCall((*PetscHelpPrintf)(comm, ",%d", value[i])); 1914*10c654e6SJacob Faibussowitsch PetscCall((*PetscHelpPrintf)(comm, ">: %s (%s)\n", text, ManSection(man))); 1915e2446a98SMatthew Knepley } 19163ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1917e2446a98SMatthew Knepley } 1918e2446a98SMatthew Knepley 191988aa4217SBarry Smith /*MC 1920d1da0b69SBarry Smith PetscOptionsViewer - Gets a viewer appropriate for the type indicated by the user 19218cc676e6SMatthew G Knepley 192288aa4217SBarry Smith Synopsis: 192388aa4217SBarry Smith #include "petscsys.h" 19243a89f35bSSatish Balay PetscErrorCode PetscOptionsViewer(const char opt[],const char text[],const char man[],PetscViewer *viewer,PetscViewerFormat *format,PetscBool *set) 192588aa4217SBarry Smith 19267cdbe19fSJose E. Roman Logically Collective on the communicator passed in `PetscOptionsBegin()` 19277cdbe19fSJose E. Roman 19288cc676e6SMatthew G Knepley Input Parameters: 19298cc676e6SMatthew G Knepley + opt - option name 19308cc676e6SMatthew G Knepley . text - short string that describes the option 19318cc676e6SMatthew G Knepley - man - manual page with additional information on option 19328cc676e6SMatthew G Knepley 1933d8d19677SJose E. Roman Output Parameters: 19348cc676e6SMatthew G Knepley + viewer - the viewer 19357962402dSFande Kong . format - the PetscViewerFormat requested by the user, pass NULL if not needed 1936811af0c4SBarry Smith - set - `PETSC_TRUE` if found, else `PETSC_FALSE` 19378cc676e6SMatthew G Knepley 19388cc676e6SMatthew G Knepley Level: beginner 19398cc676e6SMatthew G Knepley 194095452b02SPatrick Sanan Notes: 1941811af0c4SBarry Smith Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()` 19428cc676e6SMatthew G Knepley 1943811af0c4SBarry Smith See `PetscOptionsGetViewer()` for the format of the supplied viewer and its options 19448cc676e6SMatthew G Knepley 1945db781477SPatrick Sanan .seealso: `PetscOptionsGetViewer()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`, 1946db781477SPatrick Sanan `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()` 1947db781477SPatrick Sanan `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`, 1948db781477SPatrick Sanan `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`, 1949c2e3fba1SPatrick Sanan `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`, 1950db781477SPatrick Sanan `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`, 1951db781477SPatrick Sanan `PetscOptionsFList()`, `PetscOptionsEList()` 195288aa4217SBarry Smith M*/ 195388aa4217SBarry Smith 1954d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsViewer_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscViewer *viewer, PetscViewerFormat *format, PetscBool *set) 1955d71ae5a4SJacob Faibussowitsch { 1956*10c654e6SJacob Faibussowitsch const MPI_Comm comm = PetscOptionsObject->comm; 1957*10c654e6SJacob Faibussowitsch const char *prefix = PetscOptionsObject->prefix; 19588cc676e6SMatthew G Knepley 19598cc676e6SMatthew G Knepley PetscFunctionBegin; 1960*10c654e6SJacob Faibussowitsch PetscValidCharPointer(opt, 2); 1961*10c654e6SJacob Faibussowitsch PetscValidPointer(viewer, 5); 1962*10c654e6SJacob Faibussowitsch if (format) PetscValidPointer(format, 6); 1963*10c654e6SJacob Faibussowitsch if (set) PetscValidBoolPointer(set, 7); 19641a1499c8SBarry Smith if (!PetscOptionsObject->count) { 1965*10c654e6SJacob Faibussowitsch PetscOptionItem amsopt; 1966*10c654e6SJacob Faibussowitsch 19679566063dSJacob Faibussowitsch PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_STRING, &amsopt)); 196864facd6cSBarry Smith /* must use system malloc since SAWs may free this */ 19699566063dSJacob Faibussowitsch PetscCall(PetscStrdup("", (char **)&amsopt->data)); 19708cc676e6SMatthew G Knepley } 1971*10c654e6SJacob Faibussowitsch PetscCall(PetscOptionsGetViewer(comm, PetscOptionsObject->options, prefix, opt, viewer, format, set)); 1972*10c654e6SJacob Faibussowitsch if (ShouldPrintHelp(PetscOptionsObject)) PetscCall((*PetscHelpPrintf)(comm, " -%s%s: <%s>: %s (%s)\n", Prefix(prefix), opt + 1, "", text, ManSection(man))); 19733ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 19748cc676e6SMatthew G Knepley } 1975