class ConvergenceLineP1(ConvergenceQ1): def create_basis(self, m): e = ElementLineP1() return InteriorBasis(m, e) def setUp(self): self.mesh = MeshLine() self.mesh.refine(3)
class ConvergenceLineP2(ConvergenceQ1): rateL2 = 3.0 rateH1 = 2.0 def create_basis(self, m): e = ElementLineP2() return InteriorBasis(m, e) def setUp(self): self.mesh = MeshLine() self.mesh.refine(3)
def runTest(self): m = MeshLine(np.linspace(0., 1.)) m.refine(2) ib = InteriorBasis(m, self.e) fb = FacetBasis(m, self.e) @LinearForm def boundary_flux(v, w): return v * (w.x[0] == 1) - v * (w.x[0] == 0) L = asm(laplace, ib) M = asm(mass, ib) b = asm(boundary_flux, fb) u = solve(L + 1e-6 * M, b) np.testing.assert_array_almost_equal(u[ib.nodal_dofs[0]], m.p[0] - .5, -4)
def runTest(self): m = MeshLine(np.linspace(0., 1.)) m.refine(2) ib = InteriorBasis(m, self.e) fb = FacetBasis(m, self.e) @LinearForm def boundary_flux(v, w): return v * (w.x[0] == 1.) L = asm(laplace, ib) b = asm(boundary_flux, fb) D = m.nodes_satisfying(lambda x: x == 0.0) I = ib.complement_dofs(D) # noqa E741 u = solve(*condense(L, b, I=I)) # noqa E741 np.testing.assert_array_almost_equal(u[ib.nodal_dofs[0]], m.p[0], -10)
def runTest(self): m = MeshLine(np.linspace(0., 1.)) m.refine(2) e = ElementLineP1() ib = InteriorBasis(m, e) fb = FacetBasis(m, e) @linear_form def boundary_flux(v, dv, w): return v * (w.x[0] == 1) - v * (w.x[0] == 0) L = asm(laplace, ib) M = asm(mass, ib) b = asm(boundary_flux, fb) u = solve(L + 1e-6 * M, b) self.assertTrue(np.sum(np.abs(u - m.p[0, :] + 0.5)) < 1e-4)
def runTest(self): m = MeshLine(np.linspace(0., 1.)) m.refine(2) e = ElementLineP1() ib = InteriorBasis(m, e) fb = FacetBasis(m, e) @linear_form def boundary_flux(v, dv, w): return -v * (w.x[0] == 1.) L = asm(laplace, ib) b = asm(boundary_flux, fb) D = m.nodes_satisfying(lambda x: x == 0.0) I = ib.complement_dofs(D) # noqa E741 u = solve(*condense(L, b, I=I)) # noqa E741 self.assertTrue(np.sum(np.abs(u + m.p[0, :])) < 1e-10)
def runTest(self): m = MeshLine(np.linspace(0., 1.)) m.refine(2) ib = InteriorBasis(m, self.e) m.define_boundary('left' ,lambda x: x[0] == 0.0) m.define_boundary('right', lambda x: x[0] == 1.0) fb = FacetBasis(m, self.e, facets=m.boundaries['right']) @LinearForm def boundary_flux(v, w): return -w.x[0] * v L = asm(laplace, ib) b = asm(boundary_flux, fb) D = ib.find_dofs()['left'].all() I = ib.complement_dofs(D) # noqa E741 u = solve(*condense(L, b, I=I)) # noqa E741 np.testing.assert_array_almost_equal(u[ib.nodal_dofs[0]], -m.p[0], -10)