FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
WaveHull.h
1#ifndef WaveHull_H
2#define WaveHull_H
3
236#include <array>
237#include <fhsim/simobject/SimObject.h>
238#include <fhsim_environment/EnvironmentProvider.h>
239#include <string>
240#include <vector>
241
242class WaveHull : public SimObject
243{
244public:
246 using Dof = std::array<double, 3>;
248 using Loads = std::array<double, 6>;
249
250 WaveHull(std::string simObjectName, ISimObjectCreator* creator);
251
252 void FinalSetup(double T, const double* X, ISimObjectCreator* creator) override;
253
254 void OdeFcn(double T, const double* X, double* XDot) const override;
255
256 bool HasJacobians() const override { return true; }
257 void OdeJacobian(double T, const double* X, double* J, int nStates) override;
258 int GetJacobianSparsity(int /*nStates*/, int* /*rowPtr*/, int* /*colIdx*/) override { return -1; }
259
260#ifdef FH_VISUALIZATION
262 void RenderInit(Ogre::Root* ogreRoot, ISimObjectCreator* creator) override;
263 void RenderUpdate(double T, const double* X) override;
264#endif
265
267 Dof RawWaveLoads(double T, const double* pose) const;
268
269 const double* MotionPort(double T, const double* X);
270 const double* MotionRatePort(double T, const double* X);
271 const double* ExcitationPort(double T, const double* X);
272 const double* VelocityPort(double T, const double* X);
273 const double* PositionPort(double T, const double* X);
274 const double* RotationPort(double T, const double* X);
275
276protected:
280 virtual Loads ExtraLoads(double /*T*/, const double* /*X*/, const Dof& /*velocity*/) const { return {}; }
281
285 virtual std::array<Dof, 6> ExtraLoadsVelocityJacobian(const Dof& /*velocity*/) const { return {}; }
286
291 virtual std::array<double, 3> WaterVelocity(double /*T*/, const double* /*X*/) const { return {0.0, 0.0, 0.0}; }
292
294 virtual std::array<double, 3> HeldWaterVelocity() const { return {0.0, 0.0, 0.0}; }
295
297 static Dof InBodyFrame(const std::array<double, 3>& water, double psi);
298
300 Dof VelocityThroughWater(double T, const double* X) const;
301
303 Dof HullDamping(const Dof& velocity) const;
304
305 double Length() const { return m_length; }
306 double Breadth() const { return m_breadth; }
307 double Lcf() const { return m_lcf; }
308 double Draught() const { return m_draught; }
309 double Rho() const { return m_rho; }
310 int MotionIndex() const { return m_indexMotion; }
311 int RateIndex() const { return m_indexRate; }
312 int PoseIndex() const { return m_indexPose; }
313 int VelocityIndex() const { return m_indexVelocity; }
314
315private:
317 struct SamplePoint
318 {
319 double x;
320 double y;
321 };
322
323 void BuildFootprint(double length, double breadth, double lcf, int sampleLevel);
324 double RotationalStiffness(ISimObjectCreator* creator, const std::string& gmName, const std::string& periodName,
325 double mass, double inertia) const;
326
328 Dof VerticalAccelerations(const double* motion, const double* rate, const Dof& load) const;
330 Dof HorizontalAccelerations(const double* velocity, const Dof& load) const;
331
332
333 environment::EnvironmentProvider* m_environment = nullptr;
334
335 int m_indexMotion = 0;
336 int m_indexRate = 0;
337 int m_indexExcitation = 0;
338 int m_indexPose = 0;
339 int m_indexVelocity = 0;
340
341 double m_rho = 0.0;
342 double m_waterplaneArea = 0.0;
343 double m_filterTime = 0.0;
344 double m_rollQuadraticDamping = 0.0;
345
346 Dof m_inertia {};
347 Dof m_stiffness {};
348 Dof m_damping {};
349 double m_a35 = 0.0;
350 double m_b35 = 0.0;
351 double m_c35 = 0.0;
352
353 double m_mass = 0.0;
354 double m_a11 = 0.0;
355 double m_a22 = 0.0;
356 Dof m_horizontalInertia {};
357 Dof m_horizontalLinearDamping {};
358 Dof m_horizontalQuadraticDamping {};
359
360 std::vector<SamplePoint> m_samples;
361 double m_sampleWeight = 0.0;
362
363 std::array<double, 3> m_positionOut {};
364 std::array<double, 3> m_rotationOut {};
365
366 double m_length = 0.0;
367 double m_breadth = 0.0;
368 double m_lcf = 0.0;
369 double m_draught = 0.0;
370
371#ifdef FH_VISUALIZATION
372 Ogre::SceneNode* m_renderNode = nullptr;
373#endif
374};
375
376#endif
Definition WaveHull.h:243
virtual Loads ExtraLoads(double, const double *, const Dof &) const
Definition WaveHull.h:280
virtual std::array< double, 3 > HeldWaterVelocity() const
The water velocity of the step [m/s], NED, which OdeJacobian holds fixed. The base: still water.
Definition WaveHull.h:294
Dof VelocityThroughWater(double T, const double *X) const
(u, v, r) through the water at time T for the model-global state X.
std::array< double, 3 > Dof
Three generalized loads or coordinates: (heave, roll, pitch) or (surge, sway, yaw).
Definition WaveHull.h:246
static Dof InBodyFrame(const std::array< double, 3 > &water, double psi)
The water velocity water (NED) in the body frame of heading psi: (u_c, v_c, 0).
std::array< double, 6 > Loads
Generalized loads on the six modes, ordered surge, sway, heave, roll, pitch, yaw [N,...
Definition WaveHull.h:248
virtual std::array< double, 3 > WaterVelocity(double, const double *) const
Definition WaveHull.h:291
Dof RawWaveLoads(double T, const double *pose) const
Unfiltered wave loads (Fz, Mphi, Mtheta) at time T for the hull at pose (N, E, psi).
virtual std::array< Dof, 6 > ExtraLoadsVelocityJacobian(const Dof &) const
Definition WaveHull.h:285
Dof HullDamping(const Dof &velocity) const
The hull's damping X(u), Y(v), N(r) at the velocity through the water velocity (u,...