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"
23#include "Numeric/Stencil.H"
30ParseArgsError(
const std::string &message)
32 std::cerr <<
"ERROR: " << message << std::endl;
33 std::exit(EXIT_FAILURE);
37IsInputDefinition(
const std::string &arg)
39 return arg ==
"input" || arg.rfind(
"input=", 0) == 0;
43RejectParseArgsInputFiles(
const std::vector<char*> &argv)
45 for (std::size_t i = 1; i < argv.size(); ++i)
47 const std::string arg(argv[i]);
49 if (arg ==
"--")
break;
51 if (IsInputDefinition(arg))
53 ParseArgsError(
"--parse-args does not accept input-file directives: " + arg);
56 if (arg ==
"=")
continue;
57 if (!arg.empty() && arg[0] ==
'-')
continue;
58 if (arg.find(
'=') != std::string::npos)
continue;
59 if (i + 1 < argv.size() && std::string(argv[i + 1]) ==
"=")
continue;
60 if (i > 1 && std::string(argv[i - 1]) ==
"=")
continue;
62 ParseArgsError(
"--parse-args does not accept input files or positional arguments: " + arg);
67InjectParseArgsDefaults()
70 amrex::ParmParse pp(
"amr");
73 pp.queryAdd(
"max_level", max_level);
75 std::vector<int> n_cell(AMREX_SPACEDIM, 1);
76 pp.queryAdd(
"n_cell", n_cell);
78 int max_grid_size = 1;
79 pp.queryAdd(
"max_grid_size", max_grid_size);
81 int blocking_factor = 1;
82 pp.queryAdd(
"blocking_factor", blocking_factor);
86 amrex::ParmParse pp(
"geometry");
88 std::vector<double> prob_lo(AMREX_SPACEDIM, 0.0);
89 pp.queryAdd(
"prob_lo", prob_lo, AMREX_SPACEDIM);
91 if (!pp.contains(
"prob_hi") && !pp.contains(
"prob_extent"))
93 std::vector<double> prob_hi(AMREX_SPACEDIM, 1.0);
94 pp.addarr(
"prob_hi", prob_hi);
97 std::vector<int> is_periodic(AMREX_SPACEDIM, 0);
98 pp.queryAdd(
"is_periodic", is_periodic, AMREX_SPACEDIM);
104 std::string stop_time =
"1.0";
105 pp.queryAdd(
"stop_time", stop_time);
107 std::string timestep =
"1.0";
108 pp.queryAdd(
"timestep", timestep);
128 pp.
forbid(
"amr.plot_file",
"Depricated");
147 Util::Exception(
INFO,
"Cannot back up files yet because the output directory has not been specified");
149 std::string basefilename = std::filesystem::path(a_path).filename();
150 std::string absolutepath = std::filesystem::absolute(std::filesystem::path(a_path)).string();
151 std::string abspathfilename = absolutepath;
152 std::replace(abspathfilename.begin(),abspathfilename.end(),
'/',
'_');
155 abspathfilename = prefix +
"__" + abspathfilename;
156 basefilename = prefix +
"__" + abspathfilename;
159 if (amrex::ParallelDescriptor::IOProcessor())
161 std::string destinationpath;
162 if (fullpath) destinationpath =
filename+
"/"+abspathfilename;
163 else destinationpath =
filename+
"/"+basefilename;
166 if (std::filesystem::exists(destinationpath))
168 std::filesystem::copy_file(a_path,destinationpath);
171 catch (std::filesystem::filesystem_error
const& ex)
174 "file system error: \n",
175 " what(): " , ex.what() ,
'\n',
176 " path1(): " , ex.path1() ,
'\n',
177 " path2(): " , ex.path2() ,
'\n',
178 " code().value(): " , ex.code().value() ,
'\n',
179 " code().message(): " , ex.code().message() ,
'\n',
180 " code().category(): " , ex.code().category().name());
192 amrex::ParallelDescriptor::IOProcessor())
207 time_t timer; time(&timer);
208 std::stringstream cmd;
209 cmd <<
"xdg-open " << BUILD_DIR <<
"/src/Util/Meme/cat0" << (1+((int)timer)%6) <<
".gif &";
210 std::system(cmd.str().c_str());
215 amrex::BLBackTrace::handler(s);
222 char **argv =
nullptr;
231 bool parse_args =
false;
232 std::string parse_args_output =
"alamo-inputs.schema.json";
233 std::vector<char*> amrex_argv;
234 amrex_argv.reserve(argc > 0 ? argc : 0);
235 for (
int i = 0; i < argc; i++)
237 if (std::string(argv[i]) ==
"--parse-args")
242 if (std::string(argv[i]) ==
"--parse-args-output")
245 ParseArgsError(
"--parse-args-output requires a file path");
246 parse_args_output = argv[++i];
249 amrex_argv.push_back(argv[i]);
252 if (parse_args) RejectParseArgsInputFiles(amrex_argv);
254 int amrex_argc =
static_cast<int>(amrex_argv.size());
255 amrex_argv.push_back(
nullptr);
256 char **amrex_argv_ptr = amrex_argc == 0 ? nullptr : amrex_argv.data();
262 amrex::Initialize(amrex_argc, amrex_argv_ptr);
264 if (parse_args) InjectParseArgsDefaults();
267 pp.add(
"amrex.throw_exception",1);
278 if (amrex::ParallelDescriptor::IOProcessor())
294 std::string length, time, mass, temperature, current, amount, luminousintensity;
308 pp.
query_default(
"system.luminousintensity",luminousintensity,
"cd");
322 catch (std::runtime_error &e)
339 std::vector<Set::Scalar> prob_lo, prob_hi;
344 pp.remove(
"prob_lo");
345 pp.remove(
"prob_hi");
348 "Invalid domain specified: ", prob_lo[0],
" < x < ", prob_hi[0],
" is incorrect.");
350 "Invalid domain specified: ", prob_lo[0],
" < y < ", prob_hi[0],
" is incorrect.");
353 "Invalid domain specified: ", prob_lo[0],
" < z < ", prob_hi[0],
" is incorrect.");
359 pp.addarr(
"prob_lo",prob_lo);
360 pp.addarr(
"prob_hi",prob_hi);
374 std::vector<std::string> ignore;
377 for (
unsigned int i = 0; i < ignore.size(); i++)
380 pp.remove(ignore[i].c_str());
408 AMREX_IF_ON_HOST((
Terminate(msg, SIGABRT,
true);))
409 AMREX_IF_ON_DEVICE((amrex::Abort();))
418std::pair<std::string,std::string>
421 std::pair<std::string,std::string> ret(
"",
"");
423 if(amrex::ParallelDescriptor::IOProcessor()) {
424 if(amrex::FileExists(path)) {
425 std::time_t
t = std::time(0);
426 std::tm * now = std::localtime(&
t);
427 int year = now->tm_year+1900;
428 int month = now->tm_mon+1;
429 int day = now->tm_mday;
430 int hour = now->tm_hour;
431 int minute = now->tm_min;
432 int second = now->tm_sec;
434 std::stringstream ss;
436 << std::setfill(
'0') << std::setw(2) << month
437 << std::setfill(
'0') << std::setw(2) << day
438 << std::setfill(
'0') << std::setw(2) << hour
439 << std::setfill(
'0') << std::setw(2) << minute
440 << std::setfill(
'0') << std::setw(2) << second;
442 std::string newoldname(path +
".old." + ss.str());
443 if (amrex::system::verbose) {
444 amrex::Print() <<
"Util::CreateCleanDirectory(): " << path
445 <<
" exists. Renaming to: " << newoldname << std::endl;
447 std::rename(path.c_str(), newoldname.c_str());
449 ret.second = newoldname;
451 if( ! amrex::UtilCreateDirectory(path, 0755)) {
452 amrex::CreateDirectoryFailed(path);
457 amrex::ParallelDescriptor::Barrier(
"amrex::UtilCreateCleanDirectory");
467 if (amrex::ParallelDescriptor::IOProcessor())
468 std::cout << std::left
474 if (amrex::ParallelDescriptor::IOProcessor())
477 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
478 std::stringstream ss;
484 int terminalwidth = 80;
486 std::cout << std::left
488 << std::setw(terminalwidth - testname.size() + ss.str().size() - 6) << std::right << std::setfill(
'.') << ss.str() << std::endl;
494 if (amrex::ParallelDescriptor::IOProcessor())
497 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
498 std::stringstream ss;
504 int terminalwidth = 80;
506 std::cout << std::left
509 << std::setw(terminalwidth - testname.size() + ss.str().size() - 12) << std::right << std::setfill(
'.') << ss.str() << std::endl;
515 if (amrex::ParallelDescriptor::IOProcessor())
518 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
519 std::stringstream ss;
522 int terminalwidth = 80;
524 std::cout << std::left
527 << std::setw(terminalwidth - testname.size() + ss.str().size() - 12) << std::right << std::setfill(
'.') << ss.str() << std::endl;
532 if (amrex::ParallelDescriptor::IOProcessor())
535 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
536 std::stringstream ss;
537 std::cout << std::left <<
" └ ";
549void AverageCellcenterToNode(amrex::MultiFab& node_mf,
const int &dcomp,
const amrex::MultiFab &cell_mf,
const int &scomp,
const int &ncomp)
556 for (amrex::MFIter mfi(node_mf,amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
558 amrex::Box bx = mfi.nodaltilebox();
559 amrex::Array4<Set::Scalar>
const& node = node_mf.array(mfi);
560 amrex::Array4<const Set::Scalar>
const& cell = cell_mf.array(mfi);
561 for (
int n = 0; n < ncomp; n++)
562 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 Initialize()
Route stdout and stderr through the terminal/file tee.
void Finalize()
Flush the log and restore the original terminal stream buffers.
void DisableFile()
Stop retaining output on ranks that do not own the log file.
void Open(const std::string &path)
Open the rank-zero log after the output directory has been created.
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)