def test(): class D1(Subdomain): def is_inside(self, x): return x[1] < 0.5 is_boundary_only = True class Poisson(object): def apply(self, u): return ( integrate(lambda x: -n_dot_grad(u(x)), dS) + integrate(lambda x: 3.0, dGamma) - integrate(lambda x: 1.0, dV) ) def dirichlet(self, u): return [(u, D1())] vertices, cells = meshzoo.rectangle(0.0, 1.0, 0.0, 1.0, 51, 51) mesh = meshplex.MeshTri(vertices, cells) matrix, rhs = pyfvm.discretize_linear(Poisson(), mesh) u = linalg.spsolve(matrix, rhs) mesh.write("out.vtk", point_data={"u": u}) return
def test(): class D1(Subdomain): def is_inside(self, x): return x[1] < 0.5 is_boundary_only = True class Poisson: def apply(self, u): return (integrate(lambda x: -n_dot_grad(u(x)), dS) + integrate(lambda x: 3.0, dGamma) - integrate(lambda x: 1.0, dV)) def dirichlet(self, u): return [(u, D1())] vertices, cells = meshzoo.rectangle(0.0, 1.0, 0.0, 1.0, 51, 51) mesh = meshplex.MeshTri(vertices, cells) matrix, rhs = pyfvm.discretize_linear(Poisson(), mesh) u = linalg.spsolve(matrix, rhs) mesh.write("out.vtk", point_data={"u": u}) return
def test(): class Gamma0(Subdomain): def is_inside(self, x): return x[1] < 0.5 is_boundary_only = True class Gamma1(Subdomain): def is_inside(self, x): return x[1] >= 0.5 is_boundary_only = True class Poisson(object): def apply(self, u): return integrate(lambda x: -n_dot_grad(u(x)), dS) - integrate( lambda x: 50 * sin(2 * pi * x[0]), dV) def dirichlet(self, u): return [(lambda x: u(x) - 0.0, Gamma0()), (lambda x: u(x) - 1.0, Gamma1())] # # Read the mesh from file # mesh, _, _ = pyfvm.reader.read('circle.vtu') # Create mesh using meshzoo import meshzoo vertices, cells = meshzoo.cube(0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 30, 30, 30) mesh = meshplex.MeshTetra(vertices, cells) # vertices, cells = meshzoo.rectangle(0.0, 2.0, 0.0, 1.0, 401, 201) # mesh = meshplex.MeshTri(vertices, cells) print(len(vertices)) # import mshr # import dolfin # # h = 2.5e-3 # h = 1.e-1 # # cell_size = 2 * pi / num_boundary_points # c = mshr.Circle(dolfin.Point(0., 0., 0.), 1, int(2*pi / h)) # # cell_size = 2 * bounding_box_radius / res # m = mshr.generate_mesh(c, 2.0 / h) # coords = m.coordinates() # coords = numpy.c_[coords, numpy.zeros(len(coords))] # cells = m.cells().copy() # mesh = meshplex.MeshTri(coords, cells) # # mesh = meshplex.lloyd_smoothing(mesh, 1.0e-4) matrix, rhs = pyfvm.discretize_linear(Poisson(), mesh) # ml = pyamg.smoothed_aggregation_solver(matrix) ml = pyamg.ruge_stuben_solver(matrix) u = ml.solve(rhs, tol=1e-10) # from scipy.sparse import linalg # u = linalg.spsolve(matrix, rhs) mesh.write("out.vtk", point_data={"u": u}) return
def test(): class Gamma0(Subdomain): def is_inside(self, x): return x[1] < 0.5 is_boundary_only = True class Gamma1(Subdomain): def is_inside(self, x): return x[1] >= 0.5 is_boundary_only = True class Poisson(object): def apply(self, u): return integrate(lambda x: -n_dot_grad(u(x)), dS) - integrate( lambda x: 50 * sin(2 * pi * x[0]), dV ) def dirichlet(self, u): return [(lambda x: u(x) - 0.0, Gamma0()), (lambda x: u(x) - 1.0, Gamma1())] # # Read the mesh from file # mesh, _, _ = pyfvm.reader.read('circle.vtu') # Create mesh using meshzoo import meshzoo vertices, cells = meshzoo.cube(0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 30, 30, 30) mesh = meshplex.MeshTetra(vertices, cells) # vertices, cells = meshzoo.rectangle(0.0, 2.0, 0.0, 1.0, 401, 201) # mesh = meshplex.MeshTri(vertices, cells) print(len(vertices)) # import mshr # import dolfin # # h = 2.5e-3 # h = 1.e-1 # # cell_size = 2 * pi / num_boundary_points # c = mshr.Circle(dolfin.Point(0., 0., 0.), 1, int(2*pi / h)) # # cell_size = 2 * bounding_box_radius / res # m = mshr.generate_mesh(c, 2.0 / h) # coords = m.coordinates() # coords = numpy.c_[coords, numpy.zeros(len(coords))] # cells = m.cells().copy() # mesh = meshplex.MeshTri(coords, cells) # # mesh = meshplex.lloyd_smoothing(mesh, 1.0e-4) matrix, rhs = pyfvm.discretize_linear(Poisson(), mesh) # ml = pyamg.smoothed_aggregation_solver(matrix) ml = pyamg.ruge_stuben_solver(matrix) u = ml.solve(rhs, tol=1e-10) # from scipy.sparse import linalg # u = linalg.spsolve(matrix, rhs) mesh.write("out.vtk", point_data={"u": u}) return
def __init__(self): points, cells = meshzoo.rectangle(0.0, 1.0, 0.0, 1.0, 30, 30) self.mesh = meshplex.MeshTri(points, cells) # This matrix self.A is negative semidefinite self.A, _ = pyfvm.discretize_linear(Poisson(), self.mesh) tol = 1.0e-12 self.idx_left = numpy.where(self.mesh.node_coords[:, 0] < tol)[0] self.idx_right = numpy.where(self.mesh.node_coords[:, 0] > 1.0 - tol)[0] self.idx_bottom = numpy.where(self.mesh.node_coords[:, 1] < tol)[0] self.idx_top = numpy.where(self.mesh.node_coords[:, 1] > 1.0 - tol)[0]
def __init__(self): a = 24.0 points, cells = meshzoo.rectangle(-a / 2, a / 2, -a / 2, a / 2, 50, 50) self.mesh = meshplex.MeshTri(points, cells) x, y, z = self.mesh.node_coords.T assert numpy.all(numpy.abs(z) < 1.0e-15) self.omega = 0.2 self.V = 0.5 * self.omega**2 * (x**2 + y**2) # For the preconditioner assert numpy.all(self.V >= 0) self.A, _ = pyfvm.discretize_linear(Poisson(), self.mesh)
def __init__(self): a = 24.0 points, cells = meshzoo.rectangle_tri(np.linspace(-a / 2, a / 2, 50), np.linspace(-a / 2, a / 2, 50)) self.mesh = meshplex.Mesh(points, cells) x, y, z = self.mesh.points.T assert np.all(np.abs(z) < 1.0e-15) self.omega = 0.2 self.V = 0.5 * self.omega**2 * (x**2 + y**2) # For the preconditioner assert np.all(self.V >= 0) self.A, _ = pyfvm.discretize_linear(Poisson(), self.mesh)
def test(): class Singular: 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 = meshplex.MeshTri(vertices, cells) matrix, rhs = pyfvm.discretize_linear(Singular(), mesh) u = linalg.spsolve(matrix, rhs) mesh.write("out.vtk", point_data={"u": u}) return
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 = meshplex.MeshTri(vertices, cells) matrix, rhs = pyfvm.discretize_linear(DC(), mesh) u = linalg.spsolve(matrix, rhs) mesh.write("out.vtk", point_data={"u": u}) return
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 = meshplex.MeshTri(vertices, cells) matrix, rhs = pyfvm.discretize_linear(DC(), mesh) u = linalg.spsolve(matrix, rhs) mesh.write("out.vtk", 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 = meshplex.MeshTri(vertices, cells) matrix, rhs = pyfvm.discretize_linear(Singular(), mesh) u = linalg.spsolve(matrix, rhs) mesh.write("out.vtk", point_data={"u": u}) return
def solver(mesh): matrix, rhs = pyfvm.discretize_linear(problem, mesh) ml = pyamg.smoothed_aggregation_solver(matrix) u = ml.solve(rhs, tol=1e-10) return u