MBSim

Project Page
object.h
1 /* Copyright (C) 2004-2010 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: martin.o.foerg@googlemail.com
18  */
19 
20 #ifndef _OBJECT_H_
21 #define _OBJECT_H_
22 
23 #include "mbsim/element.h"
24 //#include "mbsim/object_interface.h"
25 
26 namespace MBSim {
27 
28  class DynamicSystem;
29  class Link;
30 
41  //class Object : public Element, public ObjectInterface {
42  class Object : public Element {
43  public:
47  Object(const std::string &name);
48 
52  virtual ~Object();
53 
54  /* INHERITED INTERFACE OF OBJECTINTERFACE */
55  virtual void updateT(double t) {};
56  virtual void updateh(double t, int j=0) {};
57  virtual void updateh0Fromh1(double t);
58  virtual void updateW0FromW1(double t);
59  virtual void updateV0FromV1(double t);
60  virtual void updateM(double t, int i=0) {};
61  virtual void updatedhdz(double t);
62  virtual void updatedq(double t, double dt);
63  virtual void updatedu(double t, double dt);
64  virtual void updateud(double t, int i=0);
65  virtual void updateqd(double t);
66  virtual void updatezd(double t);
67  virtual void sethSize(int hSize_, int i=0);
68  virtual int gethSize(int i=0) const { return hSize[i]; }
69  virtual int getqSize() const { return qSize; }
70  virtual int getuSize(int i=0) const { return uSize[i]; }
71  virtual void calcqSize() {};
72  virtual void calcuSize(int j) {};
73  //virtual int getqInd(DynamicSystem* sys);
74  virtual int getuInd(int i=0) { return uInd[i]; }
75  //virtual int getuInd(DynamicSystem* sys, int i=0);
76  virtual void setqInd(int qInd_) { qInd = qInd_; }
77  virtual void setuInd(int uInd_, int i=0) { uInd[i] = uInd_; }
78  //virtual int gethInd(DynamicSystem* sys,int i=0);
79  virtual const fmatvec::Vec& getq() const { return q; };
80  virtual const fmatvec::Vec& getu() const { return u; };
81  virtual H5::Group *getPlotGroup() { return plotGroup; }
84  virtual void updateStateDependentVariables(double t) = 0;
85  virtual void updateStateDerivativeDependentVariables(double t) {};
86  virtual void updateJacobians(double t, int j=0) = 0;
87  virtual void updatehInverseKinetics(double t, int i=0) {};
88  /*******************************************************/
89 
90  /* INHERITED INTERFACE OF ELEMENT */
91  virtual void plot(double t, double dt = 1);
92  virtual void closePlot();
93  virtual std::string getType() const { return "Object"; }
94  //virtual void setDynamicSystemSolver(DynamicSystemSolver *sys);
95  /*******************************************************/
96 
101  virtual void updateqRef(const fmatvec::Vec& qRef);
102 
107  virtual void updateqdRef(const fmatvec::Vec& qdRef);
108 
113  virtual void updateuRef(const fmatvec::Vec& uRef);
114 
119  virtual void updateuallRef(const fmatvec::Vec& uallRef);
120 
125  virtual void updateudRef(const fmatvec::Vec& udRef, int i=0);
126 
131  virtual void updateudallRef(const fmatvec::Vec& udallRef, int i=0);
132 
138  virtual void updatehRef(const fmatvec::Vec& hRef, int i=0);
139 
140  virtual void updateWRef(const fmatvec::Mat& WRef, int i=0);
141  virtual void updateVRef(const fmatvec::Mat& VRef, int i=0);
142 
148  virtual void updatedhdqRef(const fmatvec::Mat& dhdqRef, int i=0);
149 
155  virtual void updatedhduRef(const fmatvec::SqrMat& dhduRef, int i=0);
156 
162  virtual void updatedhdtRef(const fmatvec::Vec& dhdtRef, int i=0);
163 
168  virtual void updaterRef(const fmatvec::Vec& ref, int i=0);
169 
174  virtual void updateTRef(const fmatvec::Mat &ref);
175 
181  virtual void updateMRef(const fmatvec::SymMat &ref, int i=0);
182 
188  virtual void updateLLMRef(const fmatvec::SymMat &ref, int i=0);
189 
193  virtual void init(InitStage stage);
194 
198  virtual void initz();
199 
203  virtual void facLLM(int i=0);
204 
209  std::vector<Object*> getObjectsDependingOn() const { return dependency; }
210 
211  void addDependency(Object* obj) { dependency.push_back(obj); }
218  int cutDependencies();
219  int computeLevel();
220 
225  virtual void calcSize(int j) {}
226 
230  virtual double computeKineticEnergy() { return 0.5*u.T()*M[0]*u; }
231 
235  virtual double computePotentialEnergy() { return 0; }
236 
240  virtual void setUpInverseKinetics() {}
241  /*******************************************************/
242 
243  /* GETTER / SETTER */
244  void setqSize(int qSize_) { qSize = qSize_; }
245  void setuSize(int uSize_, int i=0) { uSize[i] = uSize_; }
246  int getzSize() const { return qSize + uSize[0]; }
247 
248  virtual void sethInd(int hInd_, int i=0);
249  int gethInd(int i=0) { return hInd[i]; }
250 
251  const fmatvec::Vec& geth(int i=0) const { return h[i]; };
252  fmatvec::Vec& geth(int i=0) { return h[i]; };
253  const fmatvec::Vec& getr(int i=0) const { return r[i]; };
254  fmatvec::Vec& getr(int i=0) { return r[i]; };
255  const fmatvec::SymMat& getM(int i=0) const { return M[i]; };
256  fmatvec::SymMat& getM(int i=0) { return M[i]; };
257  const fmatvec::Mat& getT() const { return T; };
258  fmatvec::Mat& getT() { return T; };
259  const fmatvec::SymMat& getLLM(int i=0) const { return LLM[i]; };
260  fmatvec::SymMat& getLLM(int i=0) { return LLM[i]; };
261 
262  fmatvec::Vec& getq() { return q; };
263  fmatvec::Vec& getu() { return u; };
264 
265  const fmatvec::Vec& getq0() const { return q0; };
266  const fmatvec::Vec& getu0() const { return u0; };
267  fmatvec::Vec& getq0() { return q0; };
268  fmatvec::Vec& getu0() { return u0; };
269 
270  const fmatvec::Vec& getqd() const { return qd; };
271  const fmatvec::Vec& getud(int i=0) const { return ud[i]; };
272  fmatvec::Vec& getqd() { return qd; };
273  fmatvec::Vec& getud(int i=0) { return ud[i]; };
274 
275  void setq(const fmatvec::Vec &q_) { q = q_; }
276  void setu(const fmatvec::Vec &u_) { u = u_; }
277 
278  void setInitialGeneralizedPosition(const fmatvec::Vec &q0_) { q0 = q0_; }
279  void setInitialGeneralizedVelocity(const fmatvec::Vec &u0_) { u0 = u0_; }
280  void setInitialGeneralizedPosition(double q0_) { q0 = fmatvec::Vec(1,fmatvec::INIT,q0_); }
281  void setInitialGeneralizedVelocity(double u0_) { u0 = fmatvec::Vec(1,fmatvec::INIT,u0_); }
282 
283  /*******************************************************/
284 
285  virtual void initializeUsingXML(TiXmlElement *element);
286 
287  virtual Element* getByPathSearch(std::string path);
288 
289  protected:
293  int qSize;
294 
298  int uSize[2];
299 
303  int hSize[2];
304 
308  int qInd, uInd[2], hInd[2];
309 
313  fmatvec::Vec q, u, uall;
314 
318  fmatvec::Vec q0, u0;
319 
323  fmatvec::Vec qd, ud[2], udall[2];
324 
328  fmatvec::Vec h[2], r[2];
329 
330  fmatvec::Mat W[2], V[2];
331 
335  fmatvec::Mat dhdq;
336  fmatvec::SqrMat dhdu;
337  fmatvec::Vec dhdt;
338 
342  fmatvec::Mat T;
343 
347  fmatvec::SymMat M[2];
348 
352  fmatvec::SymMat LLM[2];
353 
357  //fmatvec::Index Iu, Ih;
358 
362  std::vector<Object*> dependency;
363  };
364 
365 }
366 
367 #endif /* _OBJECT_H_ */
368