Skip to content

Commit 5ece656

Browse files
Added a Python mirror of the polyester line test (a friend complained about moordyn.GetPointForce())
1 parent a962ed2 commit 5ece656

File tree

3 files changed

+113
-2
lines changed

3 files changed

+113
-2
lines changed

tests/polyester.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ double get_average_tension(MoorDynLine line,
7373
REQUIRE(MoorDyn_GetPointForce(fairlead, force) == MOORDYN_SUCCESS);
7474
tension += vec_norm(force);
7575
for (unsigned int i = 0; i < n; i++) {
76-
REQUIRE(MoorDyn_GetLineNodeTen(line, i, force) == MOORDYN_SUCCESS);
76+
REQUIRE(MoorDyn_GetLineNodeTen(line, i + 1, force) == MOORDYN_SUCCESS);
7777
tension += vec_norm(force);
7878
}
7979
return tension / (n + 1);

tests/test_minimal.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import sys
21
from unittest import TestCase, main as unittest_main
32
import os
43
import tempfile

tests/test_poliester.py

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
from unittest import TestCase, main as unittest_main
2+
import os
3+
import csv
4+
import math
5+
import moordyn
6+
from test_minimal import setup_case
7+
8+
9+
MBL = 25.3e6
10+
KRS = 13.4
11+
KRD1 = 16.0
12+
KRD2 = 0.35
13+
TC = 200.0
14+
TTIMES = [320.0, 640.0, 960.0, 1280.0, 1599.0]
15+
TMEANS = [0.1, 0.2, 0.3, 0.4, 0.5]
16+
17+
18+
def vec_norm(v):
19+
return math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2])
20+
21+
22+
def get_average_tension(line, anchor, fairlead):
23+
n = moordyn.GetLineN(line)
24+
# To average the tensions along the line, we are considering the
25+
# connections instead of the line end up nodes, as long as the latter are
26+
# not that accurate
27+
tension = 0.0
28+
force = moordyn.GetPointForce(anchor)
29+
tension += vec_norm(force)
30+
force = moordyn.GetPointForce(fairlead)
31+
tension += vec_norm(force)
32+
for i in range(n):
33+
force = moordyn.GetLineNodeTen(line, i + 1)
34+
tension += vec_norm(force)
35+
return tension / (n + 1)
36+
37+
38+
class PoliesterTests(TestCase):
39+
def setUp(self):
40+
pass
41+
42+
def test_rampup_stabilization_cycles(self):
43+
global TTIMES, TMEANS
44+
45+
tmp_folder = setup_case("polyester/simple.txt")
46+
cwd = os.getcwd()
47+
os.chdir(tmp_folder)
48+
system = moordyn.Create()
49+
os.chdir(cwd)
50+
51+
n_dof = moordyn.NCoupledDOF(system)
52+
self.assertEqual(moordyn.NCoupledDOF(system), 3,
53+
"Incorrect number of DOFs")
54+
55+
anchor = moordyn.GetPoint(system, 1)
56+
fairlead = moordyn.GetPoint(system, 2)
57+
line = moordyn.GetLine(system, 1)
58+
59+
l0 = moordyn.GetLineUnstretchedLength(line)
60+
r = moordyn.GetPointPos(fairlead)
61+
dr = [0, 0, 0]
62+
moordyn.Init(system, r, dr)
63+
64+
tdata, xdata = [], []
65+
with open('Mooring/polyester/motion.csv') as csvfile:
66+
reader = csv.reader(csvfile, delimiter=',', quotechar='"')
67+
skip = 2
68+
for row in reader:
69+
if skip > 0:
70+
skip -= 1
71+
continue
72+
tdata.append(float(row[0]))
73+
xdata.append(float(row[1]))
74+
75+
t = 0
76+
times, tensions = [], []
77+
for i in range(len(tdata)):
78+
t_dst = tdata[i]
79+
x_dst = xdata[i]
80+
dt = t_dst - t
81+
dr[0] = (x_dst - r[0]) / dt
82+
f = moordyn.Step(system, r, dr, t, dt)
83+
t += dt
84+
times.append(t)
85+
tensions.append(get_average_tension(line, anchor, fairlead))
86+
87+
if (times[-1] - times[0] < TC):
88+
continue
89+
90+
tension = 0.0;
91+
for f in tensions:
92+
tension += f
93+
tension /= len(tensions)
94+
times = times[1:]
95+
tensions = tensions[1:]
96+
97+
ks = KRS * MBL
98+
kd = (KRD1 + KRD2 * tension / MBL * 100) * MBL
99+
l = l0 * (1.0 + tension / ks) / (1.0 + tension / kd)
100+
moordyn.SetLineConstantEA(line, kd)
101+
moordyn.SetLineUnstretchedLength(line, l)
102+
103+
if (t >= TTIMES[0]):
104+
tmean = TMEANS[0]
105+
TTIMES = TTIMES[1:]
106+
TMEANS = TMEANS[1:]
107+
assert(abs(tension / MBL - tmean) < 0.025)
108+
109+
moordyn.Close(system)
110+
111+
if __name__ == '__main__':
112+
unittest_main()

0 commit comments

Comments
 (0)