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