Alamo
ParmParse.H
Go to the documentation of this file.
1//
2// This is a thin wrapper to the amrex::ParmParse class
3// This class exists to add some additional parsing capability,
4// e.g. parsing Set::Matrix and Set::Vector data types.
5//
6// :ref:`IO::ParmParse` uses static :code:`Parse()` functions to
7// perform cascading class-based input parsing.
8// See the :ref:`autodoc` section for instructions on adding documentation.
9//
10// :bdg-warning-line:`This is standard infrastructure code; make sure you know what you ard doing before you change it.`
11//
12// .. _query-directives:
13//
14// **Query directives**
15//
16// Alamo uses different query directives to standardize reading inputs and automatic documentation.
17// The type of query that is used (query vs query_required, etc) triggers different handlers and different
18// automatic documentation procedures.
19// For instance, the use of a :code:`query_default` causes a default value to be set and added to the metadata
20// file, and it also serves as a flag for the autodoc system to document that a default value is available.
21// The following table is a reference for the different kinds of query directives.
22//
23//
24// .. table::
25// :widths: 1 99
26//
27// +---------------------------------+-----------------------------------------------------------------+
28// | BC Type | Description |
29// +=================================+=================================================================+
30// | :bdg-warning:`query` | Standard IO for bool, string, Set::Scalarthat does not enforce |
31// | | defaults or required values. Not recommended for general use. |
32// +---------------------------------+-----------------------------------------------------------------+
33// | :bdg-success:`query_required` | Similar to query, but will abort if no value is specified. |
34// | | Required values are indicated by :bdg-danger-line:`required`. |
35// +---------------------------------+-----------------------------------------------------------------+
36// | :bdg-success:`query_default` | Similar to query, but will fill with default value if no value |
37// | | is provided. Will also add default value to metadata. |
38// | | Default values are indicated by green badge values, e.g. |
39// | | :bdg-success:`0.0`. |
40// +---------------------------------+-----------------------------------------------------------------+
41// | :bdg-success:`query_validate` | For strings, read in a value and enforce that the value is one |
42// | | of a supplied number of values. Optionally make required, or |
43// | | set the default value to the first supplied value. |
44// | | Acceptable options are indicated by blue badge values, e.g. |
45// | | :bdg-primary:`1.0`, :bdg-primary:`2.0`. If a default value is |
46// | | available, it is indicated by a green badge, e.g. |
47// | | :bdg-success:`1.0`. |
48// +---------------------------------+-----------------------------------------------------------------+
49// | :bdg-success:`query_file` | Read in a string that defines a file name. |
50// | | Check to make sure that the file exists and is a regular file, |
51// | | and print an informative error message if not (this can be |
52// | | disabled). |
53// | | Also, copy the file to the output directory, with the full path |
54// | | preserved by replacing / with _. |
55// | | (This can also be disabled, but doing so is discouraged.) |
56// | | Default values are not allowed. |
57// | | File paths are indicated by :bdg-secondary-line:`file path`. |
58// +---------------------------------+-----------------------------------------------------------------+
59// | :bdg-primary:`queryarr` | Read in an array of numbers into either a standard vector or |
60// | | into a :code:`Set::Vector` or :code:`Set::Scalar`. |
61// | | No defaults or existence checking is performed. |
62// +---------------------------------+-----------------------------------------------------------------+
63// | :bdg-primary:`queryclass` | Read a class object with a specified prefix. |
64// | | How that class is read in is determined by its :code:`Parse` |
65// | | function. |
66// +---------------------------------+-----------------------------------------------------------------+
67//
68// .. _query_locator_macros:
69//
70// **Query macros**
71//
72// A set of preprocessor macros are defined so that you can call a query function using :code:`pp_` instead
73// of :code:`pp.`.
74// For instance, the following two can be used interchangeably:
75//
76// .. code-block:: cpp
77//
78// pp.query_required("myvar",myvar); /* function version */
79// pp_query_required("myvar",myvar); /* preprocessor macro version - preferred*/
80//
81// Using the preprocessor macros enables code location information to be passed to the parser, so that
82// more informative error messages will be printed out.
83// Note that **the ParmParse object must always be called** :code:`pp` **for this to work**.
84//
85//
86
87#ifndef IO_PARMPARSE
88#define IO_PARMPARSE
89
90#include <filesystem>
91#include <exception>
92#include <list>
93
94#include "Util/Util.H"
95#include "Set/Set.H"
96#include "AMReX_ParmParse.H"
97
98
99#define pp_query_required(...) pp.query_required(__VA_ARGS__,INFO)
100#define pp_query_default(...) pp.query_default(__VA_ARGS__,INFO)
101#define pp_query_validate(...) pp.query_validate(__VA_ARGS__,INFO)
102#define pp_query_file(...) pp.query_file(__VA_ARGS__,INFO)
103#define pp_queryarr(...) pp.queryarr(__VA_ARGS__,INFO)
104#define pp_queryarr_required(...) pp.queryarr_required(__VA_ARGS__,INFO)
105#define pp_queryarr_default(...) pp.queryarr_default(__VA_ARGS__,INFO)
106#define pp_query(...) pp.query(__VA_ARGS__)
107#define pp_queryclass(...) pp.queryclass(__VA_ARGS__,INFO)
108#define pp_forbid(...) pp.forbid(__VA_ARGS__,INFO)
109
110
111namespace IO
112{
113class ParmParse : public amrex::ParmParse
114{
115private:
116 void Define()
117 {
118 if (checked_for_input_files) return;
119 int k = 0;
120 std::string inputfile = "";
121 while (this->querykth("input",k,inputfile))
122 {
123 Util::Message(INFO,"Including inputs from "+inputfile);
124 this->addfile(inputfile);
125 k++;
126 }
128 }
130
131public:
132 ParmParse(std::string arg) : amrex::ParmParse::ParmParse(arg) {Define();} ;
133 ParmParse() : amrex::ParmParse::ParmParse() {Define();} ;
134 std::string getPrefix() const {return m_prefix;};
135 void ignore(std::string name)
136 {
137 (void)amrex::ParmParse::contains(name.c_str());
138 }
139
140 void forbid(std::string name, std::string explanation,
141 std::string file = "", std::string func = "", int line = -1)
142 {
143 if (amrex::ParmParse::contains(full(name).c_str()))
144 {
145 Util::ParmParseException(INFO,file,func,line,full(name),full(name)," forbidden: ", explanation);
146 }
147 std::set<std::string> subs = amrex::ParmParse::getEntries(full(name));
148 if (subs.size())
149 {
150 Util::ParmParseException(INFO,file,func,line,full(name),full(name)," forbidden: ", explanation);
151 }
152 }
153
154 bool contains(std::string name)
155 {
156 if (amrex::ParmParse::contains(name.c_str()))
157 return true;
158 if (amrex::ParmParse::contains(full(name).c_str()))
159 return true;
160 {
161 std::set<std::string> subs = amrex::ParmParse::getEntries(name.c_str());
162 if (subs.size())
163 return true;
164 }
165 {
166 std::set<std::string> subs = amrex::ParmParse::getEntries(full(name).c_str());
167 if (subs.size())
168 return true;
169 }
170 return false;
171 }
172
173 template<typename T>
174 int query_required( std::string name, T & value,
175 std::string file = "", std::string func = "", int line = -1)
176 {
177 if (!contains(name.c_str()))
178 {
179 Util::ParmParseException(INFO,file,func,line,full(name),"required value for ",full(name)," missing");
180 }
181 return query(name.c_str(),value);
182 }
183
184 template<typename T>
185 int query_default( std::string name, T & value, T defaultvalue,
186 std::string = "", std::string = "", int = -1)
187 {
188 if (!contains(name.c_str()))
189 {
190 add(name.c_str(),defaultvalue);
191 }
192 return query(name.c_str(),value);
193 }
194
195 int query_validate( std::string name, int & value, std::vector<int> possibleintvals,
196 std::string file = "", std::string func = "", int line = -1)
197 {
198 // First value is accepted by default...
199
200 // set default value
201 value = possibleintvals[0];
202
203 // get the read value (if it exists)
204 int retval = query(name.c_str(),value);
205
206 // check to make sure the read value matches one of the inpus
207 bool ok = false;
208 for (unsigned int i = 0; i < possibleintvals.size(); i++)
209 {
210 if (value == possibleintvals[i]) ok = true;
211 }
212
213 if (ok) return retval;
214
215 std::stringstream ss;
216 ss << possibleintvals[0];
217 for (unsigned int i = 1; i < possibleintvals.size(); i++)
218 ss << "," << possibleintvals[i];
219
220 Util::ParmParseException(INFO,file,func,line,full(name),"' expected [", ss.str(), "] but got ", value);
221
222 return -1;
223 }
224
225
226 int query_validate( std::string name, std::string & value, std::vector<const char *> possiblecharvals, bool firstbydefault,
227 std::string file = "", std::string func = "", int line = -1)
228 {
229 // if not using default values, then the input must be specified
230 if (!firstbydefault)
231 {
232 if (!contains(name.c_str()))
233 {
234 Util::ParmParseException(INFO,file,func,line,full(name),"required value for ",full(name)," missing");
235 }
236 }
237
238 // set default value
239 value = std::string(possiblecharvals[0]);
240
241 // get the read value (if it exists)
242 int retval = query(name.c_str(),value);
243
244 // check to make sure the read value matches one of the inpus
245 bool ok = false;
246 for (unsigned int i = 0; i < possiblecharvals.size(); i++)
247 {
248 if (value == std::string(possiblecharvals[i])) ok = true;
249 }
250
251 if (ok) return retval;
252
253 std::stringstream ss;
254 ss << possiblecharvals[0];
255 for (unsigned int i = 1; i < possiblecharvals.size(); i++)
256 ss << "," << possiblecharvals[i];
257
258 Util::ParmParseException(INFO,file,func,line,full(name),"' expected [", ss.str(), "] but got ", value);
259
260 return -1;
261 }
262
263 int query_validate( std::string name, std::string & value, std::vector<const char *> possiblecharvals,
264 std::string file = "", std::string func = "", int line = -1)
265 {
266 return query_validate(name,value,possiblecharvals,true,file,func,line);
267 }
268
269
270 // special case for strings
271 int query_default( std::string name, std::string & value, const char *defaultvalue,
272 std::string file = "", std::string func = "", int line = -1)
273 {
274 return query_default(name, value, std::string(defaultvalue), file, func, line);
275 }
276 // special case for bools
277 int query_default( std::string name, int & value, bool defaultvalue,
278 std::string file = "", std::string func = "query_default", int line = -1)
279 {
280 int defaultint = 0;
281 if (defaultvalue) defaultint = 1;
282 return query_default(name, value, defaultint, file, func, line);
283 }
284
285
286
287 // validate filenames
288 int query_file( std::string name, std::string & value, bool copyfile, bool checkfile,
289 std::string file = "", std::string func = "query_file", int line = -1)
290 {
291 try
292 {
293 if (!contains(name.c_str()))
294 {
295 Util::ParmParseException(INFO,file,func,line,full(name),full(name)," must be specified");
296 }
297
298 int retval = query(name.c_str(),value);
299
300 if (amrex::ParallelDescriptor::IOProcessor())
301 {
302 if ( checkfile && ! std::filesystem::exists(value))
303 {
304 Util::ParmParseException(INFO,file,func,line,full(name),full(name)," does not exist");
305 }
306 if ( checkfile && !std::filesystem::is_regular_file(value))
307 {
308 Util::ParmParseException(INFO,file,func,line,full(name),full(name)," is not a regular file");
309 }
310 if ( copyfile )
311 {
312 Util::CopyFileToOutputDir(value, true, full(name));
313 }
314 }
315 return retval;
316 }
317 catch (...)
318 {
319 Util::ParmParseException(INFO,file,func,line,full(name));
320 }
321 return -1;
322 }
323 int query_file( std::string name, std::string & value, bool copyfile,
324 std::string file = "", std::string func = "query_file", int line = -1)
325 {
326 return query_file(name,value,copyfile,true,file,func,line);
327 }
328 int query_file( std::string name, std::string & value,
329 std::string file = "", std::string func = "query_file", int line = -1)
330 {
331 return query_file(name,value,true,true,file,func,line);
332 }
333
334
335 template<typename T>
336 int queryarr( std::string name, std::vector<T> & value,
337 std::string /*file*/, std::string /*func*/, int /*line*/)
338 {
339 return amrex::ParmParse::queryarr(name.c_str(),value);
340 }
341 int queryarr( std::string name, Set::Vector & value,
342 std::string file = "", std::string func = "queryarr", int line = -1)
343 {
344 std::vector<Set::Scalar> vals;
345 amrex::ParmParse::queryarr(name.c_str(), vals);
346 if (vals.size() < AMREX_SPACEDIM)
347 {
348 Util::ParmParseException(INFO,file,func,line,full(name),full(name)," requires at least ", AMREX_SPACEDIM, " arguments, got ",vals.size());
349 }
350 for (int i = 0; i < AMREX_SPACEDIM; i++) value(i) = vals[i];
351 return 0;
352 }
353 int queryarr( std::string name, Set::Matrix & value,
354 std::string file = "", std::string func = "queryarr", int line = -1)
355 {
356 std::vector<Set::Scalar> vals;
357 amrex::ParmParse::queryarr(name.c_str(), vals);
358 if (vals.size() == 9)
359 {
360#if AMREX_SPACEDIM==2
361 Util::Warning(file,func,line,"Reading a 3D matrix (",full(name),")into a 2D code - some values will be ignored.");
362 value(0,0) = vals[0]; value(0,1)= vals[1];
363 value(1,0) = vals[3]; value(1,1)= vals[4];
364#endif
365#if AMREX_SPACEDIM==3
366 value(0,0) = vals[0]; value(0,1)= vals[1]; value(0,2)= vals[2];
367 value(1,0) = vals[3]; value(1,1)= vals[4]; value(1,2)= vals[5];
368 value(2,0) = vals[6]; value(2,1)= vals[7]; value(2,2)= vals[8];
369#endif
370 }
371 else if (vals.size() == 4)
372 {
373#if AMREX_SPACEDIM==2
374 value(0,0) = vals[0]; value(0,1)= vals[1];
375 value(1,0) = vals[2]; value(1,1)= vals[3];
376#endif
377#if AMREX_SPACEDIM==3
378 Util::Warning(file,func,line,"Reading a 2D matrix (",full(name),")into a 3D code - remaining values will be set to zero.");
379 value(0,0) = vals[0]; value(0,1)= vals[1]; value(0,2)= 0.0;
380 value(1,0) = vals[2]; value(1,1)= vals[3]; value(1,2)= 0.0;
381 value(2,0) = 0.0; value(2,1)= 0.0; value(2,2)= 0.0;
382#endif
383 }
384 else
385 {
386 Util::ParmParseException(INFO,file,func,line,full(name),full(name)," needs either 4 or 9 components, but got ",vals.size());
387 }
388 return 0;
389 }
390 template<typename T>
391 int queryarr_required( std::string name, std::vector<T> & value,
392 std::string file, std::string func, int line)
393 {
394 if (!contains(name.c_str()))
395 {
396 Util::ParmParseException(INFO,file,func,line,full(name),"required value for ",full(name)," missing");
397 }
398 return queryarr(name,value,file,func,line);
399 }
400
401
402 int queryarr_default( std::string name, std::vector<std::string> & value, std::string defaultvalue,
403 std::string = "", std::string = "", int = -1)
404 {
405 if (!contains(name.c_str()))
406 {
407 add(name.c_str(),defaultvalue);
408 }
409 return queryarr(name.c_str(),value);
410 }
411
412
413
414 template <typename T>
415 int
416 queryclass_enumerate(std::string a_name, std::vector<T> &value, int number = 1,
417 std::string file = "", std::string func = "", int line = __LINE__)
418 {
419 value.clear();
420
421 //
422 // If only one is present with no subscript, then read
423 // it only and return.
424 //
425 std::string name = a_name;
426 if (this->contains(name))
427 {
428 for (int n = 0; n < number; n++)
429 {
430 T tmp;
431 this->queryclass<T>(name, tmp, file, func, line);
432 value.push_back(tmp);
433 }
434 return 0;
435 }
436
437 //
438 // Some logic to determine whether we are starting with zero
439 // (model0, model1, model2, ...)
440 // or one
441 // (model1, model2, model3, ...)
442 // since both are supported
443 //
444 int start = -1;
445 std::string name0 = a_name + std::to_string(0);
446 std::string name1 = a_name + std::to_string(1);
447 if (this->contains(name0.c_str()))
448 {
449 start = 0;
450 name = name0;
451 }
452 else if (this->contains(name1.c_str()))
453 {
454 start = 1;
455 name = name1;
456 }
457 else
458 {
459 Util::Exception(INFO,"Enumerations must begin with 0 or 1");
460 }
461
462 //
463 // Iterate over items called (model0), model1, model2, etc
464 // until no more are found then exit.
465 //
466 for (int cntr = start; this->contains(name.c_str()); cntr++)
467 {
468 if (this->contains(name.c_str()))
469 {
470 T tmp;
471 this->queryclass<T>(name, tmp, file, func, line);
472 value.push_back(tmp);
473 }
474 name = a_name + std::to_string(cntr+1);
475 }
476
477 return 0;
478 }
479
480
481 template <typename T>
482 int
483 query_enumerate(std::string a_name, std::vector<T> &value, int number = 1,
484 std::string file = "", std::string func = "", int line = __LINE__)
485 {
486 value.clear();
487
488 //
489 // If only one is present with no subscript, then read
490 // it only and return.
491 //
492 std::string name = a_name;
493 if (this->contains(name))
494 {
495 for (int n = 0; n < number; n++)
496 {
497 T tmp;
498 this->query_required(name, tmp, file, func, line);
499 value.push_back(tmp);
500 }
501 return 0;
502 }
503
504 //
505 // Some logic to determine whether we are starting with zero
506 // (model0, model1, model2, ...)
507 // or one
508 // (model1, model2, model3, ...)
509 // since both are supported
510 //
511 int start = -1;
512 std::string name0 = a_name + std::to_string(0);
513 std::string name1 = a_name + std::to_string(1);
514 if (this->contains(name0.c_str()))
515 {
516 start = 0;
517 name = name0;
518 }
519 else if (this->contains(name1.c_str()))
520 {
521 start = 1;
522 name = name1;
523 }
524 else
525 {
526 Util::Exception(INFO,"Enumerations must begin with 0 or 1");
527 }
528
529 //
530 // Iterate over items called (model0), model1, model2, etc
531 // until no more are found then exit.
532 //
533 for (int cntr = start; this->contains(name.c_str()); cntr++)
534 {
535 if (this->contains(name.c_str()))
536 {
537 T tmp;
538 this->query_required(name, tmp, file, func, line);
539 value.push_back(tmp);
540 }
541 name = a_name + std::to_string(cntr+1);
542 }
543
544 return 0;
545 }
546
547
548
550 {
551 int cnt = 0;
552 for (auto li = m_table->begin(), End = m_table->end(); li != End; ++li)
553 {
554 if (!li->second.m_count && li->first.rfind(getPrefix()+".",0) != std::string::npos)
555 {
556 Util::Warning(INFO,li->first);
557 cnt++;
558 }
559 }
560 return cnt;
561 }
562
563 std::vector<std::string> GetUnusedInputs()
564 {
565 std::vector<std::string> ret;
566 for (auto li = m_table->begin(), End = m_table->end(); li != End; ++li)
567 {
568 if (!li->second.m_count && li->first.rfind(getPrefix()+".",0) != std::string::npos)
569 {
570 ret.push_back(li->first);
571 }
572 }
573 return ret;
574 }
575
576 static int AllUnusedInputs()
577 {
578 ParmParse pp;
579 int cnt = 0;
580 for (auto li = pp.m_table->begin(), End = pp.m_table->end(); li != End; ++li)
581 {
582 if (!li->second.m_count)
583 {
584 Util::Warning(INFO,li->first);
585 cnt++;
586 }
587 }
588 return cnt;
589 }
590 std::string prefix ()
591 {
592 return getPrefix();
593 }
594 std::string full (std::string name)
595 {
596 std::string prefix = getPrefix();
597 if (prefix != "") return getPrefix() + "." + name;
598 else return name;
599 }
600
601
602 using amrex::ParmParse::queryarr;
603 template<class T>
604 void queryclass(std::string name, T * value,
605 std::string file = "", std::string func = "", int line = -1)
606 {
607 auto old_prefix = m_prefix;
608 try
609 {
610 if (old_prefix.empty()) m_prefix = name;
611 else m_prefix.append(".").append(name);
612 T::Parse(*value, *this);
613 std::vector<std::string> unused_inputs = GetUnusedInputs();
614 if (unused_inputs.size())
615 {
616 std::stringstream ss;
617 for (unsigned int i=0; i < unused_inputs.size(); i++)
618 ss << "\n\t" << unused_inputs[i];
619 Util::ParmParseException(INFO,file,func,line,name,"The following inputs were specified but not used",ss.str());
620 }
621 }
622 catch (...)
623 {
624 m_prefix = old_prefix;
625 Util::ParmParseException(INFO,file,func,line,full(name));
626 }
627 m_prefix = old_prefix;
628 }
629 template<class T>
630 void queryclass(std::string name, T & value,
631 std::string file = "", std::string func = "", int line = __LINE__)
632 {
633 auto old_prefix = m_prefix;
634 try
635 {
636 if (old_prefix.empty()) m_prefix = name;
637 else m_prefix.append(".").append(name);
638 T::Parse(value, *this);
639 std::vector<std::string> unused_inputs = GetUnusedInputs();
640 if (unused_inputs.size())
641 {
642 std::stringstream ss;
643 for (unsigned int i=0; i < unused_inputs.size(); i++)
644 ss << "\n\t" << unused_inputs[i];
645 Util::ParmParseException(INFO,file,func,line,name,"The following inputs were specified but not used",ss.str());
646 }
647 }
648 catch (...)
649 {
650 m_prefix = old_prefix;
651 Util::ParmParseException(INFO,file,func,line,full(name));
652 }
653 m_prefix = old_prefix;
654 }
655
656 template<class T>
657 void queryclass(T * value,
658 std::string file = "", std::string func = "", int line = __LINE__)
659 {
660 try
661 {
662 T::Parse(*value, *this);
663 }
664 catch (...)
665 {
666 Util::ParmParseException(INFO,file,func,line,getPrefix());
667 }
668 }
669 template<class T>
670 void queryclass(T & value,
671 std::string file = "", std::string func = "", int line = __LINE__)
672 {
673 try
674 {
675 T::Parse(value, *this);
676 }
677 catch (...)
678 {
679 Util::ParmParseException(INFO,file,func,line,getPrefix());
680 }
681 }
682
683 //
684 // Variadic template parsing operator to assign a pointer to
685 // one of a set of possible class objects, then call that method's
686 // Parse function.
687 //
688 // If there is more than one instantiating class, then type must be set.
689 // Otherwise, no type is necessary.
690 //
691 template<typename... IC, typename... Args, typename PTRTYPE>
692 void select (std::string name, PTRTYPE *& ic_eta, Args&&... args)
693 {
694 // if there is only one IC arg provided, we don't need to check the type - assume that
695 // it is the default.
696 if constexpr (sizeof...(IC) == 0)
697 {
698 using first_IC = std::tuple_element_t<0, std::tuple<IC...>>;
699 ic_eta = new first_IC(std::forward<Args>(args)..., (*this), name + "." + std::string(first_IC::name));
700 }
701 // otherwise, check the type.
702 else
703 {
704 std::string type = "";
705 this->query_required(name + ".type", type);
706 bool matched = (( type == IC::name
707 ? (ic_eta = new IC(std::forward<Args>(args)..., (*this), name + "." + std::string(IC::name))),
708 true
709 : false) || ...);
710 if (!matched)
711 Util::Exception(INFO, type, " not a valid type for ", name);
712 }
713 }
714
715 //
716 // Identical to the above, except sets the type automatically to the
717 // firs specified
718 //
719 template<typename FirstIC, typename... IC, typename... Args, typename PTRTYPE>
720 void select_default (std::string name, PTRTYPE *& ic_eta, Args&&... args)
721 {
722 std::string type = "";
723
724 this->query_default(name + ".type", type, FirstIC::name);
725
726 bool matched =
727 (( type == FirstIC::name
728 ? (ic_eta = new FirstIC(std::forward<Args>(args)..., (*this), name + "." + std::string(FirstIC::name))),
729 true : false))
730 ||
731 (( type == IC::name
732 ? (ic_eta = new IC(std::forward<Args>(args)..., (*this), name + "." + std::string(IC::name))),
733 true : false) || ...);
734
735
736 if (!matched)
737 Util::Exception(INFO,type," not a valid type for ",name);
738 }
739
740 //
741 // Similar to select but specialized for main functions
742 //
743 template<typename... INTEGRATOR, typename... Args, typename PTRTYPE>
744 void select_main (PTRTYPE *& ic_eta, Args&&... args)
745 {
746 std::string type = "";
747
748 this->query_required("alamo.program", type);
749
750 bool matched = ((type == INTEGRATOR::name
751 ? (ic_eta = new INTEGRATOR(std::forward<Args>(args)..., (*this))),
752 true
753 : false) || ...);
754 if (!matched)
755 Util::Exception(INFO,type," not a valid type for ",type);
756 }
757
758 //
759 // Similar to select_main but works for one function only
760 // and doesn't require a type specifier.
761 //
762
763 // with variadic arguments
764 template<typename INTEGRATOR, typename Args, typename PTRTYPE>
765 void select_only (PTRTYPE *& ic_eta, Args&& args)
766 {
767 ic_eta = new INTEGRATOR(std::forward<Args>(args), (*this));
768 }
769 // without variadic arguments
770 template<typename INTEGRATOR, typename PTRTYPE>
771 void select_only (PTRTYPE *& ic_eta)
772 {
773 ic_eta = new INTEGRATOR((*this));
774 }
775
776
777 template <int N>
778 void query_exactly(std::vector<std::string> names, std::pair<std::string, Set::Scalar> values[N])
779 {
780 int cnt = 0;
781 for (unsigned int n = 0; n < names.size(); n++)
782 {
783 if (amrex::ParmParse::contains(names[n].c_str()))
784 {
785 cnt++;
786 }
787 }
788 Util::Assert(INFO, TEST(cnt == N), "incorrect number of values specified");
789
790 cnt = 0;
791 for (unsigned int n = 0; n < names.size(); n++)
792 {
793 if (amrex::ParmParse::contains(names[n].c_str()))
794 {
795 values[cnt].first = names[n];
796 query_required(names[n],values[cnt].second);
797 cnt++;
798 }
799 }
800 }
801
802
803
804
805};
806}
807#endif
#define TEST(x)
Definition Util.H:21
#define INFO
Definition Util.H:20
int query_file(std::string name, std::string &value, bool copyfile, std::string file="", std::string func="query_file", int line=-1)
Definition ParmParse.H:323
void forbid(std::string name, std::string explanation, std::string file="", std::string func="", int line=-1)
Definition ParmParse.H:140
bool contains(std::string name)
Definition ParmParse.H:154
int queryarr(std::string name, Set::Matrix &value, std::string file="", std::string func="queryarr", int line=-1)
Definition ParmParse.H:353
int AnyUnusedInputs()
Definition ParmParse.H:549
void query_exactly(std::vector< std::string > names, std::pair< std::string, Set::Scalar > values[N])
Definition ParmParse.H:778
int query_default(std::string name, std::string &value, const char *defaultvalue, std::string file="", std::string func="", int line=-1)
Definition ParmParse.H:271
int queryarr_required(std::string name, std::vector< T > &value, std::string file, std::string func, int line)
Definition ParmParse.H:391
std::vector< std::string > GetUnusedInputs()
Definition ParmParse.H:563
std::string getPrefix() const
Definition ParmParse.H:134
static bool checked_for_input_files
Definition ParmParse.H:129
int query_required(std::string name, T &value, std::string file="", std::string func="", int line=-1)
Definition ParmParse.H:174
void queryclass(std::string name, T *value, std::string file="", std::string func="", int line=-1)
Definition ParmParse.H:604
std::string prefix()
Definition ParmParse.H:590
void select(std::string name, PTRTYPE *&ic_eta, Args &&... args)
Definition ParmParse.H:692
void Define()
Definition ParmParse.H:116
void select_default(std::string name, PTRTYPE *&ic_eta, Args &&... args)
Definition ParmParse.H:720
int query_validate(std::string name, std::string &value, std::vector< const char * > possiblecharvals, std::string file="", std::string func="", int line=-1)
Definition ParmParse.H:263
int query_default(std::string name, T &value, T defaultvalue, std::string="", std::string="", int=-1)
Definition ParmParse.H:185
int queryclass_enumerate(std::string a_name, std::vector< T > &value, int number=1, std::string file="", std::string func="", int line=__LINE__)
Definition ParmParse.H:416
int queryarr(std::string name, Set::Vector &value, std::string file="", std::string func="queryarr", int line=-1)
Definition ParmParse.H:341
static int AllUnusedInputs()
Definition ParmParse.H:576
void queryclass(std::string name, T &value, std::string file="", std::string func="", int line=__LINE__)
Definition ParmParse.H:630
int query_file(std::string name, std::string &value, std::string file="", std::string func="query_file", int line=-1)
Definition ParmParse.H:328
int query_default(std::string name, int &value, bool defaultvalue, std::string file="", std::string func="query_default", int line=-1)
Definition ParmParse.H:277
void queryclass(T &value, std::string file="", std::string func="", int line=__LINE__)
Definition ParmParse.H:670
int queryarr(std::string name, std::vector< T > &value, std::string, std::string, int)
Definition ParmParse.H:336
int query_file(std::string name, std::string &value, bool copyfile, bool checkfile, std::string file="", std::string func="query_file", int line=-1)
Definition ParmParse.H:288
void select_only(PTRTYPE *&ic_eta, Args &&args)
Definition ParmParse.H:765
void select_main(PTRTYPE *&ic_eta, Args &&... args)
Definition ParmParse.H:744
void queryclass(T *value, std::string file="", std::string func="", int line=__LINE__)
Definition ParmParse.H:657
void select_only(PTRTYPE *&ic_eta)
Definition ParmParse.H:771
void ignore(std::string name)
Definition ParmParse.H:135
std::string full(std::string name)
Definition ParmParse.H:594
int query_validate(std::string name, std::string &value, std::vector< const char * > possiblecharvals, bool firstbydefault, std::string file="", std::string func="", int line=-1)
Definition ParmParse.H:226
int query_enumerate(std::string a_name, std::vector< T > &value, int number=1, std::string file="", std::string func="", int line=__LINE__)
Definition ParmParse.H:483
int queryarr_default(std::string name, std::vector< std::string > &value, std::string defaultvalue, std::string="", std::string="", int=-1)
Definition ParmParse.H:402
int query_validate(std::string name, int &value, std::vector< int > possibleintvals, std::string file="", std::string func="", int line=-1)
Definition ParmParse.H:195
ParmParse(std::string arg)
Definition ParmParse.H:132
Initialize a spherical inclusion.
Definition BMP.H:19
Eigen::Matrix< amrex::Real, AMREX_SPACEDIM, 1 > Vector
Definition Base.H:20
Eigen::Matrix< amrex::Real, AMREX_SPACEDIM, AMREX_SPACEDIM > Matrix
Definition Base.H:23
AMREX_FORCE_INLINE void Assert(std::string file, std::string func, int line, std::string smt, bool pass, Args const &... args)
Definition Util.H:70
void ParmParseException(std::string file, std::string func, int line, std::string file2, std::string, int line2, std::string fullname, Args const &... args)
Definition Util.H:263
void CopyFileToOutputDir(std::string a_path, bool fullpath, std::string prefix)
Definition Util.cpp:52
void Warning(std::string file, std::string func, int line, Args const &... args)
Definition Util.H:181
void Message(std::string file, std::string func, int line, Args const &... args)
Definition Util.H:141
void Exception(std::string file, std::string func, int line, Args const &... args)
Definition Util.H:205