27#include "ElementsKernel/Exception.h"
36 if (
m_knots.size() - functions.size() != 1) {
37 throw Elements::Exception() <<
"Invalid number of knots(" << m_knots.size() <<
")-functions(" << m_functions.size()
45 auto knotsIter =
m_knots.begin();
46 while (++knotsIter !=
m_knots.end()) {
47 if (*knotsIter < *(knotsIter - 1)) {
48 throw Elements::Exception(
"knots must be increasing");
56 throw Elements::Exception() <<
"Invalid number of knots(" << m_knots.size() <<
")-functions(" << m_functions.size()
59 auto knotsIter =
m_knots.begin();
60 while (++knotsIter !=
m_knots.end()) {
61 if (*knotsIter < *(knotsIter - 1)) {
62 throw Elements::Exception(
"knots must be increasing");
73 if (i < 0 || i >=
static_cast<ssize_t
>(
m_knots.size())) {
109 if (knotIter !=
m_knots.begin()) {
113 while (++knotIter !=
m_knots.end()) {
114 auto prevKnotIter = knotIter - 1;
115 if (max <= *prevKnotIter) {
118 if (min < *knotIter) {
119 double down = (min > *prevKnotIter) ? min : *prevKnotIter;
120 double up = (max < *knotIter) ? max : *knotIter;
125 return direction * result;
T back_inserter(T... args)
ssize_t findKnot(double x) const
PiecewiseBase(std::vector< double > knots)
std::vector< double > m_knots
A vector where the knots are kept.
Piecewise(std::vector< double > knots, std::vector< std::shared_ptr< Function > > functions)
double integrate(const double x1, const double x2) const override
double operator()(const double) const override
std::vector< std::unique_ptr< Function > > m_functions
A vector where the sub-functions are kept.
const std::vector< std::unique_ptr< Function > > & getFunctions() const
Returns the functions in the ranges between the knots.
std::unique_ptr< Function > clone() const override
ELEMENTS_API double integrate(const Function &function, const double min, const double max, std::unique_ptr< NumericalIntegrationScheme > numericalIntegrationScheme=nullptr)
std::unique_ptr< T > make_unique(Args &&... args)
Constructs an object of type T and wraps it in a std::unique_ptr using args as the parameter list for...