FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
InternalCable.h
1
10
11#ifndef CInternalCable_H
12#define CInternalCable_H
13
14// Includes
15#include "cable/subroutines/CableElDynStiff.h"
16
17#include "sfh/constants.h"
18#include "sfh/linalg.h"
19#include "sfh/math/array.h"
20#include "sfh/math/math.h"
21#include "sfh/timers/StopWatch.h"
22
23#include <fhsim/simobject/SimObject.h>
24#include <fhsim_environment/EnvironmentProvider.h>
25#include <string>
26
27
28#define ATTACH_SPHERE
29
30
33{
34 int numElements;
35 double density;
36 double numericalDamping;
37 double diameter;
38 double dE;
39 double dampingRatio;
40 double fluidRho;
41 double maxStep;
42 double maxTension;
43 double maxAcceleration;
44 double stepSafetyFactor;
45 double dMeanTension0;
46 double eAdaptationPeriod;
47 std::string materialName;
48 int cableFaces;
49 std::string cableName;
50 double drawScale;
51
54 {
55 Reset();
56 }
58 void Reset()
59 {
60 numElements = 2;
61 density = 1100;
62 numericalDamping = 1;
63 diameter = 0.01;
64 dE = 1e9;
65 dampingRatio = 1;
66 fluidRho = 1025;
67 maxStep = 1e-10;
68 maxTension = 1e10;
69 maxAcceleration = 1e10;
70 stepSafetyFactor = 50;
71 dMeanTension0 = 0;
72 eAdaptationPeriod = 0;
73 materialName = "Trawl/SteelWire";
74 cableFaces = 5;
75 cableName = "";
76 drawScale = 1;
77 }
79 double CalcEA()
80 {
81 return sfh::pi * 0.25 * diameter * diameter * dE;
82 }
83};
84
87{
88 double deltaTheta;
89 double* adTheta;
90 double* adSinTheta;
91 double* adCosTheta;
92 double textureScale;
93 double* adCirclePos;
94 double* adFacePosNormal;
95 double* adTextureCoordU;
96 double* adTextureCoordV;
97 int numRenderEdges;
98 double drawDiam;
99 int* aiIndex;
100 int sizeIndexBuffer;
101
106 SCableRenderSpec(int numFaces, int numElements, double drawDiameter)
107 {
108 drawDiam = drawDiameter;
109 numRenderEdges = numFaces + 1;
110 sizeIndexBuffer = numElements * numRenderEdges * 2;
111 textureScale = 5 * (sfh::pi * drawDiam);
112 aiIndex = new int[sizeIndexBuffer];
113 deltaTheta = 2 * sfh::pi / numFaces;
114 adTheta = new double[numRenderEdges];
115 adSinTheta = new double[numRenderEdges];
116 adCosTheta = new double[numRenderEdges];
117 adCirclePos = new double[(numElements + 1) * (numRenderEdges) * 3];
118 adFacePosNormal = new double[(numElements + 1) * (numRenderEdges) * 3];
119 adTextureCoordU = new double[numRenderEdges];
120 adTextureCoordV = new double[numElements + 1];
121 adTextureCoordV[0] = 0;
122 for (unsigned short i = 0; i < numRenderEdges; i++) {
123 adTheta[i] = i * deltaTheta;
124 adSinTheta[i] = sin(adTheta[i]);
125 adCosTheta[i] = cos(adTheta[i]);
126 adTextureCoordU[i] = adTheta[i] * (sfh::pi * drawDiam) / textureScale;
127 }
128 int i = 0;
129 for (int element = 0; element < numElements; element++) {
130 for (int edge = 0; edge < numRenderEdges; edge++) {
131 aiIndex[i++] = element * numRenderEdges + edge;
132 aiIndex[i++] = (element + 1) * numRenderEdges + edge;
133 }
134 }
135 }
136
139 {
140 delete[] adTheta;
141 delete[] adSinTheta;
142 delete[] adCosTheta;
143 delete[] adCirclePos;
144 delete[] adFacePosNormal;
145 delete[] adTextureCoordU;
146 delete[] adTextureCoordV;
147 }
148
155 void Update(int element, const double* adElPosA, const double* adElPosB, const double* adDirection, double dL0)
156 {
157 // Creating a vector not parallel to the direction of the element.
158 sfh::math::FindNotParallel(adDirection, 3, adNotParallel);
159
160 // Creating two vectors normal to each other and the direction of the element.
161 sfh::linalg::Cross(adDirection, adNotParallel, adNormal1);
162 sfh::linalg::Cross(adDirection, adNormal1, adNormal2);
163 sfh::math::Normalize3(adNormal1);
164 sfh::math::Normalize3(adNormal2);
165 sfh::math::ArrayMultiply(adNormal1, drawDiam / 2.0, 3);
166 sfh::math::ArrayMultiply(adNormal2, drawDiam / 2.0, 3);
167 adTextureCoordV[element + 1] = adTextureCoordV[element] + dL0 / textureScale * 3;
168
169 for (unsigned short face = 0; face < numRenderEdges; face++) {
170 for (unsigned short ind = 0; ind < 3; ind++) {
171 if (element == 0) {
172 adFacePosNormal[element * ((numRenderEdges) * 3) + 3 * face + ind] = adSinTheta[face] * adNormal1[ind] + adCosTheta[face] * adNormal2[ind];
173 adCirclePos[element * ((numRenderEdges) * 3) + 3 * face + ind] = adElPosA[ind] + adFacePosNormal[element * ((numRenderEdges) * 3) + 3 * face + ind];
174 }
175 adFacePosNormal[(element + 1) * ((numRenderEdges) * 3) + 3 * face + ind] = adSinTheta[face] * adNormal1[ind] + adCosTheta[face] * adNormal2[ind];
176 adCirclePos[(element + 1) * ((numRenderEdges) * 3) + 3 * face + ind] = adElPosB[ind] + adFacePosNormal[(element + 1) * ((numRenderEdges) * 3) + 3 * face + ind];
177 }
178 }
179 }
180
181private:
182 // Varaiables to avoid excessive allocations
183 double adNotParallel[3];
184 double adNormal1[3];
185 double adNormal2[3];
186};
187
188// Class definition
190{
191public:
193 InternalCable(ISimObjectCreator* creator, const SCableSpec& CableSpec);
194
197
198 // Member functions
199 virtual void FinalSetup(const double dT, const double* const adX, ISimObjectCreator* const creator);
200
202 virtual void OdeFcn(const double* const adPosA,
203 const double* const adVelA,
204 const double* const adPosB,
205 const double* const adVelB,
206 const double* const adX,
207 double* const adXDot,
208 double dT) const;
209
215 const double* posA, const double* velA,
216 const double* posB, const double* velB,
217 const double* X, double* J, int nStates, int stateOffset) const;
218
231 const double* posA, const double* velA,
232 const double* posB, const double* velB,
233 int globalPosIdxA, int globalVelIdxA,
234 int globalPosIdxB, int globalVelIdxB,
235 double endInertiaA, double endInertiaB,
236 const double* X, double* J, int nStates, int stateOffset) const;
237
239 virtual bool InitializeStates(const double* const adPosA,
240 const double* const adVelA,
241 const double* const adPosB,
242 const double* const adVelB,
243 double* const adX);
244
246 void UpdateCable(double newLength, double dT);
247
250 double* const adEndForceA,
251 double* const adEndForceB,
252 double* const pdEndInertiaA,
253 double* const pdEndInertiaB,
254 const double* const adPosA,
255 const double* const adVelA,
256 const double* const adPosB,
257 const double* const adVelB,
258 const double* const adX,
259 double dT);
260
262 double GetLength();
263
264#ifdef FH_VISUALIZATION
266 void RenderInit(Ogre::Root* ogreRoot);
267
269 void RenderUpdate(const double* const adX, const double* adPosA, const double* adPosB);
270#endif
271
272 unsigned long m_numElements;
273 unsigned long m_numNodes;
274protected:
275 // Deletes all node forces.
276 void ResetAllNodeForces() const;
277
278 // Adds the forces from each cable element to the array of node forces.
279 void AddAllElementForces(const double* const adPosA,
280 const double* const adVelA,
281 const double* const adPosB,
282 const double* const adVelB,
283 const double* const adX,
284 double dT) const;
285
286 // Calculates the derivatives of the states of the cable.
287 void CalcDerivatives(const double* const adX,
288 double* const adXDot) const;
289
290 // Adds the forces from one element to the array of node forces.
291 virtual void AddElementForce(int cableElement,
292 const double adPosA[3],
293 const double adVelA[3],
294 const double adPosB[3],
295 const double adVelB[3],
296 double adForceA[3],
297 double adForceB[3],
298 double dT) const;
299
302
303 unsigned long* m_iStatePos;
304 unsigned long* m_iStateVel;
305
306 // Member variables
308 double m_eA;
309 sfh::timers::StopWatch m_StopWatch;
310
312 double* m_inertiaA;
313 double* m_inertiaB;
314 double** m_aadForceA;
315 double** m_aadForceB;
316
317 environment::EnvironmentProvider* m_environment;
318 double m_elVelWater[3];
319 double m_elMeanPos[3];
320 double m_elMeanVel[3];
321
322#ifdef FH_VISUALIZATION
323 SCableRenderSpec* m_renderSpec;
324 Ogre::Root* m_ogreRoot;
325 Ogre::SceneManager* m_sceneMgr;
326 Ogre::Entity* m_renderElement;
327 Ogre::SceneNode* m_renderNode;
328 Ogre::ManualObject* m_cableRenderObj;
329 double m_drawDiam;
330# ifdef ATTACH_SPHERE
331 Ogre::Entity* m_renderSphere[2];
332 Ogre::SceneNode* m_renderNodeSphere[2];
333# endif
334#endif
335};
336
337
338#endif
Definition CableElDynStiff.h:34
Definition InternalCable.h:190
void ComputeStructuralJacobian(const double *posA, const double *velA, const double *posB, const double *velB, const double *X, double *J, int nStates, int stateOffset) const
double m_eA
The stiffness of the cable.
Definition InternalCable.h:308
double ** m_aadForceB
The force on the B nodes.
Definition InternalCable.h:315
~InternalCable()
The destructor deletes dynamically allocated memory.
double ** m_aadForceA
The force on the A nodes.
Definition InternalCable.h:314
void AddEndpointJacobianContributions(const double *posA, const double *velA, const double *posB, const double *velB, int globalPosIdxA, int globalVelIdxA, int globalPosIdxB, int globalVelIdxB, double endInertiaA, double endInertiaB, const double *X, double *J, int nStates, int stateOffset) const
unsigned long m_numNodes
The number of nodes of the cable.
Definition InternalCable.h:273
SCableSpec m_CableSpec
The cable specification.
Definition InternalCable.h:307
void UpdateCable(double newLength, double dT)
Updates the cable for the next step.
double * m_inertiaB
The inertia of the B nodes.
Definition InternalCable.h:313
unsigned long * m_iStatePos
An array of indices to the node position states.
Definition InternalCable.h:303
CableElDynStiff ** m_cableElements
An array holding the cable elements.
Definition InternalCable.h:311
virtual void OdeFcn(const double *const adPosA, const double *const adVelA, const double *const adPosB, const double *const adVelB, const double *const adX, double *const adXDot, double dT) const
Calculates the state derivatives and the end forces.
virtual bool InitializeStates(const double *const adPosA, const double *const adVelA, const double *const adPosB, const double *const adVelB, double *const adX)
Method for setting initial conditions when the input is known, which may be implemented in the indivi...
double * m_inertiaA
The inertia of the A nodes.
Definition InternalCable.h:312
void UpdateInertia()
Updates the inertia of the cable according to the changing length.
unsigned long m_numElements
The number of elements to divide the cable into.
Definition InternalCable.h:272
double GetLength()
Calculates the length of the cable.
unsigned long * m_iStateVel
An array of indices to the node velocity states.
Definition InternalCable.h:304
void AddEndForcesAndInertia(double *const adEndForceA, double *const adEndForceB, double *const pdEndInertiaA, double *const pdEndInertiaB, const double *const adPosA, const double *const adVelA, const double *const adPosB, const double *const adVelB, const double *const adX, double dT)
Adds the end forces and inertia to the supplied data structures.
InternalCable(ISimObjectCreator *creator, const SCableSpec &CableSpec)
The constructor sets the pointer to the output object and the parser object.
Contains some specifications and methods used for rendering cables.
Definition InternalCable.h:87
SCableRenderSpec(int numFaces, int numElements, double drawDiameter)
Definition InternalCable.h:106
~SCableRenderSpec()
The destructor frees allocated memory.
Definition InternalCable.h:138
void Update(int element, const double *adElPosA, const double *adElPosB, const double *adDirection, double dL0)
Definition InternalCable.h:155
Contains some specifications used for simulating cables.
Definition InternalCable.h:33
void Reset()
Resets the specification to the defaults.
Definition InternalCable.h:58
double CalcEA()
Calculates the stiffness of the cable.
Definition InternalCable.h:79
SCableSpec()
The constructor sets some default values.
Definition InternalCable.h:53