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.
cpl_rnf_1d.F90 in branches/UKMO/dev_r5518_new_runoff_coupling/NEMOGCM/NEMO/OPA_SRC/SBC – NEMO

source: branches/UKMO/dev_r5518_new_runoff_coupling/NEMOGCM/NEMO/OPA_SRC/SBC/cpl_rnf_1d.F90

Last change on this file was 9566, checked in by dancopsey, 6 years ago

Use complex numbers in area calculations.

File size: 9.3 KB
Line 
1MODULE cpl_rnf_1d
2   !!======================================================================
3   !!                       ***  MODULE  cpl_rnf_1d  ***
4   !! Ocean forcing:  River runoff passed from the atmosphere using
5   !!                 1D array. One value per river.
6   !!=====================================================================
7   !! History : ?.?  ! 2018-01 (D. Copsey) Initial setup
8   !!----------------------------------------------------------------------
9
10   !!----------------------------------------------------------------------
11   !!   cpl_rnf_1d_init : runoffs initialisation
12   !!----------------------------------------------------------------------
13
14#if defined key_oasis3
15   USE mod_oasis                    ! OASIS3-MCT module
16#endif
17   USE timing          ! Timing
18   USE in_out_manager  ! I/O units
19   USE lib_mpp         ! MPP library
20   USE iom
21   USE wrk_nemo        ! Memory allocation
22   USE dom_oce         ! Domain sizes (for grid box area e1e2t)
23   USE sbc_oce         ! Surface boundary condition: ocean fields
24   USE lib_fortran,    ONLY: DDPDD
25   
26   IMPLICIT NONE
27   PRIVATE
28   
29   PUBLIC   cpl_rnf_1d_init     ! routine called in nemo_init
30   PUBLIC   cpl_rnf_1d_rcv      ! routine called in sbccpl.F90
31   
32   TYPE, PUBLIC ::   RIVERS_DATA     !: Storage for river outflow data
33      INTEGER, POINTER, DIMENSION(:,:)    ::   river_number       !: River outflow number
34      REAL(wp), POINTER, DIMENSION(:)     ::   river_area         ! 1D array listing areas of each river outflow (m2)
35      COMPLEX(wp), POINTER, DIMENSION(:)  ::   river_area_c       ! Comlex version of river_area for use in bit reproducible sums (m2)
36   END TYPE RIVERS_DATA
37   
38   TYPE(RIVERS_DATA), PUBLIC, TARGET :: rivers  !: River data
39   
40   INTEGER, PUBLIC            :: nn_cpl_river   ! Maximum number of rivers being passed through the coupler
41   INTEGER, PUBLIC            :: runoff_id      ! OASIS coupling id used in oasis_get command
42   LOGICAL                    :: ln_print_river_info  ! Diagnostic prints of river coupling information
43   
44CONTAINS
45
46   SUBROUTINE cpl_rnf_1d_init
47      !!----------------------------------------------------------------------
48      !!                    ***  SUBROUTINE cpl_rnf_1d_init  ***
49      !!                     
50      !! ** Purpose : - Read in file for river outflow numbers.
51      !!                Calculate 2D area of river outflow points.
52      !!                Called from nemo_init (nemogcm.F90).
53      !!
54      !!----------------------------------------------------------------------
55      !! namelist variables
56      !!-------------------
57      CHARACTER(len=80)                         ::   file_riv_number             !: Filename for river numbers
58      INTEGER                                   ::   ios                 ! Local integer output status for namelist read
59      INTEGER                                   ::   inum
60      INTEGER                                   ::   ii, jj, rr          !: Loop indices
61      INTEGER                                   ::   max_river
62      REAL(wp), POINTER, DIMENSION(:,:)         ::   river_number        ! 2D array containing the river outflow numbers
63     
64      NAMELIST/nam_cpl_rnf_1d/file_riv_number, nn_cpl_river, ln_print_river_info
65      !!----------------------------------------------------------------------
66
67      IF( nn_timing == 1 ) CALL timing_start('cpl_rnf_1d_init')
68     
69      IF(lwp) WRITE(numout,*)
70      IF(lwp) WRITE(numout,*) 'cpl_rnf_1d_init : initialization of river runoff coupling'
71      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
72     
73      REWIND(numnam_cfg)
74     
75      ! Read the namelist
76      READ  ( numnam_ref, nam_cpl_rnf_1d, IOSTAT = ios, ERR = 901)
77901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_cpl_rnf_1d in reference namelist', lwp )
78      READ  ( numnam_cfg, nam_cpl_rnf_1d, IOSTAT = ios, ERR = 902 )
79902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_cpl_rnf_1d in configuration namelist', lwp )
80      IF(lwm) WRITE ( numond, nam_cpl_rnf_1d )
81
82      !                                               ! Parameter control and print
83      IF(lwp) WRITE(numout,*) '  '
84      IF(lwp) WRITE(numout,*) '          Namelist nam_cpl_rnf_1d : Coupled runoff using 1D array'
85      IF(lwp) WRITE(numout,*) '             Input file that contains river numbers = ',file_riv_number
86      IF(lwp) WRITE(numout,*) '             Maximum number of rivers to couple = ',nn_cpl_river
87      IF(lwp) WRITE(numout,*) '             Print river information = ',ln_print_river_info
88      IF(lwp) WRITE(numout,*) ' '
89     
90      ! Assign space for river numbers
91      ALLOCATE( rivers%river_number( jpi, jpj ) )
92      CALL wrk_alloc( jpi, jpj, river_number )
93     
94      ! Read the river numbers from netcdf file
95      CALL iom_open (file_riv_number , inum )
96      CALL iom_get  ( inum, jpdom_data, 'river_number', river_number )
97      CALL iom_close( inum )
98     
99      ! Convert from a real array to an integer array
100      max_river=0
101      DO ii = 1, jpi
102        DO jj = 1, jpj
103          rivers%river_number(ii,jj) = INT(river_number(ii,jj))
104          IF ( rivers%river_number(ii,jj) > max_river ) THEN
105            max_river = rivers%river_number(ii,jj)
106          END IF
107        END DO
108      END DO
109     
110      ! Print out the largest river number
111      WRITE(numout,*) 'Maximum river number in input file = ',max_river
112     
113      ! Get the area of each river outflow
114      ALLOCATE( rivers%river_area( nn_cpl_river ) )
115      ALLOCATE( rivers%river_area_c( nn_cpl_river ) )
116      rivers%river_area_c(:) = CMPLX( 0.e0, 0.e0, wp )
117      DO ii = nldi, nlei     
118        DO jj = nldj, nlej
119          IF ( tmask_i(ii,jj) > 0.5 ) THEN  ! This makes sure we are not at a duplicated point (at north fold or east-west cyclic point)
120            IF ( rivers%river_number(ii,jj) > 0 .AND. rivers%river_number(ii,jj) <= nn_cpl_river ) THEN
121              ! Add the area of each grid box (e1e2t) into river_area_c using DDPDD which should maintain bit reproducibility (needs to be checked)
122              CALL DDPDD( CMPLX( e1e2t(ii,jj), 0.e0, wp ), rivers%river_area_c(rivers%river_number(ii,jj) ) )
123            END IF
124          ELSE
125            IF ( jj == nldj .AND. tmask(ii,jj) > 0.5 ) THEN
126              WRITE(numout,*) 'At duplicated point at ii = ',ii
127            END IF
128          END IF
129        END DO
130      END DO
131     
132      ! Use mpp_sum to add together river areas on other processors
133      CALL mpp_sum( rivers%river_area_c, nn_cpl_river )
134     
135      ! Convert from complex number to real
136      ! DO rr = 1, nn_cpl_river
137      !    rivers%river_area(rr) = rivers%river_area_c(rr)
138      ! END DO
139      rivers%river_area(:) = REAL(rivers%river_area_c(:),wp)
140     
141      IF ( ln_print_river_info ) THEN
142        WRITE(numout,*) 'Area of rivers 1 to 10 are ',rivers%river_area(1:10)
143      END IF
144     
145   END SUBROUTINE cpl_rnf_1d_init
146   
147   SUBROUTINE cpl_rnf_1d_rcv( kstep)
148   
149      !!----------------------------------------------------------------------
150      !!                    ***  SUBROUTINE cpl_rnf_1d_rcv  ***
151      !!                     
152      !! ** Purpose : - Get river outflow from 1D array (passed from the
153      !!                atmosphere) and transfer it to the 2D NEMO runoff
154      !!                field.
155      !!                Called from sbc_cpl_rcv (sbccpl.F90).
156      !!
157      !!----------------------------------------------------------------------
158     
159      INTEGER                   , INTENT(in   ) ::   kstep     ! ocean time-step in seconds
160     
161      INTEGER  ::   kinfo                  ! OASIS3 info argument   
162      REAL(wp) ::   runoff_1d(nn_cpl_river)    ! River runoff. One value per river.
163      INTEGER  ::   ii, jj                 ! Loop indices
164      LOGICAL  ::   llaction               ! Has the get worked?
165     
166      IF ( ln_print_river_info ) THEN
167         WRITE(numout,*)' Getting data from 1D river runoff coupling '
168      ENDIF
169   
170      ! Get the river runoff sent by the atmosphere
171      CALL oasis_get ( runoff_id, kstep, runoff_1d, kinfo )
172      llaction =  kinfo == OASIS_Recvd   .OR. kinfo == OASIS_FromRest .OR.   &
173                  &        kinfo == OASIS_RecvOut .OR. kinfo == OASIS_FromRestOut
174                 
175      ! Output coupling info
176      IF ( ln_print_river_info ) THEN
177         WRITE(numout,*)' narea = ', narea
178         WRITE(numout,*)' kstep = ', kstep
179         WRITE(numout,*)' River runoff = ', runoff_1d(1:10)
180         WRITE(numout,*)' kinfo = ', kinfo
181         WRITE(numout,*)' llaction = ', llaction
182         WRITE(numout,*)' OASIS_Recvd = ',OASIS_Recvd
183         WRITE(numout,*)' OASIS_FromRest = ',OASIS_FromRest
184         WRITE(numout,*)' OASIS_RecvOut = ',OASIS_RecvOut
185         WRITE(numout,*)' OASIS_FromRestOut = ',OASIS_FromRestOut
186         WRITE(numout,*)'-------'
187      ENDIF
188     
189      IF ( llaction ) THEN
190     
191        ! Convert the 1D total runoff per river to 2D runoff flux by
192        ! dividing by the area of each runoff zone.
193        DO ii = 1, jpi
194          DO jj = 1, jpj
195            IF ( rivers%river_number(ii,jj) > 0 .AND. rivers%river_number(ii,jj) <= nn_cpl_river ) THEN
196              rnf(ii,jj) = runoff_1d(rivers%river_number(ii,jj)) / rivers%river_area(rivers%river_number(ii,jj))
197            ELSE
198              rnf(ii,jj) = 0.0
199            END IF
200           
201          END DO
202        END DO
203         
204      END IF
205     
206      IF ( ln_print_river_info ) WRITE(numout,*)' River runoff flux of AMAZON (pe 351) is ', rnf(59,29)         
207   
208   END SUBROUTINE cpl_rnf_1d_rcv
209
210END MODULE cpl_rnf_1d
Note: See TracBrowser for help on using the repository browser.