Basilisk CFD
Adaptive Cartesian mesh PDE framework
Loading...
Searching...
No Matches
conserving.h
Go to the documentation of this file.
1/** @file conserving.h
2 */
3/**
4# Momentum-conserving advection of velocity
5
6This file implements momentum-conserving VOF advection of the velocity
7components for the [two-phase](/src/two-phase.h) Navier--Stokes
8solver.
9
10On trees, we first define refinement and restriction functions which
11guarantee conservation of each component of the total momentum. Note
12that these functions do not guarantee conservation of momentum for
13each phase. */
14
15#if TREE
18 double rhou = 0.;
19 for (int _c = 0; _c < 4; _c++) /* foreach_child */
20 rhou += cm[]*rho(f[])*u[];
21 double du = u[] - rhou/((1 << dimension)*(cm[] + SEPS)*rho(f[]));
22 for (int _c = 0; _c < 4; _c++) /* foreach_child */
23 u[] += du;
24}
25
27{
28 double rhou = 0.;
29 for (int _c = 0; _c < 4; _c++) /* foreach_child */
30 rhou += cm[]*rho(f[])*u[];
31 u[] = rhou/((1 << dimension)*(cm[] + SEPS)*rho(f[]));
32}
33#endif // TREE
34
35/**
36We switch-off the default advection scheme of the [centered
37solver](centered.h). */
38
39/** @brief Event: defaults (i = 0) */
40void event_defaults (void)
41{
42 stokes = true;
43
44#if TREE
45
46 /**
47 On trees, the refinement and restriction functions above rely on the
48 volume fraction field *f* being refined/restricted before the
49 components of velocity. To ensure this, we move *f* to the front of
50 the field list (*all*). */
51
52 int i = 0;
53 while (all[i].i != f.i) i++;
54 while (i > 0 && all[i].i)
55 all[i] = all[i-1], i--;
56 all[i] = f;
57
58 /**
59 We then set the refinement and restriction functions for the
60 components of the velocity field. The boundary conditions on
61 \f$\mathbf{u}\f$ now depend on those on \f$f\f$. */
62
63 for (int _d = 0; _d < dimension; _d++) {
64 u.x.refine = u.x.prolongation = momentum_refine;
65 u.x.restriction = momentum_restriction;
66 u.x.depends = list_add (u.x.depends, f);
67 }
68#endif
69}
70
71/**
72We need to overload the stability event so that the CFL is taken into
73account (because we set stokes to true). */
74
75/** @brief Event: stability (i++) */
76void event_stability (void)
78
79/**
80We will transport the two components of the momentum, \f$q_1=f \rho_1
81\mathbf{u}\f$ and \f$q_2=(1 - f) \rho_2 \mathbf{u}\f$. We will need to
82impose boundary conditions which match this definition. This is done
83using the functions below. */
84
85for (int _d = 0; _d < dimension; _d++)
87{
88 return clamp(f[],0.,1.)*rho1*u.x[];
89}
90
91for (int _d = 0; _d < dimension; _d++)
93{
94 return (1. - clamp(f[],0.,1.))*rho2*u.x[];
95}
96
97/**
98Similarly, on trees we need prolongation functions which also follow
99this definition. */
100
101#if TREE
102for (int _d = 0; _d < dimension; _d++)
103static void prolongation_q1_x (Point point, scalar q1) {
104 for (int _c = 0; _c < 4; _c++) /* foreach_child */
105 q1[] = clamp(f[],0.,1.)*rho1*u.x[];
106}
107
108for (int _d = 0; _d < dimension; _d++)
109static void prolongation_q2_x (Point point, scalar q2) {
110 for (int _c = 0; _c < 4; _c++) /* foreach_child */
111 q2[] = (1. - clamp(f[],0.,1.))*rho2*u.x[];
112}
113#endif
114
115/**
116We overload the *vof()* event to transport consistently the volume
117fraction and the momentum of each phase. */
118
120
121/** @brief Event: vof (i++) */
122void event_vof (void) {
123
124 /**
125 We allocate two temporary vector fields to store the two components
126 of the momentum and set the boundary conditions and prolongation
127 functions. The boundary conditions on \f$q_1\f$ and \f$q_2\f$ depend on the
128 boundary conditions on \f$f\f$. */
129
130 vector q1[], q2[];
131 for (int _s = 0; _s < 1; _s++) /* scalar in {q1,q2} */ {
132 s.depends = list_add (s.depends, f);
133 for (int _d = 0; _d < dimension; _d++)
134 s.v.x.i = -1; // not a vector
135 }
136 for (int i = 0; i < nboundary; i++)
137 for (int _d = 0; _d < dimension; _d++) {
138 q1.x.boundary[i] = boundary_q1_x;
139 q2.x.boundary[i] = boundary_q2_x;
140 }
141#if TREE
142 for (int _d = 0; _d < dimension; _d++) {
143 q1.x.prolongation = prolongation_q1_x;
144 q2.x.prolongation = prolongation_q2_x;
145 }
146#endif
147
148 /**
149 We split the total momentum \f$q\f$ into its two components \f$q1\f$ and
150 \f$q2\f$ associated with \f$f\f$ and \f$1 - f\f$ respectively. */
151
152 for (int _i = 0; _i < _N; _i++) /* foreach */
153 for (int _d = 0; _d < dimension; _d++) {
154 double fc = clamp(f[],0,1);
155 q1.x[] = fc*rho1*u.x[];
156 q2.x[] = (1. - fc)*rho2*u.x[];
157 }
158
159 /**
160 Momentum \f$q2\f$ is associated with \f$1 - f\f$, so we set the *inverse*
161 attribute to *true*. We use the same slope-limiting as for the
162 velocity field. */
163
164 for (int _d = 0; _d < dimension; _d++) {
165 q2.x.inverse = true;
166 q1.x.gradient = q2.x.gradient = u.x.gradient;
167 }
168
169 /**
170 We associate the transport of \f$q1\f$ and \f$q2\f$ with \f$f\f$ and transport
171 all fields consistently using the VOF scheme. */
172
173 scalar * tracers = f.tracers;
174 f.tracers = list_concat (tracers, (scalar *){q1, q2});
175 vof_advection ({f}, i);
176 free (f.tracers);
177 f.tracers = tracers;
178
179 /**
180 We recover the advected velocity field using the total momentum and
181 the density */
182
183 for (int _i = 0; _i < _N; _i++) /* foreach */
184 for (int _d = 0; _d < dimension; _d++)
185 u.x[] = (q1.x[] + q2.x[])/rho(f[]);
186
187 /**
188 We set the list of interfaces to NULL so that the default *vof()*
189 event does nothing (otherwise we would transport \f$f\f$ twice). */
190
192}
193
194/**
195We set the list of interfaces back to its default value. */
196
197/** @brief Event: tracer_advection (i++) */
#define u
Definition advection.h:30
vector uf[]
We allocate the (face) velocity field.
Definition advection.h:29
scalar * tracers
Here we set the gradient functions for each tracer (as defined in the user-provided tracers list).
Definition hydro.h:60
double dtmax
The timestep is computed using the CFL condition on the face velocity field.
Definition all-mach.h:105
trace double timestep(void)
Definition atmosphere.h:37
#define dimension
Definition bitree.h:3
define neighbor(o, p, q)((Point)
Definition cartesian.h:146
free(list1)
bool stokes
Definition centered.h:75
int x
Definition common.h:76
scalar * all
Definition common.h:342
const scalar cm[]
Definition common.h:397
scalar * list_concat(scalar *l1, scalar *l2)
Definition common.h:234
scalar * list_add(scalar *list, scalar s)
Definition common.h:208
static number clamp(number x, number a, number b)
Definition common.h:15
int nboundary
Definition common.h:127
#define SEPS
Definition common.h:402
scalar f[]
The primary fields are:
Definition two-phase.h:56
scalar * interfaces
The height functions are stored in the vector field associated with each VOF tracer.
Definition two-phase.h:56
static scalar * interfaces1
We overload the vof() event to transport consistently the volume fraction and the momentum of each ph...
Definition conserving.h:119
Point scalar bool * data
Definition conserving.h:87
static void momentum_refine(Point point, scalar u)
Definition conserving.h:16
void event_vof(void)
Event: vof (i++)
Definition conserving.h:122
void event_defaults(void)
We switch-off the default advection scheme of the centered solver.
Definition conserving.h:40
Point scalar q2
Definition conserving.h:92
void event_tracer_advection(void)
We set the list of interfaces back to its default value.
Definition conserving.h:198
Point scalar q1
Definition conserving.h:86
void event_stability(void) dtmax
We need to overload the stability event so that the CFL is taken into account (because we set stokes ...
Definition all-mach.h:110
Point point
Definition conserving.h:86
static void momentum_restriction(Point point, scalar u)
Definition conserving.h:26
scalar s
Definition embed-tree.h:56
scalar int i
Definition embed.h:74
double rho2
Definition momentum.h:15
#define rho(f)
The density and viscosity are defined using arithmetic averages by default.
Definition momentum.h:45
double rho1
Definition momentum.h:15
static void refine_bilinear(Point point, scalar s)
def _i
Definition stencils.h:405
Definition linear.h:21
int i
Definition common.h:44
void vof_advection(scalar *interfaces, int i)
Definition vof.h:330