@@ -83,8 +83,13 @@ def dr(vertices, edges, fixed, loads, qpre, fpre, lpre, linit, E, radius,
8383 import compas
8484 from compas.datastructures import Network
8585 from compas.plotters import NetworkPlotter
86- from compas.numerical import dr
8786 from compas.utilities import i_to_rgb
87+ from compas.numerical import dr
88+
89+ # make a network
90+ # and set the default vertex and edge attributes
91+
92+ network = Network.from_obj(compas.get('lines.obj'))
8893
8994 dva = {
9095 'is_fixed': False,
@@ -108,22 +113,23 @@ def dr(vertices, edges, fixed, loads, qpre, fpre, lpre, linit, E, radius,
108113 'radius': 0.0,
109114 }
110115
111- network = Network.from_obj(compas.get('lines.obj'))
112-
113116 network.update_default_vertex_attributes(dva)
114117 network.update_default_edge_attributes(dea)
115118
119+ # identify the fixed vertices
120+ # and assign random prescribed force densities to the edges
121+
116122 for key, attr in network.vertices(True):
117123 attr['is_fixed'] = network.vertex_degree(key) == 1
118124
119125 for u, v, attr in network.edges(True):
120126 attr['qpre'] = 1.0 * random.randint(1, 7)
121127
122- k_i = network.key_index()
128+ # extract numerical data from the datastructure
123129
124130 vertices = network.get_vertices_attributes(('x', 'y', 'z'))
125- edges = [(k_i[u], k_i[v]) for u, v in network.edges()]
126- fixed = [k_i[key] for key in network.vertices_where({'is_fixed': True})]
131+ edges = list( network.edges())
132+ fixed = network.vertices_where({'is_fixed': True})
127133 loads = network.get_vertices_attributes(('px', 'py', 'pz'))
128134 qpre = network.get_edges_attribute('qpre')
129135 fpre = network.get_edges_attribute('fpre')
@@ -132,6 +138,11 @@ def dr(vertices, edges, fixed, loads, qpre, fpre, lpre, linit, E, radius,
132138 E = network.get_edges_attribute('E')
133139 radius = network.get_edges_attribute('radius')
134140
141+ # make a plotter for (dynamic) visualization
142+ # plot the lines of the original configuration of the network as reference
143+
144+ plotter = NetworkPlotter(network)
145+
135146 lines = []
136147 for u, v in network.edges():
137148 lines.append({
@@ -141,26 +152,31 @@ def dr(vertices, edges, fixed, loads, qpre, fpre, lpre, linit, E, radius,
141152 'width': 0.5
142153 })
143154
144- plotter = NetworkPlotter(network)
145155 plotter.draw_lines(lines)
146156
147- xyz, q, f, l, r = dr(vertices, edges, fixed, loads,
148- qpre, fpre, lpre,
149- linit, E, radius,
157+ # run the dynamic relaxation
158+ # update vertices and edges
159+ # visualize the final geometry
160+ # color the edges according to the size of the forces
161+ # set the width of the edges proportional to the internal forces
162+
163+ xyz, q, f, l, r = dr(vertices, edges, fixed, loads, qpre, fpre, lpre, linit, E, radius,
150164 kmax=100)
151165
152166 for key, attr in network.vertices(True):
153- index = k_i[key]
154- attr['x'] = xyz[index][0]
155- attr['y'] = xyz[index][1]
156- attr['z'] = xyz[index][2]
167+ attr['x'] = xyz[key][0]
168+ attr['y'] = xyz[key][1]
169+ attr['z'] = xyz[key][2]
157170
158171 for index, (u, v, attr) in enumerate(network.edges(True)):
159172 attr['f'] = f[index]
160173 attr['l'] = l[index]
161174
162175 fmax = max(network.get_edges_attribute('f'))
163176
177+ plotter.clear_vertices()
178+ plotter.clear_edges()
179+
164180 plotter.draw_vertices(
165181 facecolor={key: '#000000' for key in network.vertices_where({'is_fixed': True})}
166182 )
0 commit comments