コード例 #1
0
def test_balls_difference():
    radius = 1.0
    displacement = 0.5
    s0 = pygalmesh.Ball([displacement, 0, 0], radius)
    s1 = pygalmesh.Ball([-displacement, 0, 0], radius)
    u = pygalmesh.Difference(s0, s1)

    a = numpy.sqrt(radius**2 - displacement**2)
    edge_size = 0.15
    n = int(2 * numpy.pi * a / edge_size)
    circ = [[
        0.0, a * numpy.cos(i * 2 * numpy.pi / n),
        a * numpy.sin(i * 2 * numpy.pi / n)
    ] for i in range(n)]
    circ.append(circ[0])

    pygalmesh.generate_mesh(
        u,
        "out.mesh",
        feature_edges=[circ],
        cell_size=0.15,
        edge_size=edge_size,
        facet_angle=25,
        facet_size=0.15,
        cell_radius_edge_ratio=2.0,
        verbose=False,
    )

    mesh = meshio.read("out.mesh")

    tol = 0.02
    assert abs(max(mesh.points[:, 0]) - (radius + displacement)) < tol
    assert abs(min(mesh.points[:, 0]) - 0.0) < tol
    assert abs(max(mesh.points[:, 1]) - radius) < tol
    assert abs(min(mesh.points[:, 1]) + radius) < tol
    assert abs(max(mesh.points[:, 2]) - radius) < tol
    assert abs(min(mesh.points[:, 2]) + radius) < tol

    vol = sum(compute_volumes(mesh.points, mesh.cells["tetra"]))
    h = radius - displacement
    ref_vol = 4.0 / 3.0 * numpy.pi * radius**3 - 2 * h * numpy.pi / 6.0 * (
        3 * a**2 + h**2)

    assert abs(vol - ref_vol) < 0.05

    return
コード例 #2
0
def l_shape_3d(h):
    b0 = pygalmesh.Cuboid([-1.0, -1.0, -1.0], [1.0, 1.0, 1.0])
    b1 = pygalmesh.Cuboid([0.0, 0.0, 0.0], [1.1, 1.1, 1.1])
    u = pygalmesh.Difference(b0, b1)
    mesh = pygalmesh.generate_mesh(
        u,
        max_edge_size_at_feature_edges=h,
        max_cell_circumradius=h,
        verbose=False,
        # TODO sharpen the intersection edges and avoid
        # [1] 591479 segmentation fault (core dumped) python3 pygalmesh_examples.py
        # feature_edges=[
        #     [[1.0, 0.0, z] for z in numpy.linspace(0.0, 1.0, int(1.0 / h))]
        # ]
    )
    mesh.remove_lower_dimensional_cells()
    mesh.remove_orphaned_nodes()
    return mesh.points, mesh.get_cells_type("tetra")