How to use the pygmsh.rotation_matrix 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_pipes.py View on Github external
def test():
    """Pipe with double-ring enclosure, rotated in space.
    """
    geom = pygmsh.built_in.Geometry()

    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, 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
    mesh = pygmsh.generate_mesh(geom)
    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_circle_transform.py View on Github external
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
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_torus_crowd.py View on Github external
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)
github nschloe / pygmsh / test / test_torus_crowd.py View on Github external
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)