FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
NetStructure.h
1#pragma once
2
3#include <limits>
4#include <vector>
5#include "CommonTypes.h"
6
278// #define CNetStructure_DO_PROFILE
279
280// Includes
281#include "NetCableElement.h"
282#include "NetCableElementSpec.h"
283#include "NetCore.h"
284#include "NetElement3N.h"
285#include "NetElementDef.h"
286#include "NetNodeStates.h"
287#include "NetStructureSpec.h"
288
289#include "sfh/math/math.h"
290#include "sfh/timers/ProfilerWallclock.h"
291
292#include <fhsim/simobject/SimObject.h>
293#include <fhsim_environment/EnvironmentProvider.h>
294#include <fhsim_environment/SeafloorForcesInterface.h>
295#include <memory>
296#include <string>
297
298
299#ifdef FH_VISUALIZATION
300# include "sfh/ogre/C3DLine.h"
301# include "sfh/ogre/NMeshGenerators.h"
302#endif
303
304
305// Class definition
306class NetStructure : public SimObject, private NetNodeStates
307{
308public:
310 NetStructure(std::string simObjectName, ISimObjectCreator* creator);
312 virtual ~NetStructure();
313 virtual void OdeFcn(const double dT, const double* const adX, double* const adXDot) const;
314 virtual void InitialConditionSetup(const double dT, const double* const adCurrentIC, double* const adUpdatedIC, ISimObjectCreator* const creator);
315 virtual void FinalSetup(const double dT, const double* const adX, ISimObjectCreator* const creator);
317 void PreOdeFcn(double T, const double* X) override;
318 void AcceptedStep(const double T, const double* const X) override;
319 const double* outExternalNodeForce(const double dT, const double* const adX, int extNode);
320
322
348 bool HasJacobians() const override;
349 void OdeJacobian(double T, const double* X, double* J, int nStates) override;
350 int GetJacobianSparsity(int nStates, int* rowPtr, int* colIdx) override;
351
352 bool HasPortJacobians() const override;
353 void InputPortJacobian(const std::string& portName, double T, const double* X,
354 double* dF_dInput, int portSize, int nStates) override;
360 void OutputPortJacobian(const std::string& portName, double T, const double* X,
361 double* dPort_dX, int portSize, int nStates, int index) override;
363
364#ifdef FH_VISUALIZATION
366 virtual void RenderInit(Ogre::Root* const ogreRoot, ISimObjectCreator* const creator);
368 virtual void RenderUpdate(const double dT, const double* const adX);
369#endif
370 const virtual double* NodePos(const double dT, const double* const adX, int extNode);
371 const virtual double* NodeVel(const double dT, const double* const adX, int extNode);
372 const virtual double* BottomContact(const double dT, const double* const adX);
373
374 const virtual double* StrainEnergy(const double dT, const double* const adX);
375 const virtual double* VelNorm(const double dT, const double* const adX);
376 double m_velNorm;
377
381 void SetAddedDragPerMPS(double AddedDragPerMPS);
382
383protected:
385
387 NetNodeLayout Layout() const override;
389 void AddExternalForces(double T, const double* X, double* nodeForce) const override;
391 void TakeNodeForces(double T, const double* X, const double* nodeForce, double* XDot) const override;
393
396 virtual void AddInputPorts(ISimObjectCreator* creator);
397 virtual void CreateOutputPorts(ISimObjectCreator* creator);
398 std::string PosPortName(int extNode) const;
399 std::string VelPortName(int extNode) const;
400 void VelNormJacobian(const double* X, double* dPort_dX) const;
401 void StrainEnergyJacobian(const double* X, double* dPort_dX) const;
402 VSPairStrInt CreateExternalNodeMap(std::string tag, int* piUsed, const NetStructureSpec& NetSpec, ISimObjectCreator* creator);
403
409 const NetCableElement* cable,
410 const double pA[3], const double pB[3],
411 const double vA[3], const double vB[3],
412 double dFA_dpA[9], double dFA_dpB[9],
413 double dFA_dvA[9], double dFA_dvB[9]) const;
414
415 double m_StrainEnergy;
416
418 std::unique_ptr<NetCore> m_core;
419
421
422 ISignalPort** m_inExternalForces;
423 int* m_iStatePos;
424 int* m_iStateVel;
425 int m_iStateBase = 0;
426
433 int LocalIndex(int globalStateIndex) const { return globalStateIndex - m_iStateBase; }
435 // double* m_NodeExternalForces;
437
439 int m_numNodesOutputPosAndVel;
441
442
444
446 VSPairStrInt m_VsNodesInputForce;
447 bool m_useTagForExternalNodes;
449
450
451#ifdef CNetStructure_DO_PROFILE
452 sfh::timers::ProfilerWallclock m_Profiler;
453#endif
454
455#ifdef FH_VISUALIZATION
456 bool m_lineVisualization;
457 C3DLine* m_LineVisualizationPressure;
458 C3DLine* m_LineVisualizationStrain;
459#endif
460
461private:
465 void FillAnalyticalJacobian(double T, const double* X, double* J, int nStates);
466 friend class NetStructureTestAccess;
467};
Definition NetCableElement.h:48
Definition NetNodeStates.h:39
Definition NetStructureSpec.h:40
Definition NetStructure.h:307
int LocalIndex(int globalStateIndex) const
Definition NetStructure.h:433
virtual ~NetStructure()
The destructor deletes dynamically allocated memory.
void OutputPortJacobian(const std::string &portName, double T, const double *X, double *dPort_dX, int portSize, int nStates, int index) override
void AddExternalForces(double T, const double *X, double *nodeForce) const override
The forces of the input force ports, on their nodes.
NetNodeLayout Layout() const override
NetStructure(std::string simObjectName, ISimObjectCreator *creator)
The constructor sets the pointer to the output object and the parser object.
int m_iStateBase
Global index of this SimObject's first state, set in the constructor.
Definition NetStructure.h:425
ISignalPort ** m_inExternalForces
Interface member variables.
Definition NetStructure.h:422
void ComputeCableStructuralJacobian(const NetCableElement *cable, const double pA[3], const double pB[3], const double vA[3], const double vB[3], double dFA_dpA[9], double dFA_dpB[9], double dFA_dvA[9], double dFA_dvB[9]) const
bool HasJacobians() const override
void SetAddedDragPerMPS(double AddedDragPerMPS)
void TakeNodeForces(double T, const double *X, const double *nodeForce, double *XDot) const override
The state derivatives: velocity, force over inertia (and MassFactor), bounded by MaxVelocity.
std::unique_ptr< NetCore > m_core
The net core: the panels, cable elements, their loads, the wakes and the seabed contact (NetCore....
Definition NetStructure.h:418
int m_numNodesInputForce
Node counts.
Definition NetStructure.h:438
VSPairStrInt m_VsNodesOutputPosAndVel
Nodes reachable directly through input or output ports.
Definition NetStructure.h:445
bool HasJacobianConfiguration() const
void PreOdeFcn(double T, const double *X) override
Rebuilds the cast wake when due (with CastWake) and takes the wakes at the panel centroids and cable ...
Definition NetNodeStates.h:19