MBSim

Project Page
extern_generalized_io.h
1 /* Copyright (C) 2004-2009 MBSim Development Team
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation; either
5  * version 2.1 of the License, or (at your option) any later version.
6  *
7  * This library is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10  * Lesser General Public License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with this library; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15  *
16  * Contact: martin.o.foerg@googlemail.com
17  */
18 
19 #ifndef _EXTERNGENERALIZEDIO_H_
20 #define _EXTERNGENERALIZEDIO_H_
21 
22 #include "mbsim/link.h"
23 
24 namespace MBSim {
25 
26  class ExternGeneralizedIO : public Link {
27  protected:
28  Object *connectedObject;
29  int qInd, uInd;
30  double m, a, t0;
32  std::string saved_ref;
33  Object *ref;
34  double factor;
35  int index;
36  };
37  std::vector<ApplyForceAlsoTo> applyForceAlsoTo;
38  public:
39  enum Type {
40  CONSTANT, LINEAR
41  };
42  ExternGeneralizedIO(const std::string &name);
43  void updateh(double, int i=0);
44  void updateg(double);
45  void updategd(double);
46 
47  void calcxSize();
48  void updatedx(double t, double dt);
49  void updatexd(double t);
50 
51  bool isActive() const { return true; }
52  bool gActiveChanged() { return false; }
53  std::string getType() const { return "ExternGeneralizedIO"; }
54  void init(InitStage stage);
55 
56  void connect(Object *obj, int qInd_, int uInd_) { connectedObject=obj; qInd=qInd_; uInd=uInd_; }
57  void setGeneralizedForce(double h) { la(0)=h; }
58  void setGeneralizedLinearForceParameters(double m_, double a_, double t0_) { m=m_; a=a_; t0=t0_; }
59  double getGeneralizedPosition() { return g(0); }
60  double getGeneralizedVelocity() { return gd(0); }
61 
62  void plot(double t, double dt=1);
63  void initializeUsingXML(TiXmlElement *element);
64  Type getType() { return type; }
65 
66  virtual void updateWRef(const fmatvec::Mat&, int) {}
67  virtual void updateVRef(const fmatvec::Mat&, int) {}
68  virtual void updatehRef(const fmatvec::Vec&, int) {}
69  virtual void updatedhdqRef(const fmatvec::Mat&, int) {}
70  virtual void updatedhduRef(const fmatvec::SqrMat&, int) {}
71  virtual void updatedhdtRef(const fmatvec::Vec&, int) {}
72  virtual void updaterRef(const fmatvec::Vec&, int) {}
73 
74  void addApplyForceAlsoTo(Object *ref, double factor, int index);
75 
76  private:
77  std::string saved_connectedObject;
78  protected:
79  Type type;
80  };
81 
82 }
83 
84 #endif /* _SPRINGDAMPER_H_ */