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
50 struct connectedLinesStruct {
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;
190 //void calclaSizeForActiveg() {laSize=0; }
191 void calcrFactorSize(int j) override {rFactorSize=1; }
192 void calccorrSize(int j) override;
193
194 void updateGeneralizedForces() override;
195
196 void updategd() override;
197 void updateW(int j=0) override;
198
199 void updaterFactors() override;
200 void solveImpactsFixpointSingle() override;
201 void solveConstraintsFixpointSingle() override;
202 void solveImpactsGaussSeidel() override;
203 void solveConstraintsGaussSeidel() override;
204 void solveImpactsRootFinding() override;
205 void solveConstraintsRootFinding() override;
206 void jacobianImpacts() override;
207 void jacobianConstraints() override;
208 void checkImpactsForTermination() override;
209 void checkConstraintsForTermination() override;
210 const double& evalgdn();
211 const double& evalgdd();
212 private:
213 double gdn, gdd;
214 MBSim::GeneralizedForceLaw * gfl;
215 MBSim::GeneralizedImpactLaw * gil;
216 };
217
218
220 class RigidCavitationNode : public HNode {
221 public:
222 RigidCavitationNode(const std::string &name="");
223 ~RigidCavitationNode() override;
224
225 void setCavitationPressure(double pCav_) {pCav=pCav_; }
226
227 bool isSetValued() const override {return true; }
228 bool isSingleValued() const override {return true; }
229 bool isActive() const override {return active; }
230
231 void calcxSize() override {xSize=1; }
232 void calcgSize(int j) override {gSize=1; }
233 //void calcgSizeActive() {gSize=0; }
234 void calclaSize(int j) override {laSize=1; }
235 //void calclaSizeForActiveg() {laSize=0; }
236 void calcrFactorSize(int j) override {rFactorSize=1; }
237 void calcsvSize() override {svSize=1; }
238
239 void init(InitStage stage, const MBSim::InitConfigSet &config) override;
240 void initializeUsingXML(xercesc::DOMElement *element) override;
241 void plot() override;
242
243 void checkActive(int j) override;
244 //void checkActivegdn();
245 bool gActiveChanged() override;
246
247 void updateGeneralizedForces() override;
248 void updateg() override;
249 void updateW(int j=0) override;
250 void updatexd() override;
251 void updateStopVector() override;
252 void checkRoot() override;
253
254 void updaterFactors() override;
255 void solveImpactsFixpointSingle() override;
256 void solveConstraintsFixpointSingle() override;
257 void solveImpactsGaussSeidel() override;
258 void solveConstraintsGaussSeidel() override;
259 void solveImpactsRootFinding() override;
260 void solveConstraintsRootFinding() override;
261 void jacobianImpacts() override;
262 void jacobianConstraints() override;
263 void checkImpactsForTermination() override;
264 void checkConstraintsForTermination() override;
265 const double& evalgdn();
266 const double& evalgdd();
267
268 protected:
269 double pCav;
270 private:
271 bool active, active0;
272 double gdn, gdd;
273 MBSim::GeneralizedForceLaw * gfl;
274 MBSim::GeneralizedImpactLaw * gil;
275 };
276
277
279 class PressurePump : public HNode {
280 public:
281 PressurePump(const std::string &name="") : HNode(name) { }
282
283 void setpFunction(MBSim::Function<double(double)> *pFunction_) { pFunction=pFunction_; }
284
285 void init(InitStage stage, const MBSim::InitConfigSet &config) override;
286
287 void updateGeneralizedForces() override;
288 void initializeUsingXML(xercesc::DOMElement *element) override;
289
290 private:
291 MBSim::Function<double(double)> *pFunction{nullptr};
292 };
293
294 }
295
296 #endif /* ----- #ifndef _HYDNODE_H_ ----- */
297
MBSim::GeneralizedForceLaw
MBSim::Link
MBSimHydraulics::EnvironmentNode
Definition: hnode.h:137
MBSim::Link::laSize
int laSize
MBSim::Link::gdSize
int gdSize
MBSimHydraulics::RigidNode
Definition: hnode.h:179
MBSim::Link::xSize
int xSize
MBSimHydraulics::connectedLinesStruct
Definition: hnode.h:50
MBSimHydraulics::ConstrainedNode
Definition: hnode.h:115
MBSimHydraulics::HLine
Definition: hline.h:40
MBSimHydraulics::RigidCavitationNode
Definition: hnode.h:220
MBSimHydraulics::OilBulkModulus
Definition: environment.h:95
MBSim::Element::InitStage
InitStage
MBSim::Link::svSize
int svSize
MBSim::GeneralizedImpactLaw
MBSim::Function
MBSim::Element::name
std::string name
MBSimHydraulics::HNode
Definition: hnode.h:57
MBSim::Element::setName
void setName(const std::string &str)
MBSimHydraulics::PressurePump
Definition: hnode.h:279
MBSim::Link::gSize
int gSize
MBSim::Link::rFactorSize
int rFactorSize
MBSimHydraulics::ElasticNode
Definition: hnode.h:148
MBSimHydraulics::HydraulicEnvironment
Definition: environment.h:31