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#include <vector>
216
217
218#ifdef FH_VISUALIZATION
219# include "sfh/ogre/C3DLine.h"
220# include "sfh/ogre/NMeshGenerators.h"
221#endif
222
223// Class definition
224class NetStructureWithConstraints : public SimObject, private NetNodeStates
225{
226public:
228 NetStructureWithConstraints(std::string simObjectName, ISimObjectCreator* creator);
231 virtual void OdeFcn(const double dT, const double* const adX, double* const adXDot) const;
232 virtual void InitialConditionSetup(const double dT, const double* const adCurrentIC, double* const adUpdatedIC, ISimObjectCreator* const creator);
233 virtual void FinalSetup(const double dT, const double* const adX, ISimObjectCreator* const creator);
235 void PreOdeFcn(double T, const double* X) override;
236
237#ifdef FH_VISUALIZATION
239 virtual void RenderInit(Ogre::Root* const ogreRoot, ISimObjectCreator* const creator);
241 virtual void RenderUpdate(const double dT, const double* const adX);
242
243 void CreateCapsule(Ogre::ManualObject* capsule_manual);
244 C3DLine* myline;
245#endif
249 void SetAddedDragPerMPS(double AddedDragPerMPS);
250protected:
252
254 NetNodeLayout Layout() const override;
256 void AddExternalForces(double T, const double* X, double* nodeForce) const override;
258 void TakeNodeForces(double T, const double* X, const double* nodeForce, double* XDot) const override;
260 virtual void AddInputPorts(ISimObjectCreator* creator);
261 virtual void CreateDataStructures();
262 VSPairStrInt CreateExternalNodeMap(std::string tag, int* piUsed, const NetStructureSpec& NetSpec, ISimObjectCreator* creator);
263 void ValidateConstraintInput(ISimObjectCreator* creator) const;
264
266
267 // ISignalPort **m_inExternalForces;
268 /*ISignalPort **m_InConstraintsPos; // NEW: added to test new approach where pos and vel for selected nodes are set by external objects
269 ISignalPort **m_InConstraintsVel; // NEW: added to test new approach where pos and vel for selected nodes are set by external objects*/
270 ISignalPort** m_InTopConstraintsPos = nullptr;
271 ISignalPort** m_InTopConstraintsVel = nullptr;
272 int* m_iStatePos;
273 int* m_iStateVel;
275
276
278 int m_numNodesOutputPosAndVel;
279 int m_numNodesCalc;
281
282 int (*m_hasPosAndVelStates)[2] = nullptr;
283
284 int m_NumNodesInputPosAndVel; // NEW: added to test new approach where pos and vel for selected nodes are set by external objects
285 int m_NumNodesOutputForce; // NEW: added to test new approach where pos and vel for selected nodes are set by external objects
286
287 VSPairStrInt m_VsNodesInputPosAndVel; // NEW: added to test new approach where pos and vel for selected nodes are set by external objects
288 VSPairStrInt m_VsNodesOutputForce; // NEW: added to test new approach where pos and vel for selected nodes are set by external objects
289 // VSPairStrInt m_VsNodesTopConstraintsInputPos;
290
291
293 std::unique_ptr<NetCore> m_core;
294
295
297
299 VSPairStrInt m_VsNodesInputForce;
300 bool m_useTagForExternalNodes;
302
303
304 bool m_CageWakeEffectsActive;
305
306 // CONSTRAINTS (NB LOTS OF HARD CODING HERE NOW)
308 std::unique_ptr<CoRiBoDynamics::ConstraintSolver> m_constraintSolver;
309 struct states
310 {
311 int p;
312 int q;
313 int w;
314 int v;
315 };
316 std::vector<states> m_stateVector;
317
324 const double* NodePositionState(const double* X, int node) const { return X + (NodeHasOwnStates(node) ? m_iStatePos[node] : DrivingElement(node).p); }
326 const double* NodeVelocityState(const double* X, int node) const { return X + (NodeHasOwnStates(node) ? m_iStateVel[node] : DrivingElement(node).v); }
328 bool NodeHasOwnStates(int node) const { return m_hasPosAndVelStates[node][1] == 1; }
330 const states& DrivingElement(int node) const { return m_stateVector[m_hasPosAndVelStates[node][0]]; }
331
332 CoRiBoDynamics::JointConstraint* m_jointConstr;
333 // Coordinates for attachment of the constraints chains
334 mutable double m_topPosition1[3];
335 mutable double m_topVelocity1[3];
336 double m_topOrientation1[4];
337 double m_topangularVel1[3];
338 mutable double m_topPosition2[3];
339 mutable double m_topVelocity2[3];
340 double m_topOrientation2[4];
341
342 double m_topangularVel2[3];
343
344 double m_YoungsModulus;
346 int m_numConstraintsElements;
347 double m_depthOfConstraintsCable;
348#ifdef FH_VISUALIZATION
349 Ogre::SceneNode** m_renderNodes;
350 // Ogre::SceneNode* m_renderNode2; ///< The node to which the rendered entity is attached.
351#endif
352
353#ifdef NetStructureWithConstraints_DO_PROFILE
354 sfh::timers::ProfilerWallclock m_Profiler;
355#endif
356};
Definition NetNodeStates.h:39
Definition NetStructureSpec.h:40
Definition NetStructureWithConstraints.h:225
VSPairStrInt m_VsNodesOutputPosAndVel
Nodes reachable directly through input or output ports.
Definition NetStructureWithConstraints.h:298
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:293
bool NodeHasOwnStates(int node) const
True unless a rigid element drives the node.
Definition NetStructureWithConstraints.h:328
const states & DrivingElement(int node) const
The state indices of the rigid element that drives the node.
Definition NetStructureWithConstraints.h:330
const double * NodePositionState(const double *X, int node) const
Definition NetStructureWithConstraints.h:324
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:270
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:345
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:277
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:282
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:332
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:326
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:308
Definition NetNodeStates.h:19
Definition NetStructureWithConstraints.h:310