Skip to content

Commit 982878e

Browse files
authored
Merge branch 'bartgol/eamxx/fix-fill-val-def' (PR #7557)
Changes: - For floating point numbers, ensure it is ALWAYS the same number. - Switch to an inline templated constexpr variable. - Test behavior of fill_aware_combine - Test behavior of field ops with a fill-value RHS [non-BFB for certain EAMxx outputs]
2 parents e251a8c + a6539e5 commit 982878e

21 files changed

+206
-86
lines changed

components/eamxx/src/diagnostics/aodvis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void AODVis::initialize_impl(const RunType /*run_type*/) {
4747
auto nondim = ekat::units::Units::nondimensional();
4848
const auto &grid_name =
4949
m_diagnostic_output.get_header().get_identifier().get_grid_name();
50-
const auto var_fill_value = constants::DefaultFillValue<Real>().value;
50+
const auto var_fill_value = constants::fill_value<Real>;
5151

5252
m_mask_val = m_params.get<double>("mask_value", var_fill_value);
5353

components/eamxx/src/diagnostics/atm_backtend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void AtmBackTendDiag::init_timestep(const util::TimeStamp &start_of_step) {
6363
}
6464

6565
void AtmBackTendDiag::compute_diagnostic_impl() {
66-
Real var_fill_value = constants::DefaultFillValue<Real>().value;
66+
Real var_fill_value = constants::fill_value<Real>;
6767
std::int64_t dt;
6868

6969
const auto &f = get_field_in(m_name);

components/eamxx/src/diagnostics/field_at_pressure_level.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ initialize_impl (const RunType /*run_type*/)
8585
// Add a field representing the mask as extra data to the diagnostic field.
8686
auto nondim = ekat::units::Units::nondimensional();
8787
const auto& gname = fid.get_grid_name();
88-
m_mask_val = m_params.get<double>("mask_value",Real(constants::DefaultFillValue<float>::value));
88+
m_mask_val = m_params.get<double>("mask_value",Real(constants::fill_value<double>));
8989

9090

9191
std::string mask_name = m_diag_name + " mask";

components/eamxx/src/diagnostics/tests/aodvis_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ TEST_CASE("aodvis") {
3131
using namespace ShortFieldTagsNames;
3232
using namespace ekat::units;
3333

34-
Real var_fill_value = constants::DefaultFillValue<Real>().value;
34+
Real var_fill_value = constants::fill_value<Real>;
3535

3636
Real some_limit = 0.0025;
3737

components/eamxx/src/diagnostics/tests/atm_backtend_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ TEST_CASE("atm_backtend") {
6565
REQUIRE_THROWS(diag_factory.create("AtmBackTendDiag", comm,
6666
params)); // No 'tendency_name'
6767

68-
Real var_fill_value = constants::DefaultFillValue<Real>().value;
68+
Real var_fill_value = constants::fill_value<Real>;
6969

7070
// Set time for qc and randomize its values
7171
qc.get_header().get_tracking().update_time_stamp(t0);

components/eamxx/src/physics/nudging/eamxx_nudging_process_interface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ void Nudging::run_impl (const double dt)
344344
const auto fl = f.get_header().get_identifier().get_layout();
345345
const auto v = f.get_view<Real**>();
346346

347-
Real var_fill_value = constants::DefaultFillValue<Real>().value;
347+
Real var_fill_value = constants::fill_value<Real>;
348348
// Query the helper field for the fill value, if not present use default
349349
if (f.get_header().has_extra_data("mask_value")) {
350350
var_fill_value = f.get_header().get_extra_data<Real>("mask_value");

components/eamxx/src/share/field/field_impl.hpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -559,9 +559,8 @@ update (const Field& x, const ST alpha, const ST beta)
559559
" - x layout: " + x_l.to_string() + "\n"
560560
" - y layout: " + y_l.to_string() + "\n");
561561

562-
// Determine if there is a FillValue that requires extra treatment.
563-
bool use_fill = get_header().has_extra_data("mask_value") or
564-
x.get_header().has_extra_data("mask_value");
562+
// Determine if the RHS has fill value entries that require extra treatment
563+
bool use_fill = x.get_header().has_extra_data("mask_value");
565564

566565
if (dt==DataType::IntType) {
567566
if (use_fill) {
@@ -609,18 +608,13 @@ update_impl (const Field& x, const ST alpha, const ST beta)
609608
const auto& layout = x.get_header().get_identifier().get_layout();
610609
const auto& dims = layout.dims();
611610

612-
ST fill_val = 0;
611+
XST fill_val = 0;
613612
if constexpr (use_fill) {
614-
if (get_header().has_extra_data("mask_value")) {
615-
fill_val = get_header().get_extra_data<ST>("mask_value");
616-
} else if (x.get_header().has_extra_data("mask_value")) {
617-
fill_val = static_cast<ST>(x.get_header().get_extra_data<XST>("mask_value"));
618-
} else {
619-
EKAT_ERROR_MSG ("Error! Field::update_impl called with use_fill,\n"
620-
" but neither *this nor x has mask_value extra data.\n"
621-
" - *this name: " + name() + "\n"
622-
" - x name: " + x.name() + "\n");
623-
}
613+
EKAT_REQUIRE_MSG (x.get_header().has_extra_data("mask_value"),
614+
"Error! Field::update_impl called with use_fill, but x does not have mask_value extra data.\n"
615+
" - *this name: " + name() + "\n"
616+
" - x name: " + x.name() + "\n");
617+
fill_val = x.get_header().get_extra_data<XST>("mask_value");
624618
}
625619

626620
// Must handle the case where one of the two views is strided (or both)

components/eamxx/src/share/field/field_impl_details.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ struct CombineViewsHelper {
114114
template<CombineMode CM, bool use_fill, typename LhsView, typename RhsView, typename ST>
115115
void
116116
cvh (LhsView lhs, RhsView rhs,
117-
ST alpha, ST beta, typename LhsView::traits::value_type fill_val,
117+
ST alpha, ST beta, typename RhsView::traits::value_type fill_val,
118118
const std::vector<int>& dims)
119119
{
120120
CombineViewsHelper <CM, use_fill, LhsView, RhsView, ST> helper;

components/eamxx/src/share/io/eamxx_scorpio_interface.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ int nctype () {
159159
} else {
160160
EKAT_ERROR_MSG ("Error! Unrecognized/unsupported data type.\n");
161161
}
162+
return PIO_NAT;
162163
}
163164

164165
template<typename T>

components/eamxx/src/share/io/scorpio_output.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ class AtmosphereOutput
219219
// NetCDF: Numeric conversion not representable
220220
// Also, by default, don't pick max float, to avoid any overflow if the value
221221
// is used inside other calculation and/or remap.
222-
float m_fill_value = constants::DefaultFillValue<float>().value;
222+
float m_fill_value = constants::fill_value<float>;
223223

224224
bool m_add_time_dim;
225225
bool m_track_avg_cnt = false;

0 commit comments

Comments
 (0)