7 #include "AMReX_ParallelDescriptor.H"
8 #include "AMReX_Utility.H"
14 #include "Numeric/Stencil.H"
30 Util::Abort(
"plot_file specified in too many locations");
31 else if (pp_amr.
contains(
"plot_file"))
33 if (amrex::ParallelDescriptor::IOProcessor())
34 amrex::Warning(
"amr.plot_file will be depricated; use plot_file instead");
54 Util::Exception(
INFO,
"Cannot back up files yet because the output directory has not been specified");
56 std::string basefilename = std::filesystem::path(a_path).filename();
57 std::string absolutepath = std::filesystem::absolute(std::filesystem::path(a_path)).string();
58 std::string abspathfilename = absolutepath;
59 std::replace(abspathfilename.begin(),abspathfilename.end(),
'/',
'_');
62 abspathfilename = prefix +
"__" + abspathfilename;
63 basefilename = prefix +
"__" + abspathfilename;
66 if (amrex::ParallelDescriptor::IOProcessor())
68 std::string destinationpath;
69 if (fullpath) destinationpath =
filename+
"/"+abspathfilename;
70 else destinationpath =
filename+
"/"+basefilename;
73 if (std::filesystem::exists(destinationpath))
75 std::filesystem::copy_file(a_path,destinationpath);
78 catch (std::filesystem::filesystem_error
const& ex)
81 "file system error: \n",
82 " what(): " , ex.what() ,
'\n',
83 " path1(): " , ex.path1() ,
'\n',
84 " path2(): " , ex.path2() ,
'\n',
85 " code().value(): " , ex.code().value() ,
'\n',
86 " code().message(): " , ex.code().message() ,
'\n',
87 " code().category(): " , ex.code().category().name());
98 if (amrex::ParallelDescriptor::IOProcessor())
113 time_t timer; time(&timer);
114 std::stringstream cmd;
115 cmd <<
"xdg-open " << BUILD_DIR <<
"/src/Util/Meme/cat0" << (1+((int)timer)%6) <<
".gif &";
116 std::system(cmd.str().c_str());
121 amrex::BLBackTrace::handler(s);
128 char **argv =
nullptr;
138 pp_amrex.add(
"throw_exception",1);
147 if (amrex::ParallelDescriptor::IOProcessor() &&
filename !=
"")
173 std::pair<std::string,std::string>
176 std::pair<std::string,std::string> ret(
"",
"");
178 if(amrex::ParallelDescriptor::IOProcessor()) {
179 if(amrex::FileExists(path)) {
180 std::time_t
t = std::time(0);
181 std::tm * now = std::localtime(&
t);
182 int year = now->tm_year+1900;
183 int month = now->tm_mon+1;
184 int day = now->tm_mday;
185 int hour = now->tm_hour;
186 int minute = now->tm_min;
187 int second = now->tm_sec;
189 std::stringstream ss;
191 << std::setfill(
'0') << std::setw(2) << month
192 << std::setfill(
'0') << std::setw(2) << day
193 << std::setfill(
'0') << std::setw(2) << hour
194 << std::setfill(
'0') << std::setw(2) << minute
195 << std::setfill(
'0') << std::setw(2) << second;
197 std::string newoldname(path +
".old." + ss.str());
198 if (amrex::system::verbose) {
199 amrex::Print() <<
"Util::CreateCleanDirectory(): " << path
200 <<
" exists. Renaming to: " << newoldname << std::endl;
202 std::rename(path.c_str(), newoldname.c_str());
204 ret.second = newoldname;
206 if( ! amrex::UtilCreateDirectory(path, 0755)) {
207 amrex::CreateDirectoryFailed(path);
212 amrex::ParallelDescriptor::Barrier(
"amrex::UtilCreateCleanDirectory");
224 int ReplaceAll(std::string &str,
const std::string before,
const std::string after)
226 size_t start_pos = 0;
227 while((start_pos = str.find(before, start_pos)) != std::string::npos) {
228 str.replace(start_pos, before.length(), after);
229 start_pos += after.length();
233 int ReplaceAll(std::string &str,
const char before,
const std::string after)
235 size_t start_pos = 0;
236 while((start_pos = str.find(before, start_pos)) != std::string::npos) {
237 str.replace(start_pos, 1, after);
238 start_pos += after.length();
243 std::string
Join(std::vector<std::string> & vec,
char separator)
245 std::ostringstream oss;
246 for (
size_t i = 0; i < vec.size(); ++i) {
248 if (i < vec.size() - 1) {
255 std::string
Wrap(std::string text,
unsigned per_line)
257 unsigned line_begin = 0;
259 while (line_begin < text.size())
261 const unsigned ideal_end = line_begin + per_line ;
262 unsigned line_end = ideal_end <= text.size() ? ideal_end : text.size()-1;
264 if (line_end == text.size() - 1)
266 else if (std::isspace(text[line_end]))
268 text[line_end] =
'\n';
273 unsigned end = line_end;
274 while ( end > line_begin && !std::isspace(text[end]))
277 if (end != line_begin)
280 text[line_end++] =
'\n';
283 text.insert(line_end++, 1,
'\n');
286 line_begin = line_end;
291 std::vector<std::string>
Split(std::string &str,
const char delim)
293 std::vector<std::string> ret;
294 std::stringstream ss(str);
296 while (std::getline(ss, item, delim)) {
301 bool Contains(std::string &str,
const std::string find)
303 if (str.find(find) != std::string::npos)
return true;
308 std::complex<int>
Parse(std::string input)
314 std::vector<std::string> tokens =
Split(input,
' ');
315 for (
unsigned int i = 0; i < tokens.size(); i++)
317 if(tokens[i]==
"")
continue;
321 im += std::stoi(tokens[i]);
325 re += std::stoi(tokens[i]);
328 return std::complex<int>(re,im);
339 if (amrex::ParallelDescriptor::IOProcessor())
340 std::cout << std::left
346 if (amrex::ParallelDescriptor::IOProcessor())
349 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
350 std::stringstream ss;
356 int terminalwidth = 80;
358 std::cout << std::left
360 << std::setw(terminalwidth - testname.size() + ss.str().size() - 6) << std::right << std::setfill(
'.') << ss.str() << std::endl;
366 if (amrex::ParallelDescriptor::IOProcessor())
369 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
370 std::stringstream ss;
376 int terminalwidth = 80;
378 std::cout << std::left
381 << std::setw(terminalwidth - testname.size() + ss.str().size() - 12) << std::right << std::setfill(
'.') << ss.str() << std::endl;
387 if (amrex::ParallelDescriptor::IOProcessor())
390 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
391 std::stringstream ss;
392 std::cout << std::left <<
" └ ";
404 void AverageCellcenterToNode(amrex::MultiFab& node_mf,
const int &dcomp,
const amrex::MultiFab &cell_mf,
const int &scomp,
const int &ncomp)
411 for (amrex::MFIter mfi(node_mf,amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
413 amrex::Box bx = mfi.nodaltilebox();
414 amrex::Array4<Set::Scalar>
const& node = node_mf.array(mfi);
415 amrex::Array4<const Set::Scalar>
const& cell = cell_mf.array(mfi);
416 for (
int n = 0; n < ncomp; n++)
417 amrex::ParallelFor (bx,[=] AMREX_GPU_DEVICE(
int i,
int j,
int k) {