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);
00063 virtual void updatedu(double t, double dt);
00064 virtual void updateud(double t, int i=0);
00065 virtual void updateqd(double t);
00066 virtual void updatezd(double 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
00101 virtual void updateqRef(const fmatvec::Vec& qRef);
00102
00107 virtual void updateqdRef(const fmatvec::Vec& qdRef);
00108
00113 virtual void updateuRef(const fmatvec::Vec& uRef);
00114
00119 virtual void updateuallRef(const fmatvec::Vec& uallRef);
00120
00125 virtual void updateudRef(const fmatvec::Vec& udRef, int i=0);
00126
00131 virtual void updateudallRef(const fmatvec::Vec& udallRef, int i=0);
00132
00138 virtual void updatehRef(const fmatvec::Vec& hRef, int i=0);
00139
00140 virtual void updateWRef(const fmatvec::Mat& WRef, int i=0);
00141 virtual void updateVRef(const fmatvec::Mat& VRef, int i=0);
00142
00148 virtual void updatedhdqRef(const fmatvec::Mat& dhdqRef, int i=0);
00149
00155 virtual void updatedhduRef(const fmatvec::SqrMat& dhduRef, int i=0);
00156
00162 virtual void updatedhdtRef(const fmatvec::Vec& dhdtRef, int i=0);
00163
00168 virtual void updaterRef(const fmatvec::Vec& ref, int i=0);
00169
00174 virtual void updateTRef(const fmatvec::Mat &ref);
00175
00181 virtual void updateMRef(const fmatvec::SymMat &ref, int i=0);
00182
00188 virtual void updateLLMRef(const fmatvec::SymMat &ref, int i=0);
00189
00193 virtual void init(InitStage stage);
00194
00198 virtual void initz();
00199
00203 virtual void writez(const H5::Group & group);
00204
00208 virtual void readz0(const H5::Group & group);
00209
00213 virtual void facLLM(int i=0);
00214
00219 std::vector<Object*> getObjectsDependingOn() const { return dependency; }
00220
00221 void addDependency(Object* obj) { dependency.push_back(obj); }
00228 int cutDependencies();
00229 int computeLevel();
00230
00235 virtual void calcSize(int j) {}
00236
00240 virtual double computeKineticEnergy() { return 0.5*u.T()*M[0]*u; }
00241
00245 virtual double computePotentialEnergy() { return 0; }
00246
00250 virtual void setUpInverseKinetics() {}
00251
00252
00253
00254 void setqSize(int qSize_) { qSize = qSize_; }
00255 void setuSize(int uSize_, int i=0) { uSize[i] = uSize_; }
00256 int getzSize() const { return qSize + uSize[0]; }
00257
00258 virtual void sethInd(int hInd_, int i=0);
00259 int gethInd(int i=0) { return hInd[i]; }
00260
00261 const fmatvec::Vec& geth(int i=0) const { return h[i]; };
00262 fmatvec::Vec& geth(int i=0) { return h[i]; };
00263 const fmatvec::Vec& getr(int i=0) const { return r[i]; };
00264 fmatvec::Vec& getr(int i=0) { return r[i]; };
00265 const fmatvec::SymMat& getM(int i=0) const { return M[i]; };
00266 fmatvec::SymMat& getM(int i=0) { return M[i]; };
00267 const fmatvec::Mat& getT() const { return T; };
00268 fmatvec::Mat& getT() { return T; };
00269 const fmatvec::SymMat& getLLM(int i=0) const { return LLM[i]; };
00270 fmatvec::SymMat& getLLM(int i=0) { return LLM[i]; };
00271
00272 fmatvec::Vec& getq() { return q; };
00273 fmatvec::Vec& getu() { return u; };
00274
00275 const fmatvec::Vec& getq0() const { return q0; };
00276 const fmatvec::Vec& getu0() const { return u0; };
00277 fmatvec::Vec& getq0() { return q0; };
00278 fmatvec::Vec& getu0() { return u0; };
00279
00280 const fmatvec::Vec& getqd() const { return qd; };
00281 const fmatvec::Vec& getud(int i=0) const { return ud[i]; };
00282 fmatvec::Vec& getqd() { return qd; };
00283 fmatvec::Vec& getud(int i=0) { return ud[i]; };
00284
00285 void setq(const fmatvec::Vec &q_) { q = q_; }
00286 void setu(const fmatvec::Vec &u_) { u = u_; }
00287
00288 void setInitialGeneralizedPosition(const fmatvec::Vec &q0_) { q0 = q0_; }
00289 void setInitialGeneralizedVelocity(const fmatvec::Vec &u0_) { u0 = u0_; }
00290 void setInitialGeneralizedPosition(double q0_) { q0 = fmatvec::Vec(1,fmatvec::INIT,q0_); }
00291 void setInitialGeneralizedVelocity(double u0_) { u0 = fmatvec::Vec(1,fmatvec::INIT,u0_); }
00292
00293
00294
00295 virtual void initializeUsingXML(MBXMLUtils::TiXmlElement *element);
00296 virtual MBXMLUtils::TiXmlElement* writeXMLFile(MBXMLUtils::TiXmlNode *element);
00297
00298 virtual Element* getByPathSearch(std::string path);
00299
00300 protected:
00304 int qSize;
00305
00309 int uSize[2];
00310
00314 int hSize[2];
00315
00319 int qInd, uInd[2], hInd[2];
00320
00324 fmatvec::Vec q, u, uall;
00325
00329 fmatvec::Vec q0, u0;
00330
00334 fmatvec::Vec qd, ud[2], udall[2];
00335
00339 fmatvec::Vec h[2], r[2];
00340
00341 fmatvec::Mat W[2], V[2];
00342
00346 fmatvec::Mat dhdq;
00347 fmatvec::SqrMat dhdu;
00348 fmatvec::Vec dhdt;
00349
00353 fmatvec::Mat T;
00354
00358 fmatvec::SymMat M[2];
00359
00363 fmatvec::SymMat LLM[2];
00364
00368
00369
00373 std::vector<Object*> dependency;
00374 };
00375
00376 }
00377
00378 #endif
00379