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"
39 Util::Abort(
"plot_file specified in too many locations");
40 else if (pp.
contains(
"amr.plot_file"))
42 if (amrex::ParallelDescriptor::IOProcessor())
43 amrex::Warning(
"amr.plot_file will be depricated; use plot_file instead");
66 Util::Exception(
INFO,
"Cannot back up files yet because the output directory has not been specified");
68 std::string basefilename = std::filesystem::path(a_path).filename();
69 std::string absolutepath = std::filesystem::absolute(std::filesystem::path(a_path)).string();
70 std::string abspathfilename = absolutepath;
71 std::replace(abspathfilename.begin(),abspathfilename.end(),
'/',
'_');
74 abspathfilename = prefix +
"__" + abspathfilename;
75 basefilename = prefix +
"__" + abspathfilename;
78 if (amrex::ParallelDescriptor::IOProcessor())
80 std::string destinationpath;
81 if (fullpath) destinationpath =
filename+
"/"+abspathfilename;
82 else destinationpath =
filename+
"/"+basefilename;
85 if (std::filesystem::exists(destinationpath))
87 std::filesystem::copy_file(a_path,destinationpath);
90 catch (std::filesystem::filesystem_error
const& ex)
93 "file system error: \n",
94 " what(): " , ex.what() ,
'\n',
95 " path1(): " , ex.path1() ,
'\n',
96 " path2(): " , ex.path2() ,
'\n',
97 " code().value(): " , ex.code().value() ,
'\n',
98 " code().message(): " , ex.code().message() ,
'\n',
99 " code().category(): " , ex.code().category().name());
110 if (amrex::ParallelDescriptor::IOProcessor())
125 time_t timer; time(&timer);
126 std::stringstream cmd;
127 cmd <<
"xdg-open " << BUILD_DIR <<
"/src/Util/Meme/cat0" << (1+((int)timer)%6) <<
".gif &";
128 std::system(cmd.str().c_str());
133 amrex::BLBackTrace::handler(s);
140 char **argv =
nullptr;
148 amrex::Initialize(argc, argv);
151 pp.add(
"amrex.throw_exception",1);
160 if (amrex::ParallelDescriptor::IOProcessor() &&
filename !=
"")
166 std::string length, time, mass, temperature, current, amount, luminousintensity;
180 pp.
query_default(
"system.luminousintensity",luminousintensity,
"cd");
194 catch (std::runtime_error &e)
211 std::vector<Set::Scalar> prob_lo, prob_hi;
216 pp.remove(
"prob_lo");
217 pp.remove(
"prob_hi");
220 "Invalid domain specified: ", prob_lo[0],
" < x < ", prob_hi[0],
" is incorrect.");
222 "Invalid domain specified: ", prob_lo[0],
" < y < ", prob_hi[0],
" is incorrect.");
225 "Invalid domain specified: ", prob_lo[0],
" < z < ", prob_hi[0],
" is incorrect.");
231 pp.addarr(
"prob_lo",prob_lo);
232 pp.addarr(
"prob_hi",prob_hi);
246 std::vector<std::string> ignore;
249 for (
unsigned int i = 0; i < ignore.size(); i++)
252 pp.remove(ignore[i].c_str());
277std::pair<std::string,std::string>
280 std::pair<std::string,std::string> ret(
"",
"");
282 if(amrex::ParallelDescriptor::IOProcessor()) {
283 if(amrex::FileExists(path)) {
284 std::time_t
t = std::time(0);
285 std::tm * now = std::localtime(&
t);
286 int year = now->tm_year+1900;
287 int month = now->tm_mon+1;
288 int day = now->tm_mday;
289 int hour = now->tm_hour;
290 int minute = now->tm_min;
291 int second = now->tm_sec;
293 std::stringstream ss;
295 << std::setfill(
'0') << std::setw(2) << month
296 << std::setfill(
'0') << std::setw(2) << day
297 << std::setfill(
'0') << std::setw(2) << hour
298 << std::setfill(
'0') << std::setw(2) << minute
299 << std::setfill(
'0') << std::setw(2) << second;
301 std::string newoldname(path +
".old." + ss.str());
302 if (amrex::system::verbose) {
303 amrex::Print() <<
"Util::CreateCleanDirectory(): " << path
304 <<
" exists. Renaming to: " << newoldname << std::endl;
306 std::rename(path.c_str(), newoldname.c_str());
308 ret.second = newoldname;
310 if( ! amrex::UtilCreateDirectory(path, 0755)) {
311 amrex::CreateDirectoryFailed(path);
316 amrex::ParallelDescriptor::Barrier(
"amrex::UtilCreateCleanDirectory");
326 if (amrex::ParallelDescriptor::IOProcessor())
327 std::cout << std::left
333 if (amrex::ParallelDescriptor::IOProcessor())
336 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
337 std::stringstream ss;
343 int terminalwidth = 80;
345 std::cout << std::left
347 << std::setw(terminalwidth - testname.size() + ss.str().size() - 6) << std::right << std::setfill(
'.') << ss.str() << std::endl;
353 if (amrex::ParallelDescriptor::IOProcessor())
356 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
357 std::stringstream ss;
363 int terminalwidth = 80;
365 std::cout << std::left
368 << std::setw(terminalwidth - testname.size() + ss.str().size() - 12) << std::right << std::setfill(
'.') << ss.str() << std::endl;
374 if (amrex::ParallelDescriptor::IOProcessor())
377 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
378 std::stringstream ss;
381 int terminalwidth = 80;
383 std::cout << std::left
386 << std::setw(terminalwidth - testname.size() + ss.str().size() - 12) << std::right << std::setfill(
'.') << ss.str() << std::endl;
391 if (amrex::ParallelDescriptor::IOProcessor())
394 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
395 std::stringstream ss;
396 std::cout << std::left <<
" └ ";
408void AverageCellcenterToNode(amrex::MultiFab& node_mf,
const int &dcomp,
const amrex::MultiFab &cell_mf,
const int &scomp,
const int &ncomp)
415 for (amrex::MFIter mfi(node_mf,amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
417 amrex::Box bx = mfi.nodaltilebox();
418 amrex::Array4<Set::Scalar>
const& node = node_mf.array(mfi);
419 amrex::Array4<const Set::Scalar>
const& cell = cell_mf.array(mfi);
420 for (
int n = 0; n < ncomp; n++)
421 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)