2#include "AMReX_Config.H"
3#include "AMReX_DistributionMapping.H"
4#include "AMReX_VisMF.H"
15#include "AMReX_ParallelDescriptor.H"
16#include "AMReX_Utility.H"
22#include "Numeric/Stencil.H"
29ParseArgsError(
const std::string &message)
31 std::cerr <<
"ERROR: " << message << std::endl;
32 std::exit(EXIT_FAILURE);
36IsInputDefinition(
const std::string &arg)
38 return arg ==
"input" || arg.rfind(
"input=", 0) == 0;
42RejectParseArgsInputFiles(
const std::vector<char*> &argv)
44 for (std::size_t i = 1; i < argv.size(); ++i)
46 const std::string arg(argv[i]);
48 if (arg ==
"--")
break;
50 if (IsInputDefinition(arg))
52 ParseArgsError(
"--parse-args does not accept input-file directives: " + arg);
55 if (arg ==
"=")
continue;
56 if (!arg.empty() && arg[0] ==
'-')
continue;
57 if (arg.find(
'=') != std::string::npos)
continue;
58 if (i + 1 < argv.size() && std::string(argv[i + 1]) ==
"=")
continue;
59 if (i > 1 && std::string(argv[i - 1]) ==
"=")
continue;
61 ParseArgsError(
"--parse-args does not accept input files or positional arguments: " + arg);
66InjectParseArgsDefaults()
69 amrex::ParmParse pp(
"amr");
72 pp.queryAdd(
"max_level", max_level);
74 std::vector<int> n_cell(AMREX_SPACEDIM, 1);
75 pp.queryAdd(
"n_cell", n_cell);
77 int max_grid_size = 1;
78 pp.queryAdd(
"max_grid_size", max_grid_size);
80 int blocking_factor = 1;
81 pp.queryAdd(
"blocking_factor", blocking_factor);
85 amrex::ParmParse pp(
"geometry");
87 std::vector<double> prob_lo(AMREX_SPACEDIM, 0.0);
88 pp.queryAdd(
"prob_lo", prob_lo, AMREX_SPACEDIM);
90 if (!pp.contains(
"prob_hi") && !pp.contains(
"prob_extent"))
92 std::vector<double> prob_hi(AMREX_SPACEDIM, 1.0);
93 pp.addarr(
"prob_hi", prob_hi);
96 std::vector<int> is_periodic(AMREX_SPACEDIM, 0);
97 pp.queryAdd(
"is_periodic", is_periodic, AMREX_SPACEDIM);
103 std::string stop_time =
"1.0";
104 pp.queryAdd(
"stop_time", stop_time);
106 std::string timestep =
"1.0";
107 pp.queryAdd(
"timestep", timestep);
127 pp.
forbid(
"amr.plot_file",
"Depricated");
146 Util::Exception(
INFO,
"Cannot back up files yet because the output directory has not been specified");
148 std::string basefilename = std::filesystem::path(a_path).filename();
149 std::string absolutepath = std::filesystem::absolute(std::filesystem::path(a_path)).string();
150 std::string abspathfilename = absolutepath;
151 std::replace(abspathfilename.begin(),abspathfilename.end(),
'/',
'_');
154 abspathfilename = prefix +
"__" + abspathfilename;
155 basefilename = prefix +
"__" + abspathfilename;
158 if (amrex::ParallelDescriptor::IOProcessor())
160 std::string destinationpath;
161 if (fullpath) destinationpath =
filename+
"/"+abspathfilename;
162 else destinationpath =
filename+
"/"+basefilename;
165 if (std::filesystem::exists(destinationpath))
167 std::filesystem::copy_file(a_path,destinationpath);
170 catch (std::filesystem::filesystem_error
const& ex)
173 "file system error: \n",
174 " what(): " , ex.what() ,
'\n',
175 " path1(): " , ex.path1() ,
'\n',
176 " path2(): " , ex.path2() ,
'\n',
177 " code().value(): " , ex.code().value() ,
'\n',
178 " code().message(): " , ex.code().message() ,
'\n',
179 " code().category(): " , ex.code().category().name());
191 amrex::ParallelDescriptor::IOProcessor())
206 time_t timer; time(&timer);
207 std::stringstream cmd;
208 cmd <<
"xdg-open " << BUILD_DIR <<
"/src/Util/Meme/cat0" << (1+((int)timer)%6) <<
".gif &";
209 std::system(cmd.str().c_str());
214 amrex::BLBackTrace::handler(s);
221 char **argv =
nullptr;
229 bool parse_args =
false;
230 std::string parse_args_output =
"alamo-inputs.schema.json";
231 std::vector<char*> amrex_argv;
232 amrex_argv.reserve(argc > 0 ? argc : 0);
233 for (
int i = 0; i < argc; i++)
235 if (std::string(argv[i]) ==
"--parse-args")
240 if (std::string(argv[i]) ==
"--parse-args-output")
243 ParseArgsError(
"--parse-args-output requires a file path");
244 parse_args_output = argv[++i];
247 amrex_argv.push_back(argv[i]);
250 if (parse_args) RejectParseArgsInputFiles(amrex_argv);
252 int amrex_argc =
static_cast<int>(amrex_argv.size());
253 amrex_argv.push_back(
nullptr);
254 char **amrex_argv_ptr = amrex_argc == 0 ? nullptr : amrex_argv.data();
260 amrex::Initialize(amrex_argc, amrex_argv_ptr);
262 if (parse_args) InjectParseArgsDefaults();
265 pp.add(
"amrex.throw_exception",1);
275 amrex::ParallelDescriptor::IOProcessor() &&
filename !=
"")
281 std::string length, time, mass, temperature, current, amount, luminousintensity;
295 pp.
query_default(
"system.luminousintensity",luminousintensity,
"cd");
309 catch (std::runtime_error &e)
326 std::vector<Set::Scalar> prob_lo, prob_hi;
331 pp.remove(
"prob_lo");
332 pp.remove(
"prob_hi");
335 "Invalid domain specified: ", prob_lo[0],
" < x < ", prob_hi[0],
" is incorrect.");
337 "Invalid domain specified: ", prob_lo[0],
" < y < ", prob_hi[0],
" is incorrect.");
340 "Invalid domain specified: ", prob_lo[0],
" < z < ", prob_hi[0],
" is incorrect.");
346 pp.addarr(
"prob_lo",prob_lo);
347 pp.addarr(
"prob_hi",prob_hi);
361 std::vector<std::string> ignore;
364 for (
unsigned int i = 0; i < ignore.size(); i++)
367 pp.remove(ignore[i].c_str());
394 AMREX_IF_ON_HOST((
Terminate(msg, SIGABRT,
true);))
395 AMREX_IF_ON_DEVICE((amrex::Abort();))
404std::pair<std::string,std::string>
407 std::pair<std::string,std::string> ret(
"",
"");
409 if(amrex::ParallelDescriptor::IOProcessor()) {
410 if(amrex::FileExists(path)) {
411 std::time_t
t = std::time(0);
412 std::tm * now = std::localtime(&
t);
413 int year = now->tm_year+1900;
414 int month = now->tm_mon+1;
415 int day = now->tm_mday;
416 int hour = now->tm_hour;
417 int minute = now->tm_min;
418 int second = now->tm_sec;
420 std::stringstream ss;
422 << std::setfill(
'0') << std::setw(2) << month
423 << std::setfill(
'0') << std::setw(2) << day
424 << std::setfill(
'0') << std::setw(2) << hour
425 << std::setfill(
'0') << std::setw(2) << minute
426 << std::setfill(
'0') << std::setw(2) << second;
428 std::string newoldname(path +
".old." + ss.str());
429 if (amrex::system::verbose) {
430 amrex::Print() <<
"Util::CreateCleanDirectory(): " << path
431 <<
" exists. Renaming to: " << newoldname << std::endl;
433 std::rename(path.c_str(), newoldname.c_str());
435 ret.second = newoldname;
437 if( ! amrex::UtilCreateDirectory(path, 0755)) {
438 amrex::CreateDirectoryFailed(path);
443 amrex::ParallelDescriptor::Barrier(
"amrex::UtilCreateCleanDirectory");
453 if (amrex::ParallelDescriptor::IOProcessor())
454 std::cout << std::left
460 if (amrex::ParallelDescriptor::IOProcessor())
463 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
464 std::stringstream ss;
470 int terminalwidth = 80;
472 std::cout << std::left
474 << std::setw(terminalwidth - testname.size() + ss.str().size() - 6) << std::right << std::setfill(
'.') << ss.str() << std::endl;
480 if (amrex::ParallelDescriptor::IOProcessor())
483 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
484 std::stringstream ss;
490 int terminalwidth = 80;
492 std::cout << std::left
495 << std::setw(terminalwidth - testname.size() + ss.str().size() - 12) << std::right << std::setfill(
'.') << ss.str() << std::endl;
501 if (amrex::ParallelDescriptor::IOProcessor())
504 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
505 std::stringstream ss;
508 int terminalwidth = 80;
510 std::cout << std::left
513 << std::setw(terminalwidth - testname.size() + ss.str().size() - 12) << std::right << std::setfill(
'.') << ss.str() << std::endl;
518 if (amrex::ParallelDescriptor::IOProcessor())
521 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
522 std::stringstream ss;
523 std::cout << std::left <<
" └ ";
535void AverageCellcenterToNode(amrex::MultiFab& node_mf,
const int &dcomp,
const amrex::MultiFab &cell_mf,
const int &scomp,
const int &ncomp)
542 for (amrex::MFIter mfi(node_mf,amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
544 amrex::Box bx = mfi.nodaltilebox();
545 amrex::Array4<Set::Scalar>
const& node = node_mf.array(mfi);
546 amrex::Array4<const Set::Scalar>
const& cell = cell_mf.array(mfi);
547 for (
int n = 0; n < ncomp; n++)
548 amrex::ParallelFor (bx,[=] AMREX_GPU_DEVICE(
int i,
int j,
int k) {
void forbid(std::string name, std::string explanation, const std::source_location &location=std::source_location::current())
static void SetTraversalMode(bool enabled)
int queryarr_required(std::string name, std::vector< T > &value, const std::source_location &location=std::source_location::current())
int queryarr(std::string name, std::vector< T > &value, const std::source_location &location=std::source_location::current())
static void SetTraversalOutputFile(std::string path)
int query_default(std::string name, T &value, T defaultvalue, const std::source_location &location=std::source_location::current())
static const std::string & TraversalOutputFile()
static void WriteInputTreeJsonFile(const std::string &path)
static bool InTraversalMode()
bool contains(std::string name, const std::source_location &location=std::source_location::current())
static std::string LightYellow
static std::string LightGreen
void WriteMetaData(std::string plot_file, Status status, int per)
void FileNameParse(std::string &filename)
Internal function to do processing of the file name.
void SetGlobalConstants()
Eigen::Matrix< amrex::Real, AMREX_SPACEDIM, 1 > Vector
int Message(std::string testname)
int SubMessage(std::string testname, int failed)
int SubFinalMessage(int failed)
void SubWarning(std::string testname)
A collection of utility routines.
std::pair< std::string, std::string > CreateCleanDirectory(const std::string &path, bool callbarrier)
void DebugMessage(std::string, std::string, int, Args const &...)
std::string GetFileName()
void AverageCellcenterToNode(amrex::MultiFab &node_mf, const int &dcomp, const amrex::MultiFab &cell_mf, const int &scomp, const int &ncomp)
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE void Assert(const char *file, const char *func, int line, const char *smt, bool pass, Args const &... args)
std::pair< std::string, std::string > file_overwrite
void CopyFileToOutputDir(std::string a_path, bool fullpath, std::string prefix)
std::pair< std::string, std::string > GetOverwrittenFile()
void Message(std::string file, std::string func, int line, Args const &... args)
AMREX_GPU_HOST_DEVICE void Abort(const char *msg)
void Exception(std::string file, std::string func, int line, Args const &... args)
void Terminate(const char *, int signal, bool)
void SignalHandler(int s)
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE T CellToNodeAverage(const amrex::Array4< const T > &f, const int &i, const int &j, const int &k, const int &m, std::array< StencilType, AMREX_SPACEDIM > stencil=DefaultType())
static void setTimeUnit(std::string unit)
static void setLuminousIntensityUnit(std::string unit)
static void setLengthUnit(std::string unit)
static void setMassUnit(std::string unit)
static void setTemperatureUnit(std::string unit)
static void setCurrentUnit(std::string unit)
static void setAmountUnit(std::string unit)