Skip to content

Commit 7d5b36b

Browse files
committed
small tweaks and rename groups
1 parent 98a6eaf commit 7d5b36b

File tree

9 files changed

+63
-60
lines changed

9 files changed

+63
-60
lines changed

src/compas_rv/datastructures/diagram.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ class Diagram(Mesh):
77
Base data structure for form, force and thrust diagrams.
88
"""
99

10-
def edge_loop(self, uv):
10+
def edge_loop(self, edge):
1111
"""
1212
Identify all edges on the same loop as a given edge.
1313
This implementation is different than the base implmentation in the mesh data structure,
1414
because of the "unloaded" faces in form, force, and thrust diagrams.
1515
1616
Parameters
1717
----------
18-
uv : tuple[int, int]
18+
edge : tuple[int, int]
1919
The identifier of the edge.
2020
2121
Returns
@@ -24,8 +24,8 @@ def edge_loop(self, uv):
2424
A list of edge identifiers.
2525
2626
"""
27-
u, v = uv
28-
f1, f2 = self.edge_faces(uv)
27+
u, v = edge
28+
f1, f2 = self.edge_faces(edge)
2929

3030
if f1 is not None and not self.face_attribute(f1, "_is_loaded"):
3131
loop = []
@@ -91,7 +91,7 @@ def smooth(self, fixed, kmax=10):
9191
None
9292
9393
"""
94-
self.smooth_area(self, fixed=fixed, kmax=kmax)
94+
self.smooth_area(fixed=fixed, kmax=kmax)
9595

9696
def corner_vertices(self, tol=160):
9797
"""
@@ -116,10 +116,10 @@ def corner_vertices(self, tol=160):
116116
else:
117117
nbrs = []
118118
for nkey in self.vertex_neighbors(key):
119-
if self.is_edge_on_boundary(key, nkey):
119+
if self.is_edge_on_boundary((key, nkey)):
120120
nbrs.append(nkey)
121-
u = self.edge_vector(key, nbrs[0])
122-
v = self.edge_vector(key, nbrs[1])
121+
u = self.edge_vector((key, nbrs[0]))
122+
v = self.edge_vector((key, nbrs[1]))
123123
if angle_vectors(u, v, deg=True) < tol:
124124
vkeys.append(key)
125125
return vkeys

src/compas_rv/datastructures/formdiagram.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from compas.geometry import scale_vector
22
from compas.geometry import sum_vectors
33
from compas_fd.solvers import fd_numpy
4-
from compas_tna.diagrams import FormDiagram
4+
from compas_tna.diagrams import FormDiagram as BaseFormDiagram
55

66
from .diagram import Diagram
77
from .pattern import Pattern
88

99

10-
class FormDiagram(Diagram, FormDiagram):
10+
class FormDiagram(Diagram, BaseFormDiagram):
1111
"""
1212
Data structure for form diagrams.
1313
"""
@@ -77,17 +77,18 @@ def solve_fd(self) -> None:
7777
7878
"""
7979
vertex_index = self.vertex_index()
80-
xyz = self.vertices_attributes("xyz")
80+
xyz: list[list[float]] = self.vertices_attributes("xyz") # type: ignore
8181
loads = [[0.0, 0.0, 0.0] for _ in xyz]
8282
fixed = [vertex_index[key] for key in self.vertices_where(is_support=True)]
8383
fixed += [vertex_index[key] for key in self.vertices_where(is_fixed=True)]
8484
edges = list(self.edges_where(_is_edge=True))
85-
q = self.edges_attribute("q", keys=edges)
85+
q: list[float] = self.edges_attribute("q", keys=edges) # type: ignore
8686
edges = [(vertex_index[u], vertex_index[v]) for u, v in edges]
8787
result = fd_numpy(vertices=xyz, fixed=fixed, edges=edges, forcedensities=q, loads=loads)
88-
for key in self.vertices():
89-
index = vertex_index[key]
90-
self.vertex_attributes(key, "xyz", result.vertices[index])
88+
for vertex in self.vertices():
89+
index = vertex_index[vertex]
90+
self.vertex_attributes(vertex, "xyz", result.vertices[index])
91+
self.vertex_attributes(vertex, ["_rx", "_ry", "_rz"], result.residuals[index])
9192

9293
def flip_cycles_if_normal_down(self):
9394
"""Flip the cycles of the diagram if the average normal points downward."""

src/compas_rv/scene/diagramobject.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Optional
2+
13
import Rhino # type: ignore
24
import rhinoscriptsyntax as rs # type: ignore
35
import scriptcontext as sc # type: ignore
@@ -51,39 +53,37 @@ def settings(self):
5153

5254
@property
5355
def diagram(self) -> Diagram:
54-
return self.mesh
56+
return self.mesh # type: ignore
5557

5658
@diagram.setter
5759
def diagram(self, diagram: Diagram) -> None:
5860
self.mesh = diagram
5961

60-
def edges(self, **kwargs):
61-
return self.diagram.edges(**kwargs)
62+
def edges(self, **kwargs) -> list[tuple[int, int]]:
63+
return self.diagram.edges(**kwargs) # type: ignore
6264

63-
def faces(self, **kwargs):
64-
return self.diagram.faces(**kwargs)
65+
def faces(self, **kwargs) -> list[int]:
66+
return self.diagram.faces(**kwargs) # type: ignore
6567

66-
def forces(self):
67-
return self.diagram.edges_attribute("_f", keys=self.edges())
68+
def forces(self) -> list[float]:
69+
return self.diagram.edges_attribute("_f", keys=self.edges()) # type: ignore
6870

69-
def compute_edge_colors(self, tol=1e-3) -> None:
71+
def compute_edge_colors(self, tol=1e-3) -> list[Color]:
7072
forces = self.forces()
7173
magnitudes = [abs(f) for f in forces]
7274
fmin = min(magnitudes)
7375
fmax = max(magnitudes)
7476

75-
if fmax - fmin < tol:
76-
# size of the range of forces is already checked here
77-
# no need to check again in the loop
78-
return
79-
8077
colors = []
8178

82-
for force, magnitude in zip(forces, magnitudes):
83-
# this will need to be updated once we allow for tension forces
84-
# or we have to exclude tension forces from the calculation
85-
# and give tension edges their own style
86-
colors.append(Color.from_i((magnitude - fmin) / (fmax - fmin)))
79+
if fmax - fmin >= tol:
80+
# size of the range of forces is already checked here
81+
# no need to check again in the loop
82+
for magnitude in magnitudes:
83+
# this will need to be updated once we allow for tension forces
84+
# or we have to exclude tension forces from the calculation
85+
# and give tension edges their own style
86+
colors.append(Color.from_i((magnitude - fmin) / (fmax - fmin)))
8787

8888
return colors
8989

src/compas_rv/scene/forceobject.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99

1010
class RhinoForceObject(RhinoDiagramObject):
1111
session = RVSession()
12-
diagram: ForceDiagram
12+
diagram: ForceDiagram # type: ignore
1313

1414
vertexcolor = ColorDictAttribute(default=Color.blue())
1515
edgecolor = ColorDictAttribute(default=Color.blue().darkened(50))
1616
facecolor = ColorDictAttribute(default=Color.blue().lightened(25))
1717

1818
def __init__(
1919
self,
20-
vertexgroup="RV::ForceDiagram::Vertices",
21-
edgegroup="RV::ForceDiagram::Edges",
22-
facegroup="RV::ForceDiagram::Faces",
20+
vertexgroup="RhinoVAULT::ForceDiagram::Vertices",
21+
edgegroup="RhinoVAULT::ForceDiagram::Edges",
22+
facegroup="RhinoVAULT::ForceDiagram::Faces",
2323
**kwargs,
2424
):
2525
super().__init__(

src/compas_rv/scene/formobject.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,33 @@
88

99
class RhinoFormObject(RhinoDiagramObject):
1010
session = RVSession()
11-
diagram: FormDiagram
11+
diagram: FormDiagram # type: ignore
1212

1313
vertexcolor = ColorDictAttribute(default=Color.green())
1414
edgecolor = ColorDictAttribute(default=Color.green().darkened(50))
1515
facecolor = ColorDictAttribute(default=Color.green().lightened(25))
1616

1717
def __init__(
1818
self,
19-
vertexgroup="RV::FormDiagram::Vertices",
20-
edgegroup="RV::FormDiagram::Edges",
21-
facegroup="RV::FormDiagram::Faces",
19+
vertexgroup="RhinoVAULT::FormDiagram::Vertices",
20+
edgegroup="RhinoVAULT::FormDiagram::Edges",
21+
facegroup="RhinoVAULT::FormDiagram::Faces",
22+
layer="RhinoVAULT::FormDiagram",
2223
**kwargs,
2324
):
2425
super().__init__(
2526
vertexgroup=vertexgroup,
2627
edgegroup=edgegroup,
2728
facegroup=facegroup,
29+
layer=layer,
2830
**kwargs,
2931
)
3032

3133
# =============================================================================
3234
# Properties
3335
# =============================================================================
3436

35-
def edges(self):
37+
def edges(self, **kwargs):
3638
return self.diagram.edges_where(_is_edge=True)
3739

3840
def faces(self, **kwargs):

src/compas_rv/scene/patternobject.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class RhinoPatternObject(RUIMeshObject):
1818
def __init__(
1919
self,
2020
disjoint=True,
21-
vertexgroup="RV::FormDiagram::Vertices",
22-
edgegroup="RV::FormDiagram::Edges",
23-
facegroup="RV::FormDiagram::Faces",
21+
vertexgroup="RhinoVAULT::FormDiagram::Vertices",
22+
edgegroup="RhinoVAULT::FormDiagram::Edges",
23+
facegroup="RhinoVAULT::FormDiagram::Faces",
2424
**kwargs,
2525
):
2626
super().__init__(

src/compas_rv/scene/thrustobject.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ def __init__(
3636
show_supports=True,
3737
show_fixed=True,
3838
show_free=False,
39-
vertexgroup="RV::ThrustDiagram::Vertices",
40-
edgegroup="RV::ThrustDiagram::Edges",
41-
facegroup="RV::ThrustDiagram::Faces",
42-
loadgroup="RV::ThrustDiagram::Loads",
43-
selfweightgroup="RV::ThrustDiagram::Selfweight",
44-
forcegroup="RV::ThrustDiagram::Forces",
45-
reactiongroup="RV::ThrustDiagram::Reactions",
46-
residualgroup="RV::ThrustDiagram::Residuals",
39+
vertexgroup="RhinoVAULT::ThrustDiagram::Vertices",
40+
edgegroup="RhinoVAULT::ThrustDiagram::Edges",
41+
facegroup="RhinoVAULT::ThrustDiagram::Faces",
42+
loadgroup="RhinoVAULT::ThrustDiagram::Loads",
43+
selfweightgroup="RhinoVAULT::ThrustDiagram::Selfweight",
44+
forcegroup="RhinoVAULT::ThrustDiagram::Forces",
45+
reactiongroup="RhinoVAULT::ThrustDiagram::Reactions",
46+
residualgroup="RhinoVAULT::ThrustDiagram::Residuals",
4747
**kwargs,
4848
):
4949
super().__init__(

src/compas_rv/solvers/forcefromform.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def update_force_from_form(force: ForceDiagram, form: FormDiagram):
1414
xy = np.array(form.vertices_attributes("xy"), dtype=np.float64)
1515
edges = [[vertex_index[u], vertex_index[v]] for u, v in form.edges_where(_is_edge=True)]
1616
C: sps.csr_matrix = connectivity_matrix(edges, "csr")
17-
Q = sps.diags([form.edges_attribute("q", keys=list(form.edges_where(_is_edge=True)))], [0])
17+
Q = sps.diags([form.edges_attribute("q", keys=list(form.edges_where(_is_edge=True)))], [0]) # type: ignore
1818
uv = C.dot(xy)
1919

2020
_vertex_index = force.vertex_index()
@@ -35,5 +35,5 @@ def update_force_from_form(force: ForceDiagram, form: FormDiagram):
3535

3636
for vertex, attr in force.vertices(True):
3737
index = _vertex_index[vertex]
38-
attr["x"] = _xy[index, 0]
39-
attr["y"] = _xy[index, 1]
38+
attr["x"] = _xy[index, 0] # type: ignore
39+
attr["y"] = _xy[index, 1] # type: ignore

src/compas_rv/solvers/scalehorizonal.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ def conduit_edges(self) -> EdgesConduit:
4343
def numdata(self) -> FDNumericalData:
4444
if self._numdata is None:
4545
vertex_index = self.thrust.vertex_index()
46-
vertices = self.thrust.vertices_attributes("xyz")
47-
loads = [self.thrust.vertex_attributes(vertex, ["px", "py", "pz"]) or [0, 0, 0] for vertex in self.thrust.vertices()]
46+
vertices: list[list[float]] = self.thrust.vertices_attributes("xyz") # type: ignore
47+
loads: list[list[float]] = [self.thrust.vertex_attributes(vertex, ["px", "py", "pz"]) or [0, 0, 0] for vertex in self.thrust.vertices()] # type: ignore
4848
fixed = [vertex_index[vertex] for vertex in self.thrust.vertices_where(is_support=True)]
4949
edges = list(self.thrust.edges_where(_is_edge=True))
50-
forcedensities = list(self.thrust.edges_attribute(name="q", keys=edges))
50+
forcedensities: list[float] = list(self.thrust.edges_attribute(name="q", keys=edges)) # type: ignore
5151
edges = [(vertex_index[u], vertex_index[v]) for u, v in edges]
5252
self._numdata = FDNumericalData.from_params(vertices, fixed, edges, forcedensities, loads)
5353
return self._numdata
@@ -59,7 +59,7 @@ def loadupdater(self) -> LoadUpdater:
5959
self._loadupdater = LoadUpdater(
6060
self.thrust,
6161
array(self.numdata.p, copy=True),
62-
array(self.thrust.vertices_attribute("t"), dtype=float64).reshape((-1, 1)),
62+
array(self.thrust.vertices_attribute("t"), dtype=float64).reshape((-1, 1)), # type: ignore
6363
1.0,
6464
)
6565
return self._loadupdater

0 commit comments

Comments
 (0)