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

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Home