mbsim  4.0.0
MBSim Kernel
body.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 _BODY_H_
21 #define _BODY_H_
22 
23 #include <mbsim/objects/object.h>
24 namespace OpenMBV {
25  class Body;
26 }
27 
28 namespace MBSim {
29 
30  class Frame;
31  class Contour;
32 
49  class Body : public Object {
50  public:
55  Body(const std::string &name);
56 
60  ~Body() override;
61 
62  void setGeneralizedInitialPosition(const fmatvec::Vec &q0_) { q0 <<= q0_; }
63  void setGeneralizedInitialVelocity(const fmatvec::Vec &u0_) { u0 <<= u0_; }
64  void setGeneralizedInitialPosition(double q0_) { q0.resize(1,fmatvec::INIT,q0_); }
65  void setGeneralizedInitialVelocity(double u0_) { u0.resize(1,fmatvec::INIT,u0_); }
66 
67  /* INHERITED INTERFACE OF OBJECTINTERFACE */
68  void sethSize(int hSize_, int i=0) override;
69  void sethInd(int hInd_, int i=0) override;
70  /*******************************************************/
71 
72  /* INHERITED INTERFACE OF ELEMENT */
73  void plot() override;
74  void setDynamicSystemSolver(DynamicSystemSolver *sys) override;
75  /*******************************************************/
76 
77  /* INHERITED INTERFACE OF OBJECT */
78  void init(InitStage stage, const InitConfigSet &config) override;
79  /*******************************************************/
80 
81  void createPlotGroup() override;
82 
83  /* INTERFACE FOR DERIVED CLASSES */
84 
90  virtual Contour* getContour(const std::string &name, bool check=true) const;
91 
97  virtual Frame* getFrame(const std::string &name, bool check=true) const;
98 
102  virtual Frame *getFrameOfReference() { return R; }
103 
107  virtual const Frame *getFrameOfReference() const { return R; }
108 
112  virtual void setFrameOfReference(Frame *frame) { R = frame; }
113  /*******************************************************/
114 
115  /* GETTER / SETTER */
116  const std::vector<Frame*>& getFrames() const { return frame; }
117  const std::vector<Contour*>& getContours() const { return contour; }
118  std::shared_ptr<OpenMBV::Group> getOpenMBVGrp() override { return openMBVGrp; }
119  std::shared_ptr<OpenMBV::Body>& getOpenMBVBody() { return openMBVBody; }
120  std::shared_ptr<OpenMBV::Group> getFramesOpenMBVGrp() override { return framesOpenMBVGrp; }
121  std::shared_ptr<OpenMBV::Group> getContoursOpenMBVGrp() override { return contoursOpenMBVGrp; }
122  H5::GroupBase *getFramesPlotGroup() override { return framesPlotGroup; }
123  H5::GroupBase *getContoursPlotGroup() override { return contoursPlotGroup; }
124  /*******************************************************/
125 
130  int frameIndex(const Frame *frame_) const;
131 
136  int contourIndex(const Contour *contour_) const;
137 
138  void initializeUsingXML(xercesc::DOMElement *element) override;
139 
140  Element * getChildByContainerAndName(const std::string &container, const std::string &name) const override;
141 
142  fmatvec::Mat3xV& getPJT(int i=0, bool check=true) { assert((not check) or (not updPJ)); return PJT[i]; }
143  fmatvec::Mat3xV& getPJR(int i=0, bool check=true) { assert((not check) or (not updPJ)); return PJR[i]; }
144 
145  const fmatvec::Mat3xV& evalPJT() { if(updPJ) updateJacobians(); return PJT[0]; }
146  const fmatvec::Mat3xV& evalPJR() { if(updPJ) updateJacobians(); return PJR[0]; }
147 
148  void resetUpToDate() override;
149  virtual void resetPositionsUpToDate();
150  virtual void resetVelocitiesUpToDate();
151  virtual void resetJacobiansUpToDate();
152  virtual void resetGyroscopicAccelerationsUpToDate();
153  virtual void updateJacobians() { }
154 
158  virtual void addFrame(Frame * frame);
159 
163  virtual void addContour(Contour* contour);
164 
165  protected:
169  std::vector<Frame*> frame;
170  std::vector<Contour*> contour;
171 
176 
180  fmatvec::Mat3xV PJT[2], PJR[2];
181 
182  bool updPos, updVel, updPJ;
183 
184  std::shared_ptr<OpenMBV::Body> openMBVBody;
185  std::shared_ptr<OpenMBV::Group> openMBVGrp;
186  std::shared_ptr<OpenMBV::Group> framesOpenMBVGrp;
187  std::shared_ptr<OpenMBV::Group> contoursOpenMBVGrp;
188  H5::GroupBase *framesPlotGroup;
189  H5::GroupBase *contoursPlotGroup;
190 
191  private:
192  std::string saved_frameOfReference;
193  };
194 
195 }
196 
197 #endif
198 
virtual void setFrameOfReference(Frame *frame)
Definition: body.h:112
solver interface for modelling and simulation of dynamic systems
Definition: dynamic_system_solver.h:58
int contourIndex(const Contour *contour_) const
Definition: body.cc:176
basic class for contour definition for rigid (which do not know about their shape) and flexible (they...
Definition: contour.h:40
fmatvec::Mat3xV PJT[2]
Definition: body.h:180
Frame * R
frame of reference of the object
Definition: body.h:175
int frameIndex(const Frame *frame_) const
Definition: body.cc:168
virtual const Frame * getFrameOfReference() const
Definition: body.h:107
void init(InitStage stage, const InitConfigSet &config) override
plots time series header
Definition: body.cc:80
virtual Contour * getContour(const std::string &name, bool check=true) const
Definition: body.cc:140
InitStage
The stages of the initialization.
Definition: element.h:64
Element * getChildByContainerAndName(const std::string &container, const std::string &name) const override
Get the Element named name in the container named container.
Definition: body.cc:196
void setDynamicSystemSolver(DynamicSystemSolver *sys) override
sets the used dynamics system solver to the element
Definition: body.cc:71
virtual Frame * getFrame(const std::string &name, bool check=true) const
Definition: body.cc:154
std::string name
name of element
Definition: element.h:262
std::vector< Frame * > frame
vector of frames and contours
Definition: body.h:169
cartesian frame on bodies used for application of e.g. links and loads
Definition: frame.h:39
Body(const std::string &name)
constructor
Definition: body.cc:35
virtual void addContour(Contour *contour)
Definition: body.cc:122
void plot() override
plots time dependent data
Definition: body.cc:62
~Body() override
destructor
Definition: body.cc:37
virtual Frame * getFrameOfReference()
Definition: body.h:102
Element(const std::string &name)
constructor
Definition: element.cc:68
virtual void addFrame(Frame *frame)
Definition: body.cc:131
void createPlotGroup() override
creates the plotGroup for H5-output
Definition: body.cc:116
base class for all mechanical bodies with mass and generalised coordinates
Definition: body.h:49
class for all objects having own dynamics and mass
Definition: object.h:42
fmatvec::Vec q0
initial position, velocity
Definition: object.h:309
namespace MBSim
Definition: bilateral_constraint.cc:29