~ubuntu-branches/ubuntu/wily/dolfin/wily-proposed

« back to all changes in this revision

Viewing changes to test/unit/geometry/python/CollisionDetection.py

  • Committer: Package Import Robot
  • Author(s): Johannes Ring
  • Date: 2015-03-17 07:57:11 UTC
  • mfrom: (1.1.18) (19.1.24 experimental)
  • Revision ID: package-import@ubuntu.com-20150317075711-1v207zbty9qmygow
Tags: 1.5.0-1
* New upstream release (closes: #780359).
* debian/control:
  - Bump Standards-Version to 3.9.6 (no changes needed).
  - Bump X-Python-Version to >= 2.7.
  - Update package names for new SONAME 1.5 (libdolfin1.4 ->
    libdolfin1.5, libdolfin1.4-dbg -> libdolfin1.5-dbg and
    libdolfin1.4-dev -> libdolfin1.5-dev).
  - Bump minimum required version for python-instant, python-ufl and
    python-ffc to 1.5.0.
  - Add python-sympy and python-six to Depends for binary package
    python-dolfin.
  - Add dh-python to Build-Depends.
  - Remove libcgal-dev from {Build-}Depends.
* Remove CSGCGALMeshGenerator3D-oom.patch since CGAL is no longer used
  by DOLFIN.
* Move debian/libdolfin1.4.install -> debian/libdolfin1.5.install.
* debian/rules: No longer any non DFSG-free stuff to remove, so update
  get-orig-source target (update debian/watch accordingly).
* Update debian/copyright and debian/copyright_hints.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""Unit tests for the CollisionDetection class"""
2
 
 
3
 
# Copyright (C) 2014 Anders Logg and August Johansson
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:  2014-02-16
21
 
# Last changed: 2014-05-30
22
 
 
23
 
import unittest
24
 
from dolfin import *
25
 
 
26
 
def create_triangular_mesh_3D():
27
 
    editor = MeshEditor()
28
 
    mesh = Mesh()
29
 
    editor.open(mesh,2,3)
30
 
    editor.init_cells(2)
31
 
    editor.init_vertices(4)
32
 
    editor.add_cell(0, 0,1,2)
33
 
    editor.add_cell(1, 1,2,3)
34
 
    editor.add_vertex(0, 0,0,0.5)
35
 
    editor.add_vertex(1, 1,0,0.5)
36
 
    editor.add_vertex(2, 0,1,0.5)
37
 
    editor.add_vertex(3, 1,1,0.5)
38
 
    editor.close()
39
 
    return mesh;
40
 
 
41
 
@unittest.skipIf(MPI.size(mpi_comm_world()) > 1, "Skipping unit test(s) not working in parallel")
42
 
class IntervalTest(unittest.TestCase):
43
 
    "Test class for collision with interval"
44
 
 
45
 
    def test_collides_point(self):
46
 
 
47
 
        mesh = UnitIntervalMesh(1)
48
 
        cell = Cell(mesh, 0)
49
 
 
50
 
        self.assertEqual(cell.collides(Point(0.5)), True)
51
 
        self.assertEqual(cell.collides(Point(1.5)), False)
52
 
 
53
 
@unittest.skipIf(MPI.size(mpi_comm_world()) > 1, "Skipping unit test(s) not working in parallel")
54
 
class TriangleTest(unittest.TestCase):
55
 
    "Test class for collision with triangle"
56
 
 
57
 
    def test_collides_point(self):
58
 
 
59
 
        mesh = UnitSquareMesh(1, 1)
60
 
        cell = Cell(mesh, 0)
61
 
 
62
 
        self.assertEqual(cell.collides(Point(0.5)), True)
63
 
        self.assertEqual(cell.collides(Point(1.5)), False)
64
 
 
65
 
    def test_collides_triangle(self):
66
 
 
67
 
        m0 = UnitSquareMesh(8, 8)
68
 
        c0 = Cell(m0, 0)
69
 
 
70
 
        m1 = UnitSquareMesh(8, 8)
71
 
        m1.translate(Point(0.1, 0.1))
72
 
        c1 = Cell(m1, 0)
73
 
        c2 = Cell(m1, 1)
74
 
 
75
 
        self.assertEqual(c0.collides(c0), True)
76
 
        self.assertEqual(c0.collides(c1), True)
77
 
        # self.assertEqual(c0.collides(c2), False) # touching edges
78
 
        self.assertEqual(c1.collides(c0), True)
79
 
        self.assertEqual(c1.collides(c1), True)
80
 
        self.assertEqual(c1.collides(c2), False)
81
 
        # self.assertEqual(c2.collides(c0), False) # touching edges
82
 
        self.assertEqual(c2.collides(c1), False)
83
 
        self.assertEqual(c2.collides(c2), True)
84
 
 
85
 
@unittest.skipIf(MPI.size(mpi_comm_world()) > 1, "Skipping unit test(s) not working in parallel")
86
 
class TetrahedronTest(unittest.TestCase):
87
 
    "Test class for collision with tetrahedron"
88
 
 
89
 
    def test_collides_point(self):
90
 
 
91
 
        mesh = UnitCubeMesh(1, 1, 1)
92
 
        cell = Cell(mesh, 0)
93
 
 
94
 
        self.assertEqual(cell.collides(Point(0.5)), True)
95
 
        self.assertEqual(cell.collides(Point(1.5)), False)
96
 
 
97
 
    def test_collides_triangle(self):
98
 
 
99
 
        tetmesh = UnitCubeMesh(2, 2, 2)
100
 
        trimesh = create_triangular_mesh_3D()
101
 
        dx = Point(0.1, 0.1, -0.1)
102
 
        trimesh_shift = create_triangular_mesh_3D()
103
 
        trimesh_shift.translate(dx)
104
 
 
105
 
        tet0 = Cell(tetmesh, 18)
106
 
        tet1 = Cell(tetmesh, 19)
107
 
        tri0 = Cell(trimesh, 1)
108
 
        tri0shift = Cell(trimesh_shift, 1)
109
 
 
110
 
        # proper intersection
111
 
        self.assertEqual(tet0.collides(tri0shift), True)
112
 
        self.assertEqual(tri0shift.collides(tet0), True)
113
 
        self.assertEqual(tet1.collides(tri0shift), True)
114
 
        self.assertEqual(tri0shift.collides(tet1), True)
115
 
 
116
 
        # point touch
117
 
        self.assertEqual(tet0.collides(tri0), True)
118
 
        self.assertEqual(tri0.collides(tet0), True)
119
 
 
120
 
        # face alignment (true or false)
121
 
        self.assertEqual(tet1.collides(tri0), True)
122
 
        self.assertEqual(tri0.collides(tet1), True)
123
 
 
124
 
    def test_collides_tetrahedron(self):
125
 
 
126
 
        m0 = UnitCubeMesh(2, 2, 2)
127
 
        c19 = Cell(m0, 19)
128
 
        c26 = Cell(m0, 26)
129
 
        c37 = Cell(m0, 37)
130
 
        c43 = Cell(m0, 43)
131
 
        c45 = Cell(m0, 45)
132
 
 
133
 
        m1 = UnitCubeMesh(1,1,1)
134
 
        m1.translate(Point(0.5, 0.5, 0.5))
135
 
        c3 = Cell(m0, 3)
136
 
        c5 = Cell(m1, 5)
137
 
 
138
 
        # self collisions
139
 
        self.assertEqual(c3.collides(c3), True)
140
 
        self.assertEqual(c45.collides(c45), True)
141
 
 
142
 
        # standard collisions
143
 
        self.assertEqual(c3.collides(c37), True)
144
 
        self.assertEqual(c37.collides(c3), True)
145
 
 
146
 
        # edge face
147
 
        self.assertEqual(c5.collides(c45), True)
148
 
        self.assertEqual(c45.collides(c5), True)
149
 
 
150
 
        # touching edges
151
 
        self.assertEqual(c5.collides(c19), False)
152
 
        self.assertEqual(c19.collides(c5), False)
153
 
 
154
 
        # touching faces
155
 
        self.assertEqual(c3.collides(c43), True)
156
 
        self.assertEqual(c43.collides(c3), True)
157
 
 
158
 
if __name__ == "__main__":
159
 
        unittest.main()