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

sparseBlockStructure2D.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 
00029 #ifndef SPARSE_BLOCK_STRUCTURE_2D_H
00030 #define SPARSE_BLOCK_STRUCTURE_2D_H
00031 
00032 #include "core/globalDefs.h"
00033 #include "core/geometry2D.h"
00034 #include "multiBlock/threadAttribution.h"
00035 #include <vector>
00036 #include <map>
00037 
00038 
00039 namespace plb {
00040 
00041 class SparseBlockStructure2D {
00042 public:
00043     typedef std::map<Dot2D, std::vector<plint> > GridT;
00044 public:
00046     SparseBlockStructure2D(plint nx, plint ny);
00048     SparseBlockStructure2D(Box2D boundingBox_);
00050     SparseBlockStructure2D(Box2D boundingBox_,
00051                            plint gridNx_, plint gridNy_);
00053     SparseBlockStructure2D(SparseBlockStructure2D const& rhs, Box2D boundingBox_);
00055     void addBlock(Box2D const& bulk, Box2D const& uniqueBulk, plint blockId);
00057     void addBlock(Box2D const& bulk, plint blockId);
00059     void removeBlock(plint blockId);
00061     bool exists(plint blockId);
00063     plint nextIncrementalId() const;
00065     Box2D getBoundingBox() const;
00067     bool getBulk(plint blockId, Box2D& bulk) const;
00069     bool getUniqueBulk(plint blockId, Box2D& uniqueBulk) const;
00071     plint getNumBlocks() const;
00073     plint getNumBulkCells() const;
00075     std::map<plint,Box2D> const& getBulks() const;
00077     std::vector<plint> getLocalBlocks(ThreadAttribution const& attribution) const;
00079     plint locate(plint iX, plint iY) const;
00081     void intersect( Box2D const& bulk, std::vector<plint>& ids,
00082                     std::vector<Box2D>& intersections ) const;
00085     void computeOverlaps( Box2D const& bulk, plint dx, plint dy,
00086                           std::vector<plint>& ids,
00087                           std::vector<Box2D>& overlapsOnBulk,
00088                           std::vector<Box2D>& overlapsOnNeighbors ) const;
00090     void computeOverlaps( plint blockId, plint envelopeWidth,
00091                           std::vector<plint>& ids,
00092                           std::vector<Box2D>& overlapsOnBulk,
00093                           std::vector<Box2D>& overlapsOnNeighbors ) const;
00096     void findNeighbors( Box2D const& block, plint neighborhoodWidth,
00097                         std::vector<plint>& neighbors,
00098                         plint excludeId=-1 ) const;
00100     void findNeighbors( plint blockId, plint neighborhoodWidth,
00101                         std::vector<plint>& neighbors ) const;
00102     void swap(SparseBlockStructure2D& rhs);
00103 private:
00105     void defaultGridN();
00107     void iniGridParameters();
00109     plint gridPosX(plint realX) const;
00111     plint gridPosY(plint realY) const;
00113     Box2D getGridBox(Box2D const& realBlock) const;
00116     void computeEnvelopeTerm (
00117         plint block0, plint block1,
00118         plint& env0, plint& env1, plint delta ) const;
00120     void integrateBlock(plint blockId, Box2D bulk);
00122     void extractBlock(plint blockId);
00123 private:
00124     Box2D boundingBox;
00125     plint gridLx, gridLy;
00126     plint gridNx, gridNy;
00127     GridT grid;
00128     // Attention: If replacing the map by a hashed_map, remember that
00129     // nextIncrementalId() uses the fact that elements are ordered inside
00130     // the map. Therefore, nextIncrementalId() must then be rewritten.
00131     std::map<plint,Box2D> bulks;
00134     std::map<plint,Box2D> uniqueBulks;
00135 };
00136 
00140 SparseBlockStructure2D intersect( SparseBlockStructure2D const& sparseBlock,
00141                                   Box2D domain, bool crop );
00142 
00144 SparseBlockStructure2D intersect( SparseBlockStructure2D const& sparseBlock,
00145                                   Box2D domain, Box2D newBoundingBox );
00146 
00149 SparseBlockStructure2D intersect( SparseBlockStructure2D const& sparseBlock1,
00150                                   SparseBlockStructure2D const& sparseBlock2, bool crop );
00151 
00153 SparseBlockStructure2D block_union( SparseBlockStructure2D const& sparseBlock1,
00154                                     SparseBlockStructure2D const& sparseBlock2,
00155                                     std::map<plint,std::vector<plint> >& remappedIds);
00156 
00161 SparseBlockStructure2D extend( SparseBlockStructure2D const& sparseBlock,
00162                                Box2D addedBulk, Box2D addedUniqueBulk,
00163                                std::vector<plint>& newIds );
00164 
00166 SparseBlockStructure2D except( SparseBlockStructure2D const& sparseBlock,
00167                                Box2D exceptedBlock,
00168                                std::map<plint,std::vector<plint> >& remappedIds );
00169 
00177 SparseBlockStructure2D alignDistribution2D (
00178                            SparseBlockStructure2D const& originalStructure,
00179                            SparseBlockStructure2D const& partnerStructure,
00180                            std::vector<plint>& newIds,
00181                            std::map<plint,std::vector<plint> >& remappedFromPartner );
00182 
00183 
00184 
00186 class EuclideanIterator2D {
00187 public:
00188     EuclideanIterator2D(SparseBlockStructure2D const& sparseBlock_);
00192     bool getNextChunkX(plint iX, plint iY,
00193                        plint& blockId, plint& chunkSize) const;
00197     bool getNextChunkY(plint iX, plint iY,
00198                        plint& blockId, plint& chunkSize) const;
00199 private:
00200     SparseBlockStructure2D const& sparseBlock;
00201 };
00202 
00203 }  // namespace plb
00204 
00205 #endif  // SPARSE_BLOCK_STRUCTURE_2D_H