1 # Copyright (C) 2012-2022 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,WriteInTmpDir
25 class MEDPartitionerTest(unittest.TestCase):
27 def testPartition(self):
28 fname="PyPartitionTest.med"
29 data=MEDLoaderDataForTest.buildACompleteMEDDataStructureWithFieldsOnCells_1()
31 part_file=MEDPartitioner(fname,2)
32 part_data=MEDPartitioner(data,2)
33 part_file.write("splitted_PyPartitionTest_1")
34 part_data.write("splitted_PyPartitionTest_2")
35 part_file_xml=MEDPartitioner("splitted_PyPartitionTest_1.xml")
36 part_data_xml=MEDPartitioner("splitted_PyPartitionTest_2.xml")
37 data1=part_file_xml.getMEDFileData()
38 data2=part_data_xml.getMEDFileData()
39 m1d=data1.getMeshes().getMeshAtPos(0)
40 m2d=data2.getMeshes().getMeshAtPos(0)
41 self.assertTrue(m1d.isEqual(m2d,1e-12))
44 def testPartitionGraph(self):
45 data=MEDLoaderDataForTest.buildACompleteMEDDataStructureWithFieldsOnCells_1()
46 m=data.getMeshes().getMeshAtPos(0)
47 graph=MEDPartitioner.Graph(m.getLevel0Mesh().generateGraph())
49 tool=MEDPartitioner(data,graph)
50 data2=tool.getMEDFileData()
51 self.assertEqual( 2, data2.getMeshes().getNumberOfMeshes() )
54 def testPartitionWithJoints(self):
56 arr=DataArrayDouble(5) ; arr.iota()
57 c=MEDCouplingCMesh() ; c.setCoords(arr,arr)
58 m=c.buildUnstructured()
61 mm.setMeshAtLevel(0,m)
62 ms=MEDFileMeshes() ; ms.pushMesh(mm)
65 part_file=MEDPartitioner(data,4,"metis",True,True,True)
66 data_file=part_file.getMEDFileData()
67 meshes=data_file.getMeshes()
68 self.assertEqual( 4, meshes.getNumberOfMeshes())
69 self.assertEqual( 3, meshes.getMeshAtPos(0).getJoints().getNumberOfJoints())
70 self.assertEqual( 3, meshes.getMeshAtPos(1).getJoints().getNumberOfJoints())
71 self.assertEqual( 3, meshes.getMeshAtPos(2).getJoints().getNumberOfJoints())
72 self.assertEqual( 3, meshes.getMeshAtPos(3).getJoints().getNumberOfJoints())
73 joints=meshes.getMeshAtPos(0).getJoints()
74 self.assertEqual( 1, joints.getJointAtPos(0).getDomainNumber(), 1)
75 #VSR (10/05/2016): changed to work with metis 5.1... to be confirmed!
76 #self.assertEqual( 2, joints.getJointAtPos(1).getDomainNumber(), 2)
77 #self.assertEqual( 3, joints.getJointAtPos(2).getDomainNumber(), 3)
78 self.assertEqual( 3, joints.getJointAtPos(1).getDomainNumber(), 3)
79 self.assertEqual( 2, joints.getJointAtPos(2).getDomainNumber(), 2)
80 self.assertEqual( 2, joints.getJointAtPos(0).getStepAtPos(0).getNumberOfCorrespondences())
81 self.assertEqual( 2, joints.getJointAtPos(1).getStepAtPos(0).getNumberOfCorrespondences())
82 self.assertEqual( 1, joints.getJointAtPos(2).getStepAtPos(0).getNumberOfCorrespondences())
84 for ii in range(joints.getJointAtPos(0).getStepAtPos(0).getNumberOfCorrespondences()):
85 correspond=joints.getJointAtPos(0).getStepAtPos(0).getCorrespondenceAtPos(ii)
86 #VSR (10/05/2016): changed to work with metis 5.1... to be confirmed!
87 #if correspond.getCorrespondence().isEqual(DataArrayInt([1,3,2,4])):
88 if correspond.getCorrespondence().isEqual(DataArrayInt([3,1,4,2])):
90 self.assertEqual(NORM_QUAD4, correspond.getLocalGeometryType())
91 self.assertEqual(NORM_QUAD4, correspond.getRemoteGeometryType())
94 self.assertEqual(1,found)
97 def testPartitionPartGraph(self):
98 arr=DataArrayDouble(5) ; arr.iota()
99 c=MEDCouplingCMesh() ; c.setCoords(arr,arr)
100 m=c.buildUnstructured()
101 part=MEDPartitioner.Graph(m.generateGraph())
104 p=part.getPartition()
105 self.assertTrue(isinstance(a,MEDCouplingSkyLineArray))
106 self.assertTrue(isinstance(p,MEDCouplingSkyLineArray))
107 self.assertTrue(part.nbVertices() > 0 )
110 if __name__ == "__main__":