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

Reciprocal in a given dimension and constant in the others. More...

#include <PrimitiveFunctions.h>

Inheritance diagram for inet::math::UnireciprocalFunction< R, D >:
inet::math::FunctionBase< R, D > inet::math::IFunction< R, D >

Public Member Functions

 UnireciprocalFunction (double a, double b, double c, double d, int dimension)
 
virtual int getDimension () const
 
virtual R getValue (const typename D::P &p) const override
 Returns the value of the function at the given point. More...
 
virtual void partition (const typename D::I &i, const std::function< void(const typename D::I &, const IFunction< R, D > *)> callback) const override
 Subdivides the provided domain and calls back f with the subdomains and the corresponding potentially simpler domain limited functions. More...
 
virtual R getMin (const typename D::I &i) const override
 Returns the minimum value for the given domain. More...
 
virtual R getMax (const typename D::I &i) const override
 Returns the maximum value for the given domain. More...
 
virtual R getMean (const typename D::I &i) const override
 Returns the mean value for the given domain. More...
 
virtual R getIntegral (const typename D::I &i) const override
 Returns the integral value for the given domain. More...
 
virtual void printPartition (std::ostream &os, const typename D::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...
 
- Public Member Functions inherited from inet::math::FunctionBase< R, D >
virtual Interval< R > getRange () const override
 Returns the valid range of the function as an interval. More...
 
virtual Interval< R > getRange (const typename D::I &i) const override
 Returns the valid range of the function as an interval for the given domain. More...
 
virtual D::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 D::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 D::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 getMax () const override
 Returns the maximum value for the whole domain. More...
 
virtual R getMean () const override
 Returns the mean value for the whole domain. More...
 
virtual R getIntegral () const override
 Returns the integral value for the whole domain. More...
 
virtual const Ptr< const IFunction< R, D > > add (const Ptr< const IFunction< R, D >> &o) const override
 Adds the provided function to this function. More...
 
virtual const Ptr< const IFunction< R, D > > subtract (const Ptr< const IFunction< R, D >> &o) const override
 Substracts the provided function from this function. More...
 
virtual const Ptr< const IFunction< R, D > > multiply (const Ptr< const IFunction< double, D >> &o) const override
 Multiplies the provided function with this function. More...
 
virtual const Ptr< const IFunction< double, D > > divide (const Ptr< const IFunction< R, D >> &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 D::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 D::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 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, D >
virtual ~IFunction ()
 

Protected Member Functions

virtual double getIntegralFunctionValue (const typename D::P &p) const
 

Protected Attributes

const double a
 
const double b
 
const double c
 
const double d
 
const int dimension
 

Detailed Description

template<typename R, typename D>
class inet::math::UnireciprocalFunction< R, D >

Reciprocal in a given dimension and constant in the others.

Constructor & Destructor Documentation

◆ UnireciprocalFunction()

template<typename R , typename D >
inet::math::UnireciprocalFunction< R, D >::UnireciprocalFunction ( double  a,
double  b,
double  c,
double  d,
int  dimension 
)
inline
242 : a(a), b(b), c(c), d(d), dimension(dimension) {}

Member Function Documentation

◆ getDimension()

template<typename R , typename D >
virtual int inet::math::UnireciprocalFunction< R, D >::getDimension ( ) const
inlinevirtual
244 { return dimension; }

◆ getIntegral()

template<typename R , typename D >
virtual R inet::math::UnireciprocalFunction< R, D >::getIntegral ( const typename D::I &  i) const
inlineoverridevirtual

Returns the integral value for the given domain.

Reimplemented from inet::math::FunctionBase< R, D >.

275  {
276  return R(getIntegralFunctionValue(i.getUpper()) - getIntegralFunctionValue(i.getLower()));
277  }

◆ getIntegralFunctionValue()

template<typename R , typename D >
virtual double inet::math::UnireciprocalFunction< R, D >::getIntegralFunctionValue ( const typename D::P &  p) const
inlineprotectedvirtual
235  {
236  // https://www.wolframalpha.com/input/?i=integrate+(a+*+x+%2B+b)+%2F+(c+*+x+%2B+d)
237  double x = p.get(dimension);
238  return (a * c * x + (b * c - a * d) * std::log(d + c * x)) / (c * c);
239  }

◆ getMax()

template<typename R , typename D >
virtual R inet::math::UnireciprocalFunction< R, D >::getMax ( const typename D::I &  i) const
inlineoverridevirtual

Returns the maximum value for the given domain.

Reimplemented from inet::math::FunctionBase< R, D >.

263  {
264  double x = -d / c;
265  if (i.getLower().get(dimension) < x && x < i.getUpper().get(dimension))
266  return getUpperBound<R>();
267  else
268  return math::maxnan(getValue(i.getLower()), getValue(i.getUpper()));
269  }

◆ getMean()

template<typename R , typename D >
virtual R inet::math::UnireciprocalFunction< R, D >::getMean ( const typename D::I &  i) const
inlineoverridevirtual

Returns the mean value for the given domain.

Reimplemented from inet::math::FunctionBase< R, D >.

271  {
272  return getIntegral(i) / (i.getUpper().get(dimension) - i.getLower().get(dimension));
273  }

◆ getMin()

template<typename R , typename D >
virtual R inet::math::UnireciprocalFunction< R, D >::getMin ( const typename D::I &  i) const
inlineoverridevirtual

Returns the minimum value for the given domain.

Reimplemented from inet::math::FunctionBase< R, D >.

255  {
256  double x = -d / c;
257  if (i.getLower().get(dimension) < x && x < i.getUpper().get(dimension))
258  return getLowerBound<R>();
259  else
260  return math::minnan(getValue(i.getLower()), getValue(i.getUpper()));
261  }

◆ getValue()

template<typename R , typename D >
virtual R inet::math::UnireciprocalFunction< R, D >::getValue ( const typename D::P &  p) const
inlineoverridevirtual

Returns the value of the function at the given point.

The returned value falls into the range of the function. The provided point must fall into the domain of the function.

Implements inet::math::IFunction< R, D >.

246  {
247  double x = p.get(dimension);
248  return R(a * x + b) / (c * x + d);
249  }

◆ partition()

template<typename R , typename D >
virtual void inet::math::UnireciprocalFunction< R, D >::partition ( const typename D::I &  i,
const std::function< void(const typename D::I &, const IFunction< R, D > *)>  f 
) const
inlineoverridevirtual

Subdivides the provided domain and calls back f with the subdomains and the corresponding potentially simpler domain limited functions.

Reimplemented from inet::math::FunctionBase< R, D >.

251  {
252  callback(i, this);
253  }

◆ printPartition()

template<typename R , typename D >
virtual void inet::math::UnireciprocalFunction< R, D >::printPartition ( std::ostream &  os,
const typename D::I &  i,
int  level = 0 
) const
inlineoverridevirtual

Prints a single partition of this function in a human readable form to the provided stream for the given domain.

Reimplemented from inet::math::FunctionBase< R, D >.

279  {
280  os << "reciprocal in dim. " << dimension << " over " << i << "\n"
281  << std::string(level + 2, ' ') << "→ " << getValue(i.getLower()) << " … " << getValue(i.getUpper()) << std::endl;
282  }

Member Data Documentation

◆ a

template<typename R , typename D >
const double inet::math::UnireciprocalFunction< R, D >::a
protected

◆ b

template<typename R , typename D >
const double inet::math::UnireciprocalFunction< R, D >::b
protected

◆ c

template<typename R , typename D >
const double inet::math::UnireciprocalFunction< R, D >::c
protected

◆ d

template<typename R , typename D >
const double inet::math::UnireciprocalFunction< R, D >::d
protected

◆ dimension

template<typename R , typename D >
const int inet::math::UnireciprocalFunction< R, D >::dimension
protected

The documentation for this class was generated from the following file:
inet::math::UnireciprocalFunction::b
const double b
Definition: PrimitiveFunctions.h:229
inet::math::UnireciprocalFunction::getIntegralFunctionValue
virtual double getIntegralFunctionValue(const typename D::P &p) const
Definition: PrimitiveFunctions.h:235
inet::math::maxnan
const T maxnan(const T &a, const T &b)
This function properly and symmetrically handles NaNs in contrast with std::max and std::fmax.
Definition: INETMath.h:234
inet::units::constants::R
const value< double, compose< units::J, compose< pow< units::mol, -1 >, pow< units::kg, -1 > > > > R(8.314472)
inet::math::UnireciprocalFunction::dimension
const int dimension
Definition: PrimitiveFunctions.h:232
inet::math::FunctionBase::getIntegral
virtual R getIntegral() const override
Returns the integral value for the whole domain.
Definition: FunctionBase.h:103
inet::math::UnireciprocalFunction::d
const double d
Definition: PrimitiveFunctions.h:231
inet::math::UnireciprocalFunction::getValue
virtual R getValue(const typename D::P &p) const override
Returns the value of the function at the given point.
Definition: PrimitiveFunctions.h:246
inet::math::minnan
const T minnan(const T &a, const T &b)
This function properly and symmetrically handles NaNs in contrast with std::min and std::fmin.
Definition: INETMath.h:216
inet::math::UnireciprocalFunction::a
const double a
Definition: PrimitiveFunctions.h:228
inet::math::UnireciprocalFunction::c
const double c
Definition: PrimitiveFunctions.h:230