Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TUV-x height grid updates #134

Merged
merged 29 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4c269e4
update TUV-x height grid from host data
mattldawson Sep 4, 2024
e1fd505
Merge branch 'development' into develop-94-tuvx-height-grid
mattldawson Sep 4, 2024
beb5126
add missing newlines
mattldawson Sep 4, 2024
afbe013
add tuvx temperature function
boulderdaze Sep 11, 2024
778a65a
Merge remote-tracking branch 'remotes/matt/develop-94-tuvx-height-gri…
boulderdaze Sep 11, 2024
fc1e9c5
set temperature edges
boulderdaze Sep 11, 2024
6ea9c50
fix module name
boulderdaze Sep 12, 2024
9642bfa
fix temperature test
boulderdaze Sep 12, 2024
e0d6f83
rewrote comments
boulderdaze Sep 12, 2024
7851097
add test
boulderdaze Sep 23, 2024
3a71dc3
add metadata cmake test
boulderdaze Sep 26, 2024
99d6dea
correct metadata
boulderdaze Sep 26, 2024
e4119ea
add height grid from host and run TUV-x for photo rate calcs
mattldawson Oct 9, 2024
0ec84f1
update musica commit in tests
mattldawson Oct 9, 2024
2261760
Merge branch 'development' into develop-94-tuvx-height-grid
mattldawson Oct 9, 2024
45ef3b6
fix typo
mattldawson Oct 9, 2024
aafd074
Merge metadata check from branch '120-test-metadata' into develop-94-…
mattldawson Oct 10, 2024
4660749
update metadata and test build script
mattldawson Oct 10, 2024
fe44583
add conversion from geopotential height to regular height
mattldawson Oct 11, 2024
e8c6b61
code review
boulderdaze Oct 15, 2024
a29d7c0
fix valgrind errors
boulderdaze Oct 16, 2024
452f068
fix minor syntax errors
boulderdaze Oct 16, 2024
e3ec7b2
Merge branch 'development' into 94-tuvx-height-grid
boulderdaze Oct 17, 2024
ecce5b3
address code review
boulderdaze Oct 21, 2024
2f82f9a
remove target attribute
boulderdaze Oct 21, 2024
05ebaa0
formatting
boulderdaze Oct 22, 2024
1844af0
added deallocate height grid call, reworked tuvx run function
boulderdaze Oct 22, 2024
b6ebb76
add valgrind suppression file
boulderdaze Oct 22, 2024
76a26ee
add valgrind suppression option
boulderdaze Oct 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
32 changes: 17 additions & 15 deletions schemes/musica/tuvx/musica_ccpp_tuvx.F90
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ 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, &
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)
Expand Down Expand Up @@ -86,7 +86,7 @@ subroutine tuvx_init(vertical_layer_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()
Expand All @@ -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, &
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably recommend calculating reciprocal_of_gravitational_acceleration outside of the i_col loop and then just passing it to calculate_heights like you were doing previously (this could potentially reduce the total number of divisions that have to be done).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, thank you for the comment!

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