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

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