Skip to content

Commit bf484c4

Browse files
committed
EAMxx: make the vertical derivative better
1 parent 7d9061c commit bf484c4

File tree

3 files changed

+13
-53
lines changed

3 files changed

+13
-53
lines changed

components/eamxx/mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ nav:
1919
- 'Overview': 'user/diags/index.md'
2020
- 'Field contraction diagnostics': 'user/diags/field_contraction.md'
2121
- 'Conditional sampling': 'user/diags/conditional_sampling.md'
22-
- 'Vertical divergence diagnostics': 'user/diags/vert_derivative.md'
22+
- 'Vertical derivative': 'user/diags/vert_derivative.md'
2323
- 'Presentations': 'user/presentations.md'
2424
- 'IO Aliases': 'user/io_aliases.md'
2525
- 'Developer Guide':

components/eamxx/src/diagnostics/vert_derivative.cpp

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,9 @@ void VertDerivativeDiag::set_grids(const std::shared_ptr<const GridsManager> gri
2828
m_diag_name = fn + "_" + m_derivative_method + "vert_derivative";
2929

3030
auto scalar3d = g->get_3d_scalar_layout(true);
31-
if (m_derivative_method == "p") {
32-
add_field<Required>("pseudo_density", scalar3d, Pa, gn);
33-
} else if (m_derivative_method == "z") {
34-
add_field<Required>("pseudo_density", scalar3d, Pa, gn);
35-
add_field<Required>("qv", scalar3d, kg / kg, gn);
36-
add_field<Required>("p_mid", scalar3d, Pa, gn);
37-
add_field<Required>("T_mid", scalar3d, K, gn);
31+
add_field<Required>("pseudo_density", scalar3d, Pa, gn);
32+
if (m_derivative_method == "z") {
33+
add_field<Required>("dz", scalar3d, m, gn);
3834
}
3935
}
4036

@@ -49,24 +45,16 @@ void VertDerivativeDiag::initialize_impl(const RunType /*run_type*/) {
4945
// TODO: support higher-dimensioned input fields
5046
EKAT_REQUIRE_MSG(layout.rank() >= 2 && layout.rank() <= 2,
5147
"Error! Field rank not supported by VertDerivativeDiag.\n"
52-
" - field name: " +
53-
fid.name() +
54-
"\n"
55-
" - field layout: " +
56-
layout.to_string() + "\n");
48+
" - field name: " + fid.name() + "\n"
49+
" - field layout: " + layout.to_string() + "\n");
5750
EKAT_REQUIRE_MSG(layout.tags().back() == LEV,
5851
"Error! VertDerivativeDiag diagnostic expects a layout ending "
5952
"with the 'LEV' tag.\n"
60-
" - field name : " +
61-
fid.name() +
62-
"\n"
63-
" - field layout: " +
64-
layout.to_string() + "\n");
53+
" - field name : " + fid.name() + "\n"
54+
" - field layout: " + layout.to_string() + "\n");
6555

6656
ekat::units::Units diag_units = fid.get_units();
6757

68-
m_denominator = get_field_in("pseudo_density").clone("denominator");
69-
7058
if (m_derivative_method == "p") {
7159
diag_units = fid.get_units() / Pa;
7260
} else if (m_derivative_method == "z") {
@@ -94,46 +82,20 @@ void VertDerivativeDiag::compute_diagnostic_impl() {
9482
using KT = KokkosTypes<DefaultDevice>;
9583
using MT = typename KT::MemberType;
9684
using TPF = ekat::TeamPolicyFactory<typename KT::ExeSpace>;
97-
const int ncols = m_denominator.get_header().get_identifier().get_layout().dim(0);
98-
const int nlevs = m_denominator.get_header().get_identifier().get_layout().dim(1);
85+
const int ncols = f.get_header().get_identifier().get_layout().dim(0);
86+
const int nlevs = f.get_header().get_identifier().get_layout().dim(1);
9987
const auto policy = TPF::get_default_team_policy(ncols, nlevs);
10088

101-
// get the denominator first
102-
if (m_derivative_method == "p") {
103-
m_denominator.update(dp, sp(1.0), sp(0.0));
104-
} else if (m_derivative_method == "dz") {
105-
// TODO: for some reason the z_mid field keeps getting set to 0
106-
// TODO: as a workaround, just calculate z_mid here (sigh...)
107-
// m_denominator.update(get_field_in("z_mid"), 1.0, 0.0);
108-
using PF = scream::PhysicsFunctions<DefaultDevice>;
109-
auto zm_v = m_denominator.get_view<Real **>();
110-
auto pm_v = get_field_in("p_mid").get_view<const Real **>();
111-
auto tm_v = get_field_in("T_mid").get_view<const Real **>();
112-
auto qv_v = get_field_in("qv").get_view<const Real **>();
113-
114-
Kokkos::parallel_for(
115-
"Compute dz for " + m_diagnostic_output.name(), policy, KOKKOS_LAMBDA(const MT &team) {
116-
const int icol = team.league_rank();
117-
auto zm_icol = ekat::subview(zm_v, icol);
118-
auto dp_icol = ekat::subview(dp2d, icol);
119-
auto pm_icol = ekat::subview(pm_v, icol);
120-
auto tm_icol = ekat::subview(tm_v, icol);
121-
auto qv_icol = ekat::subview(qv_v, icol);
122-
PF::calculate_dz(team, dp_icol, pm_icol, tm_icol, qv_icol, zm_icol);
123-
});
124-
}
89+
auto d_v = (m_derivative_method == "z") ? get_field_in("dz").get_view<Real **>() : dp2d;
12590

126-
auto d_v = m_denominator.get_view<Real **>();
12791
Kokkos::parallel_for(
12892
"Compute df / denominator for " + m_diagnostic_output.name(), policy,
12993
KOKKOS_LAMBDA(const MT &team) {
13094
const int icol = team.league_rank();
13195
auto f_icol = ekat::subview(f2d, icol); // field at midpoint
13296
auto o_icol = ekat::subview(o2d, icol); // output at midnpoint
133-
auto d_icol =
134-
ekat::subview(d_v, icol); // recall denominator is already a difference of interfaces
135-
auto dpicol =
136-
ekat::subview(dp2d, icol); // in case of z deriv, d_icol and dpicol are not the same
97+
auto d_icol = ekat::subview(d_v, icol); // recall denominator is already a difference of interfaces
98+
auto dpicol = ekat::subview(dp2d, icol); // in case of z deriv, d_icol and dpicol are not the same
13799

138100
Kokkos::parallel_for(Kokkos::TeamVectorRange(team, nlevs), [&](const int ilev) {
139101
// boundary points

components/eamxx/src/diagnostics/vert_derivative.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ class VertDerivativeDiag : public AtmosphereDiagnostic {
3333
std::string m_diag_name;
3434
// Name of derivative method (differential dp or dz)
3535
std::string m_derivative_method;
36-
// Need to hold the ncol,nlev denominator
37-
Field m_denominator;
3836
};
3937

4038
} // namespace scream

0 commit comments

Comments
 (0)