Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RFLU_ModStencilsUtils.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: Suite of utility routines to construct stencils.
26 !
27 ! Description: None.
28 !
29 ! Notes: None.
30 !
31 ! ******************************************************************************
32 !
33 ! $Id: RFLU_ModStencilsUtils.F90,v 1.14 2008/12/06 08:44:24 mtcampbe Exp $
34 !
35 ! Copyright: (c) 2003-2006 by the University of Illinois
36 !
37 ! ******************************************************************************
38 
40 
41  USE modglobal, ONLY: t_global
42  USE modparameters
43  USE moddatatypes
44  USE moderror
45  USE modbndpatch, ONLY: t_patch
46  USE moddatastruct, ONLY: t_region
47  USE modgrid, ONLY: t_grid
48  USE modstencil, ONLY: t_stencil
49  USE modsortsearch
50  USE modmpi
51 
53 
54  IMPLICIT NONE
55 
56  PRIVATE
57  PUBLIC :: rflu_addbfaces, &
65 
66 
67 ! ******************************************************************************
68 ! Declarations and definitions
69 ! ******************************************************************************
70 
71  CHARACTER(CHRLEN) :: RCSIdentString = &
72  '$RCSfile: RFLU_ModStencilsUtils.F90,v $ $Revision: 1.14 $'
73 
74 ! ******************************************************************************
75 ! Routines
76 ! ******************************************************************************
77 
78  CONTAINS
79 
80 
81 
82 
83 
84 ! ******************************************************************************
85 !
86 ! Purpose: Extend basic stencil by adding boundary faces.
87 !
88 ! Description: None.
89 !
90 ! Input:
91 ! pRegion Pointer to region
92 ! nBFaceMembsMaxTemp Maximum allowed number of boundary faces in stencil
93 ! nCellMembs Number of cell members in stencil
94 ! cellMembs List of cell members of stencil
95 !
96 ! Output:
97 ! nBFaceMembs Number of boundary faces in stencil
98 ! bFaceMembs List of boundary faces in stencil
99 !
100 ! Notes: None.
101 !
102 ! ******************************************************************************
103 
104  SUBROUTINE rflu_addbfaces(pRegion,nBFaceMembsMaxTemp,nCellMembs,cellMembs, &
105  nbfacemembs,bfacemembs)
106 
107  IMPLICIT NONE
108 
109 ! ******************************************************************************
110 ! Declarations and definitions
111 ! ******************************************************************************
112 
113 ! ==============================================================================
114 ! Arguments
115 ! ==============================================================================
116 
117  INTEGER, INTENT(IN) :: nbfacemembsmaxtemp,ncellmembs
118  INTEGER, INTENT(OUT) :: nbfacemembs
119  INTEGER, INTENT(IN) :: cellmembs(ncellmembs)
120  INTEGER, INTENT(OUT) :: bfacemembs(2,nbfacemembsmaxtemp)
121  TYPE(t_region), POINTER :: pregion
122 
123 ! ==============================================================================
124 ! Locals
125 ! ==============================================================================
126 
127  INTEGER :: errorflag,ifl,iloc,ipatch,isg,isl
128  TYPE(t_global), POINTER :: global
129  TYPE(t_grid), POINTER :: pgrid
130  TYPE(t_patch), POINTER :: ppatch
131 
132 ! ******************************************************************************
133 ! Set pointers
134 ! ******************************************************************************
135 
136  global => pregion%global
137 
138  pgrid => pregion%grid
139 
140 ! ******************************************************************************
141 ! Start
142 ! ******************************************************************************
143 
144  CALL registerfunction(global,'RFLU_AddBFaces',&
145  'RFLU_ModStencilsUtils.F90')
146 
147 ! ******************************************************************************
148 ! Build sorted bf2c lists (and sorting keys) so can be searched later on
149 ! ******************************************************************************
150 
151  DO ipatch = 1,pgrid%nPatches
152  ppatch => pregion%patches(ipatch)
153 
154  IF ( (ppatch%bcType == bc_noslipwall_hflux) .OR. &
155  (ppatch%bcType == bc_noslipwall_temp ) .OR. &
156  (ppatch%bcType == bc_slipwall ) .OR. &
157  (ppatch%bcType == bc_injection ) ) THEN
158  IF ( ppatch%nBFaces > 0 ) THEN
159  ALLOCATE(ppatch%bf2cSorted(ppatch%nBFaces),stat=errorflag)
160  global%error = errorflag
161  IF ( global%error /= err_none ) THEN
162  CALL errorstop(global,err_allocate,__line__,'pPatch%bf2cSorted')
163  END IF ! global%error
164 
165  ALLOCATE(ppatch%bf2cSortedKeys(ppatch%nBFaces),stat=errorflag)
166  global%error = errorflag
167  IF ( global%error /= err_none ) THEN
168  CALL errorstop(global,err_allocate,__line__,'pPatch%bf2cSortedKeys')
169  END IF ! global%error
170 
171  DO ifl = 1,ppatch%nBFaces
172  ppatch%bf2cSorted(ifl) = ppatch%bf2c(ifl)
173  END DO ! ifl
174 
175  CALL quicksortinteger(ppatch%bf2cSorted,ppatch%nBFaces)
176 
177  DO ifl = 1,ppatch%nBFaces
178  CALL binarysearchinteger(ppatch%bf2cSorted,ppatch%nBFaces, &
179  ppatch%bf2c(ifl),iloc)
180 
181  IF ( iloc /= element_not_found ) THEN
182  ppatch%bf2cSortedKeys(iloc) = ifl
183  ELSE
184  CALL errorstop(global,err_binary_search,__line__)
185  END IF ! iloc
186  END DO ! ifl
187  END IF ! pPatch%nBFaces
188  END IF ! pPatch%bcType
189  END DO ! iPatch
190 
191 ! ******************************************************************************
192 ! Initialize list
193 ! ******************************************************************************
194 
195  nbfacemembs = 0
196 
197  DO isl = 1,nbfacemembsmaxtemp
198  bfacemembs(1,isl) = crazy_value_int
199  bfacemembs(2,isl) = crazy_value_int
200  END DO ! isl
201 
202 ! ******************************************************************************
203 ! Find boundary cells in stencil
204 ! ******************************************************************************
205 
206  islloop: DO isl = 1,ncellmembs
207  isg = cellmembs(isl)
208 
209  DO ipatch = 1,pgrid%nPatches
210  ppatch => pregion%patches(ipatch)
211 
212  IF ( (ppatch%bcType == bc_noslipwall_hflux) .OR. &
213  (ppatch%bcType == bc_noslipwall_temp ) .OR. &
214  (ppatch%bcType == bc_slipwall ) .OR. &
215  (ppatch%bcType == bc_injection ) ) THEN
216  IF ( ppatch%nBFaces > 0 ) THEN
217  CALL binarysearchinteger(ppatch%bf2cSorted,ppatch%nBFaces,isg, &
218  iloc)
219 
220  IF ( iloc /= element_not_found ) THEN
221  IF ( nbfacemembs < nbfacemembsmaxtemp ) THEN
222  nbfacemembs = nbfacemembs + 1
223 
224  bfacemembs(1,nbfacemembs) = ipatch
225  bfacemembs(2,nbfacemembs) = ppatch%bf2cSortedKeys(iloc)
226  ELSE
227  EXIT islloop
228  END IF ! nBFaceMembs
229  END IF ! iloc
230  END IF ! pPatch%nBFaces
231  END IF ! pPatch%bcType
232  END DO ! iPatch
233  END DO islloop
234 
235 ! ******************************************************************************
236 ! Deallocate memory for sorted bf2c lists
237 ! ******************************************************************************
238 
239  DO ipatch = 1,pgrid%nPatches
240  ppatch => pregion%patches(ipatch)
241 
242  IF ( (ppatch%bcType == bc_noslipwall_hflux) .OR. &
243  (ppatch%bcType == bc_noslipwall_temp ) .OR. &
244  (ppatch%bcType == bc_slipwall ) .OR. &
245  (ppatch%bcType == bc_injection ) ) THEN
246  IF ( ppatch%nBFaces > 0 ) THEN
247  DEALLOCATE(ppatch%bf2cSorted,stat=errorflag)
248  global%error = errorflag
249  IF ( global%error /= err_none ) THEN
250  CALL errorstop(global,err_deallocate,__line__,'pPatch%bf2cSorted')
251  END IF ! global%error
252 
253  DEALLOCATE(ppatch%bf2cSortedKeys,stat=errorflag)
254  global%error = errorflag
255  IF ( global%error /= err_none ) THEN
256  CALL errorstop(global,err_deallocate,__line__, &
257  'pPatch%bf2cSortedKeys')
258  END IF ! global%error
259  END IF ! pPatch%nBFaces
260  END IF ! pPatch%bcType
261  END DO ! iPatch
262 
263 ! ******************************************************************************
264 ! End
265 ! ******************************************************************************
266 
267  CALL deregisterfunction(global)
268 
269  END SUBROUTINE rflu_addbfaces
270 
271 
272 
273 
274 
275 
276 
277 
278 ! ******************************************************************************
279 !
280 ! Purpose: Extend basic stencil in only ONE direction
281 !
282 ! Description: Loop over cells in the last layer of stencil and add cells
283 ! whose normal vector is aligned along a particular direction, i.e. x, y, z
284 ! Not just add vertex-neighbors because we only want to extend the stencil
285 ! in one direction
286 !
287 ! Input:
288 ! global Pointer to global data
289 ! pGrid Pointer to grid
290 ! stencilSizeMax Maximum allowed size of stencil
291 ! ixg Index of cell for which cells are added
292 ! degr Degree of stencil before addition of cell layer
293 ! x2csBeg Beginning index for the last layer of cells in stencil
294 ! x2csEnd Ending index for the last layer of cells in stencil
295 ! x2cs Stencil before addition of cell layer
296 ! fnDir Direction of stencil
297 !
298 ! Output:
299 ! degr Degree of stencil after addition of cell layer
300 ! x2cs Stencil after addition of cell layer
301 !
302 ! Notes: None.
303 !
304 ! ******************************************************************************
305 
306  SUBROUTINE rflu_addcelllayer_1d(global,pGrid,stencilSizeMax,ixg,degr, &
307  x2csbeg,x2csend,x2cs,fndir)
308 
309  IMPLICIT NONE
310 
311 ! ******************************************************************************
312 ! Declarations and definitions
313 ! ******************************************************************************
314 
315 ! ==============================================================================
316 ! Arguments
317 ! ==============================================================================
318 
319  INTEGER, INTENT(IN) :: fndir,ixg,stencilsizemax,x2csbeg,x2csend
320  INTEGER, INTENT(INOUT) :: degr
321  INTEGER, INTENT(INOUT) :: x2cs(stencilsizemax)
322  TYPE(t_global), POINTER :: global
323  TYPE(t_grid), POINTER :: pgrid
324 
325 ! ==============================================================================
326 ! Locals
327 ! ==============================================================================
328 
329  INTEGER :: c1,c2,degrhelp,icg,icg2,icl,ifg,ifl,iloc,ipatch,isl,iv2c,ivg, &
330  ivl,nfaces
331  INTEGER :: x2cshelp(stencilsizemax),x2cssort(stencilsizemax)
332  REAL(RFREAL) :: fn
333 
334 ! ******************************************************************************
335 ! Start
336 ! ******************************************************************************
337 
338  CALL registerfunction(global,'RFLU_AddCellLayer_1D',&
339  'RFLU_ModStencilsUtils.F90')
340 
341 ! ******************************************************************************
342 ! Add layer of cells to existing stencil in 1D, store in separate array
343 ! ******************************************************************************
344 
345 ! ==============================================================================
346 ! Initialize
347 ! ==============================================================================
348 
349  degrhelp = 0 ! renamed because 'degr' is already used
350 
351  DO isl = 1,stencilsizemax
352  x2cshelp(isl) = 0 ! store new layer's members
353  x2cssort(isl) = 0 ! duplicated array for x2cs
354  END DO ! isl
355 
356  DO isl = 1,degr
357  x2cssort(isl) = x2cs(isl)
358  END DO ! isl
359 
360  CALL quicksortinteger(x2cssort(1:degr),degr)
361 
362 ! ==============================================================================
363 ! Loop over existing members in the last layer and find candidates for stencil
364 ! ==============================================================================
365 
366  outerloop: DO isl = x2csbeg,x2csend
367  icg = x2cs(isl)
368  icl = pgrid%cellGlob2Loc(2,icg)
369 
370  nfaces = SIZE(pgrid%hex2f,2)
371 
372  DO ifl = 1,nfaces
373  ipatch = pgrid%hex2f(1,ifl,icl)
374  ifg = pgrid%hex2f(2,ifl,icl)
375 
376  IF ( ipatch == 0 ) THEN ! Interior face
377  c1 = pgrid%f2c(1,ifg)
378  c2 = pgrid%f2c(2,ifg)
379 
380  IF ( c1 /= ixg .AND. c2 /= ixg ) THEN
381  IF ( c1 == icg ) THEN
382  fn = pgrid%fn(fndir,ifg)
383  ELSE IF ( c2 == icg ) THEN
384  fn = -pgrid%fn(fndir,ifg)
385  ELSE ! defensive programming
386  CALL errorstop(global,err_reached_default,__line__)
387  END IF ! c1
388 
389  IF ( abs(fn) >= 0.999_rfreal ) THEN
390  IF ( c1 == icg ) THEN
391  icg2 = c2
392  ELSE IF ( c2 == icg ) THEN
393  icg2 = c1
394  ELSE ! defensive programming
395  CALL errorstop(global,err_reached_default,__line__)
396  END IF ! c1
397 
398  CALL binarysearchinteger(x2cssort(1:degr),degr,icg2,iloc)
399 
400  IF ( iloc == element_not_found ) THEN
401  IF ( degrhelp > 0 ) THEN
402  CALL binarysearchinteger(x2cshelp(1:degrhelp),degrhelp, &
403  icg2,iloc)
404  IF ( iloc == element_not_found ) THEN
405  IF ( degrhelp < stencilsizemax ) THEN
406  degrhelp = degrhelp + 1
407  x2cshelp(degrhelp) = icg2
408  IF ( degrhelp > 1 ) THEN
409  CALL quicksortinteger(x2cshelp(1:degrhelp),degrhelp)
410  END IF ! degrHelp
411  ELSE
412  EXIT outerloop
413  END IF ! degrHelp
414  END IF ! iloc
415  ELSE ! First member
416  degrhelp = degrhelp + 1
417  x2cshelp(degrhelp) = icg2
418  END IF ! degrHelp
419  END IF ! iloc
420  END IF ! ABS(fn)
421  END IF ! c1, c2
422  ELSE IF ( ipatch > 0 ) THEN ! Boundary face
423 ! TO DO
424 ! Currently do not add boundary faces for constrained reconstruction
425 ! END TO DO
426  ELSE ! Defensive programming
427  CALL errorstop(global,err_reached_default,__line__)
428  END IF ! iPatch
429  END DO ! ifl
430  END DO outerloop
431 
432 ! ******************************************************************************
433 ! Merge new layer with existing stencil
434 ! ******************************************************************************
435 
436  DO isl = 1,degrhelp
437  IF ( degr < stencilsizemax ) THEN
438  degr = degr + 1
439  x2cs(degr) = x2cshelp(isl)
440  END IF ! degr
441  END DO ! isl
442 
443 ! ******************************************************************************
444 ! End
445 ! ******************************************************************************
446 
447  CALL deregisterfunction(global)
448 
449  END SUBROUTINE rflu_addcelllayer_1d
450 
451 
452 
453 
454 
455 
456 ! ******************************************************************************
457 !
458 ! Purpose: Extend basic stencil in ONE direction by adding vertex neighbours
459 ! of cells based on geometry.
460 !
461 ! Description: Loop over cells in last layer of stencil and add all cells
462 ! which share vertices with that layer of cells and are aligned with the
463 ! given direction.
464 !
465 ! Input:
466 ! global Pointer to global data
467 ! pGrid Pointer to grid
468 ! stencilSizeMax Maximum allowed size of stencil
469 ! ixg Index of cell for which cells are added
470 ! degr Degree of stencil before addition of cell layer
471 ! x2csBeg Beginning index for last layer of cells in stencil
472 ! x2csEnd Ending index for last layer of cells in stencil
473 ! x2cs Stencil before addition of cell layer
474 ! rc Location for which stencil is constructed
475 ! dir Direction in which stencil is to be constructed
476 !
477 ! Output:
478 ! degr Degree of stencil after addition of cell layer
479 ! x2cs Stencil after addition of cell layer
480 !
481 ! Notes: None.
482 !
483 ! ******************************************************************************
484 
485  SUBROUTINE rflu_addcelllayer_1d_g(global,pGrid,stencilSizeMax,ixg,degr, &
486  x2csbeg,x2csend,x2cs,rc,dir)
487 
489 
490  IMPLICIT NONE
491 
492 ! ******************************************************************************
493 ! Declarations and definitions
494 ! ******************************************************************************
495 
496 ! ==============================================================================
497 ! Arguments
498 ! ==============================================================================
499 
500  INTEGER, INTENT(IN) :: dir,ixg,stencilsizemax,x2csbeg,x2csend
501  INTEGER, INTENT(INOUT) :: degr
502  INTEGER, INTENT(INOUT) :: x2cs(stencilsizemax)
503  REAL(RFREAL), INTENT(IN) :: rc(xcoord:zcoord)
504  TYPE(t_global), POINTER :: global
505  TYPE(t_grid), POINTER :: pgrid
506 
507 ! ==============================================================================
508 ! Locals
509 ! ==============================================================================
510 
511  LOGICAL :: alignflag
512  INTEGER :: degrhelp,icg,icg2,icl,ict,iloc,isl,ivg,ivl,iv2c
513  INTEGER :: x2cshelp(stencilsizemax),x2cssort(stencilsizemax)
514  REAL(RFREAL) :: dr(xcoord:zcoord)
515 
516 ! ******************************************************************************
517 ! Start
518 ! ******************************************************************************
519 
520  CALL registerfunction(global,'RFLU_AddCellLayer_1D_G',&
521  'RFLU_ModStencilsUtils.F90')
522 
523 ! ******************************************************************************
524 ! Add layer of cells to existing stencil, store in separate array
525 ! ******************************************************************************
526 
527 ! ==============================================================================
528 ! Initialize
529 ! ==============================================================================
530 
531  degrhelp = 0
532 
533  DO isl = 1,stencilsizemax
534  x2cshelp(isl) = 0
535  x2cssort(isl) = 0
536  END DO ! isl
537 
538  DO isl = 1,degr
539  x2cssort(isl) = x2cs(isl)
540  END DO ! isl
541 
542  CALL quicksortinteger(x2cssort(1:degr),degr)
543 
544 ! ==============================================================================
545 ! Loop over existing members in last layer and find candidates for stencil
546 ! ==============================================================================
547 
548  outerloop: DO isl = x2csbeg,x2csend
549  icg = x2cs(isl)
550  ict = rflu_getglobalcelltype(global,pgrid,icg)
551  icl = pgrid%cellGlob2Loc(2,icg)
552 
553  SELECT CASE ( ict )
554 
555 ! ------------------------------------------------------------------------------
556 ! Hexahedra
557 ! ------------------------------------------------------------------------------
558 
559  CASE ( cell_type_hex )
560  DO ivl = 1,8
561  ivg = pgrid%hex2v(ivl,icl)
562 
563  DO iv2c = pgrid%v2cInfo(v2c_beg,ivg),pgrid%v2cInfo(v2c_end,ivg)
564  icg2 = pgrid%v2c(iv2c)
565 
566  IF ( icg2 /= ixg ) THEN
567  CALL binarysearchinteger(x2cssort(1:degr),degr,icg2,iloc)
568 
569  IF ( iloc == element_not_found ) THEN
570  IF ( degrhelp > 0 ) THEN
571  CALL binarysearchinteger(x2cshelp(1:degrhelp),degrhelp, &
572  icg2,iloc)
573  IF ( iloc == element_not_found ) THEN
574  IF ( degrhelp < stencilsizemax ) THEN
575  dr(xcoord) = pgrid%cofg(xcoord,icg2) - rc(xcoord)
576  dr(ycoord) = pgrid%cofg(ycoord,icg2) - rc(ycoord)
577  dr(zcoord) = pgrid%cofg(zcoord,icg2) - rc(zcoord)
578 
579  alignflag = rflu_testvectorcartaxisaligned(global,dr,dir)
580 
581  IF ( alignflag .EQV. .true. ) THEN
582  degrhelp = degrhelp + 1
583  x2cshelp(degrhelp) = icg2
584 
585  IF ( degrhelp > 1 ) THEN
586  CALL quicksortinteger(x2cshelp(1:degrhelp),degrhelp)
587  END IF ! degrHelp
588  END IF ! alignFlag
589  ELSE
590  EXIT outerloop
591  END IF ! degrHelp
592  END IF ! iloc
593  ELSE
594  dr(xcoord) = pgrid%cofg(xcoord,icg2) - rc(xcoord)
595  dr(ycoord) = pgrid%cofg(ycoord,icg2) - rc(ycoord)
596  dr(zcoord) = pgrid%cofg(zcoord,icg2) - rc(zcoord)
597 
598  alignflag = rflu_testvectorcartaxisaligned(global,dr,dir)
599 
600  IF ( alignflag .EQV. .true. ) THEN
601  degrhelp = degrhelp + 1
602  x2cshelp(degrhelp) = icg2
603  END IF ! alignFlag
604  END IF ! degrHelp
605  END IF ! iloc
606  END IF ! icg2
607 
608  END DO ! iv2c
609  END DO ! ivl
610 
611 ! ------------------------------------------------------------------------------
612 ! Default
613 ! ------------------------------------------------------------------------------
614 
615  CASE default
616  CALL errorstop(global,err_reached_default,__line__)
617  END SELECT ! ict
618  END DO outerloop
619 
620 ! ******************************************************************************
621 ! Merge new layer with existing stencil
622 ! ******************************************************************************
623 
624  DO isl = 1,degrhelp
625  IF ( degr < stencilsizemax ) THEN
626  degr = degr + 1
627  x2cs(degr) = x2cshelp(isl)
628  END IF ! degr
629  END DO ! isl
630 
631 ! ******************************************************************************
632 ! End
633 ! ******************************************************************************
634 
635  CALL deregisterfunction(global)
636 
637  END SUBROUTINE rflu_addcelllayer_1d_g
638 
639 
640 
641 
642 
643 
644 ! ******************************************************************************
645 !
646 ! Purpose: Extend basic stencil by adding vertex neighbours of cells.
647 !
648 ! Description: Loop over cells in last layer of stencil and add all cells
649 ! which share vertices with that layer of cells.
650 !
651 ! Input:
652 ! global Pointer to global data
653 ! pGrid Pointer to grid
654 ! stencilSizeMax Maximum allowed size of stencil
655 ! ixg Index of cell for which cells are added
656 ! degr Degree of stencil before addition of cell layer
657 ! x2csBeg Beginning index for last layer of cells in stencil
658 ! x2csEnd Ending index for last layer of cells in stencil
659 ! x2cs Stencil before addition of cell layer
660 !
661 ! Output:
662 ! degr Degree of stencil after addition of cell layer
663 ! x2cs Stencil after addition of cell layer
664 !
665 ! Notes: None.
666 !
667 ! ******************************************************************************
668 
669  SUBROUTINE rflu_addcelllayer(global,pGrid,stencilSizeMax,ixg,degr,x2csBeg, &
670  x2csend,x2cs)
671 
672  IMPLICIT NONE
673 
674 ! ******************************************************************************
675 ! Declarations and definitions
676 ! ******************************************************************************
677 
678 ! ==============================================================================
679 ! Arguments
680 ! ==============================================================================
681 
682  INTEGER, INTENT(IN) :: ixg,stencilsizemax,x2csbeg,x2csend
683  INTEGER, INTENT(INOUT) :: degr
684  INTEGER, INTENT(INOUT) :: x2cs(stencilsizemax)
685  TYPE(t_global), POINTER :: global
686  TYPE(t_grid), POINTER :: pgrid
687 
688 ! ==============================================================================
689 ! Locals
690 ! ==============================================================================
691 
692  INTEGER :: degrhelp,icg,icg2,icl,ict,iloc,isl,ivg,ivl,iv2c
693  INTEGER :: x2cshelp(stencilsizemax),x2cssort(stencilsizemax)
694 
695 ! ******************************************************************************
696 ! Start
697 ! ******************************************************************************
698 
699  CALL registerfunction(global,'RFLU_AddCellLayer',&
700  'RFLU_ModStencilsUtils.F90')
701 
702 ! ******************************************************************************
703 ! Add layer of cells to existing stencil, store in separate array
704 ! ******************************************************************************
705 
706 ! ==============================================================================
707 ! Initialize
708 ! ==============================================================================
709 
710  degrhelp = 0
711 
712  DO isl = 1,stencilsizemax
713  x2cshelp(isl) = 0
714  x2cssort(isl) = 0
715  END DO ! isl
716 
717  DO isl = 1,degr
718  x2cssort(isl) = x2cs(isl)
719  END DO ! isl
720 
721  CALL quicksortinteger(x2cssort(1:degr),degr)
722 
723 ! ==============================================================================
724 ! Loop over existing members in last layer and find candidates for stencil
725 ! ==============================================================================
726 
727  outerloop: DO isl = x2csbeg,x2csend
728  icg = x2cs(isl)
729  ict = rflu_getglobalcelltype(global,pgrid,icg)
730  icl = pgrid%cellGlob2Loc(2,icg)
731 
732  SELECT CASE ( ict )
733 
734 ! ------------------------------------------------------------------------------
735 ! Tetrahedra
736 ! ------------------------------------------------------------------------------
737 
738  CASE ( cell_type_tet )
739  DO ivl = 1,4
740  ivg = pgrid%tet2v(ivl,icl)
741 
742  DO iv2c = pgrid%v2cInfo(v2c_beg,ivg),pgrid%v2cInfo(v2c_end,ivg)
743  icg2 = pgrid%v2c(iv2c)
744 
745  IF ( icg2 /= ixg ) THEN
746  CALL binarysearchinteger(x2cssort(1:degr),degr,icg2,iloc)
747 
748  IF ( iloc == element_not_found ) THEN
749  IF ( degrhelp > 0 ) THEN
750  CALL binarysearchinteger(x2cshelp(1:degrhelp),degrhelp, &
751  icg2,iloc)
752 
753  IF ( iloc == element_not_found ) THEN
754  IF ( degrhelp < stencilsizemax ) THEN
755  degrhelp = degrhelp + 1
756  x2cshelp(degrhelp) = icg2
757 
758  IF ( degrhelp > 1 ) THEN
759  CALL quicksortinteger(x2cshelp(1:degrhelp),degrhelp)
760  END IF ! degrHelp
761  ELSE
762  EXIT outerloop
763  END IF ! degrHelp
764  END IF ! iloc
765  ELSE
766  degrhelp = degrhelp + 1
767  x2cshelp(degrhelp) = icg2
768  END IF ! degrHelp
769  END IF ! iloc
770  END IF ! icg2
771 
772  END DO ! iv2c
773  END DO ! ivl
774 
775 ! ------------------------------------------------------------------------------
776 ! Hexahedra
777 ! ------------------------------------------------------------------------------
778 
779  CASE ( cell_type_hex )
780  DO ivl = 1,8
781  ivg = pgrid%hex2v(ivl,icl)
782 
783  DO iv2c = pgrid%v2cInfo(v2c_beg,ivg),pgrid%v2cInfo(v2c_end,ivg)
784  icg2 = pgrid%v2c(iv2c)
785 
786  IF ( icg2 /= ixg ) THEN
787  CALL binarysearchinteger(x2cssort(1:degr),degr,icg2,iloc)
788 
789  IF ( iloc == element_not_found ) THEN
790  IF ( degrhelp > 0 ) THEN
791  CALL binarysearchinteger(x2cshelp(1:degrhelp),degrhelp, &
792  icg2,iloc)
793  IF ( iloc == element_not_found ) THEN
794  IF ( degrhelp < stencilsizemax ) THEN
795  degrhelp = degrhelp + 1
796  x2cshelp(degrhelp) = icg2
797 
798  IF ( degrhelp > 1 ) THEN
799  CALL quicksortinteger(x2cshelp(1:degrhelp),degrhelp)
800  END IF ! degrHelp
801  ELSE
802  EXIT outerloop
803  END IF ! degrHelp
804  END IF ! iloc
805  ELSE
806  degrhelp = degrhelp + 1
807  x2cshelp(degrhelp) = icg2
808  END IF ! degrHelp
809  END IF ! iloc
810  END IF ! icg2
811 
812  END DO ! iv2c
813  END DO ! ivl
814 
815 ! ------------------------------------------------------------------------------
816 ! Prisms
817 ! ------------------------------------------------------------------------------
818 
819  CASE ( cell_type_pri )
820  DO ivl = 1,6
821  ivg = pgrid%pri2v(ivl,icl)
822 
823  DO iv2c = pgrid%v2cInfo(v2c_beg,ivg),pgrid%v2cInfo(v2c_end,ivg)
824  icg2 = pgrid%v2c(iv2c)
825 
826  IF ( icg2 /= ixg ) THEN
827  CALL binarysearchinteger(x2cssort(1:degr),degr,icg2,iloc)
828 
829  IF ( iloc == element_not_found ) THEN
830  IF ( degrhelp > 0 ) THEN
831  CALL binarysearchinteger(x2cshelp(1:degrhelp),degrhelp, &
832  icg2,iloc)
833 
834  IF ( iloc == element_not_found ) THEN
835  IF ( degrhelp < stencilsizemax ) THEN
836  degrhelp = degrhelp + 1
837  x2cshelp(degrhelp) = icg2
838 
839  IF ( degrhelp > 1 ) THEN
840  CALL quicksortinteger(x2cshelp(1:degrhelp),degrhelp)
841  END IF ! degrHelp
842  ELSE
843  EXIT outerloop
844  END IF ! degrHelp
845  END IF ! iloc
846  ELSE
847  degrhelp = degrhelp + 1
848  x2cshelp(degrhelp) = icg2
849  END IF ! degrHelp
850  END IF ! iloc
851  END IF ! icg2
852 
853  END DO ! iv2c
854  END DO ! ivl
855 
856 ! ------------------------------------------------------------------------------
857 ! Pyramids
858 ! ------------------------------------------------------------------------------
859 
860  CASE ( cell_type_pyr )
861  DO ivl = 1,5
862  ivg = pgrid%pyr2v(ivl,icl)
863 
864  DO iv2c = pgrid%v2cInfo(v2c_beg,ivg),pgrid%v2cInfo(v2c_end,ivg)
865  icg2 = pgrid%v2c(iv2c)
866 
867  IF ( icg2 /= ixg ) THEN
868  CALL binarysearchinteger(x2cssort(1:degr),degr,icg2,iloc)
869 
870  IF ( iloc == element_not_found ) THEN
871  IF ( degrhelp > 0 ) THEN
872  CALL binarysearchinteger(x2cshelp(1:degrhelp),degrhelp, &
873  icg2,iloc)
874 
875  IF ( iloc == element_not_found ) THEN
876  IF ( degrhelp < stencilsizemax ) THEN
877  degrhelp = degrhelp + 1
878  x2cshelp(degrhelp) = icg2
879 
880  IF ( degrhelp > 1 ) THEN
881  CALL quicksortinteger(x2cshelp(1:degrhelp),degrhelp)
882  END IF ! degrHelp
883  ELSE
884  EXIT outerloop
885  END IF ! degrHelp
886  END IF ! iloc
887  ELSE
888  degrhelp = degrhelp + 1
889  x2cshelp(degrhelp) = icg2
890  END IF ! degrHelp
891  END IF ! iloc
892  END IF ! icg2
893 
894  END DO ! iv2c
895  END DO ! ivl
896 
897 ! ------------------------------------------------------------------------------
898 ! Default
899 ! ------------------------------------------------------------------------------
900 
901  CASE default
902  CALL errorstop(global,err_reached_default,__line__)
903  END SELECT ! ict
904  END DO outerloop
905 
906 ! ******************************************************************************
907 ! Merge new layer with existing stencil
908 ! ******************************************************************************
909 
910  DO isl = 1,degrhelp
911  IF ( degr < stencilsizemax ) THEN
912  degr = degr + 1
913  x2cs(degr) = x2cshelp(isl)
914  END IF ! degr
915  END DO ! isl
916 
917 ! ******************************************************************************
918 ! End
919 ! ******************************************************************************
920 
921  CALL deregisterfunction(global)
922 
923  END SUBROUTINE rflu_addcelllayer
924 
925 
926 
927 
928 
929 
930 ! ******************************************************************************
931 !
932 ! Purpose: Construct initial stencil by adding cells sharing vertices which
933 ! define face.
934 !
935 ! Description: None.
936 !
937 ! Input:
938 ! global Pointer to global data
939 ! pGrid Pointer to grid
940 ! stencilSizeMax Maximum allowed size of stencil
941 ! f2v List of vertices which define face
942 !
943 ! Output:
944 ! degr Number of cells sharing vertices defining face
945 ! x2cs List of cells sharing vertices defining face
946 !
947 ! Notes:
948 ! 1. It is assumed that there are no members in the stencil when this
949 ! routine is called.
950 !
951 ! ******************************************************************************
952 
953  SUBROUTINE rflu_addfacevertneighbs(global,pGrid,stencilSizeMax,f2v,degr, &
954  x2cs)
955 
956  IMPLICIT NONE
957 
958 ! ******************************************************************************
959 ! Declarations and definitions
960 ! ******************************************************************************
961 
962 ! ==============================================================================
963 ! Arguments
964 ! ==============================================================================
965 
966  INTEGER, INTENT(IN) :: stencilsizemax
967  INTEGER, INTENT(IN) :: f2v(4)
968  INTEGER, INTENT(INOUT) :: degr
969  INTEGER, INTENT(INOUT) :: x2cs(stencilsizemax)
970  TYPE(t_global), POINTER :: global
971  TYPE(t_grid), POINTER :: pgrid
972 
973 ! ==============================================================================
974 ! Locals
975 ! ==============================================================================
976 
977  INTEGER :: icg,iloc,ivg,ivl,ivl2
978 
979 ! ******************************************************************************
980 ! Start
981 ! ******************************************************************************
982 
983  CALL registerfunction(global,'RFLU_AddFaceVertNeighbs',&
984  'RFLU_ModStencilsUtils.F90')
985 
986 ! ******************************************************************************
987 ! Add layer of cells to existing stencil, store in separate array
988 ! ******************************************************************************
989 
990 ! ==============================================================================
991 ! Initialize
992 ! ==============================================================================
993 
994  degr = 0
995 
996 ! ==============================================================================
997 ! Loop over vertices of face and add cells
998 ! ==============================================================================
999 
1000  outerloop: DO ivl = 1,4
1001  ivg = f2v(ivl)
1002 
1003  IF ( ivg /= vert_none ) THEN
1004 
1005  DO ivl2 = pgrid%v2cInfo(v2c_beg,ivg),pgrid%v2cInfo(v2c_end,ivg)
1006  icg = pgrid%v2c(ivl2)
1007 
1008  IF ( degr /= 0 ) THEN
1009  CALL binarysearchinteger(x2cs(1:degr),degr,icg,iloc)
1010 
1011  IF ( iloc == element_not_found ) THEN
1012  IF ( degr < stencilsizemax ) THEN
1013  degr = degr + 1
1014  x2cs(degr) = icg
1015 
1016  IF ( degr > 1 ) THEN
1017  CALL quicksortinteger(x2cs(1:degr),degr)
1018  END IF ! degr
1019  ELSE
1020  EXIT outerloop
1021  END IF ! degr
1022  END IF ! iloc
1023  ELSE
1024  degr = degr + 1
1025 
1026  x2cs(degr) = icg
1027  END IF ! degr
1028  END DO ! ivl2
1029 
1030  END IF ! ivg
1031  END DO outerloop
1032 
1033 ! ******************************************************************************
1034 ! End
1035 ! ******************************************************************************
1036 
1037  CALL deregisterfunction(global)
1038 
1039  END SUBROUTINE rflu_addfacevertneighbs
1040 
1041 
1042 
1043 
1044 
1045 
1046 ! *******************************************************************************
1047 !
1048 ! Purpose: Compute stencil size for given order.
1049 !
1050 ! Description: None.
1051 !
1052 ! Input:
1053 ! global Global pointer
1054 ! dimens Dimensionality
1055 ! factor Safety factor
1056 ! order Polynomial order
1057 !
1058 ! Output:
1059 ! RFLU_ComputeStencilSize (Minimum) number of points in stencil
1060 !
1061 ! Notes:
1062 ! 1. Include additional support (+1) to allow for interpolation.
1063 ! 2. Make larger than necessary to allow for least-squares if order > 1.
1064 ! 3. If order = 0, do not include factor.
1065 !
1066 ! ******************************************************************************
1067 
1068  INTEGER FUNCTION rflu_computestencilsize(global,dimens,factor,order)
1069 
1070  IMPLICIT NONE
1071 
1072 ! ******************************************************************************
1073 ! Declarations and definitions
1074 ! ******************************************************************************
1075 
1076 ! ==============================================================================
1077 ! Arguments
1078 ! ==============================================================================
1079 
1080  INTEGER, INTENT(IN) :: dimens,factor,order
1081  TYPE(t_global), POINTER :: global
1082 
1083 ! ==============================================================================
1084 ! Locals
1085 ! ==============================================================================
1086 
1087  CHARACTER(CHRLEN) :: rcsidentstring
1088 
1089 ! ******************************************************************************
1090 ! Start
1091 ! ******************************************************************************
1092 
1093  CALL registerfunction(global,'RFLU_ComputeStencilSize',&
1094  'RFLU_ModStencilsUtils.F90')
1095 
1096 ! ******************************************************************************
1097 ! Compute stencil size
1098 ! ******************************************************************************
1099 
1100  IF ( order > 0 ) THEN
1101  SELECT CASE ( dimens )
1102  CASE ( 2 )
1103  rflu_computestencilsize = factor*(order + 1)*(order + 2)/2
1104  CASE ( 3 )
1105  rflu_computestencilsize = factor*(order + 1)*(order + 2)*(order + 3)/6
1106  CASE default
1107  CALL errorstop(global,err_dimens_invalid,__line__)
1108  END SELECT ! dimens
1109  ELSE
1111  END IF ! order
1112 
1113 ! ******************************************************************************
1114 ! End
1115 ! ******************************************************************************
1116 
1117  CALL deregisterfunction(global)
1118 
1119  END FUNCTION rflu_computestencilsize
1120 
1121 
1122 
1123 
1124 
1125 
1126 ! ******************************************************************************
1127 !
1128 ! Purpose: Compute stencil weights.
1129 !
1130 ! Description: Compute stencil weights in iterative fashion. If weights are
1131 ! rejected, requested order is lowered and the weights are recomputed. Once
1132 ! order is equal to zero, the weights are set instead of computed.
1133 !
1134 ! Input:
1135 ! global Global pointer
1136 ! dimens Dimensionality
1137 ! wtsMode Mode of computing weights
1138 ! scalMode Mode of scaling
1139 ! derivDegree Degree of derivative (0 = interpolation)
1140 ! order Order of accuracy of approximation
1141 ! nRows Number of members in stencil
1142 ! dr Relative position vectors of members in stencil
1143 !
1144 ! Output:
1145 ! orderNominal Order of accuracy of approximation
1146 ! wts Stencil weights
1147 ! sCount Number of singular values
1148 !
1149 ! Notes:
1150 ! 1. It is important to note that the order is the polynomial order of
1151 ! approximation, that is, order equal to 1 means a linear polynomial
1152 ! which may be first- or second-order accurate...
1153 ! 2. Still need to check for singular systems because although initial
1154 ! stencils ought to be non-singular, they may become singular with grid
1155 ! motion.
1156 ! 3. Although this is a routine to compute weights, it is not located in the
1157 ! module RFLU_ComputeWeights, because it requires the function
1158 ! RFLU_ComputeStencilSize, and this leads to a circular dependency:
1159 ! RFLU_ModWeights depends on RFLU_ModStencils (because of
1160 ! RFLU_ComputeStencilSize), and RFLU_ModStencils depends on
1161 ! RFLU_ModWeights (because of RFLU_ComputeStencilWeights)
1162 !
1163 ! ******************************************************************************
1164 
1165  SUBROUTINE rflu_computestencilweights(global,dimens,wtsMode,scalMode, &
1166  derivdegree,ordernominal,nrows,dr, &
1167  wts,scount)
1168 
1169  USE modtools, ONLY: compfact
1170 
1172 
1173  IMPLICIT NONE
1174 
1175 ! ******************************************************************************
1176 ! Declarations and definitions
1177 ! ******************************************************************************
1178 
1179 ! ==============================================================================
1180 ! Arguments
1181 ! ==============================================================================
1182 
1183  INTEGER, INTENT(IN) :: derivdegree,dimens,nrows,scalmode,wtsmode
1184  INTEGER, INTENT(IN) :: ordernominal
1185  INTEGER, INTENT(OUT), OPTIONAL :: scount
1186  REAL(RFREAL), INTENT(IN) :: dr(xcoord:zcoord,nrows)
1187  REAL(RFREAL), INTENT(OUT) :: wts(:,:)
1188  TYPE(t_global), POINTER :: global
1189 
1190 ! ==============================================================================
1191 ! Locals
1192 ! ==============================================================================
1193 
1194  CHARACTER(CHRLEN) :: rcsidentstring
1195  INTEGER :: errorflag,isl,j,ncols,order,p,q,r
1196  REAL(RFREAL) :: colscal,term,wtsnorm,wtsnormmax,wtsnormmin
1197  REAL(RFREAL) :: rowscal(nrows)
1198  REAL(RFREAL) :: drcopy(xcoord:zcoord,nrows)
1199  REAL(RFREAL), DIMENSION(:,:), ALLOCATABLE :: a,ainv
1200 
1201 ! ******************************************************************************
1202 ! Start
1203 ! ******************************************************************************
1204 
1205  CALL registerfunction(global,'RFLU_ComputeStencilWeights',&
1206  'RFLU_ModStencilsUtils.F90')
1207 
1208  wtsnormmin = 1.0_rfreal
1209  wtsnormmax = 10.0_rfreal
1210 
1211 ! ******************************************************************************
1212 ! Check that stencil large enough, reduce order if necessary
1213 ! ******************************************************************************
1214 
1215  IF ( nrows < rflu_computestencilsize(global,dimens,1,ordernominal) ) THEN
1216  SELECT CASE ( dimens )
1217  CASE ( 2 )
1218  SELECT CASE ( nrows )
1219  CASE ( 0:2 ) ! Constant
1220  order = 0
1221  CASE ( 3:5 ) ! Linear
1222  order = 1
1223  CASE ( 6:9 ) ! Quadratic
1224  order = 2
1225  CASE ( 10:14 ) ! Cubic
1226  order = 3
1227  CASE default ! More than cubic
1228  CALL errorstop(global,err_reached_default,__line__)
1229  END SELECT ! nRows
1230  CASE ( 3 )
1231  SELECT CASE ( nrows )
1232  CASE ( 0:3 ) ! Constant
1233  order = 0
1234  CASE ( 4:9 ) ! Linear
1235  order = 1
1236  CASE ( 10:19 ) ! Quadratic
1237  order = 2
1238  CASE ( 20:34 ) ! Cubic
1239  order = 3
1240  CASE default ! More than cubic
1241  CALL errorstop(global,err_reached_default,__line__)
1242  END SELECT ! nRows
1243  CASE default
1244  CALL errorstop(global,err_reached_default,__line__)
1245  END SELECT ! dimens
1246  ELSE
1247  order = ordernominal
1248  END IF ! nRowsEff
1249 
1250 ! ******************************************************************************
1251 ! Row scaling
1252 ! ******************************************************************************
1253 
1254  IF ( scalmode == compwts_scal_none ) THEN
1255  DO isl = 1,nrows
1256  rowscal(isl) = 1.0_rfreal
1257  END DO ! isl
1258  ELSE IF ( scalmode == compwts_scal_invdist ) THEN
1259  DO isl = 1,nrows
1260  rowscal(isl) = 1.0_rfreal/sqrt(dr(xcoord,isl)*dr(xcoord,isl) &
1261  + dr(ycoord,isl)*dr(ycoord,isl) &
1262  + dr(zcoord,isl)*dr(zcoord,isl))
1263  END DO ! isl
1264  ELSE
1265  CALL errorstop(global,err_reached_default,__line__)
1266  END IF ! scalMode
1267 
1268 ! ******************************************************************************
1269 ! Column scaling
1270 ! ******************************************************************************
1271 
1272  colscal = maxval(abs(dr(xcoord:zcoord,1:nrows)))
1273 
1274  DO isl = 1,nrows
1275  drcopy(xcoord,isl) = dr(xcoord,isl)/colscal
1276  drcopy(ycoord,isl) = dr(ycoord,isl)/colscal
1277  drcopy(zcoord,isl) = dr(zcoord,isl)/colscal
1278  END DO ! isl
1279 
1280 ! ******************************************************************************
1281 ! Compute weights iteratively
1282 ! ******************************************************************************
1283 
1284  DO
1285 
1286 ! ==============================================================================
1287 ! Order greater than zero, so compute weights
1288 ! ==============================================================================
1289 
1290  IF ( order > 0 ) THEN
1291  ncols = rflu_computestencilsize(global,dimens,1,order)
1292 
1293 ! ------------------------------------------------------------------------------
1294 ! Allocate temporary memory
1295 ! ------------------------------------------------------------------------------
1296 
1297  ALLOCATE(a(nrows,ncols),stat=errorflag)
1298  global%error = errorflag
1299  IF ( global%error /= err_none ) THEN
1300  CALL errorstop(global,err_allocate,__line__,'a')
1301  END IF ! global%error
1302 
1303  ALLOCATE(ainv(ncols,nrows),stat=errorflag)
1304  global%error = errorflag
1305  IF ( global%error /= err_none ) THEN
1306  CALL errorstop(global,err_allocate,__line__,'aInv')
1307  END IF ! global%error
1308 
1309 ! ------------------------------------------------------------------------------
1310 ! Build matrix
1311 ! ------------------------------------------------------------------------------
1312 
1313  SELECT CASE ( dimens )
1314  CASE ( 2 )
1315  DO isl = 1,nrows
1316  a(isl,1) = rowscal(isl)
1317 
1318  j = 2
1319 
1320  DO p = 1,order
1321  DO q = 0,p
1322  term = rowscal(isl)/(compfact(p-q)*compfact(q))
1323  a(isl,j) = term*drcopy(xcoord,isl)**(p-q) &
1324  *drcopy(ycoord,isl)**q
1325  j = j + 1
1326  END DO ! q
1327  END DO ! p
1328  END DO ! isl
1329  CASE ( 3 )
1330  DO isl = 1,nrows
1331  a(isl,1) = rowscal(isl)
1332 
1333  j = 2
1334 
1335  DO p = 1,order
1336  DO q = 0,p
1337  DO r = 0,q
1338  term = rowscal(isl)/(compfact(p-q)*compfact(q-r)*compfact(r))
1339  a(isl,j) = term*drcopy(xcoord,isl)**(p-q) &
1340  *drcopy(ycoord,isl)**(q-r) &
1341  *drcopy(zcoord,isl)**r
1342  j = j + 1
1343  END DO ! r
1344  END DO ! q
1345  END DO ! p
1346  END DO ! isl
1347  CASE default
1348  CALL errorstop(global,err_reached_default,__line__)
1349  END SELECT ! dimens
1350 
1351 ! ------------------------------------------------------------------------------
1352 ! Invert matrix
1353 ! ------------------------------------------------------------------------------
1354 
1355  CALL rflu_invertmatrixsvd(global,nrows,ncols,a,ainv,scount)
1356 
1357 ! ------------------------------------------------------------------------------
1358 ! Extract weights from inverse. NOTE appearance of scalings.
1359 ! ------------------------------------------------------------------------------
1360 
1361  IF ( derivdegree == deriv_degree_0 ) THEN
1362  DO isl = 1,nrows
1363  wts(1,isl) = rowscal(isl)*ainv(1,isl)
1364  END DO ! isl
1365  ELSE IF ( derivdegree == deriv_degree_1 ) THEN
1366  SELECT CASE ( dimens )
1367  CASE ( 2 )
1368  DO isl = 1,nrows
1369  wts(xcoord,isl) = rowscal(isl)*ainv(2,isl)/colscal
1370  wts(ycoord,isl) = rowscal(isl)*ainv(3,isl)/colscal
1371  wts(zcoord,isl) = 0.0_rfreal
1372  END DO ! isl
1373  CASE ( 3 )
1374  DO isl = 1,nrows
1375  wts(xcoord,isl) = rowscal(isl)*ainv(2,isl)/colscal
1376  wts(ycoord,isl) = rowscal(isl)*ainv(3,isl)/colscal
1377  wts(zcoord,isl) = rowscal(isl)*ainv(4,isl)/colscal
1378  END DO ! isl
1379  CASE default
1380  CALL errorstop(global,err_reached_default,__line__)
1381  END SELECT ! dimens
1382  ELSE
1383  CALL errorstop(global,err_reached_default,__line__)
1384  END IF ! derivDegree
1385 
1386 ! ------------------------------------------------------------------------------
1387 ! Check whether weights make sense
1388 ! ------------------------------------------------------------------------------
1389 
1390  wtsnorm = 0.0_rfreal
1391 
1392  DO isl = 1,nrows
1393  wtsnorm = wtsnorm + abs(ainv(1,isl))
1394  END DO ! isl
1395 
1396 ! ------------------------------------------------------------------------------
1397 ! Deallocate temporary memory
1398 ! ------------------------------------------------------------------------------
1399 
1400  DEALLOCATE(a,stat=errorflag)
1401  global%error = errorflag
1402  IF ( global%error /= err_none ) THEN
1403  CALL errorstop(global,err_deallocate,__line__,'a')
1404  END IF ! global%error
1405 
1406  DEALLOCATE(ainv,stat=errorflag)
1407  global%error = errorflag
1408  IF ( global%error /= err_none ) THEN
1409  CALL errorstop(global,err_deallocate,__line__,'aInv')
1410  END IF ! global%error
1411 
1412 ! ------------------------------------------------------------------------------
1413 ! Decide whether to accept or reject weights
1414 ! ------------------------------------------------------------------------------
1415 
1416  IF ( scount == 0 .AND. &
1417  wtsnorm > wtsnormmin .AND. wtsnorm < wtsnormmax ) THEN
1418  EXIT
1419  ELSE
1420  IF ( wtsmode == compwts_mode_adapt ) THEN
1421  order = order - 1
1422  ELSE
1423  EXIT
1424  END IF ! wtsMode
1425  END IF ! errNorm
1426 
1427 ! ==============================================================================
1428 ! Order equal to zero, so set weights
1429 ! ==============================================================================
1430 
1431  ELSE
1432  IF ( derivdegree == deriv_degree_0 ) THEN
1433  DO isl = 1,nrows
1434  wts(1,isl) = 1.0_rfreal/REAL(nRows,KIND=RFREAL)
1435  END DO ! isl
1436  ELSE IF ( derivdegree == deriv_degree_1 ) THEN
1437  DO isl = 1,nrows
1438  wts(xcoord,isl) = 0.0_rfreal
1439  wts(ycoord,isl) = 0.0_rfreal
1440  wts(zcoord,isl) = 0.0_rfreal
1441  END DO ! isl
1442  ELSE
1443  CALL errorstop(global,err_reached_default,__line__)
1444  END IF ! derivDegree
1445 
1446  EXIT
1447  END IF ! order
1448  END DO ! <empty>
1449 
1450 ! ******************************************************************************
1451 ! End
1452 ! ******************************************************************************
1453 
1454  CALL deregisterfunction(global)
1455 
1456  END SUBROUTINE rflu_computestencilweights
1457 
1458 
1459 
1460 
1461 
1462 
1463 
1464 ! ******************************************************************************
1465 !
1466 ! Purpose: Sort boundary faces by increasing distance from location at which
1467 ! gradient is reconstructed.
1468 !
1469 ! Description: None.
1470 !
1471 ! Input:
1472 ! pRegion Pointer to region
1473 ! xyz Coordinates at which gradient is reconstructed
1474 ! nBFaceMembs Number of boundary face stencil members
1475 ! bFaceMembs Boundary face stencil members
1476 !
1477 ! Output:
1478 ! bFaceMembs Boundary face stencil members
1479 !
1480 ! Notes: None.
1481 !
1482 ! ******************************************************************************
1483 
1484  SUBROUTINE rflu_sortbfaces(pRegion,xyz,nBFaceMembs,bFaceMembs)
1485 
1486  IMPLICIT NONE
1487 
1488 ! ******************************************************************************
1489 ! Declarations and definitions
1490 ! ******************************************************************************
1491 
1492 ! ==============================================================================
1493 ! Arguments
1494 ! ==============================================================================
1495 
1496  INTEGER, INTENT(IN) :: nbfacemembs
1497  INTEGER, INTENT(INOUT) :: bfacemembs(2,nbfacemembs)
1498  REAL(RFREAL), INTENT(IN) :: xyz(xcoord:zcoord)
1499  TYPE(t_region), POINTER :: pregion
1500 
1501 ! ==============================================================================
1502 ! Locals
1503 ! ==============================================================================
1504 
1505  INTEGER :: ifl,ipatch,isl
1506  INTEGER :: key(nbfacemembs)
1507  INTEGER :: bfacemembsbak(2,nbfacemembs)
1508  REAL(RFREAL) :: dist(nbfacemembs)
1509  TYPE(t_global), POINTER :: global
1510  TYPE(t_grid), POINTER :: pgrid
1511  TYPE(t_patch), POINTER :: ppatch
1512 
1513 ! ******************************************************************************
1514 ! Set pointers and variables
1515 ! ******************************************************************************
1516 
1517  global => pregion%global
1518  pgrid => pregion%grid
1519 
1520 ! ******************************************************************************
1521 ! Start
1522 ! ******************************************************************************
1523 
1524  CALL registerfunction(global,'RFLU_SortBFaces',&
1525  'RFLU_ModStencilsUtils.F90')
1526 
1527 ! ******************************************************************************
1528 ! Back up data structure so can copy later on
1529 ! ******************************************************************************
1530 
1531  DO isl = 1,nbfacemembs
1532  bfacemembsbak(1,isl) = bfacemembs(1,isl)
1533  bfacemembsbak(2,isl) = bfacemembs(2,isl)
1534  END DO ! isl
1535 
1536 ! ******************************************************************************
1537 ! Compute squared distance and build key for sorting
1538 ! ******************************************************************************
1539 
1540  DO isl = 1,nbfacemembs
1541  ipatch = bfacemembs(1,isl)
1542  ifl = bfacemembs(2,isl)
1543 
1544  ppatch => pregion%patches(ipatch)
1545 
1546  key(isl) = isl
1547  dist(isl) = (ppatch%fc(xcoord,ifl) - xyz(xcoord))**2 &
1548  + (ppatch%fc(ycoord,ifl) - xyz(ycoord))**2 &
1549  + (ppatch%fc(zcoord,ifl) - xyz(zcoord))**2
1550  END DO ! isl
1551 
1552 ! ******************************************************************************
1553 ! Sort according to increasing distance
1554 ! ******************************************************************************
1555 
1556  CALL quicksortrfrealinteger(dist,key,nbfacemembs)
1557 
1558  DO isl = 1,nbfacemembs
1559  bfacemembs(1,isl) = bfacemembsbak(1,key(isl))
1560  bfacemembs(2,isl) = bfacemembsbak(2,key(isl))
1561  END DO ! isl
1562 
1563 ! ******************************************************************************
1564 ! End
1565 ! ******************************************************************************
1566 
1567  CALL deregisterfunction(global)
1568 
1569  END SUBROUTINE rflu_sortbfaces
1570 
1571 
1572 
1573 
1574 
1575 ! ******************************************************************************
1576 ! End
1577 ! ******************************************************************************
1578 
1579 END MODULE rflu_modstencilsutils
1580 
1581 
1582 ! ******************************************************************************
1583 !
1584 ! RCS Revision history:
1585 !
1586 ! $Log: RFLU_ModStencilsUtils.F90,v $
1587 ! Revision 1.14 2008/12/06 08:44:24 mtcampbe
1588 ! Updated license.
1589 !
1590 ! Revision 1.13 2008/11/19 22:17:35 mtcampbe
1591 ! Added Illinois Open Source License/Copyright
1592 !
1593 ! Revision 1.12 2007/03/06 18:08:37 haselbac
1594 ! Added function to add cell layer in 1d based on geometry (not on hex2f)
1595 !
1596 ! Revision 1.11 2006/04/07 15:19:20 haselbac
1597 ! Removed tabs
1598 !
1599 ! Revision 1.10 2006/04/01 15:56:37 haselbac
1600 ! Bug fix: Only add bfaces if have actual faces
1601 !
1602 ! Revision 1.9 2006/03/25 21:57:59 haselbac
1603 ! Changed bf2cSorted list to contain only actual entries (bcos of sype changes)
1604 !
1605 ! Revision 1.8 2006/01/06 22:14:15 haselbac
1606 ! Added new routine for adding cell layer in 1d
1607 !
1608 ! Revision 1.7 2005/10/09 13:27:18 haselbac
1609 ! Temporarily disable addition of v bfaces to stencils
1610 !
1611 ! Revision 1.6 2005/10/05 14:10:01 haselbac
1612 ! Added routines which used to be in RFLU_ModStencils
1613 !
1614 ! Revision 1.5 2005/04/15 15:07:05 haselbac
1615 ! Added routines to build and destroy c2c stencil in CSR format
1616 !
1617 ! Revision 1.4 2004/12/29 21:09:44 haselbac
1618 ! Cosmetics only
1619 !
1620 ! Revision 1.3 2004/01/22 16:03:59 haselbac
1621 ! Made contents of modules PRIVATE, only procs PUBLIC, to avoid errors on ALC
1622 ! and titan
1623 !
1624 ! Revision 1.2 2003/12/05 16:53:11 haselbac
1625 ! Added cell-to-cell CSR routines for parallel higher-order scheme
1626 !
1627 ! Revision 1.1 2003/12/04 03:29:22 haselbac
1628 ! Initial revision
1629 !
1630 ! ******************************************************************************
1631 
1632 
1633 
1634 
1635 
1636 
1637 
1638 
1639 
1640 
1641 
1642 
1643 
1644 
subroutine, public rflu_computestencilweights(global, dimens, wtsMode, scalMode, derivDegree, orderNominal, nRows, dr, wts, sCount)
unsigned char r() const
Definition: Color.h:68
subroutine, public rflu_addcelllayer(global, pGrid, stencilSizeMax, ixg, degr, x2csBeg, x2csEnd, x2cs)
INTEGER function compfact(n)
Definition: ModTools.F90:156
subroutine, public rflu_addcelllayer_1d(global, pGrid, stencilSizeMax, ixg, degr, x2csBeg, x2csEnd, x2cs, fnDir)
subroutine ainv(ajac, ajacin, det, ndim)
Definition: ainv.f90:53
Size order() const
Degree of the element. 1 for linear and 2 for quadratic.
subroutine rflu_invertmatrixsvd(global, nRows, nCols, a, aInv, sCount)
subroutine registerfunction(global, funName, fileName)
Definition: ModError.F90:449
double sqrt(double d)
Definition: double.h:73
subroutine quicksortinteger(a, n)
subroutine binarysearchinteger(a, n, v, i, j)
subroutine, public rflu_addfacevertneighbs(global, pGrid, stencilSizeMax, f2v, degr, x2cs)
LOGICAL function, public rflu_testvectorcartaxisaligned(global, dr, dir)
subroutine, public rflu_addbfaces(pRegion, nBFaceMembsMaxTemp, nCellMembs, cellMembs, nBFaceMembs, bFaceMembs)
IndexType nfaces() const
Definition: Mesh.H:641
INTEGER function rflu_computestencilsize(global, factor, order)
subroutine quicksortrfrealinteger(a, b, n)
subroutine, public rflu_addcelllayer_1d_g(global, pGrid, stencilSizeMax, ixg, degr, x2csBeg, x2csEnd, x2cs, rc, dir)
subroutine, public rflu_sortbfaces(pRegion, xyz, nBFaceMembs, bFaceMembs)
j indices j
Definition: Indexing.h:6
NT q
subroutine errorstop(global, errorCode, errorLine, addMessage)
Definition: ModError.F90:483
vector3d dir(void) const
Definition: vector3d.h:144
long double dist(long double *coord1, long double *coord2, int size)
static T_Key key
Definition: vinci_lass.c:76
subroutine deregisterfunction(global)
Definition: ModError.F90:469
INTEGER function, public rflu_getglobalcelltype(global, pGrid, icg)
RT a() const
Definition: Line_2.h:140