forked from TJFord/iblb2d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboundary.cpp
290 lines (266 loc) · 6.95 KB
/
boundary.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# include <iostream>
# include <fstream>
# include <iomanip>
# include <string>
# include "boundary.h"
static const int oppositeOf[9] = { 0, 3, 4, 1, 2, 7, 8, 5, 6 };
void bounceBack(double* f, void* selfData)
{
bbData *data = (bbData*)selfData;
double fTmp[9];
int id,st,size;
int iPop;
size = data->size;
for(int i=0;i<size;i++){
id = data->node[i];
st = id*9;
for (iPop=0; iPop<9; ++iPop){
fTmp[iPop] = f[st + oppositeOf[iPop]];
}
for (iPop=0; iPop<9; ++iPop){
f[st + iPop] = fTmp[iPop];
}
}
}
inline static double leftRho(double* f, int id, double ux) {
int st = id*9;
return 1./(1.-ux) * (
f[st] + f[st+2] + f[st+4] + 2*(f[st+3]+f[st+6]+f[st+7])
);
}
inline static double rightRho(double* f, int id, double ux) {
int st = id*9;
return 1./(1.+ux) * (
f[st] + f[st+2] + f[st+4] + 2*(f[st+1]+f[st+5]+f[st+8])
);
}
inline static double upperRho(double* f, int id, double uy) {
int st = id*9;
return 1./(1.+uy) * (
f[st] + f[st+3] + f[st+1] + 2*(f[st+6]+f[st+2]+f[st+5])
);
}
/* Compute density on wall from bulk information on
lower boundary. */
inline static double lowerRho(double* f, int id, double uy) {
int st = id*9;
return 1./(1.-uy) * (
f[st] + f[st+3] + f[st+1] + 2*(f[st+8]+f[st+4]+f[st+7])
);
}
inline static void completeLeft(double* f,int id,
double ux, double uy, double rho)
{
int st = id*9;
f[st+5] = f[st+7] + 0.5 *(f[st+4]-f[st+2])
+ rho*ux/6. + rho*uy/2.;
f[st+8] = f[st+6] + 0.5 *(f[st+2]-f[st+4])
+ rho*ux/6. - rho*uy/2.;
f[st+1] = f[st+3] + 2./3.*rho*ux;
}
inline static void completeRight(double* f,int id,
double ux, double uy, double rho)
{
int st = id*9;
f[st+6] = f[st+8] + 0.5 *(f[st+4]-f[st+2])
- rho*ux/6 + rho*uy/2.;
f[st+7] = f[st+5] + 0.5 *(f[st+2]-f[st+4])
- rho*ux/6 - rho*uy/2.;
f[st+3] = f[st+1] - 2./3.*rho*ux;
}
inline static void completeUpper(double* f,int id,
double ux, double uy, double rho)
{
int st = id*9;
f[st+7] = f[st+5] + 0.5 * (f[st+1]-f[st+3])
- rho*uy/6 - rho*ux/2.;
f[st+8] = f[st+6] + 0.5 *(f[st+3]-f[st+1])
- rho*uy/6 + rho*ux/2.;
f[st+4] = f[st+2] - 2./3.*rho*uy;
}
inline static void completeLower(double* f, int id,
double ux, double uy, double rho)
{
int st = id*9;
f[st+6] = f[st+8] + 0.5 *(f[st+1]-f[st+3])
+ rho*uy/6 - rho*ux/2.;
f[st+5] = f[st+7] + 0.5 *(f[st+3]-f[st+1])
+ rho*uy/6 + rho*ux/2.;
f[st+2] = f[st+4] + 2./3.*rho*uy;
}
// ZouHe velocity boundaries on upper, lower, left and right
// boundaries
void leftZouHe(double* f, void* selfData) {
velData* data = (velData*) selfData;
double rho;
int id,size;
double ux,uy;
size = data->size;
for (int i=0;i<size;i++){
id = data->node[i];
ux = data->ux[i];
uy = data->uy[i];
rho = leftRho(f,id,ux);
completeLeft(f,id,ux,uy,rho);
}
}
// right zou he velocity boundary
void rightZouHe(double* f, void* selfData) {
velData* data = (velData*) selfData;
double rho;
int id,size;
double ux,uy;
size = data->size;
for (int i=0;i<size;i++){
id = data->node[i];
ux = data->ux[i];
uy = data->uy[i];
rho = rightRho(f,id,ux);
completeRight(f,id,ux,uy,rho);
}
}
void upperZouHe(double* f, void* selfData) {
velData* data = (velData*) selfData;
double rho;
int id,size;
double ux,uy;
size = data->size;
for (int i=0;i<size;i++){
id = data->node[i];
ux = data->ux[i];
uy = data->uy[i];
rho = upperRho(f,id,uy);
completeUpper(f,id,ux,uy,rho);
}
}
void lowerZouHe(double* f, void* selfData) {
velData* data = (velData*) selfData;
double rho;
int id,size;
double ux,uy;
size = data->size;
for (int i=0;i<size;i++){
id = data->node[i];
ux = data->ux[i];
uy = data->uy[i];
rho = lowerRho(f,id,uy);
completeLower(f,id,ux,uy,rho);
}
}
void rightOpen (double* f, void* selfData){
openData *data = (openData*)selfData;
int id,st,size,next,tgt;
size = data->size;
for (int i=0;i<size;i++){
id = data->node[i];
next = data->nodeNext[i];
st = id*9;
tgt = next*9;
f[st+3] = f[tgt+3];
f[st+6] = f[tgt+6];
f[st+7] = f[tgt+7];
}
/* int st = id*9;
int *leftID =(int*)selfData;
//std::cout<<*leftID<<std::endl;
int tgt = *leftID;
f[st+3] = f[tgt*9+3];
f[st+6] = f[tgt*9+6];
f[st+7] = f[tgt*9+7];*/
/*
f[st+1] = f[tgt*9+1];
f[st+2] = f[tgt*9+2];
f[st+4] = f[tgt*9+4];
f[st+5] = f[tgt*9+5];
f[st+8] = f[tgt*9+8];
f[st] = f[tgt*9];*/
}
void leftOpen(double *f, void* selfData){
openData *data = (openData*)selfData;
int id,st,size,next,tgt;
size = data->size;
for (int i=0;i<size;i++){
id = data->node[i];
next = data->nodeNext[i];
st = id*9;
tgt = next*9;
f[st+1] = f[tgt+1];
f[st+5] = f[tgt+5];
f[st+8] = f[tgt+8];
}
}
void upperOpen(double *f, void* selfData){
openData *data = (openData*)selfData;
int id,st,size,next,tgt;
size = data->size;
for (int i=0;i<size;i++){
id = data->node[i];
next = data->nodeNext[i];
st = id*9;
tgt = next*9;
f[st+4] = f[tgt+4];
f[st+7] = f[tgt+7];
f[st+8] = f[tgt+8];
}
}
void lowerOpen(double *f, void* selfData){
openData *data = (openData*)selfData;
int id,st,size,next,tgt;
size = data->size;
for (int i=0;i<size;i++){
id = data->node[i];
next = data->nodeNext[i];
st = id*9;
tgt = next*9;
f[st+2] = f[tgt+2];
f[st+6] = f[tgt+6];
f[st+5] = f[tgt+5];
}
}
/*
void velocityZouHe(double* f, int id, int *n, void* selfData)
//void velocityZouHe(double *f, int id, void*selfData)
{
velData* data = (velData*) selfData;
double ux = data->ux;
double uy = data->uy;
int inplane[3]={0,0,0};
int leaving[3]={0,0,0};
int unknown[3]={0,0,0};
int tmp(0),tmp2(0),tmp3(0);
for (int i=0;i<q;i++)
{
int dotpt=c[i][0]*n[0]+c[i][1]*n[1];
if (dotpt==0)
{
inplane[tmp]=i;
tmp++;
}
else if (dotpt > 0)
{
leaving[tmp2]=i;
tmp2++;
}
else
{
unknown[tmp3]=i;
tmp3++;
}
}
int st = id*q;
if (n[0]==0)//along y direction
double rho = 1./(1-uy)*(f[st+inplane[0]]+f[st+inplane[1]]+f[st+inplane[2]]
+2*(f[st+leaving[0]]+f[st+leaving[1]]+f[st+leaving[2]]));
// double rho = rightRho(f,id, data->ux);
// completeRight(f,id, data->ux, data->uy, rho);
//not correct from below
f[st+unknown[0]] = f[st+oppositeOf[unknown[0]]] + 0.5 *(f[st+4]-f[st+2])
- rho*ux/6 + rho*uy/2.;
f[st+7] = f[st+5] + 0.5 *(f[st+2]-f[st+4])
- rho*ux/6 - rho*uy/2.;
f[st+3] = f[st+1] - 2./3.*rho*ux;
else if (n[1]==0)
else
cerr<<"can not handle nonorthogonal boundary"<<endl;
}
*/