]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/MEDCoupling_Swig/MEDCouplingBasicsTest.py
Salome HOME
addition of MEDCouplingUMesh::conformize2D to conformize a 2D mesh
[tools/medcoupling.git] / src / MEDCoupling_Swig / MEDCouplingBasicsTest.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2014  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 from MEDCouplingDataForTest import MEDCouplingDataForTest
26 import rlcompleter,readline # this line has to be here, to ensure a usability of MEDCoupling/MEDLoader. B4 removing it please notify to anthony.geay@cea.fr
27
28 class MEDCouplingBasicsTest(unittest.TestCase):
29     def testArray2(self):
30         arr=DataArrayDouble.New()
31         arr.setValues([12.,11.,10.,9.,8.,7.,6.,5.,4.,3.,2.,1.],3,4)
32         arr.setInfoOnComponent(0,"ggg");
33         arr.setInfoOnComponent(1,"hhhh");
34         arr.setInfoOnComponent(2,"jj");
35         arr.setInfoOnComponent(3,"kkkkkk");
36         arr2=arr.convertToIntArr();
37         arr3=arr2.convertToDblArr();
38         self.assertTrue(arr.isEqual(arr3,1e-14))
39         pass
40
41     def testArray3(self):
42         arr1=DataArrayInt.New();
43         arr1Ref=[0,10,1,11,2,12,3,13,4,14,5,15,6,16]
44         arr1.setValues(arr1Ref,7,2);
45         self.assertEqual(7,arr1.getNumberOfTuples());
46         self.assertEqual(2,arr1.getNumberOfComponents());
47         self.assertEqual(arr1Ref,list(arr1.getValues()));
48         arr2=arr1.substr(3);
49         self.assertEqual(4,arr2.getNumberOfTuples());
50         self.assertEqual(2,arr2.getNumberOfComponents());
51         self.assertEqual(arr1Ref[6:],list(arr2.getValues()));
52         arr3=arr1.substr(2,5);
53         self.assertEqual(3,arr3.getNumberOfTuples());
54         self.assertEqual(2,arr3.getNumberOfComponents());
55         self.assertEqual(arr1Ref[4:10],list(arr3.getValues()));
56         #
57         arr4=DataArrayDouble.New();
58         arr4Ref=[0.8,10.8,1.9,11.9,2.1,12.1,3.2,13.2,4.3,14.3,5.4,15.4,6.5,16.5]
59         arr4.setValues(arr4Ref,7,2);
60         self.assertEqual(7,arr4.getNumberOfTuples());
61         self.assertEqual(2,arr4.getNumberOfComponents());
62         tmp=arr4.getValues()
63         for i in xrange(14):
64             self.assertTrue(abs(arr4Ref[i]-tmp[i])<1e-14);
65             pass
66         arr5=arr4.substr(3);
67         self.assertEqual(4,arr5.getNumberOfTuples());
68         self.assertEqual(2,arr5.getNumberOfComponents());
69         tmp=arr5.getValues()
70         for i in xrange(8):
71             self.assertTrue(abs(arr4Ref[6+i]-tmp[i])<1e-14);
72             pass
73         arr6=arr4.substr(2,5);
74         self.assertEqual(3,arr6.getNumberOfTuples());
75         self.assertEqual(2,arr6.getNumberOfComponents());
76         tmp=arr6.getValues()
77         for i in xrange(6):
78             self.assertTrue(abs(arr4Ref[4+i]-tmp[i])<1e-14);
79             pass
80         pass
81
82     def testMesh(self):
83         tab4=[1, 2, 8, 7, 2, 3, 9, 8, 3,
84               4, 10, 9, 4, 5, 11, 10, 5,
85               0, 6, 11, 0, 1, 7, 6 ]
86         nbOfNodes=12
87         nbOfCells=6
88         coords=[ 0.024155, 0.04183768725682622, -0.305, 0.04831000000000001, -1.015761910347357e-17,
89                  -0.305, 0.09662000000000001, -1.832979297858306e-18, -0.305, 0.120775, 0.04183768725682623,
90                  -0.305, 0.09662000000000001, 0.08367537451365245, -0.305, 0.04831000000000001, 0.08367537451365246,
91                  -0.305, 0.024155, 0.04183768725682622, -0.2863, 0.04831000000000001, -1.015761910347357e-17, -0.2863, 
92                  0.09662000000000001, -1.832979297858306e-18, -0.2863, 0.120775, 0.04183768725682623, -0.2863, 0.09662000000000001,
93                  0.08367537451365245, -0.2863, 0.04831000000000001, 0.08367537451365246, -0.2863 ]
94         self.assertEqual(MEDCouplingMesh.GetNumberOfNodesOfGeometricType(NORM_TRI3),3)
95         self.assertTrue(MEDCouplingMesh.IsStaticGeometricType(NORM_TRI3))
96         self.assertTrue(MEDCouplingMesh.IsLinearGeometricType(NORM_TRI3))
97         self.assertEqual(MEDCouplingMesh.GetDimensionOfGeometricType(NORM_TRI3),2)
98         self.assertEqual(MEDCouplingMesh.GetReprOfGeometricType(NORM_TRI3),"NORM_TRI3")
99         self.assertRaises(InterpKernelException,MEDCouplingMesh.GetNumberOfNodesOfGeometricType,NORM_POLYGON)
100         self.assertTrue(not MEDCouplingMesh.IsStaticGeometricType(NORM_POLYGON))
101         self.assertTrue(MEDCouplingMesh.IsLinearGeometricType(NORM_POLYGON))
102         self.assertEqual(MEDCouplingMesh.GetDimensionOfGeometricType(NORM_POLYGON),2)
103         self.assertEqual(MEDCouplingMesh.GetReprOfGeometricType(NORM_POLYGON),"NORM_POLYGON")
104         self.assertEqual(MEDCouplingMesh.GetNumberOfNodesOfGeometricType(NORM_TRI6),6)
105         self.assertTrue(MEDCouplingMesh.IsStaticGeometricType(NORM_TRI6))
106         self.assertTrue(not MEDCouplingMesh.IsLinearGeometricType(NORM_TRI6))
107         self.assertEqual(MEDCouplingMesh.GetDimensionOfGeometricType(NORM_TRI6),2)
108         self.assertEqual(MEDCouplingMesh.GetReprOfGeometricType(NORM_TRI6),"NORM_TRI6")
109         mesh=MEDCouplingUMesh.New()
110         mesh.setMeshDimension(2)
111         mesh.allocateCells(8);
112         mesh.setName("mesh1")
113         self.assertTrue(mesh.getName()=="mesh1")
114         for i in range(nbOfCells):
115             mesh.insertNextCell(NORM_QUAD4,4,tab4[4*i:4*(i+1)]);
116             pass
117         mesh.finishInsertingCells()
118         self.assertTrue(mesh.getNumberOfCells()==nbOfCells)
119         self.assertTrue(mesh.getNodalConnectivity().getNbOfElems()==30)
120         self.assertTrue(mesh.getNodalConnectivityIndex().getNbOfElems()==nbOfCells+1)
121         myCoords=DataArrayDouble.New()
122         myCoords.setValues(coords,nbOfNodes,3);
123         self.assertTrue(myCoords.getIJ(3,2)==-0.305)
124         mesh.setCoords(myCoords);
125         mesh.checkCoherency();
126         self.assertTrue(mesh.getAllGeoTypes()==[4])
127         myFalseConn=DataArrayInt.New()
128         myFalseConn.setValues(tab4,6,4)
129         self.assertTrue(myFalseConn.getIJ(1,1)==3)
130         #
131         field=MEDCouplingFieldDouble.New(ON_CELLS)
132         field.setMesh(mesh)
133         field.setNature(Integral)
134         myCoords=DataArrayDouble.New()
135         sampleTab=[]
136         for i in range(nbOfCells*9):
137             sampleTab.append(float(i))
138         myCoords.setValues(sampleTab,nbOfCells,9);
139         field.setArray(myCoords)
140         self.assertTrue(3==mesh.getSpaceDimension())
141         field.checkCoherency()
142         mesh2=mesh.clone(False)
143         mesh3=mesh.clone(True)
144         mesh3=0
145         mesh2=0
146         ## deep full recursively copy of field -> both field and mesh underneath copied
147         field2=field.clone(True)
148         field2.setMesh(field.getMesh().clone(True))
149         mesh3=mesh.clone(True)
150         field3=mesh3.fillFromAnalytic(ON_CELLS,2,"x*IVec+(y+z)*JVec")
151         field3.applyFunc("u*u*u+cos(u)")
152         pass
153         
154     def testMeshPointsCloud(self):
155         targetCoords=[-0.3,-0.3,0.5, 0.2,-0.3,1., 0.7,-0.3,1.5,
156                       -0.3,0.2,0.5, 0.2,0.2,1., 0.7,0.2,1.5, -0.3,0.7,0.5, 0.2,0.7,1., 0.7,0.7,1.5]
157         targetMesh=MEDCouplingUMesh.New();
158         targetMesh.setMeshDimension(0);
159         targetMesh.allocateCells(8);
160         targetMesh.insertNextCell(NORM_POINT1,1,[0]);
161         targetMesh.insertNextCell(NORM_POINT1,1,[1]);
162         targetMesh.insertNextCell(NORM_POINT1,1,[2]);
163         targetMesh.insertNextCell(NORM_POINT1,1,[3]);
164         targetMesh.insertNextCell(NORM_POINT1,1,[4]);
165         targetMesh.insertNextCell(NORM_POINT1,1,[5]);
166         targetMesh.insertNextCell(NORM_POINT1,1,[7]);
167         targetMesh.insertNextCell(NORM_POINT1,1,[6]);
168         targetMesh.finishInsertingCells();
169         self.assertRaises(InterpKernelException,targetMesh.checkCoherency);
170         myCoords=DataArrayDouble.New();
171         myCoords.setValues(targetCoords,9,3);
172         targetMesh.setCoords(myCoords);
173         self.assertEqual(targetMesh.getSpaceDimension(),3)
174         self.assertEqual(targetMesh.getNumberOfCells(),8)
175         self.assertEqual(targetMesh.getNumberOfNodes(),9)
176         self.assertEqual(targetMesh.getMeshDimension(),0)
177         pass
178
179     def testMeshM1D(self):
180         meshM1D=MEDCouplingUMesh.New();
181         self.assertRaises(InterpKernelException,meshM1D.getMeshDimension);
182         self.assertRaises(InterpKernelException,meshM1D.getNumberOfNodes);
183         self.assertRaises(InterpKernelException,meshM1D.getNumberOfCells);
184         self.assertRaises(InterpKernelException,meshM1D.setMeshDimension,-2)
185         self.assertRaises(InterpKernelException,meshM1D.setMeshDimension,-10)
186         meshM1D.setMeshDimension(-1);
187         meshM1D.checkCoherency();
188         self.assertEqual(meshM1D.getMeshDimension(),-1);
189         self.assertEqual(meshM1D.getNumberOfCells(),1);
190         self.assertRaises(InterpKernelException,meshM1D.getNumberOfNodes);
191         self.assertRaises(InterpKernelException,meshM1D.getSpaceDimension);
192         cpy=meshM1D.clone(True);
193         self.assertTrue(cpy.isEqual(meshM1D,1e-12));
194         fieldOnCells=MEDCouplingFieldDouble.New(ON_CELLS);
195         fieldOnCells.setMesh(meshM1D);
196         array=DataArrayDouble.New();
197         array.setValues(6*[7.],1,6);
198         fieldOnCells.setArray(array);
199         fieldOnCells.checkCoherency();
200         pass
201     
202     def testDeepCopy(self):
203         array=DataArrayDouble.New();
204         array.setValues(5*3*[7.],5,3);
205         self.assertEqual(array.getIJ(3,2),7.);
206         array2=array.deepCpy();
207         self.assertEqual(array2.getIJ(3,2),7.)
208         #
209         array3=DataArrayInt.New();
210         array3.setValues(5*3*[17],5,3);
211         self.assertEqual(array3.getIJ(3,2),17);
212         array4=array3.deepCpy();
213         self.assertEqual(array4.getIJ(3,2),17);
214         pass
215     
216     def testRevNodal(self):
217         mesh=MEDCouplingDataForTest.build2DTargetMesh_1()
218         revNodal,revNodalIndx=mesh.getReverseNodalConnectivity();
219         revNodalExpected=[0,0,1,1,2,0,3,0,1,2,3,4,2,4,3,3,4,4];
220         revNodalIndexExpected=[0,1,3,5,7,12,14,15,17,18];
221         self.assertEqual(revNodal.getNbOfElems(),18)
222         self.assertEqual(revNodalIndx.getNbOfElems(),10)
223         self.assertEqual(list(revNodal.getValues()),revNodalExpected)
224         self.assertEqual(list(revNodalIndx.getValues()),revNodalIndexExpected)
225         pass
226     
227     def testConvertToPolyTypes(self):
228         mesh=MEDCouplingDataForTest.build2DTargetMesh_1();
229         elts=[1,3];
230         mesh.convertToPolyTypes(elts);
231         mesh.checkCoherency();
232         self.assertEqual(5,mesh.getNumberOfCells());
233         self.assertEqual(23,mesh.getNodalConnectivity().getNumberOfTuples());
234         expected1=[4, 0, 3, 4, 1, 5, 1, 4, 2, 3, 4, 5, 2, 5, 6, 7, 4, 3, 4, 7, 8, 5, 4]
235         self.assertEqual(expected1,list(mesh.getNodalConnectivity().getValues()));
236         #
237         mesh=MEDCouplingDataForTest.build3DTargetMesh_1();
238         mesh.convertToPolyTypes(elts);
239         mesh.checkCoherency();
240         self.assertEqual(8,mesh.getNumberOfCells());
241         self.assertEqual(114,mesh.getNodalConnectivity().getNumberOfTuples());
242         mesh.convertToPolyTypes(elts);
243         mesh.checkCoherency();
244         self.assertEqual(8,mesh.getNumberOfCells());
245         self.assertEqual(114,mesh.getNodalConnectivity().getNumberOfTuples());
246         pass
247
248     def testDescConn2D(self):
249         mesh=MEDCouplingDataForTest.build2DTargetMesh_1();
250         desc=DataArrayInt.New();
251         descIndx=DataArrayInt.New();
252         revDesc=DataArrayInt.New();
253         revDescIndx=DataArrayInt.New();
254         mesh2=mesh.buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
255         mesh2.checkCoherency();
256         self.assertEqual(1,mesh2.getMeshDimension());
257         self.assertEqual(13,mesh2.getNumberOfCells());
258         self.assertEqual(14,revDescIndx.getNbOfElems()); self.assertEqual(14,revDescIndx.getNumberOfTuples());
259         self.assertEqual(6,descIndx.getNbOfElems()); self.assertEqual(6,descIndx.getNumberOfTuples());
260         self.assertEqual(18,desc.getNbOfElems()); self.assertEqual(18,desc.getNumberOfTuples());
261         self.assertEqual(18,revDesc.getNbOfElems()); self.assertEqual(18,revDesc.getNumberOfTuples());
262         expected1=[0,1,2,3, 2,4,5, 6,7,4, 8,9,1,10, 11,12,6,9];
263         self.assertEqual(expected1,list(desc.getValues()));
264         expected2=[0,4,7,10,14,18];
265         self.assertEqual(expected2,list(descIndx.getValues()));
266         expected3=[0,1,3,5,6,8,9,11,12,13,15,16,17,18];
267         self.assertEqual(expected3,list(revDescIndx.getValues()));
268         expected4=[0, 0,3, 0,1, 0, 1,2, 1, 2,4, 2, 3, 3,4, 3, 4, 4];
269         self.assertEqual(expected4,list(revDesc.getValues()));
270         conn=mesh2.getNodalConnectivity();
271         connIndex=mesh2.getNodalConnectivityIndex();
272         expected5=[0,3,6,9,12,15,18,21,24,27,30,33,36,39];
273         self.assertEqual(expected5,list(connIndex.getValues()));
274         expected6=[1, 0, 3, 1, 3, 4, 1, 4, 1, 1, 1, 0, 1, 4, 2, 1, 2, 1, 1, 4, 5, 1, 5, 2, 1, 6, 7, 1, 7, 4, 1, 3, 6, 1, 7, 8, 1, 8, 5];
275         self.assertEqual(expected6,list(conn.getValues()));
276         #
277         eltsV=[1,3];
278         mesh.convertToPolyTypes(eltsV);
279         mesh.checkCoherency();
280         #
281         desc=DataArrayInt.New();
282         descIndx=DataArrayInt.New();
283         revDesc=DataArrayInt.New();
284         revDescIndx=DataArrayInt.New();
285         #
286         mesh2=mesh.buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
287         mesh2.checkCoherency();
288         self.assertEqual(1,mesh2.getMeshDimension());
289         self.assertEqual(13,mesh2.getNumberOfCells());
290         self.assertEqual(14,revDescIndx.getNbOfElems()); self.assertEqual(14,revDescIndx.getNumberOfTuples());
291         self.assertEqual(6,descIndx.getNbOfElems()); self.assertEqual(6,descIndx.getNumberOfTuples());
292         self.assertEqual(18,desc.getNbOfElems()); self.assertEqual(18,desc.getNumberOfTuples());
293         self.assertEqual(18,revDesc.getNbOfElems()); self.assertEqual(18,revDesc.getNumberOfTuples());
294         self.assertEqual(expected1,list(desc.getValues()));
295         self.assertEqual(expected2,list(descIndx.getValues()));
296         self.assertEqual(expected3,list(revDescIndx.getValues()));
297         self.assertEqual(expected4,list(revDesc.getValues()));
298         conn=mesh2.getNodalConnectivity();
299         connIndex=mesh2.getNodalConnectivityIndex();
300         self.assertEqual(expected5,list(connIndex.getValues()));
301         self.assertEqual(expected6,list(conn.getValues()));
302         pass
303     
304     def testDescConn3D(self):
305         mesh=MEDCouplingDataForTest.build3DTargetMesh_1();
306         desc=DataArrayInt.New();
307         descIndx=DataArrayInt.New();
308         revDesc=DataArrayInt.New();
309         revDescIndx=DataArrayInt.New();
310         #
311         mesh2=mesh.buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
312         mesh2.checkCoherency();
313         self.assertEqual(2,mesh2.getMeshDimension());
314         self.assertEqual(36,mesh2.getNumberOfCells());
315         self.assertEqual(37,revDescIndx.getNbOfElems()); self.assertEqual(37,revDescIndx.getNumberOfTuples());
316         self.assertEqual(9,descIndx.getNbOfElems()); self.assertEqual(9,descIndx.getNumberOfTuples());
317         self.assertEqual(48,desc.getNbOfElems()); self.assertEqual(48,desc.getNumberOfTuples());
318         self.assertEqual(48,revDesc.getNbOfElems()); self.assertEqual(48,revDesc.getNumberOfTuples());
319         expected1=[0, 6, 12, 18, 24, 30, 36, 42, 48]
320         expected2=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 3, 11, 12, 4, 13, 14, 15, 16, 17, 10, 18, 19, 13, 1, 20, 21, 22, 23, 24, 7, 25, 26, 27, 28, 22, 12, 29, 23, 30, 31, 32, 17, 33, 28, 34, 35, 30]
321         expected3=[0, 1, 3, 4, 6, 8, 9, 10, 12, 13, 14, 16, 17, 19, 21, 22, 23, 24, 26, 27, 28, 29, 30, 32, 34, 35, 36, 37, 38, 40, 41, 43, 44, 45, 46, 47, 48]
322         expected4=[0, 0, 4, 0, 0, 1, 0, 2, 0, 1, 1, 5, 1, 1, 1, 3, 2, 2, 6, 2, 3, 2, 2, 3, 3, 7, 3, 3, 4, 4, 4, 5, 4, 6, 4, 5, 5, 5, 5, 7, 6, 6, 7, 6, 6, 7, 7, 7]
323         expected5=[0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115, 120, 125, 130, 135, 140, 145, 150, 155, 160, 165, 170, 175, 180]
324         expected6=[4, 0, 1, 4, 3, 4, 9, 12, 13, 10, 4, 0, 9, 10, 1, 4, 1, 10, 13, 4, 4, 4, 13, 12, 3, 4, 3, 12, 9, 0, 4, 1, 2, 5, 4, 4, 10, 13, 14, 11, 4, 1, 10, 11, 2, 4, 2, 11, 14,
325                    5, 4, 5, 14, 13, 4, 4, 3, 4, 7, 6, 4, 12, 15, 16, 13, 4, 4, 13, 16, 7, 4, 7, 16, 15, 6, 4, 6, 15, 12, 3, 4, 4, 5, 8, 7, 4, 13, 16, 17, 14, 4, 5, 14, 17, 8, 4, 8,
326                    17, 16, 7, 4, 18, 21, 22, 19, 4, 9, 18, 19, 10, 4, 10, 19, 22, 13, 4, 13, 22, 21, 12, 4, 12, 21, 18, 9, 4, 19, 22, 23, 20, 4, 10, 19, 20, 11, 4, 11, 20, 23, 14, 4,
327                    14, 23, 22, 13, 4, 21, 24, 25, 22, 4, 13, 22, 25, 16, 4, 16, 25, 24, 15, 4, 15, 24, 21, 12, 4, 22, 25, 26, 23, 4, 14, 23, 26, 17, 4, 17, 26, 25, 16]
328         expected7=[4, 0, 1, 4, 3, 4, 9, 12, 13, 10, 4, 0, 9, 10, 1, 4, 1, 10, 13, 4, 4, 4, 13, 12, 3, 4, 3, 12, 9, 0, 5, 1, 2, 5, 4, 5, 10, 13, 14, 11, 5, 1, 10, 11, 2, 5, 2, 11, 14,
329                    5, 5, 5, 14, 13, 4, 4, 3, 4, 7, 6, 4, 12, 15, 16, 13, 4, 4, 13, 16, 7, 4, 7, 16, 15, 6, 4, 6, 15, 12, 3, 5, 4, 5, 8, 7, 5, 13, 16, 17, 14, 5, 5, 14, 17, 8, 5, 8,
330                    17, 16, 7, 4, 18, 21, 22, 19, 4, 9, 18, 19, 10, 4, 10, 19, 22, 13, 4, 13, 22, 21, 12, 4, 12, 21, 18, 9, 4, 19, 22, 23, 20, 4, 10, 19, 20, 11, 4, 11, 20, 23, 14, 4,
331                    14, 23, 22, 13, 4, 21, 24, 25, 22, 4, 13, 22, 25, 16, 4, 16, 25, 24, 15, 4, 15, 24, 21, 12, 4, 22, 25, 26, 23, 4, 14, 23, 26, 17, 4, 17, 26, 25, 16]
332         
333         self.assertEqual(expected1,list(descIndx.getValues()));
334         self.assertEqual(expected2,list(desc.getValues()));
335         self.assertEqual(expected3,list(revDescIndx.getValues()));
336         self.assertEqual(expected4,list(revDesc.getValues()));
337         self.assertEqual(expected5,list(mesh2.getNodalConnectivityIndex().getValues()));
338         self.assertEqual(expected6,list(mesh2.getNodalConnectivity().getValues()));
339         #
340         eltsV=[1,3]
341         mesh.convertToPolyTypes(eltsV);
342         mesh.checkCoherency();
343         desc=DataArrayInt.New();
344         descIndx=DataArrayInt.New();
345         revDesc=DataArrayInt.New();
346         revDescIndx=DataArrayInt.New();
347         mesh2=mesh.buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
348         mesh2.checkCoherency();
349         self.assertEqual(2,mesh2.getMeshDimension());
350         self.assertEqual(36,mesh2.getNumberOfCells());
351         self.assertEqual(37,revDescIndx.getNbOfElems()); self.assertEqual(37,revDescIndx.getNumberOfTuples());
352         self.assertEqual(9,descIndx.getNbOfElems()); self.assertEqual(9,descIndx.getNumberOfTuples());
353         self.assertEqual(48,desc.getNbOfElems()); self.assertEqual(48,desc.getNumberOfTuples());
354         self.assertEqual(48,revDesc.getNbOfElems()); self.assertEqual(48,revDesc.getNumberOfTuples());
355         self.assertEqual(expected1,list(descIndx.getValues()));
356         self.assertEqual(expected2,list(desc.getValues()));
357         self.assertEqual(expected3,list(revDescIndx.getValues()));
358         self.assertEqual(expected4,list(revDesc.getValues()));
359         self.assertEqual(expected5,list(mesh2.getNodalConnectivityIndex().getValues()));
360         self.assertEqual(expected7,list(mesh2.getNodalConnectivity().getValues()));
361         pass
362
363     def testFindBoundaryNodes(self):
364         mesh=MEDCouplingDataForTest.build3DTargetMesh_1();
365         boundaryNodes=mesh.findBoundaryNodes();
366         expected1=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26];
367         self.assertEqual(expected1,boundaryNodes.getValues());
368         pass
369
370     def testBoundaryMesh(self):
371         mesh=MEDCouplingDataForTest.build3DTargetMesh_1();
372         mesh2=mesh.buildBoundaryMesh(False);
373         self.assertEqual(24,mesh2.getNumberOfCells());
374         self.assertEqual(26,mesh2.getNumberOfNodes());
375         pass
376
377     def testBuildPartOfMySelf(self):
378         mesh=MEDCouplingDataForTest.build2DTargetMesh_1();
379         mesh.setName("Toto");
380         tab1=[0,4]
381         tab2=[0,2,3]
382         #
383         subMesh=mesh.buildPart(tab1)
384         self.assertTrue(isinstance(subMesh,MEDCouplingUMesh))
385         subMesh=mesh.buildPartOfMySelf(tab1,True);
386         self.assertTrue(isinstance(subMesh,MEDCouplingUMesh))
387         name=subMesh.getName();
388         self.assertEqual(2,len(mesh.getAllGeoTypes()));
389         self.assertEqual(NORM_TRI3,mesh.getAllGeoTypes()[0]);
390         self.assertEqual(NORM_QUAD4,mesh.getAllGeoTypes()[1]);
391         self.assertEqual(1,len(subMesh.getAllGeoTypes()));
392         self.assertEqual(NORM_QUAD4,subMesh.getAllGeoTypes()[0]);
393         self.assertEqual(name,"Toto");
394         self.assertEqual(2,subMesh.getNumberOfCells());
395         subConn=[4,0,3,4,1,4,7,8,5,4];
396         subConnIndex=[0,5,10];
397         self.assertEqual(10,subMesh.getNodalConnectivity().getNbOfElems());
398         self.assertEqual(3,subMesh.getNodalConnectivityIndex().getNbOfElems());
399         self.assertEqual(subConn[0:10],list(subMesh.getNodalConnectivity().getValues()));
400         self.assertEqual(subConnIndex[0:3],list(subMesh.getNodalConnectivityIndex().getValues()));
401         #
402         subMesh=mesh.buildPartOfMySelf(tab2[0:3],True);
403         self.assertTrue(isinstance(subMesh,MEDCouplingUMesh));
404         name=subMesh.getName();
405         self.assertEqual(2,len(subMesh.getAllGeoTypes()));
406         self.assertEqual(NORM_TRI3,subMesh.getAllGeoTypes()[0]);
407         self.assertEqual(NORM_QUAD4,subMesh.getAllGeoTypes()[1]);
408         self.assertEqual(name,"Toto");
409         self.assertEqual(3,subMesh.getNumberOfCells());
410         subConn2=[4,0,3,4,1,3,4,5,2,4,6,7,4,3]
411         subConnIndex2=[0,5,9,14]
412         self.assertEqual(14,subMesh.getNodalConnectivity().getNbOfElems());
413         self.assertEqual(4,subMesh.getNodalConnectivityIndex().getNbOfElems());
414         self.assertEqual(subConn2[0:14],list(subMesh.getNodalConnectivity().getValues()));
415         self.assertEqual(subConnIndex2[0:4],list(subMesh.getNodalConnectivityIndex().getValues()));
416         dd=DataArrayInt.New()
417         dd.alloc(3,1)
418         dd.iota(0)
419         dd.setName("coucou")
420         subMesh=subMesh.buildPartOfMySelf(dd,True);
421         self.assertEqual("coucou",subMesh.getName());
422         pass
423     
424     def testBuildPartOfMySelfNode(self):
425         mesh=MEDCouplingDataForTest.build2DTargetMesh_1();
426         tab1=[5,7,8,4]
427         subMesh=mesh.buildPartOfMySelfNode(tab1[0:4],True);
428         self.assertTrue(isinstance(subMesh,MEDCouplingUMesh))
429         self.assertEqual(1,len(subMesh.getAllGeoTypes()));
430         self.assertEqual(NORM_QUAD4,subMesh.getAllGeoTypes()[0]);
431         self.assertEqual(1,subMesh.getNumberOfCells());
432         self.assertEqual(5,subMesh.getNodalConnectivity().getNbOfElems());
433         self.assertEqual(2,subMesh.getNodalConnectivityIndex().getNbOfElems());
434         subConn=[4,7,8,5,4]
435         subConnIndex=[0,5]
436         self.assertEqual(subConn[0:5],list(subMesh.getNodalConnectivity().getValues()));
437         self.assertEqual(subConnIndex[0:2],list(subMesh.getNodalConnectivityIndex().getValues()));
438         #
439         ddd=DataArrayInt.New()
440         ddd.setValues(tab1[0:2],2,1)
441         ddd.setName("ddd")
442         subMesh=mesh.buildPartOfMySelfNode(ddd,False);
443         self.assertEqual("ddd",subMesh.getName())
444         self.assertTrue(isinstance(subMesh,MEDCouplingUMesh))
445         self.assertEqual(2,len(subMesh.getAllGeoTypes()));
446         self.assertEqual(NORM_TRI3,subMesh.getAllGeoTypes()[0]);
447         self.assertEqual(NORM_QUAD4,subMesh.getAllGeoTypes()[1]);
448         self.assertEqual(3,subMesh.getNumberOfCells());
449         self.assertEqual(14,subMesh.getNodalConnectivity().getNbOfElems());
450         self.assertEqual(4,subMesh.getNodalConnectivityIndex().getNbOfElems());
451         subConn2=[3,4,5,2,4,6,7,4,3,4,7,8,5,4]
452         subConnIndex2=[0,4,9,14]
453         self.assertEqual(subConn2[0:14],list(subMesh.getNodalConnectivity().getValues()));
454         self.assertEqual(subConnIndex2[0:4],list(subMesh.getNodalConnectivityIndex().getValues()));
455         #testing the case where length of tab2 is greater than max number of node per cell.
456         tab2=[0,3,2,1,4,5,6]
457         subMesh=mesh.buildPartOfMySelfNode(tab2[0:7],True);
458         self.assertTrue(isinstance(subMesh,MEDCouplingUMesh))
459         self.assertEqual(2,len(subMesh.getAllGeoTypes()));
460         self.assertEqual(NORM_TRI3,subMesh.getAllGeoTypes()[0]);
461         self.assertEqual(NORM_QUAD4,subMesh.getAllGeoTypes()[1]);
462         self.assertEqual(3,subMesh.getNumberOfCells());
463         pass
464     
465     def testZipCoords(self):
466         mesh=MEDCouplingDataForTest.build2DTargetMesh_1();
467         self.assertEqual(2,len(mesh.getAllGeoTypes()));
468         self.assertEqual(2,mesh.getSpaceDimension());
469         self.assertEqual(9,mesh.getNumberOfNodes());
470         self.assertEqual(5,mesh.getNumberOfCells());
471         oldConn=mesh.getNodalConnectivity().getValues()[0:mesh.getNodalConnectivity().getNbOfElems()];
472         oldConnIndex=mesh.getNodalConnectivityIndex().getValues()[0:mesh.getNumberOfCells()+1]
473         oldCoords=mesh.getCoords();
474         mesh.zipCoords();
475         self.assertEqual(2,len(mesh.getAllGeoTypes()));
476         self.assertEqual(2,mesh.getSpaceDimension());
477         self.assertEqual(9,mesh.getNumberOfNodes());
478         self.assertEqual(5,mesh.getNumberOfCells());
479         self.assertEqual(mesh.getCoords().getValues()[0:2*9],oldCoords.getValues());
480         self.assertEqual(list(oldConn),list(mesh.getNodalConnectivity().getValues()));
481         self.assertEqual(list(oldConnIndex),list(mesh.getNodalConnectivityIndex().getValues()));
482         #
483         tab1=[0,4]
484         subMesh=mesh.buildPartOfMySelf(tab1,True);
485         self.assertTrue(isinstance(subMesh,MEDCouplingUMesh))
486         traducer=subMesh.zipCoordsTraducer();
487         expectedTraducer=[0, 1, -1, 2, 3, 4, -1, 5, 6]
488         self.assertEqual(expectedTraducer,list(traducer.getValues()));
489         self.assertEqual(NORM_QUAD4,subMesh.getAllGeoTypes()[0]);
490         self.assertEqual(2,subMesh.getNumberOfCells());
491         subConn=[4,0,2,3,1,4,5,6,4,3]
492         subConnIndex=[0,5,10]
493         self.assertEqual(7,subMesh.getNumberOfNodes());
494         self.assertEqual(10,subMesh.getNodalConnectivity().getNbOfElems());
495         self.assertEqual(3,subMesh.getNodalConnectivityIndex().getNbOfElems());
496         self.assertEqual(subConn,list(subMesh.getNodalConnectivity().getValues()));
497         self.assertEqual(subConnIndex,list(subMesh.getNodalConnectivityIndex().getValues()));
498         #
499         subMesh=mesh.buildPartOfMySelf(tab1,False);
500         self.assertTrue(isinstance(subMesh,MEDCouplingUMesh))
501         self.assertEqual(NORM_QUAD4,subMesh.getAllGeoTypes()[0]);
502         self.assertEqual(2,subMesh.getNumberOfCells());
503         self.assertEqual(7,subMesh.getNumberOfNodes());
504         self.assertEqual(10,subMesh.getNodalConnectivity().getNbOfElems());
505         self.assertEqual(3,subMesh.getNodalConnectivityIndex().getNbOfElems());
506         self.assertEqual(subConn,list(subMesh.getNodalConnectivity().getValues()));
507         self.assertEqual(subConnIndex,list(subMesh.getNodalConnectivityIndex().getValues()));
508         pass
509     
510     def testZipConnectivity(self):
511         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
512         m2=MEDCouplingDataForTest.build2DTargetMesh_1();
513         cells1=[2,3,4]
514         m3=m2.buildPartOfMySelf(cells1,True);
515         self.assertTrue(isinstance(m3,MEDCouplingUMesh))
516         m4=MEDCouplingDataForTest.build2DSourceMesh_1();
517         m5=MEDCouplingUMesh.MergeUMeshes(m1,m3);
518         m6=MEDCouplingUMesh.MergeUMeshes(m5,m4);
519         #
520         self.assertEqual(10,m6.getNumberOfCells());
521         self.assertEqual(22,m6.getNumberOfNodes());
522         (arr,areNodesMerged,newNbOfNodes)=m6.mergeNodes(1e-13);
523         self.assertTrue(areNodesMerged);
524         self.assertEqual(10,m6.getNumberOfCells());
525         self.assertEqual(9,m6.getNumberOfNodes());
526         #
527         arr=m6.zipConnectivityTraducer(0);
528         self.assertEqual(7,m6.getNumberOfCells());
529         m7=m6.clone(True);
530         arr=m6.zipConnectivityTraducer(0);
531         self.assertTrue(m7.isEqual(m6,1e-12));
532         self.assertEqual(7,m6.getNumberOfCells());
533         pass
534     
535     def testEqualMesh(self):
536         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
537         mesh2=MEDCouplingDataForTest.build2DTargetMesh_1();
538         #
539         self.assertTrue(mesh1.isEqual(mesh1,1e-12));
540         #
541         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
542         self.assertTrue(mesh2.isEqual(mesh1,1e-12));
543         pt=mesh2.getCoords().getValues();
544         tmp=pt[1]
545         mesh2.getCoords().setIJ(0,1,5.999);
546         self.assertTrue(not mesh1.isEqual(mesh2,1e-12));
547         self.assertTrue(not mesh2.isEqual(mesh1,1e-12));
548         mesh2.getCoords().setIJ(0,1,tmp);
549         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
550         self.assertTrue(mesh2.isEqual(mesh1,1e-12));
551         #
552         pt2=mesh1.getNodalConnectivity().getValues();
553         mesh1.getNodalConnectivity().setIJ(5,0,int(pt2[5])+1);
554         self.assertTrue(not mesh1.isEqual(mesh2,1e-12));
555         self.assertTrue(not mesh2.isEqual(mesh1,1e-12));
556         mesh1.getNodalConnectivity().setIJ(5,0,int(pt2[5]));
557         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
558         self.assertTrue(mesh2.isEqual(mesh1,1e-12));
559         #
560         pt2=mesh1.getNodalConnectivityIndex().getValues();
561         mesh1.getNodalConnectivityIndex().setIJ(1,0,int(pt2[1]+1));
562         self.assertTrue(not mesh1.isEqual(mesh2,1e-12));
563         self.assertTrue(not mesh2.isEqual(mesh1,1e-12));
564         mesh1.getNodalConnectivityIndex().setIJ(1,0,int(pt2[1]));
565         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
566         self.assertTrue(mesh2.isEqual(mesh1,1e-12));
567         #
568         tmp3=mesh1.getName();
569         mesh1.setName("lllll");
570         self.assertTrue(not mesh1.isEqual(mesh2,1e-12));
571         self.assertTrue(not mesh2.isEqual(mesh1,1e-12));
572         mesh1.setName(tmp3);
573         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
574         self.assertTrue(mesh2.isEqual(mesh1,1e-12));
575         #
576         tmp3=mesh2.getCoords().getInfoOnComponent(1);
577         mesh2.getCoords().setInfoOnComponent(1,"kkkkkk");
578         self.assertTrue(not mesh1.isEqual(mesh2,1e-12));
579         self.assertTrue(not mesh2.isEqual(mesh1,1e-12));
580         mesh2.getCoords().setInfoOnComponent(1,tmp3);
581         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
582         self.assertTrue(mesh2.isEqual(mesh1,1e-12));
583         pass
584     
585     def testEqualFieldDouble(self):
586         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
587         mesh2=MEDCouplingDataForTest.build2DTargetMesh_1();
588         #
589         fieldOnCells1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
590         fieldOnCells1.setMesh(mesh1);
591         fieldOnCells2=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
592         fieldOnCells2.setMesh(mesh2);
593         #
594         self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
595         self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
596         #
597         fieldOnNodes1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
598         self.assertTrue(not fieldOnCells1.isEqual(fieldOnNodes1,1e-12,1e-15));
599         self.assertTrue(not fieldOnNodes1.isEqual(fieldOnCells1,1e-12,1e-15));
600         #
601         fieldOnCells2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
602         self.assertEqual(fieldOnCells2.getMesh(),None) # to check that convertMesh wrapping do not raise but return Py_None
603         self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
604         self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
605         fieldOnCells1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
606         self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
607         self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
608         fieldOnCells1.setTime(4.,6,7);
609         self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
610         self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
611         fieldOnCells2.setTime(4.,6,7);
612         self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
613         self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
614         fieldOnCells1.setName("Power");
615         self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
616         self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
617         fieldOnCells2.setName("Power");
618         self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
619         self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
620         #
621         fieldOnCells1.setMesh(mesh1);
622         self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
623         self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
624         fieldOnCells2.setMesh(mesh1);
625         self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
626         self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
627         arr=DataArrayDouble.New();
628         arr.setName("popo");
629         arr.setValues(mesh1.getNumberOfCells()*3*[6.],mesh1.getNumberOfCells(),3);
630         fieldOnCells1.setArray(arr);
631         self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
632         self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
633         fieldOnCells2.setArray(arr);
634         self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
635         self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
636         #
637         arr2=arr.deepCpy();
638         fieldOnCells2.setArray(arr2);
639         self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
640         self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
641         arr.setIJ(1,2,6.1);
642         self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
643         self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
644         arr.setIJ(1,2,6.);
645         self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
646         self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
647         arr2.setName("popo2");
648         self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
649         self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
650         #
651         arr2.setName("popo");
652         self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
653         self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
654         #
655         arr2.setInfoOnComponent(2,"jjj");
656         self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
657         self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
658         arr.setInfoOnComponent(2,"jjj");
659         self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
660         self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
661         pass
662
663     def testNatureChecking(self):
664         field=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
665         field.setNature(Integral);
666         field.setNature(ConservativeVolumic);
667         field.setNature(IntegralGlobConstraint);
668         field=MEDCouplingFieldDouble.New(ON_NODES,NO_TIME);
669         field.setNature(ConservativeVolumic);
670         self.assertRaises(InterpKernelException,field.setNature,Integral);
671         self.assertRaises(InterpKernelException,field.setNature,IntegralGlobConstraint);
672         pass
673
674     def testBuildSubMeshData(self):
675         targetMesh=MEDCouplingDataForTest.build2DTargetMesh_1()
676         #check buildSubMesh on field on cells
677         fieldCells=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
678         fieldCells.setMesh(targetMesh);
679         elts=[1,2,4]
680         ret1,di=fieldCells.buildSubMeshData(elts);
681         self.assertTrue(isinstance(ret1,MEDCouplingUMesh))
682         self.assertEqual(3,ret1.getNumberOfCells());
683         self.assertEqual(9,ret1.getNumberOfNodes());
684         self.assertEqual(3,di.getNumberOfTuples());
685         self.assertEqual(1,di.getNumberOfComponents());
686         toCheck=di.getValues();
687         self.assertTrue(elts,toCheck);
688         #check buildSubMesh on field on nodes
689         fieldNodes=MEDCouplingFieldDouble.New(ON_NODES,NO_TIME);
690         fieldNodes.setMesh(targetMesh);
691         ret2,di=fieldNodes.buildSubMeshData(elts);
692         self.assertTrue(isinstance(ret2,MEDCouplingUMesh))
693         self.assertEqual(3,ret2.getNumberOfCells());
694         self.assertEqual(6,ret2.getNumberOfNodes());
695         self.assertEqual(6,di.getNumberOfTuples());
696         self.assertEqual(1,di.getNumberOfComponents());
697         toCheck=di.getValues();
698         expected=[1,2,4,5,7,8]
699         self.assertEqual(expected,list(toCheck));
700         pass
701     
702     def testExtrudedMesh1(self):
703         mesh3D,mesh2D=MEDCouplingDataForTest.build3DExtrudedUMesh_1();
704         ext=MEDCouplingExtrudedMesh.New(mesh3D,mesh2D,1);
705         self.assertEqual(18,ext.getNumberOfCells());
706         self.assertEqual(60,ext.getNumberOfNodes());
707         ids3D=ext.getMesh3DIds();
708         ids3DExpected=[5,4,3,2,1,0, 11,10,9,8,7,6, 17,16,15,14,13,12]
709         self.assertEqual(18,ids3D.getNumberOfTuples());
710         self.assertEqual(1,ids3D.getNumberOfComponents());
711         self.assertEqual(ids3DExpected,list(ids3D.getValues()));
712         mesh1D=ext.getMesh1D();
713         self.assertEqual(4,mesh1D.getNumberOfNodes());
714         self.assertEqual(3,mesh1D.getNumberOfCells());
715         mesh1DExpected=[0.66666666666666663, 1.4583333333333333, 0, 0.66666666666666663,
716                         1.4583333333333333, 1, 0.66666666666666663, 1.4583333333333333,
717                         2, 0.66666666666666663, 1.4583333333333333, 3]
718         mesh1DCoords=mesh1D.getCoords();
719         self.assertEqual(4,mesh1DCoords.getNumberOfTuples());
720         self.assertEqual(3,mesh1DCoords.getNumberOfComponents());
721         self.assertEqual(mesh1DExpected,mesh1DCoords.getValues());
722         conn1D=mesh1D.getNodalConnectivity();
723         self.assertEqual(9,conn1D.getNumberOfTuples());
724         self.assertEqual(1,conn1D.getNumberOfComponents());
725         conn1DExpected=[1,0,1,1,1,2,1,2,3]
726         self.assertEqual(conn1DExpected,list(conn1D.getValues()));
727         pass
728
729     def testExtrudedMesh3(self):
730         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
731         m1.changeSpaceDimension(3);
732         m2=MEDCouplingDataForTest.buildCU1DMesh_U();
733         m2.changeSpaceDimension(3);
734         center=[0.,0.,0.]
735         vector=[0.,1.,0.]
736         m2.rotate(center,vector,-pi/2.);
737         m3=m1.buildExtrudedMesh(m2,0);
738         #
739         m4=MEDCouplingExtrudedMesh.New(m3,m1,0);
740         self.assertEqual(15,m4.getNumberOfCells());
741         self.assertEqual(5,m4.getMesh2D().getNumberOfCells());
742         self.assertEqual(3,m4.getMesh1D().getNumberOfCells());
743         m3DIds=m4.getMesh3DIds().getValues();
744         self.assertEqual(range(15),list(m3DIds));
745         #some random in cells to check that extrusion alg find it correctly
746         expected1=[1,3,2,0,6,5,7,10,11,8,12,9,14,13,4]
747         m3.renumberCells(expected1,False);
748         m4=MEDCouplingExtrudedMesh.New(m3,m1,0);
749         self.assertEqual(15,m4.getNumberOfCells());
750         self.assertEqual(5,m4.getMesh2D().getNumberOfCells());
751         self.assertEqual(3,m4.getMesh1D().getNumberOfCells());
752         m3DIds=m4.getMesh3DIds().getValues();
753         self.assertEqual(expected1,list(m3DIds));
754         #play with polygons and polyedrons
755         cells=[2,3]
756         m1.convertToPolyTypes(cells);
757         m3=m1.buildExtrudedMesh(m2,0);
758         self.assertEqual(NORM_HEXA8,m3.getTypeOfCell(0));
759         self.assertEqual(NORM_PENTA6,m3.getTypeOfCell(1));
760         self.assertEqual(NORM_POLYHED,m3.getTypeOfCell(2));
761         self.assertEqual(NORM_POLYHED,m3.getTypeOfCell(3));
762         self.assertEqual(NORM_HEXA8,m3.getTypeOfCell(4));
763         m3.renumberCells(expected1,False);
764         m4=MEDCouplingExtrudedMesh.New(m3,m1,0);
765         self.assertEqual(15,m4.getNumberOfCells());
766         self.assertEqual(5,m4.getMesh2D().getNumberOfCells());
767         self.assertEqual(3,m4.getMesh1D().getNumberOfCells());
768         m3DIds=m4.getMesh3DIds().getValues();
769         self.assertEqual(expected1,list(m3DIds));
770         pass
771
772     def testExtrudedMesh4(self):
773         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
774         cells=[2,4];
775         m1.convertToPolyTypes(cells);
776         m1.changeSpaceDimension(3);
777         m2=MEDCouplingDataForTest.buildCU1DMesh_U();
778         m2.changeSpaceDimension(3);
779         center=[0.,0.,0.]
780         vector=[0.,1.,0.]
781         m2.rotate(center,vector,-pi/2.);
782         m3=m1.buildExtrudedMesh(m2,0);
783         expected1=[1,3,2,0,6,5,7,10,11,8,12,9,14,13,4]
784         rexpected1=[3, 0, 2, 1, 14, 5, 4, 6, 9, 11, 7, 8, 10, 13, 12]
785         m3.renumberCells(expected1,False);
786         m4=MEDCouplingExtrudedMesh.New(m3,m1,0);
787         self.assertEqual(NORM_HEXA8,m4.getTypeOfCell(0));
788         self.assertEqual(NORM_HEXA8,m4.getTypeOfCell(1));
789         self.assertEqual(NORM_POLYHED,m4.getTypeOfCell(2));
790         self.assertEqual(NORM_PENTA6,m4.getTypeOfCell(7));
791         f=m4.getMeasureField(True);
792         arr=f.getArray();
793         self.assertEqual(15,arr.getNumberOfTuples());
794         self.assertEqual(1,arr.getNumberOfComponents());
795         arrPtr=arr.getValues();
796         expected2=[0.075,0.0375,0.0375,0.075,0.075,
797                    0.1125,0.05625,0.05625,0.1125,0.1125,
798                    0.0625,0.03125,0.03125,0.0625,0.0625]
799         for i in xrange(15):
800             self.assertAlmostEqual(expected2[rexpected1[i]],arrPtr[i],16);
801             pass
802         m5=m4.build3DUnstructuredMesh();
803         self.assertTrue(m5.isEqual(m3,1e-12));
804         f=m5.getMeasureField(True);
805         f.setMesh(m4)
806         self.assertTrue(isinstance(f.getMesh(),MEDCouplingExtrudedMesh))
807         arr=f.getArray();
808         arrPtr=arr.getValues();
809         for i in xrange(15):
810             self.assertAlmostEqual(expected2[rexpected1[i]],arrPtr[i],15);
811             pass
812         pass
813
814     def testFindCommonNodes(self):
815         targetMesh=MEDCouplingDataForTest.build3DTargetMesh_1();
816         comm,commI=targetMesh.findCommonNodes(1e-10,-1);
817         self.assertEqual(1,commI.getNumberOfTuples());
818         self.assertEqual(0,comm.getNumberOfTuples());
819         o2n,newNbOfNodes=targetMesh.buildNewNumberingFromCommonNodesFormat(comm,commI);
820         self.assertEqual(27,newNbOfNodes);
821         self.assertEqual(27,o2n.getNumberOfTuples());
822         o2nExp1=range(27)
823         self.assertEqual(o2nExp1,list(o2n.getValues()));
824         #
825         targetMesh=MEDCouplingDataForTest.build3DTargetMeshMergeNode_1();
826         self.assertEqual(31,targetMesh.getNumberOfNodes());
827         comm,commI=targetMesh.findCommonNodes(1e-10);# testing default parameter
828         self.assertEqual(3,commI.getNumberOfTuples());
829         self.assertEqual(6,comm.getNumberOfTuples());
830         commExpected=[1,27,28,29,23,30]
831         commIExpected=[0,4,6]
832         self.assertEqual(commExpected,list(comm.getValues()));
833         self.assertEqual(commIExpected,list(commI.getValues()));
834         o2n,newNbOfNodes=targetMesh.buildNewNumberingFromCommonNodesFormat(comm,commI);
835         self.assertEqual(31,o2n.getNumberOfTuples());
836         self.assertEqual(27,newNbOfNodes);
837         o2nExp2=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
838                  21,22,23,24,25,26,1,1,1,23]
839         self.assertEqual(o2nExp2,list(o2n.getValues()));
840         #
841         targetMesh=MEDCouplingDataForTest.build3DTargetMesh_1();
842         time=targetMesh.getTimeOfThis();
843         o2n,areNodesMerged,newNbOfNodes=targetMesh.mergeNodes(1e-10);
844         targetMesh.updateTime();
845         self.assertEqual(time,targetMesh.getTimeOfThis());
846         self.assertTrue(not areNodesMerged);
847         #
848         targetMesh=MEDCouplingDataForTest.build3DTargetMeshMergeNode_1();
849         time=targetMesh.getTimeOfThis();
850         o2n,areNodesMerged,newNbOfNodes=targetMesh.mergeNodes(1e-10);
851         targetMesh.updateTime();
852         self.assertTrue(time!=targetMesh.getTimeOfThis());
853         self.assertTrue(areNodesMerged);
854         connExp=[18,0,1,4,3,9,10,13,12, 18,1,2,5,4,10,11,14,13, 18,3,4,7,6,12,13,16,15,
855                  18,4,5,8,7,13,14,17,16,
856                  18,9,10,13,12,18,19,22,21, 18,10,11,14,13,19,20,23,22, 18,12,13,16,15,21,22,25,24,
857                  18,13,14,17,16,22,23,26,25]
858         self.assertEqual(72,targetMesh.getNodalConnectivity().getNumberOfTuples());
859         self.assertEqual(connExp,list(targetMesh.getNodalConnectivity().getValues()));
860         self.assertEqual(27,targetMesh.getCoords().getNumberOfTuples());
861         coordsExp=[ 0., 0., 0., 50., 0., 0. , 200., 0., 0.  , 0., 50., 0., 50., 50., 0. ,
862                     200., 50., 0.,   0., 200., 0., 50., 200., 0. , 200., 200., 0. ,
863                     0., 0., 50., 50., 0., 50. , 200., 0., 50.  , 0., 50., 50., 50.,
864                     50., 50. , 200., 50., 50.,   0., 200., 50., 50., 200., 50. ,
865                     200., 200., 50. , 0., 0., 200., 50., 0., 200. , 200., 0., 200.  
866                     , 0., 50., 200., 50., 50., 200. , 200., 50., 200., 
867                     0., 200., 200., 50., 200., 200. , 200., 200., 200. ]
868         self.assertEqual(coordsExp,targetMesh.getCoords().getValues());
869         # 2D
870         targetMesh=MEDCouplingDataForTest.build2DTargetMeshMergeNode_1();
871         self.assertEqual(18,targetMesh.getNumberOfNodes());
872         time=targetMesh.getTimeOfThis();
873         o2n,areNodesMerged,newNbOfNodes=targetMesh.mergeNodes(1e-10);
874         self.assertTrue(time!=targetMesh.getTimeOfThis());
875         self.assertTrue(areNodesMerged);
876         self.assertEqual(9,targetMesh.getNumberOfNodes());
877         connExp2=[4,0,4,3,1, 3,1,3,2, 3,3,5,2, 4,4,6,7,3, 4,7,8,5,3]
878         self.assertEqual(23,targetMesh.getNodalConnectivity().getNumberOfTuples());
879         self.assertEqual(connExp2,list(targetMesh.getNodalConnectivity().getValues()));
880         coordsExp2=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, 0.2,0.2, -0.3,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7]
881         self.assertEqual(9,targetMesh.getCoords().getNumberOfTuples());
882         self.assertEqual(coordsExp2,targetMesh.getCoords().getValues());
883         pass
884
885     def testCheckButterflyCells(self):
886         sourceMesh=MEDCouplingDataForTest.build2DTargetMesh_1();
887         cells=sourceMesh.checkButterflyCells();
888         self.assertEqual(0,len(cells));
889         conn=sourceMesh.getNodalConnectivity()
890         tmp=conn.getIJ(15,0)
891         conn.setIJ(15,0,conn.getIJ(16,0))
892         conn.setIJ(16,0,tmp)
893         cells=sourceMesh.checkButterflyCells();
894         self.assertEqual(1,len(cells));
895         self.assertEqual([3],cells.getValues());
896         tmp=conn.getIJ(15,0)
897         conn.setIJ(15,0,conn.getIJ(16,0))
898         conn.setIJ(16,0,tmp)
899         cells=sourceMesh.checkButterflyCells();
900         self.assertEqual(0,len(cells));
901         # 3D surf
902         sourceMesh=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
903         cells=sourceMesh.checkButterflyCells();
904         self.assertEqual(0,len(cells));
905         conn=sourceMesh.getNodalConnectivity()
906         tmp=conn.getIJ(15,0)
907         conn.setIJ(15,0,conn.getIJ(16,0))
908         conn.setIJ(16,0,tmp)
909         cells=sourceMesh.checkButterflyCells();
910         self.assertEqual(1,len(cells));
911         self.assertEqual([3],cells.getValues());
912         tmp=conn.getIJ(15,0)
913         conn.setIJ(15,0,conn.getIJ(16,0))
914         conn.setIJ(16,0,tmp)
915         cells=sourceMesh.checkButterflyCells();
916         self.assertEqual(0,len(cells));
917         pass
918
919     def testMergeMesh1(self):
920         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
921         m2=MEDCouplingDataForTest.build2DSourceMesh_1();
922         vec=[1.,0.]
923         m2.translate(vec);
924         m3=m1.mergeMyselfWith(m2);
925         self.assertTrue(isinstance(m3,MEDCouplingUMesh));
926         m3.checkCoherency();
927         m4=MEDCouplingDataForTest.build2DTargetMeshMerged_1();
928         self.assertTrue(m3.isEqual(m4,1.e-12));
929         da,isMerged,newNbOfNodes=m3.mergeNodes(1.e-12);
930         self.assertEqual(11,m3.getNumberOfNodes());
931         self.assertTrue(isMerged);
932         pass
933
934     def testMergeMeshOnSameCoords1(self):
935         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
936         m2=MEDCouplingDataForTest.build2DTargetMesh_1();
937         cells=range(5);
938         m2.convertToPolyTypes(cells);
939         m1.tryToShareSameCoords(m2,1e-12);
940         m3=MEDCouplingDataForTest.build2DTargetMesh_1();
941         m3.tryToShareSameCoords(m2,1e-12);
942         meshes=[m1,m2,m3]
943         m4=MEDCouplingUMesh.MergeUMeshesOnSameCoords(meshes);
944         m4.checkCoherency();
945         self.assertEqual(15,m4.getNumberOfCells());
946         cells1=[0,1,2,3,4]
947         m1_1=m4.buildPartOfMySelf(cells1,True);
948         m1_1.setName(m1.getName());
949         self.assertTrue(m1.isEqual(m1_1,1e-12));
950         cells2=[5,6,7,8,9]
951         m2_1=m4.buildPartOfMySelf(cells2,True);
952         m2_1.setName(m2.getName());
953         self.assertTrue(m2.isEqual(m2_1,1e-12));
954         cells3=[10,11,12,13,14]
955         m3_1=m4.buildPartOfMySelf(cells3,True);
956         m3_1.setName(m3.getName());
957         self.assertTrue(m3.isEqual(m3_1,1e-12));
958         pass
959
960     def testMergeField1(self):
961         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
962         m2=MEDCouplingDataForTest.build2DSourceMesh_1();
963         vec=[1.,0.]
964         m2.translate(vec);
965         f1=m1.getMeasureField(True);
966         f2=m2.getMeasureField(True);
967         f3=MEDCouplingFieldDouble.MergeFields(f1,f2);
968         f3.checkCoherency();
969         m4=MEDCouplingDataForTest.build2DTargetMeshMerged_1();
970         self.assertTrue(f3.getMesh().isEqual(m4,1.e-12));
971         name=f3.getName();
972         self.assertEqual(name,"MeasureOfMesh_");
973         self.assertEqual(f3.getTypeOfField(),ON_CELLS);
974         self.assertEqual(f3.getTimeDiscretization(),ONE_TIME);
975         self.assertEqual(1,f3.getNumberOfComponents());
976         self.assertEqual(7,f3.getNumberOfTuples());
977         values=[0.25,0.125,0.125,0.25,0.25,0.5,0.5]
978         tmp=f3.getArray().getValues();
979         self.assertEqual(len(values),len(tmp))
980         for i in xrange(7):
981             self.assertTrue(abs(values[i]-tmp[i])<1e-12)
982             pass
983         pass
984
985     def testFillFromAnalytic(self):
986         m=MEDCouplingDataForTest.build2DTargetMesh_1();
987         m.setTime(3.4,5,6); m.setTimeUnit("us");
988         f1=m.fillFromAnalytic(ON_CELLS,1,"x+y");
989         self.assertAlmostEqual(3.4,f1.getTime()[0],12) ; self.assertEqual(5,f1.getTime()[1]) ; self.assertEqual(6,f1.getTime()[2])
990         self.assertEqual("us",f1.getTimeUnit())
991         f1.checkCoherency();                    
992         self.assertEqual(f1.getTypeOfField(),ON_CELLS);
993         self.assertEqual(f1.getTimeDiscretization(),ONE_TIME);
994         self.assertEqual(1,f1.getNumberOfComponents());
995         self.assertEqual(5,f1.getNumberOfTuples());
996         values1=[-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9]
997         tmp=f1.getArray().getValues();
998         self.assertEqual(len(values1),len(tmp))
999         for i in xrange(len(tmp)):
1000             self.assertTrue(abs(tmp[i]-values1[i])<1.e-12)
1001             pass
1002         #
1003         f1=m.fillFromAnalytic(ON_NODES,1,"x+y");
1004         f1.checkCoherency();
1005         self.assertEqual(f1.getTypeOfField(),ON_NODES);
1006         self.assertEqual(f1.getTimeDiscretization(),ONE_TIME);
1007         self.assertEqual(1,f1.getNumberOfComponents());
1008         self.assertEqual(9,f1.getNumberOfTuples());
1009         values2=[-0.6,-0.1,0.4,-0.1,0.4,0.9,0.4,0.9,1.4]
1010         tmp=f1.getArray().getValues();
1011         self.assertEqual(len(values2),len(tmp))
1012         for i in xrange(len(tmp)):
1013             self.assertTrue(abs(tmp[i]-values2[i])<1.e-12)
1014             pass
1015         #
1016         f1=m.fillFromAnalytic(ON_NODES,2,"(x+y)*IVec+(2*(x+y))*JVec");
1017         f1.checkCoherency();
1018         self.assertEqual(f1.getTypeOfField(),ON_NODES);
1019         self.assertEqual(f1.getTimeDiscretization(),ONE_TIME);
1020         self.assertEqual(2,f1.getNumberOfComponents());
1021         self.assertEqual(9,f1.getNumberOfTuples());
1022         values3=[-0.6,-1.2,-0.1,-0.2,0.4,0.8,-0.1,-0.2,0.4,0.8,0.9,1.8,0.4,0.8,0.9,1.8,1.4,2.8]
1023         tmp=f1.getArray().getValues();
1024         self.assertEqual(len(values3),len(tmp))
1025         for i in xrange(len(tmp)):
1026             self.assertTrue(abs(tmp[i]-values3[i])<1.e-12)
1027             pass
1028         values4=f1.accumulate();
1029         self.assertEqual(2,len(values4))
1030         self.assertTrue(abs(3.6-values4[0])<1.e-12);
1031         self.assertTrue(abs(7.2-values4[1])<1.e-12);
1032         values4=f1.integral(True);
1033         self.assertEqual(2,len(values4))
1034         self.assertTrue(abs(0.5-values4[0])<1.e-12);
1035         self.assertTrue(abs(1.-values4[1])<1.e-12);
1036         #
1037         self.assertRaises(InterpKernelException,m.fillFromAnalytic,ON_NODES,1,"1./(x-0.2)");
1038         pass
1039
1040     def testFillFromAnalytic2(self):
1041         m=MEDCouplingDataForTest.build2DTargetMesh_1();
1042         f1=m.fillFromAnalytic(ON_CELLS,1,"y+x");
1043         f1.checkCoherency();
1044         self.assertEqual(f1.getTypeOfField(),ON_CELLS);
1045         self.assertEqual(f1.getTimeDiscretization(),ONE_TIME);
1046         self.assertEqual(1,f1.getNumberOfComponents());
1047         self.assertEqual(5,f1.getNumberOfTuples());
1048         values1=[-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9]
1049         tmp=f1.getArray().getValues();
1050         self.assertEqual(len(values1),len(tmp))
1051         for i in xrange(len(values1)):
1052             self.assertTrue(abs(values1[i]-tmp[i])<1.e-12);
1053             pass
1054         #
1055         f1=m.fillFromAnalytic(ON_NODES,1,"y+2*x");
1056         f1.checkCoherency();
1057         self.assertEqual(f1.getTypeOfField(),ON_NODES);
1058         self.assertEqual(f1.getTimeDiscretization(),ONE_TIME);
1059         self.assertEqual(1,f1.getNumberOfComponents());
1060         self.assertEqual(9,f1.getNumberOfTuples());
1061         values2=[-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1]
1062         tmp=f1.getArray().getValues();
1063         self.assertEqual(len(values2),len(tmp))
1064         for i in xrange(len(values2)):
1065             self.assertTrue(abs(values2[i]-tmp[i])<1.e-12);
1066             pass
1067         f1=m.fillFromAnalytic(ON_NODES,1,"2.*x+y");
1068         f1.checkCoherency();
1069         self.assertEqual(f1.getTypeOfField(),ON_NODES);
1070         self.assertEqual(f1.getTimeDiscretization(),ONE_TIME);
1071         self.assertEqual(1,f1.getNumberOfComponents());
1072         self.assertEqual(9,f1.getNumberOfTuples());
1073         tmp=f1.getArray().getValues();
1074         values2Bis=[-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1]
1075         self.assertEqual(len(values2Bis),len(tmp))
1076         for i in xrange(len(values2Bis)):
1077             self.assertTrue(abs(values2Bis[i]-tmp[i])<1.e-12);
1078             pass
1079         #
1080         f1=m.fillFromAnalytic(ON_NODES,2,"(x+y)*IVec+2*(x+y)*JVec");
1081         f1.checkCoherency();
1082         self.assertEqual(f1.getTypeOfField(),ON_NODES);
1083         self.assertEqual(f1.getTimeDiscretization(),ONE_TIME);
1084         self.assertEqual(2,f1.getNumberOfComponents());
1085         self.assertEqual(9,f1.getNumberOfTuples());
1086         values3=[-0.6,-1.2,-0.1,-0.2,0.4,0.8,-0.1,-0.2,0.4,0.8,0.9,1.8,0.4,0.8,0.9,1.8,1.4,2.8]
1087         tmp=f1.getArray().getValues();
1088         self.assertEqual(len(values3),len(tmp))
1089         for i in xrange(len(values3)):
1090             self.assertTrue(abs(values3[i]-tmp[i])<1.e-12);
1091             pass
1092         values4=f1.accumulate();
1093         self.assertTrue(abs(3.6-values4[0])<1.e-12);
1094         self.assertTrue(abs(7.2-values4[1])<1.e-12);
1095         values4=f1.integral(True);
1096         self.assertTrue(abs(0.5-values4[0])<1.e-12);
1097         self.assertTrue(abs(1.-values4[1])<1.e-12);
1098         pass
1099
1100     def testApplyFunc(self):
1101         m=MEDCouplingDataForTest.build2DTargetMesh_1();
1102         f1=m.fillFromAnalytic(ON_NODES,2,"(x+y)*IVec+(2*(x+y))*JVec");
1103         f1.checkCoherency();
1104         self.assertEqual(f1.getTypeOfField(),ON_NODES);
1105         self.assertEqual(f1.getTimeDiscretization(),ONE_TIME);
1106         self.assertEqual(2,f1.getNumberOfComponents());
1107         self.assertEqual(9,f1.getNumberOfTuples());
1108         f1.applyFunc(1,"x+y");
1109         self.assertEqual(f1.getTypeOfField(),ON_NODES);
1110         self.assertEqual(f1.getTimeDiscretization(),ONE_TIME);
1111         self.assertEqual(1,f1.getNumberOfComponents());
1112         self.assertEqual(9,f1.getNumberOfTuples());
1113         values1=[-1.8,-0.3,1.2,-0.3,1.2,2.7,1.2,2.7,4.2]
1114         tmp=f1.getArray().getValues();
1115         self.assertEqual(len(values1),len(tmp))
1116         for i in xrange(len(tmp)):
1117             self.assertTrue(abs(tmp[i]-values1[i])<1.e-12)
1118             pass
1119         pass
1120
1121     def testApplyFunc2(self):
1122         m=MEDCouplingDataForTest.build2DTargetMesh_1();
1123         f1=m.fillFromAnalytic(ON_NODES,2,"(x+y)*IVec+2*(x+y)*JVec");
1124         f1.checkCoherency();
1125         self.assertEqual(f1.getTypeOfField(),ON_NODES);
1126         self.assertEqual(f1.getTimeDiscretization(),ONE_TIME);
1127         self.assertEqual(2,f1.getNumberOfComponents());
1128         self.assertEqual(9,f1.getNumberOfTuples());
1129         #
1130         f2=f1.clone(True);
1131         self.assertRaises(InterpKernelException, f2.applyFunc, 1, "a+b+c+d");
1132         self.assertRaises(InterpKernelException, f2.applyFunc, 1, "a/0");
1133         self.assertRaises(InterpKernelException, f2.applyFunc, "a/0");
1134         f2.applyFunc("abs(u)^2.4+2*u");
1135         self.assertEqual(f1.getTypeOfField(),ON_NODES);
1136         self.assertEqual(f1.getTimeDiscretization(),ONE_TIME);
1137         self.assertEqual(2,f1.getNumberOfComponents());
1138         self.assertEqual(9,f1.getNumberOfTuples());
1139         values2=[-0.9065304805418678, -0.85105859001709905, -0.19601892829446504, -0.37898777756476987,
1140                  0.91090317490482353, 2.1853504664669781, -0.19601892829446504, -0.37898777756476987,
1141                  0.91090317490482353, 2.1853504664669781, 2.5765725275664879, 7.6987743736515295,
1142                  0.91090317490482353, 2.1853504664669781, 2.5765725275664879, 7.6987743736515295,
1143                  5.0423700574830965, 17.435300118916864]
1144         tmp=f2.getArray().getValues();
1145         self.assertEqual(len(tmp),len(values2))
1146         for i in xrange(len(tmp)):
1147             self.assertTrue(abs(tmp[i]-values2[i])<1.e-12)
1148             pass
1149         #
1150         f1.applyFunc(1,"x+y");
1151         self.assertEqual(f1.getTypeOfField(),ON_NODES);
1152         self.assertEqual(f1.getTimeDiscretization(),ONE_TIME);
1153         self.assertEqual(1,f1.getNumberOfComponents());
1154         self.assertEqual(9,f1.getNumberOfTuples());
1155         values1=[-1.8,-0.3,1.2,-0.3,1.2,2.7,1.2,2.7,4.2]
1156         tmp=f1.getArray().getValues();
1157         self.assertEqual(len(tmp),len(values1))
1158         for i in xrange(len(tmp)):
1159             self.assertTrue(abs(tmp[i]-values1[i])<1.e-12)
1160             pass
1161         pass
1162
1163     def testOperationsOnFields(self):
1164         m=MEDCouplingDataForTest.build2DTargetMesh_1();
1165         f1=m.fillFromAnalytic(ON_NODES,1,"x+y");
1166         f2=m.fillFromAnalytic(ON_NODES,1,"x+y");
1167         f1.checkCoherency();
1168         f2.checkCoherency();
1169         f3=f1+f2;
1170         f3.checkCoherency();
1171         self.assertEqual(f3.getTypeOfField(),ON_NODES);
1172         self.assertEqual(f3.getTimeDiscretization(),ONE_TIME);
1173         values1=[-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8]
1174         tmp=f3.getArray().getValues();
1175         self.assertEqual(len(values1),len(tmp))
1176         for i in xrange(len(tmp)):
1177             self.assertTrue(abs(tmp[i]-values1[i])<1.e-12)
1178             pass
1179         #
1180         f3=f1*f2;
1181         f3.checkCoherency();
1182         self.assertEqual(f3.getTypeOfField(),ON_NODES);
1183         self.assertEqual(f3.getTimeDiscretization(),ONE_TIME);
1184         values2=[0.36,0.01,0.16,0.01,0.16,0.81,0.16,0.81,1.96]
1185         tmp=f3.getArray().getValues();
1186         self.assertEqual(len(values2),len(tmp))
1187         for i in xrange(len(tmp)):
1188             self.assertTrue(abs(tmp[i]-values2[i])<1.e-12)
1189             pass
1190         #
1191         f3=f1+f2;
1192         f4=f1-f3;
1193         f4.checkCoherency();
1194         self.assertEqual(f4.getTypeOfField(),ON_NODES);
1195         self.assertEqual(f4.getTimeDiscretization(),ONE_TIME);
1196         values3=[0.6,0.1,-0.4,0.1,-0.4,-0.9,-0.4,-0.9,-1.4]
1197         tmp=f4.getArray().getValues();
1198         self.assertEqual(len(values3),len(tmp))
1199         for i in xrange(len(tmp)):
1200             self.assertTrue(abs(tmp[i]-values3[i])<1.e-12)
1201             pass
1202         #
1203         f3=f1+f2;
1204         f4=f3/f2;
1205         f4.checkCoherency();
1206         self.assertEqual(f4.getTypeOfField(),ON_NODES);
1207         self.assertEqual(f4.getTimeDiscretization(),ONE_TIME);
1208         tmp=f4.getArray().getValues();
1209         for i in xrange(len(tmp)):
1210             self.assertTrue(abs(tmp[i]-2.)<1.e-12)
1211             pass
1212         #
1213         f4=f2.buildNewTimeReprFromThis(NO_TIME,False);
1214         f4.checkCoherency();
1215         self.assertEqual(f4.getTypeOfField(),ON_NODES);
1216         self.assertEqual(f4.getTimeDiscretization(),NO_TIME);
1217         self.assertRaises(InterpKernelException,f1.__add__,f4);
1218         f5=f4.buildNewTimeReprFromThis(ONE_TIME,False);
1219         self.assertEqual(f5.getTypeOfField(),ON_NODES);
1220         self.assertEqual(f5.getTimeDiscretization(),ONE_TIME);
1221         f3=f1+f5;
1222         tmp=f3.getArray().getValues();
1223         values4=[-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8]
1224         self.assertEqual(len(values3),len(tmp))
1225         for i in xrange(len(tmp)):
1226             self.assertTrue(abs(tmp[i]-values4[i])<1.e-12)
1227             pass
1228         #
1229         f4=f2.buildNewTimeReprFromThis(NO_TIME,True);
1230         f4.checkCoherency();
1231         self.assertEqual(f4.getTypeOfField(),ON_NODES);
1232         self.assertEqual(f4.getTimeDiscretization(),NO_TIME);
1233         self.assertRaises(InterpKernelException,f1.__add__,f4);
1234         f5=f4.buildNewTimeReprFromThis(ONE_TIME,True);
1235         self.assertEqual(f5.getTypeOfField(),ON_NODES);
1236         self.assertEqual(f5.getTimeDiscretization(),ONE_TIME);
1237         f3=f1+f5;
1238         tmp=f3.getArray().getValues();
1239         values5=[-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8]
1240         self.assertEqual(len(values5),len(tmp))
1241         for i in xrange(len(tmp)):
1242             self.assertTrue(abs(tmp[i]-values5[i])<1.e-12)
1243             pass
1244         pass
1245
1246     def testOperationsOnFields2(self):
1247         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
1248         m.setTime(3.4,5,6); m.setTimeUnit("us");
1249         f1=m.fillFromAnalytic(ON_NODES,1,"x+y+z");
1250         f2=m.fillFromAnalytic(ON_NODES,1,"a*a+b+c*c");
1251         f3=f1/f2;
1252         f3.checkCoherency();
1253         self.assertEqual(f3.getTypeOfField(),ON_NODES);
1254         self.assertEqual(f3.getTimeDiscretization(),ONE_TIME);
1255         expected1=[-2.4999999999999991, 1.2162162162162162, 0.77868852459016391,
1256                    0.7407407407407407, 1.129032258064516, 0.81632653061224492,
1257                    0.86538461538461531, 1.0919540229885056, 0.84302325581395343]
1258         self.assertEqual(1,f3.getNumberOfComponents());
1259         self.assertEqual(9,f3.getNumberOfTuples());
1260         val=f3.getArray().getValues();
1261         for i in xrange(9):
1262             self.assertTrue(abs(expected1[i]-val[i])<1.e-12);
1263         #
1264         f1=m.buildOrthogonalField();
1265         self.assertAlmostEqual(3.4,f1.getTime()[0],12) ; self.assertEqual(5,f1.getTime()[1]) ; self.assertEqual(6,f1.getTime()[2])
1266         self.assertEqual("us",f1.getTimeUnit())
1267         f2=m.fillFromAnalytic(ON_CELLS,1,"x");
1268         f3=f1*f2;
1269         expected2=[-0.035355339059327376,0.,0.035355339059327376, 0.2592724864350674,0.,-0.2592724864350674, 0.37712361663282529,0.,-0.37712361663282529, -0.035355339059327376,0.,0.035355339059327376, 0.31819805153394637,0.,-0.31819805153394637]
1270         val=f3.getArray().getValues();
1271         for i in xrange(15):
1272             self.assertTrue(abs(expected2[i]-val[i])<1.e-12);
1273             pass
1274         #
1275         f3=f2*f1;
1276         val=f3.getArray().getValues();
1277         for i in xrange(15):
1278             self.assertTrue(abs(expected2[i]-val[i])<1.e-12);
1279             pass
1280         pass
1281
1282     def testOperationsOnFields3(self):
1283         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
1284         f1=m.fillFromAnalytic(ON_NODES,1,"x+y+z");
1285         f2=m.fillFromAnalytic(ON_NODES,1,"a*a+b+c*c");
1286         f1/=f2
1287         f1.checkCoherency();
1288         self.assertEqual(f1.getTypeOfField(),ON_NODES);
1289         self.assertEqual(f1.getTimeDiscretization(),ONE_TIME);
1290         expected1=[-2.4999999999999991, 1.2162162162162162, 0.77868852459016391,
1291                    0.7407407407407407, 1.129032258064516, 0.81632653061224492,
1292                    0.86538461538461531, 1.0919540229885056, 0.84302325581395343]
1293         self.assertEqual(1,f1.getNumberOfComponents());
1294         self.assertEqual(9,f1.getNumberOfTuples());
1295         val=f1.getArray().getValues();
1296         for i in xrange(9):
1297             self.assertTrue(abs(expected1[i]-val[i])<1.e-12);
1298             pass
1299         #
1300         f1=m.buildOrthogonalField();
1301         f2=m.fillFromAnalytic(ON_CELLS,1,"x");
1302         f1*=f2
1303         expected2=[-0.035355339059327376,0.,0.035355339059327376, 0.2592724864350674,0.,-0.2592724864350674, 0.37712361663282529,0.,-0.37712361663282529, -0.035355339059327376,0.,0.035355339059327376, 0.31819805153394637,0.,-0.31819805153394637]
1304         val=f1.getArray().getValues();
1305         for i in xrange(15):
1306             self.assertTrue(abs(expected2[i]-val[i])<1.e-12);
1307             pass
1308         #
1309         f1=m.buildOrthogonalField();
1310         # to avoid valgrind leaks
1311         # self.assertRaises(InterpKernelException,f2.__imul__,f1);
1312         pass
1313
1314     def testOperationsOnFields4(self):
1315         m=MEDCouplingDataForTest.build2DTargetMesh_1();
1316         nbOfCells=m.getNumberOfCells();
1317         f1=MEDCouplingFieldDouble.New(ON_CELLS,CONST_ON_TIME_INTERVAL);
1318         f1.setMesh(m);
1319         array=DataArrayDouble.New();
1320         f1.setArray(array);
1321         self.assertRaises(InterpKernelException,f1.setEndArray,array);
1322         self.assertRaises(InterpKernelException,f1.getEndArray);
1323         arr1=[0.,10.,20.,1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.]
1324         arr2=[5.,15.,25.,6.,16.,26.,7.,17.,27.,8.,18.,28.,9.,19.,29.]
1325         array.setValues(arr1,nbOfCells,3);
1326         f1.setStartTime(2.,0,0);
1327         f1.setEndTime(3.,0,0);
1328         f1.checkCoherency();
1329         pos=[0.3,-0.2]
1330         res=f1.getValueOn(pos);
1331         self.assertTrue(abs(arr1[3]-res[0])<1.e-12);
1332         self.assertTrue(abs(arr1[4]-res[1])<1.e-12);
1333         self.assertTrue(abs(arr1[5]-res[2])<1.e-12);
1334         res=None
1335         res=f1.getValueOn(pos,2.2);
1336         self.assertTrue(abs(arr1[3]-res[0])<1.e-12);
1337         self.assertTrue(abs(arr1[4]-res[1])<1.e-12);
1338         self.assertTrue(abs(arr1[5]-res[2])<1.e-12);
1339         res=None
1340         self.assertRaises(InterpKernelException,f1.getValueOn,pos,3.2)
1341         f2=MEDCouplingFieldDouble.New(ON_CELLS,LINEAR_TIME);
1342         f2.setMesh(m);
1343         f2.setArray(f1.getArray());
1344         f2.setStartTime(2.,3,0);
1345         f2.setEndTime(4.,13,0);
1346         self.assertRaises(InterpKernelException,f2.checkCoherency)
1347         array2=DataArrayDouble.New();
1348         array2.setValues(arr2,nbOfCells,3);
1349         f2.setEndArray(array2);
1350         f2.checkCoherency();
1351         #
1352         res=None
1353         res=f2.getValueOn(pos,3.21);
1354         self.assertTrue(abs(4.025-res[0])<1.e-12);
1355         self.assertTrue(abs(14.025-res[1])<1.e-12);
1356         self.assertTrue(abs(24.025-res[2])<1.e-12);
1357         f3=f2.clone(True);
1358         self.assertTrue(f2.isEqual(f3,1e-12,1e-12));
1359         f3.getEndArray().setIJ(0,0,5.001);
1360         self.assertTrue(not f2.isEqual(f3,1e-12,1e-12));
1361         self.assertTrue(f2.isEqual(f3,1e-12,1e-2));
1362         f3.setStartTime(2.1,3,0);
1363         self.assertTrue(not f2.isEqual(f3,1e-12,1e-2));
1364         f3.setStartTime(2.,3,0);
1365         self.assertTrue(f2.isEqual(f3,1e-12,1e-2));
1366         f3.setStartTime(2.,4,0);
1367         self.assertTrue(not f2.isEqual(f3,1e-12,1e-2));
1368         f3.setStartTime(2.,3,1);
1369         self.assertTrue(not f2.isEqual(f3,1e-12,1e-2));
1370         f3.setStartTime(2.,3,0);
1371         self.assertTrue(f2.isEqual(f3,1e-12,1e-2));
1372         f3.setEndTime(4.1,13,0);
1373         self.assertTrue(not f2.isEqual(f3,1e-12,1e-2));
1374         f3.setEndTime(4.,13,0);
1375         self.assertTrue(f2.isEqual(f3,1e-12,1e-2));
1376         f3.setEndTime(4.,14,0);
1377         self.assertTrue(not f2.isEqual(f3,1e-12,1e-2));
1378         f3.setEndTime(4.,13,1);
1379         self.assertTrue(not f2.isEqual(f3,1e-12,1e-2));
1380         f3.setEndTime(4.,13,0);
1381         self.assertTrue(f2.isEqual(f3,1e-12,1e-2));
1382         f4=f2+f2
1383         res=None
1384         res=f4.getValueOn(pos,3.21);
1385         self.assertTrue(abs(8.05-res[0])<1.e-12);
1386         self.assertTrue(abs(28.05-res[1])<1.e-12);
1387         self.assertTrue(abs(48.05-res[2])<1.e-12);
1388         f4+=f2;
1389         res=None
1390         res=f4.getValueOn(pos,3.21);
1391         self.assertTrue(abs(12.075-res[0])<1.e-12);
1392         self.assertTrue(abs(42.075-res[1])<1.e-12);
1393         self.assertTrue(abs(72.075-res[2])<1.e-12);
1394         pass
1395     
1396     def testMergeNodesOnField(self):
1397         targetMesh=MEDCouplingDataForTest.build3DTargetMeshMergeNode_1();
1398         f1=targetMesh.fillFromAnalytic(ON_NODES,1,"x+y+z");
1399         f1.mergeNodes(1e-10);
1400         #
1401         targetMesh=MEDCouplingDataForTest.build3DTargetMeshMergeNode_1();
1402         f1=targetMesh.fillFromAnalytic(ON_NODES,1,"x+y+z");
1403         tmp=f1.getArray()
1404         tmp.setIJ(0,0,1000.);
1405         f1.mergeNodes(1e-10);
1406         #
1407         targetMesh=MEDCouplingDataForTest.build3DTargetMeshMergeNode_1();
1408         f1=targetMesh.fillFromAnalytic(ON_NODES,1,"x+y+z");
1409         tmp=f1.getArray()
1410         tmp.setIJ(1,0,1000.);
1411         self.assertRaises(InterpKernelException,f1.mergeNodes,1.e-10)
1412         pass
1413
1414     def testCheckConsecutiveCellTypes(self):
1415         sourceMesh=MEDCouplingDataForTest.build2DSourceMesh_1();
1416         targetMesh=MEDCouplingDataForTest.build2DTargetMesh_1();
1417         self.assertTrue(sourceMesh.checkConsecutiveCellTypes());
1418         order1=[NORM_TRI3,NORM_QUAD4]
1419         order2=[NORM_QUAD4,NORM_TRI3]
1420         self.assertTrue(not targetMesh.checkConsecutiveCellTypes());
1421         self.assertTrue(not targetMesh.checkConsecutiveCellTypesAndOrder(order1));
1422         self.assertTrue(not targetMesh.checkConsecutiveCellTypesAndOrder(order2));
1423         da=targetMesh.getRenumArrForConsecutiveCellTypesSpec(order1);
1424         self.assertEqual(5,da.getNumberOfTuples());
1425         self.assertEqual(1,da.getNumberOfComponents());
1426         expected1=[2,0,1,3,4]
1427         self.assertTrue(expected1==list(da.getValues()));
1428         da=targetMesh.getRenumArrForConsecutiveCellTypesSpec(order2);
1429         self.assertEqual(5,da.getNumberOfTuples());
1430         self.assertEqual(1,da.getNumberOfComponents());
1431         expected2=[0,3,4,1,2]
1432         self.assertTrue(expected2==list(da.getValues()));
1433         renumber1=[4,0,1,2,3]
1434         targetMesh.renumberCells(renumber1,False);
1435         self.assertTrue(targetMesh.checkConsecutiveCellTypes());
1436         self.assertTrue(targetMesh.checkConsecutiveCellTypesAndOrder(order1));
1437         self.assertTrue(not targetMesh.checkConsecutiveCellTypesAndOrder(order2));
1438         pass
1439
1440     def testRearrange2ConsecutiveCellTypes(self):
1441         m1_1=MEDCouplingDataForTest.build2DSourceMesh_1();
1442         m2_1=MEDCouplingDataForTest.build2DTargetMesh_1();
1443         arr1=m1_1.rearrange2ConsecutiveCellTypes();
1444         m1_2=MEDCouplingDataForTest.build2DSourceMesh_1();
1445         self.assertTrue(m1_2.isEqual(m1_1,1e-12));
1446         expected1=[0,1]
1447         self.assertEqual(2,arr1.getNumberOfTuples());
1448         self.assertEqual(1,arr1.getNumberOfComponents());
1449         self.assertEqual(expected1,arr1.getValues());
1450         expected2=[0,3,4,1,2]
1451         arr1=m2_1.rearrange2ConsecutiveCellTypes();
1452         self.assertEqual(5,arr1.getNumberOfTuples());
1453         self.assertEqual(1,arr1.getNumberOfComponents());
1454         self.assertEqual(expected2,list(arr1.getValues()));
1455         m2_2=MEDCouplingDataForTest.build2DTargetMesh_1();
1456         self.assertEqual(5,arr1.getNumberOfTuples());
1457         self.assertEqual(1,arr1.getNumberOfComponents());
1458         self.assertEqual(expected2,list(arr1.getValues()));
1459         self.assertTrue(not m2_2.isEqual(m2_1,1e-12));
1460         m2_2.renumberCells(expected2,False);
1461         self.assertTrue(m2_2.isEqual(m2_1,1e-12));
1462         pass
1463
1464     def testSplitByType(self):
1465         m1=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
1466         v=m1.splitByType();
1467         self.assertEqual(3,len(v));
1468         m2=MEDCouplingUMesh.MergeUMeshesOnSameCoords(v);
1469         m2.setName(m1.getName());
1470         self.assertTrue(m1.isEqual(m2,1.e-12));
1471         pass
1472
1473     def testFuseUMeshesOnSameCoords(self):
1474         m2=MEDCouplingDataForTest.build2DTargetMesh_1();
1475         cells1=[2,3,4]
1476         m3=m2.buildPartOfMySelf(cells1,True);
1477         self.assertTrue(isinstance(m3,MEDCouplingUMesh))
1478         cells2=[1,2,4]
1479         m4=m2.buildPartOfMySelf(cells2,True);
1480         self.assertTrue(isinstance(m4,MEDCouplingUMesh))
1481         cells3=[1,2]
1482         m5=m2.buildPartOfMySelf(cells3,True);
1483         self.assertTrue(isinstance(m5,MEDCouplingUMesh))
1484         meshes=[m3,m4,m5]
1485         #
1486         m7,corr=MEDCouplingUMesh.FuseUMeshesOnSameCoords(meshes,0);
1487         self.assertEqual(4,m7.getNumberOfCells());
1488         self.assertEqual(3,len(corr));
1489         expectedVals1=[3,3,2]
1490         expectedVals2=[[0,1,2],[3,0,2],[3,0]]
1491         for i in xrange(3):
1492             arr=corr[i];
1493             self.assertEqual(1,arr.getNumberOfComponents());
1494             nbOfVals=expectedVals1[i];
1495             self.assertEqual(nbOfVals,arr.getNumberOfTuples());
1496             vals=arr.getValues();
1497             self.assertEqual(expectedVals2[i],list(vals));
1498             pass
1499         arr2,fidsOfGroups=DataArrayInt.MakePartition(corr,m7.getNumberOfCells());
1500         fidExp=[5,1,3,4]
1501         fidsGrp=[[1,3,5],[3,4,5],[4,5]]
1502         self.assertEqual(3,len(fidsOfGroups));
1503         self.assertEqual(1,arr2.getNumberOfComponents());
1504         self.assertEqual(4,arr2.getNumberOfTuples());
1505         self.assertEqual(fidExp,list(arr2.getValues()));
1506         for i in xrange(3):
1507             nbOfVals=expectedVals1[i];
1508             self.assertEqual(list(fidsOfGroups[i]),fidsGrp[i]);
1509             pass
1510         pass
1511
1512     def testFuseUMeshesOnSameCoords2(self):
1513         m1,m2=MEDCouplingDataForTest.build3DExtrudedUMesh_1();
1514         part1=[2,3,6,4,10]
1515         m3=m1.buildPartOfMySelf(part1,True);
1516         part2=[5,6,4,7]
1517         m4=m1.buildPartOfMySelf(part2,True);
1518         meshes=[m1,m3,m3,m4]
1519         m5,corr=MEDCouplingUMesh.FuseUMeshesOnSameCoords(meshes,0);
1520         self.assertEqual(18,m5.getNumberOfCells());
1521         exp2=[
1522             [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17],
1523             [2,3,6,4,10],
1524             [2,3,6,4,10],
1525             [5,6,4,7]]
1526         i=0;
1527         for it in corr:
1528             self.assertEqual(exp2[i],list(it.getValues()));
1529             i+=1
1530             pass
1531         pass
1532
1533     def testBuildOrthogonalField(self):
1534         targetMesh=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
1535         field=targetMesh.buildOrthogonalField();
1536         expected=[0.70710678118654746,0.,-0.70710678118654746]
1537         self.assertEqual(5,field.getNumberOfTuples());
1538         self.assertEqual(3,field.getNumberOfComponents());
1539         vals=field.getArray().getValues();
1540         for i in xrange(15):
1541             self.assertTrue(abs(expected[i%3]-vals[i])<1e-12);
1542         # testing
1543         targetCoords=[0.,0.,0.,0.5,0.,0.5,1.,0.,1.,0.,1.,0.]
1544         targetConn=[0,1,2,3]
1545         targetMesh=MEDCouplingUMesh.New();
1546         targetMesh.setMeshDimension(2);
1547         targetMesh.allocateCells(1);
1548         targetMesh.insertNextCell(NORM_QUAD4,targetConn[0:4])
1549         targetMesh.finishInsertingCells();
1550         myCoords=DataArrayDouble.New();
1551         myCoords.setValues(targetCoords,4,3);
1552         targetMesh.setCoords(myCoords);
1553         field=targetMesh.buildOrthogonalField();
1554         self.assertEqual(1,field.getNumberOfTuples());
1555         self.assertEqual(3,field.getNumberOfComponents());
1556         vals=field.getArray().getValues();
1557         self.assertTrue(abs(-0.70710678118654746-vals[0])<1e-12);
1558         self.assertTrue(abs(0.-vals[1])<1e-12);
1559         self.assertTrue(abs(0.70710678118654746-vals[2])<1e-12);
1560         pass
1561
1562     def testGetCellsContainingPoint(self):
1563         targetMesh=MEDCouplingDataForTest.build2DTargetMesh_1();
1564         pos=[0.,0.,0.4,0.4,0.,0.4,0.1,0.1,0.25,0.,0.65,0.]
1565         #2D basic
1566         t1,t2=targetMesh.getCellsContainingPoints(pos,6,1e-12);
1567         self.assertEqual(6,t1.getNumberOfTuples());
1568         self.assertEqual(1,t1.getNumberOfComponents());
1569         self.assertEqual(7,t2.getNumberOfTuples());
1570         self.assertEqual(1,t2.getNumberOfComponents());
1571         expectedValues1=[0,4,3,0,1,2]
1572         expectedValues2=[0,1,2,3,4,5,6]
1573         self.assertEqual(list(t1.getValues()),expectedValues1);
1574         self.assertEqual(list(t2.getValues()),expectedValues2);
1575         #2D with no help of bounding box.
1576         center=[0.2,0.2]
1577         MEDCouplingPointSet.Rotate2DAlg(center,0.78539816339744830962,6,pos);
1578         targetMesh.rotate(center,0.78539816339744830962);
1579         t1=None
1580         t2=None
1581         t1,t2=targetMesh.getCellsContainingPoints(pos,1e-12);
1582         self.assertEqual(6,t1.getNumberOfTuples());
1583         self.assertEqual(7,t2.getNumberOfTuples());
1584         self.assertEqual(list(t1.getValues()),expectedValues1);
1585         self.assertEqual(list(t2.getValues()),expectedValues2);
1586         t1,t2=targetMesh.getCellsContainingPoints(DataArrayDouble.New(pos,6,2),1e-12);
1587         self.assertEqual(6,t1.getNumberOfTuples());
1588         self.assertEqual(7,t2.getNumberOfTuples());
1589         self.assertEqual(list(t1.getValues()),expectedValues1);
1590         self.assertEqual(list(t2.getValues()),expectedValues2);
1591         self.assertRaises(InterpKernelException,targetMesh.getCellsContainingPoints,DataArrayDouble.New(pos,4,3),1e-12);
1592         #2D outside
1593         pos1bis=[-0.3303300858899107,-0.11819805153394641]
1594         self.assertEqual(-1,targetMesh.getCellContainingPoint(pos1bis,1e-12));
1595         #test limits 2D
1596         targetMesh=MEDCouplingDataForTest.build2DTargetMesh_1();
1597         pos2=[0.2,-0.05]
1598         t1=None
1599         t1=targetMesh.getCellsContainingPoint(pos2,1e-12)
1600         self.assertEqual(2,len(t1));
1601         expectedValues3=[0,1]
1602         self.assertEqual(list(t1.getValues()),expectedValues3);
1603         pos3=[0.2,0.2]
1604         t1=None
1605         t1=targetMesh.getCellsContainingPoint(pos3,1e-12);
1606         self.assertEqual(5,len(t1));
1607         expectedValues4=[0,1,2,3,4]
1608         self.assertEqual(list(t1.getValues()),expectedValues4);
1609         self.assertEqual(0,targetMesh.getCellContainingPoint(pos3,1e-12));
1610         #3D
1611         targetMesh=MEDCouplingDataForTest.build3DTargetMesh_1();
1612         pos4=[25.,25.,25.]
1613         self.assertEqual(0,targetMesh.getCellContainingPoint(pos4,1e-12));
1614         pos5=[50.,50.,50.]
1615         t1=None
1616         t1=targetMesh.getCellsContainingPoint(pos5,1e-12);
1617         self.assertEqual(8,len(t1));
1618         expectedValues5=[0,1,2,3,4,5,6,7]
1619         self.assertEqual(list(t1.getValues()),expectedValues5);
1620         pos6=[0., 50., 0.]
1621         t1=None
1622         t1=targetMesh.getCellsContainingPoint(pos6,1e-12);
1623         self.assertEqual(2,len(t1));
1624         expectedValues6=[0,2]
1625         self.assertEqual(list(t1.getValues()),expectedValues6);
1626         #3D outside
1627         pos7=[-1.0,-1.0,0.]
1628         self.assertEqual(-1,targetMesh.getCellContainingPoint(pos7,1e-12));
1629         #3D outside 2
1630         center2=[0.,0.,0.]
1631         vec2=[0.,-1.,0.]
1632         targetMesh.rotate(center2,vec2,0.78539816339744830962);
1633         pos8=[-25.,25.,12.]
1634         self.assertEqual(-1,targetMesh.getCellContainingPoint(pos8,1e-12));
1635         pass
1636
1637     def testGetValueOn1(self):
1638         targetMesh=MEDCouplingDataForTest.build2DTargetMesh_1();
1639         fieldOnCells=MEDCouplingFieldDouble.New(ON_CELLS);
1640         nbOfCells=targetMesh.getNumberOfCells();
1641         fieldOnCells.setMesh(targetMesh);
1642         array=DataArrayDouble.New();
1643         tmp=2*nbOfCells*[None]
1644         for i in xrange(nbOfCells):
1645             tmp[2*i]=7.+float(i);
1646             tmp[2*i+1]=17.+float(i)
1647             pass
1648         array.setValues(tmp,nbOfCells,2);
1649         fieldOnCells.setArray(array);
1650         #
1651         pos1=[0.25,0.]
1652         res=fieldOnCells.getValueOn(pos1);
1653         self.assertEqual(2,len(res))
1654         self.assertTrue(abs(8.-res[0])<1e-12);
1655         self.assertTrue(abs(18.-res[1])<1e-12);
1656         #
1657         #
1658         targetMesh=MEDCouplingDataForTest.build2DSourceMesh_1();
1659         fieldOnNodes=MEDCouplingFieldDouble.New(ON_NODES);
1660         nbOfNodes=targetMesh.getNumberOfNodes();
1661         fieldOnNodes.setMesh(targetMesh);
1662         array=DataArrayDouble.New();
1663         tmp=2*nbOfNodes*[None]
1664         for i in xrange(nbOfNodes):
1665             tmp[2*i]=17.+float(i);
1666             tmp[2*i+1]=27.+float(i)
1667             pass
1668         array.setValues(tmp,nbOfNodes,2);
1669         fieldOnNodes.setArray(array);
1670         #
1671         pos2=[-0.13333333333333333,-0.13333333333333333]
1672         res=None
1673         res=fieldOnNodes.getValueOn(pos2);
1674         self.assertEqual(2,len(res))
1675         self.assertTrue(abs(17.5-res[0])<1e-12);
1676         self.assertTrue(abs(27.5-res[1])<1e-12);
1677         pos3=[0.033333333333333326,0.36666666666666664]
1678         res=None
1679         res=fieldOnNodes.getValueOn(pos3);
1680         self.assertEqual(2,len(res))
1681         self.assertTrue(abs(18.666666666666667-res[0])<1e-12);
1682         self.assertTrue(abs(28.666666666666667-res[1])<1e-12);
1683         pass
1684
1685     def testCMesh0(self):
1686         mesh=MEDCouplingCMesh.New();
1687         meshEmpty=mesh.clone(True);
1688         self.assertTrue(meshEmpty.isEqual(mesh, 1e-12));
1689         
1690         coordsX=DataArrayDouble.New();
1691         arrX=[ -1., 1., 2., 4. ]
1692         coordsX.setValues(arrX, 4, 1);
1693         coordsY=DataArrayDouble.New();
1694         arrY=[ -2., 2., 4., 8. ]
1695         coordsY.setValues(arrY, 4, 1);
1696         coordsZ=DataArrayDouble.New();
1697         arrZ=[ -3., 3., 6., 12. ]
1698         coordsZ.setValues(arrZ, 4, 1);
1699         mesh.setCoords(coordsX, coordsY, coordsZ);
1700         #
1701         fieldOnNodes=mesh.fillFromAnalytic(ON_NODES, 1, "x+y/2.+z/3.");
1702         self.assertEqual(1, fieldOnNodes.getNumberOfComponents());
1703         self.assertEqual(64, fieldOnNodes.getNumberOfTuples());
1704         expected1=[-3., -1., 0., 2., -1., 1., 2., 4., 0., 2., 3., 5., 2., 4., 5., 7., -1., 1., 2.,
1705                     4., 1., 3., 4., 6., 2., 4., 5., 7., 4., 6., 7., 9., 0., 2., 3., 5., 2., 4., 5.,
1706                     7., 3., 5., 6., 8., 5., 7., 8., 10., 2., 4., 5.,
1707                     7., 4., 6., 7., 9., 5., 7., 8., 10., 7., 9., 10., 12.];
1708         
1709         val=fieldOnNodes.getArray().getValues();
1710         for i in xrange(64):
1711           self.assertAlmostEqual(expected1[i], val[i], 12)
1712         res=fieldOnNodes.getValueOnPos(1, 3, 2);
1713         self.assertAlmostEqual(7., res[0], 12);
1714         #
1715         fieldOnCells=mesh.fillFromAnalytic(ON_CELLS, 1, "x+y/2.+z/3.");
1716         self.assertEqual(1, fieldOnCells.getNumberOfComponents());
1717         self.assertEqual(27, fieldOnCells.getNumberOfTuples());
1718         val=fieldOnCells.getArray().getValues();
1719         expected2=[0, 1.5, 3, 1.5, 3, 4.5, 3, 4.5, 6, 1.5, 3, 4.5, 3, 4.5,
1720                     6, 4.5, 6, 7.5, 3, 4.5, 6, 4.5, 6, 7.5, 6, 7.5, 9];
1721         for i in xrange(27):
1722           self.assertAlmostEqual(expected2[i], val[i], 12);
1723         #res=fieldOnCells.getValueOnPos(1,2,1);
1724         #self.assertAlmostEqual(6.,res,12);
1725         #
1726         meshDeepCopy=mesh.deepCpy();
1727         meshClone=mesh.clone(False);
1728         
1729         meshEmpty.copyTinyStringsFrom(mesh);
1730         #no data in meshEmpty, expected False
1731         self.assertTrue(not meshEmpty.isEqual(mesh, 1e-12));
1732         
1733         self.assertTrue(meshDeepCopy.isEqual(mesh, 1e-12));
1734         meshDeepCopy.copyTinyStringsFrom(mesh);
1735         self.assertTrue(meshDeepCopy.isEqual(mesh, 1e-12));
1736         self.assertTrue(meshClone.isEqual(mesh, 1e-12));
1737         
1738         self.assertEqual(CARTESIAN, mesh.getType());
1739         self.assertEqual(CARTESIAN, meshEmpty.getType());
1740         self.assertEqual(CARTESIAN, meshDeepCopy.getType());
1741         self.assertEqual(CARTESIAN, meshClone.getType());
1742         pass
1743
1744     def testCMesh1(self):
1745         mesh1=MEDCouplingCMesh.New();
1746         coordsX1=DataArrayDouble.New();
1747         arrX1=[ -1., 1., 2., 4. ]
1748         coordsX1.setValues(arrX1, 4, 1);
1749         coordsY1=DataArrayDouble.New();
1750         arrY1=[ -2., 2., 4., 8. ]
1751         coordsY1.setValues(arrY1, 4, 1);
1752         coordsZ1=DataArrayDouble.New();
1753         arrZ1=[ -3., 3., 6., 12. ]
1754         coordsZ1.setValues(arrZ1, 4, 1);
1755         mesh1.setCoords(coordsX1, coordsY1, coordsZ1);
1756         
1757         mesh2=MEDCouplingCMesh.New();
1758         coordsX2=DataArrayDouble.New();
1759         arrX2=[ -1., 1., 2., 4. ]
1760         coordsX2.setValues(arrX2, 4, 1);
1761         coordsY2=DataArrayDouble.New();
1762         arrY2=[ -2., 2., 4., 8. ]
1763         coordsY2.setValues(arrY2, 4, 1);
1764         coordsZ2=DataArrayDouble.New();
1765         arrZ2=[ -3., 3., 6., 12.+1e-6 ]
1766         coordsZ2.setValues(arrZ2, 4, 1);
1767         mesh2.setCoords(coordsX2, coordsY2, coordsZ2);
1768         
1769         mesh3=MEDCouplingCMesh.New();
1770         coordsX3=DataArrayDouble.New();
1771         arrX3=[-1.]
1772         coordsX3.setValues(arrX3, 1, 1);
1773         coordsY3=DataArrayDouble.New();
1774         arrY3=[-2.]
1775         coordsY3.setValues(arrY3, 1, 1);
1776         coordsZ3=DataArrayDouble.New();
1777         arrZ3=[-3.]
1778         coordsZ3.setValues(arrZ3, 1, 1);
1779         mesh3.setCoords(coordsX3, coordsY3, coordsZ3);
1780         
1781         self.assertEqual(3, mesh1.getSpaceDimension());
1782         self.assertEqual(3, mesh1.getMeshDimension());
1783         
1784         self.assertTrue(not mesh1.isEqual(mesh2, 1e-12));
1785         self.assertTrue(not mesh2.isEqual(mesh1, 1e-12));
1786         self.assertTrue(not mesh2.isEqualWithoutConsideringStr(mesh1, 1e-12));
1787         self.assertTrue(mesh1.isEqual(mesh2, 1e-5));
1788         self.assertTrue(not mesh1.isEqual(mesh2, 1e-7));
1789         
1790         self.assertRaises(InterpKernelException, mesh3.checkCoherency1, 1e-12);
1791         mesh1.checkCoherency2(1e-12);
1792         self.assertEqual(NORM_HEXA8, mesh1.getTypeOfCell(1));
1793         
1794         self.assertEqual(NORM_HEXA8, mesh1.getAllGeoTypes()[0]);
1795         self.assertEqual(27, mesh1.getNumberOfCellsWithType(NORM_HEXA8));
1796         self.assertRaises(InterpKernelException, mesh1.getNumberOfCellsWithType, NORM_QUAD4);
1797         
1798         coo=mesh1.getCoordinatesOfNode(0);
1799         self.assertEqual(3, len(coo));
1800         self.assertAlmostEqual(-1., coo[0], 14);
1801         self.assertAlmostEqual(-2., coo[1], 14);
1802         self.assertAlmostEqual(-3., coo[2], 14);
1803         coo=mesh1.getCoordinatesOfNode(63);
1804         self.assertEqual(3, len(coo));
1805         self.assertAlmostEqual(4., coo[0], 14);
1806         self.assertAlmostEqual(8., coo[1], 14);
1807         self.assertAlmostEqual(12., coo[2], 14);
1808         
1809         a=str(mesh1)
1810         repr=mesh1.simpleRepr();
1811         repr=mesh1.advancedRepr();
1812         self.assertTrue("Cartesian" in repr);
1813         self.assertTrue("Number of components : 1" in repr);
1814         self.assertTrue("Number of tuples : 4" in repr);
1815         self.assertTrue("Z Array :" in repr);
1816         pass
1817
1818     def testCMesh2(self):
1819         mesh1=MEDCouplingCMesh.New();
1820         coordsX1=DataArrayDouble.New();
1821         arrX1=[ -1., 1., 2., 4. ]
1822         coordsX1.setValues(arrX1, 4, 1);
1823         coordsY1=DataArrayDouble.New();
1824         arrY1=[ -2., 2., 4., 8. ]
1825         coordsY1.setValues(arrY1, 4, 1);
1826         coordsZ1=DataArrayDouble.New();
1827         arrZ1=[ -3., 3., 6., 12. ]
1828         coordsZ1.setValues(arrZ1, 4, 1);
1829         mesh1.setCoords(coordsX1, coordsY1, coordsZ1);
1830         
1831         dis=mesh1.getDistributionOfTypes();
1832         self.assertEqual(1, len(dis));
1833         self.assertEqual(NORM_HEXA8, dis[0][0]);
1834         self.assertEqual(27, dis[0][1]);
1835         self.assertEqual(-1, dis[0][2]);
1836         
1837         idsPerType=[]
1838         self.assertTrue(not mesh1.checkTypeConsistencyAndContig(dis, idsPerType));
1839         dis[0][0]=NORM_QUAD4;
1840         self.assertRaises(InterpKernelException, mesh1.checkTypeConsistencyAndContig, dis, idsPerType);
1841         dis[0][0]=NORM_HEXA8;
1842         dis[0][2]=0;
1843         ids=DataArrayInt.New();
1844         ids.alloc(10, 1);
1845         ids.fillWithValue(23);
1846         idsPerType=[ids];
1847         check=mesh1.checkTypeConsistencyAndContig(dis, idsPerType);
1848         self.assertTrue(check);
1849         self.assertTrue(check.isEqual(ids));
1850         
1851         code, idsInPflPerType, pfls=mesh1.splitProfilePerType(ids);
1852         self.assertEqual(1, len(code));
1853         self.assertEqual(NORM_HEXA8, code[0][0]);
1854         self.assertEqual(10, code[0][1]);
1855         self.assertEqual(0, code[0][2]);
1856         self.assertEqual(1, len(idsInPflPerType));
1857         self.assertEqual(1, len(pfls));
1858         self.assertTrue(idsInPflPerType[0].isEqual(DataArrayInt([0,1,2,3,4,5,6,7,8,9])));
1859         self.assertTrue(pfls[0].isEqual(ids));
1860         
1861         cells1=[0, 1, 25, 26]
1862         partMesh1=mesh1.buildPart(cells1)
1863         self.assertTrue(isinstance(partMesh1,MEDCouplingMesh))
1864         self.assertEqual(4, partMesh1.getNumberOfCellsWithType(NORM_HEXA8));
1865         self.assertEqual(64, mesh1.getNumberOfNodes());
1866         self.assertEqual(64, partMesh1.getNumberOfNodes());
1867         
1868         cells2=[25, 26]
1869         partMesh2, arr1=mesh1.buildPartAndReduceNodes(cells2)
1870         self.assertTrue(isinstance(partMesh2,MEDCouplingCMesh))
1871         self.assertEqual(2,partMesh2.getNumberOfCellsWithType(NORM_HEXA8));
1872         self.assertEqual(12,partMesh2.getNumberOfNodes());
1873         
1874         cells3=[2, 3]
1875         partMesh3, arr2=partMesh1.buildPartAndReduceNodes(cells3)
1876         self.assertTrue(isinstance(partMesh3,MEDCouplingUMesh))
1877         self.assertEqual(2, partMesh3.getNumberOfCellsWithType(NORM_HEXA8));
1878         self.assertEqual(12, partMesh3.getNumberOfNodes());
1879         
1880         self.assertRaises(InterpKernelException, mesh1.simplexize, 0);
1881         self.assertRaises(InterpKernelException, mesh1.getMeasureFieldOnNode, True);
1882         
1883         #double bbox1[6];
1884         #double bbox2[6];
1885         bbox1=mesh1.getBoundingBox(); #[(-1.0, 4.0), (-2.0, 8.0), (-3.0, 12.0)]
1886         bbox2=partMesh1.getBoundingBox();
1887         self.assertTrue(bbox1==bbox2);
1888         bbox1=partMesh3.getBoundingBox();
1889         bbox2=partMesh2.getBoundingBox();
1890         self.assertTrue(bbox1==bbox2);
1891         
1892         self.assertRaises(InterpKernelException, mesh1.buildOrthogonalField);
1893         mesh2d=MEDCouplingCMesh.New();
1894         mesh2d.setCoords(coordsX1, coordsY1);
1895         f1=mesh2d.buildOrthogonalField();
1896         
1897         pass
1898
1899     def testScale(self):
1900         mesh=MEDCouplingDataForTest.build2DTargetMesh_1();
1901         pos=[0.2,0.2]
1902         mesh.scale(pos,0.5);
1903         expected1=[-0.05,-0.05, 0.2,-0.05, 0.45,-0.05, -0.05,0.2, 0.2,0.2, 0.45,0.2,
1904                    -0.05,0.45, 0.2,0.45, 0.45,0.45]
1905         val=mesh.getCoords().getValues();
1906         self.assertEqual(18,len(val))
1907         for i in xrange(18):
1908             self.assertTrue(abs(expected1[i]-val[i])<1e-12);
1909             pass
1910         pass
1911
1912     def testTryToShareSameCoords(self):
1913         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
1914         m2=MEDCouplingDataForTest.build2DTargetMesh_1();
1915         self.assertTrue(m1.getCoords().getHiddenCppPointer()!=m2.getCoords().getHiddenCppPointer());
1916         m1.tryToShareSameCoords(m2,1e-12);
1917         self.assertTrue(m1.getCoords().getHiddenCppPointer()==m2.getCoords().getHiddenCppPointer());
1918         m1.tryToShareSameCoords(m2,1e-12);
1919         self.assertTrue(m1.getCoords().getHiddenCppPointer()==m2.getCoords().getHiddenCppPointer());
1920         m2.tryToShareSameCoords(m1,1e-12);
1921         self.assertTrue(m1.getCoords().getHiddenCppPointer()==m2.getCoords().getHiddenCppPointer());
1922         #
1923         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
1924         m2=MEDCouplingDataForTest.build2DTargetMesh_2();
1925         self.assertTrue(m1.getCoords().getHiddenCppPointer()!=m2.getCoords().getHiddenCppPointer());
1926         m1.tryToShareSameCoords(m2,1e-12);
1927         self.assertTrue(m1.getCoords().getHiddenCppPointer()==m2.getCoords().getHiddenCppPointer());
1928         m1.tryToShareSameCoords(m2,1e-12);
1929         self.assertTrue(m1.getCoords().getHiddenCppPointer()==m2.getCoords().getHiddenCppPointer());
1930         m2.tryToShareSameCoords(m1,1e-12);
1931         self.assertTrue(m1.getCoords().getHiddenCppPointer()==m2.getCoords().getHiddenCppPointer());
1932         #
1933         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
1934         m2=MEDCouplingDataForTest.build2DSourceMesh_1();
1935         self.assertTrue(m1.getCoords().getHiddenCppPointer()!=m2.getCoords().getHiddenCppPointer());
1936         self.assertRaises(InterpKernelException,m1.tryToShareSameCoords,m2,1e-12)
1937         pass
1938
1939     def testFindNodeOnPlane(self):
1940         mesh=MEDCouplingDataForTest.build3DTargetMesh_1();
1941         pt=[300.,300.,0.]
1942         v=[0.,0.,2.]
1943         n=mesh.findNodesOnPlane(pt,v,1e-12);
1944         self.assertEqual(9,len(n));
1945         m3dSurf=mesh.buildFacePartOfMySelfNode(n,True);
1946         self.assertTrue(isinstance(m3dSurf,MEDCouplingUMesh))
1947         me=MEDCouplingExtrudedMesh.New(mesh,m3dSurf,0);
1948         da=me.getMesh3DIds();
1949         self.assertEqual(8,me.getNumberOfCells());
1950         expected=[0,1,2,3,4,5,6,7]
1951         val=da.getValues();
1952         self.assertEqual(expected,list(val));
1953         #
1954         m3dSurf=mesh.buildFacePartOfMySelfNode(n,True);
1955         self.assertTrue(isinstance(m3dSurf,MEDCouplingUMesh))
1956         me=MEDCouplingExtrudedMesh.New(mesh,m3dSurf,0);
1957         da=me.getMesh3DIds();
1958         self.assertEqual(8,me.getNumberOfCells());
1959         expected=[0,1,2,3,4,5,6,7]
1960         val=da.getValues();
1961         self.assertEqual(expected,list(val));
1962         pass
1963
1964     def testRenumberCells(self):
1965         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
1966         m2=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
1967         self.assertTrue(m.isEqual(m2,0));
1968         arr=[12,3,25,2,26]
1969         m.renumberCells(arr,True);
1970         self.assertTrue(not m.isEqual(m2,0));
1971         self.assertEqual(NORM_QUAD4,m.getTypeOfCell(0));
1972         self.assertEqual(NORM_TRI3,m.getTypeOfCell(1));
1973         self.assertEqual(NORM_QUAD4,m.getTypeOfCell(2));
1974         self.assertEqual(NORM_TRI3,m.getTypeOfCell(3));
1975         self.assertEqual(NORM_QUAD4,m.getTypeOfCell(4));
1976         arr2=[5,-1,-5,4,8]
1977         m.renumberCells(arr2,True);
1978         self.assertTrue(m.isEqual(m2,0));
1979         pass
1980
1981     def testChangeSpaceDimension(self):
1982         m1=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
1983         m2=MEDCouplingDataForTest.build2DTargetMesh_1();
1984         #
1985         self.assertEqual(3,m1.getSpaceDimension());
1986         m1.changeSpaceDimension(2);
1987         self.assertEqual(2,m1.getSpaceDimension());
1988         m1.setName(m2.getName());
1989         self.assertTrue(m1.isEqual(m2,1e-12));
1990         m1.changeSpaceDimension(3);
1991         self.assertEqual(3,m1.getSpaceDimension());
1992         expected=[-0.3,-0.3,0., 0.2,-0.3,0., 0.7,-0.3,0., -0.3,0.2,0., 0.2,0.2,0., 0.7,0.2,0., -0.3,0.7,0., 0.2,0.7,0., 0.7,0.7,0.]
1993         val=m1.getCoords().getValues();
1994         for i in xrange(27):
1995             self.assertTrue(abs(expected[i]-val[i])<1e-14);
1996             pass
1997         pass
1998
1999     def testGaussPointField1(self):
2000         _a=0.446948490915965;
2001         _b=0.091576213509771;
2002         _p1=0.11169079483905;
2003         _p2=0.0549758718227661;
2004         refCoo1=[ 0.,0., 1.,0., 0.,1. ]
2005         gsCoo1=[ 2*_b-1, 1-4*_b, 2*_b-1, 2.07*_b-1, 1-4*_b,
2006                  2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 ]
2007         wg1=[ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 ]
2008         _refCoo1=refCoo1
2009         _gsCoo1=gsCoo1
2010         _wg1=wg1
2011         #
2012         m=MEDCouplingDataForTest.build2DTargetMesh_1();
2013         f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,NO_TIME);
2014         f.setMesh(m);
2015         self.assertEqual(5,f.getNumberOfMeshPlacesExpected());
2016         self.assertEqual(0,f.getNbOfGaussLocalization());
2017         f.setGaussLocalizationOnType(NORM_TRI3,_refCoo1,_gsCoo1,_wg1);
2018         f.setGaussLocalizationOnType(NORM_TRI3,_refCoo1,_gsCoo1,_wg1); # not a bug only to check that it works well
2019         self.assertRaises(InterpKernelException,f.setGaussLocalizationOnType,NORM_QUAD4,_refCoo1,_gsCoo1,_wg1)
2020         self.assertEqual(1,f.getNbOfGaussLocalization());
2021         refCoo2=[ 0.,0., 1.,0., 1.,1., 0.,1. ]
2022         _refCoo2=refCoo2
2023         _gsCoo1=_gsCoo1[0:4]
2024         _wg1=_wg1[0:2]
2025         f.setGaussLocalizationOnType(NORM_QUAD4,_refCoo2,_gsCoo1,_wg1);
2026         self.assertEqual(2,f.getNbOfGaussLocalization());
2027         array=DataArrayDouble.New();
2028         ptr=18*2*[None]
2029         for i in xrange(18*2):
2030             ptr[i]=float(i+1)
2031         array.setValues(ptr,18,2);
2032         ptr=array.getPointer();
2033         f.setArray(array);
2034         f.setName("MyFirstFieldOnGaussPoint");
2035         f.checkCoherency();
2036         self.assertAlmostEqual(27.,f.getIJK(2,5,0),14);
2037         self.assertAlmostEqual(16.,f.getIJK(1,5,1),14);
2038         #
2039         f.clearGaussLocalizations();
2040         self.assertEqual(0,f.getNbOfGaussLocalization());
2041         self.assertRaises(InterpKernelException,f.checkCoherency);
2042         ids1=[0,1,3,4]
2043         self.assertRaises(InterpKernelException,f.setGaussLocalizationOnCells,ids1,_refCoo2,_gsCoo1,_wg1);
2044         self.assertEqual(0,f.getNbOfGaussLocalization());
2045         ids2=[0,4]
2046         f.setGaussLocalizationOnCells(ids2,_refCoo2,_gsCoo1,_wg1);
2047         self.assertEqual(1,f.getNbOfGaussLocalization());
2048         self.assertEqual(0,f.getGaussLocalizationIdOfOneCell(0));
2049         self.assertRaises(InterpKernelException,f.getGaussLocalizationIdOfOneCell,1);
2050         ids3=[1,2]
2051         f.setGaussLocalizationOnCells(ids3,_refCoo1,_gsCoo1,_wg1);
2052         self.assertEqual(2,f.getNbOfGaussLocalization());
2053         self.assertEqual(0,f.getGaussLocalizationIdOfOneCell(0));
2054         self.assertEqual(1,f.getGaussLocalizationIdOfOneCell(1));
2055         self.assertEqual(1,f.getGaussLocalizationIdOfOneCell(2));
2056         self.assertRaises(InterpKernelException,f.checkCoherency);#<- cell 3 has no localization
2057         ids4=[3]
2058         _gsCoo2=_gsCoo1;
2059         _wg2=_wg1;
2060         _gsCoo2[0]=0.8888777776666;
2061         _wg2[0]=0.1234567892377;
2062         f.setGaussLocalizationOnCells(ids4,_refCoo2,_gsCoo2,_wg2);
2063         self.assertEqual(3,f.getNbOfGaussLocalization());
2064         tmpIds=f.getCellIdsHavingGaussLocalization(0);
2065         self.assertEqual(ids2,list(tmpIds.getValues()));
2066         self.assertRaises(InterpKernelException,f.checkCoherency);#<- it's always not ok because undelying array not with the good size.
2067         array2=f.getArray().substr(0,10);
2068         f.setArray(array2);
2069         f.checkCoherency();#<- here it is OK
2070         f2=f.clone(True);
2071         self.assertTrue(f.isEqual(f2,1e-14,1e-14));
2072         gl1=f2.getGaussLocalization(0);
2073         tmp=gl1.getGaussCoord(1,1);
2074         self.assertAlmostEqual(2.07*_b-1,tmp,14);
2075         gl1.setGaussCoord(1,1,0.07);
2076         self.assertTrue(not f.isEqual(f2,1e-14,1e-14));
2077         gl1.setGaussCoord(1,1,tmp);
2078         self.assertTrue(f.isEqual(f2,1e-14,1e-14));
2079         f2.checkCoherency();
2080         pass
2081
2082     def testGaussPointNEField1(self):
2083         m=MEDCouplingDataForTest.build2DTargetMesh_1();
2084         f=MEDCouplingFieldDouble.New(ON_GAUSS_NE,NO_TIME);
2085         f.setMesh(m);
2086         self.assertEqual(5,f.getNumberOfMeshPlacesExpected());
2087         f.setName("MyFirstFieldOnNE");
2088         f.setDescription("MyDescriptionNE");
2089         array=DataArrayDouble.New();
2090         tmp=18*2*[None]
2091         for i in xrange(18*2):
2092             tmp[i]=float(i+7)
2093             pass
2094         array.setValues(tmp,18,2);
2095         ptr=array.getPointer();
2096         f.setArray(array);
2097         #
2098         f.checkCoherency();
2099         f2=f.clone(True);
2100         self.assertTrue(f.isEqual(f2,1e-14,1e-14));
2101         self.assertAlmostEqual(21.,f.getIJK(2,0,0),14);
2102         self.assertAlmostEqual(18.,f.getIJK(1,1,1),14);
2103         pass
2104
2105     def testCellOrientation1(self):
2106         m=MEDCouplingDataForTest.build2DTargetMesh_1();
2107         vec=[0.,0.,-1.]
2108         self.assertRaises(InterpKernelException,m.are2DCellsNotCorrectlyOriented,vec,False);
2109         m.changeSpaceDimension(3);
2110         res1=m.are2DCellsNotCorrectlyOriented(vec,False);
2111         self.assertTrue(len(res1)==0);
2112         vec[2]=1.;
2113         res1=m.are2DCellsNotCorrectlyOriented(vec,False);
2114         self.assertEqual(5,len(res1));
2115         #
2116         vec[2]=-1.;
2117         # connectivity inversion
2118         conn=m.getNodalConnectivity().getValues();
2119         tmp=conn[11];
2120         conn[11]=conn[12];
2121         conn[12]=tmp;
2122         m.getNodalConnectivity().setValues(conn,len(conn),1)
2123         res1=m.are2DCellsNotCorrectlyOriented(vec,False);
2124         self.assertEqual(1,len(res1));
2125         self.assertEqual(2,res1.getValues()[0]);
2126         m.orientCorrectly2DCells(vec,False);
2127         res1=m.are2DCellsNotCorrectlyOriented(vec,False);
2128         self.assertTrue(len(res1)==0);
2129         m2=MEDCouplingDataForTest.build2DTargetMesh_1();
2130         m2.changeSpaceDimension(3);
2131         self.assertTrue(m.isEqual(m2,1e-12));
2132         pass
2133
2134     def testCellOrientation2(self):
2135         m2,m1=MEDCouplingDataForTest.build3DExtrudedUMesh_1();
2136         res1=m2.arePolyhedronsNotCorrectlyOriented();
2137         self.assertEqual(6,len(res1));
2138         m2.orientCorrectlyPolyhedrons();
2139         res1=m2.arePolyhedronsNotCorrectlyOriented();
2140         self.assertTrue(len(res1)==0);
2141         m2.checkCoherency();
2142         self.assertEqual(18,m2.getNumberOfCells());
2143         cellIds2=[0,6,12]
2144         m2.convertToPolyTypes(cellIds2);
2145         m2.orientCorrectlyPolyhedrons();
2146         res1=m2.arePolyhedronsNotCorrectlyOriented();
2147         self.assertTrue(len(res1)==0);
2148         f2=m2.getMeasureField(False);
2149         f2Ptr=f2.getArray().getValues();
2150         #Test to check global reverse in MEDCouplingUMesh::tryToCorrectPolyhedronOrientation
2151         m3=MEDCouplingDataForTest.build2DTargetMesh_1();
2152         vec=[0.,0.,1.]
2153         m3.changeSpaceDimension(3);
2154         ids2=[0,1,2,3,4]
2155         m3.convertToPolyTypes(ids2);
2156         m3.orientCorrectly2DCells(vec,False);
2157         m4=MEDCouplingDataForTest.buildCU1DMesh_U();
2158         m4.changeSpaceDimension(3);
2159         center=[0.,0.,0.]
2160         vector=[0.,1.,0.]
2161         m4.rotate(center,vector,-pi/2.);
2162         m5=m3.buildExtrudedMesh(m4,0);
2163         res1=m5.arePolyhedronsNotCorrectlyOriented();
2164         self.assertEqual(15,len(res1));
2165         m5.orientCorrectlyPolyhedrons();
2166         res1=m5.arePolyhedronsNotCorrectlyOriented();
2167         self.assertTrue(len(res1)==0);
2168         f3=m5.getMeasureField(False);
2169         self.assertEqual(15,f3.getArray().getNumberOfTuples());
2170         self.assertEqual(1,f3.getNumberOfComponents());
2171         f3Ptr=f3.getArray().getValues();
2172         expected1=[0.075,0.0375,0.0375,0.075,0.075, 0.1125,0.05625,0.05625,0.1125,0.1125, 0.0625,0.03125,0.03125,0.0625,0.0625];
2173         for i in xrange(15):
2174             self.assertTrue(abs(expected1[i]-f3Ptr[i])<1e-12);
2175             pass
2176         f4=m5.getBarycenterAndOwner();
2177         self.assertEqual(15,f4.getNumberOfTuples());
2178         self.assertEqual(3,f4.getNumberOfComponents());
2179         f4Ptr=f4.getValues();
2180         expected2=[-0.05,-0.05,0.15, 0.3666666666666667,-0.13333333333333333,0.15, 0.53333333333333333,0.033333333333333333,0.15, -0.05,0.45,0.15, 0.45,0.45,0.15,-0.05,-0.05,0.525, 0.3666666666666667,-0.13333333333333333,0.525, 0.53333333333333333,0.033333333333333333,0.525, -0.05,0.45,0.525, 0.45,0.45,0.525,-0.05,-0.05,0.875, 0.3666666666666667,-0.13333333333333333,0.875, 0.53333333333333333,0.033333333333333333,0.875, -0.05,0.45,0.875, 0.45,0.45,0.875];
2181         for i in xrange(45):
2182             self.assertTrue(abs(expected2[i]-f4Ptr[i])<1e-12);
2183             pass
2184         pass
2185
2186     def testCellOrientation3(self):
2187         from cmath import rect  
2188
2189         c = [rect(1.0, i*pi/4.0) for i in range(8)]
2190         coords = [c[-1].real,c[-1].imag,  c[3].real,c[3].imag,
2191                    c[5].real,c[5].imag,  c[1].real,c[1].imag]
2192         connec = [0,1,2,3] 
2193         baseMesh = MEDCouplingUMesh.New("circle", 2)  
2194         baseMesh.allocateCells(1)
2195         meshCoords = DataArrayDouble.New(coords, 4, 2)
2196         baseMesh.setCoords(meshCoords)
2197         baseMesh.insertNextCell(NORM_QPOLYG, connec)  # a circle
2198         baseMesh.finishInsertingCells()  
2199         baseMesh.changeSpaceDimension(3)
2200         Oz = [0.0, 0.0, -1.0] 
2201         cell_lst = baseMesh.are2DCellsNotCorrectlyOriented(Oz, False)
2202         self.assertEqual(cell_lst.getNumberOfTuples(), 0)
2203         Oz[2] = 1.0
2204         cell_lst = baseMesh.are2DCellsNotCorrectlyOriented(Oz, False)
2205         self.assertEqual(cell_lst.getNumberOfTuples(), 1)
2206
2207     def testPolyhedronBarycenter(self):
2208         connN=[0,3,2,1, -1, 4,5,6,7, -1, 0,4,7,3, -1, 3,7,6,2, -1, 2,6,5,1, -1, 1,5,4,0];
2209         coords=[0.,0.,0., 1.,0.,0., 1.,1.,0., 0.,1.,0., 0.,0.,1., 1.,0.,1., 1.,1.,1., 0.,1.,1., 0.5, 0.5, 0.5];
2210         meshN=MEDCouplingUMesh.New();
2211         meshN.setName("ForBary");
2212         meshN.setMeshDimension(3);
2213         meshN.allocateCells(4);
2214         meshN.insertNextCell(NORM_POLYHED,29,connN[0:29])
2215         meshN.finishInsertingCells();
2216         myCoords=DataArrayDouble.New();
2217         myCoords.setValues(coords,9,3);
2218         meshN.setCoords(myCoords);
2219         meshN.checkCoherency();
2220         #
2221         res1=meshN.arePolyhedronsNotCorrectlyOriented();
2222         meshN.orientCorrectlyPolyhedrons();
2223         self.assertTrue(len(res1)==0);
2224         da=meshN.getBarycenterAndOwner();
2225         self.assertEqual(1,da.getNumberOfTuples());
2226         self.assertEqual(3,da.getNumberOfComponents());
2227         daPtr=da.getValues();
2228         ref=meshN.getCoords().getValues()[24:];
2229         for i in xrange(3):
2230             self.assertTrue(abs(ref[i]-daPtr[i])<1e-12);
2231             pass
2232         #
2233         center=[0.,0.,0.]
2234         vec=[0.,2.78,0.]
2235         da=meshN.getBarycenterAndOwner();
2236         daPtr=da.getValues();
2237         ref=meshN.getCoords().getValues()[24:];
2238         for i in xrange(3):
2239             self.assertTrue(abs(ref[i]-daPtr[i])<1e-12);
2240             pass
2241         #
2242         meshN.rotate(center,vec,pi/7.);
2243         meshN.translate(vec);
2244         da=meshN.getBarycenterAndOwner();
2245         daPtr=da.getValues();
2246         ref=meshN.getCoords().getValues()[24:];
2247         for i in xrange(3):
2248             self.assertTrue(abs(ref[i]-daPtr[i])<1e-12);
2249             pass
2250         #
2251         center2=[1.12,3.45,6.78]
2252         vec2=[4.5,9.3,2.8]
2253         meshN.rotate(center2,vec2,e);
2254         meshN.translate(vec2);
2255         da=meshN.getBarycenterAndOwner();
2256         daPtr=da.getValues();
2257         ref=meshN.getCoords().getValues()[24:];
2258         for i in xrange(3):
2259             self.assertTrue(abs(ref[i]-daPtr[i])<1e-10);
2260             pass
2261         pass
2262
2263     def testNormL12Integ1D(self):
2264         m1=MEDCouplingDataForTest.build1DTargetMesh_3();
2265         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
2266         f1.setMesh(m1);
2267         array=DataArrayDouble.New();
2268         arr=[-5.23,15.45,-25.56,6.67,-16.78,26.89,-7.91,17.23,-27.43,8.21,-18.63,28.72]
2269         array.setValues(arr,m1.getNumberOfCells(),3);
2270         f1.setArray(array);
2271         #
2272         f3=m1.getBarycenterAndOwner();
2273         self.assertEqual(4,f3.getNumberOfTuples());
2274         self.assertEqual(1,f3.getNumberOfComponents());
2275         expected9=[0.75,5.105,0.8,5.155]
2276         ptr=f3.getValues();
2277         for i in xrange(4):
2278             self.assertTrue(abs(expected9[i]-ptr[i])<1e-12);
2279             pass
2280         #
2281         f2=m1.getMeasureField(False);
2282         self.assertEqual(4,f2.getArray().getNumberOfTuples());
2283         self.assertEqual(1,f2.getNumberOfComponents());
2284         expected1=[0.5,0.21,-0.6,-0.31]
2285         ptr=f2.getArray().getValues();
2286         for i in xrange(4):
2287             self.assertTrue(abs(expected1[i]-ptr[i])<1e-12);
2288             pass
2289         expected2=[0.5,0.21,0.6,0.31]
2290         f2=m1.getMeasureField(True);
2291         ptr=f2.getArray().getValues();
2292         for i in xrange(4):
2293             self.assertTrue(abs(expected2[i]-ptr[i])<1e-12);
2294             pass
2295         #integral
2296         self.assertTrue(4,f1.getNumberOfTuples())
2297         res=f1.integral(False);
2298         self.assertTrue(3,len(res))
2299         expected3=[0.9866,-0.3615,0.4217]
2300         for i in xrange(3):
2301             self.assertTrue(abs(expected3[i]-res[i])<1e-12);
2302             pass
2303         self.assertTrue(abs(expected3[0]-f1.integral(0,False))<1e-12);
2304         self.assertTrue(abs(expected3[1]-f1.integral(1,False))<1e-12);
2305         self.assertTrue(abs(expected3[2]-f1.integral(2,False))<1e-12);
2306         res=f1.integral(True);
2307         expected4=[-3.4152,8.7639,-14.6879]
2308         for i in xrange(3):
2309             self.assertTrue(abs(expected4[i]-res[i])<1e-12);
2310             pass
2311         #normL1
2312         res=f1.normL1();
2313         self.assertTrue(3,len(res))
2314         expected5=[6.979506172839505, 16.89018518518518, 27.02969135802469]
2315         for i in xrange(3):
2316             self.assertTrue(abs(expected5[i]-res[i])<1e-12);
2317             pass
2318         self.assertTrue(abs(expected5[0]-f1.normL1(0))<1e-12);
2319         self.assertTrue(abs(expected5[1]-f1.normL1(1))<1e-12);
2320         self.assertTrue(abs(expected5[2]-f1.normL1(2))<1e-12);
2321         #normL2
2322         res=f1.normL2();
2323         self.assertTrue(3,len(res))
2324         expected7=[7.090910979452395, 16.9275542960123, 27.053271464160858]
2325         for i in xrange(3):
2326             self.assertTrue(abs(expected7[i]-res[i])<1e-9);
2327             pass
2328         self.assertTrue(abs(expected7[0]-f1.normL2(0))<1e-9);
2329         self.assertTrue(abs(expected7[1]-f1.normL2(1))<1e-9);
2330         self.assertTrue(abs(expected7[2]-f1.normL2(2))<1e-9);
2331         #buildMeasureField
2332         f4=f1.buildMeasureField(False);
2333         self.assertTrue(abs(-0.2-f4.accumulate(0))<1e-12);
2334         f4=f1.buildMeasureField(True);
2335         self.assertTrue(abs(1.62-f4.accumulate(0))<1e-12);
2336         # Testing with 2D Curve
2337         m1=MEDCouplingDataForTest.build2DCurveTargetMesh_3();
2338         f2=m1.getMeasureField(False);
2339         self.assertEqual(4,f2.getArray().getNumberOfTuples());
2340         self.assertEqual(1,f2.getNumberOfComponents());
2341         ptr=f2.getArray().getValues();
2342         for i in xrange(4):
2343             self.assertTrue(abs(sqrt(2.)*expected2[i]-ptr[i])<1e-12);
2344             pass
2345         f2=m1.getMeasureField(True);
2346         self.assertEqual(4,f2.getArray().getNumberOfTuples());
2347         self.assertEqual(1,f2.getNumberOfComponents());
2348         ptr=f2.getArray().getValues();
2349         for i in xrange(4):
2350             self.assertTrue(abs(expected2[i]*sqrt(2.)-ptr[i])<1e-12);
2351             pass
2352         #bary
2353         f3=m1.getBarycenterAndOwner();
2354         self.assertEqual(4,f3.getNumberOfTuples());
2355         self.assertEqual(2,f3.getNumberOfComponents());
2356         expected10=[0.75,0.75,5.105,5.105,0.8,0.8,5.155,5.155]
2357         ptr=f3.getValues();
2358         for i in xrange(8):
2359             self.assertTrue(abs(expected10[i]-ptr[i])<1e-12);
2360             pass
2361         #
2362         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
2363         f1.setMesh(m1);
2364         array=DataArrayDouble.New();
2365         array.setValues(arr,m1.getNumberOfCells(),3);
2366         f1.setArray(array);
2367         res=f1.integral(False);
2368         for i in xrange(3):
2369             self.assertTrue(abs(sqrt(2.)*expected4[i]-res[i])<1e-12);
2370             pass
2371         res=f1.integral(True);
2372         for i in xrange(3):
2373             self.assertTrue(abs(sqrt(2.)*expected4[i]-res[i])<1e-12);
2374             pass
2375         res=f1.normL1();
2376         for i in xrange(3):
2377             self.assertTrue(abs(expected5[i]-res[i])<1e-12);
2378             pass
2379         res=f1.normL2();
2380         for i in xrange(3):
2381             self.assertTrue(abs(expected7[i]-res[i])<1e-12);
2382             pass
2383         pass
2384
2385     def testAreaBary2D(self):
2386         m1=MEDCouplingDataForTest.build2DTargetMesh_3();
2387         f1=m1.getMeasureField(False);
2388         self.assertEqual(10,f1.getArray().getNumberOfTuples());
2389         self.assertEqual(1,f1.getNumberOfComponents());
2390         expected1=[-0.5,-1,-1.5,-0.5,-1,  0.5,1,1.5,0.5,1]
2391         ptr=f1.getArray().getValues();
2392         for i in xrange(10):
2393             self.assertTrue(abs(expected1[i]-ptr[i])<1e-12);
2394             pass
2395         f1=m1.getMeasureField(True);
2396         ptr=f1.getArray().getValues();
2397         for i in xrange(10):
2398             self.assertTrue(abs(abs(expected1[i])-ptr[i])<1e-12);
2399             pass
2400         f2=m1.getBarycenterAndOwner();
2401         self.assertEqual(10,f2.getNumberOfTuples());
2402         self.assertEqual(2,f2.getNumberOfComponents());
2403         expected2=[0.5,0.3333333333333333,0.5,0.5,0.5,0.77777777777777777,0.5,0.3333333333333333,0.5,0.5,0.5,0.3333333333333333,0.5,0.5,0.5,0.77777777777777777,0.5,0.3333333333333333,0.5,0.5]
2404         ptr=f2.getValues();
2405         for i in xrange(20):
2406             self.assertTrue(abs(expected2[i]-ptr[i])<1e-12);
2407             pass
2408         m1.changeSpaceDimension(3);
2409         f1=m1.getMeasureField(False);
2410         self.assertEqual(10,f1.getArray().getNumberOfTuples());
2411         self.assertEqual(1,f1.getNumberOfComponents());
2412         ptr=f1.getArray().getValues();
2413         for i in xrange(10):
2414             self.assertTrue(abs(abs(expected1[i])-ptr[i])<1e-12);
2415             pass
2416         f2=m1.getBarycenterAndOwner();
2417         self.assertEqual(10,f2.getNumberOfTuples());
2418         self.assertEqual(3,f2.getNumberOfComponents());
2419         ptr=f2.getValues();
2420         expected3=[0.5,0.3333333333333333,0.,0.5,0.5,0.,0.5,0.77777777777777777,0.,0.5,0.3333333333333333,0.,0.5,0.5,0., 0.5,0.3333333333333333,0.,0.5,0.5,0.,0.5,0.77777777777777777,0.,0.5,0.3333333333333333,0.,0.5,0.5,0.]
2421         for i in xrange(30):
2422             self.assertTrue(abs(expected3[i]-ptr[i])<1e-12);
2423             pass
2424         pass
2425
2426     def testAreaBary3D(self):
2427         coords=[ 0.241310763507 , 0.0504777305619 , 0.0682283524903 , 0.252501053866 , -0.0625176732937 , 0.137272639894 ,
2428                  0.152262663601 , 0.241816569527 , 0.133812556197 , 0.18047750211 , -0.0789949051358 , 0.339098173401 ,
2429                  0.151741971857 , 0.238885278571 , 0.137715037333 , 0.242532155481 , -0.0928169086456 , 0.0678043417367 ,
2430                  0.240941965335 , -0.015461491464 , 0.0617186345825 , 0.24127650112 , 0.0499427876717 , 0.0679634099148 ,
2431                  -0.145828917428 , 0.206291632565 , 0.0310071927543 , 0.0125651775307 , 0.266262085828 , 0.105228430543 ,
2432                  -0.0994066533286 , 0.233224271238 , 0.0572213839567 , -0.0951345338317 , 0.234819509426 , 0.0592126284538 ,
2433                  0.136580574205 , -0.205486212579 , 0.0572866072014 , 0.0637270784978 , -0.168886355238 , 0.446614057077 ,
2434                  0.041337157151 , -0.213402568198 , 0.372407095999 , 0.0411601970268 , -0.202387875756 , 0.411334979491 ,
2435                  -0.108355701857 , 0.193636239335 , 0.204886756738 , 0.00639779029829 , 0.155296981517 , 0.252585892979 ,
2436                  0.0262473111702 , -0.112919732543 , 0.424286639249 ,-0.224103052733 , -0.139430015438 , -0.0122352295701 ,
2437                 -0.0312760589481 , -0.274272003594 , 0.0323959636568 , -0.166663422532 , -0.217754445175 , 0.00392109070364 ,
2438                  -0.30586619777 , -0.0475168041091 , -0.0144585228182 , -0.280881480586 , 0.135571293538 , 0.00623923647986 ,
2439                  -0.25548538234 , 0.156819217766 , 0.0645277879769 , -0.131567009284 , 0.184133752309 , 0.206021802753 ,
2440                  -0.196204010965 , 0.151602971681 , 0.212974777736 , -0.183713879463 , 0.0802946639531 , 0.260115662599 ,
2441                  -0.244241178767 , -0.0738873389604 , 0.144590565817 , -0.155804057829 , -0.164892720025 , 0.210613950558 ,
2442                  -0.170950800428 , -0.215099334026 , 0.00610122860092 , -0.30552634869 , -0.0490020791904 , -0.0132786533145 ,
2443                  0.271831011884 , 0.15105657296 , 0.0230534827908 , 0.281919192283 , 0.0898544306288 , -0.0625201489143 ,
2444                  0.260240727276 , -0.0120688706637 , -0.0532316588626 , 0.244947737722 , 0.0197984684293 , 0.0309341209233 ,
2445                  0.23439631578 , 0.229825279875 , 0.0508520585381 , 0.160921316875 , 0.265078502128 , 0.121716560626 ,
2446                  -0.315088694175 , 0.0747700471918 , -0.245836615071 , -0.327728781776 , 0.0857114674649 , -0.239431905957 ,
2447                  -0.308385460634 , 0.145142997084 , -0.149886828433 , 0.0488236045164 , 0.309462801914 , 0.0849169148265 ,
2448                 -0.0244964803395 , 0.33145611751 , -0.0476415818061 , 0.0060567994229 , 0.32418412014 , 0.0367779543812 ,
2449                  -0.0950221448063 , 0.236675326003 , 0.0572594453983 , 0.248723023186 , 0.0886648784791 , -0.176629430538 ,
2450                  0.116796984 , 0.256596599567 , -0.292863523603 , 0.118024552914 , 0.229154257843 , -0.34233232501 ,
2451                  0.217507892549 , -0.0417822335742 , -0.176771782888 , -0.224429321304 , 0.0125595300114 , -0.362064725588 ,
2452                  0.0937301100955 , -0.0500824832657 , -0.299713548444 , -0.244162220397 , 0.0383853931293 , -0.389856984411 ,
2453                  -0.0281989366102 , 0.097392811563 , -0.458244577284 , -0.385010847162 , 0.10122766194 , -0.140052859922 ,
2454                  -0.377936358012 , 0.110875172128 , -0.176207095463 , 0.244483045556 , -0.0991073977045 , 0.0575134372934 ,
2455                 0.262605120167 , -0.100243191645 , -0.0495620806935 , 0.240306880972 , -0.136153701579 , -0.114745281696 ,
2456                  0.215763176129 , -0.0836766059189 , -0.183249640616 , 0.237870396603 , -0.132449578286 , -0.121598854639 ,
2457                  -0.0637683083097 , -0.27921020214 , -0.149112321992 , -0.0856211014977 , -0.2973233473 , -0.0446878139589 ,
2458                  0.104675342288 , -0.0625908305324 , -0.290346256534 , 0.0248264249186 , -0.247797708548 , -0.165830884019 ,
2459                  0.0719302438309 , -0.178468260473 , -0.211432157345 , 0.142871843159 , -0.208769948542 , 0.0454101128246 ,
2460                  0.167803379307 , -0.207851396623 , -0.088802726124 , 0.12868717152 , -0.230920439715 , 0.00760508389036 ,
2461                  -0.0372812069535 , -0.286740286332 , 0.00963701291166 ]
2462         
2463         connN = [ #polyhedron 0
2464             0 , 1 , 3 , 4 , 2 , -1 , 1 , 5 , 6 , 7 , 0 , -1 , 0 , 7 , 8 , 10 , 11 , 9 , 2 , -1 , 1 , 5 , 12 , 14 , 15 , 13 , 3 , -1 , 16 , 9 , 2 , 4 , 17 , -1
2465             , 4 , 3 , 13 , 18 , 17 , -1 , 5 , 6 , 19 , 21 , 20 , 12 , -1 , 6 , 7 , 8 , 23 , 22 , 19 , -1 , 23 , 24 , 10 , 8 , -1 , 25 , 11 , 9 , 16 , -1
2466             , 24 , 26 , 25 , 11 , 10 , -1 , 12 , 14 , 20 , -1 , 27 , 28 , 29 , 15 , 13 , 18 , -1 , 14 , 15 , 29 , 30 , 21 , 20 , -1 , 26 , 27 , 18 , 17 , 16 , 25 , -1
2467             , 22 , 19 , 21 , 30 , 31 , -1 , 22 , 31 , 28 , 27 , 26 , 24 , 23 , -1 , 31 , 30 , 29 , 28,
2468             # polyhedron 1
2469             0 , 7 , 8 , 10 , 11 , 9 , 2 , -1 , 32 , 0 , 7 , 35 , 34 , 33 , -1 , 32 , 0 , 2 , 37 , 36 , -1 , 35 , 7 , 8 , 40 , 39 , 38 , -1
2470             , 2 , 37 , 41 , 9 , -1 , 40 , 8 , 10 , 44 , 43 , 42 , -1 , 41 , 9 , 11 , 44 , 43 , -1 , 44 , 11 , 10 , -1 , 32 , 33 , 45 , 47 , 46 , 36 , -1
2471             , 33 , 34 , 48 , 45 , -1 , 35 , 34 , 48 , 50 , 49 , 38 , -1 , 41 , 43 , 42 , 46 , 36 , 37 , -1 , 38 , 39 , 51 , 49 , -1
2472             , 39 , 40 , 42 , 46 , 47 , 52 , 51 , -1 , 45 , 47 , 52 , 50 , 48 , -1 , 52 , 51 , 49 , 50,
2473             # polyhedron 2
2474             6 , 7 , 8 , 23 , 22 , 19 , -1 , 6 , 35 , 7 , -1 , 6 , 35 , 38 , 19 , -1 , 35 , 7 , 8 , 40 , 39 , 38 , -1 , 53 , 22 , 19 , 38 , 39 , 54 , -1
2475             , 23 , 53 , 54 , 40 , 8 , -1 , 53 , 22 , 23 , -1 , 39 , 54 , 40,
2476             # polyhedron 3
2477             35 , 34 , 48 , 50 , 49 , 38 , -1 , 6 , 35 , 34 , 56 , 55 , 5 , -1 , 6 , 35 , 38 , 19 , -1 , 34 , 56 , 57 , 59 , 58 , 48 , -1
2478             , 60 , 61 , 21 , 19 , 38 , 49 , -1 , 62 , 50 , 48 , 58 , -1 , 60 , 63 , 64 , 62 , 50 , 49 , -1 , 5 , 6 , 19 , 21 , 20 , 12 , -1
2479             , 55 , 5 , 12 , 65 , -1 , 66 , 67 , 65 , 55 , 56 , 57 , -1 , 63 , 66 , 57 , 59 , 64 , -1 , 64 , 62 , 58 , 59 , -1
2480             , 60 , 63 , 66 , 67 , 68 , 61 , -1 , 61 , 68 , 20 , 21 , -1 , 67 , 68 , 20 , 12 , 65]
2481         
2482         barys = [ -0.0165220465527 , -0.0190922868195 , 0.158882733414 ,
2483                   0.0287618656076 , 0.135874379934 , -0.14601588119 ,
2484                   -0.147128055553 , 0.0465995097041 , -0.049391174453 ,
2485                   -0.00142506732317 , -0.0996953090351 , -0.115159183132 ]
2486         meshN=MEDCouplingUMesh.New();
2487         meshN.setName("ForBary");
2488         meshN.setMeshDimension(3);
2489         meshN.allocateCells(4);
2490         meshN.insertNextCell(NORM_POLYHED,113,connN);
2491         meshN.insertNextCell(NORM_POLYHED,99,connN[113:]);
2492         meshN.insertNextCell(NORM_POLYHED,43,connN[212:]);
2493         meshN.insertNextCell(NORM_POLYHED,92,connN[255:]);
2494         meshN.finishInsertingCells();
2495         myCoords=DataArrayDouble.New();
2496         myCoords.setValues(coords,69,3);
2497         meshN.setCoords(myCoords);
2498         meshN.checkCoherency();
2499         res1=meshN.arePolyhedronsNotCorrectlyOriented();
2500         meshN.orientCorrectlyPolyhedrons();
2501         res1=meshN.arePolyhedronsNotCorrectlyOriented();
2502         self.assertTrue(len(res1)==0);
2503         #
2504         da=meshN.getBarycenterAndOwner();
2505         self.assertEqual(4,da.getNumberOfTuples());
2506         self.assertEqual(3,da.getNumberOfComponents());
2507         daPtr=da.getValues();
2508         for i in xrange(12):
2509             self.assertTrue(abs(barys[i]-daPtr[i])<1e-12);
2510             pass
2511         pass
2512
2513     def testRenumberCellsForFields(self):
2514         m=MEDCouplingDataForTest.build2DTargetMesh_1();
2515         f=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
2516         f.setMesh(m);
2517         arr=DataArrayDouble.New();
2518         nbOfCells=m.getNumberOfCells();
2519         values1=[7.,107.,10007.,8.,108.,10008.,9.,109.,10009.,10.,110.,10010.,11.,111.,10011.]
2520         arr.setValues(values1,nbOfCells,3);
2521         f.setArray(arr);
2522         renumber1=[3,1,0,4,2]
2523         loc=[-0.05,-0.05, 0.55,-0.25, 0.55,0.15, -0.05,0.45, 0.45,0.45]
2524         for j in xrange(5):
2525             res=f.getValueOn(loc[2*j:2*j+2]);
2526             for i in xrange(3):
2527                 self.assertTrue(abs(values1[i+3*j]-res[i])<1e-12);
2528                 pass
2529             pass
2530         f.renumberCells(renumber1,False);
2531         ptr=f.getArray().getValues();
2532         expected1=[9.,109.,10009.,8.,108.,10008.,11.,111.,10011.,7.,107.,10007.,10.,110.,10010.]
2533         for i in xrange(15):
2534             self.assertTrue(abs(expected1[i]-ptr[i])<1e-12);
2535             pass
2536         #check that fields remains the same geometrically
2537         for j in xrange(5):
2538             res=f.getValueOn(loc[2*j:2*(j+1)]);
2539             for i in xrange(3):
2540                 self.assertTrue(abs(values1[i+3*j]-res[i])<1e-12);
2541                 pass
2542             pass
2543         #On gauss
2544         f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,NO_TIME);
2545         f.setMesh(m);
2546         _a=0.446948490915965;
2547         _b=0.091576213509771;
2548         _p1=0.11169079483905;
2549         _p2=0.0549758718227661;
2550         refCoo1=[ 0.,0., 1.,0., 0.,1. ]
2551         gsCoo1=[ 2*_b-1, 1-4*_b, 2*_b-1, 2.07*_b-1, 1-4*_b, 2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 ];
2552         wg1=[ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 ]
2553         _refCoo1=refCoo1[0:6];
2554         _gsCoo1=gsCoo1[0:12];
2555         _wg1=wg1[0:6];
2556         f.setGaussLocalizationOnType(NORM_TRI3,_refCoo1,_gsCoo1,_wg1);
2557         refCoo2=[ 0.,0., 1.,0., 1.,1., 0.,1. ]
2558         _refCoo2=refCoo2[0:8];
2559         _gsCoo1=_gsCoo1[0:4]
2560         _wg1=_wg1[0:2]
2561         f.setGaussLocalizationOnType(NORM_QUAD4,_refCoo2,_gsCoo1,_wg1);
2562         arr=DataArrayDouble.New();
2563         values2=[1.,1001.,2.,1002., 11.,1011.,12.,1012.,13.,1013.,14.,1014.,15.,1015.,16.,1016., 21.,1021.,22.,1022.,23.,1023.,24.,1024.,25.,1025.,26.,1026., 31.,1031.,32.,1032., 41.,1041.,42.,1042.]
2564         arr.setValues(values2,18,2);
2565         f.setArray(arr);
2566         f.checkCoherency();
2567         fCpy=f.clone(True);
2568         self.assertTrue(f.isEqual(fCpy,1e-12,1e-12));
2569         f.renumberCells(renumber1,False);
2570         self.assertTrue(not f.isEqual(fCpy,1e-12,1e-12));
2571         expected2=[21.,1021.,22.,1022.,23.,1023.,24.,1024.,25.,1025.,26.,1026., 11.,1011.,12.,1012.,13.,1013.,14.,1014.,15.,1015.,16.,1016., 41.,1041.,42.,1042., 1.,1001.,2.,1002., 31.,1031.,32.,1032.]
2572         ptr=f.getArray().getValues();
2573         for i in xrange(36):
2574             self.assertTrue(abs(expected2[i]-ptr[i])<1e-12);
2575             pass
2576         renumber2=[2,1,4,0,3]
2577         f.renumberCells(renumber2,False);
2578         self.assertTrue(f.isEqual(fCpy,1e-12,1e-12));
2579         #GaussNE
2580         f=MEDCouplingFieldDouble.New(ON_GAUSS_NE,NO_TIME);
2581         f.setMesh(m);
2582         arr=DataArrayDouble.New();
2583         values3=[1.,1001.,2.,1002.,3.,1003.,4.,1004., 11.,1011.,12.,1012.,13.,1013., 21.,1021.,22.,1022.,23.,1023., 31.,1031.,32.,1032.,33.,1033.,34.,1034., 41.,1041.,42.,1042.,43.,1043.,44.,1044.]
2584         arr.setValues(values3,18,2);
2585         f.setArray(arr);
2586         f.checkCoherency();
2587         fCpy=f.clone(True);
2588         self.assertTrue(f.isEqual(fCpy,1e-12,1e-12));
2589         f.renumberCells(renumber1,False);
2590         self.assertTrue(not f.isEqual(fCpy,1e-12,1e-12));
2591         expected3=[21.,1021.,22.,1022.,23.,1023.,11.,1011.,12.,1012.,13.,1013.,41.,1041.,42.,1042.,43.,1043.,44.,1044.,1.,1001.,2.,1002.,3.,1003.,4.,1004.,31.,1031.,32.,1032.,33.,1033.,34.,1034.]
2592         ptr=f.getArray().getValues();
2593         for i in xrange(36):
2594             self.assertTrue(abs(expected3[i]-ptr[i])<1e-12);
2595             pass
2596         f.renumberCells(renumber2,False);#perform reverse operation of renumbering to check that the resulting field is equal.
2597         self.assertTrue(f.isEqual(fCpy,1e-12,1e-12));
2598         #
2599         pass
2600
2601     def testRenumberNodesForFields(self):
2602         m=MEDCouplingDataForTest.build2DTargetMesh_1();
2603         f=MEDCouplingFieldDouble.New(ON_NODES,NO_TIME);
2604         f.setMesh(m);
2605         self.assertEqual(9,f.getNumberOfMeshPlacesExpected());
2606         arr=DataArrayDouble.New();
2607         nbOfNodes=m.getNumberOfNodes();
2608         values1=[7.,107.,10007.,8.,108.,10008.,9.,109.,10009.,10.,110.,10010.,11.,111.,10011.,12.,112.,10012.,13.,113.,10013.,14.,114.,10014.,15.,115.,10015.]
2609         arr.setValues(values1,nbOfNodes,3);
2610         f.setArray(arr);
2611         f.checkCoherency();
2612         renumber1=[0,4,1,3,5,2,6,7,8]
2613         loc=[0.5432,-0.2432, 0.5478,0.1528]
2614         expected1=[9.0272, 109.0272, 10009.0272, 11.4124,111.4124,10011.4124]
2615         for j in xrange(2):
2616             res=f.getValueOn(loc[2*j:2*j+2]);
2617             for i in xrange(3):
2618                 self.assertTrue(abs(expected1[i+3*j]-res[i])<1e-12);
2619                 pass
2620             pass
2621         fCpy=f.clone(True);
2622         self.assertTrue(f.isEqual(fCpy,1e-12,1e-12));
2623         f.renumberNodes(renumber1);
2624         self.assertTrue(not f.isEqual(fCpy,1e-12,1e-12));
2625         for j in xrange(2):
2626             res=f.getValueOn(loc[2*j:2*j+2]);
2627             for i in xrange(3):
2628                 self.assertTrue(abs(expected1[i+3*j]-res[i])<1e-12);
2629                 pass
2630             pass
2631         expected2=[7.,107.,10007.,9.,109.,10009.,12.,112.,10012.,10.,110.,10010.,8.,108.,10008.,11.,111.,10011.,13.,113.,10013.,14.,114.,10014.,15.,115.,10015.]
2632         for i in xrange(27):
2633             self.assertTrue(abs(expected2[i]-f.getArray().getValues()[i])<1e-12);
2634             pass
2635         renumber2=[0,2,5,3,1,4,6,7,8]
2636         f.renumberNodes(renumber2);
2637         self.assertTrue(f.isEqual(fCpy,1e-12,1e-12));
2638         pass
2639
2640     def testConvertQuadraticCellsToLinear(self):
2641         mesh=MEDCouplingDataForTest.build2DTargetMesh_3();
2642         mesh.checkCoherency();
2643         types=mesh.getAllGeoTypes();
2644         types.sort()
2645         self.assertEqual(5,len(types));
2646         expected1=[NORM_POLYGON, NORM_TRI3, NORM_QUAD4, NORM_TRI6, NORM_QUAD8]
2647         expected1.sort()
2648         self.assertEqual(expected1,types);
2649         self.assertTrue(mesh.isPresenceOfQuadratic());
2650         self.assertEqual(62,mesh.getMeshLength());
2651         f1=mesh.getMeasureField(False);
2652         #
2653         mesh.convertQuadraticCellsToLinear();
2654         self.assertTrue(not mesh.isPresenceOfQuadratic());
2655         #
2656         mesh.checkCoherency();
2657         f2=mesh.getMeasureField(False);
2658         self.assertTrue(f1.getArray().isEqual(f2.getArray(),1e-12));
2659         self.assertEqual(48,mesh.getMeshLength());
2660         types2=mesh.getAllGeoTypes();
2661         types2.sort()
2662         self.assertEqual(3,len(types2));
2663         expected2=[NORM_POLYGON, NORM_TRI3, NORM_QUAD4]
2664         expected2.sort()
2665         self.assertEqual(expected2,types2);
2666         pass
2667
2668     def testCheckGeoEquivalWith(self):
2669         mesh1=MEDCouplingDataForTest.build2DTargetMesh_3();
2670         mesh2=MEDCouplingDataForTest.build2DTargetMesh_3();
2671         #First test mesh1
2672         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh1,0,1e-12);#deepEqual
2673         self.assertTrue(cellCor==None);
2674         self.assertTrue(nodeCor==None);
2675         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh1,1,1e-12);#fastEqual
2676         self.assertTrue(cellCor==None);
2677         self.assertTrue(nodeCor==None);
2678         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh1,10,1e-12);#deepEqual with geo permutations
2679         self.assertTrue(cellCor==None);
2680         self.assertTrue(nodeCor==None);
2681         #Second test mesh1 and mesh2 are 2 different meshes instance
2682         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,0,1e-12);#deepEqual
2683         self.assertTrue(cellCor==None);
2684         self.assertTrue(nodeCor==None);
2685         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,1,1e-12);#fastEqual
2686         self.assertTrue(cellCor==None);
2687         self.assertTrue(nodeCor==None);
2688         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,10,1e-12);#deepEqual with geo permutations
2689         self.assertTrue(cellCor==None);
2690         self.assertTrue(nodeCor==None);
2691         #Third test : cell permutation by keeping the first the middle and the last as it is.
2692         renum=[0,2,1,3,4,5,6,8,7,9]
2693         mesh2.renumberCells(renum,False);
2694         self.assertRaises(InterpKernelException,mesh1.checkGeoEquivalWith,mesh2,0,1e-12);#deepEqual fails
2695         self.assertTrue(cellCor==None);
2696         self.assertTrue(nodeCor==None);
2697         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,1,1e-12);#fastEqual do not see anything
2698         self.assertTrue(cellCor==None);
2699         self.assertTrue(nodeCor==None);
2700         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,10,1e-12);#deepEqual with geo permutations
2701         self.assertTrue(cellCor);
2702         self.assertEqual(10,cellCor.getNumberOfTuples());
2703         self.assertEqual(1,cellCor.getNumberOfComponents());
2704         self.assertEqual(renum,list(cellCor.getValues()))
2705         self.assertTrue(nodeCor==None);
2706         cellCor=0;
2707         self.assertTrue(nodeCor==None);
2708         a,b=mesh1.checkDeepEquivalWith(mesh2,0,1e-12);
2709         self.assertEqual(renum,list(a.getValues()))
2710         self.assertTrue(b==None);
2711         mesh2.setCoords(mesh1.getCoords())
2712         a=mesh1.checkDeepEquivalOnSameNodesWith(mesh2,0,1e-12);
2713         self.assertEqual(renum,list(a.getValues()))
2714         #4th test : cell and node permutation by keeping the first the middle and the last as it is.
2715         mesh2=MEDCouplingDataForTest.build2DTargetMesh_3();
2716         renum2=[0,2,1,3,4,5,6,8,7,9,10]
2717         mesh2.renumberCells(renum,False);
2718         mesh2.renumberNodes(renum2,11);
2719         cellCor=None
2720         nodeCor=None
2721         self.assertRaises(InterpKernelException,mesh1.checkGeoEquivalWith,mesh2,0,1e-12);#deepEqual fails
2722         self.assertTrue(cellCor==None);
2723         self.assertTrue(nodeCor==None);
2724         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,1,1e-12);#fastEqual do not see anything
2725         self.assertTrue(cellCor==None);
2726         self.assertTrue(nodeCor==None);
2727         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,10,1e-12);#deepEqual with geo permutations
2728         self.assertTrue(cellCor);
2729         self.assertEqual(10,cellCor.getNumberOfTuples());
2730         self.assertEqual(1,cellCor.getNumberOfComponents());
2731         self.assertEqual(renum,list(cellCor.getValues()))
2732         self.assertTrue(nodeCor);
2733         self.assertEqual(11,nodeCor.getNumberOfTuples());
2734         self.assertEqual(1,nodeCor.getNumberOfComponents());
2735         self.assertEqual(renum2,list(nodeCor.getValues()))
2736         cellCor=0;
2737         nodeCor=0;
2738         #5th test : modification of the last cell to check fastCheck detection.
2739         mesh2=MEDCouplingDataForTest.build2DTargetMesh_3();
2740         renum3=[0,2,1,3,4,5,6,8,9,7]
2741         mesh2.renumberCells(renum3,False);
2742         mesh2.renumberNodes(renum2,11);
2743         cellCor=None
2744         nodeCor=None
2745         self.assertRaises(InterpKernelException,mesh1.checkGeoEquivalWith,mesh2,0,1e-12)
2746         self.assertTrue(cellCor==None);
2747         self.assertTrue(nodeCor==None);
2748         self.assertRaises(InterpKernelException,mesh1.checkGeoEquivalWith,mesh2,1,1e-12)
2749         self.assertTrue(cellCor==None);
2750         self.assertTrue(nodeCor==None);
2751         cellCor,nodeCor=mesh2.checkGeoEquivalWith(mesh1,10,1e-12);#deepEqual with geo permutations
2752         self.assertTrue(cellCor!=None);
2753         self.assertEqual(10,cellCor.getNumberOfTuples());
2754         self.assertEqual(1,cellCor.getNumberOfComponents());
2755         self.assertEqual(renum3,list(cellCor.getValues()))
2756         self.assertTrue(nodeCor!=None);
2757         self.assertEqual(11,nodeCor.getNumberOfTuples());
2758         self.assertEqual(1,nodeCor.getNumberOfComponents());
2759         self.assertEqual(renum2,list(nodeCor.getValues()));
2760         pass
2761
2762     def testCheckGeoEquivalWith2(self):
2763         mesh1=MEDCouplingDataForTest.build2DTargetMesh_4();
2764         mesh2=MEDCouplingDataForTest.build2DTargetMesh_1();
2765         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,10,1e-12);
2766         self.assertEqual(None,cellCor);
2767         self.assertNotEqual(None,nodeCor);
2768         expected1=[0, 1, 3, 4, 5, 6, 7, 8, 9]
2769         for i in xrange(9):
2770             self.assertEqual(expected1[i],nodeCor.getIJ(i,0));
2771             pass
2772         pass
2773
2774     def testCopyTinyStringsFromOnFields(self):
2775         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
2776         nbOfCells=m.getNumberOfCells();
2777         f=MEDCouplingFieldDouble.New(ON_CELLS,LINEAR_TIME);
2778         f.setMesh(m);
2779         self.assertEqual(5,f.getNumberOfMeshPlacesExpected());
2780         f.setName("a");
2781         f.setDescription("b");
2782         a1=DataArrayDouble.New();
2783         a1.alloc(nbOfCells,2);
2784         a1.fillWithZero();
2785         a1.setInfoOnComponent(0,"c");
2786         a1.setInfoOnComponent(1,"d");
2787         a2=a1.deepCpy();
2788         a2.setInfoOnComponent(0,"e");
2789         a2.setInfoOnComponent(1,"f");
2790         f.setArray(a1);
2791         f.setEndArray(a2);
2792         f.setEndTime(3.,3,4);
2793         m.setName("g");
2794         m.getCoords().setInfoOnComponent(0,"h");
2795         m.getCoords().setInfoOnComponent(1,"i");
2796         m.getCoords().setInfoOnComponent(2,"j");
2797         #
2798         f.checkCoherency();
2799         f2=f.clone(True);
2800         self.assertTrue(f2.isEqual(f,1e-12,1e-12));
2801         f2.setName("smth");
2802         self.assertTrue(not f2.isEqual(f,1e-12,1e-12));
2803         f2.copyTinyStringsFrom(f);
2804         self.assertTrue(f2.isEqual(f,1e-12,1e-12));
2805         f2.setDescription("GGG");
2806         self.assertTrue(not f2.isEqual(f,1e-12,1e-12));
2807         f2.copyTinyStringsFrom(f);
2808         self.assertTrue(f2.isEqual(f,1e-12,1e-12));
2809         f2.getArray().setInfoOnComponent(0,"mmmm");
2810         self.assertTrue(not f2.isEqual(f,1e-12,1e-12));
2811         f2.copyTinyStringsFrom(f);
2812         self.assertTrue(f2.isEqual(f,1e-12,1e-12));
2813         f2.getEndArray().setInfoOnComponent(1,"mmmm");
2814         self.assertTrue(not f2.isEqual(f,1e-12,1e-12));
2815         f2.copyTinyStringsFrom(f);
2816         self.assertTrue(f2.isEqual(f,1e-12,1e-12));
2817         m2=m.clone(True);
2818         self.assertTrue(m2.isEqual(m,1e-12));
2819         m2.setName("123");
2820         self.assertTrue(not m2.isEqual(m,1e-12));
2821         m2.copyTinyStringsFrom(m);
2822         self.assertTrue(m2.isEqual(m,1e-12));
2823         m2.getCoords().setInfoOnComponent(1,"eee");
2824         self.assertTrue(not m2.isEqual(m,1e-12));
2825         m2.copyTinyStringsFrom(m);
2826         self.assertTrue(m2.isEqual(m,1e-12));
2827         pass
2828
2829     def testTryToShareSameCoordsPermute(self):
2830         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
2831         m2=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
2832         #self.assertTrue(m.getCoords()!=m2.getCoords());
2833         m.tryToShareSameCoordsPermute(m2,1e-12);
2834         #self.assertTrue(m.getCoords()==m2.getCoords());
2835         self.assertTrue(m2.isEqual(m,1e-12));
2836         renum1=[1,2,0,5,8,7,4,3,6]
2837         r1=DataArrayInt.New()
2838         r1.setValues(renum1,len(renum1),1)
2839         m.renumberNodes(r1,9);
2840         #self.assertTrue(m.getCoords()!=m2.getCoords());
2841         self.assertTrue(not m2.isEqual(m,1e-12));
2842         m.tryToShareSameCoordsPermute(m2,1e-12);
2843         #self.assertTrue(m.getCoords()==m2.getCoords());
2844         self.assertTrue(m2.isEqual(m,1e-12));
2845         pass
2846
2847     def testTryToShareSameCoordsPermute2(self):
2848         m1=MEDCouplingDataForTest.build2DTargetMesh_4();
2849         targetCoords=[-0.3,-0.3, 0.2,-0.3, -0.3,0.2, 0.2,0.2 ]
2850         targetConn=[0,2,3,1]
2851         m2=MEDCouplingUMesh.New();
2852         m2.setMeshDimension(2);
2853         m2.allocateCells(1);
2854         m2.insertNextCell(NORM_QUAD4,targetConn[0:4])
2855         m2.finishInsertingCells();
2856         myCoords=DataArrayDouble.New();
2857         myCoords.setValues(targetCoords,4,2);
2858         m2.setCoords(myCoords);
2859         m2.checkCoherency();
2860         m1.checkCoherency();
2861         #
2862         expected1=[0.25,0.125,0.125,0.25,0.25]
2863         f1=m1.getMeasureField(False);
2864         f2=m2.getMeasureField(False);
2865         self.assertEqual(5,f1.getArray().getNumberOfTuples());
2866         self.assertEqual(1,f2.getArray().getNumberOfTuples());
2867         for i in xrange(5):
2868             self.assertAlmostEqual(expected1[i],f1.getIJ(i,0),12);
2869             pass
2870         self.assertAlmostEqual(expected1[0],f2.getIJ(0,0),12);
2871         self.assertRaises(InterpKernelException,m1.tryToShareSameCoordsPermute,m2,1e-12);# <- here in this order the sharing is impossible.
2872         # Let's go for deeper test of tryToShareSameCoordsPermute
2873         m2.tryToShareSameCoordsPermute(m1,1e-12);
2874         f1=m1.getMeasureField(False);
2875         f2=m2.getMeasureField(False);
2876         self.assertEqual(5,f1.getArray().getNumberOfTuples());
2877         self.assertEqual(1,f2.getArray().getNumberOfTuples());
2878         for i in xrange(5):
2879             self.assertAlmostEqual(expected1[i],f1.getIJ(i,0),12);
2880             pass
2881         self.assertAlmostEqual(expected1[0],f2.getIJ(0,0),12);
2882         pass
2883
2884     def testChangeUnderlyingMesh1(self):
2885         mesh1=MEDCouplingDataForTest.build2DTargetMesh_3();
2886         mesh2=MEDCouplingDataForTest.build2DTargetMesh_3();
2887         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
2888         f1.setMesh(mesh1);
2889         array=DataArrayDouble.New();
2890         arr=[7., 107., 8., 108., 9., 109., 10., 110., 11., 111., 12., 112., 13., 113., 14., 114., 15., 115., 16., 116.]
2891         array.setValues(arr,mesh1.getNumberOfCells(),2);
2892         f1.setArray(array);
2893         #
2894         renum=[0,2,1,3,4,5,6,8,7,9]
2895         mesh2.renumberCells(renum,False);
2896         #self.assertTrue(f1.getMesh()==mesh1);
2897         f1.changeUnderlyingMesh(mesh1,10,1e-12);# nothing done only to check that nothing done.
2898         #self.assertTrue(f1.getMesh()==mesh1);
2899         f1.changeUnderlyingMesh(mesh2,10,1e-12);
2900         #self.assertTrue(f1.getMesh()==mesh2);
2901         expected1=[7.,107.,9.,109.,8.,108.,10.,110.,11.,111.,12.,112.,13.,113.,15.,115.,14.,114.,16.,116.]
2902         for i in xrange(20):
2903             self.assertAlmostEqual(expected1[i],f1.getArray().getIJ(0,i),12);
2904             pass
2905         #
2906         f1=MEDCouplingFieldDouble.New(ON_NODES,NO_TIME);
2907         f1.setMesh(mesh1);
2908         array=DataArrayDouble.New();
2909         arr2=[7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.,17.,117.]
2910         array.setValues(arr2,mesh1.getNumberOfNodes(),2);
2911         f1.setArray(array);
2912         #
2913         renum2=[0,2,10,3,4,5,6,8,7,9,1]
2914         mesh2.renumberNodes(renum2,11);
2915         #self.assertTrue(f1.getMesh()==mesh1);
2916         f1.changeUnderlyingMesh(mesh2,10,1e-12);
2917         #self.assertTrue(f1.getMesh()==mesh2);
2918         expected2=[7.,107.,17.,117.,8.,108.,10.,110.,11.,111.,12.,112.,13.,113.,15.,115.,14.,114.,16.,116.,9.,109.]
2919         for i in xrange(22):
2920             self.assertAlmostEqual(expected2[i],f1.getArray().getIJ(0,i),12);
2921             pass
2922         pass
2923
2924     def testGetMaxValue1(self):
2925         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
2926         nbOfCells=m.getNumberOfCells();
2927         f=MEDCouplingFieldDouble.New(ON_CELLS,LINEAR_TIME);
2928         f.setMesh(m);
2929         a1=DataArrayDouble.New();
2930         val1=[3.,4.,5.,6.,7.]
2931         a1.setValues(val1,nbOfCells,1);
2932         a2=DataArrayDouble.New();
2933         val2=[0.,1.,2.,8.,7.]
2934         a2.setValues(val2,nbOfCells,1);
2935         f.setArray(a1);
2936         f.setEndArray(a2);
2937         f.setEndTime(3.,3,4);
2938         f.checkCoherency();
2939         #
2940         self.assertAlmostEqual(8.,f.getMaxValue(),14);
2941         self.assertAlmostEqual(0.,f.getMinValue(),14);
2942         self.assertAlmostEqual(5.,f.getAverageValue(),14);
2943         self.assertAlmostEqual(5.125,f.getWeightedAverageValue(0,True),14);
2944         a1.setIJ(0,2,9.5);
2945         self.assertAlmostEqual(9.5,f.getMaxValue(),14);
2946         self.assertAlmostEqual(0.,f.getMinValue(),14);
2947         a2.setIJ(0,0,9.);
2948         self.assertAlmostEqual(9.5,f.getMaxValue(),14);
2949         self.assertAlmostEqual(1.,f.getMinValue(),14);
2950         pass
2951
2952     def testSubstractInPlaceDM1(self):
2953         mesh1=MEDCouplingDataForTest.build2DTargetMesh_3();
2954         mesh2=MEDCouplingDataForTest.build2DTargetMesh_3();
2955         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
2956         f1.setMesh(mesh1);
2957         array=DataArrayDouble.New();
2958         arr=[7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.]
2959         array.setValues(arr,mesh1.getNumberOfCells(),2);
2960         f1.setArray(array);
2961         #
2962         self.assertEqual(10,f1.getNumberOfTuples());
2963         self.assertEqual(2,f1.getNumberOfComponents());
2964         self.assertEqual(20,f1.getNumberOfValues());
2965         #
2966         renum=[0,2,3,1,4,5,6,8,7,9]
2967         mesh2.renumberCells(renum,False);
2968         #
2969         f2=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
2970         f2.setMesh(mesh2);
2971         array=DataArrayDouble.New();
2972         arr2=[7.1,107.1,10.1,110.1,8.1,108.1,9.1,109.1,11.1,111.1,12.1,112.1,13.1,113.1,15.1,115.1,14.1,114.1,16.1,116.1]
2973         array.setValues(arr2,mesh2.getNumberOfCells(),2);
2974         f2.setArray(array);
2975         #
2976         f1.substractInPlaceDM(f2,10,1e-12);
2977         f1.applyFunc(1,"abs(x+y+0.2)");
2978         self.assertAlmostEqual(0.,f1.getMaxValue(),13);
2979         pass
2980
2981     def testDotCrossProduct1(self):
2982         mesh1=MEDCouplingDataForTest.build2DTargetMesh_3();
2983         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
2984         f1.setTime(2.3,5,6);
2985         f1.setMesh(mesh1);
2986         array=DataArrayDouble.New();
2987         arr1=[7.,107.,207.,8.,108.,208.,9.,109.,209.,10.,110.,210.,11.,111.,211.,12.,112.,212.,13.,113.,213.,14.,114.,214.,15.,115.,215.,16.,116.,216.]
2988         array.setValues(arr1,mesh1.getNumberOfCells(),3);
2989         f1.setArray(array);
2990         f2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
2991         f2.setTime(7.8,4,5);
2992         f2.setMesh(mesh1);
2993         array=DataArrayDouble.New();
2994         arr2=[1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.,25.,26.,27.,28.,29.,30.]
2995         array.setValues(arr2,mesh1.getNumberOfCells(),3);
2996         f2.setArray(array);
2997         #
2998         f3=f1.dot(f2);
2999         expected1=[842.,1820.,2816.,3830.,4862.,5912.,6980.,8066.,9170.,10292.]
3000         for i in xrange(10):
3001             self.assertAlmostEqual(expected1[i],f3.getIJ(i,0),9);
3002             pass
3003         #
3004         f4=f1.crossProduct(f2);
3005         expected2=[-93., 186., -93., -392., 784., -392., -691., 1382., -691., -990., 1980., -990., -1289., 2578., -1289., -1588., 3176., -1588., -1887., 3774., -1887., -2186., 4372., -2186., -2485., 4970., -2485., -2784., 5568., -2784.]
3006         for i in xrange(30):
3007             self.assertAlmostEqual(expected2[i],f4.getIJ(0,i),9);
3008             pass
3009         pass
3010
3011     def testMinMaxFields1(self):
3012         mesh1=MEDCouplingDataForTest.build2DTargetMesh_3();
3013         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
3014         f1.setTime(2.3,5,6);
3015         f1.setMesh(mesh1);
3016         array=DataArrayDouble.New();
3017         arr1=[7.,107.,207.,8.,108.,208.,9.,109.,209.,10.,110.,210.,11.,111.,211.,12.,112.,212.,13.,113.,213.,14.,114.,214.,15.,115.,215.,16.,116.,216.]
3018         array.setValues(arr1,mesh1.getNumberOfCells(),3);
3019         f1.setArray(array);
3020         f2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
3021         f2.setTime(7.8,4,5);
3022         f2.setMesh(mesh1);
3023         array=DataArrayDouble.New();
3024         arr2=[6.,108.,206.,9.,107.,209.,8.,110.,208.,11.,109.,211.,10.,112.,210.,13.,111.,213.,12.,114.,212.,15.,113.,215.,14.,116.,214.,17.,115.,217.]
3025         array.setValues(arr2,mesh1.getNumberOfCells(),3);
3026         f2.setArray(array);
3027         #
3028         f3=f1.max(f2);
3029         expected1=[7.,108.,207.,9.,108.,209.,9.,110.,209.,11.,110.,211.,11.,112.,211.,13.,112.,213.,13.,114.,213.,15.,114.,215.,15.,116.,215.,17.,116.,217.]
3030         for i in xrange(30):
3031             self.assertAlmostEqual(expected1[i],f3.getIJ(0,i),9);
3032             pass
3033         #
3034         f4=f1.min(f2);
3035         expected2=[6.,107.,206.,8.,107.,208.,8.,109.,208.,10.,109.,210.,10.,111.,210.,12.,111.,212.,12.,113.,212.,14.,113.,214.,14.,115.,214.,16.,115.,216.]
3036         for i in xrange(30):
3037             self.assertAlmostEqual(expected2[i],f4.getIJ(0,i),9);
3038             pass
3039         #
3040         pass
3041
3042     def testApplyLin1(self):
3043         mesh1=MEDCouplingDataForTest.build2DTargetMesh_3();
3044         f1=MEDCouplingFieldDouble.New(ON_CELLS,LINEAR_TIME);
3045         f1.setMesh(mesh1);
3046         array=DataArrayDouble.New();
3047         arr=[7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.]
3048         array.setValues(arr,mesh1.getNumberOfCells(),2);
3049         f1.setArray(array);
3050         #
3051         f1.applyLin(2.,3.,0);
3052         expected1=[17.,107.,19.,108.,21.,109.,23.,110.,25.,111.,27.,112.,29.,113.,31.,114.,33.,115.,35.,116.]
3053         for i in xrange(20):
3054             self.assertAlmostEqual(expected1[i],f1.getIJ(0,i),9);
3055             pass
3056         #
3057         arr2=[2.,102.,3.,103.,4.,104.,5.,105.,6.,106.,7.,107.,8.,108.,9.,109.,10.,110.,11.,111.]
3058         array=DataArrayDouble.New();
3059         array.setValues(arr2,mesh1.getNumberOfCells(),2);
3060         f1.setEndArray(array);
3061         #
3062         f1.applyLin(4.,5.,1);
3063         #
3064         expected2=[17.,433.,19.,437.,21.,441.,23.,445.,25.,449.,27.,453.,29.,457.,31.,461.,33.,465.,35.,469.]
3065         for i in xrange(20):
3066             self.assertAlmostEqual(expected2[i],f1.getIJ(0,i),9);
3067             pass
3068         expected3=[2.,413.,3.,417.,4.,421.,5.,425.,6.,429.,7.,433.,8.,437.,9.,441.,10.,445.,11.,449.]
3069         for i in xrange(20):
3070             self.assertAlmostEqual(expected3[i],f1.getEndArray().getIJ(0,i),9);
3071             pass
3072         #
3073         pass
3074
3075     def testGetIdsInRange1(self):
3076         mesh1=MEDCouplingDataForTest.build2DTargetMesh_3();
3077         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
3078         f1.setTime(2.3,5,6);
3079         f1.setMesh(mesh1);
3080         array=DataArrayDouble.New();
3081         arr1=[2.,8.,6.,5.,11.,7.,9.,3.,10.,4.]
3082         array.setValues(arr1,mesh1.getNumberOfCells(),1);
3083         f1.setArray(array);
3084         #
3085         f1.checkCoherency();
3086         da=f1.getIdsInRange(2.9,7.1);
3087         self.failUnlessEqual(5,da.getNbOfElems());
3088         expected1=[2,3,5,7,9]
3089         self.failUnlessEqual(expected1,list(da.getValues()));
3090         da=f1.getIdsInRange(8.,12.);
3091         self.failUnlessEqual(4,da.getNbOfElems());
3092         expected2=[1,4,6,8]
3093         self.failUnlessEqual(expected2,list(da.getValues()));
3094         #
3095         pass
3096
3097     def testBuildSubPart1(self):
3098         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
3099         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
3100         f1.setTime(2.3,5,6);
3101         f1.setMesh(mesh1);
3102         array=DataArrayDouble.New();
3103         arr1=[3.,103.,4.,104.,5.,105.,6.,106.,7.,107.]
3104         array.setValues(arr1,mesh1.getNumberOfCells(),2);
3105         f1.setArray(array);
3106         #
3107         part1=[2,1,4]
3108         f2=f1[part1];
3109         f2.zipCoords()
3110         self.failUnlessEqual(3,f2.getNumberOfTuples());
3111         self.failUnlessEqual(2,f2.getNumberOfComponents());
3112         expected1=[5.,105.,4.,104.,7.,107.]
3113         for i in xrange(6):
3114             self.assertAlmostEqual(f2.getIJ(0,i),expected1[i],12);
3115             pass
3116         self.failUnlessEqual(3,f2.getMesh().getNumberOfCells());
3117         self.failUnlessEqual(6,f2.getMesh().getNumberOfNodes());
3118         self.failUnlessEqual(2,f2.getMesh().getSpaceDimension());
3119         self.failUnlessEqual(2,f2.getMesh().getMeshDimension());
3120         m2C=f2.getMesh();
3121         self.failUnlessEqual(13,m2C.getMeshLength());
3122         expected2=[0.2, -0.3, 0.7, -0.3, 0.2, 0.2, 0.7, 0.2, 0.2, 0.7, 0.7, 0.7]
3123         for i in xrange(12):
3124             self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12);
3125             pass
3126         expected3=[3,2,3,1,3,0,2,1,4,4,5,3,2]
3127         self.failUnlessEqual(expected3,list(m2C.getNodalConnectivity().getValues()));
3128         expected4=[0,4,8,13]
3129         self.failUnlessEqual(expected4,list(m2C.getNodalConnectivityIndex().getValues()));
3130         # Test with field on nodes.
3131         f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME);
3132         f1.setTime(2.3,5,6);
3133         f1.setMesh(mesh1);
3134         array=DataArrayDouble.New();
3135         arr2=[3.,103.,4.,104.,5.,105.,6.,106.,7.,107.,8.,108.,9.,109.,10.,110.,11.,111.]
3136         array.setValues(arr2,mesh1.getNumberOfNodes(),2);
3137         f1.setArray(array);
3138         part2=[1,2]
3139         f2=f1.buildSubPart(part2);
3140         self.failUnlessEqual(4,f2.getNumberOfTuples());
3141         self.failUnlessEqual(2,f2.getNumberOfComponents());
3142         expected5=[4.,104.,5.,105.,7.,107.,8.,108.]
3143         for i in xrange(8):
3144             self.assertAlmostEqual(f2.getIJ(0,i),expected5[i],12);
3145             pass
3146         self.failUnlessEqual(2,f2.getMesh().getNumberOfCells());
3147         self.failUnlessEqual(4,f2.getMesh().getNumberOfNodes());
3148         self.failUnlessEqual(2,f2.getMesh().getSpaceDimension());
3149         self.failUnlessEqual(2,f2.getMesh().getMeshDimension());
3150         m2C=f2.getMesh();
3151         self.failUnlessEqual(8,m2C.getMeshLength());
3152         for i in xrange(8):#8 is not an error
3153             self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12);
3154             pass
3155         self.failUnlessEqual(expected3[:4],list(m2C.getNodalConnectivity().getValues())[4:]);
3156         self.failUnlessEqual(expected3[4:8],list(m2C.getNodalConnectivity().getValues())[:4]);
3157         self.failUnlessEqual(expected4[:3],list(m2C.getNodalConnectivityIndex().getValues()));
3158         #idem previous because nodes of cell#4 are not fully present in part3
3159         part3=[1,2]
3160         arrr=DataArrayInt.New();
3161         arrr.setValues(part3,2,1);
3162         f2=f1.buildSubPart(arrr);
3163         self.failUnlessEqual(4,f2.getNumberOfTuples());
3164         self.failUnlessEqual(2,f2.getNumberOfComponents());
3165         for i in xrange(8):
3166             self.assertAlmostEqual(f2.getIJ(0,i),expected5[i],12);
3167             pass
3168         self.failUnlessEqual(2,f2.getMesh().getNumberOfCells());
3169         self.failUnlessEqual(4,f2.getMesh().getNumberOfNodes());
3170         self.failUnlessEqual(2,f2.getMesh().getSpaceDimension());
3171         self.failUnlessEqual(2,f2.getMesh().getMeshDimension());
3172         m2C=f2.getMesh();
3173         self.failUnlessEqual(8,m2C.getMeshLength());
3174         for i in xrange(8):#8 is not an error
3175             self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12);
3176             pass
3177         self.failUnlessEqual(expected3[:4],list(m2C.getNodalConnectivity().getValues())[4:8]);
3178         self.failUnlessEqual(expected3[4:8],list(m2C.getNodalConnectivity().getValues())[:4]);
3179         self.failUnlessEqual(expected4[:3],list(m2C.getNodalConnectivityIndex().getValues()));
3180         #
3181         part4=[1,2,4]
3182         f2=f1.buildSubPart(part4);
3183         self.failUnlessEqual(6,f2.getNumberOfTuples());
3184         self.failUnlessEqual(2,f2.getNumberOfComponents());
3185         expected6=[4.,104.,5.,105.,7.,107.,8.,108.,10.,110.,11.,111.]
3186         for i in xrange(12):
3187             self.assertAlmostEqual(f2.getIJ(0,i),expected6[i],12);
3188             pass
3189         self.failUnlessEqual(3,f2.getMesh().getNumberOfCells());
3190         self.failUnlessEqual(6,f2.getMesh().getNumberOfNodes());
3191         self.failUnlessEqual(2,f2.getMesh().getSpaceDimension());
3192         self.failUnlessEqual(2,f2.getMesh().getMeshDimension());
3193         m2C=f2.getMesh();
3194         self.failUnlessEqual(13,m2C.getMeshLength());
3195         for i in xrange(12):
3196             self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12);
3197             pass
3198         self.failUnlessEqual(expected3[0:4],list(m2C.getNodalConnectivity().getValues())[4:8]);
3199         self.failUnlessEqual(expected3[4:8],list(m2C.getNodalConnectivity().getValues())[0:4]);
3200         self.failUnlessEqual(expected3[8:13],list(m2C.getNodalConnectivity().getValues())[8:13]);
3201         self.failUnlessEqual(expected4,list(m2C.getNodalConnectivityIndex().getValues()));
3202         pass
3203
3204     def testDoublyContractedProduct1(self):
3205         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
3206         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
3207         f1.setMesh(mesh1);
3208         array=DataArrayDouble.New();
3209         arr1=[7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5]
3210         array.setValues(arr1,mesh1.getNumberOfCells(),6);
3211         f1.setArray(array);
3212         f1.checkCoherency();
3213         #
3214         f2=f1.doublyContractedProduct();
3215         f2.checkCoherency();
3216         self.assertEqual(1,f2.getNumberOfComponents());
3217         self.assertEqual(5,f2.getNumberOfTuples());
3218         for i in xrange(5):
3219             self.assertAlmostEqual(3906.56,f2.getIJ(i,0),9);
3220             pass
3221         #
3222         pass
3223
3224     def testDeterminant1(self):
3225         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
3226         f1=MEDCouplingFieldDouble.New(ON_CELLS,CONST_ON_TIME_INTERVAL);
3227         f1.setTime(2.3,5,6);
3228         f1.setEndTime(3.8,7,3);
3229         f1.setMesh(mesh1);
3230         array=DataArrayDouble.New();
3231         arr1=[1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5]
3232         array.setValues(arr1,mesh1.getNumberOfCells(),4);
3233         f1.setArray(array);
3234         #4 components
3235         f1.checkCoherency();
3236         f2=f1.determinant();
3237         f2.checkCoherency();
3238         self.assertEqual(CONST_ON_TIME_INTERVAL,f2.getTimeDiscretization());
3239         self.assertEqual(1,f2.getNumberOfComponents());
3240         self.assertEqual(5,f2.getNumberOfValues());
3241         for i in xrange(5):
3242             self.assertAlmostEqual(-2.42,f2.getIJ(i,0),13);
3243             pass
3244         #6 components multi arrays with end array not defined
3245         f1=MEDCouplingFieldDouble.New(ON_NODES,LINEAR_TIME);
3246         f1.setTime(2.3,5,6);
3247         f1.setEndTime(3.8,7,3);
3248         f1.setMesh(mesh1);
3249         array=DataArrayDouble.New();
3250         arr2=[1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7,
3251               1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7]
3252         array.setValues(arr2,mesh1.getNumberOfNodes(),6);
3253         f1.setArray(array);
3254         self.assertRaises(InterpKernelException,f1.checkCoherency);#no end array specified !
3255         #
3256         f2=f1.determinant();
3257         self.assertEqual(LINEAR_TIME,f2.getTimeDiscretization());
3258         self.assertEqual(1,f2.getArray().getNumberOfComponents());
3259         self.assertEqual(9,f2.getNumberOfTuples());
3260         for i in xrange(9):
3261             self.assertAlmostEqual(137.335,f2.getIJ(i,0),10);
3262             pass
3263         #6 components multi arrays with end array defined
3264         array=DataArrayDouble.New();
3265         arr3=[7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5,
3266               7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5]
3267         array.setValues(arr3,mesh1.getNumberOfNodes(),6);
3268         f1.setEndArray(array);
3269         f1.checkCoherency();
3270         f2=f1.determinant();
3271         f2.checkCoherency();
3272         self.assertEqual(LINEAR_TIME,f2.getTimeDiscretization());
3273         self.assertEqual(1,f2.getNumberOfComponents());
3274         self.assertEqual(9,f2.getNumberOfTuples());
3275         time2,it,order=f2.getTime()
3276         self.assertAlmostEqual(2.3,time2,12);
3277         self.assertEqual(5,it);
3278         self.assertEqual(6,order);
3279         time2,it,order=f2.getEndTime()
3280         self.assertAlmostEqual(3.8,time2,12);
3281         self.assertEqual(7,it);
3282         self.assertEqual(3,order);
3283         for i in xrange(9):
3284             self.assertAlmostEqual(137.335,f2.getIJ(i,0),10);
3285             self.assertAlmostEqual(1289.685,f2.getEndArray().getIJ(i,0),9);
3286             pass
3287         #9 components
3288         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
3289         f1.setTime(7.8,10,2);
3290         f1.setMesh(mesh1);
3291         array=DataArrayDouble.New();
3292         arr4=[1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1]
3293         array.setValues(arr4,mesh1.getNumberOfCells(),9);
3294         f1.setArray(array);
3295         #
3296         f1.checkCoherency();
3297         f2=f1.determinant();
3298         f2.checkCoherency();
3299         self.assertEqual(ONE_TIME,f2.getTimeDiscretization());
3300         self.assertEqual(1,f2.getNumberOfComponents());
3301         self.assertEqual(5,f2.getNumberOfTuples());
3302         time2,it,order=f2.getTime()
3303         self.assertAlmostEqual(7.8,time2,12);
3304         self.assertEqual(10,it);
3305         self.assertEqual(2,order);
3306         for i in xrange(5):
3307             self.assertAlmostEqual(3.267,f2.getIJ(i,0),13);
3308             pass
3309         pass
3310
3311     def testEigenValues1(self):
3312         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
3313         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
3314         f1.setMesh(mesh1);
3315         array=DataArrayDouble.New();
3316         arr1=[1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7]
3317         array.setValues(arr1,mesh1.getNumberOfCells(),6);
3318         f1.setArray(array);
3319         f1.checkCoherency();
3320         #
3321         f2=f1.eigenValues();
3322         f2.checkCoherency();
3323         self.assertEqual(3,f2.getNumberOfComponents());
3324         self.assertEqual(5,f2.getNumberOfTuples());
3325         expected1=[13.638813677891717,-4.502313844635971,-2.2364998332557486]
3326         for i in xrange(5):
3327             self.assertAlmostEqual(expected1[0],f2.getIJ(i,0),13);
3328             self.assertAlmostEqual(expected1[1],f2.getIJ(i,1),13);
3329             self.assertAlmostEqual(expected1[2],f2.getIJ(i,2),13);
3330             pass
3331         pass
3332
3333     def testEigenVectors1(self):
3334         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
3335         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
3336         f1.setMesh(mesh1);
3337         array=DataArrayDouble.New();
3338         arr1=[1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7]
3339         array.setValues(arr1,mesh1.getNumberOfCells(),6);
3340         f1.setArray(array);
3341         f1.checkCoherency();
3342         #
3343         f2=f1.eigenVectors();
3344         f2.checkCoherency();
3345         self.assertEqual(9,f2.getNumberOfComponents());
3346         self.assertEqual(5,f2.getNumberOfTuples());
3347         expected1=[0.5424262364180696, 0.5351201064614425, 0.6476266283176001,#eigenvect 0
3348                    0.7381111277307373, 0.06458838384003074, -0.6715804522117897,#eigenvect 1
3349                    -0.4012053603397987, 0.8423032781211455, -0.3599436712889738#eigenvect 2
3350                    ]
3351         for i in xrange(5):
3352             self.assertAlmostEqual(expected1[0],f2.getIJ(i,0),13);
3353             self.assertAlmostEqual(expected1[1],f2.getIJ(i,1),13);
3354             self.assertAlmostEqual(expected1[2],f2.getIJ(i,2),13);
3355             self.assertAlmostEqual(expected1[3],f2.getIJ(i,3),13);
3356             self.assertAlmostEqual(expected1[4],f2.getIJ(i,4),13);
3357             self.assertAlmostEqual(expected1[5],f2.getIJ(i,5),13);
3358             self.assertAlmostEqual(expected1[6],f2.getIJ(i,6),13);
3359             self.assertAlmostEqual(expected1[7],f2.getIJ(i,7),13);
3360             self.assertAlmostEqual(expected1[8],f2.getIJ(i,8),13);
3361             pass
3362         #
3363         pass
3364
3365     def testInverse1(self):
3366         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
3367         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
3368         f1.setMesh(mesh1);
3369         array=DataArrayDouble.New();
3370         arr1=[1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1]
3371         array.setValues(arr1,mesh1.getNumberOfCells(),9);
3372         f1.setArray(array);
3373         f1.checkCoherency();
3374         #
3375         f2=f1.inverse();
3376         f2.checkCoherency();
3377         self.assertEqual(9,f2.getNumberOfComponents());
3378         self.assertEqual(5,f2.getNumberOfTuples());
3379         expected1=[-2.6538108356290113, 2.855831037649208, -1.1111111111111067, 3.461891643709813, -4.775022956841121, 2.2222222222222143, -1.1111111111111054, 2.222222222222214, -1.1111111111111072]
3380         for i in xrange(5):
3381             self.assertAlmostEqual(expected1[0],f2.getIJ(i,0),13);
3382             self.assertAlmostEqual(expected1[1],f2.getIJ(i,1),13);
3383             self.assertAlmostEqual(expected1[2],f2.getIJ(i,2),13);
3384             self.assertAlmostEqual(expected1[3],f2.getIJ(i,3),13);
3385             self.assertAlmostEqual(expected1[4],f2.getIJ(i,4),13);
3386             self.assertAlmostEqual(expected1[5],f2.getIJ(i,5),13);
3387             self.assertAlmostEqual(expected1[6],f2.getIJ(i,6),13);
3388             self.assertAlmostEqual(expected1[7],f2.getIJ(i,7),13);
3389             self.assertAlmostEqual(expected1[8],f2.getIJ(i,8),13);
3390             pass
3391         #
3392         array=DataArrayDouble.New();
3393         arr3=[7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5]
3394         array.setValues(arr3,mesh1.getNumberOfCells(),6);
3395         f1.setArray(array);
3396         f1.checkCoherency();
3397         #
3398         f2=f1.inverse();
3399         f2.checkCoherency();
3400         self.assertEqual(6,f2.getNumberOfComponents());
3401         self.assertEqual(5,f2.getNumberOfTuples());
3402         expected3=[-0.3617705098531818, -0.8678630828458127, -0.026843764174972983, 0.5539957431465833, 0.13133439560823013, -0.05301294502145887]
3403         for i in xrange(5):
3404             self.assertAlmostEqual(expected3[0],f2.getIJ(i,0),13);
3405             self.assertAlmostEqual(expected3[1],f2.getIJ(i,1),13);
3406             self.assertAlmostEqual(expected3[2],f2.getIJ(i,2),13);
3407             self.assertAlmostEqual(expected3[3],f2.getIJ(i,3),13);
3408             self.assertAlmostEqual(expected3[4],f2.getIJ(i,4),13);
3409             self.assertAlmostEqual(expected3[5],f2.getIJ(i,5),13);
3410             pass
3411         #
3412         array=DataArrayDouble.New();
3413         arr2=[1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5]
3414         array.setValues(arr2,mesh1.getNumberOfCells(),4);
3415         f1.setArray(array);
3416         f1.checkCoherency();
3417         #
3418         f2=f1.inverse();
3419         f2.checkCoherency();
3420         self.assertEqual(4,f2.getNumberOfComponents());
3421         self.assertEqual(5,f2.getNumberOfTuples());
3422         expected2=[-1.8595041322314059, 0.9504132231404963, 1.404958677685951, -0.49586776859504156]
3423         for i in xrange(5):
3424             self.assertAlmostEqual(expected2[0],f2.getIJ(i,0),13);
3425             self.assertAlmostEqual(expected2[1],f2.getIJ(i,1),13);
3426             self.assertAlmostEqual(expected2[2],f2.getIJ(i,2),13);
3427             self.assertAlmostEqual(expected2[3],f2.getIJ(i,3),13);
3428             pass
3429         #
3430         pass
3431
3432     def testTrace1(self):
3433         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
3434         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
3435         f1.setMesh(mesh1);
3436         array=DataArrayDouble.New();
3437         arr1=[1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1]
3438         array.setValues(arr1,mesh1.getNumberOfCells(),9);
3439         f1.setArray(array);
3440         f1.checkCoherency();
3441         #
3442         f2=f1.trace();
3443         f2.checkCoherency();
3444         self.assertEqual(1,f2.getNumberOfComponents());
3445         self.assertEqual(5,f2.getNumberOfTuples());
3446         for i in xrange(5):
3447             self.assertAlmostEqual(15.9,f2.getIJ(i,0),13);
3448             pass
3449         #
3450         array=DataArrayDouble.New();
3451         arr3=[7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5]
3452         array.setValues(arr3,mesh1.getNumberOfCells(),6);
3453         f1.setArray(array);
3454         f1.checkCoherency();
3455         #
3456         f2=f1.trace();
3457         f2.checkCoherency();
3458         self.assertEqual(1,f2.getNumberOfComponents());
3459         self.assertEqual(5,f2.getNumberOfTuples());
3460         for i in xrange(5):
3461             self.assertAlmostEqual(25.8,f2.getIJ(i,0),13);
3462             pass
3463         #
3464         array=DataArrayDouble.New();
3465         arr2=[1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5]
3466         array.setValues(arr2,mesh1.getNumberOfCells(),4);
3467         f1.setArray(array);
3468         f1.checkCoherency();
3469         #
3470         f2=f1.trace();
3471         f2.checkCoherency();
3472         self.assertEqual(1,f2.getNumberOfComponents());
3473         self.assertEqual(5,f2.getNumberOfTuples());
3474         for i in xrange(5):
3475             self.assertAlmostEqual(5.7,f2.getIJ(i,0),13);
3476             pass
3477         #
3478         pass
3479
3480     def testDeviator1(self):
3481         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
3482         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
3483         f1.setMesh(mesh1);
3484         array=DataArrayDouble.New();
3485         arr1=[1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7]
3486         array.setValues(arr1,mesh1.getNumberOfCells(),6);
3487         f1.setArray(array);
3488         f1.checkCoherency();
3489         #
3490         f2=f1.deviator();
3491         f2.checkCoherency();
3492         self.assertEqual(6,f2.getNumberOfComponents());
3493         self.assertEqual(5,f2.getNumberOfTuples());
3494         expected1=[-1.1,0.,1.1,4.5,5.6,6.7]
3495         for i in xrange(5):
3496             self.assertAlmostEqual(expected1[0],f2.getIJ(i,0),13);
3497             self.assertAlmostEqual(expected1[1],f2.getIJ(i,1),13);
3498             self.assertAlmostEqual(expected1[2],f2.getIJ(i,2),13);
3499             self.assertAlmostEqual(expected1[3],f2.getIJ(i,3),13);
3500             self.assertAlmostEqual(expected1[4],f2.getIJ(i,4),13);
3501             self.assertAlmostEqual(expected1[5],f2.getIJ(i,5),13);
3502             pass
3503         #
3504         pass
3505
3506     def testMagnitude1(self):
3507         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
3508         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
3509         f1.setMesh(mesh1);
3510         array=DataArrayDouble.New();
3511         arr1=[1.2,2.3,3.4,4.5,5.6, 1.2,2.3,3.4,4.5,5.6, 1.2,2.3,3.4,4.5,5.6, 1.2,2.3,3.4,4.5,5.6, 1.2,2.3,3.4,4.5,5.6]
3512         array.setValues(arr1,mesh1.getNumberOfCells(),5);
3513         f1.setArray(array);
3514         f1.checkCoherency();
3515         #
3516         f2=f1.magnitude();
3517         f2.checkCoherency();
3518         self.assertEqual(1,f2.getNumberOfComponents());
3519         self.assertEqual(5,f2.getNumberOfTuples());
3520         for i in xrange(5):
3521             self.assertAlmostEqual(8.3606219864313918,f2.getIJ(i,0),13);
3522             pass
3523         #
3524         pass
3525
3526     def testMaxPerTuple1(self):
3527         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
3528         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
3529         f1.setMesh(mesh1);
3530         array=DataArrayDouble.New();
3531         arr1=[1.2,2.3,3.4,4.5,5.6, 1.2,3.4,4.5,5.6,2.3, 3.4,4.5,5.6,1.2,2.3, 5.6,1.2,2.3,3.4,4.5, 4.5,5.6,1.2,2.3,3.4]
3532         array.setValues(arr1,mesh1.getNumberOfCells(),5);
3533         f1.setArray(array);
3534         f1.checkCoherency();
3535         #
3536         f2=f1.maxPerTuple();
3537         f2.checkCoherency();
3538         self.assertEqual(1,f2.getNumberOfComponents());
3539         self.assertEqual(5,f2.getNumberOfTuples());
3540         for i in xrange(5):
3541             self.assertAlmostEqual(5.6,f2.getIJ(i,0),13);
3542             pass
3543         #
3544         d2,d2I=array.maxPerTupleWithCompoId()
3545         self.assertEqual(1,d2.getNumberOfComponents());
3546         self.assertEqual(5,d2.getNumberOfTuples());
3547         for i in xrange(5):
3548             self.assertAlmostEqual(5.6,d2.getIJ(i,0),13);
3549             pass
3550         self.assertTrue(d2I.isEqual(DataArrayInt([4,3,2,0,1])))
3551         pass
3552
3553     def testChangeNbOfComponents(self):
3554         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
3555         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
3556         f1.setMesh(mesh1);
3557         array=DataArrayDouble.New();
3558         arr1=[1.2,2.3,3.4,4.5,5.6, 1.2,3.4,4.5,5.6,2.3, 3.4,4.5,5.6,1.2,2.3, 5.6,1.2,2.3,3.4,4.5, 4.5,5.6,1.2,2.3,3.4]
3559         array.setValues(arr1,mesh1.getNumberOfCells(),5);
3560         f1.setArray(array);
3561         f1.checkCoherency();
3562         #
3563         f1.changeNbOfComponents(3,7.77);
3564         f1.checkCoherency();
3565         self.assertEqual(3,f1.getNumberOfComponents());
3566         self.assertEqual(5,f1.getNumberOfTuples());
3567         expected1=[1.2,2.3,3.4, 1.2,3.4,4.5, 3.4,4.5,5.6, 5.6,1.2,2.3, 4.5,5.6,1.2]
3568         for i in xrange(15):
3569             self.assertAlmostEqual(expected1[i],f1.getIJ(0,i),13);
3570             pass
3571         f1.changeNbOfComponents(4,7.77);
3572         f1.checkCoherency();
3573         self.assertEqual(4,f1.getNumberOfComponents());
3574         self.assertEqual(5,f1.getNumberOfTuples());
3575         expected2=[1.2,2.3,3.4,7.77, 1.2,3.4,4.5,7.77, 3.4,4.5,5.6,7.77, 5.6,1.2,2.3,7.77, 4.5,5.6,1.2,7.77]
3576         for i in xrange(20):
3577             self.assertAlmostEqual(expected2[i],f1.getIJ(0,i),13);
3578             pass
3579         #
3580         pass
3581
3582     def testSortPerTuple1(self):
3583         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
3584         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
3585         f1.setMesh(mesh1);
3586         array=DataArrayDouble.New();
3587         arr1=[1.2,2.3,3.4,4.5,5.6, 1.2,3.4,4.5,5.6,2.3, 3.4,4.5,5.6,1.2,2.3, 5.6,1.2,2.3,3.4,4.5, 4.5,5.6,1.2,2.3,3.4]
3588         array.setValues(arr1,mesh1.getNumberOfCells(),5);
3589         f1.setArray(array);
3590         f1.checkCoherency();
3591         #
3592         f1.sortPerTuple(True);
3593         f1.checkCoherency();
3594         self.assertEqual(5,f1.getNumberOfComponents());
3595         self.assertEqual(5,f1.getNumberOfTuples());
3596         for i in xrange(5):
3597             self.assertAlmostEqual(arr1[0],f1.getIJ(i,0),13);
3598             self.assertAlmostEqual(arr1[1],f1.getIJ(i,1),13);
3599             self.assertAlmostEqual(arr1[2],f1.getIJ(i,2),13);
3600             self.assertAlmostEqual(arr1[3],f1.getIJ(i,3),13);
3601             self.assertAlmostEqual(arr1[4],f1.getIJ(i,4),13);
3602             pass
3603         #
3604         f1.sortPerTuple(False);
3605         f1.checkCoherency();
3606         self.assertEqual(5,f1.getNumberOfComponents());
3607         self.assertEqual(5,f1.getNumberOfTuples());
3608         for i in xrange(5):
3609             self.assertAlmostEqual(arr1[4],f1.getIJ(i,0),13);
3610             self.assertAlmostEqual(arr1[3],f1.getIJ(i,1),13);
3611             self.assertAlmostEqual(arr1[2],f1.getIJ(i,2),13);
3612             self.assertAlmostEqual(arr1[1],f1.getIJ(i,3),13);
3613             self.assertAlmostEqual(arr1[0],f1.getIJ(i,4),13);
3614             pass
3615         #
3616         pass
3617
3618     def testIsEqualWithoutConsideringStr1(self):
3619         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
3620         mesh2=MEDCouplingDataForTest.build2DTargetMesh_1();
3621         #
3622         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
3623         self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
3624         mesh2.setName("rr");
3625         self.assertTrue(not mesh1.isEqual(mesh2,1e-12));
3626         self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
3627         da1,da2=mesh1.checkGeoEquivalWith(mesh2,2,1e-12);
3628         self.assertRaises(InterpKernelException,mesh1.checkGeoEquivalWith,mesh2,0,1e-12);
3629         mesh2.setName("");
3630         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
3631         self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
3632         mesh2.getCoords().setInfoOnComponent(0,"tty");
3633         self.assertTrue(not mesh1.isEqual(mesh2,1e-12));
3634         self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
3635         mesh2.getCoords().setInfoOnComponent(0,"");
3636         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
3637         self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
3638         mesh2.getCoords().setInfoOnComponent(1,"tty");
3639         self.assertTrue(not mesh1.isEqual(mesh2,1e-12));
3640         self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
3641         mesh2.getCoords().setInfoOnComponent(1,"");
3642         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
3643         self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
3644         tmp=mesh2.getCoords().getIJ(0,3);
3645         mesh2.getCoords().setIJ(0,3,9999.);
3646         self.assertTrue(not mesh1.isEqual(mesh2,1e-12));
3647         self.assertTrue(not mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
3648         mesh2.getCoords().setIJ(0,3,tmp);
3649         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
3650         self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
3651         tmp2=mesh2.getNodalConnectivity().getIJ(0,4);
3652         mesh2.getNodalConnectivity().setIJ(0,4,0);
3653         self.assertTrue(not mesh1.isEqual(mesh2,1e-12));
3654         self.assertTrue(not mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
3655         mesh2.getNodalConnectivity().setIJ(0,4,tmp2);
3656         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
3657         self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
3658         #
3659         f1=mesh1.getMeasureField(True);
3660         f2=mesh2.getMeasureField(True);
3661         self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
3662         self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,1e-12));
3663         f2.setName("ftest");
3664         self.assertTrue(not f1.isEqual(f2,1e-12,1e-12));
3665         self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,1e-12));
3666         f1.setName("ftest");
3667         self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
3668         self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,1e-12));
3669         #
3670         f2.getArray().setInfoOnComponent(0,"eee");
3671         self.assertTrue(not f1.isEqual(f2,1e-12,1e-12));
3672         self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,1e-12));
3673         f2.getArray().setInfoOnComponent(0,"");
3674         self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
3675         self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,1e-12));
3676         #
3677         f2.getArray().setIJ(1,0,0.123);
3678         self.assertTrue(not f1.isEqual(f2,1e-12,1e-12));
3679         self.assertTrue(not f1.isEqualWithoutConsideringStr(f2,1e-12,1e-12));
3680         f2.getArray().setIJ(1,0,0.125);
3681         self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
3682         self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,1e-12));
3683         #
3684         pass
3685     
3686     def testGetNodeIdsOfCell1(self):
3687         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
3688         li=mesh1.getNodeIdsOfCell(1)
3689         expected1=[1, 4, 2]
3690         self.assertEqual(expected1,list(li))
3691         li=mesh1.getCoordinatesOfNode(4)
3692         self.assertEqual(2,len(li))
3693         self.assertAlmostEqual(0.2,li[0],13);
3694         self.assertAlmostEqual(0.2,li[1],13);
3695         li=mesh1.getCoords().getValuesAsTuple()
3696         self.assertEqual(9,len(li))
3697         li2=mesh1.getNodalConnectivityIndex().getValuesAsTuple()
3698         self.assertEqual(6,len(li2))
3699         pass
3700
3701     def testGetEdgeRatioField1(self):
3702         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
3703         m1.setTime(3.4,5,6); m1.setTimeUnit("us");
3704         f1=m1.getEdgeRatioField();
3705         self.assertAlmostEqual(3.4,f1.getTime()[0],12) ; self.assertEqual(5,f1.getTime()[1]) ; self.assertEqual(6,f1.getTime()[2])
3706         self.assertEqual("us",f1.getTimeUnit())
3707         self.assertEqual(m1.getNumberOfCells(),f1.getNumberOfTuples());
3708         self.assertEqual(5,f1.getNumberOfTuples());
3709         self.assertEqual(1,f1.getNumberOfComponents());
3710         expected1=[1.,1.4142135623730951, 1.4142135623730951,1.,1.]
3711         for i in xrange(5):
3712             self.assertAlmostEqual(expected1[i],f1.getIJ(i,0),14);
3713             pass
3714         #
3715         m1=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
3716         f1=m1.getEdgeRatioField();
3717         self.assertEqual(m1.getNumberOfCells(),f1.getNumberOfTuples());
3718         self.assertEqual(5,f1.getNumberOfTuples());
3719         self.assertEqual(1,f1.getNumberOfComponents());
3720         expected2=[1.4142135623730951, 1.7320508075688772, 1.7320508075688772, 1.4142135623730951, 1.4142135623730951]
3721         for i in xrange(5):
3722             self.assertAlmostEqual(expected2[i],f1.getIJ(i,0),14);
3723             pass
3724         pass
3725
3726     def testFillFromAnalytic3(self):
3727         m=MEDCouplingDataForTest.build2DTargetMesh_1()
3728         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME)
3729         self.assertRaises(InterpKernelException,f1.fillFromAnalytic,1,"y+x");
3730         f1.setMesh(m)
3731         f1.setName("myField");
3732         f1.fillFromAnalytic(1,"y+x");
3733         f1.checkCoherency();
3734         self.assertEqual(f1.getName(),"myField");
3735         self.assertEqual(f1.getTypeOfField(),ON_CELLS);
3736         self.assertEqual(f1.getTimeDiscretization(),ONE_TIME);
3737         self.assertEqual(1,f1.getNumberOfComponents());
3738         self.assertEqual(5,f1.getNumberOfTuples());
3739         values1=[-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9]
3740         tmp=f1.getArray().getValues();
3741         self.assertEqual(len(values1),len(tmp))
3742         for i in xrange(len(values1)):
3743             self.assertTrue(abs(values1[i]-tmp[i])<1.e-12);
3744             pass
3745         #
3746         f1=MEDCouplingFieldDouble.New(ON_NODES,CONST_ON_TIME_INTERVAL)
3747         f1.setMesh(m)
3748         f1.fillFromAnalytic(1,"y+2*x");
3749         f1.setEndTime(1.2,3,4);
3750         f1.checkCoherency();
3751         self.assertEqual(f1.getTypeOfField(),ON_NODES);
3752         self.assertEqual(f1.getTimeDiscretization(),CONST_ON_TIME_INTERVAL);
3753         self.assertEqual(1,f1.getNumberOfComponents());
3754         self.assertEqual(9,f1.getNumberOfTuples());
3755         values2=[-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1]
3756         tmp=f1.getArray().getValues();
3757         self.assertEqual(len(values2),len(tmp))
3758         for i in xrange(len(values2)):
3759             self.assertTrue(abs(values2[i]-tmp[i])<1.e-12);
3760             pass
3761         f1=MEDCouplingFieldDouble.New(ON_NODES,LINEAR_TIME);
3762         f1.setMesh(m)
3763         f1.fillFromAnalytic(1,"2.*x+y");
3764         f1.setEndTime(1.2,3,4);
3765         f1.checkCoherency();
3766         self.assertEqual(f1.getTypeOfField(),ON_NODES);
3767         self.assertEqual(f1.getTimeDiscretization(),LINEAR_TIME);
3768         self.assertEqual(1,f1.getNumberOfComponents());
3769         self.assertEqual(9,f1.getNumberOfTuples());
3770         tmp=f1.getArray().getValues();
3771         values2Bis=[-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1]
3772         self.assertEqual(len(values2Bis),len(tmp))
3773         for i in xrange(len(values2Bis)):
3774             self.assertTrue(abs(values2Bis[i]-tmp[i])<1.e-12);
3775             pass
3776         tmp=f1.getEndArray().getValues();
3777         self.assertEqual(len(values2Bis),len(tmp))
3778         for i in xrange(len(values2Bis)):
3779             self.assertTrue(abs(values2Bis[i]-tmp[i])<1.e-12);
3780             pass
3781         #
3782         f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME);
3783         f1.setMesh(m)
3784         f1.fillFromAnalytic(2,"(x+y)*IVec+2*(x+y)*JVec");
3785         f1.checkCoherency();
3786         self.assertEqual(f1.getTypeOfField(),ON_NODES);
3787         self.assertEqual(f1.getTimeDiscretization(),ONE_TIME);
3788         self.assertEqual(2,f1.getNumberOfComponents());
3789         self.assertEqual(9,f1.getNumberOfTuples());
3790         values3=[-0.6,-1.2,-0.1,-0.2,0.4,0.8,-0.1,-0.2,0.4,0.8,0.9,1.8,0.4,0.8,0.9,1.8,1.4,2.8]
3791         tmp=f1.getArray().getValues();
3792         self.assertEqual(len(values3),len(tmp))
3793         for i in xrange(len(values3)):
3794             self.assertTrue(abs(values3[i]-tmp[i])<1.e-12);
3795             pass
3796         values4=f1.accumulate();
3797         self.assertTrue(abs(3.6-values4[0])<1.e-12);
3798         self.assertTrue(abs(7.2-values4[1])<1.e-12);
3799         values4=f1.integral(True);
3800         self.assertTrue(abs(0.5-values4[0])<1.e-12);
3801         self.assertTrue(abs(1.-values4[1])<1.e-12);
3802         #
3803         f1=MEDCouplingFieldDouble.New(ON_NODES,NO_TIME);
3804         f1.setMesh(m);
3805         self.assertRaises(InterpKernelException,f1.fillFromAnalytic,1,"1./(x-0.2)");
3806         pass
3807
3808     def testFieldDoubleOpEqual1(self):
3809         m=MEDCouplingDataForTest.build2DTargetMesh_1();
3810         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
3811         self.assertRaises(InterpKernelException,f1.assign,0.07);
3812         f1.setMesh(m);
3813         f1.assign(0.07);
3814         f1.checkCoherency();
3815         self.assertEqual(1,f1.getNumberOfComponents());
3816         self.assertEqual(5,f1.getNumberOfTuples());
3817         for i in xrange(5):
3818             self.assertAlmostEqual(0.07,f1.getIJ(i,0),16);
3819             pass
3820         f1.assign(0.09);
3821         f1.checkCoherency();
3822         self.assertEqual(1,f1.getNumberOfComponents());
3823         self.assertEqual(5,f1.getNumberOfTuples());
3824         for i in xrange(5):
3825             self.assertAlmostEqual(0.09,f1.getIJ(i,0),16);
3826             pass
3827         #
3828         f1=MEDCouplingFieldDouble.New(ON_NODES,LINEAR_TIME);
3829         f1.setEndTime(4.5,2,3);
3830         f1.setMesh(m);
3831         f1.assign(0.08);
3832         f1.checkCoherency();
3833         self.assertEqual(1,f1.getNumberOfComponents());
3834         self.assertEqual(9,f1.getNumberOfTuples());
3835         for i in xrange(9):
3836             self.assertAlmostEqual(0.08,f1.getIJ(i,0),16);
3837             pass
3838         self.assertEqual(1,f1.getEndArray().getNumberOfComponents());
3839         self.assertEqual(9,f1.getEndArray().getNumberOfTuples());
3840         for i in xrange(9):
3841             self.assertAlmostEqual(0.08,f1.getEndArray().getIJ(i,0),16);
3842             pass
3843         pass
3844
3845     def testAreaBary3D2(self):
3846         coordsForHexa8=[-75.45749305371, 180.95495078401, 39.515472018008,
3847                         -9.755591679144, 23.394927935279, 5.108794294848,
3848                         14.337630157832, 61.705351002702, 160.42422501908,
3849                         -27.273893776752, 167.567731083961, 192.830034145464,
3850                         99.857193154796,264.499264735586,-8.287335493412,
3851                         144.939882761126,156.38626563134,-31.896173894226,
3852                         161.34096835726,182.4654895809,73.832387065572,
3853                         132.680430393685,255.37973247196,96.15235602819];
3854         volHexa8=3258520.29637466;
3855         baryHexa8=[43.925705821778, 155.31893955289, 65.874418109644]
3856         
3857         coordsForPenta6=[-68.199829618726,178.938498373416,62.608505919588,
3858                          8.461744647847,76.653979804423,165.00018874933,
3859                          -27.273893776752,167.567731083961,192.830034145464,
3860                          106.586501038965,262.629609408327,13.124533008813,
3861                          155.465082847275,197.414118382622,78.408350795821,
3862                          132.680430393685,255.37973247196,96.15235602819];
3863         volPenta6=944849.868507338;
3864         baryPenta6=[39.631002313543,182.692711783428,106.98540473964]
3865         
3866         coordsForPyra5=[132.680430393685,255.37973247196,96.15235602819,
3867                         -27.273893776752,167.567731083961,192.830034145464,
3868                         8.461744647847,76.653979804423,165.00018874933,
3869                         155.465082847275,197.414118382622,78.408350795821,
3870                         -68.199829618726,178.938498373416,62.608505919588];
3871         volPyra5=756943.92980254;
3872         baryPyra5=[29.204294116618,172.540129749156,118.01035951483]
3873         mesh=MEDCouplingUMesh.New("Bary3D2",3);
3874         coo=DataArrayDouble.New();
3875         tmp=coordsForHexa8+coordsForPenta6+coordsForPyra5
3876         coo.setValues(tmp,19,3);
3877         mesh.setCoords(coo);
3878         #
3879         tmpConn=[0,1,2,3,4,5,6,7]
3880         mesh.allocateCells(3);
3881         self.assertRaises(InterpKernelException,mesh.insertNextCell,NORM_HEXA8,9,tmpConn[0:8])
3882         mesh.insertNextCell(NORM_HEXA8,tmpConn[0:8])
3883         mesh.insertNextCell(NORM_PENTA6,6,[i+8 for i in tmpConn])
3884         mesh.insertNextCell(NORM_PYRA5,5,[i+14 for i in tmpConn])
3885         mesh.finishInsertingCells();
3886         mesh.checkCoherency();
3887         mesh.mergeNodes(1e-7)
3888         self.assertEqual(12,mesh.getNumberOfNodes());
3889         vols=mesh.getMeasureField(True);
3890         self.assertEqual(3,vols.getNumberOfTuples());
3891         self.assertEqual(1,vols.getNumberOfComponents());
3892         self.assertAlmostEqual(volHexa8,vols.getIJ(0,0),6);
3893         self.assertAlmostEqual(volPenta6,vols.getIJ(1,0),7);
3894         self.assertAlmostEqual(volPyra5,vols.getIJ(2,0),7);
3895         bary=mesh.getBarycenterAndOwner();
3896         self.assertEqual(3,bary.getNumberOfTuples());
3897         self.assertEqual(3,bary.getNumberOfComponents());
3898         self.assertAlmostEqual(baryHexa8[0],bary.getIJ(0,0),11);
3899         self.assertAlmostEqual(baryHexa8[1],bary.getIJ(0,1),11);
3900         self.assertAlmostEqual(baryHexa8[2],bary.getIJ(0,2),11);
3901         self.assertAlmostEqual(baryPenta6[0],bary.getIJ(1,0),11);
3902         self.assertAlmostEqual(baryPenta6[1],bary.getIJ(1,1),11);
3903         self.assertAlmostEqual(baryPenta6[2],bary.getIJ(1,2),11);
3904         self.assertAlmostEqual(baryPyra5[0],bary.getIJ(2,0),11);
3905         self.assertAlmostEqual(baryPyra5[1],bary.getIJ(2,1),11);
3906         self.assertAlmostEqual(baryPyra5[2],bary.getIJ(2,2),11);
3907         pass
3908
3909     def testGetMeasureFieldCMesh1(self):
3910         m=MEDCouplingCMesh.New();
3911         da=DataArrayDouble.New();
3912         discX=[2.3,3.4,5.8,10.2]
3913         discY=[12.3,23.4,45.8]
3914         discZ=[-0.7,1.2,1.25,2.13,2.67]
3915         da.setValues(discX,4,1);
3916         m.setCoordsAt(0,da);
3917         m.checkCoherency();
3918         self.assertEqual(4,m.getNumberOfNodes());
3919         self.assertEqual(3,m.getNumberOfCells());
3920         self.assertEqual(1,m.getSpaceDimension());
3921         f=m.getMeasureField(True);
3922         self.assertEqual(3,f.getNumberOfTuples());
3923         self.assertEqual(1,f.getNumberOfComponents());
3924         expected1=[1.1,2.4,4.4]
3925         for i in xrange(3):
3926             self.assertAlmostEqual(expected1[i],f.getIJ(i,0),12);
3927             pass
3928         coords=m.getCoordinatesAndOwner();
3929         self.assertEqual(4,coords.getNumberOfTuples());
3930         self.assertEqual(1,coords.getNumberOfComponents());
3931         for i in xrange(4):
3932             self.assertAlmostEqual(discX[i],coords.getIJ(i,0),12);
3933             pass
3934         coords=m.getBarycenterAndOwner();
3935         self.assertEqual(3,coords.getNumberOfTuples());
3936         self.assertEqual(1,coords.getNumberOfComponents());
3937         expected1_3=[2.85,4.6,8.]
3938         for i in xrange(3):
3939             self.assertAlmostEqual(expected1_3[i],coords.getIJ(i,0),12);
3940             pass
3941         #
3942         da=DataArrayDouble.New();
3943         da.setValues(discY,3,1);
3944         m.setCoordsAt(1,da);
3945         m.checkCoherency();
3946         self.assertEqual(12,m.getNumberOfNodes());
3947         self.assertEqual(6,m.getNumberOfCells());
3948         self.assertEqual(2,m.getSpaceDimension());
3949         f=m.getMeasureField(True);
3950         self.assertEqual(6,f.getNumberOfTuples());
3951         self.assertEqual(1,f.getNumberOfComponents());
3952         expected2=[12.21,26.64,48.84,24.64,53.76,98.56]
3953         for i in xrange(6):
3954             self.assertAlmostEqual(expected2[i],f.getIJ(i,0),12);
3955             pass
3956         coords=m.getCoordinatesAndOwner();
3957         self.assertEqual(12,coords.getNumberOfTuples());
3958         self.assertEqual(2,coords.getNumberOfComponents());
3959         expected2_2=[2.3,12.3,3.4,12.3,5.8,12.3,10.2,12.3, 2.3,23.4,3.4,23.4,5.8,23.4,10.2,23.4, 2.3,45.8,3.4,45.8,5.8,45.8,10.2,45.8]
3960         for i in xrange(24):
3961             self.assertAlmostEqual(expected2_2[i],coords.getIJ(0,i),12);
3962             pass
3963         coords=m.getBarycenterAndOwner();
3964         self.assertEqual(6,coords.getNumberOfTuples());
3965         self.assertEqual(2,coords.getNumberOfComponents());
3966         expected2_3=[2.85,17.85,4.6,17.85,8.,17.85, 2.85,34.6,4.6,34.6,8.,34.6]
3967         for i in xrange(12):
3968             self.assertAlmostEqual(expected2_3[i],coords.getIJ(0,i),12);
3969             pass
3970         #
3971         da=DataArrayDouble.New();
3972         da.setValues(discZ,5,1);
3973         m.setCoordsAt(2,da);
3974         m.checkCoherency();
3975         self.assertEqual(60,m.getNumberOfNodes());
3976         self.assertEqual(24,m.getNumberOfCells());
3977         self.assertEqual(3,m.getSpaceDimension());
3978         f=m.getMeasureField(True);
3979         self.assertEqual(24,f.getNumberOfTuples());
3980         self.assertEqual(1,f.getNumberOfComponents());
3981         expected3=[23.199, 50.616, 92.796, 46.816, 102.144, 187.264, 0.6105, 1.332, 2.442, 1.232, 2.688, 4.928, 10.7448, 23.4432, 42.9792, 21.6832, 47.3088, 86.7328, 6.5934, 14.3856, 26.3736, 13.3056, 29.0304, 53.2224]
3982         for i in xrange(24):
3983             self.assertAlmostEqual(expected3[i],f.getIJ(i,0),12);
3984             pass
3985         coords=m.getCoordinatesAndOwner();
3986         self.assertEqual(60,coords.getNumberOfTuples());
3987         self.assertEqual(3,coords.getNumberOfComponents());
3988         expected3_2=[
3989             2.3,12.3,-0.7, 3.4,12.3,-0.7, 5.8,12.3,-0.7, 10.2,12.3,-0.7, 2.3,23.4,-0.7, 3.4,23.4,-0.7, 5.8,23.4,-0.7, 10.2,23.4,-0.7, 2.3,45.8,-0.7, 3.4,45.8,-0.7, 5.8,45.8,-0.7, 10.2,45.8,-0.7,
3990             2.3,12.3,1.2, 3.4,12.3,1.2, 5.8,12.3,1.2, 10.2,12.3,1.2, 2.3,23.4,1.2, 3.4,23.4,1.2, 5.8,23.4,1.2, 10.2,23.4,1.2, 2.3,45.8,1.2, 3.4,45.8,1.2, 5.8,45.8,1.2, 10.2,45.8,1.2,
3991             2.3,12.3,1.25, 3.4,12.3,1.25, 5.8,12.3,1.25, 10.2,12.3,1.25, 2.3,23.4,1.25, 3.4,23.4,1.25, 5.8,23.4,1.25, 10.2,23.4,1.25, 2.3,45.8,1.25, 3.4,45.8,1.25, 5.8,45.8,1.25, 10.2,45.8,1.25,
3992             2.3,12.3,2.13, 3.4,12.3,2.13, 5.8,12.3,2.13, 10.2,12.3,2.13, 2.3,23.4,2.13, 3.4,23.4,2.13, 5.8,23.4,2.13, 10.2,23.4,2.13, 2.3,45.8,2.13, 3.4,45.8,2.13, 5.8,45.8,2.13, 10.2,45.8,2.13,
3993             2.3,12.3,2.67, 3.4,12.3,2.67, 5.8,12.3,2.67, 10.2,12.3,2.67, 2.3,23.4,2.67, 3.4,23.4,2.67, 5.8,23.4,2.67, 10.2,23.4,2.67, 2.3,45.8,2.67, 3.4,45.8,2.67, 5.8,45.8,2.67, 10.2,45.8,2.67];
3994         for i in xrange(180):
3995             self.assertAlmostEqual(expected3_2[i],coords.getIJ(0,i),12);
3996             pass
3997         coords=m.getBarycenterAndOwner();
3998         self.assertEqual(24,coords.getNumberOfTuples());
3999         self.assertEqual(3,coords.getNumberOfComponents());
4000         expected3_3=[
4001             2.85,17.85,0.25,4.6,17.85,0.25,8.,17.85,0.25, 2.85,34.6,0.25,4.6,34.6,0.25,8.,34.6,0.25,
4002             2.85,17.85,1.225,4.6,17.85,1.225,8.,17.85,1.225, 2.85,34.6,1.225,4.6,34.6,1.225,8.,34.6,1.225,
4003             2.85,17.85,1.69,4.6,17.85,1.69,8.,17.85,1.69, 2.85,34.6,1.69,4.6,34.6,1.69,8.,34.6,1.69,
4004             2.85,17.85,2.4,4.6,17.85,2.4,8.,17.85,2.4, 2.85,34.6,2.4,4.6,34.6,2.4,8.,34.6,2.4];
4005         for i in xrange(72):
4006             self.assertAlmostEqual(expected3_3[i],coords.getIJ(0,i),12);
4007             pass
4008         pass
4009
4010     def testFieldDoubleZipCoords1(self):
4011         m=MEDCouplingDataForTest.build2DTargetMeshMergeNode_1();
4012         f=m.fillFromAnalytic(ON_NODES,2,"x*2.");
4013         f.getArray().setInfoOnComponent(0,"titi");
4014         f.getArray().setInfoOnComponent(1,"tutu");
4015         f.checkCoherency();
4016         self.assertEqual(18,f.getNumberOfTuples());
4017         self.assertEqual(2,f.getNumberOfComponents());
4018         expected1=[-0.6, -0.6, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 0.4, 0.4]
4019         for i in xrange(36):
4020             self.assertAlmostEqual(expected1[i],f.getIJ(0,i),12);
4021             pass
4022         self.assertTrue(f.zipCoords());
4023         f.checkCoherency();
4024         expected2=[-0.6, -0.6, 1.4, 1.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 0.4, 0.4]
4025         for i in xrange(30):
4026             self.assertAlmostEqual(expected2[i],f.getIJ(0,i),12);
4027             pass
4028         self.assertTrue(not f.zipCoords());
4029         f.checkCoherency();
4030         for i in xrange(30):
4031             self.assertAlmostEqual(expected2[i],f.getIJ(0,i),12);
4032             pass
4033         self.assertTrue(f.getArray().getInfoOnComponent(0)=="titi");
4034         self.assertTrue(f.getArray().getInfoOnComponent(1)=="tutu");
4035         pass
4036
4037     def testFieldDoubleZipConnectivity1(self):
4038         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
4039         m2=MEDCouplingDataForTest.build2DTargetMesh_1();
4040         cells1=[2,3,4]
4041         m3_1=m2.buildPartOfMySelf(cells1,True);
4042         m3=m3_1;
4043         m4=MEDCouplingDataForTest.build2DSourceMesh_1();
4044         m5=MEDCouplingUMesh.MergeUMeshes(m1,m3);
4045         m6=MEDCouplingUMesh.MergeUMeshes(m5,m4);
4046         #
4047         self.assertEqual(10,m6.getNumberOfCells());
4048         self.assertEqual(22,m6.getNumberOfNodes());
4049         arr,areNodesMerged,newNbOfNodes=m6.mergeNodes(1e-13);
4050         self.assertEqual(9,m6.getNumberOfNodes());
4051         f=m6.fillFromAnalytic(ON_CELLS,2,"x");
4052         f2=m6.fillFromAnalytic(ON_NODES,2,"x");
4053         self.assertEqual(10,f.getNumberOfTuples());
4054         self.assertEqual(2,f.getNumberOfComponents());
4055         expected1=[-0.05, -0.05, 0.3666666666666667, 0.3666666666666667, 0.53333333333333321, 0.53333333333333321,
4056                    -0.05, -0.05, 0.45, 0.45, 0.53333333333333321, 0.53333333333333321, -0.05, -0.05, 0.45, 0.45,
4057                    0.36666666666666659, 0.36666666666666659, 0.033333333333333326, 0.033333333333333326];
4058         for i in xrange(20):
4059             self.assertAlmostEqual(expected1[i],f.getIJ(0,i),12);
4060             pass
4061         f.getArray().setInfoOnComponent(0,"titi");
4062         f.getArray().setInfoOnComponent(1,"tutu");
4063         f.checkCoherency();
4064         self.assertTrue(f.zipConnectivity(0));
4065         expected2=[-0.05, -0.05, 0.3666666666666667, 0.3666666666666667, 0.53333333333333321, 0.53333333333333321,
4066                    -0.05, -0.05, 0.45, 0.45, 0.36666666666666659, 0.36666666666666659, 0.033333333333333326, 0.033333333333333326];
4067         self.assertEqual(7,f.getNumberOfTuples());
4068         self.assertEqual(2,f.getNumberOfComponents());
4069         for i in xrange(14):
4070             self.assertAlmostEqual(expected2[i],f.getIJ(0,i),12);
4071             pass
4072         self.assertTrue(f.getArray().getInfoOnComponent(0)=="titi");
4073         self.assertTrue(f.getArray().getInfoOnComponent(1)=="tutu");
4074         self.assertTrue(not f.zipConnectivity(0));
4075         #
4076         expected3=[-0.3, -0.3, 0.2, 0.2, 0.7, 0.7, -0.3, -0.3, 0.2, 0.2, 0.7, 0.7,
4077                    -0.3, -0.3, 0.2, 0.2, 0.7, 0.7];
4078         self.assertEqual(9,f2.getNumberOfTuples());
4079         self.assertEqual(2,f2.getNumberOfComponents());
4080         for i in xrange(18):
4081             self.assertAlmostEqual(expected3[i],f2.getIJ(0,i),12);
4082             pass
4083         self.assertTrue(f2.zipConnectivity(0));
4084         self.assertEqual(9,f2.getNumberOfTuples());
4085         self.assertEqual(2,f2.getNumberOfComponents());
4086         for i in xrange(18):
4087             self.assertAlmostEqual(expected3[i],f2.getIJ(0,i),12);
4088             pass
4089         pass
4090
4091     def testDaDoubleRenumber1(self):
4092         a=DataArrayDouble.New();
4093         arr1=[1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1]
4094         a.setValues(arr1,7,2);
4095         a.setInfoOnComponent(0,"toto");
4096         a.setInfoOnComponent(1,"tata");
4097         #
4098         arr2=[3,1,0,6,5,4,2]
4099         b=a.renumber(arr2);
4100         self.assertEqual(7,b.getNumberOfTuples());
4101         self.assertEqual(2,b.getNumberOfComponents());
4102         self.assertTrue(b.getInfoOnComponent(0)=="toto");
4103         self.assertTrue(b.getInfoOnComponent(1)=="tata");
4104         expected1=[3.1, 13.1, 2.1, 12.1, 7.1, 17.1, 1.1, 11.1, 6.1, 16.1, 5.1, 15.1, 4.1, 14.1]
4105         for i in xrange(14):
4106             self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
4107             pass
4108         #
4109         c=DataArrayInt.New();
4110         arr3=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
4111         c.setValues(arr3,7,2);
4112         c.setInfoOnComponent(0,"toto");
4113         c.setInfoOnComponent(1,"tata");
4114         d=c.renumber(arr2);
4115         self.assertEqual(7,d.getNumberOfTuples());
4116         self.assertEqual(2,d.getNumberOfComponents());
4117         self.assertTrue(d.getInfoOnComponent(0)=="toto");
4118         self.assertTrue(d.getInfoOnComponent(1)=="tata");
4119         expected2=[3, 13, 2, 12, 7, 17, 1, 11, 6, 16, 5, 15, 4, 14]
4120         for i in xrange(14):
4121             self.assertEqual(expected2[i],d.getIJ(0,i));
4122             pass
4123         pass
4124
4125     def testDaDoubleRenumberAndReduce1(self):
4126         a=DataArrayDouble.New();
4127         arr1=[1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1]
4128         a.setValues(arr1,7,2);
4129         a.setInfoOnComponent(0,"toto");
4130         a.setInfoOnComponent(1,"tata");
4131         #
4132         arr2=[2,-1,1,-1,0,4,3]
4133         b=a.renumberAndReduce(arr2,5);
4134         self.assertEqual(5,b.getNumberOfTuples());
4135         self.assertEqual(2,b.getNumberOfComponents());
4136         self.assertTrue(b.getInfoOnComponent(0)=="toto");
4137         self.assertTrue(b.getInfoOnComponent(1)=="tata");
4138         expected1=[5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1]
4139         for i in xrange(10):
4140             self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
4141             pass
4142         #
4143         c=DataArrayInt.New();
4144         arr3=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
4145         c.setValues(arr3,7,2);
4146         c.setInfoOnComponent(0,"toto");
4147         c.setInfoOnComponent(1,"tata");
4148         d=c.renumberAndReduce(arr2,5);
4149         self.assertEqual(5,d.getNumberOfTuples());
4150         self.assertEqual(2,d.getNumberOfComponents());
4151         self.assertTrue(d.getInfoOnComponent(0)=="toto");
4152         self.assertTrue(d.getInfoOnComponent(1)=="tata");
4153         expected2=[5,15,3,13,1,11,7,17,6,16]
4154         for i in xrange(10):
4155             self.assertEqual(expected2[i],d.getIJ(0,i));
4156             pass
4157         pass
4158
4159     def testDaDoubleRenumberInPlace1(self):
4160         a=DataArrayDouble.New();
4161         arr1=[1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1]
4162         a.setValues(arr1,7,2);
4163         #
4164         arr2=[3,1,0,6,5,4,2]
4165         a.renumberInPlace(arr2);
4166         self.assertEqual(7,a.getNumberOfTuples());
4167         self.assertEqual(2,a.getNumberOfComponents());
4168         expected1=[3.1, 13.1, 2.1, 12.1, 7.1, 17.1, 1.1, 11.1, 6.1, 16.1, 5.1, 15.1, 4.1, 14.1]
4169         for i in xrange(14):
4170             self.assertAlmostEqual(expected1[i],a.getIJ(0,i),14);
4171             pass
4172         #
4173         c=DataArrayInt.New();
4174         arr3=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
4175         c.setValues(arr3,7,2);
4176         c.renumberInPlace(arr2);
4177         self.assertEqual(7,c.getNumberOfTuples());
4178         self.assertEqual(2,c.getNumberOfComponents());
4179         expected2=[3, 13, 2, 12, 7, 17, 1, 11, 6, 16, 5, 15, 4, 14]
4180         for i in xrange(14):
4181             self.assertEqual(expected2[i],c.getIJ(0,i));
4182             pass
4183         pass
4184
4185     def testDaDoubleRenumberR1(self):
4186         a=DataArrayDouble.New();
4187         arr1=[1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1]
4188         a.setValues(arr1,7,2);
4189         a.setInfoOnComponent(0,"toto");
4190         a.setInfoOnComponent(1,"tata");
4191         #
4192         arr2=[3,1,0,6,5,4,2]
4193         b=a.renumberR(arr2);
4194         self.assertEqual(7,b.getNumberOfTuples());
4195         self.assertEqual(2,b.getNumberOfComponents());
4196         self.assertTrue(b.getInfoOnComponent(0)=="toto");
4197         self.assertTrue(b.getInfoOnComponent(1)=="tata");
4198         expected1=[4.1, 14.1, 2.1, 12.1, 1.1, 11.1, 7.1, 17.1, 6.1, 16.1, 5.1, 15.1, 3.1, 13.1]
4199         for i in xrange(14):
4200             self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
4201             pass
4202         #
4203         c=DataArrayInt.New();
4204         arr3=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
4205         c.setValues(arr3,7,2);
4206         c.setInfoOnComponent(0,"toto");
4207         c.setInfoOnComponent(1,"tata");
4208         d=c.renumberR(arr2);
4209         self.assertEqual(7,d.getNumberOfTuples());
4210         self.assertEqual(2,d.getNumberOfComponents());
4211         self.assertTrue(d.getInfoOnComponent(0)=="toto");
4212         self.assertTrue(d.getInfoOnComponent(1)=="tata");
4213         expected2=[4, 14, 2, 12, 1, 11, 7, 17, 6, 16, 5, 15, 3, 13]
4214         for i in xrange(14):
4215             self.assertEqual(expected2[i],d.getIJ(0,i));
4216             pass
4217         pass
4218
4219     def testDaDoubleRenumberInPlaceR1(self):
4220         a=DataArrayDouble.New();
4221         arr1=[1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1]
4222         a.setValues(arr1,7,2);
4223         #
4224         arr2=[3,1,0,6,5,4,2]
4225         a.renumberInPlaceR(arr2);
4226         self.assertEqual(7,a.getNumberOfTuples());
4227         self.assertEqual(2,a.getNumberOfComponents());
4228         expected1=[4.1, 14.1, 2.1, 12.1, 1.1, 11.1, 7.1, 17.1, 6.1, 16.1, 5.1, 15.1, 3.1, 13.1]
4229         for i in xrange(14):
4230             self.assertAlmostEqual(expected1[i],a.getIJ(0,i),14);
4231             pass
4232         #
4233         c=DataArrayInt.New();
4234         arr3=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
4235         c.setValues(arr3,7,2);
4236         c.renumberInPlaceR(arr2);
4237         self.assertEqual(7,c.getNumberOfTuples());
4238         self.assertEqual(2,c.getNumberOfComponents());
4239         expected2=[4, 14, 2, 12, 1, 11, 7, 17, 6, 16, 5, 15, 3, 13]
4240         for i in xrange(14):
4241             self.assertEqual(expected2[i],c.getIJ(0,i));
4242             pass
4243         pass
4244
4245     def testDaDoubleSelectByTupleId1(self):
4246         a=DataArrayDouble.New();
4247         arr1=[1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1]
4248         a.setValues(arr1,7,2);
4249         a.setInfoOnComponent(0,"toto");
4250         a.setInfoOnComponent(1,"tata");
4251         #
4252         arr2=[4,2,0,6,5]
4253         b=a.selectByTupleId(arr2);
4254         self.assertEqual(5,b.getNumberOfTuples());
4255         self.assertEqual(2,b.getNumberOfComponents());
4256         self.assertTrue(b.getInfoOnComponent(0)=="toto");
4257         self.assertTrue(b.getInfoOnComponent(1)=="tata");
4258         expected1=[5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1]
4259         for i in xrange(10):
4260             self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
4261             pass
4262         #
4263         c=DataArrayInt.New();
4264         arr3=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
4265         c.setValues(arr3,7,2);
4266         c.setInfoOnComponent(0,"toto");
4267         c.setInfoOnComponent(1,"tata");
4268         d=c.selectByTupleId(arr2);
4269         self.assertEqual(5,d.getNumberOfTuples());
4270         self.assertEqual(2,d.getNumberOfComponents());
4271         self.assertTrue(d.getInfoOnComponent(0)=="toto");
4272         self.assertTrue(d.getInfoOnComponent(1)=="tata");
4273         expected2=[5,15,3,13,1,11,7,17,6,16]
4274         for i in xrange(10):
4275             self.assertEqual(expected2[i],d.getIJ(0,i));
4276             pass
4277         pass
4278
4279     def testDaDoubleGetMinMaxValues1(self):
4280         a=DataArrayDouble.New();
4281         arr1=[2.34,4.56,-6.77,4.55,4.56,2.24,2.34,1.02,4.56]
4282         a.setValues(arr1,9,1);
4283         m,where=a.getMaxValue();
4284         self.assertEqual(1,where);
4285         self.assertAlmostEqual(4.56,m,12);
4286         m,ws=a.getMaxValue2();
4287         self.assertAlmostEqual(4.56,m,12);
4288         self.assertEqual(3,ws.getNumberOfTuples());
4289         self.assertEqual(1,ws.getNumberOfComponents());
4290         expected1=[1,4,8]
4291         for i in xrange(3):
4292             self.assertEqual(expected1[i],ws.getIJ(i,0));
4293             pass
4294         a=DataArrayDouble.New();
4295         arr2=[-2.34,-4.56,6.77,-4.55,-4.56,-2.24,-2.34,-1.02,-4.56]
4296         a.setValues(arr2,9,1);
4297         m,where=a.getMinValue();
4298         self.assertEqual(1,where);
4299         self.assertAlmostEqual(-4.56,m,12);
4300         m,ws=a.getMinValue2();
4301         self.assertAlmostEqual(-4.56,m,12);
4302         self.assertEqual(3,ws.getNumberOfTuples());
4303         self.assertEqual(1,ws.getNumberOfComponents());
4304         for i in xrange(3):
4305             self.assertEqual(expected1[i],ws.getIJ(i,0));
4306             pass
4307         pass
4308
4309     def testFieldDoubleGetMinMaxValues2(self):
4310         m2,m1=MEDCouplingDataForTest.build3DExtrudedUMesh_1();
4311         self.assertEqual(18,m2.getNumberOfCells());
4312         arr1=[8.71,4.53,-12.41,8.71,-8.71,8.7099,4.55,8.71,5.55,6.77,-1e-200,4.55,8.7099,0.,1.23,0.,2.22,8.71]
4313         f=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
4314         a=DataArrayDouble.New();
4315         a.setValues(arr1,18,1);
4316         f.setArray(a);
4317         f.setMesh(m2);
4318         #
4319         f.checkCoherency();
4320         m=f.getMaxValue();
4321         self.assertAlmostEqual(8.71,m,12);
4322         m,ws=f.getMaxValue2();
4323         self.assertAlmostEqual(8.71,m,12);
4324         self.assertEqual(4,ws.getNumberOfTuples());
4325         self.assertEqual(1,ws.getNumberOfComponents());
4326         expected1=[0,3,7,17]
4327         for i in xrange(4):
4328             self.assertEqual(expected1[i],ws.getIJ(i,0));
4329             pass
4330         #
4331         arr2=[-8.71,-4.53,12.41,-8.71,8.71,-8.7099,-4.55,-8.71,-5.55,-6.77,1e-200,-4.55,-8.7099,0.,-1.23,0.,-2.22,-8.71]
4332         a.setValues(arr2,18,1);
4333         f.checkCoherency();
4334         m=f.getMinValue();
4335         self.assertAlmostEqual(-8.71,m,12);
4336         m,ws=f.getMinValue2();
4337         self.assertAlmostEqual(-8.71,m,12);
4338         self.assertEqual(4,ws.getNumberOfTuples());
4339         self.assertEqual(1,ws.getNumberOfComponents());
4340         for i in xrange(4):
4341             self.assertEqual(expected1[i],ws.getIJ(i,0));
4342             pass
4343         pass
4344
4345     def testBuildUnstructuredCMesh1(self):
4346         m=MEDCouplingCMesh.New();
4347         da=DataArrayDouble.New();
4348         discX=[2.3,3.4,5.8,10.2]
4349         discY=[12.3,23.4,45.8]
4350         discZ=[-0.7,1.2,1.25,2.13,2.67]
4351         da.setValues(discX,4,1);
4352         m.setCoordsAt(0,da);
4353         m.checkCoherency();
4354         self.assertEqual(0,m.getCellContainingPoint([2.4],1e-12));
4355         self.assertEqual(1,m.getCellContainingPoint([3.7],1e-12));
4356         self.assertEqual(2,m.getCellContainingPoint([5.9],1e-12));
4357         self.assertEqual(-1,m.getCellContainingPoint([10.3],1e-12));
4358         self.assertEqual(-1,m.getCellContainingPoint([1.3],1e-12));
4359         #
4360         m2=m.buildUnstructured();
4361         m2.checkCoherency();
4362         f1=m.getMeasureField(False);
4363         f2=m2.getMeasureField(False);
4364         self.assertTrue(isinstance(f1.getMesh(),MEDCouplingCMesh))
4365         self.assertEqual(f1.getNumberOfTuples(),3);
4366         self.assertEqual(f2.getNumberOfTuples(),3);
4367         self.assertEqual(1,m2.getMeshDimension());
4368         self.assertEqual(1,m2.getSpaceDimension());
4369         for i in xrange(3):
4370             self.assertAlmostEqual(f1.getIJ(i,0),f2.getIJ(i,0),10);
4371             pass
4372         da=DataArrayDouble.New();
4373         da.setValues(discY,3,1);
4374         m.setCoordsAt(1,da);
4375         #
4376         m2=m.buildUnstructured();
4377         m2.checkCoherency();
4378         f1=m.getMeasureField(False);
4379         f2=m2.getMeasureField(False);
4380         self.assertEqual(f1.getNumberOfTuples(),6);
4381         self.assertEqual(f2.getNumberOfTuples(),6);
4382         self.assertEqual(2,m2.getMeshDimension());
4383         self.assertEqual(2,m2.getSpaceDimension());
4384         for i in xrange(6):
4385             self.assertAlmostEqual(f1.getIJ(i,0),f2.getIJ(i,0),10);
4386             pass
4387         #
4388         da=DataArrayDouble.New();
4389         da.setValues(discZ,5,1);
4390         m.setCoordsAt(2,da);
4391         m2=m.buildUnstructured();
4392         m2.checkCoherency();
4393         f1=m.getMeasureField(False);
4394         f2=m2.getMeasureField(False);
4395         self.assertEqual(f1.getNumberOfTuples(),24);
4396         self.assertEqual(f2.getNumberOfTuples(),24);
4397         self.assertEqual(3,m2.getMeshDimension());
4398         self.assertEqual(3,m2.getSpaceDimension());
4399         for i in xrange(24):
4400             self.assertAlmostEqual(f1.getIJ(i,0),f2.getIJ(i,0),10);
4401             pass
4402         #
4403         pos1=[5.,30.,2.]
4404         self.assertEqual(16,m.getCellContainingPoint(pos1,1e-12));
4405         #
4406         elems=m2.getCellsInBoundingBox([3.5,6.,12.2,25.,0.,1.5],1e-7)
4407         self.assertEqual([1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17],elems.getValues())
4408         #
4409         pt=[2.4,12.7,-3.4]
4410         m.scale(pt,3.7);
4411         m3=m.buildUnstructured();
4412         m2.scale(pt,3.7);
4413         self.assertTrue(m3.isEqual(m2,1e-12));
4414         pass
4415
4416     def testDataArrayIntInvertO2NNO21(self):
4417         arr1=[2,0,4,1,5,3]
4418         da=DataArrayInt.New();
4419         da.setValues(arr1,6,1);
4420         da2=da.invertArrayO2N2N2O(6);
4421         self.assertEqual(6,da2.getNumberOfTuples());
4422         self.assertEqual(1,da2.getNumberOfComponents());
4423         expected1=[1,3,0,5,2,4]
4424         for i in xrange(6):
4425             self.assertEqual(expected1[i],da2.getIJ(i,0));
4426             pass
4427         da3=da2.invertArrayN2O2O2N(6);
4428         for i in xrange(6):
4429             self.assertEqual(arr1[i],da3.getIJ(i,0));
4430             pass
4431         #
4432         arr2=[3,-1,5,4,-1,0,-1,1,2,-1]
4433         da=DataArrayInt.New();
4434         da.setValues(arr2,10,1);
4435         da2=da.invertArrayO2N2N2O(6);
4436         self.assertEqual(6,da2.getNumberOfTuples());
4437         self.assertEqual(1,da2.getNumberOfComponents());
4438         expected2=[5,7,8,0,3,2]
4439         for i in xrange(6):
4440             self.assertEqual(expected2[i],da2.getIJ(i,0));
4441             pass
4442         da3=da2.invertArrayN2O2O2N(10);
4443         for i in xrange(10):
4444             self.assertEqual(arr2[i],da3.getIJ(i,0));
4445             pass
4446         pass
4447     
4448     def testKeepSetSelectedComponent1(self):
4449         arr1=[1.,2.,3.,4., 11.,12.,13.,14., 21.,22.,23.,24., 31.,32.,33.,34., 41.,42.,43.,44.]
4450         a1=DataArrayDouble.New();
4451         a1.setValues(arr1,5,4);
4452         expp=[21.,22.,23.,24.]
4453         self.assertEqual(4,len(a1.getTuple(2)));
4454         for i in xrange(4):
4455             self.assertAlmostEqual(expp[i],a1.getTuple(2)[i],12)
4456             pass
4457         a1.setInfoOnComponent(0,"aaaa");
4458         a1.setInfoOnComponent(1,"bbbb");
4459         a1.setInfoOnComponent(2,"cccc");
4460         a1.setInfoOnComponent(3,"dddd");
4461         arr2V=[1,2,1,2,0,0]
4462         a2=a1.keepSelectedComponents(arr2V);
4463         self.assertEqual(6,a2.getNumberOfComponents());
4464         self.assertEqual(5,a2.getNumberOfTuples());
4465         self.assertTrue(a2.getInfoOnComponent(0)=="bbbb");
4466         self.assertTrue(a2.getInfoOnComponent(1)=="cccc");
4467         self.assertTrue(a2.getInfoOnComponent(2)=="bbbb");
4468         self.assertTrue(a2.getInfoOnComponent(3)=="cccc");
4469         self.assertTrue(a2.getInfoOnComponent(4)=="aaaa");
4470         self.assertTrue(a2.getInfoOnComponent(5)=="aaaa");
4471         expected1=[2.,3.,2.,3.,1.,1., 12.,13.,12.,13.,11.,11., 22.,23.,22.,23.,21.,21., 32.,33.,32.,33.,31.,31., 42.,43.,42.,43.,41.,41.]
4472         for i in xrange(30):
4473             self.assertAlmostEqual(expected1[i],a2.getIJ(0,i),14);
4474             pass
4475         a3=a1.convertToIntArr();
4476         self.assertEqual([21,22,23,24],a3.getTuple(2))
4477         a4=a3.keepSelectedComponents(arr2V);
4478         self.assertEqual(6,a4.getNumberOfComponents());
4479         self.assertEqual(5,a4.getNumberOfTuples());
4480         self.assertTrue(a4.getInfoOnComponent(0)=="bbbb");
4481         self.assertTrue(a4.getInfoOnComponent(1)=="cccc");
4482         self.assertTrue(a4.getInfoOnComponent(2)=="bbbb");
4483         self.assertTrue(a4.getInfoOnComponent(3)=="cccc");
4484         self.assertTrue(a4.getInfoOnComponent(4)=="aaaa");
4485         self.assertTrue(a4.getInfoOnComponent(5)=="aaaa");
4486         for i in xrange(30):
4487             self.assertEqual(int(expected1[i]),a4.getIJ(0,i));
4488             pass
4489         # setSelectedComponents
4490         arr3V=[3,2]
4491         a5=a1.keepSelectedComponents(arr3V);
4492         a5.setInfoOnComponent(0,"eeee");
4493         a5.setInfoOnComponent(1,"ffff");
4494         arr4V=[1,2]
4495         a2.setSelectedComponents(a5,arr4V);
4496         self.assertEqual(6,a2.getNumberOfComponents());
4497         self.assertEqual(5,a2.getNumberOfTuples());
4498         self.assertTrue(a2.getInfoOnComponent(0)=="bbbb");
4499         self.assertTrue(a2.getInfoOnComponent(1)=="eeee");
4500         self.assertTrue(a2.getInfoOnComponent(2)=="ffff");
4501         self.assertTrue(a2.getInfoOnComponent(3)=="cccc");
4502         self.assertTrue(a2.getInfoOnComponent(4)=="aaaa");
4503         self.assertTrue(a2.getInfoOnComponent(5)=="aaaa");
4504         expected2=[2.,4.,3.,3.,1.,1., 12.,14.,13.,13.,11.,11., 22.,24.,23.,23.,21.,21., 32.,34.,33.,33.,31.,31., 42.,44.,43.,43.,41.,41.]
4505         for i in xrange(30):
4506             self.assertAlmostEqual(expected2[i],a2.getIJ(0,i),14);
4507             pass
4508         a6=a5.convertToIntArr();
4509         a6.setInfoOnComponent(0,"eeee");
4510         a6.setInfoOnComponent(1,"ffff");
4511         a4.setSelectedComponents(a6,arr4V);
4512         self.assertEqual(6,a4.getNumberOfComponents());
4513         self.assertEqual(5,a4.getNumberOfTuples());
4514         self.assertTrue(a4.getInfoOnComponent(0)=="bbbb");
4515         self.assertTrue(a4.getInfoOnComponent(1)=="eeee");
4516         self.assertTrue(a4.getInfoOnComponent(2)=="ffff");
4517         self.assertTrue(a4.getInfoOnComponent(3)=="cccc");
4518         self.assertTrue(a4.getInfoOnComponent(4)=="aaaa");
4519         self.assertTrue(a4.getInfoOnComponent(5)=="aaaa");
4520         for i in xrange(30):
4521             self.assertEqual(int(expected2[i]),a4.getIJ(0,i));
4522             pass
4523         # test of throw
4524         arr5V=[2,3,6]
4525         arr6V=[2,7,5]
4526         arr7V=[2,1,4,6]
4527         self.assertRaises(InterpKernelException,a2.keepSelectedComponents,arr5V);
4528         self.assertRaises(InterpKernelException,a2.keepSelectedComponents,arr6V);
4529         self.assertRaises(InterpKernelException,a2.setSelectedComponents,a1,arr7V);
4530         arr7V=arr7V[0:3]
4531         self.assertRaises(InterpKernelException,a2.setSelectedComponents,a1,arr7V);
4532         #
4533         pass
4534
4535     def testKeepSetSelectedComponent2(self):
4536         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
4537         arr1=[1.,2.,3.,4., 11.,12.,13.,14., 21.,22.,23.,24., 31.,32.,33.,34., 41.,42.,43.,44.]
4538         a1=DataArrayDouble.New();
4539         a1.setValues(arr1,5,4);
4540         a1.setInfoOnComponent(0,"aaaa");
4541         a1.setInfoOnComponent(1,"bbbb");
4542         a1.setInfoOnComponent(2,"cccc");
4543         a1.setInfoOnComponent(3,"dddd");
4544         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
4545         f1.setTime(2.3,4,5);
4546         f1.setMesh(m1);
4547         f1.setName("f1");
4548         f1.setArray(a1);
4549         f1.checkCoherency();
4550         #
4551         arr2V=[1,2,1,2,0,0]
4552         f2=f1.keepSelectedComponents(arr2V);
4553         self.assertTrue(f2.getTimeDiscretization()==ONE_TIME);
4554         t,dt,it=f2.getTime()
4555         self.assertAlmostEqual(2.3,t,13);
4556         self.assertEqual(4,dt);
4557         self.assertEqual(5,it);
4558         f2.checkCoherency();
4559         self.assertEqual(6,f2.getNumberOfComponents());
4560         self.assertEqual(5,f2.getNumberOfTuples());
4561         self.assertTrue(f2.getArray().getInfoOnComponent(0)=="bbbb");
4562         self.assertTrue(f2.getArray().getInfoOnComponent(1)=="cccc");
4563         self.assertTrue(f2.getArray().getInfoOnComponent(2)=="bbbb");
4564         self.assertTrue(f2.getArray().getInfoOnComponent(3)=="cccc");
4565         self.assertTrue(f2.getArray().getInfoOnComponent(4)=="aaaa");
4566         self.assertTrue(f2.getArray().getInfoOnComponent(5)=="aaaa");
4567         expected1=[2.,3.,2.,3.,1.,1., 12.,13.,12.,13.,11.,11., 22.,23.,22.,23.,21.,21., 32.,33.,32.,33.,31.,31., 42.,43.,42.,43.,41.,41.]
4568         for i in xrange(30):
4569             self.assertAlmostEqual(expected1[i],f2.getIJ(0,i),14);
4570             pass
4571         #setSelectedComponents
4572         arr3V=[3,2]
4573         f5=f1.keepSelectedComponents(arr3V);
4574         f5.setTime(6.7,8,9);
4575         f5.getArray().setInfoOnComponent(0,"eeee");
4576         f5.getArray().setInfoOnComponent(1,"ffff");
4577         f5.checkCoherency();
4578         arr4V=[1,2]
4579         f2.setSelectedComponents(f5,arr4V);
4580         self.assertEqual(6,f2.getNumberOfComponents());
4581         self.assertEqual(5,f2.getNumberOfTuples());
4582         f2.checkCoherency();
4583         t,dt,it=f2.getTime()
4584         self.assertAlmostEqual(2.3,t,13);
4585         self.assertEqual(4,dt);
4586         self.assertEqual(5,it);
4587         self.assertTrue(f2.getArray().getInfoOnComponent(0)=="bbbb");
4588         self.assertTrue(f2.getArray().getInfoOnComponent(1)=="eeee");
4589         self.assertTrue(f2.getArray().getInfoOnComponent(2)=="ffff");
4590         self.assertTrue(f2.getArray().getInfoOnComponent(3)=="cccc");
4591         self.assertTrue(f2.getArray().getInfoOnComponent(4)=="aaaa");
4592         self.assertTrue(f2.getArray().getInfoOnComponent(5)=="aaaa");
4593         expected2=[2.,4.,3.,3.,1.,1., 12.,14.,13.,13.,11.,11., 22.,24.,23.,23.,21.,21., 32.,34.,33.,33.,31.,31., 42.,44.,43.,43.,41.,41.]
4594         for i in xrange(30):
4595             self.assertAlmostEqual(expected2[i],f2.getIJ(0,i),14);
4596             pass
4597         #
4598         pass
4599     
4600     def testElementaryDAThrowAndSpecialCases(self):
4601         da=DataArrayInt.New();
4602         self.assertRaises(InterpKernelException, da.checkAllocated);
4603         self.assertRaises(InterpKernelException, da.fillWithValue, 1);
4604         self.assertRaises(InterpKernelException, da.iota, 1);
4605         da.alloc(7,1);
4606         da.fillWithValue(11); #11,11,11,11...
4607         da.iota(10); #10,11,12,13...
4608         
4609         db=DataArrayInt.New();
4610         db.alloc(7,2);
4611         
4612         dbl2=DataArrayDouble.New();
4613         dbl2.alloc(7,2);
4614         self.assertRaises(InterpKernelException, dbl2.isUniform, 10., 1e-15);
4615         self.assertRaises(InterpKernelException, dbl2.sort);
4616         self.assertRaises(InterpKernelException, dbl2.iota, 10.);
4617         
4618         dbl=DataArrayDouble.New();
4619         #DataArrayDouble not allocated yet
4620         self.assertRaises(InterpKernelException, dbl.iota, 10.);
4621         self.assertRaises(InterpKernelException, dbl.isUniform, 10., 1e-15);
4622         self.assertRaises(InterpKernelException, dbl.sort);
4623         self.assertRaises(InterpKernelException, dbl.fromNoInterlace);
4624         self.assertRaises(InterpKernelException, dbl.toNoInterlace);
4625         
4626         dbl.alloc(7,1);
4627         dbl.iota(10.);
4628         self.assertTrue(not dbl.isUniform(10.,1e-15));
4629         dbl.sort();
4630         self.assertTrue(dbl.isMonotonic(True, .99));
4631         self.assertTrue(dbl.isMonotonic(True, -.99));
4632         self.assertTrue(not dbl.isMonotonic(True, 1.1));
4633         self.assertTrue(not dbl.isMonotonic(True, -1.1));
4634         dbl.reverse();
4635         self.assertTrue(dbl.isMonotonic(False, .99));
4636         self.assertTrue(not dbl.isMonotonic(False, 1.1));
4637         self.assertTrue(not dbl.isMonotonic(False, -1.1));
4638         
4639         dc=DataArrayInt.New();
4640         dc.alloc(14,1);
4641         
4642         dd=DataArrayDouble.New();
4643         self.assertRaises(InterpKernelException, dd.checkAllocated);
4644         self.assertRaises(InterpKernelException, dd.fillWithValue, 1.);
4645         self.assertRaises(InterpKernelException, dd.iota, 1.);
4646         self.assertTrue(not ((dd.repr().find("No data"))==-1));
4647         
4648         dd.alloc(0,1); #Allocated but nbOfElements==0!
4649         self.assertTrue(not ((dd.repr().find("Number of tuples : 0"))==-1));
4650         self.assertTrue(not ((dd.repr().find("Empty Data"))==-1));
4651         dd.fillWithValue(11); #?!...ok
4652         dd.iota(10); #?!...ok
4653         self.assertTrue(dd.isMonotonic(True, 1.));  #nothing is monotonic
4654         self.assertTrue(dd.isMonotonic(False, 1.));
4655         
4656         self.assertRaises(InterpKernelException, db.copyStringInfoFrom, da);
4657         self.assertRaises(InterpKernelException, db.copyStringInfoFrom, da);
4658         cIds=[2,2]
4659         self.assertRaises(InterpKernelException, da.copyPartOfStringInfoFrom, db, cIds);
4660         cIds[0]=1;
4661         cIds[0]=-1;
4662         self.assertRaises(InterpKernelException, da.copyPartOfStringInfoFrom, db, cIds);
4663         
4664         info=["infoOfOneComponent"]*2;
4665         self.assertRaises(InterpKernelException, da.setInfoOnComponents, info);
4666         self.assertRaises(InterpKernelException, da.setInfoOnComponent, 1, info[0]);
4667         db.setInfoOnComponents(info);
4668         
4669         self.assertRaises(InterpKernelException, da.getInfoOnComponent, -1);
4670         self.assertRaises(InterpKernelException, da.getInfoOnComponent, 2);
4671         self.assertTrue(db.getInfoOnComponent(1)==db.getInfoOnComponent(0));
4672         self.assertRaises(InterpKernelException, db.getVarOnComponent, -1);
4673         self.assertRaises(InterpKernelException, db.getVarOnComponent, 2);
4674         self.assertRaises(InterpKernelException, db.getUnitOnComponent, -1);
4675         self.assertRaises(InterpKernelException, db.getUnitOnComponent, 2);
4676         
4677         self.assertTrue(da.GetVarNameFromInfo("varname unit ")=="varname unit ");
4678         self.assertTrue(da.GetVarNameFromInfo("varname]unit[")=="varname]unit[");
4679         self.assertTrue(da.GetVarNameFromInfo("[unit]")=="");
4680         self.assertTrue(da.GetVarNameFromInfo("varname [unit]")=="varname");
4681         
4682         self.assertTrue(da.GetUnitFromInfo("varname unit ")=="");
4683         self.assertTrue(da.GetUnitFromInfo("varname]unit[")=="");
4684         self.assertTrue(da.GetUnitFromInfo("[unit]")=="unit");
4685         self.assertTrue(da.GetUnitFromInfo("varname [unit]")=="unit");
4686         
4687         self.assertRaises(InterpKernelException, da.checkNbOfTuplesAndComp, db, "theMessageInThrow");
4688         self.assertRaises(InterpKernelException, da.checkNbOfTuplesAndComp, dc, "theMessageInThrow");
4689         self.assertRaises(InterpKernelException, db.checkNbOfTuplesAndComp, dc, "theMessageInThrow");
4690         
4691         self.assertRaises(InterpKernelException, da.checkNbOfTuplesAndComp, 7, 2, "theMessageInThrow");
4692         da.checkNbOfTuplesAndComp(7,1,"theMessageInThrow");
4693         
4694         self.assertRaises(InterpKernelException, db.checkNbOfElems, 7*2+1, "theMessageInThrow");
4695         db.checkNbOfElems(7*2,"theMessageInThrow");
4696         
4697         self.assertRaises(InterpKernelException, db.GetNumberOfItemGivenBES, 10, 9, 1, "theMessageInThrow");
4698         self.assertRaises(InterpKernelException, db.GetNumberOfItemGivenBES, 0, 1, -1, "theMessageInThrow");
4699         self.assertEqual(10,db.GetNumberOfItemGivenBES(0,10,1,"theMessageInThrow"));
4700         self.assertEqual(5,db.GetNumberOfItemGivenBES(0,10,2,"theMessageInThrow"));
4701         self.assertEqual(6,db.GetNumberOfItemGivenBES(0,11,2,"theMessageInThrow"));
4702         
4703         self.assertTrue(not ((da.repr().find("Number of components : 1"))==-1));
4704         self.assertTrue(not ((dd.repr().find("Number of components : 1"))==-1));
4705         self.assertTrue(not ((dbl.repr().find("Number of components : 1"))==-1));
4706         
4707         self.assertTrue(not ((da.reprZip().find("Number of components : 1"))==-1));
4708         self.assertTrue(not ((dd.reprZip().find("Number of components : 1"))==-1));
4709         self.assertTrue(not ((dbl.reprZip().find("Number of components : 1"))==-1));
4710         
4711         self.assertRaises(InterpKernelException, dbl.selectByTupleId2, 0, 1, -1);
4712         self.assertRaises(InterpKernelException, dbl.substr, -1, 1);
4713         self.assertRaises(InterpKernelException, dbl.substr, 8, 1);
4714         self.assertRaises(InterpKernelException, dbl.substr, 0, 8);
4715         self.assertRaises(InterpKernelException, dbl.meldWith, dd);
4716         
4717         self.assertRaises(InterpKernelException, dbl.setPartOfValuesAdv, dbl2, da); #dbl dbl2 not have the same number of components
4718         self.assertRaises(InterpKernelException, dbl.setPartOfValuesAdv, dd, da);  #da tuple selector DataArrayInt instance not have exactly 2 components
4719         
4720         dbl3=DataArrayDouble.New();
4721         dbl3.alloc(6,2);
4722         dbl3.fillWithValue(11.);
4723         #bad number of components
4724         self.assertRaises(InterpKernelException, dbl3.getMaxValue);
4725         self.assertRaises(InterpKernelException, dd.getMaxValue);
4726         self.assertRaises(InterpKernelException, dbl3.getMinValue);
4727         self.assertRaises(InterpKernelException, dd.getMinValue);
4728         self.assertRaises(InterpKernelException, dbl3.getAverageValue);
4729         self.assertRaises(InterpKernelException, dd.getAverageValue);
4730         self.assertRaises(InterpKernelException, dd.accumulate, 100);
4731         self.assertRaises(InterpKernelException, dbl.fromPolarToCart);
4732         self.assertRaises(InterpKernelException, dbl3.fromCylToCart);
4733         self.assertRaises(InterpKernelException, dbl3.fromSpherToCart);
4734         self.assertRaises(InterpKernelException, dbl3.doublyContractedProduct);
4735         self.assertRaises(InterpKernelException, dbl3.determinant);
4736         self.assertRaises(InterpKernelException, dbl3.eigenValues);
4737         self.assertRaises(InterpKernelException, dbl3.eigenVectors);
4738         self.assertRaises(InterpKernelException, dbl3.inverse);
4739         self.assertRaises(InterpKernelException, dbl3.trace);
4740         self.assertRaises(InterpKernelException, dbl3.deviator);
4741         
4742         dbl3.setIJ(5,1,12.);
4743         self.assertTrue(dbl3.getMaxValueInArray()==12.);
4744         self.assertTrue(dbl3.getMinValueInArray()==11.);
4745         
4746         db.fillWithValue(100); #bad Ids
4747         self.assertRaises(InterpKernelException, dbl3.setPartOfValuesAdv, dbl2, db);
4748         db.fillWithValue(-1); #bad Ids
4749         self.assertRaises(InterpKernelException, dbl3.setPartOfValuesAdv, dbl2, db);
4750         db.fillWithValue(6); #bad Ids for dbl3
4751         self.assertRaises(InterpKernelException, dbl3.setPartOfValuesAdv, dbl2, db);
4752         
4753         dbl3.checkNoNullValues();
4754         dbl3.setIJ(5,0,0.);
4755         self.assertRaises(InterpKernelException, dbl3.checkNoNullValues);
4756         self.assertRaises(InterpKernelException, dbl3.applyInv, 1.);  #div by zero
4757         self.assertRaises(InterpKernelException, dbl2.getIdsInRange, 1., 2.);
4758         a=[]
4759         self.assertRaises(InterpKernelException, DataArrayDouble_Aggregate, a);
4760         self.assertRaises(InterpKernelException, DataArrayDouble_Meld, a);
4761         
4762         a=[dbl2,dbl]; #Nb of components mismatch
4763         self.assertRaises(InterpKernelException, DataArrayDouble_Aggregate, a);
4764         
4765         self.assertRaises(InterpKernelException, DataArrayDouble_Dot, dbl2, dbl);
4766         
4767         self.assertRaises(InterpKernelException, DataArrayDouble_CrossProduct, dbl2, dbl); #Nb of components mismatch
4768         self.assertRaises(InterpKernelException, DataArrayDouble_CrossProduct, dbl2, dbl2); #Nb of components must be equal to 3
4769         dbl4=DataArrayDouble.New();
4770         dbl4.alloc(6,3);
4771         dbl5=DataArrayDouble.New();
4772         dbl5.alloc(7,3);
4773         self.assertRaises(InterpKernelException, DataArrayDouble_CrossProduct, dbl4, dbl5); #Nb of tuples mismatch
4774         
4775         a[0]=dbl4; #Nb of tuple mismatch
4776         a[1]=dbl5; #Nb of tuple mismatch
4777         self.assertRaises(InterpKernelException, DataArrayDouble_Meld, a);
4778         self.assertRaises(InterpKernelException, DataArrayDouble_Dot, dbl4, dbl5);
4779         pass
4780
4781     def testDAIGetIdsEqual1(self):
4782         tab1=[5,-2,-4,-2,3,2,-2];
4783         da=DataArrayInt.New();
4784         da.setValues(tab1,7,1);
4785         da2=da.getIdsEqual(-2);
4786         self.assertEqual(3,da2.getNumberOfTuples());
4787         self.assertEqual(1,da2.getNumberOfComponents());
4788         expected1=[1,3,6];
4789         self.assertEqual(expected1,da2.getValues());
4790         pass
4791
4792     def testDAIGetIdsEqualList1(self):
4793         tab1=[5,-2,-4,-2,3,2,-2];
4794         da=DataArrayInt.New();
4795         da.setValues(tab1,7,1);
4796         da2=da.getIdsEqualList([3,-2,0]);
4797         self.assertEqual(4,da2.getNumberOfTuples());
4798         self.assertEqual(1,da2.getNumberOfComponents());
4799         expected1=[1,3,4,6];
4800         self.assertEqual(expected1,da2.getValues());
4801         pass
4802
4803     def testDAFromNoInterlace1(self):
4804         tab1=[1,11,21,31,41,2,12,22,32,42,3,13,23,33,43]
4805         da=DataArrayInt.New();
4806         da.setValues(tab1,5,3);
4807         da2=da.fromNoInterlace();
4808         expected1=[1,2,3,11,12,13,21,22,23,31,32,33,41,42,43]
4809         self.assertEqual(5,da2.getNumberOfTuples());
4810         self.assertEqual(3,da2.getNumberOfComponents());# it's not a bug. Avoid to have 1 million components !
4811         self.assertEqual(expected1,da2.getValues());
4812         da3=da.convertToDblArr();
4813         da4=da3.fromNoInterlace();
4814         self.assertEqual(5,da4.getNumberOfTuples());
4815         self.assertEqual(3,da4.getNumberOfComponents());# it's not a bug. Avoid to have 1 million components !
4816         for i in xrange(15):
4817             self.assertAlmostEqual(expected1[i],da4.getIJ(0,i),14);
4818             pass
4819         pass
4820     
4821     def testDAToNoInterlace1(self):
4822         tab1=[1,2,3,11,12,13,21,22,23,31,32,33,41,42,43]
4823         da=DataArrayInt.New();
4824         da.setValues(tab1,5,3);
4825         da2=da.toNoInterlace();
4826         expected1=[1,11,21,31,41,2,12,22,32,42,3,13,23,33,43]
4827         self.assertEqual(5,da2.getNumberOfTuples());
4828         self.assertEqual(3,da2.getNumberOfComponents());# it's not a bug. Avoid to have 1 million components !
4829         self.assertEqual(expected1,da2.getValues());
4830         da3=da.convertToDblArr();
4831         da4=da3.toNoInterlace();
4832         self.assertEqual(5,da4.getNumberOfTuples());
4833         self.assertEqual(3,da4.getNumberOfComponents());# it's not a bug. Avoid to have 1 million components !
4834         for i in xrange(15):
4835             self.assertAlmostEqual(expected1[i],da4.getIJ(0,i),14);
4836             pass
4837         pass
4838     
4839     def testDAIsUniform1(self):
4840         tab1=[1,1,1,1,1]
4841         da=DataArrayInt.New();
4842         da.setValues(tab1,5,1);
4843         self.assertTrue(da.isUniform(1));
4844         da.setIJ(2,0,2);
4845         self.assertTrue(not da.isUniform(1));
4846         da.setIJ(2,0,1);
4847         self.assertTrue(da.isUniform(1));
4848         da2=da.convertToDblArr();
4849         self.assertTrue(da2.isUniform(1.,1.e-12));
4850         da2.setIJ(1,0,1.+1.e-13);
4851         self.assertTrue(da2.isUniform(1.,1.e-12));
4852         da2.setIJ(1,0,1.+1.e-11);
4853         self.assertTrue(not da2.isUniform(1.,1.e-12));
4854         pass
4855     
4856     def testDADFromPolarToCart1(self):
4857         tab1=[2.,0.2,2.5,0.7]
4858         da=DataArrayDouble.New();
4859         da.setValues(tab1,2,2);
4860         da2=da.fromPolarToCart();
4861         expected1=[1.9601331556824833,0.39733866159012243, 1.9121054682112213,1.6105442180942275]
4862         for i in xrange(4):
4863             self.assertAlmostEqual(expected1[i],da2.getIJ(0,i),13);
4864             pass
4865         pass
4866     
4867     def testDADFromCylToCart1(self):
4868         tab1=[2.,0.2,4.,2.5,0.7,9.]
4869         da=DataArrayDouble.New();
4870         da.setValues(tab1,2,3);
4871         da2=da.fromCylToCart();
4872         expected1=[1.9601331556824833,0.39733866159012243,4., 1.9121054682112213,1.6105442180942275,9.]
4873         for i in xrange(6):
4874             self.assertAlmostEqual(expected1[i],da2.getIJ(0,i),13);
4875             pass
4876         pass
4877     
4878     def testDADFromSpherToCart1(self):
4879         tab1=[2.,0.2,0.3,2.5,0.7,0.8]
4880         da=DataArrayDouble.New();
4881         da.setValues(tab1,2,3);
4882         da2=da.fromSpherToCart();
4883         expected1=[0.37959212195737485,0.11742160338765303,1.9601331556824833, 1.1220769624465328,1.1553337045129035,1.9121054682112213]
4884         for i in xrange(6):
4885             self.assertAlmostEqual(expected1[i],da2.getIJ(0,i),13);
4886             pass
4887         pass
4888
4889     def testUnPolyze1(self):
4890         elts=[0,1,2,3,4,5,6,7]
4891         eltsV=elts;
4892         mesh=MEDCouplingDataForTest.build3DTargetMesh_1();
4893         mesh.convertToPolyTypes(eltsV);
4894         mesh.unPolyze();
4895         mesh2=MEDCouplingDataForTest.build3DTargetMesh_1();
4896         mesh.checkCoherency();
4897         self.assertTrue(mesh.isEqual(mesh2,1e-12));
4898         mesh.convertToPolyTypes(eltsV);
4899         self.assertTrue(not mesh.isEqual(mesh2,1e-12));
4900         mesh.getNodalConnectivity().setIJ(0,6,10);
4901         mesh.getNodalConnectivity().setIJ(0,7,9);
4902         mesh.getNodalConnectivity().setIJ(0,8,12);
4903         mesh.getNodalConnectivity().setIJ(0,9,13);
4904         mesh.unPolyze();
4905         self.assertTrue(mesh.isEqual(mesh2,1e-12));
4906         mesh.convertToPolyTypes(eltsV);
4907         mesh.getNodalConnectivity().setIJ(0,6,12);
4908         mesh.getNodalConnectivity().setIJ(0,7,13);
4909         mesh.getNodalConnectivity().setIJ(0,8,10);
4910         mesh.getNodalConnectivity().setIJ(0,9,9);
4911         mesh.unPolyze();
4912         self.assertTrue(mesh.isEqual(mesh2,1e-12));
4913         mesh.convertToPolyTypes(eltsV);
4914         mesh.getNodalConnectivity().setIJ(0,6,12);
4915         mesh.getNodalConnectivity().setIJ(0,7,10);
4916         mesh.getNodalConnectivity().setIJ(0,8,13);
4917         mesh.getNodalConnectivity().setIJ(0,9,9);
4918         mesh.unPolyze();
4919         self.assertTrue(not mesh.isEqual(mesh2,1e-12));
4920         # Test for 2D mesh
4921         mesh=MEDCouplingDataForTest.build2DTargetMesh_1();
4922         mesh2=MEDCouplingDataForTest.build2DTargetMesh_1();
4923         eltsV=eltsV[:5];
4924         mesh.convertToPolyTypes(eltsV);
4925         self.assertTrue(not mesh.isEqual(mesh2,1e-12));
4926         mesh.unPolyze();
4927         self.assertTrue(mesh.isEqual(mesh2,1e-12));
4928         pass
4929
4930     def testConvertDegeneratedCells1(self):
4931         mesh=MEDCouplingDataForTest.build3DTargetMesh_1();
4932         conn=[0,1,3,3,9,10,12,12, 0,1,3,4,9,9,9,9, 1,1,1,1,10,12,9,10, 10,11,12,9,1,1,1,1]
4933         mesh.allocateCells(4);
4934         mesh.insertNextCell(NORM_HEXA8,8,conn[0:8])
4935         mesh.insertNextCell(NORM_HEXA8,8,conn[8:16])
4936         mesh.insertNextCell(NORM_HEXA8,8,conn[16:24])
4937         mesh.insertNextCell(NORM_HEXA8,8,conn[24:32])
4938         mesh.finishInsertingCells();
4939         mesh.checkCoherency();
4940         self.assertEqual(4,mesh.getNumberOfCells());
4941         self.assertEqual(NORM_HEXA8,mesh.getTypeOfCell(0));
4942         self.assertEqual(NORM_HEXA8,mesh.getTypeOfCell(1));
4943         self.assertEqual(NORM_HEXA8,mesh.getTypeOfCell(2));
4944         self.assertEqual(NORM_HEXA8,mesh.getTypeOfCell(3));
4945         f1=mesh.getMeasureField(True);
4946         mesh.convertDegeneratedCells();
4947         mesh.checkCoherency();
4948         f2=mesh.getMeasureField(True);
4949         self.assertEqual(4,mesh.getNumberOfCells());
4950         self.assertEqual(NORM_PENTA6,mesh.getTypeOfCell(0));
4951         self.assertEqual(NORM_PYRA5,mesh.getTypeOfCell(1));
4952         self.assertEqual(NORM_TETRA4,mesh.getTypeOfCell(2));
4953         self.assertEqual(NORM_PYRA5,mesh.getTypeOfCell(3));
4954         for i in xrange(4):
4955             self.assertAlmostEqual(f1.getArray().getIJ(0,i),f2.getArray().getIJ(0,i),5);
4956             pass
4957         pass
4958
4959     def testGetNodeIdsNearPoints1(self):
4960         mesh=MEDCouplingDataForTest.build2DTargetMesh_1();
4961         coords=mesh.getCoords();
4962         tmp=DataArrayDouble.New();
4963         vals=[0.2,0.2,0.1,0.2,0.2,0.2]
4964         tmp.setValues(vals,3,2);
4965         tmp2=DataArrayDouble.Aggregate(coords,tmp);
4966         mesh.setCoords(tmp2);
4967         pts=[0.2,0.2,0.1,0.3,-0.3,0.7]
4968         c=mesh.getNodeIdsNearPoint(pts[:2],1e-7);
4969         self.assertEqual([4,9,11],c.getValues());
4970         c,cI=mesh.getNodeIdsNearPoints(pts,3,1e-7);
4971         self.assertEqual([0,3,3,4],cI.getValues());
4972         self.assertEqual([4,9,11,6],c.getValues());
4973         c,cI=mesh.getNodeIdsNearPoints(pts,1e-7);
4974         self.assertEqual([0,3,3,4],cI.getValues());
4975         self.assertEqual([4,9,11,6],c.getValues());
4976         c,cI=mesh.getNodeIdsNearPoints(DataArrayDouble.New(pts,3,2),1e-7);
4977         self.assertEqual([0,3,3,4],cI.getValues());
4978         self.assertEqual([4,9,11,6],c.getValues());
4979         self.assertRaises(InterpKernelException,mesh.getNodeIdsNearPoints,DataArrayDouble.New(pts,2,3),1e-7);
4980         pass
4981
4982     def testFieldCopyTinyAttrFrom1(self):
4983         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
4984         f1.setName("f1");
4985         f1.setTimeTolerance(1.e-5);
4986         f1.setDescription("f1Desc");
4987         f1.setTime(1.23,4,5);
4988         f2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
4989         f2.setName("f2");
4990         f2.setDescription("f2Desc");
4991         f2.setTime(6.78,9,10);
4992         f2.setTimeTolerance(4.556e-12);
4993         #
4994         f1.copyTinyAttrFrom(f2);
4995         self.assertAlmostEqual(4.556e-12,f1.getTimeTolerance(),24);
4996         t,dt,it=f1.getTime()
4997         self.assertAlmostEqual(6.78,t,12);
4998         self.assertEqual(9,dt);
4999         self.assertEqual(10,it);
5000         self.assertTrue(f1.getName()=="f1");#name unchanged
5001         self.assertTrue(f1.getDescription()=="f1Desc");#description unchanged
5002         #
5003         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
5004         f1.setName("f1");
5005         f1.setTimeTolerance(1.e-5);
5006         f1.setDescription("f1Desc");
5007         f2=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
5008         f2.setName("f2");
5009         f2.setDescription("f2Desc");
5010         f2.setTimeTolerance(4.556e-12);
5011         #
5012         f1.copyTinyAttrFrom(f2);
5013         self.assertAlmostEqual(4.556e-12,f1.getTimeTolerance(),24);
5014         self.assertTrue(f1.getName()=="f1");#name unchanged
5015         self.assertTrue(f1.getDescription()=="f1Desc");#description unchanged
5016         #
5017         f1=MEDCouplingFieldDouble.New(ON_CELLS,CONST_ON_TIME_INTERVAL);
5018         f1.setName("f1");
5019         f1.setTimeTolerance(1.e-5);
5020         f1.setDescription("f1Desc");
5021         f1.setTime(1.23,4,5);
5022         f1.setEndTime(5.43,2,1);
5023         f2=MEDCouplingFieldDouble.New(ON_CELLS,CONST_ON_TIME_INTERVAL);
5024         f2.setName("f2");
5025         f2.setDescription("f2Desc");
5026         f2.setTimeTolerance(4.556e-12);
5027         f2.setTime(6.78,9,10);
5028         f2.setEndTime(10.98,7,6);
5029         #
5030         f1.copyTinyAttrFrom(f2);
5031         self.assertAlmostEqual(4.556e-12,f1.getTimeTolerance(),24);
5032         self.assertTrue(f1.getName()=="f1");#name unchanged
5033         self.assertTrue(f1.getDescription()=="f1Desc");#description unchanged
5034         t,dt,it=f1.getTime()
5035         self.assertAlmostEqual(6.78,t,12);
5036         self.assertEqual(9,dt);
5037         self.assertEqual(10,it);
5038         t,dt,it=f1.getEndTime()
5039         self.assertAlmostEqual(10.98,t,12);
5040         self.assertEqual(7,dt);
5041         self.assertEqual(6,it);
5042         #
5043         f1=MEDCouplingFieldDouble.New(ON_CELLS,LINEAR_TIME);
5044         f1.setName("f1");
5045         f1.setTimeTolerance(1.e-5);
5046         f1.setDescription("f1Desc");
5047         f1.setTime(1.23,4,5);
5048         f1.setEndTime(5.43,2,1);
5049         f2=MEDCouplingFieldDouble.New(ON_CELLS,LINEAR_TIME);
5050         f2.setName("f2");
5051         f2.setDescription("f2Desc");
5052         f2.setTimeTolerance(4.556e-12);
5053         f2.setTime(6.78,9,10);
5054         f2.setEndTime(10.98,7,6);
5055         #
5056         f1.copyTinyAttrFrom(f2);
5057         self.assertAlmostEqual(4.556e-12,f1.getTimeTolerance(),24);
5058         self.assertTrue(f1.getName()=="f1");#name unchanged
5059         self.assertTrue(f1.getDescription()=="f1Desc");#description unchanged
5060         t,dt,it=f1.getTime()
5061         self.assertAlmostEqual(6.78,t,12);
5062         self.assertEqual(9,dt);
5063         self.assertEqual(10,it);
5064         t,dt,it=f1.getEndTime()
5065         self.assertAlmostEqual(10.98,t,12);
5066         self.assertEqual(7,dt);
5067         self.assertEqual(6,it);
5068         pass
5069
5070     def testExtrudedMesh5(self):
5071         coo1=[0.,1.,2.,3.5]
5072         a=DataArrayDouble.New();
5073         a.setValues(coo1,4,1);
5074         b=MEDCouplingCMesh.New();
5075         b.setCoordsAt(0,a);
5076         c=b.buildUnstructured();
5077         self.assertEqual(1,c.getSpaceDimension());
5078         c.changeSpaceDimension(2);
5079         #
5080         d=DataArrayDouble.New();
5081         d.alloc(13,1);
5082         d.iota();
5083         e=MEDCouplingCMesh.New();
5084         e.setCoordsAt(0,d);
5085         f=e.buildUnstructured();
5086         g=f.getCoords().applyFunc(2,"3.5*IVec+x/6*3.14159265359*JVec");
5087         self.assertRaises(InterpKernelException,f.getCoords().applyFunc,2,"3.5*IVec+x/6*3.14159265359*KVec"); # KVec refers to component #2 and there is only 2 components !
5088         h=g.fromPolarToCart();
5089         f.setCoords(h);
5090         i=c.buildExtrudedMesh(f,1);
5091         self.assertEqual(52,i.getNumberOfNodes());
5092         tmp,tmp2,tmp3=i.mergeNodes(1e-9);
5093         self.assertTrue(tmp2);
5094         self.assertEqual(37,tmp3);
5095         i.convertDegeneratedCells();
5096         i.checkCoherency();
5097         self.assertEqual(36,i.getNumberOfCells());
5098         self.assertEqual(37,i.getNumberOfNodes());
5099         self.assertEqual(12,i.getNumberOfCellsWithType(NORM_TRI3));
5100         self.assertEqual(24,i.getNumberOfCellsWithType(NORM_QUAD4));
5101         expected1=[0.25,0.75,2.0625]
5102         j=i.getMeasureField(True);
5103         for ii in xrange(12):
5104             for k in xrange(3):
5105                 self.assertAlmostEqual(expected1[k],j.getIJ(0,ii*3+k),10);
5106                 pass
5107             pass
5108         expected2=[0.62200846792814113, 0.16666666666681595, 1.4513530918323276, 0.38888888888923495, 2.6293994326053212, 0.7045454545460802, 0.45534180126145435, 0.45534180126150181, 1.0624642029433926, 1.0624642029435025, 1.9248539780597826, 1.9248539780599816, 0.16666666666661334, 0.62200846792815856, 0.38888888888876294, 1.4513530918323678, 0.70454545454522521, 2.629399432605394, -0.16666666666674007, 0.62200846792812436, -0.38888888888906142, 1.4513530918322881, -0.70454545454576778, 2.6293994326052488, -0.45534180126154766, 0.45534180126140844, -1.0624642029436118, 1.0624642029432834, -1.9248539780601803, 1.9248539780595841, -0.62200846792817499, 0.1666666666665495, -1.451353091832408, 0.388888888888613, -2.6293994326054668, 0.70454545454495332, -0.62200846792810593, -0.16666666666680507, -1.451353091832247, -0.38888888888921297, -2.6293994326051746, -0.70454545454604123, -0.45534180126135926, -0.45534180126159562, -1.0624642029431723, -1.0624642029437235, -1.9248539780593836, -1.9248539780603811, -0.1666666666664828, -0.62200846792819242, -0.38888888888846079, -1.4513530918324489, -0.70454545454467987, -2.6293994326055397, 0.16666666666687083, -0.62200846792808862, 0.38888888888936374, -1.4513530918322073, 0.70454545454631357, -2.6293994326051022, 0.45534180126164348, -0.45534180126131207, 1.0624642029438327, -1.0624642029430627, 1.9248539780605791, -1.9248539780591853, 0.62200846792821063, -0.16666666666641802, 1.4513530918324888, -0.38888888888831086, 2.6293994326056125, -0.70454545454440853]
5109         m=i.getBarycenterAndOwner();
5110         for i in xrange(72):
5111             self.assertAlmostEqual(expected2[i],m.getIJ(0,i),10);
5112             pass
5113         #
5114         pass
5115
5116     def testExtrudedMesh6(self):
5117         coo1=[0.,1.,2.,3.5]
5118         a=DataArrayDouble.New();
5119         a.setValues(coo1,4,1);
5120         b=MEDCouplingCMesh.New();
5121         b.setCoordsAt(0,a);
5122         c=b.buildUnstructured();
5123         self.assertEqual(1,c.getSpaceDimension());
5124         c.changeSpaceDimension(2);
5125         #
5126         d=DataArrayDouble.New();
5127         d.alloc(5);
5128         d.iota();
5129         e=MEDCouplingCMesh.New();
5130         e.setCoordsAt(0,d);
5131         f=e.buildUnstructured();
5132         d2=f.getCoords().applyFunc("x*x/2");
5133         f.setCoords(d2);
5134         f.changeSpaceDimension(2);
5135         #
5136         center=[0.,0.]
5137         f.rotate(center,None,pi/3);
5138         g=c.buildExtrudedMesh(f,0);
5139         g.checkCoherency();
5140         expected1=[ 0.4330127018922193, 0.4330127018922193, 0.649519052838329, 1.2990381056766578, 1.299038105676658, 1.948557158514987, 2.1650635094610955, 2.1650635094610964, 3.2475952641916446, 3.031088913245533, 3.0310889132455352, 4.546633369868303 ]
5141         f1=g.getMeasureField(True);
5142         for i in xrange(12):
5143             self.assertAlmostEqual(expected1[i],f1.getIJ(0,i),12);
5144             pass
5145         expected2=[0.625, 0.21650635094610962, 1.625, 0.21650635094610959, 2.8750000000000004, 0.21650635094610965, 1.1250000000000002, 1.0825317547305482, 2.125, 1.0825317547305482, 3.3750000000000004, 1.0825317547305484, 2.125, 2.8145825622994254, 3.125, 2.8145825622994254, 4.375, 2.8145825622994254, 3.6250000000000009, 5.4126587736527414, 4.625, 5.4126587736527414, 5.875, 5.4126587736527414]
5146         f2=g.getBarycenterAndOwner();
5147         for i in xrange(24):
5148             self.assertAlmostEqual(expected2[i],f2.getIJ(0,i),12);
5149             pass
5150         pass
5151
5152     def testExtrudedMesh7(self):
5153         coo1=[0.,1.,2.,3.5]
5154         a=DataArrayDouble.New();
5155         a.setValues(coo1,4,1);
5156         b=MEDCouplingCMesh.New();
5157         b.setCoordsAt(0,a);
5158         c=b.buildUnstructured();
5159         self.assertEqual(1,c.getSpaceDimension());
5160         c.changeSpaceDimension(2);
5161         #
5162         d=DataArrayDouble.New();
5163         d.alloc(13,1);
5164         d.iota();
5165         e=MEDCouplingCMesh.New();
5166         e.setCoordsAt(0,d);
5167         f=e.buildUnstructured();
5168         g=f.getCoords().applyFunc(2,"3.5*IVec+x/6*3.14159265359*JVec");
5169         h=g.fromPolarToCart();
5170         f.setCoords(h);
5171         i=c.buildExtrudedMesh(f,1);
5172         self.assertEqual(52,i.getNumberOfNodes());
5173         tmp,tmp2,tmp3=i.mergeNodes(1e-9);
5174         self.assertTrue(tmp2);
5175         self.assertEqual(37,tmp3);
5176         i.convertDegeneratedCells();
5177         vec1=[10.,0]
5178         i.translate(vec1);
5179         g2=h.applyFunc(3,"13.5/3.5*x*IVec+0*JVec+13.5/3.5*y*KVec");
5180         f.setCoords(g2);
5181         i.changeSpaceDimension(3);
5182         i3=i.buildExtrudedMesh(f,1);
5183         f2=i3.getMeasureField(True);
5184         tmp,tmp2,tmp3=i.mergeNodes(1e-9);
5185         self.assertTrue(tmp2);
5186         self.assertEqual(444,tmp3);
5187         expected1=[1.327751058489274, 4.2942574094314701, 13.024068164857139, 1.3069177251569044, 4.1484240761012954, 12.297505664866796, 1.270833333332571, 3.8958333333309674, 11.039062499993179, 1.2291666666659207, 3.6041666666644425, 9.585937499993932, 1.1930822748415895, 3.3515759238941376, 8.3274943351204556, 1.1722489415082769, 3.2057425905609289, 7.6009318351210622, 1.1722489415082862, 3.2057425905609884, 7.6009318351213713, 1.1930822748416161, 3.3515759238943001, 8.3274943351212727, 1.2291666666659564, 3.6041666666646734, 9.5859374999950777, 1.2708333333326081, 3.8958333333311868, 11.039062499994293, 1.3069177251569224, 4.1484240761014384, 12.297505664867627, 1.3277510584902354, 4.2942574094346071, 13.024068164866796]
5188         for ii in xrange(12):
5189             for jj in xrange(36):
5190                 self.assertAlmostEqual(expected1[jj],f2.getIJ(0,ii*36+jj),9);
5191                 pass
5192         #
5193         pass
5194
5195     def testSimplexize1(self):
5196         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
5197         m.convertToPolyTypes([3]);
5198         da=m.simplexize(0);
5199         self.assertEqual(7,da.getNumberOfTuples());
5200         self.assertEqual(1,da.getNumberOfComponents());
5201         expected2=[0,0,1,2,3,4,4]
5202         for i in xrange(7):
5203             self.assertEqual(expected2[i],da.getIJ(i,0));
5204             pass
5205         m.checkCoherency();
5206         self.assertEqual(7,m.getNumberOfCells());
5207         self.assertEqual(NORM_TRI3,m.getTypeOfCell(0));
5208         self.assertEqual(NORM_TRI3,m.getTypeOfCell(1));
5209         self.assertEqual(NORM_TRI3,m.getTypeOfCell(2));
5210         self.assertEqual(NORM_TRI3,m.getTypeOfCell(3));
5211         self.assertEqual(NORM_POLYGON,m.getTypeOfCell(4));
5212         self.assertEqual(NORM_TRI3,m.getTypeOfCell(5));
5213         self.assertEqual(NORM_TRI3,m.getTypeOfCell(6));
5214         expected1=[0.125,0.125,0.125,0.125,0.25,0.125,0.125]
5215         f=m.getMeasureField(False);
5216         for i in xrange(7):
5217             self.assertAlmostEqual(expected1[i]*sqrt(2.),f.getIJ(i,0),10);
5218             pass
5219         types=m.getAllGeoTypes();
5220         self.assertEqual([NORM_TRI3,NORM_POLYGON],types);
5221         #
5222         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
5223         m.convertToPolyTypes([3]);
5224         da=m.simplexize(1);
5225         self.assertEqual(7,da.getNumberOfTuples());
5226         self.assertEqual(1,da.getNumberOfComponents());
5227         for i in xrange(7):
5228             self.assertEqual(expected2[i],da.getIJ(i,0));
5229             pass
5230         m.checkCoherency();
5231         types=m.getAllGeoTypes();
5232         self.assertEqual([NORM_TRI3,NORM_POLYGON],types);
5233         self.assertEqual(7,m.getNumberOfCells());
5234         self.assertEqual(NORM_TRI3,m.getTypeOfCell(0));
5235         self.assertEqual(NORM_TRI3,m.getTypeOfCell(1));
5236         self.assertEqual(NORM_TRI3,m.getTypeOfCell(2));
5237         self.assertEqual(NORM_TRI3,m.getTypeOfCell(3));
5238         self.assertEqual(NORM_POLYGON,m.getTypeOfCell(4));
5239         self.assertEqual(NORM_TRI3,m.getTypeOfCell(5));
5240         self.assertEqual(NORM_TRI3,m.getTypeOfCell(6));
5241         f=m.getMeasureField(False);
5242         for i in xrange(7):
5243             self.assertAlmostEqual(expected1[i]*sqrt(2.),f.getIJ(i,0),10);
5244             pass
5245         pass
5246
5247     def testSimplexize2(self):
5248         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
5249         m.convertToPolyTypes([3]);
5250         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
5251         f1.setMesh(m);
5252         arr=DataArrayDouble.New();
5253         arr1=[10.,110.,20.,120.,30.,130.,40.,140.,50.,150.]
5254         arr.setValues(arr1,5,2);
5255         f1.setArray(arr);
5256         #
5257         f1.checkCoherency();
5258         self.assertTrue(f1.simplexize(0));
5259         f1.checkCoherency();
5260         expected1=[10.,110.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.,50.,150.]
5261         for i in xrange(14):
5262             self.assertAlmostEqual(expected1[i],f1.getIJ(0,i),10);
5263             pass
5264         self.assertTrue(not f1.simplexize(0));
5265         for i in xrange(14):
5266             self.assertAlmostEqual(expected1[i],f1.getIJ(0,i),10);
5267             pass
5268         #
5269         pass
5270
5271     def testDAMeld1(self):
5272         da1=DataArrayDouble.New();
5273         da1.alloc(7,2);
5274         da2=DataArrayDouble.New();
5275         da2.alloc(7,1);
5276         #
5277         da1.fillWithValue(7.);
5278         da2.iota(0.);
5279         da3=da2.applyFunc(3,"10*x*IVec+100*x*JVec+1000*x*KVec");
5280         #
5281         da1.setInfoOnComponent(0,"c0da1");
5282         da1.setInfoOnComponent(1,"c1da1");
5283         da3.setInfoOnComponent(0,"c0da3");
5284         da3.setInfoOnComponent(1,"c1da3");
5285         da3.setInfoOnComponent(2,"c2da3");
5286         #
5287         da1C=da1.deepCpy();
5288         da1.meldWith(da3);
5289         self.assertEqual(5,da1.getNumberOfComponents());
5290         self.assertEqual(7,da1.getNumberOfTuples());
5291         self.assertTrue(da1.getInfoOnComponent(0)=="c0da1");
5292         self.assertTrue(da1.getInfoOnComponent(1)=="c1da1");
5293         self.assertTrue(da1.getInfoOnComponent(2)=="c0da3");
5294         self.assertTrue(da1.getInfoOnComponent(3)=="c1da3");
5295         self.assertTrue(da1.getInfoOnComponent(4)=="c2da3");
5296         #
5297         expected1=[7.,7.,0.,0.,0., 7.,7.,10.,100.,1000., 7.,7.,20.,200.,2000., 7.,7.,30.,300.,3000., 7.,7.,40.,400.,4000.,7.,7.,50.,500.,5000.,7.,7.,60.,600.,6000.]
5298         for i in xrange(35):
5299             self.assertAlmostEqual(expected1[i],da1.getIJ(0,i),10);
5300             pass
5301         #
5302         dai1=da1C.convertToIntArr();
5303         dai3=da3.convertToIntArr();
5304         dai1.meldWith(dai3);
5305         self.assertEqual(5,dai1.getNumberOfComponents());
5306         self.assertEqual(7,dai1.getNumberOfTuples());
5307         self.assertTrue(dai1.getInfoOnComponent(0)=="c0da1");
5308         self.assertTrue(dai1.getInfoOnComponent(1)=="c1da1");
5309         self.assertTrue(dai1.getInfoOnComponent(2)=="c0da3");
5310         self.assertTrue(dai1.getInfoOnComponent(3)=="c1da3");
5311         self.assertTrue(dai1.getInfoOnComponent(4)=="c2da3");
5312         for i in xrange(35):
5313             self.assertEqual(int(expected1[i]),dai1.getIJ(0,i));
5314             pass
5315         # test of static method DataArrayDouble::meld
5316         da4=DataArrayDouble.Meld(da1C,da3);
5317         tmp=DataArrayDouble.Meld([da1C,da3]);
5318         self.assertTrue(da4.isEqual(tmp,1e-10))
5319         self.assertEqual(5,da4.getNumberOfComponents());
5320         self.assertEqual(7,da4.getNumberOfTuples());
5321         self.assertTrue(da4.getInfoOnComponent(0)=="c0da1");
5322         self.assertTrue(da4.getInfoOnComponent(1)=="c1da1");
5323         self.assertTrue(da4.getInfoOnComponent(2)=="c0da3");
5324         self.assertTrue(da4.getInfoOnComponent(3)=="c1da3");
5325         self.assertTrue(da4.getInfoOnComponent(4)=="c2da3");
5326         for i in xrange(35):
5327             self.assertAlmostEqual(expected1[i],da4.getIJ(0,i),10);
5328             pass
5329         # test of static method DataArrayInt::meld
5330         dai1=da1C.convertToIntArr();
5331         dai4=DataArrayInt.Meld(dai1,dai3);
5332         tmp=DataArrayInt.Meld([dai1,dai3]);
5333         self.assertTrue(dai4.isEqual(tmp))
5334         self.assertEqual(5,dai4.getNumberOfComponents());
5335         self.assertEqual(7,dai4.getNumberOfTuples());
5336         self.assertTrue(dai4.getInfoOnComponent(0)=="c0da1");
5337         self.assertTrue(dai4.getInfoOnComponent(1)=="c1da1");
5338         self.assertTrue(dai4.getInfoOnComponent(2)=="c0da3");
5339         self.assertTrue(dai4.getInfoOnComponent(3)=="c1da3");
5340         self.assertTrue(dai4.getInfoOnComponent(4)=="c2da3");
5341         for i in xrange(35):
5342             self.assertEqual(int(expected1[i]),dai4.getIJ(0,i));
5343             pass
5344         pass
5345
5346     def testFieldMeld1(self):
5347         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
5348         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
5349         f1.setMesh(m);
5350         da1=DataArrayDouble.New();
5351         arr1=[12.,23.,34.,45.,56.]
5352         da1.setValues(arr1,5,1);
5353         da1.setInfoOnComponent(0,"aaa");
5354         f1.setArray(da1);
5355         f1.setTime(3.4,2,1);
5356         f1.checkCoherency();
5357         #
5358         f2=f1.deepCpy();
5359         f2.setMesh(f1.getMesh());
5360         f2.checkCoherency();
5361         f2.changeNbOfComponents(2,5.);
5362         f2.assign(5.);
5363         f2.getArray().setInfoOnComponent(0,"bbb");
5364         f2.getArray().setInfoOnComponent(1,"ccc");
5365         f2.checkCoherency();
5366         #
5367         f3=MEDCouplingFieldDouble.MeldFields(f2,f1);
5368         f3.checkCoherency();
5369         self.assertEqual(5,f3.getNumberOfTuples());
5370         self.assertEqual(3,f3.getNumberOfComponents());
5371         self.assertTrue(f3.getArray().getInfoOnComponent(0)=="bbb");
5372         self.assertTrue(f3.getArray().getInfoOnComponent(1)=="ccc");
5373         self.assertTrue(f3.getArray().getInfoOnComponent(2)=="aaa");
5374         expected1=[5.,5.,12.,5.,5.,23.,5.,5.,34.,5.,5.,45.,5.,5.,56.]
5375         for i in xrange(15):
5376             self.assertAlmostEqual(expected1[i],f3.getIJ(0,i),12);
5377             pass
5378         time,dt,it=f3.getTime();
5379         self.assertAlmostEqual(3.4,time,14);
5380         self.assertEqual(2,dt);
5381         self.assertEqual(1,it);
5382         #
5383         f4=f2.buildNewTimeReprFromThis(NO_TIME,False);
5384         f5=f1.buildNewTimeReprFromThis(NO_TIME,False);
5385         f6=MEDCouplingFieldDouble.MeldFields(f4,f5);
5386         f6.checkCoherency();
5387         self.assertEqual(5,f6.getNumberOfTuples());
5388         self.assertEqual(3,f6.getNumberOfComponents());
5389         self.assertTrue(f6.getArray().getInfoOnComponent(0)=="bbb");
5390         self.assertTrue(f6.getArray().getInfoOnComponent(1)=="ccc");
5391         self.assertTrue(f6.getArray().getInfoOnComponent(2)=="aaa");
5392         for i in xrange(15):
5393             self.assertAlmostEqual(expected1[i],f6.getIJ(0,i),12);
5394             pass
5395         #
5396         pass
5397
5398     def testMergeNodes2(self):
5399         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
5400         m2=MEDCouplingDataForTest.build2DTargetMesh_1();
5401         vec=[0.002,0.]
5402         m2.translate(vec);
5403         #
5404         m3=MEDCouplingUMesh.MergeUMeshes([m1,m2]);
5405         da,b,newNbOfNodes=m3.mergeNodes2(0.01);
5406         self.assertEqual(9,m3.getNumberOfNodes());
5407         expected1=[-0.299,-0.3, 0.201,-0.3, 0.701,-0.3, -0.299,0.2, 0.201,0.2, 0.701,0.2, -0.299,0.7, 0.201,0.7, 0.701,0.7]
5408         for i in xrange(18):
5409             self.assertAlmostEqual(expected1[i],m3.getCoords().getIJ(0,i),13);
5410             pass
5411         #
5412         pass
5413
5414     def testMergeField2(self):
5415         m=MEDCouplingDataForTest.build2DTargetMesh_1();
5416         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
5417         f1.setMesh(m);
5418         arr=DataArrayDouble.New();
5419         arr.alloc(5,2);
5420         arr.fillWithValue(2.);
5421         f1.setArray(arr);
5422         f2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
5423         f2.setMesh(m);
5424         arr=DataArrayDouble.New();
5425         arr.alloc(5,2);
5426         arr.fillWithValue(5.);
5427         f2.setArray(arr);
5428         f3=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
5429         f3.setMesh(m);
5430         arr=DataArrayDouble.New();
5431         arr.alloc(5,2);
5432         arr.fillWithValue(7.);
5433         f3.setArray(arr);
5434         #
5435         f4=MEDCouplingFieldDouble.MergeFields([f1,f2,f3]);
5436         self.assertEqual(15,f4.getMesh().getNumberOfCells());
5437         expected1=[2.,2.,2.,2.,2.,2.,2.,2.,2.,2., 5.,5.,5.,5.,5.,5.,5.,5.,5.,5., 7.,7.,7.,7.,7.,7.,7.,7.,7.,7.]
5438         for i in xrange(30):
5439             self.assertAlmostEqual(expected1[i],f4.getIJ(0,i),13);
5440             pass
5441         #
5442         pass
5443
5444     def testDAIBuildComplement1(self):
5445         a=DataArrayInt.New();
5446         tab=[3,1,7,8]
5447         a.setValues(tab,4,1);
5448         b=a.buildComplement(12);
5449         self.assertEqual(8,b.getNumberOfTuples());
5450         self.assertEqual(1,b.getNumberOfComponents());
5451         expected1=[0,2,4,5,6,9,10,11]
5452         for i in xrange(8):
5453             self.assertEqual(expected1[i],b.getIJ(0,i));
5454             pass
5455         pass
5456
5457     def testDAIBuildUnion1(self):
5458         a=DataArrayInt.New();
5459         tab1=[3,1,7,8]
5460         a.setValues(tab1,4,1);
5461         c=DataArrayInt.New();
5462         tab2=[5,3,0,18,8]
5463         c.setValues(tab2,5,1);
5464         b=a.buildUnion(c);
5465         self.assertEqual(7,b.getNumberOfTuples());
5466         self.assertEqual(1,b.getNumberOfComponents());
5467         expected1=[0,1,3,5,7,8,18]
5468         for i in xrange(7):
5469             self.assertEqual(expected1[i],b.getIJ(0,i));
5470             pass
5471         b=DataArrayInt.BuildUnion([a,c]);
5472         self.assertEqual(7,b.getNumberOfTuples());
5473         self.assertEqual(1,b.getNumberOfComponents());
5474         expected1=[0,1,3,5,7,8,18]
5475         for i in xrange(7):
5476             self.assertEqual(expected1[i],b.getIJ(0,i));
5477             pass
5478         pass
5479
5480     def testDAIBuildIntersection1(self):
5481         a=DataArrayInt.New();
5482         tab1=[3,1,7,8]
5483         a.setValues(tab1,4,1);
5484         c=DataArrayInt.New();
5485         tab2=[5,3,0,18,8]
5486         c.setValues(tab2,5,1);
5487         b=a.buildIntersection(c);
5488         self.assertEqual(2,b.getNumberOfTuples());
5489         self.assertEqual(1,b.getNumberOfComponents());
5490         expected1=[3,8]
5491         for i in xrange(2):
5492             self.assertEqual(expected1[i],b.getIJ(0,i));
5493             pass
5494         b=DataArrayInt.BuildIntersection([a,c]);
5495         self.assertEqual(2,b.getNumberOfTuples());
5496         self.assertEqual(1,b.getNumberOfComponents());
5497         expected1=[3,8]
5498         for i in xrange(2):
5499             self.assertEqual(expected1[i],b.getIJ(0,i));
5500             pass
5501         pass
5502
5503     def testDAIDeltaShiftIndex1(self):
5504         a=DataArrayInt.New();
5505         tab=[1,3,6,7,7,9,15]
5506         a.setValues(tab,7,1);
5507         b=a.deltaShiftIndex();
5508         self.assertEqual(6,b.getNumberOfTuples());
5509         self.assertEqual(1,b.getNumberOfComponents());
5510         expected1=[2,3,1,0,2,6]
5511         for i in xrange(6):
5512             self.assertEqual(expected1[i],b.getIJ(0,i));
5513             pass
5514         pass
5515
5516     def testDaDoubleSelectByTupleIdSafe1(self):
5517         a=DataArrayDouble.New();
5518         arr1=[1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1]
5519         a.setValues(arr1,7,2);
5520         a.setInfoOnComponent(0,"toto");
5521         a.setInfoOnComponent(1,"tata");
5522         #
5523         arr2=[4,2,0,6,5]
5524         b=a.selectByTupleIdSafe(arr2);
5525         self.assertEqual(5,b.getNumberOfTuples());
5526         self.assertEqual(2,b.getNumberOfComponents());
5527         self.assertTrue(b.getInfoOnComponent(0)=="toto");
5528         self.assertTrue(b.getInfoOnComponent(1)=="tata");
5529         expected1=[5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1]
5530         for i in xrange(10):
5531             self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
5532             pass
5533         arr4=[4,-1,0,6,5]
5534         self.assertRaises(InterpKernelException,a.selectByTupleIdSafe,arr4);
5535         arr5=[4,2,0,6,7]
5536         self.assertRaises(InterpKernelException,a.selectByTupleIdSafe,arr5);
5537         #
5538         c=DataArrayInt.New();
5539         arr3=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
5540         c.setValues(arr3,7,2);
5541         c.setInfoOnComponent(0,"toto");
5542         c.setInfoOnComponent(1,"tata");
5543         d=c.selectByTupleIdSafe(arr2);
5544         self.assertEqual(5,d.getNumberOfTuples());
5545         self.assertEqual(2,d.getNumberOfComponents());
5546         self.assertTrue(d.getInfoOnComponent(0)=="toto");
5547         self.assertTrue(d.getInfoOnComponent(1)=="tata");
5548         expected2=[5,15,3,13,1,11,7,17,6,16]
5549         for i in xrange(10):
5550             self.assertEqual(expected2[i],d.getIJ(0,i));
5551             pass
5552         self.assertRaises(InterpKernelException,c.selectByTupleIdSafe,arr4);
5553         self.assertRaises(InterpKernelException,c.selectByTupleIdSafe,arr5);
5554         pass
5555
5556     def testAreCellsIncludedIn1(self):
5557         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
5558         pt=[1,3]
5559         m2=m.buildPartOfMySelf(pt,True);
5560         ret,tmp=m.areCellsIncludedIn(m2,0)
5561         self.assertTrue(ret);
5562         self.assertEqual(2,tmp.getNumberOfTuples());
5563         self.assertEqual(1,tmp.getNumberOfComponents());
5564         self.assertEqual(pt[0],tmp.getIJ(0,0));
5565         self.assertEqual(pt[1],tmp.getIJ(0,1));
5566         ret,tmp=m2.areCellsIncludedIn(m,0)
5567         self.assertTrue(not ret);
5568         m3=MEDCouplingUMesh.MergeUMeshesOnSameCoords(m,m2)
5569         c,cI=m3.findCommonCells(2,m.getNumberOfCells())
5570         self.assertTrue(c.isEqual(DataArrayInt([1,5,3,6])))
5571         self.assertTrue(cI.isEqual(DataArrayInt([0,2,4])))
5572         pass
5573
5574     def testSwigErrorProtection1(self):
5575         m=MEDCouplingDataForTest.build3DTargetMesh_1();
5576         m.rotate([0.,0.,0.],[0.3,0.6,1.2],0.37)
5577         m.rotate([0.,0.,0.],[0.3,6,1.2],0.37)
5578         self.assertRaises(InterpKernelException,m.rotate,[0.,0.,0.],(0.3,6,"1.2"),0.37)
5579         self.assertRaises(InterpKernelException,m.rotate,[0.,"0.",0.],[0.3,0.6,1.2],0.37)
5580         self.assertRaises(InterpKernelException,m.rotate,[0.,0.,0.],[0.3,'0.6',1.2],0.37)
5581         m2=m.buildPartOfMySelf([2,5],True)
5582         m3=m.buildPartOfMySelf((2,5),True)
5583         self.assertTrue(m2.isEqual(m3,1e-12))
5584         self.assertRaises(InterpKernelException,m.buildPartOfMySelf,[2,5.],True)
5585         da1=m.getCoords().keepSelectedComponents([1])
5586         da2=m.getCoords().keepSelectedComponents((1,))
5587         self.assertTrue(da1.isEqual(da2,1e-12))
5588         self.assertRaises(InterpKernelException,m.getCoords().keepSelectedComponents,["1"])
5589         pass
5590
5591     def testDAIBuildSubstraction1(self):
5592         a=DataArrayInt.New()
5593         aa=[2,3,6,8,9]
5594         a.setValues(aa,5,1)
5595         b=DataArrayInt.New()
5596         bb=[1,3,5,9,11]
5597         b.setValues(bb,5,1)
5598         self.assertEqual([2,6,8],a.buildSubstraction(b).getValues())
5599         pass
5600
5601     def testBuildOrthogonalField2(self):
5602         m=MEDCouplingDataForTest.build2DTargetMesh_1();
5603         d1=DataArrayInt.New();
5604         d2=DataArrayInt.New();
5605         d3=DataArrayInt.New();
5606         d4=DataArrayInt.New();
5607         m1=m.buildDescendingConnectivity(d1,d2,d3,d4);
5608         #
5609         f1=m1.buildOrthogonalField();
5610         da1=f1.getArray();
5611         self.assertEqual(2,da1.getNumberOfComponents());
5612         self.assertEqual(13,da1.getNumberOfTuples());
5613         #
5614         expected1=[-1.,0.,0.,1.,1.,0.,0.,-1.,0.707106781186548,0.707106781186548,0.,-1.,0.,1.,1.,0.,0.,1.,1.,0.,-1.,0.,0.,1.,1.,0.];
5615         for i in xrange(26):
5616             self.assertAlmostEqual(expected1[i],da1.getIJ(0,i),14);
5617             pass
5618         pass
5619
5620     def testSwigErrorProtection2(self):
5621         m=MEDCouplingDataForTest.build2DTargetMesh_1();
5622         coo=m.getCoords()
5623         c=m.getNodalConnectivity()
5624         ci=m.getNodalConnectivityIndex()
5625         del m
5626         self.assertEqual(2,coo.getNumberOfComponents());
5627         self.assertEqual(6,ci.getNumberOfTuples());
5628         self.assertEqual(23,c.getNumberOfTuples());
5629         m=MEDCouplingDataForTest.build2DTargetMesh_1();
5630         f=m.getMeasureField(True)
5631         c=f.getArray()
5632         del f
5633         self.assertEqual(1,c.getNumberOfComponents());
5634         m=MEDCouplingCMesh.New()
5635         x=DataArrayDouble.New()
5636         x.setValues([1.,2.,4.],3,1)
5637         m.setCoordsAt(0,x)
5638         del x
5639         xx=m.getCoordsAt(0)
5640         del m
5641         self.assertEqual(3,xx.getNumberOfTuples());
5642         #
5643         m=MEDCouplingDataForTest.build2DTargetMesh_1();
5644         f=m.getMeasureField(True)
5645         m2=f.getMesh()
5646         del m
5647         del f
5648         self.assertEqual(5,m2.getNumberOfCells());
5649         pass
5650
5651     def testUMInsertNextCell1(self):
5652         targetCoords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ]
5653         targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
5654         targetMesh=MEDCouplingUMesh.New();
5655         targetMesh.allocateCells(5);
5656         self.assertRaises(InterpKernelException,targetMesh.insertNextCell,NORM_QUAD4,4,targetConn[0:4])
5657         targetMesh.setMeshDimension(2);
5658         targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
5659         self.assertRaises(InterpKernelException,targetMesh.insertNextCell,NORM_TETRA4,4,targetConn[0:4])
5660         self.assertRaises(InterpKernelException,targetMesh.insertNextCell,NORM_SEG2,2,targetConn[0:2])
5661         self.assertRaises(InterpKernelException,targetMesh.insertNextCell,NORM_POINT1,1,targetConn[0:1])
5662         targetMesh.insertNextCell(NORM_TRI3,3,targetConn[4:7])
5663         targetMesh.insertNextCell(NORM_TRI3,3,targetConn[7:10])
5664         targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[10:14])
5665         targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[14:18])
5666         targetMesh.finishInsertingCells();
5667         myCoords=DataArrayDouble.New();
5668         myCoords.setValues(targetCoords,9,2);
5669         targetMesh.setCoords(myCoords);
5670         targetMesh.checkCoherency();
5671         pass
5672
5673     def testFieldOperatorDivDiffComp1(self):
5674         m=MEDCouplingDataForTest.build2DTargetMesh_1();
5675         m1,d0,d1,d2,d3=m.buildDescendingConnectivity();
5676         #
5677         f1=m1.buildOrthogonalField();
5678         arr1=[2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.]
5679         arr=DataArrayDouble.New();
5680         arr.setValues(arr1,13,1);
5681         f2=MEDCouplingFieldDouble.New(ON_CELLS);
5682         f2.setArray(arr);
5683         f2.setMesh(m1);
5684         f2.checkCoherency();
5685         #
5686         f3=f1/f2;
5687         self.assertRaises(InterpKernelException,f2.__div__,f1)
5688         f3.checkCoherency();
5689         f1/=f2;
5690         #self.assertRaises(InterpKernelException,f2.__idiv__,f1) # mem leaks
5691         self.assertTrue(f1.isEqual(f3,1e-10,1e-10));
5692         expected1=[-0.5, 0.0, 0.0, 0.33333333333333331, 0.25, 0.0, 0.0, -0.20000000000000001, 0.117851130197758, 0.117851130197758, 0.0, -0.14285714285714285, 0.0, 0.125, 0.1111111111111111, 0.0, 0.0, 0.10000000000000001, 0.090909090909090912, 0.0, -0.083333333333333329, 0.0, 0.0, 0.076923076923076927, 0.071428571428571425, 0.0]
5693         for i in xrange(26):
5694             self.assertAlmostEqual(expected1[i],f3.getIJ(0,i),10);
5695             pass
5696         pass
5697
5698     def testDARearrange1(self):
5699         da1=DataArrayInt.New();
5700         da1.alloc(12,1);
5701         da1.iota(0);
5702         #
5703         self.assertEqual(12,da1.getNbOfElems());
5704         self.assertEqual(1,da1.getNumberOfComponents());
5705         self.assertEqual(12,da1.getNumberOfTuples());
5706         da1.rearrange(4);
5707         self.assertEqual(12,da1.getNbOfElems());
5708         self.assertEqual(4,da1.getNumberOfComponents());
5709         self.assertEqual(3,da1.getNumberOfTuples());
5710         for i in xrange(12):
5711             self.assertEqual(i,da1.getIJ(0,i));
5712         #
5713         da1.rearrange(6);
5714         self.assertEqual(12,da1.getNbOfElems());
5715         self.assertEqual(6,da1.getNumberOfComponents());
5716         self.assertEqual(2,da1.getNumberOfTuples());
5717         for i in xrange(12):
5718             self.assertEqual(i,da1.getIJ(0,i));
5719         #
5720         self.assertRaises(InterpKernelException,da1.rearrange,7);
5721         #
5722         da1.rearrange(12);
5723         self.assertEqual(12,da1.getNbOfElems());
5724         self.assertEqual(12,da1.getNumberOfComponents());
5725         self.assertEqual(1,da1.getNumberOfTuples());
5726         for i in xrange(12):
5727             self.assertEqual(i,da1.getIJ(0,i));
5728         #
5729         da1.rearrange(3);
5730         self.assertEqual(12,da1.getNbOfElems());
5731         self.assertEqual(3,da1.getNumberOfComponents());
5732         self.assertEqual(4,da1.getNumberOfTuples());
5733         for i in xrange(12):
5734             self.assertEqual(i,da1.getIJ(0,i));
5735         #double
5736         da2=da1.convertToDblArr();
5737         st=da2.getHiddenCppPointer()
5738         #
5739         self.assertEqual(12,da2.getNbOfElems());
5740         self.assertEqual(3,da2.getNumberOfComponents());
5741         self.assertEqual(4,da2.getNumberOfTuples());
5742         da2.rearrange(4);
5743         self.assertEqual(12,da2.getNbOfElems());
5744         self.assertEqual(4,da2.getNumberOfComponents());
5745         self.assertEqual(3,da2.getNumberOfTuples());
5746         for i in xrange(12):
5747             self.assertAlmostEqual(float(i),da2.getIJ(0,i),14);
5748         #
5749         da2.rearrange(6);
5750         self.assertEqual(12,da2.getNbOfElems());
5751         self.assertEqual(6,da2.getNumberOfComponents());
5752         self.assertEqual(2,da2.getNumberOfTuples());
5753         for i in xrange(12):
5754             self.assertAlmostEqual(float(i),da2.getIJ(0,i),14);
5755         #
5756         self.assertRaises(InterpKernelException,da2.rearrange,7);
5757         #
5758         da2.rearrange(1);
5759         self.assertEqual(st,da2.getHiddenCppPointer())
5760         self.assertEqual(12,da2.getNbOfElems());
5761         self.assertEqual(1,da2.getNumberOfComponents());
5762         self.assertEqual(12,da2.getNumberOfTuples());
5763         for i in xrange(12):
5764             self.assertAlmostEqual(float(i),da2.getIJ(0,i),14);
5765         #
5766         da2.rearrange(3);
5767         self.assertEqual(12,da2.getNbOfElems());
5768         self.assertEqual(3,da2.getNumberOfComponents());
5769         self.assertEqual(4,da2.getNumberOfTuples());
5770         for i in xrange(12):
5771             self.assertAlmostEqual(float(i),da2.getIJ(0,i),14);
5772         pass
5773
5774     def testDARearrange2(self):
5775         da1=DataArrayInt.New();
5776         arr=[1,2,3,2,2,3,5,1,5,5,2,2]
5777         da1.setValues(arr,4,3);
5778         s=da1.getDifferentValues();
5779         expected1=DataArrayInt([1,2,3,5])
5780         self.assertTrue(expected1.isEqual(s));
5781         pass
5782
5783     def testSwigErrorProtection3(self):
5784         da=DataArrayInt.New()
5785         da.setValues([1,2,3,4,0,0,0,0,0,0,0,0],4,3)
5786         self.assertEqual([1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0],da.getValues())
5787         self.assertEqual(3,da.getNumberOfComponents());
5788         self.assertEqual(4,da.getNumberOfTuples());
5789         da=DataArrayInt.New()
5790         da.setValues(((1,2,3),(4,4,3),(0,0,0),(0,0,0)),4,3)
5791         self.assertEqual([1, 2, 3, 4, 4, 3, 0, 0, 0, 0, 0, 0],da.getValues())
5792         self.assertEqual(3,da.getNumberOfComponents());
5793         self.assertEqual(4,da.getNumberOfTuples());
5794         da.setValues((10*[1]+290*[2])[:12],4,3)
5795         self.assertEqual(10*[1]+[2,2],da.getValues())
5796         self.assertEqual(3,da.getNumberOfComponents());
5797         self.assertEqual(4,da.getNumberOfTuples());
5798         #
5799         da=DataArrayDouble.New()
5800         da.setValues([1,2,3.,4,0,0,0,0,0,0,0,0],4,3)
5801         self.assertEqual([1., 2., 3., 4., 0., 0., 0., 0., 0., 0., 0., 0.],da.getValues())
5802         self.assertEqual(3,da.getNumberOfComponents());
5803         self.assertEqual(4,da.getNumberOfTuples());
5804         da=DataArrayDouble.New()
5805         da.setValues(((1,2,3),(4.,4,3),(0,0,0),(0,0,0)),4,3)
5806         self.assertEqual([1., 2., 3., 4., 4., 3., 0., 0., 0., 0., 0., 0.],da.getValues())
5807         self.assertEqual(3,da.getNumberOfComponents());
5808         self.assertEqual(4,da.getNumberOfTuples());
5809         da.setValues((10*[1]+290*[2])[:12],4,3)
5810         self.assertEqual(10*[1.]+[2.,2.],da.getValues())
5811         self.assertEqual(3,da.getNumberOfComponents());
5812         self.assertEqual(4,da.getNumberOfTuples());
5813         pass
5814
5815     def testDAIBuildPermutationArr1(self):
5816         a=DataArrayInt.New()
5817         a.setValues([4,5,6,7,8],5,1)
5818         b=DataArrayInt.New()
5819         b.setValues([5,4,8,6,7],5,1)
5820         c=a.buildPermutationArr(b)
5821         self.assertEqual([1,0,4,2,3],c.getValues())
5822         self.assertTrue(a.isEqualWithoutConsideringStrAndOrder(b))
5823         b.setIJ(0,0,9)
5824         self.assertTrue(not a.isEqualWithoutConsideringStrAndOrder(b))
5825         self.assertRaises(InterpKernelException,a.buildPermutationArr,b)
5826         a.setIJ(3,0,4)
5827         b.setIJ(0,0,5)
5828         b.setIJ(4,0,4)#a==[4,5,6,4,8] and b==[5,4,8,6,4]
5829         self.assertTrue(a.isEqualWithoutConsideringStrAndOrder(b))
5830         c=a.buildPermutationArr(b)
5831         self.assertEqual([1,3,4,2,3],c.getValues())
5832         d=b.convertToDblArr()
5833         expect3=[4,4,5,6,8]
5834         b.sort()
5835         self.assertEqual(expect3,b.getValues())
5836         d.sort()
5837         self.assertEqual(5,d.getNumberOfTuples());
5838         self.assertEqual(1,d.getNumberOfComponents());
5839         for i in xrange(5):
5840             self.assertAlmostEqual(float(expect3[i]),d.getIJ(i,0),14);
5841             pass
5842         pass
5843
5844     def testAreCellsIncludedIn2(self):
5845         myName="Vitoo";
5846         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
5847         m2=m.buildPartOfMySelf([],True);
5848         self.assertEqual(0,m2.getNumberOfCells());
5849         self.assertEqual(3,m2.getSpaceDimension());
5850         self.assertEqual(2,m2.getMeshDimension());
5851         m2.setName(myName);
5852         test,tmp=m.areCellsIncludedIn(m2,0)
5853         self.assertTrue(test);
5854         self.assertEqual(myName,tmp.getName());
5855         self.assertEqual(0,tmp.getNumberOfTuples())
5856         self.assertEqual(1,tmp.getNumberOfComponents())
5857         pass
5858
5859     def testUMeshGetPartBarycenterAndOwner1(self):
5860         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
5861         part1=[1,0,4];
5862         part=DataArrayInt.New();
5863         part.setValues(part1,3,1);
5864         b=m1.getPartBarycenterAndOwner(part);
5865         self.assertEqual(2,b.getNumberOfComponents());
5866         self.assertEqual(3,b.getNumberOfTuples());
5867         expected1=[0.36666666666666665,-0.13333333333333333,-0.05,-0.05,0.45,0.45];
5868         for i in xrange(6):
5869             self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
5870             pass
5871         pass
5872
5873     def testUMeshGetPartMeasureField1(self):
5874         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
5875         part1=[1,0,4];
5876         part=DataArrayInt.New();
5877         part.setValues(part1,3,1);
5878         b=m1.getPartMeasureField(True,part);
5879         self.assertEqual(1,b.getNumberOfComponents());
5880         self.assertEqual(3,b.getNumberOfTuples());
5881         expected1=[0.125,0.25,0.25];
5882         for i in xrange(3):
5883             self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
5884             pass
5885         pass
5886
5887     def testUMeshBuildPartOrthogonalField1(self):
5888         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
5889         m1.changeSpaceDimension(3);
5890         part1=[1,0,4];
5891         part=DataArrayInt.New();
5892         part.setValues(part1,3,1);
5893         b=m1.buildPartOrthogonalField(part);
5894         self.assertEqual(3,b.getArray().getNumberOfComponents());
5895         self.assertEqual(3,b.getArray().getNumberOfTuples());
5896         expected1=[0.,0.,-1.,0.,0.,-1.,0.,0.,-1.];
5897         for i in xrange(9):
5898             self.assertAlmostEqual(expected1[i],b.getArray().getIJ(0,i),14);
5899             pass
5900         pass
5901
5902     def testUMeshGetTypesOfPart1(self):
5903         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
5904         part1=[0,3,4];
5905         p1=DataArrayInt.New()
5906         p1.setValues(part1,3,1)
5907         s=m1.getTypesOfPart(p1);
5908         self.assertEqual([NORM_QUAD4],s);
5909         part2=[2,2,2,1];
5910         p2=DataArrayInt.New()
5911         p2.setValues(part2,4,1)
5912         s=m1.getTypesOfPart(p2);
5913         self.assertEqual([NORM_TRI3],s);
5914         part3=[3,2,1];
5915         p3=DataArrayInt.New()
5916         p3.setValues(part3,3,1)
5917         s=m1.getTypesOfPart(p3);
5918         self.assertEqual(s,[NORM_TRI3,NORM_QUAD4]);
5919         pass
5920
5921     def testUMeshKeepCellIdsByType1(self):
5922         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
5923         part1=[0,3,4]
5924         p1=DataArrayInt.New()
5925         p1.setValues(part1,3,1)
5926         p1.setName("p1")
5927         a=m1.keepCellIdsByType(NORM_TRI3,p1);
5928         self.assertEqual("p1",a.getName())
5929         self.assertEqual(1,a.getNumberOfComponents());
5930         self.assertEqual(0,a.getNumberOfTuples());
5931         #
5932         part2=[3,2,0,2,4]
5933         p2=DataArrayInt.New()
5934         p2.setValues(part2,5,1)
5935         p2.setName("p2")
5936         a=m1.keepCellIdsByType(NORM_TRI3,p2);
5937         self.assertEqual("p2",a.getName())
5938         self.assertEqual(1,a.getNumberOfComponents());
5939         self.assertEqual(2,a.getNumberOfTuples());
5940         self.assertEqual(2,a.getIJ(0,0));
5941         self.assertEqual(2,a.getIJ(1,0));
5942         #
5943         a=m1.keepCellIdsByType(NORM_QUAD4,p2);
5944         self.assertEqual("p2",a.getName())
5945         self.assertEqual(1,a.getNumberOfComponents());
5946         self.assertEqual(3,a.getNumberOfTuples());
5947         self.assertEqual(3,a.getIJ(0,0));
5948         self.assertEqual(0,a.getIJ(1,0));
5949         self.assertEqual(4,a.getIJ(2,0));
5950         pass
5951     
5952     def testSwigErrorDaIntSelectByTupleId1(self):
5953         a=DataArrayInt.New();
5954         arr1=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
5955         a.setValues(arr1,7,2);
5956         a.setInfoOnComponent(0,"toto");
5957         a.setInfoOnComponent(1,"tata");
5958         #
5959         arr2=[4,2,0,6,5]
5960         b=a.selectByTupleId(arr2);
5961         self.assertEqual(5,b.getNumberOfTuples());
5962         self.assertEqual(2,b.getNumberOfComponents());
5963         self.assertTrue(b.getInfoOnComponent(0)=="toto");
5964         self.assertTrue(b.getInfoOnComponent(1)=="tata");
5965         expected1=[5,15,3,13,1,11,7,17,6,16]
5966         self.assertEqual(expected1,b.getValues())
5967         #
5968         a2=DataArrayInt.New()
5969         a2.setValues(arr2,5,1)
5970         b=a.selectByTupleId(a2);
5971         self.assertEqual(5,b.getNumberOfTuples());
5972         self.assertEqual(2,b.getNumberOfComponents());
5973         self.assertTrue(b.getInfoOnComponent(0)=="toto");
5974         self.assertTrue(b.getInfoOnComponent(1)=="tata");
5975         expected1=[5,15,3,13,1,11,7,17,6,16]
5976         self.assertEqual(expected1,b.getValues())
5977         pass
5978
5979     def testSwigErrorRenum(self):
5980         da=DataArrayDouble.New()
5981         da.setValues([7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.],10,2)
5982         d=DataArrayInt.New()
5983         d.setValues([0,2,3,1,4,5,6,8,7,9],10,1)
5984         da.renumberInPlace(d)
5985         da.renumber(d)
5986         pass
5987
5988     def testSwigGetItem1(self):
5989         da=DataArrayInt.New()
5990         da.alloc(16,3)
5991         da.rearrange(1)
5992         da.iota(7)
5993         da.rearrange(3)
5994         da.setInfoOnComponent(0,"X [m]")
5995         da.setInfoOnComponent(1,"Y [m]")
5996         da.setInfoOnComponent(2,"Z [km]")
5997         da2=da[5:-1]
5998         self.assertEqual([22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51],da2.getValues())
5999         da2=da[4]
6000         self.assertEqual([19, 20, 21],da2.getValues())
6001         try:
6002             da2=da[4:17]
6003         except InterpKernelException as e:
6004             self.assertTrue(True)
6005         else:
6006             self.assertTrue(False)
6007             pass
6008         da2=da[5:-2,2]
6009         self.assertEqual([24, 27, 30, 33, 36, 39, 42, 45, 48],da2.getValues())
6010         da2=da[5:8,:]
6011         self.assertEqual([22, 23, 24, 25, 26, 27, 28, 29, 30],da2.getValues())
6012         da2=da[:]
6013         self.assertTrue(da2.isEqual(da))
6014         da2=da[:,:]
6015         self.assertTrue(da2.isEqual(da))
6016         try:
6017             da2=da[:,:,:]
6018         except InterpKernelException as e:
6019             self.assertTrue(True)
6020         else:
6021             self.assertTrue(False)
6022             pass
6023         try:
6024             da2=da[5:8,-2]
6025         except InterpKernelException as e:
6026             self.assertTrue(True)
6027         else:
6028             self.assertTrue(False)
6029             pass
6030         da2=da[5:8,:-2]
6031         self.assertEqual([22, 25, 28],da2.getValues())
6032         try:
6033             da2=da[5:-18,2]
6034         except InterpKernelException as e:
6035             self.assertTrue(True)
6036         else:
6037             self.assertTrue(False)
6038             pass
6039         da2=da[5:5,2]
6040         self.assertEqual([],da2.getValues())
6041         pass
6042
6043     def testSwigGetItem2(self):
6044         da=DataArrayDouble.New()
6045         da.alloc(16,3)
6046         da.rearrange(1)
6047         da.iota(7)
6048         da.rearrange(3)
6049         da.setInfoOnComponent(0,"X [m]")
6050         da.setInfoOnComponent(1,"Y [m]")
6051         da.setInfoOnComponent(2,"Z [km]")
6052         da2=da[5:-1]
6053         self.assertEqual([22., 23., 24., 25., 26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36., 37., 38., 39., 40., 41., 42., 43., 44., 45., 46., 47., 48., 49., 50., 51.],da2.getValues())
6054         da2=da[4]
6055         self.assertEqual([19., 20., 21],da2.getValues())
6056         try:
6057             da2=da[4:17]
6058         except InterpKernelException as e:
6059             self.assertTrue(True)
6060         else:
6061             self.assertTrue(False)
6062             pass
6063         da2=da[5:-2,2]
6064         self.assertEqual([24., 27., 30., 33., 36., 39., 42., 45., 48.],da2.getValues())
6065         da2=da[5:8,:]
6066         self.assertEqual([22., 23., 24., 25., 26., 27., 28., 29., 30.],da2.getValues())
6067         da2=da[:]
6068         self.assertTrue(da2.isEqual(da,1e-12))
6069         da2=da[:,:]
6070         self.assertTrue(da2.isEqual(da,1e-12))
6071         try:
6072             da2=da[:,:,:]
6073         except InterpKernelException as e:
6074             self.assertTrue(True)
6075         else:
6076             self.assertTrue(False)
6077             pass
6078         try:
6079             da2=da[5:8,-2]
6080         except InterpKernelException as e:
6081             self.assertTrue(True)
6082         else:
6083             self.assertTrue(False)
6084             pass
6085         da2=da[5:8,:-2]
6086         self.assertEqual([22., 25., 28.],da2.getValues())
6087         try:
6088             da2=da[5:-18,2]
6089         except InterpKernelException as e:
6090             self.assertTrue(True)
6091         else:
6092             self.assertTrue(False)
6093             pass
6094         da2=da[5:5,2]
6095         self.assertEqual([],da2.getValues())
6096         pass
6097
6098     def testSwigSetItem1(self):
6099         da=DataArrayInt.New()
6100         da.alloc(20,1)
6101         da.iota(7)
6102         da.rearrange(5)
6103         da.setInfoOnComponent(0,"X [m]") ; da.setInfoOnComponent(1,"Y [km]") ; da.setInfoOnComponent(2,"Y [m]")
6104         da.setInfoOnComponent(3,"Z [W]") ; da.setInfoOnComponent(4,"ZZ [km]") ; 
6105         da[:,2]=3
6106         self.assertEqual([7, 8, 3, 10, 11, 12, 13, 3, 15, 16, 17, 18, 3, 20, 21, 22, 23, 3, 25, 26],da.getValues())
6107         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6108         da[2]=3
6109         self.assertEqual([7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 3, 3, 3, 3, 3, 22, 23, 24, 25, 26],da.getValues())
6110         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6111         da[[0,3]]=-1
6112         self.assertEqual([-1, -1, -1, -1, -1, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, -1, -1, -1, -1, -1],da.getValues())
6113         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6114         da[:,[1,3,4]]=-3
6115         self.assertEqual([7, -3, 9, -3, -3, 12, -3, 14, -3, -3, 17, -3, 19, -3, -3, 22, -3, 24, -3, -3],da.getValues())
6116         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6117         da2=DataArrayInt.New() ; da2.setValues([0,2,3],3,1)
6118         da[da2]=-7
6119         self.assertEqual([-7, -7, -7, -7, -7, 12, 13, 14, 15, 16, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7],da.getValues())
6120         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6121         da[da2,-2:]=-7
6122         self.assertEqual([7, 8, 9, -7, -7, 12, 13, 14, 15, 16, 17, 18, 19, -7, -7, 22, 23, 24, -7, -7],da.getValues())
6123         # Let's test with DAI right hand side
6124         da1=DataArrayInt.New()
6125         da1.setValues([25,26,27,125,126,127],2,3)
6126         #
6127         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6128         da[-2:,1:4]=da1
6129         self.assertEqual([7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 25, 26, 27, 21, 22, 125, 126, 127, 26],da.getValues())
6130         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6131         da[1:,3]=[225,226,227]
6132         self.assertEqual([7, 8, 9, 10, 11, 12, 13, 14, 225, 16, 17, 18, 19, 226, 21, 22, 23, 24, 227, 26],da.getValues())
6133         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6134         da[1,2:]=[225,226,227]
6135         self.assertEqual([7, 8, 9, 10, 11, 12, 13, 225, 226, 227, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26],da.getValues())
6136         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6137         da[da2,-2:]=[88,99,1010,1111,1212,1313]
6138         self.assertEqual([7, 8, 9, 88, 99, 12, 13, 14, 15, 16, 17, 18, 19, 1010, 1111, 22, 23, 24, 1212, 1313],da.getValues())
6139         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6140         da3=DataArrayInt.New(); da3.setValues([88,99,1010,1111,1212,1313],3,2)
6141         da[da2,-2:]=da3
6142         self.assertEqual([7, 8, 9, 88, 99, 12, 13, 14, 15, 16, 17, 18, 19, 1010, 1111, 22, 23, 24, 1212, 1313],da.getValues())
6143         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6144         da[da2,[0,2]]=da3
6145         self.assertEqual([88, 8, 99, 10, 11, 12, 13, 14, 15, 16, 1010, 18, 1111, 20, 21, 1212, 23, 1313, 25, 26],da.getValues())
6146         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6147         da[da2,0:3:2]=da3
6148         self.assertEqual([88, 8, 99, 10, 11, 12, 13, 14, 15, 16, 1010, 18, 1111, 20, 21, 1212, 23, 1313, 25, 26],da.getValues())
6149         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6150         da[da2,0:3:2]=-8
6151         self.assertEqual([-8, 8, -8, 10, 11, 12, 13, 14, 15, 16, -8, 18, -8, 20, 21, -8, 23, -8, 25, 26],da.getValues())
6152         pass
6153
6154     def testSwigSetItem2(self):
6155         da=DataArrayDouble.New()
6156         da.alloc(20,1)
6157         da.iota(7)
6158         da.rearrange(5)
6159         da.setInfoOnComponent(0,"X [m]") ; da.setInfoOnComponent(1,"Y [km]") ; da.setInfoOnComponent(2,"Y [m]")
6160         da.setInfoOnComponent(3,"Z [W]") ; da.setInfoOnComponent(4,"ZZ [km]") ; 
6161         da[:,2]=3.
6162         self.assertEqual([7., 8., 3., 10., 11., 12., 13., 3., 15., 16., 17., 18., 3., 20., 21., 22., 23., 3., 25., 26.],da.getValues())
6163         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6164         da[2]=3.
6165         self.assertEqual([7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 3., 3., 3., 3., 3., 22., 23., 24., 25., 26.],da.getValues())
6166         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6167         da[[0,3]]=-1.
6168         self.assertEqual([-1., -1., -1., -1., -1., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., -1., -1., -1., -1., -1.],da.getValues())
6169         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6170         da[:,[1,3,4]]=-3.
6171         self.assertEqual([7., -3., 9., -3., -3., 12., -3., 14., -3., -3., 17., -3., 19., -3., -3., 22., -3., 24., -3., -3.],da.getValues())
6172         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6173         da2=DataArrayInt.New() ; da2.setValues([0,2,3],3,1)
6174         da[da2]=-7.
6175         self.assertEqual([-7., -7., -7., -7., -7., 12., 13., 14., 15., 16., -7., -7., -7., -7., -7., -7., -7., -7., -7., -7.],da.getValues())
6176         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6177         da[da2,-2:]=-7
6178         self.assertEqual([7., 8., 9., -7., -7., 12., 13., 14., 15., 16., 17., 18., 19., -7., -7., 22., 23., 24., -7., -7.],da.getValues())
6179         # Let's test with DAI right hand side
6180         da1=DataArrayDouble.New()
6181         da1.setValues([25,26,27,125,126,127],2,3)
6182         #
6183         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6184         da[-2:,1:4]=da1
6185         self.assertEqual([7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 25., 26., 27., 21., 22., 125., 126., 127., 26.],da.getValues())
6186         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6187         da[1:,3]=[225.,226.,227.]
6188         self.assertEqual([7., 8., 9., 10., 11., 12., 13., 14., 225., 16., 17., 18., 19., 226., 21., 22., 23., 24., 227., 26.],da.getValues())
6189         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6190         da[1,2:]=[225,226,227]
6191         self.assertEqual([7., 8., 9., 10., 11., 12., 13., 225., 226., 227., 17., 18., 19., 20., 21., 22., 23., 24., 25., 26.],da.getValues())
6192         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6193         da[da2,-2:]=[88,99,1010,1111,1212,1313]
6194         self.assertEqual([7., 8., 9., 88., 99., 12., 13., 14., 15., 16., 17., 18., 19., 1010., 1111., 22., 23., 24., 1212., 1313.],da.getValues())
6195         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6196         da3=DataArrayDouble.New(); da3.setValues([88,99,1010,1111,1212,1313],3,2)
6197         da[da2,-2:]=da3
6198         self.assertEqual([7., 8., 9., 88., 99., 12., 13., 14., 15., 16., 17., 18., 19., 1010., 1111., 22., 23., 24., 1212., 1313.],da.getValues())
6199         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6200         da[da2,[0,2]]=da3
6201         self.assertEqual([88., 8., 99., 10., 11., 12., 13., 14., 15., 16., 1010., 18., 1111., 20., 21., 1212., 23., 1313., 25., 26.],da.getValues())
6202         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6203         da[da2,0:3:2]=da3
6204         self.assertEqual([88., 8., 99., 10., 11., 12., 13., 14., 15., 16., 1010., 18., 1111., 20., 21., 1212., 23., 1313., 25., 26.],da.getValues())
6205         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6206         da[da2,0:3:2]=-8.
6207         self.assertEqual([-8., 8., -8., 10., 11., 12., 13., 14., 15., 16., -8., 18., -8., 20., 21., -8., 23., -8., 25., 26.],da.getValues())
6208         pass
6209
6210     def testSwigDADOp(self):
6211         da=DataArrayDouble.New()
6212         da.alloc(12,1)
6213         da.iota(7.)
6214         da1=DataArrayDouble.New()
6215         da1.alloc(12,1)
6216         da1.iota(8.)
6217         da2=da+da1
6218         self.assertEqual([15., 17., 19., 21., 23., 25., 27., 29., 31., 33., 35., 37.],da2.getValues())
6219         da2=da+3
6220         da3=3+da
6221         self.assertTrue(da2.isEqual(da3,1e-12))
6222         da2=da-1.
6223         self.assertEqual([6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0],da2.getValues())
6224         da2=1-da
6225         self.assertEqual([-6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0, -13.0, -14.0, -15.0, -16.0, -17.0],da2.getValues())
6226         da2=da*3
6227         self.assertEqual([21.0, 24.0, 27.0, 30.0, 33.0, 36.0, 39.0, 42.0, 45.0, 48.0, 51.0, 54.0],da2.getValues())
6228         da2=3.*da
6229         self.assertEqual([21.0, 24.0, 27.0, 30.0, 33.0, 36.0, 39.0, 42.0, 45.0, 48.0, 51.0, 54.0],da2.getValues())
6230         da2=da*da1
6231         self.assertEqual([56.0, 72.0, 90.0, 110.0, 132.0, 156.0, 182.0, 210.0, 240.0, 272.0, 306.0, 342.0],da2.getValues())
6232         da2=da/4.
6233         self.assertEqual([1.75, 2.0, 2.25, 2.5, 2.75, 3.0, 3.25, 3.5, 3.75, 4.0, 4.25, 4.5],da2.getValues())
6234         da3=4./da
6235         da4=da3*da2
6236         self.assertTrue(da4.isUniform(1.,1e-12))
6237         st1=da.getHiddenCppPointer()
6238         da+=1
6239         st2=da.getHiddenCppPointer()
6240         self.assertEqual(st1,st2)
6241         self.assertTrue(da.isEqual(da1,1e-12))
6242         da-=8
6243         st2=da.getHiddenCppPointer()
6244         self.assertEqual(st1,st2)
6245         self.assertEqual(range(12),da.getValues())
6246         da+=da1
6247         st2=da.getHiddenCppPointer()
6248         self.assertEqual(st1,st2)
6249         self.assertEqual([8.0, 10.0, 12.0, 14.0, 16.0, 18.0, 20.0, 22.0, 24.0, 26.0, 28.0, 30.0],da.getValues())
6250         da*=0.5
6251         st2=da.getHiddenCppPointer()
6252         self.assertEqual(st1,st2)
6253         self.assertEqual([4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0],da.getValues())
6254         da*=da1
6255         st2=da.getHiddenCppPointer()
6256         self.assertEqual(st1,st2)
6257         self.assertEqual([32.0, 45.0, 60.0, 77.0, 96.0, 117.0, 140.0, 165.0, 192.0, 221.0, 252.0, 285.0],da.getValues())
6258         da/=da1
6259         self.assertEqual(st1,st2)
6260         self.assertEqual([4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0],da.getValues())
6261         da/=2
6262         st2=da.getHiddenCppPointer()
6263         self.assertEqual(st1,st2)
6264         self.assertEqual([2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0, 7.5],da.getValues())
6265         da.rearrange(3)
6266         da5=DataArrayDouble.New()
6267         da5.setValues([5.,4.,3.,2.],4,1)
6268         da*=da5 # it works with unmathing number of compo
6269         st2=da.getHiddenCppPointer()
6270         self.assertEqual(st1,st2)
6271         self.assertEqual([10.0, 12.5, 15.0, 14.0, 16.0, 18.0, 15.0, 16.5, 18.0, 13.0, 14.0, 15.0],da.getValues())
6272         #
6273         da.alloc(30,1)
6274         da.iota(7.)
6275         da.rearrange(3)
6276         ids=DataArrayInt.New()
6277         ids.setValues([3,4,7],3,1)
6278         da[ids,:]=[5.,8.,9.]
6279         self.assertEqual([7.,8.,9.,10.,11.,12.,13.,14.,15.,5.,8.,9.,5.,8.,9.,22.,23.,24.,25.,26.,27.,5.,8.,9.,31.,32.,33.,34.,35.,36.0],da.getValues())
6280         #
6281         da.rearrange(1) ; da.iota(7) ; da.rearrange(3)
6282         da[ids,[1,2]]=[5,8]
6283         self.assertEqual([7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,5.,8.,19.,5.,8.,22.,23.,24.,25.,26.,27.,28.,5.,8.,31.,32.,33.,34.,35.,36.],da.getValues())
6284         pass
6285
6286     def testSwigDAIOp(self):
6287         da=DataArrayInt.New()
6288         da.alloc(12,1)
6289         da.iota(7)
6290         da1=DataArrayInt.New()
6291         da1.alloc(12,1)
6292         da1.iota(8)
6293         da2=da+da1
6294         self.assertEqual([15,17,19,21,23,25,27,29,31,33,35,37],da2.getValues())
6295         da2=da+3
6296         da3=3+da
6297         self.assertTrue(da2.isEqual(da3))
6298         da2=da-1
6299         self.assertEqual([6,7,8,9,10,11,12,13,14,15,16,17],da2.getValues())
6300         da2=1-da
6301         self.assertEqual([-6,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17],da2.getValues())
6302         da2=da*3
6303         self.assertEqual([21,24,27,30,33,36,39,42,45,48,51,54.0],da2.getValues())
6304         da2=3*da
6305         self.assertEqual([21,24,27,30,33,36,39,42,45,48,51,54.0],da2.getValues())
6306         da2=da*da1
6307         self.assertEqual([56,72,90,110,132,156,182,210,240,272,306,342.0],da2.getValues())
6308         da2=da/4
6309         self.assertEqual([1,2,2,2,2,3,3,3,3,4,4,4],da2.getValues())
6310         da3=4/da
6311         da4=da3*da2
6312         self.assertTrue(da4.isUniform(0))
6313         st1=da.getHiddenCppPointer()
6314         da+=1
6315         st2=da.getHiddenCppPointer()
6316         self.assertEqual(st1,st2)
6317         self.assertTrue(da.isEqual(da1))
6318         da-=8
6319         st2=da.getHiddenCppPointer()
6320         self.assertEqual(st1,st2)
6321         self.assertEqual(range(12),da.getValues())
6322         da+=da1
6323         st2=da.getHiddenCppPointer()
6324         self.assertEqual(st1,st2)
6325         self.assertEqual([8,10,12,14,16,18,20,22,24,26,28,30],da.getValues())
6326         da/=2
6327         st2=da.getHiddenCppPointer()
6328         self.assertEqual(st1,st2)
6329         self.assertEqual([4,5,6,7,8,9,10,11,12,13,14,15],da.getValues())
6330         da*=da1
6331         st2=da.getHiddenCppPointer()
6332         self.assertEqual(st1,st2)
6333         self.assertEqual([32,45,60,77,96,117,140,165,192,221,252,285],da.getValues())
6334         da/=da1
6335         self.assertEqual(st1,st2)
6336         self.assertEqual([4,5,6,7,8,9,10,11,12,13,14,15],da.getValues())
6337         da/=2
6338         st2=da.getHiddenCppPointer()
6339         self.assertEqual(st1,st2)
6340         self.assertEqual([2,2, 3,3, 4,4, 5,5, 6,6, 7,7],da.getValues())
6341         da.rearrange(3)
6342         da5=DataArrayInt.New()
6343         da5.setValues([5,4,3,2],4,1)
6344         da*=da5 # it works with unmathing number of compo
6345         st2=da.getHiddenCppPointer()
6346         self.assertEqual(st1,st2)
6347         self.assertEqual([10,10, 15,12,16,16,15,15, 18,12,14,14],da.getValues())
6348         da%=6
6349         st2=da.getHiddenCppPointer()
6350         self.assertEqual(st1,st2)
6351         self.assertEqual([4,4,3,0,4,4,3,3,0,0,2,2],da.getValues())
6352         #
6353         da.alloc(30,1)
6354         da.iota(7)
6355         da.rearrange(3)
6356         ids=DataArrayInt.New()
6357         ids.setValues([3,4,7],3,1)
6358         da[ids,:]=[5,8,9]
6359         self.assertEqual([7,8,9,10,11,12,13,14,15,5,8,9,5,8,9,22,23,24,25,26,27,5,8,9,31,32,33,34,35,36],da.getValues())
6360         #
6361         da.rearrange(1) ; da.iota(7) ; da.rearrange(3)
6362         da[ids,[1,2]]=[5,8]
6363         self.assertEqual([7,8,9,10,11,12,13,14,15,16,5,8,19,5,8,22,23,24,25,26,27,28,5,8,31,32,33,34,35,36],da.getValues())
6364         pass
6365
6366     def testSwigDAIOp2(self):
6367         da=DataArrayInt.New()
6368         st=da.getHiddenCppPointer()
6369         da.alloc(10,3)
6370         da.rearrange(1)
6371         da.iota(0)
6372         da.rearrange(3)
6373         da[:,1]+=4
6374         da[-2:,2]+=10
6375         da[-2:,2]+=10
6376         da[:,2]+=da[:,0]
6377         da[da[0],:]=7
6378         self.assertEqual(st,da.getHiddenCppPointer())
6379         self.assertEqual(da.getValues(),[7,7,7,3,8,8,7,7,7,9,14,20,12,17,26,7,7,7,18,23,38,21,26,44,24,29,70,27,32,76])
6380         pass
6381
6382     def testSwigDAIOp3(self):
6383         da=DataArrayInt.New()
6384         self.assertRaises(InterpKernelException,da.__len__)
6385         self.assertRaises(InterpKernelException,da.__int__)
6386         for elt in da:
6387             self.assertTrue(False)
6388             pass
6389         da.alloc(12,3)
6390         da.rearrange(1) ; da.fillWithZero()
6391         l1=list(da)
6392         self.assertEqual(36,len(da));
6393         da.rearrange(3)
6394         tmp=da[0]
6395         self.assertRaises(InterpKernelException,tmp.__int__)
6396         self.assertEqual(12,len(da));
6397         l=list(da)
6398         for elt in enumerate(l):
6399             elt[1][2]=elt[0]
6400             pass
6401         ref=[0,0,0,0,0,1,0,0,2,0,0,3,0,0,4,0,0,5,0,0,6,0,0,7,0,0,8,0,0,9,0,0,10,0,0,11]
6402         self.assertEqual(ref,da.getValues());
6403         da.rearrange(1)
6404         l=[int(elt) for elt in l1]
6405         self.assertEqual(ref,da.getValues());
6406         self.assertEqual(11,int(da[-1:]))
6407         pass
6408
6409     def testSwigDADOp3(self):
6410         da=DataArrayDouble.New()
6411         self.assertRaises(InterpKernelException,da.__len__)
6412         self.assertRaises(InterpKernelException,da.__float__)
6413         for elt in da:
6414             self.assertTrue(False)
6415             pass
6416         da.alloc(12,3)
6417         da.rearrange(1) ; da.fillWithZero()
6418         l1=list(da)
6419         self.assertEqual(36,len(da));
6420         da.rearrange(3)
6421         tmp=da[0]
6422         self.assertRaises(InterpKernelException,tmp.__float__)
6423         self.assertEqual(12,len(da));
6424         l=list(da)
6425         for elt in enumerate(l):
6426             elt[1][2]=elt[0]
6427             pass
6428         ref=[0.,0.,0.,0.,0.,1.,0.,0.,2.,0.,0.,3.,0.,0.,4.,0.,0.,5.,0.,0.,6.,0.,0.,7.,0.,0.,8.,0.,0.,9.,0.,0.,10.,0.,0.,11.]
6429         self.assertEqual(ref,da.getValues());
6430         da.rearrange(1)
6431         l=[float(elt) for elt in l1]
6432         self.assertEqual(ref,da.getValues());
6433         self.assertEqual(11.,float(da[-1:]))
6434         pass
6435
6436     def testSwigDataArrayIntIterator1(self):
6437         da=DataArrayInt.New()
6438         da.alloc(12,1)
6439         da.iota(2)
6440         da.rearrange(3)
6441         # __getitem__ testing
6442         li=[]
6443         for it in da:
6444             li+=it[1:]
6445             pass
6446         self.assertEqual([3, 4, 6, 7, 9, 10, 12, 13],li)
6447         li=[]
6448         for it in da:
6449             li+=[it[-1]]
6450             pass
6451         self.assertEqual([4, 7, 10, 13],li)
6452         li=[]
6453         for it in da:
6454             li+=it[[2,1,0]]
6455             pass
6456         self.assertEqual([4, 3, 2, 7, 6, 5, 10, 9, 8, 13, 12, 11],li)
6457         # __setitem__ testing
6458         da3=da.deepCpy()
6459         da2=DataArrayInt.New()
6460         da2.alloc(12,1)
6461         da2.iota(2002)
6462         da2.rearrange(3)
6463         it2=da2.__iter__()
6464         i=0
6465         for it in da:
6466             pt=it2.next()
6467             it[:]=pt
6468             pass
6469         self.assertTrue(da.isEqual(da2))
6470         da=da3
6471         da3=da.deepCpy()
6472         #
6473         for it in da:
6474             it[:]=5
6475             pass
6476         da.rearrange(1)
6477         self.assertTrue(da.isUniform(5))
6478         da=da3
6479         da3=da.deepCpy()
6480         #
6481         for it in da:
6482             it[:]=[8,9,12]
6483             pass
6484         self.assertEqual([8, 9, 12, 8, 9, 12, 8, 9, 12, 8, 9, 12],da.getValues())
6485         da=da3
6486         da3=da.deepCpy()
6487         #
6488         for it in da:
6489             it[2]=[7]
6490             pass
6491         self.assertEqual([2, 3, 7, 5, 6, 7, 8, 9, 7, 11, 12, 7],da.getValues())
6492         pass
6493
6494     def testSwigDataArrayDoubleIterator1(self):
6495         da=DataArrayDouble.New()
6496         da.alloc(12,1)
6497         da.iota(2)
6498         da.rearrange(3)
6499         # __getitem__ testing
6500         li=[]
6501         for it in da:
6502             li+=it[1:]
6503             pass
6504         self.assertEqual([3, 4, 6, 7, 9, 10, 12, 13],li)
6505         li=[]
6506         for it in da:
6507             li+=[it[-1]]
6508             pass
6509         self.assertEqual([4, 7, 10, 13],li)
6510         li=[]
6511         for it in da:
6512             li+=it[[2,1,0]]
6513             pass
6514         self.assertEqual([4, 3, 2, 7, 6, 5, 10, 9, 8, 13, 12, 11],li)
6515         # __setitem__ testing
6516         da3=da.deepCpy()
6517         da2=DataArrayDouble.New()
6518         da2.alloc(12,1)
6519         da2.iota(2002)
6520         da2.rearrange(3)
6521         it2=da2.__iter__()
6522         i=0
6523         for it in da:
6524             pt=it2.next()
6525             it[:]=pt
6526             pass
6527         self.assertTrue(da.isEqual(da2,1e-12))
6528         da=da3
6529         da3=da.deepCpy()
6530         #
6531         for it in da:
6532             it[:]=5
6533             pass
6534         da.rearrange(1)
6535         self.assertTrue(da.isUniform(5,1e-12))
6536         da=da3
6537         da3=da.deepCpy()
6538         #
6539         for it in da:
6540             it[:]=[8,9,12]
6541             pass
6542         self.assertEqual([8, 9, 12, 8, 9, 12, 8, 9, 12, 8, 9, 12],da.getValues())
6543         da=da3
6544         da3=da.deepCpy()
6545         #
6546         for it in da:
6547             it[2]=[7]
6548             pass
6549         self.assertEqual([2, 3, 7, 5, 6, 7, 8, 9, 7, 11, 12, 7],da.getValues())
6550         pass
6551
6552     def testSwigUMeshIterator1(self):
6553         m=MEDCouplingDataForTest.build2DTargetMesh_1()
6554         li1=[]
6555         li2=[]
6556         for cell in m:
6557             li1+=cell.getAllConn()[1:]
6558             li2+=[cell.getType()]
6559             pass
6560         self.assertEqual(li1,[0, 3, 4, 1, 1, 4, 2, 4, 5, 2, 6, 7, 4, 3, 7, 8, 5, 4])
6561         self.assertEqual(li2,[4, 3, 3, 4, 4])
6562         pass
6563
6564     def testSwigUMeshIterator2(self):
6565         m=MEDCouplingDataForTest.build2DTargetMesh_1()
6566         self.assertRaises(InterpKernelException,m.cellsByType);
6567         m.rearrange2ConsecutiveCellTypes()
6568         li1=[]
6569         li2=[]
6570         li3=[]
6571         for cellsByType in m.cellsByType():
6572             li1.append(cellsByType.getType())
6573             li2.append(cellsByType.getNumberOfElems())
6574             temp=[]
6575             for cell in cellsByType:
6576                 t=[None,None]
6577                 t[0]=cell.getType()
6578                 t[1]=cell.getAllConn()[1:]
6579                 temp.append(t)
6580                 pass
6581             li3.append(temp)
6582             pass
6583         self.assertEqual(li1,[4, 3])
6584         self.assertEqual(li2,[3, 2])
6585         self.assertEqual(li3,[[[4, (0, 3, 4, 1)], [4, (6, 7, 4, 3)], [4, (7, 8, 5, 4)]], [[3, (1, 4, 2)], [3, (4, 5, 2)]]])
6586         pass
6587
6588     def testDAIAggregateMulti1(self):
6589         a=DataArrayInt.New()
6590         a.setValues(range(4),2,2)
6591         a.setName("aa")
6592         b=DataArrayInt.New()
6593         b.setValues(range(6),3,2)
6594         c=DataArrayInt.Aggregate([a,b])
6595         self.assertEqual(range(4)+range(6),c.getValues())
6596         self.assertEqual("aa",c.getName())
6597         self.assertEqual(5,c.getNumberOfTuples())
6598         self.assertEqual(2,c.getNumberOfComponents())
6599         pass
6600
6601     def testMergeUMeshes2(self):
6602         m1=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
6603         m2=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
6604         m3=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
6605         #
6606         vec1=[0,2,3]
6607         m2_2=m2.buildPartOfMySelf(vec1,False);
6608         vec2=[1,1]
6609         m3_2=m3.buildPartOfMySelf(vec2,False);
6610         #
6611         ms=[m1,m2_2,m3_2];
6612         #
6613         self.assertRaises(InterpKernelException,MEDCouplingUMesh.MergeUMeshes,ms+[None]);
6614         self.assertRaises(InterpKernelException,MEDCouplingUMesh.MergeUMeshes,ms+[3.4])
6615         m4=MEDCouplingUMesh.MergeUMeshes(ms);
6616         m4.checkCoherency();
6617         self.assertEqual(10,m4.getNumberOfCells());
6618         self.assertEqual(20,m4.getNumberOfNodes());
6619         self.assertEqual(45,m4.getMeshLength());
6620         m4bis=MEDCouplingMesh.MergeMeshes(ms);
6621         self.assertTrue(m4.isEqual(m4bis,1e-12))
6622         del m4bis
6623         #
6624         vec3=[0,1,2,3,4]
6625         m4_1=m4.buildPartOfMySelf(vec3,False);
6626         m4_1.setName(m1.getName());
6627         self.assertTrue(m4_1.isEqual(m1,1e-12));
6628         #
6629         vec4=[5,6,7]
6630         m4_2=m4.buildPartOfMySelf(vec4,False);
6631         cellCor,nodeCor=m4_2.checkGeoEquivalWith(m2_2,10,1e-12);
6632         #
6633         vec5=[8,9]
6634         m4_3=m4.buildPartOfMySelf(vec5,False);
6635         self.assertEqual(2,m4_3.getNumberOfCells());
6636         self.assertEqual(3,m4_3.getNumberOfNodes());
6637         m3_2.zipCoords();
6638         m4_3.setName(m3_2.getName());
6639         self.assertTrue(m4_3.isEqual(m3_2,1e-12));
6640         #
6641         pass
6642
6643     def testBuild0DMeshFromCoords1(self):
6644         sourceCoords=[-0.3,-0.3,0., 0.7,-0.3,0., -0.3,0.7,0., 0.7,0.7,0.]
6645         coo=DataArrayDouble.New();
6646         coo.setValues(sourceCoords,4,3);
6647         coo.setName("My0D");
6648         m=MEDCouplingUMesh.Build0DMeshFromCoords(coo);
6649         m.checkCoherency();
6650         self.assertEqual(4,m.getNumberOfNodes());
6651         self.assertEqual(4,m.getNumberOfCells());
6652         self.assertEqual(3,m.getSpaceDimension());
6653         self.assertEqual(0,m.getMeshDimension());
6654         types1=m.getAllGeoTypes();
6655         self.assertEqual([NORM_POINT1],types1);
6656         for i in xrange(4):
6657             conn=m.getNodeIdsOfCell(i);
6658             self.assertEqual([i],conn);
6659             self.assertTrue(NORM_POINT1==m.getTypeOfCell(i));
6660             pass
6661         self.assertEqual(m.getName(),"My0D");
6662         pass
6663
6664     def testDescriptionInMeshTimeUnit1(self):
6665         text1="totoTTEDD";
6666         m=MEDCouplingDataForTest.build2DTargetMesh_1();
6667         m.setDescription(text1);
6668         self.assertEqual(m.getDescription(),text1);
6669         m2=m.deepCpy();
6670         self.assertTrue(m.isEqual(m2,1e-12));
6671         self.assertEqual(m2.getDescription(),text1);
6672         m2.setDescription("ggg");
6673         self.assertTrue(not m.isEqual(m2,1e-12));
6674         #
6675         f=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
6676         f.setTimeUnit(text1);
6677         self.assertEqual(f.getTimeUnit(),text1);
6678         f2=f.deepCpy();
6679         self.assertEqual(f2.getTimeUnit(),text1);
6680         #
6681         pass
6682
6683     def testMultiFields1(self):
6684         mfs=MEDCouplingDataForTest.buildMultiFields_1();
6685         ms=mfs.getMeshes();
6686         dms,refs=mfs.getDifferentMeshes()
6687         das=mfs.getArrays();
6688         das2,refs2=mfs.getDifferentArrays()
6689         self.assertEqual(5,len(mfs.getFields()))
6690         self.assertEqual(1,len(mfs.getFields()[0].getArrays()));
6691         self.assertEqual(2,len(mfs.getFields()[1].getArrays()));
6692         self.assertEqual(1,len(mfs.getFields()[2].getArrays()));
6693         self.assertEqual(1,len(mfs.getFields()[3].getArrays()));
6694         self.assertEqual(1,len(mfs.getFields()[4].getArrays()));
6695         self.assertEqual(5,len(ms));
6696         self.assertEqual(2,len(dms));
6697         self.assertEqual(6,len(das));
6698         self.assertEqual(5,len(das2));
6699         mfs2=mfs.deepCpy();
6700         self.assertTrue(mfs.isEqual(mfs2,1e-12,1e-12))
6701         pass
6702
6703     def testFieldOverTime1(self):
6704         fs=MEDCouplingDataForTest.buildMultiFields_2();
6705         self.assertRaises(InterpKernelException,MEDCouplingFieldOverTime.New,fs);
6706         f4bis=fs[4].buildNewTimeReprFromThis(ONE_TIME,False);
6707         fs[4]=f4bis;
6708         self.assertRaises(InterpKernelException,MEDCouplingFieldOverTime.New,fs);
6709         f4bis.setTime(2.7,20,21);
6710         fot=MEDCouplingFieldOverTime.New(fs);
6711         dt=fot.getDefinitionTimeZone();
6712         hs=dt.getHotSpotsTime();
6713         self.assertEqual(6,len(hs));
6714         expected1=[0.2,0.7,1.2,1.35,1.7,2.7]
6715         for i in xrange(6):
6716             self.assertAlmostEqual(expected1[i],hs[i],12);
6717             pass
6718         meshId,arrId,arrIdInField,fieldId=dt.getIdsOnTimeRight(0.2);
6719         self.assertEqual(0,meshId);
6720         self.assertEqual(0,arrId);
6721         self.assertEqual(0,arrIdInField);
6722         self.assertEqual(0,fieldId);
6723         #
6724         meshId,arrId,arrIdInField,fieldId=dt.getIdsOnTimeRight(0.7);
6725         self.assertEqual(0,meshId);
6726         self.assertEqual(1,arrId);
6727         self.assertEqual(0,arrIdInField);
6728         self.assertEqual(1,fieldId);
6729         #
6730         meshId,arrId,arrIdInField,fieldId=dt.getIdsOnTimeLeft(1.2);#**** WARNING left here
6731         self.assertEqual(0,meshId);
6732         self.assertEqual(2,arrId);
6733         self.assertEqual(1,arrIdInField);
6734         self.assertEqual(1,fieldId);
6735         #
6736         meshId,arrId,arrIdInField,fieldId=dt.getIdsOnTimeRight(1.2);#**** WARNING right again here
6737         self.assertEqual(1,meshId);
6738         self.assertEqual(3,arrId);
6739         self.assertEqual(0,arrIdInField);
6740         self.assertEqual(2,fieldId);
6741         #
6742         meshId,arrId,arrIdInField,fieldId=dt.getIdsOnTimeRight(1.35);
6743         self.assertEqual(1,meshId);
6744         self.assertEqual(3,arrId);
6745         self.assertEqual(0,arrIdInField);
6746         self.assertEqual(2,fieldId);
6747         #
6748         meshId,arrId,arrIdInField,fieldId=dt.getIdsOnTimeRight(1.7);
6749         self.assertEqual(0,meshId);
6750         self.assertEqual(3,arrId);
6751         self.assertEqual(0,arrIdInField);
6752         self.assertEqual(3,fieldId);
6753         #
6754         meshId,arrId,arrIdInField,fieldId=dt.getIdsOnTimeRight(2.7);
6755         self.assertEqual(1,meshId);
6756         self.assertEqual(4,arrId);
6757         self.assertEqual(0,arrIdInField);
6758         self.assertEqual(4,fieldId);
6759         #
6760         dt2=MEDCouplingDefinitionTime();
6761         self.assertTrue(not dt2.isEqual(dt));
6762         dt2.assign(dt);
6763         dt2.assign(dt);#to check memory management
6764         self.assertTrue(dt2.isEqual(dt));
6765         #
6766         dt3=MEDCouplingDefinitionTime();
6767         #
6768         pass
6769
6770     def testDAICheckAndPreparePermutation1(self):
6771         vals1=[9,10,0,6,4,11,3,7];
6772         expect1=[5,6,0,3,2,7,1,4];
6773         vals2=[9,10,0,6,10,11,3,7];
6774         da=DataArrayInt.New();
6775         da.setValues(vals1,8,1);
6776         da2=da.checkAndPreparePermutation();
6777         self.assertEqual(8,da2.getNumberOfTuples());
6778         self.assertEqual(1,da2.getNumberOfComponents());
6779         for i in xrange(8):
6780             self.assertEqual(expect1[i],da2.getIJ(i,0));
6781             pass
6782         #
6783         da=DataArrayInt.New();
6784         da.alloc(8,1);
6785         da.iota(0);
6786         da2=da.checkAndPreparePermutation();
6787         self.assertEqual(8,da2.getNumberOfTuples());
6788         self.assertEqual(1,da2.getNumberOfComponents());
6789         self.assertTrue(da2.isIdentity());
6790         #
6791         da=DataArrayInt.New();
6792         da.alloc(8,1);
6793         da.setValues(vals2,8,1);
6794         self.assertRaises(InterpKernelException,da.checkAndPreparePermutation);
6795         pass
6796
6797     def testDAIChangeSurjectiveFormat1(self):
6798         vals1=[0,3,2,3,2,2,1,2]
6799         expected1=[0,1,2,6,8]
6800         expected2=[0,  6,  2,4,5,7,  1,3]
6801         da=DataArrayInt.New();
6802         da.setValues(vals1,8,1);
6803         #
6804         da2,da2I=da.changeSurjectiveFormat(4);
6805         self.assertEqual(5,da2I.getNumberOfTuples());
6806         self.assertEqual(8,da2.getNumberOfTuples());
6807         self.assertEqual(expected1,da2I.getValues());
6808         self.assertEqual(expected2,da2.getValues());
6809         #
6810         self.assertRaises(InterpKernelException,da.changeSurjectiveFormat,3);
6811         #
6812         pass
6813
6814     def testUMeshGetCellIdsLyingOnNodes1(self):
6815         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
6816         nodeIds1=[1,2,3,4,6]
6817         nodeIds2=[6,7]
6818         da=m.getCellIdsLyingOnNodes(nodeIds1,True);
6819         self.assertEqual(1,da.getNumberOfTuples());
6820         self.assertEqual(1,da.getNumberOfComponents());
6821         self.assertEqual(1,da.getIJ(0,0));
6822         da2=DataArrayInt.New()
6823         da2.setValues(nodeIds2,2,1)
6824         da=m.getCellIdsLyingOnNodes(da2,False);
6825         self.assertEqual(2,da.getNumberOfTuples());
6826         self.assertEqual(1,da.getNumberOfComponents());
6827         self.assertEqual(3,da.getIJ(0,0));
6828         self.assertEqual(4,da.getIJ(1,0));
6829         pass
6830
6831     def testUMeshFindCellIdsOnBoundary1(self):
6832         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
6833         da5=m.findCellIdsOnBoundary();
6834         self.assertEqual(5,da5.getNumberOfTuples());
6835         self.assertTrue(da5.isIdentity());
6836         pass
6837
6838     def testMeshSetTime1(self):
6839         m1=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
6840         m2=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
6841         #
6842         self.assertTrue(m1.isEqual(m2,1e-12));
6843         m1.setTime(3.14,6,7);
6844         tmp3,tmp1,tmp2=m1.getTime();
6845         self.assertEqual(6,tmp1);
6846         self.assertEqual(7,tmp2);
6847         self.assertAlmostEqual(3.14,tmp3,12);
6848         self.assertTrue(not m1.isEqual(m2,1e-12));
6849         m2.setTime(3.14,6,7);
6850         self.assertTrue(m1.isEqual(m2,1e-12));
6851         m1.setTimeUnit("ms");
6852         self.assertTrue(m1.getTimeUnit()=="ms");
6853         m1.setTimeUnit("us");
6854         self.assertTrue(m1.getTimeUnit()=="us");
6855         self.assertTrue(not m1.isEqual(m2,1e-12));
6856         m2.setTimeUnit("us");
6857         self.assertTrue(m1.isEqual(m2,1e-12));
6858         m2.setTime(3.14,6,8);
6859         self.assertTrue(not m1.isEqual(m2,1e-12));
6860         m2.setTime(3.14,7,7);
6861         self.assertTrue(not m1.isEqual(m2,1e-12));
6862         m2.setTime(3.15,6,7);
6863         self.assertTrue(not m1.isEqual(m2,1e-12));
6864         #
6865         m1.setTime(10.34,55,12);
6866         m3=m1.deepCpy();
6867         self.assertTrue(m1.isEqual(m3,1e-12));
6868         tmp3,tmp1,tmp2=m3.getTime();
6869         self.assertEqual(55,tmp1);
6870         self.assertEqual(12,tmp2);
6871         self.assertAlmostEqual(10.34,tmp3,12);
6872         #
6873         # testing CMesh
6874         coo1=[0.,1.,2.,3.5]
6875         a=DataArrayDouble.New();
6876         a.setValues(coo1,4,1);
6877         b=MEDCouplingCMesh.New();
6878         b.setCoordsAt(0,a);
6879         #
6880         b.setTime(5.67,8,100);
6881         tmp3,tmp1,tmp2=b.getTime();
6882         self.assertEqual(8,tmp1);
6883         self.assertEqual(100,tmp2);
6884         self.assertAlmostEqual(5.67,tmp3,12);
6885         c=b.deepCpy();
6886         self.assertTrue(c.isEqual(b,1e-12));
6887         tmp3,tmp1,tmp2=c.getTime();
6888         self.assertEqual(8,tmp1);
6889         self.assertEqual(100,tmp2);
6890         self.assertAlmostEqual(5.67,tmp3,12);
6891         pass
6892
6893     def testApplyFuncTwo1(self):
6894         m1=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
6895         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
6896         f1.setMesh(m1);
6897         #
6898         vals=[1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.,5.,15.,25.]
6899         da=DataArrayDouble.New();
6900         da.setValues(vals,5,3);
6901         f1.setArray(da);
6902         #
6903         self.assertRaises(InterpKernelException,da.applyFunc2,1,"y+z");
6904         da.setInfoOnComponent(0,"x [m]");
6905         da.setInfoOnComponent(1,"y [mm]");
6906         da.setInfoOnComponent(2,"z [km]");
6907         
6908         self.assertRaises(InterpKernelException, da.applyFunc2, 1, "x+y+zz+zzz");
6909         self.assertRaises(InterpKernelException, da.applyFunc2, 1, "toto(x+y)");
6910         self.assertRaises(InterpKernelException, da.applyFunc2, 1, "x/0");
6911         
6912         da2=da.applyFunc2(1,"y+z");
6913         self.assertEqual(1,da2.getNumberOfComponents());
6914         self.assertEqual(5,da2.getNumberOfTuples());
6915         expected1=[32.,34.,36.,38.,40.]
6916         for i in xrange(5):
6917             self.assertAlmostEqual(expected1[i],da2.getIJ(0,i),12);
6918             pass
6919         da2=da.applyFunc(1,"y+z");
6920         expected2=[12.,14.,16.,18.,20.]
6921         for i in xrange(5):
6922             self.assertAlmostEqual(expected2[i],da2.getIJ(0,i),12);
6923             pass
6924         #
6925         self.assertEqual(3,f1.getNumberOfComponents());
6926         self.assertEqual(5,f1.getNumberOfTuples());
6927         f1.applyFunc2(1,"y+z");
6928         self.assertEqual(1,f1.getNumberOfComponents());
6929         self.assertEqual(5,f1.getNumberOfTuples());
6930         for i in xrange(5):
6931             self.assertAlmostEqual(expected1[i],f1.getArray().getIJ(0,i),12);
6932             pass
6933         #
6934         pass
6935
6936     def testApplyFuncThree1(self):
6937         m1=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
6938         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
6939         f1.setMesh(m1);
6940         #
6941         vals=[1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.,5.,15.,25.]
6942         da=DataArrayDouble.New();
6943         da.setValues(vals,5,3);
6944         f1.setArray(da);
6945         #
6946         vs=3*[None];
6947         vs[0]="x"; vs[1]="Y"; vs[2]="z";
6948         self.assertRaises(InterpKernelException, da.applyFunc3, 1, vs, "y+z");
6949         self.assertRaises(InterpKernelException, da.applyFunc3, 1, vs, "x+Y+z+zz+zzz");
6950         self.assertRaises(InterpKernelException, da.applyFunc3, 1, vs, "x/0");
6951         vs[1]="y";
6952         da2=da.applyFunc3(1,vs,"y+z");
6953         expected1=[32.,34.,36.,38.,40.]
6954         for i in xrange(5):
6955             self.assertAlmostEqual(expected1[i],da2.getIJ(0,i),12);
6956             pass
6957         self.assertRaises(InterpKernelException, da.applyFunc3, 1, ["x","y","z","a"],"x+a")
6958         f1.setArray(da);
6959         self.assertEqual(3,f1.getNumberOfComponents());
6960         self.assertEqual(5,f1.getNumberOfTuples());
6961         f1.applyFunc3(1,vs,"y+z");
6962         self.assertEqual(1,f1.getNumberOfComponents());
6963         self.assertEqual(5,f1.getNumberOfTuples());
6964         for i in xrange(5):
6965             self.assertAlmostEqual(expected1[i],f1.getArray().getIJ(0,i),12);
6966             pass
6967         pass
6968
6969     def testFillFromAnalyticTwo1(self):
6970         m1=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
6971         m1.setTime(3.4,5,6); m1.setTimeUnit("us");
6972         self.assertRaises(InterpKernelException,m1.fillFromAnalytic2,ON_NODES,1,"y+z");
6973         m1.getCoords().setInfoOnComponent(0,"x [m]");
6974         m1.getCoords().setInfoOnComponent(1,"y");
6975         m1.getCoords().setInfoOnComponent(2,"z");
6976         f1=m1.fillFromAnalytic2(ON_NODES,1,"y+z");
6977         self.assertAlmostEqual(3.4,f1.getTime()[0],12) ; self.assertEqual(5,f1.getTime()[1]) ; self.assertEqual(6,f1.getTime()[2])
6978         self.assertEqual("us",f1.getTimeUnit())
6979         self.assertEqual(1,f1.getNumberOfComponents());
6980         self.assertEqual(9,f1.getNumberOfTuples());
6981         expected1=[0.2, 0.7, 1.2, 0.7, 1.2, 1.7, 1.2, 1.7, 2.2]
6982         for i in xrange(9):
6983             self.assertAlmostEqual(expected1[i],f1.getArray().getIJ(0,i),12);
6984             pass
6985         pass
6986
6987     def testFillFromAnalyticThree1(self):
6988         m1=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
6989         m1.setTime(3.4,5,6); m1.setTimeUnit("us");
6990         vs=3*[None];
6991         vs[0]="x"; vs[1]="Y"; vs[2]="z";
6992         self.assertRaises(InterpKernelException,m1.fillFromAnalytic3,ON_NODES,1,vs,"y+z");
6993         vs[1]="y";
6994         f1=m1.fillFromAnalytic3(ON_NODES,1,vs,"y+z");
6995         self.assertAlmostEqual(3.4,f1.getTime()[0],12) ; self.assertEqual(5,f1.getTime()[1]) ; self.assertEqual(6,f1.getTime()[2])
6996         self.assertEqual("us",f1.getTimeUnit())
6997         self.assertEqual(1,f1.getNumberOfComponents());
6998         self.assertEqual(9,f1.getNumberOfTuples());
6999         expected1=[0.2, 0.7, 1.2, 0.7, 1.2, 1.7, 1.2, 1.7, 2.2]
7000         for i in xrange(9):
7001             self.assertAlmostEqual(expected1[i],f1.getArray().getIJ(0,i),12);
7002             pass
7003         pass
7004
7005     def testDAUnitVar1(self):
7006         da=DataArrayDouble.New();
7007         da.alloc(1,3);
7008         da.setInfoOnComponent(0,"XPS [m]");
7009         st1=da.getVarOnComponent(0);
7010         self.assertTrue(st1=="XPS");
7011         st2=da.getUnitOnComponent(0);
7012         self.assertTrue(st2=="m");
7013         #
7014         da.setInfoOnComponent(0,"XPS         [m]");
7015         st1=da.getVarOnComponent(0);
7016         self.assertTrue(st1=="XPS");
7017         st2=da.getUnitOnComponent(0);
7018         self.assertTrue(st2=="m");
7019         #
7020         da.setInfoOnComponent(0,"XPP         [m]");
7021         st1=da.getVarOnComponent(0);
7022         self.assertTrue(st1=="XPP");
7023         st2=da.getUnitOnComponent(0);
7024         self.assertTrue(st2=="m");
7025         #
7026         da.setInfoOnComponent(0,"XPP kdep  kefer   [ m  ]");
7027         st1=da.getVarOnComponent(0);
7028         self.assertTrue(st1=="XPP kdep  kefer");
7029         st2=da.getUnitOnComponent(0);
7030         self.assertTrue(st2==" m  ");
7031         #
7032         da.setInfoOnComponent(0,"     XPP k[  dep  k]efer   [ m^ 2/s^3*kJ  ]");
7033         st1=da.getVarOnComponent(0);
7034         self.assertTrue(st1=="     XPP k[  dep  k]efer");
7035         st2=da.getUnitOnComponent(0);
7036         self.assertTrue(st2==" m^ 2/s^3*kJ  ");
7037         #
7038         da.setInfoOnComponent(0,"     XPP kefer   ");
7039         st1=da.getVarOnComponent(0);
7040         self.assertTrue(st1=="     XPP kefer   ");
7041         st2=da.getUnitOnComponent(0);
7042         self.assertTrue(st2=="");
7043         #
7044         da.setInfoOnComponent(0,"temperature( bof)");
7045         st1=da.getVarOnComponent(0);
7046         self.assertTrue(st1=="temperature( bof)");
7047         st2=da.getUnitOnComponent(0);
7048         self.assertTrue(st2=="");
7049         #
7050         da.setInfoOnComponent(0,"kkk [m]");
7051         da.setInfoOnComponent(1,"ppp   [m^2/kJ]");
7052         da.setInfoOnComponent(2,"abcde   [MW/s]");
7053         #
7054         vs=da.getVarsOnComponent();
7055         self.assertEqual(3,len(vs));
7056         self.assertTrue(vs[0]=="kkk");
7057         self.assertTrue(vs[1]=="ppp");
7058         self.assertTrue(vs[2]=="abcde");
7059         vs=da.getUnitsOnComponent();
7060         self.assertEqual(3,len(vs));
7061         self.assertTrue(vs[0]=="m");
7062         self.assertTrue(vs[1]=="m^2/kJ");
7063         self.assertTrue(vs[2]=="MW/s");
7064         pass
7065
7066     def testGaussCoordinates1(self):
7067         #Testing 1D cell types
7068         m1=MEDCouplingDataForTest.build1DMultiTypes_1();
7069         f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME);
7070         f.setMesh(m1);
7071         wg1=[0.3];
7072         gsCoo1=[0.2];
7073         refCoo1=[-1.0,1.0];
7074         f.setGaussLocalizationOnType(NORM_SEG2,refCoo1,gsCoo1,wg1);
7075         wg2=wg1;
7076         gsCoo2=[0.2];
7077         refCoo2=[-1.0,1.0,0.0];
7078         f.setGaussLocalizationOnType(NORM_SEG3,refCoo2,gsCoo2,wg2);
7079         #
7080         resToTest=f.getLocalizationOfDiscr();
7081         self.assertEqual(3,resToTest.getNumberOfComponents());
7082         self.assertEqual(2,resToTest.getNumberOfTuples());
7083         expected1=[0.6,0.6,0.6, 0.6,0.6,0.6]
7084         for i in xrange(6):
7085             self.assertAlmostEqual(expected1[i],resToTest.getIJ(0,i),14);
7086             pass
7087         #
7088         #Testing 2D cell types
7089         m2=MEDCouplingDataForTest.build2DMultiTypes_1();
7090         f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME);
7091         f.setMesh(m2);
7092         wg3=[0.3,0.3];
7093         tria3CooGauss=[ 0.1, 0.8, 0.2, 0.7 ]
7094         gsCoo3=tria3CooGauss
7095         tria3CooRef=[ 0.0, 0.0, 1.0 , 0.0, 0.0, 1.0 ]
7096         refCoo3=tria3CooRef;
7097         f.setGaussLocalizationOnType(NORM_TRI3,refCoo3,gsCoo3,wg3);
7098         wg4=[0.3,0.3,0.3];
7099         tria6CooGauss=[ 0.3, 0.2, 0.2, 0.1, 0.2, 0.4 ]
7100         gsCoo4=tria6CooGauss;
7101         tria6CooRef=[0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0, 0.5, 0.5, 0.0, 0.5]
7102         refCoo4=tria6CooRef;
7103         f.setGaussLocalizationOnType(NORM_TRI6,refCoo4,gsCoo4,wg4);
7104         wg5=[0.3,0.3,0.3,0.3];
7105         quad4CooGauss=[ 0.3, 0.2, 0.2, 0.1, 0.2, 0.4, 0.15, 0.27 ]
7106         gsCoo5=quad4CooGauss;
7107         quad4CooRef=[-1.0, 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0]
7108         refCoo5=quad4CooRef;
7109         f.setGaussLocalizationOnType(NORM_QUAD4,refCoo5,gsCoo5,wg5);
7110         wg6=[0.3,0.3,0.3,0.3];
7111         quad8CooGauss=[ 0.34, 0.16, 0.21, 0.3, 0.23, 0.4, 0.14, 0.37 ]
7112         gsCoo6=quad8CooGauss;
7113         quad8CooRef=[ -1.0, -1.0, 1.0, -1.0, 1.0,  1.0, -1.0,  1.0, 0.0, -1.0, 1.0,  0.0, 0.0,  1.0, -1.0,  0.0]
7114         refCoo6=quad8CooRef;
7115         f.setGaussLocalizationOnType(NORM_QUAD8,refCoo6,gsCoo6,wg6);
7116         #
7117         resToTest=f.getLocalizationOfDiscr();
7118         self.assertEqual(3,resToTest.getNumberOfComponents());
7119         self.assertEqual(13,resToTest.getNumberOfTuples());#2+3+4+4 gauss points for resp TRI3,TRI6,QUAD4,QUAD8
7120         expected2=[5.1,1.55,0.0, 4.7,1.65,0.0,
7121                    2.32,1.52,0.0, 1.6,1.32,0.0, 3.52,1.26,0.0,#TRI6
7122                    2.6,1.6,0.0, 2.4,1.8,0.0, 2.4,1.2,0.0, 2.3,1.46,0.0,#QUAD4
7123                    2.32,2.68,0.0, 2.6,2.42,0.0, 2.8,2.46,0.0, 2.74,2.28,0.0 ];#QUAD8
7124         for i in xrange(39):
7125             self.assertAlmostEqual(expected2[i],resToTest.getIJ(0,i),14);
7126             pass
7127         #
7128         #Testing 3D cell types
7129         m3=MEDCouplingDataForTest.build3DMultiTypes_1();
7130         f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME);
7131         f.setMesh(m3);
7132         #
7133         wg7=[0.3];
7134         tetra4CooGauss=[0.34, 0.16, 0.21]
7135         gsCoo7=tetra4CooGauss;
7136         tetra4CooRef=[0.0,1.0,0.0, 0.0,0.0,1.0, 0.0,0.0,0.0, 1.0,0.0,0.0]
7137         refCoo7=tetra4CooRef;
7138         f.setGaussLocalizationOnType(NORM_TETRA4,refCoo7,gsCoo7,wg7);
7139         wg8=[0.3];
7140         tetra10CooGauss=[0.2, 0.3, 0.1]
7141         gsCoo8=tetra10CooGauss;
7142         tetra10CooRef=[0.0,1.0,0.0, 0.0,0.0,0.0, 0.0,0.0,1.0, 1.0,0.0,0.0, 0.0,0.5,0.0, 0.0,0.0,0.5, 0.0,0.5,0.5, 0.5,0.5,0.0, 0.5,0.0,0.0, 0.5,0.0,0.5]
7143         refCoo8=tetra10CooRef;
7144         f.setGaussLocalizationOnType(NORM_TETRA10,refCoo8,gsCoo8,wg8);
7145         wg9=[0.3];
7146         pyra5CooGauss=[0.2, 0.3, 0.1]
7147         gsCoo9=pyra5CooGauss;
7148         pyra5CooRef=[1.0,0.0,0.0, 0.0,1.0,0.0, -1.0,0.0,0.0, 0.0,-1.0,0.0, 0.0,0.0,1.0]
7149         refCoo9=pyra5CooRef;
7150         f.setGaussLocalizationOnType(NORM_PYRA5,refCoo9,gsCoo9,wg9);
7151         wg10=[0.3];
7152         pyra13CooGauss=[0.1, 0.2, 0.7]
7153         gsCoo10=pyra13CooGauss;
7154         pyra13CooRef=[1.0,0.0,0.0, 0.0,1.0,0.0,-1.0,0.0,0.0,0.0,-1.0,0.0,0.0,0.0,1.0,0.5,0.5,0.0,-0.5,0.5,0.0,-0.5,-0.5,0.0,0.5,-0.5,0.0,0.5,0.0,0.5,0.0,0.5,0.5,-0.5,0.0,0.5,0.0,-0.5,0.5]
7155         refCoo10=pyra13CooRef;
7156         f.setGaussLocalizationOnType(NORM_PYRA13,refCoo10,gsCoo10,wg10);
7157         wg11=[0.3];
7158         penta6CooGauss=[0.2, 0.3, 0.1]
7159         gsCoo11=penta6CooGauss;
7160         penta6CooRef=[-1.0,1.0,0.0,-1.0,-0.0,1.0,-1.0,0.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0]
7161         refCoo11=penta6CooRef;
7162         f.setGaussLocalizationOnType(NORM_PENTA6,refCoo11,gsCoo11,wg11);
7163         wg12=[0.3];
7164         penta15CooGauss=[0.2, 0.3,0.15]
7165         gsCoo12=penta15CooGauss;
7166         penta15CooRef=[-1.0,1.0,0.0,-1.0,0.0,1.0,-1.0,0.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,-1.0,0.5,0.5,-1.0,0.0,0.5,-1.0,0.5,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.5,0.5,1.0,0.0, 0.5,1.0,0.5,0.0]
7167         refCoo12=penta15CooRef;
7168         f.setGaussLocalizationOnType(NORM_PENTA15,refCoo12,gsCoo12,wg12);
7169         wg13=[0.3];
7170         hexa8CooGauss=[0.2,0.3,0.15]
7171         gsCoo13=hexa8CooGauss;
7172         hexa8CooRef=[-1.0,-1.0,-1.0,1.0,-1.0,-1.0,1.0,1.0,-1.0,-1.0,1.0,-1.0,-1.0,-1.0,1.0,1.0,-1.0,1.0,1.0,1.0,1.0,-1.0,1.0,1.0]
7173         refCoo13=hexa8CooRef;
7174         f.setGaussLocalizationOnType(NORM_HEXA8,refCoo13,gsCoo13,wg13);
7175         wg14=[0.3];
7176         hexa20CooGauss=[0.11,0.3,0.55]
7177         gsCoo14=hexa20CooGauss;
7178         hexa20CooRef=[-1.0,-1.0,-1.0,1.0,-1.0,-1.0,1.0,1.0,-1.0,-1.0,1.0,-1.0,-1.0,-1.0,1.0,1.0,-1.0,1.0,1.0,1.0,1.0,-1.0,1.0,1.0,0.0,-1.0,-1.0,1.0,0.0,-1.0,0.0,1.0,-1.0,-1.0,0.0,-1.0,-1.0,-1.0,0.0,1.0,-1.0,0.0,1.0,1.0,0.0,-1.0,1.0,0.0,0.0,-1.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,-1.0,0.0,1.0]
7179         refCoo14=hexa20CooRef;
7180         f.setGaussLocalizationOnType(NORM_HEXA20,refCoo14,gsCoo14,wg14);
7181         #
7182         resToTest=f.getLocalizationOfDiscr();
7183         self.assertEqual(3,resToTest.getNumberOfComponents());
7184         self.assertEqual(8,resToTest.getNumberOfTuples());#2+3+4+4 gauss points for resp TRI3,TRI6,QUAD4,QUAD8
7185         expected3=[1.312,3.15,1.02, 0.56,3.3,0.6, 2.18,1.1,0.2, 1.18,1.54,0.98, 1.56,0.3,3.6, 1.613,0.801,4.374, 2.6,2.4,2.3, 2.31232,2.3933985,1.553255]
7186         for i in xrange(24):
7187             self.assertAlmostEqual(expected3[i],resToTest.getIJ(0,i),14);
7188             pass
7189         #
7190         pass
7191
7192     def testP2Localization1(self):
7193         m=MEDCouplingUMesh.New("testP2",2);
7194         coords=[0.,2.,3.5,0.,4.5,1.5,1.2,0.32,3.4,1.,2.1,2.4]
7195         conn=[0,1,2,3,4,5]
7196         coo=DataArrayDouble.New();
7197         coo.setValues(coords,6,2);
7198         m.setCoords(coo);
7199         m.allocateCells(1);
7200         m.insertNextCell(NORM_TRI6,6,conn[0:6])
7201         m.finishInsertingCells();
7202         #
7203         f=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME);
7204         f.setMesh(m);
7205         da=DataArrayDouble.New();
7206         vals1=[1.2,2.3,3.4, 2.2,3.3,4.4, 3.2,4.3,5.4, 4.2,5.3,6.4, 5.2,6.3,7.4, 6.2,7.3,8.4]
7207         da.setValues(vals1,6,3);
7208         f.setArray(da);
7209         #
7210         loc=[2.27,1.3]
7211         locs=f.getValueOnMulti(loc);
7212         expected1=[6.0921164547752236, 7.1921164547752232, 8.2921164547752255]
7213         for i in xrange(3):
7214             self.assertAlmostEqual(expected1[i],locs.getIJ(0,i),12);
7215             pass
7216         pass
7217
7218     def testP2Localization2(self):
7219         m=MEDCouplingUMesh.New("testP2_2",3);
7220         coords=[0.33312787792955395, -0.35155740179580952, -0.03567564825034563, 1.307146326477638, -0.57234557776250305, -0.08608044208272235, 0.5551834466499993, 0.62324964668794192, -0.014638951108536295, 0.37761817224442129, -0.38324019806913578, 0.96283164472856886, 0.79494856035658679, -0.40628057809270046, 0.0021004190225864614, 1.023740446371799, 0.07665912970471335, -0.072889657161871096, 0.54564584619517376, 0.11132872093429744, 0.039647326652013051, 0.27164784387819052, -0.42018012100866675, 0.46563376500745146, 0.89501965094896418, -0.56148455362735061, 0.43337469695473035, 0.49118025152924394, 0.093884938060727313, 0.47216346905220891]
7221         conn=[0,1,2,3,4,5,6,7,8,9]
7222         coo=DataArrayDouble.New();
7223         coo.setValues(coords,10,3);
7224         m.setCoords(coo);
7225         m.allocateCells(1);
7226         m.insertNextCell(NORM_TETRA10,10,conn[0:10])
7227         m.finishInsertingCells();
7228         #
7229         f=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME);
7230         f.setMesh(m);
7231         da=DataArrayDouble.New();
7232         vals1=[1.1,2.1,3.1,4.1,5.2,6.2,7.2,8.2,9.2,10.2]
7233         da.setValues(vals1,10,1);
7234         f.setArray(da);
7235         #
7236         loc=[0.64637931739890486, -0.16185896817550552, 0.22678966365273748]
7237         locs=f.getValueOnMulti(loc);
7238         expected1=[10.0844021968047]
7239         for i in xrange(1):
7240             self.assertAlmostEqual(expected1[i],locs.getIJ(0,i),12);
7241             pass
7242         pass
7243
7244     def testGetValueOn2(self):
7245         m=MEDCouplingDataForTest.build2DTargetMesh_1();
7246         f=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
7247         f.setMesh(m);
7248         arr=DataArrayDouble.New();
7249         nbOfCells=m.getNumberOfCells();
7250         f.setArray(arr);
7251         values1=[7.,107.,10007.,8.,108.,10008.,9.,109.,10009.,10.,110.,10010.,11.,111.,10011.]
7252         arr.setValues(values1,nbOfCells,3);
7253         loc=[-0.05,-0.05, 0.55,-0.25, 0.55,0.15, -0.05,0.45, 0.45,0.45]
7254         f.checkCoherency();
7255         locs=f.getValueOnMulti(loc);
7256         self.assertEqual(5,locs.getNumberOfTuples());
7257         self.assertEqual(3,locs.getNumberOfComponents());
7258         for j in xrange(15):
7259             self.assertAlmostEqual(values1[j],locs.getIJ(0,j),12);
7260             pass
7261         # Testing ON_NODES
7262         f=MEDCouplingFieldDouble.New(ON_NODES,NO_TIME);
7263         f.setMesh(m);
7264         arr=DataArrayDouble.New();
7265         nbOfNodes=m.getNumberOfNodes();
7266         f.setArray(arr);
7267         values2=[7.,107.,10007.,8.,108.,10008.,9.,109.,10009.,10.,110.,10010.,11.,111.,10011.,12.,112.,10012.,13.,113.,10013.,14.,114.,10014.,15.,115.,10015.]
7268         arr.setValues(values2,nbOfNodes,3);
7269         loc2=[0.5432,-0.2432, 0.5478,0.1528, 0.5432,-0.2432, 0.5432,-0.2432]
7270         expected2=[9.0272, 109.0272, 10009.0272, 11.4124,111.4124,10011.4124, 9.0272, 109.0272, 10009.0272, 9.0272, 109.0272, 10009.0272]
7271         f.checkCoherency();
7272         loc3=DataArrayDouble.New()
7273         loc3.setValues(loc2,4,2);
7274         locs=f.getValueOnMulti(loc3);
7275         self.assertEqual(4,locs.getNumberOfTuples());
7276         self.assertEqual(3,locs.getNumberOfComponents());
7277         for i in xrange(12):
7278             self.assertAlmostEqual(expected2[i],locs.getIJ(0,i),12);
7279             pass
7280         #
7281         pass
7282
7283     def testDAIGetIdsNotEqual1(self):
7284         d=DataArrayInt.New();
7285         vals1=[2,3,5,6,8,5,5,6,1,-5]
7286         d.setValues(vals1,10,1);
7287         d2=d.getIdsNotEqual(5);
7288         self.assertEqual(7,d2.getNumberOfTuples());
7289         self.assertEqual(1,d2.getNumberOfComponents());
7290         expected1=[0,1,3,4,7,8,9]
7291         for i in xrange(7):
7292             self.assertEqual(expected1[i],d2.getIJ(0,i));
7293             pass
7294         d.rearrange(2);
7295         self.assertRaises(InterpKernelException,d.getIdsNotEqual,5);
7296         vals2=[-4,5,6]
7297         vals3=vals2;
7298         d.rearrange(1);
7299         d3=d.getIdsNotEqualList(vals3);
7300         self.assertEqual(5,d3.getNumberOfTuples());
7301         self.assertEqual(1,d3.getNumberOfComponents());
7302         expected2=[0,1,4,8,9]
7303         for i in xrange(5):
7304             self.assertEqual(expected2[i],d3.getIJ(0,i));
7305             pass
7306         pass
7307
7308     def testDAIComputeOffsets1(self):
7309         d=DataArrayInt.New();
7310         vals1=[3,5,1,2,0,8]
7311         expected1=[0,3,8,9,11,11]
7312         d.setValues(vals1,6,1);
7313         d.computeOffsets();
7314         self.assertEqual(6,d.getNumberOfTuples());
7315         self.assertEqual(1,d.getNumberOfComponents());
7316         for i in xrange(6):
7317             self.assertEqual(expected1[i],d.getIJ(0,i));
7318             pass
7319         pass
7320
7321     def testUMeshHexagonPrism1(self):
7322         coords=[0.8660254037844386, 0.5, 0.0, 0.0, 1.0, 0.0, -0.8660254037844386, 0.5, 0.0, -0.8660254037844386, -0.5, 0.0, 0.0, -1.0, 0.0, 0.8660254037844386, -0.5, 0.0,
7323                 0.8660254037844386, 0.5, 2.0, 0.0, 1.0, 2.0, -0.8660254037844386, 0.5, 2.0, -0.8660254037844386, -0.5, 2.0, 0.0, -1.0, 2.0, 0.8660254037844386, -0.5, 2.0];
7324         conn=[1,2,3,4,5,0,7,8,9,10,11,6]
7325         mesh=MEDCouplingUMesh.New("MyFirstHexagonalPrism",3);
7326         coo=DataArrayDouble.New();
7327         coo.setValues(coords,12,3);
7328         mesh.setCoords(coo);
7329         mesh.allocateCells(1);
7330         mesh.insertNextCell(NORM_HEXGP12,12,conn[0:12])
7331         mesh.finishInsertingCells();
7332         #
7333         mesh.checkCoherency();
7334         vols=mesh.getMeasureField(False);
7335         self.assertEqual(1,vols.getNumberOfTuples());
7336         self.assertEqual(1,vols.getNumberOfComponents());
7337         self.assertAlmostEqual(-5.196152422706632,vols.getIJ(0,0),12);
7338         bary=mesh.getBarycenterAndOwner();
7339         self.assertEqual(1,bary.getNumberOfTuples());
7340         self.assertEqual(3,bary.getNumberOfComponents());
7341         expected1=[0.,0.,1.]
7342         for i in xrange(3):
7343             self.assertAlmostEqual(expected1[i],bary.getIJ(0,i),12);
7344             pass
7345         d1=DataArrayInt.New();
7346         d2=DataArrayInt.New();
7347         d3=DataArrayInt.New();
7348         d4=DataArrayInt.New();
7349         m2=mesh.buildDescendingConnectivity(d1,d2,d3,d4);
7350         self.assertEqual(8,m2.getNumberOfCells());
7351         expected4=[[1,2,3,4,5,0],[7,6,11,10,9,8],[1,7,8,2],[2,8,9,3],[3,9,10,4],[4,10,11,5],[5,11,6,0],[0,6,7,1]];
7352         expected2=[NORM_POLYGON, NORM_POLYGON, NORM_QUAD4, NORM_QUAD4, NORM_QUAD4, NORM_QUAD4, NORM_QUAD4, NORM_QUAD4];
7353         expected3=[6,6,4,4,4,4,4,4]
7354         for i in xrange(8):
7355             self.assertTrue(m2.getTypeOfCell(i)==expected2[i]);
7356             v=m2.getNodeIdsOfCell(i);
7357             self.assertTrue(len(v)==expected3[i]);
7358             self.assertEqual(expected4[i],v);
7359         #
7360         mesh.convertAllToPoly();
7361         self.assertTrue(NORM_POLYHED==mesh.getTypeOfCell(0));
7362         mesh.unPolyze();
7363         self.assertTrue(NORM_HEXGP12==mesh.getTypeOfCell(0));
7364         self.assertEqual(13,mesh.getMeshLength());
7365         #
7366         pass
7367
7368     def testDADCheckIsMonotonic(self):
7369         da=DataArrayDouble.New();
7370         da.setValues([-1.,1.01,2.03,6.],2,2);
7371         self.assertRaises(InterpKernelException,da.isMonotonic,True,1e-12);
7372         da.rearrange(1);
7373         self.assertTrue(da.isMonotonic(True,1e-12));
7374         da.checkMonotonic(True,1e-12);
7375         da.setIJ(2,0,6.1);
7376         self.assertTrue(not da.isMonotonic(True,1e-12));
7377         self.assertRaises(InterpKernelException,da.checkMonotonic,True,1e-12);
7378         da.setIJ(2,0,5.99);
7379         self.assertTrue(da.isMonotonic(True,1e-12));
7380         self.assertTrue(not da.isMonotonic(True,1e-1));
7381         pass
7382
7383     def testCheckCoherencyDeeper1(self):
7384         m=MEDCouplingDataForTest.build3DSourceMesh_1();
7385         m.checkCoherency();
7386         m.checkCoherency1();
7387         m.getNodalConnectivity().setIJ(8,0,-1);
7388         m.checkCoherency();
7389         self.assertRaises(InterpKernelException,m.checkCoherency1);
7390         m.getNodalConnectivity().setIJ(8,0,-6);
7391         m.checkCoherency();
7392         self.assertRaises(InterpKernelException,m.checkCoherency1);
7393         m.getNodalConnectivity().setIJ(8,0,9);#9>=NbOfNodes
7394         m.checkCoherency();
7395         self.assertRaises(InterpKernelException,m.checkCoherency1);
7396         m.getNodalConnectivity().setIJ(8,0,8);#OK
7397         m.checkCoherency();
7398         m.checkCoherency1();
7399         elts=[1,5]
7400         m.convertToPolyTypes(elts);
7401         m.checkCoherency();
7402         m.checkCoherency1();
7403         m.getNodalConnectivity().setIJ(2,0,9);#9>=NbOfNodes
7404         m.checkCoherency();
7405         self.assertRaises(InterpKernelException,m.checkCoherency1);
7406         m.getNodalConnectivity().setIJ(2,0,-3);
7407         m.checkCoherency();
7408         self.assertRaises(InterpKernelException,m.checkCoherency1);
7409         m.getNodalConnectivity().setIJ(2,0,-1);
7410         m.checkCoherency();
7411         self.assertRaises(InterpKernelException,m.checkCoherency1);#Throw because cell#0 is not a polyhedron
7412         m.getNodalConnectivity().setIJ(2,0,4);
7413         m.checkCoherency();
7414         m.checkCoherency1();
7415         m.getNodalConnectivity().setIJ(7,0,-1);
7416         m.checkCoherency();
7417         m.checkCoherency1();#OK because we are in polyhedron connec
7418         m.getNodalConnectivity().setIJ(36,0,14);
7419         m.checkCoherency();
7420         self.assertRaises(InterpKernelException,m.checkCoherency1);#Throw beacause now cell 5 is a TETRA4 (14) so mimatch of number index and static type.
7421         pass
7422
7423     def testUnPolyze2(self):
7424         m=MEDCouplingUMesh.New("jjj",3);
7425         coo=DataArrayDouble.New();
7426         coo.alloc(4,3);
7427         coo.rearrange(1);
7428         coo.iota(0);
7429         coo.rearrange(3);
7430         m.setCoords(coo);
7431         m.allocateCells(2);
7432         m.insertNextCell(NORM_TETRA4,4,[0,1,2,3]);
7433         m.insertNextCell(NORM_TETRA4,4,[0,1,2,3]);
7434         m.finishInsertingCells();
7435         m2=MEDCouplingUMesh.MergeUMeshesOnSameCoords(4*[m]);
7436         m2.convertToPolyTypes([2]);
7437         m2.unPolyze();
7438         self.assertEqual(NORM_TETRA4,m2.getTypeOfCell(2));
7439         self.assertEqual(40,m2.getMeshLength());
7440         temp2=m2.getNodeIdsOfCell(2);
7441         self.assertEqual(temp2,[0,1,2,3]);
7442         m2.checkCoherency1();
7443         m3=m2.deepCpy();
7444         m2.unPolyze();
7445         self.assertTrue(m3.isEqual(m2,1e-12));
7446         pass
7447
7448     def testDACpyFrom1(self):
7449         d=DataArrayDouble.New();
7450         d.alloc(12,1);
7451         d.iota(14.);
7452         d.rearrange(3);
7453         d.setName("Toto");
7454         d.setInfoOnComponent(0,"X [m]");
7455         d.setInfoOnComponent(1,"Y [m]");
7456         d.setInfoOnComponent(2,"Z [m]");
7457         #
7458         d1=DataArrayDouble.New();
7459         self.assertTrue(not d.isEqual(d1,1e-12));
7460         d1.cpyFrom(d);
7461         self.assertTrue(d.isEqual(d1,1e-12));
7462         d1.cpyFrom(d);
7463         self.assertTrue(d.isEqual(d1,1e-12));
7464         d1.rearrange(2);
7465         self.assertTrue(not d.isEqual(d1,1e-12));
7466         d1.cpyFrom(d);
7467         self.assertTrue(d.isEqual(d1,1e-12));
7468         #
7469         d2=d.convertToIntArr();
7470         d4=DataArrayInt.New();
7471         self.assertTrue(not d2.isEqual(d4));
7472         d4.cpyFrom(d2);
7473         self.assertTrue(d2.isEqual(d4));
7474         d4.cpyFrom(d2);
7475         self.assertTrue(d2.isEqual(d4));
7476         d4.rearrange(2);
7477         self.assertTrue(not d2.isEqual(d4));
7478         d4.cpyFrom(d2);
7479         self.assertTrue(d2.isEqual(d4));
7480         pass
7481
7482     def testDAITransformWithIndArr1(self):
7483         tab1=[17,18,22,19]
7484         tab2=[0,1,1,3,3,0,1,3,2,2,3,0]
7485         expected=[17,18,18,19,19,17,18,19,22,22,19,17]
7486         d=DataArrayInt.New();
7487         d.setValues(tab1,4,1);
7488         d1=DataArrayInt.New();
7489         d1.setValues(tab2,12,1);
7490         d2=d1[:]
7491         #
7492         d1.transformWithIndArr(d);
7493         self.assertEqual(12,d1.getNumberOfTuples());
7494         self.assertEqual(1,d1.getNumberOfComponents());
7495         for i in xrange(12):
7496             self.assertEqual(expected[i],d1.getIJ(i,0));
7497             pass
7498         #
7499         d1=d2
7500         d1.transformWithIndArr(tab1)
7501         self.assertEqual(12,d1.getNumberOfTuples());
7502         self.assertEqual(1,d1.getNumberOfComponents());
7503         for i in xrange(12):
7504             self.assertEqual(expected[i],d1.getIJ(i,0));
7505             pass
7506         pass
7507
7508     def testDAIBuildPermArrPerLevel1(self):
7509         arr=[2,0,1,1,0,1,2,0,1,1,0,0]
7510         expected1=[10,0,5,6,1,7,11,2,8,9,3,4]
7511         da=DataArrayInt.New();
7512         da.setValues(arr,12,1);
7513         da2=da.buildPermArrPerLevel();
7514         self.assertEqual(12,da2.getNumberOfTuples());
7515         self.assertEqual(1,da2.getNumberOfComponents());
7516         for i in xrange(12):
7517             self.assertEqual(expected1[i],da2.getIJ(i,0));
7518             pass
7519         pass
7520
7521     def testDAIOperations1(self):
7522         arr1=[-1,-2,4,7,3,2,6,6,4,3,0,1]
7523         da=DataArrayInt.New();
7524         da.setValues(arr1,4,3);
7525         da1=DataArrayInt.New();
7526         da1.alloc(12,1);
7527         da1.iota(2);
7528         self.assertRaises(InterpKernelException,DataArrayInt.Add,da,da1);#not same number of tuples/Components
7529         da1.rearrange(3);
7530         da2=DataArrayInt.Add(da,da1);
7531         self.assertEqual(4,da2.getNumberOfTuples());
7532         self.assertEqual(3,da2.getNumberOfComponents());
7533         expected1=[1,1,8,12,9,9,14,15,14,14,12,14]
7534         for i in xrange(12):
7535             self.assertEqual(expected1[i],da2.getIJ(0,i));
7536             pass
7537         da1.substractEqual(da);
7538         expected2=[3,5,0,-2,3,5,2,3,6,8,12,12]
7539         for i in xrange(12):
7540             self.assertEqual(expected2[i],da1.getIJ(0,i));
7541             pass
7542         da1.rearrange(1); da1.iota(2); da1.rearrange(3);
7543         da1.addEqual(da);
7544         for i in xrange(12):
7545             self.assertEqual(expected1[i],da1.getIJ(0,i));
7546             pass
7547         da1.rearrange(1); da1.iota(2); da1.rearrange(3);
7548         da2=DataArrayInt.Multiply(da,da1);
7549         self.assertEqual(4,da2.getNumberOfTuples());
7550         self.assertEqual(3,da2.getNumberOfComponents());
7551         expected3=[-2,-6,16,35,18,14,48,54,40,33,0,13]
7552         for i in xrange(12):
7553             self.assertEqual(expected3[i],da2.getIJ(0,i));
7554             pass
7555         da.divideEqual(da1);
7556         self.assertEqual(4,da.getNumberOfTuples());
7557         self.assertEqual(3,da.getNumberOfComponents());
7558         expected4=[0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]
7559         for i in xrange(12):
7560             self.assertEqual(expected4[i],da.getIJ(0,i));
7561             pass
7562         da.setValues(arr1,4,3);
7563         da1.multiplyEqual(da);
7564         self.assertEqual(4,da1.getNumberOfTuples());
7565         self.assertEqual(3,da1.getNumberOfComponents());
7566         for i in xrange(12):
7567             self.assertEqual(expected3[i],da1.getIJ(0,i));
7568             pass
7569         da1.rearrange(1); da1.iota(2); da1.rearrange(3);
7570         da2=DataArrayInt.Divide(da,da1);
7571         self.assertEqual(4,da2.getNumberOfTuples());
7572         self.assertEqual(3,da2.getNumberOfComponents());
7573         for i in xrange(12):
7574             self.assertEqual(expected4[i],da2.getIJ(0,i));
7575             pass
7576         da1.applyInv(321);
7577         self.assertEqual(4,da1.getNumberOfTuples());
7578         self.assertEqual(3,da1.getNumberOfComponents());
7579         expected5=[160,107,80,64,53,45,40,35,32,29,26,24]
7580         for i in xrange(12):
7581             self.assertEqual(expected5[i],da1.getIJ(0,i));
7582             pass
7583         da1.applyDivideBy(2);
7584         self.assertEqual(4,da1.getNumberOfTuples());
7585         self.assertEqual(3,da1.getNumberOfComponents());
7586         expected6=[80,53,40,32,26,22,20,17,16,14,13,12]
7587         for i in xrange(12):
7588             self.assertEqual(expected6[i],da1.getIJ(0,i));
7589             pass
7590         expected7=[3,4,5,4,5,1,6,3,2,0,6,5]
7591         da1.applyModulus(7);
7592         for i in xrange(12):
7593             self.assertEqual(expected7[i],da1.getIJ(0,i));
7594             pass
7595         da1.applyLin(1,1);
7596         expected8=[3,3,3,3,3,1,3,3,0,0,3,3]
7597         da1.applyRModulus(3);
7598         for i in xrange(12):
7599             self.assertEqual(expected8[i],da1.getIJ(0,i));
7600             pass
7601         pass
7602
7603     def testEmulateMEDMEMBDC1(self):
7604         m,m1=MEDCouplingDataForTest.buildPointe_1();
7605         m2,da1,da2,da3,da4,da5,da0=m.emulateMEDMEMBDC(m1)
7606         expected0=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,36,37,32,33,34,35,38,39,40,41,42,43,44,45,46]
7607         expected1=[1,32,29,23,41,36]
7608         self.assertEqual(47,da0.getNumberOfTuples());
7609         self.assertEqual(1,da0.getNumberOfComponents());
7610         for i in xrange(47):
7611             self.assertEqual(expected0[i],da0.getIJ(0,i));
7612             pass
7613         self.assertEqual(6,da5.getNumberOfTuples());
7614         self.assertEqual(1,da5.getNumberOfComponents());
7615         for i in xrange(6):
7616             self.assertEqual(expected1[i],da5.getIJ(0,i));
7617             pass
7618         expected2=[0,1,2,3,4,0,5,6,7,4,8,9,1,7,10,11,12,13,14,5,15,16,17,8,18,19,20,10,21,22,23,2,13,24,25,21,16,26,27,12,19,28,29,15,22,30,31,18,36,26,28,30,24,37,32,33,34,35,38,36,39,40,41,42,37,38,43,44,45,46]
7619         self.assertEqual(70,da1.getNumberOfTuples());
7620         self.assertEqual(1,da1.getNumberOfComponents());
7621         for i in xrange(70):
7622             self.assertEqual(expected2[i],da1.getIJ(0,i));
7623             pass
7624         expected3=[0,4,8,12,16,20,24,28,32,36,40,44,48,53,58,64,70]
7625         self.assertEqual(17,da2.getNumberOfTuples());
7626         self.assertEqual(1,da2.getNumberOfComponents());
7627         for i in xrange(17):
7628             self.assertEqual(expected3[i],da2.getIJ(0,i));
7629             pass
7630         expected4=[0,2,4,6,7,9,11,12,14,16,17,19,20,22,24,25,27,29,30,32,34,35,37,39,40,42,43,45,46,48,49,51,52,53,54,55,56,58,60,62,63,64,65,66,67,68,69,70]
7631         #expected4=[0,2,4,6,7,9,11,12,14,16,17,19,20,22,24,25,27,29,30,32,34,35,37,39,40,42,43,45,46,48,49,51,52,54,56,57,58,59,60,62,63,64,65,66,67,68,69,70];
7632         self.assertEqual(48,da4.getNumberOfTuples());
7633         self.assertEqual(1,da4.getNumberOfComponents());
7634         for i in xrange(48):
7635             self.assertEqual(expected4[i],da4.getIJ(0,i));
7636             pass
7637         expected5=[0,1,0,3,0,7,0,1,2,1,4,1,2,3,2,5,2,3,6,3,4,9,4,8,4,5,10,5,9,5,6,11,6,10,6,7,8,7,11,7,8,12,8,9,12,9,10,12,10,11,12,11,13,13,13,13,12,14,13,15,14,15,14,14,14,14,15,15,15,15]
7638         self.assertEqual(70,da3.getNumberOfTuples());
7639         self.assertEqual(1,da3.getNumberOfComponents());
7640         for i in xrange(70):
7641             self.assertEqual(expected5[i],da3.getIJ(0,i));
7642             pass
7643         pass
7644
7645     def testGetLevArrPerCellTypes1(self):
7646         m,m1=MEDCouplingDataForTest.buildPointe_1();
7647         m1,d0,d1,d2,d3=m.buildDescendingConnectivity();
7648         order=[NORM_TRI3,NORM_QUAD4];
7649         da0,da1=m1.getLevArrPerCellTypes(order);
7650         expected0=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1]
7651         expected1=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,36,37,32,33,34,35,38,39,40,41,42,43,44,45,46]
7652         self.assertEqual(47,da0.getNumberOfTuples());
7653         self.assertEqual(1,da0.getNumberOfComponents());
7654         for i in xrange(47):
7655             self.assertEqual(expected0[i],da0.getIJ(0,i));
7656             pass
7657         self.assertEqual(2,da1.getNumberOfTuples());
7658         self.assertEqual(1,da1.getNumberOfComponents());
7659         self.assertEqual(36,da1.getIJ(0,0));#36 TRI3
7660         self.assertEqual(11,da1.getIJ(1,0));#11 QUAD4
7661         #
7662         da2=da0.buildPermArrPerLevel();
7663         #
7664         self.assertEqual(47,da2.getNumberOfTuples());
7665         self.assertEqual(1,da2.getNumberOfComponents());
7666         for i in xrange(47):
7667             self.assertEqual(expected1[i],da2.getIJ(0,i));
7668             pass
7669         pass
7670
7671     def testSortCellsInMEDFileFrmt1(self):
7672         m,m1=MEDCouplingDataForTest.buildPointe_1();
7673         m2=m.deepCpy()
7674         da=DataArrayInt.New()
7675         da.setValues([0,1,2,14,3,12,4,5,15,6,7,8,9,10,11,13],16,1)
7676         daa=da.invertArrayN2O2O2N(16)
7677         m.renumberCells(daa,False)
7678         da2=m.sortCellsInMEDFileFrmt()
7679         self.assertEqual(da2.getValues(),[0,1,2,14,3,12,4,5,15,6,7,8,9,10,11,13])
7680         self.assertTrue(m.isEqual(m2,1e-12))
7681         self.assertTrue(da.isEqual(da2))
7682         pass
7683
7684     def testBuildPartAndReduceNodes1(self):
7685         m=MEDCouplingDataForTest.build2DTargetMesh_1();
7686         arr=[1,0]
7687         m2,da=m.buildPartAndReduceNodes(arr);
7688         self.assertEqual(5,m2.getNumberOfNodes());
7689         self.assertEqual(2,m2.getNumberOfCells());
7690         f=m2.getMeasureField(True);
7691         self.assertAlmostEqual(0.125,f.getArray().getIJ(0,0),12);
7692         self.assertAlmostEqual(0.25,f.getArray().getIJ(1,0),12);
7693         #
7694         arr2=DataArrayInt.New()
7695         arr2.setValues(arr,2,1)
7696         m2,da=m.buildPartAndReduceNodes(arr2);
7697         self.assertEqual(5,m2.getNumberOfNodes());
7698         self.assertEqual(2,m2.getNumberOfCells());
7699         f=m2.getMeasureField(True);
7700         self.assertAlmostEqual(0.125,f.getArray().getIJ(0,0),12);
7701         self.assertAlmostEqual(0.25,f.getArray().getIJ(1,0),12);
7702         pass
7703
7704     def testDAITransformWithIndArrR1(self):
7705         tab1=[2,4,5,3,6,7]
7706         tab2=[-1,-1,0,1,2,3,4,5,-1,-1,-1,-1]
7707         expected=[0,3,1,2,4,5]
7708         d=DataArrayInt.New();
7709         d.setValues(tab1,6,1);
7710         d1=DataArrayInt.New();
7711         d1.setValues(tab2,12,1);
7712         d2=d1[:]
7713         #
7714         d3=d.transformWithIndArrR(d1);
7715         self.assertEqual(6,d3.getNumberOfTuples());
7716         self.assertEqual(1,d3.getNumberOfComponents());
7717         for i in xrange(6):
7718             self.assertEqual(expected[i],d3.getIJ(i,0));
7719             pass
7720         #
7721         d1=d2
7722         d3=d.transformWithIndArrR(tab2)
7723         self.assertEqual(6,d3.getNumberOfTuples());
7724         self.assertEqual(1,d3.getNumberOfComponents());
7725         for i in xrange(6):
7726             self.assertEqual(expected[i],d3.getIJ(i,0));
7727             pass
7728         pass
7729
7730     def testDAISplitByValueRange1(self):
7731         val1=[6,5,0,3,2,7,8,1,4]
7732         val2=[0,4,9]
7733         d=DataArrayInt.New();
7734         d.setValues(val1,9,1);
7735         e,f,g=d.splitByValueRange(val2);
7736         self.assertEqual(9,e.getNumberOfTuples());
7737         self.assertEqual(1,e.getNumberOfComponents());
7738         self.assertEqual(9,f.getNumberOfTuples());
7739         self.assertEqual(1,f.getNumberOfComponents());
7740         self.assertEqual(2,g.getNumberOfTuples());
7741         self.assertEqual(1,g.getNumberOfComponents());
7742         #
7743         expected1=[1,1,0,0,0,1,1,0,1]
7744         expected2=[2,1,0,3,2,3,4,1,0]
7745         for i in xrange(9):
7746             self.assertEqual(expected1[i],e.getIJ(i,0));
7747             self.assertEqual(expected2[i],f.getIJ(i,0));
7748             pass
7749         self.assertEqual(0,g.getIJ(0,0));
7750         self.assertEqual(1,g.getIJ(1,0));
7751         #
7752         d.setIJ(6,0,9);
7753         self.assertRaises(InterpKernelException,d.splitByValueRange,val2);
7754         pass
7755
7756     def testUMeshSplitProfilePerType1(self):
7757         val0=[2,0,1,3,4]
7758         m=MEDCouplingDataForTest.build2DTargetMesh_1();
7759         m.renumberCells(val0,False);
7760         #
7761         val1=[0,2,3]
7762         d=DataArrayInt.New();
7763         d.setValues(val1,3,1);
7764         d.setName("sup")
7765         code,idsInPflPerType,pfls=m.splitProfilePerType(d);
7766         self.assertEqual(2,len(code));
7767         self.assertEqual(2,len(idsInPflPerType));
7768         expected1=[[3,1,0], [4,2,1]]
7769         self.assertEqual(expected1,code)
7770         self.assertEqual(2,len(idsInPflPerType));
7771         self.assertEqual(1,idsInPflPerType[0].getNumberOfTuples());
7772         self.assertEqual(0,idsInPflPerType[0].getIJ(0,0));
7773         self.assertEqual(2,idsInPflPerType[1].getNumberOfTuples());
7774         self.assertEqual(1,idsInPflPerType[1].getIJ(0,0));
7775         self.assertEqual(2,idsInPflPerType[1].getIJ(1,0));
7776         #
7777         self.assertEqual(2,len(pfls));
7778         self.assertEqual("sup",pfls[0].getName())
7779         self.assertEqual(1,pfls[0].getNumberOfTuples());
7780         self.assertEqual(0,pfls[0].getIJ(0,0));
7781         self.assertEqual("sup",pfls[1].getName())
7782         self.assertEqual(2,pfls[1].getNumberOfTuples());
7783         self.assertEqual(0,pfls[1].getIJ(0,0));
7784         self.assertEqual(1,pfls[1].getIJ(1,0));
7785         #
7786         val2=[0,2,3,4]
7787         d=DataArrayInt.New();
7788         d.setValues(val2,4,1);
7789         code,idsInPflPerType,pfls=m.splitProfilePerType(d);
7790         self.assertEqual(2,len(code));
7791         self.assertEqual(2,len(idsInPflPerType));
7792         expected2=[[3,1,0], [4,3,-1]]
7793         self.assertEqual(expected2,code);
7794         self.assertEqual(2,len(idsInPflPerType));
7795         self.assertEqual(1,idsInPflPerType[0].getNumberOfTuples());
7796         self.assertEqual(0,idsInPflPerType[0].getIJ(0,0));
7797         self.assertEqual(3,idsInPflPerType[1].getNumberOfTuples());
7798         self.assertEqual(1,idsInPflPerType[1].getIJ(0,0));
7799         self.assertEqual(2,idsInPflPerType[1].getIJ(1,0));
7800         self.assertEqual(3,idsInPflPerType[1].getIJ(2,0));
7801         #
7802         self.assertEqual(1,len(pfls));
7803         self.assertEqual(1,pfls[0].getNumberOfTuples());
7804         self.assertEqual(0,pfls[0].getIJ(0,0));
7805         #
7806         val3=[1,0,2]
7807         d=DataArrayInt.New();
7808         d.setValues(val3,3,1);
7809         code,idsInPflPerType,pfls=m.splitProfilePerType(d);
7810         self.assertEqual(2,len(code));
7811         self.assertEqual(2,len(idsInPflPerType));
7812         expected3=[[3,2,0], [4,1,1]]
7813         self.assertEqual(expected3,code);
7814         self.assertEqual(2,len(idsInPflPerType));
7815         self.assertEqual(2,idsInPflPerType[0].getNumberOfTuples());
7816         self.assertEqual(0,idsInPflPerType[0].getIJ(0,0));
7817         self.assertEqual(1,idsInPflPerType[0].getIJ(1,0));
7818         self.assertEqual(1,idsInPflPerType[1].getNumberOfTuples());
7819         self.assertEqual(2,idsInPflPerType[1].getIJ(0,0));
7820         #
7821         self.assertEqual(2,len(pfls));
7822         self.assertEqual(2,pfls[0].getNumberOfTuples());
7823         self.assertEqual(1,pfls[0].getIJ(0,0));
7824         self.assertEqual(0,pfls[0].getIJ(1,0));
7825         self.assertEqual(0,pfls[1].getIJ(0,0));
7826         #
7827         val4=[3,4]
7828         d=DataArrayInt.New();
7829         d.setValues(val4,2,1);
7830         code,idsInPflPerType,pfls=m.splitProfilePerType(d);
7831         self.assertEqual(1,len(code));
7832         self.assertEqual(1,len(idsInPflPerType));
7833         expected4=[[4,2,0]]
7834         self.assertEqual(expected4,code);
7835         self.assertEqual(1,len(idsInPflPerType));
7836         self.assertEqual(2,idsInPflPerType[0].getNumberOfTuples());
7837         self.assertEqual(0,idsInPflPerType[0].getIJ(0,0));
7838         self.assertEqual(1,idsInPflPerType[0].getIJ(1,0));
7839         #
7840         self.assertEqual(1,len(pfls));
7841         self.assertEqual(2,pfls[0].getNumberOfTuples());
7842         self.assertEqual(1,pfls[0].getIJ(0,0));
7843         self.assertEqual(2,pfls[0].getIJ(1,0));
7844         pass
7845
7846     def testDAIBuildExplicitArrByRanges1(self):
7847         d=DataArrayInt.New();
7848         vals1=[0,2,3]
7849         d.setValues(vals1,3,1);
7850         e=DataArrayInt.New();
7851         vals2=[0,3,6,10,14,20]
7852         e.setValues(vals2,6,1);
7853         #
7854         f=d.buildExplicitArrByRanges(e);
7855         self.assertEqual(11,f.getNumberOfTuples());
7856         self.assertEqual(1,f.getNumberOfComponents());
7857         expected1=[0,1,2,6,7,8,9,10,11,12,13]
7858         for i in xrange(11):
7859             self.assertEqual(expected1[i],f.getIJ(i,0));
7860             pass
7861         pass
7862
7863     def testDAIComputeOffsets2(self):
7864         d=DataArrayInt.New();
7865         vals1=[3,5,1,2,0,8]
7866         expected1=[0,3,8,9,11,11,19]
7867         d.setValues(vals1,6,1);
7868         d.computeOffsets2();
7869         self.assertEqual(7,d.getNumberOfTuples());
7870         self.assertEqual(1,d.getNumberOfComponents());
7871         for i in xrange(7):
7872             self.assertEqual(expected1[i],d.getIJ(0,i));
7873             pass
7874         pass
7875
7876     def testMergeField3(self):
7877         m=MEDCouplingDataForTest.build2DTargetMesh_1();
7878         m.getCoords().setInfoOnComponent(0,"x [m]");
7879         m.getCoords().setInfoOnComponent(1,"z [km]");
7880         m.setName("m");
7881         m.setDescription("desc");
7882         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
7883         f1.setName("f1");
7884         f1.setMesh(m);
7885         arr=DataArrayDouble.New();
7886         arr.alloc(5,2);
7887         arr.setInfoOnComponent(0,"X [m]");
7888         arr.setInfoOnComponent(1,"YY [mm]");
7889         arr.fillWithValue(2.);
7890         f1.setArray(arr);
7891         #
7892         f2=MEDCouplingFieldDouble.MergeFields([f1]);
7893         self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
7894         #
7895         pass
7896     
7897     def testGetDistributionOfTypes1(self):
7898         m=MEDCouplingDataForTest.build2DTargetMesh_1();
7899         tab1=[2,0,1,3,4]
7900         self.assertRaises(InterpKernelException,m.getDistributionOfTypes);
7901         m.renumberCells(tab1,False);
7902         code=m.getDistributionOfTypes();
7903         self.assertEqual(2,len(code));
7904         self.assertEqual(3,code[0][0]);
7905         self.assertEqual(2,code[0][1]);
7906         self.assertEqual(-1,code[0][2]);
7907         self.assertEqual(4,code[1][0]);
7908         self.assertEqual(3,code[1][1]);
7909         self.assertEqual(-1,code[1][2]);
7910         pass
7911
7912     def testNorm2_1(self):
7913         m=MEDCouplingDataForTest.build2DTargetMesh_1();
7914         f=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
7915         f.setMesh(m);
7916         #
7917         d=DataArrayDouble.New();
7918         tab=[1.2,1.3,2.2,2.3,3.2,3.3,4.2,4.3,5.2,5.3]
7919         d.setValues(tab,5,2);
7920         f.setArray(d);
7921         f.checkCoherency();
7922         #
7923         self.assertAlmostEqual(11.209371079592289,f.norm2(),14);
7924         #
7925         pass
7926
7927     def testNormMax1(self):
7928         m=MEDCouplingDataForTest.build2DTargetMesh_1();
7929         f=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
7930         f.setMesh(m);
7931         #
7932         d=DataArrayDouble.New();
7933         tab=[2.3,-1.2,6.3,-7.8,2.9,7.7,2.1,0.,3.6,-7.6]
7934         d.setValues(tab,5,2);
7935         f.setArray(d);
7936         f.checkCoherency();
7937         #
7938         self.assertAlmostEqual(7.8,f.normMax(),14);
7939         #
7940         pass
7941
7942     def testFindAndCorrectBadOriented3DExtrudedCells1(self):
7943         coords=[0.0011180339887498999, -0.0011755705045849499, 0.0, -0.0012331070204200001, -0.0011755705045849499, 0.0, -0.00067557050458494599, -0.00145964954842536, 0.0, -0.00050000000000000001, -0.00086602540378443902, 0.0, 0.00140211303259031, -0.00061803398874989504, 0.0, 0.00086602540378443902, -0.00050000000000000001, 0.0, 0.001, 0.0, 0.0, 0.00034561537182258202, 0.000269164072574575, 0.0, 0.0, 0.001, 0.0, -0.00050000000000000001, 0.00086602540378443902, 0.0, -0.000269164072574575, 0.00034561537182258202, 0.0, -0.001, 0.0, 0.0, -0.00086602540378443902, -0.00050000000000000001, 0.0, -0.00034561537182258202, -0.000269164072574575, 0.0, 0.0, -0.001, 0.0, 0.00050000000000000001, -0.00086602540378443902, 0.0, 0.000269164072574575, -0.00034561537182258202, 0.0, 0.0015, -6.01853107621011e-36, 0.0, 0.00056049747291484397, -0.00145964954842536, 0.0, 0.0011180339887498999, -0.0011755705045849499, 0.00050000000000000001, -0.0012331070204200001, -0.0011755705045849499, 0.00050000000000000001, -0.00067557050458494599, -0.00145964954842536, 0.00050000000000000001, -0.00050000000000000001, -0.00086602540378443902, 0.00050000000000000001, 0.00140211303259031, -0.00061803398874989504, 0.00050000000000000001, 0.00086602540378443902, -0.00050000000000000001, 0.00050000000000000001, 0.001, 0.0, 0.00050000000000000001, 0.00034561537182258202, 0.000269164072574575, 0.00050000000000000001, 0.0, 0.001, 0.00050000000000000001, -0.00050000000000000001, 0.00086602540378443902, 0.00050000000000000001, -0.000269164072574575, 0.00034561537182258202, 0.00050000000000000001, -0.001, 0.0, 0.00050000000000000001, -0.00086602540378443902, -0.00050000000000000001, 0.00050000000000000001, -0.00034561537182258202, -0.000269164072574575, 0.00050000000000000001, 0.0, -0.001, 0.00050000000000000001, 0.00050000000000000001, -0.00086602540378443902, 0.00050000000000000001, 0.000269164072574575, -0.00034561537182258202, 0.00050000000000000001, 0.0015, -6.01853107621011e-36, 0.00050000000000000001, 0.00056049747291484397, -0.00145964954842536, 0.00050000000000000001];
7944         conn=[2, 1, 3, 21, 20, 22, 4, 0, 5, 23, 19, 24, 8, 9, 10, 27, 28, 29, 11, 12, 13, 30, 31, 32, 0, 18, 15, 5, 19, 37, 34, 24, 6, 17, 4, 5, 25, 36, 23, 24, 3, 14, 16, 13, 22, 33, 35, 32, 13, 16, 7, 10, 32, 35, 26, 29]
7945         connExp=[16, 2, 1, 3, 21, 20, 22, 16, 4, 0, 5, 23, 19, 24, 16, 8, 10, 9, 27, 29, 28, 16, 11, 13, 12, 30, 32, 31, 18, 0, 18, 15, 5, 19, 37, 34, 24,18, 6, 17, 4, 5, 25, 36, 23, 24, 18, 3, 13, 16, 14, 22, 32, 35, 33, 18, 13, 10, 7, 16, 32, 29, 26, 35]
7946         invalidCells=[2,3,6,7]
7947         m=MEDCouplingUMesh.New("Example",3);
7948         coo=DataArrayDouble.New();
7949         coo.setValues(coords,38,3);
7950         m.setCoords(coo);
7951         m.allocateCells(8);
7952         m.insertNextCell(NORM_PENTA6,6,conn[0:6])
7953         m.insertNextCell(NORM_PENTA6,6,conn[6:12])
7954         m.insertNextCell(NORM_PENTA6,6,conn[12:18])
7955         m.insertNextCell(NORM_PENTA6,6,conn[18:24])
7956         m.insertNextCell(NORM_HEXA8,8,conn[24:32])
7957         m.insertNextCell(NORM_HEXA8,8,conn[32:40])
7958         m.insertNextCell(NORM_HEXA8,8,conn[40:48])
7959         m.insertNextCell(NORM_HEXA8,8,conn[48:56])
7960         m.finishInsertingCells();
7961         #
7962         v=m.findAndCorrectBadOriented3DExtrudedCells();
7963         self.assertEqual(4,len(v));
7964         self.assertEqual(v.getValues(),invalidCells);
7965         self.assertEqual(connExp,m.getNodalConnectivity().getValues());
7966         self.assertTrue(m.findAndCorrectBadOriented3DExtrudedCells().empty())
7967         #
7968         pass
7969
7970     def testConvertExtrudedPolyhedra1(self):
7971         conn=[1,2,3,4, 5,6,7,8,9,10,11,12, 13,14,15,16, 17,18,19,20,21,22, 23,24,25,26,27,28, 29,30,31,32,33,34,35,36,37,38, 39,40,41,42,43,44,45,46, 47,48,49,50,51,52,53,54,55,56,57,58, 59,60,61,62,63,64,65,66,67,68,69,70,71,72]
7972         m=MEDCouplingUMesh.New("Example",3);
7973         coo=DataArrayDouble.New();
7974         coo.alloc(73,3);
7975         coo.rearrange(1); coo.iota(0); coo.rearrange(3);
7976         m.setCoords(coo);
7977         m.allocateCells(9);
7978         m.insertNextCell(NORM_TETRA4,4,conn[0:4])
7979         m.insertNextCell(NORM_HEXA8,8,conn[4:12])
7980         m.insertNextCell(NORM_TETRA4,4,conn[12:16])
7981         m.insertNextCell(NORM_POLYHED,6,conn[16:22])
7982         m.insertNextCell(NORM_PENTA6,6,conn[22:28])
7983         m.insertNextCell(NORM_POLYHED,10,conn[28:38])
7984         m.insertNextCell(NORM_HEXA8,8,conn[38:46])
7985         m.insertNextCell(NORM_HEXGP12,12,conn[46:58])
7986         m.insertNextCell(NORM_POLYHED,14,conn[58:72])
7987         m.finishInsertingCells();
7988         #
7989         m.convertExtrudedPolyhedra();
7990         da=m.getNodalConnectivity();
7991         dai=m.getNodalConnectivityIndex();
7992         self.assertEqual(10,dai.getNbOfElems());
7993         self.assertEqual(159,da.getNbOfElems());
7994         #
7995         expected1=[14,1,2,3,4,18,5,6,7,8,9,10,11,12,14,13,14,15,16,31,17,18,19,-1,20,22,21,-1,17,20,21,18,-1,18,21,22,19,-1,19,22,20,17,16,23,24,25,26,27,28,31,29,30,31,32,33,-1,34,38,37,36,35,-1,29,34,35,30,-1,30,35,36,31,-1,31,36,37,32,-1,32,37,38,33,-1,33,38,34,29,18,39,40,41,42,43,44,45,46,22,47,48,49,50,51,52,53,54,55,56,57,58,31,59,60,61,62,63,64,65,-1,66,72,71,70,69,68,67,-1,59,66,67,60,-1,60,67,68,61,-1,61,68,69,62,-1,62,69,70,63,-1,63,70,71,64,-1,64,71,72,65,-1,65,72,66,59];
7996         expected2=[0,5,14,19,42,49,86,95,108,159]
7997         self.assertEqual(expected1,da.getValues());
7998         self.assertEqual(expected2,dai.getValues());
7999         m.checkCoherency2()
8000         pass
8001
8002     def testNonRegressionCopyTinyStrings(self):
8003         m=MEDCouplingDataForTest.build2DTargetMesh_1()
8004         f1=m.getMeasureField(True)
8005         f1.getArray().setInfoOnComponent(0,"P [N/m^2]")
8006         bary=m.getBarycenterAndOwner()
8007         f2=f1.buildNewTimeReprFromThis(NO_TIME,False)
8008         f2.setArray(bary)
8009         self.assertRaises(InterpKernelException,f1.copyTinyAttrFrom,f2)
8010         pass
8011
8012     def testDaDSetPartOfValuesAdv1(self):
8013         tab1=[3.,4.,5., 13.,14.,15., 23.,24.,25., 33.,34.,35., 43.,44.,45., 53.,54.,55.]
8014         tab2=[6.,7.,8., 16.,17.,18., 26.,27.,28.]
8015         tab3=[4,1, 2,2, 3,0]
8016         a=DataArrayDouble.New();
8017         a.setValues(tab1,6,3);
8018         b=DataArrayDouble.New();
8019         b.setValues(tab2,3,3);
8020         c=DataArrayInt.New();
8021         c.setValues(tab3,3,2);
8022         #
8023         a.setPartOfValuesAdv(b,c);
8024         expected1=[3.,4.,5., 13.,14.,15., 26.,27.,28., 6.,7.,8., 16.,17.,18., 53.,54.,55.]
8025         self.assertEqual(expected1,a.getValues());
8026         pass
8027
8028     def testUMeshBuildSetInstanceFromThis1(self):
8029         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
8030         m2=m.buildSetInstanceFromThis(3);
8031         self.assertTrue(m.isEqual(m2,1e-12));
8032         #
8033         m=MEDCouplingUMesh.New("toto",2);
8034         m2=m.buildSetInstanceFromThis(3);
8035         self.assertEqual(0,m2.getNumberOfNodes());
8036         self.assertEqual(0,m2.getNumberOfCells());
8037         pass
8038
8039     def testUMeshMergeMeshesCVW1(self):
8040         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
8041         m2=MEDCouplingUMesh.New("toto",2);
8042         m3=MEDCouplingUMesh.MergeUMeshes([m,m2]);
8043         m3.setName(m.getName());
8044         self.assertTrue(m.isEqual(m3,1e-12));
8045         pass
8046     
8047     def testChangeUnderlyingMeshWithCMesh1(self):
8048         mesh=MEDCouplingCMesh.New();
8049         coordsX=DataArrayDouble.New();
8050         arrX=[ -1., 1., 2., 4. ]
8051         coordsX.setValues(arrX,4,1);
8052         coordsY=DataArrayDouble.New();
8053         arrY=[ -2., 2., 4., 8. ]
8054         coordsY.setValues(arrY,4,1);
8055         coordsZ=DataArrayDouble.New();
8056         arrZ=[ -3., 3., 6., 12. ]
8057         coordsZ.setValues(arrZ,4,1);
8058         mesh.setCoords(coordsX,coordsY,coordsZ);
8059         f=mesh.getMeasureField(True)
8060         mesh2=mesh.deepCpy()
8061         for myId in [0,1,2,10,11,12,20,21,22]:
8062             f=mesh.getMeasureField(True)
8063             f.changeUnderlyingMesh(mesh2,myId,1e-12);
8064             pass
8065         mesh2.setName("uuuu")
8066         for myId in [1,2,10,11,12,20,21,22]:
8067             f=mesh.getMeasureField(True)
8068             f.changeUnderlyingMesh(mesh2,myId,1e-12);
8069             pass
8070         pass
8071
8072     def testDADFindCommonTuples1(self):
8073         da=DataArrayDouble.New();
8074         # nbOftuples=1
8075         array1=[2.3,1.2,1.3,2.3,2.301,0.8]
8076         da.setValues(array1,6,1)
8077         c,cI=da.findCommonTuples(1e-2);
8078         expected1=[0,3,4]
8079         expected2=[0,3]
8080         self.assertEqual(3,c.getNbOfElems());
8081         self.assertEqual(2,cI.getNbOfElems());
8082         self.assertEqual(expected1,c.getValues())
8083         self.assertEqual(expected2,cI.getValues())
8084         c,cI=da.findCommonTuples(2e-1)
8085         expected3=[0,3,4,1,2]
8086         expected4=[0,3,5]
8087         self.assertEqual(5,c.getNbOfElems());
8088         self.assertEqual(3,cI.getNbOfElems());
8089         self.assertEqual(expected3,c.getValues())
8090         self.assertEqual(expected4,cI.getValues())
8091         # nbOftuples=2
8092         array2=[2.3,2.3,1.2,1.2,1.3,1.3,2.3,2.3,2.301,2.301,0.8,0.8]
8093         da.setValues(array2,6,2)
8094         c,cI=da.findCommonTuples(1e-2);
8095         self.assertEqual(3,c.getNbOfElems());
8096         self.assertEqual(2,cI.getNbOfElems());
8097         self.assertEqual(expected1,c.getValues())
8098         self.assertEqual(expected2,cI.getValues())
8099         c,cI=da.findCommonTuples(2e-1)
8100         self.assertEqual(5,c.getNbOfElems());
8101         self.assertEqual(3,cI.getNbOfElems());
8102         self.assertEqual(expected3,c.getValues())
8103         self.assertEqual(expected4,cI.getValues())
8104         # nbOftuples=3
8105         array3=[2.3,2.3,2.3,1.2,1.2,1.2,1.3,1.3,1.3,2.3,2.3,2.3,2.301,2.301,2.301,0.8,0.8,0.8]
8106         da.setValues(array3,6,3)
8107         c,cI=da.findCommonTuples(1e-2);
8108         self.assertEqual(3,c.getNbOfElems());
8109         self.assertEqual(2,cI.getNbOfElems());
8110         self.assertEqual(expected1,c.getValues())
8111         self.assertEqual(expected2,cI.getValues())
8112         c,cI=da.findCommonTuples(2e-1)
8113         self.assertEqual(5,c.getNbOfElems());
8114         self.assertEqual(3,cI.getNbOfElems());
8115         self.assertEqual(expected3,c.getValues())
8116         self.assertEqual(expected4,cI.getValues())
8117         # nbOftuples=1, no common groups
8118         array11=[2.3,1.2,1.3,2.4,2.5,0.8]
8119         da.setValues(array11,6,1)
8120         c,cI=da.findCommonTuples(1e-2);
8121         self.assertEqual(0,c.getNbOfElems());
8122         self.assertEqual(1,cI.getNbOfElems());
8123         self.assertEqual([0],cI.getValues())
8124         
8125         array12=[0.]*(6*5)
8126         da.setValues(array12,6,5) #bad NumberOfComponents
8127         self.assertRaises(InterpKernelException, da.findCommonTuples, 1e-2);
8128         pass
8129
8130     def testDABack1(self):
8131         da=DataArrayDouble.New();
8132         array1=[2.3,1.2,1.3,2.3,2.301,0.8]
8133         da.setValues(array1,6,1);
8134         self.assertAlmostEqual(0.8,da.back(),14);
8135         da.rearrange(2);
8136         self.assertRaises(InterpKernelException,da.back);
8137         da.alloc(0,1);
8138         self.assertRaises(InterpKernelException,da.back);
8139         #
8140         da=DataArrayInt.New();
8141         array2=[4,7,8,2]
8142         da.setValues(array2,4,1);
8143         self.assertEqual(2,da.back());
8144         da.rearrange(2);
8145         self.assertRaises(InterpKernelException,da.back);
8146         da.alloc(0,1);
8147         self.assertRaises(InterpKernelException,da.back);
8148         pass
8149
8150     def testDADGetDifferentValues1(self):
8151         da=DataArrayDouble.New();
8152         array1=[2.3,1.2,1.3,2.3,2.301,0.8]
8153         da.setValues(array1,6,1)
8154         #
8155         expected1=[2.301,1.2,1.3,0.8]
8156         dv=da.getDifferentValues(1e-2);
8157         self.assertEqual(4,dv.getNbOfElems());
8158         for i in xrange(4):
8159             self.assertAlmostEqual(expected1[i],dv.getIJ(i,0),14);
8160             pass
8161         #
8162         dv=da.getDifferentValues(2e-1);
8163         expected2=[2.301,1.3,0.8]
8164         self.assertEqual(3,dv.getNbOfElems());
8165         for i in xrange(3):
8166             self.assertAlmostEqual(expected2[i],dv.getIJ(i,0),14);
8167             pass
8168         pass
8169
8170     def testDAIBuildOld2NewArrayFromSurjectiveFormat2(self):
8171         arr=[0,3, 5,7,9]
8172         arrI=[0,2,5]
8173         a=DataArrayInt.New();
8174         a.setValues(arr,5,1);
8175         b=DataArrayInt.New();
8176         b.setValues(arrI,3,1);
8177         ret,newNbTuple=DataArrayInt.BuildOld2NewArrayFromSurjectiveFormat2(10,a,b);
8178         expected=[0,1,2,0,3,4,5,4,6,4]
8179         self.assertEqual(10,ret.getNbOfElems());
8180         self.assertEqual(7,newNbTuple);
8181         self.assertEqual(1,ret.getNumberOfComponents());
8182         self.assertEqual(expected,ret.getValues());
8183         self.assertRaises(InterpKernelException,DataArrayInt.BuildOld2NewArrayFromSurjectiveFormat2,9,a,b);
8184         pass
8185
8186     def testDADIReverse1(self):
8187         arr=[0,3,5,7,9,2]
8188         a=DataArrayInt.New();
8189         a.setValues(arr,6,1);
8190         self.assertEqual(2,a.back());
8191         a.reverse();
8192         for i in xrange(6):
8193             self.assertEqual(arr[5-i],a.getIJ(i,0));
8194             pass
8195         a.setValues(arr[:-1],5,1);
8196         a.reverse();
8197         for i in xrange(5):
8198             self.assertEqual(arr[4-i],a.getIJ(i,0));
8199             pass
8200         #
8201         arr2=[0.,3.,5.,7.,9.,2.]
8202         b=DataArrayDouble.New();
8203         b.setValues(arr2,6,1);
8204         b.reverse();
8205         for i in xrange(6):
8206             self.assertAlmostEqual(arr2[5-i],b.getIJ(i,0),14);
8207             pass
8208         b.setValues(arr2[:5],5,1);
8209         self.assertAlmostEqual(9.,b.back(),14)
8210         b.reverse();
8211         for i in xrange(5):
8212             self.assertAlmostEqual(arr2[4-i],b.getIJ(i,0),14);
8213             pass
8214         pass
8215
8216     def testGetNodeIdsInUse1(self):
8217         m0=MEDCouplingDataForTest.build2DTargetMesh_1();
8218         CellIds=[1,2]
8219         m1=m0.buildPartOfMySelf(CellIds,True);
8220         arr,newNbOfNodes=m1.getNodeIdsInUse();
8221         expected=[-1,0,1,-1,2,3,-1,-1,-1]
8222         self.assertEqual(4,newNbOfNodes);
8223         self.assertEqual(9,arr.getNbOfElems());
8224         self.assertEqual(expected,arr.getValues());
8225         arr2=arr.invertArrayO2N2N2O(newNbOfNodes);
8226         self.assertEqual(4,arr2.getNbOfElems());
8227         expected2=[1,2,4,5]
8228         self.assertEqual(expected2,arr2.getValues());
8229         pass
8230
8231     def testBuildDescendingConnec2(self):
8232         mesh=MEDCouplingDataForTest.build2DTargetMesh_1();
8233         #
8234         mesh2,desc,descIndx,revDesc,revDescIndx=mesh.buildDescendingConnectivity2();
8235         mesh2.checkCoherency();
8236         self.assertEqual(1,mesh2.getMeshDimension());
8237         self.assertEqual(13,mesh2.getNumberOfCells());
8238         self.assertEqual(14,revDescIndx.getNbOfElems()); self.assertEqual(14,revDescIndx.getNumberOfTuples());
8239         self.assertEqual(6,descIndx.getNbOfElems()); self.assertEqual(6,descIndx.getNumberOfTuples());
8240         self.assertEqual(18,desc.getNbOfElems()); self.assertEqual(18,desc.getNumberOfTuples());
8241         self.assertEqual(18,revDesc.getNbOfElems()); self.assertEqual(18,revDesc.getNumberOfTuples());
8242         expected1=[1,2,3,4,-3,5,6, 7,8,-5,9,10,-2,11, 12,13,-7,-10]
8243         self.assertEqual(expected1,desc.getValues());
8244         expected2=[0,4,7,10,14,18]
8245         self.assertEqual(expected2,descIndx.getValues());
8246         expected3=[0,1,3,5,6,8,9,11,12,13,15,16,17,18]
8247         self.assertEqual(expected3,revDescIndx.getValues());
8248         expected4=[0, 0,3, 0,1, 0, 1,2, 1, 2,4, 2, 3, 3,4, 3, 4, 4]
8249         self.assertEqual(expected4,revDesc.getValues());
8250         conn=mesh2.getNodalConnectivity();
8251         connIndex=mesh2.getNodalConnectivityIndex();
8252         expected5=[0,3,6,9,12,15,18,21,24,27,30,33,36,39]
8253         self.assertEqual(expected5,connIndex.getValues());
8254         expected6=[1, 0, 3, 1, 3, 4, 1, 4, 1, 1, 1, 0, 1, 4, 2, 1, 2, 1, 1, 4, 5, 1, 5, 2, 1, 6, 7, 1, 7, 4, 1, 3, 6, 1, 7, 8, 1, 8, 5]
8255         self.assertEqual(expected6,conn.getValues());
8256         pass
8257
8258     def testIntersect2DMeshesTmp1(self):
8259         m1c=MEDCouplingCMesh.New();
8260         coordsX=DataArrayDouble.New();
8261         arrX=[ -1., 1., 2., 4. ]
8262         coordsX.setValues(arrX,4,1);
8263         m1c.setCoordsAt(0,coordsX);
8264         coordsY=DataArrayDouble.New();
8265         arrY=[ -2., 2., 4., 8. ]
8266         coordsY.setValues(arrY,4,1);
8267         m1c.setCoordsAt(1,coordsY);
8268         m1=m1c.buildUnstructured()
8269         m1bis=m1.buildPartOfMySelf([3,4,5],False)
8270         m2=m1.deepCpy()
8271         m2=m2.buildPartOfMySelf([0,1,2],False)
8272         m2.translate([0.5,0.5])
8273         #
8274         m3,d1,d2=MEDCouplingUMesh.Intersect2DMeshes(m1bis,m2,1e-10)
8275         expected1=[0,0,1,1,1,2,2,2]
8276         expected2=[0,-1,0,1,-1,1,2,-1]
8277         self.assertEqual(8,d1.getNumberOfTuples());
8278         self.assertEqual(8,d2.getNumberOfTuples());
8279         self.assertEqual(8,m3.getNumberOfCells());
8280         self.assertEqual(22,m3.getNumberOfNodes());
8281         self.assertEqual(2,m3.getSpaceDimension());
8282         self.assertEqual(expected1,d1.getValues());
8283         self.assertEqual(expected2,d2.getValues());
8284         expected3=[5,17,1,16,12,5,16,0,4,5,17,12,5,18,1,17,13,5,19,2,18,13,5,17,5,6,19,13,5,20,2,19,14,5,21,3,20,14,5,19,6,7,21,14]
8285         expected4=[0,5,12,17,22,28,33,38,44]
8286         expected5=[-1.0,2.0,1.0,2.0,2.0,2.0,4.0,2.0,-1.0,4.0,1.0,4.0,2.0,4.0,4.0,4.0,-0.5,-1.5,1.5,-1.5,2.5,-1.5,4.5,-1.5,-0.5,2.5,1.5,2.5,2.5,2.5,4.5,2.5,-0.5,2.0,1.0,2.5,1.5,2.0,2.0,2.5,2.5,2.0,4.0,2.5]
8287         self.assertEqual(44,m3.getNodalConnectivity().getNumberOfTuples());
8288         self.assertEqual(9,m3.getNodalConnectivityIndex().getNumberOfTuples());
8289         self.assertEqual(expected3,m3.getNodalConnectivity().getValues());
8290         self.assertEqual(expected4,m3.getNodalConnectivityIndex().getValues());
8291         for i in xrange(44):
8292             self.assertAlmostEqual(expected5[i],m3.getCoords().getIJ(0,i),12);
8293             pass
8294         pass
8295
8296     def testFindNodesOnLine1(self):
8297         mesh=MEDCouplingDataForTest.build2DTargetMesh_1();
8298         pt=[-0.3,-0.3]
8299         pt2=[0.,0.,0.]
8300         pt3=[-0.3,0.,0.]
8301         vec=[0.,1.]
8302         vec2=[1.,0.,0.]
8303         vec3=[0.,1.,1.]
8304         expected1=[0,3,6]
8305         res=mesh.findNodesOnLine(pt,vec,1e-12);
8306         self.assertEqual(3,len(res));
8307         self.assertEqual(expected1,res.getValues());
8308         #
8309         mesh.changeSpaceDimension(3);
8310         mesh.rotate(pt2,vec2,pi/4.);
8311         res=mesh.findNodesOnLine(pt3,vec3,1e-12);
8312         self.assertEqual(3,len(res));
8313         self.assertEqual(expected1,res.getValues());
8314         pass
8315
8316     def testIntersect2DMeshesTmp2(self):
8317         m1c=MEDCouplingCMesh.New();
8318         coordsX1=DataArrayDouble.New();
8319         arrX1=[ 0., 1., 1.5, 2. ]
8320         coordsX1.setValues(arrX1,4,1);
8321         m1c.setCoordsAt(0,coordsX1);
8322         coordsY1=DataArrayDouble.New();
8323         arrY1=[ 0., 1.5, 3.]
8324         coordsY1.setValues(arrY1,3,1);
8325         m1c.setCoordsAt(1,coordsY1);
8326         m1=m1c.buildUnstructured();
8327         m2c=MEDCouplingCMesh.New();
8328         coordsX2=DataArrayDouble.New();
8329         arrX2=[ 0., 1., 2. ]
8330         coordsX2.setValues(arrX2,3,1);
8331         m2c.setCoordsAt(0,coordsX2);
8332         coordsY2=DataArrayDouble.New();
8333         arrY2=[ 0., 1., 3.]
8334         coordsY2.setValues(arrY2,3,1);
8335         m2c.setCoordsAt(1,coordsY2);
8336         m2=m2c.buildUnstructured();
8337         #
8338         m3,d1,d2=MEDCouplingUMesh.Intersect2DMeshes(m1,m2,1e-10)
8339         #
8340         expected1=[0,0,1,1,2,2,3,4,5]
8341         expected2=[0,2,1,3,1,3,2,3,3]
8342         self.assertEqual(9,d1.getNumberOfTuples());
8343         self.assertEqual(9,d2.getNumberOfTuples());
8344         self.assertEqual(9,m3.getNumberOfCells());
8345         self.assertEqual(22,m3.getNumberOfNodes());
8346         self.assertEqual(2,m3.getSpaceDimension());
8347         self.assertEqual(expected1,d1.getValues());
8348         self.assertEqual(expected2,d2.getValues());
8349         expected3=[5,16,13,12,15,5,15,4,5,16,5,21,2,13,16,5,16,5,6,21,5,17,14,2,21,5,21,6,7,17,5,4,18,19,5,5,5,19,10,6,5,6,10,20,7]
8350         expected4=[0,5,10,15,20,25,30,35,40,45]
8351         expected5=[0.0,0.0,1.0,0.0,1.5,0.0,2.0,0.0,0.0,1.5,1.0,1.5,1.5,1.5,2.0,1.5,0.0,3.0,1.0,3.0,1.5,3.0,2.0,3.0,0.0,0.0,1.0,0.0,2.0,0.0,0.0,1.0,1.0,1.0,2.0,1.0,0.0,3.0,1.0,3.0,2.0,3.0,1.5,1.0]
8352         self.assertEqual(45,m3.getNodalConnectivity().getNumberOfTuples());
8353         self.assertEqual(10,m3.getNodalConnectivityIndex().getNumberOfTuples());
8354         self.assertEqual(expected3,m3.getNodalConnectivity().getValues());
8355         self.assertEqual(expected4,m3.getNodalConnectivityIndex().getValues());
8356         for i in xrange(44):
8357             self.assertAlmostEqual(expected5[i],m3.getCoords().getIJ(0,i),12);
8358             pass
8359         pass
8360     
8361     def testBuildPartOfMySelfSafe1(self):
8362         mesh=MEDCouplingDataForTest.build2DTargetMesh_1()
8363         self.assertRaises(InterpKernelException,mesh.buildPartOfMySelf,[0,-1,4,2],True)
8364         self.assertRaises(InterpKernelException,mesh.buildPartOfMySelf,[0,4,5,4],True)
8365         pass
8366
8367     def testIntersect2DMeshesTmp3(self):
8368         m1Coords=[0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1,0.,-1.5,0.5,0.,1.25,0.,0.70710678118654757,0.70710678118654757,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.70710678118654757,0.70710678118654757,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.70710678118654757,-0.70710678118654757,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.70710678118654757,-0.70710678118654757,1.0606601717798214,-1.0606601717798214];
8369         m1Conn=[0,3,1,13,11,9, 3,4,2,1,14,12,10,11, 5,3,0,15,13,17, 6,4,3,5,16,14,15,18, 5,0,7,17,21,19, 6,5,7,8,18,19,22,20, 0,1,7,9,23,21, 1,2,8,7,10,24,22,23];
8370         m1=MEDCouplingUMesh.New();
8371         m1.setMeshDimension(2);
8372         m1.allocateCells(8);
8373         m1.insertNextCell(NORM_TRI6,6,m1Conn[0:6]);
8374         m1.insertNextCell(NORM_QUAD8,8,m1Conn[6:14]);
8375         m1.insertNextCell(NORM_TRI6,6,m1Conn[14:20]);
8376         m1.insertNextCell(NORM_QUAD8,8,m1Conn[20:28]);
8377         m1.insertNextCell(NORM_TRI6,6,m1Conn[28:34]);
8378         m1.insertNextCell(NORM_QUAD8,8,m1Conn[34:42]);
8379         m1.insertNextCell(NORM_TRI6,6,m1Conn[42:48]);
8380         m1.insertNextCell(NORM_QUAD8,8,m1Conn[48:56]);
8381         m1.finishInsertingCells();
8382         myCoords1=DataArrayDouble.New();
8383         myCoords1.setValues(m1Coords,25,2);
8384         m1.setCoords(myCoords1);
8385         #
8386         m2Coords=[0.,0.,1.1,0.,1.1,1.,0.,1.,1.7,0.,1.7,1.,-1.1,1.,-1.1,0.,-1.7,0.,-1.7,1.,-1.7,-1,-1.1,-1.,0.,-1.,1.1,-1,1.7,-1.]
8387         m2Conn=[0,3,2,1, 1,2,5,4, 7,6,3,0, 8,9,6,7, 7,0,12,11, 8,7,11,10, 0,1,13,12, 1,4,14,13]
8388         m2=MEDCouplingUMesh.New();
8389         m2.setMeshDimension(2);
8390         m2.allocateCells(8);
8391         for i in xrange(8):
8392             m2.insertNextCell(NORM_QUAD4,4,m2Conn[4*i:4*(i+1)])
8393             pass
8394         m2.finishInsertingCells();
8395         myCoords2=DataArrayDouble.New();
8396         myCoords2.setValues(m2Coords,15,2);
8397         m2.setCoords(myCoords2);
8398         #
8399         m3,d1,d2=MEDCouplingUMesh.Intersect2DMeshes(m1,m2,1e-10)
8400         m3.unPolyze()
8401         #
8402         expected1=[0,1,1,1,2,3,3,3,4,5,5,5,6,7,7,7]
8403         expected2=[0,0,1,-1,2,2,3,-1,4,4,5,-1,6,6,7,-1]
8404         self.assertEqual(16,d1.getNumberOfTuples());
8405         self.assertEqual(16,d2.getNumberOfTuples());
8406         self.assertEqual(16,m3.getNumberOfCells());
8407         self.assertEqual(104,m3.getNumberOfNodes());
8408         self.assertEqual(2,m3.getSpaceDimension());
8409         self.assertEqual(expected1,d1.getValues());
8410         self.assertEqual(expected2,d2.getValues());
8411         expected3=[6,28,1,25,44,45,46,8,26,1,28,27,47,48,49,50,8,40,2,26,27,51,52,53,54,8,28,4,40,27,55,56,57,58,6,28,25,5,59,60,61,8,28,5,32,31,62,63,64,65,8,32,6,41,31,66,67,68,69,8,41,4,28,31,70,71,72,73,6,25,37,5,74,75,76,8,32,5,37,36,77,78,79,80,8,42,6,32,36,81,82,83,84,8,37,8,42,36,85,86,87,88,6,1,37,25,89,90,91,8,37,1,26,38,92,93,94,95,8,26,2,43,38,96,97,98,99,8,43,8,37,38,100,101,102,103]
8412         expected4=[0,7,16,25,34,41,50,59,68,75,84,93,102,109,118,127,136]
8413         expected5=[0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1.,0.,-1.5,0.5,0.,1.25,0.,0.7071067811865476,0.7071067811865476,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.7071067811865476,0.7071067811865476,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.7071067811865476,-0.7071067811865476,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.7071067811865476,-0.7071067811865476,1.0606601717798214,-1.0606601717798214,0.,0.,1.1,0.,1.1,1.,0.,1.,1.7,0.,1.7,1.,-1.1,1.,-1.1,0.,-1.7,0.,-1.7,1.,-1.7,-1.,-1.1,-1.,0.,-1.,1.1,-1.,1.7,-1.,1.118033988749895,1.,-1.118033988749895,1.,-1.118033988749895,-1.,1.118033988749895,-1.,0.7071067811865477,0.7071067811865476,0.5,0.,0.,0.5,1.05,0.,0.7071067811865475,0.7071067811865477,0.55,1.,1.1,0.5,1.4012585384440737,0.535233134659635,1.3,0.,1.1,0.5,1.1090169943749475,1.,0.,1.25,0.6123724356957946,1.369306393762915,1.1090169943749475,1.,0.55,1.,0.,0.5,-0.5,0.,-0.7071067811865477,0.7071067811865476,-0.7071067811865475,0.7071067811865477,-1.05,0.,-1.1,0.5,-0.55,1.,-1.3,0.,-1.4012585384440737,0.5352331346596344,-1.1090169943749475,1.,-1.1,0.5,-0.6123724356957941,1.3693063937629155,0.,1.25,-0.55,1.,-1.1090169943749475,1.,0.,-0.5,-0.7071067811865475,-0.7071067811865477,-0.5,0.,-1.05,0.,-0.7071067811865478,-0.7071067811865475,-0.55,-1.,-1.1,-0.5,-1.4012585384440734,-0.5352331346596354,-1.3,0.,-1.1,-0.5,-1.1090169943749475,-1.,0.,-1.25,-0.6123724356957945,-1.369306393762915,-1.1090169943749475,-1.,-0.55,-1.,0.7071067811865475,-0.7071067811865477,0.,-0.5,0.5,0.,0.7071067811865477,-0.7071067811865475,1.05,0.,1.1,-0.5,0.55,-1.,1.3,0.,1.4012585384440737,-0.535233134659635,1.1090169943749475,-1.,1.1,-0.5,0.6123724356957946,-1.369306393762915,0.,-1.25,0.55,-1.,1.1090169943749475,-1.0]
8414         self.assertEqual(136,m3.getNodalConnectivity().getNumberOfTuples());
8415         self.assertEqual(17,m3.getNodalConnectivityIndex().getNumberOfTuples());
8416         self.assertEqual(expected3,m3.getNodalConnectivity().getValues());
8417         self.assertEqual(expected4,m3.getNodalConnectivityIndex().getValues());
8418         for i in xrange(208):
8419             self.assertAlmostEqual(expected5[i],m3.getCoords().getIJ(0,i),12);
8420             pass
8421         pass
8422
8423     def testUMeshTessellate2D1(self):
8424         m1Coords=[0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1,0.,-1.5,0.5,0.,1.25,0.,0.70710678118654757,0.70710678118654757,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.70710678118654757,0.70710678118654757,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.70710678118654757,-0.70710678118654757,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.70710678118654757,-0.70710678118654757,1.0606601717798214,-1.0606601717798214];
8425         m1Conn=[0,3,1,13,11,9, 3,4,2,1,14,12,10,11, 5,3,0,15,13,17, 6,4,3,5,16,14,15,18, 5,0,7,17,21,19, 6,5,7,8,18,19,22,20, 0,1,7,9,23,21, 1,2,8,7,10,24,22,23];
8426         m1=MEDCouplingUMesh.New();
8427         m1.setMeshDimension(2);
8428         m1.allocateCells(8);
8429         m1.insertNextCell(NORM_TRI6,6,m1Conn[0:6]);
8430         m1.insertNextCell(NORM_QUAD8,8,m1Conn[6:14]);
8431         m1.insertNextCell(NORM_TRI6,6,m1Conn[14:20]);
8432         m1.insertNextCell(NORM_QUAD8,8,m1Conn[20:28]);
8433         m1.insertNextCell(NORM_TRI6,6,m1Conn[28:34]);
8434         m1.insertNextCell(NORM_QUAD8,8,m1Conn[34:42]);
8435         m1.insertNextCell(NORM_TRI6,6,m1Conn[42:48]);
8436         m1.insertNextCell(NORM_QUAD8,8,m1Conn[48:56]);
8437         m1.finishInsertingCells();
8438         myCoords1=DataArrayDouble.New();
8439         myCoords1.setValues(m1Coords,25,2);
8440         m1.setCoords(myCoords1);
8441         #
8442         m11=m1.deepCpy();
8443         m11.tessellate2D(1.);
8444         self.assertTrue(m11.getCoords().isEqual(m11.getCoords(),1e-12));
8445         expected1=[5,0,3,11,1,5,3,4,12,2,1,11,5,5,15,3,0,5,6,16,4,3,15,5,5,5,0,7,19,5,6,5,19,7,8,20,5,0,1,23,7,5,1,2,24,8,7,23]
8446         expected2=[0,5,12,17,24,29,36,41,48]
8447         self.assertEqual(48,m11.getNodalConnectivity().getNumberOfTuples());
8448         self.assertEqual(9,m11.getNodalConnectivityIndex().getNumberOfTuples());
8449         self.assertEqual(expected1,m11.getNodalConnectivity().getValues());
8450         self.assertEqual(expected2,m11.getNodalConnectivityIndex().getValues());
8451         #
8452         m12=m1.deepCpy();
8453         m12.tessellate2D(0.5);
8454         self.assertEqual(41,m12.getNumberOfNodes());
8455         expected3=[5,0,3,25,26,1,5,3,4,27,28,2,1,26,25,5,5,29,30,3,0,5,6,31,32,4,3,30,29,5,5,5,0,7,33,34,5,6,5,34,33,7,8,35,36,5,0,1,37,38,7,5,1,2,39,40,8,7,38,37]
8456         expected4=[0,6,15,21,30,36,45,51,60]
8457         expected5=[0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1.,0.,-1.5,0.5,0.,1.25,0.,0.7071067811865476,0.7071067811865476,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.7071067811865476,0.7071067811865476,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.7071067811865476,-0.7071067811865476,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.7071067811865476,-0.7071067811865476,1.0606601717798214,-1.0606601717798214,0.479425538604203,0.8775825618903728,0.8414709848078964,0.54030230586814,0.7191383079063044,1.3163738428355591,1.2622064772118446,0.8104534588022099,-0.877582561890373,0.4794255386042027,-0.5403023058681399,0.8414709848078964,-1.3163738428355596,0.7191383079063038,-0.8104534588022098,1.2622064772118446,-0.4794255386042031,-0.8775825618903728,-0.8414709848078965,-0.5403023058681399,-0.7191383079063045,-1.3163738428355591,-1.2622064772118449,-0.8104534588022098,0.8775825618903729,-0.47942553860420295,0.54030230586814,-0.8414709848078964,1.3163738428355594,-0.7191383079063043,0.8104534588022099,-1.2622064772118446]
8458         for i in xrange(82):
8459             self.assertAlmostEqual(expected5[i],m12.getCoords().getIJ(0,i),12);
8460             pass
8461         self.assertEqual(60,m12.getNodalConnectivity().getNumberOfTuples());
8462         self.assertEqual(9,m12.getNodalConnectivityIndex().getNumberOfTuples());
8463         self.assertEqual(expected3,m12.getNodalConnectivity().getValues());
8464         self.assertEqual(expected4,m12.getNodalConnectivityIndex().getValues());
8465         pass
8466
8467     def testUMeshTessellate2DCurve1(self):
8468         # A quarter of circle:
8469         mcoords = [0.4,0.0,   0.0,-0.4,   0.283,-0.283]
8470         mconnec = [0,1,2]
8471
8472         m1 = MEDCouplingUMesh.New()
8473         m1.setMeshDimension(1)
8474         m1.allocateCells(1)
8475         m1.insertNextCell(NORM_SEG3, mconnec)
8476
8477         myCoords = DataArrayDouble.New(mcoords, 3, 2)
8478         m1.setCoords(myCoords)
8479         
8480         m2 = m1.deepCpy()
8481         m2.tessellate2DCurve(0.1)
8482         # If the following raises, the test will fail automatically:
8483         m2.checkCoherency1(0.0) # eps param not used
8484
8485     def testIntersect2DMeshesTmp4(self):
8486         m1Coords=[0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1,0.,-1.5,0.5,0.,1.25,0.,0.70710678118654757,0.70710678118654757,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.70710678118654757,0.70710678118654757,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.70710678118654757,-0.70710678118654757,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.70710678118654757,-0.70710678118654757,1.0606601717798214,-1.0606601717798214];
8487         m1Conn=[0,3,1,13,11,9, 3,4,2,1,14,12,10,11, 5,3,0,15,13,17, 6,4,3,5,16,14,15,18, 5,0,7,17,21,19, 6,5,7,8,18,19,22,20, 0,1,7,9,23,21, 1,2,8,7,10,24,22,23];
8488         m1=MEDCouplingUMesh.New();
8489         m1.setMeshDimension(2);
8490         m1.allocateCells(8);
8491         m1.insertNextCell(NORM_TRI6,6,m1Conn[0:6]);
8492         m1.insertNextCell(NORM_QUAD8,8,m1Conn[6:14]);
8493         m1.insertNextCell(NORM_TRI6,6,m1Conn[14:20]);
8494         m1.insertNextCell(NORM_QUAD8,8,m1Conn[20:28]);
8495         m1.insertNextCell(NORM_TRI6,6,m1Conn[28:34]);
8496         m1.insertNextCell(NORM_QUAD8,8,m1Conn[34:42]);
8497         m1.insertNextCell(NORM_TRI6,6,m1Conn[42:48]);
8498         m1.insertNextCell(NORM_QUAD8,8,m1Conn[48:56]);
8499         m1.finishInsertingCells();
8500         myCoords1=DataArrayDouble.New();
8501         myCoords1.setValues(m1Coords,25,2);
8502         m1.setCoords(myCoords1);
8503         #
8504         m2Coords=[0.,0.,1.1,0.,1.1,1.,0.,1.,1.7,0.,1.7,1.,-1.1,1.,-1.1,0.,-1.7,0.,-1.7,1.,-1.7,-1,-1.1,-1.,0.,-1.,1.1,-1,1.7,-1.]
8505         m2Conn=[0,3,2,1, 1,2,5,4, 7,6,3,0, 8,9,6,7, 7,0,12,11, 8,7,11,10, 0,1,13,12, 1,4,14,13]
8506         m2=MEDCouplingUMesh.New();
8507         m2.setMeshDimension(2);
8508         m2.allocateCells(8);
8509         for i in xrange(8):
8510             m2.insertNextCell(NORM_QUAD4,4,m2Conn[4*i:4*(i+1)])
8511             pass
8512         m2.finishInsertingCells();
8513         myCoords2=DataArrayDouble.New();
8514         myCoords2.setValues(m2Coords,15,2);
8515         m2.setCoords(myCoords2);
8516         #
8517         m3,d1,d2=MEDCouplingUMesh.Intersect2DMeshes(m2,m1,1e-10)
8518         m3.unPolyze()
8519         #
8520         expected1=[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7]
8521         expected2=[0,1,1,-1,2,3,3,-1,4,5,5,-1,6,7,7,-1]
8522         self.assertEqual(16,d1.getNumberOfTuples());
8523         self.assertEqual(16,d2.getNumberOfTuples());
8524         self.assertEqual(16,m3.getNumberOfCells());
8525         self.assertEqual(104,m3.getNumberOfNodes());
8526         self.assertEqual(2,m3.getSpaceDimension());
8527         self.assertEqual(expected1,d1.getValues());
8528         self.assertEqual(expected2,d2.getValues());
8529         expected3=[6,16,15,18,44,45,46,8,18,2,1,16,47,48,49,50,8,17,1,2,40,51,52,53,54,8,40,5,4,17,55,56,57,58,6,18,15,20,59,60,61,8,20,7,6,18,62,63,64,65,8,41,6,7,21,66,67,68,69,8,21,8,9,41,70,71,72,73,6,20,15,22,74,75,76,8,22,11,7,20,77,78,79,80,8,21,7,11,42,81,82,83,84,8,42,10,8,21,85,86,87,88,6,22,15,16,89,90,91,8,16,1,13,22,92,93,94,95,8,43,13,1,17,96,97,98,99,8,17,4,14,43,100,101,102,103]
8530         expected4=[0,7,16,25,34,41,50,59,68,75,84,93,102,109,118,127,136]
8531         expected5=[0.,0.,1.1, 0.,1.1,1.,0.,1.,1.7,0.,1.7,1.,-1.1,1.,-1.1,0.,-1.7,0.,-1.7,1.,-1.7,-1.,-1.1,-1.,0.,-1.,1.1,-1.,1.7,-1.,0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1.,0.,-1.5,0.5,0.,1.25,0.,0.7071067811865476,0.7071067811865476,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.7071067811865476,0.7071067811865476,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.7071067811865476,-0.7071067811865476,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.7071067811865476,-0.7071067811865476,1.0606601717798214,-1.0606601717798214,1.1180339887498951,1.,-1.1180339887498951,1.,-1.1180339887498951,-1.,1.1180339887498951,-1.,0.5,0.,0.,0.5,0.7071067811865477,0.7071067811865476,0.55,1.,1.1,0.5,1.05,0.,0.7071067811865477,0.7071067811865475,1.3,0.,1.1,0.5,1.1090169943749475,1.,1.4012585384440737,0.535233134659635,1.4090169943749475,1.,1.7,0.5,1.6,0.,1.4012585384440737,0.535233134659635,0.,0.5,-0.5,0.,-0.7071067811865477,0.7071067811865476,-1.05,0.,-1.1,0.5,-0.55,1.,-0.7071067811865478,0.7071067811865475,-1.1090169943749475,1.,-1.1,0.5,-1.3,0.,-1.4012585384440737,0.5352331346596344,-1.6,0.,-1.7,0.5,-1.4090169943749475,1.,-1.4012585384440737,0.5352331346596344,-0.5,0.,0.,-0.5,-0.7071067811865475,-0.7071067811865477,-0.55,-1.,-1.1,-0.5,-1.05,0.,-0.7071067811865475,-0.7071067811865477,-1.3,0.,-1.1,-0.5,-1.1090169943749475,-1.,-1.4012585384440734,-0.5352331346596354,-1.4090169943749475,-1.,-1.7,-0.5,-1.6,0.,-1.4012585384440732,-0.5352331346596354,0.,-0.5,0.5,0.,0.7071067811865475,-0.7071067811865477,1.05,0.,1.1,-0.5,0.55,-1.,0.7071067811865475,-0.7071067811865477,1.1090169943749475,-1.,1.1,-0.5,1.3,0.,1.4012585384440737,-0.535233134659635,1.6,0.,1.7,-0.5,1.4090169943749475,-1.,1.4012585384440737,-0.535233134659635]
8532         self.assertEqual(136,m3.getNodalConnectivity().getNumberOfTuples());
8533         self.assertEqual(17,m3.getNodalConnectivityIndex().getNumberOfTuples());
8534         self.assertEqual(expected3,m3.getNodalConnectivity().getValues());
8535         self.assertEqual(expected4,m3.getNodalConnectivityIndex().getValues());
8536         for i in xrange(208):
8537             self.assertAlmostEqual(expected5[i],m3.getCoords().getIJ(0,i),12);
8538             pass
8539         pass
8540
8541     def testGetCellIdsCrossingPlane1(self):
8542         mesh3D,mesh2D=MEDCouplingDataForTest.build3DExtrudedUMesh_1();
8543         vec=[-0.07,1.,0.07]
8544         origin=[1.524,1.4552,1.74768]
8545         ids1=mesh3D.getCellIdsCrossingPlane(origin,vec,1e-10)
8546         self.assertEqual([1,3,4,7,9,10,13,15,16],ids1.getValues())
8547         vec2=[0.,0.,1.]
8548         ids2=mesh3D.getCellIdsCrossingPlane(origin,vec2,1e-10)
8549         self.assertEqual([6,7,8,9,10,11],ids2.getValues())
8550         pass
8551
8552     def testBuildSlice3D1(self):
8553         mesh3D,mesh2D=MEDCouplingDataForTest.build3DExtrudedUMesh_1();
8554         vec1=[-0.07,1.,0.07]
8555         origin1=[1.524,1.4552,1.74768]
8556         slice1,ids=mesh3D.buildSlice3D(origin1,vec1,1e-10);
8557         expected1=[1,3,4,7,9,10,13,15,16]
8558         expected2=[5,42,41,40,43,44,5,42,46,45,41,5,44,43,40,47,48,5,49,42,44,50,5,49,51,46,42,5,50,44,48,52,5,53,49,50,54,5,53,55,51,49,5,54,50,52,56]
8559         expected3=[0,6,11,17,22,27,32,37,42,47]
8560         expected4=[1.,1.,0.,1.,1.25,0.,1.,1.5,0.,2.,1.,0.,1.,2.,0.,0.,2.,0.,3.,1.,0.,3.,2.,0.,0.,1.,0.,2.,2.,0.,1.,1.,1.,1.,1.25,1.,1.,1.5,1.,2.,1.,1.,1.,2.,1.,0.,2.,1.,3.,1.,1.,3.,2.,1.,0.,1.,1.,2.,2.,1.,1.,1.,2.,1.,1.25,2.,1.,1.5,2.,2.,1.,2.,1.,2.,2.,0.,2.,2.,3.,1.,2.,3.,2.,2.,0.,1.,2.,2.,2.,2.,1.,1.,3.,1.,1.25,3.,1.,1.5,3.,2.,1.,3.,1.,2.,3.,0.,2.,3.,3.,1.,3.,3.,2.,3.,0.,1.,3.,2.,2.,3.,1.,1.5408576,0.,2.,1.6108576000000001,0.,2.,1.5408576,1.,1.,1.5,0.5836800000000008,1.,1.4708576,1.,3.,1.6808576,0.,3.,1.6108576000000001,1.,0.,1.4708576,0.,0.,1.4008576,1.,2.,1.4708576,2.,1.,1.4008576000000001,2.,3.,1.5408575999999998,2.,0.,1.3308575999999999,2.,2.,1.4008576,3.,1.,1.3308576,3.,3.,1.4708576,3.,0.,1.2608576,3.]
8561         self.assertEqual(2,slice1.getMeshDimension());
8562         self.assertEqual(3,slice1.getSpaceDimension());
8563         self.assertEqual(57,slice1.getNumberOfNodes());
8564         self.assertEqual(9,slice1.getNumberOfCells());
8565         self.assertEqual(9,ids.getNumberOfTuples());
8566         self.assertEqual(47,slice1.getNodalConnectivity().getNumberOfTuples());
8567         self.assertEqual(10,slice1.getNodalConnectivityIndex().getNumberOfTuples());
8568         self.assertEqual(expected1,ids.getValues());
8569         self.assertEqual(expected2,slice1.getNodalConnectivity().getValues());
8570         self.assertEqual(expected3,slice1.getNodalConnectivityIndex().getValues());
8571         for i in xrange(171):
8572             self.assertAlmostEqual(expected4[i],slice1.getCoords().getIJ(0,i),12);
8573             pass
8574         # 2nd slice based on already existing nodes of mesh3D.
8575         vec2=[0.,3.,1.]
8576         origin2=[2.5,1.,3.]
8577         slice1,ids=mesh3D.buildSlice3D(origin2,vec2,1e-10);
8578         expected5=[5,50,10,4,51,5,50,52,7,10,5,51,4,5,53,5,54,50,51,55,56,5,54,57,52,50,5,56,55,51,53,58,5,38,59,56,54,43,5,54,57,46,43,5,38,59,56,58,48]
8579         expected6=[0,5,10,15,21,26,32,38,43,49]
8580         expected7=[1.,1.,0.,1.,1.25,0.,1.,1.5,0.,2.,1.,0.,1.,2.,0.,0.,2.,0.,3.,1.,0.,3.,2.,0.,0.,1.,0.,1.,3.,0.,2.,2.,0.,2.,3.,0.,1.,1.,1.,1.,1.25,1.,1.,1.5,1.,2.,1.,1.,1.,2.,1.,0.,2.,1.,3.,1.,1.,3.,2.,1.,0.,1.,1.,1.,3.,1.,2.,2.,1.,2.,3.,1.,0.,0.,2.,1.,1.,2.,1.,1.25,2.,1.,0.,2.,1.,1.5,2.,2.,0.,2.,2.,1.,2.,1.,2.,2.,0.,2.,2.,3.,1.,2.,3.,2.,2.,0.,1.,2.,2.,2.,2.,0.,0.,3.,1.,1.,3.,1.,1.25,3.,1.,0.,3.,1.,1.5,3.,2.,0.,3.,2.,1.,3.,1.,2.,3.,0.,2.,3.,3.,1.,3.,3.,2.,3.,0.,1.,3.,2.,2.,3.,2.,1.6666666666666667,1.,1.,1.6666666666666667,1.,3.,1.6666666666666667,1.,0.,1.6666666666666667,1.,2.,1.3333333333333335,2.,1.,1.5,1.5,1.,1.3333333333333333,2.,3.,1.3333333333333335,2.,0.,1.3333333333333335,2.,1.,1.25,2.25]
8581         self.assertEqual(2,slice1.getMeshDimension());
8582         self.assertEqual(3,slice1.getSpaceDimension());
8583         self.assertEqual(60,slice1.getNumberOfNodes());
8584         self.assertEqual(9,slice1.getNumberOfCells());
8585         self.assertEqual(9,ids.getNumberOfTuples());
8586         self.assertEqual(49,slice1.getNodalConnectivity().getNumberOfTuples());
8587         self.assertEqual(10,slice1.getNodalConnectivityIndex().getNumberOfTuples());
8588         self.assertEqual(expected1,ids.getValues());
8589         self.assertEqual(expected5,slice1.getNodalConnectivity().getValues());
8590         self.assertEqual(expected6,slice1.getNodalConnectivityIndex().getValues());
8591         for i in xrange(180):
8592             self.assertAlmostEqual(expected7[i],slice1.getCoords().getIJ(0,i),12);
8593             pass
8594         # 3rd slice based on shared face of mesh3D.
8595         vec3=[0.,0.,1.]
8596         origin3=[2.5,1.,2.]
8597         slice1,ids=mesh3D.buildSlice3D(origin3,vec3,1e-10);
8598         expected8=[6,7,8,9,10,11,12,13,14,15,16,17]
8599         expected9=[5,15,26,16,18,5,16,21,28,22,19,17,5,18,20,21,16,5,21,24,25,28,5,26,16,17,19,22,23,5,22,27,29,28,5,15,26,16,18,5,16,21,28,22,19,17,5,18,20,21,16,5,21,24,25,28,5,26,16,17,19,22,23,5,22,27,29,28]
8600         expected10=[0,5,12,17,22,29,34,39,46,51,56,63,68]
8601         expected11=[0.,0.,1.,1.,1.,1.,1.,1.25,1.,1.,0.,1.,1.,1.5,1.,2.,0.,1.,2.,1.,1.,1.,2.,1.,0.,2.,1.,3.,1.,1.,3.,2.,1.,0.,1.,1.,1.,3.,1.,2.,2.,1.,2.,3.,1.,0.,0.,2.,1.,1.,2.,1.,1.25,2.,1.,0.,2.,1.,1.5,2.,2.,0.,2.,2.,1.,2.,1.,2.,2.,0.,2.,2.,3.,1.,2.,3.,2.,2.,0.,1.,2.,1.,3.,2.,2.,2.,2.,2.,3.,2.,0.,0.,3.,1.,1.,3.,1.,1.25,3.,1.,0.,3.,1.,1.5,3.,2.,0.,3.,2.,1.,3.,1.,2.,3.,0.,2.,3.,3.,1.,3.,3.,2.,3.,0.,1.,3.,1.,3.,3.,2.,2.,3.,2.,3.,3.]
8602         self.assertEqual(2,slice1.getMeshDimension());
8603         self.assertEqual(3,slice1.getSpaceDimension());
8604         self.assertEqual(45,slice1.getNumberOfNodes());
8605         self.assertEqual(12,slice1.getNumberOfCells());
8606         self.assertEqual(12,ids.getNumberOfTuples());
8607         self.assertEqual(68,slice1.getNodalConnectivity().getNumberOfTuples());
8608         self.assertEqual(13,slice1.getNodalConnectivityIndex().getNumberOfTuples());
8609         self.assertEqual(expected8,ids.getValues());
8610         self.assertEqual(expected9,slice1.getNodalConnectivity().getValues());
8611         self.assertEqual(expected10,slice1.getNodalConnectivityIndex().getValues());
8612         for i in xrange(135):
8613             self.assertAlmostEqual(expected11[i],slice1.getCoords().getIJ(0,i),12);
8614             pass
8615         pass
8616
8617     def testBuildSlice3DSurf1(self):
8618         mesh3D,mesh2D=MEDCouplingDataForTest.build3DExtrudedUMesh_1();
8619         mesh2D=mesh3D.buildDescendingConnectivity()[0];
8620         vec1=[-0.07,1.,0.07]
8621         origin1=[1.524,1.4552,1.74768]
8622         slice1,ids=mesh2D.buildSlice3DSurf(origin1,vec1,1e-10);
8623         expected1=[6,8,10,11,13,18,19,21,23,25,26,38,41,43,47,49,52,53,64,67,69,73,75,78,79]
8624         expected2=[1,40,41,1,42,41,1,40,43,1,44,43,1,42,44,1,45,41,1,42,46,1,46,45,1,47,40,1,47,48,1,44,48,1,49,42,1,44,50,1,49,50,1,49,51,1,51,46,1,48,52,1,50,52,1,53,49,1,50,54,1,53,54,1,53,55,1,55,51,1,52,56,1,54,56]
8625         expected3=[0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75];
8626         expected4=[1.,1.,0.,1.,1.25,0.,1.,1.5,0.,2.,1.,0.,1.,2.,0.,0.,2.,0.,3.,1.,0.,3.,2.,0.,0.,1.,0.,2.,2.,0.,1.,1.,1.,1.,1.25,1.,1.,1.5,1.,2.,1.,1.,1.,2.,1.,0.,2.,1.,3.,1.,1.,3.,2.,1.,0.,1.,1.,2.,2.,1.,1.,1.,2.,1.,1.25,2.,1.,1.5,2.,2.,1.,2.,1.,2.,2.,0.,2.,2.,3.,1.,2.,3.,2.,2.,0.,1.,2.,2.,2.,2.,1.,1.,3.,1.,1.25,3.,1.,1.5,3.,2.,1.,3.,1.,2.,3.,0.,2.,3.,3.,1.,3.,3.,2.,3.,0.,1.,3.,2.,2.,3.,1.,1.5408576,0.,2.,1.6108576000000001,0.,2.,1.5408576,1.,1.,1.5,0.5836800000000008,1.,1.4708576,1.,3.,1.6808576,0.,3.,1.6108576000000001,1.,0.,1.4708576,0.,0.,1.4008576,1.,2.,1.4708576,2.,1.,1.4008576000000001,2.,3.,1.5408575999999998,2.,0.,1.3308575999999999,2.,2.,1.4008576,3.,1.,1.3308576,3.,3.,1.4708576,3.,0.,1.2608576,3.]
8627         self.assertEqual(1,slice1.getMeshDimension());
8628         self.assertEqual(3,slice1.getSpaceDimension());
8629         self.assertEqual(57,slice1.getNumberOfNodes());
8630         self.assertEqual(25,slice1.getNumberOfCells());
8631         self.assertEqual(25,ids.getNumberOfTuples());
8632         self.assertEqual(75,slice1.getNodalConnectivity().getNumberOfTuples());
8633         self.assertEqual(26,slice1.getNodalConnectivityIndex().getNumberOfTuples());
8634         self.assertEqual(expected1,ids.getValues());
8635         self.assertEqual(expected2,slice1.getNodalConnectivity().getValues());
8636         self.assertEqual(expected3,slice1.getNodalConnectivityIndex().getValues());
8637         for i in xrange(171):
8638             self.assertAlmostEqual(expected4[i],slice1.getCoords().getIJ(0,i),12);
8639             pass
8640         #
8641         vec2=[0.,0.,1.]
8642         origin2=[2.5,1.,2.]
8643         slice1,ids=mesh2D.buildSlice3DSurf(origin2,vec2,1e-10);
8644         expected5=[32,32,32,32,33,34,35,36,37,38,39,40,41,42,43,43,43,43,43,43,44,44,44,44,45,46,47,47,47,47,48,49,50,51,52,53,53,53,53,53,53,54,54,54,54,55,56,57,59,60,61,62,63,64,65,66,67,68,71,72,74,75,76,77,78,81,82,83]
8645         expected6=[1,15,18,1,18,16,1,16,26,1,26,15,1,26,15,1,16,26,1,18,16,1,15,18,1,16,21,1,21,28,1,22,28,1,19,22,1,17,19,1,16,17,1,16,21,1,21,28,1,28,22,1,22,19,1,19,17,1,17,16,1,16,18,1,18,20,1,20,21,1,21,16,1,20,21,1,18,20,1,28,21,1,21,24,1,24,25,1,25,28,1,25,28,1,24,25,1,21,24,1,23,22,1,26,23,1,26,16,1,16,17,1,17,19,1,19,22,1,22,23,1,23,26,1,22,28,1,28,29,1,29,27,1,27,22,1,27,22,1,29,27,1,28,29,1,26,15,1,16,26,1,18,16,1,15,18,1,16,21,1,21,28,1,22,28,1,19,22,1,17,19,1,16,17,1,20,21,1,18,20,1,25,28,1,24,25,1,21,24,1,23,22,1,26,23,1,27,22,1,29,27,1,28,29]
8646         expected7=[0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,99,102,105,108,111,114,117,120,123,126,129,132,135,138,141,144,147,150,153,156,159,162,165,168,171,174,177,180,183,186,189,192,195,198,201,204];
8647         expected8=[0.,0.,1.,1.,1.,1.,1.,1.25, 1.,1.,0.,1.,1.,1.5, 1.,2.,0.,1.,2.,1.,1.,1.,2.,1.,0.,2.,1.,3.,1.,1.,3.,2.,1.,0.,1.,1.,1.,3.,1.,2.,2.,1.,2.,3.,1.,0.,0.,2.,1.,1.,2.,1.,1.25, 2.,1.,0.,2.,1.,1.5, 2.,2.,0.,2.,2.,1.,2.,1.,2.,2.,0.,2.,2.,3.,1.,2.,3.,2.,2.,0.,1.,2.,1.,3.,2.,2.,2.,2.,2.,3.,2.,0.,0.,3.,1.,1.,3.,1.,1.25, 3.,1.,0.,3.,1.,1.5, 3.,2.,0.,3.,2.,1.,3.,1.,2.,3.,0.,2.,3.,3.,1.,3.,3.,2.,3.,0.,1.,3.,1.,3.,3.,2.,2.,3.,2.,3.,3.]
8648         self.assertEqual(1,slice1.getMeshDimension());
8649         self.assertEqual(3,slice1.getSpaceDimension());
8650         self.assertEqual(45,slice1.getNumberOfNodes());
8651         self.assertEqual(68,slice1.getNumberOfCells());
8652         self.assertEqual(68,ids.getNumberOfTuples());
8653         self.assertEqual(204,slice1.getNodalConnectivity().getNumberOfTuples());
8654         self.assertEqual(69,slice1.getNodalConnectivityIndex().getNumberOfTuples());
8655         self.assertEqual(expected5,ids.getValues());
8656         self.assertEqual(expected6,slice1.getNodalConnectivity().getValues());
8657         self.assertEqual(expected7,slice1.getNodalConnectivityIndex().getValues());
8658         for i in xrange(135):
8659             self.assertAlmostEqual(expected8[i],slice1.getCoords().getIJ(0,i),12);
8660             pass
8661         pass
8662
8663     def testDataArrayDoubleAdvSetting1(self):
8664         data1=[1.,11.,2.,12.,3.,13.,4.,14.,5.,15.,6.,16.,7.,17.]
8665         data2=[8.,38.,9.,39.,0.,30.,11.,41.,12.,42.]
8666         compsCpp=["comp1","comp2"]
8667         da=DataArrayDouble.New();
8668         da.setInfoAndChangeNbOfCompo(compsCpp);
8669         da.setName("da");
8670         da.alloc(7,2);
8671         compsCpp=compsCpp[:-1]
8672         self.assertRaises(InterpKernelException,da.setInfoAndChangeNbOfCompo,compsCpp);
8673         da.setValues(data1,7,2)
8674         #
8675         p=[(0,3),(3,5),(5,7)]
8676         tmp=da.selectByTupleRanges(p);
8677         self.assertTrue(tmp.isEqual(da,1e-14));
8678         p=[(0,2),(3,4),(5,7)]
8679         tmp=da.selectByTupleRanges(p);
8680         expected1=[1.,11.,2.,12.,4.,14.,6.,16.,7.,17.]
8681         self.assertEqual(5,tmp.getNumberOfTuples());
8682         self.assertEqual(2,tmp.getNumberOfComponents());
8683         for i in xrange(10):
8684             self.assertAlmostEqual(expected1[i],tmp.getIJ(0,i),14);
8685             pass
8686         p=[(0,2),(0,2),(5,6)]
8687         tmp=da.selectByTupleRanges(p);
8688         expected2=[1.,11.,2.,12.,1.,11.,2.,12.,6.,16.]
8689         self.assertEqual(5,tmp.getNumberOfTuples());
8690         self.assertEqual(2,tmp.getNumberOfComponents());
8691         for i in xrange(10):
8692             self.assertAlmostEqual(expected2[i],tmp.getIJ(0,i),14);
8693             pass
8694         p=[(0,2),(-1,2),(5,6)]
8695         self.assertRaises(InterpKernelException,da.selectByTupleRanges,p);
8696         p=[(0,2),(0,2),(5,8)]
8697         self.assertRaises(InterpKernelException,da.selectByTupleRanges,p);
8698         #
8699         da2=DataArrayDouble.New();
8700         da2.setValues(data2,5,2);
8701         #
8702         dac=da.deepCpy();
8703         dac.setContigPartOfSelectedValues2(1,da2,2,4,1);
8704         expected3=[1.,11.,0.,30.,11.,41.,4.,14.,5.,15.,6.,16.,7.,17.]
8705         for i in xrange(14):
8706             self.assertAlmostEqual(expected3[i],dac.getIJ(0,i),14);
8707             pass
8708         #
8709         dac=da.deepCpy();
8710         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues2,3,da2,0,5,1);
8711         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues2,0,da2,4,6,1);
8712         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues2,3,da2,5,0,1);
8713         dac.setContigPartOfSelectedValues2(3,da2,1,5,1);
8714         expected4=[1.,11.,2.,12.,3.,13.,9.,39.,0.,30.,11.,41.,12.,42.]
8715         for i in xrange(14):
8716             self.assertAlmostEqual(expected4[i],dac.getIJ(0,i),14);
8717             pass
8718         #
8719         ids=DataArrayInt.New();
8720         ids.alloc(3,1);
8721         dac=da.deepCpy();
8722         ids.setIJ(0,0,2); ids.setIJ(1,0,0); ids.setIJ(2,0,4);
8723         dac.setContigPartOfSelectedValues(2,da2,ids);
8724         expected5=[1.,11.,2.,12.,0.,30.,8.,38.,12.,42.,6.,16.,7.,17.]
8725         for i in xrange(14):
8726             self.assertAlmostEqual(expected5[i],dac.getIJ(0,i),14);
8727             pass
8728         #
8729         dac=da.deepCpy();
8730         ids.setIJ(0,0,2); ids.setIJ(1,0,5); ids.setIJ(2,0,4);
8731         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues,1,da2,ids);
8732         ids.setIJ(0,0,2); ids.setIJ(1,0,2); ids.setIJ(2,0,-1);
8733         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues,1,da2,ids);
8734         ids.setIJ(0,0,2); ids.setIJ(1,0,2); ids.setIJ(2,0,1);
8735         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues,5,da2,ids);
8736         #
8737         ids.setIJ(0,0,2); ids.setIJ(1,0,2); ids.setIJ(2,0,1);
8738         dac=da.deepCpy();
8739         dac.setContigPartOfSelectedValues(4,da2,ids);
8740         expected6=[1.,11.,2.,12.,3.,13.,4.,14.,0.,30.,0.,30.,9.,39.]
8741         for i in xrange(14):
8742             self.assertAlmostEqual(expected6[i],dac.getIJ(0,i),14);
8743             pass
8744         pass
8745
8746     def testDataArrayIntAdvSetting1(self):
8747         data1=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
8748         data2=[8,38,9,39,0,30,11,41,12,42]
8749         compsCpp=["comp1","comp2"]
8750         da=DataArrayInt.New();
8751         da.setInfoAndChangeNbOfCompo(compsCpp);
8752         da.setName("da");
8753         da.alloc(7,2);
8754         compsCpp=compsCpp[:-1]
8755         self.assertRaises(InterpKernelException,da.setInfoAndChangeNbOfCompo,compsCpp);
8756         da.setValues(data1,7,2)
8757         #
8758         p=[(0,3),(3,5),(5,7)]
8759         tmp=da.selectByTupleRanges(p);
8760         self.assertTrue(tmp.isEqual(da));
8761         p=[(0,2),(3,4),(5,7)]
8762         tmp=da.selectByTupleRanges(p);
8763         expected1=[1,11,2,12,4,14,6,16,7,17]
8764         self.assertEqual(5,tmp.getNumberOfTuples());
8765         self.assertEqual(2,tmp.getNumberOfComponents());
8766         for i in xrange(10):
8767             self.assertEqual(expected1[i],tmp.getIJ(0,i));
8768             pass
8769         p=[(0,2),(0,2),(5,6)]
8770         tmp=da.selectByTupleRanges(p);
8771         expected2=[1,11,2,12,1,11,2,12,6,16]
8772         self.assertEqual(5,tmp.getNumberOfTuples());
8773         self.assertEqual(2,tmp.getNumberOfComponents());
8774         for i in xrange(10):
8775             self.assertEqual(expected2[i],tmp.getIJ(0,i));
8776             pass
8777         p=[(0,2),(-1,2),(5,6)]
8778         self.assertRaises(InterpKernelException,da.selectByTupleRanges,p);
8779         p=[(0,2),(0,2),(5,8)]
8780         self.assertRaises(InterpKernelException,da.selectByTupleRanges,p);
8781         #
8782         da2=DataArrayInt.New();
8783         da2.setValues(data2,5,2);
8784         #
8785         dac=da.deepCpy();
8786         dac.setContigPartOfSelectedValues2(1,da2,2,4,1);
8787         expected3=[1,11,0,30,11,41,4,14,5,15,6,16,7,17]
8788         for i in xrange(14):
8789             self.assertEqual(expected3[i],dac.getIJ(0,i));
8790             pass
8791         #
8792         dac=da.deepCpy();
8793         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues2,3,da2,0,5,1);
8794         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues2,0,da2,4,6,1);
8795         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues2,3,da2,5,0,1);
8796         dac.setContigPartOfSelectedValues2(3,da2,1,5,1);
8797         expected4=[1,11,2,12,3,13,9,39,0,30,11,41,12,42]
8798         for i in xrange(14):
8799             self.assertEqual(expected4[i],dac.getIJ(0,i));
8800             pass
8801         #
8802         ids=DataArrayInt.New();
8803         ids.alloc(3,1);
8804         dac=da.deepCpy();
8805         ids.setIJ(0,0,2); ids.setIJ(1,0,0); ids.setIJ(2,0,4);
8806         dac.setContigPartOfSelectedValues(2,da2,ids);
8807         expected5=[1,11,2,12,0,30,8,38,12,42,6,16,7,17]
8808         for i in xrange(14):
8809             self.assertEqual(expected5[i],dac.getIJ(0,i));
8810             pass
8811         #
8812         dac=da.deepCpy();
8813         ids.setIJ(0,0,2); ids.setIJ(1,0,5); ids.setIJ(2,0,4);
8814         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues,1,da2,ids);
8815         ids.setIJ(0,0,2); ids.setIJ(1,0,2); ids.setIJ(2,0,-1);
8816         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues,1,da2,ids);
8817         ids.setIJ(0,0,2); ids.setIJ(1,0,2); ids.setIJ(2,0,1);
8818         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues,5,da2,ids);
8819         #
8820         ids.setIJ(0,0,2); ids.setIJ(1,0,2); ids.setIJ(2,0,1);
8821         dac=da.deepCpy();
8822         dac.setContigPartOfSelectedValues(4,da2,ids);
8823         expected6=[1,11,2,12,3,13,4,14,0,30,0,30,9,39]
8824         for i in xrange(14):
8825             self.assertEqual(expected6[i],dac.getIJ(0,i));
8826             pass
8827         pass
8828
8829     def testBuildDescendingConnec2Of3DMesh1(self):
8830         mesh=MEDCouplingDataForTest.build3DSourceMesh_1();
8831         #
8832         mesh2,desc,descIndx,revDesc,revDescIndx=mesh.buildDescendingConnectivity2();
8833         mesh2.checkCoherency();
8834         self.assertEqual(2,mesh2.getMeshDimension());
8835         self.assertEqual(30,mesh2.getNumberOfCells());
8836         self.assertEqual(31,revDescIndx.getNbOfElems()); self.assertEqual(31,revDescIndx.getNumberOfTuples());
8837         self.assertEqual(13,descIndx.getNbOfElems()); self.assertEqual(13,descIndx.getNumberOfTuples());
8838         self.assertEqual(48,desc.getNbOfElems()); self.assertEqual(48,desc.getNumberOfTuples());
8839         self.assertEqual(48,revDesc.getNbOfElems()); self.assertEqual(48,revDesc.getNumberOfTuples());
8840         expected1=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,-10,15,-5,-13,16,17,-14,18,-4,19,-2,20,21,22,23,24,25,-11,26,-1,-12,-25,-22,27,28,-7,-20,-24,29,-16,-18,30,-8,-28]
8841         self.assertEqual(expected1,desc.getValues());
8842         expected2=[0,4,8,12,16,20,24,28,32,36,40,44,48]
8843         self.assertEqual(expected2,descIndx.getValues());
8844         expected3=[0,2,4,5,7,9,10,12,14,15,17,19,21,23,25,26,28,29,31,32,34,35,37,38,40,42,43,44,46,47,48]
8845         self.assertEqual(expected3,revDescIndx.getValues());
8846         expected4=[0,8,0,6,0,0,5,1,4,1,1,9,1,11,2,2,3,2,7,2,8,3,4,3,5,3,4,10,4,5,11,5,6,10,6,6,9,7,7,10,7,8,8,9,9,11,10,11]
8847         self.assertEqual(expected4,revDesc.getValues());
8848         conn=mesh2.getNodalConnectivity();
8849         connIndex=mesh2.getNodalConnectivityIndex();
8850         expected5=[0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120]
8851         self.assertEqual(expected5,connIndex.getValues());
8852         expected6=[3,8,1,7,3,8,3,1,3,1,3,7,3,7,3,8,3,6,0,8,3,6,2,0,3,0,2,8,3,8,2,6,3,7,4,5,3,7,8,4,3,4,8,5,3,5,8,7,3,6,8,4,3,6,7,8,3,4,7,6,3,8,4,0,3,0,4,6,3,6,3,8,3,7,3,6,3,8,0,1,3,1,0,3,3,3,0,8,3,4,1,5,3,4,8,1,3,1,8,5,3,1,7,5,3,0,2,3,3,3,2,8,3,1,4,0,3,3,2,6]
8853         self.assertEqual(expected6,conn.getValues());
8854         pass
8855
8856     def testAre2DCellsNotCorrectlyOriented1(self):
8857         m1Coords=[1.,1.,-1.,-1.,-1.,-1.,1.,-1.]
8858         m1Conn=[0,3,1,2]
8859         m1=MEDCouplingUMesh.New();
8860         m1.setMeshDimension(2);
8861         m1.allocateCells(1);
8862         m1.insertNextCell(NORM_QUAD4,4,m1Conn[0:4])
8863         m1.finishInsertingCells();
8864         myCoords1=DataArrayDouble.New();
8865         myCoords1.setValues(m1Coords,4,2);
8866         m1.setCoords(myCoords1);
8867         #
8868         vec1=[0.,0.,1.]
8869         for i in xrange(18):
8870             vec2=[3.*cos(pi/9.*i),3.*sin(pi/9.*i)];
8871             m1Cpy=m1.deepCpy();
8872             m1Cpy.translate(vec2);
8873             self.assertRaises(InterpKernelException,m1Cpy.are2DCellsNotCorrectlyOriented,vec1,False);
8874             m1Cpy.changeSpaceDimension(3);
8875             res=m1Cpy.are2DCellsNotCorrectlyOriented(vec1,False)
8876             self.assertEqual([0],res.getValues());
8877             pass
8878         pass
8879
8880     def testDataArrayAbs1(self):
8881         d1=DataArrayDouble.New();
8882         val1=[2.,-3.,-5.,6.,-7.,-8.,9.,10.,-11.,-12.,-13.,-15.]
8883         expected1=[2.,3.,5.,6.,7.,8.,9.,10.,11.,12.,13.,15.]
8884         d1.setValues(val1,6,2);
8885         d2=d1.convertToIntArr();
8886         #
8887         d1.abs();
8888         for i in xrange(12):
8889             self.assertAlmostEqual(expected1[i],d1.getIJ(0,i),14);
8890             pass
8891         #
8892         expected2=[2,3,5,6,7,8,9,10,11,12,13,15]
8893         d2.abs();
8894         for i in xrange(12):
8895             self.assertEqual(expected2[i],d2.getIJ(0,i));
8896             pass
8897         #
8898         pass
8899
8900     # test on 1D
8901     def testGetValueOn3(self):
8902         v=[0.,1.,1.5,2.]
8903         v2=[0.7,1.25,0.,2.,1.5]
8904         disp=[5.,50.,500.,6.,60.,600.,7.,70.,700.,8.,80.,800.]
8905         m=MEDCouplingUMesh.New("myMesh",1)
8906         nbNodes=len(v)
8907         nbCells=nbNodes-1
8908         m.allocateCells(nbCells)
8909         coords=DataArrayDouble.New() ; coords.setValues(v,nbNodes,1)
8910         m.setCoords(coords)
8911         m.insertNextCell(NORM_SEG2,2,[0,1])
8912         m.insertNextCell(NORM_SEG2,2,[2,1])
8913         m.insertNextCell(NORM_SEG2,2,[2,3])
8914         m.finishInsertingCells()
8915         f=MEDCouplingFieldDouble.New(ON_NODES)
8916         f.setMesh(m)
8917         array=DataArrayDouble.New(); array.setValues(disp,m.getNumberOfNodes(),3)
8918         f.setArray(array)
8919         arr1=f.getValueOnMulti(v2)
8920         self.assertEqual(5,arr1.getNumberOfTuples());
8921         self.assertEqual(3,arr1.getNumberOfComponents());
8922         expected1=[5.7,57.,570.,6.5,65.,650.,5.,50.,500.,8.,80.,800.,7.,70.,700.]
8923         for i in xrange(15):
8924             self.assertAlmostEqual(expected1[i],arr1.getIJ(0,i),14);
8925             pass
8926         pass
8927
8928     def testGetNodeIdsOfCell2(self):
8929         m1c=MEDCouplingCMesh.New();
8930         coordsX=DataArrayDouble.New();
8931         arrX=[ -1., 1., 2., 4., 4.5 ]
8932         coordsX.setValues(arrX,5,1);
8933         coordsY=DataArrayDouble.New();
8934         arrY=[ -2., 2., 4., 8.]
8935         coordsY.setValues(arrY,4,1);
8936         coordsZ=DataArrayDouble.New();
8937         arrZ=[ -2., 2., 4.]
8938         coordsZ.setValues(arrZ,3,1);
8939         # test in 1D
8940         m1c.setCoordsAt(0,coordsX);
8941         expected1=[[0,1],[1,2],[2,3],[3,4]]
8942         self.assertEqual(4,m1c.getNumberOfCells())
8943         for i in xrange(m1c.getNumberOfCells()):
8944             self.assertEqual(expected1[i],m1c.getNodeIdsOfCell(i))
8945             pass
8946         # test in 2D
8947         m1c.setCoordsAt(1,coordsY);
8948         self.assertEqual(12,m1c.getNumberOfCells())
8949         self.assertEqual(20,m1c.getNumberOfNodes())
8950         expected2=[[0,1,6,5],[1,2,7,6],[2,3,8,7],[3,4,9,8],[5,6,11,10],[6,7,12,11],[7,8,13,12],[8,9,14,13],[10,11,16,15],[11,12,17,16],[12,13,18,17],[13,14,19,18]]
8951         for i in xrange(m1c.getNumberOfCells()):
8952             self.assertEqual(expected2[i],m1c.getNodeIdsOfCell(i))
8953             pass
8954         # test in 3D
8955         m1c.setCoordsAt(2,coordsZ);
8956         self.assertEqual(24,m1c.getNumberOfCells())
8957         self.assertEqual(60,m1c.getNumberOfNodes())
8958         expected3=[[0,1,6,5,20,21,26,25],[1,2,7,6,21,22,27,26],[2,3,8,7,22,23,28,27],[3,4,9,8,23,24,29,28],[5,6,11,10,25,26,31,30],[6,7,12,11,26,27,32,31],[7,8,13,12,27,28,33,32],[8,9,14,13,28,29,34,33],[10,11,16,15,30,31,36,35],[11,12,17,16,31,32,37,36],[12,13,18,17,32,33,38,37],[13,14,19,18,33,34,39,38],[20,21,26,25,40,41,46,45],[21,22,27,26,41,42,47,46],[22,23,28,27,42,43,48,47],[23,24,29,28,43,44,49,48],[25,26,31,30,45,46,51,50],[26,27,32,31,46,47,52,51],[27,28,33,32,47,48,53,52],[28,29,34,33,48,49,54,53],[30,31,36,35,50,51,56,55],[31,32,37,36,51,52,57,56],[32,33,38,37,52,53,58,57],[33,34,39,38,53,54,59,58]]
8959         self.assertEqual(24,m1c.getNumberOfCells())
8960         for i in xrange(m1c.getNumberOfCells()):
8961             self.assertEqual(expected3[i],m1c.getNodeIdsOfCell(i))
8962             pass
8963         pass
8964     
8965     def testSwigDADOp4(self):
8966         da=DataArrayDouble.New(range(6,30),12,2)
8967         self.assertEqual(12,da.getNumberOfTuples());
8968         self.assertEqual(2,da.getNumberOfComponents());
8969         for i in xrange(24):
8970             self.assertAlmostEqual(da.getIJ(0,i),float(i+6),13)
8971             pass
8972         # operator transpose
8973         da.transpose()
8974         self.assertEqual(2,da.getNumberOfTuples());
8975         self.assertEqual(12,da.getNumberOfComponents());
8976         for i in xrange(24):
8977             self.assertAlmostEqual(da.getIJ(0,i),float(i+6),13)
8978             pass
8979         da.transpose()
8980         # operator __neg__
8981         da2=DataArrayDouble.New(12,1)
8982         da2.iota(0.)
8983         dabis=-da
8984         for i in xrange(24):
8985             self.assertAlmostEqual(dabis.getIJ(0,i),-float(i+6),13)
8986             pass
8987         # operator+=
8988         da+=da2
8989         expected1=[6.,7.,9.,10.,12.,13.,15.,16.,18.,19.,21.,22.,24.,25.,27.,28.,30.,31.,33.,34.,36.,37.,39.,40.]
8990         for i in xrange(24):
8991             self.assertAlmostEqual(da.getIJ(0,i),expected1[i],13)
8992             pass
8993         da=-dabis
8994         da+=[100.,101.]
8995         expected2=[106.,108.,108.,110.,110.,112.,112.,114.,114.,116.,116.,118.,118.,120.,120.,122.,122.,124.,124.,126.,126.,128.,128.,130.]
8996         self.assertEqual(12,da.getNumberOfTuples());
8997         self.assertEqual(2,da.getNumberOfComponents());
8998         for i in xrange(24):
8999             self.assertAlmostEqual(da.getIJ(0,i),expected2[i],13)
9000             pass
9001         for pos,elt in enumerate(dabis):
9002             da[pos]+=elt
9003             pass
9004         self.assertEqual(12,da.getNumberOfTuples());
9005         self.assertEqual(2,da.getNumberOfComponents());
9006         for elt in da:
9007             li=elt[:]
9008             self.assertAlmostEqual(li[0],100.,13) ; self.assertAlmostEqual(li[1],101.,13)
9009             pass
9010         # operator-=
9011         da=DataArrayDouble.New(range(6,30),12,2)
9012         da2=DataArrayDouble.New(range(12),12,1)
9013         dabis=-da
9014         da-=da2
9015         expected1=[6.,7.,7.,8.,8.,9.,9.,10.,10.,11.,11.,12.,12.,13.,13.,14.,14.,15.,15.,16.,16.,17.,17.,18.]
9016         for i in xrange(24):
9017             self.assertAlmostEqual(da.getIJ(0,i),expected1[i],13)
9018             pass
9019         da=-dabis
9020         da-=[100.,101.]
9021         expected2=[-94.,-94.,-92.,-92.,-90.,-90.,-88.,-88.,-86.,-86.,-84.,-84.,-82.,-82.,-80.,-80.,-78.,-78.,-76.,-76.,-74.,-74.,-72.,-72.]
9022         self.assertEqual(12,da.getNumberOfTuples());
9023         self.assertEqual(2,da.getNumberOfComponents());
9024         for i in xrange(24):
9025             self.assertAlmostEqual(da.getIJ(0,i),expected2[i],13)
9026             pass
9027         for pos,elt in enumerate(dabis):
9028             da[pos]-=elt
9029             pass
9030         self.assertEqual(12,da.getNumberOfTuples());
9031         self.assertEqual(2,da.getNumberOfComponents());
9032         expected3=[-88.,-87.,-84.,-83.,-80.,-79.,-76.,-75.,-72.,-71.,-68.,-67.,-64.,-63.,-60.,-59.,-56.,-55.,-52.,-51.,-48.,-47.,-44.,-43.]
9033         for i in xrange(24):
9034             self.assertAlmostEqual(da.getIJ(0,i),expected3[i],13)
9035             pass
9036         # operator*=
9037         da=DataArrayDouble.New(range(6,30),12,2)
9038         da2=DataArrayDouble.New(range(12),12,1)
9039         dabis=-da
9040         da*=da2
9041         expected1=[0.,0.,8.,9.,20.,22.,36.,39.,56.,60.,80.,85.,108.,114.,140.,147.,176.,184.,216.,225.,260.,270.,308.,319.]
9042         for i in xrange(24):
9043             self.assertAlmostEqual(da.getIJ(0,i),expected1[i],13)
9044             pass
9045         da=-dabis
9046         da*=[100.,101.]
9047         expected2=[600.,707.,800.,909.,1000.,1111.,1200.,1313.,1400.,1515.,1600.,1717.,1800.,1919.,2000.,2121.,2200.,2323.,2400.,2525.,2600.,2727.,2800.,2929.]
9048         self.assertEqual(12,da.getNumberOfTuples());
9049         self.assertEqual(2,da.getNumberOfComponents());
9050         for i in xrange(24):
9051             self.assertAlmostEqual(da.getIJ(0,i),expected2[i],13)
9052             pass
9053         for pos,elt in enumerate(dabis):
9054             da[pos]*=elt
9055             pass
9056         self.assertEqual(12,da.getNumberOfTuples());
9057         self.assertEqual(2,da.getNumberOfComponents());
9058         expected3=[-3600.,-4949.,-6400.,-8181.,-10000.,-12221.,-14400.,-17069.,-19600.,-22725.,-25600.,-29189.,-32400.,-36461.,-40000.,-44541.,-48400.,-53429.,-57600.,-63125.,-67600.,-73629.,-78400.,-84941.0]
9059         for i in xrange(24):
9060             self.assertAlmostEqual(da.getIJ(0,i),expected3[i],13)
9061             pass
9062         # operator/=
9063         da=DataArrayDouble.New(range(6,30),12,2)
9064         da2=DataArrayDouble.New(range(1,13),12,1)
9065         dabis=-da
9066         da/=da2
9067         expected1=[6.0,7.0,4.0,4.5,3.3333333333333335,3.6666666666666665,3.0,3.25,2.8,3.0,2.6666666666666665,2.8333333333333335,2.5714285714285716,2.7142857142857144,2.5,2.625,2.4444444444444446,2.5555555555555554,2.4,2.5,2.3636363636363638,2.4545454545454546,2.3333333333333335,2.4166666666666665]
9068         for i in xrange(24):
9069             self.assertAlmostEqual(da.getIJ(0,i),expected1[i],13)
9070             pass
9071         da=-dabis
9072         da/=[100.,101.]
9073         expected2=[0.06,0.06930693069306931,0.08,0.0891089108910891,0.1,0.10891089108910891,0.12,0.12871287128712872,0.14,0.1485148514851485,0.16,0.16831683168316833,0.18,0.18811881188118812,0.2,0.2079207920792079,0.22,0.22772277227722773,0.24,0.24752475247524752,0.26,0.26732673267326734,0.28,0.2871287128712871]
9074         self.assertEqual(12,da.getNumberOfTuples());
9075         self.assertEqual(2,da.getNumberOfComponents());
9076         for i in xrange(24):
9077             self.assertAlmostEqual(da.getIJ(0,i),expected2[i],13)
9078             pass
9079         for pos,elt in enumerate(dabis):
9080             da[pos]/=elt
9081             pass
9082         self.assertEqual(12,da.getNumberOfTuples());
9083         self.assertEqual(2,da.getNumberOfComponents());
9084         expected3=[-0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.0099009900990099]
9085         for i in xrange(24):
9086             self.assertAlmostEqual(da.getIJ(0,i),expected3[i],13)
9087             pass
9088         pass
9089
9090     def testSwigDAIOp4(self):
9091         da=DataArrayInt.New(range(6,30),12,2)
9092         self.assertEqual(12,da.getNumberOfTuples());
9093         self.assertEqual(2,da.getNumberOfComponents());
9094         for i in xrange(24):
9095             self.assertEqual(da.getIJ(0,i),i+6)
9096             pass
9097         # operator transpose
9098         da.transpose()
9099         self.assertEqual(2,da.getNumberOfTuples());
9100         self.assertEqual(12,da.getNumberOfComponents());
9101         for i in xrange(24):
9102             self.assertEqual(da.getIJ(0,i),i+6)
9103             pass
9104         da.transpose()
9105         # operator __neg__
9106         da2=DataArrayInt.New(12,1)
9107         da2.iota(0)
9108         dabis=-da
9109         for i in xrange(24):
9110             self.assertEqual(dabis.getIJ(0,i),-(i+6))
9111             pass
9112         # operator+=
9113         da+=da2
9114         expected1=[6,7,9,10,12,13,15,16,18,19,21,22,24,25,27,28,30,31,33,34,36,37,39,40]
9115         for i in xrange(24):
9116             self.assertEqual(da.getIJ(0,i),expected1[i])
9117             pass
9118         da=-dabis
9119         da+=[100,101]
9120         expected2=[106,108,108,110,110,112,112,114,114,116,116,118,118,120,120,122,122,124,124,126,126,128,128,130]
9121         self.assertEqual(12,da.getNumberOfTuples());
9122         self.assertEqual(2,da.getNumberOfComponents());
9123         for i in xrange(24):
9124             self.assertEqual(da.getIJ(0,i),expected2[i])
9125             pass
9126         for pos,elt in enumerate(dabis):
9127             da[pos]+=elt
9128             pass
9129         self.assertEqual(12,da.getNumberOfTuples());
9130         self.assertEqual(2,da.getNumberOfComponents());
9131         for elt in da:
9132             li=elt[:]
9133             self.assertEqual(li[0],100) ; self.assertEqual(li[1],101)
9134             pass
9135         # operator-=
9136         da=DataArrayInt.New(range(6,30),12,2)
9137         da2=DataArrayInt.New(range(12),12,1)
9138         dabis=-da
9139         da-=da2
9140         expected1=[6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18]
9141         for i in xrange(24):
9142             self.assertEqual(da.getIJ(0,i),expected1[i])
9143             pass
9144         da=-dabis
9145         da-=[100,101]
9146         expected2=[-94,-94,-92,-92,-90,-90,-88,-88,-86,-86,-84,-84,-82,-82,-80,-80,-78,-78,-76,-76,-74,-74,-72,-72]
9147         self.assertEqual(12,da.getNumberOfTuples());
9148         self.assertEqual(2,da.getNumberOfComponents());
9149         for i in xrange(24):
9150             self.assertEqual(da.getIJ(0,i),expected2[i])
9151             pass
9152         for pos,elt in enumerate(dabis):
9153             da[pos]-=elt
9154             pass
9155         self.assertEqual(12,da.getNumberOfTuples());
9156         self.assertEqual(2,da.getNumberOfComponents());
9157         expected3=[-88,-87,-84,-83,-80,-79,-76,-75,-72,-71,-68,-67,-64,-63,-60,-59,-56,-55,-52,-51,-48,-47,-44,-43]
9158         for i in xrange(24):
9159             self.assertEqual(da.getIJ(0,i),expected3[i])
9160             pass
9161         # operator*=
9162         da=DataArrayInt.New(range(6,30),12,2)
9163         da2=DataArrayInt.New(range(12),12,1)
9164         dabis=-da
9165         da*=da2
9166         expected1=[0,0,8,9,20,22,36,39,56,60,80,85,108,114,140,147,176,184,216,225,260,270,308,319]
9167         for i in xrange(24):
9168             self.assertEqual(da.getIJ(0,i),expected1[i])
9169             pass
9170         da=-dabis
9171         da*=[100,101]
9172         expected2=[600,707,800,909,1000,1111,1200,1313,1400,1515,1600,1717,1800,1919,2000,2121,2200,2323,2400,2525,2600,2727,2800,2929]
9173         self.assertEqual(12,da.getNumberOfTuples());
9174         self.assertEqual(2,da.getNumberOfComponents());
9175         for i in xrange(24):
9176             self.assertEqual(da.getIJ(0,i),expected2[i])
9177             pass
9178         for pos,elt in enumerate(dabis):
9179             da[pos]*=elt
9180             pass
9181         self.assertEqual(12,da.getNumberOfTuples());
9182         self.assertEqual(2,da.getNumberOfComponents());
9183         expected3=[-3600,-4949,-6400,-8181,-10000,-12221,-14400,-17069,-19600,-22725,-25600,-29189,-32400,-36461,-40000,-44541,-48400,-53429,-57600,-63125,-67600,-73629,-78400,-84941.0]
9184         for i in xrange(24):
9185             self.assertEqual(da.getIJ(0,i),expected3[i])
9186             pass
9187         # operator/=
9188         da=DataArrayInt.New(range(6,30),12,2)
9189         da2=DataArrayInt.New(range(1,13),12,1)
9190         dabis=-da
9191         da/=da2
9192         expected1=[6,7,4,4,3,3,3,3,2,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2]
9193         for i in xrange(24):
9194             self.assertEqual(da.getIJ(0,i),expected1[i])
9195             pass
9196         da=-dabis
9197         da/=DataArrayInt.New([2,3],1,2)
9198         self.assertEqual(12,da.getNumberOfTuples());
9199         self.assertEqual(2,da.getNumberOfComponents());
9200         expected2=[3,2,4,3,5,3,6,4,7,5,8,5,9,6,10,7,11,7,12,8,13,9,14,9]
9201         for i in xrange(24):
9202             self.assertEqual(da.getIJ(0,i),expected2[i])
9203             pass
9204         pass
9205
9206     def testSwigDADOp5(self):
9207         da=DataArrayDouble.New([5,6,7,8,9,6,7,-2,3,9,8,10])
9208         da.rearrange(3)
9209         da2=DataArrayDouble.New([5.,8.,10.,12])
9210         self.assertEqual(4,da2.getNumberOfTuples());
9211         self.assertEqual(1,da2.getNumberOfComponents());
9212         da3=da+da2
9213         self.assertEqual(4,da3.getNumberOfTuples());
9214         self.assertEqual(3,da3.getNumberOfComponents());
9215         expected1=[10.,11.,12.,16.,17.,14.,17.,8.,13.,21.,20.,22.]
9216         for i in xrange(12):
9217             self.assertAlmostEqual(da3.getIJ(0,i),expected1[i],13)
9218             pass
9219         da3=da2+da
9220         self.assertEqual(4,da3.getNumberOfTuples());
9221         self.assertEqual(3,da3.getNumberOfComponents());
9222         for i in xrange(12):
9223             self.assertAlmostEqual(da3.getIJ(0,i),expected1[i],13)
9224             pass
9225         # Test new API of classmethod DataArrayDouble.New
9226         vals=[5,6,7,8,9,6,7,-2,3,9,8,10]
9227         da=DataArrayDouble.New(vals)
9228         self.assertEqual(12,da.getNumberOfTuples());
9229         self.assertEqual(1,da.getNumberOfComponents());
9230         for i in xrange(12):
9231             self.assertAlmostEqual(da.getIJ(0,i),vals[i],13)
9232             pass
9233         da=DataArrayDouble.New(vals,12)
9234         self.assertEqual(12,da.getNumberOfTuples());
9235         self.assertEqual(1,da.getNumberOfComponents());
9236         for i in xrange(12):
9237             self.assertAlmostEqual(da.getIJ(0,i),vals[i],13)
9238             pass
9239         da=DataArrayDouble.New(vals,1,12)
9240         self.assertEqual(1,da.getNumberOfTuples());
9241         self.assertEqual(12,da.getNumberOfComponents());
9242         for i in xrange(12):
9243             self.assertAlmostEqual(da.getIJ(0,i),vals[i],13)
9244             pass
9245         da=DataArrayDouble.New(vals,6,2)
9246         self.assertEqual(6,da.getNumberOfTuples());
9247         self.assertEqual(2,da.getNumberOfComponents());
9248         for i in xrange(12):
9249             self.assertAlmostEqual(da.getIJ(0,i),vals[i],13)
9250             pass
9251         da=DataArrayDouble.New(vals,4,3)
9252         self.assertEqual(4,da.getNumberOfTuples());
9253         self.assertEqual(3,da.getNumberOfComponents());
9254         for i in xrange(12):
9255             self.assertAlmostEqual(da.getIJ(0,i),vals[i],13)
9256             pass
9257         self.assertRaises(InterpKernelException,DataArrayDouble.New,vals,11);
9258         self.assertRaises(InterpKernelException,DataArrayDouble.New,vals,13);
9259         self.assertRaises(InterpKernelException,DataArrayDouble.New,vals,5,2);
9260         self.assertRaises(InterpKernelException,DataArrayDouble.New,vals,7,2);
9261         pass
9262
9263     def testSwigDADOp6(self):
9264         da=DataArrayInt.New([5,6,7,8,9,6,7,-2,3,9,8,10])
9265         da.rearrange(3)
9266         da2=DataArrayInt.New([5,8,10,12])
9267         self.assertEqual(4,da2.getNumberOfTuples());
9268         self.assertEqual(1,da2.getNumberOfComponents());
9269         da3=da+da2
9270         self.assertEqual(4,da3.getNumberOfTuples());
9271         self.assertEqual(3,da3.getNumberOfComponents());
9272         expected1=[10,11,12,16,17,14,17,8,13,21,20,22]
9273         for i in xrange(12):
9274             self.assertEqual(da3.getIJ(0,i),expected1[i])
9275             pass
9276         da3=da2+da
9277         self.assertEqual(4,da3.getNumberOfTuples());
9278         self.assertEqual(3,da3.getNumberOfComponents());
9279         for i in xrange(12):
9280             self.assertEqual(da3.getIJ(0,i),expected1[i])
9281             pass
9282         da3=da+DataArrayInt.New(da2.getValues())
9283         # Test new API of classmethod DataArrayInt.New
9284         vals=[5,6,7,8,9,6,7,-2,3,9,8,10]
9285         da=DataArrayDouble.New(vals)
9286         self.assertEqual(12,da.getNumberOfTuples());
9287         self.assertEqual(1,da.getNumberOfComponents());
9288         for i in xrange(12):
9289             self.assertEqual(da.getIJ(0,i),vals[i])
9290             pass
9291         da=DataArrayDouble.New(vals,12)
9292         self.assertEqual(12,da.getNumberOfTuples());
9293         self.assertEqual(1,da.getNumberOfComponents());
9294         for i in xrange(12):
9295             self.assertEqual(da.getIJ(0,i),vals[i])
9296             pass
9297         da=DataArrayDouble.New(vals,1,12)
9298         self.assertEqual(1,da.getNumberOfTuples());
9299         self.assertEqual(12,da.getNumberOfComponents());
9300         for i in xrange(12):
9301             self.assertEqual(da.getIJ(0,i),vals[i])
9302             pass
9303         da=DataArrayDouble.New(vals,6,2)
9304         self.assertEqual(6,da.getNumberOfTuples());
9305         self.assertEqual(2,da.getNumberOfComponents());
9306         for i in xrange(12):
9307             self.assertEqual(da.getIJ(0,i),vals[i])
9308             pass
9309         da=DataArrayDouble.New(vals,4,3)
9310         self.assertEqual(4,da.getNumberOfTuples());
9311         self.assertEqual(3,da.getNumberOfComponents());
9312         for i in xrange(12):
9313             self.assertEqual(da.getIJ(0,i),vals[i])
9314             pass
9315         self.assertRaises(InterpKernelException,DataArrayDouble.New,vals,11);
9316         self.assertRaises(InterpKernelException,DataArrayDouble.New,vals,13);
9317         self.assertRaises(InterpKernelException,DataArrayDouble.New,vals,5,2);
9318         self.assertRaises(InterpKernelException,DataArrayDouble.New,vals,7,2);
9319         pass
9320
9321     def testSwigDADOp9(self):
9322         l1=[(1.,2.,3),(4.,5.,6.),(7.,8.,9.),[10.,11.,12.]]
9323         da1=DataArrayDouble(l1,4,3)
9324         self.assertEqual(4,da1.getNumberOfTuples());
9325         self.assertEqual(3,da1.getNumberOfComponents());
9326         da2=DataArrayDouble(12) ; da2.iota(1.) ; da2.rearrange(3)
9327         self.assertTrue(da2.isEqual(da1,1e-12))
9328         self.assertRaises(InterpKernelException,DataArrayDouble.New,l1,3,4);
9329         da3=DataArrayDouble(l1,4)
9330         self.assertTrue(da3.isEqual(da1,1e-12))
9331         self.assertRaises(InterpKernelException,DataArrayDouble.New,l1,3);
9332         self.assertRaises(InterpKernelException,DataArrayDouble.New,l1,5);
9333         l1=[(1.,2.,3),(4.,(5.),((6.))),(7.,8.,9.),[10.,11.,12.]]
9334         da1=DataArrayDouble(l1,4,3)
9335         self.assertEqual(4,da1.getNumberOfTuples());
9336         self.assertEqual(3,da1.getNumberOfComponents());
9337         da2=DataArrayDouble(12) ; da2.iota(1.) ; da2.rearrange(3)
9338         self.assertTrue(da2.isEqual(da1,1e-12))
9339         self.assertRaises(InterpKernelException,DataArrayDouble.New,l1,3,4);
9340         da3=DataArrayDouble(l1,4)
9341         self.assertTrue(da3.isEqual(da1,1e-12))
9342         self.assertRaises(InterpKernelException,DataArrayDouble.New,l1,3);
9343         self.assertRaises(InterpKernelException,DataArrayDouble.New,l1,5);
9344         #
9345         l1=[(1,2,3),(4,5,6),(7,8,9),[10,11,12]]
9346         da1=DataArrayInt(l1,4,3)
9347         self.assertEqual(4,da1.getNumberOfTuples());
9348         self.assertEqual(3,da1.getNumberOfComponents());
9349         da2=DataArrayInt(12) ; da2.iota(1) ; da2.rearrange(3)
9350         self.assertTrue(da2.isEqual(da1))
9351         self.assertRaises(InterpKernelException,DataArrayInt.New,l1,3,4);
9352         da3=DataArrayInt(l1,4)
9353         self.assertTrue(da3.isEqual(da1))
9354         self.assertRaises(InterpKernelException,DataArrayInt.New,l1,3);
9355         self.assertRaises(InterpKernelException,DataArrayInt.New,l1,5);
9356         l1=[(1,[2],3),(4,[(5)],6),((([7])),8,9),[10,11,12]]
9357         da1=DataArrayInt(l1,4,3)
9358         self.assertEqual(4,da1.getNumberOfTuples());
9359         self.assertEqual(3,da1.getNumberOfComponents());
9360         da2=DataArrayInt(12) ; da2.iota(1) ; da2.rearrange(3)
9361         self.assertTrue(da2.isEqual(da1))
9362         self.assertRaises(InterpKernelException,DataArrayInt.New,l1,3,4);
9363         da3=DataArrayInt(l1,4)
9364         self.assertTrue(da3.isEqual(da1))
9365         self.assertRaises(InterpKernelException,DataArrayInt.New,l1,3);
9366         self.assertRaises(InterpKernelException,DataArrayInt.New,l1,5);
9367         pass
9368
9369     def testRenumberNodesInConn1(self):
9370         mesh2DCoords=[-0.3,-0.3,0., 0.2,-0.3,0., 0.7,-0.3,0., -0.3,0.2,0., 0.2,0.2,0., 0.7,0.2,0., -0.3,0.7,0., 0.2,0.7,0., 0.7,0.7,0. ]
9371         mesh2DConn=[1,4,2, 4,5,2, 0,3,4,1, 6,7,4,3, 7,8,5,4]
9372         mesh2D=MEDCouplingUMesh.New("mesh",2);
9373         mesh2D.allocateCells(5);
9374         mesh2D.insertNextCell(NORM_TRI3,3,mesh2DConn[0:3])
9375         mesh2D.insertNextCell(NORM_TRI3,3,mesh2DConn[3:6])
9376         mesh2D.insertNextCell(NORM_QUAD4,4,mesh2DConn[6:10])
9377         mesh2D.insertNextCell(NORM_QUAD4,4,mesh2DConn[10:14])
9378         mesh2D.insertNextCell(NORM_QUAD4,4,mesh2DConn[14:18])
9379         mesh2D.finishInsertingCells();
9380         myCoords=DataArrayDouble.New(mesh2DCoords,9,3);
9381         mesh2D.setCoords(myCoords);
9382         mesh2D.checkCoherency();
9383         #
9384         mesh3DCoords=[-0.3,-0.3,0., -0.3,0.2,0., 0.2,0.2,0., 0.2,-0.3,0., -0.3,-0.3,1., -0.3,0.2,1., 0.2,0.2,1., 0.2,-0.3,1. ]
9385         mesh3DConn=[0,1,2,3,4,5,6,7]
9386         mesh3D=MEDCouplingUMesh.New("mesh",3);
9387         mesh3D.allocateCells(1);
9388         mesh3D.insertNextCell(NORM_HEXA8,8,mesh3DConn[:])
9389         mesh3D.finishInsertingCells();
9390         myCoords3D=DataArrayDouble.New(mesh3DCoords,8,3);
9391         mesh3D.setCoords(myCoords3D);
9392         mesh3D.checkCoherency();
9393         #
9394         mesh3D_2=mesh3D.deepCpy();
9395         mesh2D_2=mesh2D.deepCpy();
9396         mesh3D_4=mesh3D.deepCpy();
9397         mesh2D_4=mesh2D.deepCpy();
9398         oldNbOf3DNodes=mesh3D.getNumberOfNodes();
9399         renumNodes=DataArrayInt.New();
9400         renumNodes.alloc(mesh2D.getNumberOfNodes(),1);
9401         renumNodes.iota(oldNbOf3DNodes);
9402         coo=DataArrayDouble.Aggregate(mesh3D.getCoords(),mesh2D.getCoords());
9403         mesh3D.setCoords(coo);
9404         mesh2D.setCoords(coo);
9405         mesh2DCpy=mesh2D.deepCpy()
9406         mesh2D_3=mesh2D.deepCpy();
9407         mesh2D_3.shiftNodeNumbersInConn(oldNbOf3DNodes);
9408         mesh2D.renumberNodesInConn(renumNodes);
9409         mesh2DCpy.renumberNodesInConn(renumNodes.getValues());
9410         self.assertTrue(mesh2D.isEqual(mesh2DCpy,1e-12))
9411         self.assertTrue(mesh2D.isEqual(mesh2D_3,1e-12))
9412         #
9413         da1,da2=mesh3D.checkGeoEquivalWith(mesh3D_2,10,1e-12);
9414         self.assertTrue(da1==None);
9415         self.assertEqual(8,da2.getNumberOfTuples());
9416         self.assertEqual(1,da2.getNumberOfComponents());
9417         expected1=[8,11,12,9,4,5,6,7]
9418         for i in xrange(8):
9419             self.assertEqual(expected1[i],da2.getIJ(i,0));
9420             pass
9421         #
9422         da1,da2=mesh2D.checkGeoEquivalWith(mesh2D_2,10,1e-12);
9423         self.assertTrue(da1==None);
9424         self.assertEqual(9,da2.getNumberOfTuples());
9425         self.assertEqual(1,da2.getNumberOfComponents());
9426         for i in xrange(9):
9427             self.assertEqual(8+i,da2.getIJ(i,0));
9428             pass
9429         #
9430         mesh2D_5=mesh2D_4.deepCpy();
9431         mesh2D_5.translate([1.,0.,0.]);
9432         meshes=[mesh3D_4,mesh2D_4,mesh2D_5];
9433         MEDCouplingUMesh.PutUMeshesOnSameAggregatedCoords(meshes);
9434         self.assertTrue(mesh3D_4.getCoords().getHiddenCppPointer()==mesh2D_4.getCoords().getHiddenCppPointer());
9435         self.assertTrue(mesh2D_4.getCoords().getHiddenCppPointer()==mesh2D_5.getCoords().getHiddenCppPointer());
9436         mesh3D_4.checkCoherency(); mesh2D_4.checkCoherency(); mesh2D_5.checkCoherency();
9437         self.assertEqual(26,mesh3D_4.getNumberOfNodes());
9438         self.assertEqual(3,mesh3D_4.getSpaceDimension());
9439         self.assertEqual(9,mesh3D_4.getNodalConnectivity().getNumberOfTuples());
9440         self.assertEqual(23,mesh2D_4.getNodalConnectivity().getNumberOfTuples());
9441         self.assertEqual(23,mesh2D_5.getNodalConnectivity().getNumberOfTuples());
9442         expected2=[18,0,1,2,3,4,5,6,7]
9443         expected3=[3,9,12,10, 3,12,13,10, 4,8,11,12,9, 4,14,15,12,11, 4,15,16,13,12]
9444         expected4=[3,18,21,19, 3,21,22,19, 4,17,20,21,18, 4,23,24,21,20, 4,24,25,22,21]
9445         expected5=[-0.3,-0.3,0., -0.3,0.2,0., 0.2,0.2,0., 0.2,-0.3,0., -0.3,-0.3,1., -0.3,0.2,1., 0.2,0.2,1., 0.2,-0.3,1., -0.3,-0.3,0., 0.2,-0.3,0., 0.7,-0.3,0., -0.3,0.2,0., 0.2,0.2,0., 0.7,0.2,0., -0.3,0.7,0., 0.2,0.7,0., 0.7,0.7,0., 0.7, -0.3, 0.0, 1.2, -0.3, 0.0, 1.7, -0.3, 0.0, 0.7, 0.2, 0.0, 1.2, 0.2, 0.0, 1.7, 0.2, 0.0, 0.7, 0.7, 0.0, 1.2, 0.7, 0.0, 1.7, 0.7, 0.0]
9446         self.assertEqual(expected2,mesh3D_4.getNodalConnectivity().getValues());
9447         self.assertEqual(expected3,mesh2D_4.getNodalConnectivity().getValues());
9448         self.assertEqual(expected4,mesh2D_5.getNodalConnectivity().getValues());
9449         for i in xrange(78):
9450             self.assertAlmostEqual(expected5[i],mesh3D_4.getCoords().getIJ(0,i),12);
9451             pass
9452         #
9453         MEDCouplingUMesh.MergeNodesOnUMeshesSharingSameCoords(meshes,1e-12);
9454         mesh3D_4.checkCoherency(); mesh2D_4.checkCoherency(); mesh2D_5.checkCoherency();
9455         self.assertTrue(mesh3D_4.getCoords().getHiddenCppPointer()==mesh2D_4.getCoords().getHiddenCppPointer());
9456         self.assertTrue(mesh2D_4.getCoords().getHiddenCppPointer()==mesh2D_5.getCoords().getHiddenCppPointer());
9457         self.assertEqual(19,mesh3D_4.getNumberOfNodes());
9458         self.assertEqual(3,mesh3D_4.getSpaceDimension());
9459         self.assertEqual(9,mesh3D_4.getNodalConnectivity().getNumberOfTuples());
9460         self.assertEqual(23,mesh2D_4.getNodalConnectivity().getNumberOfTuples());
9461         self.assertEqual(23,mesh2D_5.getNodalConnectivity().getNumberOfTuples());
9462         expected6=[18,0,1,2,3,4,5,6,7]
9463         expected7=[3,3,2,8, 3,2,9,8, 4,0,1,2,3, 4,10,11,2,1, 4,11,12,9,2]
9464         expected8=[3,13,15,14, 3,15,16,14, 4,8,9,15,13, 4,12,17,15,9, 4,17,18,16,15]
9465         expected9=[-0.3, -0.3, 0., -0.3, 0.2, 0., 0.2, 0.2, 0., 0.2, -0.3, 0., -0.3, -0.3, 1., -0.3, 0.2, 1.,
9466                     0.2, 0.2, 1., 0.2, -0.3, 1., 0.7, -0.3, 0., 0.7, 0.2, 0., -0.3, 0.7, 0., 0.2, 0.7, 0.,
9467                     0.7, 0.7, 0., 1.2, -0.3, 0., 1.7, -0.3, 0., 1.2, 0.2, 0., 1.7, 0.2, 0., 1.2, 0.7, 0., 1.7, 0.7, 0.]
9468         self.assertEqual(expected6,mesh3D_4.getNodalConnectivity().getValues());
9469         self.assertEqual(expected7,mesh2D_4.getNodalConnectivity().getValues());
9470         self.assertEqual(expected8,mesh2D_5.getNodalConnectivity().getValues());
9471         for i in xrange(57):
9472             self.assertAlmostEqual(expected9[i],mesh3D_4.getCoords().getIJ(0,i),12);
9473             pass
9474         #
9475         pass
9476     
9477     def testComputeNeighborsOfCells1(self):
9478         m=MEDCouplingDataForTest.build2DTargetMesh_1();
9479         d1,d2=m.computeNeighborsOfCells();
9480         self.assertEqual(6,d2.getNumberOfTuples());
9481         self.assertEqual(10,d1.getNumberOfTuples());
9482         expected1=[0,2,4,6,8,10]
9483         expected2=[3,1,0,2,4,1,4,0,2,3]
9484         self.assertEqual(expected1,d2.getValues());
9485         self.assertEqual(expected2,d1.getValues());
9486         pass
9487
9488     def testCheckButterflyCellsBug1(self):
9489         mesh2DCoords=[323.85,120.983748908684,317.5,131.982271536747,336.55,120.983748908686,330.2,131.982271536751,323.85,142.98079416481]
9490         mesh2DConn=[4,1,0,2,3]
9491         mesh2D=MEDCouplingUMesh.New("mesh",2);
9492         mesh2D.allocateCells(1);
9493         mesh2D.insertNextCell(NORM_POLYGON,5,mesh2DConn[0:5])
9494         mesh2D.finishInsertingCells();
9495         myCoords=DataArrayDouble.New(mesh2DCoords,5,2);
9496         mesh2D.setCoords(myCoords);
9497         mesh2D.checkCoherency();
9498         #
9499         v=mesh2D.checkButterflyCells();
9500         self.assertTrue(v.empty());
9501         pass
9502
9503     def testDataArrayIntRange1(self):
9504         d=DataArrayInt.Range(2,17,7);
9505         expected1=[2,9,16]
9506         self.assertEqual(3,d.getNumberOfTuples());
9507         self.assertEqual(1,d.getNumberOfComponents());
9508         self.assertEqual(expected1,d.getValues());
9509         #
9510         d=DataArrayInt.Range(2,23,7);
9511         self.assertEqual(3,d.getNumberOfTuples());
9512         self.assertEqual(1,d.getNumberOfComponents());
9513         self.assertEqual(expected1,d.getValues());
9514         #
9515         d=DataArrayInt.Range(2,24,7);
9516         expected2=[2,9,16,23]
9517         self.assertEqual(4,d.getNumberOfTuples());
9518         self.assertEqual(1,d.getNumberOfComponents());
9519         self.assertEqual(expected2,d.getValues());
9520         #
9521         d=DataArrayInt.Range(24,2,-7);
9522         expected3=[24,17,10,3]
9523         self.assertEqual(4,d.getNumberOfTuples());
9524         self.assertEqual(1,d.getNumberOfComponents());
9525         self.assertEqual(expected3,d.getValues());
9526         #
9527         d=DataArrayInt.Range(23,2,-7);
9528         expected4=[23,16,9]
9529         self.assertEqual(3,d.getNumberOfTuples());
9530         self.assertEqual(1,d.getNumberOfComponents());
9531         self.assertEqual(expected4,d.getValues());
9532         #
9533         d=DataArrayInt.Range(23,22,-7);
9534         self.assertEqual(1,d.getNumberOfTuples());
9535         self.assertEqual(1,d.getNumberOfComponents());
9536         self.assertEqual(23,d.getIJ(0,0));
9537         #
9538         d=DataArrayInt.Range(22,23,7);
9539         self.assertEqual(1,d.getNumberOfTuples());
9540         self.assertEqual(1,d.getNumberOfComponents());
9541         self.assertEqual(22,d.getIJ(0,0));
9542         #
9543         d=DataArrayInt.Range(22,22,7);
9544         self.assertEqual(0,d.getNumberOfTuples());
9545         self.assertEqual(1,d.getNumberOfComponents());
9546         #
9547         d=DataArrayInt.Range(22,22,-7);
9548         self.assertEqual(0,d.getNumberOfTuples());
9549         self.assertEqual(1,d.getNumberOfComponents());
9550         #
9551         self.assertRaises(InterpKernelException,DataArrayInt.Range,22,23,-7);
9552         self.assertRaises(InterpKernelException,DataArrayInt.Range,23,22,7);
9553         self.assertRaises(InterpKernelException,DataArrayInt.Range,23,22,0);
9554         self.assertRaises(InterpKernelException,DataArrayInt.Range,22,23,0);
9555         pass
9556
9557     def testSwigUMeshGetItem1(self):
9558         m=MEDCouplingDataForTest.build2DTargetMesh_1();
9559         subMesh=m.buildPartOfMySelf([1,3],True);
9560         self.assertTrue(isinstance(subMesh,MEDCouplingUMesh))
9561         m1=m[[1,3]]
9562         self.assertTrue(isinstance(m1,MEDCouplingUMesh))
9563         m2=m[(1,3)]
9564         self.assertTrue(isinstance(m2,MEDCouplingUMesh))
9565         m3=m[1::2]
9566         self.assertTrue(isinstance(m3,MEDCouplingUMesh))
9567         m4=m[DataArrayInt.New([1,3])]
9568         m5_1=m[1]
9569         self.assertTrue(isinstance(m5_1,MEDCouplingUMesh))
9570         m5_2=m[3]
9571         self.assertTrue(isinstance(m5_2,MEDCouplingUMesh))
9572         m5=MEDCouplingUMesh.MergeUMeshesOnSameCoords([m5_1,m5_2]);
9573         m5.setName(subMesh.getName())
9574         self.assertTrue(isinstance(m4,MEDCouplingUMesh))
9575         self.assertTrue(subMesh.isEqual(m1,1e-12))
9576         self.assertTrue(subMesh.isEqual(m2,1e-12))
9577         self.assertTrue(subMesh.isEqual(m3,1e-12))
9578         self.assertTrue(subMesh.isEqual(m4,1e-12))
9579         self.assertTrue(subMesh.isEqual(m5,1e-12))
9580         self.assertRaises(InterpKernelException,m.buildPartOfMySelf,[1,5],True);
9581         pass
9582     
9583     def testSwigGetItem3(self):
9584         da=DataArrayInt.New([4,5,6])
9585         self.assertEqual(5,da[1])
9586         self.assertRaises(InterpKernelException,da.__getitem__,-1)
9587         self.assertRaises(InterpKernelException,da.__getitem__,3)
9588         da=DataArrayInt.New([4,5,6,7,8,9],2,3)
9589         self.assertEqual(9,da[1,2])
9590         da=DataArrayDouble.New([4.1,5.2,6.3])
9591         self.assertAlmostEqual(5.2,da[1],12)
9592         self.assertRaises(InterpKernelException,da.__getitem__,-1)
9593         self.assertRaises(InterpKernelException,da.__getitem__,3)
9594         da=DataArrayDouble.New([4.12,5.12,6.12,7.12,8.12,9.12],2,3)
9595         self.assertAlmostEqual(9.12,da[1,2],12)
9596         pass
9597
9598     def testSwigDADISub1(self):
9599         mesh3D,mesh2D=MEDCouplingDataForTest.build3DExtrudedUMesh_1();
9600         bary=mesh3D.getBarycenterAndOwner()
9601         bary=bary[:,:2]
9602         pts=bary.getDifferentValues(1e-12)
9603         expected=[[0,6,12],[1,7,13],[2,8,14],[3,9,15],[4,10,16],[5,11,17]]
9604         for pos,pt in enumerate(pts):
9605             bary2=bary[:,:2]
9606             bary2[:]-=pt
9607             norm=bary2.magnitude()
9608             self.assertEqual(expected[pos],norm.getIdsInRange(-1.,1e-5).getValues())
9609             pass
9610         expected2=[[3.,54.],[-141.,180.],[21.,54.],[39.,72.],[-15.,90.],[21.,90.]]
9611         for pos,pt in enumerate(pts):
9612             bary2=bary[:,:2]
9613             bary2[:]+=pt
9614             self.assertAlmostEqual(expected2[pos][0],bary2.accumulate()[0],12);
9615             self.assertAlmostEqual(expected2[pos][1],bary2.accumulate()[1],12);
9616             pass
9617         expected3=[[-3.,22.5],[45.,337.5],[-9., 22.5],[-15.,67.5],[3.,112.5],[-9.,112.5]]
9618         for pos,pt in enumerate(pts):
9619             bary2=bary[:,:2]
9620             bary2[:]*=pt
9621             self.assertAlmostEqual(expected3[pos][0],bary2.accumulate()[0],12);
9622             self.assertAlmostEqual(expected3[pos][1],bary2.accumulate()[1],12);
9623             pass
9624         expected4=[[-12.,90.],[0.8,6.],[-4,90.],[-2.4,30.],[12.,18],[-4,18.]]
9625         for pos,pt in enumerate(pts):
9626             bary2=bary[:,:2]
9627             bary2[:]/=pt
9628             self.assertAlmostEqual(expected4[pos][0],bary2.accumulate()[0],12);
9629             self.assertAlmostEqual(expected4[pos][1],bary2.accumulate()[1],12);
9630             pass
9631         #
9632         d=DataArrayInt.New([1,2,0,1,0,2],3,2)
9633         e=DataArrayInt.New([1,11,101,2,12,102,3,13,103,4,14,104],4,3)
9634         expected5=[[1,11,101,77,77,77,77,77,77,4,14,104],[77,77,77,77,77,77,3,13,103,4,14,104],[77,77,77,2,12,102,77,77,77,4,14,104]]
9635         expected6=[[1,77,77,2,77,77,3,77,77,4,77,77],[77,77,101,77,77,102,77,77,103,77,77,104],[77,11,77,77,12,77,77,13,77,77,14,77]]
9636         for pos,tup in enumerate(d):
9637             f=e[:]
9638             self.assertTrue(isinstance(f,DataArrayInt))
9639             f[tup]=77
9640             self.assertEqual(expected5[pos],f.getValues())
9641             self.assertEqual(6*[77],f[tup].getValues())
9642             f=e[:]
9643             f[:,tup]=77
9644             self.assertEqual(expected6[pos],f.getValues())
9645             self.assertEqual(8*[77],f[:,tup].getValues())
9646             pass
9647         #
9648         e=e.convertToDblArr()
9649         for pos,tup in enumerate(d):
9650             f=e[:]
9651             self.assertTrue(isinstance(f,DataArrayDouble))
9652             f[tup]=77.
9653             self.assertEqual(expected5[pos],f.convertToIntArr().getValues())
9654             self.assertEqual(6*[77],f[tup].convertToIntArr().getValues())
9655             f=e[:]
9656             f[:,tup]=77.
9657             self.assertEqual(expected6[pos],f.convertToIntArr().getValues())
9658             self.assertEqual(8*[77],f[:,tup].convertToIntArr().getValues())
9659             pass
9660         pass
9661
9662     def testDataArrayDoubleGetMinMaxPerComponent1(self):
9663         values1=[1.,2.,3.,-0.9,2.1,3.,1.3,1.7,3.,1.,1.8,3.]
9664         d1=DataArrayDouble.New();
9665         self.assertRaises(InterpKernelException,d1.getMinMaxPerComponent)
9666         d1=DataArrayDouble.New(values1,4,3);
9667         res=d1.getMinMaxPerComponent();
9668         self.assertTrue(isinstance(res,list))
9669         self.assertEqual(3,len(res))
9670         for i in xrange(3):
9671             self.assertTrue(isinstance(res[i],tuple))
9672             self.assertEqual(2,len(res[i]))
9673             pass
9674         expected1=[-0.9,1.3,1.7,2.1,3.,3.]
9675         for i in xrange(6):
9676             self.assertAlmostEqual(expected1[i],res[i/2][i%2],14)
9677             pass
9678         #
9679         d1.rearrange(2);
9680         res=d1.getMinMaxPerComponent();
9681         self.assertTrue(isinstance(res,list))
9682         self.assertEqual(2,len(res))
9683         for i in xrange(2):
9684             self.assertTrue(isinstance(res[i],tuple))
9685             self.assertEqual(2,len(res[i]))
9686             pass
9687         expected2=[1.,3.,-0.9,3.]
9688         for i in xrange(4):
9689             self.assertAlmostEqual(expected2[i],res[i/2][i%2],14)
9690             pass
9691         #
9692         d1.rearrange(1);
9693         res=d1.getMinMaxPerComponent();
9694         self.assertTrue(isinstance(res,list))
9695         self.assertEqual(1,len(res))
9696         for i in xrange(1):
9697             self.assertTrue(isinstance(res[i],tuple))
9698             self.assertEqual(2,len(res[i]))
9699             pass
9700         expected3=[-0.9,3.]
9701         for i in xrange(2):
9702             self.assertAlmostEqual(expected3[i],res[i/2][i%2],14)
9703             pass
9704         pass
9705
9706     def testDataArrayIntGetHashCode1(self):
9707         d1=DataArrayInt.New(range(3545))
9708         d2=DataArrayInt.New(range(3545))
9709         self.assertEqual(d2.getHashCode(),d1.getHashCode())
9710         self.assertEqual(232341068,d1.getHashCode())
9711         d1[886]=6
9712         self.assertEqual(232340188,d1.getHashCode())
9713         pass
9714
9715     def testZipConnectivityPol1(self):
9716         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
9717         cells1=[2,3,4]
9718         m2_1=m1.buildPartOfMySelf(cells1,True);
9719         m2=m2_1
9720         self.assertTrue(isinstance(m2,MEDCouplingUMesh))
9721         # no permutation policy 0
9722         isOk,arr=m1.areCellsIncludedIn(m2,0)
9723         self.assertTrue(isOk);
9724         self.assertEqual(3,arr.getNumberOfTuples());
9725         self.assertEqual(1,arr.getNumberOfComponents());
9726         self.assertEqual(cells1,arr.getValues())
9727         # no permutation policy 1
9728         isOk,arr=m1.areCellsIncludedIn(m2,1)
9729         self.assertTrue(isOk);
9730         self.assertEqual(3,arr.getNumberOfTuples());
9731         self.assertEqual(1,arr.getNumberOfComponents());
9732         self.assertEqual(cells1,arr.getValues())
9733         # no permutation policy 2
9734         isOk,arr=m1.areCellsIncludedIn(m2,2)
9735         self.assertTrue(isOk);
9736         self.assertEqual(3,arr.getNumberOfTuples());
9737         self.assertEqual(1,arr.getNumberOfComponents());
9738         self.assertEqual(cells1,arr.getValues())
9739         # some modification into m2
9740         modif1=[2,4,5]
9741         m2.getNodalConnectivity()[1:4]=modif1
9742         #policy 0 fails because cell0 in m2 has same orientation be not same connectivity
9743         expected1=[5,3,4]
9744         isOk,arr=m1.areCellsIncludedIn(m2,0)
9745         self.assertTrue(not isOk);
9746         self.assertEqual(3,arr.getNumberOfTuples());
9747         self.assertEqual(1,arr.getNumberOfComponents());
9748         self.assertEqual(expected1,arr.getValues())
9749         #policy 1 succeeds because cell0 in m2 has not exactly the same conn
9750         isOk,arr=m1.areCellsIncludedIn(m2,1)
9751         self.assertTrue(isOk);
9752         self.assertEqual(3,arr.getNumberOfTuples());
9753         self.assertEqual(1,arr.getNumberOfComponents());
9754         self.assertEqual(cells1,arr.getValues())
9755         #policy 2 succeeds because cell0 in m2 has same nodes in connectivity
9756         isOk,arr=m1.areCellsIncludedIn(m2,2)
9757         self.assertTrue(isOk);
9758         self.assertEqual(3,arr.getNumberOfTuples());
9759         self.assertEqual(1,arr.getNumberOfComponents());
9760         self.assertEqual(cells1,arr.getValues())
9761         #some new modification into m2
9762         modif2=[2,5,4]
9763         m2.getNodalConnectivity()[1:4]=modif2
9764         #policy 0 fails because cell0 in m2 has not exactly the same conn
9765         isOk,arr=m1.areCellsIncludedIn(m2,0)
9766         self.assertTrue(not isOk);
9767         self.assertEqual(3,arr.getNumberOfTuples());
9768         self.assertEqual(1,arr.getNumberOfComponents());
9769         self.assertEqual(expected1,arr.getValues())
9770         #policy 1 fails too because cell0 in m2 has not same orientation
9771         isOk,arr=m1.areCellsIncludedIn(m2,1)
9772         self.assertTrue(not isOk);
9773         self.assertEqual(3,arr.getNumberOfTuples());
9774         self.assertEqual(1,arr.getNumberOfComponents());
9775         self.assertEqual(expected1,arr.getValues())
9776         #policy 2 succeeds because cell0 in m2 has same nodes in connectivity
9777         isOk,arr=m1.areCellsIncludedIn(m2,2)
9778         self.assertTrue(isOk);
9779         self.assertEqual(3,arr.getNumberOfTuples());
9780         self.assertEqual(1,arr.getNumberOfComponents());
9781         self.assertEqual(cells1,arr.getValues())
9782         # Now 1D
9783         cells2=[3,2]
9784         m1=MEDCouplingDataForTest.build1DSourceMesh_2();
9785         m2_1=m1.buildPartOfMySelf(cells2,True);
9786         m2=m2_1
9787         self.assertTrue(isinstance(m2,MEDCouplingUMesh))
9788         # no permutation policy 0
9789         isOk,arr=m1.areCellsIncludedIn(m2,0)
9790         self.assertTrue(isOk);
9791         self.assertEqual(2,arr.getNumberOfTuples());
9792         self.assertEqual(1,arr.getNumberOfComponents());
9793         self.assertEqual(cells2,arr.getValues())
9794         # no permutation policy 1
9795         isOk,arr=m1.areCellsIncludedIn(m2,1)
9796         self.assertTrue(isOk);
9797         self.assertEqual(2,arr.getNumberOfTuples());
9798         self.assertEqual(1,arr.getNumberOfComponents());
9799         self.assertEqual(cells2,arr.getValues())
9800         # no permutation policy 2
9801         isOk,arr=m1.areCellsIncludedIn(m2,2)
9802         self.assertTrue(isOk);
9803         self.assertEqual(2,arr.getNumberOfTuples());
9804         self.assertEqual(1,arr.getNumberOfComponents());
9805         self.assertEqual(cells2,arr.getValues())
9806         # some modification into m2
9807         modif3=[4,3]
9808         m2.getNodalConnectivity()[1:3]=modif3
9809         #policy 0 fails because cell0 in m2 has not exactly the same conn
9810         expected2=[4,2]
9811         isOk,arr=m1.areCellsIncludedIn(m2,0)
9812         self.assertTrue(not isOk);
9813         self.assertEqual(2,arr.getNumberOfTuples());
9814         self.assertEqual(1,arr.getNumberOfComponents());
9815         self.assertEqual(expected2,arr.getValues())
9816         #policy 1 fails too because cell0 in m2 has not same orientation
9817         isOk,arr=m1.areCellsIncludedIn(m2,1)
9818         self.assertTrue(not isOk);
9819         self.assertEqual(2,arr.getNumberOfTuples());
9820         self.assertEqual(1,arr.getNumberOfComponents());
9821         self.assertEqual(expected2,arr.getValues())
9822         #policy 2 succeeds because cell0 in m2 has same nodes in connectivity
9823         isOk,arr=m1.areCellsIncludedIn(m2,2)
9824         self.assertTrue(isOk);
9825         self.assertEqual(2,arr.getNumberOfTuples());
9826         self.assertEqual(1,arr.getNumberOfComponents());
9827         self.assertEqual(cells2,arr.getValues())
9828         pass
9829
9830     def toSeeIfDaIIopsAreOK(self,d):
9831         d+=5
9832         d*=6
9833         d/=3
9834         d-=2
9835         d%=7
9836         pass
9837         
9838     def testSwigDAIOp5(self):
9839         d=DataArrayInt.New([4,5,6,10,3,-1],2,3)
9840         self.toSeeIfDaIIopsAreOK(d)
9841         dExp=DataArrayInt.New([2,4,6,0,0,6],2,3)
9842         self.assertTrue(d.isEqual(dExp));
9843         pass
9844     
9845     def toSeeIfDaDIopsAreOK(self,d):
9846         d+=5
9847         d*=6
9848         d/=3
9849         d-=2
9850         pass
9851
9852     def testSwigDADOp7(self):
9853         d=DataArrayDouble.New([4.,5.,6.,10.,3.,-1.],2,3)
9854         self.toSeeIfDaDIopsAreOK(d)
9855         dExp=DataArrayDouble.New([16.,18.,20.,28.,14.,6.],2,3)
9856         self.assertTrue(d.isEqual(dExp,1e-14));
9857         pass
9858
9859     def testConvexEnvelop2D1(self):
9860         coords=[7.54758495819e-14,-1.12270326253e-12,8.43143594193,-1.02835845055e-12,4.21571797096,7.30183771609,-4.21571797097,7.30183771609,-8.43143594193,-1.09439981894e-12,-4.21571797097,-7.30183771609,4.21571797097,-7.30183771609,16.8628718839,-1.02835845055e-12,12.6471539129,7.30183771609,8.43143594193,14.6036754322,2.26427548746e-13,14.6036754322,-8.43143594193,14.6036754322,-12.6471539129,7.30183771609,-16.8628718839,-1.39630321727e-12,-12.6471539129,-7.30183771609,-8.43143594193,-14.6036754322,3.7737924791e-14,-14.6036754322,8.43143594193,-14.6036754322,12.6471539129,-7.30183771609,25.2943078258,-1.07553085654e-12,21.0785898548,7.30183771609,16.8628718839,14.6036754322,12.6471539129,21.9055131483,4.21571797096,21.9055131483,-4.21571797097,21.9055131483,-12.6471539129,21.9055131483,-16.8628718839,14.6036754322,-21.0785898548,7.30183771609,-25.2943078258,-1.02835845055e-12,-21.0785898548,-7.30183771609,-16.8628718839,-14.6036754322,-12.6471539129,-21.9055131483,-4.21571797097,-21.9055131483,4.21571797097,-21.9055131483,12.6471539129,-21.9055131483,16.8628718839,-14.6036754322,21.0785898548,-7.30183771609,33.7257437677,-7.45324014622e-13,29.5100257968,7.30183771609,25.2943078258,14.6036754322,21.0785898548,21.9055131483,16.8628718839,29.2073508644,8.43143594193,29.2073508644,-1.20761359331e-12,29.2073508644,-8.43143594193,29.2073508644,-16.8628718839,29.2073508644,-21.0785898548,21.9055131483,-25.2943078258,14.6036754322,-29.5100257968,7.30183771609,-33.7257437677,-7.26455052226e-13,-29.5100257968,-7.30183771609,-25.2943078258,-14.6036754322,-21.0785898548,-21.9055131483,-16.8628718839,-29.2073508644,-8.43143594193,-29.2073508644,4.15117172701e-13,-29.2073508644,8.43143594193,-29.2073508644,16.8628718839,-29.2073508644,21.0785898548,-21.9055131483,25.2943078258,-14.6036754322,29.5100257968,-7.30183771609,42.1571797097,-1.86802727715e-12,37.9414617387,7.30183771609,33.7257437677,14.6036754322,29.5100257968,21.9055131483,25.2943078258,29.2073508644,21.0785898548,36.5091885805,12.6471539129,36.5091885805,4.21571797096,36.5091885805,-4.21571797096,36.5091885805,-12.6471539129,36.5091885805,-21.0785898548,36.5091885805,-25.2943078258,29.2073508644,-29.5100257968,21.9055131483,-33.7257437677,14.6036754322,-37.9414617387,7.30183771609,-42.1571797097,-9.81186044565e-13,-37.9414617387,-7.30183771609,-33.7257437677,-14.6036754322,-29.5100257968,-21.9055131483,-25.2943078258,-29.2073508644,-21.0785898548,-36.5091885805,-12.6471539129,-36.5091885805,-4.21571797097,-36.5091885805,4.21571797097,-36.5091885805,12.6471539129,-36.5091885805,21.0785898548,-36.5091885805,25.2943078258,-29.2073508644,29.5100257968,-21.9055131483,33.7257437677,-14.6036754322,37.9414617387,-7.30183771609,50.5886156516,-6.98151608633e-13,46.3728976806,7.30183771609,42.1571797097,14.6036754322,37.9414617387,21.9055131483,33.7257437677,29.2073508644,29.5100257968,36.5091885805,25.2943078258,43.8110262966,16.8628718839,43.8110262966,8.43143594193,43.8110262966,-1.84915831476e-12,43.8110262966,-8.43143594193,43.8110262966,-16.8628718839,43.8110262966,-25.2943078258,43.8110262966,-29.5100257968,36.5091885805,-33.7257437677,29.2073508644,-37.9414617387,21.9055131483,-42.1571797097,14.6036754322,-46.3728976806,7.30183771609,-50.5886156516,-1.47177906685e-12,-46.3728976806,-7.30183771609,-42.1571797097,-14.6036754322,-37.9414617387,-21.9055131483,-33.7257437677,-29.2073508644,-29.5100257968,-36.5091885805,-25.2943078258,-43.8110262966,-16.8628718839,-43.8110262966,-8.43143594193,-43.8110262966,7.54758495819e-14,-43.8110262966,8.43143594193,-43.8110262966,16.8628718839,-43.8110262966,25.2943078258,-43.8110262966,29.5100257968,-36.5091885805,33.7257437677,-29.2073508644,37.9414617387,-21.9055131483,42.1571797097,-14.6036754322,46.3728976806,-7.30183771609,59.0200515935,-7.9249642061e-13,54.8043336225,7.30183771609,50.5886156516,14.6036754322,46.3728976806,21.9055131483,42.1571797097,29.2073508644,37.9414617387,36.5091885805,33.7257437677,43.8110262966,29.5100257968,51.1128640127,21.0785898548,51.1128640127,12.6471539129,51.1128640127,4.21571797096,51.1128640127,-4.21571797096,51.1128640127,-12.6471539129,51.1128640127,-21.0785898548,51.1128640127,-29.5100257968,51.1128640127,-33.7257437677,43.8110262966,-37.9414617387,36.5091885805,-42.1571797097,29.2073508644,-46.3728976806,21.9055131483,-50.5886156516,14.6036754322,-54.8043336226,7.30183771609,-59.0200515935,-1.31139288649e-12,-54.8043336226,-7.30183771609,-50.5886156516,-14.6036754322,-46.3728976806,-21.9055131483,-42.1571797097,-29.2073508644,-37.9414617387,-36.5091885805,-33.7257437677,-43.8110262966,-29.5100257968,-51.1128640127,-21.0785898548,-51.1128640127,-12.6471539129,-51.1128640127,-4.21571797097,-51.1128640127,4.21571797097,-51.1128640127,12.6471539129,-51.1128640127,21.0785898548,-51.1128640127,29.5100257968,-51.1128640127,33.7257437677,-43.8110262966,37.9414617387,-36.5091885805,42.1571797097,-29.2073508644,46.3728976806,-21.9055131483,50.5886156516,-14.6036754322,54.8043336225,-7.30183771609,67.4514875354,-2.14162723189e-12,63.2357695645,7.30183771609,59.0200515935,14.6036754322,54.8043336226,21.9055131483,50.5886156516,29.2073508644,46.3728976806,36.5091885805,42.1571797097,43.8110262966,37.9414617387,51.1128640127,33.7257437677,58.4147017287,25.2943078258,58.4147017287,16.8628718839,58.4147017287,8.43143594193,58.4147017287,6.79282646237e-13,58.4147017287,-8.43143594193,58.4147017287,-16.8628718839,58.4147017287,-25.2943078258,58.4147017287,-33.7257437677,58.4147017287,-37.9414617387,51.1128640127,-42.1571797097,43.8110262966,-46.3728976806,36.5091885805,-50.5886156516,29.2073508644,-54.8043336226,21.9055131483,-59.0200515935,14.6036754322,-63.2357695645,7.30183771609,-67.4514875354,-1.16044118732e-12,-63.2357695645,-7.30183771609,-59.0200515935,-14.6036754322,-54.8043336226,-21.9055131483,-50.5886156516,-29.2073508644,-46.3728976806,-36.5091885805,-42.1571797097,-43.8110262966,-37.9414617387,-51.1128640127,-33.7257437677,-58.4147017287,-25.2943078258,-58.4147017287,-16.8628718839,-58.4147017287,-8.43143594193,-58.4147017287,-5.66068871864e-14,-58.4147017287,8.43143594193,-58.4147017287,16.8628718839,-58.4147017287,25.2943078258,-58.4147017287,33.7257437677,-58.4147017287,37.9414617387,-51.1128640127,42.1571797097,-43.8110262966,46.3728976806,-36.5091885805,50.5886156516,-29.2073508644,54.8043336226,-21.9055131483,59.0200515935,-14.6036754322,63.2357695645,-7.30183771609,75.8829234774,-2.29257893105e-12,71.6672055064,7.30183771609,67.4514875354,14.6036754322,63.2357695645,21.9055131483,59.0200515935,29.2073508644,54.8043336226,36.5091885805,50.5886156516,43.8110262966,46.3728976806,51.1128640127,42.1571797097,58.4147017287,37.9414617387,65.7165394448,29.5100257968,65.7165394448,21.0785898548,65.7165394448,12.6471539129,65.7165394448,4.21571797097,65.7165394448,-4.21571797096,65.7165394448,-12.6471539129,65.7165394448,-21.0785898548,65.7165394448,-29.5100257968,65.7165394448,-37.9414617387,65.7165394448,-42.1571797097,58.4147017287,-46.3728976806,51.1128640127,-50.5886156516,43.8110262966,-54.8043336226,36.5091885805,-59.0200515935,29.2073508644,-63.2357695645,21.9055131483,-67.4514875354,14.6036754322,-71.6672055064,7.30183771609,-75.8829234774,-1.31139288649e-12,-71.6672055064,-7.30183771609,-67.4514875354,-14.6036754322,-63.2357695645,-21.9055131483,-59.0200515935,-29.2073508644,-54.8043336226,-36.5091885805,-50.5886156516,-43.8110262966,-46.3728976806,-51.1128640127,-42.1571797097,-58.4147017287,-37.9414617387,-65.7165394448,-29.5100257968,-65.7165394448,-21.0785898548,-65.7165394448,-12.6471539129,-65.7165394448,-4.21571797097,-65.7165394448,4.21571797097,-65.7165394448,12.6471539129,-65.7165394448,21.0785898548,-65.7165394448,29.5100257968,-65.7165394448,37.9414617387,-65.7165394448,42.1571797097,-58.4147017287,46.3728976806,-51.1128640127,50.5886156516,-43.8110262966,54.8043336226,-36.5091885805,59.0200515935,-29.2073508644,63.2357695645,-21.9055131483,67.4514875354,-14.6036754322,71.6672055064,-7.30183771609,84.3143594193,-1.49064802924e-12,80.0986414483,7.30183771609,75.8829234774,14.6036754322,71.6672055064,21.9055131483,67.4514875354,29.2073508644,63.2357695645,36.5091885805,59.0200515935,43.8110262966,54.8043336226,51.1128640127,50.5886156516,58.4147017287,46.3728976806,65.7165394448,42.1571797097,73.0183771609,33.7257437677,73.0183771609,25.2943078258,73.0183771609,16.8628718839,73.0183771609,8.43143594193,73.0183771609,2.0755858635e-12,73.0183771609,-8.43143594193,73.0183771609,-16.8628718839,73.0183771609,-25.2943078258,73.0183771609,-33.7257437677,73.0183771609,-42.1571797097,73.0183771609,-46.3728976806,65.7165394448,-50.5886156516,58.4147017287,-54.8043336226,51.1128640127,-59.0200515935,43.8110262966,-63.2357695645,36.5091885805,-67.4514875354,29.2073508644,-71.6672055064,21.9055131483,-75.8829234774,14.6036754322,-80.0986414483,7.30183771609,-84.3143594193,-1.11326878133e-12,-80.0986414483,-7.30183771609,-75.8829234774,-14.6036754322,-71.6672055064,-21.9055131483,-67.4514875354,-29.2073508644,-63.2357695645,-36.5091885805,-59.0200515935,-43.8110262966,-54.8043336226,-51.1128640127,-50.5886156516,-58.4147017287,-46.3728976806,-65.7165394448,-42.1571797097,-73.0183771609,-33.7257437677,-73.0183771609,-25.2943078258,-73.0183771609,-16.8628718839,-73.0183771609,-8.43143594193,-73.0183771609,-5.66068871864e-14,-73.0183771609,8.43143594193,-73.0183771609,16.8628718839,-73.0183771609,25.2943078258,-73.0183771609,33.7257437677,-73.0183771609,42.1571797097,-73.0183771609,46.3728976806,-65.7165394448,50.5886156516,-58.4147017287,54.8043336226,-51.1128640127,59.0200515935,-43.8110262966,63.2357695645,-36.5091885805,67.4514875354,-29.2073508644,71.6672055064,-21.9055131483,75.8829234774,-14.6036754322,80.0986414483,-7.3018377161]
9861         conn=[0,2,3,4,5,6,1,1,8,2,0,6,18,7,2,9,10,3,0,1,8,3,10,11,12,4,0,2,4,3,12,13,14,5,0,5,0,4,14,15,16,6,6,1,0,5,16,17,18,7,20,8,1,18,36,19,8,21,9,2,1,7,20,9,22,23,10,2,8,21,10,23,24,11,3,2,9,11,24,25,26,12,3,10,12,11,26,27,13,4,3,13,12,27,28,29,14,4,14,4,13,29,30,15,5,15,5,14,30,31,32,16,16,6,5,15,32,33,17,17,18,6,16,33,34,35,18,7,1,6,17,35,36,19,38,20,7,36,60,37,20,39,21,8,7,19,38,21,40,22,9,8,20,39,22,41,42,23,9,21,40,23,42,43,24,10,9,22,24,43,44,25,11,10,23,25,44,45,46,26,11,24,26,25,46,47,27,12,11,27,26,47,48,28,13,12,28,27,48,49,50,29,13,29,13,28,50,51,30,14,30,14,29,51,52,31,15,31,15,30,52,53,54,32,32,16,15,31,54,55,33,33,17,16,32,55,56,34,34,35,17,33,56,57,58,35,36,18,17,34,58,59,36,19,7,18,35,59,60,37,62,38,19,60,90,61,38,63,39,20,19,37,62,39,64,40,21,20,38,63,40,65,41,22,21,39,64,41,66,67,42,22,40,65,42,67,68,43,23,22,41,43,68,69,44,24,23,42,44,69,70,45,25,24,43,45,70,71,72,46,25,44,46,45,72,73,47,26,25,47,46,73,74,48,27,26,48,47,74,75,49,28,27,49,48,75,76,77,50,28,50,28,49,77,78,51,29,51,29,50,78,79,52,30,52,30,51,79,80,53,31,53,31,52,80,81,82,54,54,32,31,53,82,83,55,55,33,32,54,83,84,56,56,34,33,55,84,85,57,57,58,34,56,85,86,87,58,59,35,34,57,87,88,59,60,36,35,58,88,89,60,37,19,36,59,89,90,61,92,62,37,90,126,91,62,93,63,38,37,61,92,63,94,64,39,38,62,93,64,95,65,40,39,63,94,65,96,66,41,40,64,95,66,97,98,67,41,65,96,67,98,99,68,42,41,66,68,99,100,69,43,42,67,69,100,101,70,44,43,68,70,101,102,71,45,44,69,71,102,103,104,72,45,70,72,71,104,105,73,46,45,73,72,105,106,74,47,46,74,73,106,107,75,48,47,75,74,107,108,76,49,48,76,75,108,109,110,77,49,77,49,76,110,111,78,50,78,50,77,111,112,79,51,79,51,78,112,113,80,52,80,52,79,113,114,81,53,81,53,80,114,115,116,82,82,54,53,81,116,117,83,83,55,54,82,117,118,84,84,56,55,83,118,119,85,85,57,56,84,119,120,86,86,87,57,85,120,121,122,87,88,58,57,86,122,123,88,89,59,58,87,123,124,89,90,60,59,88,124,125,90,61,37,60,89,125,126,91,128,92,61,126,168,127,92,129,93,62,61,91,128,93,130,94,63,62,92,129,94,131,95,64,63,93,130,95,132,96,65,64,94,131,96,133,97,66,65,95,132,97,134,135,98,66,96,133,98,135,136,99,67,66,97,99,136,137,100,68,67,98,100,137,138,101,69,68,99,101,138,139,102,70,69,100,102,139,140,103,71,70,101,103,140,141,142,104,71,102,104,103,142,143,105,72,71,105,104,143,144,106,73,72,106,105,144,145,107,74,73,107,106,145,146,108,75,74,108,107,146,147,109,76,75,109,108,147,148,149,110,76,110,76,109,149,150,111,77,111,77,110,150,151,112,78,112,78,111,151,152,113,79,113,79,112,152,153,114,80,114,80,113,153,154,115,81,115,81,114,154,155,156,116,116,82,81,115,156,157,117,117,83,82,116,157,158,118,118,84,83,117,158,159,119,119,85,84,118,159,160,120,120,86,85,119,160,161,121,121,122,86,120,161,162,163,122,123,87,86,121,163,164,123,124,88,87,122,164,165,124,125,89,88,123,165,166,125,126,90,89,124,166,167,126,91,61,90,125,167,168,127,170,128,91,168,216,169,128,171,129,92,91,127,170,129,172,130,93,92,128,171,130,173,131,94,93,129,172,131,174,132,95,94,130,173,132,175,133,96,95,131,174,133,176,134,97,96,132,175,134,177,178,135,97,133,176,135,178,179,136,98,97,134,136,179,180,137,99,98,135,137,180,181,138,100,99,136,138,181,182,139,101,100,137,139,182,183,140,102,101,138,140,183,184,141,103,102,139,141,184,185,186,142,103,140,142,141,186,187,143,104,103,143,142,187,188,144,105,104,144,143,188,189,145,106,105,145,144,189,190,146,107,106,146,145,190,191,147,108,107,147,146,191,192,148,109,108,148,147,192,193,194,149,109,149,109,148,194,195,150,110,150,110,149,195,196,151,111,151,111,150,196,197,152,112,152,112,151,197,198,153,113,153,113,152,198,199,154,114,154,114,153,199,200,155,115,155,115,154,200,201,202,156,156,116,115,155,202,203,157,157,117,116,156,203,204,158,158,118,117,157,204,205,159,159,119,118,158,205,206,160,160,120,119,159,206,207,161,161,121,120,160,207,208,162,162,163,121,161,208,209,210,163,164,122,121,162,210,211,164,165,123,122,163,211,212,165,166,124,123,164,212,213,166,167,125,124,165,213,214,167,168,126,125,166,214,215,168,127,91,126,167,215,216,169,218,170,127,216,270,217,170,219,171,128,127,169,218,171,220,172,129,128,170,219,172,221,173,130,129,171,220,173,222,174,131,130,172,221,174,223,175,132,131,173,222,175,224,176,133,132,174,223,176,225,177,134,133,175,224,177,226,227,178,134,176,225,178,227,228,179,135,134,177,179,228,229,180,136,135,178,180,229,230,181,137,136,179,181,230,231,182,138,137,180,182,231,232,183,139,138,181,183,232,233,184,140,139,182,184,233,234,185,141,140,183,185,234,235,236,186,141,184,186,185,236,237,187,142,141,187,186,237,238,188,143,142,188,187,238,239,189,144,143,189,188,239,240,190,145,144,190,189,240,241,191,146,145,191,190,241,242,192,147,146,192,191,242,243,193,148,147,193,192,243,244,245,194,148,194,148,193,245,246,195,149,195,149,194,246,247,196,150,196,150,195,247,248,197,151,197,151,196,248,249,198,152,198,152,197,249,250,199,153,199,153,198,250,251,200,154,200,154,199,251,252,201,155,201,155,200,252,253,254,202,202,156,155,201,254,255,203,203,157,156,202,255,256,204,204,158,157,203,256,257,205,205,159,158,204,257,258,206,206,160,159,205,258,259,207,207,161,160,206,259,260,208,208,162,161,207,260,261,209,209,210,162,208,261,262,263,210,211,163,162,209,263,264,211,212,164,163,210,264,265,212,213,165,164,211,265,266,213,214,166,165,212,266,267,214,215,167,166,213,267,268,215,216,168,167,214,268,269,216,169,127,168,215,269,270,217,272,218,169,270,330,271,218,273,219,170,169,217,272,219,274,220,171,170,218,273,220,275,221,172,171,219,274,221,276,222,173,172,220,275,222,277,223,174,173,221,276,223,278,224,175,174,222,277,224,279,225,176,175,223,278,225,280,226,177,176,224,279,226,281,282,227,177,225,280,227,282,283,228,178,177,226,228,283,284,229,179,178,227,229,284,285,230,180,179,228,230,285,286,231,181,180,229,231,286,287,232,182,181,230,232,287,288,233,183,182,231,233,288,289,234,184,183,232,234,289,290,235,185,184,233,235,290,291,292,236,185,234,236,235,292,293,237,186,185,237,236,293,294,238,187,186,238,237,294,295,239,188,187,239,238,295,296,240,189,188,240,239,296,297,241,190,189,241,240,297,298,242,191,190,242,241,298,299,243,192,191,243,242,299,300,244,193,192,244,243,300,301,302,245,193,245,193,244,302,303,246,194,246,194,245,303,304,247,195,247,195,246,304,305,248,196,248,196,247,305,306,249,197,249,197,248,306,307,250,198,250,198,249,307,308,251,199,251,199,250,308,309,252,200,252,200,251,309,310,253,201,253,201,252,310,311,312,254,254,202,201,253,312,313,255,255,203,202,254,313,314,256,256,204,203,255,314,315,257,257,205,204,256,315,316,258,258,206,205,257,316,317,259,259,207,206,258,317,318,260,260,208,207,259,318,319,261,261,209,208,260,319,320,262,262,263,209,261,320,321,322,263,264,210,209,262,322,323,264,265,211,210,263,323,324,265,266,212,211,264,324,325,266,267,213,212,265,325,326,267,268,214,213,266,326,327,268,269,215,214,267,327,328,269,270,216,215,268,328,329,270,217,169,216,269,329,330,271,272,217,330,273,218,217,271,274,219,218,272,275,220,219,273,276,221,220,274,277,222,221,275,278,223,222,276,279,224,223,277,280,225,224,278,281,226,225,279,281,282,226,280,283,227,226,281,284,228,227,282,285,229,228,283,286,230,229,284,287,231,230,285,288,232,231,286,289,233,232,287,290,234,233,288,291,235,234,289,291,292,235,290,291,293,236,235,292,294,237,236,293,295,238,237,294,296,239,238,295,297,240,239,296,298,241,240,297,299,242,241,298,300,243,242,299,301,244,243,301,300,302,244,244,301,303,245,245,302,304,246,246,303,305,247,247,304,306,248,248,305,307,249,249,306,308,250,250,307,309,251,251,308,310,252,252,309,311,253,311,253,310,312,254,253,311,313,255,254,312,314,256,255,313,315,257,256,314,316,258,257,315,317,259,258,316,318,260,259,317,319,261,260,318,320,262,261,319,321,321,322,262,320,323,263,262,321,324,264,263,322,325,265,264,323,326,266,265,324,327,267,266,325,328,268,267,326,329,269,268,327,330,270,269,328,271,217,270,329]
9862         connI=[0,7,14,21,28,35,42,49,56,63,70,77,84,91,98,105,112,119,126,133,140,147,154,161,168,175,182,189,196,203,210,217,224,231,238,245,252,259,266,273,280,287,294,301,308,315,322,329,336,343,350,357,364,371,378,385,392,399,406,413,420,427,434,441,448,455,462,469,476,483,490,497,504,511,518,525,532,539,546,553,560,567,574,581,588,595,602,609,616,623,630,637,644,651,658,665,672,679,686,693,700,707,714,721,728,735,742,749,756,763,770,777,784,791,798,805,812,819,826,833,840,847,854,861,868,875,882,889,896,903,910,917,924,931,938,945,952,959,966,973,980,987,994,1001,1008,1015,1022,1029,1036,1043,1050,1057,1064,1071,1078,1085,1092,1099,1106,1113,1120,1127,1134,1141,1148,1155,1162,1169,1176,1183,1190,1197,1204,1211,1218,1225,1232,1239,1246,1253,1260,1267,1274,1281,1288,1295,1302,1309,1316,1323,1330,1337,1344,1351,1358,1365,1372,1379,1386,1393,1400,1407,1414,1421,1428,1435,1442,1449,1456,1463,1470,1477,1484,1491,1498,1505,1512,1519,1526,1533,1540,1547,1554,1561,1568,1575,1582,1589,1596,1603,1610,1617,1624,1631,1638,1645,1652,1659,1666,1673,1680,1687,1694,1701,1708,1715,1722,1729,1736,1743,1750,1757,1764,1771,1778,1785,1792,1799,1806,1813,1820,1827,1834,1841,1848,1855,1862,1869,1876,1883,1890,1897,1901,1905,1909,1913,1917,1921,1925,1929,1933,1937,1941,1945,1949,1953,1957,1961,1965,1969,1973,1977,1981,1985,1989,1993,1997,2001,2005,2009,2013,2017,2021,2025,2029,2033,2037,2041,2045,2049,2053,2057,2061,2065,2069,2073,2077,2081,2085,2089,2093,2097,2101,2105,2109,2113,2117,2121,2125,2129,2133,2137]
9863         #
9864         m=MEDCouplingUMesh.New("convexhull",2);
9865         m.allocateCells(331);
9866         for i in xrange(331):
9867             m.insertNextCell(NORM_POLYGON,conn[connI[i]:connI[i+1]]);
9868             pass
9869         m.finishInsertingCells();
9870         coordsDa=DataArrayDouble.New(coords,331,2);
9871         m.setCoords(coordsDa);
9872         m.checkCoherency();
9873         #
9874         da=m.convexEnvelop2D();
9875         m.checkCoherency()
9876         self.assertEqual(coordsDa.getHiddenCppPointer(),m.getCoords().getHiddenCppPointer())
9877         daC=da.buildComplement(m.getNumberOfCells());
9878         expected2=DataArrayInt.New([271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,302,303,304,305,306,307,308,309,310,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330]);
9879         self.assertTrue(expected2.isEqual(daC));
9880         #
9881         vals=m.getMeasureField(ON_CELLS).getArray()
9882         ref=271*[184.69493088478035]+3*[-61.564976961404426,-92.34746544254946,-92.34746544259811,-92.34746544253488,-92.3474654425349,-92.34746544180479,-92.34746544253493,-92.3474654419026,-92.34746544190256,-92.34746544253491]+2*[61.564976961404426,-92.34746544254946,-92.34746544259811,-92.34746544253488,-92.3474654425349,-92.34746544180479,-92.34746544253493,-92.3474654419026,-92.34746544190256,-92.34746544253491]+[-61.564976961404426,-92.34746544254946,-92.34746544259811,-92.34746544253488,-92.3474654425349,-92.34746544180479,-92.34746544253493,-92.3474654419026,-92.34746544190256,-92.34746544253491]
9883         vals-=DataArrayDouble.New(ref)
9884         vals.abs()
9885         theTest=vals.getIdsInRange(-1.,1e-7)
9886         self.assertTrue(theTest.isIdentity())
9887         self.assertEqual(331,len(theTest))
9888         pass
9889
9890     def testSwigDAIOp8(self):
9891         da=DataArrayInt.New([7,5,6,7,8,9,9,10,12,13,47,15])
9892         self.assertTrue(7 in da)
9893         self.assertTrue(47 in da)
9894         self.assertTrue(15 in da)
9895         self.assertEqual(0,da.index(7))
9896         self.assertEqual(10,da.index(47))
9897         self.assertTrue(14 not in da)
9898         self.assertEqual(5,da.search([9,9]))
9899         self.assertEqual(-1,da.search([5,8]))
9900         da.rearrange(2)
9901         self.assertTrue([47,16] not in da)
9902         self.assertTrue([5,6] not in da)
9903         self.assertTrue([6,7] in da)
9904         self.assertEqual(4,da.index([12,13]))
9905         pass
9906
9907     def testDataArraySort1(self):
9908         arr=DataArrayInt.New();
9909         self.assertRaises(InterpKernelException,arr.sort,True)
9910         self.assertRaises(InterpKernelException,arr.sort,False)
9911         values=[2,1,6,5,4,7]
9912         arr.alloc(3,2);
9913         self.assertRaises(InterpKernelException,arr.sort,True)
9914         self.assertRaises(InterpKernelException,arr.sort,False)
9915         arr.rearrange(1);
9916         arr.setValues(values,6,1)
9917         arr1=arr.deepCpy();
9918         arr2=arr.deepCpy();
9919         arr1.sort(True);
9920         expected1=[1,2,4,5,6,7]
9921         self.assertEqual(6,arr1.getNumberOfTuples());
9922         self.assertEqual(1,arr1.getNumberOfComponents());
9923         self.assertEqual(expected1,arr1.getValues());
9924         arr2.sort(False);
9925         expected2=[7,6,5,4,2,1]
9926         self.assertEqual(6,arr2.getNumberOfTuples());
9927         self.assertEqual(1,arr2.getNumberOfComponents());
9928         self.assertTrue(expected2,arr2.getValues());
9929         #
9930         ard=DataArrayDouble.New();
9931         self.assertRaises(InterpKernelException,ard.sort,True)
9932         self.assertRaises(InterpKernelException,ard.sort,False)
9933         valuesD=[2.,1.,6.,5.,4.,7.]
9934         ard.alloc(3,2);
9935         self.assertRaises(InterpKernelException,ard.sort,True)
9936         self.assertRaises(InterpKernelException,ard.sort,False)
9937         ard.rearrange(1);
9938         ard.setValues(valuesD,6,1)
9939         ard1=ard.deepCpy();
9940         ard2=ard.deepCpy();
9941         ard1.sort(True);
9942         expected3=[1.,2.,4.,5.,6.,7.]
9943         self.assertEqual(6,ard1.getNumberOfTuples());
9944         self.assertEqual(1,ard1.getNumberOfComponents());
9945         for i in xrange(6):
9946             self.assertAlmostEqual(expected3[i],ard1.getIJ(i,0),12)
9947             pass
9948         ard2.sort(False);
9949         expected4=[7.,6.,5.,4.,2.,1.]
9950         self.assertEqual(6,ard2.getNumberOfTuples());
9951         self.assertEqual(1,ard2.getNumberOfComponents());
9952         for i in xrange(6):
9953             self.assertAlmostEqual(expected4[i],ard2.getIJ(i,0),12)
9954             pass
9955         pass
9956     
9957     def testPartitionBySpreadZone1(self):
9958         m=MEDCouplingDataForTest.build2DTargetMesh_1();
9959         m4=MEDCouplingUMesh.MergeUMeshes([m,m[-3:],m[0:2]]);
9960         m4.renumberCells([5,2,9,6,4,7,0,1,3,8]);
9961         #
9962         v2=m4.partitionBySpreadZone();
9963         self.assertTrue(3,len(v2));
9964         self.assertTrue(v2[0].isEqual(DataArrayInt.New([0,1,7])))
9965         self.assertTrue(v2[1].isEqual(DataArrayInt.New([2,4,5,6,9])))
9966         self.assertTrue(v2[2].isEqual(DataArrayInt.New([3,8])))
9967         #
9968         m5=m4.buildSpreadZonesWithPoly();
9969         self.assertEqual(3,m5.getNumberOfCells());
9970         self.assertTrue(m5.getCoords().getHiddenCppPointer()==m4.getCoords().getHiddenCppPointer());
9971         self.assertEqual([5,15,16,17,14,11,13,12,5,2,1,0,3,6,7,8,5,5,18,21,22,20,19],m5.getNodalConnectivity().getValues())
9972         self.assertEqual([0,8,17,23],m5.getNodalConnectivityIndex().getValues())
9973         #
9974         pass
9975
9976     def testGiveCellsWithType1(self):
9977         expected0=[1,2]
9978         expected1=[0,3,4]
9979         m=MEDCouplingDataForTest.build2DTargetMesh_1();
9980         da=m.giveCellsWithType(NORM_TRI3);
9981         self.assertEqual(2,da.getNumberOfTuples());
9982         self.assertEqual(1,da.getNumberOfComponents());
9983         self.assertEqual(expected0,da.getValues())
9984         #
9985         da=m.giveCellsWithType(NORM_QUAD4);
9986         self.assertEqual(3,da.getNumberOfTuples());
9987         self.assertEqual(1,da.getNumberOfComponents());
9988         self.assertEqual(expected1,da.getValues())
9989         #
9990         da=m.giveCellsWithType(NORM_TRI6);
9991         self.assertEqual(0,da.getNumberOfTuples());
9992         self.assertEqual(1,da.getNumberOfComponents());
9993         #
9994         self.assertRaises(InterpKernelException,m.giveCellsWithType,NORM_SEG2)
9995         self.assertRaises(InterpKernelException,m.giveCellsWithType,NORM_HEXA8)
9996         pass
9997
9998     def testSwigDAOp1(self):
9999         d=DataArrayDouble.New(5,2)
10000         d.rearrange(1) ; d.iota(2.) ; d.rearrange(2)
10001         d.setInfoOnComponents(["X [m]","Y [m]"])
10002         d.setName("AName")
10003         #
10004         d1=d+[8,9]
10005         self.assertTrue(d1.isEqualWithoutConsideringStr(DataArrayDouble.New([10.0,12.0,12.0,14.0,14.0,16.0,16.0,18.0,18.0,20.0]),1e-12))
10006         d1bis=DataArrayDouble.New([8,9],1,2)+d
10007         self.assertTrue(d1bis.isEqual(d1,1e-12))
10008         d1ter=[8,9]+d
10009         self.assertTrue(d1ter.isEqual(d1,1e-12))
10010         #
10011         d2=d1-[8,9]
10012         self.assertTrue(d2.isEqual(d,1e-12))
10013         self.assertRaises(InterpKernelException,d1.__rsub__,[8,9])#[8,9]-d1
10014         #
10015         d3=d*[8,9]
10016         self.assertTrue(d3.isEqualWithoutConsideringStr(DataArrayDouble.New([16.0,27.0,32.0,45.0,48.0,63.0,64.0,81.0,80.0,99.0]),1e-12))
10017         d3bis=DataArrayDouble.New([8,9],1,2)*d
10018         self.assertTrue(d3bis.isEqual(d3,1e-12))
10019         d3ter=[8,9]*d
10020         self.assertTrue(d3ter.isEqual(d3,1e-12))
10021         #
10022         d4=d3/[8,9]
10023         self.assertTrue(d4.isEqual(d,1e-12))
10024         #
10025         d=DataArrayInt.New(5,2)
10026         d.rearrange(1) ; d.iota(2) ; d.rearrange(2)
10027         d.setInfoOnComponents(["X [m]","Y [m]"])
10028         d.setName("AName")
10029         #
10030         d1=d+[8,9]
10031         self.assertEqual(d1.getValues(),[10,12,12,14,14,16,16,18,18,20])
10032         d1bis=DataArrayInt.New([8,9],1,2)+d
10033         self.assertTrue(d1bis.isEqual(d1))
10034         d1ter=[8,9]+d
10035         self.assertTrue(d1ter.isEqual(d1))
10036         #
10037         d2=d1-[8,9]
10038         self.assertTrue(d2.isEqual(d))
10039         self.assertRaises(InterpKernelException,d1.__rsub__,[8,9])
10040         #
10041         d3=d*[8,9]
10042         self.assertEqual(d3.getValues(),[16,27,32,45,48,63,64,81,80,99])
10043         d3bis=DataArrayInt.New([8,9],1,2)*d
10044         self.assertTrue(d3bis.isEqual(d3))
10045         d3ter=[8,9]*d
10046         self.assertTrue(d3ter.isEqual(d3))
10047         #
10048         d4=d3/[8,9]
10049         self.assertTrue(d4.isEqual(d))
10050         #
10051         d5=d%[4,5]
10052         self.assertEqual(d5.getValues(),[2,3,0,0,2,2,0,4,2,1])
10053         pass
10054
10055     def testSwigSelectTupleId2DAIBug1(self):
10056         da=DataArrayInt.New([0,1,2,3,12,13,4,5,6,7,14,15,8,9,10,11,16,17])
10057         self.assertEqual([2,6,10],da[2::6].getValues())
10058         self.assertEqual([0,4,8],da[::6].getValues())
10059         self.assertEqual([5,9],da[7::6].getValues())
10060         self.assertEqual([5],da[7:-5:6].getValues())
10061         pass
10062
10063     def testSwigCpp5Safe1(self):
10064         m=MEDCouplingUMesh.New("toto",2)
10065         coords=DataArrayDouble.New([0.,0.,1.,0.,1.,1.,0.,1.],4,2)
10066         m.setCoords(coords)
10067         vecs=DataArrayDouble.New([2.,3.,4.,5.,6.,7.],3,2)
10068         expected1=[[2.,3.,3.,3.,3.,4.,2.,4.0],[4.,5.,5.,5.,5.,6.,4.,6.0],[6.,7.,7.,7.,7.,8.,6.,8.0]]
10069         for pos,vec in enumerate(vecs):
10070             m2=m.deepCpy()
10071             m2.translate(vec)
10072             self.assertTrue(m2.getCoords().isEqual(DataArrayDouble.New(expected1[pos],4,2),1e-12))
10073             pass
10074         for pos,vec in enumerate(vecs):
10075             m2=m.deepCpy()
10076             m2.translate(vec.buildDADouble())
10077             self.assertTrue(m2.getCoords().isEqual(DataArrayDouble.New(expected1[pos],4,2),1e-12))
10078             pass
10079         pass
10080     
10081     def testSwigBugNonRegressionZipDA(self):
10082         angles=map(lambda x:pi/3*x,xrange(6))
10083         radius=3
10084         #
10085         dad=DataArrayDouble.New(6, 2)
10086         dad[:,0]=radius
10087         dad[:,1]=angles
10088         #
10089         dad2=dad.fromPolarToCart()
10090         dads=[dad2.deepCpy() for elt in 7*[None]]
10091         #
10092         translationToPerform=[[0.01,0.02],[3./2.*radius,-radius*sqrt(3.)/2],[3./2.*radius,radius*sqrt(3.)/2],[0.,radius*sqrt(3.)],[-3./2.*radius,radius*sqrt(3.)/2],[-3./2.*radius,-radius*sqrt(3.)/2],[0.,-radius*sqrt(3.)]]
10093         for d,t in zip(dads,translationToPerform):
10094             d+=t
10095             pass
10096         for elt in dads:
10097             self.assertTrue(not dad2.isEqual(elt,1e-12))
10098             pass
10099         for d,t in zip(dads,translationToPerform):
10100             d-=t
10101             pass
10102         for elt in dads:
10103             self.assertTrue(dad2.isEqual(elt,1e-12))
10104             pass
10105         pass
10106
10107     def testBuildSlice3D2(self):
10108         mesh3D,mesh2D=MEDCouplingDataForTest.build3DExtrudedUMesh_1();
10109         vec1=[-0.07,1.,0.07]
10110         origin1=[1.524,1.4552,1.74768]
10111         slice1,ids=mesh3D.buildSlice3D(origin1,vec1,1e-10);
10112         f=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME)
10113         f.setTime(4.5,6,7) ; f.setMesh(mesh3D)
10114         arr=DataArrayDouble(mesh3D.getNumberOfCells(),2)
10115         arr.rearrange(1) ; arr.iota(2.) ; arr.rearrange(2)
10116         f.setArray(arr)
10117         f.checkCoherency()
10118         expected1=DataArrayInt([1,3,4,7,9,10,13,15,16])
10119         self.assertTrue(expected1.isEqual(ids))
10120         arr2=arr[expected1]
10121         #
10122         f2=f.extractSlice3D(origin1,vec1,1e-10)
10123         self.assertTrue(f2.getArray().isEqual(arr2,1e-12));
10124         self.assertTrue(slice1.isEqual(f2.getMesh(),1e-12))
10125         self.assertEqual(6,f2.getTime()[1]) ; self.assertEqual(7,f2.getTime()[2])
10126         self.assertAlmostEqual(4.5,f2.getTime()[0],12);
10127         pass
10128
10129     def testComputeTupleIdsToSelectFromCellIds1(self):
10130         m=MEDCouplingDataForTest.build2DTargetMesh_3()
10131         f=MEDCouplingFieldDouble.New(ON_GAUSS_NE,NO_TIME);
10132         f.setMesh(m);
10133         arr=DataArrayDouble(52,2) ; arr.rearrange(1) ; arr.iota(7.) ; arr.rearrange(2)
10134         f.setArray(arr)
10135         #
10136         f2=f.buildSubPart([1,5,9])
10137         f2.checkCoherency()
10138         cI=m.computeNbOfNodesPerCell()
10139         cI.computeOffsets2()
10140         sel=DataArrayInt([1,5,9])
10141         res=sel.buildExplicitArrByRanges(cI)
10142         arr2=arr[res]
10143         self.assertTrue(arr2.isEqual(DataArrayDouble([13,14,15,16,17,18,19,20,59,60,61,62,63,64,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110],15,2),1e-12))
10144         self.assertTrue(arr2.isEqual(f2.getArray(),1e-12))
10145         pass
10146
10147     def testComputeSkin1(self):
10148         arrX=DataArrayDouble([2.,3.4,5.6,7.7,8.0]) ; arrY=DataArrayDouble([2.,3.4,5.6,7.7,9.0,14.2])
10149         cmesh=MEDCouplingCMesh() ; cmesh.setCoordsAt(0,arrX) ; cmesh.setCoordsAt(1,arrY)
10150         umesh=cmesh.buildUnstructured()
10151         #
10152         skin=umesh.computeSkin()
10153         self.assertEqual(18,skin.getNumberOfCells())
10154         self.assertEqual(1,skin.getMeshDimension())
10155         self.assertTrue(skin.getCoords().getHiddenCppPointer()==umesh.getCoords().getHiddenCppPointer())
10156         self.assertEqual([0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54],skin.getNodalConnectivityIndex().getValues())
10157         self.assertEqual([1,1,0,1,0,5,1,2,1,1,3,2,1,4,3,1,9,4,1,5,10,1,14,9,1,10,15,1,19,14,1,15,20,1,24,19,1,20,25,1,25,26,1,26,27,1,27,28,1,28,29,1,29,24],skin.getNodalConnectivity().getValues())
10158         ids=skin.computeFetchedNodeIds()
10159         self.assertEqual([0,1,2,3,4,5,9,10,14,15,19,20,24,25,26,27,28,29],ids.getValues())
10160         part=umesh.buildFacePartOfMySelfNode(ids,True)
10161         part.setName(skin.getName());
10162         self.assertTrue(part.isEqual(skin,1e-12))
10163         part2=part[1::2]
10164         part[::2]=part2
10165         self.assertTrue(not part.isEqual(skin,1e-12))
10166         trad=part.zipConnectivityTraducer(0)
10167         self.assertEqual(9,part.getNumberOfCells())
10168         self.assertEqual([0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8],trad.getValues())
10169         pass
10170
10171     def testUMeshSetPartOfMySelf2(self):
10172         # resize with explicit ids list
10173         m=MEDCouplingDataForTest.build2DTargetMesh_1()
10174         self.assertEqual([3,4],m.getAllGeoTypes())
10175         part=m[[0,3,4]]
10176         part.simplexize(0)
10177         part2=part[[1,2,5]]
10178         m[[0,3,4]]=part2
10179         self.assertEqual([3,0,4,1,3,1,4,2,3,4,5,2,3,6,7,4,3,7,5,4],m.getNodalConnectivity().getValues())
10180         self.assertEqual([0,4,8,12,16,20],m.getNodalConnectivityIndex().getValues())
10181         self.assertEqual([3],m.getAllGeoTypes())
10182         # no resize with explicit ids list
10183         m=MEDCouplingDataForTest.build2DTargetMesh_1()
10184         part=m[[0,3]]
10185         part.convertAllToPoly()
10186         m[[3,4]]=part
10187         self.assertEqual([4,0,3,4,1,3,1,4,2,3,4,5,2,5,0,3,4,1,5,6,7,4,3],m.getNodalConnectivity().getValues())
10188         self.assertEqual([0,5,9,13,18,23],m.getNodalConnectivityIndex().getValues())
10189         self.assertEqual([3,4,5],m.getAllGeoTypes())
10190         # resize with range ids
10191         m=MEDCouplingDataForTest.build2DTargetMesh_1()
10192         part=m[3:]
10193         m[1:3]=part
10194         self.assertEqual([4,0,3,4,1,4,6,7,4,3,4,7,8,5,4,4,6,7,4,3,4,7,8,5,4],m.getNodalConnectivity().getValues())
10195         self.assertEqual([0,5,10,15,20,25],m.getNodalConnectivityIndex().getValues())
10196         self.assertEqual([4],m.getAllGeoTypes())
10197         # no resize with range ids
10198         m=MEDCouplingDataForTest.build2DTargetMesh_1()
10199         part=m[0::3]
10200         part.convertAllToPoly()
10201         m[3:]=part
10202         self.assertEqual([4,0,3,4,1,3,1,4,2,3,4,5,2,5,0,3,4,1,5,6,7,4,3],m.getNodalConnectivity().getValues())
10203         self.assertEqual([0,5,9,13,18,23],m.getNodalConnectivityIndex().getValues())
10204         self.assertEqual([3,4,5],m.getAllGeoTypes())
10205         # no resize with range ids negative direction
10206         m=MEDCouplingDataForTest.build2DTargetMesh_1()
10207         part=m[3::-3]
10208         part.convertAllToPoly()
10209         m[:-3:-1]=part
10210         self.assertEqual([4,0,3,4,1,3,1,4,2,3,4,5,2,5,0,3,4,1,5,6,7,4,3],m.getNodalConnectivity().getValues())
10211         self.assertEqual([0,5,9,13,18,23],m.getNodalConnectivityIndex().getValues())
10212         self.assertEqual([3,4,5],m.getAllGeoTypes())
10213         pass
10214
10215     def testUnPolyze3(self):
10216         coord=[0.0,0.5,-0.5,-0.5,-0.5,-0.5,0.5,-0.5,-0.5,0.0,0.5,0.5,-0.5,-0.5,0.5,0.5,-0.5,0.5]
10217         conn=[1,2,5,4,-1,4,3,0,1,-1,2,0,3,5,-1,0,2,1,-1,4,5,3]
10218         m=MEDCouplingUMesh.New("a mesh",3);
10219         m.allocateCells(1);
10220         m.insertNextCell(NORM_POLYHED,22,conn[0:22])
10221         m.finishInsertingCells();
10222         coords=DataArrayDouble(coord,6,3);
10223         m.setCoords(coords);
10224         m.checkCoherency();
10225         #
10226         vol=m.getMeasureField(ON_CELLS);
10227         self.assertEqual(1,vol.getArray().getNumberOfTuples());
10228         self.assertAlmostEqual(0.5,vol.getArray().getIJ(0,0),12)
10229         #
10230         m.unPolyze();
10231         #
10232         self.assertEqual([NORM_PENTA6],m.getAllGeoTypes())
10233         self.assertTrue(DataArrayInt([0,7]).isEqual(m.getNodalConnectivityIndex()))
10234         self.assertTrue(DataArrayInt([16,0,2,1,3,5,4]).isEqual(m.getNodalConnectivity()))
10235         #
10236         vol=m.getMeasureField(ON_CELLS);
10237         self.assertEqual(1,vol.getArray().getNumberOfTuples());
10238         self.assertAlmostEqual(0.5,vol.getArray().getIJ(0,0),12)
10239         pass
10240
10241     def testKrSpatialDiscretization1(self):
10242         srcPointCoordsX=[0.8401877171547095, 0.7830992237586059, 0.9116473579367843, 0.335222755714889, 0.2777747108031878, 0.4773970518621602, 0.3647844727918433, 0.9522297251747128, 0.6357117279599009, 0.1416025553558034]
10243         srcFieldValsOnPoints=[2.129892434968836, 2.295320474540621, 1.931948594981134, 2.728013590937196, 2.715603240418478, 2.661778472822935, 2.695696990104364, 1.893710234970982, 2.529628016549284, 2.728432341300668]
10244         targetPointCoordsX=[-0.5,-0.45,-0.4,-0.35,-0.3,-0.25,-0.2,-0.15,-0.1,-0.05,-6.93889390391e-17,0.05,0.1,0.15,0.2,0.25,0.3,0.35,0.4,0.45,0.5,0.55,0.6,0.65,0.7,0.75,0.8,0.85,0.9,0.95,1.0,1.05,1.1,1.15,1.2,1.25,1.3,1.35,1.4,1.45]
10245         targetFieldValsExpected=[2.975379475824351, 2.95613491917003, 2.936890362515361, 2.917645805861018, 2.898401249206574, 2.879156692552137, 2.859912135897732, 2.840667579243201, 2.821423022588731, 2.802178465934342, 2.78293390927989, 2.763689352625457, 2.744444795971001, 2.725209522098197, 2.709077577124666, 2.706677252549218, 2.727467797847971, 2.713338094723676, 2.671342424824244, 2.664877370146978, 2.653840141412181, 2.619607861392791, 2.569777214476479, 2.513263929794591, 2.450732752808528, 2.368313560985155, 2.250909795670307, 2.098194272085416, 1.954257891732065, 1.895040660973802, 1.865256788315972, 1.835475248687992, 1.80569370905998, 1.775912169431971, 1.746130629803976, 1.716349090175918, 1.686567550547855, 1.656786010919941, 1.627004471291988, 1.597222931663817]
10246         coeffsExpected=DataArrayDouble.New([52.238272642008695, 26.186513281350948, -173.42106377948534, 324.56733663875184, -104.64968873410248, 34.375030568158316, -256.12372208190425, 105.2292032463934, -16.239907618144965, 7.838025836978943, 2.621910745077291, -0.4902609628247241])
10247         #
10248         nbOfInputPoints=10;
10249         f=MEDCouplingFieldDouble.New(ON_NODES_KR,ONE_TIME);
10250         srcArrX=DataArrayDouble.New(srcPointCoordsX,nbOfInputPoints,1);
10251         cmesh=MEDCouplingCMesh.New("aMesh");
10252         cmesh.setCoordsAt(0,srcArrX);
10253         umesh=cmesh.buildUnstructured();
10254         f.setMesh(umesh);
10255         srcVals=DataArrayDouble.New(srcFieldValsOnPoints,nbOfInputPoints,1);
10256         f.setArray(srcVals);
10257         f.checkCoherency();
10258         #
10259         res0=f.getValueOn(targetPointCoordsX[:1]);
10260         self.assertAlmostEqual(targetFieldValsExpected[0],res0[0],10)
10261         #
10262         valuesToTest=f.getValueOnMulti(targetPointCoordsX);
10263         self.assertEqual(40,valuesToTest.getNumberOfTuples());
10264         self.assertEqual(1,valuesToTest.getNumberOfComponents());
10265         for i in xrange(40):
10266             self.assertAlmostEqual(targetFieldValsExpected[i],valuesToTest.getIJ(i,0),10)
10267             pass
10268         fd=f.getDiscretization()
10269         del f
10270         self.assertTrue(isinstance(fd,MEDCouplingFieldDiscretizationKriging))
10271         coeffs,isDrift=fd.computeVectorOfCoefficients(umesh,srcVals)
10272         self.assertEqual(2,isDrift)
10273         self.assertTrue(coeffsExpected.isEqual(coeffs,1e-8))
10274         #
10275         pass
10276
10277     def testDuplicateEachTupleNTimes1(self):
10278         d=DataArrayDouble.New([9.,8.,7.,6.],4,1) ; d.setInfoOnComponents(["mass [kg]"]) ; d.setName("aname")
10279         d2=d.duplicateEachTupleNTimes(3)
10280         self.assertTrue(d2.isEqualWithoutConsideringStr(DataArrayDouble.New([9.,9.,9.,8.,8.,8.,7.,7.,7.,6.,6.,6.],4*3,1),1e-14))
10281         self.assertEqual("aname",d2.getName())
10282         self.assertEqual(["mass [kg]"],d2.getInfoOnComponents())
10283         #
10284         d=DataArrayInt.New([9,8,7,6],4,1) ; d.setInfoOnComponents(["mass [kg]"]) ; d.setName("aname")
10285         d2=d.duplicateEachTupleNTimes(3)
10286         self.assertTrue(d2.isEqualWithoutConsideringStr(DataArrayInt.New([9,9,9,8,8,8,7,7,7,6,6,6],4*3,1)))
10287         self.assertEqual("aname",d2.getName())
10288         self.assertEqual(["mass [kg]"],d2.getInfoOnComponents())
10289         pass
10290
10291     def testSwigComputeTupleIdsNearTuples1(self):
10292         da=DataArrayDouble([5.,6.,-5.,-6.,5.,-6.,-5.,6.,5.,6.],5,2)
10293         arr,arrI=da.computeTupleIdsNearTuples(DataArrayDouble([5.,-6.,5.,6.,-5.,-6.],3,2),1e-10)
10294         self.assertEqual([2,0,4,1],arr.getValues())
10295         self.assertEqual([0,1,3,4],arrI.getValues())
10296         arr,arrI=da.computeTupleIdsNearTuples([5.,-6.,5.,6.,-5.,-6.],1e-10)
10297         self.assertEqual([2,0,4,1],arr.getValues())
10298         self.assertEqual([0,1,3,4],arrI.getValues())
10299         expected0=[[2],[0,4],[1]]
10300         expected1=[[0,1],[0,2],[0,1]]
10301         for pos,it in enumerate(DataArrayDouble([5.,-6.,5.,6.,-5.,-6.],3,2)):
10302             arr,arrI=da.computeTupleIdsNearTuples(it,1e-10)
10303             self.assertEqual(expected0[pos],arr.getValues())
10304             self.assertEqual(expected1[pos],arrI.getValues())
10305             pass
10306         pass
10307
10308     def testSwigDataTupleIOp1(self):
10309         d=DataArrayDouble(10,1)
10310         d.iota(7.)
10311         for elt in d:
10312             elt+=2.
10313             pass
10314         toTest=DataArrayDouble([9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0])
10315         self.assertTrue(toTest.isEqual(d,1e-12))
10316         for elt in d:
10317             elt-=2.
10318             pass
10319         toTest=DataArrayDouble([7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0])
10320         self.assertTrue(toTest.isEqual(d,1e-12))
10321         for elt in d:
10322             elt*=2.
10323             pass
10324         toTest=DataArrayDouble([14.0,16.0,18.0,20.0,22.0,24.0,26.0,28.0,30.0,32.0])
10325         self.assertTrue(toTest.isEqual(d,1e-12))
10326         for elt in d:
10327             elt/=2.
10328             pass
10329         toTest=DataArrayDouble([7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0])
10330         self.assertTrue(toTest.isEqual(d,1e-12))
10331         #
10332         d=DataArrayInt(10,1)
10333         d.iota(7)
10334         for elt in d:
10335             elt+=2
10336             pass
10337         self.assertEqual(d.getValues(),[9,10,11,12,13,14,15,16,17,18])
10338         for elt in d:
10339             elt-=2
10340             pass
10341         self.assertEqual(d.getValues(),[7,8,9,10,11,12,13,14,15,16])
10342         for elt in d:
10343             elt*=2
10344             pass
10345         self.assertEqual(d.getValues(),[14,16,18,20,22,24,26,28,30,32])
10346         for elt in d:
10347             elt/=2
10348             pass
10349         self.assertEqual(d.getValues(),[7,8,9,10,11,12,13,14,15,16])
10350         for elt in d:
10351             elt%=3
10352             pass
10353         self.assertEqual(d.getValues(),[1,2,0,1,2,0,1,2,0,1])
10354         pass
10355
10356     def testIntersect2DMeshesTmp5(self):
10357         coords=DataArrayDouble.New([41,0,42,0,0,42,0,41,41.5,0,29.698484809834998,29.698484809834994,0,41.5,28.991378028648452,28.991378028648445,-42,0,-41,0,-29.698484809834994,29.698484809834998,-41.5,0,-28.991378028648445,28.991378028648452,0,-42,0,-41,-29.698484809835001,-29.698484809834994,0,-41.5,-28.991378028648455,-28.991378028648445,29.698484809834987,-29.698484809835001,28.991378028648441,-28.991378028648455,43,0,0,43,42.5,0,30.405591591021544,30.40559159102154,0,42.5,-43,0,-30.40559159102154,30.405591591021544,-42.5,0,0,-43,-30.405591591021551,-30.40559159102154,0,-42.5,30.405591591021537,-30.405591591021551,44,0,0,44,43.5,0,31.112698372208094,31.112698372208087,0,43.5,-44,0,-31.112698372208087,31.112698372208094,-43.5,0,0,-44,-31.112698372208097,-31.112698372208087,0,-43.5,31.112698372208083,-31.112698372208097,45,0,0,45,44.5,0,31.81980515339464,31.819805153394636,0,44.5,-45,0,-31.819805153394636,31.81980515339464,-44.5,0,0,-45,-31.819805153394647,-31.819805153394636,0,-44.5,31.819805153394629,-31.819805153394647,47,0,0,47,46,0,33.234018715767739,33.234018715767732,0,46,-47,0,-33.234018715767732,33.234018715767739,-46,0,0,-47,-33.234018715767739,-33.234018715767732,0,-46,33.234018715767725,-33.234018715767739,49,0,0,49,48,0,34.648232278140831,34.648232278140824,0,48,-49,0,-34.648232278140824,34.648232278140831,-48,0,0,-49,-34.648232278140839,-34.648232278140824,0,-48,34.648232278140817,-34.648232278140839,51,0,0,51,50,0,36.062445840513924,36.062445840513924,0,50,-51,0,-36.062445840513924,36.062445840513924,-50,0,0,-51,-36.062445840513931,-36.062445840513924,0,-50,36.062445840513917,-36.062445840513931,53,0,0,53,52,0,37.476659402887023,37.476659402887016,0,52,-53,0,-37.476659402887016,37.476659402887023,-52,0,0,-53,-37.47665940288703,-37.476659402887016,0,-52,37.476659402887009,-37.47665940288703,55,0,0,55,54,0,38.890872965260115,38.890872965260108,0,54,-55,0,-38.890872965260108,38.890872965260115,-54,0,0,-55,-38.890872965260122,-38.890872965260108,0,-54,38.890872965260101,-38.890872965260122,59,0,0,59,57,0,41.719300090006307,41.7193000900063,0,57,-59,0,-41.7193000900063,41.719300090006307,-57,0,0,-59,-41.719300090006314,-41.7193000900063,0,-57,41.719300090006293,-41.719300090006314,63,0,0,63,61,0,44.547727214752499,44.547727214752491,0,61,-63,0,-44.547727214752491,44.547727214752499,-61,0,0,-63,-44.547727214752506,-44.547727214752491,0,-61,44.547727214752484,-44.547727214752506,67,0,0,67,65,0,47.37615433949869,47.376154339498683,0,65,-67,0,-47.376154339498683,47.37615433949869,-65,0,0,-67,-47.376154339498697,-47.376154339498683,0,-65,47.376154339498676,-47.376154339498697,71,0,0,71,69,0,50.204581464244875,50.204581464244868,0,69,-71,0,-50.204581464244868,50.204581464244875,-69,0,0,-71,-50.204581464244889,-50.204581464244868,0,-69,50.20458146424486,-50.204581464244889,75,0,0,75,73,0,53.033008588991066,53.033008588991059,0,73,-75,0,-53.033008588991059,53.033008588991066,-73,0,0,-75,-53.033008588991073,-53.033008588991059,0,-73,53.033008588991052,-53.033008588991073,80,0,0,80,77.5,0,56.568542494923804,56.568542494923797,0,77.5,-80,0,-56.568542494923797,56.568542494923804,-77.5,0,0,-80,-56.568542494923818,-56.568542494923797,0,-77.5,56.56854249492379,-56.568542494923818],188,2)
10358         conn=DataArrayInt.New([8,0,1,2,3,4,5,6,7,8,3,2,8,9,6,10,11,12,8,9,8,13,14,11,15,16,17,8,14,13,1,0,16,18,4,19,8,1,20,21,2,22,23,24,5,8,2,21,25,8,24,26,27,10,8,8,25,28,13,27,29,30,15,8,13,28,20,1,30,31,22,18,8,20,32,33,21,34,35,36,23,8,21,33,37,25,36,38,39,26,8,25,37,40,28,39,41,42,29,8,28,40,32,20,42,43,34,31,8,32,44,45,33,46,47,48,35,8,33,45,49,37,48,50,51,38,8,37,49,52,40,51,53,54,41,8,40,52,44,32,54,55,46,43,8,44,56,57,45,58,59,60,47,8,45,57,61,49,60,62,63,50,8,49,61,64,52,63,65,66,53,8,52,64,56,44,66,67,58,55,8,56,68,69,57,70,71,72,59,8,57,69,73,61,72,74,75,62,8,61,73,76,64,75,77,78,65,8,64,76,68,56,78,79,70,67,8,68,80,81,69,82,83,84,71,8,69,81,85,73,84,86,87,74,8,73,85,88,76,87,89,90,77,8,76,88,80,68,90,91,82,79,8,80,92,93,81,94,95,96,83,8,81,93,97,85,96,98,99,86,8,85,97,100,88,99,101,102,89,8,88,100,92,80,102,103,94,91,8,92,104,105,93,106,107,108,95,8,93,105,109,97,108,110,111,98,8,97,109,112,100,111,113,114,101,8,100,112,104,92,114,115,106,103,8,104,116,117,105,118,119,120,107,8,105,117,121,109,120,122,123,110,8,109,121,124,112,123,125,126,113,8,112,124,116,104,126,127,118,115,8,116,128,129,117,130,131,132,119,8,117,129,133,121,132,134,135,122,8,121,133,136,124,135,137,138,125,8,124,136,128,116,138,139,130,127,8,128,140,141,129,142,143,144,131,8,129,141,145,133,144,146,147,134,8,133,145,148,136,147,149,150,137,8,136,148,140,128,150,151,142,139,8,140,152,153,141,154,155,156,143,8,141,153,157,145,156,158,159,146,8,145,157,160,148,159,161,162,149,8,148,160,152,140,162,163,154,151,8,152,164,165,153,166,167,168,155,8,153,165,169,157,168,170,171,158,8,157,169,172,160,171,173,174,161,8,160,172,164,152,174,175,166,163,8,164,176,177,165,178,179,180,167,8,165,177,181,169,180,182,183,170,8,169,181,184,172,183,185,186,173,8,172,184,176,164,186,187,178,175],540)
10359         connI=DataArrayInt.New([0,9,18,27,36,45,54,63,72,81,90,99,108,117,126,135,144,153,162,171,180,189,198,207,216,225,234,243,252,261,270,279,288,297,306,315,324,333,342,351,360,369,378,387,396,405,414,423,432,441,450,459,468,477,486,495,504,513,522,531,540],61)
10360         #
10361         m1=MEDCouplingUMesh.New("Fix",2);
10362         m1.setCoords(coords);
10363         m1.setConnectivity(conn,connI,True);
10364         #
10365         coords=DataArrayDouble([46.5,-2.5,53.5,-2.5,53.5,2.5,46.5,2.5,50,-2.5,53.5,0,50,2.5,46.5,0,60.5,-2.5,60.5,2.5,57,-2.5,60.5,0,57,2.5,53.5,7.5,46.5,7.5,53.5,5,50,7.5,46.5,5,60.5,7.5,60.5,5,57,7.5,-2,47,2,47,2,53,-2,53,0,47,2,50,0,53,-2,50,6,47,6,53,4,47,6,50,4,53,2,59,-2,59,2,56,0,59,-2,56,6,59,6,56,4,59],42,2)
10366         # connectivity
10367         conn=DataArrayInt([8,0,1,2,3,4,5,6,7,8,1,8,9,2,10,11,12,5,8,3,2,13,14,6,15,16,17,8,2,9,18,13,12,19,20,15,8,21,22,23,24,25,26,27,28,8,22,29,30,23,31,32,33,26,8,24,23,34,35,27,36,37,38,8,23,30,39,34,33,40,41,36],72);
10368         conn.setName("");
10369         connI=DataArrayInt([0,9,18,27,36,45,54,63,72],9)
10370         m2=MEDCouplingUMesh.New("Mobile",2);
10371         m2.setCoords(coords);
10372         m2.setConnectivity(conn,connI,True);
10373         #
10374         m3,d1,d2=MEDCouplingUMesh.Intersect2DMeshes(m1,m2,1e-10);
10375         self.assertEqual(105,m3.getNumberOfCells());
10376         self.assertEqual(105,d1.getNumberOfTuples());
10377         self.assertEqual(105,d2.getNumberOfTuples());
10378         self.assertEqual(704,m3.getNumberOfNodes());
10379         #
10380         areaExpected=[-65.18804756198824,-65.18804756198824,-65.18804756198824,-65.18804756198824,-66.75884388878285,-66.75884388878285,-66.7588438887833,-66.75884388878308,-68.32964021557768,-68.32964021557768,-68.32964021557814,-68.32964021557791,-69.9004365423732,-69.9004365423732,-69.90043654237297,-69.90043654237297,-1.194568659706448,-1.0869994447159463,-142.2316939607081,-144.51326206513068,-144.5132620651309,-1.1945686597064424,-143.3186934054243,-5.002264310862817,-10.0261332846393,-3.9727823117092953,-7.290862524642649,-124.504404940456,-3.9727823117093237,-146.82366506060032,-150.79644737231024,-5.002264310862776,-145.79418306144626,-5.00208651738126,-10.054764051268958,-4.001067863263231,-8.027932154428669,-129.99378209314813,-4.001067863263216,-153.07856481622616,-157.0796326794898,-5.0020865173811915,-152.07754616210832,-5.001928880064381,-10.050590216368969,-4.00098721602491,-8.025810856794209,-136.28350081741684,-4.000987216024939,-159.36183077064402,-163.36281798667005,-5.0019288800643285,-158.36088910660442,-1.2991516319851801,-3.702636830195414,-3.7815130030068254,-6.265364371195623,-0.02516260900254963,-0.6553944641345026,-3.975752765070567,-7.368528340442765,-142.57249927881398,-0.02516260900254963,-3.9757527650706095,-165.64508791977525,-169.64600329384803,-1.299151631985167,-3.7026368301953885,-164.6442148316677,-10.00321285677458,-20.08414323176165,-8.001644468035863,-16.042954878437143,-304.0096070742277,-8.00164446803587,-350.1399180412005,-358.1415625092368,-10.003212856774468,-348.13834965246224,-3.794150313030109,-8.65049239704272,-0.02260276689354157,-0.5885167811200915,-370.2185414798688,-0.022602766893559393,-383.2517009710623,-383.2743037379555,-3.7941503130300576,-379.48015342492505,-408.40704496667513,-408.4070449666742,-408.4070449666742,-408.4070449666742,-433.53978619538975,-433.5397861953902,-433.5397861953911,-433.53978619539066,-458.67252742410983,-458.6725274241094,-458.67252742410983,-458.6725274241089,-608.6835766330232,-608.6835766330232,-608.6835766330232,-608.6835766330241]
10381         expected1=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,16,16,17,18,19,19,20,20,20,20,20,21,21,22,23,23,24,24,24,24,24,25,25,26,27,27,28,28,28,28,28,29,29,30,31,31,32,32,32,32,32,32,32,32,32,33,33,33,34,35,35,35,36,36,36,36,36,37,37,38,39,39,40,40,40,40,40,41,41,42,43,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59]
10382         expected2=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,2,-1,-1,-1,0,-1,0,2,4,5,-1,4,-1,-1,0,-1,0,2,4,5,-1,4,-1,-1,0,-1,0,2,4,5,-1,4,-1,-1,0,-1,0,1,2,3,4,5,6,7,-1,4,6,-1,-1,0,1,-1,1,3,6,7,-1,6,-1,-1,1,-1,1,3,6,7,-1,6,-1,-1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]
10383         f3=m3.getMeasureField(ON_CELLS).getArray().getValues();
10384         for i in xrange(105):
10385             self.assertAlmostEqual(areaExpected[i],f3[i],10)
10386             pass
10387         self.assertEqual(expected1,d1.getValues())
10388         self.assertEqual(expected2,d2.getValues())
10389         pass
10390
10391     def testSwig2Intersect2DMeshesQuadra1(self):
10392         import cmath
10393         def createDiagCircle(lX, lY, R, cells=[0,1]):  
10394             """ A circle in a square box, cut along the diagonal. 
10395             """    
10396             c = []
10397             for i in range(8):
10398               c.append(cmath.rect(R, i*pi/4))
10399         
10400             coords = [0.0,0.0,          c[3].real,c[3].imag,       -lX/2.0, lY/2.0,
10401                       0.0, lY/2.0,      lX/2.0,lY/2.0,             lX/2.0,0.0,
10402                       #   6                  7                              8
10403                       lX/2.0,-lY/2.0,   c[7].real,c[7].imag,       c[1].real,c[1].imag,
10404                       #   9                  10                            11  
10405                       c[5].real,c[5].imag,   -lX/2.0,-lY/2.0,      0.0, -lY/2.0,
10406                       #   12                  13                            14
10407                       -lX/2.0,0.0,         0.0,0.0,                  0.0, 0.0]
10408             # Points 13 (reps. 14) are average of points (6,7) (resp (1,2))
10409             coords[13*2]   = 0.5*(coords[6*2]+coords[7*2])
10410             coords[13*2+1] = 0.5*(coords[6*2+1]+coords[7*2+1])
10411             coords[14*2]   = 0.5*(coords[1*2]+coords[2*2])
10412             coords[14*2+1] = 0.5*(coords[1*2+1]+coords[2*2+1])
10413             connec  = [1,7,8,0]      # half circle up right
10414             connec3 = [6,7,1,2,4,13,8,14,3,5]
10415             
10416             baseMesh = MEDCouplingUMesh.New("box_circle", 2)  
10417             baseMesh.allocateCells(2)
10418             meshCoords = DataArrayDouble.New(coords, len(coords)/2, 2)
10419             meshCoords.setInfoOnComponents(["X [au]", "Y [au]"])
10420             baseMesh.setCoords(meshCoords)
10421             
10422             if 0 in cells:
10423               baseMesh.insertNextCell(NORM_QPOLYG, connec)  
10424             if 1 in cells: 
10425               baseMesh.insertNextCell(NORM_QPOLYG, connec3) 
10426             baseMesh.finishInsertingCells()  
10427             baseMesh.checkCoherency() 
10428             return baseMesh 
10429         
10430         eps = 1.0e-7
10431         m1 = createDiagCircle(1.0, 1.0, 0.5*0.90, cells=[0,1])  
10432         m2 = createDiagCircle(1.0, 1.0, 0.5*0.95, cells=[0])
10433         m3, _, _= MEDCouplingUMesh.Intersect2DMeshes(m1, m2, eps)
10434         m3.mergeNodes(eps)
10435         m3.convertDegeneratedCells()
10436         m3.zipCoords()        
10437         m4 = m3.deepCpy()
10438         m5, _, _ = MEDCouplingUMesh.Intersect2DMeshes(m3, m4, eps)
10439         m5.mergeNodes(eps)
10440         # Check coordinates:
10441         self.assertTrue(m3.getCoords().isEqual(m5.getCoords(), eps))
10442
10443     def testIntersect2DMeshesTmp7(self):
10444         eps = 1.0e-8
10445         coords = [-0.5,-0.5,   -0.5, 0.5, 0.5, 0.5,    0.5,-0.5]
10446         connec = range(4)
10447         m1 = MEDCouplingUMesh.New("box", 2)  
10448         m1.allocateCells(1)
10449         meshCoords = DataArrayDouble.New(coords, len(coords)/2, 2)
10450         m1.setCoords(meshCoords)
10451         m1.insertNextCell(NORM_POLYGON, connec)
10452         m1.finishInsertingCells()  
10453      
10454         m2 = MEDCouplingDataForTest.buildCircle(0.25, 0.2, 0.4)
10455         # Was looping indefinitly:
10456         m_intersec, resToM1, resToM2 = MEDCouplingUMesh.Intersect2DMeshes(m1, m2, eps)
10457         m_intersec.zipCoords()
10458         coo_tgt = DataArrayDouble([-0.5, -0.5, -0.5, 0.5, 0.5, 0.5, 0.5, -0.5, -0.03284271247461901, 0.4828427124746191, 
10459           -0.014575131106459124, 0.5000000000000001, 0.5, -0.11224989991991996, 0.24271243444677046, 0.5, 0.5, 0.19387505004004, 
10460           -0.04799910280454185, -0.06682678787499614, -0.023843325638122054, 0.4915644577163915, 0.5, -0.30612494995996, 0.0, -0.5, 
10461           -0.5, 0.0, -0.25728756555322957, 0.5, -0.023843325638122026, 0.49156445771639157, -0.04799910280454181, -0.06682678787499613], 17 ,2)
10462         conn_tgt = [32, 5, 2, 6, 4, 7, 8, 9, 10, 32, 6, 3, 0, 1, 5, 4, 11, 12, 13, 14, 15, 16]
10463         connI_tgt = [0, 9, 22]
10464         res1_tgt  = [0, 0]
10465         res2_tgt = [0, -1]
10466         self.assert_(coo_tgt.isEqualWithoutConsideringStr(m_intersec.getCoords(), 1e-12))
10467         self.assertEqual(conn_tgt, m_intersec.getNodalConnectivity().getValues())
10468         self.assertEqual(connI_tgt, m_intersec.getNodalConnectivityIndex().getValues())
10469         self.assertEqual(res1_tgt, resToM1.getValues())
10470         self.assertEqual(res2_tgt, resToM2.getValues())
10471         
10472     def testDAIBuildUnique1(self):
10473         d=DataArrayInt([1,2,2,3,3,3,3,4,5,5,7,7,7,19])
10474         e=d.buildUnique()
10475         self.assertTrue(e.isEqual(DataArrayInt([1,2,3,4,5,7,19])))
10476         pass
10477
10478     def testDAIPartitionByDifferentValues1(self):
10479         d=DataArrayInt([1,0,1,2,0,2,2,-3,2])
10480         expected=[[-3,[7]],[0,[1,4]],[1,[0,2]],[2,[3,5,6,8]]]
10481         for i,elt in enumerate(zip(*d.partitionByDifferentValues())):
10482             self.assertEqual(expected[i][0],elt[1])
10483             self.assertEqual(expected[i][1],elt[0].getValues())
10484             pass
10485         pass
10486
10487     def testFieldGaussMultiDiscPerType1(self):
10488         coords=DataArrayDouble([0.,0.,0.,1.,1.,1.,1.,0.,0.,0.5,0.5,1.,1.,0.5,0.5,0.],8,2)
10489         mQ8=MEDCouplingUMesh("",2) ; mQ8.setCoords(coords)
10490         mQ8.allocateCells(1)
10491         mQ8.insertNextCell(NORM_QUAD8,range(8))
10492         mQ8.finishInsertingCells()
10493         mQ4=MEDCouplingUMesh("",2) ; mQ4.setCoords(coords)
10494         mQ4.allocateCells(1)
10495         mQ4.insertNextCell(NORM_QUAD4,range(4))
10496         mQ4.finishInsertingCells()
10497         mT3=MEDCouplingUMesh("",2) ; mT3.setCoords(coords)
10498         mT3.allocateCells(1)
10499         mT3.insertNextCell(NORM_TRI3,range(3))
10500         mT3.finishInsertingCells()
10501         
10502         tr=[[0.,0.],[2.,0.], [0.,2.],[2.,2.],[4.,2.],[6.,2.],[8.,2.],[10.,2.],[12.,2.],[0.,4.],[2.,4.],[4.,4.],[6.,4.],[8.,4.],[10.,4.],[12.,4.],[14.,4.],[16.,4.],[18.,4.],[20.,4.],[22.,4.]]
10503         ms=2*[mQ4]+7*[mQ8]+11*[mT3]
10504         ms[:]=(elt.deepCpy() for elt in ms)
10505         for m,t in zip(ms,tr):
10506             d=m.getCoords() ; d+= t
10507             pass
10508         m=MEDCouplingUMesh.MergeUMeshes(ms)
10509         f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,NO_TIME)
10510         f.setMesh(m)
10511         # throw because cell 0,1 are QUAD4 and cell 3 is QUAD8
10512         self.assertRaises(InterpKernelException,f.setGaussLocalizationOnCells,[0,1,3],[0.,0.,1.,0.,1.,1.,0.,1.],[0.3,0.3,0.7,0.7],[0.8,0.2])
10513         f.setGaussLocalizationOnCells([0,1],[0.,0.,1.,0.,1.,1.,0.,1.],[0.3,0.3,0.7,0.7],[0.8,0.2])
10514         f.setGaussLocalizationOnCells([3,2,5],[0.,0.,1.,0.,1.,1.,0.,1.,0.5,0.,1.,0.5,0.5,1.,0.,0.5],[0.3,0.3,0.7,0.7,0.9,0.9],[0.8,0.05,0.15])
10515         f.setGaussLocalizationOnCells([4,6,8,7],[0.,0.,1.,0.,1.,1.,0.,1.,0.5,0.,1.,0.5,0.5,1.,0.,0.5],[0.3,0.3,0.7,0.7,0.9,0.9,-0.1,0.3],[0.7,0.05,0.15,0.1])
10516         f.setGaussLocalizationOnCells([9,10,11,12,13],[0.,0.,1.,0.,1.,1.],[0.4,0.4],[1.])
10517         f.setGaussLocalizationOnCells([14,15,16,17,18,19],[0.,0.,1.,0.,1.,1.],[0.4,0.4,0.14,0.16],[0.22,0.78])
10518         self.assertEqual(46,f.getNumberOfTuplesExpected())
10519         vals=DataArrayDouble.New(46*3,1) ; vals.iota(7.7) ; vals.rearrange(3)
10520         f.setArray(vals)
10521         f.checkCoherency()
10522         #f.getLocalizationOfDiscr()
10523         self.assertRaises(InterpKernelException,f.getGaussLocalizationIdOfOneType,NORM_QUAD8) #throw because several loc
10524         self.assertEqual([1,2],f.getGaussLocalizationIdsOfOneType(NORM_QUAD8))
10525         self.assertEqual([0,0,1,1,2,1,2,2,2,3,3,3,3,3,4,4,4,4,4,4],f.getDiscretization().getArrayOfDiscIds().getValues())
10526         fc=f[[1,2,3,8]]
10527         fc.checkCoherency()
10528         self.assertTrue(DataArrayDouble([13.7,14.7,15.7,16.7,17.7,18.7,19.7,20.7,21.7,22.7,23.7,24.7,25.7,26.7,27.7,28.7,29.7,30.7,31.7,32.7,33.7,34.7,35.7,36.7,82.7,83.7,84.7,85.7,86.7,87.7,88.7,89.7,90.7,91.7,92.7,93.7],12,3).isEqual(fc.getArray(),1e-10))
10529         fc.renumberCells([3,2,0,1])
10530         self.assertTrue(DataArrayDouble([28.7, 29.7, 30.7, 31.7, 32.7, 33.7, 34.7, 35.7, 36.7, 82.7, 83.7, 84.7, 85.7, 86.7, 87.7, 88.7, 89.7, 90.7, 91.7, 92.7, 93.7, 19.7, 20.7, 21.7, 22.7, 23.7, 24.7, 25.7, 26.7, 27.7, 13.7, 14.7, 15.7, 16.7, 17.7, 18.7],12,3).isEqual(fc.getArray(),1e-10))
10531         fc.getArray()
10532         pass
10533
10534     def testSwigRotate(self):
10535         d=DataArrayDouble([1.,2.,3.,4.,6.,5.],2,3)
10536         MEDCouplingPointSet.Rotate3DAlg([0.,0.,0.],[0.,1.,0.],1.5707963267948966,d)
10537         self.assertTrue(d.isEqual(DataArrayDouble([3.,2.,-1.,5.,6.,-4.],2,3),1e-12))
10538         d=DataArrayDouble([1.,2.,3.,4.,6.,5.],3,2)
10539         MEDCouplingPointSet.Rotate2DAlg([0.,0.],1.5707963267948966,d)
10540         self.assertTrue(d.isEqual(DataArrayDouble([-2.,1.,-4.,3.,-5.,6.],3,2),1e-12))
10541         pass
10542
10543     def testSwigCMeshProtection(self):
10544         cm=MEDCouplingCMesh()
10545         self.assertRaises(InterpKernelException,cm.setCoordsAt,0,DataArrayDouble([4.,4.5,6.,7.],2,2))
10546         self.assertRaises(InterpKernelException,cm.setCoords,DataArrayDouble([4.,4.5,6.,7.],2,2))
10547         pass
10548
10549     def testSwigCellsInBoundingBox1(self):
10550         m3D=MEDCouplingDataForTest.build3DExtrudedUMesh_1()[0]
10551         self.assertTrue(m3D.getCellsInBoundingBox([(0,3),(0,3),(0,1)],-1e-12).isEqual(DataArrayInt([0,1,2,3,4,5])))
10552         self.assertRaises(InterpKernelException,m3D.getCellsInBoundingBox,[(0,3,0),(3,0,1)],-1e-12)
10553         pass
10554
10555     def testDAICheckMonotonic1(self):
10556         data1=[-1,0,2,2,4,5]
10557         data2=[6,2,0,-8,-9,-56]
10558         data3=[-1,0,3,2,4,6]
10559         data4=[7,5,2,3,0,-6]
10560         d=DataArrayInt.New(data1);
10561         self.assertTrue(d.isMonotonic(True));
10562         self.assertTrue(not d.isMonotonic(False));
10563         d.checkMonotonic(True);
10564         self.assertRaises(InterpKernelException,d.checkMonotonic,False)
10565         d=DataArrayInt.New(data2);
10566         self.assertTrue(d.isMonotonic(False));
10567         self.assertTrue(not d.isMonotonic(True));
10568         d.checkMonotonic(False);
10569         self.assertRaises(InterpKernelException,d.checkMonotonic,True)
10570         d=DataArrayInt.New(data3);
10571         self.assertTrue(not d.isMonotonic(False));
10572         self.assertTrue(not d.isMonotonic(True));
10573         self.assertRaises(InterpKernelException,d.checkMonotonic,True)
10574         self.assertRaises(InterpKernelException,d.checkMonotonic,False)
10575         d=DataArrayInt.New(data4);
10576         self.assertTrue(not d.isMonotonic(False));
10577         self.assertTrue(not d.isMonotonic(True));
10578         self.assertRaises(InterpKernelException,d.checkMonotonic,True)
10579         self.assertRaises(InterpKernelException,d.checkMonotonic,False)
10580         d=DataArrayInt.New(0,1)
10581         self.assertTrue(d.isMonotonic(True));
10582         self.assertTrue(d.isMonotonic(False));
10583         d.checkMonotonic(True);
10584         d.checkMonotonic(False);
10585         d=DataArrayInt.New(data4,3,2);#throw because nbComp!=1
10586         self.assertRaises(InterpKernelException,d.isMonotonic,True)
10587         self.assertRaises(InterpKernelException,d.isMonotonic,False)
10588         self.assertRaises(InterpKernelException,d.checkMonotonic,True)
10589         self.assertRaises(InterpKernelException,d.checkMonotonic,False)
10590         pass
10591
10592     def testSwigDASetItemOnEmpty1(self):
10593         d=DataArrayInt(0,1)
10594         isThrow=False
10595         try:
10596             d[0:1000:2]=4
10597         except InterpKernelException as e:
10598             isThrow=True
10599             pass
10600         self.assertTrue(isThrow)
10601         d[:]=4
10602         d[::2]=5
10603         #
10604         d=DataArrayDouble(0,1)
10605         isThrow=False
10606         try:
10607             d[0:1000:2]=4
10608         except InterpKernelException as e:
10609             isThrow=True
10610             pass
10611         self.assertTrue(isThrow)
10612         d[:]=4
10613         d[::2]=5
10614         d=DataArrayInt([],0,1)
10615         d2=DataArrayInt(0)
10616         self.assertTrue(d2.isEqual(d))
10617         d=DataArrayDouble([],0,1)
10618         d2=DataArrayDouble(0)
10619         self.assertTrue(d2.isEqual(d,1e-12))
10620         pass
10621
10622     def testSwigDAITransformWithIndArr1(self):
10623         arr=DataArrayInt([0,4,5,1])
10624         d=DataArrayInt([7,8,9,10])
10625         self.assertRaises(InterpKernelException,arr.transformWithIndArr,d)
10626         pass
10627
10628     def testIntersect2DMeshesTmp6(self):
10629         # coordinates
10630         coords=DataArrayDouble.New([2.7554552980815448e-15,45,-45,5.5109105961630896e-15,-31.819805153394636,31.81980515339464,2.8779199779962799e-15,47,2.8166876380389124e-15,46,-47,5.7558399559925599e-15,-33.234018715767732,33.234018715767739,-46,5.6333752760778247e-15],8,2);
10631         # connectivity
10632         conn=DataArrayInt.New([8,0,3,5,1,4,6,7,2])
10633         connI=DataArrayInt.New([0,9]);
10634         m1=MEDCouplingUMesh.New("Fixe",2);
10635         m1.setCoords(coords);
10636         m1.setConnectivity(conn,connI,True);
10637         #
10638         coords=DataArrayDouble.New([-7.3800475508445391,41.854329503018846,-3.7041190667754655,42.338274668899189,-3.7041190667754655,45.338274668899189,-7.3800475508445382,44.854329503018839,-5.5473631693521845,42.136406608386956,-3.7041190667754655,43.838274668899189,-5.5420833088100014,45.09630208595901,-7.3800475508445382,43.354329503018839,-3.7041190667754651,52.338274668899189,-7.3800475508445382,51.854329503018839,-3.7041190667754655,48.838274668899189,-5.5420833088100014,52.09630208595901,-7.3800475508445382,48.354329503018839],13,2);
10639         # connectivity
10640         conn=DataArrayInt.New([8,0,1,2,3,4,5,6,7,8,3,2,8,9,6,10,11,12]);
10641         connI=DataArrayInt.New([0,9,18]);
10642         #
10643         m2=MEDCouplingUMesh.New("Mobile",2);
10644         m2.setCoords(coords);
10645         m2.setConnectivity(conn,connI,True);
10646         #
10647         m3,d1,d2=MEDCouplingUMesh.Intersect2DMeshes(m1,m2,1e-10);
10648         self.assertTrue(d1.isEqual(DataArrayInt([0,0,0,0])));
10649         self.assertTrue(d2.isEqual(DataArrayInt([0,1,-1,-1])));
10650         self.assertEqual(4,m3.getNumberOfCells());
10651         self.assertEqual(4,d1.getNumberOfTuples());
10652         self.assertEqual(4,d2.getNumberOfTuples());
10653         self.assertEqual(43,m3.getNumberOfNodes());
10654         dI,areMerged,newNbOfNodes=m3.mergeNodes(1e-12)
10655         self.assertEqual(35,m3.getNumberOfNodes());
10656         m3.zipCoords();
10657         self.assertEqual(23,m3.getNumberOfNodes());
10658         #
10659         f=m3.getMeasureField(True);
10660         valuesExpected=DataArrayDouble([1.6603638692585716,5.747555728471923,129.68907101754394,7.4162714498559694])
10661         self.assertTrue(f.getArray().isEqual(valuesExpected,1e-12))
10662         pass
10663
10664     def testDAPushBack(self):
10665         d=DataArrayDouble(0,1)
10666         for i in xrange(8):
10667             d.pushBackSilent(i)
10668             pass
10669         self.assertEqual(d.getNumberOfTuples(),8)
10670         self.assertEqual(d.getNbOfElemAllocated(),8)
10671         d.pushBackSilent(4.44)
10672         self.assertEqual(d.getNumberOfTuples(),9)
10673         self.assertEqual(d.getNbOfElemAllocated(),16)
10674         self.assertTrue(d.isEqual(DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.,4.44]),1e-12))
10675         e=d.deepCpy()
10676         self.assertEqual(e.getNumberOfTuples(),9)
10677         self.assertEqual(e.getNbOfElemAllocated(),9)
10678         self.assertTrue(e.isEqual(DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.,4.44]),1e-12))
10679         self.assertAlmostEqual(d.popBackSilent(),4.44,12)
10680         self.assertEqual(d.getNumberOfTuples(),8)
10681         self.assertEqual(d.getNbOfElemAllocated(),16)
10682         self.assertTrue(d.isEqual(DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.]),1e-12))
10683         f=DataArrayDouble()
10684         f.reserve(1000)
10685         f.pushBackSilent(4.)
10686         self.assertTrue(f.isEqual(DataArrayDouble([4.]),1e-12))
10687         self.assertEqual(f.getNumberOfTuples(),1)
10688         self.assertEqual(f.getNbOfElemAllocated(),1000)
10689         ff=f[:]
10690         self.assertTrue(ff.isEqual(DataArrayDouble([4.]),1e-12))
10691         self.assertEqual(ff.getNumberOfTuples(),1)
10692         self.assertEqual(ff.getNbOfElemAllocated(),1)
10693         d=DataArrayDouble()
10694         d.pushBackSilent(4.44)
10695         d.pushBackSilent(5.55)
10696         d.pushBackSilent(6.66)
10697         self.assertTrue(d.isEqual(DataArrayDouble([4.44,5.55,6.66]),1e-12))
10698         #
10699         d=DataArrayInt(0,1)
10700         for i in xrange(8):
10701             d.pushBackSilent(i)
10702             pass
10703         self.assertEqual(d.getNumberOfTuples(),8)
10704         self.assertEqual(d.getNbOfElemAllocated(),8)
10705         d.pushBackSilent(444)
10706         self.assertEqual(d.getNumberOfTuples(),9)
10707         self.assertEqual(d.getNbOfElemAllocated(),16)
10708         self.assertTrue(d.isEqual(DataArrayInt([0,1,2,3,4,5,6,7,444])))
10709         e=d.deepCpy()
10710         self.assertEqual(e.getNumberOfTuples(),9)
10711         self.assertEqual(e.getNbOfElemAllocated(),9)
10712         self.assertTrue(e.isEqual(DataArrayInt([0,1,2,3,4,5,6,7,444])))
10713         self.assertEqual(d.popBackSilent(),444)
10714         self.assertEqual(d.getNumberOfTuples(),8)
10715         self.assertEqual(d.getNbOfElemAllocated(),16)
10716         self.assertTrue(d.isEqual(DataArrayInt([0,1,2,3,4,5,6,7])))
10717         f=DataArrayInt()
10718         f.reserve(1000)
10719         f.pushBackSilent(4)
10720         self.assertTrue(f.isEqual(DataArrayInt([4])))
10721         self.assertEqual(f.getNumberOfTuples(),1)
10722         self.assertEqual(f.getNbOfElemAllocated(),1000)
10723         ff=f[:]
10724         self.assertTrue(ff.isEqual(DataArrayInt([4])))
10725         self.assertEqual(ff.getNumberOfTuples(),1)
10726         self.assertEqual(ff.getNbOfElemAllocated(),1)
10727         d=DataArrayInt()
10728         d.pushBackSilent(444)
10729         d.pushBackSilent(555)
10730         d.pushBackSilent(666)
10731         self.assertTrue(d.isEqual(DataArrayInt([444,555,666])))
10732         #
10733         d=DataArrayInt()
10734         d.alloc(10,1)
10735         d.setInfoOnComponent(0,"ABC")
10736         d.setName("dEf")
10737         d.iota(7)
10738         e=DataArrayInt([7,8,9,10,11,12,13,14,15,16]) ; e.copyStringInfoFrom(d) ; self.assertTrue(d.isEqual(e))
10739         self.assertEqual(10,d.getNbOfElemAllocated())
10740         d.pushBackSilent(55)
10741         e=DataArrayInt([7,8,9,10,11,12,13,14,15,16,55]) ; e.copyStringInfoFrom(d) ; self.assertTrue(d.isEqual(e))
10742         self.assertEqual(20,d.getNbOfElemAllocated())
10743         d.reserve(4)
10744         e=DataArrayInt([7,8,9,10]) ; e.copyStringInfoFrom(d) ; self.assertTrue(d.isEqual(e))
10745         self.assertEqual(4,d.getNbOfElemAllocated())
10746         d.pushBackSilent(5)
10747         e=DataArrayInt([7,8,9,10,5]) ; e.copyStringInfoFrom(d) ; self.assertTrue(d.isEqual(e))
10748         self.assertEqual(8,d.getNbOfElemAllocated())
10749         self.assertEqual(5,d.popBackSilent())
10750         e=DataArrayInt([7,8,9,10]) ; e.copyStringInfoFrom(d) ; self.assertTrue(d.isEqual(e))
10751         self.assertEqual(8,d.getNbOfElemAllocated())
10752         self.assertRaises(OverflowError,d.reserve,-1)
10753         e=DataArrayInt([7,8,9,10]) ; e.copyStringInfoFrom(d) ; self.assertTrue(d.isEqual(e))
10754         self.assertEqual(8,d.getNbOfElemAllocated())
10755         d.reserve(0)
10756         e=DataArrayInt([]) ; e.setInfoOnComponent(0,"ABC") ; e.setName("dEf") ; self.assertTrue(d.isEqual(e))
10757         self.assertEqual(0,d.getNbOfElemAllocated())
10758         #
10759         d=DataArrayDouble()
10760         d.alloc(10,1)
10761         d.setInfoOnComponent(0,"ABC")
10762         d.setName("dEf")
10763         d.iota(7)
10764         e=DataArrayDouble([7,8,9,10,11,12,13,14,15,16]) ; e.copyStringInfoFrom(d) ; self.assertTrue(d.isEqual(e,1e-14))
10765         self.assertEqual(10,d.getNbOfElemAllocated())
10766         d.pushBackSilent(55)
10767         e=DataArrayDouble([7,8,9,10,11,12,13,14,15,16,55]) ; e.copyStringInfoFrom(d) ; self.assertTrue(d.isEqual(e,1e-14))
10768         self.assertEqual(20,d.getNbOfElemAllocated())
10769         d.reserve(4)
10770         e=DataArrayDouble([7,8,9,10]) ; e.copyStringInfoFrom(d) ; self.assertTrue(d.isEqual(e,1e-14))
10771         self.assertEqual(4,d.getNbOfElemAllocated())
10772         d.pushBackSilent(5)
10773         e=DataArrayDouble([7,8,9,10,5]) ; e.copyStringInfoFrom(d) ; self.assertTrue(d.isEqual(e,1e-14))
10774         self.assertEqual(8,d.getNbOfElemAllocated())
10775         self.assertEqual(5.,d.popBackSilent())
10776         e=DataArrayDouble([7,8,9,10]) ; e.copyStringInfoFrom(d) ; self.assertTrue(d.isEqual(e,1e-14))
10777         self.assertEqual(8,d.getNbOfElemAllocated())
10778         self.assertRaises(OverflowError,d.reserve,-1)
10779         e=DataArrayDouble([7,8,9,10]) ; e.copyStringInfoFrom(d) ; self.assertTrue(d.isEqual(e,1e-14))
10780         self.assertEqual(8,d.getNbOfElemAllocated())
10781         d.reserve(0)
10782         e=DataArrayDouble([]) ; e.setInfoOnComponent(0,"ABC") ; e.setName("dEf") ; self.assertTrue(d.isEqual(e,1e-14))
10783         self.assertEqual(0,d.getNbOfElemAllocated())
10784         pass
10785
10786     def testDAIBuildSubstractionOptimized1(self):
10787         da1=DataArrayInt.New([1,3,5,6,7,9,13])
10788         da2=DataArrayInt.New([3,5,9])
10789         da3=DataArrayInt.New([1,3,5])
10790         da4=DataArrayInt.New([1,3,5,6,7,9,13])
10791         #
10792         a=da1.buildSubstractionOptimized(da2);
10793         self.assertTrue(a.isEqual(DataArrayInt([1,6,7,13])));
10794         #
10795         a=da1.buildSubstractionOptimized(da3);
10796         self.assertTrue(a.isEqual(DataArrayInt([6,7,9,13])));
10797         #
10798         a=da1.buildSubstractionOptimized(da4);
10799         self.assertTrue(a.isEqual(DataArrayInt([])));
10800         pass
10801
10802     def testDAIIsStrictlyMonotonic1(self):
10803         da1=DataArrayInt.New([1,3,5,6,7,9,13])
10804         self.assertTrue(da1.isStrictlyMonotonic(True));
10805         da1.checkStrictlyMonotonic(True);
10806         self.assertTrue(da1.isMonotonic(True));
10807         da1.checkMonotonic(True);
10808         self.assertTrue(not da1.isStrictlyMonotonic(False));
10809         self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,False)
10810         self.assertTrue(not da1.isMonotonic(False));
10811         self.assertRaises(InterpKernelException,da1.checkMonotonic,False)
10812         #
10813         da1=DataArrayInt.New([1,3,5,6,6,9,13])
10814         self.assertTrue(not da1.isStrictlyMonotonic(True));
10815         self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,True)
10816         self.assertTrue(da1.isMonotonic(True));
10817         da1.checkMonotonic(True);
10818         self.assertTrue(not da1.isStrictlyMonotonic(False));
10819         self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,False)
10820         self.assertTrue(not da1.isMonotonic(False));
10821         self.assertRaises(InterpKernelException,da1.checkMonotonic,False)
10822         #
10823         da1=DataArrayInt.New([1,3,5,6,5,9,13])
10824         self.assertTrue(not da1.isStrictlyMonotonic(True));
10825         self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,True)
10826         self.assertTrue(not da1.isMonotonic(True));
10827         self.assertRaises(InterpKernelException,da1.checkMonotonic,True)
10828         self.assertTrue(not da1.isStrictlyMonotonic(False));
10829         self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,False)
10830         self.assertTrue(not da1.isMonotonic(False));
10831         self.assertRaises(InterpKernelException,da1.checkMonotonic,False)
10832         #
10833         da1=DataArrayInt.New([13,9,7,6,5,3,1])
10834         self.assertTrue(not da1.isStrictlyMonotonic(True));
10835         self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,True)
10836         self.assertTrue(not da1.isMonotonic(True));
10837         self.assertRaises(InterpKernelException,da1.checkMonotonic,True)
10838         self.assertTrue(da1.isStrictlyMonotonic(False));
10839         da1.checkStrictlyMonotonic(False);
10840         self.assertTrue(da1.isMonotonic(False));
10841         da1.checkMonotonic(False);
10842         #
10843         da1=DataArrayInt.New([13,9,6,6,5,3,1])
10844         self.assertTrue(not da1.isStrictlyMonotonic(True));
10845         self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,True)
10846         self.assertTrue(not da1.isMonotonic(True));
10847         self.assertRaises(InterpKernelException,da1.checkMonotonic,True)
10848         self.assertTrue(not da1.isStrictlyMonotonic(False));
10849         self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,False)
10850         self.assertTrue(da1.isMonotonic(False));
10851         da1.checkMonotonic(False);
10852         #
10853         da1=DataArrayInt.New([13,9,5,6,5,3,1])
10854         self.assertTrue(not da1.isStrictlyMonotonic(True));
10855         self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,True)
10856         self.assertTrue(not da1.isMonotonic(True));
10857         self.assertRaises(InterpKernelException,da1.checkMonotonic,True)
10858         self.assertTrue(not da1.isStrictlyMonotonic(False));
10859         self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,False)
10860         self.assertTrue(not da1.isMonotonic(False));
10861         self.assertRaises(InterpKernelException,da1.checkMonotonic,False)
10862         #
10863         da1=DataArrayInt.New([])
10864         self.assertTrue(da1.isStrictlyMonotonic(True));
10865         da1.checkStrictlyMonotonic(True);
10866         self.assertTrue(da1.isMonotonic(True));
10867         da1.checkMonotonic(True);
10868         self.assertTrue(da1.isStrictlyMonotonic(False));
10869         da1.checkStrictlyMonotonic(False);
10870         self.assertTrue(da1.isMonotonic(False));
10871         da1.checkMonotonic(False);
10872         #
10873         da1=DataArrayInt.New([13])
10874         self.assertTrue(da1.isStrictlyMonotonic(True));
10875         da1.checkStrictlyMonotonic(True);
10876         self.assertTrue(da1.isMonotonic(True));
10877         da1.checkMonotonic(True);
10878         self.assertTrue(da1.isStrictlyMonotonic(False));
10879         da1.checkStrictlyMonotonic(False);
10880         self.assertTrue(da1.isMonotonic(False));
10881         da1.checkMonotonic(False);
10882         pass
10883
10884     def testFindAndCorrectBadOriented3DCells1(self):
10885         nbOfDisc=20
10886         vects=([0,0,-1],[0.3,0.7,0.2],[-0.3,0.7,0.2],[-0.3,-0.7,0.2])
10887         #
10888         m0=MEDCouplingUMesh("m",3) ; m0.allocateCells(0); m0.insertNextCell(NORM_TETRA4,[0,1,2,3]); #Well oriented
10889         m1=MEDCouplingUMesh("m",3) ; m1.allocateCells(0); m1.insertNextCell(NORM_PYRA5,[0,1,2,3,4]); #Well oriented
10890         m2=MEDCouplingUMesh("m",3) ; m2.allocateCells(0); m2.insertNextCell(NORM_PENTA6,[0,1,2,3,4,5]); #Well oriented 
10891         m3=MEDCouplingUMesh("m",3) ; m3.allocateCells(0); m3.insertNextCell(NORM_HEXA8,[0,1,2,3,4,5,6,7]); #Well oriented
10892         m4=MEDCouplingUMesh("m",3) ; m4.allocateCells(0)
10893         self.assertRaises(InterpKernelException,m4.insertNextCell,NORM_HEXGP12,[0,1,2,3,4,5,6,7,8,9,10,11,12]);
10894         m4.insertNextCell(NORM_HEXGP12,[0,1,2,3,4,5,6,7,8,9,10,11]); #Well oriented
10895         c0=DataArrayDouble([0.,0.,0.,0.,1.,0.,1.,0.,0.,0.,0.,1.],4,3) ; m0.setCoords(c0)
10896         c1=DataArrayDouble([0.,0.,0.,0.,1.,0.,1.,1.,0.,1.,0.,0.,0.,0.,1.],5,3) ; m1.setCoords(c1)
10897         c2=DataArrayDouble([0.,0.,0.,0.,1.,0.,1.,0.,0., 0.,0.,1.,0.,1.,1.,1.,0.,1.],6,3) ; m2.setCoords(c2)
10898         c3=DataArrayDouble([0.,0.,0.,0.,1.,0.,1.,1.,0.,1.,0.,0.,0.,0.,1.,0.,1.,1.,1.,1.,1.,1.,0.,1.],8,3) ; m3.setCoords(c3)
10899         c4=DataArrayDouble([0.,0.,0.,0.,1.,0.,1.,1.,0.,1.,0.,0.,0.8,0.,0.,0.45,0.,0.,   0.,0.,1.,0.,1.,1.,1.,1.,1.,1.,0.,1.,0.8,0.,1.,0.45,0.,1.],12,3) ; m4.setCoords(c4)
10900         m=MEDCouplingMesh.MergeMeshes([m0,m1,m2,m3,m4])
10901         expected1=DataArrayDouble([0.16666666666666666,0.3333333333333333,0.5,1.,1.])
10902         for v in vects:
10903             for i in xrange(nbOfDisc):
10904                 mm=m.deepCpy()
10905                 mm.rotate([0.,0.,0.],[0.3,0.7,0.2],float(i)/float(nbOfDisc)*2*pi)
10906                 mm2=mm.deepCpy()
10907                 self.assertTrue(mm.getMeasureField(False).getArray().isEqual(expected1,1e-14))
10908                 self.assertTrue(mm.findAndCorrectBadOriented3DCells().empty())
10909                 self.assertTrue(mm.isEqual(mm2,1e-14))
10910                 self.assertTrue(mm.getMeasureField(False).getArray().isEqual(expected1,1e-14))
10911                 mm.convertAllToPoly()
10912                 self.assertTrue(mm.getMeasureField(False).getArray().isEqual(expected1,1e-14))
10913                 pass
10914             pass
10915         #
10916         mOK=m.deepCpy()
10917         m0=MEDCouplingUMesh("m",3) ; m0.allocateCells(0); m0.insertNextCell(NORM_TETRA4,[0,2,1,3]); #Not well oriented
10918         m1=MEDCouplingUMesh("m",3) ; m1.allocateCells(0); m1.insertNextCell(NORM_PYRA5,[0,1,2,3,4]); #Well oriented 
10919         m2=MEDCouplingUMesh("m",3) ; m2.allocateCells(0); m2.insertNextCell(NORM_PENTA6,[0,1,2,3,4,5]); #Well oriented 
10920         m3=MEDCouplingUMesh("m",3) ; m3.allocateCells(0); m3.insertNextCell(NORM_HEXA8,[0,3,2,1,4,7,6,5]); #Not well oriented
10921         m4=MEDCouplingUMesh("m",3) ; m4.allocateCells(0); m4.insertNextCell(NORM_HEXGP12,[0,5,4,3,2,1,6,11,10,9,8,7]); #Not well oriented
10922         m0.setCoords(c0) ; m1.setCoords(c1) ; m2.setCoords(c2) ; m3.setCoords(c3) ; m4.setCoords(c4)
10923         m=MEDCouplingMesh.MergeMeshes([m0,m1,m2,m3,m4])
10924         expected2=DataArrayDouble([-0.16666666666666666,0.3333333333333333,0.5,-1.,-1.])
10925         for v in vects:
10926             for i in xrange(nbOfDisc):
10927                 mm=m.deepCpy()
10928                 mm.rotate([0.,0.,0.],[0.3,0.7,0.2],float(i)/float(nbOfDisc)*2*pi)
10929                 mm2=mm.deepCpy() ; mm3=mm.deepCpy() ; mm3.convertAllToPoly()
10930                 self.assertTrue(mm3.getMeasureField(False).getArray().isEqual(expected2,1e-14))
10931                 self.assertTrue(mm.getMeasureField(False).getArray().isEqual(expected2,1e-14))
10932                 self.assertTrue(mm.findAndCorrectBadOriented3DCells().isEqual(DataArrayInt([0,3,4])))
10933                 mOK.setCoords(mm.getCoords())
10934                 self.assertTrue(mm.isEqual(mOK,1e-14))
10935                 self.assertTrue(mm.getMeasureField(False).getArray().isEqual(expected1,1e-14))
10936                 mmm=mm.deepCpy()
10937                 self.assertTrue(mmm.findAndCorrectBadOriented3DCells().empty())
10938                 mm.convertAllToPoly()
10939                 self.assertTrue(mm.getMeasureField(False).getArray().isEqual(expected1,1e-14))
10940                 pass
10941             pass
10942         #
10943         m0=MEDCouplingUMesh("m",3) ; m0.allocateCells(0); m0.insertNextCell(NORM_TETRA4,[0,1,2,3]); #Well oriented
10944         m1=MEDCouplingUMesh("m",3) ; m1.allocateCells(0); m1.insertNextCell(NORM_PYRA5,[0,3,2,1,4]); #Not well oriented 
10945         m2=MEDCouplingUMesh("m",3) ; m2.allocateCells(0); m2.insertNextCell(NORM_PENTA6,[0,2,1,3,5,4]); #Not well oriented 
10946         m3=MEDCouplingUMesh("m",3) ; m3.allocateCells(0); m3.insertNextCell(NORM_HEXA8,[0,1,2,3,4,5,6,7]); #Well oriented
10947         m4=MEDCouplingUMesh("m",3) ; m4.allocateCells(0); m4.insertNextCell(NORM_HEXGP12,range(12)); #Well oriented
10948         m0.setCoords(c0) ; m1.setCoords(c1) ; m2.setCoords(c2) ; m3.setCoords(c3) ; m4.setCoords(c4)
10949         m=MEDCouplingMesh.MergeMeshes([m0,m1,m2,m3,m4])
10950         expected3=DataArrayDouble([0.16666666666666666,-0.3333333333333333,-0.5,1.,1.])
10951         for v in vects:
10952             for i in xrange(nbOfDisc):
10953                 mm=m.deepCpy()
10954                 mm.rotate([0.,0.,0.],[0.3,0.7,0.2],float(i)/float(nbOfDisc)*2*pi)
10955                 mm2=mm.deepCpy() ; mm3=mm.deepCpy() ; mm3.convertAllToPoly()
10956                 self.assertTrue(mm3.getMeasureField(False).getArray().isEqual(expected3,1e-14))
10957                 self.assertTrue(mm.getMeasureField(False).getArray().isEqual(expected3,1e-14))
10958                 self.assertTrue(mm.findAndCorrectBadOriented3DCells().isEqual(DataArrayInt([1,2])))
10959                 mOK.setCoords(mm.getCoords())
10960                 self.assertTrue(mm.isEqual(mOK,1e-14))
10961                 self.assertTrue(mm.getMeasureField(False).getArray().isEqual(expected1,1e-14))
10962                 mmm=mm.deepCpy()
10963                 self.assertTrue(mmm.findAndCorrectBadOriented3DCells().empty())
10964                 mm.convertAllToPoly()
10965                 self.assertTrue(mm.getMeasureField(False).getArray().isEqual(expected1,1e-14))
10966                 pass
10967             pass
10968         pass
10969
10970     def testSwig2CellOrientation1(self):
10971         coords=DataArrayDouble([-0.21606,-0.10803,0.29999999999999999,-0.21606,-0.10803,0.37700000000000006,0,-0.10803,0.29999999999999999,0,-0.10803,0.37700000000000006,0,0.10803,0.29999999999999999,0,0.10803,0.37700000000000006,-0.21606,0.10803,0.29999999999999999,-0.21606,0.10803,0.37700000000000006,0,0.03601,0.29999999999999999,0,0.03601,0.37700000000000006,0,-0.03601,0.29999999999999999,0,-0.03601,0.37700000000000006],12,3)
10972         conn=[[0,2,10,8,4,6],[1,3,11,9,5,7],[0,1,3,2],[2,3,11,10],[10,11,9,8],[8,9,5,4],[4,5,7,6],[6,7,1,0]]
10973         for i in xrange(256):
10974             mesh=MEDCouplingUMesh("FluidMesh_1",3);
10975             mesh.allocateCells(0)
10976             conn2=[elt[:] for elt in conn]
10977             code=bin(i)[2:] ; code='0'*(8-len(code))+code
10978             for face,rev in zip(conn2,code):
10979                 if bool(int(rev)):
10980                     face.reverse()
10981                     pass
10982                 pass
10983             conn3=[elt+[-1] for elt in conn2]
10984             conn3=sum(conn3,[])[:-1]
10985             mesh.insertNextCell(NORM_POLYHED,conn3)
10986             mesh.setCoords(coords)
10987             mesh.orientCorrectlyPolyhedrons()
10988             self.assertTrue(mesh.getBarycenterAndOwner().isEqual(DataArrayDouble([-0.10803,0.,0.3385],1,3),1e-12))
10989             pass
10990         pass
10991
10992     def testSwig2CheckConsecutiveCellTypesForMEDFileFrmt1(self):
10993         m1=MEDCouplingUMesh("",2) ; m1.allocateCells(0)
10994         m1.insertNextCell(NORM_QUAD4,[0,1,2,3])
10995         m1.insertNextCell(NORM_TRI3,[0,1,2])
10996         d=DataArrayDouble(4,3) ; d[:]=0.
10997         m1.setCoords(d)
10998         self.assertTrue(m1.checkConsecutiveCellTypes())
10999         self.assertTrue(not m1.checkConsecutiveCellTypesForMEDFileFrmt())
11000         m1.renumberCells([1,0])
11001         self.assertTrue(m1.checkConsecutiveCellTypes())
11002         self.assertTrue(m1.checkConsecutiveCellTypesForMEDFileFrmt())
11003         pass
11004
11005     def testSwig2DAAccumulate1(self):
11006         d=DataArrayInt(10) ; d.iota(0)
11007         self.assertEqual([45],d.accumulate())
11008         self.assertEqual(45,d.accumulate(0))
11009         d=DataArrayInt(30) ; d.iota(0) ; d.rearrange(3)
11010         self.assertEqual([135,145,155],d.accumulate())
11011         self.assertEqual(135,d.accumulate(0))
11012         self.assertEqual(145,d.accumulate(1))
11013         self.assertEqual(155,d.accumulate(2))
11014         d=DataArrayDouble(10) ; d.iota(0.)
11015         self.assertEqual([45.],d.accumulate())
11016         self.assertEqual(45.,d.accumulate(0))
11017         d=DataArrayDouble(30) ; d.iota(0) ; d.rearrange(3)
11018         self.assertEqual([135.,145.,155.],d.accumulate())
11019         self.assertEqual(135.,d.accumulate(0))
11020         self.assertEqual(145.,d.accumulate(1))
11021         self.assertEqual(155.,d.accumulate(2))
11022         pass
11023
11024     def testSwig2UMeshDistanceToMesh1(self):
11025         m=MEDCouplingUMesh("toto",2)
11026         coords=DataArrayDouble([2.3,3.4,5.6,6.5,-4.3,3.2,-9.8,7.6,-5.4],3,3)
11027         m.setCoords(coords)
11028         m.allocateCells(0)
11029         m.insertNextCell(NORM_TRI3,[0,1,2])
11030         a,b=m.distanceToPoint([-0.335,2.27,1.21])
11031         self.assertEqual(0,b)
11032         self.assertAlmostEqual(0.022360988100374124,a,14);
11033         a,b=m.distanceToPoint(DataArrayDouble([-0.335,2.27,1.21],1,3))
11034         self.assertEqual(0,b)
11035         self.assertAlmostEqual(0.022360988100374124,a,14);
11036         a,b=coords.distanceToTuple([-0.335,2.27,1.21])
11037         self.assertAlmostEqual(5.243302871282566,a,14)
11038         self.assertEqual(0,b)
11039         #
11040         m=MEDCouplingUMesh("toto",2)
11041         coords=DataArrayDouble([0.,0.,0., 8.,0.,0., 8.,8.,0., 0.,8.,0.],4,3)
11042         m.setCoords(coords)
11043         m.allocateCells(0)
11044         m.insertNextCell(NORM_QUAD4,[0,1,2,3])
11045         m.checkCoherency2()
11046         self.assertEqual([4,0,1,2,3],m.getNodalConnectivity().getValues())
11047         a,b=m.distanceToPoint([5.,2.,0.1])
11048         self.assertAlmostEqual(0.1,a,14) ; self.assertEqual(0,b)
11049         a,b=m.distanceToPoint([5.,-2.,4.])
11050         self.assertAlmostEqual(sqrt(2*2+4*4),a,14) ; self.assertEqual(0,b)
11051         m.allocateCells(0)
11052         m.insertNextCell(NORM_POLYGON,[0,1,2,3])
11053         m.checkCoherency2()
11054         self.assertEqual([5,0,1,2,3],m.getNodalConnectivity().getValues())
11055         a,b=m.distanceToPoint([11.,3.,4.])
11056         self.assertAlmostEqual(sqrt(3*3+4*4),a,14) ; self.assertEqual(0,b)
11057         a,b=m.distanceToPoint([4.,12.,5.])
11058         self.assertAlmostEqual(sqrt(4*4+5*5),a,14) ; self.assertEqual(0,b)
11059         d=DataArrayDouble([-1.2,3.,2.],1,3)
11060         for elt in d:
11061             a,b=m.distanceToPoint(d)
11062             self.assertAlmostEqual(sqrt(1.2*1.2+2*2),a,14) ; self.assertEqual(0,b)
11063             pass
11064         #
11065         m=MEDCouplingUMesh("toto",1)
11066         coords=DataArrayDouble([0.,0.,4.,0.,0.,4.],3,2) ; m.setCoords(coords)
11067         m.allocateCells(0) ; m.insertNextCell(NORM_SEG2,[0,1]) ; m.insertNextCell(NORM_SEG2,[1,2])
11068         a,b=m.distanceToPoint([-0.1,4.1])
11069         self.assertAlmostEqual(0.14142135623730925,a,14)  # b==1 self.assertEqual(2,c)
11070         a,b=m.distanceToPoint([0.,3.9])
11071         self.assertAlmostEqual(0.07071067811865482,a,14) ; self.assertEqual(1,b) # self.assertEqual(2,c)
11072         pass
11073
11074     def testSwig2NonRegressionPartitionBySpreadZone1(self):
11075         m=MEDCouplingCMesh()
11076         arr=DataArrayDouble(6) ; arr.iota(0.)
11077         m.setCoords(arr,arr,arr)
11078         m=m.buildUnstructured()
11079         mPart=m[50,80,85,87,92,122]
11080         zones=mPart.partitionBySpreadZone()
11081         self.assertEqual(4,len(zones))
11082         self.assertTrue(zones[0].isEqual(DataArrayInt([0])))
11083         self.assertTrue(zones[1].isEqual(DataArrayInt([1,2])))
11084         self.assertTrue(zones[2].isEqual(DataArrayInt([3,4])))
11085         self.assertTrue(zones[3].isEqual(DataArrayInt([5])))
11086         #
11087         n,ni=m.computeNeighborsOfCells()
11088         a,b=MEDCouplingUMesh.ComputeSpreadZoneGraduallyFromSeed(0,n,ni)
11089         self.assertEqual(13,b) ; self.assertEqual(125,len(a)) ; self.assertTrue(a.isIdentity())
11090         a,b=MEDCouplingUMesh.ComputeSpreadZoneGraduallyFromSeed([1],n,ni)
11091         self.assertEqual(12,b) ; self.assertEqual(125,len(a)) ; self.assertTrue(a.isIdentity())
11092         a,b=MEDCouplingUMesh.ComputeSpreadZoneGraduallyFromSeed((2,),n,ni)
11093         self.assertEqual(11,b) ; self.assertEqual(125,len(a)) ; self.assertTrue(a.isIdentity())
11094         a,b=MEDCouplingUMesh.ComputeSpreadZoneGraduallyFromSeed(DataArrayInt([3]),n,ni)
11095         self.assertEqual(12,b) ; self.assertEqual(125,len(a)) ; self.assertTrue(a.isIdentity())
11096         pass
11097
11098     def testSwigUMeshInsertNextCell1(self):
11099         m=MEDCouplingUMesh("toto",2)
11100         #
11101         coords=DataArrayDouble([0.,0.,1.,1.,1.,0.]) ; m.setCoords(coords)
11102         da=DataArrayInt([0,1,2])
11103         m.allocateCells(0)
11104         for i in xrange(5):
11105             m.insertNextCell(NORM_TRI3,da)
11106             pass
11107         self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2])))
11108         self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,8,12,16,20])))
11109         #
11110         da=DataArrayInt([0,1,2,3])
11111         m.allocateCells(0)
11112         for i in xrange(5):
11113             m.insertNextCell(NORM_TRI3,3,da)
11114             pass
11115         self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2])))
11116         self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,8,12,16,20])))
11117         #
11118         da=DataArrayInt([0,1])
11119         m.allocateCells(0)
11120         self.assertRaises(InterpKernelException,m.insertNextCell,NORM_TRI3,3,da)
11121         #
11122         da=DataArrayInt([0,1,2,0,1,3,0,1,4,0,1,5,0,1,6],5,3)
11123         m.allocateCells(0)
11124         for t in da:
11125             m.insertNextCell(NORM_TRI3,t)
11126             pass
11127         self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([3,0,1,2,3,0,1,3,3,0,1,4,3,0,1,5,3,0,1,6])))
11128         self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,8,12,16,20])))
11129         self.assertRaises(InterpKernelException,m.insertNextCell,NORM_TRI3,None)
11130         pass
11131
11132     def testSwigCurveLinearMesh1(self):
11133         m=MEDCouplingCurveLinearMesh("toto")
11134         m.setNodeGridStructure([2,3])
11135         coords=DataArrayDouble([0.,0., 2.,0., 0.,1., 1.9,1.1, 0.3,1.9, 2.2,2.1],6,2)
11136         m.setCoords(coords)
11137         m.checkCoherency()
11138         m0=m.deepCpy()
11139         self.assertTrue(m0.isEqual(m,1e-12))
11140         m.getCoords().setInfoOnComponents(["X [m]","Y [m]"])
11141         self.assertTrue(not m0.isEqual(m,1e-12))
11142         m0=m.deepCpy()
11143         self.assertTrue(m0.isEqual(m,1e-12))
11144         self.assertEqual(m.getNodeGridStructure(),(2,3))
11145         pass
11146
11147     def testSimplexize3(self):
11148         m=MEDCouplingUMesh("toto",3)
11149         m.allocateCells(0)
11150         m.insertNextCell(NORM_TETRA4,[0,1,2,3])
11151         self.assertEqual([NORM_TETRA4],m.getAllGeoTypesSorted())
11152         m.insertNextCell(NORM_HEXA8,[4,5,6,7,8,9,10,11])
11153         self.assertEqual([NORM_TETRA4,NORM_HEXA8],m.getAllGeoTypesSorted())
11154         m.insertNextCell(NORM_HEXA8,[12,13,14,15,16,17,18,19])
11155         self.assertEqual([NORM_TETRA4,NORM_HEXA8],m.getAllGeoTypesSorted())
11156         m.insertNextCell(NORM_TETRA4,[20,21,22,23])
11157         self.assertEqual([NORM_TETRA4,NORM_HEXA8,NORM_TETRA4],m.getAllGeoTypesSorted())
11158         c1=DataArrayDouble([0.,0.,0.,0.,1.,0.,1.,0.,0.,0.,0.,1.],4,3)
11159         c2=DataArrayDouble([0.,0.,0.,0.,1.,0.,1.,1.,0.,1.,0.,0., 0.,0.,1.,0.,1.,1.,1.,1.,1.,1.,0.,1.],8,3) ; c2+=[2.,0.,0.]
11160         c3=c2+[2.,0.,0.]
11161         c4=c1+[6.,0.,0.]
11162         c=DataArrayDouble.Aggregate([c1,c2,c3,c4])
11163         m.setCoords(c)
11164         m.checkCoherency2()
11165         #
11166         m1=m.deepCpy()
11167         d1=m1.simplexize(PLANAR_FACE_5)
11168         m1.checkCoherency2()
11169         vol1=m1.getMeasureField(ON_CELLS).getArray()
11170         self.assertTrue(vol1.isEqual(DataArrayDouble([1./6, 1./6, 1./6,1./6, 1./6, 1./3,1./6, 1./6, 1./6, 1./6, 1./3, 1./6]),1e-12))
11171         self.assertEqual(m1.getNodalConnectivity().getValues(),[14,0,1,2,3,14,4,9,5,6,14,4,8,9,11,14,4,7,11,6,14,9,11,10,6,14,4,9,6,11,14,12,17,13,14,14,12,16,17,19,14,12,15,19,14,14,17,19,18,14,14,12,17,14,19,14,20,21,22,23])
11172         self.assertEqual(m1.getNodalConnectivityIndex().getValues(),[0,5,10,15,20,25,30,35,40,45,50,55,60])
11173         self.assertTrue(d1.isEqual(DataArrayInt([0,1,1,1,1,1,2,2,2,2,2,3])))
11174         #
11175         m2=m.deepCpy()
11176         d2=m2.simplexize(PLANAR_FACE_6)
11177         m2.checkCoherency2()
11178         vol2=m2.getMeasureField(ON_CELLS).getArray()
11179         self.assertTrue(vol2.isEqual(DataArrayDouble([1./6, 1./6, 1./6,1./6, 1./6, 1./6,1./6,1./6, 1./6, 1./6, 1./6, 1./6,1./6,1./6]),1e-12))
11180         self.assertEqual(m2.getNodalConnectivity().getValues(),[14,0,1,2,3,14,4,9,5,10,14,4,5,6,10,14,4,8,9,10,14,4,11,8,10,14,4,6,7,10,14,4,7,11,10,14,12,17,13,18,14,12,13,14,18,14,12,16,17,18,14,12,19,16,18,14,12,14,15,18,14,12,15,19,18,14,20,21,22,23])
11181         self.assertEqual(m2.getNodalConnectivityIndex().getValues(),[0,5,10,15,20,25,30,35,40,45,50,55,60,65,70])
11182         self.assertTrue(d2.isEqual(DataArrayInt([0,1,1,1,1,1,1,2,2,2,2,2,2,3])))
11183         pass
11184
11185     def testSwig2CurveLinearMesh2(self):
11186         c=MEDCouplingCMesh()
11187         #2D
11188         arr1=DataArrayDouble([0,1,3,7])
11189         arr2=DataArrayDouble([0,1,1.5])
11190         c.setCoords(arr1,arr2)
11191         u=c.buildUnstructured()
11192         coo=u.getCoords()
11193         cl=MEDCouplingCurveLinearMesh()
11194         cl.setCoords(coo)
11195         cl.setNodeGridStructure([4,3])
11196         cl.checkCoherency2()
11197         li1=[1.,2.,4.,0.5,1.,2.]
11198         self.assertTrue(cl.getMeasureField(False).getArray().isEqual(DataArrayDouble(li1),1e-14))
11199         self.assertTrue(u.getMeasureField(False).getArray().isEqual(DataArrayDouble(li1),1e-14))
11200         li1_1=[0.5,0.5,2.,0.5,5.,0.5,0.5,1.25,2.,1.25,5.,1.25]
11201         self.assertTrue(cl.getBarycenterAndOwner().isEqual(DataArrayDouble(li1_1,6,2),1e-14))
11202         self.assertTrue(u.getBarycenterAndOwner().isEqual(DataArrayDouble(li1_1,6,2),1e-14))
11203         #3D
11204         c.setCoords(arr1,arr2,arr2)
11205         u=c.buildUnstructured()
11206         coo=u.getCoords()
11207         cl=MEDCouplingCurveLinearMesh()
11208         cl.setCoords(coo)
11209         cl.setNodeGridStructure([4,3,3])
11210         cl.checkCoherency2()
11211         li2=[1.,2.,4.,0.5, 1.,2.,0.5,1.,2.,0.25,0.5,1.]
11212         li2_1=[0.5,0.5,0.5,2.,0.5,0.5,5.,0.5,0.5,0.5,1.25,0.5,2.,1.25,0.5,5.,1.25,0.5,0.5,0.5,1.25,2.,0.5,1.25,5.,0.5,1.25,0.5,1.25,1.25,2.,1.25,1.25,5.,1.25,1.25]
11213         self.assertTrue(cl.getMeasureField(False).getArray().isEqual(DataArrayDouble(li2),1e-14))
11214         self.assertTrue(u.getMeasureField(False).getArray().isEqual(DataArrayDouble(li2),1e-14))
11215         self.assertTrue(cl.getBarycenterAndOwner().isEqual(DataArrayDouble(li2_1,12,3),1e-14))
11216         self.assertTrue(u.getBarycenterAndOwner().isEqual(DataArrayDouble(li2_1,12,3),1e-14))
11217         #1D spaceDim 1
11218         coo=DataArrayDouble(5) ; coo.iota(0.)
11219         coo=coo*coo
11220         cl.setCoords(coo)
11221         cl.setNodeGridStructure([5])
11222         cl.checkCoherency2()
11223         li3=[1.,3.,5.,7.]
11224         li3_1=[0.5,2.5,6.5,12.5]
11225         self.assertTrue(cl.getMeasureField(False).getArray().isEqual(DataArrayDouble(li3),1e-14))
11226         self.assertTrue(cl.buildUnstructured().getMeasureField(False).getArray().isEqual(DataArrayDouble(li3),1e-14))
11227         self.assertTrue(cl.getBarycenterAndOwner().isEqual(DataArrayDouble(li3_1),1e-14))
11228         self.assertTrue(cl.buildUnstructured().getBarycenterAndOwner().isEqual(DataArrayDouble(li3_1),1e-14))
11229         #1D spaceDim 2
11230         coo=DataArrayDouble.Meld(coo,coo)
11231         cl.setCoords(coo)
11232         cl.checkCoherency2()
11233         li4=[sqrt(2.)*elt for elt in [1.,3.,5.,7.]]
11234         li4_1=[0.5,0.5,2.5,2.5,6.5,6.5,12.5,12.5]
11235         self.assertTrue(cl.getMeasureField(False).getArray().isEqual(DataArrayDouble(li4),1e-14))
11236         self.assertTrue(cl.buildUnstructured().getMeasureField(False).getArray().isEqual(DataArrayDouble(li4),1e-14))
11237         self.assertTrue(cl.getBarycenterAndOwner().isEqual(DataArrayDouble(li4_1,4,2),1e-14))
11238         self.assertTrue(cl.buildUnstructured().getBarycenterAndOwner().isEqual(DataArrayDouble(li4_1,4,2),1e-14))
11239         pass
11240
11241     def testSwig2CurveLinearMeshNonRegression1(self):
11242         coords=DataArrayDouble([0.0, 0.0, 0.10000000149011612, 0.6000000238418579, 0.10000000149011612, 0.30000001192092896, 1.100000023841858, 0.10000000149011612, 0.20000000298023224, 0.10000000149011612, 0.6000000238418579, 0.20000000298023224, 0.699999988079071, 0.6000000238418579, 0.10000000149011612, 1.2000000476837158, 0.6000000238418579, 0.30000001192092896, 0.10000000149011612, 1.100000023841858, 0.30000001192092896, 0.5, 1.100000023841858, 0.20000000298023224, 1.0, 1.2000000476837158, 0.10000000149011612, 0.0, 0.10000000149011612, 0.5, 0.5, 0.10000000149011612, 0.6000000238418579, 1.2000000476837158, 0.10000000149011612, 0.699999988079071, 0.10000000149011612, 0.6000000238418579, 0.699999988079071, 0.6000000238418579, 0.6000000238418579, 0.5, 1.100000023841858, 0.6000000238418579, 0.6000000238418579, 0.10000000149011612, 1.0, 0.6000000238418579, 0.699999988079071, 1.2000000476837158, 0.699999988079071, 0.8999999761581421, 1.0, 0.5, 0.10000000149011612, 0.10000000149011612, 1.2000000476837158, 0.699999988079071, 0.10000000149011612, 1.0, 1.0, 0.10000000149011612, 1.100000023841858, 0.10000000149011612, 0.6000000238418579, 1.100000023841858, 0.6000000238418579, 0.6000000238418579, 1.100000023841858, 1.100000023841858, 0.6000000238418579, 1.2000000476837158, 0.10000000149011612, 1.2000000476837158, 1.0, 0.5, 1.100000023841858, 1.2000000476837158, 1.2000000476837158, 1.100000023841858, 1.0],27,3)
11243         m=MEDCouplingCurveLinearMesh("toto")
11244         m.setCoords(coords)
11245         m.setNodeGridStructure([3,3,3])
11246         #
11247         vol=m.getMeasureField(False).getArray()
11248         self.assertTrue(vol.isEqual(DataArrayDouble([0.11450000709295281, 0.10583334351579375,0.11149999939029423,0.08866666863113633, 0.1404166805123294,0.1250000135352219,0.1270833433481557,0.13258334288001067]),1e-12))
11249         self.assertTrue(vol.isEqual(m.buildUnstructured().getMeasureField(False).getArray(),1e-12))
11250         #
11251         self.assertTrue(m.getBarycenterAndOwner().isEqual(m.buildUnstructured().getBarycenterAndOwner(),1e-12))
11252         pass
11253
11254     def testSwig2NonRegressionDASetSelectedComponents1(self):
11255         da=DataArrayDouble.New([1.,2.,3.,4.,5.,6.],3,2)
11256         dv=DataArrayDouble.New();
11257         dv.alloc(4,4)
11258         dv.fillWithZero()
11259         # da has less tuples than dv
11260         dv.setSelectedComponents(da,[1,0])
11261         #
11262         self.assertTrue(dv.isEqual(DataArrayDouble([2.,1.,0.,0.,4.,3.,0.,0.,6.,5.,0.,0.,0.,0.,0.,0.],4,4),1e-14))
11263         #
11264         da=DataArrayInt.New([1,2,3,4,5,6],3,2)
11265         dv=DataArrayInt.New();
11266         dv.alloc(4,4)
11267         dv.fillWithZero()
11268         # da has less tuples than dv
11269         dv.setSelectedComponents(da,[1,0])
11270         #
11271         self.assertTrue(dv.isEqual(DataArrayInt([2,1,0,0,4,3,0,0,6,5,0,0,0,0,0,0],4,4)))
11272         pass
11273
11274     def testSwigSetItem3(self):
11275         # 1-2 
11276         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11277         d[3]=[1,2]
11278         self.assertTrue(d.isEqual(DataArrayDouble([0,0,0,0,0,0,1,2,0,0,0,0],6,2),1e-14))
11279         # 2-2 false
11280         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11281         d[[5,3,2]]=[1,2]
11282         self.assertTrue(d.isEqual(DataArrayDouble([0,0,0,0,1,2,1,2,0,0,1,2],6,2),1e-14))
11283         # 3-2 false
11284         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11285         d[:]=[1,2]
11286         self.assertTrue(d.isEqual(DataArrayDouble([1,2,1,2,1,2,1,2,1,2,1,2],6,2),1e-14))
11287         # 4-2 false
11288         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11289         d[DataArrayInt([0,3,4])]=[1,2]
11290         self.assertTrue(d.isEqual(DataArrayDouble([1,2,0,0,0,0,1,2,1,2,0,0],6,2),1e-14))
11291         # 5-2
11292         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11293         d[5,1]=[7]
11294         self.assertTrue(d.isEqual(DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,7],6,2),1e-14))
11295         # 6-2 false
11296         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11297         d[[3,5],1]=[7]
11298         self.assertTrue(d.isEqual(DataArrayDouble([0,0,0,0,0,0,0,7,0,0,0,7],6,2),1e-14))
11299         # 7-2 false
11300         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11301         d[:-1:2,1]=[7]
11302         self.assertTrue(d.isEqual(DataArrayDouble([0,7,0,0,0,7,0,0,0,7,0,0],6,2),1e-14))
11303         # 8-2 false
11304         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11305         d[DataArrayInt([0,3,4]),1]=[7]
11306         self.assertTrue(d.isEqual(DataArrayDouble([0,7,0,0,0,0,0,7,0,7,0,0],6,2),1e-14))
11307         # 9-2
11308         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11309         d[3,[1,0]]=[7,8]
11310         self.assertTrue(d.isEqual(DataArrayDouble([0,0,0,0,0,0,8,7,0,0,0,0],6,2),1e-14))
11311         # 10-2 false
11312         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11313         d[[1,3,4],[1,0]]=[7,8]
11314         self.assertTrue(d.isEqual(DataArrayDouble([0,0,8,7,0,0,8,7,8,7,0,0],6,2),1e-14))
11315         # 11-2 false
11316         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11317         d[1::2,[1,0]]=[7,8]
11318         self.assertTrue(d.isEqual(DataArrayDouble([0,0,8,7,0,0,8,7,0,0,8,7],6,2),1e-14))
11319         # 12-2 false
11320         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11321         d[DataArrayInt([1,4]),[1,0]]=[7,8]
11322         self.assertTrue(d.isEqual(DataArrayDouble([0,0,8,7,0,0,0,0,8,7,0,0],6,2),1e-14))
11323         # 13-2
11324         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11325         d[1,:-1]=[9]
11326         self.assertTrue(d.isEqual(DataArrayDouble([0,0,9,0,0,0,0,0,0,0,0,0],6,2),1e-14))
11327         # 14-2 false
11328         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11329         d[[1,4,5],:]=[7,8]
11330         self.assertTrue(d.isEqual(DataArrayDouble([0,0,7,8,0,0,0,0,7,8,7,8],6,2),1e-14))
11331         # 15-2 false
11332         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11333         d[1::2,:]=[3,9]
11334         self.assertTrue(d.isEqual(DataArrayDouble([0,0,3,9,0,0,3,9,0,0,3,9],6,2),1e-14))
11335         # 1-2 
11336         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11337         d[3]=[1,2]
11338         self.assertTrue(d.isEqual(DataArrayInt([0,0,0,0,0,0,1,2,0,0,0,0],6,2)))
11339         # 2-2 false
11340         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11341         d[[5,3,2]]=[1,2]
11342         self.assertTrue(d.isEqual(DataArrayInt([0,0,0,0,1,2,1,2,0,0,1,2],6,2)))
11343         # 3-2 false
11344         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11345         d[:]=[1,2]
11346         self.assertTrue(d.isEqual(DataArrayInt([1,2,1,2,1,2,1,2,1,2,1,2],6,2)))
11347         # 4-2 false
11348         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11349         d[DataArrayInt([0,3,4])]=[1,2]
11350         self.assertTrue(d.isEqual(DataArrayInt([1,2,0,0,0,0,1,2,1,2,0,0],6,2)))
11351         # 5-2
11352         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11353         d[5,1]=[7]
11354         self.assertTrue(d.isEqual(DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,7],6,2)))
11355         # 6-2 false
11356         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11357         d[[3,5],1]=[7]
11358         self.assertTrue(d.isEqual(DataArrayInt([0,0,0,0,0,0,0,7,0,0,0,7],6,2)))
11359         # 7-2 false
11360         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11361         d[:-1:2,1]=[7]
11362         self.assertTrue(d.isEqual(DataArrayInt([0,7,0,0,0,7,0,0,0,7,0,0],6,2)))
11363         # 8-2 false
11364         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11365         d[DataArrayInt([0,3,4]),1]=[7]
11366         self.assertTrue(d.isEqual(DataArrayInt([0,7,0,0,0,0,0,7,0,7,0,0],6,2)))
11367         # 9-2
11368         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11369         d[3,[1,0]]=[7,8]
11370         self.assertTrue(d.isEqual(DataArrayInt([0,0,0,0,0,0,8,7,0,0,0,0],6,2)))
11371         # 10-2 false
11372         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11373         d[[1,3,4],[1,0]]=[7,8]
11374         self.assertTrue(d.isEqual(DataArrayInt([0,0,8,7,0,0,8,7,8,7,0,0],6,2)))
11375         # 11-2 false
11376         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11377         d[1::2,[1,0]]=[7,8]
11378         self.assertTrue(d.isEqual(DataArrayInt([0,0,8,7,0,0,8,7,0,0,8,7],6,2)))
11379         # 12-2 false
11380         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11381         d[DataArrayInt([1,4]),[1,0]]=[7,8]
11382         self.assertTrue(d.isEqual(DataArrayInt([0,0,8,7,0,0,0,0,8,7,0,0],6,2)))
11383         # 13-2
11384         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11385         d[1,:-1]=[9]
11386         self.assertTrue(d.isEqual(DataArrayInt([0,0,9,0,0,0,0,0,0,0,0,0],6,2)))
11387         # 14-2 false
11388         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11389         d[[1,4,5],:]=[7,8]
11390         self.assertTrue(d.isEqual(DataArrayInt([0,0,7,8,0,0,0,0,7,8,7,8],6,2)))
11391         # 15-2 false
11392         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11393         d[1::2,:]=[3,9]
11394         self.assertTrue(d.isEqual(DataArrayInt([0,0,3,9,0,0,3,9,0,0,3,9],6,2)))
11395         pass
11396
11397     def testSwig2ConvertLinearCellsToQuadratic1(self):
11398         coordsExp=DataArrayDouble([-0.3,-0.3,0.2,-0.3,0.7,-0.3,-0.3,0.2,0.2,0.2,0.7,0.2,-0.3,0.7,0.2,0.7,0.7,0.7,-0.3,-0.05,-0.05,0.2,0.2,-0.05,-0.05,-0.3,0.45,-0.05,0.45,-0.3,0.45,0.2,0.7,-0.05,-0.05,0.7,0.2,0.45,-0.3,0.45,0.45,0.7,0.7,0.45],22,2)
11399         # 2D
11400         m2D=MEDCouplingDataForTest.build2DTargetMesh_1()
11401         m2D.convertLinearCellsToQuadratic(0)
11402         m2D.checkCoherency1()
11403         self.assertEqual(m2D.getNodalConnectivity().getValues(),[8,0,3,4,1,9,10,11,12,6,1,4,2,11,13,14,6,4,5,2,15,16,13,8,6,7,4,3,17,18,10,19,8,7,8,5,4,20,21,15,18])
11404         self.assertEqual(m2D.getNodalConnectivityIndex().getValues(),[0,9,16,23,32,41])
11405         self.assertTrue(m2D.getCoords().isEqual(coordsExp,1e-14))
11406         # 1D
11407         m1D=MEDCouplingDataForTest.build2DTargetMesh_1().buildDescendingConnectivity()[0]
11408         m1D.convertLinearCellsToQuadratic(0)
11409         m1D.checkCoherency1()
11410         self.assertEqual(m1D.getNodalConnectivity().getValues(),[2,0,3,9,2,3,4,10,2,4,1,11,2,1,0,12,2,4,2,13,2,2,1,14,2,4,5,15,2,5,2,16,2,6,7,17,2,7,4,18,2,3,6,19,2,7,8,20,2,8,5,21])
11411         self.assertEqual(m1D.getNodalConnectivityIndex().getValues(),[0,4,8,12,16,20,24,28,32,36,40,44,48,52])
11412         self.assertTrue(m1D.getCoords().isEqual(coordsExp,1e-14))
11413         # 3D
11414         m2D=MEDCouplingDataForTest.build2DTargetMesh_1()
11415         m2D.changeSpaceDimension(3)
11416         arr=DataArrayDouble(4);  arr.iota(0) ; z=MEDCouplingCMesh() ; z.setCoords(arr)
11417         m1D=z.buildUnstructured() ; m1D.setCoords(arr.changeNbOfComponents(3,0.))
11418         m1D.getCoords()[:]=m1D.getCoords()[:,[1,2,0]]
11419         cooTmp=m2D.getCoords()[:]
11420         m3D=m2D.buildExtrudedMesh(m1D,0)
11421         m3D.convertLinearCellsToQuadratic(0)
11422         m3D.checkCoherency1()
11423         # check of new m3D content
11424         coordsExp2=[coordsExp.changeNbOfComponents(3,i) for i in xrange(4)]
11425         coordsExp3=[DataArrayDouble.Meld(cooTmp[:,[0,1]],cooTmp[:,2]+(0.5+float(i))) for i in xrange(3)]
11426         coordsExp4=DataArrayDouble.Aggregate([coordsExp2[0],coordsExp3[0],coordsExp2[1],coordsExp3[1],coordsExp2[2],coordsExp3[2],coordsExp2[3]])
11427         c=DataArrayDouble.Aggregate(m3D.getCoords(),coordsExp4)
11428         self.assertEqual(len(coordsExp4),115)
11429         self.assertEqual(len(m3D.getCoords()),115)
11430         a,b=c.findCommonTuples(1e-14)
11431         self.assertEqual(len(b),len(coordsExp4)+1)
11432         e,f=DataArrayInt.BuildOld2NewArrayFromSurjectiveFormat2(2*115,a,b)
11433         self.assertEqual(f,115)
11434         self.assertTrue(e.isEqual(DataArrayInt([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,0,1,2,3,4,5,6,7,8,36,37,38,39,48,49,53,54,58,59,60,66,67,44,47,52,45,46,57,64,65,70,9,10,11,12,13,14,15,16,17,40,41,42,43,50,51,55,56,61,62,63,68,69,75,78,81,76,77,84,88,89,92,18,19,20,21,22,23,24,25,26,71,72,73,74,79,80,82,83,85,86,87,90,91,97,100,103,98,99,106,110,111,114,27,28,29,30,31,32,33,34,35,93,94,95,96,101,102,104,105,107,108,109,112,113])))
11435         self.assertTrue(DataArrayInt([30,0,3,4,1,9,12,13,10,36,37,38,39,40,41,42,43,44,45,46,47,25,1,4,2,10,13,11,38,48,49,42,50,51,47,46,52,25,4,5,2,13,14,11,53,54,48,55,56,50,46,57,52,30,6,7,4,3,15,16,13,12,58,59,37,60,61,62,41,63,64,65,46,45,30,7,8,5,4,16,17,14,13,66,67,53,59,68,69,55,62,65,70,57,46,30,9,12,13,10,18,21,22,19,40,41,42,43,71,72,73,74,75,76,77,78,25,10,13,11,19,22,20,42,50,51,73,79,80,78,77,81,25,13,14,11,22,23,20,55,56,50,82,83,79,77,84,81,30,15,16,13,12,24,25,22,21,61,62,41,63,85,86,72,87,88,89,77,76,30,16,17,14,13,25,26,23,22,68,69,55,62,90,91,82,86,89,92,84,77,30,18,21,22,19,27,30,31,28,71,72,73,74,93,94,95,96,97,98,99,100,25,19,22,20,28,31,29,73,79,80,95,101,102,100,99,103,25,22,23,20,31,32,29,82,83,79,104,105,101,99,106,103,30,24,25,22,21,33,34,31,30,85,86,72,87,107,108,94,109,110,111,99,98,30,25,26,23,22,34,35,32,31,90,91,82,86,112,113,104,108,111,114,106,99]).isEqual(m3D.getNodalConnectivity()))
11436         self.assertTrue(DataArrayInt([0,21,37,53,74,95,116,132,148,169,190,211,227,243,264,285]).isEqual(m3D.getNodalConnectivityIndex()))
11437         # testing explode3DMeshTo1D
11438         m3DSlice0=m3D[:5]
11439         m3DSlice0.zipCoords()
11440         a,b,c,d,e=m3DSlice0.explode3DMeshTo1D()
11441         self.assertTrue(b.isEqual(DataArrayInt([0,1,2,3,4,5,6,7,8,9,10,11,2,12,13,6,14,15,11,10,16,17,18,12,19,20,14,10,21,16,22,23,1,24,25,26,5,27,28,29,10,9,30,31,17,23,32,33,19,26,29,34,21,10])))
11442         self.assertTrue(c.isEqual(DataArrayInt([0,12,21,30,42,54])))
11443         self.assertTrue(d.isEqual(DataArrayInt([0,0,3,0,1,0,0,0,3,0,1,0,0,0,3,0,1,2,3,4,0,1,1,2,1,1,2,1,1,2,2,4,2,2,4,2,2,4,3,3,4,3,3,3,4,3,3,3,4,4,4,4,4,4])))
11444         self.assertTrue(e.isEqual(DataArrayInt([0,1,3,5,6,7,9,11,12,13,15,20,22,24,25,27,28,30,32,33,35,36,38,39,41,42,43,45,46,47,49,50,51,52,53,54])))
11445         self.assertTrue(a.getNodalConnectivity().isEqual(DataArrayInt([2,0,3,18,2,3,4,19,2,4,1,20,2,1,0,21,2,9,12,22,2,12,13,23,2,13,10,24,2,10,9,25,2,0,9,26,2,3,12,27,2,4,13,28,2,1,10,29,2,4,2,30,2,2,1,31,2,13,11,32,2,11,10,33,2,2,11,34,2,4,5,35,2,5,2,36,2,13,14,37,2,14,11,38,2,5,14,39,2,6,7,40,2,7,4,41,2,3,6,42,2,15,16,43,2,16,13,44,2,12,15,45,2,6,15,46,2,7,16,47,2,7,8,48,2,8,5,49,2,16,17,50,2,17,14,51,2,8,17,52])))
11446         self.assertTrue(a.getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140])))
11447         self.assertTrue(a.getCoords().isEqual(DataArrayDouble([-0.3,-0.3,0.0,0.2,-0.3,0.0,0.7,-0.3,0.0,-0.3,0.2,0.0,0.2,0.2,0.0,0.7,0.2,0.0,-0.3,0.7,0.0,0.2,0.7,0.0,0.7,0.7,0.0,-0.3,-0.3,1.0,0.2,-0.3,1.0,0.7,-0.3,1.0,-0.3,0.2,1.0,0.2,0.2,1.0,0.7,0.2,1.0,-0.3,0.7,1.0,0.2,0.7,1.0,0.7,0.7,1.0,-0.3,-0.05,0.0,-0.05,0.2,0.0,0.2,-0.05,0.0,-0.05,-0.3,0.0,-0.3,-0.05,1.0,-0.05,0.2,1.0,0.2,-0.05,1.0,-0.05,-0.3,1.0,-0.3,-0.3,0.5,-0.3,0.2,0.5,0.2,0.2,0.5,0.2,-0.3,0.5,0.45,-0.05,0.0,0.45,-0.3,0.0,0.45,-0.05,1.0,0.45,-0.3,1.0,0.7,-0.3,0.5,0.45,0.2,0.0,0.7,-0.05,0.0,0.45,0.2,1.0,0.7,-0.05,1.0,0.7,0.2,0.5,-0.05,0.7,0.0,0.2,0.45,0.0,-0.3,0.45,0.0,-0.05,0.7,1.0,0.2,0.45,1.0,-0.3,0.45,1.0,-0.3,0.7,0.5,0.2,0.7,0.5,0.45,0.7,0.0,0.7,0.45,0.0,0.45,0.7,1.0,0.7,0.45,1.0,0.7,0.7,0.5],53,3),1e-14))
11448         pass
11449
11450     def testSwig2DataArrayPushBackValsSilent1(self):
11451         d=DataArrayDouble()
11452         d.pushBackValsSilent([4,5,6])
11453         self.assertTrue(d.isEqual(DataArrayDouble([4.,5.,6.]),1e-14))
11454         e=DataArrayDouble([1,2,3],1,3)
11455         for t in e: d.pushBackValsSilent(t)
11456         self.assertTrue(d.isEqual(DataArrayDouble([4.,5.,6.,1.,2.,3.]),1e-14))
11457         d.pushBackValsSilent(DataArrayDouble([9,10.]))
11458         self.assertTrue(d.isEqual(DataArrayDouble([4.,5.,6.,1.,2.,3.,9.,10.]),1e-14))
11459         d.pushBackValsSilent(DataArrayDouble(0,1))
11460         self.assertTrue(d.isEqual(DataArrayDouble([4.,5.,6.,1.,2.,3.,9.,10.]),1e-14))
11461         e=DataArrayDouble([1,2,3],3,1)
11462         for t in e: d.pushBackValsSilent(t)
11463         self.assertTrue(d.isEqual(DataArrayDouble([4.,5.,6.,1.,2.,3.,9.,10.,1.,2.,3.]),1e-14))
11464         d.pushBackValsSilent(77)
11465         self.assertTrue(d.isEqual(DataArrayDouble([4.,5.,6.,1.,2.,3.,9.,10.,1.,2.,3.,77.]),1e-14))
11466         #
11467         d=DataArrayInt()
11468         d.pushBackValsSilent([4,5,6])
11469         self.assertTrue(d.isEqual(DataArrayInt([4,5,6])))
11470         e=DataArrayInt([1,2,3],1,3)
11471         for t in e: d.pushBackValsSilent(t)
11472         self.assertTrue(d.isEqual(DataArrayInt([4,5,6,1,2,3])))
11473         d.pushBackValsSilent(DataArrayInt([9,10]))
11474         self.assertTrue(d.isEqual(DataArrayInt([4,5,6,1,2,3,9,10])))
11475         d.pushBackValsSilent(DataArrayInt(0,1))
11476         self.assertTrue(d.isEqual(DataArrayInt([4,5,6,1,2,3,9,10])))
11477         e=DataArrayInt([1,2,3],3,1)
11478         for t in e: d.pushBackValsSilent(t)
11479         self.assertTrue(d.isEqual(DataArrayInt([4,5,6,1,2,3,9,10,1,2,3])))
11480         d.pushBackValsSilent(77)
11481         self.assertTrue(d.isEqual(DataArrayInt([4,5,6,1,2,3,9,10,1,2,3,77])))
11482         pass
11483
11484     def testSwig2ConvertLinearCellsToQuadratic2(self):
11485         m2D=MEDCouplingDataForTest.build2DTargetMesh_1()
11486         ret=m2D.convertLinearCellsToQuadratic(1)
11487         self.assertTrue(ret.isIdentity())
11488         self.assertEqual(5,len(ret))
11489         m2D.checkCoherency1()
11490         coordsExp=DataArrayDouble([-0.3,-0.3,0.2,-0.3,0.7,-0.3,-0.3,0.2,0.2,0.2,0.7,0.2,-0.3,0.7,0.2,0.7,0.7,0.7,-0.3,-0.05,-0.05,0.2,0.2,-0.05,-0.05,-0.3,0.45,-0.05,0.45,-0.3,0.45,0.2,0.7,-0.05,-0.05,0.7,0.2,0.45,-0.3,0.45,0.45,0.7,0.7,0.45,-0.05,-0.05,0.3666666666666667,-0.1333333333333333,0.5333333333333332,0.03333333333333334,-0.05,0.45,0.45,0.45],27,2)
11491         self.assertTrue(m2D.getCoords().isEqual(coordsExp,1e-14))
11492         self.assertTrue(m2D.getNodalConnectivity().isEqual(DataArrayInt([9,0,3,4,1,9,10,11,12,22,7,1,4,2,11,13,14,23,7,4,5,2,15,16,13,24,9,6,7,4,3,17,18,10,19,25,9,7,8,5,4,20,21,15,18,26])))
11493         self.assertTrue(m2D.getNodalConnectivityIndex().isEqual(DataArrayInt([0,10,18,26,36,46])))
11494         #
11495         m2D=MEDCouplingDataForTest.build2DTargetMesh_1()[(0,3)] ; m2D.zipCoords()
11496         m2D.changeSpaceDimension(3)
11497         arr=DataArrayDouble(3);  arr.iota(0) ; z=MEDCouplingCMesh() ; z.setCoords(arr)
11498         m1D=z.buildUnstructured() ; m1D.setCoords(arr.changeNbOfComponents(3,0.))
11499         m1D.getCoords()[:]=m1D.getCoords()[:,[1,2,0]]
11500         cooTmp=m2D.getCoords()[:]
11501         m3D=m2D.buildExtrudedMesh(m1D,0)
11502         ret=m3D.convertLinearCellsToQuadratic(1)
11503         self.assertTrue(ret.isIdentity())
11504         self.assertEqual(4,len(ret))
11505         m3D.checkCoherency1()
11506         coordsExp2=DataArrayDouble([-0.3,-0.3,0.0,0.2,-0.3,0.0,-0.3,0.2,0.0,0.2,0.2,0.0,-0.3,0.7,0.0,0.2,0.7,0.0,-0.3,-0.3,1.0,0.2,-0.3,1.0,-0.3,0.2,1.0,0.2,0.2,1.0,-0.3,0.7,1.0,0.2,0.7,1.0,-0.3,-0.3,2.0,0.2,-0.3,2.0,-0.3,0.2,2.0,0.2,0.2,2.0,-0.3,0.7,2.0,0.2,0.7,2.0,-0.3,-0.05,0.0,-0.05,0.2,0.0,0.2,-0.05,0.0,-0.05,-0.3,0.0,-0.3,-0.05,1.0,-0.05,0.2,1.0,0.2,-0.05,1.0,-0.05,-0.3,1.0,-0.3,-0.3,0.5,-0.3,0.2,0.5,0.2,0.2,0.5,0.2,-0.3,0.5,-0.05,0.7,0.0,0.2,0.45,0.0,-0.3,0.45,0.0,-0.05,0.7,1.0,0.2,0.45,1.0,-0.3,0.45,1.0,-0.3,0.7,0.5,0.2,0.7,0.5,-0.3,-0.05,2.0,-0.05,0.2,2.0,0.2,-0.05,2.0,-0.05,-0.3,2.0,-0.3,-0.3,1.5,-0.3,0.2,1.5,0.2,0.2,1.5,0.2,-0.3,1.5,-0.05,0.7,2.0,0.2,0.45,2.0,-0.3,0.45,2.0,-0.3,0.7,1.5,0.2,0.7,1.5,-0.05,-0.05,0.0,-0.3,-0.05,0.5,-0.05,0.2,0.5,0.2,-0.05,0.5,-0.05,-0.3,0.5,-0.05,-0.05,1.0,-0.05,0.45,0.0,-0.05,0.7,0.5,0.2,0.45,0.5,-0.3,0.45,0.5,-0.05,0.45,1.0,-0.3,-0.05,1.5,-0.05,0.2,1.5,0.2,-0.05,1.5,-0.05,-0.3,1.5,-0.05,-0.05,2.0,-0.05,0.7,1.5,0.2,0.45,1.5,-0.3,0.45,1.5,-0.05,0.45,2.0,-0.05,-0.05,0.5,-0.05,0.45,0.5,-0.05,-0.05,1.5,-0.05,0.45,1.5],75,3)
11507         self.assertTrue(m3D.getCoords().isEqual(coordsExp2,1e-14))
11508         self.assertTrue(m3D.getNodalConnectivity().isEqual(DataArrayInt([27,0,2,3,1,6,8,9,7,18,19,20,21,22,23,24,25,26,27,28,29,51,52,53,54,55,56,71,27,4,5,3,2,10,11,9,8,30,31,19,32,33,34,23,35,36,37,28,27,57,58,59,53,60,61,72,27,6,8,9,7,12,14,15,13,22,23,24,25,38,39,40,41,42,43,44,45,56,62,63,64,65,66,73,27,10,11,9,8,16,17,15,14,33,34,23,35,46,47,39,48,49,50,44,43,61,67,68,63,69,70,74])))
11509         self.assertTrue(m3D.getNodalConnectivityIndex().isEqual(DataArrayInt([0,28,56,84,112])))
11510         pass
11511
11512     def testSwig2GaussNEIntegral1(self):
11513         m2D=MEDCouplingDataForTest.build2DTargetMesh_1()
11514         m0=m2D[0] ; m0.zipCoords()
11515         m1=m2D[[1,2]] ; m1.zipCoords()
11516         m2=m2D[[3,4]] ; m2.zipCoords()
11517         m0.convertLinearCellsToQuadratic(1)
11518         m1.convertLinearCellsToQuadratic(0)
11519         m2.convertLinearCellsToQuadratic(1)
11520         m=MEDCouplingUMesh.MergeUMeshes([m0,m1,m2])
11521         m.mergeNodes(1e-12)
11522         f=MEDCouplingFieldDouble(ON_GAUSS_NE)
11523         f.setMesh(m)
11524         arr=DataArrayDouble([1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8,9.9,
11525                              11.1,12.2,13.3,14.4,15.5,16.6,
11526                              21.1,22.2,23.3,24.4,25.5,26.6,
11527                              31.1,32.2,33.3,34.4,35.5,36.6,37.7,38.8,39.9,
11528                              41.1,42.2,43.3,44.4,45.5,46.6,47.7,48.8,49.9])
11529         arr2=DataArrayDouble(len(arr),2)
11530         arr2[:,0]=arr ; arr2[:,1]=arr+100
11531         f.setArray(arr2)
11532         f.checkCoherency()
11533         res=f.integral(False)
11534         # a=25./81 ; b=40./81 ; c=64./81
11535         # p1=0.11169079483905 ; p2=0.0549758718227661
11536         # 1st compo
11537         # c0=(a*(1.1+2.2+3.3+4.4)+b*(5.5+6.6+7.7+8.8)+c*9.9)*0.25/3.9999999999999978 ; c0=1.5837962962962973
11538         # c1=(p2*(11.1+12.2+13.3)+p1*(14.4+15.5+16.6))*0.125/0.4999999999854482 ; c1=1.8014347172346943
11539         # c2=(p2*(21.1+22.2+23.3)+p1*(24.4+25.5+26.6))*0.125/0.4999999999854482 ; c2=3.0514347172346943
11540         # c3=(a*(31.1+32.2+33.3+34.4)+b*(35.5+36.6+37.7+38.8)+c*39.9)*0.25/3.9999999999999978 ; c3=9.0837962962963
11541         # c4=(a*(41.1+42.2+43.3+44.4)+b*(45.5+46.6+47.7+48.8)+c*49.9)*0.25/3.9999999999999978 ; c4=11.583796296296303
11542         # c0+c1+c2+c3+c4=27.104258323358287
11543         integExp0=27.104258323358287
11544         self.assertAlmostEqual(res[0],integExp0,13)
11545         # 2nd compo
11546         # c0=(a*(101.1+102.2+103.3+104.4)+b*(105.5+106.6+107.7+108.8)+c*109.9)*0.25/3.9999999999999978 ; c0=26.58379629629631
11547         # c1=(p2*(111.1+112.2+113.3)+p1*(114.4+115.5+116.6))*0.125/0.4999999999854482 ; c1=14.301434717234699
11548         # c2=(p2*(121.1+122.2+123.3)+p1*(124.4+125.5+126.6))*0.125/0.4999999999854482 ; c2=15.5514347172347
11549         # c3=(a*(131.1+132.2+133.3+134.4)+b*(135.5+136.6+137.7+138.8)+c*139.9)*0.25/3.9999999999999978 ; c3=34.08379629629631
11550         # c4=(a*(141.1+142.2+143.3+144.4)+b*(145.5+146.6+147.7+148.8)+c*149.9)*0.25/3.9999999999999978 ; c4=36.58379629629632
11551         # c0+c1+c2+c3+c4=127.10425832335835
11552         integExp1=127.10425832335835
11553         self.assertAlmostEqual(res[1],integExp1,12)
11554         meas=f.getDiscretization().getMeasureField(f.getMesh(),False)
11555         intPerTuple=meas*f
11556         res2=intPerTuple.accumulate()
11557         self.assertAlmostEqual(res2[0],integExp0,13)
11558         self.assertAlmostEqual(res2[1],integExp1,12)
11559         #
11560         meas2=f.buildMeasureField(False)
11561         intPerTuple=meas2*f
11562         res3=intPerTuple.accumulate()
11563         self.assertAlmostEqual(res3[0],integExp0,13)
11564         self.assertAlmostEqual(res3[1],integExp1,12)
11565         #
11566         res4=f.getWeightedAverageValue(False) # res4==res2 because sum of area of mesh is equal to 1
11567         self.assertAlmostEqual(res4[0],integExp0,13)
11568         self.assertAlmostEqual(res4[1],integExp1,12)
11569         #
11570         m.scale([0,0],2.)
11571         #
11572         res5=f.getWeightedAverageValue() # res4==res4 because weighted average is not sensitive to the scaling
11573         self.assertAlmostEqual(res5[0],integExp0,13)
11574         self.assertAlmostEqual(res5[1],integExp1,12)
11575         meas3=f.buildMeasureField(False)
11576         delta=4*meas2.getArray()-meas3.getArray()
11577         delta.abs()
11578         self.assertTrue(delta.isUniform(0.,1e-16))
11579         res6=f.integral(False)
11580         self.assertAlmostEqual(res6[0],4.*integExp0,12)
11581         self.assertAlmostEqual(res6[1],4.*integExp1,11)
11582         pass
11583
11584     def testSwig2SlowDADFindClosestTupleId(self):
11585         nbPts=[10,]
11586         for nbPt in nbPts:
11587             d=DataArrayDouble(nbPt) ; d.iota() ; d*=1./(nbPt-1)
11588             c=MEDCouplingCMesh() ; c.setCoords(d,d) ; m=c.buildUnstructured() ; pts=m.getCoords() ; del m
11589             #
11590             d0=DataArrayDouble((nbPt-1)*(nbPt-1)) ; d0.iota() ; d0*=(3./((nbPt-1)*(nbPt-1))) ; d0=d0.applyFunc("exp(x)-1")
11591             d1=DataArrayDouble((nbPt-1)*(nbPt-1)) ; d1.iota()
11592             d2=DataArrayDouble.Meld(d0,d1) ; d2=d2.fromPolarToCart() ; d2+=[0.32,0.73]
11593             ids=pts.findClosestTupleId(d2)
11594             #print "Start of costly computation"
11595             idsExpected=DataArrayInt(len(d2))
11596             tmp=1e300
11597             for i,elt in enumerate(d2):
11598                 l,m=(pts-elt).magnitude().getMinValue()
11599                 idsExpected.setIJSilent(i,0,m)
11600                 if l<tmp:
11601                     tmp=l ; tmp1=m ; tmp2=i
11602                     pass
11603                 pass
11604             #print "End of costly computation"
11605             self.assertTrue(idsExpected.isEqual(ids))
11606             a,b,c=pts.minimalDistanceTo(d2)
11607             self.assertEqual(tmp,a)
11608             self.assertEqual(tmp1,b)
11609             self.assertEqual(tmp2,c)
11610             #
11611             l=[d2[:,i] for i in [0,1]]
11612             for elt in l: elt.reverse()
11613             d2i=DataArrayDouble.Meld(l)
11614             ids1=pts.findClosestTupleId(d2i)
11615             idsExpectedI=idsExpected.deepCpy() ; idsExpectedI.reverse()
11616             self.assertTrue(idsExpectedI.isEqual(ids1))
11617             #
11618             l=[pts[:,i] for i in [0,1]]
11619             for elt in l: elt.reverse()
11620             ptsi=DataArrayDouble.Meld(l)
11621             ids2=ptsi.findClosestTupleId(d2)
11622             idsExpected2=nbPt*nbPt-1-ids
11623             self.assertTrue(idsExpected2.isEqual(ids2))
11624             #
11625             ids3=ptsi.findClosestTupleId(d2i)
11626             idsExpected3=idsExpected2.deepCpy() ; idsExpected3.reverse()
11627             self.assertTrue(idsExpected3.isEqual(ids3))
11628             pass
11629
11630     def testSwig2DataArrayAsciiChar1(self):
11631         alpha=DataArrayInt(26) ; alpha.iota(ord("A"))
11632         d=DataArrayAsciiChar(alpha.getValues(),2,13)
11633         d.setInfoOnComponents(["c%i"%(v) for v in xrange(13)])
11634         self.assertEqual('ABCDEFGHIJKLM',d.getTuple(0))
11635         self.assertEqual('NOPQRSTUVWXYZ',d.getTuple(1))
11636         self.assertEqual(2,d.getNumberOfTuples())
11637         self.assertEqual(26,d.getNbOfElems())
11638         self.assertEqual(13,d.getNumberOfComponents())
11639         dd=d.deepCpy()
11640         self.assertTrue(d.isEqual(dd))
11641         dd.setIJ(0,3,'d')
11642         self.assertTrue(not d.isEqual(dd))
11643         d.setIJ(0,3,ord('d'))
11644         self.assertTrue(d.isEqual(dd))
11645         d.rearrange(1)
11646         d.reserve(20)
11647         self.assertEqual(20,d.getNumberOfTuples())
11648         self.assertEqual(20,d.getNbOfElems())
11649         self.assertEqual(1,d.getNumberOfComponents())
11650         #
11651         d0=DataArrayAsciiChar([ord('a')],1,1)
11652         self.assertEqual('a',d0.asciiCharValue())
11653         self.assertTrue(not d0.empty())
11654         d0=DataArrayAsciiChar(0,3)
11655         self.assertTrue(d0.empty())
11656         d.pushBackSilent("U") ; d.pushBackSilent("V") ; d.pushBackSilent("W")
11657         self.assertEqual("W",d.popBackSilent())
11658         d.rearrange(2)
11659         self.assertEqual(['AB','Cd','EF','GH','IJ','KL','MN','OP','QR','ST','UV'],d.toStrList())
11660         d.fillWithZero()
11661         self.assertEqual(11*[''],d.toStrList())
11662         d.fillWithValue('T')
11663         self.assertEqual(11*["TT"],d.toStrList())
11664         d.rearrange(1)
11665         self.assertTrue(d.isUniform("T"))
11666         d.rearrange(2)
11667         #
11668         dd.rearrange(2)
11669         dd2=dd.deepCpy()
11670         dd.renumberInPlace([3,1,2,4,0,11,10,9,8,7,5,12,6])
11671         self.assertEqual(dd.toStrList(),['IJ','Cd','EF','AB','GH','UV','YZ','ST','QR','OP','MN','KL','WX'])
11672         dd.renumberInPlaceR([3,1,2,4,0,11,10,9,8,7,5,12,6])
11673         self.assertEqual(['AB','Cd','EF','GH','IJ','KL','MN','OP','QR','ST','UV','WX','YZ'],dd.toStrList())
11674         e=dd.renumber([3,1,2,4,0,11,10,9,8,7,5,12,6])
11675         self.assertEqual(e.toStrList(),['IJ','Cd','EF','AB','GH','UV','YZ','ST','QR','OP','MN','KL','WX'])
11676         e=dd.renumberR([3,1,2,4,0,11,10,9,8,7,5,12,6])
11677         self.assertEqual(e.toStrList(),['GH','Cd','EF','IJ','AB','WX','UV','ST','QR','OP','KL','YZ','MN'])
11678         e=dd.renumberAndReduce([1,1,1,1,1,1,1,2,0,0,0,0,0],3)
11679         self.assertEqual(['YZ','MN','OP'],e.toStrList())
11680         self.assertEqual(['GH','IJ'],dd.selectByTupleIdSafe([3,4]).toStrList())
11681         self.assertEqual(['AB','GH','MN','ST','YZ'],dd.selectByTupleId2(0,13,3).toStrList())
11682         dd3=dd.changeNbOfComponents(3,"G")
11683         self.assertEqual(['ABG','CdG','EFG','GHG','IJG','KLG','MNG','OPG','QRG','STG','UVG','WXG','YZG'],dd3.toStrList())
11684         dd3.rearrange(1) ; self.assertEqual("G",dd3.back()) ; dd3.rearrange(3)
11685         self.assertTrue(dd3.changeNbOfComponents(2,"\0").isEqual(dd))
11686         self.assertEqual(len(dd),13)
11687         d=DataArrayAsciiChar(13,2) ; d.fillWithValue('Y')
11688         dd3.meldWith(d)
11689         self.assertEqual(['ABGYY','CdGYY','EFGYY','GHGYY','IJGYY','KLGYY','MNGYY','OPGYY','QRGYY','STGYY','UVGYY','WXGYY','YZGYY'],dd3.toStrList())
11690         self.assertEqual("d",dd3.getIJ(0,6))
11691         self.assertRaises(InterpKernelException,dd3.getIJSafe,0,6)
11692         self.assertEqual("d",dd3.getIJSafe(1,1))
11693         dd3.rearrange(1)
11694         e=dd3.getIdsEqual("Y")
11695         self.assertTrue(e.isEqual(DataArrayInt([3,4,8,9,13,14,18,19,23,24,28,29,33,34,38,39,43,44,48,49,53,54,58,59,60,63,64])))
11696         e=dd3.getIdsNotEqual("Y")
11697         self.assertTrue(e.isEqual(DataArrayInt([0,1,2,5,6,7,10,11,12,15,16,17,20,21,22,25,26,27,30,31,32,35,36,37,40,41,42,45,46,47,50,51,52,55,56,57,61,62])))
11698         self.assertEqual(("d",6),dd3.getMaxValue())
11699         self.assertEqual(("A",0),dd3.getMinValue())
11700         self.assertEqual(26,dd3.search("LGYYM"))
11701         self.assertEqual(-1,dd3.search("LGYYN"))
11702         dd3.rearrange(5)
11703         self.assertEqual(7,dd3.locateTuple("OPGYY"))
11704         self.assertTrue("OPGYY" in dd3)
11705         self.assertEqual(7,dd3.index("OPGYY"))
11706         self.assertEqual(-1,dd3.locateTuple("OPGYP"))
11707         dd3.rearrange(1)
11708         self.assertEqual(2,dd3.locateValue("OPGYY"))
11709         self.assertTrue(dd3.presenceOfValue("OPGYY"))
11710         self.assertTrue("O" in dd3)
11711         self.assertTrue(not dd3.presenceOfValue("z"))
11712         self.assertTrue("z" not in dd3)
11713         dd3.rearrange(5)
11714         l=list(dd3)
11715         self.assertEqual([e.buildDAAsciiChar().toStrList()[0] for e in list(dd3)],dd3.toStrList())
11716         dd3.reAlloc(5)
11717         dd4=DataArrayChar.Aggregate(dd3,dd3)
11718         self.assertEqual(['ABGYY','CdGYY','EFGYY','GHGYY','IJGYY','ABGYY','CdGYY','EFGYY','GHGYY','IJGYY'],dd4.toStrList())
11719         dd5=DataArrayChar.Aggregate([dd4,dd3,dd4])
11720         self.assertEqual(['ABGYY','CdGYY','EFGYY','GHGYY','IJGYY','ABGYY','CdGYY','EFGYY','GHGYY','IJGYY','ABGYY','CdGYY','EFGYY','GHGYY','IJGYY','ABGYY','CdGYY','EFGYY','GHGYY','IJGYY','ABGYY','CdGYY','EFGYY','GHGYY','IJGYY'],dd5.toStrList())
11721         # getitem,__iter__,__setitem__
11722         a=list(dd3)
11723         self.assertEqual("ABGYY",str(a[0]))
11724         dd4=dd3[::2]
11725         self.assertEqual(['ABGYY','EFGYY','IJGYY'],dd4.toStrList())
11726         dd4=dd3[(3,2,1)]
11727         self.assertEqual(['GHGYY','EFGYY','CdGYY'],dd4.toStrList())
11728         dd4=dd3[:]
11729         dd4[::2]=["12","345","67890"]
11730         self.assertEqual(['12   ','CdGYY','345  ','GHGYY','67890'],dd4.toStrList())
11731         dd4=dd3[:]
11732         dd4[[1,2]]=" "
11733         self.assertEqual(['ABGYY','     ','     ','GHGYY','IJGYY'],dd4.toStrList())
11734         dd4=dd3[:]
11735         dd4[4]='12345'
11736         self.assertEqual(['ABGYY','CdGYY','EFGYY','GHGYY','12345'],dd4.toStrList())
11737         dd4[0]=dd4[1]
11738         self.assertEqual(['CdGYY','CdGYY','EFGYY','GHGYY','12345'],dd4.toStrList())
11739         dd4=DataArrayAsciiChar(["abc","de","fghi"])
11740         self.assertEqual(['abc ','de  ','fghi'],dd4.toStrList())
11741         dd4=DataArrayAsciiChar(["abc","de","fghi"],"t")
11742         self.assertEqual(['abct','dett','fghi'],dd4.toStrList())
11743         pass
11744
11745     def testSwig2GaussNELocalizationOfDiscValues(self):
11746         m=MEDCouplingDataForTest.build2DTargetMesh_3()[[0,1,3,4,5,6,8,9]] # suppression of polygons
11747         f=MEDCouplingFieldDouble(ON_GAUSS_NE)
11748         f.setMesh(m)
11749         loc=f.getLocalizationOfDiscr()
11750         self.assertEqual(42,len(loc))
11751         self.assertTrue(loc.isEqual(DataArrayDouble([0.,0.,1.,0.,0.5,1.,0.,0.,1.,0.,1.,1.,0.,1.,0.,0.,1.,0.,0.5,1.,0.5,0.,0.75,0.5,0.25,0.5,0.,0.,1.,0.,1.,1.,0.,1.,0.5,0.,1.,0.5,0.5,1.,0.,0.5,0.,0.,0.5,1.,1.,0.,0.,0.,0.,1.,1.,1.,1.,0.,0.,0.,0.5,1.,1.,0.,0.25,0.5,0.75,0.5,0.5,0.,0.,0.,0.,1.,1.,1.,1.,0.,0.,0.5,0.5,1.,1.,0.5,0.5,0.],42,2),1e-13))
11752         m.changeSpaceDimension(3)
11753         m.getCoords()[:,2]=7.
11754         loc=f.getLocalizationOfDiscr()
11755         self.assertEqual(42,len(loc))
11756         self.assertTrue(loc.isEqual(DataArrayDouble([0.,0.,7.,1.,0.,7.,0.5,1.,7.,0.,0.,7.,1.,0.,7.,1.,1.,7.,0.,1.,7.,0.,0.,7.,1.,0.,7.,0.5,1.,7.,0.5,0.,7.,0.75,0.5,7.,0.25,0.5,7.,0.,0.,7.,1.,0.,7.,1.,1.,7.,0.,1.,7.,0.5,0.,7.,1.,0.5,7.,0.5,1.,7.,0.,0.5,7.,0.,0.,7.,0.5,1.,7.,1.,0.,7.,0.,0.,7.,0.,1.,7.,1.,1.,7.,1.,0.,7.,0.,0.,7.,0.5,1.,7.,1.,0.,7.,0.25,0.5,7.,0.75,0.5,7.,0.5,0.,7.,0.,0.,7.,0.,1.,7.,1.,1.,7.,1.,0.,7.,0.,0.5,7.,0.5,1.,7.,1.,0.5,7.,0.5,0.,7.],42,3),1e-13))
11757         pass
11758
11759     def testSwig2GaussMeasureAndIntegral(self):
11760         ft=MEDCouplingDataForTest.buildFieldOnGauss_1()
11761         mea=ft.buildMeasureField(False)
11762         mea.checkCoherency()
11763         self.assertTrue(mea.getArray().isEqual(DataArrayDouble([-0.08504076274779823,-0.06378057206084897,-0.08504076274779869,-0.10630095343474463,-0.12756114412169625,-0.10630095343474734,-0.0637805720608491,-0.0850407627477968,-0.1063009534347449,-0.0850407627477994,-0.10630095343474809,-0.1275611441216954,-0.037205333702161475,-0.037205333702161475,-0.037205333702161475,-0.037205333702161475,-0.047835429045636084,-0.047835429045636084,-0.047835429045636084,-0.047835429045636084,-0.05846552438911087,-0.05846552438911087,-0.05846552438911087,-0.05846552438911087,-0.037205333702161725,-0.037205333702161725,-0.037205333702161725,-0.037205333702161725,-0.047835429045635834,-0.047835429045635834,-0.047835429045635834,-0.047835429045635834,-0.05846552438911058,-0.05846552438911058,-0.05846552438911058,-0.05846552438911058,-0.03879154890291829,-0.03879154890291829,-0.03879154890291829,-0.04120270848015563,-0.04120270848015563,-0.04120270848015563,-0.03393028948486933,-0.03393028948486933,-0.03393028948486933,-0.03151955746491709,-0.03151955746491709,-0.03151955746491709,-0.02424752187358276,-0.02424752187358276,-0.02424752187358276,-0.026657914642918758,-0.026657914642918758,-0.026657914642918758,-0.04120270848015456,-0.04120270848015456,-0.04120270848015456,-0.03879154890291757,-0.03879154890291757,-0.03879154890291757,-0.031519557464916595,-0.031519557464916595,-0.031519557464916595,-0.03393028948487046,-0.03393028948487046,-0.03393028948487046,-0.0266579146429191,-0.0266579146429191,-0.0266579146429191,-0.024247521873582645,-0.024247521873582645,-0.024247521873582645,-0.01851718920904466,-0.01851718920904466,-0.01851718920904466,-0.01851718920904466,-0.029627502734471456,-0.029627502734471456,-0.029627502734471456,-0.029627502734471456,-0.04740400437515433,-0.015150427534672922,-0.015150427534672922,-0.015150427534672922,-0.015150427534672922,-0.024240684055476674,-0.024240684055476674,-0.024240684055476674,-0.024240684055476674,-0.038785094488762675,-0.011783665860301345,-0.011783665860301345,-0.011783665860301345,-0.011783665860301345,-0.018853865376482152,-0.018853865376482152,-0.018853865376482152,-0.018853865376482152,-0.030166184602371443,-0.018517189209044892,-0.018517189209044892,-0.018517189209044892,-0.018517189209044892,-0.029627502734471827,-0.029627502734471827,-0.029627502734471827,-0.029627502734471827,-0.04740400437515492,-0.015150427534672776,-0.015150427534672776,-0.015150427534672776,-0.015150427534672776,-0.02424068405547644,-0.02424068405547644,-0.02424068405547644,-0.02424068405547644,-0.03878509448876231,-0.011783665860301277,-0.011783665860301277,-0.011783665860301277,-0.011783665860301277,-0.01885386537648204,-0.01885386537648204,-0.01885386537648204,-0.01885386537648204,-0.030166184602371266]),1e-14))
11764         f=MEDCouplingFieldDouble(ft)
11765         arr=DataArrayDouble(126,2)
11766         arr[:,0]=range(126)
11767         arr[:,1]=range(126)
11768         arr[:,1]+=1000
11769         f.setArray(arr)
11770         f.checkCoherency()
11771         self.assertTrue(DataArrayDouble(f.integral(False)).isEqual(DataArrayDouble([-211.66121638700983,-4863.9563007698835]),1e-11))
11772         self.assertTrue(DataArrayDouble(f.getWeightedAverageValue()).isEqual(DataArrayDouble([45.496085813113595,1045.496085813114]),1e-11))
11773         self.assertTrue(DataArrayDouble(f.normL1()).isEqual(DataArrayDouble([45.49608581311362,1045.496085813114]),1e-11))
11774         self.assertTrue(DataArrayDouble(f.normL2()).isEqual(DataArrayDouble([58.16846378340898,1046.1241521947334]),1e-11))
11775         pass
11776
11777     def testSwig2FieldDiscretizationComputeMeshRestrictionFromTupleIds1(self):
11778         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1()
11779         f=MEDCouplingFieldDouble(ON_GAUSS_NE)
11780         f.setMesh(m)
11781         a,b=f.getDiscretization().computeMeshRestrictionFromTupleIds(f.getMesh(),[3,4,5,6,8,9,10,14,15,16,17])
11782         self.assertTrue(a.isEqual(DataArrayInt([1,4])))
11783         self.assertTrue(b.isEqual(DataArrayInt([4,5,6,14,15,16,17])))
11784         a,b=f.getDiscretization().computeMeshRestrictionFromTupleIds(f.getMesh(),DataArrayInt([0,1,2,3,5,7,8,9,10,11,12,18]))
11785         self.assertTrue(a.isEqual(DataArrayInt([0,2])))
11786         self.assertTrue(b.isEqual(DataArrayInt([0,1,2,3,7,8,9])))
11787         #
11788         f=MEDCouplingFieldDouble(ON_CELLS)
11789         f.setMesh(m)
11790         a,b=f.getDiscretization().computeMeshRestrictionFromTupleIds(f.getMesh(),[3,4])
11791         self.assertTrue(a.isEqual(DataArrayInt([3,4])))
11792         self.assertTrue(b.isEqual(DataArrayInt([3,4])))
11793         #
11794         f=MEDCouplingFieldDouble(ON_NODES)
11795         f.setMesh(m)
11796         a,b=f.getDiscretization().computeMeshRestrictionFromTupleIds(f.getMesh(),[1,2,3,4])
11797         self.assertTrue(a.isEqual(DataArrayInt([1])))
11798         self.assertTrue(b.isEqual(DataArrayInt([1,2,4])))
11799         #
11800         f=MEDCouplingDataForTest.buildFieldOnGauss_1()
11801         a,b=f.getDiscretization().computeMeshRestrictionFromTupleIds(f.getMesh(),[0,11,12,13,14,15,17,18,19,36,37,38,115,117,118,119,120,121,122,123,124,125])
11802         self.assertTrue(a.isEqual(DataArrayInt([0,11,12,18,35])))
11803         self.assertTrue(b.isEqual(DataArrayInt([0,11,12,13,14,15,36,37,38,117,118,119,120,121,122,123,124,125])))
11804         #
11805         d=DataArrayInt([0,3,7,9,15,18])
11806         e=DataArrayInt([0,1,2,3,7,8,15,16,17])
11807         a,b=d.searchRangesInListOfIds(e)
11808         self.assertTrue(a.isEqual(DataArrayInt([0,2,4])))
11809         self.assertTrue(b.isEqual(DataArrayInt([0,1,2,7,8,15,16,17])))
11810         pass
11811     
11812     def testSwig2BigMem(self):
11813         if MEDCouplingSizeOfVoidStar()==64:
11814             d=DataArrayAsciiChar(223456789,16)
11815             self.assertTrue(d.getNumberOfTuples(),223456789)
11816             self.assertTrue(d.getNumberOfComponents(),16)
11817             d.setIJ(223456788,5,"r")
11818             self.assertTrue(d.getIJ(223456788,5),'r')
11819             d[223456787]="1234567890123456"
11820             self.assertTrue(d[223456787],'1234567890123456')
11821             self.assertRaises(InterpKernelException,d.rearrange,1)# fails because it would lead to nb of tuples > 2147483647
11822             pass
11823         pass
11824
11825     def testSwig2DAReverseMultiCompo1(self):
11826         d=DataArrayDouble(6,2)
11827         d[:,0]=range(6)
11828         d[:,1]=range(10,16)
11829         d.reverse()
11830         self.assertTrue(d.isEqual(DataArrayDouble([5.,15.,4.,14.,3.,13.,2.,12.,1.,11.,0.,10.],6,2),1e-14))
11831         d=DataArrayDouble(7,2)
11832         d[:,0]=range(7)
11833         d[:,1]=range(10,17)
11834         d.reverse()
11835         self.assertTrue(d.isEqual(DataArrayDouble([6.,16.,5.,15.,4.,14.,3.,13.,2.,12.,1.,11.,0.,10.],7,2),1e-14))
11836         #
11837         d=DataArrayInt(6,2)
11838         d[:,0]=range(6)
11839         d[:,1]=range(10,16)
11840         d.reverse()
11841         self.assertTrue(d.isEqual(DataArrayInt([5,15,4,14,3,13,2,12,1,11,0,10],6,2)))
11842         d=DataArrayInt(7,2)
11843         d[:,0]=range(7)
11844         d[:,1]=range(10,17)
11845         d.reverse()
11846         self.assertTrue(d.isEqual(DataArrayInt([6,16,5,15,4,14,3,13,2,12,1,11,0,10],7,2)))
11847         pass
11848
11849     def testSwigDAPow1(self):
11850         d=DataArrayInt(10)
11851         d.iota(0)
11852         d1=d.deepCpy()
11853         d.setIJ(2,0,-2)
11854         self.assertTrue((d**2).isEqual(DataArrayInt([0,1,4,9,16,25,36,49,64,81])))
11855         self.assertTrue((d**3).isEqual(DataArrayInt([0,1,-8,27,64,125,216,343,512,729])))
11856         for elt in [d]:
11857             elt**=2
11858             pass
11859         self.assertTrue(d.isEqual(DataArrayInt([0,1,4,9,16,25,36,49,64,81])))
11860         self.assertTrue((d1[:4]**d1[:4]).isEqual(DataArrayInt([1,1,4,27])))
11861         self.assertTrue((3**d1[:4]).isEqual(DataArrayInt([1,3,9,27])))
11862         d2=d1[:4]
11863         d2**=d2
11864         self.assertTrue(d2.isEqual(DataArrayInt([1,1,4,27])))
11865         self.assertRaises(InterpKernelException,d2.__pow__,-1)#non supporting negative pow in DataArrayInt.__pow__
11866         self.assertRaises(InterpKernelException,d2.__ipow__,-1)#non supporting negative pow in DataArrayInt.__pow__
11867         #
11868         d=DataArrayDouble(10)
11869         d.iota(0)
11870         d1=d.deepCpy()
11871         d.setIJ(2,0,-2.)
11872         self.assertTrue((d**2).isEqual(DataArrayDouble([0,1,4,9,16,25,36,49,64,81]),1e-12))
11873         self.assertTrue((d**3).isEqual(DataArrayDouble([0,1,-8,27,64,125,216,343,512,729]),1e-12))
11874         self.assertRaises(InterpKernelException,d.__pow__,3.1)#3.1 is double not integer -> not supporting negative values in d
11875         for elt in [d]:
11876             elt**=2
11877             pass
11878         self.assertTrue(d.isEqual(DataArrayDouble([0,1,4,9,16,25,36,49,64,81]),1e-12))
11879         self.assertTrue((d1[:4]**d1[:4]).isEqual(DataArrayDouble([1,1,4,27]),1e-12))
11880         self.assertTrue((3**d1[:4]).isEqual(DataArrayDouble([1,3,9,27]),1e-12))
11881         d2=d1[:4]
11882         d2**=d2
11883         self.assertTrue(d2.isEqual(DataArrayDouble([1,1,4,27]),1e-12))
11884         d2**=-0.5
11885         self.assertTrue(d2.isEqual(DataArrayDouble([1,1,1./2,1./sqrt(27.)]),1e-14))
11886         d3=-1./d1[1:5]
11887         self.assertTrue((3**d3).isEqual(DataArrayDouble([0.3333333333333333,0.5773502691896257,0.6933612743506348,0.7598356856515925]),1e-14))
11888         d4=d3.deepCpy() ; d4.abs()
11889         self.assertTrue((d4**d3).isEqual(DataArrayDouble([1.,sqrt(2.),1.4422495703074083,sqrt(2.)]),1e-14))
11890         d4**=d3
11891         self.assertTrue(d4.isEqual(DataArrayDouble([1.,sqrt(2.),1.4422495703074083,sqrt(2.)]),1e-14))
11892         pass
11893     
11894     def testSwig2Baryenter3DForCellsWithVolumeZero1(self):
11895         coo=DataArrayDouble([0.,0.,0.,1.,0.,0.,0.,1.,0.],3,3)
11896         m2=MEDCouplingUMesh("mesh",2)
11897         m2.allocateCells(0)
11898         m2.insertNextCell(NORM_POLYGON,[0,1,2])
11899         m2.setCoords(coo)
11900         m2.checkCoherency1()
11901         #
11902         coo2=DataArrayDouble([0.,0.,0.,0.,0.,0.,0.,0.,2.],3,3)
11903         m1=MEDCouplingUMesh("mesh",1)
11904         m1.allocateCells(0)
11905         m1.insertNextCell(NORM_SEG2,[0,1])
11906         m1.insertNextCell(NORM_SEG2,[1,2])
11907         m1.setCoords(coo2)
11908         m1.checkCoherency1()
11909         #
11910         m3=m2.buildExtrudedMesh(m1,0)
11911         m3.insertNextCell(NORM_POLYHED,[3,4,5,-1,8,7,6,-1,4,3,6,7,-1,5,4,7,8,-1,5,4,-1,3,5,8,6])# addition of face #4 with null surface
11912         self.assertTrue(m3.getBarycenterAndOwner().isEqual(DataArrayDouble([0.3333333333333333,0.3333333333333333,0.,0.3333333333333333,0.3333333333333333,1.,0.3333333333333333,0.3333333333333333,1.],3,3),1e-13))
11913         m4,a,b,c,d=m3.buildDescendingConnectivity()
11914         self.assertTrue(m4.getBarycenterAndOwner().isEqual(DataArrayDouble([0.3333333333333333,0.3333333333333333,0.,0.3333333333333333,0.3333333333333333,0.,0.5,0.,0.,0.5,0.5,0.,0.,0.5,0.,0.3333333333333333,0.3333333333333333,2.,0.5,0.,1.,0.5,0.5,1.,0.,0.5,1.,0.5,0.5,0.],10,3),1e-13))
11915         pass
11916
11917     def testSwigRepr1(self):
11918         d=DataArrayDouble()
11919         self.assertTrue(len(d.__repr__())<120)
11920         d.alloc(1000,0) ; self.assertTrue(len(d.__repr__())<100)
11921         for i in xrange(100):
11922             d.alloc(i,1) ; d.iota(1.1234567890123456) ; d*=1e123
11923             self.assertTrue(len(d.__repr__())<500)
11924             pass
11925         for i in xrange(50):
11926             d.alloc(i,2) ; d.rearrange(1) ; d.iota(1.1234567890123456) ; d.rearrange(2) ; d*=1e123
11927             self.assertTrue(len(d.__repr__())<500)
11928             pass
11929         d.alloc(4000,1) ; d.iota() ; self.assertTrue(len(d.__repr__())<500)
11930         for i in xrange(2,4):
11931             d.alloc(362880,1) ; d.iota() ; d.rearrange(i) ; self.assertTrue(len(d.__repr__())<500)
11932             pass
11933         d.alloc(0,9)
11934         self.assertTrue(len(d.__repr__())<120)
11935         #
11936         d=DataArrayInt()
11937         self.assertTrue(len(d.__repr__())<100)
11938         d.alloc(1000,0) ; self.assertTrue(len(d.__repr__())<100)
11939         for i in xrange(100):
11940             d.alloc(i,1) ; d.iota(123456789)
11941             self.assertTrue(len(d.__repr__())<500)
11942             pass
11943         for i in xrange(50):
11944             d.alloc(i,2) ; d.rearrange(1) ; d.iota(123456789) ; d.rearrange(2)
11945             self.assertTrue(len(d.__repr__())<500)
11946             pass
11947         d.alloc(4000,1) ; d.iota() ; self.assertTrue(len(d.__repr__())<500)
11948         for i in xrange(2,10):
11949             d.alloc(362880,1) ; d.iota() ; d.rearrange(i) ; self.assertTrue(len(d.__repr__())<500)
11950             pass
11951         d.alloc(0,9)
11952         self.assertTrue(len(d.__repr__())<100)
11953         #
11954         d=DataArrayAsciiChar()
11955         d.alloc(1000,0) ; self.assertTrue(len(d.__repr__())<100)
11956         d.alloc(2,16) ; d[:]='1234567890ABCDEF'
11957         self.assertTrue(len(d.__repr__())<500)
11958         d.alloc(2000,16) ; d[:]='1234567890ABCDEF'
11959         self.assertTrue(len(d.__repr__())<500)
11960         d.alloc(0,16) ; d[:]='1234567890ABCDEF'
11961         self.assertTrue(len(d.__repr__())<120)
11962         #
11963         d=DataArrayByte()
11964         self.assertTrue(len(d.__repr__())<100)
11965         d.alloc(1000,0) ; self.assertTrue(len(d.__repr__())<100)
11966         d.alloc(0,16) ; self.assertTrue(len(d.__repr__())<100)
11967         d.alloc(5,1) ; d.fillWithValue(127)
11968         self.assertTrue(len(d.__repr__())<200)
11969         d.alloc(1000,1) ; d.fillWithValue(127)
11970         self.assertTrue(len(d.__repr__())<500)
11971         d.alloc(1000,3) ; d.fillWithValue(127)
11972         self.assertTrue(len(d.__repr__())<500)
11973         pass
11974     
11975     def testSwig2MeshComputeIsoBarycenterOfNodesPerCell1(self):
11976         coo=DataArrayDouble([26.17509821414239,5.0374,200.,26.175098214142388,-5.0374,200.,17.450065476094927,20.1496,200.,8.725032738047464,25.187,200.,43.62516369023732,5.0374,200.,34.90013095218986,10.0748,200.,34.900130952189855,-10.0748,200.,43.625163690237315,-5.0374,200.,26.175098214142402,25.187,200.,26.175098214142395,35.2618,200.,17.45006547609493,40.2992,200.,8.725032738047469,35.2618,200.,26.17509821414239,5.0374,200.,26.175098214142388,-5.0374,200.,17.450065476094927,20.1496,200.,8.725032738047464,25.187,200.,43.62516369023732,5.0374,200.,34.90013095218986,10.0748,200.,34.900130952189855,-10.0748,200.,43.625163690237315,-5.0374,200.,26.175098214142402,25.187,200.,26.175098214142395,35.2618,200.,17.45006547609493,40.2992,200.,8.725032738047469,35.2618,200.],24,3)
11977         m=MEDCouplingUMesh.New("toto",3)
11978         m.allocateCells(0)
11979         m.insertNextCell(NORM_POLYHED,[4,5,0,1,6,7,-1,19,18,13,12,17,16,-1,5,4,16,17,-1,0,5,17,12,-1,1,0,12,13,-1,6,1,13,18,-1,7,6,18,19,-1,4,7,19,16])
11980         m.insertNextCell(NORM_POLYHED,[9,10,11,3,2,8,-1,20,14,15,23,22,21,-1,10,9,21,22,-1,11,10,22,23,-1,3,11,23,15,-1,2,3,15,14,-1,8,2,14,20,-1,9,8,20,21])
11981         m.setCoords(coo)
11982         m.checkCoherency1()
11983         #
11984         dReference=DataArrayDouble([(34.900130952189848,0.,200),(17.450065476094931,30.2244,200.)])
11985         self.assertTrue(m.computeIsoBarycenterOfNodesPerCell().isEqual(dReference,1e-12))
11986         m.getNodalConnectivity().setIJ(87,0,24)
11987         self.assertRaises(InterpKernelException,m.computeIsoBarycenterOfNodesPerCell)
11988         m.getNodalConnectivity().setIJ(87,0,-2)
11989         self.assertRaises(InterpKernelException,m.computeIsoBarycenterOfNodesPerCell)
11990         m.getNodalConnectivity().setIJ(87,0,21)# put again 21 as at the beginning
11991         #
11992         self.assertTrue(m.unPolyze())
11993         self.assertEqual([NORM_HEXGP12],m.getAllGeoTypes())
11994         self.assertTrue(m.computeIsoBarycenterOfNodesPerCell().isEqual(dReference,1e-12))
11995         m.getNodalConnectivity().setIJ(25,0,24)
11996         self.assertRaises(InterpKernelException,m.computeIsoBarycenterOfNodesPerCell)
11997         m.getNodalConnectivity().setIJ(25,0,-1)
11998         self.assertRaises(InterpKernelException,m.computeIsoBarycenterOfNodesPerCell)
11999         pass
12000
12001     def testSwig2NonRegressionBugDescHexa20(self):
12002         coo=DataArrayDouble([0.,0.,0.,1.23,0.,0.,0.615,0.,0.,0.,2.1,0.,0.615,2.1,0.,1.23,2.1,0.,1.23,1.05,0.,0.,1.05,0.,0.,0.,2.16,1.23,0.,2.16,1.23,2.1,2.16,0.,2.1,2.16,0.,0.,4.32,0.615,0.,4.32,1.23,0.,4.32,1.23,1.05,4.32,1.23,2.1,4.32,0.615,2.1,4.32,0.,2.1,4.32,0.,1.05,4.32],20,3)
12003         m=MEDCouplingUMesh('mesh',3)
12004         m.allocateCells(0)
12005         m.insertNextCell(NORM_HEXA20,[0,3,5,1,12,18,16,14,7,4,6,2,19,17,15,13,8,11,10,9])
12006         m.setCoords(coo)
12007         m.checkCoherency1()
12008         #
12009         a,b,c,d,e=m.buildDescendingConnectivity()
12010         m2=MEDCouplingUMesh('mesh',2)
12011         m2.allocateCells(0)
12012         m2.setCoords(coo)
12013         conn2=[[0,3,5,1,7,4,6,2],[12,14,16,18,13,15,17,19],[0,12,18,3,8,19,11,7],[3,18,16,5,11,17,10,4],[5,16,14,1,10,15,9,6],[1,14,12,0,9,13,8,2]]
12014         for i in xrange(6):
12015             m2.insertNextCell(NORM_QUAD8,conn2[i])
12016             pass
12017         self.assertTrue(m2.isEqual(a,1e-12))
12018         self.assertTrue(b.isEqual(DataArrayInt([0,1,2,3,4,5])))
12019         self.assertTrue(c.isEqual(DataArrayInt([0,6])))
12020         self.assertTrue(d.isEqual(DataArrayInt([0,0,0,0,0,0])))
12021         self.assertTrue(e.isEqual(DataArrayInt([0,1,2,3,4,5,6])))
12022         #
12023         m.convertQuadraticCellsToLinear() ; m.zipCoords()
12024         m.convertLinearCellsToQuadratic(1)
12025         #
12026         coo2=DataArrayDouble([0.,0.,0.,1.23,0.,0.,0.,2.1,0.,1.23,2.1,0.,0.,0.,4.32,1.23,0.,4.32,1.23,2.1,4.32,0.,2.1,4.32,0.,1.05,0.,0.615,2.1,0.,1.23,1.05,0.,0.615,0.,0.,0.,1.05,4.32,0.615,2.1,4.32,1.23,1.05,4.32,0.615,0.,4.32,0.,0.,2.16,0.,2.1,2.16,1.23,2.1,2.16,1.23,0.,2.16,0.615,1.05,0.,0.,1.05,2.16,0.615,2.1,2.16,1.23,1.05,2.16,0.615,0.,2.16,0.615,1.05,4.32,0.615,1.05,2.16],27,3)
12027         m3=MEDCouplingUMesh("mesh",3)
12028         m3.allocateCells(1)
12029         m3.insertNextCell(NORM_HEXA27,[0,2,3,1,4,7,6,5,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26])
12030         m3.setCoords(coo2)
12031         self.assertTrue(m3.isEqual(m,1e-12))
12032         #
12033         a,b,c,d,e=m.buildDescendingConnectivity()
12034         conn4=[[0,2,3,1,8,9,10,11,20],[4,5,6,7,15,14,13,12,25],[0,4,7,2,16,12,17,8,21],[2,7,6,3,17,13,18,9,22],[3,6,5,1,18,14,19,10,23],[1,5,4,0,19,15,16,11,24]]
12035         m4=MEDCouplingUMesh("mesh",2)
12036         m4.allocateCells(0)
12037         for i in xrange(6):
12038             m4.insertNextCell(NORM_QUAD9,conn4[i])
12039             pass
12040         m4.setCoords(coo2)
12041         self.assertTrue(m4.isEqual(a,1e-12))
12042         self.assertTrue(b.isEqual(DataArrayInt([0,1,2,3,4,5])))
12043         self.assertTrue(c.isEqual(DataArrayInt([0,6])))
12044         self.assertTrue(d.isEqual(DataArrayInt([0,0,0,0,0,0])))
12045         self.assertTrue(e.isEqual(DataArrayInt([0,1,2,3,4,5,6])))
12046         pass
12047     
12048     def testSwigAdvGauss(self):
12049         f=MEDCouplingFieldTemplate(ON_GAUSS_PT)
12050         f.setDiscretization(None)
12051         f.__repr__() ; f.__str__()
12052         #
12053         f=MEDCouplingFieldTemplate(ON_GAUSS_PT)
12054         d=f.getDiscretization()
12055         i=DataArrayInt() ; i.alloc(10,1) ; i.iota(1)
12056         d.setArrayOfDiscIds(i)
12057         f.__repr__() ; f.__str__()
12058         i2=d.getArrayOfDiscIds()
12059         self.assertEqual(i.__repr__(),i2.__repr__())
12060         #
12061         f=MEDCouplingFieldDouble(ON_GAUSS_PT)
12062         f.setDiscretization(None)
12063         f.__repr__() ; f.__str__()
12064         #
12065         f=MEDCouplingFieldDouble(ON_GAUSS_PT)
12066         d=f.getDiscretization()
12067         i=DataArrayInt() ; i.alloc(10,1) ; i.iota(1)
12068         d.setArrayOfDiscIds(i)
12069         f.__repr__() ; f.__str__()
12070         #
12071         gl=MEDCouplingGaussLocalization(NORM_SEG2,[0,1],[0.5],[1.])
12072         gl.setWeights([3.])
12073         gl.__repr__() ; gl.__str__()
12074         gl=MEDCouplingGaussLocalization(NORM_ERROR)
12075         gl.setWeights([3.])
12076         gl.__repr__() ; gl.__str__()
12077         pass
12078
12079     def testSwig2NonRegressionBugSubstractInPlaceDM(self):
12080         m0=MEDCouplingCMesh()
12081         arr=DataArrayDouble(5,1) ; arr.iota(0.)
12082         m0.setCoords(arr,arr)
12083         m0=m0.buildUnstructured()
12084         m00=m0[::2] ; m00.simplexize(0) ; m01=m0[1::2]
12085         m0=MEDCouplingUMesh.MergeUMeshes([m00,m01])
12086         m0.getCoords()[:]*=1/4.
12087         m0.setName("mesh")
12088         #
12089         NodeField=MEDCouplingFieldDouble(ON_NODES,ONE_TIME) ; NodeField.setTime(5.6,5,6) ; NodeField.setMesh(m0)
12090         NodeField.setName("NodeField")
12091         NodeField.fillFromAnalytic(1,"exp(-((x-1)*(x-1)+(y-1)*(y-1)))") ; NodeField.getArray().setInfoOnComponent(0,"powernode [W]")
12092         proc0=m0.getCellsInBoundingBox([(0.,0.4),(0.,0.4)],1e-10)
12093         proc1=proc0.buildComplement(m0.getNumberOfCells())
12094         #
12095         NodeField0=NodeField[proc0] ; NodeField0.getMesh().setName(m0.getName())
12096         NodeField1=NodeField[proc1] ; NodeField1.getMesh().setName(m0.getName())
12097         #
12098         NodeField_read=MEDCouplingFieldDouble.MergeFields([NodeField0,NodeField1])
12099         NodeField_read.mergeNodes(1e-10)
12100         NodeFieldCpy=NodeField.deepCpy()
12101         NodeFieldCpy.mergeNodes(1e-10)
12102         NodeField.checkCoherency()
12103         self.assertTrue(not NodeField.getArray().isUniform(0.,1e-12))
12104         NodeField.substractInPlaceDM(NodeField_read,10,1e-12)
12105         self.assertTrue(NodeField.getArray().isUniform(0.,1e-12))
12106         pass
12107
12108     def testSwigFieldOperationOpen1(self):
12109         ## MEDCouplingFieldDouble.__add__
12110         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12111         f=MEDCouplingFieldDouble(ON_CELLS)
12112         f.setMesh(m)
12113         arr=DataArrayDouble(5,2)
12114         arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
12115         f2=f.clone(True)
12116         self.assertRaises(InterpKernelException,f.__add__,2)
12117         self.assertRaises(InterpKernelException,f.__add__,range(5))
12118         self.assertRaises(InterpKernelException,f.__add__,arr)
12119         self.assertRaises(InterpKernelException,f.__add__,f2)
12120         f.setArray(DataArrayDouble())
12121         self.assertRaises(InterpKernelException,f.__add__,2)
12122         self.assertRaises(InterpKernelException,f.__add__,range(5))
12123         self.assertRaises(InterpKernelException,f.__add__,arr)
12124         self.assertRaises(InterpKernelException,f.__add__,f2)
12125         self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
12126         f.getArray().alloc(5,2)
12127         f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
12128         ff=f+2
12129         ff.checkCoherency()
12130         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(2,9),(3,10),(4,11),(5,12),(6,13)]),1e-12))
12131         ff=f+arr
12132         ff.checkCoherency()
12133         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,7),(2,10),(4,13),(6,16),(8,19)]),1e-12))
12134         self.assertRaises(InterpKernelException,f.__add__,f2)
12135         f2.setArray(arr)
12136         ff=f+f2
12137         ff.checkCoherency()
12138         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,7),(2,10),(4,13),(6,16),(8,19)]),1e-12))
12139         ff=f+[5,8]
12140         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(5,15),(6,16),(7,17),(8,18),(9,19)]),1e-12))
12141         ### MEDCouplingFieldDouble.__sub__
12142         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12143         f=MEDCouplingFieldDouble(ON_CELLS)
12144         f.setMesh(m)
12145         arr=DataArrayDouble(5,2)
12146         arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
12147         f2=f.clone(True)
12148         self.assertRaises(InterpKernelException,f.__sub__,2)
12149         self.assertRaises(InterpKernelException,f.__sub__,range(5))
12150         self.assertRaises(InterpKernelException,f.__sub__,arr)
12151         self.assertRaises(InterpKernelException,f.__sub__,f2)
12152         f.setArray(DataArrayDouble())
12153         self.assertRaises(InterpKernelException,f.__sub__,2)
12154         self.assertRaises(InterpKernelException,f.__sub__,range(5))
12155         self.assertRaises(InterpKernelException,f.__sub__,arr)
12156         self.assertRaises(InterpKernelException,f.__sub__,f2)
12157         self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
12158         f.getArray().alloc(5,2)
12159         f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
12160         ff=f-2
12161         ff.checkCoherency()
12162         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(-2,5),(-1,6),(0,7),(1,8),(2,9)]),1e-12))
12163         ff=f-arr
12164         ff.checkCoherency()
12165         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,7),(0,6),(0,5),(0,4),(0,3)]),1e-12))
12166         self.assertRaises(InterpKernelException,f.__sub__,f2)
12167         f2.setArray(arr)
12168         ff=f-f2
12169         ff.checkCoherency()
12170         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,7),(0,6),(0,5),(0,4),(0,3)]),1e-12))
12171         ff=f-[5,8]
12172         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(-5,-1),(-4,0),(-3,1),(-2,2),(-1,3)]),1e-12))
12173         ### MEDCouplingFieldDouble.__mul__
12174         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12175         f=MEDCouplingFieldDouble(ON_CELLS)
12176         f.setMesh(m)
12177         arr=DataArrayDouble(5,2)
12178         arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
12179         f2=f.clone(True)
12180         self.assertRaises(InterpKernelException,f.__mul__,2)
12181         self.assertRaises(InterpKernelException,f.__mul__,range(5))
12182         self.assertRaises(InterpKernelException,f.__mul__,arr)
12183         self.assertRaises(InterpKernelException,f.__mul__,f2)
12184         f.setArray(DataArrayDouble())
12185         self.assertRaises(InterpKernelException,f.__mul__,2)
12186         self.assertRaises(InterpKernelException,f.__mul__,range(5))
12187         self.assertRaises(InterpKernelException,f.__mul__,arr)
12188         self.assertRaises(InterpKernelException,f.__mul__,f2)
12189         self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
12190         f.getArray().alloc(5,2)
12191         f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
12192         ff=f*2
12193         ff.checkCoherency()
12194         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,14),(2,16),(4,18),(6,20),(8,22)]),1e-12))
12195         ff=f*arr
12196         ff.checkCoherency()
12197         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,0),(1,16),(4,36),(9,60),(16,88)]),1e-12))
12198         self.assertRaises(InterpKernelException,f.__mul__,f2)
12199         f2.setArray(arr)
12200         ff=f*f2
12201         ff.checkCoherency()
12202         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,0),(1,16),(4,36),(9,60),(16,88)]),1e-12))
12203         ff=f*[5,8]
12204         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,56),(5,64),(10,72),(15,80),(20,88)]),1e-12))
12205         ### MEDCouplingFieldDouble.__div__
12206         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12207         f=MEDCouplingFieldDouble(ON_CELLS)
12208         f.setMesh(m)
12209         arr=DataArrayDouble(5,2)
12210         arr[:,0]=range(1,6) ; arr[:,1]=2*arr[:,0]
12211         f2=f.clone(True)
12212         self.assertRaises(InterpKernelException,f.__div__,2)
12213         self.assertRaises(InterpKernelException,f.__div__,range(5))
12214         self.assertRaises(InterpKernelException,f.__div__,arr)
12215         self.assertRaises(InterpKernelException,f.__div__,f2)
12216         f.setArray(DataArrayDouble())
12217         self.assertRaises(InterpKernelException,f.__div__,2)
12218         self.assertRaises(InterpKernelException,f.__div__,range(5))
12219         self.assertRaises(InterpKernelException,f.__div__,arr)
12220         self.assertRaises(InterpKernelException,f.__div__,f2)
12221         self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
12222         f.getArray().alloc(5,2)
12223         f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
12224         self.assertRaises(InterpKernelException,f.__div__,0)
12225         ff=f/2
12226         ff.checkCoherency()
12227         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,3.5),(0.5,4),(1,4.5),(1.5,5),(2,5.5)]),1e-12))
12228         ff=f/arr
12229         ff.checkCoherency()
12230         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,3.5),(0.5,2),(0.6666666666666666,1.5),(0.75,1.25),(0.8,1.1)]),1e-12))
12231         self.assertRaises(InterpKernelException,f.__div__,f2)
12232         f2.setArray(arr)
12233         ff=f/f2
12234         ff.checkCoherency()
12235         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,3.5),(0.5,2),(0.6666666666666666,1.5),(0.75,1.25),(0.8,1.1)]),1e-12))
12236         ff=f/[5,8]
12237         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,0.875),(0.2,1),(0.4,1.125),(0.6,1.25),(0.8,1.375)]),1e-12))
12238         ### MEDCouplingFieldDouble.__pow__
12239         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12240         f=MEDCouplingFieldDouble(ON_CELLS)
12241         f.setMesh(m)
12242         arr=DataArrayDouble(5)
12243         arr[:]=[1,1,3,2,0]
12244         f2=f.clone(True)
12245         self.assertRaises(InterpKernelException,f.__div__,2)
12246         self.assertRaises(InterpKernelException,f.__div__,range(5))
12247         self.assertRaises(InterpKernelException,f.__div__,arr)
12248         self.assertRaises(InterpKernelException,f.__div__,f2)
12249         f.setArray(DataArrayDouble())
12250         self.assertRaises(InterpKernelException,f.__div__,2)
12251         self.assertRaises(InterpKernelException,f.__div__,range(5))
12252         self.assertRaises(InterpKernelException,f.__div__,arr)
12253         self.assertRaises(InterpKernelException,f.__div__,f2)
12254         self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
12255         f.getArray().alloc(5,1)
12256         f.getArray()[:]=range(2,7)
12257         ff=f**2
12258         ff.checkCoherency()
12259         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([4,9,16,25,36]),1e-12))
12260         ff=f**arr
12261         ff.checkCoherency()
12262         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([2,3,64,25,1]),1e-12))
12263         f2.setArray(arr)
12264         ff=f**f2
12265         ff.checkCoherency()
12266         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([2,3,64,25,1]),1e-12))
12267         ## MEDCouplingFieldDouble.__iadd__
12268         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12269         f=MEDCouplingFieldDouble(ON_CELLS)
12270         f.setMesh(m)
12271         arr=DataArrayDouble(5,2)
12272         arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
12273         f2=f.clone(True)
12274         self.assertRaises(InterpKernelException,f.__iadd__,2)
12275         self.assertRaises(InterpKernelException,f.__iadd__,range(5))
12276         self.assertRaises(InterpKernelException,f.__iadd__,arr)
12277         self.assertRaises(InterpKernelException,f.__iadd__,f2)
12278         f.setArray(DataArrayDouble())
12279         self.assertRaises(InterpKernelException,f.__iadd__,2)
12280         self.assertRaises(InterpKernelException,f.__iadd__,range(5))
12281         self.assertRaises(InterpKernelException,f.__iadd__,arr)
12282         self.assertRaises(InterpKernelException,f.__iadd__,f2)
12283         f.getArray().alloc(5,2)
12284         f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
12285         f.checkCoherency()
12286         f+=2
12287         f.checkCoherency()
12288         self.assertTrue(f.getArray().isEqual(DataArrayDouble([(2,9),(3,10),(4,11),(5,12),(6,13)]),1e-12))
12289         f+=arr
12290         f.checkCoherency()
12291         self.assertTrue(f.getArray().isEqual(DataArrayDouble([(2,9),(4,12),(6,15),(8,18),(10,21)]),1e-12))
12292         f2.setArray(arr)
12293         f+=f2
12294         f.checkCoherency()
12295         self.assertTrue(f.getArray().isEqual(DataArrayDouble([(2,9),(5,14),(8,19),(11,24),(14,29)]),1e-12))
12296         f+=[0.1,0.2]
12297         f.checkCoherency()
12298         self.assertTrue(f.getArray().isEqual(DataArrayDouble([(2.1,9.2),(5.1,14.2),(8.1,19.2),(11.1,24.2),(14.1,29.2)]),1e-12))
12299         ## MEDCouplingFieldDouble.__isub__
12300         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12301         f=MEDCouplingFieldDouble(ON_CELLS)
12302         f.setMesh(m)
12303         arr=DataArrayDouble(5,2)
12304         arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
12305         f2=f.clone(True)
12306         self.assertRaises(InterpKernelException,f.__isub__,2)
12307         self.assertRaises(InterpKernelException,f.__isub__,range(5))
12308         self.assertRaises(InterpKernelException,f.__isub__,arr)
12309         self.assertRaises(InterpKernelException,f.__isub__,f2)
12310         f.setArray(DataArrayDouble())
12311         self.assertRaises(InterpKernelException,f.__isub__,2)
12312         self.assertRaises(InterpKernelException,f.__isub__,range(5))
12313         self.assertRaises(InterpKernelException,f.__isub__,arr)
12314         self.assertRaises(InterpKernelException,f.__isub__,f2)
12315         f.getArray().alloc(5,2)
12316         f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
12317         f.checkCoherency()
12318         f-=2
12319         f.checkCoherency()
12320         self.assertTrue(f.getArray().isEqual(DataArrayDouble([(-2,5),(-1,6),(0,7),(1,8),(2,9)]),1e-12))
12321         f-=arr
12322         f.checkCoherency()
12323         self.assertTrue(f.getArray().isEqual(DataArrayDouble([(-2,5),(-2,4),(-2,3),(-2,2),(-2,1)]),1e-12))
12324         f2.setArray(arr)
12325         f-=f2
12326         f.checkCoherency()
12327         self.assertTrue(f.getArray().isEqual(DataArrayDouble([(-2,5),(-3,2),(-4,-1),(-5,-4),(-6,-7)]),1e-12))
12328         f-=[0.1,0.2]
12329         f.checkCoherency()
12330         self.assertTrue(f.getArray().isEqual(DataArrayDouble([(-2.1,4.8),(-3.1,1.8),(-4.1,-1.2),(-5.1,-4.2),(-6.1,-7.2)]),1e-12))
12331         ## MEDCouplingFieldDouble.__imul__
12332         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12333         f=MEDCouplingFieldDouble(ON_CELLS)
12334         f.setMesh(m)
12335         arr=DataArrayDouble(5,2)
12336         arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
12337         f2=f.clone(True)
12338         self.assertRaises(InterpKernelException,f.__imul__,2)
12339         self.assertRaises(InterpKernelException,f.__imul__,range(5))
12340         self.assertRaises(InterpKernelException,f.__imul__,arr)
12341         self.assertRaises(InterpKernelException,f.__imul__,f2)
12342         f.setArray(DataArrayDouble())
12343         self.assertRaises(InterpKernelException,f.__imul__,2)
12344         self.assertRaises(InterpKernelException,f.__imul__,range(5))
12345         self.assertRaises(InterpKernelException,f.__imul__,arr)
12346         self.assertRaises(InterpKernelException,f.__imul__,f2)
12347         f.getArray().alloc(5,2)
12348         f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
12349         f.checkCoherency()
12350         f*=2
12351         f.checkCoherency()
12352         self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,14),(2,16),(4,18),(6,20),(8,22)]),1e-12))
12353         f*=arr
12354         f.checkCoherency()
12355         self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,0),(2,32),(8,72),(18,120),(32,176)]),1e-12))
12356         f2.setArray(arr)
12357         f*=f2
12358         f.checkCoherency()
12359         self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,0),(2,64),(16,288),(54,720),(128,1408)]),1e-12))
12360         f*=[0.1,0.2]
12361         f.checkCoherency()
12362         self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,0),(0.2,12.8),(1.6,57.6),(5.4,144),(12.8,281.6)]),1e-12))
12363         ## MEDCouplingFieldDouble.__idiv__
12364         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12365         f=MEDCouplingFieldDouble(ON_CELLS)
12366         f.setMesh(m)
12367         arr=DataArrayDouble(5,2)
12368         arr[:,0]=range(1,6) ; arr[:,1]=2*arr[:,0]
12369         f2=f.clone(True)
12370         self.assertRaises(InterpKernelException,f.__idiv__,2)
12371         self.assertRaises(InterpKernelException,f.__idiv__,range(5))
12372         self.assertRaises(InterpKernelException,f.__idiv__,arr)
12373         self.assertRaises(InterpKernelException,f.__idiv__,f2)
12374         f.setArray(DataArrayDouble())
12375         self.assertRaises(InterpKernelException,f.__idiv__,2)
12376         self.assertRaises(InterpKernelException,f.__idiv__,range(5))
12377         self.assertRaises(InterpKernelException,f.__idiv__,arr)
12378         self.assertRaises(InterpKernelException,f.__idiv__,f2)
12379         f.getArray().alloc(5,2)
12380         f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
12381         f.checkCoherency()
12382         f/=2
12383         f.checkCoherency()
12384         self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,3.5),(0.5,4),(1,4.5),(1.5,5),(2,5.5)]),1e-12))
12385         f/=arr
12386         f.checkCoherency()
12387         self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,1.75),(0.25,1),(0.3333333333333333,0.75),(0.375,0.625),(0.4,0.55)]),1e-12))
12388         f2.setArray(arr)
12389         f/=f2
12390         f.checkCoherency()
12391         self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,0.875),(0.125,0.25),(0.1111111111111111,0.125),(0.09375,0.078125),(0.08,0.055)]),1e-12))
12392         f/=[0.1,0.2]
12393         f.checkCoherency()
12394         self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,4.375),(1.25,1.25),(1.1111111111111111,0.625),(0.9375,0.390625),(0.8,0.275)]),1e-12))
12395         ## MEDCouplingFieldDouble.__ipow__
12396         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12397         f=MEDCouplingFieldDouble(ON_CELLS)
12398         f.setMesh(m)
12399         arr=DataArrayDouble(5,2)
12400         arr[:,0]=range(1,6) ; arr[:,1]=2*arr[:,0]
12401         f2=f.clone(True)
12402         self.assertRaises(InterpKernelException,f.__ipow__,2)
12403         self.assertRaises(InterpKernelException,f.__ipow__,range(5))
12404         self.assertRaises(InterpKernelException,f.__ipow__,arr)
12405         self.assertRaises(InterpKernelException,f.__ipow__,f2)
12406         f.setArray(DataArrayDouble())
12407         self.assertRaises(InterpKernelException,f.__ipow__,2)
12408         self.assertRaises(InterpKernelException,f.__ipow__,range(5))
12409         self.assertRaises(InterpKernelException,f.__ipow__,arr)
12410         self.assertRaises(InterpKernelException,f.__ipow__,f2)
12411         f.getArray().alloc(5,2)
12412         f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
12413         f.checkCoherency()
12414         f**=2
12415         f.checkCoherency()
12416         self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,49),(1,64),(4,81),(9,100),(16,121)]),1e-12))
12417          ## MEDCouplingFieldDouble.__radd__
12418         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12419         f=MEDCouplingFieldDouble(ON_CELLS)
12420         f.setMesh(m)
12421         arr=DataArrayDouble(5,2)
12422         arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
12423         f2=f.clone(True)
12424         self.assertRaises(InterpKernelException,f.__radd__,2)
12425         self.assertRaises(InterpKernelException,f.__radd__,range(5))
12426         self.assertRaises(InterpKernelException,f.__radd__,arr)
12427         self.assertRaises(InterpKernelException,f.__radd__,f2)
12428         f.setArray(DataArrayDouble())
12429         self.assertRaises(InterpKernelException,f.__radd__,2)
12430         self.assertRaises(InterpKernelException,f.__radd__,range(5))
12431         self.assertRaises(InterpKernelException,f.__radd__,arr)
12432         self.assertRaises(InterpKernelException,f.__radd__,f2)
12433         self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
12434         f.getArray().alloc(5,2)
12435         f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
12436         ff=2+f
12437         ff.checkCoherency()
12438         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(2,9),(3,10),(4,11),(5,12),(6,13)]),1e-12))
12439         ff=arr+f
12440         ff.checkCoherency()
12441         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,7),(2,10),(4,13),(6,16),(8,19)]),1e-12))
12442         self.assertRaises(InterpKernelException,f.__radd__,f2)
12443         ff=[5,8]+f
12444         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(5,15),(6,16),(7,17),(8,18),(9,19)]),1e-12))
12445         ### MEDCouplingFieldDouble.__rsub__
12446         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12447         f=MEDCouplingFieldDouble(ON_CELLS)
12448         f.setMesh(m)
12449         arr=DataArrayDouble(5,2)
12450         arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
12451         f2=f.clone(True)
12452         self.assertRaises(InterpKernelException,f.__rsub__,2)
12453         self.assertRaises(InterpKernelException,f.__rsub__,range(5))
12454         self.assertRaises(InterpKernelException,f.__rsub__,arr)
12455         self.assertRaises(InterpKernelException,f.__rsub__,f2)
12456         f.setArray(DataArrayDouble())
12457         self.assertRaises(InterpKernelException,f.__rsub__,2)
12458         self.assertRaises(InterpKernelException,f.__rsub__,range(5))
12459         self.assertRaises(InterpKernelException,f.__rsub__,arr)
12460         self.assertRaises(InterpKernelException,f.__rsub__,f2)
12461         self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
12462         f.getArray().alloc(5,2)
12463         f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
12464         ff=2-f
12465         ff.checkCoherency()
12466         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(2,-5),(1,-6),(0,-7),(-1,-8),(-2,-9)]),1e-12))
12467         ff=arr-f
12468         ff.checkCoherency()
12469         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,-7),(0,-6),(0,-5),(0,-4),(0,-3)]),1e-12))
12470         self.assertRaises(InterpKernelException,f.__rsub__,f2)
12471         ### MEDCouplingFieldDouble.__rmul__
12472         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12473         f=MEDCouplingFieldDouble(ON_CELLS)
12474         f.setMesh(m)
12475         arr=DataArrayDouble(5,2)
12476         arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
12477         f2=f.clone(True)
12478         self.assertRaises(InterpKernelException,f.__rmul__,2)
12479         self.assertRaises(InterpKernelException,f.__rmul__,range(5))
12480         self.assertRaises(InterpKernelException,f.__rmul__,arr)
12481         self.assertRaises(InterpKernelException,f.__rmul__,f2)
12482         f.setArray(DataArrayDouble())
12483         self.assertRaises(InterpKernelException,f.__rmul__,2)
12484         self.assertRaises(InterpKernelException,f.__rmul__,range(5))
12485         self.assertRaises(InterpKernelException,f.__rmul__,arr)
12486         self.assertRaises(InterpKernelException,f.__rmul__,f2)
12487         self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
12488         f.getArray().alloc(5,2)
12489         f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
12490         ff=2*f
12491         ff.checkCoherency()
12492         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,14),(2,16),(4,18),(6,20),(8,22)]),1e-12))
12493         ff=arr*f
12494         ff.checkCoherency()
12495         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,0),(1,16),(4,36),(9,60),(16,88)]),1e-12))
12496         self.assertRaises(InterpKernelException,f.__rmul__,f2)
12497         ff=f*[5,8]
12498         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,56),(5,64),(10,72),(15,80),(20,88)]),1e-12))
12499         ### MEDCouplingFieldDouble.__rdiv__
12500         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12501         f=MEDCouplingFieldDouble(ON_CELLS)
12502         f.setMesh(m)
12503         arr=DataArrayDouble(5,2)
12504         arr[:,0]=range(1,6) ; arr[:,1]=2*arr[:,0]
12505         f2=f.clone(True)
12506         self.assertRaises(InterpKernelException,f.__rdiv__,2)
12507         self.assertRaises(InterpKernelException,f.__rdiv__,range(5))
12508         self.assertRaises(InterpKernelException,f.__rdiv__,arr)
12509         self.assertRaises(InterpKernelException,f.__rdiv__,f2)
12510         f.setArray(DataArrayDouble())
12511         self.assertRaises(InterpKernelException,f.__rdiv__,2)
12512         self.assertRaises(InterpKernelException,f.__rdiv__,range(5))
12513         self.assertRaises(InterpKernelException,f.__rdiv__,arr)
12514         self.assertRaises(InterpKernelException,f.__rdiv__,f2)
12515         self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
12516         f.getArray().alloc(5,2)
12517         f.getArray()[:,0]=range(1,6) ; f.getArray()[:,1]=f.getArray()[:,0]+7
12518         ff=2/f
12519         ff.checkCoherency()
12520         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(2,0.25),(1,0.22222222222222221),(0.66666666666666663,0.20000000000000001),(0.5,0.18181818181818182),(0.40000000000000002,0.16666666666666666)]),1e-12))
12521         ff=arr/f
12522         ff.checkCoherency()
12523         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(1,0.25),(1,0.44444444444444442),(1,0.59999999999999998),(1,0.72727272727272729),(1,0.83333333333333337)]),1e-12))
12524         self.assertRaises(InterpKernelException,f.__rdiv__,f2)
12525         pass
12526     
12527     def testSwig2FieldDoubleBuildSubPartRange1(self):
12528         #ON_CELLS
12529         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12530         f=MEDCouplingFieldDouble(ON_CELLS)
12531         f.setMesh(m)
12532         arr=DataArrayDouble(5,2) ; arr[:,0]=range(7,12) ; arr[:,1]=100+arr[:,0]
12533         f.setArray(arr)
12534         f.checkCoherency()
12535         ff=f[1:-1:2]
12536         ff.checkCoherency()
12537         self.assertTrue((m.buildPartOfMySelf([1,3],True)).isEqual(ff.getMesh(),1e-12))
12538         self.assertTrue(9,ff.getMesh().getNumberOfNodes())
12539         self.assertTrue(2,ff.getMesh().getNumberOfCells())
12540         self.assertTrue(ff.getArray().isEqual(arr[[1,3]],1e-12))
12541         #
12542         a,b=f.buildSubMeshDataRange(2,5,1)
12543         self.assertTrue(m.buildPartOfMySelf([2,3,4],True).isEqual(a,1e-12))
12544         self.assertEqual(b,slice(2,5,1))
12545         ff=f[2:]
12546         ff.checkCoherency()
12547         self.assertTrue((m.buildPartOfMySelf([2,3,4],True)).isEqual(ff.getMesh(),1e-12))
12548         self.assertTrue(9,ff.getMesh().getNumberOfNodes())
12549         self.assertTrue(3,ff.getMesh().getNumberOfCells())
12550         self.assertTrue(ff.getArray().isEqual(arr[[2,3,4]],1e-12))
12551         #
12552         ff=f[-2:0:-1]
12553         ff.checkCoherency()
12554         self.assertTrue((m.buildPartOfMySelf([3,2,1],True)).isEqual(ff.getMesh(),1e-12))
12555         self.assertTrue(9,ff.getMesh().getNumberOfNodes())
12556         self.assertTrue(3,ff.getMesh().getNumberOfCells())
12557         self.assertTrue(ff.getArray().isEqual(arr[[3,2,1]],1e-12))
12558         self.assertTrue(f[-2:0:-1,1].getArray().isEqual(arr[[3,2,1],1],1e-12))
12559         #ON_NODES
12560         f=MEDCouplingFieldDouble(ON_NODES)
12561         f.setMesh(m)
12562         arr=DataArrayDouble(9,2) ; arr[:,0]=range(7,16) ; arr[:,1]=100+arr[:,0]
12563         f.setArray(arr)
12564         f.checkCoherency()
12565         ff=f[1:-1:2]
12566         ff.checkCoherency()
12567         self.assertTrue((m.buildPartOfMySelf([1,3],False)).isEqual(ff.getMesh(),1e-12))
12568         self.assertTrue(6,ff.getMesh().getNumberOfNodes())
12569         self.assertTrue(2,ff.getMesh().getNumberOfCells())
12570         self.assertTrue(ff.getArray().isEqual(arr[[1,2,3,4,6,7]],1e-12))
12571         #
12572         m2=m.buildPartRange(2,5,1)
12573         self.assertTrue(m.buildPartOfMySelf([2,3,4],True).isEqual(m2,1e-12))
12574         m2,b=m.buildPartRangeAndReduceNodes(2,5,1)
12575         self.assertTrue(m.buildPartOfMySelf([2,3,4],False).isEqual(m2,1e-12))
12576         self.assertTrue(b.isEqual(DataArrayInt([-1,-1,0,1,2,3,4,5,6])))
12577         a,b=f.buildSubMeshDataRange(2,5,1)
12578         self.assertTrue(m.buildPartOfMySelf([2,3,4],False).isEqual(a,1e-12))
12579         self.assertTrue(b.isEqual(DataArrayInt([2,3,4,5,6,7,8])))
12580         ff=f[2:]
12581         ff.checkCoherency()
12582         self.assertTrue((m.buildPartOfMySelf([2,3,4],False)).isEqual(ff.getMesh(),1e-12))
12583         self.assertTrue(7,ff.getMesh().getNumberOfNodes())
12584         self.assertTrue(3,ff.getMesh().getNumberOfCells())
12585         self.assertTrue(ff.getArray().isEqual(arr[[2,3,4,5,6,7,8]],1e-12))
12586         #
12587         ff=f[-2:0:-1]
12588         ff.checkCoherency()
12589         self.assertTrue((m.buildPartOfMySelf([3,2,1],False)).isEqual(ff.getMesh(),1e-12))
12590         self.assertTrue(7,ff.getMesh().getNumberOfNodes())
12591         self.assertTrue(3,ff.getMesh().getNumberOfCells())
12592         self.assertTrue(ff.getArray().isEqual(arr[[1,2,3,4,5,6,7]],1e-12))
12593         self.assertTrue(f[-2:0:-1,1].getArray().isEqual(arr[[1,2,3,4,5,6,7],1],1e-12))
12594         #ON_GAUSS_NE
12595         f=MEDCouplingFieldDouble(ON_GAUSS_NE)
12596         f.setMesh(m)
12597         arr=DataArrayDouble(18,2) ; arr[:,0]=range(7,25) ; arr[:,1]=100+arr[:,0]
12598         f.setArray(arr)
12599         f.checkCoherency()
12600         ff=f[1:-1:2]
12601         ff.checkCoherency()
12602         self.assertTrue((m.buildPartOfMySelf([1,3],True)).isEqual(ff.getMesh(),1e-12))
12603         self.assertTrue(9,ff.getMesh().getNumberOfNodes())
12604         self.assertTrue(2,ff.getMesh().getNumberOfCells())
12605         self.assertTrue(ff.getArray().isEqual(arr[[4,5,6,10,11,12,13]],1e-12))
12606         #
12607         a,b=f.buildSubMeshDataRange(2,5,1)
12608         self.assertTrue(m.buildPartOfMySelf([2,3,4],True).isEqual(a,1e-12))
12609         self.assertEqual(b,slice(7,18,1))
12610         ff=f[2:]
12611         ff.checkCoherency()
12612         self.assertTrue((m.buildPartOfMySelf([2,3,4],True)).isEqual(ff.getMesh(),1e-12))
12613         self.assertTrue(9,ff.getMesh().getNumberOfNodes())
12614         self.assertTrue(3,ff.getMesh().getNumberOfCells())
12615         self.assertTrue(ff.getArray().isEqual(arr[[7,8,9,10,11,12,13,14,15,16,17]],1e-12))
12616         #
12617         ff=f[-2:0:-1]
12618         ff.checkCoherency()
12619         self.assertTrue((m.buildPartOfMySelf([3,2,1],True)).isEqual(ff.getMesh(),1e-12))
12620         self.assertTrue(9,ff.getMesh().getNumberOfNodes())
12621         self.assertTrue(3,ff.getMesh().getNumberOfCells())
12622         self.assertTrue(ff.getArray().isEqual(arr[[10,11,12,13,7,8,9,4,5,6]],1e-12))
12623         self.assertTrue(f[-2:0:-1,1].getArray().isEqual(arr[[10,11,12,13,7,8,9,4,5,6],1],1e-12))
12624         #ON_GAUSS_PT
12625         f=MEDCouplingFieldDouble(ON_GAUSS_PT)
12626         f.setMesh(m)
12627         f.setGaussLocalizationOnCells([0,4],[0,0,1,0,1,1,1,0],[1.1,1.1,2.2,2.2],[0.2,0.8]);
12628         f.setGaussLocalizationOnCells([3],[0,0,1,0,1,1,1,0],[1.1,1.1,2.2,2.2,3.,3.],[0.2,0.4,0.4]);
12629         f.setGaussLocalizationOnCells([1],[0,0,1,0,1,0],[1.1,1.1,2.2,2.2,3.,3.,4.,4.],[0.1,0.1,0.4,0.4]);
12630         f.setGaussLocalizationOnCells([2],[0,0,1,0,1,0],[1.1,1.1,2.2,2.2,3.,3.,4.,4.,5.,5.],[0.1,0.1,0.4,0.3,0.1]);
12631         arr=DataArrayDouble(16,2) ; arr[:,0]=range(7,23) ; arr[:,1]=100+arr[:,0]
12632         f.setArray(arr)
12633         f.checkCoherency()
12634         ff=f[1:-1:2]
12635         ff.checkCoherency()
12636         self.assertTrue((m.buildPartOfMySelf([1,3],True)).isEqual(ff.getMesh(),1e-12))
12637         self.assertTrue(9,ff.getMesh().getNumberOfNodes())
12638         self.assertTrue(2,ff.getMesh().getNumberOfCells())
12639         self.assertTrue(ff.getArray().isEqual(arr[[2,3,4,5,11,12,13]],1e-12))
12640         #
12641         a,b=f.buildSubMeshDataRange(2,5,1)
12642         self.assertTrue(m.buildPartOfMySelf([2,3,4],True).isEqual(a,1e-12))
12643         self.assertEqual(b,slice(6,16,1))
12644         ff=f[2:]
12645         ff.checkCoherency()
12646         self.assertTrue((m.buildPartOfMySelf([2,3,4],True)).isEqual(ff.getMesh(),1e-12))
12647         self.assertTrue(9,ff.getMesh().getNumberOfNodes())
12648         self.assertTrue(3,ff.getMesh().getNumberOfCells())
12649         self.assertTrue(ff.getArray().isEqual(arr[[6,7,8,9,10,11,12,13,14,15]],1e-12))
12650         #
12651         ff=f[-2:0:-1]
12652         ff.checkCoherency()
12653         self.assertTrue((m.buildPartOfMySelf([3,2,1],True)).isEqual(ff.getMesh(),1e-12))
12654         self.assertTrue(9,ff.getMesh().getNumberOfNodes())
12655         self.assertTrue(3,ff.getMesh().getNumberOfCells())
12656         self.assertTrue(ff.getArray().isEqual(arr[[11,12,13,6,7,8,9,10,2,3,4,5]],1e-12))
12657         self.assertTrue(f[-2:0:-1,0].getArray().isEqual(arr[[11,12,13,6,7,8,9,10,2,3,4,5],0],1e-12))
12658         pass
12659
12660     def testSwig2FieldDoubleApplyFuncBug1(self):
12661         f=MEDCouplingFieldDouble(ON_CELLS)
12662         f.setMesh(MEDCouplingDataForTest.build2DTargetMesh_1())
12663         f.applyFunc(3,700.)
12664         f.checkCoherency()
12665         self.assertEqual(3,f.getArray().getNumberOfComponents())
12666         f.getArray().rearrange(1)
12667         self.assertTrue(f.getArray().isUniform(700.,1e-10))
12668         f.getArray().rearrange(3)
12669         f.checkCoherency()
12670         f.applyFunc(4,800.)
12671         f.checkCoherency()
12672         self.assertEqual(4,f.getArray().getNumberOfComponents())
12673         f.getArray().rearrange(1)
12674         self.assertTrue(f.getArray().isUniform(800.,1e-10))
12675         f.getArray().rearrange(4)
12676         f.checkCoherency()
12677         pass
12678
12679     def testSwig2ComputeTupleIdsNearTupleBug1(self):
12680         coords=[1.1,0.0, 1.1,0.0 ];
12681         coordsArr=DataArrayDouble(coords,2,2);
12682         mesh=MEDCouplingUMesh();
12683         mesh.setCoords(coordsArr);
12684         points=[1.1, 0.002]
12685         c,cI=mesh.getNodeIdsNearPoints(points,0.00185);
12686         self.assertTrue(c.isEqual(DataArrayInt([])))
12687         self.assertTrue(cI.isEqual(DataArrayInt([0,0])))
12688         c,cI=mesh.getNodeIdsNearPoints(points,0.00200000000000001);
12689         self.assertTrue(c.isEqual(DataArrayInt([0,1])))
12690         self.assertTrue(cI.isEqual(DataArrayInt([0,2])))
12691         pass
12692
12693     def testSwig2NonRegressionBugChangeUnderlyingWithZeroCells(self):
12694         coords1=[0.,1.,2.,3.]
12695         coords2=[2.,1.,0.,3.] #0 <==> #2
12696         # mesh 1
12697         mesh1=MEDCouplingUMesh.New();
12698         coordsArr=DataArrayDouble.New(coords1,4,1);
12699         mesh1.setCoords(coordsArr);
12700         mesh1.setMeshDimension(0);
12701         mesh1.allocateCells(0);
12702         mesh1.finishInsertingCells();
12703         # mesh 2
12704         mesh2=mesh1.deepCpy();
12705         coordsArr=DataArrayDouble.New(coords2,4,1);
12706         mesh2.setCoords(coordsArr);
12707         field = mesh1.fillFromAnalytic(ON_NODES,1,"x")
12708         field.checkCoherency()
12709         levOfCheck = 10
12710         field.changeUnderlyingMesh( mesh2, levOfCheck, 1e-13, 0 )
12711         self.assertTrue( field.getArray().getValues() == coords2 )
12712         pass
12713
12714     def testSwig2UMeshDistanceToMesh2(self):
12715         sz=5
12716         m=MEDCouplingCMesh()
12717         arr=DataArrayDouble(sz+1) ; arr.iota() ; arr/=sz
12718         m.setCoords(arr,arr,arr)
12719         m=m.buildUnstructured()
12720         m1=m.computeSkin()
12721         m1.zipCoords()
12722         c=m1.getCoords()[:]
12723         d=2*(c-[0.5,0.5,0.5])+[0.5,0.5,0.5]
12724         time_deb = datetime.now()
12725         #print "go.."
12726         a,b=m1.distanceToPoints(d)
12727         #print 'time spent in distanceToPoints %s ' %str(datetime.now() - time_deb)
12728         time_deb = datetime.now()
12729         a1=DataArrayDouble(len(d))
12730         b1=DataArrayInt(len(d))
12731         m1s=[m1[i] for i in xrange(m1.getNumberOfCells())]
12732         for j,pt in enumerate(d):
12733             eter=1e308
12734             fter=-1
12735             for i,miter in enumerate(m1s):
12736                 e,f=miter.distanceToPoint(pt)
12737                 self.assertEqual(0,f)
12738                 if e<eter:
12739                     eter=e ; fter=i
12740                     pass
12741                 pass
12742             a1[j]=eter
12743             b1[j]=fter
12744             pass
12745         #print 'time spent in naive distanceToPoints  %s ' %str(datetime.now() - time_deb)
12746         self.assertTrue(a.isEqual(a1,1e-12))
12747         self.assertTrue(b.isEqual(b1))
12748         self.assertTrue(a.isEqual(DataArrayDouble([0.8660254037844386,0.714142842854285,0.7071067811865476,0.7071067811865476,0.714142842854285,0.8660254037844386,0.714142842854285,0.5196152422706632,0.5099019513592785,0.5099019513592785,0.5196152422706632,0.714142842854285,0.7071067811865475,0.5099019513592785,0.5,0.5,0.5099019513592785,0.7071067811865476,0.7071067811865475,0.5099019513592785,0.5,0.5,0.5099019513592785,0.7071067811865476,0.714142842854285,0.5196152422706632,0.5099019513592785,0.5099019513592785,0.5196152422706632,0.714142842854285,0.8660254037844386,0.714142842854285,0.7071067811865476,0.7071067811865476,0.714142842854285,0.8660254037844386,0.714142842854285,0.5196152422706632,0.5099019513592785,0.5099019513592785,0.5196152422706631,0.714142842854285,0.5196152422706631,0.5196152422706632,0.5099019513592784,0.5099019513592785,0.5099019513592784,0.5099019513592785,0.5196152422706631,0.5196152422706632,0.714142842854285,0.5196152422706632,0.5099019513592785,0.5099019513592785,0.5196152422706632,0.714142842854285,0.7071067811865475,0.5099019513592785,0.5,0.5,0.5099019513592784,0.7071067811865475,0.5099019513592784,0.5099019513592785,0.5,0.5,0.5,0.5,0.5099019513592785,0.5099019513592785,0.7071067811865476,0.5099019513592785,0.5,0.5,0.5099019513592785,0.7071067811865476,0.7071067811865475,0.5099019513592785,0.5,0.5,0.5099019513592784,0.7071067811865475,0.5099019513592784,0.5099019513592785,0.5,0.5,0.5,0.5,0.5099019513592785,0.5099019513592785,0.7071067811865476,0.5099019513592785,0.5,0.5,0.5099019513592785,0.7071067811865476,0.714142842854285,0.5196152422706632,0.5099019513592785,0.5099019513592785,0.5196152422706631,0.714142842854285,0.5196152422706631,0.5196152422706632,0.5099019513592784,0.5099019513592785,0.5099019513592784,0.5099019513592785,0.5196152422706631,0.5196152422706632,0.714142842854285,0.5196152422706632,0.5099019513592785,0.5099019513592785,0.5196152422706632,0.714142842854285,0.8660254037844386,0.714142842854285,0.7071067811865476,0.7071067811865476,0.714142842854285,0.8660254037844386,0.714142842854285,0.5196152422706632,0.5099019513592785,0.5099019513592785,0.5196152422706632,0.714142842854285,0.7071067811865475,0.5099019513592785,0.5,0.5,0.5099019513592785,0.7071067811865476,0.7071067811865475,0.5099019513592785,0.5,0.5,0.5099019513592785,0.7071067811865476,0.714142842854285,0.5196152422706632,0.5099019513592785,0.5099019513592785,0.5196152422706632,0.714142842854285,0.8660254037844386,0.714142842854285,0.7071067811865476,0.7071067811865476,0.714142842854285,0.8660254037844386]),1e-12))
12749         self.assertTrue(b.isEqual(DataArrayInt([0,0,3,7,9,9,0,0,3,7,9,9,12,12,14,16,17,17,26,26,28,30,31,31,33,33,36,40,42,42,33,33,36,40,42,42,0,0,3,7,11,9,0,9,12,17,26,31,33,42,33,33,36,40,42,42,45,45,47,49,51,51,45,50,52,53,56,57,58,63,58,58,60,62,63,63,85,85,87,89,91,91,85,90,92,93,96,97,98,103,98,98,100,102,103,103,105,105,108,112,116,114,105,114,117,122,131,136,138,147,138,138,141,145,147,147,105,105,108,112,114,114,105,105,108,112,114,114,117,117,119,121,122,122,131,131,133,135,136,136,138,138,141,145,147,147,138,138,141,145,147,147])))
12750         pass
12751
12752     def testSwig2NonRegressionBugDistance1(self):
12753         pt=DataArrayDouble([(8.8452994616207476,3.1547005383792515,3.1547005383792515)])
12754         coo=DataArrayDouble([(8,0,0),(8,0,8),(8,8,8),(8,8,0),(16,0,0),(16,0,8),(16,8,8),(16,8,0),(8,0,4),(8,4,8),(8,8,4),(8,4,0),(16,0,4),(16,4,8),(16,8,4),(16,4,0),(12,0,0),(12,0,8),(12,8,8),(12,8,0),(8,4,4),(16,4,4),(12,0,4),(12,4,8),(12,8,4),(12,4,0)])
12755         conn=DataArrayInt([4,15,21,12,4,16,25,15,12,22,16,4,0,8,20,11,16,0,11,25,22,8,0,16,15,7,14,21,15,25,19,7,7,19,24,14,11,20,10,3,25,11,3,19,19,3,10,24,12,21,13,5,13,23,17,5,5,17,22,12,8,1,9,20,23,9,1,17,17,1,8,22,21,14,6,13,14,24,18,6 ,6,18,23,13,20,9,2,10,24,10,2,18,18,2,9,23])
12756         m=MEDCouplingUMesh("mesh",2)
12757         m.setCoords(coo)
12758         m.allocateCells()
12759         for i in xrange(24):
12760             m.insertNextCell(NORM_QUAD4,conn[4*i:4*i+4])
12761             pass
12762         m.checkCoherency2()
12763         m0=m[3] ; m0.zipCoords()
12764         expectedDist=0.8452994616207476
12765         a,b=m0.distanceToPoint(pt)
12766         self.assertAlmostEqual(expectedDist,a,14)
12767         self.assertEqual(0,b)
12768         #
12769         a,b=m.distanceToPoint(pt)
12770         self.assertAlmostEqual(expectedDist,a,14)
12771         self.assertEqual(3,b)
12772         #
12773         fd=MEDCouplingFieldDiscretization.New(ON_CELLS)
12774         self.assertEqual(24,fd.getNumberOfTuples(m))
12775         fd=MEDCouplingFieldDiscretization.New(ON_NODES)
12776         self.assertEqual(26,fd.getNumberOfTuples(m))
12777         pass
12778
12779     def testSwig2AreaBarySeg3Quad8Tri6QPolyg(self):
12780         #QUAD8 representing a circle of center zeBary and radius zeRadius
12781         zeBary=[5,6]
12782         zeRadius=3
12783         d=DataArrayDouble(8,2)
12784         d[:,0]=zeRadius
12785         d[:,1]=[87,-100,-170,110,5,-130,175,95] # angle in degree
12786         d[:,1]*=pi/180. # angle in radian
12787         d=d.fromPolarToCart()
12788         d+=zeBary
12789         m=MEDCouplingUMesh("quad8",2) ; m.allocateCells() ; m.insertNextCell(NORM_QUAD8,range(8)) ; m.setCoords(d)
12790         self.assertTrue(m.getBarycenterAndOwner().isEqual(DataArrayDouble(zeBary,1,2),1e-13))
12791         self.assertAlmostEqual(float(m.getMeasureField(False).getArray()),pi*zeRadius*zeRadius,12)
12792         tri32D=m.buildDescendingConnectivity()[0][0] ; tri32D.zipCoords()
12793         # spaceDim=3 QUAD8 becomes QUAD4 ... for the moment
12794         m.setCoords(m.getCoords().changeNbOfComponents(3,0.))
12795         m2=m.deepCpy()
12796         m2.convertQuadraticCellsToLinear()
12797         self.assertAlmostEqual(float(m.getMeasureField(False).getArray()),float(m2.getMeasureField(False).getArray()),12)
12798         self.assertTrue(m.getBarycenterAndOwner().isEqual(m2.getBarycenterAndOwner(),1e-13))
12799         #TRI6 representing a circle of center zeBary and radius zeRadius
12800         zeBary=[5,6]
12801         zeRadius=3
12802         d=DataArrayDouble(6,2)
12803         d[:,0]=zeRadius
12804         d[:,1]=[87,-100,110,5,175,95] # angle in degree
12805         d[:,1]*=pi/180. # angle in radian
12806         d=d.fromPolarToCart()
12807         d+=zeBary
12808         m=MEDCouplingUMesh("tri6",2) ; m.allocateCells() ; m.insertNextCell(NORM_TRI6,range(6)) ; m.setCoords(d)
12809         self.assertTrue(m.getBarycenterAndOwner().isEqual(DataArrayDouble(zeBary,1,2),1e-13))
12810         self.assertAlmostEqual(float(m.getMeasureField(False).getArray()),pi*zeRadius*zeRadius,12)
12811         # spaceDim=3 TRI6 becomes TRI3 ... for the moment
12812         m.setCoords(m.getCoords().changeNbOfComponents(3,0.))
12813         m2=m.deepCpy()
12814         m2.convertQuadraticCellsToLinear()
12815         self.assertAlmostEqual(float(m.getMeasureField(False).getArray()),float(m2.getMeasureField(False).getArray()),12)
12816         self.assertTrue(m.getBarycenterAndOwner().isEqual(m2.getBarycenterAndOwner(),1e-13))
12817         # QPOLYG representing a circle of center zeBary and radius zeRadius
12818         zeBary=[5,6]
12819         zeRadius=3
12820         d=DataArrayDouble(10,2)
12821         d[:,0]=zeRadius
12822         d[:,1]=[87,-80,-100,-170,110,5,-90,-130,175,95] # angle in degree
12823         d[:,1]*=pi/180. # angle in radian
12824         d=d.fromPolarToCart()
12825         d+=zeBary
12826         m=MEDCouplingUMesh("qpolyg",2) ; m.allocateCells() ; m.insertNextCell(NORM_QPOLYG,range(10)) ; m.setCoords(d)
12827         self.assertTrue(m.getBarycenterAndOwner().isEqual(DataArrayDouble(zeBary,1,2),1e-13))
12828         self.assertAlmostEqual(float(m.getMeasureField(False).getArray()),pi*zeRadius*zeRadius,12)
12829         # spaceDim=3 QPOLYG becomes POLYG ... for the moment
12830         m.setCoords(m.getCoords().changeNbOfComponents(3,0.))
12831         m2=m.deepCpy()
12832         m2.convertQuadraticCellsToLinear() ; m2.checkCoherency2()
12833         self.assertTrue(m2.getAllGeoTypes()==[NORM_POLYGON] and m2.getNodalConnectivity().getValues()==[5,0,1,2,3,4])
12834         self.assertAlmostEqual(float(m.getMeasureField(False).getArray()),float(m2.getMeasureField(False).getArray()),12)
12835         self.assertTrue(m.getBarycenterAndOwner().isEqual(m2.getBarycenterAndOwner(),1e-13))
12836         # TRI3
12837         self.assertAlmostEqual(float(tri32D.getMeasureField(False).getArray()),(87+100)*pi/180*zeRadius,13)
12838         exp=DataArrayDouble(1,2) ; exp[:,0]=3 ; exp[:,1]=(87-100)/2. ; exp[:,1]*=pi/180. ;  exp=exp.fromPolarToCart() ; exp+=DataArrayDouble([5,6],1,2)
12839         self.assertTrue(tri32D.getBarycenterAndOwner().isEqual(exp,1e-12))
12840         # spaceDim=3 TRI3 becomes TRI2 ... for the moment
12841         tri32D.changeSpaceDimension(3)
12842         tri2=tri32D.deepCpy() ; tri2.convertQuadraticCellsToLinear()
12843         self.assertAlmostEqual(float(tri32D.getMeasureField(False).getArray()),float(tri2.getMeasureField(False).getArray()),13)
12844         self.assertTrue(tri32D.getBarycenterAndOwner().isEqual(tri2.getBarycenterAndOwner(),1e-12))
12845         tri32D.changeSpaceDimension(1)
12846         self.assertAlmostEqual(float(tri32D.getMeasureField(False).getArray()),-0.67795240172962323,12)
12847         pass
12848
12849     # this bug 5/6/2013 is swig specific
12850     def testSwigNonRegressionBugRotate3D1(self):
12851         m=MEDCouplingUMesh.New()
12852         dataArray=DataArrayDouble.New(100,3)
12853         dataArray[:]=0.
12854         dataArray[0]=[0.,1,3]
12855         m.setCoords(dataArray[0])
12856         m1=m.deepCpy()
12857         m.rotate([0.,0.,3.],[1.,0.,0.],0.5*pi)
12858         self.assertTrue(m.getCoords().isEqual(DataArrayDouble([0.,0.,4.],1,3),1e-15))
12859         #
12860         d1=DataArrayDouble([0.,0.,3.],1,3) ; d2=DataArrayDouble([1.,0.,0.],1,3)
12861         pts=[[0.,0.,3.],[(0.,0.,3.)],DataArrayDouble([0.,0.,3.],1,3),list(d1)[0]]
12862         vec=[[1.,0.,0.],[(1.,0.,0.)],DataArrayDouble([1.,0.,0.],1,3),list(d2)[0]]
12863         for p in pts:
12864             for v in vec:
12865                 m2=m1.deepCpy()
12866                 m2.rotate(p,v,0.5*pi)
12867                 self.assertTrue(m2.getCoords().isEqual(DataArrayDouble([0.,0.,4.],1,3),1e-15))
12868                 pass
12869         pass
12870
12871     def testSwig2DataArrayCount1(self):
12872         d=DataArrayInt([])
12873         self.assertEqual(0,d.getNumberOfTuples())
12874         self.assertEqual(1,d.getNumberOfComponents())
12875         self.assertEqual(0,d.count(0))
12876         self.assertEqual(0,d.count(1))
12877         self.assertEqual(0,d.count(-1))
12878         d=DataArrayInt([2,1,-2,-3,2,0,0,7,2,-2,3,0])
12879         self.assertEqual(12,d.getNumberOfTuples())
12880         self.assertEqual(1,d.getNumberOfComponents())
12881         self.assertEqual(3,d.count(0))
12882         self.assertEqual(1,d.count(1))
12883         self.assertEqual(0,d.count(-1))
12884         self.assertEqual(2,d.count(-2))
12885         self.assertEqual(3,d.count(2))
12886         e=d.getDifferentValues()
12887         f=DataArrayInt()
12888         for it in e:
12889             f.pushBackSilent(d.count(int(it)))
12890             pass
12891         self.assertEqual(12,f.accumulate()[0])
12892         #
12893         eps=1e-12
12894         d=DataArrayDouble([])
12895         self.assertEqual(0,d.getNumberOfTuples())
12896         self.assertEqual(1,d.getNumberOfComponents())
12897         self.assertEqual(0,d.count(0,eps))
12898         self.assertEqual(0,d.count(1,eps))
12899         self.assertEqual(0,d.count(-1,eps))
12900         d=DataArrayDouble([2,1,-2,-3,2,0,eps/10,7,2+eps/10,-2,3,0])
12901         self.assertEqual(12,d.getNumberOfTuples())
12902         self.assertEqual(1,d.getNumberOfComponents())
12903         self.assertEqual(3,d.count(0,eps))
12904         self.assertEqual(1,d.count(1,eps))
12905         self.assertEqual(0,d.count(-1,eps))
12906         self.assertEqual(2,d.count(-2,eps))
12907         self.assertEqual(3,d.count(2,eps))
12908         self.assertEqual(3,d.count(2,eps))
12909         self.assertEqual(2,d.count(2,eps/100))
12910         e=d.getDifferentValues(eps)
12911         f=DataArrayInt()
12912         for it in e:
12913             f.pushBackSilent(d.count(float(it),eps))
12914             pass
12915         self.assertEqual(12,f.accumulate()[0])
12916         pass
12917
12918     def testSwig2DataArrayGetSlice1(self):
12919         s=slice(2,18,1)
12920         self.assertEqual(DataArray.GetNumberOfItemGivenBESRelative(s),16)
12921         self.assertEqual(DataArray.GetNumberOfItemGivenBES(s),16)
12922         self.assertEqual(DataArray.GetSlice(s,0,4),slice(2,6,1))
12923         self.assertEqual(DataArray.GetSlice(s,1,4),slice(6,10,1))
12924         self.assertEqual(DataArray.GetSlice(s,2,4),slice(10,14,1))
12925         self.assertEqual(DataArray.GetSlice(s,3,4),slice(14,18,1))
12926         #
12927         s=slice(2,18,2)
12928         self.assertEqual(DataArray.GetNumberOfItemGivenBESRelative(s),8)
12929         self.assertEqual(DataArray.GetNumberOfItemGivenBES(s),8)
12930         self.assertEqual(DataArray.GetSlice(s,0,4),slice(2,6,2))
12931         self.assertEqual(DataArray.GetSlice(s,1,4),slice(6,10,2))
12932         self.assertEqual(DataArray.GetSlice(s,2,4),slice(10,14,2))
12933         self.assertEqual(DataArray.GetSlice(s,3,4),slice(14,18,2))
12934         #
12935         s=slice(1,18,1)
12936         self.assertEqual(DataArray.GetSlice(s,0,4),slice(1,5,1))
12937         self.assertEqual(DataArray.GetSlice(s,1,4),slice(5,9,1))
12938         self.assertEqual(DataArray.GetSlice(s,2,4),slice(9,13,1))
12939         self.assertEqual(DataArray.GetSlice(s,3,4),slice(13,18,1))# 18 not 17
12940         #
12941         s=slice(1,18,2)
12942         self.assertEqual(DataArray.GetNumberOfItemGivenBESRelative(s),9)
12943         self.assertEqual(DataArray.GetNumberOfItemGivenBES(s),9)
12944         self.assertEqual(DataArray.GetSlice(s,0,4),slice(1,5,2))
12945         self.assertEqual(DataArray.GetSlice(s,1,4),slice(5,9,2))
12946         self.assertEqual(DataArray.GetSlice(s,2,4),slice(9,13,2))
12947         self.assertEqual(DataArray.GetSlice(s,3,4),slice(13,18,2))# 18 not 17
12948         #
12949         s=slice(18,2,-1)
12950         self.assertEqual(DataArray.GetSlice(s,0,4),slice(18,14,-1))
12951         self.assertEqual(DataArray.GetSlice(s,1,4),slice(14,10,-1))
12952         self.assertEqual(DataArray.GetSlice(s,2,4),slice(10,6,-1))
12953         self.assertEqual(DataArray.GetSlice(s,3,4),slice(6,2,-1))
12954         #
12955         s=slice(18,2,-2)
12956         self.assertEqual(DataArray.GetSlice(s,0,4),slice(18,14,-2))
12957         self.assertEqual(DataArray.GetSlice(s,1,4),slice(14,10,-2))
12958         self.assertEqual(DataArray.GetSlice(s,2,4),slice(10,6,-2))
12959         self.assertEqual(DataArray.GetSlice(s,3,4),slice(6,2,-2))
12960         #
12961         s=slice(18,1,-1)
12962         self.assertEqual(DataArray.GetSlice(s,0,4),slice(18,14,-1))
12963         self.assertEqual(DataArray.GetSlice(s,1,4),slice(14,10,-1))
12964         self.assertEqual(DataArray.GetSlice(s,2,4),slice(10,6,-1))
12965         self.assertEqual(DataArray.GetSlice(s,3,4),slice(6,1,-1))# 1 not 2
12966         #
12967         s=slice(18,1,-2)
12968         self.assertEqual(DataArray.GetNumberOfItemGivenBESRelative(s),9)
12969         self.assertRaises(InterpKernelException,DataArray.GetNumberOfItemGivenBES,s)
12970         self.assertEqual(sum([DataArray.GetNumberOfItemGivenBESRelative(DataArray.GetSlice(s,i,4)) for i in xrange(4)]),DataArray.GetNumberOfItemGivenBESRelative(s))
12971         self.assertEqual(DataArray.GetSlice(s,0,4),slice(18,14,-2))
12972         self.assertEqual(DataArray.GetSlice(s,1,4),slice(14,10,-2))
12973         self.assertEqual(DataArray.GetSlice(s,2,4),slice(10,6,-2))
12974         self.assertEqual(DataArray.GetSlice(s,3,4),slice(6,1,-2))# 1 not 2
12975         self.assertRaises(InterpKernelException,DataArray.GetSlice,slice(0,None,2),0,4)
12976         #
12977         d=DataArrayInt.Range(0,18,1)
12978         s=slice(2,None,1)
12979         self.assertEqual(d.getNumberOfItemGivenBES(s),16)
12980         self.assertEqual(d.getNumberOfItemGivenBESRelative(s),16)
12981         self.assertEqual(d.getSlice(s,0,4),slice(2,6,1))
12982         self.assertEqual(d.getSlice(s,1,4),slice(6,10,1))
12983         self.assertEqual(d.getSlice(s,2,4),slice(10,14,1))
12984         self.assertEqual(d.getSlice(s,3,4),slice(14,18,1))
12985         #
12986         d=DataArrayInt.Range(0,18,1)
12987         s=slice(2,-2,1)
12988         self.assertEqual(d.getSlice(s,0,4),slice(2,5,1))
12989         self.assertEqual(d.getSlice(s,1,4),slice(5,8,1))
12990         self.assertEqual(d.getSlice(s,2,4),slice(8,11,1))
12991         self.assertEqual(d.getSlice(s,3,4),slice(11,16,1))
12992         #
12993         d=DataArrayInt.Range(0,18,1)
12994         s=slice(None,None,1)
12995         self.assertEqual(d.getSlice(s,0,4),slice(0,4,1))
12996         self.assertEqual(d.getSlice(s,1,4),slice(4,8,1))
12997         self.assertEqual(d.getSlice(s,2,4),slice(8,12,1))
12998         self.assertEqual(d.getSlice(s,3,4),slice(12,18,1))
12999         #
13000         d=DataArrayInt.Range(0,18,1)
13001         s=slice(None,2,-2)
13002         self.assertRaises(InterpKernelException,d.getNumberOfItemGivenBES,s)
13003         self.assertEqual(d.getNumberOfItemGivenBESRelative(s),8)
13004         self.assertEqual(d.getSlice(s,0,4),slice(17,13,-2))
13005         self.assertEqual(d.getSlice(s,1,4),slice(13,9,-2))
13006         self.assertEqual(d.getSlice(s,2,4),slice(9,5,-2))
13007         self.assertEqual(d.getSlice(s,3,4),slice(5,2,-2))
13008         pass
13009
13010     def testSwig2AccumulatePerChunk1(self):
13011         arr=DataArrayDouble(11) ; arr.iota()
13012         m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
13013         m=m.buildUnstructured()
13014         m0=m[::2] ; ids0=m0.simplexize(0) ; m1=m[1::2]
13015         m=MEDCouplingUMesh.MergeUMeshesOnSameCoords(m0,m1) ; m.setName("mesh")
13016         m.checkConsecutiveCellTypesForMEDFileFrmt()
13017         #
13018         formula="7-sqrt((x-5.)*(x-5.)+(y-5.)*(y-5.))"
13019         f=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f.setMesh(m)
13020         f.fillFromAnalytic(1,formula)
13021         f.setName("Field1") ; f.setTime(1.1,1,-1)
13022         f.checkCoherency()
13023         #
13024         arr=f.getArray()
13025         arr2=DataArrayDouble(len(arr),2) ; arr2[:,0]=arr
13026         arr2=DataArrayDouble(len(arr),2) ; arr2[:,0]=arr ; arr2[:,1]=2*arr
13027         f.setArray(arr2)
13028         f.checkCoherency()
13029         # here the compact code to obviously put field on cell to nodes
13030         rn,rni=f.getMesh().getReverseNodalConnectivity()
13031         arr2=f.getArray()[rn]
13032         arr4=arr2.accumulatePerChunck(rni)
13033         nbOfCellsSharingNodes=rni.deltaShiftIndex()
13034         arr4/=nbOfCellsSharingNodes.convertToDblArr()
13035         #
13036         maxNbCSN=nbOfCellsSharingNodes.getMaxValue()[0]
13037         arr3=DataArrayDouble(f.getMesh().getNumberOfNodes(),f.getArray().getNumberOfComponents()) ; arr3[:]=0.
13038         for i in xrange(1,maxNbCSN+1):
13039             ids=nbOfCellsSharingNodes.getIdsEqual(i)
13040             if len(ids)==0:
13041                 continue
13042             for j in range(i):
13043                 rni2=rni[ids] ; rni2+=j
13044                 arr3[ids]+=arr2[rni2]
13045                 pass
13046             arr3[ids]/=i
13047             pass
13048         fNode=MEDCouplingFieldDouble(ON_NODES,ONE_TIME) ; fNode.setMesh(m)
13049         fNode.setName("Field1Node") ; fNode.setTime(1.1,1,-1)
13050         fNode.setArray(arr3) ; fNode.checkCoherency()
13051         self.assertTrue(arr3.isEqual(arr4,1e-12))
13052         #
13053         d=DataArrayInt.Range(0,20,1)
13054         self.assertTrue(d.accumulatePerChunck([2,4,12]).isEqual(DataArrayInt([5,60])))
13055         #
13056         a=DataArrayDouble(12) ; a.iota() ; a.rearrange(3)
13057         b=DataArrayDouble(12) ; b.iota(20) ; b.rearrange(3)
13058         ids=DataArrayInt([])
13059         self.assertEqual(len(a[ids]),0)
13060         self.assertEqual(len(b[ids]),0)
13061         a2=a.deepCpy() ;  a2[ids]+=b[ids] ; self.assertTrue(a2.isEqual(a,1e-15))
13062         a2=a.deepCpy() ;  a2[ids]*=b[ids] ; self.assertTrue(a2.isEqual(a,1e-15))
13063         a2=a.deepCpy() ;  a2[ids]/=b[ids] ; self.assertTrue(a2.isEqual(a,1e-15))
13064         a2=a.deepCpy() ;  a2[ids]-=b[ids] ; self.assertTrue(a2.isEqual(a,1e-15))
13065         pass
13066
13067     def testSwig2CheckAndPreparePermutation1(self):
13068         a=DataArrayInt([10003,9999999,5,67])
13069         self.assertTrue(a.checkAndPreparePermutation().isEqual(DataArrayInt([2,3,0,1])))
13070         a=DataArrayInt([10003,-9999999,5,67])
13071         self.assertTrue(a.checkAndPreparePermutation().isEqual(DataArrayInt([3,0,1,2])))
13072         a=DataArrayInt([])
13073         self.assertTrue(a.checkAndPreparePermutation().isEqual(DataArrayInt([])))
13074         a=DataArrayInt([])
13075         a.iota();
13076         self.assertTrue(a.isEqual(DataArrayInt([])))
13077         pass
13078
13079     def testSwig21SGTUMesh1(self):
13080         m=MEDCoupling1GTUMesh.New("m",NORM_PENTA6)
13081         m.__repr__() ; m.__str__()
13082         self.assertTrue(isinstance(m,MEDCoupling1SGTUMesh))
13083         m.setCoords(DataArrayDouble(20,3))
13084         m.allocateCells()
13085         m.__repr__() ; m.__str__()
13086         m.insertNextCell([0,1,2,5,7,2])
13087         self.assertEqual(1,m.getNumberOfCells())
13088         self.assertTrue(DataArrayInt([6]).isEqual(m.computeNbOfNodesPerCell()))
13089         self.assertTrue(DataArrayInt([5]).isEqual(m.computeNbOfFacesPerCell()))
13090         m.__repr__() ; m.__str__()
13091         m.checkCoherency()
13092         m.checkCoherency2()
13093         #
13094         cm=MEDCouplingCMesh() ; cm.setName("m")
13095         arr0=DataArrayDouble(6) ; arr0.iota()
13096         arr1=DataArrayDouble([0,1])
13097         cm.setCoords(arr0,arr1,arr1) ; um=cm.buildUnstructured()
13098         #
13099         m=MEDCoupling1SGTUMesh("m",NORM_QUAD4)
13100         mem_m=m.getHeapMemorySize()
13101         m.allocateCells(5)
13102         self.assertIn(m.getHeapMemorySize()-mem_m,xrange(5*4*4,5*4*4+32))
13103         self.assertEqual(m.getNodalConnectivity().getNbOfElemAllocated(),20)
13104         m.setCoords(um.getCoords())
13105         m.insertNextCell([1,0,6,7])
13106         self.assertEqual(1,m.getNumberOfCells())
13107         m.insertNextCell([2,1,7,8])
13108         m.insertNextCell([3,2,8,9])
13109         m.insertNextCell([4,3,9,10])
13110         m.insertNextCell([5,4,10,11])
13111         self.assertEqual(5,m.getNumberOfCells())
13112         self.assertRaises(InterpKernelException,m.insertNextCell,[0,6,7])
13113         self.assertRaises(InterpKernelException,m.insertNextCell,[0,6,7,1,2])
13114         self.assertEqual(m.getNodalConnectivity().getNbOfElemAllocated(),20)
13115         f=m.getMeasureField(ON_CELLS)
13116         self.assertEqual(f.getMesh().getHiddenCppPointer(),m.getHiddenCppPointer())
13117         self.assertTrue(f.getArray().isUniform(1,1e-14))
13118         self.assertEqual(m.getType(),10)
13119         self.assertEqual(m.getCellModelEnum(),NORM_QUAD4)
13120         mo=MEDCoupling1SGTUMesh("m",NORM_QUAD4) ; mo.setCoords(m.getCoords())
13121         mo.setNodalConnectivity(DataArrayInt([1,0,6,7,2,1,7,8,3,2,8,9,4,3,9,10,5,4,10,11]))
13122         self.assertTrue(m.isEqual(mo,1e-12))
13123         #
13124         mo2=MEDCoupling1SGTUMesh.Merge1SGTUMeshesOnSameCoords([m[[0,1]],m[[2]],m[[3,4]]])
13125         mo2.setName(m.getName())
13126         self.assertTrue(m.isEqual(mo2,1e-12))
13127         #
13128         mp0=m[[0]] ; mp0.zipCoords() ; mp1=m[2] ; mp1.zipCoords() ; mp2=m[4] ; mp2.zipCoords()
13129         mo3=MEDCoupling1SGTUMesh.Merge1SGTUMeshes([mp0,mp1,mp2])
13130         self.assertTrue(isinstance(mo3,MEDCoupling1SGTUMesh))
13131         mo3.setName(m.getName())
13132         m_ref=m[(0,2,4)] ; m_ref.zipCoords()
13133         m_ref.tryToShareSameCoordsPermute(mo3,1e-12)
13134         self.assertTrue(m_ref.isEqual(mo3,1e-12))
13135         #
13136         m1=um.buildDescendingConnectivity()[0]
13137         ids=m1.getCellIdsFullyIncludedInNodeIds(DataArrayInt.Range(0,12,1))
13138         m1=m1[ids]
13139         m1c=m1.convertIntoSingleGeoTypeMesh()
13140         self.assertTrue(isinstance(m1c,MEDCoupling1SGTUMesh))
13141         self.assertEqual(m1c.getCoords().getHiddenCppPointer(),m.getCoords().getHiddenCppPointer())
13142         m1c.checkCoherency2()
13143         self.assertTrue(m1c.getNodalConnectivity().isEqual(DataArrayInt([1,0,6,7,2,1,7,8,3,2,8,9,4,3,9,10,5,4,10,11])))
13144         self.assertEqual(20,m1c.getNodalConnectivityLength())
13145         self.assertTrue(m.isEqual(m1c,1e-12))
13146         m.getNodalConnectivity().setIJ(1,0,1)
13147         self.assertTrue(not m.isEqual(m1c,1e-12))
13148         m.getNodalConnectivity().setIJ(1,0,0)
13149         self.assertTrue(m.isEqual(m1c,1e-12))
13150         m1c.setCoords(m.getCoords().deepCpy())
13151         self.assertTrue(m.isEqual(m1c,1e-12))
13152         m1c.getCoords().setIJ(0,1,0.1)
13153         self.assertTrue(not m.isEqual(m1c,1e-12))
13154         m1c.getCoords().setIJ(0,1,0)
13155         self.assertTrue(m.isEqual(m1c,1e-12))
13156         m1c.getCoords().setInfoOnComponent(1,"X")
13157         self.assertTrue(not m.isEqual(m1c,1e-12) and m.isEqualWithoutConsideringStr(m1c,1e-12))
13158         m.getCoords().setInfoOnComponent(1,"X")
13159         self.assertTrue(m.isEqual(m1c,1e-12) and m.isEqualWithoutConsideringStr(m1c,1e-12))
13160         m.setName("m2")
13161         self.assertTrue(not m.isEqual(m1c,1e-12) and m.isEqualWithoutConsideringStr(m1c,1e-12))
13162         #
13163         m.checkCoherency() ; m.checkCoherency1() ; m.checkCoherency2()
13164         self.assertEqual(m.getMeshDimension(),2)
13165         self.assertTrue(m.giveCellsWithType(NORM_QUAD4).isEqual(DataArrayInt([0,1,2,3,4])))
13166         self.assertTrue(m.giveCellsWithType(NORM_TRI3).isEqual(DataArrayInt([])))
13167         self.assertEqual(m.getNumberOfCellsWithType(NORM_QUAD4),5)
13168         self.assertEqual(m.getNumberOfCellsWithType(NORM_TRI3),0)
13169         self.assertEqual(m.getTypeOfCell(3),NORM_QUAD4)
13170         self.assertRaises(InterpKernelException,m.getTypeOfCell,5)
13171         self.assertEqual(m.getAllGeoTypes(),[NORM_QUAD4])
13172         self.assertEqual(m.getDistributionOfTypes(),[[NORM_QUAD4,5,-1]])
13173         ##
13174         pfl1=DataArrayInt([1,3,4])
13175         a,b,c=m.splitProfilePerType(pfl1)
13176         d,e,f=m.buildUnstructured().splitProfilePerType(pfl1)
13177         self.assertTrue(a==[[4,3,0]] and len(b)==1 and b[0].isEqual(DataArrayInt([0,1,2])) and len(c)==1 and c[0].getHiddenCppPointer()==pfl1.getHiddenCppPointer())
13178         self.assertTrue(a==d and len(b)==1 and b[0].isEqual(e[0]) and len(c)==1 and c[0].isEqual(f[0]))
13179         #
13180         pfl2=DataArrayInt([0,1,2,3])
13181         a,b,c=m.splitProfilePerType(pfl2)
13182         d,e,f=m.buildUnstructured().splitProfilePerType(pfl2)
13183         self.assertTrue(a==[[4,4,0]] and len(b)==1 and b[0].isEqual(DataArrayInt([0,1,2,3])) and len(c)==1 and c[0].getHiddenCppPointer()==pfl2.getHiddenCppPointer())
13184         self.assertTrue(a==d and len(b)==1 and b[0].isEqual(e[0]) and len(c)==1 and c[0].isEqual(f[0]))
13185         #
13186         pfl3=DataArrayInt([0,1,2,3,4])
13187         a,b,c=m.splitProfilePerType(pfl3)
13188         d,e,f=m.buildUnstructured().splitProfilePerType(pfl3)
13189         self.assertTrue(a==[[4,5,-1]] and len(b)==1 and b[0].isEqual(DataArrayInt([0,1,2,3,4])) and c==[])
13190         self.assertTrue(a==d and len(b)==1 and b[0].isEqual(e[0]) and c==[])
13191         #
13192         invalidPfl=DataArrayInt([1,2,3,4,5])
13193         self.assertRaises(InterpKernelException,m.splitProfilePerType,invalidPfl)
13194         self.assertRaises(InterpKernelException,m.buildUnstructured().splitProfilePerType,invalidPfl)
13195         ##
13196         pfl1=DataArrayInt([1,2,3])
13197         a=m.checkTypeConsistencyAndContig([NORM_QUAD4,3,0],[pfl1])
13198         b=m.buildUnstructured().checkTypeConsistencyAndContig([NORM_QUAD4,3,0],[pfl1])
13199         self.assertTrue(a.isEqual(b) and pfl1.getHiddenCppPointer(),a.getHiddenCppPointer())
13200         #
13201         pfl2=DataArrayInt([0,1,2,3])
13202         a=m.checkTypeConsistencyAndContig([NORM_QUAD4,4,0],[pfl2])
13203         b=m.buildUnstructured().checkTypeConsistencyAndContig([NORM_QUAD4,4,0],[pfl2])
13204         self.assertTrue(a.isEqual(b) and pfl2.getHiddenCppPointer()==a.getHiddenCppPointer())
13205         #
13206         pfl3=DataArrayInt([0,1,2,3,4])
13207         a=m.checkTypeConsistencyAndContig([NORM_QUAD4,4,0],[pfl3])
13208         b=m.buildUnstructured().checkTypeConsistencyAndContig([NORM_QUAD4,5,0],[pfl3])
13209         self.assertTrue(a.isEqual(b) and pfl3.getHiddenCppPointer()==a.getHiddenCppPointer())
13210         #
13211         invalidPfl=DataArrayInt([1,2,3,4,5])
13212         self.assertRaises(InterpKernelException,m.checkTypeConsistencyAndContig,[NORM_QUAD4,5,0],[invalidPfl])
13213         self.assertRaises(InterpKernelException,m.buildUnstructured().checkTypeConsistencyAndContig,[NORM_QUAD4,5,0],[invalidPfl])
13214         ##
13215         self.assertTrue(DataArrayInt([4,4,4,4,4]).isEqual(m.computeNbOfNodesPerCell()))
13216         ##
13217         self.assertEqual(m.getNodeIdsOfCell(1),[2,1,7,8])
13218         ##
13219         self.assertTrue(m.computeIsoBarycenterOfNodesPerCell().isEqual(DataArrayDouble([(0.5,0.5,0),(1.5,0.5,0),(2.5,0.5,0),(3.5,0.5,0),(4.5,0.5,0)]),1e-13))
13220         ##
13221         ref=m.getCoords().getHiddenCppPointer()
13222         mcpy=m.deepCpy() ; mcpy.insertNextCell([1,0,6,7])
13223         c=m.getNodalConnectivity().deepCpy()
13224         o2n=DataArrayInt([2,0,1,4,3])
13225         m.renumberCells(o2n,False)
13226         c.rearrange(4) ; c.renumberInPlace(o2n) ; c.rearrange(1)
13227         self.assertTrue(c.isEqual(m.getNodalConnectivity()))
13228         self.assertEqual(ref,m.getCoords().getHiddenCppPointer())
13229         m2=mcpy.mergeMyselfWith(m)
13230         self.assertTrue(isinstance(m2,MEDCoupling1SGTUMesh))
13231         self.assertEqual(11,m2.getNumberOfCells())
13232         self.assertEqual(48,m2.getNumberOfNodes())
13233         self.assertTrue(m2.getCoords().isEqual(DataArrayDouble.Aggregate([m.getCoords(),m.getCoords()]),1e-12))
13234         self.assertTrue(m2.getNodalConnectivity().isEqual(DataArrayInt([1,0,6,7,2,1,7,8,3,2,8,9,4,3,9,10,5,4,10,11,1,0,6,7,26,25,31,32,27,26,32,33,25,24,30,31,29,28,34,35,28,27,33,34])))
13235         ##
13236         mu=m.buildUnstructured()
13237         mu.checkCoherency2()
13238         self.assertEqual(mu.getCoords().getHiddenCppPointer(),m.getCoords().getHiddenCppPointer())
13239         self.assertEqual(2,mu.getMeshDimension())
13240         self.assertEqual([NORM_QUAD4],mu.getAllGeoTypes())
13241         self.assertTrue(mu.getNodalConnectivity().isEqual(DataArrayInt([4,2,1,7,8,4,3,2,8,9,4,1,0,6,7,4,5,4,10,11,4,4,3,9,10])))
13242         self.assertTrue(mu.getNodalConnectivityIndex().isEqual(DataArrayInt([0,5,10,15,20,25])))
13243         ##
13244         for typ in [0,1]:
13245             mcpy2=m.deepCpy() ; umcpy2=mcpy2.buildUnstructured()
13246             ids=mcpy2.simplexize(typ) ; ids2=umcpy2.simplexize(typ)
13247             self.assertTrue(ids.isEqual(ids2))
13248             mcpy3=umcpy2.convertIntoSingleGeoTypeMesh()
13249             self.assertTrue(mcpy2.isEqual(mcpy3,1e-14))
13250             pass
13251         um1=um.convertIntoSingleGeoTypeMesh()
13252         self.assertEqual(8,um1.getNumberOfNodesPerCell())
13253         for typ in [PLANAR_FACE_5,PLANAR_FACE_6]:
13254             mcpy2=um1.deepCpy() ; umcpy2=mcpy2.buildUnstructured()
13255             ids=mcpy2.simplexize(typ) ; ids2=umcpy2.simplexize(typ)
13256             self.assertTrue(ids.isEqual(ids2))
13257             mcpy3=umcpy2.convertIntoSingleGeoTypeMesh()
13258             self.assertTrue(mcpy2.isEqual(mcpy3,1e-14))
13259             pass
13260         ##
13261         self.assertRaises(InterpKernelException,mcpy.mergeMyselfWithOnSameCoords,m)
13262         mcpy.tryToShareSameCoords(m,1e-14)
13263         m3=mcpy.mergeMyselfWithOnSameCoords(m)
13264         self.assertTrue(isinstance(m3,MEDCoupling1SGTUMesh))
13265         self.assertEqual(11,m3.getNumberOfCells())
13266         self.assertEqual(24,m3.getNumberOfNodes())
13267         self.assertEqual(m3.getCoords().getHiddenCppPointer(),mcpy.getCoords().getHiddenCppPointer())
13268         self.assertTrue(m3.getNodalConnectivity().isEqual(DataArrayInt([1,0,6,7,2,1,7,8,3,2,8,9,4,3,9,10,5,4,10,11,1,0,6,7,2,1,7,8,3,2,8,9,1,0,6,7,5,4,10,11,4,3,9,10])))
13269         ##
13270         ref=mcpy.getCoords().deepCpy()
13271         c3=mcpy.getNodalConnectivity()[:]
13272         mcpy.getNodalConnectivity().setIJ(int(c3.getIdsEqual(11)),0,24)
13273         c2=DataArrayDouble.Aggregate([mcpy.getCoords(),mcpy.getCoords()[11:]])
13274         mcpy.setCoords(c2)
13275         mcpy.checkCoherency2()
13276         a,b=mcpy.getNodeIdsInUse()
13277         self.assertEqual(12,b)
13278         self.assertTrue(a.isEqual(DataArrayInt([0,1,2,3,4,5,6,7,8,9,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1])))
13279         ids=mcpy.zipCoordsTraducer()
13280         self.assertTrue(ids.isEqual(DataArrayInt([0,1,2,3,4,5,6,7,8,9,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1])))
13281         self.assertTrue(mcpy.getCoords().isEqual(ref[:12],1e-12))
13282         self.assertTrue(mcpy.getNodalConnectivity().isEqual(c3))
13283         mcpy.checkCoherency2()
13284         ##
13285         m4=mcpy[DataArrayInt([0,3,4])]
13286         m5=mcpy.buildPartOfMySelfKeepCoords(DataArrayInt([0,3,4]))
13287         self.assertTrue(isinstance(m4,MEDCoupling1SGTUMesh))
13288         self.assertTrue(m4.isEqual(m5,-1e-14))# < 0 not a bug it proves that coordinates pointer are equal
13289         self.assertTrue(m4.getNodalConnectivity().isEqual(DataArrayInt([1,0,6,7,4,3,9,10,5,4,10,11])))
13290         m6=mcpy[::2]
13291         self.assertTrue(isinstance(m6,MEDCoupling1SGTUMesh))
13292         self.assertTrue(m6.getNodalConnectivity().isEqual(DataArrayInt([1,0,6,7,3,2,8,9,5,4,10,11])))
13293         ##
13294         mcpy.setCoords(DataArrayDouble.Aggregate([mcpy.getCoords(),mcpy.getCoords()]))
13295         mcpy.checkCoherency2()
13296         ##
13297         mcppy=mcpy.deepCpyConnectivityOnly()
13298         self.assertTrue(mcppy.isEqual(mcpy,1e-12))
13299         self.assertTrue(mcppy.getCoords().getHiddenCppPointer()==mcpy.getCoords().getHiddenCppPointer())
13300         self.assertTrue(mcppy.getNodalConnectivity().isEqual(mcpy.getNodalConnectivity()))
13301         self.assertTrue(mcppy.getNodalConnectivity().getHiddenCppPointer()!=mcpy.getNodalConnectivity().getHiddenCppPointer())
13302         ##
13303         a,b=mcpy.getReverseNodalConnectivity()
13304         self.assertTrue(a.isEqual(DataArrayInt([0,5,0,1,5,1,2,2,3,3,4,4,0,5,0,1,5,1,2,2,3,3,4,4])))
13305         self.assertTrue(b.isEqual(DataArrayInt([0,2,5,7,9,11,12,14,17,19,21,23,24,24,24,24,24,24,24,24,24,24,24,24,24])))
13306         self.assertTrue(mcpy.fillCellIdsToKeepFromNodeIds([0,1,6,7],False).isEqual(DataArrayInt([0,1,5])))
13307         self.assertTrue(mcpy.fillCellIdsToKeepFromNodeIds([0,1,6,7],True).isEqual(DataArrayInt([0,5])))
13308         self.assertTrue(mcpy.getCellsInBoundingBox([(0,1),(0,1),(0,1)],1e-12).isEqual(DataArrayInt([0,1,5])))
13309         f=mcpy.buildOrthogonalField()
13310         self.assertEqual(f.getMesh().getHiddenCppPointer(),mcpy.getHiddenCppPointer())
13311         self.assertTrue(f.getArray().isEqual(DataArrayDouble(6*[(0,0,-1)]),1e-12))
13312         mcpy.changeSpaceDimension(2)
13313         self.assertEqual(1,mcpy.getCellContainingPoint([1.5,0.5],1e-12))
13314         ##
13315         self.assertTrue(mcpy.fillCellIdsToKeepFromNodeIds(DataArrayInt([6,7]),False).isEqual(DataArrayInt([0,1,5])))
13316         ##
13317         mcpy2=mcpy.deepCpy()
13318         self.assertEqual([None,None],mcpy.checkGeoEquivalWith(mcpy2,1,1e-12))#fast equal
13319         mcpy.checkFastEquivalWith(mcpy2,1e-12)
13320         mcpy2.renumberCells([0,2,4,3,1,5])
13321         mcpy.checkFastEquivalWith(mcpy2,1e-12)
13322         self.assertEqual([None,None],mcpy.checkGeoEquivalWith(mcpy2,1,1e-12))#fast equal
13323         mcpy2.renumberCells([0,2,4,3,1,5])
13324         mcpy2.renumberCells([1,3,5,0,2,4])
13325         self.assertRaises(InterpKernelException,mcpy.checkFastEquivalWith,mcpy2,1e-12)
13326         self.assertRaises(InterpKernelException,mcpy.checkGeoEquivalWith,mcpy2,1,1e-12)#fast equal
13327         pass
13328
13329     def testSwig21DGTUMesh1(self):
13330         a0=DataArrayInt([0,2,3,5,6,8])
13331         a1=DataArrayInt([0,4,7,11,14,18,21,25])
13332         a2=DataArrayInt([0,1,4,5])
13333         self.assertTrue(DataArrayInt.AggregateIndexes([a0,a1,a2]).isEqual(DataArrayInt([0,2,3,5,6,8,12,15,19,22,26,29,33,34,37,38])))
13334         self.assertEqual(a1[3:].front(),11)
13335         self.assertEqual(a1[4:].convertToDblArr().front(),14.)
13336         a1c=DataArrayInt([5,7,1,2, 8,11,0, 5,6,3,12, 1,5,2, 13,12,11,7, 6,1,0, 20,21,19,17])
13337         d,e=MEDCouplingUMesh.ExtractFromIndexedArrays2(1,5,2,a1c,a1)
13338         self.assertTrue(d.isEqual(DataArrayInt([8,11,0,1,5,2])))
13339         self.assertTrue(e.isEqual(DataArrayInt([0,3,6])))
13340         #
13341         m=MEDCouplingDataForTest.build2DTargetMesh_1()[0,3,4]
13342         ref=DataArrayInt([0,3,4,1,6,7,4,3,7,8,5,4])
13343         self.assertTrue(m.convertNodalConnectivityToStaticGeoTypeMesh().isEqual(ref))
13344         d,e=m.convertNodalConnectivityToDynamicGeoTypeMesh()
13345         self.assertTrue(d.isEqual(ref))
13346         self.assertTrue(e.isEqual(DataArrayInt.Range(0,13,4)))
13347         self.assertTrue(m.fillCellIdsToKeepFromNodeIds(DataArrayInt([6,7]),False).isEqual(DataArrayInt([1,2])))
13348         #
13349         m=MEDCoupling1GTUMesh.New("m",NORM_POLYHED)
13350         self.assertTrue(isinstance(m,MEDCoupling1DGTUMesh))
13351         m.__repr__() ; m.__str__()
13352         m.setCoords(DataArrayDouble(20,3))
13353         m.allocateCells()
13354         m.__repr__() ; m.__str__()
13355         m.insertNextCell([0,1,2,5,7,2,-1,1,3])
13356         self.assertEqual(1,m.getNumberOfCells())
13357         self.assertTrue(DataArrayInt([8]).isEqual(m.computeNbOfNodesPerCell()))
13358         self.assertTrue(DataArrayInt([2]).isEqual(m.computeNbOfFacesPerCell()))
13359         m.__repr__() ; m.__str__()
13360         m.checkCoherency()
13361         m.checkCoherency2()
13362         #
13363         cm=MEDCouplingCMesh() ; cm.setName("m")
13364         arr0=DataArrayDouble(6) ; arr0.iota()
13365         arr1=DataArrayDouble([0,1])
13366         cm.setCoords(arr0,arr1,arr1) ; um=cm.buildUnstructured() ; um.convertAllToPoly()
13367         um2=um.deepCpyConnectivityOnly()
13368         self.assertTrue(um2.isEqual(um,1e-12))
13369         self.assertEqual(um2.getCoords().getHiddenCppPointer(),um.getCoords().getHiddenCppPointer())
13370         self.assertTrue(um2.getNodalConnectivity().isEqual(um.getNodalConnectivity()))
13371         self.assertTrue(um2.getNodalConnectivity().getHiddenCppPointer()!=um.getNodalConnectivity().getHiddenCppPointer())
13372         self.assertTrue(um2.getNodalConnectivityIndex().isEqual(um.getNodalConnectivityIndex()))
13373         self.assertTrue(um2.getNodalConnectivityIndex().getHiddenCppPointer()!=um.getNodalConnectivityIndex().getHiddenCppPointer())
13374         #
13375         self.assertRaises(InterpKernelException,MEDCoupling1SGTUMesh.New,"m",NORM_POLYHED)
13376         m=MEDCoupling1DGTUMesh("m",NORM_POLYHED)
13377         m.allocateCells(5)
13378         self.assertEqual(15,m.getNodalConnectivity().getNbOfElemAllocated())
13379         self.assertEqual(6,m.getNodalConnectivityIndex().getNbOfElemAllocated())
13380         m.setCoords(um.getCoords())
13381         m.insertNextCell([1,0,6,7,-1,7,6,1])
13382         self.assertEqual(1,m.getNumberOfCells())
13383         m.insertNextCell([2,1,7,8,-1,2,1,-1,8,-1,7])
13384         m.insertNextCell([3,2,8,9])
13385         m.insertNextCell([4,3,9,10,-1,5,3,9])
13386         m.insertNextCell([5,4,10,11,-1,11,10,-1,5])
13387         m.checkCoherency()
13388         m.checkCoherency2()
13389         self.assertEqual(5,m.getNumberOfCells())
13390         self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,8,19,23,31,40])))
13391         self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([1,0,6,7,-1,7,6,1,2,1,7,8,-1,2,1,-1,8,-1,7,3,2,8,9,4,3,9,10,-1,5,3,9,5,4,10,11,-1,11,10,-1,5])))
13392         #
13393         m4=m.deepCpy()
13394         self.assertTrue(m.isEqual(m4,1e-12))
13395         m4.getNodalConnectivity().setIJ(2,0,5)
13396         self.assertTrue(not m.isEqual(m4,1e-12))
13397         m4.getNodalConnectivity().setIJ(2,0,6)
13398         self.assertTrue(m.isEqual(m4,1e-12))
13399         m4.getNodalConnectivityIndex().setIJ(2,0,21)
13400         self.assertTrue(not m.isEqual(m4,1e-12))
13401         m4.getNodalConnectivityIndex().setIJ(2,0,19)
13402         self.assertTrue(m.isEqual(m4,1e-12))
13403         m4.getCoords().setIJ(10,1,1.1)
13404         self.assertTrue(not m.isEqual(m4,1e-12))
13405         m4.getCoords().setIJ(10,1,1.)
13406         self.assertTrue(m.isEqual(m4,1e-12))
13407         m4.getNodalConnectivity().pushBackSilent(7)
13408         self.assertTrue(not m.isEqual(m4,1e-12))
13409         self.assertEqual(7,m4.getNodalConnectivity().popBackSilent())
13410         self.assertTrue(m.isEqual(m4,1e-12))
13411         m4.setName("m4")
13412         self.assertTrue(not m.isEqual(m4,1e-12))
13413         m4.setName("m")
13414         self.assertTrue(m.isEqual(m4,1e-12))
13415         #
13416         self.assertEqual(6,m.getNodalConnectivityIndex().getNbOfElemAllocated())
13417         self.assertEqual(60,m.getNodalConnectivity().getNbOfElemAllocated())
13418         self.assertTrue(m.computeNbOfNodesPerCell().isEqual(DataArrayInt([7,8,4,7,7])))
13419         self.assertTrue(m.computeNbOfFacesPerCell().isEqual(DataArrayInt([2,4,1,2,3])))
13420         self.assertEqual(m.getNodeIdsOfCell(1),[2,1,7,8,-1,2,1,-1,8,-1,7])
13421         f=m.computeIsoBarycenterOfNodesPerCell()
13422         self.assertTrue(DataArrayDouble([(0.5714285714285714,0.5714285714285714,0),(1.5,0.5,0),(2.5,0.5,0),(3.5714285714285712,0.42857142857142855,0),(4.5714285714285712,0.5714285714285714,0)]).isEqual(f,1e-14))
13423         mu0=m.buildUnstructured()
13424         o2n=[1,2,0,4,3]
13425         m2=m.deepCpy()
13426         m3=m.deepCpyConnectivityOnly()
13427         self.assertTrue(m3.isEqual(m,1e-12))
13428         self.assertEqual(m3.getCoords().getHiddenCppPointer(),m.getCoords().getHiddenCppPointer())
13429         self.assertTrue(m3.getNodalConnectivity().getHiddenCppPointer()!=m.getNodalConnectivity().getHiddenCppPointer())
13430         self.assertTrue(m3.getNodalConnectivity().isEqual(m.getNodalConnectivity()))
13431         self.assertTrue(m3.getNodalConnectivityIndex().getHiddenCppPointer()!=m.getNodalConnectivityIndex().getHiddenCppPointer())
13432         self.assertTrue(m3.getNodalConnectivityIndex().isEqual(m.getNodalConnectivityIndex()))
13433         m.renumberCells(o2n)
13434         mu0.renumberCells(o2n)
13435         self.assertTrue(mu0.isEqual(m.buildUnstructured(),1e-12))
13436         self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,12,23,32,40])))
13437         self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([3,2,8,9,1,0,6,7,-1,7,6,1,2,1,7,8,-1,2,1,-1,8,-1,7,5,4,10,11,-1,11,10,-1,5,4,3,9,10,-1,5,3,9])))
13438         #
13439         mcpy0=m.buildUnstructured()
13440         self.assertTrue(isinstance(mcpy0,MEDCouplingUMesh))
13441         self.assertTrue(mcpy0.getNodalConnectivity().isEqual(DataArrayInt([31,3,2,8,9,31,1,0,6,7,-1,7,6,1,31,2,1,7,8,-1,2,1,-1,8,-1,7,31,5,4,10,11,-1,11,10,-1,5,31,4,3,9,10,-1,5,3,9])))
13442         self.assertTrue(mcpy0.getNodalConnectivityIndex().isEqual(DataArrayInt([0,5,14,26,36,45])))
13443         self.assertEqual(mcpy0.getAllGeoTypes(),[NORM_POLYHED])
13444         mcpy0.checkCoherency()
13445         mcpy0.checkCoherency2()
13446         mcpy1=mcpy0.convertIntoSingleGeoTypeMesh()
13447         self.assertTrue(mcpy1.isEqual(m,1e-12))
13448         #
13449         m_mrg=MEDCoupling1DGTUMesh.Merge1DGTUMeshes([m2,m,m2])
13450         self.assertTrue(m_mrg.getNodalConnectivityIndex().isEqual(DataArrayInt([0,8,19,23,31,40,44,52,63,72,80,88,99,103,111,120])))
13451         self.assertTrue(m_mrg.getNodalConnectivity().isEqual(DataArrayInt([1,0,6,7,-1,7,6,1,2,1,7,8,-1,2,1,-1,8,-1,7,3,2,8,9,4,3,9,10,-1,5,3,9,5,4,10,11,-1,11,10,-1,5,27,26,32,33,25,24,30,31,-1,31,30,25,26,25,31,32,-1,26,25,-1,32,-1,31,29,28,34,35,-1,35,34,-1,29,28,27,33,34,-1,29,27,33,49,48,54,55,-1,55,54,49,50,49,55,56,-1,50,49,-1,56,-1,55,51,50,56,57,52,51,57,58,-1,53,51,57,53,52,58,59,-1,59,58,-1,53])))
13452         m_mrg2=MEDCoupling1DGTUMesh.Merge1DGTUMeshesOnSameCoords([m3,m,m3])
13453         self.assertTrue(m_mrg2.getNodalConnectivityIndex().isEqual(DataArrayInt([0,8,19,23,31,40,44,52,63,72,80,88,99,103,111,120])))
13454         self.assertTrue(m_mrg2.getNodalConnectivity().isEqual(DataArrayInt([1,0,6,7,-1,7,6,1,2,1,7,8,-1,2,1,-1,8,-1,7,3,2,8,9,4,3,9,10,-1,5,3,9,5,4,10,11,-1,11,10,-1,5,3,2,8,9,1,0,6,7,-1,7,6,1,2,1,7,8,-1,2,1,-1,8,-1,7,5,4,10,11,-1,11,10,-1,5,4,3,9,10,-1,5,3,9,1,0,6,7,-1,7,6,1,2,1,7,8,-1,2,1,-1,8,-1,7,3,2,8,9,4,3,9,10,-1,5,3,9,5,4,10,11,-1,11,10,-1,5])))
13455         a,b=m_mrg2.getReverseNodalConnectivity()
13456         self.assertTrue(b.isEqual(DataArrayInt([0,3,15,24,33,39,48,54,66,75,84,93,99,99,99,99,99,99,99,99,99,99,99,99,99])))
13457         self.assertTrue(a.isEqual(DataArrayInt([0,6,10,0,0,1,1,6,6,7,7,10,10,11,11,1,1,2,5,7,7,11,11,12,2,3,3,5,9,9,12,13,13,3,4,8,9,13,14,3,4,4,8,8,9,13,14,14,0,0,6,6,10,10,0,0,1,1,6,6,7,7,10,10,11,11,1,1,2,5,7,7,11,11,12,2,3,3,5,9,9,12,13,13,3,4,4,8,8,9,13,14,14,4,4,8,8,14,14])))
13458         self.assertTrue(m_mrg2.fillCellIdsToKeepFromNodeIds([7],False).isEqual(DataArrayInt([0,1,6,7,10,11])))
13459         self.assertTrue(m_mrg2.fillCellIdsToKeepFromNodeIds([0,1,6,7],True).isEqual(DataArrayInt([0,6,10])))
13460         #
13461         self.assertTrue(m_mrg2.isPacked())
13462         self.assertEqual(120,m_mrg2.getNodalConnectivityIndex().popBackSilent())
13463         self.assertEqual(m_mrg2.getNumberOfCells(),14)
13464         m_mrg2.checkCoherency2()
13465         self.assertTrue(not m_mrg2.isPacked())
13466         m_mrg4,b=m_mrg2.copyWithNodalConnectivityPacked()
13467         self.assertTrue(not b)
13468         m_mrg4.checkCoherency2()
13469         self.assertEqual(m_mrg4.getNumberOfCells(),14)
13470         self.assertTrue(m_mrg4.getNodalConnectivityIndex().isEqual(m_mrg2.getNodalConnectivityIndex()))
13471         self.assertEqual(len(m_mrg4.getNodalConnectivity()),111)
13472         self.assertEqual(len(m_mrg2.getNodalConnectivity()),120)
13473         self.assertTrue(m_mrg4.getNodalConnectivity().isEqual(m_mrg2.getNodalConnectivity()[:111]))
13474         #
13475         m0=m_mrg2[:5]
13476         m1=m_mrg2[[5,6,7,8,9]]
13477         m2=m_mrg2[10:]
13478         self.assertTrue(m1.isEqualWithoutConsideringStr(m,1e-12))
13479         a,b=m.checkGeoEquivalWith(m0,12,1e-12)
13480         self.assertTrue(a.isEqual(DataArrayInt(o2n)))
13481         self.assertTrue(b is None)
13482         pass
13483
13484     def testSwig2DADAreIncludedInMe1(self):
13485         a=DataArrayDouble(30) ; a.iota() ; a.rearrange(3)
13486         p=DataArrayInt([5,2,1,9])
13487         b,c=a.areIncludedInMe(a[p],1e-12)
13488         self.assertTrue(b)
13489         self.assertTrue(c.isEqual(p))
13490         d=a[p]
13491         d.setIJ(3,1,28.1)
13492         b,c=a.areIncludedInMe(d,1e-12)
13493         self.assertTrue(not b)
13494         self.assertTrue(c.isEqual(DataArrayInt([5,2,1,10])))
13495         pass
13496
13497     def testSwig2DADesallocate1(self):
13498         d=DataArrayDouble([(1,2),(6,7),(6,8)]) ; d.setInfoOnComponents(["aa","bbb"])
13499         self.assertTrue(d.isAllocated())
13500         d.checkAllocated()
13501         self.assertEqual(d.getInfoOnComponents(),["aa","bbb"])
13502         ref=d.getHeapMemorySize()
13503         d.desallocate()
13504         self.assertEqual(ref-d.getHeapMemorySize(),6*8)
13505         self.assertTrue(not d.isAllocated())
13506         self.assertEqual(d.getInfoOnComponents(),["aa","bbb"])
13507         self.assertRaises(InterpKernelException,d.checkAllocated)
13508         #
13509         d=DataArrayInt([(1,2),(6,7),(6,8)]) ; d.setInfoOnComponents(["aa","bbb"])
13510         self.assertTrue(d.isAllocated())
13511         d.checkAllocated()
13512         self.assertEqual(d.getInfoOnComponents(),["aa","bbb"])
13513         ref=d.getHeapMemorySize()
13514         d.desallocate()
13515         self.assertEqual(ref-d.getHeapMemorySize(),6*4)
13516         self.assertTrue(not d.isAllocated())
13517         self.assertEqual(d.getInfoOnComponents(),["aa","bbb"])
13518         self.assertRaises(InterpKernelException,d.checkAllocated)
13519         pass
13520
13521     def testSwig2IsPartStructured1(self):
13522         #dim 1
13523         d10=DataArrayInt([2,3,4,5,6,7,8,9,10,11])
13524         a,b=MEDCouplingStructuredMesh.IsPartStructured(d10,[13])
13525         self.assertTrue(a) ; self.assertEqual(b,[(2,12)])
13526         d11=DataArrayInt([2,3,4,5,6,7,8,10,9,11])
13527         a,b=MEDCouplingStructuredMesh.IsPartStructured(d11,[13])
13528         self.assertTrue(not a)
13529         self.assertRaises(InterpKernelException,MEDCouplingStructuredMesh.IsPartStructured,d10,[11])
13530         #dim 2
13531         st=[10,4]
13532         d20=DataArrayInt([1,2,3,4,11,12,13,14,21,22,23,24])
13533         a,b=MEDCouplingStructuredMesh.IsPartStructured(d20,st)
13534         self.assertTrue(a) ; self.assertEqual(b,[(1,5),(0,3)])
13535         d20=DataArrayInt([1,2,3,4,12,11,13,14,21,22,23,24])
13536         a,b=MEDCouplingStructuredMesh.IsPartStructured(d20,st)
13537         self.assertTrue(not a)
13538         d20=DataArrayInt([1,2,3,4,11,12,13,15,21,22,23,24])
13539         a,b=MEDCouplingStructuredMesh.IsPartStructured(d20,st)
13540         self.assertTrue(not a)
13541         d21=DataArrayInt([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39])
13542         a,b=MEDCouplingStructuredMesh.IsPartStructured(d21,st)
13543         self.assertTrue(a) ; self.assertEqual(b,[(0,10),(0,4)])
13544         d22=DataArrayInt([1,2,3,4,11,12,13,14,21,22,23,24,31,32,33,34,41,42,43,44])
13545         self.assertRaises(InterpKernelException,MEDCouplingStructuredMesh.IsPartStructured,d22,st)
13546         a,b=MEDCouplingStructuredMesh.IsPartStructured(d22,[10,5])
13547         self.assertTrue(a) ; self.assertEqual(b,[(1,5),(0,5)])
13548         #dim 3
13549         d30=DataArrayInt([11,12,13,14,21,22,23,24,51,52,53,54,61,62,63,64])
13550         a,b=MEDCouplingStructuredMesh.IsPartStructured(d30,[10,4,2])
13551         self.assertTrue(a) ; self.assertEqual(b,[(1,5),(1,3),(0,2)])
13552         d31=DataArrayInt([11,12,13,14,21,22,24,23,51,52,53,54,61,62,63,64])
13553         a,b=MEDCouplingStructuredMesh.IsPartStructured(d31,[10,4,2])
13554         self.assertTrue(not a)
13555         self.assertRaises(InterpKernelException,MEDCouplingStructuredMesh.IsPartStructured,d30,[10,4,1])
13556         pass
13557
13558     def testSwig2PartStructured1(self):
13559         c=MEDCouplingCMesh() ; c.setName("toto")
13560         arr0=DataArrayDouble(10); arr0.iota()
13561         arr1=DataArrayDouble(4) ; arr1.iota(3)
13562         c.setCoords(arr0,arr1)
13563         self.assertEqual(c.getNodeGridStructure(),(10,4))
13564         self.assertEqual(c.getCellGridStructure(),(9,3))
13565         d20=DataArrayInt([1,2,3,4,10,11,12,13,19,20,21,22])
13566         self.assertEqual(27,c.getNumberOfCells())
13567         self.assertEqual(40,c.getNumberOfNodes())
13568         self.assertEqual(2,c.getMeshDimension())
13569         c.checkCoherency()
13570         #
13571         arr2=MEDCouplingStructuredMesh.BuildExplicitIdsFrom([9,3],[(1,5),(0,3)])
13572         self.assertTrue(arr2.isEqual(DataArrayInt([1,2,3,4,10,11,12,13,19,20,21,22])))
13573         # CMesh
13574         c2=c.buildStructuredSubPart([(1,5),(0,3)])
13575         c2.checkCoherency()
13576         self.assertTrue(isinstance(c2,MEDCouplingCMesh))
13577         self.assertEqual(12,c2.getNumberOfCells())
13578         self.assertEqual(20,c2.getNumberOfNodes())
13579         self.assertEqual(2,c2.getMeshDimension())
13580         self.assertEqual("toto",c2.getName())
13581         self.assertTrue(c2.getCoordsAt(0).isEqual(DataArrayDouble([1.,2.,3.,4.,5.]),1e-12))
13582         self.assertTrue(c2.getCoordsAt(1).isEqual(DataArrayDouble([3.,4.,5.,6.]),1e-12))
13583         #
13584         a,b=c.buildPartAndReduceNodes(d20)
13585         a.checkCoherency()
13586         exp2=DataArrayInt([-1,0,1,2,3,4,-1,-1,-1,-1,-1,5,6,7,8,9,-1,-1,-1,-1,-1,10,11,12,13,14,-1,-1,-1,-1,-1,15,16,17,18,19,-1,-1,-1,-1])
13587         self.assertTrue(exp2.isEqual(b))
13588         self.assertTrue(isinstance(a,MEDCouplingCMesh))
13589         self.assertTrue(a.buildUnstructured().isEqual(c.buildUnstructured().buildPartAndReduceNodes(d20)[0],1e-12))
13590         # CurveLinearMesh
13591         c2=MEDCouplingCurveLinearMesh() ; c2.setName("toto")
13592         c2.setCoords(c.buildUnstructured().getCoords())
13593         c2.setNodeGridStructure([10,4])
13594         c2.checkCoherency()
13595         a,b=c2.buildPartAndReduceNodes(d20)
13596         a.checkCoherency()
13597         self.assertTrue(exp2.isEqual(b))
13598         self.assertTrue(isinstance(a,MEDCouplingCurveLinearMesh))
13599         self.assertTrue(a.buildUnstructured().isEqual(c2.buildUnstructured().buildPartAndReduceNodes(d20)[0],1e-12))
13600         pass
13601
13602     def testSwig2FindPermutationFromFirstToSecond1(self):
13603         ids1=DataArrayInt([3,1,103,4,6,10,-7,205])
13604         ids2=DataArrayInt([-7,1,205,10,6,3,103,4])
13605         ids3=DataArrayInt.FindPermutationFromFirstToSecond(ids1,ids2)
13606         self.assertTrue(ids3.isEqual(DataArrayInt([5,1,6,7,4,3,0,2])))
13607         ids2ToTest=ids1.renumber(ids3)
13608         self.assertTrue(ids2ToTest.isEqual(ids2))
13609         self.assertRaises(InterpKernelException,DataArrayInt.FindPermutationFromFirstToSecond,DataArrayInt([3,1,103]),DataArrayInt([1,103]))
13610         self.assertRaises(InterpKernelException,DataArrayInt.FindPermutationFromFirstToSecond,DataArrayInt([3,1,103]),DataArrayInt([1,103,2]))
13611         self.assertRaises(InterpKernelException,DataArrayInt.FindPermutationFromFirstToSecond,DataArrayInt([3,1,103]),DataArrayInt([1,103,1]))
13612         self.assertTrue(DataArrayInt.FindPermutationFromFirstToSecond(DataArrayInt([]),DataArrayInt([])).empty())
13613         pass
13614
13615     def testSwig2BugStructuredMeshGetNodeIdsOfCell1(self):
13616         m=MEDCouplingCMesh("mesh")
13617         coordsX=DataArrayDouble([0,1.1,2.2,3.3,4.4]) ; coordsX.setInfoOnComponents(["XX [m]"])
13618         coordsY=DataArrayDouble([0,1.7,3.4]) ; coordsY.setInfoOnComponents(["YYY [km]"])
13619         m.setCoords(coordsX,coordsY)
13620         self.assertEqual([2,3,8,7],m.getNodeIdsOfCell(2))
13621         self.assertEqual([3,4,9,8],m.getNodeIdsOfCell(3))
13622         self.assertEqual([7,8,13,12],m.getNodeIdsOfCell(6))
13623         self.assertEqual([8,9,14,13],m.getNodeIdsOfCell(7))
13624         pass
13625
13626     def testSwig2ThrowOnDAIInvertN2O2ON2(self):
13627         p1=DataArrayInt([3,5,8])
13628         p2=DataArrayInt([0,3,4,5,6,7,8,9,10])
13629         p1.transformWithIndArr(p2.invertArrayN2O2O2N(11))
13630         self.assertTrue(p1.isEqual(DataArrayInt([1,3,6])))
13631         self.assertTrue(p2.invertArrayN2O2O2N(11).isEqual(DataArrayInt([0,-1,-1,1,2,3,4,5,6,7,8])))
13632         self.assertRaises(InterpKernelException,p2.invertArrayN2O2O2N,10)
13633         pass
13634
13635     def testSwig2ComputeEffectiveNbOfNodesPerCell1(self):
13636         coords=DataArrayDouble([ 0.241310763507 , 0.0504777305619 , 0.0682283524903 , 0.252501053866 , -0.0625176732937 , 0.137272639894 ,
13637                  0.152262663601 , 0.241816569527 , 0.133812556197 , 0.18047750211 , -0.0789949051358 , 0.339098173401 ,
13638                  0.151741971857 , 0.238885278571 , 0.137715037333 , 0.242532155481 , -0.0928169086456 , 0.0678043417367 ,
13639                  0.240941965335 , -0.015461491464 , 0.0617186345825 , 0.24127650112 , 0.0499427876717 , 0.0679634099148 ,
13640                  -0.145828917428 , 0.206291632565 , 0.0310071927543 , 0.0125651775307 , 0.266262085828 , 0.105228430543 ,
13641                  -0.0994066533286 , 0.233224271238 , 0.0572213839567 , -0.0951345338317 , 0.234819509426 , 0.0592126284538 ,
13642                  0.136580574205 , -0.205486212579 , 0.0572866072014 , 0.0637270784978 , -0.168886355238 , 0.446614057077 ,
13643                  0.041337157151 , -0.213402568198 , 0.372407095999 , 0.0411601970268 , -0.202387875756 , 0.411334979491 ,
13644                  -0.108355701857 , 0.193636239335 , 0.204886756738 , 0.00639779029829 , 0.155296981517 , 0.252585892979 ,
13645                  0.0262473111702 , -0.112919732543 , 0.424286639249 ,-0.224103052733 , -0.139430015438 , -0.0122352295701 ,
13646                 -0.0312760589481 , -0.274272003594 , 0.0323959636568 , -0.166663422532 , -0.217754445175 , 0.00392109070364 ,
13647                  -0.30586619777 , -0.0475168041091 , -0.0144585228182 , -0.280881480586 , 0.135571293538 , 0.00623923647986 ,
13648                  -0.25548538234 , 0.156819217766 , 0.0645277879769 , -0.131567009284 , 0.184133752309 , 0.206021802753 ,
13649                  -0.196204010965 , 0.151602971681 , 0.212974777736 , -0.183713879463 , 0.0802946639531 , 0.260115662599 ,
13650                  -0.244241178767 , -0.0738873389604 , 0.144590565817 , -0.155804057829 , -0.164892720025 , 0.210613950558 ,
13651                  -0.170950800428 , -0.215099334026 , 0.00610122860092 , -0.30552634869 , -0.0490020791904 , -0.0132786533145 ,
13652                  0.271831011884 , 0.15105657296 , 0.0230534827908 , 0.281919192283 , 0.0898544306288 , -0.0625201489143 ,
13653                  0.260240727276 , -0.0120688706637 , -0.0532316588626 , 0.244947737722 , 0.0197984684293 , 0.0309341209233 ,
13654                  0.23439631578 , 0.229825279875 , 0.0508520585381 , 0.160921316875 , 0.265078502128 , 0.121716560626 ,
13655                  -0.315088694175 , 0.0747700471918 , -0.245836615071 , -0.327728781776 , 0.0857114674649 , -0.239431905957 ,
13656                  -0.308385460634 , 0.145142997084 , -0.149886828433 , 0.0488236045164 , 0.309462801914 , 0.0849169148265 ,
13657                 -0.0244964803395 , 0.33145611751 , -0.0476415818061 , 0.0060567994229 , 0.32418412014 , 0.0367779543812 ,
13658                  -0.0950221448063 , 0.236675326003 , 0.0572594453983 , 0.248723023186 , 0.0886648784791 , -0.176629430538 ,
13659                  0.116796984 , 0.256596599567 , -0.292863523603 , 0.118024552914 , 0.229154257843 , -0.34233232501 ,
13660                  0.217507892549 , -0.0417822335742 , -0.176771782888 , -0.224429321304 , 0.0125595300114 , -0.362064725588 ,
13661                  0.0937301100955 , -0.0500824832657 , -0.299713548444 , -0.244162220397 , 0.0383853931293 , -0.389856984411 ,
13662                  -0.0281989366102 , 0.097392811563 , -0.458244577284 , -0.385010847162 , 0.10122766194 , -0.140052859922 ,
13663                  -0.377936358012 , 0.110875172128 , -0.176207095463 , 0.244483045556 , -0.0991073977045 , 0.0575134372934 ,
13664                 0.262605120167 , -0.100243191645 , -0.0495620806935 , 0.240306880972 , -0.136153701579 , -0.114745281696 ,
13665                  0.215763176129 , -0.0836766059189 , -0.183249640616 , 0.237870396603 , -0.132449578286 , -0.121598854639 ,
13666                  -0.0637683083097 , -0.27921020214 , -0.149112321992 , -0.0856211014977 , -0.2973233473 , -0.0446878139589 ,
13667                  0.104675342288 , -0.0625908305324 , -0.290346256534 , 0.0248264249186 , -0.247797708548 , -0.165830884019 ,
13668                  0.0719302438309 , -0.178468260473 , -0.211432157345 , 0.142871843159 , -0.208769948542 , 0.0454101128246 ,
13669                  0.167803379307 , -0.207851396623 , -0.088802726124 , 0.12868717152 , -0.230920439715 , 0.00760508389036 ,
13670                  -0.0372812069535 , -0.286740286332 , 0.00963701291166 ], 69, 3)
13671         connN = [ #polyhedron 0
13672             0 , 1 , 3 , 4 , 2 , -1 , 1 , 5 , 6 , 7 , 0 , -1 , 0 , 7 , 8 , 10 , 11 , 9 , 2 , -1 , 1 , 5 , 12 , 14 , 15 , 13 , 3 , -1 , 16 , 9 , 2 , 4 , 17 , -1
13673             , 4 , 3 , 13 , 18 , 17 , -1 , 5 , 6 , 19 , 21 , 20 , 12 , -1 , 6 , 7 , 8 , 23 , 22 , 19 , -1 , 23 , 24 , 10 , 8 , -1 , 25 , 11 , 9 , 16 , -1
13674             , 24 , 26 , 25 , 11 , 10 , -1 , 12 , 14 , 20 , -1 , 27 , 28 , 29 , 15 , 13 , 18 , -1 , 14 , 15 , 29 , 30 , 21 , 20 , -1 , 26 , 27 , 18 , 17 , 16 , 25 , -1
13675             , 22 , 19 , 21 , 30 , 31 , -1 , 22 , 31 , 28 , 27 , 26 , 24 , 23 , -1 , 31 , 30 , 29 , 28,
13676             # polyhedron 1
13677             0 , 7 , 8 , 10 , 11 , 9 , 2 , -1 , 32 , 0 , 7 , 35 , 34 , 33 , -1 , 32 , 0 , 2 , 37 , 36 , -1 , 35 , 7 , 8 , 40 , 39 , 38 , -1
13678             , 2 , 37 , 41 , 9 , -1 , 40 , 8 , 10 , 44 , 43 , 42 , -1 , 41 , 9 , 11 , 44 , 43 , -1 , 44 , 11 , 10 , -1 , 32 , 33 , 45 , 47 , 46 , 36 , -1
13679             , 33 , 34 , 48 , 45 , -1 , 35 , 34 , 48 , 50 , 49 , 38 , -1 , 41 , 43 , 42 , 46 , 36 , 37 , -1 , 38 , 39 , 51 , 49 , -1
13680             , 39 , 40 , 42 , 46 , 47 , 52 , 51 , -1 , 45 , 47 , 52 , 50 , 48 , -1 , 52 , 51 , 49 , 50,
13681             # polyhedron 2
13682             6 , 7 , 8 , 23 , 22 , 19 , -1 , 6 , 35 , 7 , -1 , 6 , 35 , 38 , 19 , -1 , 35 , 7 , 8 , 40 , 39 , 38 , -1 , 53 , 22 , 19 , 38 , 39 , 54 , -1
13683             , 23 , 53 , 54 , 40 , 8 , -1 , 53 , 22 , 23 , -1 , 39 , 54 , 40,
13684             # polyhedron 3
13685             35 , 34 , 48 , 50 , 49 , 38 , -1 , 6 , 35 , 34 , 56 , 55 , 5 , -1 , 6 , 35 , 38 , 19 , -1 , 34 , 56 , 57 , 59 , 58 , 48 , -1
13686             , 60 , 61 , 21 , 19 , 38 , 49 , -1 , 62 , 50 , 48 , 58 , -1 , 60 , 63 , 64 , 62 , 50 , 49 , -1 , 5 , 6 , 19 , 21 , 20 , 12 , -1
13687             , 55 , 5 , 12 , 65 , -1 , 66 , 67 , 65 , 55 , 56 , 57 , -1 , 63 , 66 , 57 , 59 , 64 , -1 , 64 , 62 , 58 , 59 , -1
13688             , 60 , 63 , 66 , 67 , 68 , 61 , -1 , 61 , 68 , 20 , 21 , -1 , 67 , 68 , 20 , 12 , 65]
13689         meshN=MEDCouplingUMesh.New()
13690         meshN.setName("ForBary")
13691         meshN.setMeshDimension(3) ; meshN.setCoords(coords)
13692         meshN.allocateCells(4)
13693         meshN.insertNextCell(NORM_POLYHED,113,connN);
13694         meshN.insertNextCell(NORM_POLYHED,99,connN[113:])
13695         meshN.insertNextCell(NORM_POLYHED,43,connN[212:])
13696         meshN.insertNextCell(NORM_POLYHED,92,connN[255:])
13697         d=meshN.computeEffectiveNbOfNodesPerCell()
13698         e=meshN.computeNbOfNodesPerCell()
13699         self.assertTrue(d.isEqual(DataArrayInt([32,28,12,26])))
13700         self.assertTrue(e.isEqual(DataArrayInt([96,84,36,78])))
13701         m0=MEDCoupling1DGTUMesh(meshN)
13702         c=MEDCouplingCMesh()
13703         arr=DataArrayDouble(3) ; arr.iota(10)
13704         c.setCoords(arr,arr,arr)
13705         m10=c.buildUnstructured()
13706         m11=c.build1SGTUnstructured()
13707         m12=MEDCoupling1SGTUMesh.New(m10)
13708         self.assertTrue(m12.isEqual(m11,1e-12))
13709         m12.setCoords(m0.getCoords()) # m12 is not OK geometrically but the aim of the test is only connectivity values
13710         m3=MEDCoupling1GTUMesh.AggregateOnSameCoordsToUMesh([m12,m0])
13711         m3.checkCoherency()
13712         self.assertEqual(m3.getCoords().getHiddenCppPointer(),m12.getCoords().getHiddenCppPointer())
13713         self.assertTrue(m3.getNodalConnectivity().isEqual(DataArrayInt([18,1,0,3,4,10,9,12,13,18,2,1,4,5,11,10,13,14,18,4,3,6,7,13,12,15,16,18,5,4,7,8,14,13,16,17,18,10,9,12,13,19,18,21,22,18,11,10,13,14,20,19,22,23,18,13,12,15,16,22,21,24,25,18,14,13,16,17,23,22,25,26,31,0,1,3,4,2,-1,1,5,6,7,0,-1,0,7,8,10,11,9,2,-1,1,5,12,14,15,13,3,-1,16,9,2,4,17,-1,4,3,13,18,17,-1,5,6,19,21,20,12,-1,6,7,8,23,22,19,-1,23,24,10,8,-1,25,11,9,16,-1,24,26,25,11,10,-1,12,14,20,-1,27,28,29,15,13,18,-1,14,15,29,30,21,20,-1,26,27,18,17,16,25,-1,22,19,21,30,31,-1,22,31,28,27,26,24,23,-1,31,30,29,28,31,0,7,8,10,11,9,2,-1,32,0,7,35,34,33,-1,32,0,2,37,36,-1,35,7,8,40,39,38,-1,2,37,41,9,-1,40,8,10,44,43,42,-1,41,9,11,44,43,-1,44,11,10,-1,32,33,45,47,46,36,-1,33,34,48,45,-1,35,34,48,50,49,38,-1,41,43,42,46,36,37,-1,38,39,51,49,-1,39,40,42,46,47,52,51,-1,45,47,52,50,48,-1,52,51,49,50,31,6,7,8,23,22,19,-1,6,35,7,-1,6,35,38,19,-1,35,7,8,40,39,38,-1,53,22,19,38,39,54,-1,23,53,54,40,8,-1,53,22,23,-1,39,54,40,31,35,34,48,50,49,38,-1,6,35,34,56,55,5,-1,6,35,38,19,-1,34,56,57,59,58,48,-1,60,61,21,19,38,49,-1,62,50,48,58,-1,60,63,64,62,50,49,-1,5,6,19,21,20,12,-1,55,5,12,65,-1,66,67,65,55,56,57,-1,63,66,57,59,64,-1,64,62,58,59,-1,60,63,66,67,68,61,-1,61,68,20,21,-1,67,68,20,12,65])))
13714         self.assertTrue(m3.getNodalConnectivityIndex().isEqual(DataArrayInt([0,9,18,27,36,45,54,63,72,186,286,330,423])))
13715         pass
13716
13717     def testSwig2Tetrahedrize1(self):
13718         d=DataArrayInt([0,3,6,10,14,20])
13719         d2=d.buildExplicitArrOfSliceOnScaledArr(slice(0,5,2))
13720         self.assertTrue(d2.isEqual(DataArrayInt([0,0,0, 2,2,2,2, 4,4,4,4,4,4])))
13721         m=MEDCouplingUMesh("Penta6",3)
13722         m.setCoords(DataArrayDouble([0,0,0,0,1,0,1,0,0,0,0,2,0,1,2,1,0,2],6,3)) ; m.getCoords().setInfoOnComponents(["X","YY","ZZZ"])
13723         m.allocateCells()
13724         m.insertNextCell(NORM_PENTA6,[1,2,0,4,5,3])
13725         st=m.getCoords().getHiddenCppPointer()
13726         c,a,b=m.tetrahedrize(PLANAR_FACE_5)
13727         c.checkCoherency2()
13728         self.assertTrue(a.isEqual(DataArrayInt([0,0,0])))
13729         self.assertEqual(0,b)
13730         self.assertEqual(m.getCoords().getHiddenCppPointer(),c.getCoords().getHiddenCppPointer())
13731         self.assertTrue(c.getNodalConnectivity().isEqual(DataArrayInt([1,2,0,4,4,3,5,0,5,0,2,4])))
13732         del m,c
13733         #
13734         m2=MEDCouplingUMesh("octa12",3)
13735         coords=DataArrayDouble([1.,0.,0.,0.5,0.8660254037844386,0.,-0.5,0.8660254037844387,0.,-1.,1.2246467991473532e-16,0.,-0.5,-0.8660254037844384,0.,0.5,-0.866025403784439,0.,1.,0.,2.,0.5,0.8660254037844386,2.,-0.5,0.8660254037844387,2.,-1.,1.2246467991473532e-16,2.,-0.5,-0.8660254037844384,2.,0.5,-0.866025403784439,2.0],12,3)
13736         m2.setCoords(coords)
13737         m2.allocateCells()
13738         m2.insertNextCell(NORM_HEXGP12,[3,2,1,0,5,4,9,8,7,6,11,10])
13739         c,a,b=m2.tetrahedrize(PLANAR_FACE_5)
13740         c.checkCoherency2()
13741         self.assertTrue(a.isEqual(DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0])))
13742         self.assertEqual(0,b)
13743         self.assertEqual(c.getCoords().getHiddenCppPointer(),coords.getHiddenCppPointer())
13744         self.assertTrue(c.getNodalConnectivity().isEqual(DataArrayInt([3,2,4,9,9,10,8,4,8,4,2,9,2,5,4,8,8,10,11,4,11,4,5,8,2,1,5,8,8,11,7,5,7,5,1,8,1,0,5,7,7,11,6,5,6,5,0,7])))
13745         del m2,coords,c
13746         #
13747         coords=DataArrayDouble([0.,0.,0.,1.,0.,0.,1.,1.,0.,0.,1.,0.,0.,0.,2.,1.,0.,2.,1.,1.,2.,0.,1.,2.],8,3) ; coords.setInfoOnComponents(["X","YY","ZZZ"])
13748         m3=MEDCouplingUMesh("hexa8",3)
13749         m3.setCoords(coords)
13750         m3.allocateCells(0)
13751         m3.insertNextCell(NORM_HEXA8,[3,2,1,0,7,6,5,4])
13752         st=m3.getCoords().getHiddenCppPointer()
13753         c,a,b=m3.tetrahedrize(PLANAR_FACE_5)
13754         c.checkCoherency2()
13755         a.isEqual(DataArrayInt([0,0,0,0,0]))
13756         self.assertEqual(0,b)
13757         self.assertEqual(m3.getCoords().getHiddenCppPointer(),coords.getHiddenCppPointer())
13758         self.assertTrue(c.getNodalConnectivity().isEqual(DataArrayInt([3,6,2,1,3,7,6,4,3,0,4,1,6,4,5,1,3,6,1,4])))
13759         #
13760         m4=MEDCouplingUMesh("hexa8",3)
13761         m4.setCoords(coords)
13762         m4.allocateCells(0)
13763         m4.insertNextCell(NORM_HEXA8,[3,2,1,0,7,6,5,4])
13764         c,a,b=m4.tetrahedrize(PLANAR_FACE_6)
13765         c.checkCoherency2()
13766         a.isEqual(DataArrayInt([0,0,0,0,0,0]))
13767         self.assertEqual(0,b)
13768         self.assertEqual(c.getCoords().getHiddenCppPointer(),coords.getHiddenCppPointer())
13769         self.assertTrue(c.getNodalConnectivity().isEqual(DataArrayInt([3,6,2,5,3,2,1,5,3,7,6,5,3,4,7,5,3,1,0,5,3,0,4,5])))
13770         #
13771         m4=MEDCouplingUMesh("hexa8",3)
13772         m4.setCoords(coords)
13773         m4.allocateCells(0)
13774         m4.insertNextCell(NORM_HEXA8,[3,2,1,0,7,6,5,4])
13775         st=m4.getCoords().getHiddenCppPointer()
13776         c,a,b=m4.tetrahedrize(GENERAL_24)
13777         c.checkCoherency2()
13778         a.isEqual(DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]))
13779         self.assertEqual(7,b)
13780         self.assertTrue(c.getCoords().getHiddenCppPointer()!=coords.getHiddenCppPointer())
13781         self.assertTrue(c.getCoords()[:8].isEqual(coords,0))
13782         self.assertTrue(c.getNodalConnectivity().isEqual(DataArrayInt([3,7,8,14,7,6,8,14,6,2,8,14,2,3,8,14,3,2,9,14,2,1,9,14,1,0,9,14,0,3,9,14,3,0,10,14,0,4,10,14,4,7,10,14,7,3,10,14,2,6,11,14,6,5,11,14,5,1,11,14,1,2,11,14,7,4,12,14,4,5,12,14,5,6,12,14,6,7,12,14,1,5,13,14,5,4,13,14,4,0,13,14,0,1,13,14])))
13783         m4CoordsExp=DataArrayDouble([0.,0.,0.,1.,0.,0.,1.,1.,0.,0.,1.,0.,0.,0.,2.,1.,0.,2.,1.,1.,2.,0.,1.,2.,0.5,1.,1.,0.5,0.5,0.,0.,0.5,1.,1.,0.5,1.,0.5,0.5,2.,0.5,0.,1.,0.5,0.5,1.],15,3)
13784         m4CoordsExp.setInfoOnComponents(["X","YY","ZZZ"])
13785         self.assertTrue(c.getCoords().isEqual(m4CoordsExp,1e-12))
13786         self.assertAlmostEqual(2.,c.getMeasureField(False).accumulate()[0],12)
13787         #
13788         m6=MEDCouplingUMesh("hexa8",3)
13789         m6.setCoords(coords)
13790         m6.allocateCells(0)
13791         m6.insertNextCell(NORM_HEXA8,[3,2,1,0,7,6,5,4])
13792         st=m6.getCoords().getHiddenCppPointer()
13793         c,a,b=m6.tetrahedrize(GENERAL_48)
13794         c.checkCoherency2()
13795         a.isEqual(DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]))
13796         self.assertEqual(19,b)
13797         self.assertTrue(c.getCoords().getHiddenCppPointer()!=coords.getHiddenCppPointer())
13798         self.assertTrue(c.getCoords()[:8].isEqual(coords,0))
13799         self.assertTrue(c.getNodalConnectivity().isEqual(DataArrayInt([3,20,8,26,3,8,21,26,3,9,20,26,3,22,9,26,3,21,12,26,3,12,22,26,8,10,2,23,8,2,13,23,8,20,10,23,8,26,20,23,8,13,21,23,8,21,26,23,12,26,21,25,12,21,16,25,12,22,26,25,12,17,22,25,12,16,0,25,12,0,17,25,21,23,13,18,21,13,1,18,21,26,23,18,21,25,26,18,21,1,16,18,21,16,25,18,9,11,20,24,9,20,26,24,9,7,11,24,9,14,7,24,9,26,22,24,9,22,14,24,20,6,10,15,20,10,23,15,20,11,6,15,20,24,11,15,20,23,26,15,20,26,24,15,22,24,26,19,22,26,25,19,22,14,24,19,22,4,14,19,22,25,17,19,22,17,4,19,26,15,23,5,26,23,18,5,26,24,15,5,26,19,24,5,26,18,25,5,26,25,19,5])))
13800         m6CoordsExp=DataArrayDouble([0.,0.,0.,1.,0.,0.,1.,1.,0.,0.,1.,0.,0.,0.,2.,1.,0.,2.,1.,1.,2.,0.,1.,2.,0.5,1.,0.,0.,1.,1.,1.,1.,1.,0.5,1.,2.,0.,0.5,0.,1.,0.5,0.,0.,0.5,2.,1.,0.5,2.,0.5,0.,0.,0.,0.,1.,1.,0.,1.,0.5,0.,2.,0.5,1.,1.,0.5,0.5,0.,0.,0.5,1.,1.,0.5,1.,0.5,0.5,2.,0.5,0.,1.,0.5,0.5,1.],27,3)
13801         m6CoordsExp.setInfoOnComponents(["X","YY","ZZZ"])
13802         self.assertTrue(c.getCoords().isEqual(m6CoordsExp,1e-12))
13803         self.assertAlmostEqual(2.,c.getMeasureField(False).accumulate()[0],12)
13804         #
13805         m7=MEDCouplingUMesh("polyhed",3)
13806         coords=DataArrayDouble([1.,0.,0.,0.5,0.8660254037844386,0.,-0.5,0.8660254037844387,0.,-1.,0.,0.,-0.5,-0.8660254037844384,0.,0.5,-0.866025403784439,0.,1.,0.,2.,0.5,0.8660254037844386,2.,-0.5,0.8660254037844387,2.,-1.,0.,2.,-0.5,-0.8660254037844384,2.,0.5,-0.866025403784439,2.0],12,3) ; coords.setInfoOnComponents(["X","YY","ZZZ"])
13807         m7.setCoords(coords)
13808         m7.allocateCells()
13809         m7.insertNextCell(NORM_POLYHED,[3,2,1,0,5,4,-1,9,10,11,6,7,8,-1,3,9,8,2,-1,2,8,7,1,-1,1,7,6,0,-1,0,6,11,5,-1,5,11,10,4,-1,4,10,9,3])
13810         c,a,b=m7.tetrahedrize(PLANAR_FACE_5)
13811         c.checkCoherency2()
13812         self.assertTrue(a.isEqual(DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])))
13813         self.assertEqual(9,b)
13814         self.assertTrue(c.getNodalConnectivity().isEqual(DataArrayInt([3,2,12,20,2,1,12,20,1,0,12,20,0,5,12,20,5,4,12,20,4,3,12,20,9,10,13,20,10,11,13,20,11,6,13,20,6,7,13,20,7,8,13,20,8,9,13,20,3,9,14,20,9,8,14,20,8,2,14,20,2,3,14,20,2,8,15,20,8,7,15,20,7,1,15,20,1,2,15,20,1,7,16,20,7,6,16,20,6,0,16,20,0,1,16,20,0,6,17,20,6,11,17,20,11,5,17,20,5,0,17,20,5,11,18,20,11,10,18,20,10,4,18,20,4,5,18,20,4,10,19,20,10,9,19,20,9,3,19,20,3,4,19,20])))
13815         self.assertAlmostEqual(5.196152422706635,c.getMeasureField(False).accumulate()[0],12)
13816         m7CoordsExp=DataArrayDouble([1.0,0.0,0.0,0.5,0.8660254037844386,0.0,-0.5,0.8660254037844387,0.0,-1.0,0.,0.0,-0.5,-0.8660254037844384,0.0,0.5,-0.866025403784439,0.0,1.0,0.0,2.0,0.5,0.8660254037844386,2.0,-0.5,0.8660254037844387,2.0,-1.0,0.,2.0,-0.5,-0.8660254037844384,2.0,0.5,-0.866025403784439,2.0,0.0,0.0,0.0,0.0,0.,2.0,-0.75,0.4330127018922194,1.0,0.0,0.8660254037844386,1.0,0.75,0.4330127018922193,1.0,0.75,-0.4330127018922195,1.0,0.0,-0.8660254037844387,1.0,-0.75,-0.4330127018922191,1.0,0.0,0.,1.0],21,3)
13817         m7CoordsExp.setInfoOnComponents(["X","YY","ZZZ"])
13818         self.assertTrue(c.getCoords().isEqual(m7CoordsExp,1e-12))
13819         del m7,coords,c
13820         #
13821         coords=DataArrayDouble([0.,0.,0.,1.,0.,0.,1.,1.,0.,0.,1.,0.,0.,0.,2.,1.,0.,2.,1.,1.,2.,0.,1.,2.],8,3) ; coords.setInfoOnComponents(["X","YY","ZZZ"])
13822         m8=MEDCouplingUMesh("pyra5",3)
13823         m8.setCoords(coords)
13824         m8.allocateCells(0)
13825         m8.insertNextCell(NORM_PYRA5,[3,2,1,0,7])
13826         st=m8.getCoords().getHiddenCppPointer()
13827         c,a,b=m8.tetrahedrize(PLANAR_FACE_5)
13828         self.assertEqual(m8.getCoords().getHiddenCppPointer(),coords.getHiddenCppPointer())
13829         c.checkCoherency2()
13830         self.assertTrue(a.isEqual(DataArrayInt([0,0])))
13831         self.assertEqual(0,b)
13832         self.assertTrue(c.getNodalConnectivity().isEqual(DataArrayInt([3,2,1,7,3,1,0,7])))
13833         self.assertAlmostEqual(0.6666666666666667,c.getMeasureField(False).accumulate()[0],12)
13834         pass
13835
13836     def testDualMesh3D1(self):
13837         arr=DataArrayDouble(2) ; arr.iota()
13838         c=MEDCouplingCMesh() ; c.setCoords(arr,arr,arr)
13839         m=c.buildUnstructured()
13840         t=m.tetrahedrize(PLANAR_FACE_5)[0]
13841         d=t.computeDualMesh()
13842         self.assertTrue(d.getNodalConnectivityIndex().isEqual(DataArrayInt([0,29,118,207,236,325,354,383,472])))
13843         self.assertTrue(d.getNodalConnectivity().isEqual(DataArrayInt([26,11,42,8,-1,25,8,42,10,-1,29,10,42,11,-1,0,26,8,25,-1,0,25,10,29,-1,0,29,11,26,24,9,42,8,-1,26,8,42,11,-1,27,11,42,9,-1,1,24,8,26,-1,1,26,11,27,-1,30,13,43,12,-1,24,12,43,15,-1,32,15,43,13,-1,1,30,12,24,-1,1,32,13,30,-1,35,17,44,16,-1,32,16,44,19,-1,27,19,44,17,-1,1,35,16,32,-1,1,27,17,35,-1,24,15,46,9,-1,27,9,46,19,-1,32,19,46,15,27,9,42,11,-1,29,11,42,10,-1,28,10,42,9,-1,2,29,10,28,-1,2,27,11,29,-1,27,17,44,19,-1,38,19,44,18,-1,37,18,44,17,-1,2,37,17,27,-1,2,38,18,37,-1,28,21,45,23,-1,41,23,45,22,-1,38,22,45,21,-1,2,41,22,38,-1,2,28,23,41,-1,27,19,46,9,-1,28,9,46,21,-1,38,21,46,19,35,16,44,17,-1,36,18,44,16,-1,37,17,44,18,-1,3,36,16,35,-1,3,35,17,37,-1,3,37,18,36,24,8,42,9,-1,25,10,42,8,-1,28,9,42,10,-1,4,25,8,24,-1,4,28,10,25,-1,24,15,43,12,-1,31,12,43,14,-1,34,14,43,15,-1,4,24,12,31,-1,4,31,14,34,-1,34,21,45,20,-1,40,20,45,23,-1,28,23,45,21,-1,4,34,20,40,-1,4,40,23,28,-1,24,9,46,15,-1,28,21,46,9,-1,34,15,46,21,30,12,43,13,-1,31,14,43,12,-1,33,13,43,14,-1,5,31,12,30,-1,5,30,13,33,-1,5,33,14,31,40,23,45,20,-1,39,20,45,22,-1,41,22,45,23,-1,6,40,20,39,-1,6,39,22,41,-1,6,41,23,40,32,13,43,15,-1,34,15,43,14,-1,33,14,43,13,-1,7,33,13,32,-1,7,34,14,33,-1,32,19,44,16,-1,36,16,44,18,-1,38,18,44,19,-1,7,32,16,36,-1,7,36,18,38,-1,34,20,45,21,-1,39,22,45,20,-1,38,21,45,22,-1,7,39,20,34,-1,7,38,22,39,-1,32,15,46,19,-1,38,19,46,21,-1,34,21,46,15])))
13844         self.assertTrue(d.getCoords().isEqual(DataArrayDouble([0.,0.,0.,1.,0.,0.,0.,1.,0.,1.,1.,0.,0.,0.,1.,1.,0.,1.,0.,1.,1.,1.,1.,1.,0.3333333333333333,0.,0.3333333333333333,0.3333333333333333,0.3333333333333333,0.3333333333333333,0.,0.3333333333333333,0.3333333333333333,0.3333333333333333,0.3333333333333333,0.,0.6666666666666666,0.,0.6666666666666666,1.,0.3333333333333333,0.6666666666666666,0.6666666666666666,0.3333333333333333,1.,0.6666666666666666,0.3333333333333333,0.6666666666666666,1.,0.6666666666666666,0.3333333333333333,0.6666666666666666,0.6666666666666666,0.,0.6666666666666666,1.,0.3333333333333333,0.6666666666666666,0.6666666666666666,0.3333333333333333,0.3333333333333333,0.6666666666666666,1.,0.3333333333333333,0.6666666666666666,0.6666666666666666,0.3333333333333333,1.,0.6666666666666666,0.,0.6666666666666666,0.6666666666666666,0.5,0.,0.5,0.,0.,0.5,0.5,0.,0.,0.5,0.5,0.,0.,0.5,0.5,0.,0.5,0.,1.,0.,0.5,0.5,0.,1.,1.,0.5,0.5,1.,0.5,1.,0.5,0.5,1.,1.,0.5,0.,1.,1.,0.5,0.5,1.,0.,0.5,1.,0.5,0.5,1.,1.,0.,0.5,1.,0.,1.,0.5,0.25,0.25,0.25,0.75,0.25,0.75,0.75,0.75,0.25,0.25,0.75,0.75,0.5,0.5,0.5],47,3),1e-12))
13845         self.assertAlmostEqual(1.,d.getMeasureField(False).accumulate()[0],1e-13)
13846         pass
13847
13848     def testDualMesh2D1(self):
13849         arr=DataArrayDouble(5) ; arr.iota()
13850         c=MEDCouplingCMesh() ; c.setCoords(arr,arr)
13851         m=c.buildUnstructured()
13852         m.simplexize(0)
13853         t=MEDCoupling1SGTUMesh(m)
13854         d=t.computeDualMesh()
13855         self.assertTrue(d.getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,12,20,28,34,42,54,66,78,86,94,106,118,130,138,146,158,170,182,190,196,204,212,220,224])))
13856         self.assertTrue(d.getNodalConnectivity().isEqual(DataArrayInt([26,81,25,0,25,81,27,82,29,83,30,1,30,83,31,84,33,85,34,2,34,85,35,86,37,87,38,3,38,87,39,88,41,4,27,81,26,5,42,89,28,82,29,82,28,89,43,90,45,91,32,84,31,83,33,84,32,91,46,92,48,93,36,86,35,85,37,86,36,93,49,94,51,95,40,88,39,87,41,88,40,95,52,96,54,9,43,89,42,10,55,97,44,90,45,90,44,97,56,98,58,99,47,92,46,91,48,92,47,99,59,100,61,101,50,94,49,93,51,94,50,101,62,102,64,103,53,96,52,95,54,96,53,103,65,104,67,14,56,97,55,15,68,105,57,98,58,98,57,105,69,106,71,107,60,100,59,99,61,100,60,107,72,108,74,109,63,102,62,101,64,102,63,109,75,110,77,111,66,104,65,103,67,104,66,111,78,112,80,19,69,105,68,20,70,106,71,106,70,21,73,108,72,107,74,108,73,22,76,110,75,109,77,110,76,23,79,112,78,111,80,112,79,24])))
13857         self.assertTrue(d.getCoords().isEqual(DataArrayDouble([0.,0.,1.,0.,2.,0.,3.,0.,4.,0.,0.,1.,1.,1.,2.,1.,3.,1.,4.,1.,0.,2.,1.,2.,2.,2.,3.,2.,4.,2.,0.,3.,1.,3.,2.,3.,3.,3.,4.,3.,0.,4.,1.,4.,2.,4.,3.,4.,4.,4.,0.5,0.,0.,0.5,0.5,0.5,0.5,1.,1.,0.5,1.5,0.,1.5,0.5,1.5,1.,2.,0.5,2.5,0.,2.5,0.5,2.5,1.,3.,0.5,3.5,0.,3.5,0.5,3.5,1.,4.,0.5,0.,1.5,0.5,1.5,0.5,2.,1.,1.5,1.5,1.5,1.5,2.,2.,1.5,2.5,1.5,2.5,2.,3.,1.5,3.5,1.5,3.5,2.,4.,1.5,0.,2.5,0.5,2.5,0.5,3.,1.,2.5,1.5,2.5,1.5,3.,2.,2.5,2.5,2.5,2.5,3.,3.,2.5,3.5,2.5,3.5,3.,4.,2.5,0.,3.5,0.5,3.5,0.5,4.,1.,3.5,1.5,3.5,1.5,4.,2.,3.5,2.5,3.5,2.5,4.,3.,3.5,3.5,3.5,3.5,4.,4.,3.5,0.3333333333333333,0.3333333333333333,0.6666666666666666,0.6666666666666666,1.3333333333333333,0.3333333333333333,1.6666666666666665,0.6666666666666666,2.333333333333333,0.3333333333333333,2.6666666666666665,0.6666666666666666,3.333333333333333,0.3333333333333333,3.6666666666666665,0.6666666666666666,0.3333333333333333,1.3333333333333333,0.6666666666666666,1.6666666666666665,1.3333333333333333,1.3333333333333333,1.6666666666666665,1.6666666666666665,2.333333333333333,1.3333333333333333,2.6666666666666665,1.6666666666666665,3.333333333333333,1.3333333333333333,3.6666666666666665,1.6666666666666665,0.3333333333333333,2.333333333333333,0.6666666666666666,2.6666666666666665,1.3333333333333333,2.333333333333333,1.6666666666666665,2.6666666666666665,2.333333333333333,2.333333333333333,2.6666666666666665,2.6666666666666665,3.333333333333333,2.333333333333333,3.6666666666666665,2.6666666666666665,0.3333333333333333,3.333333333333333,0.6666666666666666,3.6666666666666665,1.3333333333333333,3.333333333333333,1.6666666666666665,3.6666666666666665,2.333333333333333,3.333333333333333,2.6666666666666665,3.6666666666666665,3.333333333333333,3.333333333333333,3.6666666666666665,3.6666666666666665],113,2),1e-12))
13858         self.assertAlmostEqual(16.,d.getMeasureField(False).accumulate()[0],1e-13)
13859         pass
13860
13861     def testSwig2LoadBalanceBBox1(self):
13862         arr=DataArrayDouble(5) ; arr.iota()
13863         t=MEDCouplingCMesh() ; t.setCoords(arr,arr)
13864         arr=DataArrayDouble(16) ; arr.iota() ; arr*=2./15
13865         s=MEDCouplingCMesh() ; s.setCoords(arr,arr[:]) ; s.translate([2.,1.])
13866         #
13867         s1=s.build1SGTUnstructured()
13868         t1=t.build1SGTUnstructured()
13869         w=MEDCouplingPointSet.ComputeNbOfInteractionsWithSrcCells(s1,t1,1e-12)
13870         wExp=DataArrayInt([0,0,0,0,0,0,64,64,0,0,64,64,0,0,0,0])
13871         self.assertTrue(w.isEqual(wExp))
13872         slcs=w.splitInBalancedSlices(4)
13873         self.assertEqual(len(slcs),4)
13874         self.assertEqual(slcs,[slice(0,7,1),slice(7,8,1),slice(8,11,1),slice(11,16,1)])
13875         bbs=s1.getBoundingBoxForBBTree()
13876         bbt=t1.getBoundingBoxForBBTree()
13877         self.assertTrue(bbt.computeNbOfInteractionsWith(bbs,1e-12).isEqual(wExp))
13878         pass
13879
13880     def testKrSpatialDiscretization2(self):
13881         srcPointCoordsXY=DataArrayDouble([0.8401877171547095,0.39438292681909304,0.7830992237586059,0.7984400334760733,0.9116473579367843,0.19755136929338396,0.335222755714889,0.768229594811904,0.2777747108031878,0.5539699557954305,0.47739705186216025,0.6288709247619244,0.36478447279184334,0.5134009101956155,0.9522297251747128,0.9161950680037007,0.6357117279599009,0.7172969294326831,0.14160255535580338,0.6069688762570586,0.01630057162432958,0.24288677062973696,0.13723157678601872,0.8041767542269904,0.15667908925408455,0.4009443942461835,0.12979044678145574,0.10880880202576929,0.998924518003559,0.21825690531090688,0.5129323944043984,0.8391122346926072,0.6126398325956612,0.29603161769734304,0.6375522677030192,0.5242871900667843,0.493582986990727,0.9727750238835695,0.29251678441302703,0.7713576977939148,0.5267449792133388,0.7699138362751873,0.4002286220901779,0.8915294520051822,0.2833147460051415,0.3524583472648907,0.8077245200088827,0.9190264739650424,0.06975527623191256,0.9493270753646861,0.5259953502221011,0.08605584785624214,0.19221384599442307,0.6632269270081198,0.8902326025488938,0.3488929352485076,0.06417132078864207,0.02002304886468828,0.4577017372742769,0.06309583832653977,0.23827995417559517,0.9706341316786754,0.9022080734848082,0.8509197867712563,0.2666657493760184,0.5397603407221662,0.3752069763723793,0.7602487363667454,0.5125353641400744,0.6677237607854063,0.5316064341606602,0.039280343353413204,0.4376375965949323,0.9318350562508382,0.9308097953585953,0.7209523430657351,0.28429340305006756,0.7385343149018168,0.6399788165651163,0.3540486797476414,0.687861390266503,0.16597416632155615,0.4401045276038835,0.880075236260926,0.829201093329676,0.3303371296871161,0.22896817104377232,0.8933724145839793,0.35036017855180435,0.6866699083180492,0.9564682529105192,0.5886401331930609,0.6573040395310633,0.8586763259296661,0.4395599194986559,0.9239697889070817,0.39843666665183225,0.8147668963366965,0.6842185252738271,0.9109720307919067,0.4824906566564416,0.21582495896882609,0.9502523741453198,0.9201282537170352,0.14766001475400292,0.8810621695039152,0.641080596317109,0.43195341826973177,0.6195964839400707,0.281059412416564,0.7860020980173732,0.3074578737409124,0.44703357920378145,0.22610662515559543,0.18753310953617705,0.27623467206779617,0.5564437553083728,0.4165012805799494,0.16960708618611428,0.9068039338601771,0.10317118843233734,0.1260753390966334,0.49544406658757667,0.7604752284290619,0.9847516650262995,0.9350039865518939,0.6844450168704823,0.3831883312124705,0.7497708824229291,0.36866354167864823,0.2941603620043771,0.2322615386137094,0.5844885006474743,0.24441273568403568,0.15238979186508328,0.7321485158671385,0.12547490472228962,0.7934703881821923,0.164101933671209,0.7450713891280216,0.07452980059875632,0.9501040316885822,0.05252926240327268,0.5215633798025378,0.1762106563785163,0.24006237240511102,0.797798051870334,0.732654411686889,0.6565636529850605,0.9674051385221095,0.6394583455470663,0.7597348418830591,0.09348047715308166,0.13490241166898162,0.5202100698464597,0.07823214171371988,0.06990639775521419,0.2046550862512808,0.4614204733918516,0.8196772801781433,0.5733186283955903,0.7555808353962288,0.05193881879185271,0.1578071285774033,0.9999935710802644,0.204328610656936,0.8899556444445419,0.12546847580255405,0.9977989993047895,0.054057577650089554,0.8705398649305757,0.07232879943788462,0.004161608873010431,0.9230691273338484,0.5938921792404224,0.180372265717188,0.16313149927329806,0.3916902306450951,0.9130266774040771,0.8196951527240198,0.35909536870154335,0.552485022485482,0.5794299941414176,0.452575845854625,0.687387434620125,0.09964006352221597,0.5308079880340062,0.7572938323753392,0.30429514977349675,0.9922284614258579,0.5769711125534824,0.877613778169087,0.7478092963564253,0.6289099313453351,0.03542090674649035,0.7478028669710285,0.8332385420022712,0.9253765511910322,0.8732713427735824,0.8310375408413995],100,2)
13882         srcFieldValsOnPoints=DataArrayDouble([0.7643742528498438,-0.023507696856211995,1.1082895131907775,0.6299357452572031,0.8892623544912389,0.72212114810697,0.9196401044320336,-0.759961711221917,0.40801932617748826,0.8441134300809151,0.982483804252809,0.6752368914020778,0.9924403977479798,1.1063334970204484,0.9403055261137516,0.3624481886322733,1.1344772505996308,0.7522965618948239,0.17077741651388564,0.6504551671311436,0.45843479588425423,0.41098905950326753,1.0681420394050904,-0.3483587903820091,0.5620151050607809,1.384969776596035,0.7948875141132845,0.7931192000237167,1.062498042490183,1.3709072529577366,0.44929346605311893,-0.4469683401788374,0.9035857424514101,0.6137249300593463,0.6355610879026966,1.4318174829507697,0.3097567072129551,-0.20515052260807165,0.6922559820922779,1.0341638749443423,1.3072652153341024,0.38511367353000436,0.9160514929274943,0.54513408530581,0.722252267913328,0.06684522818576251,0.10571899758067793,0.3193844999960903,0.5213532270828706,-0.04834998649603944,1.2408805068350615,-0.7632951295676795,0.5980054665011202,0.9064738717547436,1.1541070755096696,1.008234260272265,1.2225806960553827,1.0788560195121106,0.9818990282104452,0.5621951325841853,1.0796757508374188,0.5082872315589883,-0.9153702001062469,0.9560418838920791,0.9251098559152824,1.1603063610984021,1.2122303611181837,0.7379539363312343,0.6877611899207183,0.723966552446608,0.5596025827162566,0.8849725005989729,1.0908363665075547,0.08956512916455672,-0.10247645571248344,0.3236718069555875,1.069478546398975,1.3900071080692746,1.0322398863403262,0.45315515354558034,0.4249870238786733,1.030226761858634,0.974024629584669,1.2838885424020365,1.3451943506525155,1.4029933267831995,0.6025539675442462,1.2947650597767038,1.0006061239483002,-0.4017336259949164,0.8771165113201297,0.9158909024218246,1.403798605551443,0.4742904006425974,0.3671787905896653,0.20646491720419674,0.40739337434288925,0.7341932402033597,-0.4295893651836911,-0.3187777570661546],100,1)
13883         targetPointCoordsXY=DataArrayDouble([-0.5,-0.5,-0.5,-0.35,-0.5,-0.2,-0.5,-0.05,-0.5,0.1,-0.5,0.25,-0.5,0.4,-0.5,0.55,-0.5,0.7,-0.5,0.85,-0.5,1.0,-0.5,1.15,-0.5,1.3,-0.5,1.45,-0.35,-0.5,-0.35,-0.35,-0.35,-0.2,-0.35,-0.05,-0.35,0.1,-0.35,0.25,-0.35,0.4,-0.35,0.55,-0.35,0.7,-0.35,0.85,-0.35,1.0,-0.35,1.15,-0.35,1.3,-0.35,1.45,-0.2,-0.5,-0.2,-0.35,-0.2,-0.2,-0.2,-0.05,-0.2,0.1,-0.2,0.25,-0.2,0.4,-0.2,0.55,-0.2,0.7,-0.2,0.85,-0.2,1.0,-0.2,1.15,-0.2,1.3,-0.2,1.45,-0.05,-0.5,-0.05,-0.35,-0.05,-0.2,-0.05,-0.05,-0.05,0.1,-0.05,0.25,-0.05,0.4,-0.05,0.55,-0.05,0.7,-0.05,0.85,-0.05,1.0,-0.05,1.15,-0.05,1.3,-0.05,1.45,0.1,-0.5,0.1,-0.35,0.1,-0.2,0.1,-0.05,0.1,0.1,0.1,0.25,0.1,0.4,0.1,0.55,0.1,0.7,0.1,0.85,0.1,1.0,0.1,1.15,0.1,1.3,0.1,1.45,0.25,-0.5,0.25,-0.35,0.25,-0.2,0.25,-0.05,0.25,0.1,0.25,0.25,0.25,0.4,0.25,0.55,0.25,0.7,0.25,0.85,0.25,1.0,0.25,1.15,0.25,1.3,0.25,1.45,0.4,-0.5,0.4,-0.35,0.4,-0.2,0.4,-0.05,0.4,0.1,0.4,0.25,0.4,0.4,0.4,0.55,0.4,0.7,0.4,0.85,0.4,1.0,0.4,1.15,0.4,1.3,0.4,1.45,0.55,-0.5,0.55,-0.35,0.55,-0.2,0.55,-0.05,0.55,0.1,0.55,0.25,0.55,0.4,0.55,0.55,0.55,0.7,0.55,0.85,0.55,1.0,0.55,1.15,0.55,1.3,0.55,1.45,0.7,-0.5,0.7,-0.35,0.7,-0.2,0.7,-0.05,0.7,0.1,0.7,0.25,0.7,0.4,0.7,0.55,0.7,0.7,0.7,0.85,0.7,1.0,0.7,1.15,0.7,1.3,0.7,1.45,0.85,-0.5,0.85,-0.35,0.85,-0.2,0.85,-0.05,0.85,0.1,0.85,0.25,0.85,0.4,0.85,0.55,0.85,0.7,0.85,0.85,0.85,1.0,0.85,1.15,0.85,1.3,0.85,1.45,1.0,-0.5,1.0,-0.35,1.0,-0.2,1.0,-0.05,1.0,0.1,1.0,0.25,1.0,0.4,1.0,0.55,1.0,0.7,1.0,0.85,1.0,1.0,1.0,1.15,1.0,1.3,1.0,1.45,1.15,-0.5,1.15,-0.35,1.15,-0.2,1.15,-0.05,1.15,0.1,1.15,0.25,1.15,0.4,1.15,0.55,1.15,0.7,1.15,0.85,1.15,1.0,1.15,1.15,1.15,1.3,1.15,1.45,1.3,-0.5,1.3,-0.35,1.3,-0.2,1.3,-0.05,1.3,0.1,1.3,0.25,1.3,0.4,1.3,0.55,1.3,0.7,1.3,0.85,1.3,1.0,1.3,1.15,1.3,1.3,1.3,1.45,1.45,-0.5,1.45,-0.35,1.45,-0.2,1.45,-0.05,1.45,0.1,1.45,0.25,1.45,0.4,1.45,0.55,1.45,0.7,1.45,0.85,1.45,1.0,1.45,1.15,1.45,1.3,1.45,1.45],196,2)
13884         targetFieldValsExpected=DataArrayDouble([1.645976003316459, 1.454458180060204, 1.286087532859835, 1.147305389930914, 1.040143042030752, 0.9592075185603157, 0.8932542207607532, 0.8296417057622609, 0.7572539678257579, 0.6669048311361028, 0.551329882743212, 0.4064445075734602, 0.2323703965460786, 0.03253142054561309, 1.615321686989539, 1.414941300553572, 1.238383118538708, 1.096701655702075, 0.9955792747382535, 0.9271194507282707, 0.8741000712825546, 0.8201879508155141, 0.7537335933761495, 0.6656210809234322, 0.5470285414729397, 0.3927301586610237, 0.2044036897887453, -0.01181672742825013, 1.609602552867195, 1.400625195269133, 1.213287847440801, 1.065318574929208, 0.9717609562002842, 0.9182626517777217, 0.8760698972315855, 0.8258196104516153, 0.7586487405165288, 0.6686168424854784, 0.5434121624038266, 0.3741815029337978, 0.1661376046619205, -0.0704038088420833, 1.635421686625182, 1.422642113482769, 1.225977424080963, 1.066864693789366, 0.9864801043792362, 0.9486639217909161, 0.9075176697327381, 0.8471248730261529, 0.7660983406349626, 0.6675300501188994, 0.5320013361909732, 0.3404583135353376, 0.1074346390951333, -0.1520751802856468, 1.695346918429566, 1.489526279573347, 1.297678617961701, 1.139921240332637, 1.080508463804929, 1.036847769764088, 0.9687840669352359, 0.8790397822170175, 0.76938768351059, 0.6441978169925557, 0.4915328571013788, 0.2742929463574293, 0.0148214290833748, -0.2671755287427691, 1.782761788232491, 1.59423004798623, 1.422317125787222, 1.286999529473285, 1.20500638941831, 1.127058114031519, 1.022332539190471, 0.8945753999401338, 0.7469190939381181, 0.582396906110898, 0.4015920181411496, 0.1584700483835366, -0.1251860255418387, -0.4254052799545267, 1.881794862747652, 1.712890309994015, 1.557517508390291, 1.422727414977963, 1.308048056353061, 1.187569766723152, 1.03942150436647, 0.8677583087532357, 0.6766652050643343, 0.4703897480238999, 0.2497994532908829, -0.02005989176786582, -0.3224387891441491, -0.6331519303649853, 1.973114284621266, 1.820187301531605, 1.673403730111759, 1.528504440482262, 1.379693463484634, 1.207642134784147, 1.008217764780293, 0.7863328498822348, 0.5465383049529959, 0.2944879513187435, 0.03250657765404452, -0.2670900851421072, -0.5806516907976924, -0.8911331026431459, 2.038729888975378, 1.895652364645637, 1.751759791756183, 1.594035761810714, 1.403016809171641, 1.171403152610878, 0.913267035125007, 0.6343281031932027, 0.3434843176189371, 0.04195410032095204, -0.2645533663891493, -0.58577400250975, -0.8958218846257981, -1.192230697656513, 2.064018033720731, 1.922048791644444, 1.773847180028208, 1.600340336378483, 1.361620036333164, 1.060873411411508, 0.7373484802125152, 0.3868966266761109, 0.04316272760227413, -0.3009370030949727, -0.6505233805563486, -0.9669887470696283, -1.250005719852354, -1.519122595631787, 2.039938287785342, 1.887400820799651, 1.722008733683987, 1.523879290022419, 1.23834392230135, 0.8606985727866472, 0.4844892131548788, 0.08077959236877175, -0.3195742594962179, -0.726291368696764, -1.094357645641832, -1.359078900303776, -1.604725656501341, -1.845297168323687, 1.965762248218393, 1.791665198563286, 1.595056719739704, 1.353692777435502, 1.033006623003495, 0.6416349531117889, 0.2290046916364761, -0.1993180965088852, -0.6311618804827295, -1.051489875129883, -1.409404344854132, -1.681249363331096, -1.917859637689007, -2.145034400762945, 1.849053542205925, 1.648479366622312, 1.418493963148431, 1.141939527533839, 0.8042385795619003, 0.4127534639189761, -0.008572116677791453, -0.4428317297963555, -0.8745477268718713, -1.281769237471681, -1.635421857742795, -1.926210204560556, -2.175577364628722, -2.405762639746138, 1.701519686999922, 1.475879908746998, 1.219065416294153, 0.9203732349759972, 0.5740137315474942, 0.1856460506119944, -0.2298288912529738, -0.6558565521653752, -1.075391078040103, -1.469402631469075, -1.820558929095151, -2.123592211415966, -2.388177455227765, -2.628832075944413])
13885         coeffsExpected=DataArrayDouble([0.3953237723894342,-0.17220705170185724,0.620727139132215,-0.01938292763088709,-0.007524685306185282,0.0016277944443884584,-0.0005209587893117361,-1.8992696595839718,-0.13154330748345855,0.11248800965389728,-0.47310750305033406,0.03685741122098605,0.21362468750754374,0.8082608687799991,-0.6775548200221704,-0.027683208482275873,-0.007806877014495724,-0.013539239795959668,0.3478535665778018,0.005145793726360813,0.03708618549628136,-0.18235332489209385,-0.04517273339177797,-0.081755114492025,0.12791746560435255,0.09659355695676189,-0.024809653129318366,0.08327587452569823,-1.790380673650165,-0.10622983512164165,0.14989029282340274,0.05949513762355707,0.004548072841131278,0.011252095917834793,-0.004848057194721367,-0.2658537133108412,0.016651579133606154,-0.021640915366981317,0.008975511042160175,-0.021052213988815974,-0.09347841701844657,0.03533229488135717,-0.014556185287109863,-0.27228591670520086,0.002989987191209683,-0.5489428537951813,-0.02134456783001304,-0.22462281620064825,0.005230853443767429,-0.1894678262257301,0.0033140729457334884,5.295483062326795,-0.2724500716060311,0.026433905662192683,0.01368706308878908,-0.03014264855048227,0.053679001877659956,0.08109477254132096,-0.005004603067203444,0.016907143132293558,0.2105509502082437,0.003657404455024417,-4.904755847017426,0.01634808163992959,-0.008325515865305198,0.062188432751569676,-0.013114633511406406,0.11020519384963083,-0.008599402366091309,-0.012125149710784723,0.31723729052927313,-0.10298398036815914,-0.07250078775612204,0.39976713701763433,0.45897498107347223,0.01018626210400031,0.20163425809089347,0.19729093298588943,0.42863333455911523,0.015595097081693168,0.06060353651437489,-0.16379444813161725,-0.43290344196574165,-0.5931022701412187,1.1906610004748832,0.44418106894148945,0.06536220001548931,0.010261694323554562,-0.05943099382075491,-0.04939614579484797,0.002234505477641322,-0.011262130967449935,0.09644905007708474,-0.029518792883267808,0.41564004027396634,-0.18459770295961597,0.3100981306103734,-0.2509873737065425,0.5434321443668653,0.3009912967350914,1.9560655796099518,-0.7143435150084513,-1.5123449469879784])
13886         #
13887         nbOfInputPoints=100;
13888         f=MEDCouplingFieldDouble.New(ON_NODES_KR,ONE_TIME);
13889         mesh=MEDCoupling1SGTUMesh.New("aMesh",NORM_POINT1);
13890         mesh.setCoords(srcPointCoordsXY);
13891         f.setMesh(mesh);
13892         f.setArray(srcFieldValsOnPoints);
13893         f.checkCoherency();
13894         #
13895         res0=f.getValueOn([-0.5,-0.5]);
13896         self.assertAlmostEqual(targetFieldValsExpected.getIJ(0,0),res0[0],10)
13897         #
13898         valuesToTest=f.getValueOnMulti(targetPointCoordsXY);
13899         self.assertEqual(196,valuesToTest.getNumberOfTuples());
13900         self.assertEqual(1,valuesToTest.getNumberOfComponents());
13901         for i in xrange(40):
13902             self.assertAlmostEqual(targetFieldValsExpected[i],valuesToTest.getIJ(i,0),10)
13903             pass
13904         fd=f.getDiscretization()
13905         del f
13906         self.assertTrue(isinstance(fd,MEDCouplingFieldDiscretizationKriging))
13907         coeffs,isDrift=fd.computeVectorOfCoefficients(mesh,srcFieldValsOnPoints)
13908         self.assertEqual(3,isDrift)
13909         self.assertTrue(coeffsExpected.isEqual(coeffs,1e-8))
13910         # testing matrix
13911         pts3=[-0.5,-0.5,-0.5,-0.35,-0.35,-0.2]
13912         mesh.setCoords(srcPointCoordsXY[:4])
13913         m,nbCols=fd.computeEvaluationMatrixOnGivenPts(mesh,pts3)
13914         self.assertTrue(m.isEqual(DataArrayDouble([0.05768877688524917,-4.438982030395039,1.9495386255911573,3.431754627918642,0.11803848510231275,-4.138339658420563,1.6630742187104417,3.357226954607818,0.14630203028580618,-3.5156045565871734,1.414680070737206,2.954622455564169]),1e-12))
13915         if MEDCouplingHasNumPyBindings():
13916             import numpy as np
13917             m0=m.toNumPyArray() ; m0=m0.reshape(3,nbCols) ; m0=np.matrix(m0)
13918             srcFieldValsOnPoints2=DataArrayDouble(4,2) ; srcFieldValsOnPoints2[:,0]=srcFieldValsOnPoints[:4] ; srcFieldValsOnPoints2[:,1]=2*srcFieldValsOnPoints[:4]
13919             n0=srcFieldValsOnPoints2.toNumPyArray() ; n0=n0.reshape(4,2) ; n0=np.matrix(n0)
13920             #
13921             f=MEDCouplingFieldDouble.New(ON_NODES_KR,ONE_TIME) ;  f.setMesh(mesh) ; f.setArray(srcFieldValsOnPoints2) ; f.checkCoherency()
13922             self.assertTrue(DataArrayDouble(np.array((m0*n0))).isEqual(f.getValueOnMulti(pts3),1e-14))
13923             pass
13924         #
13925         pass
13926     
13927     # test the when input slice is all the same object is return by MEDCouplingMesh.buildPartRange
13928     def testSwig2MeshPartSlice1(self):
13929         a=DataArrayDouble(4) ; a.iota()
13930         c=MEDCouplingCMesh() ; c.setCoords(a,a) ; m=c.buildUnstructured()
13931         fc0=c.getMeasureField(False) ; fc1=fc0[:] ; fc2=fc0*fc1 ; fc2.setName(fc0.getName())
13932         self.assertEqual(fc0.getMesh().getHiddenCppPointer(),fc1.getMesh().getHiddenCppPointer())
13933         self.assertEqual(fc2.getMesh().getHiddenCppPointer(),fc1.getMesh().getHiddenCppPointer())
13934         self.assertTrue(fc2.isEqual(fc1,1e-12,1e-12))
13935         #
13936         fm0=m.getMeasureField(False) ; fm1=fm0[:] ; fm2=fm0*fm1 ; fm2.setName(fm0.getName())
13937         self.assertEqual(fm0.getMesh().getHiddenCppPointer(),fm1.getMesh().getHiddenCppPointer())
13938         self.assertEqual(fm2.getMesh().getHiddenCppPointer(),fm1.getMesh().getHiddenCppPointer())
13939         self.assertTrue(fm2.isEqual(fm1,1e-12,1e-12))
13940         pass
13941
13942     # test the correct behaviour when attempting to aggregate two fields whose mesh is null
13943     def testSwig2MergeFieldsOnFieldsHavingNoMesh(self):
13944         a=DataArrayDouble(4) ; a.iota() ; a*=1.5
13945         c=MEDCouplingCMesh() ; c.setCoords(a,a) ; f1=c.getMeasureField(False)
13946         f1.setMesh(None) ; f2=f1.deepCpy() ; f2*=2
13947         f3=MEDCouplingFieldDouble.MergeFields(f1,f2)
13948         daExp=DataArrayDouble([2.25,2.25,2.25,2.25,2.25,2.25,2.25,2.25,2.25,4.5,4.5,4.5,4.5,4.5,4.5,4.5,4.5,4.5])
13949         self.assertTrue(f3.getArray().isEqual(daExp,1e-12))
13950         self.assertEqual(f3.getTypeOfField(),ON_CELLS)
13951         self.assertEqual(f3.getMesh(),None)
13952         f4=MEDCouplingFieldDouble.MergeFields([f1,f2])
13953         self.assertTrue(f4.getArray().isEqual(daExp,1e-12))
13954         self.assertEqual(f4.getTypeOfField(),ON_CELLS)
13955         self.assertEqual(f4.getMesh(),None)
13956         pass
13957
13958     # test a simple node to cell convertion of a field
13959     def testSwig2NodeToCellDiscretization1(self):
13960         f=MEDCouplingFieldDouble(ON_NODES) ; f.setTime(1.1,2,3)
13961         a1=DataArrayDouble(4) ; a1.iota()
13962         a2=DataArrayDouble(3) ; a2.iota()
13963         m=MEDCouplingCMesh() ; m.setCoords(a1,a2)
13964         f.setMesh(m)
13965         arr=DataArrayDouble([21.,121.,20.,120.,19.,119.,18.,118.,17.,117.,16.,116.,15.,115.,14.,114.,13.,113.,12.,112.,11.,111.,10.,110.],12,2) ; arr.setInfoOnComponents(["aa [km]","bbb [kJ]"])
13966         f.setArray(arr) ; f.setName("toto")
13967         #
13968         f2=f.nodeToCellDiscretization()
13969         self.assertEqual(ON_CELLS,f2.getTypeOfField())
13970         self.assertEqual("toto",f2.getName())
13971         self.assertEqual([1.1,2,3],f2.getTime())
13972         self.assertEqual(["aa [km]","bbb [kJ]"],f2.getArray().getInfoOnComponents())
13973         self.assertEqual(6,f2.getArray().getNumberOfTuples())
13974         self.assertEqual(f.getMesh().getHiddenCppPointer(),f2.getMesh().getHiddenCppPointer())
13975         exp=DataArrayDouble([18.5,118.5,17.5,117.5,16.5,116.5,14.5,114.5,13.5,113.5,12.5,112.5],6,2) ; exp.setInfoOnComponents(["aa [km]","bbb [kJ]"])
13976         self.assertTrue(f2.getArray().isEqual(exp,1e-13))
13977         pass
13978     
13979     def testSwig2NonRegressionBugIntersectMeshes1(self):
13980         src=MEDCouplingUMesh("src",2)
13981         src.setCoords(DataArrayDouble([-2.5,-3,-2.5,3,2.5,3],3,2))
13982         src.allocateCells()
13983         src.insertNextCell(NORM_TRI3,[0,1,2])
13984         #
13985         trg=MEDCouplingUMesh("trg",2)
13986         trg.setCoords(DataArrayDouble([-2.5,-3.,0.,-3.,0.,-2.,-2.,0.,-2.25,0.,-2.5,0.,-2.5,-1.5,0.,-2.5,-1.25,-3.,-1.414213562373095,-1.414213562373095],10,2))
13987         trg.allocateCells()
13988         trg.insertNextCell(NORM_QPOLYG,[2,1,0,5,3,7,8,6,4,9])
13989         #
13990         a,b,c=MEDCouplingUMesh.Intersect2DMeshes(src,trg,1.0e-8)
13991         a.mergeNodes(1e-8)
13992         self.assertTrue(a.getCoords().isEqual(DataArrayDouble([-2.5,-3.,-2.5,3.,2.5,3.,0.,-3.,0.,-2.,-2.,0.,-2.25,0.,-2.5,0.,-2.5,-1.5,0.,-2.5,-1.25,-3.,-1.414213562373095,-1.414213562373095,-1.2803687993289596,-1.5364425591947515,-1.8901843996644798,-2.2682212795973755,-1.81117884244736,-0.8483107924994473,-2.5,1.5,0.,3.,0.6098156003355202,0.7317787204026243],18,2),1e-12))
13993         self.assertTrue(a.getNodalConnectivity().isEqual(DataArrayInt([32,12,0,7,5,13,8,6,14,32,7,1,2,12,5,15,16,17,14,6])))
13994         self.assertTrue(a.getNodalConnectivityIndex().isEqual(DataArrayInt([0,9,20])))
13995         self.assertTrue(b.isEqual(DataArrayInt([0,0])))
13996         self.assertTrue(c.isEqual(DataArrayInt([0,-1])))
13997         pass
13998
13999     def testSwig2MeshOrientCorrectly2DCells1(self):
14000         m=MEDCouplingUMesh("mesh",2)
14001         coo=DataArrayDouble([1.,0.,0.5,-0.1,0.,1.,0.,0.,0.07,0.5,0.59,0.5],6,2)
14002         m.setCoords(coo)
14003         m.allocateCells()
14004         m.insertNextCell(NORM_TRI6,[3,0,2,1,5,4])
14005         m.insertNextCell(NORM_QPOLYG,[3,0,2,1,5,4])
14006         self.assertTrue(DataArrayDouble([-0.58093333350930543,-0.58093333350930543]).isEqual(m.getMeasureField(False).getArray(),1e-12))
14007         m.changeSpaceDimension(3)
14008         m.orientCorrectly2DCells([0.,0.,-1.],False)
14009         #
14010         m.checkCoherency()
14011         self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([6,3,2,0,4,5,1, 32,3,2,0,4,5,1])))
14012         self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,7,14])))
14013         m.changeSpaceDimension(2)
14014         self.assertTrue(DataArrayDouble([0.58093333350930543,0.58093333350930543]).isEqual(m.getMeasureField(False).getArray(),1e-12))
14015         pass
14016
14017     def testSwig2Hexa8HavingFacesWarped1(self):
14018         """ This test is bases on a "error" of interpolation detected. After investigation cell #3 of src is warped that leads to the fact that when trg is 
14019         intersected with src the sum of intersection volume is greater than the volume of the trg cell.
14020         A test that can be done is to split the cell #3 of src into tetrohedrons and by summing all the volumes it does not fit the volume computed of cell#3 unsplitted (expect for
14021         GENERAL_24).
14022         """
14023         srcCoo=DataArrayDouble([0.15694071546650565,0.09383333333333337,6.920842121738133,0.15774332475430292,0.185486666666667,6.920682472824616,0.1585459340420992,0.27713999999999994,6.9205228239111,0.07427195882345167,0.05782666666666668,6.937285959830335,0.06343673343819695,0.11347333333333297,6.939441220162809,0.05260150805294228,0.16911999999999996,6.941596480495282,0.014076262238703396,0.04800666666666667,6.949259628344076,0.014076262238703396,0.07092000000000007,6.949259628344076,0.15407499632681992,0.09383333333333338,6.897607484780063,0.15489234394181514,0.18548666666666702,6.897567331066572,0.15570969155680933,0.27714,6.897527177353081,0.06988819198237989,0.05782666666666669,6.901743317269663,0.05885399917995321,0.11347333333333298,6.9022853924017955,0.047819806377526586,0.16912,6.902827467533927,0.0085871208577874,0.048006666666666684,6.9047548457815076,0.0085871208577874,0.07092000000000008,6.9047548457815076,0.153883333333333,0.09383333333333338,6.820902,0.154701666666667,0.18548666666666702,6.820902,0.15551999999999996,0.27714,6.820902,0.06959499999999999,0.05782666666666669,6.820902,0.058547499999999975,0.11347333333333298,6.820902,0.04749999999999999,0.16912,6.820902],22,3)
14024         src=MEDCouplingUMesh("TBmesh3D",3) ; src.setCoords(srcCoo)
14025         src.allocateCells()
14026         src.insertNextCell(NORM_HEXA8,[0,1,4,3,8,9,12,11])
14027         src.insertNextCell(NORM_HEXA8,[1,2,5,4,9,10,13,12])
14028         src.insertNextCell(NORM_HEXA8,[4,5,7,6,12,13,15,14])
14029         src.insertNextCell(NORM_HEXA8,[8,9,12,11,16,17,20,19])
14030         src.insertNextCell(NORM_HEXA8,[9,10,13,12,17,18,21,20])
14031         src.checkCoherency2()
14032         # trg is useless here but I keep it in case of MEDCouplingRemapper were expected to do something about warped NORM_HEXA8
14033         trgCoo=DataArrayDouble([0.0960891897852753,0.105088620541845,6.8598,0.0599574480546212,0.118434267436059,6.8598,0.113514510609589,0.14874473653263,6.8598,0.0831322609794463,0.167319109733883,6.8598,0.0960891897852753,0.105088620541845,6.92146666666667,0.0599574480546212,0.118434267436059,6.92146666666667,0.113514510609589,0.14874473653263,6.92146666666667,0.0831322609794463,0.167319109733883,6.92146666666667],8,3)
14034         trg=MEDCouplingUMesh("MESH",3) ; trg.setCoords(trgCoo)
14035         trg.allocateCells()
14036         trg.insertNextCell(NORM_HEXA8,[0,1,3,2,4,5,7,6])
14037         #
14038         srcFace=src.buildDescendingConnectivity()[0]
14039         conn=MEDCoupling1SGTUMesh(srcFace).getNodalConnectivity() ; conn.rearrange(4)
14040         eqFaces=srcFace.computePlaneEquationOf3DFaces()
14041         nodeIdInCell=3
14042         e=(srcFace.getCoords()[conn[:,nodeIdInCell]]*eqFaces[:,:-1]).sumPerTuple()+eqFaces[:,3]# e represent the error between the expected 'a*X+b*Y+c*Z+d' in eqFaces and 0. Closer e to 0. is closer the 4th point is to the plane built with the 3 first points
14043         lambd=-e/(eqFaces[:,:3]**2).sumPerTuple()
14044         pts=lambd*eqFaces[:,:-1]+srcFace.getCoords()[conn[:,nodeIdInCell]]#pts represent the projection of the last points of each NORM_QUAD4 to the plane defined by the 3 first points of the NORM_QUAD4 cell
14045         shouldBeZero=(pts*eqFaces[:,:-1]).sumPerTuple()+eqFaces[:,3]# this line is useless only to be sure that pts are on the plane.
14046         check=(pts-srcFace.getCoords()[conn[:,nodeIdInCell]]).magnitude() # check contains the distance of the last point to its plane
14047         idsToTest=check.getIdsNotInRange(0.,1e-10)
14048         self.assertTrue(idsToTest.isEqual(DataArrayInt([17,18,19,20,22,23,24])))
14049         idsToTest2=idsToTest.getIdsNotInRange(18,22)
14050         self.assertTrue(idsToTest2.isEqual(DataArrayInt([0,4,5,6])))
14051         idsToTest2.rearrange(2)
14052         self.assertTrue(idsToTest2.sumPerTuple().isEqual(DataArrayInt([4,11])))
14053         pass
14054
14055     def testSwig2SortHexa8EachOther1(self):
14056         """
14057         testing MEDCoupling1SGTUMesh.sortHexa8EachOther method
14058         """
14059         coords1=DataArrayDouble([(-0.5,0.5,-0.5),(0.5,-0.5,-0.5),(-0.5,-0.5,0.5),(-0.5,-0.5,-0.5),(0.5,-0.5,0.5),(-0.5,0.5,0.5),(0.5,0.5,0.5),(0.5,0.5,-0.5)])
14060         m1=MEDCouplingUMesh("m1",3) ; m1.setCoords(coords1)
14061         m1.allocateCells() ; m1.insertNextCell(NORM_HEXA8,[7,1,3,0,6,4,2,5])
14062         m1.checkCoherency()
14063         #
14064         m2=m1.deepCpy() ; m2.setName("m2")
14065         #
14066         trs=[[0.,0.,-1.],[0.,0.,1.],[1.,0.,0.],[0.,-1.,0.],[-1.,0.,0.],[0.,1.,0.]]
14067         for i,t in enumerate(trs):
14068             for j in xrange(64):
14069                 j2=(j//16) ; j1=((j%16)//4) ; j0=(j%4)
14070                 m11=m1.deepCpy()
14071                 m11.rotate([0.,0.,0.],[0.,0.,1.],float(j0)*pi/2)
14072                 m11.rotate([0.,0.,0.],[0.,1.,0.],float(j1)*pi/2)
14073                 m11.rotate([0.,0.,0.],[1.,0.,0.],float(j2)*pi/2)
14074                 m11.translate(t)
14075                 #
14076                 m=MEDCouplingUMesh.MergeUMeshes(m2,m11)
14077                 m.mergeNodes(1e-12)
14078                 self.assertEqual(12,m.getNumberOfNodes())
14079                 m=MEDCoupling1SGTUMesh(m)
14080                 m.sortHexa8EachOther()
14081                 tmp0=m.buildUnstructured().tetrahedrize(PLANAR_FACE_6)[0].buildUnstructured()
14082                 self.assertEqual(20,tmp0.computeSkin().getNumberOfCells())
14083                 pass
14084             pass
14085         pass
14086
14087     def testSwig2normMinComputeAbs1(self):
14088         d=DataArrayDouble([4,-5,2,6.1,-7.33,1,-1,3e2,0.07,-0.009,-6,-1e30],4,3)
14089         d.setInfoOnComponents(["XX [m]","YYY [km]","ABSJJ [MW]"])
14090         d0=d.computeAbs()
14091         dExp=d.deepCpy() ; dExp.abs()
14092         self.assertTrue(dExp.isEqual(d0,1e-12))
14093         e=d0-DataArrayDouble([4,5,2,6.1,7.33,1,1,3e2,0.07,0.009,6,1e30],4,3)
14094         self.assertAlmostEqual(0.,e.normMin(),13)
14095         self.assertAlmostEqual(0.009,d.normMin(),13)
14096         #
14097         di=DataArrayInt([3,-12,5,6,14,16,-23,100,23,-1,0,-6],4,3)
14098         di.setInfoOnComponents(["XX [m]","YYY [km]","ABSJJ [MW]"])
14099         d0i=di.computeAbs()
14100         diExp=di.deepCpy() ; diExp.abs()
14101         self.assertTrue(diExp.isEqual(d0i))
14102         self.assertEqual([3,12,5,6,14,16,23,100,23,1,0,6],d0i.getValues())
14103         pass
14104
14105     def testSwig2GetCellsContainingPointsForNonConvexPolygon1(self):
14106         coo=DataArrayDouble([-0.5,-0.5,-0.5,0.5,0.5,0.5,0.5,-0.5,0.,-0.5,0.,0.,0.5,0.,],7,2)
14107         m=MEDCouplingUMesh("Intersect2D",2) ; m.setCoords(coo) ; m.allocateCells()
14108         m.insertNextCell(NORM_POLYGON,[6,3,4,5])
14109         m.insertNextCell(NORM_POLYGON,[4,0,1,2,6,5])
14110         m.checkCoherency2()
14111         #
14112         self.assertTrue(m.getCellsContainingPoint((0.4,-0.4),1e-12).isEqual(DataArrayInt([0])))
14113         self.assertTrue(m.getCellsContainingPoint((-0.4,-0.4),1e-12).isEqual(DataArrayInt([1])))
14114         self.assertTrue(m.getCellsContainingPoint((0.,-0.4),1e-12).isEqual(DataArrayInt([0,1])))
14115         pass
14116     
14117     def testSwig2GetCellsContainingPointsForNonConvexPolygon2(self):
14118         coo=DataArrayDouble([-0.5,-0.5,-0.5,0.5,0.5,0.5,0.5,-0.5,-2.0816681711721685e-17,-2.0816681711721685e-17,-0.17677669529663687,0.1767766952966369,0.,0.5,0.5,0.,0.17677669529663684,-0.17677669529663692,0.17677669529663692,0.17677669529663684,-0.17677669529663692,-0.17677669529663687,0.,-0.5,-0.5,0.,0.33838834764831843,-0.3383883476483185,-0.33838834764831843,0.33838834764831843,-0.21213203435596423,0.21213203435596426,0.2121320343559642,-0.2121320343559643,0.21213203435596426,0.2121320343559642,-0.21213203435596423,-0.21213203435596428,0.3560660171779821,-0.35606601717798214,-0.35606601717798214,0.35606601717798214,0.19445436482630052,-0.19445436482630063,-0.19445436482630055,0.19445436482630057,0.,0.27],24,2)
14119         m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo) ; m.allocateCells()
14120         m.insertNextCell(NORM_QPOLYG,[8,5,4,9])
14121         m.insertNextCell(NORM_QPOLYG,[5,8,4,10])
14122         m.insertNextCell(NORM_QPOLYG,[16,8,5,15,21,9,22,17])
14123         m.insertNextCell(NORM_QPOLYG,[15,1,2,3,16,20,6,7,19,17])
14124         m.insertNextCell(NORM_QPOLYG,[15,5,8,16,22,10,21,18])
14125         m.insertNextCell(NORM_QPOLYG,[16,3,0,1,15,19,11,12,20,18])
14126         m.checkCoherency2()
14127         self.assertTrue(m.getCellsContainingPoint([0.,0.27],1e-12).isEqual(DataArrayInt([2])))
14128         pass
14129
14130     def testSwig2DAIGetIdsEqualTuple1(self):
14131         da=DataArrayInt([0,7,1,2,4,1,2,1,1,2,0,1,2,1,5,1,1,2],9,2)
14132         self.assertTrue(da.getIdsEqualTuple([1,2]).isEqual(DataArrayInt([1,4,8])))
14133         self.assertTrue(da.getIdsEqualTuple((1,2)).isEqual(DataArrayInt([1,4,8])))
14134         self.assertTrue(da.getIdsEqualTuple(DataArrayInt([1,2])).isEqual(DataArrayInt([1,4,8])))
14135         da.rearrange(3)
14136         self.assertRaises(InterpKernelException,da.getIdsEqualTuple,[1,2])# mismatch nb of compo (3) and nb of elts in input tuple (2)
14137         self.assertTrue(da.getIdsEqualTuple([2,0,1]).isEqual(DataArrayInt([3])))
14138         self.assertTrue(da.getIdsEqualTuple([2,0,7]).isEqual(DataArrayInt([])))
14139         da.rearrange(1)
14140         self.assertTrue(da.getIdsEqualTuple(2).isEqual(DataArrayInt([3,6,9,12,17])))
14141         self.assertTrue(da.getIdsEqualTuple(2).isEqual(da.getIdsEqual(2)))
14142         pass
14143
14144     def testSwig2GaussNEStaticInfo1(self):
14145         self.assertTrue(DataArrayDouble(MEDCouplingFieldDiscretizationGaussNE.GetWeightArrayFromGeometricType(NORM_TRI3)).isEqual(DataArrayDouble([0.16666666666666666,0.16666666666666666,0.16666666666666666]),1e-12))
14146         self.assertTrue(DataArrayDouble(MEDCouplingFieldDiscretizationGaussNE.GetRefCoordsFromGeometricType(NORM_TRI3)).isEqual(DataArrayDouble([0.,0.,1.,0.,0.,1.]),1e-12))
14147         self.assertTrue(DataArrayDouble(MEDCouplingFieldDiscretizationGaussNE.GetLocsFromGeometricType(NORM_TRI3)).isEqual(DataArrayDouble([0.16666666666666666,0.16666666666666666,0.6666666666666667,0.16666666666666666,0.16666666666666666,0.6666666666666667]),1e-12))
14148         pass
14149
14150     def testSwigReverseNodalConnOnStructuredMesh(self):
14151         # 1D - standard
14152         c=MEDCouplingCMesh() ; arr=DataArrayDouble(10) ; arr.iota()
14153         c.setCoordsAt(0,arr)
14154         rn,rni=c.getReverseNodalConnectivity()
14155         rn2,rni2=c.buildUnstructured().getReverseNodalConnectivity()
14156         self.assertTrue(rn.isEqual(DataArrayInt([0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8])))
14157         self.assertTrue(rni.isEqual(DataArrayInt([0,1,3,5,7,9,11,13,15,17,18])))
14158         self.assertTrue(rn.isEqual(rn2)) ; self.assertTrue(rni.isEqual(rni2))
14159         # 1D - limit
14160         c=MEDCouplingCMesh() ; arr=DataArrayDouble(1) ; arr.iota()
14161         c.setCoordsAt(0,arr)
14162         rn,rni=c.getReverseNodalConnectivity()
14163         rn2,rni2=c.buildUnstructured().getReverseNodalConnectivity()
14164         self.assertTrue(rn.isEqual(DataArrayInt([0])))
14165         self.assertTrue(rni.isEqual(DataArrayInt([0,1])))
14166         self.assertTrue(rn.isEqual(rn2)) ; self.assertTrue(rni.isEqual(rni2))
14167         # 1D - limit
14168         c=MEDCouplingCMesh() ; arr=DataArrayDouble(0) ; arr.iota()
14169         c.setCoordsAt(0,arr)
14170         rn,rni=c.getReverseNodalConnectivity()
14171         rn.isEqual(DataArrayInt([]))
14172         rni.isEqual(DataArrayInt([0]))
14173         # 2D - standard
14174         c=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota() ; arr2=DataArrayDouble(4) ; arr.iota()
14175         c.setCoords(arr,arr2)
14176         rn,rni=c.getReverseNodalConnectivity()
14177         rn2,rni2=c.buildUnstructured().getReverseNodalConnectivity()
14178         self.assertTrue(rn.isEqual(DataArrayInt([0,0,1,1,2,2,3,3,0,4,0,1,4,5,1,2,5,6,2,3,6,7,3,7,4,8,4,5,8,9,5,6,9,10,6,7,10,11,7,11,8,8,9,9,10,10,11,11])))
14179         self.assertTrue(rni.isEqual(DataArrayInt([0,1,3,5,7,8,10,14,18,22,24,26,30,34,38,40,41,43,45,47,48])))
14180         self.assertTrue(rn.isEqual(rn2)) ; self.assertTrue(rni.isEqual(rni2))
14181         # 2D - limit
14182         c=MEDCouplingCMesh() ; arr=DataArrayDouble(10) ; arr.iota() ; arr2=DataArrayDouble(1) ; arr.iota()
14183         c.setCoords(arr,arr2)
14184         rn,rni=c.getReverseNodalConnectivity()
14185         self.assertTrue(rn.isEqual(DataArrayInt([0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8])))
14186         self.assertTrue(rni.isEqual(DataArrayInt([0,1,3,5,7,9,11,13,15,17,18])))
14187         # 2D - limit
14188         c=MEDCouplingCMesh() ; arr=DataArrayDouble(10) ; arr.iota() ; arr2=DataArrayDouble(1) ; arr.iota()
14189         c.setCoords(arr2,arr)
14190         rn,rni=c.getReverseNodalConnectivity()
14191         self.assertTrue(rn.isEqual(DataArrayInt([0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8])))
14192         self.assertTrue(rni.isEqual(DataArrayInt([0,1,3,5,7,9,11,13,15,17,18])))
14193         # 3D - standard
14194         c=MEDCouplingCMesh() ; arr0=DataArrayDouble(5) ; arr0.iota() ; arr1=DataArrayDouble(3) ; arr1.iota() ; arr2=DataArrayDouble(4) ; arr2.iota()
14195         c.setCoords(arr0,arr1,arr2)
14196         rn,rni=c.getReverseNodalConnectivity()
14197         self.assertTrue(rn.isEqual(DataArrayInt([0,0,1,1,2,2,3,3,0,4,0,1,4,5,1,2,5,6,2,3,6,7,3,7,4,4,5,5,6,6,7,7,0,8,0,1,8,9,1,2,9,10,2,3,10,11,3,11,0,4,8,12,0,1,4,5,8,9,12,13,1,2,5,6,9,10,13,14,2,3,6,7,10,11,14,15,3,7,11,15,4,12,4,5,12,13,5,6,13,14,6,7,14,15,7,15,8,16,8,9,16,17,9,10,17,18,10,11,18,19,11,19,8,12,16,20,8,9,12,13,16,17,20,21,9,10,13,14,17,18,21,22,10,11,14,15,18,19,22,23,11,15,19,23,12,20,12,13,20,21,13,14,21,22,14,15,22,23,15,23,16,16,17,17,18,18,19,19,16,20,16,17,20,21,17,18,21,22,18,19,22,23,19,23,20,20,21,21,22,22,23,23])))
14198         self.assertTrue(rni.isEqual(DataArrayInt([0,1,3,5,7,8,10,14,18,22,24,25,27,29,31,32,34,38,42,46,48,52,60,68,76,80,82,86,90,94,96,98,102,106,110,112,116,124,132,140,144,146,150,154,158,160,161,163,165,167,168,170,174,178,182,184,185,187,189,191,192])))
14199         rn2,rni2=c.buildUnstructured().getReverseNodalConnectivity()
14200         self.assertTrue(rn.isEqual(rn2)) ; self.assertTrue(rni.isEqual(rni2))
14201         pass
14202
14203     def testSwig2CellToNodeDiscretization1(self):
14204         m=MEDCouplingCMesh() ; arr0=DataArrayDouble(5) ; arr0.iota() ; arr1=DataArrayDouble(4) ; arr1.iota() ; m.setCoords(arr0,arr1)
14205         f=MEDCouplingFieldDouble(ON_CELLS) ; f.setMesh(m) ; f.setTime(1.1,5,6)
14206         arr=DataArrayDouble(12) ; arr.iota()
14207         arr=DataArrayDouble.Meld(arr,arr+100.) ; arr.setInfoOnComponents(["aaa","bbb"])
14208         f.setArray(arr)
14209         f.checkCoherency()
14210         #
14211         ref=DataArrayDouble([0.,0.5,1.5,2.5,3.,2.,2.5,3.5,4.5,5.,6.,6.5,7.5,8.5,9.,8.,8.5,9.5,10.5,11.])
14212         ref=DataArrayDouble.Meld(ref,ref+100.) ; ref.setInfoOnComponents(["aaa","bbb"])
14213         f2=f.cellToNodeDiscretization()
14214         f2.checkCoherency()
14215         self.assertEqual(f2.getTime()[1:],[5,6])
14216         self.assertAlmostEqual(f2.getTime()[0],1.1,15)
14217         self.assertEqual(f2.getMesh().getHiddenCppPointer(),m.getHiddenCppPointer())
14218         self.assertTrue(f2.getArray().isEqual(ref,1e-12))
14219         rn,rni=m.getReverseNodalConnectivity()
14220         rni2=(rni.deltaShiftIndex()).convertToDblArr()
14221         arr2=(f.getArray()[rn]).accumulatePerChunck(rni)/rni2
14222         self.assertTrue(f2.getArray().isEqual(arr2,1e-12))
14223         del f2
14224         #
14225         u=m.buildUnstructured() ; f.setMesh(u) ; del m
14226         f3=f.cellToNodeDiscretization()
14227         f3.checkCoherency()
14228         self.assertEqual(f3.getTime()[1:],[5,6])
14229         self.assertAlmostEqual(f3.getTime()[0],1.1,15)
14230         self.assertEqual(f3.getMesh().getHiddenCppPointer(),u.getHiddenCppPointer())
14231         self.assertTrue(f3.getArray().isEqual(ref,1e-12))
14232         pass
14233
14234     def testSwig2GetMeshSpaceDimensionCMesh1(self):
14235         c=MEDCouplingCMesh()
14236         arr0=DataArrayDouble([0,1,2])
14237         arr1=DataArrayDouble([0])
14238         c.setCoords(arr0,arr0,arr0)
14239         self.assertEqual(c.getMeshDimension(),3)
14240         self.assertEqual(c.getSpaceDimension(),3)
14241         #
14242         c.setCoords(arr0,arr0,arr1)
14243         self.assertEqual(c.getMeshDimension(),2)
14244         self.assertEqual(c.getSpaceDimension(),3)
14245         #
14246         c.setCoords(arr0,arr0)
14247         self.assertEqual(c.getMeshDimension(),2)
14248         self.assertEqual(c.getSpaceDimension(),2)
14249         #
14250         c.setCoords(arr0,arr1)
14251         self.assertEqual(c.getMeshDimension(),1)
14252         self.assertEqual(c.getSpaceDimension(),2)
14253         #
14254         c.setCoords(arr0)
14255         self.assertEqual(c.getMeshDimension(),1)
14256         self.assertEqual(c.getSpaceDimension(),1)
14257         #
14258         c.setCoords(arr1)
14259         self.assertEqual(c.getMeshDimension(),0)
14260         self.assertEqual(c.getSpaceDimension(),1)
14261         pass
14262
14263     def testSwig2BuildSpreadZonesWithPolyOnQPolyg1(self):
14264         nx=6
14265         ny=6
14266         m=MEDCouplingCMesh()
14267         arr1=DataArrayDouble(nx) ; arr1.iota()
14268         arr2=DataArrayDouble(ny) ; arr2.iota()
14269         m.setCoords(arr1,arr2)
14270         m=m.buildUnstructured()
14271         da=DataArrayInt.Range(nx-1,(nx-1)*(ny-1),nx)
14272         m2=m[da] ; m2.simplexize(0)
14273         dan=da.buildComplement(m.getNumberOfCells())
14274         m1=m[dan]
14275         m=MEDCouplingUMesh.MergeUMeshesOnSameCoords(m1,m2)
14276         #
14277         m.convertLinearCellsToQuadratic()
14278         m1=m[::2] ; m2=m[1::2] ; m2.convertAllToPoly()
14279         m=MEDCouplingUMesh.MergeUMeshesOnSameCoords(m1,m2)
14280         p=m.buildSpreadZonesWithPoly()
14281         self.assertTrue(p.getNodalConnectivity().isEqual(DataArrayInt([32,1,0,6,12,18,24,30,31,32,33,34,35,29,23,17,11,5,4,3,2,36,37,94,62,72,83,84,86,89,99,92,93,82,71,60,51,49,46,43,40])))
14282         self.assertTrue(p.getNodalConnectivityIndex().isEqual(DataArrayInt([0,41])))
14283         self.assertTrue(p.getCoords().isEqual(DataArrayDouble([0.,0.,1.,0.,2.,0.,3.,0.,4.,0.,5.,0.,0.,1.,1.,1.,2.,1.,3.,1.,4.,1.,5.,1.,0.,2.,1.,2.,2.,2.,3.,2.,4.,2.,5.,2.,0.,3.,1.,3.,2.,3.,3.,3.,4.,3.,5.,3.,0.,4.,1.,4.,2.,4.,3.,4.,4.,4.,5.,4.,0.,5.,1.,5.,2.,5.,3.,5.,4.,5.,5.,5.,0.5,0.,0.,0.5,0.5,1.,1.,0.5,1.5,0.,1.5,1.,2.,0.5,2.5,0.,2.5,1.,3.,0.5,3.5,0.,3.5,1.,4.,0.5,4.5,0.,4.5,1.,5.,0.5,1.,1.5,1.5,2.,2.,1.5,2.5,2.,3.,1.5,3.5,2.,4.,1.5,4.5,2.,5.,1.5,0.5,2.,0.,2.5,0.5,3.,1.,2.5,2.,2.5,2.5,3.,3.,2.5,3.5,3.,4.,2.5,4.5,3.,5.,2.5,0.,3.5,0.5,4.,1.,3.5,1.5,3.,1.5,4.,2.,3.5,3.,3.5,3.5,4.,4.,3.5,4.5,4.,5.,3.5,0.,4.5,0.5,5.,1.,4.5,1.5,5.,2.,4.5,2.5,4.,2.5,5.,3.,4.5,4.,4.5,4.5,5.,5.,4.5,0.,1.5,0.5,1.5,1.5,2.5,2.5,3.5,3.5,4.5,3.5,5.0],100,2),1e-13))
14284         pass
14285
14286     def testSwig2Conformize2D1(self):
14287         eps = 1.0e-8
14288         coo = [0.,-0.5,0.,0.,0.5,0.,0.5,-0.5,0.25,
14289                -0.1,0.25,0.,0.5,-0.1,0.,0.5,0.5,0.5,0.25,0.4,0.25,0.5,0.5,0.4]
14290         conn = [5,5,2,6,4,5,6,3,0,1,5,4,5,10,8,11,9,5,11,2,1,7,10,9]
14291         connI = [0,5,12,17,24]
14292         m = MEDCouplingUMesh("box",2)
14293         cooArr = DataArrayDouble(coo,len(coo)/2,2)
14294         m.setCoords(cooArr)
14295         m.setConnectivity(DataArrayInt(conn),DataArrayInt(connI))
14296         m.mergeNodes(eps)
14297         m.checkCoherency()
14298         self.assertTrue(m.conformize2D(eps).isEqual(DataArrayInt([3])))
14299         self.assertEqual(m.getCoords().getHiddenCppPointer(),cooArr.getHiddenCppPointer()) # check that coordinates remain the same here
14300         self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([5,5,2,6,4,5,6,3,0,1,5,4,5,10,8,11,9,5,11,2,5,1,7,10,9])))
14301         self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,5,12,17,25])))
14302         pass
14303
14304     def testSwig2Conformize2D2(self):
14305         eps = 1.0e-8
14306         coo=DataArrayDouble([-10,-6,0,-6,0,0,7,0,-10,2,0,2,0,6,7,6,0,8,7,8,-10,12,-4,12,0,12,0,11,7,11,-4,16,0,16,7,16],18,2)
14307         conn=DataArrayInt([2,3,7,6, 13,16,17,14, 4,10,12,5, 9,14,13,8, 8,9,7,6, 5,4,0,1, 16,12,11,15])
14308         m=MEDCoupling1SGTUMesh("mesh",NORM_QUAD4)
14309         m.setCoords(coo)
14310         m.setNodalConnectivity(conn)
14311         m=m.buildUnstructured()
14312         self.assertTrue(m.conformize2D(eps).isEqual(DataArrayInt([0,1,2,5])))
14313         self.assertEqual(m.getCoords().getHiddenCppPointer(),coo.getHiddenCppPointer()) # check that coordinates remain the same here
14314         self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([5,2,3,7,6,5, 5,13,12,16,17,14, 5,4,10,11,12,13,8,6,5, 4,9,14,13,8, 4,8,9,7,6, 5,5,4,0,1,2, 4,16,12,11,15])))
14315         self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,6,12,21,26,31,37,42])))
14316         pass
14317
14318     def testSwigSplit2DCells1(self):
14319         coo=DataArrayDouble([[0,0],[1,0],[1,1],[0,1],[0.5,0],[1,0.5],[0.5,1],[0.,0.5]])
14320         m=MEDCouplingUMesh("mesh",2)
14321         m.setCoords(coo)
14322         m.allocateCells()
14323         m.insertNextCell(NORM_QUAD8,[0,1,2,3,4,5,6,7])
14324         _,d,di,_,_=m.buildDescendingConnectivity()
14325         subb=DataArrayInt([5])
14326         subbi=DataArrayInt([0,0,1,1,1])
14327         mid=DataArrayInt([-1,-1])
14328         midi=DataArrayInt([0,0,2,2,2])
14329         self.assertEqual(2,m.split2DCells(d,di,subb,subbi,mid,midi))
14330         self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([32,0,1,5,2,3,4,8,9,6,7])))
14331         self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,11])))
14332         self.assertTrue(m.getCoords().isEqual(DataArrayDouble([[0,0],[1,0],[1,1],[0,1],[0.5,0],[1,0.5],[0.5,1],[0.,0.5],[1.,0.25],[1.,0.75]]),1e-12))
14333         pass
14334
14335     def testSwig2Conformize2D3(self):
14336         eps = 1.0e-8
14337         coo=DataArrayDouble([-10,-6,0,-6,0,0,7,0,-10,2,0,2,0,6.5,7,6.5,0,8,7,8,-10,12,-4,12,0,12,0,11,7,11,-4,16,0,16,7,16],18,2)
14338         conn=DataArrayInt([2,3,7,6, 13,16,17,14, 4,10,12,5, 9,14,13,8, 8,9,7,6, 5,4,0,1, 16,12,11,15])
14339         m=MEDCoupling1SGTUMesh("mesh",NORM_QUAD4)
14340         m.setCoords(coo)
14341         m.setNodalConnectivity(conn)
14342         m=m.buildUnstructured()
14343         m.convertLinearCellsToQuadratic()
14344         self.assertTrue(m.conformize2D(eps).isEqual(DataArrayInt([0,1,2,5])))
14345         self.assertTrue(m.getCoords().getHiddenCppPointer()!=coo.getHiddenCppPointer()) # coordinates are not the same here contrary to testSwig2Conformize2D2 ...
14346         self.assertTrue(m.getCoords()[:18].isEqual(coo,1e-12)) # but the 18 first nodes are the same
14347         pass
14348
14349     def testSwig2Conformize2D4(self):
14350         eps = 1.0e-8
14351         coo=DataArrayDouble([-10,-6,0,-6,0,0,7,0,-10,2,0,2,0,6.5,7,6.5,0,8,7,8,-10,12,-4,12,0,12,0,11,7,11,-4,16,0,16,7,16],18,2)
14352         conn=DataArrayInt([2,3,7,6, 13,16,17,14, 4,10,12,5, 9,14,13,8, 8,9,7,6, 5,4,0,1, 16,12,11,15])
14353         m=MEDCoupling1SGTUMesh("mesh",NORM_QUAD4)
14354         m.setCoords(coo)
14355         m.setNodalConnectivity(conn)
14356         m=m.buildUnstructured()
14357         m.convertLinearCellsToQuadratic()
14358         self.assertEqual(42,m.getNumberOfNodes())
14359         oldCoo=m.getCoords().deepCpy()
14360         m.conformize2D(eps)
14361         self.assertTrue(m.getCoords()[:42].isEqual(oldCoo,1e-12))
14362         self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([32,2,3,7,6,5,18,19,20,42,43,32,13,12,16,17,14,44,38,23,24,25,32,4,10,11,12,13,8,6,5,26,45,39,44,31,34,42,29,8,9,14,13,8,30,25,31,32,8,8,9,7,6,32,33,20,34,32,5,4,0,1,2,29,35,36,46,43,8,16,12,11,15,38,39,40,41])))
14363         self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,11,22,39,48,57,68,77])))
14364         self.assertTrue(m.getCoords().isEqual(DataArrayDouble([[-10.,-6.0],[0.,-6.0],[0.,0.0],[7.,0.0],[-10.,2.0],[0.,2.0],[0.,6.5],[7.,6.5],[0.,8.0],[7.,8.0],[-10.,12.0],[-4.,12.0],[0.,12.0],[0.,11.0],[7.,11.0],[-4.,16.0],[0.,16.0],[7.,16.0],[3.5, 0.0],[7.,3.25],[3.5, 6.5],[0.,3.25],[0.,13.5],[3.5, 16.0],[7.,13.5],[3.5, 11.0],[-10.,7.0],[-5.,12.0],[0.,7.0],[-5.,2.0],[7.,9.5],[0.,9.5],[3.5, 8.0],[7.,7.25],[0.,7.25],[-10.,-2.0],[-5.,-6.0],[0.,-2.0],[0.,14.0],[-2.,12.0],[-4.,14.0],[-2.,16.0],[0.,4.25],[0.,1.0],[0.,11.5],[-7.,12.0],[0.,-3.]]),1e-12))
14365         pass
14366
14367     def testSwig2Conformize2D5(self):
14368         eps=1e-8
14369         coo=DataArrayDouble([[2,2],[2,-6],[10,-2],[-2,-2],[6,0],[6,-4],[2,7],[2,4.5],[-1.4641016151377544,0],[-1.950753362380551,-1.3742621398390762],[-7,-3],[-0.8284271247461898,-4.82842712474619],[0.26794919243112281,3.5],[0,1.4641016151377548],[-4.4753766811902755,-2.1871310699195381],[-3.9142135623730949,-3.9142135623730949],[-1.8042260651806146,-3.23606797749979]])
14370         m=MEDCouplingUMesh("mesh",2)
14371         m.allocateCells()
14372         m.setCoords(coo)
14373         m.insertNextCell(NORM_TRI6,[1,2,0,5,4,3])
14374         m.insertNextCell(NORM_TRI6,[8,6,0,12,7,13])
14375         m.insertNextCell(NORM_TRI6,[11,9,10,16,14,15])
14376         self.assertTrue(m.conformize2D(eps).isEqual(DataArrayInt([0])))
14377         self.assertTrue(m.getCoords().isEqual(DataArrayDouble([2.,2.,2.,-6.,10.,-2.,-2.,-2.,6.,0.,6.,-4.,2.,7.,2.,4.5,-1.4641016151377544,0.,-1.950753362380551,-1.3742621398390762,-7.,-3.,-0.8284271247461898,-4.82842712474619,0.2679491924311228,3.5,8.881784197001252e-16,1.4641016151377548,-4.4753766811902755,-2.187131069919538,-3.914213562373095,-3.914213562373095,-1.8042260651806146,-3.236067977499789,-1.7705659643687133,-0.6647725630649153,0.46926627053963865,-5.695518130045146],19,2),1e-12))
14378         self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([32,1,2,0,8,9,11,5,4,13,17,16,18,6,8,6,0,12,7,13,6,11,9,10,16,14,15])))
14379         self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,13,20,27])))
14380         pass
14381
14382     def setUp(self):
14383         pass
14384     pass
14385
14386 if __name__ == '__main__':
14387     unittest.main()