Skip to content

Commit 996d166

Browse files
committed
Implement time-travelling ice in post atm
1 parent db26dc0 commit 996d166

1 file changed

Lines changed: 74 additions & 1 deletion

File tree

mediator/med_phases_post_atm_mod.F90

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ subroutine med_phases_post_atm(gcomp, rc)
3333
use med_map_mod , only : med_map_field_packed
3434
use med_constants_mod , only : dbug_flag => med_constants_dbug_flag
3535
use med_utils_mod , only : chkerr => med_utils_ChkErr
36-
use med_internalstate_mod , only : compocn, compatm, compice, complnd, compwav
36+
use med_internalstate_mod , only : compocn, compatm, compice, complnd, compwav, coupling_mode
3737
use perf_mod , only : t_startf, t_stopf
3838

3939
! input/output variables
@@ -58,6 +58,11 @@ subroutine med_phases_post_atm(gcomp, rc)
5858
call ESMF_GridCompGetInternalState(gcomp, is_local, rc)
5959
if (ChkErr(rc,__LINE__,u_FILE_u)) return
6060

61+
if (trim(coupling_mode) == 'access') then
62+
call med_phases_post_atm_custom_access(gcomp, rc)
63+
if (ChkErr(rc,__LINE__,u_FILE_u)) return
64+
end if
65+
6166
! map atm to ocn
6267
if (is_local%wrap%med_coupling_active(compatm,compocn)) then
6368
call t_startf('MED:'//trim(subname)//' map_atm2ocn')
@@ -128,4 +133,72 @@ subroutine med_phases_post_atm(gcomp, rc)
128133

129134
end subroutine med_phases_post_atm
130135

136+
subroutine med_phases_post_atm_custom_access(gcomp, rc)
137+
use med_kind_mod , only : CX=>SHR_KIND_CX, CS=>SHR_KIND_CS, CL=>SHR_KIND_CL, R8=>SHR_KIND_R8
138+
use med_internalstate_mod , only : compocn, compatm, compice, coupling_mode
139+
use med_internalstate_mod , only : InternalState
140+
use ESMF , only : ESMF_GridComp, ESMF_FieldBundleGet
141+
use ESMF , only : ESMF_FieldGet, ESMF_Field
142+
use ESMF , only : ESMF_LogWrite, ESMF_LOGMSG_INFO, ESMF_SUCCESS
143+
use med_constants_mod , only : dbug_flag => med_constants_dbug_flag
144+
use perf_mod , only : t_startf, t_stopf
145+
146+
! input/output variables
147+
type(ESMF_GridComp) :: gcomp
148+
integer, intent(out) :: rc
149+
150+
! local variables
151+
type(InternalState) :: is_local
152+
real(R8), pointer :: ice_frac_cat_ptr(:, :), ice_flux_cat_ptr(:, :)
153+
type(ESMF_Field) :: ice_frac_cat, ice_flux_cat
154+
integer :: lsize1, lsize2, i, j, n
155+
character(len=*), parameter :: subname='(med_phases_post_atm_custom_access)'
156+
character(len=CS) :: fld_names(4)
157+
!---------------------------------------
158+
159+
rc = ESMF_SUCCESS
160+
161+
call t_startf('MED:'//subname)
162+
if (dbug_flag > 20) then
163+
call ESMF_LogWrite(subname//' called', ESMF_LOGMSG_INFO)
164+
end if
165+
166+
! Get the internal state
167+
nullify(is_local%wrap)
168+
call ESMF_GridCompGetInternalState(gcomp, is_local, rc)
169+
170+
call ESMF_FieldBundleGet(is_local%wrap%FBImp(compice, compatm), fieldName='ia_aicen', field=ice_frac_cat, rc=rc)
171+
call ESMF_FieldGet(ice_frac_cat, farrayptr=ice_frac_cat_ptr)
172+
173+
lsize1 = size(ice_frac_cat_ptr, dim=1)
174+
lsize2 = size(ice_frac_cat_ptr, dim=2)
175+
176+
fld_names = [character(len=CS) :: &
177+
'topmelt', &
178+
'botmelt', &
179+
'sublim', &
180+
'pen_rad']
181+
182+
do n = 1,size(fld_names)
183+
184+
call ESMF_FieldBundleGet(is_local%wrap%FBImp(compatm, compatm), fieldName=trim(fld_names(n)), field=ice_flux_cat, rc=rc)
185+
call ESMF_FieldGet(ice_flux_cat, farrayptr=ice_flux_cat_ptr)
186+
187+
do j = 1,lsize2
188+
do i = 1,lsize1
189+
if (ice_frac_cat_ptr(i, j) > 0.0) then
190+
ice_flux_cat_ptr(i, j) = ice_flux_cat_ptr(i, j) / ice_frac_cat_ptr(i, j)
191+
end if
192+
end do
193+
end do
194+
195+
end do
196+
197+
if (dbug_flag > 20) then
198+
call ESMF_LogWrite(subname//' done', ESMF_LOGMSG_INFO)
199+
end if
200+
call t_stopf('MED:'//subname)
201+
202+
end subroutine med_phases_post_atm_custom_access
203+
131204
end module med_phases_post_atm_mod

0 commit comments

Comments
 (0)