New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
icbini.F90 in branches/2012/dev_r3337_NOCS10_ICB/NEMOGCM/NEMO/OPA_SRC/ICB – NEMO

source: branches/2012/dev_r3337_NOCS10_ICB/NEMOGCM/NEMO/OPA_SRC/ICB/icbini.F90 @ 3371

Last change on this file since 3371 was 3371, checked in by sga, 12 years ago

NEMO branch dev_r3337_NOCS10_ICB: move icb_alloc function into icb_oce to be next to declarations

File size: 20.6 KB
Line 
1MODULE icbini
2
3   !!======================================================================
4   !!                       ***  MODULE  icbini  ***
5   !! Icebergs:  initialise variables for iceberg tracking
6   !!======================================================================
7   !! History :   -   !  2010-01  (T. Martin & A. Adcroft)  Original code
8   !!            3.3  !  2011-03  (G. Madec)  Part conversion to NEMO form ; Removal of mapping from another grid
9   !!             -   !  2011-04  (S. Alderson)  Split into separate modules ; Restore restart routines
10   !!             -   !  2011-05  (S. Alderson)  generate_test_icebergs restored ; new forcing arrays with extra halo ;
11   !!             -   !                          north fold exchange arrays added
12   !!----------------------------------------------------------------------
13   !!----------------------------------------------------------------------
14   !!   icb_init      : initialise icebergs
15   !!   icb_gen       : generate test icebergs
16   !!   icb_nam       : read iceberg namelist
17   !!----------------------------------------------------------------------
18   USE dom_oce        ! ocean domain
19   USE in_out_manager ! IO routines and numout in particular
20   USE lib_mpp        ! mpi library and lk_mpp in particular
21   USE sbc_oce        ! ocean: surface boundary condition
22   USE iom            ! IOM library
23   USE fldread        ! field read
24   USE lbclnk         ! lateral boundary condition - MPP link
25   !
26   USE icb_oce        ! define iceberg arrays
27   USE icbutl         ! iceberg utility routines
28   USE icbrst         ! iceberg restart routines
29   USE icbtrj         ! iceberg trajectory I/O routines
30   USE icbdia         ! iceberg budget routines
31
32   IMPLICIT NONE
33   PRIVATE
34
35   PUBLIC   icb_init  ! routine called in nemogcm.F90 module
36   PUBLIC   icb_gen   ! routine called in icbclv.F90 module
37
38   CHARACTER(len=100) ::   cn_dir = './'   ! Root directory for location of icb files
39   TYPE(FLD_N)        ::   sn_icb          ! information about the calving file to be read
40
41   !!----------------------------------------------------------------------
42   !! NEMO/OPA 3.3 , NEMO Consortium (2011)
43   !! $Id:$
44   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
45   !!----------------------------------------------------------------------
46CONTAINS
47
48   SUBROUTINE icb_init( pdt, kt )
49      !!----------------------------------------------------------------------
50      !!                  ***  ROUTINE dom_init  ***
51      !!
52      !! ** Purpose :   iceberg initialization.
53      !!
54      !! ** Method  : - blah blah
55      !!----------------------------------------------------------------------
56      REAL(wp), INTENT(in) ::   pdt   ! iceberg time-step (rdt*nn_fsbc)
57      INTEGER , INTENT(in) ::   kt    ! time step number
58      !
59      INTEGER ::   ji, jj, jn               ! dummy loop indices
60      INTEGER ::   i1, i2, i3               ! local integers
61      INTEGER ::   ii, inum, ivar           !   -       -
62      INTEGER ::   istat1, istat2, istat3   !   -       -
63      CHARACTER(len=300) ::   cl_sdist      ! local character
64      !!----------------------------------------------------------------------
65      !
66      CALL icb_nam               ! Read and print namelist parameters
67      !
68      IF( .NOT. ln_icebergs )   RETURN
69
70      !                          ! allocate gridded fields
71      IF( icb_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'icb_alloc : unable to allocate arrays' )
72
73      !                          ! open ascii output file or files for iceberg status information
74      !                          ! note that we choose to do this on all processors since we cannot
75      !                          ! predict where icebergs will be ahead of time
76      CALL ctl_opn( numicb, 'icebergs.stat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
77
78      ! set parameters (mostly from namelist)
79      !
80      berg_dt         = pdt
81      first_width (:) = SQRT(  rn_initial_mass(:) / ( rn_LoW_ratio * rn_rho_bergs * rn_initial_thickness(:) )  )
82      first_length(:) = rn_LoW_ratio * first_width(:)
83
84      berg_grid%calving      (:,:)   = 0._wp
85      berg_grid%calving_hflx (:,:)   = 0._wp
86      berg_grid%stored_heat  (:,:)   = 0._wp
87      berg_grid%floating_melt(:,:)   = 0._wp
88      berg_grid%maxclass     (:,:)   = nclasses
89      berg_grid%stored_ice   (:,:,:) = 0._wp
90      berg_grid%tmp          (:,:)   = 0._wp
91      src_calving            (:,:)   = 0._wp
92      src_calving_hflx       (:,:)   = 0._wp
93
94      !                          ! domain for icebergs
95      IF( lk_mpp .AND. jpni == 1 )   CALL ctl_stop( 'icbinit: having ONE processor in x currently does not work' )
96      ! NB: the issue here is simply that cyclic east-west boundary condition have not been coded in mpp case
97      ! for the north fold we work out which points communicate by asking
98      ! lbc_lnk to pass processor number (valid even in single processor case)
99      ! borrow src_calving arrays for this
100      !
101      ! pack i and j together using a scaling of a power of 10
102      nicbpack = 10000
103      IF( jpiglo >= nicbpack )   CALL ctl_stop( 'icbini: processor index packing failure' )
104      nicbfldproc(:) = -1
105
106      DO jj = 1, jpj
107         DO ji = 1, jpi
108            src_calving_hflx(ji,jj) = narea
109            src_calving     (ji,jj) = nicbpack * (njmpp+jj-1) + nimpp+ji-1   !!gm use here mjg(jj) and mig(ji)...
110!!gm        src_calving     (ji,jj) = nicbpack * mjg(jj) + mig(ji)
111         END DO
112      END DO
113      CALL lbc_lnk( src_calving_hflx, 'T', 1._wp )
114      CALL lbc_lnk( src_calving     , 'T', 1._wp )
115
116      ! work out interior of processor from exchange array
117      ! first entry with narea for this processor is left hand interior index
118      ! last  entry                               is right hand interior index
119      jj = jpj/2
120      nicbdi = -1
121      nicbei = -1
122      DO ji = 1, jpi
123         i3 = INT( src_calving(ji,jj) )
124         i2 = INT( i3/nicbpack )
125         i1 = i3 - i2*nicbpack
126         i3 = INT( src_calving_hflx(ji,jj) )
127         IF( i1 == nimpp+ji-1 .AND. i3 == narea ) THEN
128            IF( nicbdi < 0 ) THEN   ;   nicbdi = ji
129            ELSE                    ;   nicbei = ji
130            ENDIF
131         ENDIF
132      END DO
133      !
134      ! repeat for j direction
135      ji = jpi/2
136      nicbdj = -1
137      nicbej = -1
138      DO jj = 1, jpj
139         i3 = INT( src_calving(ji,jj) )
140         i2 = INT( i3/nicbpack )
141         i1 = i3 - i2*nicbpack
142         i3 = INT( src_calving_hflx(ji,jj) )
143         IF( i2 == njmpp+jj-1 .AND. i3 == narea ) THEN
144            IF( nicbdj < 0 ) THEN   ;   nicbdj = jj
145            ELSE                    ;   nicbej = jj
146            ENDIF
147         ENDIF
148      END DO
149      !   
150      ! special for east-west boundary exchange we save the destination index
151      i1 = MAX( nicbdi-1, 1)
152      i3 = INT( src_calving(i1,jpj/2) )
153      jj = INT( i3/nicbpack )
154      ricb_left = REAL( i3 - nicbpack*jj, wp )
155      i1 = MIN( nicbei+1, jpi )
156      i3 = INT( src_calving(i1,jpj/2) )
157      jj = INT( i3/nicbpack )
158      ricb_right = REAL( i3 - nicbpack*jj, wp )
159     
160      ! north fold
161      IF( npolj > 0 ) THEN
162         !
163         ! icebergs in row nicbej+1 get passed across fold
164         nicbfldpts(:)  = INT( src_calving(:,nicbej+1) )
165         nicbflddest(:) = INT( src_calving_hflx(:,nicbej+1) )
166         !
167         ! work out list of unique processors to talk to
168         DO ji = nicbdi, nicbei
169            ii = nicbflddest(ji)
170            DO jn = 1, jpni
171               IF( nicbfldproc(jn) == -1 ) THEN
172                  nicbfldproc(jn) = ii
173                  EXIT                             !!gm EXIT should be avoided: use DO WHILE expression instead
174               ENDIF
175               IF( nicbfldproc(jn) == ii ) EXIT
176            END DO
177         END DO
178      ENDIF
179      !
180      IF( nn_verbose_level > 0) THEN
181         WRITE(numicb,*) 'processor ', narea
182         WRITE(numicb,*) 'jpi, jpj   ', jpi, jpj
183         WRITE(numicb,*) 'nldi, nlei ', nldi, nlei
184         WRITE(numicb,*) 'nldj, nlej ', nldj, nlej
185         WRITE(numicb,*) 'berg i interior ', nicbdi, nicbei
186         WRITE(numicb,*) 'berg j interior ', nicbdj, nicbej
187         WRITE(numicb,*) 'berg left       ', ricb_left
188         WRITE(numicb,*) 'berg right      ', ricb_right
189         jj = jpj/2
190         WRITE(numicb,*) "central j line:"
191         WRITE(numicb,*) "i processor"
192         WRITE(numicb,*) (INT(src_calving_hflx(ji,jj)), ji=1,jpi)
193         WRITE(numicb,*) "i point"
194         WRITE(numicb,*) (INT(src_calving(ji,jj)), ji=1,jpi)
195         ji = jpi/2
196         WRITE(numicb,*) "central i line:"
197         WRITE(numicb,*) "j processor"
198         WRITE(numicb,*) (INT(src_calving_hflx(ji,jj)), jj=1,jpj)
199         WRITE(numicb,*) "j point"
200         WRITE(numicb,*) (INT(src_calving(ji,jj)), jj=1,jpj)
201         IF( npolj > 0 ) THEN
202            WRITE(numicb,*) 'north fold destination points '
203            WRITE(numicb,*) nicbfldpts
204            WRITE(numicb,*) 'north fold destination procs  '
205            WRITE(numicb,*) nicbflddest
206         ENDIF
207         CALL flush(numicb)
208      ENDIF
209     
210      src_calving     (:,:) = 0._wp
211      src_calving_hflx(:,:) = 0._wp
212
213      ! assign each new iceberg with a unique number constructed from the processor number
214      ! and incremented by the total number of processors
215      num_bergs(:) = 0
216      num_bergs(1) = narea - jpnij
217
218      ! when not generating test icebergs we need to setup calving file
219      IF( nn_test_icebergs < 0 ) THEN
220         !
221         ! maximum distribution class array does not change in time so read it once
222         cl_sdist = TRIM( cn_dir )//TRIM( sn_icb%clname )
223         CALL iom_open ( cl_sdist, inum )                              ! open file
224         ivar = iom_varid( inum, 'maxclass', ldstop=.FALSE. )
225         IF( ivar > 0 ) THEN
226            CALL iom_get  ( inum, jpdom_data, 'maxclass', src_calving )   ! read the max distribution array
227            berg_grid%maxclass(:,:) = INT( src_calving )
228            src_calving(:,:) = 0._wp
229         ENDIF
230         CALL iom_close( inum )                                     ! close file
231         !
232         WRITE(numicb,*)
233         WRITE(numicb,*) '          calving read in a file'
234         ALLOCATE( sf_icb(1), STAT=istat1 )         ! Create sf_icb structure (calving)
235         ALLOCATE( sf_icb(1)%fnow(jpi,jpj,1), STAT=istat2 )
236         ALLOCATE( sf_icb(1)%fdta(jpi,jpj,1,2), STAT=istat3 )
237         IF( istat1+istat2+istat3 > 0 ) THEN
238            CALL ctl_stop( 'sbc_icb: unable to allocate sf_icb structure' )   ;   RETURN
239         ENDIF
240         !                                          ! fill sf_icb with the namelist (sn_icb) and control print
241         CALL fld_fill( sf_icb, (/ sn_icb /), cn_dir, 'icb_init', 'read calving data', 'namicb' )
242         !
243      ENDIF
244
245      IF( .NOT.ln_rstart ) THEN
246         IF( nn_test_icebergs > 0 )   CALL icb_gen()
247      ELSE
248         IF( nn_test_icebergs > 0 ) THEN
249            CALL icb_gen()
250         ELSE
251            CALL icebergs_read_restart()
252             l_restarted_bergs = .TRUE.
253         ENDIF
254      ENDIF
255      !
256      IF( nn_sample_rate .GT. 0 ) CALL traj_init( nitend )
257      !
258      CALL icb_budget_init()
259      !
260      IF( nn_verbose_level >= 2 )   CALL print_bergs('icb_init, initial status', nit000-1)
261      !
262   END SUBROUTINE icb_init
263
264   SUBROUTINE icb_gen()
265      !!----------------------------------------------------------------------
266      !!                  ***  ROUTINE icb_gen  ***
267      !!
268      !! ** Purpose :   iceberg generation
269      !!
270      !! ** Method  : - blah blah
271      !!----------------------------------------------------------------------
272      INTEGER                         ::   ji, jj, ibergs
273      TYPE(iceberg)                   ::   localberg ! NOT a pointer but an actual local variable
274      TYPE(point)                     ::   localpt
275      INTEGER                         ::   iyr, imon, iday, ihr, imin, isec
276      INTEGER                         ::   iberg
277      !!----------------------------------------------------------------------
278
279      ! For convenience
280      iberg = nn_test_icebergs
281
282      ! call get_date(Time, iyr, imon, iday, ihr, imin, isec)
283      ! Convert nemo time variables from dom_oce into local versions
284      iyr  = nyear
285      imon = nmonth
286      iday = nday
287      ihr = INT(nsec_day/3600)
288      imin = INT((nsec_day-ihr*3600)/60)
289      isec = nsec_day - ihr*3600 - imin*60
290
291      ! no overlap for icebergs since we want only one instance of each across the whole domain
292      ! so restrict area of interest
293      ! use tmask here because tmask_i has been doctored on one side of the north fold line
294
295      DO jj = nicbdj, nicbej
296         DO ji = nicbdi, nicbei
297            IF( tmask(ji,jj,1) > 0._wp        .AND.                                       &
298                rn_test_box(1) < glamt(ji,jj) .AND. glamt(ji,jj) < rn_test_box(2) .AND.   &
299                rn_test_box(3) < gphit(ji,jj) .AND. gphit(ji,jj) < rn_test_box(4) ) THEN
300               localberg%mass_scaling = rn_mass_scaling(iberg)
301               localpt%xi = REAL( nimpp+ji-1, wp )
302               localpt%yj = REAL( njmpp+jj-1, wp )
303               localpt%lon = bilin(glamt, localpt%xi, localpt%yj, 'T', 0, 0 )
304               localpt%lat = bilin(gphit, localpt%xi, localpt%yj, 'T', 0, 0 )
305               localpt%mass      = rn_initial_mass     (iberg)
306               localpt%thickness = rn_initial_thickness(iberg)
307               localpt%width  = first_width (iberg)
308               localpt%length = first_length(iberg)
309               localpt%year = iyr
310               localpt%day = FLOAT(iday)+(FLOAT(ihr)+FLOAT(imin)/60._wp)/24._wp
311               localpt%mass_of_bits = 0._wp
312               localpt%heat_density = 0._wp
313               localpt%uvel = 0._wp
314               localpt%vvel = 0._wp
315               CALL increment_kounter()
316               localberg%number(:) = num_bergs(:)
317               call add_new_berg_to_list(localberg, localpt)
318            ENDIF
319         END DO
320      END DO
321      !
322      ibergs = count_bergs()
323      IF( lk_mpp ) CALL mpp_sum(ibergs)
324      WRITE(numicb,'(a,i6,a)') 'diamonds, icb_gen: ',ibergs,' were generated'
325      !
326   END SUBROUTINE icb_gen
327
328   SUBROUTINE icb_nam
329      !!----------------------------------------------------------------------
330      !!                     ***  ROUTINE icb_nam  ***
331      !!
332      !! ** Purpose :   read iceberg namelist and print the variables.
333      !!
334      !! ** input   : - namberg namelist
335      !!----------------------------------------------------------------------
336      INTEGER  ::   jn      ! dummy loop indices
337      REAL(wp) ::   zfact   ! local scalar
338      !
339      NAMELIST/namberg/ ln_icebergs    , ln_bergdia     , nn_sample_rate      , rn_initial_mass      ,   &
340         &              rn_distribution, rn_mass_scaling, rn_initial_thickness, nn_verbose_write     ,   &
341         &              rn_rho_bergs   , rn_LoW_ratio   , nn_verbose_level    , ln_operator_splitting,   &
342         &              rn_bits_erosion_fraction        , rn_sicn_shift       , ln_passive_mode      ,   &
343         &              ln_time_average_weight          , nn_test_icebergs    , rn_test_box          ,   &
344         &              rn_speed_limit , cn_dir, sn_icb
345      !!----------------------------------------------------------------------
346
347      ! (NB: frequency positive => hours, negative => months)
348      !            !   file     ! frequency !  variable  ! time intep !  clim  ! 'yearly' or ! weights  ! rotation   !
349      !            !   name     !  (hours)  !   name     !   (T/F)    !  (T/F) !  'monthly'  ! filename ! pairs      !
350      sn_icb = FLD_N( 'calving' ,    -1     , 'calving'  ,  .TRUE.    , .TRUE. ,   'yearly'  , ''       , ''         )
351
352      REWIND( numnam )              ! Namelist namrun : iceberg parameters
353      READ  ( numnam, namberg )
354     
355!!gm  bug here in mpp : the return instruction will be done only on the 1st processor (lwp=True)
356!      IF( .NOT. ln_icebergs .AND. lwp ) THEN
357!         WRITE(numout,*)
358!         WRITE(numout,*) 'icb_nam : iceberg initialization through namberg namelist read'
359!         WRITE(numout,*) '~~~~~~~~ '
360!         WRITE(numout,*) 'NO icebergs used'
361!         RETURN
362!      ENDIF
363!!gm solution:
364
365      IF( .NOT. ln_icebergs ) THEN   ! no icebergs
366         IF(lwp) THEN
367            WRITE(numout,*)
368            WRITE(numout,*) 'icb_nam :   ln_icebergs = F , NO icebergs used'
369            WRITE(numout,*) '~~~~~~~~ '
370         ENDIF
371         RETURN
372      ENDIF
373!!gm end
374
375      IF( nn_test_icebergs > nclasses ) THEN
376          IF(lwp) WRITE(numout,*) 'Resetting nn_test_icebergs to ', nclasses
377          nn_test_icebergs = nclasses
378      ENDIF
379
380      zfact = SUM( rn_distribution )
381      IF( zfact < 1._wp ) THEN
382         IF( zfact <= 0._wp ) THEN
383            CALL ctl_stop( 'icb_init: sum of berg distribution equal to zero' )
384         ELSE
385            rn_distribution(:) = rn_distribution(:) / zfact
386            CALL ctl_warn( 'icb_init: sum of berg input distribution not equal to one and so RESCALED' )
387         ENDIF
388      ENDIF
389
390      IF(lwp) THEN                  ! control print
391         WRITE(numout,*)
392         WRITE(numout,*) 'icb_nam : iceberg initialization through namberg namelist read'
393         WRITE(numout,*) '~~~~~~~~ '
394         WRITE(numout,*) '   Calculate budgets                                            ln_bergdia       = ', ln_bergdia
395         WRITE(numout,*) '   Period between sampling of position for trajectory storage   nn_sample_rate = ', nn_sample_rate
396         WRITE(numout,*) '   Mass thresholds between iceberg classes (kg)                 rn_initial_mass     ='
397         DO jn=1,nclasses
398            WRITE(numout,'(a,f15.2)') '                                                                ',rn_initial_mass(jn)
399         ENDDO
400         WRITE(numout,*) '   Fraction of calving to apply to this class (non-dim)         rn_distribution     ='
401         DO jn = 1, nclasses
402            WRITE(numout,'(a,f10.2)') '                                                                ',rn_distribution(jn)
403         END DO
404         WRITE(numout,*) '   Ratio between effective and real iceberg mass (non-dim)      rn_mass_scaling     = '
405         DO jn = 1, nclasses
406            WRITE(numout,'(a,f10.2)') '                                                                ',rn_mass_scaling(jn)
407         END DO
408         WRITE(numout,*) '   Total thickness of newly calved bergs (m)                    rn_initial_thickness = '
409         DO jn = 1, nclasses
410            WRITE(numout,'(a,f10.2)') '                                                                ',rn_initial_thickness(jn)
411         END DO
412         WRITE(numout,*) '   Timesteps between verbose messages                           nn_verbose_write    = ', nn_verbose_write
413
414         WRITE(numout,*) '   Density of icebergs                           rn_rho_bergs  = ', rn_rho_bergs
415         WRITE(numout,*) '   Initial ratio L/W for newly calved icebergs   rn_LoW_ratio  = ', rn_LoW_ratio
416         WRITE(numout,*) '   Turn on more verbose output                          level  = ', nn_verbose_level
417         WRITE(numout,*) '   Use first order operator splitting for thermodynamics    ',   &
418            &                    'use_operator_splitting = ', ln_operator_splitting
419         WRITE(numout,*) '   Fraction of erosion melt flux to divert to bergy bits    ',   &
420            &                    'bits_erosion_fraction = ', rn_bits_erosion_fraction
421
422         WRITE(numout,*) '   Shift of sea-ice concentration in erosion flux modulation ',   &
423            &                    '(0<sicn_shift<1)    rn_sicn_shift  = ', rn_sicn_shift
424         WRITE(numout,*) '   Do not add freshwater flux from icebergs to ocean                ',   &
425            &                    '                  passive_mode            = ', ln_passive_mode
426         WRITE(numout,*) '   Time average the weight on the ocean   time_average_weight       = ', ln_time_average_weight
427         WRITE(numout,*) '   Create icebergs in absence of a restart file   nn_test_icebergs  = ', nn_test_icebergs
428         WRITE(numout,*) '                   in lon/lat box                                   = ', rn_test_box
429         WRITE(numout,*) '   CFL speed limit for a berg            speed_limit                = ', rn_speed_limit
430         WRITE(numout,*) '   Writing Iceberg status information to icebergs.stat file        '
431      ENDIF
432      !
433   END SUBROUTINE icb_nam
434
435   !!======================================================================
436
437END MODULE icbini
Note: See TracBrowser for help on using the repository browser.