All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
polynom_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 _POLYNOM_FUNCTION_H_
21 #define _POLYNOM_FUNCTION_H_
22 
23 #include "mbsim/functions/function.h"
24 
25 namespace MBSim {
26 
27  template<typename Sig> class PolynomFunction;
28 
29  template<typename Ret, typename Arg>
30  class PolynomFunction<Ret(Arg)> : public Function<Ret(Arg)> {
32  public:
33  PolynomFunction() { }
34  PolynomFunction(const fmatvec::VecV &a_) : a(a_) { }
35  void init(Element::InitStage stage) {
37  if(stage == Element::preInit) {
38  ad.resize(a.size()-1);
39  add.resize(ad.size()-1);
40  for(int i=1; i<a.size(); i++)
41  ad.e(i-1) = double(i)*a.e(i);
42  for(int i=1; i<ad.size(); i++)
43  add.e(i-1) = double(i)*ad(i);
44  }
45  }
46  Ret operator()(const Arg &x_) {
47  double x = ToDouble<Arg>::cast(x_);
48  double value=a(a.size()-1);
49  for (int i=int(a.size())-2; i>-1; i--)
50  value=value*x+a.e(i);
51  return FromDouble<Ret>::cast(value);
52  }
53  typename B::DRetDArg parDer(const Arg &x_) {
54  double x = ToDouble<Arg>::cast(x_);
55  double value=ad(ad.size()-1);
56  for (int i=int(ad.size())-2; i>-1; i--)
57  value=value*x+ad.e(i);
58  return FromDouble<Ret>::cast(value);
59  }
60  typename B::DRetDArg parDerDirDer(const Arg &xDir_, const Arg &x_) {
61  double x = ToDouble<Arg>::cast(x_);
62  double xDir = ToDouble<Arg>::cast(xDir_);
63  double value=add(add.size()-1);
64  for (int i=int(add.size())-2; i>-1; i--)
65  value=value*x+add.e(i);
66  return FromDouble<Ret>::cast(value*xDir);
67  }
68  Ret parDerParDer(const double &x) {
69  double value=add(add.size()-1);
70  for (int i=int(add.size())-2; i>-1; i--)
71  value=value*x+add.e(i);
72  return FromDouble<Ret>::cast(value);
73  }
74 
75  void initializeUsingXML(xercesc::DOMElement *element) {
76  a = Element::getVec(MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%"coefficients"));
77  }
78 
79  private:
80  fmatvec::VecV a, ad, add;
81  };
82 
83 }
84 
85 #endif
Definition: element.h:101
Definition: polynom_function.h:27
Definition: utils.h:153
InitStage
The stages of the initialization.
Definition: element.h:97
Definition: utils.h:197
Definition: planar_contour.h:31
Definition: element.h:100
void init(Element::InitStage stage)
plots time series header
Definition: polynom_function.h:35

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML