Skip to content

Commit

Permalink
Merge branch '94-tuvx-height-grid' into 95-update-tuvx-temp
Browse files Browse the repository at this point in the history
  • Loading branch information
boulderdaze committed Oct 22, 2024
2 parents 8960b91 + 05ebaa0 commit f31eb23
Show file tree
Hide file tree
Showing 13 changed files with 164 additions and 144 deletions.
20 changes: 11 additions & 9 deletions schemes/musica/micm/musica_ccpp_micm.F90
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,19 @@ 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

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
Expand Down Expand Up @@ -132,6 +132,8 @@ subroutine micm_final(errmsg, errcode)
errmsg = ''
errcode = 0

deallocate( micm )

end subroutine micm_final

end module musica_ccpp_micm
22 changes: 12 additions & 10 deletions schemes/musica/micm/musica_ccpp_micm_util.F90
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ 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

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
Expand Down Expand Up @@ -83,6 +84,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
Expand Down
68 changes: 36 additions & 32 deletions schemes/musica/musica_ccpp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -45,48 +45,52 @@ 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) &
* 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, 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)
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions schemes/musica/musica_ccpp.meta
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,25 @@
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
type = real | kind = kind_phys
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
Expand Down
2 changes: 1 addition & 1 deletion schemes/musica/musica_ccpp_namelist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
<standard_name>filename_of_tuvx_configuration</standard_name>
<units>none</units>
<desc>
A configuration file for the TUVX photolysis rate calculator
A configuration file for the TUV-x photolysis rate calculator
</desc>
<values>
<value>UNSET_PATH</value>
Expand Down
28 changes: 15 additions & 13 deletions schemes/musica/tuvx/musica_ccpp_tuvx.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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, &
Expand Down Expand Up @@ -99,20 +99,21 @@ subroutine tuvx_init(vertical_layer_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, reciprocal_of_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

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)
Expand All @@ -128,7 +129,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 )
Expand All @@ -148,6 +149,7 @@ subroutine tuvx_final(errmsg, errcode)
errmsg = ''
errcode = 0
deallocate( height_grid )
deallocate( tuvx )

end subroutine tuvx_final

Expand Down
Loading

0 comments on commit f31eb23

Please sign in to comment.