Basilisk CFD
Adaptive Cartesian mesh PDE framework
Loading...
Searching...
No Matches
bcg.h
Go to the documentation of this file.
1/** @file bcg.h
2 */
3/**
4# Bell-Collela-Glaz advection scheme
5
6The function below implements the 2nd-order, unsplit, upwind scheme of
7[Bell-Collela-Glaz, 1989](references.bib#bell89). Given a centered
8scalar field *f*, a vector field *uf* (possibly weighted by a
9face metric), a timestep *dt* and a source term field *src*, it fills
10the vector field *flux* with the components of the advection
11fluxes of *f*. */
12
13trace
15 vector uf,
17 double dt,
18 const scalar src)
19{
20
21 /**
22 We first compute the cell-centered gradient of *f* in a locally-allocated
23 vector field. */
24
25 vector g[];
26 gradients ({f}, {g});
27
28 /**
29 For each face, the flux is composed of two parts... */
30
31 for (int _i = 0; _i < _N; _i++) /* foreach_face */ {
32
33 /**
34 A normal component... (Note that we cheat a bit here, `un` should
35 strictly be `dt*(uf.x[i] + uf.x[i+1])/((fm.x[] +
36 fm.x[i+1])*Delta)` but this causes trouble with boundary
37 conditions (when using narrow '1 ghost cell' stencils)). */
38
39 double un = dt*uf.x[]/(fm.x[]*Delta + SEPS), s = sign(un);
40 int i = -(s + 1.)/2.;
41 double f2 = f[i] + (src[] + src[-1])*dt/4. + s*(1. - s*un)*g.x[i]*Delta/2.;
42
43 /**
44 and tangential components... */
45
46 #if dimension > 1
47 if (fm.y[i] && fm.y[i,1]) {
48 double vn = (uf.y[i] + uf.y[i,1])/(fm.y[i] + fm.y[i,1]);
49 double fyy = vn < 0. ? f[i,1] - f[i] : f[i] - f[i,-1];
50 f2 -= dt*vn*fyy/(2.*Delta);
51 }
52 #endif
53 #if dimension > 2
54 if (fm.z[i] && fm.z[i,0,1]) {
55 double wn = (uf.z[i] + uf.z[i,0,1])/(fm.z[i] + fm.z[i,0,1]);
56 double fzz = wn < 0. ? f[i,0,1] - f[i] : f[i] - f[i,0,-1];
57 f2 -= dt*wn*fzz/(2.*Delta);
58 }
59 #endif
60
61 flux.x[] = f2*uf.x[];
62 }
63}
64
65/**
66The function below uses the *tracer_fluxes* function to integrate the
67advection equation, using an explicit scheme with timestep *dt*, for
68each tracer in the list. */
69
70trace
71void advection (scalar * tracers, vector u, double dt,
72 scalar * src = NULL)
73{
74
75 /**
76 If *src* is not provided we set all the source terms to zero. */
77
78 scalar * psrc = src;
79 if (!src)
80 for (int _s = 0; _s < 1; _s++) /* scalar in tracers */ {
81 const scalar zero[] = 0.;
82 src = list_append (src, zero);
83 }
84 assert (list_len (tracers) == list_len (src));
85
87 for (f,source in tracers,src) {
88 vector flux[];
90#if !EMBED
91 for (int _i = 0; _i < _N; _i++) /* foreach */
92 for (int _d = 0; _d < dimension; _d++)
93 f[] += dt*(flux.x[] - flux.x[1])/(Delta*cm[]);
94#else // EMBED
95 update_tracer (f, u, flux, dt);
96#endif // EMBED
97 }
98
99 if (!psrc)
100 free (src);
101}
#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
vector g[]
We store the combined pressure gradient and acceleration field in g*.
Definition all-mach.h:65
vector un[]
Definition atmosphere.h:5
trace void advection(scalar *tracers, vector u, double dt, scalar *src=NULL)
The function below uses the tracer_fluxes function to integrate the advection equation,...
Definition bcg.h:71
trace void tracer_fluxes(scalar f, vector uf, vector flux, double dt, const scalar src)
Definition bcg.h:14
#define dimension
Definition bitree.h:3
free(list1)
double zero(double s0, double s1, double s2)
Definition common.h:116
const scalar cm[]
Definition common.h:397
int list_len(scalar *list)
Definition common.h:180
static int sign(number x)
Definition common.h:13
scalar * list_append(scalar *list, scalar s)
Definition common.h:188
const vector fm[]
Definition common.h:396
#define SEPS
Definition common.h:402
scalar f[]
The primary fields are:
Definition two-phase.h:56
#define assert(a)
Definition config.h:107
double dt
scalar s
Definition embed-tree.h:56
scalar int i
Definition embed.h:74
trace void update_tracer(scalar f, vector uf, vector flux, double dt)
Definition embed.h:803
int source
Definition qcc.c:67
def _i
Definition stencils.h:405
scalar x
Definition common.h:47
scalar y
Definition common.h:49
void gradients(scalar *f, vector *g)
Given a list of scalar fields f, this function fills the gradient fields g with the corresponding gra...
Definition utils.h:247
scalar flux[]
Definition vof.h:166