ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_SuperDropletPCMassChange.H
Go to the documentation of this file.
1 #ifndef SUPERDROPLET_PC_MASSCHANGE_H_
2 #define SUPERDROPLET_PC_MASSCHANGE_H_
3 
4 #include <cmath>
5 #include <limits>
6 #include <AMReX_GpuPrint.H>
7 #include <AMReX_Math.H>
10 
11 #ifdef ERF_USE_PARTICLES
12 
13 /*! \brief Namespace with classes and functions for condensation/evaporation
14  * (liquid <--> vapor) */
15 namespace SDMassChangeUtils_LV
16 {
17  /*! \brief Ventilation factor as a function of droplet radius (Bayley et al., 2025, Eq. 3) */
18  template <typename RT /*!< real-type */ >
19  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
20  RT ventilationFactor ( const RT a_R, /*!< radius */
21  const RT a_alpha1, /*!< fit coefficient alpha_1 */
22  const RT a_beta1, /*!< fit exponent beta_1 */
23  const RT a_alpha2, /*!< fit coefficient alpha_2 */
24  const RT a_beta2, /*!< fit exponent beta_2 */
25  const RT a_fcap /*!< maximum ventilation factor */ ) noexcept
26  {
27  RT x1 = a_alpha1 * std::pow(a_R, a_beta1);
28  RT x2 = a_alpha2 * std::pow(a_R, a_beta2);
29  RT fv = RT(1.0) + (x1*x2) / (x1 + x2);
30  return std::min(fv, a_fcap);
31  }
32 
33 #ifdef ERF_USE_ML_UPHYS_DIAGNOSTICS
34  /*! \brief Phase change equation (in terms of R) */
35  template <typename RT /*!< real-type */ >
36  struct dRdt
37  {
38  RT L; /*!< latent heat of vaporization (condensate) */
39  RT K; /*!< thermal conductivity (condensate) */
40  RT Rv; /*!< gas constant of air with vapor */
41  RT rho_l; /*!< density of condensate */
42 
43  /*! \brief Right-hand-side of the phase change ODE */
44  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
45  RT operator () ( const RT a_R, /*!< radius */
46  const RT a_S, /*!< saturation ratio */
47  const RT a_T, /*!< temperature */
48  const RT a_e_s, /*!< saturation pressure */
49  const RT a_D, /*!< mol. diffusion coeff */
50  const RT a_a, /*!< curvature coeff */
51  const RT a_b, /*!< solute coeff */
52  const RT a_N_s, /*!< total solute moles */
53  const RT a_f_v /*!< ventilation factor */ ) const noexcept
54  {
55  RT lambda_v = 2*a_D/std::sqrt(8*a_T*Rv/PI);
56  RT Kn = lambda_v/a_R;
57  RT dcf = (1+Kn) / (1+2*Kn*(1+Kn));
58 
59  RT F_k = ( L/(Rv*a_T) - RT(1.0)) * ((L*rho_l) / (K*a_T));
60  RT F_d = (rho_l*Rv*a_T) / (dcf*a_D*a_e_s);
61 
62  RT R_inv = RT(1.0)/a_R;
63  RT R_inv_cubed = R_inv*R_inv*R_inv;
64 
65  RT alpha = (a_S-RT(1.0)) / (F_k + F_d);
66  RT retval = alpha*R_inv;
67 
68  RT beta = -(a_a/a_T) / (F_k + F_d);
69  retval += beta*R_inv*R_inv;
70 
71  RT gamma = a_b * a_N_s / (F_k + F_d);
72  retval += gamma*R_inv_cubed*R_inv;
73 
74  return a_f_v * retval;
75  }
76 
77  };
78 #endif
79 
80  /*! \brief Phase change equation (in terms of R^2) */
81  template <typename RT /*!< real-type */ >
82  struct dRsqdt
83  {
84  RT L; /*!< latent heat of vaporization (condensate) */
85  RT K; /*!< thermal conductivity (condensate) */
86  RT Rv; /*!< gas constant of air with vapor */
87  RT rho_l; /*!< density of condensate */
88 
89  /*! \brief Right-hand-side of the phase change ODE */
90  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
91  RT rhs_func ( const RT a_R_sq, /*!< radius squared */
92  const RT a_S, /*!< saturation ratio */
93  const RT a_T, /*!< temperature */
94  const RT a_e_s, /*!< saturation pressure */
95  const RT a_D, /*!< mol. diffusion coeff */
96  const RT a_a, /*!< curvature coeff */
97  const RT a_b, /*!< solute coeff */
98  const RT a_N_s, /*!< total solute moles */
99  const RT a_f_v /*!< ventilation factor */ ) const noexcept
100  {
101  RT lambda_v = 2*a_D/std::sqrt(8*a_T*Rv/PI);
102  RT Kn = lambda_v/std::sqrt(a_R_sq);
103  RT dcf = (1+Kn) / (1+2*Kn*(1+Kn));
104 
105  RT F_k = ( L/(Rv*a_T) - RT(1.0)) * ((L*rho_l) / (K*a_T));
106  RT F_d = (rho_l*Rv*a_T) / (dcf*a_D*a_e_s);
107 
108  RT R_inv = RT(1.0)/std::sqrt(a_R_sq);
109  RT R_inv_cubed = R_inv*R_inv*R_inv;
110 
111  RT alpha = RT(2.0) * (a_S-RT(1.0)) / (F_k + F_d);
112  RT retval = alpha;
113 
114  RT beta = -RT(2.0) * (a_a/a_T) / (F_k + F_d);
115  retval += beta*R_inv;
116 
117  RT gamma = RT(2.0) * a_b * a_N_s / (F_k + F_d);
118  retval += gamma*R_inv_cubed;
119 
120  return a_f_v * retval;
121  }
122 
123  /*! \brief Jacobian of right-hand-side of the phase change ODE */
124  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
125  RT rhs_jac ( const RT a_R_sq, /*!< radius squared */
126  const RT a_T, /*!< temperature */
127  const RT a_e_s, /*!< saturation pressure */
128  const RT a_D, /*!< mol. diffusion coeff */
129  const RT a_a, /*!< curvature coeff */
130  const RT a_b, /*!< solute coeff */
131  const RT a_N_s, /*!< total solute moles */
132  const RT a_f_v /*!< ventilation factor */ ) const noexcept
133  {
134  RT lambda_v = 2*a_D/std::sqrt(8*a_T*Rv/PI);
135  RT Kn = lambda_v/std::sqrt(a_R_sq);
136  RT dcf = (1+Kn) / (1+2*Kn*(1+Kn));
137 
138  RT F_k = ( L/(Rv*a_T) - RT(1.0)) * ((L*rho_l) / (K*a_T));
139  RT F_d = (rho_l*Rv*a_T) / (dcf*a_D*a_e_s);
140 
141  RT R_inv = RT(1.0)/std::sqrt(a_R_sq);
142  RT R_inv_3 = R_inv*R_inv*R_inv;
143  RT R_inv_5 = R_inv_3*R_inv*R_inv;
144 
145  RT retval = RT(0.0);
146 
147  RT beta = -RT(2.0) * (a_a/a_T) / (F_k + F_d);
148  retval -= myhalf * beta*R_inv_3;
149 
150  RT gamma = RT(2.0) * a_b * a_N_s / (F_k + F_d);
151  retval -= myhalf * three*gamma*R_inv_5;
152 
153  return a_f_v * retval;
154  }
155 
156  };
157 
158  /*! \brief Scalar Newton solver for phase change equation
159  *
160  * Solves the following nonlinear equation:
161  * mu * u - F(u) - R = 0,
162  * where:
163  * u: solution variable
164  * mu: constant
165  * R: right-hand-side (constant)
166  * F(u): function
167  */
168  template<typename NE /*!< Nonlinear equation */, typename RT /*!< real-type */>
169  struct NewtonSolver
170  {
171  const NE m_ne; /*!< nonlinear equation */
172 
173  RT m_rtol; /*!< relative tolerance */
174  RT m_atol; /*!< absolute tolerance */
175  RT m_stol; /*!< step size tolerance */
176  int m_maxits; /*!< max number of iterations */
177 
178  /*! \brief solve the nonlinear equation */
179  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
180  void operator() ( RT& a_u, /*!< solution variable */
181  RT& a_r, /*!< right-hand-side */
182  const RT& a_mu, /*!< mu */
183  const RT& a_S, /*!< saturation ratio */
184  const RT& a_T, /*!< temperature */
185  const RT& a_e_s, /*!< saturation pressure */
186  const RT& a_D, /*!< mol. diff. coeff */
187  const RT& a_a, /*!< curvature coeff */
188  const RT& a_b, /*!< solute coeff */
189  const RT& a_N_s, /*!< total solute moles */
190  const RT& a_f_v, /*!< ventilation factor */
191  RT& a_res_norm_a, /*!< absolute norm at exit */
192  RT& a_res_norm_r /*!< relative norm at exit */,
193  bool& a_converged /*!< convergence status at exit */
194  ) const
195  {
196  a_converged = false;
197  RT res_norm0 = RT(0.0);
198 
199  for (int k = 0; k < m_maxits; k++) {
200  RT residual = a_mu * a_u
201  - ( a_r
202  + m_ne.rhs_func( a_u, a_S, a_T, a_e_s, a_D, a_a, a_b, a_N_s, a_f_v ) );
203  a_res_norm_a = std::abs(residual);
204 
205  if (k == 0) {
206  if (a_res_norm_a > 0) {
207  res_norm0 = a_res_norm_a;
208  } else {
209  res_norm0 = RT(1.0);
210  }
211  }
212  a_res_norm_r = a_res_norm_a / res_norm0;
213 
214  if (a_res_norm_a <= m_atol) {
215  a_converged = true;
216  break;
217  }
218  if (a_res_norm_r <= m_rtol) {
219  a_converged = true;
220  break;
221  }
222  if (!amrex::Math::isfinite(a_res_norm_a)) {
223  a_converged = false;
224  break;
225  }
226 
227  RT slope = a_mu - m_ne.rhs_jac( a_u, a_T, a_e_s, a_D, a_a, a_b, a_N_s, a_f_v );
228  RT du = RT(0.0);
229  du = - residual / slope;
230 
231  RT du_norm = std::abs(du);
232  RT u_norm = std::abs(a_u);
233  // Retrying cannot resolve a correction at the solution's roundoff.
234  const RT step_tol = std::max(m_stol, std::numeric_limits<RT>::epsilon());
235  if (u_norm > RT(0.0) && du_norm/u_norm <= step_tol) {
236  a_converged = true;
237  break;
238  }
239 
240  a_u += du;
241  if (a_u <= RT(0.0)) {
242  a_converged = false;
243  break;
244  }
245  }
246  }
247  };
248 
249  /*! \brief Implicit and explicit time integrators for the phase change equation */
250  template< typename ODE /*!< ODE */,
251  typename NewtonSolver /*!< Newton solver */,
252  /**
253  * @brief Implicit and explicit time integrators for the phase change equation.
254  *
255  * @tparam ODE ODE type.
256  * @tparam NewtonSolver Newton solver type.
257  * @tparam RT Real-type.
258  */
259  typename RT /*!< real-type */ >
260  struct TI
261  {
262  const ODE m_ode; /*!< ODE */
263  const NewtonSolver m_newton; /*!< Newton solver */
264 
265  RT m_t_final; /*!< final time */
266  RT m_max_steps; /*!< max number of timesteps */
267  RT m_S; /*!< saturation ratio */
268  RT m_T; /*!< temperature */
269  RT m_e_s; /*!< saturation pressure */
270  RT m_D; /*!< mol. diff. coeff */
271  RT m_a; /*!< coefficient of curvature */
272  RT m_b; /*!< coefficient of solute */
273  RT m_N_s; /*!< total solute moles */
274 
275  RT m_cfl; /*!< CFL */
276  RT m_atol; /*!< absolute tolerance (for adaptive dt) */
277  RT m_rtol; /*!< absolute tolerance (for adaptive dt) */
278  RT m_stol; /*!< solution update tolerance for exit due to steady state */
279 
280  bool m_adapt_dt; /*!< use error-based adaptive dt? */
281  bool m_verbose; /*!< verbosity */
282 
283  bool m_ventilation; /*!< include ventilation factor? */
284  RT m_vent_alpha1; /*!< ventilation factor fit coefficient alpha_1 */
285  RT m_vent_beta1; /*!< ventilation factor fit exponent beta_1 */
286  RT m_vent_alpha2; /*!< ventilation factor fit coefficient alpha_2 */
287  RT m_vent_beta2; /*!< ventilation factor fit exponent beta_2 */
288  RT m_vent_fcap; /*!< maximum ventilation factor */
289 
290  /*! \brief Ventilation factor at the given radius-squared, frozen over a
291  * step to keep the implicit Jacobian exact (unity if disabled) */
292  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
293  RT ventFactor (const RT& a_u) const
294  {
295  if (!m_ventilation) { return RT(1.0); }
296  return ventilationFactor( std::sqrt(a_u),
297  m_vent_alpha1, m_vent_beta1,
298  m_vent_alpha2, m_vent_beta2,
299  m_vent_fcap );
300  }
301 
302  /*! \brief Compute timestep from stiffness estimate */
303  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
304  RT computeTimestep (const RT& a_u) const
305  {
306  RT tau = m_ode.rhs_jac(a_u, m_T, m_e_s, m_D, m_a, m_b, m_N_s, ventFactor(a_u));
307  return m_cfl / std::sqrt(tau*tau);
308  }
309 
310  /*! \brief Compute stiffness estimate (tau) */
311  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
312  RT computeTau (const RT& a_u) const
313  {
314  return m_ode.rhs_jac(a_u, m_T, m_e_s, m_D, m_a, m_b, m_N_s, ventFactor(a_u));
315  }
316 
317  /*! \brief Limit timestep to not exceed final time */
318  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
319  RT limitTimestep (RT dt, RT cur_time) const
320  {
321  if ((cur_time + dt) > m_t_final) {
322  dt = m_t_final - cur_time;
323  }
324  return dt;
325  }
326 
327  /*! \brief Check if timestep is too small to continue */
328  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
329  bool isTimestepTooSmall (RT dt, RT tau) const
330  {
331  return (dt < (RT(1.0e-12) * m_cfl / std::sqrt(tau*tau)))
332  && (dt < (RT(1.0e-12) * m_t_final));
333  }
334 
335  /*! \brief Evaluate ODE right-hand side */
336  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
337  RT evalRHS (const RT& a_u) const
338  {
339  return m_ode.rhs_func(a_u, m_S, m_T, m_e_s, m_D, m_a, m_b, m_N_s, ventFactor(a_u));
340  }
341 
342  /*! \brief Print verbose step information */
343  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
344  void printStepInfo (RT cur_time, RT dt, RT tau, RT radius, RT snorm) const
345  {
346  if (m_verbose) {
347  AMREX_DEVICE_PRINTF("Time %1.2e, dt = %1.2e, cfl = %1.1e, radius = %1.4e, snorm = %1.1e\n",
348  cur_time, dt, dt * std::sqrt(tau*tau), radius, snorm);
349  }
350  }
351 
352  /*! \brief Print verbose step info with Newton solver details */
353  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
354  void printStepInfoNewton (RT cur_time, RT dt, RT tau, RT radius, RT snorm,
355  RT res_norm_a, RT res_norm_r, bool converged) const
356  {
357  if (m_verbose) {
358  AMREX_DEVICE_PRINTF("Time %1.2e, dt = %1.2e, cfl = %1.1e, radius = %1.4e, snorm = %1.1e\n",
359  cur_time, dt, dt * std::sqrt(tau*tau), radius, snorm);
360  AMREX_DEVICE_PRINTF(" norms = %1.3e (abs), %1.3e (rel), converged = %s\n",
361  res_norm_a, res_norm_r, (converged ? "yes" : "no"));
362  }
363  }
364 
365  /*! \brief 3rd-order, 4-stage Bogacki-Shampine explicit RK method
366  * with 2nd order embedded method */
367  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
368  void rk3bs ( RT& a_u, /*!< solution */
369  bool& a_success /*!< success/failure flag */ ) const
370  {
371  RT cur_time = RT(0.0);
372  a_success = true;
373 
374  RT tau = m_ode.rhs_jac(a_u, m_T, m_e_s, m_D, m_a, m_b, m_N_s, ventFactor(a_u));
375  RT dt = m_cfl / std::sqrt(tau*tau);
376 
377  RT dt_new = dt;
378  RT a_u_old = a_u;
379 
380  int n_step = 0;
381  while ((cur_time < m_t_final) && (n_step < m_max_steps)) {
382 
383  if (!m_adapt_dt) {
384  tau = m_ode.rhs_jac(a_u, m_T, m_e_s, m_D, m_a, m_b, m_N_s, ventFactor(a_u));
385  dt = m_cfl / std::sqrt(tau*tau);
386  } else {
387  dt = dt_new;
388  }
389 
390  if ((cur_time + dt) > m_t_final) {
391  dt = m_t_final - cur_time;
392  }
393  if (!amrex::Math::isfinite(dt)) {
394  a_success = false;
395  break;
396  }
397 
398  RT u_new = RT(0.0);
399  bool step_success = false;
400  while (!step_success) {
401 
402  if ( (dt < (RT(1.0e-12)*m_cfl/std::sqrt(tau*tau)))
403  && (dt < (RT(1.0e-12)*m_t_final)) ) {
404  break;
405  }
406 
407  RT u1 = a_u;
408  if (u1 <= 0) {
409  dt *= myhalf;
410  continue;
411  }
412  RT f1 = m_ode.rhs_func(u1, m_S, m_T, m_e_s, m_D, m_a, m_b, m_N_s, ventFactor(a_u));
413 
414  RT u2 = a_u + myhalf*dt*f1;
415  if (u2 <= 0) {
416  dt *= myhalf;
417  continue;
418  }
419  RT f2 = m_ode.rhs_func(u2, m_S, m_T, m_e_s, m_D, m_a, m_b, m_N_s, ventFactor(a_u));
420 
421  RT u3 = a_u + RT(0.75)*dt*f2;
422  if (u3 <= 0) {
423  dt *= myhalf;
424  continue;
425  }
426  RT f3 = m_ode.rhs_func(u3, m_S, m_T, m_e_s, m_D, m_a, m_b, m_N_s, ventFactor(a_u));
427 
428  RT u4 = a_u + (RT(1.0)/RT(9.0))*dt * (RT(2.0)*f1 + three*f2 + RT(4.0)*f3);
429  if (u4 <= 0) {
430  dt *= myhalf;
431  continue;
432  }
433  RT f4 = m_ode.rhs_func(u4, m_S, m_T, m_e_s, m_D, m_a, m_b, m_N_s, ventFactor(a_u));
434 
435  u_new = u4;
436 
437  if (m_adapt_dt) {
438  RT u_embed = a_u + (RT(1.0)/RT(24.0))*dt * (RT(7.0)*f1 + RT(6.0)*f2 + RT(8.0)*f3 + three*f4);
439  RT err = std::sqrt((u_new-u_embed)*(u_new-u_embed));
440  RT tol = m_atol + m_rtol * std::max(a_u, a_u_old);
441  RT E = err / tol;
442  dt_new = dt / std::cbrt(E);
443  }
444 
445  if (amrex::Math::isfinite(u_new)) {
446  if (u_new > 0) {
447  step_success = true;
448  break;
449  }
450  }
451  dt *= myhalf;
452  }
453 
454  if (step_success) {
455 
456  RT snorm = std::sqrt((a_u-u_new)*(a_u-u_new)/(a_u*a_u));
457  a_u_old = a_u;
458  a_u = u_new;
459  cur_time += dt;
460 
461  if (m_verbose) {
462  AMREX_DEVICE_PRINTF( "Time %1.2e, dt = %1.2e, cfl = %1.1e, radius = %1.4e, snorm = %1.1e\n",
463  cur_time, dt, dt * std::sqrt(tau*tau), std::sqrt(a_u), snorm);
464  }
465  if (snorm < m_stol) {
466  break;
467  }
468 
469  } else {
470 
471  a_success = false;
472  break;
473 
474  }
475 
476  n_step++;
477  }
478 
479  return;
480  }
481 
482  /*! \brief 4th-order, 4-stage explicit Runge-Kutta method */
483  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
484  void rk4 ( RT& a_u, /*!< solution */
485  bool& a_success /*!< success/failure flag */ ) const
486  {
487  RT cur_time = RT(0.0);
488  a_success = true;
489 
490  int n_step = 0;
491  while ((cur_time < m_t_final) && (n_step < m_max_steps)) {
492 
493  RT tau = computeTau(a_u);
494  RT dt = m_cfl / std::sqrt(tau*tau);
495  dt = limitTimestep(dt, cur_time);
496  if (!amrex::Math::isfinite(dt)) {
497  a_success = false;
498  break;
499  }
500 
501  RT u_new = RT(0.0);
502  bool step_success = false;
503  while (!step_success) {
504 
505  if (isTimestepTooSmall(dt, tau)) { break; }
506 
507  RT u1 = a_u;
508  if (u1 <= 0) { dt *= myhalf; continue; }
509  RT f1 = evalRHS(u1);
510 
511  RT u2 = a_u + myhalf*dt*f1;
512  if (u2 <= 0) { dt *= myhalf; continue; }
513  RT f2 = evalRHS(u2);
514 
515  RT u3 = a_u + myhalf*dt*f2;
516  if (u3 <= 0) { dt *= myhalf; continue; }
517  RT f3 = evalRHS(u3);
518 
519  RT u4 = a_u + dt*f3;
520  if (u4 <= 0) { dt *= myhalf; continue; }
521  RT f4 = evalRHS(u4);
522 
523  u_new = a_u + dt*(f1 + RT(2.0)*f2 + RT(2.0)*f3 + f4)/RT(6.0);
524 
525  if (amrex::Math::isfinite(u_new) && (u_new > 0)) {
526  step_success = true;
527  break;
528  }
529  dt *= myhalf;
530  }
531 
532  if (step_success) {
533  RT snorm = std::sqrt((a_u-u_new)*(a_u-u_new)/(a_u*a_u));
534  a_u = u_new;
535  cur_time += dt;
536  printStepInfo(cur_time, dt, tau, std::sqrt(a_u), snorm);
537  if (snorm < m_stol) { break; }
538  } else {
539  a_success = false;
540  break;
541  }
542 
543  n_step++;
544  }
545 
546  return;
547  }
548 
549  /*! \brief 1st order implicit backward Euler method */
550  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
551  void be ( RT& a_u, /*!< solution */
552  bool& a_success /*!< success/failure flag */ ) const
553  {
554  RT cur_time = RT(0.0);
555  a_success = true;
556 
557  int n_step = 0;
558  while ((cur_time < m_t_final) && (n_step < m_max_steps)) {
559 
560  RT tau = computeTau(a_u);
561  RT dt = m_cfl / std::sqrt(tau*tau);
562  dt = limitTimestep(dt, cur_time);
563  if (!amrex::Math::isfinite(dt)) {
564  a_success = false;
565  break;
566  }
567 
568 #ifdef AMREX_USE_FLOAT
569  RT res_norm_a = std::numeric_limits<float>::max();
570  RT res_norm_r = std::numeric_limits<float>::max();
571 #else
572  RT res_norm_a = std::numeric_limits<double>::max();
573  RT res_norm_r = std::numeric_limits<double>::max();
574 #endif
575  bool converged = false;
576 
577  RT u_new = RT(0.0);
578  bool step_success = false;
579  while (!step_success) {
580 
581  if (isTimestepTooSmall(dt, tau)) { break; }
582 
583  RT mu = RT(1.0) / dt;
584  RT rhs = mu * a_u;
585  u_new = a_u;
586  m_newton(u_new, rhs, mu,
587  m_S, m_T, m_e_s, m_D, m_a, m_b, m_N_s, ventFactor(a_u),
588  res_norm_a, res_norm_r, converged);
589 
590  if (converged && amrex::Math::isfinite(u_new) && (u_new > 0)) {
591  step_success = true;
592  break;
593  }
594  dt *= myhalf;
595  }
596 
597  if (step_success) {
598  RT snorm = std::sqrt((a_u-u_new)*(a_u-u_new)/(a_u*a_u));
599  a_u = u_new;
600  cur_time += dt;
601  printStepInfoNewton(cur_time, dt, tau, std::sqrt(a_u), snorm,
602  res_norm_a, res_norm_r, converged);
603  if (snorm < m_stol) { break; }
604  } else {
605  a_success = false;
606  break;
607  }
608 
609  n_step++;
610  }
611 
612  return;
613  }
614 
615  /*! \brief 2nd-order implicit Crank-Nicolson method */
616  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
617  void cn ( RT& a_u, /*!< solution */
618  bool& a_success /*!< success/failure flag */ ) const
619  {
620  RT cur_time = RT(0.0);
621  a_success = true;
622 
623  int n_step = 0;
624  while ((cur_time < m_t_final) && (n_step < m_max_steps)) {
625 
626  RT tau = computeTau(a_u);
627  RT dt = m_cfl / std::sqrt(tau*tau);
628  dt = limitTimestep(dt, cur_time);
629  if (!amrex::Math::isfinite(dt)) {
630  a_success = false;
631  break;
632  }
633 
634  RT res_norm_a = std::numeric_limits<RT>::max();
635  RT res_norm_r = std::numeric_limits<RT>::max();
636  bool converged = false;
637 
638  RT u_new = RT(0.0);
639  bool step_success = false;
640  while (!step_success) {
641 
642  if (isTimestepTooSmall(dt, tau)) { break; }
643 
644  RT mu = RT(1.0) / (myhalf*dt);
645  RT u1 = a_u;
646  RT f1 = evalRHS(u1);
647 
648  RT u2 = u1;
649  RT rhs = mu * (a_u + myhalf*dt*f1);
650  m_newton(u2, rhs, mu,
651  m_S, m_T, m_e_s, m_D, m_a, m_b, m_N_s, ventFactor(a_u),
652  res_norm_a, res_norm_r, converged);
653  if (u2 <= 0) { dt *= myhalf; continue; }
654  RT f2 = evalRHS(u2);
655 
656  u_new = a_u + myhalf * dt * (f1 + f2);
657 
658  if (converged && amrex::Math::isfinite(u_new) && (u_new > 0)) {
659  step_success = true;
660  break;
661  }
662  dt *= myhalf;
663  }
664 
665  if (step_success) {
666  RT snorm = std::sqrt((a_u-u_new)*(a_u-u_new)/(a_u*a_u));
667  a_u = u_new;
668  cur_time += dt;
669  printStepInfoNewton(cur_time, dt, tau, std::sqrt(a_u), snorm,
670  res_norm_a, res_norm_r, converged);
671  if (snorm < m_stol) { break; }
672  } else {
673  a_success = false;
674  break;
675  }
676 
677  n_step++;
678  }
679 
680  return;
681  }
682 
683  /*! \brief 2nd-order, 2-stage diagonally-implicit RK method */
684  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
685  void dirk212 ( RT& a_u, /*!< solution */
686  bool& a_success /*!< success/failure flag */ ) const
687  {
688  RT cur_time = RT(0.0);
689  a_success = true;
690 
691  int n_step = 0;
692  while ((cur_time < m_t_final) && (n_step < m_max_steps)) {
693 
694  RT tau = computeTau(a_u);
695  RT dt = m_cfl / std::sqrt(tau*tau);
696  dt = limitTimestep(dt, cur_time);
697  if (!amrex::Math::isfinite(dt)) {
698  a_success = false;
699  break;
700  }
701 
702  bool converged = false;
703  RT res_norm_a = std::numeric_limits<RT>::max();
704  RT res_norm_r = std::numeric_limits<RT>::max();
705 
706  RT u_new = RT(0.0);
707  bool step_success = false;
708  while (!step_success) {
709 
710  if (isTimestepTooSmall(dt, tau)) {
711  break;
712  }
713  RT mu = RT(1.0) / dt;
714 
715  converged = true;
716  res_norm_a = RT(0.0);
717  res_norm_r = RT(0.0);
718 
719  RT u1 = a_u;
720  {
721  RT rhs = mu * a_u;
722  RT res_norm_a_i = std::numeric_limits<RT>::max();
723  RT res_norm_r_i = std::numeric_limits<RT>::max();
724  bool converged_i = false;
725  m_newton( u1, rhs, mu,
726  m_S, m_T, m_e_s, m_D, m_a, m_b, m_N_s, ventFactor(a_u),
727  res_norm_a_i, res_norm_r_i, converged_i );
728  converged = converged && converged_i;
729  res_norm_a = std::max(res_norm_a, res_norm_a_i);
730  res_norm_r = std::max(res_norm_r, res_norm_r_i);
731  }
732  if (u1 <= 0) {
733  dt *= myhalf;
734  continue;
735  }
736  RT f1 = evalRHS(u1);
737 
738  RT u2 = u1;
739  {
740  RT rhs = mu * (a_u - dt*f1);
741  RT res_norm_a_i = std::numeric_limits<RT>::max();
742  RT res_norm_r_i = std::numeric_limits<RT>::max();
743  bool converged_i = false;
744  m_newton( u2, rhs, mu,
745  m_S, m_T, m_e_s, m_D, m_a, m_b, m_N_s, ventFactor(a_u),
746  res_norm_a_i, res_norm_r_i, converged_i );
747  converged = converged && converged_i;
748  res_norm_a = std::max(res_norm_a, res_norm_a_i);
749  res_norm_r = std::max(res_norm_r, res_norm_r_i);
750  }
751  if (u2 <= 0) {
752  dt *= myhalf;
753  continue;
754  }
755  RT f2 = evalRHS(u2);
756 
757  u_new = a_u + myhalf * dt * (f1 + f2);
758 
759  if (converged) {
760  if (amrex::Math::isfinite(u_new)) {
761  if (u_new > 0) {
762  step_success = true;
763  break;
764  }
765  }
766  }
767  dt *= myhalf;
768  }
769 
770  if (step_success) {
771 
772  RT snorm = std::sqrt((a_u-u_new)*(a_u-u_new)/(a_u*a_u));
773  a_u = u_new;
774  cur_time += dt;
775 
776  printStepInfoNewton(cur_time, dt, tau, std::sqrt(a_u), snorm,
777  res_norm_a, res_norm_r, converged);
778  if (snorm < m_stol) {
779  break;
780  }
781 
782  } else {
783 
784  a_success = false;
785  break;
786 
787  }
788 
789  n_step++;
790  }
791 
792  return;
793  }
794 
795  };
796 }
797 
798 /*! \brief Namespace with classes and functions for deposition/sublimation
799  * (solid <--> vapor) */
800 namespace SDMassChangeUtils_SV
801 {
802  /*! \brief Phase change equation (in terms of mass) */
803  template <typename RT /*!< real-type */ >
804  struct dMdt
805  {
806  RT L; /*!< latent heat of vaporization (condensate) */
807  RT K; /*!< thermal conductivity */
808  RT Rv; /*!< gas constant of air with vapor */
809  RT rho_ice; /*!< True density of ice */
810 
811  /*! \brief Compute growth ratio */
812  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
813  RT growthRatio ( const RT a_T /*!< temperature */ ) const noexcept
814  {
815  // Table of the inherent growth ratio (Chen and Lamb 1994)
816  // T(n) = (1.375-n)/4. Here, T is the temperature in [degreeC], and n is the index.
817  static constexpr amrex::Real tb_habit[121] = {
818  amrex::Real(1.000000e+00), amrex::Real(9.799412e-01), amrex::Real(9.600636e-01), amrex::Real(9.399397e-01), amrex::Real(9.200258e-01),
819  amrex::Real(9.001191e-01), amrex::Real(8.800351e-01), amrex::Real(8.570378e-01), amrex::Real(8.340652e-01), amrex::Real(8.109611e-01),
820  amrex::Real(7.830689e-01), amrex::Real(7.550922e-01), amrex::Real(7.030723e-01), amrex::Real(5.370318e-01), amrex::Real(4.677351e-01),
821  amrex::Real(5.248075e-01), amrex::Real(6.309573e-01), amrex::Real(8.128305e-01), amrex::Real(1.096478e+00), amrex::Real(1.479108e+00),
822  amrex::Real(1.905461e+00), amrex::Real(2.089296e+00), amrex::Real(2.290868e+00), amrex::Real(2.398833e+00), amrex::Real(2.454709e+00),
823  amrex::Real(2.426610e+00), amrex::Real(2.371374e+00), amrex::Real(2.290868e+00), amrex::Real(2.137962e+00), amrex::Real(1.995262e+00),
824  amrex::Real(1.862087e+00), amrex::Real(1.737801e+00), amrex::Real(1.621810e+00), amrex::Real(1.513561e+00), amrex::Real(1.396368e+00),
825  amrex::Real(1.288250e+00), amrex::Real(1.188502e+00), amrex::Real(1.096478e+00), amrex::Real(1.000000e+00), amrex::Real(9.225714e-01),
826  amrex::Real(8.511380e-01), amrex::Real(7.852356e-01), amrex::Real(7.244360e-01), amrex::Real(6.683439e-01), amrex::Real(6.165950e-01),
827  amrex::Real(5.754399e-01), amrex::Real(5.370318e-01), amrex::Real(5.011872e-01), amrex::Real(4.677351e-01), amrex::Real(4.365158e-01),
828  amrex::Real(4.073803e-01), amrex::Real(3.801894e-01), amrex::Real(3.548134e-01), amrex::Real(3.311311e-01), amrex::Real(3.162278e-01),
829  amrex::Real(3.019952e-01), amrex::Real(2.917427e-01), amrex::Real(2.851018e-01), amrex::Real(2.818383e-01), amrex::Real(2.786121e-01),
830  amrex::Real(2.754229e-01), amrex::Real(2.786121e-01), amrex::Real(2.818383e-01), amrex::Real(2.851018e-01), amrex::Real(2.917427e-01),
831  amrex::Real(2.985383e-01), amrex::Real(3.090295e-01), amrex::Real(3.198895e-01), amrex::Real(3.311311e-01), amrex::Real(3.467369e-01),
832  amrex::Real(3.672823e-01), amrex::Real(3.935501e-01), amrex::Real(4.265795e-01), amrex::Real(4.570882e-01), amrex::Real(4.897788e-01),
833  amrex::Real(5.248075e-01), amrex::Real(5.623413e-01), amrex::Real(6.095369e-01), amrex::Real(6.606934e-01), amrex::Real(7.161434e-01),
834  amrex::Real(7.852356e-01), amrex::Real(8.609938e-01), amrex::Real(9.549926e-01), amrex::Real(1.047129e+00), amrex::Real(1.148154e+00),
835  amrex::Real(1.258925e+00), amrex::Real(1.380384e+00), amrex::Real(1.496236e+00), amrex::Real(1.603245e+00), amrex::Real(1.698244e+00),
836  amrex::Real(1.778279e+00), amrex::Real(1.840772e+00), amrex::Real(1.883649e+00), amrex::Real(1.905461e+00), amrex::Real(1.905461e+00),
837  amrex::Real(1.883649e+00), amrex::Real(1.862087e+00), amrex::Real(1.840772e+00), amrex::Real(1.798871e+00), amrex::Real(1.737801e+00),
838  amrex::Real(1.698244e+00), amrex::Real(1.640590e+00), amrex::Real(1.584893e+00), amrex::Real(1.549173e+00), amrex::Real(1.513910e+00),
839  amrex::Real(1.476046e+00), amrex::Real(1.452112e+00), amrex::Real(1.428894e+00), amrex::Real(1.412863e+00), amrex::Real(1.393157e+00),
840  amrex::Real(1.376892e+00), amrex::Real(1.361131e+00), amrex::Real(1.348963e+00), amrex::Real(1.336903e+00), amrex::Real(1.327089e+00),
841  amrex::Real(1.317953e+00), amrex::Real(1.308881e+00), amrex::Real(1.302867e+00), amrex::Real(1.293898e+00), amrex::Real(1.287953e+00),
842  amrex::Real(1.279087e+00)
843  };
844  auto T_degC = a_T - RT(273.15); // [K] => [degC]
845  int n = std::min(std::max(static_cast<int>(std::round(RT(1.375)-RT(4.0)*T_degC)),1),121);
846  return static_cast<RT>(tb_habit[n-1]);
847 
848  }
849 
850  /*! \brief Compute F_k + F_d */
851  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
852  RT Fk_plus_Fd ( const RT a_T, /*!< temperature */
853  const RT a_e_s, /*!< saturation pressure */
854  const RT a_D /*!< mol. diffusion coeff */ ) const noexcept
855  {
856  auto F_k = (L/(Rv*a_T) - RT(1.0)) * (L / (K*a_T));
857  auto F_d = (Rv*a_T) / (a_D*a_e_s);
858  return (F_k + F_d);
859  }
860 
861  /*! \brief Compute dynamic viscosity */
862  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
863  RT viscCoeff ( const RT a_T /*!< temperature */ ) const noexcept
864  {
865  auto T_degC = a_T - RT(273.15); // [K] => [degC]
866  RT visc_coeff = RT(0.0);
867  if( T_degC >= RT(0.0) ) {
868  visc_coeff = ( RT(1.7180) + RT(4.9E-3)*T_degC ) * RT(1.E-5);
869  } else {
870  visc_coeff = ( RT(1.7180) + RT(4.9E-3)*T_degC -RT(1.2E-5)*T_degC*T_degC ) * RT(1.E-5);
871  }
872  return visc_coeff;
873  }
874 
875  /*! \brief Compute capacitance */
876  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
877  RT capacitance ( const RT a_a, /*!< equatorial radius */
878  const RT a_c /*!< polar radius */ ) const noexcept
879  {
880  auto phi = a_c / a_a;
881  // The optimizer evaluates both shape branches before selecting one (a sphere,
882  // phi = 1, divides 0 by 0 in each), so keep every argument in its domain. The
883  // abs, min and max leave the selected branch's values unchanged.
884  const RT tiny = std::numeric_limits<RT>::min();
885  auto ecent_prolate = std::sqrt(std::abs(RT(1.0) - RT(1.0)/(phi*phi)));
886  auto ecent_oblate = std::sqrt(amrex::min(std::abs(RT(1.0) - phi*phi), RT(1.0)));
887  auto capaci_prolate = ecent_prolate*a_c / amrex::max(std::log((RT(1.0)+ecent_prolate)*phi), tiny);
888  auto capaci_oblate = ecent_oblate*a_a / amrex::max(std::asin(ecent_oblate), tiny);
889  RT capaci = RT(0.0);
890  if(phi >= RT(1.001)) {
891  capaci = capaci_prolate;
892  } else if (phi <= RT(0.999)) {
893  capaci = capaci_oblate;
894  } else {
895  capaci = (RT(2.0)*a_a + a_c)/three;
896  }
897  return capaci;
898  }
899 
900  /*! \brief Compute ventilation effect */
901  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
902  RT ventX ( const RT a_a, /*!< equatorial radius */
903  const RT a_c, /*!< polar radius */
904  const RT a_vterm,/*!< terminal velocity */
905  const RT a_T, /*!< temperature */
906  const RT a_rhom, /*!< moist density */
907  const RT a_D /*!< mol. diffusion coeff */ ) const noexcept
908  {
909  auto visc_coeff = viscCoeff(a_T);
910  auto maxdim = RT(2.0) * std::max(a_a, a_c);
911  auto n_re = a_rhom * maxdim * a_vterm / visc_coeff;
912  auto n_sc = visc_coeff / (a_rhom*a_D);
913  auto X_vent = std::cbrt(n_sc) * std::sqrt(n_re);
914  return X_vent;
915  }
916 
917  /*! \brief Radius change */
918  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
919  RT growthRatioStar ( const RT a_dmass, /*!< delta mass */
920  const RT a_a, /*!< equatorial radius */
921  const RT a_c, /*!< polar radius */
922  const RT a_vterm, /*!< terminal velocity */
923  const RT a_rhom, /*!< moist air density */
924  const RT a_T, /*!< temperature */
925  const RT a_D /*!< mol. diffusion coeff */ ) const noexcept
926  {
927  auto capaci = capacitance(a_a, a_c);
928  auto X_vent = ventX(a_a, a_c, a_vterm, a_T, a_rhom, a_D);
929  RT fratio = RT(0.0);
930  if(X_vent <= RT(1.0)) {
931  fratio = (RT(1.0) + RT(0.14)*X_vent*X_vent*std::sqrt(a_c/capaci))
932  / (RT(1.0) + RT(0.14)*X_vent*X_vent*std::sqrt(a_a/capaci));
933  } else {
934  fratio = (RT(0.86) + RT(0.28)*X_vent*std::sqrt(a_c/capaci))
935  / (RT(0.86) + RT(0.28)*X_vent*std::sqrt(a_a/capaci));
936  }
937 
938  auto gr = growthRatio(a_T);
939  if ((RT(2.0)*std::max(a_a,a_c) < RT(1.0e-5)) || (a_dmass <= RT(0.0))) { gr = RT(1.0); }
940  auto gr_star = gr * fratio;
941  if((a_dmass > RT(0.0)) && (a_c/a_a > RT(40.0))) { gr_star = std::min(gr_star,RT(1.0)); }
942 
943  return gr_star;
944  }
945 
946  /*! \brief Volume change */
947  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
948  RT dVolume ( const RT a_dmass, /*!< delta mass */
949  const RT a_a, /*!< equatorial radius */
950  const RT a_c, /*!< polar radius */
951  const RT a_rho, /*!< ice density of particle */
952  const RT a_S, /*!< saturation ratio */
953  const RT a_T, /*!< temperature */
954  const RT a_e_s, /*!< saturation pressure */
955  const RT a_es_ratio_wi, /*!< ratio of saturation pressures of water to ice */
956  const RT a_D /*!< mol. diffusion coeff */ ) const noexcept
957  {
958  RT rho_i_ds = a_rho;
959  auto gr = growthRatio(a_T);
960  if (a_dmass > RT(0.0)) {
961  if ((gr < RT(1.0)) && (a_a < RT(1.0e-4))) {
962  rho_i_ds = rho_ice;
963  } else {
964  if (RT(2.0)*std::max(a_a,a_c) < RT(1.0e-5)) { gr = RT(1.0); }
965  auto ex_vap_dens = RT(1000.0) * (std::min(a_S,a_es_ratio_wi) - RT(1.0)) / (Fk_plus_Fd(a_T,a_e_s,a_D) * a_D);
966  rho_i_ds = rho_ice * std::exp(-three*std::max(ex_vap_dens-RT(0.05),RT(0.0))/gr);
967  }
968  }
969 
970  auto dvol = a_dmass / rho_i_ds;
971  return dvol;
972  }
973 
974  /*! \brief Radius change */
975  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
976  RT dLogRadius ( const RT a_grstar, /*!< growth ratio */
977  const RT a_dlogvol /*!< delta log volume */ ) const noexcept
978  {
979  return a_dlogvol / (a_grstar+RT(2.0));
980  }
981 
982  /*! \brief Right-hand-side of the phase change ODE */
983  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
984  RT rhs_func ( const RT a_a, /*!< equatorial radius */
985  const RT a_c, /*!< polar radius */
986  const RT a_vterm,/*!< terminal velocity */
987  const RT a_S, /*!< saturation ratio */
988  const RT a_rhom, /*!< moist density */
989  const RT a_T, /*!< temperature */
990  const RT a_e_s, /*!< saturation pressure */
991  const RT a_D /*!< mol. diffusion coeff */ ) const noexcept
992  {
993  auto capaci = capacitance(a_a, a_c);
994  auto X_vent = ventX(a_a, a_c, a_vterm, a_T, a_rhom, a_D);
995 
996  RT f_vent = RT(0.0);
997  if (X_vent <= RT(1.0)) { f_vent = RT(1.0) + RT(0.14)*X_vent*X_vent; }
998  else { f_vent = RT(0.86) + RT(0.28)*X_vent; }
999 
1000  auto retval = RT(4.0)*PI * capaci * (a_S-RT(1.0)) * f_vent / Fk_plus_Fd(a_T, a_e_s, a_D);
1001  return retval;
1002  }
1003 
1004  /*! \brief Ice melt rate dm_ice/dt (Pruppacher-Klett; Seifert-Beheng 2006 Eq. 72).
1005  * Negative when melting. Heat conducted from warm air plus latent heat of the
1006  * vapor flux to the 0 degC wet surface, divided by the latent heat of fusion.
1007  * Reuses capacitance and ventilation. For this functor built with the water
1008  * material, L is the latent heat of vaporization, K the air thermal
1009  * conductivity, and Rv the vapor gas constant. */
1010  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
1011  RT meltRate ( const RT a_a, /*!< equatorial radius */
1012  const RT a_c, /*!< polar radius */
1013  const RT a_vterm, /*!< terminal velocity */
1014  const RT a_T, /*!< temperature */
1015  const RT a_e_inf, /*!< ambient vapor pressure */
1016  const RT a_e_sat_wT0, /*!< sat. pressure over water at melting point */
1017  const RT a_rhom, /*!< moist density */
1018  const RT a_D, /*!< vapor diffusion coeff */
1019  const RT a_L_f /*!< latent heat of fusion */ ) const noexcept
1020  {
1021  auto capaci = capacitance(a_a, a_c);
1022  auto X_vent = ventX(a_a, a_c, a_vterm, a_T, a_rhom, a_D);
1023 
1024  RT f_vent = RT(0.0);
1025  if (X_vent <= RT(1.0)) { f_vent = RT(1.0) + RT(0.14)*X_vent*X_vent; }
1026  else { f_vent = RT(0.86) + RT(0.28)*X_vent; }
1027 
1028  RT T0 = RT(tmelt);
1029  RT heat = K * f_vent * (a_T - T0)
1030  + (L*a_D/Rv) * (a_e_inf/a_T - a_e_sat_wT0/T0) * f_vent;
1031  return -(RT(4.0)*PI*capaci/a_L_f) * heat;
1032  }
1033 
1034  };
1035 
1036  /*! \brief Implicit and explicit time integrators for the phase change equation */
1037  template< typename ODE /*!< ODE */,
1038  typename RT /*!< real-type */ >
1039  struct TI
1040  {
1041  const ODE m_ode; /*!< ODE */
1042 
1043  RT m_t_final; /*!< final time */
1044  mutable RT m_dt;/*!< dt */
1045  RT m_max_steps; /*!< max number of timesteps */
1046 
1047  RT m_a; /*!< equatorial radius */
1048  RT m_c; /*!< polar radius */
1049  RT m_vt; /*!< terminal velocity */
1050  RT m_S; /*!< saturation ratio */
1051  RT m_rhom; /*!< moist density */
1052  RT m_T; /*!< temperature */
1053  RT m_e_s; /*!< saturation pressure */
1054  RT m_D; /*!< mol. diff. coeff */
1055 
1056  bool m_verbose; /*!< verbosity */
1057 
1058  /*! \brief 1st-order, forward Euler method */
1059  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
1060  void fe ( RT& a_u, /*!< solution */
1061  bool& a_success /*!< success/failure flag */ ) const
1062  {
1063  RT cur_time = RT(0.0);
1064  a_success = true;
1065 
1066  int n_step = 0;
1067  while ((cur_time < m_t_final) && (n_step < m_max_steps)) {
1068 
1069  if ((cur_time + m_dt) > m_t_final) {
1070  m_dt = m_t_final - cur_time;
1071  }
1072 
1073  RT rhs = m_ode.rhs_func(m_a, m_c, m_vt, m_S, m_rhom, m_T, m_e_s, m_D);
1074  RT u_new = a_u + m_dt*rhs;
1075  if (!amrex::Math::isfinite(u_new)) {
1076  a_success = false;
1077  break;
1078  }
1079 
1080  RT snorm = std::sqrt((a_u-u_new)*(a_u-u_new)/(a_u*a_u));
1081  a_u = u_new;
1082  cur_time += m_dt;
1083 
1084  if (m_verbose) {
1085  AMREX_DEVICE_PRINTF( "Time %1.2e, m_dt = %1.2e, mass = %1.4e, snorm = %1.1e\n",
1086  cur_time, m_dt, a_u, snorm);
1087  }
1088 
1089  n_step++;
1090  }
1091 
1092  return;
1093  }
1094 
1095  };
1096 }
1097 
1098 #endif
1099 #endif
amrex::Real gamma
Definition: ERF_InitCustomPert_DataAssimilation_ISV.H:9
Physical constants and tuning parameters used only by the moisture and cloud-physics code.
constexpr amrex::Real tmelt
Definition: ERF_MicrophysicsConstants.H:122
Dimensionless numeric literals and pure mathematical constants.
constexpr amrex::Real three
Definition: ERF_NumericalConstants.H:39
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
constexpr amrex::Real PI
Definition: ERF_NumericalConstants.H:46
@ mu
Definition: ERF_AdvanceMorrison.cpp:94
@ beta
Definition: ERF_SLM.H:154
@ alpha
Definition: ERF_SLM.H:153
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real phi(amrex::Real d, amrex::Real z0, amrex::Real psi) noexcept
Definition: ERF_ImmersedWallCell.H:176
real(c_double), parameter epsilon
Definition: ERF_module_model_constants.F90:12