bdytides.F90 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. MODULE bdytides
  2. !!======================================================================
  3. !! *** MODULE bdytides ***
  4. !! Ocean dynamics: Tidal forcing at open boundaries
  5. !!======================================================================
  6. !! History : 2.0 ! 2007-01 (D.Storkey) Original code
  7. !! 2.3 ! 2008-01 (J.Holt) Add date correction. Origins POLCOMS v6.3 2007
  8. !! 3.0 ! 2008-04 (NEMO team) add in the reference version
  9. !! 3.3 ! 2010-09 (D.Storkey and E.O'Dea) bug fixes
  10. !! 3.4 ! 2012-09 (G. Reffray and J. Chanut) New inputs + mods
  11. !! 3.5 ! 2013-07 (J. Chanut) Compliant with time splitting changes
  12. !!----------------------------------------------------------------------
  13. #if defined key_bdy
  14. !!----------------------------------------------------------------------
  15. !! 'key_bdy' Open Boundary Condition
  16. !!----------------------------------------------------------------------
  17. !! PUBLIC
  18. !! bdytide_init : read of namelist and initialisation of tidal harmonics data
  19. !! tide_update : calculation of tidal forcing at each timestep
  20. !!----------------------------------------------------------------------
  21. USE timing ! Timing
  22. USE oce ! ocean dynamics and tracers
  23. USE dom_oce ! ocean space and time domain
  24. USE iom
  25. USE in_out_manager ! I/O units
  26. USE phycst ! physical constants
  27. USE lbclnk ! ocean lateral boundary conditions (or mpp link)
  28. USE bdy_par ! Unstructured boundary parameters
  29. USE bdy_oce ! ocean open boundary conditions
  30. USE daymod ! calendar
  31. USE wrk_nemo ! Memory allocation
  32. USE tideini
  33. ! USE tide_mod ! Useless ??
  34. USE fldread
  35. USE dynspg_oce, ONLY: lk_dynspg_ts
  36. IMPLICIT NONE
  37. PRIVATE
  38. PUBLIC bdytide_init ! routine called in bdy_init
  39. PUBLIC bdytide_update ! routine called in bdy_dta
  40. PUBLIC bdy_dta_tides ! routine called in dyn_spg_ts
  41. TYPE, PUBLIC :: TIDES_DATA !: Storage for external tidal harmonics data
  42. REAL(wp), POINTER, DIMENSION(:,:,:) :: ssh0 !: Tidal constituents : SSH0 (read in file)
  43. REAL(wp), POINTER, DIMENSION(:,:,:) :: u0 !: Tidal constituents : U0 (read in file)
  44. REAL(wp), POINTER, DIMENSION(:,:,:) :: v0 !: Tidal constituents : V0 (read in file)
  45. REAL(wp), POINTER, DIMENSION(:,:,:) :: ssh !: Tidal constituents : SSH (after nodal cor.)
  46. REAL(wp), POINTER, DIMENSION(:,:,:) :: u !: Tidal constituents : U (after nodal cor.)
  47. REAL(wp), POINTER, DIMENSION(:,:,:) :: v !: Tidal constituents : V (after nodal cor.)
  48. END TYPE TIDES_DATA
  49. !$AGRIF_DO_NOT_TREAT
  50. TYPE(TIDES_DATA), PUBLIC, DIMENSION(jp_bdy), TARGET :: tides !: External tidal harmonics data
  51. !$AGRIF_END_DO_NOT_TREAT
  52. TYPE(OBC_DATA) , PRIVATE, DIMENSION(jp_bdy) :: dta_bdy_s !: bdy external data (slow component)
  53. !!----------------------------------------------------------------------
  54. !! NEMO/OPA 3.3 , NEMO Consortium (2010)
  55. !! $Id: bdytides.F90 4758 2014-09-05 12:13:33Z jchanut $
  56. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  57. !!----------------------------------------------------------------------
  58. CONTAINS
  59. SUBROUTINE bdytide_init
  60. !!----------------------------------------------------------------------
  61. !! *** SUBROUTINE bdytide_init ***
  62. !!
  63. !! ** Purpose : - Read in namelist for tides and initialise external
  64. !! tidal harmonics data
  65. !!
  66. !!----------------------------------------------------------------------
  67. !! namelist variables
  68. !!-------------------
  69. CHARACTER(len=80) :: filtide !: Filename root for tidal input files
  70. LOGICAL :: ln_bdytide_2ddta !: If true, read 2d harmonic data
  71. LOGICAL :: ln_bdytide_conj !: If true, assume complex conjugate tidal data
  72. !!
  73. INTEGER :: ib_bdy, itide, ib !: dummy loop indices
  74. INTEGER :: ii, ij !: dummy loop indices
  75. INTEGER :: inum, igrd
  76. INTEGER, DIMENSION(3) :: ilen0 !: length of boundary data (from OBC arrays)
  77. INTEGER, POINTER, DIMENSION(:) :: nblen, nblenrim ! short cuts
  78. INTEGER :: ios ! Local integer output status for namelist read
  79. CHARACTER(len=80) :: clfile !: full file name for tidal input file
  80. REAL(wp),ALLOCATABLE, DIMENSION(:,:,:) :: dta_read !: work space to read in tidal harmonics data
  81. REAL(wp), POINTER, DIMENSION(:,:) :: ztr, zti !: " " " " " " " "
  82. !!
  83. TYPE(TIDES_DATA), POINTER :: td !: local short cut
  84. TYPE(MAP_POINTER), DIMENSION(jpbgrd) :: ibmap_ptr !: array of pointers to nbmap
  85. !!
  86. NAMELIST/nambdy_tide/filtide, ln_bdytide_2ddta, ln_bdytide_conj
  87. !!----------------------------------------------------------------------
  88. IF( nn_timing == 1 ) CALL timing_start('bdytide_init')
  89. IF (nb_bdy>0) THEN
  90. IF(lwp) WRITE(numout,*)
  91. IF(lwp) WRITE(numout,*) 'bdytide_init : initialization of tidal harmonic forcing at open boundaries'
  92. IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
  93. ENDIF
  94. REWIND(numnam_cfg)
  95. DO ib_bdy = 1, nb_bdy
  96. IF( nn_dyn2d_dta(ib_bdy) .ge. 2 ) THEN
  97. td => tides(ib_bdy)
  98. nblen => idx_bdy(ib_bdy)%nblen
  99. nblenrim => idx_bdy(ib_bdy)%nblenrim
  100. ! Namelist nambdy_tide : tidal harmonic forcing at open boundaries
  101. filtide(:) = ''
  102. ! Don't REWIND here - may need to read more than one of these namelists.
  103. READ ( numnam_ref, nambdy_tide, IOSTAT = ios, ERR = 901)
  104. 901 IF( ios /= 0 ) CALL ctl_nam ( ios , 'nambdy_tide in reference namelist', lwp )
  105. READ ( numnam_cfg, nambdy_tide, IOSTAT = ios, ERR = 902 )
  106. 902 IF( ios /= 0 ) CALL ctl_nam ( ios , 'nambdy_tide in configuration namelist', lwp )
  107. IF(lwm) WRITE ( numond, nambdy_tide )
  108. ! ! Parameter control and print
  109. IF(lwp) WRITE(numout,*) ' '
  110. IF(lwp) WRITE(numout,*) ' Namelist nambdy_tide : tidal harmonic forcing at open boundaries'
  111. IF(lwp) WRITE(numout,*) ' read tidal data in 2d files: ', ln_bdytide_2ddta
  112. IF(lwp) WRITE(numout,*) ' assume complex conjugate : ', ln_bdytide_conj
  113. IF(lwp) WRITE(numout,*) ' Number of tidal components to read: ', nb_harmo
  114. IF(lwp) THEN
  115. WRITE(numout,*) ' Tidal components: '
  116. DO itide = 1, nb_harmo
  117. WRITE(numout,*) ' ', Wave(ntide(itide))%cname_tide
  118. END DO
  119. ENDIF
  120. IF(lwp) WRITE(numout,*) ' '
  121. ! Allocate space for tidal harmonics data - get size from OBC data arrays
  122. ! -----------------------------------------------------------------------
  123. ! JC: If FRS scheme is used, we assume that tidal is needed over the whole
  124. ! relaxation area
  125. IF( cn_dyn2d(ib_bdy) == 'frs' ) THEN
  126. ilen0(:)=nblen(:)
  127. ELSE
  128. ilen0(:)=nblenrim(:)
  129. ENDIF
  130. ALLOCATE( td%ssh0( ilen0(1), nb_harmo, 2 ) )
  131. ALLOCATE( td%ssh ( ilen0(1), nb_harmo, 2 ) )
  132. ALLOCATE( td%u0( ilen0(2), nb_harmo, 2 ) )
  133. ALLOCATE( td%u ( ilen0(2), nb_harmo, 2 ) )
  134. ALLOCATE( td%v0( ilen0(3), nb_harmo, 2 ) )
  135. ALLOCATE( td%v ( ilen0(3), nb_harmo, 2 ) )
  136. td%ssh0(:,:,:) = 0._wp
  137. td%ssh (:,:,:) = 0._wp
  138. td%u0 (:,:,:) = 0._wp
  139. td%u (:,:,:) = 0._wp
  140. td%v0 (:,:,:) = 0._wp
  141. td%v (:,:,:) = 0._wp
  142. IF (ln_bdytide_2ddta) THEN
  143. ! It is assumed that each data file contains all complex harmonic amplitudes
  144. ! given on the data domain (ie global, jpidta x jpjdta)
  145. !
  146. CALL wrk_alloc( jpi, jpj, zti, ztr )
  147. !
  148. ! SSH fields
  149. clfile = TRIM(filtide)//'_grid_T.nc'
  150. CALL iom_open (clfile , inum )
  151. igrd = 1 ! Everything is at T-points here
  152. DO itide = 1, nb_harmo
  153. CALL iom_get ( inum, jpdom_data, TRIM(Wave(ntide(itide))%cname_tide)//'_z1', ztr(:,:) )
  154. CALL iom_get ( inum, jpdom_data, TRIM(Wave(ntide(itide))%cname_tide)//'_z2', zti(:,:) )
  155. DO ib = 1, ilen0(igrd)
  156. ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
  157. ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
  158. td%ssh0(ib,itide,1) = ztr(ii,ij)
  159. td%ssh0(ib,itide,2) = zti(ii,ij)
  160. END DO
  161. END DO
  162. CALL iom_close( inum )
  163. !
  164. ! U fields
  165. clfile = TRIM(filtide)//'_grid_U.nc'
  166. CALL iom_open (clfile , inum )
  167. igrd = 2 ! Everything is at U-points here
  168. DO itide = 1, nb_harmo
  169. CALL iom_get ( inum, jpdom_data, TRIM(Wave(ntide(itide))%cname_tide)//'_u1', ztr(:,:) )
  170. CALL iom_get ( inum, jpdom_data, TRIM(Wave(ntide(itide))%cname_tide)//'_u2', zti(:,:) )
  171. DO ib = 1, ilen0(igrd)
  172. ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
  173. ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
  174. td%u0(ib,itide,1) = ztr(ii,ij)
  175. td%u0(ib,itide,2) = zti(ii,ij)
  176. END DO
  177. END DO
  178. CALL iom_close( inum )
  179. !
  180. ! V fields
  181. clfile = TRIM(filtide)//'_grid_V.nc'
  182. CALL iom_open (clfile , inum )
  183. igrd = 3 ! Everything is at V-points here
  184. DO itide = 1, nb_harmo
  185. CALL iom_get ( inum, jpdom_data, TRIM(Wave(ntide(itide))%cname_tide)//'_v1', ztr(:,:) )
  186. CALL iom_get ( inum, jpdom_data, TRIM(Wave(ntide(itide))%cname_tide)//'_v2', zti(:,:) )
  187. DO ib = 1, ilen0(igrd)
  188. ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
  189. ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
  190. td%v0(ib,itide,1) = ztr(ii,ij)
  191. td%v0(ib,itide,2) = zti(ii,ij)
  192. END DO
  193. END DO
  194. CALL iom_close( inum )
  195. !
  196. CALL wrk_dealloc( jpi, jpj, ztr, zti )
  197. !
  198. ELSE
  199. !
  200. ! Read tidal data only on bdy segments
  201. !
  202. ALLOCATE( dta_read( MAXVAL(ilen0(1:3)), 1, 1 ) )
  203. !
  204. ! Set map structure
  205. ibmap_ptr(1)%ptr => idx_bdy(ib_bdy)%nbmap(:,1)
  206. ibmap_ptr(1)%ll_unstruc = ln_coords_file(ib_bdy)
  207. ibmap_ptr(2)%ptr => idx_bdy(ib_bdy)%nbmap(:,2)
  208. ibmap_ptr(2)%ll_unstruc = ln_coords_file(ib_bdy)
  209. ibmap_ptr(3)%ptr => idx_bdy(ib_bdy)%nbmap(:,3)
  210. ibmap_ptr(3)%ll_unstruc = ln_coords_file(ib_bdy)
  211. ! Open files and read in tidal forcing data
  212. ! -----------------------------------------
  213. DO itide = 1, nb_harmo
  214. ! ! SSH fields
  215. clfile = TRIM(filtide)//TRIM(Wave(ntide(itide))%cname_tide)//'_grid_T.nc'
  216. CALL iom_open( clfile, inum )
  217. CALL fld_map( inum, 'z1' , dta_read(1:ilen0(1),1:1,1:1) , 1, ibmap_ptr(1) )
  218. td%ssh0(:,itide,1) = dta_read(1:ilen0(1),1,1)
  219. CALL fld_map( inum, 'z2' , dta_read(1:ilen0(1),1:1,1:1) , 1, ibmap_ptr(1) )
  220. td%ssh0(:,itide,2) = dta_read(1:ilen0(1),1,1)
  221. CALL iom_close( inum )
  222. ! ! U fields
  223. clfile = TRIM(filtide)//TRIM(Wave(ntide(itide))%cname_tide)//'_grid_U.nc'
  224. CALL iom_open( clfile, inum )
  225. CALL fld_map( inum, 'u1' , dta_read(1:ilen0(2),1:1,1:1) , 1, ibmap_ptr(2) )
  226. td%u0(:,itide,1) = dta_read(1:ilen0(2),1,1)
  227. CALL fld_map( inum, 'u2' , dta_read(1:ilen0(2),1:1,1:1) , 1, ibmap_ptr(2) )
  228. td%u0(:,itide,2) = dta_read(1:ilen0(2),1,1)
  229. CALL iom_close( inum )
  230. ! ! V fields
  231. clfile = TRIM(filtide)//TRIM(Wave(ntide(itide))%cname_tide)//'_grid_V.nc'
  232. CALL iom_open( clfile, inum )
  233. CALL fld_map( inum, 'v1' , dta_read(1:ilen0(3),1:1,1:1) , 1, ibmap_ptr(3) )
  234. td%v0(:,itide,1) = dta_read(1:ilen0(3),1,1)
  235. CALL fld_map( inum, 'v2' , dta_read(1:ilen0(3),1:1,1:1) , 1, ibmap_ptr(3) )
  236. td%v0(:,itide,2) = dta_read(1:ilen0(3),1,1)
  237. CALL iom_close( inum )
  238. !
  239. END DO ! end loop on tidal components
  240. !
  241. DEALLOCATE( dta_read )
  242. ENDIF ! ln_bdytide_2ddta=.true.
  243. !
  244. IF ( ln_bdytide_conj ) THEN ! assume complex conjugate in data files
  245. td%ssh0(:,:,2) = - td%ssh0(:,:,2)
  246. td%u0 (:,:,2) = - td%u0 (:,:,2)
  247. td%v0 (:,:,2) = - td%v0 (:,:,2)
  248. ENDIF
  249. !
  250. IF ( lk_dynspg_ts ) THEN ! Allocate arrays to save slowly varying boundary data during
  251. ! time splitting integration
  252. ALLOCATE( dta_bdy_s(ib_bdy)%ssh ( ilen0(1) ) )
  253. ALLOCATE( dta_bdy_s(ib_bdy)%u2d ( ilen0(2) ) )
  254. ALLOCATE( dta_bdy_s(ib_bdy)%v2d ( ilen0(3) ) )
  255. dta_bdy_s(ib_bdy)%ssh(:) = 0.e0
  256. dta_bdy_s(ib_bdy)%u2d(:) = 0.e0
  257. dta_bdy_s(ib_bdy)%v2d(:) = 0.e0
  258. ENDIF
  259. !
  260. ENDIF ! nn_dyn2d_dta(ib_bdy) .ge. 2
  261. !
  262. END DO ! loop on ib_bdy
  263. IF( nn_timing == 1 ) CALL timing_stop('bdytide_init')
  264. END SUBROUTINE bdytide_init
  265. SUBROUTINE bdytide_update ( kt, idx, dta, td, jit, time_offset )
  266. !!----------------------------------------------------------------------
  267. !! *** SUBROUTINE bdytide_update ***
  268. !!
  269. !! ** Purpose : - Add tidal forcing to ssh, u2d and v2d OBC data arrays.
  270. !!
  271. !!----------------------------------------------------------------------
  272. INTEGER, INTENT( in ) :: kt ! Main timestep counter
  273. TYPE(OBC_INDEX), INTENT( in ) :: idx ! OBC indices
  274. TYPE(OBC_DATA), INTENT(inout) :: dta ! OBC external data
  275. TYPE(TIDES_DATA),INTENT( inout ) :: td ! tidal harmonics data
  276. INTEGER,INTENT(in),OPTIONAL :: jit ! Barotropic timestep counter (for timesplitting option)
  277. INTEGER,INTENT( in ), OPTIONAL :: time_offset ! time offset in units of timesteps. NB. if jit
  278. ! is present then units = subcycle timesteps.
  279. ! time_offset = 0 => get data at "now" time level
  280. ! time_offset = -1 => get data at "before" time level
  281. ! time_offset = +1 => get data at "after" time level
  282. ! etc.
  283. !!
  284. INTEGER, DIMENSION(3) :: ilen0 !: length of boundary data (from OBC arrays)
  285. INTEGER :: itide, igrd, ib ! dummy loop indices
  286. INTEGER :: time_add ! time offset in units of timesteps
  287. REAL(wp) :: z_arg, z_sarg, zflag, zramp
  288. REAL(wp), DIMENSION(jpmax_harmo) :: z_sist, z_cost
  289. !!----------------------------------------------------------------------
  290. IF( nn_timing == 1 ) CALL timing_start('bdytide_update')
  291. ilen0(1) = SIZE(td%ssh(:,1,1))
  292. ilen0(2) = SIZE(td%u(:,1,1))
  293. ilen0(3) = SIZE(td%v(:,1,1))
  294. zflag=1
  295. IF ( PRESENT(jit) ) THEN
  296. IF ( jit /= 1 ) zflag=0
  297. ENDIF
  298. IF ( nsec_day == NINT(0.5_wp * rdttra(1)) .AND. zflag==1 ) THEN
  299. !
  300. kt_tide = kt
  301. !
  302. IF(lwp) THEN
  303. WRITE(numout,*)
  304. WRITE(numout,*) 'bdytide_update : (re)Initialization of the tidal bdy forcing at kt=',kt
  305. WRITE(numout,*) '~~~~~~~~~~~~~~ '
  306. ENDIF
  307. !
  308. CALL tide_init_elevation ( idx, td )
  309. CALL tide_init_velocities( idx, td )
  310. !
  311. ENDIF
  312. time_add = 0
  313. IF( PRESENT(time_offset) ) THEN
  314. time_add = time_offset
  315. ENDIF
  316. IF( PRESENT(jit) ) THEN
  317. z_arg = ((kt-kt_tide) * rdt + (jit+0.5_wp*(time_add-1)) * rdt / REAL(nn_baro,wp) )
  318. ELSE
  319. z_arg = ((kt-kt_tide)+time_add) * rdt
  320. ENDIF
  321. ! Linear ramp on tidal component at open boundaries
  322. zramp = 1._wp
  323. IF (ln_tide_ramp) zramp = MIN(MAX( (z_arg + (kt_tide-nit000)*rdt)/(rdttideramp*rday),0._wp),1._wp)
  324. DO itide = 1, nb_harmo
  325. z_sarg = z_arg * omega_tide(itide)
  326. z_cost(itide) = COS( z_sarg )
  327. z_sist(itide) = SIN( z_sarg )
  328. END DO
  329. DO itide = 1, nb_harmo
  330. igrd=1 ! SSH on tracer grid
  331. DO ib = 1, ilen0(igrd)
  332. dta%ssh(ib) = dta%ssh(ib) + zramp*(td%ssh(ib,itide,1)*z_cost(itide) + td%ssh(ib,itide,2)*z_sist(itide))
  333. END DO
  334. igrd=2 ! U grid
  335. DO ib = 1, ilen0(igrd)
  336. dta%u2d(ib) = dta%u2d(ib) + zramp*(td%u (ib,itide,1)*z_cost(itide) + td%u (ib,itide,2)*z_sist(itide))
  337. END DO
  338. igrd=3 ! V grid
  339. DO ib = 1, ilen0(igrd)
  340. dta%v2d(ib) = dta%v2d(ib) + zramp*(td%v (ib,itide,1)*z_cost(itide) + td%v (ib,itide,2)*z_sist(itide))
  341. END DO
  342. END DO
  343. !
  344. IF( nn_timing == 1 ) CALL timing_stop('bdytide_update')
  345. !
  346. END SUBROUTINE bdytide_update
  347. SUBROUTINE bdy_dta_tides( kt, kit, time_offset )
  348. !!----------------------------------------------------------------------
  349. !! *** SUBROUTINE bdy_dta_tides ***
  350. !!
  351. !! ** Purpose : - Add tidal forcing to ssh, u2d and v2d OBC data arrays.
  352. !!
  353. !!----------------------------------------------------------------------
  354. INTEGER, INTENT( in ) :: kt ! Main timestep counter
  355. INTEGER, INTENT( in ),OPTIONAL :: kit ! Barotropic timestep counter (for timesplitting option)
  356. INTEGER, INTENT( in ),OPTIONAL :: time_offset ! time offset in units of timesteps. NB. if kit
  357. ! is present then units = subcycle timesteps.
  358. ! time_offset = 0 => get data at "now" time level
  359. ! time_offset = -1 => get data at "before" time level
  360. ! time_offset = +1 => get data at "after" time level
  361. ! etc.
  362. !!
  363. LOGICAL :: lk_first_btstp ! =.TRUE. if time splitting and first barotropic step
  364. INTEGER, DIMENSION(jpbgrd) :: ilen0
  365. INTEGER, DIMENSION(1:jpbgrd) :: nblen, nblenrim ! short cuts
  366. INTEGER :: itide, ib_bdy, ib, igrd ! loop indices
  367. INTEGER :: time_add ! time offset in units of timesteps
  368. REAL(wp) :: z_arg, z_sarg, zramp, zoff, z_cost, z_sist
  369. !!----------------------------------------------------------------------
  370. IF( nn_timing == 1 ) CALL timing_start('bdy_dta_tides')
  371. lk_first_btstp=.TRUE.
  372. IF ( PRESENT(kit).AND.( kit /= 1 ) ) THEN ; lk_first_btstp=.FALSE. ; ENDIF
  373. time_add = 0
  374. IF( PRESENT(time_offset) ) THEN
  375. time_add = time_offset
  376. ENDIF
  377. ! Absolute time from model initialization:
  378. IF( PRESENT(kit) ) THEN
  379. z_arg = ( kt + (kit+time_add-1) / REAL(nn_baro,wp) ) * rdt
  380. ELSE
  381. z_arg = ( kt + time_add ) * rdt
  382. ENDIF
  383. ! Linear ramp on tidal component at open boundaries
  384. zramp = 1.
  385. IF (ln_tide_ramp) zramp = MIN(MAX( (z_arg - nit000*rdt)/(rdttideramp*rday),0.),1.)
  386. DO ib_bdy = 1,nb_bdy
  387. IF ( nn_dyn2d_dta(ib_bdy) .ge. 2 ) THEN
  388. nblen(1:jpbgrd) = idx_bdy(ib_bdy)%nblen(1:jpbgrd)
  389. nblenrim(1:jpbgrd) = idx_bdy(ib_bdy)%nblenrim(1:jpbgrd)
  390. IF( cn_dyn2d(ib_bdy) == 'frs' ) THEN
  391. ilen0(:)=nblen(:)
  392. ELSE
  393. ilen0(:)=nblenrim(:)
  394. ENDIF
  395. ! We refresh nodal factors every day below
  396. ! This should be done somewhere else
  397. IF ( nsec_day == NINT(0.5_wp * rdttra(1)) .AND. lk_first_btstp ) THEN
  398. !
  399. kt_tide = kt
  400. !
  401. IF(lwp) THEN
  402. WRITE(numout,*)
  403. WRITE(numout,*) 'bdy_tide_dta : Refresh nodal factors for tidal open bdy data at kt=',kt
  404. WRITE(numout,*) '~~~~~~~~~~~~~~ '
  405. ENDIF
  406. !
  407. CALL tide_init_elevation ( idx=idx_bdy(ib_bdy), td=tides(ib_bdy) )
  408. CALL tide_init_velocities( idx=idx_bdy(ib_bdy), td=tides(ib_bdy) )
  409. !
  410. ENDIF
  411. zoff = -kt_tide * rdt ! time offset relative to nodal factor computation time
  412. !
  413. ! If time splitting, save data at first barotropic iteration
  414. IF ( PRESENT(kit) ) THEN
  415. IF ( lk_first_btstp ) THEN ! Save slow varying open boundary data:
  416. IF ( dta_bdy(ib_bdy)%ll_ssh ) dta_bdy_s(ib_bdy)%ssh(1:ilen0(1)) = dta_bdy(ib_bdy)%ssh(1:ilen0(1))
  417. IF ( dta_bdy(ib_bdy)%ll_u2d ) dta_bdy_s(ib_bdy)%u2d(1:ilen0(2)) = dta_bdy(ib_bdy)%u2d(1:ilen0(2))
  418. IF ( dta_bdy(ib_bdy)%ll_v2d ) dta_bdy_s(ib_bdy)%v2d(1:ilen0(3)) = dta_bdy(ib_bdy)%v2d(1:ilen0(3))
  419. ELSE ! Initialize arrays from slow varying open boundary data:
  420. IF ( dta_bdy(ib_bdy)%ll_ssh ) dta_bdy(ib_bdy)%ssh(1:ilen0(1)) = dta_bdy_s(ib_bdy)%ssh(1:ilen0(1))
  421. IF ( dta_bdy(ib_bdy)%ll_u2d ) dta_bdy(ib_bdy)%u2d(1:ilen0(2)) = dta_bdy_s(ib_bdy)%u2d(1:ilen0(2))
  422. IF ( dta_bdy(ib_bdy)%ll_v2d ) dta_bdy(ib_bdy)%v2d(1:ilen0(3)) = dta_bdy_s(ib_bdy)%v2d(1:ilen0(3))
  423. ENDIF
  424. ENDIF
  425. !
  426. ! Update open boundary data arrays:
  427. DO itide = 1, nb_harmo
  428. !
  429. z_sarg = (z_arg + zoff) * omega_tide(itide)
  430. z_cost = zramp * COS( z_sarg )
  431. z_sist = zramp * SIN( z_sarg )
  432. !
  433. IF ( dta_bdy(ib_bdy)%ll_ssh ) THEN
  434. igrd=1 ! SSH on tracer grid
  435. DO ib = 1, ilen0(igrd)
  436. dta_bdy(ib_bdy)%ssh(ib) = dta_bdy(ib_bdy)%ssh(ib) + &
  437. & ( tides(ib_bdy)%ssh(ib,itide,1)*z_cost + &
  438. & tides(ib_bdy)%ssh(ib,itide,2)*z_sist )
  439. END DO
  440. ENDIF
  441. !
  442. IF ( dta_bdy(ib_bdy)%ll_u2d ) THEN
  443. igrd=2 ! U grid
  444. DO ib = 1, ilen0(igrd)
  445. dta_bdy(ib_bdy)%u2d(ib) = dta_bdy(ib_bdy)%u2d(ib) + &
  446. & ( tides(ib_bdy)%u(ib,itide,1)*z_cost + &
  447. & tides(ib_bdy)%u(ib,itide,2)*z_sist )
  448. END DO
  449. ENDIF
  450. !
  451. IF ( dta_bdy(ib_bdy)%ll_v2d ) THEN
  452. igrd=3 ! V grid
  453. DO ib = 1, ilen0(igrd)
  454. dta_bdy(ib_bdy)%v2d(ib) = dta_bdy(ib_bdy)%v2d(ib) + &
  455. & ( tides(ib_bdy)%v(ib,itide,1)*z_cost + &
  456. & tides(ib_bdy)%v(ib,itide,2)*z_sist )
  457. END DO
  458. ENDIF
  459. END DO
  460. END IF
  461. END DO
  462. !
  463. IF( nn_timing == 1 ) CALL timing_stop('bdy_dta_tides')
  464. !
  465. END SUBROUTINE bdy_dta_tides
  466. SUBROUTINE tide_init_elevation( idx, td )
  467. !!----------------------------------------------------------------------
  468. !! *** ROUTINE tide_init_elevation ***
  469. !!----------------------------------------------------------------------
  470. TYPE(OBC_INDEX), INTENT( in ) :: idx ! OBC indices
  471. TYPE(TIDES_DATA),INTENT( inout ) :: td ! tidal harmonics data
  472. !! * Local declarations
  473. INTEGER, DIMENSION(1) :: ilen0 !: length of boundary data (from OBC arrays)
  474. REAL(wp),ALLOCATABLE, DIMENSION(:) :: mod_tide, phi_tide
  475. INTEGER :: itide, igrd, ib ! dummy loop indices
  476. igrd=1
  477. ! SSH on tracer grid.
  478. ilen0(1) = SIZE(td%ssh0(:,1,1))
  479. ALLOCATE(mod_tide(ilen0(igrd)),phi_tide(ilen0(igrd)))
  480. DO itide = 1, nb_harmo
  481. DO ib = 1, ilen0(igrd)
  482. mod_tide(ib)=SQRT(td%ssh0(ib,itide,1)**2.+td%ssh0(ib,itide,2)**2.)
  483. phi_tide(ib)=ATAN2(-td%ssh0(ib,itide,2),td%ssh0(ib,itide,1))
  484. END DO
  485. DO ib = 1 , ilen0(igrd)
  486. mod_tide(ib)=mod_tide(ib)*ftide(itide)
  487. phi_tide(ib)=phi_tide(ib)+v0tide(itide)+utide(itide)
  488. ENDDO
  489. DO ib = 1 , ilen0(igrd)
  490. td%ssh(ib,itide,1)= mod_tide(ib)*COS(phi_tide(ib))
  491. td%ssh(ib,itide,2)=-mod_tide(ib)*SIN(phi_tide(ib))
  492. ENDDO
  493. END DO
  494. DEALLOCATE(mod_tide,phi_tide)
  495. END SUBROUTINE tide_init_elevation
  496. SUBROUTINE tide_init_velocities( idx, td )
  497. !!----------------------------------------------------------------------
  498. !! *** ROUTINE tide_init_elevation ***
  499. !!----------------------------------------------------------------------
  500. TYPE(OBC_INDEX), INTENT( in ) :: idx ! OBC indices
  501. TYPE(TIDES_DATA),INTENT( inout ) :: td ! tidal harmonics data
  502. !! * Local declarations
  503. INTEGER, DIMENSION(3) :: ilen0 !: length of boundary data (from OBC arrays)
  504. REAL(wp),ALLOCATABLE, DIMENSION(:) :: mod_tide, phi_tide
  505. INTEGER :: itide, igrd, ib ! dummy loop indices
  506. ilen0(2) = SIZE(td%u0(:,1,1))
  507. ilen0(3) = SIZE(td%v0(:,1,1))
  508. igrd=2 ! U grid.
  509. ALLOCATE(mod_tide(ilen0(igrd)),phi_tide(ilen0(igrd)))
  510. DO itide = 1, nb_harmo
  511. DO ib = 1, ilen0(igrd)
  512. mod_tide(ib)=SQRT(td%u0(ib,itide,1)**2.+td%u0(ib,itide,2)**2.)
  513. phi_tide(ib)=ATAN2(-td%u0(ib,itide,2),td%u0(ib,itide,1))
  514. END DO
  515. DO ib = 1, ilen0(igrd)
  516. mod_tide(ib)=mod_tide(ib)*ftide(itide)
  517. phi_tide(ib)=phi_tide(ib)+v0tide(itide)+utide(itide)
  518. ENDDO
  519. DO ib = 1, ilen0(igrd)
  520. td%u(ib,itide,1)= mod_tide(ib)*COS(phi_tide(ib))
  521. td%u(ib,itide,2)=-mod_tide(ib)*SIN(phi_tide(ib))
  522. ENDDO
  523. END DO
  524. DEALLOCATE(mod_tide,phi_tide)
  525. igrd=3 ! V grid.
  526. ALLOCATE(mod_tide(ilen0(igrd)),phi_tide(ilen0(igrd)))
  527. DO itide = 1, nb_harmo
  528. DO ib = 1, ilen0(igrd)
  529. mod_tide(ib)=SQRT(td%v0(ib,itide,1)**2.+td%v0(ib,itide,2)**2.)
  530. phi_tide(ib)=ATAN2(-td%v0(ib,itide,2),td%v0(ib,itide,1))
  531. END DO
  532. DO ib = 1, ilen0(igrd)
  533. mod_tide(ib)=mod_tide(ib)*ftide(itide)
  534. phi_tide(ib)=phi_tide(ib)+v0tide(itide)+utide(itide)
  535. ENDDO
  536. DO ib = 1, ilen0(igrd)
  537. td%v(ib,itide,1)= mod_tide(ib)*COS(phi_tide(ib))
  538. td%v(ib,itide,2)=-mod_tide(ib)*SIN(phi_tide(ib))
  539. ENDDO
  540. END DO
  541. DEALLOCATE(mod_tide,phi_tide)
  542. END SUBROUTINE tide_init_velocities
  543. #else
  544. !!----------------------------------------------------------------------
  545. !! Dummy module NO Unstruct Open Boundary Conditions for tides
  546. !!----------------------------------------------------------------------
  547. CONTAINS
  548. SUBROUTINE bdytide_init ! Empty routine
  549. WRITE(*,*) 'bdytide_init: You should not have seen this print! error?'
  550. END SUBROUTINE bdytide_init
  551. SUBROUTINE bdytide_update( kt, jit ) ! Empty routine
  552. WRITE(*,*) 'bdytide_update: You should not have seen this print! error?', kt, jit
  553. END SUBROUTINE bdytide_update
  554. SUBROUTINE bdy_dta_tides( kt, kit, time_offset ) ! Empty routine
  555. INTEGER, INTENT( in ) :: kt ! Dummy argument empty routine
  556. INTEGER, INTENT( in ),OPTIONAL :: kit ! Dummy argument empty routine
  557. INTEGER, INTENT( in ),OPTIONAL :: time_offset ! Dummy argument empty routine
  558. WRITE(*,*) 'bdy_dta_tides: You should not have seen this print! error?', kt, jit
  559. END SUBROUTINE bdy_dta_tides
  560. #endif
  561. !!======================================================================
  562. END MODULE bdytides