Skip to content

Commit

Permalink
Some fixes for warnings in 2D (#534)
Browse files Browse the repository at this point in the history
* avoid nullptr deref in gammalaw

* remove commented debugging in turbinflow, instead add verbose flag

* require 3 dimensions to use TurbInflow

* Updates to eliminate indexing warnings in TurbInflow for 2D

* require 3D for DiagFramePlane and fix indexing warning for 2D

* docs for turbinflow verbosity
  • Loading branch information
baperry2 authored Oct 8, 2024
1 parent 37efd19 commit 862c29c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 44 deletions.
2 changes: 2 additions & 0 deletions Docs/sphinx/Utility.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ provided below. ::
turbinflow.low.turb_conv_vel = 5. # Velocity to move through the 3rd dimension to simulate time evolution
turbinflow.low.turb_nplane = 32 # Number of planes to read and store at a time
turbinflow.low.time_offset = 0.0 # Offset in time for reading through the 3rd dimension
turbinflow.low.verbose = 0 # verbosity level

turbinflow.high.turb_file = TurbFileHIT/TurbTEST # All same as above, but for second injection patch
turbinflow.high.dir = 1
Expand All @@ -87,6 +88,7 @@ provided below. ::
turbinflow.high.turb_conv_vel = 5.
turbinflow.high.turb_nplane = 32
turbinflow.high.time_offset = 0.0006
turbinflow.high.verbose = 2

Plt File Management
===================
Expand Down
10 changes: 7 additions & 3 deletions Source/Utility/Diagnostics/DiagFramePlane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ DiagFramePlane::init(const std::string& a_prefix, std::string_view a_diagName)
{
DiagBase::init(a_prefix, a_diagName);

AMREX_ALWAYS_ASSERT_WITH_MESSAGE(
AMREX_SPACEDIM == 3, "DiagFramePlane::init(): DiagFramePlane is only "
"supported for 3 dimensional simulations");

if (m_filters.empty()) {
amrex::Print() << " Filters are not available on DiagFramePlane and will "
"be discarded \n";
Expand Down Expand Up @@ -117,9 +121,9 @@ DiagFramePlane::prepare(
cdim += 1;
}
}
initDomain.setRange(2, 0, 1);
initRealBox.setLo(2, 0.0);
initRealBox.setHi(2, dxlcl[2]);
initDomain.setRange(AMREX_SPACEDIM - 1, 0, 1);
initRealBox.setLo(AMREX_SPACEDIM - 1, 0.0);
initRealBox.setHi(AMREX_SPACEDIM - 1, dxlcl[2]);
m_geomLev0.define(
initDomain, initRealBox, a_geoms[0].Coord(),
amrex::Array<int, AMREX_SPACEDIM>({AMREX_D_DECL(0, 0, 0)}));
Expand Down
13 changes: 8 additions & 5 deletions Source/Utility/TurbInflow/turbinflow.H
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ struct TurbParm
// Turbulence data file
std::string m_turb_file;

// Verbosity
int verbose = 1;

// Geometry of the turbulent data
amrex::GpuArray<int, AMREX_SPACEDIM> npboxcells = {{0}};
amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> pboxlo = {{0.0}};
amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> dx = {{0.0}};
amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> dxinv = {{0.0}};
amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> pboxsize = {{0.0}};
amrex::GpuArray<int, 3> npboxcells = {{0}};
amrex::GpuArray<amrex::Real, 3> pboxlo = {{0.0}};
amrex::GpuArray<amrex::Real, 3> dx = {{0.0}};
amrex::GpuArray<amrex::Real, 3> dxinv = {{0.0}};
amrex::GpuArray<amrex::Real, 3> pboxsize = {{0.0}};
int dir; // Direction where to use this TurbParm
amrex::Orientation::Side side; // Side on which to use this TurbParm
amrex::Real time_shift =
Expand Down
59 changes: 23 additions & 36 deletions Source/Utility/TurbInflow/turbinflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ TurbInflow::init(amrex::Geometry const& /*geom*/)
n_tp = ppr.countval("turbinflows");
amrex::Vector<std::string> tp_list;
if (n_tp > 0) {
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(
AMREX_SPACEDIM == 3, "TurbInflow::init(): TurbInflows are only supported "
"for 3 dimensional simulations for now");
tp.resize(n_tp);
tp_list.resize(n_tp);
for (int n = 0; n < n_tp; n++) {
Expand Down Expand Up @@ -41,12 +44,15 @@ TurbInflow::init(amrex::Geometry const& /*geom*/)
pp.query("time_offset", tp[n].time_shift);
pp.query("turb_scale_loc", tp[n].turb_scale_loc);
pp.query("turb_scale_vel", tp[n].turb_scale_vel);
amrex::Print() << "Initializing turbInflow " << tp_list[n]
<< " with file " << tp[n].m_turb_file
<< " (location coordinates in will be scaled by "
<< tp[n].turb_scale_loc
<< " and velocity out to be scaled by "
<< tp[n].turb_scale_vel << ") \n";
pp.query("verbose", tp[n].verbose);
if (tp[n].verbose > 0) {
amrex::Print() << "Initializing turbInflow " << tp_list[n]
<< " with file " << tp[n].m_turb_file
<< " (location coordinates in will be scaled by "
<< tp[n].turb_scale_loc
<< " and velocity out to be scaled by "
<< tp[n].turb_scale_vel << ") \n";
}

// Get the turbcenter on the injection face
amrex::Vector<amrex::Real> turb_center(AMREX_SPACEDIM - 1, 0);
Expand Down Expand Up @@ -189,16 +195,6 @@ TurbInflow::add_turb(

// Moving it into data
set_turb(dir, tdir1, tdir2, v, data, dcomp);

#if 0
std::string junk = "TurbV_AftTP"+std::to_string(n)+"_D";
std::ofstream os;
os.precision(15);
os.open(junk.c_str());
data.writeOn(os);
os.close();
amrex::Abort();
#endif
}

void
Expand Down Expand Up @@ -246,8 +242,8 @@ TurbInflow::read_one_turb_plane(TurbParm& a_tp, int iplane, int k)
}

amrex::Box dstBox = a_tp.sdata->box();
dstBox.setSmall(2, iplane);
dstBox.setBig(2, iplane);
dstBox.setSmall(AMREX_SPACEDIM - 1, iplane);
dstBox.setBig(AMREX_SPACEDIM - 1, iplane);

for (int n = 0; n < AMREX_SPACEDIM; ++n) {

Expand Down Expand Up @@ -280,25 +276,17 @@ TurbInflow::read_turb_planes(TurbParm& a_tp, amrex::Real z)
a_tp.szlo = static_cast<amrex::Real>(izlo) * a_tp.dx[2];
a_tp.szhi = static_cast<amrex::Real>(izhi) * a_tp.dx[2];

#if 0
amrex::AllPrint() << "read_turb_planes filling " << izlo << " to " << izhi
<< " covering " << a_tp.szlo + 0.5 * a_tp.dx[2]
<< " to " << a_tp.szhi - 0.5 * a_tp.dx[2] << " for z = " << z << std::endl;
#endif
if (a_tp.verbose > 1) {
amrex::Print() << "read_turb_planes filling " << izlo << " to " << izhi
<< " covering " << a_tp.szlo + 0.5 * a_tp.dx[2] << " to "
<< a_tp.szhi - 0.5 * a_tp.dx[2] << " for z = " << z
<< std::endl;
}

for (int iplane = 1; iplane <= a_tp.nplane; ++iplane) {
int k = (izlo + iplane - 1) % (a_tp.npboxcells[2] - 2);
read_one_turb_plane(a_tp, iplane, k);
}
#if 0
int myproc = amrex::ParallelDescriptor::MyProc();
std::string junk = "TurbData_proc"+std::to_string(myproc)+"_D";
std::ofstream os;
os.precision(15);
os.open(junk.c_str());
a_tp.sdata->writeOn(os);
os.close();
#endif
}

void
Expand All @@ -311,12 +299,11 @@ TurbInflow::fill_turb_plane(
{
if (
(z < a_tp.szlo + 0.5 * a_tp.dx[2]) || (z > a_tp.szhi - 0.5 * a_tp.dx[2])) {
#if 0
{
amrex::AllPrint() << "Reading new data because z " << z << " is outside " << a_tp.szlo + 0.5 * a_tp.dx[2] << " and "
if (a_tp.verbose > 1) {
amrex::Print() << "Reading new data because z " << z << " is outside "
<< a_tp.szlo + 0.5 * a_tp.dx[2] << " and "
<< a_tp.szhi - 0.5 * a_tp.dx[2] << std::endl;
}
#endif
read_turb_planes(a_tp, z);
}

Expand Down

0 comments on commit 862c29c

Please sign in to comment.