1 #ifndef ERF_TOPOGRAPHIC_SHADING_KERNELS_H_
2 #define ERF_TOPOGRAPHIC_SHADING_KERNELS_H_
4 #include <AMReX_Array4.H>
5 #include <AMReX_GpuQualifiers.H>
18 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
21 const double lat = double(lat_deg) * double(
PI) / 180.0;
22 const double h = 2.0 * double(
PI) * (calday - std::floor(calday))
23 +
double(lon_deg) * double(
PI) / 180.0 - double(
PI);
24 return {
Real(-std::cos(declin) * std::sin(h)),
25 Real(std::cos(lat)*std::sin(declin) - std::sin(lat)*std::cos(declin)*std::cos(h)),
26 Real(std::sin(lat)*std::sin(declin) + std::cos(lat)*std::cos(declin)*std::cos(h))};
29 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
32 return amrex::max(
Real(0), (s.
z - hx*s.
x - hy*s.
y) / std::sqrt(
Real(1) + hx*hx + hy*hy));
35 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
36 int wrap (
int i,
int lo,
int n) {
return lo + ((i-
lo) % n + n) % n; }
42 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
43 bool shadowed (
int i,
int j,
const amrex::Array4<const Real>& terrain,
44 int ilo,
int ihi,
int jlo,
int jhi,
bool periodic_x,
bool periodic_y,
47 const Real horizontal = std::sqrt(s.
x*s.
x + s.
y*s.
y);
51 if (s.
z <=
Real(1.e-4) || horizontal <= std::sqrt(
real_eps)) {
return false; }
55 const Real di = std::abs(s.
x) < angular_eps*horizontal ?
Real(0) : s.
x / (horizontal *
dx);
56 const Real dj = std::abs(s.
y) < angular_eps*horizontal ?
Real(0) : s.
y / (horizontal *
dy);
57 const Real ds =
Real(1) / amrex::max(std::abs(
di), std::abs(dj));
58 const Real z = terrain(i,j,0,0);
59 for (
Real r =
ds; r <= search_length; r +=
ds) {
61 if ((!periodic_x && (x < ilo || x > ihi)) ||
62 (!periodic_y && (y < jlo || y > jhi))) {
break; }
63 int ix = int(std::floor(
x)), jy = int(std::floor(
y));
65 int ip = ix+1, jp = jy+1;
66 if (periodic_x) { ix =
wrap(ix,ilo,ihi-ilo+1); ip =
wrap(ip,ilo,ihi-ilo+1); }
67 else { ip = amrex::min(ip,ihi); }
68 if (periodic_y) { jy =
wrap(jy,jlo,jhi-jlo+1); jp =
wrap(jp,jlo,jhi-jlo+1); }
69 else { jp = amrex::min(jp,jhi); }
70 AMREX_ASSERT(terrain.contains(ix,jy,0) && terrain.contains(ip,jp,0));
71 const Real h = (
Real(1)-wy)*((
Real(1)-wx)*terrain(ix,jy,0,0) + wx*terrain(ip,jy,0,0))
72 + wy*((
Real(1)-wx)*terrain(ix,jp,0,0) + wx*terrain(ip,jp,0,0));
75 const Real ray_height =
z + r*s.
z/horizontal;
77 const Real height_scale = amrex::max(
Real(1),
78 amrex::max(std::abs(
z), amrex::max(std::abs(h), std::abs(ray_height))));
80 if (h > ray_height + height_tol) {
return true; }
85 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
88 return diffuse + direct*factor;
const Real dy
Definition: ERF_InitCustomPert_ABL.H:45
const Real dx
Definition: ERF_InitCustomPert_ABL.H:44
constexpr amrex::Real real_eps
Definition: ERF_NumericalConstants.H:34
constexpr amrex::Real PI
Definition: ERF_NumericalConstants.H:46
amrex::Real Real
Definition: ERF_ShocInterface.H:19
Definition: ERF_TopographicShadingKernels.H:10
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool shadowed(int i, int j, const amrex::Array4< const Real > &terrain, int ilo, int ihi, int jlo, int jhi, bool periodic_x, bool periodic_y, Real dx, Real dy, Sun s, Real search_length)
Definition: ERF_TopographicShadingKernels.H:43
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real incidence(Real hx, Real hy, Sun s)
Definition: ERF_TopographicShadingKernels.H:30
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int wrap(int i, int lo, int n)
Definition: ERF_TopographicShadingKernels.H:36
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Sun sun_direction(double calday, double declin, Real lat_deg, Real lon_deg)
Definition: ERF_TopographicShadingKernels.H:19
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real corrected_shortwave(Real direct, Real diffuse, Real factor)
Definition: ERF_TopographicShadingKernels.H:86
real(c_double), parameter epsilon
Definition: ERF_module_model_constants.F90:12
real(c_double), private ds
Definition: ERF_module_mp_morr_two_moment.F90:203
real(c_double), private di
Definition: ERF_module_mp_morr_two_moment.F90:203
Definition: ERF_TopographicShadingKernels.H:13
Real x
Definition: ERF_TopographicShadingKernels.H:13
Real z
Definition: ERF_TopographicShadingKernels.H:13
Real y
Definition: ERF_TopographicShadingKernels.H:13