Skip to content

Commit

Permalink
update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed Jun 24, 2024
1 parent cba20c9 commit 8907605
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 133 deletions.
55 changes: 20 additions & 35 deletions scripts/example_detect_lineloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# 1. create a simple arch from nodes and edges, make form and force diagrams
# ------------------------------------------------------------------------------

graph = FormGraph.from_json(compas_ags.get('paper/gs_arch.json'))
graph = FormGraph.from_json(compas_ags.get("paper/gs_arch.json"))
form = FormDiagram.from_graph(graph)
force = ForceDiagram.from_formdiagram(form)

Expand All @@ -26,16 +26,16 @@
]
for index in edges_ind:
u, v = index
form.edge_attribute((u, v), 'is_ind', True)
form.edge_attribute((u, v), 'q', -1.)
form.edge_attribute((u, v), "is_ind", True)
form.edge_attribute((u, v), "q", -1.0)

# set the fixed corners
left = 2
right = 9
fixed = [left, right]

for key in fixed:
form.vertex_attribute(key, 'is_fixed', True)
form.vertex_attribute(key, "is_fixed", True)

# update the diagrams
form_update_q_from_qind(form)
Expand All @@ -44,23 +44,11 @@
# store lines representing the current state of equilibrium
form_lines = []
for u, v in form.edges():
form_lines.append({
'start': form.vertex_coordinates(u, 'xy'),
'end': form.vertex_coordinates(v, 'xy'),
'width': 1.0,
'color': '#cccccc',
'style': '--'
})
form_lines.append({"start": form.vertex_coordinates(u, "xy"), "end": form.vertex_coordinates(v, "xy"), "width": 1.0, "color": "#cccccc", "style": "--"})

force_lines = []
for u, v in force.edges():
force_lines.append({
'start': force.vertex_coordinates(u, 'xy'),
'end': force.vertex_coordinates(v, 'xy'),
'width': 1.0,
'color': '#cccccc',
'style': '--'
})
force_lines.append({"start": force.vertex_coordinates(u, "xy"), "end": force.vertex_coordinates(v, "xy"), "width": 1.0, "color": "#cccccc", "style": "--"})

# Detect the leaves of form diagram:

Expand All @@ -77,7 +65,7 @@
# for edge in form.leaf_edges():
# index = edge_index[edge]
# dual = edges_force[index]
# sp, ep = form.edge_coordinates(*edge)
# sp, ep = form.edge_coordinates(edge)
# print('INDEX -->', index)
# print('original edge -->', edge)
# print('dual edge -->', dual)
Expand All @@ -94,8 +82,8 @@
move_vertices = [0, 9, 8]
translation = +1.0
for key in move_vertices:
x0 = force.vertex_attribute(key, 'x')
force.vertex_attribute(key, 'x', x0 + translation)
x0 = force.vertex_attribute(key, "x")
force.vertex_attribute(key, "x", x0 + translation)

form_update_from_force(form, force)

Expand All @@ -105,19 +93,16 @@
# ------------------------------------------------------------------------------
viewer = Viewer(form, force, delay_setup=False)

viewer.draw_form(lines=form_lines,
forces_on=True,
vertexlabel={key: key for key in form.vertices()},
external_on=False,
vertexsize=0.2,
vertexcolor={**{key: '#000000' for key in form.fixed()}, **{key: '#FF0000' for key in form.fixed_x()}},
edgelabel={uv: index for index, uv in enumerate(form.edges())}
)

viewer.draw_force(lines=force_lines,
vertexlabel={key: key for key in force.vertices()},
vertexsize=0.2,
edgelabel=force_edge_labels
)
viewer.draw_form(
lines=form_lines,
forces_on=True,
vertexlabel={key: key for key in form.vertices()},
external_on=False,
vertexsize=0.2,
vertexcolor={**{key: "#000000" for key in form.fixed()}, **{key: "#FF0000" for key in form.fixed_x()}},
edgelabel={uv: index for index, uv in enumerate(form.edges())},
)

viewer.draw_force(lines=force_lines, vertexlabel={key: key for key in force.vertices()}, vertexsize=0.2, edgelabel=force_edge_labels)

viewer.show()
57 changes: 21 additions & 36 deletions scripts/paper-CSD/exampleD_truss_constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ def view_form_force(form, force, forcescale=0.5, edge_label=True):
force_edge_label = None

viewer = Viewer(form, force, delay_setup=False)
viewer.draw_form(edgelabel=form_edge_label,
forces_on=True,
forcescale=forcescale,
vertexcolor={key: '#000000' for key in form.vertices_where({'is_fixed': True})})
viewer.draw_form(edgelabel=form_edge_label, forces_on=True, forcescale=forcescale, vertexcolor={key: "#000000" for key in form.vertices_where({"is_fixed": True})})
viewer.draw_force(edgelabel=force_edge_label)
viewer.show()

Expand All @@ -34,39 +31,27 @@ def view_with_initial_stage(form, force, forcescale=0.5, edge_label=True):
force_edge_label = None

viewer = Viewer(form, force, delay_setup=False)
viewer.draw_form(lines=form_lines,
forces_on=True,
external_on=True,
forcescale=forcescale,
edgelabel=form_edge_label,
vertexcolor={key: '#000000' for key in form.vertices_where({'is_fixed': True})})
viewer.draw_force(lines=force_lines,
edgelabel=force_edge_label
)
viewer.draw_form(
lines=form_lines,
forces_on=True,
external_on=True,
forcescale=forcescale,
edgelabel=form_edge_label,
vertexcolor={key: "#000000" for key in form.vertices_where({"is_fixed": True})},
)
viewer.draw_force(lines=force_lines, edgelabel=force_edge_label)
viewer.show()


def store_initial_lines(form, force):

form_lines = []
for u, v in form.edges():
form_lines.append({
'start': form.vertex_coordinates(u, 'xy'),
'end': form.vertex_coordinates(v, 'xy'),
'width': 1.0,
'color': '#cccccc',
'style': '--'
})
form_lines.append({"start": form.vertex_coordinates(u, "xy"), "end": form.vertex_coordinates(v, "xy"), "width": 1.0, "color": "#cccccc", "style": "--"})

force_lines = []
for u, v in force.edges():
force_lines.append({
'start': force.vertex_coordinates(u, 'xy'),
'end': force.vertex_coordinates(v, 'xy'),
'width': 1.0,
'color': '#cccccc',
'style': '--'
})
force_lines.append({"start": force.vertex_coordinates(u, "xy"), "end": force.vertex_coordinates(v, "xy"), "width": 1.0, "color": "#cccccc", "style": "--"})

return form_lines, force_lines

Expand All @@ -82,7 +67,7 @@ def store_initial_lines(form, force):
# 1. Get geometry, apply loads and and compute equilibrium
# ------------------------------------------------------------------------------

input_file = compas_ags.get('paper/exD_truss.obj')
input_file = compas_ags.get("paper/exD_truss.obj")

graph = FormGraph.from_obj(input_file)
form = FormDiagram.from_graph(graph)
Expand All @@ -99,16 +84,16 @@ def store_initial_lines(form, force):
]
for index in edges_ind:
u, v = index
form.edge_attribute((u, v), 'is_ind', True)
form.edge_attribute((u, v), 'q', +2.)
form.edge_attribute((u, v), "is_ind", True)
form.edge_attribute((u, v), "q", +2.0)

index_edge = form.index_edge()

# set the fixed corners
fixed = [5, 1]

for key in fixed:
form.vertex_attribute(key, 'is_fixed', True)
form.vertex_attribute(key, "is_fixed", True)

# update the diagrams
form_update_q_from_qind(form)
Expand All @@ -128,25 +113,25 @@ def store_initial_lines(form, force):

for index in edges_fix_orient:
edge = index_edge[index]
sp, ep = form.edge_coordinates(*edge)
sp, ep = form.edge_coordinates(edge)
dx = ep[0] - sp[0]
dy = ep[1] - sp[1]
length = (dx**2 + dy**2)**0.5
form.edge_attribute(edge, 'target_vector', [dx/length, dy/length])
length = (dx**2 + dy**2) ** 0.5
form.edge_attribute(edge, "target_vector", [dx / length, dy / length])

# B. Assign forces on the top chord to have the same length
index_edges_constant_force = [9, 7, 5, 0, 1]
L = 5.0

for index in index_edges_constant_force:
form.edge_attribute(index_edge[index], 'target_force', L)
form.edge_attribute(index_edge[index], "target_force", L)

# C. Guarantee constant force application
index_edges_constant_load = [20, 18, 16, 14]
load = 2.0

for index in index_edges_constant_load:
form.edge_attribute(index_edge[index], 'target_force', load)
form.edge_attribute(index_edge[index], "target_force", load)

# Identify auto constraints
form.identify_constraints()
Expand Down
Loading

0 comments on commit 8907605

Please sign in to comment.