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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
|
/* This file is part of the OpenLB library
*
* Copyright (C) 2007 Orestis Malaspinas, Jonas Latt
* E-mail contact: info@openlb.net
* The most recent release of OpenLB can be downloaded at
* <http://www.openlb.net/>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef EXTENDED_FINITE_DIFFERENCE_BOUNDARY_2D_HH
#define EXTENDED_FINITE_DIFFERENCE_BOUNDARY_2D_HH
#include "extendedFiniteDifferenceBoundary2D.h"
#include "core/finiteDifference2D.h"
#include "core/blockLattice2D.h"
#include "core/util.h"
#include "dynamics/lbHelpers.h"
#include "dynamics/firstOrderLbHelpers.h"
#include "boundaryInstantiator2D.h"
namespace olb {
/////////// ExtendedStraightFdBoundaryPostProcessor2D ///////////////////////////////////
template<typename T, typename DESCRIPTOR, int direction, int orientation>
ExtendedStraightFdBoundaryPostProcessor2D<T,DESCRIPTOR,direction,orientation>::
ExtendedStraightFdBoundaryPostProcessor2D(int x0_, int x1_, int y0_, int y1_)
: x0(x0_), x1(x1_), y0(y0_), y1(y1_)
{
OLB_PRECONDITION(x0==x1 || y0==y1);
}
template<typename T, typename DESCRIPTOR, int direction, int orientation>
void ExtendedStraightFdBoundaryPostProcessor2D<T,DESCRIPTOR,direction,orientation>::
processSubDomain(BlockLattice2D<T,DESCRIPTOR>& blockLattice, int x0_, int x1_, int y0_, int y1_)
{
using namespace olb::util::tensorIndices2D;
typedef lbHelpers<T,DESCRIPTOR> lbH;
typedef DESCRIPTOR L;
enum {x,y};
int newX0, newX1, newY0, newY1;
if ( util::intersect (
x0, x1, y0, y1,
x0_, x1_, y0_, y1_,
newX0, newX1, newY0, newY1 ) ) {
for (int iX=newX0; iX<=newX1; ++iX) {
for (int iY=newY0; iY<=newY1; ++iY) {
Cell<T,DESCRIPTOR>& cell = blockLattice.get(iX,iY);
T rho, u[L::d];
cell.computeRhoU(rho,u);
T uSqr = util::normSqr<T,DESCRIPTOR::d>(u);
T dx_U[L::d], dy_U[L::d];
interpolateGradients<0>(blockLattice, dx_U, iX, iY);
interpolateGradients<1>(blockLattice, dy_U, iX, iY);
T rhoGradU[L::d][L::d];
rhoGradU[x][x] = rho * dx_U[x];
rhoGradU[x][y] = rho * dx_U[y];
rhoGradU[y][x] = rho * dy_U[x];
rhoGradU[y][y] = rho * dy_U[y];
T omega = blockLattice.getDynamics(iX, iY) -> getOmega();
T sToPi = - (T)1 / descriptors::invCs2<T,DESCRIPTOR>() / omega;
T pi[util::TensorVal<DESCRIPTOR >::n];
pi[xx] = (T)2 * rhoGradU[x][x] * sToPi;
pi[yy] = (T)2 * rhoGradU[y][y] * sToPi;
pi[xy] = (rhoGradU[x][y] + rhoGradU[y][x]) * sToPi;
// here ends the "regular" fdBoudaryCondition
// implemented in OpenLB
// first we compute the term
// (c_{i\alpha} \nabla_\beta)(rho*u_\alpha*u_\beta)
T dx_rho, dy_rho;
interpolateGradients<0>(blockLattice, dx_rho, iX, iY);
interpolateGradients<1>(blockLattice, dy_rho, iX, iY);
for (int iPop = 0; iPop < L::q; ++iPop) {
T cGradRhoUU = T();
for (int iAlpha=0; iAlpha < L::d; ++iAlpha) {
cGradRhoUU += descriptors::c<L>(iPop,iAlpha) * (
dx_rho*u[iAlpha]*u[x] +
dx_U[iAlpha]*rho*u[x] +
dx_U[x]*rho*u[iAlpha] + //end of dx derivatice
dy_rho*u[iAlpha]*u[y] +
dy_U[iAlpha]*rho*u[y] +
dy_U[y]*rho*u[iAlpha]);
}
// then we compute the term
// c_{i\gamma}\nabla_{\gamma}(\rho*u_\alpha * u_\beta)
T cDivRhoUU[L::d][L::d]; //first step towards QcdivRhoUU
for (int iAlpha = 0; iAlpha < L::d; ++iAlpha) {
for (int iBeta = 0; iBeta < L::d; ++iBeta) {
cDivRhoUU[iAlpha][iBeta] = descriptors::c<L>(iPop,x) *
(dx_rho*u[iAlpha]*u[iBeta] +
dx_U[iAlpha]*rho*u[iBeta] +
dx_U[iBeta]*rho*u[iAlpha])
+ descriptors::c<L>(iPop,y) *
(dy_rho*u[iAlpha]*u[iBeta] +
dy_U[iAlpha]*rho*u[iBeta] +
dy_U[iBeta]*rho*u[iAlpha]);
}
}
//Finally we can compute
// Q_{i\alpha\beta}c_{i\gamma}\nabla_{\gamma}(\rho*u_\alpha * u_\beta)
// and Q_{i\alpha\beta}\rho\nabla_{\alpha}u_\beta
T qCdivRhoUU = T();
T qRhoGradU = T();
for (int iAlpha = 0; iAlpha < L::d; ++iAlpha) {
for (int iBeta = 0; iBeta < L::d; ++iBeta) {
int ci_ci = descriptors::c<L>(iPop,iAlpha)*descriptors::c<L>(iPop,iBeta);
qCdivRhoUU += ci_ci * cDivRhoUU[iAlpha][iBeta];
qRhoGradU += ci_ci * rhoGradU[iAlpha][iBeta];
if (iAlpha == iBeta) {
qCdivRhoUU -= cDivRhoUU[iAlpha][iBeta]/descriptors::invCs2<T,L>();
qRhoGradU -= rhoGradU[iAlpha][iBeta]/descriptors::invCs2<T,L>();
}
}
}
// we then can reconstruct the value of the populations
// according to the complete C-E expansion term
cell[iPop] = lbH::equilibrium(iPop,rho,u,uSqr)
- descriptors::t<T,L>(iPop) * descriptors::invCs2<T,L>() / omega
* (qRhoGradU - cGradRhoUU + 0.5*descriptors::invCs2<T,L>()*qCdivRhoUU);
}
}
}
}
}
template<typename T, typename DESCRIPTOR, int direction, int orientation>
void ExtendedStraightFdBoundaryPostProcessor2D<T,DESCRIPTOR,direction,orientation>::
process(BlockLattice2D<T,DESCRIPTOR>& blockLattice)
{
processSubDomain(blockLattice, x0, x1, y0, y1);
}
template<typename T, typename DESCRIPTOR, int direction, int orientation>
template<int deriveDirection>
void ExtendedStraightFdBoundaryPostProcessor2D<T,DESCRIPTOR,direction,orientation>::
interpolateGradients(BlockLattice2D<T,DESCRIPTOR> const& blockLattice,
T velDeriv[DESCRIPTOR::d], int iX, int iY) const
{
fd::DirectedGradients2D<T, DESCRIPTOR, direction, orientation, direction==deriveDirection>::
interpolateVector(velDeriv, blockLattice, iX, iY);
}
template<typename T, typename DESCRIPTOR, int direction, int orientation>
template<int deriveDirection>
void ExtendedStraightFdBoundaryPostProcessor2D<T,DESCRIPTOR,direction,orientation>::
inte
|