Skip to content

Commit 77ec41c

Browse files
committed
docstring updates
1 parent a019743 commit 77ec41c

File tree

5 files changed

+72
-135
lines changed

5 files changed

+72
-135
lines changed

src/compas/numerical/algorithms/dr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ def a(t, V):
388388
# and define a callback function
389389
# for plotting the intermediate configurations
390390

391-
plotter = NetworkPlotter(network, figsize=(10, 6))
391+
plotter = NetworkPlotter(network, figsize=(10, 7), fontsize=6)
392392

393393
def callback(k, xyz, crits, args):
394394
print(k)

src/compas/numerical/algorithms/dr_numpy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ def a(t, v):
400400
'width': 0.5
401401
})
402402

403-
plotter = NetworkPlotter(network, figsize=(10, 6))
403+
plotter = NetworkPlotter(network, figsize=(10, 7), fontsize=6)
404404

405405
plotter.draw_lines(lines)
406406
plotter.draw_vertices(facecolor={key: '#000000' for key in network.vertices_where({'is_fixed': True})})

src/compas/numerical/algorithms/drx_hpc.py

Whitespace-only changes.

src/compas/numerical/algorithms/drx_numpy.py

Lines changed: 68 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import print_function
22
from __future__ import absolute_import
3+
from __future__ import division
34

45
import sys
56

@@ -43,145 +44,91 @@
4344
def drx_numpy(network, factor=1.0, tol=0.1, steps=10000, refresh=0, update=False, callback=None, **kwargs):
4445
"""Run dynamic relaxation analysis.
4546
46-
Parameters:
47-
network (obj): Network to analyse.
48-
factor (float): Convergence factor.
49-
tol (float): Tolerance value.
50-
steps (int): Maximum number of steps.
51-
refresh (int): Update progress every n steps.
52-
update (bool): Update the co-ordinates of the Network.
53-
callback (obj): Callback function.
54-
55-
Returns:
56-
array: Vertex co-ordinates.
57-
array: Edge forces.
58-
array: Edge lengths.
59-
60-
Example:
61-
62-
.. plot::
63-
64-
import compas
65-
from compas.datastructures import Network
66-
from compas.plotters import NetworkPlotter
67-
from compas.numerical import drx_numpy
68-
from compas.utilities import i_to_rgb
69-
70-
from numpy import linspace
71-
72-
L0 = 1
73-
L = 1.5
74-
n = 40
75-
EI = 0.2
76-
pins = [0, 5, 20, n - 5]
77-
78-
# Network
79-
80-
vertices = [[i, i, 0] for i in list(linspace(0, L0, n))]
81-
edges = [[i, i + 1] for i in range(n - 1)]
82-
83-
network = Network.from_vertices_and_edges(vertices=vertices, edges=edges)
84-
network.update_default_vertex_attributes({'is_fixed': False, 'P': [1, -2, 0], 'EIx': EI, 'EIy': EI})
85-
network.update_default_edge_attributes({'E': 50, 'A': 1, 'l0': L / n})
86-
network.set_vertices_attributes(pins, {'B': [0, 0, 0], 'is_fixed': True})
87-
network.beams = {'beam': {'nodes': list(range(n))}}
47+
Parameters
48+
----------
49+
network : Network
50+
Network to analyse.
51+
factor : float
52+
Convergence factor.
53+
tol : float
54+
Tolerance value.
55+
steps : int
56+
Maximum number of steps.
57+
refresh : int
58+
Update progress every n steps.
59+
update : bool
60+
Update the co-ordinates of the Network.
61+
callback : callable
62+
Callback function.
8863
89-
# Plotter
64+
Returns
65+
-------
66+
tuple
9067
91-
plotter = NetworkPlotter(network)
68+
* array: Vertex co-ordinates.
69+
* array: Edge forces.
70+
* array: Edge lengths.
9271
93-
lines = []
94-
for u, v in network.edges():
95-
lines.append({
96-
'start': network.vertex_coordinates(u, 'xy'),
97-
'end' : network.vertex_coordinates(v, 'xy'),
98-
'color': '#cccccc',
99-
'width': 1.0})
72+
Example
73+
-------
74+
.. plot::
75+
:include-source:
10076
101-
plotter.draw_lines(lines)
77+
import compas
78+
from compas.datastructures import Network
79+
from compas.plotters import NetworkPlotter
80+
from compas.numerical import drx_numpy
81+
from compas.utilities import i_to_rgb
10282
103-
# Solver
83+
from numpy import linspace
10484
105-
drx_numpy(network=network, tol=0.01, refresh=10, factor=30, update=True)
85+
L0 = 1
86+
L = 1.5
87+
n = 40
88+
EI = 0.2
89+
pins = [0, 5, 20, n - 5]
10690
107-
# Result
91+
# Network
10892
109-
plotter.draw_vertices(radius=0.005, facecolor={key: '#ff0000' for key in pins})
110-
plotter.draw_edges()
93+
vertices = [[i, i, 0] for i in list(linspace(0, L0, n))]
94+
edges = [[i, i + 1] for i in range(n - 1)]
11195
112-
plotter.show()
96+
network = Network.from_vertices_and_edges(vertices=vertices, edges=edges)
97+
network.update_default_vertex_attributes({'is_fixed': False, 'P': [1, -2, 0], 'EIx': EI, 'EIy': EI})
98+
network.update_default_edge_attributes({'E': 50, 'A': 1, 'l0': L / n})
99+
network.set_vertices_attributes(pins, {'B': [0, 0, 0], 'is_fixed': True})
100+
network.beams = {'beam': {'nodes': list(range(n))}}
113101
102+
# Plotter
114103
115-
.. code-block:: python
104+
plotter = NetworkPlotter(network)
116105
117-
# This code block produces a dynamic visualization
118-
# of the figure above using a callback function.
106+
lines = []
107+
for u, v in network.edges():
108+
lines.append({
109+
'start': network.vertex_coordinates(u, 'xy'),
110+
'end' : network.vertex_coordinates(v, 'xy'),
111+
'color': '#cccccc',
112+
'width': 1.0})
119113
120-
import compas
121-
from compas.datastructures import Network
122-
from compas.plotters import NetworkPlotter
123-
from compas.numerical import drx_numpy
124-
from compas.utilities import i_to_rgb
114+
plotter.draw_lines(lines)
125115
126-
from numpy import linspace
116+
# Solver
127117
128-
# Callback
118+
drx_numpy(network=network, tol=0.01, refresh=10, factor=30, update=True)
129119
130-
def plot_iterations(X, radius=0.005):
120+
# Result
131121
132-
for i in network.vertices():
133-
x, y, z = X[i, :]
134-
network.set_vertex_attributes(i, {'x': x, 'y': y, 'z': z})
122+
plotter.draw_vertices(radius=0.005, facecolor={key: '#ff0000' for key in pins})
123+
plotter.draw_edges()
135124
136-
plotter.update_vertices(radius)
137-
plotter.update_edges()
138-
plotter.update(pause=0.01)
125+
plotter.show()
139126
140-
# Setup
141-
142-
L0 = 1
143-
L = 1.5
144-
n = 40
145-
EI = 0.2
146-
pins = [0, 5, 20, n - 5]
147-
148-
# Network
149-
150-
vertices = [[i, i, 0] for i in list(linspace(0, L0, n))]
151-
edges = [[i, i + 1] for i in range(n - 1)]
152-
153-
network = Network.from_vertices_and_edges(vertices=vertices, edges=edges)
154-
network.update_default_vertex_attributes({'is_fixed': False, 'P': [1, -2, 0], 'EIx': EI, 'EIy': EI})
155-
network.update_default_edge_attributes({'E': 50, 'A': 1, 'l0': L / n})
156-
network.set_vertices_attributes(pins, {'B': [0, 0, 0], 'is_fixed': True})
157-
network.beams = {'beam': {'nodes': list(range(n))}}
158-
159-
# Plotter
160-
161-
plotter = NetworkPlotter(network, figsize=(10, 7))
162-
163-
# Initial configuration
164-
165-
lines = []
166-
for u, v in network.edges():
167-
lines.append({
168-
'start': network.vertex_coordinates(u, 'xy'),
169-
'end' : network.vertex_coordinates(v, 'xy'),
170-
'color': '#cccccc',
171-
'width': 1.0})
172-
173-
plotter.draw_lines(lines)
174-
plotter.draw_vertices(radius=0.005, facecolor={key: '#ff0000' for key in pins})
175-
plotter.draw_edges()
176-
177-
# Solver with dynamic visualization
178-
179-
drx_numpy(network=network, tol=0.01, refresh=10, factor=30, update=True, callback=plot_iterations)
180-
181-
plotter.show()
127+
See Also
128+
--------
129+
*
182130
183131
"""
184-
185132
# Setup
186133

187134
tic1 = time()
@@ -286,7 +233,7 @@ def drx_solver(tol, steps, factor, C, Ct, X, ks, l0, f0, ind_c, ind_t, P, S, B,
286233
if (ts % refresh == 0) or (res < tol):
287234
print('Step:{0} Residual:{1:.3g}'.format(ts, res))
288235
if callback:
289-
callback(X, **kwargs)
236+
callback(ts, X, **kwargs)
290237
ts += 1
291238
return X, f, l
292239

@@ -490,8 +437,8 @@ def _create_arrays(network):
490437

491438
from numpy import linspace
492439

493-
494-
def plot_iterations(X, radius=0.005):
440+
def plot_iterations(k, X, radius=0.005):
441+
print(k)
495442

496443
for i in network.vertices():
497444
x, y, z = X[i, :]
@@ -501,7 +448,6 @@ def plot_iterations(X, radius=0.005):
501448
plotter.update_edges()
502449
plotter.update(pause=0.01)
503450

504-
505451
# ==========================================================================
506452
# Example 1
507453
# ==========================================================================

src/compas/topology/triangulation.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from compas.geometry import is_point_in_circle_xy
1414
from compas.geometry import circle_from_points_xy
1515

16-
from compas.geometry import smooth_area
16+
from compas.geometry import mesh_smooth_area
1717

1818
from compas.topology import mesh_dual
1919

@@ -525,16 +525,7 @@ def trimesh_remesh(mesh,
525525
if allow_boundary_split:
526526
boundary = set(mesh.vertices_on_boundary())
527527

528-
vertices = {key: mesh.vertex_coordinates(key) for key in mesh.vertices()}
529-
faces = {fkey: mesh.face_vertices(fkey) for fkey in mesh.faces()}
530-
adjacency = {key: mesh.vertex_faces(key) for key in mesh.vertices()}
531-
532-
smooth_area(vertices, faces, adjacency, fixed=fixed.union(boundary), kmax=1)
533-
534-
for key, attr in mesh.vertices(True):
535-
attr['x'] = vertices[key][0]
536-
attr['y'] = vertices[key][1]
537-
attr['z'] = vertices[key][2]
528+
mesh_smooth_area(mesh, fixed=fixed.union(boundary), kmax=1)
538529

539530
# callback
540531
if callback:

0 commit comments

Comments
 (0)