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++)
59 this->throwError(
"(PiecewiseDefinedFunction::operator()): x out of range! x= "+fmatvec::toString(x)+
", upper bound= "+fmatvec::toString(a[
function.size()]));
61 typename B::DRetDArg parDer(
const Arg &x)
override {
62 for(
unsigned int i=0; i<
function.size(); i++)
65 this->throwError(
"(PiecewiseDefinedFunction::parDer): x out of range! x= "+fmatvec::toString(x)+
", upper bound= "+fmatvec::toString(a[
function.size()]));
67 typename B::DRetDArg parDerDirDer(
const Arg &xDir,
const Arg &x)
override {
68 for(
unsigned int i=0; i<
function.size(); i++)
71 this->throwError(
"(PiecewiseDefinedFunction::parDerDirDer): x out of range! x= "+fmatvec::toString(x)+
", upper bound= "+fmatvec::toString(a[
function.size()]));
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>();
87 Function<Ret(Arg)>::init(stage, config);
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
Definition: piecewise_defined_function.h:28
InitStage
The stages of the initialization.
Definition: element.h:62
Definition: planar_contour.h:30
static ContainerType * createAndInit(const xercesc::DOMElement *element)
Definition: objectfactory.h:76
Definition: piecewise_defined_function.h:37
namespace MBSim
Definition: eigenanalyzer.cc:47