Marine systems simulation
CIceFloe.h
1
11
12#ifndef CIceFloe_H
13#define CIceFloe_H
14
15#include <string>
16#include <Eigen/Eigen>
17
18#include "SimObject.h"
19#include "CEnvironment.h"
20
21namespace ice {
22
23typedef Eigen::Matrix<double,6,6> mat6;
24typedef Eigen::Matrix<double,6,1> vec6;
25typedef Eigen::Matrix<double,3,3> mat3;
26typedef Eigen::Matrix<double,3,1> vec3;
27typedef Eigen::Matrix<double,13,1> vec13;
28typedef Eigen::Quaternion<double> quat;
29
30class CIceFloe : public SimObject
31{
32public:
33 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
34
35 CIceFloe(std::string sSimObjectName, ISimObjectCreator* pCreator);
36 virtual void FinalSetup(const double dT, const double* const adX, ISimObjectCreator* const pCreator);
37 virtual ~CIceFloe();
38
39#ifdef FH_VISUALIZATION
41 virtual void RenderInit(Ogre::Root* const ogreRoot, ISimObjectCreator* const creator);
42
44 virtual void RenderUpdate(const double dT, const double* const adX);
45
47 void DrawBody(Ogre::SceneNode* renderNode, Ogre::SceneManager* sceneMgr);
48#endif
49
51 {
52 public:
54 m_PolyplateSpec(int nPolyPoints, double* xPoints, double* yPoints, double thickness_, double density_, const string& material);
56
57 int numPoints; //#points
58 double thickness; //plate thickness
59 double xCoords[10]; //polygon x-coords (Anticlockwise)
60 double yCoords[10]; //polygon y-coords (Anticlockwise)
61 double density; // density
62 double mass; // mass
63 double volume; //volume
64 mat6 inertiaMatrix; //plate inertia
65 vec3 centroid;
66 string material;
67
68 double projectedArea;
69 double cubedGRZ;
70 double cubedGRY;
71 double cubedGRX;
72 double cubedGRXY;
73 double cubedGRYX;
74 };
75
76 // ================================================================================================== Contact
77 // AABB class ==========================================================================
78 class AABB {
79 public:
80 AABB() {
81 minloc(0) = minloc(1) = minloc(2) = std::numeric_limits<double>::max();
82 maxloc(0) = maxloc(1) = maxloc(2) = -std::numeric_limits<double>::max();
83 }
84
85 AABB(const AABB &aabb) {
86 minloc = aabb.minloc;
87 maxloc = aabb.maxloc;
88 }
89
90 ~AABB(){}
91
92 void add(const vec3 &v) {
93 if (v(0) < minloc(0)) minloc(0) = v(0);
94 if (v(1) < minloc(1)) minloc(1) = v(1);
95 if (v(2) < minloc(2)) minloc(2) = v(2);
96 if (v(0) > maxloc(0)) maxloc(0) = v(0);
97 if (v(1) > maxloc(1)) maxloc(1) = v(1);
98 if (v(2) > maxloc(2)) maxloc(2) = v(2);
99 }
100
101 void clear() {
102 minloc(0) = minloc(1) = minloc(2) = std::numeric_limits<double>::max();
103 maxloc(0) = maxloc(1) = maxloc(2) = -std::numeric_limits<double>::max();
104 }
105
106 int overlap(const AABB &aabb)
107 {
108 if(maxloc(0) < aabb.minloc(0) || minloc(0) > aabb.maxloc(0)) return 0;
109 if(maxloc(1) < aabb.minloc(1) || minloc(1) > aabb.maxloc(1)) return 0;
110 if(maxloc(2) < aabb.minloc(2) || minloc(2) > aabb.maxloc(2)) return 0;
111
112 return 1;
113 }
114
115 vec3 minloc, maxloc;
116 };
117 // AABB class ==========================================================================
118
119 // AABB struct =========================================================================
120 struct AABBSpec {
121 int numE;
122 int numT;
123
124 int* indexE;
125 int* indexT;
126 };
127 // AABB struct =========================================================================
128
129 // Object struct =======================================================================
130 struct ObjectSpec {
131 int numP;
132 int numT;
133
134 double* xyzP;
135 int* indexT;
136 double* normT;
137 };
138 // Object struct =======================================================================
139 // ================================================================================================== Contact
140
141
143 virtual void OdeFcn(const double dT, const double* const adX, double* const adXDot, const bool bIsMajorTimeStep);
144
145 // r: global
146 // q: global
147 // dX: bodylocal
148 // return: forcelocal
149 virtual vec6 GetInternalForces(const vec6& dX, const vec3& r, const quat& q, CEnvironment* environment, double time, const double* states);
150
151 // return: bodylocal
152 virtual mat6 GetInertiaMatrix(const vec3& r, const quat& q, const double dT, const double* const adX);
153
154 // all global coords
155 virtual vec13 GetSecondDerivative(const vec3& r, const quat& q, const vec3& v, const vec3 w, const vec6& externalForces, CEnvironment* environment, double time, const double* states);
156
157 // bodylocal coords
158 static vec6 GetCoriolisForce(const vec6& dX, const mat6& Inertia);
159
160 virtual vec6 CalcHydroforcesPolyplate(const vec6& dX, const vec3& r, const quat& q, CEnvironment* environment, double time, const double* states);
161
162 virtual vec6 CalContactForce(const vec3& r, const quat& q, const double dT, const double* const adX);
163
164 //================================================================================================== Contact
165 virtual int rayTri(const vec3 &V1, const vec3 &V2, const vec3 &V3, const vec3 &O, const vec3 &D, double &out);
166 //================================================================================================== Contact
167
168 //================================================================================================== WAMIT
169 virtual double GaussianFun(double &x, double &muix, double &sigmax, double &y, double &muiy, double &sigmay);
170 virtual double PolyVal(int* &polyxy, double* &gassxy, double* &par, double &parx, double &pary);
171 //================================================================================================== WAMIT
172
173protected:
174
175 // Input ports.
176 ISignalPort* m_pInMoment;
177 ISignalPort* m_pInForce;
178
179 // Output ports.
180 virtual const double* Position(const double dT, const double* const adX);
181 virtual const double* Velocity(const double dT, const double* const adX);
182 virtual const double* Quater(const double dT, const double* const adX);
183 virtual const double* LocalVel(const double dT, const double* const adX);
184 virtual const double* AngVel(const double dT, const double* const adX);
185 virtual const double* ContactForce(const double dT, const double* const adX);
186
187 virtual const double* Test(const double dT, const double* const adX);
188
189 // States
194
195 // Parameters
197 double m_adVelGlobal[3];
198 double m_dragxy;
199 double m_dragz;
200 CEnvironment* m_Environment;
201 double m_ContactForce[3];
204 double m_A33;
205 quat m_qc;
206 vec6 m_Acc;
207 double m_rA33;
208 int m_dCylinder;
209 int m_dPressure;
210
211 // Mesh
213 int m_wmesh;
214 int m_hmesh;
215 double m_dmesh;
216 double m_hdmesh;
217
218 // Contact
219 int m_contact;
220 double m_psize;
221 double m_hsize;
222 double m_ikns;
223 double m_iknv;
224 double m_ikts;
225 double m_imui;
226 double m_icst;
227 double m_carea;
228
229 //================================================================================================== Contact
230 ObjectSpec m_objectA;
231 vec3 m_locA;
232
233 ObjectSpec m_objectB;
234 double* m_objectBP0;
235
236 int m_ABNumA;
237 AABBSpec* m_ABSpecA;
238 AABB m_BOXA;
239 AABB* m_BOXAI;
240
241 int m_ABNumB;
242 AABBSpec* m_ABSpecB;
243 AABB m_BOXB;
244 AABB* m_BOXBI;
245
246 int m_itsNum;
247 double m_itsPoints[1000][3];
248
249 double m_ictr;
250 //================================================================================================== Contact
251
253 {
254 public:
257
258 double xos;
259 double yos;
260 double areas;
261 double width;
262 double hsize;
263 mat3 trp_s;
264 mat3 trs_p;
265
266 double aream;
267 int mts;
268 int mws;
269 double mt0;
270 double mw0;
271 double mtl;
272 double mwl;
273
274 double h_aream;
275 int h_mts;
276 int h_mws;
277 double h_mtl;
278 double h_mwl;
279
280 double dsp;
281 double xcnr[2];
282 double ycnr[2];
283 } m_surface[12];
284
285 // Test
286 double m_test[100];
287
288#ifdef FH_VISUALIZATION
289 string m_Material;
290 vector<Ogre::SceneNode*> m_RenderNodes;
291 Ogre::SceneManager* m_SceneMgr;
292 vector<Ogre::ManualObject*> m_Manual;
293
294 Ogre::SceneNode* m_RenderNode;
295#endif
296
297 static mat6 ReorientInertiaTranslateRotate(const mat6& Inertia, const vec6& orientation);
298 static mat3 MakeDyadic(const vec3& vector);
299 static mat3 GetRotation(const vec3& angle);
300 static mat6 GetRotation6(const vec3& angle);
301};
302
303};
304#endif
Definition: CEnvironment.h:10
Definition: CIceFloe.h:78
Definition: CIceFloe.h:31
m_PolyplateSpec m_spec0
The specification of the ice floe.
Definition: CIceFloe.h:196
double m_adVelGlobal[3]
The global velocity.
Definition: CIceFloe.h:197
double m_ContactForce[3]
Pointer to DeepSeaGravityWaves -> CEnvironment.
Definition: CIceFloe.h:201
vec6 m_Acc
Global to local Quaternion.
Definition: CIceFloe.h:206
int m_IStateOmega
Index of the local angular velocity in the state vector.
Definition: CIceFloe.h:193
mat6 m_AddedMass
Damping matrix.
Definition: CIceFloe.h:203
ISignalPort * m_pInForce
A pointer to the input force.
Definition: CIceFloe.h:177
double m_dragz
The drag coefficient z.
Definition: CIceFloe.h:199
virtual void OdeFcn(const double dT, const double *const adX, double *const adXDot, const bool bIsMajorTimeStep)
Calculates the state derivatives.
int m_IStatePos
Index of the global position in the state vector.
Definition: CIceFloe.h:190
double m_rA33
Acceleration.
Definition: CIceFloe.h:207
mat6 m_DampMatrix
The contact force.
Definition: CIceFloe.h:202
double m_dragxy
The drag coefficient xy.
Definition: CIceFloe.h:198
int m_IStateLocalVel
Index of the local velocity in the state vector.
Definition: CIceFloe.h:192
static mat6 ReorientInertiaTranslateRotate(const mat6 &Inertia, const vec6 &orientation)
Testing parameters.
int m_tmesh
Mesh size to thickness ratio.
Definition: CIceFloe.h:212
double m_A33
Added mass matrix.
Definition: CIceFloe.h:204
ISignalPort * m_pInMoment
A pointer to the input moment.
Definition: CIceFloe.h:176
int m_IStateQuater
Index of the quaternions in the state vector.
Definition: CIceFloe.h:191
Definition: CIceFloe.h:120
int * indexE
Number of triangles in object.
Definition: CIceFloe.h:124
int numT
Number of edges in object.
Definition: CIceFloe.h:122
int * indexT
Index of edges in AABB.
Definition: CIceFloe.h:125
Definition: CIceFloe.h:130
double * normT
Index of triangles in object.
Definition: CIceFloe.h:136
int * indexT
Coordinate of points in object.
Definition: CIceFloe.h:135
int numT
Number of points in object.
Definition: CIceFloe.h:132
double * xyzP
Number of triangles in object.
Definition: CIceFloe.h:134
Definition: CIceFloe.h:51
Definition: CIceFloe.h:253