OpenLB 1.7
Loading...
Searching...
No Matches
Public Member Functions | List of all members
olb::util::ValueTracer< T > Class Template Reference

Check time-convergence of a scalar. More...

#include <benchmarkUtil.h>

+ Collaboration diagram for olb::util::ValueTracer< T >:

Public Member Functions

 ValueTracer (T u, T L, T epsilon)
 Ctor.
 
 ValueTracer (int deltaT, T epsilon)
 Ctor.
 
 ValueTracer (int deltaT, T epsilon, std::string name)
 Ctor.
 
void resetScale (T u, T L)
 Change values of u and L to update characteristic scales of the system.
 
void resetValues ()
 reinitializes the values
 
int getDeltaT () const
 Get characteristic time scale.
 
void takeValue (T val, bool doPrint=false)
 Feed the object with a new measured scalar.
 
bool hasConverged () const
 Test for convergence, with respect to stdDev.
 
bool convergenceCheck () const
 Test for convergence, with respect to difference between min and max value;.
 
bool hasConvergedMinMax () const
 Test for convergence, with respect to difference between min and max value;.
 
computeAverage () const
 
computeStdDev (T average) const
 
getEpsilon () const
 
void setEpsilon (T epsilon)
 

Detailed Description

template<typename T>
class olb::util::ValueTracer< T >

Check time-convergence of a scalar.

This class is useful, for example to check convergence of the velocity field for the simulation of a stationary flow. Convergence is claimed when the standard deviation of the monitored value is smaller than epsilon times the average. The statistics are taken over a macroscopic time scale of the system.

Definition at line 49 of file benchmarkUtil.h.

Constructor & Destructor Documentation

◆ ValueTracer() [1/3]

template<typename T >
olb::util::ValueTracer< T >::ValueTracer ( T u,
T L,
T epsilon )

Ctor.

Parameters
uThe characteristic velocity of the system, for computation of the characteristic time scale.
LThe characteristic length of the system, for computation of the characteristic time scale.
epsilonPrecision of the convergence.

Definition at line 45 of file benchmarkUtil.hh.

46 : _deltaT((int)(L/u/2.)),
47 _epsilon(epsilon),
48 _t(0),
49 _converged(false),
50 clout(std::cout,"ValueTracer")
51{ }

◆ ValueTracer() [2/3]

template<typename T >
olb::util::ValueTracer< T >::ValueTracer ( int deltaT,
T epsilon )

Ctor.

Parameters
deltaTcorresponds to iteration steps (averaging)
epsilonallowed derivation of quantity

Definition at line 54 of file benchmarkUtil.hh.

55 : _deltaT(deltaT),
56 _epsilon(epsilon),
57 _t(0),
58 _converged(false),
59 clout(std::cout,"ValueTracer")
60{ }

◆ ValueTracer() [3/3]

template<typename T >
olb::util::ValueTracer< T >::ValueTracer ( int deltaT,
T epsilon,
std::string name )

Ctor.

Parameters
deltaTcorresponds to iteration steps (averaging)
epsilonallowed derivation of quantity
namequantity name

Definition at line 63 of file benchmarkUtil.hh.

64 : _deltaT(deltaT),
65 _epsilon(epsilon),
66 _t(0),
67 _converged(false),
68 clout(std::cout,"ValueTracer "+name)
69{ }

Member Function Documentation

◆ computeAverage()

template<typename T >
T olb::util::ValueTracer< T >::computeAverage ( ) const

Definition at line 162 of file benchmarkUtil.hh.

163{
164 return std::accumulate(_values.begin(), _values.end(), 0.) / _values.size();
165}

◆ computeStdDev()

template<typename T >
T olb::util::ValueTracer< T >::computeStdDev ( T average) const

Definition at line 168 of file benchmarkUtil.hh.

169{
170 int n = _values.size();
171 T sqrDev = 0.;
172 for (int i=0; i<n; ++i) {
173 sqrDev += (_values[i]-average)*(_values[i]-average);
174 }
175 return util::sqrt(sqrDev/(n-1));
176}
cpu::simd::Pack< T > sqrt(cpu::simd::Pack< T > value)
Definition pack.h:100
T average(const Vector< T, Size > &a)
computes the average of all elements

References olb::util::average(), and olb::util::sqrt().

+ Here is the call graph for this function:

◆ convergenceCheck()

template<typename T >
bool olb::util::ValueTracer< T >::convergenceCheck ( ) const

Test for convergence, with respect to difference between min and max value;.

Definition at line 130 of file benchmarkUtil.hh.

131{
132 if ((int)_values.size() < util::abs(_deltaT)) {
133 return false;
134 }
135 else {
137 T stdDev = computeStdDev(average);
138 if (!std::isnan(stdDev/average)) {
139 return util::fabs(stdDev/average) < _epsilon;
140 }
141 else {
142 clout << "simulation diverged." << std::endl;
143 return false;
144 }
145 }
146}
T computeStdDev(T average) const
ADf< T, DIM > abs(const ADf< T, DIM > &a)
Definition aDiff.h:1019
cpu::simd::Pack< T > fabs(cpu::simd::Pack< T > value)
Definition pack.h:106

References olb::util::abs(), olb::util::average(), and olb::util::fabs().

+ Here is the call graph for this function:

◆ getDeltaT()

template<typename T >
int olb::util::ValueTracer< T >::getDeltaT ( ) const

Get characteristic time scale.

Definition at line 72 of file benchmarkUtil.hh.

73{
74 return _deltaT;
75}

◆ getEpsilon()

template<typename T >
T olb::util::ValueTracer< T >::getEpsilon ( ) const

Definition at line 179 of file benchmarkUtil.hh.

180{
181 return _epsilon;
182}

◆ hasConverged()

template<typename T >
bool olb::util::ValueTracer< T >::hasConverged ( ) const

Test for convergence, with respect to stdDev.

Definition at line 112 of file benchmarkUtil.hh.

113{
114 if ((int)_values.size() < util::abs(_deltaT)) {
115 return false;
116 }
117 else {
119 T stdDev = computeStdDev(average);
120 if (!std::isnan(stdDev/average)) {
121 return util::fabs(stdDev/average) < _epsilon;
122 }
123 else {
124 clout << "simulation diverged." << std::endl;
125 return true;
126 }
127 }
128}

References olb::util::abs(), olb::util::average(), and olb::util::fabs().

+ Here is the call graph for this function:

◆ hasConvergedMinMax()

template<typename T >
bool olb::util::ValueTracer< T >::hasConvergedMinMax ( ) const

Test for convergence, with respect to difference between min and max value;.

Definition at line 148 of file benchmarkUtil.hh.

149{
150 if ((int)_values.size() < util::abs(_deltaT)) {
151 return false;
152 }
153 else {
154 T minEl = *min_element(_values.begin(), _values.end());
155 T maxEl = *max_element(_values.begin(), _values.end());
157 return (maxEl - minEl)/average < _epsilon;
158 }
159}
T max_element(const Vector< T, Size > &a)
finds maximum element of all elements
T min_element(const Vector< T, Size > &a)
finds minimum element of all elements

References olb::util::abs(), olb::util::average(), olb::util::max_element(), and olb::util::min_element().

+ Here is the call graph for this function:

◆ resetScale()

template<typename T >
void olb::util::ValueTracer< T >::resetScale ( T u,
T L )

Change values of u and L to update characteristic scales of the system.

Definition at line 93 of file benchmarkUtil.hh.

94{
95 _t = _t%_deltaT;
96 _deltaT = (int) (L/u/2.);
97 if ( (int)_values.size() > util::abs(_deltaT) ) {
98 _values.erase(_values.begin(), _values.begin() + (_values.size()-_deltaT) );
99 }
100}

References olb::util::abs().

+ Here is the call graph for this function:

◆ resetValues()

template<typename T >
void olb::util::ValueTracer< T >::resetValues ( )

reinitializes the values

Definition at line 103 of file benchmarkUtil.hh.

104{
105 _t = 0;
106 if ((int)_values.size() > 0) {
107 _values.erase(_values.begin(), _values.begin() + _values.size() );
108 }
109}

◆ setEpsilon()

template<typename T >
void olb::util::ValueTracer< T >::setEpsilon ( T epsilon)

Definition at line 185 of file benchmarkUtil.hh.

186{
187 _epsilon = epsilon;
188}

◆ takeValue()

template<typename T >
void olb::util::ValueTracer< T >::takeValue ( T val,
bool doPrint = false )

Feed the object with a new measured scalar.

Definition at line 78 of file benchmarkUtil.hh.

79{
80 _values.push_back(val);
81 if ((int)_values.size() > util::abs(_deltaT)) {
82 _values.erase(_values.begin());
83 if (doPrint && _t%_deltaT==0) {
85 T stdDev = computeStdDev(average);
86 clout << "average=" << average << "; stdDev/average=" << stdDev/average << std::endl;
87 }
88 }
89 ++_t;
90}

References olb::util::abs(), and olb::util::average().

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: