1 # Copyright (C) 2012-2015 CEA/DEN, EDF R&D
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 from MEDPartitioner import *
21 from MEDLoader import *
23 from MEDLoaderDataForTest import MEDLoaderDataForTest
25 class MEDPartitionerTest(unittest.TestCase):
26 def testPartition(self):
27 fname="PyPartitionTest.med"
28 data=MEDLoaderDataForTest.buildACompleteMEDDataStructureWithFieldsOnCells_1()
30 part_file=MEDPartitioner(fname,2)
31 part_data=MEDPartitioner(data,2)
32 part_file.write("splitted_PyPartitionTest_1")
33 part_data.write("splitted_PyPartitionTest_2")
34 part_file_xml=MEDPartitioner("splitted_PyPartitionTest_1.xml")
35 part_data_xml=MEDPartitioner("splitted_PyPartitionTest_2.xml")
36 data1=part_file_xml.getMEDFileData()
37 data2=part_data_xml.getMEDFileData()
38 m1d=data1.getMeshes().getMeshAtPos(0)
39 m2d=data2.getMeshes().getMeshAtPos(0)
40 self.assertTrue(m1d.isEqual(m2d,1e-12))
42 def testPartitionGraph(self):
43 data=MEDLoaderDataForTest.buildACompleteMEDDataStructureWithFieldsOnCells_1()
44 m=data.getMeshes().getMeshAtPos(0)
45 graph=MEDPartitioner.Graph(m.getLevel0Mesh().generateGraph())
47 tool=MEDPartitioner(data,graph)
48 data2=tool.getMEDFileData()
49 self.assertEqual( 2, data2.getMeshes().getNumberOfMeshes() )
51 def testPartitionWithJoints(self):
53 arr=DataArrayDouble(5) ; arr.iota()
54 c=MEDCouplingCMesh() ; c.setCoords(arr,arr)
55 m=c.buildUnstructured()
58 mm.setMeshAtLevel(0,m)
59 ms=MEDFileMeshes() ; ms.pushMesh(mm)
62 part_file=MEDPartitioner(data,4,"metis",True,True,True)
63 data_file=part_file.getMEDFileData()
64 meshes=data_file.getMeshes()
65 self.assertEqual( 4, meshes.getNumberOfMeshes())
66 self.assertEqual( 3, meshes.getMeshAtPos(0).getJoints().getNumberOfJoints())
67 self.assertEqual( 3, meshes.getMeshAtPos(1).getJoints().getNumberOfJoints())
68 self.assertEqual( 3, meshes.getMeshAtPos(2).getJoints().getNumberOfJoints())
69 self.assertEqual( 3, meshes.getMeshAtPos(3).getJoints().getNumberOfJoints())
70 joints=meshes.getMeshAtPos(0).getJoints()
71 self.assertEqual( 1, joints.getJointAtPos(0).getDomainNumber(), 1)
72 self.assertEqual( 2, joints.getJointAtPos(1).getDomainNumber(), 2)
73 self.assertEqual( 3, joints.getJointAtPos(2).getDomainNumber(), 3)
74 self.assertEqual( 2, joints.getJointAtPos(0).getStepAtPos(0).getNumberOfCorrespondences())
75 self.assertEqual( 2, joints.getJointAtPos(1).getStepAtPos(0).getNumberOfCorrespondences())
76 self.assertEqual( 1, joints.getJointAtPos(2).getStepAtPos(0).getNumberOfCorrespondences())
78 for ii in xrange(joints.getJointAtPos(0).getStepAtPos(0).getNumberOfCorrespondences()):
79 correspond=joints.getJointAtPos(0).getStepAtPos(0).getCorrespondenceAtPos(ii)
80 if correspond.getCorrespondence().isEqual(DataArrayInt([1,3,2,4])):
82 self.assertEqual(NORM_QUAD4, correspond.getLocalGeometryType())
83 self.assertEqual(NORM_QUAD4, correspond.getRemoteGeometryType())
86 self.assertEqual(1,found)
88 def testPartitionPartGraph(self):
89 arr=DataArrayDouble(5) ; arr.iota()
90 c=MEDCouplingCMesh() ; c.setCoords(arr,arr)
91 m=c.buildUnstructured()
92 part=MEDPartitioner.Graph(m.generateGraph())
96 self.assertTrue(isinstance(a,MEDCouplingSkyLineArray))
97 self.assertTrue(isinstance(p,MEDCouplingSkyLineArray))
98 self.assertTrue(part.nbVertices() > 0 )