xref: /petsc/src/sys/objects/aoptions.c (revision 48a46eb9bd028bec07ec0f396b1a3abb43f14558)
153acd3b1SBarry Smith /*
23fc1eb6aSBarry Smith    Implements the higher-level options database querying methods. These are self-documenting and can attach at runtime to
33fc1eb6aSBarry Smith    GUI code to display the options and get values from the users.
453acd3b1SBarry Smith 
553acd3b1SBarry Smith */
653acd3b1SBarry Smith 
7af0996ceSBarry Smith #include <petsc/private/petscimpl.h> /*I  "petscsys.h"   I*/
8665c2dedSJed Brown #include <petscviewer.h>
953acd3b1SBarry Smith 
102aa6d131SJed Brown #define ManSection(str) ((str) ? (str) : "None")
112aa6d131SJed Brown 
1253acd3b1SBarry Smith /*
1353acd3b1SBarry Smith     Keep a linked list of options that have been posted and we are waiting for
143fc1eb6aSBarry Smith    user selection. See the manual page for PetscOptionsBegin()
1553acd3b1SBarry Smith 
1653acd3b1SBarry Smith     Eventually we'll attach this beast to a MPI_Comm
1753acd3b1SBarry Smith */
18e55864a3SBarry Smith 
1953acd3b1SBarry Smith /*
2053acd3b1SBarry Smith     Handles setting up the data structure in a call to PetscOptionsBegin()
2153acd3b1SBarry Smith */
229371c9d4SSatish Balay PetscErrorCode PetscOptionsBegin_Private(PetscOptionItems *PetscOptionsObject, MPI_Comm comm, const char prefix[], const char title[], const char mansec[]) {
2353acd3b1SBarry Smith   PetscFunctionBegin;
24064a246eSJacob Faibussowitsch   if (prefix) PetscValidCharPointer(prefix, 3);
25064a246eSJacob Faibussowitsch   PetscValidCharPointer(title, 4);
26064a246eSJacob Faibussowitsch   if (mansec) PetscValidCharPointer(mansec, 5);
270eb63584SBarry Smith   if (!PetscOptionsObject->alreadyprinted) {
289566063dSJacob Faibussowitsch     if (!PetscOptionsHelpPrintedSingleton) PetscCall(PetscOptionsHelpPrintedCreate(&PetscOptionsHelpPrintedSingleton));
299566063dSJacob Faibussowitsch     PetscCall(PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrintedSingleton, prefix, title, &PetscOptionsObject->alreadyprinted));
300eb63584SBarry Smith   }
3102c9f0b5SLisandro Dalcin   PetscOptionsObject->next          = NULL;
32e55864a3SBarry Smith   PetscOptionsObject->comm          = comm;
33e55864a3SBarry Smith   PetscOptionsObject->changedmethod = PETSC_FALSE;
34a297a907SKarl Rupp 
359566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(prefix, &PetscOptionsObject->prefix));
369566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(title, &PetscOptionsObject->title));
3753acd3b1SBarry Smith 
389566063dSJacob Faibussowitsch   PetscCall(PetscOptionsHasHelp(PetscOptionsObject->options, &PetscOptionsObject->printhelp));
39e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1) {
40*48a46eb9SPierre Jolivet     if (!PetscOptionsObject->alreadyprinted) PetscCall((*PetscHelpPrintf)(comm, "----------------------------------------\n%s:\n", title));
4161b37b28SSatish Balay   }
4253acd3b1SBarry Smith   PetscFunctionReturn(0);
4353acd3b1SBarry Smith }
4453acd3b1SBarry Smith 
453194b578SJed Brown /*
463194b578SJed Brown     Handles setting up the data structure in a call to PetscObjectOptionsBegin()
473194b578SJed Brown */
489371c9d4SSatish Balay PetscErrorCode PetscObjectOptionsBegin_Private(PetscObject obj, PetscOptionItems *PetscOptionsObject) {
493194b578SJed Brown   char      title[256];
503194b578SJed Brown   PetscBool flg;
513194b578SJed Brown 
523194b578SJed Brown   PetscFunctionBegin;
53dbbe0bcdSBarry Smith   PetscValidPointer(PetscOptionsObject, 2);
54dbbe0bcdSBarry Smith   PetscValidHeader(obj, 1);
55e55864a3SBarry Smith   PetscOptionsObject->object         = obj;
56e55864a3SBarry Smith   PetscOptionsObject->alreadyprinted = obj->optionsprinted;
57a297a907SKarl Rupp 
589566063dSJacob Faibussowitsch   PetscCall(PetscStrcmp(obj->description, obj->class_name, &flg));
599566063dSJacob Faibussowitsch   if (flg) PetscCall(PetscSNPrintf(title, sizeof(title), "%s options", obj->class_name));
609566063dSJacob Faibussowitsch   else PetscCall(PetscSNPrintf(title, sizeof(title), "%s (%s) options", obj->description, obj->class_name));
619566063dSJacob Faibussowitsch   PetscCall(PetscOptionsBegin_Private(PetscOptionsObject, obj->comm, obj->prefix, title, obj->mansec));
623194b578SJed Brown   PetscFunctionReturn(0);
633194b578SJed Brown }
643194b578SJed Brown 
6553acd3b1SBarry Smith /*
6653acd3b1SBarry Smith      Handles adding another option to the list of options within this particular PetscOptionsBegin() PetscOptionsEnd()
6753acd3b1SBarry Smith */
689371c9d4SSatish Balay static int PetscOptionItemCreate_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscOptionType t, PetscOptionItem *amsopt) {
694416b707SBarry Smith   PetscOptionItem next;
703be6e4c3SJed Brown   PetscBool       valid;
7153acd3b1SBarry Smith 
7253acd3b1SBarry Smith   PetscFunctionBegin;
739566063dSJacob Faibussowitsch   PetscCall(PetscOptionsValidKey(opt, &valid));
745f80ce2aSJacob Faibussowitsch   PetscCheck(valid, PETSC_COMM_WORLD, PETSC_ERR_ARG_INCOMP, "The option '%s' is not a valid key", opt);
753be6e4c3SJed Brown 
769566063dSJacob Faibussowitsch   PetscCall(PetscNew(amsopt));
7702c9f0b5SLisandro Dalcin   (*amsopt)->next = NULL;
7853acd3b1SBarry Smith   (*amsopt)->set  = PETSC_FALSE;
796356e834SBarry Smith   (*amsopt)->type = t;
8002c9f0b5SLisandro Dalcin   (*amsopt)->data = NULL;
8161b37b28SSatish Balay 
829566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(text, &(*amsopt)->text));
839566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(opt, &(*amsopt)->option));
849566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(man, &(*amsopt)->man));
8553acd3b1SBarry Smith 
86e55864a3SBarry Smith   if (!PetscOptionsObject->next) PetscOptionsObject->next = *amsopt;
87a297a907SKarl Rupp   else {
88e55864a3SBarry Smith     next = PetscOptionsObject->next;
8953acd3b1SBarry Smith     while (next->next) next = next->next;
9053acd3b1SBarry Smith     next->next = *amsopt;
9153acd3b1SBarry Smith   }
9253acd3b1SBarry Smith   PetscFunctionReturn(0);
9353acd3b1SBarry Smith }
9453acd3b1SBarry Smith 
95aee2cecaSBarry Smith /*
963fc1eb6aSBarry Smith     PetscScanString -  Gets user input via stdin from process and broadcasts to all processes
973fc1eb6aSBarry Smith 
98d083f849SBarry Smith     Collective
993fc1eb6aSBarry Smith 
1003fc1eb6aSBarry Smith    Input Parameters:
1013fc1eb6aSBarry Smith +     commm - communicator for the broadcast, must be PETSC_COMM_WORLD
1023fc1eb6aSBarry Smith .     n - length of the string, must be the same on all processes
1033fc1eb6aSBarry Smith -     str - location to store input
104aee2cecaSBarry Smith 
105aee2cecaSBarry Smith     Bugs:
106aee2cecaSBarry Smith .   Assumes process 0 of the given communicator has access to stdin
107aee2cecaSBarry Smith 
108aee2cecaSBarry Smith */
1099371c9d4SSatish Balay static PetscErrorCode PetscScanString(MPI_Comm comm, size_t n, char str[]) {
1103fc1eb6aSBarry Smith   PetscMPIInt rank, nm;
111aee2cecaSBarry Smith 
112aee2cecaSBarry Smith   PetscFunctionBegin;
1139566063dSJacob Faibussowitsch   PetscCallMPI(MPI_Comm_rank(comm, &rank));
114dd400576SPatrick Sanan   if (rank == 0) {
1155f80ce2aSJacob Faibussowitsch     char   c = (char)getchar();
1165f80ce2aSJacob Faibussowitsch     size_t i = 0;
1175f80ce2aSJacob Faibussowitsch 
118aee2cecaSBarry Smith     while (c != '\n' && i < n - 1) {
119aee2cecaSBarry Smith       str[i++] = c;
120aee2cecaSBarry Smith       c        = (char)getchar();
121aee2cecaSBarry Smith     }
122aee2cecaSBarry Smith     str[i] = 0;
123aee2cecaSBarry Smith   }
1249566063dSJacob Faibussowitsch   PetscCall(PetscMPIIntCast(n, &nm));
1259566063dSJacob Faibussowitsch   PetscCallMPI(MPI_Bcast(str, nm, MPI_CHAR, 0, comm));
126aee2cecaSBarry Smith   PetscFunctionReturn(0);
127aee2cecaSBarry Smith }
128aee2cecaSBarry Smith 
1295b02f95dSBarry Smith /*
1305b02f95dSBarry Smith     This is needed because certain strings may be freed by SAWs, hence we cannot use PetscStrallocpy()
1315b02f95dSBarry Smith */
1329371c9d4SSatish Balay static PetscErrorCode PetscStrdup(const char s[], char *t[]) {
13302c9f0b5SLisandro Dalcin   char *tmp = NULL;
1345b02f95dSBarry Smith 
1355b02f95dSBarry Smith   PetscFunctionBegin;
1365b02f95dSBarry Smith   if (s) {
1375f80ce2aSJacob Faibussowitsch     size_t len;
1385f80ce2aSJacob Faibussowitsch 
1399566063dSJacob Faibussowitsch     PetscCall(PetscStrlen(s, &len));
1405f80ce2aSJacob Faibussowitsch     tmp = (char *)malloc((len + 1) * sizeof(*tmp));
1415f80ce2aSJacob Faibussowitsch     PetscCheck(tmp, PETSC_COMM_SELF, PETSC_ERR_MEM, "No memory to duplicate string");
1429566063dSJacob Faibussowitsch     PetscCall(PetscStrcpy(tmp, s));
1435b02f95dSBarry Smith   }
1445b02f95dSBarry Smith   *t = tmp;
1455b02f95dSBarry Smith   PetscFunctionReturn(0);
1465b02f95dSBarry Smith }
1475b02f95dSBarry Smith 
148aee2cecaSBarry Smith /*
1493cc1e11dSBarry Smith     PetscOptionsGetFromTextInput - Presents all the PETSc Options processed by the program so the user may change them at runtime
150aee2cecaSBarry Smith 
15195452b02SPatrick Sanan     Notes:
15295452b02SPatrick Sanan     this isn't really practical, it is just to demonstrate the principle
153aee2cecaSBarry Smith 
1547781c08eSBarry Smith     A carriage return indicates no change from the default; but this like -ksp_monitor <stdout>  the default is actually not stdout the default
1557781c08eSBarry Smith     is to do nothing so to get it to use stdout you need to type stdout. This is kind of bug?
1567781c08eSBarry Smith 
157aee2cecaSBarry Smith     Bugs:
1587781c08eSBarry Smith +    All processes must traverse through the exact same set of option queries due to the call to PetscScanString()
1593cc1e11dSBarry Smith .    Internal strings have arbitrary length and string copies are not checked that they fit into string space
160aee2cecaSBarry Smith -    Only works for PetscInt == int, PetscReal == double etc
161aee2cecaSBarry Smith 
16295452b02SPatrick Sanan     Developer Notes:
16395452b02SPatrick Sanan     Normally the GUI that presents the options the user and retrieves the values would be running in a different
1643cc1e11dSBarry Smith      address space and communicating with the PETSc program
1653cc1e11dSBarry Smith 
166aee2cecaSBarry Smith */
1679371c9d4SSatish Balay PetscErrorCode PetscOptionsGetFromTextInput(PetscOptionItems *PetscOptionsObject) {
1684416b707SBarry Smith   PetscOptionItem next = PetscOptionsObject->next;
1696356e834SBarry Smith   char            str[512];
1707781c08eSBarry Smith   PetscBool       bid;
171a4404d99SBarry Smith   PetscReal       ir, *valr;
172330cf3c9SBarry Smith   PetscInt       *vald;
173330cf3c9SBarry Smith   size_t          i;
1746356e834SBarry Smith 
1752a409bb0SBarry Smith   PetscFunctionBegin;
1769566063dSJacob Faibussowitsch   PetscCall((*PetscPrintf)(PETSC_COMM_WORLD, "%s --------------------\n", PetscOptionsObject->title));
1776356e834SBarry Smith   while (next) {
1786356e834SBarry Smith     switch (next->type) {
1799371c9d4SSatish Balay     case OPTION_HEAD: break;
180e26ddf31SBarry Smith     case OPTION_INT_ARRAY:
1819566063dSJacob Faibussowitsch       PetscCall(PetscPrintf(PETSC_COMM_WORLD, "-%s%s <", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1));
182e26ddf31SBarry Smith       vald = (PetscInt *)next->data;
183e26ddf31SBarry Smith       for (i = 0; i < next->arraylength; i++) {
1849566063dSJacob Faibussowitsch         PetscCall(PetscPrintf(PETSC_COMM_WORLD, "%" PetscInt_FMT, vald[i]));
185*48a46eb9SPierre Jolivet         if (i < next->arraylength - 1) PetscCall(PetscPrintf(PETSC_COMM_WORLD, ","));
186e26ddf31SBarry Smith       }
1879566063dSJacob Faibussowitsch       PetscCall(PetscPrintf(PETSC_COMM_WORLD, ">: %s (%s) ", next->text, next->man));
1889566063dSJacob Faibussowitsch       PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str));
189e26ddf31SBarry Smith       if (str[0]) {
190e26ddf31SBarry Smith         PetscToken token;
191e26ddf31SBarry Smith         PetscInt   n = 0, nmax = next->arraylength, *dvalue = (PetscInt *)next->data, start, end;
192e26ddf31SBarry Smith         size_t     len;
193e26ddf31SBarry Smith         char      *value;
194ace3abfcSBarry Smith         PetscBool  foundrange;
195e26ddf31SBarry Smith 
196e26ddf31SBarry Smith         next->set = PETSC_TRUE;
197e26ddf31SBarry Smith         value     = str;
1989566063dSJacob Faibussowitsch         PetscCall(PetscTokenCreate(value, ',', &token));
1999566063dSJacob Faibussowitsch         PetscCall(PetscTokenFind(token, &value));
200e26ddf31SBarry Smith         while (n < nmax) {
201e26ddf31SBarry Smith           if (!value) break;
202e26ddf31SBarry Smith 
203e26ddf31SBarry Smith           /* look for form  d-D where d and D are integers */
204e26ddf31SBarry Smith           foundrange = PETSC_FALSE;
2059566063dSJacob Faibussowitsch           PetscCall(PetscStrlen(value, &len));
206e26ddf31SBarry Smith           if (value[0] == '-') i = 2;
207e26ddf31SBarry Smith           else i = 1;
208330cf3c9SBarry Smith           for (; i < len; i++) {
209e26ddf31SBarry Smith             if (value[i] == '-') {
21008401ef6SPierre Jolivet               PetscCheck(i != len - 1, PETSC_COMM_SELF, PETSC_ERR_USER, "Error in %" PetscInt_FMT "-th array entry %s", n, value);
211e26ddf31SBarry Smith               value[i] = 0;
2129566063dSJacob Faibussowitsch               PetscCall(PetscOptionsStringToInt(value, &start));
2139566063dSJacob Faibussowitsch               PetscCall(PetscOptionsStringToInt(value + i + 1, &end));
21408401ef6SPierre Jolivet               PetscCheck(end > start, PETSC_COMM_SELF, PETSC_ERR_USER, "Error in %" PetscInt_FMT "-th array entry, %s-%s cannot have decreasing list", n, value, value + i + 1);
215cc73adaaSBarry Smith               PetscCheck(n + end - start - 1 < nmax, PETSC_COMM_SELF, PETSC_ERR_USER, "Error in %" PetscInt_FMT "-th array entry, not enough space in left in array (%" PetscInt_FMT ") to contain entire range from %" PetscInt_FMT " to %" PetscInt_FMT, n, nmax - n, start, end);
216e26ddf31SBarry Smith               for (; start < end; start++) {
2179371c9d4SSatish Balay                 *dvalue = start;
2189371c9d4SSatish Balay                 dvalue++;
2199371c9d4SSatish Balay                 n++;
220e26ddf31SBarry Smith               }
221e26ddf31SBarry Smith               foundrange = PETSC_TRUE;
222e26ddf31SBarry Smith               break;
223e26ddf31SBarry Smith             }
224e26ddf31SBarry Smith           }
225e26ddf31SBarry Smith           if (!foundrange) {
2269566063dSJacob Faibussowitsch             PetscCall(PetscOptionsStringToInt(value, dvalue));
227e26ddf31SBarry Smith             dvalue++;
228e26ddf31SBarry Smith             n++;
229e26ddf31SBarry Smith           }
2309566063dSJacob Faibussowitsch           PetscCall(PetscTokenFind(token, &value));
231e26ddf31SBarry Smith         }
2329566063dSJacob Faibussowitsch         PetscCall(PetscTokenDestroy(&token));
233e26ddf31SBarry Smith       }
234e26ddf31SBarry Smith       break;
235e26ddf31SBarry Smith     case OPTION_REAL_ARRAY:
2369566063dSJacob Faibussowitsch       PetscCall(PetscPrintf(PETSC_COMM_WORLD, "-%s%s <", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1));
237e26ddf31SBarry Smith       valr = (PetscReal *)next->data;
238e26ddf31SBarry Smith       for (i = 0; i < next->arraylength; i++) {
2399566063dSJacob Faibussowitsch         PetscCall(PetscPrintf(PETSC_COMM_WORLD, "%g", (double)valr[i]));
240*48a46eb9SPierre Jolivet         if (i < next->arraylength - 1) PetscCall(PetscPrintf(PETSC_COMM_WORLD, ","));
241e26ddf31SBarry Smith       }
2429566063dSJacob Faibussowitsch       PetscCall(PetscPrintf(PETSC_COMM_WORLD, ">: %s (%s) ", next->text, next->man));
2439566063dSJacob Faibussowitsch       PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str));
244e26ddf31SBarry Smith       if (str[0]) {
245e26ddf31SBarry Smith         PetscToken token;
246e26ddf31SBarry Smith         PetscInt   n = 0, nmax = next->arraylength;
247e26ddf31SBarry Smith         PetscReal *dvalue = (PetscReal *)next->data;
248e26ddf31SBarry Smith         char      *value;
249e26ddf31SBarry Smith 
250e26ddf31SBarry Smith         next->set = PETSC_TRUE;
251e26ddf31SBarry Smith         value     = str;
2529566063dSJacob Faibussowitsch         PetscCall(PetscTokenCreate(value, ',', &token));
2539566063dSJacob Faibussowitsch         PetscCall(PetscTokenFind(token, &value));
254e26ddf31SBarry Smith         while (n < nmax) {
255e26ddf31SBarry Smith           if (!value) break;
2569566063dSJacob Faibussowitsch           PetscCall(PetscOptionsStringToReal(value, dvalue));
257e26ddf31SBarry Smith           dvalue++;
258e26ddf31SBarry Smith           n++;
2599566063dSJacob Faibussowitsch           PetscCall(PetscTokenFind(token, &value));
260e26ddf31SBarry Smith         }
2619566063dSJacob Faibussowitsch         PetscCall(PetscTokenDestroy(&token));
262e26ddf31SBarry Smith       }
263e26ddf31SBarry Smith       break;
2646356e834SBarry Smith     case OPTION_INT:
2659566063dSJacob Faibussowitsch       PetscCall(PetscPrintf(PETSC_COMM_WORLD, "-%s%s <%d>: %s (%s) ", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1, *(int *)next->data, next->text, next->man));
2669566063dSJacob Faibussowitsch       PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str));
2673fc1eb6aSBarry Smith       if (str[0]) {
268d25d7f95SJed Brown #if defined(PETSC_SIZEOF_LONG_LONG)
269d25d7f95SJed Brown         long long lid;
270d25d7f95SJed Brown         sscanf(str, "%lld", &lid);
271cc73adaaSBarry Smith         PetscCheck(lid <= PETSC_MAX_INT && lid >= PETSC_MIN_INT, PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE, "Argument: -%s%s %lld", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1, lid);
272c272547aSJed Brown #else
273d25d7f95SJed Brown         long lid;
274d25d7f95SJed Brown         sscanf(str, "%ld", &lid);
275cc73adaaSBarry Smith         PetscCheck(lid <= PETSC_MAX_INT && lid >= PETSC_MIN_INT, PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE, "Argument: -%s%s %ld", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1, lid);
276c272547aSJed Brown #endif
277a297a907SKarl Rupp 
278d25d7f95SJed Brown         next->set                 = PETSC_TRUE;
279d25d7f95SJed Brown         *((PetscInt *)next->data) = (PetscInt)lid;
280aee2cecaSBarry Smith       }
281aee2cecaSBarry Smith       break;
282aee2cecaSBarry Smith     case OPTION_REAL:
2839566063dSJacob Faibussowitsch       PetscCall(PetscPrintf(PETSC_COMM_WORLD, "-%s%s <%g>: %s (%s) ", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1, *(double *)next->data, next->text, next->man));
2849566063dSJacob Faibussowitsch       PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str));
2853fc1eb6aSBarry Smith       if (str[0]) {
286ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE)
287a4404d99SBarry Smith         sscanf(str, "%e", &ir);
288570b7f6dSBarry Smith #elif defined(PETSC_USE_REAL___FP16)
289570b7f6dSBarry Smith         float irtemp;
290570b7f6dSBarry Smith         sscanf(str, "%e", &irtemp);
291570b7f6dSBarry Smith         ir = irtemp;
292ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE)
293aee2cecaSBarry Smith         sscanf(str, "%le", &ir);
294ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL___FLOAT128)
295d9822059SBarry Smith         ir = strtoflt128(str, 0);
296d9822059SBarry Smith #else
297513dbe71SLisandro Dalcin         SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, "Unknown scalar type");
298a4404d99SBarry Smith #endif
299aee2cecaSBarry Smith         next->set                  = PETSC_TRUE;
300aee2cecaSBarry Smith         *((PetscReal *)next->data) = ir;
301aee2cecaSBarry Smith       }
302aee2cecaSBarry Smith       break;
3037781c08eSBarry Smith     case OPTION_BOOL:
3049566063dSJacob Faibussowitsch       PetscCall(PetscPrintf(PETSC_COMM_WORLD, "-%s%s <%s>: %s (%s) ", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1, *(PetscBool *)next->data ? "true" : "false", next->text, next->man));
3059566063dSJacob Faibussowitsch       PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str));
3067781c08eSBarry Smith       if (str[0]) {
3079566063dSJacob Faibussowitsch         PetscCall(PetscOptionsStringToBool(str, &bid));
3087781c08eSBarry Smith         next->set                  = PETSC_TRUE;
3097781c08eSBarry Smith         *((PetscBool *)next->data) = bid;
3107781c08eSBarry Smith       }
3117781c08eSBarry Smith       break;
312aee2cecaSBarry Smith     case OPTION_STRING:
3139566063dSJacob Faibussowitsch       PetscCall(PetscPrintf(PETSC_COMM_WORLD, "-%s%s <%s>: %s (%s) ", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", next->option + 1, (char *)next->data, next->text, next->man));
3149566063dSJacob Faibussowitsch       PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str));
3153fc1eb6aSBarry Smith       if (str[0]) {
316aee2cecaSBarry Smith         next->set = PETSC_TRUE;
31764facd6cSBarry Smith         /* must use system malloc since SAWs may free this */
3189566063dSJacob Faibussowitsch         PetscCall(PetscStrdup(str, (char **)&next->data));
3196356e834SBarry Smith       }
3206356e834SBarry Smith       break;
321a264d7a6SBarry Smith     case OPTION_FLIST:
3229566063dSJacob Faibussowitsch       PetscCall(PetscFunctionListPrintTypes(PETSC_COMM_WORLD, stdout, PetscOptionsObject->prefix, next->option, next->text, next->man, next->flist, (char *)next->data, (char *)next->data));
3239566063dSJacob Faibussowitsch       PetscCall(PetscScanString(PETSC_COMM_WORLD, 512, str));
3243cc1e11dSBarry Smith       if (str[0]) {
325e55864a3SBarry Smith         PetscOptionsObject->changedmethod = PETSC_TRUE;
3263cc1e11dSBarry Smith         next->set                         = PETSC_TRUE;
32764facd6cSBarry Smith         /* must use system malloc since SAWs may free this */
3289566063dSJacob Faibussowitsch         PetscCall(PetscStrdup(str, (char **)&next->data));
3293cc1e11dSBarry Smith       }
3303cc1e11dSBarry Smith       break;
3319371c9d4SSatish Balay     default: break;
3326356e834SBarry Smith     }
3336356e834SBarry Smith     next = next->next;
3346356e834SBarry Smith   }
3356356e834SBarry Smith   PetscFunctionReturn(0);
3366356e834SBarry Smith }
3376356e834SBarry Smith 
338e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS)
339e04113cfSBarry Smith #include <petscviewersaws.h>
340d5649816SBarry Smith 
341d5649816SBarry Smith static int count = 0;
342d5649816SBarry Smith 
3439371c9d4SSatish Balay PetscErrorCode PetscOptionsSAWsDestroy(void) {
3442657e9d9SBarry Smith   PetscFunctionBegin;
345d5649816SBarry Smith   PetscFunctionReturn(0);
346d5649816SBarry Smith }
347d5649816SBarry Smith 
3489c1e0ce8SBarry Smith static const char *OptionsHeader = "<head>\n"
349a8d69d7bSBarry Smith                                    "<script type=\"text/javascript\" src=\"https://www.mcs.anl.gov/research/projects/saws/js/jquery-1.9.1.js\"></script>\n"
350a8d69d7bSBarry Smith                                    "<script type=\"text/javascript\" src=\"https://www.mcs.anl.gov/research/projects/saws/js/SAWs.js\"></script>\n"
351d1fc0251SBarry Smith                                    "<script type=\"text/javascript\" src=\"js/PETSc.js\"></script>\n"
35264bbc9efSBarry Smith                                    "<script>\n"
35364bbc9efSBarry Smith                                    "jQuery(document).ready(function() {\n"
35464bbc9efSBarry Smith                                    "PETSc.getAndDisplayDirectory(null,\"#variablesInfo\")\n"
35564bbc9efSBarry Smith                                    "})\n"
35664bbc9efSBarry Smith                                    "</script>\n"
35764bbc9efSBarry Smith                                    "</head>\n";
3581423471aSBarry Smith 
3591423471aSBarry Smith /*  Determines the size and style of the scroll region where PETSc options selectable from users are displayed */
3601423471aSBarry Smith static const char *OptionsBodyBottom = "<div id=\"variablesInfo\" style=\"background-color:lightblue;height:auto;max-height:500px;overflow:scroll;\"></div>\n<br>\n</body>";
36164bbc9efSBarry Smith 
362b3506946SBarry Smith /*
3637781c08eSBarry Smith     PetscOptionsSAWsInput - Presents all the PETSc Options processed by the program so the user may change them at runtime using the SAWs
364b3506946SBarry Smith 
365b3506946SBarry Smith     Bugs:
366b3506946SBarry Smith +    All processes must traverse through the exact same set of option queries do to the call to PetscScanString()
367b3506946SBarry Smith .    Internal strings have arbitrary length and string copies are not checked that they fit into string space
368b3506946SBarry Smith -    Only works for PetscInt == int, PetscReal == double etc
369b3506946SBarry Smith 
370b3506946SBarry Smith */
3719371c9d4SSatish Balay PetscErrorCode PetscOptionsSAWsInput(PetscOptionItems *PetscOptionsObject) {
3724416b707SBarry Smith   PetscOptionItem next     = PetscOptionsObject->next;
373d5649816SBarry Smith   static int      mancount = 0;
374b3506946SBarry Smith   char            options[16];
3757aab2a10SBarry Smith   PetscBool       changedmethod = PETSC_FALSE;
376a23eb982SSurtai Han   PetscBool       stopasking    = PETSC_FALSE;
37788a9752cSBarry Smith   char            manname[16], textname[16];
3782657e9d9SBarry Smith   char            dir[1024];
379b3506946SBarry Smith 
3802a409bb0SBarry Smith   PetscFunctionBegin;
381b3506946SBarry Smith   /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */
382b3506946SBarry Smith   sprintf(options, "Options_%d", count++);
383a297a907SKarl Rupp 
3847325c4a4SBarry Smith   PetscOptionsObject->pprefix = PetscOptionsObject->prefix; /* SAWs will change this, so cannot pass prefix directly */
3851bc75a8dSBarry Smith 
3869566063dSJacob Faibussowitsch   PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", "_title"));
387792fecdfSBarry Smith   PetscCallSAWs(SAWs_Register, (dir, &PetscOptionsObject->title, 1, SAWs_READ, SAWs_STRING));
3889566063dSJacob Faibussowitsch   PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", "prefix"));
389792fecdfSBarry Smith   PetscCallSAWs(SAWs_Register, (dir, &PetscOptionsObject->pprefix, 1, SAWs_READ, SAWs_STRING));
390792fecdfSBarry Smith   PetscCallSAWs(SAWs_Register, ("/PETSc/Options/ChangedMethod", &changedmethod, 1, SAWs_WRITE, SAWs_BOOLEAN));
391792fecdfSBarry Smith   PetscCallSAWs(SAWs_Register, ("/PETSc/Options/StopAsking", &stopasking, 1, SAWs_WRITE, SAWs_BOOLEAN));
392b3506946SBarry Smith 
393b3506946SBarry Smith   while (next) {
394d50831c4SBarry Smith     sprintf(manname, "_man_%d", mancount);
3959566063dSJacob Faibussowitsch     PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", manname));
396792fecdfSBarry Smith     PetscCallSAWs(SAWs_Register, (dir, &next->man, 1, SAWs_READ, SAWs_STRING));
397d50831c4SBarry Smith     sprintf(textname, "_text_%d", mancount++);
3989566063dSJacob Faibussowitsch     PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", textname));
399792fecdfSBarry Smith     PetscCallSAWs(SAWs_Register, (dir, &next->text, 1, SAWs_READ, SAWs_STRING));
4009f32e415SBarry Smith 
401b3506946SBarry Smith     switch (next->type) {
4029371c9d4SSatish Balay     case OPTION_HEAD: break;
403b3506946SBarry Smith     case OPTION_INT_ARRAY:
4049566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
405792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, next->data, next->arraylength, SAWs_WRITE, SAWs_INT));
406b3506946SBarry Smith       break;
407b3506946SBarry Smith     case OPTION_REAL_ARRAY:
4089566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
409792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, next->data, next->arraylength, SAWs_WRITE, SAWs_DOUBLE));
410b3506946SBarry Smith       break;
411b3506946SBarry Smith     case OPTION_INT:
4129566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
413792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, next->data, 1, SAWs_WRITE, SAWs_INT));
414b3506946SBarry Smith       break;
415b3506946SBarry Smith     case OPTION_REAL:
4169566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
417792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, next->data, 1, SAWs_WRITE, SAWs_DOUBLE));
418b3506946SBarry Smith       break;
4197781c08eSBarry Smith     case OPTION_BOOL:
4209566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
421792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, next->data, 1, SAWs_WRITE, SAWs_BOOLEAN));
4221ae3d29cSBarry Smith       break;
4237781c08eSBarry Smith     case OPTION_BOOL_ARRAY:
4249566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
425792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, next->data, next->arraylength, SAWs_WRITE, SAWs_BOOLEAN));
42671f08665SBarry Smith       break;
427b3506946SBarry Smith     case OPTION_STRING:
4289566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
429792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, &next->data, 1, SAWs_WRITE, SAWs_STRING));
4301ae3d29cSBarry Smith       break;
4311ae3d29cSBarry Smith     case OPTION_STRING_ARRAY:
4329566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
433792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, next->data, next->arraylength, SAWs_WRITE, SAWs_STRING));
434b3506946SBarry Smith       break;
4359371c9d4SSatish Balay     case OPTION_FLIST: {
436a264d7a6SBarry Smith       PetscInt ntext;
4379566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
438792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, &next->data, 1, SAWs_WRITE, SAWs_STRING));
4399566063dSJacob Faibussowitsch       PetscCall(PetscFunctionListGet(next->flist, (const char ***)&next->edata, &ntext));
440792fecdfSBarry Smith       PetscCallSAWs(SAWs_Set_Legal_Variable_Values, (dir, ntext, next->edata));
4419371c9d4SSatish Balay     } break;
4429371c9d4SSatish Balay     case OPTION_ELIST: {
443a264d7a6SBarry Smith       PetscInt ntext = next->nlist;
4449566063dSJacob Faibussowitsch       PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
445792fecdfSBarry Smith       PetscCallSAWs(SAWs_Register, (dir, &next->data, 1, SAWs_WRITE, SAWs_STRING));
4469566063dSJacob Faibussowitsch       PetscCall(PetscMalloc1((ntext + 1), (char ***)&next->edata));
4479566063dSJacob Faibussowitsch       PetscCall(PetscMemcpy(next->edata, next->list, ntext * sizeof(char *)));
448792fecdfSBarry Smith       PetscCallSAWs(SAWs_Set_Legal_Variable_Values, (dir, ntext, next->edata));
4499371c9d4SSatish Balay     } break;
4509371c9d4SSatish Balay     default: break;
451b3506946SBarry Smith     }
452b3506946SBarry Smith     next = next->next;
453b3506946SBarry Smith   }
454b3506946SBarry Smith 
455b3506946SBarry Smith   /* wait until accessor has unlocked the memory */
456792fecdfSBarry Smith   PetscCallSAWs(SAWs_Push_Header, ("index.html", OptionsHeader));
457792fecdfSBarry Smith   PetscCallSAWs(SAWs_Push_Body, ("index.html", 2, OptionsBodyBottom));
4589566063dSJacob Faibussowitsch   PetscCall(PetscSAWsBlock());
459792fecdfSBarry Smith   PetscCallSAWs(SAWs_Pop_Header, ("index.html"));
460792fecdfSBarry Smith   PetscCallSAWs(SAWs_Pop_Body, ("index.html", 2));
461b3506946SBarry Smith 
46288a9752cSBarry Smith   /* determine if any values have been set in GUI */
46383355fc5SBarry Smith   next = PetscOptionsObject->next;
46488a9752cSBarry Smith   while (next) {
4659566063dSJacob Faibussowitsch     PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Options/%s", next->option));
466792fecdfSBarry Smith     PetscCallSAWs(SAWs_Selected, (dir, (int *)&next->set));
46788a9752cSBarry Smith     next = next->next;
46888a9752cSBarry Smith   }
46988a9752cSBarry Smith 
470b3506946SBarry Smith   /* reset counter to -2; this updates the screen with the new options for the selected method */
471f7b25cf6SBarry Smith   if (changedmethod) PetscOptionsObject->count = -2;
472b3506946SBarry Smith 
473a23eb982SSurtai Han   if (stopasking) {
474a23eb982SSurtai Han     PetscOptionsPublish       = PETSC_FALSE;
47512655325SBarry Smith     PetscOptionsObject->count = 0; //do not ask for same thing again
476a23eb982SSurtai Han   }
477a23eb982SSurtai Han 
478792fecdfSBarry Smith   PetscCallSAWs(SAWs_Delete, ("/PETSc/Options"));
479b3506946SBarry Smith   PetscFunctionReturn(0);
480b3506946SBarry Smith }
481b3506946SBarry Smith #endif
482b3506946SBarry Smith 
4839371c9d4SSatish Balay PetscErrorCode PetscOptionsEnd_Private(PetscOptionItems *PetscOptionsObject) {
4844416b707SBarry Smith   PetscOptionItem last;
4856356e834SBarry Smith   char            option[256], value[1024], tmp[32];
486330cf3c9SBarry Smith   size_t          j;
48753acd3b1SBarry Smith 
48853acd3b1SBarry Smith   PetscFunctionBegin;
48983355fc5SBarry Smith   if (PetscOptionsObject->next) {
49083355fc5SBarry Smith     if (!PetscOptionsObject->count) {
491a264d7a6SBarry Smith #if defined(PETSC_HAVE_SAWS)
4929566063dSJacob Faibussowitsch       PetscCall(PetscOptionsSAWsInput(PetscOptionsObject));
493b3506946SBarry Smith #else
4949566063dSJacob Faibussowitsch       PetscCall(PetscOptionsGetFromTextInput(PetscOptionsObject));
495b3506946SBarry Smith #endif
496aee2cecaSBarry Smith     }
497aee2cecaSBarry Smith   }
4986356e834SBarry Smith 
4999566063dSJacob Faibussowitsch   PetscCall(PetscFree(PetscOptionsObject->title));
5006356e834SBarry Smith 
501e26ddf31SBarry Smith   /* reset counter to -2; this updates the screen with the new options for the selected method */
502e55864a3SBarry Smith   if (PetscOptionsObject->changedmethod) PetscOptionsObject->count = -2;
5037a72a596SBarry Smith   /* reset alreadyprinted flag */
504e55864a3SBarry Smith   PetscOptionsObject->alreadyprinted = PETSC_FALSE;
505e55864a3SBarry Smith   if (PetscOptionsObject->object) PetscOptionsObject->object->optionsprinted = PETSC_TRUE;
506e55864a3SBarry Smith   PetscOptionsObject->object = NULL;
50753acd3b1SBarry Smith 
508e55864a3SBarry Smith   while (PetscOptionsObject->next) {
509e55864a3SBarry Smith     if (PetscOptionsObject->next->set) {
510e55864a3SBarry Smith       if (PetscOptionsObject->prefix) {
5119566063dSJacob Faibussowitsch         PetscCall(PetscStrcpy(option, "-"));
5129566063dSJacob Faibussowitsch         PetscCall(PetscStrcat(option, PetscOptionsObject->prefix));
5139566063dSJacob Faibussowitsch         PetscCall(PetscStrcat(option, PetscOptionsObject->next->option + 1));
5149566063dSJacob Faibussowitsch       } else PetscCall(PetscStrcpy(option, PetscOptionsObject->next->option));
5156356e834SBarry Smith 
516e55864a3SBarry Smith       switch (PetscOptionsObject->next->type) {
5179371c9d4SSatish Balay       case OPTION_HEAD: break;
5186356e834SBarry Smith       case OPTION_INT_ARRAY:
519e55864a3SBarry Smith         sprintf(value, "%d", (int)((PetscInt *)PetscOptionsObject->next->data)[0]);
520e55864a3SBarry Smith         for (j = 1; j < PetscOptionsObject->next->arraylength; j++) {
521e55864a3SBarry Smith           sprintf(tmp, "%d", (int)((PetscInt *)PetscOptionsObject->next->data)[j]);
5229566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, ","));
5239566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, tmp));
5246356e834SBarry Smith         }
5256356e834SBarry Smith         break;
5269371c9d4SSatish Balay       case OPTION_INT: sprintf(value, "%d", (int)*(PetscInt *)PetscOptionsObject->next->data); break;
5279371c9d4SSatish Balay       case OPTION_REAL: sprintf(value, "%g", (double)*(PetscReal *)PetscOptionsObject->next->data); break;
5286356e834SBarry Smith       case OPTION_REAL_ARRAY:
529e55864a3SBarry Smith         sprintf(value, "%g", (double)((PetscReal *)PetscOptionsObject->next->data)[0]);
530e55864a3SBarry Smith         for (j = 1; j < PetscOptionsObject->next->arraylength; j++) {
531e55864a3SBarry Smith           sprintf(tmp, "%g", (double)((PetscReal *)PetscOptionsObject->next->data)[j]);
5329566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, ","));
5339566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, tmp));
5346356e834SBarry Smith         }
5356356e834SBarry Smith         break;
536050cccc3SHong Zhang       case OPTION_SCALAR_ARRAY:
53795f3a755SJose E. Roman         sprintf(value, "%g+%gi", (double)PetscRealPart(((PetscScalar *)PetscOptionsObject->next->data)[0]), (double)PetscImaginaryPart(((PetscScalar *)PetscOptionsObject->next->data)[0]));
538050cccc3SHong Zhang         for (j = 1; j < PetscOptionsObject->next->arraylength; j++) {
53995f3a755SJose E. Roman           sprintf(tmp, "%g+%gi", (double)PetscRealPart(((PetscScalar *)PetscOptionsObject->next->data)[j]), (double)PetscImaginaryPart(((PetscScalar *)PetscOptionsObject->next->data)[j]));
5409566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, ","));
5419566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, tmp));
542050cccc3SHong Zhang         }
543050cccc3SHong Zhang         break;
5449371c9d4SSatish Balay       case OPTION_BOOL: sprintf(value, "%d", *(int *)PetscOptionsObject->next->data); break;
5457781c08eSBarry Smith       case OPTION_BOOL_ARRAY:
546e55864a3SBarry Smith         sprintf(value, "%d", (int)((PetscBool *)PetscOptionsObject->next->data)[0]);
547e55864a3SBarry Smith         for (j = 1; j < PetscOptionsObject->next->arraylength; j++) {
548e55864a3SBarry Smith           sprintf(tmp, "%d", (int)((PetscBool *)PetscOptionsObject->next->data)[j]);
5499566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, ","));
5509566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, tmp));
5511ae3d29cSBarry Smith         }
5521ae3d29cSBarry Smith         break;
5539371c9d4SSatish Balay       case OPTION_FLIST: PetscCall(PetscStrcpy(value, (char *)PetscOptionsObject->next->data)); break;
5549371c9d4SSatish Balay       case OPTION_ELIST: PetscCall(PetscStrcpy(value, (char *)PetscOptionsObject->next->data)); break;
5559371c9d4SSatish Balay       case OPTION_STRING: PetscCall(PetscStrcpy(value, (char *)PetscOptionsObject->next->data)); break;
5561ae3d29cSBarry Smith       case OPTION_STRING_ARRAY:
557e55864a3SBarry Smith         sprintf(value, "%s", ((char **)PetscOptionsObject->next->data)[0]);
558e55864a3SBarry Smith         for (j = 1; j < PetscOptionsObject->next->arraylength; j++) {
559e55864a3SBarry Smith           sprintf(tmp, "%s", ((char **)PetscOptionsObject->next->data)[j]);
5609566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, ","));
5619566063dSJacob Faibussowitsch           PetscCall(PetscStrcat(value, tmp));
5621ae3d29cSBarry Smith         }
5636356e834SBarry Smith         break;
5646356e834SBarry Smith       }
5659566063dSJacob Faibussowitsch       PetscCall(PetscOptionsSetValue(PetscOptionsObject->options, option, value));
5666356e834SBarry Smith     }
567*48a46eb9SPierre Jolivet     if (PetscOptionsObject->next->type == OPTION_ELIST) PetscCall(PetscStrNArrayDestroy(PetscOptionsObject->next->nlist, (char ***)&PetscOptionsObject->next->list));
5689566063dSJacob Faibussowitsch     PetscCall(PetscFree(PetscOptionsObject->next->text));
5699566063dSJacob Faibussowitsch     PetscCall(PetscFree(PetscOptionsObject->next->option));
5709566063dSJacob Faibussowitsch     PetscCall(PetscFree(PetscOptionsObject->next->man));
5719566063dSJacob Faibussowitsch     PetscCall(PetscFree(PetscOptionsObject->next->edata));
572c979a496SBarry Smith 
57383355fc5SBarry Smith     if ((PetscOptionsObject->next->type == OPTION_STRING) || (PetscOptionsObject->next->type == OPTION_FLIST) || (PetscOptionsObject->next->type == OPTION_ELIST)) {
57483355fc5SBarry Smith       free(PetscOptionsObject->next->data);
575c979a496SBarry Smith     } else {
5769566063dSJacob Faibussowitsch       PetscCall(PetscFree(PetscOptionsObject->next->data));
577c979a496SBarry Smith     }
5787781c08eSBarry Smith 
57983355fc5SBarry Smith     last                     = PetscOptionsObject->next;
58083355fc5SBarry Smith     PetscOptionsObject->next = PetscOptionsObject->next->next;
5819566063dSJacob Faibussowitsch     PetscCall(PetscFree(last));
5826356e834SBarry Smith   }
5839566063dSJacob Faibussowitsch   PetscCall(PetscFree(PetscOptionsObject->prefix));
58402c9f0b5SLisandro Dalcin   PetscOptionsObject->next = NULL;
58553acd3b1SBarry Smith   PetscFunctionReturn(0);
58653acd3b1SBarry Smith }
58753acd3b1SBarry Smith 
58888aa4217SBarry Smith /*MC
58953acd3b1SBarry Smith    PetscOptionsEnum - Gets the enum value for a particular option in the database.
59053acd3b1SBarry Smith 
5913f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
59253acd3b1SBarry Smith 
59388aa4217SBarry Smith    Synopsis:
59488aa4217SBarry Smith    #include "petscsys.h"
5953a89f35bSSatish Balay    PetscErrorCode  PetscOptionsEnum(const char opt[],const char text[],const char man[],const char *const *list,PetscEnum currentvalue,PetscEnum *value,PetscBool  *set)
59688aa4217SBarry Smith 
59753acd3b1SBarry Smith    Input Parameters:
59853acd3b1SBarry Smith +  opt - option name
59953acd3b1SBarry Smith .  text - short string that describes the option
60053acd3b1SBarry Smith .  man - manual page with additional information on option
60153acd3b1SBarry Smith .  list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null
6020fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
6030fdccdaeSBarry Smith $                 PetscOptionsEnum(..., obj->value,&object->value,...) or
6040fdccdaeSBarry Smith $                 value = defaultvalue
6050fdccdaeSBarry Smith $                 PetscOptionsEnum(..., value,&value,&flg);
6060fdccdaeSBarry Smith $                 if (flg) {
60753acd3b1SBarry Smith 
608d8d19677SJose E. Roman    Output Parameters:
60953acd3b1SBarry Smith +  value - the  value to return
610b32e0204SMatthew G Knepley -  set - PETSC_TRUE if found, else PETSC_FALSE
61153acd3b1SBarry Smith 
61253acd3b1SBarry Smith    Level: beginner
61353acd3b1SBarry Smith 
61495452b02SPatrick Sanan    Notes:
61595452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
61653acd3b1SBarry Smith 
61753acd3b1SBarry Smith           list is usually something like PCASMTypes or some other predefined list of enum names
61853acd3b1SBarry Smith 
6192efd9cb1SBarry Smith           If the user does not supply the option at all value is NOT changed. Thus
6202efd9cb1SBarry Smith           you should ALWAYS initialize value if you access it without first checking if the set flag is true.
6212efd9cb1SBarry Smith 
622989712b9SBarry Smith           The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
623989712b9SBarry Smith 
624db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
625db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
626db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
627db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
628c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
629db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
630db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
63188aa4217SBarry Smith M*/
63288aa4217SBarry Smith 
6339371c9d4SSatish Balay PetscErrorCode PetscOptionsEnum_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], const char *const *list, PetscEnum currentvalue, PetscEnum *value, PetscBool *set) {
63453acd3b1SBarry Smith   PetscInt  ntext = 0;
635aa5bb8c0SSatish Balay   PetscInt  tval;
636ace3abfcSBarry Smith   PetscBool tflg;
63753acd3b1SBarry Smith 
63853acd3b1SBarry Smith   PetscFunctionBegin;
6399371c9d4SSatish Balay   while (list[ntext++]) { PetscCheck(ntext <= 50, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "List argument appears to be wrong or have more than 50 entries"); }
64008401ef6SPierre Jolivet   PetscCheck(ntext >= 3, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "List argument must have at least two entries: typename and type prefix");
64153acd3b1SBarry Smith   ntext -= 3;
6429566063dSJacob Faibussowitsch   PetscCall(PetscOptionsEList_Private(PetscOptionsObject, opt, text, man, list, ntext, list[currentvalue], &tval, &tflg));
643aa5bb8c0SSatish Balay   /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */
644aa5bb8c0SSatish Balay   if (tflg) *value = (PetscEnum)tval;
645aa5bb8c0SSatish Balay   if (set) *set = tflg;
64653acd3b1SBarry Smith   PetscFunctionReturn(0);
64753acd3b1SBarry Smith }
64853acd3b1SBarry Smith 
64988aa4217SBarry Smith /*MC
650d3e47460SLisandro Dalcin    PetscOptionsEnumArray - Gets an array of enum values for a particular
651d3e47460SLisandro Dalcin    option in the database.
652d3e47460SLisandro Dalcin 
653d3e47460SLisandro Dalcin    Logically Collective on the communicator passed in PetscOptionsBegin()
654d3e47460SLisandro Dalcin 
65588aa4217SBarry Smith    Synopsis:
65688aa4217SBarry Smith    #include "petscsys.h"
6573a89f35bSSatish Balay    PetscErrorCode  PetscOptionsEnumArray(const char opt[],const char text[],const char man[],const char *const *list,PetscEnum value[],PetscInt *n,PetscBool  *set)
65888aa4217SBarry Smith 
659d3e47460SLisandro Dalcin    Input Parameters:
660d3e47460SLisandro Dalcin +  opt - the option one is seeking
661d3e47460SLisandro Dalcin .  text - short string describing option
662d3e47460SLisandro Dalcin .  man - manual page for option
66322d58ec6SMatthew G. Knepley .  list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null
664c89788bdSBarry Smith -  n - maximum number of values allowed in the value array
665d3e47460SLisandro Dalcin 
666d8d19677SJose E. Roman    Output Parameters:
667d3e47460SLisandro Dalcin +  value - location to copy values
668d3e47460SLisandro Dalcin .  n - actual number of values found
669d3e47460SLisandro Dalcin -  set - PETSC_TRUE if found, else PETSC_FALSE
670d3e47460SLisandro Dalcin 
671d3e47460SLisandro Dalcin    Level: beginner
672d3e47460SLisandro Dalcin 
673d3e47460SLisandro Dalcin    Notes:
674d3e47460SLisandro Dalcin    The array must be passed as a comma separated list.
675d3e47460SLisandro Dalcin 
676d3e47460SLisandro Dalcin    There must be no intervening spaces between the values.
677d3e47460SLisandro Dalcin 
678d3e47460SLisandro Dalcin    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
679d3e47460SLisandro Dalcin 
680db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
681db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
682db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
683c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
684db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
685db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`, `PetscOptionsRealArray()`
68688aa4217SBarry Smith M*/
68788aa4217SBarry Smith 
6889371c9d4SSatish Balay PetscErrorCode PetscOptionsEnumArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], const char *const *list, PetscEnum value[], PetscInt *n, PetscBool *set) {
689d3e47460SLisandro Dalcin   PetscInt        i, nlist = 0;
6904416b707SBarry Smith   PetscOptionItem amsopt;
691d3e47460SLisandro Dalcin 
692d3e47460SLisandro Dalcin   PetscFunctionBegin;
69308401ef6SPierre Jolivet   while (list[nlist++]) PetscCheck(nlist <= 50, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "List argument appears to be wrong or have more than 50 entries");
69408401ef6SPierre Jolivet   PetscCheck(nlist >= 3, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "List argument must have at least two entries: typename and type prefix");
695d3e47460SLisandro Dalcin   nlist -= 3;                            /* drop enum name, prefix, and null termination */
696d3e47460SLisandro Dalcin   if (0 && !PetscOptionsObject->count) { /* XXX Requires additional support */
697d3e47460SLisandro Dalcin     PetscEnum *vals;
6989566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_INT_ARRAY /*XXX OPTION_ENUM_ARRAY*/, &amsopt));
6999566063dSJacob Faibussowitsch     PetscCall(PetscStrNArrayallocpy(nlist, list, (char ***)&amsopt->list));
700d3e47460SLisandro Dalcin     amsopt->nlist = nlist;
7019566063dSJacob Faibussowitsch     PetscCall(PetscMalloc1(*n, (PetscEnum **)&amsopt->data));
702d3e47460SLisandro Dalcin     amsopt->arraylength = *n;
703d3e47460SLisandro Dalcin     vals                = (PetscEnum *)amsopt->data;
704d3e47460SLisandro Dalcin     for (i = 0; i < *n; i++) vals[i] = value[i];
705d3e47460SLisandro Dalcin   }
7069566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetEnumArray(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, list, value, n, set));
707d3e47460SLisandro Dalcin   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
7089566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%s", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, list[value[0]]));
7099566063dSJacob Faibussowitsch     for (i = 1; i < *n; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ",%s", list[value[i]]));
7109566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ">: %s (choose from)", text));
7119566063dSJacob Faibussowitsch     for (i = 0; i < nlist; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, " %s", list[i]));
7129566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, " (%s)\n", ManSection(man)));
713d3e47460SLisandro Dalcin   }
714d3e47460SLisandro Dalcin   PetscFunctionReturn(0);
715d3e47460SLisandro Dalcin }
716d3e47460SLisandro Dalcin 
71788aa4217SBarry Smith /*MC
7185a856986SBarry Smith    PetscOptionsBoundedInt - Gets an integer value greater than or equal a given bound for a particular option in the database.
7195a856986SBarry Smith 
7205a856986SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
7215a856986SBarry Smith 
72288aa4217SBarry Smith    Synopsis:
72388aa4217SBarry Smith    #include "petscsys.h"
7243a89f35bSSatish Balay    PetscErrorCode  PetscOptionsBoundInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg,PetscInt bound)
72588aa4217SBarry Smith 
7265a856986SBarry Smith    Input Parameters:
7275a856986SBarry Smith +  opt - option name
7285a856986SBarry Smith .  text - short string that describes the option
7295a856986SBarry Smith .  man - manual page with additional information on option
7305a856986SBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
73188aa4217SBarry Smith $                 PetscOptionsInt(..., obj->value,&obj->value,...) or
7325a856986SBarry Smith $                 value = defaultvalue
7335a856986SBarry Smith $                 PetscOptionsInt(..., value,&value,&flg);
7345a856986SBarry Smith $                 if (flg) {
73588aa4217SBarry Smith -  bound - the requested value should be greater than or equal this bound or an error is generated
7365a856986SBarry Smith 
737d8d19677SJose E. Roman    Output Parameters:
7385a856986SBarry Smith +  value - the integer value to return
7395a856986SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
7405a856986SBarry Smith 
7415a856986SBarry Smith    Notes:
7425a856986SBarry Smith     If the user does not supply the option at all value is NOT changed. Thus
7435a856986SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
7445a856986SBarry Smith 
7455a856986SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
7465a856986SBarry Smith 
7475a856986SBarry Smith     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
7485a856986SBarry Smith 
7495a856986SBarry Smith    Level: beginner
7505a856986SBarry Smith 
751db781477SPatrick Sanan .seealso: `PetscOptionsInt()`, `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
752db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`, `PetscOptionsRangeInt()`
753db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
754db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
755c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
756db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
757db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
75888aa4217SBarry Smith M*/
7595a856986SBarry Smith 
76088aa4217SBarry Smith /*MC
7615a856986SBarry Smith    PetscOptionsRangeInt - Gets an integer value within a range of values for a particular option in the database.
7625a856986SBarry Smith 
7635a856986SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
7645a856986SBarry Smith 
76588aa4217SBarry Smith    Synopsis:
76688aa4217SBarry Smith    #include "petscsys.h"
7673a89f35bSSatish Balay PetscErrorCode  PetscOptionsRangeInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg,PetscInt lb,PetscInt ub)
76888aa4217SBarry Smith 
7695a856986SBarry Smith    Input Parameters:
7705a856986SBarry Smith +  opt - option name
7715a856986SBarry Smith .  text - short string that describes the option
7725a856986SBarry Smith .  man - manual page with additional information on option
7735a856986SBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
77488aa4217SBarry Smith $                 PetscOptionsInt(..., obj->value,&obj->value,...) or
7755a856986SBarry Smith $                 value = defaultvalue
7765a856986SBarry Smith $                 PetscOptionsInt(..., value,&value,&flg);
7775a856986SBarry Smith $                 if (flg) {
77888aa4217SBarry Smith .  lb - the lower bound, provided value must be greater than or equal to this value or an error is generated
77988aa4217SBarry Smith -  ub - the upper bound, provided value must be less than or equal to this value or an error is generated
7805a856986SBarry Smith 
781d8d19677SJose E. Roman    Output Parameters:
7825a856986SBarry Smith +  value - the integer value to return
7835a856986SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
7845a856986SBarry Smith 
7855a856986SBarry Smith    Notes:
7865a856986SBarry Smith     If the user does not supply the option at all value is NOT changed. Thus
7875a856986SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
7885a856986SBarry Smith 
7895a856986SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
7905a856986SBarry Smith 
7915a856986SBarry Smith     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
7925a856986SBarry Smith 
7935a856986SBarry Smith    Level: beginner
7945a856986SBarry Smith 
795db781477SPatrick Sanan .seealso: `PetscOptionsInt()`, `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
796db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`, `PetscOptionsBoundedInt()`
797db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
798db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
799c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
800db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
801db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
80288aa4217SBarry Smith M*/
8035a856986SBarry Smith 
80488aa4217SBarry Smith /*MC
80553acd3b1SBarry Smith    PetscOptionsInt - Gets the integer value for a particular option in the database.
80653acd3b1SBarry Smith 
8073f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
80853acd3b1SBarry Smith 
80988aa4217SBarry Smith    Synopsis:
81088aa4217SBarry Smith    #include "petscsys.h"
8116eeb591dSVaclav Hapla PetscErrorCode  PetscOptionsInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg))
81288aa4217SBarry Smith 
81353acd3b1SBarry Smith    Input Parameters:
81453acd3b1SBarry Smith +  opt - option name
81553acd3b1SBarry Smith .  text - short string that describes the option
81653acd3b1SBarry Smith .  man - manual page with additional information on option
8170fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
81888aa4217SBarry Smith $                 PetscOptionsInt(..., obj->value,&obj->value,...) or
8190fdccdaeSBarry Smith $                 value = defaultvalue
8200fdccdaeSBarry Smith $                 PetscOptionsInt(..., value,&value,&flg);
8210fdccdaeSBarry Smith $                 if (flg) {
82253acd3b1SBarry Smith 
823d8d19677SJose E. Roman    Output Parameters:
82453acd3b1SBarry Smith +  value - the integer value to return
82553acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
82653acd3b1SBarry Smith 
82795452b02SPatrick Sanan    Notes:
82895452b02SPatrick Sanan     If the user does not supply the option at all value is NOT changed. Thus
8292efd9cb1SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
8302efd9cb1SBarry Smith 
831989712b9SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
832989712b9SBarry Smith 
83395452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
83453acd3b1SBarry Smith 
8355a856986SBarry Smith    Level: beginner
8365a856986SBarry Smith 
837db781477SPatrick Sanan .seealso: `PetscOptionsBoundedInt()`, `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
838db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`, `PetscOptionsRangeInt()`
839db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
840db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
841c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
842db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
843db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
84488aa4217SBarry Smith M*/
84588aa4217SBarry Smith 
8469371c9d4SSatish Balay PetscErrorCode PetscOptionsInt_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscInt currentvalue, PetscInt *value, PetscBool *set, PetscInt lb, PetscInt ub) {
8474416b707SBarry Smith   PetscOptionItem amsopt;
84812655325SBarry Smith   PetscBool       wasset;
84953acd3b1SBarry Smith 
85053acd3b1SBarry Smith   PetscFunctionBegin;
85108401ef6SPierre Jolivet   PetscCheck(currentvalue >= lb, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Current value %" PetscInt_FMT " less than allowed bound %" PetscInt_FMT, currentvalue, lb);
85208401ef6SPierre Jolivet   PetscCheck(currentvalue <= ub, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Current value %" PetscInt_FMT " greater than allowed bound %" PetscInt_FMT, currentvalue, ub);
853e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
8549566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_INT, &amsopt));
8559566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscInt), &amsopt->data));
85612655325SBarry Smith     *(PetscInt *)amsopt->data = currentvalue;
8573e211508SBarry Smith 
8589566063dSJacob Faibussowitsch     PetscCall(PetscOptionsGetInt(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, &currentvalue, &wasset));
8599371c9d4SSatish Balay     if (wasset) { *(PetscInt *)amsopt->data = currentvalue; }
860af6d86caSBarry Smith   }
8619566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetInt(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, &wasset));
862cc73adaaSBarry Smith   PetscCheck(!wasset || *value >= lb, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Newly set value %" PetscInt_FMT " less than allowed bound %" PetscInt_FMT, *value, lb);
863cc73adaaSBarry Smith   PetscCheck(!wasset || *value <= ub, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Newly set value %" PetscInt_FMT " greater than allowed bound %" PetscInt_FMT, *value, ub);
86444ef3d73SBarry Smith   if (set) *set = wasset;
865e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
8669566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <now %" PetscInt_FMT " : formerly %" PetscInt_FMT ">: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, wasset && value ? *value : currentvalue, currentvalue, text, ManSection(man)));
86753acd3b1SBarry Smith   }
86853acd3b1SBarry Smith   PetscFunctionReturn(0);
86953acd3b1SBarry Smith }
87053acd3b1SBarry Smith 
87188aa4217SBarry Smith /*MC
87253acd3b1SBarry Smith    PetscOptionsString - Gets the string value for a particular option in the database.
87353acd3b1SBarry Smith 
8743f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
87553acd3b1SBarry Smith 
87688aa4217SBarry Smith    Synopsis:
87788aa4217SBarry Smith    #include "petscsys.h"
8783a89f35bSSatish Balay    PetscErrorCode  PetscOptionsString(const char opt[],const char text[],const char man[],const char currentvalue[],char value[],size_t len,PetscBool  *set)
87988aa4217SBarry Smith 
88053acd3b1SBarry Smith    Input Parameters:
88153acd3b1SBarry Smith +  opt - option name
88253acd3b1SBarry Smith .  text - short string that describes the option
88353acd3b1SBarry Smith .  man - manual page with additional information on option
8840fdccdaeSBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. This is not used to set value
885bcbf2dc5SJed Brown -  len - length of the result string including null terminator
88653acd3b1SBarry Smith 
887d8d19677SJose E. Roman    Output Parameters:
88853acd3b1SBarry Smith +  value - the value to return
88953acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
89053acd3b1SBarry Smith 
89153acd3b1SBarry Smith    Level: beginner
89253acd3b1SBarry Smith 
89395452b02SPatrick Sanan    Notes:
89495452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
89553acd3b1SBarry Smith 
8967fccdfe4SBarry Smith    Even if the user provided no string (for example -optionname -someotheroption) the flag is set to PETSC_TRUE (and the string is fulled with nulls).
8977fccdfe4SBarry Smith 
8982efd9cb1SBarry Smith           If the user does not supply the option at all value is NOT changed. Thus
8992efd9cb1SBarry Smith           you should ALWAYS initialize value if you access it without first checking if the set flag is true.
9002efd9cb1SBarry Smith 
901989712b9SBarry Smith           The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
902989712b9SBarry Smith 
903db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
904db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
905db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
906db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
907c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
908db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
909db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
91088aa4217SBarry Smith M*/
91188aa4217SBarry Smith 
9129371c9d4SSatish Balay PetscErrorCode PetscOptionsString_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], const char currentvalue[], char value[], size_t len, PetscBool *set) {
9134416b707SBarry Smith   PetscOptionItem amsopt;
91444ef3d73SBarry Smith   PetscBool       lset;
91553acd3b1SBarry Smith 
91653acd3b1SBarry Smith   PetscFunctionBegin;
9171a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
9189566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_STRING, &amsopt));
91964facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
9209566063dSJacob Faibussowitsch     PetscCall(PetscStrdup(currentvalue ? currentvalue : "", (char **)&amsopt->data));
921af6d86caSBarry Smith   }
9229566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetString(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, len, &lset));
92344ef3d73SBarry Smith   if (set) *set = lset;
924e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
9259566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <now %s : formerly %s>: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, lset && value ? value : currentvalue, currentvalue, text, ManSection(man)));
92653acd3b1SBarry Smith   }
92753acd3b1SBarry Smith   PetscFunctionReturn(0);
92853acd3b1SBarry Smith }
92953acd3b1SBarry Smith 
93088aa4217SBarry Smith /*MC
93153acd3b1SBarry Smith    PetscOptionsReal - Gets the PetscReal value for a particular option in the database.
93253acd3b1SBarry Smith 
9333f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
93453acd3b1SBarry Smith 
93588aa4217SBarry Smith    Synopsis:
93688aa4217SBarry Smith    #include "petscsys.h"
9373a89f35bSSatish Balay    PetscErrorCode  PetscOptionsReal(const char opt[],const char text[],const char man[],PetscReal currentvalue,PetscReal *value,PetscBool  *set)
93888aa4217SBarry Smith 
93953acd3b1SBarry Smith    Input Parameters:
94053acd3b1SBarry Smith +  opt - option name
94153acd3b1SBarry Smith .  text - short string that describes the option
94253acd3b1SBarry Smith .  man - manual page with additional information on option
9430fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
94488aa4217SBarry Smith $                 PetscOptionsReal(..., obj->value,&obj->value,...) or
9450fdccdaeSBarry Smith $                 value = defaultvalue
9460fdccdaeSBarry Smith $                 PetscOptionsReal(..., value,&value,&flg);
9470fdccdaeSBarry Smith $                 if (flg) {
94853acd3b1SBarry Smith 
949d8d19677SJose E. Roman    Output Parameters:
95053acd3b1SBarry Smith +  value - the value to return
95153acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
95253acd3b1SBarry Smith 
95395452b02SPatrick Sanan    Notes:
95495452b02SPatrick Sanan     If the user does not supply the option at all value is NOT changed. Thus
9552efd9cb1SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
9562efd9cb1SBarry Smith 
957989712b9SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
958989712b9SBarry Smith 
95995452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
96053acd3b1SBarry Smith 
9615a856986SBarry Smith    Level: beginner
9625a856986SBarry Smith 
963db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
964db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
965db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
966db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
967c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
968db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
969db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
97088aa4217SBarry Smith M*/
97188aa4217SBarry Smith 
9729371c9d4SSatish Balay PetscErrorCode PetscOptionsReal_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscReal currentvalue, PetscReal *value, PetscBool *set) {
9734416b707SBarry Smith   PetscOptionItem amsopt;
97444ef3d73SBarry Smith   PetscBool       lset;
97553acd3b1SBarry Smith 
97653acd3b1SBarry Smith   PetscFunctionBegin;
977e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
9789566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_REAL, &amsopt));
9799566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscReal), &amsopt->data));
980a297a907SKarl Rupp 
9810fdccdaeSBarry Smith     *(PetscReal *)amsopt->data = currentvalue;
982538aa990SBarry Smith   }
9839566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetReal(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, &lset));
98444ef3d73SBarry Smith   if (set) *set = lset;
9851a1499c8SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
9869566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%g : %g>: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, lset && value ? (double)*value : (double)currentvalue, (double)currentvalue, text, ManSection(man)));
98753acd3b1SBarry Smith   }
98853acd3b1SBarry Smith   PetscFunctionReturn(0);
98953acd3b1SBarry Smith }
99053acd3b1SBarry Smith 
99188aa4217SBarry Smith /*MC
99253acd3b1SBarry Smith    PetscOptionsScalar - Gets the scalar value for a particular option in the database.
99353acd3b1SBarry Smith 
9943f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
99553acd3b1SBarry Smith 
99688aa4217SBarry Smith    Synopsis:
99788aa4217SBarry Smith    #include "petscsys.h"
9983a89f35bSSatish Balay    PetscErrorCode PetscOptionsScalar(const char opt[],const char text[],const char man[],PetscScalar currentvalue,PetscScalar *value,PetscBool  *set)
99988aa4217SBarry Smith 
100053acd3b1SBarry Smith    Input Parameters:
100153acd3b1SBarry Smith +  opt - option name
100253acd3b1SBarry Smith .  text - short string that describes the option
100353acd3b1SBarry Smith .  man - manual page with additional information on option
10040fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
100588aa4217SBarry Smith $                 PetscOptionsScalar(..., obj->value,&obj->value,...) or
10060fdccdaeSBarry Smith $                 value = defaultvalue
10070fdccdaeSBarry Smith $                 PetscOptionsScalar(..., value,&value,&flg);
10080fdccdaeSBarry Smith $                 if (flg) {
10090fdccdaeSBarry Smith 
1010d8d19677SJose E. Roman    Output Parameters:
101153acd3b1SBarry Smith +  value - the value to return
101253acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
101353acd3b1SBarry Smith 
101495452b02SPatrick Sanan    Notes:
101595452b02SPatrick Sanan     If the user does not supply the option at all value is NOT changed. Thus
10162efd9cb1SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
10172efd9cb1SBarry Smith 
1018989712b9SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
1019989712b9SBarry Smith 
102095452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
102153acd3b1SBarry Smith 
10225a856986SBarry Smith    Level: beginner
10235a856986SBarry Smith 
1024db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
1025db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
1026db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
1027db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1028c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1029db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1030db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
103188aa4217SBarry Smith M*/
103288aa4217SBarry Smith 
10339371c9d4SSatish Balay PetscErrorCode PetscOptionsScalar_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscScalar currentvalue, PetscScalar *value, PetscBool *set) {
103453acd3b1SBarry Smith   PetscFunctionBegin;
103553acd3b1SBarry Smith #if !defined(PETSC_USE_COMPLEX)
10369566063dSJacob Faibussowitsch   PetscCall(PetscOptionsReal(opt, text, man, currentvalue, value, set));
103753acd3b1SBarry Smith #else
10389566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetScalar(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, set));
103953acd3b1SBarry Smith #endif
104053acd3b1SBarry Smith   PetscFunctionReturn(0);
104153acd3b1SBarry Smith }
104253acd3b1SBarry Smith 
104388aa4217SBarry Smith /*MC
104490d69ab7SBarry Smith    PetscOptionsName - Determines if a particular option has been set in the database. This returns true whether the option is a number, string or boolean, even
104590d69ab7SBarry Smith                       its value is set to false.
104653acd3b1SBarry Smith 
10473f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
104853acd3b1SBarry Smith 
104988aa4217SBarry Smith    Synopsis:
105088aa4217SBarry Smith    #include "petscsys.h"
10513a89f35bSSatish Balay    PetscErrorCode PetscOptionsName(const char opt[],const char text[],const char man[],PetscBool  *flg)
105288aa4217SBarry Smith 
105353acd3b1SBarry Smith    Input Parameters:
105453acd3b1SBarry Smith +  opt - option name
105553acd3b1SBarry Smith .  text - short string that describes the option
105653acd3b1SBarry Smith -  man - manual page with additional information on option
105753acd3b1SBarry Smith 
105853acd3b1SBarry Smith    Output Parameter:
105953acd3b1SBarry Smith .  flg - PETSC_TRUE if found, else PETSC_FALSE
106053acd3b1SBarry Smith 
106153acd3b1SBarry Smith    Level: beginner
106253acd3b1SBarry Smith 
106395452b02SPatrick Sanan    Notes:
106495452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
106553acd3b1SBarry Smith 
1066db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
1067db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
1068db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
1069db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1070c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1071db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1072db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
107388aa4217SBarry Smith M*/
107488aa4217SBarry Smith 
10759371c9d4SSatish Balay PetscErrorCode PetscOptionsName_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool *flg) {
10764416b707SBarry Smith   PetscOptionItem amsopt;
107753acd3b1SBarry Smith 
107853acd3b1SBarry Smith   PetscFunctionBegin;
1079e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
10809566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt));
10819566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data));
1082a297a907SKarl Rupp 
1083ace3abfcSBarry Smith     *(PetscBool *)amsopt->data = PETSC_FALSE;
10841ae3d29cSBarry Smith   }
10859566063dSJacob Faibussowitsch   PetscCall(PetscOptionsHasName(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, flg));
1086e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
10879566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, text, ManSection(man)));
108853acd3b1SBarry Smith   }
108953acd3b1SBarry Smith   PetscFunctionReturn(0);
109053acd3b1SBarry Smith }
109153acd3b1SBarry Smith 
109288aa4217SBarry Smith /*MC
1093a264d7a6SBarry Smith      PetscOptionsFList - Puts a list of option values that a single one may be selected from
109453acd3b1SBarry Smith 
10953f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
109653acd3b1SBarry Smith 
109788aa4217SBarry Smith    Synopsis:
109888aa4217SBarry Smith    #include "petscsys.h"
10993a89f35bSSatish Balay    PetscErrorCode  PetscOptionsFList(const char opt[],const char ltext[],const char man[],PetscFunctionList list,const char currentvalue[],char value[],size_t len,PetscBool  *set)
110088aa4217SBarry Smith 
110153acd3b1SBarry Smith    Input Parameters:
110253acd3b1SBarry Smith +  opt - option name
110353acd3b1SBarry Smith .  text - short string that describes the option
110453acd3b1SBarry Smith .  man - manual page with additional information on option
110553acd3b1SBarry Smith .  list - the possible choices
11060fdccdaeSBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with
11070fdccdaeSBarry Smith $                 PetscOptionsFlist(..., obj->value,value,len,&flg);
11080fdccdaeSBarry Smith $                 if (flg) {
11093cc1e11dSBarry Smith -  len - the length of the character array value
111053acd3b1SBarry Smith 
1111d8d19677SJose E. Roman    Output Parameters:
111253acd3b1SBarry Smith +  value - the value to return
111353acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
111453acd3b1SBarry Smith 
111553acd3b1SBarry Smith    Level: intermediate
111653acd3b1SBarry Smith 
111795452b02SPatrick Sanan    Notes:
111895452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
111953acd3b1SBarry Smith 
11202efd9cb1SBarry Smith           If the user does not supply the option at all value is NOT changed. Thus
11212efd9cb1SBarry Smith           you should ALWAYS initialize value if you access it without first checking if the set flag is true.
11222efd9cb1SBarry Smith 
1123989712b9SBarry Smith           The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
1124989712b9SBarry Smith 
112553acd3b1SBarry Smith    See PetscOptionsEList() for when the choices are given in a string array
112653acd3b1SBarry Smith 
112753acd3b1SBarry Smith    To get a listing of all currently specified options,
112888c29154SBarry Smith     see PetscOptionsView() or PetscOptionsGetAll()
112953acd3b1SBarry Smith 
1130eabe10d7SBarry Smith    Developer Note: This cannot check for invalid selection because of things like MATAIJ that are not included in the list
1131eabe10d7SBarry Smith 
1132db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1133db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1134db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1135c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1136db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1137db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`, `PetscOptionsEnum()`
113888aa4217SBarry Smith M*/
113988aa4217SBarry Smith 
11409371c9d4SSatish Balay PetscErrorCode PetscOptionsFList_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char ltext[], const char man[], PetscFunctionList list, const char currentvalue[], char value[], size_t len, PetscBool *set) {
11414416b707SBarry Smith   PetscOptionItem amsopt;
114244ef3d73SBarry Smith   PetscBool       lset;
114353acd3b1SBarry Smith 
114453acd3b1SBarry Smith   PetscFunctionBegin;
11451a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
11469566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, ltext, man, OPTION_FLIST, &amsopt));
114764facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
11489566063dSJacob Faibussowitsch     PetscCall(PetscStrdup(currentvalue ? currentvalue : "", (char **)&amsopt->data));
11493cc1e11dSBarry Smith     amsopt->flist = list;
11503cc1e11dSBarry Smith   }
11519566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetString(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, len, &lset));
115244ef3d73SBarry Smith   if (set) *set = lset;
11531a1499c8SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
11549566063dSJacob Faibussowitsch     PetscCall(PetscFunctionListPrintTypes(PetscOptionsObject->comm, stdout, PetscOptionsObject->prefix, opt, ltext, man, list, currentvalue, lset && value ? value : currentvalue));
115553acd3b1SBarry Smith   }
115653acd3b1SBarry Smith   PetscFunctionReturn(0);
115753acd3b1SBarry Smith }
115853acd3b1SBarry Smith 
115988aa4217SBarry Smith /*MC
116053acd3b1SBarry Smith      PetscOptionsEList - Puts a list of option values that a single one may be selected from
116153acd3b1SBarry Smith 
11623f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
116353acd3b1SBarry Smith 
116488aa4217SBarry Smith    Synopsis:
116588aa4217SBarry Smith    #include "petscsys.h"
11663a89f35bSSatish 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)
116788aa4217SBarry Smith 
116853acd3b1SBarry Smith    Input Parameters:
116953acd3b1SBarry Smith +  opt - option name
117053acd3b1SBarry Smith .  ltext - short string that describes the option
117153acd3b1SBarry Smith .  man - manual page with additional information on option
1172a264d7a6SBarry Smith .  list - the possible choices (one of these must be selected, anything else is invalid)
117353acd3b1SBarry Smith .  ntext - number of choices
11740fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with
11750fdccdaeSBarry Smith $                 PetscOptionsElist(..., obj->value,&value,&flg);
11760fdccdaeSBarry Smith $                 if (flg) {
11770fdccdaeSBarry Smith 
1178d8d19677SJose E. Roman    Output Parameters:
117953acd3b1SBarry Smith +  value - the index of the value to return
118053acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
118153acd3b1SBarry Smith 
118253acd3b1SBarry Smith    Level: intermediate
118353acd3b1SBarry Smith 
118495452b02SPatrick Sanan    Notes:
118595452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
118653acd3b1SBarry Smith 
11872efd9cb1SBarry Smith          If the user does not supply the option at all value is NOT changed. Thus
11882efd9cb1SBarry Smith           you should ALWAYS initialize value if you access it without first checking if the set flag is true.
11892efd9cb1SBarry Smith 
1190a264d7a6SBarry Smith    See PetscOptionsFList() for when the choices are given in a PetscFunctionList()
119153acd3b1SBarry Smith 
1192db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1193db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1194db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1195c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1196db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1197db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEnum()`
119888aa4217SBarry Smith M*/
119988aa4217SBarry Smith 
12009371c9d4SSatish Balay PetscErrorCode PetscOptionsEList_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char ltext[], const char man[], const char *const *list, PetscInt ntext, const char currentvalue[], PetscInt *value, PetscBool *set) {
120153acd3b1SBarry Smith   PetscInt        i;
12024416b707SBarry Smith   PetscOptionItem amsopt;
120344ef3d73SBarry Smith   PetscBool       lset;
120453acd3b1SBarry Smith 
120553acd3b1SBarry Smith   PetscFunctionBegin;
12061a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
12079566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, ltext, man, OPTION_ELIST, &amsopt));
120864facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
12099566063dSJacob Faibussowitsch     PetscCall(PetscStrdup(currentvalue ? currentvalue : "", (char **)&amsopt->data));
12109566063dSJacob Faibussowitsch     PetscCall(PetscStrNArrayallocpy(ntext, list, (char ***)&amsopt->list));
12111ae3d29cSBarry Smith     amsopt->nlist = ntext;
12121ae3d29cSBarry Smith   }
12139566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetEList(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, list, ntext, value, &lset));
121444ef3d73SBarry Smith   if (set) *set = lset;
12151a1499c8SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
12169566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <now %s : formerly %s> %s (choose one of)", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, lset && value ? list[*value] : currentvalue, currentvalue, ltext));
1217*48a46eb9SPierre Jolivet     for (i = 0; i < ntext; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, " %s", list[i]));
12189566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, " (%s)\n", ManSection(man)));
121953acd3b1SBarry Smith   }
122053acd3b1SBarry Smith   PetscFunctionReturn(0);
122153acd3b1SBarry Smith }
122253acd3b1SBarry Smith 
122388aa4217SBarry Smith /*MC
1224acfcf0e5SJed Brown      PetscOptionsBoolGroupBegin - First in a series of logical queries on the options database for
1225d5649816SBarry Smith        which at most a single value can be true.
122653acd3b1SBarry Smith 
12273f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
122853acd3b1SBarry Smith 
122988aa4217SBarry Smith    Synopsis:
123088aa4217SBarry Smith    #include "petscsys.h"
12313a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolGroupBegin(const char opt[],const char text[],const char man[],PetscBool  *flg)
123288aa4217SBarry Smith 
123353acd3b1SBarry Smith    Input Parameters:
123453acd3b1SBarry Smith +  opt - option name
123553acd3b1SBarry Smith .  text - short string that describes the option
123653acd3b1SBarry Smith -  man - manual page with additional information on option
123753acd3b1SBarry Smith 
123853acd3b1SBarry Smith    Output Parameter:
123953acd3b1SBarry Smith .  flg - whether that option was set or not
124053acd3b1SBarry Smith 
124153acd3b1SBarry Smith    Level: intermediate
124253acd3b1SBarry Smith 
124395452b02SPatrick Sanan    Notes:
124495452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
124553acd3b1SBarry Smith 
1246acfcf0e5SJed Brown    Must be followed by 0 or more PetscOptionsBoolGroup()s and PetscOptionsBoolGroupEnd()
124753acd3b1SBarry Smith 
1248db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1249db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1250db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1251c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1252db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1253db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
125488aa4217SBarry Smith M*/
125588aa4217SBarry Smith 
12569371c9d4SSatish Balay PetscErrorCode PetscOptionsBoolGroupBegin_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool *flg) {
12574416b707SBarry Smith   PetscOptionItem amsopt;
125853acd3b1SBarry Smith 
125953acd3b1SBarry Smith   PetscFunctionBegin;
1260e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
12619566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt));
12629566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data));
1263a297a907SKarl Rupp 
1264ace3abfcSBarry Smith     *(PetscBool *)amsopt->data = PETSC_FALSE;
12651ae3d29cSBarry Smith   }
126668b16fdaSBarry Smith   *flg = PETSC_FALSE;
12679566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetBool(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, flg, NULL));
1268e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
12699566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  Pick at most one of -------------\n"));
12709566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "    -%s%s: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, text, ManSection(man)));
127153acd3b1SBarry Smith   }
127253acd3b1SBarry Smith   PetscFunctionReturn(0);
127353acd3b1SBarry Smith }
127453acd3b1SBarry Smith 
127588aa4217SBarry Smith /*MC
1276acfcf0e5SJed Brown      PetscOptionsBoolGroup - One in a series of logical queries on the options database for
1277d5649816SBarry Smith        which at most a single value can be true.
127853acd3b1SBarry Smith 
12793f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
128053acd3b1SBarry Smith 
128188aa4217SBarry Smith    Synopsis:
128288aa4217SBarry Smith    #include "petscsys.h"
12833a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolGroup(const char opt[],const char text[],const char man[],PetscBool  *flg)
128488aa4217SBarry Smith 
128553acd3b1SBarry Smith    Input Parameters:
128653acd3b1SBarry Smith +  opt - option name
128753acd3b1SBarry Smith .  text - short string that describes the option
128853acd3b1SBarry Smith -  man - manual page with additional information on option
128953acd3b1SBarry Smith 
129053acd3b1SBarry Smith    Output Parameter:
129153acd3b1SBarry Smith .  flg - PETSC_TRUE if found, else PETSC_FALSE
129253acd3b1SBarry Smith 
129353acd3b1SBarry Smith    Level: intermediate
129453acd3b1SBarry Smith 
129595452b02SPatrick Sanan    Notes:
129695452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
129753acd3b1SBarry Smith 
1298acfcf0e5SJed Brown    Must follow a PetscOptionsBoolGroupBegin() and preceded a PetscOptionsBoolGroupEnd()
129953acd3b1SBarry Smith 
1300db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1301db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1302db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1303c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1304db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1305db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
130688aa4217SBarry Smith M*/
130788aa4217SBarry Smith 
13089371c9d4SSatish Balay PetscErrorCode PetscOptionsBoolGroup_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool *flg) {
13094416b707SBarry Smith   PetscOptionItem amsopt;
131053acd3b1SBarry Smith 
131153acd3b1SBarry Smith   PetscFunctionBegin;
1312e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
13139566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt));
13149566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data));
1315a297a907SKarl Rupp 
1316ace3abfcSBarry Smith     *(PetscBool *)amsopt->data = PETSC_FALSE;
13171ae3d29cSBarry Smith   }
131817326d04SJed Brown   *flg = PETSC_FALSE;
13199566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetBool(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, flg, NULL));
1320e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
13219566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "    -%s%s: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, text, ManSection(man)));
132253acd3b1SBarry Smith   }
132353acd3b1SBarry Smith   PetscFunctionReturn(0);
132453acd3b1SBarry Smith }
132553acd3b1SBarry Smith 
132688aa4217SBarry Smith /*MC
1327acfcf0e5SJed Brown      PetscOptionsBoolGroupEnd - Last in a series of logical queries on the options database for
1328d5649816SBarry Smith        which at most a single value can be true.
132953acd3b1SBarry Smith 
13303f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
133153acd3b1SBarry Smith 
133288aa4217SBarry Smith    Synopsis:
133388aa4217SBarry Smith    #include "petscsys.h"
13343a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolGroupEnd(const char opt[],const char text[],const char man[],PetscBool  *flg)
133588aa4217SBarry Smith 
133653acd3b1SBarry Smith    Input Parameters:
133753acd3b1SBarry Smith +  opt - option name
133853acd3b1SBarry Smith .  text - short string that describes the option
133953acd3b1SBarry Smith -  man - manual page with additional information on option
134053acd3b1SBarry Smith 
134153acd3b1SBarry Smith    Output Parameter:
134253acd3b1SBarry Smith .  flg - PETSC_TRUE if found, else PETSC_FALSE
134353acd3b1SBarry Smith 
134453acd3b1SBarry Smith    Level: intermediate
134553acd3b1SBarry Smith 
134695452b02SPatrick Sanan    Notes:
134795452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
134853acd3b1SBarry Smith 
1349acfcf0e5SJed Brown    Must follow a PetscOptionsBoolGroupBegin()
135053acd3b1SBarry Smith 
1351db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1352db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1353db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1354c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1355db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1356db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
135788aa4217SBarry Smith M*/
135888aa4217SBarry Smith 
13599371c9d4SSatish Balay PetscErrorCode PetscOptionsBoolGroupEnd_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool *flg) {
13604416b707SBarry Smith   PetscOptionItem amsopt;
136153acd3b1SBarry Smith 
136253acd3b1SBarry Smith   PetscFunctionBegin;
1363e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
13649566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt));
13659566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data));
1366a297a907SKarl Rupp 
1367ace3abfcSBarry Smith     *(PetscBool *)amsopt->data = PETSC_FALSE;
13681ae3d29cSBarry Smith   }
136917326d04SJed Brown   *flg = PETSC_FALSE;
13709566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetBool(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, flg, NULL));
1371e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
13729566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "    -%s%s: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, text, ManSection(man)));
137353acd3b1SBarry Smith   }
137453acd3b1SBarry Smith   PetscFunctionReturn(0);
137553acd3b1SBarry Smith }
137653acd3b1SBarry Smith 
137788aa4217SBarry Smith /*MC
1378acfcf0e5SJed Brown    PetscOptionsBool - Determines if a particular option is in the database with a true or false
137953acd3b1SBarry Smith 
13803f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
138153acd3b1SBarry Smith 
138288aa4217SBarry Smith    Synopsis:
138388aa4217SBarry Smith    #include "petscsys.h"
13843a89f35bSSatish Balay    PetscErrorCode PetscOptionsBool(const char opt[],const char text[],const char man[],PetscBool currentvalue,PetscBool  *flg,PetscBool  *set)
138588aa4217SBarry Smith 
138653acd3b1SBarry Smith    Input Parameters:
138753acd3b1SBarry Smith +  opt - option name
138853acd3b1SBarry Smith .  text - short string that describes the option
1389868c398cSBarry Smith .  man - manual page with additional information on option
139094ae4db5SBarry Smith -  currentvalue - the current value
139153acd3b1SBarry Smith 
1392d8d19677SJose E. Roman    Output Parameters:
1393a2b725a8SWilliam Gropp +  flg - PETSC_TRUE or PETSC_FALSE
1394a2b725a8SWilliam Gropp -  set - PETSC_TRUE if found, else PETSC_FALSE
139553acd3b1SBarry Smith 
13962efd9cb1SBarry Smith    Notes:
13972efd9cb1SBarry Smith        TRUE, true, YES, yes, nostring, and 1 all translate to PETSC_TRUE
13982efd9cb1SBarry Smith        FALSE, false, NO, no, and 0 all translate to PETSC_FALSE
13992efd9cb1SBarry Smith 
14002efd9cb1SBarry 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
14012efd9cb1SBarry Smith      is equivalent to -requested_bool true
14022efd9cb1SBarry Smith 
14032efd9cb1SBarry Smith        If the user does not supply the option at all flg is NOT changed. Thus
14042efd9cb1SBarry Smith      you should ALWAYS initialize the flg if you access it without first checking if the set flag is true.
14052efd9cb1SBarry Smith 
140695452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
140753acd3b1SBarry Smith 
14085a856986SBarry Smith    Level: beginner
14095a856986SBarry Smith 
1410db781477SPatrick Sanan .seealso: `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
1411db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsGetBool()`,
1412db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`,
1413db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1414c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1415db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1416db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
141788aa4217SBarry Smith M*/
141888aa4217SBarry Smith 
14199371c9d4SSatish Balay PetscErrorCode PetscOptionsBool_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool currentvalue, PetscBool *flg, PetscBool *set) {
1420ace3abfcSBarry Smith   PetscBool       iset;
14214416b707SBarry Smith   PetscOptionItem amsopt;
142253acd3b1SBarry Smith 
142353acd3b1SBarry Smith   PetscFunctionBegin;
1424e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
14259566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL, &amsopt));
14269566063dSJacob Faibussowitsch     PetscCall(PetscMalloc(sizeof(PetscBool), &amsopt->data));
1427a297a907SKarl Rupp 
142894ae4db5SBarry Smith     *(PetscBool *)amsopt->data = currentvalue;
1429af6d86caSBarry Smith   }
14309566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetBool(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, flg, &iset));
143153acd3b1SBarry Smith   if (set) *set = iset;
14321a1499c8SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
143344ef3d73SBarry Smith     const char *v = PetscBools[currentvalue], *vn = PetscBools[iset && flg ? *flg : currentvalue];
14349566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s: <%s : %s> %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, v, vn, text, ManSection(man)));
143553acd3b1SBarry Smith   }
143653acd3b1SBarry Smith   PetscFunctionReturn(0);
143753acd3b1SBarry Smith }
143853acd3b1SBarry Smith 
143988aa4217SBarry Smith /*MC
144053acd3b1SBarry Smith    PetscOptionsRealArray - Gets an array of double values for a particular
144153acd3b1SBarry Smith    option in the database. The values must be separated with commas with
144253acd3b1SBarry Smith    no intervening spaces.
144353acd3b1SBarry Smith 
14443f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
144553acd3b1SBarry Smith 
144688aa4217SBarry Smith    Synopsis:
144788aa4217SBarry Smith    #include "petscsys.h"
14483a89f35bSSatish Balay    PetscErrorCode PetscOptionsRealArray(const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscBool  *set)
144988aa4217SBarry Smith 
145053acd3b1SBarry Smith    Input Parameters:
145153acd3b1SBarry Smith +  opt - the option one is seeking
145253acd3b1SBarry Smith .  text - short string describing option
145353acd3b1SBarry Smith .  man - manual page for option
1454c89788bdSBarry Smith -  n - maximum number of values that value has room for
145553acd3b1SBarry Smith 
1456d8d19677SJose E. Roman    Output Parameters:
145753acd3b1SBarry Smith +  value - location to copy values
1458c89788bdSBarry Smith .  n - actual number of values found
145953acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
146053acd3b1SBarry Smith 
146153acd3b1SBarry Smith    Level: beginner
146253acd3b1SBarry Smith 
146353acd3b1SBarry Smith    Notes:
146453acd3b1SBarry Smith    The user should pass in an array of doubles
146553acd3b1SBarry Smith 
146653acd3b1SBarry Smith    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
146753acd3b1SBarry Smith 
1468db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1469db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1470db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1471c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1472db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1473db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
147488aa4217SBarry Smith M*/
147588aa4217SBarry Smith 
14769371c9d4SSatish Balay PetscErrorCode PetscOptionsRealArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscReal value[], PetscInt *n, PetscBool *set) {
147753acd3b1SBarry Smith   PetscInt        i;
14784416b707SBarry Smith   PetscOptionItem amsopt;
147953acd3b1SBarry Smith 
148053acd3b1SBarry Smith   PetscFunctionBegin;
1481e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1482e26ddf31SBarry Smith     PetscReal *vals;
1483e26ddf31SBarry Smith 
14849566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_REAL_ARRAY, &amsopt));
14859566063dSJacob Faibussowitsch     PetscCall(PetscMalloc((*n) * sizeof(PetscReal), &amsopt->data));
1486e26ddf31SBarry Smith     vals = (PetscReal *)amsopt->data;
1487e26ddf31SBarry Smith     for (i = 0; i < *n; i++) vals[i] = value[i];
1488e26ddf31SBarry Smith     amsopt->arraylength = *n;
1489e26ddf31SBarry Smith   }
14909566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetRealArray(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, n, set));
1491e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
14929566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%g", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, (double)value[0]));
1493*48a46eb9SPierre Jolivet     for (i = 1; i < *n; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ",%g", (double)value[i]));
14949566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ">: %s (%s)\n", text, ManSection(man)));
149553acd3b1SBarry Smith   }
149653acd3b1SBarry Smith   PetscFunctionReturn(0);
149753acd3b1SBarry Smith }
149853acd3b1SBarry Smith 
149988aa4217SBarry Smith /*MC
1500050cccc3SHong Zhang    PetscOptionsScalarArray - Gets an array of Scalar values for a particular
1501050cccc3SHong Zhang    option in the database. The values must be separated with commas with
1502050cccc3SHong Zhang    no intervening spaces.
1503050cccc3SHong Zhang 
1504050cccc3SHong Zhang    Logically Collective on the communicator passed in PetscOptionsBegin()
1505050cccc3SHong Zhang 
150688aa4217SBarry Smith    Synopsis:
150788aa4217SBarry Smith    #include "petscsys.h"
15083a89f35bSSatish Balay    PetscErrorCode PetscOptionsScalarArray(const char opt[],const char text[],const char man[],PetscScalar value[],PetscInt *n,PetscBool  *set)
150988aa4217SBarry Smith 
1510050cccc3SHong Zhang    Input Parameters:
1511050cccc3SHong Zhang +  opt - the option one is seeking
1512050cccc3SHong Zhang .  text - short string describing option
1513050cccc3SHong Zhang .  man - manual page for option
1514c89788bdSBarry Smith -  n - maximum number of values allowed in the value array
1515050cccc3SHong Zhang 
1516d8d19677SJose E. Roman    Output Parameters:
1517050cccc3SHong Zhang +  value - location to copy values
1518c89788bdSBarry Smith .  n - actual number of values found
1519050cccc3SHong Zhang -  set - PETSC_TRUE if found, else PETSC_FALSE
1520050cccc3SHong Zhang 
1521050cccc3SHong Zhang    Level: beginner
1522050cccc3SHong Zhang 
1523050cccc3SHong Zhang    Notes:
1524050cccc3SHong Zhang    The user should pass in an array of doubles
1525050cccc3SHong Zhang 
1526050cccc3SHong Zhang    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1527050cccc3SHong Zhang 
1528db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1529db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1530db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1531c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1532db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1533db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
153488aa4217SBarry Smith M*/
153588aa4217SBarry Smith 
15369371c9d4SSatish Balay PetscErrorCode PetscOptionsScalarArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscScalar value[], PetscInt *n, PetscBool *set) {
1537050cccc3SHong Zhang   PetscInt        i;
15384416b707SBarry Smith   PetscOptionItem amsopt;
1539050cccc3SHong Zhang 
1540050cccc3SHong Zhang   PetscFunctionBegin;
1541050cccc3SHong Zhang   if (!PetscOptionsObject->count) {
1542050cccc3SHong Zhang     PetscScalar *vals;
1543050cccc3SHong Zhang 
15449566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_SCALAR_ARRAY, &amsopt));
15459566063dSJacob Faibussowitsch     PetscCall(PetscMalloc((*n) * sizeof(PetscScalar), &amsopt->data));
1546050cccc3SHong Zhang     vals = (PetscScalar *)amsopt->data;
1547050cccc3SHong Zhang     for (i = 0; i < *n; i++) vals[i] = value[i];
1548050cccc3SHong Zhang     amsopt->arraylength = *n;
1549050cccc3SHong Zhang   }
15509566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetScalarArray(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, n, set));
1551050cccc3SHong Zhang   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
15529566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%g+%gi", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, (double)PetscRealPart(value[0]), (double)PetscImaginaryPart(value[0])));
1553*48a46eb9SPierre Jolivet     for (i = 1; i < *n; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ",%g+%gi", (double)PetscRealPart(value[i]), (double)PetscImaginaryPart(value[i])));
15549566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ">: %s (%s)\n", text, ManSection(man)));
1555050cccc3SHong Zhang   }
1556050cccc3SHong Zhang   PetscFunctionReturn(0);
1557050cccc3SHong Zhang }
155853acd3b1SBarry Smith 
155988aa4217SBarry Smith /*MC
156053acd3b1SBarry Smith    PetscOptionsIntArray - Gets an array of integers for a particular
1561b32a342fSShri Abhyankar    option in the database.
156253acd3b1SBarry Smith 
15633f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
156453acd3b1SBarry Smith 
156588aa4217SBarry Smith    Synopsis:
156688aa4217SBarry Smith    #include "petscsys.h"
15673a89f35bSSatish Balay    PetscErrorCode PetscOptionsIntArray(const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscBool  *set)
156888aa4217SBarry Smith 
156953acd3b1SBarry Smith    Input Parameters:
157053acd3b1SBarry Smith +  opt - the option one is seeking
157153acd3b1SBarry Smith .  text - short string describing option
157253acd3b1SBarry Smith .  man - manual page for option
1573f8a50e2bSBarry Smith -  n - maximum number of values
157453acd3b1SBarry Smith 
1575d8d19677SJose E. Roman    Output Parameters:
157653acd3b1SBarry Smith +  value - location to copy values
1577f8a50e2bSBarry Smith .  n - actual number of values found
157853acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
157953acd3b1SBarry Smith 
158053acd3b1SBarry Smith    Level: beginner
158153acd3b1SBarry Smith 
158253acd3b1SBarry Smith    Notes:
1583b32a342fSShri Abhyankar    The array can be passed as
1584bebe2cf6SSatish Balay    a comma separated list:                                 0,1,2,3,4,5,6,7
15850fd488f5SShri Abhyankar    a range (start-end+1):                                  0-8
15860fd488f5SShri Abhyankar    a range with given increment (start-end+1:inc):         0-7:2
1587bebe2cf6SSatish Balay    a combination of values and ranges separated by commas: 0,1-8,8-15:2
1588b32a342fSShri Abhyankar 
1589b32a342fSShri Abhyankar    There must be no intervening spaces between the values.
159053acd3b1SBarry Smith 
159153acd3b1SBarry Smith    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
159253acd3b1SBarry Smith 
1593db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1594db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1595db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1596c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1597db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1598db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`, `PetscOptionsRealArray()`
159988aa4217SBarry Smith M*/
160088aa4217SBarry Smith 
16019371c9d4SSatish Balay PetscErrorCode PetscOptionsIntArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscInt value[], PetscInt *n, PetscBool *set) {
160253acd3b1SBarry Smith   PetscInt        i;
16034416b707SBarry Smith   PetscOptionItem amsopt;
160453acd3b1SBarry Smith 
160553acd3b1SBarry Smith   PetscFunctionBegin;
1606e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1607e26ddf31SBarry Smith     PetscInt *vals;
1608e26ddf31SBarry Smith 
16099566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_INT_ARRAY, &amsopt));
16109566063dSJacob Faibussowitsch     PetscCall(PetscMalloc1(*n, (PetscInt **)&amsopt->data));
1611e26ddf31SBarry Smith     vals = (PetscInt *)amsopt->data;
1612e26ddf31SBarry Smith     for (i = 0; i < *n; i++) vals[i] = value[i];
1613e26ddf31SBarry Smith     amsopt->arraylength = *n;
1614e26ddf31SBarry Smith   }
16159566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetIntArray(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, n, set));
1616e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
16179566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%" PetscInt_FMT, PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, value[0]));
1618*48a46eb9SPierre Jolivet     for (i = 1; i < *n; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ",%" PetscInt_FMT, value[i]));
16199566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ">: %s (%s)\n", text, ManSection(man)));
162053acd3b1SBarry Smith   }
162153acd3b1SBarry Smith   PetscFunctionReturn(0);
162253acd3b1SBarry Smith }
162353acd3b1SBarry Smith 
162488aa4217SBarry Smith /*MC
162553acd3b1SBarry Smith    PetscOptionsStringArray - Gets an array of string values for a particular
162653acd3b1SBarry Smith    option in the database. The values must be separated with commas with
162753acd3b1SBarry Smith    no intervening spaces.
162853acd3b1SBarry Smith 
16293f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
163053acd3b1SBarry Smith 
163188aa4217SBarry Smith    Synopsis:
163288aa4217SBarry Smith    #include "petscsys.h"
16333a89f35bSSatish Balay    PetscErrorCode PetscOptionsStringArray(const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscBool  *set)
163488aa4217SBarry Smith 
163553acd3b1SBarry Smith    Input Parameters:
163653acd3b1SBarry Smith +  opt - the option one is seeking
163753acd3b1SBarry Smith .  text - short string describing option
163853acd3b1SBarry Smith .  man - manual page for option
163953acd3b1SBarry Smith -  nmax - maximum number of strings
164053acd3b1SBarry Smith 
1641d8d19677SJose E. Roman    Output Parameters:
164253acd3b1SBarry Smith +  value - location to copy strings
164353acd3b1SBarry Smith .  nmax - actual number of strings found
164453acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
164553acd3b1SBarry Smith 
164653acd3b1SBarry Smith    Level: beginner
164753acd3b1SBarry Smith 
164853acd3b1SBarry Smith    Notes:
164953acd3b1SBarry Smith    The user should pass in an array of pointers to char, to hold all the
165053acd3b1SBarry Smith    strings returned by this function.
165153acd3b1SBarry Smith 
165253acd3b1SBarry Smith    The user is responsible for deallocating the strings that are
165353acd3b1SBarry Smith    returned. The Fortran interface for this routine is not supported.
165453acd3b1SBarry Smith 
165553acd3b1SBarry Smith    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
165653acd3b1SBarry Smith 
1657db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1658db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1659db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1660c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1661db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1662db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
166388aa4217SBarry Smith M*/
166488aa4217SBarry Smith 
16659371c9d4SSatish Balay PetscErrorCode PetscOptionsStringArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], char *value[], PetscInt *nmax, PetscBool *set) {
16664416b707SBarry Smith   PetscOptionItem amsopt;
166753acd3b1SBarry Smith 
166853acd3b1SBarry Smith   PetscFunctionBegin;
1669e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
16709566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_STRING_ARRAY, &amsopt));
16719566063dSJacob Faibussowitsch     PetscCall(PetscMalloc1(*nmax, (char **)&amsopt->data));
1672a297a907SKarl Rupp 
16731ae3d29cSBarry Smith     amsopt->arraylength = *nmax;
16741ae3d29cSBarry Smith   }
16759566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetStringArray(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, nmax, set));
1676e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
16779566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <string1,string2,...>: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, text, ManSection(man)));
167853acd3b1SBarry Smith   }
167953acd3b1SBarry Smith   PetscFunctionReturn(0);
168053acd3b1SBarry Smith }
168153acd3b1SBarry Smith 
168288aa4217SBarry Smith /*MC
1683acfcf0e5SJed Brown    PetscOptionsBoolArray - Gets an array of logical values (true or false) for a particular
1684e2446a98SMatthew Knepley    option in the database. The values must be separated with commas with
1685e2446a98SMatthew Knepley    no intervening spaces.
1686e2446a98SMatthew Knepley 
16873f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
1688e2446a98SMatthew Knepley 
168988aa4217SBarry Smith    Synopsis:
169088aa4217SBarry Smith    #include "petscsys.h"
16913a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolArray(const char opt[],const char text[],const char man[],PetscBool value[],PetscInt *n,PetscBool *set)
169288aa4217SBarry Smith 
1693e2446a98SMatthew Knepley    Input Parameters:
1694e2446a98SMatthew Knepley +  opt - the option one is seeking
1695e2446a98SMatthew Knepley .  text - short string describing option
1696e2446a98SMatthew Knepley .  man - manual page for option
1697c89788bdSBarry Smith -  n - maximum number of values allowed in the value array
1698e2446a98SMatthew Knepley 
1699d8d19677SJose E. Roman    Output Parameters:
1700e2446a98SMatthew Knepley +  value - location to copy values
1701c89788bdSBarry Smith .  n - actual number of values found
1702e2446a98SMatthew Knepley -  set - PETSC_TRUE if found, else PETSC_FALSE
1703e2446a98SMatthew Knepley 
1704e2446a98SMatthew Knepley    Level: beginner
1705e2446a98SMatthew Knepley 
1706e2446a98SMatthew Knepley    Notes:
1707e2446a98SMatthew Knepley    The user should pass in an array of doubles
1708e2446a98SMatthew Knepley 
1709e2446a98SMatthew Knepley    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1710e2446a98SMatthew Knepley 
1711db781477SPatrick Sanan .seealso: `PetscOptionsGetInt()`, `PetscOptionsGetReal()`,
1712db781477SPatrick Sanan           `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`,
1713db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1714c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1715db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1716db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
171788aa4217SBarry Smith M*/
171888aa4217SBarry Smith 
17199371c9d4SSatish Balay PetscErrorCode PetscOptionsBoolArray_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscBool value[], PetscInt *n, PetscBool *set) {
1720e2446a98SMatthew Knepley   PetscInt        i;
17214416b707SBarry Smith   PetscOptionItem amsopt;
1722e2446a98SMatthew Knepley 
1723e2446a98SMatthew Knepley   PetscFunctionBegin;
1724e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1725ace3abfcSBarry Smith     PetscBool *vals;
17261ae3d29cSBarry Smith 
17279566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_BOOL_ARRAY, &amsopt));
17289566063dSJacob Faibussowitsch     PetscCall(PetscMalloc1(*n, (PetscBool **)&amsopt->data));
1729ace3abfcSBarry Smith     vals = (PetscBool *)amsopt->data;
17301ae3d29cSBarry Smith     for (i = 0; i < *n; i++) vals[i] = value[i];
17311ae3d29cSBarry Smith     amsopt->arraylength = *n;
17321ae3d29cSBarry Smith   }
17339566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetBoolArray(PetscOptionsObject->options, PetscOptionsObject->prefix, opt, value, n, set));
1734e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
17359566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%d", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, value[0]));
1736*48a46eb9SPierre Jolivet     for (i = 1; i < *n; i++) PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ",%d", value[i]));
17379566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, ">: %s (%s)\n", text, ManSection(man)));
1738e2446a98SMatthew Knepley   }
1739e2446a98SMatthew Knepley   PetscFunctionReturn(0);
1740e2446a98SMatthew Knepley }
1741e2446a98SMatthew Knepley 
174288aa4217SBarry Smith /*MC
1743d1da0b69SBarry Smith    PetscOptionsViewer - Gets a viewer appropriate for the type indicated by the user
17448cc676e6SMatthew G Knepley 
17458cc676e6SMatthew G Knepley    Logically Collective on the communicator passed in PetscOptionsBegin()
17468cc676e6SMatthew G Knepley 
174788aa4217SBarry Smith    Synopsis:
174888aa4217SBarry Smith    #include "petscsys.h"
17493a89f35bSSatish Balay    PetscErrorCode PetscOptionsViewer(const char opt[],const char text[],const char man[],PetscViewer *viewer,PetscViewerFormat *format,PetscBool *set)
175088aa4217SBarry Smith 
17518cc676e6SMatthew G Knepley    Input Parameters:
17528cc676e6SMatthew G Knepley +  opt - option name
17538cc676e6SMatthew G Knepley .  text - short string that describes the option
17548cc676e6SMatthew G Knepley -  man - manual page with additional information on option
17558cc676e6SMatthew G Knepley 
1756d8d19677SJose E. Roman    Output Parameters:
17578cc676e6SMatthew G Knepley +  viewer - the viewer
17587962402dSFande Kong .  format - the PetscViewerFormat requested by the user, pass NULL if not needed
17598cc676e6SMatthew G Knepley -  set - PETSC_TRUE if found, else PETSC_FALSE
17608cc676e6SMatthew G Knepley 
17618cc676e6SMatthew G Knepley    Level: beginner
17628cc676e6SMatthew G Knepley 
176395452b02SPatrick Sanan    Notes:
176495452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
17658cc676e6SMatthew G Knepley 
17665a7113b9SPatrick Sanan    See PetscOptionsGetViewer() for the format of the supplied viewer and its options
17678cc676e6SMatthew G Knepley 
1768db781477SPatrick Sanan .seealso: `PetscOptionsGetViewer()`, `PetscOptionsHasName()`, `PetscOptionsGetString()`, `PetscOptionsGetInt()`,
1769db781477SPatrick Sanan           `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`
1770db781477SPatrick Sanan           `PetscOptionsInt()`, `PetscOptionsString()`, `PetscOptionsReal()`, `PetscOptionsBool()`,
1771db781477SPatrick Sanan           `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`,
1772c2e3fba1SPatrick Sanan           `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`,
1773db781477SPatrick Sanan           `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`,
1774db781477SPatrick Sanan           `PetscOptionsFList()`, `PetscOptionsEList()`
177588aa4217SBarry Smith M*/
177688aa4217SBarry Smith 
17779371c9d4SSatish Balay PetscErrorCode PetscOptionsViewer_Private(PetscOptionItems *PetscOptionsObject, const char opt[], const char text[], const char man[], PetscViewer *viewer, PetscViewerFormat *format, PetscBool *set) {
17784416b707SBarry Smith   PetscOptionItem amsopt;
17798cc676e6SMatthew G Knepley 
17808cc676e6SMatthew G Knepley   PetscFunctionBegin;
17811a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
17829566063dSJacob Faibussowitsch     PetscCall(PetscOptionItemCreate_Private(PetscOptionsObject, opt, text, man, OPTION_STRING, &amsopt));
178364facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
17849566063dSJacob Faibussowitsch     PetscCall(PetscStrdup("", (char **)&amsopt->data));
17858cc676e6SMatthew G Knepley   }
17869566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetViewer(PetscOptionsObject->comm, PetscOptionsObject->options, PetscOptionsObject->prefix, opt, viewer, format, set));
1787e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
17889566063dSJacob Faibussowitsch     PetscCall((*PetscHelpPrintf)(PetscOptionsObject->comm, "  -%s%s <%s>: %s (%s)\n", PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "", opt + 1, "", text, ManSection(man)));
17898cc676e6SMatthew G Knepley   }
17908cc676e6SMatthew G Knepley   PetscFunctionReturn(0);
17918cc676e6SMatthew G Knepley }
1792