MBSim

Project Page
extern_generalized_io.h
00001 /* Copyright (C) 2004-2009 MBSim Development Team
00002  * This library is free software; you can redistribute it and/or 
00003  * modify it under the terms of the GNU Lesser General Public 
00004  * License as published by the Free Software Foundation; either 
00005  * version 2.1 of the License, or (at your option) any later version. 
00006  *  
00007  * This library is distributed in the hope that it will be useful, 
00008  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
00009  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
00010  * Lesser General Public License for more details. 
00011  *  
00012  * You should have received a copy of the GNU Lesser General Public 
00013  * License along with this library; if not, write to the Free Software 
00014  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
00015  *
00016  * Contact: martin.o.foerg@googlemail.com
00017  */
00018 
00019 #ifndef _EXTERNGENERALIZEDIO_H_
00020 #define _EXTERNGENERALIZEDIO_H_
00021 
00022 #include "mbsim/link.h"
00023 
00024 namespace MBSim {
00025 
00026   class ExternGeneralizedIO : public Link {
00027     protected:
00028       Object *connectedObject;
00029       int qInd, uInd;
00030       double m, a, t0;
00031       struct ApplyForceAlsoTo {
00032         std::string saved_ref;
00033         Object *ref;
00034         double factor;
00035         int index;
00036       };
00037       std::vector<ApplyForceAlsoTo> applyForceAlsoTo;
00038     public:
00039       enum Type {
00040         CONSTANT, LINEAR
00041       };
00042       ExternGeneralizedIO(const std::string &name="");
00043       void updateh(double, int i=0);
00044       void updateg(double);
00045       void updategd(double);
00046 
00047       void calcxSize();
00048       void updatedx(double t, double dt);
00049       void updatexd(double t);
00050 
00051       bool isActive() const { return true; }
00052       bool gActiveChanged() { return false; }
00053       std::string getType() const { return "ExternGeneralizedIO"; }
00054       void init(InitStage stage);
00055 
00056       void connect(Object *obj, int qInd_, int uInd_) { connectedObject=obj; qInd=qInd_; uInd=uInd_; }
00057       void setGeneralizedForce(double h) { la(0)=h; }
00058       void setGeneralizedLinearForceParameters(double m_, double a_, double t0_) { m=m_; a=a_; t0=t0_; }
00059       double getGeneralizedPosition() { return g(0); }
00060       double getGeneralizedVelocity() { return gd(0); }
00061 
00062       void plot(double t, double dt=1);
00063       void initializeUsingXML(MBXMLUtils::TiXmlElement *element);
00064       Type getType() { return type; }
00065 
00066       virtual void updateWRef(const fmatvec::Mat&, int) {}
00067       virtual void updateVRef(const fmatvec::Mat&, int) {}
00068       virtual void updatehRef(const fmatvec::Vec&, int) {}
00069       virtual void updatedhdqRef(const fmatvec::Mat&, int) {}
00070       virtual void updatedhduRef(const fmatvec::SqrMat&, int) {}
00071       virtual void updatedhdtRef(const fmatvec::Vec&, int) {}
00072       virtual void updaterRef(const fmatvec::Vec&, int) {}
00073 
00074       void addApplyForceAlsoTo(Object *ref, double factor, int index);
00075 
00076     private:
00077       std::string saved_connectedObject;
00078     protected:
00079       Type type;
00080   };
00081 
00082 }
00083 
00084 #endif /* _SPRINGDAMPER_H_ */