Alexandria 2.31.0
SDC-CH common library for the Euclid project
|
Represents a piecewise function. More...
#include <Piecewise.h>
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< Function > | clone () const override |
double | integrate (const double x1, const double x2) const override |
![]() | |
virtual | ~PiecewiseBase ()=default |
const std::vector< double > & | getKnots () const |
Returns the knots of the piecewise function. | |
![]() | |
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 | |
![]() | |
PiecewiseBase (std::vector< double > knots) | |
ssize_t | findKnot (double x) const |
![]() | |
std::vector< double > | m_knots |
A vector where the knots are kept. | |
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.
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.
knots | The knots of the piecewise function |
functions | The sub-functions in the knot ranges |
Elements::Exception | if the size of the sub-functions vector is not ine less than the knots vector size |
Elements::Exception | if 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().
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().
|
virtualdefault |
Default destructor.
References Euclid::MathUtils::integrate().
|
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().
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.
|
overridevirtual |
Calculates the integral in the range [x1,x2], by delegating the integration in the sub-functions.
x1 | The lower bound of the integration |
x2 | The upper bound of the integration |
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().
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().
|
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().
|
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().