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