25#ifndef BENCHMARK_UTIL_H
26#define BENCHMARK_UTIL_H
69 ValueTracer(
int deltaT, T epsilon, std::string name );
77 void takeValue(T val,
bool doPrint=
false);
93 std::deque<T> _values;
112 T
getVal(
bool stable,
bool doPrint=
false);
116 T iniVal, currentVal, lowerVal, upperVal;
118 enum {first, up, down, bisect} state;
172 std::vector<T> _data;
179template<
typename T,
typename S>
183 const std::function<T(
int)> _smoothingFactorFunction;
194 return 2. / (1 + i); });
202 bool operator() (T output[],
const S x[])
override;
216template<
typename T,
int P=1>
242 "Time integration needs smaller time steps.\n");
243 if constexpr (P==0) {
251 if constexpr (P == 0) {
255 const T time(iT *
_dt);
287 weight = 0.5 *
_dt + offset;
295 void reset(T lowerBound, T upperBound, T dt)
304 if constexpr (P==0) {
310 throw std::runtime_error(
"Time integration needs smaller time steps.\n");
317 if constexpr (P==0) {
322 __builtin_unreachable();
327template<
typename T,
int numComponents,
int P=1>
331 std::array<std::unique_ptr<TimeIntegrator<T,P>>,numComponents>
integrators;
335 for (
int i = 0; i < numComponents; ++i) {
336 integrators[i] = std::make_unique<TimeIntegrator<T,P>>(lowerBound,upperBound,dt);
341 void takeValues(
int iT, std::array<T,numComponents> values) {
342 for (
int i = 0; i < numComponents; ++i) {
347 void reset(T lowerBound, T upperBound, T dt) {
349 integrator->reset(lowerBound,upperBound,dt);
355 std::array<T,numComponents> results;
357 [](
auto& integrator){
358 return integrator->getResult();
Some arithmetic helper functions.
Class for computing the derivative of a given 1D functor with a finite difference.
class for marking output with some text
Propose successive test values of a scalar (e.g. Re) to check stability of a system.
BisectStepper(T _iniVal, T _step=0.)
The only constructor.
T getVal(bool stable, bool doPrint=false)
Get new value, and indicate if the previous value yielded a stable system or not.
bool hasConverged(T epsilon) const
Test for convergence.
Simple circular buffer to compute average and other quantities over pre-defined temporal windows.
void insert(T entry)
insert a new entry ed eventually erases the oldest one
T & get(int pos)
get reference to the last entry for pos=0, the second-to-last for pos=1, and so on
T average()
average over all the entries
int getSize()
return size of the buffer
Exponential moving average.
void resetNoOfEntries()
reset number of entries
void takeValue(const T val)
compute next EMA with given value
bool operator()(T output[], const S x[]) override
has to be implemented for 'every' derived class
ExponentialMovingAverage(const std::function< T(int)> smoothingFactorFunction=[](int i) -> T { return 2./(1+i);})
(constructor)
Accurate summation of floating point numbers with the Kahan algorithm Reduces round-off effects which...
T solve(T startValue, bool print=false)
AnalyticalF1D< T, T > & _f
Newton1D(AnalyticalF1D< T, T > &f, T yValue=T(), T eps=1.e-8, int maxIterations=100)
AnalyticalDerivativeFD1D< T > _df
Integration with the trapezoid rule.
TimeIntegrator(T lowerBound, T upperBound, T dt)
std::conditional_t<(P==0), T, KahanSummator< T > > result
void takeValue(int iT, T value)
void reset(T lowerBound, T upperBound, T dt)
Helper class that manages an array of time integrators.
void takeValues(int iT, std::array< T, numComponents > values)
Values can be passed in {val1, val2, ...} notation.
std::array< T, numComponents > getResult()
void reset(T lowerBound, T upperBound, T dt)
std::array< std::unique_ptr< TimeIntegrator< T, P > >, numComponents > integrators
TimeIntegratorsArray(T lowerBound, T upperBound, T dt)
AnalyticalF1D< T, T > & _f
TrapezRuleInt1D(AnalyticalF1D< T, T > &f)
T integrate(T min, T max, int nSteps)
Check time-convergence of a scalar.
bool hasConverged() const
Test for convergence, with respect to stdDev.
int getDeltaT() const
Get characteristic time scale.
bool convergenceCheck() const
Test for convergence, with respect to difference between min and max value;.
void resetScale(T u, T L)
Change values of u and L to update characteristic scales of the system.
void setEpsilon(T epsilon)
bool hasConvergedMinMax() const
Test for convergence, with respect to difference between min and max value;.
ValueTracer(T u, T L, T epsilon)
Ctor.
void takeValue(T val, bool doPrint=false)
Feed the object with a new measured scalar.
T computeStdDev(T average) const
void resetValues()
reinitializes the values
ADf< T, DIM > abs(const ADf< T, DIM > &a)
cpu::simd::Pack< T > min(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
T average(const Vector< T, Size > &a)
computes the average of all elements
cpu::simd::Pack< T > max(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
cpu::simd::Pack< T > pow(cpu::simd::Pack< T > base, cpu::simd::Pack< T > exp)
void print(U data, const std::string &name="", OstreamManager clout=OstreamManager(std::cout,"print"), const char delimiter=',')
Top level namespace for all of OpenLB.
typename util::BaseTypeHelper< T >::type BaseType
#define OLB_ASSERT(COND, MESSAGE)