Debian Codegraph @

python/test/unit/geometry/test_intersection.py

raw
1 """Unit tests for intersection computation"""
2
3 # Copyright (C) 2013-2014 Anders Logg
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 import pytest
21
22 from dolfin import intersect
23 from dolfin import (UnitIntervalMesh, UnitSquareMesh, UnitCubeMesh, BoxMesh, CellType)
24 from dolfin import Point, FunctionSpace, Expression, interpolate
25 from dolfin import MPI
26
27 from dolfin_utils.test import skip_in_parallel
28
29 @skip_in_parallel
30 def test_mesh_point_1d():
31 "Test mesh-point intersection in 1D"
32
33 point = Point(0.1)
34 mesh = UnitIntervalMesh(16)
35
36 intersection = intersect(mesh, point)
37
38 assert intersection.intersected_cells() == [1]
39
40 @skip_in_parallel
41 def test_mesh_point_2d_triangle():
42 "Test mesh-point intersection in 2D for triangular mesh"
43
44 point = Point(0.1, 0.2)
45 mesh = UnitSquareMesh(16, 16)
46
47 intersection = intersect(mesh, point)
48
49 assert intersection.intersected_cells() == [98]
50
51 @skip_in_parallel
52 def test_mesh_point_3d_tetrahedron():
53 "Test mesh-point intersection in 3D for tetrahedral mesh"
54
55 point = Point(0.1, 0.2, 0.3)
56 mesh = UnitCubeMesh(8, 8, 8)
57
58 intersection = intersect(mesh, point)
59
60 assert intersection.intersected_cells() == [816]
61
62 @skip_in_parallel
63 @pytest.mark.xfail(strict=True, raises=RuntimeError)
64 def test_mesh_point_2d_quadrilateral():
65 "Test mesh-point intersection in 2D for quadrilateral mesh"
66
67 point = Point(0.1, 0.2)
68 mesh = UnitSquareMesh.create(16, 16, CellType.Type.quadrilateral)
69
70 intersection = intersect(mesh, point)
71
72 assert intersection.intersected_cells() == [49]
73
74 @skip_in_parallel
75 @pytest.mark.xfail(strict=True, raises=RuntimeError)
76 def test_mesh_point_3d_hexahedron():
77 "Test mesh-point intersection in 3D for hexahedral mesh"
78
79 point = Point(0.1, 0.2, 0.3)
80 mesh = UnitCubeMesh.create(8, 8, 8, CellType.Type.hexahedron)
81
82 intersection = intersect(mesh, point)
83
84 # Returns [] now, but [136] is the correct cell.
85 assert intersection.intersected_cells() == [136]