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_MATERIAL
30//#define FILTER_FORCES
31//#define CNETELEMENT3N_TRANSPARENT
32
33class CDynamicLines; // forward declaration
34
37{
41 bool twineStructure = true;
42 double dampingRatio = 1.0;
43};
44
46{
47public:
59 const std::string netName,
60 const unsigned long iID,
61 const NetElementDef* netPanel,
62 const double dRho_water,
63 const double knotDiameter,
64 const net_solidity::PanelSolidity& solidity,
65 const NetPanelOptions& options
66 );
67
70
71 // Owns raw visualization buffers (freed in the destructor), so it must not be copied.
72 NetElement3N(const NetElement3N&) = delete;
73 NetElement3N& operator=(const NetElement3N&) = delete;
74
98 template<class T, class Law>
99 bool AddNodeForces(const Law& 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 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 return 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, clampLog);
112 }
113
130 void NodeForceJacobian(const hydrodynamics::PanelLoadLaw& law, const hydrodynamics::Fluid& fluid,
131 const double posA_ned[3], const double posB_ned[3], const double posC_ned[3],
132 const double velA_ned[3], const double velB_ned[3], const double velC_ned[3],
133 const double waterVel_ned[3], double dF[3][6][9]) const
134 {
135 using Dual = sfh::ad::Dual<18>;
136 const int kVelocitySlot = 9;
137
138 Dual pos[3][3], vel[3][3], water[3];
139 const double* posIn[3] = {posA_ned, posB_ned, posC_ned};
140 const double* velIn[3] = {velA_ned, velB_ned, velC_ned};
141 for (int node = 0; node < 3; ++node) {
142 for (int k = 0; k < 3; ++k) {
143 pos[node][k] = Dual::Variable(posIn[node][k], 3 * node + k);
144 vel[node][k] = Dual::Variable(velIn[node][k], kVelocitySlot + 3 * node + k);
145 }
146 }
147 for (int k = 0; k < 3; ++k)
148 water[k] = Dual(waterVel_ned[k]);
149
150 Dual force[3][3];
151 AddNodeForces<Dual>(law, fluid, pos[0], pos[1], pos[2], vel[0], vel[1], vel[2], water,
152 force[0], force[1], force[2]);
153
154 for (int node = 0; node < 3; ++node)
155 for (int group = 0; group < 6; ++group)
156 for (int j = 0; j < 3; ++j)
157 for (int k = 0; k < 3; ++k)
158 dF[node][group][3 * j + k] = force[node][j].Grad(3 * group + k);
159 }
160
176 hydrodynamics::PanelLoad<double> EvaluatePanelLoad(const hydrodynamics::PanelLoadLaw& law, const hydrodynamics::Fluid& fluid,
177 const double* const posA_ned, const double* const posB_ned, const double* const posC_ned,
178 const double elementVel[3], const double waterVel_ned[3], double& area) const
179 {
181 net_element_forces::ComputePanelFrame(m_panelForceParams, posA_ned, posB_ned, posC_ned);
182 area = frame.area;
183 return net_element_forces::EvaluatePanelLoad(m_panelForceParams, frame, law, fluid,
184 Solidity(frame.meshOpeningAngle), elementVel, waterVel_ned);
185 }
186
188 bool HasBarDirections() const { return m_meshDet != 0; }
189
191 double Solidity(double meshOpeningAngle) const { return net_solidity::Solidity(m_solidity, m_barD, m_barL0, meshOpeningAngle); }
192
194 double Solidity(const double* const posA_ned, const double* const posB_ned, const double* const posC_ned) const
195 {
196 return Solidity(net_element_forces::ComputePanelFrame(m_panelForceParams, posA_ned, posB_ned, posC_ned).meshOpeningAngle);
197 }
198
200 double WakeSolidity(const double* const posA_ned, const double* const posB_ned, const double* const posC_ned) const
201 {
202 return net_solidity::WakeSolidity(m_solidity, m_barD, m_barL0,
203 net_element_forces::ComputePanelFrame(m_panelForceParams, posA_ned, posB_ned, posC_ned).meshOpeningAngle);
204 }
205
207 double CalcNodeInertia(int node);
208
211 double NumberOfTwineLengthsU() const;
212
214 double TwineDiameter() const { return m_barD; }
215
216#ifdef FH_VISUALIZATION
218 void RenderInit(Ogre::Root* ogreRoot, int NumMeshPerLine = 1);
219
221 void RenderUpdate( const double* const adPosA, const double* const adPosB,
222 const double* const adPosC );
223#endif
224
225
226private:
228 void FillPanelForceParams();
229
230 // Input
231 unsigned long m_iD;
232 std::string m_netName;
233 double m_nodeInertia[3];
234 //double m_rho_water; ///< Density of water.
235 //double m_rho_twines; ///< Material density of twines.
236 //double m_EModulus; ///< E-modulus of twine material.
237 double m_barD;
238 double m_knotD;
239 double m_barL0;
240 double m_nodeAPos_mesh[2];
241 double m_nodeBPos_mesh[2];
242 double m_nodeCPos_mesh[2];
243
244 // Calculated element properties
245 //double m_twineCrossSecArea; ///< The cross sectional area of each twine.
246 double m_nodesDistAB_mesh[2];
247 double m_nodesDistAC_mesh[2];
248 double m_nodesDistBC_mesh[2];
249 double m_meshDet;
250 double m_numMeshes;
251 double m_numUBars;
252 double m_numVBars;
253 double m_numKnots;
254 double m_weight;
255 double m_eATwine;
256
257 double m_NodeWeight;
258 double m_nodeAforce_ned[3];
259 double m_nodeBforce_ned[3];
260 double m_nodeCforce_ned[3];
261 double m_dampingCoeff;
262 double m_tensionDampingTime;
263
265 NetPanelOptions m_options;
266 net_element_forces::PanelParams m_panelForceParams;
268 net_solidity::PanelSolidity m_solidity;
269#ifdef FILTER_FORCES
270 double m_nodeAforce_ned_last[3];
271 double m_nodeBforce_ned_last[3];
272 double m_nodeCforce_ned_last[3];
273#endif
274
275#ifdef FH_VISUALIZATION
276 // Visualization specifics
277 Ogre::Root* m_ogreRoot;
278 Ogre::SceneManager* m_sceneMgr;
279 Ogre::Entity* m_renderElement[3];
280 Ogre::SceneNode* m_renderNodeMesh;
281 Ogre::SceneNode* m_renderNodeOutline;
282 Ogre::SceneNode* m_renderNodeMaterial;
283#ifdef USE_DYNAMIC_LINES
284 C3DLine* m_lines = nullptr;
285#else
286 C3DLine* m_lines = nullptr;
287 Ogre::ColourValue m_twineColour;
288#endif
289 C3DLine* m_lineOutline;
290 //Ogre::ManualObject * m_netRenderObj; ///< The manual object used for rendering the net element with a triangle skin.
291
292 // Visualization variables
293 unsigned short* m_sortU = nullptr;
294 unsigned short* m_sortV = nullptr;
295 unsigned long m_numTwines;
296 unsigned long m_numUTwines;
297 unsigned long m_numVTwines;
298 double* m_interpCoeffAu = nullptr;
299 double* m_interpCoeffAv = nullptr;
300 double* m_interpCoeffBu = nullptr;
301 double* m_interpCoeffBv = nullptr;
302 int m_NumMeshPerLine;
303#endif
304
305};
306
307
308#endif
Definition NetElement3N.h:46
double TwineDiameter() const
The twine diameter [m].
Definition NetElement3N.h:214
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:194
bool HasBarDirections() const
True when the bar directions are defined, which needs a non-zero mesh determinant.
Definition NetElement3N.h:188
double Solidity(double meshOpeningAngle) const
The solidity of the element at the given mesh half opening angle [rad].
Definition NetElement3N.h:191
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:176
~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:200
double NumberOfTwineLengthsU() const
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 dF[3][6][9]) const
Definition NetElement3N.h:130
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)
bool AddNodeForces(const Law &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, const hydrodynamics::PanelClampLog *clampLog=nullptr) const
Definition NetElement3N.h:99
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:37
double dampingRatio
NetDampingRatio: the damping ratio of the panel's stiffest stretch mode, 1 = critical....
Definition NetElement3N.h:42
bool twineStructure
Definition NetElement3N.h:41
Definition NetElement3NForces.h:118
T meshOpeningAngle
The mesh half opening angle, rad; 0 when undefined.
Definition NetElement3NForces.h:122
T area
The element's area, m^2.
Definition NetElement3NForces.h:123
Definition NetElement3NForces.h:90