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 
25 namespace MBSim {
26 
27  template<typename Sig> class VectorValuedFunction;
28 
29  // VectorValuedFunction with a double as argument (including 2nd derivative)
30  template<typename Ret>
31  class VectorValuedFunction<Ret(double)> : public Function<Ret(double)> {
33  public:
35  VectorValuedFunction(const std::vector<Function<double(double)> *> &component_) : component(component_) {
36  for(std::vector<Function<double(double)> *>::iterator it=component.begin(); it!=component.end(); ++it)
37  (*it)->setParent(this);
38  }
40  for (unsigned int i=1; i<component.size(); i++)
41  delete component[i];
42  }
43  void addComponent(Function<double(double)> *function) {
44  component.push_back(function);
45  function->setParent(this);
46  }
47  Ret operator()(const double &x) {
48  Ret y(component.size(),fmatvec::NONINIT);
49  for (unsigned int i=0; i<component.size(); i++)
50  y(i)=(*component[i])(x);
51  return y;
52  }
53  typename B::DRetDArg parDer(const double &x) {
54  typename B::DRetDArg y(component.size(),fmatvec::NONINIT);
55  for (unsigned int i=0; i<component.size(); i++)
56  y(i)=component[i]->parDer(x);
57  return y;
58  }
59  typename B::DDRetDDArg parDerParDer(const double &x) {
60  typename B::DDRetDDArg y(component.size(),fmatvec::NONINIT);
61  for (unsigned int i=0; i<component.size(); i++)
62  y(i)=component[i]->parDerParDer(x);
63  return y;
64  }
65 
66  void initializeUsingXML(xercesc::DOMElement *element) {
67  xercesc::DOMElement *e=MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%"components")->getFirstElementChild();
68  while (e) {
69  addComponent(ObjectFactory::createAndInit<Function<double(double)> >(e));
70  e=e->getNextElementSibling();
71  }
72  }
73  void init(Element::InitStage stage) {
75  for(std::vector<Function<double(double)> *>::iterator it=component.begin(); it!=component.end(); ++it)
76  (*it)->init(stage);
77  }
78  private:
79  std::vector<Function<double(double)> *> component;
80  };
81 
82  // VectorValuedFunction with a vector as argument (no 2nd derivative defined)
83  template<typename Ret, typename Arg>
84  class VectorValuedFunction<Ret(Arg)> : public Function<Ret(Arg)> {
86  public:
88  VectorValuedFunction(const std::vector<Function<double(Arg)> *> &component_) : component(component_) {
89  for(typename std::vector<Function<double(Arg)>*>::iterator it=component.begin(); it!=component.end(); ++it)
90  (*it)->setParent(this);
91  }
93  for (unsigned int i=1; i<component.size(); i++)
94  delete component[i];
95  }
96  void addComponent(Function<double(Arg)> *function) {
97  component.push_back(function);
98  function->setParent(this);
99  }
100  Ret operator()(const Arg &x) {
101  Ret y(component.size(),fmatvec::NONINIT);
102  for (unsigned int i=0; i<component.size(); i++)
103  y(i)=(*component[i])(x);
104  return y;
105  }
106  typename B::DRetDArg parDer(const Arg &x) {
107  typename B::DRetDArg y(component.size(),x.size(),fmatvec::NONINIT);
108  for (unsigned int i=0; i<component.size(); i++) {
109  auto row=component[i]->parDer(x);
110  for (int j=0; j<x.size(); j++)
111  y(i,j)=row(j);
112  }
113  return y;
114  }
115 
116  void initializeUsingXML(xercesc::DOMElement *element) {
117  xercesc::DOMElement *e=MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%"components")->getFirstElementChild();
118  while (e) {
119  addComponent(ObjectFactory::createAndInit<Function<double(Arg)> >(e));
120  e=e->getNextElementSibling();
121  }
122  }
123  void init(Element::InitStage stage) {
125  for(typename std::vector<Function<double(Arg)> *>::iterator it=component.begin(); it!=component.end(); ++it)
126  (*it)->init(stage);
127  }
128  private:
129  std::vector<Function<double(Arg)> *> component;
130  };
131 
132 }
133 
134 #endif
void init(Element::InitStage stage)
plots time series header
Definition: vector_valued_function.h:73
InitStage
The stages of the initialization.
Definition: element.h:97
Definition: vector_valued_function.h:27
Definition: planar_contour.h:31
virtual void init(InitStage stage)
plots time series header
Definition: element.cc:70
static ContainerType * createAndInit(const xercesc::DOMElement *element)
Definition: objectfactory.h:87
void init(Element::InitStage stage)
plots time series header
Definition: vector_valued_function.h:123

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML