ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
rrtmgp Namespace Reference

Functions

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real inverse_exner (const amrex::Real pressure, const amrex::Real rdOcp)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void resolve_surface_temperature (const bool is_land, const bool has_lsm_t_sfc, const bool valid_lsm_t_sfc, const amrex::Real lsm_t_sfc, const bool has_surface_layer, const amrex::Real surface_layer_theta, const amrex::Real surface_pressure, const amrex::Real rdOcp, const amrex::Real default_t_sfc, amrex::Real &t_sfc)
 
optical_props2_t get_cloud_optics_sw (const int ncol, const int nlay, cloud_optics_t &cloud_optics, gas_optics_t &kdist, real2d_k &lwp, real2d_k &iwp, real2d_k &rel, real2d_k &rei)
 
optical_props1_t get_cloud_optics_lw (const int ncol, const int nlay, cloud_optics_t &cloud_optics, gas_optics_t &kdist, real2d_k &lwp, real2d_k &iwp, real2d_k &rel, real2d_k &rei)
 
optical_props2_t get_subsampled_clouds (const int ncol, const int nlay, const int nbnd, const int ngpt, optical_props2_t &cloud_optics, gas_optics_t &kdist, real2d_k &cld, real2d_k &p_lay, const bool do_subcol_sampling)
 
optical_props1_t get_subsampled_clouds (const int ncol, const int nlay, const int nbnd, const int ngpt, optical_props1_t &cloud_optics, gas_optics_t &kdist, real2d_k &cld, real2d_k &p_lay, const bool do_subcol_sampling)
 
void rrtmgp_initialize (gas_concs_t &gas_concs_k, const std::string &coefficients_file_sw, const std::string &coefficients_file_lw, const std::string &cloud_optics_file_sw, const std::string &cloud_optics_file_lw, const int &nvar)
 
void rrtmgp_finalize ()
 
void compute_band_by_band_surface_albedos (const int ncol, const int nswbands, real1d_k &sfc_alb_dir_vis, real1d_k &sfc_alb_dir_nir, real1d_k &sfc_alb_dif_vis, real1d_k &sfc_alb_dif_nir, real2d_k &sfc_alb_dir, real2d_k &sfc_alb_dif)
 
void compute_broadband_surface_fluxes (const int ncol, const int kbot, const int nswbands, real3d_k &sw_bnd_flux_dir, real3d_k &sw_bnd_flux_dif, real1d_k &sfc_flux_dir_vis, real1d_k &sfc_flux_dir_nir, real1d_k &sfc_flux_dif_vis, real1d_k &sfc_flux_dif_nir)
 
void rrtmgp_main (const int ncol, const int nlay, real2d_k &p_lay, real2d_k &t_lay, real2d_k &p_lev, real2d_k &t_lev, gas_concs_t &gas_concs, real2d_k &sfc_alb_dir, real2d_k &sfc_alb_dif, real1d_k &mu0, real1d_k &t_sfc, real1d_k &sfc_emis, real1d_k &lw_src, real2d_k &lwp, real2d_k &iwp, real2d_k &rel, real2d_k &rei, real2d_k &cldfrac, real2d_k &sw_flux_up, real2d_k &sw_flux_dn, real2d_k &sw_flux_dn_dir, real2d_k &lw_flux_up, real2d_k &lw_flux_dn, real2d_k &sw_clnclrsky_flux_up, real2d_k &sw_clnclrsky_flux_dn, real2d_k &sw_clnclrsky_flux_dn_dir, real2d_k &sw_clrsky_flux_up, real2d_k &sw_clrsky_flux_dn, real2d_k &sw_clrsky_flux_dn_dir, real2d_k &sw_clnsky_flux_up, real2d_k &sw_clnsky_flux_dn, real2d_k &sw_clnsky_flux_dn_dir, real2d_k &lw_clnclrsky_flux_up, real2d_k &lw_clnclrsky_flux_dn, real2d_k &lw_clrsky_flux_up, real2d_k &lw_clrsky_flux_dn, real2d_k &lw_clnsky_flux_up, real2d_k &lw_clnsky_flux_dn, real3d_k &sw_bnd_flux_up, real3d_k &sw_bnd_flux_dn, real3d_k &sw_bnd_flux_dn_dir, real3d_k &lw_bnd_flux_up, real3d_k &lw_bnd_flux_dn, const RealT tsi_scaling, const bool do_subcol_sampling, const bool extra_clnclrsky_diag, const bool extra_clnsky_diag)
 
int3d_k get_subcolumn_mask (const int ncol, const int nlay, const int ngpt, real2d_k &cldf, const int overlap_option, int1d_k &seeds)
 
void rrtmgp_sw (const int ncol, const int nlay, gas_optics_t &k_dist, real2d_k &p_lay, real2d_k &t_lay, real2d_k &p_lev, real2d_k &t_lev, gas_concs_t &gas_concs, real2d_k &sfc_alb_dir, real2d_k &sfc_alb_dif, real1d_k &mu0, optical_props2_t &aerosol, optical_props2_t &clouds, fluxes_t &fluxes, fluxes_broadband_t &clnclrsky_fluxes, fluxes_broadband_t &clrsky_fluxes, fluxes_broadband_t &clnsky_fluxes, const RealT tsi_scaling, const bool extra_clnclrsky_diag, const bool extra_clnsky_diag)
 
void rrtmgp_lw (const int ncol, const int nlay, gas_optics_t &k_dist, real2d_k &p_lay, real2d_k &t_lay, real2d_k &p_lev, real2d_k &t_lev, real1d_k &t_sfc, real1d_k &sfc_emis, [[maybe_unused]] real1d_k &lw_src, gas_concs_t &gas_concs, optical_props1_t &aerosol, optical_props1_t &clouds, fluxes_t &fluxes, fluxes_broadband_t &clnclrsky_fluxes, fluxes_broadband_t &clrsky_fluxes, fluxes_broadband_t &clnsky_fluxes, const bool extra_clnclrsky_diag, const bool extra_clnsky_diag)
 
void compute_cloud_area (int ncol, int nlay, int ngpt, const RealT pmin, const RealT pmax, const real2d_k &pmid, const real3d_k &cld_tau_gpt, real1d_k &cld_area)
 
int get_wavelength_index_sw (RealT wavelength)
 
int get_wavelength_index_lw (RealT wavelength)
 
int get_wavelength_index (optical_props_t &kdist, RealT wavelength)
 
void compute_aerocom_cloudtop (int ncol, int nlay, const real2d_k &tmid, const real2d_k &pmid, const real2d_k &p_del, const real2d_k &z_del, const real2d_k &qc, const real2d_k &qi, const real2d_k &rel, const real2d_k &rei, const real2d_k &cldfrac_tot, const real2d_k &nc, real1d_k &T_mid_at_cldtop, real1d_k &p_mid_at_cldtop, real1d_k &cldfrac_ice_at_cldtop, real1d_k &cldfrac_liq_at_cldtop, real1d_k &cldfrac_tot_at_cldtop, real1d_k &cdnc_at_cldtop, real1d_k &eff_radius_qc_at_cldtop, real1d_k &eff_radius_qi_at_cldtop)
 
void rrtmgp_lw (const int ncol, const int nlay, gas_optics_t &k_dist, real2d_k &p_lay, real2d_k &t_lay, real2d_k &p_lev, real2d_k &t_lev, real1d_k &t_sfc, real1d_k &sfc_emis, real1d_k &lw_src, gas_concs_t &gas_concs, optical_props1_t &aerosol, optical_props1_t &clouds, fluxes_t &fluxes, fluxes_broadband_t &clnclrsky_fluxes, fluxes_broadband_t &clrsky_fluxes, fluxes_broadband_t &clnsky_fluxes, const bool extra_clnclrsky_diag, const bool extra_clnsky_diag)
 
template<class View1 , class View2 , class View3 , class View4 , class View5 >
void mixing_ratio_to_cloud_mass (View1 const &mixing_ratio, View2 const &cloud_fraction, View3 const &rho, View4 const &dz, View5 const &cloud_mass)
 
template<typename InT , typename OutT , typename T >
void limit_to_bounds_1d (InT const &arr_in, T const lower, T const upper, OutT &arr_out)
 
template<typename InT , typename OutT , typename T >
void limit_to_bounds_2d (InT const &arr_in, T const lower, T const upper, OutT &arr_out)
 
template<class View1 , class View2 , class View3 , class View4 , class View5 >
void compute_heating_rate (View1 const &flux_up, View2 const &flux_dn, View3 const &rho, View4 const &dz, View5 &heating_rate)
 
bool radiation_do (const int irad, const int nstep)
 

Variables

std::unique_ptr< gas_optics_t > k_dist_sw_k
 
std::unique_ptr< gas_optics_t > k_dist_lw_k
 
std::unique_ptr< cloud_optics_t > cloud_optics_sw_k
 
std::unique_ptr< cloud_optics_t > cloud_optics_lw_k
 
pool_t kokkos_mem_pool
 
bool initialized = false
 
size_t pool_max_ncol = 0
 
size_t pool_max_nlay = 0
 
int pool_nvar = 0
 

Function Documentation

◆ compute_aerocom_cloudtop()

void rrtmgp::compute_aerocom_cloudtop ( int  ncol,
int  nlay,
const real2d_k &  tmid,
const real2d_k &  pmid,
const real2d_k &  p_del,
const real2d_k &  z_del,
const real2d_k &  qc,
const real2d_k &  qi,
const real2d_k &  rel,
const real2d_k &  rei,
const real2d_k &  cldfrac_tot,
const real2d_k &  nc,
real1d_k &  T_mid_at_cldtop,
real1d_k &  p_mid_at_cldtop,
real1d_k &  cldfrac_ice_at_cldtop,
real1d_k &  cldfrac_liq_at_cldtop,
real1d_k &  cldfrac_tot_at_cldtop,
real1d_k &  cdnc_at_cldtop,
real1d_k &  eff_radius_qc_at_cldtop,
real1d_k &  eff_radius_qi_at_cldtop 
)
1166 {
1167  /* The goal of this routine is to calculate properties at cloud top
1168  * based on the AeroCom recommendation. See reference for routine
1169  * get_subcolumn_mask above, where equation 14 is used for the
1170  * maximum-random overlap assumption for subcolumn generation. We use
1171  * equation 13, the column counterpart.
1172  */
1173  // Set outputs to zero
1174  Kokkos::deep_copy(T_mid_at_cldtop, zero);
1175  Kokkos::deep_copy(p_mid_at_cldtop, zero);
1176  Kokkos::deep_copy(cldfrac_ice_at_cldtop, zero);
1177  Kokkos::deep_copy(cldfrac_liq_at_cldtop, zero);
1178  Kokkos::deep_copy(cldfrac_tot_at_cldtop, zero);
1179  Kokkos::deep_copy(cdnc_at_cldtop, zero);
1180  Kokkos::deep_copy(eff_radius_qc_at_cldtop, zero);
1181  Kokkos::deep_copy(eff_radius_qi_at_cldtop, zero);
1182 
1183  // Initialize the 1D "clear fraction" as 1 (totally clear)
1184  real1d_k aerocom_clr("aerocom_clr", ncol);
1185  Kokkos::deep_copy(aerocom_clr, one);
1186 
1187  // TODO: move tunable constant to namelist
1188  constexpr RealT q_threshold = zero; // BAD_CONSTANT!
1189 
1190  // TODO: move tunable constant to namelist
1191  constexpr RealT cldfrac_tot_threshold = amrex::Real(0.001); // BAD_CONSTANT!
1192 
1193  // Loop over all columns in parallel
1194  Kokkos::parallel_for(ncol, KOKKOS_LAMBDA(int icol)
1195  {
1196  // Loop over all layers in serial (due to accumulative
1197  // product), starting at 2 (second highest) layer because the
1198  // highest is assumed to have no clouds
1199  for(int ilay = 1; ilay < nlay; ++ilay) {
1200  // Only do the calculation if certain conditions are met
1201  if((qc(icol, ilay) + qi(icol, ilay)) > q_threshold &&
1202  (cldfrac_tot(icol, ilay) > cldfrac_tot_threshold)) {
1203  /* PART I: Probabilistically determining cloud top */
1204  // Populate aerocom_tmp as the clear-sky fraction
1205  // probability of this level, where aerocom_clr is that of
1206  // the previous level
1207  auto aerocom_tmp = aerocom_clr(icol) *
1208  (one - std::max(cldfrac_tot(icol, ilay - 1),
1209  cldfrac_tot(icol, ilay))) /
1210  (one - std::min(cldfrac_tot(icol, ilay - 1),
1211  one - cldfrac_tot_threshold));
1212  // Temporary variable for probability "weights"
1213  auto aerocom_wts = aerocom_clr(icol) - aerocom_tmp;
1214  // Temporary variable for liquid "phase"
1215  auto aerocom_phi = qc(icol, ilay) / (qc(icol, ilay) + qi(icol, ilay));
1216  /* PART II: The inferred properties */
1217  /* In general, converting a 3D property X to a 2D cloud-top
1218  * counterpart x follows: x(i) += X(i,k) * weights * Phase
1219  * but X and Phase are not always needed */
1220  // T_mid_at_cldtop
1221  T_mid_at_cldtop(icol) += tmid(icol, ilay) * aerocom_wts;
1222  // p_mid_at_cldtop
1223  p_mid_at_cldtop(icol) += pmid(icol, ilay) * aerocom_wts;
1224  // cldfrac_ice_at_cldtop
1225  cldfrac_ice_at_cldtop(icol) += (one - aerocom_phi) * aerocom_wts;
1226  // cldfrac_liq_at_cldtop
1227  cldfrac_liq_at_cldtop(icol) += aerocom_phi * aerocom_wts;
1228  // cdnc_at_cldtop
1229  /* We need to convert nc from 1/mass to 1/volume first, and
1230  * from grid-mean to in-cloud, but after that, the
1231  * calculation follows the general logic */
1232  // AML NOTE: p_del/z_del/g should be replaced with RHO for our dycore
1233  auto cdnc = nc(icol, ilay) * p_del(icol, ilay) /
1234  z_del(icol, ilay) / CONST_GRAV /
1235  cldfrac_tot(icol, ilay);
1236  cdnc_at_cldtop(icol) += cdnc * aerocom_phi * aerocom_wts;
1237  // eff_radius_qc_at_cldtop
1238  eff_radius_qc_at_cldtop(icol) += rel(icol, ilay) * aerocom_phi * aerocom_wts;
1239  // eff_radius_qi_at_cldtop
1240  eff_radius_qi_at_cldtop(icol) += rei(icol, ilay) * (one - aerocom_phi) * aerocom_wts;
1241  // Reset aerocom_clr to aerocom_tmp to accumulate
1242  aerocom_clr(icol) = aerocom_tmp;
1243  }
1244  }
1245  // After the serial loop over levels, the cloudy fraction is
1246  // defined as (1 - aerocom_clr). This is true because
1247  // aerocom_clr is the result of accumulative probabilities
1248  // (their products)
1249  cldfrac_tot_at_cldtop(icol) = one - aerocom_clr(icol);
1250  });
1251 }
constexpr amrex::Real CONST_GRAV
Definition: ERF_Constants.H:72
Kokkos::View< RealT *, KokkosDefaultDevice > real1d_k
Definition: ERF_Kokkos.H:18
amrex::Real RealT
Definition: ERF_Kokkos.H:13
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36
@ nc
Definition: ERF_Morrison.H:47
@ qi
Definition: ERF_Morrison.H:111
@ qc
Definition: ERF_Morrison.H:110

◆ compute_band_by_band_surface_albedos()

void rrtmgp::compute_band_by_band_surface_albedos ( const int  ncol,
const int  nswbands,
real1d_k &  sfc_alb_dir_vis,
real1d_k &  sfc_alb_dir_nir,
real1d_k &  sfc_alb_dif_vis,
real1d_k &  sfc_alb_dif_nir,
real2d_k &  sfc_alb_dir,
real2d_k &  sfc_alb_dif 
)
301 {
302  auto wavenumber_limits = k_dist_sw_k->get_band_lims_wavenumber();
303 
304  // Loop over bands, and determine for each band whether it is broadly in the
305  // visible or infrared part of the spectrum (visible or "not visible")
306  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {ncol, nswbands}),
307  KOKKOS_LAMBDA (int icol, int ibnd)
308  {
309  // Threshold between visible and infrared is amrex::Real(0.7) micron, or 14286 cm^-one
310  const RealT visible_wavenumber_threshold = amrex::Real(14286.0);
311 
312  // Wavenumber is in the visible if it is above the visible wavenumber
313  // threshold, and in the infrared if it is below the threshold
314  const bool is_visible_wave1 = (wavenumber_limits(0, ibnd) > visible_wavenumber_threshold ? true : false);
315  const bool is_visible_wave2 = (wavenumber_limits(1, ibnd) > visible_wavenumber_threshold ? true : false);
316 
317  if (is_visible_wave1 && is_visible_wave2) {
318  // Entire band is in the visible
319  sfc_alb_dir(icol,ibnd) = sfc_alb_dir_vis(icol);
320  sfc_alb_dif(icol,ibnd) = sfc_alb_dif_vis(icol);
321  } else if (!is_visible_wave1 && !is_visible_wave2) {
322  // Entire band is in the longwave (near-infrared)
323  sfc_alb_dir(icol,ibnd) = sfc_alb_dir_nir(icol);
324  sfc_alb_dif(icol,ibnd) = sfc_alb_dif_nir(icol);
325  } else {
326  // Band straddles the visible to near-infrared transition, so we take
327  // the albedo to be the average of the visible and near-infrared
328  // broadband albedos
329  sfc_alb_dir(icol,ibnd) = myhalf*(sfc_alb_dir_vis(icol) + sfc_alb_dir_nir(icol));
330  sfc_alb_dif(icol,ibnd) = myhalf*(sfc_alb_dif_vis(icol) + sfc_alb_dif_nir(icol));
331  }
332  });
333 }
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
std::unique_ptr< gas_optics_t > k_dist_sw_k
Definition: ERF_RRTMGP_Interface.cpp:11

Referenced by Radiation::run_impl().

Here is the caller graph for this function:

◆ compute_broadband_surface_fluxes()

void rrtmgp::compute_broadband_surface_fluxes ( const int  ncol,
const int  kbot,
const int  nswbands,
real3d_k &  sw_bnd_flux_dir,
real3d_k &  sw_bnd_flux_dif,
real1d_k &  sfc_flux_dir_vis,
real1d_k &  sfc_flux_dir_nir,
real1d_k &  sfc_flux_dif_vis,
real1d_k &  sfc_flux_dif_nir 
)
346 {
347  // Band 10 straddles the near-IR and visible, so divide contributions from band 10 between both broadband sums
348  // TODO: Hard-coding these band indices is really bad practice. If the bands ever were to change (like when
349  // the RRTMG bands were re-ordered for RRTMGP), we would be using the wrong bands for the IR and UV/VIS. This
350  // should be refactored to grab the correct bands by specifying appropriate wavenumber rather than index.
351  //sfc_flux_dir_nir(i) = sum(sw_bnd_flux_dir(i+1,kbot,1:9)) + myhalf * sw_bnd_flux_dir(i+1,kbot,10);
352  //sfc_flux_dir_vis(i) = sum(sw_bnd_flux_dir(i+1,kbot,11:14)) + myhalf * sw_bnd_flux_dir(i+1,kbot,10);
353  //sfc_flux_dif_nir(i) = sum(sw_bnd_flux_dif(i+1,kbot,1:9)) + myhalf * sw_bnd_flux_dif(i+1,kbot,10);
354  //sfc_flux_dif_vis(i) = sum(sw_bnd_flux_dif(i+1,kbot,11:14)) + myhalf * sw_bnd_flux_dif(i+1,kbot,10);
355 
356  // Initialize sums over bands
357  Kokkos::deep_copy(sfc_flux_dir_nir, 0);
358  Kokkos::deep_copy(sfc_flux_dir_vis, 0);
359  Kokkos::deep_copy(sfc_flux_dif_nir, 0);
360  Kokkos::deep_copy(sfc_flux_dif_vis, 0);
361 
362  // Threshold between visible and infrared is amrex::Real(0.7) micron, or 14286 cm^-one
363  const RealT visible_wavenumber_threshold = amrex::Real(14286.0);
364  auto wavenumber_limits = k_dist_sw_k->get_band_lims_wavenumber();
365  Kokkos::parallel_for(ncol, KOKKOS_LAMBDA(const int icol)
366  {
367  for (int ibnd = 0; ibnd < nswbands; ++ibnd) {
368  // Wavenumber is in the visible if it is above the visible wavenumber
369  // threshold, and in the infrared if it is below the threshold
370  const bool is_visible_wave1 = (wavenumber_limits(0, ibnd) > visible_wavenumber_threshold ? true : false);
371  const bool is_visible_wave2 = (wavenumber_limits(1, ibnd) > visible_wavenumber_threshold ? true : false);
372 
373  if (is_visible_wave1 && is_visible_wave2) {
374  // Entire band is in the visible
375  sfc_flux_dir_vis(icol) += sw_bnd_flux_dir(icol,kbot,ibnd);
376  sfc_flux_dif_vis(icol) += sw_bnd_flux_dif(icol,kbot,ibnd);
377  } else if (!is_visible_wave1 && !is_visible_wave2) {
378  // Entire band is in the longwave (near-infrared)
379  sfc_flux_dir_nir(icol) += sw_bnd_flux_dir(icol,kbot,ibnd);
380  sfc_flux_dif_nir(icol) += sw_bnd_flux_dif(icol,kbot,ibnd);
381  } else {
382  // Band straddles the visible to near-infrared transition, so put myhalf
383  // the flux in visible and myhalf in near-infrared fluxes
384  sfc_flux_dir_vis(icol) += myhalf * sw_bnd_flux_dir(icol,kbot,ibnd);
385  sfc_flux_dif_vis(icol) += myhalf * sw_bnd_flux_dif(icol,kbot,ibnd);
386  sfc_flux_dir_nir(icol) += myhalf * sw_bnd_flux_dir(icol,kbot,ibnd);
387  sfc_flux_dif_nir(icol) += myhalf * sw_bnd_flux_dif(icol,kbot,ibnd);
388  }
389  }
390  });
391 }

Referenced by Radiation::run_impl().

Here is the caller graph for this function:

◆ compute_cloud_area()

void rrtmgp::compute_cloud_area ( int  ncol,
int  nlay,
int  ngpt,
const RealT  pmin,
const RealT  pmax,
const real2d_k &  pmid,
const real3d_k &  cld_tau_gpt,
real1d_k &  cld_area 
)
1091 {
1092  // Subcolumn binary cld mask; if any layers with pressure between pmin and pmax are cloudy
1093  // then 2d subcol mask is 1, otherwise it is 0
1094  real2d_k subcol_mask("subcol_mask", ncol, ngpt);
1095  Kokkos::deep_copy(subcol_mask, zero);
1096  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<3>>({0, 0, 0}, {ncol, nlay, ngpt}),
1097  KOKKOS_LAMBDA (int icol, int ilay, int igpt)
1098  {
1099  // NOTE: using plev would need to assume level ordering (top to bottom or bottom to top), but
1100  // using play/pmid does not
1101  if (cld_tau_gpt(icol,ilay,igpt) > 0 && pmid(icol,ilay) >= pmin && pmid(icol,ilay) < pmax) {
1102  subcol_mask(icol,igpt) = one;
1103  }
1104  });
1105  // Compute average over subcols to get cloud area
1106  auto ngpt_inv = one / ngpt;
1107  Kokkos::deep_copy(cld_area, 0);
1108  Kokkos::parallel_for(ncol, KOKKOS_LAMBDA(int icol)
1109  {
1110  // This loop needs to be serial because of the atomic reduction
1111  for (int igpt = 0; igpt < ngpt; ++igpt) {
1112  cld_area(icol) += subcol_mask(icol,igpt) * ngpt_inv;
1113  }
1114  });
1115 }
Kokkos::View< RealT **, layout_t, KokkosDefaultDevice > real2d_k
Definition: ERF_Kokkos.H:19

◆ compute_heating_rate()

template<class View1 , class View2 , class View3 , class View4 , class View5 >
void rrtmgp::compute_heating_rate ( View1 const &  flux_up,
View2 const &  flux_dn,
View3 const &  rho,
View4 const &  dz,
View5 &  heating_rate 
)
86 {
87  const int ncol = (int)flux_up.extent(0);
88  const int nlay = (int)flux_up.extent(1)-1;
89  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {ncol, nlay}),
90  KOKKOS_LAMBDA (int icol, int ilay)
91  {
92  // NOTE: This calculation defines Fnet = Up - Dn
93  // H = dT/dt = g/Cp dF/dP
94  // Using dF/dz * dz/dP = dF/dz * (1/(-rho*g)) = dF/dP
95  // We have: dT/dt = dF/dz * (1/(-rho*Cp))
96  heating_rate(icol,ilay) = ( flux_up(icol,ilay+1) - flux_up(icol,ilay)
97  - flux_dn(icol,ilay+1) + flux_dn(icol,ilay) )
98  / ( -rho(icol,ilay) * dz(icol,ilay) * Cp_d );
99  });
100 }
constexpr amrex::Real Cp_d
Definition: ERF_Constants.H:51
@ rho
Definition: ERF_Kessler.H:25
@ dz
Definition: ERF_AdvanceWDM6.cpp:273

Referenced by Radiation::finalize_impl(), and Radiation::run_impl().

Here is the caller graph for this function:

◆ get_cloud_optics_lw()

optical_props1_t rrtmgp::get_cloud_optics_lw ( const int  ncol,
const int  nlay,
cloud_optics_t &  cloud_optics,
gas_optics_t &  kdist,
real2d_k &  lwp,
real2d_k &  iwp,
real2d_k &  rel,
real2d_k &  rei 
)
76 {
77  // Initialize optics
78  optical_props1_t clouds;
79  clouds.init(kdist.get_band_lims_wavenumber());
80  clouds.alloc_1scl(ncol, nlay);
81 
82  // Needed for consistency with all-sky example problem?
83  cloud_optics.set_ice_roughness(2);
84 
85  // Limit effective radii to be within bounds of lookup table
86  real2d_k rel_limited("rel_limited", ncol, nlay);
87  real2d_k rei_limited("rei_limited", ncol, nlay);
88  limit_to_bounds_2d(rel, cloud_optics.radliq_lwr,
89  cloud_optics.radliq_upr, rel_limited);
90  limit_to_bounds_2d(rei, cloud_optics.radice_lwr,
91  cloud_optics.radice_upr, rei_limited);
92 
93  // Calculate cloud optics
94  cloud_optics.cloud_optics(ncol, nlay, lwp, iwp, rel_limited, rei_limited, clouds);
95 
96  // Return optics
97  return clouds;
98 }
OpticalProps1sclK< RealT, layout_t, KokkosDefaultDevice > optical_props1_t
Definition: ERF_RRTMGP_Interface.H:35
void limit_to_bounds_2d(InT const &arr_in, T const lower, T const upper, OutT &arr_out)
Definition: ERF_RRTMGP_Utils.H:55

Referenced by rrtmgp_main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_cloud_optics_sw()

optical_props2_t rrtmgp::get_cloud_optics_sw ( const int  ncol,
const int  nlay,
cloud_optics_t &  cloud_optics,
gas_optics_t &  kdist,
real2d_k &  lwp,
real2d_k &  iwp,
real2d_k &  rel,
real2d_k &  rei 
)
42 {
43  // Initialize optics
44  optical_props2_t clouds;
45  clouds.init(kdist.get_band_lims_wavenumber());
46  clouds.alloc_2str(ncol, nlay);
47 
48  // Needed for consistency with all-sky example problem?
49  cloud_optics.set_ice_roughness(2);
50 
51  // Limit effective radii to be within bounds of lookup table
52  real2d_k rel_limited("rel_limited", ncol, nlay);
53  real2d_k rei_limited("rei_limited", ncol, nlay);
54  limit_to_bounds_2d(rel, cloud_optics.radliq_lwr,
55  cloud_optics.radliq_upr, rel_limited);
56  limit_to_bounds_2d(rei, cloud_optics.radice_lwr,
57  cloud_optics.radice_upr, rei_limited);
58 
59  // Calculate cloud optics
60  cloud_optics.cloud_optics(ncol, nlay, lwp, iwp, rel_limited, rei_limited, clouds);
61 
62  // Return optics
63  return clouds;
64 }
OpticalProps2strK< RealT, layout_t, KokkosDefaultDevice > optical_props2_t
Definition: ERF_RRTMGP_Interface.H:36

Referenced by rrtmgp_main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_subcolumn_mask()

int3d_k rrtmgp::get_subcolumn_mask ( const int  ncol,
const int  nlay,
const int  ngpt,
real2d_k &  cldf,
const int  overlap_option,
int1d_k &  seeds 
)
534 {
535  // Routine will return subcolumn mask with values of 0 indicating no cloud, 1 indicating cloud
536  int3d_k subcolumn_mask("subcolumn_mask", ncol, nlay, ngpt);
537 
538  // Subcolumn generators are a means for producing a variable x(i,j,k), where
539  //
540  // c(i,j,k) = 1 for x(i,j,k) > 1 - cldf(i,j)
541  // c(i,j,k) = 0 for x(i,j,k) <= 1 - cldf(i,j)
542  //
543  // I am going to call this "cldx" to be just slightly less ambiguous
544  real3d_k cldx("cldx", ncol, nlay, ngpt);
545 
546  // Apply overlap assumption to set cldx
547  if (overlap_option == 0) { // Dummy mask, always cloudy
548  Kokkos::deep_copy(cldx, 1);
549  } else { // Default case, maximum-random overlap
550  // Maximum-random overlap:
551  // Uses essentially the algorithm described in eq (14) in Raisanen et al. 2004,
552  // https://rmets.onlinelibrary.wiley.com/doi/epdf/amrex::Real(10.1256)/qj.03.99. Also the same
553  // algorithm used in RRTMG implementation of maximum-random overlap (see
554  // https://github.com/AER-RC/RRTMG_SW/blob/master/src/mcica_subcol_gen_sw.f90)
555  //
556  // First, fill cldx with random numbers.
557  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<3>>({0, 0, 0}, {ncol, nlay, ngpt}),
558  KOKKOS_LAMBDA (int icol, int ilay, int igpt)
559  {
560  conv::Random rand(seeds(icol) + ilay*ngpt + igpt);
561  cldx(icol,ilay,igpt) = rand.genFP<RealT>();
562  });
563 
564  // Step down columns and apply algorithm from eq (14)
565  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {ncol, ngpt}),
566  KOKKOS_LAMBDA (int icol, int igpt)
567  {
568  for (int ilay = 1; ilay < nlay; ilay++) {
569  // Check cldx in level above and see if it satisfies conditions to create a cloudy subcolumn
570  if (cldx(icol,ilay-1,igpt) > one - cldf(icol,ilay-1)) {
571  // Cloudy subcolumn above, use same random number here so that clouds in these two adjacent
572  // layers are maximimally overlapped
573  cldx(icol,ilay,igpt) = cldx(icol,ilay-1,igpt);
574  } else {
575  // Cloud-less above, use new random number so that clouds are distributed
576  // randomly in this layer. Need to scale new random number to range
577  // [0, one - cldf(ilay-1)] because we have artificially changed the distribution
578  // of random numbers in this layer with the above branch of the conditional,
579  // which would otherwise inflate cloud fraction in this layer.
580  cldx(icol,ilay,igpt) = cldx(icol,ilay ,igpt) * (one - cldf(icol,ilay-1));
581  }
582  }
583  });
584  }
585 
586  // Use cldx array to create subcolumn mask
587  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<3>>({0, 0, 0}, {ncol, nlay, ngpt}),
588  KOKKOS_LAMBDA (int icol, int ilay, int igpt)
589  {
590  if (cldx(icol,ilay,igpt) > one - cldf(icol,ilay)) {
591  subcolumn_mask(icol,ilay,igpt) = 1;
592  } else {
593  subcolumn_mask(icol,ilay,igpt) = 0;
594  }
595  });
596  return subcolumn_mask;
597 }
Kokkos::View< RealT ***, layout_t, KokkosDefaultDevice > real3d_k
Definition: ERF_Kokkos.H:20
Kokkos::View< int ***, layout_t, KokkosDefaultDevice > int3d_k
Definition: ERF_Kokkos.H:23

Referenced by get_subsampled_clouds().

Here is the caller graph for this function:

◆ get_subsampled_clouds() [1/2]

optical_props1_t rrtmgp::get_subsampled_clouds ( const int  ncol,
const int  nlay,
const int  nbnd,
const int  ngpt,
optical_props1_t &  cloud_optics,
gas_optics_t &  kdist,
real2d_k &  cld,
real2d_k &  p_lay,
const bool  do_subcol_sampling 
)
180 {
181  // Initialized subsampled optics
182  optical_props1_t subsampled_optics;
183  subsampled_optics.init(kdist.get_band_lims_wavenumber(), kdist.get_band_lims_gpoint(), "subsampled_optics");
184  subsampled_optics.alloc_1scl(ncol, nlay);
185 
186  // Check that we do not have clouds with no optical properties; this would get corrected
187  // when we assign optical props, but we want to use a "radiative cloud fraction"
188  // for the subcolumn sampling too because otherwise we can get vertically-contiguous cloud
189  // mask profiles with no actual cloud properties in between, which would just further overestimate
190  // the vertical correlation of cloudy layers. I.e., cloudy layers might look maximally overlapped
191  // even when separated by layers with no cloud properties, when in fact those layers should be
192  // randomly overlapped.
193  real2d_k cldfrac_rad("cldfrac_rad", ncol, nlay);
194  Kokkos::deep_copy(cldfrac_rad, zero);
195  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<3>>({0, 0, 0}, {ncol, nlay, nbnd}),
196  KOKKOS_LAMBDA (int icol, int ilay, int ibnd)
197  {
198  if (cloud_optics.tau(icol,ilay,ibnd) > 0) {
199  cldfrac_rad(icol,ilay) = cld(icol,ilay);
200  }
201  });
202 
203  // Get subcolumn cloud mask (see the shortwave overload for the overlap options)
204  int overlap = do_subcol_sampling ? 1 : 0;
205  // Get unique seeds for each column that are reproducible across different MPI rank layouts;
206  // use decimal part of pressure for this, consistent with the implementation in EAM; use different
207  // seed values for longwave and shortwave
208  int1d_k seeds("seeds", ncol);
209  Kokkos::parallel_for(ncol, KOKKOS_LAMBDA(int icol)
210  {
211  seeds(icol) = 1e9 * (p_lay(icol,nlay-1) - int(p_lay(icol,nlay-1)));
212  });
213  auto cldmask = get_subcolumn_mask(ncol, nlay, ngpt, cldfrac_rad, overlap, seeds);
214 
215  // Assign optical properties to subcolumns (note this implements MCICA)
216  auto gpoint_bands = kdist.get_gpoint_bands();
217  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<3>>({0, 0, 0}, {ncol, nlay, ngpt}),
218  KOKKOS_LAMBDA (int icol, int ilay, int igpt)
219  {
220  auto ibnd = gpoint_bands(igpt);
221  if (cldmask(icol,ilay,igpt) == 1) {
222  subsampled_optics.tau(icol,ilay,igpt) = cloud_optics.tau(icol,ilay,ibnd);
223  } else {
224  subsampled_optics.tau(icol,ilay,igpt) = 0;
225  }
226  });
227  return subsampled_optics;
228 }
Kokkos::View< int *, KokkosDefaultDevice > int1d_k
Definition: ERF_Kokkos.H:21
int3d_k get_subcolumn_mask(const int ncol, const int nlay, const int ngpt, real2d_k &cldf, const int overlap_option, int1d_k &seeds)
Definition: ERF_RRTMGP_Interface.cpp:528
Here is the call graph for this function:

◆ get_subsampled_clouds() [2/2]

optical_props2_t rrtmgp::get_subsampled_clouds ( const int  ncol,
const int  nlay,
const int  nbnd,
const int  ngpt,
optical_props2_t &  cloud_optics,
gas_optics_t &  kdist,
real2d_k &  cld,
real2d_k &  p_lay,
const bool  do_subcol_sampling 
)
111 {
112  // Initialized subsampled optics
113  optical_props2_t subsampled_optics;
114  subsampled_optics.init(kdist.get_band_lims_wavenumber(), kdist.get_band_lims_gpoint(), "subsampled_optics");
115  subsampled_optics.alloc_2str(ncol, nlay);
116 
117  // Check that we do not have clouds with no optical properties; this would get corrected
118  // when we assign optical props, but we want to use a "radiative cloud fraction"
119  // for the subcolumn sampling too because otherwise we can get vertically-contiguous cloud
120  // mask profiles with no actual cloud properties in between, which would just further overestimate
121  // the vertical correlation of cloudy layers. I.e., cloudy layers might look maximally overlapped
122  // even when separated by layers with no cloud properties, when in fact those layers should be
123  // randomly overlapped.
124  real2d_k cldfrac_rad("cldfrac_rad", ncol, nlay);
125  Kokkos::deep_copy(cldfrac_rad, zero);
126  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<3>>({0, 0, 0}, {ncol, nlay, nbnd}),
127  KOKKOS_LAMBDA (int icol, int ilay, int ibnd)
128  {
129  if (cloud_optics.tau(icol,ilay,ibnd) > 0) {
130  cldfrac_rad(icol,ilay) = cld(icol,ilay);
131  }
132  });
133 
134  // Get subcolumn cloud mask; get_subcolumn_mask supports overlap options 0 (trivial all-or-nothing
135  // cloud: any layer with nonzero radiative cloud fraction is overcast in every gpoint) or 1 (max-rand
136  // MCICA sampling), selected here by erf.rad_do_subcol_sampling. In the future, we should support
137  // generalized overlap as well, with parameters derived from DPSCREAM simulations with very
138  // high resolution.
139  int overlap = do_subcol_sampling ? 1 : 0;
140 
141  // Get unique seeds for each column that are reproducible across different MPI rank layouts;
142  // use decimal part of pressure for this, consistent with the implementation in EAM
143  int1d_k seeds("seeds", ncol);
144  Kokkos::parallel_for(ncol, KOKKOS_LAMBDA(int icol)
145  {
146  seeds(icol) = amrex::Real(1.0e9) * (p_lay(icol,nlay-1) - int(p_lay(icol,nlay-1)));
147  });
148  auto cldmask = get_subcolumn_mask(ncol, nlay, ngpt, cldfrac_rad, overlap, seeds);
149 
150  // Assign optical properties to subcolumns (note this implements MCICA)
151  auto gpoint_bands = kdist.get_gpoint_bands();
152  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<3>>({0, 0, 0}, {ncol, nlay, ngpt}),
153  KOKKOS_LAMBDA (int icol, int ilay, int igpt)
154  {
155  auto ibnd = gpoint_bands(igpt);
156  if (cldmask(icol,ilay,igpt) == 1) {
157  subsampled_optics.tau(icol,ilay,igpt) = cloud_optics.tau(icol,ilay,ibnd);
158  subsampled_optics.ssa(icol,ilay,igpt) = cloud_optics.ssa(icol,ilay,ibnd);
159  subsampled_optics.g (icol,ilay,igpt) = cloud_optics.g (icol,ilay,ibnd);
160  } else {
161  subsampled_optics.tau(icol,ilay,igpt) = 0;
162  subsampled_optics.ssa(icol,ilay,igpt) = 0;
163  subsampled_optics.g (icol,ilay,igpt) = 0;
164  }
165  });
166  return subsampled_optics;
167 }

Referenced by rrtmgp_main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_wavelength_index()

int rrtmgp::get_wavelength_index ( optical_props_t &  kdist,
RealT  wavelength 
)
1129 {
1130  // Get wavelength bounds for all wavelength bands
1131  auto band_lims_wvn = kdist.get_band_lims_wavenumber();
1132  real2d_k wavelength_bounds("wavelength_bounds",band_lims_wvn.extent(0), band_lims_wvn.extent(1));
1133  wavelength_bounds = kdist.get_band_lims_wavelength();
1134 
1135  // Find the band index for the specified wavelength
1136  // Note that bands are stored in wavenumber space, units of cm-1, so if we are passed wavelength
1137  // in units of meters, we need a conversion factor of 10^2
1138  int nbnds = kdist.get_nband();
1139  int band_index = -1;
1140  Kokkos::parallel_reduce(nbnds, KOKKOS_LAMBDA(int ibnd, int& band_index_inner)
1141  {
1142  if (wavelength_bounds(0,ibnd) < wavelength_bounds(1,ibnd)) {
1143  if (wavelength_bounds(0,ibnd) <= wavelength * 1e2 && wavelength * 1e2 <= wavelength_bounds(1,ibnd)) {
1144  band_index_inner = ibnd;
1145  }
1146  } else {
1147  if (wavelength_bounds(0,ibnd) >= wavelength * 1e2 && wavelength * 1e2 >= wavelength_bounds(1,ibnd)) {
1148  band_index_inner = ibnd;
1149  }
1150  }
1151  }, Kokkos::Max<int>(band_index));
1152  return band_index;
1153 }
Real wavelength
Definition: ERF_InitCustomPert_MovingTerrain.H:5

Referenced by get_wavelength_index_lw(), and get_wavelength_index_sw().

Here is the caller graph for this function:

◆ get_wavelength_index_lw()

int rrtmgp::get_wavelength_index_lw ( RealT  wavelength)
int get_wavelength_index(optical_props_t &kdist, RealT wavelength)
Definition: ERF_RRTMGP_Interface.cpp:1127
std::unique_ptr< gas_optics_t > k_dist_lw_k
Definition: ERF_RRTMGP_Interface.cpp:12
Here is the call graph for this function:

◆ get_wavelength_index_sw()

int rrtmgp::get_wavelength_index_sw ( RealT  wavelength)
Here is the call graph for this function:

◆ inverse_exner()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real rrtmgp::inverse_exner ( const amrex::Real  pressure,
const amrex::Real  rdOcp 
)
13 {
14  return one / getExnergivenP(pressure, rdOcp);
15 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getExnergivenP(const amrex::Real P, const amrex::Real rdOcp)
Definition: ERF_EOS.H:141
const Real rdOcp
Definition: ERF_InitCustomPert_ABL.H:128

Referenced by Radiation::kokkos_buffers_to_mf(), and Radiation::populateDatalogMF().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ limit_to_bounds_1d()

template<typename InT , typename OutT , typename T >
void rrtmgp::limit_to_bounds_1d ( InT const &  arr_in,
T const  lower,
T const  upper,
OutT &  arr_out 
)
45 {
46  Kokkos::parallel_for(arr_out.size(), KOKKOS_LAMBDA(int i)
47  {
48  arr_out(i) = std::min(std::max(arr_in(i), lower), upper);
49  });
50 }

◆ limit_to_bounds_2d()

template<typename InT , typename OutT , typename T >
void rrtmgp::limit_to_bounds_2d ( InT const &  arr_in,
T const  lower,
T const  upper,
OutT &  arr_out 
)
59 {
60  const int ex0 = (int) arr_out.extent(0);
61  const int ex1 = (int) arr_out.extent(1);
62  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {ex0, ex1}),
63  KOKKOS_LAMBDA (int i, int j)
64  {
65  arr_out(i, j) = std::min(std::max(arr_in(i, j), lower), upper);
66  });
67 }

Referenced by get_cloud_optics_lw(), get_cloud_optics_sw(), rrtmgp_lw(), and rrtmgp_sw().

Here is the caller graph for this function:

◆ mixing_ratio_to_cloud_mass()

template<class View1 , class View2 , class View3 , class View4 , class View5 >
void rrtmgp::mixing_ratio_to_cloud_mass ( View1 const &  mixing_ratio,
View2 const &  cloud_fraction,
View3 const &  rho,
View4 const &  dz,
View5 const &  cloud_mass 
)
17 {
18  const int ncol = mixing_ratio.extent(0);
19  const int nlay = mixing_ratio.extent(1);
20  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {ncol, nlay}),
21  KOKKOS_LAMBDA (int icol, int ilay)
22  {
23  // Compute in-cloud mixing ratio (mixing ratio of the cloudy part of the layer)
24  // NOTE: these thresholds (from E3SM) seem arbitrary, but included here for consistency
25  // This limits in-cloud mixing ratio to amrex::Real(0.005) kg/kg. According to note in cloud_diagnostics
26  // in EAM, this is consistent with limits in MG2. Is this true for P3?
27  if (cloud_fraction(icol,ilay) > 0) {
28  // Compute layer-integrated cloud mass (per unit area)
29  auto incloud_mixing_ratio = std::min(mixing_ratio(icol,ilay) /
30  std::max(amrex::Real(0.0001), cloud_fraction(icol,ilay)), amrex::Real(0.005));
31  cloud_mass(icol,ilay) = incloud_mixing_ratio * rho(icol,ilay) * dz(icol,ilay);
32  } else {
33  cloud_mass(icol,ilay) = 0;
34  }
35  });
36 }

Referenced by Radiation::run_impl().

Here is the caller graph for this function:

◆ radiation_do()

bool rrtmgp::radiation_do ( const int  irad,
const int  nstep 
)
inline
107 {
108  // If irad == 0, then never do radiation;
109  // Otherwise, we always call radiation at the first step,
110  // and afterwards we do radiation if the timestep is divisible
111  // by irad
112  if (irad == 0) {
113  return false;
114  } else {
115  return ( (nstep == 0) || (nstep % irad == 0) );
116  }
117 }

◆ resolve_surface_temperature()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void rrtmgp::resolve_surface_temperature ( const bool  is_land,
const bool  has_lsm_t_sfc,
const bool  valid_lsm_t_sfc,
const amrex::Real  lsm_t_sfc,
const bool  has_surface_layer,
const amrex::Real  surface_layer_theta,
const amrex::Real  surface_pressure,
const amrex::Real  rdOcp,
const amrex::Real  default_t_sfc,
amrex::Real &  t_sfc 
)

Resolve the RRTMGP surface-temperature input from ERF's surface sources.

RRTMGP and LSM surface-temperature fields contain absolute temperature, while the SurfaceLayer field contains potential temperature. The latter must therefore be converted with the physical surface pressure diagnosed from the lowest atmospheric cell before it is handed to RRTMGP.

Parameters
[in]is_landtrue when the column is over land
[in]has_lsm_t_sfctrue when an LSM t_sfc field exists
[in]valid_lsm_t_sfctrue when the LSM value is not a sentinel
[in]lsm_t_sfcLSM t_sfc value, when present
[in]has_surface_layertrue when a SurfaceLayer field exists
[in]surface_layer_thetaSurfaceLayer potential temperature
[in]surface_pressurephysical surface pressure diagnosed from the lowest atmospheric cell
[in]rdOcpconfigured Rd/cp exponent
[in]default_t_sfcconfigured absolute-temperature fallback
[out]t_sfcresolved absolute temperature for RRTMGP
49 {
50  // A valid land-model value is already absolute temperature. A valid LSM
51  // value over water follows the existing fallback chain instead.
52  const bool use_lsm_t_sfc = is_land && has_lsm_t_sfc && valid_lsm_t_sfc;
53 
54  if (use_lsm_t_sfc) {
55  t_sfc = lsm_t_sfc;
56  } else if (has_surface_layer &&
58  surface_layer_theta, surface_pressure, rdOcp, t_sfc)) {
59  // SurfaceLayer::get_t_surf() returns theta. RRTMGP requires T.
60  // The helper also rejects an invalid pressure or nonphysical theta.
61  } else {
62  t_sfc = default_t_sfc;
63  }
64 
65 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool theta_to_temperature(const amrex::Real theta, const amrex::Real pressure, const amrex::Real rdOcp, amrex::Real &temperature)
Definition: ERF_SurfaceTemperature.H:136

Referenced by Radiation::mf_to_kokkos_buffers().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rrtmgp_finalize()

void rrtmgp::rrtmgp_finalize ( )
278 {
279  initialized = false;
280  k_dist_sw_k->finalize();
281  k_dist_lw_k->finalize();
282  cloud_optics_sw_k->finalize();
283  cloud_optics_lw_k->finalize();
284  k_dist_sw_k = nullptr;
285  k_dist_lw_k = nullptr;
286  cloud_optics_sw_k = nullptr;
287  cloud_optics_lw_k = nullptr;
288  pool_t::finalize();
289 }
std::unique_ptr< cloud_optics_t > cloud_optics_sw_k
Definition: ERF_RRTMGP_Interface.cpp:19
std::unique_ptr< cloud_optics_t > cloud_optics_lw_k
Definition: ERF_RRTMGP_Interface.cpp:20
bool initialized
Definition: ERF_RRTMGP_Interface.cpp:25

Referenced by Radiation::~Radiation().

Here is the caller graph for this function:

◆ rrtmgp_initialize()

void rrtmgp::rrtmgp_initialize ( gas_concs_t &  gas_concs_k,
const std::string &  coefficients_file_sw,
const std::string &  coefficients_file_lw,
const std::string &  cloud_optics_file_sw,
const std::string &  cloud_optics_file_lw,
const int &  nvar 
)
243 {
244  // Initialize Kokkos
245  if (!Kokkos::is_initialized()) { Kokkos::initialize(); }
246 
247  // Create objects for static ptrs
248  k_dist_sw_k = std::make_unique<gas_optics_t>();
249  k_dist_lw_k = std::make_unique<gas_optics_t>();
250  cloud_optics_sw_k = std::make_unique<cloud_optics_t>();
251  cloud_optics_lw_k = std::make_unique<cloud_optics_t>();
252 
253  // Load and initialize absorption coefficient data
254  load_and_init(*k_dist_sw_k, coefficients_file_sw, gas_concs_k);
255  load_and_init(*k_dist_lw_k, coefficients_file_lw, gas_concs_k);
256 
257  // Load and initialize cloud optical property look-up table information
258  load_cld_lutcoeff(*cloud_optics_sw_k, cloud_optics_file_sw);
259  load_cld_lutcoeff(*cloud_optics_lw_k, cloud_optics_file_lw);
260 
261  // Initialize kokkos rrtmgp pool allocator
262  const size_t ngpt = std::max(k_dist_sw_k->get_ngpt(),k_dist_lw_k->get_ngpt());
263  const size_t ncol = gas_concs_k.ncol;
264  const size_t nlay = gas_concs_k.nlay;
265  auto my_size_ref = static_cast<unsigned long>(nvar * ncol * nlay * ngpt);
266  pool_t::init(my_size_ref);
267  pool_max_ncol = ncol;
268  pool_max_nlay = nlay;
269  pool_nvar = nvar;
270 
271  // We are now initialized!
272  initialized = true;
273 }
int pool_nvar
Definition: ERF_RRTMGP_Interface.cpp:30
size_t pool_max_ncol
Definition: ERF_RRTMGP_Interface.cpp:28
size_t pool_max_nlay
Definition: ERF_RRTMGP_Interface.cpp:29

Referenced by Radiation::initialize_impl().

Here is the caller graph for this function:

◆ rrtmgp_lw() [1/2]

void rrtmgp::rrtmgp_lw ( const int  ncol,
const int  nlay,
gas_optics_t &  k_dist,
real2d_k &  p_lay,
real2d_k &  t_lay,
real2d_k &  p_lev,
real2d_k &  t_lev,
real1d_k &  t_sfc,
real1d_k &  sfc_emis,
[[maybe_unused] ] real1d_k &  lw_src,
gas_concs_t &  gas_concs,
optical_props1_t &  aerosol,
optical_props1_t &  clouds,
fluxes_t &  fluxes,
fluxes_broadband_t &  clnclrsky_fluxes,
fluxes_broadband_t &  clrsky_fluxes,
fluxes_broadband_t &  clnsky_fluxes,
const bool  extra_clnclrsky_diag,
const bool  extra_clnsky_diag 
)
924 {
925  // Problem size
926  int nbnd = k_dist.get_nband();
927 
928  // Associate local pointers for fluxes
929  auto& flux_up = fluxes.flux_up;
930  auto& flux_dn = fluxes.flux_dn;
931  auto& bnd_flux_up = fluxes.bnd_flux_up;
932  auto& bnd_flux_dn = fluxes.bnd_flux_dn;
933  auto& clnclrsky_flux_up = clnclrsky_fluxes.flux_up;
934  auto& clnclrsky_flux_dn = clnclrsky_fluxes.flux_dn;
935  auto& clrsky_flux_up = clrsky_fluxes.flux_up;
936  auto& clrsky_flux_dn = clrsky_fluxes.flux_dn;
937  auto& clnsky_flux_up = clnsky_fluxes.flux_up;
938  auto& clnsky_flux_dn = clnsky_fluxes.flux_dn;
939 
940  // Reset fluxes to zero
941  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {ncol, nlay+1}),
942  KOKKOS_LAMBDA (int icol, int ilev)
943  {
944  flux_up(icol, ilev) = 0;
945  flux_dn(icol, ilev) = 0;
946  clrsky_flux_up(icol, ilev) = 0;
947  clrsky_flux_dn(icol, ilev) = 0;
948  });
949  if (extra_clnclrsky_diag) {
950  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {ncol, nlay+1}),
951  KOKKOS_LAMBDA (int icol, int ilev)
952  {
953  clnclrsky_flux_up(icol, ilev) = 0;
954  clnclrsky_flux_dn(icol, ilev) = 0;
955  });
956  }
957  if (extra_clnsky_diag) {
958  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {ncol, nlay+1}),
959  KOKKOS_LAMBDA (int icol, int ilev)
960  {
961  clnsky_flux_up(icol, ilev) = 0;
962  clnsky_flux_dn(icol, ilev) = 0;
963  });
964  }
965  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<3>>({0, 0, 0}, {ncol, nlay+1, nbnd}),
966  KOKKOS_LAMBDA (int icol, int ilev, int ibnd)
967  {
968  bnd_flux_up(icol, ilev, ibnd) = 0;
969  bnd_flux_dn(icol, ilev, ibnd) = 0;
970  });
971 
972  // Allocate space for optical properties
973  optical_props1_t optics;
974  optics.alloc_1scl(ncol, nlay, k_dist);
975 
976  optical_props1_t optics_no_aerosols;
977  if (extra_clnsky_diag) {
978  // Allocate space for optical properties (no aerosols)
979  optics_no_aerosols.alloc_1scl(ncol, nlay, k_dist);
980  }
981 
982  bool top_at_1 = false;
983  Kokkos::parallel_reduce(1, KOKKOS_LAMBDA(int, bool& val)
984  {
985  val |= p_lay(0, 0) < p_lay(0, nlay-1);
986  }, Kokkos::LOr<bool>(top_at_1));
987 
988  // Boundary conditions
989  //=====================================================================
990  source_func_t lw_sources;
991  lw_sources.alloc(ncol, nlay, k_dist);
992 
993  /*
994  // Surface LW source
995  // AML NOTE: This is removed in EAMXX, LSM doesn't transfer its lw_src?
996  auto d_lw_src = lw_sources.sfc_source;
997  Kokkos::parallel_for(ncol, KOKKOS_LAMBDA (int icol)
998  {
999  d_lw_src(icol, 0) = lw_src(icol);
1000  });
1001  */
1002 
1003  // Surface temperature
1004  // AML NOTE: We already populate this when initializing data
1005 
1006 
1007  // Surface emissivity (transposed in RRTMGP)
1008  // AML NOTE: This transfer was removed in EAMXX, LSM doesn't transfer its emis_sfc?
1009  real2d_k emis_sfc_T("emis_sfc",nbnd,ncol);
1010  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {ncol, nbnd}),
1011  KOKKOS_LAMBDA (int icol, int ibnd)
1012  {
1013  emis_sfc_T(ibnd,icol) = sfc_emis(icol);
1014  });
1015  //Kokkos::deep_copy(emis_sfc_T, amrex::Real(0.98));
1016 
1017  // Get Gaussian quadrature weights
1018  // Weights and angle secants for first order (k=1) Gaussian quadrature.
1019  // Values from Table 2, Clough et al, 1992, doi:Real(10.1029)/92JD01419
1020  // after Abramowitz & Stegun 1972, page 921
1021  int constexpr max_gauss_pts = 4;
1022  RealT gauss_Ds_host_raw[max_gauss_pts][max_gauss_pts] = { {amrex::Real(1.66), amrex::Real(1.18350343), amrex::Real(1.09719858), amrex::Real(1.06056257)},
1023  {zero , amrex::Real(2.81649655), amrex::Real(1.69338507), amrex::Real(1.38282560)},
1024  {zero , zero , amrex::Real(4.70941630), amrex::Real(2.40148179)},
1025  {zero , zero , zero , amrex::Real(7.15513024)} };
1026  realHost2d_k gauss_Ds_host(&gauss_Ds_host_raw[0][0], max_gauss_pts, max_gauss_pts);
1027 
1028  RealT gauss_wts_host_raw[max_gauss_pts][max_gauss_pts] = { {myhalf, amrex::Real(0.3180413817), amrex::Real(0.2009319137), amrex::Real(0.1355069134)},
1029  {zero , amrex::Real(0.1819586183), amrex::Real(0.2292411064), amrex::Real(0.2034645680)},
1030  {zero , zero , amrex::Real(0.0698269799), amrex::Real(0.1298475476)},
1031  {zero , zero , zero , amrex::Real(0.0311809710)} };
1032  realHost2d_k gauss_wts_host(&gauss_wts_host_raw[0][0],max_gauss_pts,max_gauss_pts);
1033 
1034  real2d_k gauss_Ds ("gauss_Ds" ,max_gauss_pts,max_gauss_pts);
1035  real2d_k gauss_wts("gauss_wts",max_gauss_pts,max_gauss_pts);
1036  Kokkos::deep_copy(gauss_Ds, gauss_Ds_host);
1037  Kokkos::deep_copy(gauss_wts, gauss_wts_host);
1038 
1039  // Limit temperatures for gas optics look-up tables
1040  real2d_k t_lay_limited("t_lay_limited", ncol, nlay );
1041  real2d_k t_lev_limited("t_lev_limited", ncol, nlay+1);
1042  limit_to_bounds_2d(t_lay, k_dist.get_temp_min(),
1043  k_dist.get_temp_max(), t_lay_limited);
1044  limit_to_bounds_2d(t_lev, k_dist.get_temp_min(),
1045  k_dist.get_temp_max(), t_lev_limited);
1046 
1047  // Do gas optics
1048  real3d_k col_gas("col_gas", ncol, nlay, k_dist.get_ngas()+1);
1049  k_dist.gas_optics(ncol, nlay, top_at_1, p_lay, p_lev, t_lay_limited,
1050  t_sfc, gas_concs, col_gas, optics, lw_sources, view_t<RealT**>(), t_lev_limited);
1051  if (extra_clnsky_diag) {
1052  k_dist.gas_optics(ncol, nlay, top_at_1, p_lay, p_lev, t_lay_limited,
1053  t_sfc, gas_concs, col_gas, optics_no_aerosols, lw_sources, view_t<RealT**>(), t_lev_limited);
1054  }
1055 
1056  if (extra_clnclrsky_diag) {
1057  // Compute clean-clear-sky fluxes before we add in aerosols and clouds
1058  rte_lw(max_gauss_pts, gauss_Ds, gauss_wts, optics, top_at_1, lw_sources, emis_sfc_T, clnclrsky_fluxes);
1059  }
1060 
1061  // Combine gas and aerosol optics
1062  aerosol.increment(optics);
1063 
1064  // Compute clear-sky fluxes before we add in clouds
1065  rte_lw(max_gauss_pts, gauss_Ds, gauss_wts, optics, top_at_1, lw_sources, emis_sfc_T, clrsky_fluxes);
1066 
1067  // Combine gas and cloud optics
1068  clouds.increment(optics);
1069 
1070  // Compute allsky fluxes
1071  rte_lw(max_gauss_pts, gauss_Ds, gauss_wts, optics, top_at_1, lw_sources, emis_sfc_T, fluxes);
1072 
1073  if (extra_clnsky_diag) {
1074  // First increment clouds in optics_no_aerosols
1075  clouds.increment(optics_no_aerosols);
1076  // Compute clean-sky fluxes
1077  rte_lw(max_gauss_pts, gauss_Ds, gauss_wts, optics_no_aerosols, top_at_1, lw_sources, emis_sfc_T, clnsky_fluxes);
1078  }
1079 }
Kokkos::View< RealT **, layout_t, KokkosHostDevice > realHost2d_k
Definition: ERF_Kokkos.H:17
Kokkos::View< T, layout_t, KokkosDefaultDevice > view_t
Definition: ERF_RRTMGP_Interface.H:25
SourceFuncLWK< RealT, layout_t, KokkosDefaultDevice > source_func_t
Definition: ERF_RRTMGP_Interface.H:37

Referenced by rrtmgp_main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rrtmgp_lw() [2/2]

void rrtmgp::rrtmgp_lw ( const int  ncol,
const int  nlay,
gas_optics_t &  k_dist,
real2d_k &  p_lay,
real2d_k &  t_lay,
real2d_k &  p_lev,
real2d_k &  t_lev,
real1d_k &  t_sfc,
real1d_k &  sfc_emis,
real1d_k &  lw_src,
gas_concs_t &  gas_concs,
optical_props1_t &  aerosol,
optical_props1_t &  clouds,
fluxes_t &  fluxes,
fluxes_broadband_t &  clnclrsky_fluxes,
fluxes_broadband_t &  clrsky_fluxes,
fluxes_broadband_t &  clnsky_fluxes,
const bool  extra_clnclrsky_diag,
const bool  extra_clnsky_diag 
)

◆ rrtmgp_main()

void rrtmgp::rrtmgp_main ( const int  ncol,
const int  nlay,
real2d_k &  p_lay,
real2d_k &  t_lay,
real2d_k &  p_lev,
real2d_k &  t_lev,
gas_concs_t &  gas_concs,
real2d_k &  sfc_alb_dir,
real2d_k &  sfc_alb_dif,
real1d_k &  mu0,
real1d_k &  t_sfc,
real1d_k &  sfc_emis,
real1d_k &  lw_src,
real2d_k &  lwp,
real2d_k &  iwp,
real2d_k &  rel,
real2d_k &  rei,
real2d_k &  cldfrac,
real2d_k &  sw_flux_up,
real2d_k &  sw_flux_dn,
real2d_k &  sw_flux_dn_dir,
real2d_k &  lw_flux_up,
real2d_k &  lw_flux_dn,
real2d_k &  sw_clnclrsky_flux_up,
real2d_k &  sw_clnclrsky_flux_dn,
real2d_k &  sw_clnclrsky_flux_dn_dir,
real2d_k &  sw_clrsky_flux_up,
real2d_k &  sw_clrsky_flux_dn,
real2d_k &  sw_clrsky_flux_dn_dir,
real2d_k &  sw_clnsky_flux_up,
real2d_k &  sw_clnsky_flux_dn,
real2d_k &  sw_clnsky_flux_dn_dir,
real2d_k &  lw_clnclrsky_flux_up,
real2d_k &  lw_clnclrsky_flux_dn,
real2d_k &  lw_clrsky_flux_up,
real2d_k &  lw_clrsky_flux_dn,
real2d_k &  lw_clnsky_flux_up,
real2d_k &  lw_clnsky_flux_dn,
real3d_k &  sw_bnd_flux_up,
real3d_k &  sw_bnd_flux_dn,
real3d_k &  sw_bnd_flux_dn_dir,
real3d_k &  lw_bnd_flux_up,
real3d_k &  lw_bnd_flux_dn,
const RealT  tsi_scaling,
const bool  do_subcol_sampling,
const bool  extra_clnclrsky_diag,
const bool  extra_clnsky_diag 
)
416 {
417  // Check if we need to reinitialize the memory pool for larger ncol or nlay
418  // This happens with vertical refinement (more layers) or regridding (more columns per chunk)
419  if (static_cast<size_t>(ncol) > pool_max_ncol || static_cast<size_t>(nlay) > pool_max_nlay) {
420 
421  // Finalize old pool (pass false to avoid printing from every MPI rank)
422  pool_t::finalize(false);
423 
424  // Reinitialize with new larger size using maximum ncol and nlay seen so far
425  // This prevents the pool from shrinking and causing heap overwrites
426  const size_t ngpt = std::max(k_dist_sw_k->get_ngpt(), k_dist_lw_k->get_ngpt());
427  const size_t new_max_ncol = std::max(pool_max_ncol, static_cast<size_t>(ncol));
428  const size_t new_max_nlay = std::max(pool_max_nlay, static_cast<size_t>(nlay));
429  auto my_size_ref = static_cast<unsigned long>(pool_nvar * new_max_ncol * new_max_nlay * ngpt);
430  pool_t::init(my_size_ref);
431  pool_max_ncol = new_max_ncol;
432  pool_max_nlay = new_max_nlay;
433  }
434 
435  // Setup pointers to RRTMGP SW fluxes
436  fluxes_t fluxes_sw;
437  fluxes_sw.flux_up = sw_flux_up;
438  fluxes_sw.flux_dn = sw_flux_dn;
439  fluxes_sw.flux_dn_dir = sw_flux_dn_dir;
440  fluxes_sw.bnd_flux_up = sw_bnd_flux_up;
441  fluxes_sw.bnd_flux_dn = sw_bnd_flux_dn;
442  fluxes_sw.bnd_flux_dn_dir = sw_bnd_flux_dn_dir;
443  // Clean-clear-sky
444  fluxes_broadband_t clnclrsky_fluxes_sw;
445  clnclrsky_fluxes_sw.flux_up = sw_clnclrsky_flux_up;
446  clnclrsky_fluxes_sw.flux_dn = sw_clnclrsky_flux_dn;
447  clnclrsky_fluxes_sw.flux_dn_dir = sw_clnclrsky_flux_dn_dir;
448  // Clear-sky
449  fluxes_broadband_t clrsky_fluxes_sw;
450  clrsky_fluxes_sw.flux_up = sw_clrsky_flux_up;
451  clrsky_fluxes_sw.flux_dn = sw_clrsky_flux_dn;
452  clrsky_fluxes_sw.flux_dn_dir = sw_clrsky_flux_dn_dir;
453  // Clean-sky
454  fluxes_broadband_t clnsky_fluxes_sw;
455  clnsky_fluxes_sw.flux_up = sw_clnsky_flux_up;
456  clnsky_fluxes_sw.flux_dn = sw_clnsky_flux_dn;
457  clnsky_fluxes_sw.flux_dn_dir = sw_clnsky_flux_dn_dir;
458 
459  // Setup pointers to RRTMGP LW fluxes
460  fluxes_t fluxes_lw;
461  fluxes_lw.flux_up = lw_flux_up;
462  fluxes_lw.flux_dn = lw_flux_dn;
463  fluxes_lw.bnd_flux_up = lw_bnd_flux_up;
464  fluxes_lw.bnd_flux_dn = lw_bnd_flux_dn;
465  // Clean-clear-sky
466  fluxes_broadband_t clnclrsky_fluxes_lw;
467  clnclrsky_fluxes_lw.flux_up = lw_clnclrsky_flux_up;
468  clnclrsky_fluxes_lw.flux_dn = lw_clnclrsky_flux_dn;
469  // Clear-sky
470  fluxes_broadband_t clrsky_fluxes_lw;
471  clrsky_fluxes_lw.flux_up = lw_clrsky_flux_up;
472  clrsky_fluxes_lw.flux_dn = lw_clrsky_flux_dn;
473  // Clean-sky
474  fluxes_broadband_t clnsky_fluxes_lw;
475  clnsky_fluxes_lw.flux_up = lw_clnsky_flux_up;
476  clnsky_fluxes_lw.flux_dn = lw_clnsky_flux_dn;
477 
478  auto nswbands = k_dist_sw_k->get_nband();
479  auto nlwbands = k_dist_lw_k->get_nband();
480 
481  // Setup aerosol optical properties
482  optical_props2_t aerosol_sw;
483  optical_props1_t aerosol_lw;
484  aerosol_sw.init(k_dist_sw_k->get_band_lims_wavenumber());
485  aerosol_sw.alloc_2str(ncol, nlay);
486  aerosol_lw.init(k_dist_lw_k->get_band_lims_wavenumber());
487  aerosol_lw.alloc_1scl(ncol, nlay);
488 
489  // Convert cloud physical properties to optical properties for input to RRTMGP
490  optical_props2_t clouds_sw = get_cloud_optics_sw(ncol, nlay,
492  lwp, iwp, rel, rei);
493  optical_props1_t clouds_lw = get_cloud_optics_lw(ncol, nlay,
495  lwp, iwp, rel, rei);
496  // Do subcolumn sampling to map bands -> gpoints based on cloud fraction and overlap assumption;
497  // This implements the Monte Carlo Independent Column Approximation by mapping only a single
498  // subcolumn (cloud state) to each gpoint.
499  auto nswgpts = k_dist_sw_k->get_ngpt();
500  auto clouds_sw_gpt = get_subsampled_clouds(ncol, nlay, nswbands, nswgpts,
501  clouds_sw, *k_dist_sw_k, cldfrac, p_lay,
502  do_subcol_sampling);
503  // Longwave
504  auto nlwgpts = k_dist_lw_k->get_ngpt();
505  auto clouds_lw_gpt = get_subsampled_clouds(ncol, nlay, nlwbands, nlwgpts,
506  clouds_lw, *k_dist_lw_k, cldfrac, p_lay,
507  do_subcol_sampling);
508 
509  // Do shortwave
510  rrtmgp_sw(ncol, nlay,
511  *k_dist_sw_k, p_lay, t_lay, p_lev, t_lev, gas_concs,
512  sfc_alb_dir, sfc_alb_dif, mu0, aerosol_sw, clouds_sw_gpt,
513  fluxes_sw, clnclrsky_fluxes_sw, clrsky_fluxes_sw, clnsky_fluxes_sw,
514  tsi_scaling, extra_clnclrsky_diag, extra_clnsky_diag);
515 
516  // Do longwave
517  rrtmgp_lw(ncol, nlay,
518  *k_dist_lw_k, p_lay, t_lay, p_lev, t_lev,
519  t_sfc, sfc_emis, lw_src,
520  gas_concs, aerosol_lw, clouds_lw_gpt,
521  fluxes_lw, clnclrsky_fluxes_lw, clrsky_fluxes_lw, clnsky_fluxes_lw,
522  extra_clnclrsky_diag, extra_clnsky_diag);
523 
524 }
FluxesBroadbandK< RealT, layout_t, KokkosDefaultDevice > fluxes_broadband_t
Definition: ERF_RRTMGP_Interface.H:33
FluxesBybandK< RealT, layout_t, KokkosDefaultDevice > fluxes_t
Definition: ERF_RRTMGP_Interface.H:32
optical_props1_t get_cloud_optics_lw(const int ncol, const int nlay, cloud_optics_t &cloud_optics, gas_optics_t &kdist, real2d_k &lwp, real2d_k &iwp, real2d_k &rel, real2d_k &rei)
Definition: ERF_RRTMGP_Interface.cpp:68
optical_props2_t get_cloud_optics_sw(const int ncol, const int nlay, cloud_optics_t &cloud_optics, gas_optics_t &kdist, real2d_k &lwp, real2d_k &iwp, real2d_k &rel, real2d_k &rei)
Definition: ERF_RRTMGP_Interface.cpp:34
void rrtmgp_sw(const int ncol, const int nlay, gas_optics_t &k_dist, real2d_k &p_lay, real2d_k &t_lay, real2d_k &p_lev, real2d_k &t_lev, gas_concs_t &gas_concs, real2d_k &sfc_alb_dir, real2d_k &sfc_alb_dif, real1d_k &mu0, optical_props2_t &aerosol, optical_props2_t &clouds, fluxes_t &fluxes, fluxes_broadband_t &clnclrsky_fluxes, fluxes_broadband_t &clrsky_fluxes, fluxes_broadband_t &clnsky_fluxes, const RealT tsi_scaling, const bool extra_clnclrsky_diag, const bool extra_clnsky_diag)
Definition: ERF_RRTMGP_Interface.cpp:601
void rrtmgp_lw(const int ncol, const int nlay, gas_optics_t &k_dist, real2d_k &p_lay, real2d_k &t_lay, real2d_k &p_lev, real2d_k &t_lev, real1d_k &t_sfc, real1d_k &sfc_emis, [[maybe_unused]] real1d_k &lw_src, gas_concs_t &gas_concs, optical_props1_t &aerosol, optical_props1_t &clouds, fluxes_t &fluxes, fluxes_broadband_t &clnclrsky_fluxes, fluxes_broadband_t &clrsky_fluxes, fluxes_broadband_t &clnsky_fluxes, const bool extra_clnclrsky_diag, const bool extra_clnsky_diag)
Definition: ERF_RRTMGP_Interface.cpp:907
optical_props1_t get_subsampled_clouds(const int ncol, const int nlay, const int nbnd, const int ngpt, optical_props1_t &cloud_optics, gas_optics_t &kdist, real2d_k &cld, real2d_k &p_lay, const bool do_subcol_sampling)
Definition: ERF_RRTMGP_Interface.cpp:171

Referenced by Radiation::run_impl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rrtmgp_sw()

void rrtmgp::rrtmgp_sw ( const int  ncol,
const int  nlay,
gas_optics_t &  k_dist,
real2d_k &  p_lay,
real2d_k &  t_lay,
real2d_k &  p_lev,
real2d_k &  t_lev,
gas_concs_t &  gas_concs,
real2d_k &  sfc_alb_dir,
real2d_k &  sfc_alb_dif,
real1d_k &  mu0,
optical_props2_t &  aerosol,
optical_props2_t &  clouds,
fluxes_t &  fluxes,
fluxes_broadband_t &  clnclrsky_fluxes,
fluxes_broadband_t &  clrsky_fluxes,
fluxes_broadband_t &  clnsky_fluxes,
const RealT  tsi_scaling,
const bool  extra_clnclrsky_diag,
const bool  extra_clnsky_diag 
)
618 {
619  // Get problem sizes
620  int nbnd = k_dist.get_nband();
621  int ngpt = k_dist.get_ngpt();
622  int ngas = gas_concs.get_num_gases();
623 
624  // Associate local pointers for fluxes
625  auto& flux_up = fluxes.flux_up;
626  auto& flux_dn = fluxes.flux_dn;
627  auto& flux_dn_dir = fluxes.flux_dn_dir;
628  auto& bnd_flux_up = fluxes.bnd_flux_up;
629  auto& bnd_flux_dn = fluxes.bnd_flux_dn;
630  auto& bnd_flux_dn_dir = fluxes.bnd_flux_dn_dir;
631  auto& clnclrsky_flux_up = clnclrsky_fluxes.flux_up;
632  auto& clnclrsky_flux_dn = clnclrsky_fluxes.flux_dn;
633  auto& clnclrsky_flux_dn_dir = clnclrsky_fluxes.flux_dn_dir;
634  auto& clrsky_flux_up = clrsky_fluxes.flux_up;
635  auto& clrsky_flux_dn = clrsky_fluxes.flux_dn;
636  auto& clrsky_flux_dn_dir = clrsky_fluxes.flux_dn_dir;
637  auto& clnsky_flux_up = clnsky_fluxes.flux_up;
638  auto& clnsky_flux_dn = clnsky_fluxes.flux_dn;
639  auto& clnsky_flux_dn_dir = clnsky_fluxes.flux_dn_dir;
640 
641  // Reset fluxes to zero
642  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {ncol, nlay+1}),
643  KOKKOS_LAMBDA (int icol, int ilev)
644  {
645  flux_up (icol,ilev) = 0;
646  flux_dn (icol,ilev) = 0;
647  flux_dn_dir(icol,ilev) = 0;
648  clrsky_flux_up (icol,ilev) = 0;
649  clrsky_flux_dn (icol,ilev) = 0;
650  clrsky_flux_dn_dir(icol,ilev) = 0;
651  });
652  if (extra_clnclrsky_diag) {
653  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {ncol, nlay+1}),
654  KOKKOS_LAMBDA (int icol, int ilev)
655  {
656  clnclrsky_flux_up (icol,ilev) = 0;
657  clnclrsky_flux_dn (icol,ilev) = 0;
658  clnclrsky_flux_dn_dir(icol,ilev) = 0;
659  });
660  }
661  if (extra_clnsky_diag) {
662  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {ncol, nlay+1}),
663  KOKKOS_LAMBDA (int icol, int ilev)
664  {
665  clnsky_flux_up (icol,ilev) = 0;
666  clnsky_flux_dn (icol,ilev) = 0;
667  clnsky_flux_dn_dir(icol,ilev) = 0;
668  });
669  }
670  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<3>>({0, 0, 0}, {ncol, nlay+1, nbnd}),
671  KOKKOS_LAMBDA (int icol, int ilev, int ibnd)
672  {
673  bnd_flux_up (icol,ilev,ibnd) = 0;
674  bnd_flux_dn (icol,ilev,ibnd) = 0;
675  bnd_flux_dn_dir(icol,ilev,ibnd) = 0;
676  });
677 
678  // Get daytime indices
679  int1d_k dayIndices("dayIndices", ncol);
680  Kokkos::deep_copy(dayIndices, -1);
681 
682  // Serialized for now.
683  int nday = 0;
684  Kokkos::parallel_reduce(1, KOKKOS_LAMBDA(int, int& nday_inner)
685  {
686  for (int icol = 0; icol < ncol; ++icol) {
687  if (mu0(icol) > 0) {
688  dayIndices(nday_inner++) = icol;
689  }
690  }
691  }, Kokkos::Sum<int>(nday));
692 
693  // Copy data back to the device
694  if (nday == 0) {
695  // No daytime columns in this chunk, skip the rest of this routine
696  return;
697  }
698 
699  // Subset mu0
700  real1d_k mu0_day("mu0_day", nday);
701  Kokkos::parallel_for(nday, KOKKOS_LAMBDA(int iday)
702  {
703  mu0_day(iday) = mu0(dayIndices(iday));
704  });
705 
706  // subset state variables
707  real2d_k p_lay_day("p_lay_day", nday, nlay);
708  real2d_k t_lay_day("t_lay_day", nday, nlay);
709  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {nday, nlay}),
710  KOKKOS_LAMBDA (int iday, int ilay)
711  {
712  p_lay_day(iday,ilay) = p_lay(dayIndices(iday),ilay);
713  t_lay_day(iday,ilay) = t_lay(dayIndices(iday),ilay);
714  });
715  real2d_k p_lev_day("p_lev_day", nday, nlay+1);
716  real2d_k t_lev_day("t_lev_day", nday, nlay+1);
717  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {nday, nlay+1}),
718  KOKKOS_LAMBDA (int iday, int ilay)
719  {
720  p_lev_day(iday,ilay) = p_lev(dayIndices(iday),ilay);
721  t_lev_day(iday,ilay) = t_lev(dayIndices(iday),ilay);
722  });
723 
724  // Subset gases
725  auto gas_names = gas_concs.get_gas_names();
726  gas_concs_t gas_concs_day;
727  gas_concs_day.init(gas_names, nday, nlay);
728  for (int igas = 0; igas < ngas; igas++) {
729  real2d_k vmr_day("vmr_day", nday, nlay);
730  real2d_k vmr("vmr" , ncol, nlay);
731  gas_concs.get_vmr(gas_names[igas], vmr);
732  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {nday, nlay}),
733  KOKKOS_LAMBDA (int iday, int ilay)
734  {
735  vmr_day(iday,ilay) = vmr(dayIndices(iday),ilay);
736  });
737  gas_concs_day.set_vmr(gas_names[igas], vmr_day);
738  }
739 
740  // Subset aerosol optics
741  optical_props2_t aerosol_day;
742  aerosol_day.init(k_dist.get_band_lims_wavenumber());
743  aerosol_day.alloc_2str(nday, nlay);
744  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<3>>({0, 0, 0}, {nday, nlay, nbnd}),
745  KOKKOS_LAMBDA (int iday, int ilay, int ibnd)
746  {
747  aerosol_day.tau(iday,ilay,ibnd) = aerosol.tau(dayIndices(iday),ilay,ibnd);
748  aerosol_day.ssa(iday,ilay,ibnd) = aerosol.ssa(dayIndices(iday),ilay,ibnd);
749  aerosol_day.g (iday,ilay,ibnd) = aerosol.g (dayIndices(iday),ilay,ibnd);
750  });
751 
752  // Subset cloud optics
753  // TODO: nbnd -> ngpt once we pass sub-sampled cloud state
754  optical_props2_t clouds_day;
755  clouds_day.init(k_dist.get_band_lims_wavenumber(), k_dist.get_band_lims_gpoint());
756  clouds_day.alloc_2str(nday, nlay);
757  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<3>>({0, 0, 0}, {nday, nlay, ngpt}),
758  KOKKOS_LAMBDA (int iday, int ilay, int igpt)
759  {
760  clouds_day.tau(iday,ilay,igpt) = clouds.tau(dayIndices(iday),ilay,igpt);
761  clouds_day.ssa(iday,ilay,igpt) = clouds.ssa(dayIndices(iday),ilay,igpt);
762  clouds_day.g (iday,ilay,igpt) = clouds.g (dayIndices(iday),ilay,igpt);
763  });
764 
765  // RRTMGP assumes surface albedos have a screwy dimension ordering
766  // for some strange reason, so we need to transpose these; also do
767  // daytime subsetting in the same kernel
768  real2d_k sfc_alb_dir_T("sfc_alb_dir", nbnd, nday);
769  real2d_k sfc_alb_dif_T("sfc_alb_dif", nbnd, nday);
770  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {nbnd, nday}),
771  KOKKOS_LAMBDA (int ibnd, int icol)
772  {
773  sfc_alb_dir_T(ibnd,icol) = sfc_alb_dir(dayIndices(icol),ibnd);
774  sfc_alb_dif_T(ibnd,icol) = sfc_alb_dif(dayIndices(icol),ibnd);
775  });
776 
777  // Temporaries we need for daytime-only fluxes
778  real2d_k flux_up_day("flux_up_day", nday, nlay+1);
779  real2d_k flux_dn_day("flux_dn_day", nday, nlay+1);
780  real2d_k flux_dn_dir_day("flux_dn_dir_day", nday, nlay+1);
781  real3d_k bnd_flux_up_day("bnd_flux_up_day", nday, nlay+1, nbnd);
782  real3d_k bnd_flux_dn_day("bnd_flux_dn_day", nday, nlay+1, nbnd);
783  real3d_k bnd_flux_dn_dir_day("bnd_flux_dn_dir_day", nday, nlay+1, nbnd);
784  fluxes_t fluxes_day;
785  fluxes_day.flux_up = flux_up_day;
786  fluxes_day.flux_dn = flux_dn_day;
787  fluxes_day.flux_dn_dir = flux_dn_dir_day;
788  fluxes_day.bnd_flux_up = bnd_flux_up_day;
789  fluxes_day.bnd_flux_dn = bnd_flux_dn_day;
790  fluxes_day.bnd_flux_dn_dir = bnd_flux_dn_dir_day;
791 
792  // Allocate space for optical properties
793  optical_props2_t optics;
794  optics.alloc_2str(nday, nlay, k_dist);
795 
796  optical_props2_t optics_no_aerosols;
797  if (extra_clnsky_diag) {
798  // Allocate space for optical properties (no aerosols)
799  optics_no_aerosols.alloc_2str(nday, nlay, k_dist);
800  }
801 
802  // Limit temperatures for gas optics look-up tables
803  real2d_k t_lay_limited("t_lay_limited", nday, nlay);
804  limit_to_bounds_2d(t_lay_day, k_dist_sw_k->get_temp_min(),
805  k_dist_sw_k->get_temp_max(), t_lay_limited);
806 
807  // Do gas optics
808  real2d_k toa_flux("toa_flux", nday, ngpt);
809  real3d_k col_gas("col_gas", ncol, nlay, k_dist.get_ngas()+1);
810  bool top_at_1 = false;
811  Kokkos::parallel_reduce(1, KOKKOS_LAMBDA(int, bool& val)
812  {
813  val |= p_lay(0, 0) < p_lay(0, nlay-1);
814  }, Kokkos::LOr<bool>(top_at_1));
815 
816  k_dist.gas_optics(nday, nlay, top_at_1, p_lay_day, p_lev_day,
817  t_lay_limited, gas_concs_day, col_gas, optics, toa_flux);
818  if (extra_clnsky_diag) {
819  k_dist.gas_optics(nday, nlay, top_at_1, p_lay_day, p_lev_day,
820  t_lay_limited, gas_concs_day, col_gas, optics_no_aerosols, toa_flux);
821  }
822 
823  // Apply tsi_scaling
824  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {nday, ngpt}),
825  KOKKOS_LAMBDA (int iday, int igpt)
826  {
827  toa_flux(iday,igpt) = tsi_scaling * toa_flux(iday,igpt);
828  });
829 
830  if (extra_clnclrsky_diag) {
831  // Compute clear-clean-sky (just gas) fluxes on daytime columns
832  rte_sw(optics, top_at_1, mu0_day, toa_flux, sfc_alb_dir_T, sfc_alb_dif_T, fluxes_day);
833  // Expand daytime fluxes to all columns
834  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {nday, nlay+1}),
835  KOKKOS_LAMBDA (int iday, int ilev)
836  {
837  int icol = dayIndices(iday);
838  clnclrsky_flux_up (icol,ilev) = flux_up_day (iday,ilev);
839  clnclrsky_flux_dn (icol,ilev) = flux_dn_day (iday,ilev);
840  clnclrsky_flux_dn_dir(icol,ilev) = flux_dn_dir_day(iday,ilev);
841  });
842  }
843 
844  // Combine gas and aerosol optics
845  aerosol_day.delta_scale();
846  aerosol_day.increment(optics);
847 
848  // Compute clearsky (gas + aerosol) fluxes on daytime columns
849  rte_sw(optics, top_at_1, mu0_day, toa_flux, sfc_alb_dir_T, sfc_alb_dif_T, fluxes_day);
850 
851  // Expand daytime fluxes to all columns
852  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {nday, nlay+1}),
853  KOKKOS_LAMBDA (int iday, int ilev)
854  {
855  int icol = dayIndices(iday);
856  clrsky_flux_up (icol,ilev) = flux_up_day (iday,ilev);
857  clrsky_flux_dn (icol,ilev) = flux_dn_day (iday,ilev);
858  clrsky_flux_dn_dir(icol,ilev) = flux_dn_dir_day(iday,ilev);
859  });
860 
861  // Now merge in cloud optics and do allsky calculations
862 
863  // Combine gas and cloud optics
864  clouds_day.delta_scale();
865  clouds_day.increment(optics);
866 
867  // Compute fluxes on daytime columns
868  rte_sw(optics, top_at_1, mu0_day, toa_flux, sfc_alb_dir_T, sfc_alb_dif_T, fluxes_day);
869 
870  // Expand daytime fluxes to all columns
871  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {nday, nlay+1}),
872  KOKKOS_LAMBDA (int iday, int ilev)
873  {
874  int icol = dayIndices(iday);
875  flux_up (icol,ilev) = flux_up_day (iday,ilev);
876  flux_dn (icol,ilev) = flux_dn_day (iday,ilev);
877  flux_dn_dir(icol,ilev) = flux_dn_dir_day(iday,ilev);
878  });
879  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<3>>({0, 0, 0}, {nday, nlay+1, nbnd}),
880  KOKKOS_LAMBDA (int iday, int ilev, int ibnd)
881  {
882  int icol = dayIndices(iday);
883  bnd_flux_up (icol,ilev,ibnd) = bnd_flux_up_day (iday,ilev,ibnd);
884  bnd_flux_dn (icol,ilev,ibnd) = bnd_flux_dn_day (iday,ilev,ibnd);
885  bnd_flux_dn_dir(icol,ilev,ibnd) = bnd_flux_dn_dir_day(iday,ilev,ibnd);
886  });
887 
888  if (extra_clnsky_diag) {
889  // First increment clouds in optics_no_aerosols
890  clouds_day.increment(optics_no_aerosols);
891  // Compute cleansky (gas + clouds) fluxes on daytime columns
892  rte_sw(optics_no_aerosols, top_at_1, mu0_day, toa_flux, sfc_alb_dir_T, sfc_alb_dif_T, fluxes_day);
893  // Expand daytime fluxes to all columns
894  Kokkos::parallel_for(Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {nday, nlay+1}),
895  KOKKOS_LAMBDA (int iday, int ilev)
896  {
897  int icol = dayIndices(iday);
898  clnsky_flux_up (icol,ilev) = flux_up_day (iday,ilev);
899  clnsky_flux_dn (icol,ilev) = flux_dn_day (iday,ilev);
900  clnsky_flux_dn_dir(icol,ilev) = flux_dn_dir_day(iday,ilev);
901  });
902  }
903 }
GasConcsK< RealT, layout_t, KokkosDefaultDevice > gas_concs_t
Definition: ERF_RRTMGP_Interface.H:31

Referenced by rrtmgp_main().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ cloud_optics_lw_k

std::unique_ptr< cloud_optics_t > rrtmgp::cloud_optics_lw_k

◆ cloud_optics_sw_k

std::unique_ptr< cloud_optics_t > rrtmgp::cloud_optics_sw_k

◆ initialized

◆ k_dist_lw_k

std::unique_ptr< gas_optics_t > rrtmgp::k_dist_lw_k

◆ k_dist_sw_k

◆ kokkos_mem_pool

pool_t rrtmgp::kokkos_mem_pool

◆ pool_max_ncol

size_t rrtmgp::pool_max_ncol = 0

Referenced by rrtmgp_initialize(), and rrtmgp_main().

◆ pool_max_nlay

size_t rrtmgp::pool_max_nlay = 0

Referenced by rrtmgp_initialize(), and rrtmgp_main().

◆ pool_nvar

int rrtmgp::pool_nvar = 0

Referenced by rrtmgp_initialize(), and rrtmgp_main().