ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
near_surface_diagnostics Namespace Reference

Classes

struct  NativeBundle
 
struct  NativeAggregate
 
struct  MostState
 
struct  MostProfile
 
struct  Sources
 
struct  WindSources
 

Functions

void fill (MultiFab &dst, int temperature_comp, int mixing_ratio_comp, int source_comp, const Sources &sources, Real missing_value)
 
void fill_wind_10m (MultiFab &dst, int u_comp, int v_comp, int u_east_comp, int v_north_comp, const WindSources &sources, Real missing_value)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool valid_real (amrex::Real value) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool valid_noahmp_component (amrex::Real value) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool native_bundle_temperature_is_valid (const NativeBundle &bundle) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool native_bundle_mixing_ratio_is_valid (const NativeBundle &bundle) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool native_bundle_vegetation_fraction_is_valid (const NativeBundle &bundle) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool native_bundle_is_valid (const NativeBundle &bundle) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool native_vegetated_tile_is_used (amrex::Real vegetation_fraction) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool native_bare_tile_is_used (amrex::Real vegetation_fraction) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE NativeAggregate aggregate_native_bundle (const NativeBundle &bundle) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real most_profile_zeta_max (const similarity_funs &sfuns) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool evaluate_most_factor (const MostState &state, amrex::Real height, amrex::Real &factor, const similarity_funs &sfuns) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool evaluate_most_momentum_factor (amrex::Real roughness_height, amrex::Real obukhov_length, amrex::Real height, amrex::Real &factor, const similarity_funs &sfuns) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool evaluate_most_profile (const MostState &state, amrex::Real height, MostProfile &profile, const similarity_funs &sfuns) noexcept
 
void fill (amrex::MultiFab &dst, int temperature_comp, int mixing_ratio_comp, int source_comp, const Sources &sources, amrex::Real missing_value=amrex::Real(-999.0))
 
void fill_wind_10m (amrex::MultiFab &dst, int u_comp, int v_comp, int u_east_comp, int v_north_comp, const WindSources &sources, amrex::Real missing_value=amrex::Real(-999.0))
 

Variables

constexpr amrex::Real wind_height = amrex::Real(10.0)
 

Function Documentation

◆ aggregate_native_bundle()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE NativeAggregate near_surface_diagnostics::aggregate_native_bundle ( const NativeBundle &  bundle)
noexcept
132 {
133  const amrex::Real f = bundle.vegetation_fraction;
134  // At the endpoints take the one tile in use, so that an unused tile's
135  // placeholder (which may be a sentinel) cannot leak in through 0 * value.
137  return {bundle.temperature_bare, bundle.mixing_ratio_bare};
138  }
139  if (!native_bare_tile_is_used(f)) {
140  return {bundle.temperature_vegetated, bundle.mixing_ratio_vegetated};
141  }
142  return {
143  f * bundle.temperature_vegetated + (amrex::Real(1.0)-f) * bundle.temperature_bare,
144  f * bundle.mixing_ratio_vegetated + (amrex::Real(1.0)-f) * bundle.mixing_ratio_bare
145  };
146 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool native_vegetated_tile_is_used(amrex::Real vegetation_fraction) noexcept
Definition: ERF_NearSurfaceDiagnostics.H:83
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool native_bare_tile_is_used(amrex::Real vegetation_fraction) noexcept
Definition: ERF_NearSurfaceDiagnostics.H:89

Referenced by fill().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ evaluate_most_factor()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool near_surface_diagnostics::evaluate_most_factor ( const MostState &  state,
amrex::Real  height,
amrex::Real &  factor,
const similarity_funs &  sfuns 
)
noexcept
169 {
170  if (!valid_real(state.roughness_height) ||
171  !valid_real(state.obukhov_length) ||
172  state.roughness_height <= amrex::Real(0.0) ||
173  height <= state.roughness_height ||
174  state.obukhov_length == amrex::Real(0.0)) {
175  return false;
176  }
177  const amrex::Real zeta = amrex::min(height / state.obukhov_length,
178  most_profile_zeta_max(sfuns));
179  factor = std::log(height / state.roughness_height) - sfuns.calc_psi_h(zeta);
180  return valid_real(factor);
181 }
Real height
Definition: ERF_InitCustomPert_SquallLine.H:37
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real most_profile_zeta_max(const similarity_funs &sfuns) noexcept
Definition: ERF_NearSurfaceDiagnostics.H:155
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool valid_real(amrex::Real value) noexcept
Definition: ERF_NearSurfaceDiagnostics.H:49
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real calc_psi_h(amrex::Real zeta) const
Definition: ERF_MOSTUtils.H:168

Referenced by evaluate_most_profile(), and fill().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ evaluate_most_momentum_factor()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool near_surface_diagnostics::evaluate_most_momentum_factor ( amrex::Real  roughness_height,
amrex::Real  obukhov_length,
amrex::Real  height,
amrex::Real &  factor,
const similarity_funs &  sfuns 
)
noexcept
191 {
192  if (!valid_real(roughness_height) || !valid_real(obukhov_length) ||
193  roughness_height <= amrex::Real(0.0) ||
194  height <= roughness_height ||
195  obukhov_length == amrex::Real(0.0)) {
196  return false;
197  }
198  const amrex::Real zeta = amrex::min(height / obukhov_length,
199  most_profile_zeta_max(sfuns));
200  factor = std::log(height / roughness_height) - sfuns.calc_psi_m(zeta);
201  return valid_real(factor);
202 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real calc_psi_m(amrex::Real zeta) const
Definition: ERF_MOSTUtils.H:149

Referenced by fill_wind_10m().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ evaluate_most_profile()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool near_surface_diagnostics::evaluate_most_profile ( const MostState &  state,
amrex::Real  height,
MostProfile &  profile,
const similarity_funs &  sfuns 
)
noexcept
211 {
212  if (!valid_real(state.theta_surface) || !valid_real(state.theta_star) ||
213  !valid_real(state.mixing_ratio_surface) || !valid_real(state.mixing_ratio_star)) {
214  return false;
215  }
216 
217  amrex::Real profile_factor = amrex::Real(0.0);
218  if (!evaluate_most_factor(state, height, profile_factor, sfuns)) {
219  return false;
220  }
221 
222  profile.potential_temperature = state.theta_surface +
223  state.theta_star / KAPPA * profile_factor;
224  profile.mixing_ratio = state.mixing_ratio_surface +
225  state.mixing_ratio_star / KAPPA * profile_factor;
226  return valid_real(profile.potential_temperature) &&
227  valid_real(profile.mixing_ratio) &&
228  profile.potential_temperature > amrex::Real(0.0) &&
229  profile.mixing_ratio >= amrex::Real(0.0);
230 }
constexpr amrex::Real KAPPA
Definition: ERF_Constants.H:71
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool evaluate_most_factor(const MostState &state, amrex::Real height, amrex::Real &factor, const similarity_funs &sfuns) noexcept
Definition: ERF_NearSurfaceDiagnostics.H:165
Here is the call graph for this function:

◆ fill() [1/2]

void near_surface_diagnostics::fill ( amrex::MultiFab &  dst,
int  temperature_comp,
int  mixing_ratio_comp,
int  source_comp,
const Sources &  sources,
amrex::Real  missing_value = amrex::Real(-999.0) 
)

◆ fill() [2/2]

void near_surface_diagnostics::fill ( MultiFab &  dst,
int  temperature_comp,
int  mixing_ratio_comp,
int  source_comp,
const Sources &  sources,
Real  missing_value 
)
48 {
49  AMREX_ALWAYS_ASSERT(sources.z_phys_nd == nullptr || sources.z_sfc_nd != nullptr);
50 
51 #ifdef _OPENMP
52 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
53 #endif
54  for (MFIter mfi(dst, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
55  const Box& bx = mfi.tilebox();
56  const auto dst_arr = dst.array(mfi);
57 
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);
74 
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;
78  // Provenance follows the temperature path only for a source-only
79  // request. When paired with humidity, it describes the humidity
80  // source without adding an unrequested temperature prerequisite.
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;
103  const similarity_funs sfuns = sources.sfuns;
104 
105  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
106  Real temperature = missing_value;
107  Real mixing_ratio = missing_value;
108  Real source_value = surface_diagnostics::to_plot_value(
110 
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
117  };
118  const bool native_temperature_valid = have_native_temperature &&
119  native_bundle_temperature_is_valid(native_bundle);
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);
124 
125  bool selected = false;
126  if (native_selected && (need_temperature || need_mixing_ratio)) {
127  const NativeAggregate aggregate = aggregate_native_bundle(native_bundle);
128  if (need_temperature) {
129  temperature = aggregate.temperature;
130  }
131  if (need_mixing_ratio) {
132  mixing_ratio = aggregate.mixing_ratio;
133  }
134  source_value = surface_diagnostics::to_plot_value(
136  selected = true;
137  }
138 
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
147  };
148  Real factor = zero;
149  const bool common_most_valid = evaluate_most_factor(state, Real(2.0), factor, sfuns);
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;
156  if (valid_real(theta_2m) && theta_2m > zero && have_atmosphere) {
157  const Real rho = cons(i,j,klo,Rho_comp);
158  const Real rhotheta = cons(i,j,klo,RhoTheta_comp);
159  const Real q_cell = moist ? cons(i,j,klo,RhoQ1_comp) / rho : zero;
160  if (valid_real(rho) && rho > zero && valid_real(rhotheta) &&
161  valid_real(q_cell) && q_cell >= zero) {
162  const Real p_cc = getPgivenRTh(rhotheta, q_cell);
163  const Real z_cc_agl = znd ? Compute_Zrel_AtCellCenter(i,j,klo,zsfc,znd)
164  : Real(0.5) * dz;
165  const Real p_2m = p_cc + rho * CONST_GRAV *
166  (z_cc_agl - Real(2.0));
167  const Real t_2m = (valid_real(p_2m) && p_2m > zero)
168  ? getTgivenPandTh(p_2m, theta_2m, R_d/Cp_d)
169  : missing_value;
170  most_temperature_valid = valid_real(t_2m) && t_2m > zero;
171  if (most_temperature_valid) { temperature = t_2m; }
172  }
173  }
174  }
175  if (common_most_valid && need_mixing_ratio && moist &&
176  have_most_mixing_ratio && valid_real(state.mixing_ratio_surface) &&
177  valid_real(state.mixing_ratio_star)) {
178  q_2m = state.mixing_ratio_surface + state.mixing_ratio_star / KAPPA * factor;
179  most_mixing_ratio_valid = valid_real(q_2m) && q_2m >= zero;
180  if (most_mixing_ratio_valid) {
181  mixing_ratio = q_2m;
182  }
183  }
184  const bool most_selected = (!need_temperature || most_temperature_valid) &&
185  (!need_mixing_ratio || most_mixing_ratio_valid);
186  // Do not expose a valid scalar from an incomplete MOST bundle
187  // when both requested fields must come from one source.
188  if (!most_selected) {
189  temperature = missing_value;
190  mixing_ratio = missing_value;
191  }
192  if (most_selected) {
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) ==
197  source_value = surface_diagnostics::to_plot_value(
199  }
200  } else if (have_land_mask && lmask(i,j,0) == 0) {
201  source_value = surface_diagnostics::to_plot_value(
203  } else {
204  source_value = surface_diagnostics::to_plot_value(
207  }
208  selected = true;
209  }
210  }
211 
212  if (temperature_comp >= 0) {
213  dst_arr(i,j,k,temperature_comp) = temperature;
214  }
215  if (mixing_ratio_comp >= 0) {
216  dst_arr(i,j,k,mixing_ratio_comp) = (selected && moist)
217  ? mixing_ratio : missing_value;
218  }
219  if (source_comp >= 0) {
220  dst_arr(i,j,k,source_comp) = source_value;
221  }
222  });
223  }
224 }
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

Referenced by erf_sbm::SBMAMRFluxRegister::accept_reflux(), erf_sbm::SBMTransport::advance_stage(), erf_sbm::SBMAMRFluxRegister::begin_interval(), erf_auxiliary::CompletedStepFluxLedger::begin_stage(), IBFaceSet::build(), erf_sbm::SBMAMRFluxRegister::discard_interval(), erf_auxiliary::CompletedStepFluxLedger::discard_step(), ERF::FillPlot2DVars(), SLM::init_from_inputs(), PlaneAverage::operator()(), obs_nudging::parse_station_series(), erf_sbm::SBMAMRFluxRegister::reflux(), and WidenForPBLH().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fill_wind_10m() [1/2]

void near_surface_diagnostics::fill_wind_10m ( amrex::MultiFab &  dst,
int  u_comp,
int  v_comp,
int  u_east_comp,
int  v_north_comp,
const WindSources &  sources,
amrex::Real  missing_value = amrex::Real(-999.0) 
)

◆ fill_wind_10m() [2/2]

void near_surface_diagnostics::fill_wind_10m ( MultiFab &  dst,
int  u_comp,
int  v_comp,
int  u_east_comp,
int  v_north_comp,
const WindSources &  sources,
Real  missing_value 
)
233 {
234  if (u_comp < 0 && v_comp < 0 && u_east_comp < 0 && v_north_comp < 0) { return; }
235 
236  const bool have_surface_layer = sources.u_star && sources.roughness_height &&
237  sources.obukhov_length && sources.xvel && sources.yvel;
238  const bool have_rotation = sources.cos_alpha && sources.sin_alpha;
239  const bool have_current = sources.current_x && sources.current_y;
240  const int klo = sources.klo;
241 
242 #ifdef _OPENMP
243 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
244 #endif
245  for (MFIter mfi(dst, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
246  const Box& bx = mfi.tilebox();
247  const auto dst_arr = dst.array(mfi);
248 
249  const auto ustar = array_or_empty(sources.u_star, mfi);
250  const auto z0 = array_or_empty(sources.roughness_height, mfi);
251  const auto olen = array_or_empty(sources.obukhov_length, mfi);
252  const auto u = array_or_empty(sources.xvel, mfi);
253  const auto v = array_or_empty(sources.yvel, mfi);
254  const auto cu = array_or_empty(sources.current_x, mfi);
255  const auto cv = array_or_empty(sources.current_y, mfi);
256  const auto cosa = array_or_empty(sources.cos_alpha, mfi);
257  const auto sina = array_or_empty(sources.sin_alpha, mfi);
258  const similarity_funs sfuns = sources.sfuns;
259 
260  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
261  Real u10 = missing_value;
262  Real v10 = missing_value;
263  Real factor = zero;
264  if (have_surface_layer &&
265  valid_real(ustar(i,j,0)) && ustar(i,j,0) >= zero &&
266  evaluate_most_momentum_factor(z0(i,j,0), olen(i,j,0), wind_height, factor, sfuns)) {
267  const Real speed = ustar(i,j,0) / KAPPA * factor;
268  // The direction of the wind at the center of the first cell, relative to
269  // the surface, and the current that is added back
270  Real u_cc, v_cc, current_u = zero, current_v = zero;
271  if (have_current) {
272  u_cc = myhalf * ((u(i,j,klo) - cu(i,j,klo)) + (u(i+1,j,klo) - cu(i+1,j,klo)));
273  v_cc = myhalf * ((v(i,j,klo) - cv(i,j,klo)) + (v(i,j+1,klo) - cv(i,j+1,klo)));
274  current_u = myhalf * (cu(i,j,klo) + cu(i+1,j,klo));
275  current_v = myhalf * (cv(i,j,klo) + cv(i,j+1,klo));
276  } else {
277  u_cc = myhalf * (u(i,j,klo) + u(i+1,j,klo));
278  v_cc = myhalf * (v(i,j,klo) + v(i,j+1,klo));
279  }
280  const Real speed_cc = std::sqrt(u_cc*u_cc + v_cc*v_cc);
281  if (valid_real(speed) && speed >= zero && valid_real(speed_cc)) {
282  u10 = current_u + ((speed_cc > zero) ? speed * u_cc / speed_cc : zero);
283  v10 = current_v + ((speed_cc > zero) ? speed * v_cc / speed_cc : zero);
284  }
285  }
286 
287  if (u_comp >= 0) { dst_arr(i,j,k,u_comp) = u10; }
288  if (v_comp >= 0) { dst_arr(i,j,k,v_comp) = v10; }
289  if (u_east_comp >= 0 || v_north_comp >= 0) {
290  Real u_east = u10;
291  Real v_north = v10;
292  // Without a grid orientation the grid is taken to be aligned with east
293  if (u10 != missing_value && have_rotation) {
294  erf_earth_wind::grid_to_earth(u10, v10, cosa(i,j,0), sina(i,j,0), u_east, v_north);
295  }
296  if (u_east_comp >= 0) { dst_arr(i,j,k,u_east_comp) = u_east; }
297  if (v_north_comp >= 0) { dst_arr(i,j,k,v_north_comp) = v_north; }
298  }
299  });
300  }
301 }
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
@ ustar
Definition: ERF_SLM.H:30
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void grid_to_earth(amrex::Real u, amrex::Real v, amrex::Real cos_alpha, amrex::Real sin_alpha, amrex::Real &u_east, amrex::Real &v_north) noexcept
Definition: ERF_EarthRelativeWind.H:29
real(c_double), parameter cv
Definition: ERF_module_model_constants.F90:25
constexpr amrex::Real wind_height
Definition: ERF_NearSurfaceDiagnostics.H:293
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool evaluate_most_momentum_factor(amrex::Real roughness_height, amrex::Real obukhov_length, amrex::Real height, amrex::Real &factor, const similarity_funs &sfuns) noexcept
Definition: ERF_NearSurfaceDiagnostics.H:186

Referenced by ERF::FillPlot2DVars().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ most_profile_zeta_max()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real near_surface_diagnostics::most_profile_zeta_max ( const similarity_funs &  sfuns)
noexcept
156 {
157  const amrex::Real zlim = most_zeta_lim; // by value: no reference to a namespace constant in device code
158  return sfuns.uses_qnse() ? zlim : amrex::Real(1.0);
159 }
constexpr amrex::Real most_zeta_lim
Definition: ERF_MOSTUtils.H:71
AMREX_GPU_HOST_DEVICE bool uses_qnse() const
Definition: ERF_MOSTUtils.H:334

Referenced by evaluate_most_factor(), and evaluate_most_momentum_factor().

Here is the caller graph for this function:

◆ native_bare_tile_is_used()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool near_surface_diagnostics::native_bare_tile_is_used ( amrex::Real  vegetation_fraction)
noexcept
90 {
91  return vegetation_fraction < amrex::Real(1.0);
92 }

Referenced by aggregate_native_bundle(), native_bundle_mixing_ratio_is_valid(), and native_bundle_temperature_is_valid().

Here is the caller graph for this function:

◆ native_bundle_is_valid()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool near_surface_diagnostics::native_bundle_is_valid ( const NativeBundle &  bundle)
noexcept
72 {
73  return native_bundle_temperature_is_valid(bundle) &&
76 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool native_bundle_vegetation_fraction_is_valid(const NativeBundle &bundle) noexcept
Definition: ERF_NearSurfaceDiagnostics.H:123
Here is the call graph for this function:

◆ native_bundle_mixing_ratio_is_valid()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool near_surface_diagnostics::native_bundle_mixing_ratio_is_valid ( const NativeBundle &  bundle)
noexcept
110 {
111  if (!native_bundle_vegetation_fraction_is_valid(bundle)) { return false; }
112  const amrex::Real f = bundle.vegetation_fraction;
113  const bool vegetated_ok = !native_vegetated_tile_is_used(f) ||
114  (valid_noahmp_component(bundle.mixing_ratio_vegetated) &&
115  bundle.mixing_ratio_vegetated >= amrex::Real(0.0));
116  const bool bare_ok = !native_bare_tile_is_used(f) ||
117  (valid_noahmp_component(bundle.mixing_ratio_bare) &&
118  bundle.mixing_ratio_bare >= amrex::Real(0.0));
119  return vegetated_ok && bare_ok;
120 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool valid_noahmp_component(amrex::Real value) noexcept
Definition: ERF_NearSurfaceDiagnostics.H:55

Referenced by fill(), and native_bundle_is_valid().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ native_bundle_temperature_is_valid()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool near_surface_diagnostics::native_bundle_temperature_is_valid ( const NativeBundle &  bundle)
noexcept
96 {
97  if (!native_bundle_vegetation_fraction_is_valid(bundle)) { return false; }
98  const amrex::Real f = bundle.vegetation_fraction;
99  const bool vegetated_ok = !native_vegetated_tile_is_used(f) ||
100  (valid_noahmp_component(bundle.temperature_vegetated) &&
101  bundle.temperature_vegetated > amrex::Real(0.0));
102  const bool bare_ok = !native_bare_tile_is_used(f) ||
103  (valid_noahmp_component(bundle.temperature_bare) &&
104  bundle.temperature_bare > amrex::Real(0.0));
105  return vegetated_ok && bare_ok;
106 }

Referenced by fill(), and native_bundle_is_valid().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ native_bundle_vegetation_fraction_is_valid()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool near_surface_diagnostics::native_bundle_vegetation_fraction_is_valid ( const NativeBundle &  bundle)
noexcept
124 {
125  return valid_noahmp_component(bundle.vegetation_fraction) &&
126  bundle.vegetation_fraction >= amrex::Real(0.0) &&
127  bundle.vegetation_fraction <= amrex::Real(1.0);
128 }

Referenced by native_bundle_is_valid(), native_bundle_mixing_ratio_is_valid(), and native_bundle_temperature_is_valid().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ native_vegetated_tile_is_used()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool near_surface_diagnostics::native_vegetated_tile_is_used ( amrex::Real  vegetation_fraction)
noexcept
84 {
85  return vegetation_fraction > amrex::Real(0.0);
86 }

Referenced by aggregate_native_bundle(), native_bundle_mixing_ratio_is_valid(), and native_bundle_temperature_is_valid().

Here is the caller graph for this function:

◆ valid_noahmp_component()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool near_surface_diagnostics::valid_noahmp_component ( amrex::Real  value)
noexcept
56 {
57  return valid_real(value) && value > amrex::Real(-9990.0) &&
58  value < amrex::Real(0.5) * lsm_undefined;
59 }
constexpr amrex::Real lsm_undefined
Definition: ERF_Constants.H:28

Referenced by native_bundle_mixing_ratio_is_valid(), native_bundle_temperature_is_valid(), and native_bundle_vegetation_fraction_is_valid().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ valid_real()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool near_surface_diagnostics::valid_real ( amrex::Real  value)
noexcept
50 {
51  return amrex::Math::isfinite(value);
52 }

Referenced by evaluate_most_factor(), evaluate_most_momentum_factor(), evaluate_most_profile(), fill(), fill_wind_10m(), and valid_noahmp_component().

Here is the caller graph for this function:

Variable Documentation

◆ wind_height

constexpr amrex::Real near_surface_diagnostics::wind_height = amrex::Real(10.0)
constexpr

Referenced by fill_wind_10m().