Skip to content

Commit

Permalink
Solar zenith angle and Earth-Sun distance (ESCOMP#171)
Browse files Browse the repository at this point in the history
Adds the calculation of solar zenith angle and Earth-Sun distance needed
as inputs to TUV-x.

closes ESCOMP#163 
closes ESCOMP#164 

Both calculations required functions that are currently in shared code
in CAM
[here](https://github.com/ESCOMP/CESM_share/blob/f6f31fd61cb8f80aee97311fcca64b3e26b0202c/src/shr_orb_mod.F90#L736-L814)
and
[here](https://github.com/ESCOMP/CESM_share/blob/f6f31fd61cb8f80aee97311fcca64b3e26b0202c/src/shr_orb_mod.F90#L110-L159)
that I put in a modified form in the `to_be_ccppized/` folder. @nusbaume
@peverwhee - if there is a better way to handle these functions, let me
know and I can update the PR.

Requires an update to CAM-SIMA that is in review to make certain
variables available through CCPP
(ESCOMP/CAM-SIMA#325)

After more discussion, the plan is to use the shared functions in
CAM-SIMA and pass the outputs through CCPP. So, this PR will be put in
draft until this issue is finished:
ESCOMP/CAM-SIMA#328

A related draft PR to CAM-SIMA has been added
(ESCOMP/CAM-SIMA#337) and will be un-drafted
once this PR is merged in.
  • Loading branch information
mattldawson authored Dec 14, 2024
1 parent e7a599f commit 8a9f22a
Show file tree
Hide file tree
Showing 13 changed files with 170 additions and 109 deletions.
4 changes: 4 additions & 0 deletions schemes/musica/micm/musica_ccpp_micm.F90
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ subroutine micm_register(solver_type, number_of_grid_cells, constituent_props, &
logical :: is_advected
integer :: i, species_index

if (associated( micm )) then
deallocate( micm )
micm => null()
end if
micm => micm_t(trim(filename_of_micm_configuration), solver_type, &
number_of_grid_cells, error)
if (has_error_occurred(error, errmsg, errcode)) return
Expand Down
44 changes: 32 additions & 12 deletions schemes/musica/musica_ccpp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,23 @@ module musica_ccpp

!> \section arg_table_musica_ccpp_register Argument Table
!! \htmlinclude musica_ccpp_register.html
subroutine musica_ccpp_register(micm_solver_type, number_of_grid_cells, &
constituent_props, errmsg, errcode)
subroutine musica_ccpp_register(constituent_props, errmsg, &
errcode)
use ccpp_constituent_prop_mod, only: ccpp_constituent_properties_t
use musica_ccpp_namelist, only: micm_solver_type

integer, intent(in) :: micm_solver_type
integer, intent(in) :: number_of_grid_cells
type(ccpp_constituent_properties_t), allocatable, intent(out) :: constituent_props(:)
character(len=512), intent(out) :: errmsg
integer, intent(out) :: errcode

type(ccpp_constituent_properties_t), allocatable :: constituent_props_subset(:)
integer :: number_of_grid_cells

! Temporary fix until the number of grid cells is only needed to create a MICM state
! instead of when the solver is created.
! The number of grid cells is not known at this point, so we set it to 1 and recreate
! the solver when the number of grid cells is known at the init stage.
number_of_grid_cells = 1
call micm_register(micm_solver_type, number_of_grid_cells, constituent_props_subset, &
errmsg, errcode)
if (errcode /= 0) return
Expand All @@ -40,20 +45,31 @@ 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, &
subroutine musica_ccpp_init(horizontal_dimension, vertical_layer_dimension, &
vertical_interface_dimension, &
photolysis_wavelength_grid_interfaces, &
constituent_props, errmsg, errcode)
use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t
use ccpp_constituent_prop_mod, only: ccpp_constituent_properties_t, ccpp_constituent_prop_ptr_t
use ccpp_kinds, only : kind_phys
use musica_ccpp_micm, only: micm
use musica_ccpp_namelist, only: micm_solver_type
use musica_ccpp_util, only: has_error_occurred
integer, intent(in) :: horizontal_dimension ! (count)
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

integer :: number_of_grid_cells
type(ccpp_constituent_properties_t), allocatable :: micm_species_props(:)

! Temporary fix until the number of grid cells is only needed to create a MICM state
! instead of when the solver is created.
! Re-create the MICM solver with the correct number of grid cells
number_of_grid_cells = horizontal_dimension * vertical_layer_dimension
call micm_register(micm_solver_type, number_of_grid_cells, micm_species_props, errmsg, errcode)
call micm_init(errmsg, errcode)
if (errcode /= 0) return
call tuvx_init(vertical_layer_dimension, vertical_interface_dimension, &
Expand All @@ -74,10 +90,10 @@ subroutine musica_ccpp_run(time_step, temperature, pressure, dry_air_density, co
constituents, geopotential_height_wrt_surface_at_midpoint, &
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, cloud_area_fraction, &
air_pressure_thickness, errmsg, errcode)
air_pressure_thickness, solar_zenith_angle, &
earth_sun_distance, 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 @@ -95,12 +111,13 @@ subroutine musica_ccpp_run(time_step, temperature, pressure, dry_air_density, co
real(kind_phys), intent(in) :: surface_geopotential(:) ! m2 s-2
real(kind_phys), intent(in) :: surface_temperature(:) ! K
real(kind_phys), intent(in) :: surface_albedo ! unitless
integer, intent(in) :: number_of_photolysis_wavelength_grid_sections ! (count)
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)
real(kind_phys), intent(in) :: solar_zenith_angle(:) ! radians (column)
real(kind_phys), intent(in) :: earth_sun_distance ! AU
character(len=512), intent(out) :: errmsg
integer, intent(out) :: errcode

Expand All @@ -113,16 +130,19 @@ subroutine musica_ccpp_run(time_step, temperature, pressure, dry_air_density, co

! Calculate photolysis rate constants using TUV-x
call tuvx_run(temperature, dry_air_density, &
constituents, &
geopotential_height_wrt_surface_at_midpoint, &
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, &
cloud_area_fraction, constituents, &
air_pressure_thickness, rate_parameters, &
cloud_area_fraction, &
air_pressure_thickness, &
solar_zenith_angle, &
earth_sun_distance, &
rate_parameters, &
errmsg, errcode)

! Get the molar mass that is set in the call to instantiate()
Expand Down
46 changes: 23 additions & 23 deletions schemes/musica/musica_ccpp.meta
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@
[ccpp-arg-table]
name = musica_ccpp_register
type = scheme
[ micm_solver_type ]
standard_name = micm_solver_type
units = none
type = integer
dimensions = ()
intent = in
[ number_of_grid_cells ]
standard_name = number_of_grid_cells
units = count
type = integer
dimensions = ()
intent = in
[ constituent_props ]
standard_name = dynamic_constituents_for_musica_ccpp
units = none
Expand All @@ -41,15 +29,21 @@
[ccpp-arg-table]
name = musica_ccpp_init
type = scheme
[ horizontal_dimension ]
standard_name = horizontal_dimension
units = count
type = integer
dimensions = ()
intent = in
[ vertical_layer_dimension ]
standard_name = vertical_layer_dimension
units = none
units = count
type = integer
dimensions = ()
intent = in
[ vertical_interface_dimension ]
standard_name = vertical_interface_dimension
units = none
units = count
type = integer
dimensions = ()
intent = in
Expand Down Expand Up @@ -147,23 +141,17 @@
units = None
dimensions = ()
intent = in
[ number_of_photolysis_wavelength_grid_sections ]
standard_name = number_of_photolysis_wavelength_grid_sections
type = integer
units = None
dimensions = ()
intent = in
[ photolysis_wavelength_grid_interfaces ]
standard_name = photolysis_wavelength_grid_interfaces
type = real | kind = kind_phys
units = nm
dimensions = (horizontal_loop_extent)
units = m
dimensions = (photolysis_wavelength_grid_interface_dimension)
intent = in
[ extraterrestrial_flux ]
standard_name = extraterrestrial_radiation_flux
type = real | kind = kind_phys
units = photons cm-2 s-1 nm-1
dimensions = (horizontal_loop_extent)
dimensions = (photolysis_wavelength_grid_section_dimension)
intent = in
[ standard_gravitational_acceleration ]
standard_name = standard_gravitational_acceleration
Expand All @@ -183,6 +171,18 @@
type = real | kind = kind_phys
dimensions = (horizontal_loop_extent,vertical_layer_dimension)
intent = in
[ solar_zenith_angle ]
standard_name = solar_zenith_angle
units = radians
type = real | kind = kind_phys
dimensions = (horizontal_loop_extent)
intent = in
[ earth_sun_distance ]
standard_name = earth_sun_distance
units = AU
type = real | kind = kind_phys
dimensions = ()
intent = in
[ errmsg ]
standard_name = ccpp_error_message
units = none
Expand Down
22 changes: 13 additions & 9 deletions schemes/musica/musica_ccpp_namelist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,20 @@
units
This is the CCPP unit specification of the variable (e.g., m s-1).
-->
<section name="MUSICA Standard Names">
<standard_name name="micm_solver_type">
<type kind="" units="none">integer</type>
</standard_name>
<standard_name name="number_of_grid_cells">
<type kind="" units="count">integer</type>
</standard_name>
</section>

<!-- MUSICA configuration options -->
<entry id="micm_solver_type">
<type>integer</type>
<category>musica_ccpp</category>
<group>musica_ccpp</group>
<standard_name>micm_solver_type</standard_name>
<units>none</units>
<desc>
The type of MICM solver to use.
</desc>
<values>
<value>1</value>
</values>
</entry>
<entry id="filename_of_micm_configuration">
<type>char*512</type>
<category>musica_ccpp</category>
Expand Down
5 changes: 5 additions & 0 deletions schemes/musica/musica_ccpp_util.F90
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
! SPDX-License-Identifier: Apache-2.0
module musica_ccpp_util

use ccpp_kinds, only: kind_phys

implicit none

private
public :: has_error_occurred

real(kind_phys), parameter, public :: PI = 3.14159265358979323846_kind_phys
real(kind_phys), parameter, public :: DEGREE_TO_RADIAN = PI / 180.0_kind_phys

contains

!> @brief Evaluate a MUSICA error for failure and convert to CCPP error data
Expand Down
Loading

0 comments on commit 8a9f22a

Please sign in to comment.