Loading [MathJax]/extensions/tex2jax.js
mbsim  4.0.0
MBSim Kernel
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
vector_valued_function.h
1/* Copyright (C) 2004-2014 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 _VECTOR_VALUED_FUNCTIONS_H_
21#define _VECTOR_VALUED_FUNCTIONS_H_
22
23#include "mbsim/functions/function.h"
24#include "mbsim/utils/utils.h"
25
26namespace MBSim {
27
28 template<typename Sig> class VectorValuedFunction;
29
30 template<typename Ret, typename Arg>
31 class VectorValuedFunction<Ret(Arg)> : public Function<Ret(Arg)> {
32 using B = fmatvec::Function<Ret(Arg)>;
33
34 public:
35 VectorValuedFunction() = default;
36 VectorValuedFunction(std::vector<Function<double(Arg)> *> component_) : component(std::move(component_)) {
37 for(auto it=component.begin(); it!=component.end(); ++it)
38 (*it)->setParent(this);
39 }
40 ~VectorValuedFunction() override {
41 for (unsigned int i=0; i<component.size(); i++)
42 delete component[i];
43 }
44 void addComponent(Function<double(Arg)> *function) {
45 component.push_back(function);
46 function->setParent(this);
47 }
48 int getArgSize() const override { return 1; }
49 std::pair<int, int> getRetSize() const override { return std::make_pair(component.size(),1); }
50 Ret operator()(const Arg &x) override {
51 for(unsigned int i=0; i<component.size(); i++)
52 y[i]=(*component[i])(x);
53 return Ret(y);
54 }
55 typename B::DRetDArg parDer(const Arg &x) override {
56 for(unsigned int i=0; i<component.size(); i++)
57 dy[i]=component[i]->parDer(x);
59 }
60 typename B::DRetDArg parDerDirDer(const Arg &xDir, const Arg &x) override {
61 for(unsigned int i=0; i<component.size(); i++)
62 ddy[i]=component[i]->parDerDirDer(xDir,x);
64 }
65 void initializeUsingXML(xercesc::DOMElement *element) override {
66 xercesc::DOMElement *e=MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%"components")->getFirstElementChild();
67 while (e) {
68 addComponent(ObjectFactory::createAndInit<Function<double(Arg)>>(e));
69 e=e->getNextElementSibling();
70 }
71 }
72 void init(Element::InitStage stage, const InitConfigSet &config) override {
73 Function<Ret(Arg)>::init(stage, config);
74 for(auto it=component.begin(); it!=component.end(); ++it)
75 (*it)->init(stage, config);
76 if(stage==Element::preInit) {
77 y.resize(component.size());
78 dy.resize(component.size());
79 ddy.resize(component.size());
80 }
81 }
82 private:
83 std::vector<Function<double(Arg)> *> component;
84 std::vector<double> y;
85 std::vector<typename fmatvec::Der<double, Arg>::type> dy ,ddy;
86 };
87
88}
89
90#endif
InitStage
The stages of the initialization.
Definition: element.h:62
@ preInit
Definition: element.h:64
Definition: utils.h:145
Definition: function.h:53
static ContainerType * createAndInit(const xercesc::DOMElement *element)
Definition: objectfactory.h:103
void init(Element::InitStage stage, const InitConfigSet &config) override
plots time series header
Definition: vector_valued_function.h:72
Definition: vector_valued_function.h:28
namespace MBSim
Definition: bilateral_constraint.cc:30