1 !WRF:MEDIATION_LAYER:PHYSICS
3 !==============================================================================
5 ! Copyright 2009. Lawrence Livermore National Security, LLC. All rights reserved.
6 ! This work was produced at the Lawrence Livermore National Laboratory (LLNL) under
7 ! contract no. DE-AC52-07NA27344 (Contract 44) between the U.S. Department of Energy (DOE)
8 ! and Lawrence Livermore National Security, LLC (LLNS) for the operation of LLNL. Copyright
9 ! is reserved to Lawrence Livermore National Security, LLC for purposes of controlled
10 ! dissemination, commercialization through formal licensing, or other disposition under
11 ! terms of Contract 44; DOE policies, regulations and orders; and U.S. statutes. The rights
12 ! of the Federal Government are reserved under Contract 44.
15 ! This work was prepared as an account of work sponsored by an agency of the United States
16 ! Government. Neither the United States Government nor Lawrence Livermore National
17 ! Security, LLC nor any of their employees, makes any warranty, express or implied, or
18 ! assumes any liability or responsibility for the accuracy, completeness, or usefulness of
19 ! any information, apparatus, product, or process disclosed, or represents that its use
20 ! would not infringe privately-owned rights. Reference herein to any specific commercial
21 ! products, process, or service by trade name, trademark, manufacturer or otherwise does
22 ! not necessarily constitute or imply its endorsement, recommendation, or favoring by the
23 ! United States Government or Lawrence Livermore National Security, LLC. The views and
24 ! opinions of authors expressed herein do not necessarily state or reflect those of the
25 ! United States Government or Lawrence Livermore National Security, LLC, and shall not be
26 ! used for advertising or product endorsement purposes.
28 ! LICENSING REQUIREMENTS
29 ! Any use, reproduction, modification, or distribution of this software or documentation
30 ! for commercial purposes requires a license from Lawrence Livermore National Security,
31 ! LLC. Contact: Lawrence Livermore National Laboratory, Industrial Partnerships Office,
32 ! P.O. Box 808, L-795, Livermore, CA 94551
34 !=============================================================================
36 ! Modification History:
38 ! Implemented 12/2009 by Jeff Mirocha, jmirocha@llnl.gov
40 !=============================================================================
42 MODULE module_sfs_driver
46 !=============================================================================
48 SUBROUTINE sfs_driver( grid, config_flags, &
52 !-----------------------------------------------------------------------------
54 ! PURPOSE: Calls turbulence subfilter stress model subroutines and handles
55 ! all MPI and OMP operations
57 !-----------------------------------------------------------------------------
60 ! Driver layer modules
62 USE module_model_constants
66 USE module_state_description
70 !! *** add new modules of schemes here
75 USE module_comm_dm, ONLY : &
77 ,PERIOD_EM_NBA_RIJ_sub &
78 ,HALO_EM_NBA_MIJ_sub &
79 ,PERIOD_EM_NBA_MIJ_sub
86 TYPE(domain) , TARGET :: grid
88 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
90 INTEGER, INTENT( IN ) :: n_nba_mij, n_nba_rij
92 REAL ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33,n_nba_mij) &
95 REAL ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33,n_nba_rij) &
100 INTEGER :: k_start , k_end, its, ite, jts, jte
101 INTEGER :: ids , ide , jds , jde , kds , kde , &
102 ims , ime , jms , jme , kms , kme , &
103 ips , ipe , jps , jpe , kps , kpe
105 INTEGER :: imsx, imex, jmsx, jmex, kmsx, kmex, &
106 ipsx, ipex, jpsx, jpex, kpsx, kpex, &
107 imsy, imey, jmsy, jmey, kmsy, kmey, &
108 ipsy, ipey, jpsy, jpey, kpsy, kpey
110 INTEGER :: ij, i, j, k
112 CALL get_ijk_from_grid ( grid , &
113 ids, ide, jds, jde, kds, kde, &
114 ims, ime, jms, jme, kms, kme, &
115 ips, ipe, jps, jpe, kps, kpe, &
116 imsx, imex, jmsx, jmex, kmsx, kmex, &
117 ipsx, ipex, jpsx, jpex, kpsx, kpex, &
118 imsy, imey, jmsy, jmey, kmsy, kmey, &
119 ipsy, ipey, jpsy, jpey, kpsy, kpey )
124 ! Compute these starting and stopping locations for each tile and number of tiles.
125 ! See: http://www.mmm.ucar.edu/wrf/WG2/topics/settiles
127 ! Solve_em has already called this, so should not be necessary to reset tiles here
128 CALL set_tiles ( ZONE_SFS, grid , ids , ide , jds , jde , ips , ipe , jps , jpe )
130 IF ( (config_flags%sfs_opt .EQ. 1) .OR. (config_flags%sfs_opt .EQ. 2) ) THEN
132 !=======================================================================
136 !=======================================================================
138 ! IF ( grid%itimestep .EQ. 1 ) THEN
140 ! IF ( (config_flags%sfs_opt .EQ. 2) .AND. (config_flags%km_opt .NE. 2)) THEN
142 ! CALL wrf_error_fatal( 'Must use km_opt=2 with sfs_opt=2' )
148 !_______________________________________________________________________
150 ! Compute NBA model constants
151 !_______________________________________________________________________
156 DO ij = 1 , grid%num_tiles !----------------------------------------
158 CALL calc_mij_constants( )
160 ENDDO !-------------------------------------------------------------
161 !$OMP END PARALLEL DO
163 !_______________________________________________________________________
166 !_______________________________________________________________________
170 DO ij = 1 , grid%num_tiles !----------------------------------------
172 CALL calc_smnsmn( nba_rij(ims,kms,jms,P_smnsmn), &
173 grid%defor11, grid%defor22, &
174 grid%defor33, grid%defor12, &
175 grid%defor13, grid%defor23, &
177 ids, ide, jds, jde, kds, kde, &
178 ims, ime, jms, jme, kms, kme, &
179 ips, ipe, jps, jpe, kps, kpe, &
180 grid%i_start(ij), grid%i_end(ij), &
181 grid%j_start(ij), grid%j_end(ij), &
184 ENDDO !-------------------------------------------------------------
185 !$OMP END PARALLEL DO
187 !_______________________________________________________________________
189 ! Update halos for R12, R13, R23 and smnsmn
190 !_______________________________________________________________________
193 # include "HALO_EM_NBA_RIJ.inc"
194 # include "PERIOD_EM_NBA_RIJ.inc"
199 DO ij = 1 , grid%num_tiles !----------------------------------------
201 CALL set_physical_bc3d( nba_rij(ims,kms,jms,P_r12), 'd', &
203 ids, ide, jds, jde, kds, kde, &
204 ims, ime, jms, jme, kms, kme, &
205 ips, ipe, jps, jpe, kps, kpe, &
206 grid%i_start(ij), grid%i_end(ij), &
207 grid%j_start(ij), grid%j_end(ij), &
211 CALL set_physical_bc3d( nba_rij(ims,kms,jms,P_r13), 'e', &
213 ids, ide, jds, jde, kds, kde, &
214 ims, ime, jms, jme, kms, kme, &
215 ips, ipe, jps, jpe, kps, kpe, &
216 grid%i_start(ij), grid%i_end(ij), &
217 grid%j_start(ij), grid%j_end(ij), &
220 CALL set_physical_bc3d( nba_rij(ims,kms,jms,P_r23), 'f', &
222 ids, ide, jds, jde, kds, kde, &
223 ims, ime, jms, jme, kms, kme, &
224 ips, ipe, jps, jpe, kps, kpe, &
225 grid%i_start(ij), grid%i_end(ij), &
226 grid%j_start(ij), grid%j_end(ij), &
229 CALL set_physical_bc3d( nba_rij(ims,kms,jms,P_smnsmn), 'c', &
231 ids, ide, jds, jde, kds, kde, &
232 ims, ime, jms, jme, kms, kme, &
233 ips, ipe, jps, jpe, kps, kpe, &
234 grid%i_start(ij), grid%i_end(ij), &
235 grid%j_start(ij), grid%j_end(ij), &
238 ENDDO !-------------------------------------------------------------
239 !$OMP END PARALLEL DO
241 !_______________________________________________________________________
243 ! Calculate M11, M22 and M33
244 !_______________________________________________________________________
248 DO ij = 1 , grid%num_tiles !----------------------------------------
250 CALL calc_mii( nba_mij(ims,kms,jms,P_m11), &
251 nba_mij(ims,kms,jms,P_m22), &
252 nba_mij(ims,kms,jms,P_m33), &
253 grid%defor11, grid%defor22, &
254 grid%defor33, grid%defor12, &
255 grid%defor13, grid%defor23, &
256 nba_rij(ims,kms,jms,P_r12), &
257 nba_rij(ims,kms,jms,P_r13), &
258 nba_rij(ims,kms,jms,P_r23), &
259 nba_rij(ims,kms,jms,P_smnsmn), &
261 grid%rdzw, grid%dx, grid%dy, &
263 ids, ide, jds, jde, kds, kde, &
264 ims, ime, jms, jme, kms, kme, &
265 ips, ipe, jps, jpe, kps, kpe, &
266 grid%i_start(ij), grid%i_end(ij), &
267 grid%j_start(ij), grid%j_end(ij), &
270 ENDDO !-------------------------------------------------------------
271 !$OMP END PARALLEL DO
273 !_______________________________________________________________________
276 !_______________________________________________________________________
280 DO ij = 1 , grid%num_tiles !----------------------------------------
282 CALL calc_m12( nba_mij(ims,kms,jms,P_m12), &
283 grid%defor11, grid%defor22, &
284 grid%defor12, grid%defor13, &
286 nba_rij(ims,kms,jms,P_r12), &
287 nba_rij(ims,kms,jms,P_r13), &
288 nba_rij(ims,kms,jms,P_r23), &
289 nba_rij(ims,kms,jms,P_smnsmn), &
291 grid%rdzw, grid%dx, grid%dy, &
293 ids, ide, jds, jde, kds, kde, &
294 ims, ime, jms, jme, kms, kme, &
295 ips, ipe, jps, jpe, kps, kpe, &
296 grid%i_start(ij), grid%i_end(ij), &
297 grid%j_start(ij), grid%j_end(ij), &
300 ENDDO !-------------------------------------------------------------
301 !$OMP END PARALLEL DO
303 !_______________________________________________________________________
306 !_______________________________________________________________________
310 DO ij = 1 , grid%num_tiles !----------------------------------------
312 CALL calc_m13( nba_mij(ims,kms,jms,P_m13), &
313 grid%defor11, grid%defor33, &
314 grid%defor12, grid%defor13, &
316 nba_rij(ims,kms,jms,P_r12), &
317 nba_rij(ims,kms,jms,P_r13), &
318 nba_rij(ims,kms,jms,P_r23), &
319 nba_rij(ims,kms,jms,P_smnsmn), &
321 grid%rdzw, grid%dx, grid%dy, &
322 grid%fnm, grid%fnp, &
324 ids, ide, jds, jde, kds, kde, &
325 ims, ime, jms, jme, kms, kme, &
326 ips, ipe, jps, jpe, kps, kpe, &
327 grid%i_start(ij), grid%i_end(ij), &
328 grid%j_start(ij), grid%j_end(ij), &
331 ENDDO !-------------------------------------------------------------
332 !$OMP END PARALLEL DO
333 !_______________________________________________________________________
336 !_______________________________________________________________________
340 DO ij = 1 , grid%num_tiles !----------------------------------------
342 CALL calc_m23( nba_mij(ims,kms,jms,P_m23), &
343 grid%defor22, grid%defor33, &
344 grid%defor12, grid%defor13, &
346 nba_rij(ims,kms,jms,P_r12), &
347 nba_rij(ims,kms,jms,P_r13), &
348 nba_rij(ims,kms,jms,P_r23), &
349 nba_rij(ims,kms,jms,P_smnsmn), &
351 grid%rdzw, grid%dx, grid%dy, &
352 grid%fnm, grid%fnp, &
354 ids, ide, jds, jde, kds, kde, &
355 ims, ime, jms, jme, kms, kme, &
356 ips, ipe, jps, jpe, kps, kpe, &
357 grid%i_start(ij), grid%i_end(ij), &
358 grid%j_start(ij), grid%j_end(ij), &
361 ENDDO !-------------------------------------------------------------
362 !$OMP END PARALLEL DO
363 !_______________________________________________________________________
365 ! Update boundary conditions and halos after calculating Mij
366 !_______________________________________________________________________
369 # include "HALO_EM_NBA_MIJ.inc"
370 # include "PERIOD_EM_NBA_MIJ.inc"
375 DO ij = 1 , grid%num_tiles !----------------------------------------
377 CALL set_physical_bc3d( nba_mij(ims,kms,jms,P_m11), 'p', &
379 ids, ide, jds, jde, kds, kde, &
380 ims, ime, jms, jme, kms, kme, &
381 ips, ipe, jps, jpe, kps, kpe, &
382 grid%i_start(ij), grid%i_end(ij), &
383 grid%j_start(ij), grid%j_end(ij), &
386 CALL set_physical_bc3d( nba_mij(ims,kms,jms,P_m22), 'p', &
388 ids, ide, jds, jde, kds, kde, &
389 ims, ime, jms, jme, kms, kme, &
390 ips, ipe, jps, jpe, kps, kpe, &
391 grid%i_start(ij), grid%i_end(ij), &
392 grid%j_start(ij), grid%j_end(ij), &
395 CALL set_physical_bc3d( nba_mij(ims,kms,jms,P_m33), 'p', &
397 ids, ide, jds, jde, kds, kde, &
398 ims, ime, jms, jme, kms, kme, &
399 ips, ipe, jps, jpe, kps, kpe, &
400 grid%i_start(ij), grid%i_end(ij), &
401 grid%j_start(ij), grid%j_end(ij), &
404 CALL set_physical_bc3d( nba_mij(ims,kms,jms,P_m12), 'd', &
406 ids, ide, jds, jde, kds, kde, &
407 ims, ime, jms, jme, kms, kme, &
408 ips, ipe, jps, jpe, kps, kpe, &
409 grid%i_start(ij), grid%i_end(ij), &
410 grid%j_start(ij), grid%j_end(ij), &
413 CALL set_physical_bc3d( nba_mij(ims,kms,jms,P_m13), 'e', &
415 ids, ide, jds, jde, kds, kde, &
416 ims, ime, jms, jme, kms, kme, &
417 ips, ipe, jps, jpe, kps, kpe, &
418 grid%i_start(ij), grid%i_end(ij), &
419 grid%j_start(ij), grid%j_end(ij), &
422 CALL set_physical_bc3d( nba_mij(ims,kms,jms,P_m23), 'f', &
424 ids, ide, jds, jde, kds, kde, &
425 ims, ime, jms, jme, kms, kme, &
426 ips, ipe, jps, jpe, kps, kpe, &
427 grid%i_start(ij), grid%i_end(ij), &
428 grid%j_start(ij), grid%j_end(ij), &
431 ENDDO !-------------------------------------------------------------
432 !$OMP END PARALLEL DO
434 !=======================================================================
438 !=======================================================================
440 ENDIF !(config_flags%sfs_opt .EQ. 1) .OR. (config_flags%sfs_opt .EQ. 2)
442 END SUBROUTINE sfs_driver
444 END MODULE module_sfs_driver