crs.F90 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. MODULE crs
  2. !!======================================================================
  3. !! *** MODULE crs_dom ***
  4. !! Declare the coarse grid domain and other public variables
  5. !! then allocate them if needed.
  6. !!======================================================================
  7. !! History 2012-06 Editing (J. Simeon, G. Madec, C. Ethe, C. Calone) Original code
  8. !!----------------------------------------------------------------------
  9. USE par_oce
  10. USE dom_oce
  11. USE in_out_manager
  12. IMPLICIT NONE
  13. PUBLIC
  14. PUBLIC crs_dom_alloc ! Called from crsini.F90
  15. PUBLIC crs_dom_alloc2 ! Called from crsini.F90
  16. PUBLIC dom_grid_glo
  17. PUBLIC dom_grid_crs
  18. ! Domain variables
  19. INTEGER :: jpiglo_crs , & !: 1st dimension of global coarse grid domain
  20. jpjglo_crs !: 2nd dimension of global coarse grid domain
  21. INTEGER :: jpi_crs , & !: 1st dimension of local coarse grid domain
  22. jpj_crs !: 2nd dimension of local coarse grid domain
  23. INTEGER :: jpi_full , & !: 1st dimension of local parent grid domain
  24. jpj_full !: 2nd dimension of local parent grid domain
  25. INTEGER :: nistr , njstr
  26. INTEGER :: niend , njend
  27. INTEGER :: jpi_crsm1, jpj_crsm1 !: loop indices
  28. INTEGER :: jpiglo_crsm1, jpjglo_crsm1 !: loop indices
  29. INTEGER :: nperio_full, nperio_crs !: jperio of parent and coarse grids
  30. INTEGER :: npolj_full, npolj_crs !: north fold mark
  31. INTEGER :: jpiglo_full, jpjglo_full !: jpiglo / jpjglo
  32. INTEGER :: npiglo, npjglo !: jpjglo
  33. INTEGER :: nlci_full, nlcj_full !: i-, j-dimension of local or sub domain on parent grid
  34. INTEGER :: nldi_full, nldj_full !: starting indices of internal sub-domain on parent grid
  35. INTEGER :: nlei_full, nlej_full !: ending indices of internal sub-domain on parent grid
  36. INTEGER :: nlci_crs, nlcj_crs !: i-, j-dimension of local or sub domain on coarse grid
  37. INTEGER :: nldi_crs, nldj_crs !: starting indices of internal sub-domain on coarse grid
  38. INTEGER :: nlei_crs, nlej_crs !: ending indices of internal sub-domain on coarse grid
  39. INTEGER :: narea_full, narea_crs !: node
  40. INTEGER :: jpnij_full, jpnij_crs !: =jpni*jpnj, the pe decomposition
  41. INTEGER :: jpim1_full, jpjm1_full !:
  42. INTEGER :: nimpp_full, njmpp_full !: global position of point (1,1) of subdomain on parent grid
  43. INTEGER :: nimpp_crs, njmpp_crs !: set to 1,1 for now . Valid only for monoproc
  44. INTEGER :: nreci_full, nrecj_full
  45. INTEGER :: nreci_crs, nrecj_crs
  46. !cc
  47. INTEGER :: noea_full, nowe_full !: index of the local neighboring processors in
  48. INTEGER :: noso_full, nono_full !: east, west, south and north directions
  49. INTEGER :: npne_full, npnw_full !: index of north east and north west processor
  50. INTEGER :: npse_full, npsw_full !: index of south east and south west processor
  51. INTEGER :: nbne_full, nbnw_full !: logical of north east & north west processor
  52. INTEGER :: nbse_full, nbsw_full !: logical of south east & south west processor
  53. INTEGER :: nidom_full !: ???
  54. INTEGER :: nproc_full !:number for local processor
  55. INTEGER :: nbondi_full, nbondj_full !: mark of i- and j-direction local boundaries
  56. INTEGER :: noea_crs, nowe_crs !: index of the local neighboring processors in
  57. INTEGER :: noso_crs, nono_crs !: east, west, south and north directions
  58. INTEGER :: npne_crs, npnw_crs !: index of north east and north west processor
  59. INTEGER :: npse_crs, npsw_crs !: index of south east and south west processor
  60. INTEGER :: nbne_crs, nbnw_crs !: logical of north east & north west processor
  61. INTEGER :: nbse_crs, nbsw_crs !: logical of south east & south west processor
  62. INTEGER :: nidom_crs !: ???
  63. INTEGER :: nproc_crs !:number for local processor
  64. INTEGER :: nbondi_crs, nbondj_crs !: mark of i- and j-direction local boundaries
  65. INTEGER, DIMENSION(:), ALLOCATABLE :: mis_crs, mie_crs, mis2_crs, mie2_crs ! starting and ending i-indices of parent subset
  66. INTEGER, DIMENSION(:), ALLOCATABLE :: mjs_crs, mje_crs, mjs2_crs, mje2_crs ! starting and ending j-indices of parent subset
  67. INTEGER, DIMENSION(:), ALLOCATABLE :: mjg_crs, mig_crs
  68. INTEGER, DIMENSION(:), ALLOCATABLE :: mi0_crs, mi1_crs, mj0_crs, mj1_crs
  69. INTEGER :: mxbinctr, mybinctr ! central point in grid box
  70. INTEGER, DIMENSION(:), ALLOCATABLE :: nlcit_crs, nlcit_full !: dimensions of every subdomain
  71. INTEGER, DIMENSION(:), ALLOCATABLE :: nldit_crs, nldit_full !: first, last indoor index for each i-domain
  72. INTEGER, DIMENSION(:), ALLOCATABLE :: nleit_crs, nleit_full !: first, last indoor index for each j-domain
  73. INTEGER, DIMENSION(:), ALLOCATABLE :: nimppt_crs, nimppt_full !: first, last indoor index for each j-domain
  74. INTEGER, DIMENSION(:), ALLOCATABLE :: nlcjt_crs, nlcjt_full !: dimensions of every subdomain
  75. INTEGER, DIMENSION(:), ALLOCATABLE :: nldjt_crs, nldjt_full !: first, last indoor index for each i-domain
  76. INTEGER, DIMENSION(:), ALLOCATABLE :: nlejt_crs, nlejt_full !: first, last indoor index for each j-domain
  77. INTEGER, DIMENSION(:), ALLOCATABLE :: njmppt_crs, njmppt_full !: first, last indoor index for each j-domain
  78. ! Masks
  79. REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: tmask_crs, umask_crs, vmask_crs, fmask_crs
  80. REAL(wp), DIMENSION(:,:) , ALLOCATABLE :: tmask_i_crs, rnfmsk_crs, tpol_crs, fpol_crs
  81. ! REAL(wp), DIMENSION(:,:), ALLOCATABLE :: tmask_i_crs, tpol, fpol
  82. ! Scale factors
  83. REAL(wp), DIMENSION(:,:), ALLOCATABLE :: e1t_crs, e2t_crs, e1e2t_crs ! horizontal scale factors grid type T
  84. REAL(wp), DIMENSION(:,:), ALLOCATABLE :: e1u_crs, e2u_crs ! horizontal scale factors grid type U
  85. REAL(wp), DIMENSION(:,:), ALLOCATABLE :: e1v_crs, e2v_crs ! horizontal scale factors grid type V
  86. REAL(wp), DIMENSION(:,:), ALLOCATABLE :: e1f_crs, e2f_crs ! horizontal scale factors grid type F
  87. REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: e3t_crs, e3u_crs, e3v_crs, e3f_crs, e3w_crs
  88. REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: e3t_max_crs, e3u_max_crs, e3v_max_crs, e3f_max_crs, e3w_max_crs
  89. ! Surface
  90. REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: e1e2w_crs, e2e3u_crs, e1e3v_crs
  91. REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: e1e2w_msk, e2e3u_msk, e1e3v_msk
  92. ! vertical scale factors
  93. ! Coordinates
  94. REAL(wp), DIMENSION(:,:), ALLOCATABLE :: gphit_crs, glamt_crs, gphif_crs, glamf_crs
  95. REAL(wp), DIMENSION(:,:), ALLOCATABLE :: gphiu_crs, glamu_crs, gphiv_crs, glamv_crs
  96. REAL(wp), DIMENSION(:,:), ALLOCATABLE :: ff_crs
  97. INTEGER, DIMENSION(:,:), ALLOCATABLE :: mbathy_crs, mbkt_crs, mbku_crs, mbkv_crs
  98. REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: gdept_crs, gdepu_crs, gdepv_crs, gdepw_crs
  99. ! Weights
  100. REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: facsurfv, facsurfu, facvol_t, facvol_w
  101. REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: ocean_volume_crs_t, ocean_volume_crs_w, bt_crs, r1_bt_crs
  102. REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: crs_surfu_wgt, crs_surfv_wgt, crs_surfw_wgt, crs_volt_wgt
  103. ! CRS Namelist
  104. INTEGER :: nn_factx = 3 !: reduction factor of x-dimension of the parent grid
  105. INTEGER :: nn_facty = 3 !: reduction factor of y-dimension of the parent grid
  106. INTEGER :: nn_binref = 0 !: 0 = binning starts north fold (equator could be asymmetric)
  107. !: 1 = binning centers at equator (north fold my have artifacts)
  108. !: for even reduction factors, equator placed in bin biased south
  109. INTEGER :: nn_msh_crs = 1 !: Organization of mesh mask output
  110. !: 0 = no mesh mask output
  111. !: 1 = unified mesh mask output
  112. !: 2 = 2 separate mesh mask output
  113. !: 3 = 3 separate mesh mask output
  114. INTEGER :: nn_crs_kz = 0 !: type of Kz coarsening ( =0->VOL ; =1->MAX ; =2->MIN)
  115. LOGICAL :: ln_crs_wn = .FALSE. !: coarsening wn or computation using horizontal divergence
  116. !
  117. INTEGER :: nrestx, nresty !: for determining odd or even reduction factor
  118. ! Grid reduction factors
  119. REAL(wp) :: rfactx_r !: inverse of x-dim reduction factor
  120. REAL(wp) :: rfacty_r !: inverse of y-dim reduction factor
  121. REAL(wp) :: rfactxy
  122. ! Physical and dynamical ocean fields for output or passing to TOP, time-mean fields
  123. REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE :: tsn_crs
  124. REAL(wp), DIMENSION(:,:,:) , ALLOCATABLE :: un_crs, vn_crs, wn_crs, rke_crs
  125. REAL(wp), DIMENSION(:,:,:) , ALLOCATABLE :: hdivn_crs
  126. REAL(wp), DIMENSION(:,:) , ALLOCATABLE :: sshn_crs
  127. !
  128. ! Surface fluxes to pass to TOP
  129. REAL(wp), PUBLIC, DIMENSION(:,:) , ALLOCATABLE :: qsr_crs, fr_i_crs, wndm_crs
  130. REAL(wp), PUBLIC, DIMENSION(:,:) , ALLOCATABLE :: emp_crs, emp_b_crs, sfx_crs
  131. REAL(wp), PUBLIC, DIMENSION(:,:) , ALLOCATABLE :: utau_crs, vtau_crs
  132. REAL(wp), PUBLIC, DIMENSION(:,:) , ALLOCATABLE :: rnf_crs
  133. ! Vertical diffusion
  134. REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:,:) :: avt_crs !: vert. diffusivity coef. [m2/s] at w-point for temp
  135. # if defined key_zdfddm
  136. REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:,:) :: avs_crs !: salinity vertical diffusivity coeff. [m2/s] at w-point
  137. # endif
  138. ! Mixing and Mixed Layer Depth
  139. INTEGER, PUBLIC, ALLOCATABLE, DIMENSION(:,:) :: nmln_crs, hmld_crs, hmlp_crs, hmlpt_crs
  140. ! Direction of lateral diffusion
  141. !! $Id: crs.F90 2355 2015-05-20 07:11:50Z ufla $
  142. CONTAINS
  143. INTEGER FUNCTION crs_dom_alloc()
  144. !!-------------------------------------------------------------------
  145. !! *** FUNCTION crs_dom_alloc ***
  146. !! ** Purpose : Allocate public crs arrays
  147. !!-------------------------------------------------------------------
  148. !! Local variables
  149. INTEGER, DIMENSION(17) :: ierr
  150. ierr(:) = 0
  151. ! Set up bins for coarse grid, horizontal only.
  152. ALLOCATE( mis2_crs(jpiglo_crs), mie2_crs(jpiglo_crs), &
  153. & mjs2_crs(jpjglo_crs), mje2_crs(jpjglo_crs), &
  154. & mi0_crs (jpiglo_crs), mi1_crs (jpiglo_crs), &
  155. & mj0_crs (jpjglo_crs), mj1_crs (jpjglo_crs), &
  156. & mig_crs (jpi_crs) , mjg_crs (jpj_crs) , STAT=ierr(1) )
  157. ! Set up Mask and Mesh
  158. ALLOCATE( tmask_crs(jpi_crs,jpj_crs,jpk) , fmask_crs(jpi_crs,jpj_crs,jpk) , &
  159. & umask_crs(jpi_crs,jpj_crs,jpk) , vmask_crs(jpi_crs,jpj_crs,jpk) , STAT=ierr(2))
  160. ALLOCATE( tmask_i_crs(jpi_crs,jpj_crs) , rnfmsk_crs(jpi_crs,jpj_crs), &
  161. & tpol_crs(jpiglo_crs,jpjglo_crs), fpol_crs(jpiglo_crs,jpjglo_crs), STAT=ierr(3) )
  162. ALLOCATE( gphit_crs(jpi_crs,jpj_crs) , glamt_crs(jpi_crs,jpj_crs) , &
  163. & gphiu_crs(jpi_crs,jpj_crs) , glamu_crs(jpi_crs,jpj_crs) , &
  164. & gphiv_crs(jpi_crs,jpj_crs) , glamv_crs(jpi_crs,jpj_crs) , &
  165. & gphif_crs(jpi_crs,jpj_crs) , glamf_crs(jpi_crs,jpj_crs) , &
  166. & ff_crs(jpi_crs,jpj_crs) , STAT=ierr(4))
  167. ALLOCATE( e1t_crs(jpi_crs,jpj_crs) , e2t_crs(jpi_crs,jpj_crs) , &
  168. & e1u_crs(jpi_crs,jpj_crs) , e2u_crs(jpi_crs,jpj_crs) , &
  169. & e1v_crs(jpi_crs,jpj_crs) , e2v_crs(jpi_crs,jpj_crs) , &
  170. & e1f_crs(jpi_crs,jpj_crs) , e2f_crs(jpi_crs,jpj_crs) , &
  171. & e1e2t_crs(jpi_crs,jpj_crs), STAT=ierr(5))
  172. ALLOCATE( e3t_crs(jpi_crs,jpj_crs,jpk) , e3w_crs(jpi_crs,jpj_crs,jpk) , &
  173. & e3u_crs(jpi_crs,jpj_crs,jpk) , e3v_crs(jpi_crs,jpj_crs,jpk) , &
  174. & e3f_crs(jpi_crs,jpj_crs,jpk) , e1e2w_msk(jpi_crs,jpj_crs,jpk) , &
  175. & e2e3u_msk(jpi_crs,jpj_crs,jpk) , e1e3v_msk(jpi_crs,jpj_crs,jpk) , &
  176. & e1e2w_crs(jpi_crs,jpj_crs,jpk) , e2e3u_crs(jpi_crs,jpj_crs,jpk) , &
  177. & e1e3v_crs(jpi_crs,jpj_crs,jpk) , e3t_max_crs(jpi_crs,jpj_crs,jpk), &
  178. & e3w_max_crs(jpi_crs,jpj_crs,jpk), e3u_max_crs(jpi_crs,jpj_crs,jpk), &
  179. & e3v_max_crs(jpi_crs,jpj_crs,jpk), STAT=ierr(6))
  180. ALLOCATE( facsurfv(jpi_crs,jpj_crs,jpk), facsurfu(jpi_crs,jpj_crs,jpk) , &
  181. & facvol_t(jpi_crs,jpj_crs,jpk), facvol_w(jpi_crs,jpj_crs,jpk) , &
  182. & ocean_volume_crs_t(jpi_crs,jpj_crs,jpk), ocean_volume_crs_w(jpi_crs,jpj_crs,jpk), &
  183. & bt_crs(jpi_crs,jpj_crs,jpk) , r1_bt_crs(jpi_crs,jpj_crs,jpk) , STAT=ierr(7))
  184. ALLOCATE( crs_surfu_wgt(jpi_crs,jpj_crs,jpk), crs_surfv_wgt(jpi_crs,jpj_crs,jpk) , &
  185. & crs_surfw_wgt(jpi_crs,jpj_crs,jpk), crs_volt_wgt(jpi_crs,jpj_crs,jpk) , STAT=ierr(8))
  186. ALLOCATE( mbathy_crs(jpi_crs,jpj_crs), mbkt_crs(jpi_crs,jpj_crs) , &
  187. & mbku_crs(jpi_crs,jpj_crs) , mbkv_crs(jpi_crs,jpj_crs) , STAT=ierr(9))
  188. ALLOCATE( gdept_crs(jpi_crs,jpj_crs,jpk), gdepu_crs(jpi_crs,jpj_crs,jpk) , &
  189. & gdepv_crs(jpi_crs,jpj_crs,jpk), gdepw_crs(jpi_crs,jpj_crs,jpk) , STAT=ierr(10) )
  190. ALLOCATE( un_crs(jpi_crs,jpj_crs,jpk) , vn_crs(jpi_crs,jpj_crs,jpk) , &
  191. & wn_crs(jpi_crs,jpj_crs,jpk) , hdivn_crs(jpi_crs,jpj_crs,jpk),&
  192. & rke_crs(jpi_crs,jpj_crs,jpk), STAT=ierr(11))
  193. ALLOCATE( sshn_crs(jpi_crs,jpj_crs), emp_crs (jpi_crs,jpj_crs), emp_b_crs(jpi_crs,jpj_crs), &
  194. & qsr_crs(jpi_crs ,jpj_crs), wndm_crs(jpi_crs,jpj_crs), utau_crs(jpi_crs,jpj_crs) , &
  195. & vtau_crs(jpi_crs,jpj_crs), rnf_crs(jpi_crs ,jpj_crs), &
  196. & fr_i_crs(jpi_crs,jpj_crs), sfx_crs(jpi_crs ,jpj_crs), STAT=ierr(12) )
  197. ALLOCATE( tsn_crs(jpi_crs,jpj_crs,jpk,jpts), avt_crs(jpi_crs,jpj_crs,jpk), &
  198. # if defined key_zdfddm
  199. & avs_crs(jpi_crs,jpj_crs,jpk), &
  200. # endif
  201. & STAT=ierr(13) )
  202. ALLOCATE( nmln_crs(jpi_crs,jpj_crs) , hmld_crs(jpi_crs,jpj_crs) , &
  203. & hmlp_crs(jpi_crs,jpj_crs) , hmlpt_crs(jpi_crs,jpj_crs) , STAT=ierr(14) )
  204. ALLOCATE( nimppt_crs(jpnij) , nlcit_crs(jpnij) , nldit_crs(jpnij) , nleit_crs(jpnij), &
  205. & nimppt_full(jpnij) , nlcit_full(jpnij) , nldit_full(jpnij) , nleit_full(jpnij), &
  206. njmppt_crs(jpnij) , nlcjt_crs(jpnij) , nldjt_crs(jpnij) , nlejt_crs(jpnij), &
  207. & njmppt_full(jpnij) , nlcjt_full(jpnij) , nldjt_full(jpnij) , nlejt_full(jpnij) , STAT=ierr(15) )
  208. crs_dom_alloc = MAXVAL(ierr)
  209. END FUNCTION crs_dom_alloc
  210. INTEGER FUNCTION crs_dom_alloc2()
  211. !!-------------------------------------------------------------------
  212. !! *** FUNCTION crs_dom_alloc ***
  213. !! ** Purpose : Allocate public crs arrays
  214. !!-------------------------------------------------------------------
  215. !! Local variables
  216. INTEGER, DIMENSION(1) :: ierr
  217. ierr(:) = 0
  218. ALLOCATE( mjs_crs(nlej_crs) , mje_crs(nlej_crs), mis_crs(nlei_crs) , mie_crs(nlei_crs), STAT=ierr(1) )
  219. crs_dom_alloc2 = MAXVAL(ierr)
  220. END FUNCTION crs_dom_alloc2
  221. SUBROUTINE dom_grid_glo
  222. !!--------------------------------------------------------------------
  223. !! *** MODULE dom_grid_glo ***
  224. !!
  225. !! ** Purpose : +Return back to parent grid domain
  226. !!---------------------------------------------------------------------
  227. ! Return to parent grid domain
  228. jpi = jpi_full
  229. jpj = jpj_full
  230. jpim1 = jpim1_full
  231. jpjm1 = jpjm1_full
  232. nperio = nperio_full
  233. npolj = npolj_full
  234. jpiglo = jpiglo_full
  235. jpjglo = jpjglo_full
  236. nlci = nlci_full
  237. nlcj = nlcj_full
  238. nldi = nldi_full
  239. nldj = nldj_full
  240. nlei = nlei_full
  241. nlej = nlej_full
  242. nimpp = nimpp_full
  243. njmpp = njmpp_full
  244. nlcit(:) = nlcit_full(:)
  245. nldit(:) = nldit_full(:)
  246. nleit(:) = nleit_full(:)
  247. nimppt(:) = nimppt_full(:)
  248. nlcjt(:) = nlcjt_full(:)
  249. nldjt(:) = nldjt_full(:)
  250. nlejt(:) = nlejt_full(:)
  251. njmppt(:) = njmppt_full(:)
  252. END SUBROUTINE dom_grid_glo
  253. SUBROUTINE dom_grid_crs
  254. !!--------------------------------------------------------------------
  255. !! *** MODULE dom_grid_crs ***
  256. !!
  257. !! ** Purpose : Save the parent grid information & Switch to coarse grid domain
  258. !!---------------------------------------------------------------------
  259. !
  260. ! Switch to coarse grid domain
  261. jpi = jpi_crs
  262. jpj = jpj_crs
  263. jpim1 = jpi_crsm1
  264. jpjm1 = jpj_crsm1
  265. nperio = nperio_crs
  266. npolj = npolj_crs
  267. jpiglo = jpiglo_crs
  268. jpjglo = jpjglo_crs
  269. nlci = nlci_crs
  270. nlcj = nlcj_crs
  271. nldi = nldi_crs
  272. nlei = nlei_crs
  273. nlej = nlej_crs
  274. nldj = nldj_crs
  275. nimpp = nimpp_crs
  276. njmpp = njmpp_crs
  277. nlcit(:) = nlcit_crs(:)
  278. nldit(:) = nldit_crs(:)
  279. nleit(:) = nleit_crs(:)
  280. nimppt(:) = nimppt_crs(:)
  281. nlcjt(:) = nlcjt_crs(:)
  282. nldjt(:) = nldjt_crs(:)
  283. nlejt(:) = nlejt_crs(:)
  284. njmppt(:) = njmppt_crs(:)
  285. !
  286. END SUBROUTINE dom_grid_crs
  287. !!======================================================================
  288. END MODULE crs