OpenLB 1.7
Loading...
Searching...
No Matches
zouHeDynamics.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2006, 2007 Orestis Malaspinas, Jonas Latt
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24#ifndef ZOU_HE_DYNAMICS_H
25#define ZOU_HE_DYNAMICS_H
26
27#include "dynamics/dynamics.h"
28
29namespace olb {
30
39template<typename T, typename DESCRIPTOR, typename DYNAMICS, typename MOMENTA, int direction, int orientation>
40class ZouHeDynamics : public dynamics::CustomCollision<T,DESCRIPTOR,MOMENTA> {
41private:
42 // Use same MOMENTA in combined and nested (boundary) dynamics
43 using CORRECTED_DYNAMICS = typename DYNAMICS::template exchange_momenta<MOMENTA>;
44
45public:
46 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
47
48 using parameters = typename CORRECTED_DYNAMICS::parameters;
49
50 template<typename M>
52
53 std::type_index id() override {
54 return typeid(ZouHeDynamics);
55 }
56
58 return block.template getData<OperatorParameters<ZouHeDynamics>>();
59 }
60
61 template <typename CELL, typename PARAMETERS, typename V=typename CELL::value_t>
62 CellStatistic<V> apply(CELL& cell, PARAMETERS& parameters) any_platform {
63 // Along all the commented parts of this code there will be an example based
64 // on the situation where the wall's normal vector if (0,1) and the
65 // numerotation of the velocites are done according to the D2Q9
66 // lattice of the OpenLB library.
67
68 // Find all the missing populations
69 // (directions 3,4,5)
70 constexpr auto missingIndexesTmp = util::subIndexOutgoing<DESCRIPTOR,direction,orientation>();
71 std::vector<int> missingIndexes(missingIndexesTmp.cbegin(), missingIndexesTmp.cend());
72
73 // Will contain the missing poputations that are not normal to the wall.
74 // (directions 3,5)
75 std::vector<int> missingDiagonalIndexes = missingIndexes;
76 for (unsigned iPop = 0; iPop < missingIndexes.size(); ++iPop) {
77 int numOfNonNullComp = 0;
78 for (int iDim = 0; iDim < DESCRIPTOR::d; ++iDim) {
79 numOfNonNullComp += util::abs(descriptors::c<DESCRIPTOR>(missingIndexes[iPop],iDim));
80 }
81
82 if (numOfNonNullComp == 1) {
83 missingDiagonalIndexes.erase(missingDiagonalIndexes.begin()+iPop);
84 break;
85 }
86 }
87
88 V rho, u[DESCRIPTOR::d];
89 V falseRho, falseU[DESCRIPTOR::d];
90 MomentaF().computeRhoU(cell, rho, u);
91 V uSqr = util::normSqr<V,DESCRIPTOR::d>(u);
92
93 // The unknown non equilibrium populations are bounced back
94 // (f[3] = feq[3] + fneq[7], f[4] = feq[4] + fneq[8],
95 // f[5] = feq[5] + fneq[1])
96 for (unsigned iPop = 0; iPop < missingIndexes.size(); ++iPop) {
97 cell[missingIndexes[iPop]] = cell[descriptors::opposite<DESCRIPTOR>(missingIndexes[iPop])]
98 - computeEquilibrium(descriptors::opposite<DESCRIPTOR>(missingIndexes[iPop]), rho, u)
99 + computeEquilibrium(missingIndexes[iPop], rho, u);
100 }
101
102 // We recompute rho and u in order to have the new momentum and density. Since
103 // the momentum is not conserved from this scheme, we will corect it. By adding
104 // a contribution to the missingDiagonalVelocities.
105 lbm<DESCRIPTOR>::computeRhoU(cell,falseRho,falseU);
106
107 V diff[DESCRIPTOR::d] {};
108 for (int iDim = 0; iDim < DESCRIPTOR::d; ++iDim) {
109 diff[iDim] = (rho*u[iDim] - falseRho*falseU[iDim])/ V(missingDiagonalIndexes.size());
110 }
111
112 for (unsigned iPop = 0; iPop < missingDiagonalIndexes.size(); ++iPop) {
113 for (int iDim = 1; iDim < DESCRIPTOR::d; ++iDim) {
114 cell[missingDiagonalIndexes[iPop]] +=
115 descriptors::c<DESCRIPTOR>(missingDiagonalIndexes[iPop],(direction+iDim)%DESCRIPTOR::d) * diff[(direction+iDim)%DESCRIPTOR::d];
116 }
117 }
118
119 typename CORRECTED_DYNAMICS::CollisionO().apply(cell, parameters);
120
121 return {rho, uSqr};
122 }
123
124 T computeEquilibrium(int iPop, T rho, const T u[DESCRIPTOR::d]) const override any_platform {
125 return typename CORRECTED_DYNAMICS::EquilibriumF().compute(iPop, rho, u);
126 };
127
128 std::string getName() const override {
129 return "ZouHeDynamics<" + CORRECTED_DYNAMICS().getName() + ">";
130 };
131
132};
133
134}
135
136#endif
Platform-abstracted block lattice for external access and inter-block interaction.
Implementation of Zou-He boundary condition following the paper from Zou and He.
std::type_index id() override
Expose unique type-identifier for RTTI.
std::string getName() const override
Return human-readable name.
AbstractParameters< T, DESCRIPTOR > & getParameters(BlockLattice< T, DESCRIPTOR > &block) override
Parameters access for legacy post processors.
typename MOMENTA::template type< DESCRIPTOR > MomentaF
T computeEquilibrium(int iPop, T rho, const T u[DESCRIPTOR::d]) const override any_platform
Return iPop equilibrium for given first and second momenta.
CellStatistic< V > apply(CELL &cell, PARAMETERS &parameters) any_platform
typename CORRECTED_DYNAMICS::parameters parameters
ADf< T, DIM > abs(const ADf< T, DIM > &a)
Definition aDiff.h:1019
Top level namespace for all of OpenLB.
#define any_platform
Define preprocessor macros for device-side functions, constant storage.
Definition platform.h:78
Dynamic access interface for FIELD-valued parameters.
Return value of any collision.
Definition interface.h:43
static void computeRhoU(CELL &cell, RHO &rho, U &u) any_platform
Computation of hydrodynamic variables.
Definition lbm.h:219