Basilisk CFD
Adaptive Cartesian mesh PDE framework
Loading...
Searching...
No Matches
spherisym.h
Go to the documentation of this file.
1/** @file spherisym.h
2 */
3/**
4# Spherically-symmetric coordinates
5
6This file defines the metric coefficients for a (one-dimensional)
7[spherically-symmetric](https://en.wikipedia.org/wiki/Circular_symmetry#Spherical_symmetry)
8coordinate system.
9
10The radial coordinate \f$r\f$ is *x*. Note that *x* (and so *X0*) cannot
11be negative.
12
13We first define a macro which will be used in some geometry-specific
14code (e.g. [viscous stress tensor](viscosity.h)). */
15
16#define SPHERISYM 1
17
18/**
19On trees we need refinement functions. */
20
21#if TREE
23{
24 fine(cm,0) = sq (x - Delta/4.);
25 fine(cm,1) = sq (x + Delta/4.);
26}
27
29{
30 if (!is_refined(neighbor(-1)))
31 fine(fm,0) = sq (x - Delta/2.);
32 if (!is_refined(neighbor(1)) && neighbor(1).neighbors)
33 fine(fm,2) = sq (x + Delta/2.);
34 fine(fm,1) = sq(x);
35}
36#endif // TREE
37
38/** @brief Event: metric (i = 0) */
39void event_metric (void) {
40
41 /**
42 By default *cm* is a constant scalar field. To make it variable, we
43 need to allocate a new field. We also move it at the begining of the
44 list of variables: this is important to ensure the metric is defined
45 before other fields. */
46
47 if (is_constant(cm)) {
48 scalar * l = list_copy (all);
49 cm = {0} /* new scalar */;
50 free (all);
51 all = list_concat ({cm}, l);
52 free (l);
53 }
54
55 /**
56 The volume/area of a cell is proportional to \f$r^2\f$ (i.e. \f$x^2\f$). We need
57 to set boundary conditions at the top and bottom so that *cm* is
58 interpolated properly when refining/coarsening the mesh. */
59
60 scalar cmv = cm;
61 for (int _i = 0; _i < _N; _i++) /* foreach */
62 cmv[] = x*x;
63 /* BC: cm[left] = dirichlet(x*x) */
64 /* BC: cm[right] = dirichlet(x*x) */
65
66 /**
67 We do the same for the length scale factors. The "length" of faces
68 on the center of spherical symmetry is zero (\f$x=r=0\f$ in the
69 center). To avoid division by zero we set it to epsilon (note that
70 mathematically the limit is well posed). */
71
72 if (is_constant(fm.x)) {
73 scalar * l = list_copy (all);
74 fm = {0} /* new vector */;
75 free (all);
76 all = list_concat ((scalar *){fm}, l);
77 free (l);
78 }
79 vector fmv = fm;
80 for (int _i = 0; _i < _N; _i++) /* foreach_face */
81 fmv.x[] = max(x*x, 1e-20);
82
83 /**
84 We set our refinement/prolongation functions on trees. */
85
86#if TREE
87 cm.refine = cm.prolongation = refine_cm_spherisym;
88 fm.x.prolongation = refine_face_x_spherisym;
89#endif
90}
define l
define neighbor(o, p, q)((Point)
Definition cartesian.h:146
free(list1)
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
static number sq(number x)
Definition common.h:11
scalar * list_copy(scalar *l)
Definition common.h:225
const vector fm[]
Definition common.h:396
Point point
Definition conserving.h:86
else fine(fs.x, 1, 0)
size_t max
Definition mtrace.h:8
static void refine_cm_spherisym(Point point, scalar cm)
On trees we need refinement functions.
Definition spherisym.h:22
static void refine_face_x_spherisym(Point point, scalar fm)
Definition spherisym.h:28
void event_metric(void)
Event: metric (i = 0)
Definition spherisym.h:39
def _i
Definition stencils.h:405
Definition linear.h:21
scalar x
Definition common.h:47
#define is_refined(cell)
Definition tree.h:410