xref: /petsc/src/sys/objects/aoptions.c (revision 30bab8dbce35fbb76248bd0fea1b2bc98f8a4f04)
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   }
433ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
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));
643ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
653194b578SJed Brown }
663194b578SJed Brown 
6753acd3b1SBarry Smith /*
6853acd3b1SBarry Smith      Handles adding another option to the list of options within this particular PetscOptionsBegin() PetscOptionsEnd()
6953acd3b1SBarry Smith */
703ba16761SJacob Faibussowitsch static PetscErrorCode 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   }
953ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
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));
1303ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
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");
147363da2dcSJacob Faibussowitsch     PetscCall(PetscArraycpy(tmp, s, len + 1));
1485b02f95dSBarry Smith   }
1495b02f95dSBarry Smith   *t = tmp;
1503ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
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   }
3433ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
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;
3543ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
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!!! */
392a364092eSJacob Faibussowitsch   PetscCall(PetscSNPrintf(options, PETSC_STATIC_ARRAY_LENGTH(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) {
404a364092eSJacob Faibussowitsch     PetscCall(PetscSNPrintf(manname, PETSC_STATIC_ARRAY_LENGTH(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));
407a364092eSJacob Faibussowitsch     PetscCall(PetscSNPrintf(textname, PETSC_STATIC_ARRAY_LENGTH(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"));
4913ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
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) {
524c6a7a370SJeremy L Thompson         PetscCall(PetscStrncpy(option, "-", sizeof(option)));
525c6a7a370SJeremy L Thompson         PetscCall(PetscStrlcat(option, PetscOptionsObject->prefix, sizeof(option)));
526c6a7a370SJeremy L Thompson         PetscCall(PetscStrlcat(option, PetscOptionsObject->next->option + 1, sizeof(option)));
527c6a7a370SJeremy L Thompson       } else PetscCall(PetscStrncpy(option, PetscOptionsObject->next->option, sizeof(option)));
5286356e834SBarry Smith 
529e55864a3SBarry Smith       switch (PetscOptionsObject->next->type) {
530d71ae5a4SJacob Faibussowitsch       case OPTION_HEAD:
531d71ae5a4SJacob Faibussowitsch         break;
5326356e834SBarry Smith       case OPTION_INT_ARRAY:
533a364092eSJacob Faibussowitsch         PetscCall(PetscSNPrintf(value, PETSC_STATIC_ARRAY_LENGTH(value), "%d", (int)((PetscInt *)PetscOptionsObject->next->data)[0]));
534e55864a3SBarry Smith         for (j = 1; j < PetscOptionsObject->next->arraylength; j++) {
535a364092eSJacob Faibussowitsch           PetscCall(PetscSNPrintf(tmp, PETSC_STATIC_ARRAY_LENGTH(tmp), "%d", (int)((PetscInt *)PetscOptionsObject->next->data)[j]));
536c6a7a370SJeremy L Thompson           PetscCall(PetscStrlcat(value, ",", sizeof(value)));
537c6a7a370SJeremy L Thompson           PetscCall(PetscStrlcat(value, tmp, sizeof(value)));
5386356e834SBarry Smith         }
5396356e834SBarry Smith         break;
540d71ae5a4SJacob Faibussowitsch       case OPTION_INT:
541a364092eSJacob Faibussowitsch         PetscCall(PetscSNPrintf(value, PETSC_STATIC_ARRAY_LENGTH(value), "%d", (int)*(PetscInt *)PetscOptionsObject->next->data));
542d71ae5a4SJacob Faibussowitsch         break;
543d71ae5a4SJacob Faibussowitsch       case OPTION_REAL:
544a364092eSJacob Faibussowitsch         PetscCall(PetscSNPrintf(value, PETSC_STATIC_ARRAY_LENGTH(value), "%g", (double)*(PetscReal *)PetscOptionsObject->next->data));
545d71ae5a4SJacob Faibussowitsch         break;
5466356e834SBarry Smith       case OPTION_REAL_ARRAY:
547a364092eSJacob Faibussowitsch         PetscCall(PetscSNPrintf(value, PETSC_STATIC_ARRAY_LENGTH(value), "%g", (double)((PetscReal *)PetscOptionsObject->next->data)[0]));
548e55864a3SBarry Smith         for (j = 1; j < PetscOptionsObject->next->arraylength; j++) {
549a364092eSJacob Faibussowitsch           PetscCall(PetscSNPrintf(tmp, PETSC_STATIC_ARRAY_LENGTH(tmp), "%g", (double)((PetscReal *)PetscOptionsObject->next->data)[j]));
550c6a7a370SJeremy L Thompson           PetscCall(PetscStrlcat(value, ",", sizeof(value)));
551c6a7a370SJeremy L Thompson           PetscCall(PetscStrlcat(value, tmp, sizeof(value)));
5526356e834SBarry Smith         }
5536356e834SBarry Smith         break;
554050cccc3SHong Zhang       case OPTION_SCALAR_ARRAY:
555a364092eSJacob Faibussowitsch         PetscCall(PetscSNPrintf(value, PETSC_STATIC_ARRAY_LENGTH(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++) {
557a364092eSJacob Faibussowitsch           PetscCall(PetscSNPrintf(tmp, PETSC_STATIC_ARRAY_LENGTH(tmp), "%g+%gi", (double)PetscRealPart(((PetscScalar *)PetscOptionsObject->next->data)[j]), (double)PetscImaginaryPart(((PetscScalar *)PetscOptionsObject->next->data)[j])));
558c6a7a370SJeremy L Thompson           PetscCall(PetscStrlcat(value, ",", sizeof(value)));
559c6a7a370SJeremy L Thompson           PetscCall(PetscStrlcat(value, tmp, sizeof(value)));
560050cccc3SHong Zhang         }
561050cccc3SHong Zhang         break;
562d71ae5a4SJacob Faibussowitsch       case OPTION_BOOL:
563a364092eSJacob Faibussowitsch         PetscCall(PetscSNPrintf(value, PETSC_STATIC_ARRAY_LENGTH(value), "%d", *(int *)PetscOptionsObject->next->data));
564d71ae5a4SJacob Faibussowitsch         break;
5657781c08eSBarry Smith       case OPTION_BOOL_ARRAY:
566a364092eSJacob Faibussowitsch         PetscCall(PetscSNPrintf(value, PETSC_STATIC_ARRAY_LENGTH(value), "%d", (int)((PetscBool *)PetscOptionsObject->next->data)[0]));
567e55864a3SBarry Smith         for (j = 1; j < PetscOptionsObject->next->arraylength; j++) {
568a364092eSJacob Faibussowitsch           PetscCall(PetscSNPrintf(tmp, PETSC_STATIC_ARRAY_LENGTH(tmp), "%d", (int)((PetscBool *)PetscOptionsObject->next->data)[j]));
569c6a7a370SJeremy L Thompson           PetscCall(PetscStrlcat(value, ",", sizeof(value)));
570c6a7a370SJeremy L Thompson           PetscCall(PetscStrlcat(value, tmp, sizeof(value)));
5711ae3d29cSBarry Smith         }
5721ae3d29cSBarry Smith         break;
573d71ae5a4SJacob Faibussowitsch       case OPTION_FLIST:
574c6a7a370SJeremy L Thompson         PetscCall(PetscStrncpy(value, (char *)PetscOptionsObject->next->data, sizeof(value)));
575d71ae5a4SJacob Faibussowitsch         break;
576d71ae5a4SJacob Faibussowitsch       case OPTION_ELIST:
577c6a7a370SJeremy L Thompson         PetscCall(PetscStrncpy(value, (char *)PetscOptionsObject->next->data, sizeof(value)));
578d71ae5a4SJacob Faibussowitsch         break;
579d71ae5a4SJacob Faibussowitsch       case OPTION_STRING:
580c6a7a370SJeremy L Thompson         PetscCall(PetscStrncpy(value, (char *)PetscOptionsObject->next->data, sizeof(value)));
581d71ae5a4SJacob Faibussowitsch         break;
5821ae3d29cSBarry Smith       case OPTION_STRING_ARRAY:
583a364092eSJacob Faibussowitsch         PetscCall(PetscSNPrintf(value, PETSC_STATIC_ARRAY_LENGTH(value), "%s", ((char **)PetscOptionsObject->next->data)[0]));
584e55864a3SBarry Smith         for (j = 1; j < PetscOptionsObject->next->arraylength; j++) {
585a364092eSJacob Faibussowitsch           PetscCall(PetscSNPrintf(tmp, PETSC_STATIC_ARRAY_LENGTH(tmp), "%s", ((char **)PetscOptionsObject->next->data)[j]));
586c6a7a370SJeremy L Thompson           PetscCall(PetscStrlcat(value, ",", sizeof(value)));
587c6a7a370SJeremy L Thompson           PetscCall(PetscStrlcat(value, tmp, sizeof(value)));
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;
6113ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
61253acd3b1SBarry Smith }
61353acd3b1SBarry Smith 
61488aa4217SBarry Smith /*MC
61553acd3b1SBarry Smith    PetscOptionsEnum - Gets the enum value for a particular option in the database.
61653acd3b1SBarry Smith 
61788aa4217SBarry Smith    Synopsis:
61888aa4217SBarry Smith    #include "petscsys.h"
6193a89f35bSSatish Balay    PetscErrorCode  PetscOptionsEnum(const char opt[],const char text[],const char man[],const char *const *list,PetscEnum currentvalue,PetscEnum *value,PetscBool  *set)
62088aa4217SBarry Smith 
6217cdbe19fSJose E. Roman    Logically Collective on the communicator passed in `PetscOptionsBegin()`
6227cdbe19fSJose E. Roman 
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
6292fe279fdSBarry Smith .vb
6302fe279fdSBarry Smith                  PetscOptionsEnum(..., obj->value,&object->value,...) or
6312fe279fdSBarry Smith                  value = defaultvalue
6322fe279fdSBarry Smith                  PetscOptionsEnum(..., value,&value,&flg);
6332fe279fdSBarry Smith                  if (flg) {
6342fe279fdSBarry Smith .ve
63553acd3b1SBarry Smith 
636d8d19677SJose E. Roman    Output Parameters:
63753acd3b1SBarry Smith +  value - the  value to return
638811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
63953acd3b1SBarry Smith 
64053acd3b1SBarry Smith    Level: beginner
64153acd3b1SBarry Smith 
64295452b02SPatrick Sanan    Notes:
643811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
64453acd3b1SBarry Smith 
645811af0c4SBarry Smith           list is usually something like `PCASMTypes` or some other predefined list of enum names
64653acd3b1SBarry Smith 
647*30bab8dbSBarry Smith           If the user does not supply the option at all `value` is NOT changed. Thus
648*30bab8dbSBarry Smith           you should ALWAYS initialize `value` if you access it without first checking if `set` is `PETSC_TRUE`.
6492efd9cb1SBarry Smith 
650*30bab8dbSBarry Smith           The `currentvalue` passed into this routine does not get transferred to the output `value` variable automatically.
651989712b9SBarry Smith 
652db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
653db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
654db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
655db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
656c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
657db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
658db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
65988aa4217SBarry Smith M*/
66088aa4217SBarry Smith 
661d71ae5a4SJacob 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)
662d71ae5a4SJacob Faibussowitsch {
66353acd3b1SBarry Smith   PetscInt  ntext = 0;
664aa5bb8c0SSatish Balay   PetscInt  tval;
665ace3abfcSBarry Smith   PetscBool tflg;
66653acd3b1SBarry Smith 
66753acd3b1SBarry Smith   PetscFunctionBegin;
668ad540459SPierre 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");
66908401ef6SPierre Jolivet   PetscCheck(ntext >= 3, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "List argument must have at least two entries: typename and type prefix");
67053acd3b1SBarry Smith   ntext -= 3;
6719566063dSJacob Faibussowitsch   PetscCall(PetscOptionsEList_Private(PetscOptionsObject, opt, text, man, list, ntext, list[currentvalue], &tval, &tflg));
672aa5bb8c0SSatish Balay   /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */
673aa5bb8c0SSatish Balay   if (tflg) *value = (PetscEnum)tval;
674aa5bb8c0SSatish Balay   if (set) *set = tflg;
6753ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
67653acd3b1SBarry Smith }
67753acd3b1SBarry Smith 
67888aa4217SBarry Smith /*MC
679d3e47460SLisandro Dalcin    PetscOptionsEnumArray - Gets an array of enum values for a particular
680d3e47460SLisandro Dalcin    option in the database.
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 
6867cdbe19fSJose E. Roman    Logically Collective on the communicator passed in `PetscOptionsBegin()`
6877cdbe19fSJose E. Roman 
688d3e47460SLisandro Dalcin    Input Parameters:
689d3e47460SLisandro Dalcin +  opt - the option one is seeking
690d3e47460SLisandro Dalcin .  text - short string describing option
691d3e47460SLisandro Dalcin .  man - manual page for option
69222d58ec6SMatthew G. Knepley .  list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null
693c89788bdSBarry Smith -  n - maximum number of values allowed in the value array
694d3e47460SLisandro Dalcin 
695d8d19677SJose E. Roman    Output Parameters:
696d3e47460SLisandro Dalcin +  value - location to copy values
697d3e47460SLisandro Dalcin .  n - actual number of values found
698811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
699d3e47460SLisandro Dalcin 
700d3e47460SLisandro Dalcin    Level: beginner
701d3e47460SLisandro Dalcin 
702d3e47460SLisandro Dalcin    Notes:
703d3e47460SLisandro Dalcin    The array must be passed as a comma separated list.
704d3e47460SLisandro Dalcin 
705d3e47460SLisandro Dalcin    There must be no intervening spaces between the values.
706d3e47460SLisandro Dalcin 
707811af0c4SBarry Smith    Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
708d3e47460SLisandro Dalcin 
709db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
710db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
711db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
712c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
713db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
714db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`, `PetscOptionsRealArray()`
71588aa4217SBarry Smith M*/
71688aa4217SBarry Smith 
717d71ae5a4SJacob 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)
718d71ae5a4SJacob Faibussowitsch {
719d3e47460SLisandro Dalcin   PetscInt        i, nlist = 0;
7204416b707SBarry Smith   PetscOptionItem amsopt;
721d3e47460SLisandro Dalcin 
722d3e47460SLisandro Dalcin   PetscFunctionBegin;
72308401ef6SPierre 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");
72408401ef6SPierre Jolivet   PetscCheck(nlist >= 3, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "List argument must have at least two entries: typename and type prefix");
725d3e47460SLisandro Dalcin   nlist -= 3;                            /* drop enum name, prefix, and null termination */
726d3e47460SLisandro Dalcin   if (0 && !PetscOptionsObject->count) { /* XXX Requires additional support */
727d3e47460SLisandro Dalcin     PetscEnum *vals;
7289566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_INT_ARRAY /*XXX OPTION_ENUM_ARRAY*/, &amsopt));
7299566063dSJacob Faibussowitsch     PetscCall(PetscStrNArrayallocpy(nlist, list, (char ***)&amsopt->list));
730d3e47460SLisandro Dalcin     amsopt->nlist = nlist;
7319566063dSJacob Faibussowitsch     PetscCall(PetscMalloc1(*n, (PetscEnum **)&amsopt->data));
732d3e47460SLisandro Dalcin     amsopt->arraylength = *n;
733d3e47460SLisandro Dalcin     vals                = (PetscEnum *)amsopt->data;
734d3e47460SLisandro Dalcin     for (i = 0; i < *n; i++) vals[i] = value[i];
735d3e47460SLisandro Dalcin   }
7369566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetEnumArray(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, list, value, n, set));
737d3e47460SLisandro Dalcin   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
7389566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%s", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, list[value[0]]));
7399566063dSJacob Faibussowitsch     for (i = 1; i < *n; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ",%s", list[value[i]]));
7409566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ">: %s (choose from)", text));
7419566063dSJacob Faibussowitsch     for (i = 0; i < nlist; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, " %s", list[i]));
7429566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, " (%s)\n", ManSection(man)));
743d3e47460SLisandro Dalcin   }
7443ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
745d3e47460SLisandro Dalcin }
746d3e47460SLisandro Dalcin 
74788aa4217SBarry Smith /*MC
7485a856986SBarry Smith    PetscOptionsBoundedInt - Gets an integer value greater than or equal a given bound for a particular option in the database.
7495a856986SBarry Smith 
75088aa4217SBarry Smith    Synopsis:
75188aa4217SBarry Smith    #include "petscsys.h"
75269d47153SPierre Jolivet    PetscErrorCode  PetscOptionsBoundedInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg,PetscInt bound)
75388aa4217SBarry Smith 
7547cdbe19fSJose E. Roman    Logically Collective on the communicator passed in `PetscOptionsBegin()`
7557cdbe19fSJose E. Roman 
7565a856986SBarry Smith    Input Parameters:
7575a856986SBarry Smith +  opt - option name
7585a856986SBarry Smith .  text - short string that describes the option
7595a856986SBarry Smith .  man - manual page with additional information on option
7605a856986SBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
76169d47153SPierre Jolivet .vb
76269d47153SPierre Jolivet   PetscOptionsInt(..., obj->value,&obj->value,...)
76369d47153SPierre Jolivet .ve
76469d47153SPierre Jolivet or
76569d47153SPierre Jolivet .vb
76669d47153SPierre Jolivet   value = defaultvalue
76769d47153SPierre Jolivet   PetscOptionsInt(..., value,&value,&flg);
76869d47153SPierre Jolivet   if (flg) {
76969d47153SPierre Jolivet .ve
77088aa4217SBarry Smith -  bound - the requested value should be greater than or equal this bound or an error is generated
7715a856986SBarry Smith 
772d8d19677SJose E. Roman    Output Parameters:
7735a856986SBarry Smith +  value - the integer value to return
774811af0c4SBarry Smith -  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
7755a856986SBarry Smith 
7762fe279fdSBarry Smith    Level: beginner
7772fe279fdSBarry Smith 
7785a856986SBarry Smith    Notes:
779*30bab8dbSBarry Smith     If the user does not supply the option at all `value` is NOT changed. Thus
780*30bab8dbSBarry Smith     you should ALWAYS initialize `value` if you access it without first checking if `flg` is `PETSC_TRUE`.
7815a856986SBarry Smith 
782*30bab8dbSBarry Smith     The `currentvalue` passed into this routine does not get transferred to the output `value` variable automatically.
7835a856986SBarry Smith 
784811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
7855a856986SBarry Smith 
786db781477SPatrick Sanan .seealso: `PetscOptionsInt()`, `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
787db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`, `PetscOptionsRangeInt()`
788db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
789db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
790c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
791db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
792db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
79388aa4217SBarry Smith M*/
7945a856986SBarry Smith 
79588aa4217SBarry Smith /*MC
7965a856986SBarry Smith    PetscOptionsRangeInt - Gets an integer value within a range of values for a particular option in the database.
7975a856986SBarry Smith 
79888aa4217SBarry Smith    Synopsis:
79988aa4217SBarry Smith    #include "petscsys.h"
8003a89f35bSSatish Balay    PetscErrorCode  PetscOptionsRangeInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg,PetscInt lb,PetscInt ub)
80188aa4217SBarry Smith 
8027cdbe19fSJose E. Roman    Logically Collective on the communicator passed in `PetscOptionsBegin()`
8037cdbe19fSJose E. Roman 
8045a856986SBarry Smith    Input Parameters:
8055a856986SBarry Smith +  opt - option name
8065a856986SBarry Smith .  text - short string that describes the option
8075a856986SBarry Smith .  man - manual page with additional information on option
8085a856986SBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
8092fe279fdSBarry Smith .vb
8102fe279fdSBarry Smith                  PetscOptionsInt(..., obj->value,&obj->value,...) or
8112fe279fdSBarry Smith                  value = defaultvalue
8122fe279fdSBarry Smith                  PetscOptionsInt(..., value,&value,&flg);
8132fe279fdSBarry Smith                  if (flg) {
8142fe279fdSBarry Smith .ve
81588aa4217SBarry Smith .  lb - the lower bound, provided value must be greater than or equal to this value or an error is generated
81688aa4217SBarry Smith -  ub - the upper bound, provided value must be less than or equal to this value or an error is generated
8175a856986SBarry Smith 
818d8d19677SJose E. Roman    Output Parameters:
8195a856986SBarry Smith +  value - the integer value to return
820811af0c4SBarry Smith -  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
8215a856986SBarry Smith 
8222fe279fdSBarry Smith    Level: beginner
8232fe279fdSBarry Smith 
8245a856986SBarry Smith    Notes:
825*30bab8dbSBarry Smith     If the user does not supply the option at all `value` is NOT changed. Thus
826*30bab8dbSBarry Smith     you should ALWAYS initialize `value` if you access it without first checking if `flg` is `PETSC_TRUE`.
8275a856986SBarry Smith 
828*30bab8dbSBarry Smith     The `currentvalue` passed into this routine does not get transferred to the output `value` variable automatically.
8295a856986SBarry Smith 
830811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
8315a856986SBarry Smith 
832db781477SPatrick Sanan .seealso: `PetscOptionsInt()`, `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
833db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`, `PetscOptionsBoundedInt()`
834db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
835db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
836c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
837db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
838db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
83988aa4217SBarry Smith M*/
8405a856986SBarry Smith 
84188aa4217SBarry Smith /*MC
84253acd3b1SBarry Smith    PetscOptionsInt - Gets the integer value for a particular option in the database.
84353acd3b1SBarry Smith 
84488aa4217SBarry Smith    Synopsis:
84588aa4217SBarry Smith    #include "petscsys.h"
8466eeb591dSVaclav Hapla    PetscErrorCode  PetscOptionsInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg))
84788aa4217SBarry Smith 
8487cdbe19fSJose E. Roman    Logically Collective on the communicator passed in `PetscOptionsBegin()`
8497cdbe19fSJose E. Roman 
85053acd3b1SBarry Smith    Input Parameters:
85153acd3b1SBarry Smith +  opt - option name
85253acd3b1SBarry Smith .  text - short string that describes the option
85353acd3b1SBarry Smith .  man - manual page with additional information on option
8540fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
8552fe279fdSBarry Smith .vb
8562fe279fdSBarry Smith                  PetscOptionsInt(..., obj->value,&obj->value,...) or
8572fe279fdSBarry Smith                  value = defaultvalue
8582fe279fdSBarry Smith                  PetscOptionsInt(..., value,&value,&flg);
8592fe279fdSBarry Smith                  if (flg) {
8602fe279fdSBarry Smith .ve
86153acd3b1SBarry Smith 
862d8d19677SJose E. Roman    Output Parameters:
86353acd3b1SBarry Smith +  value - the integer value to return
864811af0c4SBarry Smith -  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
86553acd3b1SBarry Smith 
866*30bab8dbSBarry Smith    Level: beginner
8672efd9cb1SBarry Smith 
868*30bab8dbSBarry Smith    Notes:
869*30bab8dbSBarry Smith     If the user does not supply the option at all `value` is NOT changed. Thus
870*30bab8dbSBarry Smith     you should ALWAYS initialize `value` if you access it without first checking if `flg` is `PETSC_TRUE`.
871*30bab8dbSBarry Smith 
872*30bab8dbSBarry Smith     The `currentvalue` passed into this routine does not get transferred to the output `value` variable automatically.
873989712b9SBarry Smith 
874811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
87553acd3b1SBarry Smith 
876db781477SPatrick Sanan .seealso: `PetscOptionsBoundedInt()`, `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
877db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`, `PetscOptionsRangeInt()`
878db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
879db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
880c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
881db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
882db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
88388aa4217SBarry Smith M*/
88488aa4217SBarry Smith 
885d71ae5a4SJacob 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)
886d71ae5a4SJacob Faibussowitsch {
8874416b707SBarry Smith   PetscOptionItem amsopt;
88812655325SBarry Smith   PetscBool       wasset;
88953acd3b1SBarry Smith 
89053acd3b1SBarry Smith   PetscFunctionBegin;
89108401ef6SPierre Jolivet   PetscCheck(currentvalue >= lb, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Current value %" PetscInt_FMT " less than allowed bound %" PetscInt_FMT, currentvalue, lb);
89208401ef6SPierre Jolivet   PetscCheck(currentvalue <= ub, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Current value %" PetscInt_FMT " greater than allowed bound %" PetscInt_FMT, currentvalue, ub);
893e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
8949566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_INT, &amsopt));
8959566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscInt), &amsopt->data));
89612655325SBarry Smith     *(PetscInt *)amsopt->data = currentvalue;
8973e211508SBarry Smith 
8989566063dSJacob Faibussowitsch     PetscCall(PetscOptionsGetInt(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, &currentvalue, &wasset));
899ad540459SPierre Jolivet     if (wasset) *(PetscInt *)amsopt->data = currentvalue;
900af6d86caSBarry Smith   }
9019566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetInt(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, &wasset));
902cc73adaaSBarry 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);
903cc73adaaSBarry 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);
90444ef3d73SBarry Smith   if (set) *set = wasset;
905e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
9069566063dSJacob 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)));
90753acd3b1SBarry Smith   }
9083ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
90953acd3b1SBarry Smith }
91053acd3b1SBarry Smith 
91188aa4217SBarry Smith /*MC
91253acd3b1SBarry Smith    PetscOptionsString - Gets the string value for a particular option in the database.
91353acd3b1SBarry Smith 
91488aa4217SBarry Smith    Synopsis:
91588aa4217SBarry Smith    #include "petscsys.h"
9163a89f35bSSatish Balay    PetscErrorCode  PetscOptionsString(const char opt[],const char text[],const char man[],const char currentvalue[],char value[],size_t len,PetscBool  *set)
91788aa4217SBarry Smith 
9187cdbe19fSJose E. Roman    Logically Collective on the communicator passed in `PetscOptionsBegin()`
9197cdbe19fSJose E. Roman 
92053acd3b1SBarry Smith    Input Parameters:
92153acd3b1SBarry Smith +  opt - option name
92253acd3b1SBarry Smith .  text - short string that describes the option
92353acd3b1SBarry Smith .  man - manual page with additional information on option
9240fdccdaeSBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. This is not used to set value
925bcbf2dc5SJed Brown -  len - length of the result string including null terminator
92653acd3b1SBarry Smith 
927d8d19677SJose E. Roman    Output Parameters:
92853acd3b1SBarry Smith +  value - the value to return
929811af0c4SBarry Smith -  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
93053acd3b1SBarry Smith 
93153acd3b1SBarry Smith    Level: beginner
93253acd3b1SBarry Smith 
93395452b02SPatrick Sanan    Notes:
934811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
93553acd3b1SBarry Smith 
936*30bab8dbSBarry Smith    If the user provided no string (for example `-optionname` `-someotheroption`) `flg` is set to `PETSC_TRUE` (and the string is filled with nulls).
9377fccdfe4SBarry Smith 
938*30bab8dbSBarry Smith           If the user does not supply the option at all `value` is NOT changed. Thus
939*30bab8dbSBarry Smith           you should ALWAYS initialize `value` if you access it without first checking if `flg` is `PETSC_TRUE`.
9402efd9cb1SBarry Smith 
941*30bab8dbSBarry Smith           The `currentvalue` passed into this routine does not get transferred to the output `value` variable automatically.
942989712b9SBarry Smith 
943db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
944db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
945db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
946db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
947c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
948db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
949db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
95088aa4217SBarry Smith M*/
95188aa4217SBarry Smith 
952d71ae5a4SJacob 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)
953d71ae5a4SJacob Faibussowitsch {
9544416b707SBarry Smith   PetscOptionItem amsopt;
95544ef3d73SBarry Smith   PetscBool       lset;
95653acd3b1SBarry Smith 
95753acd3b1SBarry Smith   PetscFunctionBegin;
9581a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
9599566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_STRING, &amsopt));
96064facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
9619566063dSJacob Faibussowitsch     PetscCall(PetscStrdup(currentvalue ? currentvalue : "", (char **)&amsopt->data));
962af6d86caSBarry Smith   }
9639566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetString(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, len, &lset));
96444ef3d73SBarry Smith   if (set) *set = lset;
965e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
9669566063dSJacob 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)));
96753acd3b1SBarry Smith   }
9683ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
96953acd3b1SBarry Smith }
97053acd3b1SBarry Smith 
97188aa4217SBarry Smith /*MC
972811af0c4SBarry Smith    PetscOptionsReal - Gets the `PetscReal` value for a particular option in the database.
97353acd3b1SBarry Smith 
97488aa4217SBarry Smith    Synopsis:
97588aa4217SBarry Smith    #include "petscsys.h"
9763a89f35bSSatish Balay    PetscErrorCode  PetscOptionsReal(const char opt[],const char text[],const char man[],PetscReal currentvalue,PetscReal *value,PetscBool  *set)
97788aa4217SBarry Smith 
9787cdbe19fSJose E. Roman    Logically Collective on the communicator passed in `PetscOptionsBegin()`
9797cdbe19fSJose E. Roman 
98053acd3b1SBarry Smith    Input Parameters:
98153acd3b1SBarry Smith +  opt - option name
98253acd3b1SBarry Smith .  text - short string that describes the option
98353acd3b1SBarry Smith .  man - manual page with additional information on option
9840fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
9852fe279fdSBarry Smith .vb
9862fe279fdSBarry Smith                  PetscOptionsReal(..., obj->value,&obj->value,...) or
9872fe279fdSBarry Smith                  value = defaultvalue
9882fe279fdSBarry Smith                  PetscOptionsReal(..., value,&value,&flg);
9892fe279fdSBarry Smith                  if (flg) {
9902fe279fdSBarry Smith .ve
99153acd3b1SBarry Smith 
992d8d19677SJose E. Roman    Output Parameters:
99353acd3b1SBarry Smith +  value - the value to return
994811af0c4SBarry Smith -  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
99553acd3b1SBarry Smith 
996*30bab8dbSBarry Smith    Level: beginner
9972efd9cb1SBarry Smith 
998*30bab8dbSBarry Smith    Notes:
999*30bab8dbSBarry Smith     If the user does not supply the option at all `value` is NOT changed. Thus
1000*30bab8dbSBarry Smith     you should ALWAYS initialize `value` if you access it without first checking if `flg` is `PETSC_TRUE`.
1001*30bab8dbSBarry Smith 
1002*30bab8dbSBarry Smith     The `currentvalue` passed into this routine does not get transferred to the output `value` variable automatically.
1003989712b9SBarry Smith 
1004811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
100553acd3b1SBarry Smith 
1006db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
1007db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
1008db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
1009db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1010c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1011db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1012db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
101388aa4217SBarry Smith M*/
101488aa4217SBarry Smith 
1015d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsReal_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscReal currentvalue, PetscReal *value, PetscBool *set)
1016d71ae5a4SJacob Faibussowitsch {
10174416b707SBarry Smith   PetscOptionItem amsopt;
101844ef3d73SBarry Smith   PetscBool       lset;
101953acd3b1SBarry Smith 
102053acd3b1SBarry Smith   PetscFunctionBegin;
1021e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
10229566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_REAL, &amsopt));
10239566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscReal), &amsopt->data));
1024a297a907SKarl Rupp 
10250fdccdaeSBarry Smith     *(PetscReal *)amsopt->data = currentvalue;
1026538aa990SBarry Smith   }
10279566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetReal(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, &lset));
102844ef3d73SBarry Smith   if (set) *set = lset;
10291a1499c8SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
10309566063dSJacob 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)));
103153acd3b1SBarry Smith   }
10323ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
103353acd3b1SBarry Smith }
103453acd3b1SBarry Smith 
103588aa4217SBarry Smith /*MC
1036811af0c4SBarry Smith    PetscOptionsScalar - Gets the `PetscScalar` value for a particular option in the database.
103753acd3b1SBarry Smith 
103888aa4217SBarry Smith    Synopsis:
103988aa4217SBarry Smith    #include "petscsys.h"
10403a89f35bSSatish Balay    PetscErrorCode PetscOptionsScalar(const char opt[],const char text[],const char man[],PetscScalar currentvalue,PetscScalar *value,PetscBool  *set)
104188aa4217SBarry Smith 
10427cdbe19fSJose E. Roman    Logically Collective on the communicator passed in `PetscOptionsBegin()`
10437cdbe19fSJose E. Roman 
104453acd3b1SBarry Smith    Input Parameters:
104553acd3b1SBarry Smith +  opt - option name
104653acd3b1SBarry Smith .  text - short string that describes the option
104753acd3b1SBarry Smith .  man - manual page with additional information on option
10480fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
10492fe279fdSBarry Smith .vb
10502fe279fdSBarry Smith                  PetscOptionsScalar(..., obj->value,&obj->value,...) or
10512fe279fdSBarry Smith                  value = defaultvalue
10522fe279fdSBarry Smith                  PetscOptionsScalar(..., value,&value,&flg);
10532fe279fdSBarry Smith                  if (flg) {
10542fe279fdSBarry Smith .ve
10550fdccdaeSBarry Smith 
1056d8d19677SJose E. Roman    Output Parameters:
105753acd3b1SBarry Smith +  value - the value to return
1058811af0c4SBarry Smith -  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
105953acd3b1SBarry Smith 
1060*30bab8dbSBarry Smith    Level: beginner
10612efd9cb1SBarry Smith 
1062*30bab8dbSBarry Smith    Notes:
1063*30bab8dbSBarry Smith     If the user does not supply the option at all `value` is NOT changed. Thus
1064*30bab8dbSBarry Smith     you should ALWAYS initialize `value` if you access it without first checking if `flg` is `PETSC_TRUE`.
1065*30bab8dbSBarry Smith 
1066*30bab8dbSBarry Smith     The `currentvalue` passed into this routine does not get transferred to the output `value` variable automatically.
1067989712b9SBarry Smith 
1068811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
106953acd3b1SBarry Smith 
1070db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
1071db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
1072db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
1073db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1074c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1075db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1076db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
107788aa4217SBarry Smith M*/
107888aa4217SBarry Smith 
1079d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsScalar_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscScalar currentvalue, PetscScalar *value, PetscBool *set)
1080d71ae5a4SJacob Faibussowitsch {
108153acd3b1SBarry Smith   PetscFunctionBegin;
108253acd3b1SBarry Smith #if !defined(PETSC_USE_COMPLEX)
10839566063dSJacob Faibussowitsch   PetscCall(PetscOptionsReal(opt, text, man, currentvalue, value, set));
108453acd3b1SBarry Smith #else
10859566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetScalar(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, set));
108653acd3b1SBarry Smith #endif
10873ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
108853acd3b1SBarry Smith }
108953acd3b1SBarry Smith 
109088aa4217SBarry Smith /*MC
109190d69ab7SBarry 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
109290d69ab7SBarry Smith                       its value is set to false.
109353acd3b1SBarry Smith 
109488aa4217SBarry Smith    Synopsis:
109588aa4217SBarry Smith    #include "petscsys.h"
10963a89f35bSSatish Balay    PetscErrorCode PetscOptionsName(const char opt[],const char text[],const char man[],PetscBool  *flg)
109788aa4217SBarry Smith 
10987cdbe19fSJose E. Roman    Logically Collective on the communicator passed in `PetscOptionsBegin()`
10997cdbe19fSJose E. Roman 
110053acd3b1SBarry Smith    Input Parameters:
110153acd3b1SBarry Smith +  opt - option name
110253acd3b1SBarry Smith .  text - short string that describes the option
110353acd3b1SBarry Smith -  man - manual page with additional information on option
110453acd3b1SBarry Smith 
110553acd3b1SBarry Smith    Output Parameter:
1106811af0c4SBarry Smith .  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
110753acd3b1SBarry Smith 
110853acd3b1SBarry Smith    Level: beginner
110953acd3b1SBarry Smith 
1110811af0c4SBarry Smith    Note:
1111811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
111253acd3b1SBarry Smith 
1113db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
1114db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
1115db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
1116db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1117c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1118db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1119db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
112088aa4217SBarry Smith M*/
112188aa4217SBarry Smith 
1122d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsName_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool *flg)
1123d71ae5a4SJacob Faibussowitsch {
11244416b707SBarry Smith   PetscOptionItem amsopt;
112553acd3b1SBarry Smith 
112653acd3b1SBarry Smith   PetscFunctionBegin;
1127e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
11289566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt));
11299566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data));
1130a297a907SKarl Rupp 
1131ace3abfcSBarry Smith     *(PetscBool *)amsopt->data = PETSC_FALSE;
11321ae3d29cSBarry Smith   }
11339566063dSJacob Faibussowitsch   PetscCall(PetscOptionsHasName(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, flg));
1134e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
11359566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, text, ManSection(man)));
113653acd3b1SBarry Smith   }
11373ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
113853acd3b1SBarry Smith }
113953acd3b1SBarry Smith 
114088aa4217SBarry Smith /*MC
1141a264d7a6SBarry Smith      PetscOptionsFList - Puts a list of option values that a single one may be selected from
114253acd3b1SBarry Smith 
114388aa4217SBarry Smith    Synopsis:
114488aa4217SBarry Smith    #include "petscsys.h"
11453a89f35bSSatish Balay    PetscErrorCode  PetscOptionsFList(const char opt[],const char ltext[],const char man[],PetscFunctionList list,const char currentvalue[],char value[],size_t len,PetscBool  *set)
114688aa4217SBarry Smith 
11477cdbe19fSJose E. Roman    Logically Collective on the communicator passed in `PetscOptionsBegin()`
11487cdbe19fSJose E. Roman 
114953acd3b1SBarry Smith    Input Parameters:
115053acd3b1SBarry Smith +  opt - option name
115153acd3b1SBarry Smith .  text - short string that describes the option
115253acd3b1SBarry Smith .  man - manual page with additional information on option
115353acd3b1SBarry Smith .  list - the possible choices
11540fdccdaeSBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with
11552fe279fdSBarry Smith .vb
11562fe279fdSBarry Smith                  PetscOptionsFlist(..., obj->value,value,len,&flg);
11572fe279fdSBarry Smith                  if (flg) {
11582fe279fdSBarry Smith .ve
11593cc1e11dSBarry Smith -  len - the length of the character array value
116053acd3b1SBarry Smith 
1161d8d19677SJose E. Roman    Output Parameters:
116253acd3b1SBarry Smith +  value - the value to return
1163811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
116453acd3b1SBarry Smith 
116553acd3b1SBarry Smith    Level: intermediate
116653acd3b1SBarry Smith 
116795452b02SPatrick Sanan    Notes:
1168811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
116953acd3b1SBarry Smith 
1170*30bab8dbSBarry Smith           If the user does not supply the option at all `value` is NOT changed. Thus
1171*30bab8dbSBarry Smith           you should ALWAYS initialize `value` if you access it without first checking if the `set` flag is `PETSC_TRUE`.
11722efd9cb1SBarry Smith 
1173*30bab8dbSBarry Smith           The `currentvalue` passed into this routine does not get transferred to the output `value` variable automatically.
1174989712b9SBarry Smith 
1175811af0c4SBarry Smith    See `PetscOptionsEList()` for when the choices are given in a string array
117653acd3b1SBarry Smith 
117753acd3b1SBarry Smith    To get a listing of all currently specified options,
1178811af0c4SBarry Smith     see `PetscOptionsView()` or `PetscOptionsGetAll()`
117953acd3b1SBarry Smith 
1180811af0c4SBarry Smith    Developer Note:
1181811af0c4SBarry Smith    This cannot check for invalid selection because of things like `MATAIJ` that are not included in the list
1182eabe10d7SBarry Smith 
1183db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1184db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1185db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1186c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1187db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1188db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`, `PetscOptionsEnum()`
118988aa4217SBarry Smith M*/
119088aa4217SBarry Smith 
1191d71ae5a4SJacob 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)
1192d71ae5a4SJacob Faibussowitsch {
11934416b707SBarry Smith   PetscOptionItem amsopt;
119444ef3d73SBarry Smith   PetscBool       lset;
119553acd3b1SBarry Smith 
119653acd3b1SBarry Smith   PetscFunctionBegin;
11971a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
11989566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, ltext, man, OPTION_FLIST, &amsopt));
119964facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
12009566063dSJacob Faibussowitsch     PetscCall(PetscStrdup(currentvalue ? currentvalue : "", (char **)&amsopt->data));
12013cc1e11dSBarry Smith     amsopt->flist = list;
12023cc1e11dSBarry Smith   }
12039566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetString(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, len, &lset));
120444ef3d73SBarry Smith   if (set) *set = lset;
12051a1499c8SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
12069566063dSJacob Faibussowitsch     PetscCall(PetscFunctionListPrintTypes(PetscOptionsObject->comm, stdout, PetscOptionsObject->prefix, opt, ltext, man, list, currentvalue, lset && value ? value : currentvalue));
120753acd3b1SBarry Smith   }
12083ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
120953acd3b1SBarry Smith }
121053acd3b1SBarry Smith 
121188aa4217SBarry Smith /*MC
121253acd3b1SBarry Smith      PetscOptionsEList - Puts a list of option values that a single one may be selected from
121353acd3b1SBarry Smith 
121488aa4217SBarry Smith    Synopsis:
121588aa4217SBarry Smith    #include "petscsys.h"
12163a89f35bSSatish 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)
121788aa4217SBarry Smith 
12187cdbe19fSJose E. Roman    Logically Collective on the communicator passed in `PetscOptionsBegin()`
12197cdbe19fSJose E. Roman 
122053acd3b1SBarry Smith    Input Parameters:
122153acd3b1SBarry Smith +  opt - option name
122253acd3b1SBarry Smith .  ltext - short string that describes the option
122353acd3b1SBarry Smith .  man - manual page with additional information on option
1224a264d7a6SBarry Smith .  list - the possible choices (one of these must be selected, anything else is invalid)
122553acd3b1SBarry Smith .  ntext - number of choices
12260fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with
12272fe279fdSBarry Smith .vb
12282fe279fdSBarry Smith                  PetscOptionsEList(..., obj->value,&value,&flg);
12292fe279fdSBarry Smith .ve                 if (flg) {
12300fdccdaeSBarry Smith 
1231d8d19677SJose E. Roman    Output Parameters:
123253acd3b1SBarry Smith +  value - the index of the value to return
1233811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
123453acd3b1SBarry Smith 
123553acd3b1SBarry Smith    Level: intermediate
123653acd3b1SBarry Smith 
123795452b02SPatrick Sanan    Notes:
1238811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
123953acd3b1SBarry Smith 
1240*30bab8dbSBarry Smith          If the user does not supply the option at all `value` is NOT changed. Thus
1241*30bab8dbSBarry Smith           you should ALWAYS initialize `value` if you access it without first checking if the `set` flag is `PETSC_TRUE`.
12422efd9cb1SBarry Smith 
1243811af0c4SBarry Smith    See `PetscOptionsFList()` for when the choices are given in a `PetscFunctionList()`
124453acd3b1SBarry Smith 
1245db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1246db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1247db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1248c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1249db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1250db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEnum()`
125188aa4217SBarry Smith M*/
125288aa4217SBarry Smith 
1253d71ae5a4SJacob 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)
1254d71ae5a4SJacob Faibussowitsch {
125553acd3b1SBarry Smith   PetscInt        i;
12564416b707SBarry Smith   PetscOptionItem amsopt;
125744ef3d73SBarry Smith   PetscBool       lset;
125853acd3b1SBarry Smith 
125953acd3b1SBarry Smith   PetscFunctionBegin;
12601a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
12619566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, ltext, man, OPTION_ELIST, &amsopt));
126264facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
12639566063dSJacob Faibussowitsch     PetscCall(PetscStrdup(currentvalue ? currentvalue : "", (char **)&amsopt->data));
12649566063dSJacob Faibussowitsch     PetscCall(PetscStrNArrayallocpy(ntext, list, (char ***)&amsopt->list));
12651ae3d29cSBarry Smith     amsopt->nlist = ntext;
12661ae3d29cSBarry Smith   }
12679566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetEList(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, list, ntext, value, &lset));
126844ef3d73SBarry Smith   if (set) *set = lset;
12691a1499c8SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
12709566063dSJacob 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));
127148a46eb9SPierre Jolivet     for (i = 0; i < ntext; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, " %s", list[i]));
12729566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, " (%s)\n", ManSection(man)));
127353acd3b1SBarry Smith   }
12743ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
127553acd3b1SBarry Smith }
127653acd3b1SBarry Smith 
127788aa4217SBarry Smith /*MC
1278acfcf0e5SJed Brown      PetscOptionsBoolGroupBegin - First in a series of logical queries on the options database for
1279d5649816SBarry Smith        which at most a single value can be true.
128053acd3b1SBarry Smith 
128188aa4217SBarry Smith    Synopsis:
128288aa4217SBarry Smith    #include "petscsys.h"
12833a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolGroupBegin(const char opt[],const char text[],const char man[],PetscBool  *flg)
128488aa4217SBarry Smith 
12857cdbe19fSJose E. Roman    Logically Collective on the communicator passed in `PetscOptionsBegin()`
12867cdbe19fSJose E. Roman 
128753acd3b1SBarry Smith    Input Parameters:
128853acd3b1SBarry Smith +  opt - option name
128953acd3b1SBarry Smith .  text - short string that describes the option
129053acd3b1SBarry Smith -  man - manual page with additional information on option
129153acd3b1SBarry Smith 
129253acd3b1SBarry Smith    Output Parameter:
129353acd3b1SBarry Smith .  flg - whether that option was set or not
129453acd3b1SBarry Smith 
129553acd3b1SBarry Smith    Level: intermediate
129653acd3b1SBarry Smith 
129795452b02SPatrick Sanan    Notes:
1298811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
129953acd3b1SBarry Smith 
1300*30bab8dbSBarry Smith    Must be followed by 0 or more `PetscOptionsBoolGroup()`s and `PetscOptionsBoolGroupEnd()`
130153acd3b1SBarry Smith 
1302db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1303db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1304db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1305c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1306db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1307db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
130888aa4217SBarry Smith M*/
130988aa4217SBarry Smith 
1310d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsBoolGroupBegin_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool *flg)
1311d71ae5a4SJacob Faibussowitsch {
13124416b707SBarry Smith   PetscOptionItem amsopt;
131353acd3b1SBarry Smith 
131453acd3b1SBarry Smith   PetscFunctionBegin;
1315e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
13169566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt));
13179566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data));
1318a297a907SKarl Rupp 
1319ace3abfcSBarry Smith     *(PetscBool *)amsopt->data = PETSC_FALSE;
13201ae3d29cSBarry Smith   }
132168b16fdaSBarry Smith   *flg = PETSC_FALSE;
13229566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetBool(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, flg, NULL));
1323e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
13249566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  Pick at most one of -------------\n"));
13259566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "    -%s%s: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, text, ManSection(man)));
132653acd3b1SBarry Smith   }
13273ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
132853acd3b1SBarry Smith }
132953acd3b1SBarry Smith 
133088aa4217SBarry Smith /*MC
1331acfcf0e5SJed Brown      PetscOptionsBoolGroup - One in a series of logical queries on the options database for
1332d5649816SBarry Smith        which at most a single value can be true.
133353acd3b1SBarry Smith 
133488aa4217SBarry Smith    Synopsis:
133588aa4217SBarry Smith    #include "petscsys.h"
13363a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolGroup(const char opt[],const char text[],const char man[],PetscBool  *flg)
133788aa4217SBarry Smith 
13387cdbe19fSJose E. Roman    Logically Collective on the communicator passed in `PetscOptionsBegin()`
13397cdbe19fSJose E. Roman 
134053acd3b1SBarry Smith    Input Parameters:
134153acd3b1SBarry Smith +  opt - option name
134253acd3b1SBarry Smith .  text - short string that describes the option
134353acd3b1SBarry Smith -  man - manual page with additional information on option
134453acd3b1SBarry Smith 
134553acd3b1SBarry Smith    Output Parameter:
1346811af0c4SBarry Smith .  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
134753acd3b1SBarry Smith 
134853acd3b1SBarry Smith    Level: intermediate
134953acd3b1SBarry Smith 
135095452b02SPatrick Sanan    Notes:
1351811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
135253acd3b1SBarry Smith 
1353811af0c4SBarry Smith    Must follow a `PetscOptionsBoolGroupBegin()` and preceded a `PetscOptionsBoolGroupEnd()`
135453acd3b1SBarry Smith 
1355db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1356db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1357db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1358c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1359db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1360db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
136188aa4217SBarry Smith M*/
136288aa4217SBarry Smith 
1363d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsBoolGroup_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool *flg)
1364d71ae5a4SJacob Faibussowitsch {
13654416b707SBarry Smith   PetscOptionItem amsopt;
136653acd3b1SBarry Smith 
136753acd3b1SBarry Smith   PetscFunctionBegin;
1368e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
13699566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt));
13709566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data));
1371a297a907SKarl Rupp 
1372ace3abfcSBarry Smith     *(PetscBool *)amsopt->data = PETSC_FALSE;
13731ae3d29cSBarry Smith   }
137417326d04SJed Brown   *flg = PETSC_FALSE;
13759566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetBool(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, flg, NULL));
1376e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
13779566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "    -%s%s: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, text, ManSection(man)));
137853acd3b1SBarry Smith   }
13793ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
138053acd3b1SBarry Smith }
138153acd3b1SBarry Smith 
138288aa4217SBarry Smith /*MC
1383acfcf0e5SJed Brown      PetscOptionsBoolGroupEnd - Last in a series of logical queries on the options database for
1384d5649816SBarry Smith        which at most a single value can be true.
138553acd3b1SBarry Smith 
138688aa4217SBarry Smith    Synopsis:
138788aa4217SBarry Smith    #include "petscsys.h"
13883a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolGroupEnd(const char opt[],const char text[],const char man[],PetscBool  *flg)
138988aa4217SBarry Smith 
13907cdbe19fSJose E. Roman    Logically Collective on the communicator passed in `PetscOptionsBegin()`
13917cdbe19fSJose E. Roman 
139253acd3b1SBarry Smith    Input Parameters:
139353acd3b1SBarry Smith +  opt - option name
139453acd3b1SBarry Smith .  text - short string that describes the option
139553acd3b1SBarry Smith -  man - manual page with additional information on option
139653acd3b1SBarry Smith 
139753acd3b1SBarry Smith    Output Parameter:
1398811af0c4SBarry Smith .  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
139953acd3b1SBarry Smith 
140053acd3b1SBarry Smith    Level: intermediate
140153acd3b1SBarry Smith 
140295452b02SPatrick Sanan    Notes:
1403811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
140453acd3b1SBarry Smith 
1405811af0c4SBarry Smith    Must follow a `PetscOptionsBoolGroupBegin()`
140653acd3b1SBarry Smith 
1407db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1408db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1409db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1410c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1411db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1412db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
141388aa4217SBarry Smith M*/
141488aa4217SBarry Smith 
1415d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsBoolGroupEnd_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool *flg)
1416d71ae5a4SJacob Faibussowitsch {
14174416b707SBarry Smith   PetscOptionItem amsopt;
141853acd3b1SBarry Smith 
141953acd3b1SBarry Smith   PetscFunctionBegin;
1420e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
14219566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt));
14229566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data));
1423a297a907SKarl Rupp 
1424ace3abfcSBarry Smith     *(PetscBool *)amsopt->data = PETSC_FALSE;
14251ae3d29cSBarry Smith   }
142617326d04SJed Brown   *flg = PETSC_FALSE;
14279566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetBool(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, flg, NULL));
1428e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
14299566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "    -%s%s: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, text, ManSection(man)));
143053acd3b1SBarry Smith   }
14313ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
143253acd3b1SBarry Smith }
143353acd3b1SBarry Smith 
143488aa4217SBarry Smith /*MC
1435acfcf0e5SJed Brown    PetscOptionsBool - Determines if a particular option is in the database with a true or false
143653acd3b1SBarry Smith 
143788aa4217SBarry Smith    Synopsis:
143888aa4217SBarry Smith    #include "petscsys.h"
14393a89f35bSSatish Balay    PetscErrorCode PetscOptionsBool(const char opt[],const char text[],const char man[],PetscBool currentvalue,PetscBool  *flg,PetscBool  *set)
144088aa4217SBarry Smith 
14417cdbe19fSJose E. Roman    Logically Collective on the communicator passed in `PetscOptionsBegin()`
14427cdbe19fSJose E. Roman 
144353acd3b1SBarry Smith    Input Parameters:
144453acd3b1SBarry Smith +  opt - option name
144553acd3b1SBarry Smith .  text - short string that describes the option
1446868c398cSBarry Smith .  man - manual page with additional information on option
144794ae4db5SBarry Smith -  currentvalue - the current value
144853acd3b1SBarry Smith 
1449d8d19677SJose E. Roman    Output Parameters:
1450811af0c4SBarry Smith +  flg -` PETSC_TRUE` or `PETSC_FALSE`
1451811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
145253acd3b1SBarry Smith 
1453*30bab8dbSBarry Smith    Level: beginner
1454*30bab8dbSBarry Smith 
14552efd9cb1SBarry Smith    Notes:
1456811af0c4SBarry Smith        TRUE, true, YES, yes, nostring, and 1 all translate to `PETSC_TRUE`
1457811af0c4SBarry Smith        FALSE, false, NO, no, and 0 all translate to `PETSC_FALSE`
14582efd9cb1SBarry Smith 
1459*30bab8dbSBarry 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`
1460*30bab8dbSBarry Smith      is equivalent to `-requested_bool true`
14612efd9cb1SBarry Smith 
1462*30bab8dbSBarry Smith        If the user does not supply the option at all `flg` is NOT changed. Thus
1463*30bab8dbSBarry Smith      you should ALWAYS initialize the `flg` variable if you access it without first checking if the `set` flag is `PETSC_TRUE`.
14642efd9cb1SBarry Smith 
1465811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
146653acd3b1SBarry Smith 
1467db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
1468db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
1469db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`,
1470db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1471c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1472db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1473db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
147488aa4217SBarry Smith M*/
147588aa4217SBarry Smith 
1476d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsBool_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool currentvalue, PetscBool *flg, PetscBool *set)
1477d71ae5a4SJacob Faibussowitsch {
1478ace3abfcSBarry Smith   PetscBool       iset;
14794416b707SBarry Smith   PetscOptionItem amsopt;
148053acd3b1SBarry Smith 
148153acd3b1SBarry Smith   PetscFunctionBegin;
1482e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
14839566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt));
14849566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data));
1485a297a907SKarl Rupp 
148694ae4db5SBarry Smith     *(PetscBool *)amsopt->data = currentvalue;
1487af6d86caSBarry Smith   }
14889566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetBool(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, flg, &iset));
148953acd3b1SBarry Smith   if (set) *set = iset;
14901a1499c8SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
149144ef3d73SBarry Smith     const char *v = PetscBools[currentvalue], *vn = PetscBools[iset && flg ? *flg : currentvalue];
14929566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s: <%s : %s> %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, v, vn, text, ManSection(man)));
149353acd3b1SBarry Smith   }
14943ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
149553acd3b1SBarry Smith }
149653acd3b1SBarry Smith 
149788aa4217SBarry Smith /*MC
149853acd3b1SBarry Smith    PetscOptionsRealArray - Gets an array of double values for a particular
149953acd3b1SBarry Smith    option in the database. The values must be separated with commas with
150053acd3b1SBarry Smith    no intervening spaces.
150153acd3b1SBarry Smith 
150288aa4217SBarry Smith    Synopsis:
150388aa4217SBarry Smith    #include "petscsys.h"
15043a89f35bSSatish Balay    PetscErrorCode PetscOptionsRealArray(const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscBool  *set)
150588aa4217SBarry Smith 
15067cdbe19fSJose E. Roman    Logically Collective on the communicator passed in `PetscOptionsBegin()`
15077cdbe19fSJose E. Roman 
150853acd3b1SBarry Smith    Input Parameters:
150953acd3b1SBarry Smith +  opt - the option one is seeking
151053acd3b1SBarry Smith .  text - short string describing option
151153acd3b1SBarry Smith .  man - manual page for option
1512c89788bdSBarry Smith -  n - maximum number of values that value has room for
151353acd3b1SBarry Smith 
1514d8d19677SJose E. Roman    Output Parameters:
151553acd3b1SBarry Smith +  value - location to copy values
1516c89788bdSBarry Smith .  n - actual number of values found
1517811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
151853acd3b1SBarry Smith 
151953acd3b1SBarry Smith    Level: beginner
152053acd3b1SBarry Smith 
1521*30bab8dbSBarry Smith    Note:
1522811af0c4SBarry Smith    Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
152353acd3b1SBarry Smith 
1524db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1525db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1526db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1527c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1528db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1529db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
153088aa4217SBarry Smith M*/
153188aa4217SBarry Smith 
1532d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsRealArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscReal value[], PetscInt *n, PetscBool *set)
1533d71ae5a4SJacob Faibussowitsch {
153453acd3b1SBarry Smith   PetscInt        i;
15354416b707SBarry Smith   PetscOptionItem amsopt;
153653acd3b1SBarry Smith 
153753acd3b1SBarry Smith   PetscFunctionBegin;
1538e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1539e26ddf31SBarry Smith     PetscReal *vals;
1540e26ddf31SBarry Smith 
15419566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_REAL_ARRAY, &amsopt));
15429566063dSJacob Faibussowitsch     PetscCall(PetscMalloc((*n) * sizeof(PetscReal), &amsopt->data));
1543e26ddf31SBarry Smith     vals = (PetscReal *)amsopt->data;
1544e26ddf31SBarry Smith     for (i = 0; i < *n; i++) vals[i] = value[i];
1545e26ddf31SBarry Smith     amsopt->arraylength = *n;
1546e26ddf31SBarry Smith   }
15479566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetRealArray(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, n, set));
1548e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
15499566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%g", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, (double)value[0]));
155048a46eb9SPierre Jolivet     for (i = 1; i < *n; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ",%g", (double)value[i]));
15519566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ">: %s (%s)\n", text, ManSection(man)));
155253acd3b1SBarry Smith   }
15533ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
155453acd3b1SBarry Smith }
155553acd3b1SBarry Smith 
155688aa4217SBarry Smith /*MC
1557811af0c4SBarry Smith    PetscOptionsScalarArray - Gets an array of `PetscScalar` values for a particular
1558050cccc3SHong Zhang    option in the database. The values must be separated with commas with
1559050cccc3SHong Zhang    no intervening spaces.
1560050cccc3SHong Zhang 
156188aa4217SBarry Smith    Synopsis:
156288aa4217SBarry Smith    #include "petscsys.h"
15633a89f35bSSatish Balay    PetscErrorCode PetscOptionsScalarArray(const char opt[],const char text[],const char man[],PetscScalar value[],PetscInt *n,PetscBool  *set)
156488aa4217SBarry Smith 
15657cdbe19fSJose E. Roman    Logically Collective on the communicator passed in `PetscOptionsBegin()`
15667cdbe19fSJose E. Roman 
1567050cccc3SHong Zhang    Input Parameters:
1568050cccc3SHong Zhang +  opt - the option one is seeking
1569050cccc3SHong Zhang .  text - short string describing option
1570050cccc3SHong Zhang .  man - manual page for option
1571c89788bdSBarry Smith -  n - maximum number of values allowed in the value array
1572050cccc3SHong Zhang 
1573d8d19677SJose E. Roman    Output Parameters:
1574050cccc3SHong Zhang +  value - location to copy values
1575c89788bdSBarry Smith .  n - actual number of values found
1576811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
1577050cccc3SHong Zhang 
1578050cccc3SHong Zhang    Level: beginner
1579050cccc3SHong Zhang 
1580*30bab8dbSBarry Smith    Note:
1581811af0c4SBarry Smith    Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
1582050cccc3SHong Zhang 
1583db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1584db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1585db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1586c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1587db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1588db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
158988aa4217SBarry Smith M*/
159088aa4217SBarry Smith 
1591d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsScalarArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscScalar value[], PetscInt *n, PetscBool *set)
1592d71ae5a4SJacob Faibussowitsch {
1593050cccc3SHong Zhang   PetscInt        i;
15944416b707SBarry Smith   PetscOptionItem amsopt;
1595050cccc3SHong Zhang 
1596050cccc3SHong Zhang   PetscFunctionBegin;
1597050cccc3SHong Zhang   if (!PetscOptionsObject->count) {
1598050cccc3SHong Zhang     PetscScalar *vals;
1599050cccc3SHong Zhang 
16009566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_SCALAR_ARRAY, &amsopt));
16019566063dSJacob Faibussowitsch     PetscCall(PetscMalloc((*n) * sizeof(PetscScalar), &amsopt->data));
1602050cccc3SHong Zhang     vals = (PetscScalar *)amsopt->data;
1603050cccc3SHong Zhang     for (i = 0; i < *n; i++) vals[i] = value[i];
1604050cccc3SHong Zhang     amsopt->arraylength = *n;
1605050cccc3SHong Zhang   }
16069566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetScalarArray(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, n, set));
1607050cccc3SHong Zhang   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
16089566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%g+%gi", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, (double)PetscRealPart(value[0]), (double)PetscImaginaryPart(value[0])));
160948a46eb9SPierre Jolivet     for (i = 1; i < *n; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ",%g+%gi", (double)PetscRealPart(value[i]), (double)PetscImaginaryPart(value[i])));
16109566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ">: %s (%s)\n", text, ManSection(man)));
1611050cccc3SHong Zhang   }
16123ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1613050cccc3SHong Zhang }
161453acd3b1SBarry Smith 
161588aa4217SBarry Smith /*MC
161653acd3b1SBarry Smith    PetscOptionsIntArray - Gets an array of integers for a particular
1617b32a342fSShri Abhyankar    option in the database.
161853acd3b1SBarry Smith 
161988aa4217SBarry Smith    Synopsis:
162088aa4217SBarry Smith    #include "petscsys.h"
16213a89f35bSSatish Balay    PetscErrorCode PetscOptionsIntArray(const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscBool  *set)
162288aa4217SBarry Smith 
16237cdbe19fSJose E. Roman    Logically Collective on the communicator passed in `PetscOptionsBegin()`
16247cdbe19fSJose E. Roman 
162553acd3b1SBarry Smith    Input Parameters:
162653acd3b1SBarry Smith +  opt - the option one is seeking
162753acd3b1SBarry Smith .  text - short string describing option
162853acd3b1SBarry Smith .  man - manual page for option
1629f8a50e2bSBarry Smith -  n - maximum number of values
163053acd3b1SBarry Smith 
1631d8d19677SJose E. Roman    Output Parameters:
163253acd3b1SBarry Smith +  value - location to copy values
1633f8a50e2bSBarry Smith .  n - actual number of values found
1634811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
163553acd3b1SBarry Smith 
163653acd3b1SBarry Smith    Level: beginner
163753acd3b1SBarry Smith 
163853acd3b1SBarry Smith    Notes:
1639b32a342fSShri Abhyankar    The array can be passed as
1640811af0c4SBarry Smith +   a comma separated list -                                  0,1,2,3,4,5,6,7
1641811af0c4SBarry Smith .   a range (start\-end+1) -                                  0-8
1642811af0c4SBarry Smith .   a range with given increment (start\-end+1:inc) -         0-7:2
1643811af0c4SBarry Smith -   a combination of values and ranges separated by commas -  0,1-8,8-15:2
1644b32a342fSShri Abhyankar 
1645b32a342fSShri Abhyankar    There must be no intervening spaces between the values.
164653acd3b1SBarry Smith 
1647811af0c4SBarry Smith    Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
164853acd3b1SBarry Smith 
1649db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1650db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1651db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1652c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1653db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1654db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`, `PetscOptionsRealArray()`
165588aa4217SBarry Smith M*/
165688aa4217SBarry Smith 
1657d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsIntArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscInt value[], PetscInt *n, PetscBool *set)
1658d71ae5a4SJacob Faibussowitsch {
165953acd3b1SBarry Smith   PetscInt        i;
16604416b707SBarry Smith   PetscOptionItem amsopt;
166153acd3b1SBarry Smith 
166253acd3b1SBarry Smith   PetscFunctionBegin;
1663e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1664e26ddf31SBarry Smith     PetscInt *vals;
1665e26ddf31SBarry Smith 
16669566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_INT_ARRAY, &amsopt));
16679566063dSJacob Faibussowitsch     PetscCall(PetscMalloc1(*n, (PetscInt **)&amsopt->data));
1668e26ddf31SBarry Smith     vals = (PetscInt *)amsopt->data;
1669e26ddf31SBarry Smith     for (i = 0; i < *n; i++) vals[i] = value[i];
1670e26ddf31SBarry Smith     amsopt->arraylength = *n;
1671e26ddf31SBarry Smith   }
16729566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetIntArray(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, n, set));
1673e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
16749566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%" PetscInt_FMT, PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, value[0]));
167548a46eb9SPierre Jolivet     for (i = 1; i < *n; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ",%" PetscInt_FMT, value[i]));
16769566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ">: %s (%s)\n", text, ManSection(man)));
167753acd3b1SBarry Smith   }
16783ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
167953acd3b1SBarry Smith }
168053acd3b1SBarry Smith 
168188aa4217SBarry Smith /*MC
168253acd3b1SBarry Smith    PetscOptionsStringArray - Gets an array of string values for a particular
168353acd3b1SBarry Smith    option in the database. The values must be separated with commas with
168453acd3b1SBarry Smith    no intervening spaces.
168553acd3b1SBarry Smith 
168688aa4217SBarry Smith    Synopsis:
168788aa4217SBarry Smith    #include "petscsys.h"
16883a89f35bSSatish Balay    PetscErrorCode PetscOptionsStringArray(const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscBool  *set)
168988aa4217SBarry Smith 
16907cdbe19fSJose E. Roman    Logically Collective on the communicator passed in `PetscOptionsBegin()`; No Fortran Support
16917cdbe19fSJose E. Roman 
169253acd3b1SBarry Smith    Input Parameters:
169353acd3b1SBarry Smith +  opt - the option one is seeking
169453acd3b1SBarry Smith .  text - short string describing option
169553acd3b1SBarry Smith .  man - manual page for option
169653acd3b1SBarry Smith -  nmax - maximum number of strings
169753acd3b1SBarry Smith 
1698d8d19677SJose E. Roman    Output Parameters:
169953acd3b1SBarry Smith +  value - location to copy strings
170053acd3b1SBarry Smith .  nmax - actual number of strings found
1701811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
170253acd3b1SBarry Smith 
170353acd3b1SBarry Smith    Level: beginner
170453acd3b1SBarry Smith 
170553acd3b1SBarry Smith    Notes:
170653acd3b1SBarry Smith    The user should pass in an array of pointers to char, to hold all the
170753acd3b1SBarry Smith    strings returned by this function.
170853acd3b1SBarry Smith 
170953acd3b1SBarry Smith    The user is responsible for deallocating the strings that are
1710cf53795eSBarry Smith    returned.
171153acd3b1SBarry Smith 
1712811af0c4SBarry Smith    Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
171353acd3b1SBarry Smith 
1714db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1715db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1716db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1717c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1718db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1719db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
172088aa4217SBarry Smith M*/
172188aa4217SBarry Smith 
1722d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsStringArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], char *value[], PetscInt *nmax, PetscBool *set)
1723d71ae5a4SJacob Faibussowitsch {
17244416b707SBarry Smith   PetscOptionItem amsopt;
172553acd3b1SBarry Smith 
172653acd3b1SBarry Smith   PetscFunctionBegin;
1727e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
17289566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_STRING_ARRAY, &amsopt));
17299566063dSJacob Faibussowitsch     PetscCall(PetscMalloc1(*nmax, (char **)&amsopt->data));
1730a297a907SKarl Rupp 
17311ae3d29cSBarry Smith     amsopt->arraylength = *nmax;
17321ae3d29cSBarry Smith   }
17339566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetStringArray(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, nmax, set));
1734e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
17359566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <string1,string2,...>: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, text, ManSection(man)));
173653acd3b1SBarry Smith   }
17373ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
173853acd3b1SBarry Smith }
173953acd3b1SBarry Smith 
174088aa4217SBarry Smith /*MC
1741acfcf0e5SJed Brown    PetscOptionsBoolArray - Gets an array of logical values (true or false) for a particular
1742e2446a98SMatthew Knepley    option in the database. The values must be separated with commas with
1743e2446a98SMatthew Knepley    no intervening spaces.
1744e2446a98SMatthew Knepley 
174588aa4217SBarry Smith    Synopsis:
174688aa4217SBarry Smith    #include "petscsys.h"
17473a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolArray(const char opt[],const char text[],const char man[],PetscBool value[],PetscInt *n,PetscBool *set)
174888aa4217SBarry Smith 
17497cdbe19fSJose E. Roman    Logically Collective on the communicator passed in `PetscOptionsBegin()`
17507cdbe19fSJose E. Roman 
1751e2446a98SMatthew Knepley    Input Parameters:
1752e2446a98SMatthew Knepley +  opt - the option one is seeking
1753e2446a98SMatthew Knepley .  text - short string describing option
1754e2446a98SMatthew Knepley .  man - manual page for option
1755c89788bdSBarry Smith -  n - maximum number of values allowed in the value array
1756e2446a98SMatthew Knepley 
1757d8d19677SJose E. Roman    Output Parameters:
1758e2446a98SMatthew Knepley +  value - location to copy values
1759c89788bdSBarry Smith .  n - actual number of values found
1760811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
1761e2446a98SMatthew Knepley 
1762e2446a98SMatthew Knepley    Level: beginner
1763e2446a98SMatthew Knepley 
1764e2446a98SMatthew Knepley    Notes:
1765*30bab8dbSBarry Smith    The user should pass in an array of `PetscBool`
1766e2446a98SMatthew Knepley 
1767811af0c4SBarry Smith    Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
1768e2446a98SMatthew Knepley 
1769db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1770db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1771db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1772c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1773db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1774db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
177588aa4217SBarry Smith M*/
177688aa4217SBarry Smith 
1777d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsBoolArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool value[], PetscInt *n, PetscBool *set)
1778d71ae5a4SJacob Faibussowitsch {
1779e2446a98SMatthew Knepley   PetscInt        i;
17804416b707SBarry Smith   PetscOptionItem amsopt;
1781e2446a98SMatthew Knepley 
1782e2446a98SMatthew Knepley   PetscFunctionBegin;
1783e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1784ace3abfcSBarry Smith     PetscBool *vals;
17851ae3d29cSBarry Smith 
17869566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL_ARRAY, &amsopt));
17879566063dSJacob Faibussowitsch     PetscCall(PetscMalloc1(*n, (PetscBool **)&amsopt->data));
1788ace3abfcSBarry Smith     vals = (PetscBool *)amsopt->data;
17891ae3d29cSBarry Smith     for (i = 0; i < *n; i++) vals[i] = value[i];
17901ae3d29cSBarry Smith     amsopt->arraylength = *n;
17911ae3d29cSBarry Smith   }
17929566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetBoolArray(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, n, set));
1793e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
17949566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%d", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, value[0]));
179548a46eb9SPierre Jolivet     for (i = 1; i < *n; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ",%d", value[i]));
17969566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ">: %s (%s)\n", text, ManSection(man)));
1797e2446a98SMatthew Knepley   }
17983ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1799e2446a98SMatthew Knepley }
1800e2446a98SMatthew Knepley 
180188aa4217SBarry Smith /*MC
1802d1da0b69SBarry Smith    PetscOptionsViewer - Gets a viewer appropriate for the type indicated by the user
18038cc676e6SMatthew G Knepley 
180488aa4217SBarry Smith    Synopsis:
180588aa4217SBarry Smith    #include "petscsys.h"
18063a89f35bSSatish Balay    PetscErrorCode PetscOptionsViewer(const char opt[],const char text[],const char man[],PetscViewer *viewer,PetscViewerFormat *format,PetscBool *set)
180788aa4217SBarry Smith 
18087cdbe19fSJose E. Roman    Logically Collective on the communicator passed in `PetscOptionsBegin()`
18097cdbe19fSJose E. Roman 
18108cc676e6SMatthew G Knepley    Input Parameters:
18118cc676e6SMatthew G Knepley +  opt - option name
18128cc676e6SMatthew G Knepley .  text - short string that describes the option
18138cc676e6SMatthew G Knepley -  man - manual page with additional information on option
18148cc676e6SMatthew G Knepley 
1815d8d19677SJose E. Roman    Output Parameters:
18168cc676e6SMatthew G Knepley +  viewer - the viewer
18177962402dSFande Kong .  format - the PetscViewerFormat requested by the user, pass NULL if not needed
1818811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
18198cc676e6SMatthew G Knepley 
18208cc676e6SMatthew G Knepley    Level: beginner
18218cc676e6SMatthew G Knepley 
182295452b02SPatrick Sanan    Notes:
1823811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
18248cc676e6SMatthew G Knepley 
1825811af0c4SBarry Smith    See `PetscOptionsGetViewer()` for the format of the supplied viewer and its options
18268cc676e6SMatthew G Knepley 
1827db781477SPatrick Sanan .seealso: `PetscOptionsGetViewer()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
1828db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`
1829db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
1830db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1831c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1832db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1833db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
183488aa4217SBarry Smith M*/
183588aa4217SBarry Smith 
1836d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsViewer_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscViewer *viewer, PetscViewerFormat *format, PetscBool *set)
1837d71ae5a4SJacob Faibussowitsch {
18384416b707SBarry Smith   PetscOptionItem amsopt;
18398cc676e6SMatthew G Knepley 
18408cc676e6SMatthew G Knepley   PetscFunctionBegin;
18411a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
18429566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_STRING, &amsopt));
184364facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
18449566063dSJacob Faibussowitsch     PetscCall(PetscStrdup("", (char **)&amsopt->data));
18458cc676e6SMatthew G Knepley   }
18469566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetViewer(PetscOptionsObject->comm, PetscOptionsObject->options, PetscOptionsObject->prefix, opt, viewer, format, set));
1847e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
18489566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%s>: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, "", text, ManSection(man)));
18498cc676e6SMatthew G Knepley   }
18503ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
18518cc676e6SMatthew G Knepley }
1852