def ngsolve_vector_array_factory(length, dim, seed): if dim not in NGSOLVE_spaces: mesh = ngmsh.Mesh(dim=1) if dim > 0: pids = [] for i in range(dim + 1): pids.append( mesh.Add(ngmsh.MeshPoint(ngmsh.Pnt(i / dim, 0, 0)))) for i in range(dim): mesh.Add(ngmsh.Element1D([pids[i], pids[i + 1]], index=1)) NGSOLVE_spaces[dim] = NGSolveVectorSpace( ngs.L2(ngs.Mesh(mesh), order=0)) U = NGSOLVE_spaces[dim].zeros(length) np.random.seed(seed) for v, a in zip(U._list, np.random.random((length, dim))): v.to_numpy()[:] = a if np.random.randint(2): UU = NGSOLVE_spaces[dim].zeros(length) for v, a in zip(UU._list, np.random.random((length, dim))): v.real_part.to_numpy()[:] = a for u, uu in zip(U._list, UU._list): u.imag_part = uu.real_part return U
def _create_ngsolve_space(dim): if dim not in _NGSOLVE_spaces: mesh = ngmsh.Mesh(dim=1) if dim > 0: pids = [] for i in range(dim + 1): pids.append(mesh.Add(ngmsh.MeshPoint(ngmsh.Pnt(i / dim, 0, 0)))) for i in range(dim): mesh.Add(ngmsh.Element1D([pids[i], pids[i + 1]], index=1)) _NGSOLVE_spaces[dim] = NGSolveVectorSpace(ngs.L2(ngs.Mesh(mesh), order=0)) return _NGSOLVE_spaces[dim]
def test_parallel(): mesh = ngs.Mesh(unit_square.GenerateMesh(maxh=0.2)) fes = ngs.L2(mesh, order=5, complex=True) g1 = ngs.GridFunction(fes) g2 = ngs.GridFunction(fes) for order in range(10): functions = [(f(ngs.x + 1j * ngs.y, order)) for f in fs_ng] for f in functions: g1.Set(f) with ngs.TaskManager(): g2.Set(f) error = ngs.Integrate(g1 - g2, mesh) assert error == 0j
import regpy.stoprules as rules from regpy.operators.ngsolve import Coefficient from regpy.solvers import HilbertSpaceSetting from regpy.solvers.landweber import Landweber from regpy.hilbert import L2, Sobolev from regpy.discrs.ngsolve import NgsSpace logging.basicConfig( level=logging.INFO, format='%(asctime)s %(levelname)s %(name)-40s :: %(message)s') meshsize_domain = 10 meshsize_codomain = 10 mesh = MakeQuadMesh(meshsize_domain) fes_domain = ngs.L2(mesh, order=2) domain = NgsSpace(fes_domain) mesh = MakeQuadMesh(meshsize_codomain) fes_codomain = ngs.H1(mesh, order=3, dirichlet="left|top|right|bottom") codomain = NgsSpace(fes_codomain) rhs = 10 * ngs.sin(ngs.x) * ngs.sin(ngs.y) op = Coefficient(domain, rhs, codomain=codomain, bc_left=0, bc_right=0, bc_bottom=0, bc_top=0, diffusion=False,
fes_domain = ngs.H1(mesh, order=2) domain = NgsSpace(fes_domain) fes_codomain = ngs.H1(mesh, order=2) codomain = NgsSpace(fes_codomain) g = ngs.x**2 * ngs.y op = ReactionBoundary(domain, g, codomain=codomain) exact_solution_coeff = ngs.sin(ngs.y) + 2 gfu_exact_solution = ngs.GridFunction(op.fes_domain) gfu_exact_solution.Set(exact_solution_coeff) exact_solution = gfu_exact_solution.vec.FV().NumPy() exact_data = op(exact_solution) fes_noise = ngs.L2(fes_codomain.mesh, order=1) gfu_noise_order1 = ngs.GridFunction(fes_noise) gfu_noise_order1.vec.FV().NumPy()[:] = 0.0005 * np.random.randn(fes_noise.ndof) gfu_noise = ngs.GridFunction(fes_codomain) gfu_noise.Set(gfu_noise_order1) noise = op._get_boundary_values(gfu_noise) data = exact_data + noise init = 2 init_gfu = ngs.GridFunction(op.fes_domain) init_gfu.Set(init) init_solution = init_gfu.vec.FV().NumPy().copy() init_sol = init_solution.copy() init_data = op(init_solution)
import regpy.stoprules as rules from regpy.operators.ngsolve import Coefficient from regpy.solvers import HilbertSpaceSetting from regpy.solvers.landweber import Landweber from regpy.hilbert import L2 from regpy.discrs.ngsolve import NgsSpace logging.basicConfig( level=logging.INFO, format='%(asctime)s %(levelname)s %(name)-40s :: %(message)s') meshsize_domain = 100 meshsize_codomain = 100 mesh = Make1DMesh(meshsize_domain) fes_domain = ngs.L2(mesh, order=2, dirichlet="left|right") domain = NgsSpace(fes_domain) mesh = Make1DMesh(meshsize_codomain) fes_codomain = ngs.H1(mesh, order=2, dirichlet="left|right") codomain = NgsSpace(fes_codomain) rhs = 10 * ngs.x**2 op = Coefficient(domain, codomain=codomain, rhs=rhs, bc_left=1, bc_right=1.1, diffusion=False, reaction=True)