Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RFLU_MoveGridDisp.F90
Go to the documentation of this file.
1 ! *********************************************************************
2 ! * Rocstar Simulation Suite *
3 ! * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4 ! * *
5 ! * Illinois Rocstar LLC *
6 ! * Champaign, IL *
7 ! * www.illinoisrocstar.com *
8 ! * sales@illinoisrocstar.com *
9 ! * *
10 ! * License: See LICENSE file in top level of distribution package or *
11 ! * http://opensource.org/licenses/NCSA *
12 ! *********************************************************************
13 ! *********************************************************************
14 ! * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15 ! * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16 ! * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17 ! * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18 ! * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19 ! * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20 ! * Arising FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21 ! * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22 ! *********************************************************************
23 ! ******************************************************************************
24 !
25 ! Purpose: Move grid by smoothing displacements.
26 !
27 ! Description: Simple pseudo-Laplacian smoothing of grid given boundary
28 ! distortion.
29 !
30 ! Input:
31 ! regions Region data
32 !
33 ! Output: None.
34 !
35 ! Notes:
36 ! 1. The two parameters influencing the grid motion, i.e., the number of
37 ! iterations and the smoothing coefficient, may need some tuning as more
38 ! complicated geometries are attempted...
39 ! 2. The integrity of patches with no imposed motion is ensured by one of
40 ! two methods. Both may be cast in terms of a boundary condition on the
41 ! residual of the Laplacian operator. The first is a von Neumann bc on
42 ! the residual and can be used for flat boundaries which are not aligned
43 ! the normal to which is not aligned with a coordinate direction. The
44 ! second is a Dirichlet boundary condition which can be used for flat
45 ! boundaries the normal to which is aligned with a coordinate direction.
46 ! Of course, the first method subsumes the second, but the latter may be
47 ! preferable because the first can introduce errors on the order of the
48 ! machine precision into the constant coordinate component. Which of the
49 ! two methods is more suitable is determined by a simple algorithm in
50 ! the routine RFLU_SetMoveGridOptions.F90.
51 !
52 ! ******************************************************************************
53 !
54 ! $Id: RFLU_MoveGridDisp.F90,v 1.11 2008/12/06 08:44:30 mtcampbe Exp $
55 !
56 ! Copyright: (c) 2003-2005 by the University of Illinois
57 !
58 ! ******************************************************************************
59 
60 SUBROUTINE rflu_movegriddisp(regions)
61 
62  USE moddatatypes
63  USE modgrid, ONLY: t_grid
64  USE moddatastruct, ONLY: t_region
65  USE modbndpatch, ONLY: t_patch
66  USE modglobal, ONLY: t_global
67  USE moderror
68  USE modmpi
69  USE modparameters
70 
71  IMPLICIT NONE
72 
73 ! *****************************************************************************
74 ! Declarations and definitions
75 ! *****************************************************************************
76 
77 ! =============================================================================
78 ! Arguments
79 ! =============================================================================
80 
81  TYPE(t_region), DIMENSION(:), POINTER :: regions
82 
83 ! =============================================================================
84 ! Locals
85 ! =============================================================================
86 
87  CHARACTER(CHRLEN) :: rcsidentstring
88  INTEGER :: errorflag,ic,ie,ipatch,ireg,it,iv,ivg,niter,patchcheckcounter, &
89  v1,v2
90  REAL(RFREAL) :: nx,ny,nz,sfact,term,x1,x2,y1,y2,z1,z2
91  REAL(RFREAL) :: ddisp(xcoord:zcoord)
92  REAL(RFREAL), DIMENSION(:,:), POINTER :: pdisp,prhs,pxyz
93  TYPE(t_global), POINTER :: global
94  TYPE(t_grid), POINTER :: pgrid,pgridold
95  TYPE(t_patch), POINTER :: ppatch
96  TYPE(t_region), POINTER :: pregion
97 
98 ! *****************************************************************************
99 ! Start
100 ! *****************************************************************************
101 
102  rcsidentstring = '$RCSfile: RFLU_MoveGridDisp.F90,v $ $Revision: 1.11 $'
103 
104  global => regions(1)%global
105 
106  CALL registerfunction(global,'RFLU_MoveGridDisp',&
107  'RFLU_MoveGridDisp.F90')
108 
109  IF ( global%myProcid == masterproc .AND. &
110  global%verbLevel /= verbose_low ) THEN
111  WRITE(stdout,'(A,1X,A)') solver_name, &
112  'Moving grid based on displacements...'
113  END IF ! global%myProcid
114 
115 ! *****************************************************************************
116 ! Set variables
117 ! *****************************************************************************
118 
119  niter = regions(1)%mixtInput%moveGridNIter
120  sfact = regions(1)%mixtInput%moveGridSFact
121 
122 ! TEMPORARY disable smoothing for MPI version
123  niter = 0
124 ! END TEMPORARY
125 
126 ! *****************************************************************************
127 ! Copy grid data to old grid. Must be done even if have zero smoothing
128 ! iterations.
129 ! *****************************************************************************
130 
131  DO ireg = 1,global%nRegionsLocal
132  pgrid => regions(ireg)%grid
133  pgridold => regions(ireg)%gridOld
134 
135  DO ic = 1,pgrid%nCellsTot ! Explicit copy to avoid ASCI White problem
136  pgridold%vol(ic) = pgrid%vol(ic)
137  END DO ! ic
138 
139  DO iv = 1,pgrid%nVertTot ! Explicit copy to avoid ASCI White problem
140  pgridold%xyz(xcoord,iv) = pgrid%xyz(xcoord,iv)
141  pgridold%xyz(ycoord,iv) = pgrid%xyz(ycoord,iv)
142  pgridold%xyz(zcoord,iv) = pgrid%xyz(zcoord,iv)
143  END DO ! iv
144  END DO ! iReg
145 
146 ! *****************************************************************************
147 ! Allocate temporary memory for and compute edge weights
148 ! *****************************************************************************
149 
150  IF ( niter > 0 ) THEN
151  DO ireg = 1,global%nRegionsLocal
152  pgrid => regions(ireg)%grid
153 
154  ALLOCATE(pgrid%gmEdgeWght(pgrid%nEdgesTot),stat=errorflag)
155  global%error = errorflag
156  IF ( global%error /= err_none ) THEN
157  CALL errorstop(global,err_allocate,__line__,'pGrid%gmEdgeWght')
158  END IF ! global%error )
159 
160  ALLOCATE(pgrid%gmVertWght(pgrid%nVertTot),stat=errorflag)
161  global%error = errorflag
162  IF ( global%error /= err_none ) THEN
163  CALL errorstop(global,err_allocate,__line__,'pGrid%gmVertWght')
164  END IF ! global%error
165  END DO ! iReg
166 
167  DO ireg = 1,global%nRegionsLocal
168  pgrid => regions(ireg)%grid
169 
170  DO iv = 1,pgrid%nVertTot
171  pgrid%gmVertWght(iv) = 0.0_rfreal
172  END DO ! iv
173 
174  DO ie = 1,pgrid%nEdgesTot
175  v1 = pgrid%e2v(1,ie)
176  v2 = pgrid%e2v(2,ie)
177 
178  x1 = pgrid%xyz(xcoord,v1)
179  y1 = pgrid%xyz(ycoord,v1)
180  z1 = pgrid%xyz(zcoord,v1)
181 
182  x2 = pgrid%xyz(xcoord,v2)
183  y2 = pgrid%xyz(ycoord,v2)
184  z2 = pgrid%xyz(zcoord,v2)
185 
186  term = 1.0_rfreal/sqrt((x2 - x1)**2 + (y2 - y1)**2 + (z2 - z1)**2)
187 
188  pgrid%gmEdgeWght(ie) = term
189 
190  pgrid%gmVertWght(v1) = pgrid%gmVertWght(v1) + term
191  pgrid%gmVertWght(v2) = pgrid%gmVertWght(v2) + term
192  END DO ! ie
193  END DO ! iReg
194  END IF ! nIter
195 
196 ! ******************************************************************************
197 ! Initialize displacements to zero and impose patch displacements. NOTE need to
198 ! impose patch displacements so that get boundary deformation even if have zero
199 ! smoothing iterations.
200 ! ******************************************************************************
201 
202  DO ireg = 1,global%nRegionsLocal
203  pgrid => regions(ireg)%grid
204  pdisp => pgrid%disp
205 
206  DO iv = 1,pgrid%nVertTot
207  pdisp(xcoord,iv) = 0.0_rfreal
208  pdisp(ycoord,iv) = 0.0_rfreal
209  pdisp(zcoord,iv) = 0.0_rfreal
210  END DO ! iv
211 
212  DO ipatch = 1,pgrid%nPatches
213  ppatch => regions(ireg)%patches(ipatch)
214 
215  IF ( ppatch%movePatchDir /= movepatch_dir_none ) THEN
216  DO iv = 1,ppatch%nBVert
217  ivg = ppatch%bv(iv)
218 
219  pdisp(xcoord,ivg) = ppatch%dXyz(xcoord,iv)
220  pdisp(ycoord,ivg) = ppatch%dXyz(ycoord,iv)
221  pdisp(zcoord,ivg) = ppatch%dXyz(zcoord,iv)
222  END DO ! iv
223  END IF ! pPatch%movePatchDir
224  END DO ! iPatch
225  END DO ! iReg
226 
227 ! ******************************************************************************
228 ! Apply pseudo-Laplacian smoothing to coordinates of all vertices
229 ! ******************************************************************************
230 
231  DO it = 1,niter
232 
233 ! ==============================================================================
234 ! Compute right-hand side with boundary restrictions already imposed
235 ! ==============================================================================
236 
237  DO ireg = 1,global%nRegionsLocal
238  pgrid => regions(ireg)%grid
239  pdisp => pgrid%disp
240  prhs => pgrid%rhs
241 
242  DO iv = 1,pgrid%nVert
243  prhs(xcoord,iv) = 0.0_rfreal
244  prhs(ycoord,iv) = 0.0_rfreal
245  prhs(zcoord,iv) = 0.0_rfreal
246  END DO ! iv
247 
248 ! ------------------------------------------------------------------------------
249 ! Enforce patch deformation. NOTE that strictly speaking this is not
250 ! needed during first smoothing iteration because initialized outside
251 ! iteration loop.
252 ! ------------------------------------------------------------------------------
253 
254  DO ipatch = 1,pgrid%nPatches
255  ppatch => regions(ireg)%patches(ipatch)
256 
257  IF ( ppatch%movePatchDir /= movepatch_dir_none ) THEN
258  DO iv = 1,ppatch%nBVert
259  ivg = ppatch%bv(iv)
260 
261  pdisp(xcoord,ivg) = ppatch%dXyz(xcoord,iv)
262  pdisp(ycoord,ivg) = ppatch%dXyz(ycoord,iv)
263  pdisp(zcoord,ivg) = ppatch%dXyz(zcoord,iv)
264  END DO ! iv
265  END IF ! pPatch%movePatchDir
266  END DO ! iPatch
267 
268 ! ------------------------------------------------------------------------------
269 ! Compute right-hand side. NOTE loop only over actual edges and take into
270 ! account the region degree of each edge to deal with multiple contributions
271 ! of edges on region boundaries.
272 ! ------------------------------------------------------------------------------
273 
274  DO ie = 1,pgrid%nEdges
275  v1 = pgrid%e2v(1,ie)
276  v2 = pgrid%e2v(2,ie)
277 
278  term = sfact*pgrid%gmEdgeWght(ie)/(REAL(pGrid%e2rDegr(ie),kind=rfreal))
279 
280  ddisp(xcoord) = term*(pdisp(xcoord,v2) - pdisp(xcoord,v1))
281  ddisp(ycoord) = term*(pdisp(ycoord,v2) - pdisp(ycoord,v1))
282  ddisp(zcoord) = term*(pdisp(zcoord,v2) - pdisp(zcoord,v1))
283 
284  prhs(xcoord,v1) = prhs(xcoord,v1) + ddisp(xcoord)
285  prhs(ycoord,v1) = prhs(ycoord,v1) + ddisp(ycoord)
286  prhs(zcoord,v1) = prhs(zcoord,v1) + ddisp(zcoord)
287 
288  prhs(xcoord,v2) = prhs(xcoord,v2) - ddisp(xcoord)
289  prhs(ycoord,v2) = prhs(ycoord,v2) - ddisp(ycoord)
290  prhs(zcoord,v2) = prhs(zcoord,v2) - ddisp(zcoord)
291  END DO ! ie
292 
293 ! ------------------------------------------------------------------------------
294 ! Apply boundary deformation restrictions
295 ! ------------------------------------------------------------------------------
296 
297  patchcheckcounter = 0
298 
299 ! --- Enforce imposed deformation ----------------------------------------------
300 
301  DO ipatch = 1,pgrid%nPatches
302  ppatch => regions(ireg)%patches(ipatch)
303 
304  IF ( ppatch%movePatchDir /= movepatch_dir_none ) THEN
305  patchcheckcounter = patchcheckcounter + 1
306 
307  DO iv = 1,ppatch%nBVert
308  ivg = ppatch%bv(iv)
309 
310  prhs(xcoord,ivg) = 0.0_rfreal
311  prhs(ycoord,ivg) = 0.0_rfreal
312  prhs(zcoord,ivg) = 0.0_rfreal
313  END DO ! iv
314  END IF ! pPatch%movePatchDir
315  END DO ! iPatch
316 
317 ! --- Ensure boundary integrity (no imposed motion or smoothing) ---------------
318 
319  DO ipatch = 1,pgrid%nPatches
320  ppatch => regions(ireg)%patches(ipatch)
321 
322  IF ( ppatch%movePatchDir == movepatch_dir_none ) THEN
323  patchcheckcounter = patchcheckcounter + 1
324 
325  SELECT CASE ( ppatch%moveBcType )
326 
327 ! --------- Normal displacement set to zero with Neumann bc
328 
329  CASE ( movegrid_bctype_neumann )
330  DO iv = 1,ppatch%nBVert
331  ivg = ppatch%bv(iv)
332 
333  nx = ppatch%bvn(xcoord,iv)
334  ny = ppatch%bvn(ycoord,iv)
335  nz = ppatch%bvn(zcoord,iv)
336 
337  term = prhs(xcoord,ivg)*nx &
338  + prhs(ycoord,ivg)*ny &
339  + prhs(zcoord,ivg)*nz
340 
341  prhs(xcoord,ivg) = prhs(xcoord,ivg) - term*nx
342  prhs(ycoord,ivg) = prhs(ycoord,ivg) - term*ny
343  prhs(zcoord,ivg) = prhs(zcoord,ivg) - term*nz
344  END DO ! iv
345 
346 ! --------- Normal displacement set to zero with Dirichlet bc
347 
348  CASE ( movegrid_bctype_dirichx, &
349  movegrid_bctype_dirichy, &
350  movegrid_bctype_dirichz )
351  DO iv = 1,ppatch%nBVert
352  ivg = ppatch%bv(iv)
353 
354  prhs(ppatch%moveBcType,ivg) = 0.0_rfreal
355  END DO ! iv
356 
357 ! --------- No bc (must only occur with no movement and smoothing)
358 
359  CASE ( movegrid_bctype_none )
360  IF ( ppatch%smoothGrid .EQV. .false. ) THEN
361  DO iv = 1,ppatch%nBVert
362  ivg = ppatch%bv(iv)
363 
364  prhs(xcoord,ivg) = 0.0_rfreal
365  prhs(ycoord,ivg) = 0.0_rfreal
366  prhs(zcoord,ivg) = 0.0_rfreal
367  END DO ! iv
368  ELSE ! Defensive programming
369  CALL errorstop(global,err_reached_default,__line__)
370  END IF !
371 
372  CASE default ! Defensive programming
373  CALL errorstop(global,err_reached_default,__line__)
374  END SELECT ! pPatch%moveBcType
375 
376  END IF ! pPatch%movePatchDir
377  END DO ! iPatch
378  END DO ! iReg
379 
380 ! ------------------------------------------------------------------------------
381 ! Check that all patches have mesh motion boundary conditions set. This
382 ! should never happen - if it does, there is a bug in the above code
383 ! segment (defensive coding)
384 ! ------------------------------------------------------------------------------
385 
386  IF ( patchcheckcounter /= pgrid%nPatches ) THEN
387  CALL errorstop(global,err_movepatch_bc_notset,__line__)
388  END IF ! patchCheckCounter
389 
390 ! TO DO
391 ! Reduction of rhs
392 ! END TO DO
393 
394 ! ==============================================================================
395 ! Update displacements
396 ! ==============================================================================
397 
398  DO ireg = 1,global%nRegionsLocal
399  pgrid => regions(ireg)%grid
400  pdisp => pgrid%disp
401  prhs => pgrid%rhs
402 
403  DO iv = 1,pgrid%nVertTot
404  term = 1.0_rfreal/REAL(pGrid%gmVertWght(iv),RFREAL)
405 
406  pdisp(xcoord,iv) = pdisp(xcoord,iv) + term*prhs(xcoord,iv)
407  pdisp(ycoord,iv) = pdisp(ycoord,iv) + term*prhs(ycoord,iv)
408  pdisp(zcoord,iv) = pdisp(zcoord,iv) + term*prhs(zcoord,iv)
409  END DO ! iv
410  END DO ! iReg
411 
412 ! TO DO
413 ! Update virtual vertices
414 ! END TO DO
415  END DO ! it
416 
417 ! ******************************************************************************
418 ! Update coordinates
419 ! ******************************************************************************
420 
421  IF ( niter > 0 ) THEN
422  DO ireg = 1,global%nRegionsLocal
423  pgrid => regions(ireg)%grid
424  pdisp => pgrid%disp
425  pxyz => pgrid%xyz
426 
427  DO iv = 1,pgrid%nVertTot
428  pxyz(xcoord,iv) = pxyz(xcoord,iv) + pdisp(xcoord,iv)
429  pxyz(ycoord,iv) = pxyz(ycoord,iv) + pdisp(ycoord,iv)
430  pxyz(zcoord,iv) = pxyz(zcoord,iv) + pdisp(zcoord,iv)
431  END DO ! iv
432  END DO ! iReg
433  END IF ! nIter
434 
435 ! ******************************************************************************
436 ! Deallocate temporary arrays
437 ! ******************************************************************************
438 
439  IF ( niter > 0 ) THEN
440  DO ireg = 1,global%nRegionsLocal
441  pgrid => regions(ireg)%grid
442 
443  DEALLOCATE(pgrid%gmEdgeWght,stat=errorflag)
444  global%error = errorflag
445  IF ( global%error /= err_none ) THEN
446  CALL errorstop(global,err_deallocate,__line__,'pGrid%gmEdgeWght')
447  END IF ! global%error
448 
449  DEALLOCATE(pgrid%gmVertWght,stat=errorflag)
450  global%error = errorflag
451  IF ( global%error /= err_none ) THEN
452  CALL errorstop(global,err_deallocate,__line__,'pGrid%gmVertWght')
453  END IF ! global%error
454  END DO ! iReg
455  END IF ! nIter
456 
457 ! ******************************************************************************
458 ! End
459 ! ******************************************************************************
460 
461  IF ( global%myProcid == masterproc .AND. &
462  global%verbLevel /= verbose_low ) THEN
463  WRITE(stdout,'(A,1X,A)') solver_name, &
464  'Moving grid based on displacements done.'
465  END IF ! global%myProcid
466 
467  CALL deregisterfunction(global)
468 
469 END SUBROUTINE rflu_movegriddisp
470 
471 ! ******************************************************************************
472 !
473 ! RCS Revision history:
474 !
475 ! $Log: RFLU_MoveGridDisp.F90,v $
476 ! Revision 1.11 2008/12/06 08:44:30 mtcampbe
477 ! Updated license.
478 !
479 ! Revision 1.10 2008/11/19 22:17:42 mtcampbe
480 ! Added Illinois Open Source License/Copyright
481 !
482 ! Revision 1.9 2005/06/09 20:22:58 haselbac
483 ! Replaced movePatch by movePatchDir
484 !
485 ! Revision 1.8 2005/04/15 15:07:20 haselbac
486 ! Converted to MPI, grid motion can only be used for serial runs
487 !
488 ! Revision 1.7 2004/09/17 19:59:58 haselbac
489 ! Added IF statements to prevent operations for zero iterations
490 !
491 ! Revision 1.6 2004/04/14 03:57:11 haselbac
492 ! Bug fix: Now get correct boundary deformation for zero smoothing iterations
493 !
494 ! Revision 1.5 2003/08/20 02:09:58 haselbac
495 ! Changed verbosity conditions to reduce solver output in GENx runs
496 !
497 ! Revision 1.4 2003/07/09 22:36:53 haselbac
498 ! Added IF statement to avoid probs with single-proc charm jobs
499 !
500 ! Revision 1.3 2003/05/01 14:12:10 haselbac
501 ! Added logic to deal with non-moving and non-smoothed patches
502 !
503 ! Revision 1.2 2003/04/17 00:16:19 haselbac
504 ! Bug fix: Weight should be inverse sqrt, little effect
505 !
506 ! Revision 1.1 2003/03/31 16:05:39 haselbac
507 ! Initial revision
508 !
509 ! ******************************************************************************
510 
511 
512 
513 
514 
515 
516 
subroutine rflu_movegriddisp(regions)
subroutine registerfunction(global, funName, fileName)
Definition: ModError.F90:449
**********************************************************************Rocstar Simulation Suite Illinois Rocstar LLC All rights reserved ****Illinois Rocstar LLC IL **www illinoisrocstar com **sales illinoisrocstar com WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **Arising OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE **********************************************************************INTERFACE SUBROUTINE ic
double sqrt(double d)
Definition: double.h:73
subroutine errorstop(global, errorCode, errorLine, addMessage)
Definition: ModError.F90:483
subroutine deregisterfunction(global)
Definition: ModError.F90:469