mbsimhydraulics  3.0.0
hnode_mec.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_MEC_H_
21 #define _HNODE_MEC_H_
22 
23 #include "hnode.h"
24 #include "mbsim/utils/function.h"
25 
26 #ifdef HAVE_OPENMBVCPPINTERFACE
27 namespace OpenMBV {
28  class Arrow;
29 }
30 #endif
31 
32 namespace MBSim {
33  class Frame;
34  class GeneralizedForceLaw;
35  class GeneralizedImpactLaw;
36 }
37 
38 namespace MBSimHydraulics {
39 
40  class HydFluid;
41  class OilBulkModulus;
42 
44  MBSim::Frame * frame;
45  fmatvec::Vec normal;
46  double area;
47  bool considerVolumeChange;
48  };
49 
51  MBSim::Frame * frame;
52  fmatvec::Vec normal;
53  MBSim::Frame * fref;
54  double area;
55  bool considerVolumeChange;
56  };
57 
59  class HNodeMec : public HNode {
60  public:
61  HNodeMec(const std::string &name);
62  ~HNodeMec();
63  virtual std::string getType() const { return "HNodeMec"; }
64 
65 #ifdef HAVE_OPENMBVCPPINTERFACE
66  void enableOpenMBVArrows(double size=1.);
67 #endif
68 
69  void setInitialVolume(double V0_) {V0=V0_; }
70  unsigned int addTransMecArea(MBSim::Frame * f, fmatvec::Vec fN, double area, bool considerVolumeChange=true);
71  unsigned int addRotMecArea(MBSim::Frame * f, fmatvec::Vec fN, double area, MBSim::Frame * frameOfReference, bool considerVolumeChange=true);
72  void setTransMecArea(unsigned int i, double area) {connectedTransFrames[i].area=area; }
73 
74  void calcxSize() {xSize=1; }
75 
76  void init(MBSim::InitStage stage);
77  void initializeUsingXML(TiXmlElement *element);
78 
79  virtual void updateWRef(const fmatvec::Mat& Wref, int i=0);
80  virtual void updateVRef(const fmatvec::Mat& Vref, int i=0);
81  virtual void updatehRef(const fmatvec::Vec& href, int i=0);
82  virtual void updatedhdqRef(const fmatvec::Mat& dhdqRef, int i=0);
83  virtual void updatedhduRef(const fmatvec::SqrMat& dhduRef, int i=0);
84  virtual void updatedhdtRef(const fmatvec::Vec& dhdtRef, int i=0);
85  virtual void updaterRef(const fmatvec::Vec& ref, int i=0);
86 
87  void updateh(double t, int j=0);
88  void updatedhdz(double t);
89  virtual void updater(double t, int j=0);
90  void updategd(double t);
91  void updatexd(double t);
92  void updatedx(double t, double dt);
93 
94  void plot(double t, double dt);
95 
96  protected:
97  std::vector<connectedTransFrameStruct> connectedTransFrames;
98  std::vector<connectedRotFrameStruct> connectedRotFrames;
99  double QMecTrans, QMecRot, QMec;
100  double V0;
101  unsigned int nTrans, nRot;
102 #ifdef HAVE_OPENMBVCPPINTERFACE
103  std::vector<OpenMBV::Arrow *> openMBVArrows;
104  double openMBVArrowSize;
105 #endif
106 
107  private:
108  std::vector<std::string> saved_translatorial_frameOfReference, saved_rotatorial_frameOfReference, saved_rotatorial_frameOfRotationCenter;
109  std::vector<fmatvec::Vec> saved_translatorial_normal, saved_rotatorial_normal;
110  std::vector<double> saved_translatorial_area, saved_rotatorial_area;
111  std::vector<bool> saved_translatorial_noVolumeChange, saved_rotatorial_noVolumeChange;
112  };
113 
115  class ConstrainedNodeMec : public HNodeMec {
116  public:
117  ConstrainedNodeMec(const std::string &name) : HNodeMec(name), pFun(NULL) {}
118  ~ConstrainedNodeMec() {};
119  virtual std::string getType() const { return "ConstrainedNodeMec"; }
120 
121  void setpFunction(MBSim::Function1<double,double> * pFun_) {pFun=pFun_; }
122 
123  void init(MBSim::InitStage stage);
124  void initializeUsingXML(TiXmlElement *element);
125 
126  void updateg(double t);
127 
128  private:
129  MBSim::Function1<double,double> * pFun;
130  };
131 
132 
134  class EnvironmentNodeMec : public HNodeMec {
135  public:
136  EnvironmentNodeMec(const std::string &name) : HNodeMec(name) {}
137  virtual std::string getType() const { return "EnvironmentNodeMec"; }
138 
139  void init(MBSim::InitStage stage);
140  };
141 
142 
144  class ElasticNodeMec : public HNodeMec {
145  public:
146  ElasticNodeMec(const std::string &name) : HNodeMec(name), E(0), fracAir(0), p0(0), bulkModulus(NULL) {}
147  ~ElasticNodeMec();
148  virtual std::string getType() const { return "ElasticNode"; }
149 
150  void setFracAir(double fracAir_) {fracAir=fracAir_; }
151  void setp0(double p0_) {p0=p0_; }
152 
153  void calcxSize() {xSize=2; }
154 
155  void init(MBSim::InitStage stage);
156  void initializeUsingXML(TiXmlElement *element);
157 
158  void updatexRef(const fmatvec::Vec &xParent);
159 
160  void updatexd(double t);
161  void updatedx(double t, double dt);
162 
163  void plot(double t, double dt);
164 
165 
166  private:
167  double E;
168  double fracAir;
169  double p0;
170 
171  OilBulkModulus * bulkModulus;
172  };
173 
174 
176  class RigidNodeMec : public HNodeMec {
177  public:
178  RigidNodeMec(const std::string &name);
179  ~RigidNodeMec();
180  virtual std::string getType() const { return "RigidNodeMec"; }
181 
182  bool isSetValued() const {return true; }
183  bool isActive() const {return true; }
184 
185  void calclaSize(int j) {laSize=1; }
186  //void calclaSizeForActiveg() {laSize=0; }
187  void calcrFactorSize(int j) {rFactorSize=1; }
188 
189  void init(MBSim::InitStage stage);
190 
191  void updatewbRef(const fmatvec::Vec& wbParent);
192 
193  void updategd(double t);
194  void updateW(double t, int j=0);
195 
196  void updaterFactors();
197  void solveImpactsFixpointSingle(double dt);
198  void solveConstraintsFixpointSingle();
199  void solveImpactsGaussSeidel(double dt);
200  void solveConstraintsGaussSeidel();
201  void solveImpactsRootFinding(double dt);
202  void solveConstraintsRootFinding();
203  void jacobianImpacts();
204  void jacobianConstraints();
205  void checkImpactsForTermination(double dt);
206  void checkConstraintsForTermination();
207  private:
208  double gdn, gdd;
209  MBSim::GeneralizedForceLaw * gfl;
210  MBSim::GeneralizedImpactLaw * gil;
211  };
212 }
213 
214 #endif /* ----- #ifndef _HYDNODE_MEC_H_ ----- */
215