mbsimhydraulics  3.0.0
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/link.h"
24 #include "mbsim/utils/function.h"
25 
26 #ifdef HAVE_OPENMBVCPPINTERFACE
27 namespace OpenMBV {
28  class Group;
29  class Sphere;
30 }
31 #endif
32 
33 namespace MBSim {
34  class GeneralizedForceLaw;
35  class GeneralizedImpactLaw;
36 }
37 
38 namespace MBSimControl {
39  class Signal;
40 }
41 
42 namespace MBSimHydraulics {
43 
44  class HLine;
45  class HydFluid;
46  class OilBulkModulus;
47 
49  HLine * line;
50  fmatvec::Vec sign;
51  bool inflow;
52  };
53 
55  class HNode : public MBSim::Link {
56  public:
57  HNode(const std::string &name);
58  ~HNode() {};
59  virtual std::string getType() const { return "HNode"; }
60 
61 #ifdef HAVE_OPENMBVCPPINTERFACE
62  virtual void enableOpenMBV(double size=1, double pMin=0e5, double pMax=10e5, fmatvec::Vec WrON=fmatvec::Vec(3));
63 #endif
64 
65  void addInFlow(HLine * in);
66  void addOutFlow(HLine * out);
67 
68  void calcgdSize(int j) {gdSize=1; }
69 
70  void init(MBSim::InitStage stage);
71 
72  virtual void updateWRef(const fmatvec::Mat& WRef, int i=0);
73  virtual void updateVRef(const fmatvec::Mat& VRef, int i=0);
74  virtual void updatehRef(const fmatvec::Vec& hRef, int i=0);
75  virtual void updaterRef(const fmatvec::Vec& rRef, int i=0);
76  virtual void updatedhdqRef(const fmatvec::Mat& dhdqRef, int i=0);
77  virtual void updatedhduRef(const fmatvec::SqrMat& dhduRef, int i=0);
78  virtual void updatedhdtRef(const fmatvec::Vec& dhdtRef, int i=0);
79 
80  void updateh(double t, int j=0);
81  void updatedhdz(double t);
82  virtual void updater(double t, int j);
83  virtual void updateg(double t) {};
84  virtual void updategd(double t);
85  virtual bool isActive() const {return false; }
86  virtual bool gActiveChanged() {return false; }
87 
88  void plot(double t, double dt);
89 
90  void initializeUsingXML(TiXmlElement *element);
91 
92  protected:
93  std::vector<connectedLinesStruct> connectedLines;
94  std::vector<connectedLinesStruct> connected0DOFLines;
95  std::vector<std::string> refInflowString;
96  std::vector<std::string> refOutflowString;
97  double QHyd;
98  unsigned int nLines;
99 #ifdef HAVE_OPENMBVCPPINTERFACE
100  OpenMBV::Group * openMBVGrp;
101  OpenMBV::Sphere * openMBVSphere;
102  fmatvec::Vec WrON;
103 #endif
104  };
105 
106 
108  class ConstrainedNode : public HNode {
109  public:
110  ConstrainedNode(const std::string &name) : HNode(name), pFun(NULL) {}
111  virtual std::string getType() const { return "ConstrainedNode"; }
112 
113  void setpFunction(MBSim::Function1<double,double> * pFun_) {pFun=pFun_; }
114 
115  void updateg(double t);
116  void init(MBSim::InitStage stage);
117  void initializeUsingXML(TiXmlElement *element);
118 
119  private:
120  MBSim::Function1<double,double> * pFun;
121  };
122 
123 
125  class EnvironmentNode : public HNode {
126  public:
127  EnvironmentNode(const std::string &name) : HNode(name) {}
128  virtual std::string getType() const { return "EnvironmentNode"; }
129 
130  void init(MBSim::InitStage stage);
131  };
132 
133 
135  class ElasticNode : public HNode {
136  public:
137  ElasticNode(const std::string &name) : HNode(name), V(0), E(0), fracAir(0), p0(0), bulkModulus(NULL) {}
138  ~ElasticNode();
139  virtual std::string getType() const { return "ElasticNode"; }
140 
141  void setVolume(double V_) {V=V_; }
142  void setFracAir(double fracAir_) {fracAir=fracAir_; }
143  void setp0(double p0_) {p0=p0_; }
144 
145  void calcxSize() {xSize=1; }
146 
147  void init(MBSim::InitStage stage);
148  void initializeUsingXML(TiXmlElement *element);
149 
150  void updatexRef(const fmatvec::Vec &xParent);
151 
152  void updatexd(double t);
153  void updatedx(double t, double dt);
154 
155  void plot(double t, double dt);
156 
157  private:
158  double V, E;
159  double fracAir;
160  double p0;
161  OilBulkModulus * bulkModulus;
162  };
163 
164 
166  class RigidNode : public HNode {
167  public:
168  RigidNode(const std::string &name);
169  ~RigidNode();
170  virtual std::string getType() const { return "RigidNode"; }
171 
172  bool isSetValued() const {return true; }
173  virtual bool isActive() const {return true; }
174 
175  void calclaSize(int j) {laSize=1; }
176  //void calclaSizeForActiveg() {laSize=0; }
177  void calcrFactorSize(int j) {rFactorSize=1; }
178 
179  void updategd(double t);
180  void updateW(double t, int j=0);
181 
182  void updaterFactors();
183  void solveImpactsFixpointSingle(double dt);
184  void solveConstraintsFixpointSingle();
185  void solveImpactsGaussSeidel(double dt);
186  void solveConstraintsGaussSeidel();
187  void solveImpactsRootFinding(double dt);
188  void solveConstraintsRootFinding();
189  void jacobianImpacts();
190  void jacobianConstraints();
191  void checkImpactsForTermination(double dt);
192  void checkConstraintsForTermination();
193  private:
194  double gdn, gdd;
195  MBSim::GeneralizedForceLaw * gfl;
196  MBSim::GeneralizedImpactLaw * gil;
197  };
198 
199 
201  class RigidCavitationNode : public HNode {
202  public:
203  RigidCavitationNode(const std::string &name);
205  virtual std::string getType() const { return "RigidCavitationNode"; }
206 
207  void setCavitationPressure(double pCav_) {pCav=pCav_; }
208 
209  bool isSetValued() const {return true; }
210  bool hasSmoothPart() const {return true; }
211  virtual bool isActive() const {return active; }
212 
213  void calcxSize() {xSize=1; }
214  void calcgSize(int j) {gSize=1; }
215  //void calcgSizeActive() {gSize=0; }
216  void calclaSize(int j) {laSize=1; }
217  //void calclaSizeForActiveg() {laSize=0; }
218  void calcrFactorSize(int j) {rFactorSize=1; }
219  void calcsvSize() {svSize=1; }
220 
221  void init(MBSim::InitStage stage);
222  void initializeUsingXML(TiXmlElement *element);
223  void plot(double t, double dt);
224 
225  void checkActive(int j);
226  //void checkActivegdn();
227  bool gActiveChanged();
228 
229  void updateg(double t);
230  void updateh(double t, int j=0);
231  void updateStopVector(double t);
232  void updateW(double t, int j=0);
233  void updatexd(double t);
234  void updatedx(double t, double dt);
235  void checkRoot();
236 
237  void updaterFactors();
238  void solveImpactsFixpointSingle(double dt);
239  void solveConstraintsFixpointSingle();
240  void solveImpactsGaussSeidel(double dt);
241  void solveConstraintsGaussSeidel();
242  void solveImpactsRootFinding(double dt);
243  void solveConstraintsRootFinding();
244  void jacobianImpacts();
245  void jacobianConstraints();
246  void checkImpactsForTermination(double dt);
247  void checkConstraintsForTermination();
248  protected:
249  double pCav;
250  private:
251  bool active, active0;
252  double gdn, gdd;
253  MBSim::GeneralizedForceLaw * gfl;
254  MBSim::GeneralizedImpactLaw * gil;
255  };
256 
257 
259  class PressurePump : public HNode {
260  public:
261  PressurePump(const std::string &name) : HNode(name), pSignal(NULL), pSignalString("") {}
262  virtual std::string getType() const { return "PressurePump"; }
263 
264  void setpSignal(MBSimControl::Signal * pSignal_) {pSignal=pSignal_; }
265 
266  void updateg(double t);
267  void init(MBSim::InitStage stage);
268  void initializeUsingXML(TiXmlElement *element);
269 
270  private:
271  MBSimControl::Signal * pSignal;
272  std::string pSignalString;
273  };
274 
275 }
276 
277 #endif /* ----- #ifndef _HYDNODE_H_ ----- */
278