Basilisk CFD
Adaptive Cartesian mesh PDE framework
Loading...
Searching...
No Matches
axi.h
Go to the documentation of this file.
1/** @file axi.h
2 */
3/**
4# Axisymmetric coordinates
5
6For problems with a symmetry of revolution around the \f$z\f$-axis of a
7[cylindrical coordinate
8system](http://en.wikipedia.org/wiki/Cylindrical_coordinate_system). The
9longitudinal coordinate (\f$z\f$-axis) is *x* and the radial coordinate
10(\f$\rho\f$- or \f$r\f$-axis) is *y*. Note that *y* (and so *Y0*) cannot be
11negative.
12
13We first define a macro which will be used in some geometry-specific
14code (e.g. [curvature computation](curvature.h)). */
15
16#define AXI 1
17
18/**
19On trees we need refinement functions. */
20
21#if TREE
23{
24#if !EMBED
25 fine(cm,0,0) = fine(cm,1,0) = y - Delta/4.;
26 fine(cm,0,1) = fine(cm,1,1) = y + Delta/4.;
27#else // EMBED
28 if (cs[] > 0. && cs[] < 1.) {
30 // Better? involve fs (troubles w prolongation)
31 // coord n = facet_normal (point, cs, fs);
32 for (int _c = 0; _c < 4; _c++) /* foreach_child */ {
33 if (cs[] > 0. && cs[] < 1.) {
34 coord p;
35 double alpha = plane_alpha (cs[], n);
36 plane_center (n, alpha, cs[], &p);
37 cm[] = (y + Delta*p.y)*cs[];
38 }
39 else
40 cm[] = y*cs[];
41 }
42 }
43 else
44 for (int _c = 0; _c < 4; _c++) /* foreach_child */
45 cm[] = y*cs[];
46#endif // EMBED
47}
48
50{
51#if !EMBED
52 if (!is_refined(neighbor(-1))) {
53 fine(fm,0,0) = y - Delta/4.;
54 fine(fm,0,1) = y + Delta/4.;
55 }
56 if (!is_refined(neighbor(1)) && neighbor(1).neighbors) {
57 fine(fm,2,0) = y - Delta/4.;
58 fine(fm,2,1) = y + Delta/4.;
59 }
60 fine(fm,1,0) = y - Delta/4.;
61 fine(fm,1,1) = y + Delta/4.;
62#else // EMBED
63 double sig = 0., ff = 0.;
64 if (cs[] > 0. && cs[] < 1.) {
66 sig = sign(n.y)*Delta/4.;
67 }
68 if (!is_refined(neighbor(-1))) {
69 ff = fine(fs.x,0,0);
70 fine(fm,0,0) = (y - Delta/4. - sig*(1. - ff))*ff;
71 ff = fine(fs.x,0,1);
72 fine(fm,0,1) = (y + Delta/4. - sig*(1. - ff))*ff;
73 }
74 if (!is_refined(neighbor(1)) && neighbor(1).neighbors) {
75 ff = fine(fs.x,2,0);
76 fine(fm,2,0) = (y - Delta/4. - sig*(1. - ff))*ff;
77 ff = fine(fs.x,2,1);
78 fine(fm,2,1) = (y + Delta/4. - sig*(1. - ff))*ff;
79 }
80 ff = fine(fs.x,1,0);
81 fine(fm,1,0) = (y - Delta/4. - sig*(1. - ff))*ff;
82 ff = fine(fs.x,1,1);
83 fine(fm,1,1) = (y + Delta/4. - sig*(1. - ff))*ff;
84#endif // EMBED
85}
86
88{
89#if !EMBED
90 if (!is_refined(neighbor(0,-1)))
91 fine(fm,0,0) = fine(fm,1,0) = max(y - Delta/2., 1e-20);
92 if (!is_refined(neighbor(0,1)) && neighbor(0,1).neighbors)
93 fine(fm,0,2) = fine(fm,1,2) = y + Delta/2.;
94 fine(fm,0,1) = fine(fm,1,1) = y;
95#else // EMBED
96 if (!is_refined(neighbor(0,-1))) {
97 fine(fm,0,0) = (max(y - Delta/2., 1e-20))*fine(fs.y,0,0) ;
98 fine(fm,1,0) = (max(y - Delta/2., 1e-20))*fine(fs.y,1,0);
99 }
100 if (!is_refined(neighbor(0,1)) && neighbor(0,1).neighbors) {
101 fine(fm,0,2) = (y + Delta/2.)*fine(fs.y,0,2);
102 fine(fm,1,2) = (y + Delta/2.)*fine(fs.y,1,2);
103 }
104 fine(fm,0,1) = y*fine(fs.y,0,1);
105 fine(fm,1,1) = y*fine(fs.y,1,1);
106#endif // EMBED
107}
108#endif
109
110/**
111If embedded solids are presents, *cm*, *fm* and the fluxes need to be
112updated consistently with the axisymmetric cylindrical coordinates and
113the solid fractions. */
114
115#if EMBED
116double axi_factor (Point point, coord p) {
117 return (y + p.y*Delta);
118}
119
120void cm_update (scalar cm, scalar cs, vector fs)
121{
122 for (int _i = 0; _i < _N; _i++) /* foreach */ {
123 if (cs[] > 0. && cs[] < 1.) {
124 coord p, n = facet_normal (point, cs, fs);
125 double alpha = plane_alpha (cs[], n);
126 plane_center (n, alpha, cs[], &p);
127 cm[] = (y + Delta*p.y)*cs[];
128 }
129 else
130 cm[] = y*cs[];
131 }
132 /* BC: cm[top] = dirichlet(y*cs[]) */
133 /* BC: cm[bottom] = dirichlet(y*cs[]) */
134}
135
136void fm_update (vector fm, scalar cs, vector fs)
137{
138 for (int _i = 0; _i < _N; _i++) /* foreach_face */ {
139 double sig = 0.;
140 if (cs[] > 0. && cs[] < 1.) {
142 sig = sign(n.y)*Delta/2.;
143 }
144 fm.x[] = (y - sig*(1. - fs.x[]))*fs.x[];
145 }
146 for (int _i = 0; _i < _N; _i++) /* foreach_face */
147 fm.y[] = max(y, 1e-20)*fs.y[];
148 fm.t[top] = dirichlet(y*fs.t[]);
149 fm.t[bottom] = dirichlet(y*fs.t[]);
150}
151#endif // EMBED
152
153/** @brief Event: metric (i = 0) */
154void event_metric (void) {
155
156 /**
157 By default *cm* is a constant scalar field. To make it variable, we
158 need to allocate a new field. We also move it at the begining of the
159 list of variables: this is important to ensure the metric is defined
160 before other fields. */
161
162 if (is_constant(cm)) {
163 scalar * l = list_copy (all);
164 cm = {0} /* new scalar */;
165 free (all);
166 all = list_concat ({cm}, l);
167 free (l);
168 }
169
170 /**
171 Metric factors must be taken into account for fluxes on embedded
172 boundaries. */
173
174#if EMBED
175 metric_embed_factor = axi_factor;
176#endif
177
178 /**
179 The volume/area of a cell is proportional to \f$r\f$ (i.e. \f$y\f$). We need
180 to set boundary conditions at the top and bottom so that *cm* is
181 interpolated properly when refining/coarsening the mesh. */
182
183 scalar cmv = cm;
184 for (int _i = 0; _i < _N; _i++) /* foreach */
185 cmv[] = y;
186 /* BC: cm[top] = dirichlet(y) */
187 /* BC: cm[bottom] = dirichlet(y) */
188
189 /**
190 We do the same for the length scale factors. The "length" of faces
191 on the axis of revolution is zero (\f$y=r=0\f$ on the axis). To avoid
192 division by zero we set it to epsilon (note that mathematically the
193 limit is well posed). */
194
195 if (is_constant(fm.x)) {
196 scalar * l = list_copy (all);
197 fm = {0} /* new vector */;
198 free (all);
199 all = list_concat ((scalar *){fm}, l);
200 free (l);
201 }
202 vector fmv = fm;
203 for (int _i = 0; _i < _N; _i++) /* foreach_face */
204 fmv.x[] = max(y, 1./HUGE);
205 fm.t[top] = dirichlet(y);
206 fm.t[bottom] = dirichlet(y);
207
208 /**
209 We set our refinement/prolongation functions on trees. */
210
211#if TREE
212 cm.refine = cm.prolongation = refine_cm_axi;
213 fm.x.prolongation = refine_face_x_axi;
214 fm.y.prolongation = refine_face_y_axi;
215#endif
216}
217
218/**
219## See also
220
221* [Axisymmetric streamfunction](axistream.h)
222*/
const vector alpha
Definition all-mach.h:47
static void refine_face_x_axi(Point point, scalar fm)
Definition axi.h:49
static void refine_cm_axi(Point point, scalar cm)
On trees we need refinement functions.
Definition axi.h:22
void event_metric(void)
If embedded solids are presents, cm, fm and the fluxes need to be updated consistently with the axisy...
Definition axi.h:154
static void refine_face_y_axi(Point point, scalar fm)
Definition axi.h:87
define l
define neighbor(o, p, q)((Point)
Definition cartesian.h:146
free(list1)
int y
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
#define HUGE
Definition common.h:6
scalar * list_copy(scalar *l)
Definition common.h:225
static int sign(number x)
Definition common.h:13
@ top
Definition common.h:123
@ bottom
Definition common.h:123
const vector fm[]
Definition common.h:396
#define p
Definition tree.h:320
Point point
Definition conserving.h:86
static coord interface_normal(Point point, scalar c)
Definition contact.h:29
else return n
Definition curvature.h:101
else fine(fs.x, 1, 0)
scalar cs[]
The volume and area fractions are stored in these fields.
Definition embed.h:21
vector fs[]
Definition embed.h:22
double(* metric_embed_factor)(Point, coord)
Definition embed.h:24
macro2 double dirichlet(double expr, Point point=point, scalar s=_s, bool *data=data)
For ease of use, we replace the Neumann and Dirichlet functions with macros so that they can be used ...
Definition embed.h:717
coord facet_normal(Point point, scalar c, vector s)
Definition fractions.h:426
#define plane_center(m, alpha, a, p)
This function fills the coordinates p of the centroid of the fraction a of a cubic cell lying under t...
Definition geometry.h:564
#define plane_alpha
Definition geometry.h:133
size_t max
Definition mtrace.h:8
def _i
Definition stencils.h:405
Definition linear.h:21
Definition common.h:78
scalar x
Definition common.h:47
scalar y
Definition common.h:49
#define is_refined(cell)
Definition tree.h:410