How to use the pygmsh.opencascade function in pygmsh

To help you get started, we’ve selected a few pygmsh examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nschloe / pygmsh / test / test_opencascade_ball.py View on Github external
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
github nschloe / pygmsh / test / test_meshio_logo.py View on Github external
def test():
    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])

    mesh = pygmsh.generate_mesh(geom)
    ref = 81.9131851877
github nschloe / pygmsh / test / test_opencascade_regular_extrusion.py View on Github external
def test():
    x = 5
    y = 4
    z = 3
    x_layers = 10
    y_layers = 5
    z_layers = 3
    geom = pygmsh.opencascade.Geometry()
    p = geom.add_point([0, 0, 0], 1)
    _, l, _ = geom.extrude(p, [x, 0, 0], num_layers=x_layers)
    _, s, _ = geom.extrude(l, [0, y, 0], num_layers=y_layers)
    geom.extrude(s, [0, 0, z], num_layers=z_layers)
    mesh = pygmsh.generate_mesh(geom)

    ref_vol = x * y * z
    assert abs(compute_volume(mesh) - ref_vol) < 1.0e-2 * ref_vol

    # Each grid-cell from layered extrusion will result in 6 tetrahedrons.
    ref_tetras = 6 * x_layers * y_layers * z_layers
    assert len(mesh.cells_dict["tetra"]) == ref_tetras

    return mesh
github nschloe / pygmsh / test / test_opencascade_extrude2.py View on Github external
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 = []
github nschloe / pygmsh / test / test_opencascade_cone.py View on Github external
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
github nschloe / pygmsh / test / test_opencascade_torus.py View on Github external
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
github nschloe / pygmsh / test / test_booleans.py View on Github external
def built_in_opencascade_geos():
    """Construct surface using builtin and boolean methods."""
    # construct surface with hole using standard built in
    geo_object = pygmsh.opencascade.Geometry(0.05, 0.05)
    geo_object, square = square_loop(geo_object)
    geo_object, circle = circle_loop(geo_object)
    geo_object.add_plane_surface(square, [circle])

    # construct surface using boolean
    geo_object2 = pygmsh.opencascade.Geometry(0.05, 0.05)
    geo_object2, square2 = square_loop(geo_object2)
    geo_object2, line_loop2 = circle_loop(geo_object2)
    surf1 = geo_object2.add_plane_surface(square2)
    surf2 = geo_object2.add_plane_surface(line_loop2)
    geo_object2.boolean_difference([surf1], [surf2])

    return geo_object, geo_object2
github nschloe / pygmsh / test / test_booleans.py View on Github external
def built_in_opencascade_geos_fragments():
    """Cconstruct surface using boolean fragments."""

    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.boolean_fragments([surf1], [surf2])
    return geo_object
github nschloe / pygmsh / test / test_opencascade_boolean.py View on Github external
def test_difference():
    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_difference([rectangle], [disk_w, disk_e])

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