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
|
/* Lattice Boltzmann sample, written in C++, using the OpenLB
* library
*
* Copyright (C) 2019 Davide Dapelo
* 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.
*/
/* Models for Lagrangian back-coupling methods -- generic implementation.
*/
#ifndef LB_BACK_COUPLING_MODELS_HH
#define LB_BACK_COUPLING_MODELS_HH
namespace olb {
////////////////////// Class BaseBackCouplingModel ////////////////////////
template<typename T, typename Lattice, template<typename V> class Particle>
BaseBackCouplingModel<T,Lattice,Particle>::BaseBackCouplingModel (
UnitConverter<T, Lattice>& converter,
SuperLattice3D<T, Lattice>& sLattice,
SuperGeometry3D<T>& sGeometry )
: _converter(converter),
_sGeometry(sGeometry),
_sLattice(sLattice)
{
_zeroAnalytical = std::make_shared<AnalyticalConst3D<T, T> > (T());
_zeroField = std::make_shared<AnalyticalComposed3D<T, T> > (*_zeroAnalytical, *_zeroAnalytical, *_zeroAnalytical);
}
template<typename T, typename Lattice, template<typename V> class Particle>
void BaseBackCouplingModel<T,Lattice,Particle>::resetExternalField(int material)
{
// resets external field
this->_sLattice.template defineField<descriptors::FORCE>(this->_sGeometry, material, *_zeroField);
// NECESSARY to communicate values before using them in operator()
this->_sLattice.communicate();
}
////////////////////// Class CubicDeltaBackCouplingModel ////////////////////////
template<typename T, typename Lattice, template<typename V> class Particle>
CubicDeltaBackCouplingModel<T,Lattice,Particle>::CubicDeltaBackCouplingModel (
UnitConverter<T, Lattice>& converter,
SuperLattice3D<T, Lattice>& sLattice,
SuperGeometry3D<T>& sGeometry )
: BaseBackCouplingModel<T,Lattice,Particle>(converter, sLattice, sGeometry)
{
_cubicDeltaFunctional = std::make_shared<SuperLatticeSmoothDiracDelta3D<T, Lattice> > (
this->_sLattice, this->_converter, this->_sGeometry );
}
template<typename T, typename Lattice, template<typename V> class Particle>
bool CubicDeltaBackCouplingModel<T,Lattice,Particle>::operator() (Particle<T>* p, int globic, int material, int subCycles)
{
int locIC = this->_sLattice.getLoadBalancer().loc(globic);
// reading the force from the value stored inside the particle
std::vector<T> physForceP = p->getStoreForce(); // physical force acting on the particle
T latticeForceP[3] = {T(), T(), T()}; // dimensionless force acting on the particle
latticeForceP[0] = physForceP[0] / this->_converter.getConversionFactorForce();
latticeForceP[1] = physForceP[1] / this->_converter.getConversionFactorForce();
latticeForceP[2] = physForceP[2] / this->_converter.getConversionFactorForce();
T physPosP[3] = {T(), T(), T()}; // particle's physical position
physPosP[0] = (p->getPos()[0]);
physPosP[1] = (p->getPos()[1]);
physPosP[2] = (p->getPos()[2]);
// particle's dimensionless position, rounded at neighbouring voxel
int latticeRoundedPosP[3] = {0, 0, 0};
this->_sLattice.getCuboidGeometry().get(globic).getLatticeR (
latticeRoundedPosP, physPosP );
// smooth Dirac delta
this->_cubicDeltaFunctional->operator() (_delta, physPosP, globic);
T tempDelta = T();
T F[3] = {T(), T(), T()}; // dimensionless smoothed force
for (int i = -_range; i <= _range; ++i) {
for (int j = -_range; j <= _range; ++j) {
for (int k = -_range; k <= _range; ++k) {
if (this->_sGeometry.getBlockGeometry(locIC).getMaterial(
latticeRoundedPosP[0] + i, latticeRoundedPosP[1] + j,
latticeRoundedPosP[2] + k) == material) {
tempDelta = _delta[i + _range][j + _range][k + _range];
F[0] = -latticeForceP[0] * tempDelta / (T)(subCycles);
F[1] = -latticeForceP[1] * tempDelta / (T)(subCycles);
F[2] = -latticeForceP[2] * tempDelta / (T)(subCycles);
this->_sLattice.getBlockLattice(locIC).get (
latticeRoundedPosP[0] + i,
latticeRoundedPosP[1] + j,
latticeRoundedPosP[2] + k ).template addField<descriptors::FORCE>( F );
}
}
}
}
return true;
}
////////////////////// Class LocalDeltaBackCouplingModel ////////////////////////
template<typename T, typename Lattice, template<typename V> class Particle>
LocalBackCouplingModel<T,Lattice,Particle>::LocalBackCouplingModel (
UnitConverter<T, Lattice>& converter,
SuperLattice3D<T, Lattice>& sLattice,
SuperGeometry3D<T>& sGeometry )
: BaseBackCouplingModel<T,Lattice,Particle>(converter, sLattice, sGeometry)
{}
template<typename T, typename Lattice, template<typename V> class Particle>
bool LocalBackCouplingModel<T,Lattice,Particle>::operator() (Particle<T>* p, int globic, int material, int subCycles)
{
int locIC = this->_sLattice.getLoadBalancer().loc(globic);
// reading the force from the value stored inside the particle
std::vector<T> physForceP = p->getStoreForce(); // physical force acting on the particle
T latticeForceP[3] = {T(), T(), T()}; // dimensionless force acting on the particle
latticeForceP[0] = physForceP[0] / this->_converter.getConversionFactorForce();
latticeForceP[1] = physForceP[1] / this->_converter.getConversionFactorForce();
latticeForceP[2] = physForceP[2] / this->_converter.getConversionFactorForce();
T physPosP[3] = {T(), T(), T()}; // particle's physical position
physPosP[0] = (p->getPos()[0]);
physPosP[1] = (p->getPos()[1]);
physPosP[2] = (p->getPos()[2]);
// particle's dimensionless position, rounded at neighbouring voxel
int latticeRoundedPosP[3] = {0, 0, 0};
this->_sLattice.getCuboidGeometry().get(globic).getLatticeR (
latticeRoundedPosP, physPosP );
if (this->_sGeometry.getBlockGeometry(locIC).getMaterial(
latticeRoundedPosP[0], latticeRoundedPosP[1],
latticeRoundedPosP[2]) == material) {
T F[3] = {T(), T(), T()}; // dimensionless smoothed force
F[0] = -latticeForceP[0] / (T)(subCycles);
F[1] = -latticeForceP[1] / (T)(subCycles);
F[2] = -latticeForceP[2] / (T)(subCycles);
this->_sLattice.getBlockLattice(locIC).get (
latticeRoundedPosP[0],
latticeRoundedPosP[1],
latticeRoundedPosP[2] ).template addField<descriptors::FORCE>( F );
}
return true;
}
////////////////////// Class NonLocalBaseBackCouplingModel ////////////////////////
template<typename T, typename Lattice, template<typename V> class Particle>
NonLocalBaseBackCouplingModel<T,Lattice,Particle>::NonLocalBaseBackCouplingModel (
UnitConverter<T, Lattice>& converter,
SuperLattice3D<T, Lattice>& sLattice,
SuperGeometry3D<T>& sGeometry,
SmoothingFunctional<T, Lattice>& smoothingFunctional )
: BaseBackCouplingModel<T,Lattice,Particle>(converter, sLattice, sGeometry),
_smoothingFunctional(smoothingFunctional)
{}
template<typename T, typename Lattice, template<typename V> class Particle>
bool NonLocalBaseBackCouplingModel<T,Lattice,Particle>::operator() (Particle<T>* p, int globic, int material, int subCycles)
{
int locIC = this->_sLattice.getLoadBalancer().loc(globic);
// reading the force from the value stored inside the particle
std::vector<T> physForceP = p->getStoreForce(); // physical force acting on the particle
T latticeForceP[3]
|