7 #include "AMReX_ParallelDescriptor.H"
8 #include "AMReX_Utility.H"
14 #include "Numeric/Stencil.H"
31 Util::Abort(
"plot_file specified in too many locations");
32 else if (pp_amr.
contains(
"plot_file"))
34 if (amrex::ParallelDescriptor::IOProcessor())
35 amrex::Warning(
"amr.plot_file will be depricated; use plot_file instead");
55 Util::Exception(
INFO,
"Cannot back up files yet because the output directory has not been specified");
57 std::string basefilename = std::filesystem::path(a_path).filename();
58 std::string absolutepath = std::filesystem::absolute(std::filesystem::path(a_path)).string();
59 std::string abspathfilename = absolutepath;
60 std::replace(abspathfilename.begin(),abspathfilename.end(),
'/',
'_');
63 abspathfilename = prefix +
"__" + abspathfilename;
64 basefilename = prefix +
"__" + abspathfilename;
67 if (amrex::ParallelDescriptor::IOProcessor())
69 std::string destinationpath;
70 if (fullpath) destinationpath =
filename+
"/"+abspathfilename;
71 else destinationpath =
filename+
"/"+basefilename;
74 if (std::filesystem::exists(destinationpath))
76 std::filesystem::copy_file(a_path,destinationpath);
79 catch (std::filesystem::filesystem_error
const& ex)
82 "file system error: \n",
83 " what(): " , ex.what() ,
'\n',
84 " path1(): " , ex.path1() ,
'\n',
85 " path2(): " , ex.path2() ,
'\n',
86 " code().value(): " , ex.code().value() ,
'\n',
87 " code().message(): " , ex.code().message() ,
'\n',
88 " code().category(): " , ex.code().category().name());
99 if (amrex::ParallelDescriptor::IOProcessor())
114 time_t timer; time(&timer);
115 std::stringstream cmd;
116 cmd <<
"xdg-open " << BUILD_DIR <<
"/src/Util/Meme/cat0" << (1+((int)timer)%6) <<
".gif &";
117 std::system(cmd.str().c_str());
122 amrex::BLBackTrace::handler(s);
129 char **argv =
nullptr;
139 pp_amrex.add(
"throw_exception",1);
148 if (amrex::ParallelDescriptor::IOProcessor() &&
filename !=
"")
174 std::pair<std::string,std::string>
177 std::pair<std::string,std::string> ret(
"",
"");
179 if(amrex::ParallelDescriptor::IOProcessor()) {
180 if(amrex::FileExists(path)) {
181 std::time_t
t = std::time(0);
182 std::tm * now = std::localtime(&
t);
183 int year = now->tm_year+1900;
184 int month = now->tm_mon+1;
185 int day = now->tm_mday;
186 int hour = now->tm_hour;
187 int minute = now->tm_min;
188 int second = now->tm_sec;
190 std::stringstream ss;
192 << std::setfill(
'0') << std::setw(2) << month
193 << std::setfill(
'0') << std::setw(2) << day
194 << std::setfill(
'0') << std::setw(2) << hour
195 << std::setfill(
'0') << std::setw(2) << minute
196 << std::setfill(
'0') << std::setw(2) << second;
198 std::string newoldname(path +
".old." + ss.str());
199 if (amrex::system::verbose) {
200 amrex::Print() <<
"Util::CreateCleanDirectory(): " << path
201 <<
" exists. Renaming to: " << newoldname << std::endl;
203 std::rename(path.c_str(), newoldname.c_str());
205 ret.second = newoldname;
207 if( ! amrex::UtilCreateDirectory(path, 0755)) {
208 amrex::CreateDirectoryFailed(path);
213 amrex::ParallelDescriptor::Barrier(
"amrex::UtilCreateCleanDirectory");
225 int ReplaceAll(std::string &str,
const std::string before,
const std::string after)
227 size_t start_pos = 0;
228 while((start_pos = str.find(before, start_pos)) != std::string::npos) {
229 str.replace(start_pos, before.length(), after);
230 start_pos += after.length();
234 int ReplaceAll(std::string &str,
const char before,
const std::string after)
236 size_t start_pos = 0;
237 while((start_pos = str.find(before, start_pos)) != std::string::npos) {
238 str.replace(start_pos, 1, after);
239 start_pos += after.length();
244 std::string
Join(std::vector<std::string> & vec,
char separator)
246 std::ostringstream oss;
247 for (
size_t i = 0; i < vec.size(); ++i) {
249 if (i < vec.size() - 1) {
256 std::string
Wrap(std::string text,
unsigned per_line)
258 unsigned line_begin = 0;
260 while (line_begin < text.size())
262 const unsigned ideal_end = line_begin + per_line ;
263 unsigned line_end = ideal_end <= text.size() ? ideal_end : text.size()-1;
265 if (line_end == text.size() - 1)
267 else if (std::isspace(text[line_end]))
269 text[line_end] =
'\n';
274 unsigned end = line_end;
275 while ( end > line_begin && !std::isspace(text[end]))
278 if (end != line_begin)
281 text[line_end++] =
'\n';
284 text.insert(line_end++, 1,
'\n');
287 line_begin = line_end;
292 std::vector<std::string>
Split(std::string &str,
const char delim)
294 std::vector<std::string> ret;
295 std::stringstream ss(str);
297 while (std::getline(ss, item, delim)) {
302 bool Contains(std::string &str,
const std::string find)
304 if (str.find(find) != std::string::npos)
return true;
309 std::complex<int>
Parse(std::string input)
315 std::vector<std::string> tokens =
Split(input,
' ');
316 for (
unsigned int i = 0; i < tokens.size(); i++)
318 if(tokens[i]==
"")
continue;
322 im += std::stoi(tokens[i]);
326 re += std::stoi(tokens[i]);
329 return std::complex<int>(re,im);
340 if (amrex::ParallelDescriptor::IOProcessor())
341 std::cout << std::left
347 if (amrex::ParallelDescriptor::IOProcessor())
350 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
351 std::stringstream ss;
357 int terminalwidth = 80;
359 std::cout << std::left
361 << std::setw(terminalwidth - testname.size() + ss.str().size() - 6) << std::right << std::setfill(
'.') << ss.str() << std::endl;
367 if (amrex::ParallelDescriptor::IOProcessor())
370 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
371 std::stringstream ss;
377 int terminalwidth = 80;
379 std::cout << std::left
382 << std::setw(terminalwidth - testname.size() + ss.str().size() - 12) << std::right << std::setfill(
'.') << ss.str() << std::endl;
388 if (amrex::ParallelDescriptor::IOProcessor())
391 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
392 std::stringstream ss;
393 std::cout << std::left <<
" └ ";
405 void AverageCellcenterToNode(amrex::MultiFab& node_mf,
const int &dcomp,
const amrex::MultiFab &cell_mf,
const int &scomp,
const int &ncomp)
412 for (amrex::MFIter mfi(node_mf,amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
414 amrex::Box bx = mfi.nodaltilebox();
415 amrex::Array4<Set::Scalar>
const& node = node_mf.array(mfi);
416 amrex::Array4<const Set::Scalar>
const& cell = cell_mf.array(mfi);
417 for (
int n = 0; n < ncomp; n++)
418 amrex::ParallelFor (bx,[=] AMREX_GPU_DEVICE(
int i,
int j,
int k) {