How to use the pygmsh.built_in.Geometry 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_hole_in_square.py View on Github external
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])

    mesh = pygmsh.generate_mesh(geom, extra_gmsh_arguments=["-order", "2"])
    # TODO support for volumes of triangle6
    # ref = 16.0
    # from helpers import compute_volume
    # assert abs(compute_volume(points, cells) - ref) < 1.0e-2 * ref
    return mesh
github nschloe / pygmsh / test / test_recombine.py View on Github external
def test():
    geom = pygmsh.built_in.Geometry()
    p0 = geom.add_point((0.0, 0.0, 0.0), lcar=1.0)
    p1 = geom.add_point((2.0, 0.0, 0.0), lcar=1.0)
    p2 = geom.add_point((0.0, 1.0, 0.0), lcar=1.0)
    p3 = geom.add_point((2.0, 1.0, 0.0), lcar=1.0)
    l0 = geom.add_line(p0, p1)
    l1 = geom.add_line(p1, p3)
    l2 = geom.add_line(p3, p2)
    l3 = geom.add_line(p2, p0)
    ll0 = geom.add_line_loop((l0, l1, l2, l3))
    rs0 = geom.add_surface(ll0)
    geom.set_transfinite_lines([l3, l1], 3, progression=1)
    geom.set_transfinite_lines([l2, l0], 3, progression=1)
    geom.set_transfinite_surface(rs0)
    geom.set_recombined_surfaces([rs0])

    mesh = pygmsh.generate_mesh(geom)
github nschloe / pygmsh / test / test_bsplines.py View on Github external
def test():
    geom = pygmsh.built_in.Geometry()

    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_line_loop([s1, s2])
    geom.add_plane_surface(ll)

    ref = 0.9156598733673261 if pygmsh.get_gmsh_major_version() < 4 else 0.75
github nschloe / pygmsh / test / test_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.built_in.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_helpers.py View on Github external
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
github icepack / icepack / demo / meshing.py View on Github external
def collection_to_geo(collection, lcar=10e3):
    geometry = pygmsh.built_in.Geometry()

    features = collection['features']
    num_features = len(features)

    points = [[[geometry.add_point((point[0], point[1], 0.), lcar=lcar)
                for point in line_string[:-1]]
               for line_string in feature['geometry']['coordinates']]
              for feature in features]

    line_loops = [add_loop_to_geometry(geometry, multi_line_string)
                  for multi_line_string in points]
    plane_surface = geometry.add_plane_surface(line_loops[0],
                                               holes=line_loops[1:])
    physical_surface = geometry.add_physical(plane_surface)

    return geometry
github kinnala / scikit-fem / docs / examples / ex27.py View on Github external
def make_geom(length: float, lcar: float) -> Geometry:
        # Barkley et al (2002, figure 3 a - c)
        geom = Geometry()

        points = []
        for point in [[0, -1, 0],
                      [length, -1, 0],
                      [length, 1, 0],
                      [-1, 1, 0],
                      [-1, 0, 0],
                      [0, 0, 0]]:
            points.append(geom.add_point(point, lcar))

        lines = []
        for termini in zip(points,
                           islice(cycle(points), 1, None)):
            lines.append(geom.add_line(*termini))

        for k, label in [([1], 'outlet'),
github kinnala / scikit-fem / docs / examples / ex35.py View on Github external
def make_mesh() -> MeshTri:
    # dimensions for RG316 coaxial cable
    inner_conductor_diameter = 0.50e-3
    inner_insulator_diameter = 1.52e-3
    outer_conductor_diameter = 1.98e-3
    outer_insulator_diameter = 2.48e-3

    # characteristic length for mesh generation
    lcar = 0.1e-3

    geom = Geometry()

    inner_conductor = geom.add_circle(
        (0, 0, 0), inner_conductor_diameter/2,
        lcar=lcar)
    geom.add_physical(
        inner_conductor.plane_surface, label='inner_conductor')
    geom.add_physical(
        inner_conductor.line_loop.lines, label='inner_conductor_outer_surface')

    inner_insulator = geom.add_circle(
        (0, 0, 0), inner_insulator_diameter/2,
        lcar=lcar, holes=[inner_conductor.line_loop])
    geom.add_physical(
        inner_insulator.plane_surface, label='inner_insulator')
    geom.add_physical(
        inner_insulator.line_loop.lines, label='outer_conductor_inner_surface')
github kinnala / scikit-fem / docs / examples / ex24.py View on Github external
def make_geom(length: float = 35.,
              lcar: float = 1.) -> Geometry:
    # Barkley et al (2002, figure 3 a - c)
    geom = Geometry()

    points = []
    for point in [[0, -1, 0],
                  [length, -1, 0],
                  [length, 1, 0],
                  [-1, 1, 0],
                  [-1, 0, 0],
                  [0, 0, 0]]:
        points.append(geom.add_point(point, lcar))

    lines = []
    for termini in zip(points,
                       islice(cycle(points), 1, None)):
        lines.append(geom.add_line(*termini))

    for k, label in [([1], 'outlet'),