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() for itr in range(10): prev_t_size = m.t.shape[1] prev_p_size = m.p.shape[1] m = m.refined([prev_t_size - 1]) # check that new size is current size + 1 self.assertEqual(prev_t_size, m.t.shape[1] - 1) self.assertEqual(prev_p_size, m.p.shape[1] - 1)
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.)).refined(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 test_periodic_failure(): # these meshes cannot be made periodic due to insufficient number of # elements with pytest.raises(ValueError): mp = MeshLine1DG.periodic(MeshLine(), [0], [1]) with pytest.raises(ValueError): mp = MeshQuad1DG.periodic(MeshQuad(), [0], [1]) with pytest.raises(ValueError): mp = MeshQuad1DG.periodic(MeshQuad().refined(2), [0], [1, 2])
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)
def runTest(self): m = MeshLine(np.linspace(0., 1.)).refined(2).with_boundaries({ 'left': lambda x: x[0] == 0.0, 'right': lambda x: x[0] == 1.0, }) ib = Basis(m, self.e) 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.get_dofs('left') 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)
MeshQuad().refined(2), MeshQuad1DG, ElementQuad1(), ), ( MeshQuad().refined(2), MeshQuad1DG, ElementQuad2(), ), ( MeshTri().refined(2), MeshTri1DG, ElementTriP2(), ), ( MeshLine().refined(5), MeshLine1DG, ElementLineP1(), ), ( MeshHex().refined(3), MeshHex1DG, ElementHex1(), ), ( MeshLine().refined(), MeshLine1DG, ElementLinePp(5), ), ]) def test_periodic_loading(m, mdgtype, e):
def runTest(self): for itr in range(5): finder = MeshLine().refined(itr).element_finder() self.assertEqual(finder(np.array([0.001]))[0], 0) self.assertEqual(finder(np.array([0.999]))[0], 2**itr - 1)
def setUp(self): self.mesh = MeshLine().refined(3)
def do_refined(self, m, itr): return (MeshLine(np.linspace(0, 1, 2**(itr + 2))) * MeshTri().refined(itr + 2))
def setUp(self): self.mesh = MeshLine() self.mesh.refine(3)
assert_array_equal( tri.find_simplex(query_pts.T), finder(*query_pts), ) @pytest.mark.parametrize("m", [ MeshTri(), MeshQuad(), MeshTet(), MeshHex(), MeshTri2(), MeshQuad2(), MeshTet2(), MeshHex2(), MeshLine(), ]) def test_meshio_cycle(m): M = from_meshio(to_meshio(m)) assert_array_equal(M.p, m.p) assert_array_equal(M.t, m.t) if m.boundaries is not None: np.testing.assert_equal(m.boundaries, M.boundaries) if m.subdomains is not None: np.testing.assert_equal(m.subdomains, M.subdomains) _test_lambda = { 'left': lambda x: x[0] < 0.6, 'right': lambda x: x[0] > 0.3,
def runTest(self): for itr in range(5): finder = (MeshLine(np.linspace(0, 1, 2**itr + 1)).element_finder()) self.assertEqual(finder(np.array([0.999]))[0], 2**itr - 1) self.assertEqual(finder(np.array([0.001]))[0], 0)