20 #ifndef _TWO_DIMENSIONAL_PIECEWISE_POLYNOM_FUNCTION_H_
21 #define _TWO_DIMENSIONAL_PIECEWISE_POLYNOM_FUNCTION_H_
23 #include "mbsim/functions/piecewise_polynom_function.h"
29 template<
typename Ret,
typename Arg1,
typename Arg2>
33 enum InterpolationMethod {
44 virtual void initializeUsingXML(xercesc::DOMElement *element) {
45 xercesc::DOMElement * e = MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%
"x");
47 setx(Element::getVec(e));
48 e = MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%
"y");
49 sety(Element::getVec(e));
50 e = MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%
"z");
51 setz(Element::getMat(e, y.size(), x.size()));
53 e = MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%
"xyz");
54 if(e) setxyz(Element::getMat(e));
55 e=MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%
"interpolationMethodFirstDimension");
57 std::string str=
MBXMLUtils::X()%MBXMLUtils::E(e)->getFirstTextChild()->getData();
58 str=str.substr(1,str.length()-2);
59 if(str==
"cSplinePeriodic") method1=cSplinePeriodic;
60 else if(str==
"cSplineNatural") method1=cSplineNatural;
61 else if(str==
"piecewiseLinear") method1=piecewiseLinear;
63 e=MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%
"interpolationMethodSecondDimension");
65 std::string str=
MBXMLUtils::X()%MBXMLUtils::E(e)->getFirstTextChild()->getData();
66 str=str.substr(1,str.length()-2);
67 if(str==
"cSplinePeriodic") method2=cSplinePeriodic;
68 else if(str==
"cSplineNatural") method2=cSplineNatural;
69 else if(str==
"piecewiseLinear") method2=piecewiseLinear;
73 virtual Ret operator()(
const Arg1& xVal,
const Arg2& yVal) {
80 typename B::DRetDArg1 parDer1(
const Arg1 &xVal,
const Arg2 &yVal) {
81 f2.sety(f1.parDer(xVal));
87 typename B::DRetDArg2 parDer2(
const Arg1 &xVal,
const Arg2 &yVal) {
91 return f2.parDer(yVal);
94 typename B::DRetDArg1 parDer1DirDer1(
const Arg1 &xdVal,
const Arg1 &xVal,
const Arg2 &yVal) {
95 f2.sety(f1.parDerDirDer(xdVal,xVal));
101 typename B::DRetDArg1 parDer1DirDer2(
const Arg2 &ydVal,
const Arg1 &xVal,
const Arg2 &yVal) {
102 f2.sety(f1.parDer(xVal));
104 f2.calculateSpline();
105 return f2.parDer(yVal)*ydVal;
108 typename B::DRetDArg2 parDer2DirDer1(
const Arg1 &xdVal,
const Arg1 &xVal,
const Arg2 &yVal) {
109 f2.sety(f1.parDer(xVal)*xdVal);
111 f2.calculateSpline();
112 return f2.parDer(yVal);
115 typename B::DRetDArg2 parDer2DirDer2(
const Arg2 &ydVal,
const Arg1 &xVal,
const Arg2 &yVal) {
118 f2.calculateSpline();
119 return f2.parDerDirDer(ydVal,yVal);
122 void setx(
const fmatvec::VecV &x_) { x = x_; }
124 void sety(
const fmatvec::VecV &y_) { y = y_; }
126 void setz(
const fmatvec::MatV &z_) { z = z_; }
128 void setxyz(
const fmatvec::MatV &xyz) {
129 if(xyz.rows() <= 1 or xyz.cols() <= 1)
130 THROW_MBSIMERROR(
"Dimension missmatch in size of xyz");
131 x = xyz.row(0)(fmatvec::RangeV(1,xyz.cols()-1)).T();
132 y = xyz.col(0)(fmatvec::RangeV(1,xyz.rows()-1));
133 z = xyz(fmatvec::RangeV(1,xyz.rows()-1),fmatvec::RangeV(1,xyz.cols()-1));
136 void setInterpolationMethodFirstDimension(InterpolationMethod method1_) { method1 = method1_; }
137 void setInterpolationMethodSecondDimension(InterpolationMethod method2_) { method2 = method2_; }
142 if (z.cols() != x.size())
143 THROW_MBSIMERROR(
"Dimension missmatch in xSize");
144 if (z.rows() != y.size())
145 THROW_MBSIMERROR(
"Dimension missmatch in ySize");
146 for (
int i = 1; i < x.size(); i++)
147 if (x(i - 1) >= x(i))
148 THROW_MBSIMERROR(
"x values must be strictly monotonic increasing!");
149 for (
int i = 1; i < y.size(); i++)
150 if (y(i - 1) >= y(i))
151 THROW_MBSIMERROR(
"y values must be strictly monotonic increasing!");
169 InterpolationMethod method1, method2;
Definition: two_dimensional_piecewise_polynom_function.h:27
InitStage
The stages of the initialization.
Definition: element.h:97
void init(Element::InitStage stage)
plots time series header
Definition: two_dimensional_piecewise_polynom_function.h:139
Definition: piecewise_polynom_function.h:32
Definition: planar_contour.h:31
Definition: element.h:100