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);
108 AMREX_GPU_HOST_DEVICE
116 const int klo,
const int khi)
132 bool converged_hse =
false;
136 for (
int iter = 0; iter <
MAX_ITER && !converged_hse; iter++)
141 Real A = p_hse - p_eos;
150 if (std::abs(drho) <
TOL)
152 converged_hse =
true;
166 for (
int k = kstart; k <=
khi; k++)
170 bool converged_hse =
false;
177 for (
int iter = 0; iter <
MAX_ITER && !converged_hse; iter++)
183 Real A = p_hse - p_eos;
193 if (std::abs(drho) <
TOL * r[k-1])
195 converged_hse =
true;
218 AMREX_GPU_HOST_DEVICE
226 const int klo,
const int khi)
241 bool converged_hse =
false;
245 for (
int iter = 0; iter <
MAX_ITER && !converged_hse; iter++)
250 Real A = p_hse - p_eos;
259 if (std::abs(drho) <
TOL)
261 converged_hse =
true;
275 for (
int k = kstart; k <=
khi; k++)
279 bool converged_hse =
false;
286 for (
int iter = 0; iter <
MAX_ITER && !converged_hse; iter++)
289 Real dz_avg =
myhalf * (stretched_dz[k-1] + stretched_dz[k]);
293 Real A = p_hse - p_eos;
303 if (std::abs(drho) <
TOL * r[k-1])
305 converged_hse =
true;
330 AMREX_GPU_HOST_DEVICE
339 const amrex::Array4<amrex::Real const> z_cc,
340 const int&
klo,
const int&
khi)
354 Real myhalf_dz = z_cc(i,j,k0);
359 bool converged_hse =
false;
363 for (
int iter = 0; iter <
MAX_ITER && !converged_hse; iter++)
368 Real A = p_hse - p_eos;
374 r[k0] = r[k0] + drho;
377 if (std::abs(drho) <
TOL)
379 converged_hse =
true;
394 for (
int k = kstart; k <=
khi; k++)
398 bool converged_hse =
false;
400 Real dz_loc = (z_cc(i,j,k) - z_cc(i,j,k-1));
407 for (
int iter = 0; iter <
MAX_ITER && !converged_hse; iter++)
412 Real A = p_hse - p_eos;
421 if (std::abs(drho) <
TOL * r[k-1])
423 converged_hse =
true;
435 AMREX_GPU_HOST_DEVICE
439 return p_s *
Real(100.0);
443 AMREX_GPU_HOST_DEVICE
445 const int which_zone,
const Real scaled_height)
447 if (which_zone > 0) {
448 if (which_zone == 1) {
451 return Real(0.014)/q_s;
452 }
else if (which_zone == 2) {
453 return one -
Real(0.75)*std::pow(scaled_height,
Real(1.25));
463 AMREX_GPU_HOST_DEVICE
471 if (which_zone == 1) {
479 AMREX_GPU_HOST_DEVICE
492 AMREX_GPU_HOST_DEVICE
494 const int which_zone,
const Real scaled_height)
498 #ifdef AMREX_USE_FLOAT
503 for (
int iter=0; iter<20; iter++)
507 Real F_prime = (F_plus_dF - F)/eps;
508 delta_T = -F/F_prime;
512 if (std::fabs(delta_T) >
TOL * T_b) {
513 amrex::Abort(
"Newton Raphson for temperature could not converge");
520 AMREX_GPU_HOST_DEVICE
524 T = T_b -
Real(273.15);
527 gamma = std::log(RH*std::exp((b -
T/d)*
T/(c +
T)));
535 AMREX_GPU_HOST_DEVICE
539 if(scaled_height <=
one) {
547 AMREX_GPU_HOST_DEVICE
550 const Real scaled_height,
const bool T_from_theta,
578 AMREX_GPU_HOST_DEVICE
582 const int which_zone,
const Real scaled_height,
const bool T_from_theta,
587 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,
603 AMREX_GPU_HOST_DEVICE
607 const int which_zone,
const Real scaled_height,
const bool T_from_theta,
619 #ifdef AMREX_USE_FLOAT
620 Real eps =
Real(1.e-5) * std::abs(p_k);
625 for(
int iter=0; iter<20; iter++)
627 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,
630 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,
633 Real F_prime = (F_plus_dF - F)/eps;
634 delta_p_k = -F/F_prime;
635 p_k = p_k + delta_p_k;
643 #ifdef AMREX_USE_FLOAT
646 const Real p_rel_tol =
Real(1.e-13);
648 if (std::fabs(delta_p_k) > p_rel_tol * std::abs(p_k)) {
649 amrex::Abort(
"Newton Raphson for pressure could not converge");
675 AMREX_GPU_HOST_DEVICE
680 const bool T_from_theta =
false,
699 }
else if (
z <= z_tr_2) {
704 scaled_height =
z/z_tr_2;
707 compute_p_k_in_zone(
p[0],
p_0,
theta[0], r[0], q_v[0], T_dp, T_b,
dz,
amrex::Real(0),
q_t,
eq_pot_temp,
711 for (
int k=1; k<=
khi; k++)
719 }
else if (
z <= z_tr_2) {
724 scaled_height =
z/z_tr_2;
727 compute_p_k_in_zone(
p[k],
p[k-1],
theta[k], r[k], q_v[k], T_dp, T_b,
dz, r[k-1],
q_t,
eq_pot_temp,
constexpr amrex::Real Cp_d
Definition: ERF_Constants.H:36
constexpr amrex::Real p_0
Definition: ERF_Constants.H:53
constexpr amrex::Real iGamma
Definition: ERF_Constants.H:61
constexpr amrex::Real CONST_GRAV
Definition: ERF_Constants.H:56
constexpr amrex::Real Cp_l
Definition: ERF_Constants.H:38
constexpr amrex::Real R_d
Definition: ERF_Constants.H:34
constexpr amrex::Real L_v
Definition: ERF_Constants.H:51
constexpr amrex::Real RdoCp
Definition: ERF_Constants.H:41
constexpr amrex::Real RdoRv
Definition: ERF_Constants.H:44
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 klo
Definition: ERF_InitCustomPert_ABL.H:75
const int khi
Definition: ERF_InitCustomPert_Bubble.H:21
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
amrex::Real gamma
Definition: ERF_InitCustomPert_DataAssimilation_ISV.H:9
Real eq_pot_temp
Definition: ERF_InitCustomPert_MultiSpeciesBubble.H:23
bool use_empirical
Definition: ERF_InitCustomPert_MultiSpeciesBubble.H:25
Real T_tr
Definition: ERF_InitCustomPert_SquallLine.H:43
Real q_t
Definition: ERF_InitCustomPert_SquallLine.H:24
Real theta_tr
Definition: ERF_InitCustomPert_SquallLine.H:47
Real theta_0
Definition: ERF_InitCustomPert_SquallLine.H:46
Real z_tr
Definition: ERF_InitCustomPert_SquallLine.H:36
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:31
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:30
constexpr amrex::Real fourth
Definition: ERF_NumericalConstants.H:35
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:34
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:548
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:521
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 int klo, const int khi)
Definition: ERF_HSEUtils.H:221
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:464
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 int klo, const int khi)
Definition: ERF_HSEUtils.H:111
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE Real compute_saturation_pressure(const Real T_b, const bool use_empirical)
Definition: ERF_HSEUtils.H:436
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:604
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 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:677
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:480
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:493
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:444
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:579
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:333
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:536
@ theta
Definition: ERF_SLM.H:19
@ P
Definition: ERF_IndexDefines.H:204
@ rho
Definition: ERF_Kessler.H:25
@ qt
Definition: ERF_Kessler.H:30
@ qv
Definition: ERF_Kessler.H:31
@ T
Definition: ERF_IndexDefines.H:128
constexpr int A
Definition: ERF_TwoStreamColumn.H:603
@ dz
Definition: ERF_AdvanceWDM6.cpp:272
@ p
Definition: ERF_WSM6.H:280
Definition: ERF_ConsoleIO.cpp:15
real(c_double), parameter g
Definition: ERF_module_model_constants.F90:19