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.
domutl.F90 in NEMO/branches/2020/dev_r14116_HPC-04_mcastril_Mixed_Precision_implementation_final/src/OCE/DOM – NEMO

source: NEMO/branches/2020/dev_r14116_HPC-04_mcastril_Mixed_Precision_implementation_final/src/OCE/DOM/domutl.F90 @ 14219

Last change on this file since 14219 was 14219, checked in by mcastril, 4 years ago

Add Mixed Precision support by Oriol Tintó

  • Property svn:keywords set to Id
File size: 7.6 KB
Line 
1MODULE domutl
2   !!======================================================================
3   !!                       ***  MODULE  domutl  ***
4   !! Grid utilities:
5   !!======================================================================
6   !! History : 4.2  !  2020-04  (S. Masson)  Original code
7   !!----------------------------------------------------------------------
8
9   !!----------------------------------------------------------------------
10   !!   dom_ngb       : find the closest grid point from a given lon/lat position
11   !!   dom_uniq      : identify unique point of a grid (TUVF)
12   !!----------------------------------------------------------------------
13   !
14   USE dom_oce        ! ocean space and time domain
15   !
16   USE in_out_manager ! I/O manager
17   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
18   USE lib_mpp        ! for mppsum
19
20   IMPLICIT NONE
21   PRIVATE
22
23   INTERFACE is_tile
24      MODULE PROCEDURE is_tile_2d_sp, is_tile_3d_sp, is_tile_4d_sp
25      MODULE PROCEDURE is_tile_2d_dp, is_tile_3d_dp, is_tile_4d_dp
26   END INTERFACE is_tile
27
28   PUBLIC dom_ngb    ! routine called in iom.F90 module
29   PUBLIC dom_uniq   ! Called by dommsk and domwri
30   PUBLIC is_tile
31
32   !!----------------------------------------------------------------------
33   !! NEMO/OCE 4.2 , NEMO Consortium (2020)
34   !! $Id$
35   !! Software governed by the CeCILL license (see ./LICENSE)
36   !!----------------------------------------------------------------------
37CONTAINS
38
39   SUBROUTINE dom_ngb( plon, plat, kii, kjj, cdgrid, kkk )
40      !!----------------------------------------------------------------------
41      !!                    ***  ROUTINE dom_ngb  ***
42      !!
43      !! ** Purpose :   find the closest grid point from a given lon/lat position
44      !!
45      !! ** Method  :   look for minimum distance in cylindrical projection
46      !!                -> not good if located at too high latitude...
47      !!----------------------------------------------------------------------
48      REAL(wp)        , INTENT(in   ) ::   plon, plat   ! longitude,latitude of the point
49      INTEGER         , INTENT(  out) ::   kii, kjj     ! i-,j-index of the closes grid point
50      INTEGER         , INTENT(in   ), OPTIONAL :: kkk  ! k-index of the mask level used
51      CHARACTER(len=1), INTENT(in   ) ::   cdgrid       ! grid name 'T', 'U', 'V', 'W'
52      !
53      INTEGER :: ik         ! working level
54      INTEGER , DIMENSION(2) ::   iloc
55      REAL(wp)               ::   zlon, zmini
56      REAL(wp), DIMENSION(jpi,jpj) ::   zglam, zgphi, zdist
57      LOGICAL , DIMENSION(jpi,jpj) ::   llmsk
58      !!--------------------------------------------------------------------
59      !
60      ik = 1
61      IF ( PRESENT(kkk) ) ik=kkk
62      !
63      SELECT CASE( cdgrid )
64      CASE( 'U' ) ;   zglam(:,:) = glamu(:,:)   ;   zgphi(:,:) = gphiu(:,:)   ;   llmsk(:,:) = tmask_h(:,:) * umask(:,:,ik) == 1._wp
65      CASE( 'V' ) ;   zglam(:,:) = glamv(:,:)   ;   zgphi(:,:) = gphiv(:,:)   ;   llmsk(:,:) = tmask_h(:,:) * vmask(:,:,ik) == 1._wp
66      CASE( 'F' ) ;   zglam(:,:) = glamf(:,:)   ;   zgphi(:,:) = gphif(:,:)   ;   llmsk(:,:) = tmask_h(:,:) * fmask(:,:,ik) == 1._wp
67      CASE DEFAULT;   zglam(:,:) = glamt(:,:)   ;   zgphi(:,:) = gphit(:,:)   ;   llmsk(:,:) = tmask_h(:,:) * tmask(:,:,ik) == 1._wp
68      END SELECT
69      !
70      zlon       = MOD( plon       + 720., 360. )                                     ! plon between    0 and 360
71      zglam(:,:) = MOD( zglam(:,:) + 720., 360. )                                     ! glam between    0 and 360
72      IF( zlon > 270. )   zlon = zlon - 360.                                          ! zlon between  -90 and 270
73      IF( zlon <  90. )   WHERE( zglam(:,:) > 180. ) zglam(:,:) = zglam(:,:) - 360.   ! glam between -180 and 180
74      zglam(:,:) = zglam(:,:) - zlon
75      !
76      zgphi(:,:) = zgphi(:,:) - plat
77      zdist(:,:) = zglam(:,:) * zglam(:,:) + zgphi(:,:) * zgphi(:,:)
78      !
79      CALL mpp_minloc( 'domngb', zdist(:,:), llmsk, zmini, iloc, ldhalo = .TRUE. )
80      kii = iloc(1)
81      kjj = iloc(2)
82      !
83   END SUBROUTINE dom_ngb
84
85
86   SUBROUTINE dom_uniq( puniq, cdgrd )
87      !!----------------------------------------------------------------------
88      !!                  ***  ROUTINE dom_uniq  ***
89      !!
90      !! ** Purpose :   identify unique point of a grid (TUVF)
91      !!
92      !! ** Method  :   1) aplly lbc_lnk on an array with different values for each element
93      !!                2) check which elements have been changed
94      !!----------------------------------------------------------------------
95      CHARACTER(len=1)        , INTENT(in   ) ::   cdgrd   !
96      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   puniq   !
97      !
98      REAL(wp)                       ::  zshift   ! shift value link to the process number
99      INTEGER                        ::  ji       ! dummy loop indices
100      LOGICAL , DIMENSION(jpi,jpj,1) ::   lluniq  ! store whether each point is unique or not
101      REAL(wp), DIMENSION(jpi,jpj  ) ::   ztstref
102      !!----------------------------------------------------------------------
103      !
104      ! build an array with different values for each element
105      ! in mpp: make sure that these values are different even between process
106      ! -> apply a shift value according to the process number
107      zshift = jpimax * jpjmax * ( narea - 1 )
108      ztstref(:,:) = RESHAPE( (/ (zshift + REAL(ji,wp), ji = 1, jpi*jpj) /), (/ jpi, jpj /) )
109      !
110      puniq(:,:) = ztstref(:,:)                    ! default definition
111      CALL lbc_lnk( 'domwri', puniq, cdgrd, 1._wp )   ! apply boundary conditions
112      lluniq(:,:,1) = puniq(:,:) == ztstref(:,:)   ! check which values have not been changed
113      !
114      puniq(:,:) = REAL( COUNT( lluniq(:,:,:), dim = 3 ), wp )
115      !
116   END SUBROUTINE dom_uniq
117
118
119   FUNCTION is_tile_2d_sp( pt )
120      !!
121      REAL(sp), DIMENSION(:,:), INTENT(in) ::   pt
122      INTEGER :: is_tile_2d_sp
123      !!
124      IF( ln_tile .AND. (SIZE(pt, 1) < jpi .OR. SIZE(pt, 2) < jpj) ) THEN
125         is_tile_2d_sp = 1
126      ELSE
127         is_tile_2d_sp = 0
128      ENDIF
129   END FUNCTION is_tile_2d_sp
130
131
132   FUNCTION is_tile_3d_sp( pt )
133      !!
134      REAL(sp), DIMENSION(:,:,:), INTENT(in) ::   pt
135      INTEGER :: is_tile_3d_sp
136      !!
137      IF( ln_tile .AND. (SIZE(pt, 1) < jpi .OR. SIZE(pt, 2) < jpj) ) THEN
138         is_tile_3d_sp = 1
139      ELSE
140         is_tile_3d_sp = 0
141      ENDIF
142   END FUNCTION is_tile_3d_sp
143
144
145   FUNCTION is_tile_4d_sp( pt )
146      !!
147      REAL(sp), DIMENSION(:,:,:,:), INTENT(in) ::   pt
148      INTEGER :: is_tile_4d_sp
149      !!
150      IF( ln_tile .AND. (SIZE(pt, 1) < jpi .OR. SIZE(pt, 2) < jpj) ) THEN
151         is_tile_4d_sp = 1
152      ELSE
153         is_tile_4d_sp = 0
154      ENDIF
155   END FUNCTION is_tile_4d_sp
156
157   FUNCTION is_tile_2d_dp( pt )
158      !!
159      REAL(dp), DIMENSION(:,:), INTENT(in) ::   pt
160      INTEGER :: is_tile_2d_dp
161      !!
162      IF( ln_tile .AND. (SIZE(pt, 1) < jpi .OR. SIZE(pt, 2) < jpj) ) THEN
163         is_tile_2d_dp = 1
164      ELSE
165         is_tile_2d_dp = 0
166      ENDIF
167   END FUNCTION is_tile_2d_dp
168
169
170   FUNCTION is_tile_3d_dp( pt )
171      !!
172      REAL(dp), DIMENSION(:,:,:), INTENT(in) ::   pt
173      INTEGER :: is_tile_3d_dp
174      !!
175      IF( ln_tile .AND. (SIZE(pt, 1) < jpi .OR. SIZE(pt, 2) < jpj) ) THEN
176         is_tile_3d_dp = 1
177      ELSE
178         is_tile_3d_dp = 0
179      ENDIF
180   END FUNCTION is_tile_3d_dp
181
182
183   FUNCTION is_tile_4d_dp( pt )
184      !!
185      REAL(dp), DIMENSION(:,:,:,:), INTENT(in) ::   pt
186      INTEGER :: is_tile_4d_dp
187      !!
188      IF( ln_tile .AND. (SIZE(pt, 1) < jpi .OR. SIZE(pt, 2) < jpj) ) THEN
189         is_tile_4d_dp = 1
190      ELSE
191         is_tile_4d_dp = 0
192      ENDIF
193   END FUNCTION is_tile_4d_dp
194
195
196   !!======================================================================
197END MODULE domutl
Note: See TracBrowser for help on using the repository browser.