Ejemplo n.º 1
0
def test_square_circle_slice():
    """Test planar suface square with circular hole.

    Also test for surface area of fragments.
    """
    geo_object = built_in_opencascade_geos_fragments()

    # Gmsh 4 default format MSH4 doesn't have geometrical entities.
    mesh = pygmsh.generate_mesh(geo_object, extra_gmsh_arguments=["-format", "msh2"])
    ref = 1
    val = compute_volume(mesh)
    assert np.abs(val - ref) < 1e-3 * ref

    outer_mask = np.where(mesh.cell_data["triangle"]["gmsh:geometrical"] == 13)[0]
    outer_cells = {}
    outer_cells["triangle"] = mesh.cells["triangle"][outer_mask]

    inner_mask = np.where(mesh.cell_data["triangle"]["gmsh:geometrical"] == 12)[0]
    inner_cells = {}
    inner_cells["triangle"] = mesh.cells["triangle"][inner_mask]

    ref = 1 - 0.1 ** 2 * np.pi
    value = compute_volume(meshio.Mesh(mesh.points, outer_cells))
    assert np.abs(value - ref) < 1e-2 * ref
    return
Ejemplo n.º 2
0
def test_fragments_diff_union():
    """Test planar surface with holes.

    Construct it with boolean operations and verify that it is the same.
    """
    # construct surface using boolean
    with pygmsh.occ.Geometry() as geom:
        geom.characteristic_length_min = 0.04
        geom.characteristic_length_max = 0.04
        square = square_loop(geom)
        surf1 = geom.add_plane_surface(square)
        curve_loop = circle_loop(geom)
        surf2 = geom.add_plane_surface(curve_loop)

        geom.add_physical([surf1], label="1")
        geom.add_physical([surf2], label="2")
        geom.boolean_difference(surf1, surf2, delete_other=False)
        mesh = geom.generate_mesh()

    ref = 1.0
    assert np.abs(compute_volume(mesh) - ref) < 1e-3 * ref

    surf = 1 - 0.1**2 * np.pi
    outer_mask = np.where(
        mesh.cell_data_dict["gmsh:geometrical"]["triangle"] == 1)[0]
    outer_cells = {}
    outer_cells["triangle"] = mesh.cells_dict["triangle"][outer_mask]

    inner_mask = np.where(
        mesh.cell_data_dict["gmsh:geometrical"]["triangle"] == 2)[0]
    inner_cells = {}
    inner_cells["triangle"] = mesh.cells_dict["triangle"][inner_mask]

    value = compute_volume(meshio.Mesh(mesh.points, outer_cells))
    assert np.abs(value - surf) < 1e-2 * surf
Ejemplo n.º 3
0
def test_fragments_diff_union():
    '''Test planar surface with holes.

    Construct it with boolean operations and verify that it is the same.
    '''
    # construct surface using boolean
    geo_object = pygmsh.opencascade.Geometry(0.04, 0.04)
    geo_object, square = square_loop(geo_object)
    geo_object, line_loop = circle_loop(geo_object)
    surf1 = geo_object.add_plane_surface(square)
    surf2 = geo_object.add_plane_surface(line_loop)

    geo_object.add_physical_surface([surf1], label=1)
    geo_object.add_physical_surface([surf2], label=2)
    surf_diff = geo_object.boolean_difference([surf1], [surf2], delete_other=False)
    geo_object.boolean_union([surf_diff, surf2])
    points, cells, _, cell_data, _ = pygmsh.generate_mesh(geo_object)
    assert np.abs((compute_volume(points, cells) - 1) / 1) < 1e-3
    surf = 1 - 0.1 ** 2 * np.pi
    outer_mask = np.where(cell_data['triangle']['gmsh:physical'] == 1)[0]
    outer_cells = {}
    outer_cells['triangle'] = cells['triangle'][outer_mask]

    inner_mask = np.where(cell_data['triangle']['gmsh:physical'] == 2)[0]
    inner_cells = {}
    inner_cells['triangle'] = cells['triangle'][inner_mask]
    assert np.abs((compute_volume(points, outer_cells) - surf) / surf) < 1e-2
    return
Ejemplo n.º 4
0
def test_square_circle_slice():
    """Test planar suface square with circular hole.

    Also test for surface area of fragments.
    """
    with pygmsh.occ.Geometry() as geom:
        square = square_loop(geom)
        curve_loop = circle_loop(geom)
        surf1 = geom.add_plane_surface(square)
        surf2 = geom.add_plane_surface(curve_loop)
        geom.boolean_fragments(surf1, surf2)
        # Gmsh 4 default format MSH4 doesn't have geometrical entities.
        mesh = geom.generate_mesh()

    ref = 1.0
    val = compute_volume(mesh)
    assert np.abs(val - ref) < 1e-3 * ref

    outer_mask = np.where(mesh.cell_data["gmsh:geometrical"][2] == 13)[0]
    outer_cells = {}
    outer_cells["triangle"] = mesh.cells_dict["triangle"][outer_mask]

    inner_mask = np.where(mesh.cell_data["gmsh:geometrical"][2] == 12)[0]
    inner_cells = {}
    inner_cells["triangle"] = mesh.cells_dict["triangle"][inner_mask]

    ref = 1 - 0.1**2 * np.pi
    value = compute_volume(meshio.Mesh(mesh.points, outer_cells))
    assert np.abs(value - ref) < 1e-2 * ref
Ejemplo n.º 5
0
def test_fragments_diff_union():
    """Test planar surface with holes.

    Construct it with boolean operations and verify that it is the same.
    """
    # construct surface using boolean
    geo_object = pygmsh.opencascade.Geometry(0.04, 0.04)
    geo_object, square = square_loop(geo_object)
    geo_object, line_loop = circle_loop(geo_object)
    surf1 = geo_object.add_plane_surface(square)
    surf2 = geo_object.add_plane_surface(line_loop)

    geo_object.add_physical([surf1], label=1)
    geo_object.add_physical([surf2], label=2)
    surf_diff = geo_object.boolean_difference([surf1], [surf2],
                                              delete_other=False)
    geo_object.boolean_union([surf_diff, surf2])
    mesh = pygmsh.generate_mesh(geo_object)
    assert np.abs((compute_volume(mesh) - 1) / 1) < 1e-3
    surf = 1 - 0.1**2 * np.pi
    outer_mask = np.where(
        mesh.cell_data_dict["gmsh:physical"]["triangle"] == 1)[0]
    outer_cells = {}
    outer_cells["triangle"] = mesh.cells_dict["triangle"][outer_mask]

    inner_mask = np.where(
        mesh.cell_data_dict["gmsh:physical"]["triangle"] == 2)[0]
    inner_cells = {}
    inner_cells["triangle"] = mesh.cells_dict["triangle"][inner_mask]

    value = compute_volume(meshio.Mesh(mesh.points, outer_cells))
    assert np.abs(value - surf) < 1e-2 * surf
Ejemplo n.º 6
0
def test_square_circle_slice():
    """Test planar suface square with circular hole.

    Also test for surface area of fragments.
    """
    geo_object = built_in_opencascade_geos_fragments()

    # Gmsh 4 default format MSH4 doesn't have geometrical entities.
    mesh = pygmsh.generate_mesh(geo_object,
                                extra_gmsh_arguments=["-format", "msh2"])
    ref = 1
    val = compute_volume(mesh)
    assert np.abs(val - ref) < 1e-3 * ref

    outer_mask = np.where(mesh.cell_data["gmsh:geometrical"][2] == 13)[0]
    outer_cells = {}
    outer_cells["triangle"] = mesh.cells_dict["triangle"][outer_mask]

    inner_mask = np.where(mesh.cell_data["gmsh:geometrical"][2] == 12)[0]
    inner_cells = {}
    inner_cells["triangle"] = mesh.cells_dict["triangle"][inner_mask]

    ref = 1 - 0.1**2 * np.pi
    value = compute_volume(meshio.Mesh(mesh.points, outer_cells))
    assert np.abs(value - ref) < 1e-2 * ref
    return
Ejemplo n.º 7
0
def test_fragments_diff_union():
    """Test planar surface with holes.

    Construct it with boolean operations and verify that it is the same.
    """
    # construct surface using boolean
    geo_object = pygmsh.opencascade.Geometry(0.04, 0.04)
    geo_object, square = square_loop(geo_object)
    geo_object, line_loop = circle_loop(geo_object)
    surf1 = geo_object.add_plane_surface(square)
    surf2 = geo_object.add_plane_surface(line_loop)

    geo_object.add_physical([surf1], label=1)
    geo_object.add_physical([surf2], label=2)
    surf_diff = geo_object.boolean_difference([surf1], [surf2], delete_other=False)
    geo_object.boolean_union([surf_diff, surf2])
    mesh = pygmsh.generate_mesh(geo_object)
    assert np.abs((compute_volume(mesh) - 1) / 1) < 1e-3
    surf = 1 - 0.1 ** 2 * np.pi
    outer_mask = np.where(mesh.cell_data["triangle"]["gmsh:physical"] == 1)[0]
    outer_cells = {}
    outer_cells["triangle"] = mesh.cells["triangle"][outer_mask]

    inner_mask = np.where(mesh.cell_data["triangle"]["gmsh:physical"] == 2)[0]
    inner_cells = {}
    inner_cells["triangle"] = mesh.cells["triangle"][inner_mask]

    value = compute_volume(meshio.Mesh(mesh.points, outer_cells))
    assert np.abs((value - surf)) < 1e-2 * surf
    return
Ejemplo n.º 8
0
def test(mesh_size=0.05):
    with pygmsh.geo.Geometry() as geom:
        # Draw a cross with a circular hole
        circ = geom.add_circle([0.0, 0.0], 0.1, mesh_size=mesh_size)
        poly = geom.add_polygon(
            [
                [+0.0, +0.5],
                [-0.1, +0.1],
                [-0.5, +0.0],
                [-0.1, -0.1],
                [+0.0, -0.5],
                [+0.1, -0.1],
                [+0.5, +0.0],
                [+0.1, +0.1],
            ],
            mesh_size=mesh_size,
            holes=[circ],
        )

        geom.twist(
            poly,
            translation_axis=[0.0, 0.0, 1.0],
            rotation_axis=[0.0, 0.0, 1.0],
            point_on_axis=[0.0, 0.0, 0.0],
            angle=2.0 / 6.0 * np.pi,
        )
        mesh = geom.generate_mesh()

    ref = 0.16951514066385628
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh
Ejemplo n.º 9
0
def test():
    geom = pygmsh.built_in.Geometry()
    geom.add_circle([0, 0, 0], 1, 0.1, make_surface=False)
    mesh = pygmsh.generate_mesh(geom)
    ref = 2 * np.pi
    assert np.abs(compute_volume(mesh) - ref) < 1e-2 * ref
    return
Ejemplo n.º 10
0
def test():
    geom = pygmsh.built_in.Geometry()

    X0 = np.array([[+0.0, +0.0, 0.0], [+0.5, +0.3, 0.1], [-0.5, +0.3, 0.1],
                   [+0.5, -0.3, 0.1]])

    R = np.array([0.1, 0.2, 0.1, 0.14])

    holes = [
        geom.add_ball(x0, r, with_volume=False, lcar=0.2 * r).surface_loop
        for x0, r in zip(X0, R)
    ]

    # geom.add_box(
    #         -1, 1,
    #         -1, 1,
    #         -1, 1,
    #         lcar=0.2,
    #         holes=holes
    #         )

    geom.add_ball([0, 0, 0], 1.0, lcar=0.2, holes=holes)

    # Fails on travis for some reason. TODO fix
    # geom.add_physical_volume(ball, label='cheese')

    ref = 4.07064892966291
    points, cells, _, _, _ = pygmsh.generate_mesh(geom)
    assert abs(compute_volume(points, cells) - ref) < 1.0e-2 * ref
    return points, cells
Ejemplo n.º 11
0
def test():
    '''Pipe with double-ring enclosure, rotated in space.
    '''
    geom = pygmsh.built_in.Geometry()

    sqrt2on2 = 0.5*np.sqrt(2.)
    R = pygmsh.rotation_matrix([sqrt2on2, sqrt2on2, 0], np.pi/6.0)
    geom.add_pipe(
            inner_radius=0.3,
            outer_radius=0.4,
            length=1.0,
            R=R,
            lcar=0.04
            )

    R = np.array([
        [0.0, 0.0, 1.0],
        [0.0, 1.0, 0.0],
        [1.0, 0.0, 0.0]
        ])
    geom.add_pipe(
            inner_radius=0.3,
            outer_radius=0.4,
            length=1.0,
            lcar=0.04,
            R=R,
            variant='circle_extrusion'
            )

    ref = 0.43988203517453256
    points, cells, _, _, _ = pygmsh.generate_mesh(geom)
    assert abs(compute_volume(points, cells) - ref) < 1.0e-2 * ref
    return points, cells
Ejemplo n.º 12
0
def test(lcar=0.05):
    geom = pygmsh.built_in.Geometry()

    # Draw a cross with a circular hole
    circ = geom.add_circle([0.0, 0.0, 0.0], 0.1, lcar=lcar)
    poly = geom.add_polygon(
        [
            [+0.0, +0.5, 0.0],
            [-0.1, +0.1, 0.0],
            [-0.5, +0.0, 0.0],
            [-0.1, -0.1, 0.0],
            [+0.0, -0.5, 0.0],
            [+0.1, -0.1, 0.0],
            [+0.5, +0.0, 0.0],
            [+0.1, +0.1, 0.0],
        ],
        lcar=lcar,
        holes=[circ],
    )

    axis = [0, 0, 1.0]

    geom.extrude(
        poly,
        translation_axis=axis,
        rotation_axis=axis,
        point_on_axis=[0, 0, 0],
        angle=2.0 / 6.0 * np.pi,
    )

    ref = 0.16951514066385628
    mesh = pygmsh.generate_mesh(geom)
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh
Ejemplo n.º 13
0
def test():
    X0 = np.array(
        [[+0.0, +0.0, 0.0], [+0.5, +0.3, 0.1], [-0.5, +0.3, 0.1], [+0.5, -0.3, 0.1]]
    )
    R = np.array([0.1, 0.2, 0.1, 0.14])

    with pygmsh.geo.Geometry() as geom:
        holes = [
            geom.add_ball(x0, r, with_volume=False, mesh_size=0.2 * r).surface_loop
            for x0, r in zip(X0, R)
        ]
        # geom.add_box(
        #         -1, 1,
        #         -1, 1,
        #         -1, 1,
        #         mesh_size=0.2,
        #         holes=holes
        #         )
        geom.add_ball([0, 0, 0], 1.0, mesh_size=0.2, holes=holes)
        # geom.add_physical_volume(ball, label="cheese")
        mesh = geom.generate_mesh(algorithm=5)

    ref = 4.07064892966291
    assert abs(compute_volume(mesh) - ref) < 2.0e-2 * ref
    return mesh
Ejemplo n.º 14
0
def test():
    with pygmsh.geo.Geometry() as geom:
        geom.add_ellipsoid([0.0, 0.0, 0.0], [1.0, 0.5, 0.75], 0.05)
        mesh = geom.generate_mesh()
    ref = 1.5676038497587947
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh
Ejemplo n.º 15
0
def test(lcar=1.0):
    lbw = [2, 3, 5]
    geom = pygmsh.built_in.Geometry()
    points = [geom.add_point([x, 0.0, 0.0], lcar) for x in [0.0, lbw[0]]]
    line = geom.add_line(*points)

    _, rectangle, _ = geom.extrude(line,
                                   translation_axis=[0.0, lbw[1], 0.0],
                                   num_layers=lbw[1],
                                   recombine=True)
    geom.extrude(
        rectangle,
        translation_axis=[0.0, 0.0, lbw[2]],
        num_layers=lbw[2],
        recombine=True,
    )

    # compute_volume only supports 3D for tetras, but does return
    # surface area for quads

    ref = sum(l * w for l, w in permutations(lbw, 2))  # surface area
    points, cells, _, _, _ = pygmsh.generate_mesh(geom, prune_vertices=False)
    # TODO compute hex volumes
    assert abs(compute_volume(points, {"quad": cells["quad"]}) -
               ref) < 1.0e-2 * ref
    return points, cells
Ejemplo n.º 16
0
def test(lcar=0.05):
    geom = pygmsh.built_in.Geometry()

    # Draw a square
    poly = geom.add_polygon(
        [[+0.5, +0.0, 0.0], [+0.0, +0.5, 0.0], [-0.5, +0.0, 0.0], [+0.0, -0.5, 0.0]],
        lcar=lcar,
    )

    axis = [0, 0, 1.0]

    geom.extrude(
        poly,
        translation_axis=axis,
        rotation_axis=axis,
        point_on_axis=[0.0, 0.0, 0.0],
        angle=0.5 * pi,
        num_layers=5,
        recombine=True,
    )

    ref = 3.98156496566
    mesh = pygmsh.generate_mesh(geom)
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh
Ejemplo n.º 17
0
def test():
    '''Torus, rotated in space.
    '''
    geom = pygmsh.built_in.Geometry()

    R = np.array([
        [1.0, 0.0, 0.0],
        [0.0, 0.0, 1.0],
        [0.0, 1.0, 0.0]
        ])
    geom.add_torus(
        irad=0.05, orad=0.6, lcar=0.03,
        x0=[0.0, 0.0, -1.0],
        R=R
        )

    R = np.array([
        [0.0, 0.0, 1.0],
        [0.0, 1.0, 0.0],
        [1.0, 0.0, 0.0]
        ])
    geom.add_torus(
        irad=0.05, orad=0.6, lcar=0.03,
        x0=[0.0, 0.0, 1.0],
        variant='extrude_circle'
        )

    ref = 0.06604540601899624
    points, cells, _, _, _ = pygmsh.generate_mesh(geom)
    assert abs(compute_volume(points, cells) - ref) < 1.0e-2 * ref
    return points, cells
Ejemplo n.º 18
0
def test():
    with pygmsh.geo.Geometry() as geom:
        lcar = 0.1
        p1 = geom.add_point([0.0, 0.0, 0.0], lcar)
        p2 = geom.add_point([1.0, 0.0, 0.0], lcar)
        p3 = geom.add_point([1.0, 0.5, 0.0], lcar)
        p4 = geom.add_point([1.0, 1.0, 0.0], lcar)
        s1 = geom.add_bspline([p1, p2, p3, p4])

        p2 = geom.add_point([0.0, 1.0, 0.0], lcar)
        p3 = geom.add_point([0.5, 1.0, 0.0], lcar)
        s2 = geom.add_bspline([p4, p3, p2, p1])

        ll = geom.add_curve_loop([s1, s2])
        pl = geom.add_plane_surface(ll)

        # test some __repr__
        print(p1)
        print(ll)
        print(s1)
        print(pl)

        mesh = geom.generate_mesh(verbose=True)
    # ref = 0.9156598733673261
    ref = 0.7474554072002251
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh
Ejemplo n.º 19
0
def test(lcar=0.05):
    geom = pygmsh.built_in.Geometry()

    # Draw a cross with a circular hole
    circ = geom.add_circle([0.0, 0.0, 0.0], 0.1, lcar=lcar)
    poly = geom.add_polygon(
        [
            [+0.0, +0.5, 0.0],
            [-0.1, +0.1, 0.0],
            [-0.5, +0.0, 0.0],
            [-0.1, -0.1, 0.0],
            [+0.0, -0.5, 0.0],
            [+0.1, -0.1, 0.0],
            [+0.5, +0.0, 0.0],
            [+0.1, +0.1, 0.0],
        ],
        lcar=lcar,
        holes=[circ],
    )

    axis = [0, 0, 1.0]

    geom.extrude(
        poly,
        translation_axis=axis,
        rotation_axis=axis,
        point_on_axis=[0, 0, 0],
        angle=2.0 / 6.0 * np.pi,
    )

    ref = 0.16951514066385628
    points, cells, _, _, _ = pygmsh.generate_mesh(geom)
    assert abs(compute_volume(points, cells) - ref) < 1.0e-2 * ref
    return points, cells
Ejemplo n.º 20
0
def test():
    # Characteristic length
    lcar = 1e-1

    # Coordinates of lower-left and upper-right vertices of a square domain
    xmin = 0.0
    xmax = 5.0
    ymin = 0.0
    ymax = 5.0

    # Vertices of a square hole
    squareHoleCoordinates = np.array([[1, 1, 0], [4, 1, 0], [4, 4, 0],
                                      [1, 4, 0]])

    # Create geometric object
    geom = pygmsh.built_in.Geometry()

    # Create square hole
    squareHole = geom.add_polygon(squareHoleCoordinates,
                                  lcar,
                                  make_surface=False)

    # Create square domain with square hole
    geom.add_rectangle(xmin,
                       xmax,
                       ymin,
                       ymax,
                       0.0,
                       lcar,
                       holes=[squareHole.line_loop])

    ref = 16.0
    points, cells, _, _, _ = pygmsh.generate_mesh(geom)
    assert abs(compute_volume(points, cells) - ref) < 1.0e-2 * ref
    return points, cells
Ejemplo n.º 21
0
def test(lcar=1.0):
    with pygmsh.geo.Geometry() as geom:
        lbw = [2, 3, 5]
        points = [geom.add_point([x, 0.0, 0.0], lcar) for x in [0.0, lbw[0]]]
        line = geom.add_line(*points)

        _, rectangle, _ = geom.extrude(line,
                                       translation_axis=[0.0, lbw[1], 0.0],
                                       num_layers=lbw[1],
                                       recombine=True)
        geom.extrude(
            rectangle,
            translation_axis=[0.0, 0.0, lbw[2]],
            num_layers=lbw[2],
            recombine=True,
        )
        # compute_volume only supports 3D for tetras, but does return surface area for
        # quads
        mesh = geom.generate_mesh()
        # mesh.remove_lower_dimensional_cells()
        # mesh.remove_orphaned_nodes()

    ref = sum(l * w for l, w in permutations(lbw, 2))  # surface area
    # TODO compute hex volumes
    quad_mesh = meshio.Mesh(mesh.points, {"quad": mesh.cells_dict["quad"]})
    assert abs(compute_volume(quad_mesh) - ref) < 1.0e-2 * ref
    return mesh
Ejemplo n.º 22
0
def test():
    geom = pygmsh.built_in.Geometry()

    lcar = 0.1

    circle = geom.add_circle([0.5, 0.5, 0.0], 1.0, lcar)

    triangle = geom.add_polygon([
            [2.0, -0.5, 0.0],
            [4.0, -0.5, 0.0],
            [4.0, 1.5, 0.0],
            ], lcar
            )
    rectangle = geom.add_rectangle(4.75, 6.25, -0.24, 1.25, 0.0, lcar)

    # hold all domain
    geom.add_polygon([
        [-1.0, -1.0, 0.0],
        [+7.0, -1.0, 0.0],
        [+7.0, +2.0, 0.0],
        [-1.0, +2.0, 0.0],
        ], lcar,
        holes=[circle.line_loop, triangle.line_loop, rectangle.line_loop]
        )

    ref = 24.0
    points, cells, _, _, _ = pygmsh.generate_mesh(geom)
    assert abs(compute_volume(points, cells) - ref) < 1.0e-2 * ref
    return points, cells
Ejemplo n.º 23
0
def test():
    geom = pygmsh.opencascade.Geometry(
        characteristic_length_min=2.0, characteristic_length_max=2.0
    )

    rect1 = geom.add_rectangle([10.0, 0.0, 0.0], 20.0, 40.0, corner_radius=5.0)
    rect2 = geom.add_rectangle([0.0, 10.0, 0.0], 40.0, 20.0, corner_radius=5.0)
    disk1 = geom.add_disk([14.5, 35.0, 0.0], 1.85)
    disk2 = geom.add_disk([25.5, 5.0, 0.0], 1.85)

    rect3 = geom.add_rectangle([10.0, 30.0, 0.0], 10.0, 1.0)
    rect4 = geom.add_rectangle([20.0, 9.0, 0.0], 10.0, 1.0)

    r1 = geom.add_rectangle([9.0, 0.0, 0.0], 21.0, 20.5, corner_radius=8.0)
    r2 = geom.add_rectangle([10.0, 00.0, 0.0], 20.0, 19.5, corner_radius=7.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
Ejemplo n.º 24
0
def test(lcar=0.3):
    with pygmsh.geo.Geometry() as geom:
        r = 1.25 * 3.4
        p1 = geom.add_point([0.0, 0.0, 0.0], lcar)
        # p2 = geom.add_point([+r, 0.0, 0.0], lcar)
        p3 = geom.add_point([-r, 0.0, 0.0], lcar)
        p4 = geom.add_point([0.0, +r, 0.0], lcar)
        p5 = geom.add_point([0.0, -r, 0.0], lcar)
        p6 = geom.add_point([r * cos(+pi / 12.0), r * sin(+pi / 12.0), 0.0],
                            lcar)
        p7 = geom.add_point([r * cos(-pi / 12.0), r * sin(-pi / 12.0), 0.0],
                            lcar)
        p8 = geom.add_point([0.5 * r, 0.0, 0.0], lcar)

        c0 = geom.add_circle_arc(p6, p1, p4)
        c1 = geom.add_circle_arc(p4, p1, p3)
        c2 = geom.add_circle_arc(p3, p1, p5)
        c3 = geom.add_circle_arc(p5, p1, p7)
        l1 = geom.add_line(p7, p8)
        l2 = geom.add_line(p8, p6)
        ll = geom.add_curve_loop([c0, c1, c2, c3, l1, l2])

        pacman = geom.add_plane_surface(ll)

        # test setting physical groups
        geom.add_physical(p1, label="c")
        geom.add_physical(c0, label="arc")
        geom.add_physical(pacman, "dummy")
        geom.add_physical(pacman, label="77")

        mesh = geom.generate_mesh()

    ref = 54.312974717523744
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh
Ejemplo n.º 25
0
def test():
    geom = pygmsh.opencascade.Geometry(
        characteristic_length_min=2.0, characteristic_length_max=2.0
    )

    rect1 = geom.add_rectangle([10.0, 0.0, 0.0], 20.0, 40.0, corner_radius=5.0)
    rect2 = geom.add_rectangle([0.0, 10.0, 0.0], 40.0, 20.0, corner_radius=5.0)
    disk1 = geom.add_disk([14.5, 35.0, 0.0], 1.85)
    disk2 = geom.add_disk([25.5, 5.0, 0.0], 1.85)

    rect3 = geom.add_rectangle([10.0, 30.0, 0.0], 10.0, 1.0)
    rect4 = geom.add_rectangle([20.0, 9.0, 0.0], 10.0, 1.0)

    r1 = geom.add_rectangle([9.0, 0.0, 0.0], 21.0, 20.5, corner_radius=8.0)
    r2 = geom.add_rectangle([10.0, 00.0, 0.0], 20.0, 19.5, corner_radius=7.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
Ejemplo n.º 26
0
def test():
    with pygmsh.geo.Geometry() as geom:
        poly = geom.add_polygon(
            [
                [0.0, 0.0, 0.0],
                [2.0, 0.0, 0.0],
                [3.0, 1.0, 0.0],
                [1.0, 2.0, 0.0],
                [0.0, 1.0, 0.0],
            ],
            mesh_size=0.1,
        )

        field0 = geom.add_boundary_layer(
            edges_list=[poly.curve_loop.curves[0]],
            lcmin=0.01,
            lcmax=0.1,
            distmin=0.0,
            distmax=0.2,
        )
        field1 = geom.add_boundary_layer(
            nodes_list=[poly.curve_loop.curves[1].points[1]],
            lcmin=0.01,
            lcmax=0.1,
            distmin=0.0,
            distmax=0.2,
        )
        geom.set_background_mesh([field0, field1], operator="Min")

        ref = 4.0
        mesh = geom.generate_mesh()
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh
Ejemplo n.º 27
0
def test(lcar=0.05):
    geom = pygmsh.built_in.Geometry()

    # Draw a cross with a circular hole
    circ = geom.add_circle(
        [0.0, 0.0, 0.0], 0.1,
        lcar=lcar,
        make_surface=False
        )
    poly = geom.add_polygon([
        [+0.0, +0.5, 0.0],
        [-0.1, +0.1, 0.0],
        [-0.5, +0.0, 0.0],
        [-0.1, -0.1, 0.0],
        [+0.0, -0.5, 0.0],
        [+0.1, -0.1, 0.0],
        [+0.5, +0.0, 0.0],
        [+0.1, +0.1, 0.0]
        ],
        lcar=lcar,
        holes=[circ]
        )

    axis = [0, 0, 1.0]

    geom.extrude(
        poly,
        translation_axis=axis,
        num_layers=1
        )

    ref = 0.16951514066385628
    points, cells, _, _, _ = pygmsh.generate_mesh(geom)
    assert abs(compute_volume(points, cells) - ref) < 1.0e-2 * ref
    return points, cells
Ejemplo n.º 28
0
def test(lcar=0.05):
    geom = pygmsh.built_in.Geometry()

    # Draw a cross with a circular hole
    circ = geom.add_circle([0.0, 0.0, 0.0], 0.1, lcar=lcar, make_surface=False)
    poly = geom.add_polygon(
        [
            [+0.0, +0.5, 0.0],
            [-0.1, +0.1, 0.0],
            [-0.5, +0.0, 0.0],
            [-0.1, -0.1, 0.0],
            [+0.0, -0.5, 0.0],
            [+0.1, -0.1, 0.0],
            [+0.5, +0.0, 0.0],
            [+0.1, +0.1, 0.0],
        ],
        lcar=lcar,
        holes=[circ],
    )

    axis = [0, 0, 1.0]

    geom.extrude(poly, translation_axis=axis, num_layers=1)

    ref = 0.16951514066385628
    mesh = pygmsh.generate_mesh(geom)
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh
Ejemplo n.º 29
0
def test():
    geom = pygmsh.built_in.Geometry()

    # Generate an approximation of a circle
    t = numpy.arange(0, 2.0 * numpy.pi, 0.05)
    x = numpy.vstack((numpy.cos(t), numpy.sin(t), numpy.zeros_like(t))).T
    points = [geom.add_point(p) for p in x]

    # Shuffle the orientation of lines by point order
    o = [0 if k % 3 == 0 else 1 for k in range(len(points))]

    lines = [
        geom.add_line(points[k + o[k]], points[k + (o[k] + 1) % 2])
        for k in range(len(points) - 1)
    ]
    lines.append(geom.add_line(points[-1], points[0]))

    # Shuffle the order of lines
    random.seed(1)
    random.shuffle(lines)

    oriented_lines = pygmsh.orient_lines(lines)
    ll = geom.add_line_loop(oriented_lines)
    geom.add_plane_surface(ll)

    mesh = pygmsh.generate_mesh(geom, prune_z_0=True)

    ref = numpy.pi
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh
def test():
    with pygmsh.geo.Geometry() as geom:
        # Generate an approximation of a circle
        t = np.arange(0, 2.0 * np.pi, 0.05)
        x = np.column_stack([np.cos(t), np.sin(t), np.zeros_like(t)])
        points = [geom.add_point(p) for p in x]

        # Shuffle the orientation of lines by point order
        o = [0 if k % 3 == 0 else 1 for k in range(len(points))]

        lines = [
            geom.add_line(points[k + o[k]], points[k + (o[k] + 1) % 2])
            for k in range(len(points) - 1)
        ]
        lines.append(geom.add_line(points[-1], points[0]))

        # Shuffle the order of lines
        random.seed(1)
        random.shuffle(lines)

        oriented_lines = pygmsh.orient_lines(lines)
        ll = geom.add_curve_loop(oriented_lines)
        geom.add_plane_surface(ll)

        mesh = geom.generate_mesh()

    ref = np.pi
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh
Ejemplo n.º 31
0
def test_occ():
    with pygmsh.occ.Geometry() as geom:
        geom.add_rectangle([0.0, 0.5, 0.0], 5.0, 0.5)

        edge1 = pygmsh.occ.dummy.Dummy(dim=1, id0=1)
        point1 = pygmsh.occ.dummy.Dummy(dim=0, id0=3)

        field0 = geom.add_boundary_layer(
            edges_list=[edge1],
            lcmin=0.01,
            lcmax=0.1,
            distmin=0.0,
            distmax=0.2,
            num_points_per_curve=50,
        )
        field1 = geom.add_boundary_layer(
            nodes_list=[point1],
            lcmin=0.01,
            lcmax=0.1,
            distmin=0.0,
            distmax=0.2,
            num_points_per_curve=50,
        )
        geom.set_background_mesh([field0, field1], operator="Min")

        ref = 2.5
        mesh = geom.generate_mesh()
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh
Ejemplo n.º 32
0
def test(lcar=1.0):
    lbw = [2, 3, 5]
    geom = pygmsh.built_in.Geometry()
    points = [geom.add_point([x, 0.0, 0.0], lcar) for x in [0.0, lbw[0]]]
    line = geom.add_line(*points)

    _, rectangle, _ = geom.extrude(
        line, translation_axis=[0.0, lbw[1], 0.0], num_layers=lbw[1], recombine=True
    )
    geom.extrude(
        rectangle,
        translation_axis=[0.0, 0.0, lbw[2]],
        num_layers=lbw[2],
        recombine=True,
    )

    # compute_volume only supports 3D for tetras, but does return
    # surface area for quads

    ref = sum(l * w for l, w in permutations(lbw, 2))  # surface area
    mesh = pygmsh.generate_mesh(geom, prune_vertices=False)
    # TODO compute hex volumes
    assert (
        abs(
            compute_volume(meshio.Mesh(mesh.points, {"quad": mesh.cells["quad"]})) - ref
        )
        < 1.0e-2 * ref
    )
    return mesh
Ejemplo n.º 33
0
def test():
    with pygmsh.geo.Geometry() as geom:
        lcar = 0.1
        circle = geom.add_circle([0.5, 0.5, 0.0], 1.0, lcar)
        triangle = geom.add_polygon(
            [[2.0, -0.5, 0.0], [4.0, -0.5, 0.0], [4.0, 1.5, 0.0]], lcar)
        rectangle = geom.add_rectangle(4.75, 6.25, -0.24, 1.25, 0.0, lcar)
        # hold all domain
        geom.add_polygon(
            [
                [-1.0, -1.0, 0.0],
                [+7.0, -1.0, 0.0],
                [+7.0, +2.0, 0.0],
                [-1.0, +2.0, 0.0],
            ],
            lcar,
            holes=[
                circle.curve_loop, triangle.curve_loop, rectangle.curve_loop
            ],
        )
        mesh = geom.generate_mesh()

    ref = 24.0
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh
Ejemplo n.º 34
0
def test():
    geom = pygmsh.built_in.Geometry()

    poly = geom.add_polygon([
        [0.0, 0.0, 0.0],
        [2.0, 0.0, 0.0],
        [3.0, 1.0, 0.0],
        [1.0, 2.0, 0.0],
        [0.0, 1.0, 0.0],
    ],
                            lcar=0.1)

    field0 = geom.add_boundary_layer(edges_list=[poly.line_loop.lines[0]],
                                     hfar=0.1,
                                     hwall_n=0.01,
                                     ratio=1.1,
                                     thickness=0.2,
                                     anisomax=100.0)

    field1 = geom.add_boundary_layer(
        nodes_list=[poly.line_loop.lines[1].points[1]],
        hfar=0.1,
        hwall_n=0.01,
        ratio=1.1,
        thickness=0.2,
        anisomax=100.0)

    geom.add_background_field([field0, field1])

    ref = 4.0
    points, cells, _, _, _ = pygmsh.generate_mesh(geom)
    assert abs(compute_volume(points, cells) - ref) < 1.0e-2 * ref
    return points, cells
Ejemplo n.º 35
0
def test():
    """Pipe with double-ring enclosure, rotated in space."""
    with pygmsh.geo.Geometry() as geom:
        sqrt2on2 = 0.5 * np.sqrt(2.0)
        R = pygmsh.rotation_matrix([sqrt2on2, sqrt2on2, 0], np.pi / 6.0)
        geom.add_pipe(inner_radius=0.3,
                      outer_radius=0.4,
                      length=1.0,
                      R=R,
                      mesh_size=0.04)

        R = np.array([[0.0, 0.0, 1.0], [0.0, 1.0, 0.0], [1.0, 0.0, 0.0]])
        geom.add_pipe(
            inner_radius=0.3,
            outer_radius=0.4,
            length=1.0,
            mesh_size=0.04,
            R=R,
            variant="circle_extrusion",
        )
        mesh = geom.generate_mesh()

    ref = 0.43988203517453256
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh
Ejemplo n.º 36
0
def test():
    geom = pygmsh.built_in.Geometry()

    X0 = np.array(
        [[+0.0, +0.0, 0.0], [+0.5, +0.3, 0.1], [-0.5, +0.3, 0.1], [+0.5, -0.3, 0.1]]
    )

    R = np.array([0.1, 0.2, 0.1, 0.14])

    holes = [
        geom.add_ball(x0, r, with_volume=False, lcar=0.2 * r).surface_loop
        for x0, r in zip(X0, R)
    ]

    # geom.add_box(
    #         -1, 1,
    #         -1, 1,
    #         -1, 1,
    #         lcar=0.2,
    #         holes=holes
    #         )

    geom.add_ball([0, 0, 0], 1.0, lcar=0.2, holes=holes)

    # geom.add_physical_volume(ball, label="cheese")

    ref = 4.07064892966291
    mesh = pygmsh.generate_mesh(geom)
    assert abs(compute_volume(mesh) - ref) < 2.0e-2 * ref
    return mesh
Ejemplo n.º 37
0
def test():
    geom = pygmsh.built_in.Geometry()

    X0 = np.array([[+0.0, +0.0, 0.0], [+0.5, +0.3, 0.1], [-0.5, +0.3, 0.1],
                   [+0.5, -0.3, 0.1]])

    R = np.array([0.1, 0.2, 0.1, 0.14])

    holes = [
        geom.add_ball(x0, r, with_volume=False, lcar=0.2 * r).surface_loop
        for x0, r in zip(X0, R)
    ]

    # geom.add_box(
    #         -1, 1,
    #         -1, 1,
    #         -1, 1,
    #         lcar=0.2,
    #         holes=holes
    #         )

    geom.add_ball([0, 0, 0], 1.0, lcar=0.2, holes=holes)

    # geom.add_physical_volume(ball, label="cheese")

    ref = 4.07064892966291
    mesh = pygmsh.generate_mesh(geom)
    assert abs(compute_volume(mesh) - ref) < 2.0e-2 * ref
    return mesh
Ejemplo n.º 38
0
def test():
    geom = pygmsh.built_in.Geometry()
    geom.add_circle([0, 0, 0], 1, 0.1, make_surface=False)
    mesh = pygmsh.generate_mesh(geom)
    ref = 2 * np.pi
    assert np.abs(compute_volume(mesh) - ref) < 1e-2 * ref
    return
Ejemplo n.º 39
0
def test(lcar=0.05):
    geom = pygmsh.built_in.Geometry()

    # Draw a square
    poly = geom.add_polygon(
        [
            [+0.5, +0.0, 0.0],
            [+0.0, +0.5, 0.0],
            [-0.5, +0.0, 0.0],
            [+0.0, -0.5, 0.0],
        ],
        lcar=lcar,
    )

    axis = [0, 0, 1.0]

    geom.extrude(poly,
                 translation_axis=axis,
                 rotation_axis=axis,
                 point_on_axis=[0.0, 0.0, 0.0],
                 angle=0.5 * pi,
                 num_layers=5,
                 recombine=True)

    ref = 3.98156496566
    points, cells, _, _, _ = pygmsh.generate_mesh(geom)
    assert abs(compute_volume(points, cells) - ref) < 1.0e-2 * ref
    return points, cells
Ejemplo n.º 40
0
def test():
    geom = pygmsh.built_in.Geometry()
    geom.add_ellipsoid([0.0, 0.0, 0.0], [1.0, 0.5, 0.75], 0.05)

    ref = 1.5676038497587947
    mesh = pygmsh.generate_mesh(geom)
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh
Ejemplo n.º 41
0
def test():
    geom = pygmsh.opencascade.Geometry()

    geom.add_wedge([0.0, 0.0, 0.0], [1.0, 1.0, 1.0], top_extent=0.4, char_length=0.1)

    ref = 0.7
    mesh = pygmsh.generate_mesh(geom)
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh
Ejemplo n.º 42
0
def test():
    geom = pygmsh.opencascade.Geometry()

    geom.add_cylinder([0.0, 0.0, 0.0], [0.0, 0.0, 1.0], 0.5, 0.25 * pi, char_length=0.1)

    ref = 0.097625512963
    mesh = pygmsh.generate_mesh(geom)
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh
Ejemplo n.º 43
0
def test():
    geom = pygmsh.built_in.Geometry()

    geom.add_rectangle(0.0, 1.0, 0.0, 1.0, 0.0, 0.1)

    ref = 1.0
    mesh = pygmsh.generate_mesh(geom, mesh_file_type="vtk")
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh
Ejemplo n.º 44
0
def test():
    geom = pygmsh.opencascade.Geometry()

    geom.add_box([0.0, 0.0, 0.0], [1, 2, 3], char_length=0.1)

    ref = 6
    mesh = pygmsh.generate_mesh(geom)
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh
Ejemplo n.º 45
0
def test():
    geom = pygmsh.opencascade.Geometry()

    geom.add_torus([0.0, 0.0, 0.0], 1.0, 0.3, 1.25 * pi, char_length=0.1)

    ref = 1.09994740709
    mesh = pygmsh.generate_mesh(geom)
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh
Ejemplo n.º 46
0
def test_square_circle_hole():
    """Test planar surface with holes.

    Construct it with boolean operations and verify that it is the same.
    """
    for geo_object in built_in_opencascade_geos():
        mesh = pygmsh.generate_mesh(geo_object)
        surf = 1 - 0.1 ** 2 * np.pi
        assert np.abs((compute_volume(mesh) - surf) / surf) < 1e-3
    return
Ejemplo n.º 47
0
def test():
    geom = pygmsh.built_in.Geometry()

    rectangle = geom.add_rectangle(0.0, 1.0, 0.0, 1.0, 0.0, 0.1)

    geom.add_raw_code("Recombine Surface {%s};" % rectangle.surface.id)

    ref = 1.0
    mesh = pygmsh.generate_mesh(geom, dim=2)
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh
Ejemplo n.º 48
0
def test():
    geom = pygmsh.opencascade.Geometry()

    geom.add_cone(
        [0.0, 0.0, 0.0], [0.0, 0.0, 1.0], 1.0, 0.3, 1.25 * pi, char_length=0.1
    )

    ref = 0.90779252263
    mesh = pygmsh.generate_mesh(geom)
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh
Ejemplo n.º 49
0
def test():
    geom = pygmsh.opencascade.Geometry()

    geom.add_ball(
        [0.0, 0.0, 0.0], 1.0, x0=-0.9, x1=+0.9, alpha=0.5 * pi, char_length=0.1
    )

    ref = 0.976088698545
    mesh = pygmsh.generate_mesh(geom)
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh
Ejemplo n.º 50
0
def test_translation2d():
    """Translation of a surface object."""
    geom = pygmsh.opencascade.Geometry(0.05, 0.05)
    disk = geom.add_disk([0, 0, 0], 1)
    disk2 = geom.add_disk([1.5, 0, 0], 1)
    geom.translate(disk, [1.5, 0, 0])
    geom.boolean_union([disk2, disk])

    mesh = pygmsh.generate_mesh(geom)
    surf = np.pi
    assert np.abs(compute_volume(mesh) - surf) < 1e-3 * surf
    return
Ejemplo n.º 51
0
def test(irad=0.05, orad=0.6):
    """Torus, rotated in space.
    """
    geom = pygmsh.built_in.Geometry()

    R = pygmsh.rotation_matrix([1.0, 0.0, 0.0], np.pi / 2)
    geom.add_torus(irad=irad, orad=orad, lcar=0.03, x0=[0.0, 0.0, -1.0], R=R)

    ref = 2 * np.pi ** 2 * orad * irad ** 2
    mesh = pygmsh.generate_mesh(geom)
    assert np.isclose(compute_volume(mesh), ref, rtol=5e-2)
    return mesh
Ejemplo n.º 52
0
def test():
    geom = pygmsh.built_in.Geometry()

    poly = geom.add_polygon(
        [[0.0, 0.5, 0.0], [1.0, 0.5, 0.0], [1.0, 1.0, 0.0], [0.0, 1.0, 0.0]], lcar=0.05
    )

    geom.symmetry(poly, [0.0, 1.0, 0.0, -0.5])

    mesh = pygmsh.generate_mesh(geom)
    ref = 1.0
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh
Ejemplo n.º 53
0
def test():
    geom = pygmsh.built_in.Geometry()

    circle = geom.add_circle(
        x0=[0.5, 0.5, 0.0], radius=0.25, lcar=0.1, num_sections=4, make_surface=False
    )

    geom.add_rectangle(0.0, 1.0, 0.0, 1.0, 0.0, lcar=0.1, holes=[circle.line_loop])

    ref = 0.8086582838174551
    mesh = pygmsh.generate_mesh(geom, geo_filename="h.geo")
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh
Ejemplo n.º 54
0
def test(radius=1.0):
    geom = pygmsh.built_in.Geometry()

    R = [
        pygmsh.rotation_matrix(np.eye(1, 3, d)[0], theta)
        for d, theta in enumerate(np.pi / np.array([2.0, 3.0, 5]))
    ]

    geom.add_circle([7.0, 11.0, 13.0], radius, 0.1, R[0] @ R[1] @ R[2])

    ref = np.pi * radius ** 2
    mesh = pygmsh.generate_mesh(geom)
    assert np.isclose(compute_volume(mesh), ref, rtol=1e-2)
    return mesh
Ejemplo n.º 55
0
def test():
    geom = pygmsh.built_in.Geometry()

    # internal radius of torus
    irad = 0.15
    # external radius of torus
    orad = 0.27

    Z_pos = (irad + orad) * np.concatenate(
        [+np.ones(8), -np.ones(8), +np.ones(8), -np.ones(8)]
    )

    Alpha = np.concatenate(
        [
            np.arange(8) * np.pi / 4.0,
            np.arange(8) * np.pi / 4.0 + np.pi / 16.0,
            np.arange(8) * np.pi / 4.0,
            np.arange(8) * np.pi / 4.0 + np.pi / 16.0,
        ]
    )

    A1 = (
        (irad + orad)
        / np.tan(np.pi / 8.0)
        * np.concatenate(
            [1.6 * np.ones(8), 1.6 * np.ones(8), 1.9 * np.ones(8), 1.9 * np.ones(8)]
        )
    )

    for alpha, a1, z in zip(Alpha, A1, Z_pos):
        # Rotate torus to the y-z-plane.
        R1 = pygmsh.rotation_matrix([0.0, 1.0, 0.0], 0.5 * np.pi)
        R2 = pygmsh.rotation_matrix([0.0, 0.0, 1.0], alpha)
        x0 = np.array([a1, 0.0, 0.0])
        x1 = np.array([0.0, 0.0, z])
        # First rotate to y-z-plane, then move out to a1, rotate by angle
        # alpha, move up by z.
        #
        #    xnew = R2*(R1*x+x0) + x1
        #
        geom.add_torus(
            irad=irad, orad=orad, lcar=0.1, R=np.dot(R2, R1), x0=np.dot(R2, x0) + x1
        )

    geom.add_box(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0, lcar=0.3)

    ref = len(A1) * 2 * np.pi ** 2 * orad * irad ** 2 + 2.0 ** 3
    mesh = pygmsh.generate_mesh(geom)
    assert np.isclose(compute_volume(mesh), ref, rtol=2e-2)
    return mesh
Ejemplo n.º 56
0
def test_union():
    geom = pygmsh.opencascade.Geometry(
        characteristic_length_min=0.1, characteristic_length_max=0.1
    )

    rectangle = geom.add_rectangle([-1.0, -1.0, 0.0], 2.0, 2.0)
    disk_w = geom.add_disk([-1.0, 0.0, 0.0], 0.5)
    disk_e = geom.add_disk([+1.0, 0.0, 0.0], 0.5)
    geom.boolean_union([rectangle, disk_w, disk_e])

    ref = 4.780361
    mesh = pygmsh.generate_mesh(geom)
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh
Ejemplo n.º 57
0
def test_translation3d():
    """Translation of a volume object."""
    geom = pygmsh.opencascade.Geometry(0.2, 0.2)
    ball = geom.add_ball([0, 0, 0], 1)
    ball2 = geom.add_ball([1.5, 0, 0], 1)
    geom.translate(ball, [1.5, 0, 0])
    geom.boolean_union([ball2, ball])

    mesh = pygmsh.generate_mesh(geom)
    surf = 4 / 3 * np.pi
    assert isinstance(ball, pygmsh.opencascade.volume_base.VolumeBase)
    assert isinstance(ball, pygmsh.built_in.volume_base.VolumeBase)

    assert np.abs(compute_volume(mesh) - surf) < 2e-2 * surf
    return
Ejemplo n.º 58
0
def test():
    geom = pygmsh.opencascade.Geometry(
        characteristic_length_min=1.0, characteristic_length_max=1.0
    )

    lcar = 1
    h = 25
    w = 10
    length = 100
    # x_fin = -0.5 * length
    cr = 1

    f = 0.5 * w
    y = [-f, -f + cr, +f - cr, +f]
    z = [0.0, h - cr, h]
    f = 0.5 * cr
    x = [-f, f]
    points = []
    points.append(geom.add_point((x[0], y[0], z[0]), lcar=lcar))
    points.append(geom.add_point((x[0], y[0], z[1]), lcar=lcar))
    points.append(geom.add_point((x[0], y[1], z[1]), lcar=lcar))
    points.append(geom.add_point((x[0], y[1], z[2]), lcar=lcar))
    points.append(geom.add_point((x[0], y[2], z[2]), lcar=lcar))
    points.append(geom.add_point((x[0], y[2], z[1]), lcar=lcar))
    points.append(geom.add_point((x[0], y[3], z[1]), lcar=lcar))
    points.append(geom.add_point((x[0], y[3], z[0]), lcar=lcar))

    lines = []
    lines.append(geom.add_line(points[0], points[1]))
    lines.append(geom.add_circle_arc(points[1], points[2], points[3]))

    lines.append(geom.add_line(points[3], points[4]))
    lines.append(geom.add_circle_arc(points[4], points[5], points[6]))
    lines.append(geom.add_line(points[6], points[7]))
    lines.append(geom.add_line(points[7], points[0]))

    line_loop = geom.add_line_loop(lines)
    surface = geom.add_plane_surface(line_loop)
    geom.extrude(surface, translation_axis=[length, 0, 0])

    mesh = pygmsh.generate_mesh(geom)

    ref = 24941.503891355664
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh
Ejemplo n.º 59
0
def test_all():
    geom = pygmsh.opencascade.Geometry(
        characteristic_length_min=0.1, characteristic_length_max=0.1
    )

    rectangle = geom.add_rectangle([-1.0, -1.0, 0.0], 2.0, 2.0)
    disk1 = geom.add_disk([-1.0, 0.0, 0.0], 0.5)
    disk2 = geom.add_disk([+1.0, 0.0, 0.0], 0.5)
    union = geom.boolean_union([rectangle, disk1, disk2])

    disk3 = geom.add_disk([0.0, -1.0, 0.0], 0.5)
    disk4 = geom.add_disk([0.0, +1.0, 0.0], 0.5)
    geom.boolean_difference([union], [disk3, disk4])

    ref = 4.0
    mesh = pygmsh.generate_mesh(geom)
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh
Ejemplo n.º 60
0
def test():
    geom = pygmsh.built_in.Geometry()

    geom.add_circle(
        [0.0, 0.0, 0.0],
        1.0,
        lcar=0.1,
        num_sections=4,
        # If compound==False, the section borders have to be points of the
        # discretization. If using a compound circle, they don't; gmsh can
        # choose by itself where to point the circle points.
        compound=True,
    )

    ref = 3.1363871677682247
    mesh = pygmsh.generate_mesh(geom, prune_z_0=True)
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh