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());
140 void forbid(std::string name, std::string explanation,
141 std::string file =
"", std::string func =
"",
int line = -1)
143 if (amrex::ParmParse::contains(
full(name).c_str()))
147 std::set<std::string> subs = amrex::ParmParse::getEntries(
full(name));
156 if (amrex::ParmParse::contains(name.c_str()))
158 if (amrex::ParmParse::contains(
full(name).c_str()))
161 std::set<std::string> subs = amrex::ParmParse::getEntries(name.c_str());
166 std::set<std::string> subs = amrex::ParmParse::getEntries(
full(name).c_str());
175 std::string file =
"", std::string func =
"",
int line = -1)
181 return query(name.c_str(),value);
186 std::string =
"", std::string =
"",
int = -1)
190 add(name.c_str(),defaultvalue);
192 return query(name.c_str(),value);
195 int query_validate( std::string name,
int & value, std::vector<int> possibleintvals,
196 std::string file =
"", std::string func =
"",
int line = -1)
201 value = possibleintvals[0];
204 int retval = query(name.c_str(),value);
208 for (
unsigned int i = 0; i < possibleintvals.size(); i++)
210 if (value == possibleintvals[i]) ok =
true;
213 if (ok)
return retval;
215 std::stringstream ss;
216 ss << possibleintvals[0];
217 for (
unsigned int i = 1; i < possibleintvals.size(); i++)
218 ss <<
"," << possibleintvals[i];
226 int query_validate( std::string name, std::string & value, std::vector<const char *> possiblecharvals,
bool firstbydefault,
227 std::string file =
"", std::string func =
"",
int line = -1)
239 value = std::string(possiblecharvals[0]);
242 int retval = query(name.c_str(),value);
246 for (
unsigned int i = 0; i < possiblecharvals.size(); i++)
248 if (value == std::string(possiblecharvals[i])) ok =
true;
251 if (ok)
return retval;
253 std::stringstream ss;
254 ss << possiblecharvals[0];
255 for (
unsigned int i = 1; i < possiblecharvals.size(); i++)
256 ss <<
"," << possiblecharvals[i];
263 int query_validate( std::string name, std::string & value, std::vector<const char *> possiblecharvals,
264 std::string file =
"", std::string func =
"",
int line = -1)
266 return query_validate(name,value,possiblecharvals,
true,file,func,line);
271 int query_default( std::string name, std::string & value,
const char *defaultvalue,
272 std::string file =
"", std::string func =
"",
int line = -1)
274 return query_default(name, value, std::string(defaultvalue), file, func, line);
278 std::string file =
"", std::string func =
"query_default",
int line = -1)
281 if (defaultvalue) defaultint = 1;
282 return query_default(name, value, defaultint, file, func, line);
288 int query_file( std::string name, std::string & value,
bool copyfile,
bool checkfile,
289 std::string file =
"", std::string func =
"query_file",
int line = -1)
298 int retval = query(name.c_str(),value);
300 if (amrex::ParallelDescriptor::IOProcessor())
302 if ( checkfile && ! std::filesystem::exists(value))
306 if ( checkfile && !std::filesystem::is_regular_file(value))
323 int query_file( std::string name, std::string & value,
bool copyfile,
324 std::string file =
"", std::string func =
"query_file",
int line = -1)
326 return query_file(name,value,copyfile,
true,file,func,line);
329 std::string file =
"", std::string func =
"query_file",
int line = -1)
331 return query_file(name,value,
true,
true,file,func,line);
336 int queryarr( std::string name, std::vector<T> & value,
337 std::string , std::string ,
int )
339 return amrex::ParmParse::queryarr(name.c_str(),value);
342 std::string file =
"", std::string func =
"queryarr",
int line = -1)
344 std::vector<Set::Scalar> vals;
345 amrex::ParmParse::queryarr(name.c_str(), vals);
346 if (vals.size() < AMREX_SPACEDIM)
348 Util::ParmParseException(
INFO,file,func,line,
full(name),
full(name),
" requires at least ", AMREX_SPACEDIM,
" arguments, got ",vals.size());
350 for (
int i = 0; i < AMREX_SPACEDIM; i++) value(i) = vals[i];
354 std::string file =
"", std::string func =
"queryarr",
int line = -1)
356 std::vector<Set::Scalar> vals;
357 amrex::ParmParse::queryarr(name.c_str(), vals);
358 if (vals.size() == 9)
361 Util::Warning(file,func,line,
"Reading a 3D matrix (",
full(name),
")into a 2D code - some values will be ignored.");
362 value(0,0) = vals[0]; value(0,1)= vals[1];
363 value(1,0) = vals[3]; value(1,1)= vals[4];
366 value(0,0) = vals[0]; value(0,1)= vals[1]; value(0,2)= vals[2];
367 value(1,0) = vals[3]; value(1,1)= vals[4]; value(1,2)= vals[5];
368 value(2,0) = vals[6]; value(2,1)= vals[7]; value(2,2)= vals[8];
371 else if (vals.size() == 4)
374 value(0,0) = vals[0]; value(0,1)= vals[1];
375 value(1,0) = vals[2]; value(1,1)= vals[3];
378 Util::Warning(file,func,line,
"Reading a 2D matrix (",
full(name),
")into a 3D code - remaining values will be set to zero.");
379 value(0,0) = vals[0]; value(0,1)= vals[1]; value(0,2)= 0.0;
380 value(1,0) = vals[2]; value(1,1)= vals[3]; value(1,2)= 0.0;
381 value(2,0) = 0.0; value(2,1)= 0.0; value(2,2)= 0.0;
392 std::string file, std::string func,
int line)
398 return queryarr(name,value,file,func,line);
402 int queryarr_default( std::string name, std::vector<std::string> & value, std::string defaultvalue,
403 std::string =
"", std::string =
"",
int = -1)
407 add(name.c_str(),defaultvalue);
409 return queryarr(name.c_str(),value);
414 template <
typename T>
417 std::string file =
"", std::string func =
"",
int line = __LINE__)
425 std::string name = a_name;
428 for (
int n = 0; n < number; n++)
431 this->queryclass<T>(name, tmp, file, func, line);
432 value.push_back(tmp);
445 std::string name0 = a_name + std::to_string(0);
446 std::string name1 = a_name + std::to_string(1);
452 else if (this->
contains(name1.c_str()))
466 for (
int cntr = start; this->
contains(name.c_str()); cntr++)
471 this->queryclass<T>(name, tmp, file, func, line);
472 value.push_back(tmp);
474 name = a_name + std::to_string(cntr+1);
481 template <
typename T>
484 std::string file =
"", std::string func =
"",
int line = __LINE__)
492 std::string name = a_name;
495 for (
int n = 0; n < number; n++)
499 value.push_back(tmp);
512 std::string name0 = a_name + std::to_string(0);
513 std::string name1 = a_name + std::to_string(1);
519 else if (this->
contains(name1.c_str()))
533 for (
int cntr = start; this->
contains(name.c_str()); cntr++)
539 value.push_back(tmp);
541 name = a_name + std::to_string(cntr+1);
552 for (
auto li = m_table->begin(), End = m_table->end(); li != End; ++li)
554 if (!li->second.m_count && li->first.rfind(
getPrefix()+
".",0) != std::string::npos)
565 std::vector<std::string> ret;
566 for (
auto li = m_table->begin(), End = m_table->end(); li != End; ++li)
568 if (!li->second.m_count && li->first.rfind(
getPrefix()+
".",0) != std::string::npos)
570 ret.push_back(li->first);
580 for (
auto li = pp.m_table->begin(), End = pp.m_table->end(); li != End; ++li)
582 if (!li->second.m_count)
594 std::string
full (std::string name)
602 using amrex::ParmParse::queryarr;
605 std::string file =
"", std::string func =
"",
int line = -1)
607 auto old_prefix = m_prefix;
610 if (old_prefix.empty()) m_prefix = name;
611 else m_prefix.append(
".").append(name);
612 T::Parse(*value, *
this);
614 if (unused_inputs.size())
616 std::stringstream ss;
617 for (
unsigned int i=0; i < unused_inputs.size(); i++)
618 ss <<
"\n\t" << unused_inputs[i];
624 m_prefix = old_prefix;
627 m_prefix = old_prefix;
631 std::string file =
"", std::string func =
"",
int line = __LINE__)
633 auto old_prefix = m_prefix;
636 if (old_prefix.empty()) m_prefix = name;
637 else m_prefix.append(
".").append(name);
638 T::Parse(value, *
this);
640 if (unused_inputs.size())
642 std::stringstream ss;
643 for (
unsigned int i=0; i < unused_inputs.size(); i++)
644 ss <<
"\n\t" << unused_inputs[i];
650 m_prefix = old_prefix;
653 m_prefix = old_prefix;
658 std::string file =
"", std::string func =
"",
int line = __LINE__)
662 T::Parse(*value, *
this);
671 std::string file =
"", std::string func =
"",
int line = __LINE__)
675 T::Parse(value, *
this);
691 template<
typename...
IC,
typename... Args,
typename PTRTYPE>
692 void select (std::string name, PTRTYPE *& ic_eta, Args&&... args)
696 if constexpr (
sizeof...(IC) == 0)
698 using first_IC = std::tuple_element_t<0, std::tuple<
IC...>>;
699 ic_eta =
new first_IC(std::forward<Args>(args)..., (*
this), name +
"." + std::string(first_IC::name));
704 std::string type =
"";
706 bool matched = (( type == IC::name
707 ? (ic_eta =
new IC(std::forward<Args>(args)..., (*
this), name +
"." + std::string(IC::name))),
719 template<
typename FirstIC,
typename...
IC,
typename... Args,
typename PTRTYPE>
722 std::string type =
"";
727 (( type == FirstIC::name
728 ? (ic_eta =
new FirstIC(std::forward<Args>(args)..., (*
this), name +
"." + std::string(FirstIC::name))),
732 ? (ic_eta =
new IC(std::forward<Args>(args)..., (*
this), name +
"." + std::string(IC::name))),
733 true :
false) || ...);
743 template<
typename... INTEGRATOR,
typename... Args,
typename PTRTYPE>
746 std::string type =
"";
750 bool matched = ((type == INTEGRATOR::name
751 ? (ic_eta =
new INTEGRATOR(std::forward<Args>(args)..., (*
this))),
764 template<
typename INTEGRATOR,
typename Args,
typename PTRTYPE>
767 ic_eta =
new INTEGRATOR(std::forward<Args>(args), (*
this));
770 template<
typename INTEGRATOR,
typename PTRTYPE>
773 ic_eta =
new INTEGRATOR((*
this));
778 void query_exactly(std::vector<std::string> names, std::pair<std::string, Set::Scalar> values[N])
781 for (
unsigned int n = 0; n < names.size(); n++)
783 if (amrex::ParmParse::contains(names[n].c_str()))
791 for (
unsigned int n = 0; n < names.size(); n++)
793 if (amrex::ParmParse::contains(names[n].c_str()))
795 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 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)
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)
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 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
AMREX_FORCE_INLINE void Assert(std::string file, std::string func, int line, std::string smt, bool pass, Args const &... args)
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)