xref: /petsc/src/sys/objects/aoptions.c (revision aec76313382a76d73a95f2051cbe4b1eab55c1c7)
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 
1010c654e6SJacob Faibussowitsch static const char *ManSection(const char *str)
1110c654e6SJacob Faibussowitsch {
1210c654e6SJacob Faibussowitsch   return str ? str : "None";
1310c654e6SJacob Faibussowitsch }
1410c654e6SJacob Faibussowitsch 
1510c654e6SJacob Faibussowitsch static const char *Prefix(const char *str)
1610c654e6SJacob Faibussowitsch {
1710c654e6SJacob Faibussowitsch   return str ? str : "";
1810c654e6SJacob Faibussowitsch }
1910c654e6SJacob Faibussowitsch 
2010c654e6SJacob Faibussowitsch static int ShouldPrintHelp(const PetscOptionItems *opts)
2110c654e6SJacob Faibussowitsch {
2210c654e6SJacob Faibussowitsch   return opts->printhelp && opts->count == 1 && !opts->alreadyprinted;
2310c654e6SJacob Faibussowitsch }
242aa6d131SJed Brown 
2553acd3b1SBarry Smith /*
2653acd3b1SBarry Smith     Keep a linked list of options that have been posted and we are waiting for
273fc1eb6aSBarry Smith    user selection. See the manual page for PetscOptionsBegin()
2853acd3b1SBarry Smith 
2953acd3b1SBarry Smith     Eventually we'll attach this beast to a MPI_Comm
3053acd3b1SBarry Smith */
31e55864a3SBarry Smith 
3253acd3b1SBarry Smith /*
3353acd3b1SBarry Smith     Handles setting up the data structure in a call to PetscOptionsBegin()
3453acd3b1SBarry Smith */
35d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsBegin_Private(PetscOptionItems *PetscOptionsObject, MPI_Comm comm, const char prefix[], const char title[], const char mansec[])
36d71ae5a4SJacob Faibussowitsch {
3753acd3b1SBarry Smith   PetscFunctionBegin;
38064a246eSJacob Faibussowitsch   if (prefix) PetscValidCharPointer(prefix, 3);
39064a246eSJacob Faibussowitsch   PetscValidCharPointer(title, 4);
40064a246eSJacob Faibussowitsch   if (mansec) PetscValidCharPointer(mansec, 5);
410eb63584SBarry Smith   if (!PetscOptionsObject->alreadyprinted) {
429566063dSJacob Faibussowitsch     if (!PetscOptionsHelpPrintedSingleton) PetscCall(PetscOptionsHelpPrintedCreate(&PetscOptionsHelpPrintedSingleton));
439566063dSJacob Faibussowitsch     PetscCall(PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrintedSingleton, prefix, title, &PetscOptionsObject->alreadyprinted));
440eb63584SBarry Smith   }
4502c9f0b5SLisandro Dalcin   PetscOptionsObject->next          = NULL;
46e55864a3SBarry Smith   PetscOptionsObject->comm          = comm;
47e55864a3SBarry Smith   PetscOptionsObject->changedmethod = PETSC_FALSE;
48a297a907SKarl Rupp 
499566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(prefix, &PetscOptionsObject->prefix));
509566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(title, &PetscOptionsObject->title));
5153acd3b1SBarry Smith 
529566063dSJacob Faibussowitsch   PetscCall(PetscOptionsHasHelp(PetscOptionsObject->options, &PetscOptionsObject->printhelp));
5310c654e6SJacob Faibussowitsch   if (ShouldPrintHelp(PetscOptionsObject)) PetscCall((*PetscHelpPrintf)(comm, "----------------------------------------\n%s:\n", title));
543ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
5553acd3b1SBarry Smith }
5653acd3b1SBarry Smith 
573194b578SJed Brown /*
583194b578SJed Brown     Handles setting up the data structure in a call to PetscObjectOptionsBegin()
593194b578SJed Brown */
60d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscObjectOptionsBegin_Private(PetscObject obj, PetscOptionItems *PetscOptionsObject)
61d71ae5a4SJacob Faibussowitsch {
623194b578SJed Brown   char      title[256];
633194b578SJed Brown   PetscBool flg;
643194b578SJed Brown 
653194b578SJed Brown   PetscFunctionBegin;
66dbbe0bcdSBarry Smith   PetscValidPointer(PetscOptionsObject, 2);
67dbbe0bcdSBarry Smith   PetscValidHeader(obj, 1);
68e55864a3SBarry Smith   PetscOptionsObject->object         = obj;
69e55864a3SBarry Smith   PetscOptionsObject->alreadyprinted = obj->optionsprinted;
70a297a907SKarl Rupp 
719566063dSJacob Faibussowitsch   PetscCall(PetscStrcmp(obj->description, obj->class_name, &flg));
729566063dSJacob Faibussowitsch   if (flg) PetscCall(PetscSNPrintf(title, sizeof(title), "%s options", obj->class_name));
739566063dSJacob Faibussowitsch   else PetscCall(PetscSNPrintf(title, sizeof(title), "%s (%s) options", obj->description, obj->class_name));
749566063dSJacob Faibussowitsch   PetscCall(PetscOptionsBegin_Private(PetscOptionsObject, obj->comm, obj->prefix, title, obj->mansec));
753ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
763194b578SJed Brown }
773194b578SJed Brown 
7853acd3b1SBarry Smith /*
7953acd3b1SBarry Smith      Handles adding another option to the list of options within this particular PetscOptionsBegin() PetscOptionsEnd()
8053acd3b1SBarry Smith */
813ba16761SJacob Faibussowitsch static PetscErrorCode PetscOptionItemCreate_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscOptionType t, PetscOptionItem *amsopt)
82d71ae5a4SJacob Faibussowitsch {
833be6e4c3SJed Brown   PetscBool valid;
8453acd3b1SBarry Smith 
8553acd3b1SBarry Smith   PetscFunctionBegin;
869566063dSJacob Faibussowitsch   PetscCall(PetscOptionsValidKey(opt, &valid));
875f80ce2aSJacob Faibussowitsch   PetscCheck(valid, PETSC_COMM_WORLD, PETSC_ERR_ARG_INCOMP, "The option '%s' is not a valid key", opt);
883be6e4c3SJed Brown 
899566063dSJacob Faibussowitsch   PetscCall(PetscNew(amsopt));
9002c9f0b5SLisandro Dalcin   (*amsopt)->next = NULL;
9153acd3b1SBarry Smith   (*amsopt)->set  = PETSC_FALSE;
926356e834SBarry Smith   (*amsopt)->type = t;
9302c9f0b5SLisandro Dalcin   (*amsopt)->data = NULL;
9461b37b28SSatish Balay 
959566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(text, &(*amsopt)->text));
969566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(opt, &(*amsopt)->option));
979566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(man, &(*amsopt)->man));
9853acd3b1SBarry Smith 
9910c654e6SJacob Faibussowitsch   {
10010c654e6SJacob Faibussowitsch     PetscOptionItem cur = PetscOptionsObject->next;
10110c654e6SJacob Faibussowitsch 
10210c654e6SJacob Faibussowitsch     while (cur->next) cur = cur->next;
10310c654e6SJacob Faibussowitsch     cur->next = *amsopt;
10453acd3b1SBarry Smith   }
1053ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
10653acd3b1SBarry Smith }
10753acd3b1SBarry Smith 
108aee2cecaSBarry Smith /*
1093fc1eb6aSBarry Smith     PetscScanString -  Gets user input via stdin from process and broadcasts to all processes
1103fc1eb6aSBarry Smith 
111d083f849SBarry Smith     Collective
1123fc1eb6aSBarry Smith 
1133fc1eb6aSBarry Smith    Input Parameters:
1143fc1eb6aSBarry Smith +     commm - communicator for the broadcast, must be PETSC_COMM_WORLD
1153fc1eb6aSBarry Smith .     n - length of the string, must be the same on all processes
1163fc1eb6aSBarry Smith -     str - location to store input
117aee2cecaSBarry Smith 
118aee2cecaSBarry Smith     Bugs:
119aee2cecaSBarry Smith .   Assumes process 0 of the given communicator has access to stdin
120aee2cecaSBarry Smith 
121aee2cecaSBarry Smith */
122d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscScanString(MPI_Comm comm, size_t n, char str[])
123d71ae5a4SJacob Faibussowitsch {
1243fc1eb6aSBarry Smith   PetscMPIInt rank, nm;
125aee2cecaSBarry Smith 
126aee2cecaSBarry Smith   PetscFunctionBegin;
1279566063dSJacob Faibussowitsch   PetscCallMPI(MPI_Comm_rank(comm, &rank));
128dd400576SPatrick Sanan   if (rank == 0) {
1295f80ce2aSJacob Faibussowitsch     char   c = (char)getchar();
1305f80ce2aSJacob Faibussowitsch     size_t i = 0;
1315f80ce2aSJacob Faibussowitsch 
132aee2cecaSBarry Smith     while (c != '\n' && i < n - 1) {
133aee2cecaSBarry Smith       str[i++] = c;
134aee2cecaSBarry Smith       c        = (char)getchar();
135aee2cecaSBarry Smith     }
13610c654e6SJacob Faibussowitsch     str[i] = '\0';
137aee2cecaSBarry Smith   }
1389566063dSJacob Faibussowitsch   PetscCall(PetscMPIIntCast(n, &nm));
1399566063dSJacob Faibussowitsch   PetscCallMPI(MPI_Bcast(str, nm, MPI_CHAR, 0, comm));
1403ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
141aee2cecaSBarry Smith }
142aee2cecaSBarry Smith 
1435b02f95dSBarry Smith /*
1445b02f95dSBarry Smith     This is needed because certain strings may be freed by SAWs, hence we cannot use PetscStrallocpy()
1455b02f95dSBarry Smith */
146d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscStrdup(const char s[], char *t[])
147d71ae5a4SJacob Faibussowitsch {
14802c9f0b5SLisandro Dalcin   char *tmp = NULL;
1495b02f95dSBarry Smith 
1505b02f95dSBarry Smith   PetscFunctionBegin;
1515b02f95dSBarry Smith   if (s) {
1525f80ce2aSJacob Faibussowitsch     size_t len;
1535f80ce2aSJacob Faibussowitsch 
1549566063dSJacob Faibussowitsch     PetscCall(PetscStrlen(s, &len));
1555f80ce2aSJacob Faibussowitsch     tmp = (char *)malloc((len + 1) * sizeof(*tmp));
1565f80ce2aSJacob Faibussowitsch     PetscCheck(tmp, PETSC_COMM_SELF, PETSC_ERR_MEM, "No memory to duplicate string");
157363da2dcSJacob Faibussowitsch     PetscCall(PetscArraycpy(tmp, s, len + 1));
1585b02f95dSBarry Smith   }
1595b02f95dSBarry Smith   *t = tmp;
1603ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1615b02f95dSBarry Smith }
1625b02f95dSBarry Smith 
163aee2cecaSBarry Smith /*
1643cc1e11dSBarry Smith   PetscOptionsGetFromTextInput - Presents all the PETSc Options processed by the program so the user may change them at runtime
165aee2cecaSBarry Smith 
16695452b02SPatrick Sanan   Notes:
16795452b02SPatrick Sanan   this isn't really practical, it is just to demonstrate the principle
168aee2cecaSBarry Smith 
1697781c08eSBarry Smith   A carriage return indicates no change from the default; but this like -ksp_monitor <stdout>  the default is actually not stdout the default
1707781c08eSBarry Smith   is to do nothing so to get it to use stdout you need to type stdout. This is kind of bug?
1717781c08eSBarry Smith 
172aee2cecaSBarry Smith   Bugs:
1737781c08eSBarry Smith +    All processes must traverse through the exact same set of option queries due to the call to PetscScanString()
1743cc1e11dSBarry Smith .    Internal strings have arbitrary length and string copies are not checked that they fit into string space
175aee2cecaSBarry Smith -    Only works for PetscInt == int, PetscReal == double etc
176aee2cecaSBarry Smith 
177*aec76313SJacob Faibussowitsch   Developer Notes:
17895452b02SPatrick Sanan   Normally the GUI that presents the options the user and retrieves the values would be running in a different
1793cc1e11dSBarry Smith   address space and communicating with the PETSc program
1803cc1e11dSBarry Smith 
181aee2cecaSBarry Smith */
182d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsGetFromTextInput(PetscOptionItems *PetscOptionsObject)
183d71ae5a4SJacob Faibussowitsch {
1844416b707SBarry Smith   PetscOptionItem next = PetscOptionsObject->next;
1856356e834SBarry Smith   char            str[512];
1867781c08eSBarry Smith   PetscBool       bid;
187a4404d99SBarry Smith   PetscReal       ir, *valr;
188330cf3c9SBarry Smith   PetscInt       *vald;
189330cf3c9SBarry Smith   size_t          i;
1906356e834SBarry Smith 
1912a409bb0SBarry Smith   PetscFunctionBegin;
1929566063dSJacob Faibussowitsch   PetscCall((*PetscPrintf)(PETSC_COMM_WORLD, "%s --------------------\n", PetscOptionsObject->title));
1936356e834SBarry Smith   while (next) {
1946356e834SBarry Smith     switch (next->type) {
195d71ae5a4SJacob Faibussowitsch     case OPTION_HEAD:
196d71ae5a4SJacob Faibussowitsch       break;
197e26ddf31SBarry Smith     case OPTION_INT_ARRAY:
1984bb2516aSBarry Smith       PetscCall(PetscPrintf(PETSC_COMM_WORLD, "-%s%s: <", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1));
199e26ddf31SBarry Smith       vald = (PetscInt *)next->data;
200e26ddf31SBarry Smith       for (i = 0; i < next->arraylength; i++) {
2019566063dSJacob Faibussowitsch         PetscCall(PetscPrintf(PETSC_COMM_WORLD, "%" PetscInt_FMT, vald[i]));
20248a46eb9SPierre Jolivet         if (i < next->arraylength - 1) PetscCall(PetscPrintf(PETSC_COMM_WORLD, ","));
203e26ddf31SBarry Smith       }
2049566063dSJacob Faibussowitsch       PetscCall(PetscPrintf(PETSC_COMM_WORLD, ">: %s (%s) ", next->text, next->man));
2059566063dSJacob Faibussowitsch       PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str));
206e26ddf31SBarry Smith       if (str[0]) {
207e26ddf31SBarry Smith         PetscToken token;
208e26ddf31SBarry Smith         PetscInt   n = 0, nmax = next->arraylength, *dvalue = (PetscInt *)next->data, start, end;
209e26ddf31SBarry Smith         size_t     len;
210e26ddf31SBarry Smith         char      *value;
211ace3abfcSBarry Smith         PetscBool  foundrange;
212e26ddf31SBarry Smith 
213e26ddf31SBarry Smith         next->set = PETSC_TRUE;
214e26ddf31SBarry Smith         value     = str;
2159566063dSJacob Faibussowitsch         PetscCall(PetscTokenCreate(value, ',', &token));
2169566063dSJacob Faibussowitsch         PetscCall(PetscTokenFind(token, &value));
217e26ddf31SBarry Smith         while (n < nmax) {
218e26ddf31SBarry Smith           if (!value) break;
219e26ddf31SBarry Smith 
220e26ddf31SBarry Smith           /* look for form  d-D where d and D are integers */
221e26ddf31SBarry Smith           foundrange = PETSC_FALSE;
2229566063dSJacob Faibussowitsch           PetscCall(PetscStrlen(value, &len));
223e26ddf31SBarry Smith           if (value[0] == '-') i = 2;
224e26ddf31SBarry Smith           else i = 1;
225330cf3c9SBarry Smith           for (; i < len; i++) {
226e26ddf31SBarry Smith             if (value[i] == '-') {
22708401ef6SPierre Jolivet               PetscCheck(i != len - 1, PETSC_COMM_SELF, PETSC_ERR_USER, "Error in %" PetscInt_FMT "-th array entry %s", n, value);
228e26ddf31SBarry Smith               value[i] = 0;
2299566063dSJacob Faibussowitsch               PetscCall(PetscOptionsStringToInt(value, &start));
2309566063dSJacob Faibussowitsch               PetscCall(PetscOptionsStringToInt(value + i + 1, &end));
23108401ef6SPierre Jolivet               PetscCheck(end > start, PETSC_COMM_SELF, PETSC_ERR_USER, "Error in %" PetscInt_FMT "-th array entry, %s-%s cannot have decreasing list", n, value, value + i + 1);
232cc73adaaSBarry Smith               PetscCheck(n + end - start - 1 < nmax, PETSC_COMM_SELF, PETSC_ERR_USER, "Error in %" PetscInt_FMT "-th array entry, not enough space in left in array (%" PetscInt_FMT ") to contain entire range from %" PetscInt_FMT " to %" PetscInt_FMT, n, nmax - n, start, end);
233e26ddf31SBarry Smith               for (; start < end; start++) {
2349371c9d4SSatish Balay                 *dvalue = start;
2359371c9d4SSatish Balay                 dvalue++;
2369371c9d4SSatish Balay                 n++;
237e26ddf31SBarry Smith               }
238e26ddf31SBarry Smith               foundrange = PETSC_TRUE;
239e26ddf31SBarry Smith               break;
240e26ddf31SBarry Smith             }
241e26ddf31SBarry Smith           }
242e26ddf31SBarry Smith           if (!foundrange) {
2439566063dSJacob Faibussowitsch             PetscCall(PetscOptionsStringToInt(value, dvalue));
244e26ddf31SBarry Smith             dvalue++;
245e26ddf31SBarry Smith             n++;
246e26ddf31SBarry Smith           }
2479566063dSJacob Faibussowitsch           PetscCall(PetscTokenFind(token, &value));
248e26ddf31SBarry Smith         }
2499566063dSJacob Faibussowitsch         PetscCall(PetscTokenDestroy(&token));
250e26ddf31SBarry Smith       }
251e26ddf31SBarry Smith       break;
252e26ddf31SBarry Smith     case OPTION_REAL_ARRAY:
2534bb2516aSBarry Smith       PetscCall(PetscPrintf(PETSC_COMM_WORLD, "-%s%s: <", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1));
254e26ddf31SBarry Smith       valr = (PetscReal *)next->data;
255e26ddf31SBarry Smith       for (i = 0; i < next->arraylength; i++) {
2569566063dSJacob Faibussowitsch         PetscCall(PetscPrintf(PETSC_COMM_WORLD, "%g", (double)valr[i]));
25748a46eb9SPierre Jolivet         if (i < next->arraylength - 1) PetscCall(PetscPrintf(PETSC_COMM_WORLD, ","));
258e26ddf31SBarry Smith       }
2599566063dSJacob Faibussowitsch       PetscCall(PetscPrintf(PETSC_COMM_WORLD, ">: %s (%s) ", next->text, next->man));
2609566063dSJacob Faibussowitsch       PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str));
261e26ddf31SBarry Smith       if (str[0]) {
262e26ddf31SBarry Smith         PetscToken token;
263e26ddf31SBarry Smith         PetscInt   n = 0, nmax = next->arraylength;
264e26ddf31SBarry Smith         PetscReal *dvalue = (PetscReal *)next->data;
265e26ddf31SBarry Smith         char      *value;
266e26ddf31SBarry Smith 
267e26ddf31SBarry Smith         next->set = PETSC_TRUE;
268e26ddf31SBarry Smith         value     = str;
2699566063dSJacob Faibussowitsch         PetscCall(PetscTokenCreate(value, ',', &token));
2709566063dSJacob Faibussowitsch         PetscCall(PetscTokenFind(token, &value));
271e26ddf31SBarry Smith         while (n < nmax) {
272e26ddf31SBarry Smith           if (!value) break;
2739566063dSJacob Faibussowitsch           PetscCall(PetscOptionsStringToReal(value, dvalue));
274e26ddf31SBarry Smith           dvalue++;
275e26ddf31SBarry Smith           n++;
2769566063dSJacob Faibussowitsch           PetscCall(PetscTokenFind(token, &value));
277e26ddf31SBarry Smith         }
2789566063dSJacob Faibussowitsch         PetscCall(PetscTokenDestroy(&token));
279e26ddf31SBarry Smith       }
280e26ddf31SBarry Smith       break;
2816356e834SBarry Smith     case OPTION_INT:
2824bb2516aSBarry Smith       PetscCall(PetscPrintf(PETSC_COMM_WORLD, "-%s%s: <%d>: %s (%s) ", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1, *(int *)next->data, next->text, next->man));
2839566063dSJacob Faibussowitsch       PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str));
2843fc1eb6aSBarry Smith       if (str[0]) {
285d25d7f95SJed Brown #if defined(PETSC_SIZEOF_LONG_LONG)
286d25d7f95SJed Brown         long long lid;
287d25d7f95SJed Brown         sscanf(str, "%lld", &lid);
288cc73adaaSBarry Smith         PetscCheck(lid <= PETSC_MAX_INT && lid >= PETSC_MIN_INT, PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE, "Argument: -%s%s %lld", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1, lid);
289c272547aSJed Brown #else
290d25d7f95SJed Brown         long lid;
291d25d7f95SJed Brown         sscanf(str, "%ld", &lid);
292cc73adaaSBarry Smith         PetscCheck(lid <= PETSC_MAX_INT && lid >= PETSC_MIN_INT, PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE, "Argument: -%s%s %ld", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1, lid);
293c272547aSJed Brown #endif
294a297a907SKarl Rupp 
295d25d7f95SJed Brown         next->set                 = PETSC_TRUE;
296d25d7f95SJed Brown         *((PetscInt *)next->data) = (PetscInt)lid;
297aee2cecaSBarry Smith       }
298aee2cecaSBarry Smith       break;
299aee2cecaSBarry Smith     case OPTION_REAL:
3004bb2516aSBarry Smith       PetscCall(PetscPrintf(PETSC_COMM_WORLD, "-%s%s: <%g>: %s (%s) ", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1, *(double *)next->data, next->text, next->man));
3019566063dSJacob Faibussowitsch       PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str));
3023fc1eb6aSBarry Smith       if (str[0]) {
303ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE)
304a4404d99SBarry Smith         sscanf(str, "%e", &ir);
305570b7f6dSBarry Smith #elif defined(PETSC_USE_REAL___FP16)
306570b7f6dSBarry Smith         float irtemp;
307570b7f6dSBarry Smith         sscanf(str, "%e", &irtemp);
308570b7f6dSBarry Smith         ir = irtemp;
309ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE)
310aee2cecaSBarry Smith         sscanf(str, "%le", &ir);
311ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL___FLOAT128)
312d9822059SBarry Smith         ir = strtoflt128(str, 0);
313d9822059SBarry Smith #else
314513dbe71SLisandro Dalcin         SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, "Unknown scalar type");
315a4404d99SBarry Smith #endif
316aee2cecaSBarry Smith         next->set                  = PETSC_TRUE;
317aee2cecaSBarry Smith         *((PetscReal *)next->data) = ir;
318aee2cecaSBarry Smith       }
319aee2cecaSBarry Smith       break;
3207781c08eSBarry Smith     case OPTION_BOOL:
3214bb2516aSBarry Smith       PetscCall(PetscPrintf(PETSC_COMM_WORLD, "-%s%s: <%s>: %s (%s) ", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1, *(PetscBool *)next->data ? "true" : "false", next->text, next->man));
3229566063dSJacob Faibussowitsch       PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str));
3237781c08eSBarry Smith       if (str[0]) {
3249566063dSJacob Faibussowitsch         PetscCall(PetscOptionsStringToBool(str, &bid));
3257781c08eSBarry Smith         next->set                  = PETSC_TRUE;
3267781c08eSBarry Smith         *((PetscBool *)next->data) = bid;
3277781c08eSBarry Smith       }
3287781c08eSBarry Smith       break;
329aee2cecaSBarry Smith     case OPTION_STRING:
3304bb2516aSBarry Smith       PetscCall(PetscPrintf(PETSC_COMM_WORLD, "-%s%s: <%s>: %s (%s) ", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1, (char *)next->data, next->text, next->man));
3319566063dSJacob Faibussowitsch       PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str));
3323fc1eb6aSBarry Smith       if (str[0]) {
333aee2cecaSBarry Smith         next->set = PETSC_TRUE;
33464facd6cSBarry Smith         /* must use system malloc since SAWs may free this */
3359566063dSJacob Faibussowitsch         PetscCall(PetscStrdup(str, (char **)&next->data));
3366356e834SBarry Smith       }
3376356e834SBarry Smith       break;
338a264d7a6SBarry Smith     case OPTION_FLIST:
3399566063dSJacob Faibussowitsch       PetscCall(PetscFunctionListPrintTypes(PETSC_COMM_WORLD, stdout, PetscOptionsObject->prefix, next->option, next->text, next->man, next->flist, (char *)next->data, (char *)next->data));
3409566063dSJacob Faibussowitsch       PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str));
3413cc1e11dSBarry Smith       if (str[0]) {
342e55864a3SBarry Smith         PetscOptionsObject->changedmethod = PETSC_TRUE;
3433cc1e11dSBarry Smith         next->set                         = PETSC_TRUE;
34464facd6cSBarry Smith         /* must use system malloc since SAWs may free this */
3459566063dSJacob Faibussowitsch         PetscCall(PetscStrdup(str, (char **)&next->data));
3463cc1e11dSBarry Smith       }
3473cc1e11dSBarry Smith       break;
348d71ae5a4SJacob Faibussowitsch     default:
349d71ae5a4SJacob Faibussowitsch       break;
3506356e834SBarry Smith     }
3516356e834SBarry Smith     next = next->next;
3526356e834SBarry Smith   }
3533ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
3546356e834SBarry Smith }
3556356e834SBarry Smith 
356e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS)
357e04113cfSBarry Smith   #include <petscviewersaws.h>
358d5649816SBarry Smith 
359d5649816SBarry Smith static int count = 0;
360d5649816SBarry Smith 
361d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsSAWsDestroy(void)
362d71ae5a4SJacob Faibussowitsch {
3632657e9d9SBarry Smith   PetscFunctionBegin;
3643ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
365d5649816SBarry Smith }
366d5649816SBarry Smith 
3679c1e0ce8SBarry Smith static const char *OptionsHeader = "<head>\n"
368a8d69d7bSBarry Smith                                    "<script type=\"text/javascript\" src=\"https://www.mcs.anl.gov/research/projects/saws/js/jquery-1.9.1.js\"></script>\n"
369a8d69d7bSBarry Smith                                    "<script type=\"text/javascript\" src=\"https://www.mcs.anl.gov/research/projects/saws/js/SAWs.js\"></script>\n"
370d1fc0251SBarry Smith                                    "<script type=\"text/javascript\" src=\"js/PETSc.js\"></script>\n"
37164bbc9efSBarry Smith                                    "<script>\n"
37264bbc9efSBarry Smith                                    "jQuery(document).ready(function() {\n"
37364bbc9efSBarry Smith                                    "PETSc.getAndDisplayDirectory(null,\"#variablesInfo\")\n"
37464bbc9efSBarry Smith                                    "})\n"
37564bbc9efSBarry Smith                                    "</script>\n"
37664bbc9efSBarry Smith                                    "</head>\n";
3771423471aSBarry Smith 
3781423471aSBarry Smith /*  Determines the size and style of the scroll region where PETSc options selectable from users are displayed */
3791423471aSBarry Smith static const char *OptionsBodyBottom = "<div id=\"variablesInfo\" style=\"background-color:lightblue;height:auto;max-height:500px;overflow:scroll;\"></div>\n<br>\n</body>";
38064bbc9efSBarry Smith 
381b3506946SBarry Smith /*
3827781c08eSBarry Smith     PetscOptionsSAWsInput - Presents all the PETSc Options processed by the program so the user may change them at runtime using the SAWs
383b3506946SBarry Smith 
384b3506946SBarry Smith     Bugs:
385bf31d2d3SBarry Smith +    All processes must traverse through the exact same set of option queries due to the call to PetscScanString()
386b3506946SBarry Smith .    Internal strings have arbitrary length and string copies are not checked that they fit into string space
387b3506946SBarry Smith -    Only works for PetscInt == int, PetscReal == double etc
388b3506946SBarry Smith 
389b3506946SBarry Smith */
390d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsSAWsInput(PetscOptionItems *PetscOptionsObject)
391d71ae5a4SJacob Faibussowitsch {
3924416b707SBarry Smith   PetscOptionItem next     = PetscOptionsObject->next;
393d5649816SBarry Smith   static int      mancount = 0;
394b3506946SBarry Smith   char            options[16];
3957aab2a10SBarry Smith   PetscBool       changedmethod = PETSC_FALSE;
396a23eb982SSurtai Han   PetscBool       stopasking    = PETSC_FALSE;
39788a9752cSBarry Smith   char            manname[16], textname[16];
3982657e9d9SBarry Smith   char            dir[1024];
399b3506946SBarry Smith 
4002a409bb0SBarry Smith   PetscFunctionBegin;
401b3506946SBarry Smith   /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */
402a364092eSJacob Faibussowitsch   PetscCall(PetscSNPrintf(options, PETSC_STATIC_ARRAY_LENGTH(options), "Options_%d", count++));
403a297a907SKarl Rupp 
4047325c4a4SBarry Smith   PetscOptionsObject->pprefix = PetscOptionsObject->prefix; /* SAWs will change this, so cannot pass prefix directly */
4051bc75a8dSBarry Smith 
4069566063dSJacob Faibussowitsch   PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", "_title"));
407792fecdfSBarry Smith   PetscCallSAWs(SAWs_Register, (dir, &PetscOptionsObject->title, 1, SAWs_READ, SAWs_STRING));
4089566063dSJacob Faibussowitsch   PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", "prefix"));
409792fecdfSBarry Smith   PetscCallSAWs(SAWs_Register, (dir, &PetscOptionsObject->pprefix, 1, SAWs_READ, SAWs_STRING));
410792fecdfSBarry Smith   PetscCallSAWs(SAWs_Register, ("/PETSc/Options/ChangedMethod", &changedmethod, 1, SAWs_WRITE, SAWs_BOOLEAN));
411792fecdfSBarry Smith   PetscCallSAWs(SAWs_Register, ("/PETSc/Options/StopAsking", &stopasking, 1, SAWs_WRITE, SAWs_BOOLEAN));
412b3506946SBarry Smith 
413b3506946SBarry Smith   while (next) {
414a364092eSJacob Faibussowitsch     PetscCall(PetscSNPrintf(manname, PETSC_STATIC_ARRAY_LENGTH(manname), "_man_%d", mancount));
4159566063dSJacob Faibussowitsch     PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", manname));
416792fecdfSBarry Smith     PetscCallSAWs(SAWs_Register, (dir, &next->man, 1, SAWs_READ, SAWs_STRING));
417a364092eSJacob Faibussowitsch     PetscCall(PetscSNPrintf(textname, PETSC_STATIC_ARRAY_LENGTH(textname), "_text_%d", mancount++));
4189566063dSJacob Faibussowitsch     PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", textname));
419792fecdfSBarry Smith     PetscCallSAWs(SAWs_Register, (dir, &next->text, 1, SAWs_READ, SAWs_STRING));
4209f32e415SBarry Smith 
421b3506946SBarry Smith     switch (next->type) {
422d71ae5a4SJacob Faibussowitsch     case OPTION_HEAD:
423d71ae5a4SJacob Faibussowitsch       break;
424b3506946SBarry Smith     case OPTION_INT_ARRAY:
4259566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
426792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, next->data, next->arraylength, SAWs_WRITE, SAWs_INT));
427b3506946SBarry Smith       break;
428b3506946SBarry Smith     case OPTION_REAL_ARRAY:
4299566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
430792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, next->data, next->arraylength, SAWs_WRITE, SAWs_DOUBLE));
431b3506946SBarry Smith       break;
432b3506946SBarry Smith     case OPTION_INT:
4339566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
434792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, next->data, 1, SAWs_WRITE, SAWs_INT));
435b3506946SBarry Smith       break;
436b3506946SBarry Smith     case OPTION_REAL:
4379566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
438792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, next->data, 1, SAWs_WRITE, SAWs_DOUBLE));
439b3506946SBarry Smith       break;
4407781c08eSBarry Smith     case OPTION_BOOL:
4419566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
442792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, next->data, 1, SAWs_WRITE, SAWs_BOOLEAN));
4431ae3d29cSBarry Smith       break;
4447781c08eSBarry Smith     case OPTION_BOOL_ARRAY:
4459566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
446792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, next->data, next->arraylength, SAWs_WRITE, SAWs_BOOLEAN));
44771f08665SBarry Smith       break;
448b3506946SBarry Smith     case OPTION_STRING:
4499566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
450792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, &next->data, 1, SAWs_WRITE, SAWs_STRING));
4511ae3d29cSBarry Smith       break;
4521ae3d29cSBarry Smith     case OPTION_STRING_ARRAY:
4539566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
454792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, next->data, next->arraylength, SAWs_WRITE, SAWs_STRING));
455b3506946SBarry Smith       break;
4569371c9d4SSatish Balay     case OPTION_FLIST: {
457a264d7a6SBarry Smith       PetscInt ntext;
4589566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
459792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, &next->data, 1, SAWs_WRITE, SAWs_STRING));
4609566063dSJacob Faibussowitsch       PetscCall(PetscFunctionListGet(next->flist, (const char ***)&next->edata, &ntext));
461792fecdfSBarry Smith       PetscCallSAWs(SAWs_Set_Legal_Variable_Values, (dir, ntext, next->edata));
4629371c9d4SSatish Balay     } break;
4639371c9d4SSatish Balay     case OPTION_ELIST: {
464a264d7a6SBarry Smith       PetscInt ntext = next->nlist;
4659566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
466792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, &next->data, 1, SAWs_WRITE, SAWs_STRING));
4679566063dSJacob Faibussowitsch       PetscCall(PetscMalloc1((ntext + 1), (char ***)&next->edata));
4689566063dSJacob Faibussowitsch       PetscCall(PetscMemcpy(next->edata, next->list, ntext * sizeof(char *)));
469792fecdfSBarry Smith       PetscCallSAWs(SAWs_Set_Legal_Variable_Values, (dir, ntext, next->edata));
4709371c9d4SSatish Balay     } break;
471d71ae5a4SJacob Faibussowitsch     default:
472d71ae5a4SJacob Faibussowitsch       break;
473b3506946SBarry Smith     }
474b3506946SBarry Smith     next = next->next;
475b3506946SBarry Smith   }
476b3506946SBarry Smith 
477b3506946SBarry Smith   /* wait until accessor has unlocked the memory */
478792fecdfSBarry Smith   PetscCallSAWs(SAWs_Push_Header, ("index.html", OptionsHeader));
479792fecdfSBarry Smith   PetscCallSAWs(SAWs_Push_Body, ("index.html", 2, OptionsBodyBottom));
4809566063dSJacob Faibussowitsch   PetscCall(PetscSAWsBlock());
481792fecdfSBarry Smith   PetscCallSAWs(SAWs_Pop_Header, ("index.html"));
482792fecdfSBarry Smith   PetscCallSAWs(SAWs_Pop_Body, ("index.html", 2));
483b3506946SBarry Smith 
48488a9752cSBarry Smith   /* determine if any values have been set in GUI */
48583355fc5SBarry Smith   next = PetscOptionsObject->next;
48688a9752cSBarry Smith   while (next) {
4879566063dSJacob Faibussowitsch     PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
488792fecdfSBarry Smith     PetscCallSAWs(SAWs_Selected, (dir, (int *)&next->set));
48988a9752cSBarry Smith     next = next->next;
49088a9752cSBarry Smith   }
49188a9752cSBarry Smith 
492b3506946SBarry Smith   /* reset counter to -2; this updates the screen with the new options for the selected method */
493f7b25cf6SBarry Smith   if (changedmethod) PetscOptionsObject->count = -2;
494b3506946SBarry Smith 
495a23eb982SSurtai Han   if (stopasking) {
496a23eb982SSurtai Han     PetscOptionsPublish       = PETSC_FALSE;
49712655325SBarry Smith     PetscOptionsObject->count = 0; //do not ask for same thing again
498a23eb982SSurtai Han   }
499a23eb982SSurtai Han 
500792fecdfSBarry Smith   PetscCallSAWs(SAWs_Delete, ("/PETSc/Options"));
5013ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
502b3506946SBarry Smith }
503b3506946SBarry Smith #endif
504b3506946SBarry Smith 
505d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsEnd_Private(PetscOptionItems *PetscOptionsObject)
506d71ae5a4SJacob Faibussowitsch {
50710c654e6SJacob Faibussowitsch   PetscOptionItem next, last;
50853acd3b1SBarry Smith 
50953acd3b1SBarry Smith   PetscFunctionBegin;
51083355fc5SBarry Smith   if (PetscOptionsObject->next) {
51183355fc5SBarry Smith     if (!PetscOptionsObject->count) {
512a264d7a6SBarry Smith #if defined(PETSC_HAVE_SAWS)
5139566063dSJacob Faibussowitsch       PetscCall(PetscOptionsSAWsInput(PetscOptionsObject));
514b3506946SBarry Smith #else
5159566063dSJacob Faibussowitsch       PetscCall(PetscOptionsGetFromTextInput(PetscOptionsObject));
516b3506946SBarry Smith #endif
517aee2cecaSBarry Smith     }
518aee2cecaSBarry Smith   }
5196356e834SBarry Smith 
5209566063dSJacob Faibussowitsch   PetscCall(PetscFree(PetscOptionsObject->title));
5216356e834SBarry Smith 
522e26ddf31SBarry Smith   /* reset counter to -2; this updates the screen with the new options for the selected method */
523e55864a3SBarry Smith   if (PetscOptionsObject->changedmethod) PetscOptionsObject->count = -2;
5247a72a596SBarry Smith   /* reset alreadyprinted flag */
525e55864a3SBarry Smith   PetscOptionsObject->alreadyprinted = PETSC_FALSE;
526e55864a3SBarry Smith   if (PetscOptionsObject->object) PetscOptionsObject->object->optionsprinted = PETSC_TRUE;
527e55864a3SBarry Smith   PetscOptionsObject->object = NULL;
52853acd3b1SBarry Smith 
52910c654e6SJacob Faibussowitsch   while ((next = PetscOptionsObject->next)) {
53010c654e6SJacob Faibussowitsch     const PetscOptionType type        = next->type;
53110c654e6SJacob Faibussowitsch     const size_t          arraylength = next->arraylength;
53210c654e6SJacob Faibussowitsch     void                 *data        = next->data;
53310c654e6SJacob Faibussowitsch 
53410c654e6SJacob Faibussowitsch     if (next->set) {
53510c654e6SJacob Faibussowitsch       char option[256], value[1024], tmp[32];
53610c654e6SJacob Faibussowitsch 
537e55864a3SBarry Smith       if (PetscOptionsObject->prefix) {
538c6a7a370SJeremy L Thompson         PetscCall(PetscStrncpy(option, "-", sizeof(option)));
539c6a7a370SJeremy L Thompson         PetscCall(PetscStrlcat(option, PetscOptionsObject->prefix, sizeof(option)));
54010c654e6SJacob Faibussowitsch         PetscCall(PetscStrlcat(option, next->option + 1, sizeof(option)));
54110c654e6SJacob Faibussowitsch       } else {
54210c654e6SJacob Faibussowitsch         PetscCall(PetscStrncpy(option, next->option, sizeof(option)));
54310c654e6SJacob Faibussowitsch       }
5446356e834SBarry Smith 
54510c654e6SJacob Faibussowitsch       switch (type) {
546d71ae5a4SJacob Faibussowitsch       case OPTION_HEAD:
547d71ae5a4SJacob Faibussowitsch         break;
5486356e834SBarry Smith       case OPTION_INT_ARRAY:
54910c654e6SJacob Faibussowitsch         PetscCall(PetscSNPrintf(value, PETSC_STATIC_ARRAY_LENGTH(value), "%d", (int)((PetscInt *)data)[0]));
55010c654e6SJacob Faibussowitsch         for (size_t j = 1; j < arraylength; ++j) {
55110c654e6SJacob Faibussowitsch           PetscCall(PetscSNPrintf(tmp, PETSC_STATIC_ARRAY_LENGTH(tmp), "%d", (int)((PetscInt *)data)[j]));
552c6a7a370SJeremy L Thompson           PetscCall(PetscStrlcat(value, ",", sizeof(value)));
553c6a7a370SJeremy L Thompson           PetscCall(PetscStrlcat(value, tmp, sizeof(value)));
5546356e834SBarry Smith         }
5556356e834SBarry Smith         break;
556d71ae5a4SJacob Faibussowitsch       case OPTION_INT:
55710c654e6SJacob Faibussowitsch         PetscCall(PetscSNPrintf(value, PETSC_STATIC_ARRAY_LENGTH(value), "%d", (int)*(PetscInt *)data));
558d71ae5a4SJacob Faibussowitsch         break;
559d71ae5a4SJacob Faibussowitsch       case OPTION_REAL:
56010c654e6SJacob Faibussowitsch         PetscCall(PetscSNPrintf(value, PETSC_STATIC_ARRAY_LENGTH(value), "%g", (double)*(PetscReal *)data));
561d71ae5a4SJacob Faibussowitsch         break;
5626356e834SBarry Smith       case OPTION_REAL_ARRAY:
56310c654e6SJacob Faibussowitsch         PetscCall(PetscSNPrintf(value, PETSC_STATIC_ARRAY_LENGTH(value), "%g", (double)((PetscReal *)data)[0]));
56410c654e6SJacob Faibussowitsch         for (size_t j = 1; j < arraylength; ++j) {
56510c654e6SJacob Faibussowitsch           PetscCall(PetscSNPrintf(tmp, PETSC_STATIC_ARRAY_LENGTH(tmp), "%g", (double)((PetscReal *)data)[j]));
566c6a7a370SJeremy L Thompson           PetscCall(PetscStrlcat(value, ",", sizeof(value)));
567c6a7a370SJeremy L Thompson           PetscCall(PetscStrlcat(value, tmp, sizeof(value)));
5686356e834SBarry Smith         }
5696356e834SBarry Smith         break;
570050cccc3SHong Zhang       case OPTION_SCALAR_ARRAY:
57110c654e6SJacob Faibussowitsch         PetscCall(PetscSNPrintf(value, PETSC_STATIC_ARRAY_LENGTH(value), "%g+%gi", (double)PetscRealPart(((PetscScalar *)data)[0]), (double)PetscImaginaryPart(((PetscScalar *)data)[0])));
57210c654e6SJacob Faibussowitsch         for (size_t j = 1; j < arraylength; ++j) {
57310c654e6SJacob Faibussowitsch           PetscCall(PetscSNPrintf(tmp, PETSC_STATIC_ARRAY_LENGTH(tmp), "%g+%gi", (double)PetscRealPart(((PetscScalar *)data)[j]), (double)PetscImaginaryPart(((PetscScalar *)data)[j])));
574c6a7a370SJeremy L Thompson           PetscCall(PetscStrlcat(value, ",", sizeof(value)));
575c6a7a370SJeremy L Thompson           PetscCall(PetscStrlcat(value, tmp, sizeof(value)));
576050cccc3SHong Zhang         }
577050cccc3SHong Zhang         break;
578d71ae5a4SJacob Faibussowitsch       case OPTION_BOOL:
57910c654e6SJacob Faibussowitsch         PetscCall(PetscSNPrintf(value, PETSC_STATIC_ARRAY_LENGTH(value), "%d", *(int *)data));
580d71ae5a4SJacob Faibussowitsch         break;
5817781c08eSBarry Smith       case OPTION_BOOL_ARRAY:
58210c654e6SJacob Faibussowitsch         PetscCall(PetscSNPrintf(value, PETSC_STATIC_ARRAY_LENGTH(value), "%d", (int)((PetscBool *)data)[0]));
58310c654e6SJacob Faibussowitsch         for (size_t j = 1; j < arraylength; ++j) {
58410c654e6SJacob Faibussowitsch           PetscCall(PetscSNPrintf(tmp, PETSC_STATIC_ARRAY_LENGTH(tmp), "%d", (int)((PetscBool *)data)[j]));
585c6a7a370SJeremy L Thompson           PetscCall(PetscStrlcat(value, ",", sizeof(value)));
586c6a7a370SJeremy L Thompson           PetscCall(PetscStrlcat(value, tmp, sizeof(value)));
5871ae3d29cSBarry Smith         }
5881ae3d29cSBarry Smith         break;
58910c654e6SJacob Faibussowitsch       case OPTION_FLIST: // fall-through
59010c654e6SJacob Faibussowitsch       case OPTION_ELIST: // fall-through
591d71ae5a4SJacob Faibussowitsch       case OPTION_STRING:
59210c654e6SJacob Faibussowitsch         PetscCall(PetscStrncpy(value, (char *)data, sizeof(value)));
593d71ae5a4SJacob Faibussowitsch         break;
5941ae3d29cSBarry Smith       case OPTION_STRING_ARRAY:
59510c654e6SJacob Faibussowitsch         PetscCall(PetscSNPrintf(value, PETSC_STATIC_ARRAY_LENGTH(value), "%s", ((char **)data)[0]));
59610c654e6SJacob Faibussowitsch         for (size_t j = 1; j < arraylength; j++) {
59710c654e6SJacob Faibussowitsch           PetscCall(PetscSNPrintf(tmp, PETSC_STATIC_ARRAY_LENGTH(tmp), "%s", ((char **)data)[j]));
598c6a7a370SJeremy L Thompson           PetscCall(PetscStrlcat(value, ",", sizeof(value)));
599c6a7a370SJeremy L Thompson           PetscCall(PetscStrlcat(value, tmp, sizeof(value)));
6001ae3d29cSBarry Smith         }
6016356e834SBarry Smith         break;
6026356e834SBarry Smith       }
6039566063dSJacob Faibussowitsch       PetscCall(PetscOptionsSetValue(PetscOptionsObject->options, option, value));
6046356e834SBarry Smith     }
60510c654e6SJacob Faibussowitsch     if (type == OPTION_ELIST) PetscCall(PetscStrNArrayDestroy(next->nlist, (char ***)&next->list));
60610c654e6SJacob Faibussowitsch     PetscCall(PetscFree(next->text));
60710c654e6SJacob Faibussowitsch     PetscCall(PetscFree(next->option));
60810c654e6SJacob Faibussowitsch     PetscCall(PetscFree(next->man));
60910c654e6SJacob Faibussowitsch     PetscCall(PetscFree(next->edata));
610c979a496SBarry Smith 
61110c654e6SJacob Faibussowitsch     if (type == OPTION_STRING || type == OPTION_FLIST || type == OPTION_ELIST) {
61210c654e6SJacob Faibussowitsch       free(data);
613c979a496SBarry Smith     } else {
61410c654e6SJacob Faibussowitsch       // use next->data instead of data because PetscFree() sets it to NULL
61510c654e6SJacob Faibussowitsch       PetscCall(PetscFree(next->data));
616c979a496SBarry Smith     }
6177781c08eSBarry Smith 
61810c654e6SJacob Faibussowitsch     last                     = next;
61910c654e6SJacob Faibussowitsch     PetscOptionsObject->next = next->next;
6209566063dSJacob Faibussowitsch     PetscCall(PetscFree(last));
6216356e834SBarry Smith   }
6229566063dSJacob Faibussowitsch   PetscCall(PetscFree(PetscOptionsObject->prefix));
62302c9f0b5SLisandro Dalcin   PetscOptionsObject->next = NULL;
6243ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
62553acd3b1SBarry Smith }
62653acd3b1SBarry Smith 
62710c654e6SJacob Faibussowitsch static PetscErrorCode GetListLength(const char *const *list, PetscInt *len)
62810c654e6SJacob Faibussowitsch {
62910c654e6SJacob Faibussowitsch   PetscInt retlen = 0;
63010c654e6SJacob Faibussowitsch 
63110c654e6SJacob Faibussowitsch   PetscFunctionBegin;
63210c654e6SJacob Faibussowitsch   PetscValidIntPointer(len, 2);
63310c654e6SJacob Faibussowitsch   while (list[retlen]) {
63410c654e6SJacob Faibussowitsch     PetscValidCharPointer(list[retlen], 1);
63510c654e6SJacob Faibussowitsch     PetscCheck(++retlen < 50, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "List argument appears to be wrong or have more than 50 entries");
63610c654e6SJacob Faibussowitsch   }
63710c654e6SJacob Faibussowitsch   PetscCheck(retlen > 2, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "List argument must have at least 2 entries: typename and type prefix");
63810c654e6SJacob Faibussowitsch   /* drop item name and prefix*/
63910c654e6SJacob Faibussowitsch   *len = retlen - 2;
64010c654e6SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
64110c654e6SJacob Faibussowitsch }
64210c654e6SJacob Faibussowitsch 
64388aa4217SBarry Smith /*MC
64453acd3b1SBarry Smith   PetscOptionsEnum - Gets the enum value for a particular option in the database.
64553acd3b1SBarry Smith 
64688aa4217SBarry Smith   Synopsis:
64788aa4217SBarry Smith   #include "petscsys.h"
6483a89f35bSSatish Balay   PetscErrorCode  PetscOptionsEnum(const char opt[],const char text[],const char man[],const char *const *list,PetscEnum currentvalue,PetscEnum *value,PetscBool  *set)
64988aa4217SBarry Smith 
6507cdbe19fSJose E. Roman   Logically Collective on the communicator passed in `PetscOptionsBegin()`
6517cdbe19fSJose E. Roman 
65253acd3b1SBarry Smith   Input Parameters:
65353acd3b1SBarry Smith + opt          - option name
65453acd3b1SBarry Smith . text         - short string that describes the option
65553acd3b1SBarry Smith . man          - manual page with additional information on option
65653acd3b1SBarry Smith . list         - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null
6570fdccdaeSBarry Smith - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
6582fe279fdSBarry Smith .vb
6592fe279fdSBarry Smith                  PetscOptionsEnum(..., obj->value,&object->value,...) or
6602fe279fdSBarry Smith                  value = defaultvalue
6612fe279fdSBarry Smith                  PetscOptionsEnum(..., value,&value,&flg);
6622fe279fdSBarry Smith                  if (flg) {
6632fe279fdSBarry Smith .ve
66453acd3b1SBarry Smith 
665d8d19677SJose E. Roman   Output Parameters:
66653acd3b1SBarry Smith + value - the  value to return
667811af0c4SBarry Smith - set   - `PETSC_TRUE` if found, else `PETSC_FALSE`
66853acd3b1SBarry Smith 
66953acd3b1SBarry Smith   Level: beginner
67053acd3b1SBarry Smith 
67195452b02SPatrick Sanan   Notes:
672811af0c4SBarry Smith   Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
67353acd3b1SBarry Smith 
674811af0c4SBarry Smith   list is usually something like `PCASMTypes` or some other predefined list of enum names
67553acd3b1SBarry Smith 
67630bab8dbSBarry Smith   If the user does not supply the option at all `value` is NOT changed. Thus
67730bab8dbSBarry Smith   you should ALWAYS initialize `value` if you access it without first checking if `set` is `PETSC_TRUE`.
6782efd9cb1SBarry Smith 
67930bab8dbSBarry Smith   The `currentvalue` passed into this routine does not get transferred to the output `value` variable automatically.
680989712b9SBarry Smith 
681db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
682db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
683db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
684db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
685c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
686db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
687db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
68888aa4217SBarry Smith M*/
689d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsEnum_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], const char *const *list, PetscEnum currentvalue, PetscEnum *value, PetscBool *set)
690d71ae5a4SJacob Faibussowitsch {
69153acd3b1SBarry Smith   PetscInt  ntext = 0;
692aa5bb8c0SSatish Balay   PetscInt  tval;
693ace3abfcSBarry Smith   PetscBool tflg;
69453acd3b1SBarry Smith 
69553acd3b1SBarry Smith   PetscFunctionBegin;
69610c654e6SJacob Faibussowitsch   PetscValidCharPointer(opt, 2);
69710c654e6SJacob Faibussowitsch   PetscValidPointer(list, 5);
69810c654e6SJacob Faibussowitsch   PetscValidPointer(value, 7);
69910c654e6SJacob Faibussowitsch   if (set) PetscValidBoolPointer(set, 8);
70010c654e6SJacob Faibussowitsch   PetscCall(GetListLength(list, &ntext));
7019566063dSJacob Faibussowitsch   PetscCall(PetscOptionsEList_Private(PetscOptionsObject, opt, text, man, list, ntext, list[currentvalue], &tval, &tflg));
702aa5bb8c0SSatish Balay   /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */
703aa5bb8c0SSatish Balay   if (tflg) *value = (PetscEnum)tval;
704aa5bb8c0SSatish Balay   if (set) *set = tflg;
7053ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
70653acd3b1SBarry Smith }
70753acd3b1SBarry Smith 
70888aa4217SBarry Smith /*MC
709d3e47460SLisandro Dalcin   PetscOptionsEnumArray - Gets an array of enum values for a particular
710d3e47460SLisandro Dalcin   option in the database.
711d3e47460SLisandro Dalcin 
71288aa4217SBarry Smith   Synopsis:
71388aa4217SBarry Smith   #include "petscsys.h"
7143a89f35bSSatish Balay   PetscErrorCode  PetscOptionsEnumArray(const char opt[],const char text[],const char man[],const char *const *list,PetscEnum value[],PetscInt *n,PetscBool  *set)
71588aa4217SBarry Smith 
7167cdbe19fSJose E. Roman   Logically Collective on the communicator passed in `PetscOptionsBegin()`
7177cdbe19fSJose E. Roman 
718d3e47460SLisandro Dalcin   Input Parameters:
719d3e47460SLisandro Dalcin + opt  - the option one is seeking
720d3e47460SLisandro Dalcin . text - short string describing option
721d3e47460SLisandro Dalcin . man  - manual page for option
72222d58ec6SMatthew G. Knepley . list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null
723c89788bdSBarry Smith - n    - maximum number of values allowed in the value array
724d3e47460SLisandro Dalcin 
725d8d19677SJose E. Roman   Output Parameters:
726d3e47460SLisandro Dalcin + value - location to copy values
727d3e47460SLisandro Dalcin . n     - actual number of values found
728811af0c4SBarry Smith - set   - `PETSC_TRUE` if found, else `PETSC_FALSE`
729d3e47460SLisandro Dalcin 
730d3e47460SLisandro Dalcin   Level: beginner
731d3e47460SLisandro Dalcin 
732d3e47460SLisandro Dalcin   Notes:
733d3e47460SLisandro Dalcin   The array must be passed as a comma separated list.
734d3e47460SLisandro Dalcin 
735d3e47460SLisandro Dalcin   There must be no intervening spaces between the values.
736d3e47460SLisandro Dalcin 
737811af0c4SBarry Smith   Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
738d3e47460SLisandro Dalcin 
739db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
740db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
741db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
742c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
743db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
744*aec76313SJacob Faibussowitsch           `PetscOptionsFList()`, `PetscOptionsEList()`
74588aa4217SBarry Smith M*/
746d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsEnumArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], const char *const *list, PetscEnum value[], PetscInt *n, PetscBool *set)
747d71ae5a4SJacob Faibussowitsch {
74810c654e6SJacob Faibussowitsch   PetscInt    nlist  = 0;
74910c654e6SJacob Faibussowitsch   const char *prefix = PetscOptionsObject->prefix;
750d3e47460SLisandro Dalcin 
751d3e47460SLisandro Dalcin   PetscFunctionBegin;
75210c654e6SJacob Faibussowitsch   PetscValidCharPointer(opt, 2);
75310c654e6SJacob Faibussowitsch   PetscValidPointer(list, 5);
75410c654e6SJacob Faibussowitsch   PetscValidPointer(value, 6);
75510c654e6SJacob Faibussowitsch   PetscValidIntPointer(n, 7);
75610c654e6SJacob Faibussowitsch   PetscCheck(*n > 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "n (%" PetscInt_FMT ") must be > 0", *n);
75710c654e6SJacob Faibussowitsch   if (set) PetscValidBoolPointer(set, 8);
75810c654e6SJacob Faibussowitsch   PetscCall(GetListLength(list, &nlist));
75910c654e6SJacob Faibussowitsch   PetscCall(PetscOptionsGetEnumArray(PetscOptionsObject->options, prefix, opt, list, value, n, set));
76010c654e6SJacob Faibussowitsch   if (ShouldPrintHelp(PetscOptionsObject)) {
76110c654e6SJacob Faibussowitsch     const MPI_Comm comm = PetscOptionsObject->comm;
76210c654e6SJacob Faibussowitsch     const PetscInt nv   = *n;
76310c654e6SJacob Faibussowitsch 
76410c654e6SJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(comm, "  -%s%s: <%s", Prefix(prefix), opt + 1, list[value[0]]));
76510c654e6SJacob Faibussowitsch     for (PetscInt i = 1; i < nv; ++i) PetscCall((*PetscHelpPrintf)(comm, ",%s", list[value[i]]));
76610c654e6SJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(comm, ">: %s (choose from)", text));
76710c654e6SJacob Faibussowitsch     for (PetscInt i = 0; i < nlist; ++i) PetscCall((*PetscHelpPrintf)(comm, " %s", list[i]));
76810c654e6SJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(comm, " (%s)\n", ManSection(man)));
769d3e47460SLisandro Dalcin   }
7703ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
771d3e47460SLisandro Dalcin }
772d3e47460SLisandro Dalcin 
77388aa4217SBarry Smith /*MC
7745a856986SBarry Smith    PetscOptionsBoundedInt - Gets an integer value greater than or equal a given bound for a particular option in the database.
7755a856986SBarry Smith 
77688aa4217SBarry Smith    Synopsis:
77788aa4217SBarry Smith    #include "petscsys.h"
77869d47153SPierre Jolivet    PetscErrorCode  PetscOptionsBoundedInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg,PetscInt bound)
77988aa4217SBarry Smith 
7807cdbe19fSJose E. Roman    Logically Collective on the communicator passed in `PetscOptionsBegin()`
7817cdbe19fSJose E. Roman 
7825a856986SBarry Smith    Input Parameters:
7835a856986SBarry Smith +  opt - option name
7845a856986SBarry Smith .  text - short string that describes the option
7855a856986SBarry Smith .  man - manual page with additional information on option
7865a856986SBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
78769d47153SPierre Jolivet .vb
78869d47153SPierre Jolivet   PetscOptionsInt(..., obj->value,&obj->value,...)
78969d47153SPierre Jolivet .ve
79069d47153SPierre Jolivet or
79169d47153SPierre Jolivet .vb
79269d47153SPierre Jolivet   value = defaultvalue
79369d47153SPierre Jolivet   PetscOptionsInt(..., value,&value,&flg);
79469d47153SPierre Jolivet   if (flg) {
79569d47153SPierre Jolivet .ve
79688aa4217SBarry Smith -  bound - the requested value should be greater than or equal this bound or an error is generated
7975a856986SBarry Smith 
798d8d19677SJose E. Roman    Output Parameters:
7995a856986SBarry Smith +  value - the integer value to return
800811af0c4SBarry Smith -  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
8015a856986SBarry Smith 
8022fe279fdSBarry Smith    Level: beginner
8032fe279fdSBarry Smith 
8045a856986SBarry Smith    Notes:
80530bab8dbSBarry Smith     If the user does not supply the option at all `value` is NOT changed. Thus
80630bab8dbSBarry Smith     you should ALWAYS initialize `value` if you access it without first checking if `flg` is `PETSC_TRUE`.
8075a856986SBarry Smith 
80830bab8dbSBarry Smith     The `currentvalue` passed into this routine does not get transferred to the output `value` variable automatically.
8095a856986SBarry Smith 
810811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
8115a856986SBarry Smith 
812db781477SPatrick Sanan .seealso: `PetscOptionsInt()`, `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
813db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`, `PetscOptionsRangeInt()`
814db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
815db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
816c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
817db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
818db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
81988aa4217SBarry Smith M*/
8205a856986SBarry Smith 
82188aa4217SBarry Smith /*MC
8225a856986SBarry Smith    PetscOptionsRangeInt - Gets an integer value within a range of values for a particular option in the database.
8235a856986SBarry Smith 
82488aa4217SBarry Smith    Synopsis:
82588aa4217SBarry Smith    #include "petscsys.h"
8263a89f35bSSatish Balay    PetscErrorCode  PetscOptionsRangeInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg,PetscInt lb,PetscInt ub)
82788aa4217SBarry Smith 
8287cdbe19fSJose E. Roman    Logically Collective on the communicator passed in `PetscOptionsBegin()`
8297cdbe19fSJose E. Roman 
8305a856986SBarry Smith    Input Parameters:
8315a856986SBarry Smith +  opt - option name
8325a856986SBarry Smith .  text - short string that describes the option
8335a856986SBarry Smith .  man - manual page with additional information on option
8345a856986SBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
8352fe279fdSBarry Smith .vb
8362fe279fdSBarry Smith                  PetscOptionsInt(..., obj->value,&obj->value,...) or
8372fe279fdSBarry Smith                  value = defaultvalue
8382fe279fdSBarry Smith                  PetscOptionsInt(..., value,&value,&flg);
8392fe279fdSBarry Smith                  if (flg) {
8402fe279fdSBarry Smith .ve
84188aa4217SBarry Smith .  lb - the lower bound, provided value must be greater than or equal to this value or an error is generated
84288aa4217SBarry Smith -  ub - the upper bound, provided value must be less than or equal to this value or an error is generated
8435a856986SBarry Smith 
844d8d19677SJose E. Roman    Output Parameters:
8455a856986SBarry Smith +  value - the integer value to return
846811af0c4SBarry Smith -  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
8475a856986SBarry Smith 
8482fe279fdSBarry Smith    Level: beginner
8492fe279fdSBarry Smith 
8505a856986SBarry Smith    Notes:
85130bab8dbSBarry Smith     If the user does not supply the option at all `value` is NOT changed. Thus
85230bab8dbSBarry Smith     you should ALWAYS initialize `value` if you access it without first checking if `flg` is `PETSC_TRUE`.
8535a856986SBarry Smith 
85430bab8dbSBarry Smith     The `currentvalue` passed into this routine does not get transferred to the output `value` variable automatically.
8555a856986SBarry Smith 
856811af0c4SBarry Smith     Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
8575a856986SBarry Smith 
858db781477SPatrick Sanan .seealso: `PetscOptionsInt()`, `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
859db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`, `PetscOptionsBoundedInt()`
860db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
861db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
862c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
863db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
864db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
86588aa4217SBarry Smith M*/
8665a856986SBarry Smith 
86788aa4217SBarry Smith /*MC
86853acd3b1SBarry Smith   PetscOptionsInt - Gets the integer value for a particular option in the database.
86953acd3b1SBarry Smith 
87088aa4217SBarry Smith   Synopsis:
87188aa4217SBarry Smith   #include "petscsys.h"
8726eeb591dSVaclav Hapla   PetscErrorCode  PetscOptionsInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg))
87388aa4217SBarry Smith 
8747cdbe19fSJose E. Roman   Logically Collective on the communicator passed in `PetscOptionsBegin()`
8757cdbe19fSJose E. Roman 
87653acd3b1SBarry Smith   Input Parameters:
87753acd3b1SBarry Smith + opt          - option name
87853acd3b1SBarry Smith . text         - short string that describes the option
87953acd3b1SBarry Smith . man          - manual page with additional information on option
8800fdccdaeSBarry Smith - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
8812fe279fdSBarry Smith .vb
8822fe279fdSBarry Smith                  PetscOptionsInt(..., obj->value,&obj->value,...) or
8832fe279fdSBarry Smith                  value = defaultvalue
8842fe279fdSBarry Smith                  PetscOptionsInt(..., value,&value,&flg);
8852fe279fdSBarry Smith                  if (flg) {
8862fe279fdSBarry Smith .ve
88753acd3b1SBarry Smith 
888d8d19677SJose E. Roman   Output Parameters:
88953acd3b1SBarry Smith + value - the integer value to return
890811af0c4SBarry Smith -  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
89153acd3b1SBarry Smith 
89230bab8dbSBarry Smith   Level: beginner
8932efd9cb1SBarry Smith 
89430bab8dbSBarry Smith   Notes:
89530bab8dbSBarry Smith   If the user does not supply the option at all `value` is NOT changed. Thus
89630bab8dbSBarry Smith   you should ALWAYS initialize `value` if you access it without first checking if `flg` is `PETSC_TRUE`.
89730bab8dbSBarry Smith 
89830bab8dbSBarry Smith   The `currentvalue` passed into this routine does not get transferred to the output `value` variable automatically.
899989712b9SBarry Smith 
900811af0c4SBarry Smith   Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
90153acd3b1SBarry Smith 
902db781477SPatrick Sanan .seealso: `PetscOptionsBoundedInt()`, `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
903db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`, `PetscOptionsRangeInt()`
904db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
905db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
906c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
907db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
908db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
90988aa4217SBarry Smith M*/
910d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsInt_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscInt currentvalue, PetscInt *value, PetscBool *set, PetscInt lb, PetscInt ub)
911d71ae5a4SJacob Faibussowitsch {
91210c654e6SJacob Faibussowitsch   const char        *prefix  = PetscOptionsObject->prefix;
91310c654e6SJacob Faibussowitsch   const PetscOptions options = PetscOptionsObject->options;
91412655325SBarry Smith   PetscBool          wasset;
91553acd3b1SBarry Smith 
91653acd3b1SBarry Smith   PetscFunctionBegin;
91710c654e6SJacob Faibussowitsch   PetscValidCharPointer(opt, 2);
91810c654e6SJacob Faibussowitsch   PetscValidIntPointer(value, 6);
91910c654e6SJacob Faibussowitsch   if (set) PetscValidBoolPointer(set, 7);
92008401ef6SPierre Jolivet   PetscCheck(currentvalue >= lb, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Current value %" PetscInt_FMT " less than allowed bound %" PetscInt_FMT, currentvalue, lb);
92108401ef6SPierre Jolivet   PetscCheck(currentvalue <= ub, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Current value %" PetscInt_FMT " greater than allowed bound %" PetscInt_FMT, currentvalue, ub);
922e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
92310c654e6SJacob Faibussowitsch     PetscOptionItem amsopt;
92410c654e6SJacob Faibussowitsch 
9259566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_INT, &amsopt));
9269566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscInt), &amsopt->data));
92712655325SBarry Smith     *(PetscInt *)amsopt->data = currentvalue;
9283e211508SBarry Smith 
92910c654e6SJacob Faibussowitsch     PetscCall(PetscOptionsGetInt(options, prefix, opt, &currentvalue, &wasset));
930ad540459SPierre Jolivet     if (wasset) *(PetscInt *)amsopt->data = currentvalue;
931af6d86caSBarry Smith   }
93210c654e6SJacob Faibussowitsch   PetscCall(PetscOptionsGetInt(options, prefix, opt, value, &wasset));
933cc73adaaSBarry 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);
934cc73adaaSBarry 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);
93544ef3d73SBarry Smith   if (set) *set = wasset;
93610c654e6SJacob Faibussowitsch   if (ShouldPrintHelp(PetscOptionsObject)) {
93710c654e6SJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s: <now %" PetscInt_FMT " : formerly %" PetscInt_FMT ">: %s (%s)\n", Prefix(prefix), opt + 1, wasset ? *value : currentvalue, currentvalue, text, ManSection(man)));
93853acd3b1SBarry Smith   }
9393ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
94053acd3b1SBarry Smith }
94153acd3b1SBarry Smith 
94288aa4217SBarry Smith /*MC
94353acd3b1SBarry Smith   PetscOptionsString - Gets the string value for a particular option in the database.
94453acd3b1SBarry Smith 
94588aa4217SBarry Smith   Synopsis:
94688aa4217SBarry Smith   #include "petscsys.h"
9473a89f35bSSatish Balay   PetscErrorCode  PetscOptionsString(const char opt[],const char text[],const char man[],const char currentvalue[],char value[],size_t len,PetscBool  *set)
94888aa4217SBarry Smith 
9497cdbe19fSJose E. Roman   Logically Collective on the communicator passed in `PetscOptionsBegin()`
9507cdbe19fSJose E. Roman 
95153acd3b1SBarry Smith   Input Parameters:
95253acd3b1SBarry Smith + opt          - option name
95353acd3b1SBarry Smith . text         - short string that describes the option
95453acd3b1SBarry Smith . man          - manual page with additional information on option
9550fdccdaeSBarry Smith . currentvalue - the current value; caller is responsible for setting this value correctly. This is not used to set value
956bcbf2dc5SJed Brown - len          - length of the result string including null terminator
95753acd3b1SBarry Smith 
958d8d19677SJose E. Roman   Output Parameters:
95953acd3b1SBarry Smith + value - the value to return
960811af0c4SBarry Smith -  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
96153acd3b1SBarry Smith 
96253acd3b1SBarry Smith   Level: beginner
96353acd3b1SBarry Smith 
96495452b02SPatrick Sanan   Notes:
965811af0c4SBarry Smith   Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
96653acd3b1SBarry Smith 
96730bab8dbSBarry Smith   If the user provided no string (for example `-optionname` `-someotheroption`) `flg` is set to `PETSC_TRUE` (and the string is filled with nulls).
9687fccdfe4SBarry Smith 
96930bab8dbSBarry Smith   If the user does not supply the option at all `value` is NOT changed. Thus
97030bab8dbSBarry Smith   you should ALWAYS initialize `value` if you access it without first checking if `flg` is `PETSC_TRUE`.
9712efd9cb1SBarry Smith 
97230bab8dbSBarry Smith   The `currentvalue` passed into this routine does not get transferred to the output `value` variable automatically.
973989712b9SBarry Smith 
974db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
975db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
976db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
977db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
978c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
979db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
980db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
98188aa4217SBarry Smith M*/
982d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsString_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], const char currentvalue[], char value[], size_t len, PetscBool *set)
983d71ae5a4SJacob Faibussowitsch {
98410c654e6SJacob Faibussowitsch   const char *prefix = PetscOptionsObject->prefix;
98544ef3d73SBarry Smith   PetscBool   lset;
98653acd3b1SBarry Smith 
98753acd3b1SBarry Smith   PetscFunctionBegin;
98810c654e6SJacob Faibussowitsch   PetscValidCharPointer(opt, 2);
98910c654e6SJacob Faibussowitsch   PetscValidCharPointer(value, 6);
99010c654e6SJacob Faibussowitsch   if (set) PetscValidBoolPointer(set, 8);
9911a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
99210c654e6SJacob Faibussowitsch     PetscOptionItem amsopt;
99310c654e6SJacob Faibussowitsch 
9949566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_STRING, &amsopt));
99564facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
9969566063dSJacob Faibussowitsch     PetscCall(PetscStrdup(currentvalue ? currentvalue : "", (char **)&amsopt->data));
997af6d86caSBarry Smith   }
99810c654e6SJacob Faibussowitsch   PetscCall(PetscOptionsGetString(PetscOptionsObject->options, prefix, opt, value, len, &lset));
99944ef3d73SBarry Smith   if (set) *set = lset;
100010c654e6SJacob Faibussowitsch   if (ShouldPrintHelp(PetscOptionsObject)) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s: <now %s : formerly %s>: %s (%s)\n", Prefix(prefix), opt + 1, lset ? value : currentvalue, currentvalue, text, ManSection(man)));
10013ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
100253acd3b1SBarry Smith }
100353acd3b1SBarry Smith 
100488aa4217SBarry Smith /*MC
1005811af0c4SBarry Smith   PetscOptionsReal - Gets the `PetscReal` value for a particular option in the database.
100653acd3b1SBarry Smith 
100788aa4217SBarry Smith   Synopsis:
100888aa4217SBarry Smith   #include "petscsys.h"
10093a89f35bSSatish Balay   PetscErrorCode  PetscOptionsReal(const char opt[],const char text[],const char man[],PetscReal currentvalue,PetscReal *value,PetscBool  *set)
101088aa4217SBarry Smith 
10117cdbe19fSJose E. Roman   Logically Collective on the communicator passed in `PetscOptionsBegin()`
10127cdbe19fSJose E. Roman 
101353acd3b1SBarry Smith   Input Parameters:
101453acd3b1SBarry Smith + opt          - option name
101553acd3b1SBarry Smith . text         - short string that describes the option
101653acd3b1SBarry Smith . man          - manual page with additional information on option
10170fdccdaeSBarry Smith - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
10182fe279fdSBarry Smith .vb
10192fe279fdSBarry Smith                  PetscOptionsReal(..., obj->value,&obj->value,...) or
10202fe279fdSBarry Smith                  value = defaultvalue
10212fe279fdSBarry Smith                  PetscOptionsReal(..., value,&value,&flg);
10222fe279fdSBarry Smith                  if (flg) {
10232fe279fdSBarry Smith .ve
102453acd3b1SBarry Smith 
1025d8d19677SJose E. Roman   Output Parameters:
102653acd3b1SBarry Smith + value - the value to return
1027811af0c4SBarry Smith -  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
102853acd3b1SBarry Smith 
102930bab8dbSBarry Smith   Level: beginner
10302efd9cb1SBarry Smith 
103130bab8dbSBarry Smith   Notes:
103230bab8dbSBarry Smith   If the user does not supply the option at all `value` is NOT changed. Thus
103330bab8dbSBarry Smith   you should ALWAYS initialize `value` if you access it without first checking if `flg` is `PETSC_TRUE`.
103430bab8dbSBarry Smith 
103530bab8dbSBarry Smith   The `currentvalue` passed into this routine does not get transferred to the output `value` variable automatically.
1036989712b9SBarry Smith 
1037811af0c4SBarry Smith   Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
103853acd3b1SBarry Smith 
1039db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
1040db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
1041db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
1042db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1043c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1044db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1045db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
104688aa4217SBarry Smith M*/
1047d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsReal_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscReal currentvalue, PetscReal *value, PetscBool *set)
1048d71ae5a4SJacob Faibussowitsch {
104910c654e6SJacob Faibussowitsch   const char *prefix = PetscOptionsObject->prefix;
105044ef3d73SBarry Smith   PetscBool   lset;
105153acd3b1SBarry Smith 
105253acd3b1SBarry Smith   PetscFunctionBegin;
105310c654e6SJacob Faibussowitsch   PetscValidCharPointer(opt, 2);
105410c654e6SJacob Faibussowitsch   PetscValidRealPointer(value, 6);
105510c654e6SJacob Faibussowitsch   if (set) PetscValidBoolPointer(set, 7);
1056e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
105710c654e6SJacob Faibussowitsch     PetscOptionItem amsopt;
105810c654e6SJacob Faibussowitsch 
10599566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_REAL, &amsopt));
10609566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscReal), &amsopt->data));
1061a297a907SKarl Rupp 
10620fdccdaeSBarry Smith     *(PetscReal *)amsopt->data = currentvalue;
1063538aa990SBarry Smith   }
106410c654e6SJacob Faibussowitsch   PetscCall(PetscOptionsGetReal(PetscOptionsObject->options, prefix, opt, value, &lset));
106544ef3d73SBarry Smith   if (set) *set = lset;
106610c654e6SJacob Faibussowitsch   if (ShouldPrintHelp(PetscOptionsObject)) {
106710c654e6SJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s: <now %g : formerly %g>: %s (%s)\n", Prefix(prefix), opt + 1, lset ? (double)*value : (double)currentvalue, (double)currentvalue, text, ManSection(man)));
106853acd3b1SBarry Smith   }
10693ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
107053acd3b1SBarry Smith }
107153acd3b1SBarry Smith 
107288aa4217SBarry Smith /*MC
1073811af0c4SBarry Smith   PetscOptionsScalar - Gets the `PetscScalar` value for a particular option in the database.
107453acd3b1SBarry Smith 
107588aa4217SBarry Smith   Synopsis:
107688aa4217SBarry Smith   #include "petscsys.h"
10773a89f35bSSatish Balay   PetscErrorCode PetscOptionsScalar(const char opt[],const char text[],const char man[],PetscScalar currentvalue,PetscScalar *value,PetscBool  *set)
107888aa4217SBarry Smith 
10797cdbe19fSJose E. Roman   Logically Collective on the communicator passed in `PetscOptionsBegin()`
10807cdbe19fSJose E. Roman 
108153acd3b1SBarry Smith   Input Parameters:
108253acd3b1SBarry Smith + opt          - option name
108353acd3b1SBarry Smith . text         - short string that describes the option
108453acd3b1SBarry Smith . man          - manual page with additional information on option
10850fdccdaeSBarry Smith - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
10862fe279fdSBarry Smith .vb
10872fe279fdSBarry Smith                  PetscOptionsScalar(..., obj->value,&obj->value,...) or
10882fe279fdSBarry Smith                  value = defaultvalue
10892fe279fdSBarry Smith                  PetscOptionsScalar(..., value,&value,&flg);
10902fe279fdSBarry Smith                  if (flg) {
10912fe279fdSBarry Smith .ve
10920fdccdaeSBarry Smith 
1093d8d19677SJose E. Roman   Output Parameters:
109453acd3b1SBarry Smith + value - the value to return
1095811af0c4SBarry Smith -  flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
109653acd3b1SBarry Smith 
109730bab8dbSBarry Smith   Level: beginner
10982efd9cb1SBarry Smith 
109930bab8dbSBarry Smith   Notes:
110030bab8dbSBarry Smith   If the user does not supply the option at all `value` is NOT changed. Thus
110130bab8dbSBarry Smith   you should ALWAYS initialize `value` if you access it without first checking if `flg` is `PETSC_TRUE`.
110230bab8dbSBarry Smith 
110330bab8dbSBarry Smith   The `currentvalue` passed into this routine does not get transferred to the output `value` variable automatically.
1104989712b9SBarry Smith 
1105811af0c4SBarry Smith   Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
110653acd3b1SBarry Smith 
1107db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
1108db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
1109db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
1110db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1111c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1112db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1113db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
111488aa4217SBarry Smith M*/
1115d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsScalar_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscScalar currentvalue, PetscScalar *value, PetscBool *set)
1116d71ae5a4SJacob Faibussowitsch {
111753acd3b1SBarry Smith   PetscFunctionBegin;
111853acd3b1SBarry Smith #if !defined(PETSC_USE_COMPLEX)
11199566063dSJacob Faibussowitsch   PetscCall(PetscOptionsReal(opt, text, man, currentvalue, value, set));
112053acd3b1SBarry Smith #else
11219566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetScalar(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, set));
112253acd3b1SBarry Smith #endif
11233ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
112453acd3b1SBarry Smith }
112553acd3b1SBarry Smith 
112688aa4217SBarry Smith /*MC
112790d69ab7SBarry 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
112890d69ab7SBarry Smith   its value is set to false.
112953acd3b1SBarry Smith 
113088aa4217SBarry Smith   Synopsis:
113188aa4217SBarry Smith   #include "petscsys.h"
11323a89f35bSSatish Balay   PetscErrorCode PetscOptionsName(const char opt[],const char text[],const char man[],PetscBool  *flg)
113388aa4217SBarry Smith 
11347cdbe19fSJose E. Roman   Logically Collective on the communicator passed in `PetscOptionsBegin()`
11357cdbe19fSJose E. Roman 
113653acd3b1SBarry Smith   Input Parameters:
113753acd3b1SBarry Smith + opt  - option name
113853acd3b1SBarry Smith . text - short string that describes the option
113953acd3b1SBarry Smith - man  - manual page with additional information on option
114053acd3b1SBarry Smith 
114153acd3b1SBarry Smith   Output Parameter:
1142811af0c4SBarry Smith . flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
114353acd3b1SBarry Smith 
114453acd3b1SBarry Smith   Level: beginner
114553acd3b1SBarry Smith 
1146811af0c4SBarry Smith   Note:
1147811af0c4SBarry Smith   Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
114853acd3b1SBarry Smith 
1149db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
1150db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
1151db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
1152db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1153c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1154db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1155db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
115688aa4217SBarry Smith M*/
1157d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsName_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool *flg)
1158d71ae5a4SJacob Faibussowitsch {
115910c654e6SJacob Faibussowitsch   const char *prefix = PetscOptionsObject->prefix;
116053acd3b1SBarry Smith 
116153acd3b1SBarry Smith   PetscFunctionBegin;
116210c654e6SJacob Faibussowitsch   PetscValidCharPointer(opt, 2);
116310c654e6SJacob Faibussowitsch   PetscValidBoolPointer(flg, 5);
1164e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
116510c654e6SJacob Faibussowitsch     PetscOptionItem amsopt;
116610c654e6SJacob Faibussowitsch 
11679566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt));
11689566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data));
1169a297a907SKarl Rupp 
1170ace3abfcSBarry Smith     *(PetscBool *)amsopt->data = PETSC_FALSE;
11711ae3d29cSBarry Smith   }
117210c654e6SJacob Faibussowitsch   PetscCall(PetscOptionsHasName(PetscOptionsObject->options, prefix, opt, flg));
117310c654e6SJacob Faibussowitsch   if (ShouldPrintHelp(PetscOptionsObject)) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s: %s (%s)\n", Prefix(prefix), opt + 1, text, ManSection(man)));
11743ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
117553acd3b1SBarry Smith }
117653acd3b1SBarry Smith 
117788aa4217SBarry Smith /*MC
1178a264d7a6SBarry Smith   PetscOptionsFList - Puts a list of option values that a single one may be selected from
117953acd3b1SBarry Smith 
118088aa4217SBarry Smith   Synopsis:
118188aa4217SBarry Smith   #include "petscsys.h"
11823a89f35bSSatish Balay   PetscErrorCode  PetscOptionsFList(const char opt[],const char ltext[],const char man[],PetscFunctionList list,const char currentvalue[],char value[],size_t len,PetscBool  *set)
118388aa4217SBarry Smith 
11847cdbe19fSJose E. Roman   Logically Collective on the communicator passed in `PetscOptionsBegin()`
11857cdbe19fSJose E. Roman 
118653acd3b1SBarry Smith   Input Parameters:
118753acd3b1SBarry Smith + opt          - option name
118853acd3b1SBarry Smith .  text - short string that describes the option
118953acd3b1SBarry Smith . man          - manual page with additional information on option
119053acd3b1SBarry Smith . list         - the possible choices
11910fdccdaeSBarry Smith . currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with
11922fe279fdSBarry Smith .vb
11932fe279fdSBarry Smith                  PetscOptionsFlist(..., obj->value,value,len,&flg);
11942fe279fdSBarry Smith                  if (flg) {
11952fe279fdSBarry Smith .ve
11963cc1e11dSBarry Smith - len          - the length of the character array value
119753acd3b1SBarry Smith 
1198d8d19677SJose E. Roman   Output Parameters:
119953acd3b1SBarry Smith + value - the value to return
1200811af0c4SBarry Smith - set   - `PETSC_TRUE` if found, else `PETSC_FALSE`
120153acd3b1SBarry Smith 
120253acd3b1SBarry Smith   Level: intermediate
120353acd3b1SBarry Smith 
120495452b02SPatrick Sanan   Notes:
1205811af0c4SBarry Smith   Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
120653acd3b1SBarry Smith 
120730bab8dbSBarry Smith   If the user does not supply the option at all `value` is NOT changed. Thus
120830bab8dbSBarry Smith   you should ALWAYS initialize `value` if you access it without first checking if the `set` flag is `PETSC_TRUE`.
12092efd9cb1SBarry Smith 
121030bab8dbSBarry Smith   The `currentvalue` passed into this routine does not get transferred to the output `value` variable automatically.
1211989712b9SBarry Smith 
1212811af0c4SBarry Smith   See `PetscOptionsEList()` for when the choices are given in a string array
121353acd3b1SBarry Smith 
121453acd3b1SBarry Smith   To get a listing of all currently specified options,
1215811af0c4SBarry Smith   see `PetscOptionsView()` or `PetscOptionsGetAll()`
121653acd3b1SBarry Smith 
1217*aec76313SJacob Faibussowitsch   Developer Notes:
1218811af0c4SBarry Smith   This cannot check for invalid selection because of things like `MATAIJ` that are not included in the list
1219eabe10d7SBarry Smith 
1220db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1221db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1222db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1223c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1224db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1225db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`, `PetscOptionsEnum()`
122688aa4217SBarry Smith M*/
1227d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsFList_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char ltext[], const char man[], PetscFunctionList list, const char currentvalue[], char value[], size_t len, PetscBool *set)
1228d71ae5a4SJacob Faibussowitsch {
122910c654e6SJacob Faibussowitsch   const char *prefix = PetscOptionsObject->prefix;
123044ef3d73SBarry Smith   PetscBool   lset;
123153acd3b1SBarry Smith 
123253acd3b1SBarry Smith   PetscFunctionBegin;
123310c654e6SJacob Faibussowitsch   PetscValidCharPointer(opt, 2);
123410c654e6SJacob Faibussowitsch   PetscValidCharPointer(value, 7);
123510c654e6SJacob Faibussowitsch   if (set) PetscValidBoolPointer(set, 9);
12361a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
123710c654e6SJacob Faibussowitsch     PetscOptionItem amsopt;
123810c654e6SJacob Faibussowitsch 
12399566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, ltext, man, OPTION_FLIST, &amsopt));
124064facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
12419566063dSJacob Faibussowitsch     PetscCall(PetscStrdup(currentvalue ? currentvalue : "", (char **)&amsopt->data));
12423cc1e11dSBarry Smith     amsopt->flist = list;
12433cc1e11dSBarry Smith   }
124410c654e6SJacob Faibussowitsch   PetscCall(PetscOptionsGetString(PetscOptionsObject->options, prefix, opt, value, len, &lset));
124544ef3d73SBarry Smith   if (set) *set = lset;
124610c654e6SJacob Faibussowitsch   if (ShouldPrintHelp(PetscOptionsObject)) PetscCall(PetscFunctionListPrintTypes(PetscOptionsObject->comm, stdout, Prefix(prefix), opt, ltext, man, list, currentvalue, lset ? value : currentvalue));
12473ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
124853acd3b1SBarry Smith }
124953acd3b1SBarry Smith 
125010c654e6SJacob Faibussowitsch #ifdef __cplusplus
125110c654e6SJacob Faibussowitsch   #include <type_traits>
125210c654e6SJacob Faibussowitsch #endif
125310c654e6SJacob Faibussowitsch 
125488aa4217SBarry Smith /*MC
125553acd3b1SBarry Smith   PetscOptionsEList - Puts a list of option values that a single one may be selected from
125653acd3b1SBarry Smith 
125788aa4217SBarry Smith   Synopsis:
125888aa4217SBarry Smith   #include "petscsys.h"
12593a89f35bSSatish 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)
126088aa4217SBarry Smith 
12617cdbe19fSJose E. Roman   Logically Collective on the communicator passed in `PetscOptionsBegin()`
12627cdbe19fSJose E. Roman 
126353acd3b1SBarry Smith   Input Parameters:
126453acd3b1SBarry Smith + opt          - option name
126553acd3b1SBarry Smith . ltext        - short string that describes the option
126653acd3b1SBarry Smith . man          - manual page with additional information on option
1267a264d7a6SBarry Smith . list         - the possible choices (one of these must be selected, anything else is invalid)
126853acd3b1SBarry Smith . ntext        - number of choices
12690fdccdaeSBarry Smith - currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with
12702fe279fdSBarry Smith .vb
12712fe279fdSBarry Smith                  PetscOptionsEList(..., obj->value,&value,&flg);
12722fe279fdSBarry Smith .ve                 if (flg) {
12730fdccdaeSBarry Smith 
1274d8d19677SJose E. Roman   Output Parameters:
127553acd3b1SBarry Smith + value - the index of the value to return
1276811af0c4SBarry Smith - set   - `PETSC_TRUE` if found, else `PETSC_FALSE`
127753acd3b1SBarry Smith 
127853acd3b1SBarry Smith   Level: intermediate
127953acd3b1SBarry Smith 
128095452b02SPatrick Sanan   Notes:
1281811af0c4SBarry Smith   Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
128253acd3b1SBarry Smith 
128330bab8dbSBarry Smith   If the user does not supply the option at all `value` is NOT changed. Thus
128430bab8dbSBarry Smith   you should ALWAYS initialize `value` if you access it without first checking if the `set` flag is `PETSC_TRUE`.
12852efd9cb1SBarry Smith 
1286811af0c4SBarry Smith   See `PetscOptionsFList()` for when the choices are given in a `PetscFunctionList()`
128753acd3b1SBarry Smith 
1288db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1289db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1290db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1291c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1292db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1293db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEnum()`
129488aa4217SBarry Smith M*/
1295d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsEList_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char ltext[], const char man[], const char *const *list, PetscInt ntext, const char currentvalue[], PetscInt *value, PetscBool *set)
1296d71ae5a4SJacob Faibussowitsch {
129710c654e6SJacob Faibussowitsch   const char *prefix = PetscOptionsObject->prefix;
129844ef3d73SBarry Smith   PetscBool   lset;
129953acd3b1SBarry Smith 
130053acd3b1SBarry Smith   PetscFunctionBegin;
130110c654e6SJacob Faibussowitsch   PetscValidCharPointer(opt, 2);
130210c654e6SJacob Faibussowitsch   PetscValidIntPointer(value, 8);
130310c654e6SJacob Faibussowitsch   if (set) PetscValidBoolPointer(set, 9);
13041a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
130510c654e6SJacob Faibussowitsch     PetscOptionItem amsopt;
130610c654e6SJacob Faibussowitsch 
13079566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, ltext, man, OPTION_ELIST, &amsopt));
130864facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
13099566063dSJacob Faibussowitsch     PetscCall(PetscStrdup(currentvalue ? currentvalue : "", (char **)&amsopt->data));
13109566063dSJacob Faibussowitsch     PetscCall(PetscStrNArrayallocpy(ntext, list, (char ***)&amsopt->list));
131110c654e6SJacob Faibussowitsch     PetscCheck(ntext <= CHAR_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Number of list entries %" PetscInt_FMT " > %d", ntext, CHAR_MAX);
131210c654e6SJacob Faibussowitsch #ifdef __cplusplus
131310c654e6SJacob Faibussowitsch     static_assert(std::is_same<typename std::decay<decltype(amsopt->nlist)>::type, char>::value, "");
131410c654e6SJacob Faibussowitsch #endif
131510c654e6SJacob Faibussowitsch     amsopt->nlist = (char)ntext;
13161ae3d29cSBarry Smith   }
131710c654e6SJacob Faibussowitsch   PetscCall(PetscOptionsGetEList(PetscOptionsObject->options, prefix, opt, list, ntext, value, &lset));
131844ef3d73SBarry Smith   if (set) *set = lset;
131910c654e6SJacob Faibussowitsch   if (ShouldPrintHelp(PetscOptionsObject)) {
132010c654e6SJacob Faibussowitsch     const MPI_Comm comm = PetscOptionsObject->comm;
132110c654e6SJacob Faibussowitsch 
132210c654e6SJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(comm, "  -%s%s: <now %s : formerly %s> %s (choose one of)", Prefix(prefix), opt + 1, lset ? list[*value] : currentvalue, currentvalue, ltext));
132310c654e6SJacob Faibussowitsch     for (PetscInt i = 0; i < ntext; ++i) PetscCall((*PetscHelpPrintf)(comm, " %s", list[i]));
132410c654e6SJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(comm, " (%s)\n", ManSection(man)));
132553acd3b1SBarry Smith   }
13263ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
132753acd3b1SBarry Smith }
132853acd3b1SBarry Smith 
132988aa4217SBarry Smith /*MC
1330acfcf0e5SJed Brown   PetscOptionsBoolGroupBegin - First in a series of logical queries on the options database for
1331d5649816SBarry Smith   which at most a single value can be true.
133253acd3b1SBarry Smith 
133388aa4217SBarry Smith   Synopsis:
133488aa4217SBarry Smith   #include "petscsys.h"
13353a89f35bSSatish Balay   PetscErrorCode PetscOptionsBoolGroupBegin(const char opt[],const char text[],const char man[],PetscBool  *flg)
133688aa4217SBarry Smith 
13377cdbe19fSJose E. Roman   Logically Collective on the communicator passed in `PetscOptionsBegin()`
13387cdbe19fSJose E. Roman 
133953acd3b1SBarry Smith   Input Parameters:
134053acd3b1SBarry Smith + opt  - option name
134153acd3b1SBarry Smith . text - short string that describes the option
134253acd3b1SBarry Smith - man  - manual page with additional information on option
134353acd3b1SBarry Smith 
134453acd3b1SBarry Smith   Output Parameter:
134553acd3b1SBarry Smith . flg - whether that option was set or not
134653acd3b1SBarry Smith 
134753acd3b1SBarry Smith   Level: intermediate
134853acd3b1SBarry Smith 
134995452b02SPatrick Sanan   Notes:
1350811af0c4SBarry Smith   Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
135153acd3b1SBarry Smith 
135230bab8dbSBarry Smith   Must be followed by 0 or more `PetscOptionsBoolGroup()`s and `PetscOptionsBoolGroupEnd()`
135353acd3b1SBarry Smith 
1354db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1355db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1356db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1357c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1358db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1359db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
136088aa4217SBarry Smith M*/
1361d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsBoolGroupBegin_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool *flg)
1362d71ae5a4SJacob Faibussowitsch {
136310c654e6SJacob Faibussowitsch   const char *prefix = PetscOptionsObject->prefix;
136453acd3b1SBarry Smith 
136553acd3b1SBarry Smith   PetscFunctionBegin;
136610c654e6SJacob Faibussowitsch   PetscValidCharPointer(opt, 2);
136710c654e6SJacob Faibussowitsch   PetscValidBoolPointer(flg, 5);
1368e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
136910c654e6SJacob Faibussowitsch     PetscOptionItem amsopt;
137010c654e6SJacob Faibussowitsch 
13719566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt));
13729566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data));
1373a297a907SKarl Rupp 
1374ace3abfcSBarry Smith     *(PetscBool *)amsopt->data = PETSC_FALSE;
13751ae3d29cSBarry Smith   }
137668b16fdaSBarry Smith   *flg = PETSC_FALSE;
137710c654e6SJacob Faibussowitsch   PetscCall(PetscOptionsGetBool(PetscOptionsObject->options, prefix, opt, flg, NULL));
137810c654e6SJacob Faibussowitsch   if (ShouldPrintHelp(PetscOptionsObject)) {
137910c654e6SJacob Faibussowitsch     const MPI_Comm comm = PetscOptionsObject->comm;
138010c654e6SJacob Faibussowitsch 
138110c654e6SJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(comm, "  Pick at most one of -------------\n"));
138210c654e6SJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(comm, "    -%s%s: %s (%s)\n", Prefix(prefix), opt + 1, text, ManSection(man)));
138353acd3b1SBarry Smith   }
13843ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
138553acd3b1SBarry Smith }
138653acd3b1SBarry Smith 
138788aa4217SBarry Smith /*MC
1388acfcf0e5SJed Brown   PetscOptionsBoolGroup - One in a series of logical queries on the options database for
1389d5649816SBarry Smith   which at most a single value can be true.
139053acd3b1SBarry Smith 
139188aa4217SBarry Smith   Synopsis:
139288aa4217SBarry Smith   #include "petscsys.h"
13933a89f35bSSatish Balay   PetscErrorCode PetscOptionsBoolGroup(const char opt[],const char text[],const char man[],PetscBool  *flg)
139488aa4217SBarry Smith 
13957cdbe19fSJose E. Roman   Logically Collective on the communicator passed in `PetscOptionsBegin()`
13967cdbe19fSJose E. Roman 
139753acd3b1SBarry Smith   Input Parameters:
139853acd3b1SBarry Smith + opt  - option name
139953acd3b1SBarry Smith . text - short string that describes the option
140053acd3b1SBarry Smith - man  - manual page with additional information on option
140153acd3b1SBarry Smith 
140253acd3b1SBarry Smith   Output Parameter:
1403811af0c4SBarry Smith . flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
140453acd3b1SBarry Smith 
140553acd3b1SBarry Smith   Level: intermediate
140653acd3b1SBarry Smith 
140795452b02SPatrick Sanan   Notes:
1408811af0c4SBarry Smith   Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
140953acd3b1SBarry Smith 
1410811af0c4SBarry Smith   Must follow a `PetscOptionsBoolGroupBegin()` and preceded a `PetscOptionsBoolGroupEnd()`
141153acd3b1SBarry Smith 
1412db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1413db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1414db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1415c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1416db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1417db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
141888aa4217SBarry Smith M*/
1419d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsBoolGroup_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool *flg)
1420d71ae5a4SJacob Faibussowitsch {
142110c654e6SJacob Faibussowitsch   const char *prefix = PetscOptionsObject->prefix;
142253acd3b1SBarry Smith 
142353acd3b1SBarry Smith   PetscFunctionBegin;
142410c654e6SJacob Faibussowitsch   PetscValidCharPointer(opt, 2);
142510c654e6SJacob Faibussowitsch   PetscValidBoolPointer(flg, 5);
1426e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
142710c654e6SJacob Faibussowitsch     PetscOptionItem amsopt;
142810c654e6SJacob Faibussowitsch 
14299566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt));
14309566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data));
1431a297a907SKarl Rupp 
1432ace3abfcSBarry Smith     *(PetscBool *)amsopt->data = PETSC_FALSE;
14331ae3d29cSBarry Smith   }
143417326d04SJed Brown   *flg = PETSC_FALSE;
143510c654e6SJacob Faibussowitsch   PetscCall(PetscOptionsGetBool(PetscOptionsObject->options, prefix, opt, flg, NULL));
143610c654e6SJacob Faibussowitsch   if (ShouldPrintHelp(PetscOptionsObject)) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "    -%s%s: %s (%s)\n", Prefix(prefix), opt + 1, text, ManSection(man)));
14373ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
143853acd3b1SBarry Smith }
143953acd3b1SBarry Smith 
144088aa4217SBarry Smith /*MC
1441acfcf0e5SJed Brown   PetscOptionsBoolGroupEnd - Last in a series of logical queries on the options database for
1442d5649816SBarry Smith   which at most a single value can be true.
144353acd3b1SBarry Smith 
144488aa4217SBarry Smith   Synopsis:
144588aa4217SBarry Smith   #include "petscsys.h"
14463a89f35bSSatish Balay   PetscErrorCode PetscOptionsBoolGroupEnd(const char opt[],const char text[],const char man[],PetscBool  *flg)
144788aa4217SBarry Smith 
14487cdbe19fSJose E. Roman   Logically Collective on the communicator passed in `PetscOptionsBegin()`
14497cdbe19fSJose E. Roman 
145053acd3b1SBarry Smith   Input Parameters:
145153acd3b1SBarry Smith + opt  - option name
145253acd3b1SBarry Smith . text - short string that describes the option
145353acd3b1SBarry Smith - man  - manual page with additional information on option
145453acd3b1SBarry Smith 
145553acd3b1SBarry Smith   Output Parameter:
1456811af0c4SBarry Smith . flg - `PETSC_TRUE` if found, else `PETSC_FALSE`
145753acd3b1SBarry Smith 
145853acd3b1SBarry Smith   Level: intermediate
145953acd3b1SBarry Smith 
146095452b02SPatrick Sanan   Notes:
1461811af0c4SBarry Smith   Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
146253acd3b1SBarry Smith 
1463811af0c4SBarry Smith   Must follow a `PetscOptionsBoolGroupBegin()`
146453acd3b1SBarry Smith 
1465db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1466db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1467db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1468c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1469db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1470db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
147188aa4217SBarry Smith M*/
1472d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsBoolGroupEnd_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool *flg)
1473d71ae5a4SJacob Faibussowitsch {
147410c654e6SJacob Faibussowitsch   const char *prefix = PetscOptionsObject->prefix;
147553acd3b1SBarry Smith 
147653acd3b1SBarry Smith   PetscFunctionBegin;
147710c654e6SJacob Faibussowitsch   PetscValidCharPointer(opt, 2);
147810c654e6SJacob Faibussowitsch   PetscValidBoolPointer(flg, 5);
1479e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
148010c654e6SJacob Faibussowitsch     PetscOptionItem amsopt;
148110c654e6SJacob Faibussowitsch 
14829566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt));
14839566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data));
1484a297a907SKarl Rupp 
1485ace3abfcSBarry Smith     *(PetscBool *)amsopt->data = PETSC_FALSE;
14861ae3d29cSBarry Smith   }
148717326d04SJed Brown   *flg = PETSC_FALSE;
148810c654e6SJacob Faibussowitsch   PetscCall(PetscOptionsGetBool(PetscOptionsObject->options, prefix, opt, flg, NULL));
148910c654e6SJacob Faibussowitsch   if (ShouldPrintHelp(PetscOptionsObject)) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "    -%s%s: %s (%s)\n", Prefix(prefix), opt + 1, text, ManSection(man)));
14903ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
149153acd3b1SBarry Smith }
149253acd3b1SBarry Smith 
149388aa4217SBarry Smith /*MC
1494acfcf0e5SJed Brown   PetscOptionsBool - Determines if a particular option is in the database with a true or false
149553acd3b1SBarry Smith 
149688aa4217SBarry Smith   Synopsis:
149788aa4217SBarry Smith   #include "petscsys.h"
14983a89f35bSSatish Balay   PetscErrorCode PetscOptionsBool(const char opt[],const char text[],const char man[],PetscBool currentvalue,PetscBool  *flg,PetscBool  *set)
149988aa4217SBarry Smith 
15007cdbe19fSJose E. Roman   Logically Collective on the communicator passed in `PetscOptionsBegin()`
15017cdbe19fSJose E. Roman 
150253acd3b1SBarry Smith   Input Parameters:
150353acd3b1SBarry Smith + opt          - option name
150453acd3b1SBarry Smith . text         - short string that describes the option
1505868c398cSBarry Smith . man          - manual page with additional information on option
150694ae4db5SBarry Smith - currentvalue - the current value
150753acd3b1SBarry Smith 
1508d8d19677SJose E. Roman   Output Parameters:
1509811af0c4SBarry Smith +  flg -` PETSC_TRUE` or `PETSC_FALSE`
1510811af0c4SBarry Smith - set - `PETSC_TRUE` if found, else `PETSC_FALSE`
151153acd3b1SBarry Smith 
151230bab8dbSBarry Smith   Level: beginner
151330bab8dbSBarry Smith 
15142efd9cb1SBarry Smith   Notes:
1515811af0c4SBarry Smith   TRUE, true, YES, yes, nostring, and 1 all translate to `PETSC_TRUE`
1516811af0c4SBarry Smith   FALSE, false, NO, no, and 0 all translate to `PETSC_FALSE`
15172efd9cb1SBarry Smith 
151830bab8dbSBarry 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`
151930bab8dbSBarry Smith   is equivalent to `-requested_bool true`
15202efd9cb1SBarry Smith 
152130bab8dbSBarry Smith   If the user does not supply the option at all `flg` is NOT changed. Thus
152230bab8dbSBarry Smith   you should ALWAYS initialize the `flg` variable if you access it without first checking if the `set` flag is `PETSC_TRUE`.
15232efd9cb1SBarry Smith 
1524811af0c4SBarry Smith   Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
152553acd3b1SBarry Smith 
1526db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
1527db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
1528db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`,
1529db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1530c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1531db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1532db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
153388aa4217SBarry Smith M*/
1534d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsBool_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool currentvalue, PetscBool *flg, PetscBool *set)
1535d71ae5a4SJacob Faibussowitsch {
153610c654e6SJacob Faibussowitsch   const char *prefix = PetscOptionsObject->prefix;
1537ace3abfcSBarry Smith   PetscBool   iset;
153853acd3b1SBarry Smith 
153953acd3b1SBarry Smith   PetscFunctionBegin;
154010c654e6SJacob Faibussowitsch   PetscValidCharPointer(opt, 2);
154110c654e6SJacob Faibussowitsch   PetscValidBoolPointer(flg, 6);
154210c654e6SJacob Faibussowitsch   if (set) PetscValidBoolPointer(set, 7);
1543e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
154410c654e6SJacob Faibussowitsch     PetscOptionItem amsopt;
154510c654e6SJacob Faibussowitsch 
15469566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt));
15479566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data));
1548a297a907SKarl Rupp 
154994ae4db5SBarry Smith     *(PetscBool *)amsopt->data = currentvalue;
1550af6d86caSBarry Smith   }
155110c654e6SJacob Faibussowitsch   PetscCall(PetscOptionsGetBool(PetscOptionsObject->options, prefix, opt, flg, &iset));
155253acd3b1SBarry Smith   if (set) *set = iset;
155310c654e6SJacob Faibussowitsch   if (ShouldPrintHelp(PetscOptionsObject)) {
155410c654e6SJacob Faibussowitsch     const char *curvalue = PetscBools[currentvalue];
155510c654e6SJacob Faibussowitsch 
155610c654e6SJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s: <now %s : formerly %s> %s (%s)\n", Prefix(prefix), opt + 1, iset ? PetscBools[*flg] : curvalue, curvalue, text, ManSection(man)));
155753acd3b1SBarry Smith   }
15583ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
155953acd3b1SBarry Smith }
156053acd3b1SBarry Smith 
156188aa4217SBarry Smith /*MC
156253acd3b1SBarry Smith   PetscOptionsRealArray - Gets an array of double values for a particular
156353acd3b1SBarry Smith   option in the database. The values must be separated with commas with
156453acd3b1SBarry Smith   no intervening spaces.
156553acd3b1SBarry Smith 
156688aa4217SBarry Smith   Synopsis:
156788aa4217SBarry Smith   #include "petscsys.h"
15683a89f35bSSatish Balay   PetscErrorCode PetscOptionsRealArray(const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscBool  *set)
156988aa4217SBarry Smith 
15707cdbe19fSJose E. Roman   Logically Collective on the communicator passed in `PetscOptionsBegin()`
15717cdbe19fSJose E. Roman 
157253acd3b1SBarry Smith   Input Parameters:
157353acd3b1SBarry Smith + opt  - the option one is seeking
157453acd3b1SBarry Smith . text - short string describing option
157553acd3b1SBarry Smith . man  - manual page for option
1576c89788bdSBarry Smith - n    - maximum number of values that value has room for
157753acd3b1SBarry Smith 
1578d8d19677SJose E. Roman   Output Parameters:
157953acd3b1SBarry Smith + value - location to copy values
1580c89788bdSBarry Smith . n     - actual number of values found
1581811af0c4SBarry Smith - set   - `PETSC_TRUE` if found, else `PETSC_FALSE`
158253acd3b1SBarry Smith 
158353acd3b1SBarry Smith   Level: beginner
158453acd3b1SBarry Smith 
158530bab8dbSBarry Smith   Note:
1586811af0c4SBarry 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()`
159488aa4217SBarry Smith M*/
1595d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsRealArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscReal value[], PetscInt *n, PetscBool *set)
1596d71ae5a4SJacob Faibussowitsch {
159710c654e6SJacob Faibussowitsch   const char *prefix = PetscOptionsObject->prefix;
159853acd3b1SBarry Smith 
159953acd3b1SBarry Smith   PetscFunctionBegin;
160010c654e6SJacob Faibussowitsch   PetscValidCharPointer(opt, 2);
160110c654e6SJacob Faibussowitsch   PetscValidIntPointer(n, 6);
160210c654e6SJacob Faibussowitsch   PetscCheck(*n >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "n (%" PetscInt_FMT ") cannot be negative", *n);
160310c654e6SJacob Faibussowitsch   if (*n) PetscValidRealPointer(value, 5);
160410c654e6SJacob Faibussowitsch   if (set) PetscValidBoolPointer(set, 7);
1605e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
160610c654e6SJacob Faibussowitsch     const PetscInt  nv = *n;
1607e26ddf31SBarry Smith     PetscReal      *vals;
160810c654e6SJacob Faibussowitsch     PetscOptionItem amsopt;
1609e26ddf31SBarry Smith 
16109566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_REAL_ARRAY, &amsopt));
161110c654e6SJacob Faibussowitsch     PetscCall(PetscMalloc(nv * sizeof(*vals), &vals));
161210c654e6SJacob Faibussowitsch     for (PetscInt i = 0; i < nv; ++i) vals[i] = value[i];
161310c654e6SJacob Faibussowitsch     amsopt->arraylength = nv;
161410c654e6SJacob Faibussowitsch     amsopt->data        = vals;
1615e26ddf31SBarry Smith   }
161610c654e6SJacob Faibussowitsch   PetscCall(PetscOptionsGetRealArray(PetscOptionsObject->options, prefix, opt, value, n, set));
161710c654e6SJacob Faibussowitsch   if (ShouldPrintHelp(PetscOptionsObject)) {
161810c654e6SJacob Faibussowitsch     const PetscInt nv   = *n;
161910c654e6SJacob Faibussowitsch     const MPI_Comm comm = PetscOptionsObject->comm;
162010c654e6SJacob Faibussowitsch 
162110c654e6SJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(comm, "  -%s%s: <%g", Prefix(prefix), opt + 1, (double)value[0]));
162210c654e6SJacob Faibussowitsch     for (PetscInt i = 1; i < nv; ++i) PetscCall((*PetscHelpPrintf)(comm, ",%g", (double)value[i]));
162310c654e6SJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(comm, ">: %s (%s)\n", text, ManSection(man)));
162453acd3b1SBarry Smith   }
16253ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
162653acd3b1SBarry Smith }
162753acd3b1SBarry Smith 
162888aa4217SBarry Smith /*MC
1629811af0c4SBarry Smith   PetscOptionsScalarArray - Gets an array of `PetscScalar` values for a particular
1630050cccc3SHong Zhang   option in the database. The values must be separated with commas with
1631050cccc3SHong Zhang   no intervening spaces.
1632050cccc3SHong Zhang 
163388aa4217SBarry Smith   Synopsis:
163488aa4217SBarry Smith   #include "petscsys.h"
16353a89f35bSSatish Balay   PetscErrorCode PetscOptionsScalarArray(const char opt[],const char text[],const char man[],PetscScalar value[],PetscInt *n,PetscBool  *set)
163688aa4217SBarry Smith 
16377cdbe19fSJose E. Roman   Logically Collective on the communicator passed in `PetscOptionsBegin()`
16387cdbe19fSJose E. Roman 
1639050cccc3SHong Zhang   Input Parameters:
1640050cccc3SHong Zhang + opt  - the option one is seeking
1641050cccc3SHong Zhang . text - short string describing option
1642050cccc3SHong Zhang . man  - manual page for option
1643c89788bdSBarry Smith - n    - maximum number of values allowed in the value array
1644050cccc3SHong Zhang 
1645d8d19677SJose E. Roman   Output Parameters:
1646050cccc3SHong Zhang + value - location to copy values
1647c89788bdSBarry Smith . n     - actual number of values found
1648811af0c4SBarry Smith - set   - `PETSC_TRUE` if found, else `PETSC_FALSE`
1649050cccc3SHong Zhang 
1650050cccc3SHong Zhang   Level: beginner
1651050cccc3SHong Zhang 
165230bab8dbSBarry Smith   Note:
1653811af0c4SBarry Smith   Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
1654050cccc3SHong Zhang 
1655db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1656db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1657db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1658c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1659db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1660db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
166188aa4217SBarry Smith M*/
1662d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsScalarArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscScalar value[], PetscInt *n, PetscBool *set)
1663d71ae5a4SJacob Faibussowitsch {
166410c654e6SJacob Faibussowitsch   const char *prefix = PetscOptionsObject->prefix;
1665050cccc3SHong Zhang 
1666050cccc3SHong Zhang   PetscFunctionBegin;
166710c654e6SJacob Faibussowitsch   PetscValidCharPointer(opt, 2);
166810c654e6SJacob Faibussowitsch   PetscValidIntPointer(n, 6);
166910c654e6SJacob Faibussowitsch   PetscCheck(*n >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "n (%" PetscInt_FMT ") cannot be negative", *n);
167010c654e6SJacob Faibussowitsch   if (*n) PetscValidScalarPointer(value, 5);
167110c654e6SJacob Faibussowitsch   if (set) PetscValidBoolPointer(set, 7);
1672050cccc3SHong Zhang   if (!PetscOptionsObject->count) {
167310c654e6SJacob Faibussowitsch     const PetscInt  nv = *n;
167410c654e6SJacob Faibussowitsch     PetscOptionItem amsopt;
1675050cccc3SHong Zhang     PetscScalar    *vals;
1676050cccc3SHong Zhang 
16779566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_SCALAR_ARRAY, &amsopt));
167810c654e6SJacob Faibussowitsch     PetscCall(PetscMalloc(nv * sizeof(*vals), &vals));
167910c654e6SJacob Faibussowitsch     for (PetscInt i = 0; i < nv; ++i) vals[i] = value[i];
168010c654e6SJacob Faibussowitsch     amsopt->arraylength = nv;
168110c654e6SJacob Faibussowitsch     amsopt->data        = vals;
1682050cccc3SHong Zhang   }
168310c654e6SJacob Faibussowitsch   PetscCall(PetscOptionsGetScalarArray(PetscOptionsObject->options, prefix, opt, value, n, set));
168410c654e6SJacob Faibussowitsch   if (ShouldPrintHelp(PetscOptionsObject)) {
168510c654e6SJacob Faibussowitsch     const PetscInt nv   = *n;
168610c654e6SJacob Faibussowitsch     const MPI_Comm comm = PetscOptionsObject->comm;
168710c654e6SJacob Faibussowitsch 
168810c654e6SJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(comm, "  -%s%s: <%g+%gi", Prefix(prefix), opt + 1, (double)PetscRealPart(value[0]), (double)PetscImaginaryPart(value[0])));
168910c654e6SJacob Faibussowitsch     for (PetscInt i = 1; i < nv; ++i) PetscCall((*PetscHelpPrintf)(comm, ",%g+%gi", (double)PetscRealPart(value[i]), (double)PetscImaginaryPart(value[i])));
169010c654e6SJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(comm, ">: %s (%s)\n", text, ManSection(man)));
1691050cccc3SHong Zhang   }
16923ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1693050cccc3SHong Zhang }
169453acd3b1SBarry Smith 
169588aa4217SBarry Smith /*MC
169653acd3b1SBarry Smith   PetscOptionsIntArray - Gets an array of integers for a particular
1697b32a342fSShri Abhyankar   option in the database.
169853acd3b1SBarry Smith 
169988aa4217SBarry Smith   Synopsis:
170088aa4217SBarry Smith   #include "petscsys.h"
17013a89f35bSSatish Balay   PetscErrorCode PetscOptionsIntArray(const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscBool  *set)
170288aa4217SBarry Smith 
17037cdbe19fSJose E. Roman   Logically Collective on the communicator passed in `PetscOptionsBegin()`
17047cdbe19fSJose E. Roman 
170553acd3b1SBarry Smith   Input Parameters:
170653acd3b1SBarry Smith + opt  - the option one is seeking
170753acd3b1SBarry Smith . text - short string describing option
170853acd3b1SBarry Smith . man  - manual page for option
1709f8a50e2bSBarry Smith - n    - maximum number of values
171053acd3b1SBarry Smith 
1711d8d19677SJose E. Roman   Output Parameters:
171253acd3b1SBarry Smith + value - location to copy values
1713f8a50e2bSBarry Smith . n     - actual number of values found
1714811af0c4SBarry Smith - set   - `PETSC_TRUE` if found, else `PETSC_FALSE`
171553acd3b1SBarry Smith 
171653acd3b1SBarry Smith   Level: beginner
171753acd3b1SBarry Smith 
171853acd3b1SBarry Smith   Notes:
1719b32a342fSShri Abhyankar   The array can be passed as
1720811af0c4SBarry Smith +   a comma separated list -                                  0,1,2,3,4,5,6,7
1721811af0c4SBarry Smith .   a range (start\-end+1) -                                  0-8
1722811af0c4SBarry Smith .   a range with given increment (start\-end+1:inc) -         0-7:2
1723811af0c4SBarry Smith -   a combination of values and ranges separated by commas -  0,1-8,8-15:2
1724b32a342fSShri Abhyankar 
1725b32a342fSShri Abhyankar   There must be no intervening spaces between the values.
172653acd3b1SBarry Smith 
1727811af0c4SBarry Smith   Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
172853acd3b1SBarry Smith 
1729db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1730db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1731db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1732c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1733db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1734*aec76313SJacob Faibussowitsch           `PetscOptionsFList()`, `PetscOptionsEList()`
173588aa4217SBarry Smith M*/
1736d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsIntArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscInt value[], PetscInt *n, PetscBool *set)
1737d71ae5a4SJacob Faibussowitsch {
173810c654e6SJacob Faibussowitsch   const char *prefix = PetscOptionsObject->prefix;
173953acd3b1SBarry Smith 
174053acd3b1SBarry Smith   PetscFunctionBegin;
174110c654e6SJacob Faibussowitsch   PetscValidCharPointer(opt, 2);
174210c654e6SJacob Faibussowitsch   PetscValidIntPointer(n, 6);
174310c654e6SJacob Faibussowitsch   PetscCheck(*n >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "n (%" PetscInt_FMT ") cannot be negative", *n);
174410c654e6SJacob Faibussowitsch   if (*n) PetscValidIntPointer(value, 5);
174510c654e6SJacob Faibussowitsch   if (set) PetscValidBoolPointer(set, 7);
1746e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
174710c654e6SJacob Faibussowitsch     const PetscInt  nv = *n;
1748e26ddf31SBarry Smith     PetscInt       *vals;
174910c654e6SJacob Faibussowitsch     PetscOptionItem amsopt;
1750e26ddf31SBarry Smith 
17519566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_INT_ARRAY, &amsopt));
175210c654e6SJacob Faibussowitsch     PetscCall(PetscMalloc1(nv, &vals));
175310c654e6SJacob Faibussowitsch     for (PetscInt i = 0; i < nv; ++i) vals[i] = value[i];
175410c654e6SJacob Faibussowitsch     amsopt->arraylength = nv;
175510c654e6SJacob Faibussowitsch     amsopt->data        = vals;
1756e26ddf31SBarry Smith   }
175710c654e6SJacob Faibussowitsch   PetscCall(PetscOptionsGetIntArray(PetscOptionsObject->options, prefix, opt, value, n, set));
175810c654e6SJacob Faibussowitsch   if (ShouldPrintHelp(PetscOptionsObject)) {
175910c654e6SJacob Faibussowitsch     const PetscInt nv   = *n;
176010c654e6SJacob Faibussowitsch     const MPI_Comm comm = PetscOptionsObject->comm;
176110c654e6SJacob Faibussowitsch 
176210c654e6SJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(comm, "  -%s%s: <%" PetscInt_FMT, Prefix(prefix), opt + 1, value[0]));
176310c654e6SJacob Faibussowitsch     for (PetscInt i = 1; i < nv; ++i) PetscCall((*PetscHelpPrintf)(comm, ",%" PetscInt_FMT, value[i]));
176410c654e6SJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(comm, ">: %s (%s)\n", text, ManSection(man)));
176553acd3b1SBarry Smith   }
17663ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
176753acd3b1SBarry Smith }
176853acd3b1SBarry Smith 
176988aa4217SBarry Smith /*MC
177053acd3b1SBarry Smith   PetscOptionsStringArray - Gets an array of string values for a particular
177153acd3b1SBarry Smith   option in the database. The values must be separated with commas with
177253acd3b1SBarry Smith   no intervening spaces.
177353acd3b1SBarry Smith 
177488aa4217SBarry Smith   Synopsis:
177588aa4217SBarry Smith   #include "petscsys.h"
17763a89f35bSSatish Balay   PetscErrorCode PetscOptionsStringArray(const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscBool  *set)
177788aa4217SBarry Smith 
17787cdbe19fSJose E. Roman   Logically Collective on the communicator passed in `PetscOptionsBegin()`; No Fortran Support
17797cdbe19fSJose E. Roman 
178053acd3b1SBarry Smith   Input Parameters:
178153acd3b1SBarry Smith + opt  - the option one is seeking
178253acd3b1SBarry Smith . text - short string describing option
178353acd3b1SBarry Smith . man  - manual page for option
178453acd3b1SBarry Smith - nmax - maximum number of strings
178553acd3b1SBarry Smith 
1786d8d19677SJose E. Roman   Output Parameters:
178753acd3b1SBarry Smith + value - location to copy strings
178853acd3b1SBarry Smith . nmax  - actual number of strings found
1789811af0c4SBarry Smith - set   - `PETSC_TRUE` if found, else `PETSC_FALSE`
179053acd3b1SBarry Smith 
179153acd3b1SBarry Smith   Level: beginner
179253acd3b1SBarry Smith 
179353acd3b1SBarry Smith   Notes:
179453acd3b1SBarry Smith   The user should pass in an array of pointers to char, to hold all the
179553acd3b1SBarry Smith   strings returned by this function.
179653acd3b1SBarry Smith 
179753acd3b1SBarry Smith   The user is responsible for deallocating the strings that are
1798cf53795eSBarry Smith   returned.
179953acd3b1SBarry Smith 
1800811af0c4SBarry Smith   Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
180153acd3b1SBarry Smith 
1802db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1803db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1804db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1805c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1806db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1807db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
180888aa4217SBarry Smith M*/
1809d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsStringArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], char *value[], PetscInt *nmax, PetscBool *set)
1810d71ae5a4SJacob Faibussowitsch {
181110c654e6SJacob Faibussowitsch   const char *prefix = PetscOptionsObject->prefix;
181253acd3b1SBarry Smith 
181353acd3b1SBarry Smith   PetscFunctionBegin;
181410c654e6SJacob Faibussowitsch   PetscValidCharPointer(opt, 2);
181510c654e6SJacob Faibussowitsch   PetscValidIntPointer(nmax, 6);
181610c654e6SJacob Faibussowitsch   PetscCheck(*nmax >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "n (%" PetscInt_FMT ") cannot be negative", *nmax);
181710c654e6SJacob Faibussowitsch   if (*nmax) PetscValidPointer(value, 5);
181810c654e6SJacob Faibussowitsch   if (set) PetscValidBoolPointer(set, 7);
1819e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
182010c654e6SJacob Faibussowitsch     const PetscInt  nmaxv = *nmax;
182110c654e6SJacob Faibussowitsch     PetscOptionItem amsopt;
1822a297a907SKarl Rupp 
182310c654e6SJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_STRING_ARRAY, &amsopt));
182410c654e6SJacob Faibussowitsch     PetscCall(PetscMalloc1(nmaxv, (char **)&amsopt->data));
182510c654e6SJacob Faibussowitsch     amsopt->arraylength = nmaxv;
18261ae3d29cSBarry Smith   }
182710c654e6SJacob Faibussowitsch   PetscCall(PetscOptionsGetStringArray(PetscOptionsObject->options, prefix, opt, value, nmax, set));
182810c654e6SJacob Faibussowitsch   if (ShouldPrintHelp(PetscOptionsObject)) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s: <string1,string2,...>: %s (%s)\n", Prefix(prefix), opt + 1, text, ManSection(man)));
18293ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
183053acd3b1SBarry Smith }
183153acd3b1SBarry Smith 
183288aa4217SBarry Smith /*MC
1833acfcf0e5SJed Brown   PetscOptionsBoolArray - Gets an array of logical values (true or false) for a particular
1834e2446a98SMatthew Knepley   option in the database. The values must be separated with commas with
1835e2446a98SMatthew Knepley   no intervening spaces.
1836e2446a98SMatthew Knepley 
183788aa4217SBarry Smith   Synopsis:
183888aa4217SBarry Smith   #include "petscsys.h"
18393a89f35bSSatish Balay   PetscErrorCode PetscOptionsBoolArray(const char opt[],const char text[],const char man[],PetscBool value[],PetscInt *n,PetscBool *set)
184088aa4217SBarry Smith 
18417cdbe19fSJose E. Roman   Logically Collective on the communicator passed in `PetscOptionsBegin()`
18427cdbe19fSJose E. Roman 
1843e2446a98SMatthew Knepley   Input Parameters:
1844e2446a98SMatthew Knepley + opt  - the option one is seeking
1845e2446a98SMatthew Knepley . text - short string describing option
1846e2446a98SMatthew Knepley . man  - manual page for option
1847c89788bdSBarry Smith - n    - maximum number of values allowed in the value array
1848e2446a98SMatthew Knepley 
1849d8d19677SJose E. Roman   Output Parameters:
1850e2446a98SMatthew Knepley + value - location to copy values
1851c89788bdSBarry Smith . n     - actual number of values found
1852811af0c4SBarry Smith - set   - `PETSC_TRUE` if found, else `PETSC_FALSE`
1853e2446a98SMatthew Knepley 
1854e2446a98SMatthew Knepley   Level: beginner
1855e2446a98SMatthew Knepley 
1856e2446a98SMatthew Knepley   Notes:
185730bab8dbSBarry Smith   The user should pass in an array of `PetscBool`
1858e2446a98SMatthew Knepley 
1859811af0c4SBarry Smith   Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
1860e2446a98SMatthew Knepley 
1861db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1862db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1863db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1864c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1865db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1866db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
186788aa4217SBarry Smith M*/
1868d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsBoolArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool value[], PetscInt *n, PetscBool *set)
1869d71ae5a4SJacob Faibussowitsch {
187010c654e6SJacob Faibussowitsch   const char *prefix = PetscOptionsObject->prefix;
1871e2446a98SMatthew Knepley 
1872e2446a98SMatthew Knepley   PetscFunctionBegin;
187310c654e6SJacob Faibussowitsch   PetscValidCharPointer(opt, 2);
187410c654e6SJacob Faibussowitsch   PetscValidIntPointer(n, 6);
187510c654e6SJacob Faibussowitsch   PetscCheck(*n >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "n (%" PetscInt_FMT ") cannot be negative", *n);
187610c654e6SJacob Faibussowitsch   if (*n) PetscValidBoolPointer(value, 5);
187710c654e6SJacob Faibussowitsch   if (set) PetscValidBoolPointer(set, 7);
1878e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
187910c654e6SJacob Faibussowitsch     const PetscInt  nv = *n;
1880ace3abfcSBarry Smith     PetscBool      *vals;
188110c654e6SJacob Faibussowitsch     PetscOptionItem amsopt;
18821ae3d29cSBarry Smith 
18839566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL_ARRAY, &amsopt));
188410c654e6SJacob Faibussowitsch     PetscCall(PetscMalloc1(nv, &vals));
188510c654e6SJacob Faibussowitsch     for (PetscInt i = 0; i < nv; ++i) vals[i] = value[i];
188610c654e6SJacob Faibussowitsch     amsopt->arraylength = nv;
188710c654e6SJacob Faibussowitsch     amsopt->data        = vals;
18881ae3d29cSBarry Smith   }
188910c654e6SJacob Faibussowitsch   PetscCall(PetscOptionsGetBoolArray(PetscOptionsObject->options, prefix, opt, value, n, set));
189010c654e6SJacob Faibussowitsch   if (ShouldPrintHelp(PetscOptionsObject)) {
189110c654e6SJacob Faibussowitsch     const PetscInt nv   = *n;
189210c654e6SJacob Faibussowitsch     const MPI_Comm comm = PetscOptionsObject->comm;
189310c654e6SJacob Faibussowitsch 
189410c654e6SJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(comm, "  -%s%s: <%d", Prefix(prefix), opt + 1, value[0]));
189510c654e6SJacob Faibussowitsch     for (PetscInt i = 1; i < nv; ++i) PetscCall((*PetscHelpPrintf)(comm, ",%d", value[i]));
189610c654e6SJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(comm, ">: %s (%s)\n", text, ManSection(man)));
1897e2446a98SMatthew Knepley   }
18983ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1899e2446a98SMatthew Knepley }
1900e2446a98SMatthew Knepley 
190188aa4217SBarry Smith /*MC
1902d1da0b69SBarry Smith   PetscOptionsViewer - Gets a viewer appropriate for the type indicated by the user
19038cc676e6SMatthew G Knepley 
190488aa4217SBarry Smith   Synopsis:
190588aa4217SBarry Smith   #include "petscsys.h"
19063a89f35bSSatish Balay   PetscErrorCode PetscOptionsViewer(const char opt[],const char text[],const char man[],PetscViewer *viewer,PetscViewerFormat *format,PetscBool *set)
190788aa4217SBarry Smith 
19087cdbe19fSJose E. Roman   Logically Collective on the communicator passed in `PetscOptionsBegin()`
19097cdbe19fSJose E. Roman 
19108cc676e6SMatthew G Knepley   Input Parameters:
19118cc676e6SMatthew G Knepley + opt  - option name
19128cc676e6SMatthew G Knepley . text - short string that describes the option
19138cc676e6SMatthew G Knepley - man  - manual page with additional information on option
19148cc676e6SMatthew G Knepley 
1915d8d19677SJose E. Roman   Output Parameters:
19168cc676e6SMatthew G Knepley + viewer - the viewer
19177962402dSFande Kong . format - the PetscViewerFormat requested by the user, pass NULL if not needed
1918811af0c4SBarry Smith - set    - `PETSC_TRUE` if found, else `PETSC_FALSE`
19198cc676e6SMatthew G Knepley 
19208cc676e6SMatthew G Knepley   Level: beginner
19218cc676e6SMatthew G Knepley 
192295452b02SPatrick Sanan   Notes:
1923811af0c4SBarry Smith   Must be between a `PetscOptionsBegin()` and a `PetscOptionsEnd()`
19248cc676e6SMatthew G Knepley 
1925811af0c4SBarry Smith   See `PetscOptionsGetViewer()` for the format of the supplied viewer and its options
19268cc676e6SMatthew G Knepley 
1927db781477SPatrick Sanan .seealso: `PetscOptionsGetViewer()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
1928db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`
1929*aec76313SJacob Faibussowitsch           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`,
1930db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1931c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1932db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1933db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
193488aa4217SBarry Smith M*/
1935d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscOptionsViewer_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscViewer *viewer, PetscViewerFormat *format, PetscBool *set)
1936d71ae5a4SJacob Faibussowitsch {
193710c654e6SJacob Faibussowitsch   const MPI_Comm comm   = PetscOptionsObject->comm;
193810c654e6SJacob Faibussowitsch   const char    *prefix = PetscOptionsObject->prefix;
19398cc676e6SMatthew G Knepley 
19408cc676e6SMatthew G Knepley   PetscFunctionBegin;
194110c654e6SJacob Faibussowitsch   PetscValidCharPointer(opt, 2);
194210c654e6SJacob Faibussowitsch   PetscValidPointer(viewer, 5);
194310c654e6SJacob Faibussowitsch   if (format) PetscValidPointer(format, 6);
194410c654e6SJacob Faibussowitsch   if (set) PetscValidBoolPointer(set, 7);
19451a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
194610c654e6SJacob Faibussowitsch     PetscOptionItem amsopt;
194710c654e6SJacob Faibussowitsch 
19489566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_STRING, &amsopt));
194964facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
19509566063dSJacob Faibussowitsch     PetscCall(PetscStrdup("", (char **)&amsopt->data));
19518cc676e6SMatthew G Knepley   }
195210c654e6SJacob Faibussowitsch   PetscCall(PetscOptionsGetViewer(comm, PetscOptionsObject->options, prefix, opt, viewer, format, set));
195310c654e6SJacob Faibussowitsch   if (ShouldPrintHelp(PetscOptionsObject)) PetscCall((*PetscHelpPrintf)(comm, "  -%s%s: <%s>: %s (%s)\n", Prefix(prefix), opt + 1, "", text, ManSection(man)));
19543ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
19558cc676e6SMatthew G Knepley }
1956