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");
185 catch (std::runtime_error &e)
202 std::vector<Set::Scalar> prob_lo, prob_hi;
207 pp.remove(
"prob_lo");
208 pp.remove(
"prob_hi");
211 "Invalid domain specified: ", prob_lo[0],
" < x < ", prob_hi[0],
" is incorrect.");
213 "Invalid domain specified: ", prob_lo[0],
" < y < ", prob_hi[0],
" is incorrect.");
216 "Invalid domain specified: ", prob_lo[0],
" < z < ", prob_hi[0],
" is incorrect.");
222 pp.addarr(
"prob_lo",prob_lo);
223 pp.addarr(
"prob_hi",prob_hi);
248std::pair<std::string,std::string>
251 std::pair<std::string,std::string> ret(
"",
"");
253 if(amrex::ParallelDescriptor::IOProcessor()) {
254 if(amrex::FileExists(path)) {
255 std::time_t
t = std::time(0);
256 std::tm * now = std::localtime(&
t);
257 int year = now->tm_year+1900;
258 int month = now->tm_mon+1;
259 int day = now->tm_mday;
260 int hour = now->tm_hour;
261 int minute = now->tm_min;
262 int second = now->tm_sec;
264 std::stringstream ss;
266 << std::setfill(
'0') << std::setw(2) << month
267 << std::setfill(
'0') << std::setw(2) << day
268 << std::setfill(
'0') << std::setw(2) << hour
269 << std::setfill(
'0') << std::setw(2) << minute
270 << std::setfill(
'0') << std::setw(2) << second;
272 std::string newoldname(path +
".old." + ss.str());
273 if (amrex::system::verbose) {
274 amrex::Print() <<
"Util::CreateCleanDirectory(): " << path
275 <<
" exists. Renaming to: " << newoldname << std::endl;
277 std::rename(path.c_str(), newoldname.c_str());
279 ret.second = newoldname;
281 if( ! amrex::UtilCreateDirectory(path, 0755)) {
282 amrex::CreateDirectoryFailed(path);
287 amrex::ParallelDescriptor::Barrier(
"amrex::UtilCreateCleanDirectory");
297 if (amrex::ParallelDescriptor::IOProcessor())
298 std::cout << std::left
304 if (amrex::ParallelDescriptor::IOProcessor())
307 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
308 std::stringstream ss;
314 int terminalwidth = 80;
316 std::cout << std::left
318 << std::setw(terminalwidth - testname.size() + ss.str().size() - 6) << std::right << std::setfill(
'.') << ss.str() << std::endl;
324 if (amrex::ParallelDescriptor::IOProcessor())
327 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
328 std::stringstream ss;
334 int terminalwidth = 80;
336 std::cout << std::left
339 << std::setw(terminalwidth - testname.size() + ss.str().size() - 12) << std::right << std::setfill(
'.') << ss.str() << std::endl;
345 if (amrex::ParallelDescriptor::IOProcessor())
348 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
349 std::stringstream ss;
350 std::cout << std::left <<
" └ ";
362void AverageCellcenterToNode(amrex::MultiFab& node_mf,
const int &dcomp,
const amrex::MultiFab &cell_mf,
const int &scomp,
const int &ncomp)
369 for (amrex::MFIter mfi(node_mf,amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
371 amrex::Box bx = mfi.nodaltilebox();
372 amrex::Array4<Set::Scalar>
const& node = node_mf.array(mfi);
373 amrex::Array4<const Set::Scalar>
const& cell = cell_mf.array(mfi);
374 for (
int n = 0; n < ncomp; n++)
375 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.
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)