OpenLB 1.8.1
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 if constexpr (!std::is_same_v<Expr,T>) {
60 maxU = std::max(uSqr, maxU);
61 }
62 }
63
65 nCells += rhs.nCells;
66 avRho += rhs.avRho;
67 avEnergy += rhs.avEnergy;
68 maxU = std::max(maxU, rhs.maxU);
69 return *this;
70 }
71 };
72
73public:
75 ~LatticeStatistics() = default;
76 void reset();
77 void reset(T average_rho_, T average_energy_, T maxU_, std::size_t numCells_);
78
79 int subscribeAverage();
80 int subscribeSum();
81 int subscribeMin();
82 int subscribeMax();
83
84 void incrementStats(T rho, T uSqr);
85 void incrementStats(Aggregatable& aggregatable);
86 void gatherAverage(int whichAverage, T value);
87 void gatherSum(int whichSum, T value);
88 void gatherMin(int whichMin, T value);
89 void gatherMax(int whichMax, T value);
90 void incrementStats();
91 T getAverageRho() const;
92 T getAverageEnergy() const;
93 T getMaxU() const;
94 std::size_t getNumCells() const;
95
96 T getAverage(int whichAverage) const;
97 T getSum(int whichSum) const;
98 T getMin(int whichMin) const;
99 T getMax(int whichMax) const;
100
101 std::vector<T>& getAverageVect();
102 std::vector<T>& getSumVect();
103 std::vector<T>& getMinVect();
104 std::vector<T>& getMaxVect();
105
106 void incrementTime();
107 void resetTime(size_t value=0);
108 std::size_t getTime() const;
109 void print(int iterationStep, T physicalTime=-1) const;
110 void initialize();
111
112private:
113 mutable OstreamManager clout;
114 // variables for internal computations
115 std::vector<T> tmpAv, tmpSum, tmpMin, tmpMax;
116 std::size_t tmpNumCells;
117 // variables containing the public result
118 std::vector<T> averageVect, sumVect, minVect, maxVect;
119 std::size_t numCells;
120 std::size_t latticeTime;
121 bool firstCall;
122
123};
124
125} // namespace olb
126
127#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()
T getMax(int whichMax) const
T getMin(int whichMin) const
std::size_t getNumCells() const
std::vector< T > & getAverageVect()
std::size_t getTime() const
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_0,C_1,C_2]^T * [1,D,Q].
Definition fields.h:52