mbsimhydraulics  3.0.0
hline.h
1 /* Copyright (C) 2004-2009 MBSim Development Team
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16  *
17  * Contact: markus.ms.schneider@gmail.com
18  */
19 
20 #ifndef _HLINE_H_
21 #define _HLINE_H_
22 
23 #include "mbsim/object.h"
24 #include "mbsim/utils/function.h"
25 
26 namespace MBSim {
27  class Frame;
28 }
29 
30 namespace MBSimControl {
31  class Signal;
32 }
33 
34 namespace MBSimHydraulics {
35 
36  class HNode;
37  class HydlinePressureloss;
38  class PressureLoss;
39 
41  class HLine : public MBSim::Object {
42  public:
43  HLine(const std::string &name) : MBSim::Object(name), nFrom(NULL), nTo(NULL), nFromRelative(false), nToRelative(false), direction(fmatvec::Vec(3, fmatvec::INIT, 0)), Mlocal(0), Jacobian(0,0), frameOfReference(NULL), saved_frameOfReference("") {};
44  virtual std::string getType() const { return "HLine"; }
45 
46  /* INHERITED INTERFACE OF OBJECTINTERFACE */
47  virtual void updateStateDependentVariables(double t) {};
48  virtual void updateJacobians(double t, int j=0) {};
49  virtual void updateInverseKineticsJacobians(double t) {};
50 #ifdef HAVE_OPENMBVCPPINTERFACE
51  virtual OpenMBV::Group* getOpenMBVGrp() { return 0; }
52 #endif
53  /***************************************************/
54 
55  virtual void setFrameOfReference(MBSim::Frame *frame);
56  void setFromNode(HNode * nFrom_) {nFrom=nFrom_; }
57  void setToNode(HNode * nTo_) {nTo=nTo_; }
58  void setDirection(fmatvec::Vec dir) {direction=((nrm2(dir)>0)?dir/nrm2(dir):fmatvec::Vec(3, fmatvec::INIT, 0)); }
59  HNode * getFromNode() { return nFrom; }
60  HNode * getToNode() {return nTo; }
61  void setOutflowRelative(bool rel=true) {nToRelative=rel; }
62  void setInflowRelative(bool rel=true) {nFromRelative=rel; }
63 
64  virtual fmatvec::Vec getQIn() = 0;
65  virtual fmatvec::Vec getQOut() = 0;
66  virtual fmatvec::Vec getInflowFactor() = 0;
67  virtual fmatvec::Vec getOutflowFactor() = 0;
68  virtual fmatvec::Mat& getJacobian() {return Jacobian; }
69 
70  void updateM(double t, int j=0) {M[j]=Mlocal; }
71 
72  void init(MBSim::InitStage stage);
73  void initializeUsingXML(TiXmlElement *element);
74 
75  protected:
76  HNode * nFrom;
77  HNode * nTo;
78  bool nFromRelative, nToRelative;
79  fmatvec::Vec direction;
80  fmatvec::SymMat Mlocal;
81  fmatvec::Mat Jacobian;
82  MBSim::Frame * frameOfReference;
83  private:
84  std::string saved_frameOfReference;
85  };
86 
88  class RigidHLine : public HLine {
89  public:
90  RigidHLine(const std::string &name) : HLine(name), pressureLossGravity(0), length(0), Q(fmatvec::Vec(1)) {}
91  virtual std::string getType() const { return "RigidHLine"; }
92 
93  void setLength(double length_) {length=length_; }
94  double getLength() const {return length; }
95  void addInflowDependencyOnOutflow(RigidHLine* line);
96  void addInflowDependencyOnInflow(RigidHLine* line);
97 
98  virtual fmatvec::Vec getQIn() {return Q; }
99  virtual fmatvec::Vec getQOut() {return -Q; }
100  virtual fmatvec::Vec getInflowFactor() {return fmatvec::Vec(1, fmatvec::INIT, -1.); }
101  virtual fmatvec::Vec getOutflowFactor() {return fmatvec::Vec(1, fmatvec::INIT, 1.); }
102  void calcqSize() {qSize=0; }
103  void calcuSize(int j=0) {uSize[j]=(dependency.size()?0:1); }
104  fmatvec::Mat calculateJacobian(std::vector<RigidHLine*> dep_check);
105 
106  virtual void updateStateDependentVariables(double t);
107  void updateh(double t, int j=0);
108  void updateM(double t, int j=0);
109 
110  void initializeUsingXML(TiXmlElement *element);
111  void init(MBSim::InitStage stage);
112  void plot(double t, double dt);
113 
114  protected:
115  double pressureLossGravity;
116  double length;
117  fmatvec::Vec Q;
118  std::vector<RigidHLine*> dependencyOnOutflow, dependencyOnInflow;
119  std::vector<std::string> refDependencyOnOutflowString, refDependencyOnInflowString;
120  };
121 
123  class ConstrainedLine : public HLine {
124  public:
125  ConstrainedLine(const std::string &name) : HLine(name), QFun(NULL), Q(1) {}
126  virtual std::string getType() const { return "ConstrainedLine"; }
127 
128  void setQFunction(MBSim::Function1<double,double> * QFun_) {QFun=QFun_; }
129 
130  virtual fmatvec::Vec getQIn() {return Q; }
131  virtual fmatvec::Vec getQOut() {return -Q; }
132  virtual fmatvec::Vec getInflowFactor() {return fmatvec::Vec(1, fmatvec::INIT, -1.); }
133  virtual fmatvec::Vec getOutflowFactor() {return fmatvec::Vec(1, fmatvec::INIT, 1.); }
134  void calcqSize() {qSize=0; }
135  void calcuSize(int j) {uSize[j]=0; }
136 
137  virtual void updateStateDependentVariables(double t);
138  void updateh(double t, int j=0) {};
139 
140  void initializeUsingXML(TiXmlElement *element);
141  void init(MBSim::InitStage stage);
142 
143  private:
144  MBSim::Function1<double,double> * QFun;
145  fmatvec::Vec Q;
146  };
147 
149  class FluidPump : public HLine {
150  public:
151  FluidPump(const std::string &name) : HLine(name), QSignal(NULL), QSignalString(""), Q(1) {}
152  virtual std::string getType() const { return "FluidPump"; }
153 
154  void setQSignal(MBSimControl::Signal * QSignal_) {QSignal=QSignal_; }
155 
156  virtual fmatvec::Vec getQIn();
157  virtual fmatvec::Vec getQOut();
158  virtual fmatvec::Vec getInflowFactor() {return fmatvec::Vec(1, fmatvec::INIT, -1.); }
159  virtual fmatvec::Vec getOutflowFactor() {return fmatvec::Vec(1, fmatvec::INIT, 1.); }
160  void calcqSize() {qSize=0; }
161  void calcuSize(int j) {uSize[j]=0; }
162 
163  void updateh(double t, int j=0) {};
164 
165  void initializeUsingXML(TiXmlElement *element);
166  void init(MBSim::InitStage stage);
167 
168  private:
169  MBSimControl::Signal * QSignal;
170  std::string QSignalString;
171  fmatvec::Vec Q;
172  };
173 
175  class StatelessOrifice : public HLine {
176  public:
177  StatelessOrifice(const std::string &name) : HLine(name), inflowSignal(NULL), outflowSignal(NULL), openingSignal(NULL), inflowSignalString(""), outflowSignalString(""), openingSignalString(""), diameter(0), alpha(0.), calcAreaModus(0) {}
178  virtual std::string getType() const { return "StatelessOrifice"; }
179 
180  void setInflowSignal(MBSimControl::Signal * inflowSignal_) {inflowSignal=inflowSignal_; }
181  void setOutflowSignal(MBSimControl::Signal * outflowSignal_) {outflowSignal=outflowSignal_; }
182  void setDiameter(double diameter_) {diameter=diameter_; }
183  void setOpeningSignal(MBSimControl::Signal * openingSignal_) {openingSignal=openingSignal_; }
184  void setAlpha(double alpha_) {alpha=alpha_; }
185  void setCalcAreaModus(int calcAreaModus_) {calcAreaModus=calcAreaModus_; }
186 
187  virtual fmatvec::Vec getQIn();
188  virtual fmatvec::Vec getQOut();
189  virtual fmatvec::Vec getInflowFactor() {return fmatvec::Vec(1, fmatvec::INIT, -1.); }
190  virtual fmatvec::Vec getOutflowFactor() {return fmatvec::Vec(1, fmatvec::INIT, 1.); }
191  void calcqSize() {qSize=0; }
192  void calcuSize(int j) {uSize[j]=0; }
193 
194  void updateh(double t, int j=0) {};
195 
196  void initializeUsingXML(TiXmlElement *element);
197  void init(MBSim::InitStage stage);
198  void plot(double t, double dt);
199 
200  private:
201  MBSimControl::Signal *inflowSignal, *outflowSignal, *openingSignal;
202  std::string inflowSignalString, outflowSignalString, openingSignalString;
203  double diameter, alpha;
204  int calcAreaModus;
205  fmatvec::Vec calculateQ();
206 
207  double pIn, pOut, dp, sign, opening, area, sqrt_dp;
208  };
209 
210 }
211 
212 #endif /* ----- #ifndef _HLINE_H_ ----- */
213