49 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
51 for (MFIter mfi(dst, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
52 const Box& bx = mfi.tilebox();
53 const auto dst_arr = dst.array(mfi);
55 const auto tv = array_or_empty(sources.native_temperature_vegetated, mfi);
56 const auto tb = array_or_empty(sources.native_temperature_bare, mfi);
57 const auto qv = array_or_empty(sources.native_mixing_ratio_vegetated, mfi);
58 const auto qb = array_or_empty(sources.native_mixing_ratio_bare, mfi);
59 const auto fv = array_or_empty(sources.native_vegetation_fraction, mfi);
60 const auto ts = array_or_empty(sources.theta_surface, mfi);
61 const auto tstar = array_or_empty(sources.theta_star, mfi);
62 const auto qs = array_or_empty(sources.mixing_ratio_surface, mfi);
63 const auto qstar = array_or_empty(sources.mixing_ratio_star, mfi);
64 const auto z0 = array_or_empty(sources.roughness_height, mfi);
65 const auto olen = array_or_empty(sources.obukhov_length, mfi);
66 const auto source_mask = array_or_empty(sources.source_mask, mfi);
67 const auto lmask = int_array_or_empty(sources.land_mask, mfi);
68 const auto cons = array_or_empty(sources.cons, mfi);
69 const auto znd = array_or_empty(sources.z_phys_nd, mfi);
71 const bool request_temperature = temperature_comp >= 0;
72 const bool request_mixing_ratio = mixing_ratio_comp >= 0;
73 const bool request_source = source_comp >= 0;
77 const bool source_only = request_source && !request_temperature &&
78 !request_mixing_ratio;
79 const bool need_temperature = request_temperature || source_only;
80 const bool need_mixing_ratio = request_mixing_ratio;
81 const bool have_native_temperature = sources.native_temperature_vegetated &&
82 sources.native_temperature_bare &&
83 sources.native_vegetation_fraction;
84 const bool have_native_mixing_ratio = sources.native_mixing_ratio_vegetated &&
85 sources.native_mixing_ratio_bare &&
86 sources.native_vegetation_fraction;
87 const bool have_most_temperature = sources.theta_surface && sources.theta_star &&
88 sources.roughness_height && sources.obukhov_length;
89 const bool have_most_mixing_ratio = sources.mixing_ratio_surface &&
90 sources.mixing_ratio_star &&
91 sources.roughness_height && sources.obukhov_length;
92 const bool have_atmosphere = sources.cons !=
nullptr;
93 const bool have_source_mask = sources.source_mask !=
nullptr;
94 const bool have_land_mask = sources.land_mask !=
nullptr;
95 const int klo = sources.klo;
96 const Real dz = sources.dz;
97 const bool moist = sources.moist;
98 const bool has_lsm = sources.has_lsm;
100 ParallelFor(bx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept {
101 Real temperature = missing_value;
102 Real mixing_ratio = missing_value;
106 const NativeBundle native_bundle{
107 have_native_temperature ? tv(i,j,0) : missing_value,
108 have_native_temperature ? tb(i,j,0) : missing_value,
109 have_native_mixing_ratio ?
qv(i,j,0) : missing_value,
110 have_native_mixing_ratio ? qb(i,j,0) : missing_value,
111 (have_native_temperature || have_native_mixing_ratio) ? fv(i,j,0) : missing_value
113 const bool native_temperature_valid = have_native_temperature &&
115 const bool native_mixing_ratio_valid = moist && have_native_mixing_ratio &&
117 const bool native_selected = (!need_temperature || native_temperature_valid) &&
118 (!need_mixing_ratio || native_mixing_ratio_valid);
120 bool selected =
false;
121 if (native_selected && (need_temperature || need_mixing_ratio)) {
123 if (need_temperature) {
124 temperature = aggregate.temperature;
126 if (need_mixing_ratio) {
127 mixing_ratio = aggregate.mixing_ratio;
134 if (!selected && (need_temperature || need_mixing_ratio)) {
135 const MostState state{
136 have_most_temperature ? ts(i,j,0) : missing_value,
137 have_most_temperature ? tstar(i,j,0) : missing_value,
138 have_most_mixing_ratio ?
qs(i,j,0) : missing_value,
139 have_most_mixing_ratio ? qstar(i,j,0) : missing_value,
140 (have_most_temperature || have_most_mixing_ratio) ?
z0(i,j,0) : missing_value,
141 (have_most_temperature || have_most_mixing_ratio) ? olen(i,j,0) : missing_value
145 bool most_temperature_valid =
false;
146 bool most_mixing_ratio_valid =
false;
147 Real theta_2m = missing_value;
148 Real q_2m = missing_value;
149 if (common_most_valid && need_temperature && have_most_temperature) {
150 theta_2m = state.theta_surface + state.theta_star /
KAPPA * factor;
161 (z_cc_agl -
Real(2.0));
166 if (most_temperature_valid) { temperature = t_2m; }
170 if (common_most_valid && need_mixing_ratio && moist &&
171 have_most_mixing_ratio &&
valid_real(state.mixing_ratio_surface) &&
173 q_2m = state.mixing_ratio_surface + state.mixing_ratio_star /
KAPPA * factor;
175 if (most_mixing_ratio_valid) {
179 const bool most_selected = (!need_temperature || most_temperature_valid) &&
180 (!need_mixing_ratio || most_mixing_ratio_valid);
183 if (!most_selected) {
184 temperature = missing_value;
185 mixing_ratio = missing_value;
188 if (have_source_mask && source_value_is_valid(source_mask(i,j,0))) {
189 source_value = source_mask(i,j,0);
190 if (
static_cast<int>(source_value) ==
195 }
else if (have_land_mask && lmask(i,j,0) == 0) {
207 if (temperature_comp >= 0) {
208 dst_arr(i,j,k,temperature_comp) = temperature;
210 if (mixing_ratio_comp >= 0) {
211 dst_arr(i,j,k,mixing_ratio_comp) = (selected && moist)
212 ? mixing_ratio : missing_value;
214 if (source_comp >= 0) {
215 dst_arr(i,j,k,source_comp) = source_value;
constexpr amrex::Real Cp_d
Definition: ERF_Constants.H:49
constexpr amrex::Real zero
Definition: ERF_Constants.H:8
constexpr amrex::Real CONST_GRAV
Definition: ERF_Constants.H:64
constexpr amrex::Real R_d
Definition: ERF_Constants.H:47
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:36
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:37
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:42
Real z0
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:8
rho
Definition: ERF_InitCustomPert_Bubble.H:107
ParallelFor(grown_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);})
AMREX_GPU_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:389
@ qv
Definition: ERF_Kessler.H:30
@ qs
Definition: ERF_WSM6.H:29
@ cons
Definition: ERF_IndexDefines.H:175
@ dz
Definition: ERF_AdvanceWSM6.cpp:104
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool native_bundle_temperature_is_valid(const NativeBundle &bundle) noexcept
Definition: ERF_NearSurfaceDiagnostics.H:78
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE NativeAggregate aggregate_native_bundle(const NativeBundle &bundle) noexcept
Definition: ERF_NearSurfaceDiagnostics.H:110
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool native_bundle_mixing_ratio_is_valid(const NativeBundle &bundle) noexcept
Definition: ERF_NearSurfaceDiagnostics.H:90
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real to_plot_value(SurfaceDiagnosticSource source) noexcept
Definition: ERF_SurfaceDiagnosticSource.H:35
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int to_int(SurfaceDiagnosticSource source) noexcept
Definition: ERF_SurfaceDiagnosticSource.H:28