OpenLB 1.7
Loading...
Searching...
No Matches
latticeStatistics.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2006, 2007, 2008 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
24#ifndef LATTICE_STATISTICS_HH
25#define LATTICE_STATISTICS_HH
26
27#include "latticeStatistics.h"
28#include "utilities/omath.h"
29#include <numeric>
30#include <limits>
31#include "util.h"
32
33namespace olb {
34
36
37template<typename T>
38LatticeStatistics<T>::LatticeStatistics() : clout(std::cout,"LatticeStatistics")
39{
40 initialize();
41}
42
43template<typename T>
45{
46 // avoid division by zero
47 if (tmpNumCells == 0) {
48 for (unsigned iVect=0; iVect<averageVect.size(); ++iVect) {
49 averageVect[iVect] = T();
50 }
51 for (unsigned iVect=0; iVect<sumVect.size(); ++iVect) {
52 sumVect[iVect] = T();
53 }
54 for (unsigned iVect=0; iVect<minVect.size(); ++iVect) {
55 minVect[iVect] = T();
56 }
57 for (unsigned iVect=0; iVect<maxVect.size(); ++iVect) {
58 maxVect[iVect] = T();
59 }
60 numCells = 0;
61 firstCall = false;
62 }
63 else {
64 // The average density is actually used in the "ConstRhoBgk" model.
65 // Depending on the simulation setup, it is possible that it has
66 // a nonsensical value before the simulation is started. For this
67 // and similar cases, averages are initialized to 1.
68 if (firstCall) {
69 for (unsigned iVect=0; iVect<averageVect.size(); ++iVect) {
70 averageVect[iVect] = (T)1;
71 }
72 firstCall = false;
73 }
74 else {
75 for (unsigned iVect=0; iVect<averageVect.size(); ++iVect) {
76 averageVect[iVect] = tmpAv[iVect] / (T)tmpNumCells;
77 }
78 }
79 for (unsigned iVect=0; iVect<sumVect.size(); ++iVect) {
80 sumVect[iVect] = tmpSum[iVect];
81 }
82 for (unsigned iVect=0; iVect<minVect.size(); ++iVect) {
83 minVect[iVect] = tmpMin[iVect];
84 }
85 for (unsigned iVect=0; iVect<maxVect.size(); ++iVect) {
86 maxVect[iVect] = tmpMax[iVect];
87 }
88 averageVect[avEnergy] *= (T)0.5; // energy is 0.5 *uSqr
89 maxVect[maxU] = util::sqrt(maxVect[maxU]); // u is util::sqrt(uSqr)
90 numCells = tmpNumCells;
91 }
93 for (unsigned iVect=0; iVect<averageVect.size(); ++iVect) {
94 tmpAv[iVect] = T();
95 }
96 for (unsigned iVect=0; iVect<sumVect.size(); ++iVect) {
97 tmpSum[iVect] = T();
98 }
99 for (unsigned iVect=0; iVect<minVect.size(); ++iVect) {
100 tmpMin[iVect] = std::numeric_limits<T>::max();
102 for (unsigned iVect=0; iVect<maxVect.size(); ++iVect) {
103 tmpMax[iVect] = std::numeric_limits<T>::min();
106 tmpNumCells = 0;
109template<typename T>
111 T average_rho_, T average_energy_, T maxU_, size_t numCells_ )
112{
113 averageVect[avRho] = average_rho_;
114 averageVect[avEnergy] = average_energy_;
115 maxVect[maxU] = maxU_;
116 numCells = numCells_;
117
118 tmpAv[avRho] = T();
119 tmpAv[avEnergy] = T();
120 tmpMax[maxU] = T();
121 tmpNumCells = 0;
122}
123
124template<typename T>
126{
127 tmpAv.resize(2);
128 averageVect.resize(2);
129 tmpMax.resize(1);
130 maxVect.resize(1);
131
132 tmpAv[avRho] = T();
133 tmpAv[avEnergy] = T();
134 tmpMax[maxU] = T();
135 tmpNumCells = 0;
136
137 averageVect[avRho] = (T)1;
138 averageVect[avEnergy] = T();
139 maxVect[maxU] = T();
140
141 firstCall = true;
142
143 resetTime();
144}
145
146template<typename T>
148{
149 int newSize = tmpAv.size()+1;
150 tmpAv.resize(newSize);
151 averageVect.resize(newSize);
152 return newSize-1;
153}
154
155template<typename T>
157{
158 int newSize = tmpSum.size()+1;
159 tmpSum.resize(newSize);
160 sumVect.resize(newSize);
161 return newSize-1;
162}
163
164template<typename T>
166{
167 int newSize = tmpMin.size()+1;
168 tmpMin.resize(newSize);
169 minVect.resize(newSize);
170 return newSize-1;
171}
172
173template<typename T>
175{
176 int newSize = tmpMax.size()+1;
177 tmpMax.resize(newSize);
178 maxVect.resize(newSize);
179 return newSize-1;
180}
181
182template<typename T>
184{
185 tmpAv[avRho] += rho;
186 tmpAv[avEnergy] += uSqr;
187 if (uSqr > tmpMax[maxU]) {
188 tmpMax[maxU] = uSqr;
189 }
190 ++tmpNumCells;
191}
192
193template<typename T>
195{
196 tmpNumCells += aggregatable.nCells;
197 tmpAv[avRho] += aggregatable.avRho;
198 tmpAv[avEnergy] += aggregatable.avEnergy;
199 tmpMax[maxU] = std::max(aggregatable.maxU, tmpMax[maxU]);
200}
201
202template<typename T>
203void LatticeStatistics<T>::gatherAverage(int whichAverage, T value)
204{
205 OLB_PRECONDITION( whichAverage < (int) tmpAv.size() );
206 tmpAv[whichAverage] += value;
207}
208
209template<typename T>
210void LatticeStatistics<T>::gatherSum(int whichSum, T value)
211{
212 OLB_PRECONDITION( whichSum < (int) tmpSum.size() );
213 tmpSum[whichSum] += value;
214}
215
216template<typename T>
217void LatticeStatistics<T>::gatherMin(int whichMin, T value)
218{
219 OLB_PRECONDITION( whichMin < (int) tmpMin.size() );
220 if (value < tmpMin[whichMin]) {
221 tmpMin[whichMin] = value;
222 }
223}
224
225template<typename T>
226void LatticeStatistics<T>::gatherMax(int whichMax, T value)
227{
228 OLB_PRECONDITION( whichMax < (int) tmpMax.size() );
229 if (value > tmpMax[whichMax]) {
230 tmpMax[whichMax] = value;
231 }
232}
233
234template<typename T>
236{
237 ++tmpNumCells;
238}
239
240template<typename T>
242{
243 return averageVect[avRho];
244}
245
246template<typename T>
248{
249 return averageVect[avEnergy];
250}
251
252template<typename T>
254{
255 return maxVect[maxU];
256}
257
258template<typename T>
260{
261 return numCells;
262}
263
264template<typename T>
265T LatticeStatistics<T>::getAverage(int whichAverage) const
266{
267 OLB_PRECONDITION( whichAverage < (int) tmpAv.size() );
268 return averageVect[whichAverage];
269}
270
271template<typename T>
272T LatticeStatistics<T>::getSum(int whichSum) const
273{
274 OLB_PRECONDITION( whichSum < (int) tmpSum.size() );
275 return sumVect[whichSum];
276}
277
278template<typename T>
279T LatticeStatistics<T>::getMin(int whichMin) const
280{
281 OLB_PRECONDITION( whichMin < (int) tmpMin.size() );
282 return minVect[whichMin];
283}
284
285template<typename T>
286T LatticeStatistics<T>::getMax(int whichMax) const
287{
288 OLB_PRECONDITION( whichMax < (int) tmpMax.size() );
289 return maxVect[whichMax];
290}
291
292template<typename T>
294{
295 return averageVect;
296}
297
298template<typename T>
300{
301 return sumVect;
302}
303
304template<typename T>
306{
307 return minVect;
308}
309
310template<typename T>
312{
313 return maxVect;
314}
315
316template<typename T>
318{
319 ++latticeTime;
320}
321
322template<typename T>
324{
325 latticeTime=value;
326}
327
328template<typename T>
330{
331 return latticeTime;
332}
333
334template<typename T>
335void LatticeStatistics<T>::print(int iterationStep, T physicalTime) const
336{
337 clout
338 << "step=" << iterationStep << "; "
339 << "t=" << physicalTime << "; "
340 << "uMax=" << getMaxU() << "; "
341 << "avEnergy=" << getAverageEnergy() << "; "
342 << "avRho=" << getAverageRho()
343 << std::endl;
344}
345
346} // namespace olb
347
348#endif
void gatherSum(int whichSum, T value)
T getAverage(int whichAverage) const
void gatherMax(int whichMax, T value)
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()
void gatherMin(int whichMin, T value)
void print(int iterationStep, T physicalTime=-1) const
std::vector< T > & getMaxVect()
void resetTime(size_t value=0)
Interface for post-processing steps – header file.
cpu::simd::Pack< T > sqrt(cpu::simd::Pack< T > value)
Definition pack.h:100
Top level namespace for all of OpenLB.
#define OLB_PRECONDITION(COND)
Definition olbDebug.h:46
Set of functions commonly used in LB computations – header file.