1 | #!/usr/bin/env python |
---|
2 | from os import sep |
---|
3 | from sys import path |
---|
4 | |
---|
5 | from Numeric import array, allclose |
---|
6 | |
---|
7 | import unittest |
---|
8 | |
---|
9 | # path.append('..' + sep + 'pymetis') |
---|
10 | |
---|
11 | import pymetis.metis as metis |
---|
12 | |
---|
13 | class TestMetis(unittest.TestCase): |
---|
14 | def setUp(self): |
---|
15 | pass |
---|
16 | |
---|
17 | def test_Hexmesh(self): |
---|
18 | # Hexagonal mesh |
---|
19 | # |
---|
20 | # 1---2 |
---|
21 | # / \ / \ |
---|
22 | # 6---0---3 |
---|
23 | # \ / \ / |
---|
24 | # 5---4 |
---|
25 | # |
---|
26 | # Divided 3 ways |
---|
27 | # Calling order is: elements, verticies, edge list |
---|
28 | # element type, number parts |
---|
29 | edgecut, epart, npart = metis.partMeshNodal(6, 7,\ |
---|
30 | [0, 1, 2,\ |
---|
31 | 0, 2, 3,\ |
---|
32 | 0, 3, 4,\ |
---|
33 | 0, 4, 5,\ |
---|
34 | 0, 5, 6,\ |
---|
35 | 0, 6, 1],\ |
---|
36 | 1,\ |
---|
37 | 3,) |
---|
38 | #print edgecut |
---|
39 | #print epart |
---|
40 | #print npart |
---|
41 | epart_expected = array([2, 2, 0, 0, 0, 0], 'i') |
---|
42 | npart_expected = array([0, 2, 2, 2, 0, 0, 0], 'i') |
---|
43 | self.assert_(edgecut == 5) |
---|
44 | assert allclose(epart, epart_expected) |
---|
45 | assert allclose(npart, npart_expected) |
---|
46 | |
---|
47 | |
---|
48 | def test_Hexmesh2(self): |
---|
49 | # Hexagonal mesh |
---|
50 | # |
---|
51 | # 1---2 |
---|
52 | # / \ / \ |
---|
53 | # 6---0---3 |
---|
54 | # \ / \ / |
---|
55 | # 5---4 |
---|
56 | # |
---|
57 | # Divided 2 ways |
---|
58 | # Calling order is: elements, verticies, edge list |
---|
59 | # element type, number parts |
---|
60 | edgecut, epart, npart = metis.partMeshNodal(6, 7,\ |
---|
61 | [0, 2, 1,\ |
---|
62 | 0, 3, 2,\ |
---|
63 | 0, 4, 3,\ |
---|
64 | 0, 5, 4,\ |
---|
65 | 0, 6, 5,\ |
---|
66 | 0, 1, 6],\ |
---|
67 | 1,\ |
---|
68 | 2,) |
---|
69 | #print edgecut |
---|
70 | #print epart |
---|
71 | #print npart |
---|
72 | epart_expected = array([1, 0, 0, 0, 1, 1], 'i') |
---|
73 | npart_expected = array([0, 1, 1, 0, 0, 0, 1], 'i') |
---|
74 | self.assert_(edgecut == 5) |
---|
75 | assert allclose(epart, epart_expected) |
---|
76 | assert allclose(npart, npart_expected) |
---|
77 | |
---|
78 | |
---|
79 | if __name__ == '__main__': |
---|
80 | unittest.main() |
---|
81 | |
---|