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

#include <AlgebraicOperations.h>

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

Public Member Functions

 SubtractedFunction (const Ptr< const IFunction< R, D >> &function1, const Ptr< const IFunction< R, D >> &function2)
 
virtual D::I getDomain () const override
 Returns the valid domain 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 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 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 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 R getMin () const override
 Returns the minimum value for the whole 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 override
 Returns the maximum value for the whole 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 override
 Returns the mean value for the whole 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 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...
 
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< R, D >
virtual ~IFunction ()
 

Protected Attributes

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

Constructor & Destructor Documentation

◆ SubtractedFunction()

template<typename R , typename D >
inet::math::SubtractedFunction< R, D >::SubtractedFunction ( const Ptr< const IFunction< R, D >> &  function1,
const Ptr< const IFunction< R, D >> &  function2 
)
inline
121  :
123  {}

Member Function Documentation

◆ getDomain()

template<typename R , typename D >
virtual D::I inet::math::SubtractedFunction< R, D >::getDomain ( ) const
inlineoverridevirtual

Returns the valid domain of the function as an interval.

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

125  {
126  return function1->getDomain().getIntersected(function2->getDomain());
127  }

◆ getValue()

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

129  {
130  return function1->getValue(p) - function2->getValue(p);
131  }

◆ isFinite()

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

170  {
171  return function1->isFinite(i) & function2->isFinite(i);
172  }

◆ partition()

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

133  {
134  function1->partition(i, [&] (const typename D::I& i1, const IFunction<R, D> *f1) {
135  function2->partition(i1, [&] (const typename D::I& i2, const IFunction<R, D> *f2) {
136  if (auto f1c = dynamic_cast<const ConstantFunction<R, D> *>(f1)) {
137  if (auto f2c = dynamic_cast<const ConstantFunction<R, D> *>(f2)) {
138  ConstantFunction<R, D> g(f1c->getConstantValue() - f2c->getConstantValue());
139  callback(i2, &g);
140  }
141  else if (auto f2l = dynamic_cast<const UnilinearFunction<R, D> *>(f2)) {
142  UnilinearFunction<R, D> g(i2.getLower(), i2.getUpper(), f2l->getValue(i2.getLower()) - f1c->getConstantValue(), f2l->getValue(i2.getUpper()) - f1c->getConstantValue(), f2l->getDimension());
143  simplifyAndCall(i2, &g, callback);
144  }
145  else
146  throw cRuntimeError("TODO");
147  }
148  else if (auto f1l = dynamic_cast<const UnilinearFunction<R, D> *>(f1)) {
149  if (auto f2c = dynamic_cast<const ConstantFunction<R, D> *>(f2)) {
150  UnilinearFunction<R, D> g(i2.getLower(), i2.getUpper(), f1l->getValue(i2.getLower()) - f2c->getConstantValue(), f1l->getValue(i2.getUpper()) - f2c->getConstantValue(), f1l->getDimension());
151  simplifyAndCall(i2, &g, callback);
152  }
153  else if (auto f2l = dynamic_cast<const UnilinearFunction<R, D> *>(f2)) {
154  if (f1l->getDimension() == f2l->getDimension()) {
155  UnilinearFunction<R, D> g(i2.getLower(), i2.getUpper(), f1l->getValue(i2.getLower()) - f2l->getValue(i2.getLower()), f1l->getValue(i2.getUpper()) - f2l->getValue(i2.getUpper()), f1l->getDimension());
156  simplifyAndCall(i2, &g, callback);
157  }
158  else
159  throw cRuntimeError("TODO");
160  }
161  else
162  throw cRuntimeError("TODO");
163  }
164  else
165  throw cRuntimeError("TODO");
166  });
167  });
168  }

◆ printStructure()

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

174  {
175  os << "(- ";
176  function1->printStructure(os, level + 3);
177  os << "\n" << std::string(level + 3, ' ');
178  function2->printStructure(os, level + 3);
179  os << ")";
180  }

Member Data Documentation

◆ function1

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

◆ function2

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

The documentation for this class was generated from the following file:
inet::math::SubtractedFunction::function1
const Ptr< const IFunction< R, D > > function1
Definition: AlgebraicOperations.h:117
inet::units::units::g
milli< kg >::type g
Definition: Units.h:1071
inet::math::SubtractedFunction::function2
const Ptr< const IFunction< R, D > > function2
Definition: AlgebraicOperations.h:118
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