mbsimhydraulics  4.0.0
hnode_mec.h
00001 /* Copyright (C) 2004-2009 MBSim Development Team
00002  *
00003  * This library is free software; you can redistribute it and/or 
00004  * modify it under the terms of the GNU Lesser General Public 
00005  * License as published by the Free Software Foundation; either 
00006  * version 2.1 of the License, or (at your option) any later version. 
00007  *  
00008  * This library is distributed in the hope that it will be useful, 
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
00011  * Lesser General Public License for more details. 
00012  *  
00013  * You should have received a copy of the GNU Lesser General Public 
00014  * License along with this library; if not, write to the Free Software 
00015  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
00016  *
00017  * Contact: markus.ms.schneider@gmail.com
00018  */
00019 
00020 #ifndef  _HNODE_MEC_H_
00021 #define  _HNODE_MEC_H_
00022 
00023 #include "hnode.h"
00024 #include <mbsim/functions/function.h>
00025 
00026 namespace MBSim {
00027   class Frame;
00028   class GeneralizedForceLaw;
00029   class GeneralizedImpactLaw;
00030 }
00031 
00032 namespace MBSimHydraulics {
00033 
00034   class HydFluid;
00035   class OilBulkModulus;
00036 
00037   struct connectedTransFrameStruct {
00038     MBSim::Frame * frame;
00039     fmatvec::Vec normal;
00040     double area;
00041     bool considerVolumeChange;
00042   };
00043 
00044   struct connectedRotFrameStruct {
00045     MBSim::Frame * frame;
00046     fmatvec::Vec normal;
00047     MBSim::Frame * fref;
00048     double area;
00049     bool considerVolumeChange;
00050   };
00051 
00053   class HNodeMec : public HNode {
00054     public:
00055       HNodeMec(const std::string &name);
00056       ~HNodeMec();
00057       virtual std::string getType() const { return "HNodeMec"; }
00058 
00059 #ifdef HAVE_OPENMBVCPPINTERFACE
00060       BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBVArrows, tag, (optional (size,(double),1))) { 
00061         openMBVArrowSize=(size>.0)?size:.0;
00062       }
00063 #endif
00064 
00065       void setInitialVolume(double V0_) {V0=V0_; }
00066       unsigned int addTransMecArea(MBSim::Frame * f, fmatvec::Vec fN, double area, bool considerVolumeChange=true);
00067       unsigned int addRotMecArea(MBSim::Frame * f, fmatvec::Vec fN, double area, MBSim::Frame * frameOfReference, bool considerVolumeChange=true);
00068       void setTransMecArea(unsigned int i, double area) {connectedTransFrames[i].area=area; }
00069 
00070       void calcxSize() {xSize=1; }
00071 
00072       void init(InitStage stage);
00073       void initializeUsingXML(xercesc::DOMElement *element);
00074 
00075       virtual void updateWRef(const fmatvec::Mat& Wref, int i=0);
00076       virtual void updateVRef(const fmatvec::Mat& Vref, int i=0);
00077       virtual void updatehRef(const fmatvec::Vec& href, int i=0);
00078       virtual void updatedhdqRef(const fmatvec::Mat& dhdqRef, int i=0);
00079       virtual void updatedhduRef(const fmatvec::SqrMat& dhduRef, int i=0);
00080       virtual void updatedhdtRef(const fmatvec::Vec& dhdtRef, int i=0);
00081       virtual void updaterRef(const fmatvec::Vec& ref, int i=0);
00082 
00083       void updateh(double t, int j=0);
00084       void updatedhdz(double t);
00085       virtual void updater(double t, int j=0);
00086       void updategd(double t);
00087       void updatexd(double t);
00088       void updatedx(double t, double dt);
00089 
00090       void plot(double t, double dt);
00091 
00092     protected:
00093       std::vector<connectedTransFrameStruct> connectedTransFrames;
00094       std::vector<connectedRotFrameStruct> connectedRotFrames;
00095       double QMecTrans, QMecRot, QMec;
00096       double V0;
00097       unsigned int nTrans, nRot;
00098 #ifdef HAVE_OPENMBVCPPINTERFACE
00099       std::vector<boost::shared_ptr<OpenMBV::Arrow> > openMBVArrows;
00100       double openMBVArrowSize;
00101 #endif
00102 
00103     private:
00104       std::vector<std::string> saved_translatorial_frameOfReference, saved_rotatorial_frameOfReference, saved_rotatorial_frameOfRotationCenter;
00105       std::vector<fmatvec::Vec> saved_translatorial_normal, saved_rotatorial_normal;
00106       std::vector<double> saved_translatorial_area, saved_rotatorial_area;
00107       std::vector<bool> saved_translatorial_noVolumeChange, saved_rotatorial_noVolumeChange;
00108   };
00109 
00111   class ConstrainedNodeMec : public HNodeMec {
00112     public:
00113       ConstrainedNodeMec(const std::string &name="") : HNodeMec(name), pFun(NULL) {}
00114       ~ConstrainedNodeMec() { delete pFun; }
00115       virtual std::string getType() const { return "ConstrainedNodeMec"; }
00116 
00117       void setpFunction(MBSim::Function<double(double)> * pFun_) {
00118         pFun=pFun_;
00119         pFun->setParent(this);
00120         pFun->setName("p");
00121       }
00122 
00123       void init(InitStage stage);
00124       void initializeUsingXML(xercesc::DOMElement *element);
00125 
00126       void updateg(double t);
00127 
00128       virtual bool isSingleValued() const {return true;}
00129 
00130     private:
00131       MBSim::Function<double(double)> * pFun;
00132   };
00133 
00134 
00136   class EnvironmentNodeMec : public HNodeMec {
00137     public:
00138       EnvironmentNodeMec(const std::string &name="") : HNodeMec(name) {}
00139       virtual std::string getType() const { return "EnvironmentNodeMec"; }
00140 
00141       void init(InitStage stage);
00142 
00143       virtual bool isSingleValued() const {return true;}
00144   };
00145 
00146 
00148   class ElasticNodeMec : public HNodeMec {
00149     public:
00150       ElasticNodeMec(const std::string &name="") : HNodeMec(name), E(0), fracAir(0), p0(0), bulkModulus(NULL) {}
00151       ~ElasticNodeMec();
00152       virtual std::string getType() const { return "ElasticNode"; }
00153 
00154       void setFracAir(double fracAir_) {fracAir=fracAir_; }
00155       void setp0(double p0_) {p0=p0_; }
00156 
00157       void calcxSize() {xSize=2; }
00158 
00159       void init(InitStage stage);
00160       void initializeUsingXML(xercesc::DOMElement *element);
00161 
00162       void updatexRef(const fmatvec::Vec &xParent);
00163 
00164       void updatexd(double t);
00165       void updatedx(double t, double dt);
00166 
00167       void plot(double t, double dt);
00168 
00169       virtual bool isSingleValued() const {return true;}
00170 
00171 
00172     private:
00173       double E;
00174       double fracAir;
00175       double p0;
00176 
00177       OilBulkModulus * bulkModulus;
00178   };
00179 
00180 
00182   class RigidNodeMec : public HNodeMec {
00183     public:
00184       RigidNodeMec(const std::string &name="");
00185       ~RigidNodeMec();
00186       virtual std::string getType() const { return "RigidNodeMec"; }
00187 
00188       bool isSetValued() const {return true; }
00189       bool isActive() const {return true; }
00190 
00191       void calclaSize(int j) {laSize=1; }
00192       //void calclaSizeForActiveg() {laSize=0; }
00193       void calcrFactorSize(int j) {rFactorSize=1; }
00194 
00195       void init(InitStage stage);
00196 
00197       void updatewbRef(const fmatvec::Vec& wbParent);
00198 
00199       void updategd(double t);
00200       void updateW(double t, int j=0);
00201 
00202       void updaterFactors();
00203       void solveImpactsFixpointSingle(double dt);
00204       void solveConstraintsFixpointSingle();
00205       void solveImpactsGaussSeidel(double dt);
00206       void solveConstraintsGaussSeidel();
00207       void solveImpactsRootFinding(double dt);
00208       void solveConstraintsRootFinding();
00209       void jacobianImpacts();
00210       void jacobianConstraints();
00211       void checkImpactsForTermination(double dt);
00212       void checkConstraintsForTermination();
00213     private:
00214       double gdn, gdd;
00215       MBSim::GeneralizedForceLaw * gfl;
00216       MBSim::GeneralizedImpactLaw * gil;
00217   };
00218 }
00219 
00220 #endif   /* ----- #ifndef _HYDNODE_MEC_H_  ----- */
00221