Skip to content

Commit

Permalink
#95: Test mass lumping
Browse files Browse the repository at this point in the history
  • Loading branch information
jwallwork23 committed Apr 27, 2024
1 parent 79f709e commit 08b732e
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions test/test_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,21 @@ class TestMassMatrix(unittest.TestCase):
"""

@staticmethod
def assemble_mass_matrix(space, norm_type, mixed):
def assemble_mass_matrix(space, norm_type, mixed, lumped=False):
if mixed:
return assemble_mixed_mass_matrix(space, space, norm_type=norm_type)
return assemble_mixed_mass_matrix(
space, space, norm_type=norm_type, lumped=lumped
)
else:
return assemble_mass_matrix(space, norm_type=norm_type)
return assemble_mass_matrix(space, norm_type=norm_type, lumped=lumped)

@parameterized.expand([("L2", False), ("L2", True), ("H1", False)])
def test_tiny(self, norm_type, mixed):
mesh = uniform_mesh(2, 1)
V = FunctionSpace(mesh, "DG", 0)
M = self.assemble_mass_matrix(V, norm_type, mixed)
matrix = self.assemble_mass_matrix(V, norm_type, mixed)
expected = np.array([[0.5, 0], [0, 0.5]])
got = M.convert("dense").getDenseArray()
got = matrix.convert("dense").getDenseArray()
self.assertTrue(np.allclose(expected, got))

def test_norm_type_error(self):
Expand All @@ -100,6 +102,16 @@ def test_norm_type_error_mixed(self):
msg = "Mixed matrices are only supported in the L2 norm."
self.assertEqual(str(cm.exception), msg)

@parameterized.expand([(True,), (False,)])
def test_lumping(self, mixed):
mesh = UnitTriangleMesh()
fs = FunctionSpace(mesh, "CG", 1)
matrix = self.assemble_mass_matrix(fs, "L2", mixed, lumped=True)
self.assertEqual(matrix.type, "diagonal")
expected = np.eye(3) / 6
got = matrix.convert("dense").getDenseArray()
self.assertTrue(np.allclose(expected, got))


class TestNorm(unittest.TestCase):
"""
Expand Down

0 comments on commit 08b732e

Please sign in to comment.