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