-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeom.f90
1844 lines (1474 loc) · 47.3 KB
/
geom.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
! Routines related to unstructured geometry and immersed boundary methods
MODULE COMPLEX_GEOMETRY
USE PRECISION_PARAMETERS
USE GLOBAL_CONSTANTS
USE MESH_VARIABLES
USE MESH_POINTERS
USE COMP_FUNCTIONS, ONLY: CHECKREAD,SHUTDOWN
USE MEMORY_FUNCTIONS, ONLY: ChkMemErr
IMPLICIT NONE
CHARACTER(255), PARAMETER :: geomid='$Id: geom.f90 9873 2012-01-21 20:07:13Z randy.mcdermott $'
CHARACTER(255), PARAMETER :: geomrev='$Revision: 9873 $'
CHARACTER(255), PARAMETER :: geomdate='$Date: 2012-01-21 12:07:13 -0800 (Sat, 21 Jan 2012) $'
PRIVATE
PUBLIC :: INIT_IBM,TRILINEAR,GETX,GETU,GETGRAD,INIT_FACE,GET_REV_geom, &
READ_GEOM,READ_VERT,READ_FACE,READ_VOLU,GET_VELO_IBM,GET_CUTCELL_AREA
CONTAINS
SUBROUTINE READ_GEOM
CHARACTER(30) :: ID,SHAPE,TFILE
REAL(EB) :: XYZ(3),ORIENTATION(3),XB(6),RADIUS,VELOCITY(3),OMEGA,RGB(3),PIXELS,ROUGHNESS
LOGICAL :: HOLE,TWO_SIDED
INTEGER :: IOS,IZERO,NG
TYPE(GEOMETRY_TYPE), POINTER :: G=>NULL()
NAMELIST /GEOM/ ID,SHAPE,XB,XYZ,ORIENTATION,RADIUS,VELOCITY,OMEGA,HOLE,RGB,PIXELS,TWO_SIDED,TFILE,ROUGHNESS
N_GEOM=0
REWIND(LU_INPUT)
COUNT_GEOM_LOOP: DO
CALL CHECKREAD('GEOM',LU_INPUT,IOS)
IF (IOS==1) EXIT COUNT_GEOM_LOOP
READ(LU_INPUT,NML=GEOM,END=11,ERR=12,IOSTAT=IOS)
N_GEOM=N_GEOM+1
12 IF (IOS>0) CALL SHUTDOWN('ERROR: problem with GEOM line')
ENDDO COUNT_GEOM_LOOP
11 REWIND(LU_INPUT)
IF (N_GEOM==0) RETURN
! Allocate GEOMETRY array
ALLOCATE(GEOMETRY(N_GEOM),STAT=IZERO)
CALL ChkMemErr('READ','GEOMETRY',IZERO)
READ_GEOM_LOOP: DO NG=1,N_GEOM
G=>GEOMETRY(NG)
CALL CHECKREAD('GEOM',LU_INPUT,IOS)
IF (IOS==1) EXIT READ_GEOM_LOOP
! Set defaults
ID = 'geom'
TFILE = 'null'
SHAPE = 'SPHERE'
HOLE = .FALSE.
XYZ = 0._EB
ORIENTATION = (/0._EB,0._EB,1._EB/)
XB = 0._EB
RADIUS = 1._EB
VELOCITY = 0._EB
OMEGA = 0._EB
RGB = (/192,192,192/)
PIXELS = 1.0
TWO_SIDED = .FALSE.
ROUGHNESS = 0._EB
! Read the GEOM line
READ(LU_INPUT,GEOM,END=35)
G%X1 = XB(1)
G%X2 = XB(2)
G%Y1 = XB(3)
G%Y2 = XB(4)
G%Z1 = XB(5)
G%Z2 = XB(6)
G%X0 = XYZ(1)
G%Y0 = XYZ(2)
G%Z0 = XYZ(3)
G%X = XYZ(1)
G%Y = XYZ(2)
G%Z = XYZ(3)
G%XOR = ORIENTATION(1)
G%YOR = ORIENTATION(2)
G%ZOR = ORIENTATION(3)
G%U0 = VELOCITY(1)
G%V0 = VELOCITY(2)
G%W0 = VELOCITY(3)
G%OMEGA = OMEGA
G%OMEGA_X = G%OMEGA*G%XOR
G%OMEGA_Y = G%OMEGA*G%YOR
G%OMEGA_Z = G%OMEGA*G%ZOR
G%RADIUS = RADIUS
G%SHAPE = SHAPE
G%HOLE = HOLE
G%RGB = RGB
G%PIXELS = PIXELS
G%TWO_SIDED = TWO_SIDED
G%ID = ID
G%TFILE = TFILE
G%ROUGHNESS = ROUGHNESS
IF (ABS(G%U0)>0._EB .OR. ABS(G%V0)>0._EB .OR. ABS(G%W0)>0._EB) G%TRANSLATE = .TRUE.
IF (ABS(G%OMEGA)>0._EB) G%ROTATE = .TRUE.
SELECT CASE(G%SHAPE)
CASE('BOX')
G%ISHAPE = IBOX
G%X0 = 0.5_EB*(G%X1+G%X2)
G%Y0 = 0.5_EB*(G%Y1+G%Y2)
G%Z0 = 0.5_EB*(G%Z1+G%Z2)
G%SMVOBJECT = 'movingbox'
CASE('SPHERE')
G%ISHAPE = ISPHERE
G%SMVOBJECT = 'movingsphere'
CASE('CYLINDER')
G%ISHAPE = ICYLINDER
G%SMVOBJECT = 'tube'
CASE('PLANE')
G%ISHAPE = IPLANE
G%SMVOBJECT = 'plane'
CASE DEFAULT
CALL SHUTDOWN('ERROR: unrecognized SHAPE on GEOM line')
END SELECT
! Allocate bounding box arrays
ALLOCATE(G%MIN_I(NMESHES),STAT=IZERO)
CALL ChkMemErr('READ_GEOM','MIN_I',IZERO)
ALLOCATE(G%MAX_I(NMESHES),STAT=IZERO)
CALL ChkMemErr('READ_GEOM','MAX_I',IZERO)
ALLOCATE(G%MIN_J(NMESHES),STAT=IZERO)
CALL ChkMemErr('READ_GEOM','MIN_J',IZERO)
ALLOCATE(G%MAX_J(NMESHES),STAT=IZERO)
CALL ChkMemErr('READ_GEOM','MAX_J',IZERO)
ALLOCATE(G%MIN_K(NMESHES),STAT=IZERO)
CALL ChkMemErr('READ_GEOM','MIN_K',IZERO)
ALLOCATE(G%MAX_K(NMESHES),STAT=IZERO)
CALL ChkMemErr('READ_GEOM','MAX_K',IZERO)
ENDDO READ_GEOM_LOOP
35 REWIND(LU_INPUT)
END SUBROUTINE READ_GEOM
SUBROUTINE READ_VERT
REAL(EB) :: X(3)=0._EB
INTEGER :: I,IOS,IZERO
NAMELIST /VERT/ X
N_VERT=0
REWIND(LU_INPUT)
COUNT_VERT_LOOP: DO
CALL CHECKREAD('VERT',LU_INPUT,IOS)
IF (IOS==1) EXIT COUNT_VERT_LOOP
READ(LU_INPUT,NML=VERT,END=14,ERR=15,IOSTAT=IOS)
N_VERT=N_VERT+1
15 IF (IOS>0) CALL SHUTDOWN('ERROR: problem with VERT line')
ENDDO COUNT_VERT_LOOP
14 REWIND(LU_INPUT)
IF (N_VERT==0) RETURN
! Allocate VERTEX array
ALLOCATE(VERTEX(N_VERT),STAT=IZERO)
CALL ChkMemErr('READ','VERT',IZERO)
READ_VERT_LOOP: DO I=1,N_VERT
CALL CHECKREAD('VERT',LU_INPUT,IOS)
IF (IOS==1) EXIT READ_VERT_LOOP
! Read the VERT line
READ(LU_INPUT,VERT,END=36)
VERTEX(I)%X = X(1)
VERTEX(I)%Y = X(2)
VERTEX(I)%Z = X(3)
ENDDO READ_VERT_LOOP
36 REWIND(LU_INPUT)
END SUBROUTINE READ_VERT
SUBROUTINE READ_FACE
INTEGER :: N(3),I,IOS,IZERO,NNN,NS
LOGICAL :: EX
CHARACTER(30) :: SURF_ID='INERT'
CHARACTER(100) :: MESSAGE
NAMELIST /FACE/ N,SURF_ID
N_FACE=0
REWIND(LU_INPUT)
COUNT_FACE_LOOP: DO
CALL CHECKREAD('FACE',LU_INPUT,IOS)
IF (IOS==1) EXIT COUNT_FACE_LOOP
READ(LU_INPUT,NML=FACE,END=16,ERR=17,IOSTAT=IOS)
N_FACE=N_FACE+1
16 IF (IOS>0) CALL SHUTDOWN('ERROR: problem with FACE line')
ENDDO COUNT_FACE_LOOP
17 REWIND(LU_INPUT)
IF (N_FACE==0) RETURN
! Allocate FACET array
ALLOCATE(FACET(N_FACE),STAT=IZERO)
CALL ChkMemErr('READ','FACE',IZERO)
READ_FACE_LOOP: DO I=1,N_FACE
CALL CHECKREAD('FACE',LU_INPUT,IOS)
IF (IOS==1) EXIT READ_FACE_LOOP
! Read the FACE line
READ(LU_INPUT,FACE,END=37)
FACET(I)%VERTEX(1) = N(1)
FACET(I)%VERTEX(2) = N(2)
FACET(I)%VERTEX(3) = N(3)
! Check the SURF_ID against the list of SURF's
EX = .FALSE.
DO NS=0,N_SURF
IF (TRIM(SURF_ID)==SURFACE(NS)%ID) EX = .TRUE.
ENDDO
IF (.NOT.EX) THEN
WRITE(MESSAGE,'(A,A,A)') 'ERROR: SURF_ID ',TRIM(SURF_ID),' not found'
CALL SHUTDOWN(MESSAGE)
ENDIF
! Assign SURF_INDEX, Index of the Boundary Condition
FACET(I)%SURF_ID = TRIM(SURF_ID)
FACET(I)%SURF_INDEX = DEFAULT_SURF_INDEX
DO NNN=0,N_SURF
IF (SURF_ID==SURFACE(NNN)%ID) FACET(I)%SURF_INDEX = NNN
ENDDO
ENDDO READ_FACE_LOOP
37 REWIND(LU_INPUT)
CALL INIT_FACE
END SUBROUTINE READ_FACE
SUBROUTINE READ_VOLU
INTEGER :: N(4),I,IOS,IZERO
CHARACTER(30) :: MATL_ID
NAMELIST /VOLU/ N,MATL_ID
N_VOLU=0
REWIND(LU_INPUT)
COUNT_VOLU_LOOP: DO
CALL CHECKREAD('VOLU',LU_INPUT,IOS)
IF (IOS==1) EXIT COUNT_VOLU_LOOP
READ(LU_INPUT,NML=VOLU,END=18,ERR=19,IOSTAT=IOS)
N_VOLU=N_VOLU+1
18 IF (IOS>0) CALL SHUTDOWN('ERROR: problem with VOLU line')
ENDDO COUNT_VOLU_LOOP
19 REWIND(LU_INPUT)
IF (N_VOLU==0) RETURN
! Allocate VOLUME array
ALLOCATE(VOLUME(N_VOLU),STAT=IZERO)
CALL ChkMemErr('READ','VOLU',IZERO)
READ_VOLU_LOOP: DO I=1,N_VOLU
CALL CHECKREAD('VOLU',LU_INPUT,IOS)
IF (IOS==1) EXIT READ_VOLU_LOOP
! Read the VOLU line
READ(LU_INPUT,VOLU,END=38)
VOLUME(I)%VERTEX(1) = N(1)
VOLUME(I)%VERTEX(2) = N(2)
VOLUME(I)%VERTEX(3) = N(3)
VOLUME(I)%VERTEX(4) = N(4)
VOLUME(I)%MATL_ID = TRIM(MATL_ID)
ENDDO READ_VOLU_LOOP
38 REWIND(LU_INPUT)
END SUBROUTINE READ_VOLU
SUBROUTINE INIT_IBM(T,NM)
USE COMP_FUNCTIONS, ONLY: GET_FILE_NUMBER
IMPLICIT NONE
INTEGER, INTENT(IN) :: NM
REAL(EB), INTENT(IN) :: T
INTEGER :: I,J,K,N,IERR,I_MIN,I_MAX,J_MIN,J_MAX,K_MIN,K_MAX,IC,DUMMY_INTEGER,IZERO,LU
TYPE (MESH_TYPE), POINTER :: M
REAL(EB) :: BB(6),V1(3),V2(3),V3(3),AREA,PC(18),XPC(27)
INTEGER :: NP,NXP,IERR2
LOGICAL :: EX,OP
CHARACTER(60) :: FN
REAL(FB) :: DUMMY_FB_REAL
!LOGICAL :: END_OF_LIST
!TYPE (CUTCELL_LINKED_LIST_TYPE), POINTER :: CL
M => MESHES(NM)
CUTCELL_TEST: IF (ABS(T-T_BEGIN)<ZERO_P) THEN
FACE_LOOP: DO N=1,N_FACE
V1 = (/VERTEX(FACET(N)%VERTEX(1))%X,VERTEX(FACET(N)%VERTEX(1))%Y,VERTEX(FACET(N)%VERTEX(1))%Z/)
V2 = (/VERTEX(FACET(N)%VERTEX(2))%X,VERTEX(FACET(N)%VERTEX(2))%Y,VERTEX(FACET(N)%VERTEX(2))%Z/)
V3 = (/VERTEX(FACET(N)%VERTEX(3))%X,VERTEX(FACET(N)%VERTEX(3))%Y,VERTEX(FACET(N)%VERTEX(3))%Z/)
BB(1) = MIN(V1(1),V2(1),V3(1))
BB(2) = MAX(V1(1),V2(1),V3(1))
BB(3) = MIN(V1(2),V2(2),V3(2))
BB(4) = MAX(V1(2),V2(2),V3(2))
BB(5) = MIN(V1(3),V2(3),V3(3))
BB(6) = MAX(V1(3),V2(3),V3(3))
I_MIN = MAX(1,FLOOR((BB(1)-M%XS)/M%DX(1))-1)
J_MIN = MAX(1,FLOOR((BB(3)-M%YS)/M%DY(1))-1)
K_MIN = MAX(1,FLOOR((BB(5)-M%ZS)/M%DZ(1))-1)
I_MAX = MIN(M%IBAR,CEILING((BB(2)-M%XS)/M%DX(1))+1)
J_MAX = MIN(M%JBAR,CEILING((BB(4)-M%YS)/M%DY(1))+1)
K_MAX = MIN(M%KBAR,CEILING((BB(6)-M%ZS)/M%DZ(1))+1)
DO K=K_MIN,K_MAX
DO J=J_MIN,J_MAX
DO I=I_MIN,I_MAX
IC = (K-1)*M%IBAR*M%JBAR + (J-1)*M%IBAR + I
BB(1) = M%X(I-1)
BB(2) = M%X(I)
BB(3) = M%Y(J-1)
BB(4) = M%Y(J)
BB(5) = M%Z(K-1)
BB(6) = M%Z(K)
CALL TRIANGLE_BOX_INTERSECT(IERR,V1,V2,V3,BB)
IF (IERR==1) THEN
CALL TRI_PLANE_BOX_INTERSECT(NP,PC,V1,V2,V3,BB)
CALL TRIANGLE_POLYGON_POINTS(IERR2,NXP,XPC,V1,V2,V3,NP,PC,BB)
IF (IERR2 == 1) THEN
AREA = POLYGON_AREA(NXP,XPC)
CALL CUTCELL_INSERT(IC,AREA,FACET(N)%CUTCELL_LIST)
ENDIF
ENDIF
ENDDO
ENDDO
ENDDO
ENDDO FACE_LOOP
ENDIF CUTCELL_TEST
!CL=>FACET(1)%CUTCELL_LIST
!IF ( ASSOCIATED(CL) ) THEN
! END_OF_LIST=.FALSE.
! DO WHILE (.NOT.END_OF_LIST)
! print *, CL%INDEX, CL%AREA
! CL=>CL%NEXT
! IF ( .NOT.ASSOCIATED(CL) ) THEN
! print *,'done printing linked list!'
! END_OF_LIST=.TRUE.
! ENDIF
! ENDDO
!ENDIF
! Read boundary condition from file
SURF_LOOP: DO N=1,N_SURF
IF (TRIM(SURFACE(N)%BC_FILENAME)=='null') CYCLE SURF_LOOP
IF (ABS(T-T_BEGIN)<ZERO_P .AND. LU_SFBC<0) THEN
FN = TRIM(SURFACE(N)%BC_FILENAME)
INQUIRE(FILE=FN,EXIST=EX,OPENED=OP,NUMBER=LU)
IF (.NOT.EX) CALL SHUTDOWN('Error: boundary condition file does not exist.')
IF (OP) CLOSE(LU)
LU_SFBC = GET_FILE_NUMBER()
OPEN(LU_SFBC,FILE=FN,ACTION='READ',FORM='UNFORMATTED')
READ(LU_SFBC) DUMMY_INTEGER ! one
READ(LU_SFBC) DUMMY_INTEGER ! version
IF (ALLOCATED(FB_REAL_FACE_VALS_ARRAY)) DEALLOCATE(FB_REAL_FACE_VALS_ARRAY)
ALLOCATE(FB_REAL_FACE_VALS_ARRAY(N_FACE),STAT=IZERO)
CALL ChkMemErr('INIT_IBM','FB_REAL_FACE_VALS_ARRAY',IZERO)
ENDIF
READ(LU_SFBC) DUMMY_FB_REAL ! stime
IF (T>=REAL(DUMMY_FB_REAL,EB)) THEN
! n_vert_s_vals,n_vert_d_vals,n_face_s_vals,n_face_d_vals
READ(LU_SFBC) DUMMY_INTEGER,DUMMY_INTEGER,DUMMY_INTEGER,DUMMY_INTEGER
READ(LU_SFBC) (FB_REAL_FACE_VALS_ARRAY(I),I=1,N_FACE)
FACET%TMP_F = REAL(FB_REAL_FACE_VALS_ARRAY,EB) + TMPM
ELSE
BACKSPACE LU_SFBC
ENDIF
ENDDO SURF_LOOP
END SUBROUTINE INIT_IBM
SUBROUTINE INIT_FACE
USE MATH_FUNCTIONS, ONLY: CROSS_PRODUCT
IMPLICIT NONE
INTEGER :: I
REAL(EB) :: N_VEC(3),N_LENGTH,U_VEC(3),V_VEC(3),V1(3),V2(3),V3(3)
TYPE(FACET_TYPE), POINTER :: FACE
REAL(EB), PARAMETER :: TOL=1.E-10_EB
DO I=1,N_FACE
FACE=>FACET(I)
V1 = (/VERTEX(FACE%VERTEX(1))%X,VERTEX(FACE%VERTEX(1))%Y,VERTEX(FACE%VERTEX(1))%Z/)
V2 = (/VERTEX(FACE%VERTEX(2))%X,VERTEX(FACE%VERTEX(2))%Y,VERTEX(FACE%VERTEX(2))%Z/)
V3 = (/VERTEX(FACE%VERTEX(3))%X,VERTEX(FACE%VERTEX(3))%Y,VERTEX(FACE%VERTEX(3))%Z/)
U_VEC = V2-V1
V_VEC = V3-V1
CALL CROSS_PRODUCT(N_VEC,U_VEC,V_VEC)
N_LENGTH = SQRT(DOT_PRODUCT(N_VEC,N_VEC))
IF (N_LENGTH>TOL) THEN
FACE%NVEC = N_VEC/N_LENGTH
ELSE
FACE%NVEC = 0._EB
ENDIF
FACE%AREA = TRIANGLE_AREA(V1,V2,V3)
FACE%TMP_F = SURFACE(FACE%SURF_INDEX)%TMP_FRONT
FACE%TMP_G = TMPA
ENDDO
END SUBROUTINE INIT_FACE
! http://www.sdsc.edu/~tkaiser/f90.html#Linked lists
RECURSIVE SUBROUTINE INSERT(ITEM,ROOT)
IMPLICIT NONE
TYPE(LINKED_LIST_TYPE), POINTER :: ROOT
INTEGER :: ITEM,IZERO
IF (.NOT.ASSOCIATED(ROOT)) THEN
ALLOCATE(ROOT,STAT=IZERO)
CALL ChkMemErr('GEOM','ROOT',IZERO)
NULLIFY(ROOT%NEXT)
ROOT%INDEX = ITEM
ELSE
CALL INSERT(ITEM,ROOT%NEXT)
ENDIF
END SUBROUTINE INSERT
RECURSIVE SUBROUTINE CUTCELL_INSERT(ITEM,AREA,ROOT)
IMPLICIT NONE
TYPE(CUTCELL_LINKED_LIST_TYPE), POINTER :: ROOT
INTEGER :: ITEM,IZERO
REAL(EB):: AREA
IF (.NOT.ASSOCIATED(ROOT)) THEN
ALLOCATE(ROOT,STAT=IZERO)
CALL ChkMemErr('GEOM','ROOT',IZERO)
NULLIFY(ROOT%NEXT)
ROOT%INDEX = ITEM
ROOT%AREA = AREA
ELSE
CALL CUTCELL_INSERT(ITEM,AREA,ROOT%NEXT)
ENDIF
END SUBROUTINE CUTCELL_INSERT
SUBROUTINE TRIANGLE_BOX_INTERSECT(IERR,V1,V2,V3,BB)
IMPLICIT NONE
INTEGER, INTENT(OUT) :: IERR
REAL(EB), INTENT(IN) :: V1(3),V2(3),V3(3),BB(6)
REAL(EB) :: PLANE(4),P0(3),P1(3)
IERR=0
!! Filter small triangles
!
!A_TRI = TRIANGLE_AREA(V1,V2,V3)
!A_BB = MIN( (BB(2)-BB(1))*(BB(4)-BB(3)), (BB(2)-BB(1))*(BB(6)-BB(5)), (BB(4)-BB(3))*(BB(6)-BB(5)) )
!IF (A_TRI < 0.01*A_BB) RETURN
! Are vertices outside of bounding planes?
IF (MAX(V1(1),V2(1),V3(1))<BB(1)) RETURN
IF (MIN(V1(1),V2(1),V3(1))>BB(2)) RETURN
IF (MAX(V1(2),V2(2),V3(2))<BB(3)) RETURN
IF (MIN(V1(2),V2(2),V3(2))>BB(4)) RETURN
IF (MAX(V1(3),V2(3),V3(3))<BB(5)) RETURN
IF (MIN(V1(3),V2(3),V3(3))>BB(6)) RETURN
! Any vertices inside bounding box?
IF ( V1(1)>=BB(1).AND.V1(1)<=BB(2) .AND. &
V1(2)>=BB(3).AND.V1(2)<=BB(4) .AND. &
V1(3)>=BB(5).AND.V1(3)<=BB(6) ) THEN
IERR=1
RETURN
ENDIF
IF ( V2(1)>=BB(1).AND.V2(1)<=BB(2) .AND. &
V2(2)>=BB(3).AND.V2(2)<=BB(4) .AND. &
V2(3)>=BB(5).AND.V2(3)<=BB(6) ) THEN
IERR=1
RETURN
ENDIF
IF ( V3(1)>=BB(1).AND.V3(1)<=BB(2) .AND. &
V3(2)>=BB(3).AND.V3(2)<=BB(4) .AND. &
V3(3)>=BB(5).AND.V3(3)<=BB(6) ) THEN
IERR=1
RETURN
ENDIF
! There are a couple other trivial rejection tests we could employ.
! But for now we jump straight to line segment--plane intersection.
! Test edge V1,V2 for intersection with each face of box
PLANE = (/-1._EB,0._EB,0._EB, BB(1)/); CALL LINE_PLANE_INTERSECT(IERR,V1,V2,PLANE,BB,-1); IF (IERR==1) RETURN
PLANE = (/ 1._EB,0._EB,0._EB,-BB(2)/); CALL LINE_PLANE_INTERSECT(IERR,V1,V2,PLANE,BB, 1); IF (IERR==1) RETURN
PLANE = (/0._EB,-1._EB,0._EB, BB(3)/); CALL LINE_PLANE_INTERSECT(IERR,V1,V2,PLANE,BB,-2); IF (IERR==1) RETURN
PLANE = (/0._EB, 1._EB,0._EB,-BB(4)/); CALL LINE_PLANE_INTERSECT(IERR,V1,V2,PLANE,BB, 2); IF (IERR==1) RETURN
PLANE = (/0._EB,0._EB,-1._EB, BB(5)/); CALL LINE_PLANE_INTERSECT(IERR,V1,V2,PLANE,BB,-3); IF (IERR==1) RETURN
PLANE = (/0._EB,0._EB, 1._EB,-BB(6)/); CALL LINE_PLANE_INTERSECT(IERR,V1,V2,PLANE,BB, 3); IF (IERR==1) RETURN
! Test edge V2,V3 for intersection with each face of box
PLANE = (/-1._EB,0._EB,0._EB, BB(1)/); CALL LINE_PLANE_INTERSECT(IERR,V2,V3,PLANE,BB,-1); IF (IERR==1) RETURN
PLANE = (/ 1._EB,0._EB,0._EB,-BB(2)/); CALL LINE_PLANE_INTERSECT(IERR,V2,V3,PLANE,BB, 1); IF (IERR==1) RETURN
PLANE = (/0._EB,-1._EB,0._EB, BB(3)/); CALL LINE_PLANE_INTERSECT(IERR,V2,V3,PLANE,BB,-2); IF (IERR==1) RETURN
PLANE = (/0._EB, 1._EB,0._EB,-BB(4)/); CALL LINE_PLANE_INTERSECT(IERR,V2,V3,PLANE,BB, 2); IF (IERR==1) RETURN
PLANE = (/0._EB,0._EB,-1._EB, BB(5)/); CALL LINE_PLANE_INTERSECT(IERR,V2,V3,PLANE,BB,-3); IF (IERR==1) RETURN
PLANE = (/0._EB,0._EB, 1._EB,-BB(6)/); CALL LINE_PLANE_INTERSECT(IERR,V2,V3,PLANE,BB, 3); IF (IERR==1) RETURN
! Test edge V3,V1 for intersection with each face of box
PLANE = (/-1._EB,0._EB,0._EB, BB(1)/); CALL LINE_PLANE_INTERSECT(IERR,V3,V1,PLANE,BB,-1); IF (IERR==1) RETURN
PLANE = (/ 1._EB,0._EB,0._EB,-BB(2)/); CALL LINE_PLANE_INTERSECT(IERR,V3,V1,PLANE,BB, 1); IF (IERR==1) RETURN
PLANE = (/0._EB,-1._EB,0._EB, BB(3)/); CALL LINE_PLANE_INTERSECT(IERR,V3,V1,PLANE,BB,-2); IF (IERR==1) RETURN
PLANE = (/0._EB, 1._EB,0._EB,-BB(4)/); CALL LINE_PLANE_INTERSECT(IERR,V3,V1,PLANE,BB, 2); IF (IERR==1) RETURN
PLANE = (/0._EB,0._EB,-1._EB, BB(5)/); CALL LINE_PLANE_INTERSECT(IERR,V3,V1,PLANE,BB,-3); IF (IERR==1) RETURN
PLANE = (/0._EB,0._EB, 1._EB,-BB(6)/); CALL LINE_PLANE_INTERSECT(IERR,V3,V1,PLANE,BB, 3); IF (IERR==1) RETURN
! The remaining possibility for tri-box intersection is that the corner of the box pokes through
! the triangle such that neither the vertices nor the edges of tri intersect any of the box faces.
! In this case the diagonal of the box corner intersects the plane formed by the tri. The diagonal
! is defined as the line segment from point P0 to P1, formed from the corners of the bounding box.
! Test the four box diagonals:
P0 = (/BB(1),BB(3),BB(5)/)
P1 = (/BB(2),BB(4),BB(6)/)
CALL LINE_SEGMENT_TRIANGLE_INTERSECT(IERR,V1,V2,V3,P0,P1); IF (IERR==1) RETURN
P0 = (/BB(2),BB(3),BB(5)/)
P1 = (/BB(1),BB(4),BB(6)/)
CALL LINE_SEGMENT_TRIANGLE_INTERSECT(IERR,V1,V2,V3,P0,P1); IF (IERR==1) RETURN
P0 = (/BB(1),BB(3),BB(6)/)
P1 = (/BB(2),BB(4),BB(5)/)
CALL LINE_SEGMENT_TRIANGLE_INTERSECT(IERR,V1,V2,V3,P0,P1); IF (IERR==1) RETURN
P0 = (/BB(1),BB(4),BB(5)/)
P1 = (/BB(2),BB(3),BB(6)/)
CALL LINE_SEGMENT_TRIANGLE_INTERSECT(IERR,V1,V2,V3,P0,P1); IF (IERR==1) RETURN
! test commit from Charles Luo
END SUBROUTINE TRIANGLE_BOX_INTERSECT
REAL(EB) FUNCTION TRIANGLE_AREA(V1,V2,V3)
USE MATH_FUNCTIONS, ONLY: CROSS_PRODUCT,NORM2
IMPLICIT NONE
REAL(EB), INTENT(IN) :: V1(3),V2(3),V3(3)
REAL(EB) :: N(3),R1(3),R2(3)
R1 = V2-V1
R2 = V3-V1
CALL CROSS_PRODUCT(N,R1,R2)
TRIANGLE_AREA = 0.5_EB*NORM2(N)
END FUNCTION TRIANGLE_AREA
SUBROUTINE LINE_SEGMENT_TRIANGLE_INTERSECT(IERR,V1,V2,V3,P0,P1)
USE MATH_FUNCTIONS, ONLY: CROSS_PRODUCT
IMPLICIT NONE
INTEGER, INTENT(OUT) :: IERR
REAL(EB), INTENT(IN) :: V1(3),V2(3),V3(3),P0(3),P1(3)
REAL(EB) :: E1(3),E2(3),S(3),Q(3),U,V,TMP,T,D(3),P(3)
REAL(EB), PARAMETER :: EPS=1.E-10_EB
IERR=0
! Schneider and Eberly, Section 11.1
D = P1-P0
E1 = V2-V1
E2 = V3-V1
CALL CROSS_PRODUCT(P,D,E2)
TMP = DOT_PRODUCT(P,E1)
IF ( ABS(TMP)<EPS ) RETURN
TMP = 1._EB/TMP
S = P0-V1
U = TMP*DOT_PRODUCT(S,P)
IF (U<0._EB .OR. U>1._EB) RETURN
CALL CROSS_PRODUCT(Q,S,E1)
V = TMP*DOT_PRODUCT(D,Q)
IF (V<0._EB .OR. (U+V)>1._EB) RETURN
T = TMP*DOT_PRODUCT(E2,Q)
!XI = P0 + T*D ! the intersection point
IF (T>=0._EB .AND. T<=1._EB) IERR=1
END SUBROUTINE LINE_SEGMENT_TRIANGLE_INTERSECT
SUBROUTINE LINE_PLANE_INTERSECT(IERR,P0,P1,PP,BB,IOR)
USE MATH_FUNCTIONS, ONLY: NORM2
IMPLICIT NONE
INTEGER, INTENT(OUT) :: IERR
REAL(EB), INTENT(IN) :: P0(3),P1(3),PP(4),BB(6)
INTEGER, INTENT(IN) :: IOR
REAL(EB) :: D(3),T,DENOM, Q0(3)
REAL(EB), PARAMETER :: EPS=1.E-10_EB
IERR=0
Q0=-999._EB
T=0._EB
D = P1-P0
DENOM = DOT_PRODUCT(PP(1:3),D)
IF (ABS(DENOM)>EPS) THEN
T = -( DOT_PRODUCT(PP(1:3),P0)+PP(4) )/DENOM
IF (T>=0._EB .AND. T<=1._EB) THEN
Q0 = P0 + T*D ! instersection point
IF (POINT_IN_BOX_2D(Q0,BB,IOR)) IERR=1
ENDIF
ENDIF
END SUBROUTINE LINE_PLANE_INTERSECT
LOGICAL FUNCTION POINT_IN_BOX_2D(P,BB,IOR)
IMPLICIT NONE
REAL(EB), INTENT(IN) :: P(3),BB(6)
INTEGER, INTENT(IN) :: IOR
POINT_IN_BOX_2D=.FALSE.
SELECT CASE(ABS(IOR))
CASE(1) ! YZ plane
IF ( P(2)>=BB(3).AND.P(2)<=BB(4) .AND. &
P(3)>=BB(5).AND.P(3)<=BB(6) ) POINT_IN_BOX_2D=.TRUE.
CASE(2) ! XZ plane
IF ( P(1)>=BB(1).AND.P(1)<=BB(2) .AND. &
P(3)>=BB(5).AND.P(3)<=BB(6) ) POINT_IN_BOX_2D=.TRUE.
CASE(3) ! XY plane
IF ( P(1)>=BB(1).AND.P(1)<=BB(2) .AND. &
P(2)>=BB(3).AND.P(2)<=BB(4) ) POINT_IN_BOX_2D=.TRUE.
END SELECT
END FUNCTION POINT_IN_BOX_2D
LOGICAL FUNCTION POINT_IN_TETRAHEDRON(XP,V1,V2,V3,V4,BB)
USE MATH_FUNCTIONS, ONLY: CROSS_PRODUCT
IMPLICIT NONE
REAL(EB), INTENT(IN) :: XP(3),V1(3),V2(3),V3(3),V4(3),BB(6)
REAL(EB) :: U_VEC(3),V_VEC(3),N_VEC(3),Q_VEC(3),R_VEC(3)
INTEGER :: I
! In this routine, we test all four faces of the tet volume defined by the points X(i),Y(i),Z(i); i=1:4.
! If the point is on the negative side of all the faces, it is inside the volume.
POINT_IN_TETRAHEDRON=.FALSE.
! first test bounding box
IF (XP(1)<BB(1)) RETURN
IF (XP(1)>BB(2)) RETURN
IF (XP(2)<BB(3)) RETURN
IF (XP(2)>BB(4)) RETURN
IF (XP(3)<BB(5)) RETURN
IF (XP(3)>BB(6)) RETURN
POINT_IN_TETRAHEDRON=.TRUE.
FACE_LOOP: DO I=1,4
SELECT CASE(I)
CASE(1)
! vertex ordering = 1,2,3,4
Q_VEC = XP-(/V1(1),V1(2),V1(3)/) ! form a vector from a point on the triangular surface to the point XP
R_VEC = (/V4(1),V4(2),V4(3)/)-(/V1(1),V1(2),V1(3)/) ! vector from the tri to other point of volume defining inside
U_VEC = (/V2(1)-V1(1),V2(2)-V1(2),V2(3)-V1(3)/) ! vectors forming the sides of the triangle
V_VEC = (/V3(1)-V1(1),V3(2)-V1(2),V3(3)-V1(3)/)
CASE(2)
! vertex ordering = 1,3,4,2
Q_VEC = XP-(/V1(1),V1(2),V1(3)/)
R_VEC = (/V2(1),V2(2),V2(3)/)-(/V1(1),V1(2),V1(3)/)
U_VEC = (/V3(1)-V1(1),V3(2)-V1(2),V3(3)-V1(3)/)
V_VEC = (/V4(1)-V1(1),V4(2)-V1(2),V4(3)-V1(3)/)
CASE(3)
! vertex ordering = 1,4,2,3
Q_VEC = XP-(/V1(1),V1(2),V1(3)/)
R_VEC = (/V2(1),V2(2),V2(3)/)-(/V1(1),V1(2),V1(3)/)
U_VEC = (/V4(1)-V1(1),V4(2)-V1(2),V4(3)-V1(3)/)
V_VEC = (/V2(1)-V1(1),V2(2)-V1(2),V2(3)-V1(3)/)
CASE(4)
! vertex ordering = 2,4,3,1
Q_VEC = XP-(/V2(1),V2(2),V2(3)/)
R_VEC = (/V1(1),V1(2),V1(3)/)-(/V2(1),V2(2),V2(3)/)
U_VEC = (/V4(1)-V2(1),V4(2)-V2(2),V4(3)-V2(3)/)
V_VEC = (/V3(1)-V2(1),V3(2)-V2(2),V3(3)-V2(3)/)
END SELECT
! if the sign of the dot products are equal, the point is inside, else it is outside and we return
IF ( ABS( SIGN(1._EB,DOT_PRODUCT(Q_VEC,N_VEC))-SIGN(1._EB,DOT_PRODUCT(R_VEC,N_VEC)) )>ZERO_P ) THEN
POINT_IN_TETRAHEDRON=.FALSE.
RETURN
ENDIF
ENDDO FACE_LOOP
END FUNCTION POINT_IN_TETRAHEDRON
LOGICAL FUNCTION POINT_IN_POLYHEDRON(XP,BB)
IMPLICIT NONE
REAL(EB) :: XP(3),BB(6),XX(3),YY(3),ZZ(3),RAY_DIRECTION(3)
INTEGER :: I,J,N_INTERSECTIONS,IRAY
REAL(EB), PARAMETER :: EPS=1.E-6_EB
! Schneider and Eberly, Geometric Tools for Computer Graphics, Morgan Kaufmann, 2003. Section 13.4
POINT_IN_POLYHEDRON=.FALSE.
! test global bounding box
IF ( XP(1)<BB(1) .OR. XP(1)>BB(2) ) RETURN
IF ( XP(2)<BB(3) .OR. XP(2)>BB(4) ) RETURN
IF ( XP(3)<BB(5) .OR. XP(3)>BB(6) ) RETURN
N_INTERSECTIONS=0
RAY_DIRECTION = (/0._EB,0._EB,1._EB/)
FACE_LOOP: DO I=1,N_FACE
! test bounding box
XX(1) = VERTEX(FACET(I)%VERTEX(1))%X
XX(2) = VERTEX(FACET(I)%VERTEX(2))%X
XX(3) = VERTEX(FACET(I)%VERTEX(3))%X
IF (XP(1)<MINVAL(XX)) CYCLE FACE_LOOP
IF (XP(1)>MAXVAL(XX)) CYCLE FACE_LOOP
YY(1) = VERTEX(FACET(I)%VERTEX(1))%Y
YY(2) = VERTEX(FACET(I)%VERTEX(2))%Y
YY(3) = VERTEX(FACET(I)%VERTEX(3))%Y
IF (XP(2)<MINVAL(YY)) CYCLE FACE_LOOP
IF (XP(2)>MAXVAL(YY)) CYCLE FACE_LOOP
ZZ(1) = VERTEX(FACET(I)%VERTEX(1))%Z
ZZ(2) = VERTEX(FACET(I)%VERTEX(2))%Z
ZZ(3) = VERTEX(FACET(I)%VERTEX(3))%Z
IF (XP(3)>MAXVAL(ZZ)) CYCLE FACE_LOOP
RAY_TEST_LOOP: DO J=1,3
IRAY = RAY_TRIANGLE_INTERSECT(I,XP,RAY_DIRECTION)
SELECT CASE(IRAY)
CASE(0)
! does not intersect
EXIT RAY_TEST_LOOP
CASE(1)
! ray intersects triangle
N_INTERSECTIONS=N_INTERSECTIONS+1
EXIT RAY_TEST_LOOP
CASE(2)
! ray intersects edge, try new ray (shift origin)
IF (J==1) XP=XP+(/EPS,0._EB,0._EB/) ! shift in x direction
IF (J==2) XP=XP+(/0._EB,EPS,0._EB/) ! shift in y direction
IF (J==3) WRITE(LU_ERR,*) 'WARNING: ray test failed'
END SELECT
ENDDO RAY_TEST_LOOP
ENDDO FACE_LOOP
IF ( MOD(N_INTERSECTIONS,2)/=0 ) POINT_IN_POLYHEDRON=.TRUE.
END FUNCTION POINT_IN_POLYHEDRON
LOGICAL FUNCTION POINT_IN_TRIANGLE(P,V1,V2,V3)
USE MATH_FUNCTIONS, ONLY: CROSS_PRODUCT
IMPLICIT NONE
REAL(EB), INTENT(IN) :: P(3),V1(3),V2(3),V3(3)
REAL(EB) :: E(3),E1(3),E2(3),N(3),R(3),Q(3)
INTEGER :: I
REAL(EB), PARAMETER :: EPS=1.E-10_EB
! This routine tests whether the projection of P, in the plane normal
! direction, onto to the plane defined by the triangle (V1,V2,V3) is
! inside the triangle.
POINT_IN_TRIANGLE=.TRUE. ! start by assuming the point is inside
! compute face normal
E1 = V2-V1
E2 = V3-V1
CALL CROSS_PRODUCT(N,E1,E2)
EDGE_LOOP: DO I=1,3
SELECT CASE(I)
CASE(1)
E = V2-V1
R = P-V1
CASE(2)
E = V3-V2
R = P-V2
CASE(3)
E = V1-V3
R = P-V3
END SELECT
CALL CROSS_PRODUCT(Q,E,R)
IF ( DOT_PRODUCT(Q,N) < -EPS ) THEN
POINT_IN_TRIANGLE=.FALSE.
RETURN
ENDIF
ENDDO EDGE_LOOP
END FUNCTION POINT_IN_TRIANGLE
INTEGER FUNCTION RAY_TRIANGLE_INTERSECT(TRI,XP,D)
USE MATH_FUNCTIONS, ONLY: CROSS_PRODUCT
IMPLICIT NONE
INTEGER, INTENT(IN) :: TRI
REAL(EB), INTENT(IN) :: XP(3),D(3)
REAL(EB) :: E1(3),E2(3),P(3),S(3),Q(3),U,V,TMP,V1(3),V2(3),V3(3),T !,XI(3)
REAL(EB), PARAMETER :: EPS=1.E-10_EB
! Schneider and Eberly, Section 11.1
V1(1) = VERTEX(FACET(TRI)%VERTEX(1))%X
V1(2) = VERTEX(FACET(TRI)%VERTEX(1))%Y
V1(3) = VERTEX(FACET(TRI)%VERTEX(1))%Z
V2(1) = VERTEX(FACET(TRI)%VERTEX(2))%X
V2(2) = VERTEX(FACET(TRI)%VERTEX(2))%Y
V2(3) = VERTEX(FACET(TRI)%VERTEX(2))%Z
V3(1) = VERTEX(FACET(TRI)%VERTEX(3))%X
V3(2) = VERTEX(FACET(TRI)%VERTEX(3))%Y
V3(3) = VERTEX(FACET(TRI)%VERTEX(3))%Z
E1 = V2-V1
E2 = V3-V1
CALL CROSS_PRODUCT(P,D,E2)
TMP = DOT_PRODUCT(P,E1)
IF ( ABS(TMP)<EPS ) THEN
RAY_TRIANGLE_INTERSECT=0
RETURN
ENDIF
TMP = 1._EB/TMP
S = XP-V1
U = TMP*DOT_PRODUCT(S,P)
IF (U<-EPS .OR. U>(1._EB+EPS)) THEN
! ray does not intersect triangle
RAY_TRIANGLE_INTERSECT=0
RETURN
ENDIF
IF (U<EPS .OR. U>(1._EB-EPS)) THEN
! ray intersects edge
RAY_TRIANGLE_INTERSECT=2
RETURN
ENDIF
CALL CROSS_PRODUCT(Q,S,E1)
V = TMP*DOT_PRODUCT(D,Q)
IF (V<-EPS .OR. (U+V)>(1._EB+EPS)) THEN
! ray does not intersect triangle
RAY_TRIANGLE_INTERSECT=0
RETURN
ENDIF
IF (V<EPS .OR. (U+V)>(1._EB-EPS)) THEN
! ray intersects edge
RAY_TRIANGLE_INTERSECT=2
RETURN
ENDIF
T = TMP*DOT_PRODUCT(E2,Q)
!XI = XP + T*D ! the intersection point
IF (T>0._EB) THEN
RAY_TRIANGLE_INTERSECT=1
ELSE
RAY_TRIANGLE_INTERSECT=0
ENDIF
RETURN
END FUNCTION RAY_TRIANGLE_INTERSECT
REAL(EB) FUNCTION TRILINEAR(UU,DXI,LL)
IMPLICIT NONE
REAL(EB), INTENT(IN) :: UU(0:1,0:1,0:1),DXI(3),LL(3)
! Comments:
!
! see http://local.wasp.uwa.edu.au/~pbourke/miscellaneous/interpolation/index.html
! with appropriate scaling. LL is length of side.
!
! UU(1,1,1)
! z /----------/
! ^/ / |
! ------------ | Particle position
! | | |
! LL(3) | o<-----|------- DXI = [DXI(1),DXI(2),DXI(3)]
! | | /
! | |/ Particle property at XX = TRILINEAR
! ------------> x
! ^
! |
! X0 = [0,0,0]
!
! UU(0,0,0)
!
!===========================================================
TRILINEAR = UU(0,0,0)*(LL(1)-DXI(1))*(LL(2)-DXI(2))*(LL(3)-DXI(3)) + &
UU(1,0,0)*DXI(1)*(LL(2)-DXI(2))*(LL(3)-DXI(3)) + &
UU(0,1,0)*(LL(1)-DXI(1))*DXI(2)*(LL(3)-DXI(3)) + &
UU(0,0,1)*(LL(1)-DXI(1))*(LL(2)-DXI(2))*DXI(3) + &
UU(1,0,1)*DXI(1)*(LL(2)-DXI(2))*DXI(3) + &
UU(0,1,1)*(LL(1)-DXI(1))*DXI(2)*DXI(3) + &
UU(1,1,0)*DXI(1)*DXI(2)*(LL(3)-DXI(3)) + &
UU(1,1,1)*DXI(1)*DXI(2)*DXI(3)