Basilisk CFD
Adaptive Cartesian mesh PDE framework
Loading...
Searching...
No Matches
cartesian1D.h
Go to the documentation of this file.
1/** @file cartesian1D.h
2 */
3typedef double real;
4
5#define GRIDNAME "Cartesian 1D"
6#define dimension 1
7#define GHOSTS 1
8
9#define _I (point.i - 1)
10#define _DELTA (1./point.n)
11
12typedef struct {
13 Grid g;
14 char * d;
15 int n;
16} Cartesian;
17
18struct _Point {
19 int i, j, level, n;
20};
22
23#define cartesian ((Cartesian *)grid)
24
25@define data(k,l,m) ((double *)&cartesian->d[(point.i + k)*datasize])
26@define allocated(...) true
27
29
30macro2 foreach (char flags = 0, Reduce reductions = None)
31{
33 int ig = 0, jg = 0; NOT_UNUSED(ig); NOT_UNUSED(jg);
35 point.n = cartesian->n;
36 int _k;
37 OMP(omp for schedule(static))
38 for (_k = 1; _k <= point.n; _k++) {
39 point.i = _k;
40 {...}
41 }
42 }
43}
44
46 const char * order = "xyz")
47{
49 int ig = 0, jg = 0; NOT_UNUSED(ig); NOT_UNUSED(jg);
51 point.n = cartesian->n;
52 int _k;
53 OMP(omp for schedule(static))
54 for (_k = 1; _k <= point.n + 1; _k++) {
55 point.i = _k;
56 {...}
57 }
58 }
59}
60
61macro1 is_face_x() {{ int ig = -1; NOT_UNUSED(ig); {...} }}
62
63// ghost cell coordinates for each direction
64static int _ig[] = {1,-1};
65
66// Box boundaries
67
68static void box_boundary_level_normal (const Boundary * b, scalar * list, int l)
69{
70 if (!list)
71 return;
72
73 int d = ((BoxBoundary *)b)->d;
74
76 point.n = cartesian->n;
77 int ig = _ig[d];
78 assert (d <= left);
79 point.i = d == right ? point.n + GHOSTS : GHOSTS;
80 Point neighbor = {point.i + ig};
81 for (int _s = 0; _s < 1; _s++) /* scalar in list */ {
82 scalar b = s.v.x;
83 val(s,ig) = b.boundary[d] (point, neighbor, s, NULL);
84 }
85}
86
87static double periodic_bc (Point point, Point neighbor, scalar s, bool * data);
88
89static void box_boundary_level (const Boundary * b, scalar * list, int l)
90{
91 int d = ((BoxBoundary *)b)->d;
93
94 int component = d/2;
95 for (int _s = 0; _s < 1; _s++) /* scalar in list */
96 if (!is_constant(s) && s.boundary[d] != periodic_bc) {
97 if (s.face) {
98 if ((&s.d.x)[component]) {
99 scalar b = s.v.x;
100 if (b.boundary[d])
101 normal = list_add (normal, s);
102 }
103 }
104 else if (s.boundary[d])
106 }
107
108 if (centered) {
109 Point point;
110 point.n = cartesian->n;
111 int ig = _ig[d];
112 point.i = d == right ? point.n + GHOSTS - 1 : GHOSTS;
113 Point neighbor = {point.i + ig};
114 for (int _s = 0; _s < 1; _s++) /* scalar in centered */
115 val(s,ig) = s.boundary[d] (point, neighbor, s, NULL);
116 free (centered);
117 }
118
120 free (normal);
121}
122
123// periodic boundaries
124
125static void periodic_boundary_level_x (const Boundary * b, scalar * list, int l)
126{
127 scalar * list1 = NULL;
128 for (int _s = 0; _s < 1; _s++) /* scalar in list */
129 if (!is_constant(s) && s.boundary[right] == periodic_bc)
130 list1 = list_add (list1, s);
131 if (!list1)
132 return;
133
134 Point point = *((Point *)grid);
135 point.i = 0, point.n = N;
136 for (int i = 0; i < GHOSTS; i++)
137 for (int _s = 0; _s < 1; _s++) /* scalar in list1 */
138 s[i] = s[i + point.n];
139 for (int i = point.n + GHOSTS; i < point.n + 2*GHOSTS; i++)
140 for (int _s = 0; _s < 1; _s++) /* scalar in list1 */
141 s[i] = s[i - point.n];
142
143 free (list1);
144}
145
146void free_grid (void)
147{
148 if (!grid)
149 return;
151 free (cartesian->d);
152 free (cartesian);
153 grid = NULL;
154}
155
156@if TRASH
157@ undef trash
159@endif
160
161void reset (void * alist, double val)
162{
163 scalar * list = (scalar *) alist;
164 char * data = cartesian->d;
165 for (int i = 0; i < cartesian->n + 2; i++, data += datasize) {
166 double * v = (double *) data;
167 for (int _s = 0; _s < 1; _s++) /* scalar in list */
168 if (!is_constant(s))
169 v[s.i] = val;
170 }
171}
172
173void init_grid (int n)
174{
175 if (cartesian && n == cartesian->n)
176 return;
177 free_grid();
178 Cartesian * p = qmalloc (1, Cartesian);
179 size_t len = (n + 2)*datasize;
180 p->n = N = n;
181 p->d = qmalloc (len, char);
182 /* trash the data just to make sure it's either explicitly
183 initialised or never touched */
184 double * v = (double *) p->d;
185 for (int i = 0; i < len/sizeof(double); i++)
186 v[i] = undefined;
187 grid = (Grid *) p;
188 reset (all, 0.);
189 // box boundaries
190 for (int d = 0; d < 2; d++) {
192 box->d = d;
193 Boundary * b = (Boundary *) box;
195 add_boundary (b);
196 }
197 // periodic boundaries
198 Boundary * b = qcalloc (1, Boundary);
200 add_boundary (b);
201 // mesh size
202 grid->n = grid->tn = n;
203}
204
206{
208 size_t len = (p->n + 2);
209 qrealloc (p->d, len*(datasize + size), char);
210 char * data = p->d + (len - 1)*datasize;
211 for (int i = p->n + 1; i > 0; i--, data -= datasize)
213 datasize += size;
214}
215
216Point locate (double xp = 0, double yp = 0, double zp = 0)
217{
218 Point point;
219 point.n = cartesian->n;
220 double a = (xp - X0)/L0*point.n;
221 point.i = a + 1;
222 point.level = (a > -0.5 && a < point.n + 0.5) ? 0 : - 1;
223 return point;
224}
225
226#include "variables.h"
227#include "cartesian-common.h"
228
229macro2 for (int _i = 0; _i < _N; _i++) /* foreach_vertex */
230{
232 int ig = -1; NOT_UNUSED(ig);
233 {...}
234 }
235}
236
vector g[]
We store the combined pressure gradient and acceleration field in g*.
Definition all-mach.h:65
const vector a
Definition all-mach.h:59
if TRASH define &&NewPid *& val(newpid, 0, 0, 0)) -> pid > 0) @else @ define is_newpid()(((NewPid *)&val(newpid, 0, 0, 0)) ->pid > 0) @endif Array *linear_tree(size_t size, scalar newpid)
Definition balance.h:13
void add_boundary(Boundary *b)
Definition boundaries.h:16
void free_boundaries()
Definition boundaries.h:27
define k
define double double char flags
void cartesian_methods()
define l
define double double char Reduce reductions
define m((k)==0 &&(l)==0 &&(m)==0) macro2 foreach_point(double _x=0.
Point locate(double xp=0, double yp=0, double zp=0)
static int _ig[]
Definition cartesian1D.h:64
double real
Definition cartesian1D.h:3
if TRASH undef trash define trash(list) reset(list
macro2 foreach_face_generic(char flags=0, Reduce reductions=None, const char *order="xyz")
Definition cartesian1D.h:45
void cartesian1D_methods()
static Point last_point
Definition cartesian1D.h:21
#define GHOSTS
Definition cartesian1D.h:7
static void box_boundary_level(const Boundary *b, scalar *list, int l)
Definition cartesian1D.h:89
static double periodic_bc(Point point, Point neighbor, scalar s, bool *data)
static void periodic_boundary_level_x(const Boundary *b, scalar *list, int l)
static void box_boundary_level_normal(const Boundary *b, scalar *list, int l)
Definition cartesian1D.h:68
macro1 is_face_x()
Definition cartesian1D.h:61
void free_grid(void)
#define cartesian
Definition cartesian1D.h:23
define neighbor(o, p, q)((Point)
Definition cartesian.h:146
free(list1)
define VT _attribute[s.i] v y scalar * list
Definition cartesian.h:276
OMP_PARALLEL()
Definition cartesian.h:292
#define define
int x
Definition common.h:76
scalar * all
Definition common.h:342
scalar * list_add(scalar *list, scalar s)
Definition common.h:208
double L0
Definition common.h:36
int N
Definition common.h:39
Grid * grid
Definition common.h:32
double X0
Definition common.h:34
@ left
Definition common.h:123
@ right
Definition common.h:123
size_t datasize
Definition common.h:132
#define p
Definition tree.h:320
else define undefined((double) DBL_MAX) @ define enable_fpe(flags) @ define disable_fpe(flags) static void set_fpe(void)
Definition config.h:615
#define qcalloc(size, type)
#define qmalloc(size, type)
#define assert(a)
Definition config.h:107
Point point
Definition conserving.h:86
else return n
Definition curvature.h:101
trace bool box(bool notics=false, float lc[3]={0}, float lw=1.)
Definition draw.h:1397
scalar s
Definition embed-tree.h:56
double v[2]
Definition embed.h:383
double d[2]
Definition embed.h:383
scalar int i
Definition embed.h:74
#define realloc_scalar(size)
Definition gpu.h:480
#define reset(...)
Definition grid.h:1388
#define init_grid(n)
Definition grid.h:1402
macro
We also redefine the "per field" (inner) traversal.
Definition layers.h:18
#define data(k, l)
Definition linear.h:26
size_t size
size *double * b
def _i
Definition stencils.h:405
def _k
Definition stencils.h:405
Definition common.h:26
long n
Definition common.h:27
long tn
Definition common.h:28
Definition linear.h:21
int level
Definition linear.h:23
int i
Definition linear.h:23
void(* level)(const Boundary *b, scalar *list, int l)
Definition boundaries.h:9
int j
Definition cartesian.h:26
int n
Definition cartesian.h:26
int level
Definition cartesian.h:26
int i
Definition cartesian.h:26
int i
Definition common.h:44
def allocated(k, l, n)(mem_allocated(((Tree *) grid) -> L[point.level]->m, point.i+k, point.j+l)) @ @def NEIGHBOR(k, l, n)(((((Tree *) grid) ->L[point.level]->m) ->b[point.i+k][point.j+l])) @ @def PARENT(k, l, n)(((((Tree *) grid) ->L[point.level-1]->m) ->b[(point.i+2)/2+k][(point.j+2)/2+l])) @ @def allocated_child(k, l, n)(level< depth() &&mem_allocated(((Tree *) grid) ->L[point.level+1]->m, 2 *point.i- 2+k, 2 *point.j- 2+l)) @ @def CHILD(k, l, n)(((((Tree *) grid) ->L[point.level+1]->m) ->b[2 *point.i- 2+k][2 *point.j- 2+l])) @ @define CELL(m)(*((Cell *)(m))) @define depth()(grid->depth) @define aparent(k, l, n) CELL(PARENT(k, l, n)) @define child(k, l, n) CELL(CHILD(k, l, n)) @define cell CELL(NEIGHBOR(0, 0, 0)) @define neighbor(k, l, n) CELL(NEIGHBOR(k, l, n)) @def neighborp(l, m, n)(Point)
Definition tree.h:253
define n n define n n macro POINT_VARIABLES(Point point=point)
Definition tree.h:322
macro VARIABLES(Point point=point, int _ig=ig, int _jg=jg, int _kg=kg)
Definition variables.h:3
Array * normal