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_query(...) pp.query(__VA_ARGS__)
106 #define pp_queryclass(...) pp.queryclass(__VA_ARGS__,INFO)
107 #define pp_forbid(...) pp.forbid(__VA_ARGS__,INFO)
119 std::string inputfile =
"";
120 while (this->querykth(
"input",k,inputfile))
123 this->addfile(inputfile);
136 (void)amrex::ParmParse::contains(name.c_str());
139 void forbid(std::string name, std::string explanation,
140 std::string file =
"", std::string func =
"",
int line = -1)
142 if (amrex::ParmParse::contains(
full(name).c_str()))
146 std::set<std::string> subs = amrex::ParmParse::getEntries(
full(name));
155 if (amrex::ParmParse::contains(name.c_str()))
157 if (amrex::ParmParse::contains(
full(name).c_str()))
160 std::set<std::string> subs = amrex::ParmParse::getEntries(name.c_str());
165 std::set<std::string> subs = amrex::ParmParse::getEntries(
full(name).c_str());
174 std::string file =
"", std::string func =
"",
int line = -1)
180 return query(name.c_str(),value);
185 std::string =
"", std::string =
"",
int = -1)
189 add(name.c_str(),defaultvalue);
191 return query(name.c_str(),value);
194 int query_validate( std::string name,
int & value, std::vector<int> possibleintvals,
195 std::string file =
"", std::string func =
"",
int line = -1)
200 value = possibleintvals[0];
203 int retval = query(name.c_str(),value);
207 for (
unsigned int i = 0; i < possibleintvals.size(); i++)
209 if (value == possibleintvals[i]) ok =
true;
212 if (ok)
return retval;
214 std::stringstream ss;
215 ss << possibleintvals[0];
216 for (
unsigned int i = 1; i < possibleintvals.size(); i++)
217 ss <<
"," << possibleintvals[i];
225 int query_validate( std::string name, std::string & value, std::vector<const char *> possiblecharvals,
bool firstbydefault,
226 std::string file =
"", std::string func =
"",
int line = -1)
238 value = std::string(possiblecharvals[0]);
241 int retval = query(name.c_str(),value);
245 for (
unsigned int i = 0; i < possiblecharvals.size(); i++)
247 if (value == std::string(possiblecharvals[i])) ok =
true;
250 if (ok)
return retval;
252 std::stringstream ss;
253 ss << possiblecharvals[0];
254 for (
unsigned int i = 1; i < possiblecharvals.size(); i++)
255 ss <<
"," << possiblecharvals[i];
262 int query_validate( std::string name, std::string & value, std::vector<const char *> possiblecharvals,
263 std::string file =
"", std::string func =
"",
int line = -1)
265 return query_validate(name,value,possiblecharvals,
true,file,func,line);
270 int query_default( std::string name, std::string & value,
const char *defaultvalue,
271 std::string file =
"", std::string func =
"",
int line = -1)
273 return query_default(name, value, std::string(defaultvalue), file, func, line);
277 std::string file =
"", std::string func =
"query_default",
int line = -1)
280 if (defaultvalue) defaultint = 1;
281 return query_default(name, value, defaultint, file, func, line);
287 int query_file( std::string name, std::string & value,
bool copyfile,
bool checkfile,
288 std::string file =
"", std::string func =
"query_file",
int line = -1)
297 int retval = query(name.c_str(),value);
299 if (amrex::ParallelDescriptor::IOProcessor())
301 if ( checkfile && ! std::filesystem::exists(value))
305 if ( checkfile && !std::filesystem::is_regular_file(value))
322 int query_file( std::string name, std::string & value,
bool copyfile,
323 std::string file =
"", std::string func =
"query_file",
int line = -1)
325 return query_file(name,value,copyfile,
true,file,func,line);
328 std::string file =
"", std::string func =
"query_file",
int line = -1)
330 return query_file(name,value,
true,
true,file,func,line);
335 int queryarr( std::string name, std::vector<T> & value,
336 std::string , std::string ,
int )
338 return amrex::ParmParse::queryarr(name.c_str(),value);
341 std::string file =
"", std::string func =
"queryarr",
int line = -1)
343 std::vector<Set::Scalar> vals;
344 amrex::ParmParse::queryarr(name.c_str(), vals);
345 if (vals.size() < AMREX_SPACEDIM)
347 Util::ParmParseException(
INFO,file,func,line,
full(name),
full(name),
" requires at least ", AMREX_SPACEDIM,
" arguments, got ",vals.size());
349 for (
int i = 0; i < AMREX_SPACEDIM; i++) value(i) = vals[i];
353 std::string file =
"", std::string func =
"queryarr",
int line = -1)
355 std::vector<Set::Scalar> vals;
356 amrex::ParmParse::queryarr(name.c_str(), vals);
357 if (vals.size() == 9)
359 #if AMREX_SPACEDIM==2
360 Util::Warning(file,func,line,
"Reading a 3D matrix (",
full(name),
")into a 2D code - some values will be ignored.");
361 value(0,0) = vals[0]; value(0,1)= vals[1];
362 value(1,0) = vals[3]; value(1,1)= vals[4];
364 #if AMREX_SPACEDIM==3
365 value(0,0) = vals[0]; value(0,1)= vals[1]; value(0,2)= vals[2];
366 value(1,0) = vals[3]; value(1,1)= vals[4]; value(1,2)= vals[5];
367 value(2,0) = vals[6]; value(2,1)= vals[7]; value(2,2)= vals[8];
370 else if (vals.size() == 4)
372 #if AMREX_SPACEDIM==2
373 value(0,0) = vals[0]; value(0,1)= vals[1];
374 value(1,0) = vals[2]; value(1,1)= vals[3];
376 #if AMREX_SPACEDIM==3
377 Util::Warning(file,func,line,
"Reading a 2D matrix (",
full(name),
")into a 3D code - remaining values will be set to zero.");
378 value(0,0) = vals[0]; value(0,1)= vals[1]; value(0,2)= 0.0;
379 value(1,0) = vals[2]; value(1,1)= vals[3]; value(1,2)= 0.0;
380 value(2,0) = 0.0; value(2,1)= 0.0; value(2,2)= 0.0;
391 std::string file, std::string func,
int line)
397 return queryarr(name,value,file,func,line);
403 for (
auto li = m_table->begin(), End = m_table->end(); li != End; ++li)
405 if (!li->second.m_count && li->first.rfind(
getPrefix()+
".",0) != std::string::npos)
416 std::vector<std::string> ret;
417 for (
auto li = m_table->begin(), End = m_table->end(); li != End; ++li)
419 if (!li->second.m_count && li->first.rfind(
getPrefix()+
".",0) != std::string::npos)
421 ret.push_back(li->first);
431 for (
auto li = pp.m_table->begin(), End = pp.m_table->end(); li != End; ++li)
433 if (!li->second.m_count)
445 std::string
full (std::string name)
453 using amrex::ParmParse::queryarr;
456 std::string file =
"", std::string func =
"",
int line = -1)
458 auto old_prefix = m_prefix;
461 if (old_prefix.empty()) m_prefix = name;
462 else m_prefix.append(
".").append(name);
465 if (unused_inputs.size())
467 std::stringstream ss;
468 for (
unsigned int i=0; i < unused_inputs.size(); i++)
469 ss <<
"\n\t" << unused_inputs[i];
475 m_prefix = old_prefix;
478 m_prefix = old_prefix;
482 std::string file =
"", std::string func =
"",
int line = __LINE__)
484 auto old_prefix = m_prefix;
487 if (old_prefix.empty()) m_prefix = name;
488 else m_prefix.append(
".").append(name);
491 if (unused_inputs.size())
493 std::stringstream ss;
494 for (
unsigned int i=0; i < unused_inputs.size(); i++)
495 ss <<
"\n\t" << unused_inputs[i];
501 m_prefix = old_prefix;
504 m_prefix = old_prefix;
508 std::string file =
"", std::string func =
"",
int line = __LINE__)
521 std::string file =
"", std::string func =
"",
int line = __LINE__)
540 template<
typename...
IC,
typename... Args,
typename PTRTYPE>
541 void select (std::string name, PTRTYPE *& ic_eta, Args&&... args)
543 std::string type =
"";
547 bool matched = ((type == IC::name
548 ? (ic_eta =
new IC(std::forward<Args>(args)..., (*
this), name +
"." + std::string(IC::name))),
559 template<
typename FirstIC,
typename...
IC,
typename... Args,
typename PTRTYPE>
562 std::string type =
"";
567 (( type == FirstIC::name
568 ? (ic_eta =
new FirstIC(std::forward<Args>(args)..., (*
this), name +
"." + std::string(FirstIC::name))),
572 ? (ic_eta =
new IC(std::forward<Args>(args)..., (*
this), name +
"." + std::string(IC::name))),
573 true :
false) || ...);