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

#include <AlgebraicOperations.h>

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

Public Member Functions

 DividedFunction (const Ptr< const IFunction< R, D >> &function1, const Ptr< const IFunction< R, D >> &function2)
 
virtual D::I getDomain () const override
 
virtual double 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< double, 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 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< double, D >
virtual Interval< double > getRange () const override
 Returns the valid range of the function as an interval. More...
 
virtual Interval< double > 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 bool isNonZero (const typename D::I &i) const override
 Returns true if the function value is non-zero in the given domain. More...
 
virtual double getMin () const override
 Returns the minimum value for the whole domain. More...
 
virtual double getMin (const typename D::I &i) const override
 Returns the minimum value for the given domain. More...
 
virtual double getMax () const override
 Returns the maximum value for the whole domain. More...
 
virtual double getMax (const typename D::I &i) const override
 Returns the maximum value for the given domain. More...
 
virtual double getMean () const override
 Returns the mean value for the whole domain. More...
 
virtual double getMean (const typename D::I &i) const override
 Returns the mean value for the given domain. More...
 
virtual double getIntegral () const override
 Returns the integral value for the whole domain. More...
 
virtual double getIntegral (const typename D::I &i) const override
 Returns the integral value for the given domain. More...
 
virtual const Ptr< const IFunction< double, D > > add (const Ptr< const IFunction< double, D >> &o) const override
 Adds the provided function to this function. More...
 
virtual const Ptr< const IFunction< double, D > > subtract (const Ptr< const IFunction< double, D >> &o) const override
 Substracts the provided function from this function. More...
 
virtual const Ptr< const IFunction< double, 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< double, 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 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::IFunction< double, D >
virtual ~IFunction ()
 

Protected Attributes

const Ptr< const IFunction< R, D > > function1
 
const Ptr< const IFunction< R, D > > function2
 

Constructor & Destructor Documentation

◆ DividedFunction()

template<typename R , typename D >
inet::math::DividedFunction< R, D >::DividedFunction ( const Ptr< const IFunction< R, D >> &  function1,
const Ptr< const IFunction< R, D >> &  function2 
)
inline

Member Function Documentation

◆ getDomain()

template<typename R , typename D >
virtual D::I inet::math::DividedFunction< R, D >::getDomain ( ) const
inlineoverridevirtual
270  {
271  return function1->getDomain().getIntersected(function2->getDomain());
272  }

◆ getValue()

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

274  {
275  return unit(function1->getValue(p) / function2->getValue(p)).get();
276  }

◆ isFinite()

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

326 { return false; }

◆ partition()

template<typename R , typename D >
virtual void inet::math::DividedFunction< R, D >::partition ( const typename D::I &  i,
const std::function< void(const typename D::I &, const IFunction< double, 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< double, D >.

278  {
279  function1->partition(i, [&] (const typename D::I& i1, const IFunction<R, D> *f1) {
280  // NOTE: optimization for 0 / x
281  if (auto f1c = dynamic_cast<const ConstantFunction<R, D> *>(f1)) {
282  if (toDouble(f1c->getConstantValue()) == 0 && function2->isNonZero(i1)) {
283  ConstantFunction<double, D> g(0);
284  callback(i1, &g);
285  return;
286  }
287  }
288  function2->partition(i1, [&] (const typename D::I& i2, const IFunction<R, D> *f2) {
289  if (auto f1c = dynamic_cast<const ConstantFunction<R, D> *>(f1)) {
290  if (auto f2c = dynamic_cast<const ConstantFunction<R, D> *>(f2)) {
291  ConstantFunction<double, D> g(unit(f1c->getConstantValue() / f2c->getConstantValue()).get());
292  callback(i2, &g);
293  }
294  else if (auto f2l = dynamic_cast<const UnilinearFunction<R, D> *>(f2)) {
295  UnireciprocalFunction<double, D> g(0, toDouble(f1c->getConstantValue()), f2l->getA(), f2l->getB(), f2l->getDimension());
296  simplifyAndCall(i2, &g, callback);
297  }
298  else
299  throw cRuntimeError("TODO");
300  }
301  else if (auto f1l = dynamic_cast<const UnilinearFunction<R, D> *>(f1)) {
302  if (auto f2c = dynamic_cast<const ConstantFunction<R, D> *>(f2)) {
303  UnilinearFunction<double, D> g(i2.getLower(), i2.getUpper(), unit(f1l->getValue(i2.getLower()) / f2c->getConstantValue()).get(), unit(f1l->getValue(i2.getUpper()) / f2c->getConstantValue()).get(), f1l->getDimension());
304  simplifyAndCall(i2, &g, callback);
305  }
306  else if (auto f2l = dynamic_cast<const UnilinearFunction<R, D> *>(f2)) {
307  if (f1l->getDimension() == f2l->getDimension()) {
308  UnireciprocalFunction<double, D> g(f1l->getA(), f1l->getB(), f2l->getA(), f2l->getB(), f2l->getDimension());
309  simplifyAndCall(i2, &g, callback);
310  }
311  else {
312  throw cRuntimeError("TODO");
313 // BireciprocalFunction<double, D> g(...);
314 // simplifyAndCall(i2, &g, f);
315  }
316  }
317  else
318  throw cRuntimeError("TODO");
319  }
320  else
321  throw cRuntimeError("TODO");
322  });
323  });
324  }

◆ printStructure()

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

328  {
329  os << "(/ ";
330  function1->printStructure(os, level + 3);
331  os << "\n" << std::string(level + 3, ' ');
332  function2->printStructure(os, level + 3);
333  os << ")";
334  }

Member Data Documentation

◆ function1

template<typename R , typename D >
const Ptr<const IFunction<R, D> > inet::math::DividedFunction< R, D >::function1
protected

◆ function2

template<typename R , typename D >
const Ptr<const IFunction<R, D> > inet::math::DividedFunction< R, D >::function2
protected

The documentation for this class was generated from the following file:
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::units::unit
pow< internal::none, 0 > unit
Definition: Units.h:72
inet::math::simplifyAndCall
void simplifyAndCall(const typename D::I &i, const IFunction< R, D > *f, const std::function< void(const typename D::I &, const IFunction< R, D > *)> callback)
Definition: PrimitiveFunctions.h:776
inet::math::DividedFunction::function1
const Ptr< const IFunction< R, D > > function1
Definition: AlgebraicOperations.h:264
inet::math::DividedFunction::function2
const Ptr< const IFunction< R, D > > function2
Definition: AlgebraicOperations.h:265