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/EnvironmentProvider.h>
12#include <memory>
85class CablePendulum : public SimObject
86{
87 public:
88 CablePendulum(const std::string& simObjectName, ISimObjectCreator* const creator);
89 void OdeFcn(const double T, const double* const X, double* const XDot) const;
90 void InitialConditionSetup(const double T, const double* const currentIC, double* const updatedIC, ISimObjectCreator* const creator);
91 void FinalSetup(const double T, const double* const X, ISimObjectCreator* const creator);
92
93#ifdef FH_VISUALIZATION
94 void RenderInit(Ogre::Root* const ogreRoot, ISimObjectCreator* const creator);
95 void RenderUpdate(const double T, const double* const X);
96#endif
97
98 protected:
99 void SetOutputPortValues(const double T, const double* const X) const;
100 const double* MidpointPosition(const double T, const double* const X);
101 const double* BallPosition(const double T, const double* const X);
102 const double* BallVelocity(const double T, const double* const X);
103
104 public:
105 bool HasJacobians() const override;
106 void OdeJacobian(double T, const double* X, double* J, int nStates) override;
107 int GetJacobianSparsity(int nStates, int* rowPtr, int* colIdx) override;
108
109 protected:
115 void segmentJacobian(const double* pk, const double* pl,
116 const double* vk, const double* vl,
117 double dF_dpk[9], double dF_dpl[9],
118 double dF_dvk[9], double dF_dvl[9]) const;
119
121 void addDragJacobian(const double T, const double* pk, const double* pl, const double* vk,
122 double dragFactor, double dF_dpk[9], double dF_dpl[9], double dF_dvk[9]) const;
123 Eigen::Vector3d Drag(int k, int l, const double T, const double* const X) const;
124 Eigen::Vector3d Spring(int k, int l, const double T, const double* const X) const;
125 Eigen::Vector3d Damp(int k, int l, const double T, const double* const X) const;
126 const double* SuspensionForce(const double T, const double* const X);
127 const double* CableOnBallForce(const double T, const double* const X);
128
129
130 ICommonComputation* m_SetOutputPortValues;
131 ISignalPort* m_SuspensionPos;
132 ISignalPort* m_SuspensionVel;
133
134 environment::EnvironmentProvider* Environment;
135 std::vector<int> m_PositionIndex, m_VelocityIndex;
136 int m_BallPositionIndex, m_BallVelocityIndex;
137 int m_stateBase = 0;
138
146 int LocalIndex(int globalStateIndex) const { return globalStateIndex - m_stateBase; }
147 int m_NumPoints;
148 mutable double m_MidpointPosition[3];
149 mutable double m_BallPosition[3];
150 mutable double m_BallVelocity[3];
151 mutable double m_SuspensionForce[3];
152 mutable double m_CableOnBallForce[3];
153
154 double m_BallMass, m_BallRadius, m_BallDragCoef, m_RhoWater, m_BallRho;
155 double m_ElementMass, m_ElementLength0;
156 double m_SpringCoef, m_DamperCoef, m_GravYancy;
157 double m_CrossDragCoef, m_AlongDragCoef;
158 double m_Mass, m_Length, m_Diameter, m_RhoCable, m_Modulus;
159
160#ifdef FH_VISUALIZATION
161 Ogre::ManualObject* m_Line;
162 Ogre::SceneNode* m_RenderNode;
163 std::string m_MaterialName;
164 std::string m_MeshName;
165 double m_Scale;
166#endif
167};
Definition CablePendulum.h:86
void addDragJacobian(const double T, const double *pk, const double *pl, const double *vk, double dragFactor, 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 segmentJacobian filled.
void segmentJacobian(const double *pk, const double *pl, const double *vk, const double *vl, double dF_dpk[9], double dF_dpl[9], double dF_dvk[9], double dF_dvl[9]) const
int LocalIndex(int globalStateIndex) const
Definition CablePendulum.h:146
int m_stateBase
Global index of this object's first state; cached in the constructor.
Definition CablePendulum.h:137