mbsimhydraulics  4.0.0
MBSim Hydraulics Module
hnode.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 _HNODE_H_
21 #define _HNODE_H_
22 
23 #include "mbsim/links/link.h"
24 #include <mbsim/functions/function.h>
25 
26 #include <mbsim/utils/boost_parameters.h>
27 #include <mbsim/utils/openmbv_utils.h>
28 namespace OpenMBV {
29  class Group;
30  class Sphere;
31 }
32 
33 namespace MBSim {
34  class GeneralizedForceLaw;
35  class GeneralizedImpactLaw;
36 }
37 
38 namespace MBSimHydraulics {
39 
40  BOOST_PARAMETER_NAME(size)
41  BOOST_PARAMETER_NAME(minimalPressure)
42  BOOST_PARAMETER_NAME(maximalPressure)
43  BOOST_PARAMETER_NAME(position)
44 
45  class HydraulicEnvironment;
46  class HLine;
47  class HydFluid;
48  class OilBulkModulus;
49 
51  HLine * line;
52  fmatvec::Vec sign;
53  bool inflow;
54  };
55 
57  class HNode : public MBSim::Link {
58  public:
59  HNode(const std::string &name);
60 
61  void calcSize() override;
62 
63  BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBVSphere, tag, (optional (size,(double),1)(minimalPressure,(double),0e5)(maximalPressure,(double),10e5)(position,(const fmatvec::Vec3&),fmatvec::Vec3()))) {
64  enableOpenMBV(size,minimalPressure,maximalPressure,position);
65  }
66  virtual void enableOpenMBV(double size, double pMin, double pMax, const fmatvec::Vec3 &WrON);
67 
68  void addInFlow(HLine * in);
69  void addOutFlow(HLine * out);
70 
71  void calcgdSize(int j) override {gdSize=1; }
72 
73  void init(InitStage stage, const MBSim::InitConfigSet &config) override;
74 
75  void updateWRef(fmatvec::Mat& WRef, int i=0) override;
76  void updateVRef(fmatvec::Mat& VRef, int i=0) override;
77  void updatehRef(fmatvec::Vec& hRef, int i=0) override;
78  void updaterRef(fmatvec::Vec& rRef, int i=0) override;
79  void updatedhdqRef(fmatvec::Mat& dhdqRef, int i=0);
80  void updatedhduRef(fmatvec::SqrMat& dhduRef, int i=0);
81  void updatedhdtRef(fmatvec::Vec& dhdtRef, int i=0);
82 
83  double evalQHyd() { if(updQHyd) updateQHyd(); return QHyd; }
84  double getQHyd(bool check=true) const { assert((not check) or (not updQHyd)); return QHyd; }
85  virtual void updateQHyd();
86 
87  void updateh(int j=0) override;
88  void updatedhdz();
89  void updategd() override;
90  bool isActive() const override {return false; }
91  bool gActiveChanged() override {return false; }
92 
93  void plot() override;
94 
95  void initializeUsingXML(xercesc::DOMElement *element) override;
96 
97  void resetUpToDate() override { MBSim::Link::resetUpToDate(); updQHyd = true; }
98 
99  protected:
100  HydraulicEnvironment *hydEnv=nullptr;
101  std::vector<connectedLinesStruct> connectedLines;
102  std::vector<connectedLinesStruct> connected0DOFLines;
103  std::vector<std::string> refInflowString;
104  std::vector<std::string> refOutflowString;
105  double QHyd;
106  unsigned int nLines;
107  bool updQHyd;
108  std::shared_ptr<OpenMBV::Group> openMBVGrp;
109  std::shared_ptr<OpenMBV::Sphere> openMBVSphere;
110  fmatvec::Vec3 WrON;
111  };
112 
113 
115  class ConstrainedNode : public HNode {
116  public:
117  ConstrainedNode(const std::string &name="") : HNode(name) {}
118  ~ConstrainedNode() override { delete pFun; }
119 
120  void setpFunction(MBSim::Function<double(double)> * pFun_) {
121  pFun=pFun_;
122  pFun->setParent(this);
123  pFun->setName("p");
124  }
125 
126  void updateGeneralizedForces() override;
127  void init(InitStage stage, const MBSim::InitConfigSet &config) override;
128  void initializeUsingXML(xercesc::DOMElement *element) override;
129  bool isSingleValued() const override {return true;}
130 
131  private:
132  MBSim::Function<double(double)> * pFun{nullptr};
133  };
134 
135 
137  class EnvironmentNode : public HNode {
138  public:
139  EnvironmentNode(const std::string &name="") : HNode(name) {}
140 
141  void init(InitStage stage, const MBSim::InitConfigSet &config) override;
142 
143  bool isSingleValued() const override {return true;}
144  };
145 
146 
148  class ElasticNode : public HNode {
149  public:
150  ElasticNode(const std::string &name="") : HNode(name) {}
151  ~ElasticNode() override;
152 
153  void setVolume(double V_) {V=V_; }
154  void setFracAir(double fracAir_) {fracAir=fracAir_; }
155  void setp0(double p0_) {p0=p0_; }
156 
157  void calcxSize() override {xSize=1; }
158 
159  void init(InitStage stage, const MBSim::InitConfigSet &config) override;
160  void initializeUsingXML(xercesc::DOMElement *element) override;
161 
162  void updateGeneralizedForces() override;
163 
164  void updatexd() override;
165 
166  void plot() override;
167 
168  bool isSingleValued() const override {return true;}
169 
170  private:
171  double V{0};
172  double fracAir{0};
173  double p0{0};
174  OilBulkModulus * bulkModulus{nullptr};
175  };
176 
177 
179  class RigidNode : public HNode {
180  public:
181  RigidNode(const std::string &name="");
182  ~RigidNode() override;
183 
184  bool isSetValued() const override {return true; }
185  bool isActive() const override {return true; }
186 
187  void init(InitStage stage, const MBSim::InitConfigSet &config) override;
188 
189  void calclaSize(int j) override {laSize=1; }
190  //void calclaSizeForActiveg() {laSize=0; }
191  void calcrFactorSize(int j) override {rFactorSize=1; }
192 
193  void updateGeneralizedForces() override;
194 
195  void updategd() override;
196  void updateW(int j=0) override;
197 
198  void updaterFactors() override;
199  void solveImpactsFixpointSingle() override;
200  void solveConstraintsFixpointSingle() override;
201  void solveImpactsGaussSeidel() override;
202  void solveConstraintsGaussSeidel() override;
203  void solveImpactsRootFinding() override;
204  void solveConstraintsRootFinding() override;
205  void jacobianImpacts() override;
206  void jacobianConstraints() override;
207  void checkImpactsForTermination() override;
208  void checkConstraintsForTermination() override;
209  const double& evalgdn();
210  const double& evalgdd();
211  private:
212  double gdn, gdd;
215  };
216 
217 
219  class RigidCavitationNode : public HNode {
220  public:
221  RigidCavitationNode(const std::string &name="");
222  ~RigidCavitationNode() override;
223 
224  void setCavitationPressure(double pCav_) {pCav=pCav_; }
225 
226  bool isSetValued() const override {return true; }
227  bool isSingleValued() const override {return true; }
228  bool isActive() const override {return active; }
229 
230  void calcxSize() override {xSize=1; }
231  void calcgSize(int j) override {gSize=1; }
232  //void calcgSizeActive() {gSize=0; }
233  void calclaSize(int j) override {laSize=1; }
234  //void calclaSizeForActiveg() {laSize=0; }
235  void calcrFactorSize(int j) override {rFactorSize=1; }
236  void calcsvSize() override {svSize=1; }
237 
238  void init(InitStage stage, const MBSim::InitConfigSet &config) override;
239  void initializeUsingXML(xercesc::DOMElement *element) override;
240  void plot() override;
241 
242  void checkActive(int j) override;
243  //void checkActivegdn();
244  bool gActiveChanged() override;
245 
246  void updateGeneralizedForces() override;
247  void updateg() override;
248  void updateW(int j=0) override;
249  void updatexd() override;
250  void updateStopVector() override;
251  void checkRoot() override;
252 
253  void updaterFactors() override;
254  void solveImpactsFixpointSingle() override;
255  void solveConstraintsFixpointSingle() override;
256  void solveImpactsGaussSeidel() override;
257  void solveConstraintsGaussSeidel() override;
258  void solveImpactsRootFinding() override;
259  void solveConstraintsRootFinding() override;
260  void jacobianImpacts() override;
261  void jacobianConstraints() override;
262  void checkImpactsForTermination() override;
263  void checkConstraintsForTermination() override;
264  const double& evalgdn();
265  const double& evalgdd();
266 
267  protected:
268  double pCav;
269  private:
270  bool active, active0;
271  double gdn, gdd;
274  };
275 
276 
278  class PressurePump : public HNode {
279  public:
280  PressurePump(const std::string &name="") : HNode(name) { }
281 
282  void setpFunction(MBSim::Function<double(double)> *pFunction_) { pFunction=pFunction_; }
283 
284  void init(InitStage stage, const MBSim::InitConfigSet &config) override;
285 
286  void updateGeneralizedForces() override;
287  void initializeUsingXML(xercesc::DOMElement *element) override;
288 
289  private:
290  MBSim::Function<double(double)> *pFunction{nullptr};
291  };
292 
293 }
294 
295 #endif /* ----- #ifndef _HYDNODE_H_ ----- */
296 
Definition: hnode.h:137
Definition: hnode.h:179
Definition: hnode.h:115
Definition: hline.h:40
Definition: environment.h:95
std::string name
Definition: hnode.h:57
void setName(const std::string &str)
Definition: hnode.h:278
Definition: hnode.h:148
Definition: environment.h:31