All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
fourier_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 _FOURIER_FUNCTION_H_
21 #define _FOURIER_FUNCTION_H_
22 
23 #include "mbsim/functions/function.h"
24 #include "mbsim/utils/utils.h"
25 
26 namespace MBSim {
27 
28  template<typename Sig> class FourierFunction;
29 
30  template<typename Ret, typename Arg>
31  class FourierFunction<Ret(Arg)> : public Function<Ret(Arg)> {
33 
34  public:
35  FourierFunction() { }
36  FourierFunction(double f_, const fmatvec::VecV &a_, const fmatvec::VecV &b_, double a0_=0, bool amplitudePhaseAngleForm_=false) : f(f_), a0(a0_), a(a_), b(b_), amplitudePhaseAngleForm(amplitudePhaseAngleForm_) { }
37  Ret operator()(const Arg& t_) {
38  double t = ToDouble<Arg>::cast(t_);
39  double y = a0/2;
40  double Om = 2.*M_PI*f;
41  for(int i=0; i<a.size(); i++) {
42  int k = i+1;
43  double phi = k*Om*t;
44  y += a(i)*cos(phi)+b(i)*sin(phi);
45  }
46  return FromDouble<Ret>::cast(y);
47  }
48  typename B::DRetDArg parDer(const Arg &t_) {
49  double t = ToDouble<Arg>::cast(t_);
50  double yd = 0;
51  double Om = 2.*M_PI*f;
52  for(int i=0; i<a.size(); i++) {
53  int k = i+1;
54  double phi = k*Om*t;
55  yd += k*Om*(b(i)*cos(phi)-a(i)*sin(phi));
56  }
57  return FromDouble<Ret>::cast(yd);
58  }
59  Ret parDerParDer(const double &t_) {
60  double t = ToDouble<Arg>::cast(t_);
61  double ydd = 0;
62  double Om = 2.*M_PI*f;
63  for(int i=0; i<a.size(); i++) {
64  int k = i+1;
65  double phi = i*Om*t;
66  ydd -= pow(k*Om,2)*(a(i)*cos(phi)+b(i)*sin(phi));
67  }
68  return FromDouble<Ret>::cast(ydd);
69  }
70  void initializeUsingXML(xercesc::DOMElement * element) {
71  xercesc::DOMElement *e=MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%"frequency");
72  f=Element::getDouble(e);
73  e=MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%"a0");
74  if(e) a0=Element::getDouble(e);
75  e = MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%"a");
76  if(e) {
77  a = Element::getVec(e);
78  e = MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%"b");
79  b = Element::getVec(e);
80  }
81  e = MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%"ab");
82  if(e) {
83  fmatvec::MatV xy = Element::getMat(e);
84  assert(xy.cols() == 2);
85  a = xy.col(0);
86  b = xy.col(1);
87  }
88  e = MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%"amplitudePhaseAngleForm");
89  if(e) amplitudePhaseAngleForm = Element::getBool(e);
90  }
91  void init(Element::InitStage stage) {
93  if(stage == Element::preInit) {
94  if(amplitudePhaseAngleForm) {
95  for(int i=0; i<a.size(); i++) {
96  double buf = a.e(i);
97  a(i) = buf*sin(b(i));
98  b(i) = buf*cos(b(i));
99  }
100  }
101  }
102  }
103  protected:
104  double f;
105  double a0;
106  fmatvec::VecV a, b;
107  bool amplitudePhaseAngleForm;
108  int size;
109  private:
110  };
111 
112 }
113 
114 #endif
void init(Element::InitStage stage)
plots time series header
Definition: fourier_function.h:91
Definition: utils.h:153
Definition: fourier_function.h:28
InitStage
The stages of the initialization.
Definition: element.h:97
Definition: utils.h:197
Definition: planar_contour.h:31
Definition: element.h:100

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML