8#include "AMReX_ParallelDescriptor.H"
9#include "AMReX_Utility.H"
15#include "Numeric/Stencil.H"
34 Util::Abort(
"plot_file specified in too many locations");
35 else if (pp_amr.
contains(
"plot_file"))
37 if (amrex::ParallelDescriptor::IOProcessor())
38 amrex::Warning(
"amr.plot_file will be depricated; use plot_file instead");
58 Util::Exception(
INFO,
"Cannot back up files yet because the output directory has not been specified");
60 std::string basefilename = std::filesystem::path(a_path).filename();
61 std::string absolutepath = std::filesystem::absolute(std::filesystem::path(a_path)).string();
62 std::string abspathfilename = absolutepath;
63 std::replace(abspathfilename.begin(),abspathfilename.end(),
'/',
'_');
66 abspathfilename = prefix +
"__" + abspathfilename;
67 basefilename = prefix +
"__" + abspathfilename;
70 if (amrex::ParallelDescriptor::IOProcessor())
72 std::string destinationpath;
73 if (fullpath) destinationpath =
filename+
"/"+abspathfilename;
74 else destinationpath =
filename+
"/"+basefilename;
77 if (std::filesystem::exists(destinationpath))
79 std::filesystem::copy_file(a_path,destinationpath);
82 catch (std::filesystem::filesystem_error
const& ex)
85 "file system error: \n",
86 " what(): " , ex.what() ,
'\n',
87 " path1(): " , ex.path1() ,
'\n',
88 " path2(): " , ex.path2() ,
'\n',
89 " code().value(): " , ex.code().value() ,
'\n',
90 " code().message(): " , ex.code().message() ,
'\n',
91 " code().category(): " , ex.code().category().name());
102 if (amrex::ParallelDescriptor::IOProcessor())
117 time_t timer; time(&timer);
118 std::stringstream cmd;
119 cmd <<
"xdg-open " << BUILD_DIR <<
"/src/Util/Meme/cat0" << (1+((int)timer)%6) <<
".gif &";
120 std::system(cmd.str().c_str());
125 amrex::BLBackTrace::handler(s);
132 char **argv =
nullptr;
140 amrex::Initialize(argc, argv);
143 pp_amrex.add(
"throw_exception",1);
152 if (amrex::ParallelDescriptor::IOProcessor() &&
filename !=
"")
179std::pair<std::string,std::string>
182 std::pair<std::string,std::string> ret(
"",
"");
184 if(amrex::ParallelDescriptor::IOProcessor()) {
185 if(amrex::FileExists(path)) {
186 std::time_t
t = std::time(0);
187 std::tm * now = std::localtime(&
t);
188 int year = now->tm_year+1900;
189 int month = now->tm_mon+1;
190 int day = now->tm_mday;
191 int hour = now->tm_hour;
192 int minute = now->tm_min;
193 int second = now->tm_sec;
195 std::stringstream ss;
197 << std::setfill(
'0') << std::setw(2) << month
198 << std::setfill(
'0') << std::setw(2) << day
199 << std::setfill(
'0') << std::setw(2) << hour
200 << std::setfill(
'0') << std::setw(2) << minute
201 << std::setfill(
'0') << std::setw(2) << second;
203 std::string newoldname(path +
".old." + ss.str());
204 if (amrex::system::verbose) {
205 amrex::Print() <<
"Util::CreateCleanDirectory(): " << path
206 <<
" exists. Renaming to: " << newoldname << std::endl;
208 std::rename(path.c_str(), newoldname.c_str());
210 ret.second = newoldname;
212 if( ! amrex::UtilCreateDirectory(path, 0755)) {
213 amrex::CreateDirectoryFailed(path);
218 amrex::ParallelDescriptor::Barrier(
"amrex::UtilCreateCleanDirectory");
228 if (amrex::ParallelDescriptor::IOProcessor())
229 std::cout << std::left
235 if (amrex::ParallelDescriptor::IOProcessor())
238 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
239 std::stringstream ss;
245 int terminalwidth = 80;
247 std::cout << std::left
249 << std::setw(terminalwidth - testname.size() + ss.str().size() - 6) << std::right << std::setfill(
'.') << ss.str() << std::endl;
255 if (amrex::ParallelDescriptor::IOProcessor())
258 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
259 std::stringstream ss;
265 int terminalwidth = 80;
267 std::cout << std::left
270 << std::setw(terminalwidth - testname.size() + ss.str().size() - 12) << std::right << std::setfill(
'.') << ss.str() << std::endl;
276 if (amrex::ParallelDescriptor::IOProcessor())
279 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
280 std::stringstream ss;
281 std::cout << std::left <<
" └ ";
293void AverageCellcenterToNode(amrex::MultiFab& node_mf,
const int &dcomp,
const amrex::MultiFab &cell_mf,
const int &scomp,
const int &ncomp)
300 for (amrex::MFIter mfi(node_mf,amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
302 amrex::Box bx = mfi.nodaltilebox();
303 amrex::Array4<Set::Scalar>
const& node = node_mf.array(mfi);
304 amrex::Array4<const Set::Scalar>
const& cell = cell_mf.array(mfi);
305 for (
int n = 0; n < ncomp; n++)
306 amrex::ParallelFor (bx,[=] AMREX_GPU_DEVICE(
int i,
int j,
int k) {
bool contains(std::string name)
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.
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)
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)