Skip to content

Commit 578afca

Browse files
committed
Update test scripts
1 parent c3de956 commit 578afca

2 files changed

Lines changed: 67 additions & 12 deletions

File tree

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import compas
22
from compas.geometry import Vector, Plane, Point, Line
33
from compas_fd.datastructures import CableMesh
4-
from compas_fd.fd import fd_iter_numpy
54

65
from compas_fd.constraints import Constraint
6+
from compas_fd.numdata import FDNumericalData
7+
from compas_fd.solvers import FDConstraintSolver
78

89
from compas_view2.app import App
910
from compas_view2.objects import Object, MeshObject
@@ -23,7 +24,7 @@
2324

2425
# plane constraint
2526
vertex = list(mesh.vertices_where({'x': 0, 'y': 0}))[0]
26-
plane = Plane((-1, 0, 0), (2, 1, 1))
27+
plane = Plane((-1, 0, 0), (2, 1, -1))
2728
constraint = Constraint(plane)
2829
mesh.vertex_attribute(vertex, 'constraint', constraint)
2930

@@ -37,16 +38,14 @@
3738
loads = mesh.vertices_attributes(['px', 'py', 'pz'])
3839
constraints = list(mesh.vertices_attribute('constraint'))
3940

40-
# solver
41-
result = fd_iter_numpy(vertices=vertices,
42-
fixed=fixed,
43-
edges=edges,
44-
forcedensities=forcedensities,
45-
loads=loads,
46-
constraints=constraints,
47-
max_iter=100,
48-
tol_res=1E-3,
49-
tol_dxyz=1E-1)
41+
# set up iterative constraint solver
42+
numdata = FDNumericalData.from_params(vertices, fixed, edges, forcedensities, loads)
43+
solver = FDConstraintSolver(numdata, constraints, max_iter=30,
44+
tol_res=1E-3, tol_dxyz=1E-3)
45+
46+
# run solver
47+
result = solver()
48+
print(solver.iter_count)
5049

5150
# update mesh
5251
for index, vertex in enumerate(mesh.vertices()):

scripts/test_fd_solver.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import compas
2+
from compas.geometry import Point, Line, Vector
3+
from compas_fd.datastructures import CableMesh
4+
5+
from compas_fd.numdata import FDNumericalData
6+
from compas_fd.solvers import FDSolver
7+
8+
from compas_view2.app import App
9+
from compas_view2.objects import Object, MeshObject
10+
11+
Object.register(CableMesh, MeshObject)
12+
13+
mesh = CableMesh.from_obj(compas.get('faces.obj'))
14+
15+
mesh.vertices_attribute('is_anchor', True, keys=list(mesh.vertices_where({'vertex_degree': 2})))
16+
mesh.vertices_attribute('t', 0.0)
17+
18+
# input parameters
19+
vertex_index = mesh.vertex_index()
20+
vertices = mesh.vertices_attributes('xyz')
21+
fixed = list(mesh.vertices_where({'is_anchor': True}))
22+
edges = [(vertex_index[u], vertex_index[v]) for
23+
u, v in mesh.edges_where({'_is_edge': True})]
24+
forcedensities = mesh.edges_attribute('q')
25+
loads = mesh.vertices_attributes(['px', 'py', 'pz'])
26+
27+
# set up single iteration solver
28+
numdata = FDNumericalData.from_params(vertices, fixed, edges, forcedensities, loads)
29+
solver = FDSolver(numdata)
30+
31+
# run solver
32+
result = solver()
33+
34+
# update mesh
35+
for index, vertex in enumerate(mesh.vertices()):
36+
mesh.vertex_attributes(vertex, 'xyz', result.vertices[index])
37+
mesh.vertex_attributes(vertex, ['_rx', '_ry', '_rz'], result.residuals[index])
38+
39+
40+
# ==============================================================================
41+
# Viz
42+
# ==============================================================================
43+
44+
viewer = App()
45+
46+
viewer.add(mesh)
47+
48+
for vertex in fixed:
49+
viewer.add(Point(* mesh.vertex_attributes(vertex, 'xyz')), size=20, color=(0, 0, 0))
50+
51+
for vertex in fixed:
52+
a = Point(* mesh.vertex_attributes(vertex, 'xyz'))
53+
b = a - Vector(* mesh.vertex_attributes(vertex, ['_rx', '_ry', '_rz']))
54+
viewer.add(Line(a, b), linewidth=3, linecolor=(0, 0, 1))
55+
56+
viewer.run()

0 commit comments

Comments
 (0)