From ecce5b3b641074276730d83df5dc7678160d93e1 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Mon, 21 Oct 2024 16:20:33 -0600 Subject: [PATCH 1/3] address code review --- schemes/musica/micm/musica_ccpp_micm.F90 | 18 ++++---- schemes/musica/micm/musica_ccpp_micm_util.F90 | 17 ++++---- schemes/musica/musica_ccpp.F90 | 42 ++++++++++--------- schemes/musica/musica_ccpp.meta | 12 +++--- schemes/musica/musica_ccpp_namelist.xml | 2 +- schemes/musica/tuvx/musica_ccpp_tuvx.F90 | 21 +++++----- .../tuvx/musica_ccpp_tuvx_height_grid.F90 | 35 +++++++--------- test/docker/Dockerfile.musica | 7 +++- test/docker/Dockerfile.musica.no_install | 10 ++++- test/musica/micm/test_micm_util.F90 | 24 +++++------ test/musica/test_musica_api.F90 | 36 ++++++++-------- test/musica/tuvx/test_tuvx_height_grid.F90 | 6 +-- 12 files changed, 123 insertions(+), 107 deletions(-) diff --git a/schemes/musica/micm/musica_ccpp_micm.F90 b/schemes/musica/micm/musica_ccpp_micm.F90 index b34ab965..7b7310ee 100644 --- a/schemes/musica/micm/musica_ccpp_micm.F90 +++ b/schemes/musica/micm/musica_ccpp_micm.F90 @@ -93,14 +93,14 @@ subroutine micm_run(time_step, temperature, pressure, dry_air_density, & use musica_util, only: string_t, error_t use iso_c_binding, only: c_double - real(kind_phys), intent(in) :: time_step ! s - real(c_double), target, intent(in) :: temperature(:) ! K - real(c_double), target, intent(in) :: pressure(:) ! Pa - real(c_double), target, intent(in) :: dry_air_density(:) ! kg m-3 - real(c_double), target, intent(in) :: user_defined_rate_parameters(:) ! various units - real(c_double), target, intent(inout) :: constituents(:) ! mol m-3 - character(len=512), intent(out) :: errmsg - integer, intent(out) :: errcode + real(kind_phys), intent(in) :: time_step ! s + real(c_double), intent(in) :: temperature(:) ! K + real(c_double), intent(in) :: pressure(:) ! Pa + real(c_double), intent(in) :: dry_air_density(:) ! kg m-3 + real(c_double), intent(in) :: user_defined_rate_parameters(:) ! various units + real(c_double), intent(inout) :: constituents(:) ! mol m-3 + character(len=512), intent(out) :: errmsg + integer, intent(out) :: errcode ! local variables type(string_t) :: solver_state @@ -132,6 +132,8 @@ subroutine micm_final(errmsg, errcode) errmsg = '' errcode = 0 + deallocate( micm ) + end subroutine micm_final end module musica_ccpp_micm diff --git a/schemes/musica/micm/musica_ccpp_micm_util.F90 b/schemes/musica/micm/musica_ccpp_micm_util.F90 index 1c912f3a..0261a4d7 100644 --- a/schemes/musica/micm/musica_ccpp_micm_util.F90 +++ b/schemes/musica/micm/musica_ccpp_micm_util.F90 @@ -13,14 +13,14 @@ subroutine reshape_into_micm_arr(temperature, pressure, dry_air_density, constit use iso_c_binding, only: c_double use ccpp_kinds, only: kind_phys - real(kind_phys), target, intent(in) :: temperature(:,:) ! K - real(kind_phys), target, intent(in) :: pressure(:,:) ! Pa - real(kind_phys), target, intent(in) :: dry_air_density(:,:) ! kg m-3 - real(kind_phys), target, intent(in) :: constituents(:,:,:) ! kg kg-1 - real(c_double), target, intent(out) :: micm_temperature(:) ! K - real(c_double), target, intent(out) :: micm_pressure(:) ! Pa - real(c_double), target, intent(out) :: micm_dry_air_density(:) ! kg m-3 - real(c_double), target, intent(out) :: micm_constituents(:) ! kg kg-1 + real(kind_phys), intent(in) :: temperature(:,:) ! K + real(kind_phys), intent(in) :: pressure(:,:) ! Pa + real(kind_phys), intent(in) :: dry_air_density(:,:) ! kg m-3 + real(kind_phys), intent(in) :: constituents(:,:,:) ! kg kg-1 + real(c_double), intent(out) :: micm_temperature(:) ! K + real(c_double), intent(out) :: micm_pressure(:) ! Pa + real(c_double), intent(out) :: micm_dry_air_density(:) ! kg m-3 + real(c_double), intent(out) :: micm_constituents(:) ! kg kg-1 ! local variables integer :: num_columns, num_layers, num_constituents @@ -83,6 +83,7 @@ subroutine convert_to_mol_per_cubic_meter(dry_air_density, molar_mass_arr, const real(kind_phys), intent(in) :: molar_mass_arr(:) ! kg mol-1 real(kind_phys), intent(inout) :: constituents(:,:,:) ! in: kg kg-1 | out: mol m-3 + ! local variables integer :: num_columns, num_layers, num_constituents integer :: i_column, i_layer, i_elem real(kind_phys) :: val diff --git a/schemes/musica/musica_ccpp.F90 b/schemes/musica/musica_ccpp.F90 index 36890cdb..0cc79a38 100644 --- a/schemes/musica/musica_ccpp.F90 +++ b/schemes/musica/musica_ccpp.F90 @@ -26,7 +26,7 @@ end subroutine musica_ccpp_register !> \section arg_table_musica_ccpp_init Argument Table !! \htmlinclude musica_ccpp_init.html subroutine musica_ccpp_init(vertical_layer_dimension, vertical_interface_dimension, & - errmsg, errcode) + errmsg, errcode) integer, intent(in) :: vertical_layer_dimension ! (count) integer, intent(in) :: vertical_interface_dimension ! (count) character(len=512), intent(out) :: errmsg @@ -45,25 +45,26 @@ end subroutine musica_ccpp_init subroutine musica_ccpp_run(time_step, temperature, pressure, dry_air_density, constituent_props, & constituents, geopotential_height_wrt_surface_at_midpoint, & geopotential_height_wrt_surface_at_interface, surface_geopotential, & - reciprocal_of_gravitational_acceleration, errmsg, errcode) + standard_gravitational_acceleration, errmsg, errcode) use musica_ccpp_micm_util, only: reshape_into_micm_arr, reshape_into_ccpp_arr use musica_ccpp_micm_util, only: convert_to_mol_per_cubic_meter, convert_to_mass_mixing_ratio use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t use ccpp_kinds, only: kind_phys use iso_c_binding, only: c_double - real(kind_phys), intent(in) :: time_step ! s - real(kind_phys), target, intent(in) :: temperature(:,:) ! K - real(kind_phys), target, intent(in) :: pressure(:,:) ! Pa - real(kind_phys), target, intent(in) :: dry_air_density(:,:) ! kg m-3 - type(ccpp_constituent_prop_ptr_t), intent(in) :: constituent_props(:) - real(kind_phys), target, intent(inout) :: constituents(:,:,:) ! kg kg-1 - real(kind_phys), target, intent(in) :: geopotential_height_wrt_surface_at_midpoint(:,:) ! m - real(kind_phys), target, intent(in) :: geopotential_height_wrt_surface_at_interface(:,:) ! m - real(kind_phys), target, intent(in) :: surface_geopotential(:) ! m2 s-2 - real(kind_phys), target, intent(in) :: reciprocal_of_gravitational_acceleration ! s2 m-1 - character(len=512), intent(out) :: errmsg - integer, intent(out) :: errcode + real(kind_phys), intent(in) :: time_step ! s + real(kind_phys), intent(in) :: temperature(:,:) ! K + real(kind_phys), intent(in) :: pressure(:,:) ! Pa + real(kind_phys), intent(in) :: dry_air_density(:,:) ! kg m-3 + type(ccpp_constituent_prop_ptr_t), & + intent(in) :: constituent_props(:) + real(kind_phys), intent(inout) :: constituents(:,:,:) ! kg kg-1 + real(kind_phys), intent(in) :: geopotential_height_wrt_surface_at_midpoint(:,:) ! m (column, layer) + real(kind_phys), intent(in) :: geopotential_height_wrt_surface_at_interface(:,:) ! m (column, interface) + real(kind_phys), intent(in) :: surface_geopotential(:) ! m2 s-2 + real(kind_phys), intent(in) :: standard_gravitational_acceleration ! m s-2 + character(len=512), intent(out) :: errmsg + integer, intent(out) :: errcode ! local variables real(c_double), target, dimension(size(temperature, dim=1) & @@ -83,10 +84,13 @@ subroutine musica_ccpp_run(time_step, temperature, pressure, dry_air_density, co * 3) :: photolysis_rate_constants ! s-1 integer :: i_elem - call tuvx_run(temperature, dry_air_density, geopotential_height_wrt_surface_at_midpoint, & + call tuvx_run(temperature, dry_air_density, & + geopotential_height_wrt_surface_at_midpoint, & geopotential_height_wrt_surface_at_interface, & - surface_geopotential, reciprocal_of_gravitational_acceleration, & - photolysis_rate_constants, errmsg, errcode) + surface_geopotential, & + standard_gravitational_acceleration, & + photolysis_rate_constants, & + errmsg, errcode) ! Get the molar mass that is set in the call to instantiate() do i_elem = 1, size(molar_mass_arr) @@ -115,8 +119,8 @@ subroutine musica_ccpp_run(time_step, temperature, pressure, dry_air_density, co micm_temperature, micm_pressure, micm_dry_air_density, micm_constituents) ! temporarily pass in unmapped photolysis rate constants until mapping between MICM and TUV-x is implemented - call micm_run(time_step, micm_temperature, micm_pressure, micm_dry_air_density, photolysis_rate_constants, & - micm_constituents, errmsg, errcode) + call micm_run(time_step, micm_temperature, micm_pressure, micm_dry_air_density, & + photolysis_rate_constants, micm_constituents, errmsg, errcode) ! Reshape array (1D -> 3D) and convert type (c_double -> kind_phys) call reshape_into_ccpp_arr(micm_constituents, constituents) diff --git a/schemes/musica/musica_ccpp.meta b/schemes/musica/musica_ccpp.meta index 8cca3abb..f62966f9 100644 --- a/schemes/musica/musica_ccpp.meta +++ b/schemes/musica/musica_ccpp.meta @@ -73,15 +73,15 @@ intent = inout [ geopotential_height_wrt_surface_at_midpoint ] standard_name = geopotential_height_wrt_surface - units = km + units = m type = real | kind = kind_phys dimensions = (horizontal_loop_extent,vertical_layer_dimension) intent = in [ geopotential_height_wrt_surface_at_interface ] standard_name = geopotential_height_wrt_surface_at_interface - units = km + units = m type = real | kind = kind_phys - dimensions = (horizontal_loop_extent,vertical_layer_dimension) + dimensions = (horizontal_loop_extent,vertical_interface_dimension) intent = in [ surface_geopotential ] standard_name = surface_geopotential @@ -89,9 +89,9 @@ units = m2 s-2 dimensions = (horizontal_loop_extent) intent = in -[ reciprocal_of_gravitational_acceleration ] - standard_name = reciprocal_of_gravitational_acceleration - units = s2 m-1 +[ standard_gravitational_acceleration ] + standard_name = standard_gravitational_acceleration + units = m s-2 type = real | kind = kind_phys dimensions = () intent = in diff --git a/schemes/musica/musica_ccpp_namelist.xml b/schemes/musica/musica_ccpp_namelist.xml index 9ab6b133..a8417876 100644 --- a/schemes/musica/musica_ccpp_namelist.xml +++ b/schemes/musica/musica_ccpp_namelist.xml @@ -97,7 +97,7 @@ filename_of_tuvx_configuration none - A configuration file for the TUVX photolysis rate calculator + A configuration file for the TUV-x photolysis rate calculator UNSET_PATH diff --git a/schemes/musica/tuvx/musica_ccpp_tuvx.F90 b/schemes/musica/tuvx/musica_ccpp_tuvx.F90 index ab43e5c8..25dc2029 100644 --- a/schemes/musica/tuvx/musica_ccpp_tuvx.F90 +++ b/schemes/musica/tuvx/musica_ccpp_tuvx.F90 @@ -17,9 +17,9 @@ module musica_ccpp_tuvx contains - !> Intitialize TUVX - subroutine tuvx_init(vertical_layer_dimension, & - vertical_interface_dimension, errmsg, errcode) + !> Intitialize TUV-x + subroutine tuvx_init( vertical_layer_dimension, vertical_interface_dimension, & + errmsg, errcode ) use musica_tuvx, only: grid_map_t, profile_map_t, radiator_map_t use musica_util, only: error_t use musica_ccpp_tuvx_height_grid, only: create_height_grid, & @@ -102,17 +102,17 @@ end subroutine tuvx_init subroutine tuvx_run( temperature, dry_air_density, & geopotential_height_wrt_surface_at_midpoint, & geopotential_height_wrt_surface_at_interface, & - surface_geopotential, reciprocal_of_gravitational_acceleration, & + surface_geopotential, standard_gravitational_acceleration, & photolysis_rate_constants, errmsg, errcode ) use musica_util, only: error_t use musica_ccpp_tuvx_height_grid, only: set_height_grid_values, calculate_heights - real(kind_phys), intent(in) :: temperature(:,:) ! K (column, layer) - real(kind_phys), intent(in) :: dry_air_density(:,:) ! molecule cm-3 (column, layer) + real(kind_phys), intent(in) :: temperature(:,:) ! K (column, layer) + real(kind_phys), intent(in) :: dry_air_density(:,:) ! kg m-3 (column, layer) real(kind_phys), intent(in) :: geopotential_height_wrt_surface_at_midpoint(:,:) ! m (column, layer) real(kind_phys), intent(in) :: geopotential_height_wrt_surface_at_interface(:,:) ! m (column, interface) - real(kind_phys), intent(in) :: surface_geopotential(:) ! m2 s-2 - real(kind_phys), intent(in) :: reciprocal_of_gravitational_acceleration ! s2 m-1 + real(kind_phys), intent(in) :: surface_geopotential(:) ! m2 s-2 + real(kind_phys), intent(in) :: standard_gravitational_acceleration ! m s-2 ! temporarily set to Chapman mechanism and 1 dimension ! until mapping between MICM and TUV-x is implemented real(kind_phys), intent(out) :: photolysis_rate_constants(:) ! s-1 (column, reaction) @@ -128,7 +128,7 @@ subroutine tuvx_run( temperature, dry_air_density, & call calculate_heights( geopotential_height_wrt_surface_at_midpoint(i_col,:), & geopotential_height_wrt_surface_at_interface(i_col,:), & surface_geopotential(i_col), & - reciprocal_of_gravitational_acceleration, & + standard_gravitational_acceleration, & height_midpoints, height_interfaces ) call set_height_grid_values( height_grid, height_midpoints, height_interfaces, & errmsg, errcode ) @@ -141,13 +141,14 @@ subroutine tuvx_run( temperature, dry_air_density, & end subroutine tuvx_run !> Finalize tuvx - subroutine tuvx_final(errmsg, errcode) + subroutine tuvx_final( errmsg, errcode ) character(len=512), intent(out) :: errmsg integer, intent(out) :: errcode errmsg = '' errcode = 0 deallocate( height_grid ) + deallocate( tuvx ) end subroutine tuvx_final diff --git a/schemes/musica/tuvx/musica_ccpp_tuvx_height_grid.F90 b/schemes/musica/tuvx/musica_ccpp_tuvx_height_grid.F90 index dfb2a5fd..42150f2d 100644 --- a/schemes/musica/tuvx/musica_ccpp_tuvx_height_grid.F90 +++ b/schemes/musica/tuvx/musica_ccpp_tuvx_height_grid.F90 @@ -5,10 +5,10 @@ module musica_ccpp_tuvx_height_grid private public :: create_height_grid, set_height_grid_values, calculate_heights - ! Conversions between the CAM-SIMA height grid and the TUVX height grid + ! Conversions between the CAM-SIMA height grid and the TUV-x height grid ! !----------------------------------------------------------------------- - ! Notes on the conversion between the host-model height grid and the TUVX + ! Notes on the conversion between the host-model height grid and the TUV-x ! ! TUV-x heights are "bottom-up" and require atmospheric constituent ! concentrations at interfaces. Therefore, CAM-SIMA mid-points are used @@ -52,7 +52,6 @@ module musica_ccpp_tuvx_height_grid !> Creates a TUV-x height grid function create_height_grid( vertical_layer_dimension, & vertical_interface_dimension, errmsg, errcode ) result( height_grid ) - use musica_ccpp_util, only: has_error_occurred use musica_tuvx_grid, only: grid_t use musica_util, only: error_t @@ -86,7 +85,6 @@ end function create_height_grid !> Sets TUV-x height grid values from the host-model height grid subroutine set_height_grid_values( height_grid, host_midpoints, & host_interfaces, errmsg, errcode ) - use ccpp_kinds, only: kind_phys use musica_ccpp_util, only: has_error_occurred use musica_tuvx_grid, only: grid_t @@ -146,30 +144,27 @@ end subroutine set_height_grid_values !! The equation used is taked from CAMChem !! (see https://github.com/ESCOMP/CAM/blob/f0e489e9708ce7b91635f6d4997fbf1e390b0dbb/src/chemistry/mozart/mo_gas_phase_chemdr.F90#L514-L526) subroutine calculate_heights( geopotential_height_wrt_surface_at_midpoint, & - geopotential_height_wrt_surface_at_interface, & - surface_geopotential, reciprocal_of_gravitational_acceleration, & - height_midpoints, height_interfaces ) - + geopotential_height_wrt_surface_at_interface, surface_geopotential, & + standard_gravitational_acceleration, height_midpoints, height_interfaces ) use ccpp_kinds, only: kind_phys real(kind_phys), intent(in) :: geopotential_height_wrt_surface_at_midpoint(:) ! m real(kind_phys), intent(in) :: geopotential_height_wrt_surface_at_interface(:) ! m - real(kind_phys), intent(in) :: surface_geopotential ! m2 s-2 - real(kind_phys), intent(in) :: reciprocal_of_gravitational_acceleration ! s2 m-1 - real(kind_phys), intent(out) :: height_midpoints(:) ! km - real(kind_phys), intent(out) :: height_interfaces(:) ! km + real(kind_phys), intent(in) :: surface_geopotential ! m2 s-2 + real(kind_phys), intent(in) :: standard_gravitational_acceleration ! m s-2 + real(kind_phys), intent(out) :: height_midpoints(:) ! km + real(kind_phys), intent(out) :: height_interfaces(:) ! km ! local variable real(kind_phys) :: surface_height ! m - surface_height = surface_geopotential * reciprocal_of_gravitational_acceleration - height_midpoints(:) = 0.001_kind_phys * & - ( geopotential_height_wrt_surface_at_midpoint(:) & - + surface_height ) - height_interfaces(:) = 0.001_kind_phys * & - ( geopotential_height_wrt_surface_at_interface(:) & - + surface_height ) + surface_height = & + surface_geopotential * ( 1.0_kind_phys / standard_gravitational_acceleration ) + height_midpoints(:) = & + 0.001_kind_phys * ( geopotential_height_wrt_surface_at_midpoint(:) + surface_height ) + height_interfaces(:) = & + 0.001_kind_phys * ( geopotential_height_wrt_surface_at_interface(:) + surface_height ) end subroutine calculate_heights -end module musica_ccpp_tuvx_height_grid +end module musica_ccpp_tuvx_height_grid \ No newline at end of file diff --git a/test/docker/Dockerfile.musica b/test/docker/Dockerfile.musica index d323ac74..65940f1a 100644 --- a/test/docker/Dockerfile.musica +++ b/test/docker/Dockerfile.musica @@ -1,3 +1,8 @@ +# This Dockerfile is designed for testing MUSICA CCPP functionality. +# It includes: +# - Unit tests for MUSICA utility functions +# - Integration tests for MUSICA CCPP APIs + FROM ubuntu:22.04 ARG MUSICA_GIT_TAG=dbbdb22f5f2807e27c2695db85291951ba178634 @@ -67,7 +72,7 @@ RUN sudo chown -R test_user:test_user atmospheric_physics RUN cd atmospheric_physics/test \ && mkdir lib \ && cd lib \ - && git clone -b add_const_interface --depth 1 https://github.com/peverwhee/ccpp-framework.git + && git clone -b develop --depth 1 https://github.com/NCAR/ccpp-framework.git ENV CCPP_SRC_PATH="lib/ccpp-framework/src" ENV CCPP_FORTRAN_TOOLS_PATH="lib/ccpp-framework/scripts/fortran_tools" diff --git a/test/docker/Dockerfile.musica.no_install b/test/docker/Dockerfile.musica.no_install index efae2737..74fc8b63 100644 --- a/test/docker/Dockerfile.musica.no_install +++ b/test/docker/Dockerfile.musica.no_install @@ -1,3 +1,11 @@ +# This Dockerfile is designed for testing MUSICA CCPP functionality. +# It includes: +# - Unit tests for MUSICA utility functions +# - Integration tests for MUSICA CCPP APIs +# +# Note: No installation is required, as the CMake FetchContent module +# retrieves the MUSICA library automatically. + FROM ubuntu:22.04 ARG MUSICA_GIT_TAG=dbbdb22f5f2807e27c2695db85291951ba178634 @@ -51,7 +59,7 @@ RUN sudo chown -R test_user:test_user atmospheric_physics RUN cd atmospheric_physics/test \ && mkdir lib \ && cd lib \ - && git clone -b add_const_interface --depth 1 https://github.com/peverwhee/ccpp-framework.git + && git clone -b develop --depth 1 https://github.com/NCAR/ccpp-framework.git ENV CCPP_SRC_PATH="lib/ccpp-framework/src" ENV CCPP_FORTRAN_TOOLS_PATH="lib/ccpp-framework/scripts/fortran_tools" diff --git a/test/musica/micm/test_micm_util.F90 b/test/musica/micm/test_micm_util.F90 index 3b5f80c5..f735235a 100644 --- a/test/musica/micm/test_micm_util.F90 +++ b/test/musica/micm/test_micm_util.F90 @@ -16,18 +16,18 @@ subroutine test_reshape() use iso_c_binding, only: c_double use ccpp_kinds, only: kind_phys - integer, parameter :: NUM_SPECIES = 4 - integer, parameter :: NUM_COLUMNS = 2 - integer, parameter :: NUM_LAYERS = 2 - integer, parameter :: NUM_GRID_CELLS = 4 - real(kind_phys), target :: temperature(NUM_COLUMNS,NUM_LAYERS) - real(kind_phys), target :: pressure(NUM_COLUMNS,NUM_LAYERS) - real(kind_phys), target :: dry_air_density(NUM_COLUMNS,NUM_LAYERS) - real(kind_phys), target :: constituents(NUM_COLUMNS,NUM_LAYERS,NUM_SPECIES) - real(c_double), target :: micm_temperature(NUM_GRID_CELLS) - real(c_double), target :: micm_pressure(NUM_GRID_CELLS) - real(c_double), target :: micm_dry_air_density(NUM_GRID_CELLS) - real(c_double), target :: micm_constituents(NUM_GRID_CELLS*NUM_SPECIES) + integer, parameter :: NUM_SPECIES = 4 + integer, parameter :: NUM_COLUMNS = 2 + integer, parameter :: NUM_LAYERS = 2 + integer, parameter :: NUM_GRID_CELLS = 4 + real(kind_phys) :: temperature(NUM_COLUMNS,NUM_LAYERS) + real(kind_phys) :: pressure(NUM_COLUMNS,NUM_LAYERS) + real(kind_phys) :: dry_air_density(NUM_COLUMNS,NUM_LAYERS) + real(kind_phys) :: constituents(NUM_COLUMNS,NUM_LAYERS,NUM_SPECIES) + real(c_double) :: micm_temperature(NUM_GRID_CELLS) + real(c_double) :: micm_pressure(NUM_GRID_CELLS) + real(c_double) :: micm_dry_air_density(NUM_GRID_CELLS) + real(c_double) :: micm_constituents(NUM_GRID_CELLS*NUM_SPECIES) ! local variables real(c_double), dimension(NUM_GRID_CELLS) :: arr_conditions diff --git a/test/musica/test_musica_api.F90 b/test/musica/test_musica_api.F90 index 7b82e92f..9fdcfd1f 100644 --- a/test/musica/test_musica_api.F90 +++ b/test/musica/test_musica_api.F90 @@ -18,22 +18,22 @@ subroutine test_musica_ccpp_api() implicit none - integer, parameter :: NUM_SPECIES = 4 - integer, parameter :: NUM_COLUMNS = 2 - integer, parameter :: NUM_LAYERS = 2 - integer :: solver_type - integer :: errcode - character(len=512) :: errmsg - real(kind_phys) :: time_step ! s - real(kind_phys), dimension(NUM_COLUMNS,NUM_LAYERS) :: geopotential_height_wrt_surface_at_midpoint ! m - real(kind_phys), dimension(NUM_COLUMNS,NUM_LAYERS+1) :: geopotential_height_wrt_surface_at_interface ! m - real(kind_phys), dimension(NUM_COLUMNS) :: surface_geopotential ! m2 s-2 - real(kind_phys) :: reciprocal_of_gravitational_acceleration ! s2 m-1 - real(kind_phys), target, dimension(NUM_COLUMNS,NUM_LAYERS) :: temperature ! K - real(kind_phys), target, dimension(NUM_COLUMNS,NUM_LAYERS) :: pressure ! Pa - real(kind_phys), target, dimension(NUM_COLUMNS,NUM_LAYERS) :: dry_air_density ! kg m-3 - real(kind_phys), target, dimension(NUM_COLUMNS,NUM_LAYERS,NUM_SPECIES) :: constituents ! kg kg-1 - type(ccpp_constituent_prop_ptr_t), allocatable :: constituent_props_ptr(:) + integer, parameter :: NUM_SPECIES = 4 + integer, parameter :: NUM_COLUMNS = 2 + integer, parameter :: NUM_LAYERS = 2 + integer :: solver_type + integer :: errcode + character(len=512) :: errmsg + real(kind_phys) :: time_step ! s + real(kind_phys), dimension(NUM_COLUMNS,NUM_LAYERS) :: geopotential_height_wrt_surface_at_midpoint ! m + real(kind_phys), dimension(NUM_COLUMNS,NUM_LAYERS+1) :: geopotential_height_wrt_surface_at_interface ! m + real(kind_phys), dimension(NUM_COLUMNS) :: surface_geopotential ! m2 s-2 + real(kind_phys) :: standard_gravitational_acceleration ! s2 m-1 + real(kind_phys), dimension(NUM_COLUMNS,NUM_LAYERS) :: temperature ! K + real(kind_phys), dimension(NUM_COLUMNS,NUM_LAYERS) :: pressure ! Pa + real(kind_phys), dimension(NUM_COLUMNS,NUM_LAYERS) :: dry_air_density ! kg m-3 + real(kind_phys), dimension(NUM_COLUMNS,NUM_LAYERS,NUM_SPECIES) :: constituents ! kg kg-1 + type(ccpp_constituent_prop_ptr_t), allocatable :: constituent_props_ptr(:) ! local variables type(ccpp_constituent_properties_t), allocatable, target :: constituent_props(:) @@ -52,7 +52,7 @@ subroutine test_musica_ccpp_api() geopotential_height_wrt_surface_at_interface(1,:) = (/ 3000.0_kind_phys, 1000.0_kind_phys, 0.0_kind_phys /) geopotential_height_wrt_surface_at_interface(2,:) = (/ 3000.0_kind_phys, 500.0_kind_phys, -1500.0_kind_phys /) surface_geopotential = (/ 100.0_kind_phys, 200.0_kind_phys /) - reciprocal_of_gravitational_acceleration = 10.0_kind_phys + standard_gravitational_acceleration = 10.0_kind_phys temperature(:,1) = (/ 100._kind_phys, 200._kind_phys /) temperature(:,2) = (/ 300._kind_phys, 400._kind_phys /) pressure(:,1) = (/ 6000.04_kind_phys, 7000.04_kind_phys /) @@ -114,7 +114,7 @@ subroutine test_musica_ccpp_api() call musica_ccpp_run(time_step, temperature, pressure, dry_air_density, constituent_props_ptr, & constituents, geopotential_height_wrt_surface_at_midpoint, & geopotential_height_wrt_surface_at_interface, surface_geopotential, & - reciprocal_of_gravitational_acceleration, errmsg, errcode) + standard_gravitational_acceleration, errmsg, errcode) if (errcode /= 0) then write(*,*) trim(errmsg) stop 3 diff --git a/test/musica/tuvx/test_tuvx_height_grid.F90 b/test/musica/tuvx/test_tuvx_height_grid.F90 index c0f5c6ed..a0ed0d84 100644 --- a/test/musica/tuvx/test_tuvx_height_grid.F90 +++ b/test/musica/tuvx/test_tuvx_height_grid.F90 @@ -78,18 +78,18 @@ subroutine test_calculate_height_grid_values() real(kind_phys), dimension(NUM_LAYERS) :: geopotential_height_wrt_surface_at_midpoint ! m real(kind_phys), dimension(NUM_LAYERS+1) :: geopotential_height_wrt_surface_at_interface ! m real(kind_phys) :: surface_geopotential ! m2 s-2 - real(kind_phys) :: reciprocal_of_gravitational_acceleration ! s2 m-1 + real(kind_phys) :: standard_gravitational_acceleration ! m s-2 real(kind_phys), dimension(NUM_LAYERS) :: height_midpoints ! km real(kind_phys), dimension(NUM_LAYERS+1) :: height_interfaces ! km geopotential_height_wrt_surface_at_midpoint(:) = (/ 2000.0_kind_phys, 500.0_kind_phys /) geopotential_height_wrt_surface_at_interface(:) = (/ 3000.0_kind_phys, 1000.0_kind_phys, 0.0_kind_phys /) surface_geopotential = 100.0_kind_phys - reciprocal_of_gravitational_acceleration = 10.0_kind_phys + standard_gravitational_acceleration = 0.1_kind_phys call calculate_heights(geopotential_height_wrt_surface_at_midpoint, & geopotential_height_wrt_surface_at_interface, & - surface_geopotential, reciprocal_of_gravitational_acceleration, & + surface_geopotential, standard_gravitational_acceleration, & height_midpoints, height_interfaces) ASSERT_NEAR(height_midpoints(1), 3.0, 1e-5) From 2f82f9a8d32682dd074a9d4ddb014ec697faed4c Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Mon, 21 Oct 2024 17:29:28 -0600 Subject: [PATCH 2/3] remove target attribute --- schemes/musica/musica_ccpp.F90 | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/schemes/musica/musica_ccpp.F90 b/schemes/musica/musica_ccpp.F90 index 0cc79a38..c486bee5 100644 --- a/schemes/musica/musica_ccpp.F90 +++ b/schemes/musica/musica_ccpp.F90 @@ -67,21 +67,21 @@ subroutine musica_ccpp_run(time_step, temperature, pressure, dry_air_density, co integer, intent(out) :: errcode ! local variables - real(c_double), target, dimension(size(temperature, dim=1) & - * size(temperature, dim=2)) :: micm_temperature - real(c_double), target, dimension(size(pressure, dim=1) & - * size(pressure, dim=2)) :: micm_pressure - real(c_double), target, dimension(size(dry_air_density, dim=1) & - * size(dry_air_density, dim=2)) :: micm_dry_air_density - real(c_double), target, dimension(size(constituents, dim=1) & - * size(constituents, dim=2) & - * size(constituents, dim=3)) :: micm_constituents ! mol m-3 - real(kind_phys), target, dimension(size(constituents, dim=3)) :: molar_mass_arr ! kg mol-1 + real(c_double), dimension(size(temperature, dim=1) & + * size(temperature, dim=2)) :: micm_temperature + real(c_double), dimension(size(pressure, dim=1) & + * size(pressure, dim=2)) :: micm_pressure + real(c_double), dimension(size(dry_air_density, dim=1) & + * size(dry_air_density, dim=2)) :: micm_dry_air_density + real(c_double), dimension(size(constituents, dim=1) & + * size(constituents, dim=2) & + * size(constituents, dim=3)) :: micm_constituents ! mol m-3 + real(kind_phys), dimension(size(constituents, dim=3)) :: molar_mass_arr ! kg mol-1 ! temporarily dimensioned to Chapman mechanism until mapping between MICM and TUV-x is implemented - real(c_double), target, dimension(size(constituents, dim=1) & - * size(constituents, dim=2) & - * 3) :: photolysis_rate_constants ! s-1 + real(c_double), dimension(size(constituents, dim=1) & + * size(constituents, dim=2) & + * 3) :: photolysis_rate_constants ! s-1 integer :: i_elem call tuvx_run(temperature, dry_air_density, & From 05ebaa0c7d744e7e6415bb53c91f1fa9bd697cbf Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Mon, 21 Oct 2024 18:02:45 -0600 Subject: [PATCH 3/3] formatting --- schemes/musica/micm/musica_ccpp_micm.F90 | 2 +- schemes/musica/micm/musica_ccpp_micm_util.F90 | 5 +++-- schemes/musica/tuvx/musica_ccpp_tuvx.F90 | 21 +++++++++--------- .../tuvx/musica_ccpp_tuvx_height_grid.F90 | 22 ++++++++++--------- test/docker/Dockerfile.musica.no_install | 4 ++-- test/musica/micm/test_micm_util.F90 | 22 +++++++++---------- test/musica/musica_ccpp_namelist.F90 | 4 ++-- 7 files changed, 42 insertions(+), 38 deletions(-) diff --git a/schemes/musica/micm/musica_ccpp_micm.F90 b/schemes/musica/micm/musica_ccpp_micm.F90 index 7b7310ee..9d10f004 100644 --- a/schemes/musica/micm/musica_ccpp_micm.F90 +++ b/schemes/musica/micm/musica_ccpp_micm.F90 @@ -88,7 +88,7 @@ end subroutine micm_init !> Solve chemistry at the current time step subroutine micm_run(time_step, temperature, pressure, dry_air_density, & - user_defined_rate_parameters, constituents, errmsg, errcode) + user_defined_rate_parameters, constituents, errmsg, errcode) use musica_micm, only: solver_stats_t use musica_util, only: string_t, error_t use iso_c_binding, only: c_double diff --git a/schemes/musica/micm/musica_ccpp_micm_util.F90 b/schemes/musica/micm/musica_ccpp_micm_util.F90 index 0261a4d7..47b92c81 100644 --- a/schemes/musica/micm/musica_ccpp_micm_util.F90 +++ b/schemes/musica/micm/musica_ccpp_micm_util.F90 @@ -8,8 +8,9 @@ module musica_ccpp_micm_util contains !> Reshape array (2D/3D -> 1D) and convert type (kind_phys -> c_double) - subroutine reshape_into_micm_arr(temperature, pressure, dry_air_density, constituents, & - micm_temperature, micm_pressure, micm_dry_air_density, micm_constituents) + subroutine reshape_into_micm_arr(temperature, pressure, dry_air_density, constituents, & + micm_temperature, micm_pressure, micm_dry_air_density, & + micm_constituents) use iso_c_binding, only: c_double use ccpp_kinds, only: kind_phys diff --git a/schemes/musica/tuvx/musica_ccpp_tuvx.F90 b/schemes/musica/tuvx/musica_ccpp_tuvx.F90 index 25dc2029..48779c93 100644 --- a/schemes/musica/tuvx/musica_ccpp_tuvx.F90 +++ b/schemes/musica/tuvx/musica_ccpp_tuvx.F90 @@ -18,12 +18,12 @@ module musica_ccpp_tuvx contains !> Intitialize TUV-x - subroutine tuvx_init( vertical_layer_dimension, vertical_interface_dimension, & - errmsg, errcode ) + subroutine tuvx_init(vertical_layer_dimension, vertical_interface_dimension, & + errmsg, errcode) use musica_tuvx, only: grid_map_t, profile_map_t, radiator_map_t use musica_util, only: error_t use musica_ccpp_tuvx_height_grid, only: create_height_grid, & - height_grid_label, height_grid_units + height_grid_label, height_grid_unit integer, intent(in) :: vertical_layer_dimension ! (count) integer, intent(in) :: vertical_interface_dimension ! (count) @@ -86,7 +86,7 @@ subroutine tuvx_init( vertical_layer_dimension, vertical_interface_dimension, & return end if - height_grid => grids%get( height_grid_label, height_grid_units, error ) + height_grid => grids%get( height_grid_label, height_grid_unit, error ) if (has_error_occurred( error, errmsg, errcode )) then deallocate( tuvx ) tuvx => null() @@ -99,11 +99,12 @@ subroutine tuvx_init( vertical_layer_dimension, vertical_interface_dimension, & end subroutine tuvx_init !> Calculates photolysis rate constants for the current model conditions - subroutine tuvx_run( temperature, dry_air_density, & - geopotential_height_wrt_surface_at_midpoint, & - geopotential_height_wrt_surface_at_interface, & - surface_geopotential, standard_gravitational_acceleration, & - photolysis_rate_constants, errmsg, errcode ) + subroutine tuvx_run(temperature, dry_air_density, & + geopotential_height_wrt_surface_at_midpoint, & + geopotential_height_wrt_surface_at_interface, & + surface_geopotential, & + standard_gravitational_acceleration, & + photolysis_rate_constants, errmsg, errcode) use musica_util, only: error_t use musica_ccpp_tuvx_height_grid, only: set_height_grid_values, calculate_heights @@ -141,7 +142,7 @@ subroutine tuvx_run( temperature, dry_air_density, & end subroutine tuvx_run !> Finalize tuvx - subroutine tuvx_final( errmsg, errcode ) + subroutine tuvx_final(errmsg, errcode) character(len=512), intent(out) :: errmsg integer, intent(out) :: errcode diff --git a/schemes/musica/tuvx/musica_ccpp_tuvx_height_grid.F90 b/schemes/musica/tuvx/musica_ccpp_tuvx_height_grid.F90 index 42150f2d..a91e98d4 100644 --- a/schemes/musica/tuvx/musica_ccpp_tuvx_height_grid.F90 +++ b/schemes/musica/tuvx/musica_ccpp_tuvx_height_grid.F90 @@ -44,14 +44,14 @@ module musica_ccpp_tuvx_height_grid !> Label for height grid in TUV-x character(len=*), parameter, public :: height_grid_label = "height" - !> Units for height grid in TUV-x - character(len=*), parameter, public :: height_grid_units = "km" + !> Unit for height grid in TUV-x + character(len=*), parameter, public :: height_grid_unit = "km" contains !> Creates a TUV-x height grid - function create_height_grid( vertical_layer_dimension, & - vertical_interface_dimension, errmsg, errcode ) result( height_grid ) + function create_height_grid(vertical_layer_dimension, vertical_interface_dimension, & + errmsg, errcode) result(height_grid) use musica_ccpp_util, only: has_error_occurred use musica_tuvx_grid, only: grid_t use musica_util, only: error_t @@ -76,15 +76,15 @@ function create_height_grid( vertical_layer_dimension, & errcode = 1 return end if - height_grid => grid_t( height_grid_label, height_grid_units, & + height_grid => grid_t( height_grid_label, height_grid_unit, & vertical_interface_dimension, error ) if ( has_error_occurred( error, errmsg, errcode ) ) return end function create_height_grid !> Sets TUV-x height grid values from the host-model height grid - subroutine set_height_grid_values( height_grid, host_midpoints, & - host_interfaces, errmsg, errcode ) + subroutine set_height_grid_values(height_grid, host_midpoints, & + host_interfaces, errmsg, errcode) use ccpp_kinds, only: kind_phys use musica_ccpp_util, only: has_error_occurred use musica_tuvx_grid, only: grid_t @@ -143,9 +143,11 @@ end subroutine set_height_grid_values !! !! The equation used is taked from CAMChem !! (see https://github.com/ESCOMP/CAM/blob/f0e489e9708ce7b91635f6d4997fbf1e390b0dbb/src/chemistry/mozart/mo_gas_phase_chemdr.F90#L514-L526) - subroutine calculate_heights( geopotential_height_wrt_surface_at_midpoint, & - geopotential_height_wrt_surface_at_interface, surface_geopotential, & - standard_gravitational_acceleration, height_midpoints, height_interfaces ) + subroutine calculate_heights(geopotential_height_wrt_surface_at_midpoint, & + geopotential_height_wrt_surface_at_interface, & + surface_geopotential, & + standard_gravitational_acceleration, & + height_midpoints, height_interfaces) use ccpp_kinds, only: kind_phys real(kind_phys), intent(in) :: geopotential_height_wrt_surface_at_midpoint(:) ! m diff --git a/test/docker/Dockerfile.musica.no_install b/test/docker/Dockerfile.musica.no_install index 74fc8b63..b59489af 100644 --- a/test/docker/Dockerfile.musica.no_install +++ b/test/docker/Dockerfile.musica.no_install @@ -3,8 +3,8 @@ # - Unit tests for MUSICA utility functions # - Integration tests for MUSICA CCPP APIs # -# Note: No installation is required, as the CMake FetchContent module -# retrieves the MUSICA library automatically. +# No MUSICA library installation is required, as the CMake FetchContent module +# retrieves the MUSICA library automatically. FROM ubuntu:22.04 diff --git a/test/musica/micm/test_micm_util.F90 b/test/musica/micm/test_micm_util.F90 index f735235a..5581d5d8 100644 --- a/test/musica/micm/test_micm_util.F90 +++ b/test/musica/micm/test_micm_util.F90 @@ -45,7 +45,6 @@ subroutine test_reshape() constituents(1,2,:) = (/ 0.41_kind_phys, 0.42_kind_phys, 0.43_kind_phys, 0.44_kind_phys /) constituents(2,1,:) = (/ 0.21_kind_phys, 0.22_kind_phys, 0.23_kind_phys, 0.24_kind_phys /) constituents(2,2,:) = (/ 0.31_kind_phys, 0.32_kind_phys, 0.33_kind_phys, 0.34_kind_phys /) - arr_conditions = (/ 100.0, 200.0, 300.0, 400.0 /) arr_constituents = (/ 0.1, 0.2, 0.3, 0.4, 0.21, 0.22, 0.23, 0.24, 0.41, 0.42, 0.43, 0.44, 0.31, 0.32, 0.33, 0.34 /) @@ -79,16 +78,17 @@ end subroutine test_reshape subroutine test_unit_conversion() use ccpp_kinds, only: kind_phys - integer, parameter :: NUM_COLUMNS = 2 - integer, parameter :: NUM_LAYERS = 2 - integer, parameter :: NUM_SPECIES = 4 - real(kind_phys), target, dimension(NUM_COLUMNS,NUM_LAYERS) :: dry_air_density ! kg m-3 - real(kind_phys), target, dimension(NUM_SPECIES) :: molar_mass_arr - real(kind_phys), target, dimension(NUM_COLUMNS,NUM_LAYERS,NUM_SPECIES) :: constituents - real(kind_phys), target, dimension(NUM_COLUMNS,NUM_LAYERS,NUM_SPECIES) :: ccpp_constituents ! kg kg-1 - real(kind_phys), target, dimension(NUM_COLUMNS,NUM_LAYERS,NUM_SPECIES) :: micm_constituents ! mol m-3 - integer :: i_column, i_layer, i_elem - real :: abs_error = 1e-3 + integer, parameter :: NUM_COLUMNS = 2 + integer, parameter :: NUM_LAYERS = 2 + integer, parameter :: NUM_SPECIES = 4 + real(kind_phys), dimension(NUM_COLUMNS,NUM_LAYERS) :: dry_air_density ! kg m-3 + real(kind_phys), dimension(NUM_SPECIES) :: molar_mass_arr + real(kind_phys), dimension(NUM_COLUMNS,NUM_LAYERS,NUM_SPECIES) :: constituents + real(kind_phys), dimension(NUM_COLUMNS,NUM_LAYERS,NUM_SPECIES) :: ccpp_constituents ! kg kg-1 + real(kind_phys), dimension(NUM_COLUMNS,NUM_LAYERS,NUM_SPECIES) :: micm_constituents ! mol m-3 + integer :: i_column, i_layer, i_elem + real :: abs_error = 1e-3 + dry_air_density(:,1) = (/ 3.5_kind_phys, 4.5_kind_phys /) dry_air_density(:,2) = (/ 5.5_kind_phys, 6.5_kind_phys /) molar_mass_arr(:) = (/ 200._kind_phys, 200._kind_phys, 200._kind_phys, 200._kind_phys /) diff --git a/test/musica/musica_ccpp_namelist.F90 b/test/musica/musica_ccpp_namelist.F90 index a3e507c9..69c803b3 100644 --- a/test/musica/musica_ccpp_namelist.F90 +++ b/test/musica/musica_ccpp_namelist.F90 @@ -3,9 +3,9 @@ module musica_ccpp_namelist implicit none - public :: filename_of_micm_configuration, filename_of_tuvx_configuration private - + public :: filename_of_micm_configuration, filename_of_tuvx_configuration + character(len=*), parameter :: filename_of_micm_configuration = 'chapman' character(len=*), parameter :: filename_of_tuvx_configuration = 'configs/ts1_tsmlt.json'