xref: /petsc/src/sys/objects/aoptions.c (revision 811af0c4b09a35de4306c442f88bd09fdc09897d)
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 */
229371c9d4SSatish Balay PetscErrorCode PetscOptionsBegin_Private(PetscOptionItems *PetscOptionsObject, MPI_Comm comm, const char prefix[], const char title[], const char mansec[]) {
2353acd3b1SBarry Smith   PetscFunctionBegin;
24064a246eSJacob Faibussowitsch   if (prefix) PetscValidCharPointer(prefix, 3);
25064a246eSJacob Faibussowitsch   PetscValidCharPointer(title, 4);
26064a246eSJacob Faibussowitsch   if (mansec) PetscValidCharPointer(mansec, 5);
270eb63584SBarry Smith   if (!PetscOptionsObject->alreadyprinted) {
289566063dSJacob Faibussowitsch     if (!PetscOptionsHelpPrintedSingleton) PetscCall(PetscOptionsHelpPrintedCreate(&PetscOptionsHelpPrintedSingleton));
299566063dSJacob Faibussowitsch     PetscCall(PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrintedSingleton, prefix, title, &PetscOptionsObject->alreadyprinted));
300eb63584SBarry Smith   }
3102c9f0b5SLisandro Dalcin   PetscOptionsObject->next          = NULL;
32e55864a3SBarry Smith   PetscOptionsObject->comm          = comm;
33e55864a3SBarry Smith   PetscOptionsObject->changedmethod = PETSC_FALSE;
34a297a907SKarl Rupp 
359566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(prefix, &PetscOptionsObject->prefix));
369566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(title, &PetscOptionsObject->title));
3753acd3b1SBarry Smith 
389566063dSJacob Faibussowitsch   PetscCall(PetscOptionsHasHelp(PetscOptionsObject->options, &PetscOptionsObject->printhelp));
39e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1) {
4048a46eb9SPierre Jolivet     if (!PetscOptionsObject->alreadyprinted) PetscCall((*PetscHelpPrintf)(comm, "----------------------------------------\n%s:\n", title));
4161b37b28SSatish Balay   }
4253acd3b1SBarry Smith   PetscFunctionReturn(0);
4353acd3b1SBarry Smith }
4453acd3b1SBarry Smith 
453194b578SJed Brown /*
463194b578SJed Brown     Handles setting up the data structure in a call to PetscObjectOptionsBegin()
473194b578SJed Brown */
489371c9d4SSatish Balay PetscErrorCode PetscObjectOptionsBegin_Private(PetscObject obj, PetscOptionItems *PetscOptionsObject) {
493194b578SJed Brown   char      title[256];
503194b578SJed Brown   PetscBool flg;
513194b578SJed Brown 
523194b578SJed Brown   PetscFunctionBegin;
53dbbe0bcdSBarry Smith   PetscValidPointer(PetscOptionsObject, 2);
54dbbe0bcdSBarry Smith   PetscValidHeader(obj, 1);
55e55864a3SBarry Smith   PetscOptionsObject->object         = obj;
56e55864a3SBarry Smith   PetscOptionsObject->alreadyprinted = obj->optionsprinted;
57a297a907SKarl Rupp 
589566063dSJacob Faibussowitsch   PetscCall(PetscStrcmp(obj->description, obj->class_name, &flg));
599566063dSJacob Faibussowitsch   if (flg) PetscCall(PetscSNPrintf(title, sizeof(title), "%s options", obj->class_name));
609566063dSJacob Faibussowitsch   else PetscCall(PetscSNPrintf(title, sizeof(title), "%s (%s) options", obj->description, obj->class_name));
619566063dSJacob Faibussowitsch   PetscCall(PetscOptionsBegin_Private(PetscOptionsObject, obj->comm, obj->prefix, title, obj->mansec));
623194b578SJed Brown   PetscFunctionReturn(0);
633194b578SJed Brown }
643194b578SJed Brown 
6553acd3b1SBarry Smith /*
6653acd3b1SBarry Smith      Handles adding another option to the list of options within this particular PetscOptionsBegin() PetscOptionsEnd()
6753acd3b1SBarry Smith */
689371c9d4SSatish Balay static int PetscOptionItemCreate_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscOptionType t, PetscOptionItem *amsopt) {
694416b707SBarry Smith   PetscOptionItem next;
703be6e4c3SJed Brown   PetscBool       valid;
7153acd3b1SBarry Smith 
7253acd3b1SBarry Smith   PetscFunctionBegin;
739566063dSJacob Faibussowitsch   PetscCall(PetscOptionsValidKey(opt, &valid));
745f80ce2aSJacob Faibussowitsch   PetscCheck(valid, PETSC_COMM_WORLD, PETSC_ERR_ARG_INCOMP, "The option '%s' is not a valid key", opt);
753be6e4c3SJed Brown 
769566063dSJacob Faibussowitsch   PetscCall(PetscNew(amsopt));
7702c9f0b5SLisandro Dalcin   (*amsopt)->next = NULL;
7853acd3b1SBarry Smith   (*amsopt)->set  = PETSC_FALSE;
796356e834SBarry Smith   (*amsopt)->type = t;
8002c9f0b5SLisandro Dalcin   (*amsopt)->data = NULL;
8161b37b28SSatish Balay 
829566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(text, &(*amsopt)->text));
839566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(opt, &(*amsopt)->option));
849566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(man, &(*amsopt)->man));
8553acd3b1SBarry Smith 
86e55864a3SBarry Smith   if (!PetscOptionsObject->next) PetscOptionsObject->next = *amsopt;
87a297a907SKarl Rupp   else {
88e55864a3SBarry Smith     next = PetscOptionsObject->next;
8953acd3b1SBarry Smith     while (next->next) next = next->next;
9053acd3b1SBarry Smith     next->next = *amsopt;
9153acd3b1SBarry Smith   }
9253acd3b1SBarry Smith   PetscFunctionReturn(0);
9353acd3b1SBarry Smith }
9453acd3b1SBarry Smith 
95aee2cecaSBarry Smith /*
963fc1eb6aSBarry Smith     PetscScanString -  Gets user input via stdin from process and broadcasts to all processes
973fc1eb6aSBarry Smith 
98d083f849SBarry Smith     Collective
993fc1eb6aSBarry Smith 
1003fc1eb6aSBarry Smith    Input Parameters:
1013fc1eb6aSBarry Smith +     commm - communicator for the broadcast, must be PETSC_COMM_WORLD
1023fc1eb6aSBarry Smith .     n - length of the string, must be the same on all processes
1033fc1eb6aSBarry Smith -     str - location to store input
104aee2cecaSBarry Smith 
105aee2cecaSBarry Smith     Bugs:
106aee2cecaSBarry Smith .   Assumes process 0 of the given communicator has access to stdin
107aee2cecaSBarry Smith 
108aee2cecaSBarry Smith */
1099371c9d4SSatish Balay static PetscErrorCode PetscScanString(MPI_Comm comm, size_t n, char str[]) {
1103fc1eb6aSBarry Smith   PetscMPIInt rank, nm;
111aee2cecaSBarry Smith 
112aee2cecaSBarry Smith   PetscFunctionBegin;
1139566063dSJacob Faibussowitsch   PetscCallMPI(MPI_Comm_rank(comm, &rank));
114dd400576SPatrick Sanan   if (rank == 0) {
1155f80ce2aSJacob Faibussowitsch     char   c = (char)getchar();
1165f80ce2aSJacob Faibussowitsch     size_t i = 0;
1175f80ce2aSJacob Faibussowitsch 
118aee2cecaSBarry Smith     while (c != '\n' && i < n - 1) {
119aee2cecaSBarry Smith       str[i++] = c;
120aee2cecaSBarry Smith       c        = (char)getchar();
121aee2cecaSBarry Smith     }
122aee2cecaSBarry Smith     str[i] = 0;
123aee2cecaSBarry Smith   }
1249566063dSJacob Faibussowitsch   PetscCall(PetscMPIIntCast(n, &nm));
1259566063dSJacob Faibussowitsch   PetscCallMPI(MPI_Bcast(str, nm, MPI_CHAR, 0, comm));
126aee2cecaSBarry Smith   PetscFunctionReturn(0);
127aee2cecaSBarry Smith }
128aee2cecaSBarry Smith 
1295b02f95dSBarry Smith /*
1305b02f95dSBarry Smith     This is needed because certain strings may be freed by SAWs, hence we cannot use PetscStrallocpy()
1315b02f95dSBarry Smith */
1329371c9d4SSatish Balay static PetscErrorCode PetscStrdup(const char s[], char *t[]) {
13302c9f0b5SLisandro Dalcin   char *tmp = NULL;
1345b02f95dSBarry Smith 
1355b02f95dSBarry Smith   PetscFunctionBegin;
1365b02f95dSBarry Smith   if (s) {
1375f80ce2aSJacob Faibussowitsch     size_t len;
1385f80ce2aSJacob Faibussowitsch 
1399566063dSJacob Faibussowitsch     PetscCall(PetscStrlen(s, &len));
1405f80ce2aSJacob Faibussowitsch     tmp = (char *)malloc((len + 1) * sizeof(*tmp));
1415f80ce2aSJacob Faibussowitsch     PetscCheck(tmp, PETSC_COMM_SELF, PETSC_ERR_MEM, "No memory to duplicate string");
1429566063dSJacob Faibussowitsch     PetscCall(PetscStrcpy(tmp, s));
1435b02f95dSBarry Smith   }
1445b02f95dSBarry Smith   *t = tmp;
1455b02f95dSBarry Smith   PetscFunctionReturn(0);
1465b02f95dSBarry Smith }
1475b02f95dSBarry Smith 
148aee2cecaSBarry Smith /*
1493cc1e11dSBarry Smith     PetscOptionsGetFromTextInput - Presents all the PETSc Options processed by the program so the user may change them at runtime
150aee2cecaSBarry Smith 
15195452b02SPatrick Sanan     Notes:
15295452b02SPatrick Sanan     this isn't really practical, it is just to demonstrate the principle
153aee2cecaSBarry Smith 
1547781c08eSBarry Smith     A carriage return indicates no change from the default; but this like -ksp_monitor <stdout>  the default is actually not stdout the default
1557781c08eSBarry Smith     is to do nothing so to get it to use stdout you need to type stdout. This is kind of bug?
1567781c08eSBarry Smith 
157aee2cecaSBarry Smith     Bugs:
1587781c08eSBarry Smith +    All processes must traverse through the exact same set of option queries due to the call to PetscScanString()
1593cc1e11dSBarry Smith .    Internal strings have arbitrary length and string copies are not checked that they fit into string space
160aee2cecaSBarry Smith -    Only works for PetscInt == int, PetscReal == double etc
161aee2cecaSBarry Smith 
162*811af0c4SBarry Smith     Developer Note:
16395452b02SPatrick Sanan     Normally the GUI that presents the options the user and retrieves the values would be running in a different
1643cc1e11dSBarry Smith      address space and communicating with the PETSc program
1653cc1e11dSBarry Smith 
166aee2cecaSBarry Smith */
1679371c9d4SSatish Balay PetscErrorCode PetscOptionsGetFromTextInput(PetscOptionItems *PetscOptionsObject) {
1684416b707SBarry Smith   PetscOptionItem next = PetscOptionsObject->next;
1696356e834SBarry Smith   char            str[512];
1707781c08eSBarry Smith   PetscBool       bid;
171a4404d99SBarry Smith   PetscReal       ir, *valr;
172330cf3c9SBarry Smith   PetscInt       *vald;
173330cf3c9SBarry Smith   size_t          i;
1746356e834SBarry Smith 
1752a409bb0SBarry Smith   PetscFunctionBegin;
1769566063dSJacob Faibussowitsch   PetscCall((*PetscPrintf)(PETSC_COMM_WORLD, "%s --------------------\n", PetscOptionsObject->title));
1776356e834SBarry Smith   while (next) {
1786356e834SBarry Smith     switch (next->type) {
1799371c9d4SSatish Balay     case OPTION_HEAD: break;
180e26ddf31SBarry Smith     case OPTION_INT_ARRAY:
1819566063dSJacob Faibussowitsch       PetscCall(PetscPrintf(PETSC_COMM_WORLD, "-%s%s <", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1));
182e26ddf31SBarry Smith       vald = (PetscInt *)next->data;
183e26ddf31SBarry Smith       for (i = 0; i < next->arraylength; i++) {
1849566063dSJacob Faibussowitsch         PetscCall(PetscPrintf(PETSC_COMM_WORLD, "%" PetscInt_FMT, vald[i]));
18548a46eb9SPierre Jolivet         if (i < next->arraylength - 1) PetscCall(PetscPrintf(PETSC_COMM_WORLD, ","));
186e26ddf31SBarry Smith       }
1879566063dSJacob Faibussowitsch       PetscCall(PetscPrintf(PETSC_COMM_WORLD, ">: %s (%s) ", next->text, next->man));
1889566063dSJacob Faibussowitsch       PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str));
189e26ddf31SBarry Smith       if (str[0]) {
190e26ddf31SBarry Smith         PetscToken token;
191e26ddf31SBarry Smith         PetscInt   n = 0, nmax = next->arraylength, *dvalue = (PetscInt *)next->data, start, end;
192e26ddf31SBarry Smith         size_t     len;
193e26ddf31SBarry Smith         char      *value;
194ace3abfcSBarry Smith         PetscBool  foundrange;
195e26ddf31SBarry Smith 
196e26ddf31SBarry Smith         next->set = PETSC_TRUE;
197e26ddf31SBarry Smith         value     = str;
1989566063dSJacob Faibussowitsch         PetscCall(PetscTokenCreate(value, ',', &token));
1999566063dSJacob Faibussowitsch         PetscCall(PetscTokenFind(token, &value));
200e26ddf31SBarry Smith         while (n < nmax) {
201e26ddf31SBarry Smith           if (!value) break;
202e26ddf31SBarry Smith 
203e26ddf31SBarry Smith           /* look for form  d-D where d and D are integers */
204e26ddf31SBarry Smith           foundrange = PETSC_FALSE;
2059566063dSJacob Faibussowitsch           PetscCall(PetscStrlen(value, &len));
206e26ddf31SBarry Smith           if (value[0] == '-') i = 2;
207e26ddf31SBarry Smith           else i = 1;
208330cf3c9SBarry Smith           for (; i < len; i++) {
209e26ddf31SBarry Smith             if (value[i] == '-') {
21008401ef6SPierre Jolivet               PetscCheck(i != len - 1, PETSC_COMM_SELF, PETSC_ERR_USER, "Error in %" PetscInt_FMT "-th array entry %s", n, value);
211e26ddf31SBarry Smith               value[i] = 0;
2129566063dSJacob Faibussowitsch               PetscCall(PetscOptionsStringToInt(value, &start));
2139566063dSJacob Faibussowitsch               PetscCall(PetscOptionsStringToInt(value + i + 1, &end));
21408401ef6SPierre 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);
215cc73adaaSBarry 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);
216e26ddf31SBarry Smith               for (; start < end; start++) {
2179371c9d4SSatish Balay                 *dvalue = start;
2189371c9d4SSatish Balay                 dvalue++;
2199371c9d4SSatish Balay                 n++;
220e26ddf31SBarry Smith               }
221e26ddf31SBarry Smith               foundrange = PETSC_TRUE;
222e26ddf31SBarry Smith               break;
223e26ddf31SBarry Smith             }
224e26ddf31SBarry Smith           }
225e26ddf31SBarry Smith           if (!foundrange) {
2269566063dSJacob Faibussowitsch             PetscCall(PetscOptionsStringToInt(value, dvalue));
227e26ddf31SBarry Smith             dvalue++;
228e26ddf31SBarry Smith             n++;
229e26ddf31SBarry Smith           }
2309566063dSJacob Faibussowitsch           PetscCall(PetscTokenFind(token, &value));
231e26ddf31SBarry Smith         }
2329566063dSJacob Faibussowitsch         PetscCall(PetscTokenDestroy(&token));
233e26ddf31SBarry Smith       }
234e26ddf31SBarry Smith       break;
235e26ddf31SBarry Smith     case OPTION_REAL_ARRAY:
2369566063dSJacob Faibussowitsch       PetscCall(PetscPrintf(PETSC_COMM_WORLD, "-%s%s <", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1));
237e26ddf31SBarry Smith       valr = (PetscReal *)next->data;
238e26ddf31SBarry Smith       for (i = 0; i < next->arraylength; i++) {
2399566063dSJacob Faibussowitsch         PetscCall(PetscPrintf(PETSC_COMM_WORLD, "%g", (double)valr[i]));
24048a46eb9SPierre Jolivet         if (i < next->arraylength - 1) PetscCall(PetscPrintf(PETSC_COMM_WORLD, ","));
241e26ddf31SBarry Smith       }
2429566063dSJacob Faibussowitsch       PetscCall(PetscPrintf(PETSC_COMM_WORLD, ">: %s (%s) ", next->text, next->man));
2439566063dSJacob Faibussowitsch       PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str));
244e26ddf31SBarry Smith       if (str[0]) {
245e26ddf31SBarry Smith         PetscToken token;
246e26ddf31SBarry Smith         PetscInt   n = 0, nmax = next->arraylength;
247e26ddf31SBarry Smith         PetscReal *dvalue = (PetscReal *)next->data;
248e26ddf31SBarry Smith         char      *value;
249e26ddf31SBarry Smith 
250e26ddf31SBarry Smith         next->set = PETSC_TRUE;
251e26ddf31SBarry Smith         value     = str;
2529566063dSJacob Faibussowitsch         PetscCall(PetscTokenCreate(value, ',', &token));
2539566063dSJacob Faibussowitsch         PetscCall(PetscTokenFind(token, &value));
254e26ddf31SBarry Smith         while (n < nmax) {
255e26ddf31SBarry Smith           if (!value) break;
2569566063dSJacob Faibussowitsch           PetscCall(PetscOptionsStringToReal(value, dvalue));
257e26ddf31SBarry Smith           dvalue++;
258e26ddf31SBarry Smith           n++;
2599566063dSJacob Faibussowitsch           PetscCall(PetscTokenFind(token, &value));
260e26ddf31SBarry Smith         }
2619566063dSJacob Faibussowitsch         PetscCall(PetscTokenDestroy(&token));
262e26ddf31SBarry Smith       }
263e26ddf31SBarry Smith       break;
2646356e834SBarry Smith     case OPTION_INT:
2659566063dSJacob 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));
2669566063dSJacob Faibussowitsch       PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str));
2673fc1eb6aSBarry Smith       if (str[0]) {
268d25d7f95SJed Brown #if defined(PETSC_SIZEOF_LONG_LONG)
269d25d7f95SJed Brown         long long lid;
270d25d7f95SJed Brown         sscanf(str, "%lld", &lid);
271cc73adaaSBarry 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);
272c272547aSJed Brown #else
273d25d7f95SJed Brown         long lid;
274d25d7f95SJed Brown         sscanf(str, "%ld", &lid);
275cc73adaaSBarry 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);
276c272547aSJed Brown #endif
277a297a907SKarl Rupp 
278d25d7f95SJed Brown         next->set                 = PETSC_TRUE;
279d25d7f95SJed Brown         *((PetscInt *)next->data) = (PetscInt)lid;
280aee2cecaSBarry Smith       }
281aee2cecaSBarry Smith       break;
282aee2cecaSBarry Smith     case OPTION_REAL:
2839566063dSJacob 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));
2849566063dSJacob Faibussowitsch       PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str));
2853fc1eb6aSBarry Smith       if (str[0]) {
286ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE)
287a4404d99SBarry Smith         sscanf(str, "%e", &ir);
288570b7f6dSBarry Smith #elif defined(PETSC_USE_REAL___FP16)
289570b7f6dSBarry Smith         float irtemp;
290570b7f6dSBarry Smith         sscanf(str, "%e", &irtemp);
291570b7f6dSBarry Smith         ir = irtemp;
292ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE)
293aee2cecaSBarry Smith         sscanf(str, "%le", &ir);
294ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL___FLOAT128)
295d9822059SBarry Smith         ir = strtoflt128(str, 0);
296d9822059SBarry Smith #else
297513dbe71SLisandro Dalcin         SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, "Unknown scalar type");
298a4404d99SBarry Smith #endif
299aee2cecaSBarry Smith         next->set                  = PETSC_TRUE;
300aee2cecaSBarry Smith         *((PetscReal *)next->data) = ir;
301aee2cecaSBarry Smith       }
302aee2cecaSBarry Smith       break;
3037781c08eSBarry Smith     case OPTION_BOOL:
3049566063dSJacob 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));
3059566063dSJacob Faibussowitsch       PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str));
3067781c08eSBarry Smith       if (str[0]) {
3079566063dSJacob Faibussowitsch         PetscCall(PetscOptionsStringToBool(str, &bid));
3087781c08eSBarry Smith         next->set                  = PETSC_TRUE;
3097781c08eSBarry Smith         *((PetscBool *)next->data) = bid;
3107781c08eSBarry Smith       }
3117781c08eSBarry Smith       break;
312aee2cecaSBarry Smith     case OPTION_STRING:
3139566063dSJacob 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));
3149566063dSJacob Faibussowitsch       PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str));
3153fc1eb6aSBarry Smith       if (str[0]) {
316aee2cecaSBarry Smith         next->set = PETSC_TRUE;
31764facd6cSBarry Smith         /* must use system malloc since SAWs may free this */
3189566063dSJacob Faibussowitsch         PetscCall(PetscStrdup(str, (char **)&next->data));
3196356e834SBarry Smith       }
3206356e834SBarry Smith       break;
321a264d7a6SBarry Smith     case OPTION_FLIST:
3229566063dSJacob Faibussowitsch       PetscCall(PetscFunctionListPrintTypes(PETSC_COMM_WORLD, stdout, PetscOptionsObject->prefix, next->option, next->text, next->man, next->flist, (char *)next->data, (char *)next->data));
3239566063dSJacob Faibussowitsch       PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str));
3243cc1e11dSBarry Smith       if (str[0]) {
325e55864a3SBarry Smith         PetscOptionsObject->changedmethod = PETSC_TRUE;
3263cc1e11dSBarry Smith         next->set                         = PETSC_TRUE;
32764facd6cSBarry Smith         /* must use system malloc since SAWs may free this */
3289566063dSJacob Faibussowitsch         PetscCall(PetscStrdup(str, (char **)&next->data));
3293cc1e11dSBarry Smith       }
3303cc1e11dSBarry Smith       break;
3319371c9d4SSatish Balay     default: break;
3326356e834SBarry Smith     }
3336356e834SBarry Smith     next = next->next;
3346356e834SBarry Smith   }
3356356e834SBarry Smith   PetscFunctionReturn(0);
3366356e834SBarry Smith }
3376356e834SBarry Smith 
338e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS)
339e04113cfSBarry Smith #include <petscviewersaws.h>
340d5649816SBarry Smith 
341d5649816SBarry Smith static int count = 0;
342d5649816SBarry Smith 
3439371c9d4SSatish Balay PetscErrorCode PetscOptionsSAWsDestroy(void) {
3442657e9d9SBarry Smith   PetscFunctionBegin;
345d5649816SBarry Smith   PetscFunctionReturn(0);
346d5649816SBarry Smith }
347d5649816SBarry Smith 
3489c1e0ce8SBarry Smith static const char *OptionsHeader = "<head>\n"
349a8d69d7bSBarry Smith                                    "<script type=\"text/javascript\" src=\"https://www.mcs.anl.gov/research/projects/saws/js/jquery-1.9.1.js\"></script>\n"
350a8d69d7bSBarry Smith                                    "<script type=\"text/javascript\" src=\"https://www.mcs.anl.gov/research/projects/saws/js/SAWs.js\"></script>\n"
351d1fc0251SBarry Smith                                    "<script type=\"text/javascript\" src=\"js/PETSc.js\"></script>\n"
35264bbc9efSBarry Smith                                    "<script>\n"
35364bbc9efSBarry Smith                                    "jQuery(document).ready(function() {\n"
35464bbc9efSBarry Smith                                    "PETSc.getAndDisplayDirectory(null,\"#variablesInfo\")\n"
35564bbc9efSBarry Smith                                    "})\n"
35664bbc9efSBarry Smith                                    "</script>\n"
35764bbc9efSBarry Smith                                    "</head>\n";
3581423471aSBarry Smith 
3591423471aSBarry Smith /*  Determines the size and style of the scroll region where PETSc options selectable from users are displayed */
3601423471aSBarry Smith static const char *OptionsBodyBottom = "<div id=\"variablesInfo\" style=\"background-color:lightblue;height:auto;max-height:500px;overflow:scroll;\"></div>\n<br>\n</body>";
36164bbc9efSBarry Smith 
362b3506946SBarry Smith /*
3637781c08eSBarry Smith     PetscOptionsSAWsInput - Presents all the PETSc Options processed by the program so the user may change them at runtime using the SAWs
364b3506946SBarry Smith 
365b3506946SBarry Smith     Bugs:
366b3506946SBarry Smith +    All processes must traverse through the exact same set of option queries do to the call to PetscScanString()
367b3506946SBarry Smith .    Internal strings have arbitrary length and string copies are not checked that they fit into string space
368b3506946SBarry Smith -    Only works for PetscInt == int, PetscReal == double etc
369b3506946SBarry Smith 
370b3506946SBarry Smith */
3719371c9d4SSatish Balay PetscErrorCode PetscOptionsSAWsInput(PetscOptionItems *PetscOptionsObject) {
3724416b707SBarry Smith   PetscOptionItem next     = PetscOptionsObject->next;
373d5649816SBarry Smith   static int      mancount = 0;
374b3506946SBarry Smith   char            options[16];
3757aab2a10SBarry Smith   PetscBool       changedmethod = PETSC_FALSE;
376a23eb982SSurtai Han   PetscBool       stopasking    = PETSC_FALSE;
37788a9752cSBarry Smith   char            manname[16], textname[16];
3782657e9d9SBarry Smith   char            dir[1024];
379b3506946SBarry Smith 
3802a409bb0SBarry Smith   PetscFunctionBegin;
381b3506946SBarry Smith   /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */
382b3506946SBarry Smith   sprintf(options, "Options_%d", count++);
383a297a907SKarl Rupp 
3847325c4a4SBarry Smith   PetscOptionsObject->pprefix = PetscOptionsObject->prefix; /* SAWs will change this, so cannot pass prefix directly */
3851bc75a8dSBarry Smith 
3869566063dSJacob Faibussowitsch   PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", "_title"));
387792fecdfSBarry Smith   PetscCallSAWs(SAWs_Register, (dir, &PetscOptionsObject->title, 1, SAWs_READ, SAWs_STRING));
3889566063dSJacob Faibussowitsch   PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", "prefix"));
389792fecdfSBarry Smith   PetscCallSAWs(SAWs_Register, (dir, &PetscOptionsObject->pprefix, 1, SAWs_READ, SAWs_STRING));
390792fecdfSBarry Smith   PetscCallSAWs(SAWs_Register, ("/PETSc/Options/ChangedMethod", &changedmethod, 1, SAWs_WRITE, SAWs_BOOLEAN));
391792fecdfSBarry Smith   PetscCallSAWs(SAWs_Register, ("/PETSc/Options/StopAsking", &stopasking, 1, SAWs_WRITE, SAWs_BOOLEAN));
392b3506946SBarry Smith 
393b3506946SBarry Smith   while (next) {
394d50831c4SBarry Smith     sprintf(manname, "_man_%d", mancount);
3959566063dSJacob Faibussowitsch     PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", manname));
396792fecdfSBarry Smith     PetscCallSAWs(SAWs_Register, (dir, &next->man, 1, SAWs_READ, SAWs_STRING));
397d50831c4SBarry Smith     sprintf(textname, "_text_%d", mancount++);
3989566063dSJacob Faibussowitsch     PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", textname));
399792fecdfSBarry Smith     PetscCallSAWs(SAWs_Register, (dir, &next->text, 1, SAWs_READ, SAWs_STRING));
4009f32e415SBarry Smith 
401b3506946SBarry Smith     switch (next->type) {
4029371c9d4SSatish Balay     case OPTION_HEAD: break;
403b3506946SBarry Smith     case OPTION_INT_ARRAY:
4049566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
405792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, next->data, next->arraylength, SAWs_WRITE, SAWs_INT));
406b3506946SBarry Smith       break;
407b3506946SBarry Smith     case OPTION_REAL_ARRAY:
4089566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
409792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, next->data, next->arraylength, SAWs_WRITE, SAWs_DOUBLE));
410b3506946SBarry Smith       break;
411b3506946SBarry Smith     case OPTION_INT:
4129566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
413792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, next->data, 1, SAWs_WRITE, SAWs_INT));
414b3506946SBarry Smith       break;
415b3506946SBarry Smith     case OPTION_REAL:
4169566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
417792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, next->data, 1, SAWs_WRITE, SAWs_DOUBLE));
418b3506946SBarry Smith       break;
4197781c08eSBarry Smith     case OPTION_BOOL:
4209566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
421792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, next->data, 1, SAWs_WRITE, SAWs_BOOLEAN));
4221ae3d29cSBarry Smith       break;
4237781c08eSBarry Smith     case OPTION_BOOL_ARRAY:
4249566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
425792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, next->data, next->arraylength, SAWs_WRITE, SAWs_BOOLEAN));
42671f08665SBarry Smith       break;
427b3506946SBarry Smith     case OPTION_STRING:
4289566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
429792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, &next->data, 1, SAWs_WRITE, SAWs_STRING));
4301ae3d29cSBarry Smith       break;
4311ae3d29cSBarry Smith     case OPTION_STRING_ARRAY:
4329566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
433792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, next->data, next->arraylength, SAWs_WRITE, SAWs_STRING));
434b3506946SBarry Smith       break;
4359371c9d4SSatish Balay     case OPTION_FLIST: {
436a264d7a6SBarry Smith       PetscInt ntext;
4379566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
438792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, &next->data, 1, SAWs_WRITE, SAWs_STRING));
4399566063dSJacob Faibussowitsch       PetscCall(PetscFunctionListGet(next->flist, (const char ***)&next->edata, &ntext));
440792fecdfSBarry Smith       PetscCallSAWs(SAWs_Set_Legal_Variable_Values, (dir, ntext, next->edata));
4419371c9d4SSatish Balay     } break;
4429371c9d4SSatish Balay     case OPTION_ELIST: {
443a264d7a6SBarry Smith       PetscInt ntext = next->nlist;
4449566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
445792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, &next->data, 1, SAWs_WRITE, SAWs_STRING));
4469566063dSJacob Faibussowitsch       PetscCall(PetscMalloc1((ntext + 1), (char ***)&next->edata));
4479566063dSJacob Faibussowitsch       PetscCall(PetscMemcpy(next->edata, next->list, ntext * sizeof(char *)));
448792fecdfSBarry Smith       PetscCallSAWs(SAWs_Set_Legal_Variable_Values, (dir, ntext, next->edata));
4499371c9d4SSatish Balay     } break;
4509371c9d4SSatish Balay     default: break;
451b3506946SBarry Smith     }
452b3506946SBarry Smith     next = next->next;
453b3506946SBarry Smith   }
454b3506946SBarry Smith 
455b3506946SBarry Smith   /* wait until accessor has unlocked the memory */
456792fecdfSBarry Smith   PetscCallSAWs(SAWs_Push_Header, ("index.html", OptionsHeader));
457792fecdfSBarry Smith   PetscCallSAWs(SAWs_Push_Body, ("index.html", 2, OptionsBodyBottom));
4589566063dSJacob Faibussowitsch   PetscCall(PetscSAWsBlock());
459792fecdfSBarry Smith   PetscCallSAWs(SAWs_Pop_Header, ("index.html"));
460792fecdfSBarry Smith   PetscCallSAWs(SAWs_Pop_Body, ("index.html", 2));
461b3506946SBarry Smith 
46288a9752cSBarry Smith   /* determine if any values have been set in GUI */
46383355fc5SBarry Smith   next = PetscOptionsObject->next;
46488a9752cSBarry Smith   while (next) {
4659566063dSJacob Faibussowitsch     PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
466792fecdfSBarry Smith     PetscCallSAWs(SAWs_Selected, (dir, (int *)&next->set));
46788a9752cSBarry Smith     next = next->next;
46888a9752cSBarry Smith   }
46988a9752cSBarry Smith 
470b3506946SBarry Smith   /* reset counter to -2; this updates the screen with the new options for the selected method */
471f7b25cf6SBarry Smith   if (changedmethod) PetscOptionsObject->count = -2;
472b3506946SBarry Smith 
473a23eb982SSurtai Han   if (stopasking) {
474a23eb982SSurtai Han     PetscOptionsPublish       = PETSC_FALSE;
47512655325SBarry Smith     PetscOptionsObject->count = 0; //do not ask for same thing again
476a23eb982SSurtai Han   }
477a23eb982SSurtai Han 
478792fecdfSBarry Smith   PetscCallSAWs(SAWs_Delete, ("/PETSc/Options"));
479b3506946SBarry Smith   PetscFunctionReturn(0);
480b3506946SBarry Smith }
481b3506946SBarry Smith #endif
482b3506946SBarry Smith 
4839371c9d4SSatish Balay PetscErrorCode PetscOptionsEnd_Private(PetscOptionItems *PetscOptionsObject) {
4844416b707SBarry Smith   PetscOptionItem last;
4856356e834SBarry Smith   char            option[256], value[1024], tmp[32];
486330cf3c9SBarry Smith   size_t          j;
48753acd3b1SBarry Smith 
48853acd3b1SBarry Smith   PetscFunctionBegin;
48983355fc5SBarry Smith   if (PetscOptionsObject->next) {
49083355fc5SBarry Smith     if (!PetscOptionsObject->count) {
491a264d7a6SBarry Smith #if defined(PETSC_HAVE_SAWS)
4929566063dSJacob Faibussowitsch       PetscCall(PetscOptionsSAWsInput(PetscOptionsObject));
493b3506946SBarry Smith #else
4949566063dSJacob Faibussowitsch       PetscCall(PetscOptionsGetFromTextInput(PetscOptionsObject));
495b3506946SBarry Smith #endif
496aee2cecaSBarry Smith     }
497aee2cecaSBarry Smith   }
4986356e834SBarry Smith 
4999566063dSJacob Faibussowitsch   PetscCall(PetscFree(PetscOptionsObject->title));
5006356e834SBarry Smith 
501e26ddf31SBarry Smith   /* reset counter to -2; this updates the screen with the new options for the selected method */
502e55864a3SBarry Smith   if (PetscOptionsObject->changedmethod) PetscOptionsObject->count = -2;
5037a72a596SBarry Smith   /* reset alreadyprinted flag */
504e55864a3SBarry Smith   PetscOptionsObject->alreadyprinted = PETSC_FALSE;
505e55864a3SBarry Smith   if (PetscOptionsObject->object) PetscOptionsObject->object->optionsprinted = PETSC_TRUE;
506e55864a3SBarry Smith   PetscOptionsObject->object = NULL;
50753acd3b1SBarry Smith 
508e55864a3SBarry Smith   while (PetscOptionsObject->next) {
509e55864a3SBarry Smith     if (PetscOptionsObject->next->set) {
510e55864a3SBarry Smith       if (PetscOptionsObject->prefix) {
5119566063dSJacob Faibussowitsch         PetscCall(PetscStrcpy(option, "-"));
5129566063dSJacob Faibussowitsch         PetscCall(PetscStrcat(option, PetscOptionsObject->prefix));
5139566063dSJacob Faibussowitsch         PetscCall(PetscStrcat(option, PetscOptionsObject->next->option + 1));
5149566063dSJacob Faibussowitsch       } else PetscCall(PetscStrcpy(option, PetscOptionsObject->next->option));
5156356e834SBarry Smith 
516e55864a3SBarry Smith       switch (PetscOptionsObject->next->type) {
5179371c9d4SSatish Balay       case OPTION_HEAD: break;
5186356e834SBarry Smith       case OPTION_INT_ARRAY:
519e55864a3SBarry Smith         sprintf(value, "%d", (int)((PetscInt *)PetscOptionsObject->next->data)[0]);
520e55864a3SBarry Smith         for (j = 1; j < PetscOptionsObject->next->arraylength; j++) {
521e55864a3SBarry Smith           sprintf(tmp, "%d", (int)((PetscInt *)PetscOptionsObject->next->data)[j]);
5229566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, ","));
5239566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, tmp));
5246356e834SBarry Smith         }
5256356e834SBarry Smith         break;
5269371c9d4SSatish Balay       case OPTION_INT: sprintf(value, "%d", (int)*(PetscInt *)PetscOptionsObject->next->data); break;
5279371c9d4SSatish Balay       case OPTION_REAL: sprintf(value, "%g", (double)*(PetscReal *)PetscOptionsObject->next->data); break;
5286356e834SBarry Smith       case OPTION_REAL_ARRAY:
529e55864a3SBarry Smith         sprintf(value, "%g", (double)((PetscReal *)PetscOptionsObject->next->data)[0]);
530e55864a3SBarry Smith         for (j = 1; j < PetscOptionsObject->next->arraylength; j++) {
531e55864a3SBarry Smith           sprintf(tmp, "%g", (double)((PetscReal *)PetscOptionsObject->next->data)[j]);
5329566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, ","));
5339566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, tmp));
5346356e834SBarry Smith         }
5356356e834SBarry Smith         break;
536050cccc3SHong Zhang       case OPTION_SCALAR_ARRAY:
53795f3a755SJose E. Roman         sprintf(value, "%g+%gi", (double)PetscRealPart(((PetscScalar *)PetscOptionsObject->next->data)[0]), (double)PetscImaginaryPart(((PetscScalar *)PetscOptionsObject->next->data)[0]));
538050cccc3SHong Zhang         for (j = 1; j < PetscOptionsObject->next->arraylength; j++) {
53995f3a755SJose E. Roman           sprintf(tmp, "%g+%gi", (double)PetscRealPart(((PetscScalar *)PetscOptionsObject->next->data)[j]), (double)PetscImaginaryPart(((PetscScalar *)PetscOptionsObject->next->data)[j]));
5409566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, ","));
5419566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, tmp));
542050cccc3SHong Zhang         }
543050cccc3SHong Zhang         break;
5449371c9d4SSatish Balay       case OPTION_BOOL: sprintf(value, "%d", *(int *)PetscOptionsObject->next->data); break;
5457781c08eSBarry Smith       case OPTION_BOOL_ARRAY:
546e55864a3SBarry Smith         sprintf(value, "%d", (int)((PetscBool *)PetscOptionsObject->next->data)[0]);
547e55864a3SBarry Smith         for (j = 1; j < PetscOptionsObject->next->arraylength; j++) {
548e55864a3SBarry Smith           sprintf(tmp, "%d", (int)((PetscBool *)PetscOptionsObject->next->data)[j]);
5499566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, ","));
5509566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, tmp));
5511ae3d29cSBarry Smith         }
5521ae3d29cSBarry Smith         break;
5539371c9d4SSatish Balay       case OPTION_FLIST: PetscCall(PetscStrcpy(value, (char *)PetscOptionsObject->next->data)); break;
5549371c9d4SSatish Balay       case OPTION_ELIST: PetscCall(PetscStrcpy(value, (char *)PetscOptionsObject->next->data)); break;
5559371c9d4SSatish Balay       case OPTION_STRING: PetscCall(PetscStrcpy(value, (char *)PetscOptionsObject->next->data)); break;
5561ae3d29cSBarry Smith       case OPTION_STRING_ARRAY:
557e55864a3SBarry Smith         sprintf(value, "%s", ((char **)PetscOptionsObject->next->data)[0]);
558e55864a3SBarry Smith         for (j = 1; j < PetscOptionsObject->next->arraylength; j++) {
559e55864a3SBarry Smith           sprintf(tmp, "%s", ((char **)PetscOptionsObject->next->data)[j]);
5609566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, ","));
5619566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, tmp));
5621ae3d29cSBarry Smith         }
5636356e834SBarry Smith         break;
5646356e834SBarry Smith       }
5659566063dSJacob Faibussowitsch       PetscCall(PetscOptionsSetValue(PetscOptionsObject->options, option, value));
5666356e834SBarry Smith     }
56748a46eb9SPierre Jolivet     if (PetscOptionsObject->next->type == OPTION_ELIST) PetscCall(PetscStrNArrayDestroy(PetscOptionsObject->next->nlist, (char ***)&PetscOptionsObject->next->list));
5689566063dSJacob Faibussowitsch     PetscCall(PetscFree(PetscOptionsObject->next->text));
5699566063dSJacob Faibussowitsch     PetscCall(PetscFree(PetscOptionsObject->next->option));
5709566063dSJacob Faibussowitsch     PetscCall(PetscFree(PetscOptionsObject->next->man));
5719566063dSJacob Faibussowitsch     PetscCall(PetscFree(PetscOptionsObject->next->edata));
572c979a496SBarry Smith 
57383355fc5SBarry Smith     if ((PetscOptionsObject->next->type == OPTION_STRING) || (PetscOptionsObject->next->type == OPTION_FLIST) || (PetscOptionsObject->next->type == OPTION_ELIST)) {
57483355fc5SBarry Smith       free(PetscOptionsObject->next->data);
575c979a496SBarry Smith     } else {
5769566063dSJacob Faibussowitsch       PetscCall(PetscFree(PetscOptionsObject->next->data));
577c979a496SBarry Smith     }
5787781c08eSBarry Smith 
57983355fc5SBarry Smith     last                     = PetscOptionsObject->next;
58083355fc5SBarry Smith     PetscOptionsObject->next = PetscOptionsObject->next->next;
5819566063dSJacob Faibussowitsch     PetscCall(PetscFree(last));
5826356e834SBarry Smith   }
5839566063dSJacob Faibussowitsch   PetscCall(PetscFree(PetscOptionsObject->prefix));
58402c9f0b5SLisandro Dalcin   PetscOptionsObject->next = NULL;
58553acd3b1SBarry Smith   PetscFunctionReturn(0);
58653acd3b1SBarry Smith }
58753acd3b1SBarry Smith 
58888aa4217SBarry Smith /*MC
58953acd3b1SBarry Smith    PetscOptionsEnum - Gets the enum value for a particular option in the database.
59053acd3b1SBarry Smith 
591*811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
59253acd3b1SBarry Smith 
59388aa4217SBarry Smith    Synopsis:
59488aa4217SBarry Smith    #include "petscsys.h"
5953a89f35bSSatish Balay    PetscErrorCode  PetscOptionsEnum(const char opt[],const char text[],const char man[],const char *const *list,PetscEnum currentvalue,PetscEnum *value,PetscBool  *set)
59688aa4217SBarry Smith 
59753acd3b1SBarry Smith    Input Parameters:
59853acd3b1SBarry Smith +  opt - option name
59953acd3b1SBarry Smith .  text - short string that describes the option
60053acd3b1SBarry Smith .  man - manual page with additional information on option
60153acd3b1SBarry Smith .  list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null
6020fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
6030fdccdaeSBarry Smith $                 PetscOptionsEnum(..., obj->value,&object->value,...) or
6040fdccdaeSBarry Smith $                 value = defaultvalue
6050fdccdaeSBarry Smith $                 PetscOptionsEnum(..., value,&value,&flg);
6060fdccdaeSBarry Smith $                 if (flg) {
60753acd3b1SBarry Smith 
608d8d19677SJose E. Roman    Output Parameters:
60953acd3b1SBarry Smith +  value - the  value to return
610*811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
61153acd3b1SBarry Smith 
61253acd3b1SBarry Smith    Level: beginner
61353acd3b1SBarry Smith 
61495452b02SPatrick Sanan    Notes:
615*811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
61653acd3b1SBarry Smith 
617*811af0c4SBarry Smith           list is usually something like `PCASMTypes` or some other predefined list of enum names
61853acd3b1SBarry Smith 
6192efd9cb1SBarry Smith           If the user does not supply the option at all value is NOT changed. Thus
6202efd9cb1SBarry Smith           you should ALWAYS initialize value if you access it without first checking if the set flag is true.
6212efd9cb1SBarry Smith 
622989712b9SBarry Smith           The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
623989712b9SBarry Smith 
624db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
625db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
626db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
627db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
628c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
629db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
630db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
63188aa4217SBarry Smith M*/
63288aa4217SBarry Smith 
6339371c9d4SSatish Balay PetscErrorCode PetscOptionsEnum_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], const char *const *list, PetscEnum currentvalue, PetscEnum *value, PetscBool *set) {
63453acd3b1SBarry Smith   PetscInt  ntext = 0;
635aa5bb8c0SSatish Balay   PetscInt  tval;
636ace3abfcSBarry Smith   PetscBool tflg;
63753acd3b1SBarry Smith 
63853acd3b1SBarry Smith   PetscFunctionBegin;
639ad540459SPierre 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");
64008401ef6SPierre Jolivet   PetscCheck(ntext >= 3, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "List argument must have at least two entries: typename and type prefix");
64153acd3b1SBarry Smith   ntext -= 3;
6429566063dSJacob Faibussowitsch   PetscCall(PetscOptionsEList_Private(PetscOptionsObject, opt, text, man, list, ntext, list[currentvalue], &tval, &tflg));
643aa5bb8c0SSatish Balay   /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */
644aa5bb8c0SSatish Balay   if (tflg) *value = (PetscEnum)tval;
645aa5bb8c0SSatish Balay   if (set) *set = tflg;
64653acd3b1SBarry Smith   PetscFunctionReturn(0);
64753acd3b1SBarry Smith }
64853acd3b1SBarry Smith 
64988aa4217SBarry Smith /*MC
650d3e47460SLisandro Dalcin    PetscOptionsEnumArray - Gets an array of enum values for a particular
651d3e47460SLisandro Dalcin    option in the database.
652d3e47460SLisandro Dalcin 
653*811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
654d3e47460SLisandro Dalcin 
65588aa4217SBarry Smith    Synopsis:
65688aa4217SBarry Smith    #include "petscsys.h"
6573a89f35bSSatish Balay    PetscErrorCode  PetscOptionsEnumArray(const char opt[],const char text[],const char man[],const char *const *list,PetscEnum value[],PetscInt *n,PetscBool  *set)
65888aa4217SBarry Smith 
659d3e47460SLisandro Dalcin    Input Parameters:
660d3e47460SLisandro Dalcin +  opt - the option one is seeking
661d3e47460SLisandro Dalcin .  text - short string describing option
662d3e47460SLisandro Dalcin .  man - manual page for option
66322d58ec6SMatthew G. Knepley .  list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null
664c89788bdSBarry Smith -  n - maximum number of values allowed in the value array
665d3e47460SLisandro Dalcin 
666d8d19677SJose E. Roman    Output Parameters:
667d3e47460SLisandro Dalcin +  value - location to copy values
668d3e47460SLisandro Dalcin .  n - actual number of values found
669*811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
670d3e47460SLisandro Dalcin 
671d3e47460SLisandro Dalcin    Level: beginner
672d3e47460SLisandro Dalcin 
673d3e47460SLisandro Dalcin    Notes:
674d3e47460SLisandro Dalcin    The array must be passed as a comma separated list.
675d3e47460SLisandro Dalcin 
676d3e47460SLisandro Dalcin    There must be no intervening spaces between the values.
677d3e47460SLisandro Dalcin 
678*811af0c4SBarry Smith    Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
679d3e47460SLisandro Dalcin 
680db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
681db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
682db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
683c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
684db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
685db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`, `PetscOptionsRealArray()`
68688aa4217SBarry Smith M*/
68788aa4217SBarry Smith 
6889371c9d4SSatish Balay PetscErrorCode PetscOptionsEnumArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], const char *const *list, PetscEnum value[], PetscInt *n, PetscBool *set) {
689d3e47460SLisandro Dalcin   PetscInt        i, nlist = 0;
6904416b707SBarry Smith   PetscOptionItem amsopt;
691d3e47460SLisandro Dalcin 
692d3e47460SLisandro Dalcin   PetscFunctionBegin;
69308401ef6SPierre 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");
69408401ef6SPierre Jolivet   PetscCheck(nlist >= 3, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "List argument must have at least two entries: typename and type prefix");
695d3e47460SLisandro Dalcin   nlist -= 3;                            /* drop enum name, prefix, and null termination */
696d3e47460SLisandro Dalcin   if (0 && !PetscOptionsObject->count) { /* XXX Requires additional support */
697d3e47460SLisandro Dalcin     PetscEnum *vals;
6989566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_INT_ARRAY /*XXX OPTION_ENUM_ARRAY*/, &amsopt));
6999566063dSJacob Faibussowitsch     PetscCall(PetscStrNArrayallocpy(nlist, list, (char ***)&amsopt->list));
700d3e47460SLisandro Dalcin     amsopt->nlist = nlist;
7019566063dSJacob Faibussowitsch     PetscCall(PetscMalloc1(*n, (PetscEnum **)&amsopt->data));
702d3e47460SLisandro Dalcin     amsopt->arraylength = *n;
703d3e47460SLisandro Dalcin     vals                = (PetscEnum *)amsopt->data;
704d3e47460SLisandro Dalcin     for (i = 0; i < *n; i++) vals[i] = value[i];
705d3e47460SLisandro Dalcin   }
7069566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetEnumArray(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, list, value, n, set));
707d3e47460SLisandro Dalcin   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
7089566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%s", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, list[value[0]]));
7099566063dSJacob Faibussowitsch     for (i = 1; i < *n; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ",%s", list[value[i]]));
7109566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ">: %s (choose from)", text));
7119566063dSJacob Faibussowitsch     for (i = 0; i < nlist; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, " %s", list[i]));
7129566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, " (%s)\n", ManSection(man)));
713d3e47460SLisandro Dalcin   }
714d3e47460SLisandro Dalcin   PetscFunctionReturn(0);
715d3e47460SLisandro Dalcin }
716d3e47460SLisandro Dalcin 
71788aa4217SBarry Smith /*MC
7185a856986SBarry Smith    PetscOptionsBoundedInt - Gets an integer value greater than or equal a given bound for a particular option in the database.
7195a856986SBarry Smith 
720*811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
7215a856986SBarry Smith 
72288aa4217SBarry Smith    Synopsis:
72388aa4217SBarry Smith    #include "petscsys.h"
7243a89f35bSSatish Balay    PetscErrorCode  PetscOptionsBoundInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg,PetscInt bound)
72588aa4217SBarry Smith 
7265a856986SBarry Smith    Input Parameters:
7275a856986SBarry Smith +  opt - option name
7285a856986SBarry Smith .  text - short string that describes the option
7295a856986SBarry Smith .  man - manual page with additional information on option
7305a856986SBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
73188aa4217SBarry Smith $                 PetscOptionsInt(..., obj->value,&obj->value,...) or
7325a856986SBarry Smith $                 value = defaultvalue
7335a856986SBarry Smith $                 PetscOptionsInt(..., value,&value,&flg);
7345a856986SBarry Smith $                 if (flg) {
73588aa4217SBarry Smith -  bound - the requested value should be greater than or equal this bound or an error is generated
7365a856986SBarry Smith 
737d8d19677SJose E. Roman    Output Parameters:
7385a856986SBarry Smith +  value - the integer value to return
739*811af0c4SBarry Smith -  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
7405a856986SBarry Smith 
7415a856986SBarry Smith    Notes:
7425a856986SBarry Smith     If the user does not supply the option at all value is NOT changed. Thus
7435a856986SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
7445a856986SBarry Smith 
7455a856986SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
7465a856986SBarry Smith 
747*811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
7485a856986SBarry Smith 
7495a856986SBarry Smith    Level: beginner
7505a856986SBarry Smith 
751db781477SPatrick Sanan .seealso: `PetscOptionsInt()`, `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
752db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`, `PetscOptionsRangeInt()`
753db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
754db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
755c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
756db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
757db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
75888aa4217SBarry Smith M*/
7595a856986SBarry Smith 
76088aa4217SBarry Smith /*MC
7615a856986SBarry Smith    PetscOptionsRangeInt - Gets an integer value within a range of values for a particular option in the database.
7625a856986SBarry Smith 
763*811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
7645a856986SBarry Smith 
76588aa4217SBarry Smith    Synopsis:
76688aa4217SBarry Smith    #include "petscsys.h"
7673a89f35bSSatish Balay    PetscErrorCode  PetscOptionsRangeInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg,PetscInt lb,PetscInt ub)
76888aa4217SBarry Smith 
7695a856986SBarry Smith    Input Parameters:
7705a856986SBarry Smith +  opt - option name
7715a856986SBarry Smith .  text - short string that describes the option
7725a856986SBarry Smith .  man - manual page with additional information on option
7735a856986SBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
77488aa4217SBarry Smith $                 PetscOptionsInt(..., obj->value,&obj->value,...) or
7755a856986SBarry Smith $                 value = defaultvalue
7765a856986SBarry Smith $                 PetscOptionsInt(..., value,&value,&flg);
7775a856986SBarry Smith $                 if (flg) {
77888aa4217SBarry Smith .  lb - the lower bound, provided value must be greater than or equal to this value or an error is generated
77988aa4217SBarry Smith -  ub - the upper bound, provided value must be less than or equal to this value or an error is generated
7805a856986SBarry Smith 
781d8d19677SJose E. Roman    Output Parameters:
7825a856986SBarry Smith +  value - the integer value to return
783*811af0c4SBarry Smith -  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
7845a856986SBarry Smith 
7855a856986SBarry Smith    Notes:
7865a856986SBarry Smith     If the user does not supply the option at all value is NOT changed. Thus
7875a856986SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
7885a856986SBarry Smith 
7895a856986SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
7905a856986SBarry Smith 
791*811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
7925a856986SBarry Smith 
7935a856986SBarry Smith    Level: beginner
7945a856986SBarry Smith 
795db781477SPatrick Sanan .seealso: `PetscOptionsInt()`, `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
796db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`, `PetscOptionsBoundedInt()`
797db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
798db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
799c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
800db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
801db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
80288aa4217SBarry Smith M*/
8035a856986SBarry Smith 
80488aa4217SBarry Smith /*MC
80553acd3b1SBarry Smith    PetscOptionsInt - Gets the integer value for a particular option in the database.
80653acd3b1SBarry Smith 
807*811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
80853acd3b1SBarry Smith 
80988aa4217SBarry Smith    Synopsis:
81088aa4217SBarry Smith    #include "petscsys.h"
8116eeb591dSVaclav Hapla    PetscErrorCode  PetscOptionsInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg))
81288aa4217SBarry Smith 
81353acd3b1SBarry Smith    Input Parameters:
81453acd3b1SBarry Smith +  opt - option name
81553acd3b1SBarry Smith .  text - short string that describes the option
81653acd3b1SBarry Smith .  man - manual page with additional information on option
8170fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
81888aa4217SBarry Smith $                 PetscOptionsInt(..., obj->value,&obj->value,...) or
8190fdccdaeSBarry Smith $                 value = defaultvalue
8200fdccdaeSBarry Smith $                 PetscOptionsInt(..., value,&value,&flg);
8210fdccdaeSBarry Smith $                 if (flg) {
82253acd3b1SBarry Smith 
823d8d19677SJose E. Roman    Output Parameters:
82453acd3b1SBarry Smith +  value - the integer value to return
825*811af0c4SBarry Smith -  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
82653acd3b1SBarry Smith 
82795452b02SPatrick Sanan    Notes:
82895452b02SPatrick Sanan     If the user does not supply the option at all value is NOT changed. Thus
8292efd9cb1SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
8302efd9cb1SBarry Smith 
831989712b9SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
832989712b9SBarry Smith 
833*811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
83453acd3b1SBarry Smith 
8355a856986SBarry Smith    Level: beginner
8365a856986SBarry Smith 
837db781477SPatrick Sanan .seealso: `PetscOptionsBoundedInt()`, `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
838db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`, `PetscOptionsRangeInt()`
839db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
840db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
841c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
842db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
843db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
84488aa4217SBarry Smith M*/
84588aa4217SBarry Smith 
8469371c9d4SSatish Balay PetscErrorCode PetscOptionsInt_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscInt currentvalue, PetscInt *value, PetscBool *set, PetscInt lb, PetscInt ub) {
8474416b707SBarry Smith   PetscOptionItem amsopt;
84812655325SBarry Smith   PetscBool       wasset;
84953acd3b1SBarry Smith 
85053acd3b1SBarry Smith   PetscFunctionBegin;
85108401ef6SPierre Jolivet   PetscCheck(currentvalue >= lb, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Current value %" PetscInt_FMT " less than allowed bound %" PetscInt_FMT, currentvalue, lb);
85208401ef6SPierre Jolivet   PetscCheck(currentvalue <= ub, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Current value %" PetscInt_FMT " greater than allowed bound %" PetscInt_FMT, currentvalue, ub);
853e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
8549566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_INT, &amsopt));
8559566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscInt), &amsopt->data));
85612655325SBarry Smith     *(PetscInt *)amsopt->data = currentvalue;
8573e211508SBarry Smith 
8589566063dSJacob Faibussowitsch     PetscCall(PetscOptionsGetInt(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, &currentvalue, &wasset));
859ad540459SPierre Jolivet     if (wasset) *(PetscInt *)amsopt->data = currentvalue;
860af6d86caSBarry Smith   }
8619566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetInt(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, &wasset));
862cc73adaaSBarry 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);
863cc73adaaSBarry 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);
86444ef3d73SBarry Smith   if (set) *set = wasset;
865e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
8669566063dSJacob 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)));
86753acd3b1SBarry Smith   }
86853acd3b1SBarry Smith   PetscFunctionReturn(0);
86953acd3b1SBarry Smith }
87053acd3b1SBarry Smith 
87188aa4217SBarry Smith /*MC
87253acd3b1SBarry Smith    PetscOptionsString - Gets the string value for a particular option in the database.
87353acd3b1SBarry Smith 
874*811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
87553acd3b1SBarry Smith 
87688aa4217SBarry Smith    Synopsis:
87788aa4217SBarry Smith    #include "petscsys.h"
8783a89f35bSSatish Balay    PetscErrorCode  PetscOptionsString(const char opt[],const char text[],const char man[],const char currentvalue[],char value[],size_t len,PetscBool  *set)
87988aa4217SBarry Smith 
88053acd3b1SBarry Smith    Input Parameters:
88153acd3b1SBarry Smith +  opt - option name
88253acd3b1SBarry Smith .  text - short string that describes the option
88353acd3b1SBarry Smith .  man - manual page with additional information on option
8840fdccdaeSBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. This is not used to set value
885bcbf2dc5SJed Brown -  len - length of the result string including null terminator
88653acd3b1SBarry Smith 
887d8d19677SJose E. Roman    Output Parameters:
88853acd3b1SBarry Smith +  value - the value to return
889*811af0c4SBarry Smith -  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
89053acd3b1SBarry Smith 
89153acd3b1SBarry Smith    Level: beginner
89253acd3b1SBarry Smith 
89395452b02SPatrick Sanan    Notes:
894*811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
89553acd3b1SBarry Smith 
8967fccdfe4SBarry 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).
8977fccdfe4SBarry Smith 
8982efd9cb1SBarry Smith           If the user does not supply the option at all value is NOT changed. Thus
8992efd9cb1SBarry Smith           you should ALWAYS initialize value if you access it without first checking if the set flag is true.
9002efd9cb1SBarry Smith 
901989712b9SBarry Smith           The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
902989712b9SBarry Smith 
903db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
904db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
905db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
906db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
907c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
908db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
909db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
91088aa4217SBarry Smith M*/
91188aa4217SBarry Smith 
9129371c9d4SSatish Balay PetscErrorCode PetscOptionsString_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], const char currentvalue[], char value[], size_t len, PetscBool *set) {
9134416b707SBarry Smith   PetscOptionItem amsopt;
91444ef3d73SBarry Smith   PetscBool       lset;
91553acd3b1SBarry Smith 
91653acd3b1SBarry Smith   PetscFunctionBegin;
9171a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
9189566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_STRING, &amsopt));
91964facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
9209566063dSJacob Faibussowitsch     PetscCall(PetscStrdup(currentvalue ? currentvalue : "", (char **)&amsopt->data));
921af6d86caSBarry Smith   }
9229566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetString(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, len, &lset));
92344ef3d73SBarry Smith   if (set) *set = lset;
924e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
9259566063dSJacob 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)));
92653acd3b1SBarry Smith   }
92753acd3b1SBarry Smith   PetscFunctionReturn(0);
92853acd3b1SBarry Smith }
92953acd3b1SBarry Smith 
93088aa4217SBarry Smith /*MC
931*811af0c4SBarry Smith    PetscOptionsReal - Gets the `PetscReal` value for a particular option in the database.
93253acd3b1SBarry Smith 
933*811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
93453acd3b1SBarry Smith 
93588aa4217SBarry Smith    Synopsis:
93688aa4217SBarry Smith    #include "petscsys.h"
9373a89f35bSSatish Balay    PetscErrorCode  PetscOptionsReal(const char opt[],const char text[],const char man[],PetscReal currentvalue,PetscReal *value,PetscBool  *set)
93888aa4217SBarry Smith 
93953acd3b1SBarry Smith    Input Parameters:
94053acd3b1SBarry Smith +  opt - option name
94153acd3b1SBarry Smith .  text - short string that describes the option
94253acd3b1SBarry Smith .  man - manual page with additional information on option
9430fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
94488aa4217SBarry Smith $                 PetscOptionsReal(..., obj->value,&obj->value,...) or
9450fdccdaeSBarry Smith $                 value = defaultvalue
9460fdccdaeSBarry Smith $                 PetscOptionsReal(..., value,&value,&flg);
9470fdccdaeSBarry Smith $                 if (flg) {
94853acd3b1SBarry Smith 
949d8d19677SJose E. Roman    Output Parameters:
95053acd3b1SBarry Smith +  value - the value to return
951*811af0c4SBarry Smith -  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
95253acd3b1SBarry Smith 
95395452b02SPatrick Sanan    Notes:
95495452b02SPatrick Sanan     If the user does not supply the option at all value is NOT changed. Thus
9552efd9cb1SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
9562efd9cb1SBarry Smith 
957989712b9SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
958989712b9SBarry Smith 
959*811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
96053acd3b1SBarry Smith 
9615a856986SBarry Smith    Level: beginner
9625a856986SBarry Smith 
963db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
964db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
965db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
966db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
967c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
968db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
969db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
97088aa4217SBarry Smith M*/
97188aa4217SBarry Smith 
9729371c9d4SSatish Balay PetscErrorCode PetscOptionsReal_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscReal currentvalue, PetscReal *value, PetscBool *set) {
9734416b707SBarry Smith   PetscOptionItem amsopt;
97444ef3d73SBarry Smith   PetscBool       lset;
97553acd3b1SBarry Smith 
97653acd3b1SBarry Smith   PetscFunctionBegin;
977e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
9789566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_REAL, &amsopt));
9799566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscReal), &amsopt->data));
980a297a907SKarl Rupp 
9810fdccdaeSBarry Smith     *(PetscReal *)amsopt->data = currentvalue;
982538aa990SBarry Smith   }
9839566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetReal(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, &lset));
98444ef3d73SBarry Smith   if (set) *set = lset;
9851a1499c8SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
9869566063dSJacob 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)));
98753acd3b1SBarry Smith   }
98853acd3b1SBarry Smith   PetscFunctionReturn(0);
98953acd3b1SBarry Smith }
99053acd3b1SBarry Smith 
99188aa4217SBarry Smith /*MC
992*811af0c4SBarry Smith    PetscOptionsScalar - Gets the `PetscScalar` value for a particular option in the database.
99353acd3b1SBarry Smith 
994*811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
99553acd3b1SBarry Smith 
99688aa4217SBarry Smith    Synopsis:
99788aa4217SBarry Smith    #include "petscsys.h"
9983a89f35bSSatish Balay    PetscErrorCode PetscOptionsScalar(const char opt[],const char text[],const char man[],PetscScalar currentvalue,PetscScalar *value,PetscBool  *set)
99988aa4217SBarry Smith 
100053acd3b1SBarry Smith    Input Parameters:
100153acd3b1SBarry Smith +  opt - option name
100253acd3b1SBarry Smith .  text - short string that describes the option
100353acd3b1SBarry Smith .  man - manual page with additional information on option
10040fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
100588aa4217SBarry Smith $                 PetscOptionsScalar(..., obj->value,&obj->value,...) or
10060fdccdaeSBarry Smith $                 value = defaultvalue
10070fdccdaeSBarry Smith $                 PetscOptionsScalar(..., value,&value,&flg);
10080fdccdaeSBarry Smith $                 if (flg) {
10090fdccdaeSBarry Smith 
1010d8d19677SJose E. Roman    Output Parameters:
101153acd3b1SBarry Smith +  value - the value to return
1012*811af0c4SBarry Smith -  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
101353acd3b1SBarry Smith 
101495452b02SPatrick Sanan    Notes:
101595452b02SPatrick Sanan     If the user does not supply the option at all value is NOT changed. Thus
10162efd9cb1SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
10172efd9cb1SBarry Smith 
1018989712b9SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
1019989712b9SBarry Smith 
1020*811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
102153acd3b1SBarry Smith 
10225a856986SBarry Smith    Level: beginner
10235a856986SBarry Smith 
1024db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
1025db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
1026db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
1027db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1028c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1029db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1030db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
103188aa4217SBarry Smith M*/
103288aa4217SBarry Smith 
10339371c9d4SSatish Balay PetscErrorCode PetscOptionsScalar_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscScalar currentvalue, PetscScalar *value, PetscBool *set) {
103453acd3b1SBarry Smith   PetscFunctionBegin;
103553acd3b1SBarry Smith #if !defined(PETSC_USE_COMPLEX)
10369566063dSJacob Faibussowitsch   PetscCall(PetscOptionsReal(opt, text, man, currentvalue, value, set));
103753acd3b1SBarry Smith #else
10389566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetScalar(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, set));
103953acd3b1SBarry Smith #endif
104053acd3b1SBarry Smith   PetscFunctionReturn(0);
104153acd3b1SBarry Smith }
104253acd3b1SBarry Smith 
104388aa4217SBarry Smith /*MC
104490d69ab7SBarry 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
104590d69ab7SBarry Smith                       its value is set to false.
104653acd3b1SBarry Smith 
1047*811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
104853acd3b1SBarry Smith 
104988aa4217SBarry Smith    Synopsis:
105088aa4217SBarry Smith    #include "petscsys.h"
10513a89f35bSSatish Balay    PetscErrorCode PetscOptionsName(const char opt[],const char text[],const char man[],PetscBool  *flg)
105288aa4217SBarry Smith 
105353acd3b1SBarry Smith    Input Parameters:
105453acd3b1SBarry Smith +  opt - option name
105553acd3b1SBarry Smith .  text - short string that describes the option
105653acd3b1SBarry Smith -  man - manual page with additional information on option
105753acd3b1SBarry Smith 
105853acd3b1SBarry Smith    Output Parameter:
1059*811af0c4SBarry Smith .  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
106053acd3b1SBarry Smith 
106153acd3b1SBarry Smith    Level: beginner
106253acd3b1SBarry Smith 
1063*811af0c4SBarry Smith    Note:
1064*811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
106553acd3b1SBarry Smith 
1066db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
1067db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
1068db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
1069db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1070c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1071db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1072db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
107388aa4217SBarry Smith M*/
107488aa4217SBarry Smith 
10759371c9d4SSatish Balay PetscErrorCode PetscOptionsName_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool *flg) {
10764416b707SBarry Smith   PetscOptionItem amsopt;
107753acd3b1SBarry Smith 
107853acd3b1SBarry Smith   PetscFunctionBegin;
1079e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
10809566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt));
10819566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data));
1082a297a907SKarl Rupp 
1083ace3abfcSBarry Smith     *(PetscBool *)amsopt->data = PETSC_FALSE;
10841ae3d29cSBarry Smith   }
10859566063dSJacob Faibussowitsch   PetscCall(PetscOptionsHasName(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, flg));
1086e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
10879566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, text, ManSection(man)));
108853acd3b1SBarry Smith   }
108953acd3b1SBarry Smith   PetscFunctionReturn(0);
109053acd3b1SBarry Smith }
109153acd3b1SBarry Smith 
109288aa4217SBarry Smith /*MC
1093a264d7a6SBarry Smith      PetscOptionsFList - Puts a list of option values that a single one may be selected from
109453acd3b1SBarry Smith 
1095*811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
109653acd3b1SBarry Smith 
109788aa4217SBarry Smith    Synopsis:
109888aa4217SBarry Smith    #include "petscsys.h"
10993a89f35bSSatish Balay    PetscErrorCode  PetscOptionsFList(const char opt[],const char ltext[],const char man[],PetscFunctionList list,const char currentvalue[],char value[],size_t len,PetscBool  *set)
110088aa4217SBarry Smith 
110153acd3b1SBarry Smith    Input Parameters:
110253acd3b1SBarry Smith +  opt - option name
110353acd3b1SBarry Smith .  text - short string that describes the option
110453acd3b1SBarry Smith .  man - manual page with additional information on option
110553acd3b1SBarry Smith .  list - the possible choices
11060fdccdaeSBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with
11070fdccdaeSBarry Smith $                 PetscOptionsFlist(..., obj->value,value,len,&flg);
11080fdccdaeSBarry Smith $                 if (flg) {
11093cc1e11dSBarry Smith -  len - the length of the character array value
111053acd3b1SBarry Smith 
1111d8d19677SJose E. Roman    Output Parameters:
111253acd3b1SBarry Smith +  value - the value to return
1113*811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
111453acd3b1SBarry Smith 
111553acd3b1SBarry Smith    Level: intermediate
111653acd3b1SBarry Smith 
111795452b02SPatrick Sanan    Notes:
1118*811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
111953acd3b1SBarry Smith 
11202efd9cb1SBarry Smith           If the user does not supply the option at all value is NOT changed. Thus
11212efd9cb1SBarry Smith           you should ALWAYS initialize value if you access it without first checking if the set flag is true.
11222efd9cb1SBarry Smith 
1123989712b9SBarry Smith           The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
1124989712b9SBarry Smith 
1125*811af0c4SBarry Smith    See `PetscOptionsEList()` for when the choices are given in a string array
112653acd3b1SBarry Smith 
112753acd3b1SBarry Smith    To get a listing of all currently specified options,
1128*811af0c4SBarry Smith     see `PetscOptionsView()` or `PetscOptionsGetAll()`
112953acd3b1SBarry Smith 
1130*811af0c4SBarry Smith    Developer Note:
1131*811af0c4SBarry Smith    This cannot check for invalid selection because of things like `MATAIJ` that are not included in the list
1132eabe10d7SBarry Smith 
1133db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1134db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1135db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1136c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1137db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1138db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`, `PetscOptionsEnum()`
113988aa4217SBarry Smith M*/
114088aa4217SBarry Smith 
11419371c9d4SSatish Balay 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) {
11424416b707SBarry Smith   PetscOptionItem amsopt;
114344ef3d73SBarry Smith   PetscBool       lset;
114453acd3b1SBarry Smith 
114553acd3b1SBarry Smith   PetscFunctionBegin;
11461a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
11479566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, ltext, man, OPTION_FLIST, &amsopt));
114864facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
11499566063dSJacob Faibussowitsch     PetscCall(PetscStrdup(currentvalue ? currentvalue : "", (char **)&amsopt->data));
11503cc1e11dSBarry Smith     amsopt->flist = list;
11513cc1e11dSBarry Smith   }
11529566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetString(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, len, &lset));
115344ef3d73SBarry Smith   if (set) *set = lset;
11541a1499c8SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
11559566063dSJacob Faibussowitsch     PetscCall(PetscFunctionListPrintTypes(PetscOptionsObject->comm, stdout, PetscOptionsObject->prefix, opt, ltext, man, list, currentvalue, lset && value ? value : currentvalue));
115653acd3b1SBarry Smith   }
115753acd3b1SBarry Smith   PetscFunctionReturn(0);
115853acd3b1SBarry Smith }
115953acd3b1SBarry Smith 
116088aa4217SBarry Smith /*MC
116153acd3b1SBarry Smith      PetscOptionsEList - Puts a list of option values that a single one may be selected from
116253acd3b1SBarry Smith 
1163*811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
116453acd3b1SBarry Smith 
116588aa4217SBarry Smith    Synopsis:
116688aa4217SBarry Smith    #include "petscsys.h"
11673a89f35bSSatish 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)
116888aa4217SBarry Smith 
116953acd3b1SBarry Smith    Input Parameters:
117053acd3b1SBarry Smith +  opt - option name
117153acd3b1SBarry Smith .  ltext - short string that describes the option
117253acd3b1SBarry Smith .  man - manual page with additional information on option
1173a264d7a6SBarry Smith .  list - the possible choices (one of these must be selected, anything else is invalid)
117453acd3b1SBarry Smith .  ntext - number of choices
11750fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with
11760fdccdaeSBarry Smith $                 PetscOptionsElist(..., obj->value,&value,&flg);
11770fdccdaeSBarry Smith $                 if (flg) {
11780fdccdaeSBarry Smith 
1179d8d19677SJose E. Roman    Output Parameters:
118053acd3b1SBarry Smith +  value - the index of the value to return
1181*811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
118253acd3b1SBarry Smith 
118353acd3b1SBarry Smith    Level: intermediate
118453acd3b1SBarry Smith 
118595452b02SPatrick Sanan    Notes:
1186*811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
118753acd3b1SBarry Smith 
11882efd9cb1SBarry Smith          If the user does not supply the option at all value is NOT changed. Thus
11892efd9cb1SBarry Smith           you should ALWAYS initialize value if you access it without first checking if the set flag is true.
11902efd9cb1SBarry Smith 
1191*811af0c4SBarry Smith    See `PetscOptionsFList()` for when the choices are given in a `PetscFunctionList()`
119253acd3b1SBarry Smith 
1193db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1194db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1195db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1196c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1197db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1198db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEnum()`
119988aa4217SBarry Smith M*/
120088aa4217SBarry Smith 
12019371c9d4SSatish Balay 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) {
120253acd3b1SBarry Smith   PetscInt        i;
12034416b707SBarry Smith   PetscOptionItem amsopt;
120444ef3d73SBarry Smith   PetscBool       lset;
120553acd3b1SBarry Smith 
120653acd3b1SBarry Smith   PetscFunctionBegin;
12071a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
12089566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, ltext, man, OPTION_ELIST, &amsopt));
120964facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
12109566063dSJacob Faibussowitsch     PetscCall(PetscStrdup(currentvalue ? currentvalue : "", (char **)&amsopt->data));
12119566063dSJacob Faibussowitsch     PetscCall(PetscStrNArrayallocpy(ntext, list, (char ***)&amsopt->list));
12121ae3d29cSBarry Smith     amsopt->nlist = ntext;
12131ae3d29cSBarry Smith   }
12149566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetEList(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, list, ntext, value, &lset));
121544ef3d73SBarry Smith   if (set) *set = lset;
12161a1499c8SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
12179566063dSJacob 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));
121848a46eb9SPierre Jolivet     for (i = 0; i < ntext; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, " %s", list[i]));
12199566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, " (%s)\n", ManSection(man)));
122053acd3b1SBarry Smith   }
122153acd3b1SBarry Smith   PetscFunctionReturn(0);
122253acd3b1SBarry Smith }
122353acd3b1SBarry Smith 
122488aa4217SBarry Smith /*MC
1225acfcf0e5SJed Brown      PetscOptionsBoolGroupBegin - First in a series of logical queries on the options database for
1226d5649816SBarry Smith        which at most a single value can be true.
122753acd3b1SBarry Smith 
1228*811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
122953acd3b1SBarry Smith 
123088aa4217SBarry Smith    Synopsis:
123188aa4217SBarry Smith    #include "petscsys.h"
12323a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolGroupBegin(const char opt[],const char text[],const char man[],PetscBool  *flg)
123388aa4217SBarry Smith 
123453acd3b1SBarry Smith    Input Parameters:
123553acd3b1SBarry Smith +  opt - option name
123653acd3b1SBarry Smith .  text - short string that describes the option
123753acd3b1SBarry Smith -  man - manual page with additional information on option
123853acd3b1SBarry Smith 
123953acd3b1SBarry Smith    Output Parameter:
124053acd3b1SBarry Smith .  flg - whether that option was set or not
124153acd3b1SBarry Smith 
124253acd3b1SBarry Smith    Level: intermediate
124353acd3b1SBarry Smith 
124495452b02SPatrick Sanan    Notes:
1245*811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
124653acd3b1SBarry Smith 
1247*811af0c4SBarry Smith    Must be followed by 0 or more P`etscOptionsBoolGroup()`s and `PetscOptionsBoolGroupEnd()`
124853acd3b1SBarry Smith 
1249db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1250db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1251db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1252c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1253db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1254db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
125588aa4217SBarry Smith M*/
125688aa4217SBarry Smith 
12579371c9d4SSatish Balay PetscErrorCode PetscOptionsBoolGroupBegin_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool *flg) {
12584416b707SBarry Smith   PetscOptionItem amsopt;
125953acd3b1SBarry Smith 
126053acd3b1SBarry Smith   PetscFunctionBegin;
1261e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
12629566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt));
12639566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data));
1264a297a907SKarl Rupp 
1265ace3abfcSBarry Smith     *(PetscBool *)amsopt->data = PETSC_FALSE;
12661ae3d29cSBarry Smith   }
126768b16fdaSBarry Smith   *flg = PETSC_FALSE;
12689566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetBool(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, flg, NULL));
1269e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
12709566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  Pick at most one of -------------\n"));
12719566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "    -%s%s: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, text, ManSection(man)));
127253acd3b1SBarry Smith   }
127353acd3b1SBarry Smith   PetscFunctionReturn(0);
127453acd3b1SBarry Smith }
127553acd3b1SBarry Smith 
127688aa4217SBarry Smith /*MC
1277acfcf0e5SJed Brown      PetscOptionsBoolGroup - One in a series of logical queries on the options database for
1278d5649816SBarry Smith        which at most a single value can be true.
127953acd3b1SBarry Smith 
1280*811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
128153acd3b1SBarry Smith 
128288aa4217SBarry Smith    Synopsis:
128388aa4217SBarry Smith    #include "petscsys.h"
12843a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolGroup(const char opt[],const char text[],const char man[],PetscBool  *flg)
128588aa4217SBarry Smith 
128653acd3b1SBarry Smith    Input Parameters:
128753acd3b1SBarry Smith +  opt - option name
128853acd3b1SBarry Smith .  text - short string that describes the option
128953acd3b1SBarry Smith -  man - manual page with additional information on option
129053acd3b1SBarry Smith 
129153acd3b1SBarry Smith    Output Parameter:
1292*811af0c4SBarry Smith .  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
129353acd3b1SBarry Smith 
129453acd3b1SBarry Smith    Level: intermediate
129553acd3b1SBarry Smith 
129695452b02SPatrick Sanan    Notes:
1297*811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
129853acd3b1SBarry Smith 
1299*811af0c4SBarry Smith    Must follow a `PetscOptionsBoolGroupBegin()` and preceded a `PetscOptionsBoolGroupEnd()`
130053acd3b1SBarry Smith 
1301db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1302db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1303db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1304c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1305db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1306db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
130788aa4217SBarry Smith M*/
130888aa4217SBarry Smith 
13099371c9d4SSatish Balay PetscErrorCode PetscOptionsBoolGroup_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool *flg) {
13104416b707SBarry Smith   PetscOptionItem amsopt;
131153acd3b1SBarry Smith 
131253acd3b1SBarry Smith   PetscFunctionBegin;
1313e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
13149566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt));
13159566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data));
1316a297a907SKarl Rupp 
1317ace3abfcSBarry Smith     *(PetscBool *)amsopt->data = PETSC_FALSE;
13181ae3d29cSBarry Smith   }
131917326d04SJed Brown   *flg = PETSC_FALSE;
13209566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetBool(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, flg, NULL));
1321e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
13229566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "    -%s%s: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, text, ManSection(man)));
132353acd3b1SBarry Smith   }
132453acd3b1SBarry Smith   PetscFunctionReturn(0);
132553acd3b1SBarry Smith }
132653acd3b1SBarry Smith 
132788aa4217SBarry Smith /*MC
1328acfcf0e5SJed Brown      PetscOptionsBoolGroupEnd - Last in a series of logical queries on the options database for
1329d5649816SBarry Smith        which at most a single value can be true.
133053acd3b1SBarry Smith 
1331*811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
133253acd3b1SBarry Smith 
133388aa4217SBarry Smith    Synopsis:
133488aa4217SBarry Smith    #include "petscsys.h"
13353a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolGroupEnd(const char opt[],const char text[],const char man[],PetscBool  *flg)
133688aa4217SBarry Smith 
133753acd3b1SBarry Smith    Input Parameters:
133853acd3b1SBarry Smith +  opt - option name
133953acd3b1SBarry Smith .  text - short string that describes the option
134053acd3b1SBarry Smith -  man - manual page with additional information on option
134153acd3b1SBarry Smith 
134253acd3b1SBarry Smith    Output Parameter:
1343*811af0c4SBarry Smith .  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
134453acd3b1SBarry Smith 
134553acd3b1SBarry Smith    Level: intermediate
134653acd3b1SBarry Smith 
134795452b02SPatrick Sanan    Notes:
1348*811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
134953acd3b1SBarry Smith 
1350*811af0c4SBarry Smith    Must follow a `PetscOptionsBoolGroupBegin()`
135153acd3b1SBarry Smith 
1352db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1353db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1354db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1355c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1356db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1357db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
135888aa4217SBarry Smith M*/
135988aa4217SBarry Smith 
13609371c9d4SSatish Balay PetscErrorCode PetscOptionsBoolGroupEnd_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool *flg) {
13614416b707SBarry Smith   PetscOptionItem amsopt;
136253acd3b1SBarry Smith 
136353acd3b1SBarry Smith   PetscFunctionBegin;
1364e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
13659566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt));
13669566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data));
1367a297a907SKarl Rupp 
1368ace3abfcSBarry Smith     *(PetscBool *)amsopt->data = PETSC_FALSE;
13691ae3d29cSBarry Smith   }
137017326d04SJed Brown   *flg = PETSC_FALSE;
13719566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetBool(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, flg, NULL));
1372e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
13739566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "    -%s%s: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, text, ManSection(man)));
137453acd3b1SBarry Smith   }
137553acd3b1SBarry Smith   PetscFunctionReturn(0);
137653acd3b1SBarry Smith }
137753acd3b1SBarry Smith 
137888aa4217SBarry Smith /*MC
1379acfcf0e5SJed Brown    PetscOptionsBool - Determines if a particular option is in the database with a true or false
138053acd3b1SBarry Smith 
1381*811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
138253acd3b1SBarry Smith 
138388aa4217SBarry Smith    Synopsis:
138488aa4217SBarry Smith    #include "petscsys.h"
13853a89f35bSSatish Balay    PetscErrorCode PetscOptionsBool(const char opt[],const char text[],const char man[],PetscBool currentvalue,PetscBool  *flg,PetscBool  *set)
138688aa4217SBarry Smith 
138753acd3b1SBarry Smith    Input Parameters:
138853acd3b1SBarry Smith +  opt - option name
138953acd3b1SBarry Smith .  text - short string that describes the option
1390868c398cSBarry Smith .  man - manual page with additional information on option
139194ae4db5SBarry Smith -  currentvalue - the current value
139253acd3b1SBarry Smith 
1393d8d19677SJose E. Roman    Output Parameters:
1394*811af0c4SBarry Smith +  flg -` PETSC_TRUE` or `PETSC_FALSE`
1395*811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
139653acd3b1SBarry Smith 
13972efd9cb1SBarry Smith    Notes:
1398*811af0c4SBarry Smith        TRUE, true, YES, yes, nostring, and 1 all translate to `PETSC_TRUE`
1399*811af0c4SBarry Smith        FALSE, false, NO, no, and 0 all translate to `PETSC_FALSE`
14002efd9cb1SBarry Smith 
1401*811af0c4SBarry 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
14022efd9cb1SBarry Smith      is equivalent to -requested_bool true
14032efd9cb1SBarry Smith 
14042efd9cb1SBarry Smith        If the user does not supply the option at all flg is NOT changed. Thus
14052efd9cb1SBarry Smith      you should ALWAYS initialize the flg if you access it without first checking if the set flag is true.
14062efd9cb1SBarry Smith 
1407*811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
140853acd3b1SBarry Smith 
14095a856986SBarry Smith    Level: beginner
14105a856986SBarry Smith 
1411db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
1412db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
1413db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`,
1414db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1415c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1416db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1417db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
141888aa4217SBarry Smith M*/
141988aa4217SBarry Smith 
14209371c9d4SSatish Balay PetscErrorCode PetscOptionsBool_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool currentvalue, PetscBool *flg, PetscBool *set) {
1421ace3abfcSBarry Smith   PetscBool       iset;
14224416b707SBarry Smith   PetscOptionItem amsopt;
142353acd3b1SBarry Smith 
142453acd3b1SBarry Smith   PetscFunctionBegin;
1425e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
14269566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt));
14279566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data));
1428a297a907SKarl Rupp 
142994ae4db5SBarry Smith     *(PetscBool *)amsopt->data = currentvalue;
1430af6d86caSBarry Smith   }
14319566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetBool(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, flg, &iset));
143253acd3b1SBarry Smith   if (set) *set = iset;
14331a1499c8SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
143444ef3d73SBarry Smith     const char *v = PetscBools[currentvalue], *vn = PetscBools[iset && flg ? *flg : currentvalue];
14359566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s: <%s : %s> %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, v, vn, text, ManSection(man)));
143653acd3b1SBarry Smith   }
143753acd3b1SBarry Smith   PetscFunctionReturn(0);
143853acd3b1SBarry Smith }
143953acd3b1SBarry Smith 
144088aa4217SBarry Smith /*MC
144153acd3b1SBarry Smith    PetscOptionsRealArray - Gets an array of double values for a particular
144253acd3b1SBarry Smith    option in the database. The values must be separated with commas with
144353acd3b1SBarry Smith    no intervening spaces.
144453acd3b1SBarry Smith 
1445*811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
144653acd3b1SBarry Smith 
144788aa4217SBarry Smith    Synopsis:
144888aa4217SBarry Smith    #include "petscsys.h"
14493a89f35bSSatish Balay    PetscErrorCode PetscOptionsRealArray(const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscBool  *set)
145088aa4217SBarry Smith 
145153acd3b1SBarry Smith    Input Parameters:
145253acd3b1SBarry Smith +  opt - the option one is seeking
145353acd3b1SBarry Smith .  text - short string describing option
145453acd3b1SBarry Smith .  man - manual page for option
1455c89788bdSBarry Smith -  n - maximum number of values that value has room for
145653acd3b1SBarry Smith 
1457d8d19677SJose E. Roman    Output Parameters:
145853acd3b1SBarry Smith +  value - location to copy values
1459c89788bdSBarry Smith .  n - actual number of values found
1460*811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
146153acd3b1SBarry Smith 
146253acd3b1SBarry Smith    Level: beginner
146353acd3b1SBarry Smith 
1464*811af0c4SBarry Smith    Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
146553acd3b1SBarry Smith 
1466db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1467db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1468db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1469c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1470db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1471db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
147288aa4217SBarry Smith M*/
147388aa4217SBarry Smith 
14749371c9d4SSatish Balay PetscErrorCode PetscOptionsRealArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscReal value[], PetscInt *n, PetscBool *set) {
147553acd3b1SBarry Smith   PetscInt        i;
14764416b707SBarry Smith   PetscOptionItem amsopt;
147753acd3b1SBarry Smith 
147853acd3b1SBarry Smith   PetscFunctionBegin;
1479e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1480e26ddf31SBarry Smith     PetscReal *vals;
1481e26ddf31SBarry Smith 
14829566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_REAL_ARRAY, &amsopt));
14839566063dSJacob Faibussowitsch     PetscCall(PetscMalloc((*n) * sizeof(PetscReal), &amsopt->data));
1484e26ddf31SBarry Smith     vals = (PetscReal *)amsopt->data;
1485e26ddf31SBarry Smith     for (i = 0; i < *n; i++) vals[i] = value[i];
1486e26ddf31SBarry Smith     amsopt->arraylength = *n;
1487e26ddf31SBarry Smith   }
14889566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetRealArray(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, n, set));
1489e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
14909566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%g", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, (double)value[0]));
149148a46eb9SPierre Jolivet     for (i = 1; i < *n; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ",%g", (double)value[i]));
14929566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ">: %s (%s)\n", text, ManSection(man)));
149353acd3b1SBarry Smith   }
149453acd3b1SBarry Smith   PetscFunctionReturn(0);
149553acd3b1SBarry Smith }
149653acd3b1SBarry Smith 
149788aa4217SBarry Smith /*MC
1498*811af0c4SBarry Smith    PetscOptionsScalarArray - Gets an array of `PetscScalar` values for a particular
1499050cccc3SHong Zhang    option in the database. The values must be separated with commas with
1500050cccc3SHong Zhang    no intervening spaces.
1501050cccc3SHong Zhang 
1502*811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
1503050cccc3SHong Zhang 
150488aa4217SBarry Smith    Synopsis:
150588aa4217SBarry Smith    #include "petscsys.h"
15063a89f35bSSatish Balay    PetscErrorCode PetscOptionsScalarArray(const char opt[],const char text[],const char man[],PetscScalar value[],PetscInt *n,PetscBool  *set)
150788aa4217SBarry Smith 
1508050cccc3SHong Zhang    Input Parameters:
1509050cccc3SHong Zhang +  opt - the option one is seeking
1510050cccc3SHong Zhang .  text - short string describing option
1511050cccc3SHong Zhang .  man - manual page for option
1512c89788bdSBarry Smith -  n - maximum number of values allowed in the value array
1513050cccc3SHong Zhang 
1514d8d19677SJose E. Roman    Output Parameters:
1515050cccc3SHong Zhang +  value - location to copy values
1516c89788bdSBarry Smith .  n - actual number of values found
1517*811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
1518050cccc3SHong Zhang 
1519050cccc3SHong Zhang    Level: beginner
1520050cccc3SHong Zhang 
1521*811af0c4SBarry Smith    Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
1522050cccc3SHong Zhang 
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 
15319371c9d4SSatish Balay PetscErrorCode PetscOptionsScalarArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscScalar value[], PetscInt *n, PetscBool *set) {
1532050cccc3SHong Zhang   PetscInt        i;
15334416b707SBarry Smith   PetscOptionItem amsopt;
1534050cccc3SHong Zhang 
1535050cccc3SHong Zhang   PetscFunctionBegin;
1536050cccc3SHong Zhang   if (!PetscOptionsObject->count) {
1537050cccc3SHong Zhang     PetscScalar *vals;
1538050cccc3SHong Zhang 
15399566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_SCALAR_ARRAY, &amsopt));
15409566063dSJacob Faibussowitsch     PetscCall(PetscMalloc((*n) * sizeof(PetscScalar), &amsopt->data));
1541050cccc3SHong Zhang     vals = (PetscScalar *)amsopt->data;
1542050cccc3SHong Zhang     for (i = 0; i < *n; i++) vals[i] = value[i];
1543050cccc3SHong Zhang     amsopt->arraylength = *n;
1544050cccc3SHong Zhang   }
15459566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetScalarArray(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, n, set));
1546050cccc3SHong Zhang   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
15479566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%g+%gi", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, (double)PetscRealPart(value[0]), (double)PetscImaginaryPart(value[0])));
154848a46eb9SPierre Jolivet     for (i = 1; i < *n; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ",%g+%gi", (double)PetscRealPart(value[i]), (double)PetscImaginaryPart(value[i])));
15499566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ">: %s (%s)\n", text, ManSection(man)));
1550050cccc3SHong Zhang   }
1551050cccc3SHong Zhang   PetscFunctionReturn(0);
1552050cccc3SHong Zhang }
155353acd3b1SBarry Smith 
155488aa4217SBarry Smith /*MC
155553acd3b1SBarry Smith    PetscOptionsIntArray - Gets an array of integers for a particular
1556b32a342fSShri Abhyankar    option in the database.
155753acd3b1SBarry Smith 
1558*811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
155953acd3b1SBarry Smith 
156088aa4217SBarry Smith    Synopsis:
156188aa4217SBarry Smith    #include "petscsys.h"
15623a89f35bSSatish Balay    PetscErrorCode PetscOptionsIntArray(const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscBool  *set)
156388aa4217SBarry Smith 
156453acd3b1SBarry Smith    Input Parameters:
156553acd3b1SBarry Smith +  opt - the option one is seeking
156653acd3b1SBarry Smith .  text - short string describing option
156753acd3b1SBarry Smith .  man - manual page for option
1568f8a50e2bSBarry Smith -  n - maximum number of values
156953acd3b1SBarry Smith 
1570d8d19677SJose E. Roman    Output Parameters:
157153acd3b1SBarry Smith +  value - location to copy values
1572f8a50e2bSBarry Smith .  n - actual number of values found
1573*811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
157453acd3b1SBarry Smith 
157553acd3b1SBarry Smith    Level: beginner
157653acd3b1SBarry Smith 
157753acd3b1SBarry Smith    Notes:
1578b32a342fSShri Abhyankar    The array can be passed as
1579*811af0c4SBarry Smith +   a comma separated list -                                  0,1,2,3,4,5,6,7
1580*811af0c4SBarry Smith .   a range (start\-end+1) -                                  0-8
1581*811af0c4SBarry Smith .   a range with given increment (start\-end+1:inc) -         0-7:2
1582*811af0c4SBarry Smith -   a combination of values and ranges separated by commas -  0,1-8,8-15:2
1583b32a342fSShri Abhyankar 
1584b32a342fSShri Abhyankar    There must be no intervening spaces between the values.
158553acd3b1SBarry Smith 
1586*811af0c4SBarry Smith    Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
158753acd3b1SBarry Smith 
1588db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1589db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1590db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1591c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1592db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1593db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`, `PetscOptionsRealArray()`
159488aa4217SBarry Smith M*/
159588aa4217SBarry Smith 
15969371c9d4SSatish Balay PetscErrorCode PetscOptionsIntArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscInt value[], PetscInt *n, PetscBool *set) {
159753acd3b1SBarry Smith   PetscInt        i;
15984416b707SBarry Smith   PetscOptionItem amsopt;
159953acd3b1SBarry Smith 
160053acd3b1SBarry Smith   PetscFunctionBegin;
1601e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1602e26ddf31SBarry Smith     PetscInt *vals;
1603e26ddf31SBarry Smith 
16049566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_INT_ARRAY, &amsopt));
16059566063dSJacob Faibussowitsch     PetscCall(PetscMalloc1(*n, (PetscInt **)&amsopt->data));
1606e26ddf31SBarry Smith     vals = (PetscInt *)amsopt->data;
1607e26ddf31SBarry Smith     for (i = 0; i < *n; i++) vals[i] = value[i];
1608e26ddf31SBarry Smith     amsopt->arraylength = *n;
1609e26ddf31SBarry Smith   }
16109566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetIntArray(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, n, set));
1611e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
16129566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%" PetscInt_FMT, PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, value[0]));
161348a46eb9SPierre Jolivet     for (i = 1; i < *n; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ",%" PetscInt_FMT, value[i]));
16149566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ">: %s (%s)\n", text, ManSection(man)));
161553acd3b1SBarry Smith   }
161653acd3b1SBarry Smith   PetscFunctionReturn(0);
161753acd3b1SBarry Smith }
161853acd3b1SBarry Smith 
161988aa4217SBarry Smith /*MC
162053acd3b1SBarry Smith    PetscOptionsStringArray - Gets an array of string values for a particular
162153acd3b1SBarry Smith    option in the database. The values must be separated with commas with
162253acd3b1SBarry Smith    no intervening spaces.
162353acd3b1SBarry Smith 
1624*811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
162553acd3b1SBarry Smith 
162688aa4217SBarry Smith    Synopsis:
162788aa4217SBarry Smith    #include "petscsys.h"
16283a89f35bSSatish Balay    PetscErrorCode PetscOptionsStringArray(const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscBool  *set)
162988aa4217SBarry Smith 
163053acd3b1SBarry Smith    Input Parameters:
163153acd3b1SBarry Smith +  opt - the option one is seeking
163253acd3b1SBarry Smith .  text - short string describing option
163353acd3b1SBarry Smith .  man - manual page for option
163453acd3b1SBarry Smith -  nmax - maximum number of strings
163553acd3b1SBarry Smith 
1636d8d19677SJose E. Roman    Output Parameters:
163753acd3b1SBarry Smith +  value - location to copy strings
163853acd3b1SBarry Smith .  nmax - actual number of strings found
1639*811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
164053acd3b1SBarry Smith 
164153acd3b1SBarry Smith    Level: beginner
164253acd3b1SBarry Smith 
164353acd3b1SBarry Smith    Notes:
164453acd3b1SBarry Smith    The user should pass in an array of pointers to char, to hold all the
164553acd3b1SBarry Smith    strings returned by this function.
164653acd3b1SBarry Smith 
164753acd3b1SBarry Smith    The user is responsible for deallocating the strings that are
164853acd3b1SBarry Smith    returned. The Fortran interface for this routine is not supported.
164953acd3b1SBarry Smith 
1650*811af0c4SBarry Smith    Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
165153acd3b1SBarry Smith 
1652db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1653db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1654db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1655c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1656db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1657db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
165888aa4217SBarry Smith M*/
165988aa4217SBarry Smith 
16609371c9d4SSatish Balay PetscErrorCode PetscOptionsStringArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], char *value[], PetscInt *nmax, PetscBool *set) {
16614416b707SBarry Smith   PetscOptionItem amsopt;
166253acd3b1SBarry Smith 
166353acd3b1SBarry Smith   PetscFunctionBegin;
1664e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
16659566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_STRING_ARRAY, &amsopt));
16669566063dSJacob Faibussowitsch     PetscCall(PetscMalloc1(*nmax, (char **)&amsopt->data));
1667a297a907SKarl Rupp 
16681ae3d29cSBarry Smith     amsopt->arraylength = *nmax;
16691ae3d29cSBarry Smith   }
16709566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetStringArray(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, nmax, set));
1671e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
16729566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <string1,string2,...>: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, text, ManSection(man)));
167353acd3b1SBarry Smith   }
167453acd3b1SBarry Smith   PetscFunctionReturn(0);
167553acd3b1SBarry Smith }
167653acd3b1SBarry Smith 
167788aa4217SBarry Smith /*MC
1678acfcf0e5SJed Brown    PetscOptionsBoolArray - Gets an array of logical values (true or false) for a particular
1679e2446a98SMatthew Knepley    option in the database. The values must be separated with commas with
1680e2446a98SMatthew Knepley    no intervening spaces.
1681e2446a98SMatthew Knepley 
1682*811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
1683e2446a98SMatthew Knepley 
168488aa4217SBarry Smith    Synopsis:
168588aa4217SBarry Smith    #include "petscsys.h"
16863a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolArray(const char opt[],const char text[],const char man[],PetscBool value[],PetscInt *n,PetscBool *set)
168788aa4217SBarry Smith 
1688e2446a98SMatthew Knepley    Input Parameters:
1689e2446a98SMatthew Knepley +  opt - the option one is seeking
1690e2446a98SMatthew Knepley .  text - short string describing option
1691e2446a98SMatthew Knepley .  man - manual page for option
1692c89788bdSBarry Smith -  n - maximum number of values allowed in the value array
1693e2446a98SMatthew Knepley 
1694d8d19677SJose E. Roman    Output Parameters:
1695e2446a98SMatthew Knepley +  value - location to copy values
1696c89788bdSBarry Smith .  n - actual number of values found
1697*811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
1698e2446a98SMatthew Knepley 
1699e2446a98SMatthew Knepley    Level: beginner
1700e2446a98SMatthew Knepley 
1701e2446a98SMatthew Knepley    Notes:
1702e2446a98SMatthew Knepley    The user should pass in an array of doubles
1703e2446a98SMatthew Knepley 
1704*811af0c4SBarry Smith    Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
1705e2446a98SMatthew Knepley 
1706db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1707db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1708db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1709c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1710db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1711db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
171288aa4217SBarry Smith M*/
171388aa4217SBarry Smith 
17149371c9d4SSatish Balay PetscErrorCode PetscOptionsBoolArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool value[], PetscInt *n, PetscBool *set) {
1715e2446a98SMatthew Knepley   PetscInt        i;
17164416b707SBarry Smith   PetscOptionItem amsopt;
1717e2446a98SMatthew Knepley 
1718e2446a98SMatthew Knepley   PetscFunctionBegin;
1719e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1720ace3abfcSBarry Smith     PetscBool *vals;
17211ae3d29cSBarry Smith 
17229566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL_ARRAY, &amsopt));
17239566063dSJacob Faibussowitsch     PetscCall(PetscMalloc1(*n, (PetscBool **)&amsopt->data));
1724ace3abfcSBarry Smith     vals = (PetscBool *)amsopt->data;
17251ae3d29cSBarry Smith     for (i = 0; i < *n; i++) vals[i] = value[i];
17261ae3d29cSBarry Smith     amsopt->arraylength = *n;
17271ae3d29cSBarry Smith   }
17289566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetBoolArray(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, n, set));
1729e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
17309566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%d", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, value[0]));
173148a46eb9SPierre Jolivet     for (i = 1; i < *n; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ",%d", value[i]));
17329566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ">: %s (%s)\n", text, ManSection(man)));
1733e2446a98SMatthew Knepley   }
1734e2446a98SMatthew Knepley   PetscFunctionReturn(0);
1735e2446a98SMatthew Knepley }
1736e2446a98SMatthew Knepley 
173788aa4217SBarry Smith /*MC
1738d1da0b69SBarry Smith    PetscOptionsViewer - Gets a viewer appropriate for the type indicated by the user
17398cc676e6SMatthew G Knepley 
1740*811af0c4SBarry Smith    Logically Collective on the communicator passed in `PetscOptionsBegin()`
17418cc676e6SMatthew G Knepley 
174288aa4217SBarry Smith    Synopsis:
174388aa4217SBarry Smith    #include "petscsys.h"
17443a89f35bSSatish Balay    PetscErrorCode PetscOptionsViewer(const char opt[],const char text[],const char man[],PetscViewer *viewer,PetscViewerFormat *format,PetscBool *set)
174588aa4217SBarry Smith 
17468cc676e6SMatthew G Knepley    Input Parameters:
17478cc676e6SMatthew G Knepley +  opt - option name
17488cc676e6SMatthew G Knepley .  text - short string that describes the option
17498cc676e6SMatthew G Knepley -  man - manual page with additional information on option
17508cc676e6SMatthew G Knepley 
1751d8d19677SJose E. Roman    Output Parameters:
17528cc676e6SMatthew G Knepley +  viewer - the viewer
17537962402dSFande Kong .  format - the PetscViewerFormat requested by the user, pass NULL if not needed
1754*811af0c4SBarry Smith -  set - `PETSC_TRUE` if found, else `PETSC_FALSE`
17558cc676e6SMatthew G Knepley 
17568cc676e6SMatthew G Knepley    Level: beginner
17578cc676e6SMatthew G Knepley 
175895452b02SPatrick Sanan    Notes:
1759*811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
17608cc676e6SMatthew G Knepley 
1761*811af0c4SBarry Smith    See `PetscOptionsGetViewer()` for the format of the supplied viewer and its options
17628cc676e6SMatthew G Knepley 
1763db781477SPatrick Sanan .seealso: `PetscOptionsGetViewer()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
1764db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`
1765db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
1766db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1767c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1768db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1769db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
177088aa4217SBarry Smith M*/
177188aa4217SBarry Smith 
17729371c9d4SSatish Balay PetscErrorCode PetscOptionsViewer_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscViewer *viewer, PetscViewerFormat *format, PetscBool *set) {
17734416b707SBarry Smith   PetscOptionItem amsopt;
17748cc676e6SMatthew G Knepley 
17758cc676e6SMatthew G Knepley   PetscFunctionBegin;
17761a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
17779566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_STRING, &amsopt));
177864facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
17799566063dSJacob Faibussowitsch     PetscCall(PetscStrdup("", (char **)&amsopt->data));
17808cc676e6SMatthew G Knepley   }
17819566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetViewer(PetscOptionsObject->comm, PetscOptionsObject->options, PetscOptionsObject->prefix, opt, viewer, format, set));
1782e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
17839566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%s>: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, "", text, ManSection(man)));
17848cc676e6SMatthew G Knepley   }
17858cc676e6SMatthew G Knepley   PetscFunctionReturn(0);
17868cc676e6SMatthew G Knepley }
1787