All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
state_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 STATE_DEPENDENT_FUNCTION_H_
21 #define STATE_DEPENDENT_FUNCTION_H_
22 
23 #include "mbsim/functions/function.h"
24 
25 namespace MBSim {
26 
27  template <class Ret>
28  class StateDependentFunction : public Function<Ret(fmatvec::VecV,double)> {
30  private:
32  int n;
33  public:
34  StateDependentFunction(Function<Ret(fmatvec::VecV)> *f_=NULL) : f(f_), n(0) {
35  if(f)
36  f->setParent(this);
37  }
38  ~StateDependentFunction() { delete f; }
39  int getArg1Size() const { return f->getArgSize();}
40  int getArg2Size() const { return 0; }
41  Ret operator()(const fmatvec::VecV &arg1, const double &arg2) {return (*f)(arg1); }
42  typename B::DRetDArg1 parDer1(const fmatvec::VecV &arg1, const double &arg2) { return f->parDer(arg1); }
43  typename B::DRetDArg2 parDer2(const fmatvec::VecV &arg1, const double &arg2) {return typename B::DRetDArg2(n); }
44  typename B::DDRetDDArg2 parDer2ParDer2(const fmatvec::VecV &arg1, const double &arg2) { return typename B::DDRetDDArg2(n); }
45  typename B::DRetDArg2 parDer2DirDer1(const fmatvec::VecV &arg1Dir, const fmatvec::VecV &arg1, const double &arg2) { return typename B::DRetDArg2(n); }
46  typename B::DDRetDArg1DArg2 parDer1ParDer2(const fmatvec::VecV &arg1, const double &arg2) { return typename B::DDRetDArg1DArg2(n,getArg1Size()); }
47  typename B::DRetDArg1 parDer1DirDer1(const fmatvec::VecV &arg1Dir, const fmatvec::VecV &arg1, const double &arg2) { return f->parDerDirDer(arg1Dir,arg1); }
48  bool constParDer1() const { return f->constParDer(); }
49  bool constParDer2() const { return true; }
50  Function<Ret(fmatvec::VecV)>* getFunction() const { return f; }
51  void init(Element::InitStage stage) {
53  f->init(stage);
54  if(stage == Element::preInit)
55  n = (*f)(fmatvec::VecV(getArg1Size())).rows();
56  }
57  };
58 
59 }
60 
61 #endif
InitStage
The stages of the initialization.
Definition: element.h:97
Definition: planar_contour.h:31
Definition: element.h:100
virtual void init(InitStage stage)
plots time series header
Definition: element.cc:70
Definition: state_dependent_function.h:28
void init(Element::InitStage stage)
plots time series header
Definition: state_dependent_function.h:51

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML