-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcurved_tet.f90
More file actions
1662 lines (1287 loc) · 44.1 KB
/
curved_tet.f90
File metadata and controls
1662 lines (1287 loc) · 44.1 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
module curved_tet
use var_array
use tetmesher
use tet_props
use lag_basis
use op_cascade
use mpi_comm_mod
use timing
use master_elem_distrib
implicit none
private
real*8, parameter :: Radius = 2.0d0
logical :: LOAD_BALANCE_BASED_ON_BOUNDARY = .true.
public :: master2curved_tet
public :: master2curved_edg_tet
public :: curved_tetgen_geom
! testers
public :: tester1
contains
subroutine Suv(u, v, S)
implicit none
real*8, intent(in) :: u, v
real*8, dimension(:), intent(out) :: S
S(1) = u
S(2) = v
S(3) = sqrt(Radius**2 - u**2 - v**2)
! S(3) = .5d0 - u - v
! done here
end subroutine Suv
subroutine master2curved_tet(r,s,t, uv, xA, x, y, z)
implicit none
real*8, intent(in) :: r, s, t
real*8, dimension(:, :), intent(in) :: uv
real*8, dimension(:), intent(in) :: xA
real*8, intent(out) :: x, y, z
! local vars
integer :: ii
real*8 :: u, v, alpha
real*8, dimension(3) :: Sf, xf
!
real*8 :: val ! the value of basis
real*8, dimension(2) :: der, uv_fin
if ( abs(t - 1.0d0) <= 1.0d-15 ) then
u = r ! simple
v = s ! simple
else
u = r/(1-t)
v = s/(1-t)
end if
alpha = t
! compute final uv
uv_fin = 0.0d0
do ii = 1, 3
call psi(etype = 1, i = ii, r = u, s = v, val = val, der = der)
uv_fin = uv_fin + val * uv(:, ii)
end do
! compute surface points
call Suv(u = uv_fin(1), v= uv_fin(2), S = Sf)
xf = alpha * xA + (1.0d0 - alpha) * Sf
x = xf(1)
y = xf(2)
z = xf(3)
! done here
end subroutine master2curved_tet
subroutine master2curved_edg_tet(r,s,t, uv, x3, x4, x, y, z)
implicit none
real*8, intent(in) :: r, s, t
real*8, dimension(:, :), intent(in) :: uv ! uv(1:2, 1:2)
real*8, dimension(:), intent(in) :: x3, x4
real*8, intent(out) :: x, y, z
! local vars
real*8 :: u, v, alpha, u0
real*8, dimension(3) :: Sf, xf, Sc
!
real*8, dimension(2) :: uv_fin
if ( abs(t - 1.0d0) <= 1.0d-15 ) then
u = r ! simple
v = s ! simple
else
u = r/(1-t)
v = s/(1-t)
end if
alpha = t
! compute final uv
if ( abs(v - 1.0d0) <= 1.0d-15 ) then
u0 = u ! simple
else
u0 = u/(1-v)
end if
uv_fin = uv(:, 1) + u0 * (uv(:, 2) - uv(:, 1))
! compute surface points
call Suv(u = uv_fin(1), v= uv_fin(2), S = Sc)
Sf = v * x3 + (1.0d0 - v) * Sc
xf = alpha * x4 + (1.0d0 - alpha) * Sf
x = xf(1)
y = xf(2)
z = xf(3)
! done here
end subroutine master2curved_edg_tet
!
! This tests a set of three tetrahedrons
! that exhibit two possible cases of mounting
! on a curved surface:
!
! 1 - one face on surface
! 2 - only one edge on the surface
!
! a sphere is used as exact surface representation
!
subroutine tester1()
implicit none
! local vars
integer :: d, i
real*8, dimension(:), allocatable :: r, s, t, x, y, z
real*8, dimension(3) :: xA, x3, x4
real*8, dimension(2, 3) :: uv
! generate the lagrangian tet. interpolation points
d = 8
call coord_tet(d, r, s, t)
allocate(x(size(r)), y(size(r)), z(size(r)))
! element 1
xA = (/ .15d0, .15d0, 2.2d0 /)
uv = reshape( (/ 0.0d0, 0.0d0, .5d0, 0.0d0 &
, 0.0d0, 0.5d0 /), (/2, 3/) )
do i = 1, size(r)
call master2curved_tet( r = r(i), s = s(i), t = t(i), uv = uv &
, xA = xA, x = x(i), y = y(i), z = z(i) )
! call master2curved_tet(r(i),s(i),t(i), xA, x(i), y(i), z(i))
end do
! export the generated curved element
call export_tet_face_curve(x = x, y=y, z=z, mina = 20.0d0 &
, maxa = 155.0d0, fname = 'curved.tec', meshnum = 1, append_it = .false.)
! element 2
xA = (/ .38d0, .38d0, 2.2d0 /)
uv = reshape( (/ 0.5d0, 0.0d0, 0.5d0, 0.5d0 &
, 0.0d0, 0.5d0 /), (/2, 3/) )
do i = 1, size(r)
call master2curved_tet( r = r(i), s = s(i), t = t(i), uv = uv &
, xA = xA, x = x(i), y = y(i), z = z(i) )
! call master2curved_tet(r(i),s(i),t(i), xA, x(i), y(i), z(i))
end do
! export the generated curved element
call export_tet_face_curve(x = x, y=y, z=z, mina = 20.0d0 &
, maxa = 155.0d0, fname = 'curved.tec', meshnum = 2, append_it = .true.)
! element 3
xA = (/ .22d0, .22d0, 3.0d0 /)
uv = reshape( (/ 0.5d0, 0.0d0, 0.0d0, 0.5d0 &
, 0.0d0, 0.0d0 /), (/2, 3/) )
x3 = (/ .15d0, .15d0, 2.2d0 /)
x4 = (/ .38d0, .38d0, 2.2d0 /)
do i = 1, size(r)
call master2curved_edg_tet( r = r(i), s = s(i), t = t(i), uv = uv &
, x3 = x3, x4 = x4, x = x(i), y = y(i), z = z(i) )
end do
! export the generated curved element
call export_tet_face_curve(x = x, y=y, z=z, mina = 20.0d0 &
, maxa = 155.0d0, fname = 'curved.tec', meshnum = 3, append_it = .true.)
! clean ups
if ( allocated(r) ) deallocate(r)
if ( allocated(s) ) deallocate(s)
if ( allocated(t) ) deallocate(t)
if ( allocated(x) ) deallocate(x)
if ( allocated(y) ) deallocate(y)
if ( allocated(z) ) deallocate(z)
! done here
end subroutine tester1
!
subroutine curved_tetgen_geom(tetgen_cmd, facet_file, cad_file, nhole, xh, tol, tmpi)
implicit none
character(len = *), intent(in) :: tetgen_cmd, facet_file, cad_file
integer, intent(in) :: nhole
real*8, dimension(:), intent(in) :: xh
real*8, intent(in) :: tol
class(mpi_comm_t) :: tmpi
! local vars
integer :: ii, jj
integer :: npts, nquad, ntri
real*8, dimension(:), allocatable :: x
integer, dimension(:), allocatable :: icontag
! outs
real*8, dimension(:, :), allocatable :: xf
integer, dimension(:, :), allocatable :: tetcon, neigh
integer :: nbntri
integer, dimension(:), allocatable :: bntri
! integer, dimension(:, :), allocatable :: bntri2bntri
type(int_array), dimension(:), allocatable :: node2bntri
real*8, allocatable :: uu(:, :)
! domain decomposition (graph partitioning) vars
integer, dimension(:), allocatable :: xadj, adj, vwgt, part
integer :: nparts
logical, dimension(:), allocatable :: vis_mask
! vars for boundary-based decomp
integer, dimension(:), allocatable :: inter_elems, near_bn_elems
integer, allocatable :: arrl(:), arrg(:)
integer :: itet
! CAD corresponding data struct
integer, allocatable :: cent_cad_found(:) !nbntri
real*8, allocatable :: uvc(:)
integer, dimension(:, :), allocatable :: tet_shifted
integer, dimension(:), allocatable :: tet2bn_tri, tet_type
! integer :: neigh_CAD_face(3)
logical :: is_CAD_bn_tri
! master element data struct
integer :: dd, indx, CAD_face
real*8, dimension(:), allocatable :: rr, ss, tt, xx, yy, zz
real*8, dimension(3) :: xA
real*8, dimension(3, 3) :: xbot
! visualization data struct
real*8 :: xtet(3, 4), lens(6)
real*8 :: ref_length
character(len = 128) :: outname, this_cpu_wtime
! MPI data struct
integer :: size_arr_on_root(2), len_bntri(1)
real*8 :: tmp_time, root_max_timing(1)
! read the facet file
print *, 'starting curved tetrahedral mesh generator'
print *, 'reading the facet file ...'
call read_facet_file(facet_file, npts, x, nquad, ntri, icontag)
print *, 'the facet file read is complete!'
! !
! ! generic tetmesher subroutine
! !
if ( tmpi%rank .eq. tmpi%root_rank ) then
print *, 'generating initial tetmesh of whole domain ...'
call tetmesh(tetgen_cmd, npts, x, nquad, ntri, icontag, nhole, xh &
, xf, tetcon, neigh, nbntri, bntri)
print *, 'initial tetmesh is done!'
end if
! Broadcast the generated grid info
!
! xf
! first pack the size info
if ( tmpi%rank .eq. tmpi%root_rank ) then
size_arr_on_root = (/ size(xf, 1), size(xf, 2) /)
end if
call tmpi%bcast_int(size_arr_on_root)
! then bcast the data
if ( tmpi%rank .ne. tmpi%root_rank ) then
allocate(xf(size_arr_on_root(1), size_arr_on_root(2)))
end if
do ii = 1, 3
call tmpi%bcast_double(xf(ii, :))
end do
! tetcon
! first pack the size info
if ( tmpi%rank .eq. tmpi%root_rank ) then
size_arr_on_root = (/ size(tetcon, 1), size(tetcon, 2) /)
end if
call tmpi%bcast_int(size_arr_on_root)
! then bcast the data
if ( tmpi%rank .ne. tmpi%root_rank ) then
allocate(tetcon(size_arr_on_root(1), size_arr_on_root(2)))
end if
do jj = 1, 4
call tmpi%bcast_int(tetcon(:, jj))
end do
! neigh
! first pack the size info
if ( tmpi%rank .eq. tmpi%root_rank ) then
size_arr_on_root = (/ size(neigh, 1), size(neigh, 2) /)
end if
call tmpi%bcast_int(size_arr_on_root)
! then bcast the data
if ( tmpi%rank .ne. tmpi%root_rank ) then
allocate(neigh(size_arr_on_root(1), size_arr_on_root(2)))
end if
do jj = 1, 4
call tmpi%bcast_int(neigh(:, jj))
end do
! bntri
! first pack the size info
if ( tmpi%rank .eq. tmpi%root_rank ) len_bntri(1) = nbntri
call tmpi%bcast_int(len_bntri)
nbntri = len_bntri(1)
if ( tmpi%rank .eq. tmpi%root_rank ) len_bntri(1) = size(bntri)
call tmpi%bcast_int(len_bntri)
! alloc.
if ( tmpi%rank .ne. tmpi%root_rank ) then
allocate(bntri(len_bntri(1)))
end if
! then bcast the data
call tmpi%bcast_int(bntri)
! ! find the boundary tri connectivity map
! ! useful for speedup the code when deciding on
! ! UV-projection or closest point
! call find_bntri2bntri_map(nbntri = nbntri, bntri = bntri, bntri2bntri = bntri2bntri)
! ! bullet proofing ...
! if ( any ( bntri2bntri .eq. -1) ) then
! print *, 'boundary triangles are not all connected together! stop'
! stop
! end if
allocate(node2bntri(size(xf, 2)))
call find_node2bntri_map(nbntri = nbntri, bntri = bntri, node2bntri = node2bntri)
! ! export linear tetmesh
! allocate(uu(1, size(xf,2)))
! uu = 1.0d0
! call write_u_tecplot_tet(meshnum=1, outfile='linear_tets.tec', x = xf &
! , icon = tetcon, u = uu, appendit = .false.)
! if ( allocated(uu) ) deallocate(uu)
! find the CAD face of boundary triangles
call find_bn_tris_CAD_face(cad_file = cad_file, nbntri = nbntri &
, bntri = bntri, xf = xf, cent_cad_found = cent_cad_found &
, uvc = uvc, tol = tol)
! prepare the output file name
write (outname, "(A7,I0.3,A4)") "grdPART", tmpi%rank, ".tec"
! shift tetcon for each tet such that the first three nodes
! are matching the boundary triangle face. This is required
! before we apply our analytical transformation
!
allocate( tet_shifted(size(tetcon, 1), size(tetcon, 2)) )
allocate( tet2bn_tri(size(tetcon, 1)), tet_type(size(tetcon, 1)) )
call shift_tetcon(nbntri = nbntri, bntri = bntri &
, tetcon = tetcon, tetcon2 = tet_shifted, tet2bn_tri = tet2bn_tri &
, tet_type = tet_type, cent_cad_found = cent_cad_found)
! generate the lagrangian tet. interpolation points
dd = 12
call coord_tet(dd, rr, ss, tt)
allocate(xx(size(rr)), yy(size(rr)), zz(size(rr)))
! determine the type of load-balance
if ( LOAD_BALANCE_BASED_ON_BOUNDARY ) then
! determine interior and boundary elems
call decomp_based_on_bn(tet_type = tet_type, inter_elems = inter_elems &
, near_bn_elems = near_bn_elems)
! init
indx = 1
! timing
tmp_time = wtime()
! decomp near boundary elems
call equal_decomp_nelem_by_np(nelem = size(near_bn_elems) &
, np = tmpi%np, arr = arrl)
call loc2glob_indx(arrl = arrl, arrg = arrg)
! only do its portion of this process rank
do itet = arrg(tmpi%rank+1), (arrg(tmpi%rank+2)-1)
ii = near_bn_elems(itet) ! get tet number
! pick the appex of the tet required for some mappings
xA = xf(:, tet_shifted(ii, 4))
! compute xbot
do jj = 1, 3
xbot(:, jj) = xf(:, tet_shifted(ii, jj))
end do
! fill this tet coords
do jj = 1, 4
xtet(:, jj) = xf(:, tet_shifted(ii,jj))
end do
select case ( tet_type(ii) )
case ( 0 ) ! interior, use linear (straight map)
! do nothing at this point
case ( 1 ) ! one face (tri) of the tet on CAD boundary
! bullet proofing ...
if ( tet2bn_tri(ii) .eq. -1 ) then
print *, 'This tet is supposed to be one-face-bn' &
, ' tet but is NOT! stop'
stop
end if
!
CAD_face = cent_cad_found(tet2bn_tri(ii))
! bullet proofing ...
if ( CAD_face .eq. -1 ) then !bn tet not on CAD database
print *, 'this boundary-face tet has a CAD face' &
, ' tag equal to -1! stop'
stop
end if
is_CAD_bn_tri = is_tri_near_CAD_boundary(node2bntri = node2bntri &
, CAD_face = cent_cad_found, nodes = tet_shifted(ii, 1:3))
do jj = 1, size(rr)
if ( .not. is_CAD_bn_tri) then
call master2curved_tet_ocas_close(r = rr(jj),s = ss(jj),t = tt(jj) &
, xbot = xbot, xA = xA, tol = tol, x = xx(jj), y = yy(jj) &
, z = zz(jj) &
, CAD_face_input = CAD_face)
else
call master2curved_tet_ocas_close(r = rr(jj),s = ss(jj),t = tt(jj) &
, xbot = xbot, xA = xA, tol = tol, x = xx(jj) &
, y = yy(jj), z = zz(jj))
end if
end do
case (2) ! one-edge-curved-on-CAD tet
do jj = 1, size(rr)
call master2curved_edg_tet_ocas_close(r= rr(jj),s= ss(jj),t= tt(jj) &
, xyz = xtet, x = xx(jj), y = yy(jj), z = zz(jj), tol = tol)
end do
case default
print *, 'unknown tet_type happened! stop'
stop
end select
! ! export the generated curved element
! call tetrahedron_edge_length ( tetra = xtet, edge_length = lens)
! ref_length = 1.5d0 * maxval(lens) / dble(dd)
! if ( indx .eq. 1) then
! call export_tet_face_curve(x = xx, y=yy, z=zz, mina = 0.0d0 &
! , maxa = 160.0d0, fname = trim(outname) &
! , meshnum = indx, append_it = .false., ref_length = ref_length)
! else
! call export_tet_face_curve(x = xx, y=yy, z=zz, mina = 0.0d0 &
! , maxa = 160.0d0, fname = trim(outname) &
! , meshnum = indx, append_it = .true., ref_length = ref_length)
! end if
indx = indx + 1
! echo the status
print *, 'still boundary elems, indx = ', indx, 'on CPU = ', tmpi%rank
end do
! call tmpi%barrier()
! finally, decomp interior elems
call equal_decomp_nelem_by_np(nelem = size(inter_elems) &
, np = tmpi%np, arr = arrl)
call loc2glob_indx(arrl = arrl, arrg = arrg)
! only do its portion of this process rank
do itet = arrg(tmpi%rank+1), (arrg(tmpi%rank+2)-1)
ii = inter_elems(itet) ! get tet number
! pick the appex of the tet required for some mappings
xA = xf(:, tet_shifted(ii, 4))
! compute xbot
do jj = 1, 3
xbot(:, jj) = xf(:, tet_shifted(ii, jj))
end do
! fill this tet coords
do jj = 1, 4
xtet(:, jj) = xf(:, tet_shifted(ii,jj))
end do
select case ( tet_type(ii) )
case ( 0 ) ! interior, use linear (straight map)
do jj = 1, size(rr)
call master2curved_tet_straight(r= rr(jj),s = ss(jj),t= tt(jj) &
, xbot = xbot, xA = xA, x = xx(jj), y = yy(jj), z = zz(jj))
end do
case ( 1 ) ! one face (tri) of the tet on CAD boundary
! do nothing at this point
case (2) ! one-edge-curved-on-CAD tet
! do nothing at this point
case default
print *, 'unknown tet_type happened! stop'
stop
end select
! ! export the generated curved element
! call tetrahedron_edge_length ( tetra = xtet, edge_length = lens)
! ref_length = 1.5d0 * maxval(lens) / dble(dd)
! if ( indx .eq. 1) then
! call export_tet_face_curve(x = xx, y=yy, z=zz, mina = 0.0d0 &
! , maxa = 160.0d0, fname = trim(outname) &
! , meshnum = indx, append_it = .false., ref_length = ref_length)
! else
! call export_tet_face_curve(x = xx, y=yy, z=zz, mina = 0.0d0 &
! , maxa = 160.0d0, fname = trim(outname) &
! , meshnum = indx, append_it = .true., ref_length = ref_length)
! end if
indx = indx + 1
! echo the status
print *, 'interior elems, indx = ', indx, 'on CPU = ', tmpi%rank
end do
else !LOAD-BALANCE
! setup vars for domain decomposition using METIS
nparts = tmpi%np
allocate(vwgt(size(neigh, 1)), part(size(neigh, 1)))
vwgt = 1
do jj = 1, size(vwgt)
if (tet_type(jj) .ne. 0) then
vwgt(jj) = 1
end if
end do
call find_tet_adj_csr_zero_based(neigh = neigh, xadj = xadj, adj = adj)
call call_metis_graph_parti(xadj = xadj, adjncy = adj, vwgt = vwgt &
, nparts = nparts, part = part)
! ! write to tecplot
! allocate(vis_mask(size(neigh, 1)))
! allocate(uu(1, size(xf,2)))
! do ii = 1, nparts
! uu = dble(ii)
! vis_mask = (part .eq. (ii-1))
! if ( ii .eq. 1) then
! call write_u_tecplot_tet(meshnum=ii, outfile='partitioned.tec', x = xf &
! , icon = tetcon, u = uu, appendit = .false., is_active = vis_mask)
! else
! call write_u_tecplot_tet(meshnum=ii, outfile='partitioned.tec', x = xf &
! , icon = tetcon, u = uu, appendit = .true., is_active = vis_mask)
! end if
! end do
! if ( allocated(uu) ) deallocate(uu)
! if ( allocated(vis_mask) ) deallocate(vis_mask)
! init
indx = 1
! timing
tmp_time = wtime()
! map tets
main_loop: do ii = 1, size(tetcon, 1)
! skip if not in right CPU
if ( tmpi%np > 1 ) then
if ( tmpi%rank .ne. part(ii) ) cycle ! not in this CPU
end if
! pick the appex of the tet required for some mappings
xA = xf(:, tet_shifted(ii, 4))
! compute xbot
do jj = 1, 3
xbot(:, jj) = xf(:, tet_shifted(ii, jj))
end do
! fill this tet coords
do jj = 1, 4
xtet(:, jj) = xf(:, tet_shifted(ii,jj))
end do
select case ( tet_type(ii) )
case ( 0 ) ! interior, use linear (straight map)
do jj = 1, size(rr)
call master2curved_tet_straight(r= rr(jj),s = ss(jj),t= tt(jj) &
, xbot = xbot, xA = xA, x = xx(jj), y = yy(jj), z = zz(jj))
end do
case ( 1 ) ! one face (tri) of the tet on CAD boundary
! bullet proofing ...
if ( tet2bn_tri(ii) .eq. -1 ) then
print *, 'This tet is supposed to be one-face-bn' &
, ' tet but is NOT! stop'
stop
end if
!
CAD_face = cent_cad_found(tet2bn_tri(ii))
! bullet proofing ...
if ( CAD_face .eq. -1 ) then !bn tet not on CAD database
print *, 'this boundary-face tet has a CAD face' &
, ' tag equal to -1! stop'
stop
end if
is_CAD_bn_tri = is_tri_near_CAD_boundary(node2bntri = node2bntri &
, CAD_face = cent_cad_found, nodes = tet_shifted(ii, 1:3))
do jj = 1, size(rr)
if ( .not. is_CAD_bn_tri) then
call master2curved_tet_ocas_close(r = rr(jj),s = ss(jj),t = tt(jj) &
, xbot = xbot, xA = xA, tol = tol, x = xx(jj), y = yy(jj), z = zz(jj) &
, CAD_face_input = CAD_face)
else
call master2curved_tet_ocas_close(r = rr(jj),s = ss(jj),t = tt(jj) &
, xbot = xbot, xA = xA, tol = tol, x = xx(jj), y = yy(jj), z = zz(jj))
end if
end do
case (2) ! one-edge-curved-on-CAD tet
do jj = 1, size(rr)
call master2curved_edg_tet_ocas_close(r= rr(jj),s= ss(jj),t= tt(jj) &
, xyz = xtet, x = xx(jj), y = yy(jj), z = zz(jj), tol = tol)
end do
case default
print *, 'unknown tet_type happened! stop'
stop
end select
! export the generated curved element
call tetrahedron_edge_length ( tetra = xtet, edge_length = lens)
ref_length = 1.5d0 * maxval(lens) / dble(dd)
if ( indx .eq. 1) then
call export_tet_face_curve(x = xx, y=yy, z=zz, mina = 0.0d0 &
, maxa = 160.0d0, fname = trim(outname) &
, meshnum = indx, append_it = .false., ref_length = ref_length)
else
call export_tet_face_curve(x = xx, y=yy, z=zz, mina = 0.0d0 &
, maxa = 160.0d0, fname = trim(outname) &
, meshnum = indx, append_it = .true., ref_length = ref_length)
end if
indx = indx + 1
! echo the status
print *, 'indx = ', indx, 'on CPU = ', tmpi%rank
end do main_loop
end if ! LOAD-BALANCE
! call tmpi%barrier()
! timing
tmp_time = wtime() - tmp_time
! write the time of this process
write (this_cpu_wtime, "(A9,I0.3,A5)") "cpu_wtime", tmpi%rank, ".time"
open (unit=22, file=this_cpu_wtime, status='unknown', action='write')
write(22, *) tmp_time
close(22)
! reduce all timings on root
call tmpi%reduce_max_double((/ tmp_time /), root_max_timing )
! write the parallel time to
! the output file on the root
! process
if ( tmpi%rank .eq. tmpi%root_rank ) then
open (unit=30, file='root_wtime.txt', status='unknown', action='write')
write(30, *) root_max_timing(1)
close(30)
end if
! clean ups
if ( allocated(x) ) deallocate(x)
if ( allocated(icontag) ) deallocate(icontag)
if ( allocated(xf) ) deallocate(xf)
if ( allocated(tetcon) ) deallocate(tetcon)
if ( allocated(neigh) ) deallocate(neigh)
if ( allocated(bntri) ) deallocate(bntri)
! do jj = 1, size(node2bntri)
! if ( allocated(node2bntri(jj)%val) ) deallocate(node2bntri(jj)%val)
! end do
! if ( allocated(node2bntri) ) deallocate(node2bntri)
if ( allocated(uu) ) deallocate(uu)
if ( allocated(xadj) ) deallocate(xadj)
if ( allocated(adj) ) deallocate(adj)
if ( allocated(vwgt) ) deallocate(vwgt)
if ( allocated(part) ) deallocate(part)
if ( allocated(vis_mask) ) deallocate(vis_mask)
if ( allocated(inter_elems) ) deallocate(inter_elems)
if ( allocated(near_bn_elems) ) deallocate(near_bn_elems)
if ( allocated(arrl) ) deallocate(arrl)
if ( allocated(arrg) ) deallocate(arrg)
if ( allocated(cent_cad_found) ) deallocate(cent_cad_found)
if ( allocated(uvc) ) deallocate(uvc)
if ( allocated(tet_shifted) ) deallocate(tet_shifted)
if ( allocated(tet2bn_tri) ) deallocate(tet2bn_tri)
if ( allocated(tet_type) ) deallocate(tet_type)
if ( allocated(rr) ) deallocate(rr)
if ( allocated(ss) ) deallocate(ss)
if ( allocated(tt) ) deallocate(tt)
if ( allocated(xx) ) deallocate(xx)
if ( allocated(yy) ) deallocate(yy)
if ( allocated(zz) ) deallocate(zz)
! done here
end subroutine curved_tetgen_geom
subroutine find_bn_tris_CAD_face(cad_file, nbntri, bntri, xf &
, cent_cad_found, uvc, tol)
implicit none
character(len=*), intent(in) :: cad_file
integer, intent(in) :: nbntri
integer, dimension(:), intent(in) :: bntri
real*8, dimension(:, :), intent(in) :: xf
integer, allocatable :: cent_cad_found(:) !nbntri
real*8, allocatable :: uvc(:)
real*8, intent(in) :: tol
! local vars
! CAD corresponding data struct
real*8, allocatable :: xc(:)
integer :: tpt, ii, jj, kk
real*8 :: tuv(2), txyz(3), xbn(3,3)
! init CAD file
call init_IGES_f90(fname = cad_file)
! find the CAD tag of the centroid of bn faces (tris)
if ( allocated(cent_cad_found) ) deallocate(cent_cad_found)
allocate(cent_cad_found(nbntri))
cent_cad_found = 0
allocate(xc(3*nbntri))
xc = 0.0d0
if ( allocated(uvc) ) deallocate(uvc)
allocate(uvc(2*nbntri))
uvc = 0.0d0
do ii = 1, nbntri
do jj = 1, 3
tpt = bntri(6*(ii-1) + jj)
do kk = 1, 3
xc(3*(ii-1) + kk) = xc(3*(ii-1) + kk) + xf(kk, tpt)
end do
end do
end do
! finalize the center coord
xc = xc / 3.0d0
! find the CAD tag of the centroids
print *, 'find the CAD tag of the centroids'
call find_pts_on_database_f90(npts = nbntri, pts = xc &
, found = cent_cad_found, uv = uvc, tol = tol)
! compute physical center of bn tris and export to MATLAB ...
! open (unit=10, file='tmp.m', status='unknown', action='write')
! write(10, *) 'x = ['
do ii = 1, nbntri
tuv(1) = uvc(2*(ii-1) + 1)
tuv(2) = uvc(2*(ii-1) + 2)
if (cent_cad_found(ii) .eq. -1) cycle
call uv2xyz_f90(CAD_face = cent_cad_found(ii), uv = tuv, xyz = txyz)
print *, 'writing the center of bntri #', ii
! write(10, *) txyz, ';'
end do
! write(10, *) '];'
! print mapped bn triangles
! write(10, *) 'tris = ['
do ii = 1, nbntri
if (cent_cad_found(ii) .eq. -1) cycle
do jj = 1, 3
tpt = bntri(6*(ii-1) + jj)
xbn(:, jj) = xf(:, tpt)
end do
! write(10, *) xbn(:, 1), ';'
! write(10, *) xbn(:, 2), ';'
! write(10, *) xbn(:, 3), ';'
! write(10, *) xbn(:, 1), ';'
! print*, ' '
end do
! write(10, *) '];'
! close(10)
! close CAD objects
!call clean_statics_f90()
! cleanups
if ( allocated(xc) ) deallocate(xc)
! done here
end subroutine find_bn_tris_CAD_face
!
subroutine find_tet_adj_csr_zero_based(neigh, xadj, adj)
implicit none
integer, dimension(:, :), intent(in) :: neigh
integer, dimension(:), allocatable :: xadj, adj
! local vars
integer :: ii, jj, nadj, indx
! counting and sizing
nadj = 0
do ii = 1, size(neigh, 1) ! loop over all tets
do jj = 1, size(neigh, 2) ! over neighbors
if (neigh(ii, jj) > 0 ) nadj = nadj + 1
end do
end do
! alloc
if ( allocated(xadj) ) deallocate(xadj)
allocate(xadj(size(neigh, 1)+1))
if ( allocated(adj) ) deallocate(adj)
allocate(adj(nadj))
! fill them
xadj(1) = 0
indx = 1
do ii = 1, size(neigh, 1)
do jj = 1, size(neigh, 2)
if (neigh(ii, jj) > 0 ) then
adj(indx) = neigh(ii, jj)
indx = indx + 1
end if
end do
xadj(ii+1) = indx - 1
end do
adj = adj - 1 ! zero-based cell number
! done here
end subroutine find_tet_adj_csr_zero_based
!
subroutine call_metis_graph_parti(xadj, adjncy, vwgt, nparts, part)
implicit none
integer, intent(in) :: xadj(:), adjncy(:), vwgt(:)
integer, intent(in) :: nparts
integer, intent(out) :: part(:)
! local vars
integer :: nvtxs, ncon
integer, pointer :: vsize(:) =>null(), adjwgt(:) =>null()
real*8, pointer :: tpwgts(:)=>null(), ubvec=>null()
integer, pointer :: options(:) =>null()
integer :: edgecut
! init
nvtxs = size(xadj) - 1
ncon = 1
! call C-func
call METIS_PartGraphRecursive(nvtxs, ncon, xadj &
,adjncy, vwgt, vsize, adjwgt &
,nparts, tpwgts, ubvec, options &
,edgecut, part)
! done here
end subroutine call_metis_graph_parti
!
subroutine shift_tetcon(nbntri, bntri, tetcon, tetcon2, tet2bn_tri, tet_type, cent_cad_found)
implicit none
integer, intent(in) :: nbntri
integer, dimension(:), intent(in), target :: bntri
integer, dimension(:, :), intent(in) :: tetcon
integer, dimension(:, :), intent(out) :: tetcon2
integer, dimension(:), intent(out) :: tet2bn_tri, tet_type
integer, dimension(:), intent(in) :: cent_cad_found
! local vars
integer :: ii, i1, i2, tetnum, jj, kk
integer, dimension(:), pointer :: pts => null(), tets_on_face => null()
integer :: edg(2)
integer, allocatable :: tets(:)
! init
tet2bn_tri = -1
tet_type = 0 ! default interior
tetcon2 = tetcon
! shift the tets that have one face on CAD boundary
do ii = 1, nbntri
if ( cent_cad_found(ii) .eq. -1 ) cycle
i1 = 6* (ii-1) + 1
i2 = 6* (ii-1) + 3
pts => bntri(i1:i2)
i1 = 6* (ii-1) + 5
i2 = 6* (ii-1) + 6
tets_on_face => bntri(i1:i2)
tetnum = maxval(tets_on_face)
if ( tetnum > size(tetcon, 1) ) tetnum = minval(tets_on_face)
if ( tetnum <= 0 ) then
print *, 'fatal; tetnum <= 0. stop'
stop
end if
tet2bn_tri(tetnum) = ii
tet_type(tetnum) = 1 ! one face on CAD
! bullet proofing ...
if ( .not. a_in_b(a = pts, b = tetcon(tetnum, :)) ) then
print *, 'Not all boundary tri points are in the given tet!!! stop'