mbsimhydraulics  4.0.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/functions/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(InitStage stage);
00073       void initializeUsingXML(xercesc::DOMElement *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(xercesc::DOMElement *element);
00111       void init(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::Function<double(double)> * QFun_) {
00129         QFun=QFun_;
00130         QFun->setParent(this);
00131         QFun->setName("Q");
00132       }
00133 
00134       virtual fmatvec::Vec getQIn() {return Q; }
00135       virtual fmatvec::Vec getQOut() {return -Q; }
00136       virtual fmatvec::Vec getInflowFactor() {return fmatvec::Vec(1, fmatvec::INIT, -1.); }
00137       virtual fmatvec::Vec getOutflowFactor() {return fmatvec::Vec(1, fmatvec::INIT, 1.); }
00138       void calcqSize() {qSize=0; }
00139       void calcuSize(int j) {uSize[j]=0; }
00140       
00141       virtual void updateStateDependentVariables(double t);
00142       void updateh(double t, int j=0) {};
00143       
00144       void initializeUsingXML(xercesc::DOMElement *element);
00145       void init(InitStage stage);
00146       
00147     private:
00148       MBSim::Function<double(double)> * QFun;
00149       fmatvec::Vec Q;
00150   };
00151 
00153   class FluidPump : public HLine {
00154     public:
00155       FluidPump(const std::string &name="") : HLine(name), QSignal(NULL), QSignalString(""), Q(1) {}
00156       virtual std::string getType() const { return "FluidPump"; }
00157       
00158       void setQSignal(MBSimControl::Signal * QSignal_) {QSignal=QSignal_; }
00159 
00160       virtual fmatvec::Vec getQIn();
00161       virtual fmatvec::Vec getQOut();
00162       virtual fmatvec::Vec getInflowFactor() {return fmatvec::Vec(1, fmatvec::INIT, -1.); }
00163       virtual fmatvec::Vec getOutflowFactor() {return fmatvec::Vec(1, fmatvec::INIT, 1.); }
00164       void calcqSize() {qSize=0; }
00165       void calcuSize(int j) {uSize[j]=0; }
00166       
00167       void updateh(double t, int j=0) {};
00168       
00169       void initializeUsingXML(xercesc::DOMElement *element);
00170       void init(InitStage stage);
00171       
00172     private:
00173       MBSimControl::Signal * QSignal;
00174       std::string QSignalString;
00175       fmatvec::Vec Q;
00176   };
00177 
00179   class StatelessOrifice : public HLine {
00180     public:
00181       StatelessOrifice(const std::string &name="") : HLine(name), inflowSignal(NULL), outflowSignal(NULL), openingSignal(NULL), inflowSignalString(""), outflowSignalString(""), openingSignalString(""), diameter(0), alpha(0.), calcAreaModus(0) {}
00182       virtual std::string getType() const { return "StatelessOrifice"; }
00183       
00184       void setInflowSignal(MBSimControl::Signal * inflowSignal_) {inflowSignal=inflowSignal_; }
00185       void setOutflowSignal(MBSimControl::Signal * outflowSignal_) {outflowSignal=outflowSignal_; }
00186       void setDiameter(double diameter_) {diameter=diameter_; }
00187       void setOpeningSignal(MBSimControl::Signal * openingSignal_) {openingSignal=openingSignal_; }
00188       void setAlpha(double alpha_) {alpha=alpha_; }
00189       void setCalcAreaModus(int calcAreaModus_) {calcAreaModus=calcAreaModus_; }
00190 
00191       virtual fmatvec::Vec getQIn();
00192       virtual fmatvec::Vec getQOut();
00193       virtual fmatvec::Vec getInflowFactor() {return fmatvec::Vec(1, fmatvec::INIT, -1.); }
00194       virtual fmatvec::Vec getOutflowFactor() {return fmatvec::Vec(1, fmatvec::INIT, 1.); }
00195       void calcqSize() {qSize=0; }
00196       void calcuSize(int j) {uSize[j]=0; }
00197       
00198       void updateh(double t, int j=0) {};
00199       
00200       void initializeUsingXML(xercesc::DOMElement *element);
00201       void init(InitStage stage);
00202       void plot(double t, double dt);
00203       
00204     private:
00205       MBSimControl::Signal *inflowSignal, *outflowSignal, *openingSignal;
00206       std::string inflowSignalString, outflowSignalString, openingSignalString;
00207       double diameter, alpha;
00208       int calcAreaModus;
00209       fmatvec::Vec calculateQ();
00210 
00211       double pIn, pOut, dp, sign, opening, area, sqrt_dp;
00212   };
00213 
00214 }
00215 
00216 #endif   /* ----- #ifndef _HLINE_H_  ----- */
00217