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 isSingleValued() const { return true; }
00052 
00053       bool isActive() const { return true; }
00054       bool gActiveChanged() { return false; }
00055       std::string getType() const { return "ExternGeneralizedIO"; }
00056       void init(InitStage stage);
00057 
00058       void connect(Object *obj, int qInd_, int uInd_) { connectedObject=obj; qInd=qInd_; uInd=uInd_; }
00059       void setGeneralizedForce(double h) { la(0)=h; }
00060       void setGeneralizedLinearForceParameters(double m_, double a_, double t0_) { m=m_; a=a_; t0=t0_; }
00061       const double& getGeneralizedPosition() { return g(0); }
00062       const double& getGeneralizedVelocity() { return gd(0); }
00063 
00064       void plot(double t, double dt=1);
00065       void initializeUsingXML(xercesc::DOMElement *element);
00066       Type getType() { return type; }
00067 
00068       virtual void updateWRef(const fmatvec::Mat&, int) {}
00069       virtual void updateVRef(const fmatvec::Mat&, int) {}
00070       virtual void updatehRef(const fmatvec::Vec&, int) {}
00071       virtual void updatedhdqRef(const fmatvec::Mat&, int) {}
00072       virtual void updatedhduRef(const fmatvec::SqrMat&, int) {}
00073       virtual void updatedhdtRef(const fmatvec::Vec&, int) {}
00074       virtual void updaterRef(const fmatvec::Vec&, int) {}
00075 
00076       void addApplyForceAlsoTo(Object *ref, double factor, int index);
00077 
00078     private:
00079       std::string saved_connectedObject;
00080     protected:
00081       Type type;
00082   };
00083 
00084 }
00085 
00086 #endif /* _SPRINGDAMPER_H_ */