Debian Codegraph @

python/test/unit/mesh/test_face.py

raw
1 """Unit tests for the Face class"""
2
3 # Copyright (C) 2011 Garth N. Wells
4 #
5 # This file is part of DOLFIN.
6 #
7 # DOLFIN is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Lesser General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # DOLFIN is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public License
18 # along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
19 #
20 # First added: 2011-02-26
21 # Last changed: 2014-05-30
22
23 import pytest
24 from dolfin import *
25 from dolfin_utils.test import skip_in_parallel, fixture
26
27
28 @fixture
29 def cube():
30 return UnitCubeMesh(5, 5, 5)
31
32
33 @fixture
34 def square():
35 return UnitSquareMesh(5, 5)
36
37
38 @skip_in_parallel
39 def test_Area(cube, square):
40 """Iterate over faces and sum area."""
41
42 area = 0.0
43 for f in faces(cube):
44 area += f.area()
45 assert round(area - 39.21320343559672494393, 7) == 0
46
47 area = 0.0
48 for f in faces(square):
49 area += f.area()
50 assert round(area - 1.0, 7) == 0
51
52
53 @skip_in_parallel
54 def test_NormalPoint(cube, square):
55 """Compute normal vector to each face."""
56 for f in faces(cube):
57 n = f.normal()
58 assert round(n.norm() - 1.0, 7) == 0
59
60 f = Face(square, 0)
61 with pytest.raises(RuntimeError):
62 f.normal()
63
64
65 @skip_in_parallel
66 def test_NormalComponent(cube, square):
67 """Compute normal vector components to each face."""
68 D = cube.topology().dim()
69 for f in faces(cube):
70 n = [f.normal(i) for i in range(D)]
71 norm = sum([x*x for x in n])
72 assert round(norm - 1.0, 7) == 0
73
74 f = Face(square, 0)
75 with pytest.raises(RuntimeError):
76 f.normal(0)