mbsim  4.0.0
MBSim Kernel
MBSim::PiecewisePolynomFunction< Ret(Arg)> Class Template Reference

class for piecewise-polynomials and cubic spline interpolation More...

#include <piecewise_polynom_function.h>

Inheritance diagram for MBSim::PiecewisePolynomFunction< Ret(Arg)>:
[legend]

Classes

class  FirstDerivative
 
class  SecondDerivative
 
class  ZerothDerivative
 

Public Types

enum  InterpolationMethod { cSplinePeriodic , cSplineNatural , piecewiseLinear , useBreaksAndCoefs }
 
enum  ExtrapolationMethod { error , continuePolynom , linear }
 
- Public Types inherited from MBSim::Element
enum  InitStage {
  resolveStringRef =0 , preInit , plotting , unknownStage ,
  LASTINITSTAGE
}
 The stages of the initialization. More...
 

Public Member Functions

int getArgSize () const
 
std::pair< int, int > getRetSize () const
 
void init (Element::InitStage stage, const InitConfigSet &config=InitConfigSet())
 plots time series header More...
 
void calculateSpline ()
 
void reset ()
 
Ret operator() (const Arg &x)
 
fmatvec::Der< Ret, Arg >::type parDer (const Arg &x)
 
fmatvec::Der< Ret, Arg >::type parDerDirDer (const Arg &argDir, const Arg &arg)
 
fmatvec::VecV getBreaks ()
 
void setInterpolationMethod (InterpolationMethod method_)
 set interpolation More...
 
void setExtrapolationMethod (ExtrapolationMethod method_)
 
void setx (const fmatvec::VecV &x_)
 
void sety (const fmatvec::MatV &y_)
 
void setxy (const fmatvec::MatV &xy)
 
void setCoefficientsArray (const std::vector< fmatvec::MatV > &allCoefs)
 set polynomial coefficients More...
 
void addCoefficients (const fmatvec::MatV &coef)
 
void setBreaks (const fmatvec::VecV &breaks_u)
 set interval boundaries More...
 
virtual void initializeUsingXML (xercesc::DOMElement *element)
 initialize function with XML code More...
 
- Public Member Functions inherited from MBSim::Function< Ret(Arg)>
 Function ()
 
void initializeUsingXML (xercesc::DOMElement *element) override
 
- Public Member Functions inherited from MBSim::FunctionBase
 FunctionBase ()
 
virtual ElementgetDependency () const
 
- Public Member Functions inherited from MBSim::Element
 Element (const std::string &name)
 constructor
 
 ~Element () override=default
 destructor
 
void throwError (const std::string &msg) const
 
virtual void setDynamicSystemSolver (DynamicSystemSolver *sys)
 sets the used dynamics system solver to the element More...
 
virtual void plot ()
 plots time dependent data More...
 
virtual void plotAtSpecialEvent ()
 plots time dependent data at special events More...
 
const std::string & getName () const
 
void setName (const std::string &str)
 
void setPath (const std::string &str)
 
DynamicSystemSolvergetDynamicSystemSolver ()
 
virtual void init (InitStage stage, const InitConfigSet &config=InitConfigSet())
 plots time series header More...
 
virtual void createPlotGroup ()
 creates the plotGroup for H5-output More...
 
H5::GroupBasegetPlotGroup ()
 
virtual H5::GroupBasegetFramesPlotGroup ()
 
virtual H5::GroupBasegetContoursPlotGroup ()
 
virtual H5::GroupBasegetGroupsPlotGroup ()
 
virtual H5::GroupBasegetObjectsPlotGroup ()
 
virtual H5::GroupBasegetLinksPlotGroup ()
 
virtual H5::GroupBasegetConstraintsPlotGroup ()
 
virtual H5::GroupBasegetObserversPlotGroup ()
 
bool getPlotFeature (const PlotFeatureEnum &pf)
 
virtual void setPlotFeature (const PlotFeatureEnum &pf, bool value)
 Set a plot feature. More...
 
void setPlotFeatureForChildren (const PlotFeatureEnum &pf, bool value)
 Set a plot feature for the children of this object. More...
 
void setPlotFeatureRecursive (const PlotFeatureEnum &pf, bool value)
 Set a plot feature for this object and the children of this object. More...
 
template<class T >
void setPlotAttribute (const std::string &name, const T &value)
 Set a plot attribute: static data attached as key/value pairs to the plot datasets/groups.
 
void setPlotAttribute (const std::string &name)
 
virtual void initializeUsingXML (xercesc::DOMElement *element)
 
template<class T >
T * getByPath (const std::string &path, bool initialCaller=true) const
 Get the object of type T represented by the path path. Do not set any argurment other than path!
 
std::string getPath (const Element *relTo=nullptr, std::string sep="/") const
 Return the path of this object. If relativeTo is not NULL return a relative path to relativeTo. Do not set any argurment other than relTo and sep!
 
virtual ElementgetChildByContainerAndName (const std::string &container, const std::string &name) const
 Get the Element named name in the container named container. More...
 
virtual std::shared_ptr< OpenMBV::GroupgetOpenMBVGrp ()
 
virtual std::shared_ptr< OpenMBV::GroupgetFramesOpenMBVGrp ()
 
virtual std::shared_ptr< OpenMBV::GroupgetContoursOpenMBVGrp ()
 
virtual std::shared_ptr< OpenMBV::GroupgetGroupsOpenMBVGrp ()
 
virtual std::shared_ptr< OpenMBV::GroupgetObjectsOpenMBVGrp ()
 
virtual std::shared_ptr< OpenMBV::GroupgetLinksOpenMBVGrp ()
 
virtual std::shared_ptr< OpenMBV::GroupgetConstraintsOpenMBVGrp ()
 
virtual std::shared_ptr< OpenMBV::GroupgetObserversOpenMBVGrp ()
 
virtual ElementgetParent ()
 
virtual const ElementgetParent () const
 
virtual void setParent (Element *parent_)
 
std::vector< Element * > getDependencies () const
 checks dependency on other elements. More...
 
void addDependency (Element *ele)
 
int computeLevel ()
 computes the length of the pathes in the graph that represents the dependencies between all elements. More...
 
virtual void updatePositions (Frame *frame)
 
virtual void updateVelocities (Frame *frame)
 
virtual void updateAccelerations (Frame *frame)
 
virtual void updateJacobians (Frame *frame, int j=0)
 
virtual void updateGyroscopicAccelerations (Frame *frame)
 
virtual void resetUpToDate ()
 
const double & getTime () const
 
double getStepSize () const
 
const MBXMLUtils::DOMEvalExceptiongetDOMEvalError () const
 

Protected Types

using B = fmatvec::Function< Ret(Arg)>
 

Protected Member Functions

void calculateSplinePeriodic ()
 calculation of periodic spline by interpolation More...
 
void calculateSplineNatural ()
 calculation of natural spline by interpolation More...
 
void calculatePLinear ()
 
- Protected Member Functions inherited from MBSim::Element
void updatePlotFeatures ()
 
void addToPlot (const std::string &name)
 
void addToPlot (const std::string &name, int size)
 
void addToPlot (const std::string &name, const std::vector< std::string > &iname)
 
template<class AT >
void plot (const AT &x)
 
template<class Type , class AT >
void plot (const fmatvec::Vector< Type, AT > &x)
 

Protected Attributes

std::vector< fmatvec::MatV > coefs
 vector of polynomial coefficents
 
fmatvec::VecV breaks
 vector of breaks (interval boundaries)
 
int nPoly
 number of defined piecewise polynomials
 
int order
 order of polynomial (3 for cubic polynomials)
 
int index
 for internal use in ppeval functions
 
fmatvec::VecV x
 
fmatvec::MatV y
 
InterpolationMethod interpolationMethod
 interpolation interpolationMethod
 
ExtrapolationMethod extrapolationMethod
 
- Protected Attributes inherited from MBSim::Element
Elementparent { nullptr }
 
std::string name
 name of element
 
std::string path
 The path of this object. Is set during the init stage reorganizeHierarchy. Before this the path is calculated dynamically using getPath() after this stage getPath just returns this value.
 
MBXMLUtils::DOMEvalException domEvalError
 Special XML helper variable.
 
DynamicSystemSolverds { nullptr }
 dynamic system
 
H5::VectorSerie< double > * plotVectorSerie { nullptr }
 time series
 
std::vector< double > plotVector
 one entry of time series
 
std::vector< std::string > plotColumns
 columns of time series
 
H5::GroupBaseplotGroup { nullptr }
 associated plot group
 
std::vector< Element * > dependency
 vector containing all dependencies.
 
PlotFeatureMap plotFeature
 plot feature
 
PlotFeatureMap plotFeatureForChildren
 
std::map< std::string, std::variant< std::monostate, int, double, std::string, std::vector< int >, std::vector< double >, std::vector< std::vector< double > > > > plotAttribute
 

Private Attributes

ZerothDerivative f
 
FirstDerivative fd
 
SecondDerivative fdd
 

Detailed Description

template<typename Ret, typename Arg>
class MBSim::PiecewisePolynomFunction< Ret(Arg)>

class for piecewise-polynomials and cubic spline interpolation

Author
Robert Huber
Date
2006-08-31 initial commit
2006-09-05 verified with matlab /octave (Robert Huber)
2008-05-21 C++ beauty treatment, PLinear (Thorsten Schindler)
2009-08-11 kernel_dev (Thorsten Schindler)
Todo:
add deletes TODO

Spline / PP-Form info Piecewise polynomial: \( c0 xloc^n + c1 xloc^{n-1} + c2 xloc^{n-2} + \dots + cn \) with [c0 c1 c2 ... cn] ith row vector of coefs-matrix breaks(i) << x << breaks(i+1) defines i and xloc = x-breaks(i)

Ex. cubic spline with breaks= [0; 0.3; 0.5] coefs= [d1 c1 b1 a1;
d2 c2 b2 a2]

\[ S(x) = a1 + b1 xloc + c1 xloc^2 + d1 xloc^3 for x\in[0;0.3] \text{and} x_loc = x \]

\[ S(x) = a2 + b2 xloc + c2 xloc^2 + d2 xloc^3 for x\in[0.3;0.5] \text{and} xloc = x - 0.3 \]

Cubic spline (xi,fi) i=1..N is being interpolated by N-1 piecewise polynomials Si of degree 3 yielding a global \( C^2 \) curve for uniqueness TWO additional boundary conditions are necessary (periodic / natural)

Piecewise linear polynomial (xi,fi) i=1..N is being interpolated by N-1 piecewise polynomials Si of degree 1 yielding a globally weak differentiable curve in the context of this class the second derivative is defined to be zero everywhere (which is mathematically wrong)

Member Function Documentation

◆ calculateSplineNatural()

template<typename Ret , typename Arg >
void MBSim::PiecewisePolynomFunction< Ret(Arg)>::calculateSplineNatural ( )
protected

calculation of natural spline by interpolation

Parameters
interpolatedarguments
interpolatedfunction values

◆ calculateSplinePeriodic()

template<typename Ret , typename Arg >
void MBSim::PiecewisePolynomFunction< Ret(Arg)>::calculateSplinePeriodic ( )
protected

calculation of periodic spline by interpolation

Parameters
interpolatedarguments
interpolatedfunction values

◆ getBreaks()

template<typename Ret , typename Arg >
fmatvec::VecV MBSim::PiecewisePolynomFunction< Ret(Arg)>::getBreaks ( )
inline
Returns
interval boundaries

◆ init()

template<typename Ret , typename Arg >
void MBSim::PiecewisePolynomFunction< Ret(Arg)>::init ( Element::InitStage  stage,
const InitConfigSet &  config = InitConfigSet() 
)
inlinevirtual

plots time series header

Parameters
invocingparent class

Reimplemented from MBSim::Element.

◆ initializeUsingXML()

template<typename Ret , typename Arg >
virtual void MBSim::PiecewisePolynomFunction< Ret(Arg)>::initializeUsingXML ( xercesc::DOMElement *  element)
virtual

initialize function with XML code

Parameters
XMLelement

Reimplemented from MBSim::Element.

◆ setBreaks()

template<typename Ret , typename Arg >
void MBSim::PiecewisePolynomFunction< Ret(Arg)>::setBreaks ( const fmatvec::VecV &  breaks_u)
inline

set interval boundaries

Parameters
intervalboundaries

◆ setCoefficientsArray()

template<typename Ret , typename Arg >
void MBSim::PiecewisePolynomFunction< Ret(Arg)>::setCoefficientsArray ( const std::vector< fmatvec::MatV > &  allCoefs)

set polynomial coefficients

Parameters
polynomialcoefficients

◆ setInterpolationMethod()

template<typename Ret , typename Arg >
void MBSim::PiecewisePolynomFunction< Ret(Arg)>::setInterpolationMethod ( InterpolationMethod  method_)
inline

set interpolation

Parameters
InterpolationMethod'cSplinePeriodic' -> cubic Spline with periodic end conditions (two-times continuously differentiable) S(x1) = S(xN) -> f(0)=f(end) S'(x1) = S'(xN) S''(x1) = S''(xN) 'cSplineNatural' -> cubic Spline with natural end conditions (two-times continuously differentiable) S''(x1) = S''(xN) = 0 'piecewiseLinear' -> piecewise linear function (weak differentiable)

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