Skip to content

Commit aba7dc2

Browse files
committed
Completed ocn_init_mct
1 parent 5df3bc3 commit aba7dc2

1 file changed

Lines changed: 111 additions & 62 deletions

File tree

config_src/mct_driver/ocn_comp_mct.F90

Lines changed: 111 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,22 @@ module ocn_comp_mct
2020
seq_infodata_GetData, &
2121
seq_infodata_start_type_start, &
2222
seq_infodata_start_type_cont, &
23-
seq_infodata_start_type_brnch
23+
seq_infodata_start_type_brnch, &
24+
seq_infodata_PutData
2425
use seq_comm_mct, only: seq_comm_name, seq_comm_inst, seq_comm_suffix
26+
use seq_timemgr_mod, only: seq_timemgr_EClockGetData
2527
use perf_mod, only: t_startf, t_stopf
26-
27-
28+
29+
2830
! From MOM6
2931
use ocean_model_mod, only: ocean_state_type, ocean_public_type
30-
use ocean_model_mod, only: ocean_model_init
31-
use MOM_time_manager, only: time_type, set_date, set_calendar_type, NOLEAP
32+
use ocean_model_mod, only: ocean_model_init, get_state_pointers
3233
use MOM_domains, only: MOM_infra_init, num_pes, root_pe, pe_here
34+
use MOM_grid, only: ocean_grid_type, get_global_grid_size
35+
use MOM_error_handler, only: MOM_error, FATAL, is_root_pe
36+
use MOM_time_manager, only: time_type, set_date, set_calendar_type, NOLEAP
3337
use coupler_indices, only: coupler_indices_init
34-
use ocn_import_export, only: SBUFF_SUM
38+
use ocn_import_export, only: SBUFF_SUM, ocn_Export, mom_sum_buffer
3539

3640
!
3741
! !PUBLIC MEMBER FUNCTIONS:
@@ -72,7 +76,7 @@ module ocn_comp_mct
7276
subroutine ocn_init_mct( EClock, cdata_o, x2o_o, o2x_o, NLFilename )
7377
!
7478
! !DESCRIPTION:
75-
! Initialize POP
79+
! Initialize POP
7680
!
7781
! !INPUT/OUTPUT PARAMETERS:
7882

@@ -99,31 +103,50 @@ subroutine ocn_init_mct( EClock, cdata_o, x2o_o, o2x_o, NLFilename )
99103
character(len=32) :: starttype ! infodata start type
100104
integer :: mpicom_ocn
101105
integer :: npes, pe0
102-
integer :: i
106+
integer :: i, errorCode
103107
integer :: lsize, nsend, nrecv
108+
logical :: ldiag_cpl = .false.
104109

105110
! mct variables (these are local for now)
106111
integer :: MOM_MCT_ID
107-
type(mct_gsMap), pointer :: MOM_MCT_gsMap ! 2d, points to cdata
108-
type(mct_gGrid), pointer :: MOM_MCT_dom ! 2d, points to cdata
112+
type(mct_gsMap), pointer :: MOM_MCT_gsMap => NULL() ! 2d, points to cdata
113+
type(mct_gGrid), pointer :: MOM_MCT_dom => NULL() ! 2d, points to cdata
109114
type(mct_gsMap) :: MOM_MCT_gsMap3d ! for 3d streams, local
110115
type(mct_gGrid) :: MOM_MCT_dom3d ! for 3d streams, local
111116

117+
! time management
118+
integer :: ocn_cpl_dt
119+
real (kind=8) :: mom_cpl_dt
120+
real (kind=8), parameter :: &
121+
seconds_in_minute = 60.0d0, &
122+
seconds_in_hour = 3600.0d0, &
123+
seconds_in_day = 86400.0d0, &
124+
minutes_in_hour = 60.0d0
125+
126+
112127
! instance control vars (these are local for now)
113128
integer(kind=4) :: inst_index
114129
character(len=16) :: inst_name
115130
character(len=16) :: inst_suffix
116131

117132
!!!DANGER!!!: change the following vars with the corresponding MOM6 vars
118-
integer :: km=62 ! number of vertical levels
133+
integer :: km=62 ! number of vertical levels
134+
integer :: nx_block=0, ny_block=0 ! size of block domain in x,y dir including ghost cells
135+
integer :: nx_global, ny_global! size of block domain in x,y dir including ghost cells
136+
integer :: max_blocks_clinic=0 !max number of blocks per processor in each distribution
137+
integer :: ncouple_per_day = 24
138+
logical :: lsend_precip_fact ! if T,send precip_fact to cpl for use in fw balance
139+
! (partially-coupled option)
140+
119141

120142
!-----------------------------------------------------------------------
121143

122144
! set (actually, get from mct) the cdata pointers:
123-
call seq_cdata_setptrs(cdata_o, id=MOM_MCT_ID, mpicom=mpicom_ocn, infodata=infodata)
145+
call seq_cdata_setptrs(cdata_o, id=MOM_MCT_ID, mpicom=mpicom_ocn, &
146+
gsMap=MOM_MCT_gsMap, dom=MOM_MCT_dom, infodata=infodata)
124147

125148
!---------------------------------------------------------------------
126-
! Initialize the model run
149+
! Initialize the model run
127150
!---------------------------------------------------------------------
128151

129152
call coupler_indices_init()
@@ -150,14 +173,14 @@ subroutine ocn_init_mct( EClock, cdata_o, x2o_o, o2x_o, NLFilename )
150173
inst_suffix = seq_comm_suffix(MOM_MCT_ID)
151174

152175
!---------------------------------------------------------------------
153-
! Initialize MOM6
176+
! Initialize MOM6
154177
!---------------------------------------------------------------------
155178

156179
call t_startf('MOM_init')
157180

158181
call MOM_infra_init(mpicom_ocn)
159182

160-
call ESMF_ClockGet(EClock, currTime=current_time, rc=rc)
183+
call ESMF_ClockGet(EClock, currTime=current_time, rc=rc)
161184
call ESMF_TimeGet(current_time, yy=year, mm=month, dd=day, h=hour, m=minute, s=seconds, rc=rc)
162185
call set_calendar_type(NOLEAP) !TODO: confirm this
163186

@@ -178,52 +201,67 @@ subroutine ocn_init_mct( EClock, cdata_o, x2o_o, o2x_o, NLFilename )
178201
call t_stopf('MOM_init')
179202

180203
!---------------------------------------------------------------------
181-
! Initialize MCT attribute vectors and indices
204+
! Initialize MCT attribute vectors and indices
182205
!---------------------------------------------------------------------
183206

184207
call t_startf('MOM_mct_init')
185208

186209
! Set mct global seg maps:
187210

188-
call ocn_SetGSMap_mct(mpicom_ocn, MOM_MCT_ID, MOM_MCT_GSMap, MOM_MCT_GSMap3d)
189-
lsize = mct_gsMap_lsize(MOM_MCT_gsmap, mpicom_ocn)
211+
call ocn_SetGSMap_mct(mpicom_ocn, MOM_MCT_ID, MOM_MCT_GSMap, MOM_MCT_GSMap3d)
212+
lsize = mct_gsMap_lsize(MOM_MCT_gsmap, mpicom_ocn)
190213

191214
! Initialize mct ocn domain (needs ocn initialization info)
192215

193216
call ocn_domain_mct(lsize, MOM_MCT_gsmap, MOM_MCT_dom)
194217
call ocn_domain_mct(lsize*km, MOM_MCT_gsmap3d, MOM_MCT_dom3d)
195218

196219
! Inialize mct attribute vectors
197-
220+
198221
! Initialize the mct attribute vector x2o_o, given Attribute list and length:
199222
call mct_aVect_init(x2o_o, rList=seq_flds_x2o_fields, lsize=lsize)
200223
! set the mct attribute vector x2o_o to zero:
201224
call mct_aVect_zero(x2o_o)
202-
225+
203226
! Initialize the mct attribute vector o2x_o, given Attribute list and length:
204227
call mct_aVect_init(o2x_o, rList=seq_flds_o2x_fields, lsize=lsize)
205228
! set the mct attribute vector o2x_o to zero:
206229
call mct_aVect_zero(o2x_o)
207230

231+
! allocate send buffer
208232
nsend = mct_avect_nRattr(o2x_o)
209-
nrecv = mct_avect_nRattr(x2o_o)
210-
!allocate (SBUFF_SUM(nx_block,ny_block,max_blocks_clinic,nsend))
211-
212-
213-
214-
233+
nrecv = mct_avect_nRattr(x2o_o)
234+
allocate (SBUFF_SUM(nx_block,ny_block,max_blocks_clinic,nsend))
215235

236+
! initialize necessary coupling info
216237

238+
call seq_timemgr_EClockGetData(EClock, dtime=ocn_cpl_dt)
239+
mom_cpl_dt = seconds_in_day / ncouple_per_day
240+
if (mom_cpl_dt /= ocn_cpl_dt) then
241+
write(*,*) 'ERROR pop_cpl_dt and ocn_cpl_dt must be identical'
242+
call exit(0)
243+
end if
217244

245+
! send initial state to driver
218246

247+
!TODO:
248+
! if ( lsend_precip_fact ) then
249+
! call seq_infodata_PutData( infodata, precip_fact=precip_fact)
250+
! end if
219251

220252

253+
call mom_sum_buffer
221254

255+
call ocn_export(o2x_o%rattr, ldiag_cpl, errorCode)
222256

257+
call t_stopf('MOM_mct_init')
223258

224259

225260

226-
call t_stopf('MOM_mct_init')
261+
call seq_infodata_PutData( infodata, &
262+
ocn_nx = nx_global , ocn_ny = ny_global)
263+
call seq_infodata_PutData( infodata, &
264+
ocn_prognostic=.true., ocnrof_prognostic=.true.)
227265

228266

229267

@@ -295,41 +333,52 @@ subroutine ocn_final_mct( EClock, cdata_o, x2o_o, o2x_o)
295333
end subroutine ocn_final_mct
296334

297335

298-
!***********************************************************************
299-
!BOP
300-
!IROUTINE: ocn_SetGSMap_mct
301-
! !INTERFACE:
302-
303-
subroutine ocn_SetGSMap_mct(mpicom_ocn, MOM_MCT_ID, gsMap_ocn, gsMap3d_ocn)
304-
305-
! !DESCRIPTION:
306-
! This routine mct global seg maps for the MOM decomposition
307-
!
308-
! !REVISION HISTORY:
309-
! same as module
310-
311-
! !INPUT/OUTPUT PARAMETERS:
312-
313-
implicit none
314-
integer , intent(in) :: mpicom_ocn
315-
integer , intent(in) :: MOM_MCT_ID
316-
type(mct_gsMap), intent(inout) :: gsMap_ocn
317-
type(mct_gsMap), intent(inout) :: gsMap3d_ocn
318-
319-
!EOP
320-
!BOC
321-
!-----------------------------------------------------------------------
322-
!
323-
! local variables
324-
!
325-
!-----------------------------------------------------------------------
326-
327-
328-
329-
!-----------------------------------------------------------------------
330-
!EOC
331-
332-
end subroutine ocn_SetGSMap_mct
336+
!> This routine mct global seg maps for the MOM decomposition
337+
!!
338+
!! \todo Find out if we should only provide indirect indexing for ocean points and not land.
339+
subroutine ocn_SetGSMap_mct(mpicom_ocn, MOM_MCT_ID, gsMap_ocn, gsMap3d_ocn)
340+
integer, intent(in) :: mpicom_ocn !< MPI communicator
341+
integer, intent(in) :: MOM_MCT_ID !< MCT component ID
342+
type(mct_gsMap), intent(inout) :: gsMap_ocn !< MCT global segment map for 2d data
343+
type(mct_gsMap), intent(inout) :: gsMap3d_ocn !< MCT global segment map for 3d data
344+
! Local variables
345+
integer :: lsize ! Local size of indirect indexing array
346+
integer :: i, j, k ! Local indices
347+
integer :: ni, nj ! Declared sizes of h-point arrays
348+
integer :: ig, jg ! Global indices
349+
type(ocean_grid_type), pointer :: grid => NULL() ! A pointer to a grid structure
350+
integer, allocatable :: gindex(:) ! Indirect indices
351+
352+
call get_state_pointers(ocn_state, grid=grid)
353+
if (.not. associated(grid)) call MOM_error(FATAL, 'ocn_comp_mct.F90, ocn_SetGSMap_mct():' // &
354+
'grid returned from get_state_pointers() was not associated!')
355+
356+
! Size of computational domain
357+
lsize = ( grid%iec - grid%isc + 1 ) * ( grid%jec - grid%jsc + 1 )
358+
359+
! Size of global domain
360+
call get_global_grid_size(grid, ni, nj)
361+
362+
! Create indirect indices for the computational domain
363+
allocate( gindex( lsize ) )
364+
365+
! Set indirect indices in gindex
366+
k = 0
367+
do j = grid%jsc, grid%jec
368+
jg = j - grid%jdg_offset ! TODO: check this calculation
369+
do i = grid%isc, grid%iec
370+
ig = i - grid%idg_offset ! TODO: check this calculation
371+
k = k + 1 ! Increment position within gindex
372+
gindex(k) = ni * ( jg - 1 ) + ig
373+
enddo
374+
enddo
375+
376+
! Tell MCT how to indirectly index into the 2d buffer
377+
call mct_gsMap_init( gsMap_ocn, gindex, mpicom_ocn, MOM_MCT_ID, lsize, ni * nj)
378+
379+
deallocate( gindex )
380+
381+
end subroutine ocn_SetGSMap_mct
333382

334383

335384
!***********************************************************************

0 commit comments

Comments
 (0)