Importing compas_fd to rhino8 ScriptEditor

hi keerthana,

just wanted to let you know that most problems are resolved.
the screenshot is generated with the following code

from compas.datastructures import Mesh
from compas.geometry import Point, Vector, Line, NurbsCurve
from compas.geometry import Sphere, Cylinder
from compas.scene import Scene
from compas.colors import Color

from compas_fd.solvers import fd_constrained_numpy
from compas_fd.constraints import Constraint

# mesh

mesh = Mesh.from_meshgrid(dx=100, nx=26)

# vertices, edges

vertices = mesh.vertices_attributes("xyz")
edges = list(mesh.edges())

# anchors/supports

supports = list(mesh.vertices_where(vertex_degree=2))
supports += list(mesh.vertices_where(x=50, y=0))
supports += list(mesh.vertices_where(x=50, y=100))

# loads

loads = [[0, 0, 0] for _ in range(mesh.number_of_vertices())]

# force densities

q = []
for edge in edges:
    if mesh.is_edge_on_boundary(edge):
        q.append(30)
    else:
        q.append(1.0)

# constraints

arch = NurbsCurve.from_points([[50, 0, 0], [50, 50, 50], [50, 100, 0]], degree=2)
constraint = Constraint(arch)

constraints = [None] * mesh.number_of_vertices()
constrained = []
for vertex in mesh.vertices_where(x=50):
    if vertex in supports:
        continue
    constraints[vertex] = constraint
    constrained.append(vertex)

# solve and update

result = fd_constrained_numpy(
    vertices=vertices,
    fixed=list(set(supports + constrained)),
    edges=edges,
    forcedensities=q,
    loads=loads,
    constraints=constraints,
)

for vertex, attr in mesh.vertices(data=True):
    attr["x"] = result.vertices[vertex, 0]
    attr["y"] = result.vertices[vertex, 1]
    attr["z"] = result.vertices[vertex, 2]

# visualize

scene = Scene()
scene.clear()

scene.add(mesh, disjoint=True)
scene.add(arch)

for vertex in supports:
    scene.add(mesh.vertex_point(vertex), color=Color.red())

for vertex in supports:
    point = mesh.vertex_point(vertex)
    vector = Vector(*result.residuals[vertex]) * -0.5
    line = Line.from_point_and_vector(point, vector)
    scene.add(line, color=Color.green())

for index, edge in enumerate(mesh.edges()):
    if mesh.is_edge_on_boundary(edge):
        line = mesh.edge_line(edge)
        radius = 0.005 * result.forces[index]
        pipe = Cylinder.from_line_and_radius(line, radius)
        scene.add(pipe, color=Color.red())

scene.draw()

we will release a new version of COMPAS with all of the small updates and a few more additional improvements on Friday (the weekly build)…

2 Likes