Basilisk CFD
Adaptive Cartesian mesh PDE framework
Loading...
Searching...
No Matches
spherical.h
Go to the documentation of this file.
1/** @file spherical.h
2 */
3/**
4# Spherical coordinates
5
6The default radius of the sphere is set to one. */
7
8double Radius = 1.;
9
10/**
11Rather than the classical [mathematical
12convention](http://en.wikipedia.org/wiki/Spherical_coordinate_system),
13we use the geographic convention: *x* is the longitude within
14\f$[-180:180]\f$ degrees and *y* is the latitude within \f$[-90:90]\f$
15degrees. \f$\Delta\f$ is the characteristic cell length expressed in the
16same units as *Radius*. */
17
18macro VARIABLES (Point point = point, int _ig = ig, int _jg = jg, int _kg = kg)
19{
21 x = x < -180. ? x + 360. : x > 180. ? x - 360. : x;
23 Delta *= Radius*pi/180.;
24}
25
26/**
27On trees we need to define consistent refinement functions. The
28default restriction functions (averages) are already consistent
29(i.e. they preserve volume and length integrals).
30
31Mathematically we have
32\f[
33cm = fm.y = \cos(\phi)
34\f]
35\f[
36fm.x = 1
37\f]
38with \f$\phi\f$ the latitude in radians. This is the definition we use for
39the length scale factors *fm*.
40
41For the volume scale factor *cm*, more care needs to be taken to
42guarantee discrete volume conservation i.e.
43\f[
44\sum_{children}cm_{child} = 4cm_{parent}
45\f]
46This is achieved by computing the exact area of a cell i.e.
47\f[
48\Delta^2 \int^{\phi + d\phi/2}_{\phi - d \phi/2} \cos\phi d\phi =
49\Delta^2 (\sin(\phi + d\phi/2) - \sin(\phi - d\phi/2)) = \Delta^2 cm
50\f]
51*/
52
53#if TREE
55{
56 double phi = y*pi/180., dphi = Delta/(2.*Radius);
57 double sinphi = sin(phi);
58 fine(cm,0,0) = fine(cm,1,0) = (sinphi - sin(phi - dphi))/dphi;
59 fine(cm,0,1) = fine(cm,1,1) = (sin(phi + dphi) - sinphi)/dphi;
60}
61
63{
64 if (!is_refined(neighbor(-1)))
65 fine(fm,0,0) = fine(fm,0,1) = 1.;
66 if (!is_refined(neighbor(1)) && neighbor(1).neighbors)
67 fine(fm,2,0) = fine(fm,2,1) = 1.;
68 fine(fm,1,0) = fine(fm,1,1) = 1.;
69}
70
72{
73 double phi = y*pi/180., dphi = Delta/(2.*Radius);
74 if (!is_refined(neighbor(0,-1)))
75 fine(fm,0,0) = fine(fm,1,0) = cos(phi - dphi);
76 if (!is_refined(neighbor(0,1)) && neighbor(0,1).neighbors)
77 fine(fm,0,2) = fine(fm,1,2) = cos(phi + dphi);
78 fine(fm,0,1) = fine(fm,1,1) = cos(phi);
79}
80#endif
81
82/** @brief Event: metric (i = 0) */
83void event_metric (void) {
84
85 /**
86 We initialise the scale factors, taking care to first allocate the
87 fields if they are still constant. */
88
89 if (is_constant(cm)) {
90 scalar * l = list_copy (all);
91 cm = {0} /* new scalar */;
92 free (all);
93 all = list_concat ({cm}, l);
94 free (l);
95 }
96 scalar cmv = cm;
97 for (int _i = 0; _i < _N; _i++) /* foreach */ {
98 double phi = y*pi/180., dphi = Delta/(2.*Radius);
99 cmv[] = (sin(phi + dphi) - sin(phi - dphi))/(2.*dphi);
100 }
101
102 if (is_constant(fm.x)) {
103 scalar * l = list_copy (all);
104 fm = {0} /* new vector */;
105 free (all);
106 all = list_concat ((scalar *){fm}, l);
107 free (l);
108 }
109 vector fmv = fm;
110 for (int _i = 0; _i < _N; _i++) /* foreach_face */
111 fmv.x[] = 1.;
112 for (int _i = 0; _i < _N; _i++) /* foreach_face */
113 fmv.y[] = cos(y*pi/180.);
114
115 /**
116 We set our refinement/prolongation functions on trees. */
117
118#if TREE
119 cm.refine = cm.prolongation = refine_cm_lonlat;
120 fm.x.prolongation = refine_face_x_lonlat;
121 fm.y.prolongation = refine_face_y_lonlat;
122#endif
123}
define l
static int _ig[]
Definition cartesian1D.h:64
define neighbor(o, p, q)((Point)
Definition cartesian.h:146
def is_boundary() _jg[]
Definition cartesian.h:152
free(list1)
int y
Definition common.h:76
int x
Definition common.h:76
#define pi
Definition common.h:4
scalar * all
Definition common.h:342
const scalar cm[]
Definition common.h:397
scalar * list_concat(scalar *l1, scalar *l2)
Definition common.h:234
scalar * list_copy(scalar *l)
Definition common.h:225
const vector fm[]
Definition common.h:396
Point point
Definition conserving.h:86
scalar phi[]
The electric potential and the volume charge density are scalars while the permittivity and conductiv...
Definition implicit.h:34
else fine(fs.x, 1, 0)
macro
We also redefine the "per field" (inner) traversal.
Definition layers.h:18
macro VARIABLES(Point point=point, int _ig=ig, int _jg=jg, int _kg=kg)
Rather than the classical mathematical convention, we use the geographic convention: x is the longitu...
Definition spherical.h:18
static void refine_face_y_lonlat(Point point, scalar fm)
Definition spherical.h:71
static void refine_cm_lonlat(Point point, scalar cm)
On trees we need to define consistent refinement functions.
Definition spherical.h:54
static void refine_face_x_lonlat(Point point, scalar fm)
Definition spherical.h:62
double Radius
Definition spherical.h:8
void event_metric(void)
Event: metric (i = 0)
Definition spherical.h:83
def _i
Definition stencils.h:405
Definition linear.h:21
scalar x
Definition common.h:47
scalar y
Definition common.h:49
#define is_refined(cell)
Definition tree.h:410