Basilisk CFD
Adaptive Cartesian mesh PDE framework
Loading...
Searching...
No Matches
momentum.h
Go to the documentation of this file.
1/** @file momentum.h
2 */
3/**
4# Momentum-conserving formulation for two-phase interfacial flows
5
6The interface between the fluids is tracked with a Volume-Of-Fluid
7method. The volume fraction in fluid 1 is \f$f=1\f$ and \f$f=0\f$ in fluid
82. The densities and dynamic viscosities for fluid 1 and 2 are *rho1*,
9*mu1*, *rho2*, *mu2*, respectively. */
10
11#include "all-mach.h"
12#include "vof.h"
13
15double rho1 = 1., mu1 = 0., rho2 = 1., mu2 = 0.;
16
17/**
18Auxilliary fields are necessary to define the (variable) specific
19volume \f$\alpha=1/\rho\f$ and average viscosity \f$\mu\f$ (on faces) as well
20as the cell-centered density. */
21
24
25/** @brief Event: defaults (i = 0) */
26void event_defaults (void) {
27 alpha = alphav;
28 rho = rhov;
29 mu = muv;
30
31 /**
32 We use (strict) minmod slope limiting for all components. */
33
34 theta = 1.;
35 for (int _d = 0; _d < dimension; _d++)
36 q.x.gradient = minmod2;
37}
38
39/**
40The density and viscosity are defined using arithmetic averages by
41default. The user can overload these definitions to use other types of
42averages (i.e. harmonic). */
43
44#ifndef rho
45# define rho(f) (clamp(f,0,1)*(rho1 - rho2) + rho2)
46#endif
47#ifndef mu
48# define mu(f) (clamp(f,0,1)*(mu1 - mu2) + mu2)
49#endif
50
51/** @brief Event: properties (i++) */
52void event_properties (void) {
53 for (int _i = 0; _i < _N; _i++) /* foreach */
54 rhov[] = rho(f[])*cm[];
55 for (int _i = 0; _i < _N; _i++) /* foreach_face */ {
56 double ff = (f[] + f[-1])/2.;
57 alphav.x[] = fm.x[]/rho(ff);
58 muv.x[] = fm.x[]*mu(ff);
59 }
60}
61
62/**
63We overload the *vof()* event to transport consistently the volume
64fraction and the momentum of each phase. */
65
67
68/** @brief Event: vof (i++) */
69void event_vof (void) {
70
71 /**
72 We split the total momentum \f$q\f$ into its two components \f$q1\f$ and
73 \f$q2\f$ associated with \f$f\f$ and \f$1 - f\f$ respectively. */
74
75 vector q1 = q, q2[];
76 for (int _i = 0; _i < _N; _i++) /* foreach */
77 for (int _d = 0; _d < dimension; _d++) {
78 double u = q.x[]/rho(f[]);
79 q1.x[] = f[]*rho1*u;
80 q2.x[] = (1. - f[])*rho2*u;
81 }
82
83 /**
84 Momentum \f$q2\f$ is associated with \f$1 - f\f$, so we set the *inverse*
85 attribute to *true*. We use the same limiting for q1 and q2. */
86
87 for (int _d = 0; _d < dimension; _d++) {
88 q2.x.inverse = true;
89 q2.x.gradient = q1.x.gradient;
90 }
91
92#if TREE
93 /**
94 The refinement function is modified by *vof_advection()*. To be able
95 to restore it, we store its value. */
96
97 void (* refine) (Point, scalar) = q1.x.refine;
98#endif
99
100 /**
101 We associate the transport of \f$q1\f$ and \f$q2\f$ with \f$f\f$ and transport
102 all fields consistently using the VOF scheme. */
103
104 scalar * tracers = f.tracers;
105 f.tracers = list_concat (tracers, (scalar *){q1, q2});
106 vof_advection ({f}, i);
107 free (f.tracers);
108 f.tracers = tracers;
109
110 /**
111 We recover the total momentum. */
112
113 for (int _i = 0; _i < _N; _i++) /* foreach */
114 for (int _d = 0; _d < dimension; _d++)
115 q.x[] = q1.x[] + q2.x[];
116
117#if TREE
118 /**
119 We restore the refinement function for the total momentum. */
120
121 for (int _s = 0; _s < 1; _s++) /* scalar in {q} */ {
122 s.refine = refine;
124 }
125#endif // TREE
126
127 /**
128 We set the list of interfaces to NULL so that the default *vof()*
129 event does nothing (otherwise we would transport \f$f\f$ twice). */
130
132}
133
134/**
135We set the list of interfaces back to its default value. */
136
137/** @brief Event: tracer_advection (i++) */
141
142/**
143## See also
144
145* [Two-phase interfacial flows](two-phase.h)
146*/
double q2
Definition NASG.h:20
double q1
Definition NASG.h:20
#define u
Definition advection.h:30
scalar * tracers
Here we set the gradient functions for each tracer (as defined in the user-provided tracers list).
Definition hydro.h:60
vector q[]
The primitive variables are the momentum , pressure , density , (face) specific volume ,...
Definition all-mach.h:44
const vector alpha
Definition all-mach.h:47
#define dimension
Definition bitree.h:3
free(list1)
int x
Definition common.h:76
const scalar cm[]
Definition common.h:397
scalar * list_concat(scalar *l1, scalar *l2)
Definition common.h:234
const vector fm[]
Definition common.h:396
scalar s
Definition embed-tree.h:56
scalar int i
Definition embed.h:74
static scalar * interfaces1
We overload the vof() event to transport consistently the volume fraction and the momentum of each ph...
Definition momentum.h:66
double rho2
Definition momentum.h:15
#define rho(f)
The density and viscosity are defined using arithmetic averages by default.
Definition momentum.h:45
void event_vof(void)
Event: vof (i++)
Definition momentum.h:69
#define mu(f)
Definition momentum.h:48
scalar f[]
Definition momentum.h:14
vector muv[]
Definition momentum.h:22
double mu1
Definition momentum.h:15
scalar * interfaces
The height functions are stored in the vector field associated with each VOF tracer.
Definition momentum.h:14
void event_defaults(void)
Event: defaults (i = 0)
Definition momentum.h:26
double rho1
Definition momentum.h:15
double mu2
Definition momentum.h:15
void event_properties(void)
Event: properties (i++)
Definition momentum.h:52
void event_tracer_advection(void)
We set the list of interfaces back to its default value.
Definition momentum.h:138
scalar rhov[]
Definition momentum.h:23
vector alphav[]
Auxilliary fields are necessary to define the (variable) specific volume and average viscosity (on ...
Definition momentum.h:22
void set_prolongation(scalar s, void(*prolongation)(Point, scalar))
def _i
Definition stencils.h:405
Definition linear.h:21
scalar x
Definition common.h:47
macro refine(bool cond)
double theta
This is the generalised minmod limiter.
Definition utils.h:223
double minmod2(double s0, double s1, double s2)
Definition utils.h:225
void vof_advection(scalar *interfaces, int i)
Definition vof.h:330