From 1d9e8a235d672dbdc7dc4fd75f97f1b727c470a9 Mon Sep 17 00:00:00 2001 From: Hannah Klion Date: Tue, 9 Jan 2024 12:10:00 -0800 Subject: [PATCH] add enum for plotfile type and add checks when writing plotfiles --- Source/DataStruct.H | 4 ++++ Source/IO/Plotfile.cpp | 13 +++++------ Source/REMORA.H | 2 +- Source/REMORA.cpp | 52 +++++++++++++++++++++++++++++------------- 4 files changed, 47 insertions(+), 24 deletions(-) diff --git a/Source/DataStruct.H b/Source/DataStruct.H index f8a021fa..a0dcf9ba 100644 --- a/Source/DataStruct.H +++ b/Source/DataStruct.H @@ -34,6 +34,10 @@ enum class Cor_Type { Custom, Beta_Plane, Real }; +enum class PlotfileType { + amrex, netcdf, hdf5 +}; + struct SolverChoice { public: void init_params() diff --git a/Source/IO/Plotfile.cpp b/Source/IO/Plotfile.cpp index ec381270..f4847f8f 100644 --- a/Source/IO/Plotfile.cpp +++ b/Source/IO/Plotfile.cpp @@ -142,7 +142,7 @@ REMORA::WritePlotFile (int which, Vector 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 "< 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), @@ -224,7 +224,7 @@ REMORA::WritePlotFile (int which, Vector 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), @@ -232,15 +232,14 @@ REMORA::WritePlotFile (int which, Vector plot_var_names) 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 @@ -259,7 +258,7 @@ REMORA::WritePlotFile (int which, Vector 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) { diff --git a/Source/REMORA.H b/Source/REMORA.H index fea6e2c6..f48e2694 100644 --- a/Source/REMORA.H +++ b/Source/REMORA.H @@ -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> nc_init_file; diff --git a/Source/REMORA.cpp b/Source/REMORA.cpp index b11fbe6a..bff263fc 100644 --- a/Source/REMORA.cpp +++ b/Source/REMORA.cpp @@ -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 @@ -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) { @@ -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) { @@ -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]; } @@ -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"); }