mbsimhydraulics  3.2.0
hline.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  _HLINE_H_
00021 #define  _HLINE_H_
00022 
00023 #include "mbsim/object.h"
00024 #include "mbsim/utils/function.h"
00025 
00026 namespace MBSim {
00027   class Frame;
00028 }
00029 
00030 namespace MBSimControl {
00031   class Signal;
00032 }
00033 
00034 namespace MBSimHydraulics {
00035 
00036   class HNode;
00037   class HydlinePressureloss;
00038   class PressureLoss;
00039 
00041   class HLine : public MBSim::Object {
00042     public:
00043       HLine(const std::string &name) : MBSim::Object(name), nFrom(NULL), nTo(NULL), nFromRelative(false), nToRelative(false), direction(fmatvec::Vec(3, fmatvec::INIT, 0)), Mlocal(), Jacobian(), frameOfReference(NULL), saved_frameOfReference("") {};
00044       virtual std::string getType() const { return "HLine"; }
00045 
00046       /* INHERITED INTERFACE OF OBJECTINTERFACE */
00047       virtual void updateStateDependentVariables(double t) {};
00048       virtual void updateJacobians(double t, int j=0) {};
00049       virtual void updateInverseKineticsJacobians(double t) {};
00050 #ifdef HAVE_OPENMBVCPPINTERFACE
00051       virtual OpenMBV::Group* getOpenMBVGrp() { return 0; }
00052 #endif
00053       /***************************************************/
00054 
00055       virtual void setFrameOfReference(MBSim::Frame *frame);
00056       void setFromNode(HNode * nFrom_) {nFrom=nFrom_; }
00057       void setToNode(HNode * nTo_) {nTo=nTo_; }
00058       void setDirection(fmatvec::Vec dir) {direction=((nrm2(dir)>0)?dir/nrm2(dir):fmatvec::Vec(3, fmatvec::INIT, 0)); }
00059       HNode * getFromNode() { return nFrom; }
00060       HNode * getToNode() {return nTo; }
00061       void setOutflowRelative(bool rel=true) {nToRelative=rel; }
00062       void setInflowRelative(bool rel=true) {nFromRelative=rel; }
00063 
00064       virtual fmatvec::Vec getQIn() = 0;
00065       virtual fmatvec::Vec getQOut() = 0;
00066       virtual fmatvec::Vec getInflowFactor() = 0;
00067       virtual fmatvec::Vec getOutflowFactor() = 0;
00068       virtual fmatvec::Mat& getJacobian() {return Jacobian; }
00069       
00070       void updateM(double t, int j=0) {M[j]=Mlocal; }
00071 
00072       void init(MBSim::InitStage stage);
00073       void initializeUsingXML(MBXMLUtils::TiXmlElement *element);
00074       
00075     protected:
00076       HNode * nFrom;
00077       HNode * nTo;
00078       bool nFromRelative, nToRelative;
00079       fmatvec::Vec direction;
00080       fmatvec::SymMat Mlocal;
00081       fmatvec::Mat Jacobian;
00082       MBSim::Frame * frameOfReference;
00083     private:
00084       std::string saved_frameOfReference;
00085   };
00086 
00088   class RigidHLine : public HLine {
00089     public:
00090       RigidHLine(const std::string &name) : HLine(name), pressureLossGravity(0), length(0), Q(fmatvec::Vec(1)) {}
00091       virtual std::string getType() const { return "RigidHLine"; }
00092       
00093       void setLength(double length_) {length=length_; }
00094       double getLength() const {return length; }
00095       void addInflowDependencyOnOutflow(RigidHLine* line);
00096       void addInflowDependencyOnInflow(RigidHLine* line);
00097 
00098       virtual fmatvec::Vec getQIn() {return Q; }
00099       virtual fmatvec::Vec getQOut() {return -Q; }
00100       virtual fmatvec::Vec getInflowFactor() {return fmatvec::Vec(1, fmatvec::INIT, -1.); }
00101       virtual fmatvec::Vec getOutflowFactor() {return fmatvec::Vec(1, fmatvec::INIT, 1.); }
00102       void calcqSize() {qSize=0; }
00103       void calcuSize(int j=0) {uSize[j]=(dependency.size()?0:1); }
00104       fmatvec::Mat calculateJacobian(std::vector<RigidHLine*> dep_check);
00105       
00106       virtual void updateStateDependentVariables(double t);
00107       void updateh(double t, int j=0);
00108       void updateM(double t, int j=0);
00109       
00110       void initializeUsingXML(MBXMLUtils::TiXmlElement *element);
00111       void init(MBSim::InitStage stage);
00112       void plot(double t, double dt);
00113       
00114     protected:
00115       double pressureLossGravity;
00116       double length;
00117       fmatvec::Vec Q;
00118       std::vector<RigidHLine*> dependencyOnOutflow, dependencyOnInflow;
00119       std::vector<std::string> refDependencyOnOutflowString, refDependencyOnInflowString;
00120   };
00121 
00123   class ConstrainedLine : public HLine {
00124     public:
00125       ConstrainedLine(const std::string &name="") : HLine(name), QFun(NULL), Q(1) {}
00126       virtual std::string getType() const { return "ConstrainedLine"; }
00127       
00128       void setQFunction(MBSim::Function1<double,double> * QFun_) {QFun=QFun_; }
00129 
00130       virtual fmatvec::Vec getQIn() {return Q; }
00131       virtual fmatvec::Vec getQOut() {return -Q; }
00132       virtual fmatvec::Vec getInflowFactor() {return fmatvec::Vec(1, fmatvec::INIT, -1.); }
00133       virtual fmatvec::Vec getOutflowFactor() {return fmatvec::Vec(1, fmatvec::INIT, 1.); }
00134       void calcqSize() {qSize=0; }
00135       void calcuSize(int j) {uSize[j]=0; }
00136       
00137       virtual void updateStateDependentVariables(double t);
00138       void updateh(double t, int j=0) {};
00139       
00140       void initializeUsingXML(MBXMLUtils::TiXmlElement *element);
00141       void init(MBSim::InitStage stage);
00142       
00143     private:
00144       MBSim::Function1<double,double> * QFun;
00145       fmatvec::Vec Q;
00146   };
00147 
00149   class FluidPump : public HLine {
00150     public:
00151       FluidPump(const std::string &name="") : HLine(name), QSignal(NULL), QSignalString(""), Q(1) {}
00152       virtual std::string getType() const { return "FluidPump"; }
00153       
00154       void setQSignal(MBSimControl::Signal * QSignal_) {QSignal=QSignal_; }
00155 
00156       virtual fmatvec::Vec getQIn();
00157       virtual fmatvec::Vec getQOut();
00158       virtual fmatvec::Vec getInflowFactor() {return fmatvec::Vec(1, fmatvec::INIT, -1.); }
00159       virtual fmatvec::Vec getOutflowFactor() {return fmatvec::Vec(1, fmatvec::INIT, 1.); }
00160       void calcqSize() {qSize=0; }
00161       void calcuSize(int j) {uSize[j]=0; }
00162       
00163       void updateh(double t, int j=0) {};
00164       
00165       void initializeUsingXML(MBXMLUtils::TiXmlElement *element);
00166       void init(MBSim::InitStage stage);
00167       
00168     private:
00169       MBSimControl::Signal * QSignal;
00170       std::string QSignalString;
00171       fmatvec::Vec Q;
00172   };
00173 
00175   class StatelessOrifice : public HLine {
00176     public:
00177       StatelessOrifice(const std::string &name="") : HLine(name), inflowSignal(NULL), outflowSignal(NULL), openingSignal(NULL), inflowSignalString(""), outflowSignalString(""), openingSignalString(""), diameter(0), alpha(0.), calcAreaModus(0) {}
00178       virtual std::string getType() const { return "StatelessOrifice"; }
00179       
00180       void setInflowSignal(MBSimControl::Signal * inflowSignal_) {inflowSignal=inflowSignal_; }
00181       void setOutflowSignal(MBSimControl::Signal * outflowSignal_) {outflowSignal=outflowSignal_; }
00182       void setDiameter(double diameter_) {diameter=diameter_; }
00183       void setOpeningSignal(MBSimControl::Signal * openingSignal_) {openingSignal=openingSignal_; }
00184       void setAlpha(double alpha_) {alpha=alpha_; }
00185       void setCalcAreaModus(int calcAreaModus_) {calcAreaModus=calcAreaModus_; }
00186 
00187       virtual fmatvec::Vec getQIn();
00188       virtual fmatvec::Vec getQOut();
00189       virtual fmatvec::Vec getInflowFactor() {return fmatvec::Vec(1, fmatvec::INIT, -1.); }
00190       virtual fmatvec::Vec getOutflowFactor() {return fmatvec::Vec(1, fmatvec::INIT, 1.); }
00191       void calcqSize() {qSize=0; }
00192       void calcuSize(int j) {uSize[j]=0; }
00193       
00194       void updateh(double t, int j=0) {};
00195       
00196       void initializeUsingXML(MBXMLUtils::TiXmlElement *element);
00197       void init(MBSim::InitStage stage);
00198       void plot(double t, double dt);
00199       
00200     private:
00201       MBSimControl::Signal *inflowSignal, *outflowSignal, *openingSignal;
00202       std::string inflowSignalString, outflowSignalString, openingSignalString;
00203       double diameter, alpha;
00204       int calcAreaModus;
00205       fmatvec::Vec calculateQ();
00206 
00207       double pIn, pOut, dp, sign, opening, area, sqrt_dp;
00208   };
00209 
00210 }
00211 
00212 #endif   /* ----- #ifndef _HLINE_H_  ----- */
00213