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 get_ball_mesh(k):
import pygmsh
h = 0.5 ** (k + 1)
geom = pygmsh.built_in.Geometry()
geom.add_ball([0.0, 0.0, 0.0], 1.0, lcar=h)
mesh = pygmsh.generate_mesh(geom, verbose=False)
cells = mesh.get_cells_type("tetra")
# toss away unused points
uvertices, uidx = numpy.unique(cells, return_inverse=True)
cells = uidx.reshape(cells.shape)
points = mesh.points[uvertices]
return meshplex.MeshTetra(points, cells)
circle = geom.add_circle([0.5, 0.5, 0.0], 1.0, lcar)
triangle = geom.add_polygon(
[[2.0, -0.5, 0.0], [4.0, -0.5, 0.0], [4.0, 1.5, 0.0]], lcar
)
rectangle = geom.add_rectangle(4.75, 6.25, -0.24, 1.25, 0.0, lcar)
# hold all domain
geom.add_polygon(
[[-1.0, -1.0, 0.0], [+7.0, -1.0, 0.0], [+7.0, +2.0, 0.0], [-1.0, +2.0, 0.0]],
lcar,
holes=[circle.line_loop, triangle.line_loop, rectangle.line_loop],
)
ref = 24.0
mesh = pygmsh.generate_mesh(geom)
assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
return mesh
_, rectangle, _ = geom.extrude(
line, translation_axis=[0.0, lbw[1], 0.0], num_layers=lbw[1], recombine=True
)
geom.extrude(
rectangle,
translation_axis=[0.0, 0.0, lbw[2]],
num_layers=lbw[2],
recombine=True,
)
# compute_volume only supports 3D for tetras, but does return
# surface area for quads
ref = sum(l * w for l, w in permutations(lbw, 2)) # surface area
mesh = pygmsh.generate_mesh(geom, prune_vertices=False)
# TODO compute hex volumes
assert (
abs(
compute_volume(meshio.Mesh(mesh.points, {"quad": mesh.cells_dict["quad"]}))
- ref
)
< 1.0e-2 * ref
)
return mesh
[0.1, 0.1, 0.0],
],
lcar=0.05,
)
axis = [0, 0, 1]
geom.extrude(
poly,
translation_axis=axis,
rotation_axis=axis,
point_on_axis=[0, 0, 0],
angle=2.0 / 6.0 * np.pi,
)
points, cells, _, _, _ = pg.generate_mesh(geom)
return points, cells["tetra"]