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):
r = dmsh.Rectangle(-1.0, +1.0, -1.0, +1.0)
c = dmsh.Circle([0.0, 0.0], 0.3)
geo = dmsh.Difference(r, c)
X, cells = dmsh.generate(
geo, lambda pts: numpy.abs(c.dist(pts)) / 5 + 0.05, show=show, tol=1.0e-10
)
ref_norms = [2.48e02, 1.200e01, 1.0]
assert_norm_equality(X.flatten(), ref_norms, 1.0e-3)
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_pacman(show=False):
geo = dmsh.Difference(
dmsh.Circle([0.0, 0.0], 1.0),
dmsh.Polygon([[0.0, 0.0], [1.5, 0.4], [1.5, -0.4]]),
)
X, cells = dmsh.generate(geo, 0.1, show=show, tol=1.0e-10)
ref_norms = [3.0385105041432689e02, 1.3644964912810719e01, 1.0]
assert_norm_equality(X.flatten(), ref_norms, 1.0e-10)
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(target_num_points):
import dmsh
print("target num points", target_num_points)
est_num_boundary_nodes = _compute_num_boundary_points(target_num_points)
est_num_boundary_nodes = 100
target_edge_length = 2 * np.pi / est_num_boundary_nodes
print(target_edge_length)
print("est num boundary", est_num_boundary_nodes)
geo = dmsh.Circle([0.0, 0.0], 1.0)
X, cells = dmsh.generate(geo, target_edge_length)
print("num points", X.shape[0])
import meshplex
mesh = meshplex.MeshTri(X, cells)
print("num boundary points", sum(mesh.is_boundary_node))
# exit(1)
return X, cells
from skfem import *
from skfem.models.poisson import vector_laplace, laplace
from skfem.models.general import divergence, rot
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.linalg import cg, LinearOperator
from sksparse.cholmod import cholesky
import dmsh
mesh = MeshTri(*map(np.transpose,
dmsh.generate(dmsh.Circle([0., 0.], 1.), .1)))
element = {'u': ElementVectorH1(ElementTriP2()),
'p': ElementTriP1()}
basis = {variable: InteriorBasis(mesh, e, intorder=3)
for variable, e in element.items()}
@linear_form
def body_force(v, dv, w):
return w.x[0] * v[1]
velocity = np.zeros(basis['u'].N)
A = asm(vector_laplace, basis['u'])
B = asm(divergence, basis['u'], basis['p'])
f = asm(body_force, basis['u'])
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)