~corrado-maurini/dolfin/tao

« back to all changes in this revision

Viewing changes to test/unit/mesh/python/Mesh.py

  • Committer: corrado maurini
  • Date: 2012-12-18 12:16:08 UTC
  • mfrom: (6685.78.207 trunk)
  • Revision ID: corrado.maurini@upmc.fr-20121218121608-nk82ly9jgsld9u84
updating with trunk, fix uint in TAO solver and hacking the check for tao FindTAO.cmake

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# You should have received a copy of the GNU Lesser General Public License
18
18
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
19
19
#
 
20
# Modified by Benjamin Kehlet 2012
 
21
#
20
22
# First added:  2006-08-08
21
 
# Last changed: 2011-03-23
 
23
# Last changed: 2012-11-12
22
24
 
23
25
import unittest
24
26
import numpy
28
30
 
29
31
    def setUp(self):
30
32
        if MPI.num_processes() == 1:
31
 
            self.interval = UnitInterval(10)
32
 
        self.circle = UnitCircle(5)
33
 
        self.square = UnitSquare(5, 5)
34
 
        self.rectangle = Rectangle(0, 0, 2, 2, 5, 5)
35
 
        self.cube = UnitCube(3, 3, 3)
36
 
        self.sphere = UnitSphere(5)
37
 
        self.box = Box(0, 0, 0, 2, 2, 2, 2, 2, 5)
 
33
            self.interval = UnitIntervalMesh(10)
 
34
        self.circle = UnitCircleMesh(5)
 
35
        self.square = UnitSquareMesh(5, 5)
 
36
        self.rectangle = RectangleMesh(0, 0, 2, 2, 5, 5)
 
37
        self.cube = UnitCubeMesh(3, 3, 3)
 
38
        self.box = BoxMesh(0, 0, 0, 2, 2, 2, 2, 2, 5)
38
39
 
39
40
    def testUFLCell(self):
40
41
        import ufl
44
45
        self.assertEqual(ufl.triangle, self.square.ufl_cell())
45
46
        self.assertEqual(ufl.triangle, self.rectangle.ufl_cell())
46
47
        self.assertEqual(ufl.tetrahedron, self.cube.ufl_cell())
47
 
        self.assertEqual(ufl.tetrahedron, self.sphere.ufl_cell())
48
48
        self.assertEqual(ufl.tetrahedron, self.box.ufl_cell())
49
49
 
50
50
# FIXME: The following test breaks in parallel
51
51
if MPI.num_processes() == 1:
52
52
    class SimpleShapes(unittest.TestCase):
53
53
 
54
 
        def testUnitSquare(self):
 
54
        def testUnitSquareMesh(self):
55
55
            """Create mesh of unit square."""
56
 
            mesh = UnitSquare(5, 7)
 
56
            mesh = UnitSquareMesh(5, 7)
57
57
            self.assertEqual(mesh.num_vertices(), 48)
58
58
            self.assertEqual(mesh.num_cells(), 70)
59
59
 
60
 
        def testUnitCube(self):
 
60
        def testUnitCubeMesh(self):
61
61
            """Create mesh of unit cube."""
62
 
            mesh = UnitCube(5, 7, 9)
 
62
            mesh = UnitCubeMesh(5, 7, 9)
63
63
            self.assertEqual(mesh.num_vertices(), 480)
64
64
            self.assertEqual(mesh.num_cells(), 1890)
65
65
 
66
66
    class MeshRefinement(unittest.TestCase):
67
67
 
68
 
        def testRefineUnitSquare(self):
 
68
        def testRefineUnitSquareMesh(self):
69
69
            """Refine mesh of unit square."""
70
 
            mesh = UnitSquare(5, 7)
 
70
            mesh = UnitSquareMesh(5, 7)
71
71
            mesh = refine(mesh)
72
72
            self.assertEqual(mesh.num_vertices(), 165)
73
73
            self.assertEqual(mesh.num_cells(), 280)
74
74
 
75
 
        def testRefineUnitCube(self):
 
75
        def testRefineUnitCubeMesh(self):
76
76
            """Refine mesh of unit cube."""
77
 
            mesh = UnitCube(5, 7, 9)
 
77
            mesh = UnitCubeMesh(5, 7, 9)
78
78
            mesh = refine(mesh)
79
79
            self.assertEqual(mesh.num_vertices(), 3135)
80
80
            self.assertEqual(mesh.num_cells(), 15120)
83
83
 
84
84
        def testBoundaryComputation(self):
85
85
            """Compute boundary of mesh."""
86
 
            mesh = UnitCube(2, 2, 2)
 
86
            mesh = UnitCubeMesh(2, 2, 2)
87
87
            boundary = BoundaryMesh(mesh)
88
88
            self.assertEqual(boundary.num_vertices(), 26)
89
89
            self.assertEqual(boundary.num_cells(), 48)
90
90
 
91
91
        def testBoundaryBoundary(self):
92
92
            """Compute boundary of boundary."""
93
 
            mesh = UnitCube(2, 2, 2)
 
93
            mesh = UnitCubeMesh(2, 2, 2)
94
94
            b0 = BoundaryMesh(mesh)
95
95
            b1 = BoundaryMesh(b0)
96
96
            self.assertEqual(b1.num_vertices(), 0)
99
99
    class MeshFunctions(unittest.TestCase):
100
100
 
101
101
        def setUp(self):
102
 
            self.mesh = UnitSquare(3, 3)
 
102
            self.mesh = UnitSquareMesh(3, 3)
103
103
            self.f = MeshFunction('int', self.mesh, 0)
104
104
 
105
105
        def testAssign(self):
139
139
                return x[0] >= 0.5
140
140
            sd1 = AutoSubDomain(inside1)
141
141
            sd2 = AutoSubDomain(inside2)
142
 
            cf = CellFunction('uint', self.mesh)
 
142
            cf = CellFunction('size_t', self.mesh)
143
143
            cf.set_all(0)
144
144
            sd1.mark(cf, 1)
145
145
            sd2.mark(cf, 2)
155
155
 
156
156
        def testMeshXML2D(self):
157
157
            """Write and read 2D mesh to/from file"""
158
 
            mesh_out = UnitSquare(3, 3)
 
158
            mesh_out = UnitSquareMesh(3, 3)
159
159
            mesh_in  = Mesh()
160
160
            file = File("unitsquare.xml")
161
161
            file << mesh_out
164
164
 
165
165
        def testMeshXML3D(self):
166
166
            """Write and read 3D mesh to/from file"""
167
 
            mesh_out = UnitCube(3, 3, 3)
 
167
            mesh_out = UnitCubeMesh(3, 3, 3)
168
168
            mesh_in  = Mesh()
169
169
            file = File("unitcube.xml")
170
170
            file << mesh_out
173
173
 
174
174
        def testMeshFunction(self):
175
175
            """Write and read mesh function to/from file"""
176
 
            mesh = UnitSquare(1, 1)
 
176
            mesh = UnitSquareMesh(1, 1)
177
177
            f = MeshFunction('int', mesh, 0)
178
178
            f[0] = 2
179
179
            f[1] = 4
190
190
 
191
191
        def testGetGeometricalDimension(self):
192
192
            """Get geometrical dimension of mesh"""
193
 
            mesh = UnitSquare(5, 5)
 
193
            mesh = UnitSquareMesh(5, 5)
194
194
            self.assertEqual(mesh.geometry().dim(), 2)
195
195
 
196
196
        def testGetCoordinates(self):
197
197
            """Get coordinates of vertices"""
198
 
            mesh = UnitSquare(5, 5)
 
198
            mesh = UnitSquareMesh(5, 5)
199
199
            self.assertEqual(len(mesh.coordinates()), 36)
200
200
 
201
201
        def testGetCells(self):
202
202
            """Get cells of mesh"""
203
 
            mesh = UnitSquare(5, 5)
 
203
            mesh = UnitSquareMesh(5, 5)
204
204
            self.assertEqual(len(mesh.cells()), 50)
205
205
 
206
206
    class IntersectionOperator(unittest.TestCase):
207
207
        def testIntersectPoint(self):
208
208
            from numpy import linspace
209
 
            mesh = UnitSquare(10, 10)
 
209
            mesh = UnitSquareMesh(10, 10)
210
210
            points = [Point(i+.05,.05) for i in linspace(-.4,1.4,19)]
211
211
            for p in points:
212
212
                if p.x()<0 or p.x()>1:
216
216
 
217
217
        def testIntersectPoints(self):
218
218
            from numpy import linspace
219
 
            mesh = UnitSquare(10, 10)
 
219
            mesh = UnitSquareMesh(10, 10)
220
220
            points = [Point(i+.05,.05) for i in linspace(-.4,1.4,19)]
221
221
            all_intersected_entities = []
222
222
            for p in points:
234
234
        def testIntersectedCellWithSingleCellMesh(self):
235
235
 
236
236
            # 2D
237
 
            mesh = UnitTriangle()
 
237
            mesh = UnitTriangleMesh()
238
238
 
239
239
            # Point Intersection
240
240
            point = Point(0.3, 0.3)
257
257
            self.assertEqual(len(cells), 0)
258
258
 
259
259
            # 3D
260
 
            mesh = UnitTetrahedron()
 
260
            mesh = UnitTetrahedronMesh()
261
261
 
262
262
            # Point intersection
263
263
            point = Point(0.3, 0.3, 0.3)
280
280
            self.assertEqual(len(cells), 0)
281
281
 
282
282
        def testClosestCellWithSingleCellMesh(self):
283
 
            mesh = UnitTriangle()
 
283
            mesh = UnitTriangleMesh()
284
284
 
285
285
            point = Point(0.3, 0.3)
286
286
            id = mesh.closest_cell(point)
290
290
            id = mesh.closest_cell(point)
291
291
            self.assertEqual(id, 0)
292
292
 
293
 
            mesh = UnitTetrahedron()
 
293
            mesh = UnitTetrahedronMesh()
294
294
 
295
295
            point = Point(0.3, 0.3, 0.3)
296
296
            id = mesh.closest_cell(point)