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