20 #ifndef _PIECEWISE_DEFINED_FUNCTIONS_H_
21 #define _PIECEWISE_DEFINED_FUNCTIONS_H_
23 #include "mbsim/functions/function.h"
24 #include "mbsim/utils/utils.h"
30 template <
typename Ret,
typename Arg>
39 template<
typename Ret,
typename Arg>
45 for(
unsigned int i=0; i<
function.size(); i++)
48 void addLimitedFunction(
const LimitedFunction<Ret(Arg)> &limitedFunction) {
49 function.push_back(limitedFunction.function);
50 limitedFunction.function->setParent(
this);
51 a.push_back(limitedFunction.limit);
53 int getArgSize()
const override {
return 1; }
54 std::pair<int, int> getRetSize()
const override {
return function.size()?
function[0]->getRetSize():std::make_pair(0,1); }
55 Ret operator()(
const Arg &x)
override {
56 for(
unsigned int i=0; i<
function.size(); i++)
61 typename B::DRetDArg parDer(
const Arg &x)
override {
62 for(
unsigned int i=0; i<
function.size(); i++)
67 typename B::DRetDArg parDerDirDer(
const Arg &xDir,
const Arg &x)
override {
68 for(
unsigned int i=0; i<
function.size(); i++)
74 void initializeUsingXML(xercesc::DOMElement *element)
override {
75 xercesc::DOMElement *e=MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%
"limitedFunctions");
76 xercesc::DOMElement *ee=e->getFirstElementChild();
77 while(ee && MBXMLUtils::E(ee)->getTagName()==MBSIM%
"LimitedFunction") {
78 addLimitedFunction(
LimitedFunction<Ret(Arg)>(
ObjectFactory::createAndInit<
Function<Ret(Arg)>>(MBXMLUtils::E(ee)->getFirstElementChildNamed(MBSIM%
"function")->getFirstElementChild()),MBXMLUtils::E(MBXMLUtils::E(ee)->getFirstElementChildNamed(MBSIM%
"limit"))->getText<double>()));
79 ee=ee->getNextElementSibling();
81 e=MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%
"shiftAbscissa");
82 if(e) shiftAbscissa=MBXMLUtils::E(e)->getText<
bool>();
83 e=MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%
"shiftOrdinate");
84 if(e) shiftOrdinate=MBXMLUtils::E(e)->getText<
bool>();
88 for(
auto it=
function.begin(); it!=
function.end(); it++)
89 (*it)->
init(stage, config);
92 for(
unsigned int i=1; i<a.size(); i++)
98 y0.resize(a.size(),0.0*(*
function[0])(Arg(1)));
100 for(
unsigned int i=1; i<a.size(); i++)
106 std::vector<Function<Ret(Arg)> *>
function;
107 std::vector<double> a, x0;
109 bool shiftAbscissa{
false}, shiftOrdinate{
false};
void init(Element::InitStage stage, const InitConfigSet &config) override
plots time series header
Definition: piecewise_defined_function.h:86
virtual void init(InitStage stage, const InitConfigSet &config)
plots time series header
Definition: element.cc:84
Definition: piecewise_defined_function.h:28
InitStage
The stages of the initialization.
Definition: element.h:62
Definition: contact_kinematics.h:32
static ContainerType * createAndInit(const xercesc::DOMElement *element)
Definition: objectfactory.h:76
std::string toString(const T &value, int precision=0)
Definition: piecewise_defined_function.h:37