Skip to content

101 calculate no photolysis rate constants #183

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

Draft
wants to merge 56 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
d9d0e5d
Merge pull request #110 from ESCOMP/development
cacraigucar Aug 15, 2024
fd27d14
Change Liceense to Apache 2.0
nusbaume Sep 24, 2024
592fe83
Remove old license file.
nusbaume Sep 24, 2024
93a1dbf
Merge pull request #121 from ESCOMP/development
jimmielin Sep 30, 2024
f8ce60b
Merge pull request #130 from ESCOMP/development
nusbaume Oct 3, 2024
67927f1
Merge pull request #146 from ESCOMP/development
mwaxmonsky Oct 25, 2024
3c575bf
stubbing out no calculation module and including reference to the ori…
K20shores Nov 13, 2024
e10f811
Upgrading to atmos_phys0_07_000 (#158)
jimmielin Nov 19, 2024
0b0467c
merging main
K20shores Dec 2, 2024
5364878
merging development
K20shores Dec 3, 2024
b3941b9
defining arguments
K20shores Dec 3, 2024
dbd5bab
getting index of constituents, I think
K20shores Dec 4, 2024
6d6444a
adding comments to explain what's going on
K20shores Dec 5, 2024
89d5e3f
adding sphers
K20shores Dec 5, 2024
57e2942
trying to set densities
K20shores Dec 5, 2024
c14d9a0
more densities
K20shores Dec 5, 2024
6904d58
might have finished the setup to actually calculate the rate
K20shores Dec 5, 2024
4857eb9
adding some of the necessary data
K20shores Dec 5, 2024
2e769a7
adding many functions
K20shores Dec 6, 2024
286f8e5
maybe most of it is implemented
K20shores Dec 6, 2024
47af226
some compile error fixes
K20shores Dec 9, 2024
289b2e9
more things
K20shores Dec 9, 2024
6726a1b
grrrr this isn't cam
K20shores Dec 9, 2024
1ff9ec7
more errors fixed
K20shores Dec 9, 2024
ffdc4e3
it compiles
K20shores Dec 13, 2024
9d4f2a6
more comments
K20shores Dec 13, 2024
e1fccfa
trying to get things correct
K20shores Dec 13, 2024
29bf3bb
correcting some dimensions
K20shores Dec 16, 2024
f2d520a
correctly setting some values
K20shores Dec 17, 2024
c156c0a
trying to correct memory leak?
K20shores Dec 17, 2024
542aea0
correcting dimensions
K20shores Dec 18, 2024
8f087d8
correcting comment
K20shores Dec 18, 2024
1685938
merging
K20shores Dec 19, 2024
2882fc2
formatting
K20shores Dec 19, 2024
f28b7c4
undoing changes accidentally made to a file
K20shores Dec 19, 2024
06b5928
Merge branch 'development' into 101-calculate-no-photolysis-rate-cons…
K20shores Jan 6, 2025
438ed3e
fixing compile error
K20shores Jan 6, 2025
5b75766
renaming things
K20shores Jan 7, 2025
ecdb406
trying to properly register species
K20shores Jan 22, 2025
5399a16
Add function for NO photolysis calculation (#191)
boulderdaze Jan 24, 2025
8cb899d
checking if there is an no photolysis rate reaction in micm
K20shores Feb 5, 2025
be612f1
initializing a variable to pass a memory test
K20shores Feb 6, 2025
3331a6b
initializing a variable to pass a memory test
K20shores Feb 6, 2025
40c767a
writing test
K20shores Feb 6, 2025
381d50a
investigating memory error
K20shores Feb 7, 2025
e9605d8
set NO photo rate inside loop over layers
mattldawson Feb 11, 2025
99d4e19
update chem mechanism commit
mattldawson Feb 11, 2025
d6336f1
Complete Zhang McFarlane conversion to CCPP (#186)
cacraigucar Jan 24, 2025
b4e2fb7
Add diagnostic output for ALL constituents (#199)
peverwhee Feb 4, 2025
9fcf672
Build MUSICA in CAM-SIMA (#198)
boulderdaze Feb 4, 2025
a605710
update test
mattldawson Feb 11, 2025
61ca4eb
move NO photolysis logic to TUVx modules
mattldawson Feb 20, 2025
c61b5a3
Implement thermo_water_update scheme (non-portable wrapper to cam_the…
jimmielin Feb 14, 2025
5467e1f
Implement diagnostics for global energy fixer, check_energy standard …
jimmielin Feb 14, 2025
b342a12
Add kessler_test Test SDF for FPHYStest to split off from FKESSLER te…
jimmielin Feb 14, 2025
9e02787
PBL utils transfer (#193)
mwaxmonsky Feb 19, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
run: |
source venv/bin/activate
cd build
gcovr -r .. --filter '\.\./schemes' --html atmospheric_physics_code_coverage.html --txt
gcovr -r .. --filter '\.\./schemes' --filter '\.\./phys_utils' --html atmospheric_physics_code_coverage.html --txt

- name: Upload code coverage results
uses: actions/upload-artifact@v4
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,20 @@ Physics packages which are CCPP_enabled (along with supporting routines) are sto

* [ccpp framework repository](https://github.com/NCAR/ccpp-framework)

# Testing

## MUSICA Chemistry

To build and test chemistry schemes, a dockerfile is provided.

From the root directory, build the docker file

```
docker build -t atmo -f test/docker/Dockerfile.musica .
```

then run it

```
docker run --rm -it atmo
```
56 changes: 56 additions & 0 deletions doc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,59 @@

===============================================================

Tag name:
Originator(s): cacraig
Date: Dec 24, 2024
One-line Summary: Complete Zhang McFarlane conversion to CCPP
Github PR URL:

This PR fixes the following NCAR/atmospheric_physics Github issues:
Add ccpp'ized ZM : https://github.com/ESCOMP/atmospheric_physics/issues/66

Code reviewed by:

List all existing files that have been added (A), modified (M), or deleted (D),
and describe the changes:
A schemes/cloud_fraction/cloud_fraction_fice.F90
A schemes/cloud_fraction/cloud_fraction_fice.meta
A schemes/sima_diagnostics/zm_convr_tendency_diagnostics.F90
A schemes/sima_diagnostics/zm_convr_tendency_diagnostics.meta
A schemes/sima_diagnostics/zm_diagnostics.F90
A schemes/sima_diagnostics/zm_diagnostics.meta
A schemes/sima_diagnostics/zm_evap_tendency_diagnostics.F90
A schemes/sima_diagnostics/zm_evap_tendency_diagnostics.meta
A schemes/sima_diagnostics/zm_momtran_tendency_diagnostics.F90
A schemes/sima_diagnostics/zm_momtran_tendency_diagnostics.meta
A schemes/sima_diagnostics/zm_tendency_diagnostics.F90
A schemes/sima_diagnostics/zm_tendency_diagnostics.meta
A schemes/utilities/to_be_ccppized_temporary.F90
A schemes/utilities/to_be_ccppized_temporary.meta
A schemes/zhang_mcfarlane/set_deep_conv_fluxes_to_general.F90
A schemes/zhang_mcfarlane/set_deep_conv_fluxes_to_general.meta
A schemes/zhang_mcfarlane/set_general_conv_fluxes_to_deep.F90
A schemes/zhang_mcfarlane/set_general_conv_fluxes_to_deep.meta
M schemes/zhang_mcfarlane/zm_conv_convtran.F90
M schemes/zhang_mcfarlane/zm_conv_convtran.meta
M schemes/zhang_mcfarlane/zm_conv_evap.F90
M schemes/zhang_mcfarlane/zm_conv_evap.meta
M schemes/zhang_mcfarlane/zm_conv_momtran.F90
M schemes/zhang_mcfarlane/zm_conv_momtran.meta
M schemes/zhang_mcfarlane/zm_convr.F90
M schemes/zhang_mcfarlane/zm_convr.meta
A schemes/zhang_mcfarlane/zm_convr_namelist.xml
A suites/suite_zhang_mcfarlane.xml
M test/test_schemes/initialize_constituents.F90
A to_be_ccppized/error_messages.F90
A to_be_ccppized/namelist_utils.F90
A to_be_ccppized/units.F90
A to_be_ccppized/wv_sat_methods.F90
A to_be_ccppized/wv_saturation.F90

List and Describe any test failures:

Summarize any changes to answers:

===============================================================
===============================================================

Tag name: atmos_phys0_07_000
Expand Down
227 changes: 155 additions & 72 deletions doc/NamesNotInDictionary.txt

Large diffs are not rendered by default.

216 changes: 216 additions & 0 deletions phys_utils/atmos_phys_pbl_utils.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
module atmos_phys_pbl_utils
! Planetary boundary layer related functions used for vertical diffusion schemes.

use ccpp_kinds, only: kind_phys

implicit none
private

public :: calc_ideal_gas_rrho
public :: calc_friction_velocity
public :: calc_kinematic_heat_flux
public :: calc_kinematic_water_vapor_flux
public :: calc_kinematic_buoyancy_flux
public :: calc_obukhov_length
public :: calc_virtual_temperature
public :: calc_eddy_flux_coefficient
public :: calc_free_atm_eddy_flux_coefficient

real(kind_phys), parameter :: minimum_friction_velocity = 0.01_kind_phys ! Assuming minimum for coarse grids
real(kind_phys), parameter :: minimum_eddy_flux_coefficient = 0.01_kind_phys ! CCM1 2.f.14

contains

pure elemental function calc_ideal_gas_rrho(rair, surface_temperature, pmid) result(rrho)
! air density reciprocal
! Taken from https://glossary.ametsoc.org/wiki/Equation_of_state
! where \alpha = rrho
real(kind_phys), intent(in) :: rair ! gas constant for dry air [ J kg-1 K-1 ]
real(kind_phys), intent(in) :: surface_temperature ! [ K ]
real(kind_phys), intent(in) :: pmid ! midpoint pressure (bottom level) [ Pa ]

real(kind_phys) :: rrho ! 1./bottom level density [ m3 kg-1 ]

rrho = rair * surface_temperature / pmid
end function calc_ideal_gas_rrho

pure elemental function calc_friction_velocity(taux, tauy, rrho) result(friction_velocity)
! https://glossary.ametsoc.org/wiki/Friction_velocity
! NOTE: taux,tauy come form the expansion of the Reynolds stress
!
! Also found in:
! Stull, Roland B. An Introduction to Boundary Layer Meteorology. Springer Kluwer Academic Publishers, 1988. Print.
! DOI: https://doi.org/10.1007/978-94-009-3027-8
! Equation 2.10b, page 67

real(kind_phys), intent(in) :: taux ! surface u stress [ N m-2 ]
real(kind_phys), intent(in) :: tauy ! surface v stress [ N m-2 ]
real(kind_phys), intent(in) :: rrho ! 1./bottom level density [ m3 kg-1 ]

real(kind_phys) :: friction_velocity ! surface friction velocity [ m s-1 ]

friction_velocity = max( sqrt( sqrt(taux**2 + tauy**2)*rrho ), minimum_friction_velocity )
end function calc_friction_velocity

pure elemental function calc_kinematic_heat_flux(shflx, rrho, cpair) result(khfs)
real(kind_phys), intent(in) :: shflx ! surface heat flux [ W m-2 ]
real(kind_phys), intent(in) :: rrho ! 1./bottom level density [ m3 kg-1 ]
real(kind_phys), intent(in) :: cpair ! specific heat of dry air [ J kg-1 K-1 ]

real(kind_phys) :: khfs ! surface kinematic heat flux [ m K s-1 ]

khfs = shflx*rrho/cpair
end function calc_kinematic_heat_flux

pure elemental function calc_kinematic_water_vapor_flux(qflx, rrho) result(kqfs)
real(kind_phys), intent(in) :: qflx ! water vapor flux [ kg m-2 s-1 ]
real(kind_phys), intent(in) :: rrho ! 1./bottom level density [ m3 kg-1 ]

real(kind_phys) :: kqfs ! surface kinematic water vapor flux [ kg kg-1 m s-1 ]

kqfs = qflx*rrho
end function calc_kinematic_water_vapor_flux

pure elemental function calc_kinematic_buoyancy_flux(khfs, zvir, ths, kqfs) result(kbfs)
real(kind_phys), intent(in) :: khfs ! surface kinematic heat flux [ m K s-1 ]
real(kind_phys), intent(in) :: zvir ! rh2o/rair - 1
real(kind_phys), intent(in) :: ths ! potential temperature at surface [ K ]
real(kind_phys), intent(in) :: kqfs ! surface kinematic water vapor flux [ kg kg-1 m s-1 ]

! (`kbfs = \overline{(w' \theta'_v)}_s`)
real(kind_phys) :: kbfs ! surface kinematic buoyancy flux [ m K s-1 ]

kbfs = khfs + zvir*ths*kqfs
end function calc_kinematic_buoyancy_flux

pure elemental function calc_obukhov_length(thvs, ustar, g, karman, kbfs) result(obukhov_length)
! Stull, Roland B. An Introduction to Boundary Layer Meteorology. Springer Kluwer Academic Publishers, 1988. Print.
! DOI: https://doi.org/10.1007/978-94-009-3027-8
! Equation 5.7c, page 181
! \frac{-\theta*u_*^3}{g*k*\overline{(w' \theta_v')}_s} = frac{-\theta*u_*^3}{g*k*kbfs}

real(kind_phys), intent(in) :: thvs ! virtual potential temperature at surface [ K ]
real(kind_phys), intent(in) :: ustar ! Surface friction velocity [ m s-1 ]
real(kind_phys), intent(in) :: g ! acceleration of gravity [ m s-2 ]
real(kind_phys), intent(in) :: karman ! Von Karman's constant (unitless)
real(kind_phys), intent(in) :: kbfs ! surface kinematic buoyancy flux [ m K s-1 ]

real(kind_phys) :: obukhov_length ! Obukhov length [ m ]

! Added sign(...) term to prevent division by 0 and using the fact that
! `kbfs = \overline{(w' \theta_v')}_s`
obukhov_length = -thvs * ustar**3 / &
(g*karman*(kbfs + sign(1.e-10_kind_phys,kbfs)))
end function calc_obukhov_length

pure elemental function calc_virtual_temperature(temperature, specific_humidity, zvir) result(virtual_temperature)
! Williamson, D., Kiehl, J., Ramanathan, V., Dickinson, R., & Hack, J. (1987).
! Description of the NCAR Community Climate Model (CCM1).
! University Corporation for Atmospheric Research. https://doi.org/10.5065/D6TB14WH (Original work published 1987)
! Equation 2.a.7

real(kind_phys), intent(in) :: temperature
real(kind_phys), intent(in) :: specific_humidity
real(kind_phys), intent(in) :: zvir ! rh2o/rair - 1

real(kind_phys) :: virtual_temperature

virtual_temperature = temperature * (1.0_kind_phys + zvir*specific_humidity)
end function calc_virtual_temperature

pure elemental function calc_eddy_flux_coefficient(mixing_length_squared, &
richardson_number, &
shear_squared) &
result(kvf)
! Computes exchange coefficients for turbulent flows.
!
! The stable case (Richardson number, Ri>0) is taken from Holtslag and
! Beljaars (1989), ECMWF proceedings.
! The unstable case (Richardson number, Ri<0) is taken from CCM1.

real(kind_phys), intent(in) :: mixing_length_squared ! [ m2 ]
real(kind_phys), intent(in) :: richardson_number ! [ 1 ]
real(kind_phys), intent(in) :: shear_squared ! [ s-2 ]

real(kind_phys) :: kvf ! Eddy diffusivity ! [ m2 s-1 ]

real(kind_phys) :: fofri ! f(ri)
real(kind_phys) :: kvn ! Neutral Kv

if( richardson_number < 0.0_kind_phys ) then
fofri = unstable_gradient_richardson_stability_parameter(richardson_number)
else
fofri = stable_gradient_richardson_stability_parameter(richardson_number)
end if
kvn = neutral_exchange_coefficient(mixing_length_squared, shear_squared)
kvf = max( minimum_eddy_flux_coefficient, kvn * fofri )
end function calc_eddy_flux_coefficient

pure elemental function calc_free_atm_eddy_flux_coefficient(mixing_length_squared, &
richardson_number, &
shear_squared) &
result(kvf)
! same as austausch_atm but only mixing for Ri<0
! i.e. no background mixing and mixing for Ri>0

real(kind_phys), intent(in) :: mixing_length_squared ! [ m2 ]
real(kind_phys), intent(in) :: richardson_number ! [ 1 ]
real(kind_phys), intent(in) :: shear_squared ! [ s-2 ]

real(kind_phys) :: kvf ! [ m2 s-1 ]

real(kind_phys) :: fofri ! f(ri)
real(kind_phys) :: kvn ! Neutral Kv

kvf = 0.0_kind_phys
if( richardson_number < 0.0_kind_phys ) then
fofri = unstable_gradient_richardson_stability_parameter(richardson_number)
kvn = neutral_exchange_coefficient(mixing_length_squared, shear_squared)
kvf = kvn * fofri
end if
end function calc_free_atm_eddy_flux_coefficient

pure elemental function unstable_gradient_richardson_stability_parameter(richardson_number) result(modifier)
! Williamson, D., Kiehl, J., Ramanathan, V., Dickinson, R., & Hack, J. (1987).
! Description of the NCAR Community Climate Model (CCM1).
! University Corporation for Atmospheric Research. https://doi.org/10.5065/D6TB14WH (Original work published 1987)
! Equation 2.f.13
! \sqrt{ 1-18*Ri }

real(kind_phys), intent(in) :: richardson_number

real(kind_phys) :: modifier

modifier = sqrt( 1._kind_phys - 18._kind_phys * richardson_number )
end function unstable_gradient_richardson_stability_parameter

pure elemental function stable_gradient_richardson_stability_parameter(richardson_number) result(modifier)
! Holtslag, A. A. M., and Beljaars A. C. M. , 1989: Surface flux parameterization schemes: Developments and experiences at KNMI.
! ECMWF Workshop on Parameterization of Fluxes and Land Surface, Reading, United Kingdom, ECMWF, 121–147.
! equation 20, page 140
! Originally used published equation from CCM1, 2.f.12, page 11
! \frac{1}{1+10*Ri*(1+8*Ri)}

real(kind_phys), intent(in) :: richardson_number

real(kind_phys) :: modifier

modifier = 1.0_kind_phys / &
( 1.0_kind_phys + 10.0_kind_phys * richardson_number * ( 1.0_kind_phys + 8.0_kind_phys * richardson_number ) )
end function stable_gradient_richardson_stability_parameter

pure elemental function neutral_exchange_coefficient(mixing_length_squared, shear_squared) result(neutral_k)
! Williamson, D., Kiehl, J., Ramanathan, V., Dickinson, R., & Hack, J. (1987).
! Description of the NCAR Community Climate Model (CCM1).
! University Corporation for Atmospheric Research. https://doi.org/10.5065/D6TB14WH (Original work published 1987)
! Equation 2.f.15, page 12
! NOTE: shear_squared variable currently (01/2025) computed in hb_diff.F90 (s2 in trbintd(...)) matches referenced equation.

real(kind_phys), intent(in) :: mixing_length_squared ! [ m2 ]
real(kind_phys), intent(in) :: shear_squared ! [ s-2 ]

real(kind_phys) :: neutral_k

neutral_k = mixing_length_squared * sqrt(shear_squared)
end function neutral_exchange_coefficient
end module atmos_phys_pbl_utils
2 changes: 1 addition & 1 deletion schemes/check_energy/check_energy_chng.meta
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
dimensions = ()
intent = out
[ teout ]
standard_name = vertically_integrated_total_energy_at_end_of_physics_timestep
standard_name = vertically_integrated_total_energy_using_dycore_energy_formula_at_end_of_physics_timestep
units = J m-2
type = real | kind = kind_phys
dimensions = (horizontal_dimension)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
dimensions = (horizontal_loop_extent)
intent = in
[ teout ]
standard_name = vertically_integrated_total_energy_at_end_of_physics_timestep
standard_name = vertically_integrated_total_energy_using_dycore_energy_formula_at_end_of_physics_timestep
units = J m-2
type = real | kind = kind_phys
dimensions = (horizontal_loop_extent)
Expand All @@ -67,7 +67,7 @@
dimensions = ()
intent = out
[ teout_glob ]
standard_name = global_mean_vertically_integrated_total_energy_at_end_of_physics_timestep
standard_name = global_mean_vertically_integrated_total_energy_using_dycore_energy_formula_at_end_of_physics_timestep
units = J m-2
type = real | kind = kind_phys
dimensions = ()
Expand Down
2 changes: 1 addition & 1 deletion schemes/check_energy/check_energy_save_teout.meta
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
dimensions = (horizontal_loop_extent)
intent = in
[ teout ]
standard_name = vertically_integrated_total_energy_at_end_of_physics_timestep
standard_name = vertically_integrated_total_energy_using_dycore_energy_formula_at_end_of_physics_timestep
units = J m-2
type = real | kind = kind_phys
dimensions = (horizontal_loop_extent)
Expand Down
Loading