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

regularizedBoundaryDynamics3D.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 REGULARIZED_BOUNDARY_DYNAMICS_3D_HH
00030 #define REGULARIZED_BOUNDARY_DYNAMICS_3D_HH
00031 
00032 #include "boundaryCondition/regularizedBoundaryDynamics3D.h"
00033 #include "core/cell.h"
00034 #include "latticeBoltzmann/indexTemplates.h"
00035 
00036 namespace plb {
00037 
00038 /* *************** Class RegularizedVelocityInnerEdgeDynamics3D ****** */
00039 
00040 template<typename T, template<typename U> class Descriptor,
00041          int plane, int normal1, int normal2>
00042 RegularizedVelocityInnerEdgeDynamics3D<T,Descriptor,plane,normal1,normal2>::
00043     RegularizedVelocityInnerEdgeDynamics3D(Dynamics<T,Descriptor>* baseDynamics_, bool automaticPrepareCollision_)
00044         : BoundaryCompositeDynamics<T,Descriptor>(baseDynamics_,automaticPrepareCollision_),
00045           dynamics1(baseDynamics_->clone()),
00046           dynamics2(baseDynamics_->clone())
00047           
00048 { }
00049 
00050 template<typename T, template<typename U> class Descriptor,
00051          int plane, int normal1, int normal2>
00052 RegularizedVelocityInnerEdgeDynamics3D<T,Descriptor,plane,normal1,normal2>*
00053     RegularizedVelocityInnerEdgeDynamics3D<T,Descriptor,plane,normal1,normal2>::clone() const
00054 {
00055     return new RegularizedVelocityInnerEdgeDynamics3D<T,Descriptor,plane,normal1,normal2>(*this);
00056 }
00057 
00058 template<typename T, template<typename U> class Descriptor,
00059          int plane, int normal1, int normal2>
00060 void RegularizedVelocityInnerEdgeDynamics3D<T,Descriptor,plane,normal1,normal2>::
00061         replaceBaseDynamics(Dynamics<T,Descriptor>* newBaseDynamics)
00062 {
00063     BoundaryCompositeDynamics<T,Descriptor>::replaceBaseDynamics(newBaseDynamics);
00064     dynamics1.replaceBaseDynamics(newBaseDynamics->clone());
00065     dynamics2.replaceBaseDynamics(newBaseDynamics->clone());
00066 }
00067 
00068 template<typename T, template<typename U> class Descriptor,
00069          int plane, int normal1, int normal2>
00070 void RegularizedVelocityInnerEdgeDynamics3D<T,Descriptor,plane,normal1,normal2>::
00071      computeVelocity(Cell<T,Descriptor> const& cell, Array<T,Descriptor<T>::d>& u_ ) const
00072 {
00073     dynamics1.computeVelocity(cell, u_);
00074 }
00075 
00076 template<typename T, template<typename U> class Descriptor,
00077          int plane, int normal1, int normal2>
00078 void RegularizedVelocityInnerEdgeDynamics3D<T,Descriptor,plane,normal1,normal2>::
00079      defineVelocity(Cell<T,Descriptor>& cell, Array<T,Descriptor<T>::d> const& u_ )
00080 {
00081     dynamics1.defineVelocity(cell, u_);
00082     dynamics2.defineVelocity(cell, u_);
00083 }
00084 
00085 template<typename T, template<typename U> class Descriptor,
00086          int plane, int normal1, int normal2>
00087 T RegularizedVelocityInnerEdgeDynamics3D<T,Descriptor,plane,normal1,normal2>::
00088      computeDensity(Cell<T,Descriptor> const& cell) const
00089 {
00090     return (dynamics1.computeDensity(cell) + dynamics2.computeDensity(cell) ) / (T)2;
00091 }
00092 
00093 template<typename T, template<typename U> class Descriptor,
00094          int plane, int normal1, int normal2>
00095 T RegularizedVelocityInnerEdgeDynamics3D<T,Descriptor,plane,normal1,normal2>::
00096      computeRhoBar(Cell<T,Descriptor> const& cell) const
00097 {
00098     return (dynamics1.computeRhoBar(cell) + dynamics2.computeRhoBar(cell) ) / (T)2;
00099 }
00100 
00101 template<typename T, template<typename U> class Descriptor,
00102          int plane, int normal1, int normal2>
00103 void RegularizedVelocityInnerEdgeDynamics3D<T,Descriptor,plane,normal1,normal2>::
00104      computeRhoBarJ(Cell<T,Descriptor> const& cell, T& rhoBar_, Array<T,Descriptor<T>::d>& j_ ) const
00105 {
00106     rhoBar_ = this->computeRhoBar(cell);
00107     T rho = Descriptor<T>::fullRho(rhoBar_);
00108     this -> computeVelocity(cell, j_);
00109     if (!this->velIsJ()) {
00110         for (int iD=0; iD<Descriptor<T>::d; ++iD) {
00111             j_[iD] *= rho;
00112         }
00113     }
00114 }
00115 
00116 template<typename T, template<typename U> class Descriptor,
00117          int plane, int normal1, int normal2>
00118 void RegularizedVelocityInnerEdgeDynamics3D<T,Descriptor,plane,normal1,normal2>::computeRhoBarJPiNeq (
00119         Cell<T,Descriptor> const& cell, T& rhoBar, Array<T,Descriptor<T>::d>& j,
00120         Array<T,SymmetricTensor<T,Descriptor>::n>& PiNeq ) const
00121 {
00122     T tmpRhoBar;
00123     Array<T,Descriptor<T>::d> tmpJ;
00124     Array<T,SymmetricTensor<T,Descriptor>::n> tmpPiNeq;
00125     dynamics1.computeRhoBarJPiNeq(cell, rhoBar, j, PiNeq);
00126     dynamics2.computeRhoBarJPiNeq(cell, tmpRhoBar, tmpJ, tmpPiNeq);
00127 
00128     rhoBar = (rhoBar+tmpRhoBar) / (T)2;
00129     for (int iD=0; iD<Descriptor<T>::d; ++iD) {
00130         j[iD] = (j[iD] + tmpJ[iD]) / (T)2;
00131     }
00132     for (int iPi=0; iPi<Descriptor<T>::d; ++iPi) {
00133         PiNeq[iPi] = (PiNeq[iPi] + tmpPiNeq[iPi]) / (T)2;
00134     }
00135 }
00136 
00137 template<typename T, template<typename U> class Descriptor,
00138          int plane, int normal1, int normal2>
00139 void RegularizedVelocityInnerEdgeDynamics3D<T,Descriptor,plane,normal1,normal2>::
00140      completePopulations(Cell<T,Descriptor>& cell) const
00141 {
00142     // 1. Assign "bounce-back of off-equilibrium" to the unknown population
00143     T rhoBar;
00144     Array<T,Descriptor<T>::d> j;
00145     this -> computeRhoBarJ(cell, rhoBar, j);
00146     T jSqr = VectorTemplate<T,Descriptor>::normSqr(j);
00147     for (plint iPop=0; iPop<Descriptor<T>::q; ++iPop) {
00148         if ( (Descriptor<T>::c[iPop][direction1] == -normal1) &&
00149              (Descriptor<T>::c[iPop][direction2] == -normal2) )
00150         {
00151             plint opp = indexTemplates::opposite<Descriptor<T> >(iPop);
00152             cell[iPop] = cell[opp]
00153                 - this->computeEquilibrium(opp, rhoBar, j, jSqr)
00154                 + this->computeEquilibrium(iPop, rhoBar, j, jSqr);
00155         }
00156     }
00157 
00158     // 2. Regularize all populations
00159     Array<T,SymmetricTensor<T,Descriptor>::n> PiNeq;
00160     this -> getBaseDynamics().computeDeviatoricStress(cell, PiNeq);;
00161     this -> getBaseDynamics().regularize(cell, rhoBar, j, jSqr, PiNeq);
00162 }
00163 
00164 
00165 /* *************** Class RegularizedVelocityInnerCornerDynamics3D ****** */
00166 
00167 template<typename T, template<typename U> class Descriptor,
00168          int normalX, int normalY, int normalZ>
00169 RegularizedVelocityInnerCornerDynamics3D<T,Descriptor,normalX,normalY,normalZ>::
00170     RegularizedVelocityInnerCornerDynamics3D(Dynamics<T,Descriptor>* baseDynamics_, bool automaticPrepareCollision_)
00171         : BoundaryCompositeDynamics<T,Descriptor>(baseDynamics_,automaticPrepareCollision_),
00172           xDynamics(baseDynamics_->clone()),
00173           yDynamics(baseDynamics_->clone()),
00174           zDynamics(baseDynamics_->clone())
00175           
00176 { }
00177 
00178 template<typename T, template<typename U> class Descriptor,
00179          int normalX, int normalY, int normalZ>
00180 RegularizedVelocityInnerCornerDynamics3D<T,Descriptor,normalX,normalY,normalZ>*
00181     RegularizedVelocityInnerCornerDynamics3D<T,Descriptor,normalX,normalY,normalZ>::clone() const
00182 {
00183     return new RegularizedVelocityInnerCornerDynamics3D<T,Descriptor,normalX,normalY,normalZ>(*this);
00184 }
00185 
00186 template<typename T, template<typename U> class Descriptor,
00187          int normalX, int normalY, int normalZ>
00188 void RegularizedVelocityInnerCornerDynamics3D<T,Descriptor,normalX,normalY,normalZ>::
00189     replaceBaseDynamics(Dynamics<T,Descriptor>* newBaseDynamics)
00190 {
00191     BoundaryCompositeDynamics<T,Descriptor>::replaceBaseDynamics(newBaseDynamics);
00192     xDynamics.replaceBaseDynamics(newBaseDynamics->clone());
00193     yDynamics.replaceBaseDynamics(newBaseDynamics->clone());
00194     zDynamics.replaceBaseDynamics(newBaseDynamics->clone());
00195 }
00196 
00197 template<typename T, template<typename U> class Descriptor,
00198          int normalX, int normalY, int normalZ>
00199 void RegularizedVelocityInnerCornerDynamics3D<T,Descriptor,normalX,normalY,normalZ>::
00200      computeVelocity(Cell<T,Descriptor> const& cell, Array<T,Descriptor<T>::d>& u_ ) const
00201 {
00202     xDynamics.computeVelocity(cell, u_);
00203 }
00204 
00205 template<typename T, template<typename U> class Descriptor,
00206          int normalX, int normalY, int normalZ>
00207 void RegularizedVelocityInnerCornerDynamics3D<T,Descriptor,normalX,normalY,normalZ>::
00208      defineVelocity(Cell<T,Descriptor>& cell, Array<T,Descriptor<T>::d> const& u_ )
00209 {
00210     xDynamics.defineVelocity(cell, u_);
00211     yDynamics.defineVelocity(cell, u_);
00212     zDynamics.defineVelocity(cell, u_);
00213 }
00214 
00215 template<typename T, template<typename U> class Descriptor,
00216          int normalX, int normalY, int normalZ>
00217 T RegularizedVelocityInnerCornerDynamics3D<T,Descriptor,normalX,normalY,normalZ>::
00218      computeDensity(Cell<T,Descriptor> const& cell) const
00219 {
00220     return (xDynamics.computeDensity(cell) +
00221             yDynamics.computeDensity(cell) +
00222             zDynamics.computeDensity(cell)) / (T)3;
00223 }
00224 
00225 template<typename T, template<typename U> class Descriptor,
00226          int normalX, int normalY, int normalZ>
00227 T RegularizedVelocityInnerCornerDynamics3D<T,Descriptor,normalX,normalY,normalZ>::
00228      computeRhoBar(Cell<T,Descriptor> const& cell) const
00229 {
00230     return (xDynamics.computeRhoBar(cell) +
00231             yDynamics.computeRhoBar(cell) +
00232             zDynamics.computeRhoBar(cell)) / (T)3;
00233 }
00234 
00235 template<typename T, template<typename U> class Descriptor,
00236          int normalX, int normalY, int normalZ>
00237 void RegularizedVelocityInnerCornerDynamics3D<T,Descriptor,normalX,normalY,normalZ>::
00238      computeRhoBarJ(Cell<T,Descriptor> const& cell, T& rhoBar_, Array<T,Descriptor<T>::d>& j_ ) const
00239 {
00240     rhoBar_ = this->computeRhoBar(cell);
00241     T rho = Descriptor<T>::fullRho(rhoBar_);
00242     this -> computeVelocity(cell, j_);
00243     if (!this->velIsJ()) {
00244         for (int iD=0; iD<Descriptor<T>::d; ++iD) {
00245             j_[iD] *= rho;
00246         }
00247     }
00248 }
00249 
00250 template<typename T, template<typename U> class Descriptor,
00251          int normalX, int normalY, int normalZ>
00252 void RegularizedVelocityInnerCornerDynamics3D<T,Descriptor,normalX,normalY,normalZ>::computeRhoBarJPiNeq (
00253         Cell<T,Descriptor> const& cell, T& rhoBar, Array<T,Descriptor<T>::d>& j,
00254         Array<T,SymmetricTensor<T,Descriptor>::n>& PiNeq ) const
00255 {
00256     T rhoBar2, rhoBar3;
00257     Array<T,Descriptor<T>::d> j2, j3;
00258     Array<T,SymmetricTensor<T,Descriptor>::n> PiNeq2, PiNeq3;
00259 
00260     xDynamics.computeRhoBarJPiNeq(cell, rhoBar, j, PiNeq);
00261     yDynamics.computeRhoBarJPiNeq(cell, rhoBar2, j2, PiNeq2);
00262     zDynamics.computeRhoBarJPiNeq(cell, rhoBar3, j3, PiNeq3);
00263 
00264     rhoBar = (rhoBar+rhoBar2+rhoBar3) / (T)3;
00265     for (int iD=0; iD<Descriptor<T>::d; ++iD) {
00266         j[iD] = (j[iD] + j2[iD] + j3[iD]) / (T)3;
00267     }
00268     for (int iPi=0; iPi<Descriptor<T>::d; ++iPi) {
00269         PiNeq[iPi] = (PiNeq[iPi] + PiNeq2[iPi] + PiNeq3[iPi]) / (T)3;
00270     }
00271 }
00272 
00273 template<typename T, template<typename U> class Descriptor,
00274          int normalX, int normalY, int normalZ>
00275 void RegularizedVelocityInnerCornerDynamics3D<T,Descriptor,normalX,normalY,normalZ>::
00276      completePopulations(Cell<T,Descriptor>& cell) const
00277 {
00278     // 1. Assign "bounce-back of off-equilibrium" to the unknown population
00279     Array<int,Descriptor<T>::d> v ( -normalX, -normalY, -normalZ );
00280     plint unknownF  = indexTemplates::findVelocity<Descriptor<T> >(v);
00281 
00282     T rhoBar;
00283     Array<T,Descriptor<T>::d> j;
00284     this -> computeRhoBarJ(cell, rhoBar, j);
00285     T jSqr = VectorTemplate<T,Descriptor>::normSqr(j);
00286 
00287     // Do nothing if there is no unknown population
00288     if (unknownF != Descriptor<T>::q) {
00289         plint oppositeF = indexTemplates::opposite<Descriptor<T> >(unknownF);
00290         cell[unknownF] = cell[oppositeF]
00291                              - this->computeEquilibrium(oppositeF, rhoBar, j, jSqr)
00292                              + this->computeEquilibrium(unknownF, rhoBar, j, jSqr);
00293     }
00294     // 2. Regularize all populations
00295     Array<T,SymmetricTensor<T,Descriptor>::n> PiNeq;
00296     this -> getBaseDynamics().computeDeviatoricStress(cell, PiNeq);;
00297     this -> getBaseDynamics().regularize(cell, rhoBar, j, jSqr, PiNeq);
00298 }
00299 
00300 }
00301 
00302 // namespace plb
00303 
00304 #endif  // REGULARIZED_BOUNDARY_DYNAMICS_3D_HH