def initialize_meshes(self): m0 = MeshHex() m = MeshHex( np.array([[0., 0., 0.], [0., 0., 1.], [0., 1., 0.], [1., 0.7, 0.7], [0., 1., 1.], [1., 0., 1.], [1., 1., 0.], [1., 1., 1.]]).T, m0.t) return m
def runTest(self): m = MeshHex() # default mesh has all edges on the boundary self.assertTrue(len(m.boundary_edges()) == m.edges.shape[1]) # check that there is a correct amount of boundary edges: # 12 (cube edges) * 2 (per cube edge) # + 6 (cube faces) * 4 (per cube face) # = 48 edges self.assertEqual(len(m.refined().boundary_edges()), 48)
class ConvergenceHexS2(ConvergenceQ1): rateL2 = 3.05 rateH1 = 2.21 eps = 0.02 def create_basis(self, m): e = ElementHexS2() return InteriorBasis(m, e) def setUp(self): self.mesh = MeshHex() self.mesh.refine(1)
class ConvergenceHex1(ConvergenceQ1): rateL2 = 2.0 rateH1 = 1.0 eps = 0.11 def create_basis(self, m): e = ElementHex1() return InteriorBasis(m, e) def setUp(self): self.mesh = MeshHex() self.mesh.refine(2)
def runTest(self): # Mesh.remove_elements m = MeshTri() m.refine() M = m.remove_elements(np.array([0])) self.assertEqual(M.t.shape[1], 7) # Mesh.define_boundary m.define_boundary('foo', lambda x: x[0] == 0.) self.assertEqual(m.boundaries['foo'].size, 2) # Mesh.define_boundary (internal) m.define_boundary('bar', lambda x: x[0] == 1. / 2, boundaries_only=False) self.assertEqual(m.boundaries['bar'].size, 2) # Mesh.scale, Mesh.translate m = MeshHex() m.scale(0.5) m.translate((0.5, 0.5, 0.5)) self.assertGreater(np.min(m.p), 0.4999) # Mesh3D.facets_satisfying self.assertEqual(len(m.facets_satisfying(lambda x: x[0] == 0.5)), 1)
def runTest(self): # Mesh.remove m = MeshTri().refined() M = m.remove_elements(np.array([0])) self.assertEqual(M.t.shape[1], 7) # boundaries M = m.with_boundaries({ 'foo': lambda x: x[0] == 0., }) self.assertEqual(M.boundaries['foo'].size, 2) m = MeshHex().scaled(0.5).translated((0.5, 0.5, 0.5)) self.assertGreater(np.min(m.p), 0.4999) # Mesh3D.facets_satisfying self.assertEqual(len(m.facets_satisfying(lambda x: x[0] == 0.5)), 1)
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.)
class NormalVectorTestQuad(NormalVectorTestTri): case = (MeshQuad(), ElementQuad1()) class NormalVectorTestQuadP(NormalVectorTestTri): case = (MeshQuad(), ElementQuadP(3)) test_integrate_volume = False class NormalVectorTestHex(NormalVectorTestTri): case = (MeshHex(), ElementHex1()) intorder = 3 class NormalVectorTestHexS2(NormalVectorTestTri): case = (MeshHex(), ElementHexS2()) intorder = 3 test_integrate_volume = False class NormalVectorTestHex2(NormalVectorTestTri): case = (MeshHex(), ElementHex2()) intorder = 3 test_integrate_volume = False
( MeshTri().refined(2), MeshTri1DG, ElementTriP2, lambda x: x[0] == 0, lambda x: x[0] == 1, ), ( MeshTri().refined(2), MeshTri1DG, ElementTriP2, lambda x: x[1] == 0, lambda x: x[1] == 1, ), ( MeshHex().refined(4), MeshHex1DG, ElementHex1, lambda x: x[1] == 0, lambda x: x[1] == 1, ), ( MeshHex().refined(3), MeshHex1DG, ElementHex2, lambda x: x[2] == 0, lambda x: x[2] == 1, ), ]) def test_periodic_mesh_assembly(m, mdgtype, etype, check1, check2): def _sort(ix):
def setUp(self): self.mesh = MeshHex().refined(1)
def setUp(self): self.mesh = MeshHex().refined(2).to_meshtet()
Functional(lambda w: dot(w.fun.grad, w.n)).assemble(fb, fun=fun(m)), 1.0, ) @pytest.mark.parametrize( "m, e, facets, normal", [ ( MeshTri().refined(2) + MeshTri().translated((1.0, 0.0)).refined(2), ElementTriP1(), lambda x: x[0] == 1.0, np.array([1, 0]), ), ( MeshHex().refined(2) + MeshHex().translated((1., 0., 0.)).refined(2), ElementHex1(), lambda x: x[0] == 1.0, np.array([1, 0, 0]), ), ] ) def test_oriented_interface_integral2(m, e, facets, normal): fb = FacetBasis(m, e, facets=m.facets_satisfying(facets, normal=normal)) assert_almost_equal( Functional(lambda w: dot(w.fun.grad, w.n)).assemble(fb, fun=m.p[0]), 1.0, )
element = ElementQuadBFS() with self.assertRaises(ValueError): element.gdof(0, 0, -1) with self.assertRaises(ValueError): element.gdof(0, 0, 16) @pytest.mark.parametrize("m,e,edg", [ (MeshTri().refined(), ElementTriP1(), ElementTriDG), (MeshTri().refined(), ElementTriP2(), ElementTriDG), (MeshTet().refined(), ElementTetP1(), ElementTetDG), (MeshTet().refined(), ElementTetP2(), ElementTetDG), (MeshTri().refined(), ElementTriArgyris(), ElementTriDG), (MeshTri().refined(), ElementTriMorley(), ElementTriDG), (MeshTri().refined(), ElementTriHermite(), ElementTriDG), (MeshHex().refined(), ElementHex1(), ElementHexDG), (MeshQuad().refined(), ElementQuad1(), ElementQuadDG), ]) def test_dg_element(m, e, edg): edg = edg(e) @Functional def square(w): return w['random']**2 basis = InteriorBasis(m, e) basisdg = InteriorBasis(m, edg) assert_allclose( square.assemble(basis, random=basis.interpolate(basis.zeros() + 1)),
class TestFinder1DLinspaced(TestCase): 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) @pytest.mark.parametrize("m", [ MeshTri.init_circle(), MeshQuad.init_tensor([0, 1, 3], [0, 1, 3]), MeshTet().refined(3), MeshHex.init_tensor([0, 1, 3], [0, 1, 3], [0, 1, 3]), ]) def test_smoothed(m): M = m.smoothed() assert M.is_valid() # points have moved? assert np.linalg.norm((M.p - m.p)**2) > 0 @pytest.mark.parametrize("m", [ MeshTri(), MeshTet(), ]) def test_oriented(m): M = m.oriented() assert np.sum(m.orientation() < 0) > 0
def setUp(self): self.mesh = MeshHex() self.mesh.refine(1)
def createBasis(self): m = MeshHex().refined(3) self.fbasis = FacetBasis(m, ElementHex2()) self.boundary_area = 6.000
class NormalVectorTestQuad(NormalVectorTestTri): case = (MeshQuad(), ElementQuad1()) class NormalVectorTestQuadP(NormalVectorTestTri): case = (MeshQuad(), ElementQuadP(3)) test_integrate_volume = False class NormalVectorTestHex(NormalVectorTestTri): case = (MeshHex(), ElementHex1()) intorder = 3 class NormalVectorTestHexS2(NormalVectorTestTri): case = (MeshHex(), ElementHexS2()) intorder = 3 test_integrate_volume = False class NormalVectorTestHex2(NormalVectorTestTri): case = (MeshHex(), ElementHex2()) intorder = 3 test_integrate_volume = False