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

multiGrid2D.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 
00025 /* Main author: Daniel Lagrava
00026  **/
00027 
00028 #ifndef MULTI_GRID_2D_H
00029 #define MULTI_GRID_2D_H
00030 
00031 #include "core/globalDefs.h"
00032 #include "core/geometry2D.h"
00033 #include "core/array.h"
00034 #include "multiBlock/multiBlock2D.h"
00035 #include "multiBlock/multiBlockManagement2D.h"
00036 #include "multiBlock/blockCommunicator2D.h"
00037 #include "multiBlock/combinedStatistics.h"
00038 #include "core/block2D.h"
00039 #include "core/blockStatistics.h"
00040 #include "multiGrid/multiScale.h"
00041 #include "multiGrid/multiGridManagement2D.h"
00042 
00043 
00044 namespace plb {
00045   
00046 class MultiGrid2D;
00047 
00049 class MultiGridPeriodicitySwitch2D {
00050   public:
00051     MultiGridPeriodicitySwitch2D(MultiGrid2D *block_);
00052     MultiGridPeriodicitySwitch2D(MultiGridPeriodicitySwitch2D const& rhs);
00053     MultiGridPeriodicitySwitch2D& operator=(MultiGridPeriodicitySwitch2D const& rhs);
00054     void swap(MultiGridPeriodicitySwitch2D& rhs);
00055     
00056     void toggle(int direction, bool periodicity);
00057     void toggleAll(bool periodicity);
00058  
00059     Array<bool,2> const& getPeriodicityArray() const;
00060     
00061   private:
00062     MultiGrid2D* block;
00063     Array<bool,2> periodicityArray;
00064     
00065 };
00066 
00068 
00072 class MultiGridStatSubscriber2D {
00073 public:
00074     MultiGridStatSubscriber2D(MultiGrid2D* multiGrid_);
00075     MultiGridStatSubscriber2D(MultiGridStatSubscriber2D const& rhs);
00076         
00077     void swap(MultiGridStatSubscriber2D& rhs);
00078     MultiGridStatSubscriber2D& operator=(MultiGridStatSubscriber2D const& rhs);
00079     
00081     plint subscribeAverage(plint dimDx, plint dimDt);
00083     plint subscribeSum(plint dimDx, plint dimDt);
00085     plint subscribeMax(plint dimDx, plint dimDt);
00087     plint subscribeIntSum(plint dimDx, plint dimDt);
00089     void initialize();    
00090     
00092     std::vector<int> const& getDimensionsX() const;
00093     std::vector<int> const& getDimensionsT() const;
00094     
00095 private:
00096     MultiGrid2D* multiGrid;
00097     std::vector<int> dimensionsX;
00098     std::vector<int> dimensionsT;
00099 };
00100 
00101   
00103 class MultiGrid2D : public Block2D
00104 {
00105   public:
00106     MultiGrid2D( MultiGridManagement2D management, 
00107                  plint behaviorLevel_);
00108     // Copy constructor
00109     MultiGrid2D(const MultiGrid2D& rhs);
00110     MultiGrid2D(MultiGrid2D const& rhs, Box2D subDomain, bool crop);
00111     virtual ~MultiGrid2D();
00112     
00113     void swap(MultiGrid2D& rhs);
00114     
00116     virtual MultiBlock2D const& getComponent(plint level) const =0;
00117     virtual MultiBlock2D& getComponent(plint level)             =0;
00118     
00119     MultiGridManagement2D const& getMultiGridManagement() const;
00120     MultiGridManagement2D& getMultiGridManagement();
00121      
00123     plint getNx() const;
00124     plint getNy() const;
00125     
00127     virtual Box2D getBoundingBox() const;
00128     
00130     plint getReferenceLevel() const;
00131     plint getNumLevels() const;
00132     plint getBehaviorLevel() const;
00133     void setBehaviorLevel(plint behaviorLevel_);
00134     
00136     virtual void initialize();
00137     
00139     void executeInternalProcessors();
00140     void executeInternalProcessors(plint level);   
00141 
00143     void subscribeProcessor(plint level);
00144     
00146     BlockStatistics& getInternalStatistics();
00147     BlockStatistics const& getInternalStatistics() const;
00148     
00150     void reduceStatistics();
00151     void evaluateStatistics();
00152     void toggleInternalStatistics(bool statisticsOn_);
00153     bool isInternalStatisticsOn() const;
00154     
00156     MultiGridPeriodicitySwitch2D const& periodicity() const;
00158     MultiGridPeriodicitySwitch2D& periodicity();
00159     void signalPeriodicity();
00160     
00162     MultiGridStatSubscriber2D& internalStatSubscription();
00163     
00165     MultiScaleManager const& getScaleManager() const;
00166 
00167     virtual DataSerializer* getBlockSerializer (
00168             Box2D const& domain, IndexOrdering::OrderingT ordering ) const;
00169     virtual DataUnSerializer* getBlockUnSerializer (
00170             Box2D const& domain, IndexOrdering::OrderingT ordering );
00171 
00172     virtual int getBlockId () const =0;
00173 
00174   private:
00175     // reference level management
00176     MultiGridManagement2D management; 
00177 
00178     plint behaviorLevel;
00179     MultiGridPeriodicitySwitch2D periodicitySwitch;
00180 
00181     plint maxProcessorLevel;
00182     bool statisticsOn;
00183     
00184     MultiGridStatSubscriber2D statsSubscriber;
00185     BlockStatistics internalStatistics;
00186     
00187     // Used to easen the scale conversion in this class
00188     MultiScaleManager *scaleManager; 
00189 };
00190 
00191 // checkpointing for the multiGrid
00192 void saveBinaryGrid(MultiGrid2D const& block, std::string fName, bool enforceUint=false);
00193 void loadBinaryGrid(MultiGrid2D& block, std::string fName, bool enforceUint=false);
00194 
00195 
00196 } // namespace plb
00197 
00198 #endif  // MULTI_GRID_2D_H