mbsim  4.0.0
MBSim Kernel
time_dependent_function.h
1/* Copyright (C) 2004-2009 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@googlemail.com
18 */
19
20#ifndef TIME_DEPENDENT_FUNCTION_H_
21#define TIME_DEPENDENT_FUNCTION_H_
22
23#include "mbsim/functions/function.h"
24
25namespace MBSim {
26
27 template <class Ret>
28 class TimeDependentFunction : public Function<Ret(fmatvec::VecV,double)> {
29 using B = fmatvec::Function<Ret(fmatvec::VecV,double)>;
30 private:
31 Function<Ret(double)> *f;
32 int n{0};
33 public:
34 TimeDependentFunction(Function<Ret(double)> *f_=NULL) : f(f_) { }
35 ~TimeDependentFunction() override { delete f; }
36 int getArg1Size() const override { return 0;}
37 int getArg2Size() const override { return 1; }
38 std::pair<int, int> getRetSize() const override { return f->getRetSize(); }
39 Ret operator()(const fmatvec::VecV &arg1, const double &arg2) override {return (*f)(arg2); }
40 typename B::DRetDArg1 parDer1(const fmatvec::VecV &arg1, const double &arg2) override { return typename B::DRetDArg1(n,getArg1Size()); }
41 typename B::DRetDArg2 parDer2(const fmatvec::VecV &arg1, const double &arg2) override {return f->parDer(arg2); }
42 typename B::DRetDArg2 parDer2DirDer1(const fmatvec::VecV &arg1Dir, const fmatvec::VecV &arg1, const double &arg2) override { return typename B::DRetDArg2(n); }
43 typename B::DRetDArg2 parDer2DirDer2(const double &arg2Dir, const fmatvec::VecV &arg1, const double &arg2) override { return f->parDerDirDer(arg2Dir,arg2); }
44 typename B::DRetDArg1 parDer1DirDer1(const fmatvec::VecV &arg1Dir, const fmatvec::VecV &arg1, const double &arg2) override { return typename B::DRetDArg1(n,getArg1Size()); }
45 typename B::DRetDArg1 parDer1DirDer2(const double &arg2Dir, const fmatvec::VecV &arg1, const double &arg2) override { return typename B::DRetDArg1(n,getArg1Size()); }
46 bool constParDer1() const override { return true; }
47 bool constParDer2() const override { return f->constParDer(); }
48 void init(Element::InitStage stage, const InitConfigSet &config) override {
49 Function<Ret(fmatvec::VecV,double)>::init(stage, config);
50 f->init(stage, config);
51 if(stage == Element::preInit)
52 n = f->getRetSize().first;
53 }
55 Function<Ret(fmatvec::VecV,double)>::setDynamicSystemSolver(sys);
57 }
58 void setParent(Element *element) override {
59 Function<Ret(fmatvec::VecV,double)>::setParent(element);
60 if(f) f->setParent(element);
61 }
62 };
63
64}
65
66#endif
solver interface for modelling and simulation of dynamic systems
Definition: dynamic_system_solver.h:61
basic class of MBSim mainly for plotting
Definition: element.h:57
virtual void init(InitStage stage, const InitConfigSet &config=InitConfigSet())
plots time series header
Definition: element.cc:86
virtual void setDynamicSystemSolver(DynamicSystemSolver *sys)
sets the used dynamics system solver to the element
Definition: element.h:92
InitStage
The stages of the initialization.
Definition: element.h:63
@ preInit
Definition: element.h:65
Definition: function.h:53
Definition: time_dependent_function.h:28
void setDynamicSystemSolver(DynamicSystemSolver *sys) override
sets the used dynamics system solver to the element
Definition: time_dependent_function.h:54
void init(Element::InitStage stage, const InitConfigSet &config) override
plots time series header
Definition: time_dependent_function.h:48
namespace MBSim
Definition: bilateral_constraint.cc:30