Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f624a2f
add nudging of moist variables other than qv
asalmgren Jun 16, 2026
edbc65d
Merge branch 'development' into alternate_moist_nudging
asalmgren Jun 16, 2026
ab7f19c
consolidate files
asalmgren Jun 17, 2026
ece4538
Merge branch 'development' into alternate_moist_nudging
asalmgren Jun 17, 2026
b7f3346
Merge branch 'development' into alternate_moist_nudging
asalmgren Jun 17, 2026
0d3cc8a
add heat release from nudging
asalmgren Jun 17, 2026
89d75c3
Merge branch 'development' into alternate_moist_nudging
asalmgren Jun 17, 2026
0cc33e7
Merge branch 'development' into alternate_moist_nudging
asalmgren Jun 17, 2026
079feaf
Merge branch 'development' into alternate_moist_nudging
asalmgren Jun 17, 2026
6200866
Merge branch 'development' into alternate_moist_nudging
AMLattanzi Jun 18, 2026
10220d0
Merge branch 'development' into alternate_moist_nudging
AMLattanzi Jun 18, 2026
dc728e1
Merge branch 'development' into alternate_moist_nudging
asalmgren Jun 19, 2026
3ab42ab
Update ERF_Utils.H
asalmgren Jun 20, 2026
a8ec8f6
Merge branch 'development' into alternate_moist_nudging
asalmgren Jun 20, 2026
9610e96
Merge branch 'development' into moist_nudging_of_qc
asalmgren Jun 22, 2026
c6b8657
Fix to moist nudging in bdy region
asalmgren Jun 22, 2026
2f8d9ac
fix compiling errors
asalmgren Jun 22, 2026
9cd144b
cleaner
asalmgren Jun 22, 2026
ec06f04
more fixes
asalmgren Jun 22, 2026
52cd305
fix scaling of heat release
asalmgren Jun 22, 2026
0114f0e
one more oops
asalmgren Jun 22, 2026
c2a3166
Merge branch 'development' into moist_nudging_of_qc
asalmgren Jun 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CMake/BuildERFExe.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,6 @@ function(build_erf_lib erf_lib_name)
${SRC_DIR}/SourceTerms/ERF_MakeGradP.cpp
${SRC_DIR}/SourceTerms/ERF_MakeMomSources.cpp
${SRC_DIR}/SourceTerms/ERF_MakeSources.cpp
${SRC_DIR}/SourceTerms/ERF_MoistSetRhs.cpp
${SRC_DIR}/SourceTerms/ERF_NumericalDiffusion.cpp
${SRC_DIR}/SourceTerms/ERF_ForestDrag.cpp
${SRC_DIR}/SourceTerms/ERF_ApplySurfaceTreatment_BulkCoeff.cpp
Expand Down
178 changes: 163 additions & 15 deletions Source/SourceTerms/ERF_AddMoistNudgingTerms.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#if defined(ERF_USE_NETCDF)

#include <ERF_SrcHeaders.H>
#include <ERF_Utils.H>

using namespace amrex;

Expand All @@ -26,41 +27,188 @@ using namespace amrex;

void add_moist_nudging_terms (const MultiFab& S_data,
MultiFab & source,
const int n_qstate,
const Real& dt,
const Real& old_stage_time_total,
const Real& time,
const Real& start_bdy_time,
const Real& final_bdy_time,
const Real& bdy_time_interval,
const Real& bdy_factor,
int width,
const Real& nudge_factor,
const int width,
const Geometry& geom,
Vector<Vector<FArrayBox>>& bdy_data_xlo,
Vector<Vector<FArrayBox>>& bdy_data_xhi,
Vector<Vector<FArrayBox>>& bdy_data_ylo,
Vector<Vector<FArrayBox>>& bdy_data_yhi,
std::unique_ptr<ReadBndryPlanes>& m_r2d)
std::unique_ptr<ReadBndryPlanes>& m_r2d,
const Real& c_p,
const Real& rdOcp)
{
BL_PROFILE_REGION("erf_add_moist_nudging_terms()");

const Box domain = geom.Domain();

int bdy_comp = BCVars::RhoQ1_bc_comp;
Array4<Real> bdatxlo, bdatxhi, bdatylo, bdatyhi;

// Relaxation constants
Real F1 = one/(nudge_factor*dt);

// Domain bounds
const auto& dom_hi = ubound(domain);
const auto& dom_lo = lbound(domain);
auto dx = geom.CellSizeArray();
auto ProbHi = geom.ProbHiArray();
auto ProbLo = geom.ProbLoArray();

// Time interpolation
Real dT = bdy_time_interval;

//
// Note that time (= start_time+old_stage_time) is measured as total time
// start_bdy_time and final_bdy_time are also measured as total time
//

int n_time = static_cast<int>( (time-start_bdy_time) / dT);
int n_time_p1 = n_time + 1;
Real alpha = ((time-start_bdy_time) - n_time * dT) / dT;

// Do not over run the last bdy file
if (time >= final_bdy_time) {
n_time = static_cast<int>( (final_bdy_time - start_bdy_time)/ dT);
n_time_p1 = n_time;
alpha = zero;
}

AMREX_ALWAYS_ASSERT( alpha >= zero && alpha <= one);
Real oma = one - alpha;

// Limiting offset
int offset = width - 1;

for (MFIter mfi(S_data,TilingIfNotGPU()); mfi.isValid(); ++mfi)
{
Box tbx = mfi.tilebox();

const Array4<const Real>& new_cons_const = S_data.const_array(mfi);
const Array4< Real>& src_arr = source.array(mfi);
const Array4<const Real>& cons_arr = S_data.const_array(mfi);

// We will add to source terms for moist variables and
// to source term for (rho theta)
const Array4< Real>& src_arr = source.array(mfi);

//
// Note that old_stage_time_total = start_time+old_stage_time is total time
// Note that time = start_time+old_stage_time is total time
// start_bdy_time and final_bdy_time are total time
//
moist_set_rhs(geom, tbx, new_cons_const, src_arr,
old_stage_time_total, dt,
start_bdy_time, final_bdy_time, bdy_time_interval,
bdy_factor, width, domain,
bdy_data_xlo, bdy_data_xhi,
bdy_data_ylo, bdy_data_yhi,
m_r2d);
}
// moist_set_rhs(geom, tbx, cons_arr, src_arr, n_qstate,
// old_stage_time_total, dt,
// start_bdy_time, final_bdy_time, bdy_time_interval,
// bdy_factor, width, domain,
// bdy_data_xlo, bdy_data_xhi,
// bdy_data_ylo, bdy_data_yhi,
// m_r2d);

// Get bndry data
if (m_r2d) {
Vector<std::unique_ptr<PlaneVector>>& bndry_data = m_r2d->interp_in_time(time);
bdatxlo = (*bndry_data[0])[0].array();
bdatylo = (*bndry_data[1])[0].array();
bdatxhi = (*bndry_data[3])[0].array();
bdatyhi = (*bndry_data[4])[0].array();
}

// NOTE: The sizing of the temporary BDY FABS is
// GLOBAL and occurs over the entire BDY region.

// Size the FABs
//==========================================================
// NOTE: No ghost cells, we force mask to be idx type (0,0,0)
IntVect ng_vect(0);
Box gdom(domain); gdom.grow(ng_vect);
Box bx_xlo, bx_xhi, bx_ylo, bx_yhi;
realbdy_interior_bxs_xy(gdom, domain, width,
bx_xlo, bx_xhi,
bx_ylo, bx_yhi,
ng_vect, true);

// Temporary FABs for storage (owned/filled on all ranks)
FArrayBox QV_xlo, QV_xhi, QV_ylo, QV_yhi;
QV_xlo.resize(bx_xlo,1,The_Async_Arena()); QV_xhi.resize(bx_xhi,1,The_Async_Arena());
QV_ylo.resize(bx_ylo,1,The_Async_Arena()); QV_yhi.resize(bx_yhi,1,The_Async_Arena());

// Populate FABs from bdy interpolation (primitive vars)
//==========================================================
const auto& bdatxlo_n = bdy_data_xlo[n_time ][WRFBdyVars::QV].const_array();
const auto& bdatxlo_np1 = bdy_data_xlo[n_time_p1][WRFBdyVars::QV].const_array();
const auto& bdatxhi_n = bdy_data_xhi[n_time ][WRFBdyVars::QV].const_array();
const auto& bdatxhi_np1 = bdy_data_xhi[n_time_p1][WRFBdyVars::QV].const_array();
const auto& bdatylo_n = bdy_data_ylo[n_time ][WRFBdyVars::QV].const_array();
const auto& bdatylo_np1 = bdy_data_ylo[n_time_p1][WRFBdyVars::QV].const_array();
const auto& bdatyhi_n = bdy_data_yhi[n_time ][WRFBdyVars::QV].const_array();
const auto& bdatyhi_np1 = bdy_data_yhi[n_time_p1][WRFBdyVars::QV].const_array();

// Get Array4 of interpolated values
Array4<Real> arr_xlo = QV_xlo.array(); Array4<Real> arr_xhi = QV_xhi.array();
Array4<Real> arr_ylo = QV_ylo.array(); Array4<Real> arr_yhi = QV_yhi.array();

Box gtbx = grow(tbx,ng_vect);
Box tbx_xlo, tbx_xhi, tbx_ylo, tbx_yhi;
realbdy_interior_bxs_xy(gtbx, domain, width,
tbx_xlo, tbx_xhi,
tbx_ylo, tbx_yhi,
ng_vect, true);

// Populate with interpolation (protect from ghost cells)
ParallelFor(tbx_xlo, tbx_xhi,
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{
int ii = std::min(std::max(i , dom_lo.x), dom_lo.x+offset);
int jj = std::min(std::max(j , dom_lo.y), dom_hi.y );
arr_xlo(i,j,k) = (bdatxlo) ? cons_arr(i,j,k,Rho_comp) * bdatxlo(ii,jj,k,bdy_comp) :
cons_arr(i,j,k,Rho_comp) * ( oma * bdatxlo_n (ii,jj,k)
+ alpha * bdatxlo_np1(ii,jj,k) );
} ,
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{
int ii = std::min(std::max(i , dom_hi.x-offset), dom_hi.x);
int jj = std::min(std::max(j , dom_lo.y ), dom_hi.y);
arr_xhi(i,j,k) = (bdatxhi) ? cons_arr(i,j,k,Rho_comp) * bdatxhi(ii,jj,k,bdy_comp) :
cons_arr(i,j,k,Rho_comp) * ( oma * bdatxhi_n (ii,jj,k)
+ alpha * bdatxhi_np1(ii,jj,k) );
});

ParallelFor(tbx_ylo, tbx_yhi,
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{
int ii = std::min(std::max(i , dom_lo.x), dom_hi.x );
int jj = std::min(std::max(j , dom_lo.y), dom_lo.y+offset);
arr_ylo(i,j,k) = (bdatylo) ? cons_arr(i,j,k,Rho_comp) * bdatylo(ii,jj,k,bdy_comp) :
cons_arr(i,j,k,Rho_comp) * ( oma * bdatylo_n (ii,jj,k)
+ alpha * bdatylo_np1(ii,jj,k) );
},
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{
int ii = std::min(std::max(i , dom_lo.x ), dom_hi.x);
int jj = std::min(std::max(j , dom_hi.y-offset), dom_hi.y);
jj = std::min(jj, dom_hi.y);
arr_yhi(i,j,k) = (bdatyhi) ? cons_arr(i,j,k,Rho_comp) * bdatyhi(ii,jj,k,bdy_comp) :
cons_arr(i,j,k,Rho_comp) * ( oma * bdatyhi_n (ii,jj,k)
+ alpha * bdatyhi_np1(ii,jj,k) );
});

realbdy_interior_bxs_xy(tbx, domain, width,
tbx_xlo, tbx_xhi,
tbx_ylo, tbx_yhi,
ng_vect);

//
// Add relaxation terms for moist variables and (rho theta) to existing source terms
//
realbdy_compute_relaxation(RhoQ1_comp, n_qstate,
width, dx, ProbLo, ProbHi, F1,
tbx_xlo , tbx_xhi , tbx_ylo , tbx_yhi ,
arr_xlo , arr_xhi , arr_ylo , arr_yhi ,
cons_arr, src_arr, c_p, rdOcp);
} // mfi
}
#endif
169 changes: 0 additions & 169 deletions Source/SourceTerms/ERF_MoistSetRhs.cpp

This file was deleted.

Loading
Loading