mbsimflexiblebody  3.2.0
flexible_body.h
00001 /* Copyright (C) 2004-2011 MBSim Development Team
00002  *
00003  * This library is free software; you can redistribute it and/or
00004  * modify it under the terms of the GNU Lesser General Public
00005  * License as published by the Free Software Foundation; either
00006  * version 2.1 of the License, or (at your option) any later version.
00007  *
00008  * This library is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  * Lesser General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU Lesser General Public
00014  * License along with this library; if not, write to the Free Software
00015  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
00016  *
00017  * Contact: thorsten.schindler@mytum.de
00018  *          rzander@users.berlios.de
00019  */
00020 
00021 #ifndef _FLEXIBLE_BODY_H_
00022 #define _FLEXIBLE_BODY_H_
00023 
00024 #define MBSIMFLEXNS "{http://mbsim.berlios.de/MBSimFlexibleBody}"
00025 
00026 #include "mbsim/body.h"
00027 #include "mbsim/frame.h"
00028 
00029 namespace MBSim {
00030   class DiscretizationInterface;
00031   class ContourPointData;
00032 }
00033 
00034 namespace MBSimFlexibleBody {
00035 
00051   class FlexibleBody : public MBSim::Body {
00052     public:
00057       FlexibleBody(const std::string &name);
00058 
00062       virtual ~FlexibleBody();
00063 
00064       /* INHERITED INTERFACE OF OBJECTINTERFACE */
00065       virtual void updatedq(double t, double dt) { qd = u*dt; }
00066       virtual void updateqd(double t) { qd = u; }
00067       virtual void updateh(double t, int k=0);
00068       virtual void updateM(double t, int k=0);
00069       virtual void updatedhdz(double t);
00070       virtual void updateStateDependentVariables(double t);
00071       virtual void updateJacobians(double t, int k=0);
00072 
00073       /* INHERITED INTERFACE OF ELEMENT */
00074       virtual void plot(double t, double dt=1);
00075       virtual std::string getType() const { return "FlexibleBody"; }
00076       virtual void initializeUsingXML(MBXMLUtils::TiXmlElement *element);
00077       /***************************************************/
00078 
00079       /* INHERITED INTERFACE OF OBJECT */
00080       virtual void init(MBSim::InitStage stage);
00081       virtual double computeKineticEnergy();
00082       virtual double computePotentialEnergy();
00083       virtual void setFrameOfReference(MBSim::Frame *frame);
00084       void setq0(fmatvec::Vec q0_) { if(q0_.size()) MBSim::Body::setInitialGeneralizedPosition(q0_); q<<q0; }
00085       void setu0(fmatvec::Vec u0_) { if(u0_.size()) MBSim::Body::setInitialGeneralizedVelocity(u0_); u<<u0; }
00086       /***************************************************/
00087 
00088       /* INTERFACE TO BE DEFINED IN DERIVED CLASSES */
00092       virtual void BuildElements() = 0;
00093 
00100       virtual void GlobalVectorContribution(int CurrentElement, const fmatvec::Vec &locVec, fmatvec::Vec &gloVec) = 0;
00101 
00108       virtual void GlobalMatrixContribution(int CurrentElement, const fmatvec::Mat &locMat, fmatvec::Mat &gloMat) = 0;
00109 
00116       virtual void GlobalMatrixContribution(int CurrentElement, const fmatvec::SymMat &locMat, fmatvec::SymMat &gloMat) = 0;
00117 
00124       virtual void updateKinematicsForFrame(MBSim::ContourPointData &data, MBSim::FrameFeature ff, MBSim::Frame *frame=0) = 0;
00125 
00131       virtual void updateJacobiansForFrame(MBSim::ContourPointData &data, MBSim::Frame *frame=0) = 0;
00132       /***************************************************/
00133 
00134       /* GETTER / SETTER */
00140       void setMassProportionalDamping(const double d_) { d_massproportional = d_; }
00141       /***************************************************/
00142 
00147       void addFrame(const std::string &name, const MBSim::ContourPointData &S_);
00148 
00153       void addFrame(MBSim::Frame *frame, const MBSim::ContourPointData &S_);
00154 
00159       void addFrame(const std::string &name, const int &id);
00160 
00165       void addFrame(MBSim::Frame *frame, const  int &id);
00166 
00167       void addContour(MBSim::Contour *contour);
00168 
00178       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()) ;}
00179 
00185       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()) ;}
00186 
00187     protected:
00191       std::vector<MBSim::DiscretizationInterface*> discretization;
00192 
00196       std::vector<fmatvec::Vec> qElement;
00197 
00201       std::vector<fmatvec::Vec> uElement;
00202 
00206       double d_massproportional;
00207 
00211       std::vector<MBSim::ContourPointData> S_Frame;
00212   };
00213 
00220   template <class AT>
00221     class FlexibleBodyContinuum : public FlexibleBody {
00222       public:
00227         FlexibleBodyContinuum<AT>(const std::string &name) : FlexibleBody(name) {}
00228 
00229         /* INHERITED INTERFACE OF ELEMENT */
00230         virtual std::string getType() const { return "FlexibleBodyContinuum"; }
00231 
00232         /* GETTER / SETTER */
00233         void setContourNodes(const std::vector<AT> nodes) { userContourNodes = nodes; }
00234 
00235         using FlexibleBody::addFrame;
00236 
00241         void addFrame(const std::string &name, const AT& alpha) {
00242           MBSim::ContourPointData cp(alpha);
00243           FlexibleBody::addFrame(name,cp);
00244         }
00245 
00250         void addFrame(MBSim::Frame *frame, const AT& alpha) {
00251           MBSim::ContourPointData cp(alpha);
00252           FlexibleBody::addFrame(frame,cp);
00253         }
00254 
00255       protected:
00259         std::vector<AT> userContourNodes;
00260     };
00261 }
00262 
00263 #endif /* _FLEXIBLE_BODY_H_ */
00264