ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_Radiation.H
Go to the documentation of this file.
1 /*
2  * RTE-RRTMGP radiation model interface to ERF
3  * The original code is developed by RobertPincus, and the code is open source available at:
4  * https://github.com/earth-system-radiation/rte-rrtmgp
5  * Please reference to the following paper,
6  * https://agupubs.onlinelibrary.wiley.com/doi/10.1029/2019MS001621
7  * NOTE: we use the C++ version of RTE-RRTMGP, which is the implementation of the original Fortran
8  * code using C++ YAKL for CUDA, HiP and SYCL application by E3SM ECP team, the C++ version
9  * of the rte-rrtmgp code is located at:
10  * https://github.com/E3SM-Project/rte-rrtmgp
11  * The RTE-RRTMGP uses BSD-3-Clause Open Source License, if you want to make changes,
12  * and modifications to the code, please refer to BSD-3-Clause Open Source License.
13  */
14 #ifndef ERF_RADIATION_H
15 #define ERF_RADIATION_H
16 
17 #include <string>
18 #include <vector>
19 #include <memory>
20 
21 #include <AMReX_FArrayBox.H>
22 #include <AMReX_Geometry.H>
23 #include <AMReX_TableData.H>
24 #include <AMReX_MultiFabUtil.H>
25 
26 #include "ERF_Config.H"
27 #include "ERF_Constants.H"
28 #include "ERF_Rad_constants.H"
29 #include "ERF_Rrtmgp.H"
30 #include "ERF_Optics.H"
31 #include "ERF_Aero_rad_props.H"
32 #include "ERF_Parameterizations.H"
33 #include "ERF_Albedo.H"
34 
35 // Radiation code interface class
36 class Radiation {
37  public:
38  Radiation () {
39  // First, make sure yakl has been initialized
40  if (!yakl::isInitialized()) yakl::init();
41  }
42 
43  ~Radiation () = default;
44 
45  // init
46  void initialize (const amrex::MultiFab& cons_in,
47  amrex::MultiFab* lsm_fluxes,
48  amrex::MultiFab* lsm_zenith,
49  amrex::MultiFab* qheating_rates,
50  amrex::MultiFab* lat,
51  amrex::MultiFab* lon,
52  amrex::Vector<amrex::MultiFab*> qmoist,
53  const amrex::BoxArray& grids,
54  const amrex::Geometry& geom,
55  const amrex::Real& dt_advance,
56  const bool& do_sw_rad,
57  const bool& do_lw_rad,
58  const bool& do_aero_rad,
59  const bool& do_snow_opt,
60  const bool& is_cmip6_volcano);
61 
62  // run radiation model
63  void run ();
64 
65  // call back
66  void on_complete ();
67 
68  void radiation_driver_lw (int ncol, int nlev,
69  const real3d& gas_vmr,
70  const real2d& pmid, const real2d& pint, const real2d& tmid, const real2d& tint,
71  const real3d& cld_tau_gpt, const real3d& aer_tau_bnd,
72  FluxesByband& fluxes_clrsky, FluxesByband& fluxes_allsky,
73  const real2d& qrl, const real2d& qrlc);
74 
75  void radiation_driver_sw (int ncol,
76  const real3d& gas_vmr, const real2d& pmid, const real2d& pint, const real2d& tmid,
77  const real2d& albedo_dir, const real2d& albedo_dif, const real1d& coszrs,
78  const real3d& cld_tau_gpt, const real3d& cld_ssa_gpt, const real3d& cld_asm_gpt,
79  const real3d& aer_tau_bnd, const real3d& aer_ssa_bnd, const real3d& aer_asm_bnd,
80  FluxesByband& fluxes_clrsky, FluxesByband& fluxes_allsky,
81  const real2d& qrs, const real2d& qrsc);
82 
83  void set_daynight_indices (const real1d& coszrs,
84  const int1d& day_indices,
85  const int1d& night_indices);
86 
87  void get_gas_vmr (const std::vector<std::string>& gas_names,
88  const real3d& gas_vmr);
89 
90  void calculate_heating_rate (const real2d& flux_up,
91  const real2d& flux_dn,
92  const real2d& pint,
93  const real2d& heating_rate);
94  void
95  export_surface_fluxes(FluxesByband& fluxes,
96  std::string band);
97 
98  void yakl_to_mf(const real2d &data, amrex::MultiFab &mf);
99  void expand_yakl1d_to_mf(const real1d &data, amrex::MultiFab &mf);
100 
101  void writePlotfile(const std::string& plot_prefix, const amrex::Real time, const int level_step);
102 
103  private:
104  // geometry
105  amrex::Geometry m_geom;
106 
107  // valid boxes on which to evolve the solution
108  amrex::BoxArray m_box;
109 
110  // Pointer to the radiation source terms
111  amrex::MultiFab* qrad_src = nullptr;
112 
113  // Pointer to latitude and longitude
114  amrex::MultiFab* m_lat = nullptr;
115  amrex::MultiFab* m_lon = nullptr;
116 
117  // Pointer to output data for LSM
118  amrex::MultiFab* m_lsm_fluxes = nullptr;
119  amrex::MultiFab* m_lsm_zenith = nullptr;
120 
121  std::string moisture_type = "None";
123 
124  amrex::Vector<int> rank_offsets;
125 
126  // Specified uniform angle for radiation
127  amrex::Real uniform_angle = 78.463;
128 
129  // Orbital properties (constant for now)
130  static constexpr amrex::Real eccen = 0.0; // Earth's eccentricity factor (unitless) (typically 0 to 0.1)
131  static constexpr amrex::Real obliqr = 23.0 * PI / 180.0; // Earth's obliquity in radians
132  static constexpr amrex::Real mvelpp = 103.0 * PI / 180.0 + PI; // Earth's moving vernal equinox longitude of perihelion plus pi (radians)
133  static constexpr amrex::Real lambm0 = -3.2503635878519378e-2; // Mean longitude of perihelion at the vernal equinox (radians)
134 
135  // number of vertical levels
136  int nlev, zlo, zhi;
137 
138  // number of columns in horizontal plane
139  int ncol;
140 
143 
144  // radiation options
148 
149  // Flag to indicate whether to do aerosol optical calculations. This
150  // zeroes out the aerosol optical properties if False
151  bool do_aerosol_rad = true;
152 
153  // rrtmgp
155 
156  // optics radiation properties
158 
159  // aerosol optics properties
161 
162  // input/output of radiation model
163  //
164  // Net flux calculated in this routine; used to check energy conservation in
165  // the physics package driver?
166  real1d net_flux;
167 
168  // This should be module data or something specific to aerosol where it is used?
169  bool is_cmip6_volc; // true if cmip6 style volcanic file is read otherwise false
170 
171  real dt; // time step(s) - needed for aerosol optics call
172 
173  // Surface and top fluxes
174  real1d fsns; // Surface solar absorbed flux
175  real1d fsnt; // Net column abs solar flux at model top
176  real1d flns; // Srf longwave cooling (up-down) flux
177  real1d flnt; // Net outgoing lw flux at model top
178  real1d fsds; // Surface solar down flux
179 
180  // radiation data
181  const std::vector<std::string> active_gases = {
182  "H2O", "CO2", "O3", "N2O",
183  "CO" , "CH4", "O2", "N2" };
184 
185  bool spectralflux = false; // calculate fluxes (up and down) per band.
186 
187  // Flag to indicate whether or not to use the radiation timestep for solar zenith
188  // angle calculations. If true, use the radiation timestep for all solar zenith
189  // angle (cosz) calculations.
190  // TODO: How does this differ if value is .false.?
191  bool use_rad_dt_cosz = false;
192 
193  // Value for prescribing an invariant solar constant (i.e. total solar
194  // irradiance at TOA). Used for idealized experiments such as RCE.
195  // Disabled when value is less than 0.
197 
198  // The RRTMGP warnings are printed when the state variables need to be limited,
199  // such as when the temperature drops too low. This is not normally an issue,
200  // but in aquaplanet and RCE configurations these situations occur much more
201  // frequently, so this flag was added to be able to disable those messages.
203 
204  // Output diagnostic brightness temperatures at the top of the
205  // atmosphere for 7 TOVS/HIRS channels (2,4,6,8,10,11,12) and 4 TOVS/MSU
206  // channels (1,2,3,4).
207  // TODO: where are these options set?
208  bool dohirs = false;
209  int ihirsfq = 1; // frequency (timesteps) of brightness temperature calcs
210 
211  // time step to use for the shr_orb_cosz calculation, if use_rad_dt_cosz set to true
212  // TODO: where is this set, and what is shr_orb_cosz? Alternative solar zenith
213  // angle calculation? What is the other behavior?
214  real dt_avg = 0.0;
215 
216  // k-distribution coefficients files to read from. These are set via namelist
217  // variables.
218  std::string rrtmgp_data_path;
221  std::string rrtmgp_coefficients_file_name_sw = "rrtmgp_coefficients_sw_20181204.nc";
222  std::string rrtmgp_coefficients_file_name_lw = "rrtmgp_coefficients_lw_20181204.nc";
223 
224  // Band midpoints; these need to be module variables because of how cam_history works;
225  // add_hist_coord sets up pointers to these, so they need to persist.
228 
229  // rad constituents mixing ratios
230  int ngas, naer;
231  std::vector<std::string> gasnames;
232  std::vector<std::string> aernames;
233 
235 
236  // Pointers to heating rates on physics buffer
237  real2d qrs; // shortwave radiative heating rate
238  real2d qrl; // longwave radiative heating rate
239 
240  // Pointers to fields on the physics buffer
241  real2d zi;
242  real2d clear_rh;
243 
244  // Clear-sky heating rates are not on the physics buffer, and we have no
245  // reason to put them there, so declare these are regular arrays here
246  real2d qrsc;
247  real2d qrlc;
248 
249  // moisture inputs from ERF
250  real2d qt, qi, qc, qn; // [ncol, nlev]
251  real2d tmid, pmid, pdel; // [ncol, nlev]
252  real2d pint, tint; // [ncol, nlev+1]
253  real2d albedo_dir, albedo_dif; // [nswbands, ncol]
254 
255  // timestep variables -- defined during each call to run()
256  real1d coszrs; // [ncol]
257  real2d cld, cldfsnow, iclwp, iciwp, icswp, dei, des, lambdac, mu, rei, rel; // [ncol, nlev]
258  // cloud, snow, and aerosol optical properties
259  real3d cld_tau_gpt_sw, cld_ssa_gpt_sw, cld_asm_gpt_sw; // [ncol, nlev, nswgpts]
260  real3d cld_tau_bnd_sw, cld_ssa_bnd_sw, cld_asm_bnd_sw; // [ncol, nlev, nswbands]
261  real3d aer_tau_bnd_sw, aer_ssa_bnd_sw, aer_asm_bnd_sw; // [ncol, nlev, nswbands]
262  real3d cld_tau_bnd_lw, aer_tau_bnd_lw; // [ncol, nlev, nlwbands]
263  real3d cld_tau_gpt_lw; // [ncol, nlev, nlwgpts]
264  // diagnostic only:
265  real3d liq_tau_bnd_sw, ice_tau_bnd_sw, snw_tau_bnd_sw; // [ncol, nlev, nswbands]
266  real3d liq_tau_bnd_lw, ice_tau_bnd_lw, snw_tau_bnd_lw; // [ncol, nlev, nlwbands]
267  // gas volume mixing ratios
268  real3d gas_vmr; // [ngas, ncol, nlev]
269  int1d gpoint_bands_sw, gpoint_bands_lw; // [nswgpts], [nlwgpts]
270  // shortwave radiation vars:
274  // aerosol optics:
277  // longwave radiation vars:
279 };
280 #endif // ERF_RADIATION_H
constexpr amrex::Real PI
Definition: ERF_Constants.H:6
Definition: ERF_Aero_rad_props.H:18
Definition: ERF_Optics.H:24
Definition: ERF_Radiation.H:36
amrex::MultiFab * m_lon
Definition: ERF_Radiation.H:115
void on_complete()
Definition: ERF_Radiation.cpp:1074
real3d cld_tau_gpt_lw
Definition: ERF_Radiation.H:263
real1d lw_band_midpoints
Definition: ERF_Radiation.H:227
real2d clear_rh
Definition: ERF_Radiation.H:242
std::string rrtmgp_data_path
Definition: ERF_Radiation.H:218
real3d aer_tau_bnd_sw
Definition: ERF_Radiation.H:261
real fixed_total_solar_irradiance
Definition: ERF_Radiation.H:196
std::string rrtmgp_coefficients_file_lw
Definition: ERF_Radiation.H:220
real1d net_flux
Definition: ERF_Radiation.H:166
real3d aer_ssa_bnd_sw
Definition: ERF_Radiation.H:261
real2d rei
Definition: ERF_Radiation.H:257
void initialize(const amrex::MultiFab &cons_in, amrex::MultiFab *lsm_fluxes, amrex::MultiFab *lsm_zenith, amrex::MultiFab *qheating_rates, amrex::MultiFab *lat, amrex::MultiFab *lon, amrex::Vector< amrex::MultiFab * > qmoist, const amrex::BoxArray &grids, const amrex::Geometry &geom, const amrex::Real &dt_advance, const bool &do_sw_rad, const bool &do_lw_rad, const bool &do_aero_rad, const bool &do_snow_opt, const bool &is_cmip6_volcano)
Definition: ERF_Radiation.cpp:102
bool is_cmip6_volc
Definition: ERF_Radiation.H:169
void get_gas_vmr(const std::vector< std::string > &gas_names, const real3d &gas_vmr)
Definition: ERF_Radiation.cpp:855
std::string moisture_type
Definition: ERF_Radiation.H:121
bool use_rad_dt_cosz
Definition: ERF_Radiation.H:191
real3d liq_tau_bnd_lw
Definition: ERF_Radiation.H:266
real2d mu
Definition: ERF_Radiation.H:257
real1d fsnt
Definition: ERF_Radiation.H:175
real2d qrl
Definition: ERF_Radiation.H:238
void export_surface_fluxes(FluxesByband &fluxes, std::string band)
Definition: ERF_Radiation.cpp:992
real3d cld_ssa_gpt_sw
Definition: ERF_Radiation.H:259
int nswbands
Definition: ERF_Radiation.H:142
real2d pint
Definition: ERF_Radiation.H:252
real2d pmid
Definition: ERF_Radiation.H:251
real2d qrlc
Definition: ERF_Radiation.H:247
int1d rrtmg_to_rrtmgp
Definition: ERF_Radiation.H:234
amrex::BoxArray m_box
Definition: ERF_Radiation.H:108
real3d aer_asm_bnd_sw
Definition: ERF_Radiation.H:261
real1d aer_ssa_bnd_sw_o_1d
Definition: ERF_Radiation.H:276
amrex::Vector< int > rank_offsets
Definition: ERF_Radiation.H:124
real1d aer_tau_bnd_sw_o_1d
Definition: ERF_Radiation.H:276
bool rrtmgp_enable_temperature_warnings
Definition: ERF_Radiation.H:202
void writePlotfile(const std::string &plot_prefix, const amrex::Real time, const int level_step)
Definition: ERF_Radiation.cpp:1132
real1d cld_asm_bnd_sw_o_1d
Definition: ERF_Radiation.H:273
real1d cld_tau_bnd_sw_o_1d
Definition: ERF_Radiation.H:273
static constexpr amrex::Real obliqr
Definition: ERF_Radiation.H:131
real1d aer_ssa_bnd_sw_1d
Definition: ERF_Radiation.H:275
real1d fsns
Definition: ERF_Radiation.H:174
int naer
Definition: ERF_Radiation.H:230
void expand_yakl1d_to_mf(const real1d &data, amrex::MultiFab &mf)
Definition: ERF_Radiation.cpp:1105
void set_daynight_indices(const real1d &coszrs, const int1d &day_indices, const int1d &night_indices)
Definition: ERF_Radiation.cpp:831
real2d dei
Definition: ERF_Radiation.H:257
amrex::MultiFab * m_lsm_fluxes
Definition: ERF_Radiation.H:118
static constexpr amrex::Real eccen
Definition: ERF_Radiation.H:130
int nswgpts
Definition: ERF_Radiation.H:141
bool spectralflux
Definition: ERF_Radiation.H:185
static constexpr amrex::Real lambm0
Definition: ERF_Radiation.H:133
int nlev
Definition: ERF_Radiation.H:136
amrex::MultiFab * qrad_src
Definition: ERF_Radiation.H:111
bool do_aerosol_rad
Definition: ERF_Radiation.H:151
real1d flns
Definition: ERF_Radiation.H:176
real3d snw_tau_bnd_lw
Definition: ERF_Radiation.H:266
real3d cld_tau_bnd_lw
Definition: ERF_Radiation.H:262
real2d des
Definition: ERF_Radiation.H:257
real1d cld_tau_bnd_sw_1d
Definition: ERF_Radiation.H:272
void run()
Definition: ERF_Radiation.cpp:278
AerRadProps aer_rad
Definition: ERF_Radiation.H:160
real2d tint
Definition: ERF_Radiation.H:252
std::vector< std::string > gasnames
Definition: ERF_Radiation.H:231
real2d zi
Definition: ERF_Radiation.H:241
const std::vector< std::string > active_gases
Definition: ERF_Radiation.H:181
real2d qi
Definition: ERF_Radiation.H:250
real3d cld_asm_gpt_sw
Definition: ERF_Radiation.H:259
int1d gpoint_bands_sw
Definition: ERF_Radiation.H:269
real2d cld
Definition: ERF_Radiation.H:257
int nlwgpts
Definition: ERF_Radiation.H:141
real3d gas_vmr
Definition: ERF_Radiation.H:268
FluxesByband sw_fluxes_clrsky
Definition: ERF_Radiation.H:271
std::string rrtmgp_coefficients_file_sw
Definition: ERF_Radiation.H:219
bool do_snow_optics
Definition: ERF_Radiation.H:147
real3d cld_asm_bnd_sw
Definition: ERF_Radiation.H:260
real1d sw_band_midpoints
Definition: ERF_Radiation.H:226
int ncol
Definition: ERF_Radiation.H:139
real2d qn
Definition: ERF_Radiation.H:250
real2d rel
Definition: ERF_Radiation.H:257
real dt
Definition: ERF_Radiation.H:171
std::string rrtmgp_coefficients_file_name_lw
Definition: ERF_Radiation.H:222
real1d aer_asm_bnd_sw_1d
Definition: ERF_Radiation.H:275
real2d iclwp
Definition: ERF_Radiation.H:257
real2d qrs
Definition: ERF_Radiation.H:237
amrex::MultiFab * m_lsm_zenith
Definition: ERF_Radiation.H:119
int ihirsfq
Definition: ERF_Radiation.H:209
real2d iciwp
Definition: ERF_Radiation.H:257
real2d qt
Definition: ERF_Radiation.H:250
std::vector< std::string > aernames
Definition: ERF_Radiation.H:232
Optics optics
Definition: ERF_Radiation.H:157
real2d albedo_dir
Definition: ERF_Radiation.H:253
real2d albedo_dif
Definition: ERF_Radiation.H:253
real3d ice_tau_bnd_lw
Definition: ERF_Radiation.H:266
int nlwbands
Definition: ERF_Radiation.H:142
real2d lambdac
Definition: ERF_Radiation.H:257
void yakl_to_mf(const real2d &data, amrex::MultiFab &mf)
Definition: ERF_Radiation.cpp:1076
real3d ice_tau_bnd_sw
Definition: ERF_Radiation.H:265
FluxesByband sw_fluxes_allsky
Definition: ERF_Radiation.H:271
real2d qrsc
Definition: ERF_Radiation.H:246
real3d cld_tau_gpt_sw
Definition: ERF_Radiation.H:259
real2d qc
Definition: ERF_Radiation.H:250
void radiation_driver_sw(int ncol, const real3d &gas_vmr, const real2d &pmid, const real2d &pint, const real2d &tmid, const real2d &albedo_dir, const real2d &albedo_dif, const real1d &coszrs, const real3d &cld_tau_gpt, const real3d &cld_ssa_gpt, const real3d &cld_asm_gpt, const real3d &aer_tau_bnd, const real3d &aer_ssa_bnd, const real3d &aer_asm_bnd, FluxesByband &fluxes_clrsky, FluxesByband &fluxes_allsky, const real2d &qrs, const real2d &qrsc)
Definition: ERF_Radiation.cpp:582
int zhi
Definition: ERF_Radiation.H:136
real2d tmid
Definition: ERF_Radiation.H:251
real1d aer_tau_bnd_sw_1d
Definition: ERF_Radiation.H:275
real3d liq_tau_bnd_sw
Definition: ERF_Radiation.H:265
void radiation_driver_lw(int ncol, int nlev, const real3d &gas_vmr, const real2d &pmid, const real2d &pint, const real2d &tmid, const real2d &tint, const real3d &cld_tau_gpt, const real3d &aer_tau_bnd, FluxesByband &fluxes_clrsky, FluxesByband &fluxes_allsky, const real2d &qrl, const real2d &qrlc)
Definition: ERF_Radiation.cpp:772
~Radiation()=default
bool do_short_wave_rad
Definition: ERF_Radiation.H:145
real1d cld_ssa_bnd_sw_1d
Definition: ERF_Radiation.H:272
real1d cld_ssa_bnd_sw_o_1d
Definition: ERF_Radiation.H:273
real2d pdel
Definition: ERF_Radiation.H:251
real2d icswp
Definition: ERF_Radiation.H:257
void calculate_heating_rate(const real2d &flux_up, const real2d &flux_dn, const real2d &pint, const real2d &heating_rate)
Definition: ERF_Radiation.cpp:959
real1d coszrs
Definition: ERF_Radiation.H:256
bool has_qmoist
Definition: ERF_Radiation.H:122
Rrtmgp radiation
Definition: ERF_Radiation.H:154
int zlo
Definition: ERF_Radiation.H:136
FluxesByband lw_fluxes_clrsky
Definition: ERF_Radiation.H:278
static constexpr amrex::Real mvelpp
Definition: ERF_Radiation.H:132
real2d cldfsnow
Definition: ERF_Radiation.H:257
amrex::Geometry m_geom
Definition: ERF_Radiation.H:105
real1d aer_asm_bnd_sw_o_1d
Definition: ERF_Radiation.H:276
std::string rrtmgp_coefficients_file_name_sw
Definition: ERF_Radiation.H:221
amrex::MultiFab * m_lat
Definition: ERF_Radiation.H:114
real3d cld_tau_bnd_sw
Definition: ERF_Radiation.H:260
real3d snw_tau_bnd_sw
Definition: ERF_Radiation.H:265
real1d fsds
Definition: ERF_Radiation.H:178
amrex::Real uniform_angle
Definition: ERF_Radiation.H:127
int ngas
Definition: ERF_Radiation.H:230
FluxesByband lw_fluxes_allsky
Definition: ERF_Radiation.H:278
real3d cld_ssa_bnd_sw
Definition: ERF_Radiation.H:260
real dt_avg
Definition: ERF_Radiation.H:214
int1d gpoint_bands_lw
Definition: ERF_Radiation.H:269
real3d aer_tau_bnd_lw
Definition: ERF_Radiation.H:262
bool dohirs
Definition: ERF_Radiation.H:208
bool do_long_wave_rad
Definition: ERF_Radiation.H:146
real1d cld_asm_bnd_sw_1d
Definition: ERF_Radiation.H:272
real1d flnt
Definition: ERF_Radiation.H:177
Radiation()
Definition: ERF_Radiation.H:38
Definition: ERF_Rrtmgp.H:39