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#include <AMReX_Vector.H>
14
15#include <array>
16#include <cmath>
17#include <concepts>
18#include <iosfwd>
19#include <limits>
20#include <optional>
21#include <set>
22#include <string>
23#include <string_view>
24#include <type_traits>
25#include <unordered_map>
26#include <variant>
27#include <vector>
28
29namespace amrex {
30
31template<int dim>
32class BoxND;
33using Box = BoxND<AMREX_SPACEDIM>;
34template<int dim>
35class IntVectND;
36using IntVect = IntVectND<AMREX_SPACEDIM>;
37template<int dim>
38class RealVectND;
40
42namespace ppdetail {
43 template <class T, class Enable = void>
44 struct ArithmeticOptional_TT : std::false_type {};
45
46 template <class T>
47 requires (std::is_arithmetic_v<T>)
48 struct ArithmeticOptional_TT<T>
49 : std::true_type
50 {
51 using value_type = T;
52 };
53
54 template <class T>
55 requires (std::is_arithmetic_v<T>)
56 struct ArithmeticOptional_TT<std::optional<T>>
57 : std::true_type
58 {
59 using value_type = T;
60 };
61
62 template <class T>
63 inline constexpr bool IsArithmeticOptional_v = ArithmeticOptional_TT<T>::value;
64
65 template <class T>
66 using underlying_type_t = typename ArithmeticOptional_TT<T>::value_type;
67}
69
70//
71// ParmParse class implements a simple database for the storage and
72// retrieval of command-line and input-file arguments. The entries are
73// stored in a static table in (name,value_list) pairs.
74//
75// The format of the input file is a series of DEFINITIONS.
76//
77// A DEFINITION is of the form <name> = <value> <value> ...
78// The equal sign is important since the list of values can span multiple
79// lines.
80//
81// Comments in an input file include all text from a '#' character to the
82// end of the line. Here is an example input file:
83/*
84 niter = 100 # niter is an integer
85 title = "Double Wammy" # example of a string with spaces
86 cell_size = 0.5 0.75 # cell spacing in each dimension
87 plot.var = Density 1 10 # a list of values
88 plot.var = Energy 5 12 # another list of values
89 bigarray = 1 2 3 4 5 6 7 8 \
90 9 10 11 12 # continuation of bigarray
91 multi_line_string = "This is a
92 multi-line string."
93 my_2d_table = \
94 # col 1 2 3
95 {{ 11.0, 12.0, 13.0 } # row 1
96 { 21.0, 22.0, 23.0 } # row 2
97 { 31.0, 32.0, 33.0 } # row 3
98 { 41.0, 42.0, 43.0 } } # row 4
99 test = apple "boy blue" 10 20 30 40
100 FILE = prob_file # insert contents of this "prob_file" here
101*/
102// For values spanning multiple lines except for table, one must use '\' at
103// the end of a line
104// for continuation, otherwise it's a runtime error. Note that there must be
105// at least one space before the continuation character `\`. Multiple lines
106// inside a pair of double quotes are considered a single string containing
107// '\n's. The "FILE = <filename>" definition is special. Rather than just
108// adding this entry to the database, it reads the contents of <filename>
109// into the database.
110// For CI/CD workflows and out-of-source tests, the environment variable
111// AMREX_INPUTS_FILE_PREFIX can be set to prefix every FILE = <filename>
112// with a custom path.
113//
114// ParmParse stores all entries in a static table which is built the
115// first time a ParmParse object is constructed (usually in main()).
116// Subsequent invocations have access to this table.
117// A ParmParse constructor has an optional "prefix" argument that will
118// limit the searches to only those entries of the table with this prefix
119// in name. For example:
120// ParmParse pp("plot");
121// will find only those entries with name given by "plot.<string>".
122//
123// All values in the table are stored as strings. For example, the
124// values of "cell_size" in the above input file are stored as the
125// strings "0.5" and "0.75". These strings can be returned as either
126// strings or numeric values by the query functions.
127// Character strings with spaces must be delimited by double quotes
128// in the input file but the quotes are stripped before they are entered
129// into the table. For example, 'title' in the above input file has a
130// single value, the string 'Double Wammy' (without the quotes).
131// Each value in the list associated with a definition can be referred to
132// by its index number. The index numbers start at 0 just like an array
133// in the C programming language. Consider the definition of "test" in
134// the above input file. The first value 'apple'is a string with index
135// 0. The second value 'boy blue' is a string with index 1. The
136// remaining four values are integers indexed 2, 3, 4, and 5.
137//
138// For a string value to represent an integer or float it must fit the
139// following regular expression:
140// Sign ::= '+' | '-'
141// Digit ::= '0' | '1' | ... | '9'
142// Integer ::= [Sign]Digit+
143// Exp ::= ('e'|'E')Integer
144// Float ::= ( Integer[.Digit*][Exp] | [Integer].Digit+[Exp] )
145//
146// Where '+' indicates one or more occurrences, '*' represents zero or
147// more occurrences, '|' means one or the other and '[]' represents zero
148// or one occurrence.
149//
150// Note that floats and doubles have the same string representation and
151// that the FORTRAN "double" exponent format is not supported.
152// That is, 1.0d+3 is not a valid representation of a floating point
153// number but that 1.0e+3 is acceptable.
154//
155// There are a host of functions allowing the user to query the database
156// and retrieve values. Here are some general rules about the names of
157// the member functions:
158//
159// * Functions with the string "get" in their names attempt to get a
160// value or an array of values from the table. They generate a
161// run-time error if they are not successful.
162//
163// * Functions with the string "query" in their names attempt to get a
164// value or an array of values from the table. They return the value 1
165// (true) if they are successful and 0 (false) if not.
166//
167// * Functions with the string "kth" in their names get values from
168// the Kth entry with the given name in the database. This is
169// necessary since there may be multiple definitions with the same
170// name in the database.
171//
172// * Functions without the string "kth" in their names get values from
173// the last entry with the given name in the database. Note that the
174// definitions from the command line are appended to the database table
175// and hence will be the last entries.
176//
177// * Functions with the string "arr" in their names get an Array of
178// values from the given entry in the table. The array argument is
179// resized (if necessary) to hold all the values requested.
180//
181// * Functions without the string "arr" in their names get single
182// values from the given entry in the table.
183//
184// The following is a code sample showing how to use ParmParse:
185//
186// main(int argc, char **argv)
187// {
188// char* in_file_name = argv[1];
189// ParmParse::Initialize(argc-2, argv+2, in_file_name);
190//
191// // Query table for value of "niter". If not in table
192// // then set to default value
193// if (!pp.query("niter",niter)) niter = 20;
194//
195// // read array of cell sizes if in table
196// Vector<float> dx;
197// if (nx=pp.countval("cell_size")) {
198// // get nx values starting at index 0 and store in dx.
199// // dx is automatically resized here.
200// pp.getarr("cell_size",dx,0,nx);
201// }
202// ParmParse::Finalize();
203// }
204//
205// void do_graphics()
206// {
207// //
208// // Will only query entries with the "plot" prefix:
209// //
210// ParmParse pp("plot");
211// //
212// // Read all variables with "plot.var" keyword.
213// //
214// std::string var_name;
215// Vector<int> range;
216// int num = pp.countname("var");
217// for (int k = 0; k < num; k++)
218// {
219// //
220// // Element 0 in list is a string.
221// //
222// pp.getkth("var",k,var_name,0);
223// //
224// // Elements 1 and 2 are integers.
225// // Note that "range" will be resized to hold 2 elements.
226// //
227// pp.getktharr("var",k,range,1,2);
228// cout << "variable = " << var_name << "lo, hi = ",
229// << range[0] << " " << range[1] << endl;
230// }
231// }
232// -----------------------------------------------------------------
233// ----------------------- END COMMENTS ---------------------------
234// -----------------------------------------------------------------
235
236
353{
354public:
355 enum { LAST = -1, FIRST = 0, ALL = -1 };
363 explicit ParmParse (std::string prefix = std::string(),
364 std::string parser_prefix = std::string());
365
367 [[nodiscard]] bool contains (std::string_view name) const;
373 [[nodiscard]] int countval (std::string_view name, int n = LAST) const;
378 [[nodiscard]] int countname (std::string_view name) const;
390 void getkth (std::string_view name,
391 int k,
392 bool& ref,
393 int ival = FIRST) const;
395 void get (std::string_view name,
396 bool& ref,
397 int ival = FIRST) const;
405 int querykth (std::string_view name,
406 int k,
407 bool& ref,
408 int ival = FIRST) const;
410 int query (std::string_view name,
411 bool& ref,
412 int ival = FIRST) const;
414 void add (std::string_view name, bool val);
424 void getkth (std::string_view name,
425 int k,
426 int& ref,
427 int ival = FIRST) const;
428
430 void get (std::string_view name,
431 int& ref,
432 int ival = FIRST) const;
440 int querykth (std::string_view name,
441 int k,
442 int& ref,
443 int ival = FIRST) const;
445 int query (std::string_view name,
446 int& ref,
447 int ival = FIRST) const;
449 void add (std::string_view name, int val);
459 void getkth (std::string_view name,
460 int k,
461 long& ref,
462 int ival = FIRST) const;
464 void get (std::string_view name,
465 long& ref,
466 int ival = FIRST) const;
474 int querykth (std::string_view name,
475 int k,
476 long& ref,
477 int ival = FIRST) const;
479 int query (std::string_view name,
480 long& ref,
481 int ival = FIRST) const;
483 void add (std::string_view name, long val);
493 void getkth (std::string_view name,
494 int k,
495 long long& ref,
496 int ival = FIRST) const;
498 void get (std::string_view name,
499 long long& ref,
500 int ival = FIRST) const;
508 int querykth (std::string_view name,
509 int k,
510 long long& ref,
511 int ival = FIRST) const;
513 int query (std::string_view name,
514 long long& ref,
515 int ival = FIRST) const;
517 void add (std::string_view name, long long val);
527 void getkth (std::string_view name,
528 int k,
529 float& ref,
530 int ival = FIRST) const;
532 void get (std::string_view name,
533 float& ref,
534 int ival = FIRST) const;
542 int querykth (std::string_view name,
543 int k,
544 float& ref,
545 int ival = FIRST) const;
547 int query (std::string_view name,
548 float& ref,
549 int ival = FIRST) const;
551 void add (std::string_view name, float val);
561 void getkth (std::string_view name,
562 int k,
563 double& ref,
564 int ival = FIRST) const;
566 void get (std::string_view name,
567 double& ref,
568 int ival = FIRST) const;
576 int querykth (std::string_view name,
577 int k,
578 double& ref,
579 int ival = FIRST) const;
581 int query (std::string_view name,
582 double& ref,
583 int ival = FIRST) const;
585 void add (std::string_view name, double val);
595 void getkth (std::string_view name,
596 int k,
597 std::string& ref,
598 int ival = FIRST) const;
599
601 void get (std::string_view name,
602 std::string& ref,
603 int ival = FIRST) const;
611 int querykth (std::string_view name,
612 int k,
613 std::string& ref,
614 int ival = FIRST) const;
616 int query (std::string_view name,
617 std::string& ref,
618 int ival = FIRST) const;
620 void add (std::string_view name, const std::string& val);
621
623 void add (std::string_view name, const char* val) { add(name, std::string(val)); }
624
633 void getline (std::string_view name, std::string& ref) const;
634
643 int queryline (std::string_view name, std::string& ref) const;
644
654 void getkth (std::string_view name,
655 int k,
656 IntVect& ref,
657 int ival = FIRST) const;
659 void get (std::string_view name,
660 IntVect& ref,
661 int ival = FIRST) const;
669 int querykth (std::string_view name,
670 int k,
671 IntVect& ref,
672 int ival = FIRST) const;
674 int query (std::string_view name,
675 IntVect& ref,
676 int ival = FIRST) const;
678 void add (std::string_view name, const IntVect& val);
688 void getkth (std::string_view name,
689 int k,
690 Box& ref,
691 int ival = FIRST) const;
693 void get (std::string_view name,
694 Box& ref,
695 int ival = FIRST) const;
703 int querykth (std::string_view name,
704 int k,
705 Box& ref,
706 int ival = FIRST) const;
708 int query (std::string_view name,
709 Box& ref,
710 int ival = FIRST) const;
712 void add (std::string_view name, const Box& val);
725 void getktharr (std::string_view name,
726 int k,
727 std::vector<int>& ref,
728 int start_ix = FIRST,
729 int num_val = ALL) const;
731 void getarr (std::string_view name,
732 std::vector<int>& ref,
733 int start_ix = FIRST,
734 int num_val = ALL) const;
736 int queryktharr (std::string_view name,
737 int k,
738 std::vector<int>& ref,
739 int start_ix = FIRST,
740 int num_val = ALL) const;
742 int queryarr (std::string_view name,
743 std::vector<int>& ref,
744 int start_ix = FIRST,
745 int num_val = ALL) const;
747 void addarr (std::string_view name, const std::vector<int>& ref);
748
761 void getktharr (std::string_view name,
762 int k,
763 std::vector<long>& ref,
764 int start_ix = FIRST,
765 int num_val = ALL) const;
767 void getarr (std::string_view name,
768 std::vector<long>& ref,
769 int start_ix = FIRST,
770 int num_val = ALL) const;
772 int queryktharr (std::string_view name,
773 int k,
774 std::vector<long>& ref,
775 int start_ix = FIRST,
776 int num_val = ALL) const;
778 int queryarr (std::string_view name,
779 std::vector<long>& ref,
780 int start_ix = FIRST,
781 int num_val = ALL) const;
783 void addarr (std::string_view name, const std::vector<long>& ref);
784
797 void getktharr (std::string_view name,
798 int k,
799 std::vector<long long>& ref,
800 int start_ix = FIRST,
801 int num_val = ALL) const;
803 void getarr (std::string_view name,
804 std::vector<long long>& ref,
805 int start_ix = FIRST,
806 int num_val = ALL) const;
808 int queryktharr (std::string_view name,
809 int k,
810 std::vector<long long>& ref,
811 int start_ix = FIRST,
812 int num_val = ALL) const;
814 int queryarr (std::string_view name,
815 std::vector<long long>& ref,
816 int start_ix = FIRST,
817 int num_val = ALL) const;
819 void addarr (std::string_view name, const std::vector<long long>& ref);
820
833 void getktharr (std::string_view name,
834 int k,
835 std::vector<float>& ref,
836 int start_ix = FIRST,
837 int num_val = ALL) const;
839 void getarr (std::string_view name,
840 std::vector<float>& ref,
841 int start_ix = FIRST,
842 int num_val = ALL) const;
844 int queryktharr (std::string_view name,
845 int k,
846 std::vector<float>& ref,
847 int start_ix = FIRST,
848 int num_val = ALL) const;
850 int queryarr (std::string_view name,
851 std::vector<float>& ref,
852 int start_ix = FIRST,
853 int num_val = ALL) const;
855 void addarr (std::string_view name, const std::vector<float>& ref);
868 void getktharr (std::string_view name,
869 int k,
870 std::vector<double>& ref,
871 int start_ix = FIRST,
872 int num_val = ALL) const;
874 void getarr (std::string_view name,
875 std::vector<double>& ref,
876 int start_ix = FIRST,
877 int num_val = ALL) const;
879 int queryktharr (std::string_view name,
880 int k,
881 std::vector<double>& ref,
882 int start_ix = FIRST,
883 int num_val = ALL) const;
885 int queryarr (std::string_view name,
886 std::vector<double>& ref,
887 int start_ix = FIRST,
888 int num_val = ALL) const;
890 void addarr (std::string_view name, const std::vector<double>& ref);
903 void getktharr (std::string_view name,
904 int k,
905 std::vector<std::string>& ref,
906 int start_ix = FIRST,
907 int num_val = ALL) const;
909 void getarr (std::string_view name,
910 std::vector<std::string>& ref,
911 int start_ix = FIRST,
912 int num_val = ALL) const;
914 int queryktharr (std::string_view name,
915 int k,
916 std::vector<std::string>& ref,
917 int start_ix = FIRST,
918 int num_val = ALL) const;
920 int queryarr (std::string_view name,
921 std::vector<std::string>& ref,
922 int start_ix = FIRST,
923 int num_val = ALL) const;
925 void addarr (std::string_view name, const std::vector<std::string>& ref);
938 void getktharr (std::string_view name,
939 int k,
940 std::vector<IntVect>& ref,
941 int start_ix = FIRST,
942 int num_val = ALL) const;
944 void getarr (std::string_view name,
945 std::vector<IntVect>& ref,
946 int start_ix = FIRST,
947 int num_val = ALL) const;
949 int queryktharr (std::string_view name,
950 int k,
951 std::vector<IntVect>& ref,
952 int start_ix = FIRST,
953 int num_val = ALL) const;
955 int queryarr (std::string_view name,
956 std::vector<IntVect>& ref,
957 int start_ix = FIRST,
958 int num_val = ALL) const;
960 void addarr (std::string_view name, const std::vector<IntVect>& ref);
973 void getktharr (std::string_view name,
974 int k,
975 std::vector<Box>& ref,
976 int start_ix = FIRST,
977 int num_val = ALL) const;
979 void getarr (std::string_view name,
980 std::vector<Box>& ref,
981 int start_ix = FIRST,
982 int num_val = ALL) const;
984 int queryktharr (std::string_view name,
985 int k,
986 std::vector<Box>& ref,
987 int start_ix = FIRST,
988 int num_val = ALL) const;
990 int queryarr (std::string_view name,
991 std::vector<Box>& ref,
992 int start_ix = FIRST,
993 int num_val = ALL) const;
995 void addarr (std::string_view name, const std::vector<Box>& ref);
996
997 /*
998 * \brief Query IntVect from array
999 *
1000 * This reads IntVect from an array (e.g., `8 16 8`), not the format
1001 * using parentheses (e.g., `(8,16,8)`).
1002 */
1003 int queryarr (std::string_view name, IntVect& ref) const;
1004
1005 /*
1006 * \brief Get IntVect from array
1007 *
1008 * This reads IntVect from an array (e.g., `8 16 8`), not the format
1009 * using parentheses (e.g., `(8,16,8)`).
1010 */
1011 void getarr (std::string_view name, IntVect& ref) const;
1012
1014 int queryarr (std::string_view name, RealVect& ref) const;
1015
1017 void getarr (std::string_view name, RealVect& ref) const;
1018
1019 template <typename T, std::size_t N>
1020 void get (std::string_view name, std::array<T,N>& ref) const {
1021 std::vector<T> v;
1022 this->getarr(name, v);
1023 AMREX_ALWAYS_ASSERT(v.size() >= N);
1024 for (std::size_t i = 0; i < N; ++i) {
1025 ref[i] = v[i];
1026 }
1027 }
1028
1029 template <typename T, std::size_t N>
1030 int query (std::string_view name, std::array<T,N>& ref) const {
1031 std::vector<T> v;
1032 int exist = this->queryarr(name, v);
1033 if (exist) {
1034 AMREX_ALWAYS_ASSERT(v.size() >= N);
1035 for (std::size_t i = 0; i < N; ++i) {
1036 ref[i] = v[i];
1037 }
1038 }
1039 return exist;
1040 }
1041
1048 template <typename T>
1049 int queryAdd (std::string_view name, T& ref) {
1050 int exist = this->query(name, ref);
1051 if (!exist) {
1052 this->add(name, ref);
1053 }
1054 return exist;
1055 }
1056
1057 int queryAdd (std::string_view name, std::string& ref) {
1058 int exist = this->query(name, ref);
1059 if (!exist && !ref.empty()) {
1060 this->add(name, ref);
1061 }
1062 return exist;
1063 }
1064
1074 template <typename T>
1075 int queryAdd (std::string_view name, std::vector<T>& ref) {
1076 std::vector<T> empty;
1077 int exist = this->queryarr(name, empty);
1078 if (exist) {
1079 ref = std::move(empty);
1080 }
1081 if (!exist && !ref.empty()) {
1082 this->addarr(name, ref);
1083 }
1084 return exist;
1085 }
1086
1087 template <typename T>
1088 int queryAdd (std::string_view name, Vector<T>& ref) {
1089 return this->queryAdd(name, static_cast<std::vector<T>&>(ref));
1090 }
1091
1098 template <typename T>
1099 int queryAdd (std::string_view name, std::vector<T>& ref, int num_val) {
1100 int exist = this->queryarr(name, ref, 0, num_val);
1101 if (!exist) {
1102 this->addarr(name, ref);
1103 }
1104 return exist;
1105 }
1106
1113 template <typename T, std::size_t N>
1114 int queryAdd (std::string_view name, std::array<T,N>& ref) {
1115 std::vector<T> v;
1116 int exist = this->queryarr(name, v);
1117 if (exist) {
1118 AMREX_ALWAYS_ASSERT(v.size() >= N);
1119 for (std::size_t i = 0; i < N; ++i) {
1120 ref[i] = v[i];
1121 }
1122 } else {
1123 v.resize(N);
1124 for (std::size_t i = 0; i < N; ++i) {
1125 v[i] = ref[i];
1126 }
1127 this->addarr(name, v);
1128 }
1129 return exist;
1130 }
1131
1138 int queryWithParser (std::string_view name, bool& ref) const;
1139 int queryWithParser (std::string_view name, int& ref) const;
1140 int queryWithParser (std::string_view name, long& ref) const;
1141 int queryWithParser (std::string_view name, long long& ref) const;
1142 int queryWithParser (std::string_view name, float& ref) const;
1143 int queryWithParser (std::string_view name, double& ref) const;
1144
1151 int queryarrWithParser (std::string_view name, int nvals, bool* ptr) const;
1152 int queryarrWithParser (std::string_view name, int nvals, int* ptr) const;
1153 int queryarrWithParser (std::string_view name, int nvals, long* ptr) const;
1154 int queryarrWithParser (std::string_view name, int nvals, long long* ptr) const;
1155 int queryarrWithParser (std::string_view name, int nvals, float* ptr) const;
1156 int queryarrWithParser (std::string_view name, int nvals, double* ptr) const;
1157 template <typename T>
1158 requires (std::same_as<T,bool> ||
1159 std::same_as<T,int> ||
1160 std::same_as<T,long> ||
1161 std::same_as<T,long long> ||
1162 std::same_as<T,float> ||
1163 std::same_as<T,double>)
1164 int queryarrWithParser (std::string_view name, int nvals, std::vector<T>& ref) const
1165 {
1166 if (this->contains(name)) {
1167 if (int(ref.size()) < nvals) { ref.resize(nvals); }
1168 return this->queryarrWithParser(name, nvals, ref.data());
1169 } else {
1170 return 0;
1171 }
1172 }
1173
1180 template <typename T>
1181 requires (std::same_as<T,bool> ||
1182 std::same_as<T,int> ||
1183 std::same_as<T,long> ||
1184 std::same_as<T,long long> ||
1185 std::same_as<T,float> ||
1186 std::same_as<T,double>)
1187 int queryAddWithParser (std::string_view name, T& ref)
1188 {
1189 int exist = this->queryWithParser(name, ref);
1190 if (!exist) {
1191 this->add(name, ref);
1192 }
1193 return exist;
1194 }
1195
1201 template <typename T>
1202 requires (std::same_as<T,bool> ||
1203 std::same_as<T,int> ||
1204 std::same_as<T,long> ||
1205 std::same_as<T,long long> ||
1206 std::same_as<T,float> ||
1207 std::same_as<T,double>)
1208 void getWithParser (std::string_view name, T& ref) const
1209 {
1210 int exist = this->queryWithParser(name, ref);
1211 if (!exist) {
1212 amrex::Error(std::string("ParmParse::getWithParser: failed to get ")+std::string(name));
1213 }
1214 }
1215
1221 template <typename T>
1222 requires (std::same_as<T,bool> ||
1223 std::same_as<T,int> ||
1224 std::same_as<T,long> ||
1225 std::same_as<T,long long> ||
1226 std::same_as<T,float> ||
1227 std::same_as<T,double>)
1228 void getarrWithParser (std::string_view name, int nvals, T* ptr) const
1229 {
1230 int exist = this->queryarrWithParser(name, nvals, ptr);
1231 if (!exist) {
1232 amrex::Error(std::string("ParmParse::getarrWithParser: failed to get ")+std::string(name));
1233 }
1234 }
1235
1241 template <typename T>
1242 requires (std::same_as<T,bool> ||
1243 std::same_as<T,int> ||
1244 std::same_as<T,long> ||
1245 std::same_as<T,long long> ||
1246 std::same_as<T,float> ||
1247 std::same_as<T,double>)
1248 void getarrWithParser (std::string_view name, int nvals, std::vector<T>& ref) const
1249 {
1250 int exist = this->queryarrWithParser(name, nvals, ref);
1251 if (!exist) {
1252 amrex::Error(std::string("ParmParse::getarrWithParser: failed to get ")+std::string(name));
1253 }
1254 }
1255
1256 /*
1257 * \brief Evaluate given string as math expression
1258 *
1259 * For unknown symbols, ParmParse database will be queried.
1260 */
1261 template <typename T>
1262 requires (std::same_as<T,bool> ||
1263 std::same_as<T,int> ||
1264 std::same_as<T,long> ||
1265 std::same_as<T,long long> ||
1266 std::same_as<T,float> ||
1267 std::same_as<T,double>)
1268 T eval (std::string const& expr) const
1269 {
1270 if constexpr (std::is_integral_v<T>) {
1271 auto const parser = this->makeIParser(expr, {});
1272 auto const exe = parser.compileHost<0>();
1273 return static_cast<T>(exe()); // In the future, we might add safety check.
1274 } else {
1275 auto const parser = this->makeParser(expr, {});
1276 auto const exe = parser.compileHost<0>();
1277 return static_cast<T>(exe());
1278 }
1279 }
1280
1281 /*
1282 * \brief Query two names.
1283 *
1284 * This function queries with `new_name` first. If it's not found, it
1285 * will try again with `old_name`.
1286 */
1287 template <typename T>
1288 int query (const char* new_name, const char* old_name, T& ref)
1289 {
1290 return (this->query(new_name, ref) ||
1291 this->query(old_name, ref));
1292 }
1293
1301 template <typename T>
1302 void get (const char* new_name, const char* old_name, T& ref)
1303 {
1304 auto exist = this->query(new_name, old_name, ref);
1305 if (!exist) {
1306 amrex::ErrorStream() << "ParmParse::get failed to find "
1307 << new_name << " and " << old_name << '\n';
1309 amrex::Abort();
1310 }
1311 }
1312
1321 template <typename T, typename ET = amrex_enum_traits<T>>
1322 requires (ET::value)
1323 int query (std::string_view name, T& ref, int ival = FIRST) const
1324 {
1325 std::string s;
1326 int exist = this->query(name, s, ival);
1327 if (exist) {
1328 try {
1329 ref = amrex::getEnum<T>(s);
1330 } catch (...) {
1331 if (amrex::Verbose() > 0 ) {
1332 amrex::Print() << "amrex::ParmParse::query (input name: "
1333 << this->prefixedName(name) << "):\n";
1334 }
1335 throw;
1336 }
1337 }
1338 return exist;
1339 }
1340
1341
1344 template <typename T, typename ET = amrex_enum_traits<T>>
1345 requires (ET::value)
1346 void add (std::string_view name, T const& val)
1347 {
1348 this->add(name, amrex::getEnumNameString(val));
1349 }
1350
1359 template <typename T, typename ET = amrex_enum_traits<T>>
1360 requires (ET::value)
1361 void get (std::string_view name, T& ref, int ival = FIRST) const
1362 {
1363 std::string s;
1364 this->get(name, s, ival);
1365 try {
1366 ref = amrex::getEnum<T>(s);
1367 } catch (...) {
1368 if (amrex::Verbose() > 0 ) {
1369 amrex::Print() << "amrex::ParmParse::get (input name: "
1370 << this->prefixedName(name) << "):\n";
1371 }
1372 throw;
1373 }
1374 }
1375
1377 template <typename T, typename ET = amrex_enum_traits<T>>
1378 requires (ET::value)
1379 int queryarr (std::string_view name,
1380 std::vector<T>& ref,
1381 int start_ix = FIRST,
1382 int num_val = ALL) const
1383 {
1384 std::vector<std::string> s;
1385 int exist = this->queryarr(name, s, start_ix, num_val);
1386 if (exist) {
1387 ref.resize(s.size());
1388 for (std::size_t i = 0; i < s.size(); ++i) {
1389 try {
1390 ref[i] = amrex::getEnum<T>(s[i]);
1391 } catch (...) {
1392 if (amrex::Verbose() > 0 ) {
1393 amrex::Print() << "amrex::ParmParse::queryarr (input name: "
1394 << this->prefixedName(name) << "):\n";
1395 }
1396 throw;
1397 }
1398 }
1399 }
1400 return exist;
1401 }
1402
1404 template <typename T, typename ET = amrex_enum_traits<T>>
1405 requires (ET::value)
1406 void getarr (std::string_view name,
1407 std::vector<T>& ref,
1408 int start_ix = FIRST,
1409 int num_val = ALL) const
1410 {
1411 std::vector<std::string> s;
1412 this->getarr(name, s, start_ix, num_val);
1413 ref.resize(s.size());
1414 for (std::size_t i = 0; i < s.size(); ++i) {
1415 try {
1416 ref[i] = amrex::getEnum<T>(s[i]);
1417 } catch (...) {
1418 if (amrex::Verbose() > 0 ) {
1419 amrex::Print() << "amrex::ParmParse::getarr (input name: "
1420 << this->prefixedName(name) << "):\n";
1421 }
1422 throw;
1423 }
1424 }
1425 }
1426
1437 template <typename T, typename ET = amrex_enum_traits<T>>
1438 requires (ET::value)
1439 int query_enum_case_insensitive (std::string_view name, T& ref, int ival = FIRST) const
1440 {
1441 std::string s;
1442 int exist = this->query(name, s, ival);
1443 if (exist) {
1444 try {
1445 ref = amrex::getEnumCaseInsensitive<T>(s);
1446 } catch (...) {
1447 if (amrex::Verbose() > 0) {
1448 amrex::Print() << "amrex::ParmParse::query_enum_case_insensitive (input name: "
1449 << this->prefixedName(name) << "):\n";
1450 }
1451 throw;
1452 }
1453 }
1454 return exist;
1455 }
1456
1467 template <typename T, typename ET = amrex_enum_traits<T>>
1468 requires (ET::value)
1469 void get_enum_case_insensitive (std::string_view name, T& ref, int ival = FIRST) const
1470 {
1471 int exist = this->query_enum_case_insensitive(name, ref, ival);
1472 if (!exist) {
1473 std::string msg("get_enum_case_insensitive(\"");
1474 msg.append(name).append("\",").append(amrex::getEnumClassName<T>())
1475 .append("&) failed.");
1476 amrex::Abort(msg);
1477 }
1478 }
1479
1492 template <typename T, typename ET = amrex_enum_traits<T>>
1493 requires (ET::value)
1494 int query_enum_sloppy (std::string_view name, T& ref, std::string_view const& ignores,
1495 int ival = FIRST) const
1496 {
1497 std::string s;
1498 int exist = this->query(name, s, ival);
1499 if (exist) {
1500 try {
1501 std::erase_if(s, [&] (auto const& c) {
1502 return ignores.find(c) != std::string_view::npos;
1503 });
1504 ref = amrex::getEnumCaseInsensitive<T>(s);
1505 } catch (...) {
1506 if (amrex::Verbose() > 0) {
1507 amrex::Print() << "amrex::ParmParse::query_enum_sloppy (input name: "
1508 << this->prefixedName(name) << "):\n";
1509 }
1510 throw;
1511 }
1512 }
1513 return exist;
1514 }
1515
1528 template <typename T, typename ET = amrex_enum_traits<T>>
1529 requires (ET::value)
1530 void get_enum_sloppy (std::string_view name, T& ref, std::string_view const& ignores,
1531 int ival = FIRST) const
1532 {
1533 int exist = this->query_enum_sloppy(name, ref, ignores, ival);
1534 if (!exist) {
1535 std::string msg("get_enum_sloppy(\"");
1536 msg.append(name).append("\",").append(amrex::getEnumClassName<T>())
1537 .append("&) failed.");
1538 amrex::Abort(msg);
1539 }
1540 }
1541
1550 template <typename T>
1551 requires (ppdetail::IsArithmeticOptional_v<T>)
1552 int queryAsDouble (std::string_view name, T& ref) const
1553 {
1554 using value_type = ppdetail::underlying_type_t<T>;
1555 double dref;
1556 int exist = queryWithParser(name, dref);
1557 if (exist) {
1558 if (std::is_integral_v<value_type>) {
1559 dref = std::round(dref);
1560 }
1561 if constexpr (std::is_integral_v<value_type> && !std::is_same_v<value_type,bool>) {
1562 // Range check before the cast, which would otherwise be UB.
1563 if (!(dref >= static_cast<double>(std::numeric_limits<value_type>::lowest()) &&
1564 dref < std::ldexp(1.0, std::numeric_limits<value_type>::digits))) {
1565 amrex::Abort("ParmParse:: queryAsDouble is not safe");
1566 }
1567 }
1568 ref = static_cast<value_type>(dref);
1569 }
1570 return exist;
1571 }
1572
1581 template <typename T>
1582 requires (ppdetail::IsArithmeticOptional_v<T>)
1583 int queryarrAsDouble (std::string_view name, int nvals, T* ptr) const
1584 {
1585 using value_type = ppdetail::underlying_type_t<T>;
1586 std::vector<double> dref(nvals);
1587 int exist = queryarrWithParser(name, nvals, dref.data());
1588 if (exist) {
1589 for (int i = 0; i < nvals; ++i) {
1590 if (std::is_integral_v<value_type>) {
1591 dref[i] = std::round(dref[i]);
1592 }
1593 if constexpr (std::is_integral_v<value_type> && !std::is_same_v<value_type,bool>) {
1594 if (!(dref[i] >= static_cast<double>(std::numeric_limits<value_type>::lowest()) &&
1595 dref[i] < std::ldexp(1.0, std::numeric_limits<value_type>::digits))) {
1596 amrex::Abort("ParmParse:: queryarrAsDouble is not safe");
1597 }
1598 }
1599 ptr[i] = static_cast<value_type>(dref[i]);
1600 }
1601 }
1602 return exist;
1603 }
1604
1613 template <typename T>
1614 requires (ppdetail::IsArithmeticOptional_v<T>)
1615 void getAsDouble (std::string_view name, T& ref) const
1616 {
1617 int exist = this->queryAsDouble(name, ref);
1618 if (!exist) {
1619 amrex::Error(std::string("ParmParse::getAsDouble: failed to get ")+std::string(name));
1620 }
1621 }
1622
1631 template <typename T>
1632 requires (ppdetail::IsArithmeticOptional_v<T>)
1633 void getarrAsDouble (std::string_view name, int nvals, T* ptr) const
1634 {
1635 int exist = this->queryarrAsDouble(name, nvals, ptr);
1636 if (!exist) {
1637 amrex::Error(std::string("ParmParse::getarrAsDouble: failed to get ")+std::string(name));
1638 }
1639 }
1640
1642 int remove (std::string_view name);
1643
1647 [[nodiscard]] Parser makeParser (std::string const& func,
1648 Vector<std::string> const& vars) const;
1649
1653 [[nodiscard]] IParser makeIParser (std::string const& func,
1654 Vector<std::string> const& vars) const;
1655
1661 int querytable (std::string_view name, std::vector<std::vector<double>>& ref) const;
1662 int querytable (std::string_view name, std::vector<std::vector<float>>& ref) const;
1663 int querytable (std::string_view name, std::vector<std::vector<int>>& ref) const;
1664
1670 template <typename T>
1671 void gettable (std::string_view name, std::vector<std::vector<T>>& ref) const
1672 {
1673 if (this->querytable(name, ref) == 0) {
1674 amrex::ErrorStream() << "ParmParse::gettable: " << name
1675 << " not found in database\n";
1677 amrex::Abort();
1678 }
1679 }
1680
1686 int queryarr (std::string_view name, std::vector<std::vector<double>>& ref) const;
1687 int queryarr (std::string_view name, std::vector<std::vector<float>>& ref) const;
1688 int queryarr (std::string_view name, std::vector<std::vector<int>>& ref) const;
1689 int queryarr (std::string_view name, std::vector<std::vector<std::string>>& ref) const;
1690
1695 template <typename T>
1696 void getarr (std::string_view name, std::vector<std::vector<T>>& ref) const
1697 {
1698 if (this->queryarr(name, ref) == 0) {
1699 amrex::ErrorStream() << "ParmParse::getarr: " << name
1700 << " not found in database\n";
1702 amrex::Abort();
1703 }
1704 }
1705
1713 static void Initialize (int argc, char** argv, const char* parfile);
1714 static void Initialize (int argc, char** argv, const std::string& parfile) {
1715 Initialize(argc, argv, parfile.c_str());
1716 }
1721 static void Finalize ();
1722
1724 static void SetParserPrefix (std::string a_prefix);
1725
1726 static int Verbose ();
1727 static void SetVerbose (int v);
1728
1732 static void dumpTable (std::ostream& os, bool prettyPrint = false);
1733
1737 static void prettyPrintTable (std::ostream& os);
1738
1741 static void prettyPrintUnusedInputs (std::ostream& os);
1742
1745 static void prettyPrintUsedInputs (std::ostream& os);
1746
1750 static void addfile (std::string const& filename);
1751
1752 static bool QueryUnusedInputs ();
1753
1755 [[nodiscard]] static bool hasUnusedInputs (const std::string& prefix = std::string());
1756
1758 [[nodiscard]] static std::vector<std::string> getUnusedInputs (const std::string& prefix = std::string());
1759
1761 [[nodiscard]] static std::set<std::string> getEntries (const std::string& prefix = std::string());
1762
1763 enum class QuoteType : unsigned char {
1764 None = 0,
1765 Double,
1766 Triple
1767 };
1768
1769 struct PP_entry {
1770 // There can be multiple occurrences for a given name (e.g.,
1771 // multiple lines starting with `foo =` in inputs. For each
1772 // occurrence, there can be multiple values. Thus, the use of
1773 // vector<vector<std::string>>.
1774 std::vector<std::vector<std::string>> m_vals;
1775 std::vector<std::vector<QuoteType>> m_quotes;
1776 mutable Long m_count = 0;
1777 mutable std::variant<
1778 std::string*,
1779 bool*,
1780 int*,
1781 long*,
1782 long long*,
1784 amrex::Box*,
1785 float*,
1786 double*
1787 > m_typehint = static_cast<std::string*>(nullptr);
1788 mutable std::vector<std::variant<bool, int, long, long long, float, double>> m_last_vals;
1789 mutable bool m_parsed = false;
1790 };
1791 using Table = std::unordered_map<std::string, PP_entry>;
1792
1793 [[nodiscard]] const Table& table() const {return *m_table;}
1794
1796 static std::string const FileKeyword;
1797
1799 static std::string const UnsetKeyword;
1800
1801 static std::string ParserPrefix;
1802
1803 [[nodiscard]] std::string const& getPrefix () const;
1804
1805 [[nodiscard]] std::string prefixedName (std::string_view str) const;
1806
1807protected:
1808
1809 std::string m_prefix; // Prefix used in keyword search
1810 std::string m_parser_prefix; // Prefix used by Parser
1812};
1813
1814}
1815
1816#endif /* AMREX_PARMPARSE_H_ */
Assertion macros used across AMReX for runtime consistency checks.
#define AMREX_ALWAYS_ASSERT(EX)
Definition AMReX_BLassert.H:50
Integer-lattice boxes and helpers for defining index-space regions.
Enum reflection utilities and the AMREX_ENUM macro.
Integer-only runtime expression parser and executor helpers.
Runtime expression parser front-end and compiled executor helpers.
Integer-only variant of amrex::Parser.
Definition AMReX_IParser.H:93
IParserExecutor< N > compileHost() const
Compile the expression into a host-only executor.
Definition AMReX_IParser.H:192
Parse Parameters From Command Line and Input Files.
Definition AMReX_ParmParse.H:353
QuoteType
Definition AMReX_ParmParse.H:1763
int queryline(std::string_view name, std::string &ref) const
Definition AMReX_ParmParse.cpp:2745
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:2760
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:1075
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:1049
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:1671
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:3045
int query(std::string_view name, std::array< T, N > &ref) const
Definition AMReX_ParmParse.H:1030
static std::string const UnsetKeyword
keyword for removing entries from the table
Definition AMReX_ParmParse.H:1799
static void prettyPrintTable(std::ostream &os)
Definition AMReX_ParmParse.cpp:1879
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:1677
static void addfile(std::string const &filename)
Definition AMReX_ParmParse.cpp:1647
static std::string const FileKeyword
keyword for files to load
Definition AMReX_ParmParse.H:1796
static std::string ParserPrefix
Definition AMReX_ParmParse.H:1801
static int Verbose()
Definition AMReX_ParmParse.cpp:1758
static void SetVerbose(int v)
Definition AMReX_ParmParse.cpp:1771
void get(const char *new_name, const char *old_name, T &ref)
Get using two names.
Definition AMReX_ParmParse.H:1302
static bool hasUnusedInputs(const std::string &prefix=std::string())
Any unused [prefix.]* parameters?
Definition AMReX_ParmParse.cpp:1709
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:1583
Parser makeParser(std::string const &func, Vector< std::string > const &vars) const
Definition AMReX_ParmParse.cpp:2963
int queryAdd(std::string_view name, std::string &ref)
Definition AMReX_ParmParse.H:1057
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:2052
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:1633
static bool QueryUnusedInputs()
Definition AMReX_ParmParse.cpp:1694
void getline(std::string_view name, std::string &ref) const
Definition AMReX_ParmParse.cpp:2737
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:2043
void add(std::string_view name, const char *val)
Convert const char * to string, to prevent auto-conversion to bool.
Definition AMReX_ParmParse.H:623
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:1950
bool contains(std::string_view name) const
Returns true if name is in table.
Definition AMReX_ParmParse.cpp:2776
void get(std::string_view name, std::array< T, N > &ref) const
Definition AMReX_ParmParse.H:1020
void getarr(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 vector of vector is in the format of [[a0...
Definition AMReX_ParmParse.H:1696
static void prettyPrintUsedInputs(std::ostream &os)
Definition AMReX_ParmParse.cpp:1891
static void Finalize()
The destructor. The internal static table will only be deleted if there are no other ParmParse object...
Definition AMReX_ParmParse.cpp:1777
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:1099
std::string m_prefix
Definition AMReX_ParmParse.H:1809
const Table & table() const
Definition AMReX_ParmParse.H:1793
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:1187
T eval(std::string const &expr) const
Definition AMReX_ParmParse.H:1268
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:1967
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:1530
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:1439
static void SetParserPrefix(std::string a_prefix)
Set prefix used by math expression Parser.
Definition AMReX_ParmParse.cpp:1807
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:2891
static std::vector< std::string > getUnusedInputs(const std::string &prefix=std::string())
Returns unused [prefix.]* parameters.
Definition AMReX_ParmParse.cpp:1715
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:2071
std::string const & getPrefix() const
Definition AMReX_ParmParse.cpp:1627
int remove(std::string_view name)
Remove given name from the table.
Definition AMReX_ParmParse.cpp:2792
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:2062
@ FIRST
Definition AMReX_ParmParse.H:355
@ LAST
Definition AMReX_ParmParse.H:355
@ ALL
Definition AMReX_ParmParse.H:355
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:1494
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:1469
static void Initialize(int argc, char **argv, const std::string &parfile)
Definition AMReX_ParmParse.H:1714
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:1114
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:1228
int query(const char *new_name, const char *old_name, T &ref)
Definition AMReX_ParmParse.H:1288
Table * m_table
Definition AMReX_ParmParse.H:1811
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:2927
std::string m_parser_prefix
Definition AMReX_ParmParse.H:1810
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:1984
static void dumpTable(std::ostream &os, bool prettyPrint=false)
Definition AMReX_ParmParse.cpp:1815
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:2033
static void prettyPrintUnusedInputs(std::ostream &os)
Definition AMReX_ParmParse.cpp:1885
static std::set< std::string > getEntries(const std::string &prefix=std::string())
Returns [prefix.]* parameters.
Definition AMReX_ParmParse.cpp:1745
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:1552
std::string prefixedName(std::string_view str) const
Definition AMReX_ParmParse.cpp:1633
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:1615
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:1976
int queryAdd(std::string_view name, Vector< T > &ref)
Definition AMReX_ParmParse.H:1088
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:1959
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:1208
std::unordered_map< std::string, PP_entry > Table
Definition AMReX_ParmParse.H:1791
IParser makeIParser(std::string const &func, Vector< std::string > const &vars) const
Definition AMReX_ParmParse.cpp:2970
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:1897
Front-end for parsing scalar expressions into GPU/CPU executors.
Definition AMReX_Parser.H:126
ParserExecutor< N > compileHost() const
Compile the current expression into a host-only executor.
Definition AMReX_Parser.H:273
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:29
amrex_long Long
Definition AMReX_INT.H:30
std::string getEnumNameString(T const &v)
Get the name string of an enum value.
Definition AMReX_Enum.H:190
Definition AMReX_Amr.cpp:50
std::ostream & ErrorStream()
Stream that receives diagnostic output (defaults to std::cerr).
Definition AMReX.cpp:973
BoxND< 3 > Box
Box is an alias for amrex::BoxND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:35
IntVectND(const Array< int, dim > &) -> IntVectND< dim >
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:38
void Error(const std::string &msg)
Print a message to stderr and abort the program.
Definition AMReX.cpp:236
int Verbose() noexcept
Return the verbosity level configured via ParmParse or SetVerbose().
Definition AMReX.cpp:182
void Abort(const std::string &msg)
Print a fatal-error message to stderr and abort execution.
Definition AMReX.cpp:242
Definition AMReX_ParmParse.H:1769
std::variant< std::string *, bool *, int *, long *, long long *, amrex::IntVect *, amrex::Box *, float *, double * > m_typehint
Definition AMReX_ParmParse.H:1787
std::vector< std::vector< std::string > > m_vals
Definition AMReX_ParmParse.H:1774
std::vector< std::vector< QuoteType > > m_quotes
Definition AMReX_ParmParse.H:1775
Long m_count
Definition AMReX_ParmParse.H:1776
std::vector< std::variant< bool, int, long, long long, float, double > > m_last_vals
Definition AMReX_ParmParse.H:1788
bool m_parsed
Definition AMReX_ParmParse.H:1789