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