mbsim  4.0.0
MBSim Kernel
object.h
1 /* Copyright (C) 2004-2014 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 
25 namespace MBSim {
26 
27  extern const PlotFeatureEnum generalizedPosition, generalizedVelocity, derivativeOfGeneralizedPosition, generalizedAcceleration;
28 
29  class DynamicSystem;
30  class Link;
31 
42  //class Object : public Element, public ObjectInterface {
43  class Object : public Element {
44  public:
48  Object(const std::string &name);
49 
50  virtual void calcSize() { }
51  int getGeneralizedPositionSize() { if(updSize) calcSize(); return nq; }
52  int getGeneralizedVelocitySize() { if(updSize) calcSize(); return nu; }
53 
54  virtual void updateT() { }
55  virtual void updateh(int j=0) { }
56  virtual void updateM() { }
57  virtual void updatedhdz();
58  virtual void updatedq();
59  virtual void updatedu();
60  virtual void updateud();
61  virtual void updateqd();
62  virtual void sethSize(int hSize_, int i=0);
63  virtual int gethSize(int i=0) const { return hSize[i]; }
64  virtual int getqSize() const { return qSize; }
65  virtual int getuSize(int i=0) const { return uSize[i]; }
66  virtual void calcqSize() { }
67  virtual void calcuSize(int j) { }
68  virtual int getqInd() { return qInd; }
69  virtual int getuInd(int i=0) { return uInd[i]; }
70  virtual void setqInd(int qInd_) { qInd = qInd_; }
71  virtual void setuInd(int uInd_, int i=0) { uInd[i] = uInd_; }
72  virtual const fmatvec::Vec& getq() const { return q; }
73  virtual const fmatvec::Vec& getu() const { return u; }
74  virtual H5::GroupBase *getPlotGroup() { return plotGroup; }
75 
76  /* INHERITED INTERFACE OF ELEMENT */
77  void plot() override;
78  /*******************************************************/
79 
84  virtual void updateqRef(fmatvec::Vec& qRef);
85 
90  virtual void updateqdRef(fmatvec::Vec& qdRef);
91 
96  virtual void updatedqRef(fmatvec::Vec& dqRef);
97 
102  virtual void updateuRef(fmatvec::Vec& uRef);
103 
108  virtual void updateuallRef(fmatvec::Vec& uallRef);
109 
114  virtual void updateudRef(fmatvec::Vec& udRef);
115 
120  virtual void updateduRef(fmatvec::Vec& duRef);
121 
126  virtual void updateudallRef(fmatvec::Vec& udallRef);
127 
133  virtual void updatehRef(fmatvec::Vec& hRef, int i=0);
134 
140  virtual void updatedhdqRef(fmatvec::Mat& dhdqRef, int i=0);
141 
147  virtual void updatedhduRef(fmatvec::SqrMat& dhduRef, int i=0);
148 
154  virtual void updatedhdtRef(fmatvec::Vec& dhdtRef, int i=0);
155 
160  virtual void updaterRef(fmatvec::Vec& ref, int i=0);
161 
166  virtual void updaterdtRef(fmatvec::Vec& ref);
167 
172  virtual void updateTRef(fmatvec::Mat &ref);
173 
179  virtual void updateMRef(fmatvec::SymMat &ref);
180 
186  virtual void updateLLMRef(fmatvec::SymMat &ref);
187 
191  void init(InitStage stage, const InitConfigSet &config) override;
192 
196  virtual void initz();
197 
201  virtual void writez(H5::GroupBase *group);
202 
206  virtual void readz0(H5::GroupBase *group);
207 
211  virtual void updateLLM() { LLM = facLL(evalM()); }
212 
216  virtual double evalKineticEnergy() { return 0.5*u.T()*evalM()*u; }
217 
221  virtual double evalPotentialEnergy() { return 0; }
222 
226  virtual void setUpInverseKinetics() { }
227  /*******************************************************/
228 
229  /* GETTER / SETTER */
230  void setqSize(int qSize_) { qSize = qSize_; }
231  void setuSize(int uSize_, int i=0) { uSize[i] = uSize_; }
232  int getzSize() const { return qSize + uSize[0]; }
233 
234  virtual void sethInd(int hInd_, int i=0);
235  int gethInd(int i=0) { return hInd[i]; }
236 
237  const fmatvec::SymMat& getM(bool check=true) const;
238  fmatvec::SymMat& getM(bool check=true);
239  const fmatvec::Vec& geth(int i=0, bool check=true) const;
240  fmatvec::Vec& geth(int i=0, bool check=true);
241 
242  fmatvec::Vec& getq() { return q; };
243  fmatvec::Vec& getu() { return u; };
244 
245  const fmatvec::Vec& getq0() const { return q0; };
246  const fmatvec::Vec& getu0() const { return u0; };
247  fmatvec::Vec& getq0() { return q0; };
248  fmatvec::Vec& getu0() { return u0; };
249 
250  const fmatvec::Mat& evalT();
251  const fmatvec::Vec& evalh(int i=0);
252  const fmatvec::SymMat& evalM();
253  const fmatvec::SymMat& evalLLM();
254  const fmatvec::Vec& evalr(int i=0);
255  const fmatvec::Vec& evalrdt();
256  const fmatvec::Vec& evalqd();
257  const fmatvec::Vec& evalud();
258  const fmatvec::Vec& evaludall();
259 
260  fmatvec::Vec& getud(bool check=true);
261  fmatvec::Vec& getudall(bool check=true);
262 
263  void resetUpToDate() override { updq = true; updu = true; updqd = true; updud = true; }
264 
265  virtual void updateGeneralizedPositions();
266  virtual void updateGeneralizedVelocities();
267  virtual void updateGeneralizedAccelerations();
268  virtual void updateDerivativeOfGeneralizedPositions();
269 
270  const fmatvec::VecV& evalGeneralizedPosition() { if(updq) updateGeneralizedPositions(); return qRel; }
271  const fmatvec::VecV& evalGeneralizedVelocity() { if(updu) updateGeneralizedVelocities(); return uRel; }
272  const fmatvec::VecV& evalDerivativeOfGeneralizedPosition() { if(updqd) updateDerivativeOfGeneralizedPositions(); return qdRel; }
273  const fmatvec::VecV& evalGeneralizedAcceleration() { if(updud) updateGeneralizedAccelerations(); return udRel; }
274  fmatvec::VecV& getGeneralizedPosition(bool check=true) { assert((not check) or (not updq)); return qRel; }
275  fmatvec::VecV& getGeneralizedVelocity(bool check=true) { assert((not check) or (not updu)); return uRel; }
276  fmatvec::VecV& getDerivativeOfGeneralizedPosition(bool check=true) { assert((not check) or (not updqd)); return qdRel; }
277  fmatvec::VecV& getGeneralizedAcceleration(bool check=true) { assert((not check) or (not updud)); return udRel; }
278 
279  void setq(const fmatvec::Vec &q_) { q = q_; }
280  void setu(const fmatvec::Vec &u_) { u = u_; }
281 
282  bool hasNonCostantMassMatrix() { return nonConstantMassMatrix; }
283  /*******************************************************/
284 
285  void initializeUsingXML(xercesc::DOMElement *element) override;
286 
287  protected:
288  int nq, nu;
289 
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 
319 
323  fmatvec::Vec qd, ud, dq, du, udall;
324 
328  fmatvec::Vec h[2], r[2], rdt;
329 
330  fmatvec::Mat W[2], V[2];
331 
336  fmatvec::SqrMat dhdu;
337  fmatvec::Vec dhdt;
338 
343 
348 
353 
354  fmatvec::VecV qRel, uRel, qdRel, udRel;
355 
356  bool updSize, updq, updu, updqd, updud;
357 
358  bool nonConstantMassMatrix{true};
359  };
360 
361 }
362 
363 #endif /* _OBJECT_H_ */
int qInd
indices of positions, velocities, right hand side
Definition: object.h:308
virtual void updateuallRef(fmatvec::Vec &uallRef)
references to velocities of dynamic system parent
Definition: object.cc:145
virtual void updatedhduRef(fmatvec::SqrMat &dhduRef, int i=0)
references to object Jacobian for implicit integration of dynamic system parent regarding velocities
Definition: object.cc:169
virtual void updateduRef(fmatvec::Vec &duRef)
references to differentiated velocities of dynamic system parent
Definition: object.cc:153
virtual void updateudallRef(fmatvec::Vec &udallRef)
references to differentiated velocities of dynamic system parent
Definition: object.cc:157
Object(const std::string &name)
constructor
Definition: object.cc:43
virtual void updateLLM()
perform Cholesky decomposition of mass martix
Definition: object.h:211
fmatvec::Mat T
linear relation matrix of differentiated position and velocity parameters
Definition: object.h:342
virtual void updateqRef(fmatvec::Vec &qRef)
references to positions of dynamic system parent
Definition: object.cc:129
int qSize
size of object positions
Definition: object.h:293
void plot() override
plots time dependent data
Definition: object.cc:100
virtual void initz()
Definition: object.cc:232
fmatvec::Vec q
positions, velocities
Definition: object.h:313
basic class of MBSim mainly for plotting
Definition: element.h:56
virtual void writez(H5::GroupBase *group)
writes its z-Vector to a subgroup of the given group
Definition: object.cc:247
virtual void updatedhdqRef(fmatvec::Mat &dhdqRef, int i=0)
references to object Jacobian for implicit integration of dynamic system parent regarding positions
Definition: object.cc:165
virtual void updaterdtRef(fmatvec::Vec &ref)
references to nonsmooth force vector of dynamic system parent
Definition: object.cc:181
int hSize[2]
size of object h-vector (columns of J)
Definition: object.h:303
fmatvec::SymMat LLM
LU-decomposition of mass matrix.
Definition: object.h:352
void init(InitStage stage, const InitConfigSet &config) override
initialize object at start of simulation with respect to contours and frames
Definition: object.cc:197
virtual void updateTRef(fmatvec::Mat &ref)
references to linear transformation matrix between differentiated positions and velocities of dynamic...
Definition: object.cc:185
InitStage
The stages of the initialization.
Definition: element.h:62
std::string name
name of element
Definition: element.h:235
virtual void updateqdRef(fmatvec::Vec &qdRef)
references to differentiated positions of dynamic system parent
Definition: object.cc:133
fmatvec::Mat dhdq
Jacobians of h.
Definition: object.h:335
virtual double evalKineticEnergy()
Definition: object.h:216
virtual void updatedhdtRef(fmatvec::Vec &dhdtRef, int i=0)
references to object Jacobian for implicit integration of dynamic system parent regarding time
Definition: object.cc:173
virtual void updateMRef(fmatvec::SymMat &ref)
references to mass matrix of dynamic system parent
Definition: object.cc:189
int uSize[2]
size of object velocities
Definition: object.h:298
virtual void updaterRef(fmatvec::Vec &ref, int i=0)
references to nonsmooth force vector of dynamic system parent
Definition: object.cc:177
virtual void readz0(H5::GroupBase *group)
reads the z-Vector of a subgroup of the given group
Definition: object.cc:253
virtual void updatedqRef(fmatvec::Vec &dqRef)
references to differentiated positions of dynamic system parent
Definition: object.cc:137
fmatvec::Vec h[2]
complete and object smooth and nonsmooth right hand side
Definition: object.h:328
H5::GroupBase * plotGroup
associated plot group
Definition: element.h:272
virtual void updateudRef(fmatvec::Vec &udRef)
references to differentiated velocities of dynamic system parent
Definition: object.cc:149
virtual void updateLLMRef(fmatvec::SymMat &ref)
references to Cholesky decomposition of dynamic system parent
Definition: object.cc:193
virtual void updatehRef(fmatvec::Vec &hRef, int i=0)
references to smooth force vector of dynamic system parent
Definition: object.cc:161
fmatvec::SymMat M
mass matrix
Definition: object.h:347
fmatvec::Vec qd
differentiated positions, velocities
Definition: object.h:323
virtual void updateuRef(fmatvec::Vec &uRef)
references to velocities of dynamic system parent
Definition: object.cc:141
class for all objects having own dynamics and mass
Definition: object.h:43
fmatvec::Vec q0
initial position, velocity
Definition: object.h:318
virtual void setUpInverseKinetics()
TODO.
Definition: object.h:226
namespace MBSim
Definition: eigenanalyzer.cc:47
virtual double evalPotentialEnergy()
Definition: object.h:221