50 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
52 for (MFIter mfi(dst, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
53 const Box& bx = mfi.tilebox();
54 const auto dst_arr = dst.array(mfi);
56 const auto tv = array_or_empty(sources.native_temperature_vegetated, mfi);
57 const auto tb = array_or_empty(sources.native_temperature_bare, mfi);
58 const auto qv = array_or_empty(sources.native_mixing_ratio_vegetated, mfi);
59 const auto qb = array_or_empty(sources.native_mixing_ratio_bare, mfi);
60 const auto fv = array_or_empty(sources.native_vegetation_fraction, mfi);
61 const auto ts = array_or_empty(sources.theta_surface, mfi);
62 const auto tstar = array_or_empty(sources.theta_star, mfi);
63 const auto qs = array_or_empty(sources.mixing_ratio_surface, mfi);
64 const auto qstar = array_or_empty(sources.mixing_ratio_star, mfi);
65 const auto z0 = array_or_empty(sources.roughness_height, mfi);
66 const auto olen = array_or_empty(sources.obukhov_length, mfi);
67 const auto source_mask = array_or_empty(sources.source_mask, mfi);
68 const auto lmask = int_array_or_empty(sources.land_mask, mfi);
69 const auto cons = array_or_empty(sources.cons, mfi);
70 const auto znd = array_or_empty(sources.z_phys_nd, mfi);
72 const bool request_temperature = temperature_comp >= 0;
73 const bool request_mixing_ratio = mixing_ratio_comp >= 0;
74 const bool request_source = source_comp >= 0;
78 const bool source_only = request_source && !request_temperature &&
79 !request_mixing_ratio;
80 const bool need_temperature = request_temperature || source_only;
81 const bool need_mixing_ratio = request_mixing_ratio;
82 const bool have_native_temperature = sources.native_temperature_vegetated &&
83 sources.native_temperature_bare &&
84 sources.native_vegetation_fraction;
85 const bool have_native_mixing_ratio = sources.native_mixing_ratio_vegetated &&
86 sources.native_mixing_ratio_bare &&
87 sources.native_vegetation_fraction;
88 const bool have_most_temperature = sources.theta_surface && sources.theta_star &&
89 sources.roughness_height && sources.obukhov_length;
90 const bool have_most_mixing_ratio = sources.mixing_ratio_surface &&
91 sources.mixing_ratio_star &&
92 sources.roughness_height && sources.obukhov_length;
93 const bool have_atmosphere = sources.cons !=
nullptr;
94 const bool have_source_mask = sources.source_mask !=
nullptr;
95 const bool have_land_mask = sources.land_mask !=
nullptr;
96 const int klo = sources.klo;
97 const Real dz = sources.dz;
98 const bool moist = sources.moist;
99 const bool has_lsm = sources.has_lsm;
101 ParallelFor(bx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept {
102 Real temperature = missing_value;
103 Real mixing_ratio = missing_value;
107 const NativeBundle native_bundle{
108 have_native_temperature ?
tv(i,j,0) : missing_value,
109 have_native_temperature ? tb(i,j,0) : missing_value,
110 have_native_mixing_ratio ?
qv(i,j,0) : missing_value,
111 have_native_mixing_ratio ? qb(i,j,0) : missing_value,
112 (have_native_temperature || have_native_mixing_ratio) ? fv(i,j,0) : missing_value
114 const bool native_temperature_valid = have_native_temperature &&
116 const bool native_mixing_ratio_valid = moist && have_native_mixing_ratio &&
118 const bool native_selected = (!need_temperature || native_temperature_valid) &&
119 (!need_mixing_ratio || native_mixing_ratio_valid);
121 bool selected =
false;
122 if (native_selected && (need_temperature || need_mixing_ratio)) {
124 if (need_temperature) {
125 temperature = aggregate.temperature;
127 if (need_mixing_ratio) {
128 mixing_ratio = aggregate.mixing_ratio;
135 if (!selected && (need_temperature || need_mixing_ratio)) {
136 const MostState state{
137 have_most_temperature ? ts(i,j,0) : missing_value,
138 have_most_temperature ?
tstar(i,j,0) : missing_value,
139 have_most_mixing_ratio ?
qs(i,j,0) : missing_value,
140 have_most_mixing_ratio ?
qstar(i,j,0) : missing_value,
141 (have_most_temperature || have_most_mixing_ratio) ?
z0(i,j,0) : missing_value,
142 (have_most_temperature || have_most_mixing_ratio) ?
olen(i,j,0) : missing_value
146 bool most_temperature_valid =
false;
147 bool most_mixing_ratio_valid =
false;
148 Real theta_2m = missing_value;
149 Real q_2m = missing_value;
150 if (common_most_valid && need_temperature && have_most_temperature) {
151 theta_2m = state.theta_surface + state.theta_star /
KAPPA * factor;
162 (z_cc_agl -
Real(2.0));
167 if (most_temperature_valid) { temperature = t_2m; }
171 if (common_most_valid && need_mixing_ratio && moist &&
172 have_most_mixing_ratio &&
valid_real(state.mixing_ratio_surface) &&
174 q_2m = state.mixing_ratio_surface + state.mixing_ratio_star /
KAPPA * factor;
176 if (most_mixing_ratio_valid) {
180 const bool most_selected = (!need_temperature || most_temperature_valid) &&
181 (!need_mixing_ratio || most_mixing_ratio_valid);
184 if (!most_selected) {
185 temperature = missing_value;
186 mixing_ratio = missing_value;
189 if (have_source_mask && source_value_is_valid(source_mask(i,j,0))) {
190 source_value = source_mask(i,j,0);
191 if (
static_cast<int>(source_value) ==
196 }
else if (have_land_mask && lmask(i,j,0) == 0) {
208 if (temperature_comp >= 0) {
209 dst_arr(i,j,k,temperature_comp) = temperature;
211 if (mixing_ratio_comp >= 0) {
212 dst_arr(i,j,k,mixing_ratio_comp) = (selected && moist)
213 ? mixing_ratio : missing_value;
215 if (source_comp >= 0) {
216 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:53
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:54
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:66
Real z0
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:12
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_nd)
Definition: ERF_TerrainMetrics.H:762
@ olen
Definition: ERF_SLM.H:104
@ tv
Definition: ERF_SLM.H:46
@ qstar
Definition: ERF_SLM.H:30
@ tstar
Definition: ERF_SLM.H:29
@ rho
Definition: ERF_Kessler.H:25
@ qv
Definition: ERF_Kessler.H:31
@ qs
Definition: ERF_Morrison.H:113
@ cons
Definition: ERF_IndexDefines.H:254
@ 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