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

blockStatistics.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_STATISTICS_H
00029 #define BLOCK_STATISTICS_H
00030 
00031 #include "core/globalDefs.h"
00032 #include <vector>
00033 #include <algorithm>
00034 
00035 namespace plb {
00036 
00037 // Forward declaration
00038 
00039 class BlockStatistics;
00040 
00042 class TimeCounter {
00043 public:
00044     TimeCounter() : latticeTime(0) { }
00045     TimeCounter(plint iniTime) : latticeTime(iniTime) { }
00047     void incrementTime() { ++latticeTime; };
00049     void resetTime(pluint value=0) { latticeTime=value; } ;
00051     pluint getTime() const { return latticeTime; };
00052 private:
00053     plint latticeTime;
00054 };
00055 
00057 class StatSubscriber {
00058 public:
00059     virtual ~StatSubscriber() { }
00061     virtual plint subscribeAverage() =0;
00063     virtual plint subscribeSum() =0;
00065     virtual plint subscribeMax() =0;
00067     virtual plint subscribeIntSum() =0;
00068 };
00069 
00071 
00077 class BlockStatistics {
00078 public:
00079     BlockStatistics();
00080     BlockStatistics(BlockStatistics const& rhs);
00081     
00082     void swap(BlockStatistics& rhs);
00084     void evaluate();
00086     void evaluate(std::vector<double> const& average, std::vector<double> const& sum,
00087                   std::vector<double> const& max, std::vector<plint> const& intSum, pluint numCells_);
00089     void gatherAverage(plint whichAverage, double value);
00091     void gatherSum(plint whichSum, double value);
00093     void gatherMax(plint whichMax, double value);
00095     void gatherIntSum(plint whichSum, plint value);
00097     void incrementStats();
00099     pluint const& getNumCells() const { return numCells; }
00100 
00102     double getAverage(plint whichAverage) const;
00104     double getSum(plint whichSum) const;
00106     double getMax(plint whichMax) const;
00108     plint getIntSum(plint whichSum) const;
00109 
00111     std::vector<double>& getAverageVect() { return averageVect; }
00113     std::vector<double>& getSumVect() { return sumVect; }
00115     std::vector<double>& getMaxVect() { return maxVect; }
00117     std::vector<plint>& getIntSumVect() { return intSumVect; }
00119     std::vector<double> getDoubleVect() const;
00120 
00122     plint subscribeAverage();
00124     plint subscribeSum();
00126     plint subscribeMax();
00128     plint subscribeIntSum();
00130     void rescale(std::vector<double> const& scales);
00131 private:
00133     enum DoubleReductions {averageRed, sumRed, maxRed};
00135     std::vector<double> tmpAv, tmpSum, tmpMax;
00137     std::vector<plint> tmpIntSum;
00139     pluint tmpNumCells;
00141     std::vector<DoubleReductions> doubleReductions;
00143     std::vector<double> averageVect, sumVect, maxVect;
00145     std::vector<plint> intSumVect;
00147     pluint numCells;
00148 };
00149 
00150 void combine(std::vector<BlockStatistics*>& components, BlockStatistics& result);
00151 
00152 }  // namespace plb
00153 
00154 #endif