-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Monge-Ampere zoom plot and tangling exercise (#65)
Closes #50. Partly addresses #19. This PR adds a zoom plot to the first Monge-Ampere demo to show that the elements aren't tangled, as well as an exercise to check this with `MeshTanglingChecker`. The PR also applies some minor refactoring to `MeshTanglingChecker`, as well as writing unit tests for it.
- Loading branch information
1 parent
25cf058
commit c6b51c1
Showing
3 changed files
with
68 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,34 @@ | ||
from firedrake import * | ||
from movement import * | ||
import unittest | ||
|
||
|
||
def test_tangling_checker(): | ||
class TestTangling(unittest.TestCase): | ||
""" | ||
Test that :class:`MeshTanglingChecker` | ||
can correctly identify tangled elements | ||
in a 2D triangular mesh. | ||
Unit tests for mesh tangling checking. | ||
""" | ||
mesh = UnitSquareMesh(3, 3) | ||
checker = MeshTanglingChecker(mesh) | ||
assert checker.check() == 0 | ||
mesh.coordinates.dat.data[3] += 0.2 | ||
assert checker.check() == 1 | ||
|
||
def test_tangling_checker_error1(self): | ||
mesh = UnitSquareMesh(3, 3) | ||
checker = MeshTanglingChecker(mesh, raise_error=True) | ||
mesh.coordinates.dat.data[3] += 0.2 | ||
with self.assertRaises(ValueError) as cm: | ||
checker.check() | ||
msg = "Mesh has 1 tangled element." | ||
self.assertEqual(str(cm.exception), msg) | ||
|
||
def test_tangling_checker_error2(self): | ||
mesh = UnitSquareMesh(3, 3) | ||
checker = MeshTanglingChecker(mesh, raise_error=True) | ||
mesh.coordinates.dat.data[3] += 0.5 | ||
with self.assertRaises(ValueError) as cm: | ||
checker.check() | ||
msg = "Mesh has 3 tangled elements." | ||
self.assertEqual(str(cm.exception), msg) | ||
|
||
def test_tangling_checker_warning1(self): | ||
mesh = UnitSquareMesh(3, 3) | ||
checker = MeshTanglingChecker(mesh, raise_error=False) | ||
self.assertEqual(checker.check(), 0) | ||
mesh.coordinates.dat.data[3] += 0.2 | ||
self.assertEqual(checker.check(), 1) |