Skip to content

Commit

Permalink
resolved: conservation check E3SM-Project#2
Browse files Browse the repository at this point in the history
  • Loading branch information
irenavankova committed Jul 10, 2024
1 parent 957d8b2 commit ecb0658
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
1 change: 1 addition & 0 deletions components/mpas-ocean/cime_config/buildnml
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,7 @@ def buildnml(case, caseroot, compname):
lines.append('<var name="accumulatedLandIceFlux"/>')
lines.append('<var name="accumulatedLandIceFrazilFlux"/>')
lines.append('<var name="accumulatedSeaIceSalinityFlux"/>')
lines.append('<var name="accumulatedSubglacialRunoffSalinityFlux"/>')
lines.append('<var name="initialCarbon"/>')
lines.append('<var name="finalCarbon"/>')
lines.append('<var name="carbonChange"/>')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@
<var name="accumulatedFrazilSalinityFlux" type="real" dimensions="Time" units="kg m^-2 s^-1"
description="Salinity flux from frazil to sea ice, given to coupler. Land ice does not contribute because its frazil salinity is assumed 0. Positive into the ocean."
/>
<var name="accumulatedSubglacialRunoffSalinityFlux" type="real" dimensions="Time" units="kg m^-2 s^-1"
description="Salinity flux from subglacial runoff. Positive into the ocean."
/>
</var_struct>
<var_struct name="conservationCheckCarbonAM" time_levs="1" packages="conservationCheckAMPKG">
<var name="initialCarbon" type="real" dimensions="Time" units="kg"
Expand Down Expand Up @@ -316,6 +319,7 @@
<var name="accumulatedLandIceFrazilFlux"/>
<var name="accumulatedSeaIceSalinityFlux"/>
<var name="accumulatedFrazilSalinityFlux"/>
<var name="accumulatedSubglacialRunoffSalinityFlux"/>
<var name="initialCarbon"/>
<var name="finalCarbon"/>
<var name="carbonChange"/>
Expand Down Expand Up @@ -375,6 +379,7 @@
<var name="accumulatedLandIceFrazilFlux"/>
<var name="accumulatedSeaIceSalinityFlux"/>
<var name="accumulatedFrazilSalinityFlux"/>
<var name="accumulatedSubglacialRunoffSalinityFlux"/>
<var name="initialCarbon"/>
<var name="accumulatedAbsoluteCarbonError"/>
<var name="accumulatedRelativeCarbonError"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1180,10 +1180,14 @@ subroutine salt_conservation(domain, err)
absoluteSaltError, &
relativeSaltError

real(kind=RKIND), dimension(:,:), pointer :: &
activeTracersSurfaceFluxSubglacialRunoff

real(kind=RKIND), pointer :: &
accumulatedSeaIceSalinityFlux, &
accumulatedFrazilSalinityFlux
! accumulatedLandIceFrazilSalinityFlux is not present because it is always 0
accumulatedFrazilSalinityFlux, &
accumulatedSubglacialRunoffSalinityFlux

real(kind=RKIND), dimension(:), allocatable :: &
sumArray, &
Expand All @@ -1204,14 +1208,15 @@ subroutine salt_conservation(domain, err)
dt, dtAvg, v, A, s, c

integer, pointer :: &
nCellsSolve
nCellsSolve, &
index_salinity_flux

integer :: &
iCell, &
ierr

integer, parameter :: &
nSums = 3
nSums = 4

logical, pointer :: &
activeTracersBulkRestoringPKG
Expand All @@ -1229,6 +1234,7 @@ subroutine salt_conservation(domain, err)

call MPAS_pool_get_array(conservationCheckSaltAMPool, "accumulatedSeaIceSalinityFlux", accumulatedSeaIceSalinityFlux)
call MPAS_pool_get_array(conservationCheckSaltAMPool, "accumulatedFrazilSalinityFlux", accumulatedFrazilSalinityFlux)
call MPAS_pool_get_array(conservationCheckSaltAMPool, "accumulatedSubglacialRunoffSalinityFlux", accumulatedSubglacialRunoffSalinityFlux)

!-------------------------------------------------------------
! Net salt flux to ice
Expand All @@ -1254,11 +1260,17 @@ subroutine salt_conservation(domain, err)
call mpas_pool_get_array(forcingPool, 'seaIceSalinityFlux', seaIceSalinityFlux)
call mpas_pool_get_array(statePool, 'accumulatedFrazilIceSalinity', accumulatedFrazilIceSalinityOld, 1)
call mpas_pool_get_array(statePool, 'accumulatedFrazilIceSalinity', accumulatedFrazilIceSalinityNew, 2)
call mpas_pool_get_array(tracersSurfaceFluxPool, 'activeTracersSurfaceFluxSubglacialRunoff', activeTracersSurfaceFluxSubglacialRunoff)
call mpas_pool_get_dimension(tracersSurfaceFluxPool, 'index_salinitySurfaceFlux', index_salinity_flux)



do iCell = 1, nCellsSolve

! salt flux to ocean
sumArray(1) = sumArray(1) + areaCell(iCell) * seaIceSalinityFlux(iCell)
! subglacial runoff
sumArray(4) = sumArray(4) + areaCell(iCell) * activeTracersSurfaceFluxSubglacialRunoff(index_salinity_flux,iCell)
enddo ! iCell

if (config_use_frazil_ice_formation) then
Expand All @@ -1285,6 +1297,7 @@ subroutine salt_conservation(domain, err)
! accumulate fluxes
accumulatedSeaIceSalinityFlux = accumulatedSeaIceSalinityFlux + sumArrayOut(1)
accumulatedFrazilSalinityFlux = accumulatedFrazilSalinityFlux + sumArrayOut(2)
accumulatedSubglacialRunoffSalinityFlux = accumulatedSubglacialRunoffSalinityFlux + sumArrayOut(4)

! cleanup
deallocate(sumArray)
Expand All @@ -1301,6 +1314,7 @@ subroutine salt_conservation(domain, err)
! Average the fluxes
accumulatedSeaIceSalinityFlux = accumulatedSeaIceSalinityFlux /accumulatedFluxCounter
accumulatedFrazilSalinityFlux = accumulatedFrazilSalinityFlux /accumulatedFluxCounter
accumulatedSubglacialRunoffSalinityFlux = accumulatedSubglacialRunoffSalinityFlux /accumulatedFluxCounter

! get initial salt content
call MPAS_pool_get_array(conservationCheckSaltAMPool, "initialSalt", initialSalt)
Expand All @@ -1317,7 +1331,8 @@ subroutine salt_conservation(domain, err)
call MPAS_pool_get_array(conservationCheckSaltAMPool, "netSaltFlux", netSaltFlux)

netSaltFlux = accumulatedSeaIceSalinityFlux &
+ accumulatedFrazilSalinityFlux
+ accumulatedFrazilSalinityFlux &
+ accumulatedSubglacialRunoffSalinityFlux

! compute the final salt error
call MPAS_pool_get_array(conservationCheckSaltAMPool, "absoluteSaltError", absoluteSaltError)
Expand Down Expand Up @@ -1347,6 +1362,8 @@ subroutine salt_conservation(domain, err)
.and.config_frazil_under_land_ice) then
v=0; write(m,"('LandIceFrazilSalinityFlux',es16.8,' (already in wmelt, do not sum) ',f16.8)") v,v*c; call mpas_log_write(m); !no sum: s=s+v
end if
v=accumulatedSubglacialRunoffSalinityFlux ; write(m,"('SubglacialRunoffSalinityFlux ',es16.8,' x2o_Fioi_salt salt ',f16.8)") v,v*c; call mpas_log_write(m); s=s+v


write(m,"('SUM VOLUME FLUXES ',es16.8,' ',f16.8,es16.8)") s, s*c; call mpas_log_write(m)
call mpas_log_write(' ')
Expand Down Expand Up @@ -2272,7 +2289,8 @@ subroutine reset_accumulated_variables(domain)

real(kind=RKIND), pointer :: &
accumulatedSeaIceSalinityFlux, &
accumulatedFrazilSalinityFlux
accumulatedFrazilSalinityFlux, &
accumulatedSubglacialRunoffSalinityFlux

real(kind=RKIND), pointer :: &
accumulatedCarbonSourceSink, &
Expand Down Expand Up @@ -2362,9 +2380,13 @@ subroutine reset_accumulated_variables(domain)

call MPAS_pool_get_array(conservationCheckSaltAMPool, "accumulatedSeaIceSalinityFlux", accumulatedSeaIceSalinityFlux)
call MPAS_pool_get_array(conservationCheckSaltAMPool, "accumulatedFrazilSalinityFlux", accumulatedFrazilSalinityFlux)
call MPAS_pool_get_array(conservationCheckSaltAMPool, "accumulatedLandIceFrazilSalinityFlux", accumulatedLandIceFrazilSalinityFlux)
call MPAS_pool_get_array(conservationCheckSaltAMPool, "accumulatedSubglacialRunoffSalinityFlux", accumulatedSubglacialRunoffSalinityFlux)


accumulatedSeaIceSalinityFlux = 0.0_RKIND
accumulatedFrazilSalinityFlux = 0.0_RKIND
accumulatedSubglacialRunoffSalinityFlux = 0.0_RKIND

call MPAS_pool_get_subpool(domain % blocklist % structs, "conservationCheckCarbonAM", conservationCheckCarbonAMPool)

Expand Down

0 comments on commit ecb0658

Please sign in to comment.