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
246protected:
248
250 NetNodeLayout Layout() const override;
252 void AddExternalForces(double T, const double* X, double* nodeForce) const override;
254 void TakeNodeForces(double T, const double* X, const double* nodeForce, double* XDot) const override;
256 virtual void AddInputPorts(ISimObjectCreator* creator);
257 virtual void CreateDataStructures();
258 VSPairStrInt CreateExternalNodeMap(std::string tag, int* piUsed, const NetStructureSpec& NetSpec, ISimObjectCreator* creator);
259 void ValidateConstraintInput(ISimObjectCreator* creator) const;
260
262
263 // ISignalPort **m_inExternalForces;
264 /*ISignalPort **m_InConstraintsPos; // NEW: added to test new approach where pos and vel for selected nodes are set by external objects
265 ISignalPort **m_InConstraintsVel; // NEW: added to test new approach where pos and vel for selected nodes are set by external objects*/
266 ISignalPort** m_InTopConstraintsPos = nullptr;
267 ISignalPort** m_InTopConstraintsVel = nullptr;
268 int* m_iStatePos;
269 int* m_iStateVel;
271
272
274 int m_numNodesOutputPosAndVel;
275 int m_numNodesCalc;
277
278 int (*m_hasPosAndVelStates)[2] = nullptr;
279
280 int m_NumNodesInputPosAndVel; // NEW: added to test new approach where pos and vel for selected nodes are set by external objects
281 int m_NumNodesOutputForce; // NEW: added to test new approach where pos and vel for selected nodes are set by external objects
282
283 VSPairStrInt m_VsNodesInputPosAndVel; // NEW: added to test new approach where pos and vel for selected nodes are set by external objects
284 VSPairStrInt m_VsNodesOutputForce; // NEW: added to test new approach where pos and vel for selected nodes are set by external objects
285 // VSPairStrInt m_VsNodesTopConstraintsInputPos;
286
287
289 std::unique_ptr<NetCore> m_core;
290
291
293
295 VSPairStrInt m_VsNodesInputForce;
296 bool m_useTagForExternalNodes;
298
299
300 bool m_CageWakeEffectsActive;
301
302 // CONSTRAINTS (NB LOTS OF HARD CODING HERE NOW)
304 std::unique_ptr<CoRiBoDynamics::ConstraintSolver> m_constraintSolver;
305 struct states
306 {
307 int p;
308 int q;
309 int w;
310 int v;
311 };
312 std::vector<states> m_stateVector;
313
320 const double* NodePositionState(const double* X, int node) const { return X + (NodeHasOwnStates(node) ? m_iStatePos[node] : DrivingElement(node).p); }
322 const double* NodeVelocityState(const double* X, int node) const { return X + (NodeHasOwnStates(node) ? m_iStateVel[node] : DrivingElement(node).v); }
324 bool NodeHasOwnStates(int node) const { return m_hasPosAndVelStates[node][1] == 1; }
326 const states& DrivingElement(int node) const { return m_stateVector[m_hasPosAndVelStates[node][0]]; }
327
328 CoRiBoDynamics::JointConstraint* m_jointConstr;
329 // Coordinates for attachment of the constraints chains
330 mutable double m_topPosition1[3];
331 mutable double m_topVelocity1[3];
332 double m_topOrientation1[4];
333 double m_topangularVel1[3];
334 mutable double m_topPosition2[3];
335 mutable double m_topVelocity2[3];
336 double m_topOrientation2[4];
337
338 double m_topangularVel2[3];
339
340 double m_YoungsModulus;
342 int m_numConstraintsElements;
343 double m_depthOfConstraintsCable;
344#ifdef FH_VISUALIZATION
345 Ogre::SceneNode** m_renderNodes;
346 // Ogre::SceneNode* m_renderNode2; ///< The node to which the rendered entity is attached.
347#endif
348
349#ifdef NetStructureWithConstraints_DO_PROFILE
350 sfh::timers::ProfilerWallclock m_Profiler;
351#endif
352};
Definition NetNodeStates.h:39
Definition NetStructureSpec.h:39
Definition NetStructureWithConstraints.h:225
VSPairStrInt m_VsNodesOutputPosAndVel
Nodes reachable directly through input or output ports.
Definition NetStructureWithConstraints.h:294
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:289
bool NodeHasOwnStates(int node) const
True unless a rigid element drives the node.
Definition NetStructureWithConstraints.h:324
const states & DrivingElement(int node) const
The state indices of the rigid element that drives the node.
Definition NetStructureWithConstraints.h:326
const double * NodePositionState(const double *X, int node) const
Definition NetStructureWithConstraints.h:320
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:266
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:341
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:273
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:278
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:328
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:322
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:304
Definition NetNodeStates.h:19
Definition NetStructureWithConstraints.h:306