00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _OBJECT_H_
00021 #define _OBJECT_H_
00022
00023 #include "mbsim/element.h"
00024
00025
00026 namespace MBSim {
00027
00028 class DynamicSystem;
00029 class Link;
00030
00041
00042 class Object : public Element {
00043 public:
00047 Object(const std::string &name);
00048
00052 virtual ~Object();
00053
00054
00055 virtual void updateT(double t) {};
00056 virtual void updateh(double t, int j=0) {};
00057 virtual void updateh0Fromh1(double t);
00058 virtual void updateW0FromW1(double t);
00059 virtual void updateV0FromV1(double t);
00060 virtual void updateM(double t, int i=0) {};
00061 virtual void updatedhdz(double t);
00062 virtual void updatedq(double t, double dt) { qd = T * u * dt; }
00063 virtual void updatedu(double t, double dt) { ud[0] = slvLLFac(LLM[0], h[0] * dt + r[0]); }
00064 virtual void updateud(double t, int i=0) { ud[i] = slvLLFac(LLM[i], h[i] + r[i]); }
00065 virtual void updateqd(double t) { qd = T * u; }
00066 virtual void updatezd(double t) { updateqd(t); updateud(t); updatexd(t); }
00067 virtual void sethSize(int hSize_, int i=0);
00068 virtual int gethSize(int i=0) const { return hSize[i]; }
00069 virtual int getqSize() const { return qSize; }
00070 virtual int getuSize(int i=0) const { return uSize[i]; }
00071 virtual void calcqSize() {};
00072 virtual void calcuSize(int j) {};
00073
00074 virtual int getuInd(int i=0) { return uInd[i]; }
00075
00076 virtual void setqInd(int qInd_) { qInd = qInd_; }
00077 virtual void setuInd(int uInd_, int i=0) { uInd[i] = uInd_; }
00078
00079 virtual const fmatvec::Vec& getq() const { return q; };
00080 virtual const fmatvec::Vec& getu() const { return u; };
00081 virtual H5::Group *getPlotGroup() { return plotGroup; }
00082 virtual PlotFeatureStatus getPlotFeature(PlotFeature fp) { return Element::getPlotFeature(fp); };
00083 virtual PlotFeatureStatus getPlotFeatureForChildren(PlotFeature fp) { return Element::getPlotFeatureForChildren(fp); };
00084 virtual void updateStateDependentVariables(double t) = 0;
00085 virtual void updateStateDerivativeDependentVariables(double t) {};
00086 virtual void updateJacobians(double t, int j=0) = 0;
00087 virtual void updatehInverseKinetics(double t, int i=0) {};
00088
00089
00090
00091 virtual void plot(double t, double dt = 1);
00092 virtual void closePlot();
00093 virtual std::string getType() const { return "Object"; }
00094
00095
00096
00097 virtual void updatedx(double t, double dt) {}
00098 virtual void updatexd(double t) {}
00099 virtual void calcxSize() { xSize = 0; }
00100 virtual const fmatvec::Vec& getx() const { return x; }
00101 virtual fmatvec::Vec& getx() { return x; }
00102 virtual void setxInd(int xInd_) { xInd = xInd_; };
00103 virtual int getxSize() const { return xSize; }
00104 virtual void updatexRef(const fmatvec::Vec& ref);
00105 virtual void updatexdRef(const fmatvec::Vec& ref);
00106
00111 virtual void updateqRef(const fmatvec::Vec& qRef);
00112
00117 virtual void updateqdRef(const fmatvec::Vec& qdRef);
00118
00123 virtual void updateuRef(const fmatvec::Vec& uRef);
00124
00129 virtual void updateuallRef(const fmatvec::Vec& uallRef);
00130
00135 virtual void updateudRef(const fmatvec::Vec& udRef, int i=0);
00136
00141 virtual void updateudallRef(const fmatvec::Vec& udallRef, int i=0);
00142
00148 virtual void updatehRef(const fmatvec::Vec& hRef, int i=0);
00149
00150 virtual void updateWRef(const fmatvec::Mat& WRef, int i=0);
00151 virtual void updateVRef(const fmatvec::Mat& VRef, int i=0);
00152
00158 virtual void updatedhdqRef(const fmatvec::Mat& dhdqRef, int i=0);
00159
00165 virtual void updatedhduRef(const fmatvec::SqrMat& dhduRef, int i=0);
00166
00172 virtual void updatedhdtRef(const fmatvec::Vec& dhdtRef, int i=0);
00173
00178 virtual void updaterRef(const fmatvec::Vec& ref, int i=0);
00179
00184 virtual void updateTRef(const fmatvec::Mat &ref);
00185
00191 virtual void updateMRef(const fmatvec::SymMat &ref, int i=0);
00192
00198 virtual void updateLLMRef(const fmatvec::SymMat &ref, int i=0);
00199
00203 virtual void init(InitStage stage);
00204
00208 virtual void initz();
00209
00213 virtual void writez(const H5::Group & group);
00214
00218 virtual void readz0(const H5::Group & group);
00219
00223 virtual void facLLM(int i=0) { LLM[i] = facLL(M[i]); }
00224
00229 std::vector<Object*> getObjectsDependingOn() const { return dependency; }
00230
00231 void addDependency(Object* obj) { dependency.push_back(obj); }
00238 int cutDependencies();
00239 int computeLevel();
00240
00245 virtual void calcSize(int j) {}
00246
00250 virtual double computeKineticEnergy() { return 0.5*u.T()*M[0]*u; }
00251
00255 virtual double computePotentialEnergy() { return 0; }
00256
00260 virtual void setUpInverseKinetics() {}
00261
00262
00263
00264 void setqSize(int qSize_) { qSize = qSize_; }
00265 void setuSize(int uSize_, int i=0) { uSize[i] = uSize_; }
00266 int getzSize() const { return qSize + uSize[0]; }
00267
00268 virtual void sethInd(int hInd_, int i=0);
00269 int gethInd(int i=0) { return hInd[i]; }
00270
00271 const fmatvec::Vec& geth(int i=0) const { return h[i]; };
00272 fmatvec::Vec& geth(int i=0) { return h[i]; };
00273 const fmatvec::Vec& getr(int i=0) const { return r[i]; };
00274 fmatvec::Vec& getr(int i=0) { return r[i]; };
00275 const fmatvec::SymMat& getM(int i=0) const { return M[i]; };
00276 fmatvec::SymMat& getM(int i=0) { return M[i]; };
00277 const fmatvec::Mat& getT() const { return T; };
00278 fmatvec::Mat& getT() { return T; };
00279 const fmatvec::SymMat& getLLM(int i=0) const { return LLM[i]; };
00280 fmatvec::SymMat& getLLM(int i=0) { return LLM[i]; };
00281
00282 fmatvec::Vec& getq() { return q; };
00283 fmatvec::Vec& getu() { return u; };
00284
00285 const fmatvec::Vec& getq0() const { return q0; };
00286 const fmatvec::Vec& getu0() const { return u0; };
00287 fmatvec::Vec& getq0() { return q0; };
00288 fmatvec::Vec& getu0() { return u0; };
00289
00290 const fmatvec::Vec& getqd() const { return qd; };
00291 const fmatvec::Vec& getud(int i=0) const { return ud[i]; };
00292 fmatvec::Vec& getqd() { return qd; };
00293 fmatvec::Vec& getud(int i=0) { return ud[i]; };
00294
00295 void setq(const fmatvec::Vec &q_) { q = q_; }
00296 void setu(const fmatvec::Vec &u_) { u = u_; }
00297
00298
00299
00300 virtual void initializeUsingXML(xercesc::DOMElement *element);
00301 virtual xercesc::DOMElement* writeXMLFile(xercesc::DOMNode *element);
00302
00303 virtual Element* getByPathSearch(std::string path);
00304
00305 protected:
00309 int qSize;
00310
00314 int uSize[2];
00315
00319 int hSize[2];
00320
00324 int qInd, uInd[2], hInd[2];
00325
00329 int xSize, xInd;
00330
00334 fmatvec::Vec q, u, uall, x;
00335
00339 fmatvec::Vec q0, u0, x0;
00340
00344 fmatvec::Vec qd, ud[2], udall[2], xd;
00345
00349 fmatvec::Vec h[2], r[2];
00350
00351 fmatvec::Mat W[2], V[2];
00352
00356 fmatvec::Mat dhdq;
00357 fmatvec::SqrMat dhdu;
00358 fmatvec::Vec dhdt;
00359
00363 fmatvec::Mat T;
00364
00368 fmatvec::SymMat M[2];
00369
00373 fmatvec::SymMat LLM[2];
00374
00378
00379
00383 std::vector<Object*> dependency;
00384 };
00385
00386 }
00387
00388 #endif
00389