All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
element.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@googlemail.com
18  * rzander@users.berlios.de
19  */
20 
21 #ifndef _ELEMENT_H_
22 #define _ELEMENT_H_
23 
24 #include "fmatvec/fmatvec.h"
25 #include "fmatvec/atom.h"
26 #include "mbsim/objectfactory.h"
27 #include <string>
28 #include <hdf5serie/vectorserie.h>
29 #include <mbxmlutilshelper/dom.h>
30 
31 #include "mbsim_event.h"
32 
33 #ifdef HAVE_OPENMBVCPPINTERFACE
34 namespace OpenMBV {
35  class Group;
36 }
37 #endif
38 
39 namespace H5 {
40  class Group;
41 }
42 
46 namespace MBSim {
47 
48  const MBXMLUtils::NamespaceURI MBSIM("http://www.mbsim-env.de/MBSim");
49 
50  class DynamicSystemSolver;
51 
58  class Element : virtual public fmatvec::Atom {
59  public:
65  };
66 
67  // NOTE!!! When adding a new PlotFeature here, the default setting for this feature must
68  // be specified in dynamic_system_solver.cc:DynamicSystemSolver::constructor() and the
69  // new feature must also be added in
70  // element.cc:Element::initializeUsingXML(xercesc::DOMElement *element)
71  // and in
72  // mbsimxml/schema/mbsim.xsd.in
74  enum PlotFeature {
79  notMinimalState, // TODO
90  LASTPLOTFEATURE
91  };
92 
97  enum InitStage {
98  modelBuildup=0, /*< build up complex internal models */
108  LASTINITSTAGE
109  };
110 
114  Element(const std::string &name);
115 
119  virtual ~Element();
120 
121  /* INTERFACE */
125  virtual void initDataInterfaceBase(DynamicSystemSolver *parentds) {};
126 
130  virtual std::string getType() const { return "Element"; }
131 
136  virtual void setDynamicSystemSolver(DynamicSystemSolver *sys) { ds = sys; }
137 
143  virtual void plot(double t, double dt = 1);
144 
150  virtual void plotAtSpecialEvent(double t, double dt = 1) {}
151 
155  virtual void closePlot();
156  /***************************************************/
157 
161  const std::string& getName() const { return name; }
162 
166  void setName(const std::string &str) { name = str; }
167 
168  // internal function do not use
169  void setPath(const std::string &str) { path=str; }
170 
175 
180  virtual void init(InitStage stage);
181 
185  virtual void createPlotGroup();
186 
191 
198  virtual void setPlotFeature(PlotFeature pf, PlotFeatureStatus value) { plotFeature[pf]=value; }
199 
205  void setPlotFeatureForChildren(PlotFeature pf, PlotFeatureStatus value) { plotFeatureForChildren[pf]=value; }
206 
212  void setPlotFeatureRecursive(PlotFeature pf, PlotFeatureStatus value) { plotFeature[pf]=value; plotFeatureForChildren[pf]=value; }
213 
218 
222  PlotFeatureStatus getPlotFeatureForChildren(PlotFeature pf) { return plotFeatureForChildren[pf]; }
223 
224  virtual void initializeUsingXML(xercesc::DOMElement *element);
225  virtual xercesc::DOMElement* writeXMLFile(xercesc::DOMNode *element);
226 
227  const std::vector<MBXMLUtils::EmbedDOMLocator>& getLocationStack() const { return locationStack; }
228 
233  template<class T> T* getByPath(const std::string &path, bool initialCaller=true) const;
234 
240  std::string getPath(const Element *relTo=NULL, std::string sep="/") const;
241 
245  virtual Element* getChildByContainerAndName(const std::string &container, const std::string &name) const {
246  THROW_MBSIMERROR("This element has no containers with childs.");
247  }
248 
249  // some convenience function for XML
250  static double getDouble(xercesc::DOMElement *e);
251  static int getInt(xercesc::DOMElement *e);
252  static bool getBool(xercesc::DOMElement *e);
253  static fmatvec::Vec3 getVec3(xercesc::DOMElement *e);
254  static fmatvec::Vec getVec(xercesc::DOMElement *e, int rows=0);
255  static fmatvec::Mat3xV getMat3xV(xercesc::DOMElement *e, int cols=0);
256  static fmatvec::Mat getMat(xercesc::DOMElement *e, int rows=0, int cols=0);
257  static fmatvec::SqrMat3 getSqrMat3(xercesc::DOMElement *e);
258  static fmatvec::SqrMat getSqrMat(xercesc::DOMElement *e, int size=0);
259  static fmatvec::SymMat3 getSymMat3(xercesc::DOMElement *e);
260  static fmatvec::SymMat getSymMat(xercesc::DOMElement *e, int size=0);
261 
262 #ifdef HAVE_OPENMBVCPPINTERFACE
263  virtual boost::shared_ptr<OpenMBV::Group> getOpenMBVGrp() {return boost::shared_ptr<OpenMBV::Group>();}
264 #endif
265 
266  virtual Element* getParent() {return parent;}
267  virtual const Element* getParent() const {return parent;}
268  virtual void setParent(Element* parent_) {parent = parent_;}
269 
274  std::vector<Element*> getElementsDependingOn() const { return dependency; }
275 
276  void addDependency(Element* ele) { dependency.push_back(ele); }
282  int computeLevel();
283 
284  protected:
285  Element *parent;
286 
290  std::string name;
291 
297  std::string path;
298 
299  std::vector<MBXMLUtils::EmbedDOMLocator> locationStack;
300 
305 
310 
314  std::vector<double> plotVector;
315 
319  std::vector<std::string> plotColumns;
320 
325 
326  void updatePlotFeatures();
327 
331  std::vector<Element*> dependency;
332 
333  private:
337  PlotFeatureStatus plotFeature[LASTPLOTFEATURE], plotFeatureForChildren[LASTPLOTFEATURE];
338  };
339 
340  template<class T>
341  T* Element::getByPath(const std::string &path, bool initialCaller) const {
342  try {
343  if(path.substr(0, 1) == "/") { // if absolute path ...
344  if(parent) // .. and a parent exists ...
345  return parent->getByPath<T>(path, false); // ... than call getByPath of the parent (walk to the top)
346  else // .. and no parent exits ...
347  return getByPath<T>(path.substr(1), false); // ... we are at top and call getByPath again with the leading "/" removed (call relative to top)
348  }
349  else if (path.substr(0, 3) == "../") // if relative path to parent ...
350  return parent->getByPath<T>(path.substr(3), false); // ... call getByPath of the parent with the leading "../" removed
351  else { // if relative path to a child ...
352  // extract the first path and all other paths (rest)
353  size_t idx=path.find('/');
354  std::string first=path.substr(0, idx);
355  std::string rest;
356  if(idx!=std::string::npos)
357  rest=path.substr(idx+1);
358  // get the object of the first child path by calling the virtual function getChildByContainerAndName
359  size_t pos0=first.find('[');
360  if(pos0==std::string::npos)
361  THROW_MBSIMERROR("Syntax error in subreference '"+first+"': no [ found.");
362  std::string container=first.substr(0, pos0);
363  if(first[first.size()-1]!=']')
364  THROW_MBSIMERROR("Syntax error in subreference '"+first+"': not ending with ].");
365  std::string name=first.substr(pos0+1, first.size()-pos0-2);
366  Element *e=getChildByContainerAndName(container, name);
367  // if their are other child paths call getByPath of e for this
368  if(!rest.empty())
369  return e->getByPath<T>(rest, false);
370  // this is the last relative path -> check type and return
371  T *t=dynamic_cast<T*>(e);
372  if(t)
373  return t;
374  else
375  THROW_MBSIMERROR("Cannot cast this element to type "+container+".");
376  }
377  }
378  catch(MBSimError &ex) {
379  if(initialCaller)
380  THROW_MBSIMERROR("Evaluation of refernece '"+path+"' failed: Message from "+
381  ex.getPath()+": "+ex.getErrorMessage());
382  else
383  throw ex;
384  }
385  }
386 
387 
388 }
389 
390 #endif
virtual void createPlotGroup()
creates the plotGroup for H5-output
Definition: element.cc:103
Definition: element.h:64
Definition: element.h:86
virtual Element * getChildByContainerAndName(const std::string &container, const std::string &name) const
Get the Element named name in the container named container.
Definition: element.h:245
Definition: element.h:101
DynamicSystemSolver * getDynamicSystemSolver()
Definition: element.h:174
solver interface for modelling and simulation of dynamic systems
Definition: dynamic_system_solver.h:49
Definition: element.h:83
virtual void setPlotFeature(PlotFeature pf, PlotFeatureStatus value)
Set a plot feature.
Definition: element.h:198
std::vector< Element * > dependency
vector containing all dependencies.
Definition: element.h:331
Definition: element.h:80
Definition: element.h:84
std::string getPath(const Element *relTo=NULL, std::string sep="/") const
Return the path of this object. If relativeTo is not NULL return a relative path to relativeTo...
Definition: element.cc:132
Definition: element.h:77
Definition: element.h:85
H5::VectorSerie< double > * plotVectorSerie
time series
Definition: element.h:309
basic class of MBSim mainly for plotting
Definition: element.h:58
virtual void initDataInterfaceBase(DynamicSystemSolver *parentds)
TODO.
Definition: element.h:125
Definition: element.h:87
std::string path
The path of this object. Is set during the init stage reorganizeHierarchy. Before this the path is ca...
Definition: element.h:297
DynamicSystemSolver * ds
dynamic system
Definition: element.h:304
virtual void plot(double t, double dt=1)
plots time dependent data
Definition: element.cc:54
H5::GroupBase * getPlotGroup()
Definition: element.h:190
virtual std::string getType() const
Definition: element.h:130
virtual void plotAtSpecialEvent(double t, double dt=1)
plots time dependent data at special events
Definition: element.h:150
Definition: element.h:75
Definition: element.h:99
std::vector< std::string > plotColumns
columns of time series
Definition: element.h:319
Definition: element.h:105
Definition: element.h:104
Definition: element.h:88
void setPlotFeatureRecursive(PlotFeature pf, PlotFeatureStatus value)
Set a plot feature for this object and the children of this object.
Definition: element.h:212
virtual void closePlot()
closes plot file
Definition: element.cc:65
InitStage
The stages of the initialization.
Definition: element.h:97
T * getByPath(const std::string &path, bool initialCaller=true) const
Get the object of type T represented by the path path. Do not set any argurment other than path! ...
Definition: element.h:341
std::vector< double > plotVector
one entry of time series
Definition: element.h:314
Definition: element.h:62
Definition: element.h:63
Definition: element.h:82
PlotFeatureStatus getPlotFeature(PlotFeature pf)
Definition: element.h:217
std::string name
name of element
Definition: element.h:290
Definition: element.h:89
Definition: element.h:100
Definition: element.h:81
Definition: element.h:76
virtual void init(InitStage stage)
plots time series header
Definition: element.cc:70
virtual ~Element()
destructor
Definition: element.cc:51
const std::string & getName() const
Definition: element.h:161
virtual void setDynamicSystemSolver(DynamicSystemSolver *sys)
sets the used dynamics system solver to the element
Definition: element.h:136
Definition: element.h:106
H5::GroupBase * plotGroup
associated plot group
Definition: element.h:324
void setPlotFeatureForChildren(PlotFeature pf, PlotFeatureStatus value)
Set a plot feature for the children of this object.
Definition: element.h:205
void setName(const std::string &str)
Definition: element.h:166
PlotFeatureStatus plotFeature[LASTPLOTFEATURE]
plot feature
Definition: element.h:337
basic error class for mbsim
Definition: mbsim_event.h:38
Definition: element.h:78
int computeLevel()
computes the length of the pathes in the graph that represents the dependencies between all elements...
Definition: element.cc:365
std::vector< Element * > getElementsDependingOn() const
checks dependency on other elements.
Definition: element.h:274
PlotFeatureStatus
Plot feature status.
Definition: element.h:61
Element(const std::string &name)
constructor
Definition: element.cc:44
PlotFeature
Plot Features.
Definition: element.h:74
PlotFeatureStatus getPlotFeatureForChildren(PlotFeature pf)
Definition: element.h:222

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML