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