forked from monasse/CELIA3D
-
Notifications
You must be signed in to change notification settings - Fork 0
/
couplage.cpp
executable file
·2067 lines (1836 loc) · 83.5 KB
/
couplage.cpp
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
//Copyright 2017 Laurent Monasse
/*
This file is part of CELIA3D.
CELIA3D is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
CELIA3D is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CELIA3D. If not, see <http://www.gnu.org/licenses/>.
*/
/*!
\file
\authors Maria Adela Puscas and Laurent Monasse
\brief Definition of specific coupling functions.
\details Computation of fluid forces and torques acting on the solid, modifications of the fluid fluxes, filling of ghost cells, computation of the swept quantity.
\warning <b> Specific coupling procedures ! </b>
*/
#include "fluide.hpp"
#include "intersections.cpp"
/*!\brief Computation of fluid forces (\a Particule.Ff) and torques (\a Particule.Mf) applied on the \a Solide.
\details Let \a f an interface element, the pressure force exerted by the fluid on interface \a f is given by:
\f{eqnarray*}{
F_f = (- p^x \, A_f n^{x}_f, \,- p^y \,A_f n^{y}_f, \,- p^z \,A_f n^{z}_f )^t
\f} \n
where \f$ A_f \f$ is the area of interface f, \f$ n_f \f$ the exterior normal to f, and \f$ p^x, p^y, p^z \f$ are the effective pressures in the x, y and z directions during the time-step (\a Cellule.pdtx, \a Cellule.pdty and \a Cellule.pdtz).
The fluid torque exerted on f is given by:
\f{eqnarray*}{
M_f = F_f \wedge (X_f - X_I),
\f}
where \f$ X_f \f$ is the center of interface f and \f$ X_I \f$ is the center of the particle containing f.
These forces are transmitted to the solid as being constant during the time-step.
\param S Solid
\param dt Time-step
\warning <b> Specific coupling procedure ! </b>
\return void
*/
void Grille::Forces_fluide(Solide& S, const double dt){
Vector_3 Ffluide(0.,0.,0.);
//Update of fluid forces and torques on the solid
for(int iter_s=0; iter_s<S.size(); iter_s++){
S.solide[iter_s].Ffprev = S.solide[iter_s].Ff;
S.solide[iter_s].Mfprev = S.solide[iter_s].Mf;
Point_3 Xn = S.solide[iter_s].x0 + S.solide[iter_s].Dx;
double fx=0.; double fy=0.; double fz=0.;
Kernel::FT mx = 0.,my = 0. ,mz = 0.;
for(int it=0; it<S.solide[iter_s].triangles.size(); it++){
for(int iter=0; iter<S.solide[iter_s].Position_Triangles_interface[it].size(); iter++)
{
double aire= std::sqrt(CGAL::to_double(S.solide[iter_s].Triangles_interface[it][iter].squared_area()));
if(dt>eps){
int i= S.solide[iter_s].Position_Triangles_interface[it][iter][0];
int j= S.solide[iter_s].Position_Triangles_interface[it][iter][1];
int k= S.solide[iter_s].Position_Triangles_interface[it][iter][2];
if(i>=marge && i<Nx+marge && j>=marge && j<Ny+marge && k>=marge && k<Nz+marge){
double tempx = (grille[i][j][k].pdtx/dt) * aire * (CGAL::to_double(S.solide[iter_s].normales[it].x()));
double tempy = (grille[i][j][k].pdty/dt) * aire * (CGAL::to_double(S.solide[iter_s].normales[it].y()));
double tempz = (grille[i][j][k].pdtz/dt) * aire * (CGAL::to_double(S.solide[iter_s].normales[it].z()));
Vector_3 temp_Mf = cross_product(Vector_3(Xn,Point_3(centroid(S.solide[iter_s].Triangles_interface[it][iter].operator[](0),
S.solide[iter_s].Triangles_interface[it][iter].operator[](1),
S.solide[iter_s].Triangles_interface[it][iter].operator[](2)))),
Vector_3(-tempx,-tempy,-tempz));
fx-= tempx; fy-= tempy; fz-= tempz;
mx+= temp_Mf.x(); my+= temp_Mf.y(); mz+= temp_Mf.z();
}
}
}
}
S.solide[iter_s].Ff = Vector_3(fx,fy,fz);
S.solide[iter_s].Mf = Vector_3(CGAL::to_double(mx),CGAL::to_double(my),CGAL::to_double(mz));
Ffluide = Ffluide + S.solide[iter_s].Ff;
}
cout<<"Fluid forces "<<Ffluide<<endl;
for(int it=0; it<S.solide.size(); it++){
for(int i=0; i<S.solide[it].faces.size(); i++){
if(S.solide[it].faces[i].voisin == -2){
S.solide[it].faces[i].voisin = -1;
}
}
}
}
/*!\brief Modification of fluid fluxes and discrete balance on a cell (cut-cell method).
\details The fluid sees the presence of the solid through this function. The final value of the state \f$ U^{n+1}_{i, j, k}\f$ in the cell is computed using:
\f{eqnarray*}{
\left( 1- \Lambda_{i,j,k}^{n+1} \right) U^{n+1}_{i,j,k} = \left( 1- \Lambda_{i,j,k} ^{n+1}\right) U^n_{i,j,k} + \Delta t \, \left( \frac{(1-\lambda_{i-1/2,j,k}^{n+1} )}{\Delta x_{ i,j,k}} F_{i-1/2, j, k}^{n+1/2} -\frac{(1-\lambda_{i+1/2,j,k}^{n+1} )}{\Delta x_{ i,j,k}} F_{i+1/2, j, k}^{n+1/2} + ...\right) \f}
\f{eqnarray*}{+ \frac{\Delta t}{V_{i,j,k}} \sum_{f \in C_{i,j,k}}{A_{f}} {\phi}_{f_{ i,j,k}} + \sum_{f \in C_{i,j,k}} \Delta U^{n, n+1}_{f_{ i,j,k}} .
\f}
where \f$ \Lambda_{i,j,k}^{n+1} \f$: \a Cellule.alpha (solid occupancy ratio in cell (i,j,k)),\n
\f$ \lambda_{i+1/2,j,k}^{n+1} \f$: \a Cellule.kappai (solid occupancy ratio on the faces of cell (i,j,k)),\n
\f$ F_{i+1/2, j, k}^{n+1/2} \f$: \a Cellule.fluxi (flux to the right of cell (i,j,k)), \n
\f$ V_{i,j,k} \f$: volume of cell (i,j,k), \n
\f{eqnarray*}{ \phi_{f_{ i,j,k}} = (0, \Pi_x, \Pi_y,\Pi_z, \Pi_v)^t. \f}
\f$ \Pi_x, \Pi_y,\Pi_z, \Pi_v\f$: \a Cellule.phi_x, \a Cellule.phi_y, Cellule.phi_z, \a Cellule.phi_v (boundary fluxes),\n
\f$ \Delta U^{n, n+1}_{f_{ i,j,k}} \f$: \a Cellule.delta_w (swept quantity).
\param dt Time-step
\warning <b> Specific coupling procedure ! </b>
\return void
*/
void Grille::Modif_fnum(const double dt){
double phi_x=0., phi_y=0., phi_z=0.;
double vol=deltax*deltay*deltaz;
for(int i=marge;i<Nx+marge;i++){
for(int j=marge;j<Ny+marge;j++){
for(int k=marge;k<Nz+marge;k++){
Cellule& c = grille[i][j][k];
if(std::abs(c.alpha-1.)>eps && !c.vide){
Cellule& ci = grille[i-1][j][k];
Cellule& cj = grille[i][j-1][k];
Cellule& ck = grille[i][j][k-1];
c.flux_modif[0] = 0.;
c.flux_modif[1] = c.phi_x;
c.flux_modif[2] = c.phi_y;
c.flux_modif[3] = c.phi_z;
c.flux_modif[4] = c.phi_v;
for(int l=0.; l<5; l++){
c.flux_modif[l] -= (1.-c.kappai)*c.dtfxi[l] - (1.-ci.kappai)*ci.dtfxi[l]
+ (1.-c.kappaj)*c.dtfyj[l] - (1.-cj.kappaj)*cj.dtfyj[l]
+ (1.-c.kappak)*c.dtfzk[l] - (1.-ck.kappak)*ck.dtfzk[l] - c.delta_w[l];
c.flux_modif[l] /= (1.-c.alpha);
}
//Update of the cell state
c.rho = c.rho0 + c.flux_modif[0];
c.impx = c.impx0 + c.flux_modif[1];
c.impy = c.impy0 + c.flux_modif[2];
c.impz = c.impz0 + c.flux_modif[3];
c.rhoE = c.rhoE0 + c.flux_modif[4];
if(std::abs(c.rho) > eps_vide){
c.u = c.impx/c.rho;
c.v = c.impy/c.rho;
c.w = c.impz/c.rho;
c.p = (gam-1.)*(c.rhoE-c.rho*c.u*c.u/2.-c.rho*c.v*c.v/2. - c.rho*c.w*c.w/2.);
if(std::abs(c.p) > eps_vide){
c.vide = false;
}
phi_x+=c.phi_x*vol/dt; phi_y+=c.phi_y*vol/dt; phi_z+=c.phi_z*vol/dt;
}
if( (abs(c.rho) <= eps_vide) || (abs(c.p) <= eps_vide)){
c.u = 0.; c.v = 0.; c.w = 0.; c.p = 0.;
c.impx=0.; c.impy=0.; c.impz=0.; c.rhoE=0.;
c.vide = true;
}
else{c.vide = false;}
}
}
}
}
Vector_3 Phi(phi_x, phi_y, phi_z); cout<<" Boundary flux "<<Phi<<endl;
}
/*!\brief Conservative mixing of small cut-cells.
\details We define a small cut-cell as a cell such that \f$ alpha > epsa \f$ (\a Cellule.alpha solid occupancy ratio, and \a epsa: limit ratio for small cut-cells defined in parametres.hpp). In order not to modify the time-step which ensuring the CFL condition, the small cut-cells are merged with their neighbours. Denote \a p a small cut-cell and \a g a neighbouring cell such that \a g is totally fluid~(\f$ alpha_g = 0 \f$ ). Define the following exchange terms:
\f{eqnarray*}{ E_{pg} = \frac{1}{2 - alpha_p} (U_g - U_{p}), \quad E_{gp} = \frac{1- alpha_p}{2 - alpha_p} (U_p - U_{g}) \f}
and set:
\f{eqnarray*}{
U_p = U_{p} + E_{pg}, \quad \quad U_g = U_{g} + E_{gp} \f}
\warning <b> Specific coupling procedure ! </b>
\return void
*/
void Grille::Mixage(){
bool test_fini = true;
for(int i=marge;i<Nx+marge;i++){
for(int j=marge;j<Ny+marge;j++){
for(int k=marge;k<Nz+marge;k++){
Cellule& cp = grille[i][j][k];
bool test=true;
if( (cp.alpha>epsa ||cp.p <0. || cp.rho<0.) && abs(cp.alpha-1.)>eps && !cp.vide){
for(int ii=-1; ii<=1 && test; ii++){
for(int jj=-1; jj<=1 && test; jj++){
for(int kk=-1; kk<=1 && test; kk++){
if (grille[i+ii][j+jj][k+kk].alpha <eps && grille[i+ii][j+jj][k+kk].p>0. && grille[i+ii][j+jj][k+kk].rho>0. && i+ii>=marge && i+ii<Nx+marge && j+jj>=marge && j+jj<Ny+marge && k+kk>=marge && k+kk<Nz+marge && !grille[i+ii][j+jj][k+kk].vide)
{
test=false;
Cellule& cg = grille[i+ii][j+jj][k+kk];
double temp_rhop= cp.rho;
double temp_rhog=cg.rho;
cp.Mrho = (cg.rho - cp.rho)/(2. - cp.alpha) ;
cp.Mimpx = (cg.impx - cp.impx)/(2. - cp.alpha);
cp.Mimpy = (cg.impy - cp.impy)/(2. - cp.alpha);
cp.Mimpz = (cg.impz - cp.impz)/(2. - cp.alpha);
cp.MrhoE = (cg.rhoE - cp.rhoE)/(2. - cp.alpha);
cg.Mrho = (1.-cp.alpha)*(cp.rho - cg.rho)/(2. - cp.alpha) ;
cg.Mimpx = (1.-cp.alpha)*(cp.impx - cg.impx)/(2. - cp.alpha);
cg.Mimpy = (1.-cp.alpha)*(cp.impy - cg.impy)/(2. - cp.alpha);
cg.Mimpz = (1.-cp.alpha)*(cp.impz - cg.impz)/(2. - cp.alpha);
cg.MrhoE = (1.-cp.alpha)*(cp.rhoE - cg.rhoE)/(2. - cp.alpha);
cp.rho += cp.Mrho;
cp.impx += cp.Mimpx;
cp.impy += cp.Mimpy;
cp.impz += cp.Mimpz;
cp.rhoE += cp.MrhoE;
cp.u = cp.impx/cp.rho;
cp.v = cp.impy/cp.rho;
cp.w = cp.impz/cp.rho;
cp.p = (gam-1.)*(cp.rhoE-cp.rho*cp.u*cp.u/2.-cp.rho*cp.v*cp.v/2. - cp.rho*cp.w*cp.w/2.);
cg.rho += cg.Mrho;
cg.impx += cg.Mimpx;
cg.impy += cg.Mimpy;
cg.impz += cg.Mimpz;
cg.rhoE += cg.MrhoE;
cg.u = cg.impx/cg.rho;
cg.v = cg.impy/cg.rho;
cg.w = cg.impz/cg.rho;
cg.p = (gam-1.)*(cg.rhoE-cg.rho*cg.u*cg.u/2.-cg.rho*cg.v*cg.v/2. - cg.rho*cg.w*cg.w/2.);
}
}
}
}
if(test){
if (grille[i-2][j][k].alpha == 0. && grille[i-2][j][k].p>0. && grille[i-2][j][k].rho>0. && i-2>=marge && !grille[i-2][j][k].vide)
{
Cellule& cg = grille[i-2][j][k];
cp.Mrho = (cg.rho - cp.rho)/(2. - cp.alpha) ;
cp.Mimpx = (cg.impx - cp.impx)/(2. - cp.alpha);
cp.Mimpy = (cg.impy - cp.impy)/(2. - cp.alpha);
cp.Mimpz = (cg.impz - cp.impz)/(2. - cp.alpha);
cp.MrhoE = (cg.rhoE - cp.rhoE)/(2. - cp.alpha);
cg.Mrho = (1.-cp.alpha)*(cp.rho - cg.rho)/(2. - cp.alpha) ;
cg.Mimpx = (1.-cp.alpha)*(cp.impx - cg.impx)/(2. - cp.alpha);
cg.Mimpy = (1.-cp.alpha)*(cp.impy - cg.impy)/(2. - cp.alpha);
cg.Mimpz = (1.-cp.alpha)*(cp.impz - cg.impz)/(2. - cp.alpha);
cg.MrhoE = (1.-cp.alpha)*(cp.rhoE - cg.rhoE)/(2. - cp.alpha);
cp.rho += cp.Mrho;
cp.impx += cp.Mimpx;
cp.impy += cp.Mimpy;
cp.impz += cp.Mimpz;
cp.rhoE += cp.MrhoE;
cp.u = cp.impx/cp.rho;
cp.v = cp.impy/cp.rho;
cp.w = cp.impz/cp.rho;
cp.p = (gam-1.)*(cp.rhoE-cp.rho*cp.u*cp.u/2.-cp.rho*cp.v*cp.v/2. - cp.rho*cp.w*cp.w/2.);
cg.rho += cg.Mrho;
cg.impx += cg.Mimpx;
cg.impy += cg.Mimpy;
cg.impz += cg.Mimpz;
cg.rhoE += cg.MrhoE;
cg.u = cg.impx/cg.rho;
cg.v = cg.impy/cg.rho;
cg.w = cg.impz/cg.rho;
cg.p = (gam-1.)*(cg.rhoE-cg.rho*cg.u*cg.u/2.-cg.rho*cg.v*cg.v/2. - cg.rho*cg.w*cg.w/2.);
test = false;
}
else if (grille[i+2][j][k].alpha == 0. && grille[i+2][j][k].p>0. && grille[i+2][j][k].rho>0. && i+2<Nx+marge && !grille[i+2][j][k].vide)
{
Cellule& cg = grille[i+2][j][k];
cp.Mrho = (cg.rho - cp.rho)/(2. - cp.alpha) ;
cp.Mimpx = (cg.impx - cp.impx)/(2. - cp.alpha);
cp.Mimpy = (cg.impy - cp.impy)/(2. - cp.alpha);
cp.Mimpz = (cg.impz - cp.impz)/(2. - cp.alpha);
cp.MrhoE = (cg.rhoE - cp.rhoE)/(2. - cp.alpha);
cg.Mrho = (1.-cp.alpha)*(cp.rho - cg.rho)/(2. - cp.alpha) ;
cg.Mimpx = (1.-cp.alpha)*(cp.impx - cg.impx)/(2. - cp.alpha);
cg.Mimpy = (1.-cp.alpha)*(cp.impy - cg.impy)/(2. - cp.alpha);
cg.Mimpz = (1.-cp.alpha)*(cp.impz - cg.impz)/(2. - cp.alpha);
cg.MrhoE = (1.-cp.alpha)*(cp.rhoE - cg.rhoE)/(2. - cp.alpha);
cp.rho += cp.Mrho;
cp.impx += cp.Mimpx;
cp.impy += cp.Mimpy;
cp.impz += cp.Mimpz;
cp.rhoE += cp.MrhoE;
cp.u = cp.impx/cp.rho;
cp.v = cp.impy/cp.rho;
cp.w = cp.impz/cp.rho;
cp.p = (gam-1.)*(cp.rhoE-cp.rho*cp.u*cp.u/2.-cp.rho*cp.v*cp.v/2. - cp.rho*cp.w*cp.w/2.);
cg.rho += cg.Mrho;
cg.impx += cg.Mimpx;
cg.impy += cg.Mimpy;
cg.impz += cg.Mimpz;
cg.rhoE += cg.MrhoE;
cg.u = cg.impx/cg.rho;
cg.v = cg.impy/cg.rho;
cg.w = cg.impz/cg.rho;
cg.p = (gam-1.)*(cg.rhoE-cg.rho*cg.u*cg.u/2.-cg.rho*cg.v*cg.v/2. - cg.rho*cg.w*cg.w/2.);
test = false;
}
else if (grille[i][j-2][k].alpha == 0. && grille[i][j-2][k].p>0. && grille[i][j-2][k].rho>0. && j-2>=marge && !grille[i][j-2][k].vide)
{
Cellule& cg = grille[i][j-2][k];
cp.Mrho = (cg.rho - cp.rho)/(2. - cp.alpha) ;
cp.Mimpx = (cg.impx - cp.impx)/(2. - cp.alpha);
cp.Mimpy = (cg.impy - cp.impy)/(2. - cp.alpha);
cp.Mimpz = (cg.impz - cp.impz)/(2. - cp.alpha);
cp.MrhoE = (cg.rhoE - cp.rhoE)/(2. - cp.alpha);
cg.Mrho = (1.-cp.alpha)*(cp.rho - cg.rho)/(2. - cp.alpha) ;
cg.Mimpx = (1.-cp.alpha)*(cp.impx - cg.impx)/(2. - cp.alpha);
cg.Mimpy = (1.-cp.alpha)*(cp.impy - cg.impy)/(2. - cp.alpha);
cg.Mimpz = (1.-cp.alpha)*(cp.impz - cg.impz)/(2. - cp.alpha);
cg.MrhoE = (1.-cp.alpha)*(cp.rhoE - cg.rhoE)/(2. - cp.alpha);
cp.rho += cp.Mrho;
cp.impx += cp.Mimpx;
cp.impy += cp.Mimpy;
cp.impz += cp.Mimpz;
cp.rhoE += cp.MrhoE;
cp.u = cp.impx/cp.rho;
cp.v = cp.impy/cp.rho;
cp.w = cp.impz/cp.rho;
cp.p = (gam-1.)*(cp.rhoE-cp.rho*cp.u*cp.u/2.-cp.rho*cp.v*cp.v/2. - cp.rho*cp.w*cp.w/2.);
cg.rho += cg.Mrho;
cg.impx += cg.Mimpx;
cg.impy += cg.Mimpy;
cg.impz += cg.Mimpz;
cg.rhoE += cg.MrhoE;
cg.u = cg.impx/cg.rho;
cg.v = cg.impy/cg.rho;
cg.w = cg.impz/cg.rho;
cg.p = (gam-1.)*(cg.rhoE-cg.rho*cg.u*cg.u/2.-cg.rho*cg.v*cg.v/2. - cg.rho*cg.w*cg.w/2.);
test = false;
}
else if (grille[i][j+2][k].alpha == 0. && grille[i][j+2][k].p>0. && grille[i][j+2][k].rho>0.&& j+2<Ny+marge && !grille[i][j+2][k].vide)
{
Cellule& cg = grille[i][j+2][k];
cp.Mrho = (cg.rho - cp.rho)/(2. - cp.alpha) ;
cp.Mimpx = (cg.impx - cp.impx)/(2. - cp.alpha);
cp.Mimpy = (cg.impy - cp.impy)/(2. - cp.alpha);
cp.Mimpz = (cg.impz - cp.impz)/(2. - cp.alpha);
cp.MrhoE = (cg.rhoE - cp.rhoE)/(2. - cp.alpha);
cg.Mrho = (1.-cp.alpha)*(cp.rho - cg.rho)/(2. - cp.alpha) ;
cg.Mimpx = (1.-cp.alpha)*(cp.impx - cg.impx)/(2. - cp.alpha);
cg.Mimpy = (1.-cp.alpha)*(cp.impy - cg.impy)/(2. - cp.alpha);
cg.Mimpz = (1.-cp.alpha)*(cp.impz - cg.impz)/(2. - cp.alpha);
cg.MrhoE = (1.-cp.alpha)*(cp.rhoE - cg.rhoE)/(2. - cp.alpha);
cp.rho += cp.Mrho;
cp.impx += cp.Mimpx;
cp.impy += cp.Mimpy;
cp.impz += cp.Mimpz;
cp.rhoE += cp.MrhoE;
cp.u = cp.impx/cp.rho;
cp.v = cp.impy/cp.rho;
cp.w = cp.impz/cp.rho;
cp.p = (gam-1.)*(cp.rhoE-cp.rho*cp.u*cp.u/2.-cp.rho*cp.v*cp.v/2. - cp.rho*cp.w*cp.w/2.);
cg.rho += cg.Mrho;
cg.impx += cg.Mimpx;
cg.impy += cg.Mimpy;
cg.impz += cg.Mimpz;
cg.rhoE += cg.MrhoE;
cg.u = cg.impx/cg.rho;
cg.v = cg.impy/cg.rho;
cg.w = cg.impz/cg.rho;
cg.p = (gam-1.)*(cg.rhoE-cg.rho*cg.u*cg.u/2.-cg.rho*cg.v*cg.v/2. - cg.rho*cg.w*cg.w/2.);
test = false;
}
else if (grille[i][j][k-2].alpha == 0. && grille[i][j][k-2].p>0. && grille[i][j][k-2].rho>0.&& k-2>=marge && !grille[i][j][k-2].vide)
{
Cellule& cg = grille[i][j][k-2];
cp.Mrho = (cg.rho - cp.rho)/(2. - cp.alpha) ;
cp.Mimpx = (cg.impx - cp.impx)/(2. - cp.alpha);
cp.Mimpy = (cg.impy - cp.impy)/(2. - cp.alpha);
cp.Mimpz = (cg.impz - cp.impz)/(2. - cp.alpha);
cp.MrhoE = (cg.rhoE - cp.rhoE)/(2. - cp.alpha);
cg.Mrho = (1.-cp.alpha)*(cp.rho - cg.rho)/(2. - cp.alpha) ;
cg.Mimpx = (1.-cp.alpha)*(cp.impx - cg.impx)/(2. - cp.alpha);
cg.Mimpy = (1.-cp.alpha)*(cp.impy - cg.impy)/(2. - cp.alpha);
cg.Mimpz = (1.-cp.alpha)*(cp.impz - cg.impz)/(2. - cp.alpha);
cg.MrhoE = (1.-cp.alpha)*(cp.rhoE - cg.rhoE)/(2. - cp.alpha);
cp.rho += cp.Mrho;
cp.impx += cp.Mimpx;
cp.impy += cp.Mimpy;
cp.impz += cp.Mimpz;
cp.rhoE += cp.MrhoE;
cp.u = cp.impx/cp.rho;
cp.v = cp.impy/cp.rho;
cp.w = cp.impz/cp.rho;
cp.p = (gam-1.)*(cp.rhoE-cp.rho*cp.u*cp.u/2.-cp.rho*cp.v*cp.v/2. - cp.rho*cp.w*cp.w/2.);
cg.rho += cg.Mrho;
cg.impx += cg.Mimpx;
cg.impy += cg.Mimpy;
cg.impz += cg.Mimpz;
cg.rhoE += cg.MrhoE;
cg.u = cg.impx/cg.rho;
cg.v = cg.impy/cg.rho;
cg.w = cg.impz/cg.rho;
cg.p = (gam-1.)*(cg.rhoE-cg.rho*cg.u*cg.u/2.-cg.rho*cg.v*cg.v/2. - cg.rho*cg.w*cg.w/2.);
test = false;
}
else if(grille[i][j][k+2].alpha == 0. && grille[i][j][k+2].p>0. && grille[i][j][k+2].rho>0. && k+2 < Nz+marge && !grille[i][j][k+2].vide)
{
Cellule& cg = grille[i][j][k+2];
cp.Mrho = (cg.rho - cp.rho)/(2. - cp.alpha) ;
cp.Mimpx = (cg.impx - cp.impx)/(2. - cp.alpha);
cp.Mimpy = (cg.impy - cp.impy)/(2. - cp.alpha);
cp.Mimpz = (cg.impz - cp.impz)/(2. - cp.alpha);
cp.MrhoE = (cg.rhoE - cp.rhoE)/(2. - cp.alpha);
cg.Mrho = (1.-cp.alpha)*(cp.rho - cg.rho)/(2. - cp.alpha) ;
cg.Mimpx = (1.-cp.alpha)*(cp.impx - cg.impx)/(2. - cp.alpha);
cg.Mimpy = (1.-cp.alpha)*(cp.impy - cg.impy)/(2. - cp.alpha);
cg.Mimpz = (1.-cp.alpha)*(cp.impz - cg.impz)/(2. - cp.alpha);
cg.MrhoE = (1.-cp.alpha)*(cp.rhoE - cg.rhoE)/(2. - cp.alpha);
cp.rho += cp.Mrho;
cp.impx += cp.Mimpx;
cp.impy += cp.Mimpy;
cp.impz += cp.Mimpz;
cp.rhoE += cp.MrhoE;
cp.u = cp.impx/cp.rho;
cp.v = cp.impy/cp.rho;
cp.w = cp.impz/cp.rho;
cp.p = (gam-1.)*(cp.rhoE-cp.rho*cp.u*cp.u/2.-cp.rho*cp.v*cp.v/2. - cp.rho*cp.w*cp.w/2.);
cg.rho += cg.Mrho;
cg.impx += cg.Mimpx;
cg.impy += cg.Mimpy;
cg.impz += cg.Mimpz;
cg.rhoE += cg.MrhoE;
cg.u = cg.impx/cg.rho;
cg.v = cg.impy/cg.rho;
cg.w = cg.impz/cg.rho;
cg.p = (gam-1.)*(cg.rhoE-cg.rho*cg.u*cg.u/2.-cg.rho*cg.v*cg.v/2. - cg.rho*cg.w*cg.w/2.);
test = false;
}
}
else if(test){
std::cout<<"No mixing target cell"<<std::endl;
std::cout<< "Position of the cell center: "<<grille[i][j][k].x << " "<<grille[i][j][k].y << " "<<grille[i][j][k].z << " "<< " rho "<<grille[i][j][k].rho << " p "<<grille[i][j][k].p <<" alpha " << grille[i][j][k].alpha<<std::endl;
std::cout<<"Neighbouring cells: "<<std::endl;
for(int ii=-1; ii<=1 && test; ii++){
for(int jj=-1; jj<=1 && test; jj++){
for(int kk=-1; kk<=1 && test; kk++){
std::cout<<"alpha "<<grille[i+ii][j+jj][k+kk].alpha<< " "<< " rho "<<grille[i+ii][j+jj][k+kk].rho << "p "<< grille[i+ii][j+jj][k+kk].p<<std::endl;
}
}
}
}
if(grille[i][j][k].p<0. || grille[i][j][k].rho<0.){
test_fini = false;
}
}
}
}
}
if(!test_fini){
cout<<" Mixing did not complete "<<endl;
Mixage();
}
}
/*!\brief Resolution of the fluid equations.
\details Directional (Strang) splitting at each time-step.
\param t Current simulation time
\param dt Time-step
\param n index of the time iterations
\return void
*/
void Grille::Solve(const double dt, double t, int n, Solide& S){
for(int i=0;i<Nx+2*marge;i++){
for(int j=0;j<Ny+2*marge;j++){
for(int k=0;k<Nz+2*marge;k++){
Cellule c = grille[i][j][k];
c.rho0 = c.rho;
c.impx0 = c.impx;
c.impy0 = c.impy;
c.impz0 = c.impz;
c.rhoE0 = c.rhoE;
c.p1=c.p;
c.alpha0=c.alpha;
c.kappai0 = c.kappai; c.kappaj0 = c.kappaj; c.kappak0 = c.kappak;
grille[i][j][k] = c;
}
}
}
//Directional splitting
if(n%6==0){
fnumx(dt/dx,t);
solve_fluidx(dt);
BC();
Fill_cel(S);
fnumy(dt/dy,t);
solve_fluidy(dt);
BC();
Fill_cel(S);
fnumz(dt/dz,t);
solve_fluidz(dt);
BC();
Fill_cel(S);
}
else if(n%6==2){
fnumx(dt/dx,t);
solve_fluidx(dt);
BC();
Fill_cel(S);
fnumz(dt/dz,t);
solve_fluidz(dt);
BC();
Fill_cel(S);
fnumy(dt/dy,t);
solve_fluidy(dt);
BC();
Fill_cel(S);
}
else if(n%6==1){
fnumy(dt/dy,t);
solve_fluidy(dt);
BC();
Fill_cel(S);
fnumx(dt/dx,t);
solve_fluidx(dt);
BC();
Fill_cel(S);
fnumz(dt/dz,t);
solve_fluidz(dt);
BC();
Fill_cel(S);
}
else if(n%6==3){
fnumy(dt/dy,t);
solve_fluidy(dt);
BC();
Fill_cel(S);
fnumz(dt/dz,t);
solve_fluidz(dt);
BC();
Fill_cel(S);
fnumx(dt/dx,t);
solve_fluidx(dt);
BC();
Fill_cel(S);
}
else if(n%6==4){
fnumz(dt/dz,t);
solve_fluidz(dt);
BC();
Fill_cel(S);
fnumx(dt/dx,t);
solve_fluidx(dt);
BC();
Fill_cel(S);
fnumy(dt/dy,t);
solve_fluidy(dt);
BC();
Fill_cel(S);
}
else if(n%6==5){
fnumz(dt/dz,t);
solve_fluidz(dt);
BC();
Fill_cel(S);
fnumy(dt/dy,t);
solve_fluidy(dt);
BC();
Fill_cel(S);
fnumx(dt/dx,t);
solve_fluidx(dt);
BC();
Fill_cel(S);
}
}
/*!\brief Filling of the ghost cells (\a alpha = 1)
\details In order to compute the fluxes at the fluid-solid interface, we define a fictitious state in the cells fully occupied by solid (\a alpha = 1), which is taken equal to the state in the mirror cell with regards to the boundary. \n
Algorithm: search for the interface closest to the center of the cell (loop on all solid faces) and compute the projection of the cell center on this interface using function <b> CGAL::projection(Point_3) </b>.
\param S Solid
\warning <b> Specific coupling procedure ! </b>
\return void
*/
void Grille::Fill_cel(Solide& S){
int nb_part = S.size();
double dist[6*nb_part];
double dist_min = 100;
int poz=0;
double x_min=0., y_min=0., z_min = 0., x_max = 0., y_max=0., z_max=0.;
Bbox Fluide(X0,Y0,Z0,X0+domainex,Y0+domainey,Z0+domainez);
for(int i=marge;i<Nx+marge;i++){
for(int j=marge;j<Ny+marge;j++){
for(int k=marge;k<Nz+marge;k++){
Triangle_3 Tri;
Cellule& c = grille[i][j][k];
if((std::abs(c.alpha-1.)<eps) ){
Point_3 center_cell(c.x, c.y, c.z);
int nbx=0, nby=0,nbz=0;
Point_3 projete(0.,0.,0.); //Projection on the closest face
Vector_3 V_f(0.,0.,0.); //Velocity of the solid boundary at the projected point
double dist_min = 10000000.;
bool fluide = false;
int cas = 0;
Point_3 triangle1;
Point_3 triangle2;
Point_3 triangle3;
for(int iter=0; iter<nb_part; iter++){
for(int it=0;it<S.solide[iter].triangles.size();it++){
if(S.solide[iter].fluide[it]){
Plane_3 P(S.solide[iter].triangles[it].operator[](0),S.solide[iter].triangles[it].operator[](1),S.solide[iter].triangles[it].operator[](2));
Point_3 xP = P.projection(center_cell);
//Test whether the projection is on the face
bool test = true;
for(int k=0;k<3 && test;k++){
int kp = (k+1)%3;
Point_3 x1 = S.solide[iter].triangles[it].operator[](k);
Point_3 x2 = S.solide[iter].triangles[it].operator[](kp);
Vector_3 vect1(xP,x1);
Vector_3 vect2(xP,x2);
if(CGAL::to_double(CGAL::cross_product(vect1,vect2)*S.solide[iter].normales[it])<0.){
test = false;
}
}
//First case: the point is on the face
if(test){
double d = sqrt(CGAL::to_double(CGAL::squared_distance(center_cell,xP)));
if(d<dist_min && inside_box(Fluide,xP)){
dist_min = d;
projete = xP;
V_f = S.solide[iter].vitesse_parois(xP);
fluide = S.solide[iter].fluide[it];
cas = 1;
triangle1=S.solide[iter].triangles[it].operator[](0);
triangle2=S.solide[iter].triangles[it].operator[](1);
triangle3=S.solide[iter].triangles[it].operator[](2);
}
}
//Second case: the point is out of the face
else{
//Search for the closest point on all edges
for(int k=0;k<3;k++){
int kp = (k+1)%3;
Point_3 x1 = S.solide[iter].triangles[it].operator[](k);
Point_3 x2 = S.solide[iter].triangles[it].operator[](kp);
double d1 = sqrt(CGAL::to_double(CGAL::squared_distance(center_cell,x1)));
double d2 = sqrt(CGAL::to_double(CGAL::squared_distance(center_cell,x2)));
double d12 = sqrt(CGAL::to_double(CGAL::squared_distance(x1,x2)));
//First subcase: the closest point is x1
if(d1*d1+d12*d12<d2*d2){
if(d1<dist_min && inside_box(Fluide,x1)){
dist_min = d1;
projete = x1;
V_f = S.solide[iter].vitesse_parois(x1);
fluide = S.solide[iter].fluide[it];
cas = 2;
}
}
//Second subcase: the closest point is x2
else if(d2*d2+d12*d12<d1*d1){
if(d2<dist_min && inside_box(Fluide,x2)){
dist_min = d2;
projete = x2;
V_f = S.solide[iter].vitesse_parois(x2);
fluide = S.solide[iter].fluide[it];
cas = 3;
}
}
//Third subcase: take the projection on (x1,x2)
else {
Line_3 L(x1,x2);
double d = sqrt(CGAL::to_double(CGAL::squared_distance(center_cell,L)));
Point_3 proj = L.projection(center_cell);
if(d<dist_min && inside_box(Fluide,proj)){
dist_min = d;
projete = proj;
V_f = S.solide[iter].vitesse_parois(proj);
fluide = S.solide[iter].fluide[it];
cas = 4;
}
}
}
}
}
}
}
//Computation of the symmetric point with regards to the plan defined by centre_face and normale_face
Point_3 symm_center = center_cell + Vector_3(center_cell,projete)*2;
Vector_3 normale(center_cell,projete);
double norme = sqrt(CGAL::to_double(normale.squared_length()));
assert(norme!= 0.);
normale = normale*1./norme;
const Cellule& cm = in_cell(symm_center);
Vector_3 vit_m(cm.u,cm.v,cm.w); //Velocity at the mirror point
Vector_3 vit = vit_m - normale*2.*((vit_m-V_f)*normale);
if(abs(cm.alpha-1.)<eps){
cout << "solid target cell: original=" << c.x << " " << c.y << " " << c.z << " target=" << cm.x << " " << cm.y << " " << cm.z << " projection=" << projete.x() << " " << projete.y() << " " << projete.z() << " fluid=" << fluide << " case=" << cas << " triangle=" << triangle1.x() << " " << triangle1.y() << " " << triangle1.z() << " " << triangle2.x() << " " << triangle2.y() << " " << triangle2.z() << " " << triangle3.x() << " " << triangle3.y() << " " << triangle3.z() << " " << endl;
}
c.rho = cm.rho;
c.u = CGAL::to_double(vit.operator[](0));
c.v = CGAL::to_double(vit.operator[](1));
c.w = CGAL::to_double(vit.operator[](2));
c.p = cm.p;
c.impx = c.rho*c.u;
c.impy = c.rho*c.v;
c.impz = c.rho*c.w;
if(std::abs(2.*(c.u*c.u+c.v*c.v+c.w*c.w)+c.p/(gam-1.)) > eps_vide){
c.rhoE = c.rho/2.*(c.u*c.u+c.v*c.v+c.w*c.w)+c.p/(gam-1.);
}
if( (std::abs(c.rho) <= eps_vide ) || (std::abs(c.p)<= eps_vide) ){
c.vide = true;
}
else{c.vide = false;}
}
}
}
}
}
/*!\brief Computation of the signed volume of a prism.
\details The signed volume of the prism with bases the triangles \f$ T1(A_1,B_1,C_1) \f$ and \f$ T2(A_2,B_2,C_2) \f$ is given by: \n
\f{eqnarray*}{
{\Vert A_1 B_1 C_1 A_2 B_2 C_2 \Vert}_P = \frac{1}{36} \left( 2 \vec{A_1 B_1} \wedge \vec{A_1 C_1} + 2 \vec{A_2 B_2} \wedge \vec{A_2 C_2} + \vec{A_1 B_1}\wedge \vec{A_2 C_2} + \vec{A_2 B_2}\wedge \vec{A_1 C_1} \right) \cdot
\f}
\f{eqnarray*}{ \left( \vec{A_1 A_2} + \vec{B_1 B_2} + \vec{C_1 C_2}\right)\f}
\param T1 Triangle_3 basis of the prism
\param T2 Triangle_3 basis of prism
\warning <b> Specific coupling procedure ! </b>
\return double
*/
double volume_prisme(const Triangle_3& T1,const Triangle_3& T2){
double volume=0.;
Vector_3 V = 2.*cross_product( Vector_3(T1.operator[](0),T1.operator[](1)), Vector_3(T1.operator[](0),T1.operator[](2)) )
+ 2*cross_product( Vector_3(T2.operator[](0),T2.operator[](1)), Vector_3(T2.operator[](0),T2.operator[](2)) )
+ cross_product( Vector_3(T1.operator[](0),T1.operator[](1)), Vector_3(T2.operator[](0),T2.operator[](2)) )
+ cross_product( Vector_3(T2.operator[](0),T2.operator[](1)), Vector_3(T1.operator[](0),T1.operator[](2)) );
volume = CGAL::to_double((Vector_3(T1.operator[](0),T2.operator[](0)) + Vector_3(T1.operator[](1),T2.operator[](1)) +
Vector_3(T1.operator[](2),T2.operator[](2)))*V);
volume /=36;
return volume;
}
/*!\brief Computation of the signed colume of a tetrahedron.
\details The signed volume of a tetrahedron \f$ T(A,B,C,D) \f$ is given by: \n
\f{eqnarray*}{
{\Vert A B C D \Vert}_{sign} = \frac{1}{6} \vec{A D} \cdot \left( \vec{A B} \wedge \vec{A C} \right)
\f}
\param Tet Tetrahedron
\warning <b> Specific coupling procedure ! </b>
\return double
*/
double volume_tetra(const Tetrahedron& Tet){
return CGAL::to_double(Tet.volume());
}
/*!\brief Barycentric transformation of point Xn.
\details Let Xn a point belonging to triangle Tn(A_1,B_1,C_1). The barycentric transform of Xn is the point Xn1 (belonging to triangle Tn1(A_2,B_2,C_2) ) given by:
\f{eqnarray*}{
\lambda = \frac{\Vert \vec{C_1 Xn} \wedge \vec{C_1 B_1} \Vert }{\Vert \vec{C_1 A_1} \wedge \vec{C_1 B_1} \Vert}
\f}
\f{eqnarray*}{
\mu = \frac{\Vert \vec{C_1 Xn} \wedge \vec{C_1 A_1} \Vert }{\Vert \vec{C_1 B_1} \wedge \vec{C_1 A_1} \Vert}
\f}
\f{eqnarray*}{
Xn1 = \lambda A_2 + \mu B_2 + (1-\lambda -\mu)C_2
\f}
\param Tn Triangle_3
\param Tn1 Triangle_3
\param Xn Point_3
\warning <b> Specific coupling procedure ! </b>
\return Point_3
*/
Point_3 tr(const Triangle_3& Tn, const Triangle_3& Tn1, const Point_3& Xn){
double lambda = 0., mu = 0.;
double AC2 = CGAL::to_double(Vector_3(Tn.vertex(0),Tn.vertex(2)).squared_length());
double BC2 = CGAL::to_double(Vector_3(Tn.vertex(1),Tn.vertex(2)).squared_length());
double AC_BC = CGAL::to_double(Vector_3(Tn.vertex(0),Tn.vertex(2))*Vector_3(Tn.vertex(1),Tn.vertex(2)));
double XC_AC = CGAL::to_double(Vector_3(Xn,Tn.vertex(2))*Vector_3(Tn.vertex(0),Tn.vertex(2)));
double XC_BC = CGAL::to_double(Vector_3(Xn,Tn.vertex(2))*Vector_3(Tn.vertex(1),Tn.vertex(2)));
double dom = AC2*BC2-AC_BC*AC_BC;
double num1 = BC2*XC_AC-AC_BC*XC_BC;
double num2 = AC2*XC_BC-AC_BC*XC_AC;
lambda = num1/dom;
mu = num2/dom;
double x = CGAL::to_double(lambda * Tn1.operator[](0).operator[](0) + mu*Tn1.operator[](1).operator[](0)
+ (1- lambda- mu)*Tn1.operator[](2).operator[](0));
double y = CGAL::to_double(lambda * Tn1.operator[](0).operator[](1) + mu*Tn1.operator[](1).operator[](1)
+ (1- lambda- mu)*Tn1.operator[](2).operator[](1));
double z = CGAL::to_double(lambda * Tn1.operator[](0).operator[](2) + mu*Tn1.operator[](1).operator[](2)
+ (1- lambda- mu)*Tn1.operator[](2).operator[](2));
return Point_3(x, y, z);
}
/*!\brief Barycentric transformation of Triangle T.
\details Calls function \a tr(Triangle_3, Triangle_3, Point_3) for each triangle vertex.
\param Tn Triangle_3
\param Tn1 Triangle_3
\param T Triangle_3
\warning <b> Specific coupling procedure ! </b>
\return Triangle_3
*/
Triangle_3 tr(const Triangle_3& Tn, const Triangle_3& Tn1, const Triangle_3& T){
const Point_3& s = tr( Tn,Tn1, T.operator[](0) );
const Point_3& r = tr( Tn,Tn1, T.operator[](1) );
const Point_3& v = tr( Tn,Tn1, T.operator[](2) );
return Triangle_3(s, r, v);
}
/*!\brief Transformation of a Point_3 into a Point_2.
\details Let Triangle Tn1(A,B,C), the barycentric transform of Point_3 Xn (belonging to Tn1) into a Point_2 is given by:
\f{eqnarray*}{
\lambda = \frac{\Vert \vec{C Xn} \wedge \vec{C B} \Vert }{\Vert \vec{C A} \wedge \vec{C B} \Vert}
\f}
\f{eqnarray*}{
\mu = \frac{\Vert \vec{C A} \wedge \vec{C Xn} \Vert }{\Vert \vec{C A} \wedge \vec{C B} \Vert}
\f}
\f{eqnarray*}{
X_{2d} = (\mu, (1-\lambda-\mu))
\f}
\param Tn1 Triangle_3
\param Xn Point_3
\warning <b> Specific coupling procedure ! </b>
\return Point_2
*/
Point_2 tr(const Triangle_3& Tn1, const Point_3& Xn){
double lambda = 0., mu = 0.;
double AC2 = CGAL::to_double(Vector_3(Tn1.vertex(0),Tn1.vertex(2)).squared_length());
double BC2 = CGAL::to_double(Vector_3(Tn1.vertex(1),Tn1.vertex(2)).squared_length());
double AC_BC = CGAL::to_double(Vector_3(Tn1.vertex(0),Tn1.vertex(2))*Vector_3(Tn1.vertex(1),Tn1.vertex(2)));
double XC_AC = CGAL::to_double(Vector_3(Xn,Tn1.vertex(2))*Vector_3(Tn1.vertex(0),Tn1.vertex(2)));
double XC_BC = CGAL::to_double(Vector_3(Xn,Tn1.vertex(2))*Vector_3(Tn1.vertex(1),Tn1.vertex(2)));
double dom = AC2*BC2-AC_BC*AC_BC;
double num1 = BC2*XC_AC-AC_BC*XC_BC;
double num2 = AC2*XC_BC-AC_BC*XC_AC;
lambda = num1/dom;
mu = num2/dom;
Point_2 M(mu, (1-lambda-mu));
return M;
}
/*!\brief Transformation of a Triangle_3 into a Triangle_2
\details Calls function \a tr(Triangle_3, Point_3) for each triangle vertex.
\param Tn1 Triangle_3
\param T Triangle_3
\warning <b> Specific coupling procedure ! </b>
\return Triangle_2
*/
Triangle_2 tr(const Triangle_3& Tn1, const Triangle_3& T){
const Point_2& s = tr( Tn1, T.operator[](0) );
const Point_2& r = tr( Tn1, T.operator[](1) );
const Point_2& v = tr( Tn1, T.operator[](2) );
return Triangle_2(s, r, v);
}
/*!\brief Barycentric transformation of a Point_2 into a Point_3.
\details Let triangle Tn1(A,B,C), the transform of Point_2 Xn(X,Y) into a point_3 (belonging to Tn1) is given by:
\f{eqnarray*}{
\lambda = 1- X - Y
\f}
\f{eqnarray*}{
\mu = X
\f}
\f{eqnarray*}{
X_{3d} = \lambda A + \mu B + (1-\lambda -\mu)C
\f}
\param Tn1 Triangle_3
\param Xn Point_2
\warning <b> Specific coupling procedure ! </b>
\return Point_3
*/
Point_3 tr(const Triangle_3& Tn1, const Point_2& Xn){
double lambda = CGAL::to_double(1.- Xn.operator[](0) - Xn.operator[](1));
double mu = CGAL::to_double(Xn.operator[](0));
double x = CGAL::to_double(lambda * Tn1.operator[](0).operator[](0) + mu*Tn1.operator[](1).operator[](0)
+ (1- lambda- mu)*Tn1.operator[](2).operator[](0));
double y = CGAL::to_double(lambda * Tn1.operator[](0).operator[](1) + mu*Tn1.operator[](1).operator[](1)
+ (1- lambda- mu)*Tn1.operator[](2).operator[](1));
double z = CGAL::to_double(lambda * Tn1.operator[](0).operator[](2) + mu*Tn1.operator[](1).operator[](2)
+ (1- lambda- mu)*Tn1.operator[](2).operator[](2));
return Point_3(x,y,z);
}
/*!\brief Barycentric transformation of a Triangle_2 into a Triangle_3
\details Calls function tr(Triangle_3, Point_2) for each triangle vertex.
\param Tn1 Triangle_3
\param T Triangle_2
\warning <b> Specific coupling procedure ! </b>
\return Triangle_3
*/
Triangle_3 tr(const Triangle_3& Tn1, const Triangle_2& T){
const Point_3& s = tr( Tn1, T.operator[](0) );
const Point_3& r = tr( Tn1, T.operator[](1) );
const Point_3& v = tr( Tn1, T.operator[](2) );
return Triangle_3(s, r, v);
}
/*!\brief List of fluid cells intersected by an interface triangle between times t-dt and t.