summaryrefslogtreecommitdiff
path: root/src/boundary/advectionDiffusionBoundaries.hh
blob: 7c7f391627d1f23c28c9234968657f613d9049f8 (plain)
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
/*  This file is part of 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.
*/

#ifndef ADVECTION_DIFFUSION_BOUNDARIES_HH
#define ADVECTION_DIFFUSION_BOUNDARIES_HH

#include "advectionDiffusionBoundaries.h"
#include "dynamics/latticeDescriptors.h"
#include "core/util.h"
#include "dynamics/lbHelpers.h"

namespace olb {

 

//==================================================================================================
//==================== For regularized Advection Diffusion Boundary Condition ======================
//============================================================================================


// For flat Walls

template<typename T, typename DESCRIPTOR, typename Dynamics, int direction, int orientation>
AdvectionDiffusionBoundariesDynamics<T,DESCRIPTOR,Dynamics,direction,orientation>::
AdvectionDiffusionBoundariesDynamics( T omega_, Momenta<T,DESCRIPTOR>& momenta_)
  : BasicDynamics<T,DESCRIPTOR>(momenta_), boundaryDynamics(omega_, momenta_)
{
}

template<typename T, typename DESCRIPTOR, typename Dynamics, int direction, int orientation>
T AdvectionDiffusionBoundariesDynamics<T,DESCRIPTOR,Dynamics,direction,orientation>::
computeEquilibrium(int iPop, T rho, const T u[DESCRIPTOR::d], T uSqr) const
{
  return lbHelpers<T,DESCRIPTOR>::equilibriumFirstOrder( iPop, rho, u );
}


template<typename T, typename DESCRIPTOR, typename Dynamics, int direction, int orientation>
void AdvectionDiffusionBoundariesDynamics<T,DESCRIPTOR,Dynamics,direction,orientation>::
collide(Cell<T,DESCRIPTOR>& cell,LatticeStatistics<T>& statistics)
{
  typedef DESCRIPTOR L;
  typedef lbHelpers<T,DESCRIPTOR> lbH;

  T dirichletTemperature = this->_momenta.computeRho(cell);
  T* u = cell.template getFieldPointer<descriptors::VELOCITY>();

  std::vector<int> unknownIndexes = util::subIndexOutgoing<L, direction,
      orientation>();
  std::vector<int> knownIndexes = util::remainingIndexes<L>(unknownIndexes);

  int missingNormal = 0;

  if ((L::d == 3 && L::q == 7)||(L::d == 2 && L::q == 5)) {
    T sum = T();
    for (unsigned i = 0; i < knownIndexes.size(); ++i) {
      sum += cell[knownIndexes[i]];
    }

    T difference = dirichletTemperature - (T) 1 - sum; // on cell there are non-shiftet values -> temperature has to be changed

    // here I know all missing and non missing f_i
    for (unsigned i = 0; i < unknownIndexes.size(); ++i) {
      int numOfNonNullComp = 0;
      for (int iDim = 0; iDim < L::d; ++iDim) {
        numOfNonNullComp += abs(descriptors::c<L>(unknownIndexes[i],iDim));
      }
      if (numOfNonNullComp == 1) {
        missingNormal = unknownIndexes[i];
        // here missing diagonal directions are erased
        // just the normal direction stays (D3Q7)
        unknownIndexes.erase(unknownIndexes.begin() + i);
        break;

      }
    }
    cell[missingNormal] = difference; // on cell there are non-shiftet values -> temperature has to be changed
    boundaryDynamics.collide(cell, statistics); // only for D3Q7
  } else {
    // part for q=19 copied from AdvectionDiffusionEdgesDynamics.collide()
    // but here just all missing directions, even at border of inlet area
    // has to be checked!
    for (unsigned iteratePop = 0; iteratePop < unknownIndexes.size();
        ++iteratePop) {
      cell[unknownIndexes[iteratePop]] =
          lbH::equilibriumFirstOrder(unknownIndexes[iteratePop], dirichletTemperature, u)
              - (cell[util::opposite<L>(unknownIndexes[iteratePop])]
                  - lbH::equilibriumFirstOrder(
                      util::opposite<L>(unknownIndexes[iteratePop]),
                      dirichletTemperature, u));
    }
  }
}

template<typename T, typename DESCRIPTOR, typename Dynamics, int direction, int orientation>
T AdvectionDiffusionBoundariesDynamics<T,DESCRIPTOR,Dynamics,direction,orientation>::
getOmega() const
{
  return boundaryDynamics.getOmega();
}

template<typename T, typename DESCRIPTOR, typename Dynamics, int direction, int orientation>
void AdvectionDiffusionBoundariesDynamics<T,DESCRIPTOR,Dynamics,direction,orientation>::
setOmega(T omega_)
{
  boundaryDynamics.setOmega(omega_);
}

//=================================================================
// For 2D Corners with regularized Dynamic ==============================================
//=================================================================
template<typename T, typename DESCRIPTOR, typename Dynamics, int xNormal, int yNormal>
AdvectionDiffusionCornerDynamics2D<T,DESCRIPTOR,Dynamics,xNormal,yNormal>::AdvectionDiffusionCornerDynamics2D(
  T omega_, Momenta<T,DESCRIPTOR>& momenta_)
  : BasicDynamics<T,DESCRIPTOR>(momenta_),
    boundaryDynamics(omega_, momenta_)
{
}

template<typename T, typename DESCRIPTOR, typename Dynamics,  int xNormal, int yNormal>
T AdvectionDiffusionCornerDynamics2D<T,DESCRIPTOR,Dynamics,xNormal,yNormal>::computeEquilibrium(int iPop, T rho, const T u[DESCRIPTOR::d], T uSqr) const
{
  return lbHelpers<T,DESCRIPTOR>::equilibriumFirstOrder( iPop, rho, u );
}


template<typename T, typename DESCRIPTOR, typename Dynamics,  int xNormal, int yNormal>
void AdvectionDiffusionCornerDynamics2D<T,DESCRIPTOR,Dynamics,xNormal,yNormal>::collide(Cell<T,DESCRIPTOR>& cell,LatticeStatistics<T>& statistics)
{
  typedef DESCRIPTOR L;
  typedef lbHelpers<T,DESCRIPTOR> lbH;

  T temperature = this->_momenta.computeRho(cell);
  T* u = cell.template getFieldPointer<descriptors::VELOCITY>();
  // I need to get Missing information on the corners !!!!
  std::vector<int> unknownIndexes = util::subIndexOutgoing2DonCorners<L,xNormal,yNormal>();
  // here I know all missing and non missing f_i


  // The collision procedure for D2Q5 and D3Q7 lattice is the same ...
  // Given the rule f_i_neq = -f_opposite(i)_neq
  // I have the right number of equations for the number of unknowns using these lattices

  for (unsigned iPop = 0; iPop < unknownIndexes.size(); ++iPop) {
    cell[unknownIndexes[iPop]] = lbH::equilibriumFirstOrder(unknownIndexes[iPop], temperature, u)
                                 -(cell[util::opposite<L>(unknownIndexes[iPop])]
                                 - lbH::equilibriumFirstOrder(util::opposite<L>(unknownIndexes[iPop]), temperature, u) ) ;
  }

  // Once all the f_i are known, I can call the collision for the Regularized Model.
  boundaryDynamics.collide(cell, statistics);

}

template<typename T, typename DESCRIPTOR, typename Dynamics, int xNormal, int yNormal>
T AdvectionDiffusionCornerDynamics2D<T,DESCRIPTOR,Dynamics,xNormal,yNormal>::getOmega() const
{
  return boundaryDynamics.getOmega();
}

template<typename T, typename DESCRIPTOR, typename Dynamics, int xNormal, int yNormal>
void AdvectionDiffusionCornerDynamics2D<T,DESCRIPTOR,Dynamics,xNormal,yNormal>::setOmega(T omega_)
{
  boundaryDynamics.setOmega(omega_);
}



//=================================================================
// For 3D Corners with regularized Dynamic ==============================================
//=================================================================
template<typename T, typename DESCRIPTOR, typename Dynamics, int xNormal, int yNormal, int zNormal>
AdvectionDiffusionCornerDynamics3D<T,DESCRIPTOR,Dynamics,xNormal,yNormal,zNormal>::AdvectionDiffusionCornerDynamics3D(
  T omega_, Momenta<T,DESCRIPTOR>& momenta_)
  : BasicDynamics<T,DESCRIPTOR>(momenta_),
    boundaryDynamics(omega_, momenta_)
{
}

template<typename T, typename DESCRIPTOR, typename Dynamics,  int xNormal, int yNormal, int zNormal>
T AdvectionDiffusionCornerDynamics3D<T,DESCRIPTOR,Dynamics,xNormal,yNormal,zNormal>::computeEquilibrium(int iPop, T rho, const T u[DESCRIPTOR::d], T uSqr) const
{
  return lbHelpers<T, DESCRIPTOR>::equilibriumFirstOrder( iPop, rho, u );
}


template<typename T, typename DESCRIPTOR, typename Dynamics,  int xNormal, int yNormal, int zNormal>
void AdvectionDiffusionCornerDynamics3D<T,DESCRIPTOR,<