Basilisk CFD
Adaptive Cartesian mesh PDE framework
Loading...
Searching...
No Matches
elevation.h
Go to the documentation of this file.
1/** @file elevation.h
2 */
3/**
4# Conservation of water surface elevation
5
6When using the default adaptive reconstruction of variables, the
7[Saint-Venant solver](saint-venant.h) or the [layered solver](hydro.h)
8will conserve the water depth when cells are refined or
9coarsened. However, this will not necessarily ensure that the
10"lake-at-rest" condition (i.e. a constant water surface elevation) is
11also preserved. In what follows, we redefine the *prolongation()* and
12*restriction()* methods of the water depth \f$h\f$ so that the water
13surface elevation \f$\eta\f$ is conserved.
14
15We start with the reconstruction of fine "wet" cells: */
16
17#if TREE
18static double default_sea_level = 0.;
19
21{
22 // reconstruction of fine cells using elevation (rather than water depth)
23 // (default refinement conserves mass but not lake-at-rest)
24 if (h[] >= dry) {
25 double eta = zb[] + h[]; // water surface elevation
26 coord g; // gradient of eta
27 if (gradient)
28 for (int _d = 0; _d < dimension; _d++)
29 g.x = gradient (zb[-1] + h[-1], eta, zb[1] + h[1])/4.;
30 else
31 for (int _d = 0; _d < dimension; _d++)
32 g.x = (zb[1] - zb[-1])/(2.*Delta);
33 // reconstruct water depth h from eta and zb
34 for (int _c = 0; _c < 4; _c++) /* foreach_child */ {
35 double etac = eta;
36 for (int _d = 0; _d < dimension; _d++)
37 etac += g.x*child.x;
38 h[] = max(0., etac - zb[]);
39 }
40 }
41 else {
42
43 /**
44 The "dry" case is a bit more complicated. We look in a 3x3
45 neighborhood of the coarse parent cell and compute a depth-weighted
46 average of the "wet" surface elevation \f$\eta\f$. We need to do this
47 because we cannot assume a priori that the surrounding wet cells are
48 necessarily close to e.g. \f$\eta = 0\f$. */
49
50 double v = 0., eta = 0.; // water surface elevation
51 // 3x3 neighbourhood
52 for (int _n = 0; _n < 1; _n++)
53 if (h[] >= dry) {
54 eta += h[]*(zb[] + h[]);
55 v += h[];
56 }
57 if (v > 0.)
58 eta /= v; // volume-averaged eta of neighbouring wet cells
59 else
60
61 /**
62 If none of the surrounding cells is wet, we set a default sealevel. */
63
65
66 /**
67 We then reconstruct the water depth in each child using \f$\eta\f$ (of the
68 parent cell i.e. a first-order interpolation in contrast to the wet
69 case above) and \f$z_b\f$ of the child cells. */
70
71 // reconstruct water depth h from eta and zb
72 for (int _c = 0; _c < 4; _c++) /* foreach_child */
73 h[] = max(0., eta - zb[]);
74 }
75}
76
77/**
78Cell restriction is simpler. We first compute the depth-weighted
79average of \f$\eta\f$ over all the children... */
80
82{
83 double eta = 0., v = 0.;
84 for (int _c = 0; _c < 4; _c++) /* foreach_child */
85 if (h[] > dry) {
86 eta += h[]*(zb[] + h[]);
87 v += h[];
88 }
89
90 /**
91 ... and use this in combination with \f$z_b\f$ (of the coarse cell) to
92 compute the water depth \f$h\f$. */
93
94 if (v > 0.)
95 h[] = max(0., eta/v - zb[]);
96 else // dry cell
97 h[] = 0.;
98}
99
100/**
101We also need to define a consistent prolongation function. For cells
102which are entirely surrounded by wet cells, we can use the standard
103linear refinement function, otherwise we use straight injection from
104the parent cell. */
105
107{
108 bool wet = true;
109 for (int _n = 0; _n < 1; _n++)
110 if (h[] <= dry) {
111 wet = false;
112 break;
113 }
114 if (wet)
116 else {
117 double hc = h[], zc = zb[];
118 for (int _c = 0; _c < 4; _c++) /* foreach_child */ {
119 h[] = hc;
120 zb[] = zc;
121 }
122 }
123}
124
125/**
126Finally we define a function which will be called by the user to apply
127these reconstructions. */
128
135#else // Cartesian
136void conserve_elevation (void) {}
137#endif
double(* gradient)(double, double, double)
Definition advection.h:31
vector g[]
We store the combined pressure gradient and acceleration field in g*.
Definition all-mach.h:65
scalar zb[]
Definition atmosphere.h:6
scalar h[]
Definition atmosphere.h:6
#define dimension
Definition bitree.h:3
int x
Definition common.h:76
Point point
Definition conserving.h:86
static void restriction_elevation(Point point, scalar h)
Cell restriction is simpler.
Definition elevation.h:81
static double default_sea_level
Definition elevation.h:18
void conserve_elevation(void)
Finally we define a function which will be called by the user to apply these reconstructions.
Definition elevation.h:129
static void prolongation_elevation(Point point, scalar h)
We also need to define a consistent prolongation function.
Definition elevation.h:106
static void refine_elevation(Point point, scalar h)
Definition elevation.h:20
double v[2]
Definition embed.h:383
double dry
Definition entrainment.h:30
scalar eta
Definition hydro.h:50
size_t max
Definition mtrace.h:8
static void refine_linear(Point point, scalar s)
void set_prolongation(scalar s, void(*prolongation)(Point, scalar))
void set_restriction(scalar s, void(*restriction)(Point, scalar))
Definition linear.h:21
Definition common.h:78
scalar x
Definition common.h:47