From 8e72936483027815eddc124c97316e4191232192 Mon Sep 17 00:00:00 2001 From: Oscar Diaz-Ibarra Date: Mon, 11 Nov 2024 20:10:50 -0700 Subject: [PATCH 1/6] EAMxx: Interface for reading file and setting index_season_lai --- ...mxx_mam_microphysics_process_interface.cpp | 9 +++ ...mxx_mam_microphysics_process_interface.hpp | 4 ++ .../mam/readfiles/find_season_index_utils.hpp | 62 +++++++++++++++++++ externals/mam4xx | 2 +- 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 components/eamxx/src/physics/mam/readfiles/find_season_index_utils.hpp diff --git a/components/eamxx/src/physics/mam/eamxx_mam_microphysics_process_interface.cpp b/components/eamxx/src/physics/mam/eamxx_mam_microphysics_process_interface.cpp index c53052b57ae..a284178a8b3 100644 --- a/components/eamxx/src/physics/mam/eamxx_mam_microphysics_process_interface.cpp +++ b/components/eamxx/src/physics/mam/eamxx_mam_microphysics_process_interface.cpp @@ -3,6 +3,7 @@ // impl namespace for some driver level functions for microphysics #include "readfiles/photo_table_utils.cpp" +#include "readfiles/find_season_index_utils.hpp" #include "physics/rrtmgp/shr_orb_mod_c2f.hpp" namespace scream { @@ -332,6 +333,14 @@ void MAMMicrophysics::set_grids( "MAX_NUM_ELEVATED_EMISSIONS_FIELDS in tracer_reader_utils.hpp \n"); } // Tracer external forcing data + + { + std::string season_wes_file ="season_wes.nc"; + const auto& clat = col_latitudes_; + mam_coupling::find_season_index_reader(season_wes_file, + clat, + index_season_lai_); + } } // set_grids // ================================================================ diff --git a/components/eamxx/src/physics/mam/eamxx_mam_microphysics_process_interface.hpp b/components/eamxx/src/physics/mam/eamxx_mam_microphysics_process_interface.hpp index 6be8f3e7fb5..d555fe82024 100644 --- a/components/eamxx/src/physics/mam/eamxx_mam_microphysics_process_interface.hpp +++ b/components/eamxx/src/physics/mam/eamxx_mam_microphysics_process_interface.hpp @@ -25,6 +25,8 @@ class MAMMicrophysics final : public scream::AtmosphereProcess { using view_1d_host = typename KT::view_1d::HostMirror; + using view_int_2d = typename KT::template view_2d; + // a thread team dispatched to a single vertical column using ThreadTeam = mam4::ThreadTeam; @@ -239,6 +241,8 @@ class MAMMicrophysics final : public scream::AtmosphereProcess { view_1d_host acos_cosine_zenith_host_; view_1d acos_cosine_zenith_; + view_int_2d index_season_lai_; + }; // MAMMicrophysics } // namespace scream diff --git a/components/eamxx/src/physics/mam/readfiles/find_season_index_utils.hpp b/components/eamxx/src/physics/mam/readfiles/find_season_index_utils.hpp new file mode 100644 index 00000000000..70f743b2376 --- /dev/null +++ b/components/eamxx/src/physics/mam/readfiles/find_season_index_utils.hpp @@ -0,0 +1,62 @@ +#ifndef EAMXX_MAM_FIND_SEASON_INDEX_UTILS +#define EAMXX_MAM_FIND_SEASON_INDEX_UTILS + +#include +#include "share/io/scorpio_input.hpp" +#include "share/io/scream_scorpio_interface.hpp" +#include + +namespace scream::mam_coupling { + +using ExeSpace = typename KT::ExeSpace; +using ESU = ekat::ExeSpaceUtils; + +// views for single- and multi-column data +using view_1d = typename KT::template view_1d; +using const_view_1d = typename KT::template view_1d; + +using view_int_1d = typename KT::template view_1d; +using view_int_2d = typename KT::template view_2d; +using view_int_3d = typename KT::template view_3d; + +using view_1d_host = typename KT::view_1d::HostMirror; +using view_3d_host = typename KT::view_3d::HostMirror; +using view_int_3d_host = typename KT::view_3d::HostMirror; + + +inline void find_season_index_reader(const std::string& season_wes_file, + const const_view_1d& clat, + view_int_2d &index_season_lai) +{ + const int plon= clat.extent(0); + scorpio::register_file(season_wes_file, scorpio::Read); + + const int nlat_lai = scorpio::get_dimlen(season_wes_file, "lat"); + const int npft_lai = scorpio::get_dimlen(season_wes_file, "pft"); + view_1d_host lat_lai_host("lat_lai_host", nlat_lai); + view_int_3d_host wk_lai_host("wk_lai_host", nlat_lai, npft_lai, 12); + + scorpio::read_var(season_wes_file, "lat", lat_lai_host.data()); + scorpio::read_var(season_wes_file, "season_wes", wk_lai_host.data()); + scorpio::release_file(season_wes_file); + + view_int_3d wk_lai("wk_lai", nlat_lai, npft_lai, 12); + + view_1d lat_lai("lat_lai", nlat_lai); + Kokkos::deep_copy(lat_lai, lat_lai_host); + Kokkos::deep_copy(wk_lai, wk_lai_host); + + // output + index_season_lai=view_int_2d("index_season_lai", plon,12); + const auto policy = ESU::get_default_team_policy(plon, 1); + Kokkos::parallel_for( + policy, KOKKOS_LAMBDA(const Team &team) { + const int j = team.league_rank(); + const auto index_season_lai_at_j = ekat::subview(index_season_lai, j); + mam4::mo_drydep::find_season_index(clat(j), lat_lai, nlat_lai, wk_lai, + index_season_lai_at_j); + }); +} + +} // namespace scream::mam_coupling +#endif // diff --git a/externals/mam4xx b/externals/mam4xx index aae46807bf5..5e21c26f066 160000 --- a/externals/mam4xx +++ b/externals/mam4xx @@ -1 +1 @@ -Subproject commit aae46807bf58d6ffcbc6db620c27568450b2d040 +Subproject commit 5e21c26f0662641cfd6522d5e96315f67cd7a4b4 From 79cb356562f29c049175ffb51555bf9cd348a9b3 Mon Sep 17 00:00:00 2001 From: Oscar Diaz-Ibarra Date: Wed, 13 Nov 2024 09:45:12 -0700 Subject: [PATCH 2/6] Use host version for find_season_index and add function description --- .../mam/readfiles/find_season_index_utils.hpp | 67 ++++++++++++------- externals/mam4xx | 2 +- 2 files changed, 43 insertions(+), 26 deletions(-) diff --git a/components/eamxx/src/physics/mam/readfiles/find_season_index_utils.hpp b/components/eamxx/src/physics/mam/readfiles/find_season_index_utils.hpp index 70f743b2376..c7778b74421 100644 --- a/components/eamxx/src/physics/mam/readfiles/find_season_index_utils.hpp +++ b/components/eamxx/src/physics/mam/readfiles/find_season_index_utils.hpp @@ -12,17 +12,22 @@ using ExeSpace = typename KT::ExeSpace; using ESU = ekat::ExeSpaceUtils; // views for single- and multi-column data -using view_1d = typename KT::template view_1d; -using const_view_1d = typename KT::template view_1d; -using view_int_1d = typename KT::template view_1d; +using const_view_1d = typename KT::template view_1d; using view_int_2d = typename KT::template view_2d; -using view_int_3d = typename KT::template view_3d; using view_1d_host = typename KT::view_1d::HostMirror; using view_3d_host = typename KT::view_3d::HostMirror; using view_int_3d_host = typename KT::view_3d::HostMirror; +using view_int_2d_host = typename KT::view_2d::HostMirror; +/** + * @brief Reads the season index from the given file and computes the season indices based on latitudes. + * + * @param[in] season_wes_file The path to the season_wes.nc file. + * @param[in] clat A 1D view of latitude values in degrees. + * @param[out] index_season_lai A 2D view to store the computed season indices. Note that indices are in C++ (starting from zero). + */ inline void find_season_index_reader(const std::string& season_wes_file, const const_view_1d& clat, @@ -33,30 +38,42 @@ inline void find_season_index_reader(const std::string& season_wes_file, const int nlat_lai = scorpio::get_dimlen(season_wes_file, "lat"); const int npft_lai = scorpio::get_dimlen(season_wes_file, "pft"); - view_1d_host lat_lai_host("lat_lai_host", nlat_lai); - view_int_3d_host wk_lai_host("wk_lai_host", nlat_lai, npft_lai, 12); - scorpio::read_var(season_wes_file, "lat", lat_lai_host.data()); - scorpio::read_var(season_wes_file, "season_wes", wk_lai_host.data()); - scorpio::release_file(season_wes_file); + view_1d_host lat_lai("lat_lai", nlat_lai); + view_int_2d_host wk_lai_temp("wk_lai", npft_lai, nlat_lai); + view_int_3d_host wk_lai("wk_lai", nlat_lai, npft_lai, 12); - view_int_3d wk_lai("wk_lai", nlat_lai, npft_lai, 12); - - view_1d lat_lai("lat_lai", nlat_lai); - Kokkos::deep_copy(lat_lai, lat_lai_host); - Kokkos::deep_copy(wk_lai, wk_lai_host); - - // output - index_season_lai=view_int_2d("index_season_lai", plon,12); - const auto policy = ESU::get_default_team_policy(plon, 1); - Kokkos::parallel_for( - policy, KOKKOS_LAMBDA(const Team &team) { - const int j = team.league_rank(); - const auto index_season_lai_at_j = ekat::subview(index_season_lai, j); - mam4::mo_drydep::find_season_index(clat(j), lat_lai, nlat_lai, wk_lai, - index_season_lai_at_j); + scorpio::read_var(season_wes_file, "lat", lat_lai.data()); + + Kokkos::MDRangePolicy> + policy_wk_lai({0, 0}, {nlat_lai, npft_lai}); + + // loop over time to get all 12 instantence of season_wes + for (int itime = 0; itime < 12; ++itime) + { + scorpio::read_var(season_wes_file, "season_wes", wk_lai_temp.data(),itime); + // copy data from wk_lai_temp to wk_lai. + // NOTE: season_wes has different layout that wk_lai + Kokkos::parallel_for("copy_to_wk_lai", policy_wk_lai, + [&](const int j, const int k) { + wk_lai(j, k, itime) = wk_lai_temp(k, j); }); -} + Kokkos::fence(); + } + scorpio::release_file(season_wes_file); + + index_season_lai =view_int_2d("index_season_lai", plon, 12); + const view_int_2d_host index_season_lai_host= Kokkos::create_mirror_view(index_season_lai); + + const view_1d_host clat_host= Kokkos::create_mirror_view(clat); + Kokkos::deep_copy(clat_host, clat); + // Computation is performed on the host + mam4::mo_drydep::find_season_index(clat_host, lat_lai, nlat_lai, wk_lai, + index_season_lai_host); + Kokkos::deep_copy(index_season_lai, index_season_lai_host); + + +} } // namespace scream::mam_coupling #endif // diff --git a/externals/mam4xx b/externals/mam4xx index 5e21c26f066..d6cb4c004a6 160000 --- a/externals/mam4xx +++ b/externals/mam4xx @@ -1 +1 @@ -Subproject commit 5e21c26f0662641cfd6522d5e96315f67cd7a4b4 +Subproject commit d6cb4c004a686664dc9d5885837f69c46be2f611 From a97a7730dad27dde08fb313440c368afa8c298e1 Mon Sep 17 00:00:00 2001 From: Oscar Diaz-Ibarra Date: Wed, 13 Nov 2024 11:39:41 -0700 Subject: [PATCH 3/6] EAMxx: Obtain season_wes_file from input file and use MAM4xx main branch --- components/eamxx/cime_config/namelist_defaults_scream.xml | 2 ++ .../physics/mam/eamxx_mam_microphysics_process_interface.cpp | 2 +- .../eamxx/tests/single-process/mam/aero_microphys/input.yaml | 2 +- externals/mam4xx | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/components/eamxx/cime_config/namelist_defaults_scream.xml b/components/eamxx/cime_config/namelist_defaults_scream.xml index 9506cbdf3ab..195f46847ef 100644 --- a/components/eamxx/cime_config/namelist_defaults_scream.xml +++ b/components/eamxx/cime_config/namelist_defaults_scream.xml @@ -295,6 +295,8 @@ be lost if SCREAM_HACK_XML is not enabled. ${DIN_LOC_ROOT}/atm/scream/mam4xx/photolysis/temp_prs_GT200nm_JPL10_c130206.nc 20100101 + + ${DIN_LOC_ROOT}/atm/scream/mam4xx/drydep/season_wes.nc ${DIN_LOC_ROOT}/atm/scream/mam4xx/emissions/ne30pg2/elevated/cmip6_mam4_so2_elev_1x1_2010_clim_ne30pg2_c20241008.nc ${DIN_LOC_ROOT}/atm/scream/mam4xx/emissions/ne30pg2/elevated/cmip6_mam4_so4_a1_elev_1x1_2010_clim_ne30pg2_c20241008.nc diff --git a/components/eamxx/src/physics/mam/eamxx_mam_microphysics_process_interface.cpp b/components/eamxx/src/physics/mam/eamxx_mam_microphysics_process_interface.cpp index a284178a8b3..57eaf927548 100644 --- a/components/eamxx/src/physics/mam/eamxx_mam_microphysics_process_interface.cpp +++ b/components/eamxx/src/physics/mam/eamxx_mam_microphysics_process_interface.cpp @@ -335,7 +335,7 @@ void MAMMicrophysics::set_grids( } // Tracer external forcing data { - std::string season_wes_file ="season_wes.nc"; + const std::string season_wes_file = m_params.get("mam4_season_wes_file"); const auto& clat = col_latitudes_; mam_coupling::find_season_index_reader(season_wes_file, clat, diff --git a/components/eamxx/tests/single-process/mam/aero_microphys/input.yaml b/components/eamxx/tests/single-process/mam/aero_microphys/input.yaml index d4d29091df4..9348a04a21d 100644 --- a/components/eamxx/tests/single-process/mam/aero_microphys/input.yaml +++ b/components/eamxx/tests/single-process/mam/aero_microphys/input.yaml @@ -37,7 +37,7 @@ atmosphere_processes: mam4_num_a2_elevated_emiss_file_name : ${SCREAM_DATA_DIR}/mam4xx/emissions/ne2np4/elevated/cmip6_mam4_num_a2_elev_ne2np4_2010_clim_c20240823.nc mam4_num_a4_elevated_emiss_file_name : ${SCREAM_DATA_DIR}/mam4xx/emissions/ne2np4/elevated/cmip6_mam4_num_a4_elev_ne2np4_2010_clim_c20240823.nc mam4_soag_elevated_emiss_file_name : ${SCREAM_DATA_DIR}/mam4xx/emissions/ne2np4/elevated/cmip6_mam4_soag_elev_ne2np4_2010_clim_c20240823.nc - + mam4_season_wes_file : ${SCREAM_DATA_DIR}/mam4xx/drydep/season_wes.nc grids_manager: Type: Mesh Free geo_data_source: IC_FILE diff --git a/externals/mam4xx b/externals/mam4xx index d6cb4c004a6..4431bbd1eef 160000 --- a/externals/mam4xx +++ b/externals/mam4xx @@ -1 +1 @@ -Subproject commit d6cb4c004a686664dc9d5885837f69c46be2f611 +Subproject commit 4431bbd1eef46de25be3a04e7091c9255bd0b819 From 1f9563a722ff4e72f1c8dd93012b7c13b4646f4b Mon Sep 17 00:00:00 2001 From: Oscar Diaz-Ibarra Date: Wed, 13 Nov 2024 11:44:09 -0700 Subject: [PATCH 4/6] EAMxx: apply clang format to find_season_index_utils.hpp. --- .../mam/readfiles/find_season_index_utils.hpp | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/components/eamxx/src/physics/mam/readfiles/find_season_index_utils.hpp b/components/eamxx/src/physics/mam/readfiles/find_season_index_utils.hpp index c7778b74421..2550673bd9c 100644 --- a/components/eamxx/src/physics/mam/readfiles/find_season_index_utils.hpp +++ b/components/eamxx/src/physics/mam/readfiles/find_season_index_utils.hpp @@ -2,9 +2,10 @@ #define EAMXX_MAM_FIND_SEASON_INDEX_UTILS #include +#include + #include "share/io/scorpio_input.hpp" #include "share/io/scream_scorpio_interface.hpp" -#include namespace scream::mam_coupling { @@ -13,27 +14,28 @@ using ESU = ekat::ExeSpaceUtils; // views for single- and multi-column data -using const_view_1d = typename KT::template view_1d; -using view_int_2d = typename KT::template view_2d; +using const_view_1d = typename KT::template view_1d; +using view_int_2d = typename KT::template view_2d; -using view_1d_host = typename KT::view_1d::HostMirror; -using view_3d_host = typename KT::view_3d::HostMirror; +using view_1d_host = typename KT::view_1d::HostMirror; +using view_3d_host = typename KT::view_3d::HostMirror; using view_int_3d_host = typename KT::view_3d::HostMirror; using view_int_2d_host = typename KT::view_2d::HostMirror; /** - * @brief Reads the season index from the given file and computes the season indices based on latitudes. + * @brief Reads the season index from the given file and computes the season + * indices based on latitudes. * * @param[in] season_wes_file The path to the season_wes.nc file. * @param[in] clat A 1D view of latitude values in degrees. - * @param[out] index_season_lai A 2D view to store the computed season indices. Note that indices are in C++ (starting from zero). + * @param[out] index_season_lai A 2D view to store the computed season indices. + * Note that indices are in C++ (starting from zero). */ -inline void find_season_index_reader(const std::string& season_wes_file, - const const_view_1d& clat, - view_int_2d &index_season_lai) -{ - const int plon= clat.extent(0); +inline void find_season_index_reader(const std::string &season_wes_file, + const const_view_1d &clat, + view_int_2d &index_season_lai) { + const int plon = clat.extent(0); scorpio::register_file(season_wes_file, scorpio::Read); const int nlat_lai = scorpio::get_dimlen(season_wes_file, "lat"); @@ -46,34 +48,32 @@ inline void find_season_index_reader(const std::string& season_wes_file, scorpio::read_var(season_wes_file, "lat", lat_lai.data()); Kokkos::MDRangePolicy> - policy_wk_lai({0, 0}, {nlat_lai, npft_lai}); + policy_wk_lai({0, 0}, {nlat_lai, npft_lai}); // loop over time to get all 12 instantence of season_wes - for (int itime = 0; itime < 12; ++itime) - { - scorpio::read_var(season_wes_file, "season_wes", wk_lai_temp.data(),itime); - // copy data from wk_lai_temp to wk_lai. - // NOTE: season_wes has different layout that wk_lai - Kokkos::parallel_for("copy_to_wk_lai", policy_wk_lai, - [&](const int j, const int k) { - wk_lai(j, k, itime) = wk_lai_temp(k, j); - }); - Kokkos::fence(); + for(int itime = 0; itime < 12; ++itime) { + scorpio::read_var(season_wes_file, "season_wes", wk_lai_temp.data(), itime); + // copy data from wk_lai_temp to wk_lai. + // NOTE: season_wes has different layout that wk_lai + Kokkos::parallel_for("copy_to_wk_lai", policy_wk_lai, + [&](const int j, const int k) { + wk_lai(j, k, itime) = wk_lai_temp(k, j); + }); + Kokkos::fence(); } scorpio::release_file(season_wes_file); - index_season_lai =view_int_2d("index_season_lai", plon, 12); - const view_int_2d_host index_season_lai_host= Kokkos::create_mirror_view(index_season_lai); + index_season_lai = view_int_2d("index_season_lai", plon, 12); + const view_int_2d_host index_season_lai_host = + Kokkos::create_mirror_view(index_season_lai); - const view_1d_host clat_host= Kokkos::create_mirror_view(clat); + const view_1d_host clat_host = Kokkos::create_mirror_view(clat); Kokkos::deep_copy(clat_host, clat); // Computation is performed on the host mam4::mo_drydep::find_season_index(clat_host, lat_lai, nlat_lai, wk_lai, - index_season_lai_host); + index_season_lai_host); Kokkos::deep_copy(index_season_lai, index_season_lai_host); - - } } // namespace scream::mam_coupling #endif // From 0d1fdc3448ca4d76b0c2fc344520de36a2cebd66 Mon Sep 17 00:00:00 2001 From: Oscar Diaz-Ibarra Date: Wed, 13 Nov 2024 13:21:52 -0700 Subject: [PATCH 5/6] EAMxx: Obtain season_wes.nc file. --- .../eamxx/tests/single-process/mam/aero_microphys/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/components/eamxx/tests/single-process/mam/aero_microphys/CMakeLists.txt b/components/eamxx/tests/single-process/mam/aero_microphys/CMakeLists.txt index e1ba85a685f..6f6f8b364b8 100644 --- a/components/eamxx/tests/single-process/mam/aero_microphys/CMakeLists.txt +++ b/components/eamxx/tests/single-process/mam/aero_microphys/CMakeLists.txt @@ -39,6 +39,7 @@ set (TEST_INPUT_FILES scream/mam4xx/emissions/ne2np4/elevated/cmip6_mam4_num_a2_elev_ne2np4_2010_clim_c20240823.nc scream/mam4xx/emissions/ne2np4/elevated/cmip6_mam4_num_a4_elev_ne2np4_2010_clim_c20240823.nc scream/mam4xx/emissions/ne2np4/elevated/cmip6_mam4_soag_elev_ne2np4_2010_clim_c20240823.nc + scream/mam4xx/drydep/season_wes.nc ) foreach (file IN ITEMS ${TEST_INPUT_FILES}) GetInputFile(${file}) From 9fbdbb39e864b46c108b35d068c729060e7840d9 Mon Sep 17 00:00:00 2001 From: Oscar Diaz-Ibarra Date: Wed, 13 Nov 2024 16:22:28 -0700 Subject: [PATCH 6/6] EAMxx: remove unused code. --- .../src/physics/mam/readfiles/find_season_index_utils.hpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/components/eamxx/src/physics/mam/readfiles/find_season_index_utils.hpp b/components/eamxx/src/physics/mam/readfiles/find_season_index_utils.hpp index 2550673bd9c..2e930cc65cb 100644 --- a/components/eamxx/src/physics/mam/readfiles/find_season_index_utils.hpp +++ b/components/eamxx/src/physics/mam/readfiles/find_season_index_utils.hpp @@ -9,16 +9,12 @@ namespace scream::mam_coupling { -using ExeSpace = typename KT::ExeSpace; -using ESU = ekat::ExeSpaceUtils; - // views for single- and multi-column data using const_view_1d = typename KT::template view_1d; using view_int_2d = typename KT::template view_2d; using view_1d_host = typename KT::view_1d::HostMirror; -using view_3d_host = typename KT::view_3d::HostMirror; using view_int_3d_host = typename KT::view_3d::HostMirror; using view_int_2d_host = typename KT::view_2d::HostMirror;