FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
NetStructureWithConstraints.h
1#pragma once
2
3#include <limits>
4#include "CommonTypes.h"
5
197// #define NetStructureWithConstraints_DO_PROFILE
198
199// Includes
200#include "NetCableElementSpec.h"
201#include "NetCableElement.h"
202#include "NetCore.h"
203#include "NetElement3N.h"
204#include "NetElementDef.h"
205#include "NetNodeStates.h"
206#include "NetStructureSpec.h"
207
208#include "sfh/timers/ProfilerWallclock.h"
209
210#include <fhsim/simobject/SimObject.h>
211#include <fhsim_coribo/JointConstraint.h>
212#include <fhsim_environment/EnvironmentProvider.h>
213#include <memory>
214#include <string>
215
216
217#ifdef FH_VISUALIZATION
218# include "sfh/ogre/C3DLine.h"
219# include "sfh/ogre/NMeshGenerators.h"
220#endif
221
222// Class definition
223class NetStructureWithConstraints : public SimObject, private NetNodeStates
224{
225public:
227 NetStructureWithConstraints(std::string simObjectName, ISimObjectCreator* creator);
230 virtual void OdeFcn(const double dT, const double* const adX, double* const adXDot) const;
231 virtual void InitialConditionSetup(const double dT, const double* const adCurrentIC, double* const adUpdatedIC, ISimObjectCreator* const creator);
232 virtual void FinalSetup(const double dT, const double* const adX, ISimObjectCreator* const creator);
234 void PreOdeFcn(double T, const double* X) override;
235
236#ifdef FH_VISUALIZATION
238 virtual void RenderInit(Ogre::Root* const ogreRoot, ISimObjectCreator* const creator);
240 virtual void RenderUpdate(const double dT, const double* const adX);
241
242 void CreateCapsule(Ogre::ManualObject* capsule_manual);
243 C3DLine* myline;
244#endif
248 void SetAddedDragPerMPS(double AddedDragPerMPS);
249protected:
251
253 NetNodeLayout Layout() const override;
255 void AddExternalForces(double T, const double* X, double* nodeForce) const override;
257 void TakeNodeForces(double T, const double* X, const double* nodeForce, double* XDot) const override;
259 virtual void AddInputPorts(ISimObjectCreator* creator);
260 virtual void CreateDataStructures();
261 VSPairStrInt CreateExternalNodeMap(std::string tag, int* piUsed, const NetStructureSpec& NetSpec, ISimObjectCreator* creator);
262 void ValidateConstraintInput(ISimObjectCreator* creator) const;
263
265
266 // ISignalPort **m_inExternalForces;
267 /*ISignalPort **m_InConstraintsPos; // NEW: added to test new approach where pos and vel for selected nodes are set by external objects
268 ISignalPort **m_InConstraintsVel; // NEW: added to test new approach where pos and vel for selected nodes are set by external objects*/
269 ISignalPort** m_InTopConstraintsPos = nullptr;
270 ISignalPort** m_InTopConstraintsVel = nullptr;
271 int* m_iStatePos;
272 int* m_iStateVel;
274
275
277 int m_numNodesOutputPosAndVel;
278 int m_numNodesCalc;
280
281 int (*m_hasPosAndVelStates)[2] = nullptr;
282
283 int m_NumNodesInputPosAndVel; // NEW: added to test new approach where pos and vel for selected nodes are set by external objects
284 int m_NumNodesOutputForce; // NEW: added to test new approach where pos and vel for selected nodes are set by external objects
285
286 VSPairStrInt m_VsNodesInputPosAndVel; // NEW: added to test new approach where pos and vel for selected nodes are set by external objects
287 VSPairStrInt m_VsNodesOutputForce; // NEW: added to test new approach where pos and vel for selected nodes are set by external objects
288 // VSPairStrInt m_VsNodesTopConstraintsInputPos;
289
290
292 std::unique_ptr<NetCore> m_core;
293
294
296
298 VSPairStrInt m_VsNodesInputForce;
299 bool m_useTagForExternalNodes;
301
302
303 bool m_CageWakeEffectsActive;
304
305 // CONSTRAINTS (NB LOTS OF HARD CODING HERE NOW)
307 std::unique_ptr<CoRiBoDynamics::ConstraintSolver> m_constraintSolver;
308 struct states
309 {
310 int p;
311 int q;
312 int w;
313 int v;
314 };
315 std::vector<states> m_stateVector;
316
323 const double* NodePositionState(const double* X, int node) const { return X + (NodeHasOwnStates(node) ? m_iStatePos[node] : DrivingElement(node).p); }
325 const double* NodeVelocityState(const double* X, int node) const { return X + (NodeHasOwnStates(node) ? m_iStateVel[node] : DrivingElement(node).v); }
327 bool NodeHasOwnStates(int node) const { return m_hasPosAndVelStates[node][1] == 1; }
329 const states& DrivingElement(int node) const { return m_stateVector[m_hasPosAndVelStates[node][0]]; }
330
331 CoRiBoDynamics::JointConstraint* m_jointConstr;
332 // Coordinates for attachment of the constraints chains
333 mutable double m_topPosition1[3];
334 mutable double m_topVelocity1[3];
335 double m_topOrientation1[4];
336 double m_topangularVel1[3];
337 mutable double m_topPosition2[3];
338 mutable double m_topVelocity2[3];
339 double m_topOrientation2[4];
340
341 double m_topangularVel2[3];
342
343 double m_YoungsModulus;
345 int m_numConstraintsElements;
346 double m_depthOfConstraintsCable;
347#ifdef FH_VISUALIZATION
348 Ogre::SceneNode** m_renderNodes;
349 // Ogre::SceneNode* m_renderNode2; ///< The node to which the rendered entity is attached.
350#endif
351
352#ifdef NetStructureWithConstraints_DO_PROFILE
353 sfh::timers::ProfilerWallclock m_Profiler;
354#endif
355};
Definition NetNodeStates.h:39
Definition NetStructureSpec.h:40
Definition NetStructureWithConstraints.h:224
VSPairStrInt m_VsNodesOutputPosAndVel
Nodes reachable directly through input or output ports.
Definition NetStructureWithConstraints.h:297
void SetAddedDragPerMPS(double AddedDragPerMPS)
std::unique_ptr< NetCore > m_core
The net core: the panels, cable elements, their loads and the wakes (NetCore.h); no seabed contact.
Definition NetStructureWithConstraints.h:292
bool NodeHasOwnStates(int node) const
True unless a rigid element drives the node.
Definition NetStructureWithConstraints.h:327
const states & DrivingElement(int node) const
The state indices of the rigid element that drives the node.
Definition NetStructureWithConstraints.h:329
const double * NodePositionState(const double *X, int node) const
Definition NetStructureWithConstraints.h:323
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 ...
ISignalPort ** m_InTopConstraintsPos
Interface member variables.
Definition NetStructureWithConstraints.h:269
virtual ~NetStructureWithConstraints()
The destructor deletes dynamically allocated memory.
NetNodeLayout Layout() const override
double m_solverFrequencyCoefficient
Frequency coefficient of the constraint solver [1/s].
Definition NetStructureWithConstraints.h:344
void TakeNodeForces(double T, const double *X, const double *nodeForce, double *XDot) const override
The free nodes' derivatives (zero for the driven nodes' frozen states), the driven nodes' forces on t...
int m_numNodesInputForce
Node counts.
Definition NetStructureWithConstraints.h:276
int(* m_hasPosAndVelStates)[2]
Per calculation node: [0] the index of the rigid element that drives it, [1] 1 if it has its own stat...
Definition NetStructureWithConstraints.h:281
NetStructureWithConstraints(std::string simObjectName, ISimObjectCreator *creator)
The constructor sets the pointer to the output object and the parser object.
CoRiBoDynamics::JointConstraint * m_jointConstr
Owned by m_constraintSolver, which deletes its constraint sets.
Definition NetStructureWithConstraints.h:331
void AddExternalForces(double T, const double *X, double *nodeForce) const override
No external node forces.
const double * NodeVelocityState(const double *X, int node) const
The velocity of a calculation node, 3 states in X (as NodePositionState()).
Definition NetStructureWithConstraints.h:325
std::unique_ptr< CoRiBoDynamics::ConstraintSolver > m_constraintSolver
Owns the rigid elements, the constraint sets (m_jointConstr among them) and, with NumCpuCore > 1,...
Definition NetStructureWithConstraints.h:307
Definition NetNodeStates.h:19
Definition NetStructureWithConstraints.h:309