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/objects/object.h"
24 #include <mbsim/functions/function.h>
25 
26 namespace MBSim {
27  class Frame;
28 }
29 
30 namespace MBSimHydraulics {
31 
32  class HNode;
33  class HydlinePressureloss;
34  class PressureLoss;
35 
37  class HLine : public MBSim::Object {
38  public:
39  HLine(const std::string &name) : MBSim::Object(name), nFrom(NULL), nTo(NULL), nFromRelative(false), nToRelative(false), direction(fmatvec::Vec(3, fmatvec::INIT, 0)), Mlocal(), QIn(1), QOut(1), Jacobian(), frameOfReference(NULL), updQ(true), saved_frameOfReference("") { }
40  virtual std::string getType() const { return "HLine"; }
41 
42  /* INHERITED INTERFACE OF OBJECTINTERFACE */
43  void updateh(int j=0) { }
44  void updateJacobians(int j=0) { }
45  void updateInverseKineticsJacobians() { }
46  virtual std::shared_ptr<OpenMBV::Group> getOpenMBVGrp() { return std::shared_ptr<OpenMBV::Group>(); }
47  /***************************************************/
48 
49  virtual void setFrameOfReference(MBSim::Frame *frame);
50  void setFromNode(HNode * nFrom_) {nFrom=nFrom_; }
51  void setToNode(HNode * nTo_) {nTo=nTo_; }
52  void setDirection(fmatvec::Vec dir) {direction=((nrm2(dir)>0)?dir/nrm2(dir):fmatvec::Vec(3, fmatvec::INIT, 0)); }
53  HNode * getFromNode() { return nFrom; }
54  HNode * getToNode() {return nTo; }
55  void setOutflowRelative(bool rel=true) { nToRelative=rel; }
56  void setInflowRelative(bool rel=true) { nFromRelative=rel; }
57  virtual fmatvec::VecV getInflowFactor() {return fmatvec::VecV(1, fmatvec::INIT, -1.); }
58  virtual fmatvec::VecV getOutflowFactor() {return fmatvec::VecV(1, fmatvec::INIT, 1.); }
59 
60  const fmatvec::VecV& evalQIn() { if(updQ) updateQ(); return QIn; }
61  const fmatvec::VecV& evalQOut() { if(updQ) updateQ(); return QOut; }
62  const fmatvec::VecV& getQIn(bool check=true) const { assert((not check) or (not updQ)); return QIn; }
63  const fmatvec::VecV& getQOut(bool check=true) const { assert((not check) or (not updQ)); return QOut; }
64  const fmatvec::MatV& getJacobian() const { return Jacobian; }
65 
66  virtual void updateQ() { }
67  void updateM() { M=Mlocal; }
68 
69  void init(InitStage stage);
70  void initializeUsingXML(xercesc::DOMElement *element);
71 
72  virtual Element* getDependency() const { return 0; }
73 
74  void resetUpToDate() { MBSim::Object::resetUpToDate(); updQ = true; }
75 
76  protected:
77  HNode * nFrom;
78  HNode * nTo;
79  bool nFromRelative, nToRelative;
80  fmatvec::VecV direction;
81  fmatvec::SymMatV Mlocal;
82  fmatvec::VecV QIn, QOut;
83  fmatvec::MatV Jacobian;
84  MBSim::Frame * frameOfReference;
85  bool updQ;
86  private:
87  std::string saved_frameOfReference;
88  };
89 
91  class RigidHLine : public HLine {
92  public:
93  RigidHLine(const std::string &name) : HLine(name), pressureLossGravity(0), length(0), updPLG(true) { }
94  virtual std::string getType() const { return "RigidHLine"; }
95 
96  void setLength(double length_) {length=length_; }
97  double getLength() const {return length; }
98  void addInflowDependencyOnOutflow(RigidHLine* line);
99  void addInflowDependencyOnInflow(RigidHLine* line);
100 
101  void calcqSize() {qSize=0; }
102  void calcuSize(int j=0) {uSize[j]=(dependency.size()?0:1); }
103  fmatvec::Mat calculateJacobian(std::vector<RigidHLine*> dep_check);
104 
105  void updatePressureLossGravity();
106  double evalPressureLossGravity() { if(updPLG) updatePressureLossGravity(); return pressureLossGravity; }
107 
108  void updateQ();
109  void updateh(int j=0);
110  void updateM();
111 
112  void initializeUsingXML(xercesc::DOMElement *element);
113  void init(InitStage stage);
114  void plot();
115 
116  void resetUpToDate() { HLine::resetUpToDate(); updPLG = true; }
117 
118  protected:
119  double pressureLossGravity;
120  double length;
121  std::vector<RigidHLine*> dependencyOnOutflow, dependencyOnInflow;
122  std::vector<std::string> refDependencyOnOutflowString, refDependencyOnInflowString;
123  bool updPLG;
124  };
125 
127  class ConstrainedLine : public HLine {
128  public:
129  ConstrainedLine(const std::string &name="") : HLine(name), QFunction(NULL) { }
130  virtual std::string getType() const { return "ConstrainedLine"; }
131 
132  void setQFunction(MBSim::Function<double(double)> * QFunction_) {
133  QFunction=QFunction_;
134  QFunction->setParent(this);
135  QFunction->setName("Q");
136  }
137 
138  void calcqSize() { qSize=0; }
139  void calcuSize(int j) { uSize[j]=0; }
140 
141  void updateQ();
142 
143  void initializeUsingXML(xercesc::DOMElement *element);
144  void init(InitStage stage);
145 
146  private:
148  };
149 
151  class FluidPump : public HLine {
152  public:
153  FluidPump(const std::string &name="") : HLine(name), QFunction(NULL) { }
154  virtual std::string getType() const { return "FluidPump"; }
155 
156  void setQFunction(MBSim::Function<double(double)> * QFunction_) { QFunction=QFunction_; }
157 
158  void calcqSize() { qSize=0; }
159  void calcuSize(int j) { uSize[j]=0; }
160 
161  void updateQ();
162 
163  void initializeUsingXML(xercesc::DOMElement *element);
164  void init(InitStage stage);
165 
166  private:
168  };
169 
171  class StatelessOrifice : public HLine {
172  public:
173  StatelessOrifice(const std::string &name="") : HLine(name), inflowFunction(NULL), outflowFunction(NULL), openingFunction(NULL), diameter(0), alpha(0.), calcAreaModus(0) {}
174  virtual std::string getType() const { return "StatelessOrifice"; }
175 
176  void setInflowFunction(MBSim::Function<double(double)> *inflowFunction_) { inflowFunction=inflowFunction_; }
177  void setOutflowFunction(MBSim::Function<double(double)> *outflowFunction_) { outflowFunction=outflowFunction_; }
178  void setOpeningFunction(MBSim::Function<double(double)> *openingFunction_) { openingFunction=openingFunction_; }
179  void setDiameter(double diameter_) { diameter=diameter_; }
180  void setAlpha(double alpha_) { alpha=alpha_; }
181  void setCalcAreaModus(int calcAreaModus_) { calcAreaModus=calcAreaModus_; }
182 
183  void calcqSize() { qSize=0; }
184  void calcuSize(int j) { uSize[j]=0; }
185 
186  void updateQ();
187 
188  void initializeUsingXML(xercesc::DOMElement *element);
189  void init(InitStage stage);
190  void plot();
191 
192  private:
193  MBSim::Function<double(double)> *inflowFunction, *outflowFunction, *openingFunction;
194  double diameter, alpha;
195  int calcAreaModus;
196 
197  double pIn, pOut, dp, sign, opening, area, sqrt_dp;
198  };
199 
200 }
201 
202 #endif /* ----- #ifndef _HLINE_H_ ----- */
203 
Vector< Ref, double > Vec
Definition: hline.h:151
Definition: hline.h:171
Definition: hline.h:91
Definition: hline.h:37
Definition: hline.h:127
Definition: hnode.h:56

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML