OpenLB 1.7
Loading...
Searching...
No Matches
latticeStatistics.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2006, 2007 Jonas Latt
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
27#ifndef LATTICE_STATISTICS_H
28#define LATTICE_STATISTICS_H
29
30#include <vector>
31#include "io/ostreamManager.h"
32
33namespace olb {
34
36
37namespace statistics {
38
39struct AVERAGE_RHO : public descriptors::FIELD_BASE<1> { };
40
41}
42
43template<typename T>
45public:
46 enum { avRho=0, avEnergy=1 } AverageT;
47 enum { maxU=0 } MaxT;
48
49 struct Aggregatable {
50 std::size_t nCells = 0;
51 T avRho { };
52 T avEnergy { };
53 T maxU { };
54
55 void increment(T rho, T uSqr) {
56 nCells += 1;
57 avRho += rho;
58 avEnergy += uSqr;
59 maxU = std::max(uSqr, maxU);
60 }
61
63 nCells += rhs.nCells;
64 avRho += rhs.avRho;
65 avEnergy += rhs.avEnergy;
66 maxU = std::max(maxU, rhs.maxU);
67 return *this;
68 }
69 };
70
71public:
73 ~LatticeStatistics() = default;
74 void reset();
75 void reset(T average_rho_, T average_energy_, T maxU_, size_t numCells_);
76
77 int subscribeAverage();
78 int subscribeSum();
79 int subscribeMin();
80 int subscribeMax();
81
82 void incrementStats(T rho, T uSqr);
83 void incrementStats(Aggregatable& aggregatable);
84 void gatherAverage(int whichAverage, T value);
85 void gatherSum(int whichSum, T value);
86 void gatherMin(int whichMin, T value);
87 void gatherMax(int whichMax, T value);
88 void incrementStats();
89 T getAverageRho() const;
90 T getAverageEnergy() const;
91 T getMaxU() const;
92 size_t const& getNumCells() const;
93
94 T getAverage(int whichAverage) const;
95 T getSum(int whichSum) const;
96 T getMin(int whichMin) const;
97 T getMax(int whichMax) const;
98
99 std::vector<T>& getAverageVect();
100 std::vector<T>& getSumVect();
101 std::vector<T>& getMinVect();
102 std::vector<T>& getMaxVect();
103
104 void incrementTime();
105 void resetTime(size_t value=0);
106 size_t getTime() const;
107 void print(int iterationStep, T physicalTime=-1) const;
108 void initialize();
109private:
110 mutable OstreamManager clout;
111 // variables for internal computations
112 std::vector<T> tmpAv, tmpSum, tmpMin, tmpMax;
113 size_t tmpNumCells;
114 // variables containing the public result
115 std::vector<T> averageVect, sumVect, minVect, maxVect;
116 size_t numCells;
117 size_t latticeTime;
118 bool firstCall;
119};
120
121} // namespace olb
122
123#endif
void gatherSum(int whichSum, T value)
T getAverage(int whichAverage) const
void gatherMax(int whichMax, T value)
enum olb::LatticeStatistics::@1 MaxT
enum olb::LatticeStatistics::@0 AverageT
std::vector< T > & getMinVect()
size_t const & getNumCells() const
T getMax(int whichMax) const
T getMin(int whichMin) const
std::vector< T > & getAverageVect()
void gatherAverage(int whichAverage, T value)
T getSum(int whichSum) const
std::vector< T > & getSumVect()
~LatticeStatistics()=default
void gatherMin(int whichMin, T value)
void print(int iterationStep, T physicalTime=-1) const
std::vector< T > & getMaxVect()
void resetTime(size_t value=0)
class for marking output with some text
Top level namespace for all of OpenLB.
Aggregatable & operator+=(const Aggregatable &rhs)
Base of a field whose size is defined by [C,U_1,...,U_N]^T * [1,V_1,...V_N].