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

Integration with the trapezoid rule. More...

#include <benchmarkUtil.h>

+ Collaboration diagram for olb::util::TimeIntegrator< T, P >:

Public Member Functions

 TimeIntegrator (T lowerBound, T upperBound, T dt)
 
void takeValue (int iT, T value)
 
void reset (T lowerBound, T upperBound, T dt)
 
getResult ()
 

Protected Attributes

_lowerBound
 
_upperBound
 
_dt
 
int _firstStep
 
int _secondStep
 
int _lastStep
 
int _prelastStep
 
std::conditional_t<(P==0), T, KahanSummator< T > > result
 

Detailed Description

template<typename T, int P = 1>
class olb::util::TimeIntegrator< T, P >

Integration with the trapezoid rule.

Compute L^P norm on a time interval with the trapezoid rule. For p < infinity, the exact physical interval bounds are respected via linear interpolation from the two neighboring time steps inside the integration domain. P=0 corresponds to the L^\infty norm. For ADf data types, the derivatives of the result contain the derivatives of the integral w.r.t. the derivation variables. Both integrands and integration limits may depend on the derivation variables.

Definition at line 217 of file benchmarkUtil.h.

Constructor & Destructor Documentation

◆ TimeIntegrator()

template<typename T , int P = 1>
olb::util::TimeIntegrator< T, P >::TimeIntegrator ( T lowerBound,
T upperBound,
T dt )
inline

Definition at line 232 of file benchmarkUtil.h.

232 :
233 _lowerBound(lowerBound),
234 _upperBound(upperBound),
235 _dt(dt),
236 _firstStep(_lowerBound > 0 ? _lowerBound / dt + 1.0 : _lowerBound / dt),
238 _lastStep(_upperBound > 0 ? _upperBound / dt : _upperBound / dt - 1.0),
240 {
242 "Time integration needs smaller time steps.\n");
243 if constexpr (P==0) {
244 result = T(0);
245 }
246 }
std::conditional_t<(P==0), T, KahanSummator< T > > result
#define OLB_ASSERT(COND, MESSAGE)
Definition olbDebug.h:45

References olb::util::TimeIntegrator< T, P >::_prelastStep, olb::util::TimeIntegrator< T, P >::_secondStep, OLB_ASSERT, and olb::util::TimeIntegrator< T, P >::result.

Member Function Documentation

◆ getResult()

template<typename T , int P = 1>
T olb::util::TimeIntegrator< T, P >::getResult ( )
inline

Definition at line 314 of file benchmarkUtil.h.

315 {
316 using BT = BaseType<T>;
317 if constexpr (P==0) {
318 return result;
319 } else {
320 return util::pow(result.getSum(), BT(1) / P);
321 }
322 __builtin_unreachable();
323 }
cpu::simd::Pack< T > pow(cpu::simd::Pack< T > base, cpu::simd::Pack< T > exp)
Definition pack.h:112

References olb::util::pow(), and olb::util::TimeIntegrator< T, P >::result.

+ Here is the call graph for this function:

◆ reset()

template<typename T , int P = 1>
void olb::util::TimeIntegrator< T, P >::reset ( T lowerBound,
T upperBound,
T dt )
inline

Definition at line 295 of file benchmarkUtil.h.

296 {
297 _lowerBound = lowerBound;
298 _upperBound = upperBound;
299 _dt = dt;
300 _firstStep = _lowerBound / dt + 1.0;
302 _lastStep = _upperBound / dt;
304 if constexpr (P==0) {
305 result = T(0);
306 } else {
307 result.initialize();
308 }
309 if (_secondStep >= _prelastStep) {
310 throw std::runtime_error("Time integration needs smaller time steps.\n");
311 }
312 }

References olb::util::TimeIntegrator< T, P >::_dt, olb::util::TimeIntegrator< T, P >::_firstStep, olb::util::TimeIntegrator< T, P >::_lastStep, olb::util::TimeIntegrator< T, P >::_lowerBound, olb::util::TimeIntegrator< T, P >::_prelastStep, olb::util::TimeIntegrator< T, P >::_secondStep, olb::util::TimeIntegrator< T, P >::_upperBound, and olb::util::TimeIntegrator< T, P >::result.

◆ takeValue()

template<typename T , int P = 1>
void olb::util::TimeIntegrator< T, P >::takeValue ( int iT,
T value )
inline

Definition at line 248 of file benchmarkUtil.h.

249 {
250 if (iT >= _firstStep && iT <= _lastStep) {
251 if constexpr (P == 0) {
252 result = util::max(result, util::abs(value));
253 }
254 else {
255 const T time(iT * _dt);
256 T weight(_dt);
257
258 /*
259 // linear extrapolation at interval bounds
260 // was deactivated due to instability
261 if (iT == _firstStep) {
262 T offset (_lowerBound - time);
263 weight = 0.5 * _dt - 0.5 * (2.0 - offset / _dt) * offset;
264 //weight = 0.5 * _dt + time - _lowerBound;
265 }
266 else if (iT == _secondStep) {
267 T offset (_lowerBound - (time - _dt));
268 weight = _dt - 0.5 * offset * offset / _dt;
269 }
270 else if (iT == _prelastStep) {
271 T offset (_upperBound - (time + _dt));
272 weight = _dt - 0.5 * offset * offset / _dt;
273 }
274 else if (iT == _lastStep) {
275 T offset (_upperBound - time);
276 weight = 0.5 * _dt + 0.5 * (2.0 + offset / _dt) * offset;
277 //weight = 0.5 * _dt + offset;
278 }
279 */
280
281 // constant extrapolation at interval bounds
282 if (iT == _firstStep) {
283 weight = 0.5 * _dt + time - _lowerBound;
284 }
285 else if (iT == _lastStep) {
286 T offset (_upperBound - time);
287 weight = 0.5 * _dt + offset;
288 }
289
290 result.add(weight * util::pow(value, P));
291 }
292 }
293 }
ADf< T, DIM > abs(const ADf< T, DIM > &a)
Definition aDiff.h:1019
cpu::simd::Pack< T > max(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
Definition pack.h:130

References olb::util::TimeIntegrator< T, P >::_dt, olb::util::TimeIntegrator< T, P >::_firstStep, olb::util::TimeIntegrator< T, P >::_lastStep, olb::util::TimeIntegrator< T, P >::_lowerBound, olb::util::TimeIntegrator< T, P >::_upperBound, olb::util::abs(), olb::util::max(), olb::util::pow(), and olb::util::TimeIntegrator< T, P >::result.

+ Here is the call graph for this function:

Member Data Documentation

◆ _dt

template<typename T , int P = 1>
T olb::util::TimeIntegrator< T, P >::_dt
protected

Definition at line 222 of file benchmarkUtil.h.

◆ _firstStep

template<typename T , int P = 1>
int olb::util::TimeIntegrator< T, P >::_firstStep
protected

Definition at line 224 of file benchmarkUtil.h.

◆ _lastStep

template<typename T , int P = 1>
int olb::util::TimeIntegrator< T, P >::_lastStep
protected

Definition at line 226 of file benchmarkUtil.h.

◆ _lowerBound

template<typename T , int P = 1>
T olb::util::TimeIntegrator< T, P >::_lowerBound
protected

Definition at line 220 of file benchmarkUtil.h.

◆ _prelastStep

template<typename T , int P = 1>
int olb::util::TimeIntegrator< T, P >::_prelastStep
protected

Definition at line 227 of file benchmarkUtil.h.

◆ _secondStep

template<typename T , int P = 1>
int olb::util::TimeIntegrator< T, P >::_secondStep
protected

Definition at line 225 of file benchmarkUtil.h.

◆ _upperBound

template<typename T , int P = 1>
T olb::util::TimeIntegrator< T, P >::_upperBound
protected

Definition at line 221 of file benchmarkUtil.h.

◆ result

template<typename T , int P = 1>
std::conditional_t< (P==0), T, KahanSummator<T> > olb::util::TimeIntegrator< T, P >::result
protected

Definition at line 229 of file benchmarkUtil.h.


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