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

multiBlockSerializer2D.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 MULTI_BLOCK_SERIALIZER_2D_H
00029 #define MULTI_BLOCK_SERIALIZER_2D_H
00030 
00031 #include "core/globalDefs.h"
00032 #include "multiBlock/multiBlock2D.h"
00033 #include "core/serializer.h"
00034 #include "core/util.h"
00035 
00036 namespace plb {
00037 
00038 class MultiBlockSerializer2D : public DataSerializer {
00039 public:
00040     MultiBlockSerializer2D(MultiBlock2D const& multiBlock_,
00041                            IndexOrdering::OrderingT ordering_);
00042     MultiBlockSerializer2D(MultiBlock2D const& multiBlock_,
00043                            Box2D domain_,
00044                            IndexOrdering::OrderingT ordering_);
00045     virtual MultiBlockSerializer2D* clone() const;
00046     virtual pluint getSize() const;
00047     virtual const char* getNextDataBuffer(pluint& bufferSize) const;
00048     virtual bool isEmpty() const;
00049 private:
00050     SparseBlockStructure2D const& getSparseBlockStructure() const;
00051     bool isLocal(plint blockId) const;
00052     void computeBufferAlongX(plint nextBlockId, plint nextChunkSize) const;
00053     void computeBufferAlongY(plint nextBlockId, plint nextChunkSize) const;
00054     void communicateBuffer(plint bufferSize, plint fromBlockId, bool isAllocated) const;
00055     void fillBufferWithZeros(plint nextChunkSize) const;
00056 private:
00057     MultiBlock2D const& multiBlock;
00058     IndexOrdering::OrderingT ordering;
00059     Box2D domain;
00060     mutable plint iX, iY;
00061     mutable std::vector<char> buffer;
00062 };
00063 
00064 class MultiBlockUnSerializer2D : public DataUnSerializer {
00065 public:
00066     MultiBlockUnSerializer2D(MultiBlock2D& multiBlock_,
00067                              IndexOrdering::OrderingT ordering_);
00068     MultiBlockUnSerializer2D(MultiBlock2D& multiBlock_,
00069                              Box2D domain_,
00070                              IndexOrdering::OrderingT ordering_);
00071     virtual MultiBlockUnSerializer2D* clone() const;
00072     virtual pluint getSize() const;
00073     virtual char* getNextDataBuffer(pluint& bufferSize);
00074     virtual void commitData();
00075     virtual bool isFull() const;
00076 private:
00077     SparseBlockStructure2D const& getSparseBlockStructure() const;
00078     bool isLocal(plint blockId) const;
00079     void fillBufferAlongX(plint nextBlockId, plint nextChunkSize);
00080     void fillBufferAlongY(plint nextBlockId, plint nextChunkSize);
00081     void communicateBuffer(plint bufferSize, plint toBlockId, bool isAllocated) const;
00082 private:
00083     MultiBlock2D& multiBlock;
00084     IndexOrdering::OrderingT ordering;
00085     Box2D domain;
00086     mutable plint iX, iY;
00087     mutable std::vector<char> buffer;
00088 };
00089 
00090 class MultiBlockFastSerializer2D : public DataSerializer {
00091 public:
00092     MultiBlockFastSerializer2D(MultiBlock2D const& multiBlock_,
00093                                IndexOrdering::OrderingT ordering_);
00094     MultiBlockFastSerializer2D(MultiBlock2D const& multiBlock_,
00095                                Box2D domain_,
00096                                IndexOrdering::OrderingT ordering_);
00097     virtual MultiBlockFastSerializer2D* clone() const;
00098     virtual pluint getSize() const;
00099     virtual const char* getNextDataBuffer(pluint& bufferSize) const;
00100     virtual bool isEmpty() const;
00101 private:
00102     pluint computeSlice() const;
00103 private:
00104     MultiBlock2D const& multiBlock;
00105     IndexOrdering::OrderingT ordering;
00106     Box2D domain;
00107     mutable plint pos;
00108     mutable std::vector<char> buffer;
00109 };
00110 
00111 class MultiBlockFastUnSerializer2D : public DataUnSerializer {
00112 public:
00113     MultiBlockFastUnSerializer2D(MultiBlock2D& multiBlock_,
00114                                  IndexOrdering::OrderingT ordering_);
00115     MultiBlockFastUnSerializer2D(MultiBlock2D& multiBlock_,
00116                                  Box2D domain_,
00117                                  IndexOrdering::OrderingT ordering_);
00118     virtual MultiBlockFastUnSerializer2D* clone() const;
00119     virtual pluint getSize() const;
00120     virtual char* getNextDataBuffer(pluint& bufferSize);
00121     virtual void commitData();
00122     virtual bool isFull() const;
00123 private:
00124     MultiBlock2D& multiBlock;
00125     IndexOrdering::OrderingT ordering;
00126     Box2D domain;
00127     mutable plint pos;
00128     mutable std::vector<char> buffer;
00129 };
00130 }  //  namespace plb
00131 
00132 #endif  // MULTI_BLOCK_SERIALIZER_2D_H