4 #include <AMReX_Math.H>
16 using namespace amrex;
20 #ifdef AMREX_USE_FLOAT
58 const bool& maintain_Th)
65 AMREX_DEVICE_PRINTF(
"ERROR: HSE Newton started from an invalid state: P = %e, rd = %e, F = %e\n",
66 double(
P),
double(rd),
double(F));
67 AMREX_DEVICE_PRINTF(
" Check the surface pressure/temperature used to seed the integration%s\n",
"");
75 while (!(std::abs(F)<=m_tol) && iter<max_iter) {
80 if (
P <
Real(1.e3)) amrex::Warning(
"P < 1000 [Pa]; Domain height may be too large...");
92 AMREX_DEVICE_PRINTF(
"WARNING: HSE Newton iterations did not converge to tolerance!\n%s",
"");
93 AMREX_DEVICE_PRINTF(
"HSE Newton tol: %e %e\n",F,m_tol);
109 AMREX_GPU_HOST_DEVICE
118 const int klo,
const int khi)
136 bool converged_hse =
false;
140 for (
int iter = 0; iter <
MAX_ITER && !converged_hse; iter++)
145 Real A = p_hse - p_eos;
154 if (std::abs(drho) <
TOL)
156 converged_hse =
true;
170 for (
int k = kstart; k <=
khi; k++)
174 bool converged_hse =
false;
181 for (
int iter = 0; iter <
MAX_ITER && !converged_hse; iter++)
187 Real A = p_hse - p_eos;
197 if (std::abs(drho) <
TOL * r[k-1])
199 converged_hse =
true;
223 AMREX_GPU_HOST_DEVICE
232 const int klo,
const int khi)
250 bool converged_hse =
false;
254 for (
int iter = 0; iter <
MAX_ITER && !converged_hse; iter++)
259 Real A = p_hse - p_eos;
268 if (std::abs(drho) <
TOL)
270 converged_hse =
true;
284 for (
int k = kstart; k <=
khi; k++)
288 bool converged_hse =
false;
295 for (
int iter = 0; iter <
MAX_ITER && !converged_hse; iter++)
298 Real dz_avg =
myhalf * (stretched_dz[k-1] + stretched_dz[k]);
302 Real A = p_hse - p_eos;
312 if (std::abs(drho) <
TOL * r[k-1])
314 converged_hse =
true;
339 AMREX_GPU_HOST_DEVICE
348 const amrex::Array4<amrex::Real const> z_cc,
349 const int&
klo,
const int&
khi)
365 Real myhalf_dz = z_cc(i,j,k0);
370 bool converged_hse =
false;
374 for (
int iter = 0; iter <
MAX_ITER && !converged_hse; iter++)
379 Real A = p_hse - p_eos;
385 r[k0] = r[k0] + drho;
388 if (std::abs(drho) <
TOL)
390 converged_hse =
true;
405 for (
int k = kstart; k <=
khi; k++)
409 bool converged_hse =
false;
411 Real dz_loc = (z_cc(i,j,k) - z_cc(i,j,k-1));
418 for (
int iter = 0; iter <
MAX_ITER && !converged_hse; iter++)
423 Real A = p_hse - p_eos;
432 if (std::abs(drho) <
TOL * r[k-1])
434 converged_hse =
true;
446 AMREX_GPU_HOST_DEVICE
450 return p_s *
Real(100.0);
454 AMREX_GPU_HOST_DEVICE
456 const int which_zone,
const Real scaled_height)
458 if (which_zone > 0) {
459 if (which_zone == 1) {
462 return Real(0.014)/q_s;
463 }
else if (which_zone == 2) {
464 return one -
Real(0.75)*std::pow(scaled_height,
Real(1.25));
474 AMREX_GPU_HOST_DEVICE
482 if (which_zone == 1) {
490 AMREX_GPU_HOST_DEVICE
501 Real H = amrex::max(
Real(1.e-10), amrex::min(
Real(1.0), RH));
503 *std::exp(-(q_v*
R_v/fac)*std::log(
H))
504 *std::exp(
L_v*q_v/(fac*T_b));
508 AMREX_GPU_HOST_DEVICE
510 const int which_zone,
const Real scaled_height)
514 #ifdef AMREX_USE_FLOAT
519 for (
int iter=0; iter<20; iter++)
523 Real F_prime = (F_plus_dF - F)/eps;
524 delta_T = -F/F_prime;
528 if (std::fabs(delta_T) >
TOL * T_b) {
529 amrex::Abort(
"Newton Raphson for temperature could not converge");
536 AMREX_GPU_HOST_DEVICE
540 T = T_b -
Real(273.15);
543 gamma = std::log(RH*std::exp((b -
T/d)*
T/(c +
T)));
551 AMREX_GPU_HOST_DEVICE
555 if(scaled_height <=
one) {
563 AMREX_GPU_HOST_DEVICE
566 const Real scaled_height,
const bool T_from_theta,
594 AMREX_GPU_HOST_DEVICE
598 const int which_zone,
const Real scaled_height,
const bool T_from_theta,
603 compute_rho(p_k, theta_k, rho_k, q_v_k, T_dp, T_b,
q_t,
eq_pot_temp,
use_empirical, which_zone, scaled_height,
619 AMREX_GPU_HOST_DEVICE
623 const int which_zone,
const Real scaled_height,
const bool T_from_theta,
635 #ifdef AMREX_USE_FLOAT
636 Real eps =
Real(1.e-5) * std::abs(p_k);
641 for(
int iter=0; iter<20; iter++)
643 Real F =
compute_F(p_k , p_k_minus_1, theta_k, rho_k, q_v_k, T_dp, T_b,
dz, rho_k_minus_1,
646 Real F_plus_dF =
compute_F(p_k+eps, p_k_minus_1, theta_k, rho_k, q_v_k, T_dp, T_b,
dz, rho_k_minus_1,
649 Real F_prime = (F_plus_dF - F)/eps;
650 delta_p_k = -F/F_prime;
651 p_k = p_k + delta_p_k;
659 #ifdef AMREX_USE_FLOAT
662 const Real p_rel_tol =
Real(1.e-13);
664 if (std::fabs(delta_p_k) > p_rel_tol * std::abs(p_k)) {
665 amrex::Abort(
"Newton Raphson for pressure could not converge");
683 template <
typename ZccFunc,
typename DzFunc>
685 AMREX_GPU_HOST_DEVICE
688 ZccFunc
const& z_cc, DzFunc
const& dz_cc,
691 const bool T_from_theta,
692 const Real z_tr_1,
const Real z_tr_2,
710 }
else if (
z <= z_tr_2) {
715 scaled_height =
z/z_tr_2;
718 compute_p_k_in_zone(
p[0],
p_0,
theta[0], r[0], q_v[0], T_dp, T_b, dz_cc(0),
amrex::Real(0),
q_t,
eq_pot_temp,
722 for (
int k=1; k<=
khi; k++)
730 }
else if (
z <= z_tr_2) {
735 scaled_height =
z/z_tr_2;
738 compute_p_k_in_zone(
p[k],
p[k-1],
theta[k], r[k], q_v[k], T_dp, T_b, dz_cc(k), r[k-1],
q_t,
eq_pot_temp,
767 AMREX_GPU_HOST_DEVICE
772 const bool T_from_theta =
false,
778 [=] (
int k) {
return (k == 0) ?
two * (z_bot +
myhalf *
dz) :
dz; },
792 AMREX_GPU_HOST_DEVICE
797 const bool T_from_theta =
false,
801 auto z_cc = [=] (
int k) {
return myhalf * (zlevels[k] + zlevels[k+1]) - zlevels[0]; };
804 [=] (
int k) {
return (k == 0) ? zlevels[0] + zlevels[1] : z_cc(k) - z_cc(k-1); },
constexpr amrex::Real R_v
Definition: ERF_Constants.H:50
constexpr amrex::Real Cp_d
Definition: ERF_Constants.H:51
constexpr amrex::Real p_0
Definition: ERF_Constants.H:69
constexpr amrex::Real iGamma
Definition: ERF_Constants.H:77
constexpr amrex::Real CONST_GRAV
Definition: ERF_Constants.H:72
constexpr amrex::Real Cp_l
Definition: ERF_Constants.H:53
constexpr amrex::Real R_d
Definition: ERF_Constants.H:49
constexpr amrex::Real L_v
Definition: ERF_Constants.H:67
constexpr amrex::Real RdoCp
Definition: ERF_Constants.H:57
constexpr amrex::Real RdoRv
Definition: ERF_Constants.H:60
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getdPdRgivenConstantTheta(const amrex::Real rho, const amrex::Real theta, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:127
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getRhogivenThetaPress(const amrex::Real th, const amrex::Real p, const amrex::Real rdOcp, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:96
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real compute_vapor_pressure(const amrex::Real p_s, const amrex::Real RH)
Definition: ERF_EOS.H:181
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getRhogivenTandPress(const amrex::Real T, const amrex::Real p, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:113
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getThgivenTandP(const amrex::Real T, const amrex::Real P, const amrex::Real rdOcp)
Definition: ERF_EOS.H:18
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getPgivenRTh(const amrex::Real rhotheta, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:81
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getTgivenPandTh(const amrex::Real P, const amrex::Real th, const amrex::Real rdOcp)
Definition: ERF_EOS.H:32
const int khi
Definition: ERF_InitCustomPert_Bubble.H:25
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
amrex::Real gamma
Definition: ERF_InitCustomPert_DataAssimilation_ISV.H:9
const int klo
Definition: ERF_InitCustomPert_KE.H:9
Real H
Definition: ERF_InitCustomPert_MovingTerrain.H:8
Real eq_pot_temp
Definition: ERF_InitCustomPert_MultiSpeciesBubble.H:27
bool use_empirical
Definition: ERF_InitCustomPert_MultiSpeciesBubble.H:29
Real T_tr
Definition: ERF_InitCustomPert_SquallLine.H:47
Real q_t
Definition: ERF_InitCustomPert_SquallLine.H:28
Real theta_tr
Definition: ERF_InitCustomPert_SquallLine.H:51
Real theta_0
Definition: ERF_InitCustomPert_SquallLine.H:50
Real z_tr
Definition: ERF_InitCustomPert_SquallLine.H:40
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_esatw(amrex::Real t, bool use_empirical=false)
Definition: ERF_MicrophysicsUtils.H:159
constexpr amrex::Real two
Definition: ERF_NumericalConstants.H:38
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
constexpr amrex::Real fourth
Definition: ERF_NumericalConstants.H:42
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
amrex::Real Real
Definition: ERF_ShocInterface.H:19
Definition: ERF_HSEUtils.H:15
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE void compute_rho(const Real &pressure, Real &theta, Real &rho, Real &q_v, Real &T_dp, Real &T_b, const Real q_t, const Real eq_pot_temp, const bool use_empirical, const int which_zone, const Real scaled_height, const bool T_from_theta, const Real theta_0, const Real theta_tr, const Real z_tr, const Real T_tr)
Definition: ERF_HSEUtils.H:564
const int MAX_ITER
Definition: ERF_HSEUtils.H:19
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE Real compute_dewpoint_temperature(const Real T_b, const Real RH)
Definition: ERF_HSEUtils.H:537
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE Real vapor_mixing_ratio(const Real p_b, const Real T_b, const Real RH, const bool use_empirical, int which_zone)
Definition: ERF_HSEUtils.H:475
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE void init_isentropic_hse_no_terrain_column(Real *theta, Real *r, Real *p, Real *q_v, ZccFunc const &z_cc, DzFunc const &dz_cc, const int &khi, const Real q_t, const Real eq_pot_temp, const bool use_empirical, const bool T_from_theta, const Real z_tr_1, const Real z_tr_2, const Real theta_0, const Real theta_tr, const Real T_tr)
Definition: ERF_HSEUtils.H:687
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE Real compute_saturation_pressure(const Real T_b, const bool use_empirical)
Definition: ERF_HSEUtils.H:447
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE Real compute_p_k_in_zone(Real &p_k, const Real p_k_minus_1, Real &theta_k, Real &rho_k, Real &q_v_k, Real &T_dp, Real &T_b, const Real dz, const Real rho_k_minus_1, const Real q_t, const Real eq_pot_temp, const bool use_empirical, const int which_zone, const Real scaled_height, const bool T_from_theta, const Real theta_0, const Real theta_tr, const Real z_tr, const Real T_tr)
Definition: ERF_HSEUtils.H:620
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void init_isentropic_hse_constant_dz(const amrex::Real &r_sfc, const amrex::Real &theta, amrex::Real *r, amrex::Real *p, const amrex::Real &dz, const amrex::Real &z_bot, const int klo, const int khi)
Definition: ERF_HSEUtils.H:112
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void init_isentropic_hse_stretched_dz(const amrex::Real &r_sfc, const amrex::Real &theta, amrex::Real *r, amrex::Real *p, const amrex::Real *stretched_dz, const amrex::Real &z_bot, const int klo, const int khi)
Definition: ERF_HSEUtils.H:226
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE Real compute_F_for_temp_in_zone(const Real T_b, const Real p_b, const Real q_t, const Real eq_pot_temp, const bool use_empirical, const int which_zone, const Real scaled_height)
Definition: ERF_HSEUtils.H:491
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE Real compute_temperature(const Real p_b, const Real q_t, const Real eq_pot_temp, const bool use_empirical, const int which_zone, const Real scaled_height)
Definition: ERF_HSEUtils.H:509
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE Real compute_relative_humidity(const Real p_b, const Real T_b, const bool use_empirical, const int which_zone, const Real scaled_height)
Definition: ERF_HSEUtils.H:455
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE Real compute_F(const Real &p_k, const Real &p_k_minus_1, Real &theta_k, Real &rho_k, Real &q_v_k, Real &T_dp, Real &T_b, const Real &dz, const Real &rho_k_minus_1, const Real q_t, const Real eq_pot_temp, const bool use_empirical, const int which_zone, const Real scaled_height, const bool T_from_theta, const Real theta_0, const Real theta_tr, const Real z_tr, const Real T_tr)
Definition: ERF_HSEUtils.H:595
const amrex::Real TOL
Definition: ERF_HSEUtils.H:23
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void init_isentropic_hse_terrain(int i, int j, const amrex::Real &r_sfc, const amrex::Real &theta, amrex::Real *r, amrex::Real *p, const amrex::Array4< amrex::Real const > z_cc, const int &klo, const int &khi)
Definition: ERF_HSEUtils.H:342
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void Newton_Raphson_hse(const Real &m_tol, const Real &RdoCp, const Real &dz, const Real &g, const Real &C, const Real &Th, const Real &T, const Real &qt, const Real &qv, Real &P, Real &rd, Real &F, const bool &maintain_Th)
Definition: ERF_HSEUtils.H:46
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE Real compute_theta(const Real scaled_height, const Real theta_0, const Real theta_tr, const Real z_tr, const Real T_tr)
Definition: ERF_HSEUtils.H:552
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE void init_isentropic_hse_no_terrain(Real *theta, Real *r, Real *p, Real *q_v, const Real &dz, const Real &z_bot, const int &khi, const Real q_t, const Real eq_pot_temp, const bool use_empirical, const bool T_from_theta=false, const Real z_tr_1=-one, const Real z_tr_2=-one, const Real theta_0=amrex::Real(300), const Real theta_tr=amrex::Real(300), const Real T_tr=amrex::Real(300))
Definition: ERF_HSEUtils.H:769
@ P
Definition: ERF_IndexDefines.H:244
@ rho
Definition: ERF_Kessler.H:25
@ theta
Definition: ERF_Kessler.H:26
@ qt
Definition: ERF_Kessler.H:30
@ qv
Definition: ERF_Kessler.H:31
@ T
Definition: ERF_IndexDefines.H:168
constexpr int A
Definition: ERF_TwoStreamColumn.H:603
@ dz
Definition: ERF_AdvanceWDM6.cpp:273
@ p
Definition: ERF_WSM6.H:301
Definition: ERF_ConsoleIO.cpp:17
real(c_double), parameter g
Definition: ERF_module_model_constants.F90:19