Exemple #1
0
def test_json_volmesh():
    before = VolMesh.from_vertices_and_cells(
        [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 0, 1], [1, 0, 1],
         [1, 1, 1], [0, 1, 1]], [[[0, 1, 5, 4], [1, 2, 5, 6], [2, 3, 7, 6],
                                  [3, 0, 4, 7], [4, 5, 6, 7], [0, 3, 2, 1]]])
    after = compas.json_loads(compas.json_dumps(before))
    assert before.dtype == after.dtype
    assert before.attributes == after.attributes
    assert all(before.has_vertex(vertex) for vertex in after.vertices())
    assert all(after.has_vertex(vertex) for vertex in before.vertices())
Exemple #2
0
def volmesh_from_ansys_results(output_path, name):
    output_path = os.path.join(output_path, name + '_output')
    nodes, elements = get_nodes_elements_from_result_files(output_path)
    nkeys = sorted(nodes.keys(), key=int)
    vertices = [[nodes[k]['x'], nodes[k]['y'], nodes[k]['z']] for k in nkeys]
    ckeys = sorted(elements.keys(), key=int)
    cells = []
    for ck in ckeys:
        i, j, k, l, m, n, o, p = elements[ck]['nodes']
        if k == l:
            cells.append([[i, j, k], [i, j, m], [j, k, m], [k, i, m]])
        else:
            cells.append([[i, j, k, l], [i, j, n, m], [j, k, o, n],
                          [k, l, p, o], [l, i, m, p], [m, n, o, p]])

    mesh = VolMesh.from_vertices_and_cells(vertices, cells)
    return mesh
Exemple #3
0
#    from compas.geometry import centroid_points
#    rs.AddPoint(centroid_points([a, b, c, d]))
#    # sphere centre
#rs.EnableRedraw(True)

cells = []
for a, b, c, d in simplices:
    #print a, b, c, d
    halffaces = [[a, b, c], [a, b, d], [a, c, d], [b, c, d]]
    cells.append(halffaces)
    #halffaces.append([a, b, c])
    #halffaces.append([c, b, a])
    #halffaces.append([a, b, d])
    #halffaces.append([d, b, a])
    #halffaces.append([a, c, d])
    #halffaces.append([d, c, a])
    #halffaces.append([b, c, d])
    #halffaces.append([d, c, d])

from compas.datastructures import VolMesh

volmesh = VolMesh.from_vertices_and_cells(points, cells)

print volmesh.cells()

#rs.EnableRedraw(False)
#for u, v in volmesh.edges():
#    u = volmesh.vertex_coordinates(u)
#    v = volmesh.vertex_coordinates(v)
#    rs.AddLine(u, v)
#rs.EnableRedraw(True)