Basilisk CFD
Adaptive Cartesian mesh PDE framework
Loading...
Searching...
No Matches
remap.h
Go to the documentation of this file.
1/** @file remap.h
2 */
3/**
4# Vertical remapping
5
6This implements a simple vertical remapping to "\f$\sigma\f$-coordinates"
7(equally-distributed by default).
8
9We can optionally use the [PPR
10Library](https://github.com/dengwirda/PPR) of Engwirda and Kelley to
11perform the remapping. The default settings are using the Parabolic
12Piecewise Method without limiting.
13
14By default we use the [C PPR implementation](remapc.h) without
15limiting. */
16
17#if USE_PPR
18# include "ppr/ppr.h"
19// int edge_meth = p1e_method, cell_meth = plm_method, cell_lim = null_limit;
21// int edge_meth = p5e_method, cell_meth = pqm_method, cell_lim = null_limit;
22#else // !USE_PPR
23# include "remapc.h"
24const bool null_limit = false, mono_limit = true;
25#endif
27
28/**
29The distribution of layers can be controlled using the *beta* array
30which defines the ratio of the thickness of each layer to the total
31depth \f$H\f$ (i.e. the relative thickness). By default all layers have
32the same relative thickness. */
33
34double * beta = NULL;
35
36/** @brief Event: defaults (i = 0) */
37void event_defaults (void)
38{
39 beta = malloc (nl*sizeof(double));
40 for (int l = 0; l < nl; l++)
41 beta[l] = 1./nl;
42}
43
44/**
45The default uniform layer distribution can be replaced with a
46geometric progression for the layer thicknesses. This needs to be
47called for example in the `init()` event. The `rmin` parameter
48specifies the minimum layer thickness relative to the uniform layer
49thickness (proportional to `1/nl`). If the `top` parameter is set to
50`true` the minimum layer thickness is at the top (layer `nl - 1`),
51otherwise it is at the bottom (layer 0). */
52
53void geometric_beta (double rmin, bool top)
54{
55 if (rmin <= 0. || rmin >= 1. || nl < 2)
56 return;
57 double r = 1. + 2.*(1./rmin - 1.)/(nl - 1.);
58 double hmin = (r - 1.)/(pow(r, nl) - 1.);
59 for (int l = 0; l < nl; l++)
60 beta[l] = hmin*pow(r, top ? nl - 1 - l : l);
61}
62
63/**
64The *vertical_remapping()* function takes a (block) field of layer
65thicknesses and the corresponding list of tracer fields and performs
66the remapping (defined by *beta*). */
67
70{
71 const int npos = nl + 1, nvar = list_len(tracers);
72#if USE_PPR
73 int ndof = 1;
74#endif
75 for (int _i = 0; _i < _N; _i++) /* foreach */ {
76#if HALF
77 double H0 = 0., H1 = 0., H;
79 if (point.l < nl/2)
80 H0 += h[];
81 else
82 H1 += h[];
83 }
84 H = H0 + H1;
85#else
86 double H = 0.;
88 H += h[];
89#endif
90
91 if (H > dry) {
92 double zpos[npos], znew[npos];
93#if USE_PPR
94 double fdat[nvar*nl], fnew[nvar*nl];
95 zpos[0] = znew[0] = 0.;
97 zpos[point.l+1] = zpos[point.l] + max(h[],dry);
98 int i = nvar*point.l;
99 for (int _s = 0; _s < 1; _s++) /* scalar in tracers */ {
100 /* dim: fnew[i] = s[] */;
101 fdat[i++] = s[];
102 }
103#if HALF
104 if (point.l < nl/2)
105 h[] = 2.*H0*beta[point.l];
106 else
107 h[] = 2.*H1*beta[point.l];
108#else
109 h[] = H*beta[point.l];
110#endif
111 znew[point.l+1] = znew[point.l] + h[];
112 }
113
116
117 foreach_layer() {
118 int i = nvar*point.l;
119 for (int _s = 0; _s < 1; _s++) /* scalar in tracers */
120 s[] = fnew[i++];
121 }
122#else // !USE_PPR
123 zpos[0] = znew[0] = 0.;
124 foreach_layer() {
125 zpos[point.l+1] = zpos[point.l] + max(h[],dry);
126#if HALF
127 if (point.l < nl/2)
128 h[] = 2.*H0*beta[point.l];
129 else
130 h[] = 2.*H1*beta[point.l];
131#else
132 h[] = H*beta[point.l];
133#endif
134 znew[point.l+1] = znew[point.l] + h[];
135 }
136 znew[npos -1] = zpos[npos - 1];
137
138 double fdat[nl][nvar], fnew[nl][nvar];
139 int v = 0;
140 for (int _s = 0; _s < 1; _s++) /* scalar in tracers */ {
141 foreach_layer() {
142 /* dim: fnew[point.l][v] = s[] */;
143 fdat[point.l][v] = s[];
144 }
145 v++;
146 }
147
148 /**
149 For the moment we simply use Neumann zero top and bottom
150 boundary conditions for all fields. Note that we also ignore the
151 corresponding dimensions since this could be inconsistent when
152 remapping quantities with different dimensions. */
153
155 0[*], HUGE[*], 0[*],
156 0[*], HUGE[*], 0[*],
157 cell_lim);
158
159 v = 0;
160 for (int _s = 0; _s < 1; _s++) /* scalar in tracers */ {
162 s[] = fnew[point.l][v];
163 v++;
164 }
165#endif // !USE_PPR
166 }
167 }
168}
169
170/**
171The remapping is applied at every timestep. */
172
173/** @brief Event: remap (i++) */
174void event_remap (void) {
175 if (nl > 1)
177}
178
179/**
180The *beta* array is freed at the end of the run. */
181
182/** @brief Event: cleanup (i = end) */
183void event_cleanup (void)
184{
185 free (beta), beta = NULL;
186}
scalar * tracers
Here we set the gradient functions for each tracer (as defined in the user-provided tracers list).
Definition hydro.h:60
scalar h[]
Definition atmosphere.h:6
define l
free(list1)
int x
Definition common.h:76
#define HUGE
Definition common.h:6
int list_len(scalar *list)
Definition common.h:180
@ top
Definition common.h:123
Point point
Definition conserving.h:86
return hxx pow(1.+sq(hx), 3/2.)
scalar s
Definition embed-tree.h:56
double v[2]
Definition embed.h:383
scalar int i
Definition embed.h:74
double dry
Definition entrainment.h:30
double * hmin
int nl
Definition layers.h:9
#define foreach_layer()
size_t max
Definition mtrace.h:8
void geometric_beta(double rmin, bool top)
The default uniform layer distribution can be replaced with a geometric progression for the layer thi...
Definition remap.h:53
double * beta
The distribution of layers can be controlled using the beta array which defines the ratio of the thic...
Definition remap.h:34
int cell_lim
Definition remap.h:26
void event_cleanup(void)
The beta array is freed at the end of the run.
Definition remap.h:183
void event_defaults(void)
Event: defaults (i = 0)
Definition remap.h:37
const bool mono_limit
Definition remap.h:24
trace void vertical_remapping(scalar h, scalar *tracers)
The vertical_remapping() function takes a (block) field of layer thicknesses and the corresponding li...
Definition remap.h:69
const bool null_limit
Definition remap.h:24
void event_remap(void)
The remapping is applied at every timestep.
Definition remap.h:174
void remap_c(int npos, int nnew, const double xpos[npos], const double xnew[nnew], const int nvar, double fdat[npos-1][nvar], double fnew[nnew-1][nvar], double f_b, double lambda_b, double df_b, double f_t, double lambda_t, double df_t, bool limiter)
Definition remapc.h:340
def _i
Definition stencils.h:405