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 Arg>
31 using B = fmatvec::Function<Ret(Arg, Arg)>;
33 enum InterpolationMethod {
45 virtual void initializeUsingXML(xercesc::DOMElement *element) {
46 xercesc::DOMElement * e = MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%
"x");
48 setx(MBXMLUtils::E(e)->getText<fmatvec::Vec>());
49 e = MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%
"y");
50 sety(MBXMLUtils::E(e)->getText<fmatvec::Vec>());
51 e = MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%
"z");
52 setz(MBXMLUtils::E(e)->getText<fmatvec::Mat>(y.size(), x.size()));
54 e = MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%
"xyz");
55 if(e) setxyz(MBXMLUtils::E(e)->getText<fmatvec::Mat>());
56 e=MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%
"interpolationMethodFirstDimension");
58 std::string str=
MBXMLUtils::X()%MBXMLUtils::E(e)->getFirstTextChild()->getData();
59 str=str.substr(1,str.length()-2);
60 if(str==
"cSplinePeriodic") method1=cSplinePeriodic;
61 else if(str==
"cSplineNatural") method1=cSplineNatural;
62 else if(str==
"piecewiseLinear") method1=piecewiseLinear;
65 e=MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%
"interpolationMethodSecondDimension");
67 std::string str=
MBXMLUtils::X()%MBXMLUtils::E(e)->getFirstTextChild()->getData();
68 str=str.substr(1,str.length()-2);
69 if(str==
"cSplinePeriodic") method2=cSplinePeriodic;
70 else if(str==
"cSplineNatural") method2=cSplineNatural;
71 else if(str==
"piecewiseLinear") method2=piecewiseLinear;
76 int getArgSize()
const {
return 1; }
78 std::pair<int, int> getRetSize()
const {
return std::make_pair(1,1); }
80 virtual Ret operator()(
const Arg& xVal,
const Arg& yVal) {
87 typename B::DRetDArg1 parDer1(
const Arg &xVal,
const Arg &yVal) {
94 typename B::DRetDArg2 parDer2(
const Arg &xVal,
const Arg &yVal) {
101 typename B::DRetDArg1 parDer1DirDer1(
const Arg &xdVal,
const Arg &xVal,
const Arg &yVal) {
104 f2.calculateSpline();
108 typename B::DRetDArg1 parDer1DirDer2(
const Arg &ydVal,
const Arg &xVal,
const Arg &yVal) {
111 f2.calculateSpline();
115 typename B::DRetDArg2 parDer2DirDer1(
const Arg &xdVal,
const Arg &xVal,
const Arg &yVal) {
118 f2.calculateSpline();
122 typename B::DRetDArg2 parDer2DirDer2(
const Arg &ydVal,
const Arg &xVal,
const Arg &yVal) {
125 f2.calculateSpline();
129 void setx(
const fmatvec::VecV &x_) { x <<= x_; }
131 void sety(
const fmatvec::VecV &y_) { y <<= y_; }
133 void setz(
const fmatvec::MatV &z_) { z <<= z_; }
135 void setxyz(
const fmatvec::MatV &xyz) {
136 if(xyz.rows() <= 1 or xyz.cols() <= 1)
137 this->throwError(
"Dimension missmatch in size of xyz");
138 x <<= xyz.row(0)(fmatvec::RangeV(1,xyz.cols()-1)).T();
139 y <<= xyz.col(0)(fmatvec::RangeV(1,xyz.rows()-1));
140 z <<= xyz(fmatvec::RangeV(1,xyz.rows()-1),fmatvec::RangeV(1,xyz.cols()-1));
143 void setInterpolationMethodFirstDimension(InterpolationMethod method1_) { method1 = method1_; }
144 void setInterpolationMethodSecondDimension(InterpolationMethod method2_) { method2 = method2_; }
147 Function<Ret(Arg, Arg)>::init(stage, config);
150 Element::throwError(
"(TwoDimensionalPiecewisePolynomFunction::init): interpolation method first dimension unknown");
152 Element::throwError(
"(TwoDimensionalPiecewisePolynomFunction::init): interpolation method second dimension unknown");
153 if (z.cols() != x.size())
154 this->throwError(
"Dimension missmatch in xSize");
155 if (z.rows() != y.size())
156 this->throwError(
"Dimension missmatch in ySize");
157 for (
int i = 1; i < x.size(); i++)
158 if (x(i - 1) >= x(i))
159 this->throwError(
"x values must be strictly monotonic increasing!");
160 for (
int i = 1; i < y.size(); i++)
161 if (y(i - 1) >= y(i))
162 this->throwError(
"y values must be strictly monotonic increasing!");
165 f1.setInterpolationMethod(
static_cast<typename
PiecewisePolynomFunction<fmatvec::VecV(
double)
>::InterpolationMethod>(method1));
168 f2.setInterpolationMethod(
static_cast<typename
PiecewisePolynomFunction<Ret(
double)
>::InterpolationMethod>(method2));
170 f1.init(stage, config);
171 f2.init(stage, config);
180 InterpolationMethod method1, method2;
InitStage
The stages of the initialization.
Definition: element.h:62
@ preInit
Definition: element.h:64
Definition: function.h:53
Definition: piecewise_polynom_function.h:31
void init(Element::InitStage stage, const InitConfigSet &config)
plots time series header
Definition: two_dimensional_piecewise_polynom_function.h:146
Definition: two_dimensional_piecewise_polynom_function.h:27
namespace MBSim
Definition: bilateral_constraint.cc:30