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, IStateUpdater* updater) 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;
144 Eigen::Vector3d Drag(int k, int l, const double T, const double* const X) const;
146 void takeCableWakes(const double T, const double* X);
147 Eigen::Vector3d Spring(int k, int l, const double T, const double* const X) const;
148 Eigen::Vector3d Damp(int k, int l, const double T, const double* const X) const;
150 CableSegmentStructuralForces StructuralForce(int k, int l, const double T, const double* const X) const;
151 const double* SuspensionForce(const double T, const double* const X);
152 const double* CableOnBallForce(const double T, const double* const X);
153
154
155 ICommonComputation* m_SetOutputPortValues;
156 ISignalPort* m_SuspensionPos;
157 ISignalPort* m_SuspensionVel;
158
159 environment::EnvironmentProvider* Environment;
160 std::vector<int> m_PositionIndex, m_VelocityIndex;
161 int m_BallPositionIndex, m_BallVelocityIndex;
162 int m_stateBase = 0;
163 int m_NumPoints;
164 mutable double m_MidpointPosition[3];
165 mutable double m_BallPosition[3];
166 mutable double m_BallVelocity[3];
167 mutable double m_SuspensionForce[3];
168 mutable double m_CableOnBallForce[3];
169 double m_BallWaterVelocity[3] = {0.0, 0.0, 0.0};
170
171 environment::sphere_hydro::Sphere m_ballShape;
172 std::optional<environment::sphere_hydro::SphereCaster> m_ballCaster;
173 environment::wake::BodyFlowInteraction m_ballFlow;
174 std::optional<environment::wake::ElementFlowInteraction> m_cableFlow;
175
176 double m_BallMass, m_BallRadius, m_RhoWater, m_BallRho;
177 double m_ElementMass, m_ElementLength0;
178 double m_SpringCoef, m_DamperCoef, m_GravYancy;
179 double m_Mass, m_Length, m_Diameter, m_RhoCable, m_Modulus;
180
181#ifdef FH_VISUALIZATION
182 Ogre::ManualObject* m_Line;
183 Ogre::SceneNode* m_RenderNode;
184 std::string m_MaterialName;
185 std::string m_MeshName;
186 double m_Scale;
187#endif
188};
Definition CablePendulum.h:111
std::optional< environment::sphere_hydro::SphereCaster > m_ballCaster
The ball on its states, for the wake.
Definition CablePendulum.h:172
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.
void PreOdeFcn(double T, const double *X, IStateUpdater *updater) 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:171
environment::wake::BodyFlowInteraction m_ballFlow
The wake the ball casts and receives.
Definition CablePendulum.h:173
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:174
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:162
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