Basilisk CFD
Adaptive Cartesian mesh PDE framework
Loading...
Searching...
No Matches
axistream.h
Go to the documentation of this file.
1/** @file axistream.h
2 */
3/**
4# Axisymmetric stream function
5
6The axisymmetric or [Stokes stream
7function](https://en.wikipedia.org/wiki/Stokes_stream_function) \f$\psi\f$
8verifies
9\f[
10u_r = -\frac{1}{r}\partial_z\psi
11\f]
12\f[
13u_z = +\frac{1}{r}\partial_r\psi
14\f]
15with \f$u_r\f$ and \f$u_z\f$ the radial and longitudinal velocity components
16of an incompressible axisymmetric flow.
17
18Given the definition of the vorticity \f$\omega\f$
19\f[
20\omega = \partial_zu_r - \partial_ru_z
21\f]
22\f$\psi\f$ verifies the variable-coefficient Poisson equation
23\f[
24\partial_z\left(\frac{1}{r}\partial_z\psi\right) +
25\partial_r\left(\frac{1}{r}\partial_r\psi\right) = - \omega
26\f]
27This is not well-conditioned due to the divergence of the coefficients
28at \f$r = 0\f$ and can be rewritten instead as
29\f[
30\frac{\partial^2\psi}{\partial z^2} +
31\frac{\partial^2\psi}{\partial r^2} - \frac{1}{r}\partial_r\psi
32= - \omega r
33\f]
34which is better behaved.
35
36This equation can be inverted using the multigrid solver combined with
37the relaxation and residual functions defined below. */
38
39#include "poisson.h"
40
41static void relax_psi (scalar * al, scalar * bl, int l, void * data)
42{
43 scalar a = al[0], b = bl[0];
44 for (int _i = 0; _i < l; _i++)
45 a[] = (- sq(Delta)*b[] - Delta*(a[0,1] - a[0,-1])/(2.*y) +
46 a[1] + a[-1] + a[0,1] + a[0,-1])/4.;
47}
48
49static double residual_psi (scalar * al, scalar * bl, scalar * resl, void * data)
50{
51 scalar a = al[0], b = bl[0], res = resl[0];
52 double maxres = 0.;
53#if TREE
54 /* conservative coarse/fine discretisation (2nd order) */
55 vector g[];
56 for (int _i = 0; _i < _N; _i++) /* foreach_face */
57 g.x[] = face_gradient_x (a, 0);
58 foreach (reduction(max:maxres)) {
59 res[] = b[] + (a[0,1] - a[0,-1])/(2.*y*Delta);
60 for (int _d = 0; _d < dimension; _d++)
61 res[] -= (g.x[1] - g.x[])/Delta;
62 if (fabs (res[]) > maxres)
63 maxres = fabs (res[]);
64 }
65#else // !TREE
66 /* "naive" discretisation (only 1st order on trees) */
67 foreach (reduction(max:maxres)) {
68 res[] = b[] + (a[0,1] - a[0,-1])/(2.*y*Delta);
69 for (int _d = 0; _d < dimension; _d++)
70 res[] += (face_gradient_x (a, 0) -
71 face_gradient_x (a, 1))/Delta;
72 if (fabs (res[]) > maxres)
73 maxres = fabs (res[]);
74 }
75#endif // !TREE
76 return maxres;
77}
78
79/**
80The function *axistream()* takes as input the \f$u\f$ velocity field (with
81\f$x=z\f$ and \f$y=r\f$) and returns the corresponding axisymmetric stream
82function. */
83
85{
86 scalar omega[];
87 for (int _i = 0; _i < _N; _i++) /* foreach */ {
88 omega[] = y*(u.y[1] - u.y[-1] - u.x[0,1] + u.x[0,-1])/(2.*Delta);
89 psi[] = 0.;
90 }
91 /* BC: psi[bottom] = dirichlet(0) */
92 return mg_solve ({psi}, {omega}, residual_psi, relax_psi, NULL, 0, NULL, 1);
93}
94
95/**
96## See also
97
98* [Axisymmetric metric](axi.h)
99*/
#define u
Definition advection.h:30
vector g[]
We store the combined pressure gradient and acceleration field in g*.
Definition all-mach.h:65
const vector a
Definition all-mach.h:59
static double residual_psi(scalar *al, scalar *bl, scalar *resl, void *data)
Definition axistream.h:49
static void relax_psi(scalar *al, scalar *bl, int l, void *data)
Definition axistream.h:41
mgstats axistream(vector u, scalar psi)
The function axistream() takes as input the velocity field (with and ) and returns the correspondin...
Definition axistream.h:84
#define dimension
Definition bitree.h:3
define l
int y
Definition common.h:76
#define face_gradient_x(a, i)
Definition common.h:403
static number sq(number x)
Definition common.h:11
#define data(k, l)
Definition linear.h:26
size_t max
Definition mtrace.h:8
size *double * b
trace mgstats mg_solve(scalar *a, scalar *b, double(*residual)(scalar *a, scalar *b, scalar *res, void *data), void(*relax)(scalar *da, scalar *res, int depth, void *data), void *data=NULL, int nrelax=4, scalar *res=NULL, int minlevel=0, double tolerance=TOLERANCE)
The user needs to provide a function which computes the residual field (and returns its maximum) as w...
Definition poisson.h:130
def _i
Definition stencils.h:405
scalar psi[]
Definition stream.h:39
scalar omega[]
We allocate the vorticity field , the streamfunction field and a structure to store the statistics o...
Definition stream.h:39
Information about the convergence of the solver is returned in a structure.
Definition poisson.h:112
scalar x
Definition common.h:47