Marine systems simulation
ShipSimObject.h
1#ifndef _CSHIP_SIM_OBJECT_H_
2#define _CSHIP_SIM_OBJECT_H_
3
179#include <ISimObjectCreator.h>
180#include <CFhSimMgr.h>
181#include <CPrintDuringExec.h>
182#include <string>
183#include <queue>
184#include <string>
185#include <iostream>
186#include <locale>
187
188#ifdef FH_VISUALIZATION
189#pragma warning(push)
190#pragma warning( disable : 4251 )
191 #include <ois/OIS.h>
192 #include <Ogre.h>
193 #include <CInputManager.h>
194#pragma warning(pop)
195 //#include <CFhVis.h>
196 #include "sfh/ogre/C3DArrow.h"
197 #include "sfh/ogre/DotSceneLoader.h"
198#endif
199
200#include <environment/DeepSeaGravityWaves.h>
201
202#include <sfh/math/interpolation/SplineInterp.h>
203
204// TODO: this will not work if someone inherits the simobject externally
205#include "Ship/Resistance/ShipResistance.h"
206#include "Ship/ViscousShip.h"
207#include "Ship/HullData/HullData.h"
208#include "Ship/HullData/VeresHullData.h"
209#include "Ship/HullData/NapaCGALHullData.h"
210#include "Ship/PotentialData/PotentialData.h"
211#include "Ship/PotentialData/VeresData.h"
212
217namespace Ship{
218 #ifdef FH_VISUALIZATION
219 class ShipSimObject:public SimObject, public ViscousShip/*, public ICurrentField*/, public OIS::KeyListener
220 #else
221 class ShipSimObject:public SimObject, public ViscousShip/*, public ICurrentField*/
222 #endif
223 {
224 public:
225 EIGEN_MAKE_ALIGNED_OPERATOR_NEW;
226
227 #ifdef FH_VISUALIZATION
228 enum RenderType
229 {
230 BOX,
231 STATIONS,
232 SLICED,
233 INTERPOLATED
234 };
235 #endif
236
238 ShipSimObject( const string simObjectName, ISimObjectCreator* const creator);
239
242
244 void FinalSetup( const double T, const double *const X, ISimObjectCreator* const creator );
245
247 void GetCurrent(const double T, const double* const X, const double position[3], double* currentVelocity);
248
250 virtual void PreOdeFcn(const double T, const double *const X, IStateUpdater* updater);
251
253 virtual void OdeFcn(const double T, const double* const X, double* const XDot, const bool bIsMajorTimeStep);
254
255 #ifdef FH_VISUALIZATION
256
258 virtual void RenderInit(Ogre::Root* const ogreRoot, ISimObjectCreator* const creator);
259
261 virtual void RenderUpdate( const double T, const double* const X );
262
264 bool keyPressed( const OIS::KeyEvent &e );
265
267 bool keyReleased( const OIS::KeyEvent &e );
268 #endif
269
270
271 public:
272
274 const double* PositionNED(const double T, const double* const X);
275
277 const double* PositionZeroCrossNED(const double T, const double* const X);
278
280 const double* PositionAPNED(const double T, const double* const X);
281
283 const double* VelocityNED(const double T, const double* const X);
284
286 const double* QuaternionNED(const double T, const double* const X);
287
288 const double* EulerAnglesNED(const double T, const double* const X);
289
291 const double* RotationBody(const double T, const double* const X);
292
294 const double* OmegaNED(const double T, const double* const X);
295
296
297 void ComputeRollPitchYaw(const double T, const double* const X);
298 void ComputeRelativeVelocity(const double T, const double* const X);
299
301 const double* BodyForce(const double T, const double* const X);
302
304 const double* VelocityBody(const double T, const double* const X);
305
310 const double* FirstOrderWaveBody(const double T, const double* const X);
311
315 const double* WaveDriftBody(const double T, const double* const X);
316
318 const double* const FluidMemForceBody(const double T, const double* const X);
319
321 const double* RestoringForceBody(const double T, const double* const X);
322
324 const double* RelativeVelocityBody(const double T, const double* const X);
325
327 const double* ViscousForceBody(const double T, const double* const X);
328
330 const double* Encounter(const double T, const double* const X);
331
333 const double* CoriolisRigidBody(const double T, const double* const X);
334
336 const double* CoriolisFluidBody(const double T, const double* const X);
337
339 const double* SpeedInfo( const double T, const double *const X);
340
342 const double* RotationForceFrame( const double T, const double *const X);
343
345 const double * KineticEnergy(const double T, const double* const X);
346
348 const double * FluidEnergy(const double T, const double* const X);
349 const double * FluidEnergy2(const double T, const double* const X);
350 const double * UFluidMemSpeed(const double T, const double* const X);
351
352 const double* FluidForceBySpeedBody(const double T, const double* const X, int index);
354 const double* FluidMemoryForceBody( const double T, const double *const X);
355
362 const double * CrossFlowBody(const double T, const double* const X);
363
388 const double * ResistanceBody(const double T, const double* const X);
389
397 const double * AdditionalDampeningBody(const double T, const double* const X);
398
400 const double* ExternalForceNED(const double T, const double* const X);
401
403 const double* ExternalForceBody(const double T, const double* const X);
404 // TODO: Documentation. Output viscous roll damping as calculated in components,
405 // 1) friciton damping
406 // 2) eddie damping
407 // 3) lift damping
408 // 4) bilge keel damping
409 // 5) skeg damping
410 // 6) skeg lift damping
411 const double * ViscousRoll(const double T, const double* const X);
412 double m_ViscousRoll[6];
413
415 const double* SteadyStateControlBODY( const double T, const double *const X);
417 const double* SteadyStateControlNED( const double T, const double *const X);
418
419 const double * DriftSpeed(const double T, const double* const X);
420
421
422 double m_waveElevation;
423 double m_waveSlope;
424 /*const double * WaveElevation(const double T, const double* const X);
425 const double * WaveSlope(const double T, const double* const X);*/
426
427 private:
428 void printShipInfo();
429
430 CPrintDuringExec* m_logg;
431
432 Eigen::Vector3d m_forceExtNED;
433 Eigen::Vector3d m_forceExtBody;
434
435 Eigen::Vector3d m_PositionMidpoint;
436 Eigen::Vector3d m_PositionAP;
437 Eigen::Vector3d m_angles;
438
439 Eigen::Matrix<double,6,6> m_mrb;
440 Eigen::Matrix<double,6,6> m_invMrb;
441
442 HullData *m_Hull;
443 HullData *m_Hull2;
444 ShipResistance *m_resitance;
445 DeepSeaGravityWaves *m_environment;
446
447
448 Eigen::Matrix<double,1,20> Horener_X;// { 0.00035500000000000001, 0.15313099999999999, 0.34123700000000001, 0.44641399999999998, 0.46219700000000002, 0.47891400000000001, 0.48653999999999997, 0.53628799999999999, 0.63426800000000005, 0.822828, 0.99002500000000004, 1.2892699999999999, 1.6440900000000001, 1.84578, 2.3112900000000001, 2.5824500000000001, 2.9922499999999999, 3.4575800000000001, 3.7147000000000001, 4.0064099999999998 };
449 Eigen::Matrix<double,1,20> Horener_Y;// { 1.9617800000000001, 1.9448000000000001, 1.8584499999999999, 1.73767, 1.5313699999999999, 1.2240599999999999, 1.14958, 1.02132, 0.92861700000000003, 0.79312000000000005, 0.71726999999999996, 0.61583900000000003, 0.50550499999999998, 0.45036799999999999, 0.37409900000000001, 0.30851600000000001, 0.254801, 0.19764300000000001, 0.14998300000000001, 0.11211599999999999 };
450 std::vector<double> hx, hy;
451 sfh::math::SplineInterp *hoerner;
452
453
455 ISignalPort *m_InForceNED;
456
458 ISignalPort *m_InMomentNED;
459
461 ISignalPort *m_InForceBODY;
462
464 ISignalPort *m_InMomentBODY;
465
466 ICommonComputation *m_computeRelativeVelocity;
467 ICommonComputation *m_computeRotationAngles;
468
469 PotentialData *m_TheoryData;
470
471 std::vector<double> m_waveHeight;
472 std::vector<double> m_waveFreq;
473 std::vector<double> m_wavePhase;
474 std::vector<double> m_waveDirection;
475 std::vector<double> m_waveNumber;
476
477 std::vector<double> m_uHistory;
478 std::vector<double> m_psiHistory;
479 std::vector<double> m_tHistory;
480
481 double **m_fluidForce;
482 double m_fluidForceExperienced[6];
483 double m_rotationForceFrame[4];
484 double m_speedInformation[5];
485 double m_kinetic;
486 double m_fluid;
487 double m_fluid2[36];
488
489 double m_steadyStateBody[6];
490 double m_steadyStateNED[6];
491
492 double m_damping[6];
493
494 double m_rollPitchYaw[3];
495 double m_speed[6];
496 double m_relativeSpeed[6];
497
498 double m_firstOrderForce[6];
499 double m_waveDriftForce[6];
500 double m_CforcesBody[6];
501 double m_CforcesFluid[6];
502
503 double m_crossFlowBody[6];
504 double m_resistance[6];
505
506 double m_fluidMemForce[6];
507 double m_restoringForce[6];
508 double m_sumBodyForce[6];
509 double m_encounterFreq[52];
510 double m_viscous[6];
511
512 double m_hydrostaticSpring[3];
513
514 double m_driftSpeed;
515
517 bool m_zeroSpeedRadiation;
519 bool m_hydroStaticsType;
521 bool m_useCrossFlow;
523 bool m_waveforceHframe;
525 int m_waveForceType;
527 int m_DOFFree[6];
529 double m_alfaN;
531 double m_alfaE;
533 double m_alfaD;
535 double m_surgeVelocity;
537 double m_wakeFraction;
539 double m_hydroStaticsStationVerticalStep;
541 double m_hydroStaticsStationHorizontalStep;
543 double m_hydroStaticsStationTop;
545 double m_hydroStaticsStationBottom;
547 double m_bilgeKeelStartPosition;
549 double m_bilgeKeelEndPosition;
551 double m_bilgeKeelHeight;
553 double m_damperLinear[3];
555 double m_damperQuadratic[3];
557 double m_damperRotLinear[3];
559 double m_damperRotQuadratic[3];
561 double m_dampingBlendSpeed;
563 double m_dampingBlendFraction;
564
566 double m_waveForceTransient;
567
583 double m_ForceScale[11];
585 std::string m_ForceInput;
587 std::string m_PotentialFileLocation;
589 std::string m_PotentialFileName;
591 std::string m_PotentialType;
593 double m_stablizeDOF[6];
594
595 bool m_coriolisRollOnly;
596 Eigen::Matrix<double, 6,1> m_coriolisDOFmangler;
597
598 static inline Eigen::Matrix3d S(const Eigen::Vector3d &v){
599 Eigen::Matrix3d retval = Eigen::Matrix3d::Zero();
600 retval(0,1)=-v(2);
601 retval(0,2)=v(1);
602 retval(1,0)=v(2);
603 retval(1,2)=-v(0);
604 retval(2,0)=-v(1);
605 retval(2,1)=v(0);
606 return retval;
607 }
608
609#ifdef FH_VISUALIZATION
611 bool m_ShowForceArrows;
613 std::string m_Material;
615 std::string m_Mesh;
617 std::string m_Scene;
619 RenderType m_RenderAs;
621 std::string m_RenderType;
622
624 CInputManager* m_InputMgr;
626 OIS::Keyboard* m_Keyboard;
627
628 #endif
629
630 int ***m_IFluidState;
631 int ***m_FluidStateSize;
632
633 unsigned int m_ISR;
634 unsigned int m_ISV;
635 unsigned int m_ISQ;
636 unsigned int m_ISW;
637
638
639 #ifdef FH_VISUALIZATION
640
641 public:
642 void DrawShip(Ogre::SceneNode* renderNode, Ogre::SceneManager* sceneMgr);
643 void DrawStations( Ogre::SceneNode* m_RenderNode, Ogre::SceneManager * sceneMgr );
644 private:
645 Ogre::ManualObject *manual ;
646 Ogre::SceneNode* m_RenderNodeHull;
647 Ogre::SceneNode* m_RenderNodeZeroCross;
648 Ogre::SceneNode* m_RenderNodeStations;
649 Ogre::SceneNode** m_RenderNodeSkegPoint;
650 double m_HideUntill;
651 double m_NodeOffset[3];
652 C3DArrow *FKF_u,*FKF_v,*FKF_w;
653 C3DArrow *FKT_u,*FKT_v,*FKT_w;
654
655 C3DArrow *FMF_u,*FMF_v,*FMF_w;
656 C3DArrow *FMT_u,*FMT_v,*FMT_w;
657
658 C3DArrow *RSF_u,*RSF_v,*RSF_w;
659 C3DArrow *RST_u,*RST_v,*RST_w;
660
661 C3DArrow *FKArrow;
662 C3DArrow *FMArrow;
663 C3DArrow *RArrow;
664 C3DArrow *Res;
665
666 C3DArrow *FKArrow_M;
667 C3DArrow *FMArrow_M;
668 C3DArrow *RArrow_M;
669 C3DArrow *Res_M;
670
671 C3DArrow *VArrow;
672 #endif
673
674 double m_maxWavePeriod;
675 };
676}
677
678#endif
Definition: DeepSeaGravityWaves.h:172
Definition: HullData.h:14
Definition: PotentialData.h:28
Definition: ShipResistance.h:9
Definition: ShipSimObject.h:223
const double * KineticEnergy(const double T, const double *const X)
const double * SteadyStateControlNED(const double T, const double *const X)
const double * CoriolisRigidBody(const double T, const double *const X)
const double * FluidEnergy(const double T, const double *const X)
const double * ExternalForceBody(const double T, const double *const X)
const double * CrossFlowBody(const double T, const double *const X)
const double * AdditionalDampeningBody(const double T, const double *const X)
const double * ViscousForceBody(const double T, const double *const X)
const double * PositionAPNED(const double T, const double *const X)
const double * SpeedInfo(const double T, const double *const X)
const double * Encounter(const double T, const double *const X)
const double * ExternalForceNED(const double T, const double *const X)
const double * SteadyStateControlBODY(const double T, const double *const X)
const double * RelativeVelocityBody(const double T, const double *const X)
const double * RotationForceFrame(const double T, const double *const X)
const double * RotationBody(const double T, const double *const X)
const double * FluidMemoryForceBody(const double T, const double *const X)
const double * QuaternionNED(const double T, const double *const X)
const double * PositionZeroCrossNED(const double T, const double *const X)
const double * ResistanceBody(const double T, const double *const X)
The calm water resistance of the hull in the surge direction The resistance force is the defined as t...
const double * WaveDriftBody(const double T, const double *const X)
The mean value of the higher order wave forces as experienced in the body frame of the vessel....
const double *const FluidMemForceBody(const double T, const double *const X)
const double * BodyForce(const double T, const double *const X)
const double * FirstOrderWaveBody(const double T, const double *const X)
The first order wave force, or froude-krylov force, as experienced in the body frame of the vessel Th...
const double * OmegaNED(const double T, const double *const X)
const double * CoriolisFluidBody(const double T, const double *const X)
const double * PositionNED(const double T, const double *const X)
const double * VelocityBody(const double T, const double *const X)
const double * RestoringForceBody(const double T, const double *const X)
const double * VelocityNED(const double T, const double *const X)
Definition: ViscousShip.h:12
Simple waypoint object.
Definition: CableAttach.h:16