20 #ifndef _TABULAR_FUNCTION_H_
21 #define _TABULAR_FUNCTION_H_
23 #include "mbsim/functions/function.h"
24 #include "mbsim/utils/utils.h"
30 template<
typename Ret,
typename Arg>
35 TabularFunction(
const fmatvec::VecV &x_,
const fmatvec::MatV &y_) : x(x_), y(y_), xIndexOld(0) { }
36 Ret operator()(
const Arg& xVal_) {
43 else if (xVal >= x(x.size() - 1)) {
44 xIndexOld = x.size() - 1;
47 else if (xVal <= x(i)) {
58 return FromVecV<Ret>::cast(trans(y.row(i) + (xVal - x(i)) * (y.row(i + 1) - y.row(i)) / (x(i + 1) - x(i))));
60 void initializeUsingXML(xercesc::DOMElement * element) {
61 xercesc::DOMElement *e = MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%
"x");
63 setx(Element::getVec(e));
64 e = MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%
"y");
65 sety(Element::getMat(e, x.size(), 0));
67 e = MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%
"xy");
68 if (e) setxy(Element::getMat(e));
70 void setx(
const fmatvec::VecV &x_) { x = x_; }
71 void sety(
const fmatvec::MatV &y_) { y = y_; }
72 void setxy(
const fmatvec::MatV &xy) {
74 THROW_MBSIMERROR(
"Dimension missmatch in size of xy");
76 y = xy(fmatvec::RangeV(0, xy.rows() - 1), fmatvec::RangeV(1, xy.cols() - 1));
81 for(
int i=1; i<x.size(); i++)
83 THROW_MBSIMERROR(
"Values of x must be strictly monotonic increasing!");
84 if(y.rows() != x.size())
85 THROW_MBSIMERROR(
"Dimension missmatch in size of x");
InitStage
The stages of the initialization.
Definition: element.h:97
Definition: planar_contour.h:31
Definition: element.h:100
void init(Element::InitStage stage)
plots time series header
Definition: tabular_function.h:78
Definition: tabular_function.h:28