Skip to content

Commit

Permalink
Add cloud optical calculations for use in TUV-x (#167)
Browse files Browse the repository at this point in the history
Adds the calculation of cloud optical properties to TUV-x for photolysis
rate constant calculations. The algorithm is adapted from a
post-calculation modification of photolysis rate constants calculated by
the lookup version of TUV-x in CAM to account for the effects of clouds,
[here](https://github.com/ESCOMP/CAM/blob/47dd341f83afc1e1faf28fd4cb6e463629db4c19/src/chemistry/mozart/mo_photo.F90#L949-L965)

closes #100 

Adds a few more Valgrind suppressions for minor memory leaks during
initialization functions in 2 tests (9 and 72 bytes). We will look into
these, but they are expected to go away as TUV-x is moved out of
Fortran.
  • Loading branch information
mattldawson authored Nov 27, 2024
1 parent 045b630 commit 557e42a
Show file tree
Hide file tree
Showing 10 changed files with 574 additions and 61 deletions.
43 changes: 30 additions & 13 deletions schemes/musica/musica_ccpp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module musica_ccpp
use musica_ccpp_micm, only: micm_register, micm_init, micm_run, micm_final
use musica_ccpp_namelist, only: filename_of_tuvx_micm_mapping_configuration
use musica_ccpp_tuvx, only: tuvx_init, tuvx_run, tuvx_final
use musica_ccpp_tuvx, only: tuvx_register, tuvx_init, tuvx_run, tuvx_final
use musica_util, only: index_mappings_t

implicit none
Expand All @@ -24,29 +24,42 @@ subroutine musica_ccpp_register(micm_solver_type, number_of_grid_cells, &
character(len=512), intent(out) :: errmsg
integer, intent(out) :: errcode

call micm_register(micm_solver_type, number_of_grid_cells, constituent_props, &
type(ccpp_constituent_properties_t), allocatable :: constituent_props_subset(:)

call micm_register(micm_solver_type, number_of_grid_cells, constituent_props_subset, &
errmsg, errcode)
if (errcode /= 0) return
constituent_props = constituent_props_subset
deallocate(constituent_props_subset)

call tuvx_register(constituent_props_subset, errmsg, errcode)
if (errcode /= 0) return
constituent_props = [ constituent_props, constituent_props_subset ]

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, &
photolysis_wavelength_grid_interfaces, errmsg, errcode)
photolysis_wavelength_grid_interfaces, &
constituent_props, errmsg, errcode)
use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t
use ccpp_kinds, only : kind_phys
use musica_ccpp_micm, only: micm
use musica_ccpp_util, only: has_error_occurred
integer, intent(in) :: vertical_layer_dimension ! (count)
integer, intent(in) :: vertical_interface_dimension ! (count)
real(kind_phys), intent(in) :: photolysis_wavelength_grid_interfaces(:) ! m
character(len=512), intent(out) :: errmsg
integer, intent(out) :: errcode
integer, intent(in) :: vertical_layer_dimension ! (count)
integer, intent(in) :: vertical_interface_dimension ! (count)
real(kind_phys), intent(in) :: photolysis_wavelength_grid_interfaces(:) ! m
type(ccpp_constituent_prop_ptr_t), intent(in) :: constituent_props(:)
character(len=512), intent(out) :: errmsg
integer, intent(out) :: errcode

call micm_init(errmsg, errcode)
if (errcode /= 0) return
call tuvx_init(vertical_layer_dimension, vertical_interface_dimension, &
photolysis_wavelength_grid_interfaces, &
micm%user_defined_reaction_rates, errmsg, errcode)
micm%user_defined_reaction_rates, &
constituent_props, errmsg, errcode)
if (errcode /= 0) return

end subroutine musica_ccpp_init
Expand All @@ -62,8 +75,9 @@ subroutine musica_ccpp_run(time_step, temperature, pressure, dry_air_density, co
geopotential_height_wrt_surface_at_interface, surface_geopotential, &
surface_temperature, surface_albedo, &
number_of_photolysis_wavelength_grid_sections, &
photolysis_wavelength_grid_interfaces, extraterrestrial_flux, &
standard_gravitational_acceleration, errmsg, errcode)
photolysis_wavelength_grid_interfaces, extraterrestrial_flux, &
standard_gravitational_acceleration, cloud_area_fraction, &
air_pressure_thickness, errmsg, errcode)
use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t
use ccpp_kinds, only: kind_phys
use musica_ccpp_micm, only: number_of_rate_parameters
Expand All @@ -85,6 +99,8 @@ subroutine musica_ccpp_run(time_step, temperature, pressure, dry_air_density, co
real(kind_phys), intent(in) :: photolysis_wavelength_grid_interfaces(:) ! nm
real(kind_phys), intent(in) :: extraterrestrial_flux(:) ! photons cm-2 s-1 nm-1
real(kind_phys), intent(in) :: standard_gravitational_acceleration ! m s-2
real(kind_phys), intent(in) :: cloud_area_fraction(:,:) ! unitless (column, level)
real(kind_phys), intent(in) :: air_pressure_thickness(:,:) ! Pa (column, level)
character(len=512), intent(out) :: errmsg
integer, intent(out) :: errcode

Expand All @@ -105,7 +121,8 @@ subroutine musica_ccpp_run(time_step, temperature, pressure, dry_air_density, co
photolysis_wavelength_grid_interfaces, &
extraterrestrial_flux, &
standard_gravitational_acceleration, &
rate_parameters, &
cloud_area_fraction, constituents, &
air_pressure_thickness, rate_parameters, &
errmsg, errcode)

! Get the molar mass that is set in the call to instantiate()
Expand Down Expand Up @@ -150,4 +167,4 @@ subroutine musica_ccpp_final(errmsg, errcode)

end subroutine musica_ccpp_final

end module musica_ccpp
end module musica_ccpp
18 changes: 18 additions & 0 deletions schemes/musica/musica_ccpp.meta
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
type = real | kind = kind_phys
dimensions = (photolysis_wavelength_grid_interface_dimension)
intent = in
[ constituent_props ]
standard_name = ccpp_constituent_properties
units = None
type = ccpp_constituent_prop_ptr_t
dimensions = (number_of_ccpp_constituents)
intent = in
[ errmsg ]
standard_name = ccpp_error_message
units = none
Expand Down Expand Up @@ -165,6 +171,18 @@
type = real | kind = kind_phys
dimensions = ()
intent = in
[ cloud_area_fraction ]
standard_name = cloud_area_fraction
units = fraction
type = real | kind = kind_phys
dimensions = (horizontal_loop_extent,vertical_layer_dimension)
intent = in
[ air_pressure_thickness ]
standard_name = air_pressure_thickness
units = Pa
type = real | kind = kind_phys
dimensions = (horizontal_loop_extent,vertical_layer_dimension)
intent = in
[ errmsg ]
standard_name = ccpp_error_message
units = none
Expand Down
Loading

0 comments on commit 557e42a

Please sign in to comment.