Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_ParmParse.H
Go to the documentation of this file.
1#ifndef AMREX_PARMPARSE_H_
2#define AMREX_PARMPARSE_H_
3#include <AMReX_Config.H>
4
5#include <AMReX_BLassert.H>
6#include <AMReX_Box.H>
7#include <AMReX_Enum.H>
8#include <AMReX_INT.H>
9#include <AMReX_IntVect.H>
10#include <AMReX_IParser.H>
11#include <AMReX_Parser.H>
12#include <AMReX_TypeTraits.H>
13
14#include <array>
15#include <iosfwd>
16#include <optional>
17#include <set>
18#include <string>
19#include <string_view>
20#include <type_traits>
21#include <unordered_map>
22#include <variant>
23#include <vector>
24
25namespace amrex {
26
27template<int dim>
28class BoxND;
29using Box = BoxND<AMREX_SPACEDIM>;
30template<int dim>
31class IntVectND;
32using IntVect = IntVectND<AMREX_SPACEDIM>;
33template<int dim>
34class RealVectND;
36
38namespace ppdetail {
39 template <class T, class Enable = void>
40 struct ArithmeticOptional_TT : std::false_type {};
41
42 template <class T>
43 struct ArithmeticOptional_TT<T, std::enable_if_t<std::is_arithmetic_v<T>>>
44 : std::true_type
45 {
46 using value_type = T;
47 };
48
49 template <class T>
50 struct ArithmeticOptional_TT<std::optional<T>,
51 std::enable_if_t<std::is_arithmetic_v<T>>>
52 : std::true_type
53 {
54 using value_type = T;
55 };
56
57 template <class T>
58 inline constexpr bool IsArithmeticOptional_v = ArithmeticOptional_TT<T>::value;
59
60 template <class T>
61 using underlying_type_t = typename ArithmeticOptional_TT<T>::value_type;
62}
64
65//
66// ParmParse class implements a simple database for the storage and
67// retrieval of command-line and input-file arguments. The entries are
68// stored in a static table in (name,value_list) pairs.
69//
70// The format of the input file is a series of DEFINITIONS.
71//
72// A DEFINITION is of the form <name> = <value> <value> ...
73// The equal sign is important since the list of values can span multiple
74// lines.
75//
76// Comments in an input file include all text from a '#' character to the
77// end of the line. Here is an example input file:
78/*
79 niter = 100 # niter is an integer
80 title = "Double Wammy" # example of a string with spaces
81 cell_size = 0.5 0.75 # cell spacing in each dimension
82 plot.var = Density 1 10 # a list of values
83 plot.var = Energy 5 12 # another list of values
84 bigarray = 1 2 3 4 5 6 7 8 \
85 9 10 11 12 # continuation of bigarray
86 multi_line_string = "This is a
87 multi-line string."
88 my_2d_table = \
89 # col 1 2 3
90 {{ 11.0, 12.0, 13.0 } # row 1
91 { 21.0, 22.0, 23.0 } # row 2
92 { 31.0, 32.0, 33.0 } # row 3
93 { 41.0, 42.0, 43.0 } } # row 4
94 test = apple "boy blue" 10 20 30 40
95 FILE = prob_file # insert contents of this "prob_file" here
96*/
97// For values spanning multiple lines except for table, one must use '\' at
98// the end of a line
99// for continuation, otherwise it's a runtime error. Note that there must be
100// at least one space before the continuation character `\`. Multiple lines
101// inside a pair of double quotes are considered a single string containing
102// '\n's. The "FILE = <filename>" definition is special. Rather than just
103// adding this entry to the database, it reads the contents of <filename>
104// into the database.
105// For CI/CD workflows and out-of-source tests, the environment variable
106// AMREX_INPUTS_FILE_PREFIX can be set to prefix every FILE = <filename>
107// with a custom path.
108//
109// ParmParse stores all entries in a static table which is built the
110// first time a ParmParse object is constructed (usually in main()).
111// Subsequent invocations have access to this table.
112// A ParmParse constructor has an optional "prefix" argument that will
113// limit the searches to only those entries of the table with this prefix
114// in name. For example:
115// ParmParse pp("plot");
116// will find only those entries with name given by "plot.<string>".
117//
118// All values in the table are stored as strings. For example, the
119// values of "cell_size" in the above input file are stored as the
120// strings "0.5" and "0.75". These strings can be returned as either
121// strings or numeric values by the query functions.
122// Character strings with spaces must be delimited by double quotes
123// in the input file but the quotes are stripped before they are entered
124// into the table. For example, 'title' in the above input file has a
125// single value, the string 'Double Wammy' (without the quotes).
126// Each value in the list associated with a definition can be referred to
127// by its index number. The index numbers start at 0 just like an array
128// in the C programming language. Consider the definition of "test" in
129// the above input file. The first value 'apple'is a string with index
130// 0. The second value 'boy blue' is a string with index 1. The
131// remaining four values are integers indexed 2, 3, 4, and 5.
132//
133// For a string value to represent an integer or float it must fit the
134// following regular expression:
135// Sign ::= '+' | '-'
136// Digit ::= '0' | '1' | ... | '9'
137// Integer ::= [Sign]Digit+
138// Exp ::= ('e'|'E')Integer
139// Float ::= ( Integer[.Digit*][Exp] | [Integer].Digit+[Exp] )
140//
141// Where '+' indicates one or more occurrences, '*' represents zero or
142// more occurrences, '|' means one or the other and '[]' represents zero
143// or one occurrence.
144//
145// Note that floats and doubles have the same string representation and
146// that the FORTRAN "double" exponent format is not supported.
147// That is, 1.0d+3 is not a valid representation of a floating point
148// number but that 1.0e+3 is acceptable.
149//
150// There are a host of functions allowing the user to query the database
151// and retrieve values. Here are some general rules about the names of
152// the member functions:
153//
154// * Functions with the string "get" in their names attempt to get a
155// value or an array of values from the table. They generate a
156// run-time error if they are not successful.
157//
158// * Functions with the string "query" in their names attempt to get a
159// value or an array of values from the table. They return the value 1
160// (true) if they are successful and 0 (false) if not.
161//
162// * Functions with the string "kth" in their names get values from
163// the Kth entry with the given name in the database. This is
164// necessary since there may be multiple definitions with the same
165// name in the database.
166//
167// * Functions without the string "kth" in their names get values from
168// the last entry with the given name in the database. Note that the
169// definitions from the command line are appended to the database table
170// and hence will be the last entries.
171//
172// * Functions with the string "arr" in their names get an Array of
173// values from the given entry in the table. The array argument is
174// resized (if necessary) to hold all the values requested.
175//
176// * Functions without the string "arr" in their names get single
177// values from the given entry in the table.
178//
179// The following is a code sample showing how to use ParmParse:
180//
181// main(int argc, char **argv)
182// {
183// char* in_file_name = argv[1];
184// ParmParse::Initialize(argc-2, argv+2, in_file_name);
185//
186// // Query table for value of "niter". If not in table
187// // then set to default value
188// if (!pp.query("niter",niter)) niter = 20;
189//
190// // read array of cell sizes if in table
191// Vector<float> dx;
192// if (nx=pp.countval("cell_size")) {
193// // get nx values starting at index 0 and store in dx.
194// // dx is automatically resized here.
195// pp.getarr("cell_size",dx,0,nx);
196// }
197// ParmParse::Finalize();
198// }
199//
200// void do_graphics()
201// {
202// //
203// // Will only query entries with the "plot" prefix:
204// //
205// ParmParse pp("plot");
206// //
207// // Read all variables with "plot.var" keyword.
208// //
209// std::string var_name;
210// Vector<int> range;
211// int num = pp.countname("var");
212// for (int k = 0; k < num; k++)
213// {
214// //
215// // Element 0 in list is a string.
216// //
217// pp.getkth("var",k,var_name,0);
218// //
219// // Elements 1 and 2 are integers.
220// // Note that "range" will be resized to hold 2 elements.
221// //
222// pp.getktharr("var",k,range,1,2);
223// cout << "variable = " << var_name << "lo, hi = ",
224// << range[0] << " " << range[1] << endl;
225// }
226// }
227// -----------------------------------------------------------------
228// ----------------------- END COMMENTS ---------------------------
229// -----------------------------------------------------------------
230
231
346{
347public:
348 enum { LAST = -1, FIRST = 0, ALL = -1 };
356 explicit ParmParse (std::string prefix = std::string(),
357 std::string parser_prefix = std::string());
358
360 [[nodiscard]] bool contains (std::string_view name) const;
366 [[nodiscard]] int countval (std::string_view name, int n = LAST) const;
371 [[nodiscard]] int countname (std::string_view name) const;
383 void getkth (std::string_view name,
384 int k,
385 bool& ref,
386 int ival = FIRST) const;
388 void get (std::string_view name,
389 bool& ref,
390 int ival = FIRST) const;
398 int querykth (std::string_view name,
399 int k,
400 bool& ref,
401 int ival = FIRST) const;
403 int query (std::string_view name,
404 bool& ref,
405 int ival = FIRST) const;
407 void add (std::string_view name, bool val);
417 void getkth (std::string_view name,
418 int k,
419 int& ref,
420 int ival = FIRST) const;
421
423 void get (std::string_view name,
424 int& ref,
425 int ival = FIRST) const;
433 int querykth (std::string_view name,
434 int k,
435 int& ref,
436 int ival = FIRST) const;
438 int query (std::string_view name,
439 int& ref,
440 int ival = FIRST) const;
442 void add (std::string_view name, int val);
452 void getkth (std::string_view name,
453 int k,
454 long& ref,
455 int ival = FIRST) const;
457 void get (std::string_view name,
458 long& ref,
459 int ival = FIRST) const;
467 int querykth (std::string_view name,
468 int k,
469 long& ref,
470 int ival = FIRST) const;
472 int query (std::string_view name,
473 long& ref,
474 int ival = FIRST) const;
476 void add (std::string_view name, long val);
486 void getkth (std::string_view name,
487 int k,
488 long long& ref,
489 int ival = FIRST) const;
491 void get (std::string_view name,
492 long long& ref,
493 int ival = FIRST) const;
501 int querykth (std::string_view name,
502 int k,
503 long long& ref,
504 int ival = FIRST) const;
506 int query (std::string_view name,
507 long long& ref,
508 int ival = FIRST) const;
510 void add (std::string_view name, long long val);
520 void getkth (std::string_view name,
521 int k,
522 float& ref,
523 int ival = FIRST) const;
525 void get (std::string_view name,
526 float& ref,
527 int ival = FIRST) const;
535 int querykth (std::string_view name,
536 int k,
537 float& ref,
538 int ival = FIRST) const;
540 int query (std::string_view name,
541 float& ref,
542 int ival = FIRST) const;
544 void add (std::string_view name, float val);
554 void getkth (std::string_view name,
555 int k,
556 double& ref,
557 int ival = FIRST) const;
559 void get (std::string_view name,
560 double& ref,
561 int ival = FIRST) const;
569 int querykth (std::string_view name,
570 int k,
571 double& ref,
572 int ival = FIRST) const;
574 int query (std::string_view name,
575 double& ref,
576 int ival = FIRST) const;
578 void add (std::string_view name, double val);
588 void getkth (std::string_view name,
589 int k,
590 std::string& ref,
591 int ival = FIRST) const;
592
594 void get (std::string_view name,
595 std::string& ref,
596 int ival = FIRST) const;
604 int querykth (std::string_view name,
605 int k,
606 std::string& ref,
607 int ival = FIRST) const;
609 int query (std::string_view name,
610 std::string& ref,
611 int ival = FIRST) const;
613 void add (std::string_view name, const std::string& val);
614
615
624 void getline (std::string_view name, std::string& ref) const;
625
634 int queryline (std::string_view name, std::string& ref) const;
635
645 void getkth (std::string_view name,
646 int k,
647 IntVect& ref,
648 int ival = FIRST) const;
650 void get (std::string_view name,
651 IntVect& ref,
652 int ival = FIRST) const;
660 int querykth (std::string_view name,
661 int k,
662 IntVect& ref,
663 int ival = FIRST) const;
665 int query (std::string_view name,
666 IntVect& ref,
667 int ival = FIRST) const;
669 void add (std::string_view name, const IntVect& val);
679 void getkth (std::string_view name,
680 int k,
681 Box& ref,
682 int ival = FIRST) const;
684 void get (std::string_view name,
685 Box& ref,
686 int ival = FIRST) const;
694 int querykth (std::string_view name,
695 int k,
696 Box& ref,
697 int ival = FIRST) const;
699 int query (std::string_view name,
700 Box& ref,
701 int ival = FIRST) const;
703 void add (std::string_view name, const Box& val);
716 void getktharr (std::string_view name,
717 int k,
718 std::vector<int>& ref,
719 int start_ix = FIRST,
720 int num_val = ALL) const;
722 void getarr (std::string_view name,
723 std::vector<int>& ref,
724 int start_ix = FIRST,
725 int num_val = ALL) const;
727 int queryktharr (std::string_view name,
728 int k,
729 std::vector<int>& ref,
730 int start_ix = FIRST,
731 int num_val = ALL) const;
733 int queryarr (std::string_view name,
734 std::vector<int>& ref,
735 int start_ix = FIRST,
736 int num_val = ALL) const;
738 void addarr (std::string_view name, const std::vector<int>& ref);
739
752 void getktharr (std::string_view name,
753 int k,
754 std::vector<long>& ref,
755 int start_ix = FIRST,
756 int num_val = ALL) const;
758 void getarr (std::string_view name,
759 std::vector<long>& ref,
760 int start_ix = FIRST,
761 int num_val = ALL) const;
763 int queryktharr (std::string_view name,
764 int k,
765 std::vector<long>& ref,
766 int start_ix = FIRST,
767 int num_val = ALL) const;
769 int queryarr (std::string_view name,
770 std::vector<long>& ref,
771 int start_ix = FIRST,
772 int num_val = ALL) const;
774 void addarr (std::string_view name, const std::vector<long>& ref);
775
788 void getktharr (std::string_view name,
789 int k,
790 std::vector<long long>& ref,
791 int start_ix = FIRST,
792 int num_val = ALL) const;
794 void getarr (std::string_view name,
795 std::vector<long long>& ref,
796 int start_ix = FIRST,
797 int num_val = ALL) const;
799 int queryktharr (std::string_view name,
800 int k,
801 std::vector<long long>& ref,
802 int start_ix = FIRST,
803 int num_val = ALL) const;
805 int queryarr (std::string_view name,
806 std::vector<long long>& ref,
807 int start_ix = FIRST,
808 int num_val = ALL) const;
810 void addarr (std::string_view name, const std::vector<long long>& ref);
811
824 void getktharr (std::string_view name,
825 int k,
826 std::vector<float>& ref,
827 int start_ix = FIRST,
828 int num_val = ALL) const;
830 void getarr (std::string_view name,
831 std::vector<float>& ref,
832 int start_ix = FIRST,
833 int num_val = ALL) const;
835 int queryktharr (std::string_view name,
836 int k,
837 std::vector<float>& ref,
838 int start_ix = FIRST,
839 int num_val = ALL) const;
841 int queryarr (std::string_view name,
842 std::vector<float>& ref,
843 int start_ix = FIRST,
844 int num_val = ALL) const;
846 void addarr (std::string_view name, const std::vector<float>& ref);
859 void getktharr (std::string_view name,
860 int k,
861 std::vector<double>& ref,
862 int start_ix = FIRST,
863 int num_val = ALL) const;
865 void getarr (std::string_view name,
866 std::vector<double>& ref,
867 int start_ix = FIRST,
868 int num_val = ALL) const;
870 int queryktharr (std::string_view name,
871 int k,
872 std::vector<double>& ref,
873 int start_ix = FIRST,
874 int num_val = ALL) const;
876 int queryarr (std::string_view name,
877 std::vector<double>& ref,
878 int start_ix = FIRST,
879 int num_val = ALL) const;
881 void addarr (std::string_view name, const std::vector<double>& ref);
894 void getktharr (std::string_view name,
895 int k,
896 std::vector<std::string>& ref,
897 int start_ix = FIRST,
898 int num_val = ALL) const;
900 void getarr (std::string_view name,
901 std::vector<std::string>& ref,
902 int start_ix = FIRST,
903 int num_val = ALL) const;
905 int queryktharr (std::string_view name,
906 int k,
907 std::vector<std::string>& ref,
908 int start_ix = FIRST,
909 int num_val = ALL) const;
911 int queryarr (std::string_view name,
912 std::vector<std::string>& ref,
913 int start_ix = FIRST,
914 int num_val = ALL) const;
916 void addarr (std::string_view name, const std::vector<std::string>& ref);
929 void getktharr (std::string_view name,
930 int k,
931 std::vector<IntVect>& ref,
932 int start_ix = FIRST,
933 int num_val = ALL) const;
935 void getarr (std::string_view name,
936 std::vector<IntVect>& ref,
937 int start_ix = FIRST,
938 int num_val = ALL) const;
940 int queryktharr (std::string_view name,
941 int k,
942 std::vector<IntVect>& ref,
943 int start_ix = FIRST,
944 int num_val = ALL) const;
946 int queryarr (std::string_view name,
947 std::vector<IntVect>& ref,
948 int start_ix = FIRST,
949 int num_val = ALL) const;
951 void addarr (std::string_view name, const std::vector<IntVect>& ref);
964 void getktharr (std::string_view name,
965 int k,
966 std::vector<Box>& ref,
967 int start_ix = FIRST,
968 int num_val = ALL) const;
970 void getarr (std::string_view name,
971 std::vector<Box>& ref,
972 int start_ix = FIRST,
973 int num_val = ALL) const;
975 int queryktharr (std::string_view name,
976 int k,
977 std::vector<Box>& ref,
978 int start_ix = FIRST,
979 int num_val = ALL) const;
981 int queryarr (std::string_view name,
982 std::vector<Box>& ref,
983 int start_ix = FIRST,
984 int num_val = ALL) const;
986 void addarr (std::string_view name, const std::vector<Box>& ref);
987
988 /*
989 * \brief Query IntVect from array
990 *
991 * This reads IntVect from an array (e.g., `8 16 8`), not the format
992 * using parentheses (e.g., `(8,16,8)`).
993 */
994 int queryarr (std::string_view name, IntVect& ref) const;
995
996 /*
997 * \brief Get IntVect from array
998 *
999 * This reads IntVect from an array (e.g., `8 16 8`), not the format
1000 * using parentheses (e.g., `(8,16,8)`).
1001 */
1002 void getarr (std::string_view name, IntVect& ref) const;
1003
1005 int queryarr (std::string_view name, RealVect& ref) const;
1006
1008 void getarr (std::string_view name, RealVect& ref) const;
1009
1010 template <typename T, std::size_t N>
1011 void get (std::string_view name, std::array<T,N>& ref) const {
1012 std::vector<T> v;
1013 this->getarr(name, v);
1014 AMREX_ALWAYS_ASSERT(v.size() >= N);
1015 for (std::size_t i = 0; i < N; ++i) {
1016 ref[i] = v[i];
1017 }
1018 }
1019
1020 template <typename T, std::size_t N>
1021 int query (std::string_view name, std::array<T,N>& ref) const {
1022 std::vector<T> v;
1023 int exist = this->queryarr(name, v);
1024 if (exist) {
1025 AMREX_ALWAYS_ASSERT(v.size() >= N);
1026 for (std::size_t i = 0; i < N; ++i) {
1027 ref[i] = v[i];
1028 }
1029 }
1030 return exist;
1031 }
1032
1039 template <typename T, std::enable_if_t<!IsStdVector<T>::value, int> = 0>
1040 int queryAdd (std::string_view name, T& ref) {
1041 int exist = this->query(name, ref);
1042 if (!exist) {
1043 this->add(name, ref);
1044 }
1045 return exist;
1046 }
1047
1048 int queryAdd (std::string_view name, std::string& ref) {
1049 int exist = this->query(name, ref);
1050 if (!exist && !ref.empty()) {
1051 this->add(name, ref);
1052 }
1053 return exist;
1054 }
1055
1065 template <typename T>
1066 int queryAdd (std::string_view name, std::vector<T>& ref) {
1067 std::vector<T> empty;
1068 int exist = this->queryarr(name, empty);
1069 if (exist) {
1070 ref = std::move(empty);
1071 }
1072 if (!exist && !ref.empty()) {
1073 this->addarr(name, ref);
1074 }
1075 return exist;
1076 }
1077
1084 template <typename T>
1085 int queryAdd (std::string_view name, std::vector<T>& ref, int num_val) {
1086 int exist = this->queryarr(name, ref, 0, num_val);
1087 if (!exist) {
1088 this->addarr(name, ref);
1089 }
1090 return exist;
1091 }
1092
1099 template <typename T, std::size_t N>
1100 int queryAdd (std::string_view name, std::array<T,N>& ref) {
1101 std::vector<T> v;
1102 int exist = this->queryarr(name, v);
1103 if (exist) {
1104 AMREX_ALWAYS_ASSERT(v.size() >= N);
1105 for (std::size_t i = 0; i < N; ++i) {
1106 ref[i] = v[i];
1107 }
1108 } else {
1109 v.resize(N);
1110 for (std::size_t i = 0; i < N; ++i) {
1111 v[i] = ref[i];
1112 }
1113 this->addarr(name, v);
1114 }
1115 return exist;
1116 }
1117
1124 int queryWithParser (std::string_view name, bool& ref) const;
1125 int queryWithParser (std::string_view name, int& ref) const;
1126 int queryWithParser (std::string_view name, long& ref) const;
1127 int queryWithParser (std::string_view name, long long& ref) const;
1128 int queryWithParser (std::string_view name, float& ref) const;
1129 int queryWithParser (std::string_view name, double& ref) const;
1130
1137 int queryarrWithParser (std::string_view name, int nvals, bool* ptr) const;
1138 int queryarrWithParser (std::string_view name, int nvals, int* ptr) const;
1139 int queryarrWithParser (std::string_view name, int nvals, long* ptr) const;
1140 int queryarrWithParser (std::string_view name, int nvals, long long* ptr) const;
1141 int queryarrWithParser (std::string_view name, int nvals, float* ptr) const;
1142 int queryarrWithParser (std::string_view name, int nvals, double* ptr) const;
1143 template <typename T, std::enable_if_t<std::is_same_v<T,bool> ||
1144 std::is_same_v<T,int> ||
1145 std::is_same_v<T,long> ||
1146 std::is_same_v<T,long long> ||
1147 std::is_same_v<T,float> ||
1148 std::is_same_v<T,double>,int> = 0>
1149 int queryarrWithParser (std::string_view name, int nvals, std::vector<T>& ref) const
1150 {
1151 if (this->contains(name)) {
1152 if (int(ref.size()) < nvals) { ref.resize(nvals); }
1153 return this->queryarrWithParser(name, nvals, ref.data());
1154 } else {
1155 return 0;
1156 }
1157 }
1158
1165 template <typename T, std::enable_if_t<std::is_same_v<T,bool> ||
1166 std::is_same_v<T,int> ||
1167 std::is_same_v<T,long> ||
1168 std::is_same_v<T,long long> ||
1169 std::is_same_v<T,float> ||
1170 std::is_same_v<T,double>,int> = 0>
1171 int queryAddWithParser (std::string_view name, T& ref)
1172 {
1173 int exist = this->queryWithParser(name, ref);
1174 if (!exist) {
1175 this->add(name, ref);
1176 }
1177 return exist;
1178 }
1179
1185 template <typename T, std::enable_if_t<std::is_same_v<T,bool> ||
1186 std::is_same_v<T,int> ||
1187 std::is_same_v<T,long> ||
1188 std::is_same_v<T,long long> ||
1189 std::is_same_v<T,float> ||
1190 std::is_same_v<T,double>,int> = 0>
1191 void getWithParser (std::string_view name, T& ref) const
1192 {
1193 int exist = this->queryWithParser(name, ref);
1194 if (!exist) {
1195 amrex::Error(std::string("ParmParse::getWithParser: failed to get ")+std::string(name));
1196 }
1197 }
1198
1204 template <typename T, std::enable_if_t<std::is_same_v<T,bool> ||
1205 std::is_same_v<T,int> ||
1206 std::is_same_v<T,long> ||
1207 std::is_same_v<T,long long> ||
1208 std::is_same_v<T,float> ||
1209 std::is_same_v<T,double>,int> = 0>
1210 void getarrWithParser (std::string_view name, int nvals, T* ptr) const
1211 {
1212 int exist = this->queryarrWithParser(name, nvals, ptr);
1213 if (!exist) {
1214 amrex::Error(std::string("ParmParse::getarrWithParser: failed to get ")+std::string(name));
1215 }
1216 }
1217
1223 template <typename T, std::enable_if_t<std::is_same_v<T,bool> ||
1224 std::is_same_v<T,int> ||
1225 std::is_same_v<T,long> ||
1226 std::is_same_v<T,long long> ||
1227 std::is_same_v<T,float> ||
1228 std::is_same_v<T,double>,int> = 0>
1229 void getarrWithParser (std::string_view name, int nvals, std::vector<T>& ref) const
1230 {
1231 int exist = this->queryarrWithParser(name, nvals, ref);
1232 if (!exist) {
1233 amrex::Error(std::string("ParmParse::getarrWithParser: failed to get ")+std::string(name));
1234 }
1235 }
1236
1237 /*
1238 * \brief Evaluate given string as math expression
1239 *
1240 * For unknown symbols, ParmParse database will be queried.
1241 */
1242 template <typename T, std::enable_if_t<std::is_same_v<T,bool> ||
1243 std::is_same_v<T,int> ||
1244 std::is_same_v<T,long> ||
1245 std::is_same_v<T,long long> ||
1246 std::is_same_v<T,float> ||
1247 std::is_same_v<T,double>,int> = 0>
1248 T eval (std::string const& expr) const
1249 {
1250 if constexpr (std::is_integral_v<T>) {
1251 auto const parser = this->makeIParser(expr, {});
1252 auto const exe = parser.compileHost<0>();
1253 return static_cast<T>(exe()); // In the future, we might add safety check.
1254 } else {
1255 auto const parser = this->makeParser(expr, {});
1256 auto const exe = parser.compileHost<0>();
1257 return static_cast<T>(exe());
1258 }
1259 }
1260
1261 /*
1262 * \brief Query two names.
1263 *
1264 * This function queries with `new_name` first. If it's not found, it
1265 * will try again with `old_name`.
1266 */
1267 template <typename T>
1268 int query (const char* new_name, const char* old_name, T& ref)
1269 {
1270 return (this->query(new_name, ref) ||
1271 this->query(old_name, ref));
1272 }
1273
1281 template <typename T>
1282 void get (const char* new_name, const char* old_name, T& ref)
1283 {
1284 auto exist = this->query(new_name, old_name, ref);
1285 if (!exist) {
1286 amrex::ErrorStream() << "ParmParse::get failed to find "
1287 << new_name << " and " << old_name << '\n';
1289 amrex::Abort();
1290 }
1291 }
1292
1301 template <typename T, typename ET = amrex_enum_traits<T>,
1302 std::enable_if_t<ET::value,int> = 0>
1303 int query (std::string_view name, T& ref, int ival = FIRST) const
1304 {
1305 std::string s;
1306 int exist = this->query(name, s, ival);
1307 if (exist) {
1308 try {
1309 ref = amrex::getEnum<T>(s);
1310 } catch (...) {
1311 if (amrex::Verbose() > 0 ) {
1312 amrex::Print() << "amrex::ParmParse::query (input name: "
1313 << this->prefixedName(name) << "):\n";
1314 }
1315 throw;
1316 }
1317 }
1318 return exist;
1319 }
1320
1321
1324 template <typename T, typename ET = amrex_enum_traits<T>,
1325 std::enable_if_t<ET::value,int> = 0>
1326 void add (std::string_view name, T const& val)
1327 {
1328 this->add(name, amrex::getEnumNameString(val));
1329 }
1330
1339 template <typename T, typename ET = amrex_enum_traits<T>,
1340 std::enable_if_t<ET::value,int> = 0>
1341 void get (std::string_view name, T& ref, int ival = FIRST) const
1342 {
1343 std::string s;
1344 this->get(name, s, ival);
1345 try {
1346 ref = amrex::getEnum<T>(s);
1347 } catch (...) {
1348 if (amrex::Verbose() > 0 ) {
1349 amrex::Print() << "amrex::ParmParse::get (input name: "
1350 << this->prefixedName(name) << "):\n";
1351 }
1352 throw;
1353 }
1354 }
1355
1357 template <typename T, typename ET = amrex_enum_traits<T>,
1358 std::enable_if_t<ET::value,int> = 0>
1359 int queryarr (std::string_view name,
1360 std::vector<T>& ref,
1361 int start_ix = FIRST,
1362 int num_val = ALL) const
1363 {
1364 std::vector<std::string> s;
1365 int exist = this->queryarr(name, s, start_ix, num_val);
1366 if (exist) {
1367 ref.resize(s.size());
1368 for (std::size_t i = 0; i < s.size(); ++i) {
1369 try {
1370 ref[i] = amrex::getEnum<T>(s[i]);
1371 } catch (...) {
1372 if (amrex::Verbose() > 0 ) {
1373 amrex::Print() << "amrex::ParmParse::queryarr (input name: "
1374 << this->prefixedName(name) << "):\n";
1375 }
1376 throw;
1377 }
1378 }
1379 }
1380 return exist;
1381 }
1382
1384 template <typename T, typename ET = amrex_enum_traits<T>,
1385 std::enable_if_t<ET::value,int> = 0>
1386 void getarr (std::string_view name,
1387 std::vector<T>& ref,
1388 int start_ix = FIRST,
1389 int num_val = ALL) const
1390 {
1391 std::vector<std::string> s;
1392 this->getarr(name, s, start_ix, num_val);
1393 ref.resize(s.size());
1394 for (std::size_t i = 0; i < s.size(); ++i) {
1395 try {
1396 ref[i] = amrex::getEnum<T>(s[i]);
1397 } catch (...) {
1398 if (amrex::Verbose() > 0 ) {
1399 amrex::Print() << "amrex::ParmParse::getarr (input name: "
1400 << this->prefixedName(name) << "):\n";
1401 }
1402 throw;
1403 }
1404 }
1405 }
1406
1417 template <typename T, typename ET = amrex_enum_traits<T>,
1418 std::enable_if_t<ET::value,int> = 0>
1419 int query_enum_case_insensitive (std::string_view name, T& ref, int ival = FIRST) const
1420 {
1421 std::string s;
1422 int exist = this->query(name, s, ival);
1423 if (exist) {
1424 try {
1425 ref = amrex::getEnumCaseInsensitive<T>(s);
1426 } catch (...) {
1427 if (amrex::Verbose() > 0) {
1428 amrex::Print() << "amrex::ParmParse::query_enum_case_insensitive (input name: "
1429 << this->prefixedName(name) << "):\n";
1430 }
1431 throw;
1432 }
1433 }
1434 return exist;
1435 }
1436
1447 template <typename T, typename ET = amrex_enum_traits<T>,
1448 std::enable_if_t<ET::value,int> = 0>
1449 void get_enum_case_insensitive (std::string_view name, T& ref, int ival = FIRST) const
1450 {
1451 int exist = this->query_enum_case_insensitive(name, ref, ival);
1452 if (!exist) {
1453 std::string msg("get_enum_case_insensitive(\"");
1454 msg.append(name).append("\",").append(amrex::getEnumClassName<T>())
1455 .append("&) failed.");
1456 amrex::Abort(msg);
1457 }
1458 }
1459
1472 template <typename T, typename ET = amrex_enum_traits<T>,
1473 std::enable_if_t<ET::value,int> = 0>
1474 int query_enum_sloppy (std::string_view name, T& ref, std::string_view const& ignores,
1475 int ival = FIRST) const
1476 {
1477 std::string s;
1478 int exist = this->query(name, s, ival);
1479 if (exist) {
1480 try {
1481 s.erase(std::remove_if(s.begin(), s.end(),
1482 [&] (auto const& c) {
1483 return ignores.find(c) != std::string_view::npos; }),
1484 s.end());
1485 ref = amrex::getEnumCaseInsensitive<T>(s);
1486 } catch (...) {
1487 if (amrex::Verbose() > 0) {
1488 amrex::Print() << "amrex::ParmParse::query_enum_sloppy (input name: "
1489 << this->prefixedName(name) << "):\n";
1490 }
1491 throw;
1492 }
1493 }
1494 return exist;
1495 }
1496
1509 template <typename T, typename ET = amrex_enum_traits<T>,
1510 std::enable_if_t<ET::value,int> = 0>
1511 void get_enum_sloppy (std::string_view name, T& ref, std::string_view const& ignores,
1512 int ival = FIRST) const
1513 {
1514 int exist = this->query_enum_sloppy(name, ref, ignores, ival);
1515 if (!exist) {
1516 std::string msg("get_enum_sloppy(\"");
1517 msg.append(name).append("\",").append(amrex::getEnumClassName<T>())
1518 .append("&) failed.");
1519 amrex::Abort(msg);
1520 }
1521 }
1522
1531 template <typename T, std::enable_if_t<ppdetail::IsArithmeticOptional_v<T>, int> = 0>
1532 int queryAsDouble (std::string_view name, T& ref) const
1533 {
1534 using value_type = ppdetail::underlying_type_t<T>;
1535 double dref;
1536 int exist = queryWithParser(name, dref);
1537 if (exist) {
1538 if (std::is_integral_v<value_type>) {
1539 dref = std::round(dref);
1540 }
1541 auto vref = static_cast<value_type>(dref);
1542 if constexpr (std::is_integral_v<value_type> && !std::is_same_v<value_type,bool>) {
1543 if (static_cast<double>(vref) != dref) {
1544 amrex::Abort("ParmParse:: queryAsDouble is not safe");
1545 }
1546 }
1547 ref = vref;
1548 }
1549 return exist;
1550 }
1551
1560 template <typename T, std::enable_if_t<ppdetail::IsArithmeticOptional_v<T>, int> = 0>
1561 int queryarrAsDouble (std::string_view name, int nvals, T* ptr) const
1562 {
1563 using value_type = ppdetail::underlying_type_t<T>;
1564 std::vector<double> dref(nvals);
1565 int exist = queryarrWithParser(name, nvals, dref.data());
1566 if (exist) {
1567 for (int i = 0; i < nvals; ++i) {
1568 if (std::is_integral_v<value_type>) {
1569 dref[i] = std::round(dref[i]);
1570 }
1571 auto vref = static_cast<value_type>(dref[i]);
1572 if constexpr (std::is_integral_v<value_type> && !std::is_same_v<value_type,bool>) {
1573 if (static_cast<double>(vref) != dref[i]) {
1574 amrex::Abort("ParmParse:: queryarrAsDouble is not safe");
1575 }
1576 }
1577 ptr[i] = vref;
1578 }
1579 }
1580 return exist;
1581 }
1582
1591 template <typename T, std::enable_if_t<ppdetail::IsArithmeticOptional_v<T>, int> = 0>
1592 void getAsDouble (std::string_view name, T& ref) const
1593 {
1594 int exist = this->queryAsDouble(name, ref);
1595 if (!exist) {
1596 amrex::Error(std::string("ParmParse::getAsDouble: failed to get ")+std::string(name));
1597 }
1598 }
1599
1608 template <typename T, std::enable_if_t<ppdetail::IsArithmeticOptional_v<T>, int> = 0>
1609 void getarrAsDouble (std::string_view name, int nvals, T* ptr) const
1610 {
1611 int exist = this->queryarrAsDouble(name, nvals, ptr);
1612 if (!exist) {
1613 amrex::Error(std::string("ParmParse::getarrAsDouble: failed to get ")+std::string(name));
1614 }
1615 }
1616
1618 int remove (std::string_view name);
1619
1623 [[nodiscard]] Parser makeParser (std::string const& func,
1624 Vector<std::string> const& vars) const;
1625
1629 [[nodiscard]] IParser makeIParser (std::string const& func,
1630 Vector<std::string> const& vars) const;
1631
1637 int querytable (std::string_view name, std::vector<std::vector<double>>& ref) const;
1638 int querytable (std::string_view name, std::vector<std::vector<float>>& ref) const;
1639 int querytable (std::string_view name, std::vector<std::vector<int>>& ref) const;
1640
1646 template <typename T>
1647 void gettable (std::string_view name, std::vector<std::vector<T>>& ref) const
1648 {
1649 if (this->querytable(name, ref) == 0) {
1650 amrex::ErrorStream() << "ParmParse::gettable: " << name
1651 << " not found in database\n";
1653 amrex::Abort();
1654 }
1655 }
1656
1664 static void Initialize (int argc, char** argv, const char* parfile);
1665 static void Initialize (int argc, char** argv, const std::string& parfile) {
1666 return Initialize(argc, argv, parfile.c_str());
1667 }
1672 static void Finalize ();
1673
1675 static void SetParserPrefix (std::string a_prefix);
1676
1677 static int Verbose ();
1678 static void SetVerbose (int v);
1679
1681 static void dumpTable (std::ostream& os, bool prettyPrint = false);
1682
1685 static void prettyPrintTable (std::ostream& os);
1686
1689 static void prettyPrintUnusedInputs (std::ostream& os);
1690
1693 static void prettyPrintUsedInputs (std::ostream& os);
1694
1696 static void addfile (std::string const& filename);
1697
1698 static bool QueryUnusedInputs ();
1699
1701 [[nodiscard]] static bool hasUnusedInputs (const std::string& prefix = std::string());
1702
1704 [[nodiscard]] static std::vector<std::string> getUnusedInputs (const std::string& prefix = std::string());
1705
1707 [[nodiscard]] static std::set<std::string> getEntries (const std::string& prefix = std::string());
1708
1709 struct PP_entry {
1710 // There can be multiple occurrences for a given name (e.g.,
1711 // multiple lines starting with `foo =` in inputs. For each
1712 // occurrence, there can be multiple values. Thus, the use of
1713 // vector<vector<std::string>>.
1714 std::vector<std::vector<std::string>> m_vals;
1715 mutable Long m_count = 0;
1716 mutable std::variant<
1717 std::string*,
1718 bool*,
1719 int*,
1720 long*,
1721 long long*,
1723 amrex::Box*,
1724 float*,
1725 double*
1726 > m_typehint = static_cast<std::string*>(nullptr);
1727 mutable std::vector<std::variant<bool, int, long, long long, float, double>> m_last_vals;
1728 mutable bool m_parsed = false;
1729 };
1730 using Table = std::unordered_map<std::string, PP_entry>;
1731
1732 [[nodiscard]] const Table& table() const {return *m_table;}
1733
1735 static std::string const FileKeyword;
1736
1737 static std::string ParserPrefix;
1738
1739 [[nodiscard]] std::string const& getPrefix () const;
1740
1741 [[nodiscard]] std::string prefixedName (std::string_view str) const;
1742
1743protected:
1744
1745 std::string m_prefix; // Prefix used in keyword search
1746 std::string m_parser_prefix; // Prefix used by Parser
1748};
1749
1750}
1751
1752#endif /* AMREX_PARMPARSE_H_ */
#define AMREX_ALWAYS_ASSERT(EX)
Definition AMReX_BLassert.H:50
Definition AMReX_IParser.H:59
IParserExecutor< N > compileHost() const
This compiles for CPU only.
Definition AMReX_IParser.H:114
Parse Parameters From Command Line and Input Files.
Definition AMReX_ParmParse.H:346
int queryline(std::string_view name, std::string &ref) const
Definition AMReX_ParmParse.cpp:2219
int countname(std::string_view name) const
Returns the number of times the given name (prepended with prefix) appears in the table.
Definition AMReX_ParmParse.cpp:2234
int queryarrWithParser(std::string_view name, int nvals, std::vector< T > &ref) const
Definition AMReX_ParmParse.H:1149
int queryAdd(std::string_view name, std::vector< T > &ref)
If name is found, the value in the ParmParse database will be stored in the ref argument....
Definition AMReX_ParmParse.H:1066
void getWithParser(std::string_view name, T &ref) const
Get with Parser. If name is found, this uses amrex::Parser to parse the entire list of empty space se...
Definition AMReX_ParmParse.H:1191
void gettable(std::string_view name, std::vector< std::vector< T > > &ref) const
Get vector of vector. It's an error if it is not found. The table (i.e., vector of vector) is in the ...
Definition AMReX_ParmParse.H:1647
int querytable(std::string_view name, std::vector< std::vector< double > > &ref) const
Query vector of vector. The return value indicates whether it's found. The table (i....
Definition AMReX_ParmParse.cpp:2519
int query(std::string_view name, std::array< T, N > &ref) const
Definition AMReX_ParmParse.H:1021
static void prettyPrintTable(std::ostream &os)
Definition AMReX_ParmParse.cpp:1394
void get(std::string_view name, T &ref, int ival=FIRST) const
. Get enum value using given name.
Definition AMReX_ParmParse.H:1341
static void Initialize(int argc, char **argv, const char *parfile)
Construct an initial ParmParse object from the argc and argv passed in to main(). An error will be si...
Definition AMReX_ParmParse.cpp:1204
void getarr(std::string_view name, std::vector< T > &ref, int start_ix=FIRST, int num_val=ALL) const
Get an array of enum values using given name.
Definition AMReX_ParmParse.H:1386
static void addfile(std::string const &filename)
Add keys and values from a file to the end of the PP table.
Definition AMReX_ParmParse.cpp:1179
static std::string const FileKeyword
keyword for files to load
Definition AMReX_ParmParse.H:1735
void get_enum_sloppy(std::string_view name, T &ref, std::string_view const &ignores, int ival=FIRST) const
. Get enum value using given name.
Definition AMReX_ParmParse.H:1511
static std::string ParserPrefix
Definition AMReX_ParmParse.H:1737
static int Verbose()
Definition AMReX_ParmParse.cpp:1285
static void SetVerbose(int v)
Definition AMReX_ParmParse.cpp:1298
int query(std::string_view name, T &ref, int ival=FIRST) const
. Query enum value using given name.
Definition AMReX_ParmParse.H:1303
void get(const char *new_name, const char *old_name, T &ref)
Get using two names.
Definition AMReX_ParmParse.H:1282
static bool hasUnusedInputs(const std::string &prefix=std::string())
Any unused [prefix.]* parameters?
Definition AMReX_ParmParse.cpp:1236
Parser makeParser(std::string const &func, Vector< std::string > const &vars) const
Definition AMReX_ParmParse.cpp:2437
int queryAdd(std::string_view name, std::string &ref)
Definition AMReX_ParmParse.H:1048
int query_enum_case_insensitive(std::string_view name, T &ref, int ival=FIRST) const
. Query enum value using given name.
Definition AMReX_ParmParse.H:1419
int queryktharr(std::string_view name, int k, std::vector< int > &ref, int start_ix=FIRST, int num_val=ALL) const
queryktharr() is to querykth() as getktharr() is to getkth().
Definition AMReX_ParmParse.cpp:1526
int queryAsDouble(std::string_view name, T &ref) const
Query T with Parser, but treat the number as double precision during parsing.
Definition AMReX_ParmParse.H:1532
static bool QueryUnusedInputs()
Definition AMReX_ParmParse.cpp:1221
void getline(std::string_view name, std::string &ref) const
Definition AMReX_ParmParse.cpp:2211
T eval(std::string const &expr) const
Definition AMReX_ParmParse.H:1248
void getarr(std::string_view name, std::vector< int > &ref, int start_ix=FIRST, int num_val=ALL) const
Same as getktharr() but searches for last occurrence of name.
Definition AMReX_ParmParse.cpp:1517
void getarrWithParser(std::string_view name, int nvals, T *ptr) const
Get with Parser. If name is not found, it's a runtime error. If the number of elements does not equal...
Definition AMReX_ParmParse.H:1210
void getkth(std::string_view name, int k, bool &ref, int ival=FIRST) const
Get the ival'th value of kth occurrence of the requested name. If successful, the value is converted ...
Definition AMReX_ParmParse.cpp:1424
void getAsDouble(std::string_view name, T &ref) const
Get T with Parser, but treat the number as double precision during parsing.
Definition AMReX_ParmParse.H:1592
bool contains(std::string_view name) const
Returns true if name is in table.
Definition AMReX_ParmParse.cpp:2250
int queryarrAsDouble(std::string_view name, int nvals, T *ptr) const
Query T array with Parser, but treat the number as double precision during parsing.
Definition AMReX_ParmParse.H:1561
void get(std::string_view name, std::array< T, N > &ref) const
Definition AMReX_ParmParse.H:1011
static void prettyPrintUsedInputs(std::ostream &os)
Definition AMReX_ParmParse.cpp:1406
static void Finalize()
The destructor. The internal static table will only be deleted if there are no other ParmParse object...
Definition AMReX_ParmParse.cpp:1304
int queryAdd(std::string_view name, std::vector< T > &ref, int num_val)
If name is found, the value in the ParmParse database will be stored in the ref argument....
Definition AMReX_ParmParse.H:1085
std::string m_prefix
Definition AMReX_ParmParse.H:1745
const Table & table() const
Definition AMReX_ParmParse.H:1732
int queryAddWithParser(std::string_view name, T &ref)
Query with Parser. If name is found, this uses amrex::Parser to parse the entire list of empty space ...
Definition AMReX_ParmParse.H:1171
int querykth(std::string_view name, int k, bool &ref, int ival=FIRST) const
Similar to getkth() but returns 0 if there is no kth occurrence of name. If successful,...
Definition AMReX_ParmParse.cpp:1441
static void SetParserPrefix(std::string a_prefix)
Set prefix used by math expression Parser.
Definition AMReX_ParmParse.cpp:1331
int queryWithParser(std::string_view name, bool &ref) const
Query with Parser. If name is found, this uses amrex::Parser to parse the entire list of empty space ...
Definition AMReX_ParmParse.cpp:2365
static std::vector< std::string > getUnusedInputs(const std::string &prefix=std::string())
Returns unused [prefix.]* parameters.
Definition AMReX_ParmParse.cpp:1242
int queryAdd(std::string_view name, T &ref)
If name is found, the value in the ParmParse database will be stored in the ref argument....
Definition AMReX_ParmParse.H:1040
void addarr(std::string_view name, const std::vector< int > &ref)
Add a key 'name' with vector of values 'ref' to the end of the PP table.
Definition AMReX_ParmParse.cpp:1545
std::string const & getPrefix() const
Definition AMReX_ParmParse.cpp:1159
int remove(std::string_view name)
Remove given name from the table.
Definition AMReX_ParmParse.cpp:2266
int queryarr(std::string_view name, std::vector< int > &ref, int start_ix=FIRST, int num_val=ALL) const
Same as queryktharr() but searches for last occurrence of name.
Definition AMReX_ParmParse.cpp:1536
@ FIRST
Definition AMReX_ParmParse.H:348
@ LAST
Definition AMReX_ParmParse.H:348
@ ALL
Definition AMReX_ParmParse.H:348
void add(std::string_view name, T const &val)
Definition AMReX_ParmParse.H:1326
int queryarr(std::string_view name, std::vector< T > &ref, int start_ix=FIRST, int num_val=ALL) const
Query an array of enum values using given name.
Definition AMReX_ParmParse.H:1359
static void Initialize(int argc, char **argv, const std::string &parfile)
Definition AMReX_ParmParse.H:1665
int queryAdd(std::string_view name, std::array< T, N > &ref)
If name is found, the value in the ParmParse database will be stored in the ref argument....
Definition AMReX_ParmParse.H:1100
int query(const char *new_name, const char *old_name, T &ref)
Definition AMReX_ParmParse.H:1268
Table * m_table
Definition AMReX_ParmParse.H:1747
int queryarrWithParser(std::string_view name, int nvals, bool *ptr) const
Query with Parser. The return value indicates whether it's found. Note that queryWithParser will be u...
Definition AMReX_ParmParse.cpp:2401
void getarrAsDouble(std::string_view name, int nvals, T *ptr) const
Get T array with Parser, but treat the number as double precision during parsing.
Definition AMReX_ParmParse.H:1609
std::string m_parser_prefix
Definition AMReX_ParmParse.H:1746
void add(std::string_view name, bool val)
Add a key 'name' with value 'val' to the end of the PP table.
Definition AMReX_ParmParse.cpp:1458
void get_enum_case_insensitive(std::string_view name, T &ref, int ival=FIRST) const
. Get enum value using given name.
Definition AMReX_ParmParse.H:1449
static void dumpTable(std::ostream &os, bool prettyPrint=false)
Write the contents of the table in ASCII to the ostream.
Definition AMReX_ParmParse.cpp:1337
void getktharr(std::string_view name, int k, std::vector< int > &ref, int start_ix=FIRST, int num_val=ALL) const
Gets an std::vector<int> of num_val values from kth occurrence of given name. If successful,...
Definition AMReX_ParmParse.cpp:1507
static void prettyPrintUnusedInputs(std::ostream &os)
Definition AMReX_ParmParse.cpp:1400
static std::set< std::string > getEntries(const std::string &prefix=std::string())
Returns [prefix.]* parameters.
Definition AMReX_ParmParse.cpp:1272
std::string prefixedName(std::string_view str) const
Definition AMReX_ParmParse.cpp:1165
void getarrWithParser(std::string_view name, int nvals, std::vector< T > &ref) const
Get with Parser. If name is not found, it's a runtime error. If the number of elements does not equal...
Definition AMReX_ParmParse.H:1229
int query(std::string_view name, bool &ref, int ival=FIRST) const
Same as querykth() but searches for the last occurrence of name.
Definition AMReX_ParmParse.cpp:1450
int query_enum_sloppy(std::string_view name, T &ref, std::string_view const &ignores, int ival=FIRST) const
. Query enum value using given name.
Definition AMReX_ParmParse.H:1474
void get(std::string_view name, bool &ref, int ival=FIRST) const
Same as getkth() but searches for the last occurrence of name.
Definition AMReX_ParmParse.cpp:1433
std::unordered_map< std::string, PP_entry > Table
Definition AMReX_ParmParse.H:1730
IParser makeIParser(std::string const &func, Vector< std::string > const &vars) const
Definition AMReX_ParmParse.cpp:2444
int countval(std::string_view name, int n=LAST) const
Returns the number of values associated with nth occurrence of name (prepended with the prefix) in th...
Definition AMReX_ParmParse.cpp:1412
Definition AMReX_Parser.H:71
ParserExecutor< N > compileHost() const
This compiles for CPU only.
Definition AMReX_Parser.H:146
This class provides the user with a few print options.
Definition AMReX_Print.H:35
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:28
amrex_long Long
Definition AMReX_INT.H:30
Definition AMReX_Amr.cpp:49
std::ostream & ErrorStream()
Definition AMReX.cpp:931
std::string getEnumNameString(T const &v)
Definition AMReX_Enum.H:156
BoxND< 3 > Box
Box is an alias for amrex::BoxND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:30
__host__ __device__ RealVectND(Real, Real, Args...) -> RealVectND< sizeof...(Args)+2 >
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:33
void Error(const std::string &msg)
Print out message to cerr and exit via amrex::Abort().
Definition AMReX.cpp:224
__host__ __device__ IntVectND(const Array< int, dim > &) -> IntVectND< dim >
int Verbose() noexcept
Definition AMReX.cpp:169
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition AMReX.cpp:230
Definition AMReX_ParmParse.H:1709
std::variant< std::string *, bool *, int *, long *, long long *, amrex::IntVect *, amrex::Box *, float *, double * > m_typehint
Definition AMReX_ParmParse.H:1726
std::vector< std::vector< std::string > > m_vals
Definition AMReX_ParmParse.H:1714
Long m_count
Definition AMReX_ParmParse.H:1715
std::vector< std::variant< bool, int, long, long long, float, double > > m_last_vals
Definition AMReX_ParmParse.H:1727
bool m_parsed
Definition AMReX_ParmParse.H:1728