Skip to content

Commit

Permalink
Pass the current CC vars to init_custom_pert so that rebalancing may …
Browse files Browse the repository at this point in the history
…be done with large perturbations. (#1493)

Co-authored-by: Aaron Lattanzi <[email protected]>
  • Loading branch information
AMLattanzi and Aaron Lattanzi authored Mar 13, 2024
1 parent c866153 commit e56589c
Show file tree
Hide file tree
Showing 58 changed files with 694 additions and 635 deletions.
9 changes: 5 additions & 4 deletions Exec/ABL/prob.H
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ public:
const amrex::Box& xbx,
const amrex::Box& ybx,
const amrex::Box& zbx,
amrex::Array4<amrex::Real > const& state,
amrex::Array4<amrex::Real > const& x_vel,
amrex::Array4<amrex::Real > const& y_vel,
amrex::Array4<amrex::Real > const& z_vel,
amrex::Array4<amrex::Real const> const& state,
amrex::Array4<amrex::Real > const& state_pert,
amrex::Array4<amrex::Real > const& x_vel_pert,
amrex::Array4<amrex::Real > const& y_vel_pert,
amrex::Array4<amrex::Real > const& z_vel_pert,
amrex::Array4<amrex::Real > const& r_hse,
amrex::Array4<amrex::Real > const& p_hse,
amrex::Array4<amrex::Real const> const& z_nd,
Expand Down
47 changes: 24 additions & 23 deletions Exec/ABL/prob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ Problem::init_custom_pert(
const amrex::Box& xbx,
const amrex::Box& ybx,
const amrex::Box& zbx,
amrex::Array4<amrex::Real > const& state,
amrex::Array4<amrex::Real > const& x_vel,
amrex::Array4<amrex::Real > const& y_vel,
amrex::Array4<amrex::Real > const& z_vel,
amrex::Array4<amrex::Real const> const& /*state*/,
amrex::Array4<amrex::Real > const& state_pert,
amrex::Array4<amrex::Real > const& x_vel_pert,
amrex::Array4<amrex::Real > const& y_vel_pert,
amrex::Array4<amrex::Real > const& z_vel_pert,
amrex::Array4<amrex::Real > const& r_hse,
amrex::Array4<amrex::Real > const& /*p_hse*/,
amrex::Array4<amrex::Real const> const& z_nd,
Expand Down Expand Up @@ -116,41 +117,41 @@ Problem::init_custom_pert(
// Add temperature perturbations
if ((z <= parms.pert_ref_height) && (parms.T_0_Pert_Mag != 0.0)) {
Real rand_double = amrex::Random(engine); // Between 0.0 and 1.0
state(i, j, k, RhoTheta_comp) = (rand_double*2.0 - 1.0)*parms.T_0_Pert_Mag;
state_pert(i, j, k, RhoTheta_comp) = (rand_double*2.0 - 1.0)*parms.T_0_Pert_Mag;
if (!parms.pert_rhotheta) {
// we're perturbing theta, not rho*theta
state(i, j, k, RhoTheta_comp) *= r_hse(i,j,k);
state_pert(i, j, k, RhoTheta_comp) *= r_hse(i,j,k);
}
}

// Set scalar = A_0*exp(-10r^2), where r is distance from center of domain
state(i, j, k, RhoScalar_comp) = parms.A_0 * exp(-10.*r*r);
state_pert(i, j, k, RhoScalar_comp) = parms.A_0 * exp(-10.*r*r);

// Set an initial value for SGS KE
if (state.nComp() > RhoKE_comp) {
if (state_pert.nComp() > RhoKE_comp) {
// Deardorff
state(i, j, k, RhoKE_comp) = r_hse(i,j,k) * parms.KE_0;
state_pert(i, j, k, RhoKE_comp) = r_hse(i,j,k) * parms.KE_0;
if (parms.KE_decay_height > 0) {
// scale initial SGS kinetic energy with height
state(i, j, k, RhoKE_comp) *= max(
state_pert(i, j, k, RhoKE_comp) *= max(
std::pow(1 - min(z/parms.KE_decay_height,1.0), parms.KE_decay_order),
1e-12);
}
}
if (state.nComp() > RhoQKE_comp) {
if (state_pert.nComp() > RhoQKE_comp) {
// PBL
state(i, j, k, RhoQKE_comp) = r_hse(i,j,k) * parms.QKE_0;
state_pert(i, j, k, RhoQKE_comp) = r_hse(i,j,k) * parms.QKE_0;
if (parms.KE_decay_height > 0) {
// scale initial SGS kinetic energy with height
state(i, j, k, RhoQKE_comp) *= max(
state_pert(i, j, k, RhoQKE_comp) *= max(
std::pow(1 - min(z/parms.KE_decay_height,1.0), parms.KE_decay_order),
1e-12);
}
}

if (use_moisture) {
state(i, j, k, RhoQ1_comp) = 0.0;
state(i, j, k, RhoQ2_comp) = 0.0;
state_pert(i, j, k, RhoQ1_comp) = 0.0;
state_pert(i, j, k, RhoQ2_comp) = 0.0;
}
});

Expand All @@ -164,19 +165,19 @@ Problem::init_custom_pert(
: prob_lo[2] + (k + 0.5) * dx[2];

// Set the x-velocity
x_vel(i, j, k) = parms.U_0;
x_vel_pert(i, j, k) = parms.U_0;
if ((z <= parms.pert_ref_height) && (parms.U_0_Pert_Mag != 0.0))
{
Real rand_double = amrex::Random(engine); // Between 0.0 and 1.0
Real x_vel_prime = (rand_double*2.0 - 1.0)*parms.U_0_Pert_Mag;
x_vel(i, j, k) += x_vel_prime;
x_vel_pert(i, j, k) += x_vel_prime;
}
if (parms.pert_deltaU != 0.0)
{
const amrex::Real yl = y - prob_lo[1];
const amrex::Real zl = z / parms.pert_ref_height;
const amrex::Real damp = std::exp(-0.5 * zl * zl);
x_vel(i, j, k) += parms.ufac * damp * z * std::cos(parms.aval * yl);
x_vel_pert(i, j, k) += parms.ufac * damp * z * std::cos(parms.aval * yl);
}
});

Expand All @@ -190,19 +191,19 @@ Problem::init_custom_pert(
: prob_lo[2] + (k + 0.5) * dx[2];

// Set the y-velocity
y_vel(i, j, k) = parms.V_0;
y_vel_pert(i, j, k) = parms.V_0;
if ((z <= parms.pert_ref_height) && (parms.V_0_Pert_Mag != 0.0))
{
Real rand_double = amrex::Random(engine); // Between 0.0 and 1.0
Real y_vel_prime = (rand_double*2.0 - 1.0)*parms.V_0_Pert_Mag;
y_vel(i, j, k) += y_vel_prime;
y_vel_pert(i, j, k) += y_vel_prime;
}
if (parms.pert_deltaV != 0.0)
{
const amrex::Real xl = x - prob_lo[0];
const amrex::Real zl = z / parms.pert_ref_height;
const amrex::Real damp = std::exp(-0.5 * zl * zl);
y_vel(i, j, k) += parms.vfac * damp * z * std::cos(parms.bval * xl);
y_vel_pert(i, j, k) += parms.vfac * damp * z * std::cos(parms.bval * xl);
}
});

Expand All @@ -214,13 +215,13 @@ Problem::init_custom_pert(
// Set the z-velocity
if (k == dom_lo_z || k == dom_hi_z+1)
{
z_vel(i, j, k) = 0.0;
z_vel_pert(i, j, k) = 0.0;
}
else if (parms.W_0_Pert_Mag != 0.0)
{
Real rand_double = amrex::Random(engine); // Between 0.0 and 1.0
Real z_vel_prime = (rand_double*2.0 - 1.0)*parms.W_0_Pert_Mag;
z_vel(i, j, k) = parms.W_0 + z_vel_prime;
z_vel_pert(i, j, k) = parms.W_0 + z_vel_prime;
}
});
}
9 changes: 5 additions & 4 deletions Exec/ABL_input_sounding/prob.H
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ public:
const amrex::Box& xbx,
const amrex::Box& ybx,
const amrex::Box& zbx,
amrex::Array4<amrex::Real > const& state,
amrex::Array4<amrex::Real > const& x_vel,
amrex::Array4<amrex::Real > const& y_vel,
amrex::Array4<amrex::Real > const& z_vel,
amrex::Array4<amrex::Real const> const& state,
amrex::Array4<amrex::Real > const& state_pert,
amrex::Array4<amrex::Real > const& x_vel_pert,
amrex::Array4<amrex::Real > const& y_vel_pert,
amrex::Array4<amrex::Real > const& z_vel_pert,
amrex::Array4<amrex::Real > const& r_hse,
amrex::Array4<amrex::Real > const& p_hse,
amrex::Array4<amrex::Real const> const& z_nd,
Expand Down
33 changes: 17 additions & 16 deletions Exec/ABL_input_sounding/prob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ Problem::init_custom_pert(
const amrex::Box& xbx,
const amrex::Box& ybx,
const amrex::Box& zbx,
amrex::Array4<amrex::Real > const& state,
amrex::Array4<amrex::Real > const& x_vel,
amrex::Array4<amrex::Real > const& y_vel,
amrex::Array4<amrex::Real > const& z_vel,
amrex::Array4<amrex::Real const> const& /*state*/,
amrex::Array4<amrex::Real > const& state_pert,
amrex::Array4<amrex::Real > const& x_vel_pert,
amrex::Array4<amrex::Real > const& y_vel_pert,
amrex::Array4<amrex::Real > const& z_vel_pert,
amrex::Array4<amrex::Real > const& /*r_hse*/,
amrex::Array4<amrex::Real > const& /*p_hse*/,
amrex::Array4<amrex::Real const> const& /*z_nd*/,
Expand Down Expand Up @@ -80,14 +81,14 @@ Problem::init_custom_pert(
const Real r = std::sqrt((x-xc)*(x-xc) + (y-yc)*(y-yc) + (z-zc)*(z-zc));

// Set scalar = A_0*exp(-10r^2), where r is distance from center of domain
state(i, j, k, RhoScalar_comp) = parms.A_0 * exp(-10.*r*r);
state_pert(i, j, k, RhoScalar_comp) = parms.A_0 * exp(-10.*r*r);

// Set an initial value for QKE
state(i, j, k, RhoQKE_comp) = parms.QKE_0;
state_pert(i, j, k, RhoQKE_comp) = parms.QKE_0;

if (use_moisture) {
state(i, j, k, RhoQ1_comp) = 0.0;
state(i, j, k, RhoQ2_comp) = 0.0;
state_pert(i, j, k, RhoQ1_comp) = 0.0;
state_pert(i, j, k, RhoQ2_comp) = 0.0;
}
});

Expand All @@ -99,19 +100,19 @@ Problem::init_custom_pert(
const Real z = prob_lo[2] + (k + 0.5) * dx[2];

// Set the x-velocity
x_vel(i, j, k) = parms.U_0;
x_vel_pert(i, j, k) = parms.U_0;
if ((z <= parms.pert_ref_height) && (parms.U_0_Pert_Mag != 0.0))
{
Real rand_double = amrex::Random(engine); // Between 0.0 and 1.0
Real x_vel_prime = (rand_double*2.0 - 1.0)*parms.U_0_Pert_Mag;
x_vel(i, j, k) += x_vel_prime;
x_vel_pert(i, j, k) += x_vel_prime;
}
if (parms.pert_deltaU != 0.0)
{
const amrex::Real yl = y - prob_lo[1];
const amrex::Real zl = z / parms.pert_ref_height;
const amrex::Real damp = std::exp(-0.5 * zl * zl);
x_vel(i, j, k) += parms.ufac * damp * z * std::cos(parms.aval * yl);
x_vel_pert(i, j, k) += parms.ufac * damp * z * std::cos(parms.aval * yl);
}
});

Expand All @@ -123,19 +124,19 @@ Problem::init_custom_pert(
const Real z = prob_lo[2] + (k + 0.5) * dx[2];

// Set the y-velocity
y_vel(i, j, k) = parms.V_0;
y_vel_pert(i, j, k) = parms.V_0;
if ((z <= parms.pert_ref_height) && (parms.V_0_Pert_Mag != 0.0))
{
Real rand_double = amrex::Random(engine); // Between 0.0 and 1.0
Real y_vel_prime = (rand_double*2.0 - 1.0)*parms.V_0_Pert_Mag;
y_vel(i, j, k) += y_vel_prime;
y_vel_pert(i, j, k) += y_vel_prime;
}
if (parms.pert_deltaV != 0.0)
{
const amrex::Real xl = x - prob_lo[0];
const amrex::Real zl = z / parms.pert_ref_height;
const amrex::Real damp = std::exp(-0.5 * zl * zl);
y_vel(i, j, k) += parms.vfac * damp * z * std::cos(parms.bval * xl);
y_vel_pert(i, j, k) += parms.vfac * damp * z * std::cos(parms.bval * xl);
}
});

Expand All @@ -148,13 +149,13 @@ Problem::init_custom_pert(
// Set the z-velocity
if (k == dom_lo_z || k == dom_hi_z+1)
{
z_vel(i, j, k) = 0.0;
z_vel_pert(i, j, k) = 0.0;
}
else if (parms.W_0_Pert_Mag != 0.0)
{
Real rand_double = amrex::Random(engine); // Between 0.0 and 1.0
Real z_vel_prime = (rand_double*2.0 - 1.0)*parms.W_0_Pert_Mag;
z_vel(i, j, k) = parms.W_0 + z_vel_prime;
z_vel_pert(i, j, k) = parms.W_0 + z_vel_prime;
}
});
}
9 changes: 5 additions & 4 deletions Exec/DevTests/Bomex/prob.H
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ public:
const amrex::Box& xbx,
const amrex::Box& ybx,
const amrex::Box& zbx,
amrex::Array4<amrex::Real > const& state,
amrex::Array4<amrex::Real > const& x_vel,
amrex::Array4<amrex::Real > const& y_vel,
amrex::Array4<amrex::Real > const& z_vel,
amrex::Array4<amrex::Real const> const& state,
amrex::Array4<amrex::Real > const& state_pert,
amrex::Array4<amrex::Real > const& x_vel_pert,
amrex::Array4<amrex::Real > const& y_vel_pert,
amrex::Array4<amrex::Real > const& z_vel_pert,
amrex::Array4<amrex::Real > const& r_hse,
amrex::Array4<amrex::Real > const& p_hse,
amrex::Array4<amrex::Real const> const& z_nd,
Expand Down
35 changes: 18 additions & 17 deletions Exec/DevTests/Bomex/prob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ Problem::init_custom_pert (
const amrex::Box& xbx,
const amrex::Box& ybx,
const amrex::Box& zbx,
amrex::Array4<amrex::Real > const& state,
amrex::Array4<amrex::Real > const& x_vel,
amrex::Array4<amrex::Real > const& y_vel,
amrex::Array4<amrex::Real > const& z_vel,
amrex::Array4<amrex::Real const> const& /*state*/,
amrex::Array4<amrex::Real > const& state_pert,
amrex::Array4<amrex::Real > const& x_vel_pert,
amrex::Array4<amrex::Real > const& y_vel_pert,
amrex::Array4<amrex::Real > const& z_vel_pert,
amrex::Array4<amrex::Real > const& /*r_hse*/,
amrex::Array4<amrex::Real > const& /*p_hse*/,
amrex::Array4<amrex::Real const> const& /*z_nd*/,
Expand Down Expand Up @@ -100,18 +101,18 @@ Problem::init_custom_pert (
// Add temperature perturbations
if ((z <= parms.pert_ref_height) && (parms.T_0_Pert_Mag != 0.0)) {
Real rand_double = amrex::Random(engine); // Between 0.0 and 1.0
state(i, j, k, RhoTheta_comp) = (rand_double*2.0 - 1.0)*parms.T_0_Pert_Mag;
state_pert(i, j, k, RhoTheta_comp) = (rand_double*2.0 - 1.0)*parms.T_0_Pert_Mag;
}

// Set scalar = A_0*exp(-10r^2), where r is distance from center of domain
state(i, j, k, RhoScalar_comp) = parms.A_0 * exp(-10.*r*r);
state_pert(i, j, k, RhoScalar_comp) = parms.A_0 * exp(-10.*r*r);

// Set an initial value for QKE
state(i, j, k, RhoQKE_comp) = parms.QKE_0;
state_pert(i, j, k, RhoQKE_comp) = parms.QKE_0;

if (use_moisture) {
state(i, j, k, RhoQ1_comp) = 0.0;
state(i, j, k, RhoQ2_comp) = 0.0;
state_pert(i, j, k, RhoQ1_comp) = 0.0;
state_pert(i, j, k, RhoQ2_comp) = 0.0;
}
});

Expand All @@ -124,19 +125,19 @@ Problem::init_custom_pert (
const Real z = prob_lo[2] + (k + 0.5) * dx[2];

// Set the x-velocity
x_vel(i, j, k) = parms.U_0;
x_vel_pert(i, j, k) = parms.U_0;
if ((z <= parms.pert_ref_height) && (parms.U_0_Pert_Mag != 0.0))
{
Real rand_double = amrex::Random(engine); // Between 0.0 and 1.0
Real x_vel_prime = (rand_double*2.0 - 1.0)*parms.U_0_Pert_Mag;
x_vel(i, j, k) += x_vel_prime;
x_vel_pert(i, j, k) += x_vel_prime;
}
if (parms.pert_deltaU != 0.0)
{
const amrex::Real yl = y - prob_lo[1];
const amrex::Real zl = z / parms.pert_ref_height;
const amrex::Real damp = std::exp(-0.5 * zl * zl);
x_vel(i, j, k) += parms.ufac * damp * z * std::cos(parms.aval * yl);
x_vel_pert(i, j, k) += parms.ufac * damp * z * std::cos(parms.aval * yl);
}
});

Expand All @@ -149,19 +150,19 @@ Problem::init_custom_pert (
const Real z = prob_lo[2] + (k + 0.5) * dx[2];

// Set the y-velocity
y_vel(i, j, k) = parms.V_0;
y_vel_pert(i, j, k) = parms.V_0;
if ((z <= parms.pert_ref_height) && (parms.V_0_Pert_Mag != 0.0))
{
Real rand_double = amrex::Random(engine); // Between 0.0 and 1.0
Real y_vel_prime = (rand_double*2.0 - 1.0)*parms.V_0_Pert_Mag;
y_vel(i, j, k) += y_vel_prime;
y_vel_pert(i, j, k) += y_vel_prime;
}
if (parms.pert_deltaV != 0.0)
{
const amrex::Real xl = x - prob_lo[0];
const amrex::Real zl = z / parms.pert_ref_height;
const amrex::Real damp = std::exp(-0.5 * zl * zl);
y_vel(i, j, k) += parms.vfac * damp * z * std::cos(parms.bval * xl);
y_vel_pert(i, j, k) += parms.vfac * damp * z * std::cos(parms.bval * xl);
}
});

Expand All @@ -174,13 +175,13 @@ Problem::init_custom_pert (
// Set the z-velocity
if (k == dom_lo_z || k == dom_hi_z+1)
{
z_vel(i, j, k) = 0.0;
z_vel_pert(i, j, k) = 0.0;
}
else if (parms.W_0_Pert_Mag != 0.0)
{
Real rand_double = amrex::Random(engine); // Between 0.0 and 1.0
Real z_vel_prime = (rand_double*2.0 - 1.0)*parms.W_0_Pert_Mag;
z_vel(i, j, k) = parms.W_0 + z_vel_prime;
z_vel_pert(i, j, k) = parms.W_0 + z_vel_prime;
}
});
}
Expand Down
9 changes: 5 additions & 4 deletions Exec/DevTests/MiguelDev/prob.H
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ public:
const amrex::Box& xbx,
const amrex::Box& ybx,
const amrex::Box& zbx,
amrex::Array4<amrex::Real > const& state,
amrex::Array4<amrex::Real > const& x_vel,
amrex::Array4<amrex::Real > const& y_vel,
amrex::Array4<amrex::Real > const& z_vel,
amrex::Array4<amrex::Real const> const& state,
amrex::Array4<amrex::Real > const& state_pert,
amrex::Array4<amrex::Real > const& x_vel_pert,
amrex::Array4<amrex::Real > const& y_vel_pert,
amrex::Array4<amrex::Real > const& z_vel_pert,
amrex::Array4<amrex::Real > const& r_hse,
amrex::Array4<amrex::Real > const& p_hse,
amrex::Array4<amrex::Real const> const& z_nd,
Expand Down
Loading

0 comments on commit e56589c

Please sign in to comment.