FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
NetElement3N.h
1
7
8#ifndef C_NET_ELEMENT_3N
9#define C_NET_ELEMENT_3N
10
11#include <math.h>
12#include "NetElementDef.h"
13#include "NetElement3NForces.h"
14#include <fhsim_environment/hydrodynamics/NetSolidity.h>
15#include <fhsim/PrintDuringExec.h>
16#include <sfh/ad/Dual.h>
17
18#ifdef FH_VISUALIZATION
19 //#define USE_DYNAMIC_LINES
20 #ifdef USE_DYNAMIC_LINES
21 #include "sfh/ogre/CDynamicLines.h"
22 #else
23 #include "sfh/ogre/C3DLine.h"
24 #endif
25#endif
26
27#define RENDER_OUTLINE
28#define RENDER_MESH
29//#define ATTACH_SPHERE
30//#define RENDER_MATERIAL
31//#define FILTER_FORCES
32//#define CNETELEMENT3N_TRANSPARENT
33
34class CDynamicLines; // forward declaration
35
38{
42 bool twineStructure = true;
43 double dampingRatio = 1.0;
44};
45
47{
48public:
60 const std::string netName,
61 const unsigned long iID,
62 const NetElementDef* netPanel,
63 const double dRho_water,
64 const double knotDiameter,
65 const net_solidity::PanelSolidity& solidity,
66 const NetPanelOptions& options
67 );
68
71
72 // Owns raw visualization buffers (freed in the destructor), so it must not be copied.
73 NetElement3N(const NetElement3N&) = delete;
74 NetElement3N& operator=(const NetElement3N&) = delete;
75
98 template<class T>
99 void AddNodeForces(const hydrodynamics::PanelLoadLaw& law, const hydrodynamics::Fluid& fluid,
100 const T* const posA_ned, const T* const posB_ned, const T* const posC_ned,
101 const T* const velA_ned, const T* const velB_ned, const T* const velC_ned,
102 const T* const waterVel_ned,
103 T* const nodeAforce_ned, T* const nodeBforce_ned, T* const nodeCforce_ned,
104 double addedLinearDrag = 0.0, const hydrodynamics::PanelClampLog* clampLog = nullptr) const
105 {
107 net_element_forces::ComputePanelFrame(m_panelForceParams, posA_ned, posB_ned, posC_ned);
108 const T solidity = net_solidity::Solidity(m_solidity, m_barD, m_barL0, frame.meshOpeningAngle);
109 net_element_forces::AddNodeForces(m_panelForceParams, frame, law, fluid, solidity,
110 velA_ned, velB_ned, velC_ned, waterVel_ned,
111 nodeAforce_ned, nodeBforce_ned, nodeCforce_ned, addedLinearDrag, clampLog);
112 }
113
138 void NodeForceJacobian(const hydrodynamics::PanelLoadLaw& law, const hydrodynamics::Fluid& fluid,
139 const double posA_ned[3], const double posB_ned[3], const double posC_ned[3],
140 const double velA_ned[3], const double velB_ned[3], const double velC_ned[3],
141 const double waterVel_ned[3], double addedLinearDrag, double dF[3][6][9]) const
142 {
143 using Dual = sfh::ad::Dual<12>;
144 const int kVelocitySlot = 9;
145
146 Dual pos[3][3], vel[3][3], water[3];
147 const double* posIn[3] = {posA_ned, posB_ned, posC_ned};
148 const double* velIn[3] = {velA_ned, velB_ned, velC_ned};
149 for (int node = 0; node < 3; ++node) {
150 for (int k = 0; k < 3; ++k) {
151 pos[node][k] = Dual::Variable(posIn[node][k], 3 * node + k);
152 vel[node][k] = Dual::Variable(velIn[node][k], kVelocitySlot + k);
153 }
154 }
155 for (int k = 0; k < 3; ++k)
156 water[k] = Dual(waterVel_ned[k]);
157
158 Dual force[3][3];
159 AddNodeForces<Dual>(law, fluid, pos[0], pos[1], pos[2], vel[0], vel[1], vel[2], water,
160 force[0], force[1], force[2], addedLinearDrag);
161
162 // CalcDampingForces applies the added drag only when it is positive.
163 const double addedDragPerNode = addedLinearDrag > 0 ? addedLinearDrag / 3 : 0.0;
164 const double damping = m_panelForceParams.dampingCoeff;
165 for (int node = 0; node < 3; ++node) {
166 for (int j = 0; j < 3; ++j) {
167 for (int k = 0; k < 3; ++k) {
168 for (int group = 0; group < 3; ++group)
169 dF[node][group][3 * j + k] = force[node][j].Grad(3 * group + k);
170
171 const double diagonal = (j == k) ? 1.0 : 0.0;
172 const double lawPart = (force[node][j].Grad(kVelocitySlot + k) + diagonal * addedDragPerNode) / 3;
173 for (int other = 0; other < 3; ++other) {
174 const double self = (other == node) ? 1.0 : 0.0;
175 dF[node][3 + other][3 * j + k] = lawPart
176 + diagonal * (damping * (1.0 / 3.0 - self) - addedDragPerNode * self);
177 }
178 }
179 }
180 }
181 }
182
198 hydrodynamics::PanelLoad<double> EvaluatePanelLoad(const hydrodynamics::PanelLoadLaw& law, const hydrodynamics::Fluid& fluid,
199 const double* const posA_ned, const double* const posB_ned, const double* const posC_ned,
200 const double elementVel[3], const double waterVel_ned[3], double& area) const
201 {
203 net_element_forces::ComputePanelFrame(m_panelForceParams, posA_ned, posB_ned, posC_ned);
204 area = frame.area;
205 return net_element_forces::EvaluatePanelLoad(m_panelForceParams, frame, law, fluid,
206 Solidity(frame.meshOpeningAngle), elementVel, waterVel_ned);
207 }
208
210 bool HasBarDirections() const { return m_meshDet != 0; }
211
213 double Solidity(double meshOpeningAngle) const { return net_solidity::Solidity(m_solidity, m_barD, m_barL0, meshOpeningAngle); }
214
216 double Solidity(const double* const posA_ned, const double* const posB_ned, const double* const posC_ned) const
217 {
218 return Solidity(net_element_forces::ComputePanelFrame(m_panelForceParams, posA_ned, posB_ned, posC_ned).meshOpeningAngle);
219 }
220
222 double WakeSolidity(const double* const posA_ned, const double* const posB_ned, const double* const posC_ned) const
223 {
224 return net_solidity::WakeSolidity(m_solidity, m_barD, m_barL0,
225 net_element_forces::ComputePanelFrame(m_panelForceParams, posA_ned, posB_ned, posC_ned).meshOpeningAngle);
226 }
227
229 double CalcNodeInertia(int node);
230
233 double NumberOfTwineLengthsU() const;
234
236 double TwineDiameter() const { return m_barD; }
237
238#ifdef FH_VISUALIZATION
240 void RenderInit(Ogre::Root* ogreRoot, int NumMeshPerLine = 1);
241
243 void RenderUpdate( const double* const adPosA, const double* const adPosB,
244 const double* const adPosC );
245#endif
246
247
248private:
250 void FillPanelForceParams();
251
252 // Input
253 unsigned long m_iD;
254 std::string m_netName;
255 double m_nodeInertia[3];
256 //double m_rho_water; ///< Density of water.
257 //double m_rho_twines; ///< Material density of twines.
258 //double m_EModulus; ///< E-modulus of twine material.
259 double m_barD;
260 double m_knotD;
261 double m_barL0;
262 double m_nodeAPos_mesh[2];
263 double m_nodeBPos_mesh[2];
264 double m_nodeCPos_mesh[2];
265
266 // Calculated element properties
267 //double m_twineCrossSecArea; ///< The cross sectional area of each twine.
268 double m_nodesDistAB_mesh[2];
269 double m_nodesDistAC_mesh[2];
270 double m_nodesDistBC_mesh[2];
271 double m_meshDet;
272 double m_numMeshes;
273 double m_numUBars;
274 double m_numVBars;
275 double m_numKnots;
276 double m_weight;
277 double m_eATwine;
278
279 double m_NodeWeight;
280 double m_nodeAforce_ned[3];
281 double m_nodeBforce_ned[3];
282 double m_nodeCforce_ned[3];
283 double m_dampingCoeff;
284
286 NetPanelOptions m_options;
287 net_element_forces::PanelParams m_panelForceParams;
289 net_solidity::PanelSolidity m_solidity;
290#ifdef FILTER_FORCES
291 double m_nodeAforce_ned_last[3];
292 double m_nodeBforce_ned_last[3];
293 double m_nodeCforce_ned_last[3];
294#endif
295
296#ifdef FH_VISUALIZATION
297 // Visualization specifics
298 Ogre::Root* m_ogreRoot;
299 Ogre::SceneManager* m_sceneMgr;
300 Ogre::Entity* m_renderElement[3];
301 Ogre::Entity* m_renderSphere[3];
302 Ogre::SceneNode* m_renderNodeMesh;
303 Ogre::SceneNode* m_renderNodeSphere[3];
304 Ogre::SceneNode* m_renderNodeOutline;
305 Ogre::SceneNode* m_renderNodeMaterial;
306#ifdef USE_DYNAMIC_LINES
307 C3DLine* m_lines = nullptr;
308#else
309 C3DLine* m_lines = nullptr;
310 Ogre::ColourValue m_twineColour;
311#endif
312 C3DLine* m_lineOutline;
313 //Ogre::ManualObject * m_netRenderObj; ///< The manual object used for rendering the net element with a triangle skin.
314
315 // Visualization variables
316 unsigned short* m_sortU = nullptr;
317 unsigned short* m_sortV = nullptr;
318 unsigned long m_numTwines;
319 unsigned long m_numUTwines;
320 unsigned long m_numVTwines;
321 double* m_interpCoeffAu = nullptr;
322 double* m_interpCoeffAv = nullptr;
323 double* m_interpCoeffBu = nullptr;
324 double* m_interpCoeffBv = nullptr;
325 int m_NumMeshPerLine;
326#endif
327
328};
329
330
331#endif
Definition NetElement3N.h:47
void AddNodeForces(const hydrodynamics::PanelLoadLaw &law, const hydrodynamics::Fluid &fluid, const T *const posA_ned, const T *const posB_ned, const T *const posC_ned, const T *const velA_ned, const T *const velB_ned, const T *const velC_ned, const T *const waterVel_ned, T *const nodeAforce_ned, T *const nodeBforce_ned, T *const nodeCforce_ned, double addedLinearDrag=0.0, const hydrodynamics::PanelClampLog *clampLog=nullptr) const
Definition NetElement3N.h:99
double TwineDiameter() const
The twine diameter [m].
Definition NetElement3N.h:236
double CalcNodeInertia(int node)
Calculates the inertia of a node.
double Solidity(const double *const posA_ned, const double *const posB_ned, const double *const posC_ned) const
The solidity of the element at the given node positions, global frame.
Definition NetElement3N.h:216
bool HasBarDirections() const
True when the bar directions are defined, which needs a non-zero mesh determinant.
Definition NetElement3N.h:210
void NodeForceJacobian(const hydrodynamics::PanelLoadLaw &law, const hydrodynamics::Fluid &fluid, const double posA_ned[3], const double posB_ned[3], const double posC_ned[3], const double velA_ned[3], const double velB_ned[3], const double velC_ned[3], const double waterVel_ned[3], double addedLinearDrag, double dF[3][6][9]) const
Definition NetElement3N.h:138
double Solidity(double meshOpeningAngle) const
The solidity of the element at the given mesh half opening angle [rad].
Definition NetElement3N.h:213
hydrodynamics::PanelLoad< double > EvaluatePanelLoad(const hydrodynamics::PanelLoadLaw &law, const hydrodynamics::Fluid &fluid, const double *const posA_ned, const double *const posB_ned, const double *const posC_ned, const double elementVel[3], const double waterVel_ned[3], double &area) const
Definition NetElement3N.h:198
~NetElement3N(void)
The destructor.
double WakeSolidity(const double *const posA_ned, const double *const posB_ned, const double *const posC_ned) const
The solidity the element hands to its wake source at the given node positions, global frame (NetSolid...
Definition NetElement3N.h:222
double NumberOfTwineLengthsU() const
NetElement3N(const std::string netName, const unsigned long iID, const NetElementDef *netPanel, const double dRho_water, const double knotDiameter, const net_solidity::PanelSolidity &solidity, const NetPanelOptions &options)
Class containing the description of a net panel and methods necessary for taking this over to triangu...
Definition NetElementDef.h:22
What a net panel adds beyond its load and weight in water. Net/NetStructure uses the defaults.
Definition NetElement3N.h:38
double dampingRatio
NetDampingRatio: scales the structural damping; unused without twineStructure.
Definition NetElement3N.h:43
bool twineStructure
Definition NetElement3N.h:42
Definition NetElement3NForces.h:86
T meshOpeningAngle
The mesh half opening angle, rad; 0 when undefined.
Definition NetElement3NForces.h:90
T area
The element's area, m^2.
Definition NetElement3NForces.h:91
Definition NetElement3NForces.h:59
double dampingCoeff
Definition NetElement3NForces.h:72