From f81987bf0e568e9aa23187e77becedca2d12e10d Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Tue, 11 Mar 2025 13:45:50 -0600 Subject: [PATCH 01/32] submodule ncar ccpp --- .gitmodules | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index 74be2ad99..da6d41f9a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -19,10 +19,10 @@ fxDONOTUSEurl = https://github.com/MPAS-Dev/MPAS-Model.git [submodule "ncar-physics"] path = src/physics/ncar_ccpp - url = https://github.com/ESCOMP/atmospheric_physics - fxtag = 37224423f62d9a71922cb6fe9beca1516d9403a4 + url = https://github.com/boulderdaze/atmospheric_physics + fxtag = fix_musica_bug fxrequired = AlwaysRequired - fxDONOTUSEurl = https://github.com/ESCOMP/atmospheric_physics + fxDONOTUSEurl = https://github.com/boulderdaze/atmospheric_physics [submodule "ccs_config"] path = ccs_config url = https://github.com/ESMCI/ccs_config_cesm.git From b71e798319c424f2c716ae3d9c491b970ee399d7 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Tue, 11 Mar 2025 16:05:49 -0600 Subject: [PATCH 02/32] have to add chdir process for install musica --- cime_config/buildlib | 7 +++++++ docker/Dockerfile.musica | 19 +++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/cime_config/buildlib b/cime_config/buildlib index 1aa4e2af7..36c186118 100755 --- a/cime_config/buildlib +++ b/cime_config/buildlib @@ -291,6 +291,11 @@ def _build_musica(clone_dest: str) -> str: except OSError as e: raise OSError("An error occurred while executing the 'cmake' command.") from e + # The installation requires the current working directory to be the build (CMake binary) directory. + # Using the cwd option in subprocess.run does not work. + current_dir = os.getcwd() + os.chdir(bld_path) + command = ["cmake", "--build", ".", "--target", "install"] try: subprocess.run(command, cwd=bld_path, stdout=subprocess.PIPE, @@ -303,6 +308,8 @@ def _build_musica(clone_dest: str) -> str: except OSError as e: raise OSError("An error occurred while executing the 'cmake' command.") from e + os.chdir(current_dir) + musica_install_path = os.path.join(bld_path, install_dir) return musica_install_path diff --git a/docker/Dockerfile.musica b/docker/Dockerfile.musica index f5deedbcb..86c2a3ecd 100644 --- a/docker/Dockerfile.musica +++ b/docker/Dockerfile.musica @@ -77,11 +77,22 @@ RUN /home/cam_sima_user/CAM-SIMA/cime/scripts/create_newcase --case $CASE_NAME \ WORKDIR $CASE_NAME -RUN ./case.setup - +RUN ./xmlchange COMPILER=gnu +RUN ./xmlchange DEBUG=true RUN ./xmlchange CAM_CONFIG_OPTS="--dyn none --physics-suites musica" -RUN ./xmlchange ROF_NCPL=48 RUN ./xmlchange STOP_OPTION=nsteps RUN ./xmlchange STOP_N=5 -RUN ./case.build \ No newline at end of file +# Match the GLC timestep to atmosphere timestep +RUN ./xmlchange ATM_NCPL=48 +RUN ./xmlchange GLC_NCPL=48 + +# Avoid writing restart files +RUN ./xmlchange REST_N=100 + +RUN ./case.setup + +# Add this to the end of 'user_nl_cam' file +# ncdata=/glade/campaign/cesm/community/amwg/sima_baselines/cam_sima_test_snapshots/cam_ne3pg3_kessler_snapshot_derecho_gnu_before_c20240412.nc + +# RUN ./case.build \ No newline at end of file From 023d1b9945903ebd3f86ca9e520265a01cfa6530 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Tue, 11 Mar 2025 16:25:12 -0600 Subject: [PATCH 03/32] remove cwd option from subprocess run --- cime_config/buildlib | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cime_config/buildlib b/cime_config/buildlib index 36c186118..b6fc55850 100755 --- a/cime_config/buildlib +++ b/cime_config/buildlib @@ -298,8 +298,8 @@ def _build_musica(clone_dest: str) -> str: command = ["cmake", "--build", ".", "--target", "install"] try: - subprocess.run(command, cwd=bld_path, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, text=True, check=False) + subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + text=True, check=False) except subprocess.CalledProcessError as e: raise subprocess.CalledProcessError(e.returncode, e.cmd, "The subprocess \ for cmake to build the MUSICA library failed.") from e From fff45bcc2e55b7f613311a5275ea3d8ea32c1ef7 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Tue, 11 Mar 2025 16:31:23 -0600 Subject: [PATCH 04/32] revert back for cwd --- cime_config/buildlib | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/cime_config/buildlib b/cime_config/buildlib index b6fc55850..c4351af54 100755 --- a/cime_config/buildlib +++ b/cime_config/buildlib @@ -291,14 +291,9 @@ def _build_musica(clone_dest: str) -> str: except OSError as e: raise OSError("An error occurred while executing the 'cmake' command.") from e - # The installation requires the current working directory to be the build (CMake binary) directory. - # Using the cwd option in subprocess.run does not work. - current_dir = os.getcwd() - os.chdir(bld_path) - command = ["cmake", "--build", ".", "--target", "install"] try: - subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + subprocess.run(command, cwd=bld_path, stdout=subprocess.PIPE, text=True, check=False) except subprocess.CalledProcessError as e: raise subprocess.CalledProcessError(e.returncode, e.cmd, "The subprocess \ @@ -308,8 +303,6 @@ def _build_musica(clone_dest: str) -> str: except OSError as e: raise OSError("An error occurred while executing the 'cmake' command.") from e - os.chdir(current_dir) - musica_install_path = os.path.join(bld_path, install_dir) return musica_install_path From 92d45986e7a2b764aa4a6984c85508141028e59b Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Wed, 12 Mar 2025 18:47:06 -0600 Subject: [PATCH 05/32] move musica init function before phy init --- src/control/cam_comp.F90 | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/control/cam_comp.F90 b/src/control/cam_comp.F90 index 0a8b1b63c..8ed03e08c 100644 --- a/src/control/cam_comp.F90 +++ b/src/control/cam_comp.F90 @@ -248,6 +248,16 @@ subroutine cam_init(caseid, ctitle, model_doi_url, & ! Read tropopause climatology call tropopause_climo_read_file() + ! Temporary: Prescribe realistic but inaccurate physical quantities + ! necessary for MUSICA that are currently unavailable in CAM-SIMA. + ! + ! Remove this when MUSICA input data are available from CAM-SIMA or + ! other physics schemes. + call musica_ccpp_dependencies_init(columns_on_task, pver, iulog) + + ! Initialize orbital data + call orbital_data_init(columns_on_task) + call phys_init() !!XXgoldyXX: v need to import this @@ -261,16 +271,6 @@ subroutine cam_init(caseid, ctitle, model_doi_url, & ! end if call history_init_files(model_doi_url, caseid, ctitle) - ! Temporary: Prescribe realistic but inaccurate physical quantities - ! necessary for MUSICA that are currently unavailable in CAM-SIMA. - ! - ! Remove this when MUSICA input data are available from CAM-SIMA or - ! other physics schemes. - call musica_ccpp_dependencies_init(columns_on_task, pver, iulog) - - ! Initialize orbital data - call orbital_data_init(columns_on_task) - end subroutine cam_init ! From a5eafccb67d74684bc87f5e2fbd3ca9e65868f34 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Wed, 12 Mar 2025 19:00:57 -0600 Subject: [PATCH 06/32] update data repo --- cime_config/atm_musica_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cime_config/atm_musica_config.py b/cime_config/atm_musica_config.py index 79cfa0bc5..e63831d1d 100644 --- a/cime_config/atm_musica_config.py +++ b/cime_config/atm_musica_config.py @@ -7,4 +7,4 @@ MUSICA_REPO_URL = "https://github.com/NCAR/musica.git" MUSICA_TAG = "cc39bb00d2220fc81c85b22d3ceea4a39bd2bacf" CHEMISTRY_DATA_REPO_URL = "https://github.com/NCAR/cam-sima-chemistry-data.git" -CHEMISTRY_DATA_TAG = "2b58f2410ec7a565bcf80dee16ec20f6bc35d78b" +CHEMISTRY_DATA_TAG = "b575c8232b85ab99e810274e5e1e9fce97d84bc2" # temp From 2147eb70baf56c9092167a07a9e0f11609e6a951 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Fri, 14 Mar 2025 15:04:38 -0600 Subject: [PATCH 07/32] temp setting constituents --- src/physics/ncar_ccpp | 2 +- .../utils/musica_ccpp_dependencies.F90 | 479 +++++++++++------- 2 files changed, 301 insertions(+), 180 deletions(-) diff --git a/src/physics/ncar_ccpp b/src/physics/ncar_ccpp index 988ef0088..04a9d1f30 160000 --- a/src/physics/ncar_ccpp +++ b/src/physics/ncar_ccpp @@ -1 +1 @@ -Subproject commit 988ef00880ba5c013de3ff4182c4592e80f343fe +Subproject commit 04a9d1f303e97cac38323bb369bd5461b1af72b6 diff --git a/src/physics/utils/musica_ccpp_dependencies.F90 b/src/physics/utils/musica_ccpp_dependencies.F90 index 885ed7a83..72c9fcff2 100644 --- a/src/physics/utils/musica_ccpp_dependencies.F90 +++ b/src/physics/utils/musica_ccpp_dependencies.F90 @@ -1,191 +1,312 @@ ! Copyright (C) 2024 National Science Foundation-National Center for Atmospheric Research ! SPDX-License-Identifier: Apache-2.0 module musica_ccpp_dependencies -!-------------------------------------------------------------------------- -! -! This module temporarily provides data that MUSICA chemistry consumes but -! does not produce. The values are realistic but are not based on the -! actual model state. These should be removed as the producers of this data -! are added to CAM-SIMA or as CCPP-compliant physics schemes. -! -! IMPORTANT: This module must be completely removed before doing any actual -! science with MUSICA chemistry in CAM-SIMA. -! -!-------------------------------------------------------------------------- + !-------------------------------------------------------------------------- + ! + ! This module temporarily provides data that MUSICA chemistry consumes but + ! does not produce. The values are realistic but are not based on the + ! actual model state. These should be removed as the producers of this data + ! are added to CAM-SIMA or as CCPP-compliant physics schemes. + ! + ! IMPORTANT: This module must be completely removed before doing any actual + ! science with MUSICA chemistry in CAM-SIMA. + ! + !-------------------------------------------------------------------------- + + use ccpp_kinds, only: kind_phys + use cam_logfile, only: iulog + + implicit none + private + + public :: musica_ccpp_dependencies_init + + !> \section arg_table_musica_ccpp_dependencies Argument Table + !! \htmlinclude arg_table_musica_ccpp_dependencies.html + !! + integer, public, protected :: photolysis_wavelength_grid_section_dimension = 102 + integer, public, protected :: photolysis_wavelength_grid_interface_dimension = 103 + real(kind_phys), allocatable, public, protected :: photolysis_wavelength_grid_interfaces(:) + real(kind_phys), allocatable, public, protected :: extraterrestrial_radiation_flux(:) + real(kind_phys), allocatable, public, protected :: surface_albedo(:) + real(kind_phys), allocatable, public, protected :: blackbody_temperature_at_surface(:) + + ! local parameters + character(len=*), parameter :: module_name = '(musica_ccpp_dependencies)' + + !> Definition of musica species object + type, private :: temp_musica_species_t + character(len=:), allocatable :: name + real(kind_phys) :: constituent_value = 0.0_kind_phys + end type temp_musica_species_t + + interface temp_musica_species_t + procedure species_constructor + end interface temp_musica_species_t - use ccpp_kinds, only: kind_phys + !============================================================================== + contains + !============================================================================== + + !> Constructor for temporary musica species object + function species_constructor(name, value) result( this ) + character(len=*), intent(in) :: name + real(kind_phys), intent(in) :: value + type(temp_musica_species_t) :: this + + this%name = name + this%constituent_value = value + + end function species_constructor + + !> Constructor for temporary musica species object + subroutine initialize_musica_species_constituents() + use cam_ccpp_cap, only: cam_model_const_properties + use cam_ccpp_cap, only: cam_constituents_array + use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t + use ccpp_const_utils, only: ccpp_const_get_idx + use musica_ccpp_namelist, only: filename_of_micm_configuration + use phys_vars_init_check, only: mark_as_initialized - implicit none - private + character(len=*), parameter :: chapman_config = 'chapman' + character(len=*), parameter :: terminator_config = 'terminator' + logical :: is_chapman = .false. + logical :: is_terminator = .false. + integer :: num_micm_species = 0 + integer :: num_tuvx_constituents = 1 + integer :: num_tuvx_only_gas_species = 0 + integer :: position + integer :: constituent_index + integer :: errcode + character(len=512) :: errmsg + integer :: i_elem + + real(kind_phys), pointer :: constituent_array(:,:,:) + type(ccpp_constituent_prop_ptr_t), pointer :: constituent_props(:) + type(temp_musica_species_t), allocatable :: species_group(:) - public :: musica_ccpp_dependencies_init + constituent_array => cam_constituents_array() + constituent_props => cam_model_const_properties() + + ! Check if the substring exists + position = index(filename_of_micm_configuration, chapman_config) + + if (position > 0) then + is_chapman = .true. + write(iulog,*) " [JW] Config is Chapman " + else + position = index(filename_of_micm_configuration, terminator_config) + if (position > 0) then + is_terminator = .true. + write(iulog,*) " [JW] Config is Terminator " + else + write(iulog,*) " [JW] Config is not found" + return + end if + end if + + if (is_chapman) then + num_micm_species = 5 + num_tuvx_only_gas_species = 1 + else if (is_terminator) then + num_micm_species = 2 + num_tuvx_only_gas_species = 3 + end if - !> \section arg_table_musica_ccpp_dependencies Argument Table - !! \htmlinclude arg_table_musica_ccpp_dependencies.html - !! - integer, public, protected :: photolysis_wavelength_grid_section_dimension = 102 - integer, public, protected :: photolysis_wavelength_grid_interface_dimension = 103 - real(kind_phys), allocatable, public, protected :: photolysis_wavelength_grid_interfaces(:) - real(kind_phys), allocatable, public, protected :: extraterrestrial_radiation_flux(:) - real(kind_phys), allocatable, public, protected :: surface_albedo(:) - real(kind_phys), allocatable, public, protected :: blackbody_temperature_at_surface(:) + allocate (species_group(num_micm_species + num_tuvx_constituents + num_tuvx_only_gas_species)) + ! TODO(jiwon) have to conver to cam-sima unit [mol m-3] + species_group(1) = species_constructor("cloud_liquid_water_mixing_ratio_wrt_moist_air_and_condensed_water", & + 1.0e-3_kind_phys) + if (is_chapman) then + species_group(2) = species_constructor("O2", 0.21_kind_phys) + species_group(3) = species_constructor("O", 1.0e-9_kind_phys) + species_group(4) = species_constructor("O1D", 1.0e-9_kind_phys) + species_group(5) = species_constructor("O3", 1.0e-4_kind_phys) + species_group(6) = species_constructor("N2", 0.79_kind_phys) + species_group(7) = species_constructor("air", 1.0e-3_kind_phys) + + else if (is_terminator) then + species_group(2) = species_constructor("Cl", 1.05e-4_kind_phys) + species_group(3) = species_constructor("Cl2", 1.05e-4_kind_phys) + species_group(4) = species_constructor("air", 1.0e-3_kind_phys) + species_group(5) = species_constructor("O2", 0.21_kind_phys) + species_group(6) = species_constructor("O3", 1.0e-4_kind_phys) + end if - ! local parameters - character(len=*), parameter :: module_name = '(musica_ccpp_dependencies)' + do i_elem = 1, num_micm_species + num_tuvx_constituents + num_tuvx_only_gas_species + write(iulog,*) " [JW] Calling ccpp_const_get_idx " + call ccpp_const_get_idx(constituent_props, trim(species_group(i_elem)%name), & + constituent_index, errmsg, errcode) + call mark_as_initialized(trim(species_group(i_elem)%name)) -!============================================================================== -contains -!============================================================================== + write(iulog,*) " [JW] constituent_index ", constituent_index + write(iulog,*) " [JW] species_group(i_elem)%name ", trim(species_group(i_elem)%name) + if (errcode /= 0) then + write(iulog,*) " [JW] ccpp_const_get_idx error occurs: ", errmsg + return + end if + + constituent_array(:,:,constituent_index) = species_group(i_elem)%constituent_value + end do - subroutine musica_ccpp_dependencies_init(horizontal_dimension, & - vertical_layer_dimension, log_file_unit) + deallocate (species_group) + end subroutine initialize_musica_species_constituents + + !> Constructor for temporary musica species object + subroutine musica_ccpp_dependencies_init(horizontal_dimension, & + vertical_layer_dimension, log_file_unit) + + use cam_abortutils, only: check_allocate + + !----------------------------------------------------------------------- + ! + ! Initialize the MUSICA scheme dependencies. + ! + !----------------------------------------------------------------------- + + integer, intent(in) :: horizontal_dimension + integer, intent(in) :: vertical_layer_dimension + integer, intent(in) :: log_file_unit - use cam_abortutils, only: check_allocate + integer :: error_code + character(len=*), parameter :: subroutine_name = & + trim(module_name)//':(musica_ccpp_dependencies_init)' - !----------------------------------------------------------------------- - ! - ! Initialize the MUSICA scheme dependencies. - ! - !----------------------------------------------------------------------- - - integer, intent(in) :: horizontal_dimension - integer, intent(in) :: vertical_layer_dimension - integer, intent(in) :: log_file_unit - - integer :: error_code - character(len=*), parameter :: subroutine_name = & - trim(module_name)//':(musica_ccpp_dependencies_init)' - - write(log_file_unit,*) 'WARNING: Using placeholder data for MUSICA chemistry.' - - allocate(photolysis_wavelength_grid_interfaces(photolysis_wavelength_grid_interface_dimension), & - stat=error_code) - call check_allocate(error_code, subroutine_name, & - 'photolysis_wavelength_grid_interfaces(photolysis_wavelength_grid_interface_dimension)', & - file=__FILE__, line=__LINE__) - allocate(extraterrestrial_radiation_flux(photolysis_wavelength_grid_section_dimension), & - stat=error_code) - call check_allocate(error_code, subroutine_name, & - 'extraterrestrial_radiation_flux(photolysis_wavelength_grid_section_dimension)', & - file=__FILE__, line=__LINE__) - allocate(surface_albedo(horizontal_dimension), stat=error_code) - call check_allocate(error_code, subroutine_name, & - 'surface_albedo(horizontal_dimension)', & - file=__FILE__, line=__LINE__) - allocate(blackbody_temperature_at_surface(horizontal_dimension), stat=error_code) - call check_allocate(error_code, subroutine_name, & - 'blackbody_temperature_at_surface(horizontal_dimension)', & - file=__FILE__, line=__LINE__) - - surface_albedo(:) = 0.1_kind_phys - blackbody_temperature_at_surface(:) = 292.3_kind_phys - extraterrestrial_radiation_flux(:) = 1.0e14_kind_phys - photolysis_wavelength_grid_interfaces = (/ & - 120.0e-9_kind_phys, & - 121.4e-9_kind_phys, & - 121.9e-9_kind_phys, & - 123.5e-9_kind_phys, & - 124.3e-9_kind_phys, & - 125.5e-9_kind_phys, & - 126.3e-9_kind_phys, & - 127.1e-9_kind_phys, & - 130.1e-9_kind_phys, & - 131.1e-9_kind_phys, & - 135.0e-9_kind_phys, & - 140.0e-9_kind_phys, & - 145.0e-9_kind_phys, & - 150.0e-9_kind_phys, & - 155.0e-9_kind_phys, & - 160.0e-9_kind_phys, & - 165.0e-9_kind_phys, & - 168.0e-9_kind_phys, & - 171.0e-9_kind_phys, & - 173.0e-9_kind_phys, & - 174.4e-9_kind_phys, & - 175.4e-9_kind_phys, & - 177.0e-9_kind_phys, & - 178.6e-9_kind_phys, & - 180.2e-9_kind_phys, & - 181.8e-9_kind_phys, & - 183.5e-9_kind_phys, & - 185.2e-9_kind_phys, & - 186.9e-9_kind_phys, & - 188.7e-9_kind_phys, & - 190.5e-9_kind_phys, & - 192.3e-9_kind_phys, & - 194.2e-9_kind_phys, & - 196.1e-9_kind_phys, & - 198.0e-9_kind_phys, & - 200.0e-9_kind_phys, & - 202.0e-9_kind_phys, & - 204.1e-9_kind_phys, & - 206.2e-9_kind_phys, & - 208.0e-9_kind_phys, & - 211.0e-9_kind_phys, & - 214.0e-9_kind_phys, & - 217.0e-9_kind_phys, & - 220.0e-9_kind_phys, & - 223.0e-9_kind_phys, & - 226.0e-9_kind_phys, & - 229.0e-9_kind_phys, & - 232.0e-9_kind_phys, & - 235.0e-9_kind_phys, & - 238.0e-9_kind_phys, & - 241.0e-9_kind_phys, & - 244.0e-9_kind_phys, & - 247.0e-9_kind_phys, & - 250.0e-9_kind_phys, & - 253.0e-9_kind_phys, & - 256.0e-9_kind_phys, & - 259.0e-9_kind_phys, & - 263.0e-9_kind_phys, & - 267.0e-9_kind_phys, & - 271.0e-9_kind_phys, & - 275.0e-9_kind_phys, & - 279.0e-9_kind_phys, & - 283.0e-9_kind_phys, & - 287.0e-9_kind_phys, & - 291.0e-9_kind_phys, & - 295.0e-9_kind_phys, & - 298.5e-9_kind_phys, & - 302.5e-9_kind_phys, & - 305.5e-9_kind_phys, & - 308.5e-9_kind_phys, & - 311.5e-9_kind_phys, & - 314.5e-9_kind_phys, & - 317.5e-9_kind_phys, & - 322.5e-9_kind_phys, & - 327.5e-9_kind_phys, & - 332.5e-9_kind_phys, & - 337.5e-9_kind_phys, & - 342.5e-9_kind_phys, & - 347.5e-9_kind_phys, & - 350.0e-9_kind_phys, & - 355.0e-9_kind_phys, & - 360.0e-9_kind_phys, & - 365.0e-9_kind_phys, & - 370.0e-9_kind_phys, & - 375.0e-9_kind_phys, & - 380.0e-9_kind_phys, & - 385.0e-9_kind_phys, & - 390.0e-9_kind_phys, & - 395.0e-9_kind_phys, & - 400.0e-9_kind_phys, & - 405.0e-9_kind_phys, & - 410.0e-9_kind_phys, & - 415.0e-9_kind_phys, & - 420.0e-9_kind_phys, & - 430.0e-9_kind_phys, & - 440.0e-9_kind_phys, & - 450.0e-9_kind_phys, & - 500.0e-9_kind_phys, & - 550.0e-9_kind_phys, & - 600.0e-9_kind_phys, & - 650.0e-9_kind_phys, & - 700.0e-9_kind_phys, & - 750.0e-9_kind_phys & - /) - - end subroutine musica_ccpp_dependencies_init - -end module musica_ccpp_dependencies + + write(log_file_unit,*) ' [JG] Calling initialize_musica_species_constituents.' + call initialize_musica_species_constituents() + + write(log_file_unit,*) 'WARNING: Using placeholder data for MUSICA chemistry.' + + allocate(photolysis_wavelength_grid_interfaces(photolysis_wavelength_grid_interface_dimension), & + stat=error_code) + call check_allocate(error_code, subroutine_name, & + 'photolysis_wavelength_grid_interfaces(photolysis_wavelength_grid_interface_dimension)', & + file=__FILE__, line=__LINE__) + allocate(extraterrestrial_radiation_flux(photolysis_wavelength_grid_section_dimension), & + stat=error_code) + call check_allocate(error_code, subroutine_name, & + 'extraterrestrial_radiation_flux(photolysis_wavelength_grid_section_dimension)', & + file=__FILE__, line=__LINE__) + allocate(surface_albedo(horizontal_dimension), stat=error_code) + call check_allocate(error_code, subroutine_name, & + 'surface_albedo(horizontal_dimension)', & + file=__FILE__, line=__LINE__) + allocate(blackbody_temperature_at_surface(horizontal_dimension), stat=error_code) + call check_allocate(error_code, subroutine_name, & + 'blackbody_temperature_at_surface(horizontal_dimension)', & + file=__FILE__, line=__LINE__) + + surface_albedo(:) = 0.1_kind_phys + blackbody_temperature_at_surface(:) = 292.3_kind_phys + extraterrestrial_radiation_flux(:) = 1.0e14_kind_phys + photolysis_wavelength_grid_interfaces = (/ & + 120.0e-9_kind_phys, & + 121.4e-9_kind_phys, & + 121.9e-9_kind_phys, & + 123.5e-9_kind_phys, & + 124.3e-9_kind_phys, & + 125.5e-9_kind_phys, & + 126.3e-9_kind_phys, & + 127.1e-9_kind_phys, & + 130.1e-9_kind_phys, & + 131.1e-9_kind_phys, & + 135.0e-9_kind_phys, & + 140.0e-9_kind_phys, & + 145.0e-9_kind_phys, & + 150.0e-9_kind_phys, & + 155.0e-9_kind_phys, & + 160.0e-9_kind_phys, & + 165.0e-9_kind_phys, & + 168.0e-9_kind_phys, & + 171.0e-9_kind_phys, & + 173.0e-9_kind_phys, & + 174.4e-9_kind_phys, & + 175.4e-9_kind_phys, & + 177.0e-9_kind_phys, & + 178.6e-9_kind_phys, & + 180.2e-9_kind_phys, & + 181.8e-9_kind_phys, & + 183.5e-9_kind_phys, & + 185.2e-9_kind_phys, & + 186.9e-9_kind_phys, & + 188.7e-9_kind_phys, & + 190.5e-9_kind_phys, & + 192.3e-9_kind_phys, & + 194.2e-9_kind_phys, & + 196.1e-9_kind_phys, & + 198.0e-9_kind_phys, & + 200.0e-9_kind_phys, & + 202.0e-9_kind_phys, & + 204.1e-9_kind_phys, & + 206.2e-9_kind_phys, & + 208.0e-9_kind_phys, & + 211.0e-9_kind_phys, & + 214.0e-9_kind_phys, & + 217.0e-9_kind_phys, & + 220.0e-9_kind_phys, & + 223.0e-9_kind_phys, & + 226.0e-9_kind_phys, & + 229.0e-9_kind_phys, & + 232.0e-9_kind_phys, & + 235.0e-9_kind_phys, & + 238.0e-9_kind_phys, & + 241.0e-9_kind_phys, & + 244.0e-9_kind_phys, & + 247.0e-9_kind_phys, & + 250.0e-9_kind_phys, & + 253.0e-9_kind_phys, & + 256.0e-9_kind_phys, & + 259.0e-9_kind_phys, & + 263.0e-9_kind_phys, & + 267.0e-9_kind_phys, & + 271.0e-9_kind_phys, & + 275.0e-9_kind_phys, & + 279.0e-9_kind_phys, & + 283.0e-9_kind_phys, & + 287.0e-9_kind_phys, & + 291.0e-9_kind_phys, & + 295.0e-9_kind_phys, & + 298.5e-9_kind_phys, & + 302.5e-9_kind_phys, & + 305.5e-9_kind_phys, & + 308.5e-9_kind_phys, & + 311.5e-9_kind_phys, & + 314.5e-9_kind_phys, & + 317.5e-9_kind_phys, & + 322.5e-9_kind_phys, & + 327.5e-9_kind_phys, & + 332.5e-9_kind_phys, & + 337.5e-9_kind_phys, & + 342.5e-9_kind_phys, & + 347.5e-9_kind_phys, & + 350.0e-9_kind_phys, & + 355.0e-9_kind_phys, & + 360.0e-9_kind_phys, & + 365.0e-9_kind_phys, & + 370.0e-9_kind_phys, & + 375.0e-9_kind_phys, & + 380.0e-9_kind_phys, & + 385.0e-9_kind_phys, & + 390.0e-9_kind_phys, & + 395.0e-9_kind_phys, & + 400.0e-9_kind_phys, & + 405.0e-9_kind_phys, & + 410.0e-9_kind_phys, & + 415.0e-9_kind_phys, & + 420.0e-9_kind_phys, & + 430.0e-9_kind_phys, & + 440.0e-9_kind_phys, & + 450.0e-9_kind_phys, & + 500.0e-9_kind_phys, & + 550.0e-9_kind_phys, & + 600.0e-9_kind_phys, & + 650.0e-9_kind_phys, & + 700.0e-9_kind_phys, & + 750.0e-9_kind_phys & + /) + + end subroutine musica_ccpp_dependencies_init + + end module musica_ccpp_dependencies + \ No newline at end of file From 10b4baa9407bc90d46febaaa6efeb48032e0d3a2 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Tue, 18 Mar 2025 15:58:16 -0600 Subject: [PATCH 08/32] temp --- .../utils/musica_ccpp_dependencies.F90 | 51 +++++++++++++------ 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/src/physics/utils/musica_ccpp_dependencies.F90 b/src/physics/utils/musica_ccpp_dependencies.F90 index 72c9fcff2..79ace1752 100644 --- a/src/physics/utils/musica_ccpp_dependencies.F90 +++ b/src/physics/utils/musica_ccpp_dependencies.F90 @@ -60,14 +60,17 @@ function species_constructor(name, value) result( this ) end function species_constructor !> Constructor for temporary musica species object - subroutine initialize_musica_species_constituents() - use cam_ccpp_cap, only: cam_model_const_properties - use cam_ccpp_cap, only: cam_constituents_array + subroutine initialize_musica_species_constituents(& + constituents_properties, constituents_array) use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t use ccpp_const_utils, only: ccpp_const_get_idx use musica_ccpp_namelist, only: filename_of_micm_configuration - use phys_vars_init_check, only: mark_as_initialized + ! use phys_vars_init_check, only: mark_as_initialized + use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t + type(ccpp_constituent_prop_ptr_t), pointer :: constituents_properties(:) + real(kind_phys), pointer :: constituents_array(:,:,:) + character(len=*), parameter :: chapman_config = 'chapman' character(len=*), parameter :: terminator_config = 'terminator' logical :: is_chapman = .false. @@ -81,13 +84,13 @@ subroutine initialize_musica_species_constituents() character(len=512) :: errmsg integer :: i_elem - real(kind_phys), pointer :: constituent_array(:,:,:) - type(ccpp_constituent_prop_ptr_t), pointer :: constituent_props(:) type(temp_musica_species_t), allocatable :: species_group(:) - constituent_array => cam_constituents_array() - constituent_props => cam_model_const_properties() - + if (.not. associated(constituents_properties)) then + write(iulog,*) " [JW] .not. associated(constituent_properties) " + return + end if + ! Check if the substring exists position = index(filename_of_micm_configuration, chapman_config) @@ -135,18 +138,25 @@ subroutine initialize_musica_species_constituents() do i_elem = 1, num_micm_species + num_tuvx_constituents + num_tuvx_only_gas_species write(iulog,*) " [JW] Calling ccpp_const_get_idx " - call ccpp_const_get_idx(constituent_props, trim(species_group(i_elem)%name), & + call ccpp_const_get_idx(constituents_properties, trim(species_group(i_elem)%name), & constituent_index, errmsg, errcode) - call mark_as_initialized(trim(species_group(i_elem)%name)) - write(iulog,*) " [JW] constituent_index ", constituent_index + constituents_array(:,:,constituent_index) = species_group(i_elem)%constituent_value + ! call mark_as_initialized(trim(species_group(i_elem)%name)) + ! call mark_as_initialized("Cl") + ! call mark_as_initialized("Cl2") + ! call mark_as_initialized("air") + ! call mark_as_initialized("O2") + ! call mark_as_initialized("O3") + write(iulog,*) " [JW] species_group(i_elem)%name ", trim(species_group(i_elem)%name) + write(iulog,*) " [JW] constituent_index ", constituent_index + write(iulog,*) " [JW] constituent value ", species_group(i_elem)%constituent_value if (errcode /= 0) then write(iulog,*) " [JW] ccpp_const_get_idx error occurs: ", errmsg return end if - constituent_array(:,:,constituent_index) = species_group(i_elem)%constituent_value end do deallocate (species_group) @@ -154,10 +164,12 @@ end subroutine initialize_musica_species_constituents !> Constructor for temporary musica species object subroutine musica_ccpp_dependencies_init(horizontal_dimension, & - vertical_layer_dimension, log_file_unit) + vertical_layer_dimension, log_file_unit, & + cam_model_const_properties, cam_constituents_array) use cam_abortutils, only: check_allocate - + use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t + !----------------------------------------------------------------------- ! ! Initialize the MUSICA scheme dependencies. @@ -168,14 +180,21 @@ subroutine musica_ccpp_dependencies_init(horizontal_dimension, & integer, intent(in) :: vertical_layer_dimension integer, intent(in) :: log_file_unit + type(ccpp_constituent_prop_ptr_t), pointer :: cam_model_const_properties(:) + real(kind_phys), pointer :: cam_constituents_array(:,:,:) + integer :: error_code character(len=*), parameter :: subroutine_name = & trim(module_name)//':(musica_ccpp_dependencies_init)' write(log_file_unit,*) ' [JG] Calling initialize_musica_species_constituents.' - call initialize_musica_species_constituents() + call initialize_musica_species_constituents(& + cam_model_const_properties, cam_constituents_array) + write(log_file_unit,*) ' [JG] Read O2, 7 indices - cam_constituents_array.' + write(log_file_unit,*) ' [JG] ', cam_constituents_array(1,1,7) + write(log_file_unit,*) 'WARNING: Using placeholder data for MUSICA chemistry.' allocate(photolysis_wavelength_grid_interfaces(photolysis_wavelength_grid_interface_dimension), & From 0224edd21cc6d11875d157d5cf6572bb9758ac53 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Wed, 19 Mar 2025 14:33:01 -0600 Subject: [PATCH 09/32] add a function to prepend caseroot dir to the config path --- cime_config/buildlib | 65 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/cime_config/buildlib b/cime_config/buildlib index c4351af54..8170fb172 100755 --- a/cime_config/buildlib +++ b/cime_config/buildlib @@ -10,6 +10,7 @@ import filecmp import shutil import subprocess import logging +import json from cam_config import ConfigCAM # CAM's configure structure from atm_musica_config import MUSICA_CCPP_SCHEME_NAME @@ -176,7 +177,9 @@ def _build_cam(): # If MUSICA-CCPP scheme is used in a suite, download # the MUSICA configuration and build the MUSICA library if MUSICA_CCPP_SCHEME_NAME in scheme_names: - _download_musica_configuration(caseroot) + musica_config_path = _download_musica_configuration(caseroot) + _prepend_caseroot_to_config(musica_config_path, caseroot) + musica_install_path = _build_musica(caseroot) cam_linked_libs = case.get_value("CAM_LINKED_LIBS") @@ -308,7 +311,7 @@ def _build_musica(clone_dest: str) -> str: return musica_install_path ############################################################################### -def _download_musica_configuration(download_dest: str) -> None: +def _download_musica_configuration(download_dest: str) -> str: ############################################################################### """ Downloads the MUSICA configuration and renames the configuration @@ -321,6 +324,8 @@ def _download_musica_configuration(download_dest: str) -> None: Exception: If the directory to be renamed is not found or any other exceptions occur during the renaming process, an exception is raised with the error message. + Returns: + musica_config_path: path to the MUSICA configuration directory """ musica_config_dir_name = "musica_configurations" @@ -345,6 +350,8 @@ def _download_musica_configuration(download_dest: str) -> None: shutil.move(renamed_dir, download_dest) + return musica_config_path + ############################################################################### def _set_musica_lib_path(musica_install_path: str, caseroot: str) -> None: ############################################################################### @@ -426,6 +433,60 @@ def _clone_and_checkout(repo_url: str, tag_name: str, clone_dest: str) -> None: except OSError as e: raise OSError("An error occurred while executing the 'git' command.") from e +############################################################################### +def _prepend_caseroot_to_config(musica_config_path: str, caseroot: str) -> None: +############################################################################### + """ + Prepends the $CASEROOT path to the TUV-x data file path to make it an absolute path + + Args: + musica_config_path: path to the MUSICA configuration directory + caseroot: $CASEROOT path + """ + entries = os.listdir(musica_config_path) + directories = [entry for entry in entries if os.path.isdir(os.path.join(musica_config_path, entry))] + + for directory in directories: + tuvx_config = os.path.join(musica_config_path, directory, "tuvx/config.json") + tuvx_config_original = os.path.join(musica_config_path, directory, "tuvx/config_original.json") + + with open(tuvx_config, 'r') as infile: + data = json.load(infile) + + modified_data = _modify_json_values(data, caseroot) + + shutil.move(tuvx_config, tuvx_config_original) + + with open(tuvx_config, 'w') as outfile: + json.dump(modified_data, outfile, indent=4) + +############################################################################### +def _modify_json_values(data, caseroot: str): +############################################################################### + """ + Recursively traverses the JSON data to update the value by prepending the + $CASEROOT path to the file path + + Args: + data: Python dictionary, list or string + caseroot: $CASEROOT path + + Returns: + data: the modified value if "musica_configurations" is found, + otherwise, the value remains unchanged + """ + if isinstance(data, dict): + for key, value in data.items(): + data[key] = _modify_json_values(value, caseroot) + elif isinstance(data, list): + for i in range(len(data)): + data[i] = _modify_json_values(data[i], caseroot) + elif isinstance(data, str): + if "musica_configurations" in data: + return os.path.join(caseroot, data) + + return data + ############################################################################### if __name__ == "__main__": From f0f58f9302a3adaf4231e417083c1d2ebc8d60bf Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Wed, 19 Mar 2025 17:06:29 -0600 Subject: [PATCH 10/32] code cleanup for musica ccpp dependeniceS --- cime_config/buildlib | 2 +- .../utils/musica_ccpp_dependencies.F90 | 127 ++++++++---------- 2 files changed, 57 insertions(+), 72 deletions(-) diff --git a/cime_config/buildlib b/cime_config/buildlib index 8170fb172..50e4e7f6c 100755 --- a/cime_config/buildlib +++ b/cime_config/buildlib @@ -455,7 +455,7 @@ def _prepend_caseroot_to_config(musica_config_path: str, caseroot: str) -> None: modified_data = _modify_json_values(data, caseroot) - shutil.move(tuvx_config, tuvx_config_original) + os.remove(tuvx_config) with open(tuvx_config, 'w') as outfile: json.dump(modified_data, outfile, indent=4) diff --git a/src/physics/utils/musica_ccpp_dependencies.F90 b/src/physics/utils/musica_ccpp_dependencies.F90 index 79ace1752..9392c840f 100644 --- a/src/physics/utils/musica_ccpp_dependencies.F90 +++ b/src/physics/utils/musica_ccpp_dependencies.F90 @@ -1,4 +1,4 @@ -! Copyright (C) 2024 National Science Foundation-National Center for Atmospheric Research +! Copyright (C) 2024-2025 National Science Foundation-National Center for Atmospheric Research ! SPDX-License-Identifier: Apache-2.0 module musica_ccpp_dependencies !-------------------------------------------------------------------------- @@ -14,7 +14,6 @@ module musica_ccpp_dependencies !-------------------------------------------------------------------------- use ccpp_kinds, only: kind_phys - use cam_logfile, only: iulog implicit none private @@ -34,10 +33,11 @@ module musica_ccpp_dependencies ! local parameters character(len=*), parameter :: module_name = '(musica_ccpp_dependencies)' - !> Definition of musica species object + !> Definition of temporary MUSICA species object + !! Use the CAM-SIMA unit (kg kg-1) to avoid unit converison type, private :: temp_musica_species_t character(len=:), allocatable :: name - real(kind_phys) :: constituent_value = 0.0_kind_phys + real(kind_phys) :: constituent_value = 0.0_kind_phys ! kg kg-1 end type temp_musica_species_t interface temp_musica_species_t @@ -48,7 +48,7 @@ module musica_ccpp_dependencies contains !============================================================================== - !> Constructor for temporary musica species object + !> Constructor for temporary MUSICA species object function species_constructor(name, value) result( this ) character(len=*), intent(in) :: name real(kind_phys), intent(in) :: value @@ -59,51 +59,49 @@ function species_constructor(name, value) result( this ) end function species_constructor - !> Constructor for temporary musica species object - subroutine initialize_musica_species_constituents(& - constituents_properties, constituents_array) + !> Initialize MUSICA species constituents + subroutine initialize_musica_species_constituents(constituents_properties, & + constituents_array) use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t use ccpp_const_utils, only: ccpp_const_get_idx + use cam_logfile, only: iulog use musica_ccpp_namelist, only: filename_of_micm_configuration - ! use phys_vars_init_check, only: mark_as_initialized - use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t - type(ccpp_constituent_prop_ptr_t), pointer :: constituents_properties(:) - real(kind_phys), pointer :: constituents_array(:,:,:) - - character(len=*), parameter :: chapman_config = 'chapman' - character(len=*), parameter :: terminator_config = 'terminator' - logical :: is_chapman = .false. - logical :: is_terminator = .false. - integer :: num_micm_species = 0 - integer :: num_tuvx_constituents = 1 - integer :: num_tuvx_only_gas_species = 0 - integer :: position - integer :: constituent_index - integer :: errcode - character(len=512) :: errmsg - integer :: i_elem - - type(temp_musica_species_t), allocatable :: species_group(:) + type(ccpp_constituent_prop_ptr_t), pointer :: constituents_properties(:) + real(kind_phys), pointer :: constituents_array(:,:,:) + + ! local variables + type(temp_musica_species_t), allocatable :: species_group(:) + character(len=*), parameter :: chapman_config = 'chapman' + character(len=*), parameter :: terminator_config = 'terminator' + logical :: is_chapman = .false. + logical :: is_terminator = .false. + integer :: num_micm_species = 0 + integer :: num_tuvx_constituents = 1 + integer :: num_tuvx_only_gas_species = 0 + integer :: errcode + character(len=512) :: errmsg + integer :: position + integer :: constituent_index + integer :: i_elem if (.not. associated(constituents_properties)) then - write(iulog,*) " [JW] .not. associated(constituent_properties) " + write(iulog,*) "Error: constituents_properties is not associated." return end if ! Check if the substring exists position = index(filename_of_micm_configuration, chapman_config) - if (position > 0) then is_chapman = .true. - write(iulog,*) " [JW] Config is Chapman " + write(iulog,*) "Using the Chapman configuriation for MUSICA." else position = index(filename_of_micm_configuration, terminator_config) if (position > 0) then is_terminator = .true. - write(iulog,*) " [JW] Config is Terminator " + write(iulog,*) "Using the Terminator configuriation for MUSICA." else - write(iulog,*) " [JW] Config is not found" + write(iulog,*) "Error: the MUSICA configuration is not found." return end if end if @@ -117,57 +115,49 @@ subroutine initialize_musica_species_constituents(& end if allocate (species_group(num_micm_species + num_tuvx_constituents + num_tuvx_only_gas_species)) - ! TODO(jiwon) have to conver to cam-sima unit [mol m-3] - species_group(1) = species_constructor("cloud_liquid_water_mixing_ratio_wrt_moist_air_and_condensed_water", & - 1.0e-3_kind_phys) + + species_group(1) = species_constructor(& + "cloud_liquid_water_mixing_ratio_wrt_moist_air_and_condensed_water", 1.0e-3_kind_phys) + if (is_chapman) then species_group(2) = species_constructor("O2", 0.21_kind_phys) - species_group(3) = species_constructor("O", 1.0e-9_kind_phys) - species_group(4) = species_constructor("O1D", 1.0e-9_kind_phys) - species_group(5) = species_constructor("O3", 1.0e-4_kind_phys) + species_group(3) = species_constructor("O", 0.42_kind_phys) + species_group(4) = species_constructor("O1D", 1.0e-12_kind_phys) + species_group(5) = species_constructor("O3", 4.0e-6_kind_phys) species_group(6) = species_constructor("N2", 0.79_kind_phys) species_group(7) = species_constructor("air", 1.0e-3_kind_phys) else if (is_terminator) then - species_group(2) = species_constructor("Cl", 1.05e-4_kind_phys) - species_group(3) = species_constructor("Cl2", 1.05e-4_kind_phys) + species_group(2) = species_constructor("Cl", 1.0e-12_kind_phys) + species_group(3) = species_constructor("Cl2", 1.0e-12_kind_phys) species_group(4) = species_constructor("air", 1.0e-3_kind_phys) species_group(5) = species_constructor("O2", 0.21_kind_phys) - species_group(6) = species_constructor("O3", 1.0e-4_kind_phys) + species_group(6) = species_constructor("O3", 4.0e-6_kind_phys) end if do i_elem = 1, num_micm_species + num_tuvx_constituents + num_tuvx_only_gas_species - write(iulog,*) " [JW] Calling ccpp_const_get_idx " call ccpp_const_get_idx(constituents_properties, trim(species_group(i_elem)%name), & constituent_index, errmsg, errcode) constituents_array(:,:,constituent_index) = species_group(i_elem)%constituent_value - ! call mark_as_initialized(trim(species_group(i_elem)%name)) - ! call mark_as_initialized("Cl") - ! call mark_as_initialized("Cl2") - ! call mark_as_initialized("air") - ! call mark_as_initialized("O2") - ! call mark_as_initialized("O3") - write(iulog,*) " [JW] species_group(i_elem)%name ", trim(species_group(i_elem)%name) - write(iulog,*) " [JW] constituent_index ", constituent_index - write(iulog,*) " [JW] constituent value ", species_group(i_elem)%constituent_value if (errcode /= 0) then - write(iulog,*) " [JW] ccpp_const_get_idx error occurs: ", errmsg + write(iulog,*) "Error in finding the index for the speices ", trim(species_group(i_elem)%name) + write(iulog,*) "Error: ", errmsg return end if - end do deallocate (species_group) + end subroutine initialize_musica_species_constituents !> Constructor for temporary musica species object subroutine musica_ccpp_dependencies_init(horizontal_dimension, & vertical_layer_dimension, log_file_unit, & - cam_model_const_properties, cam_constituents_array) + constituents_properties, constituents_array) - use cam_abortutils, only: check_allocate + use cam_abortutils, only: check_allocate use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t !----------------------------------------------------------------------- @@ -176,27 +166,22 @@ subroutine musica_ccpp_dependencies_init(horizontal_dimension, & ! !----------------------------------------------------------------------- - integer, intent(in) :: horizontal_dimension - integer, intent(in) :: vertical_layer_dimension - integer, intent(in) :: log_file_unit + integer, intent(in) :: horizontal_dimension + integer, intent(in) :: vertical_layer_dimension + integer, intent(in) :: log_file_unit + type(ccpp_constituent_prop_ptr_t), pointer :: constituents_properties(:) + real(kind_phys), pointer :: constituents_array(:,:,:) - type(ccpp_constituent_prop_ptr_t), pointer :: cam_model_const_properties(:) - real(kind_phys), pointer :: cam_constituents_array(:,:,:) - - integer :: error_code + ! local variables + integer :: error_code character(len=*), parameter :: subroutine_name = & trim(module_name)//':(musica_ccpp_dependencies_init)' - - write(log_file_unit,*) ' [JG] Calling initialize_musica_species_constituents.' - call initialize_musica_species_constituents(& - cam_model_const_properties, cam_constituents_array) - - write(log_file_unit,*) ' [JG] Read O2, 7 indices - cam_constituents_array.' - write(log_file_unit,*) ' [JG] ', cam_constituents_array(1,1,7) - write(log_file_unit,*) 'WARNING: Using placeholder data for MUSICA chemistry.' - + + call initialize_musica_species_constituents(constituents_properties, & + constituents_array) + allocate(photolysis_wavelength_grid_interfaces(photolysis_wavelength_grid_interface_dimension), & stat=error_code) call check_allocate(error_code, subroutine_name, & From 31e46f23305107ac9e2a3aa8a86a2b1653695a2e Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Wed, 19 Mar 2025 17:18:04 -0600 Subject: [PATCH 11/32] update cam_comp to initialize musica species --- src/control/cam_comp.F90 | 52 +++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/src/control/cam_comp.F90 b/src/control/cam_comp.F90 index 8ed03e08c..bdeb24f4f 100644 --- a/src/control/cam_comp.F90 +++ b/src/control/cam_comp.F90 @@ -84,27 +84,29 @@ subroutine cam_init(caseid, ctitle, model_doi_url, & ! !----------------------------------------------------------------------- - use cam_initfiles, only: cam_initfiles_open - use dyn_grid, only: model_grid_init - use phys_comp, only: phys_init - use phys_comp, only: phys_register - use dyn_comp, only: dyn_init -! use cam_restart, only: cam_read_restart - use camsrfexch, only: hub2atm_alloc, atm2hub_alloc - use cam_history, only: history_init_files -! use history_scam, only: scm_intht - use cam_pio_utils, only: init_pio_subsystem - use cam_instance, only: inst_suffix -! use history_defaults, only: initialize_iop_history - use stepon, only: stepon_init - use air_composition, only: air_composition_init - use cam_ccpp_cap, only: cam_ccpp_initialize_constituents - use physics_grid, only: columns_on_task - use vert_coord, only: pver - use phys_vars_init_check, only: mark_as_initialized - use tropopause_climo_read, only: tropopause_climo_read_file - use musica_ccpp_dependencies, only: musica_ccpp_dependencies_init - use orbital_data, only: orbital_data_init + use cam_initfiles, only: cam_initfiles_open + use dyn_grid, only: model_grid_init + use phys_comp, only: phys_init + use phys_comp, only: phys_register + use dyn_comp, only: dyn_init +! use cam_restart, only: cam_read_restart + use camsrfexch, only: hub2atm_alloc, atm2hub_alloc + use cam_history, only: history_init_files +! use history_scam, only: scm_intht + use cam_pio_utils, only: init_pio_subsystem + use cam_instance, only: inst_suffix +! use history_defaults, only: initialize_iop_history + use stepon, only: stepon_init + use air_composition, only: air_composition_init + use cam_ccpp_cap, only: cam_ccpp_initialize_constituents + use physics_grid, only: columns_on_task + use vert_coord, only: pver + use phys_vars_init_check, only: mark_as_initialized + use tropopause_climo_read, only: tropopause_climo_read_file + use musica_ccpp_dependencies, only: musica_ccpp_dependencies_init + use orbital_data, only: orbital_data_init + use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t + use ccpp_kinds, only: kind_phys ! Arguments character(len=cl), intent(in) :: caseid ! case ID @@ -150,6 +152,9 @@ subroutine cam_init(caseid, ctitle, model_doi_url, & character(len=cs) :: filein ! Input namelist filename integer :: errflg character(len=cx) :: errmsg + + type(ccpp_constituent_prop_ptr_t), pointer :: constituent_properties(:) + real(kind_phys), pointer :: constituents_array(:,:,:) !----------------------------------------------------------------------- call init_pio_subsystem() @@ -253,7 +258,10 @@ subroutine cam_init(caseid, ctitle, model_doi_url, & ! ! Remove this when MUSICA input data are available from CAM-SIMA or ! other physics schemes. - call musica_ccpp_dependencies_init(columns_on_task, pver, iulog) + constituent_properties => cam_model_const_properties() + constituents_array => cam_constituents_array() + call musica_ccpp_dependencies_init(columns_on_task, pver, iulog, & + constituent_properties, constituents_array) ! Initialize orbital data call orbital_data_init(columns_on_task) From 2cacf106450d624644966bbf71e6da7d76cfd069 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Wed, 19 Mar 2025 17:50:18 -0600 Subject: [PATCH 12/32] update cam sima data repo commit --- cime_config/atm_musica_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cime_config/atm_musica_config.py b/cime_config/atm_musica_config.py index e63831d1d..8dbd04635 100644 --- a/cime_config/atm_musica_config.py +++ b/cime_config/atm_musica_config.py @@ -7,4 +7,4 @@ MUSICA_REPO_URL = "https://github.com/NCAR/musica.git" MUSICA_TAG = "cc39bb00d2220fc81c85b22d3ceea4a39bd2bacf" CHEMISTRY_DATA_REPO_URL = "https://github.com/NCAR/cam-sima-chemistry-data.git" -CHEMISTRY_DATA_TAG = "b575c8232b85ab99e810274e5e1e9fce97d84bc2" # temp +CHEMISTRY_DATA_TAG = "cb57c11dd72de2b116157123e4f8d76ffeae21af" # temp From 9480ac45f4ed3508b773749ff84df24969602ddd Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Wed, 19 Mar 2025 18:06:55 -0600 Subject: [PATCH 13/32] add missing include --- src/control/cam_comp.F90 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/control/cam_comp.F90 b/src/control/cam_comp.F90 index bdeb24f4f..96efb0d5d 100644 --- a/src/control/cam_comp.F90 +++ b/src/control/cam_comp.F90 @@ -99,6 +99,8 @@ subroutine cam_init(caseid, ctitle, model_doi_url, & use stepon, only: stepon_init use air_composition, only: air_composition_init use cam_ccpp_cap, only: cam_ccpp_initialize_constituents + use cam_ccpp_cap, only: cam_model_const_properties + use cam_ccpp_cap, only: cam_constituents_array use physics_grid, only: columns_on_task use vert_coord, only: pver use phys_vars_init_check, only: mark_as_initialized From b8e6c78feae6dfaa3382eb9aaeeecb267679ea04 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Fri, 21 Mar 2025 17:30:19 -0600 Subject: [PATCH 14/32] copy musica config to run dir --- cime_config/atm_musica_config.py | 1 + cime_config/buildlib | 65 ++------------------------------ cime_config/buildnml | 19 +++++++++- 3 files changed, 22 insertions(+), 63 deletions(-) diff --git a/cime_config/atm_musica_config.py b/cime_config/atm_musica_config.py index 8dbd04635..1210ab2e1 100644 --- a/cime_config/atm_musica_config.py +++ b/cime_config/atm_musica_config.py @@ -4,6 +4,7 @@ """ MUSICA_CCPP_SCHEME_NAME = "musica_ccpp" +MUSICA_CONFIG_DIR_NAME = "musica_configurations" MUSICA_REPO_URL = "https://github.com/NCAR/musica.git" MUSICA_TAG = "cc39bb00d2220fc81c85b22d3ceea4a39bd2bacf" CHEMISTRY_DATA_REPO_URL = "https://github.com/NCAR/cam-sima-chemistry-data.git" diff --git a/cime_config/buildlib b/cime_config/buildlib index 50e4e7f6c..c0648130c 100755 --- a/cime_config/buildlib +++ b/cime_config/buildlib @@ -13,7 +13,7 @@ import logging import json from cam_config import ConfigCAM # CAM's configure structure -from atm_musica_config import MUSICA_CCPP_SCHEME_NAME +from atm_musica_config import MUSICA_CCPP_SCHEME_NAME, MUSICA_CONFIG_DIR_NAME from atm_musica_config import MUSICA_REPO_URL, MUSICA_TAG from atm_musica_config import CHEMISTRY_DATA_REPO_URL, CHEMISTRY_DATA_TAG @@ -177,9 +177,7 @@ def _build_cam(): # If MUSICA-CCPP scheme is used in a suite, download # the MUSICA configuration and build the MUSICA library if MUSICA_CCPP_SCHEME_NAME in scheme_names: - musica_config_path = _download_musica_configuration(caseroot) - _prepend_caseroot_to_config(musica_config_path, caseroot) - + _ = _download_musica_configuration(caseroot) musica_install_path = _build_musica(caseroot) cam_linked_libs = case.get_value("CAM_LINKED_LIBS") @@ -327,12 +325,11 @@ def _download_musica_configuration(download_dest: str) -> str: Returns: musica_config_path: path to the MUSICA configuration directory """ - musica_config_dir_name = "musica_configurations" _clone_and_checkout(CHEMISTRY_DATA_REPO_URL, CHEMISTRY_DATA_TAG, download_dest) original_dir = os.path.join(download_dest, "cam-sima-chemistry-data", "mechanisms") - renamed_dir = os.path.join(download_dest, "cam-sima-chemistry-data", musica_config_dir_name) + renamed_dir = os.path.join(download_dest, "cam-sima-chemistry-data", MUSICA_CONFIG_DIR_NAME) try: os.rename(original_dir, renamed_dir) except FileNotFoundError as e: @@ -344,7 +341,7 @@ def _download_musica_configuration(download_dest: str) -> str: except OSError as e: raise OSError("An error occurred while renaming.") from e - musica_config_path = os.path.join(download_dest, musica_config_dir_name) + musica_config_path = os.path.join(download_dest, MUSICA_CONFIG_DIR_NAME) if os.path.exists(musica_config_path): shutil.rmtree(musica_config_path) @@ -433,60 +430,6 @@ def _clone_and_checkout(repo_url: str, tag_name: str, clone_dest: str) -> None: except OSError as e: raise OSError("An error occurred while executing the 'git' command.") from e -############################################################################### -def _prepend_caseroot_to_config(musica_config_path: str, caseroot: str) -> None: -############################################################################### - """ - Prepends the $CASEROOT path to the TUV-x data file path to make it an absolute path - - Args: - musica_config_path: path to the MUSICA configuration directory - caseroot: $CASEROOT path - """ - entries = os.listdir(musica_config_path) - directories = [entry for entry in entries if os.path.isdir(os.path.join(musica_config_path, entry))] - - for directory in directories: - tuvx_config = os.path.join(musica_config_path, directory, "tuvx/config.json") - tuvx_config_original = os.path.join(musica_config_path, directory, "tuvx/config_original.json") - - with open(tuvx_config, 'r') as infile: - data = json.load(infile) - - modified_data = _modify_json_values(data, caseroot) - - os.remove(tuvx_config) - - with open(tuvx_config, 'w') as outfile: - json.dump(modified_data, outfile, indent=4) - -############################################################################### -def _modify_json_values(data, caseroot: str): -############################################################################### - """ - Recursively traverses the JSON data to update the value by prepending the - $CASEROOT path to the file path - - Args: - data: Python dictionary, list or string - caseroot: $CASEROOT path - - Returns: - data: the modified value if "musica_configurations" is found, - otherwise, the value remains unchanged - """ - if isinstance(data, dict): - for key, value in data.items(): - data[key] = _modify_json_values(value, caseroot) - elif isinstance(data, list): - for i in range(len(data)): - data[i] = _modify_json_values(data[i], caseroot) - elif isinstance(data, str): - if "musica_configurations" in data: - return os.path.join(caseroot, data) - - return data - ############################################################################### if __name__ == "__main__": diff --git a/cime_config/buildnml b/cime_config/buildnml index 32aa01a2a..12a905241 100755 --- a/cime_config/buildnml +++ b/cime_config/buildnml @@ -35,8 +35,10 @@ from cam_config import ConfigCAM # HistoryConfig allows translation from user_nl_cam into Fortran namelists from hist_config import HistoryConfig -#Import CAM's ParamGen class: +# Import CAM's ParamGen class: from atm_in_paramgen import AtmInParamGen +# Import specific names associated with the MUSICA scheme +from atm_musica_config import MUSICA_CCPP_SCHEME_NAME, MUSICA_CONFIG_DIR_NAME # Open CIME case log: _LOGGER = logging.getLogger(__name__) @@ -166,7 +168,7 @@ def buildnml(case, caseroot, compname): gen_indent = 3 #Generate model code and meta-data: - _ = config.generate_cam_src(gen_indent) + scheme_names = config.generate_cam_src(gen_indent) #---------------------------------------------------------------- # Create namelist attribute dictionary (to set namelist defaults): @@ -376,6 +378,19 @@ def buildnml(case, caseroot, compname): # end for # end with + # If MUSICA-CCPP scheme is used in a suite, copy the MUSICA + # configuration data to the run directory + if MUSICA_CCPP_SCHEME_NAME in scheme_names: + musica_config_src_dir = os.path.join(caseroot, MUSICA_CONFIG_DIR_NAME) + musica_config_dest_dir = os.path.join(rundir, MUSICA_CONFIG_DIR_NAME) + + if not os.path.exists(musica_config_src_dir): + emsg = f"The directory '{MUSICA_CONFIG_DIR_NAME}' doesn't exit. The directory \ + must be located in the caseroot if the ATM library build is successful." + raise CamBuildnmlError(emsg) + + shutil.copytree(musica_config_src_dir, musica_config_dest_dir, + dirs_exist_ok=False) ############################################################################### def _main_func(): From e64467d92d9ff1583a52f564ec5af18229f9ca40 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Fri, 21 Mar 2025 18:42:27 -0600 Subject: [PATCH 15/32] replace copy with symlinks --- cime_config/buildnml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/cime_config/buildnml b/cime_config/buildnml index 12a905241..c87031a40 100755 --- a/cime_config/buildnml +++ b/cime_config/buildnml @@ -22,7 +22,7 @@ from CIME.Tools.standard_script_setup import * from CIME.XML.standard_module_setup import * from CIME.buildnml import create_namelist_infile, parse_input from CIME.case import Case -from CIME.utils import expect +from CIME.utils import expect, symlink_force # Save local (cime_config) directory path: _CIME_CONFIG_PATH = os.path.dirname(os.path.abspath(__file__)) @@ -378,8 +378,8 @@ def buildnml(case, caseroot, compname): # end for # end with - # If MUSICA-CCPP scheme is used in a suite, copy the MUSICA - # configuration data to the run directory + # If MUSICA-CCPP scheme is used in a suite, create symlinks in the run + # directory pointing to the MUSICA configuration data in the caseroot if MUSICA_CCPP_SCHEME_NAME in scheme_names: musica_config_src_dir = os.path.join(caseroot, MUSICA_CONFIG_DIR_NAME) musica_config_dest_dir = os.path.join(rundir, MUSICA_CONFIG_DIR_NAME) @@ -389,8 +389,14 @@ def buildnml(case, caseroot, compname): must be located in the caseroot if the ATM library build is successful." raise CamBuildnmlError(emsg) - shutil.copytree(musica_config_src_dir, musica_config_dest_dir, - dirs_exist_ok=False) + os.makedirs(musica_config_dest_dir, exist_ok=True) + for root, _, files in os.walk(musica_config_src_dir): + rel_path = os.path.relpath(root, musica_config_src_dir) + dest_dir = os.path.join(musica_config_dest_dir, rel_path) + + os.makedirs(dest_dir, exist_ok=True) + for file in files: + symlink_force(os.path.join(root, file), os.path.join(dest_dir, file)) ############################################################################### def _main_func(): From 4cbb326db260a5ed7d99cdbf30ef684e674c0344 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Fri, 21 Mar 2025 18:55:11 -0600 Subject: [PATCH 16/32] add comment to check with Jesse --- cime_config/buildnml | 1 + 1 file changed, 1 insertion(+) diff --git a/cime_config/buildnml b/cime_config/buildnml index c87031a40..aa43a5fcd 100755 --- a/cime_config/buildnml +++ b/cime_config/buildnml @@ -389,6 +389,7 @@ def buildnml(case, caseroot, compname): must be located in the caseroot if the ATM library build is successful." raise CamBuildnmlError(emsg) + # TODO(JIWON) Check with Jesse if we want to check directory exists os.makedirs(musica_config_dest_dir, exist_ok=True) for root, _, files in os.walk(musica_config_src_dir): rel_path = os.path.relpath(root, musica_config_src_dir) From e1d8031bb0c91c971f2c42acdcb3ae9e410564d1 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Mon, 24 Mar 2025 11:41:16 -0600 Subject: [PATCH 17/32] check symlink exists --- cime_config/atm_musica_config.py | 2 +- cime_config/buildnml | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cime_config/atm_musica_config.py b/cime_config/atm_musica_config.py index 1210ab2e1..5fa6e35ca 100644 --- a/cime_config/atm_musica_config.py +++ b/cime_config/atm_musica_config.py @@ -8,4 +8,4 @@ MUSICA_REPO_URL = "https://github.com/NCAR/musica.git" MUSICA_TAG = "cc39bb00d2220fc81c85b22d3ceea4a39bd2bacf" CHEMISTRY_DATA_REPO_URL = "https://github.com/NCAR/cam-sima-chemistry-data.git" -CHEMISTRY_DATA_TAG = "cb57c11dd72de2b116157123e4f8d76ffeae21af" # temp +CHEMISTRY_DATA_TAG = "71ed143c54b0d5d6e3e70f3d05d413fddcf8d59e" # temp diff --git a/cime_config/buildnml b/cime_config/buildnml index aa43a5fcd..ae423127d 100755 --- a/cime_config/buildnml +++ b/cime_config/buildnml @@ -379,7 +379,7 @@ def buildnml(case, caseroot, compname): # end with # If MUSICA-CCPP scheme is used in a suite, create symlinks in the run - # directory pointing to the MUSICA configuration data in the caseroot + # directory pointing to the MUSICA configuration data located in the caseroot if MUSICA_CCPP_SCHEME_NAME in scheme_names: musica_config_src_dir = os.path.join(caseroot, MUSICA_CONFIG_DIR_NAME) musica_config_dest_dir = os.path.join(rundir, MUSICA_CONFIG_DIR_NAME) @@ -389,15 +389,15 @@ def buildnml(case, caseroot, compname): must be located in the caseroot if the ATM library build is successful." raise CamBuildnmlError(emsg) - # TODO(JIWON) Check with Jesse if we want to check directory exists - os.makedirs(musica_config_dest_dir, exist_ok=True) - for root, _, files in os.walk(musica_config_src_dir): - rel_path = os.path.relpath(root, musica_config_src_dir) - dest_dir = os.path.join(musica_config_dest_dir, rel_path) + if not os.path.exists(musica_config_dest_dir): + os.makedirs(musica_config_dest_dir, exist_ok=False) + for root, _, files in os.walk(musica_config_src_dir): + rel_path = os.path.relpath(root, musica_config_src_dir) + dest_dir = os.path.join(musica_config_dest_dir, rel_path) - os.makedirs(dest_dir, exist_ok=True) - for file in files: - symlink_force(os.path.join(root, file), os.path.join(dest_dir, file)) + os.makedirs(dest_dir, exist_ok=False) + for file in files: + symlink_force(os.path.join(root, file), os.path.join(dest_dir, file)) ############################################################################### def _main_func(): From 845ed02a5604749ec8c9ce6f2361e51f2d53bd63 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Wed, 26 Mar 2025 17:02:11 -0600 Subject: [PATCH 18/32] update the tag for musica data --- cime_config/atm_musica_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cime_config/atm_musica_config.py b/cime_config/atm_musica_config.py index 5fa6e35ca..464d3f97e 100644 --- a/cime_config/atm_musica_config.py +++ b/cime_config/atm_musica_config.py @@ -8,4 +8,4 @@ MUSICA_REPO_URL = "https://github.com/NCAR/musica.git" MUSICA_TAG = "cc39bb00d2220fc81c85b22d3ceea4a39bd2bacf" CHEMISTRY_DATA_REPO_URL = "https://github.com/NCAR/cam-sima-chemistry-data.git" -CHEMISTRY_DATA_TAG = "71ed143c54b0d5d6e3e70f3d05d413fddcf8d59e" # temp +CHEMISTRY_DATA_TAG = "71ed143c54b0d5d6e3e70f3d05d413fddcf8d59e" From 11c081a9e145f072d01fcfaf99dd8d6f313ab17d Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Thu, 27 Mar 2025 12:44:13 -0600 Subject: [PATCH 19/32] code cleanup --- src/control/cam_comp.F90 | 10 +- .../utils/musica_ccpp_dependencies.F90 | 107 ++++++++++-------- src/physics/utils/orbital_data.F90 | 2 +- 3 files changed, 68 insertions(+), 51 deletions(-) diff --git a/src/control/cam_comp.F90 b/src/control/cam_comp.F90 index 96efb0d5d..9c68a7139 100644 --- a/src/control/cam_comp.F90 +++ b/src/control/cam_comp.F90 @@ -105,10 +105,10 @@ subroutine cam_init(caseid, ctitle, model_doi_url, & use vert_coord, only: pver use phys_vars_init_check, only: mark_as_initialized use tropopause_climo_read, only: tropopause_climo_read_file - use musica_ccpp_dependencies, only: musica_ccpp_dependencies_init use orbital_data, only: orbital_data_init - use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t use ccpp_kinds, only: kind_phys + use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t + use musica_ccpp_dependencies, only: musica_ccpp_dependencies_init ! Arguments character(len=cl), intent(in) :: caseid ! case ID @@ -257,13 +257,15 @@ subroutine cam_init(caseid, ctitle, model_doi_url, & ! Temporary: Prescribe realistic but inaccurate physical quantities ! necessary for MUSICA that are currently unavailable in CAM-SIMA. + ! It also initializes the MUSICA constituent values until the file + ! I/O object is implemented. ! ! Remove this when MUSICA input data are available from CAM-SIMA or ! other physics schemes. constituent_properties => cam_model_const_properties() constituents_array => cam_constituents_array() - call musica_ccpp_dependencies_init(columns_on_task, pver, iulog, & - constituent_properties, constituents_array) + call musica_ccpp_dependencies_init(columns_on_task, pver, & + constituent_properties, constituents_array) ! Initialize orbital data call orbital_data_init(columns_on_task) diff --git a/src/physics/utils/musica_ccpp_dependencies.F90 b/src/physics/utils/musica_ccpp_dependencies.F90 index 9392c840f..6cc06ae9d 100644 --- a/src/physics/utils/musica_ccpp_dependencies.F90 +++ b/src/physics/utils/musica_ccpp_dependencies.F90 @@ -17,7 +17,7 @@ module musica_ccpp_dependencies implicit none private - + public :: musica_ccpp_dependencies_init !> \section arg_table_musica_ccpp_dependencies Argument Table @@ -34,7 +34,6 @@ module musica_ccpp_dependencies character(len=*), parameter :: module_name = '(musica_ccpp_dependencies)' !> Definition of temporary MUSICA species object - !! Use the CAM-SIMA unit (kg kg-1) to avoid unit converison type, private :: temp_musica_species_t character(len=:), allocatable :: name real(kind_phys) :: constituent_value = 0.0_kind_phys ! kg kg-1 @@ -48,20 +47,32 @@ module musica_ccpp_dependencies contains !============================================================================== - !> Constructor for temporary MUSICA species object function species_constructor(name, value) result( this ) + + !----------------------------------------------------------------------- + ! + ! Constructor for temporary MUSICA species object. + ! + !----------------------------------------------------------------------- + character(len=*), intent(in) :: name - real(kind_phys), intent(in) :: value - type(temp_musica_species_t) :: this + real(kind_phys), intent(in) :: value + type(temp_musica_species_t) :: this this%name = name this%constituent_value = value end function species_constructor - !> Initialize MUSICA species constituents subroutine initialize_musica_species_constituents(constituents_properties, & - constituents_array) + constituents_array, errmsg, errcode) + + !----------------------------------------------------------------------- + ! + ! Initialize temporary MUSICA species constituents. + ! + !----------------------------------------------------------------------- + use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t use ccpp_const_utils, only: ccpp_const_get_idx use cam_logfile, only: iulog @@ -69,6 +80,8 @@ subroutine initialize_musica_species_constituents(constituents_properties, & type(ccpp_constituent_prop_ptr_t), pointer :: constituents_properties(:) real(kind_phys), pointer :: constituents_array(:,:,:) + character(len=512), intent(out) :: errmsg + integer, intent(out) :: errcode ! local variables type(temp_musica_species_t), allocatable :: species_group(:) @@ -79,29 +92,31 @@ subroutine initialize_musica_species_constituents(constituents_properties, & integer :: num_micm_species = 0 integer :: num_tuvx_constituents = 1 integer :: num_tuvx_only_gas_species = 0 - integer :: errcode - character(len=512) :: errmsg integer :: position integer :: constituent_index - integer :: i_elem + integer :: i_species if (.not. associated(constituents_properties)) then - write(iulog,*) "Error: constituents_properties is not associated." + errcode = 1 + errmsg = "[MUSICA Error] The pointer to the constituents properties object is not associated." return end if - ! Check if the substring exists - position = index(filename_of_micm_configuration, chapman_config) + ! Currently, we only support two types of MUSICA configurations: Chapman and Terminator, + ! until the file I/O object is implemented. If the configuration is neither of these, + ! an error will be thrown. + position = index(filename_of_micm_configuration, chapman_config) ! Check if the substring exists if (position > 0) then is_chapman = .true. - write(iulog,*) "Using the Chapman configuriation for MUSICA." + write(iulog,*) "[MUSICA Info] Using the Chapman configuriation." else position = index(filename_of_micm_configuration, terminator_config) if (position > 0) then is_terminator = .true. - write(iulog,*) "Using the Terminator configuriation for MUSICA." + write(iulog,*) "[MUSICA Info] Using the Terminator configuriation." else - write(iulog,*) "Error: the MUSICA configuration is not found." + errcode = 1 + errmsg = "[MUSICA Error] MUSICA configuration is not found." return end if end if @@ -126,7 +141,6 @@ subroutine initialize_musica_species_constituents(constituents_properties, & species_group(5) = species_constructor("O3", 4.0e-6_kind_phys) species_group(6) = species_constructor("N2", 0.79_kind_phys) species_group(7) = species_constructor("air", 1.0e-3_kind_phys) - else if (is_terminator) then species_group(2) = species_constructor("Cl", 1.0e-12_kind_phys) species_group(3) = species_constructor("Cl2", 1.0e-12_kind_phys) @@ -135,29 +149,27 @@ subroutine initialize_musica_species_constituents(constituents_properties, & species_group(6) = species_constructor("O3", 4.0e-6_kind_phys) end if - do i_elem = 1, num_micm_species + num_tuvx_constituents + num_tuvx_only_gas_species - call ccpp_const_get_idx(constituents_properties, trim(species_group(i_elem)%name), & + do i_species = 1, num_micm_species + num_tuvx_constituents + num_tuvx_only_gas_species + call ccpp_const_get_idx(constituents_properties, trim(species_group(i_species)%name), & constituent_index, errmsg, errcode) - - constituents_array(:,:,constituent_index) = species_group(i_elem)%constituent_value - - if (errcode /= 0) then - write(iulog,*) "Error in finding the index for the speices ", trim(species_group(i_elem)%name) - write(iulog,*) "Error: ", errmsg + if (errcode /= 0) then + deallocate (species_group) return end if + + constituents_array(:,:,constituent_index) = species_group(i_species)%constituent_value end do deallocate (species_group) end subroutine initialize_musica_species_constituents - - !> Constructor for temporary musica species object - subroutine musica_ccpp_dependencies_init(horizontal_dimension, & - vertical_layer_dimension, log_file_unit, & - constituents_properties, constituents_array) - - use cam_abortutils, only: check_allocate + + subroutine musica_ccpp_dependencies_init( & + horizontal_dimension, vertical_layer_dimension, & + constituents_properties, constituents_array) + + use cam_abortutils, only: check_allocate, endrun + use cam_logfile, only: iulog use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t !----------------------------------------------------------------------- @@ -166,38 +178,41 @@ subroutine musica_ccpp_dependencies_init(horizontal_dimension, & ! !----------------------------------------------------------------------- - integer, intent(in) :: horizontal_dimension - integer, intent(in) :: vertical_layer_dimension - integer, intent(in) :: log_file_unit + integer, intent(in) :: horizontal_dimension + integer, intent(in) :: vertical_layer_dimension type(ccpp_constituent_prop_ptr_t), pointer :: constituents_properties(:) real(kind_phys), pointer :: constituents_array(:,:,:) ! local variables - integer :: error_code + character(len=512), :: errmsg + integer, :: errcode character(len=*), parameter :: subroutine_name = & trim(module_name)//':(musica_ccpp_dependencies_init)' - write(log_file_unit,*) 'WARNING: Using placeholder data for MUSICA chemistry.' + write(iulog,*) 'WARNING: Using placeholder data for MUSICA chemistry.' call initialize_musica_species_constituents(constituents_properties, & - constituents_array) + constituents_array, errmsg, errcode) + if (errcode /= 0) then + call endrun(errmsg, file=__FILE__, line=__LINE__) + end if allocate(photolysis_wavelength_grid_interfaces(photolysis_wavelength_grid_interface_dimension), & - stat=error_code) - call check_allocate(error_code, subroutine_name, & + stat=errcode) + call check_allocate(errcode, subroutine_name, & 'photolysis_wavelength_grid_interfaces(photolysis_wavelength_grid_interface_dimension)', & file=__FILE__, line=__LINE__) allocate(extraterrestrial_radiation_flux(photolysis_wavelength_grid_section_dimension), & - stat=error_code) - call check_allocate(error_code, subroutine_name, & + stat=errcode) + call check_allocate(errcode, subroutine_name, & 'extraterrestrial_radiation_flux(photolysis_wavelength_grid_section_dimension)', & file=__FILE__, line=__LINE__) - allocate(surface_albedo(horizontal_dimension), stat=error_code) - call check_allocate(error_code, subroutine_name, & + allocate(surface_albedo(horizontal_dimension), stat=errcode) + call check_allocate(errcode, subroutine_name, & 'surface_albedo(horizontal_dimension)', & file=__FILE__, line=__LINE__) - allocate(blackbody_temperature_at_surface(horizontal_dimension), stat=error_code) - call check_allocate(error_code, subroutine_name, & + allocate(blackbody_temperature_at_surface(horizontal_dimension), stat=errcode) + call check_allocate(errcode, subroutine_name, & 'blackbody_temperature_at_surface(horizontal_dimension)', & file=__FILE__, line=__LINE__) diff --git a/src/physics/utils/orbital_data.F90 b/src/physics/utils/orbital_data.F90 index df9f852d2..3abeece8b 100644 --- a/src/physics/utils/orbital_data.F90 +++ b/src/physics/utils/orbital_data.F90 @@ -1,4 +1,4 @@ -! Copyright (C) 2024 National Science Foundation-National Center for Atmospheric Research +! Copyright (C) 2024-2025 National Science Foundation-National Center for Atmospheric Research ! SPDX-License-Identifier: Apache-2.0 module orbital_data !-------------------------------------------------------------------------- From 4e5f381e18b19f7243a2213fdbef63f647b2c986 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Thu, 27 Mar 2025 13:03:28 -0600 Subject: [PATCH 20/32] code cleanup --- src/control/cam_comp.F90 | 2 +- .../utils/musica_ccpp_dependencies.F90 | 637 +++++++++--------- 2 files changed, 319 insertions(+), 320 deletions(-) diff --git a/src/control/cam_comp.F90 b/src/control/cam_comp.F90 index 9c68a7139..16e32984b 100644 --- a/src/control/cam_comp.F90 +++ b/src/control/cam_comp.F90 @@ -150,7 +150,7 @@ subroutine cam_init(caseid, ctitle, model_doi_url, & type(cam_out_t), pointer :: cam_out ! Output from CAM to surface type(cam_in_t), pointer :: cam_in ! Merged input state to CAM - ! Local variables + ! Local variables character(len=cs) :: filein ! Input namelist filename integer :: errflg character(len=cx) :: errmsg diff --git a/src/physics/utils/musica_ccpp_dependencies.F90 b/src/physics/utils/musica_ccpp_dependencies.F90 index 6cc06ae9d..c2bdd1cfd 100644 --- a/src/physics/utils/musica_ccpp_dependencies.F90 +++ b/src/physics/utils/musica_ccpp_dependencies.F90 @@ -1,331 +1,330 @@ ! Copyright (C) 2024-2025 National Science Foundation-National Center for Atmospheric Research ! SPDX-License-Identifier: Apache-2.0 module musica_ccpp_dependencies - !-------------------------------------------------------------------------- - ! - ! This module temporarily provides data that MUSICA chemistry consumes but - ! does not produce. The values are realistic but are not based on the - ! actual model state. These should be removed as the producers of this data - ! are added to CAM-SIMA or as CCPP-compliant physics schemes. - ! - ! IMPORTANT: This module must be completely removed before doing any actual - ! science with MUSICA chemistry in CAM-SIMA. - ! - !-------------------------------------------------------------------------- - - use ccpp_kinds, only: kind_phys - - implicit none - private - - public :: musica_ccpp_dependencies_init - - !> \section arg_table_musica_ccpp_dependencies Argument Table - !! \htmlinclude arg_table_musica_ccpp_dependencies.html - !! - integer, public, protected :: photolysis_wavelength_grid_section_dimension = 102 - integer, public, protected :: photolysis_wavelength_grid_interface_dimension = 103 - real(kind_phys), allocatable, public, protected :: photolysis_wavelength_grid_interfaces(:) - real(kind_phys), allocatable, public, protected :: extraterrestrial_radiation_flux(:) - real(kind_phys), allocatable, public, protected :: surface_albedo(:) - real(kind_phys), allocatable, public, protected :: blackbody_temperature_at_surface(:) - - ! local parameters - character(len=*), parameter :: module_name = '(musica_ccpp_dependencies)' - - !> Definition of temporary MUSICA species object - type, private :: temp_musica_species_t - character(len=:), allocatable :: name - real(kind_phys) :: constituent_value = 0.0_kind_phys ! kg kg-1 - end type temp_musica_species_t - - interface temp_musica_species_t - procedure species_constructor - end interface temp_musica_species_t - - !============================================================================== - contains - !============================================================================== - - function species_constructor(name, value) result( this ) - - !----------------------------------------------------------------------- - ! - ! Constructor for temporary MUSICA species object. - ! - !----------------------------------------------------------------------- - - character(len=*), intent(in) :: name - real(kind_phys), intent(in) :: value - type(temp_musica_species_t) :: this - - this%name = name - this%constituent_value = value - - end function species_constructor - - subroutine initialize_musica_species_constituents(constituents_properties, & - constituents_array, errmsg, errcode) - - !----------------------------------------------------------------------- - ! - ! Initialize temporary MUSICA species constituents. - ! - !----------------------------------------------------------------------- - - use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t - use ccpp_const_utils, only: ccpp_const_get_idx - use cam_logfile, only: iulog - use musica_ccpp_namelist, only: filename_of_micm_configuration - - type(ccpp_constituent_prop_ptr_t), pointer :: constituents_properties(:) - real(kind_phys), pointer :: constituents_array(:,:,:) - character(len=512), intent(out) :: errmsg - integer, intent(out) :: errcode - - ! local variables - type(temp_musica_species_t), allocatable :: species_group(:) - character(len=*), parameter :: chapman_config = 'chapman' - character(len=*), parameter :: terminator_config = 'terminator' - logical :: is_chapman = .false. - logical :: is_terminator = .false. - integer :: num_micm_species = 0 - integer :: num_tuvx_constituents = 1 - integer :: num_tuvx_only_gas_species = 0 - integer :: position - integer :: constituent_index - integer :: i_species - - if (.not. associated(constituents_properties)) then - errcode = 1 - errmsg = "[MUSICA Error] The pointer to the constituents properties object is not associated." - return - end if +!-------------------------------------------------------------------------- +! +! This module temporarily provides data that MUSICA chemistry consumes but +! does not produce. The values are realistic but are not based on the +! actual model state. These should be removed as the producers of this data +! are added to CAM-SIMA or as CCPP-compliant physics schemes. +! +! IMPORTANT: This module must be completely removed before doing any actual +! science with MUSICA chemistry in CAM-SIMA. +! +!-------------------------------------------------------------------------- + + use ccpp_kinds, only: kind_phys + + implicit none + private + + public :: musica_ccpp_dependencies_init + + !> \section arg_table_musica_ccpp_dependencies Argument Table + !! \htmlinclude arg_table_musica_ccpp_dependencies.html + !! + integer, public, protected :: photolysis_wavelength_grid_section_dimension = 102 + integer, public, protected :: photolysis_wavelength_grid_interface_dimension = 103 + real(kind_phys), allocatable, public, protected :: photolysis_wavelength_grid_interfaces(:) + real(kind_phys), allocatable, public, protected :: extraterrestrial_radiation_flux(:) + real(kind_phys), allocatable, public, protected :: surface_albedo(:) + real(kind_phys), allocatable, public, protected :: blackbody_temperature_at_surface(:) + + ! local parameters + character(len=*), parameter :: module_name = '(musica_ccpp_dependencies)' + + !> Definition of temporary MUSICA species object + type, private :: temp_musica_species_t + character(len=:), allocatable :: name + real(kind_phys) :: constituent_value = 0.0_kind_phys ! kg kg-1 + end type temp_musica_species_t + + interface temp_musica_species_t + procedure species_constructor + end interface temp_musica_species_t + +!============================================================================== +contains +!============================================================================== + + function species_constructor(name, value) result( this ) + + !----------------------------------------------------------------------- + ! + ! Constructor for temporary MUSICA species object. + ! + !----------------------------------------------------------------------- + + character(len=*), intent(in) :: name + real(kind_phys), intent(in) :: value + type(temp_musica_species_t) :: this + + this%name = name + this%constituent_value = value + + end function species_constructor + + subroutine initialize_musica_species_constituents(constituents_properties, & + constituents_array, errmsg, errcode) + + !----------------------------------------------------------------------- + ! + ! Initialize temporary MUSICA species constituents. + ! + !----------------------------------------------------------------------- + + use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t + use ccpp_const_utils, only: ccpp_const_get_idx + use cam_logfile, only: iulog + use musica_ccpp_namelist, only: filename_of_micm_configuration + + type(ccpp_constituent_prop_ptr_t), pointer :: constituents_properties(:) + real(kind_phys), pointer :: constituents_array(:,:,:) + character(len=512), intent(out) :: errmsg + integer, intent(out) :: errcode + + ! local variables + type(temp_musica_species_t), allocatable :: species_group(:) + character(len=*), parameter :: chapman_config = 'chapman' + character(len=*), parameter :: terminator_config = 'terminator' + logical :: is_chapman = .false. + logical :: is_terminator = .false. + integer :: num_micm_species = 0 + integer :: num_tuvx_constituents = 1 + integer :: num_tuvx_only_gas_species = 0 + integer :: position + integer :: constituent_index + integer :: i_species + + if (.not. associated(constituents_properties)) then + errcode = 1 + errmsg = "[MUSICA Error] The pointer to the constituents properties object is not associated." + return + end if - ! Currently, we only support two types of MUSICA configurations: Chapman and Terminator, - ! until the file I/O object is implemented. If the configuration is neither of these, - ! an error will be thrown. - position = index(filename_of_micm_configuration, chapman_config) ! Check if the substring exists + ! Currently, we only support two types of MUSICA configurations: Chapman and Terminator, + ! until the file I/O object is implemented. If the configuration is neither of these, + ! an error will be thrown. + position = index(filename_of_micm_configuration, chapman_config) ! Check if the substring exists + if (position > 0) then + is_chapman = .true. + write(iulog,*) "[MUSICA Info] Using the Chapman configuriation." + else + position = index(filename_of_micm_configuration, terminator_config) if (position > 0) then - is_chapman = .true. - write(iulog,*) "[MUSICA Info] Using the Chapman configuriation." + is_terminator = .true. + write(iulog,*) "[MUSICA Info] Using the Terminator configuriation." else - position = index(filename_of_micm_configuration, terminator_config) - if (position > 0) then - is_terminator = .true. - write(iulog,*) "[MUSICA Info] Using the Terminator configuriation." - else - errcode = 1 - errmsg = "[MUSICA Error] MUSICA configuration is not found." - return - end if - end if - - if (is_chapman) then - num_micm_species = 5 - num_tuvx_only_gas_species = 1 - else if (is_terminator) then - num_micm_species = 2 - num_tuvx_only_gas_species = 3 + errcode = 1 + errmsg = "[MUSICA Error] MUSICA configuration is not found." + return end if + end if - allocate (species_group(num_micm_species + num_tuvx_constituents + num_tuvx_only_gas_species)) - - species_group(1) = species_constructor(& - "cloud_liquid_water_mixing_ratio_wrt_moist_air_and_condensed_water", 1.0e-3_kind_phys) - - if (is_chapman) then - species_group(2) = species_constructor("O2", 0.21_kind_phys) - species_group(3) = species_constructor("O", 0.42_kind_phys) - species_group(4) = species_constructor("O1D", 1.0e-12_kind_phys) - species_group(5) = species_constructor("O3", 4.0e-6_kind_phys) - species_group(6) = species_constructor("N2", 0.79_kind_phys) - species_group(7) = species_constructor("air", 1.0e-3_kind_phys) - else if (is_terminator) then - species_group(2) = species_constructor("Cl", 1.0e-12_kind_phys) - species_group(3) = species_constructor("Cl2", 1.0e-12_kind_phys) - species_group(4) = species_constructor("air", 1.0e-3_kind_phys) - species_group(5) = species_constructor("O2", 0.21_kind_phys) - species_group(6) = species_constructor("O3", 4.0e-6_kind_phys) - end if + if (is_chapman) then + num_micm_species = 5 + num_tuvx_only_gas_species = 1 + else if (is_terminator) then + num_micm_species = 2 + num_tuvx_only_gas_species = 3 + end if + + allocate (species_group(num_micm_species + num_tuvx_constituents + num_tuvx_only_gas_species)) + + species_group(1) = species_constructor(& + "cloud_liquid_water_mixing_ratio_wrt_moist_air_and_condensed_water", 1.0e-3_kind_phys) - do i_species = 1, num_micm_species + num_tuvx_constituents + num_tuvx_only_gas_species - call ccpp_const_get_idx(constituents_properties, trim(species_group(i_species)%name), & - constituent_index, errmsg, errcode) - if (errcode /= 0) then - deallocate (species_group) - return - end if - - constituents_array(:,:,constituent_index) = species_group(i_species)%constituent_value - end do - - deallocate (species_group) - - end subroutine initialize_musica_species_constituents - - subroutine musica_ccpp_dependencies_init( & - horizontal_dimension, vertical_layer_dimension, & - constituents_properties, constituents_array) - - use cam_abortutils, only: check_allocate, endrun - use cam_logfile, only: iulog - use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t - - !----------------------------------------------------------------------- - ! - ! Initialize the MUSICA scheme dependencies. - ! - !----------------------------------------------------------------------- - - integer, intent(in) :: horizontal_dimension - integer, intent(in) :: vertical_layer_dimension - type(ccpp_constituent_prop_ptr_t), pointer :: constituents_properties(:) - real(kind_phys), pointer :: constituents_array(:,:,:) - - ! local variables - character(len=512), :: errmsg - integer, :: errcode - character(len=*), parameter :: subroutine_name = & - trim(module_name)//':(musica_ccpp_dependencies_init)' - - write(iulog,*) 'WARNING: Using placeholder data for MUSICA chemistry.' - - call initialize_musica_species_constituents(constituents_properties, & - constituents_array, errmsg, errcode) + if (is_chapman) then + species_group(2) = species_constructor("O2", 0.21_kind_phys) + species_group(3) = species_constructor("O", 0.42_kind_phys) + species_group(4) = species_constructor("O1D", 1.0e-12_kind_phys) + species_group(5) = species_constructor("O3", 4.0e-6_kind_phys) + species_group(6) = species_constructor("N2", 0.79_kind_phys) + species_group(7) = species_constructor("air", 1.0e-3_kind_phys) + else if (is_terminator) then + species_group(2) = species_constructor("Cl", 1.0e-12_kind_phys) + species_group(3) = species_constructor("Cl2", 1.0e-12_kind_phys) + species_group(4) = species_constructor("air", 1.0e-3_kind_phys) + species_group(5) = species_constructor("O2", 0.21_kind_phys) + species_group(6) = species_constructor("O3", 4.0e-6_kind_phys) + end if + + do i_species = 1, num_micm_species + num_tuvx_constituents + num_tuvx_only_gas_species + call ccpp_const_get_idx(constituents_properties, trim(species_group(i_species)%name), & + constituent_index, errmsg, errcode) if (errcode /= 0) then - call endrun(errmsg, file=__FILE__, line=__LINE__) + deallocate (species_group) + return end if - allocate(photolysis_wavelength_grid_interfaces(photolysis_wavelength_grid_interface_dimension), & - stat=errcode) - call check_allocate(errcode, subroutine_name, & - 'photolysis_wavelength_grid_interfaces(photolysis_wavelength_grid_interface_dimension)', & - file=__FILE__, line=__LINE__) - allocate(extraterrestrial_radiation_flux(photolysis_wavelength_grid_section_dimension), & - stat=errcode) - call check_allocate(errcode, subroutine_name, & - 'extraterrestrial_radiation_flux(photolysis_wavelength_grid_section_dimension)', & - file=__FILE__, line=__LINE__) - allocate(surface_albedo(horizontal_dimension), stat=errcode) - call check_allocate(errcode, subroutine_name, & - 'surface_albedo(horizontal_dimension)', & - file=__FILE__, line=__LINE__) - allocate(blackbody_temperature_at_surface(horizontal_dimension), stat=errcode) - call check_allocate(errcode, subroutine_name, & - 'blackbody_temperature_at_surface(horizontal_dimension)', & - file=__FILE__, line=__LINE__) - - surface_albedo(:) = 0.1_kind_phys - blackbody_temperature_at_surface(:) = 292.3_kind_phys - extraterrestrial_radiation_flux(:) = 1.0e14_kind_phys - photolysis_wavelength_grid_interfaces = (/ & - 120.0e-9_kind_phys, & - 121.4e-9_kind_phys, & - 121.9e-9_kind_phys, & - 123.5e-9_kind_phys, & - 124.3e-9_kind_phys, & - 125.5e-9_kind_phys, & - 126.3e-9_kind_phys, & - 127.1e-9_kind_phys, & - 130.1e-9_kind_phys, & - 131.1e-9_kind_phys, & - 135.0e-9_kind_phys, & - 140.0e-9_kind_phys, & - 145.0e-9_kind_phys, & - 150.0e-9_kind_phys, & - 155.0e-9_kind_phys, & - 160.0e-9_kind_phys, & - 165.0e-9_kind_phys, & - 168.0e-9_kind_phys, & - 171.0e-9_kind_phys, & - 173.0e-9_kind_phys, & - 174.4e-9_kind_phys, & - 175.4e-9_kind_phys, & - 177.0e-9_kind_phys, & - 178.6e-9_kind_phys, & - 180.2e-9_kind_phys, & - 181.8e-9_kind_phys, & - 183.5e-9_kind_phys, & - 185.2e-9_kind_phys, & - 186.9e-9_kind_phys, & - 188.7e-9_kind_phys, & - 190.5e-9_kind_phys, & - 192.3e-9_kind_phys, & - 194.2e-9_kind_phys, & - 196.1e-9_kind_phys, & - 198.0e-9_kind_phys, & - 200.0e-9_kind_phys, & - 202.0e-9_kind_phys, & - 204.1e-9_kind_phys, & - 206.2e-9_kind_phys, & - 208.0e-9_kind_phys, & - 211.0e-9_kind_phys, & - 214.0e-9_kind_phys, & - 217.0e-9_kind_phys, & - 220.0e-9_kind_phys, & - 223.0e-9_kind_phys, & - 226.0e-9_kind_phys, & - 229.0e-9_kind_phys, & - 232.0e-9_kind_phys, & - 235.0e-9_kind_phys, & - 238.0e-9_kind_phys, & - 241.0e-9_kind_phys, & - 244.0e-9_kind_phys, & - 247.0e-9_kind_phys, & - 250.0e-9_kind_phys, & - 253.0e-9_kind_phys, & - 256.0e-9_kind_phys, & - 259.0e-9_kind_phys, & - 263.0e-9_kind_phys, & - 267.0e-9_kind_phys, & - 271.0e-9_kind_phys, & - 275.0e-9_kind_phys, & - 279.0e-9_kind_phys, & - 283.0e-9_kind_phys, & - 287.0e-9_kind_phys, & - 291.0e-9_kind_phys, & - 295.0e-9_kind_phys, & - 298.5e-9_kind_phys, & - 302.5e-9_kind_phys, & - 305.5e-9_kind_phys, & - 308.5e-9_kind_phys, & - 311.5e-9_kind_phys, & - 314.5e-9_kind_phys, & - 317.5e-9_kind_phys, & - 322.5e-9_kind_phys, & - 327.5e-9_kind_phys, & - 332.5e-9_kind_phys, & - 337.5e-9_kind_phys, & - 342.5e-9_kind_phys, & - 347.5e-9_kind_phys, & - 350.0e-9_kind_phys, & - 355.0e-9_kind_phys, & - 360.0e-9_kind_phys, & - 365.0e-9_kind_phys, & - 370.0e-9_kind_phys, & - 375.0e-9_kind_phys, & - 380.0e-9_kind_phys, & - 385.0e-9_kind_phys, & - 390.0e-9_kind_phys, & - 395.0e-9_kind_phys, & - 400.0e-9_kind_phys, & - 405.0e-9_kind_phys, & - 410.0e-9_kind_phys, & - 415.0e-9_kind_phys, & - 420.0e-9_kind_phys, & - 430.0e-9_kind_phys, & - 440.0e-9_kind_phys, & - 450.0e-9_kind_phys, & - 500.0e-9_kind_phys, & - 550.0e-9_kind_phys, & - 600.0e-9_kind_phys, & - 650.0e-9_kind_phys, & - 700.0e-9_kind_phys, & - 750.0e-9_kind_phys & - /) - - end subroutine musica_ccpp_dependencies_init - - end module musica_ccpp_dependencies - \ No newline at end of file + constituents_array(:,:,constituent_index) = species_group(i_species)%constituent_value + end do + + deallocate (species_group) + + end subroutine initialize_musica_species_constituents + + subroutine musica_ccpp_dependencies_init( & + horizontal_dimension, vertical_layer_dimension, & + constituents_properties, constituents_array) + + use cam_abortutils, only: check_allocate, endrun + use cam_logfile, only: iulog + use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t + + !----------------------------------------------------------------------- + ! + ! Initialize the MUSICA scheme dependencies. + ! + !----------------------------------------------------------------------- + + integer, intent(in) :: horizontal_dimension + integer, intent(in) :: vertical_layer_dimension + type(ccpp_constituent_prop_ptr_t), pointer :: constituents_properties(:) + real(kind_phys), pointer :: constituents_array(:,:,:) + + ! local variables + character(len=512), :: errmsg + integer, :: errcode + character(len=*), parameter :: subroutine_name = & + trim(module_name)//':(musica_ccpp_dependencies_init)' + + write(iulog,*) 'WARNING: Using placeholder data for MUSICA chemistry.' + + call initialize_musica_species_constituents(constituents_properties, & + constituents_array, errmsg, errcode) + if (errcode /= 0) then + call endrun(errmsg, file=__FILE__, line=__LINE__) + end if + + allocate(photolysis_wavelength_grid_interfaces(photolysis_wavelength_grid_interface_dimension), & + stat=errcode) + call check_allocate(errcode, subroutine_name, & + 'photolysis_wavelength_grid_interfaces(photolysis_wavelength_grid_interface_dimension)', & + file=__FILE__, line=__LINE__) + allocate(extraterrestrial_radiation_flux(photolysis_wavelength_grid_section_dimension), & + stat=errcode) + call check_allocate(errcode, subroutine_name, & + 'extraterrestrial_radiation_flux(photolysis_wavelength_grid_section_dimension)', & + file=__FILE__, line=__LINE__) + allocate(surface_albedo(horizontal_dimension), stat=errcode) + call check_allocate(errcode, subroutine_name, & + 'surface_albedo(horizontal_dimension)', & + file=__FILE__, line=__LINE__) + allocate(blackbody_temperature_at_surface(horizontal_dimension), stat=errcode) + call check_allocate(errcode, subroutine_name, & + 'blackbody_temperature_at_surface(horizontal_dimension)', & + file=__FILE__, line=__LINE__) + + surface_albedo(:) = 0.1_kind_phys + blackbody_temperature_at_surface(:) = 292.3_kind_phys + extraterrestrial_radiation_flux(:) = 1.0e14_kind_phys + photolysis_wavelength_grid_interfaces = (/ & + 120.0e-9_kind_phys, & + 121.4e-9_kind_phys, & + 121.9e-9_kind_phys, & + 123.5e-9_kind_phys, & + 124.3e-9_kind_phys, & + 125.5e-9_kind_phys, & + 126.3e-9_kind_phys, & + 127.1e-9_kind_phys, & + 130.1e-9_kind_phys, & + 131.1e-9_kind_phys, & + 135.0e-9_kind_phys, & + 140.0e-9_kind_phys, & + 145.0e-9_kind_phys, & + 150.0e-9_kind_phys, & + 155.0e-9_kind_phys, & + 160.0e-9_kind_phys, & + 165.0e-9_kind_phys, & + 168.0e-9_kind_phys, & + 171.0e-9_kind_phys, & + 173.0e-9_kind_phys, & + 174.4e-9_kind_phys, & + 175.4e-9_kind_phys, & + 177.0e-9_kind_phys, & + 178.6e-9_kind_phys, & + 180.2e-9_kind_phys, & + 181.8e-9_kind_phys, & + 183.5e-9_kind_phys, & + 185.2e-9_kind_phys, & + 186.9e-9_kind_phys, & + 188.7e-9_kind_phys, & + 190.5e-9_kind_phys, & + 192.3e-9_kind_phys, & + 194.2e-9_kind_phys, & + 196.1e-9_kind_phys, & + 198.0e-9_kind_phys, & + 200.0e-9_kind_phys, & + 202.0e-9_kind_phys, & + 204.1e-9_kind_phys, & + 206.2e-9_kind_phys, & + 208.0e-9_kind_phys, & + 211.0e-9_kind_phys, & + 214.0e-9_kind_phys, & + 217.0e-9_kind_phys, & + 220.0e-9_kind_phys, & + 223.0e-9_kind_phys, & + 226.0e-9_kind_phys, & + 229.0e-9_kind_phys, & + 232.0e-9_kind_phys, & + 235.0e-9_kind_phys, & + 238.0e-9_kind_phys, & + 241.0e-9_kind_phys, & + 244.0e-9_kind_phys, & + 247.0e-9_kind_phys, & + 250.0e-9_kind_phys, & + 253.0e-9_kind_phys, & + 256.0e-9_kind_phys, & + 259.0e-9_kind_phys, & + 263.0e-9_kind_phys, & + 267.0e-9_kind_phys, & + 271.0e-9_kind_phys, & + 275.0e-9_kind_phys, & + 279.0e-9_kind_phys, & + 283.0e-9_kind_phys, & + 287.0e-9_kind_phys, & + 291.0e-9_kind_phys, & + 295.0e-9_kind_phys, & + 298.5e-9_kind_phys, & + 302.5e-9_kind_phys, & + 305.5e-9_kind_phys, & + 308.5e-9_kind_phys, & + 311.5e-9_kind_phys, & + 314.5e-9_kind_phys, & + 317.5e-9_kind_phys, & + 322.5e-9_kind_phys, & + 327.5e-9_kind_phys, & + 332.5e-9_kind_phys, & + 337.5e-9_kind_phys, & + 342.5e-9_kind_phys, & + 347.5e-9_kind_phys, & + 350.0e-9_kind_phys, & + 355.0e-9_kind_phys, & + 360.0e-9_kind_phys, & + 365.0e-9_kind_phys, & + 370.0e-9_kind_phys, & + 375.0e-9_kind_phys, & + 380.0e-9_kind_phys, & + 385.0e-9_kind_phys, & + 390.0e-9_kind_phys, & + 395.0e-9_kind_phys, & + 400.0e-9_kind_phys, & + 405.0e-9_kind_phys, & + 410.0e-9_kind_phys, & + 415.0e-9_kind_phys, & + 420.0e-9_kind_phys, & + 430.0e-9_kind_phys, & + 440.0e-9_kind_phys, & + 450.0e-9_kind_phys, & + 500.0e-9_kind_phys, & + 550.0e-9_kind_phys, & + 600.0e-9_kind_phys, & + 650.0e-9_kind_phys, & + 700.0e-9_kind_phys, & + 750.0e-9_kind_phys & + /) + + end subroutine musica_ccpp_dependencies_init + +end module musica_ccpp_dependencies From 394d875bd9a0c66d3376ea655efbf0c2e3080f62 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Thu, 27 Mar 2025 14:02:27 -0600 Subject: [PATCH 21/32] edit docker --- docker/Dockerfile.musica | 5 +++-- src/physics/utils/musica_ccpp_dependencies.F90 | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docker/Dockerfile.musica b/docker/Dockerfile.musica index 86c2a3ecd..d526ee8ce 100644 --- a/docker/Dockerfile.musica +++ b/docker/Dockerfile.musica @@ -92,7 +92,8 @@ RUN ./xmlchange REST_N=100 RUN ./case.setup -# Add this to the end of 'user_nl_cam' file +# You can run the model with the snapshot file by adding this line to the end of 'user_nl_cam' file on Derecho. +# Note that this snapshot contains only ten time slices. # ncdata=/glade/campaign/cesm/community/amwg/sima_baselines/cam_sima_test_snapshots/cam_ne3pg3_kessler_snapshot_derecho_gnu_before_c20240412.nc -# RUN ./case.build \ No newline at end of file +RUN ./case.build \ No newline at end of file diff --git a/src/physics/utils/musica_ccpp_dependencies.F90 b/src/physics/utils/musica_ccpp_dependencies.F90 index c2bdd1cfd..d352f5630 100644 --- a/src/physics/utils/musica_ccpp_dependencies.F90 +++ b/src/physics/utils/musica_ccpp_dependencies.F90 @@ -51,7 +51,7 @@ function species_constructor(name, value) result( this ) !----------------------------------------------------------------------- ! - ! Constructor for temporary MUSICA species object. + ! Constructor for temporary MUSICA species object ! !----------------------------------------------------------------------- From 798441be2eebff2342ef04d65dd330240bfa733c Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Thu, 27 Mar 2025 14:36:31 -0600 Subject: [PATCH 22/32] correct python str concatenation --- cime_config/buildnml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cime_config/buildnml b/cime_config/buildnml index ae423127d..cda54d235 100755 --- a/cime_config/buildnml +++ b/cime_config/buildnml @@ -385,8 +385,10 @@ def buildnml(case, caseroot, compname): musica_config_dest_dir = os.path.join(rundir, MUSICA_CONFIG_DIR_NAME) if not os.path.exists(musica_config_src_dir): - emsg = f"The directory '{MUSICA_CONFIG_DIR_NAME}' doesn't exit. The directory \ - must be located in the caseroot if the ATM library build is successful." + emsg = ( + f"The directory '{MUSICA_CONFIG_DIR_NAME}' doesn't exit. " + "The directory must be located in the caseroot if the ATM library build is successful." + ) raise CamBuildnmlError(emsg) if not os.path.exists(musica_config_dest_dir): From 195b0b1b831425ba210fd8d4823f6e6577f3ae9b Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Thu, 27 Mar 2025 15:10:47 -0600 Subject: [PATCH 23/32] reworked on the error check because the buildnml runs before buildlib --- cime_config/buildlib | 33 +++++++++++++++++---------------- cime_config/buildnml | 9 ++++----- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/cime_config/buildlib b/cime_config/buildlib index c0648130c..8f1c07a5b 100755 --- a/cime_config/buildlib +++ b/cime_config/buildlib @@ -185,13 +185,14 @@ def _build_cam(): if not musica_libs in cam_linked_libs: _set_musica_lib_path(musica_install_path, caseroot) - cmd += ' USER_INCLDIR="'\ - f'-I{os.path.join(musica_install_path, "include", "micm")} '\ - f'-I{os.path.join(musica_install_path, "include", "musica")} '\ - f'-I{os.path.join(musica_install_path, "include", "musica", "micm")} '\ - f'-I{os.path.join(musica_install_path, "include", "musica", "tuvx")} '\ - f'-I{os.path.join(musica_install_path, "include", "musica", "fortran")} '\ + cmd += (' USER_INCLDIR="' + f'-I{os.path.join(musica_install_path, "include", "micm")} ' + f'-I{os.path.join(musica_install_path, "include", "musica")} ' + f'-I{os.path.join(musica_install_path, "include", "musica", "micm")} ' + f'-I{os.path.join(musica_install_path, "include", "musica", "tuvx")} ' + f'-I{os.path.join(musica_install_path, "include", "musica", "fortran")} ' '"' + ) retcode, out, err = run_cmd(cmd) _LOGGER.info("Command %s:\n\nstdout:\n%s\n\nstderr:\n%s\n", cmd, out, err) @@ -285,8 +286,8 @@ def _build_musica(clone_dest: str) -> str: subprocess.run(command, cwd=bld_path, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=False) except subprocess.CalledProcessError as e: - raise subprocess.CalledProcessError(e.returncode, e.cmd, "The subprocess \ - for cmake to configure the MUSICA CMake project failed.") from e + raise subprocess.CalledProcessError(e.returncode, e.cmd, + "The subprocess for cmake to configure the MUSICA CMake project failed.") from e except FileNotFoundError as e: raise FileNotFoundError("The 'cmake' command was not found.") from e except OSError as e: @@ -297,8 +298,8 @@ def _build_musica(clone_dest: str) -> str: subprocess.run(command, cwd=bld_path, stdout=subprocess.PIPE, text=True, check=False) except subprocess.CalledProcessError as e: - raise subprocess.CalledProcessError(e.returncode, e.cmd, "The subprocess \ - for cmake to build the MUSICA library failed.") from e + raise subprocess.CalledProcessError(e.returncode, e.cmd, + "The subprocess for cmake to build the MUSICA library failed.") from e except FileNotFoundError as e: raise FileNotFoundError("The 'cmake' command was not found.") from e except OSError as e: @@ -378,8 +379,8 @@ def _set_musica_lib_path(musica_install_path: str, caseroot: str) -> None: subprocess.run(command, cwd=caseroot, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=False) except subprocess.CalledProcessError as e: - raise subprocess.CalledProcessError(e.returncode, e.cmd, "The subprocess \ - for xmlchange to set the MUSICA library path failed.") from e + raise subprocess.CalledProcessError(e.returncode, e.cmd, + "The subprocess for xmlchange to set the MUSICA library path failed.") from e except FileNotFoundError as e: raise FileNotFoundError("The 'xmlchange' command was not found.") from e except OSError as e: @@ -412,8 +413,8 @@ def _clone_and_checkout(repo_url: str, tag_name: str, clone_dest: str) -> None: subprocess.run(["git", "clone", repo_url, repo_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=False) except subprocess.CalledProcessError as e: - raise subprocess.CalledProcessError(e.returncode, e.cmd, f"The subprocess \ - for git to clone the repository {repo_url} failed.") from e + raise subprocess.CalledProcessError(e.returncode, e.cmd, + f"The subprocess for git to clone the repository {repo_url} failed.") from e except FileNotFoundError as e: raise FileNotFoundError("The 'git' command was not found.") from e except OSError as e: @@ -423,8 +424,8 @@ def _clone_and_checkout(repo_url: str, tag_name: str, clone_dest: str) -> None: subprocess.run(["git", "-C", repo_path, "checkout", tag_name], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=False) except subprocess.CalledProcessError as e: - raise subprocess.CalledProcessError(e.returncode, e.cmd, f"The subprocess \ - for git to checkout the branch {tag_name} failed.") from e + raise subprocess.CalledProcessError(e.returncode, e.cmd, + f"The subprocess for git to checkout the branch {tag_name} failed.") from e except FileNotFoundError as e: raise FileNotFoundError("The 'git' command was not found.") from e except OSError as e: diff --git a/cime_config/buildnml b/cime_config/buildnml index cda54d235..705c2213d 100755 --- a/cime_config/buildnml +++ b/cime_config/buildnml @@ -384,12 +384,11 @@ def buildnml(case, caseroot, compname): musica_config_src_dir = os.path.join(caseroot, MUSICA_CONFIG_DIR_NAME) musica_config_dest_dir = os.path.join(rundir, MUSICA_CONFIG_DIR_NAME) + # buildnml runs before buildlib, but the MUSICA configuration becomes + # available only after buildlib is executed. Therefore, if the configuration + # is not found, skip the creation of symlinks if not os.path.exists(musica_config_src_dir): - emsg = ( - f"The directory '{MUSICA_CONFIG_DIR_NAME}' doesn't exit. " - "The directory must be located in the caseroot if the ATM library build is successful." - ) - raise CamBuildnmlError(emsg) + return if not os.path.exists(musica_config_dest_dir): os.makedirs(musica_config_dest_dir, exist_ok=False) From dfd9974f4a72fcc3b99b9c7d637d0940c76cbebc Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Thu, 27 Mar 2025 16:10:21 -0600 Subject: [PATCH 24/32] remove code to handle the exception case --- cime_config/buildnml | 12 +++--------- src/physics/utils/musica_ccpp_dependencies.F90 | 4 ++-- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/cime_config/buildnml b/cime_config/buildnml index 705c2213d..f6b8842ab 100755 --- a/cime_config/buildnml +++ b/cime_config/buildnml @@ -384,19 +384,13 @@ def buildnml(case, caseroot, compname): musica_config_src_dir = os.path.join(caseroot, MUSICA_CONFIG_DIR_NAME) musica_config_dest_dir = os.path.join(rundir, MUSICA_CONFIG_DIR_NAME) - # buildnml runs before buildlib, but the MUSICA configuration becomes - # available only after buildlib is executed. Therefore, if the configuration - # is not found, skip the creation of symlinks - if not os.path.exists(musica_config_src_dir): - return - - if not os.path.exists(musica_config_dest_dir): - os.makedirs(musica_config_dest_dir, exist_ok=False) + if os.path.exists(musica_config_src_dir): + os.makedirs(musica_config_dest_dir, exist_ok=True) for root, _, files in os.walk(musica_config_src_dir): rel_path = os.path.relpath(root, musica_config_src_dir) dest_dir = os.path.join(musica_config_dest_dir, rel_path) - os.makedirs(dest_dir, exist_ok=False) + os.makedirs(dest_dir, exist_ok=True) for file in files: symlink_force(os.path.join(root, file), os.path.join(dest_dir, file)) diff --git a/src/physics/utils/musica_ccpp_dependencies.F90 b/src/physics/utils/musica_ccpp_dependencies.F90 index d352f5630..cda6b595e 100644 --- a/src/physics/utils/musica_ccpp_dependencies.F90 +++ b/src/physics/utils/musica_ccpp_dependencies.F90 @@ -184,10 +184,10 @@ subroutine musica_ccpp_dependencies_init( & real(kind_phys), pointer :: constituents_array(:,:,:) ! local variables - character(len=512), :: errmsg - integer, :: errcode character(len=*), parameter :: subroutine_name = & trim(module_name)//':(musica_ccpp_dependencies_init)' + character(len=512) :: errmsg + integer :: errcode write(iulog,*) 'WARNING: Using placeholder data for MUSICA chemistry.' From 634610c8a3525afa9648b0a883ddf7198e2a58d6 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Mon, 7 Apr 2025 16:38:57 -0600 Subject: [PATCH 25/32] code cleanup --- cime_config/buildlib | 1 - docker/Dockerfile.musica | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cime_config/buildlib b/cime_config/buildlib index 8f1c07a5b..0db7d95af 100755 --- a/cime_config/buildlib +++ b/cime_config/buildlib @@ -10,7 +10,6 @@ import filecmp import shutil import subprocess import logging -import json from cam_config import ConfigCAM # CAM's configure structure from atm_musica_config import MUSICA_CCPP_SCHEME_NAME, MUSICA_CONFIG_DIR_NAME diff --git a/docker/Dockerfile.musica b/docker/Dockerfile.musica index d526ee8ce..0a716b7ee 100644 --- a/docker/Dockerfile.musica +++ b/docker/Dockerfile.musica @@ -92,6 +92,12 @@ RUN ./xmlchange REST_N=100 RUN ./case.setup +# Specify the path to the MUSICA configuraiton files by adding the following lines to the `user_nl_cam` file. +# For example, to configure the Chapman mechanisms, include these lines. +# filename_of_micm_configuration=/home/cam_sima_user/case_name/test-case/musica_configurations/chapman/micm/config.json +# filename_of_tuvx_configuration=/home/cam_sima_user/case_name/test-case/musica_configurations/chapman/tuvx/config.json +# filename_of_tuvx_micm_mapping_configuration=/home/cam_sima_user/case_name/test-case/musica_configurations/chapman/tuvx_micm_mapping.json + # You can run the model with the snapshot file by adding this line to the end of 'user_nl_cam' file on Derecho. # Note that this snapshot contains only ten time slices. # ncdata=/glade/campaign/cesm/community/amwg/sima_baselines/cam_sima_test_snapshots/cam_ne3pg3_kessler_snapshot_derecho_gnu_before_c20240412.nc From b4051f591869fdc49325988f9159f67f29c09665 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Thu, 24 Apr 2025 16:38:15 -0600 Subject: [PATCH 26/32] update species concentrations --- src/physics/utils/musica_ccpp_dependencies.F90 | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/physics/utils/musica_ccpp_dependencies.F90 b/src/physics/utils/musica_ccpp_dependencies.F90 index cda6b595e..a512c44e2 100644 --- a/src/physics/utils/musica_ccpp_dependencies.F90 +++ b/src/physics/utils/musica_ccpp_dependencies.F90 @@ -132,15 +132,16 @@ subroutine initialize_musica_species_constituents(constituents_properties, & allocate (species_group(num_micm_species + num_tuvx_constituents + num_tuvx_only_gas_species)) species_group(1) = species_constructor(& - "cloud_liquid_water_mixing_ratio_wrt_moist_air_and_condensed_water", 1.0e-3_kind_phys) + "cloud_liquid_water_mixing_ratio_wrt_moist_air_and_condensed_water", 0.00060_kind_phys) if (is_chapman) then - species_group(2) = species_constructor("O2", 0.21_kind_phys) - species_group(3) = species_constructor("O", 0.42_kind_phys) - species_group(4) = species_constructor("O1D", 1.0e-12_kind_phys) - species_group(5) = species_constructor("O3", 4.0e-6_kind_phys) - species_group(6) = species_constructor("N2", 0.79_kind_phys) - species_group(7) = species_constructor("air", 1.0e-3_kind_phys) + species_group(2) = species_constructor("O2", 0.22474_kind_phys) + species_group(3) = species_constructor("O", 5.3509e-10_kind_phys) + species_group(4) = species_constructor("O1D", 5.3509e-10_kind_phys) + species_group(5) = species_constructor("O3", 0.00016_kind_phys) + species_group(6) = species_constructor("N2", 0.74015_kind_phys) + species_group(7) = species_constructor("air", 0.00060_kind_phys) + else if (is_terminator) then species_group(2) = species_constructor("Cl", 1.0e-12_kind_phys) species_group(3) = species_constructor("Cl2", 1.0e-12_kind_phys) From 8be66b7b51b9b0709cd9f2234fb1a89934fe7c8c Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Fri, 25 Apr 2025 12:26:16 -0600 Subject: [PATCH 27/32] address code review --- .gitmodules | 2 +- src/physics/utils/musica_ccpp_dependencies.F90 | 2 +- src/physics/utils/orbital_data.F90 | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index da6d41f9a..d6168e3ce 100644 --- a/.gitmodules +++ b/.gitmodules @@ -22,7 +22,7 @@ url = https://github.com/boulderdaze/atmospheric_physics fxtag = fix_musica_bug fxrequired = AlwaysRequired - fxDONOTUSEurl = https://github.com/boulderdaze/atmospheric_physics + fxDONOTUSEurl = https://github.com/ESCOMP/atmospheric_physics [submodule "ccs_config"] path = ccs_config url = https://github.com/ESMCI/ccs_config_cesm.git diff --git a/src/physics/utils/musica_ccpp_dependencies.F90 b/src/physics/utils/musica_ccpp_dependencies.F90 index a512c44e2..9900e24d1 100644 --- a/src/physics/utils/musica_ccpp_dependencies.F90 +++ b/src/physics/utils/musica_ccpp_dependencies.F90 @@ -1,4 +1,4 @@ -! Copyright (C) 2024-2025 National Science Foundation-National Center for Atmospheric Research +! Copyright (C) 2024-2025 University Corporation for Atmospheric Research ! SPDX-License-Identifier: Apache-2.0 module musica_ccpp_dependencies !-------------------------------------------------------------------------- diff --git a/src/physics/utils/orbital_data.F90 b/src/physics/utils/orbital_data.F90 index 3abeece8b..bced4e1ef 100644 --- a/src/physics/utils/orbital_data.F90 +++ b/src/physics/utils/orbital_data.F90 @@ -1,4 +1,4 @@ -! Copyright (C) 2024-2025 National Science Foundation-National Center for Atmospheric Research +! Copyright (C) 2024-2025 University Corporation for Atmospheric Research ! SPDX-License-Identifier: Apache-2.0 module orbital_data !-------------------------------------------------------------------------- From 911403f239d2eccfc4ae03b94635cbfe06b4dc48 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Fri, 25 Apr 2025 14:10:01 -0600 Subject: [PATCH 28/32] correct air mixing ratio --- src/physics/utils/musica_ccpp_dependencies.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/physics/utils/musica_ccpp_dependencies.F90 b/src/physics/utils/musica_ccpp_dependencies.F90 index 9900e24d1..730ddaffa 100644 --- a/src/physics/utils/musica_ccpp_dependencies.F90 +++ b/src/physics/utils/musica_ccpp_dependencies.F90 @@ -140,12 +140,12 @@ subroutine initialize_musica_species_constituents(constituents_properties, & species_group(4) = species_constructor("O1D", 5.3509e-10_kind_phys) species_group(5) = species_constructor("O3", 0.00016_kind_phys) species_group(6) = species_constructor("N2", 0.74015_kind_phys) - species_group(7) = species_constructor("air", 0.00060_kind_phys) + species_group(7) = species_constructor("air", 1.0_kind_phys) else if (is_terminator) then species_group(2) = species_constructor("Cl", 1.0e-12_kind_phys) species_group(3) = species_constructor("Cl2", 1.0e-12_kind_phys) - species_group(4) = species_constructor("air", 1.0e-3_kind_phys) + species_group(4) = species_constructor("air", 1.0_kind_phys) species_group(5) = species_constructor("O2", 0.21_kind_phys) species_group(6) = species_constructor("O3", 4.0e-6_kind_phys) end if From 276986fc262039838c0daf73c3e3457129aec7d4 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Mon, 28 Apr 2025 18:02:42 -0600 Subject: [PATCH 29/32] update the tag --- .gitmodules | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index d6168e3ce..ef7afbf94 100644 --- a/.gitmodules +++ b/.gitmodules @@ -19,8 +19,8 @@ fxDONOTUSEurl = https://github.com/MPAS-Dev/MPAS-Model.git [submodule "ncar-physics"] path = src/physics/ncar_ccpp - url = https://github.com/boulderdaze/atmospheric_physics - fxtag = fix_musica_bug + url = https://github.com/ESCOMP/atmospheric_physics + fxtag = ac83803062a5d38b92e416e1cf737d3811e20cd1 fxrequired = AlwaysRequired fxDONOTUSEurl = https://github.com/ESCOMP/atmospheric_physics [submodule "ccs_config"] From 3e2f445b9998ac5563621b38ab1766246331488d Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Mon, 28 Apr 2025 18:09:32 -0600 Subject: [PATCH 30/32] submodule update --- src/physics/ncar_ccpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/physics/ncar_ccpp b/src/physics/ncar_ccpp index 04a9d1f30..36f336e87 160000 --- a/src/physics/ncar_ccpp +++ b/src/physics/ncar_ccpp @@ -1 +1 @@ -Subproject commit 04a9d1f303e97cac38323bb369bd5461b1af72b6 +Subproject commit 36f336e876ece9fcfcb97a29cf1785d172a5252d From 5924f4301f02b25dcce31eb8319ad3c7eeba9804 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Mon, 28 Apr 2025 18:17:59 -0600 Subject: [PATCH 31/32] update atmos submodule --- src/physics/ncar_ccpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/physics/ncar_ccpp b/src/physics/ncar_ccpp index 36f336e87..ac8380306 160000 --- a/src/physics/ncar_ccpp +++ b/src/physics/ncar_ccpp @@ -1 +1 @@ -Subproject commit 36f336e876ece9fcfcb97a29cf1785d172a5252d +Subproject commit ac83803062a5d38b92e416e1cf737d3811e20cd1 From cb628f45fed0bd503689e8431942fee025d614ad Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Fri, 2 May 2025 11:29:09 -0600 Subject: [PATCH 32/32] address review comments --- src/physics/utils/musica_ccpp_dependencies.F90 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/physics/utils/musica_ccpp_dependencies.F90 b/src/physics/utils/musica_ccpp_dependencies.F90 index 730ddaffa..f9d0e9279 100644 --- a/src/physics/utils/musica_ccpp_dependencies.F90 +++ b/src/physics/utils/musica_ccpp_dependencies.F90 @@ -129,7 +129,9 @@ subroutine initialize_musica_species_constituents(constituents_properties, & num_tuvx_only_gas_species = 3 end if - allocate (species_group(num_micm_species + num_tuvx_constituents + num_tuvx_only_gas_species)) + allocate (species_group(num_micm_species + num_tuvx_constituents + num_tuvx_only_gas_species), & + stat=errcode, errmsg=errmsg) + if (errcode /= 0) return species_group(1) = species_constructor(& "cloud_liquid_water_mixing_ratio_wrt_moist_air_and_condensed_water", 0.00060_kind_phys) @@ -199,20 +201,20 @@ subroutine musica_ccpp_dependencies_init( & end if allocate(photolysis_wavelength_grid_interfaces(photolysis_wavelength_grid_interface_dimension), & - stat=errcode) + stat=errcode, errmsg=errmsg) call check_allocate(errcode, subroutine_name, & 'photolysis_wavelength_grid_interfaces(photolysis_wavelength_grid_interface_dimension)', & file=__FILE__, line=__LINE__) allocate(extraterrestrial_radiation_flux(photolysis_wavelength_grid_section_dimension), & - stat=errcode) + stat=errcode, errmsg=errmsg) call check_allocate(errcode, subroutine_name, & 'extraterrestrial_radiation_flux(photolysis_wavelength_grid_section_dimension)', & file=__FILE__, line=__LINE__) - allocate(surface_albedo(horizontal_dimension), stat=errcode) + allocate(surface_albedo(horizontal_dimension), stat=errcode, errmsg=errmsg) call check_allocate(errcode, subroutine_name, & 'surface_albedo(horizontal_dimension)', & file=__FILE__, line=__LINE__) - allocate(blackbody_temperature_at_surface(horizontal_dimension), stat=errcode) + allocate(blackbody_temperature_at_surface(horizontal_dimension), stat=errcode, errmsg=errmsg) call check_allocate(errcode, subroutine_name, & 'blackbody_temperature_at_surface(horizontal_dimension)', & file=__FILE__, line=__LINE__)