FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
CableBranched.h
1#pragma once
2
223#include "cable/subroutines/InternalCableWithBottomContact.h"
224
225#include "sfh/timers/StopWatch.h"
226
227#include <fhsim/simobject/SimObject.h>
228#include <fhsim_environment/EnvironmentProvider.h>
229#include <fhsim_environment/SeafloorForcesInterface.h>
230#include <functional>
231#include <memory>
232#include <mutex>
233#include <string>
234
235#ifdef FH_VISUALIZATION
236# ifdef USE_BILLBOARD_LABELS
237# include "CMovableText.h"
238# endif
239#endif
240
241// Class definition
242class CableBranched : public SimObject
243{
244public:
248 using SectionFactory = std::function<std::unique_ptr<InternalCable>(ISimObjectCreator* creator, const SCableSpec& spec)>;
249
251 CableBranched(std::string simObjectName, ISimObjectCreator* creator);
254
255 // Member functions
256 virtual void OdeFcn(const double dT, const double* const adX, double* const adXDot) const;
258 void PreOdeFcn(double T, const double* X) override;
259 bool HasJacobians() const override;
261 void OdeJacobian(double T, const double* X, double* J, int nStates) override;
262 int GetJacobianSparsity(int nStates, int* rowPtr, int* colIdx) override;
263 void FinalSetup(const double dT, const double* const adX, ISimObjectCreator* const creator);
264 void InitialConditionSetup(const double dT, const double* const adCurrentIC, double* const adUpdatedIC, ISimObjectCreator* const creator);
265#ifdef FH_VISUALIZATION
267 void RenderInit(Ogre::Root* const ogreRoot, ISimObjectCreator* const creator);
268
270 void RenderUpdate(const double dT, const double* const adX);
271#endif
272
273protected:
275 CableBranched(std::string simObjectName, ISimObjectCreator* creator, const SectionFactory& makeSection);
276
283 virtual void AddJunctionNodeForce(const double /*pos*/[3], const double /*vel*/[3], double /*force*/[3]) const { }
284
288
289 void CreateStates(ISimObjectCreator* creator);
290 void CalcOutput(const double dT, const double* const adX) const;
292 void UpdateSectionLength(int element, double dT, const double* adX) const;
297 virtual void PrepareSections(double /*dT*/, const double* /*adX*/) const { }
298 void OutputExternalConnForces(double dT, const double* adX);
299 void GetPosAndVelPointer(
300 int node,
301 double dT,
302 const double* const adX,
303 const double** const padPos,
304 const double** const padVel) const;
305
306 const double* GetPosPointer(
307 int node,
308 double dT,
309 const double* const adX) const;
310
311
313 virtual void AddBottomForces(double dT, const double* const adX) const;
314 virtual void CreateDataStructures();
315 virtual void CreateInputports(ISimObjectCreator* creator);
316 virtual void CreateOutputports(ISimObjectCreator* creator);
317
318
320 void CheckNodeNumber(int nodeNumber, std::string nodeDescription, ISimObjectCreator* creator);
321
322 ISignalPort** m_inVel;
323 ISignalPort** m_inPos;
324 ISignalPort** m_inLength;
325 ICommonComputation* m_commonCalc;
326 const double* ExternalForce(const double dT, const double* const adX, int i);
327 const double* ExternalTension(const double dT, const double* const adX, int i);
328 const double* SectionLength(const double dT, const double* const adX, int i);
332 int m_iStateBase = 0;
333 mutable bool m_forceOutsideJacobian = false;
334
341 int LocalIndex(int globalStateIndex) const { return globalStateIndex - m_iStateBase; }
349
350 // int* m_numAEndsToExt; ///< The number of elements with the A node connected to each external node.
351 // int* m_numBEndsToExt; ///< The number of elements with the B node connected to each external node.
352 // int** m_aaiAEndsToExt; ///< The elements with the A node connected to each external node.
353 // int** m_aaiBEndsToExt; ///< The elements with the B node connected to each external node.
354
355 // int* m_numElementsPerSection;
359 double m_maxStep;
361 double* m_stiffness;
367 double* m_density;
368 double* m_dE;
369 double* m_diameter;
370 double* m_maxTension;
372 // double* m_inertiaA; ///< The inertia of the connected end A of each eleemnt.
373 // double* m_inertiaB; ///< The inertia of the connected end B of each eleemnt.
374 double* m_nodeForce;
375 double* m_outNodeForce = nullptr;
376 double* m_outNodeInertia = nullptr;
377
381 mutable std::mutex m_sectionMutex;
382 // double* m_forceA; ///< The force on the A nodes.
383 // double* m_forceB; ///< The force on the B nodes.
384 double* m_lengths;
385 double* m_outLengths = nullptr;
386 std::string m_materialName;
387 double m_drawScale;
388 double* m_externalTensions;
390
391 const double* m_padVelWater;
392 environment::EnvironmentProvider* m_environment;
393 environment::SeafloorForcesInterface* m_seafloor;
394 // bool m_outputFcnCalled;
395#ifdef FH_VISUALIZATION
396# ifdef USE_BILLBOARD_LABELS
397 Ogre::SceneNode** m_renderNode;
398 Ogre::CMovableText** m_bBTxt;
399 double m_txtSize;
400# endif
401#endif
402private:
405 void ReadFile(ISimObjectCreator* creator, const SectionFactory& makeSection);
406};
Definition CableBranched.h:243
virtual void PrepareSections(double, const double *) const
Definition CableBranched.h:297
double m_drawScale
The scale for which to draw the cable diameter.
Definition CableBranched.h:387
InternalCable ** m_cableSections
An array holding the cable sections.
Definition CableBranched.h:389
int * m_iStateVel
An array of indices to the node velocity states.
Definition CableBranched.h:330
CableBranched(std::string simObjectName, ISimObjectCreator *creator, const SectionFactory &makeSection)
A subclass's sections: reads the file as Cable/Branched does and makes each section with makeSection.
double * m_relaxedLength
The relaxed length of the cable.
Definition CableBranched.h:362
CableBranched(std::string simObjectName, ISimObjectCreator *creator)
Cable/Branched: reads the file and makes every section an InternalCableWithBottomContact.
int * m_iStatePos
An array of indices to the node position states.
Definition CableBranched.h:329
int m_cableFaces
The number of faces of the cable visuaization.
Definition CableBranched.h:348
double m_bottomContactDiameter
BottomContactDiameter of the General section: the sphere of each main node in the seabed contact [m].
Definition CableBranched.h:365
void PreOdeFcn(double T, const double *X) override
Applies the Length inputs and advances the sections' mean tension from the step's start state (MARE-0...
int m_numExternalConn
The number of external connections.
Definition CableBranched.h:346
void OdeJacobian(double T, const double *X, double *J, int nStates) override
Writes nothing while HasJacobians() is false (FhSim's Jacobian checker, E12-Q3).
ISignalPort ** m_inPos
The position input ports.
Definition CableBranched.h:323
int m_iStateBase
Global index of this SimObject's first state, set in CreateStates().
Definition CableBranched.h:332
virtual void AddBottomForces(double dT, const double *const adX) const
Adds the bottom forces to the main nodes, and marks the state (MarkForceOutsideJacobian) if any of th...
double * m_dE
The stiffness of the cable material.
Definition CableBranched.h:368
double * m_density
The density of the cable material.
Definition CableBranched.h:367
int m_numNodesCalc
The number of nodes of the cable between the cable elements.
Definition CableBranched.h:343
double * m_stiffness
The linear stiffness of the cable.
Definition CableBranched.h:361
int * m_nodeConnections
The nodes connected to each cable section.
Definition CableBranched.h:347
double m_eAdaptationPeriod
The time constant of the adaptation of the mean tension.
Definition CableBranched.h:357
double * m_diameter
The diameter of the cable.
Definition CableBranched.h:369
double m_maxLengthChangeSpeed
The maximum speed of the cable length change.
Definition CableBranched.h:364
std::function< std::unique_ptr< InternalCable >(ISimObjectCreator *creator, const SCableSpec &spec)> SectionFactory
Definition CableBranched.h:248
double * m_lengths
The lengths of the cable elements.
Definition CableBranched.h:384
double * m_outLengths
As m_lengths, as CalcOutput found it for the Length ports.
Definition CableBranched.h:385
~CableBranched()
The destructor deletes dynamically allocated memory.
int LocalIndex(int globalStateIndex) const
Definition CableBranched.h:341
double m_stepSafetyFactor
The safety factor when calculating the Young modulus of the element.
Definition CableBranched.h:356
void UpdateSectionLength(int element, double dT, const double *adX) const
Reads the Length input of a cable section and applies it to the section (MARE-0037).
std::mutex m_sectionMutex
Definition CableBranched.h:381
double m_maxStep
The maximum steplength of the simulation.
Definition CableBranched.h:359
double * m_maxTension
The maximum tension in the cable.
Definition CableBranched.h:370
bool m_forceOutsideJacobian
Whether the last OdeFcn state had a force OdeJacobian does not model: bottom contact (FISH-0086) or a...
Definition CableBranched.h:333
int m_numCableSections
The number of cable sections in the branched cable, where each section may be comprised of one or mor...
Definition CableBranched.h:344
double * m_dampingRatio
The damping ratio to specify the internal damping.
Definition CableBranched.h:366
virtual void AddJunctionNodeForce(const double[3], const double[3], double[3]) const
Definition CableBranched.h:283
double * m_nodeForce
The force on the calculation nodes belonging to this simObject, as OdeFcn found it.
Definition CableBranched.h:374
double m_numericalDamping
The numerical damping of the cable.
Definition CableBranched.h:358
double * m_outNodeForce
As m_nodeForce, as CalcOutput found it for the Force and Tension ports.
Definition CableBranched.h:375
int m_numElements
The number of elements to divide the cable into.
Definition CableBranched.h:342
int * m_iStateCable
An array of indices to the cable sections states.
Definition CableBranched.h:331
double * m_meanTension
The mean tension of the cable.
Definition CableBranched.h:360
ISignalPort ** m_inLength
The cable sections length port.
Definition CableBranched.h:324
double * m_outNodeInertia
As m_nodeInertia, as CalcOutput found it.
Definition CableBranched.h:376
int m_numNodesGlobal
The number of nodes of the branched cable used for conecting the internal cable sections.
Definition CableBranched.h:345
double * m_nodeInertia
The inertia of the calculation nodes belonging to this simObject.
Definition CableBranched.h:371
ICommonComputation * m_commonCalc
Calculations necessary for more than one output port.
Definition CableBranched.h:325
std::string m_materialName
The material name of the cable;.
Definition CableBranched.h:386
double * m_relaxedLength_d
The desired relaxed length of the cable.
Definition CableBranched.h:363
ISignalPort ** m_inVel
The velocity input port s.
Definition CableBranched.h:322
void MarkForceOutsideJacobian() const
Definition CableBranched.h:287
void CheckNodeNumber(int nodeNumber, std::string nodeDescription, ISimObjectCreator *creator)
Checks to see if a specified nodenumber is ok.
Definition InternalCable.h:191
Contains some specifications used for simulating cables.
Definition InternalCable.h:36