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_query(...) pp.query(__VA_ARGS__)
105 #define pp_queryclass(...) pp.queryclass(__VA_ARGS__,INFO)
106 #define pp_forbid(...) pp.forbid(__VA_ARGS__,INFO)
117 std::string inputfile =
"";
118 while (this->querykth(
"input",k,inputfile))
121 this->addfile(inputfile);
134 (void)amrex::ParmParse::contains(name.c_str());
137 void forbid(std::string name, std::string explanation,
138 std::string file =
"", std::string func =
"",
int line = -1)
140 if (amrex::ParmParse::contains(name.c_str()))
144 std::set<std::string> subs = amrex::ParmParse::getEntries(name);
153 if (amrex::ParmParse::contains(name.c_str()))
155 if (amrex::ParmParse::contains(
full(name).c_str()))
158 std::set<std::string> subs = amrex::ParmParse::getEntries(name.c_str());
163 std::set<std::string> subs = amrex::ParmParse::getEntries(
full(name).c_str());
172 std::string file =
"", std::string func =
"",
int line = -1)
178 return query(name.c_str(),value);
183 std::string =
"", std::string =
"",
int = -1)
187 add(name.c_str(),defaultvalue);
189 return query(name.c_str(),value);
192 int query_validate( std::string name,
int & value, std::vector<int> possibleintvals,
193 std::string file =
"", std::string func =
"",
int line = -1)
198 value = possibleintvals[0];
201 int retval = query(name.c_str(),value);
205 for (
unsigned int i = 0; i < possibleintvals.size(); i++)
207 if (value == possibleintvals[i]) ok =
true;
210 if (ok)
return retval;
212 std::stringstream ss;
213 ss << possibleintvals[0];
214 for (
unsigned int i = 1; i < possibleintvals.size(); i++)
215 ss <<
"," << possibleintvals[i];
223 int query_validate( std::string name, std::string & value, std::vector<const char *> possiblecharvals,
bool firstbydefault,
224 std::string file =
"", std::string func =
"",
int line = -1)
236 value = std::string(possiblecharvals[0]);
239 int retval = query(name.c_str(),value);
243 for (
unsigned int i = 0; i < possiblecharvals.size(); i++)
245 if (value == std::string(possiblecharvals[i])) ok =
true;
248 if (ok)
return retval;
250 std::stringstream ss;
251 ss << possiblecharvals[0];
252 for (
unsigned int i = 1; i < possiblecharvals.size(); i++)
253 ss <<
"," << possiblecharvals[i];
260 int query_validate( std::string name, std::string & value, std::vector<const char *> possiblecharvals,
261 std::string file =
"", std::string func =
"",
int line = -1)
263 return query_validate(name,value,possiblecharvals,
true,file,func,line);
268 int query_default( std::string name, std::string & value,
const char *defaultvalue,
269 std::string file =
"", std::string func =
"",
int line = -1)
271 return query_default(name, value, std::string(defaultvalue), file, func, line);
275 std::string file =
"", std::string func =
"query_default",
int line = -1)
278 if (defaultvalue) defaultint = 1;
279 return query_default(name, value, defaultint, file, func, line);
285 int query_file( std::string name, std::string & value,
bool copyfile,
bool checkfile,
286 std::string file =
"", std::string func =
"query_file",
int line = -1)
295 int retval = query(name.c_str(),value);
297 if (amrex::ParallelDescriptor::IOProcessor())
299 if ( checkfile && ! std::filesystem::exists(value))
303 if ( checkfile && !std::filesystem::is_regular_file(value))
320 int query_file( std::string name, std::string & value,
bool copyfile,
321 std::string file =
"", std::string func =
"query_file",
int line = -1)
323 return query_file(name,value,copyfile,
true,file,func,line);
326 std::string file =
"", std::string func =
"query_file",
int line = -1)
328 return query_file(name,value,
true,
true,file,func,line);
333 int queryarr( std::string name, std::vector<T> & value,
334 std::string , std::string ,
int )
336 return amrex::ParmParse::queryarr(name.c_str(),value);
339 std::string file =
"", std::string func =
"queryarr",
int line = -1)
341 std::vector<Set::Scalar> vals;
342 amrex::ParmParse::queryarr(name.c_str(), vals);
343 if (vals.size() < AMREX_SPACEDIM)
345 Util::ParmParseException(
INFO,file,func,line,
full(name),
full(name),
" requires at least ", AMREX_SPACEDIM,
" arguments, got ",vals.size());
347 for (
int i = 0; i < AMREX_SPACEDIM; i++) value(i) = vals[i];
351 std::string file =
"", std::string func =
"queryarr",
int line = -1)
353 std::vector<Set::Scalar> vals;
354 amrex::ParmParse::queryarr(name.c_str(), vals);
355 if (vals.size() == 9)
357 #if AMREX_SPACEDIM==2
358 Util::Warning(file,func,line,
"Reading a 3D matrix (",
full(name),
")into a 2D code - some values will be ignored.");
359 value(0,0) = vals[0]; value(0,1)= vals[1];
360 value(1,0) = vals[3]; value(1,1)= vals[4];
362 #if AMREX_SPACEDIM==3
363 value(0,0) = vals[0]; value(0,1)= vals[1]; value(0,2)= vals[2];
364 value(1,0) = vals[3]; value(1,1)= vals[4]; value(1,2)= vals[5];
365 value(2,0) = vals[6]; value(2,1)= vals[7]; value(2,2)= vals[8];
368 else if (vals.size() == 4)
370 #if AMREX_SPACEDIM==2
371 value(0,0) = vals[0]; value(0,1)= vals[1];
372 value(1,0) = vals[2]; value(1,1)= vals[3];
374 #if AMREX_SPACEDIM==3
375 Util::Warning(file,func,line,
"Reading a 2D matrix (",
full(name),
")into a 3D code - remaining values will be set to zero.");
376 value(0,0) = vals[0]; value(0,1)= vals[1]; value(0,2)= 0.0;
377 value(1,0) = vals[2]; value(1,1)= vals[3]; value(1,2)= 0.0;
378 value(2,0) = 0.0; value(2,1)= 0.0; value(2,2)= 0.0;
391 for (
auto li = m_table->begin(), End = m_table->end(); li != End; ++li)
393 if (!li->second.m_count && li->first.rfind(
getPrefix()+
".",0) != std::string::npos)
404 std::vector<std::string> ret;
405 for (
auto li = m_table->begin(), End = m_table->end(); li != End; ++li)
407 if (!li->second.m_count && li->first.rfind(
getPrefix()+
".",0) != std::string::npos)
409 ret.push_back(li->first);
419 for (
auto li = pp.m_table->begin(), End = pp.m_table->end(); li != End; ++li)
421 if (!li->second.m_count)
433 std::string
full (std::string name)
441 using amrex::ParmParse::queryarr;
444 std::string file =
"", std::string func =
"",
int line = -1)
446 auto old_prefix = m_prefix;
449 if (old_prefix.empty()) m_prefix = name;
450 else m_prefix.append(
".").append(name);
453 if (unused_inputs.size())
455 std::stringstream ss;
456 for (
unsigned int i=0; i < unused_inputs.size(); i++)
457 ss <<
"\n\t" << unused_inputs[i];
463 m_prefix = old_prefix;
466 m_prefix = old_prefix;
470 std::string file =
"", std::string func =
"",
int line = __LINE__)
472 auto old_prefix = m_prefix;
475 if (old_prefix.empty()) m_prefix = name;
476 else m_prefix.append(
".").append(name);
479 if (unused_inputs.size())
481 std::stringstream ss;
482 for (
unsigned int i=0; i < unused_inputs.size(); i++)
483 ss <<
"\n\t" << unused_inputs[i];
489 m_prefix = old_prefix;
492 m_prefix = old_prefix;
496 std::string file =
"", std::string func =
"",
int line = __LINE__)
502 if (unused_inputs.size())
504 std::stringstream ss;
505 for (
unsigned int i=0; i < unused_inputs.size(); i++)
506 ss <<
"\n\t" << unused_inputs[i];
517 std::string file =
"", std::string func =
"",
int line = __LINE__)
523 if (unused_inputs.size())
525 std::stringstream ss;
526 for (
unsigned int i=0; i < unused_inputs.size(); i++)
527 ss <<
"\n\t" << unused_inputs[i];