Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RFLU_SetMoveGridOptions.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: Set options for moving grid computations.
26 !
27 ! Description: The options for imposing boundary conditions on the grid motion
28 ! are determined by whether the patches are flat and whether they are aligned
29 ! with a coordinate direction. If not flat, no boundary condition is (can be)
30 ! applied without a geometrical description of the surface. If the patch is
31 ! flat, Dirichlet conditions are set if the patch normal is perfectly aligned
32 ! with a coordinate direction, otherwise von Neumann conditions are applied.
33 !
34 ! Input:
35 ! pRegion Region pointer
36 !
37 ! Output: None.
38 !
39 ! Notes:
40 ! 1. At present, the only option which is determined in this routine is
41 ! how the boundary conditions are set for the grid motion, namely either
42 ! von Neumann or Dirichlet conditions. The von Neumann condition is
43 ! set for those patches the normal to which is not aligned with a
44 ! coordinate direction. The Dirichlet condition is set for patches the
45 ! normal to which is aligned with a coordinate direction.
46 ! 2. This routine must be called after the boundary vertex normals are
47 ! constructed, and after the boundary condition file is read (so that the
48 ! grid motion options for motion and smoothing are set).
49 !
50 ! ******************************************************************************
51 !
52 ! $Id: RFLU_SetMoveGridOptions.F90,v 1.15 2008/12/06 08:44:30 mtcampbe Exp $
53 !
54 ! Copyright: (c) 2002-2005 by the University of Illinois
55 !
56 ! ******************************************************************************
57 
58 SUBROUTINE rflu_setmovegridoptions(pRegion)
59 
60  USE moddatatypes
61  USE modglobal, ONLY: t_global
62  USE moderror
63  USE modparameters
64  USE moddatastruct, ONLY: t_region
65  USE modbndpatch, ONLY: t_patch
66  USE modmpi
67 
68  USE modtools
69 
70  IMPLICIT NONE
71 
72 ! **************************************I****************************************
73 ! Definitions and declarations
74 ! ******************************************************************************
75 
76 ! ==============================================================================
77 ! Arguments
78 ! ==============================================================================
79 
80  TYPE(t_region), POINTER :: pregion
81 
82 ! ==============================================================================
83 ! Locals
84 ! ==============================================================================
85 
86  LOGICAL :: outsiderflag,xflatflag,yflatflag,zflatflag
87  CHARACTER(CHRLEN) :: movebctypestring,rcsidentstring
88  INTEGER :: errorflag,ibv,ipatch
89  INTEGER, DIMENSION(2) :: maxnormloc
90  REAL(RFREAL), PARAMETER :: eqtol = 1.0e-6_rfreal
91  REAL(RFREAL) :: term,xnorm,xnormmax,xnormmin,ynorm,ynormmax,ynormmin, &
92  znorm,znormmax,znormmin
93  REAL(RFREAL), DIMENSION(:,:), ALLOCATABLE :: globalvals,localvals
94  REAL(RFREAL), DIMENSION(:,:,:), ALLOCATABLE :: bvnext
95  TYPE(t_global), POINTER :: global
96  TYPE(t_patch), POINTER :: ppatch
97 
98 ! ******************************************************************************
99 ! Start
100 ! ******************************************************************************
101 
102  rcsidentstring = '$RCSfile: RFLU_SetMoveGridOptions.F90,v $ $Revision: 1.15 $'
103 
104  global => pregion%global
105 
106  CALL registerfunction(global,'RFLU_SetMoveGridOptions',&
107  'RFLU_SetMoveGridOptions.F90')
108 
109  IF ( global%myProcid == masterproc .AND. &
110  global%verbLevel > verbose_none ) THEN
111  WRITE(stdout,'(A,1X,A)') solver_name,'Setting grid motion options...'
112  WRITE(stdout,'(A,3X,A,1X,E15.8)') solver_name,'Equality tolerance:',eqtol
113  WRITE(stdout,'(A,3X,A,3X,A,2X,A)') solver_name,'Local','Global','Option'
114  END IF ! global%verbLevel
115 
116 ! ******************************************************************************
117 ! Allocate and initialize temporary memory
118 ! ******************************************************************************
119 
120  ALLOCATE(bvnext(min_val:max_val,xcoord:zcoord,global%nPatches),stat=errorflag)
121  global%error = errorflag
122  IF ( global%error /= err_none ) THEN
123  CALL errorstop(global,err_allocate,__line__,'bvnExt')
124  END IF ! global%error
125 
126  DO ipatch = 1,global%nPatches
127  bvnext(min_val,xcoord:zcoord,ipatch) = huge(1.0_rfreal)
128  bvnext(max_val,xcoord:zcoord,ipatch) = -huge(1.0_rfreal)
129  END DO ! iPatch
130 
131  ALLOCATE(localvals(xcoord:zcoord,global%nPatches),stat=errorflag)
132  global%error = errorflag
133  IF ( global%error /= err_none ) THEN
134  CALL errorstop(global,err_allocate,__line__,'localVals')
135  END IF ! global%error
136 
137  ALLOCATE(globalvals(xcoord:zcoord,global%nPatches),stat=errorflag)
138  global%error = errorflag
139  IF ( global%error /= err_none ) THEN
140  CALL errorstop(global,err_allocate,__line__,'globalVals')
141  END IF ! global%error
142 
143 ! ******************************************************************************
144 ! Compute local extrema of patch vertex-normal vectors
145 ! ******************************************************************************
146 
147  DO ipatch = 1,pregion%grid%nPatches
148  ppatch => pregion%patches(ipatch)
149 
150  xnormmin = huge(1.0_rfreal)
151  xnormmax = -huge(1.0_rfreal)
152  ynormmin = huge(1.0_rfreal)
153  ynormmax = -huge(1.0_rfreal)
154  znormmin = huge(1.0_rfreal)
155  znormmax = -huge(1.0_rfreal)
156 
157  DO ibv = 1,ppatch%nBVertTot
158  xnorm = ppatch%bvn(xcoord,ibv)
159  ynorm = ppatch%bvn(ycoord,ibv)
160  znorm = ppatch%bvn(zcoord,ibv)
161 
162  IF ( xnorm < xnormmin ) THEN
163  xnormmin = xnorm
164  ELSE IF ( xnorm > xnormmax ) THEN
165  xnormmax = xnorm
166  END IF ! xNorm
167 
168  IF ( ynorm < ynormmin ) THEN
169  ynormmin = ynorm
170  ELSE IF ( ynorm > ynormmax ) THEN
171  ynormmax = ynorm
172  END IF ! yNorm
173 
174  IF ( znorm < znormmin ) THEN
175  znormmin = znorm
176  ELSE IF ( znorm > znormmax ) THEN
177  znormmax = znorm
178  END IF ! zNorm
179  END DO ! ibv
180 
181  bvnext(min_val,xcoord,ppatch%iPatchGlobal) = xnormmin
182  bvnext(min_val,ycoord,ppatch%iPatchGlobal) = ynormmin
183  bvnext(min_val,zcoord,ppatch%iPatchGlobal) = znormmin
184 
185  bvnext(max_val,xcoord,ppatch%iPatchGlobal) = xnormmax
186  bvnext(max_val,ycoord,ppatch%iPatchGlobal) = ynormmax
187  bvnext(max_val,zcoord,ppatch%iPatchGlobal) = znormmax
188  END DO ! iPatch
189 
190 ! ******************************************************************************
191 ! Compute global extrema of patch normal vectors
192 ! ******************************************************************************
193 
194  DO ipatch = 1,global%nPatches
195  localvals(xcoord,ipatch) = bvnext(min_val,xcoord,ipatch)
196  localvals(ycoord,ipatch) = bvnext(min_val,ycoord,ipatch)
197  localvals(zcoord,ipatch) = bvnext(min_val,zcoord,ipatch)
198  END DO ! iPatch
199 
200  CALL mpi_reduce(localvals,globalvals,(zcoord-xcoord+1)*global%nPatches, &
201  mpi_rfreal,mpi_min,masterproc,global%mpiComm,errorflag)
202  global%error = errorflag
203  IF ( global%error /= err_none ) THEN
204  CALL errorstop(global,err_mpi_trouble,__line__)
205  END IF ! global%errorFlag
206 
207  DO ipatch = 1,global%nPatches
208  bvnext(min_val,xcoord,ipatch) = globalvals(xcoord,ipatch)
209  bvnext(min_val,ycoord,ipatch) = globalvals(ycoord,ipatch)
210  bvnext(min_val,zcoord,ipatch) = globalvals(zcoord,ipatch)
211 
212  localvals(xcoord,ipatch) = bvnext(max_val,xcoord,ipatch)
213  localvals(ycoord,ipatch) = bvnext(max_val,ycoord,ipatch)
214  localvals(zcoord,ipatch) = bvnext(max_val,zcoord,ipatch)
215  END DO ! iPatch
216 
217  CALL mpi_reduce(localvals,globalvals,(zcoord-xcoord+1)*global%nPatches, &
218  mpi_rfreal,mpi_min,masterproc,global%mpiComm,errorflag)
219  global%error = errorflag
220  IF ( global%error /= err_none ) THEN
221  CALL errorstop(global,err_mpi_trouble,__line__)
222  END IF ! global%errorFlag
223 
224  DO ipatch = 1,global%nPatches
225  bvnext(max_val,xcoord,ipatch) = globalvals(xcoord,ipatch)
226  bvnext(max_val,ycoord,ipatch) = globalvals(ycoord,ipatch)
227  bvnext(max_val,zcoord,ipatch) = globalvals(zcoord,ipatch)
228  END DO ! iPatch
229 
230 ! ******************************************************************************
231 ! Loop over patches to determine options on grid motion
232 ! ******************************************************************************
233 
234  DO ipatch = 1,pregion%grid%nPatches
235  ppatch => pregion%patches(ipatch)
236 
237  ppatch%moveBcType = movegrid_bctype_none
238 
239 ! ==============================================================================
240 ! Determine whether non-moving patches are flat
241 ! ==============================================================================
242 
243  IF ( (ppatch%movePatch .EQV. .false.) .AND. &
244  (ppatch%smoothGrid .EQV. .true.) ) THEN
245 
246 ! ------------------------------------------------------------------------------
247 ! Get extrema of normal vector
248 ! ------------------------------------------------------------------------------
249 
250  xnormmin = bvnext(min_val,xcoord,ppatch%iPatchGlobal)
251  xnormmax = bvnext(max_val,xcoord,ppatch%iPatchGlobal)
252 
253  ynormmin = bvnext(min_val,ycoord,ppatch%iPatchGlobal)
254  ynormmax = bvnext(max_val,ycoord,ppatch%iPatchGlobal)
255 
256  znormmin = bvnext(min_val,zcoord,ppatch%iPatchGlobal)
257  znormmax = bvnext(max_val,zcoord,ppatch%iPatchGlobal)
258 
259 ! ------------------------------------------------------------------------------
260 ! Determine whether patch is flat by checking whether extrema have same
261 ! sign (if yes, and extrema are equal, have flat patch; if no, and extrema
262 ! are close to zero, also have flat patch)
263 ! ------------------------------------------------------------------------------
264 
265 ! --- x-direction --------------------------------------------------------------
266 
267  IF ( (sign(1.0_rfreal,xnormmin) == sign(1.0_rfreal,xnormmax)) ) THEN
268  IF ( floatequal(xnormmin,xnormmax,eqtol) .EQV. .true. ) THEN
269  xflatflag = .true.
270  ELSE
271  xflatflag = .false.
272  END IF ! FloatEqual
273  ELSE
274  IF ( (floatequal(abs(xnormmin),epsilon(1.0_rfreal),eqtol)) .AND. &
275  (floatequal(abs(xnormmax),epsilon(1.0_rfreal),eqtol)) ) THEN
276  xflatflag = .true.
277  ELSE
278  xflatflag = .false.
279  END IF ! FloatEqual
280  END IF ! FloatEqual
281 
282 ! --- y-direction --------------------------------------------------------------
283 
284  IF ( (sign(1.0_rfreal,ynormmin) == sign(1.0_rfreal,ynormmax)) ) THEN
285  IF ( floatequal(ynormmin,ynormmax,eqtol) .EQV. .true. ) THEN
286  yflatflag = .true.
287  ELSE
288  yflatflag = .false.
289  END IF ! FloatEqual
290  ELSE
291  IF ( (floatequal(abs(ynormmin),epsilon(1.0_rfreal),eqtol)) .AND. &
292  (floatequal(abs(ynormmax),epsilon(1.0_rfreal),eqtol)) ) THEN
293  yflatflag = .true.
294  ELSE
295  yflatflag = .false.
296  END IF ! FloatEqual
297  END IF ! FloatEqual
298 
299 ! --- z-direction --------------------------------------------------------------
300 
301  IF ( (sign(1.0_rfreal,znormmin) == sign(1.0_rfreal,znormmax)) ) THEN
302  IF ( floatequal(znormmin,znormmax,eqtol) .EQV. .true. ) THEN
303  zflatflag = .true.
304  ELSE
305  zflatflag = .false.
306  END IF ! FloatEqual
307  ELSE
308  IF ( (floatequal(abs(znormmin),epsilon(1.0_rfreal),eqtol)) .AND. &
309  (floatequal(abs(znormmax),epsilon(1.0_rfreal),eqtol)) ) THEN
310  zflatflag = .true.
311  ELSE
312  zflatflag = .false.
313  END IF ! FloatEqual
314  END IF ! FloatEqual
315 
316 ! ==============================================================================
317 ! Determine whether patch is flat and aligned with coordinate directions.
318 ! If flat and aligned with coordinate directions, use Dirichlet conditions,
319 ! otherwise use Neumann conditions (but only if do not have any outsider
320 ! actual vertices).
321 ! ==============================================================================
322 
323  IF ( (xflatflag .EQV. .true.) .AND. &
324  (yflatflag .EQV. .true.) .AND. &
325  (zflatflag .EQV. .true.) ) THEN
326  term = max(abs(xnormmin),abs(xnormmax), &
327  abs(ynormmin),abs(ynormmax), &
328  abs(znormmin),abs(znormmax))
329 
330 ! ------------------------------------------------------------------------------
331 ! Patch is flat and aligned with coordinate axes
332 ! ------------------------------------------------------------------------------
333 
334  IF ( floatequal(term,1.0_rfreal) .EQV. .true. ) THEN
335  IF ( term == abs(xnormmin) .OR. term == abs(xnormmax) ) THEN
336  ppatch%moveBcType = xcoord
337  ELSE IF ( term == abs(ynormmin) .OR. term == abs(ynormmax) ) THEN
338  ppatch%moveBcType = ycoord
339  ELSE IF ( term == abs(znormmin) .OR. term == abs(znormmax) ) THEN
340  ppatch%moveBcType = zcoord
341  END IF ! term
342 
343 ! ------------------------------------------------------------------------------
344 ! Patch is flat but not aligned with coordinate axes, so set boundary
345 ! condition to von Neumann
346 ! ------------------------------------------------------------------------------
347 
348  ELSE
349  ppatch%moveBcType = movegrid_bctype_neumann
350  END IF ! xFlagFlag
351  END IF ! xFlatFlag
352 
353 ! ==============================================================================
354 ! Check that patches have proper boundary condition. Patches with active
355 ! smoothing must be flat, whether or not aligned with coordinate directions.
356 ! ==============================================================================
357 
358  IF ( ppatch%moveBcType == movegrid_bctype_none ) THEN
359  ppatch%smoothGrid = .false.
360 
361  global%warnCounter = global%warnCounter + 1
362 
363  IF ( global%myProcid == masterproc .AND. &
364  global%verbLevel > verbose_none ) THEN
365  WRITE(stdout,'(A,3X,A,I3,A)') solver_name, &
366  '*** WARNING *** Invalid smoothing input for patch ',ipatch, &
367  '. Overriding user input for grid smoothing.'
368  END IF ! global%myProcid
369  END IF ! pPatch%smoothGrid
370  END IF ! pPatch%movePatch
371 
372 ! ==============================================================================
373 ! Write out info
374 ! ==============================================================================
375 
376  IF ( global%myProcid == masterproc .AND. &
377  global%verbLevel > verbose_none ) THEN
378  IF ( ppatch%moveBcType == movegrid_bctype_none ) THEN
379  movebctypestring = 'None'
380  ELSE IF ( ppatch%moveBcType == movegrid_bctype_neumann ) THEN
381  movebctypestring = 'von Neumann (homogeneous)'
382  ELSE IF ( ppatch%moveBcType == movegrid_bctype_dirichx ) THEN
383  movebctypestring = 'Dirichlet (homogeneous in x)'
384  ELSE IF ( ppatch%moveBcType == movegrid_bctype_dirichy ) THEN
385  movebctypestring = 'Dirichlet (homogeneous in y)'
386  ELSE IF ( ppatch%moveBcType == movegrid_bctype_dirichz ) THEN
387  movebctypestring = 'Dirichlet (homogeneous in z)'
388  ELSE
389  CALL errorstop(global,err_reached_default,__line__)
390  END IF ! pPatch%moveBcType
391 
392  WRITE(stdout,'(A,2X,I4,5X,I4,4X,A)') solver_name,ipatch, &
393  ppatch%iPatchGlobal, &
394  trim(movebctypestring)
395  END IF ! global%myProcid
396  END DO ! iPatch
397 
398 ! ******************************************************************************
399 ! Check settings - catch error before get to grid motion (caught there also)
400 ! ******************************************************************************
401 
402  DO ipatch = 1,pregion%grid%nPatches
403  ppatch => pregion%patches(ipatch)
404 
405  IF ( (ppatch%smoothGrid .EQV. .true.) .AND. &
406  (ppatch%moveBcType == movegrid_bctype_none) ) THEN
407  CALL errorstop(global,err_movepatch_bc_invalid,__line__)
408  END IF ! pPatch
409  END DO ! iPatch
410 
411 ! ******************************************************************************
412 ! Deallocate temporary memory
413 ! ******************************************************************************
414 
415  DEALLOCATE(bvnext,stat=errorflag)
416  global%error = errorflag
417  IF ( global%error /= err_none ) THEN
418  CALL errorstop(global,err_deallocate,__line__,'bvnExt')
419  END IF ! global%error
420 
421  DEALLOCATE(localvals,stat=errorflag)
422  global%error = errorflag
423  IF ( global%error /= err_none ) THEN
424  CALL errorstop(global,err_deallocate,__line__,'localVals')
425  END IF ! global%error
426 
427  DEALLOCATE(globalvals,stat=errorflag)
428  global%error = errorflag
429  IF ( global%error /= err_none ) THEN
430  CALL errorstop(global,err_deallocate,__line__,'globalVals')
431  END IF ! global%error
432 
433 ! ******************************************************************************
434 ! End
435 ! ******************************************************************************
436 
437  IF ( global%myProcid == masterproc .AND. &
438  global%verbLevel > verbose_none ) THEN
439  WRITE(stdout,'(A,1X,A)') solver_name,'Setting grid motion options done.'
440  END IF ! global%verbLevel
441 
442  CALL deregisterfunction(global)
443 
444 END SUBROUTINE rflu_setmovegridoptions
445 
446 ! ******************************************************************************
447 !
448 ! RCS Revision history:
449 !
450 ! $Log: RFLU_SetMoveGridOptions.F90,v $
451 ! Revision 1.15 2008/12/06 08:44:30 mtcampbe
452 ! Updated license.
453 !
454 ! Revision 1.14 2008/11/19 22:17:43 mtcampbe
455 ! Added Illinois Open Source License/Copyright
456 !
457 ! Revision 1.13 2006/04/07 15:19:22 haselbac
458 ! Removed tabs
459 !
460 ! Revision 1.12 2005/04/15 15:07:25 haselbac
461 ! Converted to MPI
462 !
463 ! Revision 1.11 2004/10/19 19:29:24 haselbac
464 ! Removed logic related to insider/outsider vertices
465 !
466 ! Revision 1.10 2003/07/22 02:12:00 haselbac
467 ! Added global%warnCounter
468 !
469 ! Revision 1.9 2003/05/01 14:13:51 haselbac
470 ! Added logic to deal with non-moving and non-smoothed patches
471 !
472 ! Revision 1.8 2003/03/27 21:50:21 haselbac
473 ! Fixed bug in determining outsiderFlag
474 !
475 ! Revision 1.7 2003/03/15 18:57:22 haselbac
476 ! Completed || of gm, added check for outsider vertices
477 !
478 ! Revision 1.6 2003/02/20 20:15:23 haselbac
479 ! Bug fix: nVertTot changed to nVert (from different working version)
480 !
481 ! Revision 1.5 2003/02/20 19:49:20 haselbac
482 ! Corrected bug in check
483 !
484 ! Revision 1.4 2003/02/06 19:32:16 haselbac
485 ! Bug fix (EPS instd of PREC), use tolerance, check for error
486 !
487 ! Revision 1.3 2003/01/28 14:49:19 haselbac
488 ! Only set bc for non-moving patches
489 !
490 ! Revision 1.2 2002/11/27 20:27:17 haselbac
491 ! Changed test for planarity and added output
492 !
493 ! Revision 1.1 2002/11/26 15:28:56 haselbac
494 ! Initial revision
495 !
496 ! ******************************************************************************
497 
498 
499 
500 
501 
502 
503 
static SURF_BEGIN_NAMESPACE double sign(double x)
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:354
subroutine registerfunction(global, funName, fileName)
Definition: ModError.F90:449
subroutine rflu_setmovegridoptions(pRegion)
subroutine errorstop(global, errorCode, errorLine, addMessage)
Definition: ModError.F90:483
subroutine deregisterfunction(global)
Definition: ModError.F90:469
LOGICAL function floatequal(a, b, tolIn)
Definition: ModTools.F90:99