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/2013/dev_r3853_CNRS9_ConfSetting/NEMOGCM/NEMO/OPA_SRC/ICB – NEMO

source: branches/2013/dev_r3853_CNRS9_ConfSetting/NEMOGCM/NEMO/OPA_SRC/ICB/icbini.F90 @ 3901

Last change on this file since 3901 was 3901, checked in by clevy, 11 years ago

Configuration Setting/Step2, see ticket:#1074

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