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(show=False):
geo = dmsh.Scaling(dmsh.Rectangle(-1.0, +2.0, -1.0, +1.0), 2.0)
X, cells = dmsh.generate(geo, 0.1, show=show, tol=1.0e-5)
ref_norms = [7.7120645429243405e03, 1.2509238632152577e02, 4.0]
assert_norm_equality(X.flatten(), ref_norms, 1.0e-10)
return X, cells
def test(show=True):
geo = dmsh.Stretch(dmsh.Rectangle(-1.0, +2.0, -1.0, +1.0), [1.0, 1.0])
X, cells = dmsh.generate(geo, 0.3, show=show, tol=1.0e-3)
ref_norms = [1.9391178579025609e02, 1.5890693098212086e01, 2.6213203435596428e00]
assert_norm_equality(X.flatten(), ref_norms, 1.0e-2)
return X, cells
def test_union(show=False):
angles = numpy.pi * numpy.array([3.0 / 6.0, 7.0 / 6.0, 11.0 / 6.0])
geo = dmsh.Union(
[
dmsh.Circle([numpy.cos(angles[0]), numpy.sin(angles[0])], 1.0),
dmsh.Circle([numpy.cos(angles[1]), numpy.sin(angles[1])], 1.0),
dmsh.Circle([numpy.cos(angles[2]), numpy.sin(angles[2])], 1.0),
]
)
X, cells = dmsh.generate(geo, 0.2, show=show, tol=1.0e-10)
ref_norms = [4.0372522103229670e02, 2.1155465970807523e01, 1.9999337650692937e00]
assert_norm_equality(X.flatten(), ref_norms, 1.0e-10)
return X, cells
def dmsh_circle(num_points):
target_edge_length = 2 * np.pi / _compute_num_boundary_points(num_points)
geo = dmsh.Circle([0.0, 0.0], 1.0)
X, cells = dmsh.generate(geo, target_edge_length)
return X, cells
def test_large():
# https://github.com/nschloe/dmsh/issues/11
r = dmsh.Rectangle(-10.0, +20.0, -10.0, +20.0)
c = dmsh.Circle([0.0, 0.0], 3)
geo = dmsh.Difference(r, c)
X, cells = dmsh.generate(geo, 2.0, tol=1.0e-5, max_steps=10000)
ref_norms = [4.6422985179724637e03, 2.4202897690682192e02, 2.0000000000000000e01]
assert_norm_equality(X.flatten(), ref_norms, 1.0e-4)
def test_halfspace(show=False):
geo = dmsh.Intersection(
[
dmsh.HalfSpace(numpy.sqrt(0.5) * numpy.array([1.0, 1.0]), 0.0),
dmsh.Circle([0.0, 0.0], 1.0),
]
)
X, cells = dmsh.generate(geo, 0.1, show=show)
ref_norms = [1.6445971629723411e02, 1.0032823867864321e01, 9.9962000746451751e-01]
assert_norm_equality(X.flatten(), ref_norms, 1.0e-10)
return X, cells
def test_circle(h0=0.7, show=True):
geo = dmsh.geometry.Circle([0.0, 0.0], 1.0)
X, cells = dmsh.generate(geo, h0, show=show)
# X = numpy.column_stack([X[0], X[1], numpy.zeros(X.shape[1])])
# import meshio
# meshio.write_points_cells("out.vtk", X, {"triangle": cells})
X = X.T
assert numpy.array_equal(
cells,
[
[3, 4, 6],
[3, 5, 0],
[5, 3, 6],
[7, 4, 2],
[4, 7, 6],
[1, 3, 0],
def test_circle(radius, ref_norms, show=False):
geo = dmsh.Circle([0.0, 0.0], 1.0)
X, cells = dmsh.generate(geo, radius, show=show)
# make sure the origin is part of the mesh
assert numpy.sum(numpy.einsum("ij,ij->i", X, X) < 1.0e-10) == 1
assert_norm_equality(X.flatten(), ref_norms, 1.0e-5)
return X, cells
def plot(f, lcar=1.0e-1):
"""Plot function over a disk.
"""
import matplotlib
import matplotlib.pyplot as plt
import dmsh
geo = dmsh.Circle([0.0, 0.0], 1.0)
points, cells = dmsh.generate(geo, 0.1)
x = points[:, 0]
y = points[:, 1]
triang = matplotlib.tri.Triangulation(x, y, cells["triangle"])
plt.tripcolor(triang, f(points.T), shading="flat")
plt.colorbar()
# Choose a diverging colormap such that the zeros are clearly
# distinguishable.
plt.set_cmap("coolwarm")
# Make sure the color map limits are symmetric around 0.
clim = plt.gci().get_clim()
mx = max(abs(clim[0]), abs(clim[1]))
plt.clim(-mx, mx)