Skip to content

Commit

Permalink
Merge pull request #122 from hklion/plotfile_type
Browse files Browse the repository at this point in the history
add enum for plotfile type and add checks when writing plotfiles
  • Loading branch information
asalmgren authored Jan 9, 2024
2 parents 398679d + 1d9e8a2 commit 3542814
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 24 deletions.
4 changes: 4 additions & 0 deletions Source/DataStruct.H
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ enum class Cor_Type {
Custom, Beta_Plane, Real
};

enum class PlotfileType {
amrex, netcdf, hdf5
};

struct SolverChoice {
public:
void init_params()
Expand Down
13 changes: 6 additions & 7 deletions Source/IO/Plotfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ REMORA::WritePlotFile (int which, Vector<std::string> plot_var_names)
if (containerHasElement(plot_var_names, "x_velocity") ||
containerHasElement(plot_var_names, "y_velocity") ||
containerHasElement(plot_var_names, "z_velocity")) {
if (plotfile_type == "amrex") {
if (plotfile_type == PlotfileType::amrex) {
Print()<<"We now average the face-based velocity components onto cell centers for plotting "<<std::endl;
}
average_face_to_cellcenter(mf[lev],mf_comp,
Expand Down Expand Up @@ -210,7 +210,7 @@ REMORA::WritePlotFile (int which, Vector<std::string> plot_var_names)

if (finest_level == 0)
{
if (plotfile_type == "amrex") {
if (plotfile_type == PlotfileType::amrex) {
amrex::Print() << "Writing plotfile " << plotfilename << "\n";
WriteMultiLevelPlotfileWithBathymetry(plotfilename, finest_level+1,
GetVecOfConstPtrs(mf),
Expand All @@ -224,23 +224,22 @@ REMORA::WritePlotFile (int which, Vector<std::string> plot_var_names)
#endif

#ifdef REMORA_USE_HDF5
} else if (plotfile_type == "hdf5" || plotfile_type == "HDF5") {
} else if (plotfile_type == PlotfileType::hdf5) {
amrex::Print() << "Writing plotfile " << plotfilename+"d01.h5" << "\n";
WriteMultiLevelPlotfileHDF5(plotfilename, finest_level+1,
GetVecOfConstPtrs(mf),
varnames,
Geom(), t_new[0], istep, refRatio());
#endif
#ifdef REMORA_USE_NETCDF
} else if (plotfile_type == "netcdf" || plotfile_type == "NetCDF") {
} else if (plotfile_type == PlotfileType::netcdf) {
// int lev = 0;
// int nc_which = 0;
// writeNCPlotFile(lev, nc_which, plotfilename, GetVecOfConstPtrs(mf), varnames, istep, t_new[0]);
// total_plot_file_step_1 += 1;
#endif
} else {
amrex::Print() << "User specified plot_filetype = " << plotfile_type << std::endl;
amrex::Abort("Dont know this plot_filetype");
amrex::Abort("User specified unknown plot_filetype");
}

} else { // multilevel
Expand All @@ -259,7 +258,7 @@ REMORA::WritePlotFile (int which, Vector<std::string> plot_var_names)
{Geom()[0].isPeriodic(0),Geom()[0].isPeriodic(1),Geom()[0].isPeriodic(2)};
g2[0].define(Geom()[0].Domain(),&(Geom()[0].ProbDomain()),0,periodicity.data());

if (plotfile_type == "amrex") {
if (plotfile_type == PlotfileType::amrex) {
r2[0] = IntVect(1,1,ref_ratio[0][0]);
for (int lev = 1; lev <= finest_level; ++lev) {
if (lev > 1) {
Expand Down
2 changes: 1 addition & 1 deletion Source/REMORA.H
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ private:
static amrex::Real sum_per;

// Native or NetCDF
static std::string plotfile_type;
static PlotfileType plotfile_type;

// NetCDF initialization files for solution and grid
static amrex::Vector<amrex::Vector<std::string>> nc_init_file;
Expand Down
52 changes: 36 additions & 16 deletions Source/REMORA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int REMORA::sum_interval = -1;
amrex::Real REMORA::sum_per = -1.0;

// Native AMReX vs NetCDF
std::string REMORA::plotfile_type = "amrex";
PlotfileType REMORA::plotfile_type = PlotfileType::amrex;

// NetCDF initialization file
std::string REMORA::nc_bdry_file = ""; // Must provide via input
Expand Down Expand Up @@ -162,14 +162,21 @@ REMORA::Evolve ()

if (plot_int_1 > 0 && (step+1) % plot_int_1 == 0) {
last_plot_file_step_1 = step+1;
WritePlotFile(1,plot_var_names_1);
if (plotfile_type == PlotfileType::amrex)
WritePlotFile(1,plot_var_names_1);
#ifdef REMORA_USE_NETCDF
WriteNCPlotFile(step);
else if (plotfile_type == PlotfileType::netcdf)
WriteNCPlotFile(step);
#endif
}
if (plot_int_2 > 0 && (step+1) % plot_int_2 == 0) {
last_plot_file_step_2 = step+1;
WritePlotFile(2,plot_var_names_2);
if (plotfile_type == PlotfileType::amrex)
WritePlotFile(2,plot_var_names_2);
#ifdef REMORA_USE_NETCDF
else if (plotfile_type == PlotfileType::netcdf)
WriteNCPlotFile(step);
#endif
}

if (check_int > 0 && (step+1) % check_int == 0) {
Expand All @@ -191,13 +198,20 @@ REMORA::Evolve ()
}

if (plot_int_1 > 0 && istep[0] > last_plot_file_step_1) {
WritePlotFile(1,plot_var_names_1);
if (plotfile_type == PlotfileType::amrex)
WritePlotFile(1,plot_var_names_1);
#ifdef REMORA_USE_NETCDF
WriteNCPlotFile(istep[0]);
if (plotfile_type == PlotfileType::netcdf)
WriteNCPlotFile(istep[0]);
#endif
}
if (plot_int_2 > 0 && istep[0] > last_plot_file_step_2) {
WritePlotFile(2,plot_var_names_2);
if (plotfile_type == PlotfileType::amrex)
WritePlotFile(2,plot_var_names_2);
#ifdef REMORA_USE_NETCDF
else if (plotfile_type == PlotfileType::netcdf)
WriteNCPlotFile(istep[0]);
#endif
}

if (check_int > 0 && istep[0] > last_check_file_step) {
Expand Down Expand Up @@ -296,10 +310,13 @@ REMORA::InitData ()
{
if (plot_int_1 > 0)
{
WritePlotFile(1,plot_var_names_1);
if (plotfile_type == PlotfileType::amrex)
WritePlotFile(1,plot_var_names_1);
#ifdef REMORA_USE_NETCDF
int step0 = 0;
WriteNCPlotFile(step0);
if (plotfile_type == PlotfileType::netcdf) {
int step0 = 0;
WriteNCPlotFile(step0);
}
#endif
last_plot_file_step_1 = istep[0];
}
Expand Down Expand Up @@ -532,15 +549,18 @@ REMORA::ReadParameters ()
boxes_at_level[0][0] = geom[0].Domain();

// Output format
pp.query("plotfile_type", plotfile_type);
if (plotfile_type != "amrex" &&
plotfile_type != "netcdf" && plotfile_type != "NetCDF")
{
amrex::Print() << "User selected plotfile_type = " << plotfile_type << std::endl;
std::string plotfile_type_str = "amrex";
pp.query("plotfile_type", plotfile_type_str);
if (plotfile_type_str == "amrex")
plotfile_type = PlotfileType::amrex;
else if (plotfile_type_str == "netcdf" || plotfile_type_str == "NetCDF")
plotfile_type = PlotfileType::netcdf;
else {
amrex::Print() << "User selected plotfile_type = " << plotfile_type_str << std::endl;
amrex::Abort("Dont know this plotfile_type");
}
#ifndef REMORA_USE_NETCDF
if (plotfile_type == "netcdf" || plotfile_type == "NetCDF")
if (plotfile_type == PlotfileType::netcdf)
{
amrex::Abort("Please compile with NetCDF in order to enable NetCDF plotfiles");
}
Expand Down

0 comments on commit 3542814

Please sign in to comment.