Skip to content

Commit 93aa33b

Browse files
committed
migration
1 parent 0b2d24f commit 93aa33b

File tree

5 files changed

+25
-94
lines changed

5 files changed

+25
-94
lines changed

src/compas_bender/__init__.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
1-
"""
2-
********************************************************************************
3-
compas_bender
4-
********************************************************************************
5-
6-
.. currentmodule:: compas_bender
7-
8-
9-
.. toctree::
10-
:maxdepth: 1
11-
12-
compas_bender.bend
13-
compas_bender.datastructures
14-
compas_bender.rhino
15-
16-
"""
17-
18-
from __future__ import print_function
19-
201
import os
212

22-
233
__author__ = ["tom van mele"]
244
__copyright__ = "ETH Zurich - Block Research Group"
255
__license__ = "MIT License"

src/compas_bender/bend/__init__.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,3 @@
1-
"""
2-
********************************************************************************
3-
bend
4-
********************************************************************************
5-
6-
.. currentmodule:: compas_bender.bend
7-
8-
9-
Functions
10-
=========
11-
12-
.. autosummary::
13-
:toctree: generated/
14-
:nosignatures:
15-
16-
bend_splines
17-
18-
"""
19-
201
from .bend_splines import bend_splines
212

223
__all__ = ["bend_splines"]

src/compas_bender/bend/bend_splines.py

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
from math import ceil
2-
from typing import List
32
from typing import Dict
3+
from typing import List
44

5+
from numpy import all
6+
from numpy import array
57
from numpy import float64
6-
from numpy import seterr
78
from numpy import isinf
89
from numpy import isnan
9-
from numpy import all
10-
from numpy import array
11-
from numpy import zeros
1210
from numpy import ones
11+
from numpy import seterr
12+
from numpy import zeros
1313
from numpy.linalg import norm
1414
from scipy.sparse import diags
1515

16-
from compas.numerical import connectivity_matrix
17-
from compas.numerical import normrow
18-
1916
from compas.geometry import cross_vectors
2017
from compas.geometry import length_vector
2118
from compas.geometry import length_vector_sqrd
22-
19+
from compas.linalg import normrow
20+
from compas.matrices import connectivity_matrix
2321
from compas_bender.datastructures import BendNetwork
2422

2523
PI = 3.14159
@@ -61,20 +59,20 @@ def bend_splines(
6159
# --------------------------------------------------------------------------
6260
# maps
6361
# --------------------------------------------------------------------------
64-
key_index = network.key_index()
65-
uv_index = network.uv_index()
62+
node_index = network.node_index()
63+
edge_index = network.edge_index()
6664
# --------------------------------------------------------------------------
6765
# attribute lists
6866
# --------------------------------------------------------------------------
6967
num_v = network.number_of_nodes()
7068
num_e = network.number_of_edges()
7169
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]
7371
free = list(set(range(num_v)) - set(fixed))
7472
xyz = network.nodes_attributes("xyz")
7573
p = network.nodes_attributes(["px", "py", "pz"])
7674
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]
7876
qpre = network.edges_attribute("qpre")
7977
fpre = network.edges_attribute("fpre") # kN
8078
lpre = network.edges_attribute("lpre") # m
@@ -116,19 +114,19 @@ def bend_splines(
116114
# --------------------------------------------------------------------------
117115
for cable in cables:
118116
for edge in cable["edges"]:
119-
index = uv_index[edge]
117+
index = edge_index[edge]
120118
qpre[index, 0] = cable["qpre"]
121119
# --------------------------------------------------------------------------
122120
# preprocess splines
123121
# --------------------------------------------------------------------------
124122
spline_nodes = []
125123
for spline in splines:
126-
spline["vi"] = [key_index[spline["start"]]]
124+
spline["vi"] = [node_index[spline["start"]]]
127125
spline["ei"] = []
128126
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)]
132130
spline["ei"].append(ei)
133131
if spline["vi"][-1] == ui:
134132
spline["vi"].append(vi)
@@ -165,14 +163,8 @@ def bend_splines(
165163
spline["E"] = spline["E"] * units.E
166164
spline["radius"] = spline["radius"] * units.radius
167165
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
176168
spline["EA"] = spline["E"] * spline["A"]
177169
spline["EI"] = spline["E"] * spline["I"]
178170
for i in spline["ei"]:
@@ -318,11 +310,7 @@ def acceleration(t, v):
318310
Q = diags([q.ravel()], [0])
319311
D = Cit.dot(Q).dot(C)
320312
# 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)
326314
xyz0 = xyz.copy()
327315
v0 = ca * v.copy()
328316
dv = rk4()
@@ -346,7 +334,7 @@ def acceleration(t, v):
346334
# update
347335
# --------------------------------------------------------------------------
348336
for key, attr in network.nodes(True):
349-
index = key_index[key]
337+
index = node_index[key]
350338
attr["x"] = xyz[index, 0]
351339
attr["y"] = xyz[index, 1]
352340
attr["z"] = xyz[index, 2]
@@ -360,7 +348,7 @@ def acceleration(t, v):
360348
attr["my"] = m[index, 1]
361349
attr["mz"] = m[index, 2]
362350
for key, attr in network.edges(True):
363-
index = uv_index[key]
351+
index = edge_index[key]
364352
attr["q"] = q[index, 0]
365353
attr["f"] = f[index, 0]
366354
attr["l"] = l[index, 0]

src/compas_bender/datastructures/__init__.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,3 @@
1-
"""
2-
********************************************************************************
3-
datastructures
4-
********************************************************************************
5-
6-
.. currentmodule:: compas_bender.datastructures
7-
8-
9-
Classes
10-
=======
11-
12-
.. autosummary::
13-
:toctree: generated/
14-
:nosignatures:
15-
16-
BendNetwork
17-
18-
"""
191
from __future__ import print_function
202
from __future__ import absolute_import
213
from __future__ import division

src/compas_bender/datastructures/bendnetwork.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
from __future__ import print_function
21
from __future__ import absolute_import
32
from __future__ import division
3+
from __future__ import print_function
44

5-
from compas.geometry import Vector
6-
from compas.geometry import Point
7-
from compas.geometry import Line
85
from compas.datastructures import Network
6+
from compas.geometry import Line
7+
from compas.geometry import Point
8+
from compas.geometry import Vector
99

1010

1111
class BendNetwork(Network):

0 commit comments

Comments
 (0)