13#ifndef CInternalCable_H
14#define CInternalCable_H
17#include <marenv/marenv.h>
18#include "cable/subroutines/CableElDynStiff.h"
20#include "sfh/constants.h"
21#include "sfh/linalg.h"
22#include "sfh/math/array.h"
23#include "sfh/math/math.h"
24#include "sfh/timers/StopWatch.h"
26#include <fhsim/simobject/SimObject.h>
27#include <fhsim_environment/EnvironmentProvider.h>
28#include <fhsim_environment/ElementFlowInteraction.h>
41inline constexpr int kNumElements = 2;
53inline constexpr const char* kMaterialName =
"Trawl/SteelWire";
66 double numericalDamping;
73 double stepSafetyFactor;
75 double eAdaptationPeriod;
76 std::string materialName;
78 std::string cableName;
89 numElements = cable_defaults::kNumElements;
101 materialName = cable_defaults::kMaterialName;
109 return sfh::pi * 0.25 * diameter * diameter * dE;
122 double* adFacePosNormal;
123 double* adTextureCoordU;
124 double* adTextureCoordV;
136 drawDiam = drawDiameter;
137 numRenderEdges = numFaces + 1;
138 sizeIndexBuffer = numElements * numRenderEdges * 2;
139 textureScale = 5 * (sfh::pi * drawDiam);
140 aiIndex =
new int[sizeIndexBuffer];
141 deltaTheta = 2 * sfh::pi / numFaces;
142 adTheta =
new double[numRenderEdges];
143 adSinTheta =
new double[numRenderEdges];
144 adCosTheta =
new double[numRenderEdges];
145 adCirclePos =
new double[(numElements + 1) * (numRenderEdges) * 3];
146 adFacePosNormal =
new double[(numElements + 1) * (numRenderEdges) * 3];
147 adTextureCoordU =
new double[numRenderEdges];
148 adTextureCoordV =
new double[numElements + 1];
149 adTextureCoordV[0] = 0;
150 for (
unsigned short i = 0; i < numRenderEdges; i++) {
151 adTheta[i] = i * deltaTheta;
152 adSinTheta[i] = sin(adTheta[i]);
153 adCosTheta[i] = cos(adTheta[i]);
154 adTextureCoordU[i] = adTheta[i] * (sfh::pi * drawDiam) / textureScale;
157 for (
int element = 0; element < numElements; element++) {
158 for (
int edge = 0; edge < numRenderEdges; edge++) {
159 aiIndex[i++] = element * numRenderEdges + edge;
160 aiIndex[i++] = (element + 1) * numRenderEdges + edge;
171 delete[] adCirclePos;
172 delete[] adFacePosNormal;
173 delete[] adTextureCoordU;
174 delete[] adTextureCoordV;
183 void Update(
int element,
const double* adElPosA,
const double* adElPosB,
const double* adDirection,
double dL0)
186 sfh::math::FindNotParallel(adDirection, 3, adNotParallel);
189 sfh::linalg::Cross(adDirection, adNotParallel, adNormal1);
190 sfh::linalg::Cross(adDirection, adNormal1, adNormal2);
191 sfh::math::Normalize3(adNormal1);
192 sfh::math::Normalize3(adNormal2);
193 sfh::math::ArrayMultiply(adNormal1, drawDiam / 2.0, 3);
194 sfh::math::ArrayMultiply(adNormal2, drawDiam / 2.0, 3);
195 adTextureCoordV[element + 1] = adTextureCoordV[element] + dL0 / textureScale * 3;
197 for (
unsigned short face = 0; face < numRenderEdges; face++) {
198 for (
unsigned short ind = 0; ind < 3; ind++) {
200 adFacePosNormal[element * ((numRenderEdges) * 3) + 3 * face + ind] = adSinTheta[face] * adNormal1[ind] + adCosTheta[face] * adNormal2[ind];
201 adCirclePos[element * ((numRenderEdges) * 3) + 3 * face + ind] = adElPosA[ind] + adFacePosNormal[element * ((numRenderEdges) * 3) + 3 * face + ind];
203 adFacePosNormal[(element + 1) * ((numRenderEdges) * 3) + 3 * face + ind] = adSinTheta[face] * adNormal1[ind] + adCosTheta[face] * adNormal2[ind];
204 adCirclePos[(element + 1) * ((numRenderEdges) * 3) + 3 * face + ind] = adElPosB[ind] + adFacePosNormal[(element + 1) * ((numRenderEdges) * 3) + 3 * face + ind];
211 double adNotParallel[3];
227 virtual void FinalSetup(
const double dT,
const double*
const adX, ISimObjectCreator*
const creator);
230 virtual void OdeFcn(
const double*
const adPosA,
231 const double*
const adVelA,
232 const double*
const adPosB,
233 const double*
const adVelB,
234 const double*
const adX,
235 double*
const adXDot,
252 void EvaluateElementsAt(
const double* adPosA,
const double* adVelA,
const double* adPosB,
const double* adVelB,
const double* adX,
double dT)
const;
263 const double* posA,
const double* velA,
264 const double* posB,
const double* velB,
265 const double* X,
double* J,
int nStates,
int stateOffset)
const;
287 const double* posA,
const double* velA,
288 const double* posB,
const double* velB,
289 int globalPosIdxA,
int globalVelIdxA,
290 int globalPosIdxB,
int globalVelIdxB,
291 double endInertiaA,
double endInertiaB,
292 const double* X,
double* J,
int nStates,
int stateOffset)
const;
296 const double*
const adVelA,
297 const double*
const adPosB,
298 const double*
const adVelB,
327 void TakeWakes(
const double* adPosA,
const double* adPosB,
const double* adX,
double T);
331 double*
const adEndForceA,
332 double*
const adEndForceB,
333 double*
const pdEndInertiaA,
334 double*
const pdEndInertiaB,
335 const double*
const adPosA,
336 const double*
const adVelA,
337 const double*
const adPosB,
338 const double*
const adVelB,
339 const double*
const adX,
345#ifdef FH_VISUALIZATION
347 void RenderInit(Ogre::Root* ogreRoot);
350 void RenderUpdate(
const double*
const adX,
const double* adPosA,
const double* adPosB);
357 void ResetAllNodeForces()
const;
360 void AddAllElementForces(
const double*
const adPosA,
361 const double*
const adVelA,
362 const double*
const adPosB,
363 const double*
const adVelB,
364 const double*
const adX,
368 void CalcDerivatives(
const double*
const adX,
369 double*
const adXDot)
const;
372 virtual void AddElementForce(
int cableElement,
373 const double adPosA[3],
374 const double adVelA[3],
375 const double adPosB[3],
376 const double adVelB[3],
386 virtual void AddNodeForce(
const double [3],
const double [3],
double [3])
const { }
398 const double posA[3],
const double velA[3],
const double posB[3],
const double velB[3],
399 const double waterVel[3],
double forceA[3],
double forceB[3])
const;
409 const double* posA,
const double* velA,
410 const double* posB,
const double* velB,
411 const double* X,
double dFA_dposB[9],
double dFA_dvelA[9])
const;
425 environment::wake::ElementFlowInteraction
m_flow;
427 double m_elVelWater[3];
428 double m_elMeanPos[3];
429 double m_elMeanVel[3];
431#ifdef FH_VISUALIZATION
433 Ogre::Root* m_ogreRoot;
434 Ogre::SceneManager* m_sceneMgr;
435 Ogre::Entity* m_renderElement;
436 Ogre::SceneNode* m_renderNode;
437 Ogre::ManualObject* m_cableRenderObj;
440 Ogre::Entity* m_renderSphere[2];
441 Ogre::SceneNode* m_renderNodeSphere[2];
446 mutable bool m_forceOutsideJacobian =
false;
Class containing a cable element object which is adapted to the required max step size.
Definition CableElDynStiff.h:30
Definition InternalCable.h:218
virtual ~InternalCable()
The destructor deletes dynamically allocated memory.
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:418
double ** m_aadForceB
The force on the B nodes.
Definition InternalCable.h:423
void EvaluateElementsAt(const double *adPosA, const double *adVelA, const double *adPosB, const double *adVelB, const double *adX, double dT) const
virtual void AddNodeForce(const double[3], const double[3], double[3]) const
Definition InternalCable.h:386
double ** m_aadForceA
The force on the A nodes.
Definition InternalCable.h:422
bool HasForceOutsideJacobian() const
Definition InternalCable.h:240
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
void MarkForceOutsideJacobian() const
Definition InternalCable.h:390
void AddBareElementForce(int cableElement, const double posA[3], const double velA[3], const double posB[3], const double velB[3], const double waterVel[3], double forceA[3], double forceB[3]) const
unsigned long m_numNodes
The number of nodes of the cable.
Definition InternalCable.h:354
void TakeWakes(const double *adPosA, const double *adPosB, const double *adX, double T)
SCableSpec m_CableSpec
The cable specification.
Definition InternalCable.h:417
environment::wake::ElementFlowInteraction m_flow
The flow at the element midpoints, the other objects' wakes taken per step (MARE-0223); the Environme...
Definition InternalCable.h:425
double m_meanTensionTime
The time of the last AdvanceMeanTension.
Definition InternalCable.h:419
double NodeInertia(unsigned long node) const
double EndInertia(int end) const
unsigned long * m_iStatePos
An array of indices to the node position states.
Definition InternalCable.h:413
environment::EnvironmentProvider * m_environment
m_flow's Environment, from FinalSetup; null before it and without one (fhsim_fishery's tests set it b...
Definition InternalCable.h:426
CableElDynStiff ** m_cableElements
An array holding the cable elements.
Definition InternalCable.h:421
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.
bool SegmentEndBlocks(unsigned long segment, const double *posA, const double *velA, const double *posB, const double *velB, const double *X, double dFA_dposB[9], double dFA_dvelA[9]) const
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...
unsigned long m_numElements
The number of elements to divide the cable into.
Definition InternalCable.h:353
double GetLength()
Calculates the length of the cable.
void UpdateCable(double newLength)
Sets the unstretched length of the cable, divided equally between its elements.
unsigned long * m_iStateVel
An array of indices to the node velocity states.
Definition InternalCable.h:414
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.
void AdvanceMeanTension(const double *adPosA, const double *adPosB, const double *adX, double T)
InternalCable(ISimObjectCreator *creator, const SCableSpec &CableSpec)
The constructor sets the pointer to the output object and the parser object.
Definition InternalCable.h:40
constexpr double kMaxLengthChangeSpeed
Cable/Branched: how fast the cables may change length [m/s].
Definition InternalCable.h:57
constexpr double kDrawScale
The visual scale of the cable.
Definition InternalCable.h:56
constexpr double kMaxTension
The maximum tension in the cable [N].
Definition InternalCable.h:49
constexpr int kNumFaces
The visual number of faces of Cable/LumpedMass.
Definition InternalCable.h:54
constexpr double kStepSafetyFactor
Read and checked, not used by the stiffness calculation.
Definition InternalCable.h:50
constexpr double kMeanTension
The mean tension of the cable [N].
Definition InternalCable.h:51
constexpr double kFluidRho
The density of the surrounding fluid [kg/m³].
Definition InternalCable.h:47
constexpr double kAdaptationPeriod
The time constant of the adaptation of the mean tension [s].
Definition InternalCable.h:52
constexpr double kYoungsModulus
The stiffness of the cable material [Pa].
Definition InternalCable.h:45
constexpr double kDampingRatio
The relative axial damping.
Definition InternalCable.h:46
constexpr int kBranchedNumFaces
The visual number of faces of Cable/Branched's General tag.
Definition InternalCable.h:55
constexpr double kDiameter
The diameter of the cable [m].
Definition InternalCable.h:44
constexpr double kDensity
The density of the cable material [kg/m³].
Definition InternalCable.h:42
constexpr double kNumericalDamping
Numerical damping rate [1/s]: a dashpot between the end nodes of each element, c = k m_e / 2 (owner r...
Definition InternalCable.h:43
constexpr double kMaxStepLength
The step the reduced stiffness is chosen for [s]; this small keeps the full stiffness.
Definition InternalCable.h:48
constexpr double seawaterDensity
Ocean water density [kg/m^3].
Definition marenv.h:20
Contains some specifications and methods used for rendering cables.
Definition InternalCable.h:115
SCableRenderSpec(int numFaces, int numElements, double drawDiameter)
Definition InternalCable.h:134
~SCableRenderSpec()
The destructor frees allocated memory.
Definition InternalCable.h:166
void Update(int element, const double *adElPosA, const double *adElPosB, const double *adDirection, double dL0)
Definition InternalCable.h:183
Contains some specifications used for simulating cables.
Definition InternalCable.h:63
void Reset()
Resets the specification to the defaults.
Definition InternalCable.h:87
double CalcEA()
Calculates the stiffness of the cable.
Definition InternalCable.h:107
SCableSpec()
The constructor sets some default values.
Definition InternalCable.h:82