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

bounceBackModels3D.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 
00028 #ifndef BOUNCE_BACK_MODELS_3D_HH
00029 #define BOUNCE_BACK_MODELS_3D_HH
00030 
00031 #include "boundaryCondition/bounceBackModels3D.h"
00032 #include "atomicBlock/blockLattice3D.h"
00033 #include "core/cell.h"
00034 #include "atomicBlock/dataProcessorWrapper3D.h"
00035 #include <typeinfo>
00036 
00037 namespace plb {
00038 
00039 /* *************** Class InitializeMomentumExchangeFunctional3D ************* */
00040 
00041 template<typename T, template<typename U> class Descriptor>
00042 class InitializeMomentumExchangeFunctional3D : public BoxProcessingFunctional3D_L<T,Descriptor> {
00043 public:
00044     virtual void process(Box3D domain, BlockLattice3D<T,Descriptor>& lattice) {
00045         for (plint iX=domain.x0; iX<=domain.x1; ++iX) {
00046             for (plint iY=domain.y0; iY<=domain.y1; ++iY) {
00047                 for (plint iZ=domain.z0; iZ<=domain.z1; ++iZ) {
00048                     Dynamics<T,Descriptor>& dynamics = lattice.get(iX,iY,iZ).getDynamics();
00049                     if (typeid(dynamics) == typeid(MomentumExchangeBounceBack<T,Descriptor>&)) {
00050                         std::vector<plint> fluidDirections;
00051                         for (plint iPop=1; iPop<Descriptor<T>::q; ++iPop) {
00052                             plint nextX = iX + Descriptor<T>::c[iPop][0];
00053                             plint nextY = iY + Descriptor<T>::c[iPop][1];
00054                             plint nextZ = iZ + Descriptor<T>::c[iPop][2];
00055                             Dynamics<T,Descriptor>& partner = lattice.get(nextX,nextY,nextZ).getDynamics();
00056                             if ( typeid(partner) !=
00057                                  typeid(MomentumExchangeBounceBack<T,Descriptor>&) )
00058                             {
00059                                 fluidDirections.push_back(iPop);
00060                             }
00061                         }
00062 
00063                         if (!fluidDirections.empty()) {
00064                             MomentumExchangeBounceBack<T,Descriptor>& bounceBackDynamics =
00065                                 dynamic_cast<MomentumExchangeBounceBack<T,Descriptor>&>(dynamics);
00066                             bounceBackDynamics.setFluidDirections(fluidDirections);
00067                         }
00068                     }
00069                 }
00070             }
00071         }
00072     }
00073     virtual BlockDomain::DomainT appliesTo() const {
00074         // Apply only to bulk, because envelopes should not contribute
00075         //   to the statistics.
00076         return BlockDomain::bulk;
00077     }
00078     virtual void getTypeOfModification(std::vector<modif::ModifT>& modified) const {
00079         modified[0] = modif::staticVariables;
00080     }
00081     virtual InitializeMomentumExchangeFunctional3D<T,Descriptor>* clone() const 
00082     {
00083         return new InitializeMomentumExchangeFunctional3D<T,Descriptor>(*this);
00084     }
00085 };
00086 
00087 /* ************* Class MomentumExchangeComplexDomainFunctional3D ** */
00088 
00089 template<typename T, template<typename U> class Descriptor>
00090 class MomentumExchangeComplexDomainFunctional3D
00091     : public BoxProcessingFunctional3D_L<T,Descriptor>
00092 {
00093 public:
00094     MomentumExchangeComplexDomainFunctional3D( DomainFunctional3D* domain_ )
00095         : domain(domain_)
00096     { }
00097     MomentumExchangeComplexDomainFunctional3D (
00098             MomentumExchangeComplexDomainFunctional3D<T,Descriptor> const& rhs )
00099         : domain(rhs.domain->clone())
00100     { }
00101     MomentumExchangeComplexDomainFunctional3D<T,Descriptor>& operator= (
00102             MomentumExchangeComplexDomainFunctional3D<T,Descriptor> const& rhs )
00103     {
00104         delete domain; domain = rhs.domain->clone();
00105     }
00106 
00107     ~MomentumExchangeComplexDomainFunctional3D() {
00108         delete domain;
00109     }
00110     virtual void process(Box3D boundingBox, BlockLattice3D<T,Descriptor>& lattice) {
00111         Dot3D relativeOffset = lattice.getLocation();
00112         for (plint iX=boundingBox.x0; iX<=boundingBox.x1; ++iX) {
00113             for (plint iY=boundingBox.y0; iY<=boundingBox.y1; ++iY) {
00114                 for (plint iZ=boundingBox.z0; iZ<=boundingBox.z1; ++iZ) {
00115                     if ((*domain)(iX+relativeOffset.x,iY+relativeOffset.y,iZ+relativeOffset.z)) {
00116                         Dynamics<T,Descriptor>& dynamics = lattice.get(iX,iY,iZ).getDynamics();
00117                         if (typeid(dynamics) == typeid(MomentumExchangeBounceBack<T,Descriptor>&)) {
00118                             std::vector<plint> fluidDirections;
00119                             for (plint iPop=1; iPop<Descriptor<T>::q; ++iPop) {
00120                                 plint nextX = iX + Descriptor<T>::c[iPop][0];
00121                                 plint nextY = iY + Descriptor<T>::c[iPop][1];
00122                                 plint nextZ = iZ + Descriptor<T>::c[iPop][2];
00123                                 Dynamics<T,Descriptor>& partner = lattice.get(nextX,nextY,nextZ).getDynamics();
00124                                 if ( typeid(partner) !=
00125                                      typeid(MomentumExchangeBounceBack<T,Descriptor>&) )
00126                                 {
00127                                     fluidDirections.push_back(iPop);
00128                                 }
00129                             }
00130 
00131                             if (!fluidDirections.empty()) {
00132                                 MomentumExchangeBounceBack<T,Descriptor>& bounceBackDynamics =
00133                                     dynamic_cast<MomentumExchangeBounceBack<T,Descriptor>&>(dynamics);
00134                                 bounceBackDynamics.setFluidDirections(fluidDirections);
00135                             }
00136                         }
00137                     }
00138                 }
00139             }
00140         }
00141     }
00142     virtual BlockDomain::DomainT appliesTo() const {
00143         // Apply only to bulk, because envelopes should not contribute
00144         //   to the statistics.
00145         return BlockDomain::bulk;
00146     }
00147     virtual void getTypeOfModification(std::vector<modif::ModifT>& modified) const {
00148         modified[0] = modif::staticVariables;
00149     }
00150     virtual MomentumExchangeComplexDomainFunctional3D<T,Descriptor>* clone() const 
00151     {
00152         return new MomentumExchangeComplexDomainFunctional3D<T,Descriptor>(*this);
00153     }
00154 private:
00155     DomainFunctional3D* domain;
00156 };
00157 
00158 template<typename T, template<typename U> class Descriptor>
00159 class InitializeDotMomentumExchangeFunctional3D : public DotProcessingFunctional3D_L<T,Descriptor> {
00160 public:
00161     virtual void process(DotList3D const& dotList, BlockLattice3D<T,Descriptor>& lattice) {
00162         for (plint iDot=0; iDot<dotList.getN(); ++iDot) {
00163             Dot3D const& dot = dotList.getDot(iDot);
00164             plint iX = dot.x;
00165             plint iY = dot.y;
00166             plint iZ = dot.z;
00167             Dynamics<T,Descriptor>& dynamics = lattice.get(iX,iY,iZ).getDynamics();
00168             if (typeid(dynamics) == typeid(MomentumExchangeBounceBack<T,Descriptor>&)) {
00169                 std::vector<plint> fluidDirections;
00170                 for (plint iPop=1; iPop<Descriptor<T>::q; ++iPop) {
00171                     plint nextX = iX + Descriptor<T>::c[iPop][0];
00172                     plint nextY = iY + Descriptor<T>::c[iPop][1];
00173                     plint nextZ = iZ + Descriptor<T>::c[iPop][2];
00174                     Dynamics<T,Descriptor>& partner = lattice.get(nextX,nextY,nextZ).getDynamics();
00175                     if ( typeid(partner) !=
00176                          typeid(MomentumExchangeBounceBack<T,Descriptor>&) )
00177                     {
00178                         fluidDirections.push_back(iPop);
00179                     }
00180                 }
00181 
00182                 if (!fluidDirections.empty()) {
00183                     MomentumExchangeBounceBack<T,Descriptor>& bounceBackDynamics =
00184                         dynamic_cast<MomentumExchangeBounceBack<T,Descriptor>&>(dynamics);
00185                     bounceBackDynamics.setFluidDirections(fluidDirections);
00186                 }
00187             }
00188         }
00189     }
00190     virtual BlockDomain::DomainT appliesTo() const {
00191         // Apply only to bulk, because envelopes should not contribute
00192         //   to the statistics.
00193         return BlockDomain::bulk;
00194     }
00195     virtual void getTypeOfModification(std::vector<modif::ModifT>& modified) const {
00196         modified[0] = modif::staticVariables;
00197     }
00198     virtual InitializeDotMomentumExchangeFunctional3D<T,Descriptor>* clone() const 
00199     {
00200         return new InitializeDotMomentumExchangeFunctional3D<T,Descriptor>(*this);
00201     }
00202 };
00203 
00204 
00205 template<typename T, template<class U> class Descriptor>
00206 void initializeMomentumExchange (
00207         BlockLattice3D<T,Descriptor>& lattice, Box3D domain )
00208 {
00209     applyProcessingFunctional (
00210         new InitializeMomentumExchangeFunctional3D<T,Descriptor>(), domain, lattice );
00211 }
00212 
00213 template<typename T, template<class U> class Descriptor>
00214 void initializeMomentumExchange (
00215         BlockLattice3D<T,Descriptor>& lattice, Box3D boundingBox,
00216         DomainFunctional3D* domain )
00217 {
00218     applyProcessingFunctional (
00219             new MomentumExchangeComplexDomainFunctional3D<T,Descriptor>(domain), boundingBox, lattice );
00220 }
00221 
00222 template<typename T, template<class U> class Descriptor>
00223 void initializeMomentumExchange (
00224         BlockLattice3D<T,Descriptor>& lattice, DotList3D const& dotList )
00225 {
00226     applyProcessingFunctional (
00227         new InitializeDotMomentumExchangeFunctional3D<T,Descriptor>(), dotList, lattice );
00228 }
00229 
00230 
00231 template<typename T, template<class U> class Descriptor>
00232 void initializeMomentumExchange (
00233         MultiBlockLattice3D<T,Descriptor>& lattice, Box3D domain )
00234 {
00235     applyProcessingFunctional (
00236         new InitializeMomentumExchangeFunctional3D<T,Descriptor>(), domain, lattice );
00237 }
00238 
00239 template<typename T, template<class U> class Descriptor>
00240 void initializeMomentumExchange (
00241         MultiBlockLattice3D<T,Descriptor>& lattice, Box3D boundingBox,
00242         DomainFunctional3D* domain )
00243 {
00244     applyProcessingFunctional (
00245             new MomentumExchangeComplexDomainFunctional3D<T,Descriptor>(domain), boundingBox, lattice );
00246 }
00247 
00248 template<typename T, template<class U> class Descriptor>
00249 void initializeMomentumExchange (
00250         MultiBlockLattice3D<T,Descriptor>& lattice, DotList3D const& dotList )
00251 {
00252     applyProcessingFunctional (
00253         new InitializeDotMomentumExchangeFunctional3D<T,Descriptor>(), dotList, lattice );
00254 }
00255 
00256 }  // namespace plb
00257 
00258 #endif  // BOUNCE_BACK_MODELS_3D_H