96#include "AMReX_ParmParse.H"
99#define pp_query_required(...) pp.query_required(__VA_ARGS__,INFO)
100#define pp_query_default(...) pp.query_default(__VA_ARGS__,INFO)
101#define pp_query_validate(...) pp.query_validate(__VA_ARGS__,INFO)
102#define pp_query_file(...) pp.query_file(__VA_ARGS__,INFO)
103#define pp_queryarr(...) pp.queryarr(__VA_ARGS__,INFO)
104#define pp_queryarr_required(...) pp.queryarr_required(__VA_ARGS__,INFO)
105#define pp_queryarr_default(...) pp.queryarr_default(__VA_ARGS__,INFO)
106#define pp_query(...) pp.query(__VA_ARGS__)
107#define pp_queryclass(...) pp.queryclass(__VA_ARGS__,INFO)
108#define pp_forbid(...) pp.forbid(__VA_ARGS__,INFO)
120 std::string inputfile =
"";
121 while (this->querykth(
"input",k,inputfile))
124 this->addfile(inputfile);
137 (void)amrex::ParmParse::contains(name.c_str());
142 if (m_prefix.length())
143 m_prefix = m_prefix +
"." +
prefix;
150 size_t pos = m_prefix.rfind(
'.');
151 if (pos == std::string::npos)
154 m_prefix = m_prefix.substr(0, pos);
158 void forbid(std::string name, std::string explanation,
159 std::string file =
"", std::string func =
"",
int line = -1)
161 if (amrex::ParmParse::contains(
full(name).c_str()))
165 std::set<std::string> subs = amrex::ParmParse::getEntries(
full(name));
174 if (amrex::ParmParse::contains(name.c_str()))
176 if (amrex::ParmParse::contains(
full(name).c_str()))
179 std::set<std::string> subs = amrex::ParmParse::getEntries(name.c_str());
184 std::set<std::string> subs = amrex::ParmParse::getEntries(
full(name).c_str());
193 std::string file =
"", std::string func =
"",
int line = -1)
199 return query(name.c_str(),value);
204 std::string =
"", std::string =
"",
int = -1)
208 add(name.c_str(),defaultvalue);
210 return query(name.c_str(),value);
213 int query_validate( std::string name,
int & value, std::vector<int> possibleintvals,
214 std::string file =
"", std::string func =
"",
int line = -1)
219 value = possibleintvals[0];
222 int retval = query(name.c_str(),value);
226 for (
unsigned int i = 0; i < possibleintvals.size(); i++)
228 if (value == possibleintvals[i]) ok =
true;
231 if (ok)
return retval;
233 std::stringstream ss;
234 ss << possibleintvals[0];
235 for (
unsigned int i = 1; i < possibleintvals.size(); i++)
236 ss <<
"," << possibleintvals[i];
244 int query_validate( std::string name, std::string & value, std::vector<const char *> possiblecharvals,
bool firstbydefault,
245 std::string file =
"", std::string func =
"",
int line = -1)
257 value = std::string(possiblecharvals[0]);
260 int retval = query(name.c_str(),value);
264 for (
unsigned int i = 0; i < possiblecharvals.size(); i++)
266 if (value == std::string(possiblecharvals[i])) ok =
true;
269 if (ok)
return retval;
271 std::stringstream ss;
272 ss << possiblecharvals[0];
273 for (
unsigned int i = 1; i < possiblecharvals.size(); i++)
274 ss <<
"," << possiblecharvals[i];
281 int query_validate( std::string name, std::string & value, std::vector<const char *> possiblecharvals,
282 std::string file =
"", std::string func =
"",
int line = -1)
284 return query_validate(name,value,possiblecharvals,
true,file,func,line);
289 int query_default( std::string name, std::string & value,
const char *defaultvalue,
290 std::string file =
"", std::string func =
"",
int line = -1)
292 return query_default(name, value, std::string(defaultvalue), file, func, line);
296 std::string file =
"", std::string func =
"query_default",
int line = -1)
299 if (defaultvalue) defaultint = 1;
300 return query_default(name, value, defaultint, file, func, line);
306 int query_file( std::string name, std::string & value,
bool copyfile,
bool checkfile,
307 std::string file =
"", std::string func =
"query_file",
int line = -1)
316 int retval = query(name.c_str(),value);
318 if (amrex::ParallelDescriptor::IOProcessor())
320 if ( checkfile && ! std::filesystem::exists(value))
324 if ( checkfile && !std::filesystem::is_regular_file(value))
341 int query_file( std::string name, std::string & value,
bool copyfile,
342 std::string file =
"", std::string func =
"query_file",
int line = -1)
344 return query_file(name,value,copyfile,
true,file,func,line);
347 std::string file =
"", std::string func =
"query_file",
int line = -1)
349 return query_file(name,value,
true,
true,file,func,line);
354 int queryarr( std::string name, std::vector<T> & value,
355 std::string , std::string ,
int )
357 return amrex::ParmParse::queryarr(name.c_str(),value);
360 std::string file =
"", std::string func =
"queryarr",
int line = -1)
362 std::vector<Set::Scalar> vals;
363 amrex::ParmParse::queryarr(name.c_str(), vals);
364 if (vals.size() < AMREX_SPACEDIM)
366 Util::ParmParseException(
INFO,file,func,line,
full(name),
full(name),
" requires at least ", AMREX_SPACEDIM,
" arguments, got ",vals.size());
368 for (
int i = 0; i < AMREX_SPACEDIM; i++) value(i) = vals[i];
372 std::string file =
"", std::string func =
"queryarr",
int line = -1)
374 std::vector<Set::Scalar> vals;
375 amrex::ParmParse::queryarr(name.c_str(), vals);
376 if (vals.size() == 9)
379 Util::Warning(file,func,line,
"Reading a 3D matrix (",
full(name),
")into a 2D code - some values will be ignored.");
380 value(0,0) = vals[0]; value(0,1)= vals[1];
381 value(1,0) = vals[3]; value(1,1)= vals[4];
384 value(0,0) = vals[0]; value(0,1)= vals[1]; value(0,2)= vals[2];
385 value(1,0) = vals[3]; value(1,1)= vals[4]; value(1,2)= vals[5];
386 value(2,0) = vals[6]; value(2,1)= vals[7]; value(2,2)= vals[8];
389 else if (vals.size() == 4)
392 value(0,0) = vals[0]; value(0,1)= vals[1];
393 value(1,0) = vals[2]; value(1,1)= vals[3];
396 Util::Warning(file,func,line,
"Reading a 2D matrix (",
full(name),
")into a 3D code - remaining values will be set to zero.");
397 value(0,0) = vals[0]; value(0,1)= vals[1]; value(0,2)= 0.0;
398 value(1,0) = vals[2]; value(1,1)= vals[3]; value(1,2)= 0.0;
399 value(2,0) = 0.0; value(2,1)= 0.0; value(2,2)= 0.0;
410 std::string file, std::string func,
int line)
416 return queryarr(name,value,file,func,line);
420 int queryarr_default( std::string name, std::vector<std::string> & value, std::string defaultvalue,
421 std::string =
"", std::string =
"",
int = -1)
425 add(name.c_str(),defaultvalue);
427 return queryarr(name.c_str(),value);
432 template <
typename T>
435 std::string file =
"", std::string func =
"",
int line = __LINE__)
443 std::string name = a_name;
446 for (
int n = 0; n < number; n++)
449 this->queryclass<T>(name, tmp, file, func, line);
450 value.push_back(tmp);
463 std::string name0 = a_name + std::to_string(0);
464 std::string name1 = a_name + std::to_string(1);
470 else if (this->
contains(name1.c_str()))
484 for (
int cntr = start; this->
contains(name.c_str()); cntr++)
489 this->queryclass<T>(name, tmp, file, func, line);
490 value.push_back(tmp);
492 name = a_name + std::to_string(cntr+1);
499 template <
typename T>
502 std::string file =
"", std::string func =
"",
int line = __LINE__)
510 std::string name = a_name;
513 for (
int n = 0; n < number; n++)
517 value.push_back(tmp);
530 std::string name0 = a_name + std::to_string(0);
531 std::string name1 = a_name + std::to_string(1);
537 else if (this->
contains(name1.c_str()))
551 for (
int cntr = start; this->
contains(name.c_str()); cntr++)
557 value.push_back(tmp);
559 name = a_name + std::to_string(cntr+1);
570 for (
auto li = m_table->begin(), End = m_table->end(); li != End; ++li)
572 if (!li->second.m_count)
576 if (li->first.rfind(
getPrefix()+
".",0) != std::string::npos)
594 std::vector<std::string> ret;
595 for (
auto li = m_table->begin(), End = m_table->end(); li != End; ++li)
597 if (!li->second.m_count && li->first.rfind(
getPrefix()+
".",0) != std::string::npos)
599 ret.push_back(li->first);
609 for (
auto li = pp.m_table->begin(), End = pp.m_table->end(); li != End; ++li)
611 if (!li->second.m_count)
623 std::string
full (std::string name)
631 using amrex::ParmParse::queryarr;
634 std::string file =
"", std::string func =
"",
int line = -1)
636 auto old_prefix = m_prefix;
639 if (old_prefix.empty()) m_prefix = name;
640 else m_prefix.append(
".").append(name);
641 T::Parse(*value, *
this);
643 if (unused_inputs.size())
645 std::stringstream ss;
646 for (
unsigned int i=0; i < unused_inputs.size(); i++)
647 ss <<
"\n\t" << unused_inputs[i];
653 m_prefix = old_prefix;
656 m_prefix = old_prefix;
660 std::string file =
"", std::string func =
"",
int line = __LINE__)
662 auto old_prefix = m_prefix;
665 if (old_prefix.empty()) m_prefix = name;
666 else m_prefix.append(
".").append(name);
667 T::Parse(value, *
this);
669 if (unused_inputs.size())
671 std::stringstream ss;
672 for (
unsigned int i=0; i < unused_inputs.size(); i++)
673 ss <<
"\n\t" << unused_inputs[i];
679 m_prefix = old_prefix;
682 m_prefix = old_prefix;
687 std::string file =
"", std::string func =
"",
int line = __LINE__)
691 T::Parse(*value, *
this);
700 std::string file =
"", std::string func =
"",
int line = __LINE__)
704 T::Parse(value, *
this);
720 template<
typename...
IC,
typename... Args,
typename PTRTYPE>
721 void select (std::string name, PTRTYPE *& ic_eta, Args&&... args)
725 if constexpr (
sizeof...(IC) == 0)
727 using first_IC = std::tuple_element_t<0, std::tuple<
IC...>>;
728 ic_eta =
new first_IC(std::forward<Args>(args)..., (*
this), name +
"." + std::string(first_IC::name));
733 std::string type =
"";
735 bool matched = (( type == IC::name
736 ? (ic_eta =
new IC(std::forward<Args>(args)..., (*
this), name +
"." + std::string(IC::name))),
748 template<
typename FirstIC,
typename...
IC,
typename... Args,
typename PTRTYPE>
751 std::string type =
"";
756 (( type == FirstIC::name
757 ? (ic_eta =
new FirstIC(std::forward<Args>(args)..., (*
this), name +
"." + std::string(FirstIC::name))),
761 ? (ic_eta =
new IC(std::forward<Args>(args)..., (*
this), name +
"." + std::string(IC::name))),
762 true :
false) || ...);
772 template<
typename...
IC,
typename... Args,
typename PTRTYPE>
782 std::string name = a_name;
786 this->
select<
IC...>(a_name, tmp, args...);
787 value.push_back(tmp);
799 std::string name0 = a_name + std::to_string(0);
800 std::string name1 = a_name + std::to_string(1);
806 else if (this->
contains(name1.c_str()))
820 for (
int cntr = start; this->
contains(name.c_str()); cntr++)
825 this->
select<
IC...>(name, tmp, args...);
826 value.push_back(tmp);
828 name = a_name + std::to_string(cntr+1);
837 template<
typename... INTEGRATOR,
typename... Args,
typename PTRTYPE>
840 std::string type =
"";
844 bool matched = ((type == INTEGRATOR::name
845 ? (ic_eta =
new INTEGRATOR(std::forward<Args>(args)..., (*
this))),
858 template<
typename INTEGRATOR,
typename Args,
typename PTRTYPE>
861 ic_eta =
new INTEGRATOR(std::forward<Args>(args), (*
this));
864 template<
typename INTEGRATOR,
typename PTRTYPE>
867 ic_eta =
new INTEGRATOR((*
this));
876 template <
typename... OBJ,
typename CLASS>
877 void select(std::string name, CLASS& value)
895 template <
typename CLASS,
int N,
typename... OBJ>
898 if constexpr (N == 0)
903 for (
unsigned int i = 0; i <
sizeof...(OBJ); i++)
904 if (type == value.names[i])
907 if (value.selected < 0)
910 ", invalid type " + type);
916 if constexpr (N <
sizeof...(OBJ))
918 if (value.selected == N)
920 std::get<N>(value.obj).Parse(std::get<N>(value.obj), *
this);
933 void query_exactly(std::vector<std::string> names, std::pair<std::string, Set::Scalar> values[N])
936 std::vector<std::string> read;
937 for (
unsigned int n = 0; n < names.size(); n++)
939 if (amrex::ParmParse::contains(names[n].c_str()))
941 read.push_back(names[n]);
950 for (
unsigned int n = 0; n < names.size(); n++)
952 if (amrex::ParmParse::contains(names[n].c_str()))
954 values[cnt].first = names[n];
int query_file(std::string name, std::string &value, bool copyfile, std::string file="", std::string func="query_file", int line=-1)
void forbid(std::string name, std::string explanation, std::string file="", std::string func="", int line=-1)
bool contains(std::string name)
int queryarr(std::string name, Set::Matrix &value, std::string file="", std::string func="queryarr", int line=-1)
void select(std::string name, CLASS &value)
void pushPrefix(const std::string prefix)
void query_exactly(std::vector< std::string > names, std::pair< std::string, Set::Scalar > values[N])
int query_default(std::string name, std::string &value, const char *defaultvalue, std::string file="", std::string func="", int line=-1)
int queryarr_required(std::string name, std::vector< T > &value, std::string file, std::string func, int line)
int AnyUnusedInputs(bool inscopeonly=true, bool verbose=false)
std::vector< std::string > GetUnusedInputs()
std::string getPrefix() const
static bool checked_for_input_files
int query_required(std::string name, T &value, std::string file="", std::string func="", int line=-1)
void queryclass(std::string name, T *value, std::string file="", std::string func="", int line=-1)
void select(std::string name, PTRTYPE *&ic_eta, Args &&... args)
void select_default(std::string name, PTRTYPE *&ic_eta, Args &&... args)
int query_validate(std::string name, std::string &value, std::vector< const char * > possiblecharvals, std::string file="", std::string func="", int line=-1)
int query_default(std::string name, T &value, T defaultvalue, std::string="", std::string="", int=-1)
int queryclass_enumerate(std::string a_name, std::vector< T > &value, int number=1, std::string file="", std::string func="", int line=__LINE__)
int queryarr(std::string name, Set::Vector &value, std::string file="", std::string func="queryarr", int line=-1)
void select_enumerate(std::string a_name, std::vector< PTRTYPE * > &value, Args &&... args)
static int AllUnusedInputs()
void queryclass(std::string name, T &value, std::string file="", std::string func="", int line=__LINE__)
int query_file(std::string name, std::string &value, std::string file="", std::string func="query_file", int line=-1)
int query_default(std::string name, int &value, bool defaultvalue, std::string file="", std::string func="query_default", int line=-1)
void queryclass(T &value, std::string file="", std::string func="", int line=__LINE__)
int queryarr(std::string name, std::vector< T > &value, std::string, std::string, int)
int query_file(std::string name, std::string &value, bool copyfile, bool checkfile, std::string file="", std::string func="query_file", int line=-1)
void static_polymorphism_parser(CLASS &value)
void select_only(PTRTYPE *&ic_eta, Args &&args)
void select_main(PTRTYPE *&ic_eta, Args &&... args)
void queryclass(T *value, std::string file="", std::string func="", int line=__LINE__)
void select_only(PTRTYPE *&ic_eta)
void ignore(std::string name)
std::string full(std::string name)
int query_validate(std::string name, std::string &value, std::vector< const char * > possiblecharvals, bool firstbydefault, std::string file="", std::string func="", int line=-1)
int query_enumerate(std::string a_name, std::vector< T > &value, int number=1, std::string file="", std::string func="", int line=__LINE__)
int queryarr_default(std::string name, std::vector< std::string > &value, std::string defaultvalue, std::string="", std::string="", int=-1)
int query_validate(std::string name, int &value, std::vector< int > possibleintvals, std::string file="", std::string func="", int line=-1)
ParmParse(std::string arg)
Initialize a spherical inclusion.
Eigen::Matrix< amrex::Real, AMREX_SPACEDIM, 1 > Vector
Eigen::Matrix< amrex::Real, AMREX_SPACEDIM, AMREX_SPACEDIM > Matrix
std::string Join(std::vector< std::string > &vec, char separator)
AMREX_FORCE_INLINE void AssertException(std::string file, std::string func, int line, std::string smt, bool pass, Args const &... args)
void Abort(const char *msg)
void ParmParseException(std::string file, std::string func, int line, std::string file2, std::string, int line2, std::string fullname, Args const &... args)
void CopyFileToOutputDir(std::string a_path, bool fullpath, std::string prefix)
void Warning(std::string file, std::string func, int line, Args const &... args)
void Message(std::string file, std::string func, int line, Args const &... args)
void Exception(std::string file, std::string func, int line, Args const &... args)