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

+*Non-Boussinesq tracer initialization in Z-units #556

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
36 changes: 24 additions & 12 deletions src/ALE/MOM_ALE.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1260,16 +1260,17 @@
!! h_dst must be dimensioned as a model array with GV%ke layers while h_src can
!! have an arbitrary number of layers specified by nk_src.
subroutine ALE_remap_scalar(CS, G, GV, nk_src, h_src, s_src, h_dst, s_dst, all_cells, old_remap, &
answers_2018, answer_date )
answers_2018, answer_date, h_neglect, h_neglect_edge)
type(remapping_CS), intent(in) :: CS !< Remapping control structure
type(ocean_grid_type), intent(in) :: G !< Ocean grid structure
type(verticalGrid_type), intent(in) :: GV !< Ocean vertical grid structure
integer, intent(in) :: nk_src !< Number of levels on source grid
real, dimension(SZI_(G),SZJ_(G),nk_src), intent(in) :: h_src !< Level thickness of source grid
!! [H ~> m or kg m-2]
!! [H ~> m or kg m-2] or other units
!! if H_neglect is provided
real, dimension(SZI_(G),SZJ_(G),nk_src), intent(in) :: s_src !< Scalar on source grid, in arbitrary units [A]
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)),intent(in) :: h_dst !< Level thickness of destination grid
!! [H ~> m or kg m-2]
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)),intent(in) :: h_dst !< Level thickness of destination grid in the
!! same units as h_src, often [H ~> m or kg m-2]
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)),intent(inout) :: s_dst !< Scalar on destination grid, in the same
!! arbitrary units as s_src [A]
logical, optional, intent(in) :: all_cells !< If false, only reconstruct for
Expand All @@ -1283,10 +1284,16 @@
!! use more robust forms of the same expressions.
integer, optional, intent(in) :: answer_date !< The vintage of the expressions to use
!! for remapping
real, optional, intent(in) :: h_neglect !< A negligibly small thickness used in
!! remapping cell reconstructions, in the same
!! units as h_src, often [H ~> m or kg m-2]
real, optional, intent(in) :: h_neglect_edge !< A negligibly small thickness used in
!! remapping edge value calculations, in the same
!! units as h_src, often [H ~> m or kg m-2]
! Local variables
integer :: i, j, k, n_points
real :: dx(GV%ke+1) ! Change in interface position [H ~> m or kg m-2]
real :: h_neglect, h_neglect_edge ! Tiny thicknesses used in remapping [H ~> m or kg m-2]
real :: h_neg, h_neg_edge ! Tiny thicknesses used in remapping [H ~> m or kg m-2]
logical :: ignore_vanished_layers, use_remapping_core_w, use_2018_remap

ignore_vanished_layers = .false.
Expand All @@ -1297,12 +1304,17 @@
use_2018_remap = .true. ; if (present(answers_2018)) use_2018_remap = answers_2018
if (present(answer_date)) use_2018_remap = (answer_date < 20190101)

if (.not.use_2018_remap) then
h_neglect = GV%H_subroundoff ; h_neglect_edge = GV%H_subroundoff
elseif (GV%Boussinesq) then
h_neglect = GV%m_to_H*1.0e-30 ; h_neglect_edge = GV%m_to_H*1.0e-10
if (present(h_neglect)) then
h_neg = h_neglect
h_neg_edge = h_neg ; if (present(h_neglect_edge)) h_neg_edge = h_neglect_edge
else
h_neglect = GV%kg_m2_to_H*1.0e-30 ; h_neglect_edge = GV%kg_m2_to_H*1.0e-10
if (.not.use_2018_remap) then
h_neg = GV%H_subroundoff ; h_neg_edge = GV%H_subroundoff
elseif (GV%Boussinesq) then
h_neg = GV%m_to_H*1.0e-30 ; h_neg_edge = GV%m_to_H*1.0e-10

Check warning on line 1314 in src/ALE/MOM_ALE.F90

View check run for this annotation

Codecov / codecov/patch

src/ALE/MOM_ALE.F90#L1312-L1314

Added lines #L1312 - L1314 were not covered by tests
else
h_neg = GV%kg_m2_to_H*1.0e-30 ; h_neg_edge = GV%kg_m2_to_H*1.0e-10

Check warning on line 1316 in src/ALE/MOM_ALE.F90

View check run for this annotation

Codecov / codecov/patch

src/ALE/MOM_ALE.F90#L1316

Added line #L1316 was not covered by tests
endif
endif

!$OMP parallel do default(shared) firstprivate(n_points,dx)
Expand All @@ -1318,10 +1330,10 @@
if (use_remapping_core_w) then
call dzFromH1H2( n_points, h_src(i,j,1:n_points), GV%ke, h_dst(i,j,:), dx )
call remapping_core_w(CS, n_points, h_src(i,j,1:n_points), s_src(i,j,1:n_points), &
GV%ke, dx, s_dst(i,j,:), h_neglect, h_neglect_edge)
GV%ke, dx, s_dst(i,j,:), h_neg, h_neg_edge)

Check warning on line 1333 in src/ALE/MOM_ALE.F90

View check run for this annotation

Codecov / codecov/patch

src/ALE/MOM_ALE.F90#L1333

Added line #L1333 was not covered by tests
else
call remapping_core_h(CS, n_points, h_src(i,j,1:n_points), s_src(i,j,1:n_points), &
GV%ke, h_dst(i,j,:), s_dst(i,j,:), h_neglect, h_neglect_edge)
GV%ke, h_dst(i,j,:), s_dst(i,j,:), h_neg, h_neg_edge)
endif
else
s_dst(i,j,:) = 0.
Expand Down
60 changes: 46 additions & 14 deletions src/ALE/MOM_regridding.F90
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
public getCoordinateResolution, getCoordinateInterfaces
public getCoordinateUnits, getCoordinateShortName, getStaticThickness
public DEFAULT_COORDINATE_MODE
public set_h_neglect, set_dz_neglect
public get_zlike_CS, get_sigma_CS, get_rho_CS

!> Documentation for coordinate options
Expand Down Expand Up @@ -1416,13 +1417,7 @@
#endif
logical :: ice_shelf

if (CS%remap_answer_date >= 20190101) then
h_neglect = GV%H_subroundoff ; h_neglect_edge = GV%H_subroundoff
elseif (GV%Boussinesq) then
h_neglect = GV%m_to_H*1.0e-30 ; h_neglect_edge = GV%m_to_H*1.0e-10
else
h_neglect = GV%kg_m2_to_H*1.0e-30 ; h_neglect_edge = GV%kg_m2_to_H*1.0e-10
endif
h_neglect = set_h_neglect(GV, CS%remap_answer_date, h_neglect_edge)

Check warning on line 1420 in src/ALE/MOM_regridding.F90

View check run for this annotation

Codecov / codecov/patch

src/ALE/MOM_regridding.F90#L1420

Added line #L1420 was not covered by tests

nz = GV%ke
ice_shelf = present(frac_shelf_h)
Expand Down Expand Up @@ -1575,13 +1570,7 @@
real :: z_top_col, totalThickness
logical :: ice_shelf

if (CS%remap_answer_date >= 20190101) then
h_neglect = GV%H_subroundoff ; h_neglect_edge = GV%H_subroundoff
elseif (GV%Boussinesq) then
h_neglect = GV%m_to_H*1.0e-30 ; h_neglect_edge = GV%m_to_H*1.0e-10
else
h_neglect = GV%kg_m2_to_H*1.0e-30 ; h_neglect_edge = GV%kg_m2_to_H*1.0e-10
endif
h_neglect = set_h_neglect(GV, CS%remap_answer_date, h_neglect_edge)

Check warning on line 1573 in src/ALE/MOM_regridding.F90

View check run for this annotation

Codecov / codecov/patch

src/ALE/MOM_regridding.F90#L1573

Added line #L1573 was not covered by tests

if (.not.CS%target_density_set) call MOM_error(FATAL, "build_grid_HyCOM1 : "//&
"Target densities must be set before build_grid_HyCOM1 is called.")
Expand Down Expand Up @@ -2095,6 +2084,49 @@

end subroutine write_regrid_file

!> Set appropriate values for the negligible thicknesses used for remapping based on an answer date.
function set_h_neglect(GV, remap_answer_date, h_neglect_edge) result(h_neglect)

Check warning on line 2088 in src/ALE/MOM_regridding.F90

View check run for this annotation

Codecov / codecov/patch

src/ALE/MOM_regridding.F90#L2088

Added line #L2088 was not covered by tests
type(verticalGrid_type), intent(in) :: GV !< Ocean vertical grid structure
integer, intent(in) :: remap_answer_date !< The vintage of the expressions to use
!! for remapping. Values below 20190101 recover the
!! remapping answers from 2018. Higher values use more
!! robust forms of the same remapping algorithms.
real, intent(out) :: h_neglect_edge !< A negligibly small thickness used in
!! remapping edge value calculations [H ~> m or kg m-2]
real :: h_neglect !< A negligibly small thickness used in
!! remapping cell reconstructions [H ~> m or kg m-2]

if (remap_answer_date >= 20190101) then
h_neglect = GV%H_subroundoff ; h_neglect_edge = GV%H_subroundoff
elseif (GV%Boussinesq) then
h_neglect = GV%m_to_H*1.0e-30 ; h_neglect_edge = GV%m_to_H*1.0e-10

Check warning on line 2102 in src/ALE/MOM_regridding.F90

View check run for this annotation

Codecov / codecov/patch

src/ALE/MOM_regridding.F90#L2100-L2102

Added lines #L2100 - L2102 were not covered by tests
else
h_neglect = GV%kg_m2_to_H*1.0e-30 ; h_neglect_edge = GV%kg_m2_to_H*1.0e-10

Check warning on line 2104 in src/ALE/MOM_regridding.F90

View check run for this annotation

Codecov / codecov/patch

src/ALE/MOM_regridding.F90#L2104

Added line #L2104 was not covered by tests
endif
end function set_h_neglect

Check warning on line 2106 in src/ALE/MOM_regridding.F90

View check run for this annotation

Codecov / codecov/patch

src/ALE/MOM_regridding.F90#L2106

Added line #L2106 was not covered by tests

!> Set appropriate values for the negligible vertical layer extents used for remapping based on an answer date.
function set_dz_neglect(GV, US, remap_answer_date, dz_neglect_edge) result(dz_neglect)
type(verticalGrid_type), intent(in) :: GV !< Ocean vertical grid structure
type(unit_scale_type), intent(in) :: US !< A dimensional unit scaling type
integer, intent(in) :: remap_answer_date !< The vintage of the expressions to use
!! for remapping. Values below 20190101 recover the
!! remapping answers from 2018. Higher values use more
!! robust forms of the same remapping algorithms.
real, intent(out) :: dz_neglect_edge !< A negligibly small vertical layer extent
!! used in remapping edge value calculations [Z ~> m]
real :: dz_neglect !< A negligibly small vertical layer extent
!! used in remapping cell reconstructions [Z ~> m]

if (remap_answer_date >= 20190101) then
dz_neglect = GV%dZ_subroundoff ; dz_neglect_edge = GV%dZ_subroundoff
elseif (GV%Boussinesq) then
dz_neglect = US%m_to_Z*1.0e-30 ; dz_neglect_edge = US%m_to_Z*1.0e-10

Check warning on line 2124 in src/ALE/MOM_regridding.F90

View check run for this annotation

Codecov / codecov/patch

src/ALE/MOM_regridding.F90#L2123-L2124

Added lines #L2123 - L2124 were not covered by tests
else
dz_neglect = GV%kg_m2_to_H * (GV%H_to_m*US%m_to_Z) * 1.0e-30
dz_neglect_edge = GV%kg_m2_to_H * (GV%H_to_m*US%m_to_Z) * 1.0e-10

Check warning on line 2127 in src/ALE/MOM_regridding.F90

View check run for this annotation

Codecov / codecov/patch

src/ALE/MOM_regridding.F90#L2126-L2127

Added lines #L2126 - L2127 were not covered by tests
endif
end function set_dz_neglect

!------------------------------------------------------------------------------
!> Query the fixed resolution data
Expand Down
36 changes: 27 additions & 9 deletions src/initialization/MOM_state_initialization.F90
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
use MOM_ALE, only : ALE_remap_scalar, ALE_regrid_accelerated, TS_PLM_edge_values
use MOM_regridding, only : regridding_CS, set_regrid_params, getCoordinateResolution
use MOM_regridding, only : regridding_main, regridding_preadjust_reqs, convective_adjustment
use MOM_regridding, only : set_dz_neglect
use MOM_remapping, only : remapping_CS, initialize_remapping, remapping_core_h
use MOM_horizontal_regridding, only : horiz_interp_and_extrap_tracer, homogenize_field
use MOM_oda_incupd, only: oda_incupd_CS, initialize_oda_incupd_fixed, initialize_oda_incupd
Expand Down Expand Up @@ -2483,6 +2484,10 @@
real, dimension(:,:,:), allocatable :: h1 ! Thicknesses on the input grid [H ~> m or kg m-2].
real, dimension(:,:,:), allocatable :: dz_interface ! Change in position of interface due to
! regridding [H ~> m or kg m-2]
real :: dz_neglect ! A negligibly small vertical layer extent used in
! remapping cell reconstructions [Z ~> m]
real :: dz_neglect_edge ! A negligibly small vertical layer extent used in
! remapping edge value calculations [Z ~> m]
real :: zTopOfCell, zBottomOfCell ! Heights in Z units [Z ~> m].
type(regridding_CS) :: regridCS ! Regridding parameters and work arrays
type(remapping_CS) :: remapCS ! Remapping parameters and work arrays
Expand Down Expand Up @@ -2768,6 +2773,11 @@
frac_shelf_h=frac_shelf_h )

deallocate( dz_interface )

call ALE_remap_scalar(remapCS, G, GV, nkd, h1, tmpT1dIn, h, tv%T, all_cells=remap_full_column, &
old_remap=remap_old_alg, answer_date=remap_answer_date )

Check warning on line 2778 in src/initialization/MOM_state_initialization.F90

View check run for this annotation

Codecov / codecov/patch

src/initialization/MOM_state_initialization.F90#L2778

Added line #L2778 was not covered by tests
call ALE_remap_scalar(remapCS, G, GV, nkd, h1, tmpS1dIn, h, tv%S, all_cells=remap_full_column, &
old_remap=remap_old_alg, answer_date=remap_answer_date )

Check warning on line 2780 in src/initialization/MOM_state_initialization.F90

View check run for this annotation

Codecov / codecov/patch

src/initialization/MOM_state_initialization.F90#L2780

Added line #L2780 was not covered by tests
else
! This is the old way of initializing to z* coordinates only
allocate( hTarget(nz) )
Expand All @@ -2788,16 +2798,24 @@
enddo ; enddo
deallocate( hTarget )

! This is a simple conversion of the target grid to thickness units that may not be
! appropriate in non-Boussinesq mode.
call dz_to_thickness_simple(dz, h, G, GV, US)
dz_neglect = set_dz_neglect(GV, US, remap_answer_date, dz_neglect_edge)
call ALE_remap_scalar(remapCS, G, GV, nkd, dz1, tmpT1dIn, dz, tv%T, all_cells=remap_full_column, &
old_remap=remap_old_alg, answer_date=remap_answer_date, &
H_neglect=dz_neglect, H_neglect_edge=dz_neglect_edge)
call ALE_remap_scalar(remapCS, G, GV, nkd, dz1, tmpS1dIn, dz, tv%S, all_cells=remap_full_column, &
old_remap=remap_old_alg, answer_date=remap_answer_date, &
H_neglect=dz_neglect, H_neglect_edge=dz_neglect_edge)

if (GV%Boussinesq .or. GV%semi_Boussinesq) then
! This is a simple conversion of the target grid to thickness units that is not
! appropriate in non-Boussinesq mode.
call dz_to_thickness_simple(dz, h, G, GV, US)
else
! Convert dz into thicknesses in units of H using the equation of state as appropriate.
call dz_to_thickness(dz, tv, h, G, GV, US)

Check warning on line 2815 in src/initialization/MOM_state_initialization.F90

View check run for this annotation

Codecov / codecov/patch

src/initialization/MOM_state_initialization.F90#L2815

Added line #L2815 was not covered by tests
endif
endif

call ALE_remap_scalar(remapCS, G, GV, nkd, h1, tmpT1dIn, h, tv%T, all_cells=remap_full_column, &
old_remap=remap_old_alg, answer_date=remap_answer_date )
call ALE_remap_scalar(remapCS, G, GV, nkd, h1, tmpS1dIn, h, tv%S, all_cells=remap_full_column, &
old_remap=remap_old_alg, answer_date=remap_answer_date )

deallocate( dz1 )
deallocate( h1 )
deallocate( tmpT1dIn )
Expand Down Expand Up @@ -2879,7 +2897,7 @@
ks, G, GV, US, PF, just_read)
endif

! Now convert thicknesses to units of H.
! Now convert dz into thicknesses in units of H.
call dz_to_thickness(dz, tv, h, G, GV, US)

endif ! useALEremapping
Expand Down
Loading
Loading