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

#include <PrimitiveFunctions.h>

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

Public Member Functions

 PeriodicallyInterpolated2DFunction (X startX, X endX, int sizeX, Y startY, Y endY, int sizeY, const IInterpolator< X, R > &interpolatorX, const IInterpolator< Y, R > &interpolatorY, const std::vector< R > &rs)
 
virtual R getValue (const Point< X, Y > &p) const override
 
virtual void partition (const Interval< X, Y > &i, const std::function< void(const Interval< X, Y > &, const IFunction< R, Domain< X, Y >> *)> callback) const override
 
- Public Member Functions inherited from inet::math::FunctionBase< R, Domain< X, Y > >
virtual void partition (const typename Domain< X, Y > ::I &i, const std::function< void(const typename Domain< X, Y > ::I &, const IFunction< R, Domain< X, Y > > *)> 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, Y > ::I &i) const override
 Returns the valid range of the function as an interval for the given domain. More...
 
virtual Domain< X, Y > ::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, Y > ::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, Y > ::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, Y > ::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, Y > ::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, Y > ::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, Y > ::I &i) const override
 Returns the integral value for the given domain. More...
 
virtual const Ptr< const IFunction< R, Domain< X, Y > > > add (const Ptr< const IFunction< R, Domain< X, Y > >> &o) const override
 Adds the provided function to this function. More...
 
virtual const Ptr< const IFunction< R, Domain< X, Y > > > subtract (const Ptr< const IFunction< R, Domain< X, Y > >> &o) const override
 Substracts the provided function from this function. More...
 
virtual const Ptr< const IFunction< R, Domain< X, Y > > > multiply (const Ptr< const IFunction< double, Domain< X, Y > >> &o) const override
 Multiplies the provided function with this function. More...
 
virtual const Ptr< const IFunction< double, Domain< X, Y > > > divide (const Ptr< const IFunction< R, Domain< X, Y > >> &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, Y > ::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, Y > ::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, Y > ::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, Y > >
virtual ~IFunction ()
 
virtual R getValue (const typename Domain< X, Y > ::P &p) const=0
 Returns the value of the function at the given point. More...
 

Protected Member Functions

virtual R getValueInterpolatedAlongX (X x, int indexX, int indexY) const
 
void call (const Interval< X, Y > &i, const std::function< void(const Interval< X, Y > &, const IFunction< R, Domain< X, Y >> *)> callback) const
 

Protected Attributes

const X startX
 
const X endX
 
const X stepX
 
int sizeX
 
const Y startY
 
const Y endY
 
const Y stepY
 
int sizeY
 
const IInterpolator< X, R > & interpolatorX
 
const IInterpolator< Y, R > & interpolatorY
 
const std::vector< R > rs
 

Constructor & Destructor Documentation

◆ PeriodicallyInterpolated2DFunction()

template<typename R , typename X , typename Y >
inet::math::PeriodicallyInterpolated2DFunction< R, X, Y >::PeriodicallyInterpolated2DFunction ( startX,
endX,
int  sizeX,
startY,
endY,
int  sizeY,
const IInterpolator< X, R > &  interpolatorX,
const IInterpolator< Y, R > &  interpolatorY,
const std::vector< R > &  rs 
)
inline
609  :
610  startX(startX), endX(endX), stepX((endX - startX) / (sizeX - 1)), sizeX(sizeX),
611  startY(startY), endY(endY), stepY((endY - startY) / (sizeY - 1)), sizeY(sizeY),
613  {
614  ASSERT(rs.size() == sizeX * sizeY);
615  }

Member Function Documentation

◆ call()

template<typename R , typename X , typename Y >
void inet::math::PeriodicallyInterpolated2DFunction< R, X, Y >::call ( const Interval< X, Y > &  i,
const std::function< void(const Interval< X, Y > &, const IFunction< R, Domain< X, Y >> *)>  callback 
) const
inlineprotected
601  {
602  if (!i.isEmpty()) {
603  ConstantFunction<R, Domain<X, Y>> g(R(0));
604  callback(i, &g);
605  }
606  }

◆ getValue()

template<typename R , typename X , typename Y >
virtual R inet::math::PeriodicallyInterpolated2DFunction< R, X, Y >::getValue ( const Point< X, Y > &  p) const
inlineoverridevirtual
617  {
618  X x = std::get<0>(p);
619  Y y = std::get<1>(p);
620  int indexX = std::floor(toDouble(x - startX) / toDouble(stepX));
621  int indexY = std::floor(toDouble(y - startY) / toDouble(stepY));
622  if (indexX < 0 || indexX > sizeX - 2 || indexY < 0 || indexY > sizeY - 2)
623  return R(0);
624  else {
625  R r1 = getValueInterpolatedAlongX(x, indexX, indexY);
626  R r2 = getValueInterpolatedAlongX(x, indexX, indexY + 1);
627  Y y1 = startY + stepY * indexY;
628  Y y2 = y1 + stepY;
629  return interpolatorY.getValue(y1, r1, y2, r2, y);
630  }
631  }

◆ getValueInterpolatedAlongX()

template<typename R , typename X , typename Y >
virtual R inet::math::PeriodicallyInterpolated2DFunction< R, X, Y >::getValueInterpolatedAlongX ( x,
int  indexX,
int  indexY 
) const
inlineprotectedvirtual
593  {
594  R r1 = rs[sizeX * indexY + indexX];
595  R r2 = rs[sizeX * indexY + indexX + 1];
596  X x1 = startX + stepX * indexX;
597  X x2 = x1 + stepX;
598  return interpolatorX.getValue(x1, r1, x2, r2, x);
599  }

◆ partition()

template<typename R , typename X , typename Y >
virtual void inet::math::PeriodicallyInterpolated2DFunction< R, X, Y >::partition ( const Interval< X, Y > &  i,
const std::function< void(const Interval< X, Y > &, const IFunction< R, Domain< X, Y >> *)>  callback 
) const
inlineoverridevirtual
633  {
634  call(i.getIntersected(Interval<X, Y>(Point<X, Y>(getLowerBound<X>(), getLowerBound<Y>()), Point<X, Y>(X(startX), Y(startY)), 0b00, 0b00, 0b00)), callback);
635  call(i.getIntersected(Interval<X, Y>(Point<X, Y>(X(startX), getLowerBound<Y>()), Point<X, Y>(X(endX), Y(startY)), 0b10, 0b00, 0b00)), callback);
636  call(i.getIntersected(Interval<X, Y>(Point<X, Y>(X(endX), getLowerBound<Y>()), Point<X, Y>(getUpperBound<X>(), Y(startY)), 0b10, 0b00, 0b00)), callback);
637 
638  call(i.getIntersected(Interval<X, Y>(Point<X, Y>(getLowerBound<X>(), Y(startY)), Point<X, Y>(X(startX), Y(endY)), 0b01, 0b00, 0b00)), callback);
639  const auto& i1 = i.getIntersected(Interval<X, Y>(Point<X, Y>(X(startX), Y(startY)), Point<X, Y>(X(endX), Y(endY)), 0b11, 0b00, 0b00));
640  if (!i1.isEmpty()) {
641  int startIndexX = std::max(0, (int)std::floor(toDouble(std::get<0>(i.getLower()) - startX) / toDouble(stepX)));
642  int endIndexX = std::min(sizeX - 1, (int)std::ceil(toDouble(std::get<0>(i.getUpper()) - startX) / toDouble(stepX)));
643  for (int indexX = startIndexX; indexX < endIndexX; indexX++) {
644  int startIndexY = std::max(0, (int)std::floor(toDouble(std::get<1>(i.getLower()) - startY) / toDouble(stepY)));
645  int endIndexY = std::min(sizeY - 1, (int)std::ceil(toDouble(std::get<1>(i.getUpper()) - startY) / toDouble(stepY)));
646  for (int indexY = startIndexY; indexY < endIndexY; indexY++) {
647  Point<X, Y> startPoint(startX + stepX * indexX, startY + stepY * indexY);
648  Point<X, Y> endPoint(startX + stepX * (indexX + 1), startY + stepY * (indexY + 1));
649  const auto& i3 = i.getIntersected(Interval<X, Y>(startPoint, endPoint, 0b11, 0b00, 0b00));
650  if (!i3.isEmpty()) {
651  if (dynamic_cast<const ConstantInterpolatorBase<X, R> *>(&interpolatorX) && dynamic_cast<const ConstantInterpolatorBase<Y, R> *>(&interpolatorY)) {
652  R r = getValue((startPoint + endPoint) / 2);
653  ConstantFunction<R, Domain<X, Y>> g(r);
654  callback(i3, &g);
655  }
656  else
657  throw cRuntimeError("TODO");
658  }
659  }
660  }
661  }
662  call(i.getIntersected(Interval<X, Y>(Point<X, Y>(X(endX), Y(startY)), Point<X, Y>(getUpperBound<X>(), Y(endY)), 0b11, 0b00, 0b00)), callback);
663 
664  call(i.getIntersected(Interval<X, Y>(Point<X, Y>(getLowerBound<X>(), Y(endY)), Point<X, Y>(X(startX), getUpperBound<Y>()), 0b01, 0b00, 0b00)), callback);
665  call(i.getIntersected(Interval<X, Y>(Point<X, Y>(X(startX), Y(endY)), Point<X, Y>(X(endX), getUpperBound<Y>()), 0b11, 0b00, 0b00)), callback);
666  call(i.getIntersected(Interval<X, Y>(Point<X, Y>(X(endX), Y(endY)), Point<X, Y>(getUpperBound<X>(), getUpperBound<Y>()), 0b11, 0b00, 0b00)), callback);
667  }

Member Data Documentation

◆ endX

template<typename R , typename X , typename Y >
const X inet::math::PeriodicallyInterpolated2DFunction< R, X, Y >::endX
protected

◆ endY

template<typename R , typename X , typename Y >
const Y inet::math::PeriodicallyInterpolated2DFunction< R, X, Y >::endY
protected

◆ interpolatorX

template<typename R , typename X , typename Y >
const IInterpolator<X, R>& inet::math::PeriodicallyInterpolated2DFunction< R, X, Y >::interpolatorX
protected

◆ interpolatorY

template<typename R , typename X , typename Y >
const IInterpolator<Y, R>& inet::math::PeriodicallyInterpolated2DFunction< R, X, Y >::interpolatorY
protected

◆ rs

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

◆ sizeX

template<typename R , typename X , typename Y >
int inet::math::PeriodicallyInterpolated2DFunction< R, X, Y >::sizeX
protected

◆ sizeY

template<typename R , typename X , typename Y >
int inet::math::PeriodicallyInterpolated2DFunction< R, X, Y >::sizeY
protected

◆ startX

template<typename R , typename X , typename Y >
const X inet::math::PeriodicallyInterpolated2DFunction< R, X, Y >::startX
protected

◆ startY

template<typename R , typename X , typename Y >
const Y inet::math::PeriodicallyInterpolated2DFunction< R, X, Y >::startY
protected

◆ stepX

template<typename R , typename X , typename Y >
const X inet::math::PeriodicallyInterpolated2DFunction< R, X, Y >::stepX
protected

◆ stepY

template<typename R , typename X , typename Y >
const Y inet::math::PeriodicallyInterpolated2DFunction< R, X, Y >::stepY
protected

The documentation for this class was generated from the following file:
inet::math::PeriodicallyInterpolated2DFunction::endX
const X endX
Definition: PrimitiveFunctions.h:581
inet::sctp::min
double min(const double a, const double b)
Returns the minimum of a and b.
Definition: SctpAssociation.h:261
inet::math::PeriodicallyInterpolated2DFunction::interpolatorX
const IInterpolator< X, R > & interpolatorX
Definition: PrimitiveFunctions.h:588
inet::math::PeriodicallyInterpolated2DFunction::rs
const std::vector< R > rs
Definition: PrimitiveFunctions.h:590
inet::math::toDouble
double toDouble(const T v)
Definition: Point.h:28
inet::math::PeriodicallyInterpolated2DFunction::getValue
virtual R getValue(const Point< X, Y > &p) const override
Definition: PrimitiveFunctions.h:617
inet::math::PeriodicallyInterpolated2DFunction::startY
const Y startY
Definition: PrimitiveFunctions.h:584
inet::units::units::g
milli< kg >::type g
Definition: Units.h:1071
inet::math::PeriodicallyInterpolated2DFunction::endY
const Y endY
Definition: PrimitiveFunctions.h:585
inet::units::constants::R
const value< double, compose< units::J, compose< pow< units::mol, -1 >, pow< units::kg, -1 > > > > R(8.314472)
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.
inet::math::PeriodicallyInterpolated2DFunction::interpolatorY
const IInterpolator< Y, R > & interpolatorY
Definition: PrimitiveFunctions.h:589
inet::math::PeriodicallyInterpolated2DFunction::sizeY
int sizeY
Definition: PrimitiveFunctions.h:587
inet::math::PeriodicallyInterpolated2DFunction::getValueInterpolatedAlongX
virtual R getValueInterpolatedAlongX(X x, int indexX, int indexY) const
Definition: PrimitiveFunctions.h:593
inet::math::PeriodicallyInterpolated2DFunction::stepY
const Y stepY
Definition: PrimitiveFunctions.h:586
inet::math::PeriodicallyInterpolated2DFunction::stepX
const X stepX
Definition: PrimitiveFunctions.h:582
inet::math::PeriodicallyInterpolated2DFunction::startX
const X startX
Definition: PrimitiveFunctions.h:580
inet::math::PeriodicallyInterpolated2DFunction::sizeX
int sizeX
Definition: PrimitiveFunctions.h:583
inet::math::PeriodicallyInterpolated2DFunction::call
void call(const Interval< X, Y > &i, const std::function< void(const Interval< X, Y > &, const IFunction< R, Domain< X, Y >> *)> callback) const
Definition: PrimitiveFunctions.h:601