Skip to content

Commit

Permalink
rename the tend and use init_timestep
Browse files Browse the repository at this point in the history
  • Loading branch information
mahf708 committed Jul 1, 2024
1 parent 5025176 commit 5ecca36
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 78 deletions.
2 changes: 1 addition & 1 deletion components/eamxx/src/diagnostics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ set(DIAGNOSTIC_SRCS
aodvis.cpp
number_path.cpp
aerocom_cld.cpp
atm_tend.cpp
atm_backtend.cpp
)

add_library(diagnostics ${DIAGNOSTIC_SRCS})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
#include "diagnostics/atm_tend.hpp"
#include "diagnostics/atm_backtend.hpp"

#include <ekat/kokkos/ekat_kokkos_utils.hpp>

#include "share/util/scream_universal_constants.hpp"

namespace scream {

AtmTendDiag::AtmTendDiag(const ekat::Comm &comm,
const ekat::ParameterList &params)
AtmBackTendDiag::AtmBackTendDiag(const ekat::Comm &comm,
const ekat::ParameterList &params)
: AtmosphereDiagnostic(comm, params) {
EKAT_REQUIRE_MSG(params.isParameter("Field Name"),
"Error! AtmTendDiag requires 'Field Name' in its "
EKAT_REQUIRE_MSG(params.isParameter("Tendency Name"),
"Error! AtmBackTendDiag requires 'Tendency Name' in its "
"input parameters.\n");

m_name = m_params.get<std::string>("Field Name");
m_name = m_params.get<std::string>("Tendency Name");
}

std::string AtmTendDiag::name() const { return m_name + "_atm_tend"; }
std::string AtmBackTendDiag::name() const { return m_name + "_atm_tend"; }

void AtmTendDiag::set_grids(
void AtmBackTendDiag::set_grids(
const std::shared_ptr<const GridsManager> grids_manager) {
using namespace ekat::units;

const auto &gname = m_params.get<std::string>("grid_name");
add_field<Required>(m_name, gname);
}

void AtmTendDiag::initialize_impl(const RunType /*run_type*/) {
void AtmBackTendDiag::initialize_impl(const RunType /*run_type*/) {
const auto &f = get_field_in(m_name);
const auto &fid = f.get_header().get_identifier();
const auto &gn = fid.get_grid_name();

// Sanity checks
using namespace ShortFieldTagsNames;
const auto &layout = fid.get_layout();
EKAT_REQUIRE_MSG(f.data_type() == DataType::RealType,
"Error! AtmTendDiag only supports Real data type field.\n"
" - field name: " +
fid.name() +
"\n"
" - field data type: " +
e2str(f.data_type()) + "\n");
EKAT_REQUIRE_MSG(
f.data_type() == DataType::RealType,
"Error! AtmBackTendDiag only supports Real data type field.\n"
" - field name: " +
fid.name() +
"\n"
" - field data type: " +
e2str(f.data_type()) + "\n");

using namespace ekat::units;
// The units are the same except per second
Expand All @@ -57,7 +58,14 @@ void AtmTendDiag::initialize_impl(const RunType /*run_type*/) {
m_f_prev = Field(prev_fid);
m_f_prev.allocate_view();
}
void AtmTendDiag::compute_diagnostic_impl() {

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

void AtmBackTendDiag::compute_diagnostic_impl() {
Real var_fill_value = constants::DefaultFillValue<Real>().value;
std::int64_t dt;

Expand Down
53 changes: 53 additions & 0 deletions components/eamxx/src/diagnostics/atm_backtend.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#ifndef EAMXX_ATM_BACKTEND_DIAG_HPP
#define EAMXX_ATM_BACKTEND_DIAG_HPP

#include "share/atm_process/atmosphere_diagnostic.hpp"
#include "share/util/scream_time_stamp.hpp"

namespace scream {

/*
* This diagnostic will back out the atmosphere tendency of a given field.
*/

class AtmBackTendDiag : public AtmosphereDiagnostic {
public:
// Constructors
AtmBackTendDiag(const ekat::Comm &comm, const ekat::ParameterList &params);

// The name of the diagnostic
std::string name() const;

// Set the grid
void set_grids(const std::shared_ptr<const GridsManager> grids_manager);

protected:
#ifdef KOKKOS_ENABLE_CUDA
public:
#endif
void compute_diagnostic_impl();

// Let's override the init time step method
void init_timestep(const util::TimeStamp &start_of_step) override;

// Let's override the initialize method to set the fields below
void initialize_impl(const RunType /*run_type*/) override;

// Keep track of field dimensions
int m_num_cols;
int m_num_levs;

// The tendency of what?
std::string m_name;

// 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

#endif // EAMXX_ATM_BACKTEND_DIAG_HPP
47 changes: 0 additions & 47 deletions components/eamxx/src/diagnostics/atm_tend.hpp

This file was deleted.

4 changes: 2 additions & 2 deletions components/eamxx/src/diagnostics/register_diagnostics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "diagnostics/aodvis.hpp"
#include "diagnostics/number_path.hpp"
#include "diagnostics/aerocom_cld.hpp"
#include "diagnostics/atm_tend.hpp"
#include "diagnostics/atm_backtend.hpp"

namespace scream {

Expand Down Expand Up @@ -54,7 +54,7 @@ inline void register_diagnostics () {
diag_factory.register_product("AerosolOpticalDepth550nm",&create_atmosphere_diagnostic<AODVis>);
diag_factory.register_product("NumberPath",&create_atmosphere_diagnostic<NumberPathDiagnostic>);
diag_factory.register_product("AeroComCld",&create_atmosphere_diagnostic<AeroComCld>);
diag_factory.register_product("AtmTendDiag",&create_atmosphere_diagnostic<AtmTendDiag>);
diag_factory.register_product("AtmBackTendDiag",&create_atmosphere_diagnostic<AtmBackTendDiag>);
}

} // namespace scream
Expand Down
2 changes: 1 addition & 1 deletion components/eamxx/src/diagnostics/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ if (NOT SCREAM_ONLY_GENERATE_BASELINES)
CreateDiagTest(aerocom_cld "aerocom_cld_test.cpp")

# Test atm_tend
CreateDiagTest(atm_tend "atm_tend_test.cpp")
CreateDiagTest(atm_backtend "atm_backtend_test.cpp")

endif()
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ std::shared_ptr<GridsManager> create_gm(const ekat::Comm &comm, const int ncols,
return gm;
}

TEST_CASE("atm_tend") {
TEST_CASE("atm_backtend") {
using namespace ShortFieldTagsNames;
using namespace ekat::units;

Expand All @@ -37,8 +37,8 @@ TEST_CASE("atm_tend") {
util::TimeStamp t0({2024, 1, 1}, {0, 0, 0});

// Create a grids manager - single column for these tests
constexpr int nlevs = 25;
const int ngcols = 25 * comm.size();
constexpr int nlevs = 7;
const int ngcols = 2 * comm.size();

auto gm = create_gm(comm, ngcols, nlevs);
auto grid = gm->get_grid("Physics");
Expand All @@ -62,8 +62,8 @@ TEST_CASE("atm_tend") {
register_diagnostics();

ekat::ParameterList params;
REQUIRE_THROWS(
diag_factory.create("AtmTendDiag", comm, params)); // No 'Field Name'
REQUIRE_THROWS(diag_factory.create("AtmBackTendDiag", comm,
params)); // No 'Tendency Name'

Real var_fill_value = constants::DefaultFillValue<Real>().value;

Expand All @@ -73,8 +73,8 @@ TEST_CASE("atm_tend") {

// Create and set up the diagnostic
params.set("grid_name", grid->name());
params.set<std::string>("Field Name", "qc");
auto diag = diag_factory.create("AtmTendDiag", comm, params);
params.set<std::string>("Tendency Name", "qc");
auto diag = diag_factory.create("AtmBackTendDiag", comm, params);
diag->set_grids(gm);
diag->set_required_field(qc);
diag->initialize(t0, RunType::Initial);
Expand Down
6 changes: 3 additions & 3 deletions components/eamxx/src/share/io/scorpio_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1377,13 +1377,13 @@ AtmosphereOutput::create_diagnostic (const std::string& diag_field_name) {
diag_name = "VaporFlux";
// split will return the list [X, ''], with X being whatever is before 'VapFlux'
params.set<std::string>("Wind Component",ekat::split(diag_field_name,"VapFlux").front());
} else if (diag_field_name.find("_atm_tend")!=std::string::npos) {
diag_name = "AtmTendDiag";
} else if (diag_field_name.find("_atm_backtend")!=std::string::npos) {
diag_name = "AtmBackTendDiag";
// TODO: not sure if this is needed? Can skip, but what to do inside diag?
// Set the grid_name
params.set("grid_name",get_field_manager("sim")->get_grid()->name());
// split will return [X, ''], with X being whatever is before '_atm_tend'
params.set<std::string>("Tend Name",ekat::split(diag_field_name,"_atm_tend").front());
params.set<std::string>("Tendency Name",ekat::split(diag_field_name,"_atm_backtend").front());
} else if (diag_field_name=="PotentialTemperature" or
diag_field_name=="LiqPotentialTemperature") {
diag_name = "PotentialTemperature";
Expand Down

0 comments on commit 5ecca36

Please sign in to comment.