FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
CablePendulum.h
1#pragma once
2
3#include "sfh/constants.h"
4#include "sfh/math.h"
5#include "sfh/text.h"
6#include "sfh/util.h"
7
8#include <Eigen/Dense>
9
10#include <fhsim/simobject/SimObject.h>
11#include <fhsim_environment/BodyFlowInteraction.h>
12#include <fhsim_environment/EnvironmentProvider.h>
13#include <fhsim_environment/ElementFlowInteraction.h>
14#include <fhsim_environment/hydrodynamics/SphereHydro.h>
15#include <optional>
16
17struct CableSegmentStructuralForces; // cable/CableSegmentStructuralJacobian.h
110class CablePendulum : public SimObject
111{
112 public:
113 CablePendulum(const std::string& simObjectName, ISimObjectCreator* const creator);
114 void OdeFcn(const double T, const double* const X, double* const XDot) const;
115 void InitialConditionSetup(const double T, const double* const currentIC, double* const updatedIC, ISimObjectCreator* const creator);
116 void FinalSetup(const double T, const double* const X, ISimObjectCreator* const creator);
118 void PreOdeFcn(double T, const double* X) override;
119
120#ifdef FH_VISUALIZATION
121 void RenderInit(Ogre::Root* const ogreRoot, ISimObjectCreator* const creator);
122 void RenderUpdate(const double T, const double* const X);
123#endif
124
125 protected:
126 void SetOutputPortValues(const double T, const double* const X) const;
127 const double* MidpointPosition(const double T, const double* const X);
128 const double* BallPosition(const double T, const double* const X);
129 const double* BallVelocity(const double T, const double* const X);
131 const double* BallWaterVelocity(const double T, const double* const X);
133 void ballWaterVelocity(const double T, const double* X, double velocity[3]) const;
134
135 public:
136 bool HasJacobians() const override;
137 void OdeJacobian(double T, const double* X, double* J, int nStates) override;
138 int GetJacobianSparsity(int nStates, int* rowPtr, int* colIdx) override;
139
140 protected:
142 void addDragJacobian(const double T, int segment, const double* pk, const double* pl, const double* vk,
143 double dF_dpk[9], double dF_dpl[9], double dF_dvk[9]) const;
145 Eigen::Vector3d NodePosition(int k, const double T, const double* const X) const;
147 Eigen::Vector3d NodeVelocity(int k, const double T, const double* const X) const;
148 Eigen::Vector3d Drag(int k, int l, const double T, const double* const X) const;
150 void takeCableWakes(const double T, const double* X);
151 Eigen::Vector3d Spring(int k, int l, const double T, const double* const X) const;
152 Eigen::Vector3d Damp(int k, int l, const double T, const double* const X) const;
154 CableSegmentStructuralForces StructuralForce(int k, int l, const double T, const double* const X) const;
155 const double* SuspensionForce(const double T, const double* const X);
156 const double* CableOnBallForce(const double T, const double* const X);
157
158
159 ICommonComputation* m_SetOutputPortValues;
160 ISignalPort* m_SuspensionPos;
161 ISignalPort* m_SuspensionVel;
162
163 environment::EnvironmentProvider* Environment;
164 std::vector<int> m_PositionIndex, m_VelocityIndex;
165 int m_BallPositionIndex, m_BallVelocityIndex;
166 int m_stateBase = 0;
167 int m_NumPoints;
168 mutable double m_MidpointPosition[3];
169 mutable double m_BallPosition[3];
170 mutable double m_BallVelocity[3];
171 mutable double m_SuspensionForce[3];
172 mutable double m_CableOnBallForce[3];
173 double m_BallWaterVelocity[3] = {0.0, 0.0, 0.0};
174
175 environment::sphere_hydro::Sphere m_ballShape;
176 std::optional<environment::sphere_hydro::SphereCaster> m_ballCaster;
177 environment::wake::BodyFlowInteraction m_ballFlow;
178 std::optional<environment::wake::ElementFlowInteraction> m_cableFlow;
179
180 double m_BallMass, m_BallRadius, m_RhoWater, m_BallRho;
181 double m_ElementMass, m_ElementLength0;
182 double m_SpringCoef, m_DamperCoef, m_GravYancy;
183 double m_Mass, m_Length, m_Diameter, m_RhoCable, m_Modulus;
184
185#ifdef FH_VISUALIZATION
186 Ogre::ManualObject* m_Line;
187 Ogre::SceneNode* m_RenderNode;
188 std::string m_MaterialName;
189 std::string m_MeshName;
190 double m_Scale;
191#endif
192};
Definition CablePendulum.h:111
std::optional< environment::sphere_hydro::SphereCaster > m_ballCaster
The ball on its states, for the wake.
Definition CablePendulum.h:176
void ballWaterVelocity(const double T, const double *X, double velocity[3]) const
The water velocity at the ball: the BodyFlowInteraction's, without the ball's own wake.
Eigen::Vector3d NodeVelocity(int k, const double T, const double *const X) const
Velocity of node k, numbered as NodePosition.
void PreOdeFcn(double T, const double *X) override
Rebuilds the ball's wake when due and takes the other objects' wakes at the ball.
const double * BallWaterVelocity(const double T, const double *const X)
Output port BallWaterVelocity [m/s], NED.
environment::sphere_hydro::Sphere m_ballShape
ρ, D = 2 R and C_d of the ball's drag.
Definition CablePendulum.h:175
Eigen::Vector3d NodePosition(int k, const double T, const double *const X) const
Position of node k: 0 is end A, 1..n are the cable's states, n+1 is end B.
environment::wake::BodyFlowInteraction m_ballFlow
The wake the ball casts and receives.
Definition CablePendulum.h:177
void takeCableWakes(const double T, const double *X)
Takes the other objects' wakes at the segment midpoints of X for the step (MARE-0223); from PreOdeFcn...
void addDragJacobian(const double T, int segment, const double *pk, const double *pl, const double *vk, double dF_dpk[9], double dF_dpl[9], double dF_dvk[9]) const
Adds the derivatives of Drag(k,l), the force on node k, to the blocks SetCableSegmentStructuralJacobi...
std::optional< environment::wake::ElementFlowInteraction > m_cableFlow
The flow at the segment midpoints, the other objects' wakes taken per step, received as the ball (MAR...
Definition CablePendulum.h:178
CableSegmentStructuralForces StructuralForce(int k, int l, const double T, const double *const X) const
Spring and Damp of the segment k-l with one evaluation of the law.
int m_stateBase
Global index of this object's first state; cached in the constructor.
Definition CablePendulum.h:166
The spring force and the damper force on node k of a segment k-l, each along the segment (towards l w...
Definition CableSegmentStructuralJacobian.h:9