From 12006cd5a709fcf6fb8a27118087384eb7988851 Mon Sep 17 00:00:00 2001 From: gaoflow Date: Mon, 1 Jun 2026 20:22:31 +0200 Subject: [PATCH] Fix NameError in Subsystem.getYawStiffness (undefined 'l') getYawStiffness computed (tau0/l)*rad_fair**2 + tau0*rad_fair, but 'l' was never defined in the method, so every call raised 'NameError: name "l" is not defined'. The variable is a leftover from the rename of the line length to 'span' (commit 2f330c8, "Subsystem updates for span consistency") which missed this one site. Use self.span (the horizontal end-to-end distance) as intended, and add a regression test exercising the formula. --- moorpy/subsystem.py | 2 +- tests/test_subsystem.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/moorpy/subsystem.py b/moorpy/subsystem.py index 71b6004..dd282e0 100644 --- a/moorpy/subsystem.py +++ b/moorpy/subsystem.py @@ -902,7 +902,7 @@ def getYawStiffness(self): tau0 = -self.fB[0] # horizontal tension component [N] - yaw_stiff = (tau0/l)*self.rad_fair**2 + tau0*self.rad_fair # [N-m] + yaw_stiff = (tau0/self.span)*self.rad_fair**2 + tau0*self.rad_fair # [N-m] return yaw_stiff diff --git a/tests/test_subsystem.py b/tests/test_subsystem.py index 7f3f2ef..6f7b612 100644 --- a/tests/test_subsystem.py +++ b/tests/test_subsystem.py @@ -12,6 +12,24 @@ import matplotlib.pyplot as plt +def test_getYawStiffness_runs(): + """Subsystem.getYawStiffness must not raise NameError. + + Regression test: the yaw-stiffness formula referenced an undefined local + ``l`` (a leftover from the rename of line length to ``span``), so every + call raised ``NameError: name 'l' is not defined``. It should instead use + ``self.span`` and return ``(tau0/span)*rad_fair**2 + tau0*rad_fair``. + """ + ss = mp.Subsystem(depth=100, span=200, rad_fair=10, z_fair=-10) + # getYawStiffness reads the horizontal fairlead force fB (set during a + # solve); inject a representative value to exercise the formula directly. + ss.fB = np.array([-1.0e5, 0.0, 5.0e4]) + + tau0 = -ss.fB[0] + expected = (tau0 / ss.span) * ss.rad_fair**2 + tau0 * ss.rad_fair + assert_allclose(ss.getYawStiffness(), expected) + + """ def test_tensions_swap(): '''Compares two equivalent catenary mooring lines that are defined in opposite directions.'''