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
383
384
385
386
387
388
389
390
391
392
393
|
/* Lattice Boltzmann sample, written in C++, using the OpenLB
* library
*
* Copyright (C) 2008 Orestis Malaspinas, Andrea Parmigiani
* 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.
*/
/* contactAngle3d.cpp
* In this example a semi-spherical droplet of fluid is initialised
* within a different fluid at a solid boundary. The contact angle
* is measured as the droplet comes to equilibrium. This is compared
* with the analytical angle (100 degrees) predicted by the
* parameters set for the boundary.
*
* This example demonstrates how to use the wetting solid boundaries
* for the free-energy model with two fluid components.
*/
#include "olb3D.h"
#include "olb3D.hh" // use only generic version!
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <math.h>
using namespace olb;
using namespace olb::descriptors;
using namespace olb::graphics;
using namespace std;
typedef double T;
#define DESCRIPTOR D3Q19<CHEM_POTENTIAL,FORCE>
// Parameters for the simulation setup
const int N = 75;
const T nxy = 75.;
const T nz = 50.;
const T radius = 0.25 * nxy;
const T alpha = 1.; // Interfacial width [lattice units]
const T kappa1 = 0.005; // For surface tensions [lattice units]
const T kappa2 = 0.005; // For surface tensions [lattice units]
const T gama = 10.; // For mobility of interface [lattice units]
const T h1 = 0.0001448; // Contact angle 80 degrees [lattice units]
const T h2 = -0.0001448; // Contact angle 100 degrees [lattice units]
const int maxIter = 70000;
const int vtkIter = 200;
const int statIter = 200;
const bool calcAngle = true;
T angle_prev = 90.;
void prepareGeometry( SuperGeometry3D<T>& superGeometry,
UnitConverter<T, DESCRIPTOR>& converter) {
OstreamManager clout( std::cout,"prepareGeometry" );
clout << "Prepare Geometry ..." << std::endl;
superGeometry.rename( 0,2 );
Vector<T,3> extend(nxy+2., nxy+2., nz-1.*converter.getPhysDeltaX() );
Vector<T,3> origin( -1., -1., 0.5*converter.getPhysDeltaX() );
IndicatorCuboid3D<T> inner ( extend, origin );
superGeometry.rename( 2,1,inner );
superGeometry.innerClean();
superGeometry.checkForErrors();
superGeometry.print();
clout << "Prepare Geometry ... OK" << std::endl;
}
void prepareLattice( SuperLattice3D<T, DESCRIPTOR>& sLattice1,
SuperLattice3D<T, DESCRIPTOR>& sLattice2,
Dynamics<T, DESCRIPTOR>& bulkDynamics1,
Dynamics<T, DESCRIPTOR>& bulkDynamics2,
UnitConverter<T, DESCRIPTOR>& converter,
SuperGeometry3D<T>& superGeometry,
sOnLatticeBoundaryCondition3D<T,DESCRIPTOR>& sOnBC1,
sOnLatticeBoundaryCondition3D<T,DESCRIPTOR>& sOnBC2 ) {
OstreamManager clout( std::cout,"prepareLattice" );
clout << "Prepare Lattice ..." << std::endl;
// Define lattice Dynamics
sLattice1.defineDynamics( superGeometry, 0, &instances::getNoDynamics<T, DESCRIPTOR>() );
sLattice2.defineDynamics( superGeometry, 0, &instances::getNoDynamics<T, DESCRIPTOR>() );
sLattice1.defineDynamics( superGeometry, 1, &bulkDynamics1 );
sLattice2.defineDynamics( superGeometry, 1, &bulkDynamics2 );
sLattice1.defineDynamics( superGeometry, 2, &instances::getNoDynamics<T, DESCRIPTOR>() );
sLattice2.defineDynamics( superGeometry, 2, &instances::getNoDynamics<T, DESCRIPTOR>() );
// Add wall boundary
sOnBC1.addFreeEnergyWallBoundary( superGeometry, 2, alpha, kappa1, kappa2, h1, h2, 1 );
sOnBC2.addFreeEnergyWallBoundary( superGeometry, 2, alpha, kappa1, kappa2, h1, h2, 2 );
// Bulk initial conditions
// Define spherical domain for fluid 2
std::vector<T> v( 3,T() );
AnalyticalConst3D<T,T> zeroVelocity( v );
AnalyticalConst3D<T,T> one( 1.0 );
SmoothIndicatorSphere3D<T,T> sphere( {nxy/2., nxy/2., 0.}, radius, 10.*alpha );
AnalyticalIdentity3D<T,T> rho( one );
AnalyticalIdentity3D<T,T> phi( one - sphere - sphere );
sLattice1.iniEquilibrium( superGeometry, 1, rho, zeroVelocity );
sLattice2.iniEquilibrium( superGeometry, 1, phi, zeroVelocity );
sLattice1.iniEquilibrium( superGeometry, 2, rho, zeroVelocity );
sLattice2.iniEquilibrium( superGeometry, 2, phi, zeroVelocity );
sLattice1.initialize();
sLattice2.initialize();
sLattice1.communicate();
sLattice2.communicate();
clout << "Prepare Lattice ... OK" << std::endl;
}
void prepareCoupling( SuperLattice3D<T, DESCRIPTOR>& sLattice1,
SuperLattice3D<T, DESCRIPTOR>& sLattice2,
SuperGeometry3D<T>& superGeometry ) {
OstreamManager clout( std::cout,"prepareCoupling" );
clout << "Add lattice coupling" << endl;
// Add the lattice couplings (not to the solid nodes)
// The chemical potential coupling must come before the force coupling
FreeEnergyChemicalPotentialGenerator3D<T, DESCRIPTOR> coupling1(
alpha, kappa1, kappa2);
FreeEnergyForceGenerator3D<T, DESCRIPTOR> coupling2;
// Suppress compiler warnings
coupling1.shift(0, 0, 0);
coupling2.shift(0, 0, 0);
sLattice1.addLatticeCoupling( superGeometry, 1, coupling1, sLattice2 );
sLattice2.addLatticeCoupling( superGeometry, 1, coupling2, sLattice1 );
clout << "Add lattice coupling ... OK!" << endl;
}
void getResults( SuperLattice3D<T, DESCRIPTOR>& sLattice1,
SuperLattice3D<T, DESCRIPTOR>& sLattice2, int iT,
SuperGeometry3D<T>& superGeometry, Timer<T>& timer,
UnitConverter<T, DESCRIPTOR> converter ) {
OstreamManager clout( std::cout,"getResults" );
SuperVTMwriter3D<T> vtmWriter( "contactAngle3d" );
if ( iT==0 ) {
// Writes the geometry, cuboid no. and rank no. as vti file for visualization
SuperLatticeGeometry3D<T, DESCRIPTOR> geometry( sLattice1, superGeometry );
SuperLatticeCuboid3D<T, DESCRIPTOR> cuboid( sLattice1 );
SuperLatticeRank3D<T, DESCRIPTOR> rank( sLattice1 );
vtmWriter.write( geometry );
vtmWriter.write( cuboid );
vtmWriter.write( rank );
vtmWriter.createMasterFile();
}
// Get statistics
if ( iT%statIter==0 ) {
// Timer console output
timer.update( iT );
timer.printStep();
sLattice1.getStatistics().print( iT, converter.getPhysTime(iT) );
sLattice2.getStatistics().print( iT, converter.getPhysTime(iT) );
}
// Writes the VTK files
if ( iT%vtkIter==0 ) {
AnalyticalConst3D<T,T> half_( 0.5 );
SuperLatticeFfromAnalyticalF3D<T, DESCRIPTOR> half(half_, sLattice1);
SuperLatticeVelocity3D<T, DESCRIPTOR> velocity( sLattice1 );
SuperLatticeDensity3D<T, DESCRIPTOR> rho( sLattice1 );
rho.getName() = "rho";
SuperLatticeDensity3D<T, DESCRIPTOR> phi( sLattice2 );
phi.getName() = "phi";
SuperIdentity3D<T,T> c1 (half*(rho+phi));
c1.getName() = "density-fluid-1";
SuperIdentity3D<T,T> c2 (half*
|