Salome HOME
Copyright update 2021
[tools/medcoupling.git] / src / RENUMBER / testRenumbering.py
1 #!/usr/bin/env python
2 #  -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2007-2021  CEA/DEN, EDF R&D
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 #
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21
22 from MEDLoader import *
23 import os
24 import sys
25 import unittest
26
27 class RenumberingTest(unittest.TestCase):
28     def testBoost2D(self):
29         filename="Test2D.med"
30         meshname="Mesh_1"
31         method="BOOST"
32         string_to_execute=self.dir_renumber+" "+self.dir_mesh+"/"+filename+" "+meshname+" "+method+" "+self.dir_mesh+"/out_"+filename
33         os.system(string_to_execute)
34         mm=MEDFileMesh.New(self.dir_mesh+"/out_"+filename,meshname)
35         m=mm.getMeshAtLevel(0)
36         ff=MEDFileField1TS(self.dir_mesh+"/out_"+filename,"Test field")
37         field_ini=DataArrayDouble([(2,3),(12,13),(14,15),(4,5),(6,7),(8,9),(16,17),(0,1),(10,11)])
38         ff.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
39         f=ff.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
40         field=f.getArray().isEqual(field_ini,1e-15)
41         connectivite=[4,1,5,12,10,4,10,12,13,11,4,5,4,14,12,4,11,13,9,3,4,12,14,15,13,4,4,0,6,14,4,13,15,8,9,4,14,6,7,15,4,15,7,2,8]
42         connectivite_index=[0,5,10,15,20,25,30,35,40,45]
43         Boost2D=m.getNodalConnectivity().getValues()==connectivite and m.getNodalConnectivityIndex().getValues()==connectivite_index and field
44         self.assertTrue(Boost2D)
45         os.remove(self.dir_mesh+"/out_"+filename)
46         pass
47
48     def tessMetis2D(self):#not activated yet
49         filename="Test2D.med"
50         meshname="Mesh_1"
51         method="METIS"
52         string_to_execute=self.dir_renumber+" "+self.dir_mesh+"/"+filename+" "+meshname+" "+method+" "+self.dir_mesh+"/out_"+filename
53         os.system(string_to_execute)
54         m = MESH(MED_DRIVER,self.dir_mesh+"/out_"+filename,meshname)
55         nbcell2dmetis=m.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS)
56         connectivite=[12,14,10,4,2,6,13,11,11,13,14,12,16,8,3,9,5,1,7,15,15,7,8,16,14,16,9,10,6,5,15,13,13,15,16,14]
57         connectivite_index=[1,5,9,13,17,21,25,29,33,37]
58         conn=m.getConnectivity(MED_NODAL,MED_CELL,MED_QUAD4)
59         conn_index=m.getConnectivityIndex(MED_NODAL,MED_CELL);
60         conn2dmetis=(list(conn)==connectivite)
61         conn_index2dmetis=(list(conn_index)==connectivite_index)
62         Metis2D=conn2dmetis and conn_index2dmetis and (nbcell2dmetis==9)
63         self.assertTrue(Metis2D)
64         os.remove(self.dir_mesh+"/out_"+filename)
65         pass
66
67     def testBoost2DPolygon(self):
68         filename="Test2Dpoly.med"
69         meshname="Mesh_1"
70         method="BOOST"
71         string_to_execute=self.dir_renumber+" "+self.dir_mesh+"/"+filename+" "+meshname+" "+method+" "+self.dir_mesh+"/out_"+filename
72         os.system(string_to_execute)
73         mm=MEDFileMesh.New(self.dir_mesh+"/out_"+filename,meshname)
74         m=mm.getMeshAtLevel(0)
75         nbcell2dpolyboost=m.getNumberOfCells()
76         connectivite=[5,1,4,8,9,5,10,9,8,11,5,4,5,7,8,5,3,10,11,15,5,11,8,7,12,5,5,0,6,7,5,15,11,12,14,5,12,7,6,13,5,14,12,13,2]
77         connectivite_index=[0,5,10,15,20,25,30,35,40,45]
78         conn=m.getNodalConnectivity().getValues()
79         conn_index=m.getNodalConnectivityIndex().getValues()
80         conn2dpolyboost=(list(conn)==connectivite)
81         conn_index2dpolyboost=(list(conn_index)==connectivite_index)
82         PolyBoost2D=conn2dpolyboost and conn_index2dpolyboost and (nbcell2dpolyboost==9)
83         self.assertTrue(PolyBoost2D)
84         os.remove(self.dir_mesh+"/out_"+filename)
85         pass
86
87     def tessMetis2DPolygon(self):#not activated yet
88         filename="Test2Dpoly.med"
89         meshname="Mesh_1"
90         method="METIS"
91         string_to_execute=self.dir_renumber+" "+self.dir_mesh+"/"+filename+" "+meshname+" "+method+" "+self.dir_mesh+"/out_"+filename
92         os.system(string_to_execute)
93         m = MESH(MED_DRIVER,self.dir_mesh+"/out_"+filename,meshname)
94         nbcell2dpolymetis=m.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS)
95         connectivite=[6,1,7,8,2,5,9,10,5,6,8,9,15,13,14,3,4,11,12,16,16,12,13,15,11,10,9,12,12,9,8,13,13,8,7,14]
96         connectivite_index=[1,5,9,13,17,21,25,29,33,37]
97         conn=m.getConnectivity(MED_NODAL,MED_CELL,MED_POLYGON)
98         conn_index=m.getConnectivityIndex(MED_NODAL,MED_CELL)
99         conn2dpolymetis=(list(conn)==connectivite)
100         conn_index2dpolymetis=(list(conn_index)==connectivite_index)
101         PolyMetis2D=conn2dpolymetis and conn_index2dpolymetis and (nbcell2dpolymetis==9)
102         self.assertTrue(PolyMetis2D)
103         os.remove(self.dir_mesh+"/out_"+filename)
104         pass
105
106     def testBoost3D(self):
107         filename="Test3D.med"
108         meshname="Mesh_1"
109         method="BOOST"
110         string_to_execute=self.dir_renumber+" "+self.dir_mesh+"/"+filename+" "+meshname+" "+method+" "+self.dir_mesh+"/out_"+filename
111         os.system(string_to_execute)
112         mm=MEDFileMesh.New(self.dir_mesh+"/out_"+filename,meshname)
113         m=mm.getMeshAtLevel(0)
114         nbcell3dboost=m.getNumberOfCells()
115         connectivite=[18,22,12,4,17,26,21,13,25,18,16,5,12,22,24,15,21,26,18,26,21,13,25,23,14,6,19,18,8,22,17,0,20,26,25,9,18,24,15,21,26,18,7,14,23,18,1,16,22,8,11,24,26,20,18,20,26,25,9,10,23,19,2,18,11,24,26,20,3,18,23,10]
116         connectivite_index=[0,9,18,27,36,45,54,63,72]
117         conn=m.getNodalConnectivity().getValues()
118         conn_index=m.getNodalConnectivityIndex().getValues()
119         conn3dboost=(list(conn)==connectivite)
120         conn_index3dboost=(list(conn_index)==connectivite_index)
121         Boost3D=conn3dboost and conn_index3dboost and (nbcell3dboost==8)
122         self.assertTrue(Boost3D)
123         os.remove(self.dir_mesh+"/out_"+filename)
124         pass
125
126     def tessMetis3D(self):#not activated yet
127         filename="Test3D.med"
128         meshname="Mesh_1"
129         method="METIS"
130         string_to_execute=self.dir_renumber+" "+self.dir_mesh+"/"+filename+" "+meshname+" "+method+" "+self.dir_mesh+"/out_"+filename
131         os.system(string_to_execute)
132         m = MESH(MED_DRIVER,self.dir_mesh+"/out_"+filename,meshname)
133         nbcell3dmetis=m.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS)
134         connectivite=[12,25,27,21,4,19,24,11,27,22,14,26,24,15,7,20,17,6,13,23,25,16,22,27,9,23,18,1,21,27,26,10,23,13,5,18,27,22,14,26,25,16,22,27,19,8,15,24,2,17,23,9,12,25,27,21,21,27,26,10,11,24,20,3]
135         connectivite_index=[1,9,17,25,33,41,49,57,65]
136         conn=m.getConnectivity(MED_NODAL,MED_CELL,MED_HEXA8)
137         conn_index=m.getConnectivityIndex(MED_NODAL,MED_CELL);
138         conn3dmetis=(list(conn)==connectivite)
139         conn_index3dmetis=(list(conn_index)==connectivite_index)
140         Metis3D=conn3dmetis&conn_index3dmetis&(nbcell3dmetis==8)
141         self.assertTrue(Metis3D)
142         os.remove(self.dir_mesh+"/out_"+filename)
143         pass
144
145     def testBoost3DPoly(self):
146         filename="Test3Dpoly.med"
147         meshname="Mesh_1"
148         method="BOOST"
149         string_to_execute=self.dir_renumber+" "+self.dir_mesh+"/"+filename+" "+meshname+" "+method+" "+self.dir_mesh+"/out_"+filename
150         os.system(string_to_execute)
151         mm=MEDFileMesh.New(self.dir_mesh+"/out_"+filename,meshname)
152         m=mm.getMeshAtLevel(0)
153         nbcell3dpolyboost=m.getNumberOfCells()
154         connectivite=[31,22,12,4,17,-1,26,25,13,21,-1,22,26,21,12,-1,12,21,13,4,-1,4,13,25,17,-1,17,25,26,22,31,16,5,12,22,-1,24,26,21,15,-1,16,24,15,5,-1,5,15,21,12,-1,12,21,26,22,-1,22,26,24,16,31,26,21,13,25,-1,23,19,6,14,-1,26,23,14,21,-1,21,14,6,13,-1,13,6,19,25,-1,25,19,23,26,31,8,22,17,0,-1,20,9,25,26,-1,8,20,26,22,-1,22,26,25,17,-1,17,25,9,0,-1,0,9,20,8,31,24,15,21,26,-1,18,23,14,7,-1,24,18,7,15,-1,15,7,14,21,-1,21,14,23,26,-1,26,23,18,24,31,1,16,22,8,-1,11,20,26,24,-1,1,11,24,16,-1,16,24,26,22,-1,22,26,20,8,-1,8,20,11,1,31,20,26,25,9,-1,10,2,19,23,-1,20,10,23,26,-1,26,23,19,25,-1,25,19,2,9,-1,9,2,10,20,31,11,24,26,20,-1,3,10,23,18,-1,11,3,18,24,-1,24,18,23,26,-1,26,23,10,20,-1,20,10,3,11]
155         connectivite_index=[0,30,60,90,120,150,180,210,240]
156         conn=m.getNodalConnectivity().getValues()
157         conn_index=m.getNodalConnectivityIndex().getValues()
158         conn3dpolyboost=(connectivite==list(conn))
159         conn_index3dpolyboost=(connectivite_index==list(conn_index))
160         PolyBoost3D=(conn3dpolyboost and conn_index3dpolyboost and (nbcell3dpolyboost==8))
161         self.assertTrue(PolyBoost3D)
162         os.remove(self.dir_mesh+"/out_"+filename)
163         pass
164
165     def tessBoost3DPoly(self):#not activated yet
166         filename="Test3Dpoly.med"
167         meshname="Mesh_1"
168         method="METIS"
169         string_to_execute=self.dir_renumber+" "+self.dir_mesh+"/"+filename+" "+meshname+" "+method+" "+self.dir_mesh+"/out_"+filename
170         os.system(string_to_execute)
171         m = MESH(MED_DRIVER,self.dir_mesh+"/out_"+filename,meshname)
172         nbcell3dpolymetis=m.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS)
173         connectivite=[12,25,27,21,-1,4,11,24,19,-1,12,4,19,25,-1,25,19,24,27,-1,27,24,11,21,-1,21,11,4,12,
174                       27,22,14,26,-1,24,20,7,15,-1,27,24,15,22,-1,22,15,7,14,-1,14,7,20,26,-1,26,20,24,27,
175                       17,6,13,23,-1,25,27,22,16,-1,17,25,16,6,-1,6,16,22,13,-1,13,22,27,23,-1,23,27,25,17,
176                       9,23,18,1,-1,21,10,26,27,-1,9,21,27,23,-1,23,27,26,18,-1,18,26,10,1,-1,1,10,21,9,
177                       23,13,5,18,-1,27,26,14,22,-1,23,27,22,13,-1,13,22,14,5,-1,5,14,26,18,-1,18,26,27,23,
178                       25,16,22,27,-1,19,24,15,8,-1,25,19,8,16,-1,16,8,15,22,-1,22,15,24,27,-1,27,24,19,25,
179                       2,17,23,9,-1,12,21,27,25,-1,2,12,25,17,-1,17,25,27,23,-1,23,27,21,9,-1,9,21,12,2,
180                       21,27,26,10,-1,11,3,20,24,-1,21,11,24,27,-1,27,24,20,26,-1,26,20,3,10,-1,10,3,11,21]
181         connectivite_index=[1, 30, 59, 88, 117, 146, 175, 204, 233]
182         conn=m.getConnectivity(MED_NODAL,MED_CELL,MED_POLYHEDRA)
183         conn_index=m.getConnectivityIndex(MED_NODAL,MED_CELL);
184         conn3dpolymetis=(list(conn)==connectivite)
185         conn_index3dpolymetis=(list(conn_index)==connectivite_index)
186         PolyMetis3D=(conn3dpolymetis and conn_index3dpolymetis and (nbcell3dpolymetis==8))
187         self.assertTrue(PolyMetis3D)
188         os.remove(self.dir_mesh+"/out_"+filename)
189         pass
190
191     def setUp(self):
192         med_root_dir=os.getenv("MEDCOUPLING_ROOT_DIR")
193         self.dir_renumber=os.path.join(med_root_dir, "bin/renumber")
194         self.dir_mesh=os.path.join(med_root_dir, "share","resources","med")
195         pass
196     pass
197
198 unittest.main()