xref: /petsc/src/sys/objects/aoptions.c (revision bf31d2d34e67170cccc52032cb9ed4707f3cb2ab) !
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:
375*bf31d2d3SBarry Smith +    All processes must traverse through the exact same set of option queries due 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 
617811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
61853acd3b1SBarry Smith 
61988aa4217SBarry Smith    Synopsis:
62088aa4217SBarry Smith    #include "petscsys.h"
6213a89f35bSSatish Balay    PetscErrorCode  PetscOptionsEnum(const char opt[],const char text[],const char man[],const char *const *list,PetscEnum currentvalue,PetscEnum *value,PetscBool  *set)
62288aa4217SBarry Smith 
62353acd3b1SBarry Smith    Input Parameters:
62453acd3b1SBarry Smith +  opt - option name
62553acd3b1SBarry Smith .  text - short string that describes the option
62653acd3b1SBarry Smith .  man - manual page with additional information on option
62753acd3b1SBarry Smith .  list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null
6280fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
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 
6472efd9cb1SBarry Smith           If the user does not supply the option at all value is NOT changed. Thus
6482efd9cb1SBarry Smith           you should ALWAYS initialize value if you access it without first checking if the set flag is true.
6492efd9cb1SBarry Smith 
650989712b9SBarry Smith           The default/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 
682811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
683d3e47460SLisandro Dalcin 
68488aa4217SBarry Smith    Synopsis:
68588aa4217SBarry Smith    #include "petscsys.h"
6863a89f35bSSatish Balay    PetscErrorCode  PetscOptionsEnumArray(const char opt[],const char text[],const char man[],const char *const *list,PetscEnum value[],PetscInt *n,PetscBool  *set)
68788aa4217SBarry Smith 
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 
750811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
7515a856986SBarry Smith 
75288aa4217SBarry Smith    Synopsis:
75388aa4217SBarry Smith    #include "petscsys.h"
75469d47153SPierre Jolivet    PetscErrorCode  PetscOptionsBoundedInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg,PetscInt bound)
75588aa4217SBarry Smith 
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:
7795a856986SBarry Smith     If the user does not supply the option at all value is NOT changed. Thus
7805a856986SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
7815a856986SBarry Smith 
7825a856986SBarry Smith     The default/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 
798811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
7995a856986SBarry Smith 
80088aa4217SBarry Smith    Synopsis:
80188aa4217SBarry Smith    #include "petscsys.h"
8023a89f35bSSatish Balay    PetscErrorCode  PetscOptionsRangeInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg,PetscInt lb,PetscInt ub)
80388aa4217SBarry Smith 
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:
8255a856986SBarry Smith     If the user does not supply the option at all value is NOT changed. Thus
8265a856986SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
8275a856986SBarry Smith 
8285a856986SBarry Smith     The default/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 
844811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
84553acd3b1SBarry Smith 
84688aa4217SBarry Smith    Synopsis:
84788aa4217SBarry Smith    #include "petscsys.h"
8486eeb591dSVaclav Hapla    PetscErrorCode  PetscOptionsInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg))
84988aa4217SBarry Smith 
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 
86695452b02SPatrick Sanan    Notes:
86795452b02SPatrick Sanan     If the user does not supply the option at all value is NOT changed. Thus
8682efd9cb1SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
8692efd9cb1SBarry Smith 
870989712b9SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
871989712b9SBarry Smith 
872811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
87353acd3b1SBarry Smith 
8745a856986SBarry Smith    Level: beginner
8755a856986SBarry 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 
914811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
91553acd3b1SBarry Smith 
91688aa4217SBarry Smith    Synopsis:
91788aa4217SBarry Smith    #include "petscsys.h"
9183a89f35bSSatish Balay    PetscErrorCode  PetscOptionsString(const char opt[],const char text[],const char man[],const char currentvalue[],char value[],size_t len,PetscBool  *set)
91988aa4217SBarry Smith 
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 
9367fccdfe4SBarry Smith    Even if the user provided no string (for example -optionname -someotheroption) the flag is set to PETSC_TRUE (and the string is fulled with nulls).
9377fccdfe4SBarry Smith 
9382efd9cb1SBarry Smith           If the user does not supply the option at all value is NOT changed. Thus
9392efd9cb1SBarry Smith           you should ALWAYS initialize value if you access it without first checking if the set flag is true.
9402efd9cb1SBarry Smith 
941989712b9SBarry Smith           The default/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 
974811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
97553acd3b1SBarry Smith 
97688aa4217SBarry Smith    Synopsis:
97788aa4217SBarry Smith    #include "petscsys.h"
9783a89f35bSSatish Balay    PetscErrorCode  PetscOptionsReal(const char opt[],const char text[],const char man[],PetscReal currentvalue,PetscReal *value,PetscBool  *set)
97988aa4217SBarry Smith 
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 
99695452b02SPatrick Sanan    Notes:
99795452b02SPatrick Sanan     If the user does not supply the option at all value is NOT changed. Thus
9982efd9cb1SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
9992efd9cb1SBarry Smith 
1000989712b9SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
1001989712b9SBarry Smith 
1002811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
100353acd3b1SBarry Smith 
10045a856986SBarry Smith    Level: beginner
10055a856986SBarry 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 
1038811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
103953acd3b1SBarry Smith 
104088aa4217SBarry Smith    Synopsis:
104188aa4217SBarry Smith    #include "petscsys.h"
10423a89f35bSSatish Balay    PetscErrorCode PetscOptionsScalar(const char opt[],const char text[],const char man[],PetscScalar currentvalue,PetscScalar *value,PetscBool  *set)
104388aa4217SBarry Smith 
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 
106095452b02SPatrick Sanan    Notes:
106195452b02SPatrick Sanan     If the user does not supply the option at all value is NOT changed. Thus
10622efd9cb1SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
10632efd9cb1SBarry Smith 
1064989712b9SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
1065989712b9SBarry Smith 
1066811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
106753acd3b1SBarry Smith 
10685a856986SBarry Smith    Level: beginner
10695a856986SBarry 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 
1094811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
109553acd3b1SBarry Smith 
109688aa4217SBarry Smith    Synopsis:
109788aa4217SBarry Smith    #include "petscsys.h"
10983a89f35bSSatish Balay    PetscErrorCode PetscOptionsName(const char opt[],const char text[],const char man[],PetscBool  *flg)
109988aa4217SBarry Smith 
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 
1143811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
114453acd3b1SBarry Smith 
114588aa4217SBarry Smith    Synopsis:
114688aa4217SBarry Smith    #include "petscsys.h"
11473a89f35bSSatish Balay    PetscErrorCode  PetscOptionsFList(const char opt[],const char ltext[],const char man[],PetscFunctionList list,const char currentvalue[],char value[],size_t len,PetscBool  *set)
114888aa4217SBarry Smith 
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 
11702efd9cb1SBarry Smith           If the user does not supply the option at all value is NOT changed. Thus
11712efd9cb1SBarry Smith           you should ALWAYS initialize value if you access it without first checking if the set flag is true.
11722efd9cb1SBarry Smith 
1173989712b9SBarry Smith           The default/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 
1214811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
121553acd3b1SBarry Smith 
121688aa4217SBarry Smith    Synopsis:
121788aa4217SBarry Smith    #include "petscsys.h"
12183a89f35bSSatish 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)
121988aa4217SBarry Smith 
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 
12402efd9cb1SBarry Smith          If the user does not supply the option at all value is NOT changed. Thus
12412efd9cb1SBarry Smith           you should ALWAYS initialize value if you access it without first checking if the set flag is 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 
1281811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
128253acd3b1SBarry Smith 
128388aa4217SBarry Smith    Synopsis:
128488aa4217SBarry Smith    #include "petscsys.h"
12853a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolGroupBegin(const char opt[],const char text[],const char man[],PetscBool  *flg)
128688aa4217SBarry Smith 
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 
1300811af0c4SBarry Smith    Must be followed by 0 or more P`etscOptionsBoolGroup()`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 
1334811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
133553acd3b1SBarry Smith 
133688aa4217SBarry Smith    Synopsis:
133788aa4217SBarry Smith    #include "petscsys.h"
13383a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolGroup(const char opt[],const char text[],const char man[],PetscBool  *flg)
133988aa4217SBarry Smith 
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 
1386811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
138753acd3b1SBarry Smith 
138888aa4217SBarry Smith    Synopsis:
138988aa4217SBarry Smith    #include "petscsys.h"
13903a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolGroupEnd(const char opt[],const char text[],const char man[],PetscBool  *flg)
139188aa4217SBarry Smith 
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 
1437811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
143853acd3b1SBarry Smith 
143988aa4217SBarry Smith    Synopsis:
144088aa4217SBarry Smith    #include "petscsys.h"
14413a89f35bSSatish Balay    PetscErrorCode PetscOptionsBool(const char opt[],const char text[],const char man[],PetscBool currentvalue,PetscBool  *flg,PetscBool  *set)
144288aa4217SBarry Smith 
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 
14532efd9cb1SBarry Smith    Notes:
1454811af0c4SBarry Smith        TRUE, true, YES, yes, nostring, and 1 all translate to `PETSC_TRUE`
1455811af0c4SBarry Smith        FALSE, false, NO, no, and 0 all translate to `PETSC_FALSE`
14562efd9cb1SBarry Smith 
1457811af0c4SBarry 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
14582efd9cb1SBarry Smith      is equivalent to -requested_bool true
14592efd9cb1SBarry Smith 
14602efd9cb1SBarry Smith        If the user does not supply the option at all flg is NOT changed. Thus
14612efd9cb1SBarry Smith      you should ALWAYS initialize the flg if you access it without first checking if the set flag is true.
14622efd9cb1SBarry Smith 
1463811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
146453acd3b1SBarry Smith 
14655a856986SBarry Smith    Level: beginner
14665a856986SBarry 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 
1502811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
150353acd3b1SBarry Smith 
150488aa4217SBarry Smith    Synopsis:
150588aa4217SBarry Smith    #include "petscsys.h"
15063a89f35bSSatish Balay    PetscErrorCode PetscOptionsRealArray(const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscBool  *set)
150788aa4217SBarry Smith 
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 
1521811af0c4SBarry Smith    Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
152253acd3b1SBarry Smith 
1523db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1524db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1525db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1526c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1527db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1528db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
152988aa4217SBarry Smith M*/
153088aa4217SBarry Smith 
1531d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsRealArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscReal value[], PetscInt *n, PetscBool *set)
1532d71ae5a4SJacob Faibussowitsch {
153353acd3b1SBarry Smith   PetscInt        i;
15344416b707SBarry Smith   PetscOptionItem amsopt;
153553acd3b1SBarry Smith 
153653acd3b1SBarry Smith   PetscFunctionBegin;
1537e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1538e26ddf31SBarry Smith     PetscReal *vals;
1539e26ddf31SBarry Smith 
15409566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_REAL_ARRAY, &amsopt));
15419566063dSJacob Faibussowitsch     PetscCall(PetscMalloc((*n) * sizeof(PetscReal), &amsopt->data));
1542e26ddf31SBarry Smith     vals = (PetscReal *)amsopt->data;
1543e26ddf31SBarry Smith     for (i = 0; i < *n; i++) vals[i] = value[i];
1544e26ddf31SBarry Smith     amsopt->arraylength = *n;
1545e26ddf31SBarry Smith   }
15469566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetRealArray(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, n, set));
1547e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
15489566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%g", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, (double)value[0]));
154948a46eb9SPierre Jolivet     for (i = 1; i < *n; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ",%g", (double)value[i]));
15509566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ">: %s (%s)\n", text, ManSection(man)));
155153acd3b1SBarry Smith   }
15523ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
155353acd3b1SBarry Smith }
155453acd3b1SBarry Smith 
155588aa4217SBarry Smith /*MC
1556811af0c4SBarry Smith    PetscOptionsScalarArray - Gets an array of `PetscScalar` values for a particular
1557050cccc3SHong Zhang    option in the database. The values must be separated with commas with
1558050cccc3SHong Zhang    no intervening spaces.
1559050cccc3SHong Zhang 
1560811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
1561050cccc3SHong Zhang 
156288aa4217SBarry Smith    Synopsis:
156388aa4217SBarry Smith    #include "petscsys.h"
15643a89f35bSSatish Balay    PetscErrorCode PetscOptionsScalarArray(const char opt[],const char text[],const char man[],PetscScalar value[],PetscInt *n,PetscBool  *set)
156588aa4217SBarry Smith 
1566050cccc3SHong Zhang    Input Parameters:
1567050cccc3SHong Zhang +  opt - the option one is seeking
1568050cccc3SHong Zhang .  text - short string describing option
1569050cccc3SHong Zhang .  man - manual page for option
1570c89788bdSBarry Smith -  n - maximum number of values allowed in the value array
1571050cccc3SHong Zhang 
1572d8d19677SJose E. Roman    Output Parameters:
1573050cccc3SHong Zhang +  value - location to copy values
1574c89788bdSBarry Smith .  n - actual number of values found
1575811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
1576050cccc3SHong Zhang 
1577050cccc3SHong Zhang    Level: beginner
1578050cccc3SHong Zhang 
1579811af0c4SBarry Smith    Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
1580050cccc3SHong Zhang 
1581db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1582db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1583db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1584c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1585db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1586db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
158788aa4217SBarry Smith M*/
158888aa4217SBarry Smith 
1589d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsScalarArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscScalar value[], PetscInt *n, PetscBool *set)
1590d71ae5a4SJacob Faibussowitsch {
1591050cccc3SHong Zhang   PetscInt        i;
15924416b707SBarry Smith   PetscOptionItem amsopt;
1593050cccc3SHong Zhang 
1594050cccc3SHong Zhang   PetscFunctionBegin;
1595050cccc3SHong Zhang   if (!PetscOptionsObject->count) {
1596050cccc3SHong Zhang     PetscScalar *vals;
1597050cccc3SHong Zhang 
15989566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_SCALAR_ARRAY, &amsopt));
15999566063dSJacob Faibussowitsch     PetscCall(PetscMalloc((*n) * sizeof(PetscScalar), &amsopt->data));
1600050cccc3SHong Zhang     vals = (PetscScalar *)amsopt->data;
1601050cccc3SHong Zhang     for (i = 0; i < *n; i++) vals[i] = value[i];
1602050cccc3SHong Zhang     amsopt->arraylength = *n;
1603050cccc3SHong Zhang   }
16049566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetScalarArray(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, n, set));
1605050cccc3SHong Zhang   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
16069566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%g+%gi", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, (double)PetscRealPart(value[0]), (double)PetscImaginaryPart(value[0])));
160748a46eb9SPierre Jolivet     for (i = 1; i < *n; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ",%g+%gi", (double)PetscRealPart(value[i]), (double)PetscImaginaryPart(value[i])));
16089566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ">: %s (%s)\n", text, ManSection(man)));
1609050cccc3SHong Zhang   }
16103ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1611050cccc3SHong Zhang }
161253acd3b1SBarry Smith 
161388aa4217SBarry Smith /*MC
161453acd3b1SBarry Smith    PetscOptionsIntArray - Gets an array of integers for a particular
1615b32a342fSShri Abhyankar    option in the database.
161653acd3b1SBarry Smith 
1617811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
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 
162353acd3b1SBarry Smith    Input Parameters:
162453acd3b1SBarry Smith +  opt - the option one is seeking
162553acd3b1SBarry Smith .  text - short string describing option
162653acd3b1SBarry Smith .  man - manual page for option
1627f8a50e2bSBarry Smith -  n - maximum number of values
162853acd3b1SBarry Smith 
1629d8d19677SJose E. Roman    Output Parameters:
163053acd3b1SBarry Smith +  value - location to copy values
1631f8a50e2bSBarry Smith .  n - actual number of values found
1632811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
163353acd3b1SBarry Smith 
163453acd3b1SBarry Smith    Level: beginner
163553acd3b1SBarry Smith 
163653acd3b1SBarry Smith    Notes:
1637b32a342fSShri Abhyankar    The array can be passed as
1638811af0c4SBarry Smith +   a comma separated list -                                  0,1,2,3,4,5,6,7
1639811af0c4SBarry Smith .   a range (start\-end+1) -                                  0-8
1640811af0c4SBarry Smith .   a range with given increment (start\-end+1:inc) -         0-7:2
1641811af0c4SBarry Smith -   a combination of values and ranges separated by commas -  0,1-8,8-15:2
1642b32a342fSShri Abhyankar 
1643b32a342fSShri Abhyankar    There must be no intervening spaces between the values.
164453acd3b1SBarry Smith 
1645811af0c4SBarry Smith    Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
164653acd3b1SBarry Smith 
1647db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1648db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1649db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1650c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1651db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1652db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`, `PetscOptionsRealArray()`
165388aa4217SBarry Smith M*/
165488aa4217SBarry Smith 
1655d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsIntArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscInt value[], PetscInt *n, PetscBool *set)
1656d71ae5a4SJacob Faibussowitsch {
165753acd3b1SBarry Smith   PetscInt        i;
16584416b707SBarry Smith   PetscOptionItem amsopt;
165953acd3b1SBarry Smith 
166053acd3b1SBarry Smith   PetscFunctionBegin;
1661e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1662e26ddf31SBarry Smith     PetscInt *vals;
1663e26ddf31SBarry Smith 
16649566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_INT_ARRAY, &amsopt));
16659566063dSJacob Faibussowitsch     PetscCall(PetscMalloc1(*n, (PetscInt **)&amsopt->data));
1666e26ddf31SBarry Smith     vals = (PetscInt *)amsopt->data;
1667e26ddf31SBarry Smith     for (i = 0; i < *n; i++) vals[i] = value[i];
1668e26ddf31SBarry Smith     amsopt->arraylength = *n;
1669e26ddf31SBarry Smith   }
16709566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetIntArray(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, n, set));
1671e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
16729566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%" PetscInt_FMT, PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, value[0]));
167348a46eb9SPierre Jolivet     for (i = 1; i < *n; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ",%" PetscInt_FMT, value[i]));
16749566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ">: %s (%s)\n", text, ManSection(man)));
167553acd3b1SBarry Smith   }
16763ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
167753acd3b1SBarry Smith }
167853acd3b1SBarry Smith 
167988aa4217SBarry Smith /*MC
168053acd3b1SBarry Smith    PetscOptionsStringArray - Gets an array of string values for a particular
168153acd3b1SBarry Smith    option in the database. The values must be separated with commas with
168253acd3b1SBarry Smith    no intervening spaces.
168353acd3b1SBarry Smith 
1684cf53795eSBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`; No Fortran Support
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 
169053acd3b1SBarry Smith    Input Parameters:
169153acd3b1SBarry Smith +  opt - the option one is seeking
169253acd3b1SBarry Smith .  text - short string describing option
169353acd3b1SBarry Smith .  man - manual page for option
169453acd3b1SBarry Smith -  nmax - maximum number of strings
169553acd3b1SBarry Smith 
1696d8d19677SJose E. Roman    Output Parameters:
169753acd3b1SBarry Smith +  value - location to copy strings
169853acd3b1SBarry Smith .  nmax - actual number of strings found
1699811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
170053acd3b1SBarry Smith 
170153acd3b1SBarry Smith    Level: beginner
170253acd3b1SBarry Smith 
170353acd3b1SBarry Smith    Notes:
170453acd3b1SBarry Smith    The user should pass in an array of pointers to char, to hold all the
170553acd3b1SBarry Smith    strings returned by this function.
170653acd3b1SBarry Smith 
170753acd3b1SBarry Smith    The user is responsible for deallocating the strings that are
1708cf53795eSBarry Smith    returned.
170953acd3b1SBarry Smith 
1710811af0c4SBarry Smith    Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
171153acd3b1SBarry Smith 
1712db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1713db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1714db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1715c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1716db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1717db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
171888aa4217SBarry Smith M*/
171988aa4217SBarry Smith 
1720d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsStringArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], char *value[], PetscInt *nmax, PetscBool *set)
1721d71ae5a4SJacob Faibussowitsch {
17224416b707SBarry Smith   PetscOptionItem amsopt;
172353acd3b1SBarry Smith 
172453acd3b1SBarry Smith   PetscFunctionBegin;
1725e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
17269566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_STRING_ARRAY, &amsopt));
17279566063dSJacob Faibussowitsch     PetscCall(PetscMalloc1(*nmax, (char **)&amsopt->data));
1728a297a907SKarl Rupp 
17291ae3d29cSBarry Smith     amsopt->arraylength = *nmax;
17301ae3d29cSBarry Smith   }
17319566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetStringArray(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, nmax, set));
1732e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
17339566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <string1,string2,...>: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, text, ManSection(man)));
173453acd3b1SBarry Smith   }
17353ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
173653acd3b1SBarry Smith }
173753acd3b1SBarry Smith 
173888aa4217SBarry Smith /*MC
1739acfcf0e5SJed Brown    PetscOptionsBoolArray - Gets an array of logical values (true or false) for a particular
1740e2446a98SMatthew Knepley    option in the database. The values must be separated with commas with
1741e2446a98SMatthew Knepley    no intervening spaces.
1742e2446a98SMatthew Knepley 
1743811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
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 
1749e2446a98SMatthew Knepley    Input Parameters:
1750e2446a98SMatthew Knepley +  opt - the option one is seeking
1751e2446a98SMatthew Knepley .  text - short string describing option
1752e2446a98SMatthew Knepley .  man - manual page for option
1753c89788bdSBarry Smith -  n - maximum number of values allowed in the value array
1754e2446a98SMatthew Knepley 
1755d8d19677SJose E. Roman    Output Parameters:
1756e2446a98SMatthew Knepley +  value - location to copy values
1757c89788bdSBarry Smith .  n - actual number of values found
1758811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
1759e2446a98SMatthew Knepley 
1760e2446a98SMatthew Knepley    Level: beginner
1761e2446a98SMatthew Knepley 
1762e2446a98SMatthew Knepley    Notes:
1763e2446a98SMatthew Knepley    The user should pass in an array of doubles
1764e2446a98SMatthew Knepley 
1765811af0c4SBarry Smith    Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
1766e2446a98SMatthew Knepley 
1767db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1768db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1769db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1770c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1771db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1772db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
177388aa4217SBarry Smith M*/
177488aa4217SBarry Smith 
1775d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsBoolArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool value[], PetscInt *n, PetscBool *set)
1776d71ae5a4SJacob Faibussowitsch {
1777e2446a98SMatthew Knepley   PetscInt        i;
17784416b707SBarry Smith   PetscOptionItem amsopt;
1779e2446a98SMatthew Knepley 
1780e2446a98SMatthew Knepley   PetscFunctionBegin;
1781e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1782ace3abfcSBarry Smith     PetscBool *vals;
17831ae3d29cSBarry Smith 
17849566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL_ARRAY, &amsopt));
17859566063dSJacob Faibussowitsch     PetscCall(PetscMalloc1(*n, (PetscBool **)&amsopt->data));
1786ace3abfcSBarry Smith     vals = (PetscBool *)amsopt->data;
17871ae3d29cSBarry Smith     for (i = 0; i < *n; i++) vals[i] = value[i];
17881ae3d29cSBarry Smith     amsopt->arraylength = *n;
17891ae3d29cSBarry Smith   }
17909566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetBoolArray(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, n, set));
1791e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
17929566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%d", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, value[0]));
179348a46eb9SPierre Jolivet     for (i = 1; i < *n; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ",%d", value[i]));
17949566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ">: %s (%s)\n", text, ManSection(man)));
1795e2446a98SMatthew Knepley   }
17963ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1797e2446a98SMatthew Knepley }
1798e2446a98SMatthew Knepley 
179988aa4217SBarry Smith /*MC
1800d1da0b69SBarry Smith    PetscOptionsViewer - Gets a viewer appropriate for the type indicated by the user
18018cc676e6SMatthew G Knepley 
1802811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
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 
18088cc676e6SMatthew G Knepley    Input Parameters:
18098cc676e6SMatthew G Knepley +  opt - option name
18108cc676e6SMatthew G Knepley .  text - short string that describes the option
18118cc676e6SMatthew G Knepley -  man - manual page with additional information on option
18128cc676e6SMatthew G Knepley 
1813d8d19677SJose E. Roman    Output Parameters:
18148cc676e6SMatthew G Knepley +  viewer - the viewer
18157962402dSFande Kong .  format - the PetscViewerFormat requested by the user, pass NULL if not needed
1816811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
18178cc676e6SMatthew G Knepley 
18188cc676e6SMatthew G Knepley    Level: beginner
18198cc676e6SMatthew G Knepley 
182095452b02SPatrick Sanan    Notes:
1821811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
18228cc676e6SMatthew G Knepley 
1823811af0c4SBarry Smith    See `PetscOptionsGetViewer()` for the format of the supplied viewer and its options
18248cc676e6SMatthew G Knepley 
1825db781477SPatrick Sanan .seealso: `PetscOptionsGetViewer()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
1826db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`
1827db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
1828db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1829c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1830db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1831db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
183288aa4217SBarry Smith M*/
183388aa4217SBarry Smith 
1834d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsViewer_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscViewer *viewer, PetscViewerFormat *format, PetscBool *set)
1835d71ae5a4SJacob Faibussowitsch {
18364416b707SBarry Smith   PetscOptionItem amsopt;
18378cc676e6SMatthew G Knepley 
18388cc676e6SMatthew G Knepley   PetscFunctionBegin;
18391a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
18409566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_STRING, &amsopt));
184164facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
18429566063dSJacob Faibussowitsch     PetscCall(PetscStrdup("", (char **)&amsopt->data));
18438cc676e6SMatthew G Knepley   }
18449566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetViewer(PetscOptionsObject->comm, PetscOptionsObject->options, PetscOptionsObject->prefix, opt, viewer, format, set));
1845e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
18469566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%s>: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, "", text, ManSection(man)));
18478cc676e6SMatthew G Knepley   }
18483ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
18498cc676e6SMatthew G Knepley }
1850