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// grown (if necessary) to hold all the values requested, but it is
180// never shrunk.
181//
182// * Functions without the string "arr" in their names get single
183// values from the given entry in the table.
184//
185// The following is a code sample showing how to use ParmParse:
186//
187// main(int argc, char **argv)
188// {
189// char* in_file_name = argv[1];
190// ParmParse::Initialize(argc-2, argv+2, in_file_name);
191//
192// // Query table for value of "niter". If not in table
193// // then set to default value
194// if (!pp.query("niter",niter)) niter = 20;
195//
196// // read array of cell sizes if in table
197// Vector<float> dx;
198// if (nx=pp.countval("cell_size")) {
199// // get nx values starting at index 0 and store in dx.
200// // dx is automatically resized here.
201// pp.getarr("cell_size",dx,0,nx);
202// }
203// ParmParse::Finalize();
204// }
205//
206// void do_graphics()
207// {
208// //
209// // Will only query entries with the "plot" prefix:
210// //
211// ParmParse pp("plot");
212// //
213// // Read all variables with "plot.var" keyword.
214// //
215// std::string var_name;
216// Vector<int> range;
217// int num = pp.countname("var");
218// for (int k = 0; k < num; k++)
219// {
220// //
221// // Element 0 in list is a string.
222// //
223// pp.getkth("var",k,var_name,0);
224// //
225// // Elements 1 and 2 are integers.
226// // Note that "range" will be resized to hold 2 elements.
227// //
228// pp.getktharr("var",k,range,1,2);
229// cout << "variable = " << var_name << "lo, hi = ",
230// << range[0] << " " << range[1] << endl;
231// }
232// }
233// -----------------------------------------------------------------
234// ----------------------- END COMMENTS ---------------------------
235// -----------------------------------------------------------------
236
237
354{
355public:
356 enum { LAST = -1, FIRST = 0, ALL = -1 };
364 explicit ParmParse (std::string prefix = std::string(),
365 std::string parser_prefix = std::string());
366
368 [[nodiscard]] bool contains (std::string_view name) const;
374 [[nodiscard]] int countval (std::string_view name, int n = LAST) const;
379 [[nodiscard]] int countname (std::string_view name) const;
391 void getkth (std::string_view name,
392 int k,
393 bool& ref,
394 int ival = FIRST) const;
396 void get (std::string_view name,
397 bool& ref,
398 int ival = FIRST) const;
406 int querykth (std::string_view name,
407 int k,
408 bool& ref,
409 int ival = FIRST) const;
411 int query (std::string_view name,
412 bool& ref,
413 int ival = FIRST) const;
415 void add (std::string_view name, bool val);
425 void getkth (std::string_view name,
426 int k,
427 int& ref,
428 int ival = FIRST) const;
429
431 void get (std::string_view name,
432 int& ref,
433 int ival = FIRST) const;
441 int querykth (std::string_view name,
442 int k,
443 int& ref,
444 int ival = FIRST) const;
446 int query (std::string_view name,
447 int& ref,
448 int ival = FIRST) const;
450 void add (std::string_view name, int val);
460 void getkth (std::string_view name,
461 int k,
462 long& ref,
463 int ival = FIRST) const;
465 void get (std::string_view name,
466 long& ref,
467 int ival = FIRST) const;
475 int querykth (std::string_view name,
476 int k,
477 long& ref,
478 int ival = FIRST) const;
480 int query (std::string_view name,
481 long& ref,
482 int ival = FIRST) const;
484 void add (std::string_view name, long val);
494 void getkth (std::string_view name,
495 int k,
496 long long& ref,
497 int ival = FIRST) const;
499 void get (std::string_view name,
500 long long& ref,
501 int ival = FIRST) const;
509 int querykth (std::string_view name,
510 int k,
511 long long& ref,
512 int ival = FIRST) const;
514 int query (std::string_view name,
515 long long& ref,
516 int ival = FIRST) const;
518 void add (std::string_view name, long long val);
528 void getkth (std::string_view name,
529 int k,
530 float& ref,
531 int ival = FIRST) const;
533 void get (std::string_view name,
534 float& ref,
535 int ival = FIRST) const;
543 int querykth (std::string_view name,
544 int k,
545 float& ref,
546 int ival = FIRST) const;
548 int query (std::string_view name,
549 float& ref,
550 int ival = FIRST) const;
552 void add (std::string_view name, float val);
562 void getkth (std::string_view name,
563 int k,
564 double& ref,
565 int ival = FIRST) const;
567 void get (std::string_view name,
568 double& ref,
569 int ival = FIRST) const;
577 int querykth (std::string_view name,
578 int k,
579 double& ref,
580 int ival = FIRST) const;
582 int query (std::string_view name,
583 double& ref,
584 int ival = FIRST) const;
586 void add (std::string_view name, double val);
596 void getkth (std::string_view name,
597 int k,
598 std::string& ref,
599 int ival = FIRST) const;
600
602 void get (std::string_view name,
603 std::string& ref,
604 int ival = FIRST) const;
612 int querykth (std::string_view name,
613 int k,
614 std::string& ref,
615 int ival = FIRST) const;
617 int query (std::string_view name,
618 std::string& ref,
619 int ival = FIRST) const;
621 void add (std::string_view name, const std::string& val);
622
624 void add (std::string_view name, const char* val) { add(name, std::string(val)); }
625
634 void getline (std::string_view name, std::string& ref) const;
635
644 int queryline (std::string_view name, std::string& ref) const;
645
655 void getkth (std::string_view name,
656 int k,
657 IntVect& ref,
658 int ival = FIRST) const;
660 void get (std::string_view name,
661 IntVect& ref,
662 int ival = FIRST) const;
670 int querykth (std::string_view name,
671 int k,
672 IntVect& ref,
673 int ival = FIRST) const;
675 int query (std::string_view name,
676 IntVect& ref,
677 int ival = FIRST) const;
679 void add (std::string_view name, const IntVect& val);
689 void getkth (std::string_view name,
690 int k,
691 Box& ref,
692 int ival = FIRST) const;
694 void get (std::string_view name,
695 Box& ref,
696 int ival = FIRST) const;
704 int querykth (std::string_view name,
705 int k,
706 Box& ref,
707 int ival = FIRST) const;
709 int query (std::string_view name,
710 Box& ref,
711 int ival = FIRST) const;
713 void add (std::string_view name, const Box& val);
727 void getktharr (std::string_view name,
728 int k,
729 std::vector<int>& ref,
730 int start_ix = FIRST,
731 int num_val = ALL) const;
733 void getarr (std::string_view name,
734 std::vector<int>& ref,
735 int start_ix = FIRST,
736 int num_val = ALL) const;
738 int queryktharr (std::string_view name,
739 int k,
740 std::vector<int>& ref,
741 int start_ix = FIRST,
742 int num_val = ALL) const;
744 int queryarr (std::string_view name,
745 std::vector<int>& ref,
746 int start_ix = FIRST,
747 int num_val = ALL) const;
749 void addarr (std::string_view name, const std::vector<int>& ref);
750
764 void getktharr (std::string_view name,
765 int k,
766 std::vector<long>& ref,
767 int start_ix = FIRST,
768 int num_val = ALL) const;
770 void getarr (std::string_view name,
771 std::vector<long>& ref,
772 int start_ix = FIRST,
773 int num_val = ALL) const;
775 int queryktharr (std::string_view name,
776 int k,
777 std::vector<long>& ref,
778 int start_ix = FIRST,
779 int num_val = ALL) const;
781 int queryarr (std::string_view name,
782 std::vector<long>& ref,
783 int start_ix = FIRST,
784 int num_val = ALL) const;
786 void addarr (std::string_view name, const std::vector<long>& ref);
787
801 void getktharr (std::string_view name,
802 int k,
803 std::vector<long long>& ref,
804 int start_ix = FIRST,
805 int num_val = ALL) const;
807 void getarr (std::string_view name,
808 std::vector<long long>& ref,
809 int start_ix = FIRST,
810 int num_val = ALL) const;
812 int queryktharr (std::string_view name,
813 int k,
814 std::vector<long long>& ref,
815 int start_ix = FIRST,
816 int num_val = ALL) const;
818 int queryarr (std::string_view name,
819 std::vector<long long>& ref,
820 int start_ix = FIRST,
821 int num_val = ALL) const;
823 void addarr (std::string_view name, const std::vector<long long>& ref);
824
838 void getktharr (std::string_view name,
839 int k,
840 std::vector<float>& ref,
841 int start_ix = FIRST,
842 int num_val = ALL) const;
844 void getarr (std::string_view name,
845 std::vector<float>& ref,
846 int start_ix = FIRST,
847 int num_val = ALL) const;
849 int queryktharr (std::string_view name,
850 int k,
851 std::vector<float>& ref,
852 int start_ix = FIRST,
853 int num_val = ALL) const;
855 int queryarr (std::string_view name,
856 std::vector<float>& ref,
857 int start_ix = FIRST,
858 int num_val = ALL) const;
860 void addarr (std::string_view name, const std::vector<float>& ref);
874 void getktharr (std::string_view name,
875 int k,
876 std::vector<double>& ref,
877 int start_ix = FIRST,
878 int num_val = ALL) const;
880 void getarr (std::string_view name,
881 std::vector<double>& ref,
882 int start_ix = FIRST,
883 int num_val = ALL) const;
885 int queryktharr (std::string_view name,
886 int k,
887 std::vector<double>& ref,
888 int start_ix = FIRST,
889 int num_val = ALL) const;
891 int queryarr (std::string_view name,
892 std::vector<double>& ref,
893 int start_ix = FIRST,
894 int num_val = ALL) const;
896 void addarr (std::string_view name, const std::vector<double>& ref);
911 void getktharr (std::string_view name,
912 int k,
913 std::vector<std::string>& ref,
914 int start_ix = FIRST,
915 int num_val = ALL) const;
917 void getarr (std::string_view name,
918 std::vector<std::string>& ref,
919 int start_ix = FIRST,
920 int num_val = ALL) const;
922 int queryktharr (std::string_view name,
923 int k,
924 std::vector<std::string>& ref,
925 int start_ix = FIRST,
926 int num_val = ALL) const;
928 int queryarr (std::string_view name,
929 std::vector<std::string>& ref,
930 int start_ix = FIRST,
931 int num_val = ALL) const;
933 void addarr (std::string_view name, const std::vector<std::string>& ref);
948 void getktharr (std::string_view name,
949 int k,
950 std::vector<IntVect>& ref,
951 int start_ix = FIRST,
952 int num_val = ALL) const;
954 void getarr (std::string_view name,
955 std::vector<IntVect>& ref,
956 int start_ix = FIRST,
957 int num_val = ALL) const;
959 int queryktharr (std::string_view name,
960 int k,
961 std::vector<IntVect>& ref,
962 int start_ix = FIRST,
963 int num_val = ALL) const;
965 int queryarr (std::string_view name,
966 std::vector<IntVect>& ref,
967 int start_ix = FIRST,
968 int num_val = ALL) const;
970 void addarr (std::string_view name, const std::vector<IntVect>& ref);
985 void getktharr (std::string_view name,
986 int k,
987 std::vector<Box>& ref,
988 int start_ix = FIRST,
989 int num_val = ALL) const;
991 void getarr (std::string_view name,
992 std::vector<Box>& ref,
993 int start_ix = FIRST,
994 int num_val = ALL) const;
996 int queryktharr (std::string_view name,
997 int k,
998 std::vector<Box>& ref,
999 int start_ix = FIRST,
1000 int num_val = ALL) const;
1002 int queryarr (std::string_view name,
1003 std::vector<Box>& ref,
1004 int start_ix = FIRST,
1005 int num_val = ALL) const;
1007 void addarr (std::string_view name, const std::vector<Box>& ref);
1008
1009 /*
1010 * \brief Query IntVect from array
1011 *
1012 * This reads IntVect from an array (e.g., `8 16 8`), not the format
1013 * using parentheses (e.g., `(8,16,8)`).
1014 */
1015 int queryarr (std::string_view name, IntVect& ref) const;
1016
1017 /*
1018 * \brief Get IntVect from array
1019 *
1020 * This reads IntVect from an array (e.g., `8 16 8`), not the format
1021 * using parentheses (e.g., `(8,16,8)`).
1022 */
1023 void getarr (std::string_view name, IntVect& ref) const;
1024
1026 int queryarr (std::string_view name, RealVect& ref) const;
1027
1029 void getarr (std::string_view name, RealVect& ref) const;
1030
1031 template <typename T, std::size_t N>
1032 void get (std::string_view name, std::array<T,N>& ref) const {
1033 std::vector<T> v;
1034 this->getarr(name, v);
1035 AMREX_ALWAYS_ASSERT(v.size() >= N);
1036 for (std::size_t i = 0; i < N; ++i) {
1037 ref[i] = v[i];
1038 }
1039 }
1040
1041 template <typename T, std::size_t N>
1042 int query (std::string_view name, std::array<T,N>& ref) const {
1043 std::vector<T> v;
1044 int exist = this->queryarr(name, v);
1045 if (exist) {
1046 AMREX_ALWAYS_ASSERT(v.size() >= N);
1047 for (std::size_t i = 0; i < N; ++i) {
1048 ref[i] = v[i];
1049 }
1050 }
1051 return exist;
1052 }
1053
1060 template <typename T>
1061 int queryAdd (std::string_view name, T& ref) {
1062 int exist = this->query(name, ref);
1063 if (!exist) {
1064 this->add(name, ref);
1065 }
1066 return exist;
1067 }
1068
1069 int queryAdd (std::string_view name, std::string& ref) {
1070 int exist = this->query(name, ref);
1071 if (!exist && !ref.empty()) {
1072 this->add(name, ref);
1073 }
1074 return exist;
1075 }
1076
1086 template <typename T>
1087 int queryAdd (std::string_view name, std::vector<T>& ref) {
1088 std::vector<T> empty;
1089 int exist = this->queryarr(name, empty);
1090 if (exist) {
1091 ref = std::move(empty);
1092 }
1093 if (!exist && !ref.empty()) {
1094 this->addarr(name, ref);
1095 }
1096 return exist;
1097 }
1098
1099 template <typename T>
1100 int queryAdd (std::string_view name, Vector<T>& ref) {
1101 return this->queryAdd(name, static_cast<std::vector<T>&>(ref));
1102 }
1103
1110 template <typename T>
1111 int queryAdd (std::string_view name, std::vector<T>& ref, int num_val) {
1112 int exist = this->queryarr(name, ref, 0, num_val);
1113 if (!exist) {
1114 this->addarr(name, ref);
1115 }
1116 return exist;
1117 }
1118
1125 template <typename T, std::size_t N>
1126 int queryAdd (std::string_view name, std::array<T,N>& ref) {
1127 std::vector<T> v;
1128 int exist = this->queryarr(name, v);
1129 if (exist) {
1130 AMREX_ALWAYS_ASSERT(v.size() >= N);
1131 for (std::size_t i = 0; i < N; ++i) {
1132 ref[i] = v[i];
1133 }
1134 } else {
1135 v.resize(N);
1136 for (std::size_t i = 0; i < N; ++i) {
1137 v[i] = ref[i];
1138 }
1139 this->addarr(name, v);
1140 }
1141 return exist;
1142 }
1143
1150 int queryWithParser (std::string_view name, bool& ref) const;
1151 int queryWithParser (std::string_view name, int& ref) const;
1152 int queryWithParser (std::string_view name, long& ref) const;
1153 int queryWithParser (std::string_view name, long long& ref) const;
1154 int queryWithParser (std::string_view name, float& ref) const;
1155 int queryWithParser (std::string_view name, double& ref) const;
1156
1163 int queryarrWithParser (std::string_view name, int nvals, bool* ptr) const;
1164 int queryarrWithParser (std::string_view name, int nvals, int* ptr) const;
1165 int queryarrWithParser (std::string_view name, int nvals, long* ptr) const;
1166 int queryarrWithParser (std::string_view name, int nvals, long long* ptr) const;
1167 int queryarrWithParser (std::string_view name, int nvals, float* ptr) const;
1168 int queryarrWithParser (std::string_view name, int nvals, double* ptr) const;
1169 template <typename T>
1170 requires (std::same_as<T,bool> ||
1171 std::same_as<T,int> ||
1172 std::same_as<T,long> ||
1173 std::same_as<T,long long> ||
1174 std::same_as<T,float> ||
1175 std::same_as<T,double>)
1176 int queryarrWithParser (std::string_view name, int nvals, std::vector<T>& ref) const
1177 {
1178 if (this->contains(name)) {
1179 if (int(ref.size()) < nvals) { ref.resize(nvals); }
1180 return this->queryarrWithParser(name, nvals, ref.data());
1181 } else {
1182 return 0;
1183 }
1184 }
1185
1192 template <typename T>
1193 requires (std::same_as<T,bool> ||
1194 std::same_as<T,int> ||
1195 std::same_as<T,long> ||
1196 std::same_as<T,long long> ||
1197 std::same_as<T,float> ||
1198 std::same_as<T,double>)
1199 int queryAddWithParser (std::string_view name, T& ref)
1200 {
1201 int exist = this->queryWithParser(name, ref);
1202 if (!exist) {
1203 this->add(name, ref);
1204 }
1205 return exist;
1206 }
1207
1213 template <typename T>
1214 requires (std::same_as<T,bool> ||
1215 std::same_as<T,int> ||
1216 std::same_as<T,long> ||
1217 std::same_as<T,long long> ||
1218 std::same_as<T,float> ||
1219 std::same_as<T,double>)
1220 void getWithParser (std::string_view name, T& ref) const
1221 {
1222 int exist = this->queryWithParser(name, ref);
1223 if (!exist) {
1224 amrex::Error(std::string("ParmParse::getWithParser: failed to get ")+std::string(name));
1225 }
1226 }
1227
1233 template <typename T>
1234 requires (std::same_as<T,bool> ||
1235 std::same_as<T,int> ||
1236 std::same_as<T,long> ||
1237 std::same_as<T,long long> ||
1238 std::same_as<T,float> ||
1239 std::same_as<T,double>)
1240 void getarrWithParser (std::string_view name, int nvals, T* ptr) const
1241 {
1242 int exist = this->queryarrWithParser(name, nvals, ptr);
1243 if (!exist) {
1244 amrex::Error(std::string("ParmParse::getarrWithParser: failed to get ")+std::string(name));
1245 }
1246 }
1247
1253 template <typename T>
1254 requires (std::same_as<T,bool> ||
1255 std::same_as<T,int> ||
1256 std::same_as<T,long> ||
1257 std::same_as<T,long long> ||
1258 std::same_as<T,float> ||
1259 std::same_as<T,double>)
1260 void getarrWithParser (std::string_view name, int nvals, std::vector<T>& ref) const
1261 {
1262 int exist = this->queryarrWithParser(name, nvals, ref);
1263 if (!exist) {
1264 amrex::Error(std::string("ParmParse::getarrWithParser: failed to get ")+std::string(name));
1265 }
1266 }
1267
1268 /*
1269 * \brief Evaluate given string as math expression
1270 *
1271 * For unknown symbols, ParmParse database will be queried.
1272 */
1273 template <typename T>
1274 requires (std::same_as<T,bool> ||
1275 std::same_as<T,int> ||
1276 std::same_as<T,long> ||
1277 std::same_as<T,long long> ||
1278 std::same_as<T,float> ||
1279 std::same_as<T,double>)
1280 T eval (std::string const& expr) const
1281 {
1282 if constexpr (std::is_integral_v<T>) {
1283 auto const parser = this->makeIParser(expr, {});
1284 auto const exe = parser.compileHost<0>();
1285 return static_cast<T>(exe()); // In the future, we might add safety check.
1286 } else {
1287 auto const parser = this->makeParser(expr, {});
1288 auto const exe = parser.compileHost<0>();
1289 return static_cast<T>(exe());
1290 }
1291 }
1292
1293 /*
1294 * \brief Query two names.
1295 *
1296 * This function queries with `new_name` first. If it's not found, it
1297 * will try again with `old_name`.
1298 */
1299 template <typename T>
1300 int query (const char* new_name, const char* old_name, T& ref)
1301 {
1302 return (this->query(new_name, ref) ||
1303 this->query(old_name, ref));
1304 }
1305
1313 template <typename T>
1314 void get (const char* new_name, const char* old_name, T& ref)
1315 {
1316 auto exist = this->query(new_name, old_name, ref);
1317 if (!exist) {
1318 amrex::ErrorStream() << "ParmParse::get failed to find "
1319 << new_name << " and " << old_name << '\n';
1321 amrex::Abort();
1322 }
1323 }
1324
1333 template <typename T, typename ET = amrex_enum_traits<T>>
1334 requires (ET::value)
1335 int query (std::string_view name, T& ref, int ival = FIRST) const
1336 {
1337 std::string s;
1338 int exist = this->query(name, s, ival);
1339 if (exist) {
1340 try {
1341 ref = amrex::getEnum<T>(s);
1342 } catch (...) {
1343 if (amrex::Verbose() > 0 ) {
1344 amrex::Print() << "amrex::ParmParse::query (input name: "
1345 << this->prefixedName(name) << "):\n";
1346 }
1347 throw;
1348 }
1349 }
1350 return exist;
1351 }
1352
1353
1356 template <typename T, typename ET = amrex_enum_traits<T>>
1357 requires (ET::value)
1358 void add (std::string_view name, T const& val)
1359 {
1360 this->add(name, amrex::getEnumNameString(val));
1361 }
1362
1371 template <typename T, typename ET = amrex_enum_traits<T>>
1372 requires (ET::value)
1373 void get (std::string_view name, T& ref, int ival = FIRST) const
1374 {
1375 std::string s;
1376 this->get(name, s, ival);
1377 try {
1378 ref = amrex::getEnum<T>(s);
1379 } catch (...) {
1380 if (amrex::Verbose() > 0 ) {
1381 amrex::Print() << "amrex::ParmParse::get (input name: "
1382 << this->prefixedName(name) << "):\n";
1383 }
1384 throw;
1385 }
1386 }
1387
1389 template <typename T, typename ET = amrex_enum_traits<T>>
1390 requires (ET::value)
1391 int queryarr (std::string_view name,
1392 std::vector<T>& ref,
1393 int start_ix = FIRST,
1394 int num_val = ALL) const
1395 {
1396 std::vector<std::string> s;
1397 int exist = this->queryarr(name, s, start_ix, num_val);
1398 if (exist) {
1399 ref.resize(s.size());
1400 for (std::size_t i = 0; i < s.size(); ++i) {
1401 try {
1402 ref[i] = amrex::getEnum<T>(s[i]);
1403 } catch (...) {
1404 if (amrex::Verbose() > 0 ) {
1405 amrex::Print() << "amrex::ParmParse::queryarr (input name: "
1406 << this->prefixedName(name) << "):\n";
1407 }
1408 throw;
1409 }
1410 }
1411 }
1412 return exist;
1413 }
1414
1416 template <typename T, typename ET = amrex_enum_traits<T>>
1417 requires (ET::value)
1418 void getarr (std::string_view name,
1419 std::vector<T>& ref,
1420 int start_ix = FIRST,
1421 int num_val = ALL) const
1422 {
1423 std::vector<std::string> s;
1424 this->getarr(name, s, start_ix, num_val);
1425 ref.resize(s.size());
1426 for (std::size_t i = 0; i < s.size(); ++i) {
1427 try {
1428 ref[i] = amrex::getEnum<T>(s[i]);
1429 } catch (...) {
1430 if (amrex::Verbose() > 0 ) {
1431 amrex::Print() << "amrex::ParmParse::getarr (input name: "
1432 << this->prefixedName(name) << "):\n";
1433 }
1434 throw;
1435 }
1436 }
1437 }
1438
1449 template <typename T, typename ET = amrex_enum_traits<T>>
1450 requires (ET::value)
1451 int query_enum_case_insensitive (std::string_view name, T& ref, int ival = FIRST) const
1452 {
1453 std::string s;
1454 int exist = this->query(name, s, ival);
1455 if (exist) {
1456 try {
1457 ref = amrex::getEnumCaseInsensitive<T>(s);
1458 } catch (...) {
1459 if (amrex::Verbose() > 0) {
1460 amrex::Print() << "amrex::ParmParse::query_enum_case_insensitive (input name: "
1461 << this->prefixedName(name) << "):\n";
1462 }
1463 throw;
1464 }
1465 }
1466 return exist;
1467 }
1468
1479 template <typename T, typename ET = amrex_enum_traits<T>>
1480 requires (ET::value)
1481 void get_enum_case_insensitive (std::string_view name, T& ref, int ival = FIRST) const
1482 {
1483 int exist = this->query_enum_case_insensitive(name, ref, ival);
1484 if (!exist) {
1485 std::string msg("get_enum_case_insensitive(\"");
1486 msg.append(name).append("\",").append(amrex::getEnumClassName<T>())
1487 .append("&) failed.");
1488 amrex::Abort(msg);
1489 }
1490 }
1491
1504 template <typename T, typename ET = amrex_enum_traits<T>>
1505 requires (ET::value)
1506 int query_enum_sloppy (std::string_view name, T& ref, std::string_view const& ignores,
1507 int ival = FIRST) const
1508 {
1509 std::string s;
1510 int exist = this->query(name, s, ival);
1511 if (exist) {
1512 try {
1513 std::erase_if(s, [&] (auto const& c) {
1514 return ignores.find(c) != std::string_view::npos;
1515 });
1516 ref = amrex::getEnumCaseInsensitive<T>(s);
1517 } catch (...) {
1518 if (amrex::Verbose() > 0) {
1519 amrex::Print() << "amrex::ParmParse::query_enum_sloppy (input name: "
1520 << this->prefixedName(name) << "):\n";
1521 }
1522 throw;
1523 }
1524 }
1525 return exist;
1526 }
1527
1540 template <typename T, typename ET = amrex_enum_traits<T>>
1541 requires (ET::value)
1542 void get_enum_sloppy (std::string_view name, T& ref, std::string_view const& ignores,
1543 int ival = FIRST) const
1544 {
1545 int exist = this->query_enum_sloppy(name, ref, ignores, ival);
1546 if (!exist) {
1547 std::string msg("get_enum_sloppy(\"");
1548 msg.append(name).append("\",").append(amrex::getEnumClassName<T>())
1549 .append("&) failed.");
1550 amrex::Abort(msg);
1551 }
1552 }
1553
1562 template <typename T>
1563 requires (ppdetail::IsArithmeticOptional_v<T>)
1564 int queryAsDouble (std::string_view name, T& ref) const
1565 {
1566 using value_type = ppdetail::underlying_type_t<T>;
1567 double dref;
1568 int exist = queryWithParser(name, dref);
1569 if (exist) {
1570 if constexpr (std::is_integral_v<value_type>) {
1571 dref = std::round(dref);
1572 }
1573 if constexpr (std::is_integral_v<value_type> && !std::is_same_v<value_type,bool>) {
1574 // Range check before the cast, which would otherwise be UB.
1575 // 2^digits, exact; avoids std::ldexp (NVHPC SCALEFS crash on Zen 4 w/o AVX-512)
1576 constexpr double upper = 2.0 * static_cast<double>(std::numeric_limits<value_type>::max()/2 + 1); // NOLINT(bugprone-integer-division)
1577 if (!(dref >= static_cast<double>(std::numeric_limits<value_type>::lowest()) &&
1578 dref < upper)) {
1579 amrex::Abort("ParmParse:: queryAsDouble is not safe");
1580 }
1581 }
1582 ref = static_cast<value_type>(dref);
1583 }
1584 return exist;
1585 }
1586
1595 template <typename T>
1596 requires (ppdetail::IsArithmeticOptional_v<T>)
1597 int queryarrAsDouble (std::string_view name, int nvals, T* ptr) const
1598 {
1599 using value_type = ppdetail::underlying_type_t<T>;
1600 std::vector<double> dref(nvals);
1601 int exist = queryarrWithParser(name, nvals, dref.data());
1602 if (exist) {
1603 for (int i = 0; i < nvals; ++i) {
1604 if constexpr (std::is_integral_v<value_type>) {
1605 dref[i] = std::round(dref[i]);
1606 }
1607 if constexpr (std::is_integral_v<value_type> && !std::is_same_v<value_type,bool>) {
1608 // 2^digits, exact; avoids std::ldexp (NVHPC SCALEFS crash on Zen 4 w/o AVX-512)
1609 constexpr double upper = 2.0 * static_cast<double>(std::numeric_limits<value_type>::max()/2 + 1); // NOLINT(bugprone-integer-division)
1610 if (!(dref[i] >= static_cast<double>(std::numeric_limits<value_type>::lowest()) &&
1611 dref[i] < upper)) {
1612 amrex::Abort("ParmParse:: queryarrAsDouble is not safe");
1613 }
1614 }
1615 ptr[i] = static_cast<value_type>(dref[i]);
1616 }
1617 }
1618 return exist;
1619 }
1620
1629 template <typename T>
1630 requires (ppdetail::IsArithmeticOptional_v<T>)
1631 void getAsDouble (std::string_view name, T& ref) const
1632 {
1633 int exist = this->queryAsDouble(name, ref);
1634 if (!exist) {
1635 amrex::Error(std::string("ParmParse::getAsDouble: failed to get ")+std::string(name));
1636 }
1637 }
1638
1647 template <typename T>
1648 requires (ppdetail::IsArithmeticOptional_v<T>)
1649 void getarrAsDouble (std::string_view name, int nvals, T* ptr) const
1650 {
1651 int exist = this->queryarrAsDouble(name, nvals, ptr);
1652 if (!exist) {
1653 amrex::Error(std::string("ParmParse::getarrAsDouble: failed to get ")+std::string(name));
1654 }
1655 }
1656
1658 int remove (std::string_view name);
1659
1663 [[nodiscard]] Parser makeParser (std::string const& func,
1664 Vector<std::string> const& vars) const;
1665
1669 [[nodiscard]] IParser makeIParser (std::string const& func,
1670 Vector<std::string> const& vars) const;
1671
1677 int querytable (std::string_view name, std::vector<std::vector<double>>& ref) const;
1678 int querytable (std::string_view name, std::vector<std::vector<float>>& ref) const;
1679 int querytable (std::string_view name, std::vector<std::vector<int>>& ref) const;
1680
1686 template <typename T>
1687 void gettable (std::string_view name, std::vector<std::vector<T>>& ref) const
1688 {
1689 if (this->querytable(name, ref) == 0) {
1690 amrex::ErrorStream() << "ParmParse::gettable: " << name
1691 << " not found in database\n";
1693 amrex::Abort();
1694 }
1695 }
1696
1702 int queryarr (std::string_view name, std::vector<std::vector<double>>& ref) const;
1703 int queryarr (std::string_view name, std::vector<std::vector<float>>& ref) const;
1704 int queryarr (std::string_view name, std::vector<std::vector<int>>& ref) const;
1705 int queryarr (std::string_view name, std::vector<std::vector<std::string>>& ref) const;
1706
1711 template <typename T>
1712 void getarr (std::string_view name, std::vector<std::vector<T>>& ref) const
1713 {
1714 if (this->queryarr(name, ref) == 0) {
1715 amrex::ErrorStream() << "ParmParse::getarr: " << name
1716 << " not found in database\n";
1718 amrex::Abort();
1719 }
1720 }
1721
1729 static void Initialize (int argc, char** argv, const char* parfile);
1730 static void Initialize (int argc, char** argv, const std::string& parfile) {
1731 Initialize(argc, argv, parfile.c_str());
1732 }
1737 static void Finalize ();
1738
1740 static void SetParserPrefix (std::string a_prefix);
1741
1742 static int Verbose ();
1743 static void SetVerbose (int v);
1744
1748 static void dumpTable (std::ostream& os, bool prettyPrint = false);
1749
1753 static void prettyPrintTable (std::ostream& os);
1754
1757 static void prettyPrintUnusedInputs (std::ostream& os);
1758
1761 static void prettyPrintUsedInputs (std::ostream& os);
1762
1766 static void addfile (std::string const& filename);
1767
1768 static bool QueryUnusedInputs ();
1769
1771 [[nodiscard]] static bool hasUnusedInputs (const std::string& prefix = std::string());
1772
1774 [[nodiscard]] static std::vector<std::string> getUnusedInputs (const std::string& prefix = std::string());
1775
1777 [[nodiscard]] static std::set<std::string> getEntries (const std::string& prefix = std::string());
1778
1779 enum class QuoteType : unsigned char {
1780 None = 0,
1781 Double,
1782 Triple
1783 };
1784
1785 struct PP_entry {
1786 // There can be multiple occurrences for a given name (e.g.,
1787 // multiple lines starting with `foo =` in inputs. For each
1788 // occurrence, there can be multiple values. Thus, the use of
1789 // vector<vector<std::string>>.
1790 std::vector<std::vector<std::string>> m_vals;
1791 std::vector<std::vector<QuoteType>> m_quotes;
1792 mutable Long m_count = 0;
1793 mutable std::variant<
1794 std::string*,
1795 bool*,
1796 int*,
1797 long*,
1798 long long*,
1800 amrex::Box*,
1801 float*,
1802 double*
1803 > m_typehint = static_cast<std::string*>(nullptr);
1804 mutable std::vector<std::variant<bool, int, long, long long, float, double>> m_last_vals;
1805 mutable bool m_parsed = false;
1806 };
1807 using Table = std::unordered_map<std::string, PP_entry>;
1808
1809 [[nodiscard]] const Table& table() const {return *m_table;}
1810
1812 static std::string const FileKeyword;
1813
1815 static std::string const UnsetKeyword;
1816
1817 static std::string ParserPrefix;
1818
1819 [[nodiscard]] std::string const& getPrefix () const;
1820
1821 [[nodiscard]] std::string prefixedName (std::string_view str) const;
1822
1823protected:
1824
1825 std::string m_prefix; // Prefix used in keyword search
1826 std::string m_parser_prefix; // Prefix used by Parser
1828};
1829
1830}
1831
1832#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.
GpuArray< MultiArray4< Real const >, 3 > s
Definition AMReX_MLEBNodeFDLaplacian.cpp:214
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:354
QuoteType
Definition AMReX_ParmParse.H:1779
int queryline(std::string_view name, std::string &ref) const
Definition AMReX_ParmParse.cpp:2779
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:2794
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:1087
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:1061
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:1687
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:3079
int query(std::string_view name, std::array< T, N > &ref) const
Definition AMReX_ParmParse.H:1042
static std::string const UnsetKeyword
keyword for removing entries from the table
Definition AMReX_ParmParse.H:1815
static void prettyPrintTable(std::ostream &os)
Definition AMReX_ParmParse.cpp:1913
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:1711
static void addfile(std::string const &filename)
Definition AMReX_ParmParse.cpp:1681
static std::string const FileKeyword
keyword for files to load
Definition AMReX_ParmParse.H:1812
static std::string ParserPrefix
Definition AMReX_ParmParse.H:1817
static int Verbose()
Definition AMReX_ParmParse.cpp:1792
static void SetVerbose(int v)
Definition AMReX_ParmParse.cpp:1805
void get(const char *new_name, const char *old_name, T &ref)
Get using two names.
Definition AMReX_ParmParse.H:1314
static bool hasUnusedInputs(const std::string &prefix=std::string())
Any unused [prefix.]* parameters?
Definition AMReX_ParmParse.cpp:1743
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:1597
Parser makeParser(std::string const &func, Vector< std::string > const &vars) const
Definition AMReX_ParmParse.cpp:2997
int queryAdd(std::string_view name, std::string &ref)
Definition AMReX_ParmParse.H:1069
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:2086
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:1649
static bool QueryUnusedInputs()
Definition AMReX_ParmParse.cpp:1728
void getline(std::string_view name, std::string &ref) const
Definition AMReX_ParmParse.cpp:2771
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:2077
void add(std::string_view name, const char *val)
Convert const char * to string, to prevent auto-conversion to bool.
Definition AMReX_ParmParse.H:624
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:1984
bool contains(std::string_view name) const
Returns true if name is in table.
Definition AMReX_ParmParse.cpp:2810
void get(std::string_view name, std::array< T, N > &ref) const
Definition AMReX_ParmParse.H:1032
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:1712
static void prettyPrintUsedInputs(std::ostream &os)
Definition AMReX_ParmParse.cpp:1925
static void Finalize()
The destructor. The internal static table will only be deleted if there are no other ParmParse object...
Definition AMReX_ParmParse.cpp:1811
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:1111
std::string m_prefix
Definition AMReX_ParmParse.H:1825
const Table & table() const
Definition AMReX_ParmParse.H:1809
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:1199
T eval(std::string const &expr) const
Definition AMReX_ParmParse.H:1280
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:2001
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:1542
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:1451
static void SetParserPrefix(std::string a_prefix)
Set prefix used by math expression Parser.
Definition AMReX_ParmParse.cpp:1841
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:2925
static std::vector< std::string > getUnusedInputs(const std::string &prefix=std::string())
Returns unused [prefix.]* parameters.
Definition AMReX_ParmParse.cpp:1749
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:2105
std::string const & getPrefix() const
Definition AMReX_ParmParse.cpp:1661
int remove(std::string_view name)
Remove given name from the table.
Definition AMReX_ParmParse.cpp:2826
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:2096
@ FIRST
Definition AMReX_ParmParse.H:356
@ LAST
Definition AMReX_ParmParse.H:356
@ ALL
Definition AMReX_ParmParse.H:356
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:1506
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:1481
static void Initialize(int argc, char **argv, const std::string &parfile)
Definition AMReX_ParmParse.H:1730
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:1126
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:1240
int query(const char *new_name, const char *old_name, T &ref)
Definition AMReX_ParmParse.H:1300
Table * m_table
Definition AMReX_ParmParse.H:1827
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:2961
std::string m_parser_prefix
Definition AMReX_ParmParse.H:1826
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:2018
static void dumpTable(std::ostream &os, bool prettyPrint=false)
Definition AMReX_ParmParse.cpp:1849
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:2067
static void prettyPrintUnusedInputs(std::ostream &os)
Definition AMReX_ParmParse.cpp:1919
static std::set< std::string > getEntries(const std::string &prefix=std::string())
Returns [prefix.]* parameters.
Definition AMReX_ParmParse.cpp:1779
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:1564
std::string prefixedName(std::string_view str) const
Definition AMReX_ParmParse.cpp:1667
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:1631
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:2010
int queryAdd(std::string_view name, Vector< T > &ref)
Definition AMReX_ParmParse.H:1100
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:1993
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:1220
std::unordered_map< std::string, PP_entry > Table
Definition AMReX_ParmParse.H:1807
IParser makeIParser(std::string const &func, Vector< std::string > const &vars) const
Definition AMReX_ParmParse.cpp:3004
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:1931
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:994
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:238
int Verbose() noexcept
Return the verbosity level configured via ParmParse or SetVerbose().
Definition AMReX.cpp:184
void Abort(const std::string &msg)
Print a fatal-error message to stderr and abort execution.
Definition AMReX.cpp:244
Definition AMReX_ParmParse.H:1785
std::variant< std::string *, bool *, int *, long *, long long *, amrex::IntVect *, amrex::Box *, float *, double * > m_typehint
Definition AMReX_ParmParse.H:1803
std::vector< std::vector< std::string > > m_vals
Definition AMReX_ParmParse.H:1790
std::vector< std::vector< QuoteType > > m_quotes
Definition AMReX_ParmParse.H:1791
Long m_count
Definition AMReX_ParmParse.H:1792
std::vector< std::variant< bool, int, long, long long, float, double > > m_last_vals
Definition AMReX_ParmParse.H:1804
bool m_parsed
Definition AMReX_ParmParse.H:1805