-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinMesh_Elements.F
1783 lines (1623 loc) · 63.6 KB
/
inMesh_Elements.F
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
c/**************************************************************************
c Copyright (c) 2011-2017, Ioannis Nompelis
c All rights reserved.
c
c Redistribution and use in source and binary forms, with or without any
c modification, are permitted provided that the following conditions are met:
c 1. Redistribution of source code must retain the above copyright
c notice, this list of conditions and the following disclaimer.
c 2. Redistribution in binary form must reproduce the above copyright
c notice, this list of conditions and the following disclaimer in the
c documentation and/or other materials provided with the distribution.
c 3. All advertising materials mentioning features or use of this software
c must display the following acknowledgement:
c "This product includes software developed by Ioannis Nompelis."
c 4. Neither the name of Ioannis Nompelis and his partners/affiliates nor the
c names of other contributors may be used to endorse or promote products
c derived from this software without specific prior written permission.
c 5. Redistribution or use of source code and binary forms for profit must
c have written permission of the copyright holder.
c
c THIS SOFTWARE IS PROVIDED BY IOANNIS NOMPELIS ''AS IS'' AND ANY
c EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
c WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
c DISCLAIMED. IN NO EVENT SHALL IOANNIS NOMPELIS BE LIABLE FOR ANY
c DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
c (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
c LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
c ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
c (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
c SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
c **************************************************************************/
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c *** Module to store standard mesh elements
c *** Created: IN <nompelis@nobelware.com> 20171006
c *** Last modified: IN <nompelis@nobelware.com> 20171101
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
Module inMesh_Elements
c Use iso_c_binding
c Use ISO_FORTRAN_ENV
Type inMesh_Tetrahedron_t
!--- Global face numbers
Integer(kind=8) :: f1,f2,f3,f4
!--- Global node numbers
Integer(kind=8) :: n1,n2,n3,n4
!--- Convention of the faces
!--- Any face of the tetrahedron's 1-4 can be any triangle and it
!--- can have any of three positive or negative alignments. Positive
!--- numbers imply outward pointing normals. Permutations of 1,2,3
!--- imply deviations from the "cannonical" alignment.
Integer(kind=2) :: fc(4)
End Type
Type inMesh_Pyramid_t
!--- Global face numbers
Integer(kind=8) :: f1,f2,f3,f4,f5
!--- Global node numbers
Integer(kind=8) :: n1,n2,n3,n4,n5
!--- Convention of the faces
!--- The base of the pyramid's can only be a quadrilateral (4 nodes)
!--- and its face convention is (by construction) -1 or +1. The
!--- remaining four faces 2-5 are triangles and can have any of three
!--- possible alignments. Positive numbers imply outward-pointing
!--- normals. permutations of 1,2,3 imply deviations from the
!--- "cannonical" alignment.
Integer(kind=2) :: fc(5)
End Type
Type inMesh_Wedge_t
!--- Global face numbers
Integer(kind=8) :: f1,f2,f3,f4,f5
!--- Global node numbers
Integer(kind=8) :: n1,n2,n3,n4,n5,n6
!--- Convention of the faces
!--- The base of the wegde is the first triangle encountered in the
!--- input list of surface elements and its face convention is (by
!--- construction) -1 or +1. The remaining faces can have any of
!--- three possible alignemnts for the top face and four possible
!--- alignments for the lateral quadrilaterals. Positive numbers imply
!--- outward-pointing normals. permutations of 1,2,3 or 4 imply
!--- deviations from the "cannonical" alignment.
Integer(kind=2) :: fc(5)
End Type
Type inMesh_Brick_t
!--- Global face numbers
Integer(kind=8) :: f1,f2,f3,f4,f5,f6
!--- Global node numbers
Integer(kind=8) :: n1,n2,n3,n4,n5,n6,n7,n8
!--- Convention of the faces
!--- The base of the brick is the first face encountered in the list
!--- and its face convention is (by construction) -1 or +1.
!--- The remaining faces can have any of four possible alignemnts.
!--- Positive numbers imply outward-pointing normals. permutations of
!--- 1,2,3,4 imply deviations from the "cannonical" alignment.
!--- Face numbers for a brick are opposing eachother for sequential
!--- odd and even numbers (i.e. 1 is opposite 2). Faces 1 and 2 are
!--- the base and top, face 3 has nodes 1 & 2, face 5 has nodes 1 & 4.
Integer(kind=2) :: fc(6)
End Type
CONTAINS
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c *** Routine to form a tetrahedron from four triangles
c *** This routine assumes that what is passed in "ifn" are _valid_ triangles
c *** (Definitions on the validity of triangles are found in my notes.)
c *** Created: IN <nompelis@nobelware.com> 20171006
c *** Last modified: IN <nompelis@nobelware.com> 20171016
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
Subroutine inMesh_Elements_FormTetrahedronFromFaces(
& nfa, ifn, ife, i, iefi,
& ieno, iefo, ierr )
Implicit None
Integer(kind=4), intent(OUT) :: ierr
Integer(kind=8), intent(IN) :: nfa,i
Integer(kind=8), intent(IN) :: ifn(0:4,nfa),ife(2,nfa)
Integer(kind=8), intent(IN) :: iefi(0:4)
c --- Variables to return to what would be a numerical solver that is aware
c --- of the conventions used.
Integer(kind=8), intent(OUT) :: ieno(0:8),iefo(0:4)
c --- Internal variable for this example
Type(inMesh_Tetrahedron_t) :: tet
Integer(kind=8) :: j1,j2,j3,j4,jj
Integer(kind=2) :: k,ik,kk
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Constructing a tetrahedron; number',i
PRINT*,'Faces:', iefi(1:4)
#endif
c --- Ssanity checks
if( iefi(0) .ne. 4 )then
PRINT*,'Not a tetrahedron (does not have 4 faces)'
ierr = 1
return
endif
if( (iefi(1) .le. 0 .OR. iefi(1) .gt. nfa) .OR.
& (iefi(2) .le. 0 .OR. iefi(2) .gt. nfa) .OR.
& (iefi(3) .le. 0 .OR. iefi(3) .gt. nfa) .OR.
& (iefi(4) .le. 0 .OR. iefi(4) .gt. nfa) ) then
PRINT*,'Face numbers out of bounds'
ierr = 2
return
endif
j1 = -1
j2 = -1
j3 = -1
j4 = -1
tet%n1 = 0
tet%n2 = 0
tet%n3 = 0
tet%n4 = 0
tet%f1 = 0
tet%f2 = 0
tet%f3 = 0
tet%f4 = 0
tet%fc(:) = 0
c --- Select the first face of the tet. to be the first one in the list
c --- Copy node numbers and face number
c --- By convention (as in Fluent case files), right is where the thumb points
c --- when listing nodes by a right-hand rule.
c --- By a starting choice we set the face-convention flag to +1 or -1
j1 = iefi(1)
tet%f1 = j1 ! set 1st face
if( ife(2,j1) .eq. i ) then ! triangle's "right" face is the tetr.
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Tetrahedron is on the right of face 1'
#endif
tet%n1 = ifn(1, j1 ) ! set 1st node
tet%n2 = ifn(2, j1 ) ! set 2nd node
tet%n3 = ifn(3, j1 ) ! set 3rd node
tet%fc(1) = -1 ! edge number and direction (sign)
else
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Tetrahedron is on the left of face 1'
#endif
tet%n1 = ifn(2, j1 ) ! set 1st node is the 2nd one
tet%n2 = ifn(1, j1 ) ! set 2nd node is the 1st one
tet%n3 = ifn(3, j1 ) ! set 3rd node is the same
tet%fc(1) = +1 ! edge number and direction (sign)
endif
c --- Find face 2; look for 2 matching nodes for n1,n2 of the tetrahedron
c --- Determine orientation of face 2 (using ife); set conventions
c --- Also set 4th node of the tetrahedron
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Will match nodes:',tet%n1,tet%n2
#endif
j2 = -1 ! undefined number
do k = 2,4 ! loop over remaining faces; 1st excluded
jj = iefi(k) ! face number
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Trial face:',k,jj
#endif
ik = 0 ! number of nodes matched for this trial face
do kk = 1,3 ! loop over trial face's nodes (always 3)
if( ifn(kk,jj) .eq. tet%n1 ) ik = ik + 1
if( ifn(kk,jj) .eq. tet%n2 ) ik = ik + 1
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Node:',kk,ifn(kk,jj)
#endif
enddo
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'After testing ik=',ik
#endif
if( ik .eq. 2 ) then
j2 = jj
endif
enddo
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Identified face 2 as:',j2
#endif
do kk = 1,3 ! loop over 2nd face's nodes (always 3)
if( ifn(kk,j2) .ne. tet%n1 .AND. ifn(kk,j2) .ne. tet%n2 ) then
tet%n4 = ifn(kk,j2)
endif
enddo
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,' Assigned fourth node of tet:',tet%n4
PRINT*,' Left/right elems:',ife(:,j2)
#endif
if( ife(1,j2) .eq. i ) then ! tetrahedron is left
tet%fc(2) = +1 ! preliminary edge direction (sign)
if( ifn(3,j2) .eq. tet%n1 ) then
tet%fc(2) = +2 ! correct edge direction (sign)
endif
if( ifn(2,j2) .eq. tet%n1 ) then
tet%fc(2) = +3 ! correct edge direction (sign)
endif
else ! tetrahedron is right
tet%fc(2) = -1 ! preliminary edge direction (sign)
if( ifn(1,j2) .eq. tet%n1 ) then
tet%fc(2) = -2 ! correct edge direction (sign)
endif
if( ifn(3,j2) .eq. tet%n1 ) then
tet%fc(2) = -3 ! correct edge direction (sign)
endif
endif
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Identified face 2 convention:',tet%fc(2)
#endif
c --- Find face 3; look for 2 matching nodes for n2,n3 of the tetrahedron
c --- Determine orientation of face 3 (using ife); set conventions
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Will match nodes:',tet%n2,tet%n3
#endif
j3 = -1 ! undefined number
do k = 2,4 ! loop over remaining faces; 1st excluded
jj = iefi(k) ! face number
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Trial face:',k,jj
#endif
ik = 0 ! number of nodes matched for this trial face
do kk = 1,3 ! loop over trial face's nodes (always 3)
if( ifn(kk,jj) .eq. tet%n2 ) ik = ik + 1
if( ifn(kk,jj) .eq. tet%n3 ) ik = ik + 1
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Node:',kk,ifn(kk,jj)
#endif
enddo
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'After testing ik=',ik
#endif
if( ik .eq. 2 ) then
j3 = jj
endif
enddo
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Identified face 3 as:',j3
PRINT*,' Left/right elems:',ife(:,j3)
#endif
if( ife(1,j3) .eq. i ) then ! tetrahedron is left
tet%fc(3) = +1 ! preliminary edge direction (sign)
if( ifn(3,j3) .eq. tet%n2 ) then
tet%fc(3) = +2 ! correct edge direction (sign)
endif
if( ifn(2,j3) .eq. tet%n2 ) then
tet%fc(3) = +3 ! correct edge direction (sign)
endif
else ! tetrahedron is right
tet%fc(3) = -1 ! preliminary edge direction (sign)
if( ifn(1,j3) .eq. tet%n2 ) then
tet%fc(3) = -2 ! correct edge direction (sign)
endif
if( ifn(3,j3) .eq. tet%n2 ) then
tet%fc(3) = -3 ! correct edge direction (sign)
endif
endif
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Identified face 3 convention:',tet%fc(3)
#endif
c --- Assign face 4; it is the remaining (un-asigned) face of the tetrahedron
c --- Determine orientation of face 4 (using ife); set conventions
do k = 2,4 ! loop over remaining faces; 1st excluded
jj = iefi(k) ! face number
if( j1.ne.jj .AND. j2.ne.jj .AND. j3.ne.jj ) j4 = jj
enddo
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Identified face 4 as:',j4
#endif
if( ife(1,j4) .eq. i ) then ! tetrahedron is left
tet%fc(4) = +1 ! preliminary edge direction (sign)
if( ifn(3,j4) .eq. tet%n3 ) then
tet%fc(4) = +2 ! correct edge direction (sign)
endif
if( ifn(2,j4) .eq. tet%n3 ) then
tet%fc(4) = +3 ! correct edge direction (sign)
endif
else ! tetrahedron is right
tet%fc(4) = -1 ! preliminary edge direction (sign)
if( ifn(1,j4) .eq. tet%n3 ) then
tet%fc(4) = -2 ! correct edge direction (sign)
endif
if( ifn(3,j4) .eq. tet%n3 ) then
tet%fc(4) = -3 ! correct edge direction (sign)
endif
endif
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Identified face 4 convention:',tet%fc(4)
#endif
c --- assign structure members
tet%f1 = j1
tet%f2 = j2
tet%f3 = j3
tet%f4 = j4
c --- Assign returned structures
ieno(0) = 4
ieno(1) = tet%n1
ieno(2) = tet%n2
ieno(3) = tet%n3
ieno(4) = tet%n4
iefo(0) = 4
iefo(1) = j1
iefo(2) = j2
iefo(3) = j3
iefo(4) = j4
End subroutine
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c *** Routine to form a pyramid cell element from four triangles and a quad.
c *** This routine assumes that what is passed in "ifn" are _valid_ surf. elems.
c *** (Definitions on the validity of surface elements are found in my notes.)
c *** Created: IN <nompelis@nobelware.com> 20171014
c *** Last modified: IN <nompelis@nobelware.com> 20171016
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
Subroutine inMesh_Elements_FormPyramidFromFaces(
& nfa, ifn, ife, i, iefi,
& ieno, iefo, ierr )
Implicit None
Integer(kind=4), intent(OUT) :: ierr
Integer(kind=8), intent(IN) :: nfa,i
Integer(kind=8), intent(IN) :: ifn(0:4,nfa),ife(2,nfa)
Integer(kind=8), intent(IN) :: iefi(0:5)
c --- Variables to return to what would be a numerical solver that is aware
c --- of the conventions used.
Integer(kind=8), intent(OUT) :: ieno(0:8),iefo(0:5)
c --- Internal variable for this example
Type(inMesh_Pyramid_t) :: pyr
Integer(kind=8) :: j1,j2,j3,j4,j5,jj
Integer(kind=2) :: k,ik,kk
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Constructing a pyramid; number',i
PRINT*,'Faces:', iefi(1:5)
#endif
c --- Ssanity checks
if( iefi(0) .ne. 5 )then
PRINT*,'Not a pyramid (does not have 5 faces)'
ierr = 1
return
endif
if( (iefi(1) .le. 0 .OR. iefi(1) .gt. nfa) .OR.
& (iefi(2) .le. 0 .OR. iefi(2) .gt. nfa) .OR.
& (iefi(3) .le. 0 .OR. iefi(3) .gt. nfa) .OR.
& (iefi(4) .le. 0 .OR. iefi(4) .gt. nfa) .OR.
& (iefi(5) .le. 0 .OR. iefi(5) .gt. nfa) ) then
PRINT*,'Face numbers out of bounds'
ierr = 2
return
endif
j1 = -1
j2 = -1
j3 = -1
j4 = -1
j5 = -1
pyr%n1 = 0
pyr%n2 = 0
pyr%n3 = 0
pyr%n4 = 0
pyr%n5 = 0
pyr%f1 = 0
pyr%f2 = 0
pyr%f3 = 0
pyr%f4 = 0
pyr%f5 = 0
pyr%fc(:) = 0
c --- Select the first face of the pyramid to be the 4-node one
c --- Copy node numbers and face number
c --- By convention (as in Fluent case files), right is where the thumb points
c --- when listing nodes by a right-hand rule.
c --- By a starting choice we set the face-convention flag to +1 or -1
do jj = 1,iefi(0)
if( ifn(0, iefi(jj) ) .eq. 4 ) j1 = jj
enddo
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'First face is number ',j1
#endif
pyr%f1 = j1 ! set 1st face
if( ife(2,j1) .eq. i ) then ! quad's "right" face is the pyramid
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Pyramid is on the right of face 1'
#endif
pyr%n1 = ifn(1, j1 ) ! set 1st node
pyr%n2 = ifn(2, j1 ) ! set 2nd node
pyr%n3 = ifn(3, j1 ) ! set 3rd node
pyr%n4 = ifn(4, j1 ) ! set 4th node
pyr%fc(1) = -1 ! edge number and direction (sign)
else
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Pyramid is on the left of face 1'
#endif
pyr%n1 = ifn(2, j1 ) ! set 1st node
pyr%n2 = ifn(1, j1 ) ! set 2nd node
pyr%n3 = ifn(4, j1 ) ! set 3rd node
pyr%n4 = ifn(3, j1 ) ! set 4th node
pyr%fc(1) = +1 ! edge number and direction (sign)
endif
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'First face nodes:',pyr%n1,pyr%n2,pyr%n3,pyr%n4
#endif
c --- Find face 2; look for 2 matching nodes for n1,n2 of the pyramid
c --- Determine orientation of face 2 (using ife); set conventions
c --- Also set 5th node of the pyramid
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Will match nodes:',pyr%n1,pyr%n2
#endif
j2 = -1 ! undefined number
do k = 1,5 ! loop over all faces
jj = iefi(k) ! face number
if( jj .ne. j1 ) then ! exclude the first (base) face
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Trial face:',k,jj
#endif
ik = 0 ! number of nodes matched for this trial face
do kk = 1,3 ! loop over trial face's nodes (always 3)
if( ifn(kk,jj) .eq. pyr%n1 ) ik = ik + 1
if( ifn(kk,jj) .eq. pyr%n2 ) ik = ik + 1
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Node:',kk,ifn(kk,jj)
#endif
enddo
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'After testing ik=',ik
#endif
if( ik .eq. 2 ) then
j2 = jj
endif
endif
enddo
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Identified face 2 as:',j2
#endif
do kk = 1,3 ! loop over 2nd face's nodes (always 3)
if( ifn(kk,j2) .ne. pyr%n1 .AND. ifn(kk,j2) .ne. pyr%n2 ) then
pyr%n5 = ifn(kk,j2)
endif
enddo
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,' Assigned fifth node of pyramid:',pyr%n5
PRINT*,' Left/right elems:',ife(:,j2)
#endif
if( ife(1,j2) .eq. i ) then ! pyramid is left
pyr%fc(2) = +1 ! preliminary edge direction (sign)
if( ifn(3,j2) .eq. pyr%n1 ) then
pyr%fc(2) = +2 ! correct edge direction (sign)
endif
if( ifn(2,j2) .eq. pyr%n1 ) then
pyr%fc(2) = +3 ! correct edge direction (sign)
endif
else ! pyramid is right
pyr%fc(2) = -1 ! preliminary edge direction (sign)
if( ifn(1,j2) .eq. pyr%n1 ) then
pyr%fc(2) = -2 ! correct edge direction (sign)
endif
if( ifn(3,j2) .eq. pyr%n1 ) then
pyr%fc(2) = -3 ! correct edge direction (sign)
endif
endif
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Identified face 2 convention:',pyr%fc(2)
#endif
c --- Find face 3; look for 2 matching nodes for n2,n3 of the pyramid
c --- Determine orientation of face 3 (using ife); set conventions
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Will match nodes:',pyr%n2,pyr%n3
#endif
j3 = -1 ! undefined number
do k = 1,5 ! loop over all faces
jj = iefi(k) ! face number
if( jj .ne. j1 ) then ! exclude the first (base) face
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Trial face:',k,jj
#endif
ik = 0 ! number of nodes matched for this trial face
do kk = 1,3 ! loop over trial face's nodes (always 3)
if( ifn(kk,jj) .eq. pyr%n2 ) ik = ik + 1
if( ifn(kk,jj) .eq. pyr%n3 ) ik = ik + 1
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Node:',kk,ifn(kk,jj)
#endif
enddo
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'After testing ik=',ik
#endif
if( ik .eq. 2 ) then
j3 = jj
endif
endif
enddo
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Identified face 3 as:',j3
PRINT*,' Left/right elems:',ife(:,j3)
#endif
if( ife(1,j3) .eq. i ) then ! pyramid is left
pyr%fc(3) = +1 ! preliminary edge direction (sign)
if( ifn(3,j3) .eq. pyr%n2 ) then
pyr%fc(3) = +2 ! correct edge direction (sign)
endif
if( ifn(2,j3) .eq. pyr%n2 ) then
pyr%fc(3) = +3 ! correct edge direction (sign)
endif
else ! pyramid is right
pyr%fc(3) = -1 ! preliminary edge direction (sign)
if( ifn(1,j3) .eq. pyr%n2 ) then
pyr%fc(3) = -2 ! correct edge direction (sign)
endif
if( ifn(3,j3) .eq. pyr%n2 ) then
pyr%fc(3) = -3 ! correct edge direction (sign)
endif
endif
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Identified face 3 convention:',pyr%fc(3)
#endif
c --- Find face 4; look for 2 matching nodes for n3,n4 of the pyramid
c --- Determine orientation of face 4 (using ife); set conventions
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Will match nodes:',pyr%n3,pyr%n4
#endif
j4 = -1 ! undefined number
do k = 1,5 ! loop over all faces
jj = iefi(k) ! face number
if( jj .ne. j1 ) then ! exclude the first (base) face
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Trial face:',k,jj
#endif
ik = 0 ! number of nodes matched for this trial face
do kk = 1,3 ! loop over trial face's nodes (always 3)
if( ifn(kk,jj) .eq. pyr%n3 ) ik = ik + 1
if( ifn(kk,jj) .eq. pyr%n4 ) ik = ik + 1
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Node:',kk,ifn(kk,jj)
#endif
enddo
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'After testing ik=',ik
#endif
if( ik .eq. 2 ) then
j4 = jj
endif
endif
enddo
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Identified face 4 as:',j4
PRINT*,' Left/right elems:',ife(:,j4)
#endif
if( ife(1,j4) .eq. i ) then ! pyramid is left
pyr%fc(4) = +1 ! preliminary edge direction (sign)
if( ifn(3,j4) .eq. pyr%n3 ) then
pyr%fc(4) = +2 ! correct edge direction (sign)
endif
if( ifn(2,j4) .eq. pyr%n3 ) then
pyr%fc(4) = +3 ! correct edge direction (sign)
endif
else ! pyramid is right
pyr%fc(4) = -1 ! preliminary edge direction (sign)
if( ifn(1,j4) .eq. pyr%n3 ) then
pyr%fc(4) = -2 ! correct edge direction (sign)
endif
if( ifn(3,j4) .eq. pyr%n3 ) then
pyr%fc(4) = -3 ! correct edge direction (sign)
endif
endif
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Identified face 4 convention:',pyr%fc(4)
#endif
c --- Find face 5; look for 2 matching nodes for n4,n1 of the pyramid
c --- Determine orientation of face 5 (using ife); set conventions
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Will match nodes:',pyr%n4,pyr%n1
#endif
j5 = -1 ! undefined number
do k = 1,5 ! loop over all faces
jj = iefi(k) ! face number
if( jj .ne. j1 ) then ! exclude the first (base) face
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Trial face:',k,jj
#endif
ik = 0 ! number of nodes matched for this trial face
do kk = 1,3 ! loop over trial face's nodes (always 3)
if( ifn(kk,jj) .eq. pyr%n4 ) ik = ik + 1
if( ifn(kk,jj) .eq. pyr%n1 ) ik = ik + 1
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Node:',kk,ifn(kk,jj)
#endif
enddo
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'After testing ik=',ik
#endif
if( ik .eq. 2 ) then
j5 = jj
endif
endif
enddo
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Identified face 5 as:',j5
PRINT*,' Left/right elems:',ife(:,j5)
#endif
if( ife(1,j5) .eq. i ) then ! pyramid is left
pyr%fc(5) = +1 ! preliminary edge direction (sign)
if( ifn(3,j5) .eq. pyr%n4 ) then
pyr%fc(5) = +2 ! correct edge direction (sign)
endif
if( ifn(2,j5) .eq. pyr%n4 ) then
pyr%fc(5) = +3 ! correct edge direction (sign)
endif
else ! pyramid is right
pyr%fc(5) = -1 ! preliminary edge direction (sign)
if( ifn(1,j5) .eq. pyr%n4 ) then
pyr%fc(5) = -2 ! correct edge direction (sign)
endif
if( ifn(3,j5) .eq. pyr%n4 ) then
pyr%fc(5) = -3 ! correct edge direction (sign)
endif
endif
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Identified face 5 convention:',pyr%fc(5)
#endif
c --- assign structure members
pyr%f1 = j1
pyr%f2 = j2
pyr%f3 = j3
pyr%f4 = j4
pyr%f5 = j5
c --- Assign returned structures
ieno(0) = 5
ieno(1) = pyr%n1
ieno(2) = pyr%n2
ieno(3) = pyr%n3
ieno(4) = pyr%n4
ieno(5) = pyr%n5
iefo(0) = 5
iefo(1) = j1
iefo(2) = j2
iefo(3) = j3
iefo(4) = j4
iefo(5) = j5
End subroutine
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c *** Routine to form a wedge cell element from two triangles and three quads.
c *** This routine assumes that what is passed in "ifn" are _valid_ surf. elems.
c *** (Definitions on the validity of surface elements are found in my notes.)
c *** Created: IN <nompelis@nobelware.com> 20171014
c *** Last modified: IN <nompelis@nobelware.com> 20191216
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
Subroutine inMesh_Elements_FormWedgeFromFaces(
& nfa, ifn, ife, i, iefi,
& ieno, iefo, ierr )
Implicit None
Integer(kind=4), intent(OUT) :: ierr
Integer(kind=8), intent(IN) :: nfa,i
Integer(kind=8), intent(IN) :: ifn(0:4,nfa),ife(2,nfa)
Integer(kind=8), intent(IN) :: iefi(0:5)
c --- Variables to return to what would be a numerical solver that is aware
c --- of the conventions used.
Integer(kind=8), intent(OUT) :: ieno(0:8),iefo(0:5)
c --- Internal variable for this example
Type(inMesh_Wedge_t) :: wed
Integer(kind=8) :: j1,j2,j3,j4,j5,jj
Integer(kind=2) :: k,ik,kk
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Constructing a wedge; number',i
PRINT*,'Faces:', iefi(1:5)
#endif
c --- Ssanity checks
if( iefi(0) .ne. 5 )then
PRINT*,'Not a wedge (does not have 5 faces)'
ierr = 1
return
endif
if( (iefi(1) .le. 0 .OR. iefi(1) .gt. nfa) .OR.
& (iefi(2) .le. 0 .OR. iefi(2) .gt. nfa) .OR.
& (iefi(3) .le. 0 .OR. iefi(3) .gt. nfa) .OR.
& (iefi(4) .le. 0 .OR. iefi(4) .gt. nfa) .OR.
& (iefi(5) .le. 0 .OR. iefi(5) .gt. nfa) ) then
PRINT*,'Face numbers out of bounds'
ierr = 2
return
endif
j1 = -1
j2 = -1
j3 = -1
j4 = -1
j5 = -1
wed%n1 = 0
wed%n2 = 0
wed%n3 = 0
wed%n4 = 0
wed%n5 = 0
wed%n6 = 0
wed%f1 = 0
wed%f2 = 0
wed%f3 = 0
wed%f4 = 0
wed%f5 = 0
wed%fc(:) = 0
c --- Select the first 3-node face of the wedge to be face 1 (the base)
c --- Copy node numbers and face number
c --- By convention (as in Fluent case files), right is where the thumb points
c --- when listing nodes by a right-hand rule.
c --- By a starting choice we set the face-convention flag to +1 or -1
do jj = 1,iefi(0)
if( j1 .eq. -1 ) then
if( ifn(0, iefi(jj) ) .eq. 3 ) j1 = jj
endif
enddo
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'First face is number ',j1
#endif
wed%f1 = j1 ! set 1st face
if( ife(2,j1) .eq. i ) then ! triangle's "right" cell is the wedge
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Wedge is on the right of face 1'
#endif
wed%n1 = ifn(1, j1 ) ! set 1st node
wed%n2 = ifn(2, j1 ) ! set 2nd node
wed%n3 = ifn(3, j1 ) ! set 3rd node
wed%fc(1) = -1 ! edge number and direction (sign)
else
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Wedge is on the left of face 1'
#endif
wed%n1 = ifn(2, j1 ) ! set 1st node
wed%n2 = ifn(1, j1 ) ! set 2nd node
wed%n3 = ifn(3, j1 ) ! set 3rd node
wed%fc(1) = +1 ! edge number and direction (sign)
endif
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'First face nodes:',wed%n1,wed%n2,wed%n3
#endif
c --- Find face 3; look for 2 matching nodes for n1,n2 of the wedge
c --- Determine orientation of face 3 (using ife); set conventions
c --- Also set 4th,5th node of the wedge
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Will match nodes:',wed%n1,wed%n2
#endif
j3 = -1 ! undefined number
do k = 1,5 ! loop over all faces
jj = iefi(k) ! face number
if( jj .ne. j1 ) then ! exclude the wedge's first (base) face
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Trial face:',k,jj
#endif
ik = 0 ! number of nodes matched for this trial face
do kk = 1,ifn(0,jj) ! loop over all the trial face's nodes
if( ifn(kk,jj) .eq. wed%n1 ) ik = ik + 1
if( ifn(kk,jj) .eq. wed%n2 ) ik = ik + 1
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Node:',kk,ifn(kk,jj)
#endif
enddo
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'After testing ik=',ik
#endif
if( ik .eq. 2 ) then
j3 = jj
endif
endif
enddo
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Identified face 3 as:',j3
PRINT*,' Left/right elems:',ife(:,j3)
#endif
if( ife(1,j3) .eq. i ) then ! wedge is left
wed%fc(3) = +1 ! preliminary edge direction (sign)
wed%n5 = ifn(3,j3)
wed%n4 = ifn(4,j3)
if( ifn(4,j3) .eq. wed%n1 ) then
wed%fc(3) = +2 ! correct edge direction (sign)
wed%n5 = ifn(2,j3)
wed%n4 = ifn(3,j3)
endif
if( ifn(3,j3) .eq. wed%n1 ) then
wed%fc(3) = +3 ! correct edge direction (sign)
wed%n5 = ifn(1,j3)
wed%n4 = ifn(2,j3)
endif
if( ifn(2,j3) .eq. wed%n1 ) then
wed%fc(3) = +4 ! correct edge direction (sign)
wed%n5 = ifn(4,j3)
wed%n4 = ifn(1,j3)
endif
else ! wedge is right
wed%fc(3) = -1 ! preliminary edge direction (sign)
wed%n4 = ifn(3,j3)
wed%n5 = ifn(4,j3)
if( ifn(1,j3) .eq. wed%n1 ) then
wed%fc(3) = -2 ! correct edge direction (sign)
wed%n4 = ifn(2,j3)
wed%n5 = ifn(3,j3)
endif
if( ifn(4,j3) .eq. wed%n1 ) then
wed%fc(3) = -3 ! correct edge direction (sign)
wed%n4 = ifn(1,j3)
wed%n5 = ifn(2,j3)
endif
if( ifn(3,j3) .eq. wed%n1 ) then
wed%fc(3) = -4 ! correct edge direction (sign)
wed%n4 = ifn(4,j3)
wed%n5 = ifn(1,j3)
endif
endif
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Identified face 3 convention:',wed%fc(3)
#endif
c --- Find face 2; look for 2 matching nodes for n4,n5 of the wedge
c --- Determine orientation of face 2 (using ife); set conventions
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Will match nodes:',wed%n4,wed%n5
#endif
j2 = -1 ! undefined number
do k = 1,5 ! loop over all faces
jj = iefi(k) ! face number
if( jj .ne. j3 ) then ! exclude the wedge's f3
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Trial face:',k,jj
#endif
ik = 0 ! number of nodes matched for this trial face
do kk = 1,ifn(0,jj) ! loop over all the trial face's nodes
if( ifn(kk,jj) .eq. wed%n4 ) ik = ik + 1
if( ifn(kk,jj) .eq. wed%n5 ) ik = ik + 1
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Node:',kk,ifn(kk,jj)
#endif
enddo
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'After testing ik=',ik
#endif
if( ik .eq. 2 ) then
j2 = jj
endif
endif
enddo
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Identified face 2 as:',j2
#endif
do kk = 1,3 ! loop over 2nd face's nodes (always 3)
if( ifn(kk,j2) .ne. wed%n4 .AND. ifn(kk,j2) .ne. wed%n5 ) then
wed%n6 = ifn(kk,j2)
endif
enddo
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,' Assigned sixth node of wedge:',wed%n6
PRINT*,' Left/right elems:',ife(:,j2)
#endif
if( ife(1,j2) .eq. i ) then ! wedge is left
wed%fc(2) = +1 ! preliminary edge direction (sign)
if( ifn(3,j2) .eq. wed%n4 ) then
wed%fc(2) = +2 ! correct edge direction (sign)
endif
if( ifn(2,j2) .eq. wed%n4 ) then
wed%fc(2) = +3 ! correct edge direction (sign)
endif
else
wed%fc(2) = -1 ! preliminary edge direction (sign)
if( ifn(1,j2) .eq. wed%n4 ) then
wed%fc(2) = -2 ! correct edge direction (sign)
endif
if( ifn(3,j2) .eq. wed%n4 ) then
wed%fc(2) = -3 ! correct edge direction (sign)
endif
endif
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Identified face 2 convention:',wed%fc(2)
#endif
c --- Find face 4; look for 2 matching nodes for n2,n3 of the wedge
c --- Determine orientation of face 4 (using ife); set conventions
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Will match nodes:',wed%n2,wed%n3
#endif
j4 = -1 ! undefined number
do k = 1,5 ! loop over all faces
jj = iefi(k) ! face number
if( jj .ne. j1 ) then ! exclude the wedge's f1
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Trial face:',k,jj
#endif
ik = 0 ! number of nodes matched for this trial face
do kk = 1,ifn(0,jj) ! loop over all the trial face's nodes
if( ifn(kk,jj) .eq. wed%n2 ) ik = ik + 1
if( ifn(kk,jj) .eq. wed%n3 ) ik = ik + 1
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Node:',kk,ifn(kk,jj)
#endif
enddo
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'After testing ik=',ik
#endif
if( ik .eq. 2 ) then
j4 = jj
endif
endif
enddo
#ifdef _DEBUG_MESH_ELEMENTS_
PRINT*,'Identified face 4 as:',j4
#endif