xref: /petsc/src/sys/objects/aoptions.c (revision cf53795e253c8c9d9d0fbcef4cffd37d916c4e81)
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 
102aa6d131SJed Brown #define ManSection(str) ((str) ? (str) : "None")
112aa6d131SJed Brown 
1253acd3b1SBarry Smith /*
1353acd3b1SBarry Smith     Keep a linked list of options that have been posted and we are waiting for
143fc1eb6aSBarry Smith    user selection. See the manual page for PetscOptionsBegin()
1553acd3b1SBarry Smith 
1653acd3b1SBarry Smith     Eventually we'll attach this beast to a MPI_Comm
1753acd3b1SBarry Smith */
18e55864a3SBarry Smith 
1953acd3b1SBarry Smith /*
2053acd3b1SBarry Smith     Handles setting up the data structure in a call to PetscOptionsBegin()
2153acd3b1SBarry Smith */
22d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsBegin_Private(PetscOptionItems *PetscOptionsObject, MPI_Comm comm, const char prefix[], const char title[], const char mansec[])
23d71ae5a4SJacob Faibussowitsch {
2453acd3b1SBarry Smith   PetscFunctionBegin;
25064a246eSJacob Faibussowitsch   if (prefix) PetscValidCharPointer(prefix, 3);
26064a246eSJacob Faibussowitsch   PetscValidCharPointer(title, 4);
27064a246eSJacob Faibussowitsch   if (mansec) PetscValidCharPointer(mansec, 5);
280eb63584SBarry Smith   if (!PetscOptionsObject->alreadyprinted) {
299566063dSJacob Faibussowitsch     if (!PetscOptionsHelpPrintedSingleton) PetscCall(PetscOptionsHelpPrintedCreate(&PetscOptionsHelpPrintedSingleton));
309566063dSJacob Faibussowitsch     PetscCall(PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrintedSingleton, prefix, title, &PetscOptionsObject->alreadyprinted));
310eb63584SBarry Smith   }
3202c9f0b5SLisandro Dalcin   PetscOptionsObject->next          = NULL;
33e55864a3SBarry Smith   PetscOptionsObject->comm          = comm;
34e55864a3SBarry Smith   PetscOptionsObject->changedmethod = PETSC_FALSE;
35a297a907SKarl Rupp 
369566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(prefix, &PetscOptionsObject->prefix));
379566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(title, &PetscOptionsObject->title));
3853acd3b1SBarry Smith 
399566063dSJacob Faibussowitsch   PetscCall(PetscOptionsHasHelp(PetscOptionsObject->options, &PetscOptionsObject->printhelp));
40e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1) {
4148a46eb9SPierre Jolivet     if (!PetscOptionsObject->alreadyprinted) PetscCall((*PetscHelpPrintf)(comm, "----------------------------------------\n%s:\n", title));
4261b37b28SSatish Balay   }
4353acd3b1SBarry Smith   PetscFunctionReturn(0);
4453acd3b1SBarry Smith }
4553acd3b1SBarry Smith 
463194b578SJed Brown /*
473194b578SJed Brown     Handles setting up the data structure in a call to PetscObjectOptionsBegin()
483194b578SJed Brown */
49d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscObjectOptionsBegin_Private(PetscObject obj, PetscOptionItems *PetscOptionsObject)
50d71ae5a4SJacob Faibussowitsch {
513194b578SJed Brown   char      title[256];
523194b578SJed Brown   PetscBool flg;
533194b578SJed Brown 
543194b578SJed Brown   PetscFunctionBegin;
55dbbe0bcdSBarry Smith   PetscValidPointer(PetscOptionsObject, 2);
56dbbe0bcdSBarry Smith   PetscValidHeader(obj, 1);
57e55864a3SBarry Smith   PetscOptionsObject->object         = obj;
58e55864a3SBarry Smith   PetscOptionsObject->alreadyprinted = obj->optionsprinted;
59a297a907SKarl Rupp 
609566063dSJacob Faibussowitsch   PetscCall(PetscStrcmp(obj->description, obj->class_name, &flg));
619566063dSJacob Faibussowitsch   if (flg) PetscCall(PetscSNPrintf(title, sizeof(title), "%s options", obj->class_name));
629566063dSJacob Faibussowitsch   else PetscCall(PetscSNPrintf(title, sizeof(title), "%s (%s) options", obj->description, obj->class_name));
639566063dSJacob Faibussowitsch   PetscCall(PetscOptionsBegin_Private(PetscOptionsObject, obj->comm, obj->prefix, title, obj->mansec));
643194b578SJed Brown   PetscFunctionReturn(0);
653194b578SJed Brown }
663194b578SJed Brown 
6753acd3b1SBarry Smith /*
6853acd3b1SBarry Smith      Handles adding another option to the list of options within this particular PetscOptionsBegin() PetscOptionsEnd()
6953acd3b1SBarry Smith */
70d71ae5a4SJacob Faibussowitsch static int PetscOptionItemCreate_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscOptionType t, PetscOptionItem *amsopt)
71d71ae5a4SJacob Faibussowitsch {
724416b707SBarry Smith   PetscOptionItem next;
733be6e4c3SJed Brown   PetscBool       valid;
7453acd3b1SBarry Smith 
7553acd3b1SBarry Smith   PetscFunctionBegin;
769566063dSJacob Faibussowitsch   PetscCall(PetscOptionsValidKey(opt, &valid));
775f80ce2aSJacob Faibussowitsch   PetscCheck(valid, PETSC_COMM_WORLD, PETSC_ERR_ARG_INCOMP, "The option '%s' is not a valid key", opt);
783be6e4c3SJed Brown 
799566063dSJacob Faibussowitsch   PetscCall(PetscNew(amsopt));
8002c9f0b5SLisandro Dalcin   (*amsopt)->next = NULL;
8153acd3b1SBarry Smith   (*amsopt)->set  = PETSC_FALSE;
826356e834SBarry Smith   (*amsopt)->type = t;
8302c9f0b5SLisandro Dalcin   (*amsopt)->data = NULL;
8461b37b28SSatish Balay 
859566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(text, &(*amsopt)->text));
869566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(opt, &(*amsopt)->option));
879566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(man, &(*amsopt)->man));
8853acd3b1SBarry Smith 
89e55864a3SBarry Smith   if (!PetscOptionsObject->next) PetscOptionsObject->next = *amsopt;
90a297a907SKarl Rupp   else {
91e55864a3SBarry Smith     next = PetscOptionsObject->next;
9253acd3b1SBarry Smith     while (next->next) next = next->next;
9353acd3b1SBarry Smith     next->next = *amsopt;
9453acd3b1SBarry Smith   }
9553acd3b1SBarry Smith   PetscFunctionReturn(0);
9653acd3b1SBarry Smith }
9753acd3b1SBarry Smith 
98aee2cecaSBarry Smith /*
993fc1eb6aSBarry Smith     PetscScanString -  Gets user input via stdin from process and broadcasts to all processes
1003fc1eb6aSBarry Smith 
101d083f849SBarry Smith     Collective
1023fc1eb6aSBarry Smith 
1033fc1eb6aSBarry Smith    Input Parameters:
1043fc1eb6aSBarry Smith +     commm - communicator for the broadcast, must be PETSC_COMM_WORLD
1053fc1eb6aSBarry Smith .     n - length of the string, must be the same on all processes
1063fc1eb6aSBarry Smith -     str - location to store input
107aee2cecaSBarry Smith 
108aee2cecaSBarry Smith     Bugs:
109aee2cecaSBarry Smith .   Assumes process 0 of the given communicator has access to stdin
110aee2cecaSBarry Smith 
111aee2cecaSBarry Smith */
112d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscScanString(MPI_Comm comm, size_t n, char str[])
113d71ae5a4SJacob Faibussowitsch {
1143fc1eb6aSBarry Smith   PetscMPIInt rank, nm;
115aee2cecaSBarry Smith 
116aee2cecaSBarry Smith   PetscFunctionBegin;
1179566063dSJacob Faibussowitsch   PetscCallMPI(MPI_Comm_rank(comm, &rank));
118dd400576SPatrick Sanan   if (rank == 0) {
1195f80ce2aSJacob Faibussowitsch     char   c = (char)getchar();
1205f80ce2aSJacob Faibussowitsch     size_t i = 0;
1215f80ce2aSJacob Faibussowitsch 
122aee2cecaSBarry Smith     while (c != '\n' && i < n - 1) {
123aee2cecaSBarry Smith       str[i++] = c;
124aee2cecaSBarry Smith       c        = (char)getchar();
125aee2cecaSBarry Smith     }
126aee2cecaSBarry Smith     str[i] = 0;
127aee2cecaSBarry Smith   }
1289566063dSJacob Faibussowitsch   PetscCall(PetscMPIIntCast(n, &nm));
1299566063dSJacob Faibussowitsch   PetscCallMPI(MPI_Bcast(str, nm, MPI_CHAR, 0, comm));
130aee2cecaSBarry Smith   PetscFunctionReturn(0);
131aee2cecaSBarry Smith }
132aee2cecaSBarry Smith 
1335b02f95dSBarry Smith /*
1345b02f95dSBarry Smith     This is needed because certain strings may be freed by SAWs, hence we cannot use PetscStrallocpy()
1355b02f95dSBarry Smith */
136d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscStrdup(const char s[], char *t[])
137d71ae5a4SJacob Faibussowitsch {
13802c9f0b5SLisandro Dalcin   char *tmp = NULL;
1395b02f95dSBarry Smith 
1405b02f95dSBarry Smith   PetscFunctionBegin;
1415b02f95dSBarry Smith   if (s) {
1425f80ce2aSJacob Faibussowitsch     size_t len;
1435f80ce2aSJacob Faibussowitsch 
1449566063dSJacob Faibussowitsch     PetscCall(PetscStrlen(s, &len));
1455f80ce2aSJacob Faibussowitsch     tmp = (char *)malloc((len + 1) * sizeof(*tmp));
1465f80ce2aSJacob Faibussowitsch     PetscCheck(tmp, PETSC_COMM_SELF, PETSC_ERR_MEM, "No memory to duplicate string");
1479566063dSJacob Faibussowitsch     PetscCall(PetscStrcpy(tmp, s));
1485b02f95dSBarry Smith   }
1495b02f95dSBarry Smith   *t = tmp;
1505b02f95dSBarry Smith   PetscFunctionReturn(0);
1515b02f95dSBarry Smith }
1525b02f95dSBarry Smith 
153aee2cecaSBarry Smith /*
1543cc1e11dSBarry Smith     PetscOptionsGetFromTextInput - Presents all the PETSc Options processed by the program so the user may change them at runtime
155aee2cecaSBarry Smith 
15695452b02SPatrick Sanan     Notes:
15795452b02SPatrick Sanan     this isn't really practical, it is just to demonstrate the principle
158aee2cecaSBarry Smith 
1597781c08eSBarry Smith     A carriage return indicates no change from the default; but this like -ksp_monitor <stdout>  the default is actually not stdout the default
1607781c08eSBarry Smith     is to do nothing so to get it to use stdout you need to type stdout. This is kind of bug?
1617781c08eSBarry Smith 
162aee2cecaSBarry Smith     Bugs:
1637781c08eSBarry Smith +    All processes must traverse through the exact same set of option queries due to the call to PetscScanString()
1643cc1e11dSBarry Smith .    Internal strings have arbitrary length and string copies are not checked that they fit into string space
165aee2cecaSBarry Smith -    Only works for PetscInt == int, PetscReal == double etc
166aee2cecaSBarry Smith 
167811af0c4SBarry Smith     Developer Note:
16895452b02SPatrick Sanan     Normally the GUI that presents the options the user and retrieves the values would be running in a different
1693cc1e11dSBarry Smith      address space and communicating with the PETSc program
1703cc1e11dSBarry Smith 
171aee2cecaSBarry Smith */
172d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsGetFromTextInput(PetscOptionItems *PetscOptionsObject)
173d71ae5a4SJacob Faibussowitsch {
1744416b707SBarry Smith   PetscOptionItem next = PetscOptionsObject->next;
1756356e834SBarry Smith   char            str[512];
1767781c08eSBarry Smith   PetscBool       bid;
177a4404d99SBarry Smith   PetscReal       ir, *valr;
178330cf3c9SBarry Smith   PetscInt       *vald;
179330cf3c9SBarry Smith   size_t          i;
1806356e834SBarry Smith 
1812a409bb0SBarry Smith   PetscFunctionBegin;
1829566063dSJacob Faibussowitsch   PetscCall((*PetscPrintf)(PETSC_COMM_WORLD, "%s --------------------\n", PetscOptionsObject->title));
1836356e834SBarry Smith   while (next) {
1846356e834SBarry Smith     switch (next->type) {
185d71ae5a4SJacob Faibussowitsch     case OPTION_HEAD:
186d71ae5a4SJacob Faibussowitsch       break;
187e26ddf31SBarry Smith     case OPTION_INT_ARRAY:
1889566063dSJacob Faibussowitsch       PetscCall(PetscPrintf(PETSC_COMM_WORLD, "-%s%s <", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1));
189e26ddf31SBarry Smith       vald = (PetscInt *)next->data;
190e26ddf31SBarry Smith       for (i = 0; i < next->arraylength; i++) {
1919566063dSJacob Faibussowitsch         PetscCall(PetscPrintf(PETSC_COMM_WORLD, "%" PetscInt_FMT, vald[i]));
19248a46eb9SPierre Jolivet         if (i < next->arraylength - 1) PetscCall(PetscPrintf(PETSC_COMM_WORLD, ","));
193e26ddf31SBarry Smith       }
1949566063dSJacob Faibussowitsch       PetscCall(PetscPrintf(PETSC_COMM_WORLD, ">: %s (%s) ", next->text, next->man));
1959566063dSJacob Faibussowitsch       PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str));
196e26ddf31SBarry Smith       if (str[0]) {
197e26ddf31SBarry Smith         PetscToken token;
198e26ddf31SBarry Smith         PetscInt   n = 0, nmax = next->arraylength, *dvalue = (PetscInt *)next->data, start, end;
199e26ddf31SBarry Smith         size_t     len;
200e26ddf31SBarry Smith         char      *value;
201ace3abfcSBarry Smith         PetscBool  foundrange;
202e26ddf31SBarry Smith 
203e26ddf31SBarry Smith         next->set = PETSC_TRUE;
204e26ddf31SBarry Smith         value     = str;
2059566063dSJacob Faibussowitsch         PetscCall(PetscTokenCreate(value, ',', &token));
2069566063dSJacob Faibussowitsch         PetscCall(PetscTokenFind(token, &value));
207e26ddf31SBarry Smith         while (n < nmax) {
208e26ddf31SBarry Smith           if (!value) break;
209e26ddf31SBarry Smith 
210e26ddf31SBarry Smith           /* look for form  d-D where d and D are integers */
211e26ddf31SBarry Smith           foundrange = PETSC_FALSE;
2129566063dSJacob Faibussowitsch           PetscCall(PetscStrlen(value, &len));
213e26ddf31SBarry Smith           if (value[0] == '-') i = 2;
214e26ddf31SBarry Smith           else i = 1;
215330cf3c9SBarry Smith           for (; i < len; i++) {
216e26ddf31SBarry Smith             if (value[i] == '-') {
21708401ef6SPierre Jolivet               PetscCheck(i != len - 1, PETSC_COMM_SELF, PETSC_ERR_USER, "Error in %" PetscInt_FMT "-th array entry %s", n, value);
218e26ddf31SBarry Smith               value[i] = 0;
2199566063dSJacob Faibussowitsch               PetscCall(PetscOptionsStringToInt(value, &start));
2209566063dSJacob Faibussowitsch               PetscCall(PetscOptionsStringToInt(value + i + 1, &end));
22108401ef6SPierre 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);
222cc73adaaSBarry 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);
223e26ddf31SBarry Smith               for (; start < end; start++) {
2249371c9d4SSatish Balay                 *dvalue = start;
2259371c9d4SSatish Balay                 dvalue++;
2269371c9d4SSatish Balay                 n++;
227e26ddf31SBarry Smith               }
228e26ddf31SBarry Smith               foundrange = PETSC_TRUE;
229e26ddf31SBarry Smith               break;
230e26ddf31SBarry Smith             }
231e26ddf31SBarry Smith           }
232e26ddf31SBarry Smith           if (!foundrange) {
2339566063dSJacob Faibussowitsch             PetscCall(PetscOptionsStringToInt(value, dvalue));
234e26ddf31SBarry Smith             dvalue++;
235e26ddf31SBarry Smith             n++;
236e26ddf31SBarry Smith           }
2379566063dSJacob Faibussowitsch           PetscCall(PetscTokenFind(token, &value));
238e26ddf31SBarry Smith         }
2399566063dSJacob Faibussowitsch         PetscCall(PetscTokenDestroy(&token));
240e26ddf31SBarry Smith       }
241e26ddf31SBarry Smith       break;
242e26ddf31SBarry Smith     case OPTION_REAL_ARRAY:
2439566063dSJacob Faibussowitsch       PetscCall(PetscPrintf(PETSC_COMM_WORLD, "-%s%s <", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1));
244e26ddf31SBarry Smith       valr = (PetscReal *)next->data;
245e26ddf31SBarry Smith       for (i = 0; i < next->arraylength; i++) {
2469566063dSJacob Faibussowitsch         PetscCall(PetscPrintf(PETSC_COMM_WORLD, "%g", (double)valr[i]));
24748a46eb9SPierre Jolivet         if (i < next->arraylength - 1) PetscCall(PetscPrintf(PETSC_COMM_WORLD, ","));
248e26ddf31SBarry Smith       }
2499566063dSJacob Faibussowitsch       PetscCall(PetscPrintf(PETSC_COMM_WORLD, ">: %s (%s) ", next->text, next->man));
2509566063dSJacob Faibussowitsch       PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str));
251e26ddf31SBarry Smith       if (str[0]) {
252e26ddf31SBarry Smith         PetscToken token;
253e26ddf31SBarry Smith         PetscInt   n = 0, nmax = next->arraylength;
254e26ddf31SBarry Smith         PetscReal *dvalue = (PetscReal *)next->data;
255e26ddf31SBarry Smith         char      *value;
256e26ddf31SBarry Smith 
257e26ddf31SBarry Smith         next->set = PETSC_TRUE;
258e26ddf31SBarry Smith         value     = str;
2599566063dSJacob Faibussowitsch         PetscCall(PetscTokenCreate(value, ',', &token));
2609566063dSJacob Faibussowitsch         PetscCall(PetscTokenFind(token, &value));
261e26ddf31SBarry Smith         while (n < nmax) {
262e26ddf31SBarry Smith           if (!value) break;
2639566063dSJacob Faibussowitsch           PetscCall(PetscOptionsStringToReal(value, dvalue));
264e26ddf31SBarry Smith           dvalue++;
265e26ddf31SBarry Smith           n++;
2669566063dSJacob Faibussowitsch           PetscCall(PetscTokenFind(token, &value));
267e26ddf31SBarry Smith         }
2689566063dSJacob Faibussowitsch         PetscCall(PetscTokenDestroy(&token));
269e26ddf31SBarry Smith       }
270e26ddf31SBarry Smith       break;
2716356e834SBarry Smith     case OPTION_INT:
2729566063dSJacob Faibussowitsch       PetscCall(PetscPrintf(PETSC_COMM_WORLD, "-%s%s <%d>: %s (%s) ", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1, *(int *)next->data, next->text, next->man));
2739566063dSJacob Faibussowitsch       PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str));
2743fc1eb6aSBarry Smith       if (str[0]) {
275d25d7f95SJed Brown #if defined(PETSC_SIZEOF_LONG_LONG)
276d25d7f95SJed Brown         long long lid;
277d25d7f95SJed Brown         sscanf(str, "%lld", &lid);
278cc73adaaSBarry 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);
279c272547aSJed Brown #else
280d25d7f95SJed Brown         long lid;
281d25d7f95SJed Brown         sscanf(str, "%ld", &lid);
282cc73adaaSBarry 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);
283c272547aSJed Brown #endif
284a297a907SKarl Rupp 
285d25d7f95SJed Brown         next->set                 = PETSC_TRUE;
286d25d7f95SJed Brown         *((PetscInt *)next->data) = (PetscInt)lid;
287aee2cecaSBarry Smith       }
288aee2cecaSBarry Smith       break;
289aee2cecaSBarry Smith     case OPTION_REAL:
2909566063dSJacob Faibussowitsch       PetscCall(PetscPrintf(PETSC_COMM_WORLD, "-%s%s <%g>: %s (%s) ", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1, *(double *)next->data, next->text, next->man));
2919566063dSJacob Faibussowitsch       PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str));
2923fc1eb6aSBarry Smith       if (str[0]) {
293ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE)
294a4404d99SBarry Smith         sscanf(str, "%e", &ir);
295570b7f6dSBarry Smith #elif defined(PETSC_USE_REAL___FP16)
296570b7f6dSBarry Smith         float irtemp;
297570b7f6dSBarry Smith         sscanf(str, "%e", &irtemp);
298570b7f6dSBarry Smith         ir = irtemp;
299ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE)
300aee2cecaSBarry Smith         sscanf(str, "%le", &ir);
301ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL___FLOAT128)
302d9822059SBarry Smith         ir = strtoflt128(str, 0);
303d9822059SBarry Smith #else
304513dbe71SLisandro Dalcin         SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, "Unknown scalar type");
305a4404d99SBarry Smith #endif
306aee2cecaSBarry Smith         next->set                  = PETSC_TRUE;
307aee2cecaSBarry Smith         *((PetscReal *)next->data) = ir;
308aee2cecaSBarry Smith       }
309aee2cecaSBarry Smith       break;
3107781c08eSBarry Smith     case OPTION_BOOL:
3119566063dSJacob Faibussowitsch       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));
3129566063dSJacob Faibussowitsch       PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str));
3137781c08eSBarry Smith       if (str[0]) {
3149566063dSJacob Faibussowitsch         PetscCall(PetscOptionsStringToBool(str, &bid));
3157781c08eSBarry Smith         next->set                  = PETSC_TRUE;
3167781c08eSBarry Smith         *((PetscBool *)next->data) = bid;
3177781c08eSBarry Smith       }
3187781c08eSBarry Smith       break;
319aee2cecaSBarry Smith     case OPTION_STRING:
3209566063dSJacob Faibussowitsch       PetscCall(PetscPrintf(PETSC_COMM_WORLD, "-%s%s <%s>: %s (%s) ", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1, (char *)next->data, next->text, next->man));
3219566063dSJacob Faibussowitsch       PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str));
3223fc1eb6aSBarry Smith       if (str[0]) {
323aee2cecaSBarry Smith         next->set = PETSC_TRUE;
32464facd6cSBarry Smith         /* must use system malloc since SAWs may free this */
3259566063dSJacob Faibussowitsch         PetscCall(PetscStrdup(str, (char **)&next->data));
3266356e834SBarry Smith       }
3276356e834SBarry Smith       break;
328a264d7a6SBarry Smith     case OPTION_FLIST:
3299566063dSJacob Faibussowitsch       PetscCall(PetscFunctionListPrintTypes(PETSC_COMM_WORLD, stdout, PetscOptionsObject->prefix, next->option, next->text, next->man, next->flist, (char *)next->data, (char *)next->data));
3309566063dSJacob Faibussowitsch       PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str));
3313cc1e11dSBarry Smith       if (str[0]) {
332e55864a3SBarry Smith         PetscOptionsObject->changedmethod = PETSC_TRUE;
3333cc1e11dSBarry Smith         next->set                         = PETSC_TRUE;
33464facd6cSBarry Smith         /* must use system malloc since SAWs may free this */
3359566063dSJacob Faibussowitsch         PetscCall(PetscStrdup(str, (char **)&next->data));
3363cc1e11dSBarry Smith       }
3373cc1e11dSBarry Smith       break;
338d71ae5a4SJacob Faibussowitsch     default:
339d71ae5a4SJacob Faibussowitsch       break;
3406356e834SBarry Smith     }
3416356e834SBarry Smith     next = next->next;
3426356e834SBarry Smith   }
3436356e834SBarry Smith   PetscFunctionReturn(0);
3446356e834SBarry Smith }
3456356e834SBarry Smith 
346e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS)
347e04113cfSBarry Smith   #include <petscviewersaws.h>
348d5649816SBarry Smith 
349d5649816SBarry Smith static int count = 0;
350d5649816SBarry Smith 
351d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsSAWsDestroy(void)
352d71ae5a4SJacob Faibussowitsch {
3532657e9d9SBarry Smith   PetscFunctionBegin;
354d5649816SBarry Smith   PetscFunctionReturn(0);
355d5649816SBarry Smith }
356d5649816SBarry Smith 
3579c1e0ce8SBarry Smith static const char *OptionsHeader = "<head>\n"
358a8d69d7bSBarry Smith                                    "<script type=\"text/javascript\" src=\"https://www.mcs.anl.gov/research/projects/saws/js/jquery-1.9.1.js\"></script>\n"
359a8d69d7bSBarry Smith                                    "<script type=\"text/javascript\" src=\"https://www.mcs.anl.gov/research/projects/saws/js/SAWs.js\"></script>\n"
360d1fc0251SBarry Smith                                    "<script type=\"text/javascript\" src=\"js/PETSc.js\"></script>\n"
36164bbc9efSBarry Smith                                    "<script>\n"
36264bbc9efSBarry Smith                                    "jQuery(document).ready(function() {\n"
36364bbc9efSBarry Smith                                    "PETSc.getAndDisplayDirectory(null,\"#variablesInfo\")\n"
36464bbc9efSBarry Smith                                    "})\n"
36564bbc9efSBarry Smith                                    "</script>\n"
36664bbc9efSBarry Smith                                    "</head>\n";
3671423471aSBarry Smith 
3681423471aSBarry Smith /*  Determines the size and style of the scroll region where PETSc options selectable from users are displayed */
3691423471aSBarry Smith static const char *OptionsBodyBottom = "<div id=\"variablesInfo\" style=\"background-color:lightblue;height:auto;max-height:500px;overflow:scroll;\"></div>\n<br>\n</body>";
37064bbc9efSBarry Smith 
371b3506946SBarry Smith /*
3727781c08eSBarry Smith     PetscOptionsSAWsInput - Presents all the PETSc Options processed by the program so the user may change them at runtime using the SAWs
373b3506946SBarry Smith 
374b3506946SBarry Smith     Bugs:
375b3506946SBarry Smith +    All processes must traverse through the exact same set of option queries do to the call to PetscScanString()
376b3506946SBarry Smith .    Internal strings have arbitrary length and string copies are not checked that they fit into string space
377b3506946SBarry Smith -    Only works for PetscInt == int, PetscReal == double etc
378b3506946SBarry Smith 
379b3506946SBarry Smith */
380d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsSAWsInput(PetscOptionItems *PetscOptionsObject)
381d71ae5a4SJacob Faibussowitsch {
3824416b707SBarry Smith   PetscOptionItem next     = PetscOptionsObject->next;
383d5649816SBarry Smith   static int      mancount = 0;
384b3506946SBarry Smith   char            options[16];
3857aab2a10SBarry Smith   PetscBool       changedmethod = PETSC_FALSE;
386a23eb982SSurtai Han   PetscBool       stopasking    = PETSC_FALSE;
38788a9752cSBarry Smith   char            manname[16], textname[16];
3882657e9d9SBarry Smith   char            dir[1024];
389b3506946SBarry Smith 
3902a409bb0SBarry Smith   PetscFunctionBegin;
391b3506946SBarry Smith   /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */
392b3506946SBarry Smith   sprintf(options, "Options_%d", count++);
393a297a907SKarl Rupp 
3947325c4a4SBarry Smith   PetscOptionsObject->pprefix = PetscOptionsObject->prefix; /* SAWs will change this, so cannot pass prefix directly */
3951bc75a8dSBarry Smith 
3969566063dSJacob Faibussowitsch   PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", "_title"));
397792fecdfSBarry Smith   PetscCallSAWs(SAWs_Register, (dir, &PetscOptionsObject->title, 1, SAWs_READ, SAWs_STRING));
3989566063dSJacob Faibussowitsch   PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", "prefix"));
399792fecdfSBarry Smith   PetscCallSAWs(SAWs_Register, (dir, &PetscOptionsObject->pprefix, 1, SAWs_READ, SAWs_STRING));
400792fecdfSBarry Smith   PetscCallSAWs(SAWs_Register, ("/PETSc/Options/ChangedMethod", &changedmethod, 1, SAWs_WRITE, SAWs_BOOLEAN));
401792fecdfSBarry Smith   PetscCallSAWs(SAWs_Register, ("/PETSc/Options/StopAsking", &stopasking, 1, SAWs_WRITE, SAWs_BOOLEAN));
402b3506946SBarry Smith 
403b3506946SBarry Smith   while (next) {
404d50831c4SBarry Smith     sprintf(manname, "_man_%d", mancount);
4059566063dSJacob Faibussowitsch     PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", manname));
406792fecdfSBarry Smith     PetscCallSAWs(SAWs_Register, (dir, &next->man, 1, SAWs_READ, SAWs_STRING));
407d50831c4SBarry Smith     sprintf(textname, "_text_%d", mancount++);
4089566063dSJacob Faibussowitsch     PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", textname));
409792fecdfSBarry Smith     PetscCallSAWs(SAWs_Register, (dir, &next->text, 1, SAWs_READ, SAWs_STRING));
4109f32e415SBarry Smith 
411b3506946SBarry Smith     switch (next->type) {
412d71ae5a4SJacob Faibussowitsch     case OPTION_HEAD:
413d71ae5a4SJacob Faibussowitsch       break;
414b3506946SBarry Smith     case OPTION_INT_ARRAY:
4159566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
416792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, next->data, next->arraylength, SAWs_WRITE, SAWs_INT));
417b3506946SBarry Smith       break;
418b3506946SBarry Smith     case OPTION_REAL_ARRAY:
4199566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
420792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, next->data, next->arraylength, SAWs_WRITE, SAWs_DOUBLE));
421b3506946SBarry Smith       break;
422b3506946SBarry Smith     case OPTION_INT:
4239566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
424792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, next->data, 1, SAWs_WRITE, SAWs_INT));
425b3506946SBarry Smith       break;
426b3506946SBarry Smith     case OPTION_REAL:
4279566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
428792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, next->data, 1, SAWs_WRITE, SAWs_DOUBLE));
429b3506946SBarry Smith       break;
4307781c08eSBarry Smith     case OPTION_BOOL:
4319566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
432792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, next->data, 1, SAWs_WRITE, SAWs_BOOLEAN));
4331ae3d29cSBarry Smith       break;
4347781c08eSBarry Smith     case OPTION_BOOL_ARRAY:
4359566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
436792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, next->data, next->arraylength, SAWs_WRITE, SAWs_BOOLEAN));
43771f08665SBarry Smith       break;
438b3506946SBarry Smith     case OPTION_STRING:
4399566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
440792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, &next->data, 1, SAWs_WRITE, SAWs_STRING));
4411ae3d29cSBarry Smith       break;
4421ae3d29cSBarry Smith     case OPTION_STRING_ARRAY:
4439566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
444792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, next->data, next->arraylength, SAWs_WRITE, SAWs_STRING));
445b3506946SBarry Smith       break;
4469371c9d4SSatish Balay     case OPTION_FLIST: {
447a264d7a6SBarry Smith       PetscInt ntext;
4489566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
449792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, &next->data, 1, SAWs_WRITE, SAWs_STRING));
4509566063dSJacob Faibussowitsch       PetscCall(PetscFunctionListGet(next->flist, (const char ***)&next->edata, &ntext));
451792fecdfSBarry Smith       PetscCallSAWs(SAWs_Set_Legal_Variable_Values, (dir, ntext, next->edata));
4529371c9d4SSatish Balay     } break;
4539371c9d4SSatish Balay     case OPTION_ELIST: {
454a264d7a6SBarry Smith       PetscInt ntext = next->nlist;
4559566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
456792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, &next->data, 1, SAWs_WRITE, SAWs_STRING));
4579566063dSJacob Faibussowitsch       PetscCall(PetscMalloc1((ntext + 1), (char ***)&next->edata));
4589566063dSJacob Faibussowitsch       PetscCall(PetscMemcpy(next->edata, next->list, ntext * sizeof(char *)));
459792fecdfSBarry Smith       PetscCallSAWs(SAWs_Set_Legal_Variable_Values, (dir, ntext, next->edata));
4609371c9d4SSatish Balay     } break;
461d71ae5a4SJacob Faibussowitsch     default:
462d71ae5a4SJacob Faibussowitsch       break;
463b3506946SBarry Smith     }
464b3506946SBarry Smith     next = next->next;
465b3506946SBarry Smith   }
466b3506946SBarry Smith 
467b3506946SBarry Smith   /* wait until accessor has unlocked the memory */
468792fecdfSBarry Smith   PetscCallSAWs(SAWs_Push_Header, ("index.html", OptionsHeader));
469792fecdfSBarry Smith   PetscCallSAWs(SAWs_Push_Body, ("index.html", 2, OptionsBodyBottom));
4709566063dSJacob Faibussowitsch   PetscCall(PetscSAWsBlock());
471792fecdfSBarry Smith   PetscCallSAWs(SAWs_Pop_Header, ("index.html"));
472792fecdfSBarry Smith   PetscCallSAWs(SAWs_Pop_Body, ("index.html", 2));
473b3506946SBarry Smith 
47488a9752cSBarry Smith   /* determine if any values have been set in GUI */
47583355fc5SBarry Smith   next = PetscOptionsObject->next;
47688a9752cSBarry Smith   while (next) {
4779566063dSJacob Faibussowitsch     PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
478792fecdfSBarry Smith     PetscCallSAWs(SAWs_Selected, (dir, (int *)&next->set));
47988a9752cSBarry Smith     next = next->next;
48088a9752cSBarry Smith   }
48188a9752cSBarry Smith 
482b3506946SBarry Smith   /* reset counter to -2; this updates the screen with the new options for the selected method */
483f7b25cf6SBarry Smith   if (changedmethod) PetscOptionsObject->count = -2;
484b3506946SBarry Smith 
485a23eb982SSurtai Han   if (stopasking) {
486a23eb982SSurtai Han     PetscOptionsPublish       = PETSC_FALSE;
48712655325SBarry Smith     PetscOptionsObject->count = 0; //do not ask for same thing again
488a23eb982SSurtai Han   }
489a23eb982SSurtai Han 
490792fecdfSBarry Smith   PetscCallSAWs(SAWs_Delete, ("/PETSc/Options"));
491b3506946SBarry Smith   PetscFunctionReturn(0);
492b3506946SBarry Smith }
493b3506946SBarry Smith #endif
494b3506946SBarry Smith 
495d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsEnd_Private(PetscOptionItems *PetscOptionsObject)
496d71ae5a4SJacob Faibussowitsch {
4974416b707SBarry Smith   PetscOptionItem last;
4986356e834SBarry Smith   char            option[256], value[1024], tmp[32];
499330cf3c9SBarry Smith   size_t          j;
50053acd3b1SBarry Smith 
50153acd3b1SBarry Smith   PetscFunctionBegin;
50283355fc5SBarry Smith   if (PetscOptionsObject->next) {
50383355fc5SBarry Smith     if (!PetscOptionsObject->count) {
504a264d7a6SBarry Smith #if defined(PETSC_HAVE_SAWS)
5059566063dSJacob Faibussowitsch       PetscCall(PetscOptionsSAWsInput(PetscOptionsObject));
506b3506946SBarry Smith #else
5079566063dSJacob Faibussowitsch       PetscCall(PetscOptionsGetFromTextInput(PetscOptionsObject));
508b3506946SBarry Smith #endif
509aee2cecaSBarry Smith     }
510aee2cecaSBarry Smith   }
5116356e834SBarry Smith 
5129566063dSJacob Faibussowitsch   PetscCall(PetscFree(PetscOptionsObject->title));
5136356e834SBarry Smith 
514e26ddf31SBarry Smith   /* reset counter to -2; this updates the screen with the new options for the selected method */
515e55864a3SBarry Smith   if (PetscOptionsObject->changedmethod) PetscOptionsObject->count = -2;
5167a72a596SBarry Smith   /* reset alreadyprinted flag */
517e55864a3SBarry Smith   PetscOptionsObject->alreadyprinted = PETSC_FALSE;
518e55864a3SBarry Smith   if (PetscOptionsObject->object) PetscOptionsObject->object->optionsprinted = PETSC_TRUE;
519e55864a3SBarry Smith   PetscOptionsObject->object = NULL;
52053acd3b1SBarry Smith 
521e55864a3SBarry Smith   while (PetscOptionsObject->next) {
522e55864a3SBarry Smith     if (PetscOptionsObject->next->set) {
523e55864a3SBarry Smith       if (PetscOptionsObject->prefix) {
5249566063dSJacob Faibussowitsch         PetscCall(PetscStrcpy(option, "-"));
5259566063dSJacob Faibussowitsch         PetscCall(PetscStrcat(option, PetscOptionsObject->prefix));
5269566063dSJacob Faibussowitsch         PetscCall(PetscStrcat(option, PetscOptionsObject->next->option + 1));
5279566063dSJacob Faibussowitsch       } else PetscCall(PetscStrcpy(option, PetscOptionsObject->next->option));
5286356e834SBarry Smith 
529e55864a3SBarry Smith       switch (PetscOptionsObject->next->type) {
530d71ae5a4SJacob Faibussowitsch       case OPTION_HEAD:
531d71ae5a4SJacob Faibussowitsch         break;
5326356e834SBarry Smith       case OPTION_INT_ARRAY:
533e55864a3SBarry Smith         sprintf(value, "%d", (int)((PetscInt *)PetscOptionsObject->next->data)[0]);
534e55864a3SBarry Smith         for (j = 1; j < PetscOptionsObject->next->arraylength; j++) {
535e55864a3SBarry Smith           sprintf(tmp, "%d", (int)((PetscInt *)PetscOptionsObject->next->data)[j]);
5369566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, ","));
5379566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, tmp));
5386356e834SBarry Smith         }
5396356e834SBarry Smith         break;
540d71ae5a4SJacob Faibussowitsch       case OPTION_INT:
541d71ae5a4SJacob Faibussowitsch         sprintf(value, "%d", (int)*(PetscInt *)PetscOptionsObject->next->data);
542d71ae5a4SJacob Faibussowitsch         break;
543d71ae5a4SJacob Faibussowitsch       case OPTION_REAL:
544d71ae5a4SJacob Faibussowitsch         sprintf(value, "%g", (double)*(PetscReal *)PetscOptionsObject->next->data);
545d71ae5a4SJacob Faibussowitsch         break;
5466356e834SBarry Smith       case OPTION_REAL_ARRAY:
547e55864a3SBarry Smith         sprintf(value, "%g", (double)((PetscReal *)PetscOptionsObject->next->data)[0]);
548e55864a3SBarry Smith         for (j = 1; j < PetscOptionsObject->next->arraylength; j++) {
549e55864a3SBarry Smith           sprintf(tmp, "%g", (double)((PetscReal *)PetscOptionsObject->next->data)[j]);
5509566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, ","));
5519566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, tmp));
5526356e834SBarry Smith         }
5536356e834SBarry Smith         break;
554050cccc3SHong Zhang       case OPTION_SCALAR_ARRAY:
55595f3a755SJose E. Roman         sprintf(value, "%g+%gi", (double)PetscRealPart(((PetscScalar *)PetscOptionsObject->next->data)[0]), (double)PetscImaginaryPart(((PetscScalar *)PetscOptionsObject->next->data)[0]));
556050cccc3SHong Zhang         for (j = 1; j < PetscOptionsObject->next->arraylength; j++) {
55795f3a755SJose E. Roman           sprintf(tmp, "%g+%gi", (double)PetscRealPart(((PetscScalar *)PetscOptionsObject->next->data)[j]), (double)PetscImaginaryPart(((PetscScalar *)PetscOptionsObject->next->data)[j]));
5589566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, ","));
5599566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, tmp));
560050cccc3SHong Zhang         }
561050cccc3SHong Zhang         break;
562d71ae5a4SJacob Faibussowitsch       case OPTION_BOOL:
563d71ae5a4SJacob Faibussowitsch         sprintf(value, "%d", *(int *)PetscOptionsObject->next->data);
564d71ae5a4SJacob Faibussowitsch         break;
5657781c08eSBarry Smith       case OPTION_BOOL_ARRAY:
566e55864a3SBarry Smith         sprintf(value, "%d", (int)((PetscBool *)PetscOptionsObject->next->data)[0]);
567e55864a3SBarry Smith         for (j = 1; j < PetscOptionsObject->next->arraylength; j++) {
568e55864a3SBarry Smith           sprintf(tmp, "%d", (int)((PetscBool *)PetscOptionsObject->next->data)[j]);
5699566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, ","));
5709566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, tmp));
5711ae3d29cSBarry Smith         }
5721ae3d29cSBarry Smith         break;
573d71ae5a4SJacob Faibussowitsch       case OPTION_FLIST:
574d71ae5a4SJacob Faibussowitsch         PetscCall(PetscStrcpy(value, (char *)PetscOptionsObject->next->data));
575d71ae5a4SJacob Faibussowitsch         break;
576d71ae5a4SJacob Faibussowitsch       case OPTION_ELIST:
577d71ae5a4SJacob Faibussowitsch         PetscCall(PetscStrcpy(value, (char *)PetscOptionsObject->next->data));
578d71ae5a4SJacob Faibussowitsch         break;
579d71ae5a4SJacob Faibussowitsch       case OPTION_STRING:
580d71ae5a4SJacob Faibussowitsch         PetscCall(PetscStrcpy(value, (char *)PetscOptionsObject->next->data));
581d71ae5a4SJacob Faibussowitsch         break;
5821ae3d29cSBarry Smith       case OPTION_STRING_ARRAY:
583e55864a3SBarry Smith         sprintf(value, "%s", ((char **)PetscOptionsObject->next->data)[0]);
584e55864a3SBarry Smith         for (j = 1; j < PetscOptionsObject->next->arraylength; j++) {
585e55864a3SBarry Smith           sprintf(tmp, "%s", ((char **)PetscOptionsObject->next->data)[j]);
5869566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, ","));
5879566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, tmp));
5881ae3d29cSBarry Smith         }
5896356e834SBarry Smith         break;
5906356e834SBarry Smith       }
5919566063dSJacob Faibussowitsch       PetscCall(PetscOptionsSetValue(PetscOptionsObject->options, option, value));
5926356e834SBarry Smith     }
59348a46eb9SPierre Jolivet     if (PetscOptionsObject->next->type == OPTION_ELIST) PetscCall(PetscStrNArrayDestroy(PetscOptionsObject->next->nlist, (char ***)&PetscOptionsObject->next->list));
5949566063dSJacob Faibussowitsch     PetscCall(PetscFree(PetscOptionsObject->next->text));
5959566063dSJacob Faibussowitsch     PetscCall(PetscFree(PetscOptionsObject->next->option));
5969566063dSJacob Faibussowitsch     PetscCall(PetscFree(PetscOptionsObject->next->man));
5979566063dSJacob Faibussowitsch     PetscCall(PetscFree(PetscOptionsObject->next->edata));
598c979a496SBarry Smith 
59983355fc5SBarry Smith     if ((PetscOptionsObject->next->type == OPTION_STRING) || (PetscOptionsObject->next->type == OPTION_FLIST) || (PetscOptionsObject->next->type == OPTION_ELIST)) {
60083355fc5SBarry Smith       free(PetscOptionsObject->next->data);
601c979a496SBarry Smith     } else {
6029566063dSJacob Faibussowitsch       PetscCall(PetscFree(PetscOptionsObject->next->data));
603c979a496SBarry Smith     }
6047781c08eSBarry Smith 
60583355fc5SBarry Smith     last                     = PetscOptionsObject->next;
60683355fc5SBarry Smith     PetscOptionsObject->next = PetscOptionsObject->next->next;
6079566063dSJacob Faibussowitsch     PetscCall(PetscFree(last));
6086356e834SBarry Smith   }
6099566063dSJacob Faibussowitsch   PetscCall(PetscFree(PetscOptionsObject->prefix));
61002c9f0b5SLisandro Dalcin   PetscOptionsObject->next = NULL;
61153acd3b1SBarry Smith   PetscFunctionReturn(0);
61253acd3b1SBarry Smith }
61353acd3b1SBarry Smith 
61488aa4217SBarry Smith /*MC
61553acd3b1SBarry Smith    PetscOptionsEnum - Gets the enum value for a particular option in the database.
61653acd3b1SBarry Smith 
617811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
61853acd3b1SBarry Smith 
61988aa4217SBarry Smith    Synopsis:
62088aa4217SBarry Smith    #include "petscsys.h"
6213a89f35bSSatish Balay    PetscErrorCode  PetscOptionsEnum(const char opt[],const char text[],const char man[],const char *const *list,PetscEnum currentvalue,PetscEnum *value,PetscBool  *set)
62288aa4217SBarry Smith 
62353acd3b1SBarry Smith    Input Parameters:
62453acd3b1SBarry Smith +  opt - option name
62553acd3b1SBarry Smith .  text - short string that describes the option
62653acd3b1SBarry Smith .  man - manual page with additional information on option
62753acd3b1SBarry Smith .  list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null
6280fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
6290fdccdaeSBarry Smith $                 PetscOptionsEnum(..., obj->value,&object->value,...) or
6300fdccdaeSBarry Smith $                 value = defaultvalue
6310fdccdaeSBarry Smith $                 PetscOptionsEnum(..., value,&value,&flg);
6320fdccdaeSBarry Smith $                 if (flg) {
63353acd3b1SBarry Smith 
634d8d19677SJose E. Roman    Output Parameters:
63553acd3b1SBarry Smith +  value - the  value to return
636811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
63753acd3b1SBarry Smith 
63853acd3b1SBarry Smith    Level: beginner
63953acd3b1SBarry Smith 
64095452b02SPatrick Sanan    Notes:
641811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
64253acd3b1SBarry Smith 
643811af0c4SBarry Smith           list is usually something like `PCASMTypes` or some other predefined list of enum names
64453acd3b1SBarry Smith 
6452efd9cb1SBarry Smith           If the user does not supply the option at all value is NOT changed. Thus
6462efd9cb1SBarry Smith           you should ALWAYS initialize value if you access it without first checking if the set flag is true.
6472efd9cb1SBarry Smith 
648989712b9SBarry Smith           The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
649989712b9SBarry Smith 
650db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
651db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
652db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
653db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
654c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
655db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
656db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
65788aa4217SBarry Smith M*/
65888aa4217SBarry Smith 
659d71ae5a4SJacob 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)
660d71ae5a4SJacob Faibussowitsch {
66153acd3b1SBarry Smith   PetscInt  ntext = 0;
662aa5bb8c0SSatish Balay   PetscInt  tval;
663ace3abfcSBarry Smith   PetscBool tflg;
66453acd3b1SBarry Smith 
66553acd3b1SBarry Smith   PetscFunctionBegin;
666ad540459SPierre Jolivet   while (list[ntext++]) PetscCheck(ntext <= 50, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "List argument appears to be wrong or have more than 50 entries");
66708401ef6SPierre Jolivet   PetscCheck(ntext >= 3, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "List argument must have at least two entries: typename and type prefix");
66853acd3b1SBarry Smith   ntext -= 3;
6699566063dSJacob Faibussowitsch   PetscCall(PetscOptionsEList_Private(PetscOptionsObject, opt, text, man, list, ntext, list[currentvalue], &tval, &tflg));
670aa5bb8c0SSatish Balay   /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */
671aa5bb8c0SSatish Balay   if (tflg) *value = (PetscEnum)tval;
672aa5bb8c0SSatish Balay   if (set) *set = tflg;
67353acd3b1SBarry Smith   PetscFunctionReturn(0);
67453acd3b1SBarry Smith }
67553acd3b1SBarry Smith 
67688aa4217SBarry Smith /*MC
677d3e47460SLisandro Dalcin    PetscOptionsEnumArray - Gets an array of enum values for a particular
678d3e47460SLisandro Dalcin    option in the database.
679d3e47460SLisandro Dalcin 
680811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
681d3e47460SLisandro Dalcin 
68288aa4217SBarry Smith    Synopsis:
68388aa4217SBarry Smith    #include "petscsys.h"
6843a89f35bSSatish Balay    PetscErrorCode  PetscOptionsEnumArray(const char opt[],const char text[],const char man[],const char *const *list,PetscEnum value[],PetscInt *n,PetscBool  *set)
68588aa4217SBarry Smith 
686d3e47460SLisandro Dalcin    Input Parameters:
687d3e47460SLisandro Dalcin +  opt - the option one is seeking
688d3e47460SLisandro Dalcin .  text - short string describing option
689d3e47460SLisandro Dalcin .  man - manual page for option
69022d58ec6SMatthew G. Knepley .  list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null
691c89788bdSBarry Smith -  n - maximum number of values allowed in the value array
692d3e47460SLisandro Dalcin 
693d8d19677SJose E. Roman    Output Parameters:
694d3e47460SLisandro Dalcin +  value - location to copy values
695d3e47460SLisandro Dalcin .  n - actual number of values found
696811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
697d3e47460SLisandro Dalcin 
698d3e47460SLisandro Dalcin    Level: beginner
699d3e47460SLisandro Dalcin 
700d3e47460SLisandro Dalcin    Notes:
701d3e47460SLisandro Dalcin    The array must be passed as a comma separated list.
702d3e47460SLisandro Dalcin 
703d3e47460SLisandro Dalcin    There must be no intervening spaces between the values.
704d3e47460SLisandro Dalcin 
705811af0c4SBarry Smith    Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
706d3e47460SLisandro Dalcin 
707db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
708db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
709db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
710c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
711db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
712db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`, `PetscOptionsRealArray()`
71388aa4217SBarry Smith M*/
71488aa4217SBarry Smith 
715d71ae5a4SJacob 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)
716d71ae5a4SJacob Faibussowitsch {
717d3e47460SLisandro Dalcin   PetscInt        i, nlist = 0;
7184416b707SBarry Smith   PetscOptionItem amsopt;
719d3e47460SLisandro Dalcin 
720d3e47460SLisandro Dalcin   PetscFunctionBegin;
72108401ef6SPierre Jolivet   while (list[nlist++]) PetscCheck(nlist <= 50, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "List argument appears to be wrong or have more than 50 entries");
72208401ef6SPierre Jolivet   PetscCheck(nlist >= 3, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "List argument must have at least two entries: typename and type prefix");
723d3e47460SLisandro Dalcin   nlist -= 3;                            /* drop enum name, prefix, and null termination */
724d3e47460SLisandro Dalcin   if (0 && !PetscOptionsObject->count) { /* XXX Requires additional support */
725d3e47460SLisandro Dalcin     PetscEnum *vals;
7269566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_INT_ARRAY /*XXX OPTION_ENUM_ARRAY*/, &amsopt));
7279566063dSJacob Faibussowitsch     PetscCall(PetscStrNArrayallocpy(nlist, list, (char ***)&amsopt->list));
728d3e47460SLisandro Dalcin     amsopt->nlist = nlist;
7299566063dSJacob Faibussowitsch     PetscCall(PetscMalloc1(*n, (PetscEnum **)&amsopt->data));
730d3e47460SLisandro Dalcin     amsopt->arraylength = *n;
731d3e47460SLisandro Dalcin     vals                = (PetscEnum *)amsopt->data;
732d3e47460SLisandro Dalcin     for (i = 0; i < *n; i++) vals[i] = value[i];
733d3e47460SLisandro Dalcin   }
7349566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetEnumArray(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, list, value, n, set));
735d3e47460SLisandro Dalcin   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
7369566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%s", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, list[value[0]]));
7379566063dSJacob Faibussowitsch     for (i = 1; i < *n; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ",%s", list[value[i]]));
7389566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ">: %s (choose from)", text));
7399566063dSJacob Faibussowitsch     for (i = 0; i < nlist; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, " %s", list[i]));
7409566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, " (%s)\n", ManSection(man)));
741d3e47460SLisandro Dalcin   }
742d3e47460SLisandro Dalcin   PetscFunctionReturn(0);
743d3e47460SLisandro Dalcin }
744d3e47460SLisandro Dalcin 
74588aa4217SBarry Smith /*MC
7465a856986SBarry Smith    PetscOptionsBoundedInt - Gets an integer value greater than or equal a given bound for a particular option in the database.
7475a856986SBarry Smith 
748811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
7495a856986SBarry Smith 
75088aa4217SBarry Smith    Synopsis:
75188aa4217SBarry Smith    #include "petscsys.h"
7523a89f35bSSatish Balay    PetscErrorCode  PetscOptionsBoundInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg,PetscInt bound)
75388aa4217SBarry Smith 
7545a856986SBarry Smith    Input Parameters:
7555a856986SBarry Smith +  opt - option name
7565a856986SBarry Smith .  text - short string that describes the option
7575a856986SBarry Smith .  man - manual page with additional information on option
7585a856986SBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
75988aa4217SBarry Smith $                 PetscOptionsInt(..., obj->value,&obj->value,...) or
7605a856986SBarry Smith $                 value = defaultvalue
7615a856986SBarry Smith $                 PetscOptionsInt(..., value,&value,&flg);
7625a856986SBarry Smith $                 if (flg) {
76388aa4217SBarry Smith -  bound - the requested value should be greater than or equal this bound or an error is generated
7645a856986SBarry Smith 
765d8d19677SJose E. Roman    Output Parameters:
7665a856986SBarry Smith +  value - the integer value to return
767811af0c4SBarry Smith -  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
7685a856986SBarry Smith 
7695a856986SBarry Smith    Notes:
7705a856986SBarry Smith     If the user does not supply the option at all value is NOT changed. Thus
7715a856986SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
7725a856986SBarry Smith 
7735a856986SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
7745a856986SBarry Smith 
775811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
7765a856986SBarry Smith 
7775a856986SBarry Smith    Level: beginner
7785a856986SBarry Smith 
779db781477SPatrick Sanan .seealso: `PetscOptionsInt()`, `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
780db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`, `PetscOptionsRangeInt()`
781db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
782db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
783c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
784db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
785db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
78688aa4217SBarry Smith M*/
7875a856986SBarry Smith 
78888aa4217SBarry Smith /*MC
7895a856986SBarry Smith    PetscOptionsRangeInt - Gets an integer value within a range of values for a particular option in the database.
7905a856986SBarry Smith 
791811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
7925a856986SBarry Smith 
79388aa4217SBarry Smith    Synopsis:
79488aa4217SBarry Smith    #include "petscsys.h"
7953a89f35bSSatish Balay    PetscErrorCode  PetscOptionsRangeInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg,PetscInt lb,PetscInt ub)
79688aa4217SBarry Smith 
7975a856986SBarry Smith    Input Parameters:
7985a856986SBarry Smith +  opt - option name
7995a856986SBarry Smith .  text - short string that describes the option
8005a856986SBarry Smith .  man - manual page with additional information on option
8015a856986SBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
80288aa4217SBarry Smith $                 PetscOptionsInt(..., obj->value,&obj->value,...) or
8035a856986SBarry Smith $                 value = defaultvalue
8045a856986SBarry Smith $                 PetscOptionsInt(..., value,&value,&flg);
8055a856986SBarry Smith $                 if (flg) {
80688aa4217SBarry Smith .  lb - the lower bound, provided value must be greater than or equal to this value or an error is generated
80788aa4217SBarry Smith -  ub - the upper bound, provided value must be less than or equal to this value or an error is generated
8085a856986SBarry Smith 
809d8d19677SJose E. Roman    Output Parameters:
8105a856986SBarry Smith +  value - the integer value to return
811811af0c4SBarry Smith -  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
8125a856986SBarry Smith 
8135a856986SBarry Smith    Notes:
8145a856986SBarry Smith     If the user does not supply the option at all value is NOT changed. Thus
8155a856986SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
8165a856986SBarry Smith 
8175a856986SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
8185a856986SBarry Smith 
819811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
8205a856986SBarry Smith 
8215a856986SBarry Smith    Level: beginner
8225a856986SBarry Smith 
823db781477SPatrick Sanan .seealso: `PetscOptionsInt()`, `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
824db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`, `PetscOptionsBoundedInt()`
825db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
826db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
827c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
828db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
829db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
83088aa4217SBarry Smith M*/
8315a856986SBarry Smith 
83288aa4217SBarry Smith /*MC
83353acd3b1SBarry Smith    PetscOptionsInt - Gets the integer value for a particular option in the database.
83453acd3b1SBarry Smith 
835811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
83653acd3b1SBarry Smith 
83788aa4217SBarry Smith    Synopsis:
83888aa4217SBarry Smith    #include "petscsys.h"
8396eeb591dSVaclav Hapla    PetscErrorCode  PetscOptionsInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg))
84088aa4217SBarry Smith 
84153acd3b1SBarry Smith    Input Parameters:
84253acd3b1SBarry Smith +  opt - option name
84353acd3b1SBarry Smith .  text - short string that describes the option
84453acd3b1SBarry Smith .  man - manual page with additional information on option
8450fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
84688aa4217SBarry Smith $                 PetscOptionsInt(..., obj->value,&obj->value,...) or
8470fdccdaeSBarry Smith $                 value = defaultvalue
8480fdccdaeSBarry Smith $                 PetscOptionsInt(..., value,&value,&flg);
8490fdccdaeSBarry Smith $                 if (flg) {
85053acd3b1SBarry Smith 
851d8d19677SJose E. Roman    Output Parameters:
85253acd3b1SBarry Smith +  value - the integer value to return
853811af0c4SBarry Smith -  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
85453acd3b1SBarry Smith 
85595452b02SPatrick Sanan    Notes:
85695452b02SPatrick Sanan     If the user does not supply the option at all value is NOT changed. Thus
8572efd9cb1SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
8582efd9cb1SBarry Smith 
859989712b9SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
860989712b9SBarry Smith 
861811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
86253acd3b1SBarry Smith 
8635a856986SBarry Smith    Level: beginner
8645a856986SBarry Smith 
865db781477SPatrick Sanan .seealso: `PetscOptionsBoundedInt()`, `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
866db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`, `PetscOptionsRangeInt()`
867db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
868db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
869c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
870db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
871db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
87288aa4217SBarry Smith M*/
87388aa4217SBarry Smith 
874d71ae5a4SJacob 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)
875d71ae5a4SJacob Faibussowitsch {
8764416b707SBarry Smith   PetscOptionItem amsopt;
87712655325SBarry Smith   PetscBool       wasset;
87853acd3b1SBarry Smith 
87953acd3b1SBarry Smith   PetscFunctionBegin;
88008401ef6SPierre Jolivet   PetscCheck(currentvalue >= lb, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Current value %" PetscInt_FMT " less than allowed bound %" PetscInt_FMT, currentvalue, lb);
88108401ef6SPierre Jolivet   PetscCheck(currentvalue <= ub, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Current value %" PetscInt_FMT " greater than allowed bound %" PetscInt_FMT, currentvalue, ub);
882e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
8839566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_INT, &amsopt));
8849566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscInt), &amsopt->data));
88512655325SBarry Smith     *(PetscInt *)amsopt->data = currentvalue;
8863e211508SBarry Smith 
8879566063dSJacob Faibussowitsch     PetscCall(PetscOptionsGetInt(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, &currentvalue, &wasset));
888ad540459SPierre Jolivet     if (wasset) *(PetscInt *)amsopt->data = currentvalue;
889af6d86caSBarry Smith   }
8909566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetInt(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, &wasset));
891cc73adaaSBarry 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);
892cc73adaaSBarry 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);
89344ef3d73SBarry Smith   if (set) *set = wasset;
894e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
8959566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <now %" PetscInt_FMT " : formerly %" PetscInt_FMT ">: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, wasset && value ? *value : currentvalue, currentvalue, text, ManSection(man)));
89653acd3b1SBarry Smith   }
89753acd3b1SBarry Smith   PetscFunctionReturn(0);
89853acd3b1SBarry Smith }
89953acd3b1SBarry Smith 
90088aa4217SBarry Smith /*MC
90153acd3b1SBarry Smith    PetscOptionsString - Gets the string value for a particular option in the database.
90253acd3b1SBarry Smith 
903811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
90453acd3b1SBarry Smith 
90588aa4217SBarry Smith    Synopsis:
90688aa4217SBarry Smith    #include "petscsys.h"
9073a89f35bSSatish Balay    PetscErrorCode  PetscOptionsString(const char opt[],const char text[],const char man[],const char currentvalue[],char value[],size_t len,PetscBool  *set)
90888aa4217SBarry Smith 
90953acd3b1SBarry Smith    Input Parameters:
91053acd3b1SBarry Smith +  opt - option name
91153acd3b1SBarry Smith .  text - short string that describes the option
91253acd3b1SBarry Smith .  man - manual page with additional information on option
9130fdccdaeSBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. This is not used to set value
914bcbf2dc5SJed Brown -  len - length of the result string including null terminator
91553acd3b1SBarry Smith 
916d8d19677SJose E. Roman    Output Parameters:
91753acd3b1SBarry Smith +  value - the value to return
918811af0c4SBarry Smith -  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
91953acd3b1SBarry Smith 
92053acd3b1SBarry Smith    Level: beginner
92153acd3b1SBarry Smith 
92295452b02SPatrick Sanan    Notes:
923811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
92453acd3b1SBarry Smith 
9257fccdfe4SBarry Smith    Even if the user provided no string (for example -optionname -someotheroption) the flag is set to PETSC_TRUE (and the string is fulled with nulls).
9267fccdfe4SBarry Smith 
9272efd9cb1SBarry Smith           If the user does not supply the option at all value is NOT changed. Thus
9282efd9cb1SBarry Smith           you should ALWAYS initialize value if you access it without first checking if the set flag is true.
9292efd9cb1SBarry Smith 
930989712b9SBarry Smith           The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
931989712b9SBarry Smith 
932db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
933db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
934db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
935db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
936c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
937db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
938db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
93988aa4217SBarry Smith M*/
94088aa4217SBarry Smith 
941d71ae5a4SJacob 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)
942d71ae5a4SJacob Faibussowitsch {
9434416b707SBarry Smith   PetscOptionItem amsopt;
94444ef3d73SBarry Smith   PetscBool       lset;
94553acd3b1SBarry Smith 
94653acd3b1SBarry Smith   PetscFunctionBegin;
9471a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
9489566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_STRING, &amsopt));
94964facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
9509566063dSJacob Faibussowitsch     PetscCall(PetscStrdup(currentvalue ? currentvalue : "", (char **)&amsopt->data));
951af6d86caSBarry Smith   }
9529566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetString(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, len, &lset));
95344ef3d73SBarry Smith   if (set) *set = lset;
954e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
9559566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <now %s : formerly %s>: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, lset && value ? value : currentvalue, currentvalue, text, ManSection(man)));
95653acd3b1SBarry Smith   }
95753acd3b1SBarry Smith   PetscFunctionReturn(0);
95853acd3b1SBarry Smith }
95953acd3b1SBarry Smith 
96088aa4217SBarry Smith /*MC
961811af0c4SBarry Smith    PetscOptionsReal - Gets the `PetscReal` value for a particular option in the database.
96253acd3b1SBarry Smith 
963811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
96453acd3b1SBarry Smith 
96588aa4217SBarry Smith    Synopsis:
96688aa4217SBarry Smith    #include "petscsys.h"
9673a89f35bSSatish Balay    PetscErrorCode  PetscOptionsReal(const char opt[],const char text[],const char man[],PetscReal currentvalue,PetscReal *value,PetscBool  *set)
96888aa4217SBarry Smith 
96953acd3b1SBarry Smith    Input Parameters:
97053acd3b1SBarry Smith +  opt - option name
97153acd3b1SBarry Smith .  text - short string that describes the option
97253acd3b1SBarry Smith .  man - manual page with additional information on option
9730fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
97488aa4217SBarry Smith $                 PetscOptionsReal(..., obj->value,&obj->value,...) or
9750fdccdaeSBarry Smith $                 value = defaultvalue
9760fdccdaeSBarry Smith $                 PetscOptionsReal(..., value,&value,&flg);
9770fdccdaeSBarry Smith $                 if (flg) {
97853acd3b1SBarry Smith 
979d8d19677SJose E. Roman    Output Parameters:
98053acd3b1SBarry Smith +  value - the value to return
981811af0c4SBarry Smith -  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
98253acd3b1SBarry Smith 
98395452b02SPatrick Sanan    Notes:
98495452b02SPatrick Sanan     If the user does not supply the option at all value is NOT changed. Thus
9852efd9cb1SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
9862efd9cb1SBarry Smith 
987989712b9SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
988989712b9SBarry Smith 
989811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
99053acd3b1SBarry Smith 
9915a856986SBarry Smith    Level: beginner
9925a856986SBarry Smith 
993db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
994db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
995db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
996db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
997c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
998db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
999db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
100088aa4217SBarry Smith M*/
100188aa4217SBarry Smith 
1002d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsReal_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscReal currentvalue, PetscReal *value, PetscBool *set)
1003d71ae5a4SJacob Faibussowitsch {
10044416b707SBarry Smith   PetscOptionItem amsopt;
100544ef3d73SBarry Smith   PetscBool       lset;
100653acd3b1SBarry Smith 
100753acd3b1SBarry Smith   PetscFunctionBegin;
1008e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
10099566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_REAL, &amsopt));
10109566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscReal), &amsopt->data));
1011a297a907SKarl Rupp 
10120fdccdaeSBarry Smith     *(PetscReal *)amsopt->data = currentvalue;
1013538aa990SBarry Smith   }
10149566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetReal(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, &lset));
101544ef3d73SBarry Smith   if (set) *set = lset;
10161a1499c8SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
10179566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%g : %g>: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, lset && value ? (double)*value : (double)currentvalue, (double)currentvalue, text, ManSection(man)));
101853acd3b1SBarry Smith   }
101953acd3b1SBarry Smith   PetscFunctionReturn(0);
102053acd3b1SBarry Smith }
102153acd3b1SBarry Smith 
102288aa4217SBarry Smith /*MC
1023811af0c4SBarry Smith    PetscOptionsScalar - Gets the `PetscScalar` value for a particular option in the database.
102453acd3b1SBarry Smith 
1025811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
102653acd3b1SBarry Smith 
102788aa4217SBarry Smith    Synopsis:
102888aa4217SBarry Smith    #include "petscsys.h"
10293a89f35bSSatish Balay    PetscErrorCode PetscOptionsScalar(const char opt[],const char text[],const char man[],PetscScalar currentvalue,PetscScalar *value,PetscBool  *set)
103088aa4217SBarry Smith 
103153acd3b1SBarry Smith    Input Parameters:
103253acd3b1SBarry Smith +  opt - option name
103353acd3b1SBarry Smith .  text - short string that describes the option
103453acd3b1SBarry Smith .  man - manual page with additional information on option
10350fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
103688aa4217SBarry Smith $                 PetscOptionsScalar(..., obj->value,&obj->value,...) or
10370fdccdaeSBarry Smith $                 value = defaultvalue
10380fdccdaeSBarry Smith $                 PetscOptionsScalar(..., value,&value,&flg);
10390fdccdaeSBarry Smith $                 if (flg) {
10400fdccdaeSBarry Smith 
1041d8d19677SJose E. Roman    Output Parameters:
104253acd3b1SBarry Smith +  value - the value to return
1043811af0c4SBarry Smith -  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
104453acd3b1SBarry Smith 
104595452b02SPatrick Sanan    Notes:
104695452b02SPatrick Sanan     If the user does not supply the option at all value is NOT changed. Thus
10472efd9cb1SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
10482efd9cb1SBarry Smith 
1049989712b9SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
1050989712b9SBarry Smith 
1051811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
105253acd3b1SBarry Smith 
10535a856986SBarry Smith    Level: beginner
10545a856986SBarry Smith 
1055db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
1056db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
1057db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
1058db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1059c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1060db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1061db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
106288aa4217SBarry Smith M*/
106388aa4217SBarry Smith 
1064d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsScalar_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscScalar currentvalue, PetscScalar *value, PetscBool *set)
1065d71ae5a4SJacob Faibussowitsch {
106653acd3b1SBarry Smith   PetscFunctionBegin;
106753acd3b1SBarry Smith #if !defined(PETSC_USE_COMPLEX)
10689566063dSJacob Faibussowitsch   PetscCall(PetscOptionsReal(opt, text, man, currentvalue, value, set));
106953acd3b1SBarry Smith #else
10709566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetScalar(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, set));
107153acd3b1SBarry Smith #endif
107253acd3b1SBarry Smith   PetscFunctionReturn(0);
107353acd3b1SBarry Smith }
107453acd3b1SBarry Smith 
107588aa4217SBarry Smith /*MC
107690d69ab7SBarry 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
107790d69ab7SBarry Smith                       its value is set to false.
107853acd3b1SBarry Smith 
1079811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
108053acd3b1SBarry Smith 
108188aa4217SBarry Smith    Synopsis:
108288aa4217SBarry Smith    #include "petscsys.h"
10833a89f35bSSatish Balay    PetscErrorCode PetscOptionsName(const char opt[],const char text[],const char man[],PetscBool  *flg)
108488aa4217SBarry Smith 
108553acd3b1SBarry Smith    Input Parameters:
108653acd3b1SBarry Smith +  opt - option name
108753acd3b1SBarry Smith .  text - short string that describes the option
108853acd3b1SBarry Smith -  man - manual page with additional information on option
108953acd3b1SBarry Smith 
109053acd3b1SBarry Smith    Output Parameter:
1091811af0c4SBarry Smith .  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
109253acd3b1SBarry Smith 
109353acd3b1SBarry Smith    Level: beginner
109453acd3b1SBarry Smith 
1095811af0c4SBarry Smith    Note:
1096811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
109753acd3b1SBarry Smith 
1098db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
1099db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
1100db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
1101db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1102c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1103db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1104db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
110588aa4217SBarry Smith M*/
110688aa4217SBarry Smith 
1107d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsName_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool *flg)
1108d71ae5a4SJacob Faibussowitsch {
11094416b707SBarry Smith   PetscOptionItem amsopt;
111053acd3b1SBarry Smith 
111153acd3b1SBarry Smith   PetscFunctionBegin;
1112e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
11139566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt));
11149566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data));
1115a297a907SKarl Rupp 
1116ace3abfcSBarry Smith     *(PetscBool *)amsopt->data = PETSC_FALSE;
11171ae3d29cSBarry Smith   }
11189566063dSJacob Faibussowitsch   PetscCall(PetscOptionsHasName(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, flg));
1119e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
11209566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, text, ManSection(man)));
112153acd3b1SBarry Smith   }
112253acd3b1SBarry Smith   PetscFunctionReturn(0);
112353acd3b1SBarry Smith }
112453acd3b1SBarry Smith 
112588aa4217SBarry Smith /*MC
1126a264d7a6SBarry Smith      PetscOptionsFList - Puts a list of option values that a single one may be selected from
112753acd3b1SBarry Smith 
1128811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
112953acd3b1SBarry Smith 
113088aa4217SBarry Smith    Synopsis:
113188aa4217SBarry Smith    #include "petscsys.h"
11323a89f35bSSatish Balay    PetscErrorCode  PetscOptionsFList(const char opt[],const char ltext[],const char man[],PetscFunctionList list,const char currentvalue[],char value[],size_t len,PetscBool  *set)
113388aa4217SBarry Smith 
113453acd3b1SBarry Smith    Input Parameters:
113553acd3b1SBarry Smith +  opt - option name
113653acd3b1SBarry Smith .  text - short string that describes the option
113753acd3b1SBarry Smith .  man - manual page with additional information on option
113853acd3b1SBarry Smith .  list - the possible choices
11390fdccdaeSBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with
11400fdccdaeSBarry Smith $                 PetscOptionsFlist(..., obj->value,value,len,&flg);
11410fdccdaeSBarry Smith $                 if (flg) {
11423cc1e11dSBarry Smith -  len - the length of the character array value
114353acd3b1SBarry Smith 
1144d8d19677SJose E. Roman    Output Parameters:
114553acd3b1SBarry Smith +  value - the value to return
1146811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
114753acd3b1SBarry Smith 
114853acd3b1SBarry Smith    Level: intermediate
114953acd3b1SBarry Smith 
115095452b02SPatrick Sanan    Notes:
1151811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
115253acd3b1SBarry Smith 
11532efd9cb1SBarry Smith           If the user does not supply the option at all value is NOT changed. Thus
11542efd9cb1SBarry Smith           you should ALWAYS initialize value if you access it without first checking if the set flag is true.
11552efd9cb1SBarry Smith 
1156989712b9SBarry Smith           The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
1157989712b9SBarry Smith 
1158811af0c4SBarry Smith    See `PetscOptionsEList()` for when the choices are given in a string array
115953acd3b1SBarry Smith 
116053acd3b1SBarry Smith    To get a listing of all currently specified options,
1161811af0c4SBarry Smith     see `PetscOptionsView()` or `PetscOptionsGetAll()`
116253acd3b1SBarry Smith 
1163811af0c4SBarry Smith    Developer Note:
1164811af0c4SBarry Smith    This cannot check for invalid selection because of things like `MATAIJ` that are not included in the list
1165eabe10d7SBarry Smith 
1166db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1167db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1168db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1169c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1170db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1171db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`, `PetscOptionsEnum()`
117288aa4217SBarry Smith M*/
117388aa4217SBarry Smith 
1174d71ae5a4SJacob 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)
1175d71ae5a4SJacob Faibussowitsch {
11764416b707SBarry Smith   PetscOptionItem amsopt;
117744ef3d73SBarry Smith   PetscBool       lset;
117853acd3b1SBarry Smith 
117953acd3b1SBarry Smith   PetscFunctionBegin;
11801a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
11819566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, ltext, man, OPTION_FLIST, &amsopt));
118264facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
11839566063dSJacob Faibussowitsch     PetscCall(PetscStrdup(currentvalue ? currentvalue : "", (char **)&amsopt->data));
11843cc1e11dSBarry Smith     amsopt->flist = list;
11853cc1e11dSBarry Smith   }
11869566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetString(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, len, &lset));
118744ef3d73SBarry Smith   if (set) *set = lset;
11881a1499c8SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
11899566063dSJacob Faibussowitsch     PetscCall(PetscFunctionListPrintTypes(PetscOptionsObject->comm, stdout, PetscOptionsObject->prefix, opt, ltext, man, list, currentvalue, lset && value ? value : currentvalue));
119053acd3b1SBarry Smith   }
119153acd3b1SBarry Smith   PetscFunctionReturn(0);
119253acd3b1SBarry Smith }
119353acd3b1SBarry Smith 
119488aa4217SBarry Smith /*MC
119553acd3b1SBarry Smith      PetscOptionsEList - Puts a list of option values that a single one may be selected from
119653acd3b1SBarry Smith 
1197811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
119853acd3b1SBarry Smith 
119988aa4217SBarry Smith    Synopsis:
120088aa4217SBarry Smith    #include "petscsys.h"
12013a89f35bSSatish 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)
120288aa4217SBarry Smith 
120353acd3b1SBarry Smith    Input Parameters:
120453acd3b1SBarry Smith +  opt - option name
120553acd3b1SBarry Smith .  ltext - short string that describes the option
120653acd3b1SBarry Smith .  man - manual page with additional information on option
1207a264d7a6SBarry Smith .  list - the possible choices (one of these must be selected, anything else is invalid)
120853acd3b1SBarry Smith .  ntext - number of choices
12090fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with
12100fdccdaeSBarry Smith $                 PetscOptionsElist(..., obj->value,&value,&flg);
12110fdccdaeSBarry Smith $                 if (flg) {
12120fdccdaeSBarry Smith 
1213d8d19677SJose E. Roman    Output Parameters:
121453acd3b1SBarry Smith +  value - the index of the value to return
1215811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
121653acd3b1SBarry Smith 
121753acd3b1SBarry Smith    Level: intermediate
121853acd3b1SBarry Smith 
121995452b02SPatrick Sanan    Notes:
1220811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
122153acd3b1SBarry Smith 
12222efd9cb1SBarry Smith          If the user does not supply the option at all value is NOT changed. Thus
12232efd9cb1SBarry Smith           you should ALWAYS initialize value if you access it without first checking if the set flag is true.
12242efd9cb1SBarry Smith 
1225811af0c4SBarry Smith    See `PetscOptionsFList()` for when the choices are given in a `PetscFunctionList()`
122653acd3b1SBarry 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()`, `PetscOptionsEnum()`
123388aa4217SBarry Smith M*/
123488aa4217SBarry Smith 
1235d71ae5a4SJacob 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)
1236d71ae5a4SJacob Faibussowitsch {
123753acd3b1SBarry Smith   PetscInt        i;
12384416b707SBarry Smith   PetscOptionItem amsopt;
123944ef3d73SBarry Smith   PetscBool       lset;
124053acd3b1SBarry Smith 
124153acd3b1SBarry Smith   PetscFunctionBegin;
12421a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
12439566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, ltext, man, OPTION_ELIST, &amsopt));
124464facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
12459566063dSJacob Faibussowitsch     PetscCall(PetscStrdup(currentvalue ? currentvalue : "", (char **)&amsopt->data));
12469566063dSJacob Faibussowitsch     PetscCall(PetscStrNArrayallocpy(ntext, list, (char ***)&amsopt->list));
12471ae3d29cSBarry Smith     amsopt->nlist = ntext;
12481ae3d29cSBarry Smith   }
12499566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetEList(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, list, ntext, value, &lset));
125044ef3d73SBarry Smith   if (set) *set = lset;
12511a1499c8SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
12529566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <now %s : formerly %s> %s (choose one of)", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, lset && value ? list[*value] : currentvalue, currentvalue, ltext));
125348a46eb9SPierre Jolivet     for (i = 0; i < ntext; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, " %s", list[i]));
12549566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, " (%s)\n", ManSection(man)));
125553acd3b1SBarry Smith   }
125653acd3b1SBarry Smith   PetscFunctionReturn(0);
125753acd3b1SBarry Smith }
125853acd3b1SBarry Smith 
125988aa4217SBarry Smith /*MC
1260acfcf0e5SJed Brown      PetscOptionsBoolGroupBegin - First in a series of logical queries on the options database for
1261d5649816SBarry Smith        which at most a single value can be true.
126253acd3b1SBarry Smith 
1263811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
126453acd3b1SBarry Smith 
126588aa4217SBarry Smith    Synopsis:
126688aa4217SBarry Smith    #include "petscsys.h"
12673a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolGroupBegin(const char opt[],const char text[],const char man[],PetscBool  *flg)
126888aa4217SBarry Smith 
126953acd3b1SBarry Smith    Input Parameters:
127053acd3b1SBarry Smith +  opt - option name
127153acd3b1SBarry Smith .  text - short string that describes the option
127253acd3b1SBarry Smith -  man - manual page with additional information on option
127353acd3b1SBarry Smith 
127453acd3b1SBarry Smith    Output Parameter:
127553acd3b1SBarry Smith .  flg - whether that option was set or not
127653acd3b1SBarry Smith 
127753acd3b1SBarry Smith    Level: intermediate
127853acd3b1SBarry Smith 
127995452b02SPatrick Sanan    Notes:
1280811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
128153acd3b1SBarry Smith 
1282811af0c4SBarry Smith    Must be followed by 0 or more P`etscOptionsBoolGroup()`s and `PetscOptionsBoolGroupEnd()`
128353acd3b1SBarry Smith 
1284db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1285db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1286db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1287c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1288db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1289db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
129088aa4217SBarry Smith M*/
129188aa4217SBarry Smith 
1292d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsBoolGroupBegin_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool *flg)
1293d71ae5a4SJacob Faibussowitsch {
12944416b707SBarry Smith   PetscOptionItem amsopt;
129553acd3b1SBarry Smith 
129653acd3b1SBarry Smith   PetscFunctionBegin;
1297e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
12989566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt));
12999566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data));
1300a297a907SKarl Rupp 
1301ace3abfcSBarry Smith     *(PetscBool *)amsopt->data = PETSC_FALSE;
13021ae3d29cSBarry Smith   }
130368b16fdaSBarry Smith   *flg = PETSC_FALSE;
13049566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetBool(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, flg, NULL));
1305e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
13069566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  Pick at most one of -------------\n"));
13079566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "    -%s%s: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, text, ManSection(man)));
130853acd3b1SBarry Smith   }
130953acd3b1SBarry Smith   PetscFunctionReturn(0);
131053acd3b1SBarry Smith }
131153acd3b1SBarry Smith 
131288aa4217SBarry Smith /*MC
1313acfcf0e5SJed Brown      PetscOptionsBoolGroup - One in a series of logical queries on the options database for
1314d5649816SBarry Smith        which at most a single value can be true.
131553acd3b1SBarry Smith 
1316811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
131753acd3b1SBarry Smith 
131888aa4217SBarry Smith    Synopsis:
131988aa4217SBarry Smith    #include "petscsys.h"
13203a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolGroup(const char opt[],const char text[],const char man[],PetscBool  *flg)
132188aa4217SBarry Smith 
132253acd3b1SBarry Smith    Input Parameters:
132353acd3b1SBarry Smith +  opt - option name
132453acd3b1SBarry Smith .  text - short string that describes the option
132553acd3b1SBarry Smith -  man - manual page with additional information on option
132653acd3b1SBarry Smith 
132753acd3b1SBarry Smith    Output Parameter:
1328811af0c4SBarry Smith .  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
132953acd3b1SBarry Smith 
133053acd3b1SBarry Smith    Level: intermediate
133153acd3b1SBarry Smith 
133295452b02SPatrick Sanan    Notes:
1333811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
133453acd3b1SBarry Smith 
1335811af0c4SBarry Smith    Must follow a `PetscOptionsBoolGroupBegin()` and preceded a `PetscOptionsBoolGroupEnd()`
133653acd3b1SBarry Smith 
1337db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1338db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1339db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1340c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1341db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1342db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
134388aa4217SBarry Smith M*/
134488aa4217SBarry Smith 
1345d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsBoolGroup_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool *flg)
1346d71ae5a4SJacob Faibussowitsch {
13474416b707SBarry Smith   PetscOptionItem amsopt;
134853acd3b1SBarry Smith 
134953acd3b1SBarry Smith   PetscFunctionBegin;
1350e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
13519566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt));
13529566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data));
1353a297a907SKarl Rupp 
1354ace3abfcSBarry Smith     *(PetscBool *)amsopt->data = PETSC_FALSE;
13551ae3d29cSBarry Smith   }
135617326d04SJed Brown   *flg = PETSC_FALSE;
13579566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetBool(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, flg, NULL));
1358e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
13599566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "    -%s%s: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, text, ManSection(man)));
136053acd3b1SBarry Smith   }
136153acd3b1SBarry Smith   PetscFunctionReturn(0);
136253acd3b1SBarry Smith }
136353acd3b1SBarry Smith 
136488aa4217SBarry Smith /*MC
1365acfcf0e5SJed Brown      PetscOptionsBoolGroupEnd - Last in a series of logical queries on the options database for
1366d5649816SBarry Smith        which at most a single value can be true.
136753acd3b1SBarry Smith 
1368811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
136953acd3b1SBarry Smith 
137088aa4217SBarry Smith    Synopsis:
137188aa4217SBarry Smith    #include "petscsys.h"
13723a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolGroupEnd(const char opt[],const char text[],const char man[],PetscBool  *flg)
137388aa4217SBarry Smith 
137453acd3b1SBarry Smith    Input Parameters:
137553acd3b1SBarry Smith +  opt - option name
137653acd3b1SBarry Smith .  text - short string that describes the option
137753acd3b1SBarry Smith -  man - manual page with additional information on option
137853acd3b1SBarry Smith 
137953acd3b1SBarry Smith    Output Parameter:
1380811af0c4SBarry Smith .  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
138153acd3b1SBarry Smith 
138253acd3b1SBarry Smith    Level: intermediate
138353acd3b1SBarry Smith 
138495452b02SPatrick Sanan    Notes:
1385811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
138653acd3b1SBarry Smith 
1387811af0c4SBarry Smith    Must follow a `PetscOptionsBoolGroupBegin()`
138853acd3b1SBarry Smith 
1389db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1390db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1391db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1392c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1393db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1394db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
139588aa4217SBarry Smith M*/
139688aa4217SBarry Smith 
1397d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsBoolGroupEnd_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool *flg)
1398d71ae5a4SJacob Faibussowitsch {
13994416b707SBarry Smith   PetscOptionItem amsopt;
140053acd3b1SBarry Smith 
140153acd3b1SBarry Smith   PetscFunctionBegin;
1402e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
14039566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt));
14049566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data));
1405a297a907SKarl Rupp 
1406ace3abfcSBarry Smith     *(PetscBool *)amsopt->data = PETSC_FALSE;
14071ae3d29cSBarry Smith   }
140817326d04SJed Brown   *flg = PETSC_FALSE;
14099566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetBool(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, flg, NULL));
1410e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
14119566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "    -%s%s: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, text, ManSection(man)));
141253acd3b1SBarry Smith   }
141353acd3b1SBarry Smith   PetscFunctionReturn(0);
141453acd3b1SBarry Smith }
141553acd3b1SBarry Smith 
141688aa4217SBarry Smith /*MC
1417acfcf0e5SJed Brown    PetscOptionsBool - Determines if a particular option is in the database with a true or false
141853acd3b1SBarry Smith 
1419811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
142053acd3b1SBarry Smith 
142188aa4217SBarry Smith    Synopsis:
142288aa4217SBarry Smith    #include "petscsys.h"
14233a89f35bSSatish Balay    PetscErrorCode PetscOptionsBool(const char opt[],const char text[],const char man[],PetscBool currentvalue,PetscBool  *flg,PetscBool  *set)
142488aa4217SBarry Smith 
142553acd3b1SBarry Smith    Input Parameters:
142653acd3b1SBarry Smith +  opt - option name
142753acd3b1SBarry Smith .  text - short string that describes the option
1428868c398cSBarry Smith .  man - manual page with additional information on option
142994ae4db5SBarry Smith -  currentvalue - the current value
143053acd3b1SBarry Smith 
1431d8d19677SJose E. Roman    Output Parameters:
1432811af0c4SBarry Smith +  flg -` PETSC_TRUE` or `PETSC_FALSE`
1433811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
143453acd3b1SBarry Smith 
14352efd9cb1SBarry Smith    Notes:
1436811af0c4SBarry Smith        TRUE, true, YES, yes, nostring, and 1 all translate to `PETSC_TRUE`
1437811af0c4SBarry Smith        FALSE, false, NO, no, and 0 all translate to `PETSC_FALSE`
14382efd9cb1SBarry Smith 
1439811af0c4SBarry 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
14402efd9cb1SBarry Smith      is equivalent to -requested_bool true
14412efd9cb1SBarry Smith 
14422efd9cb1SBarry Smith        If the user does not supply the option at all flg is NOT changed. Thus
14432efd9cb1SBarry Smith      you should ALWAYS initialize the flg if you access it without first checking if the set flag is true.
14442efd9cb1SBarry Smith 
1445811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
144653acd3b1SBarry Smith 
14475a856986SBarry Smith    Level: beginner
14485a856986SBarry Smith 
1449db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
1450db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
1451db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`,
1452db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1453c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1454db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1455db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
145688aa4217SBarry Smith M*/
145788aa4217SBarry Smith 
1458d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsBool_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool currentvalue, PetscBool *flg, PetscBool *set)
1459d71ae5a4SJacob Faibussowitsch {
1460ace3abfcSBarry Smith   PetscBool       iset;
14614416b707SBarry Smith   PetscOptionItem amsopt;
146253acd3b1SBarry Smith 
146353acd3b1SBarry Smith   PetscFunctionBegin;
1464e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
14659566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt));
14669566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data));
1467a297a907SKarl Rupp 
146894ae4db5SBarry Smith     *(PetscBool *)amsopt->data = currentvalue;
1469af6d86caSBarry Smith   }
14709566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetBool(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, flg, &iset));
147153acd3b1SBarry Smith   if (set) *set = iset;
14721a1499c8SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
147344ef3d73SBarry Smith     const char *v = PetscBools[currentvalue], *vn = PetscBools[iset && flg ? *flg : currentvalue];
14749566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s: <%s : %s> %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, v, vn, text, ManSection(man)));
147553acd3b1SBarry Smith   }
147653acd3b1SBarry Smith   PetscFunctionReturn(0);
147753acd3b1SBarry Smith }
147853acd3b1SBarry Smith 
147988aa4217SBarry Smith /*MC
148053acd3b1SBarry Smith    PetscOptionsRealArray - Gets an array of double values for a particular
148153acd3b1SBarry Smith    option in the database. The values must be separated with commas with
148253acd3b1SBarry Smith    no intervening spaces.
148353acd3b1SBarry Smith 
1484811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
148553acd3b1SBarry Smith 
148688aa4217SBarry Smith    Synopsis:
148788aa4217SBarry Smith    #include "petscsys.h"
14883a89f35bSSatish Balay    PetscErrorCode PetscOptionsRealArray(const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscBool  *set)
148988aa4217SBarry Smith 
149053acd3b1SBarry Smith    Input Parameters:
149153acd3b1SBarry Smith +  opt - the option one is seeking
149253acd3b1SBarry Smith .  text - short string describing option
149353acd3b1SBarry Smith .  man - manual page for option
1494c89788bdSBarry Smith -  n - maximum number of values that value has room for
149553acd3b1SBarry Smith 
1496d8d19677SJose E. Roman    Output Parameters:
149753acd3b1SBarry Smith +  value - location to copy values
1498c89788bdSBarry Smith .  n - actual number of values found
1499811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
150053acd3b1SBarry Smith 
150153acd3b1SBarry Smith    Level: beginner
150253acd3b1SBarry Smith 
1503811af0c4SBarry Smith    Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
150453acd3b1SBarry Smith 
1505db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1506db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1507db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1508c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1509db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1510db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
151188aa4217SBarry Smith M*/
151288aa4217SBarry Smith 
1513d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsRealArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscReal value[], PetscInt *n, PetscBool *set)
1514d71ae5a4SJacob Faibussowitsch {
151553acd3b1SBarry Smith   PetscInt        i;
15164416b707SBarry Smith   PetscOptionItem amsopt;
151753acd3b1SBarry Smith 
151853acd3b1SBarry Smith   PetscFunctionBegin;
1519e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1520e26ddf31SBarry Smith     PetscReal *vals;
1521e26ddf31SBarry Smith 
15229566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_REAL_ARRAY, &amsopt));
15239566063dSJacob Faibussowitsch     PetscCall(PetscMalloc((*n) * sizeof(PetscReal), &amsopt->data));
1524e26ddf31SBarry Smith     vals = (PetscReal *)amsopt->data;
1525e26ddf31SBarry Smith     for (i = 0; i < *n; i++) vals[i] = value[i];
1526e26ddf31SBarry Smith     amsopt->arraylength = *n;
1527e26ddf31SBarry Smith   }
15289566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetRealArray(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, n, set));
1529e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
15309566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%g", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, (double)value[0]));
153148a46eb9SPierre Jolivet     for (i = 1; i < *n; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ",%g", (double)value[i]));
15329566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ">: %s (%s)\n", text, ManSection(man)));
153353acd3b1SBarry Smith   }
153453acd3b1SBarry Smith   PetscFunctionReturn(0);
153553acd3b1SBarry Smith }
153653acd3b1SBarry Smith 
153788aa4217SBarry Smith /*MC
1538811af0c4SBarry Smith    PetscOptionsScalarArray - Gets an array of `PetscScalar` values for a particular
1539050cccc3SHong Zhang    option in the database. The values must be separated with commas with
1540050cccc3SHong Zhang    no intervening spaces.
1541050cccc3SHong Zhang 
1542811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
1543050cccc3SHong Zhang 
154488aa4217SBarry Smith    Synopsis:
154588aa4217SBarry Smith    #include "petscsys.h"
15463a89f35bSSatish Balay    PetscErrorCode PetscOptionsScalarArray(const char opt[],const char text[],const char man[],PetscScalar value[],PetscInt *n,PetscBool  *set)
154788aa4217SBarry Smith 
1548050cccc3SHong Zhang    Input Parameters:
1549050cccc3SHong Zhang +  opt - the option one is seeking
1550050cccc3SHong Zhang .  text - short string describing option
1551050cccc3SHong Zhang .  man - manual page for option
1552c89788bdSBarry Smith -  n - maximum number of values allowed in the value array
1553050cccc3SHong Zhang 
1554d8d19677SJose E. Roman    Output Parameters:
1555050cccc3SHong Zhang +  value - location to copy values
1556c89788bdSBarry Smith .  n - actual number of values found
1557811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
1558050cccc3SHong Zhang 
1559050cccc3SHong Zhang    Level: beginner
1560050cccc3SHong Zhang 
1561811af0c4SBarry Smith    Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
1562050cccc3SHong Zhang 
1563db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1564db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1565db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1566c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1567db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1568db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
156988aa4217SBarry Smith M*/
157088aa4217SBarry Smith 
1571d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsScalarArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscScalar value[], PetscInt *n, PetscBool *set)
1572d71ae5a4SJacob Faibussowitsch {
1573050cccc3SHong Zhang   PetscInt        i;
15744416b707SBarry Smith   PetscOptionItem amsopt;
1575050cccc3SHong Zhang 
1576050cccc3SHong Zhang   PetscFunctionBegin;
1577050cccc3SHong Zhang   if (!PetscOptionsObject->count) {
1578050cccc3SHong Zhang     PetscScalar *vals;
1579050cccc3SHong Zhang 
15809566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_SCALAR_ARRAY, &amsopt));
15819566063dSJacob Faibussowitsch     PetscCall(PetscMalloc((*n) * sizeof(PetscScalar), &amsopt->data));
1582050cccc3SHong Zhang     vals = (PetscScalar *)amsopt->data;
1583050cccc3SHong Zhang     for (i = 0; i < *n; i++) vals[i] = value[i];
1584050cccc3SHong Zhang     amsopt->arraylength = *n;
1585050cccc3SHong Zhang   }
15869566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetScalarArray(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, n, set));
1587050cccc3SHong Zhang   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
15889566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%g+%gi", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, (double)PetscRealPart(value[0]), (double)PetscImaginaryPart(value[0])));
158948a46eb9SPierre Jolivet     for (i = 1; i < *n; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ",%g+%gi", (double)PetscRealPart(value[i]), (double)PetscImaginaryPart(value[i])));
15909566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ">: %s (%s)\n", text, ManSection(man)));
1591050cccc3SHong Zhang   }
1592050cccc3SHong Zhang   PetscFunctionReturn(0);
1593050cccc3SHong Zhang }
159453acd3b1SBarry Smith 
159588aa4217SBarry Smith /*MC
159653acd3b1SBarry Smith    PetscOptionsIntArray - Gets an array of integers for a particular
1597b32a342fSShri Abhyankar    option in the database.
159853acd3b1SBarry Smith 
1599811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
160053acd3b1SBarry Smith 
160188aa4217SBarry Smith    Synopsis:
160288aa4217SBarry Smith    #include "petscsys.h"
16033a89f35bSSatish Balay    PetscErrorCode PetscOptionsIntArray(const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscBool  *set)
160488aa4217SBarry Smith 
160553acd3b1SBarry Smith    Input Parameters:
160653acd3b1SBarry Smith +  opt - the option one is seeking
160753acd3b1SBarry Smith .  text - short string describing option
160853acd3b1SBarry Smith .  man - manual page for option
1609f8a50e2bSBarry Smith -  n - maximum number of values
161053acd3b1SBarry Smith 
1611d8d19677SJose E. Roman    Output Parameters:
161253acd3b1SBarry Smith +  value - location to copy values
1613f8a50e2bSBarry Smith .  n - actual number of values found
1614811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
161553acd3b1SBarry Smith 
161653acd3b1SBarry Smith    Level: beginner
161753acd3b1SBarry Smith 
161853acd3b1SBarry Smith    Notes:
1619b32a342fSShri Abhyankar    The array can be passed as
1620811af0c4SBarry Smith +   a comma separated list -                                  0,1,2,3,4,5,6,7
1621811af0c4SBarry Smith .   a range (start\-end+1) -                                  0-8
1622811af0c4SBarry Smith .   a range with given increment (start\-end+1:inc) -         0-7:2
1623811af0c4SBarry Smith -   a combination of values and ranges separated by commas -  0,1-8,8-15:2
1624b32a342fSShri Abhyankar 
1625b32a342fSShri Abhyankar    There must be no intervening spaces between the values.
162653acd3b1SBarry Smith 
1627811af0c4SBarry Smith    Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
162853acd3b1SBarry Smith 
1629db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1630db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1631db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1632c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1633db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1634db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`, `PetscOptionsRealArray()`
163588aa4217SBarry Smith M*/
163688aa4217SBarry Smith 
1637d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsIntArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscInt value[], PetscInt *n, PetscBool *set)
1638d71ae5a4SJacob Faibussowitsch {
163953acd3b1SBarry Smith   PetscInt        i;
16404416b707SBarry Smith   PetscOptionItem amsopt;
164153acd3b1SBarry Smith 
164253acd3b1SBarry Smith   PetscFunctionBegin;
1643e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1644e26ddf31SBarry Smith     PetscInt *vals;
1645e26ddf31SBarry Smith 
16469566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_INT_ARRAY, &amsopt));
16479566063dSJacob Faibussowitsch     PetscCall(PetscMalloc1(*n, (PetscInt **)&amsopt->data));
1648e26ddf31SBarry Smith     vals = (PetscInt *)amsopt->data;
1649e26ddf31SBarry Smith     for (i = 0; i < *n; i++) vals[i] = value[i];
1650e26ddf31SBarry Smith     amsopt->arraylength = *n;
1651e26ddf31SBarry Smith   }
16529566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetIntArray(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, n, set));
1653e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
16549566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%" PetscInt_FMT, PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, value[0]));
165548a46eb9SPierre Jolivet     for (i = 1; i < *n; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ",%" PetscInt_FMT, value[i]));
16569566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ">: %s (%s)\n", text, ManSection(man)));
165753acd3b1SBarry Smith   }
165853acd3b1SBarry Smith   PetscFunctionReturn(0);
165953acd3b1SBarry Smith }
166053acd3b1SBarry Smith 
166188aa4217SBarry Smith /*MC
166253acd3b1SBarry Smith    PetscOptionsStringArray - Gets an array of string values for a particular
166353acd3b1SBarry Smith    option in the database. The values must be separated with commas with
166453acd3b1SBarry Smith    no intervening spaces.
166553acd3b1SBarry Smith 
1666*cf53795eSBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`; No Fortran Support
166753acd3b1SBarry Smith 
166888aa4217SBarry Smith    Synopsis:
166988aa4217SBarry Smith    #include "petscsys.h"
16703a89f35bSSatish Balay    PetscErrorCode PetscOptionsStringArray(const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscBool  *set)
167188aa4217SBarry Smith 
167253acd3b1SBarry Smith    Input Parameters:
167353acd3b1SBarry Smith +  opt - the option one is seeking
167453acd3b1SBarry Smith .  text - short string describing option
167553acd3b1SBarry Smith .  man - manual page for option
167653acd3b1SBarry Smith -  nmax - maximum number of strings
167753acd3b1SBarry Smith 
1678d8d19677SJose E. Roman    Output Parameters:
167953acd3b1SBarry Smith +  value - location to copy strings
168053acd3b1SBarry Smith .  nmax - actual number of strings found
1681811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
168253acd3b1SBarry Smith 
168353acd3b1SBarry Smith    Level: beginner
168453acd3b1SBarry Smith 
168553acd3b1SBarry Smith    Notes:
168653acd3b1SBarry Smith    The user should pass in an array of pointers to char, to hold all the
168753acd3b1SBarry Smith    strings returned by this function.
168853acd3b1SBarry Smith 
168953acd3b1SBarry Smith    The user is responsible for deallocating the strings that are
1690*cf53795eSBarry Smith    returned.
169153acd3b1SBarry Smith 
1692811af0c4SBarry Smith    Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
169353acd3b1SBarry Smith 
1694db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1695db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1696db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1697c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1698db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1699db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
170088aa4217SBarry Smith M*/
170188aa4217SBarry Smith 
1702d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsStringArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], char *value[], PetscInt *nmax, PetscBool *set)
1703d71ae5a4SJacob Faibussowitsch {
17044416b707SBarry Smith   PetscOptionItem amsopt;
170553acd3b1SBarry Smith 
170653acd3b1SBarry Smith   PetscFunctionBegin;
1707e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
17089566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_STRING_ARRAY, &amsopt));
17099566063dSJacob Faibussowitsch     PetscCall(PetscMalloc1(*nmax, (char **)&amsopt->data));
1710a297a907SKarl Rupp 
17111ae3d29cSBarry Smith     amsopt->arraylength = *nmax;
17121ae3d29cSBarry Smith   }
17139566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetStringArray(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, nmax, set));
1714e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
17159566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <string1,string2,...>: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, text, ManSection(man)));
171653acd3b1SBarry Smith   }
171753acd3b1SBarry Smith   PetscFunctionReturn(0);
171853acd3b1SBarry Smith }
171953acd3b1SBarry Smith 
172088aa4217SBarry Smith /*MC
1721acfcf0e5SJed Brown    PetscOptionsBoolArray - Gets an array of logical values (true or false) for a particular
1722e2446a98SMatthew Knepley    option in the database. The values must be separated with commas with
1723e2446a98SMatthew Knepley    no intervening spaces.
1724e2446a98SMatthew Knepley 
1725811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
1726e2446a98SMatthew Knepley 
172788aa4217SBarry Smith    Synopsis:
172888aa4217SBarry Smith    #include "petscsys.h"
17293a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolArray(const char opt[],const char text[],const char man[],PetscBool value[],PetscInt *n,PetscBool *set)
173088aa4217SBarry Smith 
1731e2446a98SMatthew Knepley    Input Parameters:
1732e2446a98SMatthew Knepley +  opt - the option one is seeking
1733e2446a98SMatthew Knepley .  text - short string describing option
1734e2446a98SMatthew Knepley .  man - manual page for option
1735c89788bdSBarry Smith -  n - maximum number of values allowed in the value array
1736e2446a98SMatthew Knepley 
1737d8d19677SJose E. Roman    Output Parameters:
1738e2446a98SMatthew Knepley +  value - location to copy values
1739c89788bdSBarry Smith .  n - actual number of values found
1740811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
1741e2446a98SMatthew Knepley 
1742e2446a98SMatthew Knepley    Level: beginner
1743e2446a98SMatthew Knepley 
1744e2446a98SMatthew Knepley    Notes:
1745e2446a98SMatthew Knepley    The user should pass in an array of doubles
1746e2446a98SMatthew Knepley 
1747811af0c4SBarry Smith    Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
1748e2446a98SMatthew Knepley 
1749db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1750db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1751db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1752c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1753db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1754db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
175588aa4217SBarry Smith M*/
175688aa4217SBarry Smith 
1757d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsBoolArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool value[], PetscInt *n, PetscBool *set)
1758d71ae5a4SJacob Faibussowitsch {
1759e2446a98SMatthew Knepley   PetscInt        i;
17604416b707SBarry Smith   PetscOptionItem amsopt;
1761e2446a98SMatthew Knepley 
1762e2446a98SMatthew Knepley   PetscFunctionBegin;
1763e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1764ace3abfcSBarry Smith     PetscBool *vals;
17651ae3d29cSBarry Smith 
17669566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL_ARRAY, &amsopt));
17679566063dSJacob Faibussowitsch     PetscCall(PetscMalloc1(*n, (PetscBool **)&amsopt->data));
1768ace3abfcSBarry Smith     vals = (PetscBool *)amsopt->data;
17691ae3d29cSBarry Smith     for (i = 0; i < *n; i++) vals[i] = value[i];
17701ae3d29cSBarry Smith     amsopt->arraylength = *n;
17711ae3d29cSBarry Smith   }
17729566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetBoolArray(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, n, set));
1773e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
17749566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%d", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, value[0]));
177548a46eb9SPierre Jolivet     for (i = 1; i < *n; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ",%d", value[i]));
17769566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ">: %s (%s)\n", text, ManSection(man)));
1777e2446a98SMatthew Knepley   }
1778e2446a98SMatthew Knepley   PetscFunctionReturn(0);
1779e2446a98SMatthew Knepley }
1780e2446a98SMatthew Knepley 
178188aa4217SBarry Smith /*MC
1782d1da0b69SBarry Smith    PetscOptionsViewer - Gets a viewer appropriate for the type indicated by the user
17838cc676e6SMatthew G Knepley 
1784811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
17858cc676e6SMatthew G Knepley 
178688aa4217SBarry Smith    Synopsis:
178788aa4217SBarry Smith    #include "petscsys.h"
17883a89f35bSSatish Balay    PetscErrorCode PetscOptionsViewer(const char opt[],const char text[],const char man[],PetscViewer *viewer,PetscViewerFormat *format,PetscBool *set)
178988aa4217SBarry Smith 
17908cc676e6SMatthew G Knepley    Input Parameters:
17918cc676e6SMatthew G Knepley +  opt - option name
17928cc676e6SMatthew G Knepley .  text - short string that describes the option
17938cc676e6SMatthew G Knepley -  man - manual page with additional information on option
17948cc676e6SMatthew G Knepley 
1795d8d19677SJose E. Roman    Output Parameters:
17968cc676e6SMatthew G Knepley +  viewer - the viewer
17977962402dSFande Kong .  format - the PetscViewerFormat requested by the user, pass NULL if not needed
1798811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
17998cc676e6SMatthew G Knepley 
18008cc676e6SMatthew G Knepley    Level: beginner
18018cc676e6SMatthew G Knepley 
180295452b02SPatrick Sanan    Notes:
1803811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
18048cc676e6SMatthew G Knepley 
1805811af0c4SBarry Smith    See `PetscOptionsGetViewer()` for the format of the supplied viewer and its options
18068cc676e6SMatthew G Knepley 
1807db781477SPatrick Sanan .seealso: `PetscOptionsGetViewer()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
1808db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`
1809db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
1810db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1811c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1812db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1813db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
181488aa4217SBarry Smith M*/
181588aa4217SBarry Smith 
1816d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsViewer_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscViewer *viewer, PetscViewerFormat *format, PetscBool *set)
1817d71ae5a4SJacob Faibussowitsch {
18184416b707SBarry Smith   PetscOptionItem amsopt;
18198cc676e6SMatthew G Knepley 
18208cc676e6SMatthew G Knepley   PetscFunctionBegin;
18211a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
18229566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_STRING, &amsopt));
182364facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
18249566063dSJacob Faibussowitsch     PetscCall(PetscStrdup("", (char **)&amsopt->data));
18258cc676e6SMatthew G Knepley   }
18269566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetViewer(PetscOptionsObject->comm, PetscOptionsObject->options, PetscOptionsObject->prefix, opt, viewer, format, set));
1827e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
18289566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%s>: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, "", text, ManSection(man)));
18298cc676e6SMatthew G Knepley   }
18308cc676e6SMatthew G Knepley   PetscFunctionReturn(0);
18318cc676e6SMatthew G Knepley }
1832