def runTest(self): from skfem.element.element_composite import ElementComposite self.check_equivalence( ElementComposite(ElementTriP1(), ElementTriP1()), ElementVectorH1(ElementTriP1()) )
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): """Solve Stokes problem, try splitting and other small things.""" m = MeshTri() m.refine() m.define_boundary('centreline', lambda x: x[0] == .5, boundaries_only=False) m.refine(3) e = ElementVectorH1(ElementTriP2()) * ElementTriP1() m.define_boundary('up', lambda x: x[1] == 1.) m.define_boundary('rest', lambda x: x[1] != 1.) basis = InteriorBasis(m, e) self.assertEqual( basis.get_dofs(m.boundaries['centreline']).all().size, (2 + 1) * (2**(1 + 3) + 1) + 2 * 2**(1 + 3)) self.assertEqual(basis.find_dofs()['centreline'].all().size, (2 + 1) * (2**(1 + 3) + 1) + 2 * 2**(1 + 3)) @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, basis.zeros(), 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())
def runTest(self): m = MeshHex() # check that these assemble to the same matrix ec = ElementHex1() * ElementHex1() * ElementHex1() ev = ElementVectorH1(ElementHex1()) basisc = Basis(m, ec) basisv = Basis(m, ev) @BilinearForm def bilinf_ev(u, v, w): from skfem.helpers import dot return dot(u, v) @BilinearForm def bilinf_ec(ux, uy, uz, vx, vy, vz, w): return ux * vx + uy * vy + uz * vz Kv = asm(bilinf_ev, basisv) Kc = asm(bilinf_ec, basisc) self.assertAlmostEqual(np.sum(np.sum((Kv - Kc).todense())), 0.)
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())
def runTest(self): self.check_equivalence(ElementTriP1() * ElementTriP1(), ElementVectorH1(ElementTriP1()))