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.find_dofs())) exact = np.stack([(1 - source) * mesh.p, (1 - mesh.p) * source]).min(0) assert_almost_equal(u[basis.nodal_dofs], exact)
def runTest(self): """Solve Stokes problem, try splitting and other small things.""" m = MeshTri().refined() m = m.refined(3).with_boundaries({ 'up': lambda x: x[1] == 1., 'rest': lambda x: x[1] != 1., }) e = ElementVectorH1(ElementTriP2()) * ElementTriP1() basis = CellBasis(m, e) @BilinearForm def bilinf(u, p, v, q, w): from skfem.helpers import grad, ddot, div return (ddot(grad(u), grad(v)) - div(u) * q - div(v) * p - 1e-2 * p * q) S = asm(bilinf, basis) D = basis.find_dofs(skip=['u^2']) x = basis.zeros() x[D['up'].all('u^1^1')] = .1 x = solve(*condense(S, x=x, D=D)) (u, u_basis), (p, p_basis) = basis.split(x) self.assertEqual(len(u), m.p.shape[1] * 2 + m.facets.shape[1] * 2) self.assertEqual(len(p), m.p.shape[1]) self.assertTrue(np.sum(p - x[basis.nodal_dofs[2]]) < 1e-8) U, P = basis.interpolate(x) self.assertTrue(isinstance(U.value, np.ndarray)) self.assertTrue(isinstance(P.value, np.ndarray)) self.assertTrue(P.shape[0] == m.nelements) self.assertTrue((basis.doflocs[:, D['up'].all()][1] == 1.).all()) # test blocks splitting of forms while at it C1 = asm(bilinf.block(1, 1), CellBasis(m, ElementTriP1())) C2 = S[basis.nodal_dofs[-1]].T[basis.nodal_dofs[-1]].T self.assertTrue(abs((C1 - C2).min()) < 1e-10) self.assertTrue(abs((C1 - C2).max()) < 1e-10) # test splitting ElementVector (ux, uxbasis), (uy, uybasis) = u_basis.split(u) assert_allclose(ux[uxbasis.nodal_dofs[0]], u[u_basis.nodal_dofs[0]]) assert_allclose(ux[uxbasis.facet_dofs[0]], u[u_basis.facet_dofs[0]]) assert_allclose(uy[uybasis.nodal_dofs[0]], u[u_basis.nodal_dofs[1]]) assert_allclose(uy[uybasis.facet_dofs[0]], u[u_basis.facet_dofs[1]])
def runTest(self): m = self.mesh_type().refined(2) basis = CellBasis(m, self.elem_type()) for fun in [ lambda x: x[0] == 0, lambda x: x[0] == 1, lambda x: x[1] == 0, lambda x: x[1] == 1, lambda x: x[2] == 0, lambda x: x[2] == 1 ]: arr1 = basis.find_dofs({'kek': m.facets_satisfying(fun)})['kek'].edge['u'] arr2 = basis.edge_dofs[:, m.edges_satisfying(fun)] assert_allclose(arr1, arr2.flatten())
def runTest(self): """Solve Stokes problem, try splitting and other small things.""" m = MeshTri().refined() m = m.refined(3).with_boundaries({ 'up': lambda x: x[1] == 1., 'rest': lambda x: x[1] != 1., }) e = ElementVectorH1(ElementTriP2()) * ElementTriP1() basis = CellBasis(m, e) @BilinearForm def bilinf(u, p, v, q, w): from skfem.helpers import grad, ddot, div return (ddot(grad(u), grad(v)) - div(u) * q - div(v) * p - 1e-2 * p * q) S = asm(bilinf, basis) D = basis.find_dofs(skip=['u^2']) x = basis.zeros() x[D['up'].all('u^1^1')] = .1 x = solve(*condense(S, x=x, D=D)) (u, u_basis), (p, p_basis) = basis.split(x) self.assertEqual(len(u), m.p.shape[1] * 2 + m.facets.shape[1] * 2) self.assertEqual(len(p), m.p.shape[1]) self.assertTrue(np.sum(p - x[basis.nodal_dofs[2]]) < 1e-8) U, P = basis.interpolate(x) self.assertTrue(isinstance(U.value, np.ndarray)) self.assertTrue(isinstance(P.value, np.ndarray)) self.assertTrue((basis.doflocs[:, D['up'].all()][1] == 1.).all())