Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow plotting only a subset of Amr levels #2825

Merged
merged 9 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Src/Amr/AMReX_Amr.H
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ public:
Real plotPer () const noexcept { return plot_per; }
//! Spacing in log10(time) of logarithmically spaced plot files
Real plotLogPer () const noexcept { return plot_log_per; }
//! Maximum level to plot
int plotMaxLevel () const noexcept { return plot_max_level; }
//! Number of time steps between small plot files.
int smallplotInt () const noexcept { return small_plot_int; }
//! Time between plot files.
Expand Down Expand Up @@ -424,6 +426,7 @@ protected:
int plot_int; //!< How often plotfile (# of time steps)
Real plot_per; //!< How often plotfile (in units of time)
Real plot_log_per; //!< How often plotfile (in units of log10(time))
int plot_max_level; //!< Maximum AMR level to write to a plotfile
int small_plot_int; //!< How often small plotfile (# of time steps)
Real small_plot_per; //!< How often small plotfile (in units of time)
Real small_plot_log_per; //!< How often small plotfile (in units of log10(time))
Expand Down
15 changes: 10 additions & 5 deletions Src/Amr/AMReX_Amr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,8 @@ Amr::writePlotFileDoit (std::string const& pltfile, bool regular)
{
auto dPlotFileTime0 = amrex::second();

int max_level_to_plot = std::min(plot_max_level, finest_level);

VisMF::SetNOutFiles(plot_nfiles);
VisMF::Header::Version currentVersion(VisMF::GetHeaderVersion());
VisMF::SetHeaderVersion(plot_headerversion);
Expand All @@ -941,7 +943,7 @@ Amr::writePlotFileDoit (std::string const& pltfile, bool regular)
if (precreateDirectories) { // ---- make all directories at once
amrex::UtilRenameDirectoryToOld(pltfile, false); // dont call barrier
amrex::UtilCreateCleanDirectory(pltfileTemp, false); // dont call barrier
for(int i(0); i <= finest_level; ++i) {
for(int i(0); i <= max_level_to_plot; ++i) {
amr_level[i]->CreateLevelDirectory(pltfileTemp);
}
ParallelDescriptor::Barrier("Amr::writePlotFile:PCD");
Expand Down Expand Up @@ -973,17 +975,17 @@ Amr::writePlotFileDoit (std::string const& pltfile, bool regular)
}

if (regular) {
for (int k(0); k <= finest_level; ++k) {
for (int k(0); k <= max_level_to_plot; ++k) {
amr_level[k]->writePlotFilePre(pltfileTemp, HeaderFile);
}
for (int k(0); k <= finest_level; ++k) {
for (int k(0); k <= max_level_to_plot; ++k) {
amr_level[k]->writePlotFile(pltfileTemp, HeaderFile);
}
for (int k(0); k <= finest_level; ++k) {
for (int k(0); k <= max_level_to_plot; ++k) {
amr_level[k]->writePlotFilePost(pltfileTemp, HeaderFile);
}
} else {
for (int k(0); k <= finest_level; ++k) {
for (int k(0); k <= max_level_to_plot; ++k) {
amr_level[k]->writeSmallPlotFile(pltfileTemp, HeaderFile);
}
}
Expand Down Expand Up @@ -3268,6 +3270,9 @@ Amr::initPltAndChk ()
}
}

plot_max_level = max_level;
pp.queryAdd("plot_max_level",plot_max_level);

small_plot_file_root = "smallplt";
pp.queryAdd("small_plot_file",small_plot_file_root);

Expand Down
9 changes: 5 additions & 4 deletions Src/Amr/AMReX_AmrLevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ AmrLevel::writePlotFile (const std::string& dir,
// if the State_Type is ::Interval, this will get t^{n+1/2} instead of t^n
Real cur_time = state[0].curTime();

int f_lev = std::min(parent->plotMaxLevel(), parent->finestLevel());

if (level == 0 && ParallelDescriptor::IOProcessor())
{
//
Expand Down Expand Up @@ -218,7 +220,6 @@ AmrLevel::writePlotFile (const std::string& dir,

os << AMREX_SPACEDIM << '\n';
os << parent->cumTime() << '\n';
int f_lev = parent->finestLevel();
os << f_lev << '\n';
for (i = 0; i < AMREX_SPACEDIM; i++) {
os << Geom().ProbLo(i) << ' ';
Expand Down Expand Up @@ -290,7 +291,7 @@ AmrLevel::writePlotFile (const std::string& dir,
RealBox gridloc = RealBox(grids[i],geom.CellSize(),geom.ProbLo());
for (n = 0; n < AMREX_SPACEDIM; n++) {
os << gridloc.lo(n) << ' ' << gridloc.hi(n) << '\n';
}
}
}
//
// The full relative pathname of the MultiFabs at this level.
Expand All @@ -307,8 +308,8 @@ AmrLevel::writePlotFile (const std::string& dir,
#ifdef AMREX_USE_EB
if (EB2::TopIndexSpaceIfPresent()) {
// volfrac threshold for amrvis
if (level == parent->finestLevel()) {
for (int lev = 0; lev <= parent->finestLevel(); ++lev) {
if (level == f_lev) {
for (int lev = 0; lev <= f_lev; ++lev) {
os << "1.0e-6\n";
}
}
Expand Down
17 changes: 13 additions & 4 deletions Tools/Plotfile/fcompare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void PrintUsage()
<< " variable.\n"
<< "\n"
<< " usage:\n"
<< " fcompare [-n|--norm num] [-d|--diffvar var] [-z|--zone_info var] [-a|--allow_diff_grids] [-r|rel_tol] [--abs_tol] [--abort_if_not_all_found] file1 file2\n"
<< " fcompare [-n|--norm num] [-d|--diffvar var] [-z|--zone_info var] [-a|--allow_diff_grids] [-l|--allow_diff_num_levels] [-r|rel_tol] [--abs_tol] [--abort_if_not_all_found] file1 file2\n"
<< "\n"
<< " optional arguments:\n"
<< " -n|--norm num : what norm to use (default is 0 for inf norm)\n"
Expand All @@ -33,6 +33,7 @@ void PrintUsage()
<< " -z|--zone_info var : output the information for a zone corresponding\n"
<< " to the maximum error for the given variable\n"
<< " -a|--allow_diff_grids : allow different BoxArrays covering the same domain\n"
<< " -l|--allow_diff_num_levels : allow different number of levels (only the levels in common will be compared)\n"
<< " -r|--rel_tol rtol : relative tolerance (default is 0)\n"
<< " --abs_tol atol : absolute tolerance (default is 0)\n"
<< " --abort_if_not_all_found : abort if not all variables are present in both files\n"
Expand All @@ -56,6 +57,7 @@ int main_main()
std::string diffvar;
int zone_info = false;
int allow_diff_grids = false;
int allow_diff_num_levels = false;
Real rtol = 0.0;
Real atol = 0.0;
std::string zone_info_var_name;
Expand All @@ -82,6 +84,8 @@ int main_main()
plot_names[0] = diffvar;
} else if (fname == "-a" || fname == "--allow_diff_grids") {
allow_diff_grids = true;
} else if (fname == "-l" || fname == "--allow_diff_num_levels") {
allow_diff_num_levels = true;
} else if (fname == "-r" || fname == "--rel_tol") {
rtol = Real(std::stod(amrex::get_command_argument(++farg)));
} else if (fname == "--abs_tol") {
Expand Down Expand Up @@ -114,10 +118,15 @@ int main_main()
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(pf_a.spaceDim() == pf_b.spaceDim(),
"ERROR: plotfiles have different numbers of spatial dimensions");

const int finest_level = pf_a.finestLevel();
const int finest_level = std::min(pf_a.finestLevel(), pf_b.finestLevel());
const int nlevels = finest_level+1;
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(pf_a.finestLevel() == pf_b.finestLevel(),
"ERROR: number of levels do not match");
if (allow_diff_num_levels && pf_a.finestLevel() != pf_b.finestLevel()) {
amrex::Print() << "\n WARNING: number of levels do not match\n";
WeiqunZhang marked this conversation as resolved.
Show resolved Hide resolved
}
else {
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(pf_a.finestLevel() == pf_b.finestLevel(),
"ERROR: number of levels do not match");
}

const int ncomp_a = pf_a.nComp();
const int ncomp_b = pf_b.nComp();
Expand Down
Loading