All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
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/functions/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(), Jacobian(), 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 boost::shared_ptr<OpenMBV::Group> getOpenMBVGrp() { return boost::shared_ptr<OpenMBV::Group>(); }
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(InitStage stage);
73  void initializeUsingXML(xercesc::DOMElement *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(xercesc::DOMElement *element);
111  void init(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::Function<double(double)> * QFun_) {
129  QFun=QFun_;
130  QFun->setParent(this);
131  QFun->setName("Q");
132  }
133 
134  virtual fmatvec::Vec getQIn() {return Q; }
135  virtual fmatvec::Vec getQOut() {return -Q; }
136  virtual fmatvec::Vec getInflowFactor() {return fmatvec::Vec(1, fmatvec::INIT, -1.); }
137  virtual fmatvec::Vec getOutflowFactor() {return fmatvec::Vec(1, fmatvec::INIT, 1.); }
138  void calcqSize() {qSize=0; }
139  void calcuSize(int j) {uSize[j]=0; }
140 
141  virtual void updateStateDependentVariables(double t);
142  void updateh(double t, int j=0) {};
143 
144  void initializeUsingXML(xercesc::DOMElement *element);
145  void init(InitStage stage);
146 
147  private:
148  MBSim::Function<double(double)> * QFun;
149  fmatvec::Vec Q;
150  };
151 
153  class FluidPump : public HLine {
154  public:
155  FluidPump(const std::string &name="") : HLine(name), QSignal(NULL), QSignalString(""), Q(1) {}
156  virtual std::string getType() const { return "FluidPump"; }
157 
158  void setQSignal(MBSimControl::Signal * QSignal_) {QSignal=QSignal_; }
159 
160  virtual fmatvec::Vec getQIn();
161  virtual fmatvec::Vec getQOut();
162  virtual fmatvec::Vec getInflowFactor() {return fmatvec::Vec(1, fmatvec::INIT, -1.); }
163  virtual fmatvec::Vec getOutflowFactor() {return fmatvec::Vec(1, fmatvec::INIT, 1.); }
164  void calcqSize() {qSize=0; }
165  void calcuSize(int j) {uSize[j]=0; }
166 
167  void updateh(double t, int j=0) {};
168 
169  void initializeUsingXML(xercesc::DOMElement *element);
170  void init(InitStage stage);
171 
172  private:
173  MBSimControl::Signal * QSignal;
174  std::string QSignalString;
175  fmatvec::Vec Q;
176  };
177 
179  class StatelessOrifice : public HLine {
180  public:
181  StatelessOrifice(const std::string &name="") : HLine(name), inflowSignal(NULL), outflowSignal(NULL), openingSignal(NULL), inflowSignalString(""), outflowSignalString(""), openingSignalString(""), diameter(0), alpha(0.), calcAreaModus(0) {}
182  virtual std::string getType() const { return "StatelessOrifice"; }
183 
184  void setInflowSignal(MBSimControl::Signal * inflowSignal_) {inflowSignal=inflowSignal_; }
185  void setOutflowSignal(MBSimControl::Signal * outflowSignal_) {outflowSignal=outflowSignal_; }
186  void setDiameter(double diameter_) {diameter=diameter_; }
187  void setOpeningSignal(MBSimControl::Signal * openingSignal_) {openingSignal=openingSignal_; }
188  void setAlpha(double alpha_) {alpha=alpha_; }
189  void setCalcAreaModus(int calcAreaModus_) {calcAreaModus=calcAreaModus_; }
190 
191  virtual fmatvec::Vec getQIn();
192  virtual fmatvec::Vec getQOut();
193  virtual fmatvec::Vec getInflowFactor() {return fmatvec::Vec(1, fmatvec::INIT, -1.); }
194  virtual fmatvec::Vec getOutflowFactor() {return fmatvec::Vec(1, fmatvec::INIT, 1.); }
195  void calcqSize() {qSize=0; }
196  void calcuSize(int j) {uSize[j]=0; }
197 
198  void updateh(double t, int j=0) {};
199 
200  void initializeUsingXML(xercesc::DOMElement *element);
201  void init(InitStage stage);
202  void plot(double t, double dt);
203 
204  private:
205  MBSimControl::Signal *inflowSignal, *outflowSignal, *openingSignal;
206  std::string inflowSignalString, outflowSignalString, openingSignalString;
207  double diameter, alpha;
208  int calcAreaModus;
209  fmatvec::Vec calculateQ();
210 
211  double pIn, pOut, dp, sign, opening, area, sqrt_dp;
212  };
213 
214 }
215 
216 #endif /* ----- #ifndef _HLINE_H_ ----- */
217 
Vector< Ref, double > Vec
Definition: hline.h:153
Definition: hline.h:179
Definition: hline.h:88
Definition: hline.h:41
Definition: hline.h:123
Definition: hnode.h:62

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML