]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/MEDCoupling_Swig/MEDCouplingRemapperTest.py
Salome HOME
Add MEDCouplingRemapper.ToCSRMatrix static method to compare matrices
[tools/medcoupling.git] / src / MEDCoupling_Swig / MEDCouplingRemapperTest.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2020  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 MEDCouplingDataForTest import MEDCouplingDataForTest
22 from MEDCouplingRemapper import *
23 from math import *
24 import unittest
25
26 class MEDCouplingBasicsTest(unittest.TestCase):
27     def testRemapper1(self):
28         sourceMesh=self.build2DSourceMesh_1();
29         targetMesh=self.build2DTargetMesh_1();
30         remapper=MEDCouplingRemapper()
31         remapper.setPrecision(1e-12);
32         remapper.setIntersectionType(Triangulation);
33         self.assertTrue(remapper.prepare(sourceMesh,targetMesh,"P0P0")==1);
34         srcField=MEDCouplingFieldDouble.New(ON_CELLS);
35         srcField.setNature(IntensiveMaximum);
36         srcField.setMesh(sourceMesh);
37         array=DataArrayDouble.New();
38         ptr=sourceMesh.getNumberOfCells()*[None]
39         for i in range(sourceMesh.getNumberOfCells()):
40             ptr[i]=float(i+7)
41             pass
42         array.setValues(ptr,sourceMesh.getNumberOfCells(),1);
43         srcField.setArray(array);
44         srcField.setName("abc") ; srcField.setDescription("def")
45         srcField.setTime(7.7,9,10)
46         trgfield=remapper.transferField(srcField,4.57);
47         self.assertEqual("abc",trgfield.getName())
48         self.assertEqual("def",trgfield.getDescription())
49         a,b,c=trgfield.getTime()
50         self.assertAlmostEqual(7.7,a,14)
51         self.assertEqual(b,9)
52         self.assertEqual(c,10)
53         values=trgfield.getArray().getValues();
54         valuesExpected=[7.5 ,7. ,7.,8.,7.5];
55         for i in range(targetMesh.getNumberOfCells()):
56             self.assertTrue(abs(values[i]-valuesExpected[i])<1e-12);
57             pass
58         self.assertTrue(1==trgfield.getArray().getNumberOfComponents());
59         pass
60
61     def testPrepareEx1(self):
62         sourceMesh=self.build2DSourceMesh_1();
63         targetMesh=self.build2DTargetMesh_3();
64         #
65         remapper=MEDCouplingRemapper();
66         remapper.setPrecision(1e-12);
67         remapper.setIntersectionType(Triangulation);
68         srcFt=MEDCouplingFieldTemplate.New(ON_CELLS);
69         trgFt=MEDCouplingFieldTemplate.New(ON_CELLS);
70         srcFt.setMesh(sourceMesh);
71         trgFt.setMesh(targetMesh);
72         self.assertEqual(1,remapper.prepareEx(srcFt,trgFt));
73         srcField=MEDCouplingFieldDouble.New(ON_CELLS);
74         srcField.setNature(IntensiveMaximum);
75         srcField.setMesh(sourceMesh);
76         array=DataArrayDouble.New();
77         ptr=sourceMesh.getNumberOfCells()*[None]
78         for i in range(sourceMesh.getNumberOfCells()):
79             ptr[i]=float(i+7);
80             pass
81         array.setValues(ptr,sourceMesh.getNumberOfCells(),1);
82         srcField.setArray(array);
83         trgfield=remapper.transferField(srcField,4.220173);
84         values=trgfield.getArray().getValues();
85         valuesExpected=[7.75, 7.0625, 4.220173,8.0]
86         self.assertEqual(4,trgfield.getArray().getNumberOfTuples());
87         self.assertEqual(1,trgfield.getArray().getNumberOfComponents());
88         for i0 in range(4):
89             self.assertAlmostEqual(valuesExpected[i0],values[i0],12);
90             pass
91         pass
92
93     def testPartialTransfer1(self):
94         sourceMesh=self.build2DSourceMesh_1();
95         targetMesh=self.build2DTargetMesh_3();
96         #
97         remapper=MEDCouplingRemapper();
98         remapper.setPrecision(1e-12);
99         remapper.setIntersectionType(Triangulation);
100         srcFt=MEDCouplingFieldTemplate.New(ON_CELLS);
101         trgFt=MEDCouplingFieldTemplate.New(ON_CELLS);
102         srcFt.setMesh(sourceMesh);
103         trgFt.setMesh(targetMesh);
104         self.assertEqual(1,remapper.prepareEx(srcFt,trgFt));
105         srcField=MEDCouplingFieldDouble.New(ON_CELLS);
106         srcField.setNature(IntensiveMaximum);
107         srcField.setMesh(sourceMesh);
108         array=DataArrayDouble.New();
109         ptr=sourceMesh.getNumberOfCells()*[None]
110         for i in range(sourceMesh.getNumberOfCells()):
111             ptr[i]=float(i+7);
112             pass
113         array.setValues(ptr,sourceMesh.getNumberOfCells(),1);
114         srcField.setArray(array);
115         trgfield=MEDCouplingFieldDouble.New(ON_CELLS);
116         trgfield.setNature(IntensiveMaximum);
117         trgfield.setMesh(targetMesh);
118         array=DataArrayDouble.New();
119         ptr=targetMesh.getNumberOfCells()*[None]
120         for i in range(targetMesh.getNumberOfCells()):
121             ptr[i]=4.220173;
122             pass
123         array.setValues(ptr,targetMesh.getNumberOfCells(),1);
124         trgfield.setArray(array);
125         remapper.partialTransfer(srcField,trgfield);
126         values=trgfield.getArray().getValues();
127         valuesExpected=[7.75, 7.0625, 4.220173,8.0]
128         self.assertEqual(4,trgfield.getArray().getNumberOfTuples());
129         self.assertEqual(1,trgfield.getArray().getNumberOfComponents());
130         for i0 in range(4):
131             self.assertAlmostEqual(valuesExpected[i0],values[i0],12);
132             pass
133         pass
134
135     def testPrepareUC(self):
136         # 1D
137         coords=DataArrayDouble([0.,0.5,0.7])
138         src=MEDCouplingUMesh("",1) ; src.setCoords(coords)
139         src.allocateCells(2) ; src.insertNextCell(NORM_SEG2,[0,1]) ; src.insertNextCell(NORM_SEG2,[1,2]) ; src.finishInsertingCells()
140         trg=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.7,-0.1,0.2,0.7,2.,2.3])
141         trg.setCoordsAt(0,arr)
142         fieldSrc=MEDCouplingFieldDouble(ON_CELLS,NO_TIME) ; fieldSrc.setMesh(src) ; arrSrc=DataArrayDouble([10.,30.])
143         fieldSrc.setNature(ExtensiveMaximum) ;  fieldSrc.setArray(arrSrc)
144         rem=MEDCouplingRemapper()
145         rem.prepare(src,trg,"P0P0")
146         trgField=rem.transferField(fieldSrc,-7.)
147         expected1=[-7.,4.,36.,-7.,-7.]
148         self.assertEqual(5,trgField.getArray().getNumberOfTuples())
149         self.assertEqual(5,len(expected1))
150         for i,val in enumerate(expected1):
151             self.assertAlmostEqual(expected1[i],trgField.getArray().getIJ(i,0),12);
152             pass
153         # 2D
154         coords=DataArrayDouble([0.,0.,0.,1.,1.,1.,1.,0.,0.5,-0.2],5,2)
155         src=MEDCouplingUMesh("",2) ; src.setCoords(coords)
156         src.allocateCells(2) ; src.insertNextCell(NORM_TRI3,[0,1,2]) ; src.insertNextCell(NORM_TRI3,[3,4,0]) ; src.finishInsertingCells()
157         trg=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.7,-0.1,0.2,0.7,2.,2.3])
158         trg.setCoordsAt(0,arr) ; trg.setCoordsAt(1,arr)
159         fieldSrc=MEDCouplingFieldDouble(ON_CELLS,NO_TIME) ; fieldSrc.setMesh(src) ; arrSrc=DataArrayDouble([10.,30.])
160         fieldSrc.setNature(ExtensiveMaximum) ;  fieldSrc.setArray(arrSrc)
161         rem=MEDCouplingRemapper()
162         rem.prepare(src,trg,"P0P0")
163         trgField=rem.transferField(fieldSrc,-7.)
164         expected2=[-7.,-7.,7.35,0.15,-7.,-7.,2.8,14.85,5.25,-7.,-7.,2.,2.5,-7.,-7.,-7.,1.2,3.,0.9,-7.,-7.,-7.,-7.,-7.,-7.]
165         self.assertEqual(25,trgField.getArray().getNumberOfTuples())
166         self.assertEqual(25,len(expected2))
167         for i,val in enumerate(expected2):
168             self.assertAlmostEqual(expected2[i],trgField.getArray().getIJ(i,0),12);
169             pass
170         # 3D
171         coords=DataArrayDouble([0.,0.,0.,0.,1.,0.,1.,1.,0.,1.,0.,0.,0.5,-0.2,0.,0.1,0.8,1.,0.5,0.,1.],7,3)
172         src=MEDCouplingUMesh("",3) ; src.setCoords(coords)
173         src.allocateCells(2) ; src.insertNextCell(NORM_TETRA4,[0,1,2,5]) ; src.insertNextCell(NORM_TETRA4,[3,4,0,6]) ; src.finishInsertingCells()
174         trg=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.7,-0.1,0.2,0.7,2.,2.3]) ; arr2=DataArrayDouble([-0.7,0.2,0.6,1.2,2.])
175         trg.setCoordsAt(0,arr) ; trg.setCoordsAt(1,arr) ; trg.setCoordsAt(2,arr2)
176         src.checkConsistency(1e-10)
177         trg.checkConsistencyLight()
178         fieldSrc=MEDCouplingFieldDouble(ON_CELLS,NO_TIME) ; fieldSrc.setMesh(src) ; arrSrc=DataArrayDouble([10.,30.])
179         fieldSrc.setNature(ExtensiveMaximum) ;  fieldSrc.setArray(arrSrc)
180         rem=MEDCouplingRemapper()
181         rem.prepare(src,trg,"P0P0")
182         trgField=rem.transferField(fieldSrc,-7.)
183         expected3=[-7.,-7.,2.925,0.015,-7.,-7.,0.9392,8.595,2.265,-7.,-7.,1.1008,1.1192,-7.,-7.,-7.,0.6392,1.6408,0.2808,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,0.81,-7.,-7.,-7.,0.1208,11.55,0.96,-7.,-7.,1.1752,0.6592,-7.,-7.,-7.,0.8512,1.7744,0.0192,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,1.92,-7.,-7.,-7.,0.12578571428571422,0.007314285714285673,-7.,-7.,-7.,0.3189253968253971,0.1879746031746033,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.]
184         self.assertEqual(100,trgField.getArray().getNumberOfTuples())
185         self.assertEqual(100,len(expected3))
186         for i,val in enumerate(expected3):
187             self.assertAlmostEqual(expected3[i],trgField.getArray().getIJ(i,0),12);
188             pass
189         pass
190
191     def testPrepareCU(self):
192         # 1D
193         coords=DataArrayDouble([0.,0.5,0.7])
194         trg=MEDCouplingUMesh("",1) ; trg.setCoords(coords)
195         trg.allocateCells(2) ; trg.insertNextCell(NORM_SEG2,[0,1]) ; trg.insertNextCell(NORM_SEG2,[1,2]) ; trg.finishInsertingCells()
196         src=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.7,-0.1,0.2,0.7,2.,2.3])
197         src.setCoordsAt(0,arr)
198         fieldSrc=MEDCouplingFieldDouble(ON_CELLS,NO_TIME) ; fieldSrc.setMesh(src) ; arrTrg=DataArrayDouble([10.,30.,40.,70.,80.])
199         fieldSrc.setNature(ExtensiveMaximum) ;  fieldSrc.setArray(arrTrg)
200         rem=MEDCouplingRemapper()
201         rem.prepare(src,trg,"P0P0")
202         trgField=rem.transferField(fieldSrc,-7.)
203         expected1=[44.,16.]
204         self.assertEqual(2.,trgField.getArray().getNumberOfTuples())
205         self.assertEqual(2,len(expected1))
206         for i,val in enumerate(expected1):
207             self.assertAlmostEqual(expected1[i],trgField.getArray().getIJ(i,0),12);
208             pass
209         # 2D
210         coords=DataArrayDouble([0.,0.,0.,1.,1.,1.,1.,0.,0.5,-0.2],5,2)
211         trg=MEDCouplingUMesh("",2) ; trg.setCoords(coords)
212         trg.allocateCells(2) ; trg.insertNextCell(NORM_TRI3,[0,1,2]) ; trg.insertNextCell(NORM_TRI3,[3,4,0]) ; trg.finishInsertingCells()
213         src=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.7,-0.1,0.2,0.7,2.,2.3])
214         src.setCoordsAt(0,arr) ; src.setCoordsAt(1,arr)
215         fieldSrc=MEDCouplingFieldDouble(ON_CELLS,NO_TIME) ; fieldSrc.setMesh(src) ; arrSrc=DataArrayDouble([10.,30.,40.,70.,80.,110.,130.,140.,170.,180.,210.,230.,240.,270.,280.,310.,330.,340.,370.,380.,410.,430.,440.,470.,480.])
216         fieldSrc.setNature(ExtensiveMaximum) ;  fieldSrc.setArray(arrSrc)
217         rem=MEDCouplingRemapper()
218         rem.prepare(src,trg,"P0P0")
219         trgField=rem.transferField(fieldSrc,-7.)
220         expected2=[441.3050624589086,68.69529914529915]
221         self.assertEqual(2,trgField.getArray().getNumberOfTuples())
222         self.assertEqual(2,len(expected2))
223         for i,val in enumerate(expected2):
224             self.assertAlmostEqual(expected2[i],trgField.getArray().getIJ(i,0),12);
225             pass
226         # 3D
227         coords=DataArrayDouble([0.,0.,0.,0.,1.,0.,1.,1.,0.,1.,0.,0.,0.5,-0.2,0.,0.1,0.8,1.,0.5,0.,1.],7,3)
228         trg=MEDCouplingUMesh("",3) ; trg.setCoords(coords)
229         trg.allocateCells(2) ; trg.insertNextCell(NORM_TETRA4,[0,1,2,5]) ; trg.insertNextCell(NORM_TETRA4,[3,4,0,6]) ; trg.finishInsertingCells()
230         src=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.7,-0.1,0.2,0.7,2.,2.3]) ; arr2=DataArrayDouble([-0.7,0.2,0.6,1.2,2.])
231         src.setCoordsAt(0,arr) ; src.setCoordsAt(1,arr) ; src.setCoordsAt(2,arr2)
232         trg.checkConsistency(1e-10)
233         src.checkConsistencyLight()
234         fieldSrc=MEDCouplingFieldDouble(ON_CELLS,NO_TIME) ; fieldSrc.setMesh(src) ; arrSrc=DataArrayDouble(100) ; arrSrc.iota(7.7)
235         fieldSrc.setNature(ExtensiveMaximum) ;  fieldSrc.setArray(arrSrc)
236         rem=MEDCouplingRemapper()
237         rem.prepare(src,trg,"P0P0")
238         trgField=rem.transferField(fieldSrc,-7.)
239         expected3=[39.635196634558845,12.13422356758468]
240         self.assertEqual(2,trgField.getArray().getNumberOfTuples())
241         self.assertEqual(2,len(expected3))
242         for i,val in enumerate(expected3):
243             self.assertAlmostEqual(expected3[i],trgField.getArray().getIJ(i,0),12);
244             pass
245         pass
246
247     def testPrepareCC(self):
248         # 1D
249         src=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.7,-0.1,0.2,0.7,2.,2.3])
250         src.setCoordsAt(0,arr)
251         trg=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.9,-0.1,0.15])
252         trg.setCoordsAt(0,arr)
253         fieldSrc=MEDCouplingFieldDouble(ON_CELLS,NO_TIME) ; fieldSrc.setMesh(src) ; arrTrg=DataArrayDouble([10.,30.,40.,70.,80.])
254         fieldSrc.setNature(ExtensiveMaximum) ;  fieldSrc.setArray(arrTrg)
255         rem=MEDCouplingRemapper()
256         rem.prepare(src,trg,"P0P0")
257         trgField=rem.transferField(fieldSrc,-7.)
258         expected1=[10.,25.]
259         self.assertEqual(2.,trgField.getArray().getNumberOfTuples())
260         self.assertEqual(2,len(expected1))
261         for i,val in enumerate(expected1):
262             self.assertAlmostEqual(expected1[i],trgField.getArray().getIJ(i,0),12);
263             pass
264         # 2D
265         src=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.7,-0.1,0.2,0.7,2.,2.3])
266         src.setCoordsAt(0,arr) ; src.setCoordsAt(1,arr)
267         trg=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.9,-0.1,0.15])
268         trg.setCoordsAt(0,arr) ; trg.setCoordsAt(1,arr)
269         fieldSrc=MEDCouplingFieldDouble(ON_CELLS,NO_TIME) ; fieldSrc.setMesh(src) ; arrSrc=DataArrayDouble([10.,30.,40.,70.,80.,110.,130.,140.,170.,180.,210.,230.,240.,270.,280.,310.,330.,340.,370.,380.,410.,430.,440.,470.,480.])
270         fieldSrc.setNature(ExtensiveMaximum) ;  fieldSrc.setArray(arrSrc)
271         rem=MEDCouplingRemapper()
272         rem.prepare(src,trg,"P0P0")
273         trgField=rem.transferField(fieldSrc,-7.)
274         expected2=[10.,25.,91.66666666666666,90.27777777777777]
275         self.assertEqual(4,trgField.getArray().getNumberOfTuples())
276         self.assertEqual(4,len(expected2))
277         for i,val in enumerate(expected2):
278             self.assertAlmostEqual(expected2[i],trgField.getArray().getIJ(i,0),12);
279             pass
280         # 3D
281         src=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.7,-0.1,0.2,0.7,2.,2.3])
282         src.setCoordsAt(0,arr) ; src.setCoordsAt(1,arr) ; src.setCoordsAt(2,arr)
283         trg=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.9,-0.1,0.15])
284         trg.setCoordsAt(0,arr) ; trg.setCoordsAt(1,arr) ; trg.setCoordsAt(2,arr)
285         fieldSrc=MEDCouplingFieldDouble(ON_CELLS,NO_TIME) ; fieldSrc.setMesh(src) ; arrSrc=DataArrayDouble(125) ; arrSrc.iota(7.7)
286         fieldSrc.setNature(ExtensiveMaximum) ;  fieldSrc.setArray(arrSrc) ; fieldSrc.checkConsistencyLight()
287         rem=MEDCouplingRemapper()
288         rem.prepare(src,trg,"P0P0")
289         trgField=rem.transferField(fieldSrc,-7.)
290         expected3=[7.7, 7.249999999999999, 10.583333333333332, 9.513888888888886, 27.25, 23.40277777777777, 26.180555555555546, 22.39583333333333]
291         self.assertEqual(8,trgField.getArray().getNumberOfTuples())
292         self.assertEqual(8,len(expected3))
293         for i,val in enumerate(expected3):
294             self.assertAlmostEqual(expected3[i],trgField.getArray().getIJ(i,0),12);
295             pass
296         pass
297
298     # Bug when source mesh is not homogeneously oriented in source mesh
299     def testNonRegressionNonHomegenousOrriented3DCells(self):
300         csrc=DataArrayDouble([-0.15240000188350677,0,0,-0.1086929515004158,0,0,-0.15240000188350677,0.018142856657505035,0,-0.13054648041725159,0.0090714283287525177,0.019050000235438347,-0.13054648041725159,0.0090714283287525177,0],5,3)
301         src1=MEDCouplingUMesh("src",3) ; src1.allocateCells(0) ; src1.insertNextCell(NORM_TETRA4,[0,1,4,3]) ; src1.insertNextCell(NORM_TETRA4,[2,0,4,3])
302         src2=MEDCouplingUMesh("src",3) ; src2.allocateCells(0) ; src2.insertNextCell(NORM_TETRA4,[0,4,1,3]) ; src2.insertNextCell(NORM_TETRA4,[2,0,4,3])
303         src1.setCoords(csrc) ; src2.setCoords(csrc)
304         ctrg=DataArrayDouble([-0.15240000188350677,-0.038100000470876694,0,0.32379999756813049,-0.038100000470876694,0,-0.15240000188350677,0.076200000941753387,0,0.32379999756813049,0.076200000941753387,0,-0.15240000188350677,-0.038100000470876694,0.076200000941753387,0.32379999756813049,-0.038100000470876694,0.076200000941753387,-0.15240000188350677,0.076200000941753387,0.076200000941753387,0.32379999756813049,0.076200000941753387,0.076200000941753387],8,3)
305         trg=MEDCouplingUMesh("trg",3) ; trg.allocateCells(0) ; trg.insertNextCell(NORM_HEXA8,[0,1,3,2,4,5,7,6])
306         trg.setCoords(ctrg)
307         rem1=MEDCouplingRemapper() ; rem1.setSplittingPolicy(PLANAR_FACE_5) ; rem1.prepare(src1,trg,"P0P0")
308         rem2=MEDCouplingRemapper() ; rem2.setSplittingPolicy(PLANAR_FACE_5) ; rem2.prepare(src1,trg,"P0P0")
309         mat1=rem1.getCrudeMatrix() ; mat2=rem2.getCrudeMatrix()
310         self.assertEqual(1,len(mat1)) ; self.assertEqual(1,len(mat2))
311         self.assertEqual(list(mat1[0].keys()),list(mat2[0].keys())) ; self.assertEqual([0,1],list(mat1[0].keys()))
312         self.assertAlmostEqual(1.25884108122e-06,mat1[0][0],16) ; self.assertAlmostEqual(1.25884108122e-06,mat2[0][0],16)
313         self.assertAlmostEqual(1.25884086663e-06,mat1[0][1],16) ; self.assertAlmostEqual(1.25884086663e-06,mat2[0][1],16)
314         #
315         d=DataArrayDouble([13.45,27.67],2,1)
316         f1=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f1.setMesh(src1) ; f1.setArray(d) ; f1.setNature(IntensiveConservation)
317         f2=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f2.setMesh(src2) ; f2.setArray(d) ; f2.setNature(IntensiveConservation)
318         f11=rem1.transferField(f1,1e300) ; f22=rem2.transferField(f2,1e300)
319         expected1=DataArrayDouble([0.012480539537637884])
320         self.assertTrue(f11.getArray().isEqual(expected1,1e-15))
321         self.assertTrue(f22.getArray().isEqual(expected1,1e-15))
322         #
323         f1.setNature(ExtensiveMaximum) ; f2.setNature(ExtensiveMaximum)
324         f11=rem1.transferField(f1,1e300) ; f22=rem2.transferField(f2,1e300)
325         #
326         expected2=DataArrayDouble([41.12])
327         self.assertTrue(f11.getArray().isEqual(expected2,1e-13))
328         self.assertTrue(f22.getArray().isEqual(expected2,1e-13))
329         pass
330
331     def testCellToNodeReverse3D(self):
332         c=DataArrayDouble([0.,1.,2.5])
333         cc=MEDCouplingCMesh()
334         cc.setCoords(c,c,c)
335         um=cc.buildUnstructured()
336         f=um.getMeasureField(False)
337         #
338         n2o=um.simplexize(PLANAR_FACE_5)
339         f.setArray(f.getArray()[n2o])
340         f.checkConsistencyLight()
341         f.setNature(IntensiveMaximum)
342         f.setTime(5.6,7,8)
343         f.setName("toto") ; f.setDescription("aDescription")
344         p=MEDCouplingRemapper()
345         p.setIntersectionType(Barycentric)
346         p.prepare(um,um,"P1P0")
347         fNode=p.reverseTransferField(f,1e300)
348         self.assertEqual("toto",fNode.getName())
349         self.assertEqual("aDescription",fNode.getDescription())
350         a,b,c=fNode.getTime()
351         self.assertAlmostEqual(5.6,a,14)
352         self.assertEqual(7,b) ; self.assertEqual(8,c)
353         #
354         integExpected=34.328125
355         self.assertAlmostEqual(fNode.integral(False)[0],integExpected,14)
356         self.assertAlmostEqual(f.integral(False)[0],integExpected,14)
357         pass
358
359     def testGauss2Gauss2DValidated(self):
360         srcFt=MEDCouplingDataForTest.buildFieldOnGauss_1()
361         trgFt=MEDCouplingDataForTest.buildFieldOnGauss_2()
362         src=MEDCouplingFieldDouble(srcFt)
363         self.assertEqual(srcFt.getMesh().getHiddenCppPointer(),src.getMesh().getHiddenCppPointer())
364         self.assertEqual(srcFt.getDiscretization().getHiddenCppPointer(),src.getDiscretization().getHiddenCppPointer())
365         #values given by ASTER usecase
366         src.setArray(DataArrayDouble([1.,1.,0.,0.,1.,1.,1.,1.,0.,0.,1.,1.,1.,1.,1.,1.,0.,0.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,0.,0.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,0.,0.,0.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,0.,0.,0.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,0.,0.,0.,0.,0.,0.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,0.,0.,0.,0.,0.,0.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.]))
367         src.getArray().setInfoOnComponents(["DOMA"])
368         rem=MEDCouplingRemapper()
369         rem.setIntersectionType(PointLocator)
370         rem.prepareEx(srcFt,trgFt)
371         trg=rem.transferField(src,1e300)
372         self.assertEqual(trg.getMesh().getHiddenCppPointer(),trgFt.getMesh().getHiddenCppPointer())
373         self.assertEqual(trg.getDiscretization().getHiddenCppPointer(),trgFt.getDiscretization().getHiddenCppPointer())
374         #values given after interpolation in ASTER
375         arrExpected=DataArrayDouble([1.,1.,1.,0.,0.,0.,1.,1.,1.,1.,1.,0.,0.,0.,1.,1.,1.,1.,1.,0.,0.,0.,1.,1.,1.,1.,1.,0.,0.,0.,1.,1.,1.,1.,1.,0.,0.,0.,1.,1.,1.,1.,1.,1.,1.,0.,0.,1.,0.,1.,1.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,0.,1.,0.,1.,1.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,0.,1.,0.,1.,1.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,0.,1.,0.,1.,1.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,0.,1.,0.,1.,1.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,1.,0.,0.,0.,0.,1.,1.,1.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,1.,0.,0.,0.,0.,1.,1.,1.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,1.,0.,0.,0.,0.,1.,1.,1.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,1.,0.,0.,0.,0.,1.,1.,1.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,1.,0.,0.,0.,0.,1.,1.,1.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,0.,1.,0.,0.,0.,1.,0.,0.,1.,1.,0.,0.,1.,0.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,0.,1.,0.,0.,0.,1.,0.,0.,1.,1.,0.,0.,1.,0.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,0.,1.,0.,0.,0.,1.,0.,0.,1.,1.,0.,0.,1.,0.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,0.,1.,0.,0.,0.,1.,0.,0.,1.,1.,0.,0.,1.,0.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,0.,1.,0.,0.,0.,1.,0.,0.,1.,1.,0.,0.,1.,0.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.]) ; arrExpected.setInfoOnComponents(["DOMA"])
376         self.assertTrue(trg.getArray().isEqual(arrExpected,1e-12))
377         #
378         # second part of the test : reverse source and target
379         #
380         rem.prepareEx(trgFt,srcFt)# sorry trgFt is in the place of source and srcFt in the place of target it is not a bug
381         trg=MEDCouplingFieldDouble(trgFt)
382         #values given after interpolation in ASTER
383         trg.setArray(DataArrayDouble([1.,1.,0.,0.,1.,0.,1.,1.,1.,1.,0.,0.,1.,0.,1.,1.,1.,1.,0.,0.,1.,0.,1.,1.,1.,1.,0.,0.,1.,0.,1.,1.,1.,1.,0.,0.,1.,0.,1.,1.,1.,1.,1.,1.,1.,0.,0.,1.,0.,1.,1.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,0.,1.,0.,1.,1.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,0.,1.,0.,1.,1.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,0.,1.,0.,1.,1.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,0.,1.,0.,1.,1.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,1.,0.,0.,0.,0.,1.,1.,0.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,1.,0.,0.,0.,0.,1.,1.,0.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,1.,0.,0.,0.,0.,1.,1.,0.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,1.,0.,0.,0.,0.,1.,1.,0.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,1.,0.,0.,0.,0.,1.,1.,0.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,0.,1.,0.,0.,0.,1.,0.,0.,1.,1.,0.,0.,1.,0.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,0.,1.,0.,0.,0.,1.,0.,0.,1.,1.,0.,0.,1.,0.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,0.,1.,0.,0.,0.,1.,0.,0.,1.,1.,0.,0.,1.,0.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,0.,1.,0.,0.,0.,1.,0.,0.,1.,1.,0.,0.,1.,0.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,0.,1.,0.,0.,0.,1.,0.,0.,1.,1.,0.,0.,1.,0.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.]))
384         trg.getArray().setInfoOnComponents(["DOMA"])
385         src=rem.transferField(trg,1e300)
386         #values given after interpolation in ASTER
387         arrExpected2=DataArrayDouble([1.,1.,0.,0.,1.,1.,1.,1.,0.,0.,1.,1.,1.,1.,1.,1.,0.,0.,0.,0.,1.,1.,1., 1.,1.,1.,1.,1.,0.,0.,0.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,0.,0.,0.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,0.,0.,0.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,0.,1.,1.,0.,1.,1.,1.,1.,0.,0.,0.,0.,1.,0.,0.,0.,1.,1.,1.,0.,1.,1.,1.,1.,1.,1.,0.,0.,1.,1.,0.,1.,1.,1.,0.,1.,0.,0.,0.,1.,0.,0.,0.,1.,1.,1.,0.,1.,1.,1.,1.,1.]) ; arrExpected2.setInfoOnComponents(["DOMA"])
388         # modification of values in ASTER due to modification of algorithm
389         # target PG 82 in target cell 32(C)/36 PG 1(C)/9 is in source cell 58(C)/120 source Gauss point 113 (1(C)/4). Values must be 1. and not 0.
390         arrExpected2.setIJ(82,0,1.)
391         self.assertTrue(src.getArray().isEqual(arrExpected2,1e-12))
392         pass
393
394     def testGauss2Gauss3DValidated(self):
395         srcFt=MEDCouplingDataForTest.buildFieldOnGauss_3()
396         trgFt=MEDCouplingDataForTest.buildFieldOnGauss_4()
397         src=MEDCouplingFieldDouble(srcFt)
398         self.assertEqual(srcFt.getMesh().getHiddenCppPointer(),src.getMesh().getHiddenCppPointer())
399         self.assertEqual(srcFt.getDiscretization().getHiddenCppPointer(),src.getDiscretization().getHiddenCppPointer())
400         #values given by ASTER usecase
401         src.setArray(DataArrayDouble([0.,1.,1.,1.,1.,1.,0.,0.,0.,0.,0.,0.,0.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,0.,0.,0.,0.,1.,1.,0.,0.,1.,1.,1.,1.,0.,0.,1.,1.,0.,0.]))
402         src.getArray().setInfoOnComponents(["DOMA"])
403         rem=MEDCouplingRemapper()
404         rem.setIntersectionType(PointLocator)
405         rem.prepareEx(srcFt,trgFt)
406         trg=rem.transferField(src,1e300)
407         self.assertEqual(trg.getMesh().getHiddenCppPointer(),trgFt.getMesh().getHiddenCppPointer())
408         self.assertEqual(trg.getDiscretization().getHiddenCppPointer(),trgFt.getDiscretization().getHiddenCppPointer())
409         #values given after interpolation in ASTER
410         arrExpected=DataArrayDouble([0.,1.,1.,1.,1.,1.,0.,0.,0.,0.,0.,0.,0.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,1.,0.,0.,0.,1.,1.,0.,0.,1.,1.,1.,1.,0.,1.,1.,1.,0.,1.]) ; arrExpected.setInfoOnComponents(["DOMA"])
411         self.assertTrue(trg.getArray().isEqual(arrExpected,1e-12))
412         #
413         # second part of the test : reverse source and target
414         #
415         rem.prepareEx(trgFt,srcFt)# sorry trgFt is in the place of source and srcFt in the place of target it is not a bug
416         trg=MEDCouplingFieldDouble(trgFt)
417         #values given after interpolation in ASTER
418         trg.setArray(DataArrayDouble([0.,1.,1.,1.,1.,1.,0.,0.,0.,0.,0.,0.,0.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,0.,1.,1.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.]))
419         trg.getArray().setInfoOnComponents(["DOMA"])
420         src=rem.transferField(trg,1e300)
421         #values given after interpolation in ASTER
422         arrExpected2=DataArrayDouble([0.,1.,1.,1.,1.,1.,0.,0.,0.,0.,0.,0.,0.,0.,0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,0.,1.,0.,1.,0.,1.,1.,1.,0.,1.,1.,1.,1.,0.,1.,1.,1.,0.,1.]) ; arrExpected2.setInfoOnComponents(["DOMA"])
423         self.assertTrue(src.getArray().isEqual(arrExpected2,1e-12))
424         pass
425
426     def testSwig2MixOfUMesh(self):
427         arr0=DataArrayDouble([0,1,1.5]) ; arr1=DataArrayDouble([0,1])
428         sc=MEDCouplingCMesh() ; sc.setCoords(arr0,arr1,arr1)
429         tc=sc.deepCopy() ; tc.translate([0.4,0.3,0.3])
430         # umesh-umesh
431         # 90 (umesh-1sgtumesh)
432         rem=MEDCouplingRemapper() ; rem.setIntersectionType(Triangulation)
433         s=sc.buildUnstructured() ; t=tc.build1SGTUnstructured()
434         self.assertTrue(isinstance(s,MEDCouplingUMesh))
435         self.assertTrue(isinstance(t,MEDCoupling1SGTUMesh))
436         rem.prepare(s,t,"P0P0")
437         mat=rem.getCrudeMatrix()
438         self.assertEqual(2,len(mat)) ; self.assertEqual(2,len(mat[0])) ; self.assertEqual(1,len(mat[1]))
439         self.assertAlmostEqual(0.294,mat[0][0],14) ; self.assertAlmostEqual(0.196,mat[0][1],14) ; self.assertAlmostEqual(0.049,mat[1][1],14)
440         del s,t
441         # 91 (umesh-1dgtumesh)
442         rem=MEDCouplingRemapper() ; rem.setIntersectionType(Triangulation)
443         s=sc.buildUnstructured() ; t=tc.buildUnstructured() ; t.convertAllToPoly() ; t=MEDCoupling1DGTUMesh(t)
444         self.assertTrue(isinstance(s,MEDCouplingUMesh))
445         self.assertTrue(isinstance(t,MEDCoupling1DGTUMesh))
446         rem.prepare(s,t,"P0P0")
447         mat=rem.getCrudeMatrix()
448         self.assertEqual(2,len(mat)) ; self.assertEqual(2,len(mat[0])) ; self.assertEqual(1,len(mat[1]))
449         self.assertAlmostEqual(0.294,mat[0][0],14) ; self.assertAlmostEqual(0.196,mat[0][1],14) ; self.assertAlmostEqual(0.049,mat[1][1],14)
450         del s,t
451         # 165 (1sgtumesh-umesh)
452         rem=MEDCouplingRemapper() ; rem.setIntersectionType(Triangulation)
453         s=sc.build1SGTUnstructured() ; t=tc.buildUnstructured()
454         self.assertTrue(isinstance(s,MEDCoupling1SGTUMesh))
455         self.assertTrue(isinstance(t,MEDCouplingUMesh))
456         rem.prepare(s,t,"P0P0")
457         mat=rem.getCrudeMatrix()
458         self.assertEqual(2,len(mat)) ; self.assertEqual(2,len(mat[0])) ; self.assertEqual(1,len(mat[1]))
459         self.assertAlmostEqual(0.294,mat[0][0],14) ; self.assertAlmostEqual(0.196,mat[0][1],14) ; self.assertAlmostEqual(0.049,mat[1][1],14)
460         del s,t
461         # 181 (1dgtumesh-umesh
462         rem=MEDCouplingRemapper() ; rem.setIntersectionType(Triangulation)
463         s=sc.buildUnstructured() ; s.convertAllToPoly() ; s=MEDCoupling1DGTUMesh(s) ; t=tc.buildUnstructured()
464         self.assertTrue(isinstance(s,MEDCoupling1DGTUMesh))
465         self.assertTrue(isinstance(t,MEDCouplingUMesh))
466         rem.prepare(s,t,"P0P0")
467         mat=rem.getCrudeMatrix()
468         self.assertEqual(2,len(mat)) ; self.assertEqual(2,len(mat[0])) ; self.assertEqual(1,len(mat[1]))
469         self.assertAlmostEqual(0.294,mat[0][0],14) ; self.assertAlmostEqual(0.196,mat[0][1],14) ; self.assertAlmostEqual(0.049,mat[1][1],14)
470         del s,t
471         # 170 (1sgtumesh-1sgtumesh)
472         rem=MEDCouplingRemapper() ; rem.setIntersectionType(Triangulation)
473         s=sc.build1SGTUnstructured() ; t=tc.build1SGTUnstructured()
474         self.assertTrue(isinstance(s,MEDCoupling1SGTUMesh))
475         self.assertTrue(isinstance(t,MEDCoupling1SGTUMesh))
476         rem.prepare(s,t,"P0P0")
477         mat=rem.getCrudeMatrix()
478         self.assertEqual(2,len(mat)) ; self.assertEqual(2,len(mat[0])) ; self.assertEqual(1,len(mat[1]))
479         self.assertAlmostEqual(0.294,mat[0][0],14) ; self.assertAlmostEqual(0.196,mat[0][1],14) ; self.assertAlmostEqual(0.049,mat[1][1],14)
480         del s,t
481         # 171 (1sgtumesh-1dgtumesh)
482         rem=MEDCouplingRemapper() ; rem.setIntersectionType(Triangulation)
483         s=sc.build1SGTUnstructured() ; t=tc.buildUnstructured() ; t.convertAllToPoly() ; t=MEDCoupling1DGTUMesh(t)
484         self.assertTrue(isinstance(s,MEDCoupling1SGTUMesh))
485         self.assertTrue(isinstance(t,MEDCoupling1DGTUMesh))
486         rem.prepare(s,t,"P0P0")
487         mat=rem.getCrudeMatrix()
488         self.assertEqual(2,len(mat)) ; self.assertEqual(2,len(mat[0])) ; self.assertEqual(1,len(mat[1]))
489         self.assertAlmostEqual(0.294,mat[0][0],14) ; self.assertAlmostEqual(0.196,mat[0][1],14) ; self.assertAlmostEqual(0.049,mat[1][1],14)
490         del s,t
491         # 186 (1dgtumesh-1sgtumesh)
492         rem=MEDCouplingRemapper() ; rem.setIntersectionType(Triangulation)
493         s=sc.buildUnstructured() ; s.convertAllToPoly() ; s=MEDCoupling1DGTUMesh(s) ; t=tc.build1SGTUnstructured()
494         self.assertTrue(isinstance(s,MEDCoupling1DGTUMesh))
495         self.assertTrue(isinstance(t,MEDCoupling1SGTUMesh))
496         rem.prepare(s,t,"P0P0")
497         mat=rem.getCrudeMatrix()
498         self.assertEqual(2,len(mat)) ; self.assertEqual(2,len(mat[0])) ; self.assertEqual(1,len(mat[1]))
499         self.assertAlmostEqual(0.294,mat[0][0],14) ; self.assertAlmostEqual(0.196,mat[0][1],14) ; self.assertAlmostEqual(0.049,mat[1][1],14)
500         del s,t
501         # 187 (1dgtumesh-1dgtumesh)
502         rem=MEDCouplingRemapper() ; rem.setIntersectionType(Triangulation)
503         s=sc.buildUnstructured() ; s.convertAllToPoly() ; s=MEDCoupling1DGTUMesh(s) ; t=tc.buildUnstructured() ; t.convertAllToPoly() ; t=MEDCoupling1DGTUMesh(t)
504         self.assertTrue(isinstance(s,MEDCoupling1DGTUMesh))
505         self.assertTrue(isinstance(t,MEDCoupling1DGTUMesh))
506         rem.prepare(s,t,"P0P0")
507         mat=rem.getCrudeMatrix()
508         self.assertEqual(2,len(mat)) ; self.assertEqual(2,len(mat[0])) ; self.assertEqual(1,len(mat[1]))
509         self.assertAlmostEqual(0.294,mat[0][0],14) ; self.assertAlmostEqual(0.196,mat[0][1],14) ; self.assertAlmostEqual(0.049,mat[1][1],14)
510         del s,t
511         # (umesh-cmesh)
512         # 167 (1sgtumesh-cmesh)
513         rem=MEDCouplingRemapper() ; rem.setIntersectionType(Triangulation)
514         s=sc.build1SGTUnstructured() ; t=tc.deepCopy()
515         self.assertTrue(isinstance(s,MEDCoupling1SGTUMesh))
516         self.assertTrue(isinstance(t,MEDCouplingCMesh))
517         rem.prepare(s,t,"P0P0")
518         mat=rem.getCrudeMatrix()
519         self.assertEqual(2,len(mat)) ; self.assertEqual(2,len(mat[0])) ; self.assertEqual(1,len(mat[1]))
520         self.assertAlmostEqual(0.294,mat[0][0],14) ; self.assertAlmostEqual(0.196,mat[0][1],14) ; self.assertAlmostEqual(0.049,mat[1][1],14)
521         del s,t
522         # 183 (1dgtumesh-cmesh)
523         #rem=MEDCouplingRemapper() ; rem.setIntersectionType(Triangulation)
524         #s=sc.buildUnstructured() ; s.convertAllToPoly() ; s=MEDCoupling1DGTUMesh(s) ; t=tc.deepCopy()
525         #self.assertTrue(isinstance(s,MEDCoupling1DGTUMesh))
526         #self.assertTrue(isinstance(t,MEDCouplingCMesh))
527         #rem.prepare(s,t,"P0P0")
528         #mat=rem.getCrudeMatrix()
529         #self.assertEqual(2,len(mat)) ; self.assertEqual(2,len(mat[0])) ; self.assertEqual(1,len(mat[1]))
530         #self.assertAlmostEqual(0.294,mat[0][0],14) ; self.assertAlmostEqual(0.196,mat[0][1],14) ; self.assertAlmostEqual(0.049,mat[1][1],14)
531         #del s,t
532         # (cmesh-umesh)
533         # 122 (cmesh-1sgtumesh)
534         rem=MEDCouplingRemapper() ; rem.setIntersectionType(Triangulation)
535         s=sc.deepCopy() ; t=tc.build1SGTUnstructured()
536         self.assertTrue(isinstance(s,MEDCouplingCMesh))
537         self.assertTrue(isinstance(t,MEDCoupling1SGTUMesh))
538         rem.prepare(s,t,"P0P0")
539         mat=rem.getCrudeMatrix()
540         self.assertEqual(2,len(mat)) ; self.assertEqual(2,len(mat[0])) ; self.assertEqual(1,len(mat[1]))
541         self.assertAlmostEqual(0.294,mat[0][0],14) ; self.assertAlmostEqual(0.196,mat[0][1],14) ; self.assertAlmostEqual(0.049,mat[1][1],14)
542         del s,t
543         # 123 (cmesh-1dgtumesh)
544         #rem=MEDCouplingRemapper() ; rem.setIntersectionType(Triangulation)
545         #s=sc.deepCopy() ; t=tc.buildUnstructured() ; t.convertAllToPoly() ; t=MEDCoupling1DGTUMesh(t)
546         #self.assertTrue(isinstance(s,MEDCouplingCMesh))
547         #self.assertTrue(isinstance(t,MEDCoupling1DGTUMesh))
548         #rem.prepare(s,t,"P0P0")
549         #mat=rem.getCrudeMatrix()
550         #self.assertEqual(2,len(mat)) ; self.assertEqual(2,len(mat[0])) ; self.assertEqual(1,len(mat[1]))
551         #self.assertAlmostEqual(0.294,mat[0][0],14) ; self.assertAlmostEqual(0.196,mat[0][1],14) ; self.assertAlmostEqual(0.049,mat[1][1],14)
552         #del s,t
553         pass
554
555     def testSwig2BarycentricP1P13D_1(self):
556         sCoo=DataArrayDouble([0.313,0.00218,6.90489,0.313,0.10692667,6.90489,0.313,0.10692667,6.96790167,0.313,0.00218,6.9773125,0.313,0.21167333,6.90489,0.313,0.21167333,6.95849083,0.313,0.31642,6.90489,0.313,0.31642,6.94908,0.313,0.09383333,7.04891667,0.313,0.00218,7.049735,0.313,0.18548667,7.04809833,0.313,0.27714,7.04728,0.313,0.05782667,7.133205,0.313,0.00218,7.1221575,0.313,0.11347333,7.1442525,0.313,0.16912,7.1553,0.313,0.02509333,7.19458,0.313,0.00218,7.19458,0.313,0.04800667,7.19458,0.313,0.07092,7.19458,0.31005609,0.00218,6.90460005,0.31005609,0.10692667,6.90460005,0.29776312,0.10692667,6.96640097,0.29592716,0.00218,6.97563097,0.31005609,0.21167333,6.90460005,0.29959908,0.21167333,6.95717096,0.31005609,0.31642,6.90460005,0.30143505,0.31642,6.94794095,0.28195788,0.09383333,7.04585928,0.28179823,0.00218,7.04666189,0.28211753,0.18548667,7.04505668,0.28227718,0.27714,7.04425407,0.26551404,0.05782667,7.12852804,0.2676693,0.00218,7.11769282,0.26335878,0.11347333,7.13936327,0.26120352,0.16912,7.15019849,0.25354037,0.02509333,7.18872374,0.25354037,0.00218,7.18872374,0.25354037,0.04800667,7.18872374,0.25354037,0.07092,7.18872374,0.30722531,0.00218,6.90374134,0.30722531,0.10692667,6.90374134,0.28311179,0.10692667,6.96195653,0.27951042,0.00218,6.97065101,0.30722531,0.21167333,6.90374134,0.28671316,0.21167333,6.95326205,0.30722531,0.31642,6.90374134,0.29031453,0.31642,6.94456758,0.25210869,0.09383333,7.03680463,0.25179553,0.00218,7.03756067,0.25242185,0.18548667,7.03604859,0.25273501,0.27714,7.03529255,0.21985294,0.05782667,7.1146769,0.22408063,0.00218,7.10447034,0.21562524,0.11347333,7.12488346,0.21139755,0.16912,7.13509002,0.19636574,0.02509333,7.17138,0.19636574,0.00218,7.17138,0.19636574,0.04800667,7.17138,0.19636574,0.07092,7.17138,0.30461645,0.00218,6.90234688,0.30461645,0.10692667,6.90234688,0.26960904,0.10692667,6.95473916,0.26438066,0.00218,6.96256398,0.30461645,0.21167333,6.90234688,0.27483742,0.21167333,6.94691434,0.30461645,0.31642,6.90234688,0.2800658,0.31642,6.93908952,0.22459952,0.09383333,7.02210067,0.22414487,0.00218,7.02278109,0.22505416,0.18548667,7.02142025,0.2255088,0.27714,7.02073983,0.17777143,0.05782667,7.09218386,0.18390909,0.00218,7.0829982,0.17163377,0.11347333,7.10136952,0.1654961,0.16912,7.11055518,0.1436733,0.02509333,7.14321531,0.1436733,0.00218,7.14321531,0.1436733,0.04800667,7.14321531,0.1436733,0.07092,7.14321531,0.30232976,0.00218,6.90047024,0.30232976,0.10692667,6.90047024,0.25777378,0.10692667,6.94502622,0.25111932,0.00218,6.95168068,0.30232976,0.21167333,6.90047024,0.26442825,0.21167333,6.93837175,0.30232976,0.31642,6.90047024,0.27108271,0.31642,6.93171729,0.20048753,0.09383333,7.00231247,0.19990888,0.00218,7.00289112,0.20106618,0.18548667,7.00173382,0.20164482,0.27714,7.00115518,0.14088667,0.05782667,7.06191333,0.14869844,0.00218,7.05410156,0.13307491,0.11347333,7.06972509,0.12526315,0.16912,7.07753685,0.097488,0.02509333,7.105312,0.097488,0.00218,7.105312,0.097488,0.04800667,7.105312,0.097488,0.07092,7.105312,0.30045312,0.00218,6.89818355,0.30045312,0.10692667,6.89818355,0.24806084,0.10692667,6.93319096,0.24023602,0.00218,6.93841934,0.30045312,0.21167333,6.89818355,0.25588566,0.21167333,6.92796258,0.30045312,0.31642,6.89818355,0.26371048,0.31642,6.9227342,0.18069933,0.09383333,6.97820048,0.18001891,0.00218,6.97865513,0.18137975,0.18548667,6.97774584,0.18206017,0.27714,6.9772912,0.11061614,0.05782667,7.02502857,0.1198018,0.00218,7.01889091,0.10143048,0.11347333,7.03116623,0.09224482,0.16912,7.0373039,0.05958469,0.02509333,7.0591267,0.05958469,0.00218,7.0591267,0.05958469,0.04800667,7.0591267,0.05958469,0.07092,7.0591267,0.29905866,0.00218,6.89557469,0.29905866,0.10692667,6.89557469,0.24084347,0.10692667,6.91968821,0.23214899,0.00218,6.92328958,0.29905866,0.21167333,6.89557469,0.24953795,0.21167333,6.91608684,0.29905866,0.31642,6.89557469,0.25823242,0.31642,6.91248547,0.16599537,0.09383333,6.95069131,0.16523933,0.00218,6.95100447,0.16675141,0.18548667,6.95037815,0.16750745,0.27714,6.95006499,0.0881231,0.05782667,6.98294706,0.09832966,0.00218,6.97871937,0.07791654,0.11347333,6.98717476,0.06770998,0.16912,6.99140245,0.03142,0.02509333,7.00643426,0.03142,0.00218,7.00643426,0.03142,0.04800667,7.00643426,0.03142,0.07092,7.00643426,0.29819995,0.00218,6.89274391,0.29819995,0.10692667,6.89274391,0.23639903,0.10692667,6.90503688,0.22716903,0.00218,6.90687284,0.29819995,0.21167333,6.89274391,0.24562904,0.21167333,6.90320092,0.29819995,0.31642,6.89274391,0.25485905,0.31642,6.90136495,0.15694072,0.09383333,6.92084212,0.15613811,0.00218,6.92100177,0.15774332,0.18548667,6.92068247,0.15854593,0.27714,6.92052282,0.07427196,0.05782667,6.93728596,0.08510718,0.00218,6.9351307,0.06343673,0.11347333,6.93944122,0.05260151,0.16912,6.94159648,0.01407626,0.02509333,6.94925963,0.01407626,0.00218,6.94925963,0.01407626,0.04800667,6.94925963,0.01407626,0.07092,6.94925963,0.29792818,0.00218,6.89054043,0.29792818,0.10692667,6.89054043,0.23499241,0.10692667,6.89363227,0.22559291,0.00218,6.89409403,0.29792818,0.21167333,6.89054043,0.24439191,0.21167333,6.8931705,0.29792818,0.31642,6.89054043,0.25379141,0.31642,6.89270873,0.154075,0.09383333,6.89760748,0.15325765,0.00218,6.89764764,0.15489234,0.18548667,6.89756733,0.15570969,0.27714,6.89752718,0.06988819,0.05782667,6.90174332,0.08092238,0.00218,6.90120124,0.058854,0.11347333,6.90228539,0.04781981,0.16912,6.90282747,0.00858712,0.02509333,6.90475485,0.00858712,0.00218,6.90475485,0.00858712,0.04800667,6.90475485,0.00858712,0.07092,6.90475485,0.29791,0.00218,6.820902,0.29791,0.10692667,6.820902,0.23489833,0.10692667,6.820902,0.2254875,0.00218,6.820902,0.29791,0.21167333,6.820902,0.24430917,0.21167333,6.820902,0.29791,0.31642,6.820902,0.25372,0.31642,6.820902,0.15388333,0.09383333,6.820902,0.153065,0.00218,6.820902,0.15470167,0.18548667,6.820902,0.15552,0.27714,6.820902,0.069595,0.05782667,6.820902,0.0806425,0.00218,6.820902,0.0585475,0.11347333,6.820902,0.0475,0.16912,6.820902,0.00822,0.02509333,6.820902,0.00822,0.00218,6.820902,0.00822,0.04800667,6.820902,0.00822,0.07092,6.820902],200,3)
557         sConn=DataArrayInt([0,1,2,3,20,21,22,23,1,4,5,2,21,24,25,22,4,6,7,5,24,26,27,25,3,2,8,9,23,22,28,29,2,5,10,8,22,25,30,28,5,7,11,10,25,27,31,30,9,8,12,13,29,28,32,33,8,10,14,12,28,30,34,32,10,11,15,14,30,31,35,34,13,12,16,17,33,32,36,37,12,14,18,16,32,34,38,36,14,15,19,18,34,35,39,38,20,21,22,23,40,41,42,43,21,24,25,22,41,44,45,42,24,26,27,25,44,46,47,45,23,22,28,29,43,42,48,49,22,25,30,28,42,45,50,48,25,27,31,30,45,47,51,50,29,28,32,33,49,48,52,53,28,30,34,32,48,50,54,52,30,31,35,34,50,51,55,54,33,32,36,37,53,52,56,57,32,34,38,36,52,54,58,56,34,35,39,38,54,55,59,58,40,41,42,43,60,61,62,63,41,44,45,42,61,64,65,62,44,46,47,45,64,66,67,65,43,42,48,49,63,62,68,69,42,45,50,48,62,65,70,68,45,47,51,50,65,67,71,70,49,48,52,53,69,68,72,73,48,50,54,52,68,70,74,72,50,51,55,54,70,71,75,74,53,52,56,57,73,72,76,77,52,54,58,56,72,74,78,76,54,55,59,58,74,75,79,78,60,61,62,63,80,81,82,83,61,64,65,62,81,84,85,82,64,66,67,65,84,86,87,85,63,62,68,69,83,82,88,89,62,65,70,68,82,85,90,88,65,67,71,70,85,87,91,90,69,68,72,73,89,88,92,93,68,70,74,72,88,90,94,92,70,71,75,74,90,91,95,94,73,72,76,77,93,92,96,97,72,74,78,76,92,94,98,96,74,75,79,78,94,95,99,98,80,81,82,83,100,101,102,103,81,84,85,82,101,104,105,102,84,86,87,85,104,106,107,105,83,82,88,89,103,102,108,109,82,85,90,88,102,105,110,108,85,87,91,90,105,107,111,110,89,88,92,93,109,108,112,113,88,90,94,92,108,110,114,112,90,91,95,94,110,111,115,114,93,92,96,97,113,112,116,117,92,94,98,96,112,114,118,116,94,95,99,98,114,115,119,118,100,101,102,103,120,121,122,123,101,104,105,102,121,124,125,122,104,106,107,105,124,126,127,125,103,102,108,109,123,122,128,129,102,105,110,108,122,125,130,128,105,107,111,110,125,127,131,130,109,108,112,113,129,128,132,133,108,110,114,112,128,130,134,132,110,111,115,114,130,131,135,134,113,112,116,117,133,132,136,137,112,114,118,116,132,134,138,136,114,115,119,118,134,135,139,138,120,121,122,123,140,141,142,143,121,124,125,122,141,144,145,142,124,126,127,125,144,146,147,145,123,122,128,129,143,142,148,149,122,125,130,128,142,145,150,148,125,127,131,130,145,147,151,150,129,128,132,133,149,148,152,153,128,130,134,132,148,150,154,152,130,131,135,134,150,151,155,154,133,132,136,137,153,152,156,157,132,134,138,136,152,154,158,156,134,135,139,138,154,155,159,158,140,141,142,143,160,161,162,163,141,144,145,142,161,164,165,162,144,146,147,145,164,166,167,165,143,142,148,149,163,162,168,169,142,145,150,148,162,165,170,168,145,147,151,150,165,167,171,170,149,148,152,153,169,168,172,173,148,150,154,152,168,170,174,172,150,151,155,154,170,171,175,174,153,152,156,157,173,172,176,177,152,154,158,156,172,174,178,176,154,155,159,158,174,175,179,178,160,161,162,163,180,181,182,183,161,164,165,162,181,184,185,182,164,166,167,165,184,186,187,185,163,162,168,169,183,182,188,189,162,165,170,168,182,185,190,188,165,167,171,170,185,187,191,190,169,168,172,173,189,188,192,193,168,170,174,172,188,190,194,192,170,171,175,174,190,191,195,194,173,172,176,177,193,192,196,197,172,174,178,176,192,194,198,196,174,175,179,178,194,195,199,198])
558         s=MEDCoupling1SGTUMesh("source",NORM_HEXA8) ; s.setCoords(sCoo)
559         s.setNodalConnectivity(sConn)
560         #
561         tCoo=DataArrayDouble([0.328,0.012,6.8598,0.328,0.168320184237353,6.8598,0.328,0.324640368474706,6.8598,0.328,0.0,6.8598,0.298,0.012,6.8598,0.1565,0.012,6.8598,0.180205346493166,0.144794653506834,6.8598,0.298,0.168320184237353,6.8598,0.0,0.012,6.8598,0.0916755774886107,0.233324422511389,6.8598,0.298,0.324640368474706,6.8598,0.298,0.0,6.8598,0.1565,0.0,6.8598,0.0,0.0,6.8598,0.328,0.012,7.2298,0.328,0.168320184237353,7.2298,0.328,0.324640368474706,7.2298,0.328,0.0,7.2298,0.298,0.012,7.2298,0.1565,0.012,7.2298,0.180205346493166,0.144794653506834,7.2298,0.298,0.168320184237353,7.2298,0.0,0.012,7.2298,0.0916755774886107,0.233324422511389,7.2298,0.298,0.324640368474706,7.2298,0.298,0.0,7.2298,0.1565,0.0,7.2298,0.0,0.0,7.2298],28,3)
562         tConn=DataArrayInt([4,5,6,7,18,19,20,21,5,8,9,6,19,22,23,20,6,9,10,7,20,23,24,21,11,12,5,4,25,26,19,18,12,13,8,5,26,27,22,19,3,11,4,0,17,25,18,14,0,4,7,1,14,18,21,15,1,7,10,2,15,21,24,16])
563         t=MEDCoupling1SGTUMesh("target",NORM_HEXA8) ; t.setCoords(tCoo)
564         t.setNodalConnectivity(tConn)
565         #
566         s.simplexize(PLANAR_FACE_5)
567         aRemapper=MEDCouplingRemapper()
568         aRemapper.setPrecision(1e-12)
569         aRemapper.setIntersectionType(Barycentric)
570         self.assertEqual(aRemapper.prepare(s,t,'P1P1'),1)
571         m=aRemapper.getCrudeMatrix()
572         self.assertEqual(len(m),28)
573         for i in range(28):
574             if i not in [5,6]:
575                 self.assertEqual(len(m[i]),0)
576                 pass
577             pass
578         self.assertEqual(len(m[5]),4)
579         self.assertEqual(len(m[6]),4)
580         self.assertAlmostEqual(0.10714286103952797,m[5][168],12)
581         self.assertAlmostEqual(0.35691534416938014,m[5][169],12)
582         self.assertAlmostEqual(0.04492099619713096,m[5][163],12)
583         self.assertAlmostEqual(0.49102079859396097,m[5][189],12)
584         self.assertAlmostEqual(0.14039089397104254,m[6][185],12)
585         self.assertAlmostEqual(0.16362822318261033,m[6][162],12)
586         self.assertAlmostEqual(0.3438363717836785 ,m[6][188],12)
587         self.assertAlmostEqual(0.3521445110626687 ,m[6][170],12)
588         pass
589
590     def testSwig2MappedBarycentricP1P12D_1(self):
591         """ Testing mapped barycentric P1P1 projection
592         (uses analytical mapping from square to arbitrary convex quadrangle)
593         """
594         n = 5
595         sCoo = DataArrayDouble(n,1)
596         sCoo.iota(0.0);     sCoo /= float(n-1)
597         m = MEDCouplingCMesh("target")
598         m.setCoordsAt(0, sCoo)
599         m.setCoordsAt(1, sCoo)
600         tgt = m.buildUnstructured()
601         coo = tgt.getCoords()
602         orig = coo.deepCopy();   orig[:,0] = 10.0; orig[:,1] = 15.0
603         pt_a = coo.deepCopy();   pt_a[:,0] = -0.3; pt_a[:,1] = 1.0
604         pt_b = coo.deepCopy();   pt_b[:,0] = 2.0;  pt_b[:,1] = 3.0
605         pt_c = coo.deepCopy();   pt_c[:,0] = 1.0;  pt_c[:,1] = 0.0
606         # P = x*C+y*A + xy(B-A-C) + ORIGIN
607         coo2 = coo[:,0]*pt_c + coo[:, 1]*pt_a + coo[:, 0]*coo[:, 1]*(pt_b - pt_a - pt_c) + orig
608
609         tgt.setCoords(coo2)
610
611         sCoo = DataArrayDouble([0.0,0.0,  -0.3,1.0,  2.0,3.0,  1.0,0.0],4,2)
612         sCoo[:,0] += 10.0;  sCoo[:,1] += 15.0;
613         sConn = DataArrayInt([0,1,2,3])
614         s = MEDCoupling1SGTUMesh("source",NORM_QUAD4) ; s.setCoords(sCoo)
615         s.setNodalConnectivity(sConn)
616         #
617         aRemapper=MEDCouplingRemapper()
618         aRemapper.setPrecision(1e-12)
619         aRemapper.setIntersectionType(MappedBarycentric)
620         self.assertEqual(aRemapper.prepare(s,tgt,'P1P1'),1)
621         srcField = MEDCouplingFieldDouble(ON_NODES, ONE_TIME)
622         srcField.setNature(IntensiveMaximum)
623         srcField.setMesh(s); srcField.setName("field")
624         srcField.setArray(DataArrayDouble([1.0,2.0,3.0,4.0]))
625         tgtF = aRemapper.transferField(srcField, 1e+300)
626         ref = [1.0, 1.75, 2.5, 3.25, 4.0, 1.25, 1.875, 2.5, 3.125, 3.75, 1.5, 2.0, 2.5, 3.0, 3.5, 1.75,
627          2.125, 2.5, 2.875, 3.25, 2.0, 2.25, 2.5, 2.75, 3.0]
628         val = tgtF.getArray().getValues()
629         for i, ref_v in enumerate(ref):
630             self.assertAlmostEqual(ref_v, val[i])
631         pass
632
633     def testSwig2MappedBarycentricP1P13_1(self):
634         """ Testing mapped barycentric P1P1 projection in 3D (uses orthogonal distances to 
635         HEXA8 faces).
636         Convention:
637               0 ------ 3
638              /|       /|
639             / |      / |
640            1 ------ 2  |
641            |  |     |  |
642            |  |     |  |
643            |  4-----|- 7
644            | /      | /
645            5 ------ 6
646         """
647         n = 5
648         sCoo = DataArrayDouble(n,1)
649         sCoo.iota(0.0)
650         sCoo /= float(n-1)
651         m = MEDCouplingCMesh("target")
652         m.setCoordsAt(0, sCoo)
653         m.setCoordsAt(1, sCoo)
654         m.setCoordsAt(2, sCoo)
655         tgt = m.buildUnstructured()
656         coo = tgt.getCoords()
657         pt_0 = coo.deepCopy(); pt_0[:,0] = -0.3; pt_0[:,1] = 1.0; pt_0[:,2] = 1.0
658         pt_1 = coo.deepCopy(); pt_1[:,0] = 0.0; pt_1[:,1] = 0.0; pt_1[:,2] = 1.0
659         pt_2 = coo.deepCopy(); pt_2[:,0] = 1.0; pt_2[:,1] = 0.0; pt_2[:,2] = 1.0
660         pt_3 = coo.deepCopy(); pt_3[:,0] = 2.0; pt_3[:,1] = 3.0; pt_3[:,2] = 1.0
661
662         pt_4 = coo.deepCopy(); pt_4[:,0] = -0.3; pt_4[:,1] = 1.0; pt_4[:,2] = 0.0
663         orig = coo.deepCopy(); orig[:,0] = 10.0; orig[:,1] = 15.0; orig[:,2] = 20.0
664         pt_6 = coo.deepCopy(); pt_6[:,0] = 1.0; pt_6[:,1] = 0.0; pt_6[:,2] = 0.0
665         pt_7 = coo.deepCopy(); pt_7[:,0] = 2.0; pt_7[:,1] = 3.0; pt_7[:,2] = 0.0
666         # P = x*p6 + y*p4 + z*p1 + xy*(p7-p6-p4) + xz*(p2-p1-p6) + yz*(p0-p4-p1) + xyz(p3-p7-p2-p0+p1+p6+p4)
667         x,y,z = coo[:,0],coo[:,1],coo[:,2]
668         coo2 = x*pt_6 + y*pt_4 + z*pt_1 + \
669                x*y*(pt_7 - pt_6 - pt_4) + x*z*(pt_2 - pt_1 - pt_6) + y*z*(pt_0 - pt_4 - pt_1) + \
670                x*y*z*(pt_3 - pt_7 - pt_2 - pt_0 + pt_6 + pt_1 + pt_4) + orig
671         tgt.setCoords(coo2)
672
673         sCoo = DataArrayDouble([-0.3,1.0,1.0,  0.0,0.0,1.0,  1.0,0.0,1.0,  2.0,3.0,1.0,
674                                 -0.3,1.0,0.0,  0.0,0.0,0.0,  1.0,0.0,0.0,  2.0,3.0,0.0,],8,3)
675         sCoo[:, 0] += 10.0; sCoo[:, 1] += 15.0; sCoo[:, 2] += 20.0;
676         sConn = DataArrayInt([0,1,2,3,4, 5,6,7])
677         s = MEDCoupling1SGTUMesh("source",NORM_HEXA8) ; s.setCoords(sCoo)
678         s.setNodalConnectivity(sConn)
679         #
680         aRemapper=MEDCouplingRemapper()
681         aRemapper.setPrecision(1e-12)
682         aRemapper.setIntersectionType(MappedBarycentric)
683         self.assertEqual(aRemapper.prepare(s,tgt,'P1P1'),1)
684         srcField = MEDCouplingFieldDouble(ON_NODES, ONE_TIME)
685         srcField.setNature(IntensiveMaximum)
686         srcField.setMesh(s); srcField.setName("field")
687         srcField.setArray(DataArrayDouble([1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0]))
688         tgtF = aRemapper.transferField(srcField, 1e+300)
689 #        print tgtF.getArray().getValues()
690         ref = [6.0, 6.251802698104413, 6.502397834044702, 6.7517940736426665, 7.0, 5.740554726834594,
691                6.1761835575796935, 6.6052985689637564, 7.009392769824465, 7.383488834310164,
692                5.487562931129931, 6.140664596972973, 6.720290674177548, 7.220534970454015, 7.651092836860121,
693                5.2407867837524345, 6.125759809889516, 6.82853486793175, 7.390880823876876, 7.848445254819061,
694                5.0, 6.12211344611157, 6.925740671133115, 7.529623182840827, 8.0, 5.0, 5.251802698104413,
695                5.502397834044702, 5.751794073642667, 6.0, 4.740554726834594, 5.1761835575796935,
696                5.6052985689637564, 6.009392769824465, 6.383488834310163, 4.487562931129931, 5.140664596972973,
697                 5.720290674177548, 6.220534970454015, 6.651092836860121, 4.2407867837524345, 5.125759809889516,
698                 5.828534867931749, 6.390880823876876, 6.848445254819061, 4.0, 5.122113446111569, 5.925740671133115,
699                 6.529623182840827, 7.0, 4.0, 4.251802698104413, 4.502397834044702, 4.751794073642667, 5.0, 3.740554726834594,
700                 4.176183557579693, 4.6052985689637564, 5.009392769824464, 5.383488834310164, 3.487562931129931,
701                 4.140664596972973, 4.720290674177548, 5.220534970454015, 5.651092836860121, 3.240786783752434, 4.125759809889516, 4.82853486793175,
702                 5.390880823876876, 5.848445254819061, 3.0, 4.122113446111569, 4.925740671133115, 5.529623182840827, 6.0, 3.0,
703                 3.2518026981044135, 3.502397834044702, 3.7517940736426674, 4.0, 2.7405547268345933, 3.176183557579693,
704                 3.6052985689637564, 4.009392769824465, 4.383488834310164, 2.487562931129931, 3.140664596972973, 3.7202906741775474, 4.220534970454015, 4.65109283686012, 2.2407867837524345, 3.1257598098895154, 3.828534867931749,
705                 4.390880823876876, 4.848445254819061, 2.0, 3.1221134461115687, 3.9257406711331146, 4.529623182840826, 5.0, 2.0, 2.2518026981044135, 2.502397834044702, 2.7517940736426674, 3.0, 1.7405547268345936, 2.176183557579693, 2.6052985689637564,
706                 3.0093927698244642, 3.3834888343101635, 1.4875629311299305, 2.1406645969729734, 2.720290674177548,
707                 3.2205349704540143, 3.6510928368601205, 1.2407867837524345, 2.125759809889516, 2.8285348679317495, 3.390880823876876, 3.848445254819061, 1.0, 2.1221134461115687, 2.9257406711331146, 3.529623182840827, 4.0]
708
709         val = tgtF.getArray().getValues()
710         for i, ref_v in enumerate(ref):
711             self.assertAlmostEqual(ref_v, val[i])
712         pass
713
714     @unittest.skipUnless(MEDCouplingHasNumPyBindings() and MEDCouplingHasSciPyBindings(),"requires numpy AND scipy")
715     def testGetCrudeCSRMatrix1(self):
716         """ testing CSR matrix output using numpy/scipy.
717         """
718         from scipy.sparse import spdiags #diags
719         import scipy
720         from numpy import array
721         arr=DataArrayDouble(3) ; arr.iota()
722         m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
723         src=m.buildUnstructured()
724         trg=src.deepCopy() ; trg=trg[[0,1,3]]
725         trg.getCoords()[:]*=0.5 ; trg.getCoords()[:]+=[0.3,0.25]
726         # Let's interpolate.
727         rem=MEDCouplingRemapper()
728         rem.prepare(src,trg,"P0P0")
729         # Internal crude sparse matrix computed. Let's manipulate it using CSR matrix in scipy.
730         for i in range(10):
731             m=rem.getCrudeCSRMatrix()
732             pass
733         m2=rem.getCrudeCSRMatrix()
734         diff=m-m2
735         self.assertTrue(isinstance(m,scipy.sparse.csr.csr_matrix))
736         self.assertEqual(m.getnnz(),7)
737         self.assertAlmostEqual(m[0,0],0.25,12)
738         self.assertAlmostEqual(m[1,0],0.1,12)
739         self.assertAlmostEqual(m[1,1],0.15,12)
740         self.assertAlmostEqual(m[2,0],0.05,12)
741         self.assertAlmostEqual(m[2,1],0.075,12)
742         self.assertAlmostEqual(m[2,2],0.05,12)
743         self.assertAlmostEqual(m[2,3],0.075,12)
744         self.assertEqual(diff.getnnz(),0)
745         # ExtensiveConservation (division by sum of cols)
746         colSum=m.sum(axis=0)
747         # version 0.12.0 # m_0=m*diags(array(1/colSum),[0])
748         m_0=m*spdiags(array(1/colSum),[0],colSum.shape[1],colSum.shape[1])
749         del colSum
750         self.assertAlmostEqual(m_0[0,0],0.625,12)
751         self.assertAlmostEqual(m_0[1,0],0.25,12)
752         self.assertAlmostEqual(m_0[1,1],0.6666666666666667,12)
753         self.assertAlmostEqual(m_0[2,0],0.125,12)
754         self.assertAlmostEqual(m_0[2,1],0.3333333333333333,12)
755         self.assertAlmostEqual(m_0[2,2],1.,12)
756         self.assertAlmostEqual(m_0[2,3],1.,12)
757         self.assertEqual(m_0.getnnz(),7)
758         # IntensiveMaximum (division by sum of rows)
759         rowSum=m.sum(axis=1)
760         # version 0.12.0 # m_1=diags(array(1/rowSum.transpose()),[0])*m
761         m_1=spdiags(array(1/rowSum.transpose()),[0],rowSum.shape[0],rowSum.shape[0])*m
762         del rowSum
763         self.assertAlmostEqual(m_1[0,0],1.,12)
764         self.assertAlmostEqual(m_1[1,0],0.4,12)
765         self.assertAlmostEqual(m_1[1,1],0.6,12)
766         self.assertAlmostEqual(m_1[2,0],0.2,12)
767         self.assertAlmostEqual(m_1[2,1],0.3,12)
768         self.assertAlmostEqual(m_1[2,2],0.2,12)
769         self.assertAlmostEqual(m_1[2,3],0.3,12)
770         self.assertEqual(m_1.getnnz(),7)
771         pass
772
773     @unittest.skipUnless(MEDCouplingHasNumPyBindings() and MEDCouplingHasSciPyBindings(),"requires numpy AND scipy")
774     def testP0P1Bary_1(self):
775         a=MEDCouplingUMesh("a",2)
776         a.allocateCells()
777         conna=[0,1,3,2,1,4,5,3,4,6,7,5,6,8,9,7,8,10,11,9,10,12,13,11,12,14,15,13,14,16,17,15,16,18,19,17,18,20,21,19,20,22,23,21,22,24,25,23,24,26,27,25]
778         a.setCoords(DataArrayDouble([1.54,0,-0.01,1.54,0.02,-0.01,1.54,0,0.01,1.54,0.02,0.01,1.54,0.04,-0.01,1.54,0.04,0.01,1.54,0.06,-0.01,1.54,0.06,0.01,1.54,0.08,-0.01,1.54,0.08,0.01,1.54,0.1,-0.01,1.54,0.1,0.01,1.54,0.12,-0.01,1.54,0.12,0.01,1.54,0.14,-0.01,1.54,0.14,0.01,1.54,0.16,-0.01,1.54,0.16,0.01,1.54,0.18,-0.01,1.54,0.18,0.01,1.54,0.2,-0.01,1.54,0.2,0.01,1.54,0.22,-0.01,1.54,0.22,0.01,1.54,0.24,-0.01,1.54,0.24,0.01,1.54,0.26,-0.01,1.54,0.26,0.01],28,3))
779         for i in range(13):
780             a.insertNextCell(NORM_QUAD4,conna[4*i:4*(i+1)])
781             pass
782         a.finishInsertingCells() ; a.simplexize(0)
783         #
784         connb=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,0,2,39,3,5,40,6,8,41,9,11,42,12,14,43,15,17,44,18,20,45,21,23,46,24,26,47,27,29,48,30,32,49,33,35,50,36,38,51,52,2,39,53,5,40,54,8,41,55,11,42,56,14,43,57,17,44,58,20,45,59,23,46,60,26,47,61,29,48,62,32,49,63,35,50,64,38,51,52,2,65,53,5,66,54,8,67,55,11,68,56,14,69,57,17,70,58,20,71,59,23,72,60,26,73,61,29,74,62,32,75,63,35,76,64,38,77,53,2,65,54,5,66,55,8,67,56,11,68,57,14,69,58,17,70,59,20,71,60,23,72,61,26,73,62,29,74,63,32,75,64,35,76,78,38,77,53,2,40,54,5,41,55,8,42,56,11,43,57,14,44,58,17,45,59,20,46,60,23,47,61,26,48,62,29,49,63,32,50,64,35,51,78,38,79,3,2,40,6,5,41,9,8,42,12,11,43,15,14,44,18,17,45,21,20,46,24,23,47,27,26,48,30,29,49,33,32,50,36,35,51,80,38,79,3,2,1,6,5,4,9,8,7,12,11,10,15,14,13,18,17,16,21,20,19,24,23,22,27,26,25,30,29,28,33,32,31,36,35,34,80,38,37]
785         b=MEDCouplingUMesh("b",2)
786         b.allocateCells()
787         for i in range(104):
788             b.insertNextCell(NORM_TRI3,connb[3*i:3*(i+1)])
789             pass
790         b.setCoords(DataArrayDouble([1.54,0,-0.01,1.54,0.01,-0.01,1.54,0.01,0,1.54,0.02,-0.01,1.54,0.03,-0.01,1.54,0.03,0,1.54,0.04,-0.01,1.54,0.05,-0.01,1.54,0.05,0,1.54,0.06,-0.01,1.54,0.07,-0.01,1.54,0.07,0,1.54,0.08,-0.01,1.54,0.09,-0.01,1.54,0.09,0,1.54,0.1,-0.01,1.54,0.11,-0.01,1.54,0.11,0,1.54,0.12,-0.01,1.54,0.13,-0.01,1.54,0.13,0,1.54,0.14,-0.01,1.54,0.15,-0.01,1.54,0.15,0,1.54,0.16,-0.01,1.54,0.17,-0.01,1.54,0.17,0,1.54,0.18,-0.01,1.54,0.19,-0.01,1.54,0.19,0,1.54,0.2,-0.01,1.54,0.21,-0.01,1.54,0.21,0,1.54,0.22,-0.01,1.54,0.23,-0.01,1.54,0.23,0,1.54,0.24,-0.01,1.54,0.25,-0.01,1.54,0.25,0,1.54,0,0,1.54,0.02,0,1.54,0.04,0,1.54,0.06,0,1.54,0.08,0,1.54,0.1,0,1.54,0.12,0,1.54,0.14,0,1.54,0.16,0,1.54,0.18,0,1.54,0.2,0,1.54,0.22,0,1.54,0.24,0,1.54,0,0.01,1.54,0.02,0.01,1.54,0.04,0.01,1.54,0.06,0.01,1.54,0.08,0.01,1.54,0.1,0.01,1.54,0.12,0.01,1.54,0.14,0.01,1.54,0.16,0.01,1.54,0.18,0.01,1.54,0.2,0.01,1.54,0.22,0.01,1.54,0.24,0.01,1.54,0.01,0.01,1.54,0.03,0.01,1.54,0.05,0.01,1.54,0.07,0.01,1.54,0.09,0.01,1.54,0.11,0.01,1.54,0.13,0.01,1.54,0.15,0.01,1.54,0.17,0.01,1.54,0.19,0.01,1.54,0.21,0.01,1.54,0.23,0.01,1.54,0.25,0.01,1.54,0.26,0.01,1.54,0.26,0,1.54,0.26,-0.01],81,3))
791         #
792         rem=MEDCouplingRemapper() ; rem.setIntersectionType(Barycentric)
793         rem.prepare(a,b,"P1P0")
794         m0=rem.getCrudeCSRMatrix()
795         self.assertEqual(m0.nnz,312)
796         #
797         ids=4*[None] ; vs=4*[None]
798         ids[0]=DataArrayInt([0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,158,161,164,167,170,173,176,179,182,185,188,191,194,197,200,203,206,209,212,215,218,221,224,227,230,233]) ; vs[0]=10./3.
799         ids[1]=DataArrayInt([1,2,4,5,7,8,10,11,13,14,16,17,19,20,22,23,25,26,28,29,31,32,34,35,37,38,40,41,43,44,46,47,49,50,52,53,55,56,58,59,61,62,64,65,67,68,70,71,73,74,76,77,80,83,86,89,92,95,98,101,104,107,110,113,116,117,120,123,126,129,132,135,138,141,144,147,150,153,156,157,159,160,162,163,165,166,168,169,171,172,174,175,177,178,180,181,183,184,186,187,189,190,192,193,195,196,198,199,201,202,204,205,207,208,210,211,213,214,216,217,219,220,222,223,225,226,228,229,231,232,234,237,240,243,246,249,252,255,258,261,264,267,270,275,278,281,284,287,290,293,296,299,302,305,308,311]) ; vs[1]=5./6.
800         ids[2]=DataArrayInt([78,81,84,87,90,93,96,99,102,105,108,111,114,119,122,125,128,131,134,137,140,143,146,149,152,155,236,239,242,245,248,251,254,257,260,263,266,269,272,273,276,279,282,285,288,291,294,297,300,303,306,309]) ; vs[2]=5./3.
801         ids[3]=DataArrayInt([79,82,85,88,91,94,97,100,103,106,109,112,115,118,121,124,127,130,133,136,139,142,145,148,151,154,235,238,241,244,247,250,253,256,259,262,265,268,271,274,277,280,283,286,289,292,295,298,301,304,307,310]) ; vs[3]=2.5
802         vals=DataArrayDouble(312,1)
803         for idd,v in zip(ids,vs):
804             vals[idd]=v
805             pass
806         vals*=1e-5
807         eps0=DataArrayDouble(m0.data)-vals ; eps0.abs()
808         self.assertTrue(eps0.findIdsInRange(1e-17,1e300).empty())
809         self.assertTrue(DataArrayInt32(m0.indices).isEqual(DataArrayInt32([0,1,3,1,4,5,4,6,7,6,8,9,8,10,11,10,12,13,12,14,15,14,16,17,16,18,19,18,20,21,20,22,23,22,24,25,24,26,27,0,2,3,1,3,5,4,5,7,6,7,9,8,9,11,10,11,13,12,13,15,14,15,17,16,17,19,18,19,21,20,21,23,22,23,25,24,25,27,0,2,3,1,3,5,4,5,7,6,7,9,8,9,11,10,11,13,12,13,15,14,15,17,16,17,19,18,19,21,20,21,23,22,23,25,24,25,27,0,2,3,1,3,5,4,5,7,6,7,9,8,9,11,10,11,13,12,13,15,14,15,17,16,17,19,18,19,21,20,21,23,22,23,25,24,25,27,0,2,3,1,3,5,4,5,7,6,7,9,8,9,11,10,11,13,12,13,15,14,15,17,16,17,19,18,19,21,20,21,23,22,23,25,24,25,27,0,1,3,1,4,5,4,6,7,6,8,9,8,10,11,10,12,13,12,14,15,14,16,17,16,18,19,18,20,21,20,22,23,22,24,25,24,26,27,0,1,3,1,4,5,4,6,7,6,8,9,8,10,11,10,12,13,12,14,15,14,16,17,16,18,19,18,20,21,20,22,23,22,24,25,24,26,27,0,1,3,1,4,5,4,6,7,6,8,9,8,10,11,10,12,13,12,14,15,14,16,17,16,18,19,18,20,21,20,22,23,22,24,25,24,26,27])))
810         self.assertTrue(DataArrayInt32(m0.indptr).isEqual(DataArrayInt32([0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,99,102,105,108,111,114,117,120,123,126,129,132,135,138,141,144,147,150,153,156,159,162,165,168,171,174,177,180,183,186,189,192,195,198,201,204,207,210,213,216,219,222,225,228,231,234,237,240,243,246,249,252,255,258,261,264,267,270,273,276,279,282,285,288,291,294,297,300,303,306,309,312])))
811         #
812         rem2=MEDCouplingRemapper() ; rem2.setIntersectionType(Barycentric)
813         rem2.prepare(b,a,"P0P1")
814         m1=rem2.getCrudeCSRMatrix()
815         self.assertEqual(m1.nnz,312)
816         #
817         m1=rem2.getCrudeCSRMatrix()
818         m1t=m1.transpose()
819         delta=m0-m1t
820         self.assertTrue(DataArrayDouble(delta.data).isUniform(0.,1e-17))
821         pass
822
823     @unittest.skipUnless(MEDCouplingHasNumPyBindings() and MEDCouplingHasSciPyBindings(),"requires numpy AND scipy")
824     def testNonConformWithRemapper_1(self):
825         coo=DataArrayDouble([-0.396700000780411,-0.134843245350081,-0.0361311386958691,-0.407550009429364,-0.13484324535008,-0.0361311386958923,-0.396700000780411,-0.132191446077668,-0.0448729493559049,-0.407550009429364,-0.132191446077666,-0.0448729493559254,-0.396700000780411,-0.128973582738749,-0.0534226071577727,-0.407550009429364,-0.128973582738747,-0.0534226071577904,-0.396700000780411,-0.128348829636458,-0.0346583696473619,-0.407550009429364,-0.128348829636457,-0.0346583696473822,-0.396700000780411,-0.125874740261886,-0.0430683597970123,-0.407550009429364,-0.125874740261885,-0.0430683597970302,-0.396700000780411,-0.122905344829122,-0.051310216195766,-0.407550009429364,-0.12290534482912,-0.0513102161957814],12,3)
826         conn=DataArrayInt([2,9,3,11,2,3,5,11,2,8,9,11,2,10,8,11,2,5,4,11,2,4,10,11,3,0,1,6,3,1,7,6,3,2,0,6,3,8,2,6,3,7,9,6,3,9,8,6])
827         m=MEDCoupling1SGTUMesh("mesh",NORM_TETRA4)
828         m.setNodalConnectivity(conn)
829         m.setCoords(coo)
830         # m is ready
831         m1,d,di,rd,rdi=m.buildUnstructured().buildDescendingConnectivity()
832         rdi2=rdi.deltaShiftIndex()
833         cellIds=rdi2.findIdsEqual(1)
834         skinAndNonConformCells=m1[cellIds]
835         skinAndNonConformCells.zipCoords() # at this point skinAndNonConformCells contains non conform cells and skin cells. Now trying to split them in two parts.
836         #
837         rem=MEDCouplingRemapper()
838         rem.setMaxDistance3DSurfIntersect(1e-12)
839         rem.setMinDotBtwPlane3DSurfIntersect(0.99)# this line is important it is to tell to remapper to select only cells with very close orientation
840         rem.prepare(skinAndNonConformCells,skinAndNonConformCells,"P0P0")
841         mat=rem.getCrudeCSRMatrix()
842         indptr=DataArrayInt32(mat.indptr) #not depend on MEDCouplingUse64BitIDs()
843         indptr2=indptr.deltaShiftIndex()
844         cellIdsOfNonConformCells=indptr2.findIdsNotEqual(1)
845         cellIdsOfSkin=indptr2.findIdsEqual(1)
846         self.assertTrue(cellIdsOfSkin.isEqual(DataArrayInt([1,2,3,5,6,7,8,9,10,11,12,13,14,15,16,17,19,20,21,23])))
847         self.assertTrue(cellIdsOfNonConformCells.isEqual(DataArrayInt([0,4,18,22])))
848         pass
849
850     def test3D1DOnP1P0_1(self):
851         """ This test focused on P1P0 interpolation with a source with meshDim=1 spaceDim=3 and a target with meshDim=3.
852         This test has revealed a bug in remapper. A reverse matrix is computed so a reverse method should be given in input.
853         """
854         target=MEDCouplingCMesh()
855         arrX=DataArrayDouble([0,1]) ; arrY=DataArrayDouble([0,1]) ; arrZ=DataArrayDouble(11) ; arrZ.iota()
856         target.setCoords(arrX,arrY,arrZ)
857         target=target.buildUnstructured() ; target.setName("TargetSecondaire")
858         #
859         sourceCoo=DataArrayDouble([(0.5,0.5,0.1),(0.5,0.5,1.2),(0.5,0.5,1.6),(0.5,0.5,1.8),(0.5,0.5,2.43),(0.5,0.5,2.55),(0.5,0.5,4.1),(0.5,0.5,4.4),(0.5,0.5,4.9),(0.5,0.5,5.1),(0.5,0.5,7.6),(0.5,0.5,7.7),(0.5,0.5,8.2),(0.5,0.5,8.4),(0.5,0.5,8.6),(0.5,0.5,8.8),(0.5,0.5,9.2),(0.5,0.5,9.6),(0.5,0.5,11.5)])
860         source=MEDCoupling1SGTUMesh("SourcePrimaire",NORM_SEG2)
861         source.setCoords(sourceCoo)
862         source.allocateCells()
863         for i in range(len(sourceCoo) - 1):
864             source.insertNextCell([i,i+1])
865             pass
866         source=source.buildUnstructured()
867         fsource=MEDCouplingFieldDouble(ON_NODES) ; fsource.setName("field")
868         fsource.setMesh(source)
869         arr=DataArrayDouble(len(sourceCoo)) ; arr.iota(0.7) ; arr*=arr
870         fsource.setArray(arr)
871         fsource.setNature(IntensiveMaximum)
872         #
873         rem=MEDCouplingRemapper()
874         rem.setIntersectionType(PointLocator)
875         rem.prepare(source,target,"P1P0")
876         f2Test=rem.transferField(fsource,-27)
877         self.assertEqual(f2Test.getName(),fsource.getName())
878         self.assertEqual(f2Test.getMesh().getHiddenCppPointer(),target.getHiddenCppPointer())
879         expArr=DataArrayDouble([0.49,7.956666666666667,27.29,-27,59.95666666666667,94.09,-27,125.69,202.89,296.09])
880         self.assertTrue(f2Test.getArray().isEqual(expArr,1e-12))
881         f2Test=rem.reverseTransferField(f2Test,-36)
882         self.assertEqual(f2Test.getName(),fsource.getName())
883         self.assertEqual(f2Test.getMesh().getHiddenCppPointer(),source.getHiddenCppPointer())
884         expArr2=DataArrayDouble([0.49,7.956666666666667,7.956666666666667,7.956666666666667,27.29,27.29,59.95666666666667,59.95666666666667,59.95666666666667,94.09,125.69,125.69,202.89,202.89,202.89,202.89,296.09,296.09,-36.])
885         self.assertTrue(f2Test.getArray().isEqual(expArr2,1e-12))
886         pass
887
888     def testRemapperAMR1(self):
889         """ This test is the origin of the ref values for MEDCouplingBasicsTest.testAMR2"""
890         coarse=DataArrayDouble(35) ; coarse.iota(0) #X=5,Y=7
891         fine=DataArrayDouble(3*2*4*4) ; fine.iota(0) #X=3,Y=2 refined by 4
892         MEDCouplingIMesh.CondenseFineToCoarse([5,7],fine,[(1,4),(2,4)],[4,4],coarse)
893         #
894         m=MEDCouplingCartesianAMRMesh("mesh",2,[6,8],[0.,0.],[1.,1.])
895         trgMesh=m.buildUnstructured()
896         m.addPatch([(1,4),(2,4)],[4,4])
897         srcMesh=m[0].getMesh().buildUnstructured()
898         srcField=MEDCouplingFieldDouble(ON_CELLS)
899         fine2=DataArrayDouble(3*2*4*4) ; fine2.iota(0) ; srcField.setArray(fine2)
900         srcField.setMesh(srcMesh) ; srcField.setNature(ExtensiveMaximum)
901         #
902         trgField=MEDCouplingFieldDouble(ON_CELLS)
903         coarse2=DataArrayDouble(35) ; coarse2.iota(0) ; trgField.setArray(coarse2)
904         trgField.setMesh(trgMesh) ; trgField.setNature(ExtensiveMaximum)
905         #
906         rem=MEDCouplingRemapper()
907         rem.prepare(srcMesh,trgMesh,"P0P0")
908         rem.partialTransfer(srcField,trgField)
909         #
910         self.assertTrue(coarse.isEqual(trgField.getArray(),1e-12))
911         pass
912
913     @unittest.skipUnless(MEDCouplingHasNumPyBindings() and MEDCouplingHasSciPyBindings(),"requires numpy AND scipy")
914     def test1DPointLocator1(self):
915         """This test focuses on PointLocator for P1P1 in 1D and 2DCurve."""
916         from numpy import array
917         from scipy.sparse import diags,csr_matrix,identity
918         ## basic case 1D
919         arrS=DataArrayInt.Range(0,11,1).convertToDblArr()
920         arrT=DataArrayDouble([0.1,1.7,5.5,9.6])
921         mS=MEDCouplingCMesh() ; mS.setCoords(arrS)
922         mT=MEDCouplingCMesh() ; mT.setCoords(arrT)
923         rem=MEDCouplingRemapper()
924         rem.setIntersectionType(PointLocator)
925         self.assertEqual(rem.prepare(mS.buildUnstructured(),mT.buildUnstructured(),"P1P1"),1)
926         m=rem.getCrudeCSRMatrix()
927         rowSum=m.sum(axis=1)
928         m=diags(array(1/rowSum.transpose()),[0])*m
929         # expected matrix
930         row=array([0,0,1,1,2,2,3,3])
931         col=array([0,1,1,2,5,6,9,10])
932         data=array([0.9,0.1,0.3,0.7,0.5,0.5,0.4,0.6])
933         mExp0=csr_matrix((data,(row,col)),shape=(4,11))
934         # compute diff and check
935         diff=abs(m-mExp0)
936         self.assertAlmostEqual(diff.sum(),0.,14)
937         ## full specific case 1D where target=source
938         rem=MEDCouplingRemapper()
939         rem.setIntersectionType(PointLocator)
940         self.assertEqual(rem.prepare(mS.buildUnstructured(),mS.buildUnstructured(),"P1P1"),1)
941         m=rem.getCrudeCSRMatrix()
942         rowSum=m.sum(axis=1)
943         m=diags(array(1/rowSum.transpose()),[0])*m
944         # expected matrix
945         mExp1=identity(11)
946         diff=abs(m-mExp1)
947         self.assertAlmostEqual(diff.sum(),0.,14)
948         ## case where some points in target are not in source
949         arrT=DataArrayDouble([-0.2,0.1,1.7,5.5,10.3])
950         mT=MEDCouplingCMesh() ; mT.setCoords(arrT)
951         mT=mT.buildUnstructured()
952         rem=MEDCouplingRemapper()
953         rem.setIntersectionType(PointLocator)
954         self.assertEqual(rem.prepare(mS.buildUnstructured(),mT,"P1P1"),1)
955         m=rem.getCrudeCSRMatrix()
956         row=array([1,1,2,2,3,3])
957         col=array([0,1,1,2,5,6])
958         data=array([1.8,0.2,0.6,1.4,1.0,1.0])
959         mExp2=csr_matrix((data,(row,col)),shape=(5,11))
960         diff=abs(m-mExp2)
961         self.assertAlmostEqual(diff.sum(),0.,14)
962         ## basic case 2D Curve
963         arrS=DataArrayInt.Range(0,11,1).convertToDblArr()
964         arrT=DataArrayDouble([0.1,1.7,5.5,9.6])
965         mS=MEDCouplingCMesh() ; mS.setCoords(arrS)
966         mT=MEDCouplingCMesh() ; mT.setCoords(arrT)
967         mS=mS.buildUnstructured() ; mS.changeSpaceDimension(2)
968         mT=mT.buildUnstructured() ; mT.changeSpaceDimension(2)
969         mS.rotate([-1.,-1.],1.2)
970         mT.rotate([-1.,-1.],1.2)
971         rem=MEDCouplingRemapper()
972         rem.setIntersectionType(PointLocator)
973         self.assertEqual(rem.prepare(mS,mT,"P1P1"),1)
974         m=rem.getCrudeCSRMatrix()
975         rowSum=m.sum(axis=1)
976         m=diags(array(1/rowSum.transpose()),[0])*m
977         diff=abs(m-mExp0)
978         self.assertAlmostEqual(diff.sum(),0.,14)
979         pass
980
981     def test3D2Dand2D3DPointLocator1(self):
982         """ Non regression test solving SIGSEGV when using 3D<->3Dsurf pointlocator."""
983         arrX=DataArrayDouble([0,1,2])
984         arrY=DataArrayDouble([0,1])
985         arrZ=DataArrayDouble([0,1])
986         ms=MEDCouplingCMesh() ; ms.setCoords(arrX,arrY,arrZ)
987         ms=ms.buildUnstructured() ; ms.setName("source")
988         #
989         mt=MEDCouplingUMesh("target",2) ; mt.allocateCells()
990         mt.insertNextCell(NORM_TRI3,[0,4,6])
991         mt.insertNextCell(NORM_TRI3,[1,5,7])
992         mt.setCoords(ms.getCoords()[:])
993         mt.zipCoords()
994         #
995         rem=MEDCouplingRemapper()
996         rem.setIntersectionType(PointLocator)
997         rem.prepare(ms,mt,"P0P0")
998         self.assertEqual(rem.getCrudeMatrix(),[{0: 1.0}, {1: 1.0}])
999         rem2=MEDCouplingRemapper()
1000         rem2.setIntersectionType(PointLocator)
1001         ##
1002         # 2D to 3D with point locator does not make sense:
1003         ##
1004         self.assertRaises(InterpKernelException, rem2.prepare,mt,ms,"P0P0")
1005         pass
1006
1007     def test2D1Dand1D2DPointLocator1(self):
1008         arrX=DataArrayDouble([0,1,2])
1009         arrY=DataArrayDouble([0,1])
1010         ms=MEDCouplingCMesh() ; ms.setCoords(arrX,arrY) ; ms=ms.buildUnstructured()
1011         mt=MEDCouplingUMesh("target",1) ; mt.setCoords(ms.getCoords()[:])
1012         mt.allocateCells()
1013         mt.insertNextCell(NORM_SEG2,[0,4]) ; mt.insertNextCell(NORM_SEG2,[1,5])
1014         rem=MEDCouplingRemapper()
1015         rem.setIntersectionType(PointLocator)
1016         rem.prepare(ms,mt,"P0P0")
1017         self.assertEqual(rem.getCrudeMatrix(),[{0:1.},{1:1.}])
1018         rem=MEDCouplingRemapper()
1019         rem.setIntersectionType(PointLocator)
1020         rem.prepare(mt,ms,"P0P0")
1021         self.assertEqual(rem.getCrudeMatrix(),[{0:1.},{1:1.}])
1022         pass
1023
1024     def test3D1DPointLocatorBBoxAdjusted(self):
1025         """ In case a 1D segment lies exactly on the interface between two 2D (or 3D) faces, the default
1026         bounding box logic will make it non-intersecting with the surrounding 2D (or 3D) faces.
1027         Test bounding box adjustment allowing to widen the BB to capture this.
1028         """
1029         m = MEDCouplingCMesh("source")
1030         di, dd = DataArrayInt, DataArrayDouble
1031         m.setCoordsAt(0, dd([0.0, 1.0, 2.0]))
1032         m.setCoordsAt(1, dd([0.0, 1.0]))
1033         m.setCoordsAt(2, dd([0.0, 1.0]))
1034         m3d = m.buildUnstructured()
1035         m1d = MEDCouplingUMesh("target", 1)
1036         m1d.setCoords(dd([1.0,0.5,0.2  ,  1.0,0.5,0.8], 2,3))
1037         m1d.setConnectivity(di([NORM_SEG2, 0, 1]), di([0,3]))
1038
1039         rem = MEDCouplingRemapper()
1040         rem.setPrecision(1e-12)
1041         rem.setIntersectionType(PointLocator)
1042         rem.prepare(m3d, m1d,"P0P1")
1043         self.assertEqual(rem.getCrudeMatrix(), [{0: 1.0, 1: 1.0}, {0: 1.0, 1: 1.0}])
1044
1045         rem = MEDCouplingRemapper()
1046         rem.setPrecision(1e-12)
1047         rem.setIntersectionType(PointLocator)
1048         rem.setBoundingBoxAdjustment(0.0)
1049         rem.setBoundingBoxAdjustmentAbs(0.0)
1050         rem.prepare(m3d, m1d,"P0P1")
1051         self.assertEqual(rem.getCrudeMatrix(), [{}, {}])
1052         pass
1053
1054     def testPointLocator3DTo2D(self):
1055         """Target mesh has spaceDim==3 and meshDim==2. Source has spaceDim==3 and meshDim==3. Here we are on pointlocator alg.
1056         The test evaluates on each nodes of target mesh the bary coor into source mesh."""
1057         src=MEDCouplingCMesh()
1058         arr=DataArrayDouble([0,1,2])
1059         src.setCoords(arr,arr,arr)
1060         src=src.buildUnstructured()
1061         src.simplexize(PLANAR_FACE_5)
1062         fsrc=MEDCouplingFieldDouble(ON_NODES) ; fsrc.setMesh(src)
1063         fsrc.setArray(DataArrayDouble([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]))
1064         #
1065         trg=MEDCouplingCMesh()
1066         arr=DataArrayDouble([0,1])
1067         trg.setCoords(arr,arr)
1068         trg=trg.buildUnstructured()
1069         trg.changeSpaceDimension(3,0.)
1070         trg.translate([0.5,0.5,0.5])
1071         #
1072         arrTrg=fsrc.getValueOnMulti(trg.getCoords())
1073         ftrg=MEDCouplingFieldDouble(ON_NODES)
1074         ftrg.setMesh(trg)
1075         ftrg.setArray(arrTrg)
1076         ftrg.checkConsistencyLight()
1077         ftrg.setNature(IntensiveMaximum)
1078         #
1079         fsrc.setNature(IntensiveMaximum)
1080         remap=MEDCouplingRemapper()
1081         remap.setIntersectionType(PointLocator)
1082         self.assertEqual(remap.prepare(src,trg,"P1P1"),1)
1083         ftrg2=remap.transferField(fsrc,1e300)
1084         self.assertTrue(ftrg.isEqual(ftrg2,1e-12,1e-12))
1085         pass
1086
1087     def testPointLocator2D2DNonConvexPolygons(self):
1088         """ PointLocator remapper now correclty support non-convex polygons
1089         """
1090         src = MEDCouplingUMesh('src', 2)
1091         coo = DataArrayDouble([(6,1),(6,2),(4,2),(4,3),(3,3),(3,4),(2,4),(2,6),(1,6),(1,8),(2,8),(2,9),(3,9),(3,8),(4,8),(4,9),(5,9),(5,8),
1092           (6,8),(6,9),(7,9),(7,8),(8,8),(8,9),(9,9),(9,8),(10,8),(10,9),(11,9),(11,8),(12,8),(12,9),(13,9),(13,8),
1093           (14,8),(14,9),(15,9),(15,8),(16,8),(16,6),(15,6),(15,4),(14,4),(14,3),(13,3),(13,2),(11,2),(11,1),(16,11),
1094           (15,11),(15,13),(14,13),(14,14),(13,14),(13,15),(11,15),(11,16),(6,16),(6,15),(4,15),(4,14),(3,14),(3,13),(2,13),
1095           (2,11),(1,11)])
1096         src.setCoords(coo)
1097         c = DataArrayInt([5, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
1098          31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 5, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1099          21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
1100          60, 61, 62, 63, 64, 65])
1101         cI = DataArrayInt([0, 49, 98])
1102         src.setConnectivity(c, cI)
1103         src.checkConsistency()
1104         tgt = MEDCouplingCMesh('tgt')
1105         da = DataArrayDouble(18, 1); da.iota();
1106         tgt.setCoords(da, da)
1107         tgt = tgt.buildUnstructured()
1108         srcF = MEDCouplingFieldDouble(ON_CELLS, ONE_TIME)
1109         srcF.setArray(DataArrayDouble([25.,50.]))
1110         srcF.setMesh(src)
1111         srcF.setNature(IntensiveConservation)
1112         remap = MEDCouplingRemapper()
1113         remap.setIntersectionType(PointLocator)
1114         remap.prepare(src, tgt, "P0P0")
1115         tgtF = remap.transferField(srcF, 0.0)
1116         ids1 = [137, 139, 141, 143, 145, 147, 149, 151, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 171, 172,
1117         173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200,
1118         201, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 242,
1119         243, 244, 245, 246, 247, 248, 249, 250, 261, 262, 263, 264, 265]
1120         ids2 = [23, 24, 25, 26, 27, 38, 39, 40, 41, 42, 43, 44, 45, 46, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 70, 71, 72, 73, 74, 75, 76,
1121            77, 78, 79, 80, 81, 82, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113,
1122            114, 115, 116, 117, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 138, 140, 142, 144, 146, 148, 150]
1123         ids3 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 47, 48,
1124                 49, 50, 51, 52, 53, 65, 66, 67, 68, 69, 83, 84, 85, 86, 100, 101, 102, 118, 119, 135, 136, 152, 153, 169, 170, 186, 187, 188, 202, 203,
1125                 204, 205, 219, 220, 221, 222, 223, 235, 236, 237, 238, 239, 240, 241, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 266, 267, 268,
1126                 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288]
1127         a = tgtF.getArray()
1128         self.assertTrue(a[ids1].isUniform(50.0, 1e-12))
1129         self.assertTrue(a[ids2].isUniform(25.0, 1e-12))
1130         self.assertTrue(a[ids3].isUniform(0.0, 1e-12))
1131         pass
1132
1133     def testExtrudedOnDiffZLev1(self):
1134         """Non regression bug : This test is base on P0P0 ExtrudedExtruded. This test checks that if the input meshes are not based on a same plane // OXY the interpolation works"""
1135         arrX=DataArrayDouble([0,1]) ; arrY=DataArrayDouble([0,1]) ; arrZ=DataArrayDouble([0,1,2])
1136         src=MEDCouplingCMesh() ; src.setCoords(arrX,arrY,arrZ)
1137         arrX=DataArrayDouble([0.5,1.5]) ; arrY=DataArrayDouble([0.5,1.5]) ; arrZ=DataArrayDouble([0.5,2])
1138         trg=MEDCouplingCMesh() ; trg.setCoords(arrX,arrY,arrZ)
1139         #
1140         src=MEDCouplingMappedExtrudedMesh(src) ; trg=MEDCouplingMappedExtrudedMesh(trg)
1141         pt1=src.getMesh2D().getCoords().getHiddenCppPointer() ; pt2=trg.getMesh2D().getCoords().getHiddenCppPointer()
1142         #
1143         rem=MEDCouplingRemapper()
1144         rem.prepare(src,trg,"P0P0")
1145         self.checkMatrix(rem.getCrudeMatrix(),[{0:0.125,1:0.25}],src.getNumberOfCells(),1e-12)
1146         #
1147         self.assertEqual(src.getMesh2D().getSpaceDimension(),3)
1148         self.assertEqual(trg.getMesh2D().getSpaceDimension(),3)
1149         self.assertEqual(src.getMesh2D().getCoords().getHiddenCppPointer(),pt1)
1150         self.assertEqual(trg.getMesh2D().getCoords().getHiddenCppPointer(),pt2)
1151         #
1152         rem2=MEDCouplingRemapper()
1153         rem2.setIntersectionType(Geometric2D)
1154         rem2.prepare(src,trg,"P0P0")
1155         self.checkMatrix(rem2.getCrudeMatrix(),[{0:0.125,1:0.25}],src.getNumberOfCells(),1e-12)
1156         pass
1157
1158     def testP0P0WithHEXGP12(self):
1159         """ Test that HEXGP12 are correctly remapped (elements with polygonal faces were not properly handled) """
1160         # From Astrid, two disjoint hexagonal prisms:
1161         coo1 = [-4.991193077144312, 8.644999999999998, 0.0, -9.982386154288623, 6.112246755425186e-16, 0.0, -4.991193077144315, -8.644999999999998, 0.0, 4.991193077144309, -8.645000000000005, 0.0, 9.982386154288626, 1.1651321638577316e-15, 0.0, 4.991193077144314, 8.645, 0.0, -4.991193077144312, 8.644999999999998, 7.561799999999991, -9.982386154288623, 6.112246755425186e-16, 7.561799999999991, -4.991193077144315, -8.644999999999998, 7.561799999999991, 4.991193077144309, -8.645000000000005, 7.561799999999991, 9.982386154288626, 1.1651321638577316e-15, 7.561799999999991, 4.991193077144314, 8.645, 7.561799999999991]
1162         coo2 = [-4.991193077144313, -8.645, 0.0, -9.982386154288626, -1.3992140779350848e-15, 0.0, -19.964772308577256, 0.0, 0.0, -24.95596538572157, -8.644999999999998, 0.0, -19.96477230857726, -17.289999999999996, 0.0, -9.982386154288626, -17.289999999999996, 0.0, -4.991193077144313, -8.645, 5.041200000000004, -9.982386154288626, -1.3992140779350848e-15, 5.041200000000004, -19.964772308577256, 0.0, 5.041200000000004, -24.95596538572157, -8.644999999999998, 5.041200000000004, -19.96477230857726, -17.289999999999996, 5.041200000000004, -9.982386154288626, -17.289999999999996, 5.041200000000004]
1163         conn1 = [31, 0, 5, 4, 3, 2, 1, -1, 11, 6, 7, 8, 9, 10, -1, 1, 7, 6, 0, -1, 2, 8, 7, 1, -1, 3, 9, 8, 2, -1, 4, 10, 9, 3, -1, 5, 11, 10, 4, -1, 0, 6, 11, 5]
1164         cI1 = [0, 44]
1165         conn2 = [31, 0, 5, 4, 3, 2, 1, -1, 6, 7, 8, 9, 10, 11, -1, 0, 1, 7, 6, -1, 1, 2, 8, 7, -1, 2, 3, 9, 8, -1, 3, 4, 10, 9, -1, 4, 5, 11, 10, -1, 5, 0, 6, 11]
1166         cI2 = [0, 44]
1167         mTgt = MEDCouplingUMesh("target", 3)
1168         mSrc = MEDCouplingUMesh("src", 3)
1169         mTgt.setCoords(DataArrayDouble(coo1, len(coo1) // 3, 3))
1170         mSrc.setCoords(DataArrayDouble(coo2, len(coo2) // 3, 3))
1171         mTgt.setConnectivity(DataArrayInt(conn1), DataArrayInt(cI1))
1172         mSrc.setConnectivity(DataArrayInt(conn2), DataArrayInt(cI2))
1173
1174         # Recognize the HEXGP12:
1175         mTgt.unPolyze()
1176         mSrc.unPolyze()
1177
1178         rmp = MEDCouplingRemapper()
1179         rmp.setIntersectionType(Triangulation)
1180         rmp.prepare(mSrc, mTgt, "P0P0")
1181         mat = rmp.getCrudeMatrix()
1182         self.assertEqual(len(mat[0]), 0)
1183         self.assertEqual(len(mat), 1)
1184         pass
1185
1186     def testP0P0KillerTet(self):
1187         """ The killer tetrahedron detected by LMEC!"""
1188         mesh = MEDCouplingUMesh('SupportOf_ECHIA1_Tin', 3)
1189 #         # was OK:
1190 #         coo = DataArrayDouble([(-4.50135,1.95352,4.59608),(-4.50409,1.86642,4.54551), (-4.55175,1.92167,4.64844),(-4.58813,1.94795,4.5283)])
1191         # was KO:
1192         coo = DataArrayDouble([(-4.501352938826142847,1.953517433537110159,4.596082552008083688),(-4.504092113061189728,1.866415526007169978,4.545507396150389567),(-4.551750368181751050,1.921669328035479962,4.648439577911889664),(-4.588131417812300050,1.947948377683889953,4.528298931319220344)])
1193         mesh.setCoords(coo)
1194         c = DataArrayInt([14, 2, 0, 3, 1]); cI = DataArrayInt([0, 5])
1195         mesh.setConnectivity(c, cI)
1196         mesh_src, mesh_tgt = mesh.deepCopy(), mesh.deepCopy()
1197         field_src = mesh_src.fillFromAnalytic(ON_CELLS, 1, "1")
1198         field_src.setNature(IntensiveMaximum)
1199         rmp = MEDCouplingRemapper()
1200         rmp.setIntersectionType(Triangulation)
1201         rmp.prepare(mesh_src, mesh_tgt, "P0P0")
1202         self.assertEqual(1, len(rmp.getCrudeMatrix()))
1203         self.assertEqual(1, len(rmp.getCrudeMatrix()[0]))
1204         pass
1205
1206     @unittest.skipUnless(MEDCouplingHasNumPyBindings() and MEDCouplingHasSciPyBindings(),"requires numpy AND scipy AND C++11")
1207     def testP1P1PL3DSpaceFrom1DTo0D(self):
1208         from scipy.sparse import csr_matrix
1209         from numpy import array
1210
1211         def generateTrg(eps):
1212             trgArr=DataArrayDouble([(0.5,0.5,0.5),(0.2,0.2,0.2),(0.9,0.9,0.9),(0.7+eps*sqrt(3),0.7-eps*sqrt(3),0.7)])
1213             trg=MEDCouplingUMesh("trg",0) ; trg.setCoords(trgArr)
1214             trg.allocateCells()
1215             RenumTrg=[2,3,0,1]
1216             for rt in RenumTrg:
1217                 trg.insertNextCell(NORM_POINT1,[rt])
1218             return trg
1219
1220         srcArr=DataArrayDouble([(0.,0.,1.),(0.,0.,0.),(1.,1.,1.)])
1221         src=MEDCouplingUMesh("src",1) ; src.setCoords(srcArr)
1222         src.allocateCells()
1223         src.insertNextCell(NORM_SEG2,[1,2])
1224         #
1225         trg=generateTrg(1e-7)# trg point 3 of trg cell 1 is NOT closer enough to source edge #1 -> not intercepted
1226         #
1227         rem=MEDCouplingRemapper()
1228         rem.setIntersectionType(PointLocator)
1229         self.assertEqual(rem.prepare(src,trg,"P1P1"),1)
1230         mat=rem.getCrudeCSRMatrix()
1231         row=array([2,2, 0,0, 1,1]) # here no ref to point 3 !
1232         col=array([1,2, 1,2, 1,2])
1233         data=array([0.1,0.9, 0.5,0.5, 0.8,0.2])
1234         mExp=csr_matrix((data,(row,col)),shape=(4,3))
1235         delta=abs(mExp-mat)
1236         self.assertAlmostEqual(delta.sum(),0.,14)
1237         #
1238         trg=generateTrg(1e-14) # trg point 3 of trg cell 1 is closer enough to source edge #1 -> intercepted
1239         rem=MEDCouplingRemapper()
1240         rem.setIntersectionType(PointLocator)
1241         self.assertEqual(rem.prepare(src,trg,"P1P1"),1)
1242         mat=rem.getCrudeCSRMatrix()
1243         row=array([2,2, 3,3, 0,0, 1,1]) # here ref to target point 3
1244         col=array([1,2, 1,2, 1,2, 1,2])
1245         data=array([0.1,0.9, 0.3,0.7, 0.5,0.5, 0.8,0.2])
1246         mExp2=csr_matrix((data,(row,col)),shape=(4,3))
1247         delta2=abs(mExp2-mat)
1248         self.assertAlmostEqual(delta2.sum(),0.,14)
1249         pass
1250
1251     def testSetMatrix1(self):
1252         """ Remapper has now setCrudeMatrix method to reload matrix to skip prepare phase """
1253         cooS=DataArrayDouble([1,1, 7,1, 7,2, 1,2],4,2)
1254         cooT=DataArrayDouble([0,0, 3,0, 3,3, 0,3, 6,0, 12,0, 12,3, 6,3],8,2)
1255         ms=MEDCouplingUMesh("source",2) ; ms.allocateCells(1) ; ms.insertNextCell(NORM_QUAD4,[0,1,2,3]) ; ms.setCoords(cooS)
1256         mt=MEDCouplingUMesh("target",2) ; mt.allocateCells(2) ; mt.insertNextCell(NORM_QUAD4,[0,1,2,3]) ; mt.insertNextCell(NORM_QUAD4,[4,5,6,7]) ; mt.setCoords(cooT)
1257         rem=MEDCouplingRemapper()
1258         self.assertEqual(rem.prepare(ms,mt,"P0P0"),1) # [{0: 2.0}, {0: 1.0}]
1259         fs=MEDCouplingFieldDouble(ON_CELLS)
1260         fs.setMesh(ms)
1261         fs.setArray(DataArrayDouble([10]))
1262         fs.checkConsistencyLight()
1263         #
1264         fs.setNature(ExtensiveConservation)
1265         self.assertTrue(rem.transferField(fs,1e300).getArray().isEqual(DataArrayDouble([20./3,10./3.]),1e-12))# sum is equal to 10. First value is twice than second value
1266         #
1267         fs.setNature(ExtensiveMaximum)
1268         self.assertTrue(rem.transferField(fs,1e300).getArray().isEqual(DataArrayDouble([20./6.,10./6.]),1e-12))#sum is equal to 5 (10/2. because only half part on input cell is intercepted by the target cells). First value is twice than second value
1269         #
1270         fs.setNature(IntensiveConservation)
1271         self.assertTrue(rem.transferField(fs,1e300).getArray().isEqual(DataArrayDouble([2./9.*10.,1./18.*10.]),1e-12))#
1272         #
1273         fs.setNature(IntensiveMaximum)
1274         self.assertTrue(rem.transferField(fs,1e300).getArray().isEqual(DataArrayDouble([10.,10.]),1e-12))#
1275         ####
1276         rem2=MEDCouplingRemapper()
1277         rem2.setCrudeMatrix(ms,mt,"P0P0",rem.getCrudeMatrix())
1278         fs.setNature(ExtensiveConservation)
1279         self.assertTrue(rem2.transferField(fs,1e300).getArray().isEqual(DataArrayDouble([20./3,10./3.]),1e-12))
1280         #
1281         fs.setNature(ExtensiveMaximum)
1282         self.assertTrue(rem2.transferField(fs,1e300).getArray().isEqual(DataArrayDouble([20./6.,10./6.]),1e-12))
1283         #
1284         fs.setNature(IntensiveConservation)
1285         self.assertTrue(rem2.transferField(fs,1e300).getArray().isEqual(DataArrayDouble([2./9.*10.,1./18.*10.]),1e-12))
1286         #
1287         fs.setNature(IntensiveMaximum)
1288         self.assertTrue(rem2.transferField(fs,1e300).getArray().isEqual(DataArrayDouble([10.,10.]),1e-12))
1289         #
1290         srcFt=MEDCouplingFieldTemplate.New(ON_CELLS);
1291         trgFt=MEDCouplingFieldTemplate.New(ON_CELLS);
1292         srcFt.setMesh(ms);
1293         trgFt.setMesh(mt);
1294         rem3=MEDCouplingRemapper()
1295         rem3.setCrudeMatrixEx(srcFt,trgFt,rem.getCrudeMatrix())
1296         fs.setNature(ExtensiveConservation)
1297         self.assertTrue(rem3.transferField(fs,1e300).getArray().isEqual(DataArrayDouble([20./3,10./3.]),1e-12))
1298         pass
1299
1300     @unittest.skipUnless(MEDCouplingHasNumPyBindings() and MEDCouplingHasSciPyBindings(),"requires numpy AND scipy")
1301     def testSetMatrix2(self):
1302         """ Remapper has now setCrudeMatrix method to reload matrix to skip prepare phase. Same as testSetMatrix1 but with CSR scipy matrix """
1303         arrx_s=DataArrayDouble(6) ; arrx_s.iota()
1304         arry_s=DataArrayDouble(6) ; arry_s.iota()
1305         ms=MEDCouplingCMesh() ; ms.setCoords(arrx_s,arry_s)
1306         ms=ms.buildUnstructured()
1307         #
1308         arrx_t=DataArrayDouble([2.5,4.5,5.5])
1309         arry_t=DataArrayDouble([2.5,3.5,5.5])
1310         mt=MEDCouplingCMesh() ; mt.setCoords(arrx_t,arry_t)
1311         mt=mt.buildUnstructured()
1312         #
1313         rem=MEDCouplingRemapper()
1314         self.assertEqual(rem.prepare(ms,mt,"P0P0"),1)
1315         #
1316         fs=MEDCouplingFieldDouble(ON_CELLS)
1317         fs.setMesh(ms)
1318         arr=DataArrayDouble(25) ; arr.iota()
1319         fs.setArray(arr)
1320         fs.checkConsistencyLight()
1321         #
1322         fs.setNature(ExtensiveConservation)
1323         self.assertTrue(rem.transferField(fs,1e300).getArray().isEqual(DataArrayDouble([54.25,11.75,79.25,16.75]),1e-12))
1324         mat=rem.getCrudeCSRMatrix()
1325         rem2=MEDCouplingRemapper()
1326         rem2.setCrudeMatrix(ms,mt,"P0P0",mat)
1327         self.assertTrue(rem2.transferField(fs,1e300).getArray().isEqual(DataArrayDouble([54.25,11.75,79.25,16.75]),1e-12))
1328         pass
1329
1330     def testSmallTetraCell(self):
1331         """This test is a non regression test. When using tetra/tetra P0P0 interpolation on very small cells the
1332         3x3 matrix in the TetraAffine contains very small values and so the determinant is small (cubic).
1333         So the tetra was detected as flat. Now the infinite norm of matrix is considered to establish if matrix is inversible or not."""
1334         coords = [(-0.019866666666666668, 0.02, 0.002), (-0.020000073463967143, 0.019999926535763005, 0.0018666666666666673), (-0.020000073463967143, 0.019999926535763005, 0.002), (-0.020000072974206463, 0.019866593202430387, 0.002)]
1335         m=MEDCouplingUMesh("mesh",3)
1336         m.allocateCells()
1337         m.insertNextCell(NORM_TETRA4,[0,1,2,3])
1338         m.setCoords(DataArrayDouble(coords))
1339         rem=MEDCouplingRemapper()
1340         rem.setPrecision(1e-12)
1341         rem.prepare(m,m,"P0P0")
1342         mat=rem.getCrudeMatrix()
1343         self.assertTrue(len(mat)==1)
1344         self.assertTrue(len(mat[0])==1)
1345         self.assertTrue(list(mat[0].keys())==[0])
1346         res=list(mat[0].values())[0]
1347         ref=float(m.getMeasureField(True).getArray())
1348         self.assertTrue(abs(res-ref)/ref<1e-12)
1349         pass
1350
1351     def test3D0DPointLocator(self):
1352         """
1353         For pointlocator fans, Remapper support following intersection
1354         IntersectionType == PointLocator
1355         - source == 3D
1356         - target == 0D
1357         """
1358         src = MEDCouplingUMesh("src",3)
1359         src.allocateCells()
1360         src.setCoords( DataArrayDouble([(0,0,0),(1,0,0),(0,1,0),(0,0,1)]) )
1361         src.insertNextCell(NORM_TETRA4,[0,1,2,3])
1362         trg = MEDCouplingUMesh.Build0DMeshFromCoords( DataArrayDouble([(0.4,0.3,0.07)]) )
1363         # P1P1
1364         rem=MEDCouplingRemapper()
1365         rem.setIntersectionType(PointLocator)
1366         rem.prepare(src,trg,"P1P1")
1367         self.checkMatrix(rem.getCrudeMatrix(),[{0:0.23,1:0.4,2:0.3,3:0.07}],src.getNumberOfNodes(),1e-12)
1368         # P1P0
1369         rem=MEDCouplingRemapper()
1370         rem.setIntersectionType(PointLocator)
1371         rem.prepare(src,trg,"P1P0")
1372         self.checkMatrix(rem.getCrudeMatrix(),[{0:0.23,1:0.4,2:0.3,3:0.07}],src.getNumberOfNodes(),1e-12)
1373         # P0P1
1374         rem=MEDCouplingRemapper()
1375         rem.setIntersectionType(PointLocator)
1376         rem.prepare(src,trg,"P0P1")
1377         self.checkMatrix(rem.getCrudeMatrix(),[{0:1.0}],src.getNumberOfCells(),1e-12)
1378         # P0P0
1379         rem=MEDCouplingRemapper()
1380         rem.setIntersectionType(PointLocator)
1381         rem.prepare(src,trg,"P0P0")
1382         self.checkMatrix(rem.getCrudeMatrix(),[{0:1.0}],src.getNumberOfCells(),1e-12)
1383         pass
1384
1385     def test2D0DPointLocator(self):
1386         """
1387         For pointlocator fans, Remapper support following intersection
1388         IntersectionType == PointLocator
1389         - source == 2D
1390         - target == 0D
1391         """
1392         src = MEDCouplingUMesh("src",2)
1393         src.allocateCells()
1394         src.setCoords( DataArrayDouble([(0,0),(1,0),(0,1)]) )
1395         src.insertNextCell(NORM_TRI3,[0,1,2])
1396         trg = MEDCouplingUMesh.Build0DMeshFromCoords( DataArrayDouble([(0.4,0.3)]) )
1397         # P1P1
1398         rem=MEDCouplingRemapper()
1399         rem.setIntersectionType(PointLocator)
1400         rem.prepare(src,trg,"P1P1")
1401         self.checkMatrix(rem.getCrudeMatrix(),[{0:0.3,1:0.4,2:0.3}],src.getNumberOfNodes(),1e-12)
1402         # P1P0
1403         rem=MEDCouplingRemapper()
1404         rem.setIntersectionType(PointLocator)
1405         rem.prepare(src,trg,"P1P0")
1406         self.checkMatrix(rem.getCrudeMatrix(),[{0:0.3,1:0.4,2:0.3}],src.getNumberOfNodes(),1e-12)
1407         # P0P1
1408         rem=MEDCouplingRemapper()
1409         rem.setIntersectionType(PointLocator)
1410         rem.prepare(src,trg,"P0P1")
1411         self.checkMatrix(rem.getCrudeMatrix(),[{0:1.0}],src.getNumberOfNodes(),1e-12)
1412         # P0P0
1413         rem=MEDCouplingRemapper()
1414         rem.setIntersectionType(PointLocator)
1415         rem.prepare(src,trg,"P0P0")
1416         self.checkMatrix(rem.getCrudeMatrix(),[{0:1.0}],src.getNumberOfNodes(),1e-12)
1417         pass
1418
1419     def test1D0DPointLocator(self):
1420         """
1421         For pointlocator fans, Remapper support following intersection
1422         IntersectionType == PointLocator
1423         - source == 1D
1424         - target == 0D
1425         """
1426         # P1P1 - 0
1427         src = MEDCouplingUMesh("src",1)
1428         src.allocateCells()
1429         src.setCoords( DataArrayDouble([0,1]) )
1430         src.insertNextCell(NORM_SEG2,[0,1])
1431         trg = MEDCouplingUMesh.Build0DMeshFromCoords( DataArrayDouble([0.4]) )
1432         rem=MEDCouplingRemapper()
1433         rem.setIntersectionType(PointLocator)
1434         rem.prepare(src,trg,"P1P1")
1435         self.checkMatrix(rem.getCrudeMatrix(),[{0:0.6,1:0.4}],src.getNumberOfNodes(),1e-12)
1436         # P1P1 - 1
1437         src = MEDCouplingUMesh("src",1)
1438         src.allocateCells()
1439         src.setCoords( DataArrayDouble([0,1]) )
1440         src.insertNextCell(NORM_SEG2,[1,0]) # permutation
1441         trg = MEDCouplingUMesh.Build0DMeshFromCoords( DataArrayDouble([0.4]) )
1442         rem=MEDCouplingRemapper()
1443         rem.setIntersectionType(PointLocator)
1444         rem.prepare(src,trg,"P1P1")
1445         self.checkMatrix(rem.getCrudeMatrix(),[{0:0.6,1:0.4}],src.getNumberOfNodes(),1e-12)
1446         # P1P1 - 2
1447         src = MEDCouplingUMesh("src",1)
1448         src.allocateCells()
1449         src.setCoords( DataArrayDouble([1,0]) )
1450         src.insertNextCell(NORM_SEG2,[0,1])
1451         trg = MEDCouplingUMesh.Build0DMeshFromCoords( DataArrayDouble([0.4]) )
1452         rem=MEDCouplingRemapper()
1453         rem.setIntersectionType(PointLocator)
1454         rem.prepare(src,trg,"P1P1")
1455         self.checkMatrix(rem.getCrudeMatrix(),[{0:0.4,1:0.6}],src.getNumberOfNodes(),1e-12)
1456         # P1P1 - 3 - 2DCurve
1457         src = MEDCouplingUMesh("src",1)
1458         src.allocateCells()
1459         src.setCoords( DataArrayDouble([0,1]) )
1460         src.insertNextCell(NORM_SEG2,[0,1])
1461         trg = MEDCouplingUMesh.Build0DMeshFromCoords( DataArrayDouble([0.4]) )
1462         src.changeSpaceDimension(2) ; trg.changeSpaceDimension(2)
1463         src.rotate([-1.,-1.],1.2)
1464         trg.rotate([-1.,-1.],1.2)
1465         rem=MEDCouplingRemapper()
1466         rem.setIntersectionType(PointLocator)
1467         rem.prepare(src,trg,"P1P1")
1468         self.checkMatrix(rem.getCrudeMatrix(),[{0:0.6,1:0.4}],src.getNumberOfNodes(),1e-12)
1469         # P1P1 - 4
1470         src = MEDCouplingUMesh("src",1)
1471         src.allocateCells()
1472         src.setCoords( DataArrayDouble([1.1,7.6,2.3,5.4]) )
1473         src.insertNextCell(NORM_SEG2,[0,2])
1474         src.insertNextCell(NORM_SEG2,[2,3])
1475         src.insertNextCell(NORM_SEG2,[3,1])
1476         for eps in [0,1e-13,-1e-13]:
1477             trg = MEDCouplingUMesh.Build0DMeshFromCoords( DataArrayDouble([0.4,2.3+eps,4.,7.]) )
1478             rem=MEDCouplingRemapper()
1479             rem.setIntersectionType(PointLocator)
1480             rem.prepare(src,trg,"P1P1")
1481             rem.nullifiedTinyCoeffInCrudeMatrixAbs(1e-12)
1482             self.checkMatrix(rem.getCrudeMatrix(),[{}, {2: 2.0}, {2: 0.4516129032258065, 3: 0.5483870967741935}, {1: 0.7272727272727273, 3: 0.27272727272727265}],src.getNumberOfNodes(),1e-12)
1483         # P1P1 - 5 - descending order of coords in source mesh
1484         src = MEDCouplingUMesh("src",1)
1485         src.allocateCells()
1486         src.setCoords( DataArrayDouble([3.,1.]) )
1487         src.insertNextCell(NORM_SEG2,[0,1])
1488         trg = MEDCouplingUMesh.Build0DMeshFromCoords( DataArrayDouble([2.3]) )
1489         rem=MEDCouplingRemapper()
1490         rem.setIntersectionType(PointLocator)
1491         rem.prepare(src,trg,"P1P1")
1492         self.checkMatrix(rem.getCrudeMatrix(),[{0:0.65,1:0.35}],src.getNumberOfNodes(),1e-12)
1493         pass
1494
1495     @unittest.skipUnless(MEDCouplingHasNumPyBindings() and MEDCouplingHasSciPyBindings(),"requires numpy AND scipy")
1496     def testRemToCSRMatrix(self):
1497         import scipy
1498         mPy = [{0:1.0,1:3.0,3:7.0,6:10.},{1:12.0,2:23.0}]
1499         m = MEDCouplingRemapper.ToCSRMatrix(mPy,8)
1500         self.assertTrue(isinstance(m,scipy.sparse.csr.csr_matrix))
1501         self.assertEqual(m.getnnz(),6)
1502         self.assertAlmostEqual(m[0,0],1.0,12)
1503         self.assertAlmostEqual(m[0,1],3.0,12)
1504         self.assertAlmostEqual(m[0,3],7.0,12)
1505         self.assertAlmostEqual(m[0,6],10.0,12)
1506         self.assertAlmostEqual(m[1,1],12.0,12)
1507         self.assertAlmostEqual(m[1,2],23.0,12)
1508         self.assertEqual(m.shape,(2,8))
1509         pass
1510
1511     def checkMatrix(self,mat1,mat2,nbCols,eps):
1512         self.assertEqual(len(mat1),len(mat2))
1513         for i in range(len(mat1)):
1514             if len(mat2[i].keys())>0:
1515                 self.assertTrue(max(mat2[i].keys())<nbCols)
1516             if len(mat1[i].keys())>0:
1517                 self.assertTrue(max(mat1[i].keys())<nbCols)
1518             if len(mat2[i].keys())>0:
1519                 self.assertTrue(min(mat2[i].keys())>=0)
1520             if len(mat1[i].keys())>0:
1521                 self.assertTrue(min(mat1[i].keys())>=0)
1522             s1=set(mat1[i].keys()) ; s2=set(mat2[i].keys())
1523             for elt in s1.intersection(s2):
1524                 self.assertTrue(abs(mat1[i][elt]-mat2[i][elt])<eps)
1525                 pass
1526             for elt in s1.difference(s2):
1527                 self.assertTrue(abs(mat1[i][elt])<eps)
1528                 pass
1529             for elt in s2.difference(s1):
1530                 self.assertTrue(abs(mat2[i][elt])<eps)
1531                 pass
1532             pass
1533         pass
1534
1535     def build2DSourceMesh_1(self):
1536         sourceCoords=[-0.3,-0.3, 0.7,-0.3, -0.3,0.7, 0.7,0.7]
1537         sourceConn=[0,3,1,0,2,3]
1538         sourceMesh=MEDCouplingUMesh.New("my name of mesh 2D",2)
1539         sourceMesh.allocateCells(2);
1540         sourceMesh.insertNextCell(NORM_TRI3,3,sourceConn[0:3]);
1541         sourceMesh.insertNextCell(NORM_TRI3,3,sourceConn[3:6]);
1542         sourceMesh.finishInsertingCells();
1543         myCoords=DataArrayDouble.New();
1544         myCoords.setValues(sourceCoords,4,2);
1545         sourceMesh.setCoords(myCoords);
1546         return sourceMesh;
1547
1548     def build2DTargetMesh_1(self):
1549         targetCoords=[-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 ]
1550         targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
1551         targetMesh=MEDCouplingUMesh.New();
1552         targetMesh.setMeshDimension(2);
1553         targetMesh.allocateCells(5);
1554         targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[0:4]);
1555         targetMesh.insertNextCell(NORM_TRI3,3,targetConn[4:7]);
1556         targetMesh.insertNextCell(NORM_TRI3,3,targetConn[7:10]);
1557         targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[10:14]);
1558         targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[14:18]);
1559         targetMesh.finishInsertingCells();
1560         myCoords=DataArrayDouble.New();
1561         myCoords.setValues(targetCoords,9,2);
1562         targetMesh.setCoords(myCoords);
1563         return targetMesh;
1564
1565     def build2DTargetMesh_3(self):
1566         targetCoords=[-0.6,-0.4, -0.1,-0.4, 1.1,-0.4, 2.1,-0.4, -0.6,0.1,  -0.1,0.1,  1.1,0.1,  2.1,0.1, -0.6,1.1,  -0.1,1.1]
1567         targetConn=[0,4,5,1, 1,5,6,2, 2,6,7,3, 4,8,9,5]
1568         targetMesh=MEDCouplingUMesh.New();
1569         targetMesh.setMeshDimension(2);
1570         targetMesh.allocateCells(4);
1571         for i in range(4):
1572             targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[4*i:4*(i+1)])
1573             pass
1574         targetMesh.finishInsertingCells();
1575         myCoords=DataArrayDouble.New();
1576         myCoords.setValues(targetCoords,10,2);
1577         targetMesh.setCoords(myCoords);
1578         return targetMesh;
1579         pass
1580
1581     def setUp(self):
1582         pass
1583     pass
1584
1585 if __name__ == "__main__":
1586   unittest.main()