-
Notifications
You must be signed in to change notification settings - Fork 0
/
kelvin-helmholtz.c
105 lines (71 loc) · 2.23 KB
/
kelvin-helmholtz.c
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
#include "navier-stokes/centered.h"
#include "two-phase.h" // Implements two-phase flow
#include "view.h" // Creating movies using bview
#include <omp.h> // For openMP parallel
/* Physical parameters */
double REYNOLDS = 5000.;
double RHO_R = 0.75;
double MU_R = 1;
int MINLEVEL = 6;
int MAXLEVEL = 11;
int BOX_WIDTH = 4;
int gfs_output_no = 0;
scalar omega[];
double END_TIME = 5;
/* Boundary conditions */
u.n[top] = neumann(0.); // Allows outflow through boundary
u.n[bottom] = neumann(0.); // Allows outflow through boundary
int main() {
/* Create the computational domain */
init_grid(1 << MINLEVEL); // Create grid according to the minimum level
size(BOX_WIDTH); // Size of the domain
origin(-BOX_WIDTH/2, -BOX_WIDTH/2);
periodic(right);
/* Set physical constants */
rho1 = 1.; // Density of the top phase
rho2 = RHO_R; // Density of the bottom phase
mu1 = 1. / REYNOLDS; // Viscosity of top phase
mu2 = mu1 * MU_R; // Viscosity of bottom phase
/* Run simulation */
run();
}
event init(t = 0) {
/* Define volume fraction along middle of box */
fraction(f, y - 0.001 * sin(100 * 2 * pi * x / BOX_WIDTH));
// fraction(f, y);
refine((y < 0.02) && (y > -0.02) && level < MAXLEVEL);
/* Initialise the velocities */
foreach() {
u.x[] = f[];
}
}
event adapt (i++) {
adapt_wavelet ({u,f}, (double[]){1e-3,1e-3,1e-4}, maxlevel = MAXLEVEL);
}
event logfile (i++) {
fprintf (stderr, "%d %g\n", i, t);
}
event gfs_output (t += 0.1) {
/* Saves a gfs file */
vorticity(u, omega);
char gfs_filename[80];
sprintf(gfs_filename, "gfs_output_%d.gfs", gfs_output_no);
output_gfs(file = gfs_filename);
gfs_output_no++;
}
event movies (t += 1e-1) {
char time_str[80];
sprintf(time_str, "t = %g\n", t);
/* Zoomed out view */
// Set up bview box
view (width = 1024, height = 1024, fov = 24.0);
/* Movie of the volume fraction of the droplet */
clear();
draw_vof("f", lw = 2);
squares("f", linear = true, spread = -1, map = cool_warm);
draw_string(time_str, pos=1, lc= { 0, 0, 0 }, lw=2);
save ("tracer.mp4");
}
event end(t = END_TIME) {
fprintf(stderr, "Done!\n");
}