Ejemplo n.º 1
0
def test_simple_lloyd(mesh, ref1, ref2, refi):
    X, cells = mesh()

    X, cells = optimesh.lloyd(X, cells, 1.0e-2, 100, fcc_type="boundary", verbosity=2)

    # Test if we're dealing with the mesh we expect.
    nc = X.flatten()
    norm1 = numpy.linalg.norm(nc, ord=1)
    norm2 = numpy.linalg.norm(nc, ord=2)
    normi = numpy.linalg.norm(nc, ord=numpy.inf)

    tol = 1.0e-12
    assert abs(norm1 - ref1) < tol * ref1
    assert abs(norm2 - ref2) < tol * ref2
    assert abs(normi - refi) < tol * refi
    return
Ejemplo n.º 2
0
def _create_mesh(filename):
    poly = dmsh.Polygon(
        [
            [-295.0, 0.0],
            [-160.0, 0.0],
            [-50.0, 110.0],
            [-50.0, 190.0],
            [+50.0, 190.0],
            [+50.0, 110.0],
            [+160.0, 0.0],
            [+295.0, 0.0],
            [+405.0, 110.0],
            [+405.0, 235.0],
            [+200.0, 430.0],
            [+170.0, 400.0],
            [+355.0, 235.0],
            [-355.0, 235.0],
            [-170.0, 400.0],
            [-200.0, 430.0],
            [-405.0, 235.0],
            [-405.0, 110.0],
        ]
    )

    geo = dmsh.Union(
        [
            poly,
            dmsh.Circle([-295.0, 110.0], 110.0),
            dmsh.Circle([+295.0, 110.0], 110.0),
            dmsh.Circle([-160.0, 110.0], 110.0),
            dmsh.Circle([+160.0, 110.0], 110.0),
        ]
    )

    X, cells = dmsh.generate(
        geo,
        35.0,
        # show=True
    )

    X, cells = optimesh.lloyd(X, cells, 1.0e-3, 100)

    X = numpy.column_stack([X[:, 0], X[:, 1], numpy.zeros(X.shape[0])])

    meshio.write_points_cells(filename, X, {"triangle": cells})
    return
Ejemplo n.º 3
0
def create_logo():
    geom = pygmsh.opencascade.Geometry(characteristic_length_min=0.5,
                                       characteristic_length_max=0.5)

    container = geom.add_rectangle([0.0, 0.0, 0.0], 10.0, 10.0)

    letter_i = geom.add_rectangle([2.0, 2.0, 0.0], 1.0, 4.5)
    i_dot = geom.add_disk([2.5, 7.5, 0.0], 0.6)

    disk1 = geom.add_disk([6.25, 4.5, 0.0], 2.5)
    disk2 = geom.add_disk([6.25, 4.5, 0.0], 1.5)
    letter_o = geom.boolean_difference([disk1], [disk2])

    geom.boolean_difference([container], [letter_i, i_dot, letter_o])

    X, cells, _, _, _ = pygmsh.generate_mesh(geom)
    X, cells = optimesh.lloyd(X, cells["triangle"], 1.0e-3, 1000)
    return X, cells
Ejemplo n.º 4
0
    diff1 = geom.boolean_difference([r1], [r2])
    r22 = geom.add_rectangle([9.0, 10.0, 0.0], 11.0, 11.0)
    inter1 = geom.boolean_intersection([diff1, r22])

    r3 = geom.add_rectangle([10.0, 19.5, 0.0], 21.0, 21.0, corner_radius=8.0)
    r4 = geom.add_rectangle([10.0, 20.5, 0.0], 20.0, 20.0, corner_radius=7.0)
    diff2 = geom.boolean_difference([r3], [r4])
    r33 = geom.add_rectangle([20.0, 19.0, 0.0], 11.0, 11.0)
    inter2 = geom.boolean_intersection([diff2, r33])

    geom.boolean_difference(
        [rect1, rect2], [disk1, disk2, rect3, rect4, inter1, inter2]
    )

    mesh = pygmsh.generate_mesh(geom)
    ref = 1082.4470502181903
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh


if __name__ == "__main__":
    import optimesh

    mesh = test()
    points, cells = optimesh.lloyd(mesh.points, mesh.cells["triangle"], 1.0e-5, 10000)
    # # from helpers import plot
    # # plot("logo.png", points, {"triangle": cells})
    import meshio

    meshio.write_points_cells("logo.svg", points, {"triangle": cells})
Ejemplo n.º 5
0
    diff1 = geom.boolean_difference([r1], [r2])
    r22 = geom.add_rectangle([9.0, 10.0, 0.0], 11.0, 11.0)
    inter1 = geom.boolean_intersection([diff1, r22])

    r3 = geom.add_rectangle([10.0, 19.5, 0.0], 21.0, 21.0, corner_radius=8.0)
    r4 = geom.add_rectangle([10.0, 20.5, 0.0], 20.0, 20.0, corner_radius=7.0)
    diff2 = geom.boolean_difference([r3], [r4])
    r33 = geom.add_rectangle([20.0, 19.0, 0.0], 11.0, 11.0)
    inter2 = geom.boolean_intersection([diff2, r33])

    geom.boolean_difference([rect1, rect2],
                            [disk1, disk2, rect3, rect4, inter1, inter2])

    mesh = pygmsh.generate_mesh(geom)
    ref = 1082.4470502181903
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh


if __name__ == "__main__":
    import optimesh

    mesh = test()
    points, cells = optimesh.lloyd(mesh.points, mesh.cells["triangle"], 1.0e-5,
                                   10000)
    # # from helpers import plot
    # # plot("logo.png", points, {"triangle": cells})
    import meshio

    meshio.write_points_cells("logo.svg", points, {"triangle": cells})