Skip to content

Commit

Permalink
Implement call to mam4xx::perform_atmospheric_chemistry_and_microphys…
Browse files Browse the repository at this point in the history
…ics.
  • Loading branch information
overfelt committed Nov 18, 2024
1 parent 98ac5d3 commit 3dc94f2
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <physics/mam/eamxx_mam_microphysics_process_interface.hpp>

#include <mam4xx/mam4.hpp>
// impl namespace for some driver level functions for microphysics

#include "readfiles/photo_table_utils.cpp"
Expand Down Expand Up @@ -545,10 +545,12 @@ void MAMMicrophysics::initialize_impl(const RunType run_type) {
// RUN_IMPL
// ================================================================
void MAMMicrophysics::run_impl(const double dt) {
const int ncol = ncol_;
const int nlev = nlev_;
const auto scan_policy = ekat::ExeSpaceUtils<
KT::ExeSpace>::get_thread_range_parallel_scan_team_policy(ncol_, nlev_);
KT::ExeSpace>::get_thread_range_parallel_scan_team_policy(ncol, nlev);
const auto policy =
ekat::ExeSpaceUtils<KT::ExeSpace>::get_default_team_policy(ncol_, nlev_);
ekat::ExeSpaceUtils<KT::ExeSpace>::get_default_team_policy(ncol, nlev);

// preprocess input -- needs a scan for the calculation of atm height
Kokkos::parallel_for("preprocess", scan_policy, preprocess_);
Expand Down Expand Up @@ -691,7 +693,7 @@ void MAMMicrophysics::run_impl(const double dt) {
// then deep copied to a device view.

// Now use solar declination to calculate zenith angle for all points
for(int i = 0; i < ncol_; i++) {
for(int i = 0; i < ncol; i++) {
Real lat =
col_latitudes_host(i) * M_PI / 180.0; // Convert lat/lon to radians
Real lon = col_longitudes_host(i) * M_PI / 180.0;
Expand Down Expand Up @@ -722,6 +724,9 @@ void MAMMicrophysics::run_impl(const double dt) {
clsmap_4[i] = mam4::gas_chemistry::clsmap_4[i];
permute_4[i] = mam4::gas_chemistry::permute_4[i];
}
const mam4::seq_drydep::Data drydep_data = mam4::seq_drydep::set_gas_drydep_data();
const auto qv = wet_atm_.qv;
const int month = timestamp().get_month(); // 1-based
// loop over atmosphere columns and compute aerosol microphyscs
Kokkos::parallel_for(
policy, KOKKOS_LAMBDA(const ThreadTeam &team) {
Expand Down Expand Up @@ -787,20 +792,47 @@ void MAMMicrophysics::run_impl(const double dt) {
ekat::subview(linoz_dPmL_dO3col, icol);
const auto linoz_cariolle_pscs_icol =
ekat::subview(linoz_cariolle_pscs, icol);
// Note: All variables are inputs, except for progs, which is an
// input/output variable.

// All of these need to be filled with valid data:
const Real sfc_temp = 250;
const Real air_temp = atm.temperature(nlev-1);
const Real spec_hum = qv(ncol, nlev-1);
const Real tv = mam4::conversions::virtual_temperature_from_temperature(air_temp, spec_hum);
const Real pressure_sfc = atm.pressure(nlev-1);
const Real pressure_10m = 1010; // Millibars?
const Real wind_speed = 0;
const Real rain = 0;
const Real snow = 0;
const Real solar_flux = 1.0; // ?
const Real mmr[gas_pcnst] = {};
const Real fraction_landuse[mam4::mo_drydep::n_land_type] = {.5, .5, .5, .5, .5};
const int col_index_season[mam4::mo_drydep::n_land_type] = {1,2,3,4,5,6,7,8,9};
// These output values need to be put somewhere:
Real dvel[gas_pcnst] = {};
Real dflx[gas_pcnst] = {};

// Output: values are dvel, dvlx
// Input/Output: progs::stateq, progs::qqcw
mam4::microphysics::perform_atmospheric_chemistry_and_microphysics(
team, dt, rlats, cnst_offline_icol, forcings_in, atm, progs,
team, dt, rlats, month,
sfc_temp, air_temp, tv,
pressure_sfc, pressure_10m, spec_hum,
wind_speed, rain, snow,
solar_flux,
cnst_offline_icol, forcings_in, atm,
photo_table, chlorine_loading, config.setsox, config.amicphys,
config.linoz.psc_T, zenith_angle(icol), d_sfc_alb_dir_vis(icol),
o3_col_dens_i, photo_rates_icol, extfrc_icol, invariants_icol,
work_photo_table_icol, linoz_o3_clim_icol, linoz_t_clim_icol,
linoz_o3col_clim_icol, linoz_PmL_clim_icol, linoz_dPmL_dO3_icol,
linoz_dPmL_dT_icol, linoz_dPmL_dO3col_icol,
linoz_cariolle_pscs_icol, eccf, adv_mass_kg_per_moles, clsmap_4,
linoz_cariolle_pscs_icol, eccf, adv_mass_kg_per_moles,
mmr, fraction_landuse, col_index_season, clsmap_4,
permute_4, offset_aerosol,
config.linoz.o3_sfc, config.linoz.o3_tau, config.linoz.o3_lbl,
dry_diameter_icol, wet_diameter_icol, wetdens_icol);
dry_diameter_icol, wet_diameter_icol, wetdens_icol,
drydep_data,
dvel, dflx, progs);
}); // parallel_for for the column loop
Kokkos::fence();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class MAMMicrophysics final : public scream::AtmosphereProcess {
// Constructor
MAMMicrophysics(const ekat::Comm &comm, const ekat::ParameterList &params);

// Virtual Destructor
virtual ~MAMMicrophysics() {}

// --------------------------------------------------------------------------
// AtmosphereProcess overrides (see share/atm_process/atmosphere_process.hpp)
// --------------------------------------------------------------------------
Expand All @@ -40,7 +43,7 @@ class MAMMicrophysics final : public scream::AtmosphereProcess {
AtmosphereProcessType type() const override;

// The name of the subcomponent
std::string name() const { return "mam_aero_microphysics"; }
std::string name() const override { return "mam_aero_microphysics"; }

// grid
void set_grids(
Expand All @@ -57,7 +60,7 @@ class MAMMicrophysics final : public scream::AtmosphereProcess {
void run_impl(const double dt) override;

// Finalize
void finalize_impl(){/*Do nothing*/};
void finalize_impl() override {/*Do nothing*/};

private:
// number of horizontal columns and vertical levels
Expand Down

0 comments on commit 3dc94f2

Please sign in to comment.