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  */
19 
20 #ifndef _ELEMENT_H_
21 #define _ELEMENT_H_
22 
23 #include "fmatvec/fmatvec.h"
24 #include "fmatvec/atom.h"
25 #include "mbsim/objectfactory.h"
26 #include <string>
27 #include <hdf5serie/vectorserie.h>
28 #include <mbxmlutilshelper/dom.h>
29 
30 #include "mbsim_event.h"
31 
32 namespace OpenMBV {
33  class Group;
34 }
35 
36 namespace H5 {
37  class Group;
38 }
39 
43 namespace MBSim {
44 
45 #ifndef SWIG
46  const MBXMLUtils::NamespaceURI MBSIM("http://www.mbsim-env.de/MBSim");
47 #endif
48 
49  class DynamicSystemSolver;
50  class Frame;
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 */
105  LASTINITSTAGE
106  };
107 
111  Element(const std::string &name);
112 
116  virtual ~Element();
117 
118  /* INTERFACE */
122  virtual void initDataInterfaceBase(DynamicSystemSolver *parentds) {};
123 
127  virtual std::string getType() const { return "Element"; }
128 
133  virtual void setDynamicSystemSolver(DynamicSystemSolver *sys) { ds = sys; }
134 
140  virtual void plot();
141 
147  virtual void plotAtSpecialEvent() {}
148 
152  virtual void closePlot();
153  /***************************************************/
154 
158  const std::string& getName() const { return name; }
159 
163  void setName(const std::string &str) { name = str; }
164 
165  // internal function do not use
166  void setPath(const std::string &str) { path=str; }
167 
172 
177  virtual void init(InitStage stage);
178 
182  virtual void createPlotGroup();
183 
188 
195  virtual void setPlotFeature(PlotFeature pf, PlotFeatureStatus value) { plotFeature[pf]=value; }
196 
202  void setPlotFeatureForChildren(PlotFeature pf, PlotFeatureStatus value) { plotFeatureForChildren[pf]=value; }
203 
209  void setPlotFeatureRecursive(PlotFeature pf, PlotFeatureStatus value) { plotFeature[pf]=value; plotFeatureForChildren[pf]=value; }
210 
215 
219  PlotFeatureStatus getPlotFeatureForChildren(PlotFeature pf) { return plotFeatureForChildren[pf]; }
220 
221  PlotFeatureStatus initializePlotFeatureStatusUsingXML(xercesc::DOMElement *e);
222  PlotFeature initializePlotFeatureUsingXML(xercesc::DOMElement *e);
223  virtual void initializeUsingXML(xercesc::DOMElement *element);
224 
225  const std::vector<MBXMLUtils::EmbedDOMLocator>& getLocationStack() const { return locationStack; }
226 
231  template<class T> T* getByPath(const std::string &path, bool initialCaller=true) const;
232 
238  std::string getPath(const Element *relTo=NULL, std::string sep="/") const;
239 
243  virtual Element* getChildByContainerAndName(const std::string &container, const std::string &name) const {
244  THROW_MBSIMERROR("This element has no containers with childs.");
245  }
246 
247  // some convenience function for XML
248  static double getDouble(xercesc::DOMElement *e);
249  static int getInt(xercesc::DOMElement *e);
250  static bool getBool(xercesc::DOMElement *e);
251  static fmatvec::Vec3 getVec3(xercesc::DOMElement *e);
252  static fmatvec::Vec getVec(xercesc::DOMElement *e, int rows=0);
253  static fmatvec::Mat3xV getMat3xV(xercesc::DOMElement *e, int cols=0);
254  static fmatvec::Mat getMat(xercesc::DOMElement *e, int rows=0, int cols=0);
255  static fmatvec::SqrMat3 getSqrMat3(xercesc::DOMElement *e);
256  static fmatvec::SqrMat getSqrMat(xercesc::DOMElement *e, int size=0);
257  static fmatvec::SymMat3 getSymMat3(xercesc::DOMElement *e);
258  static fmatvec::SymMat getSymMat(xercesc::DOMElement *e, int size=0);
259 
260  virtual std::shared_ptr<OpenMBV::Group> getOpenMBVGrp() {return std::shared_ptr<OpenMBV::Group>();}
261 
262  virtual Element* getParent() {return parent;}
263  virtual const Element* getParent() const {return parent;}
264  virtual void setParent(Element* parent_) {parent = parent_;}
265 
270  std::vector<Element*> getDependencies() const { return dependency; }
271 
272  void addDependency(Element* ele) { if(ele) dependency.push_back(ele); }
273 
279  int computeLevel();
280 
281  virtual void updatePositions(Frame *frame) { }
282  virtual void updateVelocities(Frame *frame) { }
283  virtual void updateAccelerations(Frame *frame) { }
284  virtual void updateJacobians(Frame *frame, int j=0) { }
285  virtual void updateGyroscopicAccelerations(Frame *frame) { }
286 
287  virtual void resetUpToDate() {}
288 
289  const double& getTime() const;
290  double getStepSize() const;
291 
292  protected:
293  Element *parent;
294 
298  std::string name;
299 
305  std::string path;
306 
307  std::vector<MBXMLUtils::EmbedDOMLocator> locationStack;
308 
313 
318 
322  std::vector<double> plotVector;
323 
327  std::vector<std::string> plotColumns;
328 
333 
334  void updatePlotFeatures();
335 
339  std::vector<Element*> dependency;
340 
341  private:
345  PlotFeatureStatus plotFeature[LASTPLOTFEATURE], plotFeatureForChildren[LASTPLOTFEATURE];
346  };
347 
348  template<class T>
349  T* Element::getByPath(const std::string &path, bool initialCaller) const {
350  try {
351  if(path.substr(0, 1) == "/") { // if absolute path ...
352  if(parent) // .. and a parent exists ...
353  return parent->getByPath<T>(path, false); // ... than call getByPath of the parent (walk to the top)
354  else // .. and no parent exits ...
355  return getByPath<T>(path.substr(1), false); // ... we are at top and call getByPath again with the leading "/" removed (call relative to top)
356  }
357  else if (path.substr(0, 3) == "../") // if relative path to parent ...
358  return parent->getByPath<T>(path.substr(3), false); // ... call getByPath of the parent with the leading "../" removed
359  else { // if relative path to a child ...
360  // extract the first path and all other paths (rest)
361  size_t idx=path.find('/');
362  std::string first=path.substr(0, idx);
363  std::string rest;
364  if(idx!=std::string::npos)
365  rest=path.substr(idx+1);
366  // get the object of the first child path by calling the virtual function getChildByContainerAndName
367  size_t pos0=first.find('[');
368  if(pos0==std::string::npos)
369  THROW_MBSIMERROR("Syntax error in subreference '"+first+"': no [ found.");
370  std::string container=first.substr(0, pos0);
371  if(first[first.size()-1]!=']')
372  THROW_MBSIMERROR("Syntax error in subreference '"+first+"': not ending with ].");
373  std::string name=first.substr(pos0+1, first.size()-pos0-2);
374  Element *e=getChildByContainerAndName(container, name);
375  // if their are other child paths call getByPath of e for this
376  if(!rest.empty())
377  return e->getByPath<T>(rest, false);
378  // this is the last relative path -> check type and return
379  T *t=dynamic_cast<T*>(e);
380  if(t)
381  return t;
382  else
383  THROW_MBSIMERROR("Cannot cast this element to type "+container+".");
384  }
385  }
386  catch(MBSimError &ex) {
387  if(initialCaller)
388  THROW_MBSIMERROR("Evaluation of refernece '"+path+"' failed: Message from "+
389  ex.getPath()+": "+ex.getErrorMessage());
390  else
391  throw ex;
392  }
393  }
394 
395 
396 }
397 
398 #endif
std::vector< Element * > getDependencies() const
checks dependency on other elements.
Definition: element.h:270
virtual void createPlotGroup()
creates the plotGroup for H5-output
Definition: element.cc:103
Definition: element.h:64
virtual void plot()
plots time dependent data
Definition: element.cc:54
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:243
Definition: element.h:101
DynamicSystemSolver * getDynamicSystemSolver()
Definition: element.h:171
solver interface for modelling and simulation of dynamic systems
Definition: dynamic_system_solver.h:48
Definition: element.h:83
virtual void setPlotFeature(PlotFeature pf, PlotFeatureStatus value)
Set a plot feature.
Definition: element.h:195
std::vector< Element * > dependency
vector containing all dependencies.
Definition: element.h:339
Definition: element.h:80
Definition: element.h:84
virtual void plotAtSpecialEvent()
plots time dependent data at special events
Definition: element.h:147
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:133
Definition: element.h:77
Definition: element.h:85
H5::VectorSerie< double > * plotVectorSerie
time series
Definition: element.h:317
basic class of MBSim mainly for plotting
Definition: element.h:58
virtual void initDataInterfaceBase(DynamicSystemSolver *parentds)
TODO.
Definition: element.h:122
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:305
DynamicSystemSolver * ds
dynamic system
Definition: element.h:312
H5::GroupBase * getPlotGroup()
Definition: element.h:187
virtual std::string getType() const
Definition: element.h:127
Definition: element.h:75
Definition: element.h:99
std::vector< std::string > plotColumns
columns of time series
Definition: element.h:327
Definition: element.h:103
Definition: element.h:102
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:209
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:349
std::vector< double > plotVector
one entry of time series
Definition: element.h:322
Definition: element.h:62
Definition: element.h:63
Definition: element.h:82
PlotFeatureStatus getPlotFeature(PlotFeature pf)
Definition: element.h:214
std::string name
name of element
Definition: element.h:298
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:158
virtual void setDynamicSystemSolver(DynamicSystemSolver *sys)
sets the used dynamics system solver to the element
Definition: element.h:133
Definition: element.h:104
H5::GroupBase * plotGroup
associated plot group
Definition: element.h:332
void setPlotFeatureForChildren(PlotFeature pf, PlotFeatureStatus value)
Set a plot feature for the children of this object.
Definition: element.h:202
void setName(const std::string &str)
Definition: element.h:163
PlotFeatureStatus plotFeature[LASTPLOTFEATURE]
plot feature
Definition: element.h:345
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:368
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:219

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML