Alexandria  2.16
Please provide a description of the project.
Public Member Functions | Private Attributes | List of all members
Euclid::MathUtils::Piecewise Class Reference

Represents a piecewise function. More...

#include <Piecewise.h>

Inheritance diagram for Euclid::MathUtils::Piecewise:
[legend]
Collaboration diagram for Euclid::MathUtils::Piecewise:
[legend]

Public Member Functions

 Piecewise (std::vector< double > knots, std::vector< std::shared_ptr< Function >> functions)
 
 Piecewise (std::vector< double > knots, std::vector< std::unique_ptr< Function >> &&functions)
 
virtual ~Piecewise ()=default
 Default destructor. More...
 
const std::vector< double > & getKnots () const
 Returns the knots of the piecewise function. More...
 
const std::vector< std::unique_ptr< Function > > & getFunctions () const
 Returns the functions in the ranges between the knots. More...
 
double operator() (const double) const override
 
std::unique_ptr< Functionclone () const override
 
double integrate (const double x1, const double x2) const override
 
- Public Member Functions inherited from Euclid::MathUtils::Integrable
virtual ~Integrable ()=default
 Default destructor. More...
 
- Public Member Functions inherited from Euclid::MathUtils::Function
virtual ~Function ()=default
 Default destructor. More...
 

Private Attributes

std::vector< double > m_knots
 A vector where the knots are kept. More...
 
std::vector< std::unique_ptr< Function > > m_functions
 A vector where the sub-functions are kept. More...
 

Detailed Description

Represents a piecewise function.

A Piecewise function is defined by multiple sub functions, each applied to an interval defined by the piecewise knots. Outside of the knots range the Piecewise evaluates zero.

Definition at line 48 of file Piecewise.h.

Constructor & Destructor Documentation

◆ Piecewise() [1/2]

Euclid::MathUtils::Piecewise::Piecewise ( std::vector< double >  knots,
std::vector< std::shared_ptr< Function >>  functions 
)

Creates a new Piecewise instance with the given knots and functions between them. The functions vector must have size one less than the knots. The sub-function with index 0 corresponds to the range [knot0,knot1], the one with index 1 to the range [knot1,knot2], etc.

Parameters
knotsThe knots of the piecewise function
functionsThe sub-functions in the knot ranges
Exceptions
Elements::Exceptionif the size of the sub-functions vector is not ine less than the knots vector size
Elements::Exceptionif the knots are not strictly increasing

Referenced by clone().

◆ Piecewise() [2/2]

Euclid::MathUtils::Piecewise::Piecewise ( std::vector< double >  knots,
std::vector< std::unique_ptr< Function >> &&  functions 
)

Definition at line 52 of file Piecewise.cpp.

◆ ~Piecewise()

virtual Euclid::MathUtils::Piecewise::~Piecewise ( )
virtualdefault

Default destructor.

Member Function Documentation

◆ clone()

std::unique_ptr< Function > Euclid::MathUtils::Piecewise::clone ( ) const
overridevirtual

Creates a Piecewise function with the same knots and sub-functions. Note that the sub-functions are not cloned, but just a pointer is copied.

Implements Euclid::MathUtils::Function.

Definition at line 90 of file Piecewise.cpp.

References m_functions, m_knots, and Piecewise().

Here is the call graph for this function:

◆ getFunctions()

const std::vector< std::unique_ptr< Function > > & Euclid::MathUtils::Piecewise::getFunctions ( ) const

Returns the functions in the ranges between the knots.

Definition at line 70 of file Piecewise.cpp.

References m_functions.

Referenced by Euclid::MathUtils::multiplyPiecewises(), and Euclid::MathUtils::multiplyPiecewiseWithGeneric().

◆ getKnots()

const std::vector< double > & Euclid::MathUtils::Piecewise::getKnots ( ) const

Returns the knots of the piecewise function.

Definition at line 66 of file Piecewise.cpp.

References m_knots.

Referenced by Euclid::MathUtils::multiplyPiecewises(), and Euclid::MathUtils::multiplyPiecewiseWithGeneric().

◆ integrate()

double Euclid::MathUtils::Piecewise::integrate ( const double  x1,
const double  x2 
) const
overridevirtual

Calculates the integral in the range [x1,x2], by delegating the integration in the sub-functions.

Parameters
x1The lower bound of the integration
x2The upper bound of the integration
Returns
The integral in the range [x1,x2]

Implements Euclid::MathUtils::Integrable.

Definition at line 99 of file Piecewise.cpp.

References Euclid::MathUtils::integrate(), m_functions, and m_knots.

Here is the call graph for this function:

◆ operator()()

double Euclid::MathUtils::Piecewise::operator() ( const double  x) const
overridevirtual

Returns the value of the piecewise function for the given value, by using the correct sub-function. Values outside of the knots evaluate to zero.

Implements Euclid::MathUtils::Function.

Definition at line 74 of file Piecewise.cpp.

References m_functions, and m_knots.

Member Data Documentation

◆ m_functions

std::vector<std::unique_ptr<Function> > Euclid::MathUtils::Piecewise::m_functions
private

A vector where the sub-functions are kept.

Definition at line 100 of file Piecewise.h.

Referenced by clone(), getFunctions(), integrate(), and operator()().

◆ m_knots

std::vector<double> Euclid::MathUtils::Piecewise::m_knots
private

A vector where the knots are kept.

Definition at line 98 of file Piecewise.h.

Referenced by clone(), getKnots(), integrate(), and operator()().


The documentation for this class was generated from the following files: