mbsimflexiblebody  3.0.0
flexible_body.h
1 /* Copyright (C) 2004-2011 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: thorsten.schindler@mytum.de
18  * rzander@users.berlios.de
19  */
20 
21 #ifndef _FLEXIBLE_BODY_H_
22 #define _FLEXIBLE_BODY_H_
23 
24 #define MBSIMFLEXNS "{http://mbsim.berlios.de/MBSimFlexibleBody}"
25 
26 #include "mbsim/body.h"
27 #include "mbsim/frame.h"
28 
29 namespace MBSim {
30  class DiscretizationInterface;
31  class ContourPointData;
32 }
33 
34 namespace MBSimFlexibleBody {
35 
51  class FlexibleBody : public MBSim::Body {
52  public:
57  FlexibleBody(const std::string &name);
58 
62  virtual ~FlexibleBody();
63 
64  /* INHERITED INTERFACE OF OBJECTINTERFACE */
65  virtual void updatedq(double t, double dt) { qd = u*dt; }
66  virtual void updateqd(double t) { qd = u; }
67  virtual void updateh(double t, int k=0);
68  virtual void updateM(double t, int k=0);
69  virtual void updatedhdz(double t);
70  virtual void updateStateDependentVariables(double t);
71  virtual void updateJacobians(double t, int k=0);
72 
73  /* INHERITED INTERFACE OF ELEMENT */
74  virtual void plot(double t, double dt=1);
75  virtual std::string getType() const { return "FlexibleBody"; }
76  virtual void initializeUsingXML(TiXmlElement *element);
77  /***************************************************/
78 
79  /* INHERITED INTERFACE OF OBJECT */
80  virtual void init(MBSim::InitStage stage);
81  virtual double computeKineticEnergy();
82  virtual double computePotentialEnergy();
83  virtual void setFrameOfReference(MBSim::Frame *frame);
84  void setq0(fmatvec::Vec q0_) { MBSim::Body::setInitialGeneralizedPosition(q0_); q<<q0; }
85  void setu0(fmatvec::Vec u0_) { MBSim::Body::setInitialGeneralizedVelocity(u0_); u<<u0; }
86  /***************************************************/
87 
88  /* INTERFACE TO BE DEFINED IN DERIVED CLASSES */
92  virtual void BuildElements() = 0;
93 
100  virtual void GlobalVectorContribution(int CurrentElement, const fmatvec::Vec &locVec, fmatvec::Vec &gloVec) = 0;
101 
108  virtual void GlobalMatrixContribution(int CurrentElement, const fmatvec::Mat &locMat, fmatvec::Mat &gloMat) = 0;
109 
116  virtual void GlobalMatrixContribution(int CurrentElement, const fmatvec::SymMat &locMat, fmatvec::SymMat &gloMat) = 0;
117 
124  virtual void updateKinematicsForFrame(MBSim::ContourPointData &data, MBSim::FrameFeature ff, MBSim::Frame *frame=0) = 0;
125 
131  virtual void updateJacobiansForFrame(MBSim::ContourPointData &data, MBSim::Frame *frame=0) = 0;
132  /***************************************************/
133 
134  /* GETTER / SETTER */
140  void setMassProportionalDamping(const double d_) { d_massproportional = d_; }
141  /***************************************************/
142 
147  void addFrame(const std::string &name, const MBSim::ContourPointData &S_);
148 
153  void addFrame(MBSim::Frame *frame, const MBSim::ContourPointData &S_);
154 
159  void addFrame(const std::string &name, const int &id);
160 
165  void addFrame(MBSim::Frame *frame, const int &id);
166 
176  virtual void exportPositionVelocity(const std::string & filenamePos, const std::string & filenameVel = std::string(), const int & deg = 3, const bool &writePsFile = false){throw MBSim::MBSimError("exportPositionVelocity(const std::string& filenamePos, const std::string& filenameVel, const int& deg, const bool& writePsFile) is not implemented for " + this->getType()) ;}
177 
183  virtual void importPositionVelocity(const std::string& filenamePos, const std::string& filenameVel = std::string()){throw MBSim::MBSimError("importPositionVelocity(const std::string& filenamePos, const std::string& filenameVel) is not implemented for " + this->getType()) ;}
184 
185  protected:
189  std::vector<MBSim::DiscretizationInterface*> discretization;
190 
194  std::vector<fmatvec::Vec> qElement;
195 
199  std::vector<fmatvec::Vec> uElement;
200 
205 
209  std::vector<MBSim::ContourPointData> S_Frame;
210  };
211 
218  template <class AT>
220  public:
225  FlexibleBodyContinuum<AT>(const std::string &name) : FlexibleBody(name) {}
226 
227  /* INHERITED INTERFACE OF ELEMENT */
228  virtual std::string getType() const { return "FlexibleBodyContinuum"; }
229 
230  /* GETTER / SETTER */
231  void setContourNodes(const std::vector<AT> nodes) { userContourNodes = nodes; }
232 
234 
239  void addFrame(const std::string &name, const AT& alpha) {
240  MBSim::ContourPointData cp(alpha);
241  FlexibleBody::addFrame(name,cp);
242  }
243 
248  void addFrame(MBSim::Frame *frame, const AT& alpha) {
249  MBSim::ContourPointData cp(alpha);
250  FlexibleBody::addFrame(frame,cp);
251  }
252 
253  protected:
257  std::vector<AT> userContourNodes;
258  };
259 }
260 
261 #endif /* _FLEXIBLE_BODY_H_ */
262