Palabos  Version 1.0
blockLattice2D.h
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 BLOCK_LATTICE_2D_H
00029 #define BLOCK_LATTICE_2D_H
00030 
00031 #include "core/globalDefs.h"
00032 #include "core/plbDebug.h"
00033 #include "core/cell.h"
00034 #include "atomicBlock/dataField2D.h"
00035 #include "core/blockLatticeBase2D.h"
00036 #include "atomicBlock/atomicBlock2D.h"
00037 #include "core/blockIdentifiers.h"
00038 #include <vector>
00039 #include <map>
00040 
00041 
00042 namespace plb {
00043 
00044 template<typename T, template<typename U> class Descriptor> struct Dynamics;
00045 template<typename T, template<typename U> class Descriptor> class BlockLattice2D;
00046 
00047 
00048 template<typename T, template<typename U> class Descriptor>
00049 class BlockLatticeDataTransfer2D : public BlockDataTransfer2D {
00050 public:
00051     BlockLatticeDataTransfer2D(BlockLattice2D<T,Descriptor>& lattice_);
00052     virtual plint staticCellSize() const;
00054     virtual void send(Box2D domain, std::vector<char>& buffer, modif::ModifT kind) const;
00056     virtual void receive(Box2D domain, std::vector<char> const& buffer, modif::ModifT kind);
00058     virtual void receive( Box2D domain, std::vector<char> const& buffer,
00059                           modif::ModifT kind, std::map<int,std::string> const& foreignIds );
00061     virtual void attribute(Box2D toDomain, plint deltaX, plint deltaY,
00062                            AtomicBlock2D const& from, modif::ModifT kind);
00063 private:
00064     void send_static(Box2D domain, std::vector<char>& buffer) const;
00065     void send_dynamic(Box2D domain, std::vector<char>& buffer) const;
00066     void send_all(Box2D domain, std::vector<char>& buffer) const;
00067 
00068     void receive_static(Box2D domain, std::vector<char> const& buffer);
00069     void receive_dynamic(Box2D domain, std::vector<char> const& buffer);
00070     void receive_all(Box2D domain, std::vector<char> const& buffer);
00071     void receive_regenerate(Box2D domain, std::vector<char> const& buffer,
00072                             std::map<int,int> const& idIndirect = (std::map<int,int>()) );
00073 
00074     void attribute_static (
00075         Box2D toDomain, plint deltaX, plint deltaY,
00076         BlockLattice2D<T,Descriptor> const& from );
00077     void attribute_dynamic (
00078         Box2D toDomain, plint deltaX, plint deltaY,
00079         BlockLattice2D<T,Descriptor> const& from );
00080     void attribute_all (
00081         Box2D toDomain, plint deltaX, plint deltaY,
00082         BlockLattice2D<T,Descriptor> const& from );
00083     void attribute_regenerate (
00084         Box2D toDomain, plint deltaX, plint deltaY,
00085         BlockLattice2D<T,Descriptor> const& from );
00086 private:
00087     BlockLattice2D<T,Descriptor>& lattice;
00088 };
00089 
00090 
00096 template<typename T, template<typename U> class Descriptor>
00097 class BlockLattice2D : public BlockLatticeBase2D<T,Descriptor>,
00098                        public AtomicBlock2D
00099 {
00100 public:
00102     BlockLattice2D(plint nx_, plint ny_, Dynamics<T,Descriptor>* backgroundDynamics);
00104     ~BlockLattice2D();
00106     BlockLattice2D(BlockLattice2D<T,Descriptor> const& rhs);
00108     BlockLattice2D& operator=(BlockLattice2D<T,Descriptor> const& rhs);
00110     void swap(BlockLattice2D& rhs);
00111 public:
00113     virtual Cell<T,Descriptor>& get(plint iX, plint iY) {
00114         PLB_PRECONDITION(iX<this->getNx());
00115         PLB_PRECONDITION(iY<this->getNy());
00116         return grid[iX][iY];
00117     }
00119     virtual Cell<T,Descriptor> const& get(plint iX, plint iY) const {
00120         PLB_PRECONDITION(iX<this->getNx());
00121         PLB_PRECONDITION(iY<this->getNy());
00122         return grid[iX][iY];
00123     }
00125     virtual void specifyStatisticsStatus(Box2D domain, bool status);
00127     virtual void collide(Box2D domain);
00129     virtual void collide();
00131     virtual void stream(Box2D domain);
00133     virtual void stream();
00135     virtual void collideAndStream(Box2D domain);
00137     virtual void collideAndStream();
00139     virtual void incrementTime();
00141     virtual BlockLatticeDataTransfer2D<T,Descriptor>& getDataTransfer();
00143     virtual BlockLatticeDataTransfer2D<T,Descriptor> const& getDataTransfer() const;
00144 public:
00146     void attributeDynamics(plint iX, plint iY, Dynamics<T,Descriptor>* dynamics);
00148     Dynamics<T,Descriptor>& getBackgroundDynamics();
00150     Dynamics<T,Descriptor> const& getBackgroundDynamics() const;
00152     void bulkStream(Box2D domain);
00154     void boundaryStream(Box2D bound, Box2D domain);
00156     void bulkCollideAndStream(Box2D domain);
00157 private:
00159     void linearBulkCollideAndStream(Box2D domain);
00162     void blockwiseBulkCollideAndStream(Box2D domain);
00163 private:
00165     void allocateAndInitialize();
00167     void releaseMemory();
00168     void implementPeriodicity();
00169 private:
00170     void periodicDomain(Box2D domain);
00171 private:
00172     Dynamics<T,Descriptor>* backgroundDynamics;
00173     Cell<T,Descriptor>     *rawData;
00174     Cell<T,Descriptor>    **grid;
00175     BlockLatticeDataTransfer2D<T,Descriptor> dataTransfer;
00176 public:
00177     static CachePolicy2D& cachePolicy();
00178 template<typename T_, template<typename U_> class Descriptor_>
00179     friend class ExternalRhoJcollideAndStream2D;
00180 };
00181 
00182 template<typename T, template<typename U> class Descriptor>
00183 double getStoredAverageDensity(BlockLattice2D<T,Descriptor> const& blockLattice);
00184 
00185 template<typename T, template<typename U> class Descriptor>
00186 double getStoredAverageEnergy(BlockLattice2D<T,Descriptor> const& blockLattice);
00187 
00188 template<typename T, template<typename U> class Descriptor>
00189 double getStoredAverageVelocity(BlockLattice2D<T,Descriptor> const& blockLattice);
00190 
00191 }  // namespace plb
00192 
00193 #endif  // BLOCK_LATTICE_2D_H