mbsim  4.0.0
MBSim Kernel
continued_function.h
1/* Copyright (C) 2004-2016 MBSim Development Team
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 *
17 * Contact: martin.o.foerg@gmail.com
18 */
19
20#ifndef _CONTINUED_FUNCTION_H_
21#define _CONTINUED_FUNCTION_H_
22
23#include "mbsim/functions/function.h"
24
25namespace MBSim {
26
27 template<typename Sig> class ContinuedFunction;
28
29 template<typename Ret, typename Arg>
30 class ContinuedFunction<Ret(Arg)> : public Function<Ret(Arg)> {
31 using B = fmatvec::Function<Ret(Arg)>;
32 public:
33 ContinuedFunction() : f(nullptr), rule(nullptr) { }
34 ~ContinuedFunction() override { delete f; delete rule; }
35 int getArgSize() const override { return f->getArgSize(); }
36 std::pair<int, int> getRetSize() const override { return f->getRetSize(); }
37 Ret operator()(const Arg &x) override { return (*f)((*rule)(x)); }
38 typename B::DRetDArg parDer(const Arg &x) override { return f->parDer((*rule)(x)); }
39 typename B::DRetDArg parDerDirDer(const Arg &xDir, const Arg &x) override { return f->parDerDirDer(xDir,(*rule)(x)); }
40 void setFunction(Function<Ret(Arg)> *f_) {
41 f = f_;
42 f->setParent(this);
43 f->setName("Function");
44 }
45 void setContinuationRule(Function<Arg(Arg)> *rule_) {
46 rule = rule_;
47 rule->setParent(this);
48 rule->setName("ContinuationRule");
49 }
50 void initializeUsingXML(xercesc::DOMElement *element) override {
51 xercesc::DOMElement *e=MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%"function");
52 setFunction(ObjectFactory::createAndInit<Function<Ret(Arg)>>(e->getFirstElementChild()));
53 e=MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%"continuationRule");
54 setContinuationRule(ObjectFactory::createAndInit<Function<Arg(Arg)>>(e->getFirstElementChild()));
55 }
56 void init(Element::InitStage stage, const InitConfigSet &config) override {
57 Function<Ret(Arg)>::init(stage, config);
58 f->init(stage, config);
59 InitConfigSet configRule(config);
60 configRule.insert(noDer);
61 configRule.insert(noDerDer);
62 rule->init(stage, configRule);
63 }
64 private:
65 Function<Ret(Arg)> *f;
66 Function<Arg(Arg)> *rule;
67 };
68
69}
70
71#endif
void init(Element::InitStage stage, const InitConfigSet &config) override
plots time series header
Definition: continued_function.h:56
Definition: continued_function.h:27
InitStage
The stages of the initialization.
Definition: element.h:62
Definition: function.h:53
static ContainerType * createAndInit(const xercesc::DOMElement *element)
Definition: objectfactory.h:103
namespace MBSim
Definition: bilateral_constraint.cc:30