Skip to content

Commit

Permalink
Update test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam-Bouten committed Nov 11, 2021
1 parent dcd6276 commit 4a61d63
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import compas
from compas.geometry import Vector, Plane, Point, Line
from compas_fd.datastructures import CableMesh
from compas_fd.fd import fd_iter_numpy

from compas_fd.constraints import Constraint
from compas_fd.numdata import FDNumericalData
from compas_fd.solvers import FDConstraintSolver

from compas_view2.app import App
from compas_view2.objects import Object, MeshObject
Expand All @@ -23,7 +24,7 @@

# plane constraint
vertex = list(mesh.vertices_where({'x': 0, 'y': 0}))[0]
plane = Plane((-1, 0, 0), (2, 1, 1))
plane = Plane((-1, 0, 0), (2, 1, -1))
constraint = Constraint(plane)
mesh.vertex_attribute(vertex, 'constraint', constraint)

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

# solver
result = fd_iter_numpy(vertices=vertices,
fixed=fixed,
edges=edges,
forcedensities=forcedensities,
loads=loads,
constraints=constraints,
max_iter=100,
tol_res=1E-3,
tol_dxyz=1E-1)
# set up iterative constraint solver
numdata = FDNumericalData.from_params(vertices, fixed, edges, forcedensities, loads)
solver = FDConstraintSolver(numdata, constraints, max_iter=30,
tol_res=1E-3, tol_dxyz=1E-3)

# run solver
result = solver()
print(solver.iter_count)

# update mesh
for index, vertex in enumerate(mesh.vertices()):
Expand Down
56 changes: 56 additions & 0 deletions scripts/test_fd_solver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import compas
from compas.geometry import Point, Line, Vector
from compas_fd.datastructures import CableMesh

from compas_fd.numdata import FDNumericalData
from compas_fd.solvers import FDSolver

from compas_view2.app import App
from compas_view2.objects import Object, MeshObject

Object.register(CableMesh, MeshObject)

mesh = CableMesh.from_obj(compas.get('faces.obj'))

mesh.vertices_attribute('is_anchor', True, keys=list(mesh.vertices_where({'vertex_degree': 2})))
mesh.vertices_attribute('t', 0.0)

# input parameters
vertex_index = mesh.vertex_index()
vertices = mesh.vertices_attributes('xyz')
fixed = list(mesh.vertices_where({'is_anchor': True}))
edges = [(vertex_index[u], vertex_index[v]) for
u, v in mesh.edges_where({'_is_edge': True})]
forcedensities = mesh.edges_attribute('q')
loads = mesh.vertices_attributes(['px', 'py', 'pz'])

# set up single iteration solver
numdata = FDNumericalData.from_params(vertices, fixed, edges, forcedensities, loads)
solver = FDSolver(numdata)

# run solver
result = solver()

# update mesh
for index, vertex in enumerate(mesh.vertices()):
mesh.vertex_attributes(vertex, 'xyz', result.vertices[index])
mesh.vertex_attributes(vertex, ['_rx', '_ry', '_rz'], result.residuals[index])


# ==============================================================================
# Viz
# ==============================================================================

viewer = App()

viewer.add(mesh)

for vertex in fixed:
viewer.add(Point(* mesh.vertex_attributes(vertex, 'xyz')), size=20, color=(0, 0, 0))

for vertex in fixed:
a = Point(* mesh.vertex_attributes(vertex, 'xyz'))
b = a - Vector(* mesh.vertex_attributes(vertex, ['_rx', '_ry', '_rz']))
viewer.add(Line(a, b), linewidth=3, linecolor=(0, 0, 1))

viewer.run()

0 comments on commit 4a61d63

Please sign in to comment.