Alexandria 2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
Euclid::MathUtils::Piecewise Class Referencefinal

Represents a piecewise function. More...

#include <Piecewise.h>

Inheritance diagram for Euclid::MathUtils::Piecewise:
Inheritance graph
[legend]
Collaboration diagram for Euclid::MathUtils::Piecewise:
Collaboration graph
[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.
 
const std::vector< std::unique_ptr< Function > > & getFunctions () const
 Returns the functions in the ranges between the knots.
 
double operator() (const double) const override
 
void operator() (const std::vector< double > &xs, std::vector< double > &out) 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::PiecewiseBase
virtual ~PiecewiseBase ()=default
 
const std::vector< double > & getKnots () const
 Returns the knots of the piecewise function.
 
- Public Member Functions inherited from Euclid::MathUtils::Integrable
virtual ~Integrable ()=default
 Default destructor.
 

Private Attributes

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

Additional Inherited Members

- Protected Member Functions inherited from Euclid::MathUtils::PiecewiseBase
 PiecewiseBase (std::vector< double > knots)
 
ssize_t findKnot (double x) const
 
- Protected Attributes inherited from Euclid::MathUtils::PiecewiseBase
std::vector< doublem_knots
 A vector where the knots are kept.
 

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 87 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

Definition at line 34 of file Piecewise.cpp.

References std::back_inserter(), std::vector< T >::begin(), std::array< T >::begin(), std::vector< T >::end(), std::array< T >::end(), m_functions, Euclid::MathUtils::PiecewiseBase::m_knots, std::vector< T >::size(), std::array< T >::size(), and std::transform().

Here is the call graph for this function:

◆ Piecewise() [2/2]

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

Definition at line 53 of file Piecewise.cpp.

References std::vector< T >::begin(), std::vector< T >::end(), m_functions, Euclid::MathUtils::PiecewiseBase::m_knots, and std::vector< T >::size().

Here is the call graph for this function:

◆ ~Piecewise()

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

Default destructor.

References Euclid::MathUtils::integrate().

Here is the call graph for this function:

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::NAryFunction< N >.

Definition at line 87 of file Piecewise.cpp.

References std::back_inserter(), m_functions, Euclid::MathUtils::PiecewiseBase::m_knots, std::move(), and std::transform().

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 67 of file Piecewise.cpp.

References m_functions.

◆ 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 95 of file Piecewise.cpp.

References std::vector< T >::begin(), std::array< T >::begin(), std::vector< T >::end(), Euclid::MathUtils::integrate(), m_functions, Euclid::MathUtils::PiecewiseBase::m_knots, and std::upper_bound().

Here is the call graph for this function:

◆ operator()() [1/2]

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

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.

Definition at line 71 of file Piecewise.cpp.

References Euclid::MathUtils::PiecewiseBase::findKnot(), m_functions, Euclid::MathUtils::PiecewiseBase::m_knots, and std::vector< T >::size().

Here is the call graph for this function:

◆ operator()() [2/2]

void Euclid::MathUtils::Piecewise::operator() ( const std::vector< double > &  xs,
std::vector< double > &  out 
) const
override

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

Definition at line 82 of file Piecewise.cpp.

References std::vector< T >::begin(), std::array< T >::begin(), std::cref(), std::array< T >::end(), std::vector< T >::resize(), std::array< T >::size(), and std::transform().

Here is the call graph for this function:

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 136 of file Piecewise.h.

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


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