Skip to content

Commit

Permalink
Call diff dertemp function if moist
Browse files Browse the repository at this point in the history
  • Loading branch information
ewquon committed Jul 9, 2024
1 parent 2773e05 commit 901b1ae
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
11 changes: 11 additions & 0 deletions Source/Derive.H
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ void erf_dertemp (
const int* bcrec,
const int level);

void erf_dermoisttemp (
const amrex::Box& bx,
amrex::FArrayBox& derfab,
int dcomp,
int ncomp,
const amrex::FArrayBox& datfab,
const amrex::Geometry& geomdata,
amrex::Real time,
const int* bcrec,
const int level);

void erf_dertheta (
const amrex::Box& bx,
amrex::FArrayBox& derfab,
Expand Down
23 changes: 23 additions & 0 deletions Source/Derive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,29 @@ erf_dertemp (const Box& bx,
tfab(i,j,k) = getTgivenRandRTh(rho,rhotheta);
});
}
void
erf_dermoisttemp (const Box& bx,
FArrayBox& derfab,
int /*dcomp*/,
int /*ncomp*/,
const FArrayBox& datfab,
const Geometry& /*geomdata*/,
Real /*time*/,
const int* /*bcrec*/,
const int /*level*/)
{
auto const dat = datfab.array();
auto tfab = derfab.array();

ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
{
const Real rho = dat(i, j, k, Rho_comp);
const Real rhotheta = dat(i, j, k, RhoTheta_comp);
AMREX_ALWAYS_ASSERT(rhotheta > 0.);
const Real qv = dat(i, j, k, RhoQ1_comp) / rho;
tfab(i,j,k) = getTgivenRandRTh(rho,rhotheta,qv);
});
}

/**
* Function to define the potential temperature by calling an EOS routine
Expand Down
9 changes: 8 additions & 1 deletion Source/IO/ERF_WriteBndryPlanes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ void WriteBndryPlanes::write_planes (const int t_step, const Real time,
Box target_box_shifted(IntVect(0,0,0),new_hi);
BoxArray ba_shifted(target_box_shifted);

int n_moist_var = NMOIST_max - (S.nComp() - NVAR_max);
bool ismoist = (n_moist_var >= 1);

for (int i = 0; i < m_var_names.size(); i++)
{
std::string var_name = m_var_names[i];
Expand All @@ -169,7 +172,11 @@ void WriteBndryPlanes::write_planes (const int t_step, const Real time,
for (MFIter mfi(Temp, TilingIfNotGPU()); mfi.isValid(); ++mfi)
{
const Box& bx = mfi.tilebox();
derived::erf_dertemp(bx, Temp[mfi], 0, 1, S[mfi], m_geom[bndry_lev], time, nullptr, bndry_lev);
if (ismoist) {
derived::erf_dermoisttemp(bx, Temp[mfi], 0, 1, S[mfi], m_geom[bndry_lev], time, nullptr, bndry_lev);
} else {
derived::erf_dertemp(bx, Temp[mfi], 0, 1, S[mfi], m_geom[bndry_lev], time, nullptr, bndry_lev);
}
}
bndry.copyFrom(Temp, nghost, 0, 0, ncomp, m_geom[bndry_lev].periodicity());
} else if (var_name == "scalar") {
Expand Down
8 changes: 7 additions & 1 deletion Source/IO/Plotfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,15 @@ ERF::WritePlotFile (int which, Vector<std::string> plot_var_names)
}
};

bool ismoist = (solverChoice.moisture_type != MoistureType::None);

// Note: All derived variables must be computed in order of "derived_names" defined in ERF.H
calculate_derived("soundspeed", vars_new[lev][Vars::cons], derived::erf_dersoundspeed);
calculate_derived("temp", vars_new[lev][Vars::cons], derived::erf_dertemp);
if (ismoist) {
calculate_derived("temp", vars_new[lev][Vars::cons], derived::erf_dermoisttemp);
} else {
calculate_derived("temp", vars_new[lev][Vars::cons], derived::erf_dertemp);
}
calculate_derived("theta", vars_new[lev][Vars::cons], derived::erf_dertheta);
calculate_derived("KE", vars_new[lev][Vars::cons], derived::erf_derKE);
calculate_derived("QKE", vars_new[lev][Vars::cons], derived::erf_derQKE);
Expand Down

0 comments on commit 901b1ae

Please sign in to comment.