Exemplo n.º 1
0
def test_2d():
    points = numpy.array([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]])
    constraints = [[0, 1], [1, 2], [2, 3], [3, 0]]

    mesh = pygalmesh.generate_2d(points,
                                 constraints,
                                 cell_size=1.0e-1,
                                 num_lloyd_steps=10)

    assert mesh.points.shape == (276, 2)
    assert mesh.get_cells_type("triangle").shape == (486, 3)
Exemplo n.º 2
0
def square2x2():
    points = numpy.array([[0.0, 0.0], [2.0, 0.0], [2.0, 2.0], [0.0, 2.0]])
    constraints = [[0, 1], [1, 2], [2, 3], [3, 0]]
    mesh = pygalmesh.generate_2d(
        points,
        constraints,
        max_edge_size=0.3,
        num_lloyd_steps=10,
    )

    print(len(mesh.points), len( mesh.get_cells_type("triangle")))
    write_node(mesh.points)
    write_ele(len(mesh.points), mesh.get_cells_type("triangle"))
    mesh.write("square.svg")
Exemplo n.º 3
0
def disk(h):
    n = int(2 * numpy.pi / h)
    points = numpy.array([[
        numpy.cos(alpha), numpy.sin(alpha)
    ] for alpha in numpy.linspace(0.0, 2 * numpy.pi, n + 1, endpoint=False)])
    constraints = [[k, k + 1] for k in range(n)] + [[n, 0]]
    mesh = pygalmesh.generate_2d(
        points,
        constraints,
        # Relax max_edge size a bit; with 1.5, one gets node/cell numbers comparable to
        # the other mesh generators.
        max_edge_size=h * 1.5,
        num_lloyd_steps=0,
    )
    return mesh.points, mesh.get_cells_type("triangle")
Exemplo n.º 4
0
def test_disk():
    h = 0.1
    n = int(2 * numpy.pi / h)
    points = numpy.array([[
        numpy.cos(alpha), numpy.sin(alpha)
    ] for alpha in numpy.linspace(0.0, 2 * numpy.pi, n + 1, endpoint=False)])
    constraints = [[k, k + 1] for k in range(n)] + [[n, 0]]
    mesh = pygalmesh.generate_2d(
        points,
        constraints,
        max_edge_size=h,
        num_lloyd_steps=0,
    )
    areas = compute_triangle_areas(mesh.points,
                                   mesh.get_cells_type("triangle"))
    assert numpy.all(areas > 1.0e-5)
Exemplo n.º 5
0
def l_shape(h):
    points = numpy.array([
        [-1.0, -1.0],
        [+1.0, -1.0],
        [+1.0, +0.0],
        [+0.0, +0.0],
        [+0.0, +1.0],
        [-1.0, +1.0],
    ])
    n = len(points) - 1
    constraints = [[k, k + 1] for k in range(n)] + [[n, 0]]
    mesh = pygalmesh.generate_2d(
        points,
        constraints,
        # Relax max_edge size a bit; with 1.5, one gets node/cell numbers comparable to
        # the other mesh generators.
        max_edge_size=h * 1.5,
        num_lloyd_steps=0,
    )
    return mesh.points, mesh.get_cells_type("triangle")
Exemplo n.º 6
0
def run_cgal(HMIN=0.01):

    n = 50
    points = numpy.array(
        [[numpy.cos(alpha), numpy.sin(alpha)]
         for alpha in numpy.linspace(0.0, 2 * numpy.pi, n, endpoint=False)])
    constraints = [[k, k + 1] for k in range(n - 1)] + [[n - 1, 0]]

    t1 = time.time()
    mesh = pygalmesh.generate_2d(points, constraints, edge_size=HMIN)
    elapsed = time.time() - t1

    # mesh.write("cgal_circle.vtk")

    points = mesh.points
    cells = mesh.cells[0].data

    num_cells = len(cells)
    num_vertices = len(points)

    plex = meshplex.MeshTri(points, cells)
    quality = numpy.abs(plex.cell_quality)

    return quality, elapsed, num_vertices, num_cells