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