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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
|
/* Lattice Boltzmann sample, written in C++, using the OpenLB
* library
*
* Copyright (C) 2015 Mathias J. Krause, Patrick Nathan
* 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.
*/
/* nozzle3d.cpp:
* This example examines a turbulent flow in a nozzle injection tube. At the
* main inlet, either a block profile or a power 1/7 profile is imposed as a
* Dirchlet velocity boundary condition, whereas at the outlet a
* Dirichlet pressure condition is set by p=0 (i.e. rho=1).
*
* The example shows the usage of turbulent models.
*
* The results of a simular simulation setup are publish in TODO
*/
#include "olb3D.h"
#ifndef OLB_PRECOMPILED // Unless precompiled version is used
#include "olb3D.hh" // Include full template code
#endif
#include <vector>
#include <cmath>
#include <iostream>
#include <fstream>
using namespace olb;
using namespace olb::descriptors;
using namespace olb::graphics;
using namespace olb::util;
using namespace std;
typedef double T;
// Choose your turbulent model of choice
//#define RLB
#define Smagorinsky //default
//#define ConsitentStrainSmagorinsky
//#define ShearSmagorinsky
//#define Krause
#ifdef ShearSmagorinsky
#define DESCRIPTOR ShearSmagorinskyD3Q19Descriptor
#else
#define DESCRIPTOR D3Q19<>
#endif
// Parameters for the simulation setup
const int N = 3; // resolution of the model, for RLB N>=5, others N>=2, but N>=5 recommended
const int M = 1; // time discretization refinement
const int inflowProfileMode = 0; // block profile (mode=0), power profile (mode=1)
const T maxPhysT = 200.; // max. simulation time in s, SI unit
template <typename T, typename _DESCRIPTOR>
class TurbulentVelocity3D : public AnalyticalF3D<T,T> {
protected:
// block profile (mode=0), power profile (mode=1)
int _mode;
T rho;
T nu;
T u0;
T p0;
T charL;
T dx;
public:
TurbulentVelocity3D( UnitConverter<T,_DESCRIPTOR> const& converter, int mode=0 ) : AnalyticalF3D<T,T>( 3 ) {
_mode = mode;
u0 = converter.getCharLatticeVelocity();
rho = converter.getPhysDensity();
nu = converter.getPhysViscosity();
charL = converter.getCharPhysLength();
p0 = converter.getCharPhysPressure();
dx = converter.getConversionFactorLength();
this->getName() = "turbulentVelocity3d";
};
bool operator()( T output[], const S input[] ) override {
T y = input[1];
T z = input[2];
// block profile inititalization
T u_calc = u0;
// power profile inititalization
if ( _mode==1 ) {
T obst_y = 5.5+dx;
T obst_z = 5.5+dx;
T obst_r = 0.5;
T B = 5.5;
T kappa = 0.4;
T ReTau = 183.6;
u_calc = u0/7.*( 2.*nu*ReTau/( charL*kappa )*log( fabs( 2.*ReTau/charL*( obst_r - sqrt( pow( y - obst_y, 2. )
+ pow( z - obst_z, 2. ) ) )*1.5*( 1 + sqrt( pow( y - obst_y, 2. )
+ pow( z - obst_z, 2. ) )/obst_r )/( 1 + 2.*pow( sqrt( pow( y - obst_y, 2. )
+ pow( z - obst_z, 2. ) )/obst_r, 2. ) ) ) + B ) );
}
T a = -1., b = 1.;
T nRandom = rand()/( T )RAND_MAX*( b-a ) + a;
output[0] = u_calc+ 0.15*u0*nRandom;
output[1] = 0.15*u0*nRandom;
output[2] = 0.15*u0*nRandom;
return true;
};
};
void prepareGeometry( UnitConverter<T,DESCRIPTOR> const& converter, IndicatorF3D<T>& indicator, SuperGeometry3D<T>& superGeometry ) {
OstreamManager clout( std::cout,"prepareGeometry" );
clout << "Prepare Geometry ..." << std::endl;
// Sets material number for fluid and boundary
superGeometry.rename( 0,2,indicator );
Vector<T,3> origin( T(),
5.5*converter.getCharPhysLength()+converter.getConversionFactorLength(),
5.5*converter.getCharPhysLength()+converter.getConversionFactorLength() );
Vector<T,3> extend( 4.*converter.getCharPhysLength()+5*converter.getConversionFactorLength(),
5.5*converter.getCharPhysLength()+converter.getConversionFactorLength(),
5.5*converter.getCharPhysLength()+converter.getConversionFactorLength() );
IndicatorCylinder3D<T> inletCylinder( extend, origin, converter.getCharPhysLength() );
superGeometry.rename( 2,1,inletCylinder );
origin[0]=4.*converter.getCharPhysLength();
origin[1]=5.5*converter.getCharPhysLength()+converter.getConversionFactorLength();
origin[2]=5.5*converter.getCharPhysLength()+converter.getConversionFactorLength();
extend[0]=54.*converter.getCharPhysLength();
extend[1]=5.5*converter.getCharPhysLength()+converter.getConversionFactorLength();
extend[2]=5.5*converter.getCharPhysLength()+converter.getConversionFactorLength();
IndicatorCylinder3D<T> injectionTube( extend, origin, 5.5*converter.getCharPhysLength() );
superGeometry.rename( 2,1,injectionTube );
origin[0]=converter.getConversionFactorLength();
origin[1]=5.5*converter.getCharPhysLength()+converter.getConversionFactorLength();
origin[2]=5.5*converter.getCharPhysLength()+converter.getConversionFactorLength();
extend[0]=T();
extend[1]=5.5*converter.getCharPhysLength()+converter.getConversionFactorLength();
extend[2]=5.5*converter.getCharPhysLength()+converter.getConversionFactorLength();
IndicatorCylinder3D<T> cylinderIN( extend, origin, converter.getCharPhysLength() );
superGeometry.rename( 1,3,cylinderIN );
origin[0]=54.*converter.getCharPhysLength()-converter.getConversionFactorLength();
origin[1]=5.5*converter.getCharPhysLength()+converter.getConversionFactorLength();
origin[2]=5.5*converter.getCharPhysLength()+converter.getConversionFactorLength();
extend[0]=54.*converter.getCharPhysLength();
extend[1]=5.5*converter.getCharPhysLength()+converter.getConversionFactorLength();
extend[2]=5.5*converter.getCharPhysLength()+converter.getConversionFactorLength();
IndicatorCylinder3D<T> cylinderOUT( extend, origin, 5.5*converter.getCharPhysLength() );
superGeometry.rename( 1,4,cylinderOUT );
// Removes all not needed boundary voxels outside the surface
superGeometry.clean();
// Removes all not needed boundary voxels inside the surface
superGeometry.innerClean();
superGeometry.checkForErrors();
superGeometry.print();
clout << "Prepare Geometry ... OK" << std::endl;
}
void prepareLattice( SuperLattice3D<T,DESCRIPTOR>& sLattice,
UnitConverter<T,DESCRIPTOR> const& converter,
Dynamics<T, DESCRIPTOR>& bulkDynamics,
sOnLatticeBoundaryCondition3D<T,DESCRIPTOR>& bc,
sOffLatticeBoundaryCondition3D<T,DESCRIPTOR>& offBc,
SuperGeometry3D<T>& superGeometry ) {
OstreamManager clout( std::cout,"prepareLattice" );
clout << "Prepare Lattice ..." << std::endl;
const T omega = converter.getLatticeRelaxationFrequency();
// Material=0 -->do nothing
sLattice.defineDynamics( superGeometry, 0, &instances::getNoDynamics<T, DESCRIPTOR>() );
// Material=1 -->bulk dynamics
// Material=3 -->bulk dynamics (inflow)
// Material=4 -->bulk dynamics (outflow)
sLattice.defineDynamics( superGeometry.getMaterialIndicator({1, 3, 4}), &
|