FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
NetElement3NForces.h
1#pragma once
2
25#include <fhsim_environment/hydrodynamics/PanelClampLog.h>
26#include <fhsim_environment/hydrodynamics/PanelLoadLaw.h>
27
28#include <sfh/linalg/matrix_ops.h>
29#include <sfh/math/array.h>
30#include <sfh/math/math.h>
31#include <sfh/sim/kinematics.h>
32#include <sfh/util/diagnostic.h>
33
34#include <cmath>
35#include <type_traits>
36
37namespace net_element_forces
38{
39
41const double kMinMeshBarLength = 1.0e-10;
42
45const hydrodynamics::FlowReference kFlowReference = hydrodynamics::FlowReference::FreeStream;
46
47
58{
59 double nodesDistAB_mesh[2];
60 double nodesDistAC_mesh[2];
61 double nodesDistBC_mesh[2];
62 double meshDet;
63 double barL0;
64 double eATwine;
65 double barD;
66 double knotDiameter;
67 double numBarsU;
68 double numBarsV;
69 double numKnots;
70 double NodeWeight;
71 double dampingCoeff;
74 bool twineStructure = true;
75};
76
77
83template<class T>
92
93
104template<class T>
105void CalcLocalUVComponents(const PanelParams& params, const T distAB_panel[3],
106 const T distAC_panel[3], T meshBarComp[6], T meshBarLength[2])
107{
108 using std::sqrt;
109
110 meshBarComp[0] = (params.nodesDistAC_mesh[1] * distAB_panel[0] - params.nodesDistAB_mesh[1] * distAC_panel[0]) / params.meshDet;
111 meshBarComp[1] = (params.nodesDistAC_mesh[1] * distAB_panel[1] - params.nodesDistAB_mesh[1] * distAC_panel[1]) / params.meshDet;
112 meshBarComp[2] = T(0.0);
113 meshBarComp[3] = (params.nodesDistAB_mesh[0] * distAC_panel[0] - params.nodesDistAC_mesh[0] * distAB_panel[0]) / params.meshDet;
114 meshBarComp[4] = (params.nodesDistAB_mesh[0] * distAC_panel[1] - params.nodesDistAC_mesh[0] * distAB_panel[1]) / params.meshDet;
115 meshBarComp[5] = T(0.0);
116
117 meshBarLength[0] = sfh::math::Max(
118 sqrt(meshBarComp[0] * meshBarComp[0] + meshBarComp[1] * meshBarComp[1]),
119 T(kMinMeshBarLength));
120 meshBarLength[1] = sfh::math::Max(
121 sqrt(meshBarComp[3] * meshBarComp[3] + meshBarComp[4] * meshBarComp[4]),
122 T(kMinMeshBarLength));
123}
124
125
135template<class T>
136PanelFrame<T> ComputePanelFrame(const PanelParams& params, const T* const posA_ned,
137 const T* const posB_ned, const T* const posC_ned)
138{
139 using std::acos;
140 using std::sqrt;
141
142 PanelFrame<T> frame;
143 sfh::sim::RMatrixFromThreePoints(posA_ned, posB_ned, posC_ned, frame.R_ned2panel);
144
145 // The panel-frame separations. They are held as 3-vectors although the third component
146 // is always zero, so that the standard rotation and array routines apply.
147 T distAB_ned[3], distAC_ned[3];
148 T distAB_panel[3], distAC_panel[3];
149 sfh::math::ArraySubtract(posB_ned, posA_ned, distAB_ned, 3ul);
150 sfh::math::ArraySubtract(posC_ned, posA_ned, distAC_ned, 3ul);
151 sfh::sim::RotateToLocal(distAB_ned, frame.R_ned2panel, distAB_panel);
152 sfh::sim::RotateToLocal(distAC_ned, frame.R_ned2panel, distAC_panel);
153
154 CalcLocalUVComponents(params, distAB_panel, distAC_panel, frame.meshBarComp,
155 frame.meshBarLength);
156
157 // The mesh half opening angle, from the scalar product of the u- and v-bar vectors
158 // (Priour, 2001, p. 232). The positive mesh directions must be defined so that the half
159 // angle is the one between bars that would naturally tend to close.
160 T normBarCompU = T(0);
161 T normBarCompV = T(0);
162 for (int i = 0; i < 3; i++) {
163 normBarCompU += frame.meshBarComp[i] * frame.meshBarComp[i];
164 normBarCompV += frame.meshBarComp[i + 3] * frame.meshBarComp[i + 3];
165 }
166 normBarCompU = sqrt(normBarCompU);
167 normBarCompV = sqrt(normBarCompV);
168
169 frame.meshOpeningAngle = 0.5 * acos(sfh::linalg::Dot(frame.meshBarComp, frame.meshBarComp + 3, 2ul) / (normBarCompU * normBarCompV));
170 if (!(frame.meshOpeningAngle == frame.meshOpeningAngle)) frame.meshOpeningAngle = T(0);
171
172 // In the panel frame AB lies along x and the element in the xy-plane.
173 frame.area = 0.5 * sfh::math::Abs(distAB_panel[0] * distAC_panel[1] - distAB_panel[1] * distAC_panel[0]);
174 return frame;
175}
176
177
183template<class T>
184void CalcTensionForces(const PanelParams& params, const T meshBarComp[6],
185 const T meshBarLength[2], T nodeATension_panel[3], T nodeBTension_panel[3],
186 T nodeCTension_panel[3])
187{
188 // The original multiplied by the `bool` of this comparison. That promotes to 1.0 or 0.0
189 // for a built-in type but discards the derivative of a differentiable one, so the branch
190 // is written out. The retained branch is the original expression unchanged, and
191 // multiplying it by an exact 1.0 was exact, so the `double` value is unaffected.
192 T twineTension[2];
193 twineTension[0] = (meshBarLength[0] > params.barL0)
194 ? params.eATwine * (meshBarLength[0] - params.barL0) / params.barL0
195 : T(0.0);
196 twineTension[1] = (meshBarLength[1] > params.barL0)
197 ? params.eATwine * (meshBarLength[1] - params.barL0) / params.barL0
198 : T(0.0);
199 twineTension[0] = sfh::math::Max(twineTension[0], T(0.0));
200 twineTension[1] = sfh::math::Max(twineTension[1], T(0.0));
201
202 nodeATension_panel[0] = params.nodesDistBC_mesh[1] * twineTension[0] * meshBarComp[0] / (2 * meshBarLength[0]) - params.nodesDistBC_mesh[0] * twineTension[1] * meshBarComp[3] / (2 * meshBarLength[1]);
203 nodeATension_panel[1] = params.nodesDistBC_mesh[1] * twineTension[0] * meshBarComp[1] / (2 * meshBarLength[0]) - params.nodesDistBC_mesh[0] * twineTension[1] * meshBarComp[4] / (2 * meshBarLength[1]);
204 nodeATension_panel[2] = T(0.0);
205
206 nodeBTension_panel[0] = -params.nodesDistAC_mesh[1] * twineTension[0] * meshBarComp[0] / (2 * meshBarLength[0]) + params.nodesDistAC_mesh[0] * twineTension[1] * meshBarComp[3] / (2 * meshBarLength[1]);
207 nodeBTension_panel[1] = -params.nodesDistAC_mesh[1] * twineTension[0] * meshBarComp[1] / (2 * meshBarLength[0]) + params.nodesDistAC_mesh[0] * twineTension[1] * meshBarComp[4] / (2 * meshBarLength[1]);
208 nodeBTension_panel[2] = T(0.0);
209
210 nodeCTension_panel[0] = params.nodesDistAB_mesh[1] * twineTension[0] * meshBarComp[0] / (2 * meshBarLength[0]) - params.nodesDistAB_mesh[0] * twineTension[1] * meshBarComp[3] / (2 * meshBarLength[1]);
211 nodeCTension_panel[1] = params.nodesDistAB_mesh[1] * twineTension[0] * meshBarComp[1] / (2 * meshBarLength[0]) - params.nodesDistAB_mesh[0] * twineTension[1] * meshBarComp[4] / (2 * meshBarLength[1]);
212 nodeCTension_panel[2] = T(0.0);
213}
214
215
232template<class T>
233hydrodynamics::PanelLoad<T> EvaluatePanelLoad(const PanelParams& params, const PanelFrame<T>& frame,
234 const hydrodynamics::PanelLoadLaw& law, const hydrodynamics::Fluid& fluid, const T& solidity,
235 const T elementVel_ned[3], const T* const waterVel_ned)
236{
237 hydrodynamics::PanelGeometry<T> geometry;
238 geometry.area = frame.area;
239
240 hydrodynamics::Netting<T> netting;
241 netting.solidity = solidity;
242 netting.twineThickness = params.barD;
243 netting.hasBarDirections = params.meshDet != 0;
244 netting.barLength = params.barL0;
245 netting.knotDiameter = params.knotDiameter;
246 netting.numBarsU = params.numBarsU;
247 netting.numBarsV = params.numBarsV;
248 netting.numKnots = params.numKnots;
249
250 hydrodynamics::FlowSample<T> flow;
251 flow.reference = kFlowReference;
252
253 for (int i = 0; i < 3; i++) {
254 geometry.normal[i] = frame.R_ned2panel[i][2];
255 flow.relativeVelocity[i] = waterVel_ned[i] - elementVel_ned[i];
256
257 // The bars lie in the panel's xy-plane; rotate them to the global frame and normalise.
258 const T barU = frame.R_ned2panel[i][0] * frame.meshBarComp[0] + frame.R_ned2panel[i][1] * frame.meshBarComp[1];
259 const T barV = frame.R_ned2panel[i][0] * frame.meshBarComp[3] + frame.R_ned2panel[i][1] * frame.meshBarComp[4];
260 netting.barU[i] = barU / frame.meshBarLength[0];
261 netting.barV[i] = barV / frame.meshBarLength[1];
262 }
263
264 return hydrodynamics::Evaluate(law, geometry, netting, fluid, flow);
265}
266
267
269template<class T>
270void CalcDampingForces(const PanelParams& params, const T elementVel_ned[3],
271 const T* const velA_ned, const T* const velB_ned, const T* const velC_ned,
272 T dampingForcesNodeA_ned[3], T dampingForcesNodeB_ned[3],
273 T dampingForcesNodeC_ned[3], double addedLinearDrag)
274{
275 for (unsigned short i = 0; i < 3; i++) {
276 dampingForcesNodeA_ned[i] = params.dampingCoeff * (elementVel_ned[i] - velA_ned[i]);
277 dampingForcesNodeB_ned[i] = params.dampingCoeff * (elementVel_ned[i] - velB_ned[i]);
278 dampingForcesNodeC_ned[i] = params.dampingCoeff * (elementVel_ned[i] - velC_ned[i]);
279 }
280
281 if (addedLinearDrag > 0) {
282 for (unsigned short i = 0; i < 3; i++) {
283 dampingForcesNodeA_ned[i] -= addedLinearDrag / 3 * velA_ned[i];
284 dampingForcesNodeB_ned[i] -= addedLinearDrag / 3 * velB_ned[i];
285 dampingForcesNodeC_ned[i] -= addedLinearDrag / 3 * velC_ned[i];
286 }
287 }
288}
289
290
313template<class T>
314bool AddNodeForces(const PanelParams& params, const PanelFrame<T>& frame,
315 const hydrodynamics::PanelLoadLaw& law, const hydrodynamics::Fluid& fluid, const T& solidity,
316 const T* const velA_ned, const T* const velB_ned, const T* const velC_ned,
317 const T* const waterVel_ned, T* const nodeAforce_ned, T* const nodeBforce_ned,
318 T* const nodeCforce_ned, double addedLinearDrag = 0.0,
319 const hydrodynamics::PanelClampLog* clampLog = nullptr)
320{
321 T nodeATension_panel[3] = {T(0), T(0), T(0)};
322 T nodeBTension_panel[3] = {T(0), T(0), T(0)};
323 T nodeCTension_panel[3] = {T(0), T(0), T(0)};
324 if (params.twineStructure)
325 CalcTensionForces(params, frame.meshBarComp, frame.meshBarLength, nodeATension_panel,
326 nodeBTension_panel, nodeCTension_panel);
327
328 T elementVel_ned[3];
329 for (int i = 0; i < 3; i++) {
330 elementVel_ned[i] = (velA_ned[i] + velB_ned[i] + velC_ned[i]) / 3.0;
331 }
332
333 const hydrodynamics::PanelLoad<T> load =
334 EvaluatePanelLoad(params, frame, law, fluid, solidity, elementVel_ned, waterVel_ned);
335 if (clampLog)
336 clampLog->Note(load.flags);
337
338 T dampingForcesNodeA_ned[3] = {T(0), T(0), T(0)};
339 T dampingForcesNodeB_ned[3] = {T(0), T(0), T(0)};
340 T dampingForcesNodeC_ned[3] = {T(0), T(0), T(0)};
341 if (params.twineStructure) {
342 CalcDampingForces(params, elementVel_ned, velA_ned, velB_ned, velC_ned,
343 dampingForcesNodeA_ned, dampingForcesNodeB_ned, dampingForcesNodeC_ned,
344 addedLinearDrag);
345
346 // Local z-components of the tension are zero, the element being plane.
347 sfh::sim::RotateFromLocalAndAdd(nodeATension_panel, frame.R_ned2panel, nodeAforce_ned);
348 sfh::sim::RotateFromLocalAndAdd(nodeBTension_panel, frame.R_ned2panel, nodeBforce_ned);
349 sfh::sim::RotateFromLocalAndAdd(nodeCTension_panel, frame.R_ned2panel, nodeCforce_ned);
350 }
351
352 // The hydrodynamic force is shared equally between the three nodes.
353 for (int i = 0; i < 3; i++) {
354 const T hydroForcePerNode = load.force[i] / 3.0;
355 nodeAforce_ned[i] += hydroForcePerNode;
356 nodeBforce_ned[i] += hydroForcePerNode;
357 nodeCforce_ned[i] += hydroForcePerNode;
358 }
359
360 // The weight in water of the netting, distributed equally between the three nodes.
361 nodeAforce_ned[2] += params.NodeWeight;
362 nodeBforce_ned[2] += params.NodeWeight;
363 nodeCforce_ned[2] += params.NodeWeight;
364
365 if (params.twineStructure) {
366 for (unsigned short i = 0; i < 3; i++) {
367 nodeAforce_ned[i] += dampingForcesNodeA_ned[i];
368 nodeBforce_ned[i] += dampingForcesNodeB_ned[i];
369 nodeCforce_ned[i] += dampingForcesNodeC_ned[i];
370 }
371 } else if (addedLinearDrag > 0) {
372 // Without twine structure only the added linear drag of CalcDampingForces remains.
373 for (unsigned short i = 0; i < 3; i++) {
374 nodeAforce_ned[i] -= addedLinearDrag / 3 * velA_ned[i];
375 nodeBforce_ned[i] -= addedLinearDrag / 3 * velB_ned[i];
376 nodeCforce_ned[i] -= addedLinearDrag / 3 * velC_ned[i];
377 }
378 }
379
380 // The check reads raw `double` arrays, so it applies only to the `double` instantiation. The caller reports a
381 // failure: this kernel has no logger (MARE-0430).
382 if constexpr (std::is_same_v<T, double>) {
383 const unsigned long none = static_cast<unsigned long>(-1);
384 return sfh::util::FindBadValues(nodeAforce_ned, 3) == none && sfh::util::FindBadValues(nodeBforce_ned, 3) == none && sfh::util::FindBadValues(nodeCforce_ned, 3) == none;
385 } else {
386 return true;
387 }
388}
389
390} // namespace net_element_forces
Definition NetElement3NForces.h:85
T meshBarComp[6]
The u-bar in [0..2] and the v-bar in [3..5], panel frame.
Definition NetElement3NForces.h:87
T meshOpeningAngle
The mesh half opening angle, rad; 0 when undefined.
Definition NetElement3NForces.h:89
T R_ned2panel[3][3]
Columns: the panel x, y and z axes in the global frame.
Definition NetElement3NForces.h:86
T area
The element's area, m^2.
Definition NetElement3NForces.h:90
T meshBarLength[2]
The length of a u-bar and of a v-bar, bounded away from zero.
Definition NetElement3NForces.h:88
Definition NetElement3NForces.h:58
double meshDet
Mesh determinant, Priour (2005, Eq. 7); 0 for collinear corners.
Definition NetElement3NForces.h:62
double nodesDistBC_mesh[2]
Distance from node B to C in mesh (u,v) coordinates.
Definition NetElement3NForces.h:61
bool twineStructure
Definition NetElement3NForces.h:74
double knotDiameter
Diameter of the knots.
Definition NetElement3NForces.h:66
double eATwine
E-modulus times twine cross-sectional area.
Definition NetElement3NForces.h:64
double numKnots
Number of knots in the element, its number of meshes.
Definition NetElement3NForces.h:69
double nodesDistAB_mesh[2]
Distance from node A to B in mesh (u,v) coordinates.
Definition NetElement3NForces.h:59
double barD
Diameter of the twines.
Definition NetElement3NForces.h:65
double dampingCoeff
Definition NetElement3NForces.h:71
double NodeWeight
Weight in water carried by one node.
Definition NetElement3NForces.h:70
double barL0
Unstretched length of a mesh bar.
Definition NetElement3NForces.h:63
double numBarsV
Number of v-bars in the element, half its bar count.
Definition NetElement3NForces.h:68
double numBarsU
Number of u-bars in the element, half its bar count.
Definition NetElement3NForces.h:67
double nodesDistAC_mesh[2]
Distance from node A to C in mesh (u,v) coordinates.
Definition NetElement3NForces.h:60