Skip to content

Commit

Permalink
better reorganization of logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mahf708 committed Jul 2, 2024
1 parent 86586bf commit 613a260
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
4 changes: 1 addition & 3 deletions components/eamxx/src/diagnostics/atm_backtend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ void AtmBackTendDiag::initialize_impl(const RunType /*run_type*/) {
}

void AtmBackTendDiag::init_timestep(const util::TimeStamp &start_of_step) {
m_start_t = start_of_step;
const auto &f_curr = get_field_in(m_name);
m_f_prev.deep_copy(f_curr);
m_f_prev.get_header().get_tracking().update_time_stamp(start_of_step);
}

void AtmBackTendDiag::compute_diagnostic_impl() {
Expand All @@ -83,8 +83,6 @@ void AtmBackTendDiag::compute_diagnostic_impl() {
// yet, so fill with an invalid value
m_diagnostic_output.deep_copy(var_fill_value);
}
m_f_prev.deep_copy(f);
m_f_prev.get_header().get_tracking().update_time_stamp(curr_ts);
}

} // namespace scream
3 changes: 0 additions & 3 deletions components/eamxx/src/diagnostics/atm_backtend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ class AtmBackTendDiag : public AtmosphereDiagnostic {
// Store the previous field
Field m_f_prev;

// Store the timestamp of the start of the timestep
util::TimeStamp m_start_t;

}; // class AtmBackTendDiag

} // namespace scream
Expand Down
33 changes: 20 additions & 13 deletions components/eamxx/src/diagnostics/tests/atm_backtend_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ TEST_CASE("atm_backtend") {
auto gm = create_gm(comm, ngcols, nlevs);
auto grid = gm->get_grid("Physics");

// Input (randomized) qc, nc
// Input (randomized) qc
FieldLayout scalar2d_layout{{COL, LEV}, {ngcols, nlevs}};
FieldIdentifier qc_fid("qc", scalar2d_layout, kg / kg, grid->name());

Expand Down Expand Up @@ -88,21 +88,28 @@ TEST_CASE("atm_backtend") {
some_field.deep_copy(var_fill_value);
REQUIRE(views_are_equal(diag_f, some_field));

some_field.deep_copy(qc);
const Real a_day = 24.0 * 60.0 * 60.0; // seconds

util::TimeStamp t1({2024, 1, 2}, {0, 0, 0}); // a day later
const Real a_day = 24.0 * 60.0 * 60.0; // seconds
qc.get_header().get_tracking().update_time_stamp(t1);
randomize(qc, engine, pdf);
constexpr int ntests = 10;

// Run diag again
diag->compute_diagnostic();
some_field.update(qc, 1.0 / a_day, -1.0 / a_day);
REQUIRE(views_are_equal(diag_f, some_field));
for(int itest = 2; itest < ntests; ++itest) {
// Run diag again

some_field.deep_copy(qc);

diag->init_timestep(t0);

util::TimeStamp t1({2024, 1, itest}, {0, 0, 0}); // a day later
qc.get_header().get_tracking().update_time_stamp(t1);
randomize(qc, engine, pdf);

diag->compute_diagnostic();
some_field.update(qc, 1.0 / a_day, -1.0 / a_day);
REQUIRE(views_are_equal(diag_f, some_field));

// This should fail (return false):
some_field.update(qc, 1.0 / a_day, -1.0 / a_day);
REQUIRE_FALSE(views_are_equal(diag_f, some_field));
// reset t0 to t1 to keep iterating...
t0 = t1;
}
}

} // namespace scream

0 comments on commit 613a260

Please sign in to comment.