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
348{
349public:
350 enum { LAST = -1, FIRST = 0, ALL = -1 };
358 explicit ParmParse (std::string prefix = std::string(),
359 std::string parser_prefix = std::string());
360
362 [[nodiscard]] bool contains (std::string_view name) const;
368 [[nodiscard]] int countval (std::string_view name, int n = LAST) const;
373 [[nodiscard]] int countname (std::string_view name) const;
385 void getkth (std::string_view name,
386 int k,
387 bool& ref,
388 int ival = FIRST) const;
390 void get (std::string_view name,
391 bool& ref,
392 int ival = FIRST) const;
400 int querykth (std::string_view name,
401 int k,
402 bool& ref,
403 int ival = FIRST) const;
405 int query (std::string_view name,
406 bool& ref,
407 int ival = FIRST) const;
409 void add (std::string_view name, bool val);
419 void getkth (std::string_view name,
420 int k,
421 int& ref,
422 int ival = FIRST) const;
423
425 void get (std::string_view name,
426 int& ref,
427 int ival = FIRST) const;
435 int querykth (std::string_view name,
436 int k,
437 int& ref,
438 int ival = FIRST) const;
440 int query (std::string_view name,
441 int& ref,
442 int ival = FIRST) const;
444 void add (std::string_view name, int val);
454 void getkth (std::string_view name,
455 int k,
456 long& ref,
457 int ival = FIRST) const;
459 void get (std::string_view name,
460 long& ref,
461 int ival = FIRST) const;
469 int querykth (std::string_view name,
470 int k,
471 long& ref,
472 int ival = FIRST) const;
474 int query (std::string_view name,
475 long& ref,
476 int ival = FIRST) const;
478 void add (std::string_view name, long val);
488 void getkth (std::string_view name,
489 int k,
490 long long& ref,
491 int ival = FIRST) const;
493 void get (std::string_view name,
494 long long& ref,
495 int ival = FIRST) const;
503 int querykth (std::string_view name,
504 int k,
505 long long& ref,
506 int ival = FIRST) const;
508 int query (std::string_view name,
509 long long& ref,
510 int ival = FIRST) const;
512 void add (std::string_view name, long long val);
522 void getkth (std::string_view name,
523 int k,
524 float& ref,
525 int ival = FIRST) const;
527 void get (std::string_view name,
528 float& ref,
529 int ival = FIRST) const;
537 int querykth (std::string_view name,
538 int k,
539 float& ref,
540 int ival = FIRST) const;
542 int query (std::string_view name,
543 float& ref,
544 int ival = FIRST) const;
546 void add (std::string_view name, float val);
556 void getkth (std::string_view name,
557 int k,
558 double& ref,
559 int ival = FIRST) const;
561 void get (std::string_view name,
562 double& ref,
563 int ival = FIRST) const;
571 int querykth (std::string_view name,
572 int k,
573 double& ref,
574 int ival = FIRST) const;
576 int query (std::string_view name,
577 double& ref,
578 int ival = FIRST) const;
580 void add (std::string_view name, double val);
590 void getkth (std::string_view name,
591 int k,
592 std::string& ref,
593 int ival = FIRST) const;
594
596 void get (std::string_view name,
597 std::string& ref,
598 int ival = FIRST) const;
606 int querykth (std::string_view name,
607 int k,
608 std::string& ref,
609 int ival = FIRST) const;
611 int query (std::string_view name,
612 std::string& ref,
613 int ival = FIRST) const;
615 void add (std::string_view name, const std::string& val);
616
618 void add (std::string_view name, const char* val) { add(name, std::string(val)); }
619
628 void getline (std::string_view name, std::string& ref) const;
629
638 int queryline (std::string_view name, std::string& ref) const;
639
649 void getkth (std::string_view name,
650 int k,
651 IntVect& ref,
652 int ival = FIRST) const;
654 void get (std::string_view name,
655 IntVect& ref,
656 int ival = FIRST) const;
664 int querykth (std::string_view name,
665 int k,
666 IntVect& ref,
667 int ival = FIRST) const;
669 int query (std::string_view name,
670 IntVect& ref,
671 int ival = FIRST) const;
673 void add (std::string_view name, const IntVect& val);
683 void getkth (std::string_view name,
684 int k,
685 Box& ref,
686 int ival = FIRST) const;
688 void get (std::string_view name,
689 Box& ref,
690 int ival = FIRST) const;
698 int querykth (std::string_view name,
699 int k,
700 Box& ref,
701 int ival = FIRST) const;
703 int query (std::string_view name,
704 Box& ref,
705 int ival = FIRST) const;
707 void add (std::string_view name, const Box& val);
720 void getktharr (std::string_view name,
721 int k,
722 std::vector<int>& ref,
723 int start_ix = FIRST,
724 int num_val = ALL) const;
726 void getarr (std::string_view name,
727 std::vector<int>& ref,
728 int start_ix = FIRST,
729 int num_val = ALL) const;
731 int queryktharr (std::string_view name,
732 int k,
733 std::vector<int>& ref,
734 int start_ix = FIRST,
735 int num_val = ALL) const;
737 int queryarr (std::string_view name,
738 std::vector<int>& ref,
739 int start_ix = FIRST,
740 int num_val = ALL) const;
742 void addarr (std::string_view name, const std::vector<int>& ref);
743
756 void getktharr (std::string_view name,
757 int k,
758 std::vector<long>& ref,
759 int start_ix = FIRST,
760 int num_val = ALL) const;
762 void getarr (std::string_view name,
763 std::vector<long>& ref,
764 int start_ix = FIRST,
765 int num_val = ALL) const;
767 int queryktharr (std::string_view name,
768 int k,
769 std::vector<long>& ref,
770 int start_ix = FIRST,
771 int num_val = ALL) const;
773 int queryarr (std::string_view name,
774 std::vector<long>& ref,
775 int start_ix = FIRST,
776 int num_val = ALL) const;
778 void addarr (std::string_view name, const std::vector<long>& ref);
779
792 void getktharr (std::string_view name,
793 int k,
794 std::vector<long long>& ref,
795 int start_ix = FIRST,
796 int num_val = ALL) const;
798 void getarr (std::string_view name,
799 std::vector<long long>& ref,
800 int start_ix = FIRST,
801 int num_val = ALL) const;
803 int queryktharr (std::string_view name,
804 int k,
805 std::vector<long long>& ref,
806 int start_ix = FIRST,
807 int num_val = ALL) const;
809 int queryarr (std::string_view name,
810 std::vector<long long>& ref,
811 int start_ix = FIRST,
812 int num_val = ALL) const;
814 void addarr (std::string_view name, const std::vector<long long>& ref);
815
828 void getktharr (std::string_view name,
829 int k,
830 std::vector<float>& ref,
831 int start_ix = FIRST,
832 int num_val = ALL) const;
834 void getarr (std::string_view name,
835 std::vector<float>& ref,
836 int start_ix = FIRST,
837 int num_val = ALL) const;
839 int queryktharr (std::string_view name,
840 int k,
841 std::vector<float>& ref,
842 int start_ix = FIRST,
843 int num_val = ALL) const;
845 int queryarr (std::string_view name,
846 std::vector<float>& ref,
847 int start_ix = FIRST,
848 int num_val = ALL) const;
850 void addarr (std::string_view name, const std::vector<float>& ref);
863 void getktharr (std::string_view name,
864 int k,
865 std::vector<double>& ref,
866 int start_ix = FIRST,
867 int num_val = ALL) const;
869 void getarr (std::string_view name,
870 std::vector<double>& ref,
871 int start_ix = FIRST,
872 int num_val = ALL) const;
874 int queryktharr (std::string_view name,
875 int k,
876 std::vector<double>& ref,
877 int start_ix = FIRST,
878 int num_val = ALL) const;
880 int queryarr (std::string_view name,
881 std::vector<double>& ref,
882 int start_ix = FIRST,
883 int num_val = ALL) const;
885 void addarr (std::string_view name, const std::vector<double>& ref);
898 void getktharr (std::string_view name,
899 int k,
900 std::vector<std::string>& ref,
901 int start_ix = FIRST,
902 int num_val = ALL) const;
904 void getarr (std::string_view name,
905 std::vector<std::string>& ref,
906 int start_ix = FIRST,
907 int num_val = ALL) const;
909 int queryktharr (std::string_view name,
910 int k,
911 std::vector<std::string>& ref,
912 int start_ix = FIRST,
913 int num_val = ALL) const;
915 int queryarr (std::string_view name,
916 std::vector<std::string>& ref,
917 int start_ix = FIRST,
918 int num_val = ALL) const;
920 void addarr (std::string_view name, const std::vector<std::string>& ref);
933 void getktharr (std::string_view name,
934 int k,
935 std::vector<IntVect>& ref,
936 int start_ix = FIRST,
937 int num_val = ALL) const;
939 void getarr (std::string_view name,
940 std::vector<IntVect>& ref,
941 int start_ix = FIRST,
942 int num_val = ALL) const;
944 int queryktharr (std::string_view name,
945 int k,
946 std::vector<IntVect>& ref,
947 int start_ix = FIRST,
948 int num_val = ALL) const;
950 int queryarr (std::string_view name,
951 std::vector<IntVect>& ref,
952 int start_ix = FIRST,
953 int num_val = ALL) const;
955 void addarr (std::string_view name, const std::vector<IntVect>& ref);
968 void getktharr (std::string_view name,
969 int k,
970 std::vector<Box>& ref,
971 int start_ix = FIRST,
972 int num_val = ALL) const;
974 void getarr (std::string_view name,
975 std::vector<Box>& ref,
976 int start_ix = FIRST,
977 int num_val = ALL) const;
979 int queryktharr (std::string_view name,
980 int k,
981 std::vector<Box>& ref,
982 int start_ix = FIRST,
983 int num_val = ALL) const;
985 int queryarr (std::string_view name,
986 std::vector<Box>& ref,
987 int start_ix = FIRST,
988 int num_val = ALL) const;
990 void addarr (std::string_view name, const std::vector<Box>& ref);
991
992 /*
993 * \brief Query IntVect from array
994 *
995 * This reads IntVect from an array (e.g., `8 16 8`), not the format
996 * using parentheses (e.g., `(8,16,8)`).
997 */
998 int queryarr (std::string_view name, IntVect& ref) const;
999
1000 /*
1001 * \brief Get IntVect from array
1002 *
1003 * This reads IntVect from an array (e.g., `8 16 8`), not the format
1004 * using parentheses (e.g., `(8,16,8)`).
1005 */
1006 void getarr (std::string_view name, IntVect& ref) const;
1007
1009 int queryarr (std::string_view name, RealVect& ref) const;
1010
1012 void getarr (std::string_view name, RealVect& ref) const;
1013
1014 template <typename T, std::size_t N>
1015 void get (std::string_view name, std::array<T,N>& ref) const {
1016 std::vector<T> v;
1017 this->getarr(name, v);
1018 AMREX_ALWAYS_ASSERT(v.size() >= N);
1019 for (std::size_t i = 0; i < N; ++i) {
1020 ref[i] = v[i];
1021 }
1022 }
1023
1024 template <typename T, std::size_t N>
1025 int query (std::string_view name, std::array<T,N>& ref) const {
1026 std::vector<T> v;
1027 int exist = this->queryarr(name, v);
1028 if (exist) {
1029 AMREX_ALWAYS_ASSERT(v.size() >= N);
1030 for (std::size_t i = 0; i < N; ++i) {
1031 ref[i] = v[i];
1032 }
1033 }
1034 return exist;
1035 }
1036
1043 template <typename T, std::enable_if_t<!IsStdVector<T>::value, int> = 0>
1044 int queryAdd (std::string_view name, T& ref) {
1045 int exist = this->query(name, ref);
1046 if (!exist) {
1047 this->add(name, ref);
1048 }
1049 return exist;
1050 }
1051
1052 int queryAdd (std::string_view name, std::string& ref) {
1053 int exist = this->query(name, ref);
1054 if (!exist && !ref.empty()) {
1055 this->add(name, ref);
1056 }
1057 return exist;
1058 }
1059
1069 template <typename T>
1070 int queryAdd (std::string_view name, std::vector<T>& ref) {
1071 std::vector<T> empty;
1072 int exist = this->queryarr(name, empty);
1073 if (exist) {
1074 ref = std::move(empty);
1075 }
1076 if (!exist && !ref.empty()) {
1077 this->addarr(name, ref);
1078 }
1079 return exist;
1080 }
1081
1088 template <typename T>
1089 int queryAdd (std::string_view name, std::vector<T>& ref, int num_val) {
1090 int exist = this->queryarr(name, ref, 0, num_val);
1091 if (!exist) {
1092 this->addarr(name, ref);
1093 }
1094 return exist;
1095 }
1096
1103 template <typename T, std::size_t N>
1104 int queryAdd (std::string_view name, std::array<T,N>& ref) {
1105 std::vector<T> v;
1106 int exist = this->queryarr(name, v);
1107 if (exist) {
1108 AMREX_ALWAYS_ASSERT(v.size() >= N);
1109 for (std::size_t i = 0; i < N; ++i) {
1110 ref[i] = v[i];
1111 }
1112 } else {
1113 v.resize(N);
1114 for (std::size_t i = 0; i < N; ++i) {
1115 v[i] = ref[i];
1116 }
1117 this->addarr(name, v);
1118 }
1119 return exist;
1120 }
1121
1128 int queryWithParser (std::string_view name, bool& ref) const;
1129 int queryWithParser (std::string_view name, int& ref) const;
1130 int queryWithParser (std::string_view name, long& ref) const;
1131 int queryWithParser (std::string_view name, long long& ref) const;
1132 int queryWithParser (std::string_view name, float& ref) const;
1133 int queryWithParser (std::string_view name, double& ref) const;
1134
1141 int queryarrWithParser (std::string_view name, int nvals, bool* ptr) const;
1142 int queryarrWithParser (std::string_view name, int nvals, int* ptr) const;
1143 int queryarrWithParser (std::string_view name, int nvals, long* ptr) const;
1144 int queryarrWithParser (std::string_view name, int nvals, long long* ptr) const;
1145 int queryarrWithParser (std::string_view name, int nvals, float* ptr) const;
1146 int queryarrWithParser (std::string_view name, int nvals, double* ptr) const;
1147 template <typename T, std::enable_if_t<std::is_same_v<T,bool> ||
1148 std::is_same_v<T,int> ||
1149 std::is_same_v<T,long> ||
1150 std::is_same_v<T,long long> ||
1151 std::is_same_v<T,float> ||
1152 std::is_same_v<T,double>,int> = 0>
1153 int queryarrWithParser (std::string_view name, int nvals, std::vector<T>& ref) const
1154 {
1155 if (this->contains(name)) {
1156 if (int(ref.size()) < nvals) { ref.resize(nvals); }
1157 return this->queryarrWithParser(name, nvals, ref.data());
1158 } else {
1159 return 0;
1160 }
1161 }
1162
1169 template <typename T, std::enable_if_t<std::is_same_v<T,bool> ||
1170 std::is_same_v<T,int> ||
1171 std::is_same_v<T,long> ||
1172 std::is_same_v<T,long long> ||
1173 std::is_same_v<T,float> ||
1174 std::is_same_v<T,double>,int> = 0>
1175 int queryAddWithParser (std::string_view name, T& ref)
1176 {
1177 int exist = this->queryWithParser(name, ref);
1178 if (!exist) {
1179 this->add(name, ref);
1180 }
1181 return exist;
1182 }
1183
1189 template <typename T, std::enable_if_t<std::is_same_v<T,bool> ||
1190 std::is_same_v<T,int> ||
1191 std::is_same_v<T,long> ||
1192 std::is_same_v<T,long long> ||
1193 std::is_same_v<T,float> ||
1194 std::is_same_v<T,double>,int> = 0>
1195 void getWithParser (std::string_view name, T& ref) const
1196 {
1197 int exist = this->queryWithParser(name, ref);
1198 if (!exist) {
1199 amrex::Error(std::string("ParmParse::getWithParser: failed to get ")+std::string(name));
1200 }
1201 }
1202
1208 template <typename T, std::enable_if_t<std::is_same_v<T,bool> ||
1209 std::is_same_v<T,int> ||
1210 std::is_same_v<T,long> ||
1211 std::is_same_v<T,long long> ||
1212 std::is_same_v<T,float> ||
1213 std::is_same_v<T,double>,int> = 0>
1214 void getarrWithParser (std::string_view name, int nvals, T* ptr) const
1215 {
1216 int exist = this->queryarrWithParser(name, nvals, ptr);
1217 if (!exist) {
1218 amrex::Error(std::string("ParmParse::getarrWithParser: failed to get ")+std::string(name));
1219 }
1220 }
1221
1227 template <typename T, std::enable_if_t<std::is_same_v<T,bool> ||
1228 std::is_same_v<T,int> ||
1229 std::is_same_v<T,long> ||
1230 std::is_same_v<T,long long> ||
1231 std::is_same_v<T,float> ||
1232 std::is_same_v<T,double>,int> = 0>
1233 void getarrWithParser (std::string_view name, int nvals, std::vector<T>& ref) const
1234 {
1235 int exist = this->queryarrWithParser(name, nvals, ref);
1236 if (!exist) {
1237 amrex::Error(std::string("ParmParse::getarrWithParser: failed to get ")+std::string(name));
1238 }
1239 }
1240
1241 /*
1242 * \brief Evaluate given string as math expression
1243 *
1244 * For unknown symbols, ParmParse database will be queried.
1245 */
1246 template <typename T, std::enable_if_t<std::is_same_v<T,bool> ||
1247 std::is_same_v<T,int> ||
1248 std::is_same_v<T,long> ||
1249 std::is_same_v<T,long long> ||
1250 std::is_same_v<T,float> ||
1251 std::is_same_v<T,double>,int> = 0>
1252 T eval (std::string const& expr) const
1253 {
1254 if constexpr (std::is_integral_v<T>) {
1255 auto const parser = this->makeIParser(expr, {});
1256 auto const exe = parser.compileHost<0>();
1257 return static_cast<T>(exe()); // In the future, we might add safety check.
1258 } else {
1259 auto const parser = this->makeParser(expr, {});
1260 auto const exe = parser.compileHost<0>();
1261 return static_cast<T>(exe());
1262 }
1263 }
1264
1265 /*
1266 * \brief Query two names.
1267 *
1268 * This function queries with `new_name` first. If it's not found, it
1269 * will try again with `old_name`.
1270 */
1271 template <typename T>
1272 int query (const char* new_name, const char* old_name, T& ref)
1273 {
1274 return (this->query(new_name, ref) ||
1275 this->query(old_name, ref));
1276 }
1277
1285 template <typename T>
1286 void get (const char* new_name, const char* old_name, T& ref)
1287 {
1288 auto exist = this->query(new_name, old_name, ref);
1289 if (!exist) {
1290 amrex::ErrorStream() << "ParmParse::get failed to find "
1291 << new_name << " and " << old_name << '\n';
1293 amrex::Abort();
1294 }
1295 }
1296
1305 template <typename T, typename ET = amrex_enum_traits<T>,
1306 std::enable_if_t<ET::value,int> = 0>
1307 int query (std::string_view name, T& ref, int ival = FIRST) const
1308 {
1309 std::string s;
1310 int exist = this->query(name, s, ival);
1311 if (exist) {
1312 try {
1313 ref = amrex::getEnum<T>(s);
1314 } catch (...) {
1315 if (amrex::Verbose() > 0 ) {
1316 amrex::Print() << "amrex::ParmParse::query (input name: "
1317 << this->prefixedName(name) << "):\n";
1318 }
1319 throw;
1320 }
1321 }
1322 return exist;
1323 }
1324
1325
1328 template <typename T, typename ET = amrex_enum_traits<T>,
1329 std::enable_if_t<ET::value,int> = 0>
1330 void add (std::string_view name, T const& val)
1331 {
1332 this->add(name, amrex::getEnumNameString(val));
1333 }
1334
1343 template <typename T, typename ET = amrex_enum_traits<T>,
1344 std::enable_if_t<ET::value,int> = 0>
1345 void get (std::string_view name, T& ref, int ival = FIRST) const
1346 {
1347 std::string s;
1348 this->get(name, s, ival);
1349 try {
1350 ref = amrex::getEnum<T>(s);
1351 } catch (...) {
1352 if (amrex::Verbose() > 0 ) {
1353 amrex::Print() << "amrex::ParmParse::get (input name: "
1354 << this->prefixedName(name) << "):\n";
1355 }
1356 throw;
1357 }
1358 }
1359
1361 template <typename T, typename ET = amrex_enum_traits<T>,
1362 std::enable_if_t<ET::value,int> = 0>
1363 int queryarr (std::string_view name,
1364 std::vector<T>& ref,
1365 int start_ix = FIRST,
1366 int num_val = ALL) const
1367 {
1368 std::vector<std::string> s;
1369 int exist = this->queryarr(name, s, start_ix, num_val);
1370 if (exist) {
1371 ref.resize(s.size());
1372 for (std::size_t i = 0; i < s.size(); ++i) {
1373 try {
1374 ref[i] = amrex::getEnum<T>(s[i]);
1375 } catch (...) {
1376 if (amrex::Verbose() > 0 ) {
1377 amrex::Print() << "amrex::ParmParse::queryarr (input name: "
1378 << this->prefixedName(name) << "):\n";
1379 }
1380 throw;
1381 }
1382 }
1383 }
1384 return exist;
1385 }
1386
1388 template <typename T, typename ET = amrex_enum_traits<T>,
1389 std::enable_if_t<ET::value,int> = 0>
1390 void getarr (std::string_view name,
1391 std::vector<T>& ref,
1392 int start_ix = FIRST,
1393 int num_val = ALL) const
1394 {
1395 std::vector<std::string> s;
1396 this->getarr(name, s, start_ix, num_val);
1397 ref.resize(s.size());
1398 for (std::size_t i = 0; i < s.size(); ++i) {
1399 try {
1400 ref[i] = amrex::getEnum<T>(s[i]);
1401 } catch (...) {
1402 if (amrex::Verbose() > 0 ) {
1403 amrex::Print() << "amrex::ParmParse::getarr (input name: "
1404 << this->prefixedName(name) << "):\n";
1405 }
1406 throw;
1407 }
1408 }
1409 }
1410
1421 template <typename T, typename ET = amrex_enum_traits<T>,
1422 std::enable_if_t<ET::value,int> = 0>
1423 int query_enum_case_insensitive (std::string_view name, T& ref, int ival = FIRST) const
1424 {
1425 std::string s;
1426 int exist = this->query(name, s, ival);
1427 if (exist) {
1428 try {
1429 ref = amrex::getEnumCaseInsensitive<T>(s);
1430 } catch (...) {
1431 if (amrex::Verbose() > 0) {
1432 amrex::Print() << "amrex::ParmParse::query_enum_case_insensitive (input name: "
1433 << this->prefixedName(name) << "):\n";
1434 }
1435 throw;
1436 }
1437 }
1438 return exist;
1439 }
1440
1451 template <typename T, typename ET = amrex_enum_traits<T>,
1452 std::enable_if_t<ET::value,int> = 0>
1453 void get_enum_case_insensitive (std::string_view name, T& ref, int ival = FIRST) const
1454 {
1455 int exist = this->query_enum_case_insensitive(name, ref, ival);
1456 if (!exist) {
1457 std::string msg("get_enum_case_insensitive(\"");
1458 msg.append(name).append("\",").append(amrex::getEnumClassName<T>())
1459 .append("&) failed.");
1460 amrex::Abort(msg);
1461 }
1462 }
1463
1476 template <typename T, typename ET = amrex_enum_traits<T>,
1477 std::enable_if_t<ET::value,int> = 0>
1478 int query_enum_sloppy (std::string_view name, T& ref, std::string_view const& ignores,
1479 int ival = FIRST) const
1480 {
1481 std::string s;
1482 int exist = this->query(name, s, ival);
1483 if (exist) {
1484 try {
1485 s.erase(std::remove_if(s.begin(), s.end(),
1486 [&] (auto const& c) {
1487 return ignores.find(c) != std::string_view::npos; }),
1488 s.end());
1489 ref = amrex::getEnumCaseInsensitive<T>(s);
1490 } catch (...) {
1491 if (amrex::Verbose() > 0) {
1492 amrex::Print() << "amrex::ParmParse::query_enum_sloppy (input name: "
1493 << this->prefixedName(name) << "):\n";
1494 }
1495 throw;
1496 }
1497 }
1498 return exist;
1499 }
1500
1513 template <typename T, typename ET = amrex_enum_traits<T>,
1514 std::enable_if_t<ET::value,int> = 0>
1515 void get_enum_sloppy (std::string_view name, T& ref, std::string_view const& ignores,
1516 int ival = FIRST) const
1517 {
1518 int exist = this->query_enum_sloppy(name, ref, ignores, ival);
1519 if (!exist) {
1520 std::string msg("get_enum_sloppy(\"");
1521 msg.append(name).append("\",").append(amrex::getEnumClassName<T>())
1522 .append("&) failed.");
1523 amrex::Abort(msg);
1524 }
1525 }
1526
1535 template <typename T, std::enable_if_t<ppdetail::IsArithmeticOptional_v<T>, int> = 0>
1536 int queryAsDouble (std::string_view name, T& ref) const
1537 {
1538 using value_type = ppdetail::underlying_type_t<T>;
1539 double dref;
1540 int exist = queryWithParser(name, dref);
1541 if (exist) {
1542 if (std::is_integral_v<value_type>) {
1543 dref = std::round(dref);
1544 }
1545 auto vref = static_cast<value_type>(dref);
1546 if constexpr (std::is_integral_v<value_type> && !std::is_same_v<value_type,bool>) {
1547 if (static_cast<double>(vref) != dref) {
1548 amrex::Abort("ParmParse:: queryAsDouble is not safe");
1549 }
1550 }
1551 ref = vref;
1552 }
1553 return exist;
1554 }
1555
1564 template <typename T, std::enable_if_t<ppdetail::IsArithmeticOptional_v<T>, int> = 0>
1565 int queryarrAsDouble (std::string_view name, int nvals, T* ptr) const
1566 {
1567 using value_type = ppdetail::underlying_type_t<T>;
1568 std::vector<double> dref(nvals);
1569 int exist = queryarrWithParser(name, nvals, dref.data());
1570 if (exist) {
1571 for (int i = 0; i < nvals; ++i) {
1572 if (std::is_integral_v<value_type>) {
1573 dref[i] = std::round(dref[i]);
1574 }
1575 auto vref = static_cast<value_type>(dref[i]);
1576 if constexpr (std::is_integral_v<value_type> && !std::is_same_v<value_type,bool>) {
1577 if (static_cast<double>(vref) != dref[i]) {
1578 amrex::Abort("ParmParse:: queryarrAsDouble is not safe");
1579 }
1580 }
1581 ptr[i] = vref;
1582 }
1583 }
1584 return exist;
1585 }
1586
1595 template <typename T, std::enable_if_t<ppdetail::IsArithmeticOptional_v<T>, int> = 0>
1596 void getAsDouble (std::string_view name, T& ref) const
1597 {
1598 int exist = this->queryAsDouble(name, ref);
1599 if (!exist) {
1600 amrex::Error(std::string("ParmParse::getAsDouble: failed to get ")+std::string(name));
1601 }
1602 }
1603
1612 template <typename T, std::enable_if_t<ppdetail::IsArithmeticOptional_v<T>, int> = 0>
1613 void getarrAsDouble (std::string_view name, int nvals, T* ptr) const
1614 {
1615 int exist = this->queryarrAsDouble(name, nvals, ptr);
1616 if (!exist) {
1617 amrex::Error(std::string("ParmParse::getarrAsDouble: failed to get ")+std::string(name));
1618 }
1619 }
1620
1622 int remove (std::string_view name);
1623
1627 [[nodiscard]] Parser makeParser (std::string const& func,
1628 Vector<std::string> const& vars) const;
1629
1633 [[nodiscard]] IParser makeIParser (std::string const& func,
1634 Vector<std::string> const& vars) const;
1635
1641 int querytable (std::string_view name, std::vector<std::vector<double>>& ref) const;
1642 int querytable (std::string_view name, std::vector<std::vector<float>>& ref) const;
1643 int querytable (std::string_view name, std::vector<std::vector<int>>& ref) const;
1644
1650 template <typename T>
1651 void gettable (std::string_view name, std::vector<std::vector<T>>& ref) const
1652 {
1653 if (this->querytable(name, ref) == 0) {
1654 amrex::ErrorStream() << "ParmParse::gettable: " << name
1655 << " not found in database\n";
1657 amrex::Abort();
1658 }
1659 }
1660
1668 static void Initialize (int argc, char** argv, const char* parfile);
1669 static void Initialize (int argc, char** argv, const std::string& parfile) {
1670 Initialize(argc, argv, parfile.c_str());
1671 }
1676 static void Finalize ();
1677
1679 static void SetParserPrefix (std::string a_prefix);
1680
1681 static int Verbose ();
1682 static void SetVerbose (int v);
1683
1685 static void dumpTable (std::ostream& os, bool prettyPrint = false);
1686
1689 static void prettyPrintTable (std::ostream& os);
1690
1693 static void prettyPrintUnusedInputs (std::ostream& os);
1694
1697 static void prettyPrintUsedInputs (std::ostream& os);
1698
1700 static void addfile (std::string const& filename);
1701
1702 static bool QueryUnusedInputs ();
1703
1705 [[nodiscard]] static bool hasUnusedInputs (const std::string& prefix = std::string());
1706
1708 [[nodiscard]] static std::vector<std::string> getUnusedInputs (const std::string& prefix = std::string());
1709
1711 [[nodiscard]] static std::set<std::string> getEntries (const std::string& prefix = std::string());
1712
1713 struct PP_entry {
1714 // There can be multiple occurrences for a given name (e.g.,
1715 // multiple lines starting with `foo =` in inputs. For each
1716 // occurrence, there can be multiple values. Thus, the use of
1717 // vector<vector<std::string>>.
1718 std::vector<std::vector<std::string>> m_vals;
1719 mutable Long m_count = 0;
1720 mutable std::variant<
1721 std::string*,
1722 bool*,
1723 int*,
1724 long*,
1725 long long*,
1727 amrex::Box*,
1728 float*,
1729 double*
1730 > m_typehint = static_cast<std::string*>(nullptr);
1731 mutable std::vector<std::variant<bool, int, long, long long, float, double>> m_last_vals;
1732 mutable bool m_parsed = false;
1733 };
1734 using Table = std::unordered_map<std::string, PP_entry>;
1735
1736 [[nodiscard]] const Table& table() const {return *m_table;}
1737
1739 static std::string const FileKeyword;
1740
1741 static std::string ParserPrefix;
1742
1743 [[nodiscard]] std::string const& getPrefix () const;
1744
1745 [[nodiscard]] std::string prefixedName (std::string_view str) const;
1746
1747protected:
1748
1749 std::string m_prefix; // Prefix used in keyword search
1750 std::string m_parser_prefix; // Prefix used by Parser
1752};
1753
1754}
1755
1756#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:348
int queryline(std::string_view name, std::string &ref) const
Definition AMReX_ParmParse.cpp:2239
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:2254
int queryarrWithParser(std::string_view name, int nvals, std::vector< T > &ref) const
Definition AMReX_ParmParse.H:1153
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:1070
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:1195
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:1651
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:2539
int query(std::string_view name, std::array< T, N > &ref) const
Definition AMReX_ParmParse.H:1025
static void prettyPrintTable(std::ostream &os)
Definition AMReX_ParmParse.cpp:1414
void get(std::string_view name, T &ref, int ival=FIRST) const
. Get enum value using given name.
Definition AMReX_ParmParse.H:1345
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:1224
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:1390
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:1199
static std::string const FileKeyword
keyword for files to load
Definition AMReX_ParmParse.H:1739
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:1515
static std::string ParserPrefix
Definition AMReX_ParmParse.H:1741
static int Verbose()
Definition AMReX_ParmParse.cpp:1305
static void SetVerbose(int v)
Definition AMReX_ParmParse.cpp:1318
int query(std::string_view name, T &ref, int ival=FIRST) const
. Query enum value using given name.
Definition AMReX_ParmParse.H:1307
void get(const char *new_name, const char *old_name, T &ref)
Get using two names.
Definition AMReX_ParmParse.H:1286
static bool hasUnusedInputs(const std::string &prefix=std::string())
Any unused [prefix.]* parameters?
Definition AMReX_ParmParse.cpp:1256
Parser makeParser(std::string const &func, Vector< std::string > const &vars) const
Definition AMReX_ParmParse.cpp:2457
int queryAdd(std::string_view name, std::string &ref)
Definition AMReX_ParmParse.H:1052
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:1423
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:1546
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:1536
static bool QueryUnusedInputs()
Definition AMReX_ParmParse.cpp:1241
void getline(std::string_view name, std::string &ref) const
Definition AMReX_ParmParse.cpp:2231
T eval(std::string const &expr) const
Definition AMReX_ParmParse.H:1252
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:1537
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:1214
void add(std::string_view name, const char *val)
Convert const char * to string, to prevent auto-conversion to bool.
Definition AMReX_ParmParse.H:618
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:1444
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:1596
bool contains(std::string_view name) const
Returns true if name is in table.
Definition AMReX_ParmParse.cpp:2270
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:1565
void get(std::string_view name, std::array< T, N > &ref) const
Definition AMReX_ParmParse.H:1015
static void prettyPrintUsedInputs(std::ostream &os)
Definition AMReX_ParmParse.cpp:1426
static void Finalize()
The destructor. The internal static table will only be deleted if there are no other ParmParse object...
Definition AMReX_ParmParse.cpp:1324
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:1089
std::string m_prefix
Definition AMReX_ParmParse.H:1749
const Table & table() const
Definition AMReX_ParmParse.H:1736
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:1175
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:1461
static void SetParserPrefix(std::string a_prefix)
Set prefix used by math expression Parser.
Definition AMReX_ParmParse.cpp:1351
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:2385
static std::vector< std::string > getUnusedInputs(const std::string &prefix=std::string())
Returns unused [prefix.]* parameters.
Definition AMReX_ParmParse.cpp:1262
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:1044
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:1565
std::string const & getPrefix() const
Definition AMReX_ParmParse.cpp:1179
int remove(std::string_view name)
Remove given name from the table.
Definition AMReX_ParmParse.cpp:2286
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:1556
@ FIRST
Definition AMReX_ParmParse.H:350
@ LAST
Definition AMReX_ParmParse.H:350
@ ALL
Definition AMReX_ParmParse.H:350
void add(std::string_view name, T const &val)
Definition AMReX_ParmParse.H:1330
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:1363
static void Initialize(int argc, char **argv, const std::string &parfile)
Definition AMReX_ParmParse.H:1669
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:1104
int query(const char *new_name, const char *old_name, T &ref)
Definition AMReX_ParmParse.H:1272
Table * m_table
Definition AMReX_ParmParse.H:1751
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:2421
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:1613
std::string m_parser_prefix
Definition AMReX_ParmParse.H:1750
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:1478
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:1453
static void dumpTable(std::ostream &os, bool prettyPrint=false)
Write the contents of the table in ASCII to the ostream.
Definition AMReX_ParmParse.cpp:1357
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:1527
static void prettyPrintUnusedInputs(std::ostream &os)
Definition AMReX_ParmParse.cpp:1420
static std::set< std::string > getEntries(const std::string &prefix=std::string())
Returns [prefix.]* parameters.
Definition AMReX_ParmParse.cpp:1292
std::string prefixedName(std::string_view str) const
Definition AMReX_ParmParse.cpp:1185
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:1233
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:1470
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:1478
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:1453
std::unordered_map< std::string, PP_entry > Table
Definition AMReX_ParmParse.H:1734
IParser makeIParser(std::string const &func, Vector< std::string > const &vars) const
Definition AMReX_ParmParse.cpp:2464
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:1432
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:1713
std::variant< std::string *, bool *, int *, long *, long long *, amrex::IntVect *, amrex::Box *, float *, double * > m_typehint
Definition AMReX_ParmParse.H:1730
std::vector< std::vector< std::string > > m_vals
Definition AMReX_ParmParse.H:1718
Long m_count
Definition AMReX_ParmParse.H:1719
std::vector< std::variant< bool, int, long, long long, float, double > > m_last_vals
Definition AMReX_ParmParse.H:1731
bool m_parsed
Definition AMReX_ParmParse.H:1732