Skip to content

Commit aa61de6

Browse files
committed
lines2ss is compatible with shared anchors:
- we differentiate points that are anchored using groundBody.attachedP. - when we delete a line and the attached point is also deleted, we update groundBody.attachedP to match the index of the points in the ms.
1 parent 1877739 commit aa61de6

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

moorpy/helpers.py

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,15 +1334,14 @@ def lines2ss(ms):
13341334
multi-segmented mooring lines with subsystems.
13351335
13361336
'''
1337-
13381337
i = 0
13391338
while True:
13401339
subsys_line_id = []
13411340
subsys_point_id = []
13421341
line_ID_of_interest = []
13431342
point_ID_of_interest = []
13441343
pointi = ms.pointList[i]
1345-
if len(pointi.attached) > 2:
1344+
if len(pointi.attached) > 2 and pointi.number not in ms.groundBody.attachedP:
13461345
raise ValueError("f point number {pointi.number} branches out.")
13471346
# 1) define the connected lines if any
13481347
subsys_line_id.append(pointi.attached[0])
@@ -1353,13 +1352,14 @@ def lines2ss(ms):
13531352
for line_id in subsys_line_id:
13541353
for pointj in ms.pointList:
13551354
if line_id in pointj.attached:
1356-
line_ID_of_interest.append(pointj.attached)
1355+
if pointj.number not in ms.groundBody.attachedP: # Do not consider anchors
1356+
line_ID_of_interest.append(pointj.attached)
13571357
point_ID_of_interest.append(pointj.number)
1358-
# if len(pointj.attached) > 2: # this is the case where we end the subsystem chain if the subsystem line is branching
1359-
# continue
1358+
# if len(pointj.attached) > 2: # this is the case where we end the subsystem chain if the subsystem line is branching
1359+
# continue
13601360
old_subsys_line = subsys_line_id
13611361
old_subsys_point = subsys_point_id
1362-
# 3) get the unique values
1362+
# 3) get the unique values
13631363
subsys_line_id = np.unique(np.concatenate(line_ID_of_interest))
13641364
subsys_point_id = np.unique(point_ID_of_interest)
13651365
if len(subsys_line_id) == len(old_subsys_line) and len(subsys_point_id) == len(old_subsys_point):
@@ -1416,32 +1416,12 @@ def lines2ss(ms):
14161416
ms = lines2subsystem(lines, points, ms, span=None, case=case)
14171417
ms.initialize()
14181418
ms.solveEquilibrium()
1419-
i += 1
1419+
i += 1
14201420
if i >= len(ms.pointList):
14211421
break
14221422

14231423
return ms
14241424

1425-
def lengthAwareSegmentation(lineList, factor=1):
1426-
'''Function to segment a set of lines based on their lengths
1427-
to give appropriate segment lengths.
1428-
1429-
Parameters
1430-
----------
1431-
lineList : list
1432-
List of line objects to segment
1433-
1434-
Returns
1435-
-------
1436-
None
1437-
1438-
'''
1439-
for line in lineList:
1440-
line.nNodes = int(np.ceil( np.sqrt(np.maximum(1, line.L-10))/2 ) + 1)
1441-
line.nNodes = int(line.nNodes * factor)
1442-
if line.nNodes == 1:
1443-
line.nNodes += 1 # minimum of 1 segment (two nodes)
1444-
14451425
def lines2subsystem(lines,points, ms,span=None,case=0):
14461426
'''Takes a set of connected lines (in order from rA to rB) in a moorpy system and creates a subsystem equivalent.
14471427
The original set of lines are then removed from the moorpy system and replaced with the
@@ -1558,6 +1538,26 @@ def lines2subsystem(lines,points, ms,span=None,case=0):
15581538

15591539
return(ms)
15601540

1541+
def lengthAwareSegmentation(lineList, factor=1):
1542+
'''Function to segment a set of lines based on their lengths
1543+
to give appropriate segment lengths.
1544+
1545+
Parameters
1546+
----------
1547+
lineList : list
1548+
List of line objects to segment
1549+
1550+
Returns
1551+
-------
1552+
None
1553+
1554+
'''
1555+
for line in lineList:
1556+
line.nNodes = int(np.ceil( np.sqrt(np.maximum(1, line.L-10))/2 ) + 1)
1557+
line.nNodes = int(line.nNodes * factor)
1558+
if line.nNodes == 1:
1559+
line.nNodes += 1 # minimum of 1 segment (two nodes)
1560+
15611561
def deleteLine(ms,ln,delpts=0):
15621562
'''
15631563
Deletes a line from the linelist, and updates the points to have the correct line
@@ -1640,6 +1640,10 @@ def deleteLine(ms,ln,delpts=0):
16401640
# reduce point.number for each point after deleted point
16411641
for k in range(0,len(ms.pointList)):
16421642
if ms.pointList[k].number > i + 1:
1643+
if ms.pointList[k].number in ms.groundBody.attachedP:
1644+
idx = ms.groundBody.attachedP.index(ms.pointList[k].number) # reduce the number in the groundBody attached points
1645+
ms.groundBody.attachedP[idx] -= 1
1646+
16431647
ms.pointList[k].number = ms.pointList[k].number - 1
16441648
# lower index of any body attached points after deleted point, remove deleted point from body attached points
16451649
for k in range(0,len(ms.bodyList)):

0 commit comments

Comments
 (0)