From f72b8a3cd1031157b3105549041a223d33d319b5 Mon Sep 17 00:00:00 2001 From: tomvanmele Date: Thu, 29 Feb 2024 21:05:46 +0100 Subject: [PATCH] lint and formatting --- src/compas_tna/__init__.py | 6 +- src/compas_tna/diagrams/diagram.py | 2 +- src/compas_tna/diagrams/forcediagram.py | 8 +- src/compas_tna/diagrams/formdiagram.py | 37 ++++----- src/compas_tna/equilibrium/diagrams.py | 9 +-- src/compas_tna/equilibrium/horizontal.py | 35 +++----- .../equilibrium/horizontal_numpy.py | 80 +++++-------------- src/compas_tna/equilibrium/parallelisation.py | 2 +- .../equilibrium/parallelisation_numpy.py | 7 +- src/compas_tna/equilibrium/relaxation.py | 4 +- src/compas_tna/equilibrium/scale_numpy.py | 10 +-- src/compas_tna/equilibrium/vertical_numpy.py | 12 ++- src/compas_tna/loads/loadupdater.py | 18 ++--- src/compas_tna/loads/thickness.py | 1 + src/compas_tna/notebook/scene/__init__.py | 3 +- src/compas_tna/notebook/scene/forceobject.py | 1 + src/compas_tna/notebook/scene/formobject.py | 1 + src/compas_tna/rhino/scene/__init__.py | 3 +- src/compas_tna/rhino/scene/forceobject.py | 3 +- src/compas_tna/rhino/scene/formobject.py | 4 +- src/compas_tna/scene/forceobject.py | 2 +- src/compas_tna/scene/formobject.py | 2 +- 22 files changed, 93 insertions(+), 157 deletions(-) diff --git a/src/compas_tna/__init__.py b/src/compas_tna/__init__.py index ac535fd4..18734b33 100644 --- a/src/compas_tna/__init__.py +++ b/src/compas_tna/__init__.py @@ -48,7 +48,7 @@ def get(filename): >>> import compas_tna >>> from compas_tna.diagrams import FormDiagram - >>> form = FormDiagram.from_obj(compas.get('faces.obj')) + >>> form = FormDiagram.from_obj(compas.get("faces.obj")) """ filename = filename.strip("/") @@ -58,9 +58,7 @@ def get(filename): if os.path.exists(localpath): return localpath else: - return "https://raw.githubusercontent.com/BlockResearchGroup/compas_tna/master/data/{}".format( - filename - ) + return "https://raw.githubusercontent.com/BlockResearchGroup/compas_tna/master/data/{}".format(filename) __all_plugins__ = [ diff --git a/src/compas_tna/diagrams/diagram.py b/src/compas_tna/diagrams/diagram.py index 2b0363a8..c3361adf 100644 --- a/src/compas_tna/diagrams/diagram.py +++ b/src/compas_tna/diagrams/diagram.py @@ -1,6 +1,6 @@ -from __future__ import print_function from __future__ import absolute_import from __future__ import division +from __future__ import print_function from compas.datastructures import Mesh diff --git a/src/compas_tna/diagrams/forcediagram.py b/src/compas_tna/diagrams/forcediagram.py index fdb4995f..f4c06420 100644 --- a/src/compas_tna/diagrams/forcediagram.py +++ b/src/compas_tna/diagrams/forcediagram.py @@ -1,6 +1,6 @@ -from __future__ import print_function from __future__ import absolute_import from __future__ import division +from __future__ import print_function from compas_tna.diagrams import Diagram @@ -103,7 +103,8 @@ def uv_index(self, form=None): Parameters ---------- form : :class:`compas_tna.diagrams.FormDiagram`, optional - If provided, this maps edge uv's to the index in a list matching the ordering of corresponding edges in the form diagram. + If provided, this maps edge uv's to the index in a list + matching the ordering of corresponding edges in the form diagram. Returns ------- @@ -121,7 +122,8 @@ def uv_index(self, form=None): return uv_index def ordered_edges(self, form): - """Construct an edge list in which the edges are ordered according to the ordering of edges in a corresponding list of form diagram edges. + """Construct an edge list in which the edges are ordered + according to the ordering of edges in a corresponding list of form diagram edges. Parameters ---------- diff --git a/src/compas_tna/diagrams/formdiagram.py b/src/compas_tna/diagrams/formdiagram.py index 873c7145..e8a973c6 100644 --- a/src/compas_tna/diagrams/formdiagram.py +++ b/src/compas_tna/diagrams/formdiagram.py @@ -1,11 +1,10 @@ -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.datastructures import Graph +from compas.geometry import Vector from compas.utilities import pairwise - from compas_tna.diagrams import Diagram @@ -16,19 +15,22 @@ class FormDiagram(Diagram): ----- A FormDiagram has the following constructor functions - * ``from_obj`` : Construct a diagram from the geometry described in an OBJ file. Only points, lines, and faces are taken into account. - * ``from_json`` : Construct a diagram from a JSON file containing a serialised "data" dictionary. - * ``from_lines`` : Construct a diagram from pairs of line start and end points. + * ``from_obj`` : Construct a diagram from the geometry described in an OBJ file. + Only points, lines, and faces are taken into account. + * ``from_json`` : Construct a diagram from a JSON file containing a serialised "data" dictionary. + * ``from_lines`` : Construct a diagram from pairs of line start and end points. Default vertex/edge/face attributes can be "public" or "protected". - Protected attributes are usually only for internal use and should only be modified by the algorithms that rely on them. + Protected attributes are usually only for internal use + and should only be modified by the algorithms that rely on them. If you do change them, do so with care... Protected vertex attributes are: ``_sw, _rx, _ry, _rz``. Protected edge attributes are: ``_h, _f, _a, _is_edge, _is_tension``. Protected face attributes are: ``_is_loaded``. The FormDiagram is a mesh. - Since edges are implicit objects in COMPAS meshes, those edges that are not relevant from a TNA perspective have to be marked as ``_is_edge=False``. + Since edges are implicit objects in COMPAS meshes, + those edges that are not relevant from a TNA perspective have to be marked as ``_is_edge=False``. Usually, the user should not have to worry about this. Furthermore, changing an edge to ``_is_edge=False`` requires an equivalent change in the force diagram. Therefore, the attribute ``_is_edge`` is marked as "protected". @@ -130,7 +132,7 @@ def from_lines(cls, lines, delete_boundary_face=True, precision=None, **kwargs): >>> import compas >>> from compas.files import OBJ >>> from compas_tna.diagrams import FormDiagram - >>> obj = OBJ(compas.get('lines.obj')) + >>> obj = OBJ(compas.get("lines.obj")) >>> vertices = obj.parser.vertices >>> edges = obj.parser.lines >>> lines = [(vertices[u], vertices[v]) for u, v in edges] @@ -156,10 +158,7 @@ def uv_index(self): dict A dictionary of uv-index pairs. """ - return { - (u, v): index - for index, (u, v) in enumerate(self.edges_where(_is_edge=True)) - } + return {(u, v): index for index, (u, v) in enumerate(self.edges_where(_is_edge=True))} def index_uv(self): """Returns a dictionary that maps edges in a list to the corresponding @@ -197,11 +196,7 @@ def dual_diagram(self, cls): """ dual = cls() fkey_centroid = {fkey: self.face_centroid(fkey) for fkey in self.faces()} - inner = list( - set(self.vertices()) - - set(self.vertices_on_boundary()) - - set(self.supports()) - ) + inner = list(set(self.vertices()) - set(self.vertices_on_boundary()) - set(self.supports())) vertices = {} faces = {} for key in inner: @@ -360,11 +355,7 @@ def update_boundaries(self): self.delete_vertex(vertex) # boundaries for boundary in self.vertices_on_boundaries(): - supports = [ - vertex - for vertex in boundary - if self.vertex_attribute(vertex, "is_support") - ] + supports = [vertex for vertex in boundary if self.vertex_attribute(vertex, "is_support")] if len(supports) == 0: # if the boundary contains no supports # only an additional face has to be added diff --git a/src/compas_tna/equilibrium/diagrams.py b/src/compas_tna/equilibrium/diagrams.py index 21f9b5be..fae651e1 100644 --- a/src/compas_tna/equilibrium/diagrams.py +++ b/src/compas_tna/equilibrium/diagrams.py @@ -3,16 +3,15 @@ from numpy import empty_like from numpy.linalg import cond from scipy.linalg import lstsq -from scipy.linalg import solve from scipy.linalg import norm +from scipy.linalg import solve from scipy.sparse.linalg import factorized -from compas.matrices import connectivity_matrix -from compas.matrices import equilibrium_matrix from compas.linalg import dof -from compas.linalg import rref from compas.linalg import nonpivots - +from compas.linalg import rref +from compas.matrices import connectivity_matrix +from compas.matrices import equilibrium_matrix EPS = 1 / sys.float_info.epsilon diff --git a/src/compas_tna/equilibrium/horizontal.py b/src/compas_tna/equilibrium/horizontal.py index 9883fed8..b6934796 100644 --- a/src/compas_tna/equilibrium/horizontal.py +++ b/src/compas_tna/equilibrium/horizontal.py @@ -1,8 +1,9 @@ -from __future__ import print_function from __future__ import absolute_import from __future__ import division +from __future__ import print_function from compas.geometry import angle_vectors_xy + from .parallelisation import parallelise_edges @@ -51,10 +52,7 @@ def horizontal_nodal(form, force, alpha=100, kmax=100, callback=None): # form diagram # -------------------------------------------------------------------------- k_i = form.vertex_index() - i_nbrs = { - k_i[key]: [k_i[nbr] for nbr in form.vertex_neighbors(key)] - for key in form.vertices() - } + i_nbrs = {k_i[key]: [k_i[nbr] for nbr in form.vertex_neighbors(key)] for key in form.vertices()} fixed = set(list(form.supports()) + list(form.fixed())) fixed = [k_i[key] for key in fixed] xy = form.vertices_attributes("xy") @@ -65,9 +63,7 @@ def horizontal_nodal(form, force, alpha=100, kmax=100, callback=None): hmin = form.edges_attribute("hmin", keys=edges) hmax = form.edges_attribute("hmax", keys=edges) - flipmask = [ - -1.0 if form.edge_attribute(edge, "_is_tension") else 1.0 for edge in edges - ] + flipmask = [-1.0 if form.edge_attribute(edge, "_is_tension") else 1.0 for edge in edges] uv_i = form.uv_index() ij_e = {(k_i[u], k_i[v]): index for (u, v), index in iter(uv_i.items())} @@ -77,10 +73,7 @@ def horizontal_nodal(form, force, alpha=100, kmax=100, callback=None): # force diagram # -------------------------------------------------------------------------- _k_i = force.vertex_index() - _i_nbrs = { - _k_i[key]: [_k_i[nbr] for nbr in force.vertex_neighbors(key)] - for key in force.vertices() - } + _i_nbrs = {_k_i[key]: [_k_i[nbr] for nbr in force.vertex_neighbors(key)] for key in force.vertices()} _fixed = list(force.fixed()) _fixed = [_k_i[key] for key in _fixed] _xy = force.vertices_attributes("xy") @@ -103,10 +96,7 @@ def horizontal_nodal(form, force, alpha=100, kmax=100, callback=None): # that is the (alpha) weighted average of the directions of corresponding # edges of the two diagrams # -------------------------------------------------------------------------- - uv = [ - [factor * (xy[j][0] - xy[i][0]), factor * (xy[j][1] - xy[i][1])] - for (i, j), factor in zip(edges, flipmask) - ] + uv = [[factor * (xy[j][0] - xy[i][0]), factor * (xy[j][1] - xy[i][1])] for (i, j), factor in zip(edges, flipmask)] _uv = [[_xy[j][0] - _xy[i][0], _xy[j][1] - _xy[i][1]] for i, j in _edges] lengths = [(dx**2 + dy**2) ** 0.5 for dx, dy in uv] forces = [(dx**2 + dy**2) ** 0.5 for dx, dy in _uv] @@ -114,12 +104,11 @@ def horizontal_nodal(form, force, alpha=100, kmax=100, callback=None): # the target vectors # -------------------------------------------------------------------------- form_targets = [ - [alpha * v[0] / l, alpha * v[1] / l] if l else [0, 0] - for v, l in zip(uv, lengths) + [alpha * v[0] / length, alpha * v[1] / length] if length else [0, 0] for v, length in zip(uv, lengths) ] force_targets = [ - [(1 - alpha) * v[0] / l, (1 - alpha) * v[1] / l] if l else [0, 0] - for v, l in zip(_uv, forces) + [(1 - alpha) * v[0] / length, (1 - alpha) * v[1] / length] if length else [0, 0] + for v, length in zip(_uv, forces) ] targets = [[a[0] + b[0], a[1] + b[1]] for a, b in zip(form_targets, force_targets)] # -------------------------------------------------------------------------- @@ -168,7 +157,7 @@ def horizontal_nodal(form, force, alpha=100, kmax=100, callback=None): # compute the force densities # -------------------------------------------------------------------------- forces[:] = [f * factor for f, factor in zip(forces, flipmask)] - q = [f / l for f, l in zip(forces, lengths)] + q = [f / length for f, length in zip(forces, lengths)] # -------------------------------------------------------------------------- # rotate the force diagram 90 degrees in CW direction # this way the relation between the two diagrams is easier to read @@ -188,9 +177,7 @@ def horizontal_nodal(form, force, alpha=100, kmax=100, callback=None): form.vertex_attributes(key, "xy", xy[i]) for uv in form.edges_where({"_is_edge": True}): i = uv_i[uv] - form.edge_attributes( - uv, ["q", "_f", "_l", "_a"], [q[i], forces[i], lengths[i], angles[i]] - ) + form.edge_attributes(uv, ["q", "_f", "_l", "_a"], [q[i], forces[i], lengths[i], angles[i]]) # -------------------------------------------------------------------------- # update force # -------------------------------------------------------------------------- diff --git a/src/compas_tna/equilibrium/horizontal_numpy.py b/src/compas_tna/equilibrium/horizontal_numpy.py index 9ea4f9bc..07cc166c 100644 --- a/src/compas_tna/equilibrium/horizontal_numpy.py +++ b/src/compas_tna/equilibrium/horizontal_numpy.py @@ -1,21 +1,20 @@ from typing import Tuple -from compas.geometry import angle_vectors_xy from numpy import array from numpy import float64 from numpy import where -from compas.matrices import connectivity_matrix -from compas.linalg import normrow +from compas.geometry import angle_vectors_xy from compas.linalg import normalizerow - -from compas_tna.diagrams import FormDiagram +from compas.linalg import normrow +from compas.matrices import connectivity_matrix from compas_tna.diagrams import ForceDiagram +from compas_tna.diagrams import FormDiagram -from .diagrams import rot90 from .diagrams import apply_bounds -from .parallelisation_numpy import parallelise_sparse +from .diagrams import rot90 from .parallelisation_numpy import parallelise_nodal +from .parallelisation_numpy import parallelise_sparse def horizontal_numpy( @@ -72,18 +71,10 @@ def horizontal_numpy( xy = array(form.vertices_attributes("xy"), dtype=float64) edges = list(form.edges_where({"_is_edge": True})) - lmin = array(form.edges_attribute("lmin", keys=edges), dtype=float64).reshape( - (-1, 1) - ) - lmax = array(form.edges_attribute("lmax", keys=edges), dtype=float64).reshape( - (-1, 1) - ) - hmin = array(form.edges_attribute("hmin", keys=edges), dtype=float64).reshape( - (-1, 1) - ) - hmax = array(form.edges_attribute("hmax", keys=edges), dtype=float64).reshape( - (-1, 1) - ) + lmin = array(form.edges_attribute("lmin", keys=edges), dtype=float64).reshape((-1, 1)) + lmax = array(form.edges_attribute("lmax", keys=edges), dtype=float64).reshape((-1, 1)) + hmin = array(form.edges_attribute("hmin", keys=edges), dtype=float64).reshape((-1, 1)) + hmax = array(form.edges_attribute("hmax", keys=edges), dtype=float64).reshape((-1, 1)) edges = [[k_i[u], k_i[v]] for u, v in edges] C = connectivity_matrix(edges, "csr") @@ -100,12 +91,8 @@ def horizontal_numpy( _xy = array(force.vertices_attributes("xy"), dtype=float64) _edges = force.ordered_edges(form) - _lmin = array(force.edges_attribute("lmin", keys=_edges), dtype=float64).reshape( - (-1, 1) - ) - _lmax = array(force.edges_attribute("lmax", keys=_edges), dtype=float64).reshape( - (-1, 1) - ) + _lmin = array(force.edges_attribute("lmin", keys=_edges), dtype=float64).reshape((-1, 1)) + _lmax = array(force.edges_attribute("lmax", keys=_edges), dtype=float64).reshape((-1, 1)) _edges = [[_k_i[u], _k_i[v]] for u, v in _edges] _C = connectivity_matrix(_edges, "csr") @@ -234,47 +221,29 @@ def horizontal_nodal_numpy( # -------------------------------------------------------------------------- k_i = form.vertex_index() uv_i = form.uv_index() - i_nbrs = { - k_i[key]: [k_i[nbr] for nbr in form.vertex_neighbors(key)] - for key in form.vertices() - } + i_nbrs = {k_i[key]: [k_i[nbr] for nbr in form.vertex_neighbors(key)] for key in form.vertices()} ij_e = {(k_i[u], k_i[v]): index for (u, v), index in iter(uv_i.items())} fixed = set(list(form.supports()) + list(form.fixed())) fixed = [k_i[key] for key in fixed] edges = [[k_i[u], k_i[v]] for u, v in form.edges_where({"_is_edge": True})] lmin = array( - [ - attr.get("lmin", 1e-7) - for key, attr in form.edges_where({"_is_edge": True}, True) - ], + [attr.get("lmin", 1e-7) for key, attr in form.edges_where({"_is_edge": True}, True)], dtype=float64, ).reshape((-1, 1)) lmax = array( - [ - attr.get("lmax", 1e7) - for key, attr in form.edges_where({"_is_edge": True}, True) - ], + [attr.get("lmax", 1e7) for key, attr in form.edges_where({"_is_edge": True}, True)], dtype=float64, ).reshape((-1, 1)) hmin = array( - [ - attr.get("hmin", 1e-7) - for key, attr in form.edges_where({"_is_edge": True}, True) - ], + [attr.get("hmin", 1e-7) for key, attr in form.edges_where({"_is_edge": True}, True)], dtype=float64, ).reshape((-1, 1)) hmax = array( - [ - attr.get("hmax", 1e7) - for key, attr in form.edges_where({"_is_edge": True}, True) - ], + [attr.get("hmax", 1e7) for key, attr in form.edges_where({"_is_edge": True}, True)], dtype=float64, ).reshape((-1, 1)) flipmask = array( - [ - 1.0 if not attr["_is_tension"] else -1.0 - for key, attr in form.edges_where({"_is_edge": True}, True) - ], + [1.0 if not attr["_is_tension"] else -1.0 for key, attr in form.edges_where({"_is_edge": True}, True)], dtype=float, ).reshape((-1, 1)) xy = array(form.vertices_attributes("xy"), dtype=float64) @@ -284,10 +253,7 @@ def horizontal_nodal_numpy( # -------------------------------------------------------------------------- _k_i = force.vertex_index() _uv_i = force.uv_index(form=form) - _i_nbrs = { - _k_i[key]: [_k_i[nbr] for nbr in force.vertex_neighbors(key)] - for key in force.vertices() - } + _i_nbrs = {_k_i[key]: [_k_i[nbr] for nbr in force.vertex_neighbors(key)] for key in force.vertices()} _ij_e = {(_k_i[u], _k_i[v]): index for (u, v), index in iter(_uv_i.items())} _fixed = list(force.fixed()) _fixed = [_k_i[key] for key in _fixed] @@ -295,12 +261,8 @@ def horizontal_nodal_numpy( _edges = force.ordered_edges(form) _xy = array(force.vertices_attributes("xy"), dtype=float64) - _lmin = array( - [attr.get("lmin", 1e-7) for key, attr in force.edges(True)], dtype=float64 - ).reshape((-1, 1)) - _lmax = array( - [attr.get("lmax", 1e7) for key, attr in force.edges(True)], dtype=float64 - ).reshape((-1, 1)) + _lmin = array([attr.get("lmin", 1e-7) for key, attr in force.edges(True)], dtype=float64).reshape((-1, 1)) + _lmax = array([attr.get("lmax", 1e7) for key, attr in force.edges(True)], dtype=float64).reshape((-1, 1)) _edges = [[_k_i[u], _k_i[v]] for u, v in _edges] _C = connectivity_matrix(_edges, "csr") diff --git a/src/compas_tna/equilibrium/parallelisation.py b/src/compas_tna/equilibrium/parallelisation.py index 5e966f91..ff9eefd0 100644 --- a/src/compas_tna/equilibrium/parallelisation.py +++ b/src/compas_tna/equilibrium/parallelisation.py @@ -1,6 +1,6 @@ -from __future__ import print_function from __future__ import absolute_import from __future__ import division +from __future__ import print_function from compas.geometry import midpoint_point_point_xy diff --git a/src/compas_tna/equilibrium/parallelisation_numpy.py b/src/compas_tna/equilibrium/parallelisation_numpy.py index b6bac9a3..ac5f6157 100644 --- a/src/compas_tna/equilibrium/parallelisation_numpy.py +++ b/src/compas_tna/equilibrium/parallelisation_numpy.py @@ -6,10 +6,9 @@ from scipy.linalg import lstsq from scipy.sparse.linalg import factorized -from compas.linalg import normrow from compas.linalg import chofactor from compas.linalg import lufactorized - +from compas.linalg import normrow EPS = 1 / sys.float_info.epsilon @@ -45,9 +44,7 @@ def parallelise_sparse(A, B, X, known, k=1, key=None): return X -def parallelise_nodal( - xy, C, targets, i_nbrs, ij_e, fixed=None, kmax=100, lmin=None, lmax=None -): +def parallelise_nodal(xy, C, targets, i_nbrs, ij_e, fixed=None, kmax=100, lmin=None, lmax=None): fixed = fixed or [] fixed = set(fixed) diff --git a/src/compas_tna/equilibrium/relaxation.py b/src/compas_tna/equilibrium/relaxation.py index af4d5e9c..d979b579 100644 --- a/src/compas_tna/equilibrium/relaxation.py +++ b/src/compas_tna/equilibrium/relaxation.py @@ -1,7 +1,9 @@ from typing import List -from compas_tna.diagrams import FormDiagram + from compas_fd.solvers import fd_numpy +from compas_tna.diagrams import FormDiagram + def relax_boundary_openings(form: FormDiagram, fixed: List[int]) -> FormDiagram: """Relax the FormDiagram to create a smooth starting geometry with inward curving unsupported boundaries. diff --git a/src/compas_tna/equilibrium/scale_numpy.py b/src/compas_tna/equilibrium/scale_numpy.py index fae23a36..3834b7c1 100644 --- a/src/compas_tna/equilibrium/scale_numpy.py +++ b/src/compas_tna/equilibrium/scale_numpy.py @@ -1,18 +1,18 @@ import sys + from numpy import array from numpy import float64 from scipy.sparse import diags from scipy.sparse.linalg import spsolve -from compas.matrices import connectivity_matrix from compas.linalg import normrow -from compas_tna.diagrams import FormDiagram +from compas.matrices import connectivity_matrix from compas_tna.diagrams import ForceDiagram +from compas_tna.diagrams import FormDiagram from compas_tna.loads import LoadUpdater from .diagrams import update_z - EPS = 1 / sys.float_info.epsilon @@ -119,9 +119,7 @@ def scale_from_target( q = scale * q0 Q = diags([q.ravel()], [0]) - _ = update_z( - xyz, Q, C, p, free, fixed, update_loads, tol=rtol, kmax=kmax, display=display - ) + _ = update_z(xyz, Q, C, p, free, fixed, update_loads, tol=rtol, kmax=kmax, display=display) # -------------------------------------------------------------------------- # update # -------------------------------------------------------------------------- diff --git a/src/compas_tna/equilibrium/vertical_numpy.py b/src/compas_tna/equilibrium/vertical_numpy.py index b62a333a..c5ce89eb 100644 --- a/src/compas_tna/equilibrium/vertical_numpy.py +++ b/src/compas_tna/equilibrium/vertical_numpy.py @@ -5,11 +5,10 @@ from scipy.sparse import diags from scipy.sparse.linalg import spsolve -from compas.matrices import connectivity_matrix from compas.linalg import normrow - -from compas_tna.diagrams import FormDiagram +from compas.matrices import connectivity_matrix from compas_tna.diagrams import ForceDiagram # noqa: F401 +from compas_tna.diagrams import FormDiagram from compas_tna.loads import LoadUpdater from .diagrams import update_z @@ -179,7 +178,8 @@ def vertical_from_q(form, scale=1.0, density=1.0, kmax=100, tol=1e-3, display=Fa Notes ----- - The force densities stored in the Form Diagram are the ratios of lengths of corresponding edges in the Form and Force Diagram. + The force densities stored in the Form Diagram are + the ratios of lengths of corresponding edges in the Form and Force Diagram. This means they are not yet scaled with the scale of the horizontal forces. The horizontal forces stored in the diagram are scaled. @@ -223,9 +223,7 @@ def vertical_from_q(form, scale=1.0, density=1.0, kmax=100, tol=1e-3, display=Fa # -------------------------------------------------------------------------- # compute vertical # -------------------------------------------------------------------------- - update_z( - xyz, Q, C, p, free, fixed, update_loads, tol=tol, kmax=kmax, display=display - ) + update_z(xyz, Q, C, p, free, fixed, update_loads, tol=tol, kmax=kmax, display=display) # -------------------------------------------------------------------------- # update # -------------------------------------------------------------------------- diff --git a/src/compas_tna/loads/loadupdater.py b/src/compas_tna/loads/loadupdater.py index c974fc84..6d380c22 100644 --- a/src/compas_tna/loads/loadupdater.py +++ b/src/compas_tna/loads/loadupdater.py @@ -1,13 +1,13 @@ from typing import Literal -from nptyping import NDArray -from nptyping import Float64 import numpy import scipy.sparse +from nptyping import Float64 +from nptyping import NDArray from compas.datastructures import Mesh -from compas.geometry import length_vector from compas.geometry import cross_vectors +from compas.geometry import length_vector from compas.matrices import face_matrix @@ -31,8 +31,8 @@ class LoadUpdater(object): Examples -------- >>> import numpy - >>> xyz = numpy.array(form.vertices_attributes('xyz')) - >>> p = numpy.array(form.vertices_attributes(['px', 'py', 'pz'])) + >>> xyz = numpy.array(form.vertices_attributes("xyz")) + >>> p = numpy.array(form.vertices_attributes(["px", "py", "pz"])) >>> p0 = p.copy() Construct a load updater with the (additional) point loads applied at the vertices. @@ -61,9 +61,7 @@ def __init__( self.live = live self.vertex_index = mesh.vertex_index() self.fvertex_index = {face: index for index, face in enumerate(mesh.faces())} - self.is_loaded = { - face: mesh.face_attribute(face, "_is_loaded") for face in mesh.faces() - } + self.is_loaded = {face: mesh.face_attribute(face, "_is_loaded") for face in mesh.faces()} self.F = self.face_matrix() def __call__( @@ -95,9 +93,7 @@ def face_matrix(self) -> scipy.sparse.csr_matrix: """ face_vertices = [None] * self.mesh.number_of_faces() for fkey in self.mesh.faces(): - face_vertices[self.fvertex_index[fkey]] = [ - self.vertex_index[key] for key in self.mesh.face_vertices(fkey) - ] + face_vertices[self.fvertex_index[fkey]] = [self.vertex_index[key] for key in self.mesh.face_vertices(fkey)] return face_matrix(face_vertices, rtype="csr", normalize=True) def tributary_areas( diff --git a/src/compas_tna/loads/thickness.py b/src/compas_tna/loads/thickness.py index e38a94dd..de6aa2b6 100644 --- a/src/compas_tna/loads/thickness.py +++ b/src/compas_tna/loads/thickness.py @@ -1,5 +1,6 @@ from numpy import array from scipy.interpolate import griddata + from compas_tna.diagrams import FormDiagram diff --git a/src/compas_tna/notebook/scene/__init__.py b/src/compas_tna/notebook/scene/__init__.py index c1a2204b..73044266 100644 --- a/src/compas_tna/notebook/scene/__init__.py +++ b/src/compas_tna/notebook/scene/__init__.py @@ -1,6 +1,7 @@ """ This package provides scene object plugins for visualising TNA diagrams in Jupyter Notebooks. -When working in a notebook, :class:`compas.scene.SceneObject` will automatically use the corresponding scene object for each TNA diagram type. +When working in a notebook, :class:`compas.scene.SceneObject` +will automatically use the corresponding scene object for each TNA diagram type. """ from __future__ import absolute_import diff --git a/src/compas_tna/notebook/scene/forceobject.py b/src/compas_tna/notebook/scene/forceobject.py index 0c90db8f..d2dff6d7 100644 --- a/src/compas_tna/notebook/scene/forceobject.py +++ b/src/compas_tna/notebook/scene/forceobject.py @@ -1,4 +1,5 @@ from compas_notebook.scene import ThreeMeshObject + from compas_tna.scene import ForceDiagramObject diff --git a/src/compas_tna/notebook/scene/formobject.py b/src/compas_tna/notebook/scene/formobject.py index 0ec15dfa..3af88ab8 100644 --- a/src/compas_tna/notebook/scene/formobject.py +++ b/src/compas_tna/notebook/scene/formobject.py @@ -1,4 +1,5 @@ from compas_notebook.scene import ThreeMeshObject + from compas_tna.scene import FormDiagramObject diff --git a/src/compas_tna/rhino/scene/__init__.py b/src/compas_tna/rhino/scene/__init__.py index b37adda9..c1e96c50 100644 --- a/src/compas_tna/rhino/scene/__init__.py +++ b/src/compas_tna/rhino/scene/__init__.py @@ -1,6 +1,7 @@ """ This package provides scene object plugins for visualising TNA diagrams in Rhino. -When working in Rhino, :class:`compas.scene.SceneObject` will automatically use the corresponding Rhino scene object for each TNA diagram type. +When working in Rhino, :class:`compas.scene.SceneObject` +will automatically use the corresponding Rhino scene object for each TNA diagram type. """ from __future__ import absolute_import diff --git a/src/compas_tna/rhino/scene/forceobject.py b/src/compas_tna/rhino/scene/forceobject.py index 0451ed07..c88dafcc 100644 --- a/src/compas_tna/rhino/scene/forceobject.py +++ b/src/compas_tna/rhino/scene/forceobject.py @@ -1,8 +1,9 @@ -from __future__ import print_function from __future__ import absolute_import from __future__ import division +from __future__ import print_function from compas_rhino.scene import RhinoMeshObject + from compas_tna.scene import ForceDiagramObject diff --git a/src/compas_tna/rhino/scene/formobject.py b/src/compas_tna/rhino/scene/formobject.py index 8a0aaf80..127260b7 100644 --- a/src/compas_tna/rhino/scene/formobject.py +++ b/src/compas_tna/rhino/scene/formobject.py @@ -1,11 +1,11 @@ -from __future__ import print_function from __future__ import absolute_import from __future__ import division +from __future__ import print_function import scriptcontext as sc # type: ignore - from compas_rhino.conversions import line_to_rhino from compas_rhino.scene import RhinoMeshObject + from compas_tna.scene import FormDiagramObject diff --git a/src/compas_tna/scene/forceobject.py b/src/compas_tna/scene/forceobject.py index 0a1335e6..166e4c6a 100644 --- a/src/compas_tna/scene/forceobject.py +++ b/src/compas_tna/scene/forceobject.py @@ -1,6 +1,6 @@ -from __future__ import print_function from __future__ import absolute_import from __future__ import division +from __future__ import print_function from compas.colors import Color from compas.scene import MeshObject diff --git a/src/compas_tna/scene/formobject.py b/src/compas_tna/scene/formobject.py index b47dbcb6..205bd99b 100644 --- a/src/compas_tna/scene/formobject.py +++ b/src/compas_tna/scene/formobject.py @@ -1,6 +1,6 @@ -from __future__ import print_function from __future__ import absolute_import from __future__ import division +from __future__ import print_function from compas.colors import Color from compas.scene import MeshObject