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