7#include "AMReX_ParallelDescriptor.H"
8#include "AMReX_Utility.H"
14#include "Numeric/Stencil.H"
33 Util::Abort(
"plot_file specified in too many locations");
34 else if (pp_amr.
contains(
"plot_file"))
36 if (amrex::ParallelDescriptor::IOProcessor())
37 amrex::Warning(
"amr.plot_file will be depricated; use plot_file instead");
57 Util::Exception(
INFO,
"Cannot back up files yet because the output directory has not been specified");
59 std::string basefilename = std::filesystem::path(a_path).filename();
60 std::string absolutepath = std::filesystem::absolute(std::filesystem::path(a_path)).string();
61 std::string abspathfilename = absolutepath;
62 std::replace(abspathfilename.begin(),abspathfilename.end(),
'/',
'_');
65 abspathfilename = prefix +
"__" + abspathfilename;
66 basefilename = prefix +
"__" + abspathfilename;
69 if (amrex::ParallelDescriptor::IOProcessor())
71 std::string destinationpath;
72 if (fullpath) destinationpath =
filename+
"/"+abspathfilename;
73 else destinationpath =
filename+
"/"+basefilename;
76 if (std::filesystem::exists(destinationpath))
78 std::filesystem::copy_file(a_path,destinationpath);
81 catch (std::filesystem::filesystem_error
const& ex)
84 "file system error: \n",
85 " what(): " , ex.what() ,
'\n',
86 " path1(): " , ex.path1() ,
'\n',
87 " path2(): " , ex.path2() ,
'\n',
88 " code().value(): " , ex.code().value() ,
'\n',
89 " code().message(): " , ex.code().message() ,
'\n',
90 " code().category(): " , ex.code().category().name());
101 if (amrex::ParallelDescriptor::IOProcessor())
116 time_t timer; time(&timer);
117 std::stringstream cmd;
118 cmd <<
"xdg-open " << BUILD_DIR <<
"/src/Util/Meme/cat0" << (1+((int)timer)%6) <<
".gif &";
119 std::system(cmd.str().c_str());
124 amrex::BLBackTrace::handler(s);
131 char **argv =
nullptr;
139 amrex::Initialize(argc, argv);
142 pp_amrex.add(
"throw_exception",1);
151 if (amrex::ParallelDescriptor::IOProcessor() &&
filename !=
"")
178std::pair<std::string,std::string>
181 std::pair<std::string,std::string> ret(
"",
"");
183 if(amrex::ParallelDescriptor::IOProcessor()) {
184 if(amrex::FileExists(path)) {
185 std::time_t
t = std::time(0);
186 std::tm * now = std::localtime(&
t);
187 int year = now->tm_year+1900;
188 int month = now->tm_mon+1;
189 int day = now->tm_mday;
190 int hour = now->tm_hour;
191 int minute = now->tm_min;
192 int second = now->tm_sec;
194 std::stringstream ss;
196 << std::setfill(
'0') << std::setw(2) << month
197 << std::setfill(
'0') << std::setw(2) << day
198 << std::setfill(
'0') << std::setw(2) << hour
199 << std::setfill(
'0') << std::setw(2) << minute
200 << std::setfill(
'0') << std::setw(2) << second;
202 std::string newoldname(path +
".old." + ss.str());
203 if (amrex::system::verbose) {
204 amrex::Print() <<
"Util::CreateCleanDirectory(): " << path
205 <<
" exists. Renaming to: " << newoldname << std::endl;
207 std::rename(path.c_str(), newoldname.c_str());
209 ret.second = newoldname;
211 if( ! amrex::UtilCreateDirectory(path, 0755)) {
212 amrex::CreateDirectoryFailed(path);
217 amrex::ParallelDescriptor::Barrier(
"amrex::UtilCreateCleanDirectory");
229int ReplaceAll(std::string &str,
const std::string before,
const std::string after)
231 size_t start_pos = 0;
232 while((start_pos = str.find(before, start_pos)) != std::string::npos) {
233 str.replace(start_pos, before.length(), after);
234 start_pos += after.length();
238int ReplaceAll(std::string &str,
const char before,
const std::string after)
240 size_t start_pos = 0;
241 while((start_pos = str.find(before, start_pos)) != std::string::npos) {
242 str.replace(start_pos, 1, after);
243 start_pos += after.length();
248std::string
Join(std::vector<std::string> & vec,
char separator)
250 std::ostringstream oss;
251 for (
size_t i = 0; i < vec.size(); ++i) {
253 if (i < vec.size() - 1) {
260std::string
Wrap(std::string text,
unsigned per_line)
262 unsigned line_begin = 0;
264 while (line_begin < text.size())
266 const unsigned ideal_end = line_begin + per_line ;
267 unsigned line_end = ideal_end <= text.size() ? ideal_end : text.size()-1;
269 if (line_end == text.size() - 1)
271 else if (std::isspace(text[line_end]))
273 text[line_end] =
'\n';
278 unsigned end = line_end;
279 while ( end > line_begin && !std::isspace(text[end]))
282 if (end != line_begin)
285 text[line_end++] =
'\n';
288 text.insert(line_end++, 1,
'\n');
291 line_begin = line_end;
296std::vector<std::string>
Split(std::string &str,
const char delim)
298 std::vector<std::string> ret;
299 std::stringstream ss(str);
301 while (std::getline(ss, item, delim)) {
306bool Contains(std::string &str,
const std::string find)
308 if (str.find(find) != std::string::npos)
return true;
313std::complex<int>
Parse(std::string input)
319 std::vector<std::string> tokens =
Split(input,
' ');
320 for (
unsigned int i = 0; i < tokens.size(); i++)
322 if(tokens[i]==
"")
continue;
326 im += std::stoi(tokens[i]);
330 re += std::stoi(tokens[i]);
333 return std::complex<int>(re,im);
344 if (amrex::ParallelDescriptor::IOProcessor())
345 std::cout << std::left
351 if (amrex::ParallelDescriptor::IOProcessor())
354 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
355 std::stringstream ss;
361 int terminalwidth = 80;
363 std::cout << std::left
365 << std::setw(terminalwidth - testname.size() + ss.str().size() - 6) << std::right << std::setfill(
'.') << ss.str() << std::endl;
371 if (amrex::ParallelDescriptor::IOProcessor())
374 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
375 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;
392 if (amrex::ParallelDescriptor::IOProcessor())
395 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
396 std::stringstream ss;
397 std::cout << std::left <<
" └ ";
409void AverageCellcenterToNode(amrex::MultiFab& node_mf,
const int &dcomp,
const amrex::MultiFab &cell_mf,
const int &scomp,
const int &ncomp)
416 for (amrex::MFIter mfi(node_mf,amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
418 amrex::Box bx = mfi.nodaltilebox();
419 amrex::Array4<Set::Scalar>
const& node = node_mf.array(mfi);
420 amrex::Array4<const Set::Scalar>
const& cell = cell_mf.array(mfi);
421 for (
int n = 0; n < ncomp; n++)
422 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.
std::string Wrap(std::string text, unsigned per_line)
bool Contains(std::string &str, const std::string find)
std::vector< std::string > Split(std::string &str, const char delim)
std::string Join(std::vector< std::string > &vec, char separator)
int ReplaceAll(std::string &str, const std::string before, const std::string after)
std::complex< int > Parse(std::string input)
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)