/* This file is part of the OpenLB library
*
* Copyright (C) 2006, 2007, 2008 Jonas Latt
* E-mail contact: info@openlb.net
* The most recent release of OpenLB can be downloaded at
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef LATTICE_STATISTICS_HH
#define LATTICE_STATISTICS_HH
#include "blockLattice2D.h"
#include "blockLattice3D.h"
#include "latticeStatistics.h"
#include
#include
#include
#include "util.h"
namespace olb {
////////////////////// Class LatticeStatistics /////////////////
template
LatticeStatistics::LatticeStatistics() : clout(std::cout,"LatticeStatistics")
{
initialize();
}
template
LatticeStatistics::~LatticeStatistics()
{
}
template
void LatticeStatistics::reset()
{
// avoid division by zero
if (tmpNumCells == 0) {
for (unsigned iVect=0; iVect::max();
}
for (unsigned iVect=0; iVect::min();
}
tmpNumCells = 0;
}
template
void LatticeStatistics::reset (
T average_rho_, T average_energy_, T maxU_, size_t numCells_ )
{
averageVect[avRho] = average_rho_;
averageVect[avEnergy] = average_energy_;
maxVect[maxU] = maxU_;
numCells = numCells_;
tmpAv[avRho] = T();
tmpAv[avEnergy] = T();
tmpMax[maxU] = T();
tmpNumCells = 0;
}
template
void LatticeStatistics::initialize()
{
tmpAv.resize(2);
averageVect.resize(2);
tmpMax.resize(1);
maxVect.resize(1);
tmpAv[avRho] = T();
tmpAv[avEnergy] = T();
tmpMax[maxU] = T();
tmpNumCells = 0;
averageVect[avRho] = (T)1;
averageVect[avEnergy] = T();
maxVect[maxU] = T();
firstCall = true;
resetTime();
}
template
int LatticeStatistics::subscribeAverage()
{
int newSize = tmpAv.size()+1;
tmpAv.resize(newSize);
averageVect.resize(newSize);
return newSize-1;
}
template
int LatticeStatistics::subscribeSum()
{
int newSize = tmpSum.size()+1;
tmpSum.resize(newSize);
sumVect.resize(newSize);
return newSize-1;
}
template
int LatticeStatistics::subscribeMin()
{
int newSize = tmpMin.size()+1;
tmpMin.resize(newSize);
minVect.resize(newSize);
return newSize-1;
}
template
int LatticeStatistics::subscribeMax()
{
int newSize = tmpMax.size()+1;
tmpMax.resize(newSize);
maxVect.resize(newSize);
return newSize-1;
}
template
void LatticeStatistics::incrementStats(T rho, T uSqr)
{
tmpAv[avRho] += rho;
tmpAv[avEnergy] += uSqr;
if (uSqr > tmpMax[maxU]) {
tmpMax[maxU] = uSqr;
}
++tmpNumCells;
}
template
void LatticeStatistics::gatherAverage(int whichAverage, T value)
{
OLB_PRECONDITION( whichAverage < (int) tmpAv.size() );
tmpAv[whichAverage] += value;
}
template
void LatticeStatistics::gatherSum(int whichSum, T value)
{
OLB_PRECONDITION( whichSum < (int) tmpSum.size() );
tmpSum[whichSum] += value;
}
template
void LatticeStatistics::gatherMin(int whichMin, T value)
{
OLB_PRECONDITION( whichMin < (int) tmpMin.size() );
if (value < tmpMin[whichMin]) {
tmpMin[whichMin] = value;
}
}
template
void LatticeStatistics::gatherMax(int whichMax, T value)
{
OLB_PRECONDITION( whichMax < (int) tmpMax.size() );
if (value > tmpMax[whichMax]) {
tmpMax[whichMax] = value;
}
}
template
void LatticeStatistics::incrementStats()
{
++tmpNumCells;
}
template
T LatticeStatistics::getAverageRho() const
{
return averageVect[avRho];
}
template
T LatticeStatistics::getAverageEnergy() const
{
return averageVect[avEnergy];
}
template
T LatticeStatistics::getMaxU() const
{
return maxVect[maxU];
}
template
size_t const& LatticeStatistics::getNumCells() const
{
return numCells;
}
template
T LatticeStatistics::getAverage(int whichAverage) const
{
OLB_PRECONDITION( whichAverage < (int) tmpAv.size() );
return averageVect[whichAverage];
}
template
T LatticeStatistics::getSum(int whichSum) const
{
OLB_PRECONDITION( whichSum < (int) tmpSum.size() );
return sumVect[whichSum];
}
template
T LatticeStatistics::getMin(int whichMin) const
{
OLB_PRECONDITION( whichMin < (int) tmpMin.size() );
return minVect[whichMin];
}
template
T LatticeStatistics::getMax(int whichMax) const
{
OLB_PRECONDITION( whichMax < (int) tmpMax.size() );
return maxVect[whichMax];
}
template
std::vector& LatticeStatistics::getAverageVect()
{
return averageVect;
}
template
std::vector& LatticeStatistics::getSumVect()
{
return sumVect;
}
template
std::vector& LatticeStatistics::getMinVect()
{
return minVect;
}
template
std::vector& LatticeStatistics::getMaxVect()
{
return maxVect;
}
template
void LatticeStatistics::incrementTime()
{
++latticeTime;
}
template
void LatticeStatistics::resetTime(size_t value)
{
latticeTime=value;
}
template
size_t LatticeStatistics::getTime() const
{
return latticeTime;
}
template
void LatticeStatistics::print(int iterationStep, T physicalTime) const
{
clout
<< "step=" << iterationStep << "; "
<< "t=" << physicalTime << "; "
<< "uMax=" << getMaxU() << "; "
<< "avEnergy=" << getAverageEnergy() << "; "
<< "avRho=" << getAverageRho()
<< std::endl;
}
} // namespace olb
#endif