1 #ifndef ERF_RRTMGP_UTILS_H
2 #define ERF_RRTMGP_UTILS_H
4 #include "rrtmgp_const.h"
8 #include "YAKL_Bounds_fortran.h"
15 using yakl::intrinsics::maxval;
16 using yakl::intrinsics::minval;
17 using yakl::intrinsics::count;
18 using yakl::intrinsics::sum;
21 template<
class T,
int myMem,
int myStyle>
24 yakl::Array<T,2,myMem,myStyle>
const &cloud_fraction,
25 yakl::Array<T,2,myMem,myStyle>
const &dp,
26 yakl::Array<T,2,myMem,myStyle> &cloud_mass)
28 int ncol = mixing_ratio.dimension[0];
29 int nlay = mixing_ratio.dimension[1];
30 yakl::fortran::parallel_for(yakl::fortran::SimpleBounds<2>(nlay, ncol), YAKL_LAMBDA(
int ilay,
int icol)
36 if (cloud_fraction(icol,ilay) > 0) {
38 auto incloud_mixing_ratio = std::min(mixing_ratio(icol,ilay) / std::max(0.0001, cloud_fraction(icol,ilay)), 0.005);
39 cloud_mass(icol,ilay) = incloud_mixing_ratio * dp(icol,ilay) /
CONST_GRAV;
41 cloud_mass(icol,ilay) = 0;
47 template<
class S,
class T>
54 yakl::c::parallel_for(arr_in.totElems(), YAKL_LAMBDA(
int i)
56 arr_out.data()[i] = std::min(std::max(arr_in.data()[i], lower), upper);
71 template <
class T,
int myMem,
int myStyle>
74 yakl::Array<T,2,myMem,myStyle>
const &flux_dn,
75 yakl::Array<T,2,myMem,myStyle>
const &
rho ,
76 yakl::Array<T,2,myMem,myStyle>
const &dz ,
77 yakl::Array<T,2,myMem,myStyle> &heating_rate)
79 auto ncol = flux_up.dimension[0];
80 auto nlay = flux_up.dimension[1]-1;
81 yakl::fortran::parallel_for(yakl::fortran::SimpleBounds<2>(nlay,ncol), YAKL_LAMBDA(
int ilay,
int icol)
83 heating_rate(icol,ilay) = ( flux_up(icol,ilay+1) - flux_up(icol,ilay)
84 - flux_dn(icol,ilay+1) + flux_dn(icol,ilay) )
85 / (
Cp_d *
rho(icol,ilay) * dz(icol,ilay));
111 return ( (nstep == 0) || (nstep % irad == 0) );
constexpr amrex::Real Cp_d
Definition: ERF_Constants.H:12
constexpr amrex::Real CONST_GRAV
Definition: ERF_Constants.H:21
@ rho
Definition: ERF_Kessler.H:30
@ T
Definition: ERF_IndexDefines.H:99
Definition: ERF_RRTMGP_Interface.cpp:15
bool radiation_do(const int irad, const int nstep)
Definition: ERF_RRTMGP_Utils.H:101
void compute_heating_rate(yakl::Array< T, 2, myMem, myStyle > const &flux_up, yakl::Array< T, 2, myMem, myStyle > const &flux_dn, yakl::Array< T, 2, myMem, myStyle > const &rho, yakl::Array< T, 2, myMem, myStyle > const &dz, yakl::Array< T, 2, myMem, myStyle > &heating_rate)
Definition: ERF_RRTMGP_Utils.H:73
void limit_to_bounds(S const &arr_in, T const lower, T const upper, S &arr_out)
Definition: ERF_RRTMGP_Utils.H:49
void mixing_ratio_to_cloud_mass(yakl::Array< T, 2, myMem, myStyle > const &mixing_ratio, yakl::Array< T, 2, myMem, myStyle > const &cloud_fraction, yakl::Array< T, 2, myMem, myStyle > const &dp, yakl::Array< T, 2, myMem, myStyle > &cloud_mass)
Definition: ERF_RRTMGP_Utils.H:23