Skip to content

Commit

Permalink
Merge pull request #91 from seahorce-scidac/add_z_phys_in_plot
Browse files Browse the repository at this point in the history
add z_phys_nd to the plotfile
  • Loading branch information
asalmgren authored Dec 15, 2023
2 parents 6c8a66c + f7825ed commit cad1533
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 62 deletions.
78 changes: 49 additions & 29 deletions Source/IO/Plotfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ ROMSX::WritePlotFile (int which, Vector<std::string> plot_var_names)
mf[lev].define(grids[lev], dmap[lev], ncomp_mf, ngrow_vars);
}

Vector<MultiFab> mf_nd(finest_level+1);
for (int lev = 0; lev <= finest_level; ++lev) {
BoxArray nodal_grids(grids[lev]); nodal_grids.surroundingNodes();
mf_nd[lev].define(nodal_grids, dmap[lev], AMREX_SPACEDIM, 0);
mf_nd[lev].setVal(0.);
}

for (int lev = 0; lev <= finest_level; ++lev) {
int mf_comp = 0;

Expand Down Expand Up @@ -176,14 +183,26 @@ ROMSX::WritePlotFile (int which, Vector<std::string> plot_var_names)
{
MultiFab temp_dat(mf[lev].boxArray(), mf[lev].DistributionMap(), 1, 0);
temp_dat.setVal(0);
particleData.tracer_particles->Redistribute();
particleData.tracer_particles->Increment(temp_dat, lev);
MultiFab::Copy(mf[lev], temp_dat, 0, mf_comp, 1, 0);
mf_comp += 1;
}
#endif
}

// Fill terrain distortion MF
for (int lev(0); lev <= finest_level; ++lev) {
MultiFab::Copy(mf_nd[lev],*vec_z_phys_nd[lev],0,2,1,0);
Real dz = Geom()[lev].CellSizeArray()[2];
for (MFIter mfi(mf_nd[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi) {
const Box& bx = mfi.tilebox();
Array4< Real> mf_arr = mf_nd[lev].array(mfi);
ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) {
mf_arr(i,j,k,2) -= k * dz;
});
}
}

std::string plotfilename;
if (which == 1)
plotfilename = Concatenate(plot_file_1, istep[0], 5);
Expand All @@ -194,10 +213,11 @@ ROMSX::WritePlotFile (int which, Vector<std::string> plot_var_names)
{
if (plotfile_type == "amrex") {
amrex::Print() << "Writing plotfile " << plotfilename << "\n";
WriteMultiLevelPlotfile(plotfilename, finest_level+1,
GetVecOfConstPtrs(mf),
varnames,
Geom(), t_new[0], istep, refRatio());
WriteMultiLevelPlotfileWithBathymetry(plotfilename, finest_level+1,
GetVecOfConstPtrs(mf),
GetVecOfConstPtrs(mf_nd),
varnames,
t_new[0], istep);
writeJobInfo(plotfilename);

#ifdef ROMSX_USE_PARTICLES
Expand Down Expand Up @@ -273,7 +293,7 @@ ROMSX::WritePlotFile (int which, Vector<std::string> plot_var_names)
}

WriteMultiLevelPlotfile(plotfilename, finest_level+1, GetVecOfConstPtrs(mf2), varnames,
g2, t_new[0], istep, rr);
g2, t_new[0], istep, rr);
writeJobInfo(plotfilename);

#ifdef ROMSX_USE_PARTICLES
Expand All @@ -294,18 +314,18 @@ ROMSX::WritePlotFile (int which, Vector<std::string> plot_var_names)
}

void
ROMSX::WriteMultiLevelPlotfileWithTerrain (const std::string& plotfilename, int nlevels,
const Vector<const MultiFab*>& mf,
const Vector<const MultiFab*>& mf_nd,
const Vector<std::string>& varnames,
Real time,
const Vector<int>& level_steps,
const std::string &versionName,
const std::string &levelPrefix,
const std::string &mfPrefix,
const Vector<std::string>& extra_dirs) const
ROMSX::WriteMultiLevelPlotfileWithBathymetry (const std::string& plotfilename, int nlevels,
const Vector<const MultiFab*>& mf,
const Vector<const MultiFab*>& mf_nd,
const Vector<std::string>& varnames,
Real time,
const Vector<int>& level_steps,
const std::string &versionName,
const std::string &levelPrefix,
const std::string &mfPrefix,
const Vector<std::string>& extra_dirs) const
{
BL_PROFILE("WriteMultiLevelPlotfileWithTerrain()");
BL_PROFILE("WriteMultiLevelPlotfileWithBathymetry()");

BL_ASSERT(nlevels <= mf.size());
BL_ASSERT(nlevels <= ref_ratio.size()+1);
Expand Down Expand Up @@ -337,9 +357,9 @@ ROMSX::WriteMultiLevelPlotfileWithTerrain (const std::string& plotfilename, int
std::ofstream::trunc |
std::ofstream::binary);
if( ! HeaderFile.good()) FileOpenFailed(HeaderFileName);
WriteGenericPlotfileHeaderWithTerrain(HeaderFile, nlevels, boxArrays, varnames,
time, level_steps, versionName,
levelPrefix, mfPrefix);
WriteGenericPlotfileHeaderWithBathymetry(HeaderFile, nlevels, boxArrays, varnames,
time, level_steps, versionName,
levelPrefix, mfPrefix);
};

if (AsyncOut::UseAsyncOut()) {
Expand Down Expand Up @@ -379,15 +399,15 @@ ROMSX::WriteMultiLevelPlotfileWithTerrain (const std::string& plotfilename, int
}

void
ROMSX::WriteGenericPlotfileHeaderWithTerrain (std::ostream &HeaderFile,
int nlevels,
const Vector<BoxArray> &bArray,
const Vector<std::string> &varnames,
Real time,
const Vector<int> &level_steps,
const std::string &versionName,
const std::string &levelPrefix,
const std::string &mfPrefix) const
ROMSX::WriteGenericPlotfileHeaderWithBathymetry (std::ostream &HeaderFile,
int nlevels,
const Vector<BoxArray> &bArray,
const Vector<std::string> &varnames,
Real time,
const Vector<int> &level_steps,
const std::string &versionName,
const std::string &levelPrefix,
const std::string &mfPrefix) const
{
BL_ASSERT(nlevels <= bArray.size());
BL_ASSERT(nlevels <= ref_ratio.size()+1);
Expand Down
51 changes: 18 additions & 33 deletions Source/ROMSX.H
Original file line number Diff line number Diff line change
Expand Up @@ -152,28 +152,28 @@ public:
/** write plotfile to disk */
void WritePlotFile (int which, amrex::Vector<std::string> plot_var_names);

void WriteMultiLevelPlotfileWithTerrain (const std::string &plotfilename,
int nlevels,
const amrex::Vector<const amrex::MultiFab*> &mf,
const amrex::Vector<const amrex::MultiFab*> &mf_nd,
const amrex::Vector<std::string> &varnames,
amrex::Real time,
const amrex::Vector<int> &level_steps,
const std::string &versionName = "HyperCLaw-V1.1",
const std::string &levelPrefix = "Level_",
const std::string &mfPrefix = "Cell",
const amrex::Vector<std::string>& extra_dirs = amrex::Vector<std::string>()) const;


void WriteGenericPlotfileHeaderWithTerrain (std::ostream &HeaderFile,
void WriteMultiLevelPlotfileWithBathymetry (const std::string &plotfilename,
int nlevels,
const amrex::Vector<amrex::BoxArray> &bArray,
const amrex::Vector<const amrex::MultiFab*> &mf,
const amrex::Vector<const amrex::MultiFab*> &mf_nd,
const amrex::Vector<std::string> &varnames,
amrex::Real time,
const amrex::Vector<int> &level_steps,
const std::string &versionName,
const std::string &levelPrefix,
const std::string &mfPrefix) const;
const std::string &versionName = "HyperCLaw-V1.1",
const std::string &levelPrefix = "Level_",
const std::string &mfPrefix = "Cell",
const amrex::Vector<std::string>& extra_dirs = amrex::Vector<std::string>()) const;


void WriteGenericPlotfileHeaderWithBathymetry (std::ostream &HeaderFile,
int nlevels,
const amrex::Vector<amrex::BoxArray> &bArray,
const amrex::Vector<std::string> &varnames,
amrex::Real time,
const amrex::Vector<int> &level_steps,
const std::string &versionName,
const std::string &levelPrefix,
const std::string &mfPrefix) const;

std::string pp_prefix {"romsx"};

Expand Down Expand Up @@ -694,21 +694,6 @@ private:
int coordinatorProc = amrex::ParallelDescriptor::IOProcessorNumber(),
int allow_empty_mf = 0);

// *** *** FArrayBox's for holding the SURFACE data
// Data read from the wrfinput NetCDF file
amrex::FArrayBox NC_HGT_fab; // Terrain height (variable HGT in the wrfinput file)
amrex::IArrayBox NC_IVGTYP_fab; // Vegetation type (IVGTYP); Discrete numbers;
amrex::FArrayBox NC_z0_fab; // Surface Roughness, z0 = z0 (IVGTYP)
amrex::FArrayBox NC_PSFC_fab; // Surface pressure

// TODO: Clarify the relation between SST and TSK
amrex::FArrayBox NC_SST_fab; // Sea Surface Temperature; Defined even for land area
amrex::FArrayBox NC_TSK_fab; // Surface Skin Temperature; Appears to be same as SST...

amrex::FArrayBox NC_eta_fab, NC_phb_fab, NC_z_phy_fab;
#endif // ROMSX_USE_NETCDF

#ifdef ROMSX_USE_NETCDF
// Vectors (over time) of Vector (over variables) of FArrayBoxs for holding the data read from the wrfbdy NetCDF file
amrex::Vector<amrex::Vector<amrex::FArrayBox>> bdy_data_xlo;
amrex::Vector<amrex::Vector<amrex::FArrayBox>> bdy_data_xhi;
Expand Down

0 comments on commit cad1533

Please sign in to comment.