-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathHexMesh.f90
More file actions
6094 lines (5443 loc) · 238 KB
/
Copy pathHexMesh.f90
File metadata and controls
6094 lines (5443 loc) · 238 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "Includes.h"
MODULE HexMeshClass
use Utilities , only: toLower, almostEqual, AlmostEqualRelax, sortDescendInt, sortAscendInt
use SMConstants
USE MeshTypes
USE NodeClass
USE ElementClass
USE FaceClass
use FacePatchClass
USE TransfiniteMapClass
use SharedBCModule
use ElementConnectivityDefinitions
use ZoneClass , only: Zone_t, ConstructZones, ReassignZones
use PhysicsStorage
use NodalStorageClass
use MPI_Process_Info
use MPI_Face_Class
use FluidData
use StorageClass
use FileReadingUtilities , only: RemovePath, getFileName
use FTValueDictionaryClass , only: FTValueDictionary
use SolutionFile
use BoundaryConditions, only: BCs
use IntegerDataLinkedList , only: IntegerDataLinkedList_t
use PartitionedMeshClass , only: mpi_partition
use IBMClass
#if defined(NAVIERSTOKES)
use WallDistance
#endif
#ifdef _HAS_MPI_
use mpi
#endif
IMPLICIT NONE
private
public HexMesh
public Neighbor_t, NUM_OF_NEIGHBORS
public MultiLevel_RK
public GetOriginalNumberOfFaces
public ConstructFaces, ConstructPeriodicFaces
public DeletePeriodicMinusFaces, GetElementsFaceIDs
public no_of_stats_variables
!
! ---------------
! Mesh definition
! ---------------
!
type MultiLevel_RK
integer :: nLevel
integer :: maxLevel
real(kind=RP) :: CFL_CutOff
integer, allocatable :: ML_GlobalLevel(:) ! Number of Multi-Level Timestep Element - Global - in TimeIntegrator.f90 and DGSEMClass.f90
integer, allocatable :: ML_Level(:) ! Number of Multi-Level Timestep Element - Partition
integer, allocatable :: MLIter(:,:) ! Number of ML Iteration - partition (L1 include L2 & L3, etc); size(nLevel, 6(eID, fID, fID_Inter, fID Bound, eID Seq, eID MPI))
integer, allocatable :: MLIter_eID(:) ! Sorted Element ID from nLevel to Level 1 (eID) size is (mesh%element)
integer, allocatable :: MLIter_fID(:) ! Element ID for each level iteration (fID) size is (mesh% faces)
integer, allocatable :: MLIter_fID_Interior(:) ! Interior Face ID for each level iteration (fID) size is (mesh%faces_interior)
integer, allocatable :: MLIter_fID_Boundary(:) ! Boundary Face ID for each level 1 iteration (fID) size is (mesh%faces_boundary)
integer, allocatable :: MLIter_fID_MPI(:) ! MPI Face ID for each level 1 iteration (fID) size is (mesh%faces_mpi)
integer, allocatable :: MLIter_eID_Seq(:) ! Element ID for each level 1 iteration (eID,levelIteration) size is (mesh%element,nLevel)
integer, allocatable :: MLIter_eID_MPI(:) ! Element ID for each level 1 iteration (eID,levelIteration) size is (mesh%element,nLevel)
integer, allocatable :: MLIter_eIDN(:) ! Sorted Element ID from nLevel to Level 1 (eID) size is (mesh%element)
integer, allocatable :: MLIter_eIDN_Seq(:) ! Element ID for each level 1 iteration (eID,levelIteration) size is (mesh%element,nLevel)
integer, allocatable :: MLIter_eIDN_MPI(:) ! Element ID for each level 1 iteration (eID,levelIteration) size is (mesh%element,nLevel)
contains
procedure :: construct => MultiLevel_RK_Construct
procedure :: update => MultiLevel_RK_Update
procedure :: sendGlobalID => MultiLevel_RK_SendGlobID
procedure :: destruct => MultiLevel_RK_Destruct
end type MultiLevel_RK
type HexMesh
integer :: numberOfFaces
integer :: nodeType
integer :: no_of_elements
integer :: no_of_allElements
integer :: no_of_faces
integer :: dt_restriction = DT_FIXED ! Time step restriction of last step (DT_FIXED -initial value-, DT_DIFF or DT_CONV)
integer , dimension(:), allocatable :: Nx, Ny, Nz
integer :: NDOF
integer, allocatable :: faces_interior(:)
integer, allocatable :: faces_mpi(:)
integer, allocatable :: faces_boundary(:)
integer, allocatable :: elements_sequential(:)
integer, allocatable :: elements_mpi(:)
integer, allocatable :: HOPRnodeIDs(:)
character(len=LINE_LENGTH) :: meshFileName
type(SolutionStorage_t) :: storage ! Here the solution and its derivative are stored
type(Node) , dimension(:), allocatable :: nodes
type(Face) , dimension(:), allocatable :: faces
type(Element), dimension(:), allocatable :: elements
type(MPI_FacesSet_t) :: MPIfaces
type(IBM_type) :: IBM
type(Zone_t), dimension(:), allocatable :: zones
type(MultiLevel_RK) :: MLRK
logical :: child = .FALSE. ! Is this a (multigrid) child mesh? default .FALSE.
logical :: meshIs2D = .FALSE. ! Is this a 2D mesh? default .FALSE.
integer :: dir2D = 0 ! If it is in fact a 2D mesh, dir 2D stores the global direction IX, IY or IZ
integer :: dir2D_ctrl = 0 ! dir2D as in the control file
logical :: anisotropic = .FALSE. ! Is the mesh composed by elements with anisotropic polynomial orders? default false
logical :: ignoreBCnonConformities = .FALSE.
integer, allocatable :: HO_Elements(:) !List of elements with polynomial order greater than 1
integer, allocatable :: LO_Elements(:) !List of elements with polynomial order less or equal than 1
integer, allocatable :: HO_FacesInterior(:) !List of interior faces with polynomial order greater than 1
integer, allocatable :: HO_FacesBoundary(:) !List of boundary faces with polynomial order greater than 1
integer, allocatable :: HO_ElementsMPI(:) !List of MPI elements with polynomial order greater than 1
integer, allocatable :: HO_ElementsSequential(:) !List of sequential elements with polynomial order greater than 1
integer, allocatable :: elements_acoustics(:) !List of elements with acoustic polynomial order adaptation
integer, allocatable :: elements_aerodynamics(:) !List of elements with standard polynomial order adaptation
contains
procedure :: destruct => HexMesh_Destruct
procedure :: Describe => HexMesh_Describe
procedure :: DescribePartition => DescribeMeshPartition
procedure :: AllocateStorage => HexMesh_AllocateStorage
procedure :: ConstructZones => HexMesh_ConstructZones
procedure :: DefineAsBoundaryFaces => HexMesh_DefineAsBoundaryFaces
procedure :: CheckIfMeshIs2D => HexMesh_CheckIfMeshIs2D
procedure :: CorrectOrderFor2DMesh => HexMesh_CorrectOrderFor2DMesh
procedure :: SetConnectivitiesAndLinkFaces => HexMesh_SetConnectivitiesAndLinkFaces
procedure :: UpdateFacesWithPartition => HexMesh_UpdateFacesWithPartition
procedure :: ConstructGeometry => HexMesh_ConstructGeometry
procedure :: ProlongSolutionToFaces => HexMesh_ProlongSolutionToFaces
procedure :: ProlongGradientsToFaces => HexMesh_ProlongGradientsToFaces
procedure :: PrepareForIO => HexMesh_PrepareForIO
procedure :: Export => HexMesh_Export
procedure :: ExportOrders => HexMesh_ExportOrders
procedure :: ExportBoundaryMesh => HexMesh_ExportBoundaryMesh
procedure :: SaveSolution => HexMesh_SaveSolution
procedure :: pAdapt => HexMesh_pAdapt
procedure :: pAdapt_MPI => HexMesh_pAdapt_MPI
procedure :: DefineAcousticElements => HexMesh_DefineAcousticElements
procedure :: UpdateHOArrays => HexMesh_UpdateHOArrays
#if defined(NAVIERSTOKES) || defined(INCNS)
procedure :: SaveStatistics => HexMesh_SaveStatistics
procedure :: ResetStatistics => HexMesh_ResetStatistics
#endif
procedure :: LoadSolution => HexMesh_LoadSolution
procedure :: LoadSolutionForRestart => HexMesh_LoadSolutionForRestart
procedure :: WriteCoordFile
#if defined(ACOUSTIC)
procedure :: InitializeBaseFlow => HexMesh_InitializeBaseFlow
procedure :: SetUniformBaseFlow => HexMesh_SetUniformBaseFlow
procedure :: LoadBaseFlowSolution => HexMesh_LoadBaseFlowSolution
procedure :: ProlongBaseSolutionToFaces => HexMesh_ProlongBaseSolutionToFaces
procedure :: UpdateMPIFacesBaseSolution => HexMesh_UpdateMPIFacesBaseSolution
procedure :: GatherMPIFacesBaseSolution => HexMesh_GatherMPIFacesBaseSolution
#endif
procedure :: UpdateMPIFacesPolynomial => HexMesh_UpdateMPIFacesPolynomial
procedure :: UpdateMPIFacesSolution => HexMesh_UpdateMPIFacesSolution
procedure :: UpdateMPIFacesGradients => HexMesh_UpdateMPIFacesGradients
procedure :: UpdateMPIFacesAviscflux => HexMesh_UpdateMPIFacesAviscflux
procedure :: GatherMPIFacesSolution => HexMesh_GatherMPIFacesSolution
procedure :: GatherMPIFacesGradients => HexMesh_GatherMPIFacesGradients
procedure :: GatherMPIFacesAviscFlux => HexMesh_GatherMPIFacesAviscFlux
procedure :: FindPointWithCoords => HexMesh_FindPointWithCoords
procedure :: FindPointWithCoordsInNeighbors=> HexMesh_FindPointWithCoordsInNeighbors
procedure :: ComputeWallDistances => HexMesh_ComputeWallDistances
procedure :: ConformingOnZone => HexMesh_ConformingOnZone
procedure :: SetStorageToEqn => HexMesh_SetStorageToEqn
#if defined(INCNS) && defined(CAHNHILLIARD)
procedure :: ConvertDensityToPhaseFIeld => HexMesh_ConvertDensityToPhaseField
procedure :: ConvertPhaseFieldToDensity => HexMesh_ConvertPhaseFieldToDensity
#endif
procedure :: copy => HexMesh_Assign
generic :: assignment(=) => copy
end type HexMesh
integer, parameter :: NUM_OF_NEIGHBORS = 6 ! Hardcoded: Hexahedral conforming meshes
integer :: no_of_stats_variables
TYPE Neighbor_t ! added to introduce colored computation of numerical Jacobian (is this the best place to define this type??) - only usable for conforming meshes
INTEGER :: elmnt(NUM_OF_NEIGHBORS+1) ! "7" hardcoded for 3D hexahedrals in conforming meshes (the last one is itself)... This definition must change if the code is expected to be more general
END TYPE Neighbor_t
!
! ========
CONTAINS
! ========
!
! -----------
! Destructors
! -----------
!
!////////////////////////////////////////////////////////////////////////
!
SUBROUTINE HexMesh_Destruct( self )
IMPLICIT NONE
CLASS(HexMesh) :: self
safedeallocate (self % Nx)
safedeallocate (self % Ny)
safedeallocate (self % Nz)
!
! -----
! Nodes
! -----
!
call self % nodes % destruct
DEALLOCATE( self % nodes )
safedeallocate (self % HOPRnodeIDs)
!
! --------
! Elements
! --------
!
call self % elements % destruct
DEALLOCATE( self % elements )
!
! -----
! Faces
! -----
!
call self % faces % Destruct
DEALLOCATE( self % faces )
!
! -----
! Zones
! -----
!
if (allocated(self % zones)) DEALLOCATE( self % zones )
!
! ----------------
! Solution storage
! ----------------
!
call self % storage % destruct
!
! --------
! MPIfaces
! --------
!
#ifdef _HAS_MPI_
if ( MPI_Process % doMPIAction ) then
call DestructMPIFaces( self % MPIfaces)
end if
#endif
safedeallocate(self % elements_sequential)
safedeallocate(self % elements_mpi)
safedeallocate(self % faces_interior)
safedeallocate(self % faces_mpi)
safedeallocate(self % faces_boundary)
safedeallocate(self % HO_Elements)
safedeallocate(self % LO_Elements)
safedeallocate(self % HO_FacesInterior)
safedeallocate(self % HO_FacesBoundary)
safedeallocate(self % HO_ElementsMPI)
safedeallocate(self % HO_ElementsSequential)
!
! ----------------
! IBM storage
! ----------------
!
if( self% IBM% active ) then
if( self% child ) then
call self% IBM% destruct( .true. )
else
call self% IBM% destruct( .false. )
end if
end if
!
! ----------------
! MLRK Library
! ----------------
!
call self % MLRK % destruct
END SUBROUTINE HexMesh_Destruct
!
! -------------
! Print methods
! -------------
!
!////////////////////////////////////////////////////////////////////////
!
SUBROUTINE PrintMesh( self )
IMPLICIT NONE
TYPE(HexMesh) :: self
INTEGER :: k
PRINT *, "Nodes..."
DO k = 1, SIZE(self % nodes)
CALL PrintNode( self % nodes(k), k )
END DO
PRINT *, "Elements..."
DO k = 1, SIZE(self % elements)
CALL PrintElement( self % elements(k), k )
END DO
PRINT *, "Faces..."
DO k = 1, SIZE(self % faces)
CALL self % faces(k) % Print
END DO
END SUBROUTINE PrintMesh
!
!////////////////////////////////////////////////////////////////////////
!
integer function GetOriginalNumberOfFaces(self)
USE FTMultiIndexTableClass
USE FTValueClass
IMPLICIT NONE
TYPE(HexMesh) :: self
INTEGER :: eID, faceNumber
INTEGER :: faceID
INTEGER :: nodeIDs(8), faceNodeIDs(4), j
CLASS(FTMultiIndexTable), POINTER :: table
CLASS(FTObject), POINTER :: obj
CLASS(FTValue) , POINTER :: v
ALLOCATE(table)
CALL table % initWithSize( SIZE( self % nodes) )
GetOriginalNumberOfFaces = 0
DO eID = 1, SIZE( self % elements )
nodeIDs = self % elements(eID) % nodeIDs
DO faceNumber = 1, 6
DO j = 1, 4
faceNodeIDs(j) = nodeIDs(localFaceNode(j,faceNumber))
END DO
IF (.not. table % containsKeys(faceNodeIDs) ) THEN
GetOriginalNumberOfFaces = GetOriginalNumberOfFaces + 1
ALLOCATE(v)
CALL v % initWithValue(GetOriginalNumberOfFaces)
obj => v
CALL table % addObjectForKeys(obj,faceNodeIDs)
CALL release(v)
END IF
END DO
END DO
CALL release(table)
end function GetOriginalNumberOfFaces
SUBROUTINE ConstructFaces( self, success )
!
! -------------------------------------------------------------
! Go through the elements and find the unique faces in the mesh
! -------------------------------------------------------------
!
use IntegerArrayLinkedListTable
IMPLICIT NONE
TYPE(HexMesh) :: self
LOGICAL :: success
INTEGER :: eID, faceNumber
INTEGER :: faceID
INTEGER :: nodeIDs(8), faceNodeIDs(4), j
type(Table_t) :: table
table = Table_t(size(self % nodes))
self % numberOfFaces = 0
DO eID = 1, SIZE( self % elements )
nodeIDs = self % elements(eID) % nodeIDs
DO faceNumber = 1, 6
DO j = 1, 4
faceNodeIDs(j) = nodeIDs(localFaceNode(j,faceNumber))
END DO
faceID = table % ContainsEntry(faceNodeIDs)
IF ( faceID .ne. 0 ) THEN
!
! --------------------------------------------------------------
! Add this element to the slave side of the face associated with
! these nodes.
! --------------------------------------------------------------
!
self % faces(faceID) % elementIDs(2) = eID
self % faces(faceID) % elementSide(2) = faceNumber
self % faces(faceID) % FaceType = HMESH_INTERIOR
self % faces(faceID) % rotation = faceRotation(masterNodeIDs = self % faces(faceID) % nodeIDs, &
slaveNodeIDs = faceNodeIDs )
ELSE
!
! ------------------
! Construct new face
! ------------------
!
self % numberOfFaces = self % numberOfFaces + 1
IF(self % numberOfFaces > SIZE(self % faces)) THEN
call table % Destruct
PRINT *, "Too many faces for # of elements:", self % numberOfFaces, " vs ", SIZE(self % faces)
success = .FALSE.
RETURN
END IF
CALL self % faces(self % numberOfFaces) % Construct(ID = self % numberOfFaces, &
nodeIDs = faceNodeIDs, &
elementID = eID, &
side = faceNumber)
self % faces(self % numberOfFaces) % boundaryName = &
self % elements(eID) % boundaryName(faceNumber)
!
! ----------------------------------------------
! Mark which face is associated with these nodes
! ----------------------------------------------
!
call table % AddEntry(faceNodeIDs)
END IF
END DO
END DO
call table % Destruct
END SUBROUTINE ConstructFaces
subroutine GetElementsFaceIDs(self)
implicit none
type(HexMesh), intent(inout) :: self
!
! ---------------
! Local variables
! ---------------
!
integer :: fID, eL, eR, e, side
do fID = 1, size(self % faces)
select case (self % faces(fID) % faceType)
case (HMESH_INTERIOR)
eL = self % faces(fID) % elementIDs(1)
eR = self % faces(fID) % elementIDs(2)
self % elements(eL) % faceIDs(self % faces(fID) % elementSide(1)) = fID
self % elements(eR) % faceIDs(self % faces(fID) % elementSide(2)) = fID
self % elements(eL) % faceSide(self % faces(fID) % elementSide(1)) = 1
self % elements(eR) % faceSide(self % faces(fID) % elementSide(2)) = 2
case (HMESH_BOUNDARY)
eL = self % faces(fID) % elementIDs(1)
self % elements(eL) % faceIDs(self % faces(fID) % elementSide(1)) = fID
self % elements(eL) % faceSide(self % faces(fID) % elementSide(1)) = 1
case (HMESH_MPI)
side = maxloc(self % faces(fID) % elementIDs, 1)
e = self % faces(fID) % elementIDs(side)
self % elements(e) % faceIDs(self % faces(fID) % elementSide(side)) = fID
self % elements(e) % faceSide(self % faces(fID) % elementSide(side)) = side
self % elements(e) % hasSharedFaces = .true.
case (HMESH_UNDEFINED)
eL = self % faces(fID) % elementIDs(1)
self % elements(eL) % faceIDs(self % faces(fID) % elementSide(1)) = fID
self % elements(eL) % faceSide(self % faces(fID) % elementSide(1)) = 1
end select
end do
end subroutine GetElementsFaceIDs
!
!////////////////////////////////////////////////////////////////////////
!
!
!---------------------------------------------------------------------
!! Element faces can be rotated with respect to each other. Orientation
!! gives the relative orientation of the master (1) face to the
!! slave (2) face . In this routine,
!! orientation is measured in 90 degree increments:
!! rotation angle = orientation*pi/2
!!
!! As an example, faceRotation = 1 <=> rotating master by 90 deg.
!
INTEGER pure FUNCTION faceRotation(masterNodeIDs, slaveNodeIDs)
IMPLICIT NONE
INTEGER, DIMENSION(4), intent(in) :: masterNodeIDs, slaveNodeIDs !< Node IDs
!
! ---------------
! Local variables
! ---------------
!
integer, dimension(4), parameter :: NEXTNODE = (/2,3,4,1/)
INTEGER :: j
!
! Rotate until both first nodes match (each j corresponds to a 90deg rotation)
! -----------------------------------
DO j = 1, 4
IF(masterNodeIDs(1) == slaveNodeIDs(j)) EXIT
END DO
!
! Check whether the orientation is same or opposite
! -------------------------------------------------
if ( masterNodeIDS(2) == slaveNodeIDs(NEXTNODE(j)) ) then
faceRotation = j - 1
else
faceRotation = j + 3
end if
END FUNCTION faceRotation
!
!////////////////////////////////////////////////////////////////////////
!
SUBROUTINE ConstructPeriodicFaces(self, useRelaxTol)
USE Physics
IMPLICIT NONE
!
!-------------------------------------------------------------------
! This subroutine looks for periodic boundary conditions. If they
! are found, periodic+ face is set as an interior face. The slave
! face is the periodic- face and will be deleted in the following
! step.
!-------------------------------------------------------------------
!
!
!--------------------
! External variables
!--------------------
!
TYPE(HexMesh) :: self
LOGICAL, intent(in) :: useRelaxTol
!
!--------------------
! Local variables
!--------------------
!
!
REAL(KIND=RP) :: x1(NDIM), x2(NDIM), edge_length(4), min_edge_length
LOGICAL :: master_matched(4), slave_matched(4), success, found
INTEGER :: coord, slaveNodeIDs(4), localCoord
INTEGER :: i,j,k,l
integer :: zIDplus, zIDMinus, iFace, jFace
character(len=LINE_LENGTH) :: associatedBname
!
! --------------------------------------------
! Loop to find faces with the label "periodic"
! --------------------------------------------
!
! -----------------------------
! Loop zones with BC "periodic"
! -----------------------------
!
do zIDPlus = 1, size(self % zones)
!
! Cycle if the zone is not periodic
! ---------------------------------
if ( trim(BCs(zIDPlus) % bc % bcType) .ne. "periodic") cycle
!
! Cycle if the zone has already marked to be deleted
! --------------------------------------------------
if ( self % zones(zIDPlus) % toBeDeleted ) cycle
!
! Reset the coordinate (changes when changing zones)
! --------------------------------------------------
coord = 0
!
! Get the marker of the associated zone
! -------------------------------------
found = .false.
do zIDMinus = 1, size(self % zones)
call BCs(zIDPlus) % bc % GetPeriodicPair(associatedBname)
if ( trim(associatedBname) .eq. trim(self % zones(zIDMinus) % Name) ) then
found = .true.
self % zones(zIDMinus) % toBeDeleted = .true.
exit
end if
end do
if ( .not. found ) then
print*, 'coupled boundary "',trim(associatedBname),' for boundary "',trim(self % zones(zIDPlus) % Name),'" not found.'
errorMessage(STD_OUT)
error stop
end if
!
! Loop faces in the periodic+ zone
! --------------------------------
ploop: do iFace = 1, self % zones(zIDPlus) % no_of_faces
!
! Get the face ID
! ---------------
i = self % zones(zIDPlus) % faces(iFace)
!
! Consider only HMESH_UNDEFINED faces
! -----------------------------------
if ( (self % faces(i) % faceType .ne. HMESH_UNDEFINED)) cycle ploop
!
! Loop faces in the periodic- zone
! --------------------------------
mloop: do jFace = 1, self % zones(zIDMinus) % no_of_faces
!
! Get the face ID
! ---------------
j = self % zones(zIDMinus) % faces(jFace)
!
! Consider only HMESH_UNDEFINED faces
! -----------------------------------
if ( (self % faces(j) % faceType .ne. HMESH_UNDEFINED)) cycle mloop
!
! ----------------------------------------------------------------------------------------
! The index i is a periodic+ face
! The index j is a periodic- face
! We are looking for couples of periodic+ and periodic- faces where 2 of the 3 coordinates
! in all the corners are shared. The non-shared coordinate has to be always the same one.
! ---------------------------------------------------------------------------------------
!
master_matched(:) = .FALSE. ! True if the master corner finds a partner
slave_matched(:) = .FALSE. ! True if the slave corner finds a partner
! compute minimum edge length to make matching tolerance relative to element size. Assumes that the periodic
! coordinate of all the nodes not vary significativelly compared to the other two coordinates.
if (useRelaxTol) then
edge_length(1)=NORM2(self % nodes(self % faces(i) % nodeIDs(1)) % x - self % nodes(self % faces(i) % nodeIDs(2)) % x)
edge_length(2)=NORM2(self % nodes(self % faces(i) % nodeIDs(2)) % x - self % nodes(self % faces(i) % nodeIDs(3)) % x)
edge_length(3)=NORM2(self % nodes(self % faces(i) % nodeIDs(3)) % x - self % nodes(self % faces(i) % nodeIDs(4)) % x)
edge_length(4)=NORM2(self % nodes(self % faces(i) % nodeIDs(4)) % x - self % nodes(self % faces(i) % nodeIDs(1)) % x)
min_edge_length=minval(edge_length)
end if
if ( coord .eq. 0 ) then
!
! Check all coordinates
! ---------------------
do localCoord = 1, 3
master_matched = .false.
slave_matched = .false.
mastercoord: DO k = 1, 4
x1 = self%nodes(self%faces(i)%nodeIDs(k))%x
slavecoord: DO l = 1, 4
IF (.NOT.slave_matched(l)) THEN
x2 = self%nodes(self%faces(j)%nodeIDs(l))%x
IF (useRelaxTol) THEN
CALL CompareTwoNodesRelax(x1, x2, master_matched(k), localCoord, min_edge_length)
ELSE
CALL CompareTwoNodes(x1, x2, master_matched(k), localCoord)
END IF
IF (master_matched(k)) THEN
slave_matched(l) = .TRUE.
EXIT slavecoord
ENDIF
ENDIF
ENDDO slavecoord
IF (.NOT.master_matched(k)) EXIT mastercoord
ENDDO mastercoord
if ( all(master_matched) ) exit
end do
else
!
! Check only the shared coordinates
! ---------------------------------
DO k = 1, 4
x1 = self%nodes(self%faces(i)%nodeIDs(k))%x
DO l = 1, 4
IF (.NOT.slave_matched(l)) THEN
x2 = self%nodes(self%faces(j)%nodeIDs(l))%x
IF (useRelaxTol) THEN
CALL CompareTwoNodesRelax(x1, x2, master_matched(k), coord, min_edge_length)
ELSE
CALL CompareTwoNodes(x1, x2, master_matched(k), coord)
END IF
IF (master_matched(k)) THEN
slave_matched(l) = .TRUE.
EXIT
ENDIF
ENDIF
ENDDO
IF (.NOT.master_matched(k)) EXIT
ENDDO
end if
IF ( all(master_matched) ) THEN
if ( coord .eq. 0 ) coord = localCoord
self % faces(i) % boundaryName = emptyBCName
self % faces(i) % elementIDs(2) = self % faces(j) % elementIDs(1)
self % faces(i) % elementSide(2) = self % faces(j) % elementSide(1)
self % faces(i) % FaceType = HMESH_INTERIOR
self % elements(self % faces(i) % elementIDs(1)) % boundaryName(self % faces(i) % elementSide(1)) = emptyBCName
self % elements(self % faces(i) % elementIDs(2)) % boundaryName(self % faces(i) % elementSide(2)) = emptyBCName
!
! To obtain the face rotation, we traduce the right element node IDs to the left
! ------------------------------------------------------------------------------
do k = 1, 4
x1 = self % nodes ( self % faces(i) % nodeIDs(k)) % x
do l = 1, 4
x2 = self % nodes ( self % faces(j) % nodeIDs(l) ) % x
IF (useRelaxTol) THEN
CALL CompareTwoNodesRelax(x1, x2, success, coord, min_edge_length)
ELSE
CALL CompareTwoNodes(x1, x2, success, coord)
END IF
if ( success ) then
slaveNodeIDs(l) = self % faces(i) % nodeIDs(k)
end if
end do
end do
self % faces(i) % rotation = faceRotation(self % faces(i) % nodeIDs, &
slaveNodeIDs)
cycle ploop
ENDIF
end do mloop ! periodic- faces
!
! If the code arrives here, the periodic+ face was not able to find a partner
! ---------------------------------------------------------------------------
print*, "When constructing periodic boundary conditions,"
write(STD_OUT,'(A,I0,A,I0,A,I0)') "Face ",i," in zone ",zIDPlus, &
" was not able to find a partner. Element: ", self % faces(i) % elementIDs(1)
errorMessage(STD_OUT)
error stop
end do ploop ! periodic+ faces
end do ! periodic+ zones
if ( MPI_Process % isRoot .and. useRelaxTol) print *, "Success: when matching all periodic boundary conditions with relaxed comparison"
END SUBROUTINE ConstructPeriodicFaces
!
!////////////////////////////////////////////////////////////////////////
!
SUBROUTINE CompareTwoNodes(x1, x2, success, coord)
IMPLICIT NONE
!
!-------------------------------------------------------------------
! Comparison of two nodes. If two of the three coordinates are the
! same, there is success. If there is success, the coordinate which
! is not the same is saved. If the initial value of coord is not 0,
! only that coordinate is checked.
!-------------------------------------------------------------------
!
!
! --------------------
! External variables
! --------------------
!
REAL(KIND=RP) :: x1(3)
REAL(KIND=RP) :: x2(3)
LOGICAL :: success
INTEGER :: coord
!
! --------------------
! Local variables
! --------------------
!
INTEGER :: i
INTEGER :: counter
counter = 0
IF (coord == 0) THEN
DO i = 1,3
IF ( AlmostEqual( x1(i), x2(i) ) ) THEN
counter = counter + 1
ELSE
coord = i
ENDIF
ENDDO
IF (counter.ge.2) THEN
success = .TRUE.
ELSE
success = .FALSE.
ENDIF
ELSE
DO i = 1,3
IF (i /= coord) THEN
IF ( AlmostEqual( x1(i), x2(i) ) ) THEN
counter = counter + 1
ENDIF
ENDIF
ENDDO
IF (counter.ge.2) THEN
success = .TRUE.
ELSE
success = .FALSE.
ENDIF
ENDIF
END SUBROUTINE CompareTwoNodes
!
!////////////////////////////////////////////////////////////////////////
!
SUBROUTINE CompareTwoNodesRelax(x1, x2, success, coord, min_edge_length)
IMPLICIT NONE
!
!-------------------------------------------------------------------
! Similar to CompareTwoNodes, but the comparison of the two nodes
! is done relaxed by the minimum edge length
!-------------------------------------------------------------------
! --------------------
! External variables
! --------------------
!
REAL(KIND=RP) :: x1(3)
REAL(KIND=RP) :: x2(3)
REAL(KIND=RP) :: min_edge_length
LOGICAL :: success
INTEGER :: coord
!
! --------------------
! Local variables
! --------------------
!
INTEGER :: i
INTEGER :: counter
counter = 0
IF (coord == 0) THEN
DO i = 1,3
IF ( AlmostEqualRelax( x1(i), x2(i) , min_edge_length ) ) THEN
counter = counter + 1
ELSE
coord = i
ENDIF
ENDDO
IF (counter.ge.2) THEN
success = .TRUE.
ELSE
success = .FALSE.
ENDIF
ELSE
DO i = 1,3
IF (i /= coord) THEN
IF ( AlmostEqualRelax( x1(i), x2(i) , min_edge_length ) ) THEN
counter = counter + 1
ENDIF
ENDIF
ENDDO
IF (counter.ge.2) THEN
success = .TRUE.
ELSE
success = .FALSE.
ENDIF
ENDIF
END SUBROUTINE CompareTwoNodesRelax
!
!////////////////////////////////////////////////////////////////////////
!
SUBROUTINE DeletePeriodicminusfaces(self)
use MPI_Face_Class
IMPLICIT NONE
!
!-------------------------------------------------------------------
! This subroutine looks for periodic boundary conditions. If they
! are found, periodic+ face is set as an interior face. The slave
! face is the periodic- face and will be deleted in the following
! step.
!-------------------------------------------------------------------
!
!
! --------------------
! External variables
! --------------------
!
TYPE(HexMesh) :: self
!
! --------------------
! Local variables
! --------------------
!
TYPE(Face),ALLOCATABLE :: dummy_faces(:)
INTEGER :: i, domain
INTEGER :: iFace, numberOfFaces
character(len=LINE_LENGTH) :: bName
integer :: newFaceID(self % numberOfFaces)
!
! This first loop marks which faces will not be deleted
! -----------------------------------------------------
newFaceID = -1
iFace = 0
ALLOCATE( dummy_faces(self % numberOfFaces) )
DO i = 1, self%numberOfFaces
if ( self % faces(i) % faceType .ne. HMESH_UNDEFINED ) then
iFace = iFace + 1
dummy_faces(iFace) = self%faces(i)
dummy_faces(iFace) % ID = iFace
newFaceID(i) = iFace
elseif (.not. self % zones(self % faces(i) % zone) % toBeDeleted) then
iFace = iFace + 1
dummy_faces(iFace) = self%faces(i)
dummy_faces(iFace) % ID = iFace
newFaceID(i) = iFace
ENDIF
ENDDO
numberOfFaces = iFace
DEALLOCATE(self%faces)
ALLOCATE(self%faces(numberOfFaces))
self%numberOfFaces = numberOfFaces
DO i = 1, self%numberOfFaces
self%faces(i) = dummy_faces(i)
ENDDO
!
! Update MPI face IDs
! -------------------
if ( (MPI_Process % doMPIAction) .and. self % MPIfaces % Constructed ) then
do domain = 1, MPI_Process % nProcs
do iFace = 1, self % MPIfaces % faces(domain) % no_of_faces
self % MPIfaces % faces(domain) % faceIDs(iFace) = newFaceID(self % MPIfaces % faces(domain) % faceIDs(iFace))
end do
end do
end if
!
! Reassign zones
! -----------------
CALL ReassignZones(self % faces, self % zones)
END SUBROUTINE DeletePeriodicminusfaces
!
!////////////////////////////////////////////////////////////////////////
!
subroutine HexMesh_ProlongSolutionToFaces(self, nEqn, HO_Elements, element_mask, Level)
implicit none
class(HexMesh), intent(inout) :: self
integer, intent(in) :: nEqn
logical, optional, intent(in) :: HO_Elements
logical, optional, intent(in) :: element_mask(:)
integer, optional, intent(in) :: Level
!
! ---------------
! Local variables
! ---------------
!
integer :: fIDs(6)
integer :: eID, i, locLevel, lID
logical :: HOElements
logical :: compute_element
if (present(HO_Elements)) then
HOElements = HO_Elements
else
HOElements = .false.
end if
if (HOElements) then
!$omp do schedule(runtime) private(eID, fIDs)
do i = 1, size(self % HO_Elements)
eID = self % HO_Elements(i)
compute_element = .true.
if (present(element_mask)) compute_element = element_mask(eID)
if (compute_element) then
fIDs = self % elements(eID) % faceIDs
call self % elements(eID) % ProlongSolutionToFaces(nEqn, &
self % faces(fIDs(1)),&
self % faces(fIDs(2)),&
self % faces(fIDs(3)),&
self % faces(fIDs(4)),&
self % faces(fIDs(5)),&
self % faces(fIDs(6)) )
endif
end do
!$omp end do
else
! The following differentiation is needed due to problem on AnisFAS NS
if (present(Level)) then
locLevel = Level
!$omp do schedule(runtime) private(fIDs, eID)
do lID = 1, self % MLRK % MLIter(locLevel,8)
eID = self % MLRK % MLIter_eIDN(lID)
compute_element = .true.
if (present(element_mask)) compute_element = element_mask(eID)
if (compute_element) then
fIDs = self % elements(eID) % faceIDs
call self % elements(eID) % ProlongSolutionToFaces(nEqn, &
self % faces(fIDs(1)),&
self % faces(fIDs(2)),&
self % faces(fIDs(3)),&
self % faces(fIDs(4)),&
self % faces(fIDs(5)),&
self % faces(fIDs(6)) )
endif
end do
!$omp end do
else