summaryrefslogtreecommitdiff
path: root/src/boundary/advectionDiffusionMomentaOnBoundaries.hh
blob: d5832bee4c5c983a3a955ba9134144902f90a3a1 (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
/*  This file is part of the OpenLB library
 *
 *  Copyright (C) 2006, 2007 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.
*/

/** \file
 * Implementation of boundary cell dynamics -- generic implementation.
 */
#ifndef ADE_MOMENTA_ON_BOUNDARIES_HH
#define ADE_MOMENTA_ON_BOUNDARIES_HH

#include <limits>
#include "advectionDiffusionMomentaOnBoundaries.h"
#include "dynamics/lbHelpers.h"
#include "dynamics/firstOrderLbHelpers.h"

namespace olb {

////////////////////// Class AdvectionDiffusionBM //////////////////////

template<typename T, typename DESCRIPTOR, int direction, int orientation>
RegularizedTemperatureBM<T,DESCRIPTOR,direction,orientation>::RegularizedTemperatureBM(const T temperature) :
  AdvectionDiffusionBulkMomenta<T,DESCRIPTOR>(),
  _temperature(temperature)
{
}

template<typename T, typename DESCRIPTOR, int direction, int orientation>
T RegularizedTemperatureBM<T,DESCRIPTOR,direction,orientation>::computeRho( Cell<T,DESCRIPTOR> const& cell ) const
{
  return _temperature;
}

template<typename T, typename DESCRIPTOR, int direction, int orientation>
void RegularizedTemperatureBM<T,DESCRIPTOR,direction,orientation>::computeJ( Cell<T,DESCRIPTOR> const& cell, T j[DESCRIPTOR::d] ) const
{
  const T* u = cell.template getFieldPointer<descriptors::VELOCITY>();
  computeJneq( cell, j );

  for (int iD=0; iD<DESCRIPTOR::d; ++iD) {
    j[iD] += _temperature * u[iD];
  }
}


template<typename T, typename DESCRIPTOR, int direction, int orientation>
void RegularizedTemperatureBM<T,DESCRIPTOR,direction,orientation>::computeJneq( Cell<T,DESCRIPTOR> const& cell, T jNeq[DESCRIPTOR::d] ) const
{
  std::vector<int> const& onWallIndices = util::subIndex<DESCRIPTOR, direction, 0>();
  std::vector<int> const& normalIndices = util::subIndex<DESCRIPTOR, direction, orientation>();

  const T* u = cell.template getFieldPointer<descriptors::VELOCITY>();

  T jNeqOnWall[DESCRIPTOR::d], jNeqNormal[DESCRIPTOR::d];
  for (int iD=0; iD<DESCRIPTOR::d; ++iD) {
    jNeqOnWall[iD] = T();
    jNeqNormal[iD] = T();
  }

  for (unsigned fIndex=0; fIndex<onWallIndices.size(); ++fIndex) {
    for (int iD=0; iD<DESCRIPTOR::d; ++iD) {
      jNeqOnWall[iD] += (cell[onWallIndices[fIndex]] - lbHelpers<T,DESCRIPTOR>::equilibriumFirstOrder(onWallIndices[fIndex],_temperature,u)) * descriptors::c<DESCRIPTOR>(onWallIndices[fIndex],iD);
    }
  }

  for (unsigned fIndex=0; fIndex<normalIndices.size(); ++fIndex) {
    for (int iD=0; iD<DESCRIPTOR::d; ++iD) {
      jNeqNormal[iD] += (cell[normalIndices[fIndex]]-lbHelpers<T,DESCRIPTOR>::equilibriumFirstOrder(normalIndices[fIndex],_temperature,u)) * descriptors::c<DESCRIPTOR>(normalIndices[fIndex],iD);
    }
  }

  for (int iD=0; iD<DESCRIPTOR::d; ++iD) {
    jNeq[iD] = jNeqOnWall[iD] + (T)2 * jNeqNormal[iD];
  }
}

template<typename T, typename DESCRIPTOR, int direction, int orientation>
void RegularizedTemperatureBM<T,DESCRIPTOR,direction,orientation>::defineRho( Cell<T,DESCRIPTOR>& cell, T rho )
{
  _temperature = rho;
}

template<typename T, typename DESCRIPTOR, int direction, int orientation>
void RegularizedTemperatureBM<T,DESCRIPTOR,direction,orientation>::defineRhoU( Cell<T,DESCRIPTOR>& cell, T rho, const T u[DESCRIPTOR::d])
{
  _temperature = rho;
  T *u_ = cell.template getFieldPointer<descriptors::VELOCITY>();
  for (int iD = 0; iD < DESCRIPTOR::d; ++iD) {
    u_[iD] = u[iD];
  }
  for (int iPop = 0; iPop < DESCRIPTOR::q; ++iPop) {
    cell[iPop] = lbHelpers<T, DESCRIPTOR>::equilibriumFirstOrder( iPop, rho, u );
  }
}




template<typename T, typename DESCRIPTOR, int direction, int orientation>
RegularizedHeatFluxBM<T,DESCRIPTOR,direction,orientation>::RegularizedHeatFluxBM(T *heatFlux) :
  AdvectionDiffusionBulkMomenta<T,DESCRIPTOR>()
{
  for (int iDim = 0; iDim < DESCRIPTOR::d; iDim++) {
    if (heatFlux == nullptr)
      _heatFlux[iDim] = T();
    else
      _heatFlux[iDim] = heatFlux[iDim];
  }
}

template<typename T, typename DESCRIPTOR, int direction, int orientation>
T RegularizedHeatFluxBM<T,DESCRIPTOR,direction,orientation>::computeRho( Cell<T,DESCRIPTOR> const& cell ) const
{
  std::vector<int> const& onWallIndices = util::subIndex<DESCRIPTOR, direction, 0>();
  std::vector<int> const& normalIndices = util::subIndex<DESCRIPTOR, direction, orientation>();
  const T* u = cell.template getFieldPointer<descriptors::VELOCITY>();

  T rhoOnWall = T();
  for (unsigned fIndex=0; fIndex<onWallIndices.size(); ++fIndex) {
    rhoOnWall += cell[onWallIndices[fIndex]];
  }

  T rhoNormal = T();
  for (unsigned fIndex=0; fIndex<normalIndices.size(); ++fIndex) {
    rhoNormal += cell[normalIndices[fIndex]];
  }

  T rho =((T)2*rhoNormal+rhoOnWall+(T)1 - (T)orientation*_heatFlux[direction]) /
         ((T)1+(T)orientation*u[direction]);

  return rho;
}

template<typename T, typename DESCRIPTOR, int direction, int orientation>
void RegularizedHeatFluxBM<T,DESCRIPTOR,direction,orientation>::computeJ( Cell<T,DESCRIPTOR> const& cell, T j[DESCRIPTOR::d] ) const
{
  T temperature = computeRho(cell);
  const T* u = cell.template getFieldPointer<descriptors::VELOCITY>();

  for (int iD=0; iD<DESCRIPTOR::d; ++iD) {
    j[iD] = _heatFlux[iD] + temperature * u[iD];
  }
}


template<typename T, typename DESCRIPTOR, int direction, int orientation>
void RegularizedHeatFluxBM<T,DESCRIPTOR,direction,orientation>::computeJneq( Cell<T,DESCRIPTOR> const& cell, T jNeq[DESCRIPTOR::d] ) const
{
  for (int iD=0; iD<DESCRIPTOR::d; ++iD) {
    jNeq[iD] = _heatFlux[iD];
  }
}


}  // namespace olb

#endif