Repository navigation
Expand file tree
/
Copy pathhole.c
More file actions
420 lines (346 loc) · 14.1 KB
/
Copy pathhole.c
File metadata and controls
420 lines (346 loc) · 14.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
#include "grid/octree.h"
#include "navier-stokes/centered.h"
#include "two-phase.h"
#include "view.h"
#include "vof.h"
#include "tension.h"
//#include "adapt2.h"
//#include "progress.h"
double hx = 0;
double hy = 0;
double hz = 0;
double L = 8;
double h = 1; //sheet thickness
double MAXLEVEL = 8;
double t_out = 0.001;
double t_end = 0.4;
double t_hole =0.001;
double th = 0.125;
double n1 = 0.375; //Size factor of R, we want to make the distance between rim center and hole center is (n1+n2) times of the thickness
//where n1 indicates the radial distance between the nearest interface of the rim and hole center
double n2 = 1.6875;// of n1; //Size factor of A, Major radius is n2 times the thickness
double Theta = 0; // angle of the liquid sheet with x-direction given in degree
double u0 = 68;
double rhog = 1.2e-3;
double mul = 2.68e-3;
double mug = 4.837e-5;
double femax = 1e-8;
double uemax = 1e-8;
int fov1 = 40;
double tx1 = -0.5;
double ty1 = -0.5;
double vmax = 1;
int image_width = 600;
int image_height = 600;
int main(){
init_grid(64);
origin(hx,hy,hz);
// origin(hx,-L/2,L/2);
size(L);
//Physical properties
rho1 = 1., rho2 = rhog;
mu1 = mul, mu2 = mug;
f.sigma =1.;
TOLERANCE = 1.e-6;
// NITERMIN = 2;
// NITERMAX = 30;
run();
}
double X,Y,Z,D,R,r,A,B,e,n2,R2;
scalar f1[], f2[], f3[], f4[], f5[];
event init(t = 0){
if(!restore(file = "dump")){
//We will consider different types of initial sheet.
//1)Planar
// a)flat sheet
// b)inclined sheet
//2)non-panar
// a)curved sheet
// b)spherical
//Though all other cases are great for testing 2b) spherical sheet is somthing we are highly interested because of its resemblence with bag shape of
//deformed droplet for each type of sheet we can use two differnt shape of rim which are a) circular b) elliptical. We can make our desired combination of shape of sheet and rim
//by turning on the flags during compilation. For better rim retraction rate, elliptic rim has been found to work better
#if _planar
X = L/2;
Y = L/2;
Z = L/2;
refine( - (x-X)*sin(Theta*3.14/180) - (y-Y)*cos(Theta*3.14/180) < 4*th && - (x-X)*sin(Theta*3.14/180) - (y-Y)*cos(Theta*3.14/180) > - 4*th && level < MAXLEVEL );
fraction(f, - (x-X)*sin(Theta*3.14/180) - (y-Y)*cos(Theta*3.14/180) + th/2);
fraction(f1, - (x-X)*sin(Theta*3.14/180) - (y-Y)*cos(Theta*3.14/180) - th/2);
#endif
#if _curve
R2 = 0.75*L;//radius of curvature of the curved sheet
// X = R2*sin(Theta*3.14/180);// this angle indicates the angle made by the axis of the cylinder
Y = R2*cos(Theta*3.14/180);
X = L/2;
// Y = L/2;
Z = L/2;
/** A = 0.5;
B =0.2;
R = 1;**/
/**
refine(sq(x)+sq(y) < sq(R2+2*th) && sq(x)+sq(y) > sq(R2-2*th) && level < MAXLEVEL);
fraction(f, -sq(x) - sq(y) + sq(R2+th/2));
fraction(f1, -sq(x) - sq(y) + sq(R2-th/2));
*/
refine( sq(x-X)+sq(y)+sq(z-Z) < sq(R2+2*th) && sq(x-X)+sq(y)+sq(z-Z) > sq(R2-2*th) && level < MAXLEVEL );
fraction(f, -sq(x-X) -sq(y) -sq(z-Z) +sq(R2+th/2) );
fraction(f1, -sq(x-X) -sq(y) -sq(z-Z) +sq(R2-th/2) );
// fraction(f,-sq(sq(R)-sqrt(sq((x-X)*cos(Theta*3.14/180)-(y-sqrt(sq(Y)-sq(x-X)))*sin(Theta*3.14/180) )+sq(z-L/2) ) ) -sq(A/B*((x-X)*sin(Theta*3.14/180)+(y-sqrt(sq(Y)-sq(x-X)))*cos(Theta*3.14/180)) ) + sq(A) );//torus inclined and curved about z -axis
// fraction(f,-sq(sq(R)-sqrt(sq(x-L/2)+sq(z-L/2) ) ) -sq(A/B*(y-sqrt(sq(R2)-sq(x-L/2)))) + sq(A) );//torus
// fraction(f,-sq(sq(R)-sqrt(sq(x-L/2)+sq(z-L/2) ) ) -sq(A/B*(y-sqrt(sq(R2)-sq((x-L/2)*cos(Theta*3.14/180)-(y-L/2)*sin(Theta*3.14/180) )))) + sq(A) );//torus
// fraction(f,-sq(sq(R)-sqrt(sq((x-L/2)*cos(Theta*3.14/180)-(y-L/2)*sin(Theta*3.14/180))+sq(z-L/2) ) ) -sq(A/B*(y-sqrt(sq(R2)-sq((x-L/2)*cos(Theta*3.14/180)-(y-L/2)*sin(Theta*3.14/180) )))) + sq(A) );//torus
// fraction(f,-sq(sq(R)-sqrt(sq((x-L/2)*cos(Theta*3.14/180)-(y-L/2)*sin(Theta*3.14/180))+sq(z-L/2) ) ) -sq(A/B*((x-L/2)*sin(Theta*3.14/180)+ (y-sqrt(sq(R2)-sq((x-L/2)*cos(Theta*3.14/180)-(y-L/2)*sin(Theta*3.14/180) )))*cos(Theta*3.14/180)) ) + sq(A) );//torus
// fraction(f,-sq(sq(R)-sqrt(sq((x-X)*cos(Theta*3.14/180)-(y-Y)*sin(Theta*3.14/180))+sq(z-Z) ) ) -sq(A/B*((x-X)*sin(Theta*3.14/180)+ (y-sqrt(sq(R2)-sq((x-X)*cos(Theta*3.14/180)-(y-Y)*sin(Theta*3.14/180) )))*cos(Theta*3.14/180)) ) + sq(A) );//torus
#endif
foreach(){
f[] = clamp(f[]-f1[],0.,1.);
}
fprintf(stdout,"theta = %g X = %g Y = %g Z =%g n1 = %g \n",Theta,X,Y,Z,n1);
}//end of restore
}//end of event init
event create_hole(t= t_hole){
#if _circle
// For circular rim , radius of the rim is not fixed and governed by the mass conservation. Which means rim radius also depends on the hole radius
// So it is convenient for us to calculate the hole diameter between the rim centers not the rim interface
R = n1*th;
//B denotes the radius of the rim
// B = (-2*R*th-sqrt(sq(2*R*th)-4*(th-2*3.24*R)*th*sq(R)) )/(2*th-4*3.14*R);
B = sqrt(R*th/(2*3.14));
#endif
#if _ellipse
// In elliptical rim, rim is highly flattened and we keep the major axis constant and let the mass conservation calculate the minor radius, Thus if the user wants to hole such that the
// distance between the hole center and the nearest peripheral interface is n1 times the thickness while the user also wants the major radius to be n2 times the thickness then we can disign
// the problem such that the distance btween rim center and hole center R = (n1+n2)*th which eventually leads us with a hole where distance between hole center and the peripheral interface
// is n1*th as we attempted.
//n2 = 1.2*n1;
R = (n1+n2)*th;
A = n2*th; //2.5*th;
B = (R*th)/(2*3.14*A); //from mass conservation
e = sqrt(1-sq(B/A));//eccentricity of the ellipse
printf("R = %0.5f A = %0.5f B = %0.5f e = %0.5f\n",R,A,B,e);
#endif
// Volume before hole formation
double vol_i = 0.;
foreach(reduction(+:vol_i)){
double dv = f[]*dv();
vol_i +=dv;
}
printf("time = %0.8f Volume = %0.8f\n",t,vol_i);
fflush(ferr);
//Make a hole and create a rim along the peripheri of the hole. Adjust the rim radius iteratively so that overall mass is conserved
int ite=0;
double vol0 = 0;
double vol1 = 0;
double B0 = 0;
double B1 = 0;;
while(1){
B0 = B;
printf("while loop begins\n");
// fraction(f3, -sq(R - sqrt(sq((x-X)*cos(Theta*3.14/180)-(y-Y)*sin(Theta*3.14/180) ) + sq(z-Z))) -sq((x-X)*sin(Theta*3.14/180) + (y-Y)*cos(Theta*3.14/180)) + sq(r));//inclined torus final
#if _ellipse
fraction(f2, -sq((x-X)*cos(Theta*3.14/180) - (y-Y)*sin(Theta*3.14/180) ) - sq(z-Z) + sq(R+A*0.75) );// inclined cylinder final
// fraction(f3, -sq(R-sqrt(sq((x-X)*cos(Theta*3.14/180)-(y-sqrt(sq(Y)-sq(x-X)))*sin(Theta*3.14/180) ) + sq(z-Z) ) ) - sq(A/B0*((x-X)*sin(Theta*3.14/180)+(y-sqrt(sq(R2)-sq(x-X)))*cos(Theta*3.14/180)) ) + sq(A) );//torus
fraction(f3, -sq(R-sqrt(sq((x-X)*cos(Theta*3.14/180)-(y-sqrt(sq(R2)-sq(x-X)))*sin(Theta*3.14/180) ) + sq(z-Z) ) ) - sq(A/B0*((x-X)*sin(Theta*3.14/180)+(y-sqrt(sq(R2)-sq(x-X)-sq(z-Z)))*cos(Theta*3.14/180)) ) + sq(A) );//torus
#endif
#if _circle
fraction(f2, -sq((x-X)*cos(Theta*3.14/180) - (y-Y)*sin(Theta*3.14/180) ) - sq(z-Z) + sq(R) );// inclined cylinder final
fraction(f3, -sq(R - sqrt(sq((x-X)*cos(Theta*3.14/180)-(y-Y)*sin(Theta*3.14/180) ) + sq(z-Z))) -sq((x-X)*sin(Theta*3.14/180) + (y-Y)*cos(Theta*3.14/180)) + sq(B0));//inclined circular torus final
#endif
foreach(){
f4[]=clamp(f[]-f2[],0.,1.);
f[]=clamp(f4[]+f3[],0.,1.);
}
printf("vof subtracted\n");
//Calculate the volume after adding rim
double vol = 0.;
foreach(reduction(+:vol)){
double dv = f[]*dv();
vol +=dv;
}
// printf("time = %0.8f Volume = %0.8f\n",t,vol2);
// fflush(ferr);
printf("ite= %2d vol =%0.8f vol2 = %0.8f B = %0.8f\n",ite,vol_i,vol,B);
if(ite == 0){
vol0 = vol;
//lets consider a second guess point B1
if(vol > vol_i){
B1 = B + 0.01*B;
}
if(vol < vol_i){
B1 = B - 0.01*B;
}
#if _ellipse
//fraction(f5, -sq(R - sqrt(sq((x-X)*cos(Theta*3.14/180)-(y-Y)*sin(Theta*3.14/180) ) + sq(z-Z))) -sq(A/B1 *((x-X)*sin(Theta*3.14/180) + (y-Y)*cos(Theta*3.14/180))) + sq(A));//inclined elliptic torus final
// fraction(f5, -sq(R -sqrt(sq((x-X)*cos(Theta*3.14/180)-(y-sqrt(sq(Y)-sq(x-X)))*sin(Theta*3.14/180) )+sq(z-Z) ) ) -sq(A/B1*((x-X)*sin(Theta*3.14/180)+(y-sqrt(sq(R2)-sq(x-X)))*cos(Theta*3.14/180)) ) + sq(A) );//torus with curvature in x direction only
fraction(f5, -sq(R -sqrt(sq((x-X)*cos(Theta*3.14/180)-(y-sqrt(sq(R2)-sq(x-X)))*sin(Theta*3.14/180) )+sq(z-Z) ) ) -sq(A/B1*((x-X)*sin(Theta*3.14/180)+(y-sqrt(sq(R2)-sq(x-X)-sq(z-Z)))*cos(Theta*3.14/180)) ) + sq(A) );//torus with curvature in both x and zdirections
#endif
#if _circle
fraction(f5, -sq(R - sqrt(sq((x-X)*cos(Theta*3.14/180)-(y-Y)*sin(Theta*3.14/180) ) + sq(z-Z))) -sq((x-X)*sin(Theta*3.14/180) + (y-Y)*cos(Theta*3.14/180)) + sq(B1));//inclined circular torus final
#endif
foreach(){
f4[]=clamp(f[]-f2[],0.,1.);
f[]=clamp(f4[]+f5[],0.,1.);
}
//Calculate the volume after adding rim
double vol1 = 0.;
foreach(reduction(+:vol1)){
double dv = f[]*dv();
vol1 +=dv;
}
printf("vol1 = %0.5f\n",vol1);
}else{
B0 = B1;
vol0 = vol1;
B1 = B;
vol1 = vol;
}
printf("vol1 = %0.5f\n",vol1);
B = B1 - ((vol1-vol_i)*(B1 - B0))/(vol1 - vol0);
if(fabs(vol_i-vol) < 0.0001*vol_i){
break;
}
//Increment and decrement in rim radius
ite=ite+1;
}//end of while
}//end event create_hole
scalar vml[];
#if _ellipse
char txt[5] = "erim";
#endif
#if _circle
char txt[5] = "crim";
#endif
event images(t+= t_out){
clear();
char name[80];
foreach(){
vml[] = f[]*sqrt(u.x[]*u.x[]+u.y[]*u.y[]);
}
clear();
view(fov = fov1, tx = -0.5 ,ty = 0.5, camera = "top", width = image_width, height = image_height);
box();
cells();
draw_vof("f");
// squares("f",min = 0, max = vmax);
sprintf(name,"vof_top_%s-%05.3f.ppm",txt,t);
save(name);
clear();
view(fov = fov1, tx = -0.5 ,ty = -0.5, camera = "front", width = image_width, height = image_height);
box();
// cells();
draw_vof("f");
// squares("f",min = 0, max = vmax);
sprintf(name,"vof_side_%s-%05.3f.ppm",txt,t);
save(name);
clear();
view(fov = fov1, tx = -0.1 ,ty = 0.3, camera = "iso", width = image_width, height = image_height);
box();
cells();
draw_vof("f");
// squares("f",min = 0, max = vmax);
sprintf(name,"vof_iso_%s-%05.3f.ppm",txt,t);
save(name);
}
event snapshot(t += t_out){
clear();
char name[80];
clear();
sprintf(name,"snapshot_%s-%05.3f.gfs",txt,t);
output_gfs(file=name, t=t, list = {f,u,p});
sprintf(name,"dump_%s-%05.3f",txt,t);
p.nodump = false;
dump(file = name);
}
/** Check volume conservation or mass conservation
*/
/**
Every ten timesteps, we output the time, volume, position, and
velocity of the bubble.*/
event logfile (i++) {
scalar posx[],posy[],posz[],Rxyz[],rxyz[];
position (f, posx, {1,0,0});
position (f, posy, {0,1,0});
position (f, posz, {0,0,1});
double xb = 0., yb = 0., zb = 0., sb = 0.;
double vbx = 0., vby = 0., vbz = 0., ke = 0.;
foreach(reduction(+:xb) reduction(+:yb) reduction(+:zb)
reduction(+:vbx) reduction(+:vby) reduction(+:vbz)
reduction(+:sb) reduction(+:ke)
) {
if( f[] <= 1e-6 || f[] >= 1. - 1e-6){
posx[] = nodata;
posy[] = nodata;
posz[] = nodata;
Rxyz[] = nodata;
rxyz[] = nodata;
}else{
Rxyz[]=sqrt(sq(posx[]-X)+sq(posy[]-X)+sq(posz[]-X));
rxyz[] = sqrt(sq(posy[]-Y)); //rim thickness or rim radius is the thickest part of the rim and essentially the sheet
}
double dv = f[]*dv();
//centroid
xb += x*dv;
yb += y*dv;
zb += z*dv;
//mean velocity
vbx += u.x[]*dv;
vby += u.y[]*dv;
vbz += u.z[]*dv;
//volume
sb += dv;
//kinetic energy
foreach_dimension(){
ke += dv*sq(u.x[]);
}
}
// scalar posx1[],posz1[];
/** double xpos = L/2;
double ypos = L/2;
double zpos = L/2;
double zmax,zmin;
foreach(){
if(x > xpos && x < xpos+Delta && y > ypos && y < ypos+Delta){
// if(y > sy.max-0.01*Delta && y < sy.max ){
if(f[] > 0.0001 && f[] < 0.9999){
if(z > zpos){
zmax = z;
}
if(z < zpos){
zmin = z;
}
posz[] = z; //for debugging
printf("%g\n",posz[]); // for debugging
}
}//end of if
}//end of foreach()
printf("zmax= %g zmin = %g\n",zmax,zmin);
stats sx = statsf (posx);
stats sy = statsf (posy);
stats sz = statsf (posz);
*/
stats R_val = statsf (Rxyz);
stats r_val = statsf (rxyz);
// fprintf(stdout, "%g %g\n", r_val.min, sy.max);
// Next section is for finding the hole radius from hole center to rim center as soon as the rim develops
/*
*/
double area = interface_area(f);
if(t == 0){
fprintf(ferr,"1:time 2:sb 3:xc 4:yc 5:zc 6:uc 7:vc 8: wc 9:KE 10:area 11:R 12:r\n");
}else if(t >= t_hole){
fprintf (ferr,
"%.6f %.6f %.6f %.6f %.6f %.6f %.6f %.6f %.6f %.6f %0.6f %0.6f\n",
t, sb, xb/sb, yb/sb, zb/sb,
vbx/sb, vby/sb, vbz/sb, ke/2., area, R_val.min, r_val.max);
fflush (ferr);
}
}//end of event logfile
// Declare the end of simulaiton
event end(t=t_end){
printf("i = %d, t = %g\n",i,t);
}
/**
event adapt(i++){
adapt_wavelet((scalar *){f,u}, (double[]){femax,uemax,uemax,uemax},minlevel = 3, maxlevel = MAXLEVEL);
}*/