-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtension-hybridV3.h
144 lines (122 loc) · 3.56 KB
/
tension-hybridV3.h
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
//This has exact lines from SPs integral.h (unlike LS it did not improve the things)
//For begining we calculate the sign distance fn at cell centers by simple averaging
#include "voftols.h"
#undef SEPS
#define SEPS 1e-30
scalar d[];
extern scalar kappa;
extern scalar sigma;
void vof2distCC(scalar c){
vertex scalar ls[];
vof2dist(c,ls);
foreach(){
int num = 0;
d[] = 0.;
for(int ii = 0; ii <= 1; ii++)
for(int jj = 0; jj <= 1; jj++){
if(fabs(ls[ii,jj]) < L0){
d[] += ls[ii,jj];
num += 1;
}
}
if(num > 0)
d[] /= num;
else
d[] = nodata;
}
}
event defaults (i = 0) {
if (is_constant(a.x)) {
a = new face vector;
foreach_face()
a.x[] = 0.;
}
}
event stability (i++)
{
double amin = HUGE, amax = -HUGE, dmin = HUGE;
foreach_face (reduction(min:amin) reduction(max:amax) reduction(min:dmin))
if (fm.x[] > 0.) {
if (alpha.x[]/fm.x[] > amax) amax = alpha.x[]/fm.x[];
if (alpha.x[]/fm.x[] < amin) amin = alpha.x[]/fm.x[];
if (Delta < dmin) dmin = Delta;
}
double rhom = (1./amin + 1./amax)/2.;
foreach(reduction(min:dtmax)){
double dt = sqrt (rhom*cube(dmin)/(pi*sigma[]));
if (dt < dtmax)
dtmax = dt;
}
}
static inline double curvatureLS (Point point, scalar d) {
double dx = (d[1] - d[-1])/2.;
double dy = (d[0,1] - d[0,-1])/2.;
double dxx = d[1] - 2.*d[] + d[-1];
double dyy = d[0,1] - 2.*d[] + d[0,-1];
double dxy = (d[1,1] - d[-1,1] - d[1,-1] + d[-1,-1])/4.;
double dn = sqrt(sq(dx) + sq(dy)) + 1e-30;
bool flagnd = true;
foreach_dimension()
if(fabs(d[]) < nodata || fabs(d[1]) < nodata || fabs(d[-1]) < nodata)
flagnd = false;
if(flagnd)
return nodata;
else
return (sq(dx)*dyy - 2.*dx*dy*dxy + sq(dy)*dxx)/cube(dn)/Delta;
}
event properties(i++){
vof2distCC(f);
curvature(f, kappa);
boundary ({kappa,d});
foreach(){
if(kappa[] == nodata && fabs(d[]) != nodata)
kappa[] = curvatureLS (point, d); // Not true, why did i say earlier that "I am opposite to curvature fn of basilisk"
}
boundary ((scalar *){kappa});
}
event acceleration (i++)
{
tensor S[];
foreach (){
foreach_dimension(){
S.y.y[] = 0.0;
for (int i = -1; i <= 1; i += 2){
if(fabs(d[]) < nodata && fabs(d[1]) < nodata && fabs(d[-1]) < nodata && fabs(kappa[]) < nodata){ // FIX me
if (d[]*(d[] + d[i]) < 0.) {
double xi = d[]/(d[] - d[i] + SEPS);
double nx = ((d[1] - d[-1])/2. +
xi*i*(d[-1] - 2.*d[] + d[1]))/Delta;
double ki = kappa[];// + xi*(kappa[i] - kappa[]);
double sigmaxi = sigma[] + xi * (sigma[i] - sigma[]);
S.y.y[] += sigmaxi*(fabs(nx)/Delta - sign(d[])*ki*(0.5 - xi));
}
}
}
}
}
boundary({S.x.x,S.y.y});
foreach_vertex(){
foreach_dimension(){
S.x.y[] = 0.0;
if ((d[] + d[0, -1]) * (d[-1] + d[-1, -1]) > 0.) // perhaps i can use vertex values
S.x.y[] = 0.0;
else{
if(fabs(d[]) < nodata && fabs(d[-1]) < nodata && fabs(d[-1,-1]) < nodata &&fabs(d[0,-1]) < nodata){ //FIX me
double xi = (d[-1] + d[-1,-1])/(d[-1] + d[-1,-1] - d[] - d[0,-1]);
double ny = (xi*(d[] - d[-1] + d[-1,-1] - d[0,-1]) +
d[-1] - d[-1,-1])/Delta;
double sigmaxi = 0.5 * (sigma[-1] + sigma[-1,-1] + xi * (sigma[] - sigma[-1] - sigma [-1,-1] + sigma[0,-1]));
S.x.y[] = - sigmaxi*sign(d[] + d[0,-1])*ny/Delta;
}
}
}
}
boundary({S.x.y,S.y.x});
face vector ia = a;
foreach_face(){
if(fabs(kappa[]) < nodata){
ia.x[] += alpha.x[] / fm.x[] * (S.x.x[] - S.x.x[-1] + S.x.y[0,1] - S.x.y[]) / Delta;
}
}
boundary((scalar *){ia});
}