How to use the pygmsh.built_in 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_pacman.py View on Github external
def test(lcar=0.3):
    geom = pygmsh.built_in.Geometry()

    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)
github nschloe / pygmsh / test / test_rectangle.py View on Github external
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
github nschloe / pygmsh / test / test_tori.py View on Github external
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)

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

    ref = 2 * 2 * np.pi ** 2 * orad * irad ** 2
    mesh = pygmsh.generate_mesh(geom)
    assert np.isclose(compute_volume(mesh), ref, rtol=5e-2)
    return mesh
github nschloe / pygmsh / test / test_torus_crowd.py View on Github external
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,
github nschloe / pygmsh / test / test_transfinite.py View on Github external
def test(lcar=1.0):
    geom = pygmsh.built_in.Geometry()
    poly = geom.add_polygon(
        [[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 1.0, 0.0], [0.0, 1.0, 0.0]], lcar
    )

    geom.set_transfinite_surface(poly.surface, size=[11, 9])

    mesh = pygmsh.generate_mesh(geom, geo_filename="transfinite.geo")
    assert len(mesh.cells_dict["triangle"]) == 10 * 8 * 2
    return mesh
github nschloe / pygmsh / test / test_torus.py View on Github external
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
github nschloe / pygmsh / test / test_symmetry.py View on Github external
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
github nschloe / pygmsh / test / test_circle.py View on Github external
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
github nschloe / pygmsh / test / test_airfoil.py View on Github external
[0.952002, -0.003650, 0.0],
            [0.964576, -0.002708, 0.0],
            [0.975305, -0.001896, 0.0],
            [0.984145, -0.001222, 0.0],
            [0.991060, -0.000691, 0.0],
            [0.996020, -0.000308, 0.0],
            [0.999004, -0.000077, 0.0],
        ]
    )

    # Scale airfoil to input coord
    coord = 1.0
    airfoil_coordinates *= coord

    # Instantiate geometry object
    geom = pygmsh.built_in.Geometry()

    # Create polygon for airfoil
    char_length = 1.0e-1
    airfoil = geom.add_polygon(airfoil_coordinates, char_length, make_surface=False)

    # Create surface for numerical domain with an airfoil-shaped hole
    left_dist = 1.0
    right_dist = 3.0
    top_dist = 1.0
    bottom_dist = 1.0
    xmin = airfoil_coordinates[:, 0].min() - left_dist * coord
    xmax = airfoil_coordinates[:, 0].max() + right_dist * coord
    ymin = airfoil_coordinates[:, 1].min() - bottom_dist * coord
    ymax = airfoil_coordinates[:, 1].max() + top_dist * coord
    domainCoordinates = numpy.array(
        [[xmin, ymin, 0.0], [xmax, ymin, 0.0], [xmax, ymax, 0.0], [xmin, ymax, 0.0]]
github nschloe / colorio / colorio / _color_space.py View on Github external
def save_cone_gamut(self, filename, observer, max_Y):
        import meshio
        import pygmsh

        geom = pygmsh.built_in.Geometry()

        max_stepsize = 4.0e-2
        xy, _ = get_mono_outline_xy(observer, max_stepsize=max_stepsize)

        # append third component
        xy = numpy.column_stack([xy, numpy.full(xy.shape[0], 1.0e-5)])

        # Draw a cross.
        poly = geom.add_polygon(xy, lcar=max_stepsize)

        axis = [0, 0, max_Y]

        geom.extrude(poly, translation_axis=axis, point_on_axis=[0, 0, 0])

        mesh = pygmsh.generate_mesh(geom, verbose=False)
        # meshio.write(filename, mesh)