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():
class DC(object):
def apply(self, u):
a = numpy.array([2, 1, 0])
return (
integrate(lambda x: -n_dot_grad(u(x)) + n_dot(a) * u(x), dS)
- integrate(lambda x: 1.0, dV)
)
def dirichlet(self, u):
return [(u, Boundary())]
vertices, cells = meshzoo.rectangle(0.0, 1.0, 0.0, 1.0, 51, 51)
mesh = voropy.mesh_tri.MeshTri(vertices, cells)
matrix, rhs = pyfvm.discretize_linear(DC(), mesh)
u = linalg.spsolve(matrix, rhs)
mesh.write('out.vtu', point_data={'u': u})
return
def test():
class Bratu(object):
def apply(self, u):
return integrate(lambda x: -n_dot_grad(u(x)), dS) \
- integrate(lambda x: 2.0 * exp(u(x)), dV)
def dirichlet(self, u):
return [(u, Boundary())]
vertices, cells = meshzoo.rectangle(0.0, 2.0, 0.0, 1.0, 101, 51)
mesh = voropy.mesh_tri.MeshTri(vertices, cells)
f, jacobian = pyfvm.discretize(Bratu(), mesh)
def jacobian_solver(u0, rhs):
from scipy.sparse import linalg
jac = jacobian.get_linear_operator(u0)
return linalg.spsolve(jac, rhs)
u0 = numpy.zeros(len(vertices))
u = pyfvm.newton(f.eval, jacobian_solver, u0)
# import scipy.optimize
# u = scipy.optimize.newton_krylov(f.eval, u0)
mesh.write('out.vtu', point_data={'u': u})
return
def test():
class Singular(object):
def apply(self, u):
return integrate(lambda x: - 1.0e-2 * n_dot_grad(u(x)), dS) \
+ integrate(u, dV) \
- integrate(lambda x: 1.0, dV)
def dirichlet(self, u):
return [(u, Boundary())]
vertices, cells = meshzoo.rectangle(0.0, 1.0, 0.0, 1.0, 51, 51)
mesh = voropy.mesh_tri.MeshTri(vertices, cells)
matrix, rhs = pyfvm.discretize_linear(Singular(), mesh)
u = linalg.spsolve(matrix, rhs)
mesh.write('out.vtu', point_data={'u': u})
return
def get_mesh(k):
n = 2**(k+1)
vertices, cells = meshzoo.rectangle(
0.0, 1.0,
0.0, 1.0,
n+1, n+1,
zigzag=True
)
return voropy.mesh_tri.MeshTri(vertices, cells)
def get_mesh(self, k):
n = 2 ** (k + 1)
vertices, cells = meshzoo.rectangle(
0.0, 1.0, 0.0, 1.0, n + 1, n + 1, zigzag=True
)
return meshplex.MeshTri(vertices, cells)
def get_mesh(k):
n = 2**(k+1)
vertices, cells = meshzoo.rectangle(
0.0, 1.0,
0.0, 1.0,
n+1, n+1,
zigzag=True
)
return voropy.mesh_tri.MeshTri(vertices, cells)
def test_center():
points, cells = meshzoo.rectangle(nx=11, ny=9, variant="center")
meshzoo.show2d(points, cells)
assert len(points) == 99
assert len(cells) == 160
def get_mesh(self, k):
n = 2 ** (k + 1)
vertices, cells = meshzoo.cube(
0.0, 1.0, 0.0, 1.0, 0.0, 1.0, n + 1, n + 1, n + 1
)
return meshplex.MeshTetra(vertices, cells)
def get_mesh(k):
n = 2**(k+1)
vertices, cells = meshzoo.cube(
0.0, 1.0,
0.0, 1.0,
0.0, 1.0,
n+1, n+1, n+1
)
return voropy.mesh_tetra.MeshTetra(vertices, cells, mode='algebraic')
def get_mesh(self, k):
n = 2 ** (k + 1)
vertices, cells = meshzoo.cube(
0.0, 1.0, 0.0, 1.0, 0.0, 1.0, n + 1, n + 1, n + 1
)
return meshplex.MeshTetra(vertices, cells)