2#include "AMReX_Config.H"
3#include "AMReX_DistributionMapping.H"
4#include "AMReX_VisMF.H"
12#include "AMReX_ParallelDescriptor.H"
13#include "AMReX_Utility.H"
19#include "Numeric/Stencil.H"
40 Util::Abort(
"plot_file specified in too many locations");
41 else if (pp_amr.
contains(
"plot_file"))
43 if (amrex::ParallelDescriptor::IOProcessor())
44 amrex::Warning(
"amr.plot_file will be depricated; use plot_file instead");
64 Util::Exception(
INFO,
"Cannot back up files yet because the output directory has not been specified");
66 std::string basefilename = std::filesystem::path(a_path).filename();
67 std::string absolutepath = std::filesystem::absolute(std::filesystem::path(a_path)).string();
68 std::string abspathfilename = absolutepath;
69 std::replace(abspathfilename.begin(),abspathfilename.end(),
'/',
'_');
72 abspathfilename = prefix +
"__" + abspathfilename;
73 basefilename = prefix +
"__" + abspathfilename;
76 if (amrex::ParallelDescriptor::IOProcessor())
78 std::string destinationpath;
79 if (fullpath) destinationpath =
filename+
"/"+abspathfilename;
80 else destinationpath =
filename+
"/"+basefilename;
83 if (std::filesystem::exists(destinationpath))
85 std::filesystem::copy_file(a_path,destinationpath);
88 catch (std::filesystem::filesystem_error
const& ex)
91 "file system error: \n",
92 " what(): " , ex.what() ,
'\n',
93 " path1(): " , ex.path1() ,
'\n',
94 " path2(): " , ex.path2() ,
'\n',
95 " code().value(): " , ex.code().value() ,
'\n',
96 " code().message(): " , ex.code().message() ,
'\n',
97 " code().category(): " , ex.code().category().name());
108 if (amrex::ParallelDescriptor::IOProcessor())
123 time_t timer; time(&timer);
124 std::stringstream cmd;
125 cmd <<
"xdg-open " << BUILD_DIR <<
"/src/Util/Meme/cat0" << (1+((int)timer)%6) <<
".gif &";
126 std::system(cmd.str().c_str());
131 amrex::BLBackTrace::handler(s);
138 char **argv =
nullptr;
146 amrex::Initialize(argc, argv);
149 pp_amrex.add(
"throw_exception",1);
158 if (amrex::ParallelDescriptor::IOProcessor() &&
filename !=
"")
165 std::string length, time, mass, temperature, current, amount, luminousintensity;
179 pp.
query_default(
"system.luminousintensity",luminousintensity,
"cd");
193 catch (std::runtime_error &e)
210 std::vector<Set::Scalar> prob_lo, prob_hi;
215 pp.remove(
"prob_lo");
216 pp.remove(
"prob_hi");
219 "Invalid domain specified: ", prob_lo[0],
" < x < ", prob_hi[0],
" is incorrect.");
221 "Invalid domain specified: ", prob_lo[0],
" < y < ", prob_hi[0],
" is incorrect.");
224 "Invalid domain specified: ", prob_lo[0],
" < z < ", prob_hi[0],
" is incorrect.");
230 pp.addarr(
"prob_lo",prob_lo);
231 pp.addarr(
"prob_hi",prob_hi);
245 std::vector<std::string> ignore;
248 for (
unsigned int i = 0; i < ignore.size(); i++)
251 pp.remove(ignore[i].c_str());
276std::pair<std::string,std::string>
279 std::pair<std::string,std::string> ret(
"",
"");
281 if(amrex::ParallelDescriptor::IOProcessor()) {
282 if(amrex::FileExists(path)) {
283 std::time_t
t = std::time(0);
284 std::tm * now = std::localtime(&
t);
285 int year = now->tm_year+1900;
286 int month = now->tm_mon+1;
287 int day = now->tm_mday;
288 int hour = now->tm_hour;
289 int minute = now->tm_min;
290 int second = now->tm_sec;
292 std::stringstream ss;
294 << std::setfill(
'0') << std::setw(2) << month
295 << std::setfill(
'0') << std::setw(2) << day
296 << std::setfill(
'0') << std::setw(2) << hour
297 << std::setfill(
'0') << std::setw(2) << minute
298 << std::setfill(
'0') << std::setw(2) << second;
300 std::string newoldname(path +
".old." + ss.str());
301 if (amrex::system::verbose) {
302 amrex::Print() <<
"Util::CreateCleanDirectory(): " << path
303 <<
" exists. Renaming to: " << newoldname << std::endl;
305 std::rename(path.c_str(), newoldname.c_str());
307 ret.second = newoldname;
309 if( ! amrex::UtilCreateDirectory(path, 0755)) {
310 amrex::CreateDirectoryFailed(path);
315 amrex::ParallelDescriptor::Barrier(
"amrex::UtilCreateCleanDirectory");
325 if (amrex::ParallelDescriptor::IOProcessor())
326 std::cout << std::left
332 if (amrex::ParallelDescriptor::IOProcessor())
335 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
336 std::stringstream ss;
342 int terminalwidth = 80;
344 std::cout << std::left
346 << std::setw(terminalwidth - testname.size() + ss.str().size() - 6) << std::right << std::setfill(
'.') << ss.str() << std::endl;
352 if (amrex::ParallelDescriptor::IOProcessor())
355 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
356 std::stringstream ss;
362 int terminalwidth = 80;
364 std::cout << std::left
367 << std::setw(terminalwidth - testname.size() + ss.str().size() - 12) << std::right << std::setfill(
'.') << ss.str() << std::endl;
373 if (amrex::ParallelDescriptor::IOProcessor())
376 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
377 std::stringstream ss;
380 int terminalwidth = 80;
382 std::cout << std::left
385 << std::setw(terminalwidth - testname.size() + ss.str().size() - 12) << std::right << std::setfill(
'.') << ss.str() << std::endl;
390 if (amrex::ParallelDescriptor::IOProcessor())
393 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
394 std::stringstream ss;
395 std::cout << std::left <<
" └ ";
407void AverageCellcenterToNode(amrex::MultiFab& node_mf,
const int &dcomp,
const amrex::MultiFab &cell_mf,
const int &scomp,
const int &ncomp)
414 for (amrex::MFIter mfi(node_mf,amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
416 amrex::Box bx = mfi.nodaltilebox();
417 amrex::Array4<Set::Scalar>
const& node = node_mf.array(mfi);
418 amrex::Array4<const Set::Scalar>
const& cell = cell_mf.array(mfi);
419 for (
int n = 0; n < ncomp; n++)
420 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 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 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 Message(std::string file, std::string func, int line, Args const &... args)
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)