1
1
from math import ceil
2
- from typing import List
3
2
from typing import Dict
3
+ from typing import List
4
4
5
+ from numpy import all
6
+ from numpy import array
5
7
from numpy import float64
6
- from numpy import seterr
7
8
from numpy import isinf
8
9
from numpy import isnan
9
- from numpy import all
10
- from numpy import array
11
- from numpy import zeros
12
10
from numpy import ones
11
+ from numpy import seterr
12
+ from numpy import zeros
13
13
from numpy .linalg import norm
14
14
from scipy .sparse import diags
15
15
16
- from compas .numerical import connectivity_matrix
17
- from compas .numerical import normrow
18
-
19
16
from compas .geometry import cross_vectors
20
17
from compas .geometry import length_vector
21
18
from compas .geometry import length_vector_sqrd
22
-
19
+ from compas .linalg import normrow
20
+ from compas .matrices import connectivity_matrix
23
21
from compas_bender .datastructures import BendNetwork
24
22
25
23
PI = 3.14159
@@ -61,20 +59,20 @@ def bend_splines(
61
59
# --------------------------------------------------------------------------
62
60
# maps
63
61
# --------------------------------------------------------------------------
64
- key_index = network .key_index ()
65
- uv_index = network .uv_index ()
62
+ node_index = network .node_index ()
63
+ edge_index = network .edge_index ()
66
64
# --------------------------------------------------------------------------
67
65
# attribute lists
68
66
# --------------------------------------------------------------------------
69
67
num_v = network .number_of_nodes ()
70
68
num_e = network .number_of_edges ()
71
69
anchors = list (network .nodes_where ({"is_anchor" : True }))
72
- fixed = [key_index [key ] for key in anchors ]
70
+ fixed = [node_index [key ] for key in anchors ]
73
71
free = list (set (range (num_v )) - set (fixed ))
74
72
xyz = network .nodes_attributes ("xyz" )
75
73
p = network .nodes_attributes (["px" , "py" , "pz" ])
76
74
edges = list (network .edges ())
77
- edges = [(key_index [u ], key_index [v ]) for u , v in edges ]
75
+ edges = [(node_index [u ], node_index [v ]) for u , v in edges ]
78
76
qpre = network .edges_attribute ("qpre" )
79
77
fpre = network .edges_attribute ("fpre" ) # kN
80
78
lpre = network .edges_attribute ("lpre" ) # m
@@ -116,19 +114,19 @@ def bend_splines(
116
114
# --------------------------------------------------------------------------
117
115
for cable in cables :
118
116
for edge in cable ["edges" ]:
119
- index = uv_index [edge ]
117
+ index = edge_index [edge ]
120
118
qpre [index , 0 ] = cable ["qpre" ]
121
119
# --------------------------------------------------------------------------
122
120
# preprocess splines
123
121
# --------------------------------------------------------------------------
124
122
spline_nodes = []
125
123
for spline in splines :
126
- spline ["vi" ] = [key_index [spline ["start" ]]]
124
+ spline ["vi" ] = [node_index [spline ["start" ]]]
127
125
spline ["ei" ] = []
128
126
for u , v in spline ["edges" ]:
129
- ui = key_index [u ]
130
- vi = key_index [v ]
131
- ei = uv_index [(u , v )]
127
+ ui = node_index [u ]
128
+ vi = node_index [v ]
129
+ ei = edge_index [(u , v )]
132
130
spline ["ei" ].append (ei )
133
131
if spline ["vi" ][- 1 ] == ui :
134
132
spline ["vi" ].append (vi )
@@ -165,14 +163,8 @@ def bend_splines(
165
163
spline ["E" ] = spline ["E" ] * units .E
166
164
spline ["radius" ] = spline ["radius" ] * units .radius
167
165
spline ["thickness" ] = spline ["thickness" ] * units .thickness
168
- spline ["A" ] = PI * (
169
- spline ["radius" ] ** 2 - (spline ["radius" ] - spline ["thickness" ]) ** 2
170
- )
171
- spline ["I" ] = (
172
- PI
173
- * (spline ["radius" ] ** 4 - (spline ["radius" ] - spline ["thickness" ]) ** 4 )
174
- / 4.0
175
- )
166
+ spline ["A" ] = PI * (spline ["radius" ] ** 2 - (spline ["radius" ] - spline ["thickness" ]) ** 2 )
167
+ spline ["I" ] = PI * (spline ["radius" ] ** 4 - (spline ["radius" ] - spline ["thickness" ]) ** 4 ) / 4.0
176
168
spline ["EA" ] = spline ["E" ] * spline ["A" ]
177
169
spline ["EI" ] = spline ["E" ] * spline ["I" ]
178
170
for i in spline ["ei" ]:
@@ -318,11 +310,7 @@ def acceleration(t, v):
318
310
Q = diags ([q .ravel ()], [0 ])
319
311
D = Cit .dot (Q ).dot (C )
320
312
# relax
321
- mass = (
322
- 0.5
323
- * dt ** 2
324
- * Ct2 .dot (qpre + q_fpre + q_lpre + EA / linit + 4 * EI / l ** 3 )
325
- )
313
+ mass = 0.5 * dt ** 2 * Ct2 .dot (qpre + q_fpre + q_lpre + EA / linit + 4 * EI / l ** 3 )
326
314
xyz0 = xyz .copy ()
327
315
v0 = ca * v .copy ()
328
316
dv = rk4 ()
@@ -346,7 +334,7 @@ def acceleration(t, v):
346
334
# update
347
335
# --------------------------------------------------------------------------
348
336
for key , attr in network .nodes (True ):
349
- index = key_index [key ]
337
+ index = node_index [key ]
350
338
attr ["x" ] = xyz [index , 0 ]
351
339
attr ["y" ] = xyz [index , 1 ]
352
340
attr ["z" ] = xyz [index , 2 ]
@@ -360,7 +348,7 @@ def acceleration(t, v):
360
348
attr ["my" ] = m [index , 1 ]
361
349
attr ["mz" ] = m [index , 2 ]
362
350
for key , attr in network .edges (True ):
363
- index = uv_index [key ]
351
+ index = edge_index [key ]
364
352
attr ["q" ] = q [index , 0 ]
365
353
attr ["f" ] = f [index , 0 ]
366
354
attr ["l" ] = l [index , 0 ]
0 commit comments