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;
170 catch (std::runtime_error &e)
187 std::vector<Set::Scalar> prob_lo, prob_hi;
192 pp.remove(
"prob_lo");
193 pp.remove(
"prob_hi");
196 "Invalid domain specified: ", prob_lo[0],
" < x < ", prob_hi[0],
" is incorrect.");
198 "Invalid domain specified: ", prob_lo[0],
" < y < ", prob_hi[0],
" is incorrect.");
201 "Invalid domain specified: ", prob_lo[0],
" < z < ", prob_hi[0],
" is incorrect.");
207 pp.addarr(
"prob_lo",prob_lo);
208 pp.addarr(
"prob_hi",prob_hi);
233std::pair<std::string,std::string>
236 std::pair<std::string,std::string> ret(
"",
"");
238 if(amrex::ParallelDescriptor::IOProcessor()) {
239 if(amrex::FileExists(path)) {
240 std::time_t
t = std::time(0);
241 std::tm * now = std::localtime(&
t);
242 int year = now->tm_year+1900;
243 int month = now->tm_mon+1;
244 int day = now->tm_mday;
245 int hour = now->tm_hour;
246 int minute = now->tm_min;
247 int second = now->tm_sec;
249 std::stringstream ss;
251 << std::setfill(
'0') << std::setw(2) << month
252 << std::setfill(
'0') << std::setw(2) << day
253 << std::setfill(
'0') << std::setw(2) << hour
254 << std::setfill(
'0') << std::setw(2) << minute
255 << std::setfill(
'0') << std::setw(2) << second;
257 std::string newoldname(path +
".old." + ss.str());
258 if (amrex::system::verbose) {
259 amrex::Print() <<
"Util::CreateCleanDirectory(): " << path
260 <<
" exists. Renaming to: " << newoldname << std::endl;
262 std::rename(path.c_str(), newoldname.c_str());
264 ret.second = newoldname;
266 if( ! amrex::UtilCreateDirectory(path, 0755)) {
267 amrex::CreateDirectoryFailed(path);
272 amrex::ParallelDescriptor::Barrier(
"amrex::UtilCreateCleanDirectory");
282 if (amrex::ParallelDescriptor::IOProcessor())
283 std::cout << std::left
289 if (amrex::ParallelDescriptor::IOProcessor())
292 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
293 std::stringstream ss;
299 int terminalwidth = 80;
301 std::cout << std::left
303 << std::setw(terminalwidth - testname.size() + ss.str().size() - 6) << std::right << std::setfill(
'.') << ss.str() << std::endl;
309 if (amrex::ParallelDescriptor::IOProcessor())
312 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
313 std::stringstream ss;
319 int terminalwidth = 80;
321 std::cout << std::left
324 << std::setw(terminalwidth - testname.size() + ss.str().size() - 12) << std::right << std::setfill(
'.') << ss.str() << std::endl;
330 if (amrex::ParallelDescriptor::IOProcessor())
333 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
334 std::stringstream ss;
335 std::cout << std::left <<
" └ ";
347void AverageCellcenterToNode(amrex::MultiFab& node_mf,
const int &dcomp,
const amrex::MultiFab &cell_mf,
const int &scomp,
const int &ncomp)
354 for (amrex::MFIter mfi(node_mf,amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
356 amrex::Box bx = mfi.nodaltilebox();
357 amrex::Array4<Set::Scalar>
const& node = node_mf.array(mfi);
358 amrex::Array4<const Set::Scalar>
const& cell = cell_mf.array(mfi);
359 for (
int n = 0; n < ncomp; n++)
360 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 setLengthUnit(std::string unit)