46 if (
q.boxArray() != file_moisture.boxArray() ||
47 q.DistributionMap() != file_moisture.DistributionMap()) {
48 Abort(
"seb_init_soil_moisture_from_file: the file's soil moisture is not on the grids "
49 "of the balance's soil water");
51 const int nlayers =
static_cast<int>(weights.size());
52 if (nlayers < 1 || nlayers != file_moisture.nComp()) {
53 Abort(
"seb_init_soil_moisture_from_file: " + std::to_string(nlayers) +
54 " layer weight(s) for a soil moisture field of " +
55 std::to_string(file_moisture.nComp()) +
" layer(s)");
60 Gpu::DeviceVector<Real> weights_d(nlayers);
61 Gpu::copy(Gpu::hostToDevice, weights.begin(), weights.end(), weights_d.begin());
62 const Real* w = weights_d.data();
66 ReduceOps<ReduceOpSum, ReduceOpSum, ReduceOpMin, ReduceOpMax, ReduceOpMax> reduce_op;
67 ReduceData<Long, Long, Real, Real, Real> reduce_data(reduce_op);
68 using ReduceTuple =
typename decltype(reduce_data)::Type;
69 const Real huge = std::numeric_limits<Real>::max();
74 for (MFIter mfi(
q, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
75 const Box& bx = mfi.tilebox();
76 const Array4<Real>& dst =
q.array(mfi);
77 const Array4<const Real>& file = file_moisture.const_array(mfi);
79 reduce_op.eval(bx, reduce_data,
80 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept -> ReduceTuple
82 if (mask.
water(i, j)) { return {Long(0), Long(0), huge, -huge, -huge}; }
83 Real mean = Real(0.0);
86 for (
int n = 0; n < nlayers; ++n) {
88 if (w[n] > Real(0.0)) {
89 const Real value = file(i, j, k, n);
91 lowest = amrex::min(lowest, value);
92 highest = amrex::max(highest, value);
95 if (!amrex::Math::isfinite(mean)) {
return {Long(0), Long(1), huge, -huge, -huge}; }
100 mean = amrex::min(amrex::max(mean, lowest), highest);
101 if (mean < q_lo_ok || mean > q_hi_ok) {
return {Long(0), Long(1), huge, -huge, mean}; }
103 mean = amrex::min(amrex::max(mean, q_lo), q_hi);
105 return {Long(1), Long(0), mean, mean, -huge};
110 const ReduceTuple result = reduce_data.value(reduce_op);
112 report.
n_set = amrex::get<0>(result);
113 report.
n_refused = amrex::get<1>(result);
114 report.
q_min = amrex::get<2>(result);
115 report.
q_max = amrex::get<3>(result);
SEBLandMaskView seb_land_mask_view(const amrex::iMultiFab *mask, const amrex::MFIter &mfi)
The view of mask on the box of mfi; off when mask is nullptr.
Definition: ERF_SEBLandMask.H:54
void seb_assert_land_mask_layout(const amrex::iMultiFab *mask, const amrex::FabArrayBase &field, const char *who)
Stop when mask is given and is not on the grids of field.
Definition: ERF_SEBLandMask.H:43
constexpr amrex::Real seb_soil_value_rel_tol
Relative distance outside [q_lo, q_hi] at which seb_init_soil_moisture_from_file still takes a mean,...
Definition: ERF_SEBSoilInit.H:51
@ q
Definition: ERF_WSM6.H:296
The land mask of one box, for a device kernel. Captured by value.
Definition: ERF_SEBLandMask.H:29
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool water(int i, int j) const noexcept
True when the balance does not run on column (i, j).
Definition: ERF_SEBLandMask.H:35
What seb_init_soil_moisture_from_file did on the boxes of this rank.
Definition: ERF_SEBSoilInit.H:76
amrex::Real q_min
lowest value set [m^3/m^3]; meaningful when n_set > 0
Definition: ERF_SEBSoilInit.H:79
amrex::Real q_refused_max
highest finite refused mean; the lowest Real when no refused mean is finite
Definition: ERF_SEBSoilInit.H:82
amrex::Long n_refused
land columns whose mean is not usable (left as they were)
Definition: ERF_SEBSoilInit.H:78
amrex::Long n_set
land columns that took the file's mean
Definition: ERF_SEBSoilInit.H:77
amrex::Real q_max
Definition: ERF_SEBSoilInit.H:80