forked from eX-Mech/pipeMeshNek
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipeMeshNek.f90
1809 lines (1531 loc) · 64 KB
/
pipeMeshNek.f90
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
program pipeMeshNek
!==============================================================================
! geometry definitions
!
! (X) : border number
!
! ____________________________L_(2)_______________________________
! | |
! | |
! R (1) | (3)
! | |
! __ .| __ . __ . __ . __ . __ . __ . __ . __ . __ . __ . __ . __ . __| . __
! (0,0,0) axis of symmetry (4)
!
!==============================================================================
!==============================================================================
! variables definition
IMPLICIT NONE
! geometry variables
REAL(KIND=8) :: R ! pipe radius
REAL(KIND=8) :: L ! pipe length
REAL(KIND=8) :: lSq ! side of the inner square
REAL(KIND=8) :: iR ! inner element radius
REAL(KIND=8) :: oR ! outer element radius
! mesh variables
INTEGER :: nR ! number of elements on the radius (has to be > nTh/8)
INTEGER :: nL ! number of elements along the pipe
INTEGER :: nTh ! number of circular sweeps (has to be >= 8 and a power of 2)
REAL(KIND=8) :: rR ! element ratio along the radius
REAL(KIND=8) :: rL ! element ratio along the pipe
REAL(KIND=8) :: sR ! "summation"
REAL(KIND=8) :: dR ! delta element
REAL(KIND=8) :: dL ! delta element
REAL(KIND=8) :: de ! delta element
REAL(KIND=8) :: rP0 ! radius "penalization", inner part
REAL(KIND=8) :: rP1 ! radius "penalization", outer part
TYPE element
INTEGER :: num
INTEGER :: group
CHARACTER(LEN=1) :: groupL = 'a'
! vertices
REAL(KIND=8), DIMENSION(8) :: x
REAL(KIND=8), DIMENSION(8) :: y
REAL(KIND=8), DIMENSION(8) :: z
! faces
LOGICAL, DIMENSION(8) :: curvedEdge
REAL(KIND=8), DIMENSION(8) :: curvedEdgeR = 0
! boundary conditions
CHARACTER(LEN=2), DIMENSION(6) :: bcType
REAL(KIND=8), DIMENSION(6,5) :: bcParameters = 0
END TYPE element
TYPE(element), DIMENSION(:), ALLOCATABLE :: elem ! elements constituting the mesh
INTEGER :: nEl ! number of elements (total)
INTEGER :: nSq ! number of elements on the side of the inner square
INTEGER :: nPp ! number of elements in the central tube
REAL(KIND=8) :: alpha ! circular sweep angle
INTEGER :: nCurvedEdges ! number of curved edges
INTEGER :: nFpp ! number of elements on one face of the pipe
INTEGER :: nFpp4 ! number of elements on a quarter of a face of the pipe
INTEGER :: nPolynom ! Polynomial degree (-> nPolynom+1 Grid points)
REAL(KIND=8), DIMENSION(20) :: xGridNodes ! (Local) Lobatto node-positions
INTEGER :: nsteps, iostep
REAL(KIND=8) :: Re, dt
REAL(KIND=8) :: reTau ! Friction-Reynolds Number (Re_tau)
REAL(KIND=8) :: deltaR, deltaRmin, deltaRmax, thMin, thMax ! wall-unit mesh-quality measures
REAL(KIND=8) :: deltaZmin, deltaZmax, deltaRThmin, deltaRThmax !
INTEGER :: np1, np10 ! number of gridPoints below 1 (10) wall units
! miscellaneous
LOGICAL :: debugFlag
INTEGER :: i, j, k, m, row, col
REAL(KIND=8) :: xTmp1, xTmp2
REAL(KIND=8) :: yTmp1, yTmp2
INTEGER :: fid1 = 100, fid3d = 103, fid2d = 102
LOGICAL :: existFlag
CHARACTER(LEN=24) :: nameRea
REAL(KIND=8) :: PI = 4d0*DATAN(1d0)
REAL(KIND=8) :: SQ22 = SQRT(2d0)/2d0
!==============================================================================
! read input file 'INPUTgeometry'
INQUIRE (FILE='INPUTgeometry', EXIST=existFlag)
IF (.NOT.existFlag) THEN
WRITE(*,*) '*************************************'
WRITE(*,*) '*** ERROR: ***'
WRITE(*,*) '*** File not found ***'
WRITE(*,*) '*** INPUTgeometry ***'
WRITE(*,*) '*************************************'
WRITE(*,*) 'STOP.'
STOP
ELSE
OPEN(UNIT=fid1, FILE='INPUTgeometry', STATUS='old', FORM='formatted', ACTION='read')
ENDIF
READ(fid1,*) R
READ(fid1,*) L
READ(fid1,*) ! jump one line
READ(fid1,*) nR
READ(fid1,*) rP0
READ(fid1,*) rP1
READ(fid1,*) nL
READ(fid1,*) nTh
READ(fid1,*) ! jump one line
READ(fid1,*) rR
READ(fid1,*) rL
READ(fid1,*) ! jump one line
READ(fid1,*) Re
READ(fid1,*) dt
READ(fid1,*) nsteps
READ(fid1,*) iostep
READ(fid1,*) ! jump one line
READ(fid1,*) nPolynom
READ(fid1,*) reTau
READ(fid1,*) ! jump one line
READ(fid1,*) debugFlag
CLOSE(fid1)
!==============================================================================
! check the input
! check if the number of circular sweeps is >= 8 and a power of 2
!
IF ( nTh.LT.8 .OR. MODULO(LOG(nTh*1d0)/LOG(2d0),1d0).GT.0d0 ) THEN
WRITE(*,*) '******************************************'
WRITE(*,*) '*** ERROR: ***'
WRITE(*,*) '*** The number of circular sweeps ***'
WRITE(*,*) '*** (nTh) has to be >= 8 ***'
WRITE(*,*) '*** and a power of 2. ***'
WRITE(*,*) '******************************************'
WRITE(*,*) 'STOP.'
STOP
ENDIF
! check if nR > nTh/8
!
IF ( nR .LE. nTh/8 ) THEN
WRITE(*,*) '******************************************'
WRITE(*,*) '*** ERROR: ***'
WRITE(*,*) '*** The number of elements on the ***'
WRITE(*,*) '*** radius (nR) has to be >= nTh/8. ***'
WRITE(*,*) '******************************************'
WRITE(*,*) 'STOP.'
STOP
ENDIF
!==============================================================================
! do some preliminary computations
! mesh
!
alpha = 2d0*PI/nTH
nSq = nTh / 8
nFpp = 4*nSq**2 + (nR-nSq)*nTh
nFpp4 = nFpp / 4
nPp = nFpp * nL
nEl = nPp
! ratios
!
sR = 0d0
DO i = 1, (nR-nSq)
sR = sR + rR**i
ENDDO
dR = R/(nSq+sR)
lSq = nSq*dR
sR = 0d0
DO i = 1, nL
sR = sR + rL**(i-1)
ENDDO
dL = L/sR
CALL lobatto_set(nPolynom, xGridNodes)
np1=-1 ! outmost grid point in counting algorithm is wall!
np10=-1 ! outmost grid point in counting algorithm is wall!
deltaR = 0
deltaRmin = R
deltaRThmin = R*alpha
deltaZmin = L
thMin = PI/2.
deltaRmax = 0
deltaRThmax = 0
deltaZmax = 0
thMax = PI/2.
ALLOCATE( elem(nEl) )
!==============================================================================
! write a little output to screen
WRITE(*,*)
WRITE(*,'(a)') '--> Geometry data:'
WRITE(*,*)
WRITE(*,'(4x,a4,1x,f7.3)') 'R =', R
WRITE(*,'(4x,a4,1x,f7.3)') 'L =', L
WRITE(*,*)
WRITE(*,'(4x,a4,1x,f7.3,3x,a6,1x,f7.3,1x,a4,1x,f7.3)') 'rR =', rR, '| e0 =', dR, 'e1 =', rR**(nR -1)*dR
WRITE(*,'(4x,a4,1x,f7.3,3x,a6,1x,f7.3,1x,a4,1x,f7.3)') 'rL =', rL, '| e0 =', dL, 'e1 =', rL**(nL -1)*dL
WRITE(*,*)
WRITE(*,*)
WRITE(*,'(a)') '--> Element data:'
WRITE(*,*)
WRITE(*,'(4x,a6,1x,i10)') 'nFpp =', nFpp
WRITE(*,*)
!WRITE(*,'(4x,a6,1x,i10)') 'nPp =', nPp
!WRITE(*,*)
WRITE(*,'(4x,a6,1x,i10)') 'nEl =', nEl
WRITE(*,*)
!==============================================================================
! create the mesh
i = 0
! 1/4 of first face
!
! SQUARE PART
!
DO row = 1, nSq
!
DO col = 1, nSq
!
i = i + 1
!
elem(i)%num = i
elem(i)%group = 1
elem(i)%curvedEdge(:) = .FALSE.
elem(i)%bcType(:) = 'E'
elem(i)%bcType(5) = 'v'
! front face
elem(i)%bcParameters(5,1) = i-nFpp
elem(i)%bcParameters(5,2) = 6
! back face
elem(i)%bcParameters(6,1) = i+nFpp
elem(i)%bcParameters(6,2) = 5
! right face
IF ( col .NE. nSq ) THEN
elem(i)%bcParameters(3,1) = i+1
elem(i)%bcParameters(3,2) = 1
ELSE
elem(i)%bcParameters(3,1) = nSq**2+nSq
elem(i)%bcParameters(3,2) = 1
ENDIF
! left face
IF ( col .NE. 1 ) THEN
elem(i)%bcParameters(1,1) = i-1
elem(i)%bcParameters(1,2) = 3
ELSE
elem(i)%bcParameters(1,1) = nFpp4+1
elem(i)%bcParameters(1,2) = 4
ENDIF
! bottom face
IF ( row .NE. 1 ) THEN
elem(i)%bcParameters(4,1) = i-nSq
elem(i)%bcParameters(4,2) = 2
ELSE
elem(i)%bcParameters(4,1) = 1-nFpp4 + (col-1)*nSq
elem(i)%bcParameters(4,2) = 1
ENDIF
! top face
IF ( row .NE. nSq ) THEN
elem(i)%bcParameters(2,1) = i+nSq
elem(i)%bcParameters(2,2) = 4
ELSE
elem(i)%bcParameters(2,1) = nSq**2+2*nSq-col+1
elem(i)%bcParameters(2,2) = 1
ENDIF
IF ( col > row ) THEN
! lower right part
iR = lSq/nSq * (col-1) * (rP0 + (rP1-rP0)/nSq*(col-1))
oR = lSq/nSq * col * (rP0 + (rP1-rP0)/nSq* col )
elem(i)%curvedEdge(1) = .TRUE.
elem(i)%curvedEdge(3) = .TRUE.
elem(i)%curvedEdge(5) = .TRUE.
elem(i)%curvedEdge(7) = .TRUE.
elem(i)%curvedEdgeR(1) = -iR
elem(i)%curvedEdgeR(3) = oR
elem(i)%curvedEdgeR(5) = -iR
elem(i)%curvedEdgeR(7) = oR
elem(i)%y(1) = elem(i-1)%y(4)
elem(i)%y(2) = elem(i-1)%y(3)
! elem(i)%y(3) = oR * DCOS( DASIN((elem(i-1)%x(3)+(oR-lSq/nSq*col)*SQ22)/oR) ) &
! - (oR - lSq/nSq*col)*SQ22 * 1.5*(nSq-col+2)
! elem(i)%y(4) = oR * DCOS( DASIN((elem(i-1)%x(4)+(oR-lSq/nSq*col)*SQ22)/oR) ) &
! - (oR - lSq/nSq*col)*SQ22 * 1.5*(nSq-col+2)
elem(i)%y(3) = oR * DCOS( DASIN(elem(i-1)%x(3)/oR) ) &
- (oR*DCOS(DASIN(lSq/nSq*col*SQ22/oR)) - lSq/nSq*col*SQ22)
elem(i)%y(4) = oR * DCOS( DASIN(elem(i-1)%x(4)/oR) ) &
- (oR*DCOS(DASIN(lSq/nSq*col*SQ22/oR)) - lSq/nSq*col*SQ22)
elem(i)%x(1) = elem(i-1)%x(4)
elem(i)%x(2) = elem(i-1)%x(3)
elem(i)%x(3) = elem(i)%x(2)
elem(i)%x(4) = elem(i)%x(1)
if ( debugFlag ) then
write(*,*) 'lr ', row, col, rP0+(rP1-rP0)/nSq*col
endif
ELSEIF ( row > col ) THEN
! upper left part
iR = lSq/nSq * (row-1) * (rP0 + (rP1-rP0)/nSq*(row-1))
oR = lSq/nSq * row * (rP0 + (rP1-rP0)/nSq* row )
elem(i)%curvedEdge(2) = .TRUE.
elem(i)%curvedEdge(4) = .TRUE.
elem(i)%curvedEdge(6) = .TRUE.
elem(i)%curvedEdge(8) = .TRUE.
elem(i)%curvedEdgeR(2) = oR
elem(i)%curvedEdgeR(4) = -iR
elem(i)%curvedEdgeR(6) = oR
elem(i)%curvedEdgeR(8) = -iR
elem(i)%y(1) = elem(i-nSq)%y(2)
elem(i)%y(2) = elem(i)%y(1)
elem(i)%y(3) = elem(i-nSq)%y(3)
elem(i)%y(4) = elem(i)%y(3)
elem(i)%x(1) = elem(i-nSq)%x(2)
! elem(i)%x(2) = oR * DSIN( DACOS((elem(i)%y(2)+(oR-lSq/nSq*row)*SQ22)/oR) ) &
! - (oR - lSq/nSq*row)*SQ22 * 1.5*(nSq-row+2)
! elem(i)%x(3) = oR * DSIN( DACOS((elem(i)%y(4)+(oR-lSq/nSq*row)*SQ22)/oR) ) &
! - (oR - lSq/nSq*row)*SQ22 * 1.5*(nSq-row+2)
elem(i)%x(2) = oR * DSIN( DACOS(elem(i)%y(2)/oR) ) &
- (oR*DCOS(DASIN(lSq/nSq*row*SQ22/oR)) - lSq/nSq*row*SQ22)
elem(i)%x(3) = oR * DSIN( DACOS(elem(i)%y(4)/oR) ) &
- (oR*DCOS(DASIN(lSq/nSq*row*SQ22/oR)) - lSq/nSq*row*SQ22)
elem(i)%x(4) = elem(i-nSq)%x(3)
if ( debugFlag ) then
write(*,*) 'ul ', row, col, rP0+(rP1-rP0)/nSq*row
endif
ELSE
! diagonal
oR = lSq/nSq * row * (rP0 + (rP1-rP0)/nSq*row)
elem(i)%curvedEdge(2) = .TRUE.
elem(i)%curvedEdge(3) = .TRUE.
elem(i)%curvedEdge(6) = .TRUE.
elem(i)%curvedEdge(7) = .TRUE.
elem(i)%curvedEdgeR(2) = oR
elem(i)%curvedEdgeR(3) = oR
elem(i)%curvedEdgeR(6) = oR
elem(i)%curvedEdgeR(7) = oR
elem(i)%y(1) = lSq/nSq * (row-1) * SQ22
elem(i)%y(2) = elem(i)%y(1)
elem(i)%y(3) = lSq/nSq * row * SQ22
! elem(i)%y(4) = oR * DCOS( DASIN((lSq/nSq*(row-1)*SQ22+(oR-lSq/nSq*col)*SQ22)/oR) ) &
! - (oR - lSq/nSq*row)*SQ22 * 1.5*(nSq-row+2)
elem(i)%y(4) = oR * DCOS( DASIN(lSq/nSq*(row-1)*SQ22/oR) ) &
- (oR*DCOS(DASIN(lSq/nSq*col*SQ22/oR)) - lSq/nSq*col*SQ22)
elem(i)%x(1) = lSq/nSq * (row-1) * SQ22
! elem(i)%x(2) = oR * DSIN( DACOS((elem(i)%y(2)+(oR-lSq/nSq*col)*SQ22)/oR) ) &
! - (oR - lSq/nSq*row)*SQ22 * 1.5*(nSq-row+2)
elem(i)%x(2) = oR * DSIN( DACOS(elem(i)%y(2)/oR) ) &
- (oR*DCOS(DASIN(lSq/nSq*row*SQ22/oR)) - lSq/nSq*row*SQ22)
elem(i)%x(3) = lSq/nSq * row * SQ22
elem(i)%x(4) = elem(i)%x(1)
if ( debugFlag ) then
write(*,*) 'd ', row, oR
endif
ENDIF
elem(i)%y(5) = elem(i)%y(1)
elem(i)%y(6) = elem(i)%y(2)
elem(i)%y(7) = elem(i)%y(3)
elem(i)%y(8) = elem(i)%y(4)
elem(i)%x(5) = elem(i)%x(1)
elem(i)%x(6) = elem(i)%x(2)
elem(i)%x(7) = elem(i)%x(3)
elem(i)%x(8) = elem(i)%x(4)
elem(i)%z(1) = 0d0
elem(i)%z(2) = 0d0
elem(i)%z(3) = 0d0
elem(i)%z(4) = 0d0
elem(i)%z(5) = 0d0 + dL
elem(i)%z(6) = 0d0 + dL
elem(i)%z(7) = 0d0 + dL
elem(i)%z(8) = 0d0 + dL
ENDDO
ENDDO
!
! CIRCULAR PART
!
iR = lSq*rP1
oR = lSq + dR*rR
col = 1
DO row = 1, nTh/8
!
i = i + 1
!
elem(i)%num = i
elem(i)%group = 1
elem(i)%curvedEdge(:) = .FALSE.
elem(i)%curvedEdge(1) = .TRUE.
elem(i)%curvedEdge(3) = .TRUE.
elem(i)%curvedEdge(5) = .TRUE.
elem(i)%curvedEdge(7) = .TRUE.
elem(i)%curvedEdgeR(1) = -iR
elem(i)%curvedEdgeR(3) = oR
elem(i)%curvedEdgeR(5) = -iR
elem(i)%curvedEdgeR(7) = oR
elem(i)%bcType(:) = 'E'
elem(i)%bcType(5) = 'v'
! front face
elem(i)%bcParameters(5,1) = i-nFpp
elem(i)%bcParameters(5,2) = 6
! back face
elem(i)%bcParameters(6,1) = i+nFpp
elem(i)%bcParameters(6,2) = 5
! right face
elem(i)%bcParameters(3,1) = i+nTh/4
elem(i)%bcParameters(3,2) = 1
! left face
elem(i)%bcParameters(1,1) = row*nSq
elem(i)%bcParameters(1,2) = 3
! bottom face
IF ( row .NE. 1 ) THEN
elem(i)%bcParameters(4,1) = i-1
elem(i)%bcParameters(4,2) = 2
ELSE
elem(i)%bcParameters(4,1) = 1-nFpp4+nSq**2+nTh/8
elem(i)%bcParameters(4,2) = 2
ENDIF
! top face
elem(i)%bcParameters(2,1) = i+1
elem(i)%bcParameters(2,2) = 4
elem(i)%y(1) = elem(nSq*row)%y(4)
elem(i)%y(2) = elem(nSq*row)%y(3)
elem(i)%y(3) = oR * COS(alpha*row)
elem(i)%y(4) = oR * COS(alpha*(row-1))
elem(i)%y(5) = elem(i)%y(1)
elem(i)%y(6) = elem(i)%y(2)
elem(i)%y(7) = elem(i)%y(3)
elem(i)%y(8) = elem(i)%y(4)
elem(i)%x(1) = elem(nSq*row)%x(4)
elem(i)%x(2) = elem(nSq*row)%x(3)
elem(i)%x(3) = oR * SIN(alpha*row)
elem(i)%x(4) = oR * SIN(alpha*(row-1))
elem(i)%x(5) = elem(i)%x(1)
elem(i)%x(6) = elem(i)%x(2)
elem(i)%x(7) = elem(i)%x(3)
elem(i)%x(8) = elem(i)%x(4)
elem(i)%z(1) = 0d0
elem(i)%z(2) = 0d0
elem(i)%z(3) = 0d0
elem(i)%z(4) = 0d0
elem(i)%z(5) = 0d0 + dL
elem(i)%z(6) = 0d0 + dL
elem(i)%z(7) = 0d0 + dL
elem(i)%z(8) = 0d0 + dL
ENDDO
row = 1
DO col = 1, nTh/8
!
i = i + 1
!
elem(i)%num = i
elem(i)%group = 1
elem(i)%curvedEdge(:) = .FALSE.
elem(i)%curvedEdge(1) = .TRUE.
elem(i)%curvedEdge(3) = .TRUE.
elem(i)%curvedEdge(5) = .TRUE.
elem(i)%curvedEdge(7) = .TRUE.
elem(i)%curvedEdgeR(1) = -iR
elem(i)%curvedEdgeR(3) = oR
elem(i)%curvedEdgeR(5) = -iR
elem(i)%curvedEdgeR(7) = oR
elem(i)%bcType(:) = 'E'
elem(i)%bcType(5) = 'v'
! front face
elem(i)%bcParameters(5,1) = i-nFpp
elem(i)%bcParameters(5,2) = 6
! back face
elem(i)%bcParameters(6,1) = i+nFpp
elem(i)%bcParameters(6,2) = 5
! right face
elem(i)%bcParameters(3,1) = i+nTh/4
elem(i)%bcParameters(3,2) = 1
! left face
elem(i)%bcParameters(1,1) = nSq**2-col+1
elem(i)%bcParameters(1,2) = 2
! bottom face
elem(i)%bcParameters(4,1) = i-1
elem(i)%bcParameters(4,2) = 2
! top face
IF ( col .NE. nSq ) THEN
elem(i)%bcParameters(2,1) = i+1
elem(i)%bcParameters(2,2) = 4
ELSE
elem(i)%bcParameters(2,1) = nFpp4+nSq**2+1
elem(i)%bcParameters(2,2) = 4
ENDIF
elem(i)%y(1) = elem(nSq**2+1-col)%y(3)
elem(i)%y(2) = elem(nSq**2+1-col)%y(2)
elem(i)%y(3) = oR * COS(PI/4+alpha*col)
elem(i)%y(4) = oR * COS(PI/4+alpha*(col-1))
elem(i)%y(5) = elem(i)%y(1)
elem(i)%y(6) = elem(i)%y(2)
elem(i)%y(7) = elem(i)%y(3)
elem(i)%y(8) = elem(i)%y(4)
elem(i)%x(1) = elem(nSq**2+1-col)%x(3)
elem(i)%x(2) = elem(nSq**2+1-col)%x(2)
elem(i)%x(3) = oR * SIN(PI/4+alpha*col)
elem(i)%x(4) = oR * SIN(PI/4+alpha*(col-1))
elem(i)%x(5) = elem(i)%x(1)
elem(i)%x(6) = elem(i)%x(2)
elem(i)%x(7) = elem(i)%x(3)
elem(i)%x(8) = elem(i)%x(4)
elem(i)%z(1) = 0d0
elem(i)%z(2) = 0d0
elem(i)%z(3) = 0d0
elem(i)%z(4) = 0d0
elem(i)%z(5) = 0d0 + dL
elem(i)%z(6) = 0d0 + dL
elem(i)%z(7) = 0d0 + dL
elem(i)%z(8) = 0d0 + dL
ENDDO
!
! other columns of the circular part
!
de = dR*rR**2
DO row = 1, (nR-nSq-1)
!iR = lSq + dR
!oR = lSq + de + dR
iR = oR
oR = iR + de
!dR = de + dR
de = rR*de
DO col = 1, nTh/4
!
i = i + 1
!
elem(i)%num = i
elem(i)%group = 1
elem(i)%curvedEdge(:) = .FALSE.
elem(i)%curvedEdge(3) = .TRUE.
elem(i)%curvedEdge(7) = .TRUE.
elem(i)%curvedEdge(1) = .TRUE.
elem(i)%curvedEdge(5) = .TRUE.
elem(i)%curvedEdgeR(3) = oR
elem(i)%curvedEdgeR(7) = oR
elem(i)%curvedEdgeR(1) = -iR
elem(i)%curvedEdgeR(5) = -iR
elem(i)%bcType(:) = 'E'
elem(i)%bcType(5) = 'v'
! front face
elem(i)%bcParameters(5,1) = i-nFpp
elem(i)%bcParameters(5,2) = 6
! back face
elem(i)%bcParameters(6,1) = i+nFpp
elem(i)%bcParameters(6,2) = 5
! right face
elem(i)%bcParameters(3,1) = i+nTh/4
elem(i)%bcParameters(3,2) = 1
! left face
elem(i)%bcParameters(1,1) = i-nTh/4
elem(i)%bcParameters(1,2) = 3
! bottom face
IF ( col .NE. 1 ) THEN
elem(i)%bcParameters(4,1) = i-1
elem(i)%bcParameters(4,2) = 2
ELSE
elem(i)%bcParameters(4,1) = -nFpp4+nSq**2+nTh/4*row
elem(i)%bcParameters(4,2) = 2
ENDIF
! top face
IF ( col .NE. nTh/4 ) THEN
elem(i)%bcParameters(2,1) = i+1
elem(i)%bcParameters(2,2) = 4
ELSE
elem(i)%bcParameters(2,1) = nFpp4+nSq**2+nTh/4*row+1
elem(i)%bcParameters(2,2) = 4
ENDIF
elem(i)%y(1) = elem(i-nTh/4)%y(4)
elem(i)%y(2) = elem(i-nTh/4)%y(3)
elem(i)%y(3) = oR * COS(alpha*col)
elem(i)%y(4) = oR * COS(alpha*(col-1))
elem(i)%y(5) = elem(i)%y(1)
elem(i)%y(6) = elem(i)%y(2)
elem(i)%y(7) = elem(i)%y(3)
elem(i)%y(8) = elem(i)%y(4)
elem(i)%x(1) = elem(i-nTh/4)%x(4)
elem(i)%x(2) = elem(i-nTh/4)%x(3)
elem(i)%x(3) = oR * SIN(alpha*col)
elem(i)%x(4) = oR * SIN(alpha*(col-1))
elem(i)%x(5) = elem(i)%x(1)
elem(i)%x(6) = elem(i)%x(2)
elem(i)%x(7) = elem(i)%x(3)
elem(i)%x(8) = elem(i)%x(4)
elem(i)%z(1) = 0d0
elem(i)%z(2) = 0d0
elem(i)%z(3) = 0d0
elem(i)%z(4) = 0d0
elem(i)%z(5) = 0d0 + dL
elem(i)%z(6) = 0d0 + dL
elem(i)%z(7) = 0d0 + dL
elem(i)%z(8) = 0d0 + dL
ENDDO
ENDDO
!
! add "Wall" boundary condition on the external elements
!
DO j = nFpp4-nTh/4+1, nFpp4
elem(j)%bcType(3) = 'W'
ENDDO
! calculate a few grid measures in wall-units
! Cf. mesh description in [El Khoury 13]
! delta-r^+ : distance between (pipe) wall and outmost gridpoint
! delta-R^+ : min and max
! delta-R^Theta+ : min and max
! delta-Z^+ : min and max
! And: element corner-angle (in degrees)
! theta : min and max
! OBS: accounts (only) for linear (!) element deformation!
! BUT the curved mesh faces are concentric for the outer element-rings!
! --> should be correct
! Loop over all elements
DO j = 1, nFpp4
! Minimal and maximal element-corner angle
xTmp1 = (elem(j)%x(4)-elem(j)%x(1))
yTmp1 = (elem(j)%y(4)-elem(j)%y(1))
xTmp2 = (elem(j)%x(2)-elem(j)%x(1))
yTmp2 = (elem(j)%y(2)-elem(j)%y(1))
thMin = min(thMin, DACOS((xTmp1*xTmp2 + yTmp1*yTmp2)/ &
SQRT((xTmp1**2+yTmp1**2)*(xTmp2**2+yTmp2**2))))
thMax = max(thMax, DACOS((xTmp1*xTmp2 + yTmp1*yTmp2)/ &
SQRT((xTmp1**2+yTmp1**2)*(xTmp2**2+yTmp2**2))))
xTmp1 = (elem(j)%x(3)-elem(j)%x(2))
yTmp1 = (elem(j)%y(3)-elem(j)%y(2))
thMin = min(thMin, PI-DACOS((xTmp1*xTmp2 + yTmp1*yTmp2)/ &
SQRT((xTmp1**2+yTmp1**2)*(xTmp2**2+yTmp2**2))))
thMax = max(thMax, PI-DACOS((xTmp1*xTmp2 + yTmp1*yTmp2)/ &
SQRT((xTmp1**2+yTmp1**2)*(xTmp2**2+yTmp2**2))))
xTmp2 = (elem(j)%x(4)-elem(j)%x(3))
yTmp2 = (elem(j)%y(4)-elem(j)%y(3))
thMin = min(thMin, PI-DACOS((xTmp1*xTmp2 + yTmp1*yTmp2)/ &
SQRT((xTmp1**2+yTmp1**2)*(xTmp2**2+yTmp2**2))))
thMax = max(thMax, PI-DACOS((xTmp1*xTmp2 + yTmp1*yTmp2)/ &
SQRT((xTmp1**2+yTmp1**2)*(xTmp2**2+yTmp2**2))))
xTmp1 = (elem(j)%x(1)-elem(j)%x(4))
yTmp1 = (elem(j)%y(1)-elem(j)%y(4))
thMin = min(thMin, DACOS((xTmp1*xTmp2 + yTmp1*yTmp2)/ &
SQRT((xTmp1**2+yTmp1**2)*(xTmp2**2+yTmp2**2))))
thMax = max(thMax, DACOS((xTmp1*xTmp2 + yTmp1*yTmp2)/ &
SQRT((xTmp1**2+yTmp1**2)*(xTmp2**2+yTmp2**2))))
! Iterate over all GLL-Nodes (only of interior elements)
! (Otherwise, delta-r-max would immediately be on the outer ring)
IF (J .GT. nFpp4-nTh/4) THEN
CYCLE
ENDIF
DO k = 2, nPolynom+1
DO m = 2, nPolynom+1
! xTmp1 and xTmp2, respectively,
! correspond to temporary points G and F in (GeoGebra-file) sketch.ggb
xTmp1 = elem(j)%x(1) + (1.+xGridNodes(k))*.5*(elem(j)%x(4)-elem(j)%x(1))
yTmp1 = elem(j)%y(1) + (1.+xGridNodes(k))*.5*(elem(j)%y(4)-elem(j)%y(1))
xTmp2 = elem(j)%x(2) + (1.+xGridNodes(k))*.5*(elem(j)%x(3)-elem(j)%x(2))
yTmp2 = elem(j)%y(2) + (1.+xGridNodes(k))*.5*(elem(j)%y(3)-elem(j)%y(2))
deltaRmin = min(deltaRmin,SQRT( &
((xGridNodes(m)-xGridNodes(m-1))*.5*(xTmp2-xTmp1))**2 + &
((xGridNodes(m)-xGridNodes(m-1))*.5*(yTmp2-yTmp1))**2))
deltaRmax = max(deltaRmax,SQRT( &
((xGridNodes(m)-xGridNodes(m-1))*.5*(xTmp2-xTmp1))**2 + &
((xGridNodes(m)-xGridNodes(m-1))*.5*(yTmp2-yTmp1))**2))
! Minimize/Maximize along both dimensions ..
xTmp1 = elem(j)%x(1) + (1.+xGridNodes(k))*.5*(elem(j)%x(2)-elem(j)%x(1))
yTmp1 = elem(j)%y(1) + (1.+xGridNodes(k))*.5*(elem(j)%y(2)-elem(j)%y(1))
xTmp2 = elem(j)%x(4) + (1.+xGridNodes(k))*.5*(elem(j)%x(3)-elem(j)%x(4))
yTmp2 = elem(j)%y(4) + (1.+xGridNodes(k))*.5*(elem(j)%y(3)-elem(j)%y(4))
deltaRmin = min(deltaRmin,SQRT( &
((xGridNodes(m)-xGridNodes(m-1))*.5*(xTmp2-xTmp1))**2 + &
((xGridNodes(m)-xGridNodes(m-1))*.5*(yTmp2-yTmp1))**2))
deltaRmax = max(deltaRmax,SQRT( &
((xGridNodes(m)-xGridNodes(m-1))*.5*(xTmp2-xTmp1))**2 + &
((xGridNodes(m)-xGridNodes(m-1))*.5*(yTmp2-yTmp1))**2))
ENDDO
ENDDO
ENDDO
! Iterate one elements-row inwards from wall
j = nFpp4-nTh/4+1
DO WHILE ( (deltaR*reTau/R) .LT. 10. )
! NOTE: that the element vertices are double-counted (intentionally)!
DO k = 1, nPolynom+1
xTmp1 = elem(j)%x(4) + (1.+xGridNodes(k))*.5*(elem(j)%x(1)-elem(j)%x(4))
yTmp1 = elem(j)%y(4) + (1.+xGridNodes(k))*.5*(elem(j)%y(1)-elem(j)%y(4))
deltaR = R - SQRT(xTmp1**2 + yTmp1**2)
IF ( (deltaR*reTau/R) .LT. 10. ) THEN
nP10 = nP10 +1
IF ( (deltaR*reTau/R) .LT. 1. ) THEN
nP1 = nP1 +1
ENDIF
ENDIF
ENDDO
j = INT(elem(j)%bcParameters(1,1))
! For "interior face" BC-Type ('E') the connectivity seems to be not guaranteed
IF (nP10 .GT. 1000) THEN
WRITE(*,*) 'pipeMeshNek seems stuck while counting grid points'
WRITE(*,*) 'STOP.'
STOP
ENDIF
ENDDO
j = nFpp4-nTh/4+2
xTmp1 = elem(j)%x(1) + (1.+xGridNodes(nPolynom))*.5*(elem(j)%x(4)-elem(j)%x(1))
yTmp1 = elem(j)%y(1) + (1.+xGridNodes(nPolynom))*.5*(elem(j)%y(4)-elem(j)%y(1))
deltaR = R-SQRT(xTmp1**2 + yTmp1**2)
DO k = 2, nPolynom+1
xTmp1 = elem(j)%x(3) + (1.+xGridNodes(k))*.5*(elem(j)%x(4)-elem(j)%x(3))
yTmp1 = elem(j)%y(3) + (1.+xGridNodes(k))*.5*(elem(j)%y(4)-elem(j)%y(3))
xTmp2 = elem(j)%x(3) + (1.+xGridNodes(k-1))*.5*(elem(j)%x(4)-elem(j)%x(3))
yTmp2 = elem(j)%y(3) + (1.+xGridNodes(k-1))*.5*(elem(j)%y(4)-elem(j)%y(3))
deltaRThmin = min(deltaRThmin, &
R*ABS(DATAN(yTmp1/xTmp1) - DATAN(yTmp2/xTmp2)))
deltaRThmax = max(deltaRThmax, &
R*ABS(DATAN(yTmp1/xTmp1) - DATAN(yTmp2/xTmp2)))
ENDDO
WRITE(*,*) 'delta r Plus (outmost grid) ', deltaR*reTau/R
WRITE(*,*) '# grid points < delta r+=1 ', np1
WRITE(*,*) '# grid points < delta r+=10 ', np10
WRITE(*,*) 'Theta min [°] ', thMin/PI*180.
WRITE(*,*) 'Theta max [°] ', thMax/PI*180.
WRITE(*,*) 'delta r Plus min ', deltaRmin*reTau/R
! squareroot of two for diagonals
WRITE(*,*) 'delta r Plus max ', SQRT(2d0)*deltaRmax*reTau/R
WRITE(*,*) 'delta R Theta Plus min ', deltaRThmin*reTau/R
WRITE(*,*) 'delta R Theta Plus max ', deltaRThmax*reTau/R
!
! "mirror" the first 1/4 face on the other quarters
!
DO i = i+1, 2*nFpp4
elem(i)%num = i
elem(i)%group = 1
elem(i)%curvedEdge(:) = elem(i-nFpp4)%curvedEdge(:)
elem(i)%curvedEdgeR(:) = elem(i-nFpp4)%curvedEdgeR(:)
elem(i)%bcType(:) = elem(i-nFpp4)%bcType(:)
elem(i)%bcParameters(:,1) = elem(i-nFpp4)%bcParameters(:,1)+nFpp4
elem(i)%bcParameters(:,2) = elem(i-nFpp4)%bcParameters(:,2)
elem(i)%y(:) = - elem(i-nFpp4)%x(:)
elem(i)%x(:) = elem(i-nFpp4)%y(:)
elem(i)%z(:) = elem(i-nFpp4)%z(:)
ENDDO
DO i = i, 3*nFpp4
elem(i)%num = i
elem(i)%group = 1
elem(i)%curvedEdge(:) = elem(i-2*nFpp4)%curvedEdge(:)
elem(i)%curvedEdgeR(:) = elem(i-2*nFpp4)%curvedEdgeR(:)
elem(i)%bcType(:) = elem(i-2*nFpp4)%bcType(:)
elem(i)%bcParameters(:,1) = elem(i-2*nFpp4)%bcParameters(:,1)+2*nFpp4
elem(i)%bcParameters(:,2) = elem(i-2*nFpp4)%bcParameters(:,2)
elem(i)%y(:) = - elem(i-2*nFpp4)%y(:)
elem(i)%x(:) = - elem(i-2*nFpp4)%x(:)
elem(i)%z(:) = elem(i-2*nFpp4)%z(:)
ENDDO
DO i = i, 4*nFpp4
elem(i)%num = i
elem(i)%group = 1
elem(i)%curvedEdge(:) = elem(i-3*nFpp4)%curvedEdge(:)
elem(i)%curvedEdgeR(:) = elem(i-3*nFpp4)%curvedEdgeR(:)
elem(i)%bcType(:) = elem(i-3*nFpp4)%bcType(:)
elem(i)%bcParameters(:,1) = elem(i-3*nFpp4)%bcParameters(:,1)+3*nFpp4
elem(i)%bcParameters(:,2) = elem(i-3*nFpp4)%bcParameters(:,2)
elem(i)%y(:) = elem(i-3*nFpp4)%x(:)
elem(i)%x(:) = - elem(i-3*nFpp4)%y(:)
elem(i)%z(:) = elem(i-3*nFpp4)%z(:)
ENDDO
i = i - 1
!
! correct boundary conditions at "glue side"
!
DO j = 1, nSq
elem(j)%bcParameters(4,1) = 3*nFpp4+(j-1)*nSq+1
elem(3*nFpp4+(j-1)*nSq+1)%bcParameters(1,1) = j
ENDDO
DO j = 1, (nR-nSq)
elem(nSq**2+1+(j-1)*nTh/4)%bcParameters(4,1) = 3*nFpp4+nSq**2+nTh/4*j
elem(3*nFpp4+nSq**2+nTh/4*j)%bcParameters(2,1) = nSq**2+1+(j-1)*nTh/4
ENDDO
!
! advance the face to the end of the pipe
!
de = rL * dL
deltaZmin = min(deltaZmin,de)
deltaZmax = max(deltaZmax,de)
DO j = 1, nL-1
deltaZmin = min(deltaZmin,de)
deltaZmax = max(deltaZmax,de)
CALL advanceFace (1 + nFpp*(j-1), nFpp*j, de, elem)
de = rL * de
i = i + nFpp
IF ( j .EQ. 1 ) THEN
elem(1+nFpp:nFpp*2)%bcType(5) = 'E'
ENDIF
ENDDO
!
! add PERIODIC boundary conditions on first and last face
!
DO j = i-nFpp+1, i
! write last face
elem(j)%bcType(6) = 'P' ! O
elem(j)%bcParameters(6,1) = j-nPp+nFpp
! and correct periodicity on the first face
elem(j-nPp+nFpp)%bcType(5) = 'P' ! v
elem(j-nPp+nFpp)%bcParameters(5,1) = j
ENDDO
WRITE(*,*) 'delta z Plus min ', 0.5*(xGridNodes(nPolynom+1)-xGridNodes(nPolynom)) &
*deltaZmin*reTau/R
WRITE(*,*) 'delta z Plus max ', 0.5*(xGridNodes(nPolynom/2+2)-xGridNodes(nPolynom/2+1)) &
*deltaZmax*reTau/R
!==============================================================================
! clean up
! eliminate useless parameters in boundary conditions
!
! now we also have periodic elements
!!!DO i = 1, nEl
!!! DO j = 1, 6
!!! IF ( elem(i)%bcType(j) .NE. 'E' ) THEN
!!! elem(i)%bcParameters(j,:) = 0
!!! ENDIF
!!! ENDDO
!!!ENDDO
! count curved edges
!
nCurvedEdges = 0
DO i = 1, nEl
DO j = 1, 8
IF ( elem(i)%curvedEdge(j) ) nCurvedEdges = nCurvedEdges + 1
ENDDO
ENDDO
! set to zero any "approximate" zero
!
DO i = 1, nEl
DO j = 1, 8
IF ( abs(elem(i)%x(j)) .LE. 1d-15 ) THEN
elem(i)%x(j) = 0d0
ENDIF
IF ( abs(elem(i)%y(j)) .LE. 1d-15 ) THEN
elem(i)%y(j) = 0d0
ENDIF
IF ( abs(elem(i)%z(j)) .LE. 1d-15 ) THEN
elem(i)%z(j) = 0d0
ENDIF
ENDDO
ENDDO
!==============================================================================
! initialize nameRea
WRITE(nameRea,'(a)') 'base.rea'
INQUIRE (FILE=trim(nameRea), EXIST=existFlag)
IF (existFlag) THEN
WRITE(*,*) '*************************************'
!WRITE(*,*) '*** ERROR: ***'
WRITE(*,*) '*** WARNING: ***'
WRITE(*,*) '*** File already present ***'
WRITE(*,*) '*** ', trim(nameRea), ' ***'
WRITE(*,*) '*************************************'
WRITE(*,*) 'OVERWRITING.'
!WRITE(*,*) 'STOP.'
!STOP
ENDIF
!ELSE
!OPEN(UNIT=fid3d, FILE=trim(nameRea), STATUS='new', ACTION='write')
OPEN(UNIT=fid3d, FILE=trim(nameRea), ACTION='write')
CALL initializeMeshFile(fid3d, Re, dt, nsteps, iostep, debugFlag)
!ENDIF
WRITE(nameRea,'(a)') 'base2d.rea'
INQUIRE (FILE=trim(nameRea), EXIST=existFlag)
IF (existFlag) THEN
WRITE(*,*) '*************************************'
!WRITE(*,*) '*** ERROR: ***'
WRITE(*,*) '*** WARNING: ***'
WRITE(*,*) '*** File already present ***'