Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions components/eamxx/src/dynamics/homme/homme_grids_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "share/remap/inverse_remapper.hpp"
#include "share/grid/se_grid.hpp"
#include "share/io/scorpio_input.hpp"
#include "share/physics/physics_constants.hpp"

// Get all Homme's compile-time dims and constants
#include "PhysicalConstants.hpp"
Expand Down Expand Up @@ -197,7 +198,8 @@ void HommeGridsManager::build_dynamics_grid () {
}

void HommeGridsManager::
build_physics_grid (const ci_string& type, const ci_string& rebalance) {
build_physics_grid (const ci_string& type, const ci_string& rebalance)
{
std::string name = "physics_" + type;
if (rebalance != "none") {
name += " " + rebalance;
Expand Down Expand Up @@ -275,16 +277,25 @@ build_physics_grid (const ci_string& type, const ci_string& rebalance) {
auto hybm = phys_grid->create_geometry_data("hybm",layout_mid,none);
auto lev = phys_grid->create_geometry_data("lev", layout_mid,mbar);
auto ilev = phys_grid->create_geometry_data("ilev",layout_int,mbar);
auto P0 = phys_grid->create_geometry_data("P0", FieldLayout::scalar(), Pa);
const auto p0_val = physics::Constants<Real>::P0.value;
P0.deep_copy(p0_val);

for (auto f : {hyai, hybi, hyam, hybm}) {
auto f_d = get_grid("dynamics")->get_geometry_data(f.name());
f.deep_copy(f_d);
f.sync_to_host();
}


using stratts_t = std::map<std::string,std::string>;
auto& lev_io_atts = lev.get_header().get_extra_data<stratts_t>("io: string attributes");
auto& ilev_io_atts = ilev.get_header().get_extra_data<stratts_t>("io: string attributes");
lev_io_atts["formula_terms"] = "a: hyam b: hybm p0: P0 ps: ps" ;
ilev_io_atts["formula_terms"] = "a: hyai b: hybi p0: P0 ps: ps" ;
lev_io_atts["positive"] = "down";
ilev_io_atts["positive"] = "down";

// Build lev from hyam and hybm
const Real ps0 = 100000.0;

auto hyam_v = hyam.get_view<const Real*,Host>();
auto hybm_v = hybm.get_view<const Real*,Host>();
auto hyai_v = hyai.get_view<const Real*,Host>();
Expand All @@ -293,10 +304,10 @@ build_physics_grid (const ci_string& type, const ci_string& rebalance) {
auto ilev_v = ilev.get_view<Real*,Host>();
auto num_v_levs = phys_grid->get_num_vertical_levels();
for (int ii=0;ii<num_v_levs;ii++) {
lev_v(ii) = 0.01*ps0*(hyam_v(ii)+hybm_v(ii));
ilev_v(ii) = 0.01*ps0*(hyai_v(ii)+hybi_v(ii));
lev_v(ii) = 0.01*p0_val*(hyam_v(ii)+hybm_v(ii));
ilev_v(ii) = 0.01*p0_val*(hyai_v(ii)+hybi_v(ii));
}
ilev_v(num_v_levs) = 0.01*ps0*(hyai_v(num_v_levs)+hybi_v(num_v_levs));
ilev_v(num_v_levs) = 0.01*p0_val*(hyai_v(num_v_levs)+hybi_v(num_v_levs));
lev.sync_to_dev();
ilev.sync_to_dev();
}
Expand Down
Comment thread
bartgol marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,16 @@ build_point_grid (const std::string& name, ekat::ParameterList& params)
void MeshFreeGridsManager::
add_geo_data (const nonconstgrid_ptr_type& grid) const
{
using namespace ShortFieldTagsNames;
using namespace ekat::units;

if (!m_params.isParameter("geo_data_source")) {
return;
}

// Load geo data fields if geo data filename is present, and file contains them
const auto& geo_data_source = m_params.get<std::string>("geo_data_source");
if (geo_data_source=="CREATE_EMPTY_DATA") {
using namespace ShortFieldTagsNames;
using namespace ekat::units;

auto layout_mid = grid->get_vertical_layout(LEV);
auto layout_int = grid->get_vertical_layout(ILEV);

Expand All @@ -162,6 +162,14 @@ add_geo_data (const nonconstgrid_ptr_type& grid) const
auto lev = grid->create_geometry_data("lev" , layout_mid, mbar);
auto ilev = grid->create_geometry_data("ilev" , layout_int, mbar);

using stratts_t = std::map<std::string,std::string>;
auto& lev_io_atts = lev.get_header().get_extra_data<stratts_t>("io: string attributes");
auto& ilev_io_atts = ilev.get_header().get_extra_data<stratts_t>("io: string attributes");
lev_io_atts["formula_terms"] = "a: hyam b: hybm p0: P0 ps: ps" ;
ilev_io_atts["formula_terms"] = "a: hyai b: hybi p0: P0 ps: ps" ;
lev_io_atts["positive"] = "down";
ilev_io_atts["positive"] = "down";

const auto invalid = ekat::invalid<Real>();
lat.deep_copy(invalid);;
lon.deep_copy(invalid);
Expand Down Expand Up @@ -189,6 +197,12 @@ add_geo_data (const nonconstgrid_ptr_type& grid) const
load_vertical_coordinates(grid,filename);
}
}

// This is to ensure output streams will save P0 among the geo data.
// NOTE: MeshFreeGridsManager is mostly for unit tests, so this is somewhat moot,
// but it helps to have consistent treatment of geo data across GM's
auto P0 = grid->create_geometry_data("P0", FieldLayout::scalar(), Pa);
Comment thread
bartgol marked this conversation as resolved.
P0.deep_copy(physics::Constants<Real>::P0.value);
Comment thread
bartgol marked this conversation as resolved.
}

void MeshFreeGridsManager::
Expand Down Expand Up @@ -268,6 +282,14 @@ load_vertical_coordinates (const nonconstgrid_ptr_type& grid, const std::string&
scorpio::read_var(filename,"ilev",ilev_v.data());
scorpio::release_file(filename);

using stratts_t = std::map<std::string,std::string>;
auto& lev_io_atts = lev.get_header().get_extra_data<stratts_t>("io: string attributes");
auto& ilev_io_atts = ilev.get_header().get_extra_data<stratts_t>("io: string attributes");
lev_io_atts["formula_terms"] = "a: hyam b: hybm p0: P0 ps: ps" ;
ilev_io_atts["formula_terms"] = "a: hyai b: hybi p0: P0 ps: ps" ;
lev_io_atts["positive"] = "down";
ilev_io_atts["positive"] = "down";

// Build lev and ilev from hyam and hybm, and ilev from hyai and hybi
using PC = scream::physics::Constants<Real>;
const Real ps0 = PC::P0.value;
Expand Down
3 changes: 3 additions & 0 deletions components/eamxx/src/share/field/field_layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ class FieldLayout {
// Create invalid layout
static FieldLayout invalid () { return FieldLayout({FieldTag::Invalid},{0}); }

// Create scalar layout
static FieldLayout scalar () { return FieldLayout({},{}); }

// ----- Getters ----- //

LayoutType type () const { return m_type; }
Expand Down
5 changes: 3 additions & 2 deletions components/eamxx/src/share/util/io_metadata/io_metadata.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
variable,standard_name,long_name
lev,,hybrid level at midpoints (1000*(A+B))
ilev,,hybrid level at interfaces (1000*(A+B))
lev,atmosphere_hybrid_sigma_pressure_coordinate,hybrid level at midpoints (1000*(A+B))
ilev,atmosphere_hybrid_sigma_pressure_coordinate,hybrid level at interfaces (1000*(A+B))
P0,,reference pressure
hyai,,hybrid A coefficient at layer interfaces
hybi,,hybrid B coefficient at layer interfaces
hyam,,hybrid A coefficient at layer midpoints
Expand Down
Loading