Example #1
0
def test_balls_union():
    radius = 1.0
    displacement = 0.5
    s0 = frentos.Ball([displacement, 0, 0], radius)
    s1 = frentos.Ball([-displacement, 0, 0], radius)
    uni = frentos.ListOfDomains()
    uni.append(s0)
    uni.append(s1)
    u = frentos.Union(uni)

    a = numpy.sqrt(radius**2 - displacement**2)
    edge_size = 0.1
    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])

    frentos.generate_mesh(
            u,
            'out.mesh',
            feature_edges=[circ],
            cell_size=0.15,
            edge_size=edge_size,
            verbose=False
            )

    vertices, cells, _, _, _ = meshio.read('out.mesh')

    assert abs(max(vertices[:, 0]) - (radius + displacement)) < 0.02
    assert abs(min(vertices[:, 0]) + (radius + displacement)) < 0.02
    assert abs(max(vertices[:, 1]) - radius) < 0.02
    assert abs(min(vertices[:, 1]) + radius) < 0.02
    assert abs(max(vertices[:, 2]) - radius) < 0.02
    assert abs(min(vertices[:, 2]) + radius) < 0.02

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

    assert abs(vol - ref_vol) < 0.1

    return
Example #2
0
def test_balls_difference():
    radius = 1.0
    displacement = 0.5
    s0 = frentos.Ball([displacement, 0, 0], radius)
    s1 = frentos.Ball([-displacement, 0, 0], radius)
    u = frentos.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])

    frentos.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
            )

    vertices, cells, _, _, _ = meshio.read('out.mesh')

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

    vol = sum(compute_volumes(vertices, 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
Example #3
0
def test_sphere():
    radius = 1.0
    s = frentos.Ball([0, 0, 0], radius)
    frentos.generate_surface_mesh(
            s,
            'out.off',
            angle_bound=30,
            radius_bound=0.1,
            distance_bound=0.1,
            verbose=False
            )

    vertices, cells, _, _, _ = meshio.read('out.off')

    tol = 1.0e-2
    assert abs(max(vertices[:, 0]) - radius) < tol
    assert abs(min(vertices[:, 0]) + radius) < tol
    assert abs(max(vertices[:, 1]) - radius) < tol
    assert abs(min(vertices[:, 1]) + radius) < tol
    assert abs(max(vertices[:, 2]) - radius) < tol
    assert abs(min(vertices[:, 2]) + radius) < tol

    areas = compute_triangle_areas(vertices, cells['triangle'])
    surface_area = sum(areas)
    assert abs(surface_area - 4 * numpy.pi * radius**2) < 0.1

    return
Example #4
0
def test_ball():
    s = frentos.Ball([0, 0, 0], 1.0)
    frentos.generate_mesh(s, 'out.mesh', cell_size=0.2, verbose=False)

    vertices, cells, _, _, _ = meshio.read('out.mesh')

    assert abs(max(vertices[:, 0]) - 1.0) < 0.02
    assert abs(min(vertices[:, 0]) + 1.0) < 0.02
    assert abs(max(vertices[:, 1]) - 1.0) < 0.02
    assert abs(min(vertices[:, 1]) + 1.0) < 0.02
    assert abs(max(vertices[:, 2]) - 1.0) < 0.02
    assert abs(min(vertices[:, 2]) + 1.0) < 0.02

    vol = sum(compute_volumes(vertices, cells['tetra']))
    assert abs(vol - 4.0/3.0 * numpy.pi) < 0.15

    return