52 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
54 for (MFIter mfi(dst, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
55 const Box& bx = mfi.tilebox();
56 const auto dst_arr = dst.array(mfi);
58 const auto tv = array_or_empty(sources.native_temperature_vegetated, mfi);
59 const auto tb = array_or_empty(sources.native_temperature_bare, mfi);
60 const auto qv = array_or_empty(sources.native_mixing_ratio_vegetated, mfi);
61 const auto qb = array_or_empty(sources.native_mixing_ratio_bare, mfi);
62 const auto fv = array_or_empty(sources.native_vegetation_fraction, mfi);
63 const auto ts = array_or_empty(sources.theta_surface, mfi);
64 const auto tstar = array_or_empty(sources.theta_star, mfi);
65 const auto qs = array_or_empty(sources.mixing_ratio_surface, mfi);
66 const auto qstar = array_or_empty(sources.mixing_ratio_star, mfi);
67 const auto z0 = array_or_empty(sources.roughness_height, mfi);
68 const auto olen = array_or_empty(sources.obukhov_length, mfi);
69 const auto source_mask = array_or_empty(sources.source_mask, mfi);
70 const auto lmask = int_array_or_empty(sources.land_mask, mfi);
71 const auto cons = array_or_empty(sources.cons, mfi);
72 const auto znd = array_or_empty(sources.z_phys_nd, mfi);
73 const auto zsfc = array_or_empty(sources.z_sfc_nd, mfi);
75 const bool request_temperature = temperature_comp >= 0;
76 const bool request_mixing_ratio = mixing_ratio_comp >= 0;
77 const bool request_source = source_comp >= 0;
81 const bool source_only = request_source && !request_temperature &&
82 !request_mixing_ratio;
83 const bool need_temperature = request_temperature || source_only;
84 const bool need_mixing_ratio = request_mixing_ratio;
85 const bool have_native_temperature = sources.native_temperature_vegetated &&
86 sources.native_temperature_bare &&
87 sources.native_vegetation_fraction;
88 const bool have_native_mixing_ratio = sources.native_mixing_ratio_vegetated &&
89 sources.native_mixing_ratio_bare &&
90 sources.native_vegetation_fraction;
91 const bool have_most_temperature = sources.theta_surface && sources.theta_star &&
92 sources.roughness_height && sources.obukhov_length;
93 const bool have_most_mixing_ratio = sources.mixing_ratio_surface &&
94 sources.mixing_ratio_star &&
95 sources.roughness_height && sources.obukhov_length;
96 const bool have_atmosphere = sources.cons !=
nullptr;
97 const bool have_source_mask = sources.source_mask !=
nullptr;
98 const bool have_land_mask = sources.land_mask !=
nullptr;
99 const int klo = sources.klo;
100 const Real
dz = sources.dz;
101 const bool moist = sources.moist;
102 const bool has_lsm = sources.has_lsm;
105 ParallelFor(bx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept {
106 Real temperature = missing_value;
107 Real mixing_ratio = missing_value;
111 const NativeBundle native_bundle{
112 have_native_temperature ?
tv(i,j,0) : missing_value,
113 have_native_temperature ? tb(i,j,0) : missing_value,
114 have_native_mixing_ratio ?
qv(i,j,0) : missing_value,
115 have_native_mixing_ratio ? qb(i,j,0) : missing_value,
116 (have_native_temperature || have_native_mixing_ratio) ? fv(i,j,0) : missing_value
118 const bool native_temperature_valid = have_native_temperature &&
120 const bool native_mixing_ratio_valid = moist && have_native_mixing_ratio &&
122 const bool native_selected = (!need_temperature || native_temperature_valid) &&
123 (!need_mixing_ratio || native_mixing_ratio_valid);
125 bool selected =
false;
126 if (native_selected && (need_temperature || need_mixing_ratio)) {
128 if (need_temperature) {
129 temperature = aggregate.temperature;
131 if (need_mixing_ratio) {
132 mixing_ratio = aggregate.mixing_ratio;
139 if (!selected && (need_temperature || need_mixing_ratio)) {
140 const MostState state{
141 have_most_temperature ? ts(i,j,0) : missing_value,
142 have_most_temperature ?
tstar(i,j,0) : missing_value,
143 have_most_mixing_ratio ?
qs(i,j,0) : missing_value,
144 have_most_mixing_ratio ?
qstar(i,j,0) : missing_value,
145 (have_most_temperature || have_most_mixing_ratio) ?
z0(i,j,0) : missing_value,
146 (have_most_temperature || have_most_mixing_ratio) ?
olen(i,j,0) : missing_value
150 bool most_temperature_valid =
false;
151 bool most_mixing_ratio_valid =
false;
152 Real theta_2m = missing_value;
153 Real q_2m = missing_value;
154 if (common_most_valid && need_temperature && have_most_temperature) {
155 theta_2m = state.theta_surface + state.theta_star /
KAPPA * factor;
166 (z_cc_agl - Real(2.0));
171 if (most_temperature_valid) { temperature = t_2m; }
175 if (common_most_valid && need_mixing_ratio && moist &&
176 have_most_mixing_ratio &&
valid_real(state.mixing_ratio_surface) &&
178 q_2m = state.mixing_ratio_surface + state.mixing_ratio_star /
KAPPA * factor;
180 if (most_mixing_ratio_valid) {
184 const bool most_selected = (!need_temperature || most_temperature_valid) &&
185 (!need_mixing_ratio || most_mixing_ratio_valid);
188 if (!most_selected) {
189 temperature = missing_value;
190 mixing_ratio = missing_value;
193 if (have_source_mask && source_value_is_valid(source_mask(i,j,0))) {
194 source_value = source_mask(i,j,0);
195 if (
static_cast<int>(source_value) ==
200 }
else if (have_land_mask && lmask(i,j,0) == 0) {
212 if (temperature_comp >= 0) {
213 dst_arr(i,j,k,temperature_comp) = temperature;
215 if (mixing_ratio_comp >= 0) {
216 dst_arr(i,j,k,mixing_ratio_comp) = (selected && moist)
217 ? mixing_ratio : missing_value;
219 if (source_comp >= 0) {
220 dst_arr(i,j,k,source_comp) = source_value;
constexpr amrex::Real Cp_d
Definition: ERF_Constants.H:51
constexpr amrex::Real CONST_GRAV
Definition: ERF_Constants.H:72
constexpr amrex::Real R_d
Definition: ERF_Constants.H:49
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getPgivenRTh(const amrex::Real rhotheta, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:81
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getTgivenPandTh(const amrex::Real P, const amrex::Real th, const amrex::Real rdOcp)
Definition: ERF_EOS.H:32
#define Rho_comp
Definition: ERF_IndexDefines.H:61
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:62
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:78
Real z0
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:12
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
const int klo
Definition: ERF_InitCustomPert_KE.H:9
ParallelFor(fab_box, [=] AMREX_GPU_DEVICE(int i, int j, int k) { qrcuten_arr(i, j, k)=Real(0);qscuten_arr(i, j, k)=Real(0);qicuten_arr(i, j, k)=Real(0);})
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_Zrel_AtCellCenter(const int &i, const int &j, const int &k, const amrex::Array4< const amrex::Real > &z_sfc_nd, const amrex::Array4< const amrex::Real > &z_nd)
Definition: ERF_TerrainMetrics.H:764
@ olen
Definition: ERF_SLM.H:106
@ tv
Definition: ERF_SLM.H:48
@ qstar
Definition: ERF_SLM.H:32
@ tstar
Definition: ERF_SLM.H:31
@ rho
Definition: ERF_Kessler.H:25
@ qv
Definition: ERF_Kessler.H:31
@ qs
Definition: ERF_Morrison.H:113
@ cons
Definition: ERF_IndexDefines.H:231
@ dz
Definition: ERF_AdvanceWDM6.cpp:273
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool native_bundle_temperature_is_valid(const NativeBundle &bundle) noexcept
Definition: ERF_NearSurfaceDiagnostics.H:95
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE NativeAggregate aggregate_native_bundle(const NativeBundle &bundle) noexcept
Definition: ERF_NearSurfaceDiagnostics.H:131
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool native_bundle_mixing_ratio_is_valid(const NativeBundle &bundle) noexcept
Definition: ERF_NearSurfaceDiagnostics.H:109
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real to_plot_value(SurfaceDiagnosticSource source) noexcept
Definition: ERF_SurfaceDiagnosticSource.H:45
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int to_int(SurfaceDiagnosticSource source) noexcept
Definition: ERF_SurfaceDiagnosticSource.H:33
Definition: ERF_MOSTUtils.H:84