def test_subdomain_facet_assembly(): def subdomain(x): return np.logical_and( np.logical_and(x[0] > .25, x[0] < .75), np.logical_and(x[1] > .25, x[1] < .75), ) m, e = MeshTri().refined(4), ElementTriP2() cbasis = CellBasis(m, e) cbasis_p0 = cbasis.with_element(ElementTriP0()) sfbasis = FacetBasis(m, e, facets=m.facets_around(subdomain, flip=True)) sfbasis_p0 = sfbasis.with_element(ElementTriP0()) sigma = cbasis_p0.zeros() + 1 @BilinearForm def laplace(u, v, w): return dot(w.sigma * grad(u), grad(v)) A = laplace.assemble(cbasis, sigma=cbasis_p0.interpolate(sigma)) u0 = cbasis.zeros() u0[cbasis.get_dofs(elements=subdomain)] = 1 u0_dofs = cbasis.get_dofs() + cbasis.get_dofs(elements=subdomain) A, b = enforce(A, D=u0_dofs, x=u0) u = solve(A, b) @Functional def measure_current(w): return dot(w.n, w.sigma * grad(w.u)) meas = measure_current.assemble(sfbasis, sigma=sfbasis_p0.interpolate(sigma), u=sfbasis.interpolate(u)) assert_almost_equal(meas, 9.751915526759191)
def test_point_source(etype): mesh = MeshLine1().refined() basis = CellBasis(mesh, etype()) source = np.array([0.7]) u = solve(*condense(asm(laplace, basis), basis.point_source(source), D=basis.get_dofs())) exact = np.stack([(1 - source) * mesh.p, (1 - mesh.p) * source]).min(0) assert_almost_equal(u[basis.nodal_dofs], exact)