Skip to content

Commit 22cde10

Browse files
committed
pass column views to microphysics and then process to write out diagnostics
1 parent 31c0b60 commit 22cde10

File tree

4 files changed

+72
-9
lines changed

4 files changed

+72
-9
lines changed

components/eamxx/src/physics/mam/eamxx_mam_microphysics_process_interface.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ void MAMMicrophysics::run_impl(const double dt) {
570570
const int team_size=nlev;
571571
#else
572572
const int team_size=1;
573-
#endif
573+
#endif
574574
const auto policy =
575575
ekat::ExeSpaceUtils<KT::ExeSpace>::get_team_policy_force_team_size(ncol, team_size);
576576

@@ -802,6 +802,12 @@ void MAMMicrophysics::run_impl(const double dt) {
802802
const int surface_lev = nlev - 1; // Surface level
803803
const auto &index_season_lai = index_season_lai_;
804804
const int pcnst = mam4::pcnst;
805+
806+
Kokkos::Array<Real, gas_pcnst> molar_mass_g_per_mol_tmp;
807+
for (int i = 0; i < gas_pcnst; ++i) {
808+
molar_mass_g_per_mol_tmp[i] = mam4::gas_chemistry::adv_mass[i]; // host-only access
809+
}
810+
805811
//NOTE: we need to initialize photo_rates_
806812
Kokkos::deep_copy(photo_rates_,0.0);
807813
// loop over atmosphere columns and compute aerosol microphyscs
@@ -920,7 +926,15 @@ void MAMMicrophysics::run_impl(const double dt) {
920926
const auto aqh2so4_flx_col = ekat::subview(aqh2so4_flx, icol); // deposition flux of h2so4 [mole/mole/s]
921927
Real dflx_col[gas_pcnst] = {}; // deposition velocity [1/cm/s]
922928
Real dvel_col[gas_pcnst] = {}; // deposition flux [1/cm^2/s]
929+
// mam::microphysics wants the full column of these tendencies
930+
// TODO: is it better for each column's threadTeam to have its own 3d view,
931+
// or subview into a 4d view that contains all 'ncol' columns of these?
932+
view_3d qgcm_tendaa("diag_tendency-col", nlev, gas_pcnst, mam4::microphysics::nqtendaa());
933+
view_3d qqcwgcm_tendaa("diag_tendency_cw-col", nlev, gas_pcnst, mam4::microphysics::nqqcwtendaa());
934+
Kokkos::deep_copy(qgcm_tendaa, 0.0);
935+
Kokkos::deep_copy(qqcwgcm_tendaa, 0.0);
923936
// Output: values are dvel, dflx
937+
// Diagnostic Output: qgcm_tendaa, qqcwgcm_tendaa
924938
// Input/Output: progs::stateq, progs::qqcw
925939
team.team_barrier();
926940
mam4::microphysics::perform_atmospheric_chemistry_and_microphysics(
@@ -937,8 +951,9 @@ void MAMMicrophysics::run_impl(const double dt) {
937951
offset_aerosol, config.linoz.o3_sfc, config.linoz.o3_tau,
938952
config.linoz.o3_lbl, dry_diameter_icol, wet_diameter_icol,
939953
wetdens_icol, dry_atm.phis(icol), cmfdqr, prain_icol, nevapr_icol,
940-
work_set_het_icol, drydep_data, aqso4_flx_col, aqh2so4_flx_col, dvel_col, dflx_col, progs);
941-
954+
work_set_het_icol, drydep_data, aqso4_flx_col, aqh2so4_flx_col,
955+
dvel_col, dflx_col, qgcm_tendaa, qqcwgcm_tendaa, progs);
956+
942957
team.team_barrier();
943958
// Update constituent fluxes with gas drydep fluxes (dflx)
944959
// FIXME: Possible units mismatch (dflx is in kg/cm2/s but
@@ -947,6 +962,7 @@ void MAMMicrophysics::run_impl(const double dt) {
947962
Kokkos::parallel_for(Kokkos::TeamVectorRange(team, offset_aerosol, pcnst), [&](int ispc) {
948963
constituent_fluxes(icol, ispc) -= dflx_col[ispc - offset_aerosol];
949964
});
965+
950966
}); // parallel_for for the column loop
951967
Kokkos::fence();
952968

@@ -958,10 +974,6 @@ void MAMMicrophysics::run_impl(const double dt) {
958974
// NOTE: These indices should match the species in extfrc_lst
959975
// TODO: getting rid of hard-coded indices
960976
Kokkos::Array<int, extcnt> extfrc_pcnst_index = {3, 6, 14, 27, 28, 13, 18, 30, 5};
961-
Kokkos::Array<Real, gas_pcnst> molar_mass_g_per_mol_tmp;
962-
for (int i = 0; i < gas_pcnst; ++i) {
963-
molar_mass_g_per_mol_tmp[i] = mam4::gas_chemistry::adv_mass[i]; // host-only access
964-
}
965977

966978
// Transpose extfrc_ from internal layout [ncol][nlev][extcnt]
967979
// to output layout [ncol][extcnt][nlev]

components/eamxx/src/physics/mam/eamxx_mam_microphysics_process_interface.hpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,57 @@ class MAMMicrophysics final : public MAMGenericInterface {
6060
// Finalize
6161
void finalize_impl(){/*Do nothing*/};
6262

63+
void process_diagnostic_tendencies(view_3d &qgcm_tendaa, view_3d &qqcwgcm_tendaa,
64+
const Kokkos::Array<Real, mam_coupling::gas_pcnst()> &adv_mass,
65+
const const_view_1d &pdel, const int ncol, const int nlev) {
66+
// HACK: these are placeholders until we establish a way of requesting diagnostic output
67+
// flag: write the full columns of mean tracer mixing ratios
68+
constexpr bool write_full_col_gas_spec = true;
69+
// flag: write the column-integrated tendencies
70+
constexpr bool write_coltend_gas_spec = true;
71+
const int gas_pcnst = mam_coupling::gas_pcnst();
72+
const int nq = mam4::microphysics::nqtendaa();
73+
const int nqqcw = mam4::microphysics::nqqcwtendaa();
74+
75+
if (write_full_col_gas_spec) {
76+
// TODO: write out qgcm_tendaa and qqcwgcm_tendaa...
77+
}
78+
79+
if (write_coltend_gas_spec) {
80+
using physconst = scream::physics::Constants<Real>;
81+
static constexpr Real gravity = physconst::gravit;
82+
static constexpr Real mw_dry_air = physconst::MWdry;
83+
// first calculate the tendencies
84+
view_2d q_coltendaa("diag_tends", gas_pcnst, nq);
85+
view_2d qqcw_coltendaa("diag_tends-cw", gas_pcnst, nqqcw);
86+
Kokkos::deep_copy(q_coltendaa, 0.0);
87+
Kokkos::deep_copy(qqcw_coltendaa, 0.0);
88+
89+
// TODO: can probably do this using vert_contract.hpp, though the messiness
90+
// of the weights could mean it's not worth it
91+
Kokkos::parallel_for("calc_diagnostic_tendencies",
92+
Kokkos::MDRangePolicy<Kokkos::Rank<3>>({0,0,0}, {nlev, gas_pcnst, nq}),
93+
KOKKOS_LAMBDA(const int k, const int spec, const int itend) {
94+
Real pdel_fac = pdel(k) / gravity;
95+
// const auto q_k = ekat::subview(qgcm_tendaa, k);
96+
q_coltendaa(spec, itend) = q_coltendaa(spec, itend)
97+
+ qgcm_tendaa(k, spec, itend) * pdel_fac * (adv_mass[spec] / mw_dry_air);
98+
});
99+
// NOTE: looping over the third dimension (nqqcw) may be pointless
100+
// here because nqqcw == 1 appears to be hard-coded
101+
Kokkos::parallel_for("calc_diagnostic_tendencies",
102+
Kokkos::MDRangePolicy<Kokkos::Rank<3>>({0,0,0}, {nlev, gas_pcnst, nqqcw}),
103+
KOKKOS_LAMBDA(const int k, const int spec, const int itend) {
104+
Real pdel_fac = pdel(k) / gravity;
105+
// const auto q_k = ekat::subview(qqcwgcm_tendaa, k);
106+
qqcw_coltendaa(spec, itend) = qqcw_coltendaa(spec, itend)
107+
+ qqcwgcm_tendaa(k, spec, itend) * pdel_fac * (adv_mass[spec] / mw_dry_air);
108+
});
109+
110+
// TODO: write q_coltendaa and qqcw_coltendaa out...
111+
}
112+
}
113+
63114
private:
64115
// The orbital year, used for zenith angle calculations:
65116
// If > 0, use constant orbital year for duration of simulation

0 commit comments

Comments
 (0)