Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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
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
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
def test():
geom = pygmsh.opencascade.Geometry()
geom.add_ellipsoid([1.0, 1.0, 1.0], [1.0, 2.0, 3.0], char_length=0.1)
ref = 8.0 * pi
mesh = pygmsh.generate_mesh(geom)
assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
return mesh
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
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)
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
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
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)