1
"""Unit tests for MeshValueCollection"""
3
# Copyright (C) 2011 Johan Hake
5
# This file is part of DOLFIN.
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.
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.
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/>.
20
# First added: 2011-03-10
21
# Last changed: 2011-03-10
27
class MeshValueCollections(unittest.TestCase):
29
def testAssign2DCells(self):
30
mesh = UnitSquare (3, 3)
31
ncells = mesh.num_cells()
32
f = MeshValueCollection("int", 2)
34
for cell in cells(mesh):
35
value = ncells - cell.index()
36
all_new = all_new and f.set_value(cell.index(), value, mesh)
37
g = MeshValueCollection("int", 2)
39
self.assertEqual(18, f.size())
40
self.assertEqual(18, g.size())
41
self.assertTrue(all_new)
43
for cell in cells(mesh):
44
value = ncells - cell.index()
45
self.assertEqual(value, g.get_value(cell.index(), 0))
47
def testAssign2DFacets(self):
48
mesh = UnitSquare (3, 3)
50
ncells = mesh.num_cells()
51
f = MeshValueCollection("int", 1)
53
for cell in cells(mesh):
54
value = ncells - cell.index()
55
for i, facet in enumerate(facets(cell)):
56
all_new = all_new and f.set_value(facet.index(), i, value+i)
58
g = MeshValueCollection("int", 1)
60
self.assertEqual(54, f.size())
61
self.assertEqual(54, g.size())
62
self.assertTrue(all_new)
64
for cell in cells(mesh):
65
value = ncells - cell.index()
66
for i, facet in enumerate(facets(cell)):
67
self.assertEqual(value, g.get_value(facet.index(), i))
69
def testAssign2DVertices(self):
70
mesh = UnitSquare (3, 3)
72
ncells = mesh.num_cells()
73
f = MeshValueCollection("int", 0)
75
for cell in cells(mesh):
76
value = ncells - cell.index()
77
for i, vert in enumerate(vertices(cell)):
78
all_new = all_new and f.set_value(vert.index(), i, value+i)
80
g = MeshValueCollection("int", 0)
82
self.assertEqual(54, f.size())
83
self.assertEqual(54, g.size())
84
self.assertTrue(all_new)
86
for cell in cells(mesh):
87
value = ncells - cell.index()
88
for i, vert in enumerate(vertices(cell)):
89
self.assertEqual(value, g.get_value(vert.index(), i))
91
def testMeshFunctionAssign2DCells(self):
92
mesh = UnitSquare (3, 3)
93
ncells = mesh.num_cells()
94
f = CellFunction("int", mesh)
95
for cell in cells(mesh):
96
f[cell] = ncells - cell.index()
98
g = MeshValueCollection("int", 2)
100
self.assertEqual(18, f.size())
101
self.assertEqual(18, g.size())
103
for cell in cells(mesh):
104
value = ncells - cell.index()
105
self.assertEqual(value, g.get_value(cell.index(), 0))
107
def testMeshFunctionAssign2DFacets(self):
108
mesh = UnitSquare (3, 3)
109
f = FacetFunction("int", mesh, 25)
110
g = MeshValueCollection("int", 1)
112
self.assertEqual(33, f.size())
113
self.assertEqual(54, g.size())
115
for cell in cells(mesh):
116
for i, facet in enumerate(facets(cell)):
117
self.assertEqual(25, g.get_value(facet.index(), i))
119
def testMeshFunctionAssign2DVertices(self):
120
mesh = UnitSquare (3, 3)
121
f = VertexFunction("int", mesh, 25)
122
g = MeshValueCollection("int", 0)
124
self.assertEqual(16, f.size())
125
self.assertEqual(54, g.size())
127
for cell in cells(mesh):
128
for i, vert in enumerate(vertices(cell)):
129
self.assertEqual(25, g.get_value(vert.index(), i))
131
if __name__ == "__main__":