Skip to content

Commit 37dea04

Browse files
authored
Merge pull request #3108 from eagles-project/oscar/find_season_index
MAM4xx: Add reader for season_wes, which is part of the microphysics interface.
2 parents 3f99ea0 + 9fbdbb3 commit 37dea04

File tree

7 files changed

+93
-2
lines changed

7 files changed

+93
-2
lines changed

components/eamxx/cime_config/namelist_defaults_scream.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ be lost if SCREAM_HACK_XML is not enabled.
295295
<mam4_xs_long_file type="file" doc="File containing photolysis data"> ${DIN_LOC_ROOT}/atm/scream/mam4xx/photolysis/temp_prs_GT200nm_JPL10_c130206.nc</mam4_xs_long_file>
296296
<!--Elevated emissions-->
297297
<elevated_emiss_ymd type="integer"> 20100101 </elevated_emiss_ymd>
298+
<!--Dry gas deposition-->
299+
<mam4_season_wes_file type="file" doc="File containing season_wes data"> ${DIN_LOC_ROOT}/atm/scream/mam4xx/drydep/season_wes.nc</mam4_season_wes_file>
298300
<!-- For all other grids -->
299301
<mam4_so2_elevated_emiss_file_name type="file" doc="elevated emissions for so2">${DIN_LOC_ROOT}/atm/scream/mam4xx/emissions/ne30pg2/elevated/cmip6_mam4_so2_elev_1x1_2010_clim_ne30pg2_c20241008.nc</mam4_so2_elevated_emiss_file_name>
300302
<mam4_so4_a1_elevated_emiss_file_name type="file" doc="elevated emissions for so4_a1">${DIN_LOC_ROOT}/atm/scream/mam4xx/emissions/ne30pg2/elevated/cmip6_mam4_so4_a1_elev_1x1_2010_clim_ne30pg2_c20241008.nc</mam4_so4_a1_elevated_emiss_file_name>

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// impl namespace for some driver level functions for microphysics
44

55
#include "readfiles/photo_table_utils.cpp"
6+
#include "readfiles/find_season_index_utils.hpp"
67
#include "physics/rrtmgp/shr_orb_mod_c2f.hpp"
78

89
namespace scream {
@@ -332,6 +333,14 @@ void MAMMicrophysics::set_grids(
332333
"MAX_NUM_ELEVATED_EMISSIONS_FIELDS in tracer_reader_utils.hpp \n");
333334

334335
} // Tracer external forcing data
336+
337+
{
338+
const std::string season_wes_file = m_params.get<std::string>("mam4_season_wes_file");
339+
const auto& clat = col_latitudes_;
340+
mam_coupling::find_season_index_reader(season_wes_file,
341+
clat,
342+
index_season_lai_);
343+
}
335344
} // set_grids
336345

337346
// ================================================================

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class MAMMicrophysics final : public scream::AtmosphereProcess {
2525

2626
using view_1d_host = typename KT::view_1d<Real>::HostMirror;
2727

28+
using view_int_2d = typename KT::template view_2d<int>;
29+
2830
// a thread team dispatched to a single vertical column
2931
using ThreadTeam = mam4::ThreadTeam;
3032

@@ -239,6 +241,8 @@ class MAMMicrophysics final : public scream::AtmosphereProcess {
239241
view_1d_host acos_cosine_zenith_host_;
240242
view_1d acos_cosine_zenith_;
241243

244+
view_int_2d index_season_lai_;
245+
242246
}; // MAMMicrophysics
243247

244248
} // namespace scream
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#ifndef EAMXX_MAM_FIND_SEASON_INDEX_UTILS
2+
#define EAMXX_MAM_FIND_SEASON_INDEX_UTILS
3+
4+
#include <ekat/kokkos/ekat_kokkos_utils.hpp>
5+
#include <mam4xx/mam4.hpp>
6+
7+
#include "share/io/scorpio_input.hpp"
8+
#include "share/io/scream_scorpio_interface.hpp"
9+
10+
namespace scream::mam_coupling {
11+
12+
// views for single- and multi-column data
13+
14+
using const_view_1d = typename KT::template view_1d<const Real>;
15+
using view_int_2d = typename KT::template view_2d<int>;
16+
17+
using view_1d_host = typename KT::view_1d<Real>::HostMirror;
18+
using view_int_3d_host = typename KT::view_3d<int>::HostMirror;
19+
using view_int_2d_host = typename KT::view_2d<int>::HostMirror;
20+
21+
/**
22+
* @brief Reads the season index from the given file and computes the season
23+
* indices based on latitudes.
24+
*
25+
* @param[in] season_wes_file The path to the season_wes.nc file.
26+
* @param[in] clat A 1D view of latitude values in degrees.
27+
* @param[out] index_season_lai A 2D view to store the computed season indices.
28+
* Note that indices are in C++ (starting from zero).
29+
*/
30+
31+
inline void find_season_index_reader(const std::string &season_wes_file,
32+
const const_view_1d &clat,
33+
view_int_2d &index_season_lai) {
34+
const int plon = clat.extent(0);
35+
scorpio::register_file(season_wes_file, scorpio::Read);
36+
37+
const int nlat_lai = scorpio::get_dimlen(season_wes_file, "lat");
38+
const int npft_lai = scorpio::get_dimlen(season_wes_file, "pft");
39+
40+
view_1d_host lat_lai("lat_lai", nlat_lai);
41+
view_int_2d_host wk_lai_temp("wk_lai", npft_lai, nlat_lai);
42+
view_int_3d_host wk_lai("wk_lai", nlat_lai, npft_lai, 12);
43+
44+
scorpio::read_var(season_wes_file, "lat", lat_lai.data());
45+
46+
Kokkos::MDRangePolicy<Kokkos::HostSpace::execution_space, Kokkos::Rank<2>>
47+
policy_wk_lai({0, 0}, {nlat_lai, npft_lai});
48+
49+
// loop over time to get all 12 instantence of season_wes
50+
for(int itime = 0; itime < 12; ++itime) {
51+
scorpio::read_var(season_wes_file, "season_wes", wk_lai_temp.data(), itime);
52+
// copy data from wk_lai_temp to wk_lai.
53+
// NOTE: season_wes has different layout that wk_lai
54+
Kokkos::parallel_for("copy_to_wk_lai", policy_wk_lai,
55+
[&](const int j, const int k) {
56+
wk_lai(j, k, itime) = wk_lai_temp(k, j);
57+
});
58+
Kokkos::fence();
59+
}
60+
scorpio::release_file(season_wes_file);
61+
62+
index_season_lai = view_int_2d("index_season_lai", plon, 12);
63+
const view_int_2d_host index_season_lai_host =
64+
Kokkos::create_mirror_view(index_season_lai);
65+
66+
const view_1d_host clat_host = Kokkos::create_mirror_view(clat);
67+
Kokkos::deep_copy(clat_host, clat);
68+
69+
// Computation is performed on the host
70+
mam4::mo_drydep::find_season_index(clat_host, lat_lai, nlat_lai, wk_lai,
71+
index_season_lai_host);
72+
Kokkos::deep_copy(index_season_lai, index_season_lai_host);
73+
}
74+
} // namespace scream::mam_coupling
75+
#endif //

components/eamxx/tests/single-process/mam/aero_microphys/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ set (TEST_INPUT_FILES
3939
scream/mam4xx/emissions/ne2np4/elevated/cmip6_mam4_num_a2_elev_ne2np4_2010_clim_c20240823.nc
4040
scream/mam4xx/emissions/ne2np4/elevated/cmip6_mam4_num_a4_elev_ne2np4_2010_clim_c20240823.nc
4141
scream/mam4xx/emissions/ne2np4/elevated/cmip6_mam4_soag_elev_ne2np4_2010_clim_c20240823.nc
42+
scream/mam4xx/drydep/season_wes.nc
4243
)
4344
foreach (file IN ITEMS ${TEST_INPUT_FILES})
4445
GetInputFile(${file})

components/eamxx/tests/single-process/mam/aero_microphys/input.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ atmosphere_processes:
3737
mam4_num_a2_elevated_emiss_file_name : ${SCREAM_DATA_DIR}/mam4xx/emissions/ne2np4/elevated/cmip6_mam4_num_a2_elev_ne2np4_2010_clim_c20240823.nc
3838
mam4_num_a4_elevated_emiss_file_name : ${SCREAM_DATA_DIR}/mam4xx/emissions/ne2np4/elevated/cmip6_mam4_num_a4_elev_ne2np4_2010_clim_c20240823.nc
3939
mam4_soag_elevated_emiss_file_name : ${SCREAM_DATA_DIR}/mam4xx/emissions/ne2np4/elevated/cmip6_mam4_soag_elev_ne2np4_2010_clim_c20240823.nc
40-
40+
mam4_season_wes_file : ${SCREAM_DATA_DIR}/mam4xx/drydep/season_wes.nc
4141
grids_manager:
4242
Type: Mesh Free
4343
geo_data_source: IC_FILE

0 commit comments

Comments
 (0)