Skip to content

Commit

Permalink
migration
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed Mar 4, 2024
1 parent 0b2d24f commit 93aa33b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 94 deletions.
20 changes: 0 additions & 20 deletions src/compas_bender/__init__.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
"""
********************************************************************************
compas_bender
********************************************************************************
.. currentmodule:: compas_bender
.. toctree::
:maxdepth: 1
compas_bender.bend
compas_bender.datastructures
compas_bender.rhino
"""

from __future__ import print_function

import os


__author__ = ["tom van mele"]
__copyright__ = "ETH Zurich - Block Research Group"
__license__ = "MIT License"
Expand Down
19 changes: 0 additions & 19 deletions src/compas_bender/bend/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
"""
********************************************************************************
bend
********************************************************************************
.. currentmodule:: compas_bender.bend
Functions
=========
.. autosummary::
:toctree: generated/
:nosignatures:
bend_splines
"""

from .bend_splines import bend_splines

__all__ = ["bend_splines"]
54 changes: 21 additions & 33 deletions src/compas_bender/bend/bend_splines.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
from math import ceil
from typing import List
from typing import Dict
from typing import List

from numpy import all
from numpy import array
from numpy import float64
from numpy import seterr
from numpy import isinf
from numpy import isnan
from numpy import all
from numpy import array
from numpy import zeros
from numpy import ones
from numpy import seterr
from numpy import zeros
from numpy.linalg import norm
from scipy.sparse import diags

from compas.numerical import connectivity_matrix
from compas.numerical import normrow

from compas.geometry import cross_vectors
from compas.geometry import length_vector
from compas.geometry import length_vector_sqrd

from compas.linalg import normrow
from compas.matrices import connectivity_matrix
from compas_bender.datastructures import BendNetwork

PI = 3.14159
Expand Down Expand Up @@ -61,20 +59,20 @@ def bend_splines(
# --------------------------------------------------------------------------
# maps
# --------------------------------------------------------------------------
key_index = network.key_index()
uv_index = network.uv_index()
node_index = network.node_index()
edge_index = network.edge_index()
# --------------------------------------------------------------------------
# attribute lists
# --------------------------------------------------------------------------
num_v = network.number_of_nodes()
num_e = network.number_of_edges()
anchors = list(network.nodes_where({"is_anchor": True}))
fixed = [key_index[key] for key in anchors]
fixed = [node_index[key] for key in anchors]
free = list(set(range(num_v)) - set(fixed))
xyz = network.nodes_attributes("xyz")
p = network.nodes_attributes(["px", "py", "pz"])
edges = list(network.edges())
edges = [(key_index[u], key_index[v]) for u, v in edges]
edges = [(node_index[u], node_index[v]) for u, v in edges]
qpre = network.edges_attribute("qpre")
fpre = network.edges_attribute("fpre") # kN
lpre = network.edges_attribute("lpre") # m
Expand Down Expand Up @@ -116,19 +114,19 @@ def bend_splines(
# --------------------------------------------------------------------------
for cable in cables:
for edge in cable["edges"]:
index = uv_index[edge]
index = edge_index[edge]
qpre[index, 0] = cable["qpre"]
# --------------------------------------------------------------------------
# preprocess splines
# --------------------------------------------------------------------------
spline_nodes = []
for spline in splines:
spline["vi"] = [key_index[spline["start"]]]
spline["vi"] = [node_index[spline["start"]]]
spline["ei"] = []
for u, v in spline["edges"]:
ui = key_index[u]
vi = key_index[v]
ei = uv_index[(u, v)]
ui = node_index[u]
vi = node_index[v]
ei = edge_index[(u, v)]
spline["ei"].append(ei)
if spline["vi"][-1] == ui:
spline["vi"].append(vi)
Expand Down Expand Up @@ -165,14 +163,8 @@ def bend_splines(
spline["E"] = spline["E"] * units.E
spline["radius"] = spline["radius"] * units.radius
spline["thickness"] = spline["thickness"] * units.thickness
spline["A"] = PI * (
spline["radius"] ** 2 - (spline["radius"] - spline["thickness"]) ** 2
)
spline["I"] = (
PI
* (spline["radius"] ** 4 - (spline["radius"] - spline["thickness"]) ** 4)
/ 4.0
)
spline["A"] = PI * (spline["radius"] ** 2 - (spline["radius"] - spline["thickness"]) ** 2)
spline["I"] = PI * (spline["radius"] ** 4 - (spline["radius"] - spline["thickness"]) ** 4) / 4.0
spline["EA"] = spline["E"] * spline["A"]
spline["EI"] = spline["E"] * spline["I"]
for i in spline["ei"]:
Expand Down Expand Up @@ -318,11 +310,7 @@ def acceleration(t, v):
Q = diags([q.ravel()], [0])
D = Cit.dot(Q).dot(C)
# relax
mass = (
0.5
* dt**2
* Ct2.dot(qpre + q_fpre + q_lpre + EA / linit + 4 * EI / l**3)
)
mass = 0.5 * dt**2 * Ct2.dot(qpre + q_fpre + q_lpre + EA / linit + 4 * EI / l**3)
xyz0 = xyz.copy()
v0 = ca * v.copy()
dv = rk4()
Expand All @@ -346,7 +334,7 @@ def acceleration(t, v):
# update
# --------------------------------------------------------------------------
for key, attr in network.nodes(True):
index = key_index[key]
index = node_index[key]
attr["x"] = xyz[index, 0]
attr["y"] = xyz[index, 1]
attr["z"] = xyz[index, 2]
Expand All @@ -360,7 +348,7 @@ def acceleration(t, v):
attr["my"] = m[index, 1]
attr["mz"] = m[index, 2]
for key, attr in network.edges(True):
index = uv_index[key]
index = edge_index[key]
attr["q"] = q[index, 0]
attr["f"] = f[index, 0]
attr["l"] = l[index, 0]
Expand Down
18 changes: 0 additions & 18 deletions src/compas_bender/datastructures/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
"""
********************************************************************************
datastructures
********************************************************************************
.. currentmodule:: compas_bender.datastructures
Classes
=======
.. autosummary::
:toctree: generated/
:nosignatures:
BendNetwork
"""
from __future__ import print_function
from __future__ import absolute_import
from __future__ import division
Expand Down
8 changes: 4 additions & 4 deletions src/compas_bender/datastructures/bendnetwork.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from __future__ import print_function
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from compas.geometry import Vector
from compas.geometry import Point
from compas.geometry import Line
from compas.datastructures import Network
from compas.geometry import Line
from compas.geometry import Point
from compas.geometry import Vector


class BendNetwork(Network):
Expand Down

0 comments on commit 93aa33b

Please sign in to comment.