$treeview $search $mathjax
Palabos  Version 1.1
$projectbrief
$projectbrief
$searchbox

bounceBackModels.hh

Go to the documentation of this file.
00001 /* This file is part of the Palabos library.
00002  *
00003  * Copyright (C) 2011 FlowKit Sarl
00004  * Avenue de Chailly 23
00005  * 1012 Lausanne, Switzerland
00006  * E-mail contact: contact@flowkit.com
00007  *
00008  * The most recent release of Palabos can be downloaded at 
00009  * <http://www.palabos.org/>
00010  *
00011  * The library Palabos is free software: you can redistribute it and/or
00012  * modify it under the terms of the GNU Affero General Public License as
00013  * published by the Free Software Foundation, either version 3 of the
00014  * License, or (at your option) any later version.
00015  *
00016  * The library is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU Affero General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Affero General Public License
00022  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00023 */
00024 
00029 #ifndef BOUNCE_BACK_MODELS_HH
00030 #define BOUNCE_BACK_MODELS_HH
00031 
00032 #include "boundaryCondition/bounceBackModels.h"
00033 #include "core/cell.h"
00034 #include "latticeBoltzmann/dynamicsTemplates.h"
00035 #include "latticeBoltzmann/momentTemplates.h"
00036 #include "core/latticeStatistics.h"
00037 #include "core/array.h"
00038 #include <algorithm>
00039 #include <limits>
00040 
00041 namespace plb {
00042 
00043 /* *************** Class MomentumExchangeBounceBack ************************* */
00044 
00045 template<typename T, template<typename U> class Descriptor>
00046 MomentumExchangeBounceBack<T,Descriptor>::MomentumExchangeBounceBack (
00047         Array<plint, Descriptor<T>::d> forceIds_, T rho_)
00048     : fluidDirections(),
00049       forceIds(forceIds_),
00050       rho(rho_)
00051 { }
00052 
00053 template<typename T, template<typename U> class Descriptor>
00054 MomentumExchangeBounceBack<T,Descriptor>::MomentumExchangeBounceBack(HierarchicUnserializer& unserializer)
00055 {
00056     unserialize(unserializer);
00057 }
00058 
00059 
00060 template<typename T, template<typename U> class Descriptor>
00061 MomentumExchangeBounceBack<T,Descriptor>* MomentumExchangeBounceBack<T,Descriptor>::clone() const {
00062     return new MomentumExchangeBounceBack<T,Descriptor>(*this);
00063 }
00064 
00065 template<typename T, template<typename U> class Descriptor>
00066 int MomentumExchangeBounceBack<T,Descriptor>::id =
00067     meta::registerGeneralDynamics<T,Descriptor,MomentumExchangeBounceBack<T,Descriptor> >("MomentumExchangeBounceBack");
00068 
00069 template<typename T, template<typename U> class Descriptor>
00070 int MomentumExchangeBounceBack<T,Descriptor>::getId() const {
00071     return id;
00072 }
00073 
00074 template<typename T, template<typename U> class Descriptor>
00075 void MomentumExchangeBounceBack<T,Descriptor>::serialize(HierarchicSerializer& serializer) const
00076 {
00077     serializer.addValue(rho);
00078     serializer.addValue((int)(fluidDirections.size()));
00079     serializer.addValues(fluidDirections);
00080     for (plint iDim=0; iDim<Descriptor<T>::d; ++iDim) {
00081         serializer.addValue(forceIds[iDim]);
00082     }
00083 //     Dynamics<T,Descriptor>::serialize(serializer);
00084 }
00085 
00086 template<typename T, template<typename U> class Descriptor>
00087 void MomentumExchangeBounceBack<T,Descriptor>::unserialize(HierarchicUnserializer& unserializer) 
00088 {
00089     PLB_PRECONDITION( unserializer.getId() == this->getId() );
00090     unserializer.readValue(rho);
00091     fluidDirections.resize(unserializer.readValue<int>());
00092     unserializer.readValues(fluidDirections);
00093     for (plint iDim=0; iDim<Descriptor<T>::d; ++iDim) {
00094         unserializer.readValue(forceIds[iDim]);
00095     }
00096 //     Dynamics<T,Descriptor>::unserialize(unserializer);
00097 }
00098  
00099 template<typename T, template<typename U> class Descriptor>
00100 void MomentumExchangeBounceBack<T,Descriptor>::collide (
00101         Cell<T,Descriptor>& cell,
00102         BlockStatistics& statistics )
00103 {
00104     enum { numDim=Descriptor<T>::d };
00105     using namespace indexTemplates;
00106 
00107     // Before collision, the amount of exchanged momentum is computed.
00108     Array<T,numDim> momentum;
00109     momentum.resetToZero();
00110     // Sum over all populations which are incoming from the fluid.
00111     for (pluint iFluid=0; iFluid < fluidDirections.size(); ++iFluid) {
00112         plint iPop = fluidDirections[iFluid];
00113         plint iOpp = opposite<Descriptor<T> >(iPop);
00114         for (plint iD=0; iD<numDim; ++iD) {
00115             // The momentum contribution is multiplied by two:
00116             //   One contribution for the momentum loss into the obstacle,
00117             //   and one contribution for the momentum gain in the subsequent
00118             //   after-bounce-back streaming step.
00119             momentum[iD] += (T)2*Descriptor<T>::c[iPop][iD]*cell[iOpp];
00120         }
00121     }
00122     // Add the momentum exchange for this cell to the total balance due to the
00123     //   obstacle.
00124     if (cell.takesStatistics()) {
00125         for (plint iD=0; iD<numDim; ++iD) {
00126             // Add a negative sign, to get the force acting on the obstacle,
00127             //   and not on the fluid.
00128             statistics.gatherSum(forceIds[iD], -momentum[iD]);
00129         }
00130     }
00131 
00132     // Finally, do the bounce-back operation, which replaces the usual collision.
00133     for (plint iPop=1; iPop <= Descriptor<T>::q/2; ++iPop) {
00134         std::swap(cell[iPop], cell[iPop+Descriptor<T>::q/2]);
00135     }
00136 }
00137 
00138 template<typename T, template<typename U> class Descriptor>
00139 T MomentumExchangeBounceBack<T,Descriptor>::computeEquilibrium(plint iPop, T rhoBar, Array<T,Descriptor<T>::d> const& j,
00140                                                                T jSqr, T thetaBar) const
00141 {
00142     return T();
00143 }
00144 
00145 template<typename T, template<typename U> class Descriptor>
00146 void MomentumExchangeBounceBack<T,Descriptor>::regularize(
00147         Cell<T,Descriptor>& cell, T rhoBar, Array<T,Descriptor<T>::d> const& j,
00148         T jSqr, Array<T,SymmetricTensor<T,Descriptor>::n> const& PiNeq, T thetaBar ) const
00149 { }
00150 
00151 template<typename T, template<typename U> class Descriptor>
00152 T MomentumExchangeBounceBack<T,Descriptor>::computeDensity(Cell<T,Descriptor> const& cell) const {
00153     return rho;
00154 }
00155 
00156 template<typename T, template<typename U> class Descriptor>
00157 T MomentumExchangeBounceBack<T,Descriptor>::computePressure(Cell<T,Descriptor> const& cell) const {
00158     return T();
00159 }
00160 
00161 template<typename T, template<typename U> class Descriptor>
00162 void MomentumExchangeBounceBack<T,Descriptor>::computeVelocity (
00163         Cell<T,Descriptor> const& cell,
00164         Array<T,Descriptor<T>::d>& u) const
00165 {
00166     u.resetToZero();
00167 }
00168 
00169 template<typename T, template<typename U> class Descriptor>
00170 T MomentumExchangeBounceBack<T,Descriptor>::computeTemperature(Cell<T,Descriptor> const& cell) const {
00171     return T();
00172 }
00173 
00174 template<typename T, template<typename U> class Descriptor>
00175 void MomentumExchangeBounceBack<T,Descriptor>::computeDeviatoricStress (
00176         Cell<T,Descriptor> const& cell,
00177         Array<T,SymmetricTensor<T,Descriptor>::n>& PiNeq ) const
00178 {
00179     PiNeq.resetToZero();
00180 }
00181 
00182 template<typename T, template<typename U> class Descriptor>
00183 void MomentumExchangeBounceBack<T,Descriptor>::computeHeatFlux (
00184         Cell<T,Descriptor> const& cell,
00185         Array<T,Descriptor<T>::d>& q) const
00186 {
00187     q.resetToZero();
00188 }
00189 
00190 template<typename T, template<typename U> class Descriptor>
00191 void MomentumExchangeBounceBack<T,Descriptor>::computeMoment (
00192         Cell<T,Descriptor> const& cell, plint momentId, T* moment) const
00193 { }
00194 
00195 template<typename T, template<typename U> class Descriptor>
00196 T MomentumExchangeBounceBack<T,Descriptor>::getOmega() const {
00197     return T();
00198 }
00199 
00200 template<typename T, template<typename U> class Descriptor>
00201 void MomentumExchangeBounceBack<T,Descriptor>::setOmega(T omega_)
00202 { }
00203 
00204 template<typename T, template<typename U> class Descriptor>
00205 T MomentumExchangeBounceBack<T,Descriptor>::computeRhoBar(Cell<T,Descriptor> const& cell) const {
00206     return Descriptor<T>::rhoBar(rho);
00207 }
00208 
00209 template<typename T, template<typename U> class Descriptor>
00210 void MomentumExchangeBounceBack<T,Descriptor>::computeRhoBarJ (
00211         Cell<T,Descriptor> const& cell, T& rhoBar, Array<T,Descriptor<T>::d>& j) const
00212 {
00213     rhoBar = Descriptor<T>::rhoBar(rho);
00214     j.resetToZero();
00215 }
00216 
00217 template<typename T, template<typename U> class Descriptor>
00218 void MomentumExchangeBounceBack<T,Descriptor>::computeRhoBarJPiNeq (
00219         Cell<T,Descriptor> const& cell, T& rhoBar, Array<T,Descriptor<T>::d>& j,
00220         Array<T,SymmetricTensor<T,Descriptor>::n>& PiNeq ) const
00221 {
00222     rhoBar = Descriptor<T>::rhoBar(rho);
00223     j.resetToZero();
00224     PiNeq.resetToZero();
00225 }
00226 
00227 template<typename T, template<typename U> class Descriptor>
00228 T MomentumExchangeBounceBack<T,Descriptor>::computeEbar(Cell<T,Descriptor> const& cell) const
00229 {
00230     return T();
00231 }
00232 
00233 template<typename T, template<typename U> class Descriptor>
00234 plint MomentumExchangeBounceBack<T,Descriptor>::numDecomposedVariables(plint order) const {
00235     return Descriptor<T>::q + Descriptor<T>::ExternalField::numScalars;
00236 }
00237 
00238 template<typename T, template<typename U> class Descriptor>
00239 void MomentumExchangeBounceBack<T,Descriptor>::decompose (
00240         Cell<T,Descriptor> const& cell, std::vector<T>& rawData, plint order ) const
00241 {
00242     rawData.resize(numDecomposedVariables(order));
00243     std::fill(rawData.begin(), rawData.end(), T());
00244 }
00245 
00246 template<typename T, template<typename U> class Descriptor>
00247 void MomentumExchangeBounceBack<T,Descriptor>::recompose (
00248         Cell<T,Descriptor>& cell, std::vector<T> const& rawData, plint order ) const
00249 { }
00250 
00251 template<typename T, template<typename U> class Descriptor>
00252 void MomentumExchangeBounceBack<T,Descriptor>::rescale (
00253         std::vector<T>& rawData, T xDxInv, T xDt, plint order ) const
00254 { }
00255 
00256 template<typename T, template<typename U> class Descriptor>
00257 void MomentumExchangeBounceBack<T,Descriptor>::setFluidDirections (
00258         std::vector<plint> const& fluidDirections_ )
00259 {
00260     fluidDirections = fluidDirections_;
00261 }
00262 
00263 template<typename T, template<typename U> class Descriptor>
00264 std::vector<plint> const&  MomentumExchangeBounceBack<T,Descriptor>::getFluidDirections() const
00265 {
00266     return fluidDirections;
00267 }
00268 
00269 }  // namespace plb
00270 
00271 #endif  // BOUNCE_BACK_MODELS_HH