Salome HOME
Merge remote branch 'origin/V7_4_BR'
[tools/medcoupling.git] / src / MEDCoupling_Swig / MEDCouplingExamplesTest.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2014  CEA/DEN, EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 from MEDCoupling import *
22 import unittest
23 from math import pi, sqrt
24
25 class MEDCouplingBasicsTest(unittest.TestCase):
26
27     def testExample_MEDCouplingFieldDouble_WriteVTK(self):
28         #! [PySnippet_MEDCouplingFieldDouble_WriteVTK_1]
29         # mesh
30         coords = [0.,2.,4.]
31         coordsArr=DataArrayDouble.New(coords,3,1)
32         mesh=MEDCouplingCMesh.New()
33         mesh.setCoords(coordsArr,coordsArr) # mesh becomes a 2D one
34
35         # 3 fields (lying on the same mesh!)
36         field1 = mesh.getMeasureField( True )
37         field2 = mesh.buildOrthogonalField()
38         field3 = mesh.fillFromAnalytic( ON_CELLS, 2, "IVec * x + JVec * y" )
39         field2.setName( "Normal" ) # name is necessary!
40         field3.setName( "Barycenter" ) # name is necessary!
41
42         # WriteVTK
43         fileName = "testExample_MEDCouplingFieldDouble_WriteVTK"
44         fs = [ field1, field2, field3 ] # field series
45         writtenFileName=MEDCouplingFieldDouble.WriteVTK( fileName, fs )
46         print "The file name with correct extension is : %s"%(writtenFileName)
47         #! [PySnippet_MEDCouplingFieldDouble_WriteVTK_1]
48         import os
49         os.remove( writtenFileName )
50
51         return
52
53     def testExample_MEDCouplingFieldDouble_MaxFields(self):
54         #! [PySnippet_MEDCouplingFieldDouble_MaxFields_1]
55         vals1   = [0.,2., 4.,6.] # for field 1
56         vals2   = [2.,0., 6.,4.] # for field 2
57         valsMax = [2.,2., 6.,6.] # expected max field
58         valsMin = [0.,0., 4.,4.] # expected min field
59
60         # field 1
61         valsArr1=DataArrayDouble.New(vals1,2,2) # 2 tuples per 2 components
62         field1 = MEDCouplingFieldDouble.New( ON_NODES )
63         field1.setArray( valsArr1 )
64
65         # field 2
66         valsArr2=DataArrayDouble.New(vals2,2,2) # 2 tuples per 2 components
67         field2 = MEDCouplingFieldDouble.New( ON_NODES )
68         field2.setArray( valsArr2 )
69
70         # max field 
71         fieldMax = MEDCouplingFieldDouble.MaxFields( field1, field2 )
72         self.assertTrue( fieldMax.getArray().getValues() == valsMax )
73
74         # min field 
75         fieldMin = MEDCouplingFieldDouble.MinFields( field1, field2 )
76         self.assertTrue( fieldMin.getArray().getValues() == valsMin )
77         #! [PySnippet_MEDCouplingFieldDouble_MaxFields_1]
78
79     def testExample_MEDCouplingFieldDouble_MergeFields(self):
80         #! [PySnippet_MEDCouplingFieldDouble_MergeFields_1]
81         # mesh 1
82         coords = [0.,2.,4.]
83         coordsArr=DataArrayDouble.New(coords,3,1)
84         mesh1=MEDCouplingCMesh.New()
85         mesh1.setCoords(coordsArr)
86         # field 1
87         field1 = mesh1.fillFromAnalytic( ON_CELLS, 1, "x")
88
89         # mesh 2 and field 2
90         field2 = field1.cloneWithMesh( True )
91         vec = [5.]
92         field2.getMesh().translate(vec) # translate mesh2
93         field2.applyFunc("x + 5") # "translate" field2
94
95         # concatenate field1 and field2
96         field3 = MEDCouplingFieldDouble.MergeFields( field1, field2 )
97         field4 = MEDCouplingFieldDouble.MergeFields( [ field1, field2] )
98         #! [PySnippet_MEDCouplingFieldDouble_MergeFields_1]
99         return
100
101     def testExample_MEDCouplingFieldDouble_substractInPlaceDM(self):
102         #! [PySnippet_MEDCouplingFieldDouble_substractInPlaceDM_1]
103         coords1=[0.,1.,2.,3.]
104         coords2=[2.,1.,0.,3.] #0 <==> #2
105         # mesh 1
106         mesh1=MEDCouplingUMesh.New();
107         coordsArr=DataArrayDouble.New(coords1, 4, 1);
108         mesh1.setCoords(coordsArr);
109         mesh1.setMeshDimension(0);
110         mesh1.allocateCells(0);
111         mesh1.finishInsertingCells();
112         # mesh 2
113         mesh2=mesh1.deepCpy();
114         mesh2.getCoords().setValues(coords2, 4, 1);
115         #! [PySnippet_MEDCouplingFieldDouble_substractInPlaceDM_1]
116         #! [PySnippet_MEDCouplingFieldDouble_substractInPlaceDM_2]
117         field1 = mesh1.fillFromAnalytic(ON_NODES,1,"x") # field1 values == coords1
118         field2 = mesh2.fillFromAnalytic(ON_NODES,1,"x") # field2 values == coords2
119         levOfCheck = 10 # nodes can be permuted
120         field1.substractInPlaceDM( field2, levOfCheck, 1e-13, 0 ) # values #0 and #2 must swap
121         #! [PySnippet_MEDCouplingFieldDouble_substractInPlaceDM_2]
122         #! [PySnippet_MEDCouplingFieldDouble_substractInPlaceDM_3]
123         field2.applyFunc( 1, 0.0 ) # all field2 values == 0.0
124         self.assertTrue( field1.isEqual( field2, 1e-13, 1e-13 )) # field1 == field2 == 0.0
125         #! [PySnippet_MEDCouplingFieldDouble_substractInPlaceDM_3]
126         return
127
128     def testExample_MEDCouplingFieldDouble_changeUnderlyingMesh(self):
129         #! [PySnippet_MEDCouplingFieldDouble_changeUnderlyingMesh_1]
130         coords1=[0.,1.,2.,3.]
131         coords2=[2.,1.,0.,3.] #0 <==> #2
132         # mesh 1
133         mesh1=MEDCouplingUMesh.New();
134         coordsArr=DataArrayDouble.New(coords1, 4, 1);
135         mesh1.setCoords(coordsArr);
136         mesh1.setMeshDimension(0);
137         mesh1.allocateCells(0);
138         mesh1.finishInsertingCells();
139         # mesh 2
140         mesh2=mesh1.deepCpy();
141         mesh2.getCoords().setValues(coords2, 4, 1);
142         #! [PySnippet_MEDCouplingFieldDouble_changeUnderlyingMesh_1]
143         #! [PySnippet_MEDCouplingFieldDouble_changeUnderlyingMesh_2]
144         field = mesh1.fillFromAnalytic(ON_NODES,1,"x") # field values == coords1
145         levOfCheck = 10 # nodes can be permuted
146         field.changeUnderlyingMesh( mesh2, levOfCheck, 1e-13, 0 ) # values #0 and #2 must swap
147         self.assertTrue( field.getArray().getValues() == coords2 )
148         #! [PySnippet_MEDCouplingFieldDouble_changeUnderlyingMesh_2]
149         return
150
151     def testExample_MEDCouplingFieldDouble_applyFunc_same_nb_comp(self):
152         #! [PySnippet_MEDCouplingFieldDouble_applyFunc_same_nb_comp_1]
153         v = [1.,2., 3.,4.]
154         array = DataArrayDouble.New( v, 2, 2 ) # 2 tuples per 2 components
155         field = MEDCouplingFieldDouble.New( ON_CELLS )
156         field.setArray( array )
157         func = "IVec * v + JVec * w*w + 10"
158         field.applyFunc( 2, func )
159         self.assertTrue( field.getNumberOfComponents() == 2 ) # 2 components remains
160         #! [PySnippet_MEDCouplingFieldDouble_applyFunc_same_nb_comp_1]
161         #! [PySnippet_MEDCouplingFieldDouble_applyFunc_same_nb_comp_2]
162         v2 = field.getArray().getValues()
163         self.assertAlmostEqual( v2[0], 10 + v[0], 13 )      # "10 + IVec * v"
164         self.assertAlmostEqual( v2[1], 10 + v[1]*v[1], 13 ) # "10 + JVec * v*v"
165         self.assertAlmostEqual( v2[2], 10 + v[2], 13 )      # "10 + IVec * v"
166         self.assertAlmostEqual( v2[3], 10 + v[3]*v[3], 13 ) # "10 + JVec * v*v"
167         #! [PySnippet_MEDCouplingFieldDouble_applyFunc_same_nb_comp_2]
168         return
169
170     def testExample_MEDCouplingFieldDouble_applyFunc3(self):
171         #! [PySnippet_MEDCouplingFieldDouble_applyFunc3_1]
172         # create a 2D vector field
173         values = [1.,1., 2.,1.]
174         array = DataArrayDouble.New( values, 2, 2 ) # 2 tuples per 2 components
175         field = MEDCouplingFieldDouble.New( ON_CELLS )
176         field.setArray( array )
177         # transform the field to a 3D vector field
178         func = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10"
179         varNames=["a","b"] # names used to refer to X and Y components
180         field.applyFunc3( 3, varNames, func ) # require 3 components 
181         self.assertTrue( field.getNumberOfComponents() == 3 ) # 3 components as required
182         #! [PySnippet_MEDCouplingFieldDouble_applyFunc3_1]
183         #! [PySnippet_MEDCouplingFieldDouble_applyFunc3_2]
184         vec1 = field.getArray().getTuple(1) # vector #1
185         a,b = values[2], values[3] # initial components of the vector #1
186         self.assertAlmostEqual( vec1[0], 10 + b, 13 ) # "10 + IVec * b"
187         self.assertAlmostEqual( vec1[1], 10 + a, 13 ) # "10 + JVec * a"
188         self.assertAlmostEqual( vec1[2], 10 + sqrt(a*a+b*b), 13 ) # "10 + KVec * sqrt( a*a + b*b )"
189         #! [PySnippet_MEDCouplingFieldDouble_applyFunc3_2]
190         return
191
192     def testExample_MEDCouplingFieldDouble_applyFunc2(self):
193         #! [PySnippet_MEDCouplingFieldDouble_applyFunc2_1]
194         # create a 2D vector field
195         values = [1.,1., 2.,1.]
196         array = DataArrayDouble.New( values, 2, 2 ) # 2 tuples per 2 components
197         array.setInfoOnComponent(0,"a") # name used to refer to X component within a function
198         array.setInfoOnComponent(1,"b") # name used to refer to Y component within a function
199         field = MEDCouplingFieldDouble.New( ON_CELLS )
200         field.setArray( array )
201         # transform the field to a 3D vector field
202         func = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10"
203         field.applyFunc2( 3, func ) # require 3 components 
204         self.assertTrue( field.getNumberOfComponents() == 3 ) # 3 components as required
205         #! [PySnippet_MEDCouplingFieldDouble_applyFunc2_1]
206         #! [PySnippet_MEDCouplingFieldDouble_applyFunc2_2]
207         vec1 = field.getArray().getTuple(1) # vector #1
208         a,b = values[2], values[3] # initial components of the vector #1
209         self.assertAlmostEqual( vec1[0], 10 + b, 13 ) # "10 + IVec * b"
210         self.assertAlmostEqual( vec1[1], 10 + a, 13 ) # "10 + JVec * a"
211         self.assertAlmostEqual( vec1[2], 10 + sqrt(a*a+b*b), 13 ) # "10 + KVec * sqrt( a*a + b*b )"
212         #! [PySnippet_MEDCouplingFieldDouble_applyFunc2_2]
213         return
214
215     def testExample_MEDCouplingFieldDouble_applyFunc(self):
216         #! [PySnippet_MEDCouplingFieldDouble_applyFunc_1]
217         # create a 2D vector field
218         values = [1.,1., 2.,1.]
219         array = DataArrayDouble.New( values, 2, 2 ) # 2 tuples per 2 components
220         field = MEDCouplingFieldDouble.New( ON_CELLS )
221         field.setArray( array )
222         # transform the field to a 3D vector field
223         func = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10"
224         field.applyFunc( 3, func ) # require 3 components 
225         self.assertTrue( field.getNumberOfComponents() == 3 ) # 3 components as required
226         #! [PySnippet_MEDCouplingFieldDouble_applyFunc_1]
227         #! [PySnippet_MEDCouplingFieldDouble_applyFunc_2]
228         vec1 = field.getArray().getTuple(1) # vector #1
229         a,b = values[2], values[3] # initial components of the vector #1
230         self.assertAlmostEqual( vec1[0], 10 + b, 13 ) # "10 + IVec * b"
231         self.assertAlmostEqual( vec1[1], 10 + a, 13 ) # "10 + JVec * a"
232         self.assertAlmostEqual( vec1[2], 10 + sqrt(a*a+b*b), 13 ) # "10 + KVec * sqrt( a*a + b*b )"
233         #! [PySnippet_MEDCouplingFieldDouble_applyFunc_2]
234         return
235
236     def testExample_MEDCouplingFieldDouble_applyFunc_val(self):
237         #! [PySnippet_MEDCouplingFieldDouble_applyFunc_val_1]
238         coords = [0.,2.,4.]
239         coordsArr=DataArrayDouble.New(coords,3,1)
240         mesh=MEDCouplingCMesh.New()
241         mesh.setCoords(coordsArr,coordsArr)
242         field = MEDCouplingFieldDouble.New( ON_CELLS )
243         field.setMesh( mesh )
244         field.fillFromAnalytic(2,"IVec * x + JVec * y") # 2 components
245         #! [PySnippet_MEDCouplingFieldDouble_applyFunc_val_1]
246         #! [PySnippet_MEDCouplingFieldDouble_applyFunc_val_2]
247         newValue = 7.
248         field.applyFunc( 3, newValue ) # 3 components are required
249         self.assertTrue( field.getIJ(1,0) == newValue ) # a value is as expected
250         self.assertTrue( field.getNumberOfComponents() == 3 )
251         self.assertTrue( field.getNumberOfTuples() == mesh.getNumberOfCells() )
252         #! [PySnippet_MEDCouplingFieldDouble_applyFunc_val_2]
253         return
254
255     def testExample_MEDCouplingFieldDouble_fillFromAnalytic3(self):
256         #! [PySnippet_MEDCouplingFieldDouble_fillFromAnalytic3_1]
257         coords = [0.,2.,4.,6.] #  6. is not used
258         x=DataArrayDouble.New(coords[:3],3,1)
259         y=DataArrayDouble.New(coords[:2],2,1)
260         mesh=MEDCouplingCMesh.New()
261         mesh.setCoords(x,y)
262         #! [PySnippet_MEDCouplingFieldDouble_fillFromAnalytic3_1]
263         #! [PySnippet_MEDCouplingFieldDouble_fillFromAnalytic3_2]
264         field = MEDCouplingFieldDouble.New( ON_CELLS )
265         field.setMesh( mesh )
266         func = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10"
267         varNames=["a","b"] # names used to refer to X and Y coord components
268         field.fillFromAnalytic3(3,varNames,func)
269         #! [PySnippet_MEDCouplingFieldDouble_fillFromAnalytic3_2]
270         #! [PySnippet_MEDCouplingFieldDouble_fillFromAnalytic3_3]
271         vals1 = field.getArray().getTuple(1) # values of the cell #1
272         assert len( vals1 ) == 3 # 3 components in the field
273         #
274         bc = mesh.getBarycenterAndOwner() # func is applied to barycenters of cells
275         bc1 = bc.getTuple(1) # coordinates of the second point
276         #
277         dist = sqrt( bc1[0]*bc1[0] + bc1[1]*bc1[1] ) # "sqrt( a*a + b*b )"
278         self.assertAlmostEqual( vals1[0], 10 + bc1[1], 13 ) # "10 + IVec * b"
279         self.assertAlmostEqual( vals1[1], 10 + bc1[0], 13 ) # "10 + JVec * a"
280         self.assertAlmostEqual( vals1[2], 10 + dist  , 13 ) # "10 + KVec * sqrt( a*a + b*b )"
281         #! [PySnippet_MEDCouplingFieldDouble_fillFromAnalytic3_3]
282         return
283
284     def testExample_MEDCouplingFieldDouble_fillFromAnalytic2(self):
285         #! [PySnippet_MEDCouplingFieldDouble_fillFromAnalytic2_1]
286         coords = [0.,2.,4.]
287         x=DataArrayDouble.New(coords[:3],3,1)
288         y=DataArrayDouble.New(coords[:2],2,1)
289         x.setInfoOnComponent(0,"a") # name used to refer to X coordinate within a function
290         y.setInfoOnComponent(0,"b") # name used to refer to Y coordinate within a function
291         mesh=MEDCouplingCMesh.New()
292         mesh.setCoords(x,y)
293         #! [PySnippet_MEDCouplingFieldDouble_fillFromAnalytic2_1]
294         #! [PySnippet_MEDCouplingFieldDouble_fillFromAnalytic2_2]
295         field = MEDCouplingFieldDouble.New( ON_CELLS )
296         field.setMesh( mesh )
297         func = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10"
298         field.fillFromAnalytic2(3,func)
299         #! [PySnippet_MEDCouplingFieldDouble_fillFromAnalytic2_2]
300         #! [PySnippet_MEDCouplingFieldDouble_fillFromAnalytic2_3]
301         vals1 = field.getArray().getTuple(1) # values of the cell #1
302         assert len( vals1 ) == 3 # 3 components in the field
303         #
304         bc = mesh.getBarycenterAndOwner() # func is applied to barycenters of cells
305         bc1 = bc.getTuple(1) # coordinates of the second point
306         #
307         dist = sqrt( bc1[0]*bc1[0] + bc1[1]*bc1[1] ) # "sqrt( a*a + b*b )"
308         self.assertAlmostEqual( vals1[0], 10 + bc1[1], 13 ) # "10 + IVec * b"
309         self.assertAlmostEqual( vals1[1], 10 + bc1[0], 13 ) # "10 + JVec * a"
310         self.assertAlmostEqual( vals1[2], 10 + dist  , 13 ) # "10 + KVec * sqrt( a*a + b*b )"
311         #! [PySnippet_MEDCouplingFieldDouble_fillFromAnalytic2_3]
312         return
313
314     def testExample_MEDCouplingFieldDouble_fillFromAnalytic(self):
315         #! [PySnippet_MEDCouplingFieldDouble_fillFromAnalytic_1]
316         coords = [0.,2.,4.]
317         x=DataArrayDouble.New(coords[:3],3,1)
318         y=DataArrayDouble.New(coords[:2],2,1)
319         mesh=MEDCouplingCMesh.New()
320         mesh.setCoords(x,y)
321         #! [PySnippet_MEDCouplingFieldDouble_fillFromAnalytic_1]
322         #! [PySnippet_MEDCouplingFieldDouble_fillFromAnalytic_2]
323         field = MEDCouplingFieldDouble.New( ON_CELLS )
324         field.setMesh( mesh )
325         func = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10"
326         field.fillFromAnalytic(3,func)
327         #! [PySnippet_MEDCouplingFieldDouble_fillFromAnalytic_2]
328         #! [PySnippet_MEDCouplingFieldDouble_fillFromAnalytic_3]
329         vals1 = field.getArray().getTuple(1) # values of the cell #1
330         assert len( vals1 ) == 3 # 3 components in the field
331         #
332         bc = mesh.getBarycenterAndOwner() # func is applied to barycenters of cells
333         bc1 = bc.getTuple(1) # coordinates of the second point
334         #
335         dist = sqrt( bc1[0]*bc1[0] + bc1[1]*bc1[1] ) # "sqrt( a*a + b*b )"
336         self.assertAlmostEqual( vals1[0], 10 + bc1[1], 13 ) # "10 + IVec * b"
337         self.assertAlmostEqual( vals1[1], 10 + bc1[0], 13 ) # "10 + JVec * a"
338         self.assertAlmostEqual( vals1[2], 10 + dist  , 13 ) # "10 + KVec * sqrt( a*a + b*b )"
339         #! [PySnippet_MEDCouplingFieldDouble_fillFromAnalytic_3]
340         return
341
342     def testExample_MEDCouplingFieldDouble_getValueOn_time(self):
343         #! [PySnippet_MEDCouplingFieldDouble_getValueOn_time_1]
344         coords = [0.,2.,4.]
345         coordsArr=DataArrayDouble.New(coords,3,1)
346         mesh=MEDCouplingCMesh.New()
347         mesh.setCoords(coordsArr,coordsArr)
348         #! [PySnippet_MEDCouplingFieldDouble_getValueOn_time_1]
349         #! [PySnippet_MEDCouplingFieldDouble_getValueOn_time_2]
350         field = MEDCouplingFieldDouble.New( ON_CELLS, LINEAR_TIME )
351         field.setMesh( mesh )
352         field.fillFromAnalytic(1,"10") # all values == 10.
353         field.setEndArray( field.getArray() + field.getArray() ) # all values == 20.
354         time1, time2 = 1.1, 22.
355         field.setStartTime( time1, 0, 0 )
356         field.setEndTime  ( time2, 0, 0 )
357         #! [PySnippet_MEDCouplingFieldDouble_getValueOn_time_2]
358         #! [PySnippet_MEDCouplingFieldDouble_getValueOn_time_3]
359         pos = [ 1., 1. ] # we are in 2D space
360         value = field.getValueOn( pos, 0.5*( time1 + time2 ))
361         self.assertTrue( value[0] == 0.5*( 10. + 20.))
362         #! [PySnippet_MEDCouplingFieldDouble_getValueOn_time_3]
363         return
364
365     def testExample_MEDCouplingFieldDouble_getValueOnMulti(self):
366         #! [PySnippet_MEDCouplingFieldDouble_getValueOnMulti_1]
367         coords = [0.,2.,4.]
368         coordsArr=DataArrayDouble.New(coords,3,1)
369         mesh=MEDCouplingCMesh.New()
370         mesh.setCoords(coordsArr,coordsArr)
371         field = mesh.fillFromAnalytic(ON_CELLS,1,"x+y")
372         #! [PySnippet_MEDCouplingFieldDouble_getValueOnMulti_1]
373         #! [PySnippet_MEDCouplingFieldDouble_getValueOnMulti_2]
374         bc = mesh.getBarycenterAndOwner() # field values are located at cell barycenters
375         valArray = field.getValueOnMulti( bc )
376         self.assertTrue( valArray.isEqual( field.getArray(), 1e-13 ))
377         #! [PySnippet_MEDCouplingFieldDouble_getValueOnMulti_2]
378         return
379
380     def testExample_MEDCouplingFieldDouble_getValueOn(self):
381         #! [PySnippet_MEDCouplingFieldDouble_getValueOn_1]
382         coords = [0.,2.,4.]
383         coordsArr=DataArrayDouble.New(coords,3,1)
384         mesh=MEDCouplingCMesh.New()
385         mesh.setCoords(coordsArr,coordsArr)
386         field = mesh.fillFromAnalytic(ON_CELLS,1,"x+y")
387         #! [PySnippet_MEDCouplingFieldDouble_getValueOn_1]
388         #! [PySnippet_MEDCouplingFieldDouble_getValueOn_2]
389         bc = mesh.getBarycenterAndOwner() # field values are located at cell barycenters
390         vals = [] # array to collect values returned by getValueOn()
391         for i,tupl in enumerate( bc ):
392             vals.extend( field.getValueOn( tupl ) )
393         self.assertTrue( vals == field.getArray().getValues() )
394         #! [PySnippet_MEDCouplingFieldDouble_getValueOn_2]
395         return
396
397     def testExample_MEDCouplingFieldDouble_getValueOnPos(self):
398         #! [PySnippet_MEDCouplingFieldDouble_getValueOnPos_1]
399         coords = [0.,2.,4.]
400         coordsArr=DataArrayDouble.New(coords,3,1)
401         mesh=MEDCouplingCMesh.New()
402         mesh.setCoords(coordsArr,coordsArr)
403         field = mesh.fillFromAnalytic(ON_CELLS,1,"x+y")
404         #! [PySnippet_MEDCouplingFieldDouble_getValueOnPos_1]
405         #! [PySnippet_MEDCouplingFieldDouble_getValueOnPos_2]
406         val11 = field.getValueOnPos( 1,1,-1)
407         bc = mesh.getBarycenterAndOwner() # field values are located at cell barycenters
408         self.assertTrue( val11[0] == bc[3,0] + bc[3,1] )
409         #! [PySnippet_MEDCouplingFieldDouble_getValueOnPos_2]
410         return
411
412     def testExample_MEDCouplingFieldDouble_renumberNodes(self):
413         #! [PySnippet_MEDCouplingFieldDouble_renumberNodes_1]
414         coords = [0.,2.,4.]
415         coordsArr=DataArrayDouble.New(coords,3,1)
416         mesh=MEDCouplingCMesh.New()
417         mesh.setCoords(coordsArr,coordsArr)
418         mesh=mesh.buildUnstructured()
419         #! [PySnippet_MEDCouplingFieldDouble_renumberNodes_1]
420         #! [PySnippet_MEDCouplingFieldDouble_renumberNodes_2]
421         field = mesh.fillFromAnalytic(ON_NODES,2,"IVec*x+JVec*y")
422         values = field.getArray()
423         nodeCoords = mesh.getCoords()
424         self.assertTrue( values.isEqualWithoutConsideringStr( nodeCoords, 1e-13 ))
425         #! [PySnippet_MEDCouplingFieldDouble_renumberNodes_2]
426         #! [PySnippet_MEDCouplingFieldDouble_renumberNodes_3]
427         renumber = [8, 7, 6, 5, 4, 3, 2, 1, 0]
428         field.renumberNodes(renumber,False)
429         mesh2 = field.getMesh() # field now refers to another mesh
430         values = field.getArray()
431         nodeCoords = mesh2.getCoords()
432         self.assertTrue( values.isEqualWithoutConsideringStr( nodeCoords, 1e-13 ))
433         #! [PySnippet_MEDCouplingFieldDouble_renumberNodes_3]
434         return
435
436
437     def testExample_MEDCouplingFieldDouble_renumberCells(self):
438         #! [PySnippet_MEDCouplingFieldDouble_renumberCells_1]
439         coords = [0.,2.,4.]
440         coordsArr=DataArrayDouble.New(coords,3,1)
441         mesh=MEDCouplingCMesh.New()
442         mesh.setCoords(coordsArr,coordsArr)
443         mesh=mesh.buildUnstructured()
444         #! [PySnippet_MEDCouplingFieldDouble_renumberCells_1]
445         #! [PySnippet_MEDCouplingFieldDouble_renumberCells_2]
446         field = mesh.fillFromAnalytic(ON_CELLS,2,"IVec*x+JVec*y")
447         values = field.getArray()
448         bc = mesh.getBarycenterAndOwner()
449         self.assertTrue( values.isEqualWithoutConsideringStr( bc, 1e-13 ))
450         #! [PySnippet_MEDCouplingFieldDouble_renumberCells_2]
451         #! [PySnippet_MEDCouplingFieldDouble_renumberCells_3]
452         renumber = [ 3, 2, 1, 0 ]
453         field.renumberCells(renumber,False)
454         mesh2 = field.getMesh() # field now refers to another mesh
455         values = field.getArray()
456         bc = mesh2.getBarycenterAndOwner()
457         self.assertTrue( values.isEqualWithoutConsideringStr( bc, 1e-13 ))
458         #! [PySnippet_MEDCouplingFieldDouble_renumberCells_3]
459         return
460
461     def testExample_MEDCouplingFieldDouble_buildNewTimeReprFromThis(self):
462         #! [PySnippet_MEDCouplingFieldDouble_buildNewTimeReprFromThis_1]
463         coords = [0.,2.,4.]
464         coordsArr=DataArrayDouble.New(coords,3,1)
465         mesh=MEDCouplingCMesh.New()
466         mesh.setCoords(coordsArr,coordsArr)
467         field1 = mesh.fillFromAnalytic(ON_NODES,1,"x+y")
468         self.assertTrue( field1.getTimeDiscretization() == ONE_TIME )
469         #! [PySnippet_MEDCouplingFieldDouble_buildNewTimeReprFromThis_1]
470         #! [PySnippet_MEDCouplingFieldDouble_buildNewTimeReprFromThis_2]
471         field2 = field1.buildNewTimeReprFromThis(NO_TIME,False)
472         self.assertTrue( field2.getTimeDiscretization() == NO_TIME )
473         #! [PySnippet_MEDCouplingFieldDouble_buildNewTimeReprFromThis_2]
474         return
475
476     def testExample_MEDCouplingMesh_fillFromAnalytic3(self):
477         #! [PySnippet_MEDCouplingMesh_fillFromAnalytic3_1]
478         coords = [0.,2.,4.,6.] #  6. is not used
479         x=DataArrayDouble.New(coords[:3],3,1)
480         y=DataArrayDouble.New(coords[:2],2,1)
481         mesh=MEDCouplingCMesh.New()
482         mesh.setCoords(x,y)
483         #! [PySnippet_MEDCouplingMesh_fillFromAnalytic3_1]
484         #! [PySnippet_MEDCouplingMesh_fillFromAnalytic3_2]
485         func = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10"
486         varNames=["a","b"] # names used to refer to X and Y coord components
487         field=mesh.fillFromAnalytic3(ON_CELLS,3,varNames,func)
488         #! [PySnippet_MEDCouplingMesh_fillFromAnalytic3_2]
489         #! [PySnippet_MEDCouplingMesh_fillFromAnalytic3_3]
490         vals1 = field.getArray().getTuple(1) # values of the cell #1
491         assert len( vals1 ) == 3 # 3 components in the field
492         #
493         bc = mesh.getBarycenterAndOwner() # func is applied to barycenters of cells
494         bc1 = bc.getTuple(1) # coordinates of the second point
495         #
496         dist = sqrt( bc1[0]*bc1[0] + bc1[1]*bc1[1] ) # "sqrt( a*a + b*b )"
497         self.assertAlmostEqual( vals1[0], 10 + bc1[1], 13 ) # "10 + IVec * b"
498         self.assertAlmostEqual( vals1[1], 10 + bc1[0], 13 ) # "10 + JVec * a"
499         self.assertAlmostEqual( vals1[2], 10 + dist  , 13 ) # "10 + KVec * sqrt( a*a + b*b )"
500         #! [PySnippet_MEDCouplingMesh_fillFromAnalytic3_3]
501         return
502
503     def testExample_MEDCouplingMesh_fillFromAnalytic2(self):
504         #! [PySnippet_MEDCouplingMesh_fillFromAnalytic2_1]
505         coords = [0.,2.,4.,6.] #  6. is not used
506         x=DataArrayDouble.New(coords[:3],3,1)
507         y=DataArrayDouble.New(coords[:2],2,1)
508         x.setInfoOnComponent(0,"a") # name used to refer to X coordinate within a function
509         y.setInfoOnComponent(0,"b") # name used to refer to Y coordinate within a function
510         mesh=MEDCouplingCMesh.New()
511         mesh.setCoords(x,y)
512         #! [PySnippet_MEDCouplingMesh_fillFromAnalytic2_1]
513         #! [PySnippet_MEDCouplingMesh_fillFromAnalytic2_2]
514         func = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10"
515         field=mesh.fillFromAnalytic2(ON_CELLS,3,func)
516         #! [PySnippet_MEDCouplingMesh_fillFromAnalytic2_2]
517         #! [PySnippet_MEDCouplingMesh_fillFromAnalytic2_3]
518         vals1 = field.getArray().getTuple(1) # values of the cell #1
519         assert len( vals1 ) == 3 # 3 components in the field
520         #
521         bc = mesh.getBarycenterAndOwner() # func is applied to barycenters of cells
522         bc1 = bc.getTuple(1) # coordinates of the second point
523         #
524         dist = sqrt( bc1[0]*bc1[0] + bc1[1]*bc1[1] ) # "sqrt( a*a + b*b )"
525         self.assertAlmostEqual( vals1[0], 10 + bc1[1], 13 ) # "10 + IVec * b"
526         self.assertAlmostEqual( vals1[1], 10 + bc1[0], 13 ) # "10 + JVec * a"
527         self.assertAlmostEqual( vals1[2], 10 + dist  , 13 ) # "10 + KVec * sqrt( a*a + b*b )"
528         #! [PySnippet_MEDCouplingMesh_fillFromAnalytic2_3]
529         return
530
531     def testExample_MEDCouplingMesh_fillFromAnalytic(self):
532         #! [PySnippet_MEDCouplingMesh_fillFromAnalytic_1]
533         coords = [0.,2.,4.,6.] #  6. is not used
534         x=DataArrayDouble.New(coords[:3],3,1)
535         y=DataArrayDouble.New(coords[:2],2,1)
536         mesh=MEDCouplingCMesh.New()
537         mesh.setCoords(x,y)
538         #! [PySnippet_MEDCouplingMesh_fillFromAnalytic_1]
539         #! [PySnippet_MEDCouplingMesh_fillFromAnalytic_2]
540         func = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10"
541         field=mesh.fillFromAnalytic(ON_CELLS,3,func)
542         #! [PySnippet_MEDCouplingMesh_fillFromAnalytic_2]
543         #! [PySnippet_MEDCouplingMesh_fillFromAnalytic_3]
544         vals1 = field.getArray().getTuple(1) # values of the cell #1
545         assert len( vals1 ) == 3 # 3 components in the field
546         #
547         bc = mesh.getBarycenterAndOwner() # func is applied to barycenters of cells
548         bc1 = bc.getTuple(1) # coordinates of the second point
549         #
550         dist = sqrt( bc1[0]*bc1[0] + bc1[1]*bc1[1] ) # "sqrt( a*a + b*b )"
551         self.assertAlmostEqual( vals1[0], 10 + bc1[1], 13 ) # "10 + IVec * b"
552         self.assertAlmostEqual( vals1[1], 10 + bc1[0], 13 ) # "10 + JVec * a"
553         self.assertAlmostEqual( vals1[2], 10 + dist  , 13 ) # "10 + KVec * sqrt( a*a + b*b )"
554         #! [PySnippet_MEDCouplingMesh_fillFromAnalytic_3]
555         return
556
557     def testExample_MEDCouplingCMesh_getCoordsAt(self):
558         #! [PySnippet_MEDCouplingCMesh_getCoordsAt_1]
559         coords = [1.,2.,4.]
560         x=DataArrayDouble.New(coords,3,1)
561         mesh=MEDCouplingCMesh.New()
562         mesh.setCoordsAt(0,x)
563         x2=mesh.getCoordsAt(0)
564         assert coords == x2.getValues()
565         #! [PySnippet_MEDCouplingCMesh_getCoordsAt_1]
566         return
567
568     def testExample_MEDCouplingUMesh_areCellsIncludedIn(self):
569         #! [PySnippet_MEDCouplingUMesh_areCellsIncludedIn_1]
570         mesh1=MEDCouplingUMesh.New();
571         mesh1.setMeshDimension(2);
572         mesh1.allocateCells(5);
573         conn=[0,3,4,1, 1,2,4, 4,5,2, 6,7,4,3, 7,8,5,4];
574         mesh1.insertNextCell(NORM_QUAD4,4,conn[0:4]);   # 0
575         mesh1.insertNextCell(NORM_TRI3,3, conn[4:7]);   # 1
576         mesh1.insertNextCell(NORM_TRI3,3, conn[7:10]);  # 2
577         mesh1.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3
578         mesh1.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4
579         mesh1.finishInsertingCells();
580         coords=[-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 ];
581         coordsArr=DataArrayDouble.New();
582         coordsArr.setValues(coords,9,2);
583         mesh1.setCoords(coordsArr);
584         #! [PySnippet_MEDCouplingUMesh_areCellsIncludedIn_1]
585         #! [PySnippet_MEDCouplingUMesh_areCellsIncludedIn_2]
586         cells2 = [ 4,2,0 ]
587         mesh2 = mesh1.buildPartOfMySelf(cells2, True ) # even cells selected
588         #! [PySnippet_MEDCouplingUMesh_areCellsIncludedIn_2]
589         #! [PySnippet_MEDCouplingUMesh_areCellsIncludedIn_3]
590         compType = 0 # the strongest policy
591         isOk, corr2to1 = mesh1.areCellsIncludedIn( mesh2, compType )
592         assert isOk # a larger mesh1 includes a smaller mesh2
593         assert corr2to1.getValues() == cells2
594         #! [PySnippet_MEDCouplingUMesh_areCellsIncludedIn_3]
595         #! [PySnippet_MEDCouplingUMesh_areCellsIncludedIn_4]
596         isOk, corr1to2 = mesh2.areCellsIncludedIn( mesh1, compType )
597         assert not isOk # the smaller mesh2 does NOT include the larger mesh1
598         assert corr1to2.getValues() == [2, 3, 1, 4, 0]
599         #! [PySnippet_MEDCouplingUMesh_areCellsIncludedIn_4]
600
601     def testExample_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells(self):
602         #! [PySnippet_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells_1]
603         # 2D coordinates of 5 base nodes
604         coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2];
605         coordsArr=DataArrayDouble.New();
606         coordsArr.setValues(coords,5,2);
607         # coordinates of 5 top nodes
608         coordsArr2 = coordsArr.deepCpy()
609         # 3D coordinates of base + top nodes
610         coordsArr  = coordsArr.changeNbOfComponents( 3, 0 )
611         coordsArr2 = coordsArr2.changeNbOfComponents( 3, 1 )
612         coordsArr = DataArrayDouble.Aggregate([coordsArr,coordsArr2])
613         # mesh
614         mesh=MEDCouplingUMesh.New();
615         mesh.setCoords(coordsArr);
616         mesh.setMeshDimension(3);
617         mesh.allocateCells(2);
618         # connectivity of reversed HEXA8 and PENTA6
619         conn=[0,1,4,3, 5,6,9,8, 1,2,4, 6,7,9]
620         mesh.insertNextCell(NORM_HEXA8, 8,conn[0:0+8])
621         mesh.insertNextCell(NORM_PENTA6,6,conn[8:8+6])
622         mesh.finishInsertingCells();
623         #! [PySnippet_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells_1]
624         #! [PySnippet_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells_2]
625         fixedCells = mesh.findAndCorrectBadOriented3DExtrudedCells()
626         assert len( fixedCells ) == 2 # 2 cells fixed
627         fixedCells = mesh.findAndCorrectBadOriented3DExtrudedCells()
628         assert len( fixedCells ) == 0 # no bad cells
629         #! [PySnippet_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells_2]
630         return
631
632     def testExample_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented(self):
633         #! [PySnippet_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented_1]
634         # 2D coordinates of 5 base nodes
635         coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2];
636         coordsArr=DataArrayDouble.New();
637         coordsArr.setValues(coords,5,2);
638         # coordinates of 5 top nodes
639         coordsArr2 = coordsArr.deepCpy()
640         # 3D coordinates of base + top nodes
641         coordsArr  = coordsArr.changeNbOfComponents( 3, 0 )
642         coordsArr2 = coordsArr2.changeNbOfComponents( 3, 1 )
643         coordsArr = DataArrayDouble.Aggregate([coordsArr,coordsArr2])
644         # mesh
645         mesh=MEDCouplingUMesh.New();
646         mesh.setCoords(coordsArr);
647         mesh.setMeshDimension(3);
648         mesh.allocateCells(2);
649         # connectivity of a HEXA8 + a reversed PENTA6
650         conn=[0,3,4,1, 5,8,9,6, 1,2,4, 6,7,9]
651         mesh.insertNextCell(NORM_POLYHED, 8,conn[0:0+8]) # "extruded" polyhedron
652         mesh.insertNextCell(NORM_POLYHED,6,conn[8:8+6])
653         mesh.finishInsertingCells();
654         # fix connectivity of NORM_POLYHED's
655         mesh.convertExtrudedPolyhedra()
656         #! [PySnippet_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented_1]
657         #! [PySnippet_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented_2]
658         badCells = mesh.arePolyhedronsNotCorrectlyOriented()
659         assert len( badCells ) == 1 # one polyhedron is KO
660         # fix invalid rolyherdons
661         mesh.orientCorrectlyPolyhedrons()
662         # re-check the orientation
663         badCells = mesh.arePolyhedronsNotCorrectlyOriented()
664         assert len( badCells ) == 0 # connectivity is OK
665         #! [PySnippet_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented_2]
666         return
667
668     def testExample_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented(self):
669         #! [PySnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_1]
670         mesh=MEDCouplingUMesh.New();
671         mesh.setMeshDimension(2);
672         mesh.allocateCells(5);
673         conn=[0,3,4,1, 1,2,4, 4,5,2, 6,7,4,3, 7,8,5,4];
674         mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]);   # 0
675         mesh.insertNextCell(NORM_TRI3,3, conn[4:7]);   # 1
676         mesh.insertNextCell(NORM_TRI3,3, conn[7:10]);  # 2
677         mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3
678         mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4
679         mesh.finishInsertingCells();
680         coords=[-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 ];
681         coordsArr=DataArrayDouble.New();
682         coordsArr.setValues(coords,9,2);
683         mesh.setCoords(coordsArr);
684         mesh.changeSpaceDimension(3)
685         #! [PySnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_1]
686         #! [PySnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_2]
687         vec = [0.,0.,-1.]
688         badCellIds=mesh.are2DCellsNotCorrectlyOriented( vec, False )
689         assert len( badCellIds ) == 1 # one cell is reversed
690         # fix orientation
691         mesh.orientCorrectly2DCells( vec, False )
692         # re-check orientation
693         badCellIds=mesh.are2DCellsNotCorrectlyOriented( vec, False )
694         assert len( badCellIds ) == 0 # the orientation is OK
695         #! [PySnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_2]
696         return
697
698     def testExample_MEDCouplingUMesh_getCellsContainingPoints(self):
699         #! [PySnippet_MEDCouplingUMesh_getCellsContainingPoints_1]
700         mesh=MEDCouplingUMesh.New();
701         mesh.setMeshDimension(2);
702         mesh.allocateCells(5);
703         conn=[0,3,4,1, 1,2,4, 4,5,2, 6,7,4,3, 7,8,5,4];
704         mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]);   # 0
705         mesh.insertNextCell(NORM_TRI3,3, conn[4:7]);   # 1
706         mesh.insertNextCell(NORM_TRI3,3, conn[7:10]);  # 2
707         mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3
708         mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4
709         mesh.finishInsertingCells();
710         coords=[-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 ];
711         coordsArr=DataArrayDouble.New();
712         coordsArr.setValues(coords,9,2);
713         mesh.setCoords(coordsArr);
714         #! [PySnippet_MEDCouplingUMesh_getCellsContainingPoints_1]
715         #! [PySnippet_MEDCouplingUMesh_getCellsContainingPoints_2]
716         pos = [ 10., 10,              # point out of the mesh
717                 0.3, 0.3,             # point located somewhere inside the mesh
718                 coords[2], coords[3]] # point at the node #1
719         eps = 1e-4 # ball radius
720         cells,cellsIndex=mesh.getCellsContainingPoints( pos, 3, eps )
721         assert cells.getValues() == [4, 0, 1]
722         assert cellsIndex.getValues() == [0, 0, 1, 3]
723         #! [PySnippet_MEDCouplingUMesh_getCellsContainingPoints_2]
724         return
725
726
727     def testExample_MEDCouplingUMesh_getCellsContainingPoint(self):
728         #! [PySnippet_MEDCouplingUMesh_getCellsContainingPoint_1]
729         mesh=MEDCouplingUMesh.New();
730         mesh.setMeshDimension(2);
731         mesh.allocateCells(5);
732         conn=[0,3,4,1, 1,2,4, 4,5,2, 6,7,4,3, 7,8,5,4];
733         mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]);  
734         mesh.insertNextCell(NORM_TRI3,3, conn[4:7]);  
735         mesh.insertNextCell(NORM_TRI3,3, conn[7:10]); 
736         mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]);
737         mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]);
738         mesh.finishInsertingCells();
739         coords=[-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 ];
740         coordsArr=DataArrayDouble.New();
741         coordsArr.setValues(coords,9,2);
742         mesh.setCoords(coordsArr);
743         #! [PySnippet_MEDCouplingUMesh_getCellsContainingPoint_1]
744         #! [PySnippet_MEDCouplingUMesh_getCellsContainingPoint_2]
745         pos4 = coords[ 4*2 : ] # coordinates of the node #4
746         eps = 1e-4 # ball radius
747         pos = [ pos4[0]+eps, pos4[1]-eps ] # ball center
748         cellIds=mesh.getCellsContainingPoint( pos, eps )
749         assert len( cellIds ) == mesh.getNumberOfCells()
750         #! [PySnippet_MEDCouplingUMesh_getCellsContainingPoint_2]
751         return
752
753
754     def testExample_MEDCouplingUMesh_buildPartOrthogonalField(self):
755         #! [PySnippet_MEDCouplingUMesh_buildPartOrthogonalField_1]
756         mesh=MEDCouplingUMesh.New();
757         mesh.setMeshDimension(2);
758         mesh.allocateCells(5);
759         conn=[0,3,4,1, 1,2,4, 4,5,2, 6,7,4,3, 7,8,5,4];
760         mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]);   # 0
761         mesh.insertNextCell(NORM_TRI3,3, conn[4:7]);   # 1
762         mesh.insertNextCell(NORM_TRI3,3, conn[7:10]);  # 2
763         mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3
764         mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4
765         mesh.finishInsertingCells();
766         coords=[-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 ];
767         coordsArr=DataArrayDouble.New();
768         coordsArr.setValues(coords,9,2);
769         mesh.setCoords(coordsArr);
770         #! [PySnippet_MEDCouplingUMesh_buildPartOrthogonalField_1]
771         #! [PySnippet_MEDCouplingUMesh_buildPartOrthogonalField_2]
772         part = DataArrayInt([1,2,3,4],4,1) # cell #0 is omitted
773         vecField=mesh.buildPartOrthogonalField( part )
774         vecArr = vecField.getArray()
775         assert len( vecArr ) == len( part )
776         assert vecArr.getNumberOfComponents() == 3
777         #! [PySnippet_MEDCouplingUMesh_buildPartOrthogonalField_2]
778         return
779
780     def testExample_MEDCouplingUMesh_getPartMeasureField(self):
781         #! [PySnippet_MEDCouplingUMesh_getPartMeasureField_1]
782         mesh=MEDCouplingUMesh.New();
783         mesh.setMeshDimension(2);
784         mesh.allocateCells(5);
785         conn=[0,3,4,1, 1,2,4, 4,5,2, 6,7,4,3, 7,8,5,4];
786         mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]);   # 0
787         mesh.insertNextCell(NORM_TRI3,3, conn[4:7]);   # 1
788         mesh.insertNextCell(NORM_TRI3,3, conn[7:10]);  # 2
789         mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3
790         mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4
791         mesh.finishInsertingCells();
792         coords=[-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 ];
793         coordsArr=DataArrayDouble.New();
794         coordsArr.setValues(coords,9,2);
795         mesh.setCoords(coordsArr);
796         #! [PySnippet_MEDCouplingUMesh_getPartMeasureField_1]
797         #! [PySnippet_MEDCouplingUMesh_getPartMeasureField_2]
798         isAbs = True
799         part = DataArrayInt([1,2,3,4],4,1) # cell #0 is omitted
800         areaArr=mesh.getPartMeasureField( isAbs, part )
801         assert areaArr[0] > 0 # orientation ignored
802         areaArr=mesh.getPartMeasureField( not isAbs, part )
803         assert areaArr[0] < 0 # orientation considered
804         assert len( areaArr ) == len( part )
805         #! [PySnippet_MEDCouplingUMesh_getPartMeasureField_2]
806         #! [PySnippet_MEDCouplingUMesh_getPartMeasureField_3]
807         part = DataArrayInt([1,2,3,4],4,1) # cell #0 is omitted
808         baryCenters = mesh.getPartBarycenterAndOwner( part )
809         assert len( baryCenters ) == len( part )
810         assert baryCenters.getNumberOfComponents() == mesh.getSpaceDimension()
811         #! [PySnippet_MEDCouplingUMesh_getPartMeasureField_3]
812         return
813
814     def testExample_MEDCouplingUMesh_getCellsInBoundingBox(self):
815         #! [PySnippet_MEDCouplingUMesh_getCellsInBoundingBox_1]
816         mesh=MEDCouplingUMesh.New();
817         mesh.setMeshDimension(2);
818         coords=[0.,0., 0.,1., 1.,1];
819         coordsArr=DataArrayDouble.New();
820         coordsArr.setValues(coords,3,2);
821         mesh.setCoords(coordsArr);
822         mesh.allocateCells(1);
823         conn=[0,1,2];
824         mesh.insertNextCell(NORM_TRI3,3,conn);
825         mesh.finishInsertingCells();
826         #! [PySnippet_MEDCouplingUMesh_getCellsInBoundingBox_1]
827         #! [PySnippet_MEDCouplingUMesh_getCellsInBoundingBox_2]
828         bbox = [1., 1., 1.001,1.001] # xMin, xMax, yMin, yMax
829         cellsInBox = mesh.getCellsInBoundingBox( bbox, 0.0 )
830         assert cellsInBox.getValues() == []
831         cellsInBox = mesh.getCellsInBoundingBox( bbox, 0.1 )
832         assert cellsInBox.getValues() == [0]
833         #! [PySnippet_MEDCouplingUMesh_getCellsInBoundingBox_2]
834
835
836     def testExample_MEDCouplingUMesh_renumberNodesInConn(self):
837         #! [PySnippet_MEDCouplingUMesh_renumberNodesInConn_1]
838         mesh=MEDCouplingUMesh.New();
839         mesh.setMeshDimension(2);
840         mesh.allocateCells(1);
841         conn=[4,3,2,1];
842         mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]);
843         mesh.finishInsertingCells();
844         #! [PySnippet_MEDCouplingUMesh_renumberNodesInConn_1]
845         #! [PySnippet_MEDCouplingUMesh_renumberNodesInConn_2]
846         old2newIds = [-1,3,2,1,0]
847         mesh.renumberNodesInConn( old2newIds )
848         nodes0 = mesh.getNodeIdsOfCell( 0 )
849         assert nodes0 == [0,1,2,3]
850         #! [PySnippet_MEDCouplingUMesh_renumberNodesInConn_2]
851         return
852
853
854     def testExample_MEDCouplingUMesh_renumberNodes(self):
855         #! [PySnippet_MEDCouplingUMesh_renumberNodes_1]
856         mesh=MEDCouplingUMesh.New();
857         mesh.setMeshDimension(2);
858         coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.3];
859         coordsArr=DataArrayDouble.New();
860         coordsArr.setValues(coords,4,2);
861         mesh.setCoords(coordsArr);
862         mesh.allocateCells(0);
863         mesh.finishInsertingCells();
864         #! [PySnippet_MEDCouplingUMesh_renumberNodes_1]
865         #! [PySnippet_MEDCouplingUMesh_renumberNodes_2]
866         mesh.renumberNodes([ 2,1,0,-1 ], 3);
867         coordsArr = mesh.getCoords() # get a shorten array
868         assert coordsArr.getValues() == [0.7,-0.3, 0.2,-0.3, -0.3,-0.3]
869         #! [PySnippet_MEDCouplingUMesh_renumberNodes_2]
870         #! [PySnippet_MEDCouplingUMesh_renumberNodes_3]
871         coordsArr.setValues(coords,4,2); # restore old nodes
872         mesh.renumberNodes2([ 2,1,0,2 ], 3);
873         coordsArr = mesh.getCoords() # get a shorten array
874         assert coordsArr.getValues() == [0.7,-0.3, 0.2,-0.3, -0.3,0.0]
875         #! [PySnippet_MEDCouplingUMesh_renumberNodes_3]
876         return
877
878     def testExample_MEDCouplingUMesh_findBoundaryNodes(self):
879         #! [PySnippet_MEDCouplingUMesh_findBoundaryNodes_1]
880         mesh=MEDCouplingUMesh.New();
881         mesh.setMeshDimension(2);
882         mesh.allocateCells(5);
883         conn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
884         mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]);  
885         mesh.insertNextCell(NORM_TRI3,3, conn[4:7]);  
886         mesh.insertNextCell(NORM_TRI3,3, conn[7:10]); 
887         mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]);
888         mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]);
889         mesh.finishInsertingCells();
890         coords=[-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 ];
891         coordsArr=DataArrayDouble.New();
892         coordsArr.setValues(coords,9,2);
893         mesh.setCoords(coordsArr);
894         #! [PySnippet_MEDCouplingUMesh_findBoundaryNodes_1]
895         #! [PySnippet_MEDCouplingUMesh_findBoundaryNodes_2]
896         nodeIdsArr=mesh.findBoundaryNodes()
897         assert nodeIdsArr.getNumberOfTuples() == mesh.getNumberOfNodes() - 1 
898         #! [PySnippet_MEDCouplingUMesh_findBoundaryNodes_2]
899         return
900
901     def testExample_MEDCouplingUMesh_buildBoundaryMesh(self):
902         #! [PySnippet_MEDCouplingUMesh_buildBoundaryMesh_1]
903         mesh=MEDCouplingUMesh.New();
904         mesh.setMeshDimension(2);
905         mesh.allocateCells(5);
906         conn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
907         mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]);  
908         mesh.insertNextCell(NORM_TRI3,3, conn[4:7]);  
909         mesh.insertNextCell(NORM_TRI3,3, conn[7:10]); 
910         mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]);
911         mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]);
912         mesh.finishInsertingCells();
913         coords=[-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 ];
914         coordsArr=DataArrayDouble.New();
915         coordsArr.setValues(coords,9,2);
916         mesh.setCoords(coordsArr);
917         #! [PySnippet_MEDCouplingUMesh_buildBoundaryMesh_1]
918         #! [PySnippet_MEDCouplingUMesh_buildBoundaryMesh_2]
919         mesh1=mesh.buildBoundaryMesh(True)
920         mesh2=mesh.buildBoundaryMesh(False)
921         assert coordsArr.isEqual( mesh1.getCoords(), 1e-13 )  # same nodes
922         assert not coordsArr.isEqual( mesh2.getCoords(), 1e-13 ) # different nodes
923         #! [PySnippet_MEDCouplingUMesh_buildBoundaryMesh_2]
924         return
925
926     def testExample_MEDCouplingUMesh_buildFacePartOfMySelfNode(self):
927         #! [PySnippet_MEDCouplingUMesh_buildFacePartOfMySelfNode_1]
928         mesh=MEDCouplingUMesh.New();
929         mesh.setMeshDimension(2);
930         mesh.allocateCells(5);
931         conn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
932         mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]);   # 0
933         mesh.insertNextCell(NORM_TRI3,3, conn[4:7]);   # 1
934         mesh.insertNextCell(NORM_TRI3,3, conn[7:10]);  # 2
935         mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3
936         mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4
937         mesh.finishInsertingCells();
938         coords=[-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 ];
939         coordsArr=DataArrayDouble.New();
940         coordsArr.setValues(coords,9,2);
941         mesh.setCoords(coordsArr);
942         #! [PySnippet_MEDCouplingUMesh_buildFacePartOfMySelfNode_1]
943         #! [PySnippet_MEDCouplingUMesh_buildFacePartOfMySelfNode_2]
944         nodeIds = mesh.getNodeIdsOfCell( 0 )
945         allNodes = True
946         mesh1 = mesh.buildFacePartOfMySelfNode( nodeIds, allNodes )
947         assert mesh1.getNumberOfCells() == 4 # 4 segments bounding QUAD4 #0 only
948         mesh2 = mesh.buildFacePartOfMySelfNode( nodeIds, not allNodes )
949         assert mesh2.getNumberOfCells() >  4 # more segments added
950         #! [PySnippet_MEDCouplingUMesh_buildFacePartOfMySelfNode_2]
951         return
952
953
954     def testExample_MEDCouplingUMesh_buildPartOfMySelfNode(self):
955         #! [PySnippet_MEDCouplingUMesh_buildPartOfMySelfNode_1]
956         mesh=MEDCouplingUMesh.New();
957         mesh.setMeshDimension(2);
958         mesh.allocateCells(5);
959         conn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
960         mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]);   # 0
961         mesh.insertNextCell(NORM_TRI3,3, conn[4:7]);   # 1
962         mesh.insertNextCell(NORM_TRI3,3, conn[7:10]);  # 2
963         mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3
964         mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4
965         mesh.finishInsertingCells();
966         coords=[-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 ];
967         coordsArr=DataArrayDouble.New();
968         coordsArr.setValues(coords,9,2);
969         mesh.setCoords(coordsArr);
970         #! [PySnippet_MEDCouplingUMesh_buildPartOfMySelfNode_1]
971         #! [PySnippet_MEDCouplingUMesh_buildPartOfMySelfNode_2]
972         nodeIds = mesh.getNodeIdsOfCell( 0 )
973         allNodes = True
974         mesh1 = mesh.buildPartOfMySelfNode( nodeIds, allNodes )
975         mesh2 = mesh.buildPartOfMySelfNode( nodeIds, not allNodes )
976         assert mesh1.getNumberOfCells() == 1 # cell #0 is found only
977         assert mesh2.getNumberOfCells() == mesh.getNumberOfCells() # all cells are found
978         #! [PySnippet_MEDCouplingUMesh_buildPartOfMySelfNode_2]
979         return
980
981
982     def testExample_MEDCouplingUMesh_getCellIdsLyingOnNodes(self):
983         #! [PySnippet_MEDCouplingUMesh_getCellIdsLyingOnNodes_1]
984         mesh=MEDCouplingUMesh.New();
985         mesh.setMeshDimension(2);
986         mesh.allocateCells(5);
987         conn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
988         mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]);   # 0
989         mesh.insertNextCell(NORM_TRI3,3, conn[4:7]);   # 1
990         mesh.insertNextCell(NORM_TRI3,3, conn[7:10]);  # 2
991         mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3
992         mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4
993         mesh.finishInsertingCells();
994         coords=[-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 ];
995         coordsArr=DataArrayDouble.New();
996         coordsArr.setValues(coords,9,2);
997         mesh.setCoords(coordsArr);
998         #! [PySnippet_MEDCouplingUMesh_getCellIdsLyingOnNodes_1]
999         #! [PySnippet_MEDCouplingUMesh_getCellIdsLyingOnNodes_2]
1000         nodeIds = mesh.getNodeIdsOfCell( 0 )
1001         allNodes = True
1002         cellIdsArr1 = mesh.getCellIdsLyingOnNodes( nodeIds, allNodes )
1003         cellIdsArr2 = mesh.getCellIdsLyingOnNodes( nodeIds, not allNodes )
1004         assert cellIdsArr1.getNumberOfTuples() == 1 # cell #0 is found only
1005         assert cellIdsArr2.getNumberOfTuples() == mesh.getNumberOfCells() # all cells are found
1006         #! [PySnippet_MEDCouplingUMesh_getCellIdsLyingOnNodes_2]
1007         return
1008
1009
1010     def testExample_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds(self):
1011         #! [PySnippet_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds_1]
1012         mesh=MEDCouplingUMesh.New();
1013         mesh.setMeshDimension(2);
1014         mesh.allocateCells(5);
1015         conn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
1016         mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]);  
1017         mesh.insertNextCell(NORM_TRI3,3, conn[4:7]);  
1018         mesh.insertNextCell(NORM_TRI3,3, conn[7:10]); 
1019         mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]);
1020         mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]);
1021         mesh.finishInsertingCells();
1022         coords=[-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 ];
1023         coordsArr=DataArrayDouble.New();
1024         coordsArr.setValues(coords,9,2);
1025         mesh.setCoords(coordsArr);
1026         #! [PySnippet_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds_1]
1027         #! [PySnippet_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds_2]
1028         cellIds = [1,2]
1029         nodeIds =  mesh.getNodeIdsOfCell( cellIds[0] )
1030         nodeIds += mesh.getNodeIdsOfCell( cellIds[1] )
1031         cellIdsArr = mesh.getCellIdsFullyIncludedInNodeIds( nodeIds )
1032         assert cellIdsArr.getValues() == cellIds
1033         #! [PySnippet_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds_2]
1034         return
1035
1036
1037     def testExample_MEDCouplingUMesh_buildPartOfMySelf(self):
1038         #! [PySnippet_MEDCouplingUMesh_buildPartOfMySelf_1]
1039         mesh=MEDCouplingUMesh.New();
1040         mesh.setMeshDimension(2);
1041         mesh.allocateCells(5);
1042         conn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
1043         mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]);   # 0
1044         mesh.insertNextCell(NORM_TRI3,3, conn[4:7]);   # 1
1045         mesh.insertNextCell(NORM_TRI3,3, conn[7:10]);  # 2
1046         mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3
1047         mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4
1048         mesh.finishInsertingCells();
1049         coords=[-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 ];
1050         coordsArr=DataArrayDouble.New();
1051         coordsArr.setValues(coords,9,2);
1052         mesh.setCoords(coordsArr);
1053         #! [PySnippet_MEDCouplingUMesh_buildPartOfMySelf_1]
1054         #! [PySnippet_MEDCouplingUMesh_buildPartOfMySelf_2]
1055         cellIds=[1,2]
1056         mesh2=mesh.buildPartOfMySelf(cellIds, True)
1057         mesh3=mesh.buildPartOfMySelf(cellIds, False)
1058         coordsArr2 = mesh2.getCoords()
1059         assert coordsArr.isEqual( coordsArr2, 1e-13 )  # same nodes
1060         coordsArr3 = mesh3.getCoords()
1061         assert not coordsArr.isEqual( coordsArr3, 1e-13 ) # different nodes
1062         assert mesh2.getNodeIdsOfCell(0) == mesh.getNodeIdsOfCell( cellIds[0]) # cell #1 was copied
1063         assert mesh2.getNodeIdsOfCell(1) == mesh.getNodeIdsOfCell( cellIds[1]) # cell #2 was copied
1064         #! [PySnippet_MEDCouplingUMesh_buildPartOfMySelf_2]
1065         return
1066
1067     def testExample_MEDCouplingUMesh_mergeNodes(self):
1068         #! [PySnippet_MEDCouplingUMesh_mergeNodes_1]
1069         mesh=MEDCouplingUMesh.New();
1070         mesh.setMeshDimension(2);
1071         mesh.allocateCells(5);
1072         conn=[0,3,4,1, 1,4,2, 4,5,2];
1073         mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]); 
1074         mesh.insertNextCell(NORM_TRI3,3, conn[4:7]); 
1075         mesh.insertNextCell(NORM_TRI3,3, conn[7:10]);
1076         mesh.finishInsertingCells();
1077         coords=[0.3,-0.301, # 0
1078                 0.2,-0.3,   # 1
1079                 0.3,-0.302, # 2 ~~ 0
1080                 1.1,0.0,    # 3
1081                 1.1,0.0,    # 4 == 3
1082                 0.3,-0.303];# 5 ~~ 0
1083         coordsArr=DataArrayDouble.New();
1084         coordsArr.setValues(coords,6,2);
1085         mesh.setCoords(coordsArr);
1086         #! [PySnippet_MEDCouplingUMesh_mergeNodes_1]
1087         #! [PySnippet_MEDCouplingUMesh_mergeNodes_2]
1088         arr,areNodesMerged,newNbOfNodes=mesh.mergeNodes(0.004)
1089         assert arr.getValues() == [0, 1, 0, 2, 2, 0]
1090         assert areNodesMerged
1091         assert newNbOfNodes == 3
1092         #! [PySnippet_MEDCouplingUMesh_mergeNodes_2]
1093         #! [PySnippet_MEDCouplingUMesh_mergeNodes_3]
1094         baryCoords2 = coords[2*2:] # initial coordinates of node #2
1095         coordsArr = mesh.getCoords() # retrieve a new shorten coord array
1096         self.assertNotAlmostEqual( baryCoords2[1], coordsArr.getIJ(0,1), 13 ) # Y of node #0 differs from that of baryCoords2
1097         # restore coordinates
1098         coordsArr = DataArrayDouble(coords,6,2);
1099         mesh.setCoords(coordsArr);
1100         # call mergeNodes2()
1101         mesh.mergeNodes2(0.004)
1102         coordsArr = mesh.getCoords() # retrieve a new shorten coord array
1103         self.assertAlmostEqual( baryCoords2[1], coordsArr.getIJ(0,1), 13 ) # Y of node #0 equals to that of baryCoords2
1104         #! [PySnippet_MEDCouplingUMesh_mergeNodes_3]
1105         return
1106
1107     def testExample_MEDCouplingUMesh_zipConnectivityTraducer(self):
1108         #! [PySnippet_MEDCouplingUMesh_zipConnectivityTraducer_1]
1109         mesh=MEDCouplingUMesh.New();
1110         mesh.setMeshDimension(2);
1111         mesh.allocateCells(5);
1112         conn=[0,3,4,1, 1,4,2];
1113         mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]);           # 0
1114         mesh.insertNextCell(NORM_TRI3,3, conn[4:7]);           # 1
1115         mesh.insertNextCell(NORM_TRI3,3, conn[4:7]);           # 2 == 1
1116         mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]);           # 3 == 0
1117         mesh.insertNextCell(NORM_QUAD4,4,conn[2:4]+conn[0:2]); # 4 ~~ 0
1118         mesh.finishInsertingCells();
1119         coords=[-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 ];
1120         coordsArr=DataArrayDouble.New();
1121         coordsArr.setValues(coords,9,2);
1122         mesh.setCoords(coordsArr);
1123         #! [PySnippet_MEDCouplingUMesh_zipConnectivityTraducer_1]
1124         #! [PySnippet_MEDCouplingUMesh_zipConnectivityTraducer_2]
1125         oldNbCells = mesh.getNumberOfCells()
1126         arr = mesh.zipConnectivityTraducer(0)
1127         assert mesh.getNumberOfCells() == oldNbCells-2
1128         assert arr.getValues() == [0, 1, 1, 0, 2]
1129         #! [PySnippet_MEDCouplingUMesh_zipConnectivityTraducer_2]
1130         return
1131
1132     def testExample_MEDCouplingUMesh_zipCoordsTraducer(self):
1133         #! [PySnippet_MEDCouplingUMesh_zipCoordsTraducer_1]
1134         mesh=MEDCouplingUMesh.New();
1135         mesh.setMeshDimension(2);
1136         mesh.allocateCells(5);
1137         conn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
1138         mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]);  
1139         mesh.insertNextCell(NORM_TRI3,3, conn[4:7]);  
1140         mesh.insertNextCell(NORM_TRI3,3, conn[7:10]); 
1141         mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]);
1142         mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]);
1143         mesh.finishInsertingCells();
1144         coords=[-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 ];
1145         coordsArr=DataArrayDouble.New();
1146         coordsArr.setValues(coords,9,2);
1147         mesh.setCoords(coordsArr);
1148         #! [PySnippet_MEDCouplingUMesh_zipCoordsTraducer_1]
1149         #! [PySnippet_MEDCouplingUMesh_zipCoordsTraducer_2]
1150         cellIds=[1,2]
1151         mesh2=mesh.buildPartOfMySelf(cellIds,True);
1152         arr=mesh2.zipCoordsTraducer();
1153         assert mesh2.getNumberOfNodes() == 4 # nb of nodes decreased
1154         assert arr.getValues() == [-1,0,1,-1,2,3,-1,-1,-1] # -1 for unused nodes
1155         #! [PySnippet_MEDCouplingUMesh_zipCoordsTraducer_2]
1156         return
1157
1158     def testExample_MEDCouplingUMesh_getNodeIdsInUse(self):
1159         #! [PySnippet_MEDCouplingUMesh_getNodeIdsInUse_1]
1160         mesh=MEDCouplingUMesh.New();
1161         mesh.setMeshDimension(2);
1162         mesh.allocateCells(5);
1163         conn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
1164         mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]);  
1165         mesh.insertNextCell(NORM_TRI3,3, conn[4:7]);  
1166         mesh.insertNextCell(NORM_TRI3,3, conn[7:10]); 
1167         mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]);
1168         mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]);
1169         mesh.finishInsertingCells();
1170         coords=[-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 ];
1171         coordsArr=DataArrayDouble.New();
1172         coordsArr.setValues(coords,9,2);
1173         mesh.setCoords(coordsArr);
1174         #! [PySnippet_MEDCouplingUMesh_getNodeIdsInUse_1]
1175         #! [PySnippet_MEDCouplingUMesh_getNodeIdsInUse_2]
1176         cellIds=[1,2]
1177         mesh2=mesh.buildPartOfMySelf(cellIds,True);
1178         arr,newNbOfNodes=mesh2.getNodeIdsInUse();
1179         assert arr.getValues() == [-1,0,1,-1,2,3,-1,-1,-1]
1180         #! [PySnippet_MEDCouplingUMesh_getNodeIdsInUse_2]
1181         #! [PySnippet_MEDCouplingUMesh_getNodeIdsInUse_3]
1182         arr2=arr.invertArrayO2N2N2O(newNbOfNodes);
1183         assert arr2.getValues() == [1,2,4,5]
1184         #! [PySnippet_MEDCouplingUMesh_getNodeIdsInUse_3]
1185         return
1186
1187     def testExample_MEDCouplingUMesh_convertToPolyTypes(self):
1188         #! [PySnippet_MEDCouplingUMesh_convertToPolyTypes_1]
1189         mesh=MEDCouplingUMesh.New();
1190         mesh.setMeshDimension(2);
1191         mesh.allocateCells(5);
1192         conn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
1193         mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]);   # 0
1194         mesh.insertNextCell(NORM_TRI3,3, conn[4:7]);   # 1
1195         mesh.insertNextCell(NORM_TRI3,3, conn[7:10]);  # 2
1196         mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3
1197         mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4
1198         mesh.finishInsertingCells();
1199         coords=[-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 ];
1200         coordsArr=DataArrayDouble.New();
1201         coordsArr.setValues(coords,9,2);
1202         mesh.setCoords(coordsArr);
1203         #! [PySnippet_MEDCouplingUMesh_convertToPolyTypes_1]
1204         #! [PySnippet_MEDCouplingUMesh_convertToPolyTypes_2]
1205         cells=[1,3];
1206         mesh.convertToPolyTypes(cells);
1207         assert mesh.getTypeOfCell(0) == NORM_QUAD4
1208         assert mesh.getTypeOfCell(1) == NORM_POLYGON, mesh.getTypeOfCell(1)
1209         assert mesh.getTypeOfCell(2) == NORM_TRI3
1210         assert mesh.getTypeOfCell(3) == NORM_POLYGON
1211         #! [PySnippet_MEDCouplingUMesh_convertToPolyTypes_2]
1212         return
1213
1214     def testExample_MEDCouplingUMesh_buildDescendingConnectivity2(self):
1215         #! [PySnippet_MEDCouplingUMesh_buildDescendingConnectivity2_1]
1216         mesh=MEDCouplingUMesh.New();
1217         mesh.setMeshDimension(2);
1218         mesh.allocateCells(5);
1219         conn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
1220         mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]);   # 0
1221         mesh.insertNextCell(NORM_TRI3,3, conn[4:7]);   # 1
1222         mesh.insertNextCell(NORM_TRI3,3, conn[7:10]);  # 2
1223         mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3
1224         mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4
1225         mesh.finishInsertingCells();
1226         coords=[-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 ];
1227         coordsArr=DataArrayDouble.New();
1228         coordsArr.setValues(coords,9,2);
1229         mesh.setCoords(coordsArr);
1230         #! [PySnippet_MEDCouplingUMesh_buildDescendingConnectivity2_1]
1231         #! [PySnippet_MEDCouplingUMesh_buildDescendingConnectivity2_2]
1232         desc=DataArrayInt.New();
1233         descIndx=DataArrayInt.New();
1234         revDesc=DataArrayInt.New();
1235         revDescIndx=DataArrayInt.New();
1236         mesh2=mesh.buildDescendingConnectivity2(desc,descIndx,revDesc,revDescIndx);
1237         assert desc.getValues()        == [1,2,3,4,-3,5,6, 7,8,-5,9,10,-2,11, 12,13,-7,-10]
1238         assert descIndx.getValues()    == [0,4,7,10,14,18]
1239         assert revDesc.getValues()     == [0, 0,3, 0,1, 0, 1,2, 1, 2,4, 2, 3, 3,4, 3, 4, 4]
1240         assert revDescIndx.getValues() == [0,1,3,5,6,8,9,11,12,13,15,16,17,18]
1241         #! [PySnippet_MEDCouplingUMesh_buildDescendingConnectivity2_2]
1242         #! [PySnippet_MEDCouplingUMesh_buildDescendingConnectivity2_3]
1243         assert mesh2.getNodeIdsOfCell( 3-1 ) == [4, 1]  # cell #3 in FORTRAN mode
1244         #! [PySnippet_MEDCouplingUMesh_buildDescendingConnectivity2_3]
1245         return
1246
1247     def testExample_MEDCouplingUMesh_buildDescendingConnectivity(self):
1248         #! [PySnippet_MEDCouplingUMesh_buildDescendingConnectivity_1]
1249         mesh=MEDCouplingUMesh.New();
1250         mesh.setMeshDimension(2);
1251         mesh.allocateCells(5);
1252         conn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
1253         mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]);   # 0
1254         mesh.insertNextCell(NORM_TRI3,3, conn[4:7]);   # 1
1255         mesh.insertNextCell(NORM_TRI3,3, conn[7:10]);  # 2
1256         mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3
1257         mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4
1258         mesh.finishInsertingCells();
1259         coords=[-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 ];
1260         coordsArr=DataArrayDouble.New();
1261         coordsArr.setValues(coords,9,2);
1262         mesh.setCoords(coordsArr);
1263         #! [PySnippet_MEDCouplingUMesh_buildDescendingConnectivity_1]
1264         #! [PySnippet_MEDCouplingUMesh_buildDescendingConnectivity_2]
1265         desc=DataArrayInt.New();
1266         descIndx=DataArrayInt.New();
1267         revDesc=DataArrayInt.New();
1268         revDescIndx=DataArrayInt.New();
1269         mesh2=mesh.buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
1270         assert desc.getValues()        == [0,1,2,3, 2,4,5, 6,7,4, 8,9,1,10, 11,12,6,9]
1271         assert descIndx.getValues()    == [0,4,7,10,14,18]
1272         assert revDesc.getValues()     == [0, 0,3, 0,1, 0, 1,2, 1, 2,4, 2, 3, 3,4, 3, 4, 4]
1273         assert revDescIndx.getValues() == [0,1,3,5,6,8,9,11,12,13,15,16,17,18]
1274         #! [PySnippet_MEDCouplingUMesh_buildDescendingConnectivity_2]
1275         return
1276
1277     def testExample_MEDCouplingUMesh_getReverseNodalConnectivity(self):
1278         #! [PySnippet_MEDCouplingUMesh_getReverseNodalConnectivity_1]
1279         mesh=MEDCouplingUMesh.New();
1280         mesh.setMeshDimension(2);
1281         mesh.allocateCells(5);
1282         conn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
1283         mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]);   # 0
1284         mesh.insertNextCell(NORM_TRI3,3, conn[4:7]);   # 1
1285         mesh.insertNextCell(NORM_TRI3,3, conn[7:10]);  # 2
1286         mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3
1287         mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4
1288         mesh.finishInsertingCells();
1289         coords=[-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 ];
1290         coordsArr=DataArrayDouble.New();
1291         coordsArr.setValues(coords,9,2);
1292         mesh.setCoords(coordsArr);
1293         #! [PySnippet_MEDCouplingUMesh_getReverseNodalConnectivity_1]
1294         #! [PySnippet_MEDCouplingUMesh_getReverseNodalConnectivity_2]
1295         revNodal,revNodalIndx=mesh.getReverseNodalConnectivity();
1296         assert revNodal.getValues()     == [0,0,1,1,2,0,3,0,1,2,3,4,2,4,3,3,4,4];
1297         assert revNodalIndx.getValues() == [0,1,3,5,7,12,14,15,17,18];
1298         #! [PySnippet_MEDCouplingUMesh_getReverseNodalConnectivity_2]
1299         return
1300
1301     def testExample_MEDCouplingUMesh_checkDeepEquivalWith(self):
1302         #! [PySnippet_MEDCouplingUMesh_checkDeepEquivalWith_1]
1303         # mesh 1
1304         mesh1=MEDCouplingUMesh.New();
1305         mesh1.setMeshDimension(2);
1306         coords=[0.0,0.0, #0
1307                 1.0,0.0, #1
1308                 1.0,1.0, #2
1309                 0.0,1.0] #3
1310         coordsArr=DataArrayDouble.New(coords,4,2);
1311         mesh1.setCoords(coordsArr);
1312         mesh1.allocateCells(2);
1313         mesh1.insertNextCell(NORM_TRI3,3,[0,1,2]); #0
1314         mesh1.insertNextCell(NORM_TRI3,3,[1,2,3]); #1
1315         mesh1.finishInsertingCells();
1316         # mesh 2
1317         mesh2=MEDCouplingUMesh.New();
1318         mesh2.setMeshDimension(2);
1319         coords=[0.0,1.0,    #0 = #3
1320                 0.0,0.0,    #1 = #0
1321                 1.0,0.0,    #2 = #1
1322                 1.0,1.001]  #3 ~ #2
1323         coordsArr2=DataArrayDouble.New(coords,4,2)
1324         mesh2.setCoords(coordsArr2);
1325         mesh2.allocateCells(2);
1326         mesh2.insertNextCell(NORM_TRI3,3,[2,3,0]); #0 = #1
1327         mesh2.insertNextCell(NORM_TRI3,3,[3,1,2]); #1 ~ #0
1328         mesh2.finishInsertingCells();
1329         #! [PySnippet_MEDCouplingUMesh_checkDeepEquivalWith_1]
1330         #! [PySnippet_MEDCouplingUMesh_checkDeepEquivalWith_2]
1331         cellCompPol = 1 # "permuted same orientation" - policy of medium severity
1332         cOld2New, nOld2New = mesh1.checkDeepEquivalWith( mesh2, cellCompPol, 0.002 )
1333         assert nOld2New.getValues() == [3, 0, 1, 2]
1334         assert cOld2New.getValues() == [1, 0]
1335         #! [PySnippet_MEDCouplingUMesh_checkDeepEquivalWith_2]
1336         #! [PySnippet_MEDCouplingUMesh_checkDeepEquivalWith_3]
1337         self.assertRaises( InterpKernelException, mesh1.checkDeepEquivalOnSameNodesWith, mesh2, cellCompPol, 0.002)
1338         mesh2.setCoords(coordsArr) # make meshes share the same coordinates array
1339         mesh2.allocateCells(2);
1340         mesh2.insertNextCell(NORM_TRI3,3,[1,2,3]); #0 = #1
1341         mesh2.insertNextCell(NORM_TRI3,3,[1,0,2]); #1 ~ #0
1342         mesh2.finishInsertingCells();
1343         cellCompPol = 2 # the weakest policy
1344         mesh1.checkDeepEquivalOnSameNodesWith( mesh2, cellCompPol, 0 )
1345         #! [PySnippet_MEDCouplingUMesh_checkDeepEquivalWith_3]
1346         return
1347
1348     def testExample_MEDCouplingPointSet_scale(self):
1349         #! [PySnippet_MEDCouplingPointSet_scale_1]
1350         coords=[0.0,0.0, 1.0,0.0, 1.0,1.0, 0.0,1.0] # 2D coordinates of 4 nodes
1351         coordsArr=DataArrayDouble.New();
1352         coordsArr.setValues(coords,4,2);
1353         mesh=MEDCouplingUMesh.New();
1354         mesh.setCoords(coordsArr);
1355         initCoords = coordsArr.deepCpy()
1356         #! [PySnippet_MEDCouplingPointSet_scale_1]
1357         #! [PySnippet_MEDCouplingPointSet_scale_2]
1358         center = [0.,0.]
1359         factor = 2.
1360         mesh.scale(center,factor)
1361         #! [PySnippet_MEDCouplingPointSet_scale_2]
1362         #! [PySnippet_MEDCouplingPointSet_scale_3]
1363         coords2 = mesh.getCoords()
1364         assert coords2.isEqualWithoutConsideringStr( initCoords, 1.0 )
1365         assert not coords2.isEqualWithoutConsideringStr( initCoords, 0.9 )
1366         #! [PySnippet_MEDCouplingPointSet_scale_3]
1367         return
1368
1369     def testExample_MEDCouplingPointSet_translate(self):
1370         #! [PySnippet_MEDCouplingPointSet_translate_1]
1371         coords=[0.0,0.0, 1.0,0.0, 1.0,1.0, 0.0,1.0] # 2D coordinates of 4 nodes
1372         coordsArr=DataArrayDouble.New();
1373         coordsArr.setValues(coords,4,2);
1374         mesh=MEDCouplingUMesh.New();
1375         mesh.setCoords(coordsArr);
1376         initCoords = coordsArr.deepCpy()
1377         #! [PySnippet_MEDCouplingPointSet_translate_1]
1378         #! [PySnippet_MEDCouplingPointSet_translate_2]
1379         vector = [1.,1.]
1380         mesh.translate(vector)
1381         #! [PySnippet_MEDCouplingPointSet_translate_2]
1382         #! [PySnippet_MEDCouplingPointSet_translate_3]
1383         coords2 = mesh.getCoords()
1384         assert coords2.isEqualWithoutConsideringStr( initCoords, 1 )
1385         assert not coords2.isEqualWithoutConsideringStr( initCoords, 0.9 )
1386         #! [PySnippet_MEDCouplingPointSet_translate_3]
1387         return
1388
1389     def testExample_MEDCouplingPointSet_rotate(self):
1390         #! [PySnippet_MEDCouplingPointSet_rotate_1]
1391         coords=[0.0,0.0, 0.1,0.0, 0.1,0.1, 0.0,0.1] # 2D coordinates of 4 nodes
1392         coordsArr=DataArrayDouble.New();
1393         coordsArr.setValues(coords,4,2);
1394         mesh=MEDCouplingUMesh.New();
1395         mesh.setCoords(coordsArr);
1396         #! [PySnippet_MEDCouplingPointSet_rotate_1]
1397         #! [PySnippet_MEDCouplingPointSet_rotate_2]
1398         center = [0.,0.]
1399         mesh.rotate(center,-pi/2)
1400         #! [PySnippet_MEDCouplingPointSet_rotate_2]
1401         #! [PySnippet_MEDCouplingPointSet_rotate_3]
1402         mesh.changeSpaceDimension(3)
1403         center = [0.,0.,0.]
1404         vector = [0.,0.,1.]
1405         mesh.rotate(center,vector,pi/2)
1406         #! [PySnippet_MEDCouplingPointSet_rotate_3]
1407         #! [PySnippet_MEDCouplingPointSet_rotate_4]
1408         mesh.changeSpaceDimension(2)
1409         coords2 = mesh.getCoords()
1410         for i,c in enumerate( coords ):
1411             self.assertAlmostEqual( c, coords2.getIJ(0,i), 13 )
1412         #! [PySnippet_MEDCouplingPointSet_rotate_4]
1413         return
1414
1415     def testExample_MEDCouplingPointSet_getBoundingBox(self):
1416         #! [PySnippet_MEDCouplingPointSet_getBoundingBox_1]
1417         cc=[0.0, 0.1, 0.2, # 3D coordinates of 2 nodes
1418             2.0, 2.1, 2.2]
1419         coordsArr=DataArrayDouble.New();
1420         coordsArr.setValues(cc,2,3);
1421         mesh=MEDCouplingUMesh.New();
1422         mesh.setCoords(coordsArr);
1423         #! [PySnippet_MEDCouplingPointSet_getBoundingBox_1]
1424         #! [PySnippet_MEDCouplingPointSet_getBoundingBox_2]
1425         bbox=mesh.getBoundingBox()
1426         assert bbox == [( cc[0], cc[3] ), # NOTE: list of 3 tuples is retirned!
1427                         ( cc[1], cc[4] ),
1428                         ( cc[2], cc[5] )]
1429         #! [PySnippet_MEDCouplingPointSet_getBoundingBox_2]
1430
1431     def testExample_MEDCouplingPointSet_getNodeIdsNearPoint(self):
1432         #! [PySnippet_MEDCouplingPointSet_getNodeIdsNearPoint_1]
1433         # 2D coordinates of 5 nodes
1434         coords=[0.3,-0.301, # 0
1435                 0.2,-0.3,   # 1
1436                 0.3,-0.302, # 2
1437                 1.1,0.0,    # 3
1438                 0.3,-0.30299999999999];# 4
1439         coordsArr=DataArrayDouble.New();
1440         coordsArr.setValues(coords,5,2);
1441         mesh=MEDCouplingUMesh.New();
1442         mesh.setCoords(coordsArr);
1443         #! [PySnippet_MEDCouplingPointSet_getNodeIdsNearPoint_1]
1444         #! [PySnippet_MEDCouplingPointSet_getNodeIdsNearPoint_2]
1445         point=[0.3, -0.3]   # point close to nodes #0, #2 and #4
1446         ids=mesh.getNodeIdsNearPoint(point,0.003);
1447         assert ids.getValues() == [0,2,4]
1448         #! [PySnippet_MEDCouplingPointSet_getNodeIdsNearPoint_2]
1449         return
1450
1451     def testExample_MEDCouplingPointSet_getNodeIdsNearPoints(self):
1452         #! [PySnippet_MEDCouplingPointSet_getNodeIdsNearPoints_1]
1453         # 2D coordinates of 7 nodes
1454         coords=[0.3,-0.301, # 0
1455                 0.2,-0.3,   # 1
1456                 0.3,-0.302, # 2
1457                 1.1,0.0,    # 3
1458                 1.1,0.0,    # 4
1459                 1.1,0.002,  # 5
1460                 0.3,-0.303];# 6
1461         coordsArr=DataArrayDouble.New();
1462         coordsArr.setValues(coords,7,2);
1463         mesh=MEDCouplingUMesh.New();
1464         mesh.setCoords(coordsArr);
1465         #! [PySnippet_MEDCouplingPointSet_getNodeIdsNearPoints_1]
1466         #! [PySnippet_MEDCouplingPointSet_getNodeIdsNearPoints_2]
1467         points=[0.2,-0.301,   # ~ node #1
1468                 0.0, 0.0,
1469                 1.1, 0.002]   # ~ nodes #3, #4 and #5
1470         ids,idsIndex=mesh.getNodeIdsNearPoints(points,3,0.003);
1471         assert ids.getValues() == [1, 3, 4, 5]
1472         assert idsIndex.getValues() == [0, 1, 1, 4]
1473         #! [PySnippet_MEDCouplingPointSet_getNodeIdsNearPoints_2]
1474         return
1475
1476     def testExample_MEDCouplingPointSet_findCommonNodes(self):
1477         #! [PySnippet_MEDCouplingPointSet_findCommonNodes_1]
1478         coords=[0.3,-0.301, # 0
1479                 0.2,-0.3,   # 1
1480                 0.3,-0.302, # 2
1481                 1.1,0.0,    # 3
1482                 1.1,0.0,    # 4
1483                 0.3,-0.303];# 5
1484         coordsArr=DataArrayDouble.New();
1485         coordsArr.setValues(coords,6,2);
1486         mesh=MEDCouplingUMesh.New();
1487         mesh.setCoords(coordsArr);
1488         #! [PySnippet_MEDCouplingPointSet_findCommonNodes_1]
1489         #! [PySnippet_MEDCouplingPointSet_findCommonNodes_2]
1490         comm,commI=mesh.findCommonNodes(1e-13)
1491         assert comm.getValues() == [3,4]
1492         comm,commI=mesh.findCommonNodes(0.004)
1493         assert comm.getValues() == [0,2,5,3,4]
1494         #! [PySnippet_MEDCouplingPointSet_findCommonNodes_2]
1495         return
1496
1497     def testExample_MEDCouplingPointSet_getCoordinatesOfNode(self):
1498         #! [PySnippet_MEDCouplingPointSet_getCoordinatesOfNode_1]
1499         coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3];
1500         coordsArr=DataArrayDouble.New();
1501         coordsArr.setValues(coords,3,2);
1502         mesh=MEDCouplingUMesh.New();
1503         mesh.setCoords(coordsArr);
1504 #! [PySnippet_MEDCouplingPointSet_getCoordinatesOfNode_1]
1505 #! [PySnippet_MEDCouplingPointSet_getCoordinatesOfNode_2]
1506         nodeCoords=mesh.getCoordinatesOfNode(1)
1507         self.assertAlmostEqual(0.2, nodeCoords[0],13);
1508         self.assertAlmostEqual(-0.3,nodeCoords[1],13);
1509 #! [PySnippet_MEDCouplingPointSet_getCoordinatesOfNode_2]
1510         return
1511
1512     def testExample_DataArrayInt_getTuple(self):
1513 #! [Snippet_DataArrayInt_getTuple_1]
1514         dv=DataArrayInt.New();
1515         dv.alloc( 6, 1 )
1516         dv.iota(7)
1517         dv.rearrange( 2 )
1518         assert dv.getTuple( 1 ) == [9,10]
1519 #! [Snippet_DataArrayInt_getTuple_1]
1520 #! [Snippet_DataArrayInt_getTuple_2]
1521         for tpl in dv:
1522             print tpl
1523 #! [Snippet_DataArrayInt_getTuple_2]
1524         return
1525
1526     def testExample_DataArrayInt_buildPermutationArr(self):
1527 #! [PySnippet_DataArrayInt_buildPermutationArr_1]
1528         a=DataArrayInt.New()
1529         a.setValues([4,5,6,7,8],5,1)
1530         b=DataArrayInt.New()
1531         b.setValues([5,4,8,6,7],5,1)
1532         c=a.buildPermutationArr(b)
1533 #! [PySnippet_DataArrayInt_buildPermutationArr_1]
1534         self.assertEqual([1,0,4,2,3],c.getValues())
1535         return
1536
1537     def testExample_DataArrayInt_invertArrayO2N2N2O(self):
1538 #! [PySnippet_DataArrayInt_invertArrayO2N2N2O_1]
1539         arr1=[2,0,4,1,5,3]
1540         da=DataArrayInt.New();
1541         da.setValues(arr1,6,1);
1542         da2=da.invertArrayO2N2N2O(6);
1543         expected1=[1,3,0,5,2,4]
1544         for i in xrange(6):
1545             self.assertEqual(expected1[i],da2.getIJ(i,0));
1546             pass
1547 #! [PySnippet_DataArrayInt_invertArrayO2N2N2O_1]
1548         return
1549
1550     def testExample_DataArrayInt_invertArrayN2O2O2N(self):
1551 #! [PySnippet_DataArrayInt_invertArrayN2O2O2N_1]
1552         arr1=[2,0,4,1,5,3]
1553         da=DataArrayInt.New();
1554         da.setValues(arr1,6,1);
1555         da2=da.invertArrayN2O2O2N(7);
1556         expected1=[1,3,0,5,2,4,-1]
1557         for i in xrange(6):
1558             self.assertEqual(expected1[i],da2.getIJ(i,0));
1559             pass
1560 #! [PySnippet_DataArrayInt_invertArrayN2O2O2N_1]
1561         return
1562
1563
1564     def testExample_DataArrayDouble_getIdsInRange(self):
1565 #! [PySnippet_DataArrayDouble_getIdsInRange_1]
1566         da=DataArrayDouble.New()
1567         da.alloc( 10, 1 )
1568         da[ :, :] = range(10)
1569         da2 = da.getIdsInRange( 2.5, 6 )
1570 #! [PySnippet_DataArrayDouble_getIdsInRange_1]
1571         return
1572
1573     def testExample_DataArrayDouble_setPartOfValues2(self):
1574 #! [Snippet_DataArrayDouble_setPartOfValues2_1]
1575         da=DataArrayDouble.New()
1576         da.alloc( 4, 7 )
1577         #
1578         dv=DataArrayDouble.New();
1579         dv.alloc( 6, 1 )
1580         dv.iota(7)
1581         dv.rearrange( 2 )
1582 #! [Snippet_DataArrayDouble_setPartOfValues2_1]
1583 #! [Snippet_DataArrayDouble_setPartOfValues2_2]
1584         da.fillWithZero()
1585         da[ [0,1,2], [1,3] ] = dv
1586 #! [Snippet_DataArrayDouble_setPartOfValues2_2]
1587 #! [Snippet_DataArrayDouble_setPartOfValues2_3]
1588         da.fillWithZero()
1589         dv.rearrange( 6 )
1590         da[ [0,2,3], [0,2,3,4,5,6]] = dv
1591 #! [Snippet_DataArrayDouble_setPartOfValues2_3]
1592         return
1593
1594     def testExample_DataArrayInt_setPartOfValues2(self):
1595 #! [Snippet_DataArrayInt_setPartOfValues2_1]
1596         da=DataArrayInt.New()
1597         da.alloc( 4, 7 )
1598         #
1599         dv=DataArrayInt.New();
1600         dv.alloc( 6, 1 )
1601         dv.iota(7)
1602         dv.rearrange( 2 )
1603 #! [Snippet_DataArrayInt_setPartOfValues2_1]
1604 #! [Snippet_DataArrayInt_setPartOfValues2_2]
1605         da.fillWithZero()
1606         da[ [0,1,2], [1,3] ] = dv
1607 #! [Snippet_DataArrayInt_setPartOfValues2_2]
1608 #! [Snippet_DataArrayInt_setPartOfValues2_3]
1609         da.fillWithZero()
1610         dv.rearrange( 6 )
1611         da[ [0,2,3], [0,2,3,4,5,6]] = dv
1612 #! [Snippet_DataArrayInt_setPartOfValues2_3]
1613         return
1614
1615     def testExample_DataArrayDouble_setPartOfValues3(self):
1616 #! [Snippet_DataArrayDouble_setPartOfValues3_1]
1617         da=DataArrayDouble.New()
1618         da.alloc( 4, 7 )
1619         #
1620         dv=DataArrayDouble.New();
1621         dv.alloc( 6, 1 )
1622         dv.iota(7)
1623         dv.rearrange( 2 )
1624 #! [Snippet_DataArrayDouble_setPartOfValues3_1]
1625 #! [Snippet_DataArrayDouble_setPartOfValues3_2]
1626         da.fillWithZero()
1627         da[ 0:3, [1,3] ] = dv
1628 #! [Snippet_DataArrayDouble_setPartOfValues3_2]
1629 #! [Snippet_DataArrayDouble_setPartOfValues3_3]
1630         da.fillWithZero()
1631         dv.rearrange( 6 )
1632         da[ 0:4:2, [0,2,3,4,5,6]] = dv
1633 #! [Snippet_DataArrayDouble_setPartOfValues3_3]
1634         return
1635
1636     def testExample_DataArrayInt_setPartOfValues3(self):
1637 #! [Snippet_DataArrayInt_setPartOfValues3_1]
1638         da=DataArrayInt.New()
1639         da.alloc( 4, 7 )
1640         #
1641         dv=DataArrayInt.New();
1642         dv.alloc( 6, 1 )
1643         dv.iota(7)
1644         dv.rearrange( 2 )
1645 #! [Snippet_DataArrayInt_setPartOfValues3_1]
1646 #! [Snippet_DataArrayInt_setPartOfValues3_2]
1647         da.fillWithZero()
1648         da[ 0:3, [1,3] ] = dv
1649 #! [Snippet_DataArrayInt_setPartOfValues3_2]
1650 #! [Snippet_DataArrayInt_setPartOfValues3_3]
1651         da.fillWithZero()
1652         dv.rearrange( 6 )
1653         da[ 0:4:2, [0,2,3,4,5,6]] = dv
1654 #! [Snippet_DataArrayInt_setPartOfValues3_3]
1655         return
1656
1657     def testExample_DataArrayDouble_setPartOfValues1(self):
1658 #! [Snippet_DataArrayDouble_setPartOfValues1_1]
1659         da=DataArrayDouble.New()
1660         da.alloc( 4, 4 )
1661         da.setInfoOnComponents( ["v1","v2","v3","v4"])
1662         #
1663         dv=DataArrayDouble.New();
1664         dv.alloc( 4, 1 )
1665         dv.iota(7)
1666         dv.rearrange( 2 )
1667         dv.setInfoOnComponents( ["a1","a2"])
1668 #! [Snippet_DataArrayDouble_setPartOfValues1_1]
1669 #! [Snippet_DataArrayDouble_setPartOfValues1_2]
1670         da.fillWithZero()
1671         da.setPartOfValues1( dv, 1,3,1, 1,3,1, True )
1672 #! [Snippet_DataArrayDouble_setPartOfValues1_2]
1673 #! [Snippet_DataArrayDouble_setPartOfValues1_3]
1674         da.fillWithZero()
1675         da.setPartOfValues1( dv, 0,4,1, 1,2,1, False )
1676 #! [Snippet_DataArrayDouble_setPartOfValues1_3]
1677 #! [Snippet_DataArrayDouble_setPartOfValues1_4]
1678         da.fillWithZero()
1679         da.setPartOfValues1( dv, 1,2,1, 0,4,1, False )
1680 #! [Snippet_DataArrayDouble_setPartOfValues1_4]
1681 #! [Snippet_DataArrayDouble_setPartOfValues1_5]
1682         da.fillWithZero()
1683         da.setPartOfValues1( dv, 0,3,2, 1,4,2, True )
1684 #! [Snippet_DataArrayDouble_setPartOfValues1_5]
1685 #! [Snippet_DataArrayDouble_setPartOfValues1_6]
1686         da2 = da.deepCpy()
1687         da2.fillWithZero()
1688         da2[ 0:3:2, 1:4:2 ] = dv
1689         self.assertTrue( da.isEqual( da2, 1e-20 ))
1690 #! [Snippet_DataArrayDouble_setPartOfValues1_6]
1691         return
1692
1693     def testExample_DataArrayInt_setPartOfValues1(self):
1694 #! [Snippet_DataArrayInt_setPartOfValues1_1]
1695         da=DataArrayInt.New()
1696         da.alloc( 4, 4 )
1697         da.setInfoOnComponents( ["v1","v2","v3","v4"])
1698         #
1699         dv=DataArrayInt.New();
1700         dv.alloc( 4, 1 )
1701         dv.iota(7)
1702         dv.rearrange( 2 )
1703         dv.setInfoOnComponents( ["a1","a2"])
1704 #! [Snippet_DataArrayInt_setPartOfValues1_1]
1705 #! [Snippet_DataArrayInt_setPartOfValues1_2]
1706         da.fillWithZero()
1707         da.setPartOfValues1( dv, 1,3,1, 1,3,1, True )
1708 #! [Snippet_DataArrayInt_setPartOfValues1_2]
1709 #! [Snippet_DataArrayInt_setPartOfValues1_3]
1710         da.fillWithZero()
1711         da.setPartOfValues1( dv, 0,4,1, 1,2,1, False )
1712 #! [Snippet_DataArrayInt_setPartOfValues1_3]
1713 #! [Snippet_DataArrayInt_setPartOfValues1_4]
1714         da.fillWithZero()
1715         da.setPartOfValues1( dv, 1,2,1, 0,4,1, False )
1716 #! [Snippet_DataArrayInt_setPartOfValues1_4]
1717 #! [Snippet_DataArrayInt_setPartOfValues1_5]
1718         da.fillWithZero()
1719         da.setPartOfValues1( dv, 0,3,2, 1,4,2, True )
1720 #! [Snippet_DataArrayInt_setPartOfValues1_5]
1721 #! [Snippet_DataArrayInt_setPartOfValues1_6]
1722         da2 = da.deepCpy()
1723         da2.fillWithZero()
1724         da2[ 0:3:2, 1:4:2 ] = dv
1725         self.assertTrue( da.isEqual( da2 ))
1726 #! [Snippet_DataArrayInt_setPartOfValues1_6]
1727         return
1728
1729     def testExample_DataArrayDouble_setPartOfValuesSimple1(self):
1730 #! [Snippet_DataArrayDouble_setPartOfValuesSimple1_1]
1731         da=DataArrayDouble.New()
1732         da.alloc( 4, 4 )
1733         dv = 7
1734 #! [Snippet_DataArrayDouble_setPartOfValuesSimple1_1]
1735 #! [Snippet_DataArrayDouble_setPartOfValuesSimple1_2]
1736         da.fillWithZero()
1737         da.setPartOfValuesSimple1( dv, 1,3,1, 1,3,1 )
1738 #! [Snippet_DataArrayDouble_setPartOfValuesSimple1_2]
1739 #! [Snippet_DataArrayDouble_setPartOfValuesSimple1_3]
1740         da.fillWithZero()
1741         da.setPartOfValuesSimple1( dv, 0,4,1, 1,2,1 )
1742 #! [Snippet_DataArrayDouble_setPartOfValuesSimple1_3]
1743 #! [Snippet_DataArrayDouble_setPartOfValuesSimple1_4]
1744         da.fillWithZero()
1745         da.setPartOfValuesSimple1( dv, 1,2,1, 0,4,1 )
1746 #! [Snippet_DataArrayDouble_setPartOfValuesSimple1_4]
1747 #! [Snippet_DataArrayDouble_setPartOfValuesSimple1_5]
1748         da.fillWithZero()
1749         da.setPartOfValuesSimple1( dv, 0,3,2, 1,4,2 )
1750 #! [Snippet_DataArrayDouble_setPartOfValuesSimple1_5]
1751 #! [Snippet_DataArrayDouble_setPartOfValuesSimple1_6]
1752         da2 = da.deepCpy()
1753         da2.fillWithZero()
1754         da2[ 0:3:2, 1:4:2 ] = dv
1755         self.assertTrue( da.isEqual( da2, 1e-20 ))
1756 #! [Snippet_DataArrayDouble_setPartOfValuesSimple1_6]
1757         return
1758
1759     def testExample_DataArrayInt_setPartOfValuesSimple1(self):
1760 #! [Snippet_DataArrayInt_setPartOfValuesSimple1_1]
1761         da=DataArrayInt.New()
1762         da.alloc( 4, 4 )
1763         dv = 7
1764 #! [Snippet_DataArrayInt_setPartOfValuesSimple1_1]
1765 #! [Snippet_DataArrayInt_setPartOfValuesSimple1_2]
1766         da.fillWithZero()
1767         da.setPartOfValuesSimple1( dv, 1,3,1, 1,3,1 )
1768 #! [Snippet_DataArrayInt_setPartOfValuesSimple1_2]
1769 #! [Snippet_DataArrayInt_setPartOfValuesSimple1_3]
1770         da.fillWithZero()
1771         da.setPartOfValuesSimple1( dv, 0,4,1, 1,2,1 )
1772 #! [Snippet_DataArrayInt_setPartOfValuesSimple1_3]
1773 #! [Snippet_DataArrayInt_setPartOfValuesSimple1_4]
1774         da.fillWithZero()
1775         da.setPartOfValuesSimple1( dv, 1,2,1, 0,4,1 )
1776 #! [Snippet_DataArrayInt_setPartOfValuesSimple1_4]
1777 #! [Snippet_DataArrayInt_setPartOfValuesSimple1_5]
1778         da.fillWithZero()
1779         da.setPartOfValuesSimple1( dv, 0,3,2, 1,4,2 )
1780 #! [Snippet_DataArrayInt_setPartOfValuesSimple1_5]
1781 #! [Snippet_DataArrayInt_setPartOfValuesSimple1_6]
1782         da2 = da.deepCpy()
1783         da2.fillWithZero()
1784         da2[ 0:3:2, 1:4:2 ] = dv
1785         self.assertTrue( da.isEqual( da2 ))
1786 #! [Snippet_DataArrayInt_setPartOfValuesSimple1_6]
1787         return
1788
1789     def testExample_DataArrayDouble_setPartOfValuesSimple2(self):
1790 #! [Snippet_DataArrayDouble_setPartOfValuesSimple2_1]
1791         da=DataArrayDouble.New()
1792         da.alloc( 4, 4 )
1793         dv = 7
1794 #! [Snippet_DataArrayDouble_setPartOfValuesSimple2_1]
1795 #! [Snippet_DataArrayDouble_setPartOfValuesSimple2_2]
1796         da.fillWithZero()
1797         da[[1,2], [1,2]] = dv
1798 #! [Snippet_DataArrayDouble_setPartOfValuesSimple2_2]
1799 #! [Snippet_DataArrayDouble_setPartOfValuesSimple2_3]
1800         da.fillWithZero()
1801         da[[0,1,2,3], [1]] = dv
1802 #! [Snippet_DataArrayDouble_setPartOfValuesSimple2_3]
1803 #! [Snippet_DataArrayDouble_setPartOfValuesSimple2_4]
1804         da.fillWithZero()
1805         da[[1], [0,1,2,3]] = dv
1806 #! [Snippet_DataArrayDouble_setPartOfValuesSimple2_4]
1807 #! [Snippet_DataArrayDouble_setPartOfValuesSimple2_5]
1808         da.fillWithZero()
1809         da[[0,2], [1,3]] = dv
1810 #! [Snippet_DataArrayDouble_setPartOfValuesSimple2_5]
1811         return
1812
1813     def testExample_DataArrayInt_setPartOfValuesSimple2(self):
1814 #! [Snippet_DataArrayInt_setPartOfValuesSimple2_1]
1815         da=DataArrayInt.New()
1816         da.alloc( 4, 4 )
1817         dv = 7
1818 #! [Snippet_DataArrayInt_setPartOfValuesSimple2_1]
1819 #! [Snippet_DataArrayInt_setPartOfValuesSimple2_2]
1820         da.fillWithZero()
1821         da[[1,2], [1,2]] = dv
1822 #! [Snippet_DataArrayInt_setPartOfValuesSimple2_2]
1823 #! [Snippet_DataArrayInt_setPartOfValuesSimple2_3]
1824         da.fillWithZero()
1825         da[[0,1,2,3], [1]] = dv
1826 #! [Snippet_DataArrayInt_setPartOfValuesSimple2_3]
1827 #! [Snippet_DataArrayInt_setPartOfValuesSimple2_4]
1828         da.fillWithZero()
1829         da[[1], [0,1,2,3]] = dv
1830 #! [Snippet_DataArrayInt_setPartOfValuesSimple2_4]
1831 #! [Snippet_DataArrayInt_setPartOfValuesSimple2_5]
1832         da.fillWithZero()
1833         da[[0,2], [1,3]] = dv
1834 #! [Snippet_DataArrayInt_setPartOfValuesSimple2_5]
1835         return
1836
1837     def testExample_DataArrayDouble_setPartOfValuesSimple3(self):
1838 #! [Snippet_DataArrayDouble_setPartOfValuesSimple3_1]
1839         da=DataArrayDouble.New()
1840         da.alloc( 4, 4 )
1841         dv = 7
1842 #! [Snippet_DataArrayDouble_setPartOfValuesSimple3_1]
1843 #! [Snippet_DataArrayDouble_setPartOfValuesSimple3_2]
1844         da.fillWithZero()
1845         da[[1,2], 1:3] = dv
1846 #! [Snippet_DataArrayDouble_setPartOfValuesSimple3_2]
1847 #! [Snippet_DataArrayDouble_setPartOfValuesSimple3_3]
1848         da.fillWithZero()
1849         da[[0,1,2,3], 1:2] = dv
1850 #! [Snippet_DataArrayDouble_setPartOfValuesSimple3_3]
1851 #! [Snippet_DataArrayDouble_setPartOfValuesSimple3_4]
1852         da.fillWithZero()
1853         da[[1], 0:4] = dv
1854 #! [Snippet_DataArrayDouble_setPartOfValuesSimple3_4]
1855 #! [Snippet_DataArrayDouble_setPartOfValuesSimple3_5]
1856         da.fillWithZero()
1857         da[[0,2], 1:4:2] = dv
1858 #! [Snippet_DataArrayDouble_setPartOfValuesSimple3_5]
1859         return
1860
1861     def testExample_DataArrayInt_setPartOfValuesSimple3(self):
1862 #! [Snippet_DataArrayInt_setPartOfValuesSimple3_1]
1863         da=DataArrayInt.New()
1864         da.alloc( 4, 4 )
1865         dv = 7
1866 #! [Snippet_DataArrayInt_setPartOfValuesSimple3_1]
1867 #! [Snippet_DataArrayInt_setPartOfValuesSimple3_2]
1868         da.fillWithZero()
1869         da[[1,2], 1:3] = dv
1870 #! [Snippet_DataArrayInt_setPartOfValuesSimple3_2]
1871 #! [Snippet_DataArrayInt_setPartOfValuesSimple3_3]
1872         da.fillWithZero()
1873         da[[0,1,2,3], 1:2] = dv
1874 #! [Snippet_DataArrayInt_setPartOfValuesSimple3_3]
1875 #! [Snippet_DataArrayInt_setPartOfValuesSimple3_4]
1876         da.fillWithZero()
1877         da[[1], 0:4] = dv
1878 #! [Snippet_DataArrayInt_setPartOfValuesSimple3_4]
1879 #! [Snippet_DataArrayInt_setPartOfValuesSimple3_5]
1880         da.fillWithZero()
1881         da[[0,2], 1:4:2] = dv
1882 #! [Snippet_DataArrayInt_setPartOfValuesSimple3_5]
1883         return
1884
1885     def testExample_DataArrayDouble_setSelectedComponents(self):
1886 #! [Snippet_DataArrayDouble_setSelectedComponents1]
1887         da=DataArrayDouble.New();
1888         array1=[1.,2., 3.,4., 5.,6.]
1889         da.setValues(array1,3,2)
1890         da.setInfoOnComponents( ["a1","a2"])
1891 #! [Snippet_DataArrayDouble_setSelectedComponents1]
1892 #! [Snippet_DataArrayDouble_setSelectedComponents2]
1893         dv=DataArrayDouble.New();
1894         dv.alloc( 4, 4 )
1895         dv.fillWithZero()
1896         dv.setInfoOnComponents( ["v1","v2","v3","v4"])
1897         dv2 = dv.deepCpy()
1898         dv.setSelectedComponents( da, [1,0] )
1899 #! [Snippet_DataArrayDouble_setSelectedComponents2]
1900 #! [Snippet_DataArrayDouble_setSelectedComponents3]
1901         dv2[:3,[1,0]] = da
1902         self.assertTrue( dv.isEqualWithoutConsideringStr( dv2, 1e-20 ))
1903 #! [Snippet_DataArrayDouble_setSelectedComponents3]
1904         return
1905
1906     def testExample_DataArrayInt_setSelectedComponents(self):
1907 #! [Snippet_DataArrayInt_setSelectedComponents1]
1908         da=DataArrayInt.New();
1909         array1=[1,2, 3,4, 5,6]
1910         da.setValues(array1,3,2)
1911         da.setInfoOnComponents( ["a1","a2"])
1912 #! [Snippet_DataArrayInt_setSelectedComponents1]
1913 #! [Snippet_DataArrayInt_setSelectedComponents2]
1914         dv=DataArrayInt.New();
1915         dv.alloc( 4, 4 )
1916         dv.fillWithZero()
1917         dv.setInfoOnComponents( ["v1","v2","v3","v4"])
1918         dv2 = dv.deepCpy()
1919         dv.setSelectedComponents( da, [1,0] )
1920 #! [Snippet_DataArrayInt_setSelectedComponents2]
1921 #! [Snippet_DataArrayInt_setSelectedComponents3]
1922         dv2[:3,[1,0]] = da
1923         self.assertTrue( dv.isEqualWithoutConsideringStr( dv2 ))
1924 #! [Snippet_DataArrayInt_setSelectedComponents3]
1925         return
1926
1927     def testExample_DataArrayDouble_getDifferentValues(self):
1928 #! [Snippet_DataArrayDouble_getDifferentValues1]
1929         da=DataArrayDouble.New();
1930         array1=[2.3,1.2,1.3,2.3,2.301,0.8]
1931         da.setValues(array1,6,1)
1932         #
1933         dv=da.getDifferentValues(2e-1);
1934         expected2=[2.301,1.3,0.8]
1935         self.assertEqual(3,dv.getNbOfElems());
1936         for i in xrange(3):
1937             self.assertAlmostEqual(expected2[i],dv.getIJ(i,0),14);
1938             pass
1939 #! [Snippet_DataArrayDouble_getDifferentValues1]
1940         return
1941
1942     def testExample_DataArrayDouble_findCommonTuples1(self):
1943 #! [PySnippet_DataArrayDouble_findCommonTuples1]
1944         da=DataArrayDouble.New();
1945         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]
1946         da.setValues(array2,6,2)
1947 #! [PySnippet_DataArrayDouble_findCommonTuples1]
1948 #! [PySnippet_DataArrayDouble_findCommonTuples2]
1949         c,cI=da.findCommonTuples(1.01e-1);
1950         expected3=[0,3,4,1,2]
1951         expected4=[0,3,5]
1952         self.assertEqual(expected3,c.getValues())
1953         self.assertEqual(expected4,cI.getValues())
1954 #! [PySnippet_DataArrayDouble_findCommonTuples2]
1955         return
1956
1957     def testExampleDataArrayDoubleMeldWith(self):
1958 #! [PySnippet_DataArrayDouble_Meld1_1]
1959         da1=DataArrayDouble.New();
1960         da1.alloc(7,2);
1961         da2=DataArrayDouble.New();
1962         da2.alloc(7,1);
1963         #
1964         da1.fillWithValue(7.);
1965         da2.iota(0.);
1966         da3=da2.applyFunc(3,"10*x*IVec+100*x*JVec+1000*x*KVec");
1967         #
1968         da1.setInfoOnComponent(0,"c0da1");
1969         da1.setInfoOnComponent(1,"c1da1");
1970         da3.setInfoOnComponent(0,"c0da3");
1971         da3.setInfoOnComponent(1,"c1da3");
1972         da3.setInfoOnComponent(2,"c2da3");
1973         #
1974         da1C=da1.deepCpy();
1975         da1.meldWith(da3);
1976 #! [PySnippet_DataArrayDouble_Meld1_1]
1977
1978     def testExampleDataArrayIntMeldWith(self):
1979 #! [PySnippet_DataArrayInt_Meld1_1]
1980         da1=DataArrayInt.New();
1981         da1.alloc(7,2);
1982         da2=DataArrayInt.New();
1983         da2.alloc(7,1);
1984         #
1985         da1.fillWithValue(7);
1986         da2.iota(0);
1987         #
1988         da1.setInfoOnComponent(0,"c0da1");
1989         da1.setInfoOnComponent(1,"c1da1");
1990         da2.setInfoOnComponent(0,"c0da2");
1991         #
1992         da1.meldWith(da2);
1993 #! [PySnippet_DataArrayInt_Meld1_1]
1994
1995     def testExampleDataArrayDoubleKeepSelectedComponents1(self):
1996 #! [SnippeDataArrayDoubleKeepSelectedComponents1_1]
1997         arr1=[1.,2.,3.,4.,     # tuple 0
1998               11.,12.,13.,14., # tuple 1
1999               21.,22.,23.,24., # ...
2000               31.,32.,33.,34.,
2001               41.,42.,43.,44.]
2002         a1=DataArrayDouble.New()
2003         a1.setValues(arr1,5,4)
2004         a1.setInfoOnComponent(0,"a");
2005         a1.setInfoOnComponent(1,"b");
2006         a1.setInfoOnComponent(2,"c");
2007         a1.setInfoOnComponent(3,"d");
2008 #! [SnippeDataArrayDoubleKeepSelectedComponents1_1]
2009 #! [SnippeDataArrayDoubleKeepSelectedComponents1_2]
2010         arr2V=[1,2,1,2,0,0]
2011         a2=a1.keepSelectedComponents(arr2V)
2012 #! [SnippeDataArrayDoubleKeepSelectedComponents1_2]
2013         return
2014
2015     def testExampleDataArrayIntKeepSelectedComponents1(self):
2016 #! [SnippeDataArrayIntKeepSelectedComponents1_1]
2017         arr1=[1,2,3,4,     # tuple 0
2018               11,12,13,14, # tuple 1
2019               21,22,23,24, # 
2020               31,32,33,34,
2021               41,42,43,44]
2022         a1=DataArrayInt.New()
2023         a1.setValues(arr1,5,4)
2024         a1.setInfoOnComponent(0,"a");
2025         a1.setInfoOnComponent(1,"b");
2026         a1.setInfoOnComponent(2,"c");
2027         a1.setInfoOnComponent(3,"d");
2028 #! [SnippeDataArrayIntKeepSelectedComponents1_1]
2029 #! [SnippeDataArrayIntKeepSelectedComponents1_2]
2030         arr2V=[1,2,1,2,0,0]
2031         a2=a1.keepSelectedComponents(arr2V)
2032 #! [SnippeDataArrayIntKeepSelectedComponents1_2]
2033 #! [SnippeDataArrayIntKeepSelectedComponents1_3]
2034         a3=a1[:,arr2V ]
2035 #! [SnippeDataArrayIntKeepSelectedComponents1_3]
2036         return
2037
2038     def testExampleFieldDoubleBuildSubPart1(self):
2039         from MEDCouplingDataForTest import MEDCouplingDataForTest
2040 #! [PySnippetFieldDoubleBuildSubPart1_1]
2041         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1()
2042         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME)
2043         f1.setTime(2.3,5,6)
2044         f1.setMesh(mesh1)
2045         array=DataArrayDouble.New()
2046         arr1=[3.,103.,4.,104.,5.,105.,6.,106.,7.,107.]
2047         array.setValues(arr1,mesh1.getNumberOfCells(),2)
2048         f1.setArray(array)
2049 # ! [PySnippetFieldDoubleBuildSubPart1_1]
2050 # ! [PySnippetFieldDoubleBuildSubPart1_2]
2051         part1=[2,1,4]
2052         f2=f1.buildSubPart(part1)
2053 # ! [PySnippetFieldDoubleBuildSubPart1_2]
2054         f2.zipCoords()
2055         self.assertEqual(3,f2.getNumberOfTuples())
2056         self.assertEqual(2,f2.getNumberOfComponents())
2057         expected1=[5.,105.,4.,104.,7.,107.]
2058         for i in xrange(6):
2059             self.assertAlmostEqual(f2.getIJ(0,i),expected1[i],12)
2060             pass
2061         self.assertEqual(3,f2.getMesh().getNumberOfCells())
2062         self.assertEqual(6,f2.getMesh().getNumberOfNodes())
2063         self.assertEqual(2,f2.getMesh().getSpaceDimension())
2064         self.assertEqual(2,f2.getMesh().getMeshDimension())
2065         m2C=f2.getMesh()
2066         self.assertEqual(13,m2C.getMeshLength())
2067         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]
2068         for i in xrange(12):
2069             self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12)
2070             pass
2071         expected3=[3,2,3,1,3,0,2,1,4,4,5,3,2]
2072         self.assertEqual(expected3,list(m2C.getNodalConnectivity().getValues()))
2073         expected4=[0,4,8,13]
2074         self.assertEqual(expected4,list(m2C.getNodalConnectivityIndex().getValues()))
2075         # Test with field on nodes.
2076 # ! [PySnippetFieldDoubleBuildSubPart1_3]
2077         f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME)
2078         f1.setTime(2.3,5,6)
2079         f1.setMesh(mesh1)
2080         array=DataArrayDouble.New()
2081         arr2=[3.,103.,4.,104.,5.,105.,6.,106.,7.,107.,8.,108.,9.,109.,10.,110.,11.,111.]
2082         array.setValues(arr2,mesh1.getNumberOfNodes(),2)
2083         f1.setArray(array)
2084 # ! [PySnippetFieldDoubleBuildSubPart1_3]
2085 # ! [PySnippetFieldDoubleBuildSubPart1_4]
2086         part2=[1,2]
2087         f2=f1.buildSubPart(part2)
2088 # ! [PySnippetFieldDoubleBuildSubPart1_4]
2089         self.assertEqual(4,f2.getNumberOfTuples())
2090         self.assertEqual(2,f2.getNumberOfComponents())
2091         expected5=[4.,104.,5.,105.,7.,107.,8.,108.]
2092         for i in xrange(8):
2093             self.assertAlmostEqual(f2.getIJ(0,i),expected5[i],12)
2094             pass
2095         self.assertEqual(2,f2.getMesh().getNumberOfCells())
2096         self.assertEqual(4,f2.getMesh().getNumberOfNodes())
2097         self.assertEqual(2,f2.getMesh().getSpaceDimension())
2098         self.assertEqual(2,f2.getMesh().getMeshDimension())
2099         m2C=f2.getMesh()
2100         self.assertEqual(8,m2C.getMeshLength())
2101         for i in xrange(8):#8 is not an error
2102             self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12)
2103             pass
2104         self.assertEqual(expected3[:4],[int(i) for i in m2C.getNodalConnectivity()][4:])
2105         self.assertEqual(expected3[4:8],[int(i) for i in m2C.getNodalConnectivity()][:4])
2106         self.assertEqual(expected4[:3],[int(i) for i in m2C.getNodalConnectivityIndex()])
2107         #idem previous because nodes of cell#4 are not fully present in part3
2108         part3=[1,2]
2109         arrr=DataArrayInt.New()
2110         arrr.setValues(part3,2,1)
2111         f2=f1.buildSubPart(arrr)
2112         self.assertEqual(4,f2.getNumberOfTuples())
2113         self.assertEqual(2,f2.getNumberOfComponents())
2114         for i in xrange(8):
2115             self.assertAlmostEqual(f2.getIJ(0,i),expected5[i],12)
2116             pass
2117         self.assertEqual(2,f2.getMesh().getNumberOfCells())
2118         self.assertEqual(4,f2.getMesh().getNumberOfNodes())
2119         self.assertEqual(2,f2.getMesh().getSpaceDimension())
2120         self.assertEqual(2,f2.getMesh().getMeshDimension())
2121         m2C=f2.getMesh()
2122         self.assertEqual(8,m2C.getMeshLength())
2123         for i in xrange(8):#8 is not an error
2124             self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12)
2125             pass
2126         self.assertEqual(expected3[:4],[int(i) for i in m2C.getNodalConnectivity()][4:8])
2127         self.assertEqual(expected3[4:8],[int(i) for i in m2C.getNodalConnectivity()][:4])
2128         self.assertEqual(expected4[:3],m2C.getNodalConnectivityIndex().getValues())
2129         part4=[1,2,4]
2130         f2=f1.buildSubPart(part4)
2131         self.assertEqual(6,f2.getNumberOfTuples())
2132         self.assertEqual(2,f2.getNumberOfComponents())
2133         expected6=[4.,104.,5.,105.,7.,107.,8.,108.,10.,110.,11.,111.]
2134         for i in xrange(12):
2135             self.assertAlmostEqual(f2.getIJ(0,i),expected6[i],12)
2136             pass
2137         self.assertEqual(3,f2.getMesh().getNumberOfCells())
2138         self.assertEqual(6,f2.getMesh().getNumberOfNodes())
2139         self.assertEqual(2,f2.getMesh().getSpaceDimension())
2140         self.assertEqual(2,f2.getMesh().getMeshDimension())
2141         m2C=f2.getMesh()
2142         self.assertEqual(13,m2C.getMeshLength())
2143         for i in xrange(12):
2144             self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12)
2145             pass
2146         self.assertEqual(expected3[0:4],m2C.getNodalConnectivity().getValues()[4:8])
2147         self.assertEqual(expected3[4:8],m2C.getNodalConnectivity().getValues()[0:4])
2148         self.assertEqual(expected3[8:13],m2C.getNodalConnectivity().getValues()[8:13])
2149         self.assertEqual(expected4,m2C.getNodalConnectivityIndex().getValues())
2150         # previous line equivalent to
2151         self.assertEqual(expected4,[int(i) for i in m2C.getNodalConnectivityIndex()])
2152         return
2153
2154     def testExampleUMeshStdBuild1(self):
2155 # ! [PySnippetUMeshStdBuild1_1]
2156         coords=[-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., 
2157                  0.7,0.2,0.,    -0.3,0.7,0.,    0.2,0.7,0.,     0.7,0.7,0. ]
2158         nodalConnPerCell=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
2159 # ! [PySnippetUMeshStdBuild1_1]
2160 # ! [PySnippetUMeshStdBuild1_2]
2161         mesh=MEDCouplingUMesh.New("My2DMesh",2)
2162 # ! [PySnippetUMeshStdBuild1_2]
2163 # ! [PySnippetUMeshStdBuild1_3]
2164         mesh.allocateCells(5)#You can put more than 5 if you want but not less.
2165         mesh.insertNextCell(NORM_QUAD4,nodalConnPerCell[:4])
2166         mesh.insertNextCell(NORM_TRI3,nodalConnPerCell[4:7])
2167         mesh.insertNextCell(NORM_TRI3,nodalConnPerCell[7:10])
2168         mesh.insertNextCell(NORM_QUAD4,nodalConnPerCell[10:14])
2169         mesh.insertNextCell(NORM_QUAD4,nodalConnPerCell[14:])
2170         mesh.finishInsertingCells()
2171 # ! [PySnippetUMeshStdBuild1_3]
2172 # ! [PySnippetUMeshStdBuild1_4]
2173         coordsArr=DataArrayDouble.New(coords,9,3)#here coordsArr are declared to have 3 components, mesh will deduce that its spaceDim==3. 
2174         mesh.setCoords(coordsArr)#coordsArr contains 9 tuples, that is to say mesh contains 9 nodes.
2175 # ! [PySnippetUMeshStdBuild1_4]
2176 # ! [PySnippetUMeshStdBuild1_5]
2177 # ! [PySnippetUMeshStdBuild1_5]
2178         mesh.checkCoherency()
2179         return
2180
2181     def testExampleCMeshStdBuild1(self):
2182 # ! [PySnippetCMeshStdBuild1_1]
2183         XCoords=[-0.3,0.,0.1,0.3,0.45,0.47,0.49,1.,1.22] # 9 values along X
2184         YCoords=[0.,0.1,0.37,0.45,0.47,0.49,1.007] # 7 values along Y
2185         arrX=DataArrayDouble.New(XCoords)
2186         arrX.setInfoOnComponent(0,"X [m]")
2187         arrY=DataArrayDouble.New(YCoords)
2188         arrY.setInfoOnComponent(0,"Y [m]")
2189 # ! [PySnippetCMeshStdBuild1_1]
2190 # ! [PySnippetCMeshStdBuild1_2]
2191         mesh=MEDCouplingCMesh.New("My2D_CMesh")
2192         mesh.setCoords(arrX,arrY)
2193 # ! [PySnippetCMeshStdBuild1_2]
2194 # ! [PySnippetCMeshStdBuild1_3]
2195         self.assertEqual(8*6,mesh.getNumberOfCells())
2196         self.assertEqual(9*7,mesh.getNumberOfNodes())
2197         self.assertEqual(2,mesh.getSpaceDimension())
2198         self.assertEqual(2,mesh.getMeshDimension())
2199 # ! [PySnippetCMeshStdBuild1_3]
2200         mesh=MEDCouplingCMesh.New("My2D_CMesh")
2201 # ! [PySnippetCMeshStdBuild1_2bis]
2202         mesh.setCoordsAt(0,arrX)
2203         mesh.setCoordsAt(1,arrY)
2204 # ! [PySnippetCMeshStdBuild1_2bis]
2205         self.assertEqual(8*6,mesh.getNumberOfCells())
2206         self.assertEqual(9*7,mesh.getNumberOfNodes())
2207         self.assertEqual(2,mesh.getSpaceDimension())
2208         self.assertEqual(2,mesh.getMeshDimension())
2209         return
2210
2211     def testExampleUMeshAdvBuild1(self):
2212 # ! [PySnippetUMeshAdvBuild1_1]
2213         coords=[-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., 
2214                  0.7,0.2,0.,    -0.3,0.7,0.,    0.2,0.7,0.,     0.7,0.7,0. ]
2215         nodalConnPerCell=[4,0,3,4,1, 3,1,4,2, 3,4,5,2, 4,6,7,4,3, 4,7,8,5,4]
2216         nodalConnPerCellIndex=[0,5,9,13,18,23]
2217 # ! [PySnippetUMeshAdvBuild1_1]
2218 # ! [PySnippetUMeshAdvBuild1_2]
2219         mesh=MEDCouplingUMesh.New("My2DMesh",2)
2220 # ! [PySnippetUMeshAdvBuild1_2]
2221 # ! [PySnippetUMeshAdvBuild1_3]
2222         nodalConn=DataArrayInt.New(nodalConnPerCell,23,1)
2223         nodalConnI=DataArrayInt.New(nodalConnPerCellIndex,6,1)
2224         mesh.setConnectivity(nodalConn,nodalConnI,True)
2225 # ! [PySnippetUMeshAdvBuild1_3]
2226 # ! [PySnippetUMeshAdvBuild1_4]
2227         coordsArr=DataArrayDouble.New(coords,9,3)#here coordsArr are declared to have 3 components, mesh will deduce that its spaceDim==3.
2228         mesh.setCoords(coordsArr)#coordsArr contains 9 tuples, that is to say mesh contains 9 nodes.
2229 # ! [PySnippetUMeshAdvBuild1_4]
2230 # ! [PySnippetUMeshAdvBuild1_5]
2231 # ! [PySnippetUMeshAdvBuild1_5]
2232         mesh.checkCoherency()
2233         return
2234
2235     def testExampleDataArrayBuild1(self):
2236 # ! [PySnippetDataArrayBuild1_0]
2237         dataDouble=[0.,10.,20.,1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.]
2238 # ! [PySnippetDataArrayBuild1_0]
2239 # ! [PySnippetDataArrayBuild1_1]
2240         arrayDouble=DataArrayDouble.New()
2241         arrayDouble.setValues(dataDouble,5,3)# 5 tuples containing each 3 components
2242 # ! [PySnippetDataArrayBuild1_1]
2243 # ! [PySnippetDataArrayBuild1_1bis]
2244         arrayDouble=DataArrayDouble.New(dataDouble,5,3)
2245 # ! [PySnippetDataArrayBuild1_1bis]
2246 # ! [PySnippetDataArrayBuild1_2]
2247         dataInt=[0, 10, 20, 1, 11, 21, 2, 12, 22, 3, 13, 23, 4, 14, 24]
2248 # ! [PySnippetDataArrayBuild1_2]
2249 # ! [PySnippetDataArrayBuild1_3]
2250         arrayInt=DataArrayInt.New()
2251         arrayInt.setValues(dataInt,5,3)# 5 tuples containing each 3 components
2252 # ! [PySnippetDataArrayBuild1_3]
2253 # ! [PySnippetDataArrayBuild1_3bis]
2254         arrayInt=DataArrayInt.New(dataInt,5,3)
2255 # ! [PySnippetDataArrayBuild1_3bis]
2256         return
2257
2258     def testExampleFieldDoubleBuild1(self):
2259         XCoords=[-0.3,0.07,0.1,0.3,0.45,0.47,0.49,1.,1.22] ; arrX=DataArrayDouble.New(XCoords)
2260         YCoords=[0.07,0.1,0.37,0.45,0.47,0.49,1.007] ; arrY=DataArrayDouble.New(YCoords)
2261         mesh=MEDCouplingCMesh.New("My2D_CMesh")
2262         mesh.setCoords(arrX,arrY)
2263 # ! [PySnippetFieldDoubleBuild1_1]
2264         fieldOnCells=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME)
2265         fieldOnCells.setName("MyTensorFieldOnCellNoTime")
2266         fieldOnCells.setMesh(mesh)
2267         array=DataArrayDouble.New()
2268         array.alloc(fieldOnCells.getMesh().getNumberOfCells(),9) # Implicitely fieldOnCells will be a 9 components field.
2269         array.fillWithValue(7.)
2270         fieldOnCells.setArray(array)
2271         # fieldOnCells is now usable
2272         # ...
2273 # ! [PySnippetFieldDoubleBuild1_1]
2274 # ! [PySnippetFieldDoubleBuild1_2]
2275         f1=mesh.fillFromAnalytic(ON_CELLS,1,"x*x+y*y*3+2.*x") # f1 is scalar
2276         f2=mesh.fillFromAnalytic(ON_CELLS,1,"cos(x+y/x)") # f2 is scalar too
2277         f2bis=mesh.fillFromAnalytic(ON_CELLS,2,"x*x*IVec+3*y*JVec") # f2bis is a vectors field
2278         f3=f1+f2 # f3 scalar
2279         f4=f3/f2 # f4 scalar
2280         f2bis.applyFunc(1,"sqrt(x*x+y*y)") # f2bis becomes scalar
2281         f5=f2bis*f4 # f5 scalar
2282         pos1=[0.48,0.38]
2283         res=f4.getValueOn(pos1) # f4 is scalar so the returned value is of size 1.
2284         # ...
2285 # ! [PySnippetFieldDoubleBuild1_2]
2286 # ! [PySnippetFieldDoubleBuild1_3]
2287 # ! [PySnippetFieldDoubleBuild1_3]
2288         return
2289
2290     def testExampleFieldDoubleBuild2(self):
2291         XCoords=[-0.3,0.,0.1,0.3,0.45,0.47,0.49,1.,1.22] ; arrX=DataArrayDouble.New(XCoords)
2292         YCoords=[0.,0.1,0.37,0.45,0.47,0.49,1.007] ; arrY=DataArrayDouble.New(YCoords)
2293         mesh=MEDCouplingCMesh.New("My2D_CMesh")
2294         mesh.setCoords(arrX,arrY)
2295 # ! [PySnippetFieldDoubleBuild2_1]
2296         fieldOnNodes=MEDCouplingFieldDouble.New(ON_NODES,NO_TIME)
2297         fieldOnNodes.setName("MyScalarFieldOnNodeNoTime")
2298         fieldOnNodes.setMesh(mesh)
2299         array=DataArrayDouble.New()
2300         array.alloc(fieldOnNodes.getMesh().getNumberOfNodes(),1) # Implicitely fieldOnNodes will be a 1 component field.
2301         array.fillWithValue(7.)
2302         fieldOnNodes.setArray(array)
2303         # fieldOnNodes is now usable
2304         # ...
2305 # ! [PySnippetFieldDoubleBuild2_1]
2306         return
2307
2308     def testExampleFieldDoubleBuild3(self):
2309         XCoords=[-0.3,0.,0.1,0.3,0.45,0.47,0.49,1.,1.22] ; arrX=DataArrayDouble.New(XCoords)
2310         YCoords=[0.,0.1,0.37,0.45,0.47,0.49,1.007] ; arrY=DataArrayDouble.New(YCoords)
2311         mesh=MEDCouplingCMesh.New("My2D_CMesh")
2312         mesh.setCoords(arrX,arrY)
2313 # ! [PySnippetFieldDoubleBuild3_1]
2314         fieldOnCells=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME)
2315         fieldOnCells.setName("MyTensorFieldOnCellNoTime")
2316         fieldOnCells.setTimeUnit("ms") # Time unit is ms.
2317         fieldOnCells.setTime(4.22,2,-1) # Time attached is 4.22 ms, iteration id is 2 and order id (or sub iteration id) is -1
2318         fieldOnCells.setMesh(mesh)
2319         array=DataArrayDouble.New()
2320         array.alloc(fieldOnCells.getMesh().getNumberOfCells(),2) # Implicitely fieldOnCells will be a 2 components field.
2321         array.fillWithValue(7.)
2322         fieldOnCells.setArray(array)
2323         # fieldOnCells is now usable
2324         # ...
2325 # ! [PySnippetFieldDoubleBuild3_1]
2326         return
2327
2328     def testExampleFieldDoubleBuild4(self):
2329         XCoords=[-0.3,0.,0.1,0.3,0.45,0.47,0.49,1.,1.22] ; arrX=DataArrayDouble.New(XCoords)
2330         YCoords=[0.,0.1,0.37,0.45,0.47,0.49,1.007] ; arrY=DataArrayDouble.New(YCoords)
2331         mesh=MEDCouplingCMesh.New("My2D_CMesh")
2332         mesh.setCoords(arrX,arrY)
2333 # ! [PySnippetFieldDoubleBuild4_1]
2334         fieldOnNodes=MEDCouplingFieldDouble.New(ON_NODES,CONST_ON_TIME_INTERVAL)
2335         fieldOnNodes.setName("MyVecFieldOnNodeWithConstTime")
2336         fieldOnNodes.setTimeUnit("ms") # Time unit is ms.
2337         fieldOnNodes.setStartTime(4.22,2,-1)
2338         fieldOnNodes.setEndTime(6.44,4,-1)# fieldOnNodes is defined in interval [4.22 ms,6.44 ms]
2339         fieldOnNodes.setMesh(mesh)
2340         array=DataArrayDouble.New()
2341         array.alloc(fieldOnNodes.getMesh().getNumberOfNodes(),3) # Implicitely fieldOnNodes will be a 3 components field.
2342         array.fillWithValue(7.)
2343         fieldOnNodes.setArray(array)
2344         # fieldOnNodes is now usable
2345         # ...
2346 # ! [PySnippetFieldDoubleBuild4_1]
2347         return
2348
2349     def testExampleDataArrayApplyFunc1(self):
2350 # ! [PySnippetDataArrayApplyFunc1_1]
2351         d=DataArrayDouble.New([1.,2.,11.,12.,21.,22.,31.,41.],4,2)
2352         self.assertRaises(InterpKernelException,d.applyFunc,"x*y")
2353 # ! [PySnippetDataArrayApplyFunc1_1]
2354 # ! [PySnippetDataArrayApplyFunc1_2]
2355         d=DataArrayDouble.New([1.,2.,11.,12.,21.,22.,31.,41.],4,2)
2356         d1=d.applyFunc("smth*smth")
2357         self.assertTrue(d1.isEqual(DataArrayDouble([1.,4.,121.,144.,441.,484.,961.,1681.],4,2),1e-12))
2358 # ! [PySnippetDataArrayApplyFunc1_2]
2359 # ! [PySnippetDataArrayApplyFunc1_3]
2360         d2=d.applyFunc(2,"smth1*IVec+2*smth2*JVec")
2361         self.assertTrue(d2.isEqual(DataArrayDouble([1.,4.,11.,24.,21.,44.,31.,82.],4,2),1e-12))
2362 # ! [PySnippetDataArrayApplyFunc1_3]
2363 # ! [PySnippetDataArrayApplyFunc1_4]
2364         dd=DataArrayDouble.New([1.,4.,3.,11.,144.,13.,21.,484.,23.,31.,1024.,33.],4,3)
2365 # ! [PySnippetDataArrayApplyFunc1_4]
2366 # ! [PySnippetDataArrayApplyFunc1_5]
2367         dd1=dd.applyFunc(1,"f+sqrt(g)+h")
2368         self.assertTrue(dd1.isEqual(DataArrayDouble([6.,36.,66.,96.],4,1),1e-12))
2369 # ! [PySnippetDataArrayApplyFunc1_5]
2370 # ! [PySnippetDataArrayApplyFunc1_6]
2371         dd2=dd.applyFunc(1,"a+0.*b+c")
2372         self.assertTrue(dd2.isEqual(DataArrayDouble([4.,24.,44.,64.],4,1),1e-12))
2373 # ! [PySnippetDataArrayApplyFunc1_6]
2374 # ! [PySnippetDataArrayApplyFunc1_7]
2375         ddd=DataArrayDouble.New([1.,4.,3.,11.,144.,13.,21.,484.,23.,31.,1024.,33.],4,3)
2376         ddd.setInfoOnComponents(["Y [m]","AA [m/s]","GG [MW]"])
2377 # ! [PySnippetDataArrayApplyFunc1_7]
2378 # ! [PySnippetDataArrayApplyFunc1_8]
2379         ddd1=ddd.applyFunc2(1,"Y+GG")
2380         self.assertTrue(ddd1.isEqual(DataArrayDouble([4.,24.,44.,64.],4,1),1e-12))
2381 # ! [PySnippetDataArrayApplyFunc1_8]
2382 # ! [PySnippetDataArrayApplyFunc1_9]
2383         ddd1=ddd.applyFunc3(1,["X","Y","Z"],"X+Z")
2384         self.assertTrue(ddd1.isEqual(DataArrayDouble([4.,24.,44.,64.],4,1),1e-12))
2385 # ! [PySnippetDataArrayApplyFunc1_9]
2386         return
2387
2388     pass
2389
2390 unittest.main()