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/BodyWake.h>
12#include <fhsim_environment/EnvironmentProvider.h>
13#include <fhsim_environment/hydrodynamics/SphereHydro.h>
14#include <memory>
15#include <optional>
105class CablePendulum : public SimObject
106{
107 public:
108 CablePendulum(const std::string& simObjectName, ISimObjectCreator* const creator);
109 void OdeFcn(const double T, const double* const X, double* const XDot) const;
110 void InitialConditionSetup(const double T, const double* const currentIC, double* const updatedIC, ISimObjectCreator* const creator);
111 void FinalSetup(const double T, const double* const X, ISimObjectCreator* const creator);
113 void PreOdeFcn(double T, const double* X, IStateUpdater* updater) override;
114
115#ifdef FH_VISUALIZATION
116 void RenderInit(Ogre::Root* const ogreRoot, ISimObjectCreator* const creator);
117 void RenderUpdate(const double T, const double* const X);
118#endif
119
120 protected:
121 void SetOutputPortValues(const double T, const double* const X) const;
122 const double* MidpointPosition(const double T, const double* const X);
123 const double* BallPosition(const double T, const double* const X);
124 const double* BallVelocity(const double T, const double* const X);
126 const double* BallWaterVelocity(const double T, const double* const X);
128 void ballWaterVelocity(const double T, const double* X, double velocity[3]) const;
129
130 public:
131 bool HasJacobians() const override;
132 void OdeJacobian(double T, const double* X, double* J, int nStates) override;
133 int GetJacobianSparsity(int nStates, int* rowPtr, int* colIdx) override;
134
135 protected:
137 void addDragJacobian(const double T, const double* pk, const double* pl, const double* vk,
138 double dF_dpk[9], double dF_dpl[9], double dF_dvk[9]) const;
139 Eigen::Vector3d Drag(int k, int l, const double T, const double* const X) const;
140 Eigen::Vector3d Spring(int k, int l, const double T, const double* const X) const;
141 Eigen::Vector3d Damp(int k, int l, const double T, const double* const X) const;
142 const double* SuspensionForce(const double T, const double* const X);
143 const double* CableOnBallForce(const double T, const double* const X);
144
145
146 ICommonComputation* m_SetOutputPortValues;
147 ISignalPort* m_SuspensionPos;
148 ISignalPort* m_SuspensionVel;
149
150 environment::EnvironmentProvider* Environment;
151 std::vector<int> m_PositionIndex, m_VelocityIndex;
152 int m_BallPositionIndex, m_BallVelocityIndex;
153 int m_stateBase = 0;
154 int m_NumPoints;
155 mutable double m_MidpointPosition[3];
156 mutable double m_BallPosition[3];
157 mutable double m_BallVelocity[3];
158 mutable double m_SuspensionForce[3];
159 mutable double m_CableOnBallForce[3];
160 double m_BallWaterVelocity[3] = {0.0, 0.0, 0.0};
161
162 environment::sphere_hydro::Sphere m_ballShape;
163 std::optional<environment::sphere_hydro::SphereCaster> m_ballCaster;
164 environment::wake::BodyWakeSettings m_wakeSettings;
165 std::unique_ptr<environment::wake::BodyWake> m_ballWake;
166
167 double m_BallMass, m_BallRadius, m_RhoWater, m_BallRho;
168 double m_ElementMass, m_ElementLength0;
169 double m_SpringCoef, m_DamperCoef, m_GravYancy;
170 double m_Mass, m_Length, m_Diameter, m_RhoCable, m_Modulus;
171
172#ifdef FH_VISUALIZATION
173 Ogre::ManualObject* m_Line;
174 Ogre::SceneNode* m_RenderNode;
175 std::string m_MaterialName;
176 std::string m_MeshName;
177 double m_Scale;
178#endif
179};
Definition CablePendulum.h:106
environment::wake::BodyWakeSettings m_wakeSettings
The wake parameters.
Definition CablePendulum.h:164
std::optional< environment::sphere_hydro::SphereCaster > m_ballCaster
The ball on its states, for the wake.
Definition CablePendulum.h:163
void ballWaterVelocity(const double T, const double *X, double velocity[3]) const
The water velocity at the ball: the BodyWake'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:162
std::unique_ptr< environment::wake::BodyWake > m_ballWake
The wake the ball casts and receives, from FinalSetup.
Definition CablePendulum.h:165
void addDragJacobian(const double T, 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...
int m_stateBase
Global index of this object's first state; cached in the constructor.
Definition CablePendulum.h:153