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

Linear in one dimension and constant in the others. More...

#include <PrimitiveFunctions.h>

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

Public Member Functions

 UnilinearFunction (typename D::P lower, typename D::P upper, R rLower, R rUpper, int dimension)
 
virtual const D::P & getLower () const
 
virtual const D::P & getUpper () const
 
virtual R getRLower () const
 
virtual R getRUpper () const
 
virtual int getDimension () const
 
virtual double getA () const
 
virtual double getB () const
 
virtual Interval< R > getRange () const override
 Returns the valid range of the function as an interval. More...
 
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 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 typename D::I &i) const override
 Returns true if the function value is non-zero in the given domain. 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 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...
 
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::FunctionBase< R, D >
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 isNonZero () const override
 Returns true if the function value is non-zero in the whole 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 R getIntegral (const typename D::I &i) const override
 Returns the integral value for the given 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...
 
- Public Member Functions inherited from inet::math::IFunction< R, D >
virtual ~IFunction ()
 

Protected Attributes

const D::P lower
 
const D::P upper
 
const R rLower
 
const R rUpper
 
const int dimension
 

Detailed Description

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

Linear in one dimension and constant in the others.

Constructor & Destructor Documentation

◆ UnilinearFunction()

template<typename R , typename D >
inet::math::UnilinearFunction< R, D >::UnilinearFunction ( typename D::P  lower,
typename D::P  upper,
rLower,
rUpper,
int  dimension 
)
inline

Member Function Documentation

◆ getA()

template<typename R , typename D >
virtual double inet::math::UnilinearFunction< R, D >::getA ( ) const
inlinevirtual
76 { return toDouble(rUpper - rLower) / toDouble(upper.get(dimension) - lower.get(dimension)); }

◆ getB()

template<typename R , typename D >
virtual double inet::math::UnilinearFunction< R, D >::getB ( ) const
inlinevirtual
77 { return (toDouble(rLower) * upper.get(dimension) - toDouble(rUpper) * lower.get(dimension)) / (upper.get(dimension) - lower.get(dimension)); }

◆ getDimension()

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

◆ getLower()

template<typename R , typename D >
virtual const D::P& inet::math::UnilinearFunction< R, D >::getLower ( ) const
inlinevirtual
70 { return lower; }

◆ getMax()

template<typename R , typename D >
virtual R inet::math::UnilinearFunction< 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 >.

102  {
103  return math::maxnan(getValue(i.getLower()), getValue(i.getUpper()));
104  }

◆ getMean()

template<typename R , typename D >
virtual R inet::math::UnilinearFunction< 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 >.

106  {
107  return getValue((i.getLower() + i.getUpper()) / 2);
108  }

◆ getMin()

template<typename R , typename D >
virtual R inet::math::UnilinearFunction< 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 >.

98  {
99  return math::minnan(getValue(i.getLower()), getValue(i.getUpper()));
100  }

◆ getRange()

template<typename R , typename D >
virtual Interval<R> inet::math::UnilinearFunction< R, D >::getRange ( ) const
inlineoverridevirtual

Returns the valid range of the function as an interval.

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

79 { return Interval<R>(math::minnan(rLower, rUpper), math::maxnan(rLower, rUpper), 0b1, 0b1, 0b0); }

◆ getRLower()

template<typename R , typename D >
virtual R inet::math::UnilinearFunction< R, D >::getRLower ( ) const
inlinevirtual
72 { return rLower; }

Referenced by inet::math::simplifyAndCall().

◆ getRUpper()

template<typename R , typename D >
virtual R inet::math::UnilinearFunction< R, D >::getRUpper ( ) const
inlinevirtual
73 { return rUpper; }

Referenced by inet::math::simplifyAndCall().

◆ getUpper()

template<typename R , typename D >
virtual const D::P& inet::math::UnilinearFunction< R, D >::getUpper ( ) const
inlinevirtual
71 { return upper; }

◆ getValue()

template<typename R , typename D >
virtual R inet::math::UnilinearFunction< 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 >.

81  {
82  double alpha = (p - lower).get(dimension) / (upper - lower).get(dimension);
83  return rLower * (1 - alpha) + rUpper * alpha;
84  }

◆ isFinite()

template<typename R , typename D >
virtual bool inet::math::UnilinearFunction< R, D >::isFinite ( const typename D::I &  i) const
inlineoverridevirtual

Returns true if the function value is finite in the given domain.

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

90  {
91  return std::isfinite(toDouble(rLower)) && std::isfinite(toDouble(rUpper));
92  }

◆ isNonZero()

template<typename R , typename D >
virtual bool inet::math::UnilinearFunction< R, D >::isNonZero ( const typename D::I &  i) const
inlineoverridevirtual

Returns true if the function value is non-zero in the given domain.

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

94  {
95  return rLower != R(0) || rUpper != R(0);
96  }

◆ partition()

template<typename R , typename D >
virtual void inet::math::UnilinearFunction< 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 >.

86  {
87  callback(i, this);
88  }

◆ printPartition()

template<typename R , typename D >
virtual void inet::math::UnilinearFunction< 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 >.

110  {
111  os << "linear in dim. " << dimension << " over " << i << "\n"
112  << std::string(level + 2, ' ') << "→ " << getValue(i.getLower()) << " … " << getValue(i.getUpper()) << std::endl;
113  }

◆ printStructure()

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

Prints the internal data structure of this function in a human readable form to the provided stream.

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

115  {
116  os << "Linear, " << lower << " … " << upper << " → " << rLower << " … " << rUpper;
117  }

Member Data Documentation

◆ dimension

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

◆ lower

template<typename R , typename D >
const D::P inet::math::UnilinearFunction< R, D >::lower
protected

◆ rLower

template<typename R , typename D >
const R inet::math::UnilinearFunction< R, D >::rLower
protected

◆ rUpper

template<typename R , typename D >
const R inet::math::UnilinearFunction< R, D >::rUpper
protected

◆ upper

template<typename R , typename D >
const D::P inet::math::UnilinearFunction< R, D >::upper
protected

The documentation for this class was generated from the following file:
inet::math::UnilinearFunction::upper
const D::P upper
Definition: PrimitiveFunctions.h:61
inet::math::toDouble
double toDouble(const T v)
Definition: Point.h:28
inet::math::UnilinearFunction::lower
const D::P lower
Definition: PrimitiveFunctions.h:60
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::math::UnilinearFunction::rUpper
const R rUpper
Definition: PrimitiveFunctions.h:63
inet::units::constants::R
const value< double, compose< units::J, compose< pow< units::mol, -1 >, pow< units::kg, -1 > > > > R(8.314472)
inet::math::UnilinearFunction::rLower
const R rLower
Definition: PrimitiveFunctions.h:62
inet::math::UnilinearFunction::getValue
virtual R getValue(const typename D::P &p) const override
Returns the value of the function at the given point.
Definition: PrimitiveFunctions.h:81
inet::math::UnilinearFunction::dimension
const int dimension
Definition: PrimitiveFunctions.h:64
inet::units::constants::alpha
const value< double, units::unit > alpha(7.2973525376e-3)
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