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

#include <AlgebraicOperations.h>

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

Public Member Functions

 MultipliedFunction (const Ptr< const IFunction< R, D >> &function1, const Ptr< const IFunction< double, D >> &function2)
 
virtual D::I getDomain () const override
 Returns the valid domain of the function as an interval. More...
 
virtual const Ptr< const IFunction< R, D > > & getF1 () const
 
virtual const Ptr< const IFunction< double, D > > & getF2 () 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 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< double, D > > function2
 

Constructor & Destructor Documentation

◆ MultipliedFunction()

template<typename R , typename D >
inet::math::MultipliedFunction< R, D >::MultipliedFunction ( const Ptr< const IFunction< R, D >> &  function1,
const Ptr< const IFunction< double, D >> &  function2 
)
inline
191  :
193  {}

Member Function Documentation

◆ getDomain()

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

Returns the valid domain of the function as an interval.

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

195  {
196  return function1->getDomain().getIntersected(function2->getDomain());
197  }

◆ getF1()

template<typename R , typename D >
virtual const Ptr<const IFunction<R, D> >& inet::math::MultipliedFunction< R, D >::getF1 ( ) const
inlinevirtual
199 { return function1; }

◆ getF2()

template<typename R , typename D >
virtual const Ptr<const IFunction<double, D> >& inet::math::MultipliedFunction< R, D >::getF2 ( ) const
inlinevirtual
201 { return function2; }

◆ getValue()

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

203  {
204  return function1->getValue(p) * function2->getValue(p);
205  }

◆ isFinite()

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

247  {
248  return function1->isFinite(i) & function2->isFinite(i);
249  }

◆ partition()

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

207  {
208  function1->partition(i, [&] (const typename D::I& i1, const IFunction<R, D> *f1) {
209  // NOTE: optimization for 0 * x
210  if (auto f1c = dynamic_cast<const ConstantFunction<R, D> *>(f1)) {
211  if (toDouble(f1c->getConstantValue()) == 0 && function2->isFinite(i1)) {
212  callback(i1, f1);
213  return;
214  }
215  }
216  function2->partition(i1, [&] (const typename D::I& i2, const IFunction<double, D> *f2) {
217  if (auto f1c = dynamic_cast<const ConstantFunction<R, D> *>(f1)) {
218  if (auto f2c = dynamic_cast<const ConstantFunction<double, D> *>(f2)) {
219  ConstantFunction<R, D> g(f1c->getConstantValue() * f2c->getConstantValue());
220  callback(i2, &g);
221  }
222  else if (auto f2l = dynamic_cast<const UnilinearFunction<double, D> *>(f2)) {
223  UnilinearFunction<R, D> g(i2.getLower(), i2.getUpper(), f2l->getValue(i2.getLower()) * f1c->getConstantValue(), f2l->getValue(i2.getUpper()) * f1c->getConstantValue(), f2l->getDimension());
224  simplifyAndCall(i2, &g, callback);
225  }
226  else
227  throw cRuntimeError("TODO");
228  }
229  else if (auto f1l = dynamic_cast<const UnilinearFunction<R, D> *>(f1)) {
230  if (auto f2c = dynamic_cast<const ConstantFunction<double, D> *>(f2)) {
231  UnilinearFunction<R, D> g(i2.getLower(), i2.getUpper(), f1l->getValue(i2.getLower()) * f2c->getConstantValue(), f1l->getValue(i2.getUpper()) * f2c->getConstantValue(), f1l->getDimension());
232  simplifyAndCall(i2, &g, callback);
233  }
234  else if (auto f2l = dynamic_cast<const UnilinearFunction<double, D> *>(f2)) {
235 // QuadraticFunction<double, D> g();
236  throw cRuntimeError("TODO");
237  }
238  else
239  throw cRuntimeError("TODO");
240  }
241  else
242  throw cRuntimeError("TODO");
243  });
244  });
245  }

◆ printStructure()

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

251  {
252  os << "(* ";
253  function1->printStructure(os, level + 3);
254  os << "\n" << std::string(level + 3, ' ');
255  function2->printStructure(os, level + 3);
256  os << ")";
257  }

Member Data Documentation

◆ function1

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

◆ function2

template<typename R , typename D >
const Ptr<const IFunction<double, D> > inet::math::MultipliedFunction< 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::math::MultipliedFunction::function2
const Ptr< const IFunction< double, D > > function2
Definition: AlgebraicOperations.h:188
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::MultipliedFunction::function1
const Ptr< const IFunction< R, D > > function1
Definition: AlgebraicOperations.h:187