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 <utility>
27#include <variant>
28#include <vector>
29
30namespace amrex {
31
32template<int dim>
33class BoxND;
35template<int dim>
36class IntVectND;
38template<int dim>
39class RealVectND;
41
43namespace ppdetail {
44 template <class T, class Enable = void>
45 struct ArithmeticOptional_TT : std::false_type {};
46
47 template <class T>
48 requires (std::is_arithmetic_v<T>)
49 struct ArithmeticOptional_TT<T>
50 : std::true_type
51 {
52 using value_type = T;
53 };
54
55 template <class T>
56 requires (std::is_arithmetic_v<T>)
57 struct ArithmeticOptional_TT<std::optional<T>>
58 : std::true_type
59 {
60 using value_type = T;
61 };
62
63 template <class T>
64 inline constexpr bool IsArithmeticOptional_v = ArithmeticOptional_TT<T>::value;
65
66 template <class T>
67 using underlying_type_t = typename ArithmeticOptional_TT<T>::value_type;
68}
70
71//
72// ParmParse class implements a simple database for the storage and
73// retrieval of command-line and input-file arguments. The entries are
74// stored in a static table in (name,value_list) pairs.
75//
76// The format of the input file is a series of DEFINITIONS.
77//
78// A DEFINITION is of the form <name> = <value> <value> ...
79// The equal sign is important since the list of values can span multiple
80// lines.
81//
82// Comments in an input file include all text from a '#' character to the
83// end of the line. Here is an example input file:
84/*
85 niter = 100 # niter is an integer
86 title = "Double Wammy" # example of a string with spaces
87 cell_size = 0.5 0.75 # cell spacing in each dimension
88 plot.var = Density 1 10 # a list of values
89 plot.var = Energy 5 12 # another list of values
90 bigarray = 1 2 3 4 5 6 7 8 \
91 9 10 11 12 # continuation of bigarray
92 multi_line_string = "This is a
93 multi-line string."
94 my_2d_table = \
95 # col 1 2 3
96 {{ 11.0, 12.0, 13.0 } # row 1
97 { 21.0, 22.0, 23.0 } # row 2
98 { 31.0, 32.0, 33.0 } # row 3
99 { 41.0, 42.0, 43.0 } } # row 4
100 test = apple "boy blue" 10 20 30 40
101 FILE = prob_file # insert contents of this "prob_file" here
102*/
103// For values spanning multiple lines except for table, one must use '\' at
104// the end of a line
105// for continuation, otherwise it's a runtime error. Note that there must be
106// at least one space before the continuation character `\`. Multiple lines
107// inside a pair of double quotes are considered a single string containing
108// '\n's. The "FILE = <filename>" definition is special. Rather than just
109// adding this entry to the database, it reads the contents of <filename>
110// into the database.
111// For CI/CD workflows and out-of-source tests, the environment variable
112// AMREX_INPUTS_FILE_PREFIX can be set to prefix every FILE = <filename>
113// with a custom path.
114//
115// ParmParse stores all entries in a static table which is built the
116// first time a ParmParse object is constructed (usually in main()).
117// Subsequent invocations have access to this table.
118// A ParmParse constructor has an optional "prefix" argument that will
119// limit the searches to only those entries of the table with this prefix
120// in name. For example:
121// ParmParse pp("plot");
122// will find only those entries with name given by "plot.<string>".
123//
124// All values in the table are stored as strings. For example, the
125// values of "cell_size" in the above input file are stored as the
126// strings "0.5" and "0.75". These strings can be returned as either
127// strings or numeric values by the query functions.
128// Character strings with spaces must be delimited by double quotes
129// in the input file but the quotes are stripped before they are entered
130// into the table. For example, 'title' in the above input file has a
131// single value, the string 'Double Wammy' (without the quotes).
132// Each value in the list associated with a definition can be referred to
133// by its index number. The index numbers start at 0 just like an array
134// in the C programming language. Consider the definition of "test" in
135// the above input file. The first value 'apple'is a string with index
136// 0. The second value 'boy blue' is a string with index 1. The
137// remaining four values are integers indexed 2, 3, 4, and 5.
138//
139// For a string value to represent an integer or float it must fit the
140// following regular expression:
141// Sign ::= '+' | '-'
142// Digit ::= '0' | '1' | ... | '9'
143// Integer ::= [Sign]Digit+
144// Exp ::= ('e'|'E')Integer
145// Float ::= ( Integer[.Digit*][Exp] | [Integer].Digit+[Exp] )
146//
147// Where '+' indicates one or more occurrences, '*' represents zero or
148// more occurrences, '|' means one or the other and '[]' represents zero
149// or one occurrence.
150//
151// Note that floats and doubles have the same string representation and
152// that the FORTRAN "double" exponent format is not supported.
153// That is, 1.0d+3 is not a valid representation of a floating point
154// number but that 1.0e+3 is acceptable.
155//
156// There are a host of functions allowing the user to query the database
157// and retrieve values. Here are some general rules about the names of
158// the member functions:
159//
160// * Functions with the string "get" in their names attempt to get a
161// value or an array of values from the table. They generate a
162// run-time error if they are not successful.
163//
164// * Functions with the string "query" in their names attempt to get a
165// value or an array of values from the table. They return the value 1
166// (true) if they are successful and 0 (false) if not.
167//
168// * Functions with the string "kth" in their names get values from
169// the Kth entry with the given name in the database. This is
170// necessary since there may be multiple definitions with the same
171// name in the database.
172//
173// * Functions without the string "kth" in their names get values from
174// the last entry with the given name in the database. Note that the
175// definitions from the command line are appended to the database table
176// and hence will be the last entries.
177//
178// * Functions with the string "arr" in their names get an Array of
179// values from the given entry in the table. The array argument is
180// grown (if necessary) to hold all the values requested, but it is
181// never shrunk.
182//
183// * Functions without the string "arr" in their names get single
184// values from the given entry in the table.
185//
186// The following is a code sample showing how to use ParmParse:
187//
188// main(int argc, char **argv)
189// {
190// char* in_file_name = argv[1];
191// ParmParse::Initialize(argc-2, argv+2, in_file_name);
192//
193// // Query table for value of "niter". If not in table
194// // then set to default value
195// if (!pp.query("niter",niter)) niter = 20;
196//
197// // read array of cell sizes if in table
198// Vector<float> dx;
199// if (nx=pp.countval("cell_size")) {
200// // get nx values starting at index 0 and store in dx.
201// // dx is automatically resized here.
202// pp.getarr("cell_size",dx,0,nx);
203// }
204// ParmParse::Finalize();
205// }
206//
207// void do_graphics()
208// {
209// //
210// // Will only query entries with the "plot" prefix:
211// //
212// ParmParse pp("plot");
213// //
214// // Read all variables with "plot.var" keyword.
215// //
216// std::string var_name;
217// Vector<int> range;
218// int num = pp.countname("var");
219// for (int k = 0; k < num; k++)
220// {
221// //
222// // Element 0 in list is a string.
223// //
224// pp.getkth("var",k,var_name,0);
225// //
226// // Elements 1 and 2 are integers.
227// // Note that "range" will be resized to hold 2 elements.
228// //
229// pp.getktharr("var",k,range,1,2);
230// cout << "variable = " << var_name << "lo, hi = ",
231// << range[0] << " " << range[1] << endl;
232// }
233// }
234// -----------------------------------------------------------------
235// ----------------------- END COMMENTS ---------------------------
236// -----------------------------------------------------------------
237
238
355{
356public:
357 enum { LAST = -1, FIRST = 0, ALL = -1 };
365 explicit ParmParse (std::string prefix = std::string(),
366 std::string parser_prefix = std::string());
367
369 [[nodiscard]] bool contains (std::string_view name) const;
375 [[nodiscard]] int countval (std::string_view name, int n = LAST) const;
380 [[nodiscard]] int countname (std::string_view name) const;
392 void getkth (std::string_view name,
393 int k,
394 bool& ref,
395 int ival = FIRST) const;
397 void get (std::string_view name,
398 bool& ref,
399 int ival = FIRST) const;
407 int querykth (std::string_view name,
408 int k,
409 bool& ref,
410 int ival = FIRST) const;
412 int query (std::string_view name,
413 bool& ref,
414 int ival = FIRST) const;
416 void add (std::string_view name, bool val);
426 void getkth (std::string_view name,
427 int k,
428 int& ref,
429 int ival = FIRST) const;
430
432 void get (std::string_view name,
433 int& ref,
434 int ival = FIRST) const;
442 int querykth (std::string_view name,
443 int k,
444 int& ref,
445 int ival = FIRST) const;
447 int query (std::string_view name,
448 int& ref,
449 int ival = FIRST) const;
451 void add (std::string_view name, int val);
461 void getkth (std::string_view name,
462 int k,
463 long& ref,
464 int ival = FIRST) const;
466 void get (std::string_view name,
467 long& ref,
468 int ival = FIRST) const;
476 int querykth (std::string_view name,
477 int k,
478 long& ref,
479 int ival = FIRST) const;
481 int query (std::string_view name,
482 long& ref,
483 int ival = FIRST) const;
485 void add (std::string_view name, long val);
495 void getkth (std::string_view name,
496 int k,
497 long long& ref,
498 int ival = FIRST) const;
500 void get (std::string_view name,
501 long long& ref,
502 int ival = FIRST) const;
510 int querykth (std::string_view name,
511 int k,
512 long long& ref,
513 int ival = FIRST) const;
515 int query (std::string_view name,
516 long long& ref,
517 int ival = FIRST) const;
519 void add (std::string_view name, long long val);
529 void getkth (std::string_view name,
530 int k,
531 float& ref,
532 int ival = FIRST) const;
534 void get (std::string_view name,
535 float& ref,
536 int ival = FIRST) const;
544 int querykth (std::string_view name,
545 int k,
546 float& ref,
547 int ival = FIRST) const;
549 int query (std::string_view name,
550 float& ref,
551 int ival = FIRST) const;
553 void add (std::string_view name, float val);
563 void getkth (std::string_view name,
564 int k,
565 double& ref,
566 int ival = FIRST) const;
568 void get (std::string_view name,
569 double& ref,
570 int ival = FIRST) const;
578 int querykth (std::string_view name,
579 int k,
580 double& ref,
581 int ival = FIRST) const;
583 int query (std::string_view name,
584 double& ref,
585 int ival = FIRST) const;
587 void add (std::string_view name, double val);
597 void getkth (std::string_view name,
598 int k,
599 std::string& ref,
600 int ival = FIRST) const;
601
603 void get (std::string_view name,
604 std::string& ref,
605 int ival = FIRST) const;
613 int querykth (std::string_view name,
614 int k,
615 std::string& ref,
616 int ival = FIRST) const;
618 int query (std::string_view name,
619 std::string& ref,
620 int ival = FIRST) const;
622 void add (std::string_view name, const std::string& val);
623
625 void add (std::string_view name, const char* val) { add(name, std::string(val)); }
626
635 void getline (std::string_view name, std::string& ref) const;
636
645 int queryline (std::string_view name, std::string& ref) const;
646
656 void getkth (std::string_view name,
657 int k,
658 IntVect& ref,
659 int ival = FIRST) const;
661 void get (std::string_view name,
662 IntVect& ref,
663 int ival = FIRST) const;
671 int querykth (std::string_view name,
672 int k,
673 IntVect& ref,
674 int ival = FIRST) const;
676 int query (std::string_view name,
677 IntVect& ref,
678 int ival = FIRST) const;
680 void add (std::string_view name, const IntVect& val);
690 void getkth (std::string_view name,
691 int k,
692 Box& ref,
693 int ival = FIRST) const;
695 void get (std::string_view name,
696 Box& ref,
697 int ival = FIRST) const;
705 int querykth (std::string_view name,
706 int k,
707 Box& ref,
708 int ival = FIRST) const;
710 int query (std::string_view name,
711 Box& ref,
712 int ival = FIRST) const;
714 void add (std::string_view name, const Box& val);
728 void getktharr (std::string_view name,
729 int k,
730 std::vector<int>& ref,
731 int start_ix = FIRST,
732 int num_val = ALL) const;
734 void getarr (std::string_view name,
735 std::vector<int>& ref,
736 int start_ix = FIRST,
737 int num_val = ALL) const;
739 int queryktharr (std::string_view name,
740 int k,
741 std::vector<int>& ref,
742 int start_ix = FIRST,
743 int num_val = ALL) const;
745 int queryarr (std::string_view name,
746 std::vector<int>& ref,
747 int start_ix = FIRST,
748 int num_val = ALL) const;
750 void addarr (std::string_view name, const std::vector<int>& ref);
751
765 void getktharr (std::string_view name,
766 int k,
767 std::vector<long>& ref,
768 int start_ix = FIRST,
769 int num_val = ALL) const;
771 void getarr (std::string_view name,
772 std::vector<long>& ref,
773 int start_ix = FIRST,
774 int num_val = ALL) const;
776 int queryktharr (std::string_view name,
777 int k,
778 std::vector<long>& ref,
779 int start_ix = FIRST,
780 int num_val = ALL) const;
782 int queryarr (std::string_view name,
783 std::vector<long>& ref,
784 int start_ix = FIRST,
785 int num_val = ALL) const;
787 void addarr (std::string_view name, const std::vector<long>& ref);
788
802 void getktharr (std::string_view name,
803 int k,
804 std::vector<long long>& ref,
805 int start_ix = FIRST,
806 int num_val = ALL) const;
808 void getarr (std::string_view name,
809 std::vector<long long>& ref,
810 int start_ix = FIRST,
811 int num_val = ALL) const;
813 int queryktharr (std::string_view name,
814 int k,
815 std::vector<long long>& ref,
816 int start_ix = FIRST,
817 int num_val = ALL) const;
819 int queryarr (std::string_view name,
820 std::vector<long long>& ref,
821 int start_ix = FIRST,
822 int num_val = ALL) const;
824 void addarr (std::string_view name, const std::vector<long long>& ref);
825
839 void getktharr (std::string_view name,
840 int k,
841 std::vector<float>& ref,
842 int start_ix = FIRST,
843 int num_val = ALL) const;
845 void getarr (std::string_view name,
846 std::vector<float>& ref,
847 int start_ix = FIRST,
848 int num_val = ALL) const;
850 int queryktharr (std::string_view name,
851 int k,
852 std::vector<float>& ref,
853 int start_ix = FIRST,
854 int num_val = ALL) const;
856 int queryarr (std::string_view name,
857 std::vector<float>& ref,
858 int start_ix = FIRST,
859 int num_val = ALL) const;
861 void addarr (std::string_view name, const std::vector<float>& ref);
875 void getktharr (std::string_view name,
876 int k,
877 std::vector<double>& ref,
878 int start_ix = FIRST,
879 int num_val = ALL) const;
881 void getarr (std::string_view name,
882 std::vector<double>& ref,
883 int start_ix = FIRST,
884 int num_val = ALL) const;
886 int queryktharr (std::string_view name,
887 int k,
888 std::vector<double>& ref,
889 int start_ix = FIRST,
890 int num_val = ALL) const;
892 int queryarr (std::string_view name,
893 std::vector<double>& ref,
894 int start_ix = FIRST,
895 int num_val = ALL) const;
897 void addarr (std::string_view name, const std::vector<double>& ref);
912 void getktharr (std::string_view name,
913 int k,
914 std::vector<std::string>& ref,
915 int start_ix = FIRST,
916 int num_val = ALL) const;
918 void getarr (std::string_view name,
919 std::vector<std::string>& ref,
920 int start_ix = FIRST,
921 int num_val = ALL) const;
923 int queryktharr (std::string_view name,
924 int k,
925 std::vector<std::string>& ref,
926 int start_ix = FIRST,
927 int num_val = ALL) const;
929 int queryarr (std::string_view name,
930 std::vector<std::string>& ref,
931 int start_ix = FIRST,
932 int num_val = ALL) const;
934 void addarr (std::string_view name, const std::vector<std::string>& ref);
949 void getktharr (std::string_view name,
950 int k,
951 std::vector<IntVect>& ref,
952 int start_ix = FIRST,
953 int num_val = ALL) const;
955 void getarr (std::string_view name,
956 std::vector<IntVect>& ref,
957 int start_ix = FIRST,
958 int num_val = ALL) const;
960 int queryktharr (std::string_view name,
961 int k,
962 std::vector<IntVect>& ref,
963 int start_ix = FIRST,
964 int num_val = ALL) const;
966 int queryarr (std::string_view name,
967 std::vector<IntVect>& ref,
968 int start_ix = FIRST,
969 int num_val = ALL) const;
971 void addarr (std::string_view name, const std::vector<IntVect>& ref);
986 void getktharr (std::string_view name,
987 int k,
988 std::vector<Box>& ref,
989 int start_ix = FIRST,
990 int num_val = ALL) const;
992 void getarr (std::string_view name,
993 std::vector<Box>& ref,
994 int start_ix = FIRST,
995 int num_val = ALL) const;
997 int queryktharr (std::string_view name,
998 int k,
999 std::vector<Box>& ref,
1000 int start_ix = FIRST,
1001 int num_val = ALL) const;
1003 int queryarr (std::string_view name,
1004 std::vector<Box>& ref,
1005 int start_ix = FIRST,
1006 int num_val = ALL) const;
1008 void addarr (std::string_view name, const std::vector<Box>& ref);
1009
1010 /*
1011 * \brief Query IntVect from array
1012 *
1013 * This reads IntVect from an array (e.g., `8 16 8`), not the format
1014 * using parentheses (e.g., `(8,16,8)`).
1015 */
1016 int queryarr (std::string_view name, IntVect& ref) const;
1017
1018 /*
1019 * \brief Get IntVect from array
1020 *
1021 * This reads IntVect from an array (e.g., `8 16 8`), not the format
1022 * using parentheses (e.g., `(8,16,8)`).
1023 */
1024 void getarr (std::string_view name, IntVect& ref) const;
1025
1027 int queryarr (std::string_view name, RealVect& ref) const;
1028
1030 void getarr (std::string_view name, RealVect& ref) const;
1031
1032 template <typename T, std::size_t N>
1033 void get (std::string_view name, std::array<T,N>& ref) const {
1034 std::vector<T> v;
1035 this->getarr(name, v);
1036 AMREX_ALWAYS_ASSERT(v.size() >= N);
1037 for (std::size_t i = 0; i < N; ++i) {
1038 ref[i] = v[i];
1039 }
1040 }
1041
1042 template <typename T, std::size_t N>
1043 int query (std::string_view name, std::array<T,N>& ref) const {
1044 std::vector<T> v;
1045 int exist = this->queryarr(name, v);
1046 if (exist) {
1047 AMREX_ALWAYS_ASSERT(v.size() >= N);
1048 for (std::size_t i = 0; i < N; ++i) {
1049 ref[i] = v[i];
1050 }
1051 }
1052 return exist;
1053 }
1054
1061 template <typename T>
1062 int queryAdd (std::string_view name, T& ref) {
1063 int exist = this->query(name, ref);
1064 if (!exist) {
1065 this->add(name, ref);
1066 }
1067 return exist;
1068 }
1069
1070 int queryAdd (std::string_view name, std::string& ref) {
1071 int exist = this->query(name, ref);
1072 if (!exist && !ref.empty()) {
1073 this->add(name, ref);
1074 }
1075 return exist;
1076 }
1077
1087 template <typename T>
1088 int queryAdd (std::string_view name, std::vector<T>& ref) {
1089 std::vector<T> empty;
1090 int exist = this->queryarr(name, empty);
1091 if (exist) {
1092 ref = std::move(empty);
1093 }
1094 if (!exist && !ref.empty()) {
1095 this->addarr(name, ref);
1096 }
1097 return exist;
1098 }
1099
1100 template <typename T>
1101 int queryAdd (std::string_view name, Vector<T>& ref) {
1102 return this->queryAdd(name, static_cast<std::vector<T>&>(ref));
1103 }
1104
1111 template <typename T>
1112 int queryAdd (std::string_view name, std::vector<T>& ref, int num_val) {
1113 int exist = this->queryarr(name, ref, 0, num_val);
1114 if (!exist) {
1115 this->addarr(name, ref);
1116 }
1117 return exist;
1118 }
1119
1126 template <typename T, std::size_t N>
1127 int queryAdd (std::string_view name, std::array<T,N>& ref) {
1128 std::vector<T> v;
1129 int exist = this->queryarr(name, v);
1130 if (exist) {
1131 AMREX_ALWAYS_ASSERT(v.size() >= N);
1132 for (std::size_t i = 0; i < N; ++i) {
1133 ref[i] = v[i];
1134 }
1135 } else {
1136 v.resize(N);
1137 for (std::size_t i = 0; i < N; ++i) {
1138 v[i] = ref[i];
1139 }
1140 this->addarr(name, v);
1141 }
1142 return exist;
1143 }
1144
1151 int queryWithParser (std::string_view name, bool& ref) const;
1152 int queryWithParser (std::string_view name, int& ref) const;
1153 int queryWithParser (std::string_view name, long& ref) const;
1154 int queryWithParser (std::string_view name, long long& ref) const;
1155 int queryWithParser (std::string_view name, float& ref) const;
1156 int queryWithParser (std::string_view name, double& ref) const;
1157
1164 int queryarrWithParser (std::string_view name, int nvals, bool* ptr) const;
1165 int queryarrWithParser (std::string_view name, int nvals, int* ptr) const;
1166 int queryarrWithParser (std::string_view name, int nvals, long* ptr) const;
1167 int queryarrWithParser (std::string_view name, int nvals, long long* ptr) const;
1168 int queryarrWithParser (std::string_view name, int nvals, float* ptr) const;
1169 int queryarrWithParser (std::string_view name, int nvals, double* ptr) const;
1170 template <typename T>
1171 requires (std::same_as<T,bool> ||
1172 std::same_as<T,int> ||
1173 std::same_as<T,long> ||
1174 std::same_as<T,long long> ||
1175 std::same_as<T,float> ||
1176 std::same_as<T,double>)
1177 int queryarrWithParser (std::string_view name, int nvals, std::vector<T>& ref) const
1178 {
1179 if (this->contains(name)) {
1180 if (int(ref.size()) < nvals) { ref.resize(nvals); }
1181 return this->queryarrWithParser(name, nvals, ref.data());
1182 } else {
1183 return 0;
1184 }
1185 }
1186
1193 template <typename T>
1194 requires (std::same_as<T,bool> ||
1195 std::same_as<T,int> ||
1196 std::same_as<T,long> ||
1197 std::same_as<T,long long> ||
1198 std::same_as<T,float> ||
1199 std::same_as<T,double>)
1200 int queryAddWithParser (std::string_view name, T& ref)
1201 {
1202 int exist = this->queryWithParser(name, ref);
1203 if (!exist) {
1204 this->add(name, ref);
1205 }
1206 return exist;
1207 }
1208
1214 template <typename T>
1215 requires (std::same_as<T,bool> ||
1216 std::same_as<T,int> ||
1217 std::same_as<T,long> ||
1218 std::same_as<T,long long> ||
1219 std::same_as<T,float> ||
1220 std::same_as<T,double>)
1221 void getWithParser (std::string_view name, T& ref) const
1222 {
1223 int exist = this->queryWithParser(name, ref);
1224 if (!exist) {
1225 amrex::Error(std::string("ParmParse::getWithParser: failed to get ")+std::string(name));
1226 }
1227 }
1228
1234 template <typename T>
1235 requires (std::same_as<T,bool> ||
1236 std::same_as<T,int> ||
1237 std::same_as<T,long> ||
1238 std::same_as<T,long long> ||
1239 std::same_as<T,float> ||
1240 std::same_as<T,double>)
1241 void getarrWithParser (std::string_view name, int nvals, T* ptr) const
1242 {
1243 int exist = this->queryarrWithParser(name, nvals, ptr);
1244 if (!exist) {
1245 amrex::Error(std::string("ParmParse::getarrWithParser: failed to get ")+std::string(name));
1246 }
1247 }
1248
1254 template <typename T>
1255 requires (std::same_as<T,bool> ||
1256 std::same_as<T,int> ||
1257 std::same_as<T,long> ||
1258 std::same_as<T,long long> ||
1259 std::same_as<T,float> ||
1260 std::same_as<T,double>)
1261 void getarrWithParser (std::string_view name, int nvals, std::vector<T>& ref) const
1262 {
1263 int exist = this->queryarrWithParser(name, nvals, ref);
1264 if (!exist) {
1265 amrex::Error(std::string("ParmParse::getarrWithParser: failed to get ")+std::string(name));
1266 }
1267 }
1268
1269 /*
1270 * \brief Evaluate given string as math expression
1271 *
1272 * For unknown symbols, ParmParse database will be queried.
1273 */
1274 template <typename T>
1275 requires (std::same_as<T,bool> ||
1276 std::same_as<T,int> ||
1277 std::same_as<T,long> ||
1278 std::same_as<T,long long> ||
1279 std::same_as<T,float> ||
1280 std::same_as<T,double>)
1281 [[nodiscard]] T eval (std::string const& expr) const
1282 {
1283 if constexpr (std::is_integral_v<T>) {
1284 auto const parser = this->makeIParser(expr, {});
1285 auto const exe = parser.compileHost<0>();
1286 auto const v = exe();
1287 if constexpr (!std::same_as<T,bool>) {
1288 if (!std::in_range<T>(v)) {
1289 amrex::Error("ParmParse::eval: "+expr+" evaluates to "+std::to_string(v)
1290 +", which is out of range for its type");
1291 }
1292 }
1293 return static_cast<T>(v);
1294 } else {
1295 auto const parser = this->makeParser(expr, {});
1296 auto const exe = parser.compileHost<0>();
1297 return static_cast<T>(exe());
1298 }
1299 }
1300
1301 /*
1302 * \brief Query two names.
1303 *
1304 * This function queries with `new_name` first. If it's not found, it
1305 * will try again with `old_name`.
1306 */
1307 template <typename T>
1308 int query (const char* new_name, const char* old_name, T& ref)
1309 {
1310 return (this->query(new_name, ref) ||
1311 this->query(old_name, ref));
1312 }
1313
1321 template <typename T>
1322 void get (const char* new_name, const char* old_name, T& ref)
1323 {
1324 auto exist = this->query(new_name, old_name, ref);
1325 if (!exist) {
1326 amrex::ErrorStream() << "ParmParse::get failed to find "
1327 << new_name << " and " << old_name << '\n';
1329 amrex::Abort();
1330 }
1331 }
1332
1341 template <typename T, typename ET = amrex_enum_traits<T>>
1342 requires (ET::value)
1343 int query (std::string_view name, T& ref, int ival = FIRST) const
1344 {
1345 std::string s;
1346 int exist = this->query(name, s, ival);
1347 if (exist) {
1348 try {
1349 ref = amrex::getEnum<T>(s);
1350 } catch (...) {
1351 if (amrex::Verbose() > 0 ) {
1352 amrex::Print() << "amrex::ParmParse::query (input name: "
1353 << this->prefixedName(name) << "):\n";
1354 }
1355 throw;
1356 }
1357 }
1358 return exist;
1359 }
1360
1361
1364 template <typename T, typename ET = amrex_enum_traits<T>>
1365 requires (ET::value)
1366 void add (std::string_view name, T const& val)
1367 {
1368 this->add(name, amrex::getEnumNameString(val));
1369 }
1370
1379 template <typename T, typename ET = amrex_enum_traits<T>>
1380 requires (ET::value)
1381 void get (std::string_view name, T& ref, int ival = FIRST) const
1382 {
1383 std::string s;
1384 this->get(name, s, ival);
1385 try {
1386 ref = amrex::getEnum<T>(s);
1387 } catch (...) {
1388 if (amrex::Verbose() > 0 ) {
1389 amrex::Print() << "amrex::ParmParse::get (input name: "
1390 << this->prefixedName(name) << "):\n";
1391 }
1392 throw;
1393 }
1394 }
1395
1398 template <typename T, typename ET = amrex_enum_traits<T>>
1399 requires (ET::value)
1400 int queryarr (std::string_view name,
1401 std::vector<T>& ref,
1402 int start_ix = FIRST,
1403 int num_val = ALL) const
1404 {
1405 std::vector<std::string> s;
1406 int exist = this->queryarr(name, s, start_ix, num_val);
1407 if (exist) {
1408 // As in the other array overloads, grow the vector if
1409 // necessary, but do not shrink it.
1410 if (ref.size() < s.size()) { ref.resize(s.size()); }
1411 for (auto i = std::size_t(start_ix); i < s.size(); ++i) {
1412 try {
1413 ref[i] = amrex::getEnum<T>(s[i]);
1414 } catch (...) {
1415 if (amrex::Verbose() > 0 ) {
1416 amrex::Print() << "amrex::ParmParse::queryarr (input name: "
1417 << this->prefixedName(name) << "):\n";
1418 }
1419 throw;
1420 }
1421 }
1422 }
1423 return exist;
1424 }
1425
1428 template <typename T, typename ET = amrex_enum_traits<T>>
1429 requires (ET::value)
1430 void getarr (std::string_view name,
1431 std::vector<T>& ref,
1432 int start_ix = FIRST,
1433 int num_val = ALL) const
1434 {
1435 std::vector<std::string> s;
1436 this->getarr(name, s, start_ix, num_val);
1437 // As in the other array overloads, grow the vector if
1438 // necessary, but do not shrink it.
1439 if (ref.size() < s.size()) { ref.resize(s.size()); }
1440 for (auto i = std::size_t(start_ix); i < s.size(); ++i) {
1441 try {
1442 ref[i] = amrex::getEnum<T>(s[i]);
1443 } catch (...) {
1444 if (amrex::Verbose() > 0 ) {
1445 amrex::Print() << "amrex::ParmParse::getarr (input name: "
1446 << this->prefixedName(name) << "):\n";
1447 }
1448 throw;
1449 }
1450 }
1451 }
1452
1463 template <typename T, typename ET = amrex_enum_traits<T>>
1464 requires (ET::value)
1465 int query_enum_case_insensitive (std::string_view name, T& ref, int ival = FIRST) const
1466 {
1467 std::string s;
1468 int exist = this->query(name, s, ival);
1469 if (exist) {
1470 try {
1472 } catch (...) {
1473 if (amrex::Verbose() > 0) {
1474 amrex::Print() << "amrex::ParmParse::query_enum_case_insensitive (input name: "
1475 << this->prefixedName(name) << "):\n";
1476 }
1477 throw;
1478 }
1479 }
1480 return exist;
1481 }
1482
1493 template <typename T, typename ET = amrex_enum_traits<T>>
1494 requires (ET::value)
1495 void get_enum_case_insensitive (std::string_view name, T& ref, int ival = FIRST) const
1496 {
1497 int exist = this->query_enum_case_insensitive(name, ref, ival);
1498 if (!exist) {
1499 std::string msg("get_enum_case_insensitive(\"");
1500 msg.append(name).append("\",").append(amrex::getEnumClassName<T>())
1501 .append("&) failed.");
1502 amrex::Abort(msg);
1503 }
1504 }
1505
1518 template <typename T, typename ET = amrex_enum_traits<T>>
1519 requires (ET::value)
1520 int query_enum_sloppy (std::string_view name, T& ref, std::string_view const& ignores,
1521 int ival = FIRST) const
1522 {
1523 std::string s;
1524 int exist = this->query(name, s, ival);
1525 if (exist) {
1526 try {
1527 std::erase_if(s, [&] (auto const& c) {
1528 return ignores.find(c) != std::string_view::npos;
1529 });
1531 } catch (...) {
1532 if (amrex::Verbose() > 0) {
1533 amrex::Print() << "amrex::ParmParse::query_enum_sloppy (input name: "
1534 << this->prefixedName(name) << "):\n";
1535 }
1536 throw;
1537 }
1538 }
1539 return exist;
1540 }
1541
1554 template <typename T, typename ET = amrex_enum_traits<T>>
1555 requires (ET::value)
1556 void get_enum_sloppy (std::string_view name, T& ref, std::string_view const& ignores,
1557 int ival = FIRST) const
1558 {
1559 int exist = this->query_enum_sloppy(name, ref, ignores, ival);
1560 if (!exist) {
1561 std::string msg("get_enum_sloppy(\"");
1562 msg.append(name).append("\",").append(amrex::getEnumClassName<T>())
1563 .append("&) failed.");
1564 amrex::Abort(msg);
1565 }
1566 }
1567
1576 template <typename T>
1577 requires (ppdetail::IsArithmeticOptional_v<T>)
1578 int queryAsDouble (std::string_view name, T& ref) const
1579 {
1580 using value_type = ppdetail::underlying_type_t<T>;
1581 double dref;
1582 int exist = queryWithParser(name, dref);
1583 if (exist) {
1584 if constexpr (std::is_integral_v<value_type>) {
1585 dref = std::round(dref);
1586 }
1587 if constexpr (std::is_integral_v<value_type> && !std::is_same_v<value_type,bool>) {
1588 // Range check before the cast, which would otherwise be UB.
1589 // 2^digits, exact; avoids std::ldexp (NVHPC SCALEFS crash on Zen 4 w/o AVX-512)
1590 constexpr double upper = 2.0 * static_cast<double>(std::numeric_limits<value_type>::max()/2 + 1); // NOLINT(bugprone-integer-division)
1591 if (!(dref >= static_cast<double>(std::numeric_limits<value_type>::lowest()) &&
1592 dref < upper)) {
1593 amrex::Abort("ParmParse:: queryAsDouble is not safe");
1594 }
1595 }
1596 ref = static_cast<value_type>(dref);
1597 }
1598 return exist;
1599 }
1600
1609 template <typename T>
1610 requires (ppdetail::IsArithmeticOptional_v<T>)
1611 int queryarrAsDouble (std::string_view name, int nvals, T* ptr) const
1612 {
1613 using value_type = ppdetail::underlying_type_t<T>;
1614 std::vector<double> dref(nvals);
1615 int exist = queryarrWithParser(name, nvals, dref.data());
1616 if (exist) {
1617 for (int i = 0; i < nvals; ++i) {
1618 if constexpr (std::is_integral_v<value_type>) {
1619 dref[i] = std::round(dref[i]);
1620 }
1621 if constexpr (std::is_integral_v<value_type> && !std::is_same_v<value_type,bool>) {
1622 // 2^digits, exact; avoids std::ldexp (NVHPC SCALEFS crash on Zen 4 w/o AVX-512)
1623 constexpr double upper = 2.0 * static_cast<double>(std::numeric_limits<value_type>::max()/2 + 1); // NOLINT(bugprone-integer-division)
1624 if (!(dref[i] >= static_cast<double>(std::numeric_limits<value_type>::lowest()) &&
1625 dref[i] < upper)) {
1626 amrex::Abort("ParmParse:: queryarrAsDouble is not safe");
1627 }
1628 }
1629 ptr[i] = static_cast<value_type>(dref[i]);
1630 }
1631 }
1632 return exist;
1633 }
1634
1643 template <typename T>
1644 requires (ppdetail::IsArithmeticOptional_v<T>)
1645 void getAsDouble (std::string_view name, T& ref) const
1646 {
1647 int exist = this->queryAsDouble(name, ref);
1648 if (!exist) {
1649 amrex::Error(std::string("ParmParse::getAsDouble: failed to get ")+std::string(name));
1650 }
1651 }
1652
1661 template <typename T>
1662 requires (ppdetail::IsArithmeticOptional_v<T>)
1663 void getarrAsDouble (std::string_view name, int nvals, T* ptr) const
1664 {
1665 int exist = this->queryarrAsDouble(name, nvals, ptr);
1666 if (!exist) {
1667 amrex::Error(std::string("ParmParse::getarrAsDouble: failed to get ")+std::string(name));
1668 }
1669 }
1670
1672 int remove (std::string_view name);
1673
1677 [[nodiscard]] Parser makeParser (std::string const& func,
1678 Vector<std::string> const& vars) const;
1679
1683 [[nodiscard]] IParser makeIParser (std::string const& func,
1684 Vector<std::string> const& vars) const;
1685
1691 int querytable (std::string_view name, std::vector<std::vector<double>>& ref) const;
1692 int querytable (std::string_view name, std::vector<std::vector<float>>& ref) const;
1693 int querytable (std::string_view name, std::vector<std::vector<int>>& ref) const;
1694
1700 template <typename T>
1701 void gettable (std::string_view name, std::vector<std::vector<T>>& ref) const
1702 {
1703 if (this->querytable(name, ref) == 0) {
1704 amrex::ErrorStream() << "ParmParse::gettable: " << name
1705 << " not found in database\n";
1707 amrex::Abort();
1708 }
1709 }
1710
1716 int queryarr (std::string_view name, std::vector<std::vector<double>>& ref) const;
1717 int queryarr (std::string_view name, std::vector<std::vector<float>>& ref) const;
1718 int queryarr (std::string_view name, std::vector<std::vector<int>>& ref) const;
1719 int queryarr (std::string_view name, std::vector<std::vector<std::string>>& ref) const;
1720
1725 template <typename T>
1726 void getarr (std::string_view name, std::vector<std::vector<T>>& ref) const
1727 {
1728 if (this->queryarr(name, ref) == 0) {
1729 amrex::ErrorStream() << "ParmParse::getarr: " << name
1730 << " not found in database\n";
1732 amrex::Abort();
1733 }
1734 }
1735
1743 static void Initialize (int argc, char** argv, const char* parfile);
1744 static void Initialize (int argc, char** argv, const std::string& parfile) {
1745 Initialize(argc, argv, parfile.c_str());
1746 }
1747
1751 static void Finalize ();
1752
1754 static void SetParserPrefix (std::string a_prefix);
1755
1756 static int Verbose ();
1757 static void SetVerbose (int v);
1758
1762 static void dumpTable (std::ostream& os, bool prettyPrint = false);
1763
1767 static void prettyPrintTable (std::ostream& os);
1768
1771 static void prettyPrintUnusedInputs (std::ostream& os);
1772
1775 static void prettyPrintUsedInputs (std::ostream& os);
1776
1781 static void addfile (std::string const& filename);
1782
1783 static bool QueryUnusedInputs ();
1784
1786 [[nodiscard]] static bool hasUnusedInputs (const std::string& prefix = std::string());
1787
1789 [[nodiscard]] static std::vector<std::string> getUnusedInputs (const std::string& prefix = std::string());
1790
1792 [[nodiscard]] static std::set<std::string> getEntries (const std::string& prefix = std::string());
1793
1794 enum class QuoteType : unsigned char {
1795 None = 0,
1798 };
1799
1800 struct PP_entry {
1801 // There can be multiple occurrences for a given name (e.g.,
1802 // multiple lines starting with `foo =` in inputs. For each
1803 // occurrence, there can be multiple values. Thus, the use of
1804 // vector<vector<std::string>>.
1805 std::vector<std::vector<std::string>> m_vals;
1806 std::vector<std::vector<QuoteType>> m_quotes;
1807 mutable Long m_count = 0;
1808 mutable std::variant<
1809 std::string*,
1810 bool*,
1811 int*,
1812 long*,
1813 long long*,
1815 amrex::Box*,
1816 float*,
1817 double*
1818 > m_typehint = static_cast<std::string*>(nullptr);
1819 mutable std::vector<std::variant<bool, int, long, long long, float, double>> m_last_vals;
1820 mutable bool m_parsed = false;
1821 };
1822 using Table = std::unordered_map<std::string, PP_entry>;
1823
1824 [[nodiscard]] const Table& table() const {return *m_table;}
1825
1827 static std::string const FileKeyword;
1828
1830 static std::string const UnsetKeyword;
1831
1832 static std::string ParserPrefix;
1833
1834 [[nodiscard]] std::string const& getPrefix () const;
1835
1836 [[nodiscard]] std::string prefixedName (std::string_view str) const;
1837
1838protected:
1839
1840 std::string m_prefix; // Prefix used in keyword search
1841 std::string m_parser_prefix; // Prefix used by Parser
1843};
1844
1845}
1846
1847#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.
A Rectangular Domain on an Integer Lattice.
Definition AMReX_Box.H:54
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
An Integer Vector in dim-Dimensional Space.
Definition AMReX_IntVect.H:156
QuoteType
Definition AMReX_ParmParse.H:1794
@ Triple
Definition AMReX_ParmParse.H:1797
@ None
Definition AMReX_ParmParse.H:1795
@ Double
Definition AMReX_ParmParse.H:1796
int queryline(std::string_view name, std::string &ref) const
Definition AMReX_ParmParse.cpp:2801
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:2816
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:1088
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:1062
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:1701
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:3101
int query(std::string_view name, std::array< T, N > &ref) const
Definition AMReX_ParmParse.H:1043
static std::string const UnsetKeyword
keyword for removing entries from the table
Definition AMReX_ParmParse.H:1830
static void prettyPrintTable(std::ostream &os)
Definition AMReX_ParmParse.cpp:1935
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:1733
static void addfile(std::string const &filename)
Definition AMReX_ParmParse.cpp:1702
@ FIRST
Definition AMReX_ParmParse.H:357
@ LAST
Definition AMReX_ParmParse.H:357
@ ALL
Definition AMReX_ParmParse.H:357
static std::string const FileKeyword
keyword for files to load
Definition AMReX_ParmParse.H:1827
static std::string ParserPrefix
Definition AMReX_ParmParse.H:1832
static int Verbose()
Definition AMReX_ParmParse.cpp:1814
static void SetVerbose(int v)
Definition AMReX_ParmParse.cpp:1827
void get(const char *new_name, const char *old_name, T &ref)
Get using two names.
Definition AMReX_ParmParse.H:1322
static bool hasUnusedInputs(const std::string &prefix=std::string())
Any unused [prefix.]* parameters?
Definition AMReX_ParmParse.cpp:1765
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:1611
Parser makeParser(std::string const &func, Vector< std::string > const &vars) const
Definition AMReX_ParmParse.cpp:3019
int queryAdd(std::string_view name, std::string &ref)
Definition AMReX_ParmParse.H:1070
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:2108
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:1663
static bool QueryUnusedInputs()
Definition AMReX_ParmParse.cpp:1750
void getline(std::string_view name, std::string &ref) const
Definition AMReX_ParmParse.cpp:2793
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:2099
void add(std::string_view name, const char *val)
Convert const char * to string, to prevent auto-conversion to bool.
Definition AMReX_ParmParse.H:625
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:2006
bool contains(std::string_view name) const
Returns true if name is in table.
Definition AMReX_ParmParse.cpp:2832
void get(std::string_view name, std::array< T, N > &ref) const
Definition AMReX_ParmParse.H:1033
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:1726
static void prettyPrintUsedInputs(std::ostream &os)
Definition AMReX_ParmParse.cpp:1947
static void Finalize()
The destructor. The internal static table will only be deleted if there are no other ParmParse object...
Definition AMReX_ParmParse.cpp:1833
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:1112
std::string m_prefix
Definition AMReX_ParmParse.H:1840
const Table & table() const
Definition AMReX_ParmParse.H:1824
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:1200
T eval(std::string const &expr) const
Definition AMReX_ParmParse.H:1281
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:2023
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:1556
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:1465
static void SetParserPrefix(std::string a_prefix)
Set prefix used by math expression Parser.
Definition AMReX_ParmParse.cpp:1863
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:2947
static std::vector< std::string > getUnusedInputs(const std::string &prefix=std::string())
Returns unused [prefix.]* parameters.
Definition AMReX_ParmParse.cpp:1771
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:2127
std::string const & getPrefix() const
Definition AMReX_ParmParse.cpp:1682
int remove(std::string_view name)
Remove given name from the table.
Definition AMReX_ParmParse.cpp:2848
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:2118
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:1520
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:1495
static void Initialize(int argc, char **argv, const std::string &parfile)
Definition AMReX_ParmParse.H:1744
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:1127
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:1241
int query(const char *new_name, const char *old_name, T &ref)
Definition AMReX_ParmParse.H:1308
Table * m_table
Definition AMReX_ParmParse.H:1842
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:2983
std::string m_parser_prefix
Definition AMReX_ParmParse.H:1841
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:2040
static void dumpTable(std::ostream &os, bool prettyPrint=false)
Definition AMReX_ParmParse.cpp:1871
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:2089
static void prettyPrintUnusedInputs(std::ostream &os)
Definition AMReX_ParmParse.cpp:1941
static std::set< std::string > getEntries(const std::string &prefix=std::string())
Returns [prefix.]* parameters.
Definition AMReX_ParmParse.cpp:1801
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:1578
std::string prefixedName(std::string_view str) const
Definition AMReX_ParmParse.cpp:1688
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:1645
ParmParse(std::string prefix=std::string(), std::string parser_prefix=std::string())
Construct an additional ParmParse object sharing the same internal table as any other such objects in...
Definition AMReX_ParmParse.cpp:50
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:2032
int queryAdd(std::string_view name, Vector< T > &ref)
Definition AMReX_ParmParse.H:1101
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:2015
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:1221
std::unordered_map< std::string, PP_entry > Table
Definition AMReX_ParmParse.H:1822
IParser makeIParser(std::string const &func, Vector< std::string > const &vars) const
Definition AMReX_ParmParse.cpp:3026
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:1953
Front-end for parsing scalar expressions into GPU/CPU executors.
Definition AMReX_Parser.H:160
ParserExecutor< N > compileHost() const
Compile the current expression into a host-only executor.
Definition AMReX_Parser.H:307
This class provides the user with a few print options.
Definition AMReX_Print.H:35
A Real vector in dim-dimensional space.
Definition AMReX_RealVect.H:34
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
T getEnum(std::string_view const &s)
Convert a string to an enum value.
Definition AMReX_Enum.H:117
std::string getEnumClassName()
Return the class name string of an AMREX_ENUM-declared enum type.
Definition AMReX_Enum.H:237
std::string getEnumNameString(T const &v)
Get the name string of an enum value.
Definition AMReX_Enum.H:190
T getEnumCaseInsensitive(std::string_view const &s)
Convert a string case-insensitively to an enum value.
Definition AMReX_Enum.H:153
Definition AMReX_Amr.cpp:50
std::ostream & ErrorStream()
Stream that receives diagnostic output (defaults to std::cerr).
Definition AMReX.cpp:966
BoxND< 3 > Box
Box is an alias for amrex::BoxND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:35
void Error(const std::string &msg)
Print a message to stderr and abort the program.
Definition AMReX.cpp:233
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:38
int Verbose() noexcept
Return the verbosity level configured via ParmParse or SetVerbose().
Definition AMReX.cpp:179
void Abort(const std::string &msg)
Print a fatal-error message to stderr and abort execution.
Definition AMReX.cpp:239
RealVectND< 3 > RealVect
Definition AMReX_ParmParse.H:40
Definition AMReX_ParmParse.H:1800
std::variant< std::string *, bool *, int *, long *, long long *, amrex::IntVect *, amrex::Box *, float *, double * > m_typehint
Definition AMReX_ParmParse.H:1818
std::vector< std::vector< std::string > > m_vals
Definition AMReX_ParmParse.H:1805
std::vector< std::vector< QuoteType > > m_quotes
Definition AMReX_ParmParse.H:1806
Long m_count
Definition AMReX_ParmParse.H:1807
std::vector< std::variant< bool, int, long, long long, float, double > > m_last_vals
Definition AMReX_ParmParse.H:1819
bool m_parsed
Definition AMReX_ParmParse.H:1820