mbsimhydraulics  3.2.0
hnode.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_H_
00021 #define  _HNODE_H_
00022 
00023 #include "mbsim/link.h"
00024 #include "mbsim/utils/function.h"
00025 
00026 #ifdef HAVE_OPENMBVCPPINTERFACE
00027 namespace OpenMBV {
00028   class Group;
00029   class Sphere;
00030 }
00031 #endif
00032 
00033 namespace MBSim {
00034   class GeneralizedForceLaw;
00035   class GeneralizedImpactLaw;
00036 }
00037 
00038 namespace MBSimControl {
00039   class Signal;
00040 }
00041 
00042 namespace MBSimHydraulics {
00043 
00044   class HLine;
00045   class HydFluid;
00046   class OilBulkModulus;
00047 
00048   struct connectedLinesStruct {
00049     HLine * line;
00050     fmatvec::Vec sign;
00051     bool inflow;
00052   };
00053 
00055   class HNode : public MBSim::Link {
00056     public:
00057       HNode(const std::string &name);
00058       ~HNode() {};
00059       virtual std::string getType() const { return "HNode"; }
00060 
00061 #ifdef HAVE_OPENMBVCPPINTERFACE
00062       virtual void enableOpenMBV(double size=1, double pMin=0e5, double pMax=10e5, fmatvec::Vec WrON=fmatvec::Vec(3));
00063 #endif
00064 
00065       void addInFlow(HLine * in);
00066       void addOutFlow(HLine * out);
00067 
00068       void calcgdSize(int j) {gdSize=1; }
00069 
00070       void init(MBSim::InitStage stage);
00071 
00072       virtual void updateWRef(const fmatvec::Mat& WRef, int i=0);
00073       virtual void updateVRef(const fmatvec::Mat& VRef, int i=0);
00074       virtual void updatehRef(const fmatvec::Vec& hRef, int i=0);
00075       virtual void updaterRef(const fmatvec::Vec& rRef, int i=0);
00076       virtual void updatedhdqRef(const fmatvec::Mat& dhdqRef, int i=0);
00077       virtual void updatedhduRef(const fmatvec::SqrMat& dhduRef, int i=0);
00078       virtual void updatedhdtRef(const fmatvec::Vec& dhdtRef, int i=0);
00079 
00080       void updateh(double t, int j=0);
00081       void updatedhdz(double t);
00082       virtual void updater(double t, int j);
00083       virtual void updateg(double t) {};
00084       virtual void updategd(double t);
00085       virtual bool isActive() const {return false; }
00086       virtual bool gActiveChanged() {return false; }
00087 
00088 
00089       void plot(double t, double dt);
00090 
00091       void initializeUsingXML(MBXMLUtils::TiXmlElement *element);
00092 
00093     protected:
00094       std::vector<connectedLinesStruct> connectedLines;
00095       std::vector<connectedLinesStruct> connected0DOFLines;
00096       std::vector<std::string> refInflowString;
00097       std::vector<std::string> refOutflowString;
00098       double QHyd;
00099       unsigned int nLines;
00100 #ifdef HAVE_OPENMBVCPPINTERFACE
00101       OpenMBV::Group * openMBVGrp;
00102       OpenMBV::Sphere * openMBVSphere;
00103       fmatvec::Vec WrON;
00104 #endif
00105   };
00106 
00107 
00109   class ConstrainedNode : public HNode {
00110     public:
00111       ConstrainedNode(const std::string &name="") : HNode(name), pFun(NULL) {}
00112       virtual std::string getType() const { return "ConstrainedNode"; }
00113 
00114       void setpFunction(MBSim::Function1<double,double> * pFun_) {pFun=pFun_; }
00115 
00116       void updateg(double t);
00117       void init(MBSim::InitStage stage);
00118       void initializeUsingXML(MBXMLUtils::TiXmlElement *element);
00119       virtual bool isSingleValued() const {return true;}
00120 
00121     private:
00122       MBSim::Function1<double,double> * pFun;
00123   };
00124 
00125 
00127   class EnvironmentNode : public HNode {
00128     public:
00129       EnvironmentNode(const std::string &name="") : HNode(name) {}
00130       virtual std::string getType() const { return "EnvironmentNode"; }
00131 
00132       void init(MBSim::InitStage stage);
00133 
00134       virtual bool isSingleValued() const {return true;}
00135   };
00136 
00137 
00139   class ElasticNode : public HNode {
00140     public:
00141       ElasticNode(const std::string &name="") : HNode(name), V(0), E(0), fracAir(0), p0(0), bulkModulus(NULL) {}
00142       ~ElasticNode();
00143       virtual std::string getType() const { return "ElasticNode"; }
00144 
00145       void setVolume(double V_) {V=V_; }
00146       void setFracAir(double fracAir_) {fracAir=fracAir_; }
00147       void setp0(double p0_) {p0=p0_; }
00148 
00149       void calcxSize() {xSize=1; }
00150 
00151       void init(MBSim::InitStage stage);
00152       void initializeUsingXML(MBXMLUtils::TiXmlElement *element);
00153 
00154       void updatexRef(const fmatvec::Vec &xParent);
00155 
00156       void updatexd(double t);
00157       void updatedx(double t, double dt);
00158 
00159       void plot(double t, double dt);
00160 
00161       virtual bool isSingleValued() const {return true;}
00162 
00163     private:
00164       double V, E;
00165       double fracAir;
00166       double p0;
00167       OilBulkModulus * bulkModulus;
00168   };
00169 
00170 
00172   class RigidNode : public HNode {
00173     public:
00174       RigidNode(const std::string &name="");
00175       ~RigidNode();
00176       virtual std::string getType() const { return "RigidNode"; }
00177 
00178       bool isSetValued() const {return true; }
00179       virtual bool isActive() const {return true; }
00180 
00181       void calclaSize(int j) {laSize=1; }
00182       //void calclaSizeForActiveg() {laSize=0; }
00183       void calcrFactorSize(int j) {rFactorSize=1; }
00184 
00185       void updategd(double t);
00186       void updateW(double t, int j=0);
00187 
00188       void updaterFactors();
00189       void solveImpactsFixpointSingle(double dt);
00190       void solveConstraintsFixpointSingle();
00191       void solveImpactsGaussSeidel(double dt);
00192       void solveConstraintsGaussSeidel();
00193       void solveImpactsRootFinding(double dt);
00194       void solveConstraintsRootFinding();
00195       void jacobianImpacts();
00196       void jacobianConstraints();
00197       void checkImpactsForTermination(double dt);
00198       void checkConstraintsForTermination();
00199     private:
00200       double gdn, gdd;
00201       MBSim::GeneralizedForceLaw * gfl;
00202       MBSim::GeneralizedImpactLaw * gil;
00203   };
00204 
00205 
00207   class RigidCavitationNode : public HNode {
00208     public:
00209       RigidCavitationNode(const std::string &name="");
00210       ~RigidCavitationNode();
00211       virtual std::string getType() const { return "RigidCavitationNode"; }
00212 
00213       void setCavitationPressure(double pCav_) {pCav=pCav_; }
00214 
00215       bool isSetValued() const {return true; }
00216       bool hasSmoothPart() const {return true; }
00217       virtual bool isActive() const {return active; }
00218 
00219       void calcxSize() {xSize=1; }
00220       void calcgSize(int j) {gSize=1; }
00221       //void calcgSizeActive() {gSize=0; }
00222       void calclaSize(int j) {laSize=1; }
00223       //void calclaSizeForActiveg() {laSize=0; }
00224       void calcrFactorSize(int j) {rFactorSize=1; }
00225       void calcsvSize() {svSize=1; }
00226 
00227       void init(MBSim::InitStage stage);
00228       void initializeUsingXML(MBXMLUtils::TiXmlElement *element);
00229       void plot(double t, double dt);
00230 
00231       void checkActive(int j);
00232       //void checkActivegdn();
00233       bool gActiveChanged();
00234 
00235       void updateg(double t);
00236       void updateh(double t, int j=0);
00237       void updateStopVector(double t);
00238       void updateW(double t, int j=0);
00239       void updatexd(double t);
00240       void updatedx(double t, double dt);
00241       void checkRoot();
00242 
00243       void updaterFactors();
00244       void solveImpactsFixpointSingle(double dt);
00245       void solveConstraintsFixpointSingle();
00246       void solveImpactsGaussSeidel(double dt);
00247       void solveConstraintsGaussSeidel();
00248       void solveImpactsRootFinding(double dt);
00249       void solveConstraintsRootFinding();
00250       void jacobianImpacts();
00251       void jacobianConstraints();
00252       void checkImpactsForTermination(double dt);
00253       void checkConstraintsForTermination();
00254     protected:
00255       double pCav;
00256     private:
00257       bool active, active0;
00258       double gdn, gdd;
00259       MBSim::GeneralizedForceLaw * gfl;
00260       MBSim::GeneralizedImpactLaw * gil;
00261   };
00262 
00263 
00265   class PressurePump : public HNode {
00266     public:
00267       PressurePump(const std::string &name="") : HNode(name), pSignal(NULL), pSignalString("") {}
00268       virtual std::string getType() const { return "PressurePump"; }
00269 
00270       void setpSignal(MBSimControl::Signal * pSignal_) {pSignal=pSignal_; }
00271 
00272       void updateg(double t);
00273       void init(MBSim::InitStage stage);
00274       void initializeUsingXML(MBXMLUtils::TiXmlElement *element);
00275 
00276     private:
00277       MBSimControl::Signal * pSignal;
00278       std::string pSignalString;
00279   };
00280 
00281 }
00282 
00283 #endif   /* ----- #ifndef _HYDNODE_H_  ----- */
00284