INET Framework for OMNeT++/OMNEST
inet::math::PeriodicallyInterpolated1DFunction< R, X > Class Template Reference

One-dimensional interpolated (e.g. More...

#include <PrimitiveFunctions.h>

Inheritance diagram for inet::math::PeriodicallyInterpolated1DFunction< R, X >:
inet::math::FunctionBase< R, Domain< X > > inet::math::IFunction< R, Domain< X > >

Public Member Functions

 PeriodicallyInterpolated1DFunction (X start, X end, const IInterpolator< X, R > &interpolator, const std::vector< R > &rs)
 
virtual R getValue (const Point< X > &p) const override
 
virtual void partition (const Interval< X > &i, const std::function< void(const Interval< X > &, const IFunction< R, Domain< X >> *)> callback) const override
 
- Public Member Functions inherited from inet::math::FunctionBase< R, Domain< X > >
virtual void partition (const typename Domain< X > ::I &i, const std::function< void(const typename Domain< X > ::I &, const IFunction< R, Domain< X > > *)> callback) const override
 Subdivides the provided domain and calls back f with the subdomains and the corresponding potentially simpler domain limited functions. More...
 
virtual Interval< R > getRange () const override
 Returns the valid range of the function as an interval. More...
 
virtual Interval< R > getRange (const typename Domain< X > ::I &i) const override
 Returns the valid range of the function as an interval for the given domain. More...
 
virtual Domain< X > ::I getDomain () const override
 Returns the valid domain of the function as an interval. More...
 
virtual bool isFinite () const override
 Returns true if the function value is finite in the whole domain. More...
 
virtual bool isFinite (const typename Domain< X > ::I &i) const override
 Returns true if the function value is finite in the given domain. More...
 
virtual bool isNonZero () const override
 Returns true if the function value is non-zero in the whole domain. More...
 
virtual bool isNonZero (const typename Domain< X > ::I &i) const override
 Returns true if the function value is non-zero in the given domain. More...
 
virtual R getMin () const override
 Returns the minimum value for the whole domain. More...
 
virtual R getMin (const typename Domain< X > ::I &i) const override
 Returns the minimum value for the given domain. More...
 
virtual R getMax () const override
 Returns the maximum value for the whole domain. More...
 
virtual R getMax (const typename Domain< X > ::I &i) const override
 Returns the maximum value for the given domain. More...
 
virtual R getMean () const override
 Returns the mean value for the whole domain. More...
 
virtual R getMean (const typename Domain< X > ::I &i) const override
 Returns the mean value for the given domain. More...
 
virtual R getIntegral () const override
 Returns the integral value for the whole domain. More...
 
virtual R getIntegral (const typename Domain< X > ::I &i) const override
 Returns the integral value for the given domain. More...
 
virtual const Ptr< const IFunction< R, Domain< X > > > add (const Ptr< const IFunction< R, Domain< X > >> &o) const override
 Adds the provided function to this function. More...
 
virtual const Ptr< const IFunction< R, Domain< X > > > subtract (const Ptr< const IFunction< R, Domain< X > >> &o) const override
 Substracts the provided function from this function. More...
 
virtual const Ptr< const IFunction< R, Domain< X > > > multiply (const Ptr< const IFunction< double, Domain< X > >> &o) const override
 Multiplies the provided function with this function. More...
 
virtual const Ptr< const IFunction< double, Domain< X > > > divide (const Ptr< const IFunction< R, Domain< X > >> &o) const override
 Divides this function with the provided function. More...
 
virtual std::ostream & printOn (std::ostream &os) const override
 
virtual void print (std::ostream &os, int level=0) const override
 Prints this function in human readable form to the provided stream for the whole domain. More...
 
virtual void print (std::ostream &os, const typename Domain< X > ::I &i, int level=0) const override
 Prints this function in a human readable form to the provided stream for the given domain. More...
 
virtual void printPartitioning (std::ostream &os, const typename Domain< X > ::I &i, int level) const override
 Prints the partitioning of this function in a human readable form to the provided stream for the given domain. More...
 
virtual void printPartition (std::ostream &os, const typename Domain< X > ::I &i, int level=0) const override
 Prints a single partition of this function in a human readable form to the provided stream for the given domain. More...
 
virtual void printStructure (std::ostream &os, int level=0) const override
 Prints the internal data structure of this function in a human readable form to the provided stream. More...
 
- Public Member Functions inherited from inet::math::IFunction< R, Domain< X > >
virtual ~IFunction ()
 
virtual R getValue (const typename Domain< X > ::P &p) const=0
 Returns the value of the function at the given point. More...
 

Protected Attributes

const X start
 
const X end
 
const X step
 
const IInterpolator< X, R > & interpolator
 
const std::vector< R > rs
 

Detailed Description

template<typename R, typename X>
class inet::math::PeriodicallyInterpolated1DFunction< R, X >

One-dimensional interpolated (e.g.

constant, linear) function between intervals defined by points positioned periodically on the X axis.

Constructor & Destructor Documentation

◆ PeriodicallyInterpolated1DFunction()

template<typename R , typename X >
inet::math::PeriodicallyInterpolated1DFunction< R, X >::PeriodicallyInterpolated1DFunction ( start,
end,
const IInterpolator< X, R > &  interpolator,
const std::vector< R > &  rs 
)
inline
526  :
527  start(start), end(end), step((end - start) / (rs.size() - 1)), interpolator(interpolator), rs(rs) {}

Member Function Documentation

◆ getValue()

template<typename R , typename X >
virtual R inet::math::PeriodicallyInterpolated1DFunction< R, X >::getValue ( const Point< X > &  p) const
inlineoverridevirtual
529  {
530  X x = std::get<0>(p);
531  int index = std::floor(toDouble(x - start) / toDouble(step));
532  if (index < 0 || index > rs.size() - 2)
533  return R(0);
534  else {
535  R r1 = rs[index];
536  R r2 = rs[index + 1];
537  X x1 = start + step * index;
538  X x2 = x1 + step;
539  return interpolator.getValue(x1, r1, x2, r2, x);
540  }
541  }

◆ partition()

template<typename R , typename X >
virtual void inet::math::PeriodicallyInterpolated1DFunction< R, X >::partition ( const Interval< X > &  i,
const std::function< void(const Interval< X > &, const IFunction< R, Domain< X >> *)>  callback 
) const
inlineoverridevirtual
543  {
544  const auto& i1 = i.getIntersected(Interval<X>(getLowerBound<X>(), Point<X>(start), 0b0, 0b0, 0b0));
545  if (!i1.isEmpty()) {
546  ConstantFunction<R, Domain<X>> g(R(0));
547  callback(i1, &g);
548  }
549  const auto& i2 = i.getIntersected(Interval<X>(Point<X>(start), Point<X>(end), 0b1, 0b0, 0b0));
550  if (!i2.isEmpty()) {
551  int startIndex = std::max(0, (int)std::floor(toDouble(std::get<0>(i.getLower()) - start) / toDouble(step)));
552  int endIndex = std::min((int)rs.size() - 1, (int)std::ceil(toDouble(std::get<0>(i.getUpper()) - start) / toDouble(step)));
553  for (int index = startIndex; index < endIndex; index++) {
554  Point<X> startPoint(start + step * index);
555  Point<X> endPoint(start + step * (index + 1));
556  const auto& i3 = i.getIntersected(Interval<X>(startPoint, endPoint, 0b1, 0b0, 0b0));
557  if (!i3.isEmpty()) {
558  if (dynamic_cast<const ConstantInterpolatorBase<X, R> *>(&interpolator)) {
559  R r = getValue((startPoint + endPoint) / 2);
560  ConstantFunction<R, Domain<X>> g(r);
561  callback(i3, &g);
562  }
563  else
564  throw cRuntimeError("TODO");
565  }
566  }
567  }
568  const auto& i4 = i.getIntersected(Interval<X>(Point<X>(end), getUpperBound<X>(), 0b1, 0b0, 0b0));
569  if (!i4.isEmpty()) {
570  ConstantFunction<R, Domain<X>> g(R(0));
571  callback(i4, &g);
572  }
573  }

Member Data Documentation

◆ end

template<typename R , typename X >
const X inet::math::PeriodicallyInterpolated1DFunction< R, X >::end
protected

◆ interpolator

template<typename R , typename X >
const IInterpolator<X, R>& inet::math::PeriodicallyInterpolated1DFunction< R, X >::interpolator
protected

◆ rs

template<typename R , typename X >
const std::vector<R> inet::math::PeriodicallyInterpolated1DFunction< R, X >::rs
protected

◆ start

template<typename R , typename X >
const X inet::math::PeriodicallyInterpolated1DFunction< R, X >::start
protected

◆ step

template<typename R , typename X >
const X inet::math::PeriodicallyInterpolated1DFunction< R, X >::step
protected

The documentation for this class was generated from the following file:
inet::math::PeriodicallyInterpolated1DFunction::rs
const std::vector< R > rs
Definition: PrimitiveFunctions.h:523
inet::sctp::min
double min(const double a, const double b)
Returns the minimum of a and b.
Definition: SctpAssociation.h:261
inet::math::PeriodicallyInterpolated1DFunction::interpolator
const IInterpolator< X, R > & interpolator
Definition: PrimitiveFunctions.h:522
inet::math::toDouble
double toDouble(const T v)
Definition: Point.h:28
inet::units::units::g
milli< kg >::type g
Definition: Units.h:1071
inet::math::PeriodicallyInterpolated1DFunction::end
const X end
Definition: PrimitiveFunctions.h:520
inet::math::PeriodicallyInterpolated1DFunction::getValue
virtual R getValue(const Point< X > &p) const override
Definition: PrimitiveFunctions.h:529
inet::units::constants::R
const value< double, compose< units::J, compose< pow< units::mol, -1 >, pow< units::kg, -1 > > > > R(8.314472)
inet::math::PeriodicallyInterpolated1DFunction::step
const X step
Definition: PrimitiveFunctions.h:521
inet::math::PeriodicallyInterpolated1DFunction::start
const X start
Definition: PrimitiveFunctions.h:519
inet::sctp::max
double max(const double a, const double b)
Returns the maximum of a and b.
Definition: SctpAssociation.h:266
inet::math::IInterpolator::getValue
virtual Y getValue(const X x1, const Y y1, const X x2, const Y y2, const X x) const =0
Returns the interpolated value for the given x.