9#include "AMReX_ParallelDescriptor.H"
10#include "AMReX_Utility.H"
16#include "Numeric/Stencil.H"
35 Util::Abort(
"plot_file specified in too many locations");
36 else if (pp_amr.
contains(
"plot_file"))
38 if (amrex::ParallelDescriptor::IOProcessor())
39 amrex::Warning(
"amr.plot_file will be depricated; use plot_file instead");
59 Util::Exception(
INFO,
"Cannot back up files yet because the output directory has not been specified");
61 std::string basefilename = std::filesystem::path(a_path).filename();
62 std::string absolutepath = std::filesystem::absolute(std::filesystem::path(a_path)).string();
63 std::string abspathfilename = absolutepath;
64 std::replace(abspathfilename.begin(),abspathfilename.end(),
'/',
'_');
67 abspathfilename = prefix +
"__" + abspathfilename;
68 basefilename = prefix +
"__" + abspathfilename;
71 if (amrex::ParallelDescriptor::IOProcessor())
73 std::string destinationpath;
74 if (fullpath) destinationpath =
filename+
"/"+abspathfilename;
75 else destinationpath =
filename+
"/"+basefilename;
78 if (std::filesystem::exists(destinationpath))
80 std::filesystem::copy_file(a_path,destinationpath);
83 catch (std::filesystem::filesystem_error
const& ex)
86 "file system error: \n",
87 " what(): " , ex.what() ,
'\n',
88 " path1(): " , ex.path1() ,
'\n',
89 " path2(): " , ex.path2() ,
'\n',
90 " code().value(): " , ex.code().value() ,
'\n',
91 " code().message(): " , ex.code().message() ,
'\n',
92 " code().category(): " , ex.code().category().name());
103 if (amrex::ParallelDescriptor::IOProcessor())
118 time_t timer; time(&timer);
119 std::stringstream cmd;
120 cmd <<
"xdg-open " << BUILD_DIR <<
"/src/Util/Meme/cat0" << (1+((int)timer)%6) <<
".gif &";
121 std::system(cmd.str().c_str());
126 amrex::BLBackTrace::handler(s);
133 char **argv =
nullptr;
141 amrex::Initialize(argc, argv);
144 pp_amrex.add(
"throw_exception",1);
153 if (amrex::ParallelDescriptor::IOProcessor() &&
filename !=
"")
160 std::string length, time, mass, temperature, current, amount, luminousintensity;
174 pp.
query_default(
"system.luminousintensity",luminousintensity,
"cd");
188 catch (std::runtime_error &e)
205 std::vector<Set::Scalar> prob_lo, prob_hi;
210 pp.remove(
"prob_lo");
211 pp.remove(
"prob_hi");
214 "Invalid domain specified: ", prob_lo[0],
" < x < ", prob_hi[0],
" is incorrect.");
216 "Invalid domain specified: ", prob_lo[0],
" < y < ", prob_hi[0],
" is incorrect.");
219 "Invalid domain specified: ", prob_lo[0],
" < z < ", prob_hi[0],
" is incorrect.");
225 pp.addarr(
"prob_lo",prob_lo);
226 pp.addarr(
"prob_hi",prob_hi);
251std::pair<std::string,std::string>
254 std::pair<std::string,std::string> ret(
"",
"");
256 if(amrex::ParallelDescriptor::IOProcessor()) {
257 if(amrex::FileExists(path)) {
258 std::time_t
t = std::time(0);
259 std::tm * now = std::localtime(&
t);
260 int year = now->tm_year+1900;
261 int month = now->tm_mon+1;
262 int day = now->tm_mday;
263 int hour = now->tm_hour;
264 int minute = now->tm_min;
265 int second = now->tm_sec;
267 std::stringstream ss;
269 << std::setfill(
'0') << std::setw(2) << month
270 << std::setfill(
'0') << std::setw(2) << day
271 << std::setfill(
'0') << std::setw(2) << hour
272 << std::setfill(
'0') << std::setw(2) << minute
273 << std::setfill(
'0') << std::setw(2) << second;
275 std::string newoldname(path +
".old." + ss.str());
276 if (amrex::system::verbose) {
277 amrex::Print() <<
"Util::CreateCleanDirectory(): " << path
278 <<
" exists. Renaming to: " << newoldname << std::endl;
280 std::rename(path.c_str(), newoldname.c_str());
282 ret.second = newoldname;
284 if( ! amrex::UtilCreateDirectory(path, 0755)) {
285 amrex::CreateDirectoryFailed(path);
290 amrex::ParallelDescriptor::Barrier(
"amrex::UtilCreateCleanDirectory");
300 if (amrex::ParallelDescriptor::IOProcessor())
301 std::cout << std::left
307 if (amrex::ParallelDescriptor::IOProcessor())
310 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
311 std::stringstream ss;
317 int terminalwidth = 80;
319 std::cout << std::left
321 << std::setw(terminalwidth - testname.size() + ss.str().size() - 6) << std::right << std::setfill(
'.') << ss.str() << std::endl;
327 if (amrex::ParallelDescriptor::IOProcessor())
330 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
331 std::stringstream ss;
337 int terminalwidth = 80;
339 std::cout << std::left
342 << std::setw(terminalwidth - testname.size() + ss.str().size() - 12) << std::right << std::setfill(
'.') << ss.str() << std::endl;
348 if (amrex::ParallelDescriptor::IOProcessor())
351 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
352 std::stringstream ss;
353 std::cout << std::left <<
" └ ";
365void AverageCellcenterToNode(amrex::MultiFab& node_mf,
const int &dcomp,
const amrex::MultiFab &cell_mf,
const int &scomp,
const int &ncomp)
372 for (amrex::MFIter mfi(node_mf,amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
374 amrex::Box bx = mfi.nodaltilebox();
375 amrex::Array4<Set::Scalar>
const& node = node_mf.array(mfi);
376 amrex::Array4<const Set::Scalar>
const& cell = cell_mf.array(mfi);
377 for (
int n = 0; n < ncomp; n++)
378 amrex::ParallelFor (bx,[=] AMREX_GPU_DEVICE(
int i,
int j,
int k) {
bool contains(std::string name)
int queryarr(std::string name, std::vector< T > &value)
int query_default(std::string name, T &value, T defaultvalue)
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)
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 Abort(const char *msg)
void AverageCellcenterToNode(amrex::MultiFab &node_mf, const int &dcomp, const amrex::MultiFab &cell_mf, const int &scomp, const int &ncomp)
AMREX_FORCE_INLINE void Assert(std::string file, std::string func, int line, std::string 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 Exception(std::string file, std::string func, int line, Args const &... args)
void Terminate(const char *, int signal, bool)
void SignalHandler(int s)
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)