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
37{
38public:
41 const std::string netName,
42 const unsigned long iID,
43 const NetElementDef* netPanel,
44 const double dRho_water,
45 const double knotDiameter,
46 const double knotMomStiff,
47 const double dKknotMomStiff_contact,
48 const net_solidity::PanelSolidity& solidity,
49 const double dampingRatio
50 );
51
54
55 // Owns raw visualization buffers (freed in the destructor), so it must not be copied.
56 NetElement3N(const NetElement3N&) = delete;
57 NetElement3N& operator=(const NetElement3N&) = delete;
58
81 template<class T>
82 void AddNodeForces(const hydrodynamics::PanelLoadLaw& law, const hydrodynamics::Fluid& fluid,
83 const T* const posA_ned, const T* const posB_ned, const T* const posC_ned,
84 const T* const velA_ned, const T* const velB_ned, const T* const velC_ned,
85 const T* const waterVel_ned,
86 T* const nodeAforce_ned, T* const nodeBforce_ned, T* const nodeCforce_ned,
87 double addedLinearDrag = 0.0, const hydrodynamics::PanelClampLog* clampLog = nullptr) const
88 {
90 net_element_forces::ComputePanelFrame(m_panelForceParams, posA_ned, posB_ned, posC_ned);
91 const T solidity = net_solidity::Solidity(m_solidity, m_barD, m_barL0, frame.meshOpeningAngle);
92 net_element_forces::AddNodeForces(m_panelForceParams, frame, law, fluid, solidity,
93 velA_ned, velB_ned, velC_ned, waterVel_ned,
94 nodeAforce_ned, nodeBforce_ned, nodeCforce_ned, addedLinearDrag, clampLog);
95 }
96
121 void NodeForceJacobian(const hydrodynamics::PanelLoadLaw& law, const hydrodynamics::Fluid& fluid,
122 const double posA_ned[3], const double posB_ned[3], const double posC_ned[3],
123 const double velA_ned[3], const double velB_ned[3], const double velC_ned[3],
124 const double waterVel_ned[3], double addedLinearDrag, double dF[3][6][9]) const
125 {
126 using Dual = sfh::ad::Dual<12>;
127 const int kVelocitySlot = 9;
128
129 Dual pos[3][3], vel[3][3], water[3];
130 const double* posIn[3] = {posA_ned, posB_ned, posC_ned};
131 const double* velIn[3] = {velA_ned, velB_ned, velC_ned};
132 for (int node = 0; node < 3; ++node) {
133 for (int k = 0; k < 3; ++k) {
134 pos[node][k] = Dual::Variable(posIn[node][k], 3 * node + k);
135 vel[node][k] = Dual::Variable(velIn[node][k], kVelocitySlot + k);
136 }
137 }
138 for (int k = 0; k < 3; ++k)
139 water[k] = Dual(waterVel_ned[k]);
140
141 Dual force[3][3];
142 AddNodeForces<Dual>(law, fluid, pos[0], pos[1], pos[2], vel[0], vel[1], vel[2], water,
143 force[0], force[1], force[2], addedLinearDrag);
144
145 // CalcDampingForces applies the added drag only when it is positive.
146 const double addedDragPerNode = addedLinearDrag > 0 ? addedLinearDrag / 3 : 0.0;
147 const double damping = m_panelForceParams.dampingCoeff;
148 for (int node = 0; node < 3; ++node) {
149 for (int j = 0; j < 3; ++j) {
150 for (int k = 0; k < 3; ++k) {
151 for (int group = 0; group < 3; ++group)
152 dF[node][group][3 * j + k] = force[node][j].Grad(3 * group + k);
153
154 const double diagonal = (j == k) ? 1.0 : 0.0;
155 const double lawPart = (force[node][j].Grad(kVelocitySlot + k) + diagonal * addedDragPerNode) / 3;
156 for (int other = 0; other < 3; ++other) {
157 const double self = (other == node) ? 1.0 : 0.0;
158 dF[node][3 + other][3 * j + k] = lawPart
159 + diagonal * (damping * (1.0 / 3.0 - self) - addedDragPerNode * self);
160 }
161 }
162 }
163 }
164 }
165
181 hydrodynamics::PanelLoad<double> EvaluatePanelLoad(const hydrodynamics::PanelLoadLaw& law, const hydrodynamics::Fluid& fluid,
182 const double* const posA_ned, const double* const posB_ned, const double* const posC_ned,
183 const double elementVel[3], const double waterVel_ned[3], double& area) const
184 {
186 net_element_forces::ComputePanelFrame(m_panelForceParams, posA_ned, posB_ned, posC_ned);
187 area = frame.area;
188 return net_element_forces::EvaluatePanelLoad(m_panelForceParams, frame, law, fluid,
189 Solidity(frame.meshOpeningAngle), elementVel, waterVel_ned);
190 }
191
193 bool HasBarDirections() const { return m_meshDet != 0; }
194
196 double Solidity(double meshOpeningAngle) const { return net_solidity::Solidity(m_solidity, m_barD, m_barL0, meshOpeningAngle); }
197
199 double Solidity(const double* const posA_ned, const double* const posB_ned, const double* const posC_ned) const
200 {
201 return Solidity(net_element_forces::ComputePanelFrame(m_panelForceParams, posA_ned, posB_ned, posC_ned).meshOpeningAngle);
202 }
203
205 double WakeSolidity(const double* const posA_ned, const double* const posB_ned, const double* const posC_ned) const
206 {
207 return net_solidity::WakeSolidity(m_solidity, m_barD, m_barL0,
208 net_element_forces::ComputePanelFrame(m_panelForceParams, posA_ned, posB_ned, posC_ned).meshOpeningAngle);
209 }
210
212 double CalcNodeInertia(int node);
213
214#ifdef FH_VISUALIZATION
216 void RenderInit(Ogre::Root* ogreRoot, int NumMeshPerLine = 1);
217
219 void RenderUpdate( const double* const adPosA, const double* const adPosB,
220 const double* const adPosC );
221#endif
222
223
224private:
226 void FillPanelForceParams();
227
228 // Input
229 unsigned long m_iD;
230 std::string m_netName;
231 double m_nodeInertia[3];
232 //double m_rho_water; ///< Density of water.
233 //double m_rho_twines; ///< Material density of twines.
234 //double m_EModulus; ///< E-modulus of twine material.
235 double m_barD;
236 double m_knotD;
237 double m_barL0;
238 double m_nodeAPos_mesh[2];
239 double m_nodeBPos_mesh[2];
240 double m_nodeCPos_mesh[2];
241
242 // Calculated element properties
243 //double m_twineCrossSecArea; ///< The cross sectional area of each twine.
244 double m_nodesDistAB_mesh[2];
245 double m_nodesDistAC_mesh[2];
246 double m_nodesDistBC_mesh[2];
247 double m_meshDet;
248 double m_numMeshes;
249 double m_numUBars;
250 double m_numVBars;
251 double m_numKnots;
252 double m_weight;
253 double m_eATwine;
254
255 double m_NodeWeight;
256 double m_nodeAforce_ned[3];
257 double m_nodeBforce_ned[3];
258 double m_nodeCforce_ned[3];
259 double m_dampingCoeff;
260
262 net_element_forces::PanelParams m_panelForceParams;
264 net_solidity::PanelSolidity m_solidity;
265#ifdef FILTER_FORCES
266 double m_nodeAforce_ned_last[3];
267 double m_nodeBforce_ned_last[3];
268 double m_nodeCforce_ned_last[3];
269#endif
270
271#ifdef FH_VISUALIZATION
272 // Visualization specifics
273 Ogre::Root* m_ogreRoot;
274 Ogre::SceneManager* m_sceneMgr;
275 Ogre::Entity* m_renderElement[3];
276 Ogre::Entity* m_renderSphere[3];
277 Ogre::SceneNode* m_renderNodeMesh;
278 Ogre::SceneNode* m_renderNodeSphere[3];
279 Ogre::SceneNode* m_renderNodeOutline;
280 Ogre::SceneNode* m_renderNodeMaterial;
281#ifdef USE_DYNAMIC_LINES
282 C3DLine* m_lines = nullptr;
283#else
284 C3DLine* m_lines = nullptr;
285 Ogre::ColourValue m_twineColour;
286#endif
287 C3DLine* m_lineOutline;
288 //Ogre::ManualObject * m_netRenderObj; ///< The manual object used for rendering the net element with a triangle skin.
289
290 // Visualization variables
291 unsigned short* m_sortU = nullptr;
292 unsigned short* m_sortV = nullptr;
293 unsigned long m_numTwines;
294 unsigned long m_numUTwines;
295 unsigned long m_numVTwines;
296 double* m_interpCoeffAu = nullptr;
297 double* m_interpCoeffAv = nullptr;
298 double* m_interpCoeffBu = nullptr;
299 double* m_interpCoeffBv = nullptr;
300 int m_NumMeshPerLine;
301#endif
302
303};
304
305
306#endif
Definition NetElement3N.h:37
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:82
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:199
bool HasBarDirections() const
True when the bar directions are defined, which needs a non-zero mesh determinant.
Definition NetElement3N.h:193
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:121
NetElement3N(const std::string netName, const unsigned long iID, const NetElementDef *netPanel, const double dRho_water, const double knotDiameter, const double knotMomStiff, const double dKknotMomStiff_contact, const net_solidity::PanelSolidity &solidity, const double dampingRatio)
The constructor.
double Solidity(double meshOpeningAngle) const
The solidity of the element at the given mesh half opening angle [rad].
Definition NetElement3N.h:196
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:181
~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:205
Class containing the description of a net panel and methods necessary for taking this over to triangu...
Definition NetElementDef.h:22
Definition NetElement3NForces.h:83
T meshOpeningAngle
The mesh half opening angle, rad; 0 when undefined.
Definition NetElement3NForces.h:87
T area
The element's area, m^2.
Definition NetElement3NForces.h:88
Definition NetElement3NForces.h:59
double dampingCoeff
Coefficient of the rotational and structural damping.
Definition NetElement3NForces.h:72