14 using namespace amrex;
18 #ifdef AMREX_USE_FLOAT
56 const bool& maintain_Th)
63 AMREX_DEVICE_PRINTF(
"ERROR: HSE Newton started from an invalid state: P = %e, rd = %e, F = %e\n",
64 double(
P),
double(rd),
double(F));
65 AMREX_DEVICE_PRINTF(
" Check the surface pressure/temperature used to seed the integration%s\n",
"");
73 while (!(std::abs(F)<=m_tol) && iter<max_iter) {
78 if (
P <
Real(1.e3)) amrex::Warning(
"P < 1000 [Pa]; Domain height may be too large...");
90 AMREX_DEVICE_PRINTF(
"WARNING: HSE Newton iterations did not converge to tolerance!\n%s",
"");
91 AMREX_DEVICE_PRINTF(
"HSE Newton tol: %e %e\n",F,m_tol);
106 AMREX_GPU_HOST_DEVICE
114 const int klo,
const int khi)
130 bool converged_hse =
false;
134 for (
int iter = 0; iter <
MAX_ITER && !converged_hse; iter++)
139 Real A = p_hse - p_eos;
145 r[klo] = r[klo] + drho;
148 if (std::abs(drho) <
TOL)
150 converged_hse =
true;
164 for (
int k = kstart; k <=
khi; k++)
168 bool converged_hse =
false;
175 for (
int iter = 0; iter <
MAX_ITER && !converged_hse; iter++)
181 Real A = p_hse - p_eos;
191 if (std::abs(drho) <
TOL * r[k-1])
193 converged_hse =
true;
216 AMREX_GPU_HOST_DEVICE
224 const int klo,
const int khi)
239 bool converged_hse =
false;
243 for (
int iter = 0; iter <
MAX_ITER && !converged_hse; iter++)
248 Real A = p_hse - p_eos;
254 r[klo] = r[klo] + drho;
257 if (std::abs(drho) <
TOL)
259 converged_hse =
true;
273 for (
int k = kstart; k <=
khi; k++)
277 bool converged_hse =
false;
284 for (
int iter = 0; iter <
MAX_ITER && !converged_hse; iter++)
287 Real dz_avg =
myhalf * (stretched_dz[k-1] + stretched_dz[k]);
291 Real A = p_hse - p_eos;
301 if (std::abs(drho) <
TOL * r[k-1])
303 converged_hse =
true;
328 AMREX_GPU_HOST_DEVICE
337 const amrex::Array4<amrex::Real const> z_cc,
338 const int& klo,
const int&
khi)
352 Real myhalf_dz = z_cc(i,j,k0);
357 bool converged_hse =
false;
361 for (
int iter = 0; iter <
MAX_ITER && !converged_hse; iter++)
366 Real A = p_hse - p_eos;
372 r[k0] = r[k0] + drho;
375 if (std::abs(drho) <
TOL)
377 converged_hse =
true;
392 for (
int k = kstart; k <=
khi; k++)
396 bool converged_hse =
false;
398 Real dz_loc = (z_cc(i,j,k) - z_cc(i,j,k-1));
405 for (
int iter = 0; iter <
MAX_ITER && !converged_hse; iter++)
410 Real A = p_hse - p_eos;
419 if (std::abs(drho) <
TOL * r[k-1])
421 converged_hse =
true;
433 AMREX_GPU_HOST_DEVICE
437 return p_s *
Real(100.0);
441 AMREX_GPU_HOST_DEVICE
443 const int which_zone,
const Real scaled_height)
445 if (which_zone > 0) {
446 if (which_zone == 1) {
449 return Real(0.014)/q_s;
450 }
else if (which_zone == 2) {
451 return one -
Real(0.75)*std::pow(scaled_height,
Real(1.25));
461 AMREX_GPU_HOST_DEVICE
469 if (which_zone == 1) {
477 AMREX_GPU_HOST_DEVICE
490 AMREX_GPU_HOST_DEVICE
492 const int which_zone,
const Real scaled_height)
496 #ifdef AMREX_USE_FLOAT
501 for (
int iter=0; iter<20; iter++)
505 Real F_prime = (F_plus_dF - F)/eps;
506 delta_T = -F/F_prime;
510 if (std::fabs(delta_T) >
TOL * T_b) {
511 amrex::Abort(
"Newton Raphson for temperature could not converge");
518 AMREX_GPU_HOST_DEVICE
522 T = T_b -
Real(273.15);
525 gamma = std::log(
RH*std::exp((b -
T/d)*
T/(c +
T)));
533 AMREX_GPU_HOST_DEVICE
537 if(scaled_height <=
one) {
545 AMREX_GPU_HOST_DEVICE
548 const Real scaled_height,
const bool T_from_theta,
576 AMREX_GPU_HOST_DEVICE
580 const int which_zone,
const Real scaled_height,
const bool T_from_theta,
585 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,
601 AMREX_GPU_HOST_DEVICE
605 const int which_zone,
const Real scaled_height,
const bool T_from_theta,
610 #ifdef AMREX_USE_FLOAT
616 for(
int iter=0; iter<20; iter++)
618 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,
621 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,
624 Real F_prime = (F_plus_dF - F)/eps;
625 delta_p_k = -F/F_prime;
626 p_k = p_k + delta_p_k;
629 if (std::fabs(delta_p_k) >
TOL) {
630 amrex::Abort(
"Newton Raphson for pressure could not converge");
637 AMREX_GPU_HOST_DEVICE
642 const bool T_from_theta =
false,
657 }
else if (
z <= z_tr_2) {
662 scaled_height =
z/z_tr_2;
665 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,
669 for (
int k=1; k<=
khi; k++)
677 }
else if (
z <= z_tr_2) {
682 scaled_height =
z/z_tr_2;
685 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:49
constexpr amrex::Real two
Definition: ERF_Constants.H:10
constexpr amrex::Real one
Definition: ERF_Constants.H:9
constexpr amrex::Real fourth
Definition: ERF_Constants.H:14
constexpr amrex::Real myhalf
Definition: ERF_Constants.H:13
constexpr amrex::Real p_0
Definition: ERF_Constants.H:61
constexpr amrex::Real iGamma
Definition: ERF_Constants.H:69
constexpr amrex::Real CONST_GRAV
Definition: ERF_Constants.H:64
constexpr amrex::Real Cp_l
Definition: ERF_Constants.H:51
constexpr amrex::Real R_d
Definition: ERF_Constants.H:47
constexpr amrex::Real L_v
Definition: ERF_Constants.H:59
constexpr amrex::Real RdoCp
Definition: ERF_Constants.H:54
constexpr amrex::Real RdoRv
Definition: ERF_Constants.H:57
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:21
Real T
Definition: ERF_InitCustomPert_Bubble.H:106
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
RH
Definition: ERF_InitCustomPert_Bubble.H:108
rho
Definition: ERF_InitCustomPert_Bubble.H:107
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:123
amrex::Real Real
Definition: ERF_ShocInterface.H:19
Definition: ERF_HSEUtils.H:13
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:546
const int MAX_ITER
Definition: ERF_HSEUtils.H:17
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE Real compute_dewpoint_temperature(const Real T_b, const Real RH)
Definition: ERF_HSEUtils.H:519
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:219
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:462
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:109
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE Real compute_saturation_pressure(const Real T_b, const bool use_empirical)
Definition: ERF_HSEUtils.H:434
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:602
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(0), const Real theta_tr=amrex::Real(0), const Real T_tr=amrex::Real(0))
Definition: ERF_HSEUtils.H:639
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:478
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:491
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:442
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:577
const amrex::Real TOL
Definition: ERF_HSEUtils.H:21
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:331
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:44
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:534
@ theta
Definition: ERF_SLM.H:20
@ P
Definition: ERF_IndexDefines.H:166
@ qt
Definition: ERF_Kessler.H:29
@ qv
Definition: ERF_Kessler.H:30
@ p
Definition: ERF_WSM6.H:191
@ dz
Definition: ERF_AdvanceWSM6.cpp:104
Definition: ERF_ConsoleIO.cpp:15
real(c_double), parameter g
Definition: ERF_module_model_constants.F90:19