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 {
43  public:
47  Object(const std::string &name);
48 
49  virtual void calcSize() { }
50  int getGeneralizedPositionSize() { if(updSize) calcSize(); return nq; }
51  int getGeneralizedVelocitySize() { if(updSize) calcSize(); return nu; }
52 
53  virtual void updateT() { }
54  virtual void updateh(int j=0) { }
55  virtual void updateM() { }
56  virtual void updatedhdz();
57  virtual void updatedq();
58  virtual void updatedu();
59  virtual void updateud();
60  virtual void updateqd();
61  virtual void sethSize(int hSize_, int i=0);
62  virtual int gethSize(int i=0) const { return hSize[i]; }
63  virtual int getqSize() const { return qSize; }
64  virtual int getuSize(int i=0) const { return uSize[i]; }
65  virtual void calcqSize() { }
66  virtual void calcuSize(int j) { }
67  virtual int getqInd() { return qInd; }
68  virtual int getuInd(int i=0) { return uInd[i]; }
69  virtual void setqInd(int qInd_) { qInd = qInd_; }
70  virtual void setuInd(int uInd_, int i=0) { uInd[i] = uInd_; }
71  virtual const fmatvec::Vec& getq() const { return q; }
72  virtual const fmatvec::Vec& getu() const { return u; }
73  virtual H5::GroupBase *getPlotGroup() { return plotGroup; }
74 
75  /* INHERITED INTERFACE OF ELEMENT */
76  void plot() override;
77  /*******************************************************/
78 
83  virtual void updateqRef(fmatvec::Vec& qRef);
84 
89  virtual void updateqdRef(fmatvec::Vec& qdRef);
90 
95  virtual void updatedqRef(fmatvec::Vec& dqRef);
96 
101  virtual void updateuRef(fmatvec::Vec& uRef);
102 
107  virtual void updateuallRef(fmatvec::Vec& uallRef);
108 
113  virtual void updateudRef(fmatvec::Vec& udRef);
114 
119  virtual void updateduRef(fmatvec::Vec& duRef);
120 
125  virtual void updateudallRef(fmatvec::Vec& udallRef);
126 
132  virtual void updatehRef(fmatvec::Vec& hRef, int i=0);
133 
139  virtual void updatedhdqRef(fmatvec::Mat& dhdqRef, int i=0);
140 
146  virtual void updatedhduRef(fmatvec::SqrMat& dhduRef, int i=0);
147 
153  virtual void updatedhdtRef(fmatvec::Vec& dhdtRef, int i=0);
154 
159  virtual void updaterRef(fmatvec::Vec& ref, int i=0);
160 
165  virtual void updaterdtRef(fmatvec::Vec& ref);
166 
171  virtual void updateTRef(fmatvec::Mat &ref);
172 
178  virtual void updateMRef(fmatvec::SymMat &ref);
179 
185  virtual void updateLLMRef(fmatvec::SymMat &ref);
186 
190  void init(InitStage stage, const InitConfigSet &config) override;
191 
195  virtual void initz();
196 
200  virtual void writez(H5::GroupBase *group);
201 
205  virtual void readz0(H5::GroupBase *group);
206 
210  virtual void updateLLM() { LLM = facLL(evalM()); }
211 
215  virtual void setUpInverseKinetics() { }
216  /*******************************************************/
217 
218  /* GETTER / SETTER */
219  void setqSize(int qSize_) { qSize = qSize_; }
220  void setuSize(int uSize_, int i=0) { uSize[i] = uSize_; }
221  int getzSize() const { return qSize + uSize[0]; }
222 
223  virtual void sethInd(int hInd_, int i=0);
224  int gethInd(int i=0) { return hInd[i]; }
225 
226  const fmatvec::SymMat& getM(bool check=true) const;
227  fmatvec::SymMat& getM(bool check=true);
228  const fmatvec::Vec& geth(int i=0, bool check=true) const;
229  fmatvec::Vec& geth(int i=0, bool check=true);
230 
231  fmatvec::Vec& getq() { return q; };
232  fmatvec::Vec& getu() { return u; };
233 
234  const fmatvec::Vec& getq0() const { return q0; };
235  const fmatvec::Vec& getu0() const { return u0; };
236  fmatvec::Vec& getq0() { return q0; };
237  fmatvec::Vec& getu0() { return u0; };
238 
239  const fmatvec::Mat& evalT();
240  const fmatvec::Vec& evalh(int i=0);
241  const fmatvec::SymMat& evalM();
242  const fmatvec::SymMat& evalLLM();
243  const fmatvec::Vec& evalr(int i=0);
244  const fmatvec::Vec& evalrdt();
245  const fmatvec::Vec& evalqd();
246  const fmatvec::Vec& evalud();
247  const fmatvec::Vec& evaludall();
248 
249  fmatvec::Vec& getud(bool check=true);
250  fmatvec::Vec& getudall(bool check=true);
251 
252  void resetUpToDate() override { updq = true; updu = true; updqd = true; updud = true; }
253 
254  virtual void updateGeneralizedPositions();
255  virtual void updateGeneralizedVelocities();
256  virtual void updateGeneralizedAccelerations();
257  virtual void updateDerivativeOfGeneralizedPositions();
258 
259  const fmatvec::VecV& evalGeneralizedPosition() { if(updq) updateGeneralizedPositions(); return qRel; }
260  const fmatvec::VecV& evalGeneralizedVelocity() { if(updu) updateGeneralizedVelocities(); return uRel; }
261  const fmatvec::VecV& evalDerivativeOfGeneralizedPosition() { if(updqd) updateDerivativeOfGeneralizedPositions(); return qdRel; }
262  const fmatvec::VecV& evalGeneralizedAcceleration() { if(updud) updateGeneralizedAccelerations(); return udRel; }
263  fmatvec::VecV& getGeneralizedPosition(bool check=true) { assert((not check) or (not updq)); return qRel; }
264  fmatvec::VecV& getGeneralizedVelocity(bool check=true) { assert((not check) or (not updu)); return uRel; }
265  fmatvec::VecV& getDerivativeOfGeneralizedPosition(bool check=true) { assert((not check) or (not updqd)); return qdRel; }
266  fmatvec::VecV& getGeneralizedAcceleration(bool check=true) { assert((not check) or (not updud)); return udRel; }
267 
268  void setq(const fmatvec::Vec &q_) { q = q_; }
269  void setu(const fmatvec::Vec &u_) { u = u_; }
270 
271  bool hasNonCostantMassMatrix() { return nonConstantMassMatrix; }
272  /*******************************************************/
273 
274  void initializeUsingXML(xercesc::DOMElement *element) override;
275 
276  void createPlotGroup() override;
277 
278  protected:
279  int nq, nu;
280 
284  int qSize;
285 
289  int uSize[2];
290 
294  int hSize[2];
295 
299  int qInd, uInd[2], hInd[2];
300 
304  fmatvec::Vec q, u, uall;
305 
309  fmatvec::Vec q0, u0;
310 
314  fmatvec::Vec qd, ud, dq, du, udall;
315 
319  fmatvec::Vec h[2], r[2], rdt;
320 
321  fmatvec::Mat W[2], V[2];
322 
326  fmatvec::Mat dhdq;
327  fmatvec::SqrMat dhdu;
328  fmatvec::Vec dhdt;
329 
333  fmatvec::Mat T;
334 
338  fmatvec::SymMat M;
339 
343  fmatvec::SymMat LLM;
344 
345  fmatvec::VecV qRel, uRel, qdRel, udRel;
346 
347  bool updSize, updq, updu, updqd, updud;
348 
349  bool nonConstantMassMatrix{true};
350  };
351 
352 }
353 
354 #endif /* _OBJECT_H_ */
int qInd
indices of positions, velocities, right hand side
Definition: object.h:299
virtual void updateuallRef(fmatvec::Vec &uallRef)
references to velocities of dynamic system parent
Definition: object.cc:126
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:150
virtual void updateduRef(fmatvec::Vec &duRef)
references to differentiated velocities of dynamic system parent
Definition: object.cc:134
virtual void updateudallRef(fmatvec::Vec &udallRef)
references to differentiated velocities of dynamic system parent
Definition: object.cc:138
Object(const std::string &name)
constructor
Definition: object.cc:43
virtual void updateLLM()
perform Cholesky decomposition of mass martix
Definition: object.h:210
fmatvec::Mat T
linear relation matrix of differentiated position and velocity parameters
Definition: object.h:333
virtual void updateqRef(fmatvec::Vec &qRef)
references to positions of dynamic system parent
Definition: object.cc:110
int qSize
size of object positions
Definition: object.h:284
void plot() override
plots time dependent data
Definition: object.cc:100
virtual void initz()
Definition: object.cc:196
fmatvec::Vec q
positions, velocities
Definition: object.h:304
basic class of MBSim mainly for plotting
Definition: element.h:58
virtual void writez(H5::GroupBase *group)
writes its z-Vector to a subgroup of the given group
Definition: object.cc:213
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:146
virtual void updaterdtRef(fmatvec::Vec &ref)
references to nonsmooth force vector of dynamic system parent
Definition: object.cc:162
int hSize[2]
size of object h-vector (columns of J)
Definition: object.h:294
fmatvec::SymMat LLM
LU-decomposition of mass matrix.
Definition: object.h:343
void init(InitStage stage, const InitConfigSet &config) override
initialize object at start of simulation with respect to contours and frames
Definition: object.cc:178
virtual void updateTRef(fmatvec::Mat &ref)
references to linear transformation matrix between differentiated positions and velocities of dynamic...
Definition: object.cc:166
InitStage
The stages of the initialization.
Definition: element.h:64
std::string name
name of element
Definition: element.h:251
void createPlotGroup() override
creates the plotGroup for H5-output
Definition: object.cc:345
virtual void updateqdRef(fmatvec::Vec &qdRef)
references to differentiated positions of dynamic system parent
Definition: object.cc:114
fmatvec::Mat dhdq
Jacobians of h.
Definition: object.h:326
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:154
virtual void updateMRef(fmatvec::SymMat &ref)
references to mass matrix of dynamic system parent
Definition: object.cc:170
int uSize[2]
size of object velocities
Definition: object.h:289
virtual void updaterRef(fmatvec::Vec &ref, int i=0)
references to nonsmooth force vector of dynamic system parent
Definition: object.cc:158
virtual void readz0(H5::GroupBase *group)
reads the z-Vector of a subgroup of the given group
Definition: object.cc:219
virtual void updatedqRef(fmatvec::Vec &dqRef)
references to differentiated positions of dynamic system parent
Definition: object.cc:118
fmatvec::Vec h[2]
complete and object smooth and nonsmooth right hand side
Definition: object.h:319
H5::GroupBase * plotGroup
associated plot group
Definition: element.h:288
virtual void updateudRef(fmatvec::Vec &udRef)
references to differentiated velocities of dynamic system parent
Definition: object.cc:130
virtual void updateLLMRef(fmatvec::SymMat &ref)
references to Cholesky decomposition of dynamic system parent
Definition: object.cc:174
virtual void updatehRef(fmatvec::Vec &hRef, int i=0)
references to smooth force vector of dynamic system parent
Definition: object.cc:142
fmatvec::SymMat M
mass matrix
Definition: object.h:338
fmatvec::Vec qd
differentiated positions, velocities
Definition: object.h:314
virtual void updateuRef(fmatvec::Vec &uRef)
references to velocities of dynamic system parent
Definition: object.cc:122
class for all objects having own dynamics and mass
Definition: object.h:42
fmatvec::Vec q0
initial position, velocity
Definition: object.h:309
virtual void setUpInverseKinetics()
TODO.
Definition: object.h:215
namespace MBSim
Definition: bilateral_constraint.cc:29