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 test():
class EnergyEdgeKernel(object):
def __init__(self, linear, affine):
self.subdomains = [None]
return
def eval(self, mesh, cell_mask):
edge_ce_ratio = mesh.get_ce_ratios()[..., cell_mask]
beta = 1.0
return numpy.array([
[edge_ce_ratio, -edge_ce_ratio * numpy.exp(1j * beta)],
[-edge_ce_ratio * numpy.exp(-1j * beta), edge_ce_ratio]
])
vertices, cells = meshzoo.rectangle(0.0, 2.0, 0.0, 1.0, 101, 51)
mesh = voropy.mesh_tri.MeshTri(vertices, cells)
matrix = pyfvm.get_fvm_matrix(mesh, [EnergyEdgeKernel()], [], [], [])
rhs = mesh.control_volumes.copy()
sa = pyamg.smoothed_aggregation_solver(matrix, smooth='energy')
u = sa.solve(rhs, tol=1e-10)
# Cannot write complex data ot VTU; split real and imaginary parts first.
#
mesh.write('out.vtu', point_data={'u': u.view('(2,)float')})
return