1 #ifndef ERF_TWO_STREAM_CANOPY_FORCING_H_
2 #define ERF_TWO_STREAM_CANOPY_FORCING_H_
4 #include <AMReX_Array4.H>
5 #include <AMReX_Extension.H>
6 #include <AMReX_GpuQualifiers.H>
7 #include <AMReX_MultiFab.H>
8 #include <AMReX_REAL.H>
46 const amrex::MultiFab*
beam =
nullptr;
48 const amrex::MultiFab*
fluxes =
nullptr;
63 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
66 return static_cast<int>(alb_dir(i, j, 0, 1) + amrex::Real(0.5));
93 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
95 const amrex::Array4<const amrex::Real>& scratch,
int f_dir_comp,
96 bool sw_on, amrex::Real cos_zenith, amrex::Real cloud_fraction,
bool blend,
97 const amrex::Array4<amrex::Real>& beam)
99 const bool lit = sw_on && (cos_zenith > amrex::Real(0.0));
100 for (
int m = 0; m <= m_top; ++m) {
101 const amrex::Real b = lit ? scratch(i, j, kmin + m, f_dir_comp) : amrex::Real(0.0);
102 beam(i, j, m) = blend ? (1.0 - cloud_fraction) * beam(i, j, m) + cloud_fraction * b : b;
120 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
123 w_up = (dir == 2) ? amrex::Real(0.0) : amrex::Real(0.5);
124 return k - k0 + ((dir == 2 && side > 0) ? 1 : 0);
149 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
151 const amrex::Array4<const amrex::Real>& beam,
152 const amrex::Array4<const amrex::Real>& cosz,
153 const amrex::Array4<const amrex::Real>& fluxes)
155 amrex::Real w_up = 0.0;
157 const int mu = ms + ((w_up > amrex::Real(0.0)) ? 1 : 0);
158 const amrex::Real w_lo = amrex::Real(1.0) - w_up;
159 const amrex::Real beam_h = w_lo * beam(i, j, ms) + w_up * beam(i, j,
mu);
160 const amrex::Real sw_dn = w_lo * fluxes(i, j, k0 + ms, 1) + w_up * fluxes(i, j, k0 +
mu, 1);
162 const amrex::Real cz = cosz(i, j, 0);
165 s.
dni = (cz > amrex::Real(0.0)) ? beam_h / (cz + std::numeric_limits<amrex::Real>::min()) : amrex::Real(0.0);
166 s.
diffuse = (sw_dn - beam_h > amrex::Real(0.0)) ? sw_dn - beam_h : amrex::Real(0.0);
167 s.
lw_down = w_lo * fluxes(i, j, k0 + ms, 3) + w_up * fluxes(i, j, k0 +
mu, 3);
168 s.
sw_up = w_lo * fluxes(i, j, k0 + ms, 0) + w_up * fluxes(i, j, k0 +
mu, 0);
169 s.
lw_up = w_lo * fluxes(i, j, k0 + ms, 2) + w_up * fluxes(i, j, k0 +
mu, 2);
188 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
190 const amrex::Array4<const amrex::Real>& beam,
191 const amrex::Array4<const amrex::Real>& fluxes,
192 const amrex::Array4<const amrex::Real>& alb_dir)
196 const amrex::Real up0 = fluxes(i, j, k0 + m_base, 0);
197 const amrex::Real refl = alb_dir(i, j, 0) * beam(i, j, m_base);
199 const amrex::Real share = (up0 > amrex::Real(0.0) && refl > amrex::Real(0.0))
200 ? refl / (up0 + std::numeric_limits<amrex::Real>::min()) : amrex::Real(0.0);
201 return (share < amrex::Real(1.0)) ? share : amrex::Real(1.0);
232 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
234 amrex::Real sw_walls, amrex::Real lw_walls, amrex::Real lw_down,
235 amrex::Real absorb_dif, amrex::Real emis) noexcept
239 const amrex::Real whole = (wall_view > amrex::Real(1.0)) ? wall_view : amrex::Real(1.0);
240 const amrex::Real c = amrex::Real(1.0) / whole;
242 t.d_sw = c * (absorb_dif * sw_walls - wall_view * (sw_net - sw_beam));
243 t.d_lw = c * emis * (lw_walls - wall_view * lw_down);
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int two_stream_column_base(int i, int j, const amrex::Array4< const amrex::Real > &alb_dir) noexcept
The interface a column starts on, counted from the ground: 0, or the roof's with erf....
Definition: ERF_TwoStreamCanopyForcing.H:64
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void two_stream_canopy_beam(int i, int j, int kmin, int m_top, const amrex::Array4< const amrex::Real > &scratch, int f_dir_comp, bool sw_on, amrex::Real cos_zenith, amrex::Real cloud_fraction, bool blend, const amrex::Array4< amrex::Real > &beam)
Write the direct beam on a horizontal surface at the interfaces 0 .. m_top of column (i,...
Definition: ERF_TwoStreamCanopyForcing.H:94
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real two_stream_ground_beam_share(int i, int j, int k0, const amrex::Array4< const amrex::Real > &beam, const amrex::Array4< const amrex::Real > &fluxes, const amrex::Array4< const amrex::Real > &alb_dir)
The share of column (i,j)'s shortwave up that is its ground's reflection of the direct beam: (direct-...
Definition: ERF_TwoStreamCanopyForcing.H:189
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GroundWallTerms two_stream_ground_wall_terms(amrex::Real sw_net, amrex::Real sw_beam, amrex::Real wall_view, amrex::Real sw_walls, amrex::Real lw_walls, amrex::Real lw_down, amrex::Real absorb_dif, amrex::Real emis) noexcept
The change of the open ground's net radiation beside walls (erf.ibseb.ground_sky_view)....
Definition: ERF_TwoStreamCanopyForcing.H:233
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE TwoStreamFaceSky two_stream_face_sky(int i, int j, int k, int k0, int dir, int side, const amrex::Array4< const amrex::Real > &beam, const amrex::Array4< const amrex::Real > &cosz, const amrex::Array4< const amrex::Real > &fluxes)
The column radiation a face at fluid cell (i,j,k) of direction dir, with its solid on side side,...
Definition: ERF_TwoStreamCanopyForcing.H:150
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int two_stream_canopy_sample(int k, int k0, int dir, int side, amrex::Real &w_up)
Sample interface of a face and the weight of the one above. A z face takes the interface it lies on: ...
Definition: ERF_TwoStreamCanopyForcing.H:121
@ mu
Definition: ERF_AdvanceMorrison.cpp:94
@ t
Definition: ERF_WSM6.H:295
What two_stream_ground_wall_terms() adds to the ground balance's net shortwave and longwave [W/m^2].
Definition: ERF_TwoStreamCanopyForcing.H:206
amrex::Real d_lw
Definition: ERF_TwoStreamCanopyForcing.H:208
amrex::Real d_sw
Definition: ERF_TwoStreamCanopyForcing.H:207
The fields a level's faces read for one step: the beam and the cosine of the zenith the sweep of that...
Definition: ERF_TwoStreamCanopyForcing.H:45
const amrex::MultiFab * fluxes
Definition: ERF_TwoStreamCanopyForcing.H:48
const amrex::MultiFab * beam
Direct beam on a horizontal surface, interfaces 0 .. m_top [W/m^2].
Definition: ERF_TwoStreamCanopyForcing.H:46
const amrex::MultiFab * cos_zenith
Cosine of the zenith of the sweep, floored at zero (2D) [1].
Definition: ERF_TwoStreamCanopyForcing.H:47
bool valid() const noexcept
Definition: ERF_TwoStreamCanopyForcing.H:54
const amrex::MultiFab * ground_albedo_dir
Definition: ERF_TwoStreamCanopyForcing.H:53
What one face takes from its column (all W/m^2).
Definition: ERF_TwoStreamCanopyForcing.H:129
amrex::Real sw_up
Shortwave up at the face's height (the ground's reflection, seen from there)
Definition: ERF_TwoStreamCanopyForcing.H:133
amrex::Real diffuse
Diffuse shortwave down at the face's height.
Definition: ERF_TwoStreamCanopyForcing.H:131
amrex::Real lw_up
Longwave up at the face's height (the ground's emission and the air's below)
Definition: ERF_TwoStreamCanopyForcing.H:134
amrex::Real lw_down
Longwave down at the face's height.
Definition: ERF_TwoStreamCanopyForcing.H:132
amrex::Real dni
Direct-normal irradiance at the face's height.
Definition: ERF_TwoStreamCanopyForcing.H:130