]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/MEDCoupling_Swig/MEDCouplingBasicsTest.py
Salome HOME
734391fa911d1c3281dfac9b201bbae0dfbb03f3
[tools/medcoupling.git] / src / MEDCoupling_Swig / MEDCouplingBasicsTest.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2013  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.
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 testPolyhedronBarycenter(self):
2187         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];
2188         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];
2189         meshN=MEDCouplingUMesh.New();
2190         meshN.setName("ForBary");
2191         meshN.setMeshDimension(3);
2192         meshN.allocateCells(4);
2193         meshN.insertNextCell(NORM_POLYHED,29,connN[0:29])
2194         meshN.finishInsertingCells();
2195         myCoords=DataArrayDouble.New();
2196         myCoords.setValues(coords,9,3);
2197         meshN.setCoords(myCoords);
2198         meshN.checkCoherency();
2199         #
2200         res1=meshN.arePolyhedronsNotCorrectlyOriented();
2201         meshN.orientCorrectlyPolyhedrons();
2202         self.assertTrue(len(res1)==0);
2203         da=meshN.getBarycenterAndOwner();
2204         self.assertEqual(1,da.getNumberOfTuples());
2205         self.assertEqual(3,da.getNumberOfComponents());
2206         daPtr=da.getValues();
2207         ref=meshN.getCoords().getValues()[24:];
2208         for i in xrange(3):
2209             self.assertTrue(abs(ref[i]-daPtr[i])<1e-12);
2210             pass
2211         #
2212         center=[0.,0.,0.]
2213         vec=[0.,2.78,0.]
2214         da=meshN.getBarycenterAndOwner();
2215         daPtr=da.getValues();
2216         ref=meshN.getCoords().getValues()[24:];
2217         for i in xrange(3):
2218             self.assertTrue(abs(ref[i]-daPtr[i])<1e-12);
2219             pass
2220         #
2221         meshN.rotate(center,vec,pi/7.);
2222         meshN.translate(vec);
2223         da=meshN.getBarycenterAndOwner();
2224         daPtr=da.getValues();
2225         ref=meshN.getCoords().getValues()[24:];
2226         for i in xrange(3):
2227             self.assertTrue(abs(ref[i]-daPtr[i])<1e-12);
2228             pass
2229         #
2230         center2=[1.12,3.45,6.78]
2231         vec2=[4.5,9.3,2.8]
2232         meshN.rotate(center2,vec2,e);
2233         meshN.translate(vec2);
2234         da=meshN.getBarycenterAndOwner();
2235         daPtr=da.getValues();
2236         ref=meshN.getCoords().getValues()[24:];
2237         for i in xrange(3):
2238             self.assertTrue(abs(ref[i]-daPtr[i])<1e-10);
2239             pass
2240         pass
2241
2242     def testNormL12Integ1D(self):
2243         m1=MEDCouplingDataForTest.build1DTargetMesh_3();
2244         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
2245         f1.setMesh(m1);
2246         array=DataArrayDouble.New();
2247         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]
2248         array.setValues(arr,m1.getNumberOfCells(),3);
2249         f1.setArray(array);
2250         #
2251         f3=m1.getBarycenterAndOwner();
2252         self.assertEqual(4,f3.getNumberOfTuples());
2253         self.assertEqual(1,f3.getNumberOfComponents());
2254         expected9=[0.75,5.105,0.8,5.155]
2255         ptr=f3.getValues();
2256         for i in xrange(4):
2257             self.assertTrue(abs(expected9[i]-ptr[i])<1e-12);
2258             pass
2259         #
2260         f2=m1.getMeasureField(False);
2261         self.assertEqual(4,f2.getArray().getNumberOfTuples());
2262         self.assertEqual(1,f2.getNumberOfComponents());
2263         expected1=[0.5,0.21,-0.6,-0.31]
2264         ptr=f2.getArray().getValues();
2265         for i in xrange(4):
2266             self.assertTrue(abs(expected1[i]-ptr[i])<1e-12);
2267             pass
2268         expected2=[0.5,0.21,0.6,0.31]
2269         f2=m1.getMeasureField(True);
2270         ptr=f2.getArray().getValues();
2271         for i in xrange(4):
2272             self.assertTrue(abs(expected2[i]-ptr[i])<1e-12);
2273             pass
2274         #integral
2275         self.assertTrue(4,f1.getNumberOfTuples())
2276         res=f1.integral(False);
2277         self.assertTrue(3,len(res))
2278         expected3=[0.9866,-0.3615,0.4217]
2279         for i in xrange(3):
2280             self.assertTrue(abs(expected3[i]-res[i])<1e-12);
2281             pass
2282         self.assertTrue(abs(expected3[0]-f1.integral(0,False))<1e-12);
2283         self.assertTrue(abs(expected3[1]-f1.integral(1,False))<1e-12);
2284         self.assertTrue(abs(expected3[2]-f1.integral(2,False))<1e-12);
2285         res=f1.integral(True);
2286         expected4=[-3.4152,8.7639,-14.6879]
2287         for i in xrange(3):
2288             self.assertTrue(abs(expected4[i]-res[i])<1e-12);
2289             pass
2290         #normL1
2291         res=f1.normL1();
2292         self.assertTrue(3,len(res))
2293         expected5=[6.979506172839505, 16.89018518518518, 27.02969135802469]
2294         for i in xrange(3):
2295             self.assertTrue(abs(expected5[i]-res[i])<1e-12);
2296             pass
2297         self.assertTrue(abs(expected5[0]-f1.normL1(0))<1e-12);
2298         self.assertTrue(abs(expected5[1]-f1.normL1(1))<1e-12);
2299         self.assertTrue(abs(expected5[2]-f1.normL1(2))<1e-12);
2300         #normL2
2301         res=f1.normL2();
2302         self.assertTrue(3,len(res))
2303         expected7=[7.090910979452395, 16.9275542960123, 27.053271464160858]
2304         for i in xrange(3):
2305             self.assertTrue(abs(expected7[i]-res[i])<1e-9);
2306             pass
2307         self.assertTrue(abs(expected7[0]-f1.normL2(0))<1e-9);
2308         self.assertTrue(abs(expected7[1]-f1.normL2(1))<1e-9);
2309         self.assertTrue(abs(expected7[2]-f1.normL2(2))<1e-9);
2310         #buildMeasureField
2311         f4=f1.buildMeasureField(False);
2312         self.assertTrue(abs(-0.2-f4.accumulate(0))<1e-12);
2313         f4=f1.buildMeasureField(True);
2314         self.assertTrue(abs(1.62-f4.accumulate(0))<1e-12);
2315         # Testing with 2D Curve
2316         m1=MEDCouplingDataForTest.build2DCurveTargetMesh_3();
2317         f2=m1.getMeasureField(False);
2318         self.assertEqual(4,f2.getArray().getNumberOfTuples());
2319         self.assertEqual(1,f2.getNumberOfComponents());
2320         ptr=f2.getArray().getValues();
2321         for i in xrange(4):
2322             self.assertTrue(abs(sqrt(2.)*expected2[i]-ptr[i])<1e-12);
2323             pass
2324         f2=m1.getMeasureField(True);
2325         self.assertEqual(4,f2.getArray().getNumberOfTuples());
2326         self.assertEqual(1,f2.getNumberOfComponents());
2327         ptr=f2.getArray().getValues();
2328         for i in xrange(4):
2329             self.assertTrue(abs(expected2[i]*sqrt(2.)-ptr[i])<1e-12);
2330             pass
2331         #bary
2332         f3=m1.getBarycenterAndOwner();
2333         self.assertEqual(4,f3.getNumberOfTuples());
2334         self.assertEqual(2,f3.getNumberOfComponents());
2335         expected10=[0.75,0.75,5.105,5.105,0.8,0.8,5.155,5.155]
2336         ptr=f3.getValues();
2337         for i in xrange(8):
2338             self.assertTrue(abs(expected10[i]-ptr[i])<1e-12);
2339             pass
2340         #
2341         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
2342         f1.setMesh(m1);
2343         array=DataArrayDouble.New();
2344         array.setValues(arr,m1.getNumberOfCells(),3);
2345         f1.setArray(array);
2346         res=f1.integral(False);
2347         for i in xrange(3):
2348             self.assertTrue(abs(sqrt(2.)*expected4[i]-res[i])<1e-12);
2349             pass
2350         res=f1.integral(True);
2351         for i in xrange(3):
2352             self.assertTrue(abs(sqrt(2.)*expected4[i]-res[i])<1e-12);
2353             pass
2354         res=f1.normL1();
2355         for i in xrange(3):
2356             self.assertTrue(abs(expected5[i]-res[i])<1e-12);
2357             pass
2358         res=f1.normL2();
2359         for i in xrange(3):
2360             self.assertTrue(abs(expected7[i]-res[i])<1e-12);
2361             pass
2362         pass
2363
2364     def testAreaBary2D(self):
2365         m1=MEDCouplingDataForTest.build2DTargetMesh_3();
2366         f1=m1.getMeasureField(False);
2367         self.assertEqual(10,f1.getArray().getNumberOfTuples());
2368         self.assertEqual(1,f1.getNumberOfComponents());
2369         expected1=[-0.5,-1,-1.5,-0.5,-1,  0.5,1,1.5,0.5,1]
2370         ptr=f1.getArray().getValues();
2371         for i in xrange(10):
2372             self.assertTrue(abs(expected1[i]-ptr[i])<1e-12);
2373             pass
2374         f1=m1.getMeasureField(True);
2375         ptr=f1.getArray().getValues();
2376         for i in xrange(10):
2377             self.assertTrue(abs(abs(expected1[i])-ptr[i])<1e-12);
2378             pass
2379         f2=m1.getBarycenterAndOwner();
2380         self.assertEqual(10,f2.getNumberOfTuples());
2381         self.assertEqual(2,f2.getNumberOfComponents());
2382         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]
2383         ptr=f2.getValues();
2384         for i in xrange(20):
2385             self.assertTrue(abs(expected2[i]-ptr[i])<1e-12);
2386             pass
2387         m1.changeSpaceDimension(3);
2388         f1=m1.getMeasureField(False);
2389         self.assertEqual(10,f1.getArray().getNumberOfTuples());
2390         self.assertEqual(1,f1.getNumberOfComponents());
2391         ptr=f1.getArray().getValues();
2392         for i in xrange(10):
2393             self.assertTrue(abs(abs(expected1[i])-ptr[i])<1e-12);
2394             pass
2395         f2=m1.getBarycenterAndOwner();
2396         self.assertEqual(10,f2.getNumberOfTuples());
2397         self.assertEqual(3,f2.getNumberOfComponents());
2398         ptr=f2.getValues();
2399         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.]
2400         for i in xrange(30):
2401             self.assertTrue(abs(expected3[i]-ptr[i])<1e-12);
2402             pass
2403         pass
2404
2405     def testAreaBary3D(self):
2406         coords=[ 0.241310763507 , 0.0504777305619 , 0.0682283524903 , 0.252501053866 , -0.0625176732937 , 0.137272639894 ,
2407                  0.152262663601 , 0.241816569527 , 0.133812556197 , 0.18047750211 , -0.0789949051358 , 0.339098173401 ,
2408                  0.151741971857 , 0.238885278571 , 0.137715037333 , 0.242532155481 , -0.0928169086456 , 0.0678043417367 ,
2409                  0.240941965335 , -0.015461491464 , 0.0617186345825 , 0.24127650112 , 0.0499427876717 , 0.0679634099148 ,
2410                  -0.145828917428 , 0.206291632565 , 0.0310071927543 , 0.0125651775307 , 0.266262085828 , 0.105228430543 ,
2411                  -0.0994066533286 , 0.233224271238 , 0.0572213839567 , -0.0951345338317 , 0.234819509426 , 0.0592126284538 ,
2412                  0.136580574205 , -0.205486212579 , 0.0572866072014 , 0.0637270784978 , -0.168886355238 , 0.446614057077 ,
2413                  0.041337157151 , -0.213402568198 , 0.372407095999 , 0.0411601970268 , -0.202387875756 , 0.411334979491 ,
2414                  -0.108355701857 , 0.193636239335 , 0.204886756738 , 0.00639779029829 , 0.155296981517 , 0.252585892979 ,
2415                  0.0262473111702 , -0.112919732543 , 0.424286639249 ,-0.224103052733 , -0.139430015438 , -0.0122352295701 ,
2416                 -0.0312760589481 , -0.274272003594 , 0.0323959636568 , -0.166663422532 , -0.217754445175 , 0.00392109070364 ,
2417                  -0.30586619777 , -0.0475168041091 , -0.0144585228182 , -0.280881480586 , 0.135571293538 , 0.00623923647986 ,
2418                  -0.25548538234 , 0.156819217766 , 0.0645277879769 , -0.131567009284 , 0.184133752309 , 0.206021802753 ,
2419                  -0.196204010965 , 0.151602971681 , 0.212974777736 , -0.183713879463 , 0.0802946639531 , 0.260115662599 ,
2420                  -0.244241178767 , -0.0738873389604 , 0.144590565817 , -0.155804057829 , -0.164892720025 , 0.210613950558 ,
2421                  -0.170950800428 , -0.215099334026 , 0.00610122860092 , -0.30552634869 , -0.0490020791904 , -0.0132786533145 ,
2422                  0.271831011884 , 0.15105657296 , 0.0230534827908 , 0.281919192283 , 0.0898544306288 , -0.0625201489143 ,
2423                  0.260240727276 , -0.0120688706637 , -0.0532316588626 , 0.244947737722 , 0.0197984684293 , 0.0309341209233 ,
2424                  0.23439631578 , 0.229825279875 , 0.0508520585381 , 0.160921316875 , 0.265078502128 , 0.121716560626 ,
2425                  -0.315088694175 , 0.0747700471918 , -0.245836615071 , -0.327728781776 , 0.0857114674649 , -0.239431905957 ,
2426                  -0.308385460634 , 0.145142997084 , -0.149886828433 , 0.0488236045164 , 0.309462801914 , 0.0849169148265 ,
2427                 -0.0244964803395 , 0.33145611751 , -0.0476415818061 , 0.0060567994229 , 0.32418412014 , 0.0367779543812 ,
2428                  -0.0950221448063 , 0.236675326003 , 0.0572594453983 , 0.248723023186 , 0.0886648784791 , -0.176629430538 ,
2429                  0.116796984 , 0.256596599567 , -0.292863523603 , 0.118024552914 , 0.229154257843 , -0.34233232501 ,
2430                  0.217507892549 , -0.0417822335742 , -0.176771782888 , -0.224429321304 , 0.0125595300114 , -0.362064725588 ,
2431                  0.0937301100955 , -0.0500824832657 , -0.299713548444 , -0.244162220397 , 0.0383853931293 , -0.389856984411 ,
2432                  -0.0281989366102 , 0.097392811563 , -0.458244577284 , -0.385010847162 , 0.10122766194 , -0.140052859922 ,
2433                  -0.377936358012 , 0.110875172128 , -0.176207095463 , 0.244483045556 , -0.0991073977045 , 0.0575134372934 ,
2434                 0.262605120167 , -0.100243191645 , -0.0495620806935 , 0.240306880972 , -0.136153701579 , -0.114745281696 ,
2435                  0.215763176129 , -0.0836766059189 , -0.183249640616 , 0.237870396603 , -0.132449578286 , -0.121598854639 ,
2436                  -0.0637683083097 , -0.27921020214 , -0.149112321992 , -0.0856211014977 , -0.2973233473 , -0.0446878139589 ,
2437                  0.104675342288 , -0.0625908305324 , -0.290346256534 , 0.0248264249186 , -0.247797708548 , -0.165830884019 ,
2438                  0.0719302438309 , -0.178468260473 , -0.211432157345 , 0.142871843159 , -0.208769948542 , 0.0454101128246 ,
2439                  0.167803379307 , -0.207851396623 , -0.088802726124 , 0.12868717152 , -0.230920439715 , 0.00760508389036 ,
2440                  -0.0372812069535 , -0.286740286332 , 0.00963701291166 ]
2441         
2442         connN = [ #polyhedron 0
2443             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
2444             , 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
2445             , 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
2446             , 22 , 19 , 21 , 30 , 31 , -1 , 22 , 31 , 28 , 27 , 26 , 24 , 23 , -1 , 31 , 30 , 29 , 28,
2447             # polyhedron 1
2448             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
2449             , 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
2450             , 33 , 34 , 48 , 45 , -1 , 35 , 34 , 48 , 50 , 49 , 38 , -1 , 41 , 43 , 42 , 46 , 36 , 37 , -1 , 38 , 39 , 51 , 49 , -1
2451             , 39 , 40 , 42 , 46 , 47 , 52 , 51 , -1 , 45 , 47 , 52 , 50 , 48 , -1 , 52 , 51 , 49 , 50,
2452             # polyhedron 2
2453             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
2454             , 23 , 53 , 54 , 40 , 8 , -1 , 53 , 22 , 23 , -1 , 39 , 54 , 40,
2455             # polyhedron 3
2456             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
2457             , 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
2458             , 55 , 5 , 12 , 65 , -1 , 66 , 67 , 65 , 55 , 56 , 57 , -1 , 63 , 66 , 57 , 59 , 64 , -1 , 64 , 62 , 58 , 59 , -1
2459             , 60 , 63 , 66 , 67 , 68 , 61 , -1 , 61 , 68 , 20 , 21 , -1 , 67 , 68 , 20 , 12 , 65]
2460         
2461         barys = [ -0.0165220465527 , -0.0190922868195 , 0.158882733414 ,
2462                   0.0287618656076 , 0.135874379934 , -0.14601588119 ,
2463                   -0.147128055553 , 0.0465995097041 , -0.049391174453 ,
2464                   -0.00142506732317 , -0.0996953090351 , -0.115159183132 ]
2465         meshN=MEDCouplingUMesh.New();
2466         meshN.setName("ForBary");
2467         meshN.setMeshDimension(3);
2468         meshN.allocateCells(4);
2469         meshN.insertNextCell(NORM_POLYHED,113,connN);
2470         meshN.insertNextCell(NORM_POLYHED,99,connN[113:]);
2471         meshN.insertNextCell(NORM_POLYHED,43,connN[212:]);
2472         meshN.insertNextCell(NORM_POLYHED,92,connN[255:]);
2473         meshN.finishInsertingCells();
2474         myCoords=DataArrayDouble.New();
2475         myCoords.setValues(coords,69,3);
2476         meshN.setCoords(myCoords);
2477         meshN.checkCoherency();
2478         res1=meshN.arePolyhedronsNotCorrectlyOriented();
2479         meshN.orientCorrectlyPolyhedrons();
2480         res1=meshN.arePolyhedronsNotCorrectlyOriented();
2481         self.assertTrue(len(res1)==0);
2482         #
2483         da=meshN.getBarycenterAndOwner();
2484         self.assertEqual(4,da.getNumberOfTuples());
2485         self.assertEqual(3,da.getNumberOfComponents());
2486         daPtr=da.getValues();
2487         for i in xrange(12):
2488             self.assertTrue(abs(barys[i]-daPtr[i])<1e-12);
2489             pass
2490         pass
2491
2492     def testRenumberCellsForFields(self):
2493         m=MEDCouplingDataForTest.build2DTargetMesh_1();
2494         f=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
2495         f.setMesh(m);
2496         arr=DataArrayDouble.New();
2497         nbOfCells=m.getNumberOfCells();
2498         values1=[7.,107.,10007.,8.,108.,10008.,9.,109.,10009.,10.,110.,10010.,11.,111.,10011.]
2499         arr.setValues(values1,nbOfCells,3);
2500         f.setArray(arr);
2501         renumber1=[3,1,0,4,2]
2502         loc=[-0.05,-0.05, 0.55,-0.25, 0.55,0.15, -0.05,0.45, 0.45,0.45]
2503         for j in xrange(5):
2504             res=f.getValueOn(loc[2*j:2*j+2]);
2505             for i in xrange(3):
2506                 self.assertTrue(abs(values1[i+3*j]-res[i])<1e-12);
2507                 pass
2508             pass
2509         f.renumberCells(renumber1,False);
2510         ptr=f.getArray().getValues();
2511         expected1=[9.,109.,10009.,8.,108.,10008.,11.,111.,10011.,7.,107.,10007.,10.,110.,10010.]
2512         for i in xrange(15):
2513             self.assertTrue(abs(expected1[i]-ptr[i])<1e-12);
2514             pass
2515         #check that fields remains the same geometrically
2516         for j in xrange(5):
2517             res=f.getValueOn(loc[2*j:2*(j+1)]);
2518             for i in xrange(3):
2519                 self.assertTrue(abs(values1[i+3*j]-res[i])<1e-12);
2520                 pass
2521             pass
2522         #On gauss
2523         f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,NO_TIME);
2524         f.setMesh(m);
2525         _a=0.446948490915965;
2526         _b=0.091576213509771;
2527         _p1=0.11169079483905;
2528         _p2=0.0549758718227661;
2529         refCoo1=[ 0.,0., 1.,0., 0.,1. ]
2530         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 ];
2531         wg1=[ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 ]
2532         _refCoo1=refCoo1[0:6];
2533         _gsCoo1=gsCoo1[0:12];
2534         _wg1=wg1[0:6];
2535         f.setGaussLocalizationOnType(NORM_TRI3,_refCoo1,_gsCoo1,_wg1);
2536         refCoo2=[ 0.,0., 1.,0., 1.,1., 0.,1. ]
2537         _refCoo2=refCoo2[0:8];
2538         _gsCoo1=_gsCoo1[0:4]
2539         _wg1=_wg1[0:2]
2540         f.setGaussLocalizationOnType(NORM_QUAD4,_refCoo2,_gsCoo1,_wg1);
2541         arr=DataArrayDouble.New();
2542         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.]
2543         arr.setValues(values2,18,2);
2544         f.setArray(arr);
2545         f.checkCoherency();
2546         fCpy=f.clone(True);
2547         self.assertTrue(f.isEqual(fCpy,1e-12,1e-12));
2548         f.renumberCells(renumber1,False);
2549         self.assertTrue(not f.isEqual(fCpy,1e-12,1e-12));
2550         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.]
2551         ptr=f.getArray().getValues();
2552         for i in xrange(36):
2553             self.assertTrue(abs(expected2[i]-ptr[i])<1e-12);
2554             pass
2555         renumber2=[2,1,4,0,3]
2556         f.renumberCells(renumber2,False);
2557         self.assertTrue(f.isEqual(fCpy,1e-12,1e-12));
2558         #GaussNE
2559         f=MEDCouplingFieldDouble.New(ON_GAUSS_NE,NO_TIME);
2560         f.setMesh(m);
2561         arr=DataArrayDouble.New();
2562         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.]
2563         arr.setValues(values3,18,2);
2564         f.setArray(arr);
2565         f.checkCoherency();
2566         fCpy=f.clone(True);
2567         self.assertTrue(f.isEqual(fCpy,1e-12,1e-12));
2568         f.renumberCells(renumber1,False);
2569         self.assertTrue(not f.isEqual(fCpy,1e-12,1e-12));
2570         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.]
2571         ptr=f.getArray().getValues();
2572         for i in xrange(36):
2573             self.assertTrue(abs(expected3[i]-ptr[i])<1e-12);
2574             pass
2575         f.renumberCells(renumber2,False);#perform reverse operation of renumbering to check that the resulting field is equal.
2576         self.assertTrue(f.isEqual(fCpy,1e-12,1e-12));
2577         #
2578         pass
2579
2580     def testRenumberNodesForFields(self):
2581         m=MEDCouplingDataForTest.build2DTargetMesh_1();
2582         f=MEDCouplingFieldDouble.New(ON_NODES,NO_TIME);
2583         f.setMesh(m);
2584         self.assertEqual(9,f.getNumberOfMeshPlacesExpected());
2585         arr=DataArrayDouble.New();
2586         nbOfNodes=m.getNumberOfNodes();
2587         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.]
2588         arr.setValues(values1,nbOfNodes,3);
2589         f.setArray(arr);
2590         f.checkCoherency();
2591         renumber1=[0,4,1,3,5,2,6,7,8]
2592         loc=[0.5432,-0.2432, 0.5478,0.1528]
2593         expected1=[9.0272, 109.0272, 10009.0272, 11.4124,111.4124,10011.4124]
2594         for j in xrange(2):
2595             res=f.getValueOn(loc[2*j:2*j+2]);
2596             for i in xrange(3):
2597                 self.assertTrue(abs(expected1[i+3*j]-res[i])<1e-12);
2598                 pass
2599             pass
2600         fCpy=f.clone(True);
2601         self.assertTrue(f.isEqual(fCpy,1e-12,1e-12));
2602         f.renumberNodes(renumber1);
2603         self.assertTrue(not f.isEqual(fCpy,1e-12,1e-12));
2604         for j in xrange(2):
2605             res=f.getValueOn(loc[2*j:2*j+2]);
2606             for i in xrange(3):
2607                 self.assertTrue(abs(expected1[i+3*j]-res[i])<1e-12);
2608                 pass
2609             pass
2610         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.]
2611         for i in xrange(27):
2612             self.assertTrue(abs(expected2[i]-f.getArray().getValues()[i])<1e-12);
2613             pass
2614         renumber2=[0,2,5,3,1,4,6,7,8]
2615         f.renumberNodes(renumber2);
2616         self.assertTrue(f.isEqual(fCpy,1e-12,1e-12));
2617         pass
2618
2619     def testConvertQuadraticCellsToLinear(self):
2620         mesh=MEDCouplingDataForTest.build2DTargetMesh_3();
2621         mesh.checkCoherency();
2622         types=mesh.getAllGeoTypes();
2623         types.sort()
2624         self.assertEqual(5,len(types));
2625         expected1=[NORM_POLYGON, NORM_TRI3, NORM_QUAD4, NORM_TRI6, NORM_QUAD8]
2626         expected1.sort()
2627         self.assertEqual(expected1,types);
2628         self.assertTrue(mesh.isPresenceOfQuadratic());
2629         self.assertEqual(62,mesh.getMeshLength());
2630         f1=mesh.getMeasureField(False);
2631         #
2632         mesh.convertQuadraticCellsToLinear();
2633         self.assertTrue(not mesh.isPresenceOfQuadratic());
2634         #
2635         mesh.checkCoherency();
2636         f2=mesh.getMeasureField(False);
2637         self.assertTrue(f1.getArray().isEqual(f2.getArray(),1e-12));
2638         self.assertEqual(48,mesh.getMeshLength());
2639         types2=mesh.getAllGeoTypes();
2640         types2.sort()
2641         self.assertEqual(3,len(types2));
2642         expected2=[NORM_POLYGON, NORM_TRI3, NORM_QUAD4]
2643         expected2.sort()
2644         self.assertEqual(expected2,types2);
2645         pass
2646
2647     def testCheckGeoEquivalWith(self):
2648         mesh1=MEDCouplingDataForTest.build2DTargetMesh_3();
2649         mesh2=MEDCouplingDataForTest.build2DTargetMesh_3();
2650         #First test mesh1
2651         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh1,0,1e-12);#deepEqual
2652         self.assertTrue(cellCor==None);
2653         self.assertTrue(nodeCor==None);
2654         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh1,1,1e-12);#fastEqual
2655         self.assertTrue(cellCor==None);
2656         self.assertTrue(nodeCor==None);
2657         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh1,10,1e-12);#deepEqual with geo permutations
2658         self.assertTrue(cellCor==None);
2659         self.assertTrue(nodeCor==None);
2660         #Second test mesh1 and mesh2 are 2 different meshes instance
2661         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,0,1e-12);#deepEqual
2662         self.assertTrue(cellCor==None);
2663         self.assertTrue(nodeCor==None);
2664         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,1,1e-12);#fastEqual
2665         self.assertTrue(cellCor==None);
2666         self.assertTrue(nodeCor==None);
2667         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,10,1e-12);#deepEqual with geo permutations
2668         self.assertTrue(cellCor==None);
2669         self.assertTrue(nodeCor==None);
2670         #Third test : cell permutation by keeping the first the middle and the last as it is.
2671         renum=[0,2,1,3,4,5,6,8,7,9]
2672         mesh2.renumberCells(renum,False);
2673         self.assertRaises(InterpKernelException,mesh1.checkGeoEquivalWith,mesh2,0,1e-12);#deepEqual fails
2674         self.assertTrue(cellCor==None);
2675         self.assertTrue(nodeCor==None);
2676         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,1,1e-12);#fastEqual do not see anything
2677         self.assertTrue(cellCor==None);
2678         self.assertTrue(nodeCor==None);
2679         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,10,1e-12);#deepEqual with geo permutations
2680         self.assertTrue(cellCor);
2681         self.assertEqual(10,cellCor.getNumberOfTuples());
2682         self.assertEqual(1,cellCor.getNumberOfComponents());
2683         self.assertEqual(renum,list(cellCor.getValues()))
2684         self.assertTrue(nodeCor==None);
2685         cellCor=0;
2686         self.assertTrue(nodeCor==None);
2687         a,b=mesh1.checkDeepEquivalWith(mesh2,0,1e-12);
2688         self.assertEqual(renum,list(a.getValues()))
2689         self.assertTrue(b==None);
2690         mesh2.setCoords(mesh1.getCoords())
2691         a=mesh1.checkDeepEquivalOnSameNodesWith(mesh2,0,1e-12);
2692         self.assertEqual(renum,list(a.getValues()))
2693         #4th test : cell and node permutation by keeping the first the middle and the last as it is.
2694         mesh2=MEDCouplingDataForTest.build2DTargetMesh_3();
2695         renum2=[0,2,1,3,4,5,6,8,7,9,10]
2696         mesh2.renumberCells(renum,False);
2697         mesh2.renumberNodes(renum2,11);
2698         cellCor=None
2699         nodeCor=None
2700         self.assertRaises(InterpKernelException,mesh1.checkGeoEquivalWith,mesh2,0,1e-12);#deepEqual fails
2701         self.assertTrue(cellCor==None);
2702         self.assertTrue(nodeCor==None);
2703         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,1,1e-12);#fastEqual do not see anything
2704         self.assertTrue(cellCor==None);
2705         self.assertTrue(nodeCor==None);
2706         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,10,1e-12);#deepEqual with geo permutations
2707         self.assertTrue(cellCor);
2708         self.assertEqual(10,cellCor.getNumberOfTuples());
2709         self.assertEqual(1,cellCor.getNumberOfComponents());
2710         self.assertEqual(renum,list(cellCor.getValues()))
2711         self.assertTrue(nodeCor);
2712         self.assertEqual(11,nodeCor.getNumberOfTuples());
2713         self.assertEqual(1,nodeCor.getNumberOfComponents());
2714         self.assertEqual(renum2,list(nodeCor.getValues()))
2715         cellCor=0;
2716         nodeCor=0;
2717         #5th test : modification of the last cell to check fastCheck detection.
2718         mesh2=MEDCouplingDataForTest.build2DTargetMesh_3();
2719         renum3=[0,2,1,3,4,5,6,8,9,7]
2720         mesh2.renumberCells(renum3,False);
2721         mesh2.renumberNodes(renum2,11);
2722         cellCor=None
2723         nodeCor=None
2724         self.assertRaises(InterpKernelException,mesh1.checkGeoEquivalWith,mesh2,0,1e-12)
2725         self.assertTrue(cellCor==None);
2726         self.assertTrue(nodeCor==None);
2727         self.assertRaises(InterpKernelException,mesh1.checkGeoEquivalWith,mesh2,1,1e-12)
2728         self.assertTrue(cellCor==None);
2729         self.assertTrue(nodeCor==None);
2730         cellCor,nodeCor=mesh2.checkGeoEquivalWith(mesh1,10,1e-12);#deepEqual with geo permutations
2731         self.assertTrue(cellCor!=None);
2732         self.assertEqual(10,cellCor.getNumberOfTuples());
2733         self.assertEqual(1,cellCor.getNumberOfComponents());
2734         self.assertEqual(renum3,list(cellCor.getValues()))
2735         self.assertTrue(nodeCor!=None);
2736         self.assertEqual(11,nodeCor.getNumberOfTuples());
2737         self.assertEqual(1,nodeCor.getNumberOfComponents());
2738         self.assertEqual(renum2,list(nodeCor.getValues()));
2739         pass
2740
2741     def testCheckGeoEquivalWith2(self):
2742         mesh1=MEDCouplingDataForTest.build2DTargetMesh_4();
2743         mesh2=MEDCouplingDataForTest.build2DTargetMesh_1();
2744         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,10,1e-12);
2745         self.assertEqual(None,cellCor);
2746         self.assertNotEqual(None,nodeCor);
2747         expected1=[0, 1, 3, 4, 5, 6, 7, 8, 9]
2748         for i in xrange(9):
2749             self.assertEqual(expected1[i],nodeCor.getIJ(i,0));
2750             pass
2751         pass
2752
2753     def testCopyTinyStringsFromOnFields(self):
2754         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
2755         nbOfCells=m.getNumberOfCells();
2756         f=MEDCouplingFieldDouble.New(ON_CELLS,LINEAR_TIME);
2757         f.setMesh(m);
2758         self.assertEqual(5,f.getNumberOfMeshPlacesExpected());
2759         f.setName("a");
2760         f.setDescription("b");
2761         a1=DataArrayDouble.New();
2762         a1.alloc(nbOfCells,2);
2763         a1.fillWithZero();
2764         a1.setInfoOnComponent(0,"c");
2765         a1.setInfoOnComponent(1,"d");
2766         a2=a1.deepCpy();
2767         a2.setInfoOnComponent(0,"e");
2768         a2.setInfoOnComponent(1,"f");
2769         f.setArray(a1);
2770         f.setEndArray(a2);
2771         f.setEndTime(3.,3,4);
2772         m.setName("g");
2773         m.getCoords().setInfoOnComponent(0,"h");
2774         m.getCoords().setInfoOnComponent(1,"i");
2775         m.getCoords().setInfoOnComponent(2,"j");
2776         #
2777         f.checkCoherency();
2778         f2=f.clone(True);
2779         self.assertTrue(f2.isEqual(f,1e-12,1e-12));
2780         f2.setName("smth");
2781         self.assertTrue(not f2.isEqual(f,1e-12,1e-12));
2782         f2.copyTinyStringsFrom(f);
2783         self.assertTrue(f2.isEqual(f,1e-12,1e-12));
2784         f2.setDescription("GGG");
2785         self.assertTrue(not f2.isEqual(f,1e-12,1e-12));
2786         f2.copyTinyStringsFrom(f);
2787         self.assertTrue(f2.isEqual(f,1e-12,1e-12));
2788         f2.getArray().setInfoOnComponent(0,"mmmm");
2789         self.assertTrue(not f2.isEqual(f,1e-12,1e-12));
2790         f2.copyTinyStringsFrom(f);
2791         self.assertTrue(f2.isEqual(f,1e-12,1e-12));
2792         f2.getEndArray().setInfoOnComponent(1,"mmmm");
2793         self.assertTrue(not f2.isEqual(f,1e-12,1e-12));
2794         f2.copyTinyStringsFrom(f);
2795         self.assertTrue(f2.isEqual(f,1e-12,1e-12));
2796         m2=m.clone(True);
2797         self.assertTrue(m2.isEqual(m,1e-12));
2798         m2.setName("123");
2799         self.assertTrue(not m2.isEqual(m,1e-12));
2800         m2.copyTinyStringsFrom(m);
2801         self.assertTrue(m2.isEqual(m,1e-12));
2802         m2.getCoords().setInfoOnComponent(1,"eee");
2803         self.assertTrue(not m2.isEqual(m,1e-12));
2804         m2.copyTinyStringsFrom(m);
2805         self.assertTrue(m2.isEqual(m,1e-12));
2806         pass
2807
2808     def testTryToShareSameCoordsPermute(self):
2809         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
2810         m2=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
2811         #self.assertTrue(m.getCoords()!=m2.getCoords());
2812         m.tryToShareSameCoordsPermute(m2,1e-12);
2813         #self.assertTrue(m.getCoords()==m2.getCoords());
2814         self.assertTrue(m2.isEqual(m,1e-12));
2815         renum1=[1,2,0,5,8,7,4,3,6]
2816         r1=DataArrayInt.New()
2817         r1.setValues(renum1,len(renum1),1)
2818         m.renumberNodes(r1,9);
2819         #self.assertTrue(m.getCoords()!=m2.getCoords());
2820         self.assertTrue(not m2.isEqual(m,1e-12));
2821         m.tryToShareSameCoordsPermute(m2,1e-12);
2822         #self.assertTrue(m.getCoords()==m2.getCoords());
2823         self.assertTrue(m2.isEqual(m,1e-12));
2824         pass
2825
2826     def testTryToShareSameCoordsPermute2(self):
2827         m1=MEDCouplingDataForTest.build2DTargetMesh_4();
2828         targetCoords=[-0.3,-0.3, 0.2,-0.3, -0.3,0.2, 0.2,0.2 ]
2829         targetConn=[0,2,3,1]
2830         m2=MEDCouplingUMesh.New();
2831         m2.setMeshDimension(2);
2832         m2.allocateCells(1);
2833         m2.insertNextCell(NORM_QUAD4,targetConn[0:4])
2834         m2.finishInsertingCells();
2835         myCoords=DataArrayDouble.New();
2836         myCoords.setValues(targetCoords,4,2);
2837         m2.setCoords(myCoords);
2838         m2.checkCoherency();
2839         m1.checkCoherency();
2840         #
2841         expected1=[0.25,0.125,0.125,0.25,0.25]
2842         f1=m1.getMeasureField(False);
2843         f2=m2.getMeasureField(False);
2844         self.assertEqual(5,f1.getArray().getNumberOfTuples());
2845         self.assertEqual(1,f2.getArray().getNumberOfTuples());
2846         for i in xrange(5):
2847             self.assertAlmostEqual(expected1[i],f1.getIJ(i,0),12);
2848             pass
2849         self.assertAlmostEqual(expected1[0],f2.getIJ(0,0),12);
2850         self.assertRaises(InterpKernelException,m1.tryToShareSameCoordsPermute,m2,1e-12);# <- here in this order the sharing is impossible.
2851         # Let's go for deeper test of tryToShareSameCoordsPermute
2852         m2.tryToShareSameCoordsPermute(m1,1e-12);
2853         f1=m1.getMeasureField(False);
2854         f2=m2.getMeasureField(False);
2855         self.assertEqual(5,f1.getArray().getNumberOfTuples());
2856         self.assertEqual(1,f2.getArray().getNumberOfTuples());
2857         for i in xrange(5):
2858             self.assertAlmostEqual(expected1[i],f1.getIJ(i,0),12);
2859             pass
2860         self.assertAlmostEqual(expected1[0],f2.getIJ(0,0),12);
2861         pass
2862
2863     def testChangeUnderlyingMesh1(self):
2864         mesh1=MEDCouplingDataForTest.build2DTargetMesh_3();
2865         mesh2=MEDCouplingDataForTest.build2DTargetMesh_3();
2866         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
2867         f1.setMesh(mesh1);
2868         array=DataArrayDouble.New();
2869         arr=[7., 107., 8., 108., 9., 109., 10., 110., 11., 111., 12., 112., 13., 113., 14., 114., 15., 115., 16., 116.]
2870         array.setValues(arr,mesh1.getNumberOfCells(),2);
2871         f1.setArray(array);
2872         #
2873         renum=[0,2,1,3,4,5,6,8,7,9]
2874         mesh2.renumberCells(renum,False);
2875         #self.assertTrue(f1.getMesh()==mesh1);
2876         f1.changeUnderlyingMesh(mesh1,10,1e-12);# nothing done only to check that nothing done.
2877         #self.assertTrue(f1.getMesh()==mesh1);
2878         f1.changeUnderlyingMesh(mesh2,10,1e-12);
2879         #self.assertTrue(f1.getMesh()==mesh2);
2880         expected1=[7.,107.,9.,109.,8.,108.,10.,110.,11.,111.,12.,112.,13.,113.,15.,115.,14.,114.,16.,116.]
2881         for i in xrange(20):
2882             self.assertAlmostEqual(expected1[i],f1.getArray().getIJ(0,i),12);
2883             pass
2884         #
2885         f1=MEDCouplingFieldDouble.New(ON_NODES,NO_TIME);
2886         f1.setMesh(mesh1);
2887         array=DataArrayDouble.New();
2888         arr2=[7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.,17.,117.]
2889         array.setValues(arr2,mesh1.getNumberOfNodes(),2);
2890         f1.setArray(array);
2891         #
2892         renum2=[0,2,10,3,4,5,6,8,7,9,1]
2893         mesh2.renumberNodes(renum2,11);
2894         #self.assertTrue(f1.getMesh()==mesh1);
2895         f1.changeUnderlyingMesh(mesh2,10,1e-12);
2896         #self.assertTrue(f1.getMesh()==mesh2);
2897         expected2=[7.,107.,17.,117.,8.,108.,10.,110.,11.,111.,12.,112.,13.,113.,15.,115.,14.,114.,16.,116.,9.,109.]
2898         for i in xrange(22):
2899             self.assertAlmostEqual(expected2[i],f1.getArray().getIJ(0,i),12);
2900             pass
2901         pass
2902
2903     def testGetMaxValue1(self):
2904         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
2905         nbOfCells=m.getNumberOfCells();
2906         f=MEDCouplingFieldDouble.New(ON_CELLS,LINEAR_TIME);
2907         f.setMesh(m);
2908         a1=DataArrayDouble.New();
2909         val1=[3.,4.,5.,6.,7.]
2910         a1.setValues(val1,nbOfCells,1);
2911         a2=DataArrayDouble.New();
2912         val2=[0.,1.,2.,8.,7.]
2913         a2.setValues(val2,nbOfCells,1);
2914         f.setArray(a1);
2915         f.setEndArray(a2);
2916         f.setEndTime(3.,3,4);
2917         f.checkCoherency();
2918         #
2919         self.assertAlmostEqual(8.,f.getMaxValue(),14);
2920         self.assertAlmostEqual(0.,f.getMinValue(),14);
2921         self.assertAlmostEqual(5.,f.getAverageValue(),14);
2922         self.assertAlmostEqual(5.125,f.getWeightedAverageValue(0,True),14);
2923         a1.setIJ(0,2,9.5);
2924         self.assertAlmostEqual(9.5,f.getMaxValue(),14);
2925         self.assertAlmostEqual(0.,f.getMinValue(),14);
2926         a2.setIJ(0,0,9.);
2927         self.assertAlmostEqual(9.5,f.getMaxValue(),14);
2928         self.assertAlmostEqual(1.,f.getMinValue(),14);
2929         pass
2930
2931     def testSubstractInPlaceDM1(self):
2932         mesh1=MEDCouplingDataForTest.build2DTargetMesh_3();
2933         mesh2=MEDCouplingDataForTest.build2DTargetMesh_3();
2934         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
2935         f1.setMesh(mesh1);
2936         array=DataArrayDouble.New();
2937         arr=[7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.]
2938         array.setValues(arr,mesh1.getNumberOfCells(),2);
2939         f1.setArray(array);
2940         #
2941         self.assertEqual(10,f1.getNumberOfTuples());
2942         self.assertEqual(2,f1.getNumberOfComponents());
2943         self.assertEqual(20,f1.getNumberOfValues());
2944         #
2945         renum=[0,2,3,1,4,5,6,8,7,9]
2946         mesh2.renumberCells(renum,False);
2947         #
2948         f2=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
2949         f2.setMesh(mesh2);
2950         array=DataArrayDouble.New();
2951         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]
2952         array.setValues(arr2,mesh2.getNumberOfCells(),2);
2953         f2.setArray(array);
2954         #
2955         f1.substractInPlaceDM(f2,10,1e-12);
2956         f1.applyFunc(1,"abs(x+y+0.2)");
2957         self.assertAlmostEqual(0.,f1.getMaxValue(),13);
2958         pass
2959
2960     def testDotCrossProduct1(self):
2961         mesh1=MEDCouplingDataForTest.build2DTargetMesh_3();
2962         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
2963         f1.setTime(2.3,5,6);
2964         f1.setMesh(mesh1);
2965         array=DataArrayDouble.New();
2966         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.]
2967         array.setValues(arr1,mesh1.getNumberOfCells(),3);
2968         f1.setArray(array);
2969         f2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
2970         f2.setTime(7.8,4,5);
2971         f2.setMesh(mesh1);
2972         array=DataArrayDouble.New();
2973         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.]
2974         array.setValues(arr2,mesh1.getNumberOfCells(),3);
2975         f2.setArray(array);
2976         #
2977         f3=f1.dot(f2);
2978         expected1=[842.,1820.,2816.,3830.,4862.,5912.,6980.,8066.,9170.,10292.]
2979         for i in xrange(10):
2980             self.assertAlmostEqual(expected1[i],f3.getIJ(i,0),9);
2981             pass
2982         #
2983         f4=f1.crossProduct(f2);
2984         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.]
2985         for i in xrange(30):
2986             self.assertAlmostEqual(expected2[i],f4.getIJ(0,i),9);
2987             pass
2988         pass
2989
2990     def testMinMaxFields1(self):
2991         mesh1=MEDCouplingDataForTest.build2DTargetMesh_3();
2992         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
2993         f1.setTime(2.3,5,6);
2994         f1.setMesh(mesh1);
2995         array=DataArrayDouble.New();
2996         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.]
2997         array.setValues(arr1,mesh1.getNumberOfCells(),3);
2998         f1.setArray(array);
2999         f2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
3000         f2.setTime(7.8,4,5);
3001         f2.setMesh(mesh1);
3002         array=DataArrayDouble.New();
3003         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.]
3004         array.setValues(arr2,mesh1.getNumberOfCells(),3);
3005         f2.setArray(array);
3006         #
3007         f3=f1.max(f2);
3008         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.]
3009         for i in xrange(30):
3010             self.assertAlmostEqual(expected1[i],f3.getIJ(0,i),9);
3011             pass
3012         #
3013         f4=f1.min(f2);
3014         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.]
3015         for i in xrange(30):
3016             self.assertAlmostEqual(expected2[i],f4.getIJ(0,i),9);
3017             pass
3018         #
3019         pass
3020
3021     def testApplyLin1(self):
3022         mesh1=MEDCouplingDataForTest.build2DTargetMesh_3();
3023         f1=MEDCouplingFieldDouble.New(ON_CELLS,LINEAR_TIME);
3024         f1.setMesh(mesh1);
3025         array=DataArrayDouble.New();
3026         arr=[7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.]
3027         array.setValues(arr,mesh1.getNumberOfCells(),2);
3028         f1.setArray(array);
3029         #
3030         f1.applyLin(2.,3.,0);
3031         expected1=[17.,107.,19.,108.,21.,109.,23.,110.,25.,111.,27.,112.,29.,113.,31.,114.,33.,115.,35.,116.]
3032         for i in xrange(20):
3033             self.assertAlmostEqual(expected1[i],f1.getIJ(0,i),9);
3034             pass
3035         #
3036         arr2=[2.,102.,3.,103.,4.,104.,5.,105.,6.,106.,7.,107.,8.,108.,9.,109.,10.,110.,11.,111.]
3037         array=DataArrayDouble.New();
3038         array.setValues(arr2,mesh1.getNumberOfCells(),2);
3039         f1.setEndArray(array);
3040         #
3041         f1.applyLin(4.,5.,1);
3042         #
3043         expected2=[17.,433.,19.,437.,21.,441.,23.,445.,25.,449.,27.,453.,29.,457.,31.,461.,33.,465.,35.,469.]
3044         for i in xrange(20):
3045             self.assertAlmostEqual(expected2[i],f1.getIJ(0,i),9);
3046             pass
3047         expected3=[2.,413.,3.,417.,4.,421.,5.,425.,6.,429.,7.,433.,8.,437.,9.,441.,10.,445.,11.,449.]
3048         for i in xrange(20):
3049             self.assertAlmostEqual(expected3[i],f1.getEndArray().getIJ(0,i),9);
3050             pass
3051         #
3052         pass
3053
3054     def testGetIdsInRange1(self):
3055         mesh1=MEDCouplingDataForTest.build2DTargetMesh_3();
3056         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
3057         f1.setTime(2.3,5,6);
3058         f1.setMesh(mesh1);
3059         array=DataArrayDouble.New();
3060         arr1=[2.,8.,6.,5.,11.,7.,9.,3.,10.,4.]
3061         array.setValues(arr1,mesh1.getNumberOfCells(),1);
3062         f1.setArray(array);
3063         #
3064         f1.checkCoherency();
3065         da=f1.getIdsInRange(2.9,7.1);
3066         self.failUnlessEqual(5,da.getNbOfElems());
3067         expected1=[2,3,5,7,9]
3068         self.failUnlessEqual(expected1,list(da.getValues()));
3069         da=f1.getIdsInRange(8.,12.);
3070         self.failUnlessEqual(4,da.getNbOfElems());
3071         expected2=[1,4,6,8]
3072         self.failUnlessEqual(expected2,list(da.getValues()));
3073         #
3074         pass
3075
3076     def testBuildSubPart1(self):
3077         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
3078         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
3079         f1.setTime(2.3,5,6);
3080         f1.setMesh(mesh1);
3081         array=DataArrayDouble.New();
3082         arr1=[3.,103.,4.,104.,5.,105.,6.,106.,7.,107.]
3083         array.setValues(arr1,mesh1.getNumberOfCells(),2);
3084         f1.setArray(array);
3085         #
3086         part1=[2,1,4]
3087         f2=f1[part1];
3088         f2.zipCoords()
3089         self.failUnlessEqual(3,f2.getNumberOfTuples());
3090         self.failUnlessEqual(2,f2.getNumberOfComponents());
3091         expected1=[5.,105.,4.,104.,7.,107.]
3092         for i in xrange(6):
3093             self.assertAlmostEqual(f2.getIJ(0,i),expected1[i],12);
3094             pass
3095         self.failUnlessEqual(3,f2.getMesh().getNumberOfCells());
3096         self.failUnlessEqual(6,f2.getMesh().getNumberOfNodes());
3097         self.failUnlessEqual(2,f2.getMesh().getSpaceDimension());
3098         self.failUnlessEqual(2,f2.getMesh().getMeshDimension());
3099         m2C=f2.getMesh();
3100         self.failUnlessEqual(13,m2C.getMeshLength());
3101         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]
3102         for i in xrange(12):
3103             self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12);
3104             pass
3105         expected3=[3,2,3,1,3,0,2,1,4,4,5,3,2]
3106         self.failUnlessEqual(expected3,list(m2C.getNodalConnectivity().getValues()));
3107         expected4=[0,4,8,13]
3108         self.failUnlessEqual(expected4,list(m2C.getNodalConnectivityIndex().getValues()));
3109         # Test with field on nodes.
3110         f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME);
3111         f1.setTime(2.3,5,6);
3112         f1.setMesh(mesh1);
3113         array=DataArrayDouble.New();
3114         arr2=[3.,103.,4.,104.,5.,105.,6.,106.,7.,107.,8.,108.,9.,109.,10.,110.,11.,111.]
3115         array.setValues(arr2,mesh1.getNumberOfNodes(),2);
3116         f1.setArray(array);
3117         part2=[1,2]
3118         f2=f1.buildSubPart(part2);
3119         self.failUnlessEqual(4,f2.getNumberOfTuples());
3120         self.failUnlessEqual(2,f2.getNumberOfComponents());
3121         expected5=[4.,104.,5.,105.,7.,107.,8.,108.]
3122         for i in xrange(8):
3123             self.assertAlmostEqual(f2.getIJ(0,i),expected5[i],12);
3124             pass
3125         self.failUnlessEqual(2,f2.getMesh().getNumberOfCells());
3126         self.failUnlessEqual(4,f2.getMesh().getNumberOfNodes());
3127         self.failUnlessEqual(2,f2.getMesh().getSpaceDimension());
3128         self.failUnlessEqual(2,f2.getMesh().getMeshDimension());
3129         m2C=f2.getMesh();
3130         self.failUnlessEqual(8,m2C.getMeshLength());
3131         for i in xrange(8):#8 is not an error
3132             self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12);
3133             pass
3134         self.failUnlessEqual(expected3[:4],list(m2C.getNodalConnectivity().getValues())[4:]);
3135         self.failUnlessEqual(expected3[4:8],list(m2C.getNodalConnectivity().getValues())[:4]);
3136         self.failUnlessEqual(expected4[:3],list(m2C.getNodalConnectivityIndex().getValues()));
3137         #idem previous because nodes of cell#4 are not fully present in part3
3138         part3=[1,2]
3139         arrr=DataArrayInt.New();
3140         arrr.setValues(part3,2,1);
3141         f2=f1.buildSubPart(arrr);
3142         self.failUnlessEqual(4,f2.getNumberOfTuples());
3143         self.failUnlessEqual(2,f2.getNumberOfComponents());
3144         for i in xrange(8):
3145             self.assertAlmostEqual(f2.getIJ(0,i),expected5[i],12);
3146             pass
3147         self.failUnlessEqual(2,f2.getMesh().getNumberOfCells());
3148         self.failUnlessEqual(4,f2.getMesh().getNumberOfNodes());
3149         self.failUnlessEqual(2,f2.getMesh().getSpaceDimension());
3150         self.failUnlessEqual(2,f2.getMesh().getMeshDimension());
3151         m2C=f2.getMesh();
3152         self.failUnlessEqual(8,m2C.getMeshLength());
3153         for i in xrange(8):#8 is not an error
3154             self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12);
3155             pass
3156         self.failUnlessEqual(expected3[:4],list(m2C.getNodalConnectivity().getValues())[4:8]);
3157         self.failUnlessEqual(expected3[4:8],list(m2C.getNodalConnectivity().getValues())[:4]);
3158         self.failUnlessEqual(expected4[:3],list(m2C.getNodalConnectivityIndex().getValues()));
3159         #
3160         part4=[1,2,4]
3161         f2=f1.buildSubPart(part4);
3162         self.failUnlessEqual(6,f2.getNumberOfTuples());
3163         self.failUnlessEqual(2,f2.getNumberOfComponents());
3164         expected6=[4.,104.,5.,105.,7.,107.,8.,108.,10.,110.,11.,111.]
3165         for i in xrange(12):
3166             self.assertAlmostEqual(f2.getIJ(0,i),expected6[i],12);
3167             pass
3168         self.failUnlessEqual(3,f2.getMesh().getNumberOfCells());
3169         self.failUnlessEqual(6,f2.getMesh().getNumberOfNodes());
3170         self.failUnlessEqual(2,f2.getMesh().getSpaceDimension());
3171         self.failUnlessEqual(2,f2.getMesh().getMeshDimension());
3172         m2C=f2.getMesh();
3173         self.failUnlessEqual(13,m2C.getMeshLength());
3174         for i in xrange(12):
3175             self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12);
3176             pass
3177         self.failUnlessEqual(expected3[0:4],list(m2C.getNodalConnectivity().getValues())[4:8]);
3178         self.failUnlessEqual(expected3[4:8],list(m2C.getNodalConnectivity().getValues())[0:4]);
3179         self.failUnlessEqual(expected3[8:13],list(m2C.getNodalConnectivity().getValues())[8:13]);
3180         self.failUnlessEqual(expected4,list(m2C.getNodalConnectivityIndex().getValues()));
3181         pass
3182
3183     def testDoublyContractedProduct1(self):
3184         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
3185         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
3186         f1.setMesh(mesh1);
3187         array=DataArrayDouble.New();
3188         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]
3189         array.setValues(arr1,mesh1.getNumberOfCells(),6);
3190         f1.setArray(array);
3191         f1.checkCoherency();
3192         #
3193         f2=f1.doublyContractedProduct();
3194         f2.checkCoherency();
3195         self.assertEqual(1,f2.getNumberOfComponents());
3196         self.assertEqual(5,f2.getNumberOfTuples());
3197         for i in xrange(5):
3198             self.assertAlmostEqual(3906.56,f2.getIJ(i,0),9);
3199             pass
3200         #
3201         pass
3202
3203     def testDeterminant1(self):
3204         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
3205         f1=MEDCouplingFieldDouble.New(ON_CELLS,CONST_ON_TIME_INTERVAL);
3206         f1.setTime(2.3,5,6);
3207         f1.setEndTime(3.8,7,3);
3208         f1.setMesh(mesh1);
3209         array=DataArrayDouble.New();
3210         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]
3211         array.setValues(arr1,mesh1.getNumberOfCells(),4);
3212         f1.setArray(array);
3213         #4 components
3214         f1.checkCoherency();
3215         f2=f1.determinant();
3216         f2.checkCoherency();
3217         self.assertEqual(CONST_ON_TIME_INTERVAL,f2.getTimeDiscretization());
3218         self.assertEqual(1,f2.getNumberOfComponents());
3219         self.assertEqual(5,f2.getNumberOfValues());
3220         for i in xrange(5):
3221             self.assertAlmostEqual(-2.42,f2.getIJ(i,0),13);
3222             pass
3223         #6 components multi arrays with end array not defined
3224         f1=MEDCouplingFieldDouble.New(ON_NODES,LINEAR_TIME);
3225         f1.setTime(2.3,5,6);
3226         f1.setEndTime(3.8,7,3);
3227         f1.setMesh(mesh1);
3228         array=DataArrayDouble.New();
3229         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,
3230               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]
3231         array.setValues(arr2,mesh1.getNumberOfNodes(),6);
3232         f1.setArray(array);
3233         self.assertRaises(InterpKernelException,f1.checkCoherency);#no end array specified !
3234         #
3235         f2=f1.determinant();
3236         self.assertEqual(LINEAR_TIME,f2.getTimeDiscretization());
3237         self.assertEqual(1,f2.getArray().getNumberOfComponents());
3238         self.assertEqual(9,f2.getNumberOfTuples());
3239         for i in xrange(9):
3240             self.assertAlmostEqual(137.335,f2.getIJ(i,0),10);
3241             pass
3242         #6 components multi arrays with end array defined
3243         array=DataArrayDouble.New();
3244         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,
3245               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]
3246         array.setValues(arr3,mesh1.getNumberOfNodes(),6);
3247         f1.setEndArray(array);
3248         f1.checkCoherency();
3249         f2=f1.determinant();
3250         f2.checkCoherency();
3251         self.assertEqual(LINEAR_TIME,f2.getTimeDiscretization());
3252         self.assertEqual(1,f2.getNumberOfComponents());
3253         self.assertEqual(9,f2.getNumberOfTuples());
3254         time2,it,order=f2.getTime()
3255         self.assertAlmostEqual(2.3,time2,12);
3256         self.assertEqual(5,it);
3257         self.assertEqual(6,order);
3258         time2,it,order=f2.getEndTime()
3259         self.assertAlmostEqual(3.8,time2,12);
3260         self.assertEqual(7,it);
3261         self.assertEqual(3,order);
3262         for i in xrange(9):
3263             self.assertAlmostEqual(137.335,f2.getIJ(i,0),10);
3264             self.assertAlmostEqual(1289.685,f2.getEndArray().getIJ(i,0),9);
3265             pass
3266         #9 components
3267         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
3268         f1.setTime(7.8,10,2);
3269         f1.setMesh(mesh1);
3270         array=DataArrayDouble.New();
3271         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]
3272         array.setValues(arr4,mesh1.getNumberOfCells(),9);
3273         f1.setArray(array);
3274         #
3275         f1.checkCoherency();
3276         f2=f1.determinant();
3277         f2.checkCoherency();
3278         self.assertEqual(ONE_TIME,f2.getTimeDiscretization());
3279         self.assertEqual(1,f2.getNumberOfComponents());
3280         self.assertEqual(5,f2.getNumberOfTuples());
3281         time2,it,order=f2.getTime()
3282         self.assertAlmostEqual(7.8,time2,12);
3283         self.assertEqual(10,it);
3284         self.assertEqual(2,order);
3285         for i in xrange(5):
3286             self.assertAlmostEqual(3.267,f2.getIJ(i,0),13);
3287             pass
3288         pass
3289
3290     def testEigenValues1(self):
3291         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
3292         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
3293         f1.setMesh(mesh1);
3294         array=DataArrayDouble.New();
3295         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]
3296         array.setValues(arr1,mesh1.getNumberOfCells(),6);
3297         f1.setArray(array);
3298         f1.checkCoherency();
3299         #
3300         f2=f1.eigenValues();
3301         f2.checkCoherency();
3302         self.assertEqual(3,f2.getNumberOfComponents());
3303         self.assertEqual(5,f2.getNumberOfTuples());
3304         expected1=[13.638813677891717,-4.502313844635971,-2.2364998332557486]
3305         for i in xrange(5):
3306             self.assertAlmostEqual(expected1[0],f2.getIJ(i,0),13);
3307             self.assertAlmostEqual(expected1[1],f2.getIJ(i,1),13);
3308             self.assertAlmostEqual(expected1[2],f2.getIJ(i,2),13);
3309             pass
3310         pass
3311
3312     def testEigenVectors1(self):
3313         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
3314         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
3315         f1.setMesh(mesh1);
3316         array=DataArrayDouble.New();
3317         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]
3318         array.setValues(arr1,mesh1.getNumberOfCells(),6);
3319         f1.setArray(array);
3320         f1.checkCoherency();
3321         #
3322         f2=f1.eigenVectors();
3323         f2.checkCoherency();
3324         self.assertEqual(9,f2.getNumberOfComponents());
3325         self.assertEqual(5,f2.getNumberOfTuples());
3326         expected1=[0.5424262364180696, 0.5351201064614425, 0.6476266283176001,#eigenvect 0
3327                    0.7381111277307373, 0.06458838384003074, -0.6715804522117897,#eigenvect 1
3328                    -0.4012053603397987, 0.8423032781211455, -0.3599436712889738#eigenvect 2
3329                    ]
3330         for i in xrange(5):
3331             self.assertAlmostEqual(expected1[0],f2.getIJ(i,0),13);
3332             self.assertAlmostEqual(expected1[1],f2.getIJ(i,1),13);
3333             self.assertAlmostEqual(expected1[2],f2.getIJ(i,2),13);
3334             self.assertAlmostEqual(expected1[3],f2.getIJ(i,3),13);
3335             self.assertAlmostEqual(expected1[4],f2.getIJ(i,4),13);
3336             self.assertAlmostEqual(expected1[5],f2.getIJ(i,5),13);
3337             self.assertAlmostEqual(expected1[6],f2.getIJ(i,6),13);
3338             self.assertAlmostEqual(expected1[7],f2.getIJ(i,7),13);
3339             self.assertAlmostEqual(expected1[8],f2.getIJ(i,8),13);
3340             pass
3341         #
3342         pass
3343
3344     def testInverse1(self):
3345         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
3346         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
3347         f1.setMesh(mesh1);
3348         array=DataArrayDouble.New();
3349         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]
3350         array.setValues(arr1,mesh1.getNumberOfCells(),9);
3351         f1.setArray(array);
3352         f1.checkCoherency();
3353         #
3354         f2=f1.inverse();
3355         f2.checkCoherency();
3356         self.assertEqual(9,f2.getNumberOfComponents());
3357         self.assertEqual(5,f2.getNumberOfTuples());
3358         expected1=[-2.6538108356290113, 2.855831037649208, -1.1111111111111067, 3.461891643709813, -4.775022956841121, 2.2222222222222143, -1.1111111111111054, 2.222222222222214, -1.1111111111111072]
3359         for i in xrange(5):
3360             self.assertAlmostEqual(expected1[0],f2.getIJ(i,0),13);
3361             self.assertAlmostEqual(expected1[1],f2.getIJ(i,1),13);
3362             self.assertAlmostEqual(expected1[2],f2.getIJ(i,2),13);
3363             self.assertAlmostEqual(expected1[3],f2.getIJ(i,3),13);
3364             self.assertAlmostEqual(expected1[4],f2.getIJ(i,4),13);
3365             self.assertAlmostEqual(expected1[5],f2.getIJ(i,5),13);
3366             self.assertAlmostEqual(expected1[6],f2.getIJ(i,6),13);
3367             self.assertAlmostEqual(expected1[7],f2.getIJ(i,7),13);
3368             self.assertAlmostEqual(expected1[8],f2.getIJ(i,8),13);
3369             pass
3370         #
3371         array=DataArrayDouble.New();
3372         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]
3373         array.setValues(arr3,mesh1.getNumberOfCells(),6);
3374         f1.setArray(array);
3375         f1.checkCoherency();
3376         #
3377         f2=f1.inverse();
3378         f2.checkCoherency();
3379         self.assertEqual(6,f2.getNumberOfComponents());
3380         self.assertEqual(5,f2.getNumberOfTuples());
3381         expected3=[-0.3617705098531818, -0.8678630828458127, -0.026843764174972983, 0.5539957431465833, 0.13133439560823013, -0.05301294502145887]
3382         for i in xrange(5):
3383             self.assertAlmostEqual(expected3[0],f2.getIJ(i,0),13);
3384             self.assertAlmostEqual(expected3[1],f2.getIJ(i,1),13);
3385             self.assertAlmostEqual(expected3[2],f2.getIJ(i,2),13);
3386             self.assertAlmostEqual(expected3[3],f2.getIJ(i,3),13);
3387             self.assertAlmostEqual(expected3[4],f2.getIJ(i,4),13);
3388             self.assertAlmostEqual(expected3[5],f2.getIJ(i,5),13);
3389             pass
3390         #
3391         array=DataArrayDouble.New();
3392         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]
3393         array.setValues(arr2,mesh1.getNumberOfCells(),4);
3394         f1.setArray(array);
3395         f1.checkCoherency();
3396         #
3397         f2=f1.inverse();
3398         f2.checkCoherency();
3399         self.assertEqual(4,f2.getNumberOfComponents());
3400         self.assertEqual(5,f2.getNumberOfTuples());
3401         expected2=[-1.8595041322314059, 0.9504132231404963, 1.404958677685951, -0.49586776859504156]
3402         for i in xrange(5):
3403             self.assertAlmostEqual(expected2[0],f2.getIJ(i,0),13);
3404             self.assertAlmostEqual(expected2[1],f2.getIJ(i,1),13);
3405             self.assertAlmostEqual(expected2[2],f2.getIJ(i,2),13);
3406             self.assertAlmostEqual(expected2[3],f2.getIJ(i,3),13);
3407             pass
3408         #
3409         pass
3410
3411     def testTrace1(self):
3412         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
3413         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
3414         f1.setMesh(mesh1);
3415         array=DataArrayDouble.New();
3416         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]
3417         array.setValues(arr1,mesh1.getNumberOfCells(),9);
3418         f1.setArray(array);
3419         f1.checkCoherency();
3420         #
3421         f2=f1.trace();
3422         f2.checkCoherency();
3423         self.assertEqual(1,f2.getNumberOfComponents());
3424         self.assertEqual(5,f2.getNumberOfTuples());
3425         for i in xrange(5):
3426             self.assertAlmostEqual(15.9,f2.getIJ(i,0),13);
3427             pass
3428         #
3429         array=DataArrayDouble.New();
3430         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]
3431         array.setValues(arr3,mesh1.getNumberOfCells(),6);
3432         f1.setArray(array);
3433         f1.checkCoherency();
3434         #
3435         f2=f1.trace();
3436         f2.checkCoherency();
3437         self.assertEqual(1,f2.getNumberOfComponents());
3438         self.assertEqual(5,f2.getNumberOfTuples());
3439         for i in xrange(5):
3440             self.assertAlmostEqual(25.8,f2.getIJ(i,0),13);
3441             pass
3442         #
3443         array=DataArrayDouble.New();
3444         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]
3445         array.setValues(arr2,mesh1.getNumberOfCells(),4);
3446         f1.setArray(array);
3447         f1.checkCoherency();
3448         #
3449         f2=f1.trace();
3450         f2.checkCoherency();
3451         self.assertEqual(1,f2.getNumberOfComponents());
3452         self.assertEqual(5,f2.getNumberOfTuples());
3453         for i in xrange(5):
3454             self.assertAlmostEqual(5.7,f2.getIJ(i,0),13);
3455             pass
3456         #
3457         pass
3458
3459     def testDeviator1(self):
3460         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
3461         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
3462         f1.setMesh(mesh1);
3463         array=DataArrayDouble.New();
3464         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]
3465         array.setValues(arr1,mesh1.getNumberOfCells(),6);
3466         f1.setArray(array);
3467         f1.checkCoherency();
3468         #
3469         f2=f1.deviator();
3470         f2.checkCoherency();
3471         self.assertEqual(6,f2.getNumberOfComponents());
3472         self.assertEqual(5,f2.getNumberOfTuples());
3473         expected1=[-1.1,0.,1.1,4.5,5.6,6.7]
3474         for i in xrange(5):
3475             self.assertAlmostEqual(expected1[0],f2.getIJ(i,0),13);
3476             self.assertAlmostEqual(expected1[1],f2.getIJ(i,1),13);
3477             self.assertAlmostEqual(expected1[2],f2.getIJ(i,2),13);
3478             self.assertAlmostEqual(expected1[3],f2.getIJ(i,3),13);
3479             self.assertAlmostEqual(expected1[4],f2.getIJ(i,4),13);
3480             self.assertAlmostEqual(expected1[5],f2.getIJ(i,5),13);
3481             pass
3482         #
3483         pass
3484
3485     def testMagnitude1(self):
3486         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
3487         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
3488         f1.setMesh(mesh1);
3489         array=DataArrayDouble.New();
3490         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]
3491         array.setValues(arr1,mesh1.getNumberOfCells(),5);
3492         f1.setArray(array);
3493         f1.checkCoherency();
3494         #
3495         f2=f1.magnitude();
3496         f2.checkCoherency();
3497         self.assertEqual(1,f2.getNumberOfComponents());
3498         self.assertEqual(5,f2.getNumberOfTuples());
3499         for i in xrange(5):
3500             self.assertAlmostEqual(8.3606219864313918,f2.getIJ(i,0),13);
3501             pass
3502         #
3503         pass
3504
3505     def testMaxPerTuple1(self):
3506         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
3507         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
3508         f1.setMesh(mesh1);
3509         array=DataArrayDouble.New();
3510         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]
3511         array.setValues(arr1,mesh1.getNumberOfCells(),5);
3512         f1.setArray(array);
3513         f1.checkCoherency();
3514         #
3515         f2=f1.maxPerTuple();
3516         f2.checkCoherency();
3517         self.assertEqual(1,f2.getNumberOfComponents());
3518         self.assertEqual(5,f2.getNumberOfTuples());
3519         for i in xrange(5):
3520             self.assertAlmostEqual(5.6,f2.getIJ(i,0),13);
3521             pass
3522         #
3523         d2,d2I=array.maxPerTupleWithCompoId()
3524         self.assertEqual(1,d2.getNumberOfComponents());
3525         self.assertEqual(5,d2.getNumberOfTuples());
3526         for i in xrange(5):
3527             self.assertAlmostEqual(5.6,d2.getIJ(i,0),13);
3528             pass
3529         self.assertTrue(d2I.isEqual(DataArrayInt([4,3,2,0,1])))
3530         pass
3531
3532     def testChangeNbOfComponents(self):
3533         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
3534         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
3535         f1.setMesh(mesh1);
3536         array=DataArrayDouble.New();
3537         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]
3538         array.setValues(arr1,mesh1.getNumberOfCells(),5);
3539         f1.setArray(array);
3540         f1.checkCoherency();
3541         #
3542         f1.changeNbOfComponents(3,7.77);
3543         f1.checkCoherency();
3544         self.assertEqual(3,f1.getNumberOfComponents());
3545         self.assertEqual(5,f1.getNumberOfTuples());
3546         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]
3547         for i in xrange(15):
3548             self.assertAlmostEqual(expected1[i],f1.getIJ(0,i),13);
3549             pass
3550         f1.changeNbOfComponents(4,7.77);
3551         f1.checkCoherency();
3552         self.assertEqual(4,f1.getNumberOfComponents());
3553         self.assertEqual(5,f1.getNumberOfTuples());
3554         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]
3555         for i in xrange(20):
3556             self.assertAlmostEqual(expected2[i],f1.getIJ(0,i),13);
3557             pass
3558         #
3559         pass
3560
3561     def testSortPerTuple1(self):
3562         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
3563         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
3564         f1.setMesh(mesh1);
3565         array=DataArrayDouble.New();
3566         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]
3567         array.setValues(arr1,mesh1.getNumberOfCells(),5);
3568         f1.setArray(array);
3569         f1.checkCoherency();
3570         #
3571         f1.sortPerTuple(True);
3572         f1.checkCoherency();
3573         self.assertEqual(5,f1.getNumberOfComponents());
3574         self.assertEqual(5,f1.getNumberOfTuples());
3575         for i in xrange(5):
3576             self.assertAlmostEqual(arr1[0],f1.getIJ(i,0),13);
3577             self.assertAlmostEqual(arr1[1],f1.getIJ(i,1),13);
3578             self.assertAlmostEqual(arr1[2],f1.getIJ(i,2),13);
3579             self.assertAlmostEqual(arr1[3],f1.getIJ(i,3),13);
3580             self.assertAlmostEqual(arr1[4],f1.getIJ(i,4),13);
3581             pass
3582         #
3583         f1.sortPerTuple(False);
3584         f1.checkCoherency();
3585         self.assertEqual(5,f1.getNumberOfComponents());
3586         self.assertEqual(5,f1.getNumberOfTuples());
3587         for i in xrange(5):
3588             self.assertAlmostEqual(arr1[4],f1.getIJ(i,0),13);
3589             self.assertAlmostEqual(arr1[3],f1.getIJ(i,1),13);
3590             self.assertAlmostEqual(arr1[2],f1.getIJ(i,2),13);
3591             self.assertAlmostEqual(arr1[1],f1.getIJ(i,3),13);
3592             self.assertAlmostEqual(arr1[0],f1.getIJ(i,4),13);
3593             pass
3594         #
3595         pass
3596
3597     def testIsEqualWithoutConsideringStr1(self):
3598         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
3599         mesh2=MEDCouplingDataForTest.build2DTargetMesh_1();
3600         #
3601         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
3602         self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
3603         mesh2.setName("rr");
3604         self.assertTrue(not mesh1.isEqual(mesh2,1e-12));
3605         self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
3606         da1,da2=mesh1.checkGeoEquivalWith(mesh2,2,1e-12);
3607         self.assertRaises(InterpKernelException,mesh1.checkGeoEquivalWith,mesh2,0,1e-12);
3608         mesh2.setName("");
3609         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
3610         self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
3611         mesh2.getCoords().setInfoOnComponent(0,"tty");
3612         self.assertTrue(not mesh1.isEqual(mesh2,1e-12));
3613         self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
3614         mesh2.getCoords().setInfoOnComponent(0,"");
3615         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
3616         self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
3617         mesh2.getCoords().setInfoOnComponent(1,"tty");
3618         self.assertTrue(not mesh1.isEqual(mesh2,1e-12));
3619         self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
3620         mesh2.getCoords().setInfoOnComponent(1,"");
3621         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
3622         self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
3623         tmp=mesh2.getCoords().getIJ(0,3);
3624         mesh2.getCoords().setIJ(0,3,9999.);
3625         self.assertTrue(not mesh1.isEqual(mesh2,1e-12));
3626         self.assertTrue(not mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
3627         mesh2.getCoords().setIJ(0,3,tmp);
3628         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
3629         self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
3630         tmp2=mesh2.getNodalConnectivity().getIJ(0,4);
3631         mesh2.getNodalConnectivity().setIJ(0,4,0);
3632         self.assertTrue(not mesh1.isEqual(mesh2,1e-12));
3633         self.assertTrue(not mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
3634         mesh2.getNodalConnectivity().setIJ(0,4,tmp2);
3635         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
3636         self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
3637         #
3638         f1=mesh1.getMeasureField(True);
3639         f2=mesh2.getMeasureField(True);
3640         self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
3641         self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,1e-12));
3642         f2.setName("ftest");
3643         self.assertTrue(not f1.isEqual(f2,1e-12,1e-12));
3644         self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,1e-12));
3645         f1.setName("ftest");
3646         self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
3647         self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,1e-12));
3648         #
3649         f2.getArray().setInfoOnComponent(0,"eee");
3650         self.assertTrue(not f1.isEqual(f2,1e-12,1e-12));
3651         self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,1e-12));
3652         f2.getArray().setInfoOnComponent(0,"");
3653         self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
3654         self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,1e-12));
3655         #
3656         f2.getArray().setIJ(1,0,0.123);
3657         self.assertTrue(not f1.isEqual(f2,1e-12,1e-12));
3658         self.assertTrue(not f1.isEqualWithoutConsideringStr(f2,1e-12,1e-12));
3659         f2.getArray().setIJ(1,0,0.125);
3660         self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
3661         self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,1e-12));
3662         #
3663         pass
3664     
3665     def testGetNodeIdsOfCell1(self):
3666         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
3667         li=mesh1.getNodeIdsOfCell(1)
3668         expected1=[1, 4, 2]
3669         self.assertEqual(expected1,list(li))
3670         li=mesh1.getCoordinatesOfNode(4)
3671         self.assertEqual(2,len(li))
3672         self.assertAlmostEqual(0.2,li[0],13);
3673         self.assertAlmostEqual(0.2,li[1],13);
3674         li=mesh1.getCoords().getValuesAsTuple()
3675         self.assertEqual(9,len(li))
3676         li2=mesh1.getNodalConnectivityIndex().getValuesAsTuple()
3677         self.assertEqual(6,len(li2))
3678         pass
3679
3680     def testGetEdgeRatioField1(self):
3681         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
3682         m1.setTime(3.4,5,6); m1.setTimeUnit("us");
3683         f1=m1.getEdgeRatioField();
3684         self.assertAlmostEqual(3.4,f1.getTime()[0],12) ; self.assertEqual(5,f1.getTime()[1]) ; self.assertEqual(6,f1.getTime()[2])
3685         self.assertEqual("us",f1.getTimeUnit())
3686         self.assertEqual(m1.getNumberOfCells(),f1.getNumberOfTuples());
3687         self.assertEqual(5,f1.getNumberOfTuples());
3688         self.assertEqual(1,f1.getNumberOfComponents());
3689         expected1=[1.,1.4142135623730951, 1.4142135623730951,1.,1.]
3690         for i in xrange(5):
3691             self.assertAlmostEqual(expected1[i],f1.getIJ(i,0),14);
3692             pass
3693         #
3694         m1=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
3695         f1=m1.getEdgeRatioField();
3696         self.assertEqual(m1.getNumberOfCells(),f1.getNumberOfTuples());
3697         self.assertEqual(5,f1.getNumberOfTuples());
3698         self.assertEqual(1,f1.getNumberOfComponents());
3699         expected2=[1.4142135623730951, 1.7320508075688772, 1.7320508075688772, 1.4142135623730951, 1.4142135623730951]
3700         for i in xrange(5):
3701             self.assertAlmostEqual(expected2[i],f1.getIJ(i,0),14);
3702             pass
3703         pass
3704
3705     def testFillFromAnalytic3(self):
3706         m=MEDCouplingDataForTest.build2DTargetMesh_1()
3707         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME)
3708         self.assertRaises(InterpKernelException,f1.fillFromAnalytic,1,"y+x");
3709         f1.setMesh(m)
3710         f1.setName("myField");
3711         f1.fillFromAnalytic(1,"y+x");
3712         f1.checkCoherency();
3713         self.assertEqual(f1.getName(),"myField");
3714         self.assertEqual(f1.getTypeOfField(),ON_CELLS);
3715         self.assertEqual(f1.getTimeDiscretization(),ONE_TIME);
3716         self.assertEqual(1,f1.getNumberOfComponents());
3717         self.assertEqual(5,f1.getNumberOfTuples());
3718         values1=[-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9]
3719         tmp=f1.getArray().getValues();
3720         self.assertEqual(len(values1),len(tmp))
3721         for i in xrange(len(values1)):
3722             self.assertTrue(abs(values1[i]-tmp[i])<1.e-12);
3723             pass
3724         #
3725         f1=MEDCouplingFieldDouble.New(ON_NODES,CONST_ON_TIME_INTERVAL)
3726         f1.setMesh(m)
3727         f1.fillFromAnalytic(1,"y+2*x");
3728         f1.setEndTime(1.2,3,4);
3729         f1.checkCoherency();
3730         self.assertEqual(f1.getTypeOfField(),ON_NODES);
3731         self.assertEqual(f1.getTimeDiscretization(),CONST_ON_TIME_INTERVAL);
3732         self.assertEqual(1,f1.getNumberOfComponents());
3733         self.assertEqual(9,f1.getNumberOfTuples());
3734         values2=[-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1]
3735         tmp=f1.getArray().getValues();
3736         self.assertEqual(len(values2),len(tmp))
3737         for i in xrange(len(values2)):
3738             self.assertTrue(abs(values2[i]-tmp[i])<1.e-12);
3739             pass
3740         f1=MEDCouplingFieldDouble.New(ON_NODES,LINEAR_TIME);
3741         f1.setMesh(m)
3742         f1.fillFromAnalytic(1,"2.*x+y");
3743         f1.setEndTime(1.2,3,4);
3744         f1.checkCoherency();
3745         self.assertEqual(f1.getTypeOfField(),ON_NODES);
3746         self.assertEqual(f1.getTimeDiscretization(),LINEAR_TIME);
3747         self.assertEqual(1,f1.getNumberOfComponents());
3748         self.assertEqual(9,f1.getNumberOfTuples());
3749         tmp=f1.getArray().getValues();
3750         values2Bis=[-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1]
3751         self.assertEqual(len(values2Bis),len(tmp))
3752         for i in xrange(len(values2Bis)):
3753             self.assertTrue(abs(values2Bis[i]-tmp[i])<1.e-12);
3754             pass
3755         tmp=f1.getEndArray().getValues();
3756         self.assertEqual(len(values2Bis),len(tmp))
3757         for i in xrange(len(values2Bis)):
3758             self.assertTrue(abs(values2Bis[i]-tmp[i])<1.e-12);
3759             pass
3760         #
3761         f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME);
3762         f1.setMesh(m)
3763         f1.fillFromAnalytic(2,"(x+y)*IVec+2*(x+y)*JVec");
3764         f1.checkCoherency();
3765         self.assertEqual(f1.getTypeOfField(),ON_NODES);
3766         self.assertEqual(f1.getTimeDiscretization(),ONE_TIME);
3767         self.assertEqual(2,f1.getNumberOfComponents());
3768         self.assertEqual(9,f1.getNumberOfTuples());
3769         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]
3770         tmp=f1.getArray().getValues();
3771         self.assertEqual(len(values3),len(tmp))
3772         for i in xrange(len(values3)):
3773             self.assertTrue(abs(values3[i]-tmp[i])<1.e-12);
3774             pass
3775         values4=f1.accumulate();
3776         self.assertTrue(abs(3.6-values4[0])<1.e-12);
3777         self.assertTrue(abs(7.2-values4[1])<1.e-12);
3778         values4=f1.integral(True);
3779         self.assertTrue(abs(0.5-values4[0])<1.e-12);
3780         self.assertTrue(abs(1.-values4[1])<1.e-12);
3781         #
3782         f1=MEDCouplingFieldDouble.New(ON_NODES,NO_TIME);
3783         f1.setMesh(m);
3784         self.assertRaises(InterpKernelException,f1.fillFromAnalytic,1,"1./(x-0.2)");
3785         pass
3786
3787     def testFieldDoubleOpEqual1(self):
3788         m=MEDCouplingDataForTest.build2DTargetMesh_1();
3789         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
3790         self.assertRaises(InterpKernelException,f1.assign,0.07);
3791         f1.setMesh(m);
3792         f1.assign(0.07);
3793         f1.checkCoherency();
3794         self.assertEqual(1,f1.getNumberOfComponents());
3795         self.assertEqual(5,f1.getNumberOfTuples());
3796         for i in xrange(5):
3797             self.assertAlmostEqual(0.07,f1.getIJ(i,0),16);
3798             pass
3799         f1.assign(0.09);
3800         f1.checkCoherency();
3801         self.assertEqual(1,f1.getNumberOfComponents());
3802         self.assertEqual(5,f1.getNumberOfTuples());
3803         for i in xrange(5):
3804             self.assertAlmostEqual(0.09,f1.getIJ(i,0),16);
3805             pass
3806         #
3807         f1=MEDCouplingFieldDouble.New(ON_NODES,LINEAR_TIME);
3808         f1.setEndTime(4.5,2,3);
3809         f1.setMesh(m);
3810         f1.assign(0.08);
3811         f1.checkCoherency();
3812         self.assertEqual(1,f1.getNumberOfComponents());
3813         self.assertEqual(9,f1.getNumberOfTuples());
3814         for i in xrange(9):
3815             self.assertAlmostEqual(0.08,f1.getIJ(i,0),16);
3816             pass
3817         self.assertEqual(1,f1.getEndArray().getNumberOfComponents());
3818         self.assertEqual(9,f1.getEndArray().getNumberOfTuples());
3819         for i in xrange(9):
3820             self.assertAlmostEqual(0.08,f1.getEndArray().getIJ(i,0),16);
3821             pass
3822         pass
3823
3824     def testAreaBary3D2(self):
3825         coordsForHexa8=[-75.45749305371, 180.95495078401, 39.515472018008,
3826                         -9.755591679144, 23.394927935279, 5.108794294848,
3827                         14.337630157832, 61.705351002702, 160.42422501908,
3828                         -27.273893776752, 167.567731083961, 192.830034145464,
3829                         99.857193154796,264.499264735586,-8.287335493412,
3830                         144.939882761126,156.38626563134,-31.896173894226,
3831                         161.34096835726,182.4654895809,73.832387065572,
3832                         132.680430393685,255.37973247196,96.15235602819];
3833         volHexa8=3258520.29637466;
3834         baryHexa8=[43.925705821778, 155.31893955289, 65.874418109644]
3835         
3836         coordsForPenta6=[-68.199829618726,178.938498373416,62.608505919588,
3837                          8.461744647847,76.653979804423,165.00018874933,
3838                          -27.273893776752,167.567731083961,192.830034145464,
3839                          106.586501038965,262.629609408327,13.124533008813,
3840                          155.465082847275,197.414118382622,78.408350795821,
3841                          132.680430393685,255.37973247196,96.15235602819];
3842         volPenta6=944849.868507338;
3843         baryPenta6=[39.631002313543,182.692711783428,106.98540473964]
3844         
3845         coordsForPyra5=[132.680430393685,255.37973247196,96.15235602819,
3846                         -27.273893776752,167.567731083961,192.830034145464,
3847                         8.461744647847,76.653979804423,165.00018874933,
3848                         155.465082847275,197.414118382622,78.408350795821,
3849                         -68.199829618726,178.938498373416,62.608505919588];
3850         volPyra5=756943.92980254;
3851         baryPyra5=[29.204294116618,172.540129749156,118.01035951483]
3852         mesh=MEDCouplingUMesh.New("Bary3D2",3);
3853         coo=DataArrayDouble.New();
3854         tmp=coordsForHexa8+coordsForPenta6+coordsForPyra5
3855         coo.setValues(tmp,19,3);
3856         mesh.setCoords(coo);
3857         #
3858         tmpConn=[0,1,2,3,4,5,6,7]
3859         mesh.allocateCells(3);
3860         self.assertRaises(InterpKernelException,mesh.insertNextCell,NORM_HEXA8,9,tmpConn[0:8])
3861         mesh.insertNextCell(NORM_HEXA8,tmpConn[0:8])
3862         mesh.insertNextCell(NORM_PENTA6,6,[i+8 for i in tmpConn])
3863         mesh.insertNextCell(NORM_PYRA5,5,[i+14 for i in tmpConn])
3864         mesh.finishInsertingCells();
3865         mesh.checkCoherency();
3866         mesh.mergeNodes(1e-7)
3867         self.assertEqual(12,mesh.getNumberOfNodes());
3868         vols=mesh.getMeasureField(True);
3869         self.assertEqual(3,vols.getNumberOfTuples());
3870         self.assertEqual(1,vols.getNumberOfComponents());
3871         self.assertAlmostEqual(volHexa8,vols.getIJ(0,0),6);
3872         self.assertAlmostEqual(volPenta6,vols.getIJ(1,0),7);
3873         self.assertAlmostEqual(volPyra5,vols.getIJ(2,0),7);
3874         bary=mesh.getBarycenterAndOwner();
3875         self.assertEqual(3,bary.getNumberOfTuples());
3876         self.assertEqual(3,bary.getNumberOfComponents());
3877         self.assertAlmostEqual(baryHexa8[0],bary.getIJ(0,0),11);
3878         self.assertAlmostEqual(baryHexa8[1],bary.getIJ(0,1),11);
3879         self.assertAlmostEqual(baryHexa8[2],bary.getIJ(0,2),11);
3880         self.assertAlmostEqual(baryPenta6[0],bary.getIJ(1,0),11);
3881         self.assertAlmostEqual(baryPenta6[1],bary.getIJ(1,1),11);
3882         self.assertAlmostEqual(baryPenta6[2],bary.getIJ(1,2),11);
3883         self.assertAlmostEqual(baryPyra5[0],bary.getIJ(2,0),11);
3884         self.assertAlmostEqual(baryPyra5[1],bary.getIJ(2,1),11);
3885         self.assertAlmostEqual(baryPyra5[2],bary.getIJ(2,2),11);
3886         pass
3887
3888     def testGetMeasureFieldCMesh1(self):
3889         m=MEDCouplingCMesh.New();
3890         da=DataArrayDouble.New();
3891         discX=[2.3,3.4,5.8,10.2]
3892         discY=[12.3,23.4,45.8]
3893         discZ=[-0.7,1.2,1.25,2.13,2.67]
3894         da.setValues(discX,4,1);
3895         m.setCoordsAt(0,da);
3896         m.checkCoherency();
3897         self.assertEqual(4,m.getNumberOfNodes());
3898         self.assertEqual(3,m.getNumberOfCells());
3899         self.assertEqual(1,m.getSpaceDimension());
3900         f=m.getMeasureField(True);
3901         self.assertEqual(3,f.getNumberOfTuples());
3902         self.assertEqual(1,f.getNumberOfComponents());
3903         expected1=[1.1,2.4,4.4]
3904         for i in xrange(3):
3905             self.assertAlmostEqual(expected1[i],f.getIJ(i,0),12);
3906             pass
3907         coords=m.getCoordinatesAndOwner();
3908         self.assertEqual(4,coords.getNumberOfTuples());
3909         self.assertEqual(1,coords.getNumberOfComponents());
3910         for i in xrange(4):
3911             self.assertAlmostEqual(discX[i],coords.getIJ(i,0),12);
3912             pass
3913         coords=m.getBarycenterAndOwner();
3914         self.assertEqual(3,coords.getNumberOfTuples());
3915         self.assertEqual(1,coords.getNumberOfComponents());
3916         expected1_3=[2.85,4.6,8.]
3917         for i in xrange(3):
3918             self.assertAlmostEqual(expected1_3[i],coords.getIJ(i,0),12);
3919             pass
3920         #
3921         da=DataArrayDouble.New();
3922         da.setValues(discY,3,1);
3923         m.setCoordsAt(1,da);
3924         m.checkCoherency();
3925         self.assertEqual(12,m.getNumberOfNodes());
3926         self.assertEqual(6,m.getNumberOfCells());
3927         self.assertEqual(2,m.getSpaceDimension());
3928         f=m.getMeasureField(True);
3929         self.assertEqual(6,f.getNumberOfTuples());
3930         self.assertEqual(1,f.getNumberOfComponents());
3931         expected2=[12.21,26.64,48.84,24.64,53.76,98.56]
3932         for i in xrange(6):
3933             self.assertAlmostEqual(expected2[i],f.getIJ(i,0),12);
3934             pass
3935         coords=m.getCoordinatesAndOwner();
3936         self.assertEqual(12,coords.getNumberOfTuples());
3937         self.assertEqual(2,coords.getNumberOfComponents());
3938         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]
3939         for i in xrange(24):
3940             self.assertAlmostEqual(expected2_2[i],coords.getIJ(0,i),12);
3941             pass
3942         coords=m.getBarycenterAndOwner();
3943         self.assertEqual(6,coords.getNumberOfTuples());
3944         self.assertEqual(2,coords.getNumberOfComponents());
3945         expected2_3=[2.85,17.85,4.6,17.85,8.,17.85, 2.85,34.6,4.6,34.6,8.,34.6]
3946         for i in xrange(12):
3947             self.assertAlmostEqual(expected2_3[i],coords.getIJ(0,i),12);
3948             pass
3949         #
3950         da=DataArrayDouble.New();
3951         da.setValues(discZ,5,1);
3952         m.setCoordsAt(2,da);
3953         m.checkCoherency();
3954         self.assertEqual(60,m.getNumberOfNodes());
3955         self.assertEqual(24,m.getNumberOfCells());
3956         self.assertEqual(3,m.getSpaceDimension());
3957         f=m.getMeasureField(True);
3958         self.assertEqual(24,f.getNumberOfTuples());
3959         self.assertEqual(1,f.getNumberOfComponents());
3960         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]
3961         for i in xrange(24):
3962             self.assertAlmostEqual(expected3[i],f.getIJ(i,0),12);
3963             pass
3964         coords=m.getCoordinatesAndOwner();
3965         self.assertEqual(60,coords.getNumberOfTuples());
3966         self.assertEqual(3,coords.getNumberOfComponents());
3967         expected3_2=[
3968             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,
3969             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,
3970             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,
3971             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,
3972             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];
3973         for i in xrange(180):
3974             self.assertAlmostEqual(expected3_2[i],coords.getIJ(0,i),12);
3975             pass
3976         coords=m.getBarycenterAndOwner();
3977         self.assertEqual(24,coords.getNumberOfTuples());
3978         self.assertEqual(3,coords.getNumberOfComponents());
3979         expected3_3=[
3980             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,
3981             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,
3982             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,
3983             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];
3984         for i in xrange(72):
3985             self.assertAlmostEqual(expected3_3[i],coords.getIJ(0,i),12);
3986             pass
3987         pass
3988
3989     def testFieldDoubleZipCoords1(self):
3990         m=MEDCouplingDataForTest.build2DTargetMeshMergeNode_1();
3991         f=m.fillFromAnalytic(ON_NODES,2,"x*2.");
3992         f.getArray().setInfoOnComponent(0,"titi");
3993         f.getArray().setInfoOnComponent(1,"tutu");
3994         f.checkCoherency();
3995         self.assertEqual(18,f.getNumberOfTuples());
3996         self.assertEqual(2,f.getNumberOfComponents());
3997         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]
3998         for i in xrange(36):
3999             self.assertAlmostEqual(expected1[i],f.getIJ(0,i),12);
4000             pass
4001         self.assertTrue(f.zipCoords());
4002         f.checkCoherency();
4003         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]
4004         for i in xrange(30):
4005             self.assertAlmostEqual(expected2[i],f.getIJ(0,i),12);
4006             pass
4007         self.assertTrue(not f.zipCoords());
4008         f.checkCoherency();
4009         for i in xrange(30):
4010             self.assertAlmostEqual(expected2[i],f.getIJ(0,i),12);
4011             pass
4012         self.assertTrue(f.getArray().getInfoOnComponent(0)=="titi");
4013         self.assertTrue(f.getArray().getInfoOnComponent(1)=="tutu");
4014         pass
4015
4016     def testFieldDoubleZipConnectivity1(self):
4017         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
4018         m2=MEDCouplingDataForTest.build2DTargetMesh_1();
4019         cells1=[2,3,4]
4020         m3_1=m2.buildPartOfMySelf(cells1,True);
4021         m3=m3_1;
4022         m4=MEDCouplingDataForTest.build2DSourceMesh_1();
4023         m5=MEDCouplingUMesh.MergeUMeshes(m1,m3);
4024         m6=MEDCouplingUMesh.MergeUMeshes(m5,m4);
4025         #
4026         self.assertEqual(10,m6.getNumberOfCells());
4027         self.assertEqual(22,m6.getNumberOfNodes());
4028         arr,areNodesMerged,newNbOfNodes=m6.mergeNodes(1e-13);
4029         self.assertEqual(9,m6.getNumberOfNodes());
4030         f=m6.fillFromAnalytic(ON_CELLS,2,"x");
4031         f2=m6.fillFromAnalytic(ON_NODES,2,"x");
4032         self.assertEqual(10,f.getNumberOfTuples());
4033         self.assertEqual(2,f.getNumberOfComponents());
4034         expected1=[-0.05, -0.05, 0.3666666666666667, 0.3666666666666667, 0.53333333333333321, 0.53333333333333321,
4035                    -0.05, -0.05, 0.45, 0.45, 0.53333333333333321, 0.53333333333333321, -0.05, -0.05, 0.45, 0.45,
4036                    0.36666666666666659, 0.36666666666666659, 0.033333333333333326, 0.033333333333333326];
4037         for i in xrange(20):
4038             self.assertAlmostEqual(expected1[i],f.getIJ(0,i),12);
4039             pass
4040         f.getArray().setInfoOnComponent(0,"titi");
4041         f.getArray().setInfoOnComponent(1,"tutu");
4042         f.checkCoherency();
4043         self.assertTrue(f.zipConnectivity(0));
4044         expected2=[-0.05, -0.05, 0.3666666666666667, 0.3666666666666667, 0.53333333333333321, 0.53333333333333321,
4045                    -0.05, -0.05, 0.45, 0.45, 0.36666666666666659, 0.36666666666666659, 0.033333333333333326, 0.033333333333333326];
4046         self.assertEqual(7,f.getNumberOfTuples());
4047         self.assertEqual(2,f.getNumberOfComponents());
4048         for i in xrange(14):
4049             self.assertAlmostEqual(expected2[i],f.getIJ(0,i),12);
4050             pass
4051         self.assertTrue(f.getArray().getInfoOnComponent(0)=="titi");
4052         self.assertTrue(f.getArray().getInfoOnComponent(1)=="tutu");
4053         self.assertTrue(not f.zipConnectivity(0));
4054         #
4055         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,
4056                    -0.3, -0.3, 0.2, 0.2, 0.7, 0.7];
4057         self.assertEqual(9,f2.getNumberOfTuples());
4058         self.assertEqual(2,f2.getNumberOfComponents());
4059         for i in xrange(18):
4060             self.assertAlmostEqual(expected3[i],f2.getIJ(0,i),12);
4061             pass
4062         self.assertTrue(f2.zipConnectivity(0));
4063         self.assertEqual(9,f2.getNumberOfTuples());
4064         self.assertEqual(2,f2.getNumberOfComponents());
4065         for i in xrange(18):
4066             self.assertAlmostEqual(expected3[i],f2.getIJ(0,i),12);
4067             pass
4068         pass
4069
4070     def testDaDoubleRenumber1(self):
4071         a=DataArrayDouble.New();
4072         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]
4073         a.setValues(arr1,7,2);
4074         a.setInfoOnComponent(0,"toto");
4075         a.setInfoOnComponent(1,"tata");
4076         #
4077         arr2=[3,1,0,6,5,4,2]
4078         b=a.renumber(arr2);
4079         self.assertEqual(7,b.getNumberOfTuples());
4080         self.assertEqual(2,b.getNumberOfComponents());
4081         self.assertTrue(b.getInfoOnComponent(0)=="toto");
4082         self.assertTrue(b.getInfoOnComponent(1)=="tata");
4083         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]
4084         for i in xrange(14):
4085             self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
4086             pass
4087         #
4088         c=DataArrayInt.New();
4089         arr3=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
4090         c.setValues(arr3,7,2);
4091         c.setInfoOnComponent(0,"toto");
4092         c.setInfoOnComponent(1,"tata");
4093         d=c.renumber(arr2);
4094         self.assertEqual(7,d.getNumberOfTuples());
4095         self.assertEqual(2,d.getNumberOfComponents());
4096         self.assertTrue(d.getInfoOnComponent(0)=="toto");
4097         self.assertTrue(d.getInfoOnComponent(1)=="tata");
4098         expected2=[3, 13, 2, 12, 7, 17, 1, 11, 6, 16, 5, 15, 4, 14]
4099         for i in xrange(14):
4100             self.assertEqual(expected2[i],d.getIJ(0,i));
4101             pass
4102         pass
4103
4104     def testDaDoubleRenumberAndReduce1(self):
4105         a=DataArrayDouble.New();
4106         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]
4107         a.setValues(arr1,7,2);
4108         a.setInfoOnComponent(0,"toto");
4109         a.setInfoOnComponent(1,"tata");
4110         #
4111         arr2=[2,-1,1,-1,0,4,3]
4112         b=a.renumberAndReduce(arr2,5);
4113         self.assertEqual(5,b.getNumberOfTuples());
4114         self.assertEqual(2,b.getNumberOfComponents());
4115         self.assertTrue(b.getInfoOnComponent(0)=="toto");
4116         self.assertTrue(b.getInfoOnComponent(1)=="tata");
4117         expected1=[5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1]
4118         for i in xrange(10):
4119             self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
4120             pass
4121         #
4122         c=DataArrayInt.New();
4123         arr3=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
4124         c.setValues(arr3,7,2);
4125         c.setInfoOnComponent(0,"toto");
4126         c.setInfoOnComponent(1,"tata");
4127         d=c.renumberAndReduce(arr2,5);
4128         self.assertEqual(5,d.getNumberOfTuples());
4129         self.assertEqual(2,d.getNumberOfComponents());
4130         self.assertTrue(d.getInfoOnComponent(0)=="toto");
4131         self.assertTrue(d.getInfoOnComponent(1)=="tata");
4132         expected2=[5,15,3,13,1,11,7,17,6,16]
4133         for i in xrange(10):
4134             self.assertEqual(expected2[i],d.getIJ(0,i));
4135             pass
4136         pass
4137
4138     def testDaDoubleRenumberInPlace1(self):
4139         a=DataArrayDouble.New();
4140         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]
4141         a.setValues(arr1,7,2);
4142         #
4143         arr2=[3,1,0,6,5,4,2]
4144         a.renumberInPlace(arr2);
4145         self.assertEqual(7,a.getNumberOfTuples());
4146         self.assertEqual(2,a.getNumberOfComponents());
4147         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]
4148         for i in xrange(14):
4149             self.assertAlmostEqual(expected1[i],a.getIJ(0,i),14);
4150             pass
4151         #
4152         c=DataArrayInt.New();
4153         arr3=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
4154         c.setValues(arr3,7,2);
4155         c.renumberInPlace(arr2);
4156         self.assertEqual(7,c.getNumberOfTuples());
4157         self.assertEqual(2,c.getNumberOfComponents());
4158         expected2=[3, 13, 2, 12, 7, 17, 1, 11, 6, 16, 5, 15, 4, 14]
4159         for i in xrange(14):
4160             self.assertEqual(expected2[i],c.getIJ(0,i));
4161             pass
4162         pass
4163
4164     def testDaDoubleRenumberR1(self):
4165         a=DataArrayDouble.New();
4166         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]
4167         a.setValues(arr1,7,2);
4168         a.setInfoOnComponent(0,"toto");
4169         a.setInfoOnComponent(1,"tata");
4170         #
4171         arr2=[3,1,0,6,5,4,2]
4172         b=a.renumberR(arr2);
4173         self.assertEqual(7,b.getNumberOfTuples());
4174         self.assertEqual(2,b.getNumberOfComponents());
4175         self.assertTrue(b.getInfoOnComponent(0)=="toto");
4176         self.assertTrue(b.getInfoOnComponent(1)=="tata");
4177         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]
4178         for i in xrange(14):
4179             self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
4180             pass
4181         #
4182         c=DataArrayInt.New();
4183         arr3=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
4184         c.setValues(arr3,7,2);
4185         c.setInfoOnComponent(0,"toto");
4186         c.setInfoOnComponent(1,"tata");
4187         d=c.renumberR(arr2);
4188         self.assertEqual(7,d.getNumberOfTuples());
4189         self.assertEqual(2,d.getNumberOfComponents());
4190         self.assertTrue(d.getInfoOnComponent(0)=="toto");
4191         self.assertTrue(d.getInfoOnComponent(1)=="tata");
4192         expected2=[4, 14, 2, 12, 1, 11, 7, 17, 6, 16, 5, 15, 3, 13]
4193         for i in xrange(14):
4194             self.assertEqual(expected2[i],d.getIJ(0,i));
4195             pass
4196         pass
4197
4198     def testDaDoubleRenumberInPlaceR1(self):
4199         a=DataArrayDouble.New();
4200         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]
4201         a.setValues(arr1,7,2);
4202         #
4203         arr2=[3,1,0,6,5,4,2]
4204         a.renumberInPlaceR(arr2);
4205         self.assertEqual(7,a.getNumberOfTuples());
4206         self.assertEqual(2,a.getNumberOfComponents());
4207         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]
4208         for i in xrange(14):
4209             self.assertAlmostEqual(expected1[i],a.getIJ(0,i),14);
4210             pass
4211         #
4212         c=DataArrayInt.New();
4213         arr3=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
4214         c.setValues(arr3,7,2);
4215         c.renumberInPlaceR(arr2);
4216         self.assertEqual(7,c.getNumberOfTuples());
4217         self.assertEqual(2,c.getNumberOfComponents());
4218         expected2=[4, 14, 2, 12, 1, 11, 7, 17, 6, 16, 5, 15, 3, 13]
4219         for i in xrange(14):
4220             self.assertEqual(expected2[i],c.getIJ(0,i));
4221             pass
4222         pass
4223
4224     def testDaDoubleSelectByTupleId1(self):
4225         a=DataArrayDouble.New();
4226         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]
4227         a.setValues(arr1,7,2);
4228         a.setInfoOnComponent(0,"toto");
4229         a.setInfoOnComponent(1,"tata");
4230         #
4231         arr2=[4,2,0,6,5]
4232         b=a.selectByTupleId(arr2);
4233         self.assertEqual(5,b.getNumberOfTuples());
4234         self.assertEqual(2,b.getNumberOfComponents());
4235         self.assertTrue(b.getInfoOnComponent(0)=="toto");
4236         self.assertTrue(b.getInfoOnComponent(1)=="tata");
4237         expected1=[5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1]
4238         for i in xrange(10):
4239             self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
4240             pass
4241         #
4242         c=DataArrayInt.New();
4243         arr3=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
4244         c.setValues(arr3,7,2);
4245         c.setInfoOnComponent(0,"toto");
4246         c.setInfoOnComponent(1,"tata");
4247         d=c.selectByTupleId(arr2);
4248         self.assertEqual(5,d.getNumberOfTuples());
4249         self.assertEqual(2,d.getNumberOfComponents());
4250         self.assertTrue(d.getInfoOnComponent(0)=="toto");
4251         self.assertTrue(d.getInfoOnComponent(1)=="tata");
4252         expected2=[5,15,3,13,1,11,7,17,6,16]
4253         for i in xrange(10):
4254             self.assertEqual(expected2[i],d.getIJ(0,i));
4255             pass
4256         pass
4257
4258     def testDaDoubleGetMinMaxValues1(self):
4259         a=DataArrayDouble.New();
4260         arr1=[2.34,4.56,-6.77,4.55,4.56,2.24,2.34,1.02,4.56]
4261         a.setValues(arr1,9,1);
4262         m,where=a.getMaxValue();
4263         self.assertEqual(1,where);
4264         self.assertAlmostEqual(4.56,m,12);
4265         m,ws=a.getMaxValue2();
4266         self.assertAlmostEqual(4.56,m,12);
4267         self.assertEqual(3,ws.getNumberOfTuples());
4268         self.assertEqual(1,ws.getNumberOfComponents());
4269         expected1=[1,4,8]
4270         for i in xrange(3):
4271             self.assertEqual(expected1[i],ws.getIJ(i,0));
4272             pass
4273         a=DataArrayDouble.New();
4274         arr2=[-2.34,-4.56,6.77,-4.55,-4.56,-2.24,-2.34,-1.02,-4.56]
4275         a.setValues(arr2,9,1);
4276         m,where=a.getMinValue();
4277         self.assertEqual(1,where);
4278         self.assertAlmostEqual(-4.56,m,12);
4279         m,ws=a.getMinValue2();
4280         self.assertAlmostEqual(-4.56,m,12);
4281         self.assertEqual(3,ws.getNumberOfTuples());
4282         self.assertEqual(1,ws.getNumberOfComponents());
4283         for i in xrange(3):
4284             self.assertEqual(expected1[i],ws.getIJ(i,0));
4285             pass
4286         pass
4287
4288     def testFieldDoubleGetMinMaxValues2(self):
4289         m2,m1=MEDCouplingDataForTest.build3DExtrudedUMesh_1();
4290         self.assertEqual(18,m2.getNumberOfCells());
4291         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]
4292         f=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
4293         a=DataArrayDouble.New();
4294         a.setValues(arr1,18,1);
4295         f.setArray(a);
4296         f.setMesh(m2);
4297         #
4298         f.checkCoherency();
4299         m=f.getMaxValue();
4300         self.assertAlmostEqual(8.71,m,12);
4301         m,ws=f.getMaxValue2();
4302         self.assertAlmostEqual(8.71,m,12);
4303         self.assertEqual(4,ws.getNumberOfTuples());
4304         self.assertEqual(1,ws.getNumberOfComponents());
4305         expected1=[0,3,7,17]
4306         for i in xrange(4):
4307             self.assertEqual(expected1[i],ws.getIJ(i,0));
4308             pass
4309         #
4310         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]
4311         a.setValues(arr2,18,1);
4312         f.checkCoherency();
4313         m=f.getMinValue();
4314         self.assertAlmostEqual(-8.71,m,12);
4315         m,ws=f.getMinValue2();
4316         self.assertAlmostEqual(-8.71,m,12);
4317         self.assertEqual(4,ws.getNumberOfTuples());
4318         self.assertEqual(1,ws.getNumberOfComponents());
4319         for i in xrange(4):
4320             self.assertEqual(expected1[i],ws.getIJ(i,0));
4321             pass
4322         pass
4323
4324     def testBuildUnstructuredCMesh1(self):
4325         m=MEDCouplingCMesh.New();
4326         da=DataArrayDouble.New();
4327         discX=[2.3,3.4,5.8,10.2]
4328         discY=[12.3,23.4,45.8]
4329         discZ=[-0.7,1.2,1.25,2.13,2.67]
4330         da.setValues(discX,4,1);
4331         m.setCoordsAt(0,da);
4332         m.checkCoherency();
4333         self.assertEqual(0,m.getCellContainingPoint([2.4],1e-12));
4334         self.assertEqual(1,m.getCellContainingPoint([3.7],1e-12));
4335         self.assertEqual(2,m.getCellContainingPoint([5.9],1e-12));
4336         self.assertEqual(-1,m.getCellContainingPoint([10.3],1e-12));
4337         self.assertEqual(-1,m.getCellContainingPoint([1.3],1e-12));
4338         #
4339         m2=m.buildUnstructured();
4340         m2.checkCoherency();
4341         f1=m.getMeasureField(False);
4342         f2=m2.getMeasureField(False);
4343         self.assertTrue(isinstance(f1.getMesh(),MEDCouplingCMesh))
4344         self.assertEqual(f1.getNumberOfTuples(),3);
4345         self.assertEqual(f2.getNumberOfTuples(),3);
4346         self.assertEqual(1,m2.getMeshDimension());
4347         self.assertEqual(1,m2.getSpaceDimension());
4348         for i in xrange(3):
4349             self.assertAlmostEqual(f1.getIJ(i,0),f2.getIJ(i,0),10);
4350             pass
4351         da=DataArrayDouble.New();
4352         da.setValues(discY,3,1);
4353         m.setCoordsAt(1,da);
4354         #
4355         m2=m.buildUnstructured();
4356         m2.checkCoherency();
4357         f1=m.getMeasureField(False);
4358         f2=m2.getMeasureField(False);
4359         self.assertEqual(f1.getNumberOfTuples(),6);
4360         self.assertEqual(f2.getNumberOfTuples(),6);
4361         self.assertEqual(2,m2.getMeshDimension());
4362         self.assertEqual(2,m2.getSpaceDimension());
4363         for i in xrange(6):
4364             self.assertAlmostEqual(f1.getIJ(i,0),f2.getIJ(i,0),10);
4365             pass
4366         #
4367         da=DataArrayDouble.New();
4368         da.setValues(discZ,5,1);
4369         m.setCoordsAt(2,da);
4370         m2=m.buildUnstructured();
4371         m2.checkCoherency();
4372         f1=m.getMeasureField(False);
4373         f2=m2.getMeasureField(False);
4374         self.assertEqual(f1.getNumberOfTuples(),24);
4375         self.assertEqual(f2.getNumberOfTuples(),24);
4376         self.assertEqual(3,m2.getMeshDimension());
4377         self.assertEqual(3,m2.getSpaceDimension());
4378         for i in xrange(24):
4379             self.assertAlmostEqual(f1.getIJ(i,0),f2.getIJ(i,0),10);
4380             pass
4381         #
4382         pos1=[5.,30.,2.]
4383         self.assertEqual(16,m.getCellContainingPoint(pos1,1e-12));
4384         #
4385         elems=m2.getCellsInBoundingBox([3.5,6.,12.2,25.,0.,1.5],1e-7)
4386         self.assertEqual([1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17],elems.getValues())
4387         #
4388         pt=[2.4,12.7,-3.4]
4389         m.scale(pt,3.7);
4390         m3=m.buildUnstructured();
4391         m2.scale(pt,3.7);
4392         self.assertTrue(m3.isEqual(m2,1e-12));
4393         pass
4394
4395     def testDataArrayIntInvertO2NNO21(self):
4396         arr1=[2,0,4,1,5,3]
4397         da=DataArrayInt.New();
4398         da.setValues(arr1,6,1);
4399         da2=da.invertArrayO2N2N2O(6);
4400         self.assertEqual(6,da2.getNumberOfTuples());
4401         self.assertEqual(1,da2.getNumberOfComponents());
4402         expected1=[1,3,0,5,2,4]
4403         for i in xrange(6):
4404             self.assertEqual(expected1[i],da2.getIJ(i,0));
4405             pass
4406         da3=da2.invertArrayN2O2O2N(6);
4407         for i in xrange(6):
4408             self.assertEqual(arr1[i],da3.getIJ(i,0));
4409             pass
4410         #
4411         arr2=[3,-1,5,4,-1,0,-1,1,2,-1]
4412         da=DataArrayInt.New();
4413         da.setValues(arr2,10,1);
4414         da2=da.invertArrayO2N2N2O(6);
4415         self.assertEqual(6,da2.getNumberOfTuples());
4416         self.assertEqual(1,da2.getNumberOfComponents());
4417         expected2=[5,7,8,0,3,2]
4418         for i in xrange(6):
4419             self.assertEqual(expected2[i],da2.getIJ(i,0));
4420             pass
4421         da3=da2.invertArrayN2O2O2N(10);
4422         for i in xrange(10):
4423             self.assertEqual(arr2[i],da3.getIJ(i,0));
4424             pass
4425         pass
4426     
4427     def testKeepSetSelectedComponent1(self):
4428         arr1=[1.,2.,3.,4., 11.,12.,13.,14., 21.,22.,23.,24., 31.,32.,33.,34., 41.,42.,43.,44.]
4429         a1=DataArrayDouble.New();
4430         a1.setValues(arr1,5,4);
4431         expp=[21.,22.,23.,24.]
4432         self.assertEqual(4,len(a1.getTuple(2)));
4433         for i in xrange(4):
4434             self.assertAlmostEqual(expp[i],a1.getTuple(2)[i],12)
4435             pass
4436         a1.setInfoOnComponent(0,"aaaa");
4437         a1.setInfoOnComponent(1,"bbbb");
4438         a1.setInfoOnComponent(2,"cccc");
4439         a1.setInfoOnComponent(3,"dddd");
4440         arr2V=[1,2,1,2,0,0]
4441         a2=a1.keepSelectedComponents(arr2V);
4442         self.assertEqual(6,a2.getNumberOfComponents());
4443         self.assertEqual(5,a2.getNumberOfTuples());
4444         self.assertTrue(a2.getInfoOnComponent(0)=="bbbb");
4445         self.assertTrue(a2.getInfoOnComponent(1)=="cccc");
4446         self.assertTrue(a2.getInfoOnComponent(2)=="bbbb");
4447         self.assertTrue(a2.getInfoOnComponent(3)=="cccc");
4448         self.assertTrue(a2.getInfoOnComponent(4)=="aaaa");
4449         self.assertTrue(a2.getInfoOnComponent(5)=="aaaa");
4450         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.]
4451         for i in xrange(30):
4452             self.assertAlmostEqual(expected1[i],a2.getIJ(0,i),14);
4453             pass
4454         a3=a1.convertToIntArr();
4455         self.assertEqual([21,22,23,24],a3.getTuple(2))
4456         a4=a3.keepSelectedComponents(arr2V);
4457         self.assertEqual(6,a4.getNumberOfComponents());
4458         self.assertEqual(5,a4.getNumberOfTuples());
4459         self.assertTrue(a4.getInfoOnComponent(0)=="bbbb");
4460         self.assertTrue(a4.getInfoOnComponent(1)=="cccc");
4461         self.assertTrue(a4.getInfoOnComponent(2)=="bbbb");
4462         self.assertTrue(a4.getInfoOnComponent(3)=="cccc");
4463         self.assertTrue(a4.getInfoOnComponent(4)=="aaaa");
4464         self.assertTrue(a4.getInfoOnComponent(5)=="aaaa");
4465         for i in xrange(30):
4466             self.assertEqual(int(expected1[i]),a4.getIJ(0,i));
4467             pass
4468         # setSelectedComponents
4469         arr3V=[3,2]
4470         a5=a1.keepSelectedComponents(arr3V);
4471         a5.setInfoOnComponent(0,"eeee");
4472         a5.setInfoOnComponent(1,"ffff");
4473         arr4V=[1,2]
4474         a2.setSelectedComponents(a5,arr4V);
4475         self.assertEqual(6,a2.getNumberOfComponents());
4476         self.assertEqual(5,a2.getNumberOfTuples());
4477         self.assertTrue(a2.getInfoOnComponent(0)=="bbbb");
4478         self.assertTrue(a2.getInfoOnComponent(1)=="eeee");
4479         self.assertTrue(a2.getInfoOnComponent(2)=="ffff");
4480         self.assertTrue(a2.getInfoOnComponent(3)=="cccc");
4481         self.assertTrue(a2.getInfoOnComponent(4)=="aaaa");
4482         self.assertTrue(a2.getInfoOnComponent(5)=="aaaa");
4483         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.]
4484         for i in xrange(30):
4485             self.assertAlmostEqual(expected2[i],a2.getIJ(0,i),14);
4486             pass
4487         a6=a5.convertToIntArr();
4488         a6.setInfoOnComponent(0,"eeee");
4489         a6.setInfoOnComponent(1,"ffff");
4490         a4.setSelectedComponents(a6,arr4V);
4491         self.assertEqual(6,a4.getNumberOfComponents());
4492         self.assertEqual(5,a4.getNumberOfTuples());
4493         self.assertTrue(a4.getInfoOnComponent(0)=="bbbb");
4494         self.assertTrue(a4.getInfoOnComponent(1)=="eeee");
4495         self.assertTrue(a4.getInfoOnComponent(2)=="ffff");
4496         self.assertTrue(a4.getInfoOnComponent(3)=="cccc");
4497         self.assertTrue(a4.getInfoOnComponent(4)=="aaaa");
4498         self.assertTrue(a4.getInfoOnComponent(5)=="aaaa");
4499         for i in xrange(30):
4500             self.assertEqual(int(expected2[i]),a4.getIJ(0,i));
4501             pass
4502         # test of throw
4503         arr5V=[2,3,6]
4504         arr6V=[2,7,5]
4505         arr7V=[2,1,4,6]
4506         self.assertRaises(InterpKernelException,a2.keepSelectedComponents,arr5V);
4507         self.assertRaises(InterpKernelException,a2.keepSelectedComponents,arr6V);
4508         self.assertRaises(InterpKernelException,a2.setSelectedComponents,a1,arr7V);
4509         arr7V=arr7V[0:3]
4510         self.assertRaises(InterpKernelException,a2.setSelectedComponents,a1,arr7V);
4511         #
4512         pass
4513
4514     def testKeepSetSelectedComponent2(self):
4515         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
4516         arr1=[1.,2.,3.,4., 11.,12.,13.,14., 21.,22.,23.,24., 31.,32.,33.,34., 41.,42.,43.,44.]
4517         a1=DataArrayDouble.New();
4518         a1.setValues(arr1,5,4);
4519         a1.setInfoOnComponent(0,"aaaa");
4520         a1.setInfoOnComponent(1,"bbbb");
4521         a1.setInfoOnComponent(2,"cccc");
4522         a1.setInfoOnComponent(3,"dddd");
4523         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
4524         f1.setTime(2.3,4,5);
4525         f1.setMesh(m1);
4526         f1.setName("f1");
4527         f1.setArray(a1);
4528         f1.checkCoherency();
4529         #
4530         arr2V=[1,2,1,2,0,0]
4531         f2=f1.keepSelectedComponents(arr2V);
4532         self.assertTrue(f2.getTimeDiscretization()==ONE_TIME);
4533         t,dt,it=f2.getTime()
4534         self.assertAlmostEqual(2.3,t,13);
4535         self.assertEqual(4,dt);
4536         self.assertEqual(5,it);
4537         f2.checkCoherency();
4538         self.assertEqual(6,f2.getNumberOfComponents());
4539         self.assertEqual(5,f2.getNumberOfTuples());
4540         self.assertTrue(f2.getArray().getInfoOnComponent(0)=="bbbb");
4541         self.assertTrue(f2.getArray().getInfoOnComponent(1)=="cccc");
4542         self.assertTrue(f2.getArray().getInfoOnComponent(2)=="bbbb");
4543         self.assertTrue(f2.getArray().getInfoOnComponent(3)=="cccc");
4544         self.assertTrue(f2.getArray().getInfoOnComponent(4)=="aaaa");
4545         self.assertTrue(f2.getArray().getInfoOnComponent(5)=="aaaa");
4546         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.]
4547         for i in xrange(30):
4548             self.assertAlmostEqual(expected1[i],f2.getIJ(0,i),14);
4549             pass
4550         #setSelectedComponents
4551         arr3V=[3,2]
4552         f5=f1.keepSelectedComponents(arr3V);
4553         f5.setTime(6.7,8,9);
4554         f5.getArray().setInfoOnComponent(0,"eeee");
4555         f5.getArray().setInfoOnComponent(1,"ffff");
4556         f5.checkCoherency();
4557         arr4V=[1,2]
4558         f2.setSelectedComponents(f5,arr4V);
4559         self.assertEqual(6,f2.getNumberOfComponents());
4560         self.assertEqual(5,f2.getNumberOfTuples());
4561         f2.checkCoherency();
4562         t,dt,it=f2.getTime()
4563         self.assertAlmostEqual(2.3,t,13);
4564         self.assertEqual(4,dt);
4565         self.assertEqual(5,it);
4566         self.assertTrue(f2.getArray().getInfoOnComponent(0)=="bbbb");
4567         self.assertTrue(f2.getArray().getInfoOnComponent(1)=="eeee");
4568         self.assertTrue(f2.getArray().getInfoOnComponent(2)=="ffff");
4569         self.assertTrue(f2.getArray().getInfoOnComponent(3)=="cccc");
4570         self.assertTrue(f2.getArray().getInfoOnComponent(4)=="aaaa");
4571         self.assertTrue(f2.getArray().getInfoOnComponent(5)=="aaaa");
4572         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.]
4573         for i in xrange(30):
4574             self.assertAlmostEqual(expected2[i],f2.getIJ(0,i),14);
4575             pass
4576         #
4577         pass
4578     
4579     def testElementaryDAThrowAndSpecialCases(self):
4580         da=DataArrayInt.New();
4581         self.assertRaises(InterpKernelException, da.checkAllocated);
4582         self.assertRaises(InterpKernelException, da.fillWithValue, 1);
4583         self.assertRaises(InterpKernelException, da.iota, 1);
4584         da.alloc(7,1);
4585         da.fillWithValue(11); #11,11,11,11...
4586         da.iota(10); #10,11,12,13...
4587         
4588         db=DataArrayInt.New();
4589         db.alloc(7,2);
4590         
4591         dbl2=DataArrayDouble.New();
4592         dbl2.alloc(7,2);
4593         self.assertRaises(InterpKernelException, dbl2.isUniform, 10., 1e-15);
4594         self.assertRaises(InterpKernelException, dbl2.sort);
4595         self.assertRaises(InterpKernelException, dbl2.iota, 10.);
4596         
4597         dbl=DataArrayDouble.New();
4598         #DataArrayDouble not allocated yet
4599         self.assertRaises(InterpKernelException, dbl.iota, 10.);
4600         self.assertRaises(InterpKernelException, dbl.isUniform, 10., 1e-15);
4601         self.assertRaises(InterpKernelException, dbl.sort);
4602         self.assertRaises(InterpKernelException, dbl.fromNoInterlace);
4603         self.assertRaises(InterpKernelException, dbl.toNoInterlace);
4604         
4605         dbl.alloc(7,1);
4606         dbl.iota(10.);
4607         self.assertTrue(not dbl.isUniform(10.,1e-15));
4608         dbl.sort();
4609         self.assertTrue(dbl.isMonotonic(True, .99));
4610         self.assertTrue(dbl.isMonotonic(True, -.99));
4611         self.assertTrue(not dbl.isMonotonic(True, 1.1));
4612         self.assertTrue(not dbl.isMonotonic(True, -1.1));
4613         dbl.reverse();
4614         self.assertTrue(dbl.isMonotonic(False, .99));
4615         self.assertTrue(not dbl.isMonotonic(False, 1.1));
4616         self.assertTrue(not dbl.isMonotonic(False, -1.1));
4617         
4618         dc=DataArrayInt.New();
4619         dc.alloc(14,1);
4620         
4621         dd=DataArrayDouble.New();
4622         self.assertRaises(InterpKernelException, dd.checkAllocated);
4623         self.assertRaises(InterpKernelException, dd.fillWithValue, 1.);
4624         self.assertRaises(InterpKernelException, dd.iota, 1.);
4625         self.assertTrue(not ((dd.repr().find("No data"))==-1));
4626         
4627         dd.alloc(0,1); #Allocated but nbOfElements==0!
4628         self.assertTrue(not ((dd.repr().find("Number of tuples : 0"))==-1));
4629         self.assertTrue(not ((dd.repr().find("Empty Data"))==-1));
4630         dd.fillWithValue(11); #?!...ok
4631         dd.iota(10); #?!...ok
4632         self.assertTrue(dd.isMonotonic(True, 1.));  #nothing is monotonic
4633         self.assertTrue(dd.isMonotonic(False, 1.));
4634         
4635         self.assertRaises(InterpKernelException, db.copyStringInfoFrom, da);
4636         self.assertRaises(InterpKernelException, db.copyStringInfoFrom, da);
4637         cIds=[2,2]
4638         self.assertRaises(InterpKernelException, da.copyPartOfStringInfoFrom, db, cIds);
4639         cIds[0]=1;
4640         cIds[0]=-1;
4641         self.assertRaises(InterpKernelException, da.copyPartOfStringInfoFrom, db, cIds);
4642         
4643         info=["infoOfOneComponent"]*2;
4644         self.assertRaises(InterpKernelException, da.setInfoOnComponents, info);
4645         self.assertRaises(InterpKernelException, da.setInfoOnComponent, 1, info[0]);
4646         db.setInfoOnComponents(info);
4647         
4648         self.assertRaises(InterpKernelException, da.getInfoOnComponent, -1);
4649         self.assertRaises(InterpKernelException, da.getInfoOnComponent, 2);
4650         self.assertTrue(db.getInfoOnComponent(1)==db.getInfoOnComponent(0));
4651         self.assertRaises(InterpKernelException, db.getVarOnComponent, -1);
4652         self.assertRaises(InterpKernelException, db.getVarOnComponent, 2);
4653         self.assertRaises(InterpKernelException, db.getUnitOnComponent, -1);
4654         self.assertRaises(InterpKernelException, db.getUnitOnComponent, 2);
4655         
4656         self.assertTrue(da.GetVarNameFromInfo("varname unit ")=="varname unit ");
4657         self.assertTrue(da.GetVarNameFromInfo("varname]unit[")=="varname]unit[");
4658         self.assertTrue(da.GetVarNameFromInfo("[unit]")=="");
4659         self.assertTrue(da.GetVarNameFromInfo("varname [unit]")=="varname");
4660         
4661         self.assertTrue(da.GetUnitFromInfo("varname unit ")=="");
4662         self.assertTrue(da.GetUnitFromInfo("varname]unit[")=="");
4663         self.assertTrue(da.GetUnitFromInfo("[unit]")=="unit");
4664         self.assertTrue(da.GetUnitFromInfo("varname [unit]")=="unit");
4665         
4666         self.assertRaises(InterpKernelException, da.checkNbOfTuplesAndComp, db, "theMessageInThrow");
4667         self.assertRaises(InterpKernelException, da.checkNbOfTuplesAndComp, dc, "theMessageInThrow");
4668         self.assertRaises(InterpKernelException, db.checkNbOfTuplesAndComp, dc, "theMessageInThrow");
4669         
4670         self.assertRaises(InterpKernelException, da.checkNbOfTuplesAndComp, 7, 2, "theMessageInThrow");
4671         da.checkNbOfTuplesAndComp(7,1,"theMessageInThrow");
4672         
4673         self.assertRaises(InterpKernelException, db.checkNbOfElems, 7*2+1, "theMessageInThrow");
4674         db.checkNbOfElems(7*2,"theMessageInThrow");
4675         
4676         self.assertRaises(InterpKernelException, db.GetNumberOfItemGivenBES, 10, 9, 1, "theMessageInThrow");
4677         self.assertRaises(InterpKernelException, db.GetNumberOfItemGivenBES, 0, 1, -1, "theMessageInThrow");
4678         self.assertEqual(10,db.GetNumberOfItemGivenBES(0,10,1,"theMessageInThrow"));
4679         self.assertEqual(5,db.GetNumberOfItemGivenBES(0,10,2,"theMessageInThrow"));
4680         self.assertEqual(6,db.GetNumberOfItemGivenBES(0,11,2,"theMessageInThrow"));
4681         
4682         self.assertTrue(not ((da.repr().find("Number of components : 1"))==-1));
4683         self.assertTrue(not ((dd.repr().find("Number of components : 1"))==-1));
4684         self.assertTrue(not ((dbl.repr().find("Number of components : 1"))==-1));
4685         
4686         self.assertTrue(not ((da.reprZip().find("Number of components : 1"))==-1));
4687         self.assertTrue(not ((dd.reprZip().find("Number of components : 1"))==-1));
4688         self.assertTrue(not ((dbl.reprZip().find("Number of components : 1"))==-1));
4689         
4690         self.assertRaises(InterpKernelException, dbl.selectByTupleId2, 0, 1, -1);
4691         self.assertRaises(InterpKernelException, dbl.substr, -1, 1);
4692         self.assertRaises(InterpKernelException, dbl.substr, 8, 1);
4693         self.assertRaises(InterpKernelException, dbl.substr, 0, 8);
4694         self.assertRaises(InterpKernelException, dbl.meldWith, dd);
4695         
4696         self.assertRaises(InterpKernelException, dbl.setPartOfValuesAdv, dbl2, da); #dbl dbl2 not have the same number of components
4697         self.assertRaises(InterpKernelException, dbl.setPartOfValuesAdv, dd, da);  #da tuple selector DataArrayInt instance not have exactly 2 components
4698         
4699         dbl3=DataArrayDouble.New();
4700         dbl3.alloc(6,2);
4701         dbl3.fillWithValue(11.);
4702         #bad number of components
4703         self.assertRaises(InterpKernelException, dbl3.getMaxValue);
4704         self.assertRaises(InterpKernelException, dd.getMaxValue);
4705         self.assertRaises(InterpKernelException, dbl3.getMinValue);
4706         self.assertRaises(InterpKernelException, dd.getMinValue);
4707         self.assertRaises(InterpKernelException, dbl3.getAverageValue);
4708         self.assertRaises(InterpKernelException, dd.getAverageValue);
4709         self.assertRaises(InterpKernelException, dd.accumulate, 100);
4710         self.assertRaises(InterpKernelException, dbl.fromPolarToCart);
4711         self.assertRaises(InterpKernelException, dbl3.fromCylToCart);
4712         self.assertRaises(InterpKernelException, dbl3.fromSpherToCart);
4713         self.assertRaises(InterpKernelException, dbl3.doublyContractedProduct);
4714         self.assertRaises(InterpKernelException, dbl3.determinant);
4715         self.assertRaises(InterpKernelException, dbl3.eigenValues);
4716         self.assertRaises(InterpKernelException, dbl3.eigenVectors);
4717         self.assertRaises(InterpKernelException, dbl3.inverse);
4718         self.assertRaises(InterpKernelException, dbl3.trace);
4719         self.assertRaises(InterpKernelException, dbl3.deviator);
4720         
4721         dbl3.setIJ(5,1,12.);
4722         self.assertTrue(dbl3.getMaxValueInArray()==12.);
4723         self.assertTrue(dbl3.getMinValueInArray()==11.);
4724         
4725         db.fillWithValue(100); #bad Ids
4726         self.assertRaises(InterpKernelException, dbl3.setPartOfValuesAdv, dbl2, db);
4727         db.fillWithValue(-1); #bad Ids
4728         self.assertRaises(InterpKernelException, dbl3.setPartOfValuesAdv, dbl2, db);
4729         db.fillWithValue(6); #bad Ids for dbl3
4730         self.assertRaises(InterpKernelException, dbl3.setPartOfValuesAdv, dbl2, db);
4731         
4732         dbl3.checkNoNullValues();
4733         dbl3.setIJ(5,0,0.);
4734         self.assertRaises(InterpKernelException, dbl3.checkNoNullValues);
4735         self.assertRaises(InterpKernelException, dbl3.applyInv, 1.);  #div by zero
4736         self.assertRaises(InterpKernelException, dbl2.getIdsInRange, 1., 2.);
4737         a=[]
4738         self.assertRaises(InterpKernelException, DataArrayDouble_Aggregate, a);
4739         self.assertRaises(InterpKernelException, DataArrayDouble_Meld, a);
4740         
4741         a=[dbl2,dbl]; #Nb of components mismatch
4742         self.assertRaises(InterpKernelException, DataArrayDouble_Aggregate, a);
4743         
4744         self.assertRaises(InterpKernelException, DataArrayDouble_Dot, dbl2, dbl);
4745         
4746         self.assertRaises(InterpKernelException, DataArrayDouble_CrossProduct, dbl2, dbl); #Nb of components mismatch
4747         self.assertRaises(InterpKernelException, DataArrayDouble_CrossProduct, dbl2, dbl2); #Nb of components must be equal to 3
4748         dbl4=DataArrayDouble.New();
4749         dbl4.alloc(6,3);
4750         dbl5=DataArrayDouble.New();
4751         dbl5.alloc(7,3);
4752         self.assertRaises(InterpKernelException, DataArrayDouble_CrossProduct, dbl4, dbl5); #Nb of tuples mismatch
4753         
4754         a[0]=dbl4; #Nb of tuple mismatch
4755         a[1]=dbl5; #Nb of tuple mismatch
4756         self.assertRaises(InterpKernelException, DataArrayDouble_Meld, a);
4757         self.assertRaises(InterpKernelException, DataArrayDouble_Dot, dbl4, dbl5);
4758         pass
4759
4760     def testDAIGetIdsEqual1(self):
4761         tab1=[5,-2,-4,-2,3,2,-2];
4762         da=DataArrayInt.New();
4763         da.setValues(tab1,7,1);
4764         da2=da.getIdsEqual(-2);
4765         self.assertEqual(3,da2.getNumberOfTuples());
4766         self.assertEqual(1,da2.getNumberOfComponents());
4767         expected1=[1,3,6];
4768         self.assertEqual(expected1,da2.getValues());
4769         pass
4770
4771     def testDAIGetIdsEqualList1(self):
4772         tab1=[5,-2,-4,-2,3,2,-2];
4773         da=DataArrayInt.New();
4774         da.setValues(tab1,7,1);
4775         da2=da.getIdsEqualList([3,-2,0]);
4776         self.assertEqual(4,da2.getNumberOfTuples());
4777         self.assertEqual(1,da2.getNumberOfComponents());
4778         expected1=[1,3,4,6];
4779         self.assertEqual(expected1,da2.getValues());
4780         pass
4781
4782     def testDAFromNoInterlace1(self):
4783         tab1=[1,11,21,31,41,2,12,22,32,42,3,13,23,33,43]
4784         da=DataArrayInt.New();
4785         da.setValues(tab1,5,3);
4786         da2=da.fromNoInterlace();
4787         expected1=[1,2,3,11,12,13,21,22,23,31,32,33,41,42,43]
4788         self.assertEqual(5,da2.getNumberOfTuples());
4789         self.assertEqual(3,da2.getNumberOfComponents());# it's not a bug. Avoid to have 1 million components !
4790         self.assertEqual(expected1,da2.getValues());
4791         da3=da.convertToDblArr();
4792         da4=da3.fromNoInterlace();
4793         self.assertEqual(5,da4.getNumberOfTuples());
4794         self.assertEqual(3,da4.getNumberOfComponents());# it's not a bug. Avoid to have 1 million components !
4795         for i in xrange(15):
4796             self.assertAlmostEqual(expected1[i],da4.getIJ(0,i),14);
4797             pass
4798         pass
4799     
4800     def testDAToNoInterlace1(self):
4801         tab1=[1,2,3,11,12,13,21,22,23,31,32,33,41,42,43]
4802         da=DataArrayInt.New();
4803         da.setValues(tab1,5,3);
4804         da2=da.toNoInterlace();
4805         expected1=[1,11,21,31,41,2,12,22,32,42,3,13,23,33,43]
4806         self.assertEqual(5,da2.getNumberOfTuples());
4807         self.assertEqual(3,da2.getNumberOfComponents());# it's not a bug. Avoid to have 1 million components !
4808         self.assertEqual(expected1,da2.getValues());
4809         da3=da.convertToDblArr();
4810         da4=da3.toNoInterlace();
4811         self.assertEqual(5,da4.getNumberOfTuples());
4812         self.assertEqual(3,da4.getNumberOfComponents());# it's not a bug. Avoid to have 1 million components !
4813         for i in xrange(15):
4814             self.assertAlmostEqual(expected1[i],da4.getIJ(0,i),14);
4815             pass
4816         pass
4817     
4818     def testDAIsUniform1(self):
4819         tab1=[1,1,1,1,1]
4820         da=DataArrayInt.New();
4821         da.setValues(tab1,5,1);
4822         self.assertTrue(da.isUniform(1));
4823         da.setIJ(2,0,2);
4824         self.assertTrue(not da.isUniform(1));
4825         da.setIJ(2,0,1);
4826         self.assertTrue(da.isUniform(1));
4827         da2=da.convertToDblArr();
4828         self.assertTrue(da2.isUniform(1.,1.e-12));
4829         da2.setIJ(1,0,1.+1.e-13);
4830         self.assertTrue(da2.isUniform(1.,1.e-12));
4831         da2.setIJ(1,0,1.+1.e-11);
4832         self.assertTrue(not da2.isUniform(1.,1.e-12));
4833         pass
4834     
4835     def testDADFromPolarToCart1(self):
4836         tab1=[2.,0.2,2.5,0.7]
4837         da=DataArrayDouble.New();
4838         da.setValues(tab1,2,2);
4839         da2=da.fromPolarToCart();
4840         expected1=[1.9601331556824833,0.39733866159012243, 1.9121054682112213,1.6105442180942275]
4841         for i in xrange(4):
4842             self.assertAlmostEqual(expected1[i],da2.getIJ(0,i),13);
4843             pass
4844         pass
4845     
4846     def testDADFromCylToCart1(self):
4847         tab1=[2.,0.2,4.,2.5,0.7,9.]
4848         da=DataArrayDouble.New();
4849         da.setValues(tab1,2,3);
4850         da2=da.fromCylToCart();
4851         expected1=[1.9601331556824833,0.39733866159012243,4., 1.9121054682112213,1.6105442180942275,9.]
4852         for i in xrange(6):
4853             self.assertAlmostEqual(expected1[i],da2.getIJ(0,i),13);
4854             pass
4855         pass
4856     
4857     def testDADFromSpherToCart1(self):
4858         tab1=[2.,0.2,0.3,2.5,0.7,0.8]
4859         da=DataArrayDouble.New();
4860         da.setValues(tab1,2,3);
4861         da2=da.fromSpherToCart();
4862         expected1=[0.37959212195737485,0.11742160338765303,1.9601331556824833, 1.1220769624465328,1.1553337045129035,1.9121054682112213]
4863         for i in xrange(6):
4864             self.assertAlmostEqual(expected1[i],da2.getIJ(0,i),13);
4865             pass
4866         pass
4867
4868     def testUnPolyze1(self):
4869         elts=[0,1,2,3,4,5,6,7]
4870         eltsV=elts;
4871         mesh=MEDCouplingDataForTest.build3DTargetMesh_1();
4872         mesh.convertToPolyTypes(eltsV);
4873         mesh.unPolyze();
4874         mesh2=MEDCouplingDataForTest.build3DTargetMesh_1();
4875         mesh.checkCoherency();
4876         self.assertTrue(mesh.isEqual(mesh2,1e-12));
4877         mesh.convertToPolyTypes(eltsV);
4878         self.assertTrue(not mesh.isEqual(mesh2,1e-12));
4879         mesh.getNodalConnectivity().setIJ(0,6,10);
4880         mesh.getNodalConnectivity().setIJ(0,7,9);
4881         mesh.getNodalConnectivity().setIJ(0,8,12);
4882         mesh.getNodalConnectivity().setIJ(0,9,13);
4883         mesh.unPolyze();
4884         self.assertTrue(mesh.isEqual(mesh2,1e-12));
4885         mesh.convertToPolyTypes(eltsV);
4886         mesh.getNodalConnectivity().setIJ(0,6,12);
4887         mesh.getNodalConnectivity().setIJ(0,7,13);
4888         mesh.getNodalConnectivity().setIJ(0,8,10);
4889         mesh.getNodalConnectivity().setIJ(0,9,9);
4890         mesh.unPolyze();
4891         self.assertTrue(mesh.isEqual(mesh2,1e-12));
4892         mesh.convertToPolyTypes(eltsV);
4893         mesh.getNodalConnectivity().setIJ(0,6,12);
4894         mesh.getNodalConnectivity().setIJ(0,7,10);
4895         mesh.getNodalConnectivity().setIJ(0,8,13);
4896         mesh.getNodalConnectivity().setIJ(0,9,9);
4897         mesh.unPolyze();
4898         self.assertTrue(not mesh.isEqual(mesh2,1e-12));
4899         # Test for 2D mesh
4900         mesh=MEDCouplingDataForTest.build2DTargetMesh_1();
4901         mesh2=MEDCouplingDataForTest.build2DTargetMesh_1();
4902         eltsV=eltsV[:5];
4903         mesh.convertToPolyTypes(eltsV);
4904         self.assertTrue(not mesh.isEqual(mesh2,1e-12));
4905         mesh.unPolyze();
4906         self.assertTrue(mesh.isEqual(mesh2,1e-12));
4907         pass
4908
4909     def testConvertDegeneratedCells1(self):
4910         mesh=MEDCouplingDataForTest.build3DTargetMesh_1();
4911         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]
4912         mesh.allocateCells(4);
4913         mesh.insertNextCell(NORM_HEXA8,8,conn[0:8])
4914         mesh.insertNextCell(NORM_HEXA8,8,conn[8:16])
4915         mesh.insertNextCell(NORM_HEXA8,8,conn[16:24])
4916         mesh.insertNextCell(NORM_HEXA8,8,conn[24:32])
4917         mesh.finishInsertingCells();
4918         mesh.checkCoherency();
4919         self.assertEqual(4,mesh.getNumberOfCells());
4920         self.assertEqual(NORM_HEXA8,mesh.getTypeOfCell(0));
4921         self.assertEqual(NORM_HEXA8,mesh.getTypeOfCell(1));
4922         self.assertEqual(NORM_HEXA8,mesh.getTypeOfCell(2));
4923         self.assertEqual(NORM_HEXA8,mesh.getTypeOfCell(3));
4924         f1=mesh.getMeasureField(True);
4925         mesh.convertDegeneratedCells();
4926         mesh.checkCoherency();
4927         f2=mesh.getMeasureField(True);
4928         self.assertEqual(4,mesh.getNumberOfCells());
4929         self.assertEqual(NORM_PENTA6,mesh.getTypeOfCell(0));
4930         self.assertEqual(NORM_PYRA5,mesh.getTypeOfCell(1));
4931         self.assertEqual(NORM_TETRA4,mesh.getTypeOfCell(2));
4932         self.assertEqual(NORM_PYRA5,mesh.getTypeOfCell(3));
4933         for i in xrange(4):
4934             self.assertAlmostEqual(f1.getArray().getIJ(0,i),f2.getArray().getIJ(0,i),5);
4935             pass
4936         pass
4937
4938     def testGetNodeIdsNearPoints1(self):
4939         mesh=MEDCouplingDataForTest.build2DTargetMesh_1();
4940         coords=mesh.getCoords();
4941         tmp=DataArrayDouble.New();
4942         vals=[0.2,0.2,0.1,0.2,0.2,0.2]
4943         tmp.setValues(vals,3,2);
4944         tmp2=DataArrayDouble.Aggregate(coords,tmp);
4945         mesh.setCoords(tmp2);
4946         pts=[0.2,0.2,0.1,0.3,-0.3,0.7]
4947         c=mesh.getNodeIdsNearPoint(pts[:2],1e-7);
4948         self.assertEqual([4,9,11],c.getValues());
4949         c,cI=mesh.getNodeIdsNearPoints(pts,3,1e-7);
4950         self.assertEqual([0,3,3,4],cI.getValues());
4951         self.assertEqual([4,9,11,6],c.getValues());
4952         c,cI=mesh.getNodeIdsNearPoints(pts,1e-7);
4953         self.assertEqual([0,3,3,4],cI.getValues());
4954         self.assertEqual([4,9,11,6],c.getValues());
4955         c,cI=mesh.getNodeIdsNearPoints(DataArrayDouble.New(pts,3,2),1e-7);
4956         self.assertEqual([0,3,3,4],cI.getValues());
4957         self.assertEqual([4,9,11,6],c.getValues());
4958         self.assertRaises(InterpKernelException,mesh.getNodeIdsNearPoints,DataArrayDouble.New(pts,2,3),1e-7);
4959         pass
4960
4961     def testFieldCopyTinyAttrFrom1(self):
4962         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
4963         f1.setName("f1");
4964         f1.setTimeTolerance(1.e-5);
4965         f1.setDescription("f1Desc");
4966         f1.setTime(1.23,4,5);
4967         f2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
4968         f2.setName("f2");
4969         f2.setDescription("f2Desc");
4970         f2.setTime(6.78,9,10);
4971         f2.setTimeTolerance(4.556e-12);
4972         #
4973         f1.copyTinyAttrFrom(f2);
4974         self.assertAlmostEqual(4.556e-12,f1.getTimeTolerance(),24);
4975         t,dt,it=f1.getTime()
4976         self.assertAlmostEqual(6.78,t,12);
4977         self.assertEqual(9,dt);
4978         self.assertEqual(10,it);
4979         self.assertTrue(f1.getName()=="f1");#name unchanged
4980         self.assertTrue(f1.getDescription()=="f1Desc");#description unchanged
4981         #
4982         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
4983         f1.setName("f1");
4984         f1.setTimeTolerance(1.e-5);
4985         f1.setDescription("f1Desc");
4986         f2=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
4987         f2.setName("f2");
4988         f2.setDescription("f2Desc");
4989         f2.setTimeTolerance(4.556e-12);
4990         #
4991         f1.copyTinyAttrFrom(f2);
4992         self.assertAlmostEqual(4.556e-12,f1.getTimeTolerance(),24);
4993         self.assertTrue(f1.getName()=="f1");#name unchanged
4994         self.assertTrue(f1.getDescription()=="f1Desc");#description unchanged
4995         #
4996         f1=MEDCouplingFieldDouble.New(ON_CELLS,CONST_ON_TIME_INTERVAL);
4997         f1.setName("f1");
4998         f1.setTimeTolerance(1.e-5);
4999         f1.setDescription("f1Desc");
5000         f1.setTime(1.23,4,5);
5001         f1.setEndTime(5.43,2,1);
5002         f2=MEDCouplingFieldDouble.New(ON_CELLS,CONST_ON_TIME_INTERVAL);
5003         f2.setName("f2");
5004         f2.setDescription("f2Desc");
5005         f2.setTimeTolerance(4.556e-12);
5006         f2.setTime(6.78,9,10);
5007         f2.setEndTime(10.98,7,6);
5008         #
5009         f1.copyTinyAttrFrom(f2);
5010         self.assertAlmostEqual(4.556e-12,f1.getTimeTolerance(),24);
5011         self.assertTrue(f1.getName()=="f1");#name unchanged
5012         self.assertTrue(f1.getDescription()=="f1Desc");#description unchanged
5013         t,dt,it=f1.getTime()
5014         self.assertAlmostEqual(6.78,t,12);
5015         self.assertEqual(9,dt);
5016         self.assertEqual(10,it);
5017         t,dt,it=f1.getEndTime()
5018         self.assertAlmostEqual(10.98,t,12);
5019         self.assertEqual(7,dt);
5020         self.assertEqual(6,it);
5021         #
5022         f1=MEDCouplingFieldDouble.New(ON_CELLS,LINEAR_TIME);
5023         f1.setName("f1");
5024         f1.setTimeTolerance(1.e-5);
5025         f1.setDescription("f1Desc");
5026         f1.setTime(1.23,4,5);
5027         f1.setEndTime(5.43,2,1);
5028         f2=MEDCouplingFieldDouble.New(ON_CELLS,LINEAR_TIME);
5029         f2.setName("f2");
5030         f2.setDescription("f2Desc");
5031         f2.setTimeTolerance(4.556e-12);
5032         f2.setTime(6.78,9,10);
5033         f2.setEndTime(10.98,7,6);
5034         #
5035         f1.copyTinyAttrFrom(f2);
5036         self.assertAlmostEqual(4.556e-12,f1.getTimeTolerance(),24);
5037         self.assertTrue(f1.getName()=="f1");#name unchanged
5038         self.assertTrue(f1.getDescription()=="f1Desc");#description unchanged
5039         t,dt,it=f1.getTime()
5040         self.assertAlmostEqual(6.78,t,12);
5041         self.assertEqual(9,dt);
5042         self.assertEqual(10,it);
5043         t,dt,it=f1.getEndTime()
5044         self.assertAlmostEqual(10.98,t,12);
5045         self.assertEqual(7,dt);
5046         self.assertEqual(6,it);
5047         pass
5048
5049     def testExtrudedMesh5(self):
5050         coo1=[0.,1.,2.,3.5]
5051         a=DataArrayDouble.New();
5052         a.setValues(coo1,4,1);
5053         b=MEDCouplingCMesh.New();
5054         b.setCoordsAt(0,a);
5055         c=b.buildUnstructured();
5056         self.assertEqual(1,c.getSpaceDimension());
5057         c.changeSpaceDimension(2);
5058         #
5059         d=DataArrayDouble.New();
5060         d.alloc(13,1);
5061         d.iota();
5062         e=MEDCouplingCMesh.New();
5063         e.setCoordsAt(0,d);
5064         f=e.buildUnstructured();
5065         g=f.getCoords().applyFunc(2,"3.5*IVec+x/6*3.14159265359*JVec");
5066         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 !
5067         h=g.fromPolarToCart();
5068         f.setCoords(h);
5069         i=c.buildExtrudedMesh(f,1);
5070         self.assertEqual(52,i.getNumberOfNodes());
5071         tmp,tmp2,tmp3=i.mergeNodes(1e-9);
5072         self.assertTrue(tmp2);
5073         self.assertEqual(37,tmp3);
5074         i.convertDegeneratedCells();
5075         i.checkCoherency();
5076         self.assertEqual(36,i.getNumberOfCells());
5077         self.assertEqual(37,i.getNumberOfNodes());
5078         self.assertEqual(12,i.getNumberOfCellsWithType(NORM_TRI3));
5079         self.assertEqual(24,i.getNumberOfCellsWithType(NORM_QUAD4));
5080         expected1=[0.25,0.75,2.0625]
5081         j=i.getMeasureField(True);
5082         for ii in xrange(12):
5083             for k in xrange(3):
5084                 self.assertAlmostEqual(expected1[k],j.getIJ(0,ii*3+k),10);
5085                 pass
5086             pass
5087         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]
5088         m=i.getBarycenterAndOwner();
5089         for i in xrange(72):
5090             self.assertAlmostEqual(expected2[i],m.getIJ(0,i),10);
5091             pass
5092         #
5093         pass
5094
5095     def testExtrudedMesh6(self):
5096         coo1=[0.,1.,2.,3.5]
5097         a=DataArrayDouble.New();
5098         a.setValues(coo1,4,1);
5099         b=MEDCouplingCMesh.New();
5100         b.setCoordsAt(0,a);
5101         c=b.buildUnstructured();
5102         self.assertEqual(1,c.getSpaceDimension());
5103         c.changeSpaceDimension(2);
5104         #
5105         d=DataArrayDouble.New();
5106         d.alloc(5);
5107         d.iota();
5108         e=MEDCouplingCMesh.New();
5109         e.setCoordsAt(0,d);
5110         f=e.buildUnstructured();
5111         d2=f.getCoords().applyFunc("x*x/2");
5112         f.setCoords(d2);
5113         f.changeSpaceDimension(2);
5114         #
5115         center=[0.,0.]
5116         f.rotate(center,None,pi/3);
5117         g=c.buildExtrudedMesh(f,0);
5118         g.checkCoherency();
5119         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 ]
5120         f1=g.getMeasureField(True);
5121         for i in xrange(12):
5122             self.assertAlmostEqual(expected1[i],f1.getIJ(0,i),12);
5123             pass
5124         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]
5125         f2=g.getBarycenterAndOwner();
5126         for i in xrange(24):
5127             self.assertAlmostEqual(expected2[i],f2.getIJ(0,i),12);
5128             pass
5129         pass
5130
5131     def testExtrudedMesh7(self):
5132         coo1=[0.,1.,2.,3.5]
5133         a=DataArrayDouble.New();
5134         a.setValues(coo1,4,1);
5135         b=MEDCouplingCMesh.New();
5136         b.setCoordsAt(0,a);
5137         c=b.buildUnstructured();
5138         self.assertEqual(1,c.getSpaceDimension());
5139         c.changeSpaceDimension(2);
5140         #
5141         d=DataArrayDouble.New();
5142         d.alloc(13,1);
5143         d.iota();
5144         e=MEDCouplingCMesh.New();
5145         e.setCoordsAt(0,d);
5146         f=e.buildUnstructured();
5147         g=f.getCoords().applyFunc(2,"3.5*IVec+x/6*3.14159265359*JVec");
5148         h=g.fromPolarToCart();
5149         f.setCoords(h);
5150         i=c.buildExtrudedMesh(f,1);
5151         self.assertEqual(52,i.getNumberOfNodes());
5152         tmp,tmp2,tmp3=i.mergeNodes(1e-9);
5153         self.assertTrue(tmp2);
5154         self.assertEqual(37,tmp3);
5155         i.convertDegeneratedCells();
5156         vec1=[10.,0]
5157         i.translate(vec1);
5158         g2=h.applyFunc(3,"13.5/3.5*x*IVec+0*JVec+13.5/3.5*y*KVec");
5159         f.setCoords(g2);
5160         i.changeSpaceDimension(3);
5161         i3=i.buildExtrudedMesh(f,1);
5162         f2=i3.getMeasureField(True);
5163         tmp,tmp2,tmp3=i.mergeNodes(1e-9);
5164         self.assertTrue(tmp2);
5165         self.assertEqual(444,tmp3);
5166         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]
5167         for ii in xrange(12):
5168             for jj in xrange(36):
5169                 self.assertAlmostEqual(expected1[jj],f2.getIJ(0,ii*36+jj),9);
5170                 pass
5171         #
5172         pass
5173
5174     def testSimplexize1(self):
5175         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
5176         m.convertToPolyTypes([3]);
5177         da=m.simplexize(0);
5178         self.assertEqual(7,da.getNumberOfTuples());
5179         self.assertEqual(1,da.getNumberOfComponents());
5180         expected2=[0,0,1,2,3,4,4]
5181         for i in xrange(7):
5182             self.assertEqual(expected2[i],da.getIJ(i,0));
5183             pass
5184         m.checkCoherency();
5185         self.assertEqual(7,m.getNumberOfCells());
5186         self.assertEqual(NORM_TRI3,m.getTypeOfCell(0));
5187         self.assertEqual(NORM_TRI3,m.getTypeOfCell(1));
5188         self.assertEqual(NORM_TRI3,m.getTypeOfCell(2));
5189         self.assertEqual(NORM_TRI3,m.getTypeOfCell(3));
5190         self.assertEqual(NORM_POLYGON,m.getTypeOfCell(4));
5191         self.assertEqual(NORM_TRI3,m.getTypeOfCell(5));
5192         self.assertEqual(NORM_TRI3,m.getTypeOfCell(6));
5193         expected1=[0.125,0.125,0.125,0.125,0.25,0.125,0.125]
5194         f=m.getMeasureField(False);
5195         for i in xrange(7):
5196             self.assertAlmostEqual(expected1[i]*sqrt(2.),f.getIJ(i,0),10);
5197             pass
5198         types=m.getAllGeoTypes();
5199         self.assertEqual([NORM_TRI3,NORM_POLYGON],types);
5200         #
5201         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
5202         m.convertToPolyTypes([3]);
5203         da=m.simplexize(1);
5204         self.assertEqual(7,da.getNumberOfTuples());
5205         self.assertEqual(1,da.getNumberOfComponents());
5206         for i in xrange(7):
5207             self.assertEqual(expected2[i],da.getIJ(i,0));
5208             pass
5209         m.checkCoherency();
5210         types=m.getAllGeoTypes();
5211         self.assertEqual([NORM_TRI3,NORM_POLYGON],types);
5212         self.assertEqual(7,m.getNumberOfCells());
5213         self.assertEqual(NORM_TRI3,m.getTypeOfCell(0));
5214         self.assertEqual(NORM_TRI3,m.getTypeOfCell(1));
5215         self.assertEqual(NORM_TRI3,m.getTypeOfCell(2));
5216         self.assertEqual(NORM_TRI3,m.getTypeOfCell(3));
5217         self.assertEqual(NORM_POLYGON,m.getTypeOfCell(4));
5218         self.assertEqual(NORM_TRI3,m.getTypeOfCell(5));
5219         self.assertEqual(NORM_TRI3,m.getTypeOfCell(6));
5220         f=m.getMeasureField(False);
5221         for i in xrange(7):
5222             self.assertAlmostEqual(expected1[i]*sqrt(2.),f.getIJ(i,0),10);
5223             pass
5224         pass
5225
5226     def testSimplexize2(self):
5227         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
5228         m.convertToPolyTypes([3]);
5229         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
5230         f1.setMesh(m);
5231         arr=DataArrayDouble.New();
5232         arr1=[10.,110.,20.,120.,30.,130.,40.,140.,50.,150.]
5233         arr.setValues(arr1,5,2);
5234         f1.setArray(arr);
5235         #
5236         f1.checkCoherency();
5237         self.assertTrue(f1.simplexize(0));
5238         f1.checkCoherency();
5239         expected1=[10.,110.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.,50.,150.]
5240         for i in xrange(14):
5241             self.assertAlmostEqual(expected1[i],f1.getIJ(0,i),10);
5242             pass
5243         self.assertTrue(not f1.simplexize(0));
5244         for i in xrange(14):
5245             self.assertAlmostEqual(expected1[i],f1.getIJ(0,i),10);
5246             pass
5247         #
5248         pass
5249
5250     def testDAMeld1(self):
5251         da1=DataArrayDouble.New();
5252         da1.alloc(7,2);
5253         da2=DataArrayDouble.New();
5254         da2.alloc(7,1);
5255         #
5256         da1.fillWithValue(7.);
5257         da2.iota(0.);
5258         da3=da2.applyFunc(3,"10*x*IVec+100*x*JVec+1000*x*KVec");
5259         #
5260         da1.setInfoOnComponent(0,"c0da1");
5261         da1.setInfoOnComponent(1,"c1da1");
5262         da3.setInfoOnComponent(0,"c0da3");
5263         da3.setInfoOnComponent(1,"c1da3");
5264         da3.setInfoOnComponent(2,"c2da3");
5265         #
5266         da1C=da1.deepCpy();
5267         da1.meldWith(da3);
5268         self.assertEqual(5,da1.getNumberOfComponents());
5269         self.assertEqual(7,da1.getNumberOfTuples());
5270         self.assertTrue(da1.getInfoOnComponent(0)=="c0da1");
5271         self.assertTrue(da1.getInfoOnComponent(1)=="c1da1");
5272         self.assertTrue(da1.getInfoOnComponent(2)=="c0da3");
5273         self.assertTrue(da1.getInfoOnComponent(3)=="c1da3");
5274         self.assertTrue(da1.getInfoOnComponent(4)=="c2da3");
5275         #
5276         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.]
5277         for i in xrange(35):
5278             self.assertAlmostEqual(expected1[i],da1.getIJ(0,i),10);
5279             pass
5280         #
5281         dai1=da1C.convertToIntArr();
5282         dai3=da3.convertToIntArr();
5283         dai1.meldWith(dai3);
5284         self.assertEqual(5,dai1.getNumberOfComponents());
5285         self.assertEqual(7,dai1.getNumberOfTuples());
5286         self.assertTrue(dai1.getInfoOnComponent(0)=="c0da1");
5287         self.assertTrue(dai1.getInfoOnComponent(1)=="c1da1");
5288         self.assertTrue(dai1.getInfoOnComponent(2)=="c0da3");
5289         self.assertTrue(dai1.getInfoOnComponent(3)=="c1da3");
5290         self.assertTrue(dai1.getInfoOnComponent(4)=="c2da3");
5291         for i in xrange(35):
5292             self.assertEqual(int(expected1[i]),dai1.getIJ(0,i));
5293             pass
5294         # test of static method DataArrayDouble::meld
5295         da4=DataArrayDouble.Meld(da1C,da3);
5296         tmp=DataArrayDouble.Meld([da1C,da3]);
5297         self.assertTrue(da4.isEqual(tmp,1e-10))
5298         self.assertEqual(5,da4.getNumberOfComponents());
5299         self.assertEqual(7,da4.getNumberOfTuples());
5300         self.assertTrue(da4.getInfoOnComponent(0)=="c0da1");
5301         self.assertTrue(da4.getInfoOnComponent(1)=="c1da1");
5302         self.assertTrue(da4.getInfoOnComponent(2)=="c0da3");
5303         self.assertTrue(da4.getInfoOnComponent(3)=="c1da3");
5304         self.assertTrue(da4.getInfoOnComponent(4)=="c2da3");
5305         for i in xrange(35):
5306             self.assertAlmostEqual(expected1[i],da4.getIJ(0,i),10);
5307             pass
5308         # test of static method DataArrayInt::meld
5309         dai1=da1C.convertToIntArr();
5310         dai4=DataArrayInt.Meld(dai1,dai3);
5311         tmp=DataArrayInt.Meld([dai1,dai3]);
5312         self.assertTrue(dai4.isEqual(tmp))
5313         self.assertEqual(5,dai4.getNumberOfComponents());
5314         self.assertEqual(7,dai4.getNumberOfTuples());
5315         self.assertTrue(dai4.getInfoOnComponent(0)=="c0da1");
5316         self.assertTrue(dai4.getInfoOnComponent(1)=="c1da1");
5317         self.assertTrue(dai4.getInfoOnComponent(2)=="c0da3");
5318         self.assertTrue(dai4.getInfoOnComponent(3)=="c1da3");
5319         self.assertTrue(dai4.getInfoOnComponent(4)=="c2da3");
5320         for i in xrange(35):
5321             self.assertEqual(int(expected1[i]),dai4.getIJ(0,i));
5322             pass
5323         pass
5324
5325     def testFieldMeld1(self):
5326         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
5327         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
5328         f1.setMesh(m);
5329         da1=DataArrayDouble.New();
5330         arr1=[12.,23.,34.,45.,56.]
5331         da1.setValues(arr1,5,1);
5332         da1.setInfoOnComponent(0,"aaa");
5333         f1.setArray(da1);
5334         f1.setTime(3.4,2,1);
5335         f1.checkCoherency();
5336         #
5337         f2=f1.deepCpy();
5338         f2.setMesh(f1.getMesh());
5339         f2.checkCoherency();
5340         f2.changeNbOfComponents(2,5.);
5341         f2.assign(5.);
5342         f2.getArray().setInfoOnComponent(0,"bbb");
5343         f2.getArray().setInfoOnComponent(1,"ccc");
5344         f2.checkCoherency();
5345         #
5346         f3=MEDCouplingFieldDouble.MeldFields(f2,f1);
5347         f3.checkCoherency();
5348         self.assertEqual(5,f3.getNumberOfTuples());
5349         self.assertEqual(3,f3.getNumberOfComponents());
5350         self.assertTrue(f3.getArray().getInfoOnComponent(0)=="bbb");
5351         self.assertTrue(f3.getArray().getInfoOnComponent(1)=="ccc");
5352         self.assertTrue(f3.getArray().getInfoOnComponent(2)=="aaa");
5353         expected1=[5.,5.,12.,5.,5.,23.,5.,5.,34.,5.,5.,45.,5.,5.,56.]
5354         for i in xrange(15):
5355             self.assertAlmostEqual(expected1[i],f3.getIJ(0,i),12);
5356             pass
5357         time,dt,it=f3.getTime();
5358         self.assertAlmostEqual(3.4,time,14);
5359         self.assertEqual(2,dt);
5360         self.assertEqual(1,it);
5361         #
5362         f4=f2.buildNewTimeReprFromThis(NO_TIME,False);
5363         f5=f1.buildNewTimeReprFromThis(NO_TIME,False);
5364         f6=MEDCouplingFieldDouble.MeldFields(f4,f5);
5365         f6.checkCoherency();
5366         self.assertEqual(5,f6.getNumberOfTuples());
5367         self.assertEqual(3,f6.getNumberOfComponents());
5368         self.assertTrue(f6.getArray().getInfoOnComponent(0)=="bbb");
5369         self.assertTrue(f6.getArray().getInfoOnComponent(1)=="ccc");
5370         self.assertTrue(f6.getArray().getInfoOnComponent(2)=="aaa");
5371         for i in xrange(15):
5372             self.assertAlmostEqual(expected1[i],f6.getIJ(0,i),12);
5373             pass
5374         #
5375         pass
5376
5377     def testMergeNodes2(self):
5378         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
5379         m2=MEDCouplingDataForTest.build2DTargetMesh_1();
5380         vec=[0.002,0.]
5381         m2.translate(vec);
5382         #
5383         m3=MEDCouplingUMesh.MergeUMeshes([m1,m2]);
5384         da,b,newNbOfNodes=m3.mergeNodes2(0.01);
5385         self.assertEqual(9,m3.getNumberOfNodes());
5386         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]
5387         for i in xrange(18):
5388             self.assertAlmostEqual(expected1[i],m3.getCoords().getIJ(0,i),13);
5389             pass
5390         #
5391         pass
5392
5393     def testMergeField2(self):
5394         m=MEDCouplingDataForTest.build2DTargetMesh_1();
5395         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
5396         f1.setMesh(m);
5397         arr=DataArrayDouble.New();
5398         arr.alloc(5,2);
5399         arr.fillWithValue(2.);
5400         f1.setArray(arr);
5401         f2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
5402         f2.setMesh(m);
5403         arr=DataArrayDouble.New();
5404         arr.alloc(5,2);
5405         arr.fillWithValue(5.);
5406         f2.setArray(arr);
5407         f3=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
5408         f3.setMesh(m);
5409         arr=DataArrayDouble.New();
5410         arr.alloc(5,2);
5411         arr.fillWithValue(7.);
5412         f3.setArray(arr);
5413         #
5414         f4=MEDCouplingFieldDouble.MergeFields([f1,f2,f3]);
5415         self.assertEqual(15,f4.getMesh().getNumberOfCells());
5416         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.]
5417         for i in xrange(30):
5418             self.assertAlmostEqual(expected1[i],f4.getIJ(0,i),13);
5419             pass
5420         #
5421         pass
5422
5423     def testDAIBuildComplement1(self):
5424         a=DataArrayInt.New();
5425         tab=[3,1,7,8]
5426         a.setValues(tab,4,1);
5427         b=a.buildComplement(12);
5428         self.assertEqual(8,b.getNumberOfTuples());
5429         self.assertEqual(1,b.getNumberOfComponents());
5430         expected1=[0,2,4,5,6,9,10,11]
5431         for i in xrange(8):
5432             self.assertEqual(expected1[i],b.getIJ(0,i));
5433             pass
5434         pass
5435
5436     def testDAIBuildUnion1(self):
5437         a=DataArrayInt.New();
5438         tab1=[3,1,7,8]
5439         a.setValues(tab1,4,1);
5440         c=DataArrayInt.New();
5441         tab2=[5,3,0,18,8]
5442         c.setValues(tab2,5,1);
5443         b=a.buildUnion(c);
5444         self.assertEqual(7,b.getNumberOfTuples());
5445         self.assertEqual(1,b.getNumberOfComponents());
5446         expected1=[0,1,3,5,7,8,18]
5447         for i in xrange(7):
5448             self.assertEqual(expected1[i],b.getIJ(0,i));
5449             pass
5450         b=DataArrayInt.BuildUnion([a,c]);
5451         self.assertEqual(7,b.getNumberOfTuples());
5452         self.assertEqual(1,b.getNumberOfComponents());
5453         expected1=[0,1,3,5,7,8,18]
5454         for i in xrange(7):
5455             self.assertEqual(expected1[i],b.getIJ(0,i));
5456             pass
5457         pass
5458
5459     def testDAIBuildIntersection1(self):
5460         a=DataArrayInt.New();
5461         tab1=[3,1,7,8]
5462         a.setValues(tab1,4,1);
5463         c=DataArrayInt.New();
5464         tab2=[5,3,0,18,8]
5465         c.setValues(tab2,5,1);
5466         b=a.buildIntersection(c);
5467         self.assertEqual(2,b.getNumberOfTuples());
5468         self.assertEqual(1,b.getNumberOfComponents());
5469         expected1=[3,8]
5470         for i in xrange(2):
5471             self.assertEqual(expected1[i],b.getIJ(0,i));
5472             pass
5473         b=DataArrayInt.BuildIntersection([a,c]);
5474         self.assertEqual(2,b.getNumberOfTuples());
5475         self.assertEqual(1,b.getNumberOfComponents());
5476         expected1=[3,8]
5477         for i in xrange(2):
5478             self.assertEqual(expected1[i],b.getIJ(0,i));
5479             pass
5480         pass
5481
5482     def testDAIDeltaShiftIndex1(self):
5483         a=DataArrayInt.New();
5484         tab=[1,3,6,7,7,9,15]
5485         a.setValues(tab,7,1);
5486         b=a.deltaShiftIndex();
5487         self.assertEqual(6,b.getNumberOfTuples());
5488         self.assertEqual(1,b.getNumberOfComponents());
5489         expected1=[2,3,1,0,2,6]
5490         for i in xrange(6):
5491             self.assertEqual(expected1[i],b.getIJ(0,i));
5492             pass
5493         pass
5494
5495     def testDaDoubleSelectByTupleIdSafe1(self):
5496         a=DataArrayDouble.New();
5497         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]
5498         a.setValues(arr1,7,2);
5499         a.setInfoOnComponent(0,"toto");
5500         a.setInfoOnComponent(1,"tata");
5501         #
5502         arr2=[4,2,0,6,5]
5503         b=a.selectByTupleIdSafe(arr2);
5504         self.assertEqual(5,b.getNumberOfTuples());
5505         self.assertEqual(2,b.getNumberOfComponents());
5506         self.assertTrue(b.getInfoOnComponent(0)=="toto");
5507         self.assertTrue(b.getInfoOnComponent(1)=="tata");
5508         expected1=[5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1]
5509         for i in xrange(10):
5510             self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
5511             pass
5512         arr4=[4,-1,0,6,5]
5513         self.assertRaises(InterpKernelException,a.selectByTupleIdSafe,arr4);
5514         arr5=[4,2,0,6,7]
5515         self.assertRaises(InterpKernelException,a.selectByTupleIdSafe,arr5);
5516         #
5517         c=DataArrayInt.New();
5518         arr3=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
5519         c.setValues(arr3,7,2);
5520         c.setInfoOnComponent(0,"toto");
5521         c.setInfoOnComponent(1,"tata");
5522         d=c.selectByTupleIdSafe(arr2);
5523         self.assertEqual(5,d.getNumberOfTuples());
5524         self.assertEqual(2,d.getNumberOfComponents());
5525         self.assertTrue(d.getInfoOnComponent(0)=="toto");
5526         self.assertTrue(d.getInfoOnComponent(1)=="tata");
5527         expected2=[5,15,3,13,1,11,7,17,6,16]
5528         for i in xrange(10):
5529             self.assertEqual(expected2[i],d.getIJ(0,i));
5530             pass
5531         self.assertRaises(InterpKernelException,c.selectByTupleIdSafe,arr4);
5532         self.assertRaises(InterpKernelException,c.selectByTupleIdSafe,arr5);
5533         pass
5534
5535     def testAreCellsIncludedIn1(self):
5536         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
5537         pt=[1,3]
5538         m2=m.buildPartOfMySelf(pt,True);
5539         ret,tmp=m.areCellsIncludedIn(m2,0)
5540         self.assertTrue(ret);
5541         self.assertEqual(2,tmp.getNumberOfTuples());
5542         self.assertEqual(1,tmp.getNumberOfComponents());
5543         self.assertEqual(pt[0],tmp.getIJ(0,0));
5544         self.assertEqual(pt[1],tmp.getIJ(0,1));
5545         ret,tmp=m2.areCellsIncludedIn(m,0)
5546         self.assertTrue(not ret);
5547         m3=MEDCouplingUMesh.MergeUMeshesOnSameCoords(m,m2)
5548         c,cI=m3.findCommonCells(2,m.getNumberOfCells())
5549         self.assertTrue(c.isEqual(DataArrayInt([1,5,3,6])))
5550         self.assertTrue(cI.isEqual(DataArrayInt([0,2,4])))
5551         pass
5552
5553     def testSwigErrorProtection1(self):
5554         m=MEDCouplingDataForTest.build3DTargetMesh_1();
5555         m.rotate([0.,0.,0.],[0.3,0.6,1.2],0.37)
5556         m.rotate([0.,0.,0.],[0.3,6,1.2],0.37)
5557         self.assertRaises(InterpKernelException,m.rotate,[0.,0.,0.],(0.3,6,"1.2"),0.37)
5558         self.assertRaises(InterpKernelException,m.rotate,[0.,"0.",0.],[0.3,0.6,1.2],0.37)
5559         self.assertRaises(InterpKernelException,m.rotate,[0.,0.,0.],[0.3,'0.6',1.2],0.37)
5560         m2=m.buildPartOfMySelf([2,5],True)
5561         m3=m.buildPartOfMySelf((2,5),True)
5562         self.assertTrue(m2.isEqual(m3,1e-12))
5563         self.assertRaises(InterpKernelException,m.buildPartOfMySelf,[2,5.],True)
5564         da1=m.getCoords().keepSelectedComponents([1])
5565         da2=m.getCoords().keepSelectedComponents((1,))
5566         self.assertTrue(da1.isEqual(da2,1e-12))
5567         self.assertRaises(InterpKernelException,m.getCoords().keepSelectedComponents,["1"])
5568         pass
5569
5570     def testDAIBuildSubstraction1(self):
5571         a=DataArrayInt.New()
5572         aa=[2,3,6,8,9]
5573         a.setValues(aa,5,1)
5574         b=DataArrayInt.New()
5575         bb=[1,3,5,9,11]
5576         b.setValues(bb,5,1)
5577         self.assertEqual([2,6,8],a.buildSubstraction(b).getValues())
5578         pass
5579
5580     def testBuildOrthogonalField2(self):
5581         m=MEDCouplingDataForTest.build2DTargetMesh_1();
5582         d1=DataArrayInt.New();
5583         d2=DataArrayInt.New();
5584         d3=DataArrayInt.New();
5585         d4=DataArrayInt.New();
5586         m1=m.buildDescendingConnectivity(d1,d2,d3,d4);
5587         #
5588         f1=m1.buildOrthogonalField();
5589         da1=f1.getArray();
5590         self.assertEqual(2,da1.getNumberOfComponents());
5591         self.assertEqual(13,da1.getNumberOfTuples());
5592         #
5593         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.];
5594         for i in xrange(26):
5595             self.assertAlmostEqual(expected1[i],da1.getIJ(0,i),14);
5596             pass
5597         pass
5598
5599     def testSwigErrorProtection2(self):
5600         m=MEDCouplingDataForTest.build2DTargetMesh_1();
5601         coo=m.getCoords()
5602         c=m.getNodalConnectivity()
5603         ci=m.getNodalConnectivityIndex()
5604         del m
5605         self.assertEqual(2,coo.getNumberOfComponents());
5606         self.assertEqual(6,ci.getNumberOfTuples());
5607         self.assertEqual(23,c.getNumberOfTuples());
5608         m=MEDCouplingDataForTest.build2DTargetMesh_1();
5609         f=m.getMeasureField(True)
5610         c=f.getArray()
5611         del f
5612         self.assertEqual(1,c.getNumberOfComponents());
5613         m=MEDCouplingCMesh.New()
5614         x=DataArrayDouble.New()
5615         x.setValues([1.,2.,4.],3,1)
5616         m.setCoordsAt(0,x)
5617         del x
5618         xx=m.getCoordsAt(0)
5619         del m
5620         self.assertEqual(3,xx.getNumberOfTuples());
5621         #
5622         m=MEDCouplingDataForTest.build2DTargetMesh_1();
5623         f=m.getMeasureField(True)
5624         m2=f.getMesh()
5625         del m
5626         del f
5627         self.assertEqual(5,m2.getNumberOfCells());
5628         pass
5629
5630     def testUMInsertNextCell1(self):
5631         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 ]
5632         targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
5633         targetMesh=MEDCouplingUMesh.New();
5634         targetMesh.allocateCells(5);
5635         self.assertRaises(InterpKernelException,targetMesh.insertNextCell,NORM_QUAD4,4,targetConn[0:4])
5636         targetMesh.setMeshDimension(2);
5637         targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
5638         self.assertRaises(InterpKernelException,targetMesh.insertNextCell,NORM_TETRA4,4,targetConn[0:4])
5639         self.assertRaises(InterpKernelException,targetMesh.insertNextCell,NORM_SEG2,2,targetConn[0:2])
5640         self.assertRaises(InterpKernelException,targetMesh.insertNextCell,NORM_POINT1,1,targetConn[0:1])
5641         targetMesh.insertNextCell(NORM_TRI3,3,targetConn[4:7])
5642         targetMesh.insertNextCell(NORM_TRI3,3,targetConn[7:10])
5643         targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[10:14])
5644         targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[14:18])
5645         targetMesh.finishInsertingCells();
5646         myCoords=DataArrayDouble.New();
5647         myCoords.setValues(targetCoords,9,2);
5648         targetMesh.setCoords(myCoords);
5649         targetMesh.checkCoherency();
5650         pass
5651
5652     def testFieldOperatorDivDiffComp1(self):
5653         m=MEDCouplingDataForTest.build2DTargetMesh_1();
5654         m1,d0,d1,d2,d3=m.buildDescendingConnectivity();
5655         #
5656         f1=m1.buildOrthogonalField();
5657         arr1=[2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.]
5658         arr=DataArrayDouble.New();
5659         arr.setValues(arr1,13,1);
5660         f2=MEDCouplingFieldDouble.New(ON_CELLS);
5661         f2.setArray(arr);
5662         f2.setMesh(m1);
5663         f2.checkCoherency();
5664         #
5665         f3=f1/f2;
5666         self.assertRaises(InterpKernelException,f2.__div__,f1)
5667         f3.checkCoherency();
5668         f1/=f2;
5669         #self.assertRaises(InterpKernelException,f2.__idiv__,f1) # mem leaks
5670         self.assertTrue(f1.isEqual(f3,1e-10,1e-10));
5671         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]
5672         for i in xrange(26):
5673             self.assertAlmostEqual(expected1[i],f3.getIJ(0,i),10);
5674             pass
5675         pass
5676
5677     def testDARearrange1(self):
5678         da1=DataArrayInt.New();
5679         da1.alloc(12,1);
5680         da1.iota(0);
5681         #
5682         self.assertEqual(12,da1.getNbOfElems());
5683         self.assertEqual(1,da1.getNumberOfComponents());
5684         self.assertEqual(12,da1.getNumberOfTuples());
5685         da1.rearrange(4);
5686         self.assertEqual(12,da1.getNbOfElems());
5687         self.assertEqual(4,da1.getNumberOfComponents());
5688         self.assertEqual(3,da1.getNumberOfTuples());
5689         for i in xrange(12):
5690             self.assertEqual(i,da1.getIJ(0,i));
5691         #
5692         da1.rearrange(6);
5693         self.assertEqual(12,da1.getNbOfElems());
5694         self.assertEqual(6,da1.getNumberOfComponents());
5695         self.assertEqual(2,da1.getNumberOfTuples());
5696         for i in xrange(12):
5697             self.assertEqual(i,da1.getIJ(0,i));
5698         #
5699         self.assertRaises(InterpKernelException,da1.rearrange,7);
5700         #
5701         da1.rearrange(12);
5702         self.assertEqual(12,da1.getNbOfElems());
5703         self.assertEqual(12,da1.getNumberOfComponents());
5704         self.assertEqual(1,da1.getNumberOfTuples());
5705         for i in xrange(12):
5706             self.assertEqual(i,da1.getIJ(0,i));
5707         #
5708         da1.rearrange(3);
5709         self.assertEqual(12,da1.getNbOfElems());
5710         self.assertEqual(3,da1.getNumberOfComponents());
5711         self.assertEqual(4,da1.getNumberOfTuples());
5712         for i in xrange(12):
5713             self.assertEqual(i,da1.getIJ(0,i));
5714         #double
5715         da2=da1.convertToDblArr();
5716         st=da2.getHiddenCppPointer()
5717         #
5718         self.assertEqual(12,da2.getNbOfElems());
5719         self.assertEqual(3,da2.getNumberOfComponents());
5720         self.assertEqual(4,da2.getNumberOfTuples());
5721         da2.rearrange(4);
5722         self.assertEqual(12,da2.getNbOfElems());
5723         self.assertEqual(4,da2.getNumberOfComponents());
5724         self.assertEqual(3,da2.getNumberOfTuples());
5725         for i in xrange(12):
5726             self.assertAlmostEqual(float(i),da2.getIJ(0,i),14);
5727         #
5728         da2.rearrange(6);
5729         self.assertEqual(12,da2.getNbOfElems());
5730         self.assertEqual(6,da2.getNumberOfComponents());
5731         self.assertEqual(2,da2.getNumberOfTuples());
5732         for i in xrange(12):
5733             self.assertAlmostEqual(float(i),da2.getIJ(0,i),14);
5734         #
5735         self.assertRaises(InterpKernelException,da2.rearrange,7);
5736         #
5737         da2.rearrange(1);
5738         self.assertEqual(st,da2.getHiddenCppPointer())
5739         self.assertEqual(12,da2.getNbOfElems());
5740         self.assertEqual(1,da2.getNumberOfComponents());
5741         self.assertEqual(12,da2.getNumberOfTuples());
5742         for i in xrange(12):
5743             self.assertAlmostEqual(float(i),da2.getIJ(0,i),14);
5744         #
5745         da2.rearrange(3);
5746         self.assertEqual(12,da2.getNbOfElems());
5747         self.assertEqual(3,da2.getNumberOfComponents());
5748         self.assertEqual(4,da2.getNumberOfTuples());
5749         for i in xrange(12):
5750             self.assertAlmostEqual(float(i),da2.getIJ(0,i),14);
5751         pass
5752
5753     def testDARearrange2(self):
5754         da1=DataArrayInt.New();
5755         arr=[1,2,3,2,2,3,5,1,5,5,2,2]
5756         da1.setValues(arr,4,3);
5757         s=da1.getDifferentValues();
5758         expected1=DataArrayInt([1,2,3,5])
5759         self.assertTrue(expected1.isEqual(s));
5760         pass
5761
5762     def testSwigErrorProtection3(self):
5763         da=DataArrayInt.New()
5764         da.setValues([1,2,3,4,0,0,0,0,0,0,0,0],4,3)
5765         self.assertEqual([1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0],da.getValues())
5766         self.assertEqual(3,da.getNumberOfComponents());
5767         self.assertEqual(4,da.getNumberOfTuples());
5768         da=DataArrayInt.New()
5769         da.setValues(((1,2,3),(4,4,3),(0,0,0),(0,0,0)),4,3)
5770         self.assertEqual([1, 2, 3, 4, 4, 3, 0, 0, 0, 0, 0, 0],da.getValues())
5771         self.assertEqual(3,da.getNumberOfComponents());
5772         self.assertEqual(4,da.getNumberOfTuples());
5773         da.setValues((10*[1]+290*[2])[:12],4,3)
5774         self.assertEqual(10*[1]+[2,2],da.getValues())
5775         self.assertEqual(3,da.getNumberOfComponents());
5776         self.assertEqual(4,da.getNumberOfTuples());
5777         #
5778         da=DataArrayDouble.New()
5779         da.setValues([1,2,3.,4,0,0,0,0,0,0,0,0],4,3)
5780         self.assertEqual([1., 2., 3., 4., 0., 0., 0., 0., 0., 0., 0., 0.],da.getValues())
5781         self.assertEqual(3,da.getNumberOfComponents());
5782         self.assertEqual(4,da.getNumberOfTuples());
5783         da=DataArrayDouble.New()
5784         da.setValues(((1,2,3),(4.,4,3),(0,0,0),(0,0,0)),4,3)
5785         self.assertEqual([1., 2., 3., 4., 4., 3., 0., 0., 0., 0., 0., 0.],da.getValues())
5786         self.assertEqual(3,da.getNumberOfComponents());
5787         self.assertEqual(4,da.getNumberOfTuples());
5788         da.setValues((10*[1]+290*[2])[:12],4,3)
5789         self.assertEqual(10*[1.]+[2.,2.],da.getValues())
5790         self.assertEqual(3,da.getNumberOfComponents());
5791         self.assertEqual(4,da.getNumberOfTuples());
5792         pass
5793
5794     def testDAIBuildPermutationArr1(self):
5795         a=DataArrayInt.New()
5796         a.setValues([4,5,6,7,8],5,1)
5797         b=DataArrayInt.New()
5798         b.setValues([5,4,8,6,7],5,1)
5799         c=a.buildPermutationArr(b)
5800         self.assertEqual([1,0,4,2,3],c.getValues())
5801         self.assertTrue(a.isEqualWithoutConsideringStrAndOrder(b))
5802         b.setIJ(0,0,9)
5803         self.assertTrue(not a.isEqualWithoutConsideringStrAndOrder(b))
5804         self.assertRaises(InterpKernelException,a.buildPermutationArr,b)
5805         a.setIJ(3,0,4)
5806         b.setIJ(0,0,5)
5807         b.setIJ(4,0,4)#a==[4,5,6,4,8] and b==[5,4,8,6,4]
5808         self.assertTrue(a.isEqualWithoutConsideringStrAndOrder(b))
5809         c=a.buildPermutationArr(b)
5810         self.assertEqual([1,3,4,2,3],c.getValues())
5811         d=b.convertToDblArr()
5812         expect3=[4,4,5,6,8]
5813         b.sort()
5814         self.assertEqual(expect3,b.getValues())
5815         d.sort()
5816         self.assertEqual(5,d.getNumberOfTuples());
5817         self.assertEqual(1,d.getNumberOfComponents());
5818         for i in xrange(5):
5819             self.assertAlmostEqual(float(expect3[i]),d.getIJ(i,0),14);
5820             pass
5821         pass
5822
5823     def testAreCellsIncludedIn2(self):
5824         myName="Vitoo";
5825         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
5826         m2=m.buildPartOfMySelf([],True);
5827         self.assertEqual(0,m2.getNumberOfCells());
5828         self.assertEqual(3,m2.getSpaceDimension());
5829         self.assertEqual(2,m2.getMeshDimension());
5830         m2.setName(myName);
5831         test,tmp=m.areCellsIncludedIn(m2,0)
5832         self.assertTrue(test);
5833         self.assertEqual(myName,tmp.getName());
5834         self.assertEqual(0,tmp.getNumberOfTuples())
5835         self.assertEqual(1,tmp.getNumberOfComponents())
5836         pass
5837
5838     def testUMeshGetPartBarycenterAndOwner1(self):
5839         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
5840         part1=[1,0,4];
5841         part=DataArrayInt.New();
5842         part.setValues(part1,3,1);
5843         b=m1.getPartBarycenterAndOwner(part);
5844         self.assertEqual(2,b.getNumberOfComponents());
5845         self.assertEqual(3,b.getNumberOfTuples());
5846         expected1=[0.36666666666666665,-0.13333333333333333,-0.05,-0.05,0.45,0.45];
5847         for i in xrange(6):
5848             self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
5849             pass
5850         pass
5851
5852     def testUMeshGetPartMeasureField1(self):
5853         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
5854         part1=[1,0,4];
5855         part=DataArrayInt.New();
5856         part.setValues(part1,3,1);
5857         b=m1.getPartMeasureField(True,part);
5858         self.assertEqual(1,b.getNumberOfComponents());
5859         self.assertEqual(3,b.getNumberOfTuples());
5860         expected1=[0.125,0.25,0.25];
5861         for i in xrange(3):
5862             self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
5863             pass
5864         pass
5865
5866     def testUMeshBuildPartOrthogonalField1(self):
5867         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
5868         m1.changeSpaceDimension(3);
5869         part1=[1,0,4];
5870         part=DataArrayInt.New();
5871         part.setValues(part1,3,1);
5872         b=m1.buildPartOrthogonalField(part);
5873         self.assertEqual(3,b.getArray().getNumberOfComponents());
5874         self.assertEqual(3,b.getArray().getNumberOfTuples());
5875         expected1=[0.,0.,-1.,0.,0.,-1.,0.,0.,-1.];
5876         for i in xrange(9):
5877             self.assertAlmostEqual(expected1[i],b.getArray().getIJ(0,i),14);
5878             pass
5879         pass
5880
5881     def testUMeshGetTypesOfPart1(self):
5882         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
5883         part1=[0,3,4];
5884         p1=DataArrayInt.New()
5885         p1.setValues(part1,3,1)
5886         s=m1.getTypesOfPart(p1);
5887         self.assertEqual([NORM_QUAD4],s);
5888         part2=[2,2,2,1];
5889         p2=DataArrayInt.New()
5890         p2.setValues(part2,4,1)
5891         s=m1.getTypesOfPart(p2);
5892         self.assertEqual([NORM_TRI3],s);
5893         part3=[3,2,1];
5894         p3=DataArrayInt.New()
5895         p3.setValues(part3,3,1)
5896         s=m1.getTypesOfPart(p3);
5897         self.assertEqual(s,[NORM_TRI3,NORM_QUAD4]);
5898         pass
5899
5900     def testUMeshKeepCellIdsByType1(self):
5901         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
5902         part1=[0,3,4]
5903         p1=DataArrayInt.New()
5904         p1.setValues(part1,3,1)
5905         p1.setName("p1")
5906         a=m1.keepCellIdsByType(NORM_TRI3,p1);
5907         self.assertEqual("p1",a.getName())
5908         self.assertEqual(1,a.getNumberOfComponents());
5909         self.assertEqual(0,a.getNumberOfTuples());
5910         #
5911         part2=[3,2,0,2,4]
5912         p2=DataArrayInt.New()
5913         p2.setValues(part2,5,1)
5914         p2.setName("p2")
5915         a=m1.keepCellIdsByType(NORM_TRI3,p2);
5916         self.assertEqual("p2",a.getName())
5917         self.assertEqual(1,a.getNumberOfComponents());
5918         self.assertEqual(2,a.getNumberOfTuples());
5919         self.assertEqual(2,a.getIJ(0,0));
5920         self.assertEqual(2,a.getIJ(1,0));
5921         #
5922         a=m1.keepCellIdsByType(NORM_QUAD4,p2);
5923         self.assertEqual("p2",a.getName())
5924         self.assertEqual(1,a.getNumberOfComponents());
5925         self.assertEqual(3,a.getNumberOfTuples());
5926         self.assertEqual(3,a.getIJ(0,0));
5927         self.assertEqual(0,a.getIJ(1,0));
5928         self.assertEqual(4,a.getIJ(2,0));
5929         pass
5930     
5931     def testSwigErrorDaIntSelectByTupleId1(self):
5932         a=DataArrayInt.New();
5933         arr1=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
5934         a.setValues(arr1,7,2);
5935         a.setInfoOnComponent(0,"toto");
5936         a.setInfoOnComponent(1,"tata");
5937         #
5938         arr2=[4,2,0,6,5]
5939         b=a.selectByTupleId(arr2);
5940         self.assertEqual(5,b.getNumberOfTuples());
5941         self.assertEqual(2,b.getNumberOfComponents());
5942         self.assertTrue(b.getInfoOnComponent(0)=="toto");
5943         self.assertTrue(b.getInfoOnComponent(1)=="tata");
5944         expected1=[5,15,3,13,1,11,7,17,6,16]
5945         self.assertEqual(expected1,b.getValues())
5946         #
5947         a2=DataArrayInt.New()
5948         a2.setValues(arr2,5,1)
5949         b=a.selectByTupleId(a2);
5950         self.assertEqual(5,b.getNumberOfTuples());
5951         self.assertEqual(2,b.getNumberOfComponents());
5952         self.assertTrue(b.getInfoOnComponent(0)=="toto");
5953         self.assertTrue(b.getInfoOnComponent(1)=="tata");
5954         expected1=[5,15,3,13,1,11,7,17,6,16]
5955         self.assertEqual(expected1,b.getValues())
5956         pass
5957
5958     def testSwigErrorRenum(self):
5959         da=DataArrayDouble.New()
5960         da.setValues([7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.],10,2)
5961         d=DataArrayInt.New()
5962         d.setValues([0,2,3,1,4,5,6,8,7,9],10,1)
5963         da.renumberInPlace(d)
5964         da.renumber(d)
5965         pass
5966
5967     def testSwigGetItem1(self):
5968         da=DataArrayInt.New()
5969         da.alloc(16,3)
5970         da.rearrange(1)
5971         da.iota(7)
5972         da.rearrange(3)
5973         da.setInfoOnComponent(0,"X [m]")
5974         da.setInfoOnComponent(1,"Y [m]")
5975         da.setInfoOnComponent(2,"Z [km]")
5976         da2=da[5:-1]
5977         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())
5978         da2=da[4]
5979         self.assertEqual([19, 20, 21],da2.getValues())
5980         try:
5981             da2=da[4:17]
5982         except InterpKernelException as e:
5983             self.assertTrue(True)
5984         else:
5985             self.assertTrue(False)
5986             pass
5987         da2=da[5:-2,2]
5988         self.assertEqual([24, 27, 30, 33, 36, 39, 42, 45, 48],da2.getValues())
5989         da2=da[5:8,:]
5990         self.assertEqual([22, 23, 24, 25, 26, 27, 28, 29, 30],da2.getValues())
5991         da2=da[:]
5992         self.assertTrue(da2.isEqual(da))
5993         da2=da[:,:]
5994         self.assertTrue(da2.isEqual(da))
5995         try:
5996             da2=da[:,:,:]
5997         except InterpKernelException as e:
5998             self.assertTrue(True)
5999         else:
6000             self.assertTrue(False)
6001             pass
6002         try:
6003             da2=da[5:8,-2]
6004         except InterpKernelException as e:
6005             self.assertTrue(True)
6006         else:
6007             self.assertTrue(False)
6008             pass
6009         da2=da[5:8,:-2]
6010         self.assertEqual([22, 25, 28],da2.getValues())
6011         try:
6012             da2=da[5:-18,2]
6013         except InterpKernelException as e:
6014             self.assertTrue(True)
6015         else:
6016             self.assertTrue(False)
6017             pass
6018         da2=da[5:5,2]
6019         self.assertEqual([],da2.getValues())
6020         pass
6021
6022     def testSwigGetItem2(self):
6023         da=DataArrayDouble.New()
6024         da.alloc(16,3)
6025         da.rearrange(1)
6026         da.iota(7)
6027         da.rearrange(3)
6028         da.setInfoOnComponent(0,"X [m]")
6029         da.setInfoOnComponent(1,"Y [m]")
6030         da.setInfoOnComponent(2,"Z [km]")
6031         da2=da[5:-1]
6032         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())
6033         da2=da[4]
6034         self.assertEqual([19., 20., 21],da2.getValues())
6035         try:
6036             da2=da[4:17]
6037         except InterpKernelException as e:
6038             self.assertTrue(True)
6039         else:
6040             self.assertTrue(False)
6041             pass
6042         da2=da[5:-2,2]
6043         self.assertEqual([24., 27., 30., 33., 36., 39., 42., 45., 48.],da2.getValues())
6044         da2=da[5:8,:]
6045         self.assertEqual([22., 23., 24., 25., 26., 27., 28., 29., 30.],da2.getValues())
6046         da2=da[:]
6047         self.assertTrue(da2.isEqual(da,1e-12))
6048         da2=da[:,:]
6049         self.assertTrue(da2.isEqual(da,1e-12))
6050         try:
6051             da2=da[:,:,:]
6052         except InterpKernelException as e:
6053             self.assertTrue(True)
6054         else:
6055             self.assertTrue(False)
6056             pass
6057         try:
6058             da2=da[5:8,-2]
6059         except InterpKernelException as e:
6060             self.assertTrue(True)
6061         else:
6062             self.assertTrue(False)
6063             pass
6064         da2=da[5:8,:-2]
6065         self.assertEqual([22., 25., 28.],da2.getValues())
6066         try:
6067             da2=da[5:-18,2]
6068         except InterpKernelException as e:
6069             self.assertTrue(True)
6070         else:
6071             self.assertTrue(False)
6072             pass
6073         da2=da[5:5,2]
6074         self.assertEqual([],da2.getValues())
6075         pass
6076
6077     def testSwigSetItem1(self):
6078         da=DataArrayInt.New()
6079         da.alloc(20,1)
6080         da.iota(7)
6081         da.rearrange(5)
6082         da.setInfoOnComponent(0,"X [m]") ; da.setInfoOnComponent(1,"Y [km]") ; da.setInfoOnComponent(2,"Y [m]")
6083         da.setInfoOnComponent(3,"Z [W]") ; da.setInfoOnComponent(4,"ZZ [km]") ; 
6084         da[:,2]=3
6085         self.assertEqual([7, 8, 3, 10, 11, 12, 13, 3, 15, 16, 17, 18, 3, 20, 21, 22, 23, 3, 25, 26],da.getValues())
6086         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6087         da[2]=3
6088         self.assertEqual([7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 3, 3, 3, 3, 3, 22, 23, 24, 25, 26],da.getValues())
6089         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6090         da[[0,3]]=-1
6091         self.assertEqual([-1, -1, -1, -1, -1, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, -1, -1, -1, -1, -1],da.getValues())
6092         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6093         da[:,[1,3,4]]=-3
6094         self.assertEqual([7, -3, 9, -3, -3, 12, -3, 14, -3, -3, 17, -3, 19, -3, -3, 22, -3, 24, -3, -3],da.getValues())
6095         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6096         da2=DataArrayInt.New() ; da2.setValues([0,2,3],3,1)
6097         da[da2]=-7
6098         self.assertEqual([-7, -7, -7, -7, -7, 12, 13, 14, 15, 16, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7],da.getValues())
6099         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6100         da[da2,-2:]=-7
6101         self.assertEqual([7, 8, 9, -7, -7, 12, 13, 14, 15, 16, 17, 18, 19, -7, -7, 22, 23, 24, -7, -7],da.getValues())
6102         # Let's test with DAI right hand side
6103         da1=DataArrayInt.New()
6104         da1.setValues([25,26,27,125,126,127],2,3)
6105         #
6106         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6107         da[-2:,1:4]=da1
6108         self.assertEqual([7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 25, 26, 27, 21, 22, 125, 126, 127, 26],da.getValues())
6109         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6110         da[1:,3]=[225,226,227]
6111         self.assertEqual([7, 8, 9, 10, 11, 12, 13, 14, 225, 16, 17, 18, 19, 226, 21, 22, 23, 24, 227, 26],da.getValues())
6112         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6113         da[1,2:]=[225,226,227]
6114         self.assertEqual([7, 8, 9, 10, 11, 12, 13, 225, 226, 227, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26],da.getValues())
6115         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6116         da[da2,-2:]=[88,99,1010,1111,1212,1313]
6117         self.assertEqual([7, 8, 9, 88, 99, 12, 13, 14, 15, 16, 17, 18, 19, 1010, 1111, 22, 23, 24, 1212, 1313],da.getValues())
6118         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6119         da3=DataArrayInt.New(); da3.setValues([88,99,1010,1111,1212,1313],3,2)
6120         da[da2,-2:]=da3
6121         self.assertEqual([7, 8, 9, 88, 99, 12, 13, 14, 15, 16, 17, 18, 19, 1010, 1111, 22, 23, 24, 1212, 1313],da.getValues())
6122         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6123         da[da2,[0,2]]=da3
6124         self.assertEqual([88, 8, 99, 10, 11, 12, 13, 14, 15, 16, 1010, 18, 1111, 20, 21, 1212, 23, 1313, 25, 26],da.getValues())
6125         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6126         da[da2,0:3:2]=da3
6127         self.assertEqual([88, 8, 99, 10, 11, 12, 13, 14, 15, 16, 1010, 18, 1111, 20, 21, 1212, 23, 1313, 25, 26],da.getValues())
6128         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6129         da[da2,0:3:2]=-8
6130         self.assertEqual([-8, 8, -8, 10, 11, 12, 13, 14, 15, 16, -8, 18, -8, 20, 21, -8, 23, -8, 25, 26],da.getValues())
6131         pass
6132
6133     def testSwigSetItem2(self):
6134         da=DataArrayDouble.New()
6135         da.alloc(20,1)
6136         da.iota(7)
6137         da.rearrange(5)
6138         da.setInfoOnComponent(0,"X [m]") ; da.setInfoOnComponent(1,"Y [km]") ; da.setInfoOnComponent(2,"Y [m]")
6139         da.setInfoOnComponent(3,"Z [W]") ; da.setInfoOnComponent(4,"ZZ [km]") ; 
6140         da[:,2]=3.
6141         self.assertEqual([7., 8., 3., 10., 11., 12., 13., 3., 15., 16., 17., 18., 3., 20., 21., 22., 23., 3., 25., 26.],da.getValues())
6142         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6143         da[2]=3.
6144         self.assertEqual([7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 3., 3., 3., 3., 3., 22., 23., 24., 25., 26.],da.getValues())
6145         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6146         da[[0,3]]=-1.
6147         self.assertEqual([-1., -1., -1., -1., -1., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., -1., -1., -1., -1., -1.],da.getValues())
6148         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6149         da[:,[1,3,4]]=-3.
6150         self.assertEqual([7., -3., 9., -3., -3., 12., -3., 14., -3., -3., 17., -3., 19., -3., -3., 22., -3., 24., -3., -3.],da.getValues())
6151         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6152         da2=DataArrayInt.New() ; da2.setValues([0,2,3],3,1)
6153         da[da2]=-7.
6154         self.assertEqual([-7., -7., -7., -7., -7., 12., 13., 14., 15., 16., -7., -7., -7., -7., -7., -7., -7., -7., -7., -7.],da.getValues())
6155         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6156         da[da2,-2:]=-7
6157         self.assertEqual([7., 8., 9., -7., -7., 12., 13., 14., 15., 16., 17., 18., 19., -7., -7., 22., 23., 24., -7., -7.],da.getValues())
6158         # Let's test with DAI right hand side
6159         da1=DataArrayDouble.New()
6160         da1.setValues([25,26,27,125,126,127],2,3)
6161         #
6162         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6163         da[-2:,1:4]=da1
6164         self.assertEqual([7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 25., 26., 27., 21., 22., 125., 126., 127., 26.],da.getValues())
6165         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6166         da[1:,3]=[225.,226.,227.]
6167         self.assertEqual([7., 8., 9., 10., 11., 12., 13., 14., 225., 16., 17., 18., 19., 226., 21., 22., 23., 24., 227., 26.],da.getValues())
6168         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6169         da[1,2:]=[225,226,227]
6170         self.assertEqual([7., 8., 9., 10., 11., 12., 13., 225., 226., 227., 17., 18., 19., 20., 21., 22., 23., 24., 25., 26.],da.getValues())
6171         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6172         da[da2,-2:]=[88,99,1010,1111,1212,1313]
6173         self.assertEqual([7., 8., 9., 88., 99., 12., 13., 14., 15., 16., 17., 18., 19., 1010., 1111., 22., 23., 24., 1212., 1313.],da.getValues())
6174         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6175         da3=DataArrayDouble.New(); da3.setValues([88,99,1010,1111,1212,1313],3,2)
6176         da[da2,-2:]=da3
6177         self.assertEqual([7., 8., 9., 88., 99., 12., 13., 14., 15., 16., 17., 18., 19., 1010., 1111., 22., 23., 24., 1212., 1313.],da.getValues())
6178         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6179         da[da2,[0,2]]=da3
6180         self.assertEqual([88., 8., 99., 10., 11., 12., 13., 14., 15., 16., 1010., 18., 1111., 20., 21., 1212., 23., 1313., 25., 26.],da.getValues())
6181         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6182         da[da2,0:3:2]=da3
6183         self.assertEqual([88., 8., 99., 10., 11., 12., 13., 14., 15., 16., 1010., 18., 1111., 20., 21., 1212., 23., 1313., 25., 26.],da.getValues())
6184         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
6185         da[da2,0:3:2]=-8.
6186         self.assertEqual([-8., 8., -8., 10., 11., 12., 13., 14., 15., 16., -8., 18., -8., 20., 21., -8., 23., -8., 25., 26.],da.getValues())
6187         pass
6188
6189     def testSwigDADOp(self):
6190         da=DataArrayDouble.New()
6191         da.alloc(12,1)
6192         da.iota(7.)
6193         da1=DataArrayDouble.New()
6194         da1.alloc(12,1)
6195         da1.iota(8.)
6196         da2=da+da1
6197         self.assertEqual([15., 17., 19., 21., 23., 25., 27., 29., 31., 33., 35., 37.],da2.getValues())
6198         da2=da+3
6199         da3=3+da
6200         self.assertTrue(da2.isEqual(da3,1e-12))
6201         da2=da-1.
6202         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())
6203         da2=1-da
6204         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())
6205         da2=da*3
6206         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())
6207         da2=3.*da
6208         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())
6209         da2=da*da1
6210         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())
6211         da2=da/4.
6212         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())
6213         da3=4./da
6214         da4=da3*da2
6215         self.assertTrue(da4.isUniform(1.,1e-12))
6216         st1=da.getHiddenCppPointer()
6217         da+=1
6218         st2=da.getHiddenCppPointer()
6219         self.assertEqual(st1,st2)
6220         self.assertTrue(da.isEqual(da1,1e-12))
6221         da-=8
6222         st2=da.getHiddenCppPointer()
6223         self.assertEqual(st1,st2)
6224         self.assertEqual(range(12),da.getValues())
6225         da+=da1
6226         st2=da.getHiddenCppPointer()
6227         self.assertEqual(st1,st2)
6228         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())
6229         da*=0.5
6230         st2=da.getHiddenCppPointer()
6231         self.assertEqual(st1,st2)
6232         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())
6233         da*=da1
6234         st2=da.getHiddenCppPointer()
6235         self.assertEqual(st1,st2)
6236         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())
6237         da/=da1
6238         self.assertEqual(st1,st2)
6239         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())
6240         da/=2
6241         st2=da.getHiddenCppPointer()
6242         self.assertEqual(st1,st2)
6243         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())
6244         da.rearrange(3)
6245         da5=DataArrayDouble.New()
6246         da5.setValues([5.,4.,3.,2.],4,1)
6247         da*=da5 # it works with unmathing number of compo
6248         st2=da.getHiddenCppPointer()
6249         self.assertEqual(st1,st2)
6250         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())
6251         #
6252         da.alloc(30,1)
6253         da.iota(7.)
6254         da.rearrange(3)
6255         ids=DataArrayInt.New()
6256         ids.setValues([3,4,7],3,1)
6257         da[ids,:]=[5.,8.,9.]
6258         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())
6259         #
6260         da.rearrange(1) ; da.iota(7) ; da.rearrange(3)
6261         da[ids,[1,2]]=[5,8]
6262         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())
6263         pass
6264
6265     def testSwigDAIOp(self):
6266         da=DataArrayInt.New()
6267         da.alloc(12,1)
6268         da.iota(7)
6269         da1=DataArrayInt.New()
6270         da1.alloc(12,1)
6271         da1.iota(8)
6272         da2=da+da1
6273         self.assertEqual([15,17,19,21,23,25,27,29,31,33,35,37],da2.getValues())
6274         da2=da+3
6275         da3=3+da
6276         self.assertTrue(da2.isEqual(da3))
6277         da2=da-1
6278         self.assertEqual([6,7,8,9,10,11,12,13,14,15,16,17],da2.getValues())
6279         da2=1-da
6280         self.assertEqual([-6,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17],da2.getValues())
6281         da2=da*3
6282         self.assertEqual([21,24,27,30,33,36,39,42,45,48,51,54.0],da2.getValues())
6283         da2=3*da
6284         self.assertEqual([21,24,27,30,33,36,39,42,45,48,51,54.0],da2.getValues())
6285         da2=da*da1
6286         self.assertEqual([56,72,90,110,132,156,182,210,240,272,306,342.0],da2.getValues())
6287         da2=da/4
6288         self.assertEqual([1,2,2,2,2,3,3,3,3,4,4,4],da2.getValues())
6289         da3=4/da
6290         da4=da3*da2
6291         self.assertTrue(da4.isUniform(0))
6292         st1=da.getHiddenCppPointer()
6293         da+=1
6294         st2=da.getHiddenCppPointer()
6295         self.assertEqual(st1,st2)
6296         self.assertTrue(da.isEqual(da1))
6297         da-=8
6298         st2=da.getHiddenCppPointer()
6299         self.assertEqual(st1,st2)
6300         self.assertEqual(range(12),da.getValues())
6301         da+=da1
6302         st2=da.getHiddenCppPointer()
6303         self.assertEqual(st1,st2)
6304         self.assertEqual([8,10,12,14,16,18,20,22,24,26,28,30],da.getValues())
6305         da/=2
6306         st2=da.getHiddenCppPointer()
6307         self.assertEqual(st1,st2)
6308         self.assertEqual([4,5,6,7,8,9,10,11,12,13,14,15],da.getValues())
6309         da*=da1
6310         st2=da.getHiddenCppPointer()
6311         self.assertEqual(st1,st2)
6312         self.assertEqual([32,45,60,77,96,117,140,165,192,221,252,285],da.getValues())
6313         da/=da1
6314         self.assertEqual(st1,st2)
6315         self.assertEqual([4,5,6,7,8,9,10,11,12,13,14,15],da.getValues())
6316         da/=2
6317         st2=da.getHiddenCppPointer()
6318         self.assertEqual(st1,st2)
6319         self.assertEqual([2,2, 3,3, 4,4, 5,5, 6,6, 7,7],da.getValues())
6320         da.rearrange(3)
6321         da5=DataArrayInt.New()
6322         da5.setValues([5,4,3,2],4,1)
6323         da*=da5 # it works with unmathing number of compo
6324         st2=da.getHiddenCppPointer()
6325         self.assertEqual(st1,st2)
6326         self.assertEqual([10,10, 15,12,16,16,15,15, 18,12,14,14],da.getValues())
6327         da%=6
6328         st2=da.getHiddenCppPointer()
6329         self.assertEqual(st1,st2)
6330         self.assertEqual([4,4,3,0,4,4,3,3,0,0,2,2],da.getValues())
6331         #
6332         da.alloc(30,1)
6333         da.iota(7)
6334         da.rearrange(3)
6335         ids=DataArrayInt.New()
6336         ids.setValues([3,4,7],3,1)
6337         da[ids,:]=[5,8,9]
6338         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())
6339         #
6340         da.rearrange(1) ; da.iota(7) ; da.rearrange(3)
6341         da[ids,[1,2]]=[5,8]
6342         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())
6343         pass
6344
6345     def testSwigDAIOp2(self):
6346         da=DataArrayInt.New()
6347         st=da.getHiddenCppPointer()
6348         da.alloc(10,3)
6349         da.rearrange(1)
6350         da.iota(0)
6351         da.rearrange(3)
6352         da[:,1]+=4
6353         da[-2:,2]+=10
6354         da[-2:,2]+=10
6355         da[:,2]+=da[:,0]
6356         da[da[0],:]=7
6357         self.assertEqual(st,da.getHiddenCppPointer())
6358         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])
6359         pass
6360
6361     def testSwigDAIOp3(self):
6362         da=DataArrayInt.New()
6363         self.assertRaises(InterpKernelException,da.__len__)
6364         self.assertRaises(InterpKernelException,da.__int__)
6365         for elt in da:
6366             self.assertTrue(False)
6367             pass
6368         da.alloc(12,3)
6369         da.rearrange(1) ; da.fillWithZero()
6370         l1=list(da)
6371         self.assertEqual(36,len(da));
6372         da.rearrange(3)
6373         tmp=da[0]
6374         self.assertRaises(InterpKernelException,tmp.__int__)
6375         self.assertEqual(12,len(da));
6376         l=list(da)
6377         for elt in enumerate(l):
6378             elt[1][2]=elt[0]
6379             pass
6380         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]
6381         self.assertEqual(ref,da.getValues());
6382         da.rearrange(1)
6383         l=[int(elt) for elt in l1]
6384         self.assertEqual(ref,da.getValues());
6385         self.assertEqual(11,int(da[-1:]))
6386         pass
6387
6388     def testSwigDADOp3(self):
6389         da=DataArrayDouble.New()
6390         self.assertRaises(InterpKernelException,da.__len__)
6391         self.assertRaises(InterpKernelException,da.__float__)
6392         for elt in da:
6393             self.assertTrue(False)
6394             pass
6395         da.alloc(12,3)
6396         da.rearrange(1) ; da.fillWithZero()
6397         l1=list(da)
6398         self.assertEqual(36,len(da));
6399         da.rearrange(3)
6400         tmp=da[0]
6401         self.assertRaises(InterpKernelException,tmp.__float__)
6402         self.assertEqual(12,len(da));
6403         l=list(da)
6404         for elt in enumerate(l):
6405             elt[1][2]=elt[0]
6406             pass
6407         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.]
6408         self.assertEqual(ref,da.getValues());
6409         da.rearrange(1)
6410         l=[float(elt) for elt in l1]
6411         self.assertEqual(ref,da.getValues());
6412         self.assertEqual(11.,float(da[-1:]))
6413         pass
6414
6415     def testSwigDataArrayIntIterator1(self):
6416         da=DataArrayInt.New()
6417         da.alloc(12,1)
6418         da.iota(2)
6419         da.rearrange(3)
6420         # __getitem__ testing
6421         li=[]
6422         for it in da:
6423             li+=it[1:]
6424             pass
6425         self.assertEqual([3, 4, 6, 7, 9, 10, 12, 13],li)
6426         li=[]
6427         for it in da:
6428             li+=[it[-1]]
6429             pass
6430         self.assertEqual([4, 7, 10, 13],li)
6431         li=[]
6432         for it in da:
6433             li+=it[[2,1,0]]
6434             pass
6435         self.assertEqual([4, 3, 2, 7, 6, 5, 10, 9, 8, 13, 12, 11],li)
6436         # __setitem__ testing
6437         da3=da.deepCpy()
6438         da2=DataArrayInt.New()
6439         da2.alloc(12,1)
6440         da2.iota(2002)
6441         da2.rearrange(3)
6442         it2=da2.__iter__()
6443         i=0
6444         for it in da:
6445             pt=it2.next()
6446             it[:]=pt
6447             pass
6448         self.assertTrue(da.isEqual(da2))
6449         da=da3
6450         da3=da.deepCpy()
6451         #
6452         for it in da:
6453             it[:]=5
6454             pass
6455         da.rearrange(1)
6456         self.assertTrue(da.isUniform(5))
6457         da=da3
6458         da3=da.deepCpy()
6459         #
6460         for it in da:
6461             it[:]=[8,9,12]
6462             pass
6463         self.assertEqual([8, 9, 12, 8, 9, 12, 8, 9, 12, 8, 9, 12],da.getValues())
6464         da=da3
6465         da3=da.deepCpy()
6466         #
6467         for it in da:
6468             it[2]=[7]
6469             pass
6470         self.assertEqual([2, 3, 7, 5, 6, 7, 8, 9, 7, 11, 12, 7],da.getValues())
6471         pass
6472
6473     def testSwigDataArrayDoubleIterator1(self):
6474         da=DataArrayDouble.New()
6475         da.alloc(12,1)
6476         da.iota(2)
6477         da.rearrange(3)
6478         # __getitem__ testing
6479         li=[]
6480         for it in da:
6481             li+=it[1:]
6482             pass
6483         self.assertEqual([3, 4, 6, 7, 9, 10, 12, 13],li)
6484         li=[]
6485         for it in da:
6486             li+=[it[-1]]
6487             pass
6488         self.assertEqual([4, 7, 10, 13],li)
6489         li=[]
6490         for it in da:
6491             li+=it[[2,1,0]]
6492             pass
6493         self.assertEqual([4, 3, 2, 7, 6, 5, 10, 9, 8, 13, 12, 11],li)
6494         # __setitem__ testing
6495         da3=da.deepCpy()
6496         da2=DataArrayDouble.New()
6497         da2.alloc(12,1)
6498         da2.iota(2002)
6499         da2.rearrange(3)
6500         it2=da2.__iter__()
6501         i=0
6502         for it in da:
6503             pt=it2.next()
6504             it[:]=pt
6505             pass
6506         self.assertTrue(da.isEqual(da2,1e-12))
6507         da=da3
6508         da3=da.deepCpy()
6509         #
6510         for it in da:
6511             it[:]=5
6512             pass
6513         da.rearrange(1)
6514         self.assertTrue(da.isUniform(5,1e-12))
6515         da=da3
6516         da3=da.deepCpy()
6517         #
6518         for it in da:
6519             it[:]=[8,9,12]
6520             pass
6521         self.assertEqual([8, 9, 12, 8, 9, 12, 8, 9, 12, 8, 9, 12],da.getValues())
6522         da=da3
6523         da3=da.deepCpy()
6524         #
6525         for it in da:
6526             it[2]=[7]
6527             pass
6528         self.assertEqual([2, 3, 7, 5, 6, 7, 8, 9, 7, 11, 12, 7],da.getValues())
6529         pass
6530
6531     def testSwigUMeshIterator1(self):
6532         m=MEDCouplingDataForTest.build2DTargetMesh_1()
6533         li1=[]
6534         li2=[]
6535         for cell in m:
6536             li1+=cell.getAllConn()[1:]
6537             li2+=[cell.getType()]
6538             pass
6539         self.assertEqual(li1,[0, 3, 4, 1, 1, 4, 2, 4, 5, 2, 6, 7, 4, 3, 7, 8, 5, 4])
6540         self.assertEqual(li2,[4, 3, 3, 4, 4])
6541         pass
6542
6543     def testSwigUMeshIterator2(self):
6544         m=MEDCouplingDataForTest.build2DTargetMesh_1()
6545         self.assertRaises(InterpKernelException,m.cellsByType);
6546         m.rearrange2ConsecutiveCellTypes()
6547         li1=[]
6548         li2=[]
6549         li3=[]
6550         for cellsByType in m.cellsByType():
6551             li1.append(cellsByType.getType())
6552             li2.append(cellsByType.getNumberOfElems())
6553             temp=[]
6554             for cell in cellsByType:
6555                 t=[None,None]
6556                 t[0]=cell.getType()
6557                 t[1]=cell.getAllConn()[1:]
6558                 temp.append(t)
6559                 pass
6560             li3.append(temp)
6561             pass
6562         self.assertEqual(li1,[4, 3])
6563         self.assertEqual(li2,[3, 2])
6564         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)]]])
6565         pass
6566
6567     def testDAIAggregateMulti1(self):
6568         a=DataArrayInt.New()
6569         a.setValues(range(4),2,2)
6570         a.setName("aa")
6571         b=DataArrayInt.New()
6572         b.setValues(range(6),3,2)
6573         c=DataArrayInt.Aggregate([a,b])
6574         self.assertEqual(range(4)+range(6),c.getValues())
6575         self.assertEqual("aa",c.getName())
6576         self.assertEqual(5,c.getNumberOfTuples())
6577         self.assertEqual(2,c.getNumberOfComponents())
6578         pass
6579
6580     def testMergeUMeshes2(self):
6581         m1=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
6582         m2=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
6583         m3=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
6584         #
6585         vec1=[0,2,3]
6586         m2_2=m2.buildPartOfMySelf(vec1,False);
6587         vec2=[1,1]
6588         m3_2=m3.buildPartOfMySelf(vec2,False);
6589         #
6590         ms=[m1,m2_2,m3_2];
6591         #
6592         self.assertRaises(InterpKernelException,MEDCouplingUMesh.MergeUMeshes,ms+[None]);
6593         self.assertRaises(InterpKernelException,MEDCouplingUMesh.MergeUMeshes,ms+[3.4])
6594         m4=MEDCouplingUMesh.MergeUMeshes(ms);
6595         m4.checkCoherency();
6596         self.assertEqual(10,m4.getNumberOfCells());
6597         self.assertEqual(20,m4.getNumberOfNodes());
6598         self.assertEqual(45,m4.getMeshLength());
6599         m4bis=MEDCouplingMesh.MergeMeshes(ms);
6600         self.assertTrue(m4.isEqual(m4bis,1e-12))
6601         del m4bis
6602         #
6603         vec3=[0,1,2,3,4]
6604         m4_1=m4.buildPartOfMySelf(vec3,False);
6605         m4_1.setName(m1.getName());
6606         self.assertTrue(m4_1.isEqual(m1,1e-12));
6607         #
6608         vec4=[5,6,7]
6609         m4_2=m4.buildPartOfMySelf(vec4,False);
6610         cellCor,nodeCor=m4_2.checkGeoEquivalWith(m2_2,10,1e-12);
6611         #
6612         vec5=[8,9]
6613         m4_3=m4.buildPartOfMySelf(vec5,False);
6614         self.assertEqual(2,m4_3.getNumberOfCells());
6615         self.assertEqual(3,m4_3.getNumberOfNodes());
6616         m3_2.zipCoords();
6617         m4_3.setName(m3_2.getName());
6618         self.assertTrue(m4_3.isEqual(m3_2,1e-12));
6619         #
6620         pass
6621
6622     def testBuild0DMeshFromCoords1(self):
6623         sourceCoords=[-0.3,-0.3,0., 0.7,-0.3,0., -0.3,0.7,0., 0.7,0.7,0.]
6624         coo=DataArrayDouble.New();
6625         coo.setValues(sourceCoords,4,3);
6626         coo.setName("My0D");
6627         m=MEDCouplingUMesh.Build0DMeshFromCoords(coo);
6628         m.checkCoherency();
6629         self.assertEqual(4,m.getNumberOfNodes());
6630         self.assertEqual(4,m.getNumberOfCells());
6631         self.assertEqual(3,m.getSpaceDimension());
6632         self.assertEqual(0,m.getMeshDimension());
6633         types1=m.getAllGeoTypes();
6634         self.assertEqual([NORM_POINT1],types1);
6635         for i in xrange(4):
6636             conn=m.getNodeIdsOfCell(i);
6637             self.assertEqual([i],conn);
6638             self.assertTrue(NORM_POINT1==m.getTypeOfCell(i));
6639             pass
6640         self.assertEqual(m.getName(),"My0D");
6641         pass
6642
6643     def testDescriptionInMeshTimeUnit1(self):
6644         text1="totoTTEDD";
6645         m=MEDCouplingDataForTest.build2DTargetMesh_1();
6646         m.setDescription(text1);
6647         self.assertEqual(m.getDescription(),text1);
6648         m2=m.deepCpy();
6649         self.assertTrue(m.isEqual(m2,1e-12));
6650         self.assertEqual(m2.getDescription(),text1);
6651         m2.setDescription("ggg");
6652         self.assertTrue(not m.isEqual(m2,1e-12));
6653         #
6654         f=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
6655         f.setTimeUnit(text1);
6656         self.assertEqual(f.getTimeUnit(),text1);
6657         f2=f.deepCpy();
6658         self.assertEqual(f2.getTimeUnit(),text1);
6659         #
6660         pass
6661
6662     def testMultiFields1(self):
6663         mfs=MEDCouplingDataForTest.buildMultiFields_1();
6664         ms=mfs.getMeshes();
6665         dms,refs=mfs.getDifferentMeshes()
6666         das=mfs.getArrays();
6667         das2,refs2=mfs.getDifferentArrays()
6668         self.assertEqual(5,len(mfs.getFields()))
6669         self.assertEqual(1,len(mfs.getFields()[0].getArrays()));
6670         self.assertEqual(2,len(mfs.getFields()[1].getArrays()));
6671         self.assertEqual(1,len(mfs.getFields()[2].getArrays()));
6672         self.assertEqual(1,len(mfs.getFields()[3].getArrays()));
6673         self.assertEqual(1,len(mfs.getFields()[4].getArrays()));
6674         self.assertEqual(5,len(ms));
6675         self.assertEqual(2,len(dms));
6676         self.assertEqual(6,len(das));
6677         self.assertEqual(5,len(das2));
6678         mfs2=mfs.deepCpy();
6679         self.assertTrue(mfs.isEqual(mfs2,1e-12,1e-12))
6680         pass
6681
6682     def testFieldOverTime1(self):
6683         fs=MEDCouplingDataForTest.buildMultiFields_2();
6684         self.assertRaises(InterpKernelException,MEDCouplingFieldOverTime.New,fs);
6685         f4bis=fs[4].buildNewTimeReprFromThis(ONE_TIME,False);
6686         fs[4]=f4bis;
6687         self.assertRaises(InterpKernelException,MEDCouplingFieldOverTime.New,fs);
6688         f4bis.setTime(2.7,20,21);
6689         fot=MEDCouplingFieldOverTime.New(fs);
6690         dt=fot.getDefinitionTimeZone();
6691         hs=dt.getHotSpotsTime();
6692         self.assertEqual(6,len(hs));
6693         expected1=[0.2,0.7,1.2,1.35,1.7,2.7]
6694         for i in xrange(6):
6695             self.assertAlmostEqual(expected1[i],hs[i],12);
6696             pass
6697         meshId,arrId,arrIdInField,fieldId=dt.getIdsOnTimeRight(0.2);
6698         self.assertEqual(0,meshId);
6699         self.assertEqual(0,arrId);
6700         self.assertEqual(0,arrIdInField);
6701         self.assertEqual(0,fieldId);
6702         #
6703         meshId,arrId,arrIdInField,fieldId=dt.getIdsOnTimeRight(0.7);
6704         self.assertEqual(0,meshId);
6705         self.assertEqual(1,arrId);
6706         self.assertEqual(0,arrIdInField);
6707         self.assertEqual(1,fieldId);
6708         #
6709         meshId,arrId,arrIdInField,fieldId=dt.getIdsOnTimeLeft(1.2);#**** WARNING left here
6710         self.assertEqual(0,meshId);
6711         self.assertEqual(2,arrId);
6712         self.assertEqual(1,arrIdInField);
6713         self.assertEqual(1,fieldId);
6714         #
6715         meshId,arrId,arrIdInField,fieldId=dt.getIdsOnTimeRight(1.2);#**** WARNING right again here
6716         self.assertEqual(1,meshId);
6717         self.assertEqual(3,arrId);
6718         self.assertEqual(0,arrIdInField);
6719         self.assertEqual(2,fieldId);
6720         #
6721         meshId,arrId,arrIdInField,fieldId=dt.getIdsOnTimeRight(1.35);
6722         self.assertEqual(1,meshId);
6723         self.assertEqual(3,arrId);
6724         self.assertEqual(0,arrIdInField);
6725         self.assertEqual(2,fieldId);
6726         #
6727         meshId,arrId,arrIdInField,fieldId=dt.getIdsOnTimeRight(1.7);
6728         self.assertEqual(0,meshId);
6729         self.assertEqual(3,arrId);
6730         self.assertEqual(0,arrIdInField);
6731         self.assertEqual(3,fieldId);
6732         #
6733         meshId,arrId,arrIdInField,fieldId=dt.getIdsOnTimeRight(2.7);
6734         self.assertEqual(1,meshId);
6735         self.assertEqual(4,arrId);
6736         self.assertEqual(0,arrIdInField);
6737         self.assertEqual(4,fieldId);
6738         #
6739         dt2=MEDCouplingDefinitionTime();
6740         self.assertTrue(not dt2.isEqual(dt));
6741         dt2.assign(dt);
6742         dt2.assign(dt);#to check memory management
6743         self.assertTrue(dt2.isEqual(dt));
6744         #
6745         dt3=MEDCouplingDefinitionTime();
6746         #
6747         pass
6748
6749     def testDAICheckAndPreparePermutation1(self):
6750         vals1=[9,10,0,6,4,11,3,7];
6751         expect1=[5,6,0,3,2,7,1,4];
6752         vals2=[9,10,0,6,10,11,3,7];
6753         da=DataArrayInt.New();
6754         da.setValues(vals1,8,1);
6755         da2=da.checkAndPreparePermutation();
6756         self.assertEqual(8,da2.getNumberOfTuples());
6757         self.assertEqual(1,da2.getNumberOfComponents());
6758         for i in xrange(8):
6759             self.assertEqual(expect1[i],da2.getIJ(i,0));
6760             pass
6761         #
6762         da=DataArrayInt.New();
6763         da.alloc(8,1);
6764         da.iota(0);
6765         da2=da.checkAndPreparePermutation();
6766         self.assertEqual(8,da2.getNumberOfTuples());
6767         self.assertEqual(1,da2.getNumberOfComponents());
6768         self.assertTrue(da2.isIdentity());
6769         #
6770         da=DataArrayInt.New();
6771         da.alloc(8,1);
6772         da.setValues(vals2,8,1);
6773         self.assertRaises(InterpKernelException,da.checkAndPreparePermutation);
6774         pass
6775
6776     def testDAIChangeSurjectiveFormat1(self):
6777         vals1=[0,3,2,3,2,2,1,2]
6778         expected1=[0,1,2,6,8]
6779         expected2=[0,  6,  2,4,5,7,  1,3]
6780         da=DataArrayInt.New();
6781         da.setValues(vals1,8,1);
6782         #
6783         da2,da2I=da.changeSurjectiveFormat(4);
6784         self.assertEqual(5,da2I.getNumberOfTuples());
6785         self.assertEqual(8,da2.getNumberOfTuples());
6786         self.assertEqual(expected1,da2I.getValues());
6787         self.assertEqual(expected2,da2.getValues());
6788         #
6789         self.assertRaises(InterpKernelException,da.changeSurjectiveFormat,3);
6790         #
6791         pass
6792
6793     def testUMeshGetCellIdsLyingOnNodes1(self):
6794         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
6795         nodeIds1=[1,2,3,4,6]
6796         nodeIds2=[6,7]
6797         da=m.getCellIdsLyingOnNodes(nodeIds1,True);
6798         self.assertEqual(1,da.getNumberOfTuples());
6799         self.assertEqual(1,da.getNumberOfComponents());
6800         self.assertEqual(1,da.getIJ(0,0));
6801         da2=DataArrayInt.New()
6802         da2.setValues(nodeIds2,2,1)
6803         da=m.getCellIdsLyingOnNodes(da2,False);
6804         self.assertEqual(2,da.getNumberOfTuples());
6805         self.assertEqual(1,da.getNumberOfComponents());
6806         self.assertEqual(3,da.getIJ(0,0));
6807         self.assertEqual(4,da.getIJ(1,0));
6808         pass
6809
6810     def testUMeshFindCellIdsOnBoundary1(self):
6811         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
6812         da5=m.findCellIdsOnBoundary();
6813         self.assertEqual(5,da5.getNumberOfTuples());
6814         self.assertTrue(da5.isIdentity());
6815         pass
6816
6817     def testMeshSetTime1(self):
6818         m1=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
6819         m2=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
6820         #
6821         self.assertTrue(m1.isEqual(m2,1e-12));
6822         m1.setTime(3.14,6,7);
6823         tmp3,tmp1,tmp2=m1.getTime();
6824         self.assertEqual(6,tmp1);
6825         self.assertEqual(7,tmp2);
6826         self.assertAlmostEqual(3.14,tmp3,12);
6827         self.assertTrue(not m1.isEqual(m2,1e-12));
6828         m2.setTime(3.14,6,7);
6829         self.assertTrue(m1.isEqual(m2,1e-12));
6830         m1.setTimeUnit("ms");
6831         self.assertTrue(m1.getTimeUnit()=="ms");
6832         m1.setTimeUnit("us");
6833         self.assertTrue(m1.getTimeUnit()=="us");
6834         self.assertTrue(not m1.isEqual(m2,1e-12));
6835         m2.setTimeUnit("us");
6836         self.assertTrue(m1.isEqual(m2,1e-12));
6837         m2.setTime(3.14,6,8);
6838         self.assertTrue(not m1.isEqual(m2,1e-12));
6839         m2.setTime(3.14,7,7);
6840         self.assertTrue(not m1.isEqual(m2,1e-12));
6841         m2.setTime(3.15,6,7);
6842         self.assertTrue(not m1.isEqual(m2,1e-12));
6843         #
6844         m1.setTime(10.34,55,12);
6845         m3=m1.deepCpy();
6846         self.assertTrue(m1.isEqual(m3,1e-12));
6847         tmp3,tmp1,tmp2=m3.getTime();
6848         self.assertEqual(55,tmp1);
6849         self.assertEqual(12,tmp2);
6850         self.assertAlmostEqual(10.34,tmp3,12);
6851         #
6852         # testing CMesh
6853         coo1=[0.,1.,2.,3.5]
6854         a=DataArrayDouble.New();
6855         a.setValues(coo1,4,1);
6856         b=MEDCouplingCMesh.New();
6857         b.setCoordsAt(0,a);
6858         #
6859         b.setTime(5.67,8,100);
6860         tmp3,tmp1,tmp2=b.getTime();
6861         self.assertEqual(8,tmp1);
6862         self.assertEqual(100,tmp2);
6863         self.assertAlmostEqual(5.67,tmp3,12);
6864         c=b.deepCpy();
6865         self.assertTrue(c.isEqual(b,1e-12));
6866         tmp3,tmp1,tmp2=c.getTime();
6867         self.assertEqual(8,tmp1);
6868         self.assertEqual(100,tmp2);
6869         self.assertAlmostEqual(5.67,tmp3,12);
6870         pass
6871
6872     def testApplyFuncTwo1(self):
6873         m1=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
6874         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
6875         f1.setMesh(m1);
6876         #
6877         vals=[1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.,5.,15.,25.]
6878         da=DataArrayDouble.New();
6879         da.setValues(vals,5,3);
6880         f1.setArray(da);
6881         #
6882         self.assertRaises(InterpKernelException,da.applyFunc2,1,"y+z");
6883         da.setInfoOnComponent(0,"x [m]");
6884         da.setInfoOnComponent(1,"y [mm]");
6885         da.setInfoOnComponent(2,"z [km]");
6886         
6887         self.assertRaises(InterpKernelException, da.applyFunc2, 1, "x+y+zz+zzz");
6888         self.assertRaises(InterpKernelException, da.applyFunc2, 1, "toto(x+y)");
6889         self.assertRaises(InterpKernelException, da.applyFunc2, 1, "x/0");
6890         
6891         da2=da.applyFunc2(1,"y+z");
6892         self.assertEqual(1,da2.getNumberOfComponents());
6893         self.assertEqual(5,da2.getNumberOfTuples());
6894         expected1=[32.,34.,36.,38.,40.]
6895         for i in xrange(5):
6896             self.assertAlmostEqual(expected1[i],da2.getIJ(0,i),12);
6897             pass
6898         da2=da.applyFunc(1,"y+z");
6899         expected2=[12.,14.,16.,18.,20.]
6900         for i in xrange(5):
6901             self.assertAlmostEqual(expected2[i],da2.getIJ(0,i),12);
6902             pass
6903         #
6904         self.assertEqual(3,f1.getNumberOfComponents());
6905         self.assertEqual(5,f1.getNumberOfTuples());
6906         f1.applyFunc2(1,"y+z");
6907         self.assertEqual(1,f1.getNumberOfComponents());
6908         self.assertEqual(5,f1.getNumberOfTuples());
6909         for i in xrange(5):
6910             self.assertAlmostEqual(expected1[i],f1.getArray().getIJ(0,i),12);
6911             pass
6912         #
6913         pass
6914
6915     def testApplyFuncThree1(self):
6916         m1=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
6917         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
6918         f1.setMesh(m1);
6919         #
6920         vals=[1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.,5.,15.,25.]
6921         da=DataArrayDouble.New();
6922         da.setValues(vals,5,3);
6923         f1.setArray(da);
6924         #
6925         vs=3*[None];
6926         vs[0]="x"; vs[1]="Y"; vs[2]="z";
6927         self.assertRaises(InterpKernelException, da.applyFunc3, 1, vs, "y+z");
6928         self.assertRaises(InterpKernelException, da.applyFunc3, 1, vs, "x+Y+z+zz+zzz");
6929         self.assertRaises(InterpKernelException, da.applyFunc3, 1, vs, "x/0");
6930         vs[1]="y";
6931         da2=da.applyFunc3(1,vs,"y+z");
6932         expected1=[32.,34.,36.,38.,40.]
6933         for i in xrange(5):
6934             self.assertAlmostEqual(expected1[i],da2.getIJ(0,i),12);
6935             pass
6936         self.assertRaises(InterpKernelException, da.applyFunc3, 1, ["x","y","z","a"],"x+a")
6937         f1.setArray(da);
6938         self.assertEqual(3,f1.getNumberOfComponents());
6939         self.assertEqual(5,f1.getNumberOfTuples());
6940         f1.applyFunc3(1,vs,"y+z");
6941         self.assertEqual(1,f1.getNumberOfComponents());
6942         self.assertEqual(5,f1.getNumberOfTuples());
6943         for i in xrange(5):
6944             self.assertAlmostEqual(expected1[i],f1.getArray().getIJ(0,i),12);
6945             pass
6946         pass
6947
6948     def testFillFromAnalyticTwo1(self):
6949         m1=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
6950         m1.setTime(3.4,5,6); m1.setTimeUnit("us");
6951         self.assertRaises(InterpKernelException,m1.fillFromAnalytic2,ON_NODES,1,"y+z");
6952         m1.getCoords().setInfoOnComponent(0,"x [m]");
6953         m1.getCoords().setInfoOnComponent(1,"y");
6954         m1.getCoords().setInfoOnComponent(2,"z");
6955         f1=m1.fillFromAnalytic2(ON_NODES,1,"y+z");
6956         self.assertAlmostEqual(3.4,f1.getTime()[0],12) ; self.assertEqual(5,f1.getTime()[1]) ; self.assertEqual(6,f1.getTime()[2])
6957         self.assertEqual("us",f1.getTimeUnit())
6958         self.assertEqual(1,f1.getNumberOfComponents());
6959         self.assertEqual(9,f1.getNumberOfTuples());
6960         expected1=[0.2, 0.7, 1.2, 0.7, 1.2, 1.7, 1.2, 1.7, 2.2]
6961         for i in xrange(9):
6962             self.assertAlmostEqual(expected1[i],f1.getArray().getIJ(0,i),12);
6963             pass
6964         pass
6965
6966     def testFillFromAnalyticThree1(self):
6967         m1=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
6968         m1.setTime(3.4,5,6); m1.setTimeUnit("us");
6969         vs=3*[None];
6970         vs[0]="x"; vs[1]="Y"; vs[2]="z";
6971         self.assertRaises(InterpKernelException,m1.fillFromAnalytic3,ON_NODES,1,vs,"y+z");
6972         vs[1]="y";
6973         f1=m1.fillFromAnalytic3(ON_NODES,1,vs,"y+z");
6974         self.assertAlmostEqual(3.4,f1.getTime()[0],12) ; self.assertEqual(5,f1.getTime()[1]) ; self.assertEqual(6,f1.getTime()[2])
6975         self.assertEqual("us",f1.getTimeUnit())
6976         self.assertEqual(1,f1.getNumberOfComponents());
6977         self.assertEqual(9,f1.getNumberOfTuples());
6978         expected1=[0.2, 0.7, 1.2, 0.7, 1.2, 1.7, 1.2, 1.7, 2.2]
6979         for i in xrange(9):
6980             self.assertAlmostEqual(expected1[i],f1.getArray().getIJ(0,i),12);
6981             pass
6982         pass
6983
6984     def testDAUnitVar1(self):
6985         da=DataArrayDouble.New();
6986         da.alloc(1,3);
6987         da.setInfoOnComponent(0,"XPS [m]");
6988         st1=da.getVarOnComponent(0);
6989         self.assertTrue(st1=="XPS");
6990         st2=da.getUnitOnComponent(0);
6991         self.assertTrue(st2=="m");
6992         #
6993         da.setInfoOnComponent(0,"XPS         [m]");
6994         st1=da.getVarOnComponent(0);
6995         self.assertTrue(st1=="XPS");
6996         st2=da.getUnitOnComponent(0);
6997         self.assertTrue(st2=="m");
6998         #
6999         da.setInfoOnComponent(0,"XPP         [m]");
7000         st1=da.getVarOnComponent(0);
7001         self.assertTrue(st1=="XPP");
7002         st2=da.getUnitOnComponent(0);
7003         self.assertTrue(st2=="m");
7004         #
7005         da.setInfoOnComponent(0,"XPP kdep  kefer   [ m  ]");
7006         st1=da.getVarOnComponent(0);
7007         self.assertTrue(st1=="XPP kdep  kefer");
7008         st2=da.getUnitOnComponent(0);
7009         self.assertTrue(st2==" m  ");
7010         #
7011         da.setInfoOnComponent(0,"     XPP k[  dep  k]efer   [ m^ 2/s^3*kJ  ]");
7012         st1=da.getVarOnComponent(0);
7013         self.assertTrue(st1=="     XPP k[  dep  k]efer");
7014         st2=da.getUnitOnComponent(0);
7015         self.assertTrue(st2==" m^ 2/s^3*kJ  ");
7016         #
7017         da.setInfoOnComponent(0,"     XPP kefer   ");
7018         st1=da.getVarOnComponent(0);
7019         self.assertTrue(st1=="     XPP kefer   ");
7020         st2=da.getUnitOnComponent(0);
7021         self.assertTrue(st2=="");
7022         #
7023         da.setInfoOnComponent(0,"temperature( bof)");
7024         st1=da.getVarOnComponent(0);
7025         self.assertTrue(st1=="temperature( bof)");
7026         st2=da.getUnitOnComponent(0);
7027         self.assertTrue(st2=="");
7028         #
7029         da.setInfoOnComponent(0,"kkk [m]");
7030         da.setInfoOnComponent(1,"ppp   [m^2/kJ]");
7031         da.setInfoOnComponent(2,"abcde   [MW/s]");
7032         #
7033         vs=da.getVarsOnComponent();
7034         self.assertEqual(3,len(vs));
7035         self.assertTrue(vs[0]=="kkk");
7036         self.assertTrue(vs[1]=="ppp");
7037         self.assertTrue(vs[2]=="abcde");
7038         vs=da.getUnitsOnComponent();
7039         self.assertEqual(3,len(vs));
7040         self.assertTrue(vs[0]=="m");
7041         self.assertTrue(vs[1]=="m^2/kJ");
7042         self.assertTrue(vs[2]=="MW/s");
7043         pass
7044
7045     def testGaussCoordinates1(self):
7046         #Testing 1D cell types
7047         m1=MEDCouplingDataForTest.build1DMultiTypes_1();
7048         f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME);
7049         f.setMesh(m1);
7050         wg1=[0.3];
7051         gsCoo1=[0.2];
7052         refCoo1=[-1.0,1.0];
7053         f.setGaussLocalizationOnType(NORM_SEG2,refCoo1,gsCoo1,wg1);
7054         wg2=wg1;
7055         gsCoo2=[0.2];
7056         refCoo2=[-1.0,1.0,0.0];
7057         f.setGaussLocalizationOnType(NORM_SEG3,refCoo2,gsCoo2,wg2);
7058         #
7059         resToTest=f.getLocalizationOfDiscr();
7060         self.assertEqual(3,resToTest.getNumberOfComponents());
7061         self.assertEqual(2,resToTest.getNumberOfTuples());
7062         expected1=[0.6,0.6,0.6, 0.6,0.6,0.6]
7063         for i in xrange(6):
7064             self.assertAlmostEqual(expected1[i],resToTest.getIJ(0,i),14);
7065             pass
7066         #
7067         #Testing 2D cell types
7068         m2=MEDCouplingDataForTest.build2DMultiTypes_1();
7069         f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME);
7070         f.setMesh(m2);
7071         wg3=[0.3,0.3];
7072         tria3CooGauss=[ 0.1, 0.8, 0.2, 0.7 ]
7073         gsCoo3=tria3CooGauss
7074         tria3CooRef=[ 0.0, 0.0, 1.0 , 0.0, 0.0, 1.0 ]
7075         refCoo3=tria3CooRef;
7076         f.setGaussLocalizationOnType(NORM_TRI3,refCoo3,gsCoo3,wg3);
7077         wg4=[0.3,0.3,0.3];
7078         tria6CooGauss=[ 0.3, 0.2, 0.2, 0.1, 0.2, 0.4 ]
7079         gsCoo4=tria6CooGauss;
7080         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]
7081         refCoo4=tria6CooRef;
7082         f.setGaussLocalizationOnType(NORM_TRI6,refCoo4,gsCoo4,wg4);
7083         wg5=[0.3,0.3,0.3,0.3];
7084         quad4CooGauss=[ 0.3, 0.2, 0.2, 0.1, 0.2, 0.4, 0.15, 0.27 ]
7085         gsCoo5=quad4CooGauss;
7086         quad4CooRef=[-1.0, 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0]
7087         refCoo5=quad4CooRef;
7088         f.setGaussLocalizationOnType(NORM_QUAD4,refCoo5,gsCoo5,wg5);
7089         wg6=[0.3,0.3,0.3,0.3];
7090         quad8CooGauss=[ 0.34, 0.16, 0.21, 0.3, 0.23, 0.4, 0.14, 0.37 ]
7091         gsCoo6=quad8CooGauss;
7092         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]
7093         refCoo6=quad8CooRef;
7094         f.setGaussLocalizationOnType(NORM_QUAD8,refCoo6,gsCoo6,wg6);
7095         #
7096         resToTest=f.getLocalizationOfDiscr();
7097         self.assertEqual(3,resToTest.getNumberOfComponents());
7098         self.assertEqual(13,resToTest.getNumberOfTuples());#2+3+4+4 gauss points for resp TRI3,TRI6,QUAD4,QUAD8
7099         expected2=[5.1,1.55,0.0, 4.7,1.65,0.0,
7100                    2.32,1.52,0.0, 1.6,1.32,0.0, 3.52,1.26,0.0,#TRI6
7101                    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
7102                    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
7103         for i in xrange(39):
7104             self.assertAlmostEqual(expected2[i],resToTest.getIJ(0,i),14);
7105             pass
7106         #
7107         #Testing 3D cell types
7108         m3=MEDCouplingDataForTest.build3DMultiTypes_1();
7109         f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME);
7110         f.setMesh(m3);
7111         #
7112         wg7=[0.3];
7113         tetra4CooGauss=[0.34, 0.16, 0.21]
7114         gsCoo7=tetra4CooGauss;
7115         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]
7116         refCoo7=tetra4CooRef;
7117         f.setGaussLocalizationOnType(NORM_TETRA4,refCoo7,gsCoo7,wg7);
7118         wg8=[0.3];
7119         tetra10CooGauss=[0.2, 0.3, 0.1]
7120         gsCoo8=tetra10CooGauss;
7121         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]
7122         refCoo8=tetra10CooRef;
7123         f.setGaussLocalizationOnType(NORM_TETRA10,refCoo8,gsCoo8,wg8);
7124         wg9=[0.3];
7125         pyra5CooGauss=[0.2, 0.3, 0.1]
7126         gsCoo9=pyra5CooGauss;
7127         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]
7128         refCoo9=pyra5CooRef;
7129         f.setGaussLocalizationOnType(NORM_PYRA5,refCoo9,gsCoo9,wg9);
7130         wg10=[0.3];
7131         pyra13CooGauss=[0.1, 0.2, 0.7]
7132         gsCoo10=pyra13CooGauss;
7133         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]
7134         refCoo10=pyra13CooRef;
7135         f.setGaussLocalizationOnType(NORM_PYRA13,refCoo10,gsCoo10,wg10);
7136         wg11=[0.3];
7137         penta6CooGauss=[0.2, 0.3, 0.1]
7138         gsCoo11=penta6CooGauss;
7139         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]
7140         refCoo11=penta6CooRef;
7141         f.setGaussLocalizationOnType(NORM_PENTA6,refCoo11,gsCoo11,wg11);
7142         wg12=[0.3];
7143         penta15CooGauss=[0.2, 0.3,0.15]
7144         gsCoo12=penta15CooGauss;
7145         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]
7146         refCoo12=penta15CooRef;
7147         f.setGaussLocalizationOnType(NORM_PENTA15,refCoo12,gsCoo12,wg12);
7148         wg13=[0.3];
7149         hexa8CooGauss=[0.2,0.3,0.15]
7150         gsCoo13=hexa8CooGauss;
7151         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]
7152         refCoo13=hexa8CooRef;
7153         f.setGaussLocalizationOnType(NORM_HEXA8,refCoo13,gsCoo13,wg13);
7154         wg14=[0.3];
7155         hexa20CooGauss=[0.11,0.3,0.55]
7156         gsCoo14=hexa20CooGauss;
7157         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]
7158         refCoo14=hexa20CooRef;
7159         f.setGaussLocalizationOnType(NORM_HEXA20,refCoo14,gsCoo14,wg14);
7160         #
7161         resToTest=f.getLocalizationOfDiscr();
7162         self.assertEqual(3,resToTest.getNumberOfComponents());
7163         self.assertEqual(8,resToTest.getNumberOfTuples());#2+3+4+4 gauss points for resp TRI3,TRI6,QUAD4,QUAD8
7164         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]
7165         for i in xrange(24):
7166             self.assertAlmostEqual(expected3[i],resToTest.getIJ(0,i),14);
7167             pass
7168         #
7169         pass
7170
7171     def testP2Localization1(self):
7172         m=MEDCouplingUMesh.New("testP2",2);
7173         coords=[0.,2.,3.5,0.,4.5,1.5,1.2,0.32,3.4,1.,2.1,2.4]
7174         conn=[0,1,2,3,4,5]
7175         coo=DataArrayDouble.New();
7176         coo.setValues(coords,6,2);
7177         m.setCoords(coo);
7178         m.allocateCells(1);
7179         m.insertNextCell(NORM_TRI6,6,conn[0:6])
7180         m.finishInsertingCells();
7181         #
7182         f=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME);
7183         f.setMesh(m);
7184         da=DataArrayDouble.New();
7185         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]
7186         da.setValues(vals1,6,3);
7187         f.setArray(da);
7188         #
7189         loc=[2.27,1.3]
7190         locs=f.getValueOnMulti(loc);
7191         expected1=[6.0921164547752236, 7.1921164547752232, 8.2921164547752255]
7192         for i in xrange(3):
7193             self.assertAlmostEqual(expected1[i],locs.getIJ(0,i),12);
7194             pass
7195         pass
7196
7197     def testP2Localization2(self):
7198         m=MEDCouplingUMesh.New("testP2_2",3);
7199         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]
7200         conn=[0,1,2,3,4,5,6,7,8,9]
7201         coo=DataArrayDouble.New();
7202         coo.setValues(coords,10,3);
7203         m.setCoords(coo);
7204         m.allocateCells(1);
7205         m.insertNextCell(NORM_TETRA10,10,conn[0:10])
7206         m.finishInsertingCells();
7207         #
7208         f=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME);
7209         f.setMesh(m);
7210         da=DataArrayDouble.New();
7211         vals1=[1.1,2.1,3.1,4.1,5.2,6.2,7.2,8.2,9.2,10.2]
7212         da.setValues(vals1,10,1);
7213         f.setArray(da);
7214         #
7215         loc=[0.64637931739890486, -0.16185896817550552, 0.22678966365273748]
7216         locs=f.getValueOnMulti(loc);
7217         expected1=[10.0844021968047]
7218         for i in xrange(1):
7219             self.assertAlmostEqual(expected1[i],locs.getIJ(0,i),12);
7220             pass
7221         pass
7222
7223     def testGetValueOn2(self):
7224         m=MEDCouplingDataForTest.build2DTargetMesh_1();
7225         f=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
7226         f.setMesh(m);
7227         arr=DataArrayDouble.New();
7228         nbOfCells=m.getNumberOfCells();
7229         f.setArray(arr);
7230         values1=[7.,107.,10007.,8.,108.,10008.,9.,109.,10009.,10.,110.,10010.,11.,111.,10011.]
7231         arr.setValues(values1,nbOfCells,3);
7232         loc=[-0.05,-0.05, 0.55,-0.25, 0.55,0.15, -0.05,0.45, 0.45,0.45]
7233         f.checkCoherency();
7234         locs=f.getValueOnMulti(loc);
7235         self.assertEqual(5,locs.getNumberOfTuples());
7236         self.assertEqual(3,locs.getNumberOfComponents());
7237         for j in xrange(15):
7238             self.assertAlmostEqual(values1[j],locs.getIJ(0,j),12);
7239             pass
7240         # Testing ON_NODES
7241         f=MEDCouplingFieldDouble.New(ON_NODES,NO_TIME);
7242         f.setMesh(m);
7243         arr=DataArrayDouble.New();
7244         nbOfNodes=m.getNumberOfNodes();
7245         f.setArray(arr);
7246         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.]
7247         arr.setValues(values2,nbOfNodes,3);
7248         loc2=[0.5432,-0.2432, 0.5478,0.1528, 0.5432,-0.2432, 0.5432,-0.2432]
7249         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]
7250         f.checkCoherency();
7251         loc3=DataArrayDouble.New()
7252         loc3.setValues(loc2,4,2);
7253         locs=f.getValueOnMulti(loc3);
7254         self.assertEqual(4,locs.getNumberOfTuples());
7255         self.assertEqual(3,locs.getNumberOfComponents());
7256         for i in xrange(12):
7257             self.assertAlmostEqual(expected2[i],locs.getIJ(0,i),12);
7258             pass
7259         #
7260         pass
7261
7262     def testDAIGetIdsNotEqual1(self):
7263         d=DataArrayInt.New();
7264         vals1=[2,3,5,6,8,5,5,6,1,-5]
7265         d.setValues(vals1,10,1);
7266         d2=d.getIdsNotEqual(5);
7267         self.assertEqual(7,d2.getNumberOfTuples());
7268         self.assertEqual(1,d2.getNumberOfComponents());
7269         expected1=[0,1,3,4,7,8,9]
7270         for i in xrange(7):
7271             self.assertEqual(expected1[i],d2.getIJ(0,i));
7272             pass
7273         d.rearrange(2);
7274         self.assertRaises(InterpKernelException,d.getIdsNotEqual,5);
7275         vals2=[-4,5,6]
7276         vals3=vals2;
7277         d.rearrange(1);
7278         d3=d.getIdsNotEqualList(vals3);
7279         self.assertEqual(5,d3.getNumberOfTuples());
7280         self.assertEqual(1,d3.getNumberOfComponents());
7281         expected2=[0,1,4,8,9]
7282         for i in xrange(5):
7283             self.assertEqual(expected2[i],d3.getIJ(0,i));
7284             pass
7285         pass
7286
7287     def testDAIComputeOffsets1(self):
7288         d=DataArrayInt.New();
7289         vals1=[3,5,1,2,0,8]
7290         expected1=[0,3,8,9,11,11]
7291         d.setValues(vals1,6,1);
7292         d.computeOffsets();
7293         self.assertEqual(6,d.getNumberOfTuples());
7294         self.assertEqual(1,d.getNumberOfComponents());
7295         for i in xrange(6):
7296             self.assertEqual(expected1[i],d.getIJ(0,i));
7297             pass
7298         pass
7299
7300     def testUMeshHexagonPrism1(self):
7301         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,
7302                 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];
7303         conn=[1,2,3,4,5,0,7,8,9,10,11,6]
7304         mesh=MEDCouplingUMesh.New("MyFirstHexagonalPrism",3);
7305         coo=DataArrayDouble.New();
7306         coo.setValues(coords,12,3);
7307         mesh.setCoords(coo);
7308         mesh.allocateCells(1);
7309         mesh.insertNextCell(NORM_HEXGP12,12,conn[0:12])
7310         mesh.finishInsertingCells();
7311         #
7312         mesh.checkCoherency();
7313         vols=mesh.getMeasureField(False);
7314         self.assertEqual(1,vols.getNumberOfTuples());
7315         self.assertEqual(1,vols.getNumberOfComponents());
7316         self.assertAlmostEqual(-5.196152422706632,vols.getIJ(0,0),12);
7317         bary=mesh.getBarycenterAndOwner();
7318         self.assertEqual(1,bary.getNumberOfTuples());
7319         self.assertEqual(3,bary.getNumberOfComponents());
7320         expected1=[0.,0.,1.]
7321         for i in xrange(3):
7322             self.assertAlmostEqual(expected1[i],bary.getIJ(0,i),12);
7323             pass
7324         d1=DataArrayInt.New();
7325         d2=DataArrayInt.New();
7326         d3=DataArrayInt.New();
7327         d4=DataArrayInt.New();
7328         m2=mesh.buildDescendingConnectivity(d1,d2,d3,d4);
7329         self.assertEqual(8,m2.getNumberOfCells());
7330         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]];
7331         expected2=[NORM_POLYGON, NORM_POLYGON, NORM_QUAD4, NORM_QUAD4, NORM_QUAD4, NORM_QUAD4, NORM_QUAD4, NORM_QUAD4];
7332         expected3=[6,6,4,4,4,4,4,4]
7333         for i in xrange(8):
7334             self.assertTrue(m2.getTypeOfCell(i)==expected2[i]);
7335             v=m2.getNodeIdsOfCell(i);
7336             self.assertTrue(len(v)==expected3[i]);
7337             self.assertEqual(expected4[i],v);
7338         #
7339         mesh.convertAllToPoly();
7340         self.assertTrue(NORM_POLYHED==mesh.getTypeOfCell(0));
7341         mesh.unPolyze();
7342         self.assertTrue(NORM_HEXGP12==mesh.getTypeOfCell(0));
7343         self.assertEqual(13,mesh.getMeshLength());
7344         #
7345         pass
7346
7347     def testDADCheckIsMonotonic(self):
7348         da=DataArrayDouble.New();
7349         da.setValues([-1.,1.01,2.03,6.],2,2);
7350         self.assertRaises(InterpKernelException,da.isMonotonic,True,1e-12);
7351         da.rearrange(1);
7352         self.assertTrue(da.isMonotonic(True,1e-12));
7353         da.checkMonotonic(True,1e-12);
7354         da.setIJ(2,0,6.1);
7355         self.assertTrue(not da.isMonotonic(True,1e-12));
7356         self.assertRaises(InterpKernelException,da.checkMonotonic,True,1e-12);
7357         da.setIJ(2,0,5.99);
7358         self.assertTrue(da.isMonotonic(True,1e-12));
7359         self.assertTrue(not da.isMonotonic(True,1e-1));
7360         pass
7361
7362     def testCheckCoherencyDeeper1(self):
7363         m=MEDCouplingDataForTest.build3DSourceMesh_1();
7364         m.checkCoherency();
7365         m.checkCoherency1();
7366         m.getNodalConnectivity().setIJ(8,0,-1);
7367         m.checkCoherency();
7368         self.assertRaises(InterpKernelException,m.checkCoherency1);
7369         m.getNodalConnectivity().setIJ(8,0,-6);
7370         m.checkCoherency();
7371         self.assertRaises(InterpKernelException,m.checkCoherency1);
7372         m.getNodalConnectivity().setIJ(8,0,9);#9>=NbOfNodes
7373         m.checkCoherency();
7374         self.assertRaises(InterpKernelException,m.checkCoherency1);
7375         m.getNodalConnectivity().setIJ(8,0,8);#OK
7376         m.checkCoherency();
7377         m.checkCoherency1();
7378         elts=[1,5]
7379         m.convertToPolyTypes(elts);
7380         m.checkCoherency();
7381         m.checkCoherency1();
7382         m.getNodalConnectivity().setIJ(2,0,9);#9>=NbOfNodes
7383         m.checkCoherency();
7384         self.assertRaises(InterpKernelException,m.checkCoherency1);
7385         m.getNodalConnectivity().setIJ(2,0,-3);
7386         m.checkCoherency();
7387         self.assertRaises(InterpKernelException,m.checkCoherency1);
7388         m.getNodalConnectivity().setIJ(2,0,-1);
7389         m.checkCoherency();
7390         self.assertRaises(InterpKernelException,m.checkCoherency1);#Throw because cell#0 is not a polyhedron
7391         m.getNodalConnectivity().setIJ(2,0,4);
7392         m.checkCoherency();
7393         m.checkCoherency1();
7394         m.getNodalConnectivity().setIJ(7,0,-1);
7395         m.checkCoherency();
7396         m.checkCoherency1();#OK because we are in polyhedron connec
7397         m.getNodalConnectivity().setIJ(36,0,14);
7398         m.checkCoherency();
7399         self.assertRaises(InterpKernelException,m.checkCoherency1);#Throw beacause now cell 5 is a TETRA4 (14) so mimatch of number index and static type.
7400         pass
7401
7402     def testUnPolyze2(self):
7403         m=MEDCouplingUMesh.New("jjj",3);
7404         coo=DataArrayDouble.New();
7405         coo.alloc(4,3);
7406         coo.rearrange(1);
7407         coo.iota(0);
7408         coo.rearrange(3);
7409         m.setCoords(coo);
7410         m.allocateCells(2);
7411         m.insertNextCell(NORM_TETRA4,4,[0,1,2,3]);
7412         m.insertNextCell(NORM_TETRA4,4,[0,1,2,3]);
7413         m.finishInsertingCells();
7414         m2=MEDCouplingUMesh.MergeUMeshesOnSameCoords(4*[m]);
7415         m2.convertToPolyTypes([2]);
7416         m2.unPolyze();
7417         self.assertEqual(NORM_TETRA4,m2.getTypeOfCell(2));
7418         self.assertEqual(40,m2.getMeshLength());
7419         temp2=m2.getNodeIdsOfCell(2);
7420         self.assertEqual(temp2,[0,1,2,3]);
7421         m2.checkCoherency1();
7422         m3=m2.deepCpy();
7423         m2.unPolyze();
7424         self.assertTrue(m3.isEqual(m2,1e-12));
7425         pass
7426
7427     def testDACpyFrom1(self):
7428         d=DataArrayDouble.New();
7429         d.alloc(12,1);
7430         d.iota(14.);
7431         d.rearrange(3);
7432         d.setName("Toto");
7433         d.setInfoOnComponent(0,"X [m]");
7434         d.setInfoOnComponent(1,"Y [m]");
7435         d.setInfoOnComponent(2,"Z [m]");
7436         #
7437         d1=DataArrayDouble.New();
7438         self.assertTrue(not d.isEqual(d1,1e-12));
7439         d1.cpyFrom(d);
7440         self.assertTrue(d.isEqual(d1,1e-12));
7441         d1.cpyFrom(d);
7442         self.assertTrue(d.isEqual(d1,1e-12));
7443         d1.rearrange(2);
7444         self.assertTrue(not d.isEqual(d1,1e-12));
7445         d1.cpyFrom(d);
7446         self.assertTrue(d.isEqual(d1,1e-12));
7447         #
7448         d2=d.convertToIntArr();
7449         d4=DataArrayInt.New();
7450         self.assertTrue(not d2.isEqual(d4));
7451         d4.cpyFrom(d2);
7452         self.assertTrue(d2.isEqual(d4));
7453         d4.cpyFrom(d2);
7454         self.assertTrue(d2.isEqual(d4));
7455         d4.rearrange(2);
7456         self.assertTrue(not d2.isEqual(d4));
7457         d4.cpyFrom(d2);
7458         self.assertTrue(d2.isEqual(d4));
7459         pass
7460
7461     def testDAITransformWithIndArr1(self):
7462         tab1=[17,18,22,19]
7463         tab2=[0,1,1,3,3,0,1,3,2,2,3,0]
7464         expected=[17,18,18,19,19,17,18,19,22,22,19,17]
7465         d=DataArrayInt.New();
7466         d.setValues(tab1,4,1);
7467         d1=DataArrayInt.New();
7468         d1.setValues(tab2,12,1);
7469         d2=d1[:]
7470         #
7471         d1.transformWithIndArr(d);
7472         self.assertEqual(12,d1.getNumberOfTuples());
7473         self.assertEqual(1,d1.getNumberOfComponents());
7474         for i in xrange(12):
7475             self.assertEqual(expected[i],d1.getIJ(i,0));
7476             pass
7477         #
7478         d1=d2
7479         d1.transformWithIndArr(tab1)
7480         self.assertEqual(12,d1.getNumberOfTuples());
7481         self.assertEqual(1,d1.getNumberOfComponents());
7482         for i in xrange(12):
7483             self.assertEqual(expected[i],d1.getIJ(i,0));
7484             pass
7485         pass
7486
7487     def testDAIBuildPermArrPerLevel1(self):
7488         arr=[2,0,1,1,0,1,2,0,1,1,0,0]
7489         expected1=[10,0,5,6,1,7,11,2,8,9,3,4]
7490         da=DataArrayInt.New();
7491         da.setValues(arr,12,1);
7492         da2=da.buildPermArrPerLevel();
7493         self.assertEqual(12,da2.getNumberOfTuples());
7494         self.assertEqual(1,da2.getNumberOfComponents());
7495         for i in xrange(12):
7496             self.assertEqual(expected1[i],da2.getIJ(i,0));
7497             pass
7498         pass
7499
7500     def testDAIOperations1(self):
7501         arr1=[-1,-2,4,7,3,2,6,6,4,3,0,1]
7502         da=DataArrayInt.New();
7503         da.setValues(arr1,4,3);
7504         da1=DataArrayInt.New();
7505         da1.alloc(12,1);
7506         da1.iota(2);
7507         self.assertRaises(InterpKernelException,DataArrayInt.Add,da,da1);#not same number of tuples/Components
7508         da1.rearrange(3);
7509         da2=DataArrayInt.Add(da,da1);
7510         self.assertEqual(4,da2.getNumberOfTuples());
7511         self.assertEqual(3,da2.getNumberOfComponents());
7512         expected1=[1,1,8,12,9,9,14,15,14,14,12,14]
7513         for i in xrange(12):
7514             self.assertEqual(expected1[i],da2.getIJ(0,i));
7515             pass
7516         da1.substractEqual(da);
7517         expected2=[3,5,0,-2,3,5,2,3,6,8,12,12]
7518         for i in xrange(12):
7519             self.assertEqual(expected2[i],da1.getIJ(0,i));
7520             pass
7521         da1.rearrange(1); da1.iota(2); da1.rearrange(3);
7522         da1.addEqual(da);
7523         for i in xrange(12):
7524             self.assertEqual(expected1[i],da1.getIJ(0,i));
7525             pass
7526         da1.rearrange(1); da1.iota(2); da1.rearrange(3);
7527         da2=DataArrayInt.Multiply(da,da1);
7528         self.assertEqual(4,da2.getNumberOfTuples());
7529         self.assertEqual(3,da2.getNumberOfComponents());
7530         expected3=[-2,-6,16,35,18,14,48,54,40,33,0,13]
7531         for i in xrange(12):
7532             self.assertEqual(expected3[i],da2.getIJ(0,i));
7533             pass
7534         da.divideEqual(da1);
7535         self.assertEqual(4,da.getNumberOfTuples());
7536         self.assertEqual(3,da.getNumberOfComponents());
7537         expected4=[0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]
7538         for i in xrange(12):
7539             self.assertEqual(expected4[i],da.getIJ(0,i));
7540             pass
7541         da.setValues(arr1,4,3);
7542         da1.multiplyEqual(da);
7543         self.assertEqual(4,da1.getNumberOfTuples());
7544         self.assertEqual(3,da1.getNumberOfComponents());
7545         for i in xrange(12):
7546             self.assertEqual(expected3[i],da1.getIJ(0,i));
7547             pass
7548         da1.rearrange(1); da1.iota(2); da1.rearrange(3);
7549         da2=DataArrayInt.Divide(da,da1);
7550         self.assertEqual(4,da2.getNumberOfTuples());
7551         self.assertEqual(3,da2.getNumberOfComponents());
7552         for i in xrange(12):
7553             self.assertEqual(expected4[i],da2.getIJ(0,i));
7554             pass
7555         da1.applyInv(321);
7556         self.assertEqual(4,da1.getNumberOfTuples());
7557         self.assertEqual(3,da1.getNumberOfComponents());
7558         expected5=[160,107,80,64,53,45,40,35,32,29,26,24]
7559         for i in xrange(12):
7560             self.assertEqual(expected5[i],da1.getIJ(0,i));
7561             pass
7562         da1.applyDivideBy(2);
7563         self.assertEqual(4,da1.getNumberOfTuples());
7564         self.assertEqual(3,da1.getNumberOfComponents());
7565         expected6=[80,53,40,32,26,22,20,17,16,14,13,12]
7566         for i in xrange(12):
7567             self.assertEqual(expected6[i],da1.getIJ(0,i));
7568             pass
7569         expected7=[3,4,5,4,5,1,6,3,2,0,6,5]
7570         da1.applyModulus(7);
7571         for i in xrange(12):
7572             self.assertEqual(expected7[i],da1.getIJ(0,i));
7573             pass
7574         da1.applyLin(1,1);
7575         expected8=[3,3,3,3,3,1,3,3,0,0,3,3]
7576         da1.applyRModulus(3);
7577         for i in xrange(12):
7578             self.assertEqual(expected8[i],da1.getIJ(0,i));
7579             pass
7580         pass
7581
7582     def testEmulateMEDMEMBDC1(self):
7583         m,m1=MEDCouplingDataForTest.buildPointe_1();
7584         m2,da1,da2,da3,da4,da5,da0=m.emulateMEDMEMBDC(m1)
7585         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]
7586         expected1=[1,32,29,23,41,36]
7587         self.assertEqual(47,da0.getNumberOfTuples());
7588         self.assertEqual(1,da0.getNumberOfComponents());
7589         for i in xrange(47):
7590             self.assertEqual(expected0[i],da0.getIJ(0,i));
7591             pass
7592         self.assertEqual(6,da5.getNumberOfTuples());
7593         self.assertEqual(1,da5.getNumberOfComponents());
7594         for i in xrange(6):
7595             self.assertEqual(expected1[i],da5.getIJ(0,i));
7596             pass
7597         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]
7598         self.assertEqual(70,da1.getNumberOfTuples());
7599         self.assertEqual(1,da1.getNumberOfComponents());
7600         for i in xrange(70):
7601             self.assertEqual(expected2[i],da1.getIJ(0,i));
7602             pass
7603         expected3=[0,4,8,12,16,20,24,28,32,36,40,44,48,53,58,64,70]
7604         self.assertEqual(17,da2.getNumberOfTuples());
7605         self.assertEqual(1,da2.getNumberOfComponents());
7606         for i in xrange(17):
7607             self.assertEqual(expected3[i],da2.getIJ(0,i));
7608             pass
7609         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]
7610         #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];
7611         self.assertEqual(48,da4.getNumberOfTuples());
7612         self.assertEqual(1,da4.getNumberOfComponents());
7613         for i in xrange(48):
7614             self.assertEqual(expected4[i],da4.getIJ(0,i));
7615             pass
7616         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]
7617         self.assertEqual(70,da3.getNumberOfTuples());
7618         self.assertEqual(1,da3.getNumberOfComponents());
7619         for i in xrange(70):
7620             self.assertEqual(expected5[i],da3.getIJ(0,i));
7621             pass
7622         pass
7623
7624     def testGetLevArrPerCellTypes1(self):
7625         m,m1=MEDCouplingDataForTest.buildPointe_1();
7626         m1,d0,d1,d2,d3=m.buildDescendingConnectivity();
7627         order=[NORM_TRI3,NORM_QUAD4];
7628         da0,da1=m1.getLevArrPerCellTypes(order);
7629         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]
7630         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]
7631         self.assertEqual(47,da0.getNumberOfTuples());
7632         self.assertEqual(1,da0.getNumberOfComponents());
7633         for i in xrange(47):
7634             self.assertEqual(expected0[i],da0.getIJ(0,i));
7635             pass
7636         self.assertEqual(2,da1.getNumberOfTuples());
7637         self.assertEqual(1,da1.getNumberOfComponents());
7638         self.assertEqual(36,da1.getIJ(0,0));#36 TRI3
7639         self.assertEqual(11,da1.getIJ(1,0));#11 QUAD4
7640         #
7641         da2=da0.buildPermArrPerLevel();
7642         #
7643         self.assertEqual(47,da2.getNumberOfTuples());
7644         self.assertEqual(1,da2.getNumberOfComponents());
7645         for i in xrange(47):
7646             self.assertEqual(expected1[i],da2.getIJ(0,i));
7647             pass
7648         pass
7649
7650     def testSortCellsInMEDFileFrmt1(self):
7651         m,m1=MEDCouplingDataForTest.buildPointe_1();
7652         m2=m.deepCpy()
7653         da=DataArrayInt.New()
7654         da.setValues([0,1,2,14,3,12,4,5,15,6,7,8,9,10,11,13],16,1)
7655         daa=da.invertArrayN2O2O2N(16)
7656         m.renumberCells(daa,False)
7657         da2=m.sortCellsInMEDFileFrmt()
7658         self.assertEqual(da2.getValues(),[0,1,2,14,3,12,4,5,15,6,7,8,9,10,11,13])
7659         self.assertTrue(m.isEqual(m2,1e-12))
7660         self.assertTrue(da.isEqual(da2))
7661         pass
7662
7663     def testBuildPartAndReduceNodes1(self):
7664         m=MEDCouplingDataForTest.build2DTargetMesh_1();
7665         arr=[1,0]
7666         m2,da=m.buildPartAndReduceNodes(arr);
7667         self.assertEqual(5,m2.getNumberOfNodes());
7668         self.assertEqual(2,m2.getNumberOfCells());
7669         f=m2.getMeasureField(True);
7670         self.assertAlmostEqual(0.125,f.getArray().getIJ(0,0),12);
7671         self.assertAlmostEqual(0.25,f.getArray().getIJ(1,0),12);
7672         #
7673         arr2=DataArrayInt.New()
7674         arr2.setValues(arr,2,1)
7675         m2,da=m.buildPartAndReduceNodes(arr2);
7676         self.assertEqual(5,m2.getNumberOfNodes());
7677         self.assertEqual(2,m2.getNumberOfCells());
7678         f=m2.getMeasureField(True);
7679         self.assertAlmostEqual(0.125,f.getArray().getIJ(0,0),12);
7680         self.assertAlmostEqual(0.25,f.getArray().getIJ(1,0),12);
7681         pass
7682
7683     def testDAITransformWithIndArrR1(self):
7684         tab1=[2,4,5,3,6,7]
7685         tab2=[-1,-1,0,1,2,3,4,5,-1,-1,-1,-1]
7686         expected=[0,3,1,2,4,5]
7687         d=DataArrayInt.New();
7688         d.setValues(tab1,6,1);
7689         d1=DataArrayInt.New();
7690         d1.setValues(tab2,12,1);
7691         d2=d1[:]
7692         #
7693         d3=d.transformWithIndArrR(d1);
7694         self.assertEqual(6,d3.getNumberOfTuples());
7695         self.assertEqual(1,d3.getNumberOfComponents());
7696         for i in xrange(6):
7697             self.assertEqual(expected[i],d3.getIJ(i,0));
7698             pass
7699         #
7700         d1=d2
7701         d3=d.transformWithIndArrR(tab2)
7702         self.assertEqual(6,d3.getNumberOfTuples());
7703         self.assertEqual(1,d3.getNumberOfComponents());
7704         for i in xrange(6):
7705             self.assertEqual(expected[i],d3.getIJ(i,0));
7706             pass
7707         pass
7708
7709     def testDAISplitByValueRange1(self):
7710         val1=[6,5,0,3,2,7,8,1,4]
7711         val2=[0,4,9]
7712         d=DataArrayInt.New();
7713         d.setValues(val1,9,1);
7714         e,f,g=d.splitByValueRange(val2);
7715         self.assertEqual(9,e.getNumberOfTuples());
7716         self.assertEqual(1,e.getNumberOfComponents());
7717         self.assertEqual(9,f.getNumberOfTuples());
7718         self.assertEqual(1,f.getNumberOfComponents());
7719         self.assertEqual(2,g.getNumberOfTuples());
7720         self.assertEqual(1,g.getNumberOfComponents());
7721         #
7722         expected1=[1,1,0,0,0,1,1,0,1]
7723         expected2=[2,1,0,3,2,3,4,1,0]
7724         for i in xrange(9):
7725             self.assertEqual(expected1[i],e.getIJ(i,0));
7726             self.assertEqual(expected2[i],f.getIJ(i,0));
7727             pass
7728         self.assertEqual(0,g.getIJ(0,0));
7729         self.assertEqual(1,g.getIJ(1,0));
7730         #
7731         d.setIJ(6,0,9);
7732         self.assertRaises(InterpKernelException,d.splitByValueRange,val2);
7733         pass
7734
7735     def testUMeshSplitProfilePerType1(self):
7736         val0=[2,0,1,3,4]
7737         m=MEDCouplingDataForTest.build2DTargetMesh_1();
7738         m.renumberCells(val0,False);
7739         #
7740         val1=[0,2,3]
7741         d=DataArrayInt.New();
7742         d.setValues(val1,3,1);
7743         d.setName("sup")
7744         code,idsInPflPerType,pfls=m.splitProfilePerType(d);
7745         self.assertEqual(2,len(code));
7746         self.assertEqual(2,len(idsInPflPerType));
7747         expected1=[[3,1,0], [4,2,1]]
7748         self.assertEqual(expected1,code)
7749         self.assertEqual(2,len(idsInPflPerType));
7750         self.assertEqual(1,idsInPflPerType[0].getNumberOfTuples());
7751         self.assertEqual(0,idsInPflPerType[0].getIJ(0,0));
7752         self.assertEqual(2,idsInPflPerType[1].getNumberOfTuples());
7753         self.assertEqual(1,idsInPflPerType[1].getIJ(0,0));
7754         self.assertEqual(2,idsInPflPerType[1].getIJ(1,0));
7755         #
7756         self.assertEqual(2,len(pfls));
7757         self.assertEqual("sup",pfls[0].getName())
7758         self.assertEqual(1,pfls[0].getNumberOfTuples());
7759         self.assertEqual(0,pfls[0].getIJ(0,0));
7760         self.assertEqual("sup",pfls[1].getName())
7761         self.assertEqual(2,pfls[1].getNumberOfTuples());
7762         self.assertEqual(0,pfls[1].getIJ(0,0));
7763         self.assertEqual(1,pfls[1].getIJ(1,0));
7764         #
7765         val2=[0,2,3,4]
7766         d=DataArrayInt.New();
7767         d.setValues(val2,4,1);
7768         code,idsInPflPerType,pfls=m.splitProfilePerType(d);
7769         self.assertEqual(2,len(code));
7770         self.assertEqual(2,len(idsInPflPerType));
7771         expected2=[[3,1,0], [4,3,-1]]
7772         self.assertEqual(expected2,code);
7773         self.assertEqual(2,len(idsInPflPerType));
7774         self.assertEqual(1,idsInPflPerType[0].getNumberOfTuples());
7775         self.assertEqual(0,idsInPflPerType[0].getIJ(0,0));
7776         self.assertEqual(3,idsInPflPerType[1].getNumberOfTuples());
7777         self.assertEqual(1,idsInPflPerType[1].getIJ(0,0));
7778         self.assertEqual(2,idsInPflPerType[1].getIJ(1,0));
7779         self.assertEqual(3,idsInPflPerType[1].getIJ(2,0));
7780         #
7781         self.assertEqual(1,len(pfls));
7782         self.assertEqual(1,pfls[0].getNumberOfTuples());
7783         self.assertEqual(0,pfls[0].getIJ(0,0));
7784         #
7785         val3=[1,0,2]
7786         d=DataArrayInt.New();
7787         d.setValues(val3,3,1);
7788         code,idsInPflPerType,pfls=m.splitProfilePerType(d);
7789         self.assertEqual(2,len(code));
7790         self.assertEqual(2,len(idsInPflPerType));
7791         expected3=[[3,2,0], [4,1,1]]
7792         self.assertEqual(expected3,code);
7793         self.assertEqual(2,len(idsInPflPerType));
7794         self.assertEqual(2,idsInPflPerType[0].getNumberOfTuples());
7795         self.assertEqual(0,idsInPflPerType[0].getIJ(0,0));
7796         self.assertEqual(1,idsInPflPerType[0].getIJ(1,0));
7797         self.assertEqual(1,idsInPflPerType[1].getNumberOfTuples());
7798         self.assertEqual(2,idsInPflPerType[1].getIJ(0,0));
7799         #
7800         self.assertEqual(2,len(pfls));
7801         self.assertEqual(2,pfls[0].getNumberOfTuples());
7802         self.assertEqual(1,pfls[0].getIJ(0,0));
7803         self.assertEqual(0,pfls[0].getIJ(1,0));
7804         self.assertEqual(0,pfls[1].getIJ(0,0));
7805         #
7806         val4=[3,4]
7807         d=DataArrayInt.New();
7808         d.setValues(val4,2,1);
7809         code,idsInPflPerType,pfls=m.splitProfilePerType(d);
7810         self.assertEqual(1,len(code));
7811         self.assertEqual(1,len(idsInPflPerType));
7812         expected4=[[4,2,0]]
7813         self.assertEqual(expected4,code);
7814         self.assertEqual(1,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         #
7819         self.assertEqual(1,len(pfls));
7820         self.assertEqual(2,pfls[0].getNumberOfTuples());
7821         self.assertEqual(1,pfls[0].getIJ(0,0));
7822         self.assertEqual(2,pfls[0].getIJ(1,0));
7823         pass
7824
7825     def testDAIBuildExplicitArrByRanges1(self):
7826         d=DataArrayInt.New();
7827         vals1=[0,2,3]
7828         d.setValues(vals1,3,1);
7829         e=DataArrayInt.New();
7830         vals2=[0,3,6,10,14,20]
7831         e.setValues(vals2,6,1);
7832         #
7833         f=d.buildExplicitArrByRanges(e);
7834         self.assertEqual(11,f.getNumberOfTuples());
7835         self.assertEqual(1,f.getNumberOfComponents());
7836         expected1=[0,1,2,6,7,8,9,10,11,12,13]
7837         for i in xrange(11):
7838             self.assertEqual(expected1[i],f.getIJ(i,0));
7839             pass
7840         pass
7841
7842     def testDAIComputeOffsets2(self):
7843         d=DataArrayInt.New();
7844         vals1=[3,5,1,2,0,8]
7845         expected1=[0,3,8,9,11,11,19]
7846         d.setValues(vals1,6,1);
7847         d.computeOffsets2();
7848         self.assertEqual(7,d.getNumberOfTuples());
7849         self.assertEqual(1,d.getNumberOfComponents());
7850         for i in xrange(7):
7851             self.assertEqual(expected1[i],d.getIJ(0,i));
7852             pass
7853         pass
7854
7855     def testMergeField3(self):
7856         m=MEDCouplingDataForTest.build2DTargetMesh_1();
7857         m.getCoords().setInfoOnComponent(0,"x [m]");
7858         m.getCoords().setInfoOnComponent(1,"z [km]");
7859         m.setName("m");
7860         m.setDescription("desc");
7861         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
7862         f1.setName("f1");
7863         f1.setMesh(m);
7864         arr=DataArrayDouble.New();
7865         arr.alloc(5,2);
7866         arr.setInfoOnComponent(0,"X [m]");
7867         arr.setInfoOnComponent(1,"YY [mm]");
7868         arr.fillWithValue(2.);
7869         f1.setArray(arr);
7870         #
7871         f2=MEDCouplingFieldDouble.MergeFields([f1]);
7872         self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
7873         #
7874         pass
7875     
7876     def testGetDistributionOfTypes1(self):
7877         m=MEDCouplingDataForTest.build2DTargetMesh_1();
7878         tab1=[2,0,1,3,4]
7879         self.assertRaises(InterpKernelException,m.getDistributionOfTypes);
7880         m.renumberCells(tab1,False);
7881         code=m.getDistributionOfTypes();
7882         self.assertEqual(2,len(code));
7883         self.assertEqual(3,code[0][0]);
7884         self.assertEqual(2,code[0][1]);
7885         self.assertEqual(-1,code[0][2]);
7886         self.assertEqual(4,code[1][0]);
7887         self.assertEqual(3,code[1][1]);
7888         self.assertEqual(-1,code[1][2]);
7889         pass
7890
7891     def testNorm2_1(self):
7892         m=MEDCouplingDataForTest.build2DTargetMesh_1();
7893         f=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
7894         f.setMesh(m);
7895         #
7896         d=DataArrayDouble.New();
7897         tab=[1.2,1.3,2.2,2.3,3.2,3.3,4.2,4.3,5.2,5.3]
7898         d.setValues(tab,5,2);
7899         f.setArray(d);
7900         f.checkCoherency();
7901         #
7902         self.assertAlmostEqual(11.209371079592289,f.norm2(),14);
7903         #
7904         pass
7905
7906     def testNormMax1(self):
7907         m=MEDCouplingDataForTest.build2DTargetMesh_1();
7908         f=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
7909         f.setMesh(m);
7910         #
7911         d=DataArrayDouble.New();
7912         tab=[2.3,-1.2,6.3,-7.8,2.9,7.7,2.1,0.,3.6,-7.6]
7913         d.setValues(tab,5,2);
7914         f.setArray(d);
7915         f.checkCoherency();
7916         #
7917         self.assertAlmostEqual(7.8,f.normMax(),14);
7918         #
7919         pass
7920
7921     def testFindAndCorrectBadOriented3DExtrudedCells1(self):
7922         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];
7923         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]
7924         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]
7925         invalidCells=[2,3,6,7]
7926         m=MEDCouplingUMesh.New("Example",3);
7927         coo=DataArrayDouble.New();
7928         coo.setValues(coords,38,3);
7929         m.setCoords(coo);
7930         m.allocateCells(8);
7931         m.insertNextCell(NORM_PENTA6,6,conn[0:6])
7932         m.insertNextCell(NORM_PENTA6,6,conn[6:12])
7933         m.insertNextCell(NORM_PENTA6,6,conn[12:18])
7934         m.insertNextCell(NORM_PENTA6,6,conn[18:24])
7935         m.insertNextCell(NORM_HEXA8,8,conn[24:32])
7936         m.insertNextCell(NORM_HEXA8,8,conn[32:40])
7937         m.insertNextCell(NORM_HEXA8,8,conn[40:48])
7938         m.insertNextCell(NORM_HEXA8,8,conn[48:56])
7939         m.finishInsertingCells();
7940         #
7941         v=m.findAndCorrectBadOriented3DExtrudedCells();
7942         self.assertEqual(4,len(v));
7943         self.assertEqual(v.getValues(),invalidCells);
7944         self.assertEqual(connExp,m.getNodalConnectivity().getValues());
7945         self.assertTrue(m.findAndCorrectBadOriented3DExtrudedCells().empty())
7946         #
7947         pass
7948
7949     def testConvertExtrudedPolyhedra1(self):
7950         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]
7951         m=MEDCouplingUMesh.New("Example",3);
7952         coo=DataArrayDouble.New();
7953         coo.alloc(73,3);
7954         coo.rearrange(1); coo.iota(0); coo.rearrange(3);
7955         m.setCoords(coo);
7956         m.allocateCells(9);
7957         m.insertNextCell(NORM_TETRA4,4,conn[0:4])
7958         m.insertNextCell(NORM_HEXA8,8,conn[4:12])
7959         m.insertNextCell(NORM_TETRA4,4,conn[12:16])
7960         m.insertNextCell(NORM_POLYHED,6,conn[16:22])
7961         m.insertNextCell(NORM_PENTA6,6,conn[22:28])
7962         m.insertNextCell(NORM_POLYHED,10,conn[28:38])
7963         m.insertNextCell(NORM_HEXA8,8,conn[38:46])
7964         m.insertNextCell(NORM_HEXGP12,12,conn[46:58])
7965         m.insertNextCell(NORM_POLYHED,14,conn[58:72])
7966         m.finishInsertingCells();
7967         #
7968         m.convertExtrudedPolyhedra();
7969         da=m.getNodalConnectivity();
7970         dai=m.getNodalConnectivityIndex();
7971         self.assertEqual(10,dai.getNbOfElems());
7972         self.assertEqual(159,da.getNbOfElems());
7973         #
7974         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];
7975         expected2=[0,5,14,19,42,49,86,95,108,159]
7976         self.assertEqual(expected1,da.getValues());
7977         self.assertEqual(expected2,dai.getValues());
7978         m.checkCoherency2()
7979         pass
7980
7981     def testNonRegressionCopyTinyStrings(self):
7982         m=MEDCouplingDataForTest.build2DTargetMesh_1()
7983         f1=m.getMeasureField(True)
7984         f1.getArray().setInfoOnComponent(0,"P [N/m^2]")
7985         bary=m.getBarycenterAndOwner()
7986         f2=f1.buildNewTimeReprFromThis(NO_TIME,False)
7987         f2.setArray(bary)
7988         self.assertRaises(InterpKernelException,f1.copyTinyAttrFrom,f2)
7989         pass
7990
7991     def testDaDSetPartOfValuesAdv1(self):
7992         tab1=[3.,4.,5., 13.,14.,15., 23.,24.,25., 33.,34.,35., 43.,44.,45., 53.,54.,55.]
7993         tab2=[6.,7.,8., 16.,17.,18., 26.,27.,28.]
7994         tab3=[4,1, 2,2, 3,0]
7995         a=DataArrayDouble.New();
7996         a.setValues(tab1,6,3);
7997         b=DataArrayDouble.New();
7998         b.setValues(tab2,3,3);
7999         c=DataArrayInt.New();
8000         c.setValues(tab3,3,2);
8001         #
8002         a.setPartOfValuesAdv(b,c);
8003         expected1=[3.,4.,5., 13.,14.,15., 26.,27.,28., 6.,7.,8., 16.,17.,18., 53.,54.,55.]
8004         self.assertEqual(expected1,a.getValues());
8005         pass
8006
8007     def testUMeshBuildSetInstanceFromThis1(self):
8008         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
8009         m2=m.buildSetInstanceFromThis(3);
8010         self.assertTrue(m.isEqual(m2,1e-12));
8011         #
8012         m=MEDCouplingUMesh.New("toto",2);
8013         m2=m.buildSetInstanceFromThis(3);
8014         self.assertEqual(0,m2.getNumberOfNodes());
8015         self.assertEqual(0,m2.getNumberOfCells());
8016         pass
8017
8018     def testUMeshMergeMeshesCVW1(self):
8019         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
8020         m2=MEDCouplingUMesh.New("toto",2);
8021         m3=MEDCouplingUMesh.MergeUMeshes([m,m2]);
8022         m3.setName(m.getName());
8023         self.assertTrue(m.isEqual(m3,1e-12));
8024         pass
8025     
8026     def testChangeUnderlyingMeshWithCMesh1(self):
8027         mesh=MEDCouplingCMesh.New();
8028         coordsX=DataArrayDouble.New();
8029         arrX=[ -1., 1., 2., 4. ]
8030         coordsX.setValues(arrX,4,1);
8031         coordsY=DataArrayDouble.New();
8032         arrY=[ -2., 2., 4., 8. ]
8033         coordsY.setValues(arrY,4,1);
8034         coordsZ=DataArrayDouble.New();
8035         arrZ=[ -3., 3., 6., 12. ]
8036         coordsZ.setValues(arrZ,4,1);
8037         mesh.setCoords(coordsX,coordsY,coordsZ);
8038         f=mesh.getMeasureField(True)
8039         mesh2=mesh.deepCpy()
8040         for myId in [0,1,2,10,11,12,20,21,22]:
8041             f=mesh.getMeasureField(True)
8042             f.changeUnderlyingMesh(mesh2,myId,1e-12);
8043             pass
8044         mesh2.setName("uuuu")
8045         for myId in [1,2,10,11,12,20,21,22]:
8046             f=mesh.getMeasureField(True)
8047             f.changeUnderlyingMesh(mesh2,myId,1e-12);
8048             pass
8049         pass
8050
8051     def testDADFindCommonTuples1(self):
8052         da=DataArrayDouble.New();
8053         # nbOftuples=1
8054         array1=[2.3,1.2,1.3,2.3,2.301,0.8]
8055         da.setValues(array1,6,1)
8056         c,cI=da.findCommonTuples(1e-2);
8057         expected1=[0,3,4]
8058         expected2=[0,3]
8059         self.assertEqual(3,c.getNbOfElems());
8060         self.assertEqual(2,cI.getNbOfElems());
8061         self.assertEqual(expected1,c.getValues())
8062         self.assertEqual(expected2,cI.getValues())
8063         c,cI=da.findCommonTuples(2e-1)
8064         expected3=[0,3,4,1,2]
8065         expected4=[0,3,5]
8066         self.assertEqual(5,c.getNbOfElems());
8067         self.assertEqual(3,cI.getNbOfElems());
8068         self.assertEqual(expected3,c.getValues())
8069         self.assertEqual(expected4,cI.getValues())
8070         # nbOftuples=2
8071         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]
8072         da.setValues(array2,6,2)
8073         c,cI=da.findCommonTuples(1e-2);
8074         self.assertEqual(3,c.getNbOfElems());
8075         self.assertEqual(2,cI.getNbOfElems());
8076         self.assertEqual(expected1,c.getValues())
8077         self.assertEqual(expected2,cI.getValues())
8078         c,cI=da.findCommonTuples(2e-1)
8079         self.assertEqual(5,c.getNbOfElems());
8080         self.assertEqual(3,cI.getNbOfElems());
8081         self.assertEqual(expected3,c.getValues())
8082         self.assertEqual(expected4,cI.getValues())
8083         # nbOftuples=3
8084         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]
8085         da.setValues(array3,6,3)
8086         c,cI=da.findCommonTuples(1e-2);
8087         self.assertEqual(3,c.getNbOfElems());
8088         self.assertEqual(2,cI.getNbOfElems());
8089         self.assertEqual(expected1,c.getValues())
8090         self.assertEqual(expected2,cI.getValues())
8091         c,cI=da.findCommonTuples(2e-1)
8092         self.assertEqual(5,c.getNbOfElems());
8093         self.assertEqual(3,cI.getNbOfElems());
8094         self.assertEqual(expected3,c.getValues())
8095         self.assertEqual(expected4,cI.getValues())
8096         # nbOftuples=1, no common groups
8097         array11=[2.3,1.2,1.3,2.4,2.5,0.8]
8098         da.setValues(array11,6,1)
8099         c,cI=da.findCommonTuples(1e-2);
8100         self.assertEqual(0,c.getNbOfElems());
8101         self.assertEqual(1,cI.getNbOfElems());
8102         self.assertEqual([0],cI.getValues())
8103         
8104         array12=[0.]*(6*5)
8105         da.setValues(array12,6,5) #bad NumberOfComponents
8106         self.assertRaises(InterpKernelException, da.findCommonTuples, 1e-2);
8107         pass
8108
8109     def testDABack1(self):
8110         da=DataArrayDouble.New();
8111         array1=[2.3,1.2,1.3,2.3,2.301,0.8]
8112         da.setValues(array1,6,1);
8113         self.assertAlmostEqual(0.8,da.back(),14);
8114         da.rearrange(2);
8115         self.assertRaises(InterpKernelException,da.back);
8116         da.alloc(0,1);
8117         self.assertRaises(InterpKernelException,da.back);
8118         #
8119         da=DataArrayInt.New();
8120         array2=[4,7,8,2]
8121         da.setValues(array2,4,1);
8122         self.assertEqual(2,da.back());
8123         da.rearrange(2);
8124         self.assertRaises(InterpKernelException,da.back);
8125         da.alloc(0,1);
8126         self.assertRaises(InterpKernelException,da.back);
8127         pass
8128
8129     def testDADGetDifferentValues1(self):
8130         da=DataArrayDouble.New();
8131         array1=[2.3,1.2,1.3,2.3,2.301,0.8]
8132         da.setValues(array1,6,1)
8133         #
8134         expected1=[2.301,1.2,1.3,0.8]
8135         dv=da.getDifferentValues(1e-2);
8136         self.assertEqual(4,dv.getNbOfElems());
8137         for i in xrange(4):
8138             self.assertAlmostEqual(expected1[i],dv.getIJ(i,0),14);
8139             pass
8140         #
8141         dv=da.getDifferentValues(2e-1);
8142         expected2=[2.301,1.3,0.8]
8143         self.assertEqual(3,dv.getNbOfElems());
8144         for i in xrange(3):
8145             self.assertAlmostEqual(expected2[i],dv.getIJ(i,0),14);
8146             pass
8147         pass
8148
8149     def testDAIBuildOld2NewArrayFromSurjectiveFormat2(self):
8150         arr=[0,3, 5,7,9]
8151         arrI=[0,2,5]
8152         a=DataArrayInt.New();
8153         a.setValues(arr,5,1);
8154         b=DataArrayInt.New();
8155         b.setValues(arrI,3,1);
8156         ret,newNbTuple=DataArrayInt.BuildOld2NewArrayFromSurjectiveFormat2(10,a,b);
8157         expected=[0,1,2,0,3,4,5,4,6,4]
8158         self.assertEqual(10,ret.getNbOfElems());
8159         self.assertEqual(7,newNbTuple);
8160         self.assertEqual(1,ret.getNumberOfComponents());
8161         self.assertEqual(expected,ret.getValues());
8162         self.assertRaises(InterpKernelException,DataArrayInt.BuildOld2NewArrayFromSurjectiveFormat2,9,a,b);
8163         pass
8164
8165     def testDADIReverse1(self):
8166         arr=[0,3,5,7,9,2]
8167         a=DataArrayInt.New();
8168         a.setValues(arr,6,1);
8169         self.assertEqual(2,a.back());
8170         a.reverse();
8171         for i in xrange(6):
8172             self.assertEqual(arr[5-i],a.getIJ(i,0));
8173             pass
8174         a.setValues(arr[:-1],5,1);
8175         a.reverse();
8176         for i in xrange(5):
8177             self.assertEqual(arr[4-i],a.getIJ(i,0));
8178             pass
8179         #
8180         arr2=[0.,3.,5.,7.,9.,2.]
8181         b=DataArrayDouble.New();
8182         b.setValues(arr2,6,1);
8183         b.reverse();
8184         for i in xrange(6):
8185             self.assertAlmostEqual(arr2[5-i],b.getIJ(i,0),14);
8186             pass
8187         b.setValues(arr2[:5],5,1);
8188         self.assertAlmostEqual(9.,b.back(),14)
8189         b.reverse();
8190         for i in xrange(5):
8191             self.assertAlmostEqual(arr2[4-i],b.getIJ(i,0),14);
8192             pass
8193         pass
8194
8195     def testGetNodeIdsInUse1(self):
8196         m0=MEDCouplingDataForTest.build2DTargetMesh_1();
8197         CellIds=[1,2]
8198         m1=m0.buildPartOfMySelf(CellIds,True);
8199         arr,newNbOfNodes=m1.getNodeIdsInUse();
8200         expected=[-1,0,1,-1,2,3,-1,-1,-1]
8201         self.assertEqual(4,newNbOfNodes);
8202         self.assertEqual(9,arr.getNbOfElems());
8203         self.assertEqual(expected,arr.getValues());
8204         arr2=arr.invertArrayO2N2N2O(newNbOfNodes);
8205         self.assertEqual(4,arr2.getNbOfElems());
8206         expected2=[1,2,4,5]
8207         self.assertEqual(expected2,arr2.getValues());
8208         pass
8209
8210     def testBuildDescendingConnec2(self):
8211         mesh=MEDCouplingDataForTest.build2DTargetMesh_1();
8212         #
8213         mesh2,desc,descIndx,revDesc,revDescIndx=mesh.buildDescendingConnectivity2();
8214         mesh2.checkCoherency();
8215         self.assertEqual(1,mesh2.getMeshDimension());
8216         self.assertEqual(13,mesh2.getNumberOfCells());
8217         self.assertEqual(14,revDescIndx.getNbOfElems()); self.assertEqual(14,revDescIndx.getNumberOfTuples());
8218         self.assertEqual(6,descIndx.getNbOfElems()); self.assertEqual(6,descIndx.getNumberOfTuples());
8219         self.assertEqual(18,desc.getNbOfElems()); self.assertEqual(18,desc.getNumberOfTuples());
8220         self.assertEqual(18,revDesc.getNbOfElems()); self.assertEqual(18,revDesc.getNumberOfTuples());
8221         expected1=[1,2,3,4,-3,5,6, 7,8,-5,9,10,-2,11, 12,13,-7,-10]
8222         self.assertEqual(expected1,desc.getValues());
8223         expected2=[0,4,7,10,14,18]
8224         self.assertEqual(expected2,descIndx.getValues());
8225         expected3=[0,1,3,5,6,8,9,11,12,13,15,16,17,18]
8226         self.assertEqual(expected3,revDescIndx.getValues());
8227         expected4=[0, 0,3, 0,1, 0, 1,2, 1, 2,4, 2, 3, 3,4, 3, 4, 4]
8228         self.assertEqual(expected4,revDesc.getValues());
8229         conn=mesh2.getNodalConnectivity();
8230         connIndex=mesh2.getNodalConnectivityIndex();
8231         expected5=[0,3,6,9,12,15,18,21,24,27,30,33,36,39]
8232         self.assertEqual(expected5,connIndex.getValues());
8233         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]
8234         self.assertEqual(expected6,conn.getValues());
8235         pass
8236
8237     def testIntersect2DMeshesTmp1(self):
8238         m1c=MEDCouplingCMesh.New();
8239         coordsX=DataArrayDouble.New();
8240         arrX=[ -1., 1., 2., 4. ]
8241         coordsX.setValues(arrX,4,1);
8242         m1c.setCoordsAt(0,coordsX);
8243         coordsY=DataArrayDouble.New();
8244         arrY=[ -2., 2., 4., 8. ]
8245         coordsY.setValues(arrY,4,1);
8246         m1c.setCoordsAt(1,coordsY);
8247         m1=m1c.buildUnstructured()
8248         m1bis=m1.buildPartOfMySelf([3,4,5],False)
8249         m2=m1.deepCpy()
8250         m2=m2.buildPartOfMySelf([0,1,2],False)
8251         m2.translate([0.5,0.5])
8252         #
8253         m3,d1,d2=MEDCouplingUMesh.Intersect2DMeshes(m1bis,m2,1e-10)
8254         expected1=[0,0,1,1,1,2,2,2]
8255         expected2=[0,-1,0,1,-1,1,2,-1]
8256         self.assertEqual(8,d1.getNumberOfTuples());
8257         self.assertEqual(8,d2.getNumberOfTuples());
8258         self.assertEqual(8,m3.getNumberOfCells());
8259         self.assertEqual(22,m3.getNumberOfNodes());
8260         self.assertEqual(2,m3.getSpaceDimension());
8261         self.assertEqual(expected1,d1.getValues());
8262         self.assertEqual(expected2,d2.getValues());
8263         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]
8264         expected4=[0,5,12,17,22,28,33,38,44]
8265         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]
8266         self.assertEqual(44,m3.getNodalConnectivity().getNumberOfTuples());
8267         self.assertEqual(9,m3.getNodalConnectivityIndex().getNumberOfTuples());
8268         self.assertEqual(expected3,m3.getNodalConnectivity().getValues());
8269         self.assertEqual(expected4,m3.getNodalConnectivityIndex().getValues());
8270         for i in xrange(44):
8271             self.assertAlmostEqual(expected5[i],m3.getCoords().getIJ(0,i),12);
8272             pass
8273         pass
8274
8275     def testFindNodesOnLine1(self):
8276         mesh=MEDCouplingDataForTest.build2DTargetMesh_1();
8277         pt=[-0.3,-0.3]
8278         pt2=[0.,0.,0.]
8279         pt3=[-0.3,0.,0.]
8280         vec=[0.,1.]
8281         vec2=[1.,0.,0.]
8282         vec3=[0.,1.,1.]
8283         expected1=[0,3,6]
8284         res=mesh.findNodesOnLine(pt,vec,1e-12);
8285         self.assertEqual(3,len(res));
8286         self.assertEqual(expected1,res.getValues());
8287         #
8288         mesh.changeSpaceDimension(3);
8289         mesh.rotate(pt2,vec2,pi/4.);
8290         res=mesh.findNodesOnLine(pt3,vec3,1e-12);
8291         self.assertEqual(3,len(res));
8292         self.assertEqual(expected1,res.getValues());
8293         pass
8294
8295     def testIntersect2DMeshesTmp2(self):
8296         m1c=MEDCouplingCMesh.New();
8297         coordsX1=DataArrayDouble.New();
8298         arrX1=[ 0., 1., 1.5, 2. ]
8299         coordsX1.setValues(arrX1,4,1);
8300         m1c.setCoordsAt(0,coordsX1);
8301         coordsY1=DataArrayDouble.New();
8302         arrY1=[ 0., 1.5, 3.]
8303         coordsY1.setValues(arrY1,3,1);
8304         m1c.setCoordsAt(1,coordsY1);
8305         m1=m1c.buildUnstructured();
8306         m2c=MEDCouplingCMesh.New();
8307         coordsX2=DataArrayDouble.New();
8308         arrX2=[ 0., 1., 2. ]
8309         coordsX2.setValues(arrX2,3,1);
8310         m2c.setCoordsAt(0,coordsX2);
8311         coordsY2=DataArrayDouble.New();
8312         arrY2=[ 0., 1., 3.]
8313         coordsY2.setValues(arrY2,3,1);
8314         m2c.setCoordsAt(1,coordsY2);
8315         m2=m2c.buildUnstructured();
8316         #
8317         m3,d1,d2=MEDCouplingUMesh.Intersect2DMeshes(m1,m2,1e-10)
8318         #
8319         expected1=[0,0,1,1,2,2,3,4,5]
8320         expected2=[0,2,1,3,1,3,2,3,3]
8321         self.assertEqual(9,d1.getNumberOfTuples());
8322         self.assertEqual(9,d2.getNumberOfTuples());
8323         self.assertEqual(9,m3.getNumberOfCells());
8324         self.assertEqual(22,m3.getNumberOfNodes());
8325         self.assertEqual(2,m3.getSpaceDimension());
8326         self.assertEqual(expected1,d1.getValues());
8327         self.assertEqual(expected2,d2.getValues());
8328         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]
8329         expected4=[0,5,10,15,20,25,30,35,40,45]
8330         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]
8331         self.assertEqual(45,m3.getNodalConnectivity().getNumberOfTuples());
8332         self.assertEqual(10,m3.getNodalConnectivityIndex().getNumberOfTuples());
8333         self.assertEqual(expected3,m3.getNodalConnectivity().getValues());
8334         self.assertEqual(expected4,m3.getNodalConnectivityIndex().getValues());
8335         for i in xrange(44):
8336             self.assertAlmostEqual(expected5[i],m3.getCoords().getIJ(0,i),12);
8337             pass
8338         pass
8339     
8340     def testBuildPartOfMySelfSafe1(self):
8341         mesh=MEDCouplingDataForTest.build2DTargetMesh_1()
8342         self.assertRaises(InterpKernelException,mesh.buildPartOfMySelf,[0,-1,4,2],True)
8343         self.assertRaises(InterpKernelException,mesh.buildPartOfMySelf,[0,4,5,4],True)
8344         pass
8345
8346     def testIntersect2DMeshesTmp3(self):
8347         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];
8348         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];
8349         m1=MEDCouplingUMesh.New();
8350         m1.setMeshDimension(2);
8351         m1.allocateCells(8);
8352         m1.insertNextCell(NORM_TRI6,6,m1Conn[0:6]);
8353         m1.insertNextCell(NORM_QUAD8,8,m1Conn[6:14]);
8354         m1.insertNextCell(NORM_TRI6,6,m1Conn[14:20]);
8355         m1.insertNextCell(NORM_QUAD8,8,m1Conn[20:28]);
8356         m1.insertNextCell(NORM_TRI6,6,m1Conn[28:34]);
8357         m1.insertNextCell(NORM_QUAD8,8,m1Conn[34:42]);
8358         m1.insertNextCell(NORM_TRI6,6,m1Conn[42:48]);
8359         m1.insertNextCell(NORM_QUAD8,8,m1Conn[48:56]);
8360         m1.finishInsertingCells();
8361         myCoords1=DataArrayDouble.New();
8362         myCoords1.setValues(m1Coords,25,2);
8363         m1.setCoords(myCoords1);
8364         #
8365         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.]
8366         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]
8367         m2=MEDCouplingUMesh.New();
8368         m2.setMeshDimension(2);
8369         m2.allocateCells(8);
8370         for i in xrange(8):
8371             m2.insertNextCell(NORM_QUAD4,4,m2Conn[4*i:4*(i+1)])
8372             pass
8373         m2.finishInsertingCells();
8374         myCoords2=DataArrayDouble.New();
8375         myCoords2.setValues(m2Coords,15,2);
8376         m2.setCoords(myCoords2);
8377         #
8378         m3,d1,d2=MEDCouplingUMesh.Intersect2DMeshes(m1,m2,1e-10)
8379         m3.unPolyze()
8380         #
8381         expected1=[0,1,1,1,2,3,3,3,4,5,5,5,6,7,7,7]
8382         expected2=[0,0,1,-1,2,2,3,-1,4,4,5,-1,6,6,7,-1]
8383         self.assertEqual(16,d1.getNumberOfTuples());
8384         self.assertEqual(16,d2.getNumberOfTuples());
8385         self.assertEqual(16,m3.getNumberOfCells());
8386         self.assertEqual(104,m3.getNumberOfNodes());
8387         self.assertEqual(2,m3.getSpaceDimension());
8388         self.assertEqual(expected1,d1.getValues());
8389         self.assertEqual(expected2,d2.getValues());
8390         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]
8391         expected4=[0,7,16,25,34,41,50,59,68,75,84,93,102,109,118,127,136]
8392         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]
8393         self.assertEqual(136,m3.getNodalConnectivity().getNumberOfTuples());
8394         self.assertEqual(17,m3.getNodalConnectivityIndex().getNumberOfTuples());
8395         self.assertEqual(expected3,m3.getNodalConnectivity().getValues());
8396         self.assertEqual(expected4,m3.getNodalConnectivityIndex().getValues());
8397         for i in xrange(208):
8398             self.assertAlmostEqual(expected5[i],m3.getCoords().getIJ(0,i),12);
8399             pass
8400         pass
8401
8402     def testUMeshTessellate2D1(self):
8403         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];
8404         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];
8405         m1=MEDCouplingUMesh.New();
8406         m1.setMeshDimension(2);
8407         m1.allocateCells(8);
8408         m1.insertNextCell(NORM_TRI6,6,m1Conn[0:6]);
8409         m1.insertNextCell(NORM_QUAD8,8,m1Conn[6:14]);
8410         m1.insertNextCell(NORM_TRI6,6,m1Conn[14:20]);
8411         m1.insertNextCell(NORM_QUAD8,8,m1Conn[20:28]);
8412         m1.insertNextCell(NORM_TRI6,6,m1Conn[28:34]);
8413         m1.insertNextCell(NORM_QUAD8,8,m1Conn[34:42]);
8414         m1.insertNextCell(NORM_TRI6,6,m1Conn[42:48]);
8415         m1.insertNextCell(NORM_QUAD8,8,m1Conn[48:56]);
8416         m1.finishInsertingCells();
8417         myCoords1=DataArrayDouble.New();
8418         myCoords1.setValues(m1Coords,25,2);
8419         m1.setCoords(myCoords1);
8420         #
8421         m11=m1.deepCpy();
8422         m11.tessellate2D(1.);
8423         self.assertTrue(m11.getCoords().isEqual(m11.getCoords(),1e-12));
8424         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]
8425         expected2=[0,5,12,17,24,29,36,41,48]
8426         self.assertEqual(48,m11.getNodalConnectivity().getNumberOfTuples());
8427         self.assertEqual(9,m11.getNodalConnectivityIndex().getNumberOfTuples());
8428         self.assertEqual(expected1,m11.getNodalConnectivity().getValues());
8429         self.assertEqual(expected2,m11.getNodalConnectivityIndex().getValues());
8430         #
8431         m12=m1.deepCpy();
8432         m12.tessellate2D(0.5);
8433         self.assertEqual(41,m12.getNumberOfNodes());
8434         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]
8435         expected4=[0,6,15,21,30,36,45,51,60]
8436         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]
8437         for i in xrange(82):
8438             self.assertAlmostEqual(expected5[i],m12.getCoords().getIJ(0,i),12);
8439             pass
8440         self.assertEqual(60,m12.getNodalConnectivity().getNumberOfTuples());
8441         self.assertEqual(9,m12.getNodalConnectivityIndex().getNumberOfTuples());
8442         self.assertEqual(expected3,m12.getNodalConnectivity().getValues());
8443         self.assertEqual(expected4,m12.getNodalConnectivityIndex().getValues());
8444         pass
8445
8446     def testUMeshTessellate2DCurve1(self):
8447         # A quarter of circle:
8448         mcoords = [0.4,0.0,   0.0,-0.4,   0.283,-0.283]
8449         mconnec = [0,1,2]
8450
8451         m1 = MEDCouplingUMesh.New()
8452         m1.setMeshDimension(1)
8453         m1.allocateCells(1)
8454         m1.insertNextCell(NORM_SEG3, mconnec)
8455
8456         myCoords = DataArrayDouble.New(mcoords, 3, 2)
8457         m1.setCoords(myCoords)
8458         
8459         m2 = m1.deepCpy()
8460         m2.tessellate2DCurve(0.1)
8461         # If the following raises, the test will fail automatically:
8462         m2.checkCoherency1(0.0) # eps param not used
8463
8464     def testIntersect2DMeshesTmp4(self):
8465         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];
8466         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];
8467         m1=MEDCouplingUMesh.New();
8468         m1.setMeshDimension(2);
8469         m1.allocateCells(8);
8470         m1.insertNextCell(NORM_TRI6,6,m1Conn[0:6]);
8471         m1.insertNextCell(NORM_QUAD8,8,m1Conn[6:14]);
8472         m1.insertNextCell(NORM_TRI6,6,m1Conn[14:20]);
8473         m1.insertNextCell(NORM_QUAD8,8,m1Conn[20:28]);
8474         m1.insertNextCell(NORM_TRI6,6,m1Conn[28:34]);
8475         m1.insertNextCell(NORM_QUAD8,8,m1Conn[34:42]);
8476         m1.insertNextCell(NORM_TRI6,6,m1Conn[42:48]);
8477         m1.insertNextCell(NORM_QUAD8,8,m1Conn[48:56]);
8478         m1.finishInsertingCells();
8479         myCoords1=DataArrayDouble.New();
8480         myCoords1.setValues(m1Coords,25,2);
8481         m1.setCoords(myCoords1);
8482         #
8483         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.]
8484         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]
8485         m2=MEDCouplingUMesh.New();
8486         m2.setMeshDimension(2);
8487         m2.allocateCells(8);
8488         for i in xrange(8):
8489             m2.insertNextCell(NORM_QUAD4,4,m2Conn[4*i:4*(i+1)])
8490             pass
8491         m2.finishInsertingCells();
8492         myCoords2=DataArrayDouble.New();
8493         myCoords2.setValues(m2Coords,15,2);
8494         m2.setCoords(myCoords2);
8495         #
8496         m3,d1,d2=MEDCouplingUMesh.Intersect2DMeshes(m2,m1,1e-10)
8497         m3.unPolyze()
8498         #
8499         expected1=[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7]
8500         expected2=[0,1,1,-1,2,3,3,-1,4,5,5,-1,6,7,7,-1]
8501         self.assertEqual(16,d1.getNumberOfTuples());
8502         self.assertEqual(16,d2.getNumberOfTuples());
8503         self.assertEqual(16,m3.getNumberOfCells());
8504         self.assertEqual(104,m3.getNumberOfNodes());
8505         self.assertEqual(2,m3.getSpaceDimension());
8506         self.assertEqual(expected1,d1.getValues());
8507         self.assertEqual(expected2,d2.getValues());
8508         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]
8509         expected4=[0,7,16,25,34,41,50,59,68,75,84,93,102,109,118,127,136]
8510         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]
8511         self.assertEqual(136,m3.getNodalConnectivity().getNumberOfTuples());
8512         self.assertEqual(17,m3.getNodalConnectivityIndex().getNumberOfTuples());
8513         self.assertEqual(expected3,m3.getNodalConnectivity().getValues());
8514         self.assertEqual(expected4,m3.getNodalConnectivityIndex().getValues());
8515         for i in xrange(208):
8516             self.assertAlmostEqual(expected5[i],m3.getCoords().getIJ(0,i),12);
8517             pass
8518         pass
8519
8520     def testGetCellIdsCrossingPlane1(self):
8521         mesh3D,mesh2D=MEDCouplingDataForTest.build3DExtrudedUMesh_1();
8522         vec=[-0.07,1.,0.07]
8523         origin=[1.524,1.4552,1.74768]
8524         ids1=mesh3D.getCellIdsCrossingPlane(origin,vec,1e-10)
8525         self.assertEqual([1,3,4,7,9,10,13,15,16],ids1.getValues())
8526         vec2=[0.,0.,1.]
8527         ids2=mesh3D.getCellIdsCrossingPlane(origin,vec2,1e-10)
8528         self.assertEqual([6,7,8,9,10,11],ids2.getValues())
8529         pass
8530
8531     def testBuildSlice3D1(self):
8532         mesh3D,mesh2D=MEDCouplingDataForTest.build3DExtrudedUMesh_1();
8533         vec1=[-0.07,1.,0.07]
8534         origin1=[1.524,1.4552,1.74768]
8535         slice1,ids=mesh3D.buildSlice3D(origin1,vec1,1e-10);
8536         expected1=[1,3,4,7,9,10,13,15,16]
8537         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]
8538         expected3=[0,6,11,17,22,27,32,37,42,47]
8539         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.]
8540         self.assertEqual(2,slice1.getMeshDimension());
8541         self.assertEqual(3,slice1.getSpaceDimension());
8542         self.assertEqual(57,slice1.getNumberOfNodes());
8543         self.assertEqual(9,slice1.getNumberOfCells());
8544         self.assertEqual(9,ids.getNumberOfTuples());
8545         self.assertEqual(47,slice1.getNodalConnectivity().getNumberOfTuples());
8546         self.assertEqual(10,slice1.getNodalConnectivityIndex().getNumberOfTuples());
8547         self.assertEqual(expected1,ids.getValues());
8548         self.assertEqual(expected2,slice1.getNodalConnectivity().getValues());
8549         self.assertEqual(expected3,slice1.getNodalConnectivityIndex().getValues());
8550         for i in xrange(171):
8551             self.assertAlmostEqual(expected4[i],slice1.getCoords().getIJ(0,i),12);
8552             pass
8553         # 2nd slice based on already existing nodes of mesh3D.
8554         vec2=[0.,3.,1.]
8555         origin2=[2.5,1.,3.]
8556         slice1,ids=mesh3D.buildSlice3D(origin2,vec2,1e-10);
8557         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]
8558         expected6=[0,5,10,15,21,26,32,38,43,49]
8559         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]
8560         self.assertEqual(2,slice1.getMeshDimension());
8561         self.assertEqual(3,slice1.getSpaceDimension());
8562         self.assertEqual(60,slice1.getNumberOfNodes());
8563         self.assertEqual(9,slice1.getNumberOfCells());
8564         self.assertEqual(9,ids.getNumberOfTuples());
8565         self.assertEqual(49,slice1.getNodalConnectivity().getNumberOfTuples());
8566         self.assertEqual(10,slice1.getNodalConnectivityIndex().getNumberOfTuples());
8567         self.assertEqual(expected1,ids.getValues());
8568         self.assertEqual(expected5,slice1.getNodalConnectivity().getValues());
8569         self.assertEqual(expected6,slice1.getNodalConnectivityIndex().getValues());
8570         for i in xrange(180):
8571             self.assertAlmostEqual(expected7[i],slice1.getCoords().getIJ(0,i),12);
8572             pass
8573         # 3rd slice based on shared face of mesh3D.
8574         vec3=[0.,0.,1.]
8575         origin3=[2.5,1.,2.]
8576         slice1,ids=mesh3D.buildSlice3D(origin3,vec3,1e-10);
8577         expected8=[6,7,8,9,10,11,12,13,14,15,16,17]
8578         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]
8579         expected10=[0,5,12,17,22,29,34,39,46,51,56,63,68]
8580         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.]
8581         self.assertEqual(2,slice1.getMeshDimension());
8582         self.assertEqual(3,slice1.getSpaceDimension());
8583         self.assertEqual(45,slice1.getNumberOfNodes());
8584         self.assertEqual(12,slice1.getNumberOfCells());
8585         self.assertEqual(12,ids.getNumberOfTuples());
8586         self.assertEqual(68,slice1.getNodalConnectivity().getNumberOfTuples());
8587         self.assertEqual(13,slice1.getNodalConnectivityIndex().getNumberOfTuples());
8588         self.assertEqual(expected8,ids.getValues());
8589         self.assertEqual(expected9,slice1.getNodalConnectivity().getValues());
8590         self.assertEqual(expected10,slice1.getNodalConnectivityIndex().getValues());
8591         for i in xrange(135):
8592             self.assertAlmostEqual(expected11[i],slice1.getCoords().getIJ(0,i),12);
8593             pass
8594         pass
8595
8596     def testBuildSlice3DSurf1(self):
8597         mesh3D,mesh2D=MEDCouplingDataForTest.build3DExtrudedUMesh_1();
8598         mesh2D=mesh3D.buildDescendingConnectivity()[0];
8599         vec1=[-0.07,1.,0.07]
8600         origin1=[1.524,1.4552,1.74768]
8601         slice1,ids=mesh2D.buildSlice3DSurf(origin1,vec1,1e-10);
8602         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]
8603         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]
8604         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];
8605         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.]
8606         self.assertEqual(1,slice1.getMeshDimension());
8607         self.assertEqual(3,slice1.getSpaceDimension());
8608         self.assertEqual(57,slice1.getNumberOfNodes());
8609         self.assertEqual(25,slice1.getNumberOfCells());
8610         self.assertEqual(25,ids.getNumberOfTuples());
8611         self.assertEqual(75,slice1.getNodalConnectivity().getNumberOfTuples());
8612         self.assertEqual(26,slice1.getNodalConnectivityIndex().getNumberOfTuples());
8613         self.assertEqual(expected1,ids.getValues());
8614         self.assertEqual(expected2,slice1.getNodalConnectivity().getValues());
8615         self.assertEqual(expected3,slice1.getNodalConnectivityIndex().getValues());
8616         for i in xrange(171):
8617             self.assertAlmostEqual(expected4[i],slice1.getCoords().getIJ(0,i),12);
8618             pass
8619         #
8620         vec2=[0.,0.,1.]
8621         origin2=[2.5,1.,2.]
8622         slice1,ids=mesh2D.buildSlice3DSurf(origin2,vec2,1e-10);
8623         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]
8624         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]
8625         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];
8626         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.]
8627         self.assertEqual(1,slice1.getMeshDimension());
8628         self.assertEqual(3,slice1.getSpaceDimension());
8629         self.assertEqual(45,slice1.getNumberOfNodes());
8630         self.assertEqual(68,slice1.getNumberOfCells());
8631         self.assertEqual(68,ids.getNumberOfTuples());
8632         self.assertEqual(204,slice1.getNodalConnectivity().getNumberOfTuples());
8633         self.assertEqual(69,slice1.getNodalConnectivityIndex().getNumberOfTuples());
8634         self.assertEqual(expected5,ids.getValues());
8635         self.assertEqual(expected6,slice1.getNodalConnectivity().getValues());
8636         self.assertEqual(expected7,slice1.getNodalConnectivityIndex().getValues());
8637         for i in xrange(135):
8638             self.assertAlmostEqual(expected8[i],slice1.getCoords().getIJ(0,i),12);
8639             pass
8640         pass
8641
8642     def testDataArrayDoubleAdvSetting1(self):
8643         data1=[1.,11.,2.,12.,3.,13.,4.,14.,5.,15.,6.,16.,7.,17.]
8644         data2=[8.,38.,9.,39.,0.,30.,11.,41.,12.,42.]
8645         compsCpp=["comp1","comp2"]
8646         da=DataArrayDouble.New();
8647         da.setInfoAndChangeNbOfCompo(compsCpp);
8648         da.setName("da");
8649         da.alloc(7,2);
8650         compsCpp=compsCpp[:-1]
8651         self.assertRaises(InterpKernelException,da.setInfoAndChangeNbOfCompo,compsCpp);
8652         da.setValues(data1,7,2)
8653         #
8654         p=[(0,3),(3,5),(5,7)]
8655         tmp=da.selectByTupleRanges(p);
8656         self.assertTrue(tmp.isEqual(da,1e-14));
8657         p=[(0,2),(3,4),(5,7)]
8658         tmp=da.selectByTupleRanges(p);
8659         expected1=[1.,11.,2.,12.,4.,14.,6.,16.,7.,17.]
8660         self.assertEqual(5,tmp.getNumberOfTuples());
8661         self.assertEqual(2,tmp.getNumberOfComponents());
8662         for i in xrange(10):
8663             self.assertAlmostEqual(expected1[i],tmp.getIJ(0,i),14);
8664             pass
8665         p=[(0,2),(0,2),(5,6)]
8666         tmp=da.selectByTupleRanges(p);
8667         expected2=[1.,11.,2.,12.,1.,11.,2.,12.,6.,16.]
8668         self.assertEqual(5,tmp.getNumberOfTuples());
8669         self.assertEqual(2,tmp.getNumberOfComponents());
8670         for i in xrange(10):
8671             self.assertAlmostEqual(expected2[i],tmp.getIJ(0,i),14);
8672             pass
8673         p=[(0,2),(-1,2),(5,6)]
8674         self.assertRaises(InterpKernelException,da.selectByTupleRanges,p);
8675         p=[(0,2),(0,2),(5,8)]
8676         self.assertRaises(InterpKernelException,da.selectByTupleRanges,p);
8677         #
8678         da2=DataArrayDouble.New();
8679         da2.setValues(data2,5,2);
8680         #
8681         dac=da.deepCpy();
8682         dac.setContigPartOfSelectedValues2(1,da2,2,4,1);
8683         expected3=[1.,11.,0.,30.,11.,41.,4.,14.,5.,15.,6.,16.,7.,17.]
8684         for i in xrange(14):
8685             self.assertAlmostEqual(expected3[i],dac.getIJ(0,i),14);
8686             pass
8687         #
8688         dac=da.deepCpy();
8689         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues2,3,da2,0,5,1);
8690         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues2,0,da2,4,6,1);
8691         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues2,3,da2,5,0,1);
8692         dac.setContigPartOfSelectedValues2(3,da2,1,5,1);
8693         expected4=[1.,11.,2.,12.,3.,13.,9.,39.,0.,30.,11.,41.,12.,42.]
8694         for i in xrange(14):
8695             self.assertAlmostEqual(expected4[i],dac.getIJ(0,i),14);
8696             pass
8697         #
8698         ids=DataArrayInt.New();
8699         ids.alloc(3,1);
8700         dac=da.deepCpy();
8701         ids.setIJ(0,0,2); ids.setIJ(1,0,0); ids.setIJ(2,0,4);
8702         dac.setContigPartOfSelectedValues(2,da2,ids);
8703         expected5=[1.,11.,2.,12.,0.,30.,8.,38.,12.,42.,6.,16.,7.,17.]
8704         for i in xrange(14):
8705             self.assertAlmostEqual(expected5[i],dac.getIJ(0,i),14);
8706             pass
8707         #
8708         dac=da.deepCpy();
8709         ids.setIJ(0,0,2); ids.setIJ(1,0,5); ids.setIJ(2,0,4);
8710         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues,1,da2,ids);
8711         ids.setIJ(0,0,2); ids.setIJ(1,0,2); ids.setIJ(2,0,-1);
8712         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues,1,da2,ids);
8713         ids.setIJ(0,0,2); ids.setIJ(1,0,2); ids.setIJ(2,0,1);
8714         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues,5,da2,ids);
8715         #
8716         ids.setIJ(0,0,2); ids.setIJ(1,0,2); ids.setIJ(2,0,1);
8717         dac=da.deepCpy();
8718         dac.setContigPartOfSelectedValues(4,da2,ids);
8719         expected6=[1.,11.,2.,12.,3.,13.,4.,14.,0.,30.,0.,30.,9.,39.]
8720         for i in xrange(14):
8721             self.assertAlmostEqual(expected6[i],dac.getIJ(0,i),14);
8722             pass
8723         pass
8724
8725     def testDataArrayIntAdvSetting1(self):
8726         data1=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
8727         data2=[8,38,9,39,0,30,11,41,12,42]
8728         compsCpp=["comp1","comp2"]
8729         da=DataArrayInt.New();
8730         da.setInfoAndChangeNbOfCompo(compsCpp);
8731         da.setName("da");
8732         da.alloc(7,2);
8733         compsCpp=compsCpp[:-1]
8734         self.assertRaises(InterpKernelException,da.setInfoAndChangeNbOfCompo,compsCpp);
8735         da.setValues(data1,7,2)
8736         #
8737         p=[(0,3),(3,5),(5,7)]
8738         tmp=da.selectByTupleRanges(p);
8739         self.assertTrue(tmp.isEqual(da));
8740         p=[(0,2),(3,4),(5,7)]
8741         tmp=da.selectByTupleRanges(p);
8742         expected1=[1,11,2,12,4,14,6,16,7,17]
8743         self.assertEqual(5,tmp.getNumberOfTuples());
8744         self.assertEqual(2,tmp.getNumberOfComponents());
8745         for i in xrange(10):
8746             self.assertEqual(expected1[i],tmp.getIJ(0,i));
8747             pass
8748         p=[(0,2),(0,2),(5,6)]
8749         tmp=da.selectByTupleRanges(p);
8750         expected2=[1,11,2,12,1,11,2,12,6,16]
8751         self.assertEqual(5,tmp.getNumberOfTuples());
8752         self.assertEqual(2,tmp.getNumberOfComponents());
8753         for i in xrange(10):
8754             self.assertEqual(expected2[i],tmp.getIJ(0,i));
8755             pass
8756         p=[(0,2),(-1,2),(5,6)]
8757         self.assertRaises(InterpKernelException,da.selectByTupleRanges,p);
8758         p=[(0,2),(0,2),(5,8)]
8759         self.assertRaises(InterpKernelException,da.selectByTupleRanges,p);
8760         #
8761         da2=DataArrayInt.New();
8762         da2.setValues(data2,5,2);
8763         #
8764         dac=da.deepCpy();
8765         dac.setContigPartOfSelectedValues2(1,da2,2,4,1);
8766         expected3=[1,11,0,30,11,41,4,14,5,15,6,16,7,17]
8767         for i in xrange(14):
8768             self.assertEqual(expected3[i],dac.getIJ(0,i));
8769             pass
8770         #
8771         dac=da.deepCpy();
8772         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues2,3,da2,0,5,1);
8773         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues2,0,da2,4,6,1);
8774         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues2,3,da2,5,0,1);
8775         dac.setContigPartOfSelectedValues2(3,da2,1,5,1);
8776         expected4=[1,11,2,12,3,13,9,39,0,30,11,41,12,42]
8777         for i in xrange(14):
8778             self.assertEqual(expected4[i],dac.getIJ(0,i));
8779             pass
8780         #
8781         ids=DataArrayInt.New();
8782         ids.alloc(3,1);
8783         dac=da.deepCpy();
8784         ids.setIJ(0,0,2); ids.setIJ(1,0,0); ids.setIJ(2,0,4);
8785         dac.setContigPartOfSelectedValues(2,da2,ids);
8786         expected5=[1,11,2,12,0,30,8,38,12,42,6,16,7,17]
8787         for i in xrange(14):
8788             self.assertEqual(expected5[i],dac.getIJ(0,i));
8789             pass
8790         #
8791         dac=da.deepCpy();
8792         ids.setIJ(0,0,2); ids.setIJ(1,0,5); ids.setIJ(2,0,4);
8793         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues,1,da2,ids);
8794         ids.setIJ(0,0,2); ids.setIJ(1,0,2); ids.setIJ(2,0,-1);
8795         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues,1,da2,ids);
8796         ids.setIJ(0,0,2); ids.setIJ(1,0,2); ids.setIJ(2,0,1);
8797         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues,5,da2,ids);
8798         #
8799         ids.setIJ(0,0,2); ids.setIJ(1,0,2); ids.setIJ(2,0,1);
8800         dac=da.deepCpy();
8801         dac.setContigPartOfSelectedValues(4,da2,ids);
8802         expected6=[1,11,2,12,3,13,4,14,0,30,0,30,9,39]
8803         for i in xrange(14):
8804             self.assertEqual(expected6[i],dac.getIJ(0,i));
8805             pass
8806         pass
8807
8808     def testBuildDescendingConnec2Of3DMesh1(self):
8809         mesh=MEDCouplingDataForTest.build3DSourceMesh_1();
8810         #
8811         mesh2,desc,descIndx,revDesc,revDescIndx=mesh.buildDescendingConnectivity2();
8812         mesh2.checkCoherency();
8813         self.assertEqual(2,mesh2.getMeshDimension());
8814         self.assertEqual(30,mesh2.getNumberOfCells());
8815         self.assertEqual(31,revDescIndx.getNbOfElems()); self.assertEqual(31,revDescIndx.getNumberOfTuples());
8816         self.assertEqual(13,descIndx.getNbOfElems()); self.assertEqual(13,descIndx.getNumberOfTuples());
8817         self.assertEqual(48,desc.getNbOfElems()); self.assertEqual(48,desc.getNumberOfTuples());
8818         self.assertEqual(48,revDesc.getNbOfElems()); self.assertEqual(48,revDesc.getNumberOfTuples());
8819         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]
8820         self.assertEqual(expected1,desc.getValues());
8821         expected2=[0,4,8,12,16,20,24,28,32,36,40,44,48]
8822         self.assertEqual(expected2,descIndx.getValues());
8823         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]
8824         self.assertEqual(expected3,revDescIndx.getValues());
8825         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]
8826         self.assertEqual(expected4,revDesc.getValues());
8827         conn=mesh2.getNodalConnectivity();
8828         connIndex=mesh2.getNodalConnectivityIndex();
8829         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]
8830         self.assertEqual(expected5,connIndex.getValues());
8831         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]
8832         self.assertEqual(expected6,conn.getValues());
8833         pass
8834
8835     def testAre2DCellsNotCorrectlyOriented1(self):
8836         m1Coords=[1.,1.,-1.,-1.,-1.,-1.,1.,-1.]
8837         m1Conn=[0,3,1,2]
8838         m1=MEDCouplingUMesh.New();
8839         m1.setMeshDimension(2);
8840         m1.allocateCells(1);
8841         m1.insertNextCell(NORM_QUAD4,4,m1Conn[0:4])
8842         m1.finishInsertingCells();
8843         myCoords1=DataArrayDouble.New();
8844         myCoords1.setValues(m1Coords,4,2);
8845         m1.setCoords(myCoords1);
8846         #
8847         vec1=[0.,0.,1.]
8848         for i in xrange(18):
8849             vec2=[3.*cos(pi/9.*i),3.*sin(pi/9.*i)];
8850             m1Cpy=m1.deepCpy();
8851             m1Cpy.translate(vec2);
8852             self.assertRaises(InterpKernelException,m1Cpy.are2DCellsNotCorrectlyOriented,vec1,False);
8853             m1Cpy.changeSpaceDimension(3);
8854             res=m1Cpy.are2DCellsNotCorrectlyOriented(vec1,False)
8855             self.assertEqual([0],res.getValues());
8856             pass
8857         pass
8858
8859     def testDataArrayAbs1(self):
8860         d1=DataArrayDouble.New();
8861         val1=[2.,-3.,-5.,6.,-7.,-8.,9.,10.,-11.,-12.,-13.,-15.]
8862         expected1=[2.,3.,5.,6.,7.,8.,9.,10.,11.,12.,13.,15.]
8863         d1.setValues(val1,6,2);
8864         d2=d1.convertToIntArr();
8865         #
8866         d1.abs();
8867         for i in xrange(12):
8868             self.assertAlmostEqual(expected1[i],d1.getIJ(0,i),14);
8869             pass
8870         #
8871         expected2=[2,3,5,6,7,8,9,10,11,12,13,15]
8872         d2.abs();
8873         for i in xrange(12):
8874             self.assertEqual(expected2[i],d2.getIJ(0,i));
8875             pass
8876         #
8877         pass
8878
8879     # test on 1D
8880     def testGetValueOn3(self):
8881         v=[0.,1.,1.5,2.]
8882         v2=[0.7,1.25,0.,2.,1.5]
8883         disp=[5.,50.,500.,6.,60.,600.,7.,70.,700.,8.,80.,800.]
8884         m=MEDCouplingUMesh.New("myMesh",1)
8885         nbNodes=len(v)
8886         nbCells=nbNodes-1
8887         m.allocateCells(nbCells)
8888         coords=DataArrayDouble.New() ; coords.setValues(v,nbNodes,1)
8889         m.setCoords(coords)
8890         m.insertNextCell(NORM_SEG2,2,[0,1])
8891         m.insertNextCell(NORM_SEG2,2,[2,1])
8892         m.insertNextCell(NORM_SEG2,2,[2,3])
8893         m.finishInsertingCells()
8894         f=MEDCouplingFieldDouble.New(ON_NODES)
8895         f.setMesh(m)
8896         array=DataArrayDouble.New(); array.setValues(disp,m.getNumberOfNodes(),3)
8897         f.setArray(array)
8898         arr1=f.getValueOnMulti(v2)
8899         self.assertEqual(5,arr1.getNumberOfTuples());
8900         self.assertEqual(3,arr1.getNumberOfComponents());
8901         expected1=[5.7,57.,570.,6.5,65.,650.,5.,50.,500.,8.,80.,800.,7.,70.,700.]
8902         for i in xrange(15):
8903             self.assertAlmostEqual(expected1[i],arr1.getIJ(0,i),14);
8904             pass
8905         pass
8906
8907     def testGetNodeIdsOfCell2(self):
8908         m1c=MEDCouplingCMesh.New();
8909         coordsX=DataArrayDouble.New();
8910         arrX=[ -1., 1., 2., 4., 4.5 ]
8911         coordsX.setValues(arrX,5,1);
8912         coordsY=DataArrayDouble.New();
8913         arrY=[ -2., 2., 4., 8.]
8914         coordsY.setValues(arrY,4,1);
8915         coordsZ=DataArrayDouble.New();
8916         arrZ=[ -2., 2., 4.]
8917         coordsZ.setValues(arrZ,3,1);
8918         # test in 1D
8919         m1c.setCoordsAt(0,coordsX);
8920         expected1=[[0,1],[1,2],[2,3],[3,4]]
8921         self.assertEqual(4,m1c.getNumberOfCells())
8922         for i in xrange(m1c.getNumberOfCells()):
8923             self.assertEqual(expected1[i],m1c.getNodeIdsOfCell(i))
8924             pass
8925         # test in 2D
8926         m1c.setCoordsAt(1,coordsY);
8927         self.assertEqual(12,m1c.getNumberOfCells())
8928         self.assertEqual(20,m1c.getNumberOfNodes())
8929         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]]
8930         for i in xrange(m1c.getNumberOfCells()):
8931             self.assertEqual(expected2[i],m1c.getNodeIdsOfCell(i))
8932             pass
8933         # test in 3D
8934         m1c.setCoordsAt(2,coordsZ);
8935         self.assertEqual(24,m1c.getNumberOfCells())
8936         self.assertEqual(60,m1c.getNumberOfNodes())
8937         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]]
8938         self.assertEqual(24,m1c.getNumberOfCells())
8939         for i in xrange(m1c.getNumberOfCells()):
8940             self.assertEqual(expected3[i],m1c.getNodeIdsOfCell(i))
8941             pass
8942         pass
8943     
8944     def testSwigDADOp4(self):
8945         da=DataArrayDouble.New(range(6,30),12,2)
8946         self.assertEqual(12,da.getNumberOfTuples());
8947         self.assertEqual(2,da.getNumberOfComponents());
8948         for i in xrange(24):
8949             self.assertAlmostEqual(da.getIJ(0,i),float(i+6),13)
8950             pass
8951         # operator transpose
8952         da.transpose()
8953         self.assertEqual(2,da.getNumberOfTuples());
8954         self.assertEqual(12,da.getNumberOfComponents());
8955         for i in xrange(24):
8956             self.assertAlmostEqual(da.getIJ(0,i),float(i+6),13)
8957             pass
8958         da.transpose()
8959         # operator __neg__
8960         da2=DataArrayDouble.New(12,1)
8961         da2.iota(0.)
8962         dabis=-da
8963         for i in xrange(24):
8964             self.assertAlmostEqual(dabis.getIJ(0,i),-float(i+6),13)
8965             pass
8966         # operator+=
8967         da+=da2
8968         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.]
8969         for i in xrange(24):
8970             self.assertAlmostEqual(da.getIJ(0,i),expected1[i],13)
8971             pass
8972         da=-dabis
8973         da+=[100.,101.]
8974         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.]
8975         self.assertEqual(12,da.getNumberOfTuples());
8976         self.assertEqual(2,da.getNumberOfComponents());
8977         for i in xrange(24):
8978             self.assertAlmostEqual(da.getIJ(0,i),expected2[i],13)
8979             pass
8980         for pos,elt in enumerate(dabis):
8981             da[pos]+=elt
8982             pass
8983         self.assertEqual(12,da.getNumberOfTuples());
8984         self.assertEqual(2,da.getNumberOfComponents());
8985         for elt in da:
8986             li=elt[:]
8987             self.assertAlmostEqual(li[0],100.,13) ; self.assertAlmostEqual(li[1],101.,13)
8988             pass
8989         # operator-=
8990         da=DataArrayDouble.New(range(6,30),12,2)
8991         da2=DataArrayDouble.New(range(12),12,1)
8992         dabis=-da
8993         da-=da2
8994         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.]
8995         for i in xrange(24):
8996             self.assertAlmostEqual(da.getIJ(0,i),expected1[i],13)
8997             pass
8998         da=-dabis
8999         da-=[100.,101.]
9000         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.]
9001         self.assertEqual(12,da.getNumberOfTuples());
9002         self.assertEqual(2,da.getNumberOfComponents());
9003         for i in xrange(24):
9004             self.assertAlmostEqual(da.getIJ(0,i),expected2[i],13)
9005             pass
9006         for pos,elt in enumerate(dabis):
9007             da[pos]-=elt
9008             pass
9009         self.assertEqual(12,da.getNumberOfTuples());
9010         self.assertEqual(2,da.getNumberOfComponents());
9011         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.]
9012         for i in xrange(24):
9013             self.assertAlmostEqual(da.getIJ(0,i),expected3[i],13)
9014             pass
9015         # operator*=
9016         da=DataArrayDouble.New(range(6,30),12,2)
9017         da2=DataArrayDouble.New(range(12),12,1)
9018         dabis=-da
9019         da*=da2
9020         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.]
9021         for i in xrange(24):
9022             self.assertAlmostEqual(da.getIJ(0,i),expected1[i],13)
9023             pass
9024         da=-dabis
9025         da*=[100.,101.]
9026         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.]
9027         self.assertEqual(12,da.getNumberOfTuples());
9028         self.assertEqual(2,da.getNumberOfComponents());
9029         for i in xrange(24):
9030             self.assertAlmostEqual(da.getIJ(0,i),expected2[i],13)
9031             pass
9032         for pos,elt in enumerate(dabis):
9033             da[pos]*=elt
9034             pass
9035         self.assertEqual(12,da.getNumberOfTuples());
9036         self.assertEqual(2,da.getNumberOfComponents());
9037         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]
9038         for i in xrange(24):
9039             self.assertAlmostEqual(da.getIJ(0,i),expected3[i],13)
9040             pass
9041         # operator/=
9042         da=DataArrayDouble.New(range(6,30),12,2)
9043         da2=DataArrayDouble.New(range(1,13),12,1)
9044         dabis=-da
9045         da/=da2
9046         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]
9047         for i in xrange(24):
9048             self.assertAlmostEqual(da.getIJ(0,i),expected1[i],13)
9049             pass
9050         da=-dabis
9051         da/=[100.,101.]
9052         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]
9053         self.assertEqual(12,da.getNumberOfTuples());
9054         self.assertEqual(2,da.getNumberOfComponents());
9055         for i in xrange(24):
9056             self.assertAlmostEqual(da.getIJ(0,i),expected2[i],13)
9057             pass
9058         for pos,elt in enumerate(dabis):
9059             da[pos]/=elt
9060             pass
9061         self.assertEqual(12,da.getNumberOfTuples());
9062         self.assertEqual(2,da.getNumberOfComponents());
9063         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]
9064         for i in xrange(24):
9065             self.assertAlmostEqual(da.getIJ(0,i),expected3[i],13)
9066             pass
9067         pass
9068
9069     def testSwigDAIOp4(self):
9070         da=DataArrayInt.New(range(6,30),12,2)
9071         self.assertEqual(12,da.getNumberOfTuples());
9072         self.assertEqual(2,da.getNumberOfComponents());
9073         for i in xrange(24):
9074             self.assertEqual(da.getIJ(0,i),i+6)
9075             pass
9076         # operator transpose
9077         da.transpose()
9078         self.assertEqual(2,da.getNumberOfTuples());
9079         self.assertEqual(12,da.getNumberOfComponents());
9080         for i in xrange(24):
9081             self.assertEqual(da.getIJ(0,i),i+6)
9082             pass
9083         da.transpose()
9084         # operator __neg__
9085         da2=DataArrayInt.New(12,1)
9086         da2.iota(0)
9087         dabis=-da
9088         for i in xrange(24):
9089             self.assertEqual(dabis.getIJ(0,i),-(i+6))
9090             pass
9091         # operator+=
9092         da+=da2
9093         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]
9094         for i in xrange(24):
9095             self.assertEqual(da.getIJ(0,i),expected1[i])
9096             pass
9097         da=-dabis
9098         da+=[100,101]
9099         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]
9100         self.assertEqual(12,da.getNumberOfTuples());
9101         self.assertEqual(2,da.getNumberOfComponents());
9102         for i in xrange(24):
9103             self.assertEqual(da.getIJ(0,i),expected2[i])
9104             pass
9105         for pos,elt in enumerate(dabis):
9106             da[pos]+=elt
9107             pass
9108         self.assertEqual(12,da.getNumberOfTuples());
9109         self.assertEqual(2,da.getNumberOfComponents());
9110         for elt in da:
9111             li=elt[:]
9112             self.assertEqual(li[0],100) ; self.assertEqual(li[1],101)
9113             pass
9114         # operator-=
9115         da=DataArrayInt.New(range(6,30),12,2)
9116         da2=DataArrayInt.New(range(12),12,1)
9117         dabis=-da
9118         da-=da2
9119         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]
9120         for i in xrange(24):
9121             self.assertEqual(da.getIJ(0,i),expected1[i])
9122             pass
9123         da=-dabis
9124         da-=[100,101]
9125         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]
9126         self.assertEqual(12,da.getNumberOfTuples());
9127         self.assertEqual(2,da.getNumberOfComponents());
9128         for i in xrange(24):
9129             self.assertEqual(da.getIJ(0,i),expected2[i])
9130             pass
9131         for pos,elt in enumerate(dabis):
9132             da[pos]-=elt
9133             pass
9134         self.assertEqual(12,da.getNumberOfTuples());
9135         self.assertEqual(2,da.getNumberOfComponents());
9136         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]
9137         for i in xrange(24):
9138             self.assertEqual(da.getIJ(0,i),expected3[i])
9139             pass
9140         # operator*=
9141         da=DataArrayInt.New(range(6,30),12,2)
9142         da2=DataArrayInt.New(range(12),12,1)
9143         dabis=-da
9144         da*=da2
9145         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]
9146         for i in xrange(24):
9147             self.assertEqual(da.getIJ(0,i),expected1[i])
9148             pass
9149         da=-dabis
9150         da*=[100,101]
9151         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]
9152         self.assertEqual(12,da.getNumberOfTuples());
9153         self.assertEqual(2,da.getNumberOfComponents());
9154         for i in xrange(24):
9155             self.assertEqual(da.getIJ(0,i),expected2[i])
9156             pass
9157         for pos,elt in enumerate(dabis):
9158             da[pos]*=elt
9159             pass
9160         self.assertEqual(12,da.getNumberOfTuples());
9161         self.assertEqual(2,da.getNumberOfComponents());
9162         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]
9163         for i in xrange(24):
9164             self.assertEqual(da.getIJ(0,i),expected3[i])
9165             pass
9166         # operator/=
9167         da=DataArrayInt.New(range(6,30),12,2)
9168         da2=DataArrayInt.New(range(1,13),12,1)
9169         dabis=-da
9170         da/=da2
9171         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]
9172         for i in xrange(24):
9173             self.assertEqual(da.getIJ(0,i),expected1[i])
9174             pass
9175         da=-dabis
9176         da/=DataArrayInt.New([2,3],1,2)
9177         self.assertEqual(12,da.getNumberOfTuples());
9178         self.assertEqual(2,da.getNumberOfComponents());
9179         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]
9180         for i in xrange(24):
9181             self.assertEqual(da.getIJ(0,i),expected2[i])
9182             pass
9183         pass
9184
9185     def testSwigDADOp5(self):
9186         da=DataArrayDouble.New([5,6,7,8,9,6,7,-2,3,9,8,10])
9187         da.rearrange(3)
9188         da2=DataArrayDouble.New([5.,8.,10.,12])
9189         self.assertEqual(4,da2.getNumberOfTuples());
9190         self.assertEqual(1,da2.getNumberOfComponents());
9191         da3=da+da2
9192         self.assertEqual(4,da3.getNumberOfTuples());
9193         self.assertEqual(3,da3.getNumberOfComponents());
9194         expected1=[10.,11.,12.,16.,17.,14.,17.,8.,13.,21.,20.,22.]
9195         for i in xrange(12):
9196             self.assertAlmostEqual(da3.getIJ(0,i),expected1[i],13)
9197             pass
9198         da3=da2+da
9199         self.assertEqual(4,da3.getNumberOfTuples());
9200         self.assertEqual(3,da3.getNumberOfComponents());
9201         for i in xrange(12):
9202             self.assertAlmostEqual(da3.getIJ(0,i),expected1[i],13)
9203             pass
9204         # Test new API of classmethod DataArrayDouble.New
9205         vals=[5,6,7,8,9,6,7,-2,3,9,8,10]
9206         da=DataArrayDouble.New(vals)
9207         self.assertEqual(12,da.getNumberOfTuples());
9208         self.assertEqual(1,da.getNumberOfComponents());
9209         for i in xrange(12):
9210             self.assertAlmostEqual(da.getIJ(0,i),vals[i],13)
9211             pass
9212         da=DataArrayDouble.New(vals,12)
9213         self.assertEqual(12,da.getNumberOfTuples());
9214         self.assertEqual(1,da.getNumberOfComponents());
9215         for i in xrange(12):
9216             self.assertAlmostEqual(da.getIJ(0,i),vals[i],13)
9217             pass
9218         da=DataArrayDouble.New(vals,1,12)
9219         self.assertEqual(1,da.getNumberOfTuples());
9220         self.assertEqual(12,da.getNumberOfComponents());
9221         for i in xrange(12):
9222             self.assertAlmostEqual(da.getIJ(0,i),vals[i],13)
9223             pass
9224         da=DataArrayDouble.New(vals,6,2)
9225         self.assertEqual(6,da.getNumberOfTuples());
9226         self.assertEqual(2,da.getNumberOfComponents());
9227         for i in xrange(12):
9228             self.assertAlmostEqual(da.getIJ(0,i),vals[i],13)
9229             pass
9230         da=DataArrayDouble.New(vals,4,3)
9231         self.assertEqual(4,da.getNumberOfTuples());
9232         self.assertEqual(3,da.getNumberOfComponents());
9233         for i in xrange(12):
9234             self.assertAlmostEqual(da.getIJ(0,i),vals[i],13)
9235             pass
9236         self.assertRaises(InterpKernelException,DataArrayDouble.New,vals,11);
9237         self.assertRaises(InterpKernelException,DataArrayDouble.New,vals,13);
9238         self.assertRaises(InterpKernelException,DataArrayDouble.New,vals,5,2);
9239         self.assertRaises(InterpKernelException,DataArrayDouble.New,vals,7,2);
9240         pass
9241
9242     def testSwigDADOp6(self):
9243         da=DataArrayInt.New([5,6,7,8,9,6,7,-2,3,9,8,10])
9244         da.rearrange(3)
9245         da2=DataArrayInt.New([5,8,10,12])
9246         self.assertEqual(4,da2.getNumberOfTuples());
9247         self.assertEqual(1,da2.getNumberOfComponents());
9248         da3=da+da2
9249         self.assertEqual(4,da3.getNumberOfTuples());
9250         self.assertEqual(3,da3.getNumberOfComponents());
9251         expected1=[10,11,12,16,17,14,17,8,13,21,20,22]
9252         for i in xrange(12):
9253             self.assertEqual(da3.getIJ(0,i),expected1[i])
9254             pass
9255         da3=da2+da
9256         self.assertEqual(4,da3.getNumberOfTuples());
9257         self.assertEqual(3,da3.getNumberOfComponents());
9258         for i in xrange(12):
9259             self.assertEqual(da3.getIJ(0,i),expected1[i])
9260             pass
9261         da3=da+DataArrayInt.New(da2.getValues())
9262         # Test new API of classmethod DataArrayInt.New
9263         vals=[5,6,7,8,9,6,7,-2,3,9,8,10]
9264         da=DataArrayDouble.New(vals)
9265         self.assertEqual(12,da.getNumberOfTuples());
9266         self.assertEqual(1,da.getNumberOfComponents());
9267         for i in xrange(12):
9268             self.assertEqual(da.getIJ(0,i),vals[i])
9269             pass
9270         da=DataArrayDouble.New(vals,12)
9271         self.assertEqual(12,da.getNumberOfTuples());
9272         self.assertEqual(1,da.getNumberOfComponents());
9273         for i in xrange(12):
9274             self.assertEqual(da.getIJ(0,i),vals[i])
9275             pass
9276         da=DataArrayDouble.New(vals,1,12)
9277         self.assertEqual(1,da.getNumberOfTuples());
9278         self.assertEqual(12,da.getNumberOfComponents());
9279         for i in xrange(12):
9280             self.assertEqual(da.getIJ(0,i),vals[i])
9281             pass
9282         da=DataArrayDouble.New(vals,6,2)
9283         self.assertEqual(6,da.getNumberOfTuples());
9284         self.assertEqual(2,da.getNumberOfComponents());
9285         for i in xrange(12):
9286             self.assertEqual(da.getIJ(0,i),vals[i])
9287             pass
9288         da=DataArrayDouble.New(vals,4,3)
9289         self.assertEqual(4,da.getNumberOfTuples());
9290         self.assertEqual(3,da.getNumberOfComponents());
9291         for i in xrange(12):
9292             self.assertEqual(da.getIJ(0,i),vals[i])
9293             pass
9294         self.assertRaises(InterpKernelException,DataArrayDouble.New,vals,11);
9295         self.assertRaises(InterpKernelException,DataArrayDouble.New,vals,13);
9296         self.assertRaises(InterpKernelException,DataArrayDouble.New,vals,5,2);
9297         self.assertRaises(InterpKernelException,DataArrayDouble.New,vals,7,2);
9298         pass
9299
9300     def testSwigDADOp9(self):
9301         l1=[(1.,2.,3),(4.,5.,6.),(7.,8.,9.),[10.,11.,12.]]
9302         da1=DataArrayDouble(l1,4,3)
9303         self.assertEqual(4,da1.getNumberOfTuples());
9304         self.assertEqual(3,da1.getNumberOfComponents());
9305         da2=DataArrayDouble(12) ; da2.iota(1.) ; da2.rearrange(3)
9306         self.assertTrue(da2.isEqual(da1,1e-12))
9307         self.assertRaises(InterpKernelException,DataArrayDouble.New,l1,3,4);
9308         da3=DataArrayDouble(l1,4)
9309         self.assertTrue(da3.isEqual(da1,1e-12))
9310         self.assertRaises(InterpKernelException,DataArrayDouble.New,l1,3);
9311         self.assertRaises(InterpKernelException,DataArrayDouble.New,l1,5);
9312         l1=[(1.,2.,3),(4.,(5.),((6.))),(7.,8.,9.),[10.,11.,12.]]
9313         da1=DataArrayDouble(l1,4,3)
9314         self.assertEqual(4,da1.getNumberOfTuples());
9315         self.assertEqual(3,da1.getNumberOfComponents());
9316         da2=DataArrayDouble(12) ; da2.iota(1.) ; da2.rearrange(3)
9317         self.assertTrue(da2.isEqual(da1,1e-12))
9318         self.assertRaises(InterpKernelException,DataArrayDouble.New,l1,3,4);
9319         da3=DataArrayDouble(l1,4)
9320         self.assertTrue(da3.isEqual(da1,1e-12))
9321         self.assertRaises(InterpKernelException,DataArrayDouble.New,l1,3);
9322         self.assertRaises(InterpKernelException,DataArrayDouble.New,l1,5);
9323         #
9324         l1=[(1,2,3),(4,5,6),(7,8,9),[10,11,12]]
9325         da1=DataArrayInt(l1,4,3)
9326         self.assertEqual(4,da1.getNumberOfTuples());
9327         self.assertEqual(3,da1.getNumberOfComponents());
9328         da2=DataArrayInt(12) ; da2.iota(1) ; da2.rearrange(3)
9329         self.assertTrue(da2.isEqual(da1))
9330         self.assertRaises(InterpKernelException,DataArrayInt.New,l1,3,4);
9331         da3=DataArrayInt(l1,4)
9332         self.assertTrue(da3.isEqual(da1))
9333         self.assertRaises(InterpKernelException,DataArrayInt.New,l1,3);
9334         self.assertRaises(InterpKernelException,DataArrayInt.New,l1,5);
9335         l1=[(1,[2],3),(4,[(5)],6),((([7])),8,9),[10,11,12]]
9336         da1=DataArrayInt(l1,4,3)
9337         self.assertEqual(4,da1.getNumberOfTuples());
9338         self.assertEqual(3,da1.getNumberOfComponents());
9339         da2=DataArrayInt(12) ; da2.iota(1) ; da2.rearrange(3)
9340         self.assertTrue(da2.isEqual(da1))
9341         self.assertRaises(InterpKernelException,DataArrayInt.New,l1,3,4);
9342         da3=DataArrayInt(l1,4)
9343         self.assertTrue(da3.isEqual(da1))
9344         self.assertRaises(InterpKernelException,DataArrayInt.New,l1,3);
9345         self.assertRaises(InterpKernelException,DataArrayInt.New,l1,5);
9346         pass
9347
9348     def testRenumberNodesInConn1(self):
9349         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. ]
9350         mesh2DConn=[1,4,2, 4,5,2, 0,3,4,1, 6,7,4,3, 7,8,5,4]
9351         mesh2D=MEDCouplingUMesh.New("mesh",2);
9352         mesh2D.allocateCells(5);
9353         mesh2D.insertNextCell(NORM_TRI3,3,mesh2DConn[0:3])
9354         mesh2D.insertNextCell(NORM_TRI3,3,mesh2DConn[3:6])
9355         mesh2D.insertNextCell(NORM_QUAD4,4,mesh2DConn[6:10])
9356         mesh2D.insertNextCell(NORM_QUAD4,4,mesh2DConn[10:14])
9357         mesh2D.insertNextCell(NORM_QUAD4,4,mesh2DConn[14:18])
9358         mesh2D.finishInsertingCells();
9359         myCoords=DataArrayDouble.New(mesh2DCoords,9,3);
9360         mesh2D.setCoords(myCoords);
9361         mesh2D.checkCoherency();
9362         #
9363         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. ]
9364         mesh3DConn=[0,1,2,3,4,5,6,7]
9365         mesh3D=MEDCouplingUMesh.New("mesh",3);
9366         mesh3D.allocateCells(1);
9367         mesh3D.insertNextCell(NORM_HEXA8,8,mesh3DConn[:])
9368         mesh3D.finishInsertingCells();
9369         myCoords3D=DataArrayDouble.New(mesh3DCoords,8,3);
9370         mesh3D.setCoords(myCoords3D);
9371         mesh3D.checkCoherency();
9372         #
9373         mesh3D_2=mesh3D.deepCpy();
9374         mesh2D_2=mesh2D.deepCpy();
9375         mesh3D_4=mesh3D.deepCpy();
9376         mesh2D_4=mesh2D.deepCpy();
9377         oldNbOf3DNodes=mesh3D.getNumberOfNodes();
9378         renumNodes=DataArrayInt.New();
9379         renumNodes.alloc(mesh2D.getNumberOfNodes(),1);
9380         renumNodes.iota(oldNbOf3DNodes);
9381         coo=DataArrayDouble.Aggregate(mesh3D.getCoords(),mesh2D.getCoords());
9382         mesh3D.setCoords(coo);
9383         mesh2D.setCoords(coo);
9384         mesh2DCpy=mesh2D.deepCpy()
9385         mesh2D_3=mesh2D.deepCpy();
9386         mesh2D_3.shiftNodeNumbersInConn(oldNbOf3DNodes);
9387         mesh2D.renumberNodesInConn(renumNodes);
9388         mesh2DCpy.renumberNodesInConn(renumNodes.getValues());
9389         self.assertTrue(mesh2D.isEqual(mesh2DCpy,1e-12))
9390         self.assertTrue(mesh2D.isEqual(mesh2D_3,1e-12))
9391         #
9392         da1,da2=mesh3D.checkGeoEquivalWith(mesh3D_2,10,1e-12);
9393         self.assertTrue(da1==None);
9394         self.assertEqual(8,da2.getNumberOfTuples());
9395         self.assertEqual(1,da2.getNumberOfComponents());
9396         expected1=[8,11,12,9,4,5,6,7]
9397         for i in xrange(8):
9398             self.assertEqual(expected1[i],da2.getIJ(i,0));
9399             pass
9400         #
9401         da1,da2=mesh2D.checkGeoEquivalWith(mesh2D_2,10,1e-12);
9402         self.assertTrue(da1==None);
9403         self.assertEqual(9,da2.getNumberOfTuples());
9404         self.assertEqual(1,da2.getNumberOfComponents());
9405         for i in xrange(9):
9406             self.assertEqual(8+i,da2.getIJ(i,0));
9407             pass
9408         #
9409         mesh2D_5=mesh2D_4.deepCpy();
9410         mesh2D_5.translate([1.,0.,0.]);
9411         meshes=[mesh3D_4,mesh2D_4,mesh2D_5];
9412         MEDCouplingUMesh.PutUMeshesOnSameAggregatedCoords(meshes);
9413         self.assertTrue(mesh3D_4.getCoords().getHiddenCppPointer()==mesh2D_4.getCoords().getHiddenCppPointer());
9414         self.assertTrue(mesh2D_4.getCoords().getHiddenCppPointer()==mesh2D_5.getCoords().getHiddenCppPointer());
9415         mesh3D_4.checkCoherency(); mesh2D_4.checkCoherency(); mesh2D_5.checkCoherency();
9416         self.assertEqual(26,mesh3D_4.getNumberOfNodes());
9417         self.assertEqual(3,mesh3D_4.getSpaceDimension());
9418         self.assertEqual(9,mesh3D_4.getNodalConnectivity().getNumberOfTuples());
9419         self.assertEqual(23,mesh2D_4.getNodalConnectivity().getNumberOfTuples());
9420         self.assertEqual(23,mesh2D_5.getNodalConnectivity().getNumberOfTuples());
9421         expected2=[18,0,1,2,3,4,5,6,7]
9422         expected3=[3,9,12,10, 3,12,13,10, 4,8,11,12,9, 4,14,15,12,11, 4,15,16,13,12]
9423         expected4=[3,18,21,19, 3,21,22,19, 4,17,20,21,18, 4,23,24,21,20, 4,24,25,22,21]
9424         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]
9425         self.assertEqual(expected2,mesh3D_4.getNodalConnectivity().getValues());
9426         self.assertEqual(expected3,mesh2D_4.getNodalConnectivity().getValues());
9427         self.assertEqual(expected4,mesh2D_5.getNodalConnectivity().getValues());
9428         for i in xrange(78):
9429             self.assertAlmostEqual(expected5[i],mesh3D_4.getCoords().getIJ(0,i),12);
9430             pass
9431         #
9432         MEDCouplingUMesh.MergeNodesOnUMeshesSharingSameCoords(meshes,1e-12);
9433         mesh3D_4.checkCoherency(); mesh2D_4.checkCoherency(); mesh2D_5.checkCoherency();
9434         self.assertTrue(mesh3D_4.getCoords().getHiddenCppPointer()==mesh2D_4.getCoords().getHiddenCppPointer());
9435         self.assertTrue(mesh2D_4.getCoords().getHiddenCppPointer()==mesh2D_5.getCoords().getHiddenCppPointer());
9436         self.assertEqual(19,mesh3D_4.getNumberOfNodes());
9437         self.assertEqual(3,mesh3D_4.getSpaceDimension());
9438         self.assertEqual(9,mesh3D_4.getNodalConnectivity().getNumberOfTuples());
9439         self.assertEqual(23,mesh2D_4.getNodalConnectivity().getNumberOfTuples());
9440         self.assertEqual(23,mesh2D_5.getNodalConnectivity().getNumberOfTuples());
9441         expected6=[18,0,1,2,3,4,5,6,7]
9442         expected7=[3,3,2,8, 3,2,9,8, 4,0,1,2,3, 4,10,11,2,1, 4,11,12,9,2]
9443         expected8=[3,13,15,14, 3,15,16,14, 4,8,9,15,13, 4,12,17,15,9, 4,17,18,16,15]
9444         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.,
9445                     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.,
9446                     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.]
9447         self.assertEqual(expected6,mesh3D_4.getNodalConnectivity().getValues());
9448         self.assertEqual(expected7,mesh2D_4.getNodalConnectivity().getValues());
9449         self.assertEqual(expected8,mesh2D_5.getNodalConnectivity().getValues());
9450         for i in xrange(57):
9451             self.assertAlmostEqual(expected9[i],mesh3D_4.getCoords().getIJ(0,i),12);
9452             pass
9453         #
9454         pass
9455     
9456     def testComputeNeighborsOfCells1(self):
9457         m=MEDCouplingDataForTest.build2DTargetMesh_1();
9458         d1,d2=m.computeNeighborsOfCells();
9459         self.assertEqual(6,d2.getNumberOfTuples());
9460         self.assertEqual(10,d1.getNumberOfTuples());
9461         expected1=[0,2,4,6,8,10]
9462         expected2=[3,1,0,2,4,1,4,0,2,3]
9463         self.assertEqual(expected1,d2.getValues());
9464         self.assertEqual(expected2,d1.getValues());
9465         pass
9466
9467     def testCheckButterflyCellsBug1(self):
9468         mesh2DCoords=[323.85,120.983748908684,317.5,131.982271536747,336.55,120.983748908686,330.2,131.982271536751,323.85,142.98079416481]
9469         mesh2DConn=[4,1,0,2,3]
9470         mesh2D=MEDCouplingUMesh.New("mesh",2);
9471         mesh2D.allocateCells(1);
9472         mesh2D.insertNextCell(NORM_POLYGON,5,mesh2DConn[0:5])
9473         mesh2D.finishInsertingCells();
9474         myCoords=DataArrayDouble.New(mesh2DCoords,5,2);
9475         mesh2D.setCoords(myCoords);
9476         mesh2D.checkCoherency();
9477         #
9478         v=mesh2D.checkButterflyCells();
9479         self.assertTrue(v.empty());
9480         pass
9481
9482     def testDataArrayIntRange1(self):
9483         d=DataArrayInt.Range(2,17,7);
9484         expected1=[2,9,16]
9485         self.assertEqual(3,d.getNumberOfTuples());
9486         self.assertEqual(1,d.getNumberOfComponents());
9487         self.assertEqual(expected1,d.getValues());
9488         #
9489         d=DataArrayInt.Range(2,23,7);
9490         self.assertEqual(3,d.getNumberOfTuples());
9491         self.assertEqual(1,d.getNumberOfComponents());
9492         self.assertEqual(expected1,d.getValues());
9493         #
9494         d=DataArrayInt.Range(2,24,7);
9495         expected2=[2,9,16,23]
9496         self.assertEqual(4,d.getNumberOfTuples());
9497         self.assertEqual(1,d.getNumberOfComponents());
9498         self.assertEqual(expected2,d.getValues());
9499         #
9500         d=DataArrayInt.Range(24,2,-7);
9501         expected3=[24,17,10,3]
9502         self.assertEqual(4,d.getNumberOfTuples());
9503         self.assertEqual(1,d.getNumberOfComponents());
9504         self.assertEqual(expected3,d.getValues());
9505         #
9506         d=DataArrayInt.Range(23,2,-7);
9507         expected4=[23,16,9]
9508         self.assertEqual(3,d.getNumberOfTuples());
9509         self.assertEqual(1,d.getNumberOfComponents());
9510         self.assertEqual(expected4,d.getValues());
9511         #
9512         d=DataArrayInt.Range(23,22,-7);
9513         self.assertEqual(1,d.getNumberOfTuples());
9514         self.assertEqual(1,d.getNumberOfComponents());
9515         self.assertEqual(23,d.getIJ(0,0));
9516         #
9517         d=DataArrayInt.Range(22,23,7);
9518         self.assertEqual(1,d.getNumberOfTuples());
9519         self.assertEqual(1,d.getNumberOfComponents());
9520         self.assertEqual(22,d.getIJ(0,0));
9521         #
9522         d=DataArrayInt.Range(22,22,7);
9523         self.assertEqual(0,d.getNumberOfTuples());
9524         self.assertEqual(1,d.getNumberOfComponents());
9525         #
9526         d=DataArrayInt.Range(22,22,-7);
9527         self.assertEqual(0,d.getNumberOfTuples());
9528         self.assertEqual(1,d.getNumberOfComponents());
9529         #
9530         self.assertRaises(InterpKernelException,DataArrayInt.Range,22,23,-7);
9531         self.assertRaises(InterpKernelException,DataArrayInt.Range,23,22,7);
9532         self.assertRaises(InterpKernelException,DataArrayInt.Range,23,22,0);
9533         self.assertRaises(InterpKernelException,DataArrayInt.Range,22,23,0);
9534         pass
9535
9536     def testSwigUMeshGetItem1(self):
9537         m=MEDCouplingDataForTest.build2DTargetMesh_1();
9538         subMesh=m.buildPartOfMySelf([1,3],True);
9539         self.assertTrue(isinstance(subMesh,MEDCouplingUMesh))
9540         m1=m[[1,3]]
9541         self.assertTrue(isinstance(m1,MEDCouplingUMesh))
9542         m2=m[(1,3)]
9543         self.assertTrue(isinstance(m2,MEDCouplingUMesh))
9544         m3=m[1::2]
9545         self.assertTrue(isinstance(m3,MEDCouplingUMesh))
9546         m4=m[DataArrayInt.New([1,3])]
9547         m5_1=m[1]
9548         self.assertTrue(isinstance(m5_1,MEDCouplingUMesh))
9549         m5_2=m[3]
9550         self.assertTrue(isinstance(m5_2,MEDCouplingUMesh))
9551         m5=MEDCouplingUMesh.MergeUMeshesOnSameCoords([m5_1,m5_2]);
9552         m5.setName(subMesh.getName())
9553         self.assertTrue(isinstance(m4,MEDCouplingUMesh))
9554         self.assertTrue(subMesh.isEqual(m1,1e-12))
9555         self.assertTrue(subMesh.isEqual(m2,1e-12))
9556         self.assertTrue(subMesh.isEqual(m3,1e-12))
9557         self.assertTrue(subMesh.isEqual(m4,1e-12))
9558         self.assertTrue(subMesh.isEqual(m5,1e-12))
9559         self.assertRaises(InterpKernelException,m.buildPartOfMySelf,[1,5],True);
9560         pass
9561     
9562     def testSwigGetItem3(self):
9563         da=DataArrayInt.New([4,5,6])
9564         self.assertEqual(5,da[1])
9565         self.assertRaises(InterpKernelException,da.__getitem__,-1)
9566         self.assertRaises(InterpKernelException,da.__getitem__,3)
9567         da=DataArrayInt.New([4,5,6,7,8,9],2,3)
9568         self.assertEqual(9,da[1,2])
9569         da=DataArrayDouble.New([4.1,5.2,6.3])
9570         self.assertAlmostEqual(5.2,da[1],12)
9571         self.assertRaises(InterpKernelException,da.__getitem__,-1)
9572         self.assertRaises(InterpKernelException,da.__getitem__,3)
9573         da=DataArrayDouble.New([4.12,5.12,6.12,7.12,8.12,9.12],2,3)
9574         self.assertAlmostEqual(9.12,da[1,2],12)
9575         pass
9576
9577     def testSwigDADISub1(self):
9578         mesh3D,mesh2D=MEDCouplingDataForTest.build3DExtrudedUMesh_1();
9579         bary=mesh3D.getBarycenterAndOwner()
9580         bary=bary[:,:2]
9581         pts=bary.getDifferentValues(1e-12)
9582         expected=[[0,6,12],[1,7,13],[2,8,14],[3,9,15],[4,10,16],[5,11,17]]
9583         for pos,pt in enumerate(pts):
9584             bary2=bary[:,:2]
9585             bary2[:]-=pt
9586             norm=bary2.magnitude()
9587             self.assertEqual(expected[pos],norm.getIdsInRange(-1.,1e-5).getValues())
9588             pass
9589         expected2=[[3.,54.],[-141.,180.],[21.,54.],[39.,72.],[-15.,90.],[21.,90.]]
9590         for pos,pt in enumerate(pts):
9591             bary2=bary[:,:2]
9592             bary2[:]+=pt
9593             self.assertAlmostEqual(expected2[pos][0],bary2.accumulate()[0],12);
9594             self.assertAlmostEqual(expected2[pos][1],bary2.accumulate()[1],12);
9595             pass
9596         expected3=[[-3.,22.5],[45.,337.5],[-9., 22.5],[-15.,67.5],[3.,112.5],[-9.,112.5]]
9597         for pos,pt in enumerate(pts):
9598             bary2=bary[:,:2]
9599             bary2[:]*=pt
9600             self.assertAlmostEqual(expected3[pos][0],bary2.accumulate()[0],12);
9601             self.assertAlmostEqual(expected3[pos][1],bary2.accumulate()[1],12);
9602             pass
9603         expected4=[[-12.,90.],[0.8,6.],[-4,90.],[-2.4,30.],[12.,18],[-4,18.]]
9604         for pos,pt in enumerate(pts):
9605             bary2=bary[:,:2]
9606             bary2[:]/=pt
9607             self.assertAlmostEqual(expected4[pos][0],bary2.accumulate()[0],12);
9608             self.assertAlmostEqual(expected4[pos][1],bary2.accumulate()[1],12);
9609             pass
9610         #
9611         d=DataArrayInt.New([1,2,0,1,0,2],3,2)
9612         e=DataArrayInt.New([1,11,101,2,12,102,3,13,103,4,14,104],4,3)
9613         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]]
9614         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]]
9615         for pos,tup in enumerate(d):
9616             f=e[:]
9617             self.assertTrue(isinstance(f,DataArrayInt))
9618             f[tup]=77
9619             self.assertEqual(expected5[pos],f.getValues())
9620             self.assertEqual(6*[77],f[tup].getValues())
9621             f=e[:]
9622             f[:,tup]=77
9623             self.assertEqual(expected6[pos],f.getValues())
9624             self.assertEqual(8*[77],f[:,tup].getValues())
9625             pass
9626         #
9627         e=e.convertToDblArr()
9628         for pos,tup in enumerate(d):
9629             f=e[:]
9630             self.assertTrue(isinstance(f,DataArrayDouble))
9631             f[tup]=77.
9632             self.assertEqual(expected5[pos],f.convertToIntArr().getValues())
9633             self.assertEqual(6*[77],f[tup].convertToIntArr().getValues())
9634             f=e[:]
9635             f[:,tup]=77.
9636             self.assertEqual(expected6[pos],f.convertToIntArr().getValues())
9637             self.assertEqual(8*[77],f[:,tup].convertToIntArr().getValues())
9638             pass
9639         pass
9640
9641     def testDataArrayDoubleGetMinMaxPerComponent1(self):
9642         values1=[1.,2.,3.,-0.9,2.1,3.,1.3,1.7,3.,1.,1.8,3.]
9643         d1=DataArrayDouble.New();
9644         self.assertRaises(InterpKernelException,d1.getMinMaxPerComponent)
9645         d1=DataArrayDouble.New(values1,4,3);
9646         res=d1.getMinMaxPerComponent();
9647         self.assertTrue(isinstance(res,list))
9648         self.assertEqual(3,len(res))
9649         for i in xrange(3):
9650             self.assertTrue(isinstance(res[i],tuple))
9651             self.assertEqual(2,len(res[i]))
9652             pass
9653         expected1=[-0.9,1.3,1.7,2.1,3.,3.]
9654         for i in xrange(6):
9655             self.assertAlmostEqual(expected1[i],res[i/2][i%2],14)
9656             pass
9657         #
9658         d1.rearrange(2);
9659         res=d1.getMinMaxPerComponent();
9660         self.assertTrue(isinstance(res,list))
9661         self.assertEqual(2,len(res))
9662         for i in xrange(2):
9663             self.assertTrue(isinstance(res[i],tuple))
9664             self.assertEqual(2,len(res[i]))
9665             pass
9666         expected2=[1.,3.,-0.9,3.]
9667         for i in xrange(4):
9668             self.assertAlmostEqual(expected2[i],res[i/2][i%2],14)
9669             pass
9670         #
9671         d1.rearrange(1);
9672         res=d1.getMinMaxPerComponent();
9673         self.assertTrue(isinstance(res,list))
9674         self.assertEqual(1,len(res))
9675         for i in xrange(1):
9676             self.assertTrue(isinstance(res[i],tuple))
9677             self.assertEqual(2,len(res[i]))
9678             pass
9679         expected3=[-0.9,3.]
9680         for i in xrange(2):
9681             self.assertAlmostEqual(expected3[i],res[i/2][i%2],14)
9682             pass
9683         pass
9684
9685     def testDataArrayIntGetHashCode1(self):
9686         d1=DataArrayInt.New(range(3545))
9687         d2=DataArrayInt.New(range(3545))
9688         self.assertEqual(d2.getHashCode(),d1.getHashCode())
9689         self.assertEqual(232341068,d1.getHashCode())
9690         d1[886]=6
9691         self.assertEqual(232340188,d1.getHashCode())
9692         pass
9693
9694     def testZipConnectivityPol1(self):
9695         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
9696         cells1=[2,3,4]
9697         m2_1=m1.buildPartOfMySelf(cells1,True);
9698         m2=m2_1
9699         self.assertTrue(isinstance(m2,MEDCouplingUMesh))
9700         # no permutation policy 0
9701         isOk,arr=m1.areCellsIncludedIn(m2,0)
9702         self.assertTrue(isOk);
9703         self.assertEqual(3,arr.getNumberOfTuples());
9704         self.assertEqual(1,arr.getNumberOfComponents());
9705         self.assertEqual(cells1,arr.getValues())
9706         # no permutation policy 1
9707         isOk,arr=m1.areCellsIncludedIn(m2,1)
9708         self.assertTrue(isOk);
9709         self.assertEqual(3,arr.getNumberOfTuples());
9710         self.assertEqual(1,arr.getNumberOfComponents());
9711         self.assertEqual(cells1,arr.getValues())
9712         # no permutation policy 2
9713         isOk,arr=m1.areCellsIncludedIn(m2,2)
9714         self.assertTrue(isOk);
9715         self.assertEqual(3,arr.getNumberOfTuples());
9716         self.assertEqual(1,arr.getNumberOfComponents());
9717         self.assertEqual(cells1,arr.getValues())
9718         # some modification into m2
9719         modif1=[2,4,5]
9720         m2.getNodalConnectivity()[1:4]=modif1
9721         #policy 0 fails because cell0 in m2 has same orientation be not same connectivity
9722         expected1=[5,3,4]
9723         isOk,arr=m1.areCellsIncludedIn(m2,0)
9724         self.assertTrue(not isOk);
9725         self.assertEqual(3,arr.getNumberOfTuples());
9726         self.assertEqual(1,arr.getNumberOfComponents());
9727         self.assertEqual(expected1,arr.getValues())
9728         #policy 1 succeeds because cell0 in m2 has not exactly the same conn
9729         isOk,arr=m1.areCellsIncludedIn(m2,1)
9730         self.assertTrue(isOk);
9731         self.assertEqual(3,arr.getNumberOfTuples());
9732         self.assertEqual(1,arr.getNumberOfComponents());
9733         self.assertEqual(cells1,arr.getValues())
9734         #policy 2 succeeds because cell0 in m2 has same nodes in connectivity
9735         isOk,arr=m1.areCellsIncludedIn(m2,2)
9736         self.assertTrue(isOk);
9737         self.assertEqual(3,arr.getNumberOfTuples());
9738         self.assertEqual(1,arr.getNumberOfComponents());
9739         self.assertEqual(cells1,arr.getValues())
9740         #some new modification into m2
9741         modif2=[2,5,4]
9742         m2.getNodalConnectivity()[1:4]=modif2
9743         #policy 0 fails because cell0 in m2 has not exactly the same conn
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 fails too because cell0 in m2 has not same orientation
9750         isOk,arr=m1.areCellsIncludedIn(m2,1)
9751         self.assertTrue(not isOk);
9752         self.assertEqual(3,arr.getNumberOfTuples());
9753         self.assertEqual(1,arr.getNumberOfComponents());
9754         self.assertEqual(expected1,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         # Now 1D
9762         cells2=[3,2]
9763         m1=MEDCouplingDataForTest.build1DSourceMesh_2();
9764         m2_1=m1.buildPartOfMySelf(cells2,True);
9765         m2=m2_1
9766         self.assertTrue(isinstance(m2,MEDCouplingUMesh))
9767         # no permutation policy 0
9768         isOk,arr=m1.areCellsIncludedIn(m2,0)
9769         self.assertTrue(isOk);
9770         self.assertEqual(2,arr.getNumberOfTuples());
9771         self.assertEqual(1,arr.getNumberOfComponents());
9772         self.assertEqual(cells2,arr.getValues())
9773         # no permutation policy 1
9774         isOk,arr=m1.areCellsIncludedIn(m2,1)
9775         self.assertTrue(isOk);
9776         self.assertEqual(2,arr.getNumberOfTuples());
9777         self.assertEqual(1,arr.getNumberOfComponents());
9778         self.assertEqual(cells2,arr.getValues())
9779         # no permutation policy 2
9780         isOk,arr=m1.areCellsIncludedIn(m2,2)
9781         self.assertTrue(isOk);
9782         self.assertEqual(2,arr.getNumberOfTuples());
9783         self.assertEqual(1,arr.getNumberOfComponents());
9784         self.assertEqual(cells2,arr.getValues())
9785         # some modification into m2
9786         modif3=[4,3]
9787         m2.getNodalConnectivity()[1:3]=modif3
9788         #policy 0 fails because cell0 in m2 has not exactly the same conn
9789         expected2=[4,2]
9790         isOk,arr=m1.areCellsIncludedIn(m2,0)
9791         self.assertTrue(not isOk);
9792         self.assertEqual(2,arr.getNumberOfTuples());
9793         self.assertEqual(1,arr.getNumberOfComponents());
9794         self.assertEqual(expected2,arr.getValues())
9795         #policy 1 fails too because cell0 in m2 has not same orientation
9796         isOk,arr=m1.areCellsIncludedIn(m2,1)
9797         self.assertTrue(not isOk);
9798         self.assertEqual(2,arr.getNumberOfTuples());
9799         self.assertEqual(1,arr.getNumberOfComponents());
9800         self.assertEqual(expected2,arr.getValues())
9801         #policy 2 succeeds because cell0 in m2 has same nodes in connectivity
9802         isOk,arr=m1.areCellsIncludedIn(m2,2)
9803         self.assertTrue(isOk);
9804         self.assertEqual(2,arr.getNumberOfTuples());
9805         self.assertEqual(1,arr.getNumberOfComponents());
9806         self.assertEqual(cells2,arr.getValues())
9807         pass
9808
9809     def toSeeIfDaIIopsAreOK(self,d):
9810         d+=5
9811         d*=6
9812         d/=3
9813         d-=2
9814         d%=7
9815         pass
9816         
9817     def testSwigDAIOp5(self):
9818         d=DataArrayInt.New([4,5,6,10,3,-1],2,3)
9819         self.toSeeIfDaIIopsAreOK(d)
9820         dExp=DataArrayInt.New([2,4,6,0,0,6],2,3)
9821         self.assertTrue(d.isEqual(dExp));
9822         pass
9823     
9824     def toSeeIfDaDIopsAreOK(self,d):
9825         d+=5
9826         d*=6
9827         d/=3
9828         d-=2
9829         pass
9830
9831     def testSwigDADOp7(self):
9832         d=DataArrayDouble.New([4.,5.,6.,10.,3.,-1.],2,3)
9833         self.toSeeIfDaDIopsAreOK(d)
9834         dExp=DataArrayDouble.New([16.,18.,20.,28.,14.,6.],2,3)
9835         self.assertTrue(d.isEqual(dExp,1e-14));
9836         pass
9837
9838     def testConvexEnvelop2D1(self):
9839         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]
9840         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]
9841         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]
9842         #
9843         m=MEDCouplingUMesh.New("convexhull",2);
9844         m.allocateCells(331);
9845         for i in xrange(331):
9846             m.insertNextCell(NORM_POLYGON,conn[connI[i]:connI[i+1]]);
9847             pass
9848         m.finishInsertingCells();
9849         coordsDa=DataArrayDouble.New(coords,331,2);
9850         m.setCoords(coordsDa);
9851         m.checkCoherency();
9852         #
9853         da=m.convexEnvelop2D();
9854         m.checkCoherency()
9855         self.assertEqual(coordsDa.getHiddenCppPointer(),m.getCoords().getHiddenCppPointer())
9856         daC=da.buildComplement(m.getNumberOfCells());
9857         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]);
9858         self.assertTrue(expected2.isEqual(daC));
9859         #
9860         vals=m.getMeasureField(ON_CELLS).getArray()
9861         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]
9862         vals-=DataArrayDouble.New(ref)
9863         vals.abs()
9864         theTest=vals.getIdsInRange(-1.,1e-7)
9865         self.assertTrue(theTest.isIdentity())
9866         self.assertEqual(331,len(theTest))
9867         pass
9868
9869     def testSwigDAIOp8(self):
9870         da=DataArrayInt.New([7,5,6,7,8,9,9,10,12,13,47,15])
9871         self.assertTrue(7 in da)
9872         self.assertTrue(47 in da)
9873         self.assertTrue(15 in da)
9874         self.assertEqual(0,da.index(7))
9875         self.assertEqual(10,da.index(47))
9876         self.assertTrue(14 not in da)
9877         self.assertEqual(5,da.search([9,9]))
9878         self.assertEqual(-1,da.search([5,8]))
9879         da.rearrange(2)
9880         self.assertTrue([47,16] not in da)
9881         self.assertTrue([5,6] not in da)
9882         self.assertTrue([6,7] in da)
9883         self.assertEqual(4,da.index([12,13]))
9884         pass
9885
9886     def testDataArraySort1(self):
9887         arr=DataArrayInt.New();
9888         self.assertRaises(InterpKernelException,arr.sort,True)
9889         self.assertRaises(InterpKernelException,arr.sort,False)
9890         values=[2,1,6,5,4,7]
9891         arr.alloc(3,2);
9892         self.assertRaises(InterpKernelException,arr.sort,True)
9893         self.assertRaises(InterpKernelException,arr.sort,False)
9894         arr.rearrange(1);
9895         arr.setValues(values,6,1)
9896         arr1=arr.deepCpy();
9897         arr2=arr.deepCpy();
9898         arr1.sort(True);
9899         expected1=[1,2,4,5,6,7]
9900         self.assertEqual(6,arr1.getNumberOfTuples());
9901         self.assertEqual(1,arr1.getNumberOfComponents());
9902         self.assertEqual(expected1,arr1.getValues());
9903         arr2.sort(False);
9904         expected2=[7,6,5,4,2,1]
9905         self.assertEqual(6,arr2.getNumberOfTuples());
9906         self.assertEqual(1,arr2.getNumberOfComponents());
9907         self.assertTrue(expected2,arr2.getValues());
9908         #
9909         ard=DataArrayDouble.New();
9910         self.assertRaises(InterpKernelException,ard.sort,True)
9911         self.assertRaises(InterpKernelException,ard.sort,False)
9912         valuesD=[2.,1.,6.,5.,4.,7.]
9913         ard.alloc(3,2);
9914         self.assertRaises(InterpKernelException,ard.sort,True)
9915         self.assertRaises(InterpKernelException,ard.sort,False)
9916         ard.rearrange(1);
9917         ard.setValues(valuesD,6,1)
9918         ard1=ard.deepCpy();
9919         ard2=ard.deepCpy();
9920         ard1.sort(True);
9921         expected3=[1.,2.,4.,5.,6.,7.]
9922         self.assertEqual(6,ard1.getNumberOfTuples());
9923         self.assertEqual(1,ard1.getNumberOfComponents());
9924         for i in xrange(6):
9925             self.assertAlmostEqual(expected3[i],ard1.getIJ(i,0),12)
9926             pass
9927         ard2.sort(False);
9928         expected4=[7.,6.,5.,4.,2.,1.]
9929         self.assertEqual(6,ard2.getNumberOfTuples());
9930         self.assertEqual(1,ard2.getNumberOfComponents());
9931         for i in xrange(6):
9932             self.assertAlmostEqual(expected4[i],ard2.getIJ(i,0),12)
9933             pass
9934         pass
9935     
9936     def testPartitionBySpreadZone1(self):
9937         m=MEDCouplingDataForTest.build2DTargetMesh_1();
9938         m4=MEDCouplingUMesh.MergeUMeshes([m,m[-3:],m[0:2]]);
9939         m4.renumberCells([5,2,9,6,4,7,0,1,3,8]);
9940         #
9941         v2=m4.partitionBySpreadZone();
9942         self.assertTrue(3,len(v2));
9943         self.assertTrue(v2[0].isEqual(DataArrayInt.New([0,1,7])))
9944         self.assertTrue(v2[1].isEqual(DataArrayInt.New([2,4,5,6,9])))
9945         self.assertTrue(v2[2].isEqual(DataArrayInt.New([3,8])))
9946         #
9947         m5=m4.buildSpreadZonesWithPoly();
9948         self.assertEqual(3,m5.getNumberOfCells());
9949         self.assertTrue(m5.getCoords().getHiddenCppPointer()==m4.getCoords().getHiddenCppPointer());
9950         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())
9951         self.assertEqual([0,8,17,23],m5.getNodalConnectivityIndex().getValues())
9952         #
9953         pass
9954
9955     def testGiveCellsWithType1(self):
9956         expected0=[1,2]
9957         expected1=[0,3,4]
9958         m=MEDCouplingDataForTest.build2DTargetMesh_1();
9959         da=m.giveCellsWithType(NORM_TRI3);
9960         self.assertEqual(2,da.getNumberOfTuples());
9961         self.assertEqual(1,da.getNumberOfComponents());
9962         self.assertEqual(expected0,da.getValues())
9963         #
9964         da=m.giveCellsWithType(NORM_QUAD4);
9965         self.assertEqual(3,da.getNumberOfTuples());
9966         self.assertEqual(1,da.getNumberOfComponents());
9967         self.assertEqual(expected1,da.getValues())
9968         #
9969         da=m.giveCellsWithType(NORM_TRI6);
9970         self.assertEqual(0,da.getNumberOfTuples());
9971         self.assertEqual(1,da.getNumberOfComponents());
9972         #
9973         self.assertRaises(InterpKernelException,m.giveCellsWithType,NORM_SEG2)
9974         self.assertRaises(InterpKernelException,m.giveCellsWithType,NORM_HEXA8)
9975         pass
9976
9977     def testSwigDAOp1(self):
9978         d=DataArrayDouble.New(5,2)
9979         d.rearrange(1) ; d.iota(2.) ; d.rearrange(2)
9980         d.setInfoOnComponents(["X [m]","Y [m]"])
9981         d.setName("AName")
9982         #
9983         d1=d+[8,9]
9984         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))
9985         d1bis=DataArrayDouble.New([8,9],1,2)+d
9986         self.assertTrue(d1bis.isEqual(d1,1e-12))
9987         d1ter=[8,9]+d
9988         self.assertTrue(d1ter.isEqual(d1,1e-12))
9989         #
9990         d2=d1-[8,9]
9991         self.assertTrue(d2.isEqual(d,1e-12))
9992         self.assertRaises(InterpKernelException,d1.__rsub__,[8,9])#[8,9]-d1
9993         #
9994         d3=d*[8,9]
9995         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))
9996         d3bis=DataArrayDouble.New([8,9],1,2)*d
9997         self.assertTrue(d3bis.isEqual(d3,1e-12))
9998         d3ter=[8,9]*d
9999         self.assertTrue(d3ter.isEqual(d3,1e-12))
10000         #
10001         d4=d3/[8,9]
10002         self.assertTrue(d4.isEqual(d,1e-12))
10003         #
10004         d=DataArrayInt.New(5,2)
10005         d.rearrange(1) ; d.iota(2) ; d.rearrange(2)
10006         d.setInfoOnComponents(["X [m]","Y [m]"])
10007         d.setName("AName")
10008         #
10009         d1=d+[8,9]
10010         self.assertEqual(d1.getValues(),[10,12,12,14,14,16,16,18,18,20])
10011         d1bis=DataArrayInt.New([8,9],1,2)+d
10012         self.assertTrue(d1bis.isEqual(d1))
10013         d1ter=[8,9]+d
10014         self.assertTrue(d1ter.isEqual(d1))
10015         #
10016         d2=d1-[8,9]
10017         self.assertTrue(d2.isEqual(d))
10018         self.assertRaises(InterpKernelException,d1.__rsub__,[8,9])
10019         #
10020         d3=d*[8,9]
10021         self.assertEqual(d3.getValues(),[16,27,32,45,48,63,64,81,80,99])
10022         d3bis=DataArrayInt.New([8,9],1,2)*d
10023         self.assertTrue(d3bis.isEqual(d3))
10024         d3ter=[8,9]*d
10025         self.assertTrue(d3ter.isEqual(d3))
10026         #
10027         d4=d3/[8,9]
10028         self.assertTrue(d4.isEqual(d))
10029         #
10030         d5=d%[4,5]
10031         self.assertEqual(d5.getValues(),[2,3,0,0,2,2,0,4,2,1])
10032         pass
10033
10034     def testSwigSelectTupleId2DAIBug1(self):
10035         da=DataArrayInt.New([0,1,2,3,12,13,4,5,6,7,14,15,8,9,10,11,16,17])
10036         self.assertEqual([2,6,10],da[2::6].getValues())
10037         self.assertEqual([0,4,8],da[::6].getValues())
10038         self.assertEqual([5,9],da[7::6].getValues())
10039         self.assertEqual([5],da[7:-5:6].getValues())
10040         pass
10041
10042     def testSwigCpp5Safe1(self):
10043         m=MEDCouplingUMesh.New("toto",2)
10044         coords=DataArrayDouble.New([0.,0.,1.,0.,1.,1.,0.,1.],4,2)
10045         m.setCoords(coords)
10046         vecs=DataArrayDouble.New([2.,3.,4.,5.,6.,7.],3,2)
10047         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]]
10048         for pos,vec in enumerate(vecs):
10049             m2=m.deepCpy()
10050             m2.translate(vec)
10051             self.assertTrue(m2.getCoords().isEqual(DataArrayDouble.New(expected1[pos],4,2),1e-12))
10052             pass
10053         for pos,vec in enumerate(vecs):
10054             m2=m.deepCpy()
10055             m2.translate(vec.buildDADouble())
10056             self.assertTrue(m2.getCoords().isEqual(DataArrayDouble.New(expected1[pos],4,2),1e-12))
10057             pass
10058         pass
10059     
10060     def testSwigBugNonRegressionZipDA(self):
10061         angles=map(lambda x:pi/3*x,xrange(6))
10062         radius=3
10063         #
10064         dad=DataArrayDouble.New(6, 2)
10065         dad[:,0]=radius
10066         dad[:,1]=angles
10067         #
10068         dad2=dad.fromPolarToCart()
10069         dads=[dad2.deepCpy() for elt in 7*[None]]
10070         #
10071         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.)]]
10072         for d,t in zip(dads,translationToPerform):
10073             d+=t
10074             pass
10075         for elt in dads:
10076             self.assertTrue(not dad2.isEqual(elt,1e-12))
10077             pass
10078         for d,t in zip(dads,translationToPerform):
10079             d-=t
10080             pass
10081         for elt in dads:
10082             self.assertTrue(dad2.isEqual(elt,1e-12))
10083             pass
10084         pass
10085
10086     def testBuildSlice3D2(self):
10087         mesh3D,mesh2D=MEDCouplingDataForTest.build3DExtrudedUMesh_1();
10088         vec1=[-0.07,1.,0.07]
10089         origin1=[1.524,1.4552,1.74768]
10090         slice1,ids=mesh3D.buildSlice3D(origin1,vec1,1e-10);
10091         f=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME)
10092         f.setTime(4.5,6,7) ; f.setMesh(mesh3D)
10093         arr=DataArrayDouble(mesh3D.getNumberOfCells(),2)
10094         arr.rearrange(1) ; arr.iota(2.) ; arr.rearrange(2)
10095         f.setArray(arr)
10096         f.checkCoherency()
10097         expected1=DataArrayInt([1,3,4,7,9,10,13,15,16])
10098         self.assertTrue(expected1.isEqual(ids))
10099         arr2=arr[expected1]
10100         #
10101         f2=f.extractSlice3D(origin1,vec1,1e-10)
10102         self.assertTrue(f2.getArray().isEqual(arr2,1e-12));
10103         self.assertTrue(slice1.isEqual(f2.getMesh(),1e-12))
10104         self.assertEqual(6,f2.getTime()[1]) ; self.assertEqual(7,f2.getTime()[2])
10105         self.assertAlmostEqual(4.5,f2.getTime()[0],12);
10106         pass
10107
10108     def testComputeTupleIdsToSelectFromCellIds1(self):
10109         m=MEDCouplingDataForTest.build2DTargetMesh_3()
10110         f=MEDCouplingFieldDouble.New(ON_GAUSS_NE,NO_TIME);
10111         f.setMesh(m);
10112         arr=DataArrayDouble(52,2) ; arr.rearrange(1) ; arr.iota(7.) ; arr.rearrange(2)
10113         f.setArray(arr)
10114         #
10115         f2=f.buildSubPart([1,5,9])
10116         f2.checkCoherency()
10117         cI=m.computeNbOfNodesPerCell()
10118         cI.computeOffsets2()
10119         sel=DataArrayInt([1,5,9])
10120         res=sel.buildExplicitArrByRanges(cI)
10121         arr2=arr[res]
10122         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))
10123         self.assertTrue(arr2.isEqual(f2.getArray(),1e-12))
10124         pass
10125
10126     def testComputeSkin1(self):
10127         arrX=DataArrayDouble([2.,3.4,5.6,7.7,8.0]) ; arrY=DataArrayDouble([2.,3.4,5.6,7.7,9.0,14.2])
10128         cmesh=MEDCouplingCMesh() ; cmesh.setCoordsAt(0,arrX) ; cmesh.setCoordsAt(1,arrY)
10129         umesh=cmesh.buildUnstructured()
10130         #
10131         skin=umesh.computeSkin()
10132         self.assertEqual(18,skin.getNumberOfCells())
10133         self.assertEqual(1,skin.getMeshDimension())
10134         self.assertTrue(skin.getCoords().getHiddenCppPointer()==umesh.getCoords().getHiddenCppPointer())
10135         self.assertEqual([0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54],skin.getNodalConnectivityIndex().getValues())
10136         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())
10137         ids=skin.computeFetchedNodeIds()
10138         self.assertEqual([0,1,2,3,4,5,9,10,14,15,19,20,24,25,26,27,28,29],ids.getValues())
10139         part=umesh.buildFacePartOfMySelfNode(ids,True)
10140         part.setName(skin.getName());
10141         self.assertTrue(part.isEqual(skin,1e-12))
10142         part2=part[1::2]
10143         part[::2]=part2
10144         self.assertTrue(not part.isEqual(skin,1e-12))
10145         trad=part.zipConnectivityTraducer(0)
10146         self.assertEqual(9,part.getNumberOfCells())
10147         self.assertEqual([0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8],trad.getValues())
10148         pass
10149
10150     def testUMeshSetPartOfMySelf2(self):
10151         # resize with explicit ids list
10152         m=MEDCouplingDataForTest.build2DTargetMesh_1()
10153         self.assertEqual([3,4],m.getAllGeoTypes())
10154         part=m[[0,3,4]]
10155         part.simplexize(0)
10156         part2=part[[1,2,5]]
10157         m[[0,3,4]]=part2
10158         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())
10159         self.assertEqual([0,4,8,12,16,20],m.getNodalConnectivityIndex().getValues())
10160         self.assertEqual([3],m.getAllGeoTypes())
10161         # no resize with explicit ids list
10162         m=MEDCouplingDataForTest.build2DTargetMesh_1()
10163         part=m[[0,3]]
10164         part.convertAllToPoly()
10165         m[[3,4]]=part
10166         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())
10167         self.assertEqual([0,5,9,13,18,23],m.getNodalConnectivityIndex().getValues())
10168         self.assertEqual([3,4,5],m.getAllGeoTypes())
10169         # resize with range ids
10170         m=MEDCouplingDataForTest.build2DTargetMesh_1()
10171         part=m[3:]
10172         m[1:3]=part
10173         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())
10174         self.assertEqual([0,5,10,15,20,25],m.getNodalConnectivityIndex().getValues())
10175         self.assertEqual([4],m.getAllGeoTypes())
10176         # no resize with range ids
10177         m=MEDCouplingDataForTest.build2DTargetMesh_1()
10178         part=m[0::3]
10179         part.convertAllToPoly()
10180         m[3:]=part
10181         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())
10182         self.assertEqual([0,5,9,13,18,23],m.getNodalConnectivityIndex().getValues())
10183         self.assertEqual([3,4,5],m.getAllGeoTypes())
10184         # no resize with range ids negative direction
10185         m=MEDCouplingDataForTest.build2DTargetMesh_1()
10186         part=m[3::-3]
10187         part.convertAllToPoly()
10188         m[:-3:-1]=part
10189         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())
10190         self.assertEqual([0,5,9,13,18,23],m.getNodalConnectivityIndex().getValues())
10191         self.assertEqual([3,4,5],m.getAllGeoTypes())
10192         pass
10193
10194     def testUnPolyze3(self):
10195         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]
10196         conn=[1,2,5,4,-1,4,3,0,1,-1,2,0,3,5,-1,0,2,1,-1,4,5,3]
10197         m=MEDCouplingUMesh.New("a mesh",3);
10198         m.allocateCells(1);
10199         m.insertNextCell(NORM_POLYHED,22,conn[0:22])
10200         m.finishInsertingCells();
10201         coords=DataArrayDouble(coord,6,3);
10202         m.setCoords(coords);
10203         m.checkCoherency();
10204         #
10205         vol=m.getMeasureField(ON_CELLS);
10206         self.assertEqual(1,vol.getArray().getNumberOfTuples());
10207         self.assertAlmostEqual(0.5,vol.getArray().getIJ(0,0),12)
10208         #
10209         m.unPolyze();
10210         #
10211         self.assertEqual([NORM_PENTA6],m.getAllGeoTypes())
10212         self.assertTrue(DataArrayInt([0,7]).isEqual(m.getNodalConnectivityIndex()))
10213         self.assertTrue(DataArrayInt([16,0,2,1,3,5,4]).isEqual(m.getNodalConnectivity()))
10214         #
10215         vol=m.getMeasureField(ON_CELLS);
10216         self.assertEqual(1,vol.getArray().getNumberOfTuples());
10217         self.assertAlmostEqual(0.5,vol.getArray().getIJ(0,0),12)
10218         pass
10219
10220     def testKrSpatialDiscretization1(self):
10221         srcPointCoordsX=[0.8401877171547095, 0.7830992237586059, 0.9116473579367843, 0.335222755714889, 0.2777747108031878, 0.4773970518621602, 0.3647844727918433, 0.9522297251747128, 0.6357117279599009, 0.1416025553558034]
10222         srcFieldValsOnPoints=[2.129892434968836, 2.295320474540621, 1.931948594981134, 2.728013590937196, 2.715603240418478, 2.661778472822935, 2.695696990104364, 1.893710234970982, 2.529628016549284, 2.728432341300668]
10223         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]
10224         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]
10225         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])
10226         #
10227         nbOfInputPoints=10;
10228         f=MEDCouplingFieldDouble.New(ON_NODES_KR,ONE_TIME);
10229         srcArrX=DataArrayDouble.New(srcPointCoordsX,nbOfInputPoints,1);
10230         cmesh=MEDCouplingCMesh.New("aMesh");
10231         cmesh.setCoordsAt(0,srcArrX);
10232         umesh=cmesh.buildUnstructured();
10233         f.setMesh(umesh);
10234         srcVals=DataArrayDouble.New(srcFieldValsOnPoints,nbOfInputPoints,1);
10235         f.setArray(srcVals);
10236         f.checkCoherency();
10237         #
10238         res0=f.getValueOn(targetPointCoordsX[:1]);
10239         self.assertAlmostEqual(targetFieldValsExpected[0],res0[0],10)
10240         #
10241         valuesToTest=f.getValueOnMulti(targetPointCoordsX);
10242         self.assertEqual(40,valuesToTest.getNumberOfTuples());
10243         self.assertEqual(1,valuesToTest.getNumberOfComponents());
10244         for i in xrange(40):
10245             self.assertAlmostEqual(targetFieldValsExpected[i],valuesToTest.getIJ(i,0),10)
10246             pass
10247         fd=f.getDiscretization()
10248         del f
10249         self.assertTrue(isinstance(fd,MEDCouplingFieldDiscretizationKriging))
10250         coeffs,isDrift=fd.computeVectorOfCoefficients(umesh,srcVals)
10251         self.assertEqual(2,isDrift)
10252         self.assertTrue(coeffsExpected.isEqual(coeffs,1e-8))
10253         #
10254         pass
10255
10256     def testDuplicateEachTupleNTimes1(self):
10257         d=DataArrayDouble.New([9.,8.,7.,6.],4,1) ; d.setInfoOnComponents(["mass [kg]"]) ; d.setName("aname")
10258         d2=d.duplicateEachTupleNTimes(3)
10259         self.assertTrue(d2.isEqualWithoutConsideringStr(DataArrayDouble.New([9.,9.,9.,8.,8.,8.,7.,7.,7.,6.,6.,6.],4*3,1),1e-14))
10260         self.assertEqual("aname",d2.getName())
10261         self.assertEqual(["mass [kg]"],d2.getInfoOnComponents())
10262         #
10263         d=DataArrayInt.New([9,8,7,6],4,1) ; d.setInfoOnComponents(["mass [kg]"]) ; d.setName("aname")
10264         d2=d.duplicateEachTupleNTimes(3)
10265         self.assertTrue(d2.isEqualWithoutConsideringStr(DataArrayInt.New([9,9,9,8,8,8,7,7,7,6,6,6],4*3,1)))
10266         self.assertEqual("aname",d2.getName())
10267         self.assertEqual(["mass [kg]"],d2.getInfoOnComponents())
10268         pass
10269
10270     def testSwigComputeTupleIdsNearTuples1(self):
10271         da=DataArrayDouble([5.,6.,-5.,-6.,5.,-6.,-5.,6.,5.,6.],5,2)
10272         arr,arrI=da.computeTupleIdsNearTuples(DataArrayDouble([5.,-6.,5.,6.,-5.,-6.],3,2),1e-10)
10273         self.assertEqual([2,0,4,1],arr.getValues())
10274         self.assertEqual([0,1,3,4],arrI.getValues())
10275         arr,arrI=da.computeTupleIdsNearTuples([5.,-6.,5.,6.,-5.,-6.],1e-10)
10276         self.assertEqual([2,0,4,1],arr.getValues())
10277         self.assertEqual([0,1,3,4],arrI.getValues())
10278         expected0=[[2],[0,4],[1]]
10279         expected1=[[0,1],[0,2],[0,1]]
10280         for pos,it in enumerate(DataArrayDouble([5.,-6.,5.,6.,-5.,-6.],3,2)):
10281             arr,arrI=da.computeTupleIdsNearTuples(it,1e-10)
10282             self.assertEqual(expected0[pos],arr.getValues())
10283             self.assertEqual(expected1[pos],arrI.getValues())
10284             pass
10285         pass
10286
10287     def testSwigDataTupleIOp1(self):
10288         d=DataArrayDouble(10,1)
10289         d.iota(7.)
10290         for elt in d:
10291             elt+=2.
10292             pass
10293         toTest=DataArrayDouble([9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0])
10294         self.assertTrue(toTest.isEqual(d,1e-12))
10295         for elt in d:
10296             elt-=2.
10297             pass
10298         toTest=DataArrayDouble([7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0])
10299         self.assertTrue(toTest.isEqual(d,1e-12))
10300         for elt in d:
10301             elt*=2.
10302             pass
10303         toTest=DataArrayDouble([14.0,16.0,18.0,20.0,22.0,24.0,26.0,28.0,30.0,32.0])
10304         self.assertTrue(toTest.isEqual(d,1e-12))
10305         for elt in d:
10306             elt/=2.
10307             pass
10308         toTest=DataArrayDouble([7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0])
10309         self.assertTrue(toTest.isEqual(d,1e-12))
10310         #
10311         d=DataArrayInt(10,1)
10312         d.iota(7)
10313         for elt in d:
10314             elt+=2
10315             pass
10316         self.assertEqual(d.getValues(),[9,10,11,12,13,14,15,16,17,18])
10317         for elt in d:
10318             elt-=2
10319             pass
10320         self.assertEqual(d.getValues(),[7,8,9,10,11,12,13,14,15,16])
10321         for elt in d:
10322             elt*=2
10323             pass
10324         self.assertEqual(d.getValues(),[14,16,18,20,22,24,26,28,30,32])
10325         for elt in d:
10326             elt/=2
10327             pass
10328         self.assertEqual(d.getValues(),[7,8,9,10,11,12,13,14,15,16])
10329         for elt in d:
10330             elt%=3
10331             pass
10332         self.assertEqual(d.getValues(),[1,2,0,1,2,0,1,2,0,1])
10333         pass
10334
10335     def testIntersect2DMeshesTmp5(self):
10336         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)
10337         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)
10338         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)
10339         #
10340         m1=MEDCouplingUMesh.New("Fix",2);
10341         m1.setCoords(coords);
10342         m1.setConnectivity(conn,connI,True);
10343         #
10344         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)
10345         # connectivity
10346         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);
10347         conn.setName("");
10348         connI=DataArrayInt([0,9,18,27,36,45,54,63,72],9)
10349         m2=MEDCouplingUMesh.New("Mobile",2);
10350         m2.setCoords(coords);
10351         m2.setConnectivity(conn,connI,True);
10352         #
10353         m3,d1,d2=MEDCouplingUMesh.Intersect2DMeshes(m1,m2,1e-10);
10354         self.assertEqual(105,m3.getNumberOfCells());
10355         self.assertEqual(105,d1.getNumberOfTuples());
10356         self.assertEqual(105,d2.getNumberOfTuples());
10357         self.assertEqual(704,m3.getNumberOfNodes());
10358         #
10359         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]
10360         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]
10361         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]
10362         f3=m3.getMeasureField(ON_CELLS).getArray().getValues();
10363         for i in xrange(105):
10364             self.assertAlmostEqual(areaExpected[i],f3[i],10)
10365             pass
10366         self.assertEqual(expected1,d1.getValues())
10367         self.assertEqual(expected2,d2.getValues())
10368         pass
10369
10370     def testSwig2Intersect2DMeshesQuadra1(self):
10371         import cmath
10372         def createDiagCircle(lX, lY, R, cells=[0,1]):  
10373             """ A circle in a square box, cut along the diagonal. 
10374             """    
10375             c = []
10376             for i in range(8):
10377               c.append(cmath.rect(R, i*pi/4))
10378         
10379             coords = [0.0,0.0,          c[3].real,c[3].imag,       -lX/2.0, lY/2.0,
10380                       0.0, lY/2.0,      lX/2.0,lY/2.0,             lX/2.0,0.0,
10381                       #   6                  7                              8
10382                       lX/2.0,-lY/2.0,   c[7].real,c[7].imag,       c[1].real,c[1].imag,
10383                       #   9                  10                            11  
10384                       c[5].real,c[5].imag,   -lX/2.0,-lY/2.0,      0.0, -lY/2.0,
10385                       #   12                  13                            14
10386                       -lX/2.0,0.0,         0.0,0.0,                  0.0, 0.0]
10387             # Points 13 (reps. 14) are average of points (6,7) (resp (1,2))
10388             coords[13*2]   = 0.5*(coords[6*2]+coords[7*2])
10389             coords[13*2+1] = 0.5*(coords[6*2+1]+coords[7*2+1])
10390             coords[14*2]   = 0.5*(coords[1*2]+coords[2*2])
10391             coords[14*2+1] = 0.5*(coords[1*2+1]+coords[2*2+1])
10392             connec  = [1,7,8,0]      # half circle up right
10393             connec3 = [6,7,1,2,4,13,8,14,3,5]
10394             
10395             baseMesh = MEDCouplingUMesh.New("box_circle", 2)  
10396             baseMesh.allocateCells(2)
10397             meshCoords = DataArrayDouble.New(coords, len(coords)/2, 2)
10398             meshCoords.setInfoOnComponents(["X [au]", "Y [au]"])
10399             baseMesh.setCoords(meshCoords)
10400             
10401             if 0 in cells:
10402               baseMesh.insertNextCell(NORM_QPOLYG, connec)  
10403             if 1 in cells: 
10404               baseMesh.insertNextCell(NORM_QPOLYG, connec3) 
10405             baseMesh.finishInsertingCells()  
10406             baseMesh.checkCoherency() 
10407             return baseMesh 
10408         
10409         eps = 1.0e-7
10410         m1 = createDiagCircle(1.0, 1.0, 0.5*0.90, cells=[0,1])  
10411         m2 = createDiagCircle(1.0, 1.0, 0.5*0.95, cells=[0])
10412         m3, _, _= MEDCouplingUMesh.Intersect2DMeshes(m1, m2, eps)
10413         m3.mergeNodes(eps)
10414         m3.convertDegeneratedCells()
10415         m3.zipCoords()        
10416         m4 = m3.deepCpy()
10417         m5, _, _ = MEDCouplingUMesh.Intersect2DMeshes(m3, m4, eps)
10418         m5.mergeNodes(eps)
10419         # Check coordinates:
10420         self.assertTrue(m3.getCoords().isEqual(m5.getCoords(), eps))
10421
10422     def testDAIBuildUnique1(self):
10423         d=DataArrayInt([1,2,2,3,3,3,3,4,5,5,7,7,7,19])
10424         e=d.buildUnique()
10425         self.assertTrue(e.isEqual(DataArrayInt([1,2,3,4,5,7,19])))
10426         pass
10427
10428     def testDAIPartitionByDifferentValues1(self):
10429         d=DataArrayInt([1,0,1,2,0,2,2,-3,2])
10430         expected=[[-3,[7]],[0,[1,4]],[1,[0,2]],[2,[3,5,6,8]]]
10431         for i,elt in enumerate(zip(*d.partitionByDifferentValues())):
10432             self.assertEqual(expected[i][0],elt[1])
10433             self.assertEqual(expected[i][1],elt[0].getValues())
10434             pass
10435         pass
10436
10437     def testFieldGaussMultiDiscPerType1(self):
10438         coords=DataArrayDouble([0.,0.,0.,1.,1.,1.,1.,0.,0.,0.5,0.5,1.,1.,0.5,0.5,0.],8,2)
10439         mQ8=MEDCouplingUMesh("",2) ; mQ8.setCoords(coords)
10440         mQ8.allocateCells(1)
10441         mQ8.insertNextCell(NORM_QUAD8,range(8))
10442         mQ8.finishInsertingCells()
10443         mQ4=MEDCouplingUMesh("",2) ; mQ4.setCoords(coords)
10444         mQ4.allocateCells(1)
10445         mQ4.insertNextCell(NORM_QUAD4,range(4))
10446         mQ4.finishInsertingCells()
10447         mT3=MEDCouplingUMesh("",2) ; mT3.setCoords(coords)
10448         mT3.allocateCells(1)
10449         mT3.insertNextCell(NORM_TRI3,range(3))
10450         mT3.finishInsertingCells()
10451         
10452         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.]]
10453         ms=2*[mQ4]+7*[mQ8]+11*[mT3]
10454         ms[:]=(elt.deepCpy() for elt in ms)
10455         for m,t in zip(ms,tr):
10456             d=m.getCoords() ; d+= t
10457             pass
10458         m=MEDCouplingUMesh.MergeUMeshes(ms)
10459         f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,NO_TIME)
10460         f.setMesh(m)
10461         # throw because cell 0,1 are QUAD4 and cell 3 is QUAD8
10462         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])
10463         f.setGaussLocalizationOnCells([0,1],[0.,0.,1.,0.,1.,1.,0.,1.],[0.3,0.3,0.7,0.7],[0.8,0.2])
10464         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])
10465         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])
10466         f.setGaussLocalizationOnCells([9,10,11,12,13],[0.,0.,1.,0.,1.,1.],[0.4,0.4],[1.])
10467         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])
10468         self.assertEqual(46,f.getNumberOfTuplesExpected())
10469         vals=DataArrayDouble.New(46*3,1) ; vals.iota(7.7) ; vals.rearrange(3)
10470         f.setArray(vals)
10471         f.checkCoherency()
10472         #f.getLocalizationOfDiscr()
10473         self.assertRaises(InterpKernelException,f.getGaussLocalizationIdOfOneType,NORM_QUAD8) #throw because several loc
10474         self.assertEqual([1,2],f.getGaussLocalizationIdsOfOneType(NORM_QUAD8))
10475         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())
10476         fc=f[[1,2,3,8]]
10477         fc.checkCoherency()
10478         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))
10479         fc.renumberCells([3,2,0,1])
10480         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))
10481         fc.getArray()
10482         pass
10483
10484     def testSwigRotate(self):
10485         d=DataArrayDouble([1.,2.,3.,4.,6.,5.],2,3)
10486         MEDCouplingPointSet.Rotate3DAlg([0.,0.,0.],[0.,1.,0.],1.5707963267948966,d)
10487         self.assertTrue(d.isEqual(DataArrayDouble([3.,2.,-1.,5.,6.,-4.],2,3),1e-12))
10488         d=DataArrayDouble([1.,2.,3.,4.,6.,5.],3,2)
10489         MEDCouplingPointSet.Rotate2DAlg([0.,0.],1.5707963267948966,d)
10490         self.assertTrue(d.isEqual(DataArrayDouble([-2.,1.,-4.,3.,-5.,6.],3,2),1e-12))
10491         pass
10492
10493     def testSwigCMeshProtection(self):
10494         cm=MEDCouplingCMesh()
10495         self.assertRaises(InterpKernelException,cm.setCoordsAt,0,DataArrayDouble([4.,4.5,6.,7.],2,2))
10496         self.assertRaises(InterpKernelException,cm.setCoords,DataArrayDouble([4.,4.5,6.,7.],2,2))
10497         pass
10498
10499     def testSwigCellsInBoundingBox1(self):
10500         m3D=MEDCouplingDataForTest.build3DExtrudedUMesh_1()[0]
10501         self.assertTrue(m3D.getCellsInBoundingBox([(0,3),(0,3),(0,1)],-1e-12).isEqual(DataArrayInt([0,1,2,3,4,5])))
10502         self.assertRaises(InterpKernelException,m3D.getCellsInBoundingBox,[(0,3,0),(3,0,1)],-1e-12)
10503         pass
10504
10505     def testDAICheckMonotonic1(self):
10506         data1=[-1,0,2,2,4,5]
10507         data2=[6,2,0,-8,-9,-56]
10508         data3=[-1,0,3,2,4,6]
10509         data4=[7,5,2,3,0,-6]
10510         d=DataArrayInt.New(data1);
10511         self.assertTrue(d.isMonotonic(True));
10512         self.assertTrue(not d.isMonotonic(False));
10513         d.checkMonotonic(True);
10514         self.assertRaises(InterpKernelException,d.checkMonotonic,False)
10515         d=DataArrayInt.New(data2);
10516         self.assertTrue(d.isMonotonic(False));
10517         self.assertTrue(not d.isMonotonic(True));
10518         d.checkMonotonic(False);
10519         self.assertRaises(InterpKernelException,d.checkMonotonic,True)
10520         d=DataArrayInt.New(data3);
10521         self.assertTrue(not d.isMonotonic(False));
10522         self.assertTrue(not d.isMonotonic(True));
10523         self.assertRaises(InterpKernelException,d.checkMonotonic,True)
10524         self.assertRaises(InterpKernelException,d.checkMonotonic,False)
10525         d=DataArrayInt.New(data4);
10526         self.assertTrue(not d.isMonotonic(False));
10527         self.assertTrue(not d.isMonotonic(True));
10528         self.assertRaises(InterpKernelException,d.checkMonotonic,True)
10529         self.assertRaises(InterpKernelException,d.checkMonotonic,False)
10530         d=DataArrayInt.New(0,1)
10531         self.assertTrue(d.isMonotonic(True));
10532         self.assertTrue(d.isMonotonic(False));
10533         d.checkMonotonic(True);
10534         d.checkMonotonic(False);
10535         d=DataArrayInt.New(data4,3,2);#throw because nbComp!=1
10536         self.assertRaises(InterpKernelException,d.isMonotonic,True)
10537         self.assertRaises(InterpKernelException,d.isMonotonic,False)
10538         self.assertRaises(InterpKernelException,d.checkMonotonic,True)
10539         self.assertRaises(InterpKernelException,d.checkMonotonic,False)
10540         pass
10541
10542     def testSwigDASetItemOnEmpty1(self):
10543         d=DataArrayInt(0,1)
10544         isThrow=False
10545         try:
10546             d[0:1000:2]=4
10547         except InterpKernelException as e:
10548             isThrow=True
10549             pass
10550         self.assertTrue(isThrow)
10551         d[:]=4
10552         d[::2]=5
10553         #
10554         d=DataArrayDouble(0,1)
10555         isThrow=False
10556         try:
10557             d[0:1000:2]=4
10558         except InterpKernelException as e:
10559             isThrow=True
10560             pass
10561         self.assertTrue(isThrow)
10562         d[:]=4
10563         d[::2]=5
10564         d=DataArrayInt([],0,1)
10565         d2=DataArrayInt(0)
10566         self.assertTrue(d2.isEqual(d))
10567         d=DataArrayDouble([],0,1)
10568         d2=DataArrayDouble(0)
10569         self.assertTrue(d2.isEqual(d,1e-12))
10570         pass
10571
10572     def testSwigDAITransformWithIndArr1(self):
10573         arr=DataArrayInt([0,4,5,1])
10574         d=DataArrayInt([7,8,9,10])
10575         self.assertRaises(InterpKernelException,arr.transformWithIndArr,d)
10576         pass
10577
10578     def testIntersect2DMeshesTmp6(self):
10579         # coordinates
10580         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);
10581         # connectivity
10582         conn=DataArrayInt.New([8,0,3,5,1,4,6,7,2])
10583         connI=DataArrayInt.New([0,9]);
10584         m1=MEDCouplingUMesh.New("Fixe",2);
10585         m1.setCoords(coords);
10586         m1.setConnectivity(conn,connI,True);
10587         #
10588         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);
10589         # connectivity
10590         conn=DataArrayInt.New([8,0,1,2,3,4,5,6,7,8,3,2,8,9,6,10,11,12]);
10591         connI=DataArrayInt.New([0,9,18]);
10592         #
10593         m2=MEDCouplingUMesh.New("Mobile",2);
10594         m2.setCoords(coords);
10595         m2.setConnectivity(conn,connI,True);
10596         #
10597         m3,d1,d2=MEDCouplingUMesh.Intersect2DMeshes(m1,m2,1e-10);
10598         self.assertTrue(d1.isEqual(DataArrayInt([0,0,0,0])));
10599         self.assertTrue(d2.isEqual(DataArrayInt([0,1,-1,-1])));
10600         self.assertEqual(4,m3.getNumberOfCells());
10601         self.assertEqual(4,d1.getNumberOfTuples());
10602         self.assertEqual(4,d2.getNumberOfTuples());
10603         self.assertEqual(43,m3.getNumberOfNodes());
10604         dI,areMerged,newNbOfNodes=m3.mergeNodes(1e-12)
10605         self.assertEqual(35,m3.getNumberOfNodes());
10606         m3.zipCoords();
10607         self.assertEqual(23,m3.getNumberOfNodes());
10608         #
10609         f=m3.getMeasureField(True);
10610         valuesExpected=DataArrayDouble([1.6603638692585716,5.747555728471923,129.68907101754394,7.4162714498559694])
10611         self.assertTrue(f.getArray().isEqual(valuesExpected,1e-12))
10612         pass
10613
10614     def testDAPushBack(self):
10615         d=DataArrayDouble(0,1)
10616         for i in xrange(8):
10617             d.pushBackSilent(i)
10618             pass
10619         self.assertEqual(d.getNumberOfTuples(),8)
10620         self.assertEqual(d.getNbOfElemAllocated(),8)
10621         d.pushBackSilent(4.44)
10622         self.assertEqual(d.getNumberOfTuples(),9)
10623         self.assertEqual(d.getNbOfElemAllocated(),16)
10624         self.assertTrue(d.isEqual(DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.,4.44]),1e-12))
10625         e=d.deepCpy()
10626         self.assertEqual(e.getNumberOfTuples(),9)
10627         self.assertEqual(e.getNbOfElemAllocated(),9)
10628         self.assertTrue(e.isEqual(DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.,4.44]),1e-12))
10629         self.assertAlmostEqual(d.popBackSilent(),4.44,12)
10630         self.assertEqual(d.getNumberOfTuples(),8)
10631         self.assertEqual(d.getNbOfElemAllocated(),16)
10632         self.assertTrue(d.isEqual(DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.]),1e-12))
10633         f=DataArrayDouble()
10634         f.reserve(1000)
10635         f.pushBackSilent(4.)
10636         self.assertTrue(f.isEqual(DataArrayDouble([4.]),1e-12))
10637         self.assertEqual(f.getNumberOfTuples(),1)
10638         self.assertEqual(f.getNbOfElemAllocated(),1000)
10639         ff=f[:]
10640         self.assertTrue(ff.isEqual(DataArrayDouble([4.]),1e-12))
10641         self.assertEqual(ff.getNumberOfTuples(),1)
10642         self.assertEqual(ff.getNbOfElemAllocated(),1)
10643         d=DataArrayDouble()
10644         d.pushBackSilent(4.44)
10645         d.pushBackSilent(5.55)
10646         d.pushBackSilent(6.66)
10647         self.assertTrue(d.isEqual(DataArrayDouble([4.44,5.55,6.66]),1e-12))
10648         #
10649         d=DataArrayInt(0,1)
10650         for i in xrange(8):
10651             d.pushBackSilent(i)
10652             pass
10653         self.assertEqual(d.getNumberOfTuples(),8)
10654         self.assertEqual(d.getNbOfElemAllocated(),8)
10655         d.pushBackSilent(444)
10656         self.assertEqual(d.getNumberOfTuples(),9)
10657         self.assertEqual(d.getNbOfElemAllocated(),16)
10658         self.assertTrue(d.isEqual(DataArrayInt([0,1,2,3,4,5,6,7,444])))
10659         e=d.deepCpy()
10660         self.assertEqual(e.getNumberOfTuples(),9)
10661         self.assertEqual(e.getNbOfElemAllocated(),9)
10662         self.assertTrue(e.isEqual(DataArrayInt([0,1,2,3,4,5,6,7,444])))
10663         self.assertEqual(d.popBackSilent(),444)
10664         self.assertEqual(d.getNumberOfTuples(),8)
10665         self.assertEqual(d.getNbOfElemAllocated(),16)
10666         self.assertTrue(d.isEqual(DataArrayInt([0,1,2,3,4,5,6,7])))
10667         f=DataArrayInt()
10668         f.reserve(1000)
10669         f.pushBackSilent(4)
10670         self.assertTrue(f.isEqual(DataArrayInt([4])))
10671         self.assertEqual(f.getNumberOfTuples(),1)
10672         self.assertEqual(f.getNbOfElemAllocated(),1000)
10673         ff=f[:]
10674         self.assertTrue(ff.isEqual(DataArrayInt([4])))
10675         self.assertEqual(ff.getNumberOfTuples(),1)
10676         self.assertEqual(ff.getNbOfElemAllocated(),1)
10677         d=DataArrayInt()
10678         d.pushBackSilent(444)
10679         d.pushBackSilent(555)
10680         d.pushBackSilent(666)
10681         self.assertTrue(d.isEqual(DataArrayInt([444,555,666])))
10682         #
10683         d=DataArrayInt()
10684         d.alloc(10,1)
10685         d.setInfoOnComponent(0,"ABC")
10686         d.setName("dEf")
10687         d.iota(7)
10688         e=DataArrayInt([7,8,9,10,11,12,13,14,15,16]) ; e.copyStringInfoFrom(d) ; self.assertTrue(d.isEqual(e))
10689         self.assertEqual(10,d.getNbOfElemAllocated())
10690         d.pushBackSilent(55)
10691         e=DataArrayInt([7,8,9,10,11,12,13,14,15,16,55]) ; e.copyStringInfoFrom(d) ; self.assertTrue(d.isEqual(e))
10692         self.assertEqual(20,d.getNbOfElemAllocated())
10693         d.reserve(4)
10694         e=DataArrayInt([7,8,9,10]) ; e.copyStringInfoFrom(d) ; self.assertTrue(d.isEqual(e))
10695         self.assertEqual(4,d.getNbOfElemAllocated())
10696         d.pushBackSilent(5)
10697         e=DataArrayInt([7,8,9,10,5]) ; e.copyStringInfoFrom(d) ; self.assertTrue(d.isEqual(e))
10698         self.assertEqual(8,d.getNbOfElemAllocated())
10699         self.assertEqual(5,d.popBackSilent())
10700         e=DataArrayInt([7,8,9,10]) ; e.copyStringInfoFrom(d) ; self.assertTrue(d.isEqual(e))
10701         self.assertEqual(8,d.getNbOfElemAllocated())
10702         self.assertRaises(OverflowError,d.reserve,-1)
10703         e=DataArrayInt([7,8,9,10]) ; e.copyStringInfoFrom(d) ; self.assertTrue(d.isEqual(e))
10704         self.assertEqual(8,d.getNbOfElemAllocated())
10705         d.reserve(0)
10706         e=DataArrayInt([]) ; e.setInfoOnComponent(0,"ABC") ; e.setName("dEf") ; self.assertTrue(d.isEqual(e))
10707         self.assertEqual(0,d.getNbOfElemAllocated())
10708         #
10709         d=DataArrayDouble()
10710         d.alloc(10,1)
10711         d.setInfoOnComponent(0,"ABC")
10712         d.setName("dEf")
10713         d.iota(7)
10714         e=DataArrayDouble([7,8,9,10,11,12,13,14,15,16]) ; e.copyStringInfoFrom(d) ; self.assertTrue(d.isEqual(e,1e-14))
10715         self.assertEqual(10,d.getNbOfElemAllocated())
10716         d.pushBackSilent(55)
10717         e=DataArrayDouble([7,8,9,10,11,12,13,14,15,16,55]) ; e.copyStringInfoFrom(d) ; self.assertTrue(d.isEqual(e,1e-14))
10718         self.assertEqual(20,d.getNbOfElemAllocated())
10719         d.reserve(4)
10720         e=DataArrayDouble([7,8,9,10]) ; e.copyStringInfoFrom(d) ; self.assertTrue(d.isEqual(e,1e-14))
10721         self.assertEqual(4,d.getNbOfElemAllocated())
10722         d.pushBackSilent(5)
10723         e=DataArrayDouble([7,8,9,10,5]) ; e.copyStringInfoFrom(d) ; self.assertTrue(d.isEqual(e,1e-14))
10724         self.assertEqual(8,d.getNbOfElemAllocated())
10725         self.assertEqual(5.,d.popBackSilent())
10726         e=DataArrayDouble([7,8,9,10]) ; e.copyStringInfoFrom(d) ; self.assertTrue(d.isEqual(e,1e-14))
10727         self.assertEqual(8,d.getNbOfElemAllocated())
10728         self.assertRaises(OverflowError,d.reserve,-1)
10729         e=DataArrayDouble([7,8,9,10]) ; e.copyStringInfoFrom(d) ; self.assertTrue(d.isEqual(e,1e-14))
10730         self.assertEqual(8,d.getNbOfElemAllocated())
10731         d.reserve(0)
10732         e=DataArrayDouble([]) ; e.setInfoOnComponent(0,"ABC") ; e.setName("dEf") ; self.assertTrue(d.isEqual(e,1e-14))
10733         self.assertEqual(0,d.getNbOfElemAllocated())
10734         pass
10735
10736     def testDAIBuildSubstractionOptimized1(self):
10737         da1=DataArrayInt.New([1,3,5,6,7,9,13])
10738         da2=DataArrayInt.New([3,5,9])
10739         da3=DataArrayInt.New([1,3,5])
10740         da4=DataArrayInt.New([1,3,5,6,7,9,13])
10741         #
10742         a=da1.buildSubstractionOptimized(da2);
10743         self.assertTrue(a.isEqual(DataArrayInt([1,6,7,13])));
10744         #
10745         a=da1.buildSubstractionOptimized(da3);
10746         self.assertTrue(a.isEqual(DataArrayInt([6,7,9,13])));
10747         #
10748         a=da1.buildSubstractionOptimized(da4);
10749         self.assertTrue(a.isEqual(DataArrayInt([])));
10750         pass
10751
10752     def testDAIIsStrictlyMonotonic1(self):
10753         da1=DataArrayInt.New([1,3,5,6,7,9,13])
10754         self.assertTrue(da1.isStrictlyMonotonic(True));
10755         da1.checkStrictlyMonotonic(True);
10756         self.assertTrue(da1.isMonotonic(True));
10757         da1.checkMonotonic(True);
10758         self.assertTrue(not da1.isStrictlyMonotonic(False));
10759         self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,False)
10760         self.assertTrue(not da1.isMonotonic(False));
10761         self.assertRaises(InterpKernelException,da1.checkMonotonic,False)
10762         #
10763         da1=DataArrayInt.New([1,3,5,6,6,9,13])
10764         self.assertTrue(not da1.isStrictlyMonotonic(True));
10765         self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,True)
10766         self.assertTrue(da1.isMonotonic(True));
10767         da1.checkMonotonic(True);
10768         self.assertTrue(not da1.isStrictlyMonotonic(False));
10769         self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,False)
10770         self.assertTrue(not da1.isMonotonic(False));
10771         self.assertRaises(InterpKernelException,da1.checkMonotonic,False)
10772         #
10773         da1=DataArrayInt.New([1,3,5,6,5,9,13])
10774         self.assertTrue(not da1.isStrictlyMonotonic(True));
10775         self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,True)
10776         self.assertTrue(not da1.isMonotonic(True));
10777         self.assertRaises(InterpKernelException,da1.checkMonotonic,True)
10778         self.assertTrue(not da1.isStrictlyMonotonic(False));
10779         self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,False)
10780         self.assertTrue(not da1.isMonotonic(False));
10781         self.assertRaises(InterpKernelException,da1.checkMonotonic,False)
10782         #
10783         da1=DataArrayInt.New([13,9,7,6,5,3,1])
10784         self.assertTrue(not da1.isStrictlyMonotonic(True));
10785         self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,True)
10786         self.assertTrue(not da1.isMonotonic(True));
10787         self.assertRaises(InterpKernelException,da1.checkMonotonic,True)
10788         self.assertTrue(da1.isStrictlyMonotonic(False));
10789         da1.checkStrictlyMonotonic(False);
10790         self.assertTrue(da1.isMonotonic(False));
10791         da1.checkMonotonic(False);
10792         #
10793         da1=DataArrayInt.New([13,9,6,6,5,3,1])
10794         self.assertTrue(not da1.isStrictlyMonotonic(True));
10795         self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,True)
10796         self.assertTrue(not da1.isMonotonic(True));
10797         self.assertRaises(InterpKernelException,da1.checkMonotonic,True)
10798         self.assertTrue(not da1.isStrictlyMonotonic(False));
10799         self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,False)
10800         self.assertTrue(da1.isMonotonic(False));
10801         da1.checkMonotonic(False);
10802         #
10803         da1=DataArrayInt.New([13,9,5,6,5,3,1])
10804         self.assertTrue(not da1.isStrictlyMonotonic(True));
10805         self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,True)
10806         self.assertTrue(not da1.isMonotonic(True));
10807         self.assertRaises(InterpKernelException,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([])
10814         self.assertTrue(da1.isStrictlyMonotonic(True));
10815         da1.checkStrictlyMonotonic(True);
10816         self.assertTrue(da1.isMonotonic(True));
10817         da1.checkMonotonic(True);
10818         self.assertTrue(da1.isStrictlyMonotonic(False));
10819         da1.checkStrictlyMonotonic(False);
10820         self.assertTrue(da1.isMonotonic(False));
10821         da1.checkMonotonic(False);
10822         #
10823         da1=DataArrayInt.New([13])
10824         self.assertTrue(da1.isStrictlyMonotonic(True));
10825         da1.checkStrictlyMonotonic(True);
10826         self.assertTrue(da1.isMonotonic(True));
10827         da1.checkMonotonic(True);
10828         self.assertTrue(da1.isStrictlyMonotonic(False));
10829         da1.checkStrictlyMonotonic(False);
10830         self.assertTrue(da1.isMonotonic(False));
10831         da1.checkMonotonic(False);
10832         pass
10833
10834     def testFindAndCorrectBadOriented3DCells1(self):
10835         nbOfDisc=20
10836         vects=([0,0,-1],[0.3,0.7,0.2],[-0.3,0.7,0.2],[-0.3,-0.7,0.2])
10837         #
10838         m0=MEDCouplingUMesh("m",3) ; m0.allocateCells(0); m0.insertNextCell(NORM_TETRA4,[0,1,2,3]); #Well oriented
10839         m1=MEDCouplingUMesh("m",3) ; m1.allocateCells(0); m1.insertNextCell(NORM_PYRA5,[0,1,2,3,4]); #Well oriented
10840         m2=MEDCouplingUMesh("m",3) ; m2.allocateCells(0); m2.insertNextCell(NORM_PENTA6,[0,1,2,3,4,5]); #Well oriented 
10841         m3=MEDCouplingUMesh("m",3) ; m3.allocateCells(0); m3.insertNextCell(NORM_HEXA8,[0,1,2,3,4,5,6,7]); #Well oriented
10842         m4=MEDCouplingUMesh("m",3) ; m4.allocateCells(0)
10843         self.assertRaises(InterpKernelException,m4.insertNextCell,NORM_HEXGP12,[0,1,2,3,4,5,6,7,8,9,10,11,12]);
10844         m4.insertNextCell(NORM_HEXGP12,[0,1,2,3,4,5,6,7,8,9,10,11]); #Well oriented
10845         c0=DataArrayDouble([0.,0.,0.,0.,1.,0.,1.,0.,0.,0.,0.,1.],4,3) ; m0.setCoords(c0)
10846         c1=DataArrayDouble([0.,0.,0.,0.,1.,0.,1.,1.,0.,1.,0.,0.,0.,0.,1.],5,3) ; m1.setCoords(c1)
10847         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)
10848         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)
10849         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)
10850         m=MEDCouplingMesh.MergeMeshes([m0,m1,m2,m3,m4])
10851         expected1=DataArrayDouble([0.16666666666666666,0.3333333333333333,0.5,1.,1.])
10852         for v in vects:
10853             for i in xrange(nbOfDisc):
10854                 mm=m.deepCpy()
10855                 mm.rotate([0.,0.,0.],[0.3,0.7,0.2],float(i)/float(nbOfDisc)*2*pi)
10856                 mm2=mm.deepCpy()
10857                 self.assertTrue(mm.getMeasureField(False).getArray().isEqual(expected1,1e-14))
10858                 self.assertTrue(mm.findAndCorrectBadOriented3DCells().empty())
10859                 self.assertTrue(mm.isEqual(mm2,1e-14))
10860                 self.assertTrue(mm.getMeasureField(False).getArray().isEqual(expected1,1e-14))
10861                 mm.convertAllToPoly()
10862                 self.assertTrue(mm.getMeasureField(False).getArray().isEqual(expected1,1e-14))
10863                 pass
10864             pass
10865         #
10866         mOK=m.deepCpy()
10867         m0=MEDCouplingUMesh("m",3) ; m0.allocateCells(0); m0.insertNextCell(NORM_TETRA4,[0,2,1,3]); #Not well oriented
10868         m1=MEDCouplingUMesh("m",3) ; m1.allocateCells(0); m1.insertNextCell(NORM_PYRA5,[0,1,2,3,4]); #Well oriented 
10869         m2=MEDCouplingUMesh("m",3) ; m2.allocateCells(0); m2.insertNextCell(NORM_PENTA6,[0,1,2,3,4,5]); #Well oriented 
10870         m3=MEDCouplingUMesh("m",3) ; m3.allocateCells(0); m3.insertNextCell(NORM_HEXA8,[0,3,2,1,4,7,6,5]); #Not well oriented
10871         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
10872         m0.setCoords(c0) ; m1.setCoords(c1) ; m2.setCoords(c2) ; m3.setCoords(c3) ; m4.setCoords(c4)
10873         m=MEDCouplingMesh.MergeMeshes([m0,m1,m2,m3,m4])
10874         expected2=DataArrayDouble([-0.16666666666666666,0.3333333333333333,0.5,-1.,-1.])
10875         for v in vects:
10876             for i in xrange(nbOfDisc):
10877                 mm=m.deepCpy()
10878                 mm.rotate([0.,0.,0.],[0.3,0.7,0.2],float(i)/float(nbOfDisc)*2*pi)
10879                 mm2=mm.deepCpy() ; mm3=mm.deepCpy() ; mm3.convertAllToPoly()
10880                 self.assertTrue(mm3.getMeasureField(False).getArray().isEqual(expected2,1e-14))
10881                 self.assertTrue(mm.getMeasureField(False).getArray().isEqual(expected2,1e-14))
10882                 self.assertTrue(mm.findAndCorrectBadOriented3DCells().isEqual(DataArrayInt([0,3,4])))
10883                 mOK.setCoords(mm.getCoords())
10884                 self.assertTrue(mm.isEqual(mOK,1e-14))
10885                 self.assertTrue(mm.getMeasureField(False).getArray().isEqual(expected1,1e-14))
10886                 mmm=mm.deepCpy()
10887                 self.assertTrue(mmm.findAndCorrectBadOriented3DCells().empty())
10888                 mm.convertAllToPoly()
10889                 self.assertTrue(mm.getMeasureField(False).getArray().isEqual(expected1,1e-14))
10890                 pass
10891             pass
10892         #
10893         m0=MEDCouplingUMesh("m",3) ; m0.allocateCells(0); m0.insertNextCell(NORM_TETRA4,[0,1,2,3]); #Well oriented
10894         m1=MEDCouplingUMesh("m",3) ; m1.allocateCells(0); m1.insertNextCell(NORM_PYRA5,[0,3,2,1,4]); #Not well oriented 
10895         m2=MEDCouplingUMesh("m",3) ; m2.allocateCells(0); m2.insertNextCell(NORM_PENTA6,[0,2,1,3,5,4]); #Not well oriented 
10896         m3=MEDCouplingUMesh("m",3) ; m3.allocateCells(0); m3.insertNextCell(NORM_HEXA8,[0,1,2,3,4,5,6,7]); #Well oriented
10897         m4=MEDCouplingUMesh("m",3) ; m4.allocateCells(0); m4.insertNextCell(NORM_HEXGP12,range(12)); #Well oriented
10898         m0.setCoords(c0) ; m1.setCoords(c1) ; m2.setCoords(c2) ; m3.setCoords(c3) ; m4.setCoords(c4)
10899         m=MEDCouplingMesh.MergeMeshes([m0,m1,m2,m3,m4])
10900         expected3=DataArrayDouble([0.16666666666666666,-0.3333333333333333,-0.5,1.,1.])
10901         for v in vects:
10902             for i in xrange(nbOfDisc):
10903                 mm=m.deepCpy()
10904                 mm.rotate([0.,0.,0.],[0.3,0.7,0.2],float(i)/float(nbOfDisc)*2*pi)
10905                 mm2=mm.deepCpy() ; mm3=mm.deepCpy() ; mm3.convertAllToPoly()
10906                 self.assertTrue(mm3.getMeasureField(False).getArray().isEqual(expected3,1e-14))
10907                 self.assertTrue(mm.getMeasureField(False).getArray().isEqual(expected3,1e-14))
10908                 self.assertTrue(mm.findAndCorrectBadOriented3DCells().isEqual(DataArrayInt([1,2])))
10909                 mOK.setCoords(mm.getCoords())
10910                 self.assertTrue(mm.isEqual(mOK,1e-14))
10911                 self.assertTrue(mm.getMeasureField(False).getArray().isEqual(expected1,1e-14))
10912                 mmm=mm.deepCpy()
10913                 self.assertTrue(mmm.findAndCorrectBadOriented3DCells().empty())
10914                 mm.convertAllToPoly()
10915                 self.assertTrue(mm.getMeasureField(False).getArray().isEqual(expected1,1e-14))
10916                 pass
10917             pass
10918         pass
10919
10920     def testSwig2CellOrientation1(self):
10921         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)
10922         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]]
10923         for i in xrange(256):
10924             mesh=MEDCouplingUMesh("FluidMesh_1",3);
10925             mesh.allocateCells(0)
10926             conn2=[elt[:] for elt in conn]
10927             code=bin(i)[2:] ; code='0'*(8-len(code))+code
10928             for face,rev in zip(conn2,code):
10929                 if bool(int(rev)):
10930                     face.reverse()
10931                     pass
10932                 pass
10933             conn3=[elt+[-1] for elt in conn2]
10934             conn3=sum(conn3,[])[:-1]
10935             mesh.insertNextCell(NORM_POLYHED,conn3)
10936             mesh.setCoords(coords)
10937             mesh.orientCorrectlyPolyhedrons()
10938             self.assertTrue(mesh.getBarycenterAndOwner().isEqual(DataArrayDouble([-0.10803,0.,0.3385],1,3),1e-12))
10939             pass
10940         pass
10941
10942     def testSwig2CheckConsecutiveCellTypesForMEDFileFrmt1(self):
10943         m1=MEDCouplingUMesh("",2) ; m1.allocateCells(0)
10944         m1.insertNextCell(NORM_QUAD4,[0,1,2,3])
10945         m1.insertNextCell(NORM_TRI3,[0,1,2])
10946         d=DataArrayDouble(4,3) ; d[:]=0.
10947         m1.setCoords(d)
10948         self.assertTrue(m1.checkConsecutiveCellTypes())
10949         self.assertTrue(not m1.checkConsecutiveCellTypesForMEDFileFrmt())
10950         m1.renumberCells([1,0])
10951         self.assertTrue(m1.checkConsecutiveCellTypes())
10952         self.assertTrue(m1.checkConsecutiveCellTypesForMEDFileFrmt())
10953         pass
10954
10955     def testSwig2DAAccumulate1(self):
10956         d=DataArrayInt(10) ; d.iota(0)
10957         self.assertEqual([45],d.accumulate())
10958         self.assertEqual(45,d.accumulate(0))
10959         d=DataArrayInt(30) ; d.iota(0) ; d.rearrange(3)
10960         self.assertEqual([135,145,155],d.accumulate())
10961         self.assertEqual(135,d.accumulate(0))
10962         self.assertEqual(145,d.accumulate(1))
10963         self.assertEqual(155,d.accumulate(2))
10964         d=DataArrayDouble(10) ; d.iota(0.)
10965         self.assertEqual([45.],d.accumulate())
10966         self.assertEqual(45.,d.accumulate(0))
10967         d=DataArrayDouble(30) ; d.iota(0) ; d.rearrange(3)
10968         self.assertEqual([135.,145.,155.],d.accumulate())
10969         self.assertEqual(135.,d.accumulate(0))
10970         self.assertEqual(145.,d.accumulate(1))
10971         self.assertEqual(155.,d.accumulate(2))
10972         pass
10973
10974     def testSwig2UMeshDistanceToMesh1(self):
10975         m=MEDCouplingUMesh("toto",2)
10976         coords=DataArrayDouble([2.3,3.4,5.6,6.5,-4.3,3.2,-9.8,7.6,-5.4],3,3)
10977         m.setCoords(coords)
10978         m.allocateCells(0)
10979         m.insertNextCell(NORM_TRI3,[0,1,2])
10980         a,b=m.distanceToPoint([-0.335,2.27,1.21])
10981         self.assertEqual(0,b)
10982         self.assertAlmostEqual(0.022360988100374124,a,14);
10983         a,b=m.distanceToPoint(DataArrayDouble([-0.335,2.27,1.21],1,3))
10984         self.assertEqual(0,b)
10985         self.assertAlmostEqual(0.022360988100374124,a,14);
10986         a,b=coords.distanceToTuple([-0.335,2.27,1.21])
10987         self.assertAlmostEqual(5.243302871282566,a,14)
10988         self.assertEqual(0,b)
10989         #
10990         m=MEDCouplingUMesh("toto",2)
10991         coords=DataArrayDouble([0.,0.,0., 8.,0.,0., 8.,8.,0., 0.,8.,0.],4,3)
10992         m.setCoords(coords)
10993         m.allocateCells(0)
10994         m.insertNextCell(NORM_QUAD4,[0,1,2,3])
10995         m.checkCoherency2()
10996         self.assertEqual([4,0,1,2,3],m.getNodalConnectivity().getValues())
10997         a,b=m.distanceToPoint([5.,2.,0.1])
10998         self.assertAlmostEqual(0.1,a,14) ; self.assertEqual(0,b)
10999         a,b=m.distanceToPoint([5.,-2.,4.])
11000         self.assertAlmostEqual(sqrt(2*2+4*4),a,14) ; self.assertEqual(0,b)
11001         m.allocateCells(0)
11002         m.insertNextCell(NORM_POLYGON,[0,1,2,3])
11003         m.checkCoherency2()
11004         self.assertEqual([5,0,1,2,3],m.getNodalConnectivity().getValues())
11005         a,b=m.distanceToPoint([11.,3.,4.])
11006         self.assertAlmostEqual(sqrt(3*3+4*4),a,14) ; self.assertEqual(0,b)
11007         a,b=m.distanceToPoint([4.,12.,5.])
11008         self.assertAlmostEqual(sqrt(4*4+5*5),a,14) ; self.assertEqual(0,b)
11009         d=DataArrayDouble([-1.2,3.,2.],1,3)
11010         for elt in d:
11011             a,b=m.distanceToPoint(d)
11012             self.assertAlmostEqual(sqrt(1.2*1.2+2*2),a,14) ; self.assertEqual(0,b)
11013             pass
11014         #
11015         m=MEDCouplingUMesh("toto",1)
11016         coords=DataArrayDouble([0.,0.,4.,0.,0.,4.],3,2) ; m.setCoords(coords)
11017         m.allocateCells(0) ; m.insertNextCell(NORM_SEG2,[0,1]) ; m.insertNextCell(NORM_SEG2,[1,2])
11018         a,b=m.distanceToPoint([-0.1,4.1])
11019         self.assertAlmostEqual(0.14142135623730925,a,14)  # b==1 self.assertEqual(2,c)
11020         a,b=m.distanceToPoint([0.,3.9])
11021         self.assertAlmostEqual(0.07071067811865482,a,14) ; self.assertEqual(1,b) # self.assertEqual(2,c)
11022         pass
11023
11024     def testSwig2NonRegressionPartitionBySpreadZone1(self):
11025         m=MEDCouplingCMesh()
11026         arr=DataArrayDouble(6) ; arr.iota(0.)
11027         m.setCoords(arr,arr,arr)
11028         m=m.buildUnstructured()
11029         mPart=m[50,80,85,87,92,122]
11030         zones=mPart.partitionBySpreadZone()
11031         self.assertEqual(4,len(zones))
11032         self.assertTrue(zones[0].isEqual(DataArrayInt([0])))
11033         self.assertTrue(zones[1].isEqual(DataArrayInt([1,2])))
11034         self.assertTrue(zones[2].isEqual(DataArrayInt([3,4])))
11035         self.assertTrue(zones[3].isEqual(DataArrayInt([5])))
11036         #
11037         n,ni=m.computeNeighborsOfCells()
11038         a,b=MEDCouplingUMesh.ComputeSpreadZoneGraduallyFromSeed(0,n,ni)
11039         self.assertEqual(13,b) ; self.assertEqual(125,len(a)) ; self.assertTrue(a.isIdentity())
11040         a,b=MEDCouplingUMesh.ComputeSpreadZoneGraduallyFromSeed([1],n,ni)
11041         self.assertEqual(12,b) ; self.assertEqual(125,len(a)) ; self.assertTrue(a.isIdentity())
11042         a,b=MEDCouplingUMesh.ComputeSpreadZoneGraduallyFromSeed((2,),n,ni)
11043         self.assertEqual(11,b) ; self.assertEqual(125,len(a)) ; self.assertTrue(a.isIdentity())
11044         a,b=MEDCouplingUMesh.ComputeSpreadZoneGraduallyFromSeed(DataArrayInt([3]),n,ni)
11045         self.assertEqual(12,b) ; self.assertEqual(125,len(a)) ; self.assertTrue(a.isIdentity())
11046         pass
11047
11048     def testSwigUMeshInsertNextCell1(self):
11049         m=MEDCouplingUMesh("toto",2)
11050         #
11051         coords=DataArrayDouble([0.,0.,1.,1.,1.,0.]) ; m.setCoords(coords)
11052         da=DataArrayInt([0,1,2])
11053         m.allocateCells(0)
11054         for i in xrange(5):
11055             m.insertNextCell(NORM_TRI3,da)
11056             pass
11057         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])))
11058         self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,8,12,16,20])))
11059         #
11060         da=DataArrayInt([0,1,2,3])
11061         m.allocateCells(0)
11062         for i in xrange(5):
11063             m.insertNextCell(NORM_TRI3,3,da)
11064             pass
11065         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])))
11066         self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,8,12,16,20])))
11067         #
11068         da=DataArrayInt([0,1])
11069         m.allocateCells(0)
11070         self.assertRaises(InterpKernelException,m.insertNextCell,NORM_TRI3,3,da)
11071         #
11072         da=DataArrayInt([0,1,2,0,1,3,0,1,4,0,1,5,0,1,6],5,3)
11073         m.allocateCells(0)
11074         for t in da:
11075             m.insertNextCell(NORM_TRI3,t)
11076             pass
11077         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])))
11078         self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,8,12,16,20])))
11079         self.assertRaises(InterpKernelException,m.insertNextCell,NORM_TRI3,None)
11080         pass
11081
11082     def testSwigCurveLinearMesh1(self):
11083         m=MEDCouplingCurveLinearMesh("toto")
11084         m.setNodeGridStructure([2,3])
11085         coords=DataArrayDouble([0.,0., 2.,0., 0.,1., 1.9,1.1, 0.3,1.9, 2.2,2.1],6,2)
11086         m.setCoords(coords)
11087         m.checkCoherency()
11088         m0=m.deepCpy()
11089         self.assertTrue(m0.isEqual(m,1e-12))
11090         m.getCoords().setInfoOnComponents(["X [m]","Y [m]"])
11091         self.assertTrue(not m0.isEqual(m,1e-12))
11092         m0=m.deepCpy()
11093         self.assertTrue(m0.isEqual(m,1e-12))
11094         self.assertEqual(m.getNodeGridStructure(),(2,3))
11095         pass
11096
11097     def testSimplexize3(self):
11098         m=MEDCouplingUMesh("toto",3)
11099         m.allocateCells(0)
11100         m.insertNextCell(NORM_TETRA4,[0,1,2,3])
11101         self.assertEqual([NORM_TETRA4],m.getAllGeoTypesSorted())
11102         m.insertNextCell(NORM_HEXA8,[4,5,6,7,8,9,10,11])
11103         self.assertEqual([NORM_TETRA4,NORM_HEXA8],m.getAllGeoTypesSorted())
11104         m.insertNextCell(NORM_HEXA8,[12,13,14,15,16,17,18,19])
11105         self.assertEqual([NORM_TETRA4,NORM_HEXA8],m.getAllGeoTypesSorted())
11106         m.insertNextCell(NORM_TETRA4,[20,21,22,23])
11107         self.assertEqual([NORM_TETRA4,NORM_HEXA8,NORM_TETRA4],m.getAllGeoTypesSorted())
11108         c1=DataArrayDouble([0.,0.,0.,0.,1.,0.,1.,0.,0.,0.,0.,1.],4,3)
11109         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.]
11110         c3=c2+[2.,0.,0.]
11111         c4=c1+[6.,0.,0.]
11112         c=DataArrayDouble.Aggregate([c1,c2,c3,c4])
11113         m.setCoords(c)
11114         m.checkCoherency2()
11115         #
11116         m1=m.deepCpy()
11117         d1=m1.simplexize(PLANAR_FACE_5)
11118         m1.checkCoherency2()
11119         vol1=m1.getMeasureField(ON_CELLS).getArray()
11120         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))
11121         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])
11122         self.assertEqual(m1.getNodalConnectivityIndex().getValues(),[0,5,10,15,20,25,30,35,40,45,50,55,60])
11123         self.assertTrue(d1.isEqual(DataArrayInt([0,1,1,1,1,1,2,2,2,2,2,3])))
11124         #
11125         m2=m.deepCpy()
11126         d2=m2.simplexize(PLANAR_FACE_6)
11127         m2.checkCoherency2()
11128         vol2=m2.getMeasureField(ON_CELLS).getArray()
11129         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))
11130         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])
11131         self.assertEqual(m2.getNodalConnectivityIndex().getValues(),[0,5,10,15,20,25,30,35,40,45,50,55,60,65,70])
11132         self.assertTrue(d2.isEqual(DataArrayInt([0,1,1,1,1,1,1,2,2,2,2,2,2,3])))
11133         pass
11134
11135     def testSwig2CurveLinearMesh2(self):
11136         c=MEDCouplingCMesh()
11137         #2D
11138         arr1=DataArrayDouble([0,1,3,7])
11139         arr2=DataArrayDouble([0,1,1.5])
11140         c.setCoords(arr1,arr2)
11141         u=c.buildUnstructured()
11142         coo=u.getCoords()
11143         cl=MEDCouplingCurveLinearMesh()
11144         cl.setCoords(coo)
11145         cl.setNodeGridStructure([4,3])
11146         cl.checkCoherency2()
11147         li1=[1.,2.,4.,0.5,1.,2.]
11148         self.assertTrue(cl.getMeasureField(False).getArray().isEqual(DataArrayDouble(li1),1e-14))
11149         self.assertTrue(u.getMeasureField(False).getArray().isEqual(DataArrayDouble(li1),1e-14))
11150         li1_1=[0.5,0.5,2.,0.5,5.,0.5,0.5,1.25,2.,1.25,5.,1.25]
11151         self.assertTrue(cl.getBarycenterAndOwner().isEqual(DataArrayDouble(li1_1,6,2),1e-14))
11152         self.assertTrue(u.getBarycenterAndOwner().isEqual(DataArrayDouble(li1_1,6,2),1e-14))
11153         #3D
11154         c.setCoords(arr1,arr2,arr2)
11155         u=c.buildUnstructured()
11156         coo=u.getCoords()
11157         cl=MEDCouplingCurveLinearMesh()
11158         cl.setCoords(coo)
11159         cl.setNodeGridStructure([4,3,3])
11160         cl.checkCoherency2()
11161         li2=[1.,2.,4.,0.5, 1.,2.,0.5,1.,2.,0.25,0.5,1.]
11162         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]
11163         self.assertTrue(cl.getMeasureField(False).getArray().isEqual(DataArrayDouble(li2),1e-14))
11164         self.assertTrue(u.getMeasureField(False).getArray().isEqual(DataArrayDouble(li2),1e-14))
11165         self.assertTrue(cl.getBarycenterAndOwner().isEqual(DataArrayDouble(li2_1,12,3),1e-14))
11166         self.assertTrue(u.getBarycenterAndOwner().isEqual(DataArrayDouble(li2_1,12,3),1e-14))
11167         #1D spaceDim 1
11168         coo=DataArrayDouble(5) ; coo.iota(0.)
11169         coo=coo*coo
11170         cl.setCoords(coo)
11171         cl.setNodeGridStructure([5])
11172         cl.checkCoherency2()
11173         li3=[1.,3.,5.,7.]
11174         li3_1=[0.5,2.5,6.5,12.5]
11175         self.assertTrue(cl.getMeasureField(False).getArray().isEqual(DataArrayDouble(li3),1e-14))
11176         self.assertTrue(cl.buildUnstructured().getMeasureField(False).getArray().isEqual(DataArrayDouble(li3),1e-14))
11177         self.assertTrue(cl.getBarycenterAndOwner().isEqual(DataArrayDouble(li3_1),1e-14))
11178         self.assertTrue(cl.buildUnstructured().getBarycenterAndOwner().isEqual(DataArrayDouble(li3_1),1e-14))
11179         #1D spaceDim 2
11180         coo=DataArrayDouble.Meld(coo,coo)
11181         cl.setCoords(coo)
11182         cl.checkCoherency2()
11183         li4=[sqrt(2.)*elt for elt in [1.,3.,5.,7.]]
11184         li4_1=[0.5,0.5,2.5,2.5,6.5,6.5,12.5,12.5]
11185         self.assertTrue(cl.getMeasureField(False).getArray().isEqual(DataArrayDouble(li4),1e-14))
11186         self.assertTrue(cl.buildUnstructured().getMeasureField(False).getArray().isEqual(DataArrayDouble(li4),1e-14))
11187         self.assertTrue(cl.getBarycenterAndOwner().isEqual(DataArrayDouble(li4_1,4,2),1e-14))
11188         self.assertTrue(cl.buildUnstructured().getBarycenterAndOwner().isEqual(DataArrayDouble(li4_1,4,2),1e-14))
11189         pass
11190
11191     def testSwig2CurveLinearMeshNonRegression1(self):
11192         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)
11193         m=MEDCouplingCurveLinearMesh("toto")
11194         m.setCoords(coords)
11195         m.setNodeGridStructure([3,3,3])
11196         #
11197         vol=m.getMeasureField(False).getArray()
11198         self.assertTrue(vol.isEqual(DataArrayDouble([0.11450000709295281, 0.10583334351579375,0.11149999939029423,0.08866666863113633, 0.1404166805123294,0.1250000135352219,0.1270833433481557,0.13258334288001067]),1e-12))
11199         self.assertTrue(vol.isEqual(m.buildUnstructured().getMeasureField(False).getArray(),1e-12))
11200         #
11201         self.assertTrue(m.getBarycenterAndOwner().isEqual(m.buildUnstructured().getBarycenterAndOwner(),1e-12))
11202         pass
11203
11204     def testSwig2NonRegressionDASetSelectedComponents1(self):
11205         da=DataArrayDouble.New([1.,2.,3.,4.,5.,6.],3,2)
11206         dv=DataArrayDouble.New();
11207         dv.alloc(4,4)
11208         dv.fillWithZero()
11209         # da has less tuples than dv
11210         dv.setSelectedComponents(da,[1,0])
11211         #
11212         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))
11213         #
11214         da=DataArrayInt.New([1,2,3,4,5,6],3,2)
11215         dv=DataArrayInt.New();
11216         dv.alloc(4,4)
11217         dv.fillWithZero()
11218         # da has less tuples than dv
11219         dv.setSelectedComponents(da,[1,0])
11220         #
11221         self.assertTrue(dv.isEqual(DataArrayInt([2,1,0,0,4,3,0,0,6,5,0,0,0,0,0,0],4,4)))
11222         pass
11223
11224     def testSwigSetItem3(self):
11225         # 1-2 
11226         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11227         d[3]=[1,2]
11228         self.assertTrue(d.isEqual(DataArrayDouble([0,0,0,0,0,0,1,2,0,0,0,0],6,2),1e-14))
11229         # 2-2 false
11230         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11231         d[[5,3,2]]=[1,2]
11232         self.assertTrue(d.isEqual(DataArrayDouble([0,0,0,0,1,2,1,2,0,0,1,2],6,2),1e-14))
11233         # 3-2 false
11234         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11235         d[:]=[1,2]
11236         self.assertTrue(d.isEqual(DataArrayDouble([1,2,1,2,1,2,1,2,1,2,1,2],6,2),1e-14))
11237         # 4-2 false
11238         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11239         d[DataArrayInt([0,3,4])]=[1,2]
11240         self.assertTrue(d.isEqual(DataArrayDouble([1,2,0,0,0,0,1,2,1,2,0,0],6,2),1e-14))
11241         # 5-2
11242         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11243         d[5,1]=[7]
11244         self.assertTrue(d.isEqual(DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,7],6,2),1e-14))
11245         # 6-2 false
11246         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11247         d[[3,5],1]=[7]
11248         self.assertTrue(d.isEqual(DataArrayDouble([0,0,0,0,0,0,0,7,0,0,0,7],6,2),1e-14))
11249         # 7-2 false
11250         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11251         d[:-1:2,1]=[7]
11252         self.assertTrue(d.isEqual(DataArrayDouble([0,7,0,0,0,7,0,0,0,7,0,0],6,2),1e-14))
11253         # 8-2 false
11254         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11255         d[DataArrayInt([0,3,4]),1]=[7]
11256         self.assertTrue(d.isEqual(DataArrayDouble([0,7,0,0,0,0,0,7,0,7,0,0],6,2),1e-14))
11257         # 9-2
11258         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11259         d[3,[1,0]]=[7,8]
11260         self.assertTrue(d.isEqual(DataArrayDouble([0,0,0,0,0,0,8,7,0,0,0,0],6,2),1e-14))
11261         # 10-2 false
11262         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11263         d[[1,3,4],[1,0]]=[7,8]
11264         self.assertTrue(d.isEqual(DataArrayDouble([0,0,8,7,0,0,8,7,8,7,0,0],6,2),1e-14))
11265         # 11-2 false
11266         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11267         d[1::2,[1,0]]=[7,8]
11268         self.assertTrue(d.isEqual(DataArrayDouble([0,0,8,7,0,0,8,7,0,0,8,7],6,2),1e-14))
11269         # 12-2 false
11270         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11271         d[DataArrayInt([1,4]),[1,0]]=[7,8]
11272         self.assertTrue(d.isEqual(DataArrayDouble([0,0,8,7,0,0,0,0,8,7,0,0],6,2),1e-14))
11273         # 13-2
11274         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11275         d[1,:-1]=[9]
11276         self.assertTrue(d.isEqual(DataArrayDouble([0,0,9,0,0,0,0,0,0,0,0,0],6,2),1e-14))
11277         # 14-2 false
11278         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11279         d[[1,4,5],:]=[7,8]
11280         self.assertTrue(d.isEqual(DataArrayDouble([0,0,7,8,0,0,0,0,7,8,7,8],6,2),1e-14))
11281         # 15-2 false
11282         d=DataArrayDouble([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11283         d[1::2,:]=[3,9]
11284         self.assertTrue(d.isEqual(DataArrayDouble([0,0,3,9,0,0,3,9,0,0,3,9],6,2),1e-14))
11285         # 1-2 
11286         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11287         d[3]=[1,2]
11288         self.assertTrue(d.isEqual(DataArrayInt([0,0,0,0,0,0,1,2,0,0,0,0],6,2)))
11289         # 2-2 false
11290         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11291         d[[5,3,2]]=[1,2]
11292         self.assertTrue(d.isEqual(DataArrayInt([0,0,0,0,1,2,1,2,0,0,1,2],6,2)))
11293         # 3-2 false
11294         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11295         d[:]=[1,2]
11296         self.assertTrue(d.isEqual(DataArrayInt([1,2,1,2,1,2,1,2,1,2,1,2],6,2)))
11297         # 4-2 false
11298         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11299         d[DataArrayInt([0,3,4])]=[1,2]
11300         self.assertTrue(d.isEqual(DataArrayInt([1,2,0,0,0,0,1,2,1,2,0,0],6,2)))
11301         # 5-2
11302         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11303         d[5,1]=[7]
11304         self.assertTrue(d.isEqual(DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,7],6,2)))
11305         # 6-2 false
11306         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11307         d[[3,5],1]=[7]
11308         self.assertTrue(d.isEqual(DataArrayInt([0,0,0,0,0,0,0,7,0,0,0,7],6,2)))
11309         # 7-2 false
11310         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11311         d[:-1:2,1]=[7]
11312         self.assertTrue(d.isEqual(DataArrayInt([0,7,0,0,0,7,0,0,0,7,0,0],6,2)))
11313         # 8-2 false
11314         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11315         d[DataArrayInt([0,3,4]),1]=[7]
11316         self.assertTrue(d.isEqual(DataArrayInt([0,7,0,0,0,0,0,7,0,7,0,0],6,2)))
11317         # 9-2
11318         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11319         d[3,[1,0]]=[7,8]
11320         self.assertTrue(d.isEqual(DataArrayInt([0,0,0,0,0,0,8,7,0,0,0,0],6,2)))
11321         # 10-2 false
11322         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11323         d[[1,3,4],[1,0]]=[7,8]
11324         self.assertTrue(d.isEqual(DataArrayInt([0,0,8,7,0,0,8,7,8,7,0,0],6,2)))
11325         # 11-2 false
11326         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11327         d[1::2,[1,0]]=[7,8]
11328         self.assertTrue(d.isEqual(DataArrayInt([0,0,8,7,0,0,8,7,0,0,8,7],6,2)))
11329         # 12-2 false
11330         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11331         d[DataArrayInt([1,4]),[1,0]]=[7,8]
11332         self.assertTrue(d.isEqual(DataArrayInt([0,0,8,7,0,0,0,0,8,7,0,0],6,2)))
11333         # 13-2
11334         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11335         d[1,:-1]=[9]
11336         self.assertTrue(d.isEqual(DataArrayInt([0,0,9,0,0,0,0,0,0,0,0,0],6,2)))
11337         # 14-2 false
11338         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11339         d[[1,4,5],:]=[7,8]
11340         self.assertTrue(d.isEqual(DataArrayInt([0,0,7,8,0,0,0,0,7,8,7,8],6,2)))
11341         # 15-2 false
11342         d=DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0],6,2)
11343         d[1::2,:]=[3,9]
11344         self.assertTrue(d.isEqual(DataArrayInt([0,0,3,9,0,0,3,9,0,0,3,9],6,2)))
11345         pass
11346
11347     def testSwig2ConvertLinearCellsToQuadratic1(self):
11348         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)
11349         # 2D
11350         m2D=MEDCouplingDataForTest.build2DTargetMesh_1()
11351         m2D.convertLinearCellsToQuadratic(0)
11352         m2D.checkCoherency1()
11353         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])
11354         self.assertEqual(m2D.getNodalConnectivityIndex().getValues(),[0,9,16,23,32,41])
11355         self.assertTrue(m2D.getCoords().isEqual(coordsExp,1e-14))
11356         # 1D
11357         m1D=MEDCouplingDataForTest.build2DTargetMesh_1().buildDescendingConnectivity()[0]
11358         m1D.convertLinearCellsToQuadratic(0)
11359         m1D.checkCoherency1()
11360         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])
11361         self.assertEqual(m1D.getNodalConnectivityIndex().getValues(),[0,4,8,12,16,20,24,28,32,36,40,44,48,52])
11362         self.assertTrue(m1D.getCoords().isEqual(coordsExp,1e-14))
11363         # 3D
11364         m2D=MEDCouplingDataForTest.build2DTargetMesh_1()
11365         m2D.changeSpaceDimension(3)
11366         arr=DataArrayDouble(4);  arr.iota(0) ; z=MEDCouplingCMesh() ; z.setCoords(arr)
11367         m1D=z.buildUnstructured() ; m1D.setCoords(arr.changeNbOfComponents(3,0.))
11368         m1D.getCoords()[:]=m1D.getCoords()[:,[1,2,0]]
11369         cooTmp=m2D.getCoords()[:]
11370         m3D=m2D.buildExtrudedMesh(m1D,0)
11371         m3D.convertLinearCellsToQuadratic(0)
11372         m3D.checkCoherency1()
11373         # check of new m3D content
11374         coordsExp2=[coordsExp.changeNbOfComponents(3,i) for i in xrange(4)]
11375         coordsExp3=[DataArrayDouble.Meld(cooTmp[:,[0,1]],cooTmp[:,2]+(0.5+float(i))) for i in xrange(3)]
11376         coordsExp4=DataArrayDouble.Aggregate([coordsExp2[0],coordsExp3[0],coordsExp2[1],coordsExp3[1],coordsExp2[2],coordsExp3[2],coordsExp2[3]])
11377         c=DataArrayDouble.Aggregate(m3D.getCoords(),coordsExp4)
11378         self.assertEqual(len(coordsExp4),115)
11379         self.assertEqual(len(m3D.getCoords()),115)
11380         a,b=c.findCommonTuples(1e-14)
11381         self.assertEqual(len(b),len(coordsExp4)+1)
11382         e,f=DataArrayInt.BuildOld2NewArrayFromSurjectiveFormat2(2*115,a,b)
11383         self.assertEqual(f,115)
11384         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])))
11385         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()))
11386         self.assertTrue(DataArrayInt([0,21,37,53,74,95,116,132,148,169,190,211,227,243,264,285]).isEqual(m3D.getNodalConnectivityIndex()))
11387         # testing explode3DMeshTo1D
11388         m3DSlice0=m3D[:5]
11389         m3DSlice0.zipCoords()
11390         a,b,c,d,e=m3DSlice0.explode3DMeshTo1D()
11391         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])))
11392         self.assertTrue(c.isEqual(DataArrayInt([0,12,21,30,42,54])))
11393         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])))
11394         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])))
11395         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])))
11396         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])))
11397         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))
11398         pass
11399
11400     def testSwig2DataArrayPushBackValsSilent1(self):
11401         d=DataArrayDouble()
11402         d.pushBackValsSilent([4,5,6])
11403         self.assertTrue(d.isEqual(DataArrayDouble([4.,5.,6.]),1e-14))
11404         e=DataArrayDouble([1,2,3],1,3)
11405         for t in e: d.pushBackValsSilent(t)
11406         self.assertTrue(d.isEqual(DataArrayDouble([4.,5.,6.,1.,2.,3.]),1e-14))
11407         d.pushBackValsSilent(DataArrayDouble([9,10.]))
11408         self.assertTrue(d.isEqual(DataArrayDouble([4.,5.,6.,1.,2.,3.,9.,10.]),1e-14))
11409         d.pushBackValsSilent(DataArrayDouble(0,1))
11410         self.assertTrue(d.isEqual(DataArrayDouble([4.,5.,6.,1.,2.,3.,9.,10.]),1e-14))
11411         e=DataArrayDouble([1,2,3],3,1)
11412         for t in e: d.pushBackValsSilent(t)
11413         self.assertTrue(d.isEqual(DataArrayDouble([4.,5.,6.,1.,2.,3.,9.,10.,1.,2.,3.]),1e-14))
11414         d.pushBackValsSilent(77)
11415         self.assertTrue(d.isEqual(DataArrayDouble([4.,5.,6.,1.,2.,3.,9.,10.,1.,2.,3.,77.]),1e-14))
11416         #
11417         d=DataArrayInt()
11418         d.pushBackValsSilent([4,5,6])
11419         self.assertTrue(d.isEqual(DataArrayInt([4,5,6])))
11420         e=DataArrayInt([1,2,3],1,3)
11421         for t in e: d.pushBackValsSilent(t)
11422         self.assertTrue(d.isEqual(DataArrayInt([4,5,6,1,2,3])))
11423         d.pushBackValsSilent(DataArrayInt([9,10]))
11424         self.assertTrue(d.isEqual(DataArrayInt([4,5,6,1,2,3,9,10])))
11425         d.pushBackValsSilent(DataArrayInt(0,1))
11426         self.assertTrue(d.isEqual(DataArrayInt([4,5,6,1,2,3,9,10])))
11427         e=DataArrayInt([1,2,3],3,1)
11428         for t in e: d.pushBackValsSilent(t)
11429         self.assertTrue(d.isEqual(DataArrayInt([4,5,6,1,2,3,9,10,1,2,3])))
11430         d.pushBackValsSilent(77)
11431         self.assertTrue(d.isEqual(DataArrayInt([4,5,6,1,2,3,9,10,1,2,3,77])))
11432         pass
11433
11434     def testSwig2ConvertLinearCellsToQuadratic2(self):
11435         m2D=MEDCouplingDataForTest.build2DTargetMesh_1()
11436         ret=m2D.convertLinearCellsToQuadratic(1)
11437         self.assertTrue(ret.isIdentity())
11438         self.assertEqual(5,len(ret))
11439         m2D.checkCoherency1()
11440         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)
11441         self.assertTrue(m2D.getCoords().isEqual(coordsExp,1e-14))
11442         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])))
11443         self.assertTrue(m2D.getNodalConnectivityIndex().isEqual(DataArrayInt([0,10,18,26,36,46])))
11444         #
11445         m2D=MEDCouplingDataForTest.build2DTargetMesh_1()[(0,3)] ; m2D.zipCoords()
11446         m2D.changeSpaceDimension(3)
11447         arr=DataArrayDouble(3);  arr.iota(0) ; z=MEDCouplingCMesh() ; z.setCoords(arr)
11448         m1D=z.buildUnstructured() ; m1D.setCoords(arr.changeNbOfComponents(3,0.))
11449         m1D.getCoords()[:]=m1D.getCoords()[:,[1,2,0]]
11450         cooTmp=m2D.getCoords()[:]
11451         m3D=m2D.buildExtrudedMesh(m1D,0)
11452         ret=m3D.convertLinearCellsToQuadratic(1)
11453         self.assertTrue(ret.isIdentity())
11454         self.assertEqual(4,len(ret))
11455         m3D.checkCoherency1()
11456         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)
11457         self.assertTrue(m3D.getCoords().isEqual(coordsExp2,1e-14))
11458         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])))
11459         self.assertTrue(m3D.getNodalConnectivityIndex().isEqual(DataArrayInt([0,28,56,84,112])))
11460         pass
11461
11462     def testSwig2GaussNEIntegral1(self):
11463         m2D=MEDCouplingDataForTest.build2DTargetMesh_1()
11464         m0=m2D[0] ; m0.zipCoords()
11465         m1=m2D[[1,2]] ; m1.zipCoords()
11466         m2=m2D[[3,4]] ; m2.zipCoords()
11467         m0.convertLinearCellsToQuadratic(1)
11468         m1.convertLinearCellsToQuadratic(0)
11469         m2.convertLinearCellsToQuadratic(1)
11470         m=MEDCouplingUMesh.MergeUMeshes([m0,m1,m2])
11471         m.mergeNodes(1e-12)
11472         f=MEDCouplingFieldDouble(ON_GAUSS_NE)
11473         f.setMesh(m)
11474         arr=DataArrayDouble([1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8,9.9,
11475                              11.1,12.2,13.3,14.4,15.5,16.6,
11476                              21.1,22.2,23.3,24.4,25.5,26.6,
11477                              31.1,32.2,33.3,34.4,35.5,36.6,37.7,38.8,39.9,
11478                              41.1,42.2,43.3,44.4,45.5,46.6,47.7,48.8,49.9])
11479         arr2=DataArrayDouble(len(arr),2)
11480         arr2[:,0]=arr ; arr2[:,1]=arr+100
11481         f.setArray(arr2)
11482         f.checkCoherency()
11483         res=f.integral(False)
11484         # a=25./81 ; b=40./81 ; c=64./81
11485         # p1=0.11169079483905 ; p2=0.0549758718227661
11486         # 1st compo
11487         # 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
11488         # c1=(p2*(11.1+12.2+13.3)+p1*(14.4+15.5+16.6))*0.125/0.4999999999854482 ; c1=1.8014347172346943
11489         # c2=(p2*(21.1+22.2+23.3)+p1*(24.4+25.5+26.6))*0.125/0.4999999999854482 ; c2=3.0514347172346943
11490         # 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
11491         # 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
11492         # c0+c1+c2+c3+c4=27.104258323358287
11493         integExp0=27.104258323358287
11494         self.assertAlmostEqual(res[0],integExp0,13)
11495         # 2nd compo
11496         # 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
11497         # c1=(p2*(111.1+112.2+113.3)+p1*(114.4+115.5+116.6))*0.125/0.4999999999854482 ; c1=14.301434717234699
11498         # c2=(p2*(121.1+122.2+123.3)+p1*(124.4+125.5+126.6))*0.125/0.4999999999854482 ; c2=15.5514347172347
11499         # 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
11500         # 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
11501         # c0+c1+c2+c3+c4=127.10425832335835
11502         integExp1=127.10425832335835
11503         self.assertAlmostEqual(res[1],integExp1,12)
11504         meas=f.getDiscretization().getMeasureField(f.getMesh(),False)
11505         intPerTuple=meas*f
11506         res2=intPerTuple.accumulate()
11507         self.assertAlmostEqual(res2[0],integExp0,13)
11508         self.assertAlmostEqual(res2[1],integExp1,12)
11509         #
11510         meas2=f.buildMeasureField(False)
11511         intPerTuple=meas2*f
11512         res3=intPerTuple.accumulate()
11513         self.assertAlmostEqual(res3[0],integExp0,13)
11514         self.assertAlmostEqual(res3[1],integExp1,12)
11515         #
11516         res4=f.getWeightedAverageValue(False) # res4==res2 because sum of area of mesh is equal to 1
11517         self.assertAlmostEqual(res4[0],integExp0,13)
11518         self.assertAlmostEqual(res4[1],integExp1,12)
11519         #
11520         m.scale([0,0],2.)
11521         #
11522         res5=f.getWeightedAverageValue() # res4==res4 because weighted average is not sensitive to the scaling
11523         self.assertAlmostEqual(res5[0],integExp0,13)
11524         self.assertAlmostEqual(res5[1],integExp1,12)
11525         meas3=f.buildMeasureField(False)
11526         delta=4*meas2.getArray()-meas3.getArray()
11527         delta.abs()
11528         self.assertTrue(delta.isUniform(0.,1e-16))
11529         res6=f.integral(False)
11530         self.assertAlmostEqual(res6[0],4.*integExp0,12)
11531         self.assertAlmostEqual(res6[1],4.*integExp1,11)
11532         pass
11533
11534     def testSwig2SlowDADFindClosestTupleId(self):
11535         nbPts=[10,]
11536         for nbPt in nbPts:
11537             d=DataArrayDouble(nbPt) ; d.iota() ; d*=1./(nbPt-1)
11538             c=MEDCouplingCMesh() ; c.setCoords(d,d) ; m=c.buildUnstructured() ; pts=m.getCoords() ; del m
11539             #
11540             d0=DataArrayDouble((nbPt-1)*(nbPt-1)) ; d0.iota() ; d0*=(3./((nbPt-1)*(nbPt-1))) ; d0=d0.applyFunc("exp(x)-1")
11541             d1=DataArrayDouble((nbPt-1)*(nbPt-1)) ; d1.iota()
11542             d2=DataArrayDouble.Meld(d0,d1) ; d2=d2.fromPolarToCart() ; d2+=[0.32,0.73]
11543             ids=pts.findClosestTupleId(d2)
11544             #print "Start of costly computation"
11545             idsExpected=DataArrayInt(len(d2))
11546             tmp=1e300
11547             for i,elt in enumerate(d2):
11548                 l,m=(pts-elt).magnitude().getMinValue()
11549                 idsExpected.setIJSilent(i,0,m)
11550                 if l<tmp:
11551                     tmp=l ; tmp1=m ; tmp2=i
11552                     pass
11553                 pass
11554             #print "End of costly computation"
11555             self.assertTrue(idsExpected.isEqual(ids))
11556             a,b,c=pts.minimalDistanceTo(d2)
11557             self.assertEqual(tmp,a)
11558             self.assertEqual(tmp1,b)
11559             self.assertEqual(tmp2,c)
11560             #
11561             l=[d2[:,i] for i in [0,1]]
11562             for elt in l: elt.reverse()
11563             d2i=DataArrayDouble.Meld(l)
11564             ids1=pts.findClosestTupleId(d2i)
11565             idsExpectedI=idsExpected.deepCpy() ; idsExpectedI.reverse()
11566             self.assertTrue(idsExpectedI.isEqual(ids1))
11567             #
11568             l=[pts[:,i] for i in [0,1]]
11569             for elt in l: elt.reverse()
11570             ptsi=DataArrayDouble.Meld(l)
11571             ids2=ptsi.findClosestTupleId(d2)
11572             idsExpected2=nbPt*nbPt-1-ids
11573             self.assertTrue(idsExpected2.isEqual(ids2))
11574             #
11575             ids3=ptsi.findClosestTupleId(d2i)
11576             idsExpected3=idsExpected2.deepCpy() ; idsExpected3.reverse()
11577             self.assertTrue(idsExpected3.isEqual(ids3))
11578             pass
11579
11580     def testSwig2DataArrayAsciiChar1(self):
11581         alpha=DataArrayInt(26) ; alpha.iota(ord("A"))
11582         d=DataArrayAsciiChar(alpha.getValues(),2,13)
11583         d.setInfoOnComponents(["c%i"%(v) for v in xrange(13)])
11584         self.assertEqual('ABCDEFGHIJKLM',d.getTuple(0))
11585         self.assertEqual('NOPQRSTUVWXYZ',d.getTuple(1))
11586         self.assertEqual(2,d.getNumberOfTuples())
11587         self.assertEqual(26,d.getNbOfElems())
11588         self.assertEqual(13,d.getNumberOfComponents())
11589         dd=d.deepCpy()
11590         self.assertTrue(d.isEqual(dd))
11591         dd.setIJ(0,3,'d')
11592         self.assertTrue(not d.isEqual(dd))
11593         d.setIJ(0,3,ord('d'))
11594         self.assertTrue(d.isEqual(dd))
11595         d.rearrange(1)
11596         d.reserve(20)
11597         self.assertEqual(20,d.getNumberOfTuples())
11598         self.assertEqual(20,d.getNbOfElems())
11599         self.assertEqual(1,d.getNumberOfComponents())
11600         #
11601         d0=DataArrayAsciiChar([ord('a')],1,1)
11602         self.assertEqual('a',d0.asciiCharValue())
11603         self.assertTrue(not d0.empty())
11604         d0=DataArrayAsciiChar(0,3)
11605         self.assertTrue(d0.empty())
11606         d.pushBackSilent("U") ; d.pushBackSilent("V") ; d.pushBackSilent("W")
11607         self.assertEqual("W",d.popBackSilent())
11608         d.rearrange(2)
11609         self.assertEqual(['AB','Cd','EF','GH','IJ','KL','MN','OP','QR','ST','UV'],d.toStrList())
11610         d.fillWithZero()
11611         self.assertEqual(11*[''],d.toStrList())
11612         d.fillWithValue('T')
11613         self.assertEqual(11*["TT"],d.toStrList())
11614         d.rearrange(1)
11615         self.assertTrue(d.isUniform("T"))
11616         d.rearrange(2)
11617         #
11618         dd.rearrange(2)
11619         dd2=dd.deepCpy()
11620         dd.renumberInPlace([3,1,2,4,0,11,10,9,8,7,5,12,6])
11621         self.assertEqual(dd.toStrList(),['IJ','Cd','EF','AB','GH','UV','YZ','ST','QR','OP','MN','KL','WX'])
11622         dd.renumberInPlaceR([3,1,2,4,0,11,10,9,8,7,5,12,6])
11623         self.assertEqual(['AB','Cd','EF','GH','IJ','KL','MN','OP','QR','ST','UV','WX','YZ'],dd.toStrList())
11624         e=dd.renumber([3,1,2,4,0,11,10,9,8,7,5,12,6])
11625         self.assertEqual(e.toStrList(),['IJ','Cd','EF','AB','GH','UV','YZ','ST','QR','OP','MN','KL','WX'])
11626         e=dd.renumberR([3,1,2,4,0,11,10,9,8,7,5,12,6])
11627         self.assertEqual(e.toStrList(),['GH','Cd','EF','IJ','AB','WX','UV','ST','QR','OP','KL','YZ','MN'])
11628         e=dd.renumberAndReduce([1,1,1,1,1,1,1,2,0,0,0,0,0],3)
11629         self.assertEqual(['YZ','MN','OP'],e.toStrList())
11630         self.assertEqual(['GH','IJ'],dd.selectByTupleIdSafe([3,4]).toStrList())
11631         self.assertEqual(['AB','GH','MN','ST','YZ'],dd.selectByTupleId2(0,13,3).toStrList())
11632         dd3=dd.changeNbOfComponents(3,"G")
11633         self.assertEqual(['ABG','CdG','EFG','GHG','IJG','KLG','MNG','OPG','QRG','STG','UVG','WXG','YZG'],dd3.toStrList())
11634         dd3.rearrange(1) ; self.assertEqual("G",dd3.back()) ; dd3.rearrange(3)
11635         self.assertTrue(dd3.changeNbOfComponents(2,"\0").isEqual(dd))
11636         self.assertEqual(len(dd),13)
11637         d=DataArrayAsciiChar(13,2) ; d.fillWithValue('Y')
11638         dd3.meldWith(d)
11639         self.assertEqual(['ABGYY','CdGYY','EFGYY','GHGYY','IJGYY','KLGYY','MNGYY','OPGYY','QRGYY','STGYY','UVGYY','WXGYY','YZGYY'],dd3.toStrList())
11640         self.assertEqual("d",dd3.getIJ(0,6))
11641         self.assertRaises(InterpKernelException,dd3.getIJSafe,0,6)
11642         self.assertEqual("d",dd3.getIJSafe(1,1))
11643         dd3.rearrange(1)
11644         e=dd3.getIdsEqual("Y")
11645         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])))
11646         e=dd3.getIdsNotEqual("Y")
11647         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])))
11648         self.assertEqual(("d",6),dd3.getMaxValue())
11649         self.assertEqual(("A",0),dd3.getMinValue())
11650         self.assertEqual(26,dd3.search("LGYYM"))
11651         self.assertEqual(-1,dd3.search("LGYYN"))
11652         dd3.rearrange(5)
11653         self.assertEqual(7,dd3.locateTuple("OPGYY"))
11654         self.assertTrue("OPGYY" in dd3)
11655         self.assertEqual(7,dd3.index("OPGYY"))
11656         self.assertEqual(-1,dd3.locateTuple("OPGYP"))
11657         dd3.rearrange(1)
11658         self.assertEqual(2,dd3.locateValue("OPGYY"))
11659         self.assertTrue(dd3.presenceOfValue("OPGYY"))
11660         self.assertTrue("O" in dd3)
11661         self.assertTrue(not dd3.presenceOfValue("z"))
11662         self.assertTrue("z" not in dd3)
11663         dd3.rearrange(5)
11664         l=list(dd3)
11665         self.assertEqual([e.buildDAAsciiChar().toStrList()[0] for e in list(dd3)],dd3.toStrList())
11666         dd3.reAlloc(5)
11667         dd4=DataArrayChar.Aggregate(dd3,dd3)
11668         self.assertEqual(['ABGYY','CdGYY','EFGYY','GHGYY','IJGYY','ABGYY','CdGYY','EFGYY','GHGYY','IJGYY'],dd4.toStrList())
11669         dd5=DataArrayChar.Aggregate([dd4,dd3,dd4])
11670         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())
11671         # getitem,__iter__,__setitem__
11672         a=list(dd3)
11673         self.assertEqual("ABGYY",str(a[0]))
11674         dd4=dd3[::2]
11675         self.assertEqual(['ABGYY','EFGYY','IJGYY'],dd4.toStrList())
11676         dd4=dd3[(3,2,1)]
11677         self.assertEqual(['GHGYY','EFGYY','CdGYY'],dd4.toStrList())
11678         dd4=dd3[:]
11679         dd4[::2]=["12","345","67890"]
11680         self.assertEqual(['12   ','CdGYY','345  ','GHGYY','67890'],dd4.toStrList())
11681         dd4=dd3[:]
11682         dd4[[1,2]]=" "
11683         self.assertEqual(['ABGYY','     ','     ','GHGYY','IJGYY'],dd4.toStrList())
11684         dd4=dd3[:]
11685         dd4[4]='12345'
11686         self.assertEqual(['ABGYY','CdGYY','EFGYY','GHGYY','12345'],dd4.toStrList())
11687         dd4[0]=dd4[1]
11688         self.assertEqual(['CdGYY','CdGYY','EFGYY','GHGYY','12345'],dd4.toStrList())
11689         dd4=DataArrayAsciiChar(["abc","de","fghi"])
11690         self.assertEqual(['abc ','de  ','fghi'],dd4.toStrList())
11691         dd4=DataArrayAsciiChar(["abc","de","fghi"],"t")
11692         self.assertEqual(['abct','dett','fghi'],dd4.toStrList())
11693         pass
11694
11695     def testSwig2GaussNELocalizationOfDiscValues(self):
11696         m=MEDCouplingDataForTest.build2DTargetMesh_3()[[0,1,3,4,5,6,8,9]] # suppression of polygons
11697         f=MEDCouplingFieldDouble(ON_GAUSS_NE)
11698         f.setMesh(m)
11699         loc=f.getLocalizationOfDiscr()
11700         self.assertEqual(42,len(loc))
11701         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))
11702         m.changeSpaceDimension(3)
11703         m.getCoords()[:,2]=7.
11704         loc=f.getLocalizationOfDiscr()
11705         self.assertEqual(42,len(loc))
11706         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))
11707         pass
11708
11709     def testSwig2GaussMeasureAndIntegral(self):
11710         ft=MEDCouplingDataForTest.buildFieldOnGauss_1()
11711         mea=ft.buildMeasureField(False)
11712         mea.checkCoherency()
11713         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))
11714         f=MEDCouplingFieldDouble(ft)
11715         arr=DataArrayDouble(126,2)
11716         arr[:,0]=range(126)
11717         arr[:,1]=range(126)
11718         arr[:,1]+=1000
11719         f.setArray(arr)
11720         f.checkCoherency()
11721         self.assertTrue(DataArrayDouble(f.integral(False)).isEqual(DataArrayDouble([-211.66121638700983,-4863.9563007698835]),1e-11))
11722         self.assertTrue(DataArrayDouble(f.getWeightedAverageValue()).isEqual(DataArrayDouble([45.496085813113595,1045.496085813114]),1e-11))
11723         self.assertTrue(DataArrayDouble(f.normL1()).isEqual(DataArrayDouble([45.49608581311362,1045.496085813114]),1e-11))
11724         self.assertTrue(DataArrayDouble(f.normL2()).isEqual(DataArrayDouble([58.16846378340898,1046.1241521947334]),1e-11))
11725         pass
11726
11727     def testSwig2FieldDiscretizationComputeMeshRestrictionFromTupleIds1(self):
11728         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1()
11729         f=MEDCouplingFieldDouble(ON_GAUSS_NE)
11730         f.setMesh(m)
11731         a,b=f.getDiscretization().computeMeshRestrictionFromTupleIds(f.getMesh(),[3,4,5,6,8,9,10,14,15,16,17])
11732         self.assertTrue(a.isEqual(DataArrayInt([1,4])))
11733         self.assertTrue(b.isEqual(DataArrayInt([4,5,6,14,15,16,17])))
11734         a,b=f.getDiscretization().computeMeshRestrictionFromTupleIds(f.getMesh(),DataArrayInt([0,1,2,3,5,7,8,9,10,11,12,18]))
11735         self.assertTrue(a.isEqual(DataArrayInt([0,2])))
11736         self.assertTrue(b.isEqual(DataArrayInt([0,1,2,3,7,8,9])))
11737         #
11738         f=MEDCouplingFieldDouble(ON_CELLS)
11739         f.setMesh(m)
11740         a,b=f.getDiscretization().computeMeshRestrictionFromTupleIds(f.getMesh(),[3,4])
11741         self.assertTrue(a.isEqual(DataArrayInt([3,4])))
11742         self.assertTrue(b.isEqual(DataArrayInt([3,4])))
11743         #
11744         f=MEDCouplingFieldDouble(ON_NODES)
11745         f.setMesh(m)
11746         a,b=f.getDiscretization().computeMeshRestrictionFromTupleIds(f.getMesh(),[1,2,3,4])
11747         self.assertTrue(a.isEqual(DataArrayInt([1])))
11748         self.assertTrue(b.isEqual(DataArrayInt([1,2,4])))
11749         #
11750         f=MEDCouplingDataForTest.buildFieldOnGauss_1()
11751         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])
11752         self.assertTrue(a.isEqual(DataArrayInt([0,11,12,18,35])))
11753         self.assertTrue(b.isEqual(DataArrayInt([0,11,12,13,14,15,36,37,38,117,118,119,120,121,122,123,124,125])))
11754         #
11755         d=DataArrayInt([0,3,7,9,15,18])
11756         e=DataArrayInt([0,1,2,3,7,8,15,16,17])
11757         a,b=d.searchRangesInListOfIds(e)
11758         self.assertTrue(a.isEqual(DataArrayInt([0,2,4])))
11759         self.assertTrue(b.isEqual(DataArrayInt([0,1,2,7,8,15,16,17])))
11760         pass
11761     
11762     def testSwig2BigMem(self):
11763         if MEDCouplingSizeOfVoidStar()==64:
11764             d=DataArrayAsciiChar(223456789,16)
11765             self.assertTrue(d.getNumberOfTuples(),223456789)
11766             self.assertTrue(d.getNumberOfComponents(),16)
11767             d.setIJ(223456788,5,"r")
11768             self.assertTrue(d.getIJ(223456788,5),'r')
11769             d[223456787]="1234567890123456"
11770             self.assertTrue(d[223456787],'1234567890123456')
11771             self.assertRaises(InterpKernelException,d.rearrange,1)# fails because it would lead to nb of tuples > 2147483647
11772             pass
11773         pass
11774
11775     def testSwig2DAReverseMultiCompo1(self):
11776         d=DataArrayDouble(6,2)
11777         d[:,0]=range(6)
11778         d[:,1]=range(10,16)
11779         d.reverse()
11780         self.assertTrue(d.isEqual(DataArrayDouble([5.,15.,4.,14.,3.,13.,2.,12.,1.,11.,0.,10.],6,2),1e-14))
11781         d=DataArrayDouble(7,2)
11782         d[:,0]=range(7)
11783         d[:,1]=range(10,17)
11784         d.reverse()
11785         self.assertTrue(d.isEqual(DataArrayDouble([6.,16.,5.,15.,4.,14.,3.,13.,2.,12.,1.,11.,0.,10.],7,2),1e-14))
11786         #
11787         d=DataArrayInt(6,2)
11788         d[:,0]=range(6)
11789         d[:,1]=range(10,16)
11790         d.reverse()
11791         self.assertTrue(d.isEqual(DataArrayInt([5,15,4,14,3,13,2,12,1,11,0,10],6,2)))
11792         d=DataArrayInt(7,2)
11793         d[:,0]=range(7)
11794         d[:,1]=range(10,17)
11795         d.reverse()
11796         self.assertTrue(d.isEqual(DataArrayInt([6,16,5,15,4,14,3,13,2,12,1,11,0,10],7,2)))
11797         pass
11798
11799     def testSwigDAPow1(self):
11800         d=DataArrayInt(10)
11801         d.iota(0)
11802         d1=d.deepCpy()
11803         d.setIJ(2,0,-2)
11804         self.assertTrue((d**2).isEqual(DataArrayInt([0,1,4,9,16,25,36,49,64,81])))
11805         self.assertTrue((d**3).isEqual(DataArrayInt([0,1,-8,27,64,125,216,343,512,729])))
11806         for elt in [d]:
11807             elt**=2
11808             pass
11809         self.assertTrue(d.isEqual(DataArrayInt([0,1,4,9,16,25,36,49,64,81])))
11810         self.assertTrue((d1[:4]**d1[:4]).isEqual(DataArrayInt([1,1,4,27])))
11811         self.assertTrue((3**d1[:4]).isEqual(DataArrayInt([1,3,9,27])))
11812         d2=d1[:4]
11813         d2**=d2
11814         self.assertTrue(d2.isEqual(DataArrayInt([1,1,4,27])))
11815         self.assertRaises(InterpKernelException,d2.__pow__,-1)#non supporting negative pow in DataArrayInt.__pow__
11816         self.assertRaises(InterpKernelException,d2.__ipow__,-1)#non supporting negative pow in DataArrayInt.__pow__
11817         #
11818         d=DataArrayDouble(10)
11819         d.iota(0)
11820         d1=d.deepCpy()
11821         d.setIJ(2,0,-2.)
11822         self.assertTrue((d**2).isEqual(DataArrayDouble([0,1,4,9,16,25,36,49,64,81]),1e-12))
11823         self.assertTrue((d**3).isEqual(DataArrayDouble([0,1,-8,27,64,125,216,343,512,729]),1e-12))
11824         self.assertRaises(InterpKernelException,d.__pow__,3.1)#3.1 is double not integer -> not supporting negative values in d
11825         for elt in [d]:
11826             elt**=2
11827             pass
11828         self.assertTrue(d.isEqual(DataArrayDouble([0,1,4,9,16,25,36,49,64,81]),1e-12))
11829         self.assertTrue((d1[:4]**d1[:4]).isEqual(DataArrayDouble([1,1,4,27]),1e-12))
11830         self.assertTrue((3**d1[:4]).isEqual(DataArrayDouble([1,3,9,27]),1e-12))
11831         d2=d1[:4]
11832         d2**=d2
11833         self.assertTrue(d2.isEqual(DataArrayDouble([1,1,4,27]),1e-12))
11834         d2**=-0.5
11835         self.assertTrue(d2.isEqual(DataArrayDouble([1,1,1./2,1./sqrt(27.)]),1e-14))
11836         d3=-1./d1[1:5]
11837         self.assertTrue((3**d3).isEqual(DataArrayDouble([0.3333333333333333,0.5773502691896257,0.6933612743506348,0.7598356856515925]),1e-14))
11838         d4=d3.deepCpy() ; d4.abs()
11839         self.assertTrue((d4**d3).isEqual(DataArrayDouble([1.,sqrt(2.),1.4422495703074083,sqrt(2.)]),1e-14))
11840         d4**=d3
11841         self.assertTrue(d4.isEqual(DataArrayDouble([1.,sqrt(2.),1.4422495703074083,sqrt(2.)]),1e-14))
11842         pass
11843     
11844     def testSwig2Baryenter3DForCellsWithVolumeZero1(self):
11845         coo=DataArrayDouble([0.,0.,0.,1.,0.,0.,0.,1.,0.],3,3)
11846         m2=MEDCouplingUMesh("mesh",2)
11847         m2.allocateCells(0)
11848         m2.insertNextCell(NORM_POLYGON,[0,1,2])
11849         m2.setCoords(coo)
11850         m2.checkCoherency1()
11851         #
11852         coo2=DataArrayDouble([0.,0.,0.,0.,0.,0.,0.,0.,2.],3,3)
11853         m1=MEDCouplingUMesh("mesh",1)
11854         m1.allocateCells(0)
11855         m1.insertNextCell(NORM_SEG2,[0,1])
11856         m1.insertNextCell(NORM_SEG2,[1,2])
11857         m1.setCoords(coo2)
11858         m1.checkCoherency1()
11859         #
11860         m3=m2.buildExtrudedMesh(m1,0)
11861         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
11862         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))
11863         m4,a,b,c,d=m3.buildDescendingConnectivity()
11864         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))
11865         pass
11866
11867     def testSwigRepr1(self):
11868         d=DataArrayDouble()
11869         self.assertTrue(len(d.__repr__())<120)
11870         d.alloc(1000,0) ; self.assertTrue(len(d.__repr__())<100)
11871         for i in xrange(100):
11872             d.alloc(i,1) ; d.iota(1.1234567890123456) ; d*=1e123
11873             self.assertTrue(len(d.__repr__())<500)
11874             pass
11875         for i in xrange(50):
11876             d.alloc(i,2) ; d.rearrange(1) ; d.iota(1.1234567890123456) ; d.rearrange(2) ; d*=1e123
11877             self.assertTrue(len(d.__repr__())<500)
11878             pass
11879         d.alloc(4000,1) ; d.iota() ; self.assertTrue(len(d.__repr__())<500)
11880         for i in xrange(2,4):
11881             d.alloc(362880,1) ; d.iota() ; d.rearrange(i) ; self.assertTrue(len(d.__repr__())<500)
11882             pass
11883         d.alloc(0,9)
11884         self.assertTrue(len(d.__repr__())<120)
11885         #
11886         d=DataArrayInt()
11887         self.assertTrue(len(d.__repr__())<100)
11888         d.alloc(1000,0) ; self.assertTrue(len(d.__repr__())<100)
11889         for i in xrange(100):
11890             d.alloc(i,1) ; d.iota(123456789)
11891             self.assertTrue(len(d.__repr__())<500)
11892             pass
11893         for i in xrange(50):
11894             d.alloc(i,2) ; d.rearrange(1) ; d.iota(123456789) ; d.rearrange(2)
11895             self.assertTrue(len(d.__repr__())<500)
11896             pass
11897         d.alloc(4000,1) ; d.iota() ; self.assertTrue(len(d.__repr__())<500)
11898         for i in xrange(2,10):
11899             d.alloc(362880,1) ; d.iota() ; d.rearrange(i) ; self.assertTrue(len(d.__repr__())<500)
11900             pass
11901         d.alloc(0,9)
11902         self.assertTrue(len(d.__repr__())<100)
11903         #
11904         d=DataArrayAsciiChar()
11905         d.alloc(1000,0) ; self.assertTrue(len(d.__repr__())<100)
11906         d.alloc(2,16) ; d[:]='1234567890ABCDEF'
11907         self.assertTrue(len(d.__repr__())<500)
11908         d.alloc(2000,16) ; d[:]='1234567890ABCDEF'
11909         self.assertTrue(len(d.__repr__())<500)
11910         d.alloc(0,16) ; d[:]='1234567890ABCDEF'
11911         self.assertTrue(len(d.__repr__())<120)
11912         #
11913         d=DataArrayByte()
11914         self.assertTrue(len(d.__repr__())<100)
11915         d.alloc(1000,0) ; self.assertTrue(len(d.__repr__())<100)
11916         d.alloc(0,16) ; self.assertTrue(len(d.__repr__())<100)
11917         d.alloc(5,1) ; d.fillWithValue(127)
11918         self.assertTrue(len(d.__repr__())<200)
11919         d.alloc(1000,1) ; d.fillWithValue(127)
11920         self.assertTrue(len(d.__repr__())<500)
11921         d.alloc(1000,3) ; d.fillWithValue(127)
11922         self.assertTrue(len(d.__repr__())<500)
11923         pass
11924     
11925     def testSwig2MeshComputeIsoBarycenterOfNodesPerCell1(self):
11926         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)
11927         m=MEDCouplingUMesh.New("toto",3)
11928         m.allocateCells(0)
11929         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])
11930         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])
11931         m.setCoords(coo)
11932         m.checkCoherency1()
11933         #
11934         dReference=DataArrayDouble([(34.900130952189848,0.,200),(17.450065476094931,30.2244,200.)])
11935         self.assertTrue(m.computeIsoBarycenterOfNodesPerCell().isEqual(dReference,1e-12))
11936         m.getNodalConnectivity().setIJ(87,0,24)
11937         self.assertRaises(InterpKernelException,m.computeIsoBarycenterOfNodesPerCell)
11938         m.getNodalConnectivity().setIJ(87,0,-2)
11939         self.assertRaises(InterpKernelException,m.computeIsoBarycenterOfNodesPerCell)
11940         m.getNodalConnectivity().setIJ(87,0,21)# put again 21 as at the beginning
11941         #
11942         self.assertTrue(m.unPolyze())
11943         self.assertEqual([NORM_HEXGP12],m.getAllGeoTypes())
11944         self.assertTrue(m.computeIsoBarycenterOfNodesPerCell().isEqual(dReference,1e-12))
11945         m.getNodalConnectivity().setIJ(25,0,24)
11946         self.assertRaises(InterpKernelException,m.computeIsoBarycenterOfNodesPerCell)
11947         m.getNodalConnectivity().setIJ(25,0,-1)
11948         self.assertRaises(InterpKernelException,m.computeIsoBarycenterOfNodesPerCell)
11949         pass
11950
11951     def testSwig2NonRegressionBugDescHexa20(self):
11952         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)
11953         m=MEDCouplingUMesh('mesh',3)
11954         m.allocateCells(0)
11955         m.insertNextCell(NORM_HEXA20,[0,3,5,1,12,18,16,14,7,4,6,2,19,17,15,13,8,11,10,9])
11956         m.setCoords(coo)
11957         m.checkCoherency1()
11958         #
11959         a,b,c,d,e=m.buildDescendingConnectivity()
11960         m2=MEDCouplingUMesh('mesh',2)
11961         m2.allocateCells(0)
11962         m2.setCoords(coo)
11963         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]]
11964         for i in xrange(6):
11965             m2.insertNextCell(NORM_QUAD8,conn2[i])
11966             pass
11967         self.assertTrue(m2.isEqual(a,1e-12))
11968         self.assertTrue(b.isEqual(DataArrayInt([0,1,2,3,4,5])))
11969         self.assertTrue(c.isEqual(DataArrayInt([0,6])))
11970         self.assertTrue(d.isEqual(DataArrayInt([0,0,0,0,0,0])))
11971         self.assertTrue(e.isEqual(DataArrayInt([0,1,2,3,4,5,6])))
11972         #
11973         m.convertQuadraticCellsToLinear() ; m.zipCoords()
11974         m.convertLinearCellsToQuadratic(1)
11975         #
11976         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)
11977         m3=MEDCouplingUMesh("mesh",3)
11978         m3.allocateCells(1)
11979         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])
11980         m3.setCoords(coo2)
11981         self.assertTrue(m3.isEqual(m,1e-12))
11982         #
11983         a,b,c,d,e=m.buildDescendingConnectivity()
11984         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]]
11985         m4=MEDCouplingUMesh("mesh",2)
11986         m4.allocateCells(0)
11987         for i in xrange(6):
11988             m4.insertNextCell(NORM_QUAD9,conn4[i])
11989             pass
11990         m4.setCoords(coo2)
11991         self.assertTrue(m4.isEqual(a,1e-12))
11992         self.assertTrue(b.isEqual(DataArrayInt([0,1,2,3,4,5])))
11993         self.assertTrue(c.isEqual(DataArrayInt([0,6])))
11994         self.assertTrue(d.isEqual(DataArrayInt([0,0,0,0,0,0])))
11995         self.assertTrue(e.isEqual(DataArrayInt([0,1,2,3,4,5,6])))
11996         pass
11997     
11998     def testSwigAdvGauss(self):
11999         f=MEDCouplingFieldTemplate(ON_GAUSS_PT)
12000         f.setDiscretization(None)
12001         f.__repr__() ; f.__str__()
12002         #
12003         f=MEDCouplingFieldTemplate(ON_GAUSS_PT)
12004         d=f.getDiscretization()
12005         i=DataArrayInt() ; i.alloc(10,1) ; i.iota(1)
12006         d.setArrayOfDiscIds(i)
12007         f.__repr__() ; f.__str__()
12008         i2=d.getArrayOfDiscIds()
12009         self.assertEqual(i.__repr__(),i2.__repr__())
12010         #
12011         f=MEDCouplingFieldDouble(ON_GAUSS_PT)
12012         f.setDiscretization(None)
12013         f.__repr__() ; f.__str__()
12014         #
12015         f=MEDCouplingFieldDouble(ON_GAUSS_PT)
12016         d=f.getDiscretization()
12017         i=DataArrayInt() ; i.alloc(10,1) ; i.iota(1)
12018         d.setArrayOfDiscIds(i)
12019         f.__repr__() ; f.__str__()
12020         #
12021         gl=MEDCouplingGaussLocalization(NORM_SEG2,[0,1],[0.5],[1.])
12022         gl.setWeights([3.])
12023         gl.__repr__() ; gl.__str__()
12024         gl=MEDCouplingGaussLocalization(NORM_ERROR)
12025         gl.setWeights([3.])
12026         gl.__repr__() ; gl.__str__()
12027         pass
12028
12029     def testSwig2NonRegressionBugSubstractInPlaceDM(self):
12030         m0=MEDCouplingCMesh()
12031         arr=DataArrayDouble(5,1) ; arr.iota(0.)
12032         m0.setCoords(arr,arr)
12033         m0=m0.buildUnstructured()
12034         m00=m0[::2] ; m00.simplexize(0) ; m01=m0[1::2]
12035         m0=MEDCouplingUMesh.MergeUMeshes([m00,m01])
12036         m0.getCoords()[:]*=1/4.
12037         m0.setName("mesh")
12038         #
12039         NodeField=MEDCouplingFieldDouble(ON_NODES,ONE_TIME) ; NodeField.setTime(5.6,5,6) ; NodeField.setMesh(m0)
12040         NodeField.setName("NodeField")
12041         NodeField.fillFromAnalytic(1,"exp(-((x-1)*(x-1)+(y-1)*(y-1)))") ; NodeField.getArray().setInfoOnComponent(0,"powernode [W]")
12042         proc0=m0.getCellsInBoundingBox([(0.,0.4),(0.,0.4)],1e-10)
12043         proc1=proc0.buildComplement(m0.getNumberOfCells())
12044         #
12045         NodeField0=NodeField[proc0] ; NodeField0.getMesh().setName(m0.getName())
12046         NodeField1=NodeField[proc1] ; NodeField1.getMesh().setName(m0.getName())
12047         #
12048         NodeField_read=MEDCouplingFieldDouble.MergeFields([NodeField0,NodeField1])
12049         NodeField_read.mergeNodes(1e-10)
12050         NodeFieldCpy=NodeField.deepCpy()
12051         NodeFieldCpy.mergeNodes(1e-10)
12052         NodeField.checkCoherency()
12053         self.assertTrue(not NodeField.getArray().isUniform(0.,1e-12))
12054         NodeField.substractInPlaceDM(NodeField_read,10,1e-12)
12055         self.assertTrue(NodeField.getArray().isUniform(0.,1e-12))
12056         pass
12057
12058     def testSwigFieldOperationOpen1(self):
12059         ## MEDCouplingFieldDouble.__add__
12060         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12061         f=MEDCouplingFieldDouble(ON_CELLS)
12062         f.setMesh(m)
12063         arr=DataArrayDouble(5,2)
12064         arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
12065         f2=f.clone(True)
12066         self.assertRaises(InterpKernelException,f.__add__,2)
12067         self.assertRaises(InterpKernelException,f.__add__,range(5))
12068         self.assertRaises(InterpKernelException,f.__add__,arr)
12069         self.assertRaises(InterpKernelException,f.__add__,f2)
12070         f.setArray(DataArrayDouble())
12071         self.assertRaises(InterpKernelException,f.__add__,2)
12072         self.assertRaises(InterpKernelException,f.__add__,range(5))
12073         self.assertRaises(InterpKernelException,f.__add__,arr)
12074         self.assertRaises(InterpKernelException,f.__add__,f2)
12075         self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
12076         f.getArray().alloc(5,2)
12077         f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
12078         ff=f+2
12079         ff.checkCoherency()
12080         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(2,9),(3,10),(4,11),(5,12),(6,13)]),1e-12))
12081         ff=f+arr
12082         ff.checkCoherency()
12083         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,7),(2,10),(4,13),(6,16),(8,19)]),1e-12))
12084         self.assertRaises(InterpKernelException,f.__add__,f2)
12085         f2.setArray(arr)
12086         ff=f+f2
12087         ff.checkCoherency()
12088         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,7),(2,10),(4,13),(6,16),(8,19)]),1e-12))
12089         ff=f+[5,8]
12090         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(5,15),(6,16),(7,17),(8,18),(9,19)]),1e-12))
12091         ### MEDCouplingFieldDouble.__sub__
12092         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12093         f=MEDCouplingFieldDouble(ON_CELLS)
12094         f.setMesh(m)
12095         arr=DataArrayDouble(5,2)
12096         arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
12097         f2=f.clone(True)
12098         self.assertRaises(InterpKernelException,f.__sub__,2)
12099         self.assertRaises(InterpKernelException,f.__sub__,range(5))
12100         self.assertRaises(InterpKernelException,f.__sub__,arr)
12101         self.assertRaises(InterpKernelException,f.__sub__,f2)
12102         f.setArray(DataArrayDouble())
12103         self.assertRaises(InterpKernelException,f.__sub__,2)
12104         self.assertRaises(InterpKernelException,f.__sub__,range(5))
12105         self.assertRaises(InterpKernelException,f.__sub__,arr)
12106         self.assertRaises(InterpKernelException,f.__sub__,f2)
12107         self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
12108         f.getArray().alloc(5,2)
12109         f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
12110         ff=f-2
12111         ff.checkCoherency()
12112         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(-2,5),(-1,6),(0,7),(1,8),(2,9)]),1e-12))
12113         ff=f-arr
12114         ff.checkCoherency()
12115         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,7),(0,6),(0,5),(0,4),(0,3)]),1e-12))
12116         self.assertRaises(InterpKernelException,f.__sub__,f2)
12117         f2.setArray(arr)
12118         ff=f-f2
12119         ff.checkCoherency()
12120         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,7),(0,6),(0,5),(0,4),(0,3)]),1e-12))
12121         ff=f-[5,8]
12122         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(-5,-1),(-4,0),(-3,1),(-2,2),(-1,3)]),1e-12))
12123         ### MEDCouplingFieldDouble.__mul__
12124         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12125         f=MEDCouplingFieldDouble(ON_CELLS)
12126         f.setMesh(m)
12127         arr=DataArrayDouble(5,2)
12128         arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
12129         f2=f.clone(True)
12130         self.assertRaises(InterpKernelException,f.__mul__,2)
12131         self.assertRaises(InterpKernelException,f.__mul__,range(5))
12132         self.assertRaises(InterpKernelException,f.__mul__,arr)
12133         self.assertRaises(InterpKernelException,f.__mul__,f2)
12134         f.setArray(DataArrayDouble())
12135         self.assertRaises(InterpKernelException,f.__mul__,2)
12136         self.assertRaises(InterpKernelException,f.__mul__,range(5))
12137         self.assertRaises(InterpKernelException,f.__mul__,arr)
12138         self.assertRaises(InterpKernelException,f.__mul__,f2)
12139         self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
12140         f.getArray().alloc(5,2)
12141         f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
12142         ff=f*2
12143         ff.checkCoherency()
12144         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,14),(2,16),(4,18),(6,20),(8,22)]),1e-12))
12145         ff=f*arr
12146         ff.checkCoherency()
12147         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,0),(1,16),(4,36),(9,60),(16,88)]),1e-12))
12148         self.assertRaises(InterpKernelException,f.__mul__,f2)
12149         f2.setArray(arr)
12150         ff=f*f2
12151         ff.checkCoherency()
12152         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,0),(1,16),(4,36),(9,60),(16,88)]),1e-12))
12153         ff=f*[5,8]
12154         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,56),(5,64),(10,72),(15,80),(20,88)]),1e-12))
12155         ### MEDCouplingFieldDouble.__div__
12156         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12157         f=MEDCouplingFieldDouble(ON_CELLS)
12158         f.setMesh(m)
12159         arr=DataArrayDouble(5,2)
12160         arr[:,0]=range(1,6) ; arr[:,1]=2*arr[:,0]
12161         f2=f.clone(True)
12162         self.assertRaises(InterpKernelException,f.__div__,2)
12163         self.assertRaises(InterpKernelException,f.__div__,range(5))
12164         self.assertRaises(InterpKernelException,f.__div__,arr)
12165         self.assertRaises(InterpKernelException,f.__div__,f2)
12166         f.setArray(DataArrayDouble())
12167         self.assertRaises(InterpKernelException,f.__div__,2)
12168         self.assertRaises(InterpKernelException,f.__div__,range(5))
12169         self.assertRaises(InterpKernelException,f.__div__,arr)
12170         self.assertRaises(InterpKernelException,f.__div__,f2)
12171         self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
12172         f.getArray().alloc(5,2)
12173         f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
12174         self.assertRaises(InterpKernelException,f.__div__,0)
12175         ff=f/2
12176         ff.checkCoherency()
12177         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,3.5),(0.5,4),(1,4.5),(1.5,5),(2,5.5)]),1e-12))
12178         ff=f/arr
12179         ff.checkCoherency()
12180         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))
12181         self.assertRaises(InterpKernelException,f.__div__,f2)
12182         f2.setArray(arr)
12183         ff=f/f2
12184         ff.checkCoherency()
12185         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))
12186         ff=f/[5,8]
12187         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))
12188         ### MEDCouplingFieldDouble.__pow__
12189         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12190         f=MEDCouplingFieldDouble(ON_CELLS)
12191         f.setMesh(m)
12192         arr=DataArrayDouble(5)
12193         arr[:]=[1,1,3,2,0]
12194         f2=f.clone(True)
12195         self.assertRaises(InterpKernelException,f.__div__,2)
12196         self.assertRaises(InterpKernelException,f.__div__,range(5))
12197         self.assertRaises(InterpKernelException,f.__div__,arr)
12198         self.assertRaises(InterpKernelException,f.__div__,f2)
12199         f.setArray(DataArrayDouble())
12200         self.assertRaises(InterpKernelException,f.__div__,2)
12201         self.assertRaises(InterpKernelException,f.__div__,range(5))
12202         self.assertRaises(InterpKernelException,f.__div__,arr)
12203         self.assertRaises(InterpKernelException,f.__div__,f2)
12204         self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
12205         f.getArray().alloc(5,1)
12206         f.getArray()[:]=range(2,7)
12207         ff=f**2
12208         ff.checkCoherency()
12209         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([4,9,16,25,36]),1e-12))
12210         ff=f**arr
12211         ff.checkCoherency()
12212         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([2,3,64,25,1]),1e-12))
12213         f2.setArray(arr)
12214         ff=f**f2
12215         ff.checkCoherency()
12216         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([2,3,64,25,1]),1e-12))
12217         ## MEDCouplingFieldDouble.__iadd__
12218         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12219         f=MEDCouplingFieldDouble(ON_CELLS)
12220         f.setMesh(m)
12221         arr=DataArrayDouble(5,2)
12222         arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
12223         f2=f.clone(True)
12224         self.assertRaises(InterpKernelException,f.__iadd__,2)
12225         self.assertRaises(InterpKernelException,f.__iadd__,range(5))
12226         self.assertRaises(InterpKernelException,f.__iadd__,arr)
12227         self.assertRaises(InterpKernelException,f.__iadd__,f2)
12228         f.setArray(DataArrayDouble())
12229         self.assertRaises(InterpKernelException,f.__iadd__,2)
12230         self.assertRaises(InterpKernelException,f.__iadd__,range(5))
12231         self.assertRaises(InterpKernelException,f.__iadd__,arr)
12232         self.assertRaises(InterpKernelException,f.__iadd__,f2)
12233         f.getArray().alloc(5,2)
12234         f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
12235         f.checkCoherency()
12236         f+=2
12237         f.checkCoherency()
12238         self.assertTrue(f.getArray().isEqual(DataArrayDouble([(2,9),(3,10),(4,11),(5,12),(6,13)]),1e-12))
12239         f+=arr
12240         f.checkCoherency()
12241         self.assertTrue(f.getArray().isEqual(DataArrayDouble([(2,9),(4,12),(6,15),(8,18),(10,21)]),1e-12))
12242         f2.setArray(arr)
12243         f+=f2
12244         f.checkCoherency()
12245         self.assertTrue(f.getArray().isEqual(DataArrayDouble([(2,9),(5,14),(8,19),(11,24),(14,29)]),1e-12))
12246         f+=[0.1,0.2]
12247         f.checkCoherency()
12248         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))
12249         ## MEDCouplingFieldDouble.__isub__
12250         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12251         f=MEDCouplingFieldDouble(ON_CELLS)
12252         f.setMesh(m)
12253         arr=DataArrayDouble(5,2)
12254         arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
12255         f2=f.clone(True)
12256         self.assertRaises(InterpKernelException,f.__isub__,2)
12257         self.assertRaises(InterpKernelException,f.__isub__,range(5))
12258         self.assertRaises(InterpKernelException,f.__isub__,arr)
12259         self.assertRaises(InterpKernelException,f.__isub__,f2)
12260         f.setArray(DataArrayDouble())
12261         self.assertRaises(InterpKernelException,f.__isub__,2)
12262         self.assertRaises(InterpKernelException,f.__isub__,range(5))
12263         self.assertRaises(InterpKernelException,f.__isub__,arr)
12264         self.assertRaises(InterpKernelException,f.__isub__,f2)
12265         f.getArray().alloc(5,2)
12266         f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
12267         f.checkCoherency()
12268         f-=2
12269         f.checkCoherency()
12270         self.assertTrue(f.getArray().isEqual(DataArrayDouble([(-2,5),(-1,6),(0,7),(1,8),(2,9)]),1e-12))
12271         f-=arr
12272         f.checkCoherency()
12273         self.assertTrue(f.getArray().isEqual(DataArrayDouble([(-2,5),(-2,4),(-2,3),(-2,2),(-2,1)]),1e-12))
12274         f2.setArray(arr)
12275         f-=f2
12276         f.checkCoherency()
12277         self.assertTrue(f.getArray().isEqual(DataArrayDouble([(-2,5),(-3,2),(-4,-1),(-5,-4),(-6,-7)]),1e-12))
12278         f-=[0.1,0.2]
12279         f.checkCoherency()
12280         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))
12281         ## MEDCouplingFieldDouble.__imul__
12282         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12283         f=MEDCouplingFieldDouble(ON_CELLS)
12284         f.setMesh(m)
12285         arr=DataArrayDouble(5,2)
12286         arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
12287         f2=f.clone(True)
12288         self.assertRaises(InterpKernelException,f.__imul__,2)
12289         self.assertRaises(InterpKernelException,f.__imul__,range(5))
12290         self.assertRaises(InterpKernelException,f.__imul__,arr)
12291         self.assertRaises(InterpKernelException,f.__imul__,f2)
12292         f.setArray(DataArrayDouble())
12293         self.assertRaises(InterpKernelException,f.__imul__,2)
12294         self.assertRaises(InterpKernelException,f.__imul__,range(5))
12295         self.assertRaises(InterpKernelException,f.__imul__,arr)
12296         self.assertRaises(InterpKernelException,f.__imul__,f2)
12297         f.getArray().alloc(5,2)
12298         f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
12299         f.checkCoherency()
12300         f*=2
12301         f.checkCoherency()
12302         self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,14),(2,16),(4,18),(6,20),(8,22)]),1e-12))
12303         f*=arr
12304         f.checkCoherency()
12305         self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,0),(2,32),(8,72),(18,120),(32,176)]),1e-12))
12306         f2.setArray(arr)
12307         f*=f2
12308         f.checkCoherency()
12309         self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,0),(2,64),(16,288),(54,720),(128,1408)]),1e-12))
12310         f*=[0.1,0.2]
12311         f.checkCoherency()
12312         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))
12313         ## MEDCouplingFieldDouble.__idiv__
12314         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12315         f=MEDCouplingFieldDouble(ON_CELLS)
12316         f.setMesh(m)
12317         arr=DataArrayDouble(5,2)
12318         arr[:,0]=range(1,6) ; arr[:,1]=2*arr[:,0]
12319         f2=f.clone(True)
12320         self.assertRaises(InterpKernelException,f.__idiv__,2)
12321         self.assertRaises(InterpKernelException,f.__idiv__,range(5))
12322         self.assertRaises(InterpKernelException,f.__idiv__,arr)
12323         self.assertRaises(InterpKernelException,f.__idiv__,f2)
12324         f.setArray(DataArrayDouble())
12325         self.assertRaises(InterpKernelException,f.__idiv__,2)
12326         self.assertRaises(InterpKernelException,f.__idiv__,range(5))
12327         self.assertRaises(InterpKernelException,f.__idiv__,arr)
12328         self.assertRaises(InterpKernelException,f.__idiv__,f2)
12329         f.getArray().alloc(5,2)
12330         f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
12331         f.checkCoherency()
12332         f/=2
12333         f.checkCoherency()
12334         self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,3.5),(0.5,4),(1,4.5),(1.5,5),(2,5.5)]),1e-12))
12335         f/=arr
12336         f.checkCoherency()
12337         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))
12338         f2.setArray(arr)
12339         f/=f2
12340         f.checkCoherency()
12341         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))
12342         f/=[0.1,0.2]
12343         f.checkCoherency()
12344         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))
12345         ## MEDCouplingFieldDouble.__ipow__
12346         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12347         f=MEDCouplingFieldDouble(ON_CELLS)
12348         f.setMesh(m)
12349         arr=DataArrayDouble(5,2)
12350         arr[:,0]=range(1,6) ; arr[:,1]=2*arr[:,0]
12351         f2=f.clone(True)
12352         self.assertRaises(InterpKernelException,f.__ipow__,2)
12353         self.assertRaises(InterpKernelException,f.__ipow__,range(5))
12354         self.assertRaises(InterpKernelException,f.__ipow__,arr)
12355         self.assertRaises(InterpKernelException,f.__ipow__,f2)
12356         f.setArray(DataArrayDouble())
12357         self.assertRaises(InterpKernelException,f.__ipow__,2)
12358         self.assertRaises(InterpKernelException,f.__ipow__,range(5))
12359         self.assertRaises(InterpKernelException,f.__ipow__,arr)
12360         self.assertRaises(InterpKernelException,f.__ipow__,f2)
12361         f.getArray().alloc(5,2)
12362         f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
12363         f.checkCoherency()
12364         f**=2
12365         f.checkCoherency()
12366         self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,49),(1,64),(4,81),(9,100),(16,121)]),1e-12))
12367          ## MEDCouplingFieldDouble.__radd__
12368         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12369         f=MEDCouplingFieldDouble(ON_CELLS)
12370         f.setMesh(m)
12371         arr=DataArrayDouble(5,2)
12372         arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
12373         f2=f.clone(True)
12374         self.assertRaises(InterpKernelException,f.__radd__,2)
12375         self.assertRaises(InterpKernelException,f.__radd__,range(5))
12376         self.assertRaises(InterpKernelException,f.__radd__,arr)
12377         self.assertRaises(InterpKernelException,f.__radd__,f2)
12378         f.setArray(DataArrayDouble())
12379         self.assertRaises(InterpKernelException,f.__radd__,2)
12380         self.assertRaises(InterpKernelException,f.__radd__,range(5))
12381         self.assertRaises(InterpKernelException,f.__radd__,arr)
12382         self.assertRaises(InterpKernelException,f.__radd__,f2)
12383         self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
12384         f.getArray().alloc(5,2)
12385         f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
12386         ff=2+f
12387         ff.checkCoherency()
12388         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(2,9),(3,10),(4,11),(5,12),(6,13)]),1e-12))
12389         ff=arr+f
12390         ff.checkCoherency()
12391         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,7),(2,10),(4,13),(6,16),(8,19)]),1e-12))
12392         self.assertRaises(InterpKernelException,f.__radd__,f2)
12393         ff=[5,8]+f
12394         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(5,15),(6,16),(7,17),(8,18),(9,19)]),1e-12))
12395         ### MEDCouplingFieldDouble.__rsub__
12396         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12397         f=MEDCouplingFieldDouble(ON_CELLS)
12398         f.setMesh(m)
12399         arr=DataArrayDouble(5,2)
12400         arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
12401         f2=f.clone(True)
12402         self.assertRaises(InterpKernelException,f.__rsub__,2)
12403         self.assertRaises(InterpKernelException,f.__rsub__,range(5))
12404         self.assertRaises(InterpKernelException,f.__rsub__,arr)
12405         self.assertRaises(InterpKernelException,f.__rsub__,f2)
12406         f.setArray(DataArrayDouble())
12407         self.assertRaises(InterpKernelException,f.__rsub__,2)
12408         self.assertRaises(InterpKernelException,f.__rsub__,range(5))
12409         self.assertRaises(InterpKernelException,f.__rsub__,arr)
12410         self.assertRaises(InterpKernelException,f.__rsub__,f2)
12411         self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
12412         f.getArray().alloc(5,2)
12413         f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
12414         ff=2-f
12415         ff.checkCoherency()
12416         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(2,-5),(1,-6),(0,-7),(-1,-8),(-2,-9)]),1e-12))
12417         ff=arr-f
12418         ff.checkCoherency()
12419         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,-7),(0,-6),(0,-5),(0,-4),(0,-3)]),1e-12))
12420         self.assertRaises(InterpKernelException,f.__rsub__,f2)
12421         ### MEDCouplingFieldDouble.__rmul__
12422         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12423         f=MEDCouplingFieldDouble(ON_CELLS)
12424         f.setMesh(m)
12425         arr=DataArrayDouble(5,2)
12426         arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
12427         f2=f.clone(True)
12428         self.assertRaises(InterpKernelException,f.__rmul__,2)
12429         self.assertRaises(InterpKernelException,f.__rmul__,range(5))
12430         self.assertRaises(InterpKernelException,f.__rmul__,arr)
12431         self.assertRaises(InterpKernelException,f.__rmul__,f2)
12432         f.setArray(DataArrayDouble())
12433         self.assertRaises(InterpKernelException,f.__rmul__,2)
12434         self.assertRaises(InterpKernelException,f.__rmul__,range(5))
12435         self.assertRaises(InterpKernelException,f.__rmul__,arr)
12436         self.assertRaises(InterpKernelException,f.__rmul__,f2)
12437         self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
12438         f.getArray().alloc(5,2)
12439         f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
12440         ff=2*f
12441         ff.checkCoherency()
12442         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,14),(2,16),(4,18),(6,20),(8,22)]),1e-12))
12443         ff=arr*f
12444         ff.checkCoherency()
12445         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,0),(1,16),(4,36),(9,60),(16,88)]),1e-12))
12446         self.assertRaises(InterpKernelException,f.__rmul__,f2)
12447         ff=f*[5,8]
12448         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,56),(5,64),(10,72),(15,80),(20,88)]),1e-12))
12449         ### MEDCouplingFieldDouble.__rdiv__
12450         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12451         f=MEDCouplingFieldDouble(ON_CELLS)
12452         f.setMesh(m)
12453         arr=DataArrayDouble(5,2)
12454         arr[:,0]=range(1,6) ; arr[:,1]=2*arr[:,0]
12455         f2=f.clone(True)
12456         self.assertRaises(InterpKernelException,f.__rdiv__,2)
12457         self.assertRaises(InterpKernelException,f.__rdiv__,range(5))
12458         self.assertRaises(InterpKernelException,f.__rdiv__,arr)
12459         self.assertRaises(InterpKernelException,f.__rdiv__,f2)
12460         f.setArray(DataArrayDouble())
12461         self.assertRaises(InterpKernelException,f.__rdiv__,2)
12462         self.assertRaises(InterpKernelException,f.__rdiv__,range(5))
12463         self.assertRaises(InterpKernelException,f.__rdiv__,arr)
12464         self.assertRaises(InterpKernelException,f.__rdiv__,f2)
12465         self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
12466         f.getArray().alloc(5,2)
12467         f.getArray()[:,0]=range(1,6) ; f.getArray()[:,1]=f.getArray()[:,0]+7
12468         ff=2/f
12469         ff.checkCoherency()
12470         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))
12471         ff=arr/f
12472         ff.checkCoherency()
12473         self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(1,0.25),(1,0.44444444444444442),(1,0.59999999999999998),(1,0.72727272727272729),(1,0.83333333333333337)]),1e-12))
12474         self.assertRaises(InterpKernelException,f.__rdiv__,f2)
12475         pass
12476     
12477     def testSwig2FieldDoubleBuildSubPartRange1(self):
12478         #ON_CELLS
12479         m=MEDCouplingDataForTest.build2DTargetMesh_1()
12480         f=MEDCouplingFieldDouble(ON_CELLS)
12481         f.setMesh(m)
12482         arr=DataArrayDouble(5,2) ; arr[:,0]=range(7,12) ; arr[:,1]=100+arr[:,0]
12483         f.setArray(arr)
12484         f.checkCoherency()
12485         ff=f[1:-1:2]
12486         ff.checkCoherency()
12487         self.assertTrue((m.buildPartOfMySelf([1,3],True)).isEqual(ff.getMesh(),1e-12))
12488         self.assertTrue(9,ff.getMesh().getNumberOfNodes())
12489         self.assertTrue(2,ff.getMesh().getNumberOfCells())
12490         self.assertTrue(ff.getArray().isEqual(arr[[1,3]],1e-12))
12491         #
12492         a,b=f.buildSubMeshDataRange(2,5,1)
12493         self.assertTrue(m.buildPartOfMySelf([2,3,4],True).isEqual(a,1e-12))
12494         self.assertEqual(b,slice(2,5,1))
12495         ff=f[2:]
12496         ff.checkCoherency()
12497         self.assertTrue((m.buildPartOfMySelf([2,3,4],True)).isEqual(ff.getMesh(),1e-12))
12498         self.assertTrue(9,ff.getMesh().getNumberOfNodes())
12499         self.assertTrue(3,ff.getMesh().getNumberOfCells())
12500         self.assertTrue(ff.getArray().isEqual(arr[[2,3,4]],1e-12))
12501         #
12502         ff=f[-2:0:-1]
12503         ff.checkCoherency()
12504         self.assertTrue((m.buildPartOfMySelf([3,2,1],True)).isEqual(ff.getMesh(),1e-12))
12505         self.assertTrue(9,ff.getMesh().getNumberOfNodes())
12506         self.assertTrue(3,ff.getMesh().getNumberOfCells())
12507         self.assertTrue(ff.getArray().isEqual(arr[[3,2,1]],1e-12))
12508         self.assertTrue(f[-2:0:-1,1].getArray().isEqual(arr[[3,2,1],1],1e-12))
12509         #ON_NODES
12510         f=MEDCouplingFieldDouble(ON_NODES)
12511         f.setMesh(m)
12512         arr=DataArrayDouble(9,2) ; arr[:,0]=range(7,16) ; arr[:,1]=100+arr[:,0]
12513         f.setArray(arr)
12514         f.checkCoherency()
12515         ff=f[1:-1:2]
12516         ff.checkCoherency()
12517         self.assertTrue((m.buildPartOfMySelf([1,3],False)).isEqual(ff.getMesh(),1e-12))
12518         self.assertTrue(6,ff.getMesh().getNumberOfNodes())
12519         self.assertTrue(2,ff.getMesh().getNumberOfCells())
12520         self.assertTrue(ff.getArray().isEqual(arr[[1,2,3,4,6,7]],1e-12))
12521         #
12522         m2=m.buildPartRange(2,5,1)
12523         self.assertTrue(m.buildPartOfMySelf([2,3,4],True).isEqual(m2,1e-12))
12524         m2,b=m.buildPartRangeAndReduceNodes(2,5,1)
12525         self.assertTrue(m.buildPartOfMySelf([2,3,4],False).isEqual(m2,1e-12))
12526         self.assertTrue(b.isEqual(DataArrayInt([-1,-1,0,1,2,3,4,5,6])))
12527         a,b=f.buildSubMeshDataRange(2,5,1)
12528         self.assertTrue(m.buildPartOfMySelf([2,3,4],False).isEqual(a,1e-12))
12529         self.assertTrue(b.isEqual(DataArrayInt([2,3,4,5,6,7,8])))
12530         ff=f[2:]
12531         ff.checkCoherency()
12532         self.assertTrue((m.buildPartOfMySelf([2,3,4],False)).isEqual(ff.getMesh(),1e-12))
12533         self.assertTrue(7,ff.getMesh().getNumberOfNodes())
12534         self.assertTrue(3,ff.getMesh().getNumberOfCells())
12535         self.assertTrue(ff.getArray().isEqual(arr[[2,3,4,5,6,7,8]],1e-12))
12536         #
12537         ff=f[-2:0:-1]
12538         ff.checkCoherency()
12539         self.assertTrue((m.buildPartOfMySelf([3,2,1],False)).isEqual(ff.getMesh(),1e-12))
12540         self.assertTrue(7,ff.getMesh().getNumberOfNodes())
12541         self.assertTrue(3,ff.getMesh().getNumberOfCells())
12542         self.assertTrue(ff.getArray().isEqual(arr[[1,2,3,4,5,6,7]],1e-12))
12543         self.assertTrue(f[-2:0:-1,1].getArray().isEqual(arr[[1,2,3,4,5,6,7],1],1e-12))
12544         #ON_GAUSS_NE
12545         f=MEDCouplingFieldDouble(ON_GAUSS_NE)
12546         f.setMesh(m)
12547         arr=DataArrayDouble(18,2) ; arr[:,0]=range(7,25) ; arr[:,1]=100+arr[:,0]
12548         f.setArray(arr)
12549         f.checkCoherency()
12550         ff=f[1:-1:2]
12551         ff.checkCoherency()
12552         self.assertTrue((m.buildPartOfMySelf([1,3],True)).isEqual(ff.getMesh(),1e-12))
12553         self.assertTrue(9,ff.getMesh().getNumberOfNodes())
12554         self.assertTrue(2,ff.getMesh().getNumberOfCells())
12555         self.assertTrue(ff.getArray().isEqual(arr[[4,5,6,10,11,12,13]],1e-12))
12556         #
12557         a,b=f.buildSubMeshDataRange(2,5,1)
12558         self.assertTrue(m.buildPartOfMySelf([2,3,4],True).isEqual(a,1e-12))
12559         self.assertEqual(b,slice(7,18,1))
12560         ff=f[2:]
12561         ff.checkCoherency()
12562         self.assertTrue((m.buildPartOfMySelf([2,3,4],True)).isEqual(ff.getMesh(),1e-12))
12563         self.assertTrue(9,ff.getMesh().getNumberOfNodes())
12564         self.assertTrue(3,ff.getMesh().getNumberOfCells())
12565         self.assertTrue(ff.getArray().isEqual(arr[[7,8,9,10,11,12,13,14,15,16,17]],1e-12))
12566         #
12567         ff=f[-2:0:-1]
12568         ff.checkCoherency()
12569         self.assertTrue((m.buildPartOfMySelf([3,2,1],True)).isEqual(ff.getMesh(),1e-12))
12570         self.assertTrue(9,ff.getMesh().getNumberOfNodes())
12571         self.assertTrue(3,ff.getMesh().getNumberOfCells())
12572         self.assertTrue(ff.getArray().isEqual(arr[[10,11,12,13,7,8,9,4,5,6]],1e-12))
12573         self.assertTrue(f[-2:0:-1,1].getArray().isEqual(arr[[10,11,12,13,7,8,9,4,5,6],1],1e-12))
12574         #ON_GAUSS_PT
12575         f=MEDCouplingFieldDouble(ON_GAUSS_PT)
12576         f.setMesh(m)
12577         f.setGaussLocalizationOnCells([0,4],[0,0,1,0,1,1,1,0],[1.1,1.1,2.2,2.2],[0.2,0.8]);
12578         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]);
12579         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]);
12580         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]);
12581         arr=DataArrayDouble(16,2) ; arr[:,0]=range(7,23) ; arr[:,1]=100+arr[:,0]
12582         f.setArray(arr)
12583         f.checkCoherency()
12584         ff=f[1:-1:2]
12585         ff.checkCoherency()
12586         self.assertTrue((m.buildPartOfMySelf([1,3],True)).isEqual(ff.getMesh(),1e-12))
12587         self.assertTrue(9,ff.getMesh().getNumberOfNodes())
12588         self.assertTrue(2,ff.getMesh().getNumberOfCells())
12589         self.assertTrue(ff.getArray().isEqual(arr[[2,3,4,5,11,12,13]],1e-12))
12590         #
12591         a,b=f.buildSubMeshDataRange(2,5,1)
12592         self.assertTrue(m.buildPartOfMySelf([2,3,4],True).isEqual(a,1e-12))
12593         self.assertEqual(b,slice(6,16,1))
12594         ff=f[2:]
12595         ff.checkCoherency()
12596         self.assertTrue((m.buildPartOfMySelf([2,3,4],True)).isEqual(ff.getMesh(),1e-12))
12597         self.assertTrue(9,ff.getMesh().getNumberOfNodes())
12598         self.assertTrue(3,ff.getMesh().getNumberOfCells())
12599         self.assertTrue(ff.getArray().isEqual(arr[[6,7,8,9,10,11,12,13,14,15]],1e-12))
12600         #
12601         ff=f[-2:0:-1]
12602         ff.checkCoherency()
12603         self.assertTrue((m.buildPartOfMySelf([3,2,1],True)).isEqual(ff.getMesh(),1e-12))
12604         self.assertTrue(9,ff.getMesh().getNumberOfNodes())
12605         self.assertTrue(3,ff.getMesh().getNumberOfCells())
12606         self.assertTrue(ff.getArray().isEqual(arr[[11,12,13,6,7,8,9,10,2,3,4,5]],1e-12))
12607         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))
12608         pass
12609
12610     def testSwig2FieldDoubleApplyFuncBug1(self):
12611         f=MEDCouplingFieldDouble(ON_CELLS)
12612         f.setMesh(MEDCouplingDataForTest.build2DTargetMesh_1())
12613         f.applyFunc(3,700.)
12614         f.checkCoherency()
12615         self.assertEqual(3,f.getArray().getNumberOfComponents())
12616         f.getArray().rearrange(1)
12617         self.assertTrue(f.getArray().isUniform(700.,1e-10))
12618         f.getArray().rearrange(3)
12619         f.checkCoherency()
12620         f.applyFunc(4,800.)
12621         f.checkCoherency()
12622         self.assertEqual(4,f.getArray().getNumberOfComponents())
12623         f.getArray().rearrange(1)
12624         self.assertTrue(f.getArray().isUniform(800.,1e-10))
12625         f.getArray().rearrange(4)
12626         f.checkCoherency()
12627         pass
12628
12629     def testSwig2ComputeTupleIdsNearTupleBug1(self):
12630         coords=[1.1,0.0, 1.1,0.0 ];
12631         coordsArr=DataArrayDouble(coords,2,2);
12632         mesh=MEDCouplingUMesh();
12633         mesh.setCoords(coordsArr);
12634         points=[1.1, 0.002]
12635         c,cI=mesh.getNodeIdsNearPoints(points,0.00185);
12636         self.assertTrue(c.isEqual(DataArrayInt([])))
12637         self.assertTrue(cI.isEqual(DataArrayInt([0,0])))
12638         c,cI=mesh.getNodeIdsNearPoints(points,0.00200000000000001);
12639         self.assertTrue(c.isEqual(DataArrayInt([0,1])))
12640         self.assertTrue(cI.isEqual(DataArrayInt([0,2])))
12641         pass
12642
12643     def testSwig2NonRegressionBugChangeUnderlyingWithZeroCells(self):
12644         coords1=[0.,1.,2.,3.]
12645         coords2=[2.,1.,0.,3.] #0 <==> #2
12646         # mesh 1
12647         mesh1=MEDCouplingUMesh.New();
12648         coordsArr=DataArrayDouble.New(coords1,4,1);
12649         mesh1.setCoords(coordsArr);
12650         mesh1.setMeshDimension(0);
12651         mesh1.allocateCells(0);
12652         mesh1.finishInsertingCells();
12653         # mesh 2
12654         mesh2=mesh1.deepCpy();
12655         coordsArr=DataArrayDouble.New(coords2,4,1);
12656         mesh2.setCoords(coordsArr);
12657         field = mesh1.fillFromAnalytic(ON_NODES,1,"x")
12658         field.checkCoherency()
12659         levOfCheck = 10
12660         field.changeUnderlyingMesh( mesh2, levOfCheck, 1e-13, 0 )
12661         self.assertTrue( field.getArray().getValues() == coords2 )
12662         pass
12663
12664     def testSwig2UMeshDistanceToMesh2(self):
12665         sz=5
12666         m=MEDCouplingCMesh()
12667         arr=DataArrayDouble(sz+1) ; arr.iota() ; arr/=sz
12668         m.setCoords(arr,arr,arr)
12669         m=m.buildUnstructured()
12670         m1=m.computeSkin()
12671         m1.zipCoords()
12672         c=m1.getCoords()[:]
12673         d=2*(c-[0.5,0.5,0.5])+[0.5,0.5,0.5]
12674         time_deb = datetime.now()
12675         #print "go.."
12676         a,b=m1.distanceToPoints(d)
12677         #print 'time spent in distanceToPoints %s ' %str(datetime.now() - time_deb)
12678         time_deb = datetime.now()
12679         a1=DataArrayDouble(len(d))
12680         b1=DataArrayInt(len(d))
12681         m1s=[m1[i] for i in xrange(m1.getNumberOfCells())]
12682         for j,pt in enumerate(d):
12683             eter=1e308
12684             fter=-1
12685             for i,miter in enumerate(m1s):
12686                 e,f=miter.distanceToPoint(pt)
12687                 self.assertEqual(0,f)
12688                 if e<eter:
12689                     eter=e ; fter=i
12690                     pass
12691                 pass
12692             a1[j]=eter
12693             b1[j]=fter
12694             pass
12695         #print 'time spent in naive distanceToPoints  %s ' %str(datetime.now() - time_deb)
12696         self.assertTrue(a.isEqual(a1,1e-12))
12697         self.assertTrue(b.isEqual(b1))
12698         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))
12699         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])))
12700         pass
12701
12702     def testSwig2NonRegressionBugDistance1(self):
12703         pt=DataArrayDouble([(8.8452994616207476,3.1547005383792515,3.1547005383792515)])
12704         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)])
12705         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])
12706         m=MEDCouplingUMesh("mesh",2)
12707         m.setCoords(coo)
12708         m.allocateCells()
12709         for i in xrange(24):
12710             m.insertNextCell(NORM_QUAD4,conn[4*i:4*i+4])
12711             pass
12712         m.checkCoherency2()
12713         m0=m[3] ; m0.zipCoords()
12714         expectedDist=0.8452994616207476
12715         a,b=m0.distanceToPoint(pt)
12716         self.assertAlmostEqual(expectedDist,a,14)
12717         self.assertEqual(0,b)
12718         #
12719         a,b=m.distanceToPoint(pt)
12720         self.assertAlmostEqual(expectedDist,a,14)
12721         self.assertEqual(3,b)
12722         #
12723         fd=MEDCouplingFieldDiscretization.New(ON_CELLS)
12724         self.assertEqual(24,fd.getNumberOfTuples(m))
12725         fd=MEDCouplingFieldDiscretization.New(ON_NODES)
12726         self.assertEqual(26,fd.getNumberOfTuples(m))
12727         pass
12728
12729     def testSwig2AreaBarySeg3Quad8Tri6QPolyg(self):
12730         #QUAD8 representing a circle of center zeBary and radius zeRadius
12731         zeBary=[5,6]
12732         zeRadius=3
12733         d=DataArrayDouble(8,2)
12734         d[:,0]=zeRadius
12735         d[:,1]=[87,-100,-170,110,5,-130,175,95] # angle in degree
12736         d[:,1]*=pi/180. # angle in radian
12737         d=d.fromPolarToCart()
12738         d+=zeBary
12739         m=MEDCouplingUMesh("quad8",2) ; m.allocateCells() ; m.insertNextCell(NORM_QUAD8,range(8)) ; m.setCoords(d)
12740         self.assertTrue(m.getBarycenterAndOwner().isEqual(DataArrayDouble(zeBary,1,2),1e-13))
12741         self.assertAlmostEqual(float(m.getMeasureField(False).getArray()),pi*zeRadius*zeRadius,12)
12742         tri32D=m.buildDescendingConnectivity()[0][0] ; tri32D.zipCoords()
12743         # spaceDim=3 QUAD8 becomes QUAD4 ... for the moment
12744         m.setCoords(m.getCoords().changeNbOfComponents(3,0.))
12745         m2=m.deepCpy()
12746         m2.convertQuadraticCellsToLinear()
12747         self.assertAlmostEqual(float(m.getMeasureField(False).getArray()),float(m2.getMeasureField(False).getArray()),12)
12748         self.assertTrue(m.getBarycenterAndOwner().isEqual(m2.getBarycenterAndOwner(),1e-13))
12749         #TRI6 representing a circle of center zeBary and radius zeRadius
12750         zeBary=[5,6]
12751         zeRadius=3
12752         d=DataArrayDouble(6,2)
12753         d[:,0]=zeRadius
12754         d[:,1]=[87,-100,110,5,175,95] # angle in degree
12755         d[:,1]*=pi/180. # angle in radian
12756         d=d.fromPolarToCart()
12757         d+=zeBary
12758         m=MEDCouplingUMesh("tri6",2) ; m.allocateCells() ; m.insertNextCell(NORM_TRI6,range(6)) ; m.setCoords(d)
12759         self.assertTrue(m.getBarycenterAndOwner().isEqual(DataArrayDouble(zeBary,1,2),1e-13))
12760         self.assertAlmostEqual(float(m.getMeasureField(False).getArray()),pi*zeRadius*zeRadius,12)
12761         # spaceDim=3 TRI6 becomes TRI3 ... for the moment
12762         m.setCoords(m.getCoords().changeNbOfComponents(3,0.))
12763         m2=m.deepCpy()
12764         m2.convertQuadraticCellsToLinear()
12765         self.assertAlmostEqual(float(m.getMeasureField(False).getArray()),float(m2.getMeasureField(False).getArray()),12)
12766         self.assertTrue(m.getBarycenterAndOwner().isEqual(m2.getBarycenterAndOwner(),1e-13))
12767         # QPOLYG representing a circle of center zeBary and radius zeRadius
12768         zeBary=[5,6]
12769         zeRadius=3
12770         d=DataArrayDouble(10,2)
12771         d[:,0]=zeRadius
12772         d[:,1]=[87,-80,-100,-170,110,5,-90,-130,175,95] # angle in degree
12773         d[:,1]*=pi/180. # angle in radian
12774         d=d.fromPolarToCart()
12775         d+=zeBary
12776         m=MEDCouplingUMesh("qpolyg",2) ; m.allocateCells() ; m.insertNextCell(NORM_QPOLYG,range(10)) ; m.setCoords(d)
12777         self.assertTrue(m.getBarycenterAndOwner().isEqual(DataArrayDouble(zeBary,1,2),1e-13))
12778         self.assertAlmostEqual(float(m.getMeasureField(False).getArray()),pi*zeRadius*zeRadius,12)
12779         # spaceDim=3 QPOLYG becomes POLYG ... for the moment
12780         m.setCoords(m.getCoords().changeNbOfComponents(3,0.))
12781         m2=m.deepCpy()
12782         m2.convertQuadraticCellsToLinear() ; m2.checkCoherency2()
12783         self.assertTrue(m2.getAllGeoTypes()==[NORM_POLYGON] and m2.getNodalConnectivity().getValues()==[5,0,1,2,3,4])
12784         self.assertAlmostEqual(float(m.getMeasureField(False).getArray()),float(m2.getMeasureField(False).getArray()),12)
12785         self.assertTrue(m.getBarycenterAndOwner().isEqual(m2.getBarycenterAndOwner(),1e-13))
12786         # TRI3
12787         self.assertAlmostEqual(float(tri32D.getMeasureField(False).getArray()),(87+100)*pi/180*zeRadius,13)
12788         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)
12789         self.assertTrue(tri32D.getBarycenterAndOwner().isEqual(exp,1e-12))
12790         # spaceDim=3 TRI3 becomes TRI2 ... for the moment
12791         tri32D.changeSpaceDimension(3)
12792         tri2=tri32D.deepCpy() ; tri2.convertQuadraticCellsToLinear()
12793         self.assertAlmostEqual(float(tri32D.getMeasureField(False).getArray()),float(tri2.getMeasureField(False).getArray()),13)
12794         self.assertTrue(tri32D.getBarycenterAndOwner().isEqual(tri2.getBarycenterAndOwner(),1e-12))
12795         tri32D.changeSpaceDimension(1)
12796         self.assertAlmostEqual(float(tri32D.getMeasureField(False).getArray()),-0.67795240172962323,12)
12797         pass
12798
12799     # this bug 5/6/2013 is swig specific
12800     def testSwigNonRegressionBugRotate3D1(self):
12801         m=MEDCouplingUMesh.New()
12802         dataArray=DataArrayDouble.New(100,3)
12803         dataArray[:]=0.
12804         dataArray[0]=[0.,1,3]
12805         m.setCoords(dataArray[0])
12806         m1=m.deepCpy()
12807         m.rotate([0.,0.,3.],[1.,0.,0.],0.5*pi)
12808         self.assertTrue(m.getCoords().isEqual(DataArrayDouble([0.,0.,4.],1,3),1e-15))
12809         #
12810         d1=DataArrayDouble([0.,0.,3.],1,3) ; d2=DataArrayDouble([1.,0.,0.],1,3)
12811         pts=[[0.,0.,3.],[(0.,0.,3.)],DataArrayDouble([0.,0.,3.],1,3),list(d1)[0]]
12812         vec=[[1.,0.,0.],[(1.,0.,0.)],DataArrayDouble([1.,0.,0.],1,3),list(d2)[0]]
12813         for p in pts:
12814             for v in vec:
12815                 m2=m1.deepCpy()
12816                 m2.rotate(p,v,0.5*pi)
12817                 self.assertTrue(m2.getCoords().isEqual(DataArrayDouble([0.,0.,4.],1,3),1e-15))
12818                 pass
12819         pass
12820
12821     def testSwig2DataArrayCount1(self):
12822         d=DataArrayInt([])
12823         self.assertEqual(0,d.getNumberOfTuples())
12824         self.assertEqual(1,d.getNumberOfComponents())
12825         self.assertEqual(0,d.count(0))
12826         self.assertEqual(0,d.count(1))
12827         self.assertEqual(0,d.count(-1))
12828         d=DataArrayInt([2,1,-2,-3,2,0,0,7,2,-2,3,0])
12829         self.assertEqual(12,d.getNumberOfTuples())
12830         self.assertEqual(1,d.getNumberOfComponents())
12831         self.assertEqual(3,d.count(0))
12832         self.assertEqual(1,d.count(1))
12833         self.assertEqual(0,d.count(-1))
12834         self.assertEqual(2,d.count(-2))
12835         self.assertEqual(3,d.count(2))
12836         e=d.getDifferentValues()
12837         f=DataArrayInt()
12838         for it in e:
12839             f.pushBackSilent(d.count(int(it)))
12840             pass
12841         self.assertEqual(12,f.accumulate()[0])
12842         #
12843         eps=1e-12
12844         d=DataArrayDouble([])
12845         self.assertEqual(0,d.getNumberOfTuples())
12846         self.assertEqual(1,d.getNumberOfComponents())
12847         self.assertEqual(0,d.count(0,eps))
12848         self.assertEqual(0,d.count(1,eps))
12849         self.assertEqual(0,d.count(-1,eps))
12850         d=DataArrayDouble([2,1,-2,-3,2,0,eps/10,7,2+eps/10,-2,3,0])
12851         self.assertEqual(12,d.getNumberOfTuples())
12852         self.assertEqual(1,d.getNumberOfComponents())
12853         self.assertEqual(3,d.count(0,eps))
12854         self.assertEqual(1,d.count(1,eps))
12855         self.assertEqual(0,d.count(-1,eps))
12856         self.assertEqual(2,d.count(-2,eps))
12857         self.assertEqual(3,d.count(2,eps))
12858         self.assertEqual(3,d.count(2,eps))
12859         self.assertEqual(2,d.count(2,eps/100))
12860         e=d.getDifferentValues(eps)
12861         f=DataArrayInt()
12862         for it in e:
12863             f.pushBackSilent(d.count(float(it),eps))
12864             pass
12865         self.assertEqual(12,f.accumulate()[0])
12866         pass
12867
12868     def testSwig2DataArrayGetSlice1(self):
12869         s=slice(2,18,1)
12870         self.assertEqual(DataArray.GetNumberOfItemGivenBESRelative(s),16)
12871         self.assertEqual(DataArray.GetNumberOfItemGivenBES(s),16)
12872         self.assertEqual(DataArray.GetSlice(s,0,4),slice(2,6,1))
12873         self.assertEqual(DataArray.GetSlice(s,1,4),slice(6,10,1))
12874         self.assertEqual(DataArray.GetSlice(s,2,4),slice(10,14,1))
12875         self.assertEqual(DataArray.GetSlice(s,3,4),slice(14,18,1))
12876         #
12877         s=slice(2,18,2)
12878         self.assertEqual(DataArray.GetNumberOfItemGivenBESRelative(s),8)
12879         self.assertEqual(DataArray.GetNumberOfItemGivenBES(s),8)
12880         self.assertEqual(DataArray.GetSlice(s,0,4),slice(2,6,2))
12881         self.assertEqual(DataArray.GetSlice(s,1,4),slice(6,10,2))
12882         self.assertEqual(DataArray.GetSlice(s,2,4),slice(10,14,2))
12883         self.assertEqual(DataArray.GetSlice(s,3,4),slice(14,18,2))
12884         #
12885         s=slice(1,18,1)
12886         self.assertEqual(DataArray.GetSlice(s,0,4),slice(1,5,1))
12887         self.assertEqual(DataArray.GetSlice(s,1,4),slice(5,9,1))
12888         self.assertEqual(DataArray.GetSlice(s,2,4),slice(9,13,1))
12889         self.assertEqual(DataArray.GetSlice(s,3,4),slice(13,18,1))# 18 not 17
12890         #
12891         s=slice(1,18,2)
12892         self.assertEqual(DataArray.GetNumberOfItemGivenBESRelative(s),9)
12893         self.assertEqual(DataArray.GetNumberOfItemGivenBES(s),9)
12894         self.assertEqual(DataArray.GetSlice(s,0,4),slice(1,5,2))
12895         self.assertEqual(DataArray.GetSlice(s,1,4),slice(5,9,2))
12896         self.assertEqual(DataArray.GetSlice(s,2,4),slice(9,13,2))
12897         self.assertEqual(DataArray.GetSlice(s,3,4),slice(13,18,2))# 18 not 17
12898         #
12899         s=slice(18,2,-1)
12900         self.assertEqual(DataArray.GetSlice(s,0,4),slice(18,14,-1))
12901         self.assertEqual(DataArray.GetSlice(s,1,4),slice(14,10,-1))
12902         self.assertEqual(DataArray.GetSlice(s,2,4),slice(10,6,-1))
12903         self.assertEqual(DataArray.GetSlice(s,3,4),slice(6,2,-1))
12904         #
12905         s=slice(18,2,-2)
12906         self.assertEqual(DataArray.GetSlice(s,0,4),slice(18,14,-2))
12907         self.assertEqual(DataArray.GetSlice(s,1,4),slice(14,10,-2))
12908         self.assertEqual(DataArray.GetSlice(s,2,4),slice(10,6,-2))
12909         self.assertEqual(DataArray.GetSlice(s,3,4),slice(6,2,-2))
12910         #
12911         s=slice(18,1,-1)
12912         self.assertEqual(DataArray.GetSlice(s,0,4),slice(18,14,-1))
12913         self.assertEqual(DataArray.GetSlice(s,1,4),slice(14,10,-1))
12914         self.assertEqual(DataArray.GetSlice(s,2,4),slice(10,6,-1))
12915         self.assertEqual(DataArray.GetSlice(s,3,4),slice(6,1,-1))# 1 not 2
12916         #
12917         s=slice(18,1,-2)
12918         self.assertEqual(DataArray.GetNumberOfItemGivenBESRelative(s),9)
12919         self.assertRaises(InterpKernelException,DataArray.GetNumberOfItemGivenBES,s)
12920         self.assertEqual(sum([DataArray.GetNumberOfItemGivenBESRelative(DataArray.GetSlice(s,i,4)) for i in xrange(4)]),DataArray.GetNumberOfItemGivenBESRelative(s))
12921         self.assertEqual(DataArray.GetSlice(s,0,4),slice(18,14,-2))
12922         self.assertEqual(DataArray.GetSlice(s,1,4),slice(14,10,-2))
12923         self.assertEqual(DataArray.GetSlice(s,2,4),slice(10,6,-2))
12924         self.assertEqual(DataArray.GetSlice(s,3,4),slice(6,1,-2))# 1 not 2
12925         self.assertRaises(InterpKernelException,DataArray.GetSlice,slice(0,None,2),0,4)
12926         #
12927         d=DataArrayInt.Range(0,18,1)
12928         s=slice(2,None,1)
12929         self.assertEqual(d.getNumberOfItemGivenBES(s),16)
12930         self.assertEqual(d.getNumberOfItemGivenBESRelative(s),16)
12931         self.assertEqual(d.getSlice(s,0,4),slice(2,6,1))
12932         self.assertEqual(d.getSlice(s,1,4),slice(6,10,1))
12933         self.assertEqual(d.getSlice(s,2,4),slice(10,14,1))
12934         self.assertEqual(d.getSlice(s,3,4),slice(14,18,1))
12935         #
12936         d=DataArrayInt.Range(0,18,1)
12937         s=slice(2,-2,1)
12938         self.assertEqual(d.getSlice(s,0,4),slice(2,5,1))
12939         self.assertEqual(d.getSlice(s,1,4),slice(5,8,1))
12940         self.assertEqual(d.getSlice(s,2,4),slice(8,11,1))
12941         self.assertEqual(d.getSlice(s,3,4),slice(11,16,1))
12942         #
12943         d=DataArrayInt.Range(0,18,1)
12944         s=slice(None,None,1)
12945         self.assertEqual(d.getSlice(s,0,4),slice(0,4,1))
12946         self.assertEqual(d.getSlice(s,1,4),slice(4,8,1))
12947         self.assertEqual(d.getSlice(s,2,4),slice(8,12,1))
12948         self.assertEqual(d.getSlice(s,3,4),slice(12,18,1))
12949         #
12950         d=DataArrayInt.Range(0,18,1)
12951         s=slice(None,2,-2)
12952         self.assertRaises(InterpKernelException,d.getNumberOfItemGivenBES,s)
12953         self.assertEqual(d.getNumberOfItemGivenBESRelative(s),8)
12954         self.assertEqual(d.getSlice(s,0,4),slice(17,13,-2))
12955         self.assertEqual(d.getSlice(s,1,4),slice(13,9,-2))
12956         self.assertEqual(d.getSlice(s,2,4),slice(9,5,-2))
12957         self.assertEqual(d.getSlice(s,3,4),slice(5,2,-2))
12958         pass
12959
12960     def testSwig2AccumulatePerChunk1(self):
12961         arr=DataArrayDouble(11) ; arr.iota()
12962         m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
12963         m=m.buildUnstructured()
12964         m0=m[::2] ; ids0=m0.simplexize(0) ; m1=m[1::2]
12965         m=MEDCouplingUMesh.MergeUMeshesOnSameCoords(m0,m1) ; m.setName("mesh")
12966         m.checkConsecutiveCellTypesForMEDFileFrmt()
12967         #
12968         formula="7-sqrt((x-5.)*(x-5.)+(y-5.)*(y-5.))"
12969         f=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f.setMesh(m)
12970         f.fillFromAnalytic(1,formula)
12971         f.setName("Field1") ; f.setTime(1.1,1,-1)
12972         f.checkCoherency()
12973         #
12974         arr=f.getArray()
12975         arr2=DataArrayDouble(len(arr),2) ; arr2[:,0]=arr
12976         arr2=DataArrayDouble(len(arr),2) ; arr2[:,0]=arr ; arr2[:,1]=2*arr
12977         f.setArray(arr2)
12978         f.checkCoherency()
12979         # here the compact code to obviously put field on cell to nodes
12980         rn,rni=f.getMesh().getReverseNodalConnectivity()
12981         arr2=f.getArray()[rn]
12982         arr4=arr2.accumulatePerChunck(rni)
12983         nbOfCellsSharingNodes=rni.deltaShiftIndex()
12984         arr4/=nbOfCellsSharingNodes.convertToDblArr()
12985         #
12986         maxNbCSN=nbOfCellsSharingNodes.getMaxValue()[0]
12987         arr3=DataArrayDouble(f.getMesh().getNumberOfNodes(),f.getArray().getNumberOfComponents()) ; arr3[:]=0.
12988         for i in xrange(1,maxNbCSN+1):
12989             ids=nbOfCellsSharingNodes.getIdsEqual(i)
12990             if len(ids)==0:
12991                 continue
12992             for j in range(i):
12993                 rni2=rni[ids] ; rni2+=j
12994                 arr3[ids]+=arr2[rni2]
12995                 pass
12996             arr3[ids]/=i
12997             pass
12998         fNode=MEDCouplingFieldDouble(ON_NODES,ONE_TIME) ; fNode.setMesh(m)
12999         fNode.setName("Field1Node") ; fNode.setTime(1.1,1,-1)
13000         fNode.setArray(arr3) ; fNode.checkCoherency()
13001         self.assertTrue(arr3.isEqual(arr4,1e-12))
13002         #
13003         d=DataArrayInt.Range(0,20,1)
13004         self.assertTrue(d.accumulatePerChunck([2,4,12]).isEqual(DataArrayInt([5,60])))
13005         #
13006         a=DataArrayDouble(12) ; a.iota() ; a.rearrange(3)
13007         b=DataArrayDouble(12) ; b.iota(20) ; b.rearrange(3)
13008         ids=DataArrayInt([])
13009         self.assertEqual(len(a[ids]),0)
13010         self.assertEqual(len(b[ids]),0)
13011         a2=a.deepCpy() ;  a2[ids]+=b[ids] ; self.assertTrue(a2.isEqual(a,1e-15))
13012         a2=a.deepCpy() ;  a2[ids]*=b[ids] ; self.assertTrue(a2.isEqual(a,1e-15))
13013         a2=a.deepCpy() ;  a2[ids]/=b[ids] ; self.assertTrue(a2.isEqual(a,1e-15))
13014         a2=a.deepCpy() ;  a2[ids]-=b[ids] ; self.assertTrue(a2.isEqual(a,1e-15))
13015         pass
13016
13017     def testSwig2CheckAndPreparePermutation1(self):
13018         a=DataArrayInt([10003,9999999,5,67])
13019         self.assertTrue(a.checkAndPreparePermutation().isEqual(DataArrayInt([2,3,0,1])))
13020         a=DataArrayInt([10003,-9999999,5,67])
13021         self.assertTrue(a.checkAndPreparePermutation().isEqual(DataArrayInt([3,0,1,2])))
13022         a=DataArrayInt([])
13023         self.assertTrue(a.checkAndPreparePermutation().isEqual(DataArrayInt([])))
13024         a=DataArrayInt([])
13025         a.iota();
13026         self.assertTrue(a.isEqual(DataArrayInt([])))
13027         pass
13028
13029     def testSwig21SGTUMesh1(self):
13030         m=MEDCoupling1GTUMesh.New("m",NORM_PENTA6)
13031         m.__repr__() ; m.__str__()
13032         self.assertTrue(isinstance(m,MEDCoupling1SGTUMesh))
13033         m.setCoords(DataArrayDouble(20,3))
13034         m.allocateCells()
13035         m.__repr__() ; m.__str__()
13036         m.insertNextCell([0,1,2,5,7,2])
13037         self.assertEqual(1,m.getNumberOfCells())
13038         self.assertTrue(DataArrayInt([6]).isEqual(m.computeNbOfNodesPerCell()))
13039         self.assertTrue(DataArrayInt([5]).isEqual(m.computeNbOfFacesPerCell()))
13040         m.__repr__() ; m.__str__()
13041         m.checkCoherency()
13042         m.checkCoherency2()
13043         #
13044         cm=MEDCouplingCMesh() ; cm.setName("m")
13045         arr0=DataArrayDouble(6) ; arr0.iota()
13046         arr1=DataArrayDouble([0,1])
13047         cm.setCoords(arr0,arr1,arr1) ; um=cm.buildUnstructured()
13048         #
13049         m=MEDCoupling1SGTUMesh("m",NORM_QUAD4)
13050         mem_m=m.getHeapMemorySize()
13051         m.allocateCells(5)
13052         self.assertIn(m.getHeapMemorySize()-mem_m,xrange(5*4*4,5*4*4+32))
13053         self.assertEqual(m.getNodalConnectivity().getNbOfElemAllocated(),20)
13054         m.setCoords(um.getCoords())
13055         m.insertNextCell([1,0,6,7])
13056         self.assertEqual(1,m.getNumberOfCells())
13057         m.insertNextCell([2,1,7,8])
13058         m.insertNextCell([3,2,8,9])
13059         m.insertNextCell([4,3,9,10])
13060         m.insertNextCell([5,4,10,11])
13061         self.assertEqual(5,m.getNumberOfCells())
13062         self.assertRaises(InterpKernelException,m.insertNextCell,[0,6,7])
13063         self.assertRaises(InterpKernelException,m.insertNextCell,[0,6,7,1,2])
13064         self.assertEqual(m.getNodalConnectivity().getNbOfElemAllocated(),20)
13065         f=m.getMeasureField(ON_CELLS)
13066         self.assertEqual(f.getMesh().getHiddenCppPointer(),m.getHiddenCppPointer())
13067         self.assertTrue(f.getArray().isUniform(1,1e-14))
13068         self.assertEqual(m.getType(),10)
13069         self.assertEqual(m.getCellModelEnum(),NORM_QUAD4)
13070         mo=MEDCoupling1SGTUMesh("m",NORM_QUAD4) ; mo.setCoords(m.getCoords())
13071         mo.setNodalConnectivity(DataArrayInt([1,0,6,7,2,1,7,8,3,2,8,9,4,3,9,10,5,4,10,11]))
13072         self.assertTrue(m.isEqual(mo,1e-12))
13073         #
13074         mo2=MEDCoupling1SGTUMesh.Merge1SGTUMeshesOnSameCoords([m[[0,1]],m[[2]],m[[3,4]]])
13075         mo2.setName(m.getName())
13076         self.assertTrue(m.isEqual(mo2,1e-12))
13077         #
13078         mp0=m[[0]] ; mp0.zipCoords() ; mp1=m[2] ; mp1.zipCoords() ; mp2=m[4] ; mp2.zipCoords()
13079         mo3=MEDCoupling1SGTUMesh.Merge1SGTUMeshes([mp0,mp1,mp2])
13080         self.assertTrue(isinstance(mo3,MEDCoupling1SGTUMesh))
13081         mo3.setName(m.getName())
13082         m_ref=m[(0,2,4)] ; m_ref.zipCoords()
13083         m_ref.tryToShareSameCoordsPermute(mo3,1e-12)
13084         self.assertTrue(m_ref.isEqual(mo3,1e-12))
13085         #
13086         m1=um.buildDescendingConnectivity()[0]
13087         ids=m1.getCellIdsFullyIncludedInNodeIds(DataArrayInt.Range(0,12,1))
13088         m1=m1[ids]
13089         m1c=m1.convertIntoSingleGeoTypeMesh()
13090         self.assertTrue(isinstance(m1c,MEDCoupling1SGTUMesh))
13091         self.assertEqual(m1c.getCoords().getHiddenCppPointer(),m.getCoords().getHiddenCppPointer())
13092         m1c.checkCoherency2()
13093         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])))
13094         self.assertEqual(20,m1c.getNodalConnectivityLength())
13095         self.assertTrue(m.isEqual(m1c,1e-12))
13096         m.getNodalConnectivity().setIJ(1,0,1)
13097         self.assertTrue(not m.isEqual(m1c,1e-12))
13098         m.getNodalConnectivity().setIJ(1,0,0)
13099         self.assertTrue(m.isEqual(m1c,1e-12))
13100         m1c.setCoords(m.getCoords().deepCpy())
13101         self.assertTrue(m.isEqual(m1c,1e-12))
13102         m1c.getCoords().setIJ(0,1,0.1)
13103         self.assertTrue(not m.isEqual(m1c,1e-12))
13104         m1c.getCoords().setIJ(0,1,0)
13105         self.assertTrue(m.isEqual(m1c,1e-12))
13106         m1c.getCoords().setInfoOnComponent(1,"X")
13107         self.assertTrue(not m.isEqual(m1c,1e-12) and m.isEqualWithoutConsideringStr(m1c,1e-12))
13108         m.getCoords().setInfoOnComponent(1,"X")
13109         self.assertTrue(m.isEqual(m1c,1e-12) and m.isEqualWithoutConsideringStr(m1c,1e-12))
13110         m.setName("m2")
13111         self.assertTrue(not m.isEqual(m1c,1e-12) and m.isEqualWithoutConsideringStr(m1c,1e-12))
13112         #
13113         m.checkCoherency() ; m.checkCoherency1() ; m.checkCoherency2()
13114         self.assertEqual(m.getMeshDimension(),2)
13115         self.assertTrue(m.giveCellsWithType(NORM_QUAD4).isEqual(DataArrayInt([0,1,2,3,4])))
13116         self.assertTrue(m.giveCellsWithType(NORM_TRI3).isEqual(DataArrayInt([])))
13117         self.assertEqual(m.getNumberOfCellsWithType(NORM_QUAD4),5)
13118         self.assertEqual(m.getNumberOfCellsWithType(NORM_TRI3),0)
13119         self.assertEqual(m.getTypeOfCell(3),NORM_QUAD4)
13120         self.assertRaises(InterpKernelException,m.getTypeOfCell,5)
13121         self.assertEqual(m.getAllGeoTypes(),[NORM_QUAD4])
13122         self.assertEqual(m.getDistributionOfTypes(),[[NORM_QUAD4,5,-1]])
13123         ##
13124         pfl1=DataArrayInt([1,3,4])
13125         a,b,c=m.splitProfilePerType(pfl1)
13126         d,e,f=m.buildUnstructured().splitProfilePerType(pfl1)
13127         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())
13128         self.assertTrue(a==d and len(b)==1 and b[0].isEqual(e[0]) and len(c)==1 and c[0].isEqual(f[0]))
13129         #
13130         pfl2=DataArrayInt([0,1,2,3])
13131         a,b,c=m.splitProfilePerType(pfl2)
13132         d,e,f=m.buildUnstructured().splitProfilePerType(pfl2)
13133         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())
13134         self.assertTrue(a==d and len(b)==1 and b[0].isEqual(e[0]) and len(c)==1 and c[0].isEqual(f[0]))
13135         #
13136         pfl3=DataArrayInt([0,1,2,3,4])
13137         a,b,c=m.splitProfilePerType(pfl3)
13138         d,e,f=m.buildUnstructured().splitProfilePerType(pfl3)
13139         self.assertTrue(a==[[4,5,-1]] and len(b)==1 and b[0].isEqual(DataArrayInt([0,1,2,3,4])) and c==[])
13140         self.assertTrue(a==d and len(b)==1 and b[0].isEqual(e[0]) and c==[])
13141         #
13142         invalidPfl=DataArrayInt([1,2,3,4,5])
13143         self.assertRaises(InterpKernelException,m.splitProfilePerType,invalidPfl)
13144         self.assertRaises(InterpKernelException,m.buildUnstructured().splitProfilePerType,invalidPfl)
13145         ##
13146         pfl1=DataArrayInt([1,2,3])
13147         a=m.checkTypeConsistencyAndContig([NORM_QUAD4,3,0],[pfl1])
13148         b=m.buildUnstructured().checkTypeConsistencyAndContig([NORM_QUAD4,3,0],[pfl1])
13149         self.assertTrue(a.isEqual(b) and pfl1.getHiddenCppPointer(),a.getHiddenCppPointer())
13150         #
13151         pfl2=DataArrayInt([0,1,2,3])
13152         a=m.checkTypeConsistencyAndContig([NORM_QUAD4,4,0],[pfl2])
13153         b=m.buildUnstructured().checkTypeConsistencyAndContig([NORM_QUAD4,4,0],[pfl2])
13154         self.assertTrue(a.isEqual(b) and pfl2.getHiddenCppPointer()==a.getHiddenCppPointer())
13155         #
13156         pfl3=DataArrayInt([0,1,2,3,4])
13157         a=m.checkTypeConsistencyAndContig([NORM_QUAD4,4,0],[pfl3])
13158         b=m.buildUnstructured().checkTypeConsistencyAndContig([NORM_QUAD4,5,0],[pfl3])
13159         self.assertTrue(a.isEqual(b) and pfl3.getHiddenCppPointer()==a.getHiddenCppPointer())
13160         #
13161         invalidPfl=DataArrayInt([1,2,3,4,5])
13162         self.assertRaises(InterpKernelException,m.checkTypeConsistencyAndContig,[NORM_QUAD4,5,0],[invalidPfl])
13163         self.assertRaises(InterpKernelException,m.buildUnstructured().checkTypeConsistencyAndContig,[NORM_QUAD4,5,0],[invalidPfl])
13164         ##
13165         self.assertTrue(DataArrayInt([4,4,4,4,4]).isEqual(m.computeNbOfNodesPerCell()))
13166         ##
13167         self.assertEqual(m.getNodeIdsOfCell(1),[2,1,7,8])
13168         ##
13169         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))
13170         ##
13171         ref=m.getCoords().getHiddenCppPointer()
13172         mcpy=m.deepCpy() ; mcpy.insertNextCell([1,0,6,7])
13173         c=m.getNodalConnectivity().deepCpy()
13174         o2n=DataArrayInt([2,0,1,4,3])
13175         m.renumberCells(o2n,False)
13176         c.rearrange(4) ; c.renumberInPlace(o2n) ; c.rearrange(1)
13177         self.assertTrue(c.isEqual(m.getNodalConnectivity()))
13178         self.assertEqual(ref,m.getCoords().getHiddenCppPointer())
13179         m2=mcpy.mergeMyselfWith(m)
13180         self.assertTrue(isinstance(m2,MEDCoupling1SGTUMesh))
13181         self.assertEqual(11,m2.getNumberOfCells())
13182         self.assertEqual(48,m2.getNumberOfNodes())
13183         self.assertTrue(m2.getCoords().isEqual(DataArrayDouble.Aggregate([m.getCoords(),m.getCoords()]),1e-12))
13184         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])))
13185         ##
13186         mu=m.buildUnstructured()
13187         mu.checkCoherency2()
13188         self.assertEqual(mu.getCoords().getHiddenCppPointer(),m.getCoords().getHiddenCppPointer())
13189         self.assertEqual(2,mu.getMeshDimension())
13190         self.assertEqual([NORM_QUAD4],mu.getAllGeoTypes())
13191         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])))
13192         self.assertTrue(mu.getNodalConnectivityIndex().isEqual(DataArrayInt([0,5,10,15,20,25])))
13193         ##
13194         for typ in [0,1]:
13195             mcpy2=m.deepCpy() ; umcpy2=mcpy2.buildUnstructured()
13196             ids=mcpy2.simplexize(typ) ; ids2=umcpy2.simplexize(typ)
13197             self.assertTrue(ids.isEqual(ids2))
13198             mcpy3=umcpy2.convertIntoSingleGeoTypeMesh()
13199             self.assertTrue(mcpy2.isEqual(mcpy3,1e-14))
13200             pass
13201         um1=um.convertIntoSingleGeoTypeMesh()
13202         self.assertEqual(8,um1.getNumberOfNodesPerCell())
13203         for typ in [PLANAR_FACE_5,PLANAR_FACE_6]:
13204             mcpy2=um1.deepCpy() ; umcpy2=mcpy2.buildUnstructured()
13205             ids=mcpy2.simplexize(typ) ; ids2=umcpy2.simplexize(typ)
13206             self.assertTrue(ids.isEqual(ids2))
13207             mcpy3=umcpy2.convertIntoSingleGeoTypeMesh()
13208             self.assertTrue(mcpy2.isEqual(mcpy3,1e-14))
13209             pass
13210         ##
13211         self.assertRaises(InterpKernelException,mcpy.mergeMyselfWithOnSameCoords,m)
13212         mcpy.tryToShareSameCoords(m,1e-14)
13213         m3=mcpy.mergeMyselfWithOnSameCoords(m)
13214         self.assertTrue(isinstance(m3,MEDCoupling1SGTUMesh))
13215         self.assertEqual(11,m3.getNumberOfCells())
13216         self.assertEqual(24,m3.getNumberOfNodes())
13217         self.assertEqual(m3.getCoords().getHiddenCppPointer(),mcpy.getCoords().getHiddenCppPointer())
13218         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])))
13219         ##
13220         ref=mcpy.getCoords().deepCpy()
13221         c3=mcpy.getNodalConnectivity()[:]
13222         mcpy.getNodalConnectivity().setIJ(int(c3.getIdsEqual(11)),0,24)
13223         c2=DataArrayDouble.Aggregate([mcpy.getCoords(),mcpy.getCoords()[11:]])
13224         mcpy.setCoords(c2)
13225         mcpy.checkCoherency2()
13226         a,b=mcpy.getNodeIdsInUse()
13227         self.assertEqual(12,b)
13228         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])))
13229         ids=mcpy.zipCoordsTraducer()
13230         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])))
13231         self.assertTrue(mcpy.getCoords().isEqual(ref[:12],1e-12))
13232         self.assertTrue(mcpy.getNodalConnectivity().isEqual(c3))
13233         mcpy.checkCoherency2()
13234         ##
13235         m4=mcpy[DataArrayInt([0,3,4])]
13236         m5=mcpy.buildPartOfMySelfKeepCoords(DataArrayInt([0,3,4]))
13237         self.assertTrue(isinstance(m4,MEDCoupling1SGTUMesh))
13238         self.assertTrue(m4.isEqual(m5,-1e-14))# < 0 not a bug it proves that coordinates pointer are equal
13239         self.assertTrue(m4.getNodalConnectivity().isEqual(DataArrayInt([1,0,6,7,4,3,9,10,5,4,10,11])))
13240         m6=mcpy[::2]
13241         self.assertTrue(isinstance(m6,MEDCoupling1SGTUMesh))
13242         self.assertTrue(m6.getNodalConnectivity().isEqual(DataArrayInt([1,0,6,7,3,2,8,9,5,4,10,11])))
13243         ##
13244         mcpy.setCoords(DataArrayDouble.Aggregate([mcpy.getCoords(),mcpy.getCoords()]))
13245         mcpy.checkCoherency2()
13246         ##
13247         mcppy=mcpy.deepCpyConnectivityOnly()
13248         self.assertTrue(mcppy.isEqual(mcpy,1e-12))
13249         self.assertTrue(mcppy.getCoords().getHiddenCppPointer()==mcpy.getCoords().getHiddenCppPointer())
13250         self.assertTrue(mcppy.getNodalConnectivity().isEqual(mcpy.getNodalConnectivity()))
13251         self.assertTrue(mcppy.getNodalConnectivity().getHiddenCppPointer()!=mcpy.getNodalConnectivity().getHiddenCppPointer())
13252         ##
13253         a,b=mcpy.getReverseNodalConnectivity()
13254         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])))
13255         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])))
13256         self.assertTrue(mcpy.fillCellIdsToKeepFromNodeIds([0,1,6,7],False).isEqual(DataArrayInt([0,1,5])))
13257         self.assertTrue(mcpy.fillCellIdsToKeepFromNodeIds([0,1,6,7],True).isEqual(DataArrayInt([0,5])))
13258         self.assertTrue(mcpy.getCellsInBoundingBox([(0,1),(0,1),(0,1)],1e-12).isEqual(DataArrayInt([0,1,5])))
13259         f=mcpy.buildOrthogonalField()
13260         self.assertEqual(f.getMesh().getHiddenCppPointer(),mcpy.getHiddenCppPointer())
13261         self.assertTrue(f.getArray().isEqual(DataArrayDouble(6*[(0,0,-1)]),1e-12))
13262         mcpy.changeSpaceDimension(2)
13263         self.assertEqual(1,mcpy.getCellContainingPoint([1.5,0.5],1e-12))
13264         ##
13265         self.assertTrue(mcpy.fillCellIdsToKeepFromNodeIds(DataArrayInt([6,7]),False).isEqual(DataArrayInt([0,1,5])))
13266         ##
13267         mcpy2=mcpy.deepCpy()
13268         self.assertEqual([None,None],mcpy.checkGeoEquivalWith(mcpy2,1,1e-12))#fast equal
13269         mcpy.checkFastEquivalWith(mcpy2,1e-12)
13270         mcpy2.renumberCells([0,2,4,3,1,5])
13271         mcpy.checkFastEquivalWith(mcpy2,1e-12)
13272         self.assertEqual([None,None],mcpy.checkGeoEquivalWith(mcpy2,1,1e-12))#fast equal
13273         mcpy2.renumberCells([0,2,4,3,1,5])
13274         mcpy2.renumberCells([1,3,5,0,2,4])
13275         self.assertRaises(InterpKernelException,mcpy.checkFastEquivalWith,mcpy2,1e-12)
13276         self.assertRaises(InterpKernelException,mcpy.checkGeoEquivalWith,mcpy2,1,1e-12)#fast equal
13277         pass
13278
13279     def testSwig21DGTUMesh1(self):
13280         a0=DataArrayInt([0,2,3,5,6,8])
13281         a1=DataArrayInt([0,4,7,11,14,18,21,25])
13282         a2=DataArrayInt([0,1,4,5])
13283         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])))
13284         self.assertEqual(a1[3:].front(),11)
13285         self.assertEqual(a1[4:].convertToDblArr().front(),14.)
13286         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])
13287         d,e=MEDCouplingUMesh.ExtractFromIndexedArrays2(1,5,2,a1c,a1)
13288         self.assertTrue(d.isEqual(DataArrayInt([8,11,0,1,5,2])))
13289         self.assertTrue(e.isEqual(DataArrayInt([0,3,6])))
13290         #
13291         m=MEDCouplingDataForTest.build2DTargetMesh_1()[0,3,4]
13292         ref=DataArrayInt([0,3,4,1,6,7,4,3,7,8,5,4])
13293         self.assertTrue(m.convertNodalConnectivityToStaticGeoTypeMesh().isEqual(ref))
13294         d,e=m.convertNodalConnectivityToDynamicGeoTypeMesh()
13295         self.assertTrue(d.isEqual(ref))
13296         self.assertTrue(e.isEqual(DataArrayInt.Range(0,13,4)))
13297         self.assertTrue(m.fillCellIdsToKeepFromNodeIds(DataArrayInt([6,7]),False).isEqual(DataArrayInt([1,2])))
13298         #
13299         m=MEDCoupling1GTUMesh.New("m",NORM_POLYHED)
13300         self.assertTrue(isinstance(m,MEDCoupling1DGTUMesh))
13301         m.__repr__() ; m.__str__()
13302         m.setCoords(DataArrayDouble(20,3))
13303         m.allocateCells()
13304         m.__repr__() ; m.__str__()
13305         m.insertNextCell([0,1,2,5,7,2,-1,1,3])
13306         self.assertEqual(1,m.getNumberOfCells())
13307         self.assertTrue(DataArrayInt([8]).isEqual(m.computeNbOfNodesPerCell()))
13308         self.assertTrue(DataArrayInt([2]).isEqual(m.computeNbOfFacesPerCell()))
13309         m.__repr__() ; m.__str__()
13310         m.checkCoherency()
13311         m.checkCoherency2()
13312         #
13313         cm=MEDCouplingCMesh() ; cm.setName("m")
13314         arr0=DataArrayDouble(6) ; arr0.iota()
13315         arr1=DataArrayDouble([0,1])
13316         cm.setCoords(arr0,arr1,arr1) ; um=cm.buildUnstructured() ; um.convertAllToPoly()
13317         um2=um.deepCpyConnectivityOnly()
13318         self.assertTrue(um2.isEqual(um,1e-12))
13319         self.assertEqual(um2.getCoords().getHiddenCppPointer(),um.getCoords().getHiddenCppPointer())
13320         self.assertTrue(um2.getNodalConnectivity().isEqual(um.getNodalConnectivity()))
13321         self.assertTrue(um2.getNodalConnectivity().getHiddenCppPointer()!=um.getNodalConnectivity().getHiddenCppPointer())
13322         self.assertTrue(um2.getNodalConnectivityIndex().isEqual(um.getNodalConnectivityIndex()))
13323         self.assertTrue(um2.getNodalConnectivityIndex().getHiddenCppPointer()!=um.getNodalConnectivityIndex().getHiddenCppPointer())
13324         #
13325         self.assertRaises(InterpKernelException,MEDCoupling1SGTUMesh.New,"m",NORM_POLYHED)
13326         m=MEDCoupling1DGTUMesh("m",NORM_POLYHED)
13327         m.allocateCells(5)
13328         self.assertEqual(15,m.getNodalConnectivity().getNbOfElemAllocated())
13329         self.assertEqual(6,m.getNodalConnectivityIndex().getNbOfElemAllocated())
13330         m.setCoords(um.getCoords())
13331         m.insertNextCell([1,0,6,7,-1,7,6,1])
13332         self.assertEqual(1,m.getNumberOfCells())
13333         m.insertNextCell([2,1,7,8,-1,2,1,-1,8,-1,7])
13334         m.insertNextCell([3,2,8,9])
13335         m.insertNextCell([4,3,9,10,-1,5,3,9])
13336         m.insertNextCell([5,4,10,11,-1,11,10,-1,5])
13337         m.checkCoherency()
13338         m.checkCoherency2()
13339         self.assertEqual(5,m.getNumberOfCells())
13340         self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,8,19,23,31,40])))
13341         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])))
13342         #
13343         m4=m.deepCpy()
13344         self.assertTrue(m.isEqual(m4,1e-12))
13345         m4.getNodalConnectivity().setIJ(2,0,5)
13346         self.assertTrue(not m.isEqual(m4,1e-12))
13347         m4.getNodalConnectivity().setIJ(2,0,6)
13348         self.assertTrue(m.isEqual(m4,1e-12))
13349         m4.getNodalConnectivityIndex().setIJ(2,0,21)
13350         self.assertTrue(not m.isEqual(m4,1e-12))
13351         m4.getNodalConnectivityIndex().setIJ(2,0,19)
13352         self.assertTrue(m.isEqual(m4,1e-12))
13353         m4.getCoords().setIJ(10,1,1.1)
13354         self.assertTrue(not m.isEqual(m4,1e-12))
13355         m4.getCoords().setIJ(10,1,1.)
13356         self.assertTrue(m.isEqual(m4,1e-12))
13357         m4.getNodalConnectivity().pushBackSilent(7)
13358         self.assertTrue(not m.isEqual(m4,1e-12))
13359         self.assertEqual(7,m4.getNodalConnectivity().popBackSilent())
13360         self.assertTrue(m.isEqual(m4,1e-12))
13361         m4.setName("m4")
13362         self.assertTrue(not m.isEqual(m4,1e-12))
13363         m4.setName("m")
13364         self.assertTrue(m.isEqual(m4,1e-12))
13365         #
13366         self.assertEqual(6,m.getNodalConnectivityIndex().getNbOfElemAllocated())
13367         self.assertEqual(60,m.getNodalConnectivity().getNbOfElemAllocated())
13368         self.assertTrue(m.computeNbOfNodesPerCell().isEqual(DataArrayInt([7,8,4,7,7])))
13369         self.assertTrue(m.computeNbOfFacesPerCell().isEqual(DataArrayInt([2,4,1,2,3])))
13370         self.assertEqual(m.getNodeIdsOfCell(1),[2,1,7,8,-1,2,1,-1,8,-1,7])
13371         f=m.computeIsoBarycenterOfNodesPerCell()
13372         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))
13373         mu0=m.buildUnstructured()
13374         o2n=[1,2,0,4,3]
13375         m2=m.deepCpy()
13376         m3=m.deepCpyConnectivityOnly()
13377         self.assertTrue(m3.isEqual(m,1e-12))
13378         self.assertEqual(m3.getCoords().getHiddenCppPointer(),m.getCoords().getHiddenCppPointer())
13379         self.assertTrue(m3.getNodalConnectivity().getHiddenCppPointer()!=m.getNodalConnectivity().getHiddenCppPointer())
13380         self.assertTrue(m3.getNodalConnectivity().isEqual(m.getNodalConnectivity()))
13381         self.assertTrue(m3.getNodalConnectivityIndex().getHiddenCppPointer()!=m.getNodalConnectivityIndex().getHiddenCppPointer())
13382         self.assertTrue(m3.getNodalConnectivityIndex().isEqual(m.getNodalConnectivityIndex()))
13383         m.renumberCells(o2n)
13384         mu0.renumberCells(o2n)
13385         self.assertTrue(mu0.isEqual(m.buildUnstructured(),1e-12))
13386         self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,12,23,32,40])))
13387         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])))
13388         #
13389         mcpy0=m.buildUnstructured()
13390         self.assertTrue(isinstance(mcpy0,MEDCouplingUMesh))
13391         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])))
13392         self.assertTrue(mcpy0.getNodalConnectivityIndex().isEqual(DataArrayInt([0,5,14,26,36,45])))
13393         self.assertEqual(mcpy0.getAllGeoTypes(),[NORM_POLYHED])
13394         mcpy0.checkCoherency()
13395         mcpy0.checkCoherency2()
13396         mcpy1=mcpy0.convertIntoSingleGeoTypeMesh()
13397         self.assertTrue(mcpy1.isEqual(m,1e-12))
13398         #
13399         m_mrg=MEDCoupling1DGTUMesh.Merge1DGTUMeshes([m2,m,m2])
13400         self.assertTrue(m_mrg.getNodalConnectivityIndex().isEqual(DataArrayInt([0,8,19,23,31,40,44,52,63,72,80,88,99,103,111,120])))
13401         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])))
13402         m_mrg2=MEDCoupling1DGTUMesh.Merge1DGTUMeshesOnSameCoords([m3,m,m3])
13403         self.assertTrue(m_mrg2.getNodalConnectivityIndex().isEqual(DataArrayInt([0,8,19,23,31,40,44,52,63,72,80,88,99,103,111,120])))
13404         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])))
13405         a,b=m_mrg2.getReverseNodalConnectivity()
13406         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])))
13407         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])))
13408         self.assertTrue(m_mrg2.fillCellIdsToKeepFromNodeIds([7],False).isEqual(DataArrayInt([0,1,6,7,10,11])))
13409         self.assertTrue(m_mrg2.fillCellIdsToKeepFromNodeIds([0,1,6,7],True).isEqual(DataArrayInt([0,6,10])))
13410         #
13411         self.assertTrue(m_mrg2.isPacked())
13412         self.assertEqual(120,m_mrg2.getNodalConnectivityIndex().popBackSilent())
13413         self.assertEqual(m_mrg2.getNumberOfCells(),14)
13414         m_mrg2.checkCoherency2()
13415         self.assertTrue(not m_mrg2.isPacked())
13416         m_mrg4,b=m_mrg2.copyWithNodalConnectivityPacked()
13417         self.assertTrue(not b)
13418         m_mrg4.checkCoherency2()
13419         self.assertEqual(m_mrg4.getNumberOfCells(),14)
13420         self.assertTrue(m_mrg4.getNodalConnectivityIndex().isEqual(m_mrg2.getNodalConnectivityIndex()))
13421         self.assertEqual(len(m_mrg4.getNodalConnectivity()),111)
13422         self.assertEqual(len(m_mrg2.getNodalConnectivity()),120)
13423         self.assertTrue(m_mrg4.getNodalConnectivity().isEqual(m_mrg2.getNodalConnectivity()[:111]))
13424         #
13425         m0=m_mrg2[:5]
13426         m1=m_mrg2[[5,6,7,8,9]]
13427         m2=m_mrg2[10:]
13428         self.assertTrue(m1.isEqualWithoutConsideringStr(m,1e-12))
13429         a,b=m.checkGeoEquivalWith(m0,12,1e-12)
13430         self.assertTrue(a.isEqual(DataArrayInt(o2n)))
13431         self.assertTrue(b is None)
13432         pass
13433
13434     def testSwig2DADAreIncludedInMe1(self):
13435         a=DataArrayDouble(30) ; a.iota() ; a.rearrange(3)
13436         p=DataArrayInt([5,2,1,9])
13437         b,c=a.areIncludedInMe(a[p],1e-12)
13438         self.assertTrue(b)
13439         self.assertTrue(c.isEqual(p))
13440         d=a[p]
13441         d.setIJ(3,1,28.1)
13442         b,c=a.areIncludedInMe(d,1e-12)
13443         self.assertTrue(not b)
13444         self.assertTrue(c.isEqual(DataArrayInt([5,2,1,10])))
13445         pass
13446
13447     def testSwig2DADesallocate1(self):
13448         d=DataArrayDouble([(1,2),(6,7),(6,8)]) ; d.setInfoOnComponents(["aa","bbb"])
13449         self.assertTrue(d.isAllocated())
13450         d.checkAllocated()
13451         self.assertEqual(d.getInfoOnComponents(),["aa","bbb"])
13452         ref=d.getHeapMemorySize()
13453         d.desallocate()
13454         self.assertEqual(ref-d.getHeapMemorySize(),6*8)
13455         self.assertTrue(not d.isAllocated())
13456         self.assertEqual(d.getInfoOnComponents(),["aa","bbb"])
13457         self.assertRaises(InterpKernelException,d.checkAllocated)
13458         #
13459         d=DataArrayInt([(1,2),(6,7),(6,8)]) ; d.setInfoOnComponents(["aa","bbb"])
13460         self.assertTrue(d.isAllocated())
13461         d.checkAllocated()
13462         self.assertEqual(d.getInfoOnComponents(),["aa","bbb"])
13463         ref=d.getHeapMemorySize()
13464         d.desallocate()
13465         self.assertEqual(ref-d.getHeapMemorySize(),6*4)
13466         self.assertTrue(not d.isAllocated())
13467         self.assertEqual(d.getInfoOnComponents(),["aa","bbb"])
13468         self.assertRaises(InterpKernelException,d.checkAllocated)
13469         pass
13470
13471     def testSwig2IsPartStructured1(self):
13472         #dim 1
13473         d10=DataArrayInt([2,3,4,5,6,7,8,9,10,11])
13474         a,b=MEDCouplingStructuredMesh.IsPartStructured(d10,[13])
13475         self.assertTrue(a) ; self.assertEqual(b,[(2,12)])
13476         d11=DataArrayInt([2,3,4,5,6,7,8,10,9,11])
13477         a,b=MEDCouplingStructuredMesh.IsPartStructured(d11,[13])
13478         self.assertTrue(not a)
13479         self.assertRaises(InterpKernelException,MEDCouplingStructuredMesh.IsPartStructured,d10,[11])
13480         #dim 2
13481         st=[10,4]
13482         d20=DataArrayInt([1,2,3,4,11,12,13,14,21,22,23,24])
13483         a,b=MEDCouplingStructuredMesh.IsPartStructured(d20,st)
13484         self.assertTrue(a) ; self.assertEqual(b,[(1,5),(0,3)])
13485         d20=DataArrayInt([1,2,3,4,12,11,13,14,21,22,23,24])
13486         a,b=MEDCouplingStructuredMesh.IsPartStructured(d20,st)
13487         self.assertTrue(not a)
13488         d20=DataArrayInt([1,2,3,4,11,12,13,15,21,22,23,24])
13489         a,b=MEDCouplingStructuredMesh.IsPartStructured(d20,st)
13490         self.assertTrue(not a)
13491         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])
13492         a,b=MEDCouplingStructuredMesh.IsPartStructured(d21,st)
13493         self.assertTrue(a) ; self.assertEqual(b,[(0,10),(0,4)])
13494         d22=DataArrayInt([1,2,3,4,11,12,13,14,21,22,23,24,31,32,33,34,41,42,43,44])
13495         self.assertRaises(InterpKernelException,MEDCouplingStructuredMesh.IsPartStructured,d22,st)
13496         a,b=MEDCouplingStructuredMesh.IsPartStructured(d22,[10,5])
13497         self.assertTrue(a) ; self.assertEqual(b,[(1,5),(0,5)])
13498         #dim 3
13499         d30=DataArrayInt([11,12,13,14,21,22,23,24,51,52,53,54,61,62,63,64])
13500         a,b=MEDCouplingStructuredMesh.IsPartStructured(d30,[10,4,2])
13501         self.assertTrue(a) ; self.assertEqual(b,[(1,5),(1,3),(0,2)])
13502         d31=DataArrayInt([11,12,13,14,21,22,24,23,51,52,53,54,61,62,63,64])
13503         a,b=MEDCouplingStructuredMesh.IsPartStructured(d31,[10,4,2])
13504         self.assertTrue(not a)
13505         self.assertRaises(InterpKernelException,MEDCouplingStructuredMesh.IsPartStructured,d30,[10,4,1])
13506         pass
13507
13508     def testSwig2PartStructured1(self):
13509         c=MEDCouplingCMesh() ; c.setName("toto")
13510         arr0=DataArrayDouble(10); arr0.iota()
13511         arr1=DataArrayDouble(4) ; arr1.iota(3)
13512         c.setCoords(arr0,arr1)
13513         self.assertEqual(c.getNodeGridStructure(),(10,4))
13514         self.assertEqual(c.getCellGridStructure(),(9,3))
13515         d20=DataArrayInt([1,2,3,4,10,11,12,13,19,20,21,22])
13516         self.assertEqual(27,c.getNumberOfCells())
13517         self.assertEqual(40,c.getNumberOfNodes())
13518         self.assertEqual(2,c.getMeshDimension())
13519         c.checkCoherency()
13520         #
13521         arr2=MEDCouplingStructuredMesh.BuildExplicitIdsFrom([9,3],[(1,5),(0,3)])
13522         self.assertTrue(arr2.isEqual(DataArrayInt([1,2,3,4,10,11,12,13,19,20,21,22])))
13523         # CMesh
13524         c2=c.buildStructuredSubPart([(1,5),(0,3)])
13525         c2.checkCoherency()
13526         self.assertTrue(isinstance(c2,MEDCouplingCMesh))
13527         self.assertEqual(12,c2.getNumberOfCells())
13528         self.assertEqual(20,c2.getNumberOfNodes())
13529         self.assertEqual(2,c2.getMeshDimension())
13530         self.assertEqual("toto",c2.getName())
13531         self.assertTrue(c2.getCoordsAt(0).isEqual(DataArrayDouble([1.,2.,3.,4.,5.]),1e-12))
13532         self.assertTrue(c2.getCoordsAt(1).isEqual(DataArrayDouble([3.,4.,5.,6.]),1e-12))
13533         #
13534         a,b=c.buildPartAndReduceNodes(d20)
13535         a.checkCoherency()
13536         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])
13537         self.assertTrue(exp2.isEqual(b))
13538         self.assertTrue(isinstance(a,MEDCouplingCMesh))
13539         self.assertTrue(a.buildUnstructured().isEqual(c.buildUnstructured().buildPartAndReduceNodes(d20)[0],1e-12))
13540         # CurveLinearMesh
13541         c2=MEDCouplingCurveLinearMesh() ; c2.setName("toto")
13542         c2.setCoords(c.buildUnstructured().getCoords())
13543         c2.setNodeGridStructure([10,4])
13544         c2.checkCoherency()
13545         a,b=c2.buildPartAndReduceNodes(d20)
13546         a.checkCoherency()
13547         self.assertTrue(exp2.isEqual(b))
13548         self.assertTrue(isinstance(a,MEDCouplingCurveLinearMesh))
13549         self.assertTrue(a.buildUnstructured().isEqual(c2.buildUnstructured().buildPartAndReduceNodes(d20)[0],1e-12))
13550         pass
13551
13552     def testSwig2FindPermutationFromFirstToSecond1(self):
13553         ids1=DataArrayInt([3,1,103,4,6,10,-7,205])
13554         ids2=DataArrayInt([-7,1,205,10,6,3,103,4])
13555         ids3=DataArrayInt.FindPermutationFromFirstToSecond(ids1,ids2)
13556         self.assertTrue(ids3.isEqual(DataArrayInt([5,1,6,7,4,3,0,2])))
13557         ids2ToTest=ids1.renumber(ids3)
13558         self.assertTrue(ids2ToTest.isEqual(ids2))
13559         self.assertRaises(InterpKernelException,DataArrayInt.FindPermutationFromFirstToSecond,DataArrayInt([3,1,103]),DataArrayInt([1,103]))
13560         self.assertRaises(InterpKernelException,DataArrayInt.FindPermutationFromFirstToSecond,DataArrayInt([3,1,103]),DataArrayInt([1,103,2]))
13561         self.assertRaises(InterpKernelException,DataArrayInt.FindPermutationFromFirstToSecond,DataArrayInt([3,1,103]),DataArrayInt([1,103,1]))
13562         self.assertTrue(DataArrayInt.FindPermutationFromFirstToSecond(DataArrayInt([]),DataArrayInt([])).empty())
13563         pass
13564
13565     def testSwig2BugStructuredMeshGetNodeIdsOfCell1(self):
13566         m=MEDCouplingCMesh("mesh")
13567         coordsX=DataArrayDouble([0,1.1,2.2,3.3,4.4]) ; coordsX.setInfoOnComponents(["XX [m]"])
13568         coordsY=DataArrayDouble([0,1.7,3.4]) ; coordsY.setInfoOnComponents(["YYY [km]"])
13569         m.setCoords(coordsX,coordsY)
13570         self.assertEqual([2,3,8,7],m.getNodeIdsOfCell(2))
13571         self.assertEqual([3,4,9,8],m.getNodeIdsOfCell(3))
13572         self.assertEqual([7,8,13,12],m.getNodeIdsOfCell(6))
13573         self.assertEqual([8,9,14,13],m.getNodeIdsOfCell(7))
13574         pass
13575
13576     def testSwig2ThrowOnDAIInvertN2O2ON2(self):
13577         p1=DataArrayInt([3,5,8])
13578         p2=DataArrayInt([0,3,4,5,6,7,8,9,10])
13579         p1.transformWithIndArr(p2.invertArrayN2O2O2N(11))
13580         self.assertTrue(p1.isEqual(DataArrayInt([1,3,6])))
13581         self.assertTrue(p2.invertArrayN2O2O2N(11).isEqual(DataArrayInt([0,-1,-1,1,2,3,4,5,6,7,8])))
13582         self.assertRaises(InterpKernelException,p2.invertArrayN2O2O2N,10)
13583         pass
13584
13585     def testSwig2ComputeEffectiveNbOfNodesPerCell1(self):
13586         coords=DataArrayDouble([ 0.241310763507 , 0.0504777305619 , 0.0682283524903 , 0.252501053866 , -0.0625176732937 , 0.137272639894 ,
13587                  0.152262663601 , 0.241816569527 , 0.133812556197 , 0.18047750211 , -0.0789949051358 , 0.339098173401 ,
13588                  0.151741971857 , 0.238885278571 , 0.137715037333 , 0.242532155481 , -0.0928169086456 , 0.0678043417367 ,
13589                  0.240941965335 , -0.015461491464 , 0.0617186345825 , 0.24127650112 , 0.0499427876717 , 0.0679634099148 ,
13590                  -0.145828917428 , 0.206291632565 , 0.0310071927543 , 0.0125651775307 , 0.266262085828 , 0.105228430543 ,
13591                  -0.0994066533286 , 0.233224271238 , 0.0572213839567 , -0.0951345338317 , 0.234819509426 , 0.0592126284538 ,
13592                  0.136580574205 , -0.205486212579 , 0.0572866072014 , 0.0637270784978 , -0.168886355238 , 0.446614057077 ,
13593                  0.041337157151 , -0.213402568198 , 0.372407095999 , 0.0411601970268 , -0.202387875756 , 0.411334979491 ,
13594                  -0.108355701857 , 0.193636239335 , 0.204886756738 , 0.00639779029829 , 0.155296981517 , 0.252585892979 ,
13595                  0.0262473111702 , -0.112919732543 , 0.424286639249 ,-0.224103052733 , -0.139430015438 , -0.0122352295701 ,
13596                 -0.0312760589481 , -0.274272003594 , 0.0323959636568 , -0.166663422532 , -0.217754445175 , 0.00392109070364 ,
13597                  -0.30586619777 , -0.0475168041091 , -0.0144585228182 , -0.280881480586 , 0.135571293538 , 0.00623923647986 ,
13598                  -0.25548538234 , 0.156819217766 , 0.0645277879769 , -0.131567009284 , 0.184133752309 , 0.206021802753 ,
13599                  -0.196204010965 , 0.151602971681 , 0.212974777736 , -0.183713879463 , 0.0802946639531 , 0.260115662599 ,
13600                  -0.244241178767 , -0.0738873389604 , 0.144590565817 , -0.155804057829 , -0.164892720025 , 0.210613950558 ,
13601                  -0.170950800428 , -0.215099334026 , 0.00610122860092 , -0.30552634869 , -0.0490020791904 , -0.0132786533145 ,
13602                  0.271831011884 , 0.15105657296 , 0.0230534827908 , 0.281919192283 , 0.0898544306288 , -0.0625201489143 ,
13603                  0.260240727276 , -0.0120688706637 , -0.0532316588626 , 0.244947737722 , 0.0197984684293 , 0.0309341209233 ,
13604                  0.23439631578 , 0.229825279875 , 0.0508520585381 , 0.160921316875 , 0.265078502128 , 0.121716560626 ,
13605                  -0.315088694175 , 0.0747700471918 , -0.245836615071 , -0.327728781776 , 0.0857114674649 , -0.239431905957 ,
13606                  -0.308385460634 , 0.145142997084 , -0.149886828433 , 0.0488236045164 , 0.309462801914 , 0.0849169148265 ,
13607                 -0.0244964803395 , 0.33145611751 , -0.0476415818061 , 0.0060567994229 , 0.32418412014 , 0.0367779543812 ,
13608                  -0.0950221448063 , 0.236675326003 , 0.0572594453983 , 0.248723023186 , 0.0886648784791 , -0.176629430538 ,
13609                  0.116796984 , 0.256596599567 , -0.292863523603 , 0.118024552914 , 0.229154257843 , -0.34233232501 ,
13610                  0.217507892549 , -0.0417822335742 , -0.176771782888 , -0.224429321304 , 0.0125595300114 , -0.362064725588 ,
13611                  0.0937301100955 , -0.0500824832657 , -0.299713548444 , -0.244162220397 , 0.0383853931293 , -0.389856984411 ,
13612                  -0.0281989366102 , 0.097392811563 , -0.458244577284 , -0.385010847162 , 0.10122766194 , -0.140052859922 ,
13613                  -0.377936358012 , 0.110875172128 , -0.176207095463 , 0.244483045556 , -0.0991073977045 , 0.0575134372934 ,
13614                 0.262605120167 , -0.100243191645 , -0.0495620806935 , 0.240306880972 , -0.136153701579 , -0.114745281696 ,
13615                  0.215763176129 , -0.0836766059189 , -0.183249640616 , 0.237870396603 , -0.132449578286 , -0.121598854639 ,
13616                  -0.0637683083097 , -0.27921020214 , -0.149112321992 , -0.0856211014977 , -0.2973233473 , -0.0446878139589 ,
13617                  0.104675342288 , -0.0625908305324 , -0.290346256534 , 0.0248264249186 , -0.247797708548 , -0.165830884019 ,
13618                  0.0719302438309 , -0.178468260473 , -0.211432157345 , 0.142871843159 , -0.208769948542 , 0.0454101128246 ,
13619                  0.167803379307 , -0.207851396623 , -0.088802726124 , 0.12868717152 , -0.230920439715 , 0.00760508389036 ,
13620                  -0.0372812069535 , -0.286740286332 , 0.00963701291166 ], 69, 3)
13621         connN = [ #polyhedron 0
13622             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
13623             , 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
13624             , 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
13625             , 22 , 19 , 21 , 30 , 31 , -1 , 22 , 31 , 28 , 27 , 26 , 24 , 23 , -1 , 31 , 30 , 29 , 28,
13626             # polyhedron 1
13627             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
13628             , 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
13629             , 33 , 34 , 48 , 45 , -1 , 35 , 34 , 48 , 50 , 49 , 38 , -1 , 41 , 43 , 42 , 46 , 36 , 37 , -1 , 38 , 39 , 51 , 49 , -1
13630             , 39 , 40 , 42 , 46 , 47 , 52 , 51 , -1 , 45 , 47 , 52 , 50 , 48 , -1 , 52 , 51 , 49 , 50,
13631             # polyhedron 2
13632             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
13633             , 23 , 53 , 54 , 40 , 8 , -1 , 53 , 22 , 23 , -1 , 39 , 54 , 40,
13634             # polyhedron 3
13635             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
13636             , 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
13637             , 55 , 5 , 12 , 65 , -1 , 66 , 67 , 65 , 55 , 56 , 57 , -1 , 63 , 66 , 57 , 59 , 64 , -1 , 64 , 62 , 58 , 59 , -1
13638             , 60 , 63 , 66 , 67 , 68 , 61 , -1 , 61 , 68 , 20 , 21 , -1 , 67 , 68 , 20 , 12 , 65]
13639         meshN=MEDCouplingUMesh.New()
13640         meshN.setName("ForBary")
13641         meshN.setMeshDimension(3) ; meshN.setCoords(coords)
13642         meshN.allocateCells(4)
13643         meshN.insertNextCell(NORM_POLYHED,113,connN);
13644         meshN.insertNextCell(NORM_POLYHED,99,connN[113:])
13645         meshN.insertNextCell(NORM_POLYHED,43,connN[212:])
13646         meshN.insertNextCell(NORM_POLYHED,92,connN[255:])
13647         d=meshN.computeEffectiveNbOfNodesPerCell()
13648         e=meshN.computeNbOfNodesPerCell()
13649         self.assertTrue(d.isEqual(DataArrayInt([32,28,12,26])))
13650         self.assertTrue(e.isEqual(DataArrayInt([96,84,36,78])))
13651         m0=MEDCoupling1DGTUMesh(meshN)
13652         c=MEDCouplingCMesh()
13653         arr=DataArrayDouble(3) ; arr.iota(10)
13654         c.setCoords(arr,arr,arr)
13655         m10=c.buildUnstructured()
13656         m11=c.build1SGTUnstructured()
13657         m12=MEDCoupling1SGTUMesh.New(m10)
13658         self.assertTrue(m12.isEqual(m11,1e-12))
13659         m12.setCoords(m0.getCoords()) # m12 is not OK geometrically but the aim of the test is only connectivity values
13660         m3=MEDCoupling1GTUMesh.AggregateOnSameCoordsToUMesh([m12,m0])
13661         m3.checkCoherency()
13662         self.assertEqual(m3.getCoords().getHiddenCppPointer(),m12.getCoords().getHiddenCppPointer())
13663         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])))
13664         self.assertTrue(m3.getNodalConnectivityIndex().isEqual(DataArrayInt([0,9,18,27,36,45,54,63,72,186,286,330,423])))
13665         pass
13666
13667     def testSwig2Tetrahedrize1(self):
13668         d=DataArrayInt([0,3,6,10,14,20])
13669         d2=d.buildExplicitArrOfSliceOnScaledArr(slice(0,5,2))
13670         self.assertTrue(d2.isEqual(DataArrayInt([0,0,0, 2,2,2,2, 4,4,4,4,4,4])))
13671         m=MEDCouplingUMesh("Penta6",3)
13672         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"])
13673         m.allocateCells()
13674         m.insertNextCell(NORM_PENTA6,[1,2,0,4,5,3])
13675         st=m.getCoords().getHiddenCppPointer()
13676         c,a,b=m.tetrahedrize(PLANAR_FACE_5)
13677         c.checkCoherency2()
13678         self.assertTrue(a.isEqual(DataArrayInt([0,0,0])))
13679         self.assertEqual(0,b)
13680         self.assertEqual(m.getCoords().getHiddenCppPointer(),c.getCoords().getHiddenCppPointer())
13681         self.assertTrue(c.getNodalConnectivity().isEqual(DataArrayInt([1,2,0,4,4,3,5,0,5,0,2,4])))
13682         del m,c
13683         #
13684         m2=MEDCouplingUMesh("octa12",3)
13685         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)
13686         m2.setCoords(coords)
13687         m2.allocateCells()
13688         m2.insertNextCell(NORM_HEXGP12,[3,2,1,0,5,4,9,8,7,6,11,10])
13689         c,a,b=m2.tetrahedrize(PLANAR_FACE_5)
13690         c.checkCoherency2()
13691         self.assertTrue(a.isEqual(DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0])))
13692         self.assertEqual(0,b)
13693         self.assertEqual(c.getCoords().getHiddenCppPointer(),coords.getHiddenCppPointer())
13694         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])))
13695         del m2,coords,c
13696         #
13697         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"])
13698         m3=MEDCouplingUMesh("hexa8",3)
13699         m3.setCoords(coords)
13700         m3.allocateCells(0)
13701         m3.insertNextCell(NORM_HEXA8,[3,2,1,0,7,6,5,4])
13702         st=m3.getCoords().getHiddenCppPointer()
13703         c,a,b=m3.tetrahedrize(PLANAR_FACE_5)
13704         c.checkCoherency2()
13705         a.isEqual(DataArrayInt([0,0,0,0,0]))
13706         self.assertEqual(0,b)
13707         self.assertEqual(m3.getCoords().getHiddenCppPointer(),coords.getHiddenCppPointer())
13708         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])))
13709         #
13710         m4=MEDCouplingUMesh("hexa8",3)
13711         m4.setCoords(coords)
13712         m4.allocateCells(0)
13713         m4.insertNextCell(NORM_HEXA8,[3,2,1,0,7,6,5,4])
13714         c,a,b=m4.tetrahedrize(PLANAR_FACE_6)
13715         c.checkCoherency2()
13716         a.isEqual(DataArrayInt([0,0,0,0,0,0]))
13717         self.assertEqual(0,b)
13718         self.assertEqual(c.getCoords().getHiddenCppPointer(),coords.getHiddenCppPointer())
13719         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])))
13720         #
13721         m4=MEDCouplingUMesh("hexa8",3)
13722         m4.setCoords(coords)
13723         m4.allocateCells(0)
13724         m4.insertNextCell(NORM_HEXA8,[3,2,1,0,7,6,5,4])
13725         st=m4.getCoords().getHiddenCppPointer()
13726         c,a,b=m4.tetrahedrize(GENERAL_24)
13727         c.checkCoherency2()
13728         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]))
13729         self.assertEqual(7,b)
13730         self.assertTrue(c.getCoords().getHiddenCppPointer()!=coords.getHiddenCppPointer())
13731         self.assertTrue(c.getCoords()[:8].isEqual(coords,0))
13732         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])))
13733         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)
13734         m4CoordsExp.setInfoOnComponents(["X","YY","ZZZ"])
13735         self.assertTrue(c.getCoords().isEqual(m4CoordsExp,1e-12))
13736         self.assertAlmostEqual(2.,c.getMeasureField(False).accumulate()[0],12)
13737         #
13738         m6=MEDCouplingUMesh("hexa8",3)
13739         m6.setCoords(coords)
13740         m6.allocateCells(0)
13741         m6.insertNextCell(NORM_HEXA8,[3,2,1,0,7,6,5,4])
13742         st=m6.getCoords().getHiddenCppPointer()
13743         c,a,b=m6.tetrahedrize(GENERAL_48)
13744         c.checkCoherency2()
13745         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]))
13746         self.assertEqual(19,b)
13747         self.assertTrue(c.getCoords().getHiddenCppPointer()!=coords.getHiddenCppPointer())
13748         self.assertTrue(c.getCoords()[:8].isEqual(coords,0))
13749         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])))
13750         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)
13751         m6CoordsExp.setInfoOnComponents(["X","YY","ZZZ"])
13752         self.assertTrue(c.getCoords().isEqual(m6CoordsExp,1e-12))
13753         self.assertAlmostEqual(2.,c.getMeasureField(False).accumulate()[0],12)
13754         #
13755         m7=MEDCouplingUMesh("polyhed",3)
13756         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"])
13757         m7.setCoords(coords)
13758         m7.allocateCells()
13759         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])
13760         c,a,b=m7.tetrahedrize(PLANAR_FACE_5)
13761         c.checkCoherency2()
13762         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])))
13763         self.assertEqual(9,b)
13764         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])))
13765         self.assertAlmostEqual(5.196152422706635,c.getMeasureField(False).accumulate()[0],12)
13766         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)
13767         m7CoordsExp.setInfoOnComponents(["X","YY","ZZZ"])
13768         self.assertTrue(c.getCoords().isEqual(m7CoordsExp,1e-12))
13769         del m7,coords,c
13770         #
13771         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"])
13772         m8=MEDCouplingUMesh("pyra5",3)
13773         m8.setCoords(coords)
13774         m8.allocateCells(0)
13775         m8.insertNextCell(NORM_PYRA5,[3,2,1,0,7])
13776         st=m8.getCoords().getHiddenCppPointer()
13777         c,a,b=m8.tetrahedrize(PLANAR_FACE_5)
13778         self.assertEqual(m8.getCoords().getHiddenCppPointer(),coords.getHiddenCppPointer())
13779         c.checkCoherency2()
13780         self.assertTrue(a.isEqual(DataArrayInt([0,0])))
13781         self.assertEqual(0,b)
13782         self.assertTrue(c.getNodalConnectivity().isEqual(DataArrayInt([3,2,1,7,3,1,0,7])))
13783         self.assertAlmostEqual(0.6666666666666667,c.getMeasureField(False).accumulate()[0],12)
13784         pass
13785
13786     def testDualMesh3D1(self):
13787         arr=DataArrayDouble(2) ; arr.iota()
13788         c=MEDCouplingCMesh() ; c.setCoords(arr,arr,arr)
13789         m=c.buildUnstructured()
13790         t=m.tetrahedrize(PLANAR_FACE_5)[0]
13791         d=t.computeDualMesh()
13792         self.assertTrue(d.getNodalConnectivityIndex().isEqual(DataArrayInt([0,29,118,207,236,325,354,383,472])))
13793         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])))
13794         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))
13795         self.assertAlmostEqual(1.,d.getMeasureField(False).accumulate()[0],1e-13)
13796         pass
13797
13798     def testDualMesh2D1(self):
13799         arr=DataArrayDouble(5) ; arr.iota()
13800         c=MEDCouplingCMesh() ; c.setCoords(arr,arr)
13801         m=c.buildUnstructured()
13802         m.simplexize(0)
13803         t=MEDCoupling1SGTUMesh(m)
13804         d=t.computeDualMesh()
13805         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])))
13806         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])))
13807         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))
13808         self.assertAlmostEqual(16.,d.getMeasureField(False).accumulate()[0],1e-13)
13809         pass
13810
13811     def testSwig2LoadBalanceBBox1(self):
13812         arr=DataArrayDouble(5) ; arr.iota()
13813         t=MEDCouplingCMesh() ; t.setCoords(arr,arr)
13814         arr=DataArrayDouble(16) ; arr.iota() ; arr*=2./15
13815         s=MEDCouplingCMesh() ; s.setCoords(arr,arr[:]) ; s.translate([2.,1.])
13816         #
13817         s1=s.build1SGTUnstructured()
13818         t1=t.build1SGTUnstructured()
13819         w=MEDCouplingPointSet.ComputeNbOfInteractionsWithSrcCells(s1,t1,1e-12)
13820         wExp=DataArrayInt([0,0,0,0,0,0,64,64,0,0,64,64,0,0,0,0])
13821         self.assertTrue(w.isEqual(wExp))
13822         slcs=w.splitInBalancedSlices(4)
13823         self.assertEqual(len(slcs),4)
13824         self.assertEqual(slcs,[slice(0,7,1),slice(7,8,1),slice(8,11,1),slice(11,16,1)])
13825         bbs=s1.getBoundingBoxForBBTree()
13826         bbt=t1.getBoundingBoxForBBTree()
13827         self.assertTrue(bbt.computeNbOfInteractionsWith(bbs,1e-12).isEqual(wExp))
13828         pass
13829
13830     def testKrSpatialDiscretization2(self):
13831         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)
13832         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)
13833         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)
13834         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])
13835         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])
13836         #
13837         nbOfInputPoints=100;
13838         f=MEDCouplingFieldDouble.New(ON_NODES_KR,ONE_TIME);
13839         mesh=MEDCoupling1SGTUMesh.New("aMesh",NORM_POINT1);
13840         mesh.setCoords(srcPointCoordsXY);
13841         f.setMesh(mesh);
13842         f.setArray(srcFieldValsOnPoints);
13843         f.checkCoherency();
13844         #
13845         res0=f.getValueOn([-0.5,-0.5]);
13846         self.assertAlmostEqual(targetFieldValsExpected.getIJ(0,0),res0[0],10)
13847         #
13848         valuesToTest=f.getValueOnMulti(targetPointCoordsXY);
13849         self.assertEqual(196,valuesToTest.getNumberOfTuples());
13850         self.assertEqual(1,valuesToTest.getNumberOfComponents());
13851         for i in xrange(40):
13852             self.assertAlmostEqual(targetFieldValsExpected[i],valuesToTest.getIJ(i,0),10)
13853             pass
13854         fd=f.getDiscretization()
13855         del f
13856         self.assertTrue(isinstance(fd,MEDCouplingFieldDiscretizationKriging))
13857         coeffs,isDrift=fd.computeVectorOfCoefficients(mesh,srcFieldValsOnPoints)
13858         self.assertEqual(3,isDrift)
13859         self.assertTrue(coeffsExpected.isEqual(coeffs,1e-8))
13860         # testing matrix
13861         pts3=[-0.5,-0.5,-0.5,-0.35,-0.35,-0.2]
13862         mesh.setCoords(srcPointCoordsXY[:4])
13863         m,nbCols=fd.computeEvaluationMatrixOnGivenPts(mesh,pts3)
13864         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))
13865         if MEDCouplingHasNumPyBindings():
13866             import numpy as np
13867             m0=m.toNumPyArray() ; m0=m0.reshape(3,nbCols) ; m0=np.matrix(m0)
13868             srcFieldValsOnPoints2=DataArrayDouble(4,2) ; srcFieldValsOnPoints2[:,0]=srcFieldValsOnPoints[:4] ; srcFieldValsOnPoints2[:,1]=2*srcFieldValsOnPoints[:4]
13869             n0=srcFieldValsOnPoints2.toNumPyArray() ; n0=n0.reshape(4,2) ; n0=np.matrix(n0)
13870             #
13871             f=MEDCouplingFieldDouble.New(ON_NODES_KR,ONE_TIME) ;  f.setMesh(mesh) ; f.setArray(srcFieldValsOnPoints2) ; f.checkCoherency()
13872             self.assertTrue(DataArrayDouble(np.array((m0*n0))).isEqual(f.getValueOnMulti(pts3),1e-14))
13873             pass
13874         #
13875         pass
13876     
13877     # test the when input slice is all the same object is return by MEDCouplingMesh.buildPartRange
13878     def testSwig2MeshPartSlice1(self):
13879         a=DataArrayDouble(4) ; a.iota()
13880         c=MEDCouplingCMesh() ; c.setCoords(a,a) ; m=c.buildUnstructured()
13881         fc0=c.getMeasureField(False) ; fc1=fc0[:] ; fc2=fc0*fc1 ; fc2.setName(fc0.getName())
13882         self.assertEqual(fc0.getMesh().getHiddenCppPointer(),fc1.getMesh().getHiddenCppPointer())
13883         self.assertEqual(fc2.getMesh().getHiddenCppPointer(),fc1.getMesh().getHiddenCppPointer())
13884         self.assertTrue(fc2.isEqual(fc1,1e-12,1e-12))
13885         #
13886         fm0=m.getMeasureField(False) ; fm1=fm0[:] ; fm2=fm0*fm1 ; fm2.setName(fm0.getName())
13887         self.assertEqual(fm0.getMesh().getHiddenCppPointer(),fm1.getMesh().getHiddenCppPointer())
13888         self.assertEqual(fm2.getMesh().getHiddenCppPointer(),fm1.getMesh().getHiddenCppPointer())
13889         self.assertTrue(fm2.isEqual(fm1,1e-12,1e-12))
13890         pass
13891
13892     # test the correct behaviour when attempting to aggregate two fields whose mesh is null
13893     def testSwig2MergeFieldsOnFieldsHavingNoMesh(self):
13894         a=DataArrayDouble(4) ; a.iota() ; a*=1.5
13895         c=MEDCouplingCMesh() ; c.setCoords(a,a) ; f1=c.getMeasureField(False)
13896         f1.setMesh(None) ; f2=f1.deepCpy() ; f2*=2
13897         f3=MEDCouplingFieldDouble.MergeFields(f1,f2)
13898         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])
13899         self.assertTrue(f3.getArray().isEqual(daExp,1e-12))
13900         self.assertEqual(f3.getTypeOfField(),ON_CELLS)
13901         self.assertEqual(f3.getMesh(),None)
13902         f4=MEDCouplingFieldDouble.MergeFields([f1,f2])
13903         self.assertTrue(f4.getArray().isEqual(daExp,1e-12))
13904         self.assertEqual(f4.getTypeOfField(),ON_CELLS)
13905         self.assertEqual(f4.getMesh(),None)
13906         pass
13907
13908     # test a simple node to cell convertion of a field
13909     def testSwig2NodeToCellDiscretization1(self):
13910         f=MEDCouplingFieldDouble(ON_NODES) ; f.setTime(1.1,2,3)
13911         a1=DataArrayDouble(4) ; a1.iota()
13912         a2=DataArrayDouble(3) ; a2.iota()
13913         m=MEDCouplingCMesh() ; m.setCoords(a1,a2)
13914         f.setMesh(m)
13915         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]"])
13916         f.setArray(arr) ; f.setName("toto")
13917         #
13918         f2=f.nodeToCellDiscretization()
13919         self.assertEqual(ON_CELLS,f2.getTypeOfField())
13920         self.assertEqual("toto",f2.getName())
13921         self.assertEqual([1.1,2,3],f2.getTime())
13922         self.assertEqual(["aa [km]","bbb [kJ]"],f2.getArray().getInfoOnComponents())
13923         self.assertEqual(6,f2.getArray().getNumberOfTuples())
13924         self.assertEqual(f.getMesh().getHiddenCppPointer(),f2.getMesh().getHiddenCppPointer())
13925         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]"])
13926         self.assertTrue(f2.getArray().isEqual(exp,1e-13))
13927         pass
13928     
13929     def testSwig2NonRegressionBugIntersectMeshes1(self):
13930         src=MEDCouplingUMesh("src",2)
13931         src.setCoords(DataArrayDouble([-2.5,-3,-2.5,3,2.5,3],3,2))
13932         src.allocateCells()
13933         src.insertNextCell(NORM_TRI3,[0,1,2])
13934         #
13935         trg=MEDCouplingUMesh("trg",2)
13936         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))
13937         trg.allocateCells()
13938         trg.insertNextCell(NORM_QPOLYG,[2,1,0,5,3,7,8,6,4,9])
13939         #
13940         a,b,c=MEDCouplingUMesh.Intersect2DMeshes(src,trg,1.0e-8)
13941         a.mergeNodes(1e-8)
13942         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))
13943         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])))
13944         self.assertTrue(a.getNodalConnectivityIndex().isEqual(DataArrayInt([0,9,20])))
13945         self.assertTrue(b.isEqual(DataArrayInt([0,0])))
13946         self.assertTrue(c.isEqual(DataArrayInt([0,-1])))
13947         pass
13948
13949     def testSwig2MeshOrientCorrectly2DCells1(self):
13950         m=MEDCouplingUMesh("mesh",2)
13951         coo=DataArrayDouble([1.,0.,0.5,-0.1,0.,1.,0.,0.,0.07,0.5,0.59,0.5],6,2)
13952         m.setCoords(coo)
13953         m.allocateCells()
13954         m.insertNextCell(NORM_TRI6,[3,0,2,1,5,4])
13955         m.insertNextCell(NORM_QPOLYG,[3,0,2,1,5,4])
13956         self.assertTrue(DataArrayDouble([-0.58093333350930543,-0.58093333350930543]).isEqual(m.getMeasureField(False).getArray(),1e-12))
13957         m.changeSpaceDimension(3)
13958         m.orientCorrectly2DCells([0.,0.,-1.],False)
13959         #
13960         m.checkCoherency()
13961         self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([6,3,2,0,4,5,1, 32,3,2,0,4,5,1])))
13962         self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,7,14])))
13963         m.changeSpaceDimension(2)
13964         self.assertTrue(DataArrayDouble([0.58093333350930543,0.58093333350930543]).isEqual(m.getMeasureField(False).getArray(),1e-12))
13965         pass
13966
13967     def testSwig2Hexa8HavingFacesWarped1(self):
13968         """ 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 
13969         intersected with src the sum of intersection volume is greater than the volume of the trg cell.
13970         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
13971         GENERAL_24).
13972         """
13973         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)
13974         src=MEDCouplingUMesh("TBmesh3D",3) ; src.setCoords(srcCoo)
13975         src.allocateCells()
13976         src.insertNextCell(NORM_HEXA8,[0,1,4,3,8,9,12,11])
13977         src.insertNextCell(NORM_HEXA8,[1,2,5,4,9,10,13,12])
13978         src.insertNextCell(NORM_HEXA8,[4,5,7,6,12,13,15,14])
13979         src.insertNextCell(NORM_HEXA8,[8,9,12,11,16,17,20,19])
13980         src.insertNextCell(NORM_HEXA8,[9,10,13,12,17,18,21,20])
13981         src.checkCoherency2()
13982         # trg is useless here but I keep it in case of MEDCouplingRemapper were expected to do something about warped NORM_HEXA8
13983         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)
13984         trg=MEDCouplingUMesh("MESH",3) ; trg.setCoords(trgCoo)
13985         trg.allocateCells()
13986         trg.insertNextCell(NORM_HEXA8,[0,1,3,2,4,5,7,6])
13987         #
13988         srcFace=src.buildDescendingConnectivity()[0]
13989         conn=MEDCoupling1SGTUMesh(srcFace).getNodalConnectivity() ; conn.rearrange(4)
13990         eqFaces=srcFace.computePlaneEquationOf3DFaces()
13991         nodeIdInCell=3
13992         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
13993         lambd=-e/(eqFaces[:,:3]**2).sumPerTuple()
13994         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
13995         shouldBeZero=(pts*eqFaces[:,:-1]).sumPerTuple()+eqFaces[:,3]# this line is useless only to be sure that pts are on the plane.
13996         check=(pts-srcFace.getCoords()[conn[:,nodeIdInCell]]).magnitude() # check contains the distance of the last point to its plane
13997         idsToTest=check.getIdsNotInRange(0.,1e-10)
13998         self.assertTrue(idsToTest.isEqual(DataArrayInt([17,18,19,20,22,23,24])))
13999         idsToTest2=idsToTest.getIdsNotInRange(18,22)
14000         self.assertTrue(idsToTest2.isEqual(DataArrayInt([0,4,5,6])))
14001         idsToTest2.rearrange(2)
14002         self.assertTrue(idsToTest2.sumPerTuple().isEqual(DataArrayInt([4,11])))
14003         pass
14004
14005     def testSwig2SortHexa8EachOther1(self):
14006         """
14007         testing MEDCoupling1SGTUMesh.sortHexa8EachOther method
14008         """
14009         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)])
14010         m1=MEDCouplingUMesh("m1",3) ; m1.setCoords(coords1)
14011         m1.allocateCells() ; m1.insertNextCell(NORM_HEXA8,[7,1,3,0,6,4,2,5])
14012         m1.checkCoherency()
14013         #
14014         m2=m1.deepCpy() ; m2.setName("m2")
14015         #
14016         trs=[[0.,0.,-1.],[0.,0.,1.],[1.,0.,0.],[0.,-1.,0.],[-1.,0.,0.],[0.,1.,0.]]
14017         for i,t in enumerate(trs):
14018             for j in xrange(64):
14019                 j2=(j//16) ; j1=((j%16)//4) ; j0=(j%4)
14020                 m11=m1.deepCpy()
14021                 m11.rotate([0.,0.,0.],[0.,0.,1.],float(j0)*pi/2)
14022                 m11.rotate([0.,0.,0.],[0.,1.,0.],float(j1)*pi/2)
14023                 m11.rotate([0.,0.,0.],[1.,0.,0.],float(j2)*pi/2)
14024                 m11.translate(t)
14025                 #
14026                 m=MEDCouplingUMesh.MergeUMeshes(m2,m11)
14027                 m.mergeNodes(1e-12)
14028                 self.assertEqual(12,m.getNumberOfNodes())
14029                 m=MEDCoupling1SGTUMesh(m)
14030                 m.sortHexa8EachOther()
14031                 tmp0=m.buildUnstructured().tetrahedrize(PLANAR_FACE_6)[0].buildUnstructured()
14032                 self.assertEqual(20,tmp0.computeSkin().getNumberOfCells())
14033                 pass
14034             pass
14035         pass
14036
14037     def testSwig2normMinComputeAbs1(self):
14038         d=DataArrayDouble([4,-5,2,6.1,-7.33,1,-1,3e2,0.07,-0.009,-6,-1e30],4,3)
14039         d.setInfoOnComponents(["XX [m]","YYY [km]","ABSJJ [MW]"])
14040         d0=d.computeAbs()
14041         dExp=d.deepCpy() ; dExp.abs()
14042         self.assertTrue(dExp.isEqual(d0,1e-12))
14043         e=d0-DataArrayDouble([4,5,2,6.1,7.33,1,1,3e2,0.07,0.009,6,1e30],4,3)
14044         self.assertAlmostEqual(0.,e.normMin(),13)
14045         self.assertAlmostEqual(0.009,d.normMin(),13)
14046         #
14047         di=DataArrayInt([3,-12,5,6,14,16,-23,100,23,-1,0,-6],4,3)
14048         di.setInfoOnComponents(["XX [m]","YYY [km]","ABSJJ [MW]"])
14049         d0i=di.computeAbs()
14050         diExp=di.deepCpy() ; diExp.abs()
14051         self.assertTrue(diExp.isEqual(d0i))
14052         self.assertEqual([3,12,5,6,14,16,23,100,23,1,0,6],d0i.getValues())
14053         pass
14054
14055     def testSwig2GetCellsContainingPointsForNonConvexPolygon1(self):
14056         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)
14057         m=MEDCouplingUMesh("Intersect2D",2) ; m.setCoords(coo) ; m.allocateCells()
14058         m.insertNextCell(NORM_POLYGON,[6,3,4,5])
14059         m.insertNextCell(NORM_POLYGON,[4,0,1,2,6,5])
14060         m.checkCoherency2()
14061         #
14062         self.assertTrue(m.getCellsContainingPoint((0.4,-0.4),1e-12).isEqual(DataArrayInt([0])))
14063         self.assertTrue(m.getCellsContainingPoint((-0.4,-0.4),1e-12).isEqual(DataArrayInt([1])))
14064         self.assertTrue(m.getCellsContainingPoint((0.,-0.4),1e-12).isEqual(DataArrayInt([0,1])))
14065         pass
14066     
14067     def testSwig2GetCellsContainingPointsForNonConvexPolygon2(self):
14068         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)
14069         m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo) ; m.allocateCells()
14070         m.insertNextCell(NORM_QPOLYG,[8,5,4,9])
14071         m.insertNextCell(NORM_QPOLYG,[5,8,4,10])
14072         m.insertNextCell(NORM_QPOLYG,[16,8,5,15,21,9,22,17])
14073         m.insertNextCell(NORM_QPOLYG,[15,1,2,3,16,20,6,7,19,17])
14074         m.insertNextCell(NORM_QPOLYG,[15,5,8,16,22,10,21,18])
14075         m.insertNextCell(NORM_QPOLYG,[16,3,0,1,15,19,11,12,20,18])
14076         m.checkCoherency2()
14077         self.assertTrue(m.getCellsContainingPoint([0.,0.27],1e-12).isEqual(DataArrayInt([2])))
14078         pass
14079
14080     def testSwig2DAIGetIdsEqualTuple1(self):
14081         da=DataArrayInt([0,7,1,2,4,1,2,1,1,2,0,1,2,1,5,1,1,2],9,2)
14082         self.assertTrue(da.getIdsEqualTuple([1,2]).isEqual(DataArrayInt([1,4,8])))
14083         self.assertTrue(da.getIdsEqualTuple((1,2)).isEqual(DataArrayInt([1,4,8])))
14084         self.assertTrue(da.getIdsEqualTuple(DataArrayInt([1,2])).isEqual(DataArrayInt([1,4,8])))
14085         da.rearrange(3)
14086         self.assertRaises(InterpKernelException,da.getIdsEqualTuple,[1,2])# mismatch nb of compo (3) and nb of elts in input tuple (2)
14087         self.assertTrue(da.getIdsEqualTuple([2,0,1]).isEqual(DataArrayInt([3])))
14088         self.assertTrue(da.getIdsEqualTuple([2,0,7]).isEqual(DataArrayInt([])))
14089         da.rearrange(1)
14090         self.assertTrue(da.getIdsEqualTuple(2).isEqual(DataArrayInt([3,6,9,12,17])))
14091         self.assertTrue(da.getIdsEqualTuple(2).isEqual(da.getIdsEqual(2)))
14092         pass
14093
14094     def testSwig2GaussNEStaticInfo1(self):
14095         self.assertTrue(DataArrayDouble(MEDCouplingFieldDiscretizationGaussNE.GetWeightArrayFromGeometricType(NORM_TRI3)).isEqual(DataArrayDouble([0.16666666666666666,0.16666666666666666,0.16666666666666666]),1e-12))
14096         self.assertTrue(DataArrayDouble(MEDCouplingFieldDiscretizationGaussNE.GetRefCoordsFromGeometricType(NORM_TRI3)).isEqual(DataArrayDouble([0.,0.,1.,0.,0.,1.]),1e-12))
14097         self.assertTrue(DataArrayDouble(MEDCouplingFieldDiscretizationGaussNE.GetLocsFromGeometricType(NORM_TRI3)).isEqual(DataArrayDouble([0.16666666666666666,0.16666666666666666,0.6666666666666667,0.16666666666666666,0.16666666666666666,0.6666666666666667]),1e-12))
14098         pass
14099
14100     def testSwigReverseNodalConnOnStructuredMesh(self):
14101         # 1D - standard
14102         c=MEDCouplingCMesh() ; arr=DataArrayDouble(10) ; arr.iota()
14103         c.setCoordsAt(0,arr)
14104         rn,rni=c.getReverseNodalConnectivity()
14105         rn2,rni2=c.buildUnstructured().getReverseNodalConnectivity()
14106         self.assertTrue(rn.isEqual(DataArrayInt([0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8])))
14107         self.assertTrue(rni.isEqual(DataArrayInt([0,1,3,5,7,9,11,13,15,17,18])))
14108         self.assertTrue(rn.isEqual(rn2)) ; self.assertTrue(rni.isEqual(rni2))
14109         # 1D - limit
14110         c=MEDCouplingCMesh() ; arr=DataArrayDouble(1) ; arr.iota()
14111         c.setCoordsAt(0,arr)
14112         rn,rni=c.getReverseNodalConnectivity()
14113         rn2,rni2=c.buildUnstructured().getReverseNodalConnectivity()
14114         self.assertTrue(rn.isEqual(DataArrayInt([0])))
14115         self.assertTrue(rni.isEqual(DataArrayInt([0,1])))
14116         self.assertTrue(rn.isEqual(rn2)) ; self.assertTrue(rni.isEqual(rni2))
14117         # 1D - limit
14118         c=MEDCouplingCMesh() ; arr=DataArrayDouble(0) ; arr.iota()
14119         c.setCoordsAt(0,arr)
14120         rn,rni=c.getReverseNodalConnectivity()
14121         rn.isEqual(DataArrayInt([]))
14122         rni.isEqual(DataArrayInt([0]))
14123         # 2D - standard
14124         c=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota() ; arr2=DataArrayDouble(4) ; arr.iota()
14125         c.setCoords(arr,arr2)
14126         rn,rni=c.getReverseNodalConnectivity()
14127         rn2,rni2=c.buildUnstructured().getReverseNodalConnectivity()
14128         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])))
14129         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])))
14130         self.assertTrue(rn.isEqual(rn2)) ; self.assertTrue(rni.isEqual(rni2))
14131         # 2D - limit
14132         c=MEDCouplingCMesh() ; arr=DataArrayDouble(10) ; arr.iota() ; arr2=DataArrayDouble(1) ; arr.iota()
14133         c.setCoords(arr,arr2)
14134         rn,rni=c.getReverseNodalConnectivity()
14135         self.assertTrue(rn.isEqual(DataArrayInt([0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8])))
14136         self.assertTrue(rni.isEqual(DataArrayInt([0,1,3,5,7,9,11,13,15,17,18])))
14137         # 2D - limit
14138         c=MEDCouplingCMesh() ; arr=DataArrayDouble(10) ; arr.iota() ; arr2=DataArrayDouble(1) ; arr.iota()
14139         c.setCoords(arr2,arr)
14140         rn,rni=c.getReverseNodalConnectivity()
14141         self.assertTrue(rn.isEqual(DataArrayInt([0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8])))
14142         self.assertTrue(rni.isEqual(DataArrayInt([0,1,3,5,7,9,11,13,15,17,18])))
14143         # 3D - standard
14144         c=MEDCouplingCMesh() ; arr0=DataArrayDouble(5) ; arr0.iota() ; arr1=DataArrayDouble(3) ; arr1.iota() ; arr2=DataArrayDouble(4) ; arr2.iota()
14145         c.setCoords(arr0,arr1,arr2)
14146         rn,rni=c.getReverseNodalConnectivity()
14147         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])))
14148         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])))
14149         rn2,rni2=c.buildUnstructured().getReverseNodalConnectivity()
14150         self.assertTrue(rn.isEqual(rn2)) ; self.assertTrue(rni.isEqual(rni2))
14151         pass
14152
14153     def testSwig2CellToNodeDiscretization1(self):
14154         m=MEDCouplingCMesh() ; arr0=DataArrayDouble(5) ; arr0.iota() ; arr1=DataArrayDouble(4) ; arr1.iota() ; m.setCoords(arr0,arr1)
14155         f=MEDCouplingFieldDouble(ON_CELLS) ; f.setMesh(m) ; f.setTime(1.1,5,6)
14156         arr=DataArrayDouble(12) ; arr.iota()
14157         arr=DataArrayDouble.Meld(arr,arr+100.) ; arr.setInfoOnComponents(["aaa","bbb"])
14158         f.setArray(arr)
14159         f.checkCoherency()
14160         #
14161         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.])
14162         ref=DataArrayDouble.Meld(ref,ref+100.) ; ref.setInfoOnComponents(["aaa","bbb"])
14163         f2=f.cellToNodeDiscretization()
14164         f2.checkCoherency()
14165         self.assertEqual(f2.getTime()[1:],[5,6])
14166         self.assertAlmostEqual(f2.getTime()[0],1.1,15)
14167         self.assertEqual(f2.getMesh().getHiddenCppPointer(),m.getHiddenCppPointer())
14168         self.assertTrue(f2.getArray().isEqual(ref,1e-12))
14169         rn,rni=m.getReverseNodalConnectivity()
14170         rni2=(rni.deltaShiftIndex()).convertToDblArr()
14171         arr2=(f.getArray()[rn]).accumulatePerChunck(rni)/rni2
14172         self.assertTrue(f2.getArray().isEqual(arr2,1e-12))
14173         del f2
14174         #
14175         u=m.buildUnstructured() ; f.setMesh(u) ; del m
14176         f3=f.cellToNodeDiscretization()
14177         f3.checkCoherency()
14178         self.assertEqual(f3.getTime()[1:],[5,6])
14179         self.assertAlmostEqual(f3.getTime()[0],1.1,15)
14180         self.assertEqual(f3.getMesh().getHiddenCppPointer(),u.getHiddenCppPointer())
14181         self.assertTrue(f3.getArray().isEqual(ref,1e-12))
14182         pass
14183
14184     def testSwig2GetMeshSpaceDimensionCMesh1(self):
14185         c=MEDCouplingCMesh()
14186         arr0=DataArrayDouble([0,1,2])
14187         arr1=DataArrayDouble([0])
14188         c.setCoords(arr0,arr0,arr0)
14189         self.assertEqual(c.getMeshDimension(),3)
14190         self.assertEqual(c.getSpaceDimension(),3)
14191         #
14192         c.setCoords(arr0,arr0,arr1)
14193         self.assertEqual(c.getMeshDimension(),2)
14194         self.assertEqual(c.getSpaceDimension(),3)
14195         #
14196         c.setCoords(arr0,arr0)
14197         self.assertEqual(c.getMeshDimension(),2)
14198         self.assertEqual(c.getSpaceDimension(),2)
14199         #
14200         c.setCoords(arr0,arr1)
14201         self.assertEqual(c.getMeshDimension(),1)
14202         self.assertEqual(c.getSpaceDimension(),2)
14203         #
14204         c.setCoords(arr0)
14205         self.assertEqual(c.getMeshDimension(),1)
14206         self.assertEqual(c.getSpaceDimension(),1)
14207         #
14208         c.setCoords(arr1)
14209         self.assertEqual(c.getMeshDimension(),0)
14210         self.assertEqual(c.getSpaceDimension(),1)
14211         pass
14212
14213     def setUp(self):
14214         pass
14215     pass
14216
14217 if __name__ == '__main__':
14218     unittest.main()