Salome HOME
Fix merge errors post 8.3.0
[tools/medcoupling.git] / src / MEDCoupling_Swig / MEDCouplingBasicsTest6.py
1 #  -*- coding: utf-8 -*-
2 # Copyright (C) 2017  CEA/DEN, EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 from MEDCoupling import *
22 import unittest
23 from math import pi,e,sqrt,cos,sin
24 from datetime import datetime
25 import rlcompleter,readline # this line has to be here, to ensure a usability of MEDCoupling/MEDLoader. B4 removing it please notify to anthony.geay@edf.fr
26
27 class MEDCouplingBasicsTest6(unittest.TestCase):
28     def testPointSetInvertOrientationOfAllCells(self):
29         """ Test of inversion of orientation of cells on a different geo types"""
30         def level1(self):
31             m=MEDCouplingUMesh("",1)
32             m.allocateCells()
33             m.insertNextCell(NORM_SEG2,[3,4])
34             m.insertNextCell(NORM_SEG2,[13,14])
35             m.insertNextCell(NORM_SEG3,[5,6,7])
36             m.insertNextCell(NORM_SEG2,[23,24])
37             m.insertNextCell(NORM_SEG3,[8,9,10])
38             ref0=DataArrayInt([0,3,6,10,13,17])
39             self.assertTrue(m.getNodalConnectivityIndex().isEqual(ref0))
40             m.invertOrientationOfAllCells()
41             self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([1,4,3, 1,14,13, 2,7,6,5, 1,24,23, 2,10,9,8])))
42             self.assertTrue(m.getNodalConnectivityIndex().isEqual(ref0))
43             pass
44
45         def level2(self):
46             m=MEDCouplingUMesh("",2)
47             m.allocateCells()
48             m.insertNextCell(NORM_TRI3,[1,2,3])
49             m.insertNextCell(NORM_QUAD4,[4,5,6,7])
50             m.insertNextCell(NORM_POLYGON,[8,9,10,11,12,13])
51             m.insertNextCell(NORM_TRI6,[14,15,16,17,18,19])
52             m.insertNextCell(NORM_QUAD8,[20,21,22,23,24,25,26,27])
53             m.insertNextCell(NORM_QPOLYG,[30,31,32,33,34,35, 36,37,38,39,40,41])
54             ref0=DataArrayInt([0,4,9,16,23,32,45])
55             self.assertTrue(m.getNodalConnectivityIndex().isEqual(ref0))
56             m.invertOrientationOfAllCells()
57             self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([3,1,3,2, 4,4,7,6,5, 5,8,13,12,11,10,9, 6,14,16,15,19,18,17, 8,20,23,22,21,27,26,25,24, 32,30,35,34,33,32,31,41,40,39,38,37,36])))
58             self.assertTrue(m.getNodalConnectivityIndex().isEqual(ref0))
59             pass
60
61         def level3(self):
62             m=MEDCouplingUMesh("",3)
63             m.allocateCells()
64             m.insertNextCell(NORM_TETRA4,[1,2,3,4])
65             m.insertNextCell(NORM_PYRA5,[5,6,7,8,9])
66             m.insertNextCell(NORM_PENTA6,[10,11,12,13,14,15])
67             m.insertNextCell(NORM_HEXA8,[20,21,22,23,24,25,26,27])
68             m.insertNextCell(NORM_TETRA10,[30,31,32,33,34,35,36,37,38,39])
69             m.insertNextCell(NORM_PYRA13,[40,41,42,43,44,45,46,47,48,49,50,51,52])
70             m.insertNextCell(NORM_HEXA20,[60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79])
71             m.insertNextCell(NORM_PENTA15,[80,81,82,83,84,85,86,87,88,89,90,91,92,93,94])
72             ref0=DataArrayInt([0,5,11,18,27,38,52,73,89])
73             self.assertTrue(m.getNodalConnectivityIndex().isEqual(ref0))
74             m.invertOrientationOfAllCells()
75             self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([14,1,3,2,4, 15,5,8,7,6,9, 16,10,12,11,13,15,14, 18,20,23,22,21,24,27,26,25, 20,30,32,31,33,36,35,34,37,39,38, 23,40,43,42,41,44,48,47,46,45,49,52,51,50, 30,60,63,62,61,64,67,66,65,71,70,69,68,75,74,73,72,76,79,78,77, 25,80,82,81,83,85,84,88,87,86,91,90,89,92,94,93])))
76             self.assertTrue(m.getNodalConnectivityIndex().isEqual(ref0))
77             pass
78
79         def gtumesh(self):
80             m=MEDCoupling1SGTUMesh("",NORM_SEG2)
81             m.setNodalConnectivity(DataArrayInt([1,2,3,4,5,6,7,8]))
82             self.assertEqual(m.getNumberOfCells(),4)
83             m2=m.deepCopy()
84             self.assertTrue(m2.isEqual(m,0.))
85             m.invertOrientationOfAllCells()
86             self.assertTrue(not m2.isEqual(m,0.))
87             m.getNodalConnectivity().isEqual(DataArrayInt([2,1,4,3,6,5,8,7]))
88             m.invertOrientationOfAllCells()
89             self.assertTrue(m2.isEqual(m,0.))
90             #
91             p=MEDCoupling1DGTUMesh("",NORM_POLYGON)
92             ref0=DataArrayInt([0,3,7,12])
93             p.setNodalConnectivity(DataArrayInt([1,2,3, 10,11,12,13, 20,21,22,23,24]),ref0)
94             p2=p.deepCopy()
95             self.assertTrue(p2.isEqual(p,0.))
96             self.assertEqual(p.getNumberOfCells(),3)
97             p.invertOrientationOfAllCells()
98             self.assertTrue(not p2.isEqual(p,0.))
99             self.assertTrue(p.getNodalConnectivityIndex().isEqual(ref0))
100             self.assertTrue(p.getNodalConnectivity().isEqual(DataArrayInt([1,3,2, 10,13,12,11, 20,24,23,22,21])))
101             p.invertOrientationOfAllCells()
102             self.assertTrue(p2.isEqual(p,0.))
103             pass
104         level1(self)
105         level2(self)
106         level3(self)
107         gtumesh(self)
108         pass
109     pass
110
111 if __name__ == '__main__':
112     unittest.main()