-
Notifications
You must be signed in to change notification settings - Fork 9
(draft) Write dynamic jacobians #1218
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,6 +17,7 @@ module soca_balance_mod | |||||||||||||
| use soca_ksshts_mod, only: soca_ksshts, soca_steric_jacobian | ||||||||||||||
| use soca_kst_mod, only: soca_kst, soca_soft_jacobian | ||||||||||||||
| use soca_state_mod, only: soca_state | ||||||||||||||
| use soca_write_jacobian_mod, only: write_jacobian_to_netcdf | ||||||||||||||
|
|
||||||||||||||
| implicit none | ||||||||||||||
| private | ||||||||||||||
|
|
@@ -96,6 +97,7 @@ subroutine soca_balance_setup(self, f_conf, traj, geom) | |||||||||||||
|
|
||||||||||||||
| ! declarations related to the dynamic height Jacobians | ||||||||||||||
| character(len=:), allocatable :: filename | ||||||||||||||
| character(len=:), allocatable :: str | ||||||||||||||
|
|
||||||||||||||
| ! declarations related to the sea-ice Jacobian | ||||||||||||||
| character(len=:), allocatable :: kct_name | ||||||||||||||
|
|
@@ -165,6 +167,12 @@ subroutine soca_balance_setup(self, f_conf, traj, geom) | |||||||||||||
| end do | ||||||||||||||
| end do | ||||||||||||||
| deallocate(jac) | ||||||||||||||
|
|
||||||||||||||
| ! optionally write out Kst Jacobian | ||||||||||||||
| if ( f_conf%has("kst.jacobian_output")) then | ||||||||||||||
| call f_conf%get_or_die("kst.jacobian_output.filename", str) | ||||||||||||||
| call write_jacobian_to_netcdf(self%kst%jacobian, geom, str, "kst_jacobian") | ||||||||||||||
| end if | ||||||||||||||
| end if | ||||||||||||||
|
|
||||||||||||||
| ! Get configuration for Ksshts | ||||||||||||||
|
|
@@ -193,6 +201,13 @@ subroutine soca_balance_setup(self, f_conf, traj, geom) | |||||||||||||
| end do | ||||||||||||||
| deallocate(jac) | ||||||||||||||
|
|
||||||||||||||
| ! optionally write out Ksshts Jacobian | ||||||||||||||
| if ( f_conf%has("ksshts.jacobian_output")) then | ||||||||||||||
| call f_conf%get_or_die("ksshts.jacobian_output.filename", str) | ||||||||||||||
| call write_jacobian_to_netcdf(self%ksshts%kssht, geom, str, "kssht_jacobian") | ||||||||||||||
| call write_jacobian_to_netcdf(self%ksshts%ksshs, geom, str, "ksshs_jacobian") | ||||||||||||||
|
Comment on lines
+207
to
+208
|
||||||||||||||
| call write_jacobian_to_netcdf(self%ksshts%kssht, geom, str, "kssht_jacobian") | |
| call write_jacobian_to_netcdf(self%ksshts%ksshs, geom, str, "ksshs_jacobian") | |
| filename = str | |
| call write_jacobian_to_netcdf(self%ksshts%kssht, geom, filename, "kssht_jacobian") | |
| filename = trim(str)//"_ksshs" | |
| call write_jacobian_to_netcdf(self%ksshts%ksshs, geom, filename, "ksshs_jacobian") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| ! (C) Copyright 2017-2025 UCAR | ||
| ! | ||
| ! This software is licensed under the terms of the Apache Licence Version 2.0 | ||
| ! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. | ||
|
|
||
| module soca_write_jacobian_mod | ||
|
|
||
| use kinds, only: kind_real | ||
| use soca_geom_mod, only: soca_geom | ||
| use fms_mod, only: write_data, set_domain | ||
| use fms_io_mod, only: fms_io_init, fms_io_exit | ||
|
|
||
| implicit none | ||
| private | ||
| public :: write_jacobian_to_netcdf | ||
|
|
||
| contains | ||
|
|
||
| subroutine write_jacobian_to_netcdf(jacobian, geom, filename, varname) | ||
| real(kind=kind_real), intent(in) :: jacobian(:,:,:) | ||
| type(soca_geom), intent(in) :: geom | ||
| character(len=*), intent(in) :: filename | ||
| character(len=*), intent(in) :: varname | ||
|
|
||
|
|
||
| call fms_io_init() | ||
| call set_domain(geom%Domain%mpp_domain) | ||
|
|
||
| ! Write the jacobian data from all PEs | ||
| call write_data(filename, varname, jacobian, geom%Domain%mpp_domain) | ||
|
|
||
| call fms_io_exit() | ||
|
Comment on lines
+26
to
+32
|
||
| end subroutine write_jacobian_to_netcdf | ||
|
|
||
| end module soca_write_jacobian_mod | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable 'str' is declared but never deallocated. Since it's an allocatable character string that gets assigned values from f_conf%get_or_die, it should be deallocated after use to prevent memory leaks, or the allocation should be handled more carefully within the scope where it's used.