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 <iosfwd>
17#include <optional>
18#include <set>
19#include <string>
20#include <string_view>
21#include <type_traits>
22#include <unordered_map>
23#include <variant>
24#include <vector>
25
26namespace amrex {
27
28template<int dim>
29class BoxND;
30using Box = BoxND<AMREX_SPACEDIM>;
31template<int dim>
32class IntVectND;
33using IntVect = IntVectND<AMREX_SPACEDIM>;
34template<int dim>
35class RealVectND;
37
39namespace ppdetail {
40 template <class T, class Enable = void>
41 struct ArithmeticOptional_TT : std::false_type {};
42
43 template <class T>
44 struct ArithmeticOptional_TT<T, std::enable_if_t<std::is_arithmetic_v<T>>>
45 : std::true_type
46 {
47 using value_type = T;
48 };
49
50 template <class T>
51 struct ArithmeticOptional_TT<std::optional<T>,
52 std::enable_if_t<std::is_arithmetic_v<T>>>
53 : std::true_type
54 {
55 using value_type = T;
56 };
57
58 template <class T>
59 inline constexpr bool IsArithmeticOptional_v = ArithmeticOptional_TT<T>::value;
60
61 template <class T>
62 using underlying_type_t = typename ArithmeticOptional_TT<T>::value_type;
63}
65
66//
67// ParmParse class implements a simple database for the storage and
68// retrieval of command-line and input-file arguments. The entries are
69// stored in a static table in (name,value_list) pairs.
70//
71// The format of the input file is a series of DEFINITIONS.
72//
73// A DEFINITION is of the form <name> = <value> <value> ...
74// The equal sign is important since the list of values can span multiple
75// lines.
76//
77// Comments in an input file include all text from a '#' character to the
78// end of the line. Here is an example input file:
79/*
80 niter = 100 # niter is an integer
81 title = "Double Wammy" # example of a string with spaces
82 cell_size = 0.5 0.75 # cell spacing in each dimension
83 plot.var = Density 1 10 # a list of values
84 plot.var = Energy 5 12 # another list of values
85 bigarray = 1 2 3 4 5 6 7 8 \
86 9 10 11 12 # continuation of bigarray
87 multi_line_string = "This is a
88 multi-line string."
89 my_2d_table = \
90 # col 1 2 3
91 {{ 11.0, 12.0, 13.0 } # row 1
92 { 21.0, 22.0, 23.0 } # row 2
93 { 31.0, 32.0, 33.0 } # row 3
94 { 41.0, 42.0, 43.0 } } # row 4
95 test = apple "boy blue" 10 20 30 40
96 FILE = prob_file # insert contents of this "prob_file" here
97*/
98// For values spanning multiple lines except for table, one must use '\' at
99// the end of a line
100// for continuation, otherwise it's a runtime error. Note that there must be
101// at least one space before the continuation character `\`. Multiple lines
102// inside a pair of double quotes are considered a single string containing
103// '\n's. The "FILE = <filename>" definition is special. Rather than just
104// adding this entry to the database, it reads the contents of <filename>
105// into the database.
106// For CI/CD workflows and out-of-source tests, the environment variable
107// AMREX_INPUTS_FILE_PREFIX can be set to prefix every FILE = <filename>
108// with a custom path.
109//
110// ParmParse stores all entries in a static table which is built the
111// first time a ParmParse object is constructed (usually in main()).
112// Subsequent invocations have access to this table.
113// A ParmParse constructor has an optional "prefix" argument that will
114// limit the searches to only those entries of the table with this prefix
115// in name. For example:
116// ParmParse pp("plot");
117// will find only those entries with name given by "plot.<string>".
118//
119// All values in the table are stored as strings. For example, the
120// values of "cell_size" in the above input file are stored as the
121// strings "0.5" and "0.75". These strings can be returned as either
122// strings or numeric values by the query functions.
123// Character strings with spaces must be delimited by double quotes
124// in the input file but the quotes are stripped before they are entered
125// into the table. For example, 'title' in the above input file has a
126// single value, the string 'Double Wammy' (without the quotes).
127// Each value in the list associated with a definition can be referred to
128// by its index number. The index numbers start at 0 just like an array
129// in the C programming language. Consider the definition of "test" in
130// the above input file. The first value 'apple'is a string with index
131// 0. The second value 'boy blue' is a string with index 1. The
132// remaining four values are integers indexed 2, 3, 4, and 5.
133//
134// For a string value to represent an integer or float it must fit the
135// following regular expression:
136// Sign ::= '+' | '-'
137// Digit ::= '0' | '1' | ... | '9'
138// Integer ::= [Sign]Digit+
139// Exp ::= ('e'|'E')Integer
140// Float ::= ( Integer[.Digit*][Exp] | [Integer].Digit+[Exp] )
141//
142// Where '+' indicates one or more occurrences, '*' represents zero or
143// more occurrences, '|' means one or the other and '[]' represents zero
144// or one occurrence.
145//
146// Note that floats and doubles have the same string representation and
147// that the FORTRAN "double" exponent format is not supported.
148// That is, 1.0d+3 is not a valid representation of a floating point
149// number but that 1.0e+3 is acceptable.
150//
151// There are a host of functions allowing the user to query the database
152// and retrieve values. Here are some general rules about the names of
153// the member functions:
154//
155// * Functions with the string "get" in their names attempt to get a
156// value or an array of values from the table. They generate a
157// run-time error if they are not successful.
158//
159// * Functions with the string "query" in their names attempt to get a
160// value or an array of values from the table. They return the value 1
161// (true) if they are successful and 0 (false) if not.
162//
163// * Functions with the string "kth" in their names get values from
164// the Kth entry with the given name in the database. This is
165// necessary since there may be multiple definitions with the same
166// name in the database.
167//
168// * Functions without the string "kth" in their names get values from
169// the last entry with the given name in the database. Note that the
170// definitions from the command line are appended to the database table
171// and hence will be the last entries.
172//
173// * Functions with the string "arr" in their names get an Array of
174// values from the given entry in the table. The array argument is
175// resized (if necessary) to hold all the values requested.
176//
177// * Functions without the string "arr" in their names get single
178// values from the given entry in the table.
179//
180// The following is a code sample showing how to use ParmParse:
181//
182// main(int argc, char **argv)
183// {
184// char* in_file_name = argv[1];
185// ParmParse::Initialize(argc-2, argv+2, in_file_name);
186//
187// // Query table for value of "niter". If not in table
188// // then set to default value
189// if (!pp.query("niter",niter)) niter = 20;
190//
191// // read array of cell sizes if in table
192// Vector<float> dx;
193// if (nx=pp.countval("cell_size")) {
194// // get nx values starting at index 0 and store in dx.
195// // dx is automatically resized here.
196// pp.getarr("cell_size",dx,0,nx);
197// }
198// ParmParse::Finalize();
199// }
200//
201// void do_graphics()
202// {
203// //
204// // Will only query entries with the "plot" prefix:
205// //
206// ParmParse pp("plot");
207// //
208// // Read all variables with "plot.var" keyword.
209// //
210// std::string var_name;
211// Vector<int> range;
212// int num = pp.countname("var");
213// for (int k = 0; k < num; k++)
214// {
215// //
216// // Element 0 in list is a string.
217// //
218// pp.getkth("var",k,var_name,0);
219// //
220// // Elements 1 and 2 are integers.
221// // Note that "range" will be resized to hold 2 elements.
222// //
223// pp.getktharr("var",k,range,1,2);
224// cout << "variable = " << var_name << "lo, hi = ",
225// << range[0] << " " << range[1] << endl;
226// }
227// }
228// -----------------------------------------------------------------
229// ----------------------- END COMMENTS ---------------------------
230// -----------------------------------------------------------------
231
232
349{
350public:
351 enum { LAST = -1, FIRST = 0, ALL = -1 };
359 explicit ParmParse (std::string prefix = std::string(),
360 std::string parser_prefix = std::string());
361
363 [[nodiscard]] bool contains (std::string_view name) const;
369 [[nodiscard]] int countval (std::string_view name, int n = LAST) const;
374 [[nodiscard]] int countname (std::string_view name) const;
386 void getkth (std::string_view name,
387 int k,
388 bool& ref,
389 int ival = FIRST) const;
391 void get (std::string_view name,
392 bool& ref,
393 int ival = FIRST) const;
401 int querykth (std::string_view name,
402 int k,
403 bool& ref,
404 int ival = FIRST) const;
406 int query (std::string_view name,
407 bool& ref,
408 int ival = FIRST) const;
410 void add (std::string_view name, bool val);
420 void getkth (std::string_view name,
421 int k,
422 int& ref,
423 int ival = FIRST) const;
424
426 void get (std::string_view name,
427 int& ref,
428 int ival = FIRST) const;
436 int querykth (std::string_view name,
437 int k,
438 int& ref,
439 int ival = FIRST) const;
441 int query (std::string_view name,
442 int& ref,
443 int ival = FIRST) const;
445 void add (std::string_view name, int val);
455 void getkth (std::string_view name,
456 int k,
457 long& ref,
458 int ival = FIRST) const;
460 void get (std::string_view name,
461 long& ref,
462 int ival = FIRST) const;
470 int querykth (std::string_view name,
471 int k,
472 long& ref,
473 int ival = FIRST) const;
475 int query (std::string_view name,
476 long& ref,
477 int ival = FIRST) const;
479 void add (std::string_view name, long val);
489 void getkth (std::string_view name,
490 int k,
491 long long& ref,
492 int ival = FIRST) const;
494 void get (std::string_view name,
495 long long& ref,
496 int ival = FIRST) const;
504 int querykth (std::string_view name,
505 int k,
506 long long& ref,
507 int ival = FIRST) const;
509 int query (std::string_view name,
510 long long& ref,
511 int ival = FIRST) const;
513 void add (std::string_view name, long long val);
523 void getkth (std::string_view name,
524 int k,
525 float& ref,
526 int ival = FIRST) const;
528 void get (std::string_view name,
529 float& ref,
530 int ival = FIRST) const;
538 int querykth (std::string_view name,
539 int k,
540 float& ref,
541 int ival = FIRST) const;
543 int query (std::string_view name,
544 float& ref,
545 int ival = FIRST) const;
547 void add (std::string_view name, float val);
557 void getkth (std::string_view name,
558 int k,
559 double& ref,
560 int ival = FIRST) const;
562 void get (std::string_view name,
563 double& ref,
564 int ival = FIRST) const;
572 int querykth (std::string_view name,
573 int k,
574 double& ref,
575 int ival = FIRST) const;
577 int query (std::string_view name,
578 double& ref,
579 int ival = FIRST) const;
581 void add (std::string_view name, double val);
591 void getkth (std::string_view name,
592 int k,
593 std::string& ref,
594 int ival = FIRST) const;
595
597 void get (std::string_view name,
598 std::string& ref,
599 int ival = FIRST) const;
607 int querykth (std::string_view name,
608 int k,
609 std::string& ref,
610 int ival = FIRST) const;
612 int query (std::string_view name,
613 std::string& ref,
614 int ival = FIRST) const;
616 void add (std::string_view name, const std::string& val);
617
619 void add (std::string_view name, const char* val) { add(name, std::string(val)); }
620
629 void getline (std::string_view name, std::string& ref) const;
630
639 int queryline (std::string_view name, std::string& ref) const;
640
650 void getkth (std::string_view name,
651 int k,
652 IntVect& ref,
653 int ival = FIRST) const;
655 void get (std::string_view name,
656 IntVect& ref,
657 int ival = FIRST) const;
665 int querykth (std::string_view name,
666 int k,
667 IntVect& ref,
668 int ival = FIRST) const;
670 int query (std::string_view name,
671 IntVect& ref,
672 int ival = FIRST) const;
674 void add (std::string_view name, const IntVect& val);
684 void getkth (std::string_view name,
685 int k,
686 Box& ref,
687 int ival = FIRST) const;
689 void get (std::string_view name,
690 Box& ref,
691 int ival = FIRST) const;
699 int querykth (std::string_view name,
700 int k,
701 Box& ref,
702 int ival = FIRST) const;
704 int query (std::string_view name,
705 Box& ref,
706 int ival = FIRST) const;
708 void add (std::string_view name, const Box& val);
721 void getktharr (std::string_view name,
722 int k,
723 std::vector<int>& ref,
724 int start_ix = FIRST,
725 int num_val = ALL) const;
727 void getarr (std::string_view name,
728 std::vector<int>& ref,
729 int start_ix = FIRST,
730 int num_val = ALL) const;
732 int queryktharr (std::string_view name,
733 int k,
734 std::vector<int>& ref,
735 int start_ix = FIRST,
736 int num_val = ALL) const;
738 int queryarr (std::string_view name,
739 std::vector<int>& ref,
740 int start_ix = FIRST,
741 int num_val = ALL) const;
743 void addarr (std::string_view name, const std::vector<int>& ref);
744
757 void getktharr (std::string_view name,
758 int k,
759 std::vector<long>& ref,
760 int start_ix = FIRST,
761 int num_val = ALL) const;
763 void getarr (std::string_view name,
764 std::vector<long>& ref,
765 int start_ix = FIRST,
766 int num_val = ALL) const;
768 int queryktharr (std::string_view name,
769 int k,
770 std::vector<long>& ref,
771 int start_ix = FIRST,
772 int num_val = ALL) const;
774 int queryarr (std::string_view name,
775 std::vector<long>& ref,
776 int start_ix = FIRST,
777 int num_val = ALL) const;
779 void addarr (std::string_view name, const std::vector<long>& ref);
780
793 void getktharr (std::string_view name,
794 int k,
795 std::vector<long long>& ref,
796 int start_ix = FIRST,
797 int num_val = ALL) const;
799 void getarr (std::string_view name,
800 std::vector<long long>& ref,
801 int start_ix = FIRST,
802 int num_val = ALL) const;
804 int queryktharr (std::string_view name,
805 int k,
806 std::vector<long long>& ref,
807 int start_ix = FIRST,
808 int num_val = ALL) const;
810 int queryarr (std::string_view name,
811 std::vector<long long>& ref,
812 int start_ix = FIRST,
813 int num_val = ALL) const;
815 void addarr (std::string_view name, const std::vector<long long>& ref);
816
829 void getktharr (std::string_view name,
830 int k,
831 std::vector<float>& ref,
832 int start_ix = FIRST,
833 int num_val = ALL) const;
835 void getarr (std::string_view name,
836 std::vector<float>& ref,
837 int start_ix = FIRST,
838 int num_val = ALL) const;
840 int queryktharr (std::string_view name,
841 int k,
842 std::vector<float>& ref,
843 int start_ix = FIRST,
844 int num_val = ALL) const;
846 int queryarr (std::string_view name,
847 std::vector<float>& ref,
848 int start_ix = FIRST,
849 int num_val = ALL) const;
851 void addarr (std::string_view name, const std::vector<float>& ref);
864 void getktharr (std::string_view name,
865 int k,
866 std::vector<double>& ref,
867 int start_ix = FIRST,
868 int num_val = ALL) const;
870 void getarr (std::string_view name,
871 std::vector<double>& ref,
872 int start_ix = FIRST,
873 int num_val = ALL) const;
875 int queryktharr (std::string_view name,
876 int k,
877 std::vector<double>& ref,
878 int start_ix = FIRST,
879 int num_val = ALL) const;
881 int queryarr (std::string_view name,
882 std::vector<double>& ref,
883 int start_ix = FIRST,
884 int num_val = ALL) const;
886 void addarr (std::string_view name, const std::vector<double>& ref);
899 void getktharr (std::string_view name,
900 int k,
901 std::vector<std::string>& ref,
902 int start_ix = FIRST,
903 int num_val = ALL) const;
905 void getarr (std::string_view name,
906 std::vector<std::string>& ref,
907 int start_ix = FIRST,
908 int num_val = ALL) const;
910 int queryktharr (std::string_view name,
911 int k,
912 std::vector<std::string>& ref,
913 int start_ix = FIRST,
914 int num_val = ALL) const;
916 int queryarr (std::string_view name,
917 std::vector<std::string>& ref,
918 int start_ix = FIRST,
919 int num_val = ALL) const;
921 void addarr (std::string_view name, const std::vector<std::string>& ref);
934 void getktharr (std::string_view name,
935 int k,
936 std::vector<IntVect>& ref,
937 int start_ix = FIRST,
938 int num_val = ALL) const;
940 void getarr (std::string_view name,
941 std::vector<IntVect>& ref,
942 int start_ix = FIRST,
943 int num_val = ALL) const;
945 int queryktharr (std::string_view name,
946 int k,
947 std::vector<IntVect>& ref,
948 int start_ix = FIRST,
949 int num_val = ALL) const;
951 int queryarr (std::string_view name,
952 std::vector<IntVect>& ref,
953 int start_ix = FIRST,
954 int num_val = ALL) const;
956 void addarr (std::string_view name, const std::vector<IntVect>& ref);
969 void getktharr (std::string_view name,
970 int k,
971 std::vector<Box>& ref,
972 int start_ix = FIRST,
973 int num_val = ALL) const;
975 void getarr (std::string_view name,
976 std::vector<Box>& ref,
977 int start_ix = FIRST,
978 int num_val = ALL) const;
980 int queryktharr (std::string_view name,
981 int k,
982 std::vector<Box>& ref,
983 int start_ix = FIRST,
984 int num_val = ALL) const;
986 int queryarr (std::string_view name,
987 std::vector<Box>& ref,
988 int start_ix = FIRST,
989 int num_val = ALL) const;
991 void addarr (std::string_view name, const std::vector<Box>& ref);
992
993 /*
994 * \brief Query IntVect from array
995 *
996 * This reads IntVect from an array (e.g., `8 16 8`), not the format
997 * using parentheses (e.g., `(8,16,8)`).
998 */
999 int queryarr (std::string_view name, IntVect& ref) const;
1000
1001 /*
1002 * \brief Get IntVect from array
1003 *
1004 * This reads IntVect from an array (e.g., `8 16 8`), not the format
1005 * using parentheses (e.g., `(8,16,8)`).
1006 */
1007 void getarr (std::string_view name, IntVect& ref) const;
1008
1010 int queryarr (std::string_view name, RealVect& ref) const;
1011
1013 void getarr (std::string_view name, RealVect& ref) const;
1014
1015 template <typename T, std::size_t N>
1016 void get (std::string_view name, std::array<T,N>& ref) const {
1017 std::vector<T> v;
1018 this->getarr(name, v);
1019 AMREX_ALWAYS_ASSERT(v.size() >= N);
1020 for (std::size_t i = 0; i < N; ++i) {
1021 ref[i] = v[i];
1022 }
1023 }
1024
1025 template <typename T, std::size_t N>
1026 int query (std::string_view name, std::array<T,N>& ref) const {
1027 std::vector<T> v;
1028 int exist = this->queryarr(name, v);
1029 if (exist) {
1030 AMREX_ALWAYS_ASSERT(v.size() >= N);
1031 for (std::size_t i = 0; i < N; ++i) {
1032 ref[i] = v[i];
1033 }
1034 }
1035 return exist;
1036 }
1037
1044 template <typename T>
1045 int queryAdd (std::string_view name, T& ref) {
1046 int exist = this->query(name, ref);
1047 if (!exist) {
1048 this->add(name, ref);
1049 }
1050 return exist;
1051 }
1052
1053 int queryAdd (std::string_view name, std::string& ref) {
1054 int exist = this->query(name, ref);
1055 if (!exist && !ref.empty()) {
1056 this->add(name, ref);
1057 }
1058 return exist;
1059 }
1060
1070 template <typename T>
1071 int queryAdd (std::string_view name, std::vector<T>& ref) {
1072 std::vector<T> empty;
1073 int exist = this->queryarr(name, empty);
1074 if (exist) {
1075 ref = std::move(empty);
1076 }
1077 if (!exist && !ref.empty()) {
1078 this->addarr(name, ref);
1079 }
1080 return exist;
1081 }
1082
1083 template <typename T>
1084 int queryAdd (std::string_view name, Vector<T>& ref) {
1085 return this->queryAdd(name, static_cast<std::vector<T>&>(ref));
1086 }
1087
1094 template <typename T>
1095 int queryAdd (std::string_view name, std::vector<T>& ref, int num_val) {
1096 int exist = this->queryarr(name, ref, 0, num_val);
1097 if (!exist) {
1098 this->addarr(name, ref);
1099 }
1100 return exist;
1101 }
1102
1109 template <typename T, std::size_t N>
1110 int queryAdd (std::string_view name, std::array<T,N>& ref) {
1111 std::vector<T> v;
1112 int exist = this->queryarr(name, v);
1113 if (exist) {
1114 AMREX_ALWAYS_ASSERT(v.size() >= N);
1115 for (std::size_t i = 0; i < N; ++i) {
1116 ref[i] = v[i];
1117 }
1118 } else {
1119 v.resize(N);
1120 for (std::size_t i = 0; i < N; ++i) {
1121 v[i] = ref[i];
1122 }
1123 this->addarr(name, v);
1124 }
1125 return exist;
1126 }
1127
1134 int queryWithParser (std::string_view name, bool& ref) const;
1135 int queryWithParser (std::string_view name, int& ref) const;
1136 int queryWithParser (std::string_view name, long& ref) const;
1137 int queryWithParser (std::string_view name, long long& ref) const;
1138 int queryWithParser (std::string_view name, float& ref) const;
1139 int queryWithParser (std::string_view name, double& ref) const;
1140
1147 int queryarrWithParser (std::string_view name, int nvals, bool* ptr) const;
1148 int queryarrWithParser (std::string_view name, int nvals, int* ptr) const;
1149 int queryarrWithParser (std::string_view name, int nvals, long* ptr) const;
1150 int queryarrWithParser (std::string_view name, int nvals, long long* ptr) const;
1151 int queryarrWithParser (std::string_view name, int nvals, float* ptr) const;
1152 int queryarrWithParser (std::string_view name, int nvals, double* ptr) const;
1153 template <typename T, std::enable_if_t<std::is_same_v<T,bool> ||
1154 std::is_same_v<T,int> ||
1155 std::is_same_v<T,long> ||
1156 std::is_same_v<T,long long> ||
1157 std::is_same_v<T,float> ||
1158 std::is_same_v<T,double>,int> = 0>
1159 int queryarrWithParser (std::string_view name, int nvals, std::vector<T>& ref) const
1160 {
1161 if (this->contains(name)) {
1162 if (int(ref.size()) < nvals) { ref.resize(nvals); }
1163 return this->queryarrWithParser(name, nvals, ref.data());
1164 } else {
1165 return 0;
1166 }
1167 }
1168
1175 template <typename T, std::enable_if_t<std::is_same_v<T,bool> ||
1176 std::is_same_v<T,int> ||
1177 std::is_same_v<T,long> ||
1178 std::is_same_v<T,long long> ||
1179 std::is_same_v<T,float> ||
1180 std::is_same_v<T,double>,int> = 0>
1181 int queryAddWithParser (std::string_view name, T& ref)
1182 {
1183 int exist = this->queryWithParser(name, ref);
1184 if (!exist) {
1185 this->add(name, ref);
1186 }
1187 return exist;
1188 }
1189
1195 template <typename T, std::enable_if_t<std::is_same_v<T,bool> ||
1196 std::is_same_v<T,int> ||
1197 std::is_same_v<T,long> ||
1198 std::is_same_v<T,long long> ||
1199 std::is_same_v<T,float> ||
1200 std::is_same_v<T,double>,int> = 0>
1201 void getWithParser (std::string_view name, T& ref) const
1202 {
1203 int exist = this->queryWithParser(name, ref);
1204 if (!exist) {
1205 amrex::Error(std::string("ParmParse::getWithParser: failed to get ")+std::string(name));
1206 }
1207 }
1208
1214 template <typename T, std::enable_if_t<std::is_same_v<T,bool> ||
1215 std::is_same_v<T,int> ||
1216 std::is_same_v<T,long> ||
1217 std::is_same_v<T,long long> ||
1218 std::is_same_v<T,float> ||
1219 std::is_same_v<T,double>,int> = 0>
1220 void getarrWithParser (std::string_view name, int nvals, T* ptr) const
1221 {
1222 int exist = this->queryarrWithParser(name, nvals, ptr);
1223 if (!exist) {
1224 amrex::Error(std::string("ParmParse::getarrWithParser: failed to get ")+std::string(name));
1225 }
1226 }
1227
1233 template <typename T, std::enable_if_t<std::is_same_v<T,bool> ||
1234 std::is_same_v<T,int> ||
1235 std::is_same_v<T,long> ||
1236 std::is_same_v<T,long long> ||
1237 std::is_same_v<T,float> ||
1238 std::is_same_v<T,double>,int> = 0>
1239 void getarrWithParser (std::string_view name, int nvals, std::vector<T>& ref) const
1240 {
1241 int exist = this->queryarrWithParser(name, nvals, ref);
1242 if (!exist) {
1243 amrex::Error(std::string("ParmParse::getarrWithParser: failed to get ")+std::string(name));
1244 }
1245 }
1246
1247 /*
1248 * \brief Evaluate given string as math expression
1249 *
1250 * For unknown symbols, ParmParse database will be queried.
1251 */
1252 template <typename T, std::enable_if_t<std::is_same_v<T,bool> ||
1253 std::is_same_v<T,int> ||
1254 std::is_same_v<T,long> ||
1255 std::is_same_v<T,long long> ||
1256 std::is_same_v<T,float> ||
1257 std::is_same_v<T,double>,int> = 0>
1258 T eval (std::string const& expr) const
1259 {
1260 if constexpr (std::is_integral_v<T>) {
1261 auto const parser = this->makeIParser(expr, {});
1262 auto const exe = parser.compileHost<0>();
1263 return static_cast<T>(exe()); // In the future, we might add safety check.
1264 } else {
1265 auto const parser = this->makeParser(expr, {});
1266 auto const exe = parser.compileHost<0>();
1267 return static_cast<T>(exe());
1268 }
1269 }
1270
1271 /*
1272 * \brief Query two names.
1273 *
1274 * This function queries with `new_name` first. If it's not found, it
1275 * will try again with `old_name`.
1276 */
1277 template <typename T>
1278 int query (const char* new_name, const char* old_name, T& ref)
1279 {
1280 return (this->query(new_name, ref) ||
1281 this->query(old_name, ref));
1282 }
1283
1291 template <typename T>
1292 void get (const char* new_name, const char* old_name, T& ref)
1293 {
1294 auto exist = this->query(new_name, old_name, ref);
1295 if (!exist) {
1296 amrex::ErrorStream() << "ParmParse::get failed to find "
1297 << new_name << " and " << old_name << '\n';
1299 amrex::Abort();
1300 }
1301 }
1302
1311 template <typename T, typename ET = amrex_enum_traits<T>,
1312 std::enable_if_t<ET::value,int> = 0>
1313 int query (std::string_view name, T& ref, int ival = FIRST) const
1314 {
1315 std::string s;
1316 int exist = this->query(name, s, ival);
1317 if (exist) {
1318 try {
1319 ref = amrex::getEnum<T>(s);
1320 } catch (...) {
1321 if (amrex::Verbose() > 0 ) {
1322 amrex::Print() << "amrex::ParmParse::query (input name: "
1323 << this->prefixedName(name) << "):\n";
1324 }
1325 throw;
1326 }
1327 }
1328 return exist;
1329 }
1330
1331
1334 template <typename T, typename ET = amrex_enum_traits<T>,
1335 std::enable_if_t<ET::value,int> = 0>
1336 void add (std::string_view name, T const& val)
1337 {
1338 this->add(name, amrex::getEnumNameString(val));
1339 }
1340
1349 template <typename T, typename ET = amrex_enum_traits<T>,
1350 std::enable_if_t<ET::value,int> = 0>
1351 void get (std::string_view name, T& ref, int ival = FIRST) const
1352 {
1353 std::string s;
1354 this->get(name, s, ival);
1355 try {
1356 ref = amrex::getEnum<T>(s);
1357 } catch (...) {
1358 if (amrex::Verbose() > 0 ) {
1359 amrex::Print() << "amrex::ParmParse::get (input name: "
1360 << this->prefixedName(name) << "):\n";
1361 }
1362 throw;
1363 }
1364 }
1365
1367 template <typename T, typename ET = amrex_enum_traits<T>,
1368 std::enable_if_t<ET::value,int> = 0>
1369 int queryarr (std::string_view name,
1370 std::vector<T>& ref,
1371 int start_ix = FIRST,
1372 int num_val = ALL) const
1373 {
1374 std::vector<std::string> s;
1375 int exist = this->queryarr(name, s, start_ix, num_val);
1376 if (exist) {
1377 ref.resize(s.size());
1378 for (std::size_t i = 0; i < s.size(); ++i) {
1379 try {
1380 ref[i] = amrex::getEnum<T>(s[i]);
1381 } catch (...) {
1382 if (amrex::Verbose() > 0 ) {
1383 amrex::Print() << "amrex::ParmParse::queryarr (input name: "
1384 << this->prefixedName(name) << "):\n";
1385 }
1386 throw;
1387 }
1388 }
1389 }
1390 return exist;
1391 }
1392
1394 template <typename T, typename ET = amrex_enum_traits<T>,
1395 std::enable_if_t<ET::value,int> = 0>
1396 void getarr (std::string_view name,
1397 std::vector<T>& ref,
1398 int start_ix = FIRST,
1399 int num_val = ALL) const
1400 {
1401 std::vector<std::string> s;
1402 this->getarr(name, s, start_ix, num_val);
1403 ref.resize(s.size());
1404 for (std::size_t i = 0; i < s.size(); ++i) {
1405 try {
1406 ref[i] = amrex::getEnum<T>(s[i]);
1407 } catch (...) {
1408 if (amrex::Verbose() > 0 ) {
1409 amrex::Print() << "amrex::ParmParse::getarr (input name: "
1410 << this->prefixedName(name) << "):\n";
1411 }
1412 throw;
1413 }
1414 }
1415 }
1416
1427 template <typename T, typename ET = amrex_enum_traits<T>,
1428 std::enable_if_t<ET::value,int> = 0>
1429 int query_enum_case_insensitive (std::string_view name, T& ref, int ival = FIRST) const
1430 {
1431 std::string s;
1432 int exist = this->query(name, s, ival);
1433 if (exist) {
1434 try {
1435 ref = amrex::getEnumCaseInsensitive<T>(s);
1436 } catch (...) {
1437 if (amrex::Verbose() > 0) {
1438 amrex::Print() << "amrex::ParmParse::query_enum_case_insensitive (input name: "
1439 << this->prefixedName(name) << "):\n";
1440 }
1441 throw;
1442 }
1443 }
1444 return exist;
1445 }
1446
1457 template <typename T, typename ET = amrex_enum_traits<T>,
1458 std::enable_if_t<ET::value,int> = 0>
1459 void get_enum_case_insensitive (std::string_view name, T& ref, int ival = FIRST) const
1460 {
1461 int exist = this->query_enum_case_insensitive(name, ref, ival);
1462 if (!exist) {
1463 std::string msg("get_enum_case_insensitive(\"");
1464 msg.append(name).append("\",").append(amrex::getEnumClassName<T>())
1465 .append("&) failed.");
1466 amrex::Abort(msg);
1467 }
1468 }
1469
1482 template <typename T, typename ET = amrex_enum_traits<T>,
1483 std::enable_if_t<ET::value,int> = 0>
1484 int query_enum_sloppy (std::string_view name, T& ref, std::string_view const& ignores,
1485 int ival = FIRST) const
1486 {
1487 std::string s;
1488 int exist = this->query(name, s, ival);
1489 if (exist) {
1490 try {
1491 s.erase(std::remove_if(s.begin(), s.end(),
1492 [&] (auto const& c) {
1493 return ignores.find(c) != std::string_view::npos; }),
1494 s.end());
1495 ref = amrex::getEnumCaseInsensitive<T>(s);
1496 } catch (...) {
1497 if (amrex::Verbose() > 0) {
1498 amrex::Print() << "amrex::ParmParse::query_enum_sloppy (input name: "
1499 << this->prefixedName(name) << "):\n";
1500 }
1501 throw;
1502 }
1503 }
1504 return exist;
1505 }
1506
1519 template <typename T, typename ET = amrex_enum_traits<T>,
1520 std::enable_if_t<ET::value,int> = 0>
1521 void get_enum_sloppy (std::string_view name, T& ref, std::string_view const& ignores,
1522 int ival = FIRST) const
1523 {
1524 int exist = this->query_enum_sloppy(name, ref, ignores, ival);
1525 if (!exist) {
1526 std::string msg("get_enum_sloppy(\"");
1527 msg.append(name).append("\",").append(amrex::getEnumClassName<T>())
1528 .append("&) failed.");
1529 amrex::Abort(msg);
1530 }
1531 }
1532
1541 template <typename T, std::enable_if_t<ppdetail::IsArithmeticOptional_v<T>, int> = 0>
1542 int queryAsDouble (std::string_view name, T& ref) const
1543 {
1544 using value_type = ppdetail::underlying_type_t<T>;
1545 double dref;
1546 int exist = queryWithParser(name, dref);
1547 if (exist) {
1548 if (std::is_integral_v<value_type>) {
1549 dref = std::round(dref);
1550 }
1551 auto vref = static_cast<value_type>(dref);
1552 if constexpr (std::is_integral_v<value_type> && !std::is_same_v<value_type,bool>) {
1553 if (static_cast<double>(vref) != dref) {
1554 amrex::Abort("ParmParse:: queryAsDouble is not safe");
1555 }
1556 }
1557 ref = vref;
1558 }
1559 return exist;
1560 }
1561
1570 template <typename T, std::enable_if_t<ppdetail::IsArithmeticOptional_v<T>, int> = 0>
1571 int queryarrAsDouble (std::string_view name, int nvals, T* ptr) const
1572 {
1573 using value_type = ppdetail::underlying_type_t<T>;
1574 std::vector<double> dref(nvals);
1575 int exist = queryarrWithParser(name, nvals, dref.data());
1576 if (exist) {
1577 for (int i = 0; i < nvals; ++i) {
1578 if (std::is_integral_v<value_type>) {
1579 dref[i] = std::round(dref[i]);
1580 }
1581 auto vref = static_cast<value_type>(dref[i]);
1582 if constexpr (std::is_integral_v<value_type> && !std::is_same_v<value_type,bool>) {
1583 if (static_cast<double>(vref) != dref[i]) {
1584 amrex::Abort("ParmParse:: queryarrAsDouble is not safe");
1585 }
1586 }
1587 ptr[i] = vref;
1588 }
1589 }
1590 return exist;
1591 }
1592
1601 template <typename T, std::enable_if_t<ppdetail::IsArithmeticOptional_v<T>, int> = 0>
1602 void getAsDouble (std::string_view name, T& ref) const
1603 {
1604 int exist = this->queryAsDouble(name, ref);
1605 if (!exist) {
1606 amrex::Error(std::string("ParmParse::getAsDouble: failed to get ")+std::string(name));
1607 }
1608 }
1609
1618 template <typename T, std::enable_if_t<ppdetail::IsArithmeticOptional_v<T>, int> = 0>
1619 void getarrAsDouble (std::string_view name, int nvals, T* ptr) const
1620 {
1621 int exist = this->queryarrAsDouble(name, nvals, ptr);
1622 if (!exist) {
1623 amrex::Error(std::string("ParmParse::getarrAsDouble: failed to get ")+std::string(name));
1624 }
1625 }
1626
1628 int remove (std::string_view name);
1629
1633 [[nodiscard]] Parser makeParser (std::string const& func,
1634 Vector<std::string> const& vars) const;
1635
1639 [[nodiscard]] IParser makeIParser (std::string const& func,
1640 Vector<std::string> const& vars) const;
1641
1647 int querytable (std::string_view name, std::vector<std::vector<double>>& ref) const;
1648 int querytable (std::string_view name, std::vector<std::vector<float>>& ref) const;
1649 int querytable (std::string_view name, std::vector<std::vector<int>>& ref) const;
1650
1656 template <typename T>
1657 void gettable (std::string_view name, std::vector<std::vector<T>>& ref) const
1658 {
1659 if (this->querytable(name, ref) == 0) {
1660 amrex::ErrorStream() << "ParmParse::gettable: " << name
1661 << " not found in database\n";
1663 amrex::Abort();
1664 }
1665 }
1666
1672 int queryarr (std::string_view name, std::vector<std::vector<double>>& ref) const;
1673 int queryarr (std::string_view name, std::vector<std::vector<float>>& ref) const;
1674 int queryarr (std::string_view name, std::vector<std::vector<int>>& ref) const;
1675 int queryarr (std::string_view name, std::vector<std::vector<std::string>>& ref) const;
1676
1681 template <typename T>
1682 void getarr (std::string_view name, std::vector<std::vector<T>>& ref) const
1683 {
1684 if (this->queryarr(name, ref) == 0) {
1685 amrex::ErrorStream() << "ParmParse::getarr: " << name
1686 << " not found in database\n";
1688 amrex::Abort();
1689 }
1690 }
1691
1699 static void Initialize (int argc, char** argv, const char* parfile);
1700 static void Initialize (int argc, char** argv, const std::string& parfile) {
1701 Initialize(argc, argv, parfile.c_str());
1702 }
1707 static void Finalize ();
1708
1710 static void SetParserPrefix (std::string a_prefix);
1711
1712 static int Verbose ();
1713 static void SetVerbose (int v);
1714
1718 static void dumpTable (std::ostream& os, bool prettyPrint = false);
1719
1723 static void prettyPrintTable (std::ostream& os);
1724
1727 static void prettyPrintUnusedInputs (std::ostream& os);
1728
1731 static void prettyPrintUsedInputs (std::ostream& os);
1732
1736 static void addfile (std::string const& filename);
1737
1738 static bool QueryUnusedInputs ();
1739
1741 [[nodiscard]] static bool hasUnusedInputs (const std::string& prefix = std::string());
1742
1744 [[nodiscard]] static std::vector<std::string> getUnusedInputs (const std::string& prefix = std::string());
1745
1747 [[nodiscard]] static std::set<std::string> getEntries (const std::string& prefix = std::string());
1748
1749 enum class QuoteType : unsigned char {
1750 None = 0,
1751 Double,
1752 Triple
1753 };
1754
1755 struct PP_entry {
1756 // There can be multiple occurrences for a given name (e.g.,
1757 // multiple lines starting with `foo =` in inputs. For each
1758 // occurrence, there can be multiple values. Thus, the use of
1759 // vector<vector<std::string>>.
1760 std::vector<std::vector<std::string>> m_vals;
1761 std::vector<std::vector<QuoteType>> m_quotes;
1762 mutable Long m_count = 0;
1763 mutable std::variant<
1764 std::string*,
1765 bool*,
1766 int*,
1767 long*,
1768 long long*,
1770 amrex::Box*,
1771 float*,
1772 double*
1773 > m_typehint = static_cast<std::string*>(nullptr);
1774 mutable std::vector<std::variant<bool, int, long, long long, float, double>> m_last_vals;
1775 mutable bool m_parsed = false;
1776 };
1777 using Table = std::unordered_map<std::string, PP_entry>;
1778
1779 [[nodiscard]] const Table& table() const {return *m_table;}
1780
1782 static std::string const FileKeyword;
1783
1785 static std::string const UnsetKeyword;
1786
1787 static std::string ParserPrefix;
1788
1789 [[nodiscard]] std::string const& getPrefix () const;
1790
1791 [[nodiscard]] std::string prefixedName (std::string_view str) const;
1792
1793protected:
1794
1795 std::string m_prefix; // Prefix used in keyword search
1796 std::string m_parser_prefix; // Prefix used by Parser
1798};
1799
1800}
1801
1802#endif /* AMREX_PARMPARSE_H_ */
#define AMREX_ALWAYS_ASSERT(EX)
Definition AMReX_BLassert.H:50
Integer-only runtime expression parser and executor helpers.
Runtime expression parser front-end and compiled executor helpers.
Integer-only variant of amrex::Parser.
Definition AMReX_IParser.H:91
IParserExecutor< N > compileHost() const
Compile the expression into a host-only executor.
Definition AMReX_IParser.H:189
Parse Parameters From Command Line and Input Files.
Definition AMReX_ParmParse.H:349
QuoteType
Definition AMReX_ParmParse.H:1749
int queryline(std::string_view name, std::string &ref) const
Definition AMReX_ParmParse.cpp:2715
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:2730
int queryarrWithParser(std::string_view name, int nvals, std::vector< T > &ref) const
Definition AMReX_ParmParse.H:1159
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:1071
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:1045
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:1201
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:1657
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:3015
int query(std::string_view name, std::array< T, N > &ref) const
Definition AMReX_ParmParse.H:1026
static std::string const UnsetKeyword
keyword for removing entries from the table
Definition AMReX_ParmParse.H:1785
static void prettyPrintTable(std::ostream &os)
Definition AMReX_ParmParse.cpp:1849
void get(std::string_view name, T &ref, int ival=FIRST) const
. Get enum value using given name.
Definition AMReX_ParmParse.H:1351
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:1650
void getarr(std::string_view name, std::vector< T > &ref, int start_ix=FIRST, int num_val=ALL) const
Get an array of enum values using given name.
Definition AMReX_ParmParse.H:1396
static void addfile(std::string const &filename)
Definition AMReX_ParmParse.cpp:1620
static std::string const FileKeyword
keyword for files to load
Definition AMReX_ParmParse.H:1782
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:1521
static std::string ParserPrefix
Definition AMReX_ParmParse.H:1787
static int Verbose()
Definition AMReX_ParmParse.cpp:1731
static void SetVerbose(int v)
Definition AMReX_ParmParse.cpp:1744
int query(std::string_view name, T &ref, int ival=FIRST) const
. Query enum value using given name.
Definition AMReX_ParmParse.H:1313
void get(const char *new_name, const char *old_name, T &ref)
Get using two names.
Definition AMReX_ParmParse.H:1292
static bool hasUnusedInputs(const std::string &prefix=std::string())
Any unused [prefix.]* parameters?
Definition AMReX_ParmParse.cpp:1682
Parser makeParser(std::string const &func, Vector< std::string > const &vars) const
Definition AMReX_ParmParse.cpp:2933
int queryAdd(std::string_view name, std::string &ref)
Definition AMReX_ParmParse.H:1053
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:1429
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:2022
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:1542
static bool QueryUnusedInputs()
Definition AMReX_ParmParse.cpp:1667
void getline(std::string_view name, std::string &ref) const
Definition AMReX_ParmParse.cpp:2707
T eval(std::string const &expr) const
Definition AMReX_ParmParse.H:1258
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:2013
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:1220
void add(std::string_view name, const char *val)
Convert const char * to string, to prevent auto-conversion to bool.
Definition AMReX_ParmParse.H:619
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:1920
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:1602
bool contains(std::string_view name) const
Returns true if name is in table.
Definition AMReX_ParmParse.cpp:2746
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:1571
void get(std::string_view name, std::array< T, N > &ref) const
Definition AMReX_ParmParse.H:1016
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:1682
static void prettyPrintUsedInputs(std::ostream &os)
Definition AMReX_ParmParse.cpp:1861
static void Finalize()
The destructor. The internal static table will only be deleted if there are no other ParmParse object...
Definition AMReX_ParmParse.cpp:1750
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:1095
std::string m_prefix
Definition AMReX_ParmParse.H:1795
const Table & table() const
Definition AMReX_ParmParse.H:1779
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:1181
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:1937
static void SetParserPrefix(std::string a_prefix)
Set prefix used by math expression Parser.
Definition AMReX_ParmParse.cpp:1777
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:2861
static std::vector< std::string > getUnusedInputs(const std::string &prefix=std::string())
Returns unused [prefix.]* parameters.
Definition AMReX_ParmParse.cpp:1688
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:2041
std::string const & getPrefix() const
Definition AMReX_ParmParse.cpp:1600
int remove(std::string_view name)
Remove given name from the table.
Definition AMReX_ParmParse.cpp:2762
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:2032
@ FIRST
Definition AMReX_ParmParse.H:351
@ LAST
Definition AMReX_ParmParse.H:351
@ ALL
Definition AMReX_ParmParse.H:351
void add(std::string_view name, T const &val)
Definition AMReX_ParmParse.H:1336
int queryarr(std::string_view name, std::vector< T > &ref, int start_ix=FIRST, int num_val=ALL) const
Query an array of enum values using given name.
Definition AMReX_ParmParse.H:1369
static void Initialize(int argc, char **argv, const std::string &parfile)
Definition AMReX_ParmParse.H:1700
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:1110
int query(const char *new_name, const char *old_name, T &ref)
Definition AMReX_ParmParse.H:1278
Table * m_table
Definition AMReX_ParmParse.H:1797
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:2897
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:1619
std::string m_parser_prefix
Definition AMReX_ParmParse.H:1796
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:1954
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:1459
static void dumpTable(std::ostream &os, bool prettyPrint=false)
Definition AMReX_ParmParse.cpp:1785
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:2003
static void prettyPrintUnusedInputs(std::ostream &os)
Definition AMReX_ParmParse.cpp:1855
static std::set< std::string > getEntries(const std::string &prefix=std::string())
Returns [prefix.]* parameters.
Definition AMReX_ParmParse.cpp:1718
std::string prefixedName(std::string_view str) const
Definition AMReX_ParmParse.cpp:1606
void getarrWithParser(std::string_view name, int nvals, std::vector< T > &ref) const
Get with Parser. If name is not found, it's a runtime error. If the number of elements does not equal...
Definition AMReX_ParmParse.H:1239
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:1946
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:1484
int queryAdd(std::string_view name, Vector< T > &ref)
Definition AMReX_ParmParse.H:1084
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:1929
std::unordered_map< std::string, PP_entry > Table
Definition AMReX_ParmParse.H:1777
IParser makeIParser(std::string const &func, Vector< std::string > const &vars) const
Definition AMReX_ParmParse.cpp:2940
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:1867
Front-end for parsing scalar expressions into GPU/CPU executors.
Definition AMReX_Parser.H:122
ParserExecutor< N > compileHost() const
Compile the current expression into a host-only executor.
Definition AMReX_Parser.H:268
This class provides the user with a few print options.
Definition AMReX_Print.H:35
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:28
amrex_long Long
Definition AMReX_INT.H:30
Definition AMReX_Amr.cpp:49
std::ostream & ErrorStream()
Definition AMReX.cpp:962
std::string getEnumNameString(T const &v)
Definition AMReX_Enum.H:157
BoxND< 3 > Box
Box is an alias for amrex::BoxND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:30
__host__ __device__ RealVectND(Real, Real, Args...) -> RealVectND< sizeof...(Args)+2 >
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:33
void Error(const std::string &msg)
Print out message to cerr and exit via amrex::Abort().
Definition AMReX.cpp:234
__host__ __device__ IntVectND(const Array< int, dim > &) -> IntVectND< dim >
int Verbose() noexcept
Definition AMReX.cpp:179
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition AMReX.cpp:240
Definition AMReX_ParmParse.H:1755
std::variant< std::string *, bool *, int *, long *, long long *, amrex::IntVect *, amrex::Box *, float *, double * > m_typehint
Definition AMReX_ParmParse.H:1773
std::vector< std::vector< std::string > > m_vals
Definition AMReX_ParmParse.H:1760
std::vector< std::vector< QuoteType > > m_quotes
Definition AMReX_ParmParse.H:1761
Long m_count
Definition AMReX_ParmParse.H:1762
std::vector< std::variant< bool, int, long, long long, float, double > > m_last_vals
Definition AMReX_ParmParse.H:1774
bool m_parsed
Definition AMReX_ParmParse.H:1775