]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/MEDCoupling_Swig/MEDCouplingRemapperTest.py
Salome HOME
API modif : suppression of P1P0Bary policy. Now it is included in the intersection...
[tools/medcoupling.git] / src / MEDCoupling_Swig / MEDCouplingRemapperTest.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2013  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.
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.failUnless(remapper.prepare(sourceMesh,targetMesh,"P0P0")==1);
34         srcField=MEDCouplingFieldDouble.New(ON_CELLS);
35         srcField.setNature(ConservativeVolumic);
36         srcField.setMesh(sourceMesh);
37         array=DataArrayDouble.New();
38         ptr=sourceMesh.getNumberOfCells()*[None]
39         for i in xrange(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 xrange(targetMesh.getNumberOfCells()):
56             self.failUnless(abs(values[i]-valuesExpected[i])<1e-12);
57             pass
58         self.failUnless(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(ConservativeVolumic);
75         srcField.setMesh(sourceMesh);
76         array=DataArrayDouble.New();
77         ptr=sourceMesh.getNumberOfCells()*[None]
78         for i in xrange(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 xrange(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(ConservativeVolumic);
107         srcField.setMesh(sourceMesh);
108         array=DataArrayDouble.New();
109         ptr=sourceMesh.getNumberOfCells()*[None]
110         for i in xrange(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(ConservativeVolumic);
117         trgfield.setMesh(targetMesh);
118         array=DataArrayDouble.New();
119         ptr=targetMesh.getNumberOfCells()*[None]
120         for i in xrange(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 xrange(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(Integral) ;  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(Integral) ;  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.checkCoherency2(1e-10)
177         trg.checkCoherency()
178         fieldSrc=MEDCouplingFieldDouble(ON_CELLS,NO_TIME) ; fieldSrc.setMesh(src) ; arrSrc=DataArrayDouble([10.,30.])
179         fieldSrc.setNature(Integral) ;  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(Integral) ;  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(Integral) ;  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.checkCoherency2(1e-10)
233         src.checkCoherency()
234         fieldSrc=MEDCouplingFieldDouble(ON_CELLS,NO_TIME) ; fieldSrc.setMesh(src) ; arrSrc=DataArrayDouble(100) ; arrSrc.iota(7.7)
235         fieldSrc.setNature(Integral) ;  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(Integral) ;  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(Integral) ;  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(Integral) ;  fieldSrc.setArray(arrSrc) ; fieldSrc.checkCoherency()
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(mat1[0].keys(),mat2[0].keys()) ; self.assertEqual([0,1],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(RevIntegral)
317         f2=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f2.setMesh(src2) ; f2.setArray(d) ; f2.setNature(RevIntegral)
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(Integral) ; f2.setNature(Integral)
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(ON_CELLS)
337         #
338         n2o=um.simplexize(PLANAR_FACE_5)
339         f.setArray(f.getArray()[n2o])
340         f.checkCoherency()
341         f.setNature(ConservativeVolumic)
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.deepCpy() ; 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.deepCpy()
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.deepCpy()
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.deepCpy() ; 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.deepCpy() ; 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 build2DSourceMesh_1(self):
556         sourceCoords=[-0.3,-0.3, 0.7,-0.3, -0.3,0.7, 0.7,0.7]
557         sourceConn=[0,3,1,0,2,3]
558         sourceMesh=MEDCouplingUMesh.New("my name of mesh 2D",2)
559         sourceMesh.allocateCells(2);
560         sourceMesh.insertNextCell(NORM_TRI3,3,sourceConn[0:3]);
561         sourceMesh.insertNextCell(NORM_TRI3,3,sourceConn[3:6]);
562         sourceMesh.finishInsertingCells();
563         myCoords=DataArrayDouble.New();
564         myCoords.setValues(sourceCoords,4,2);
565         sourceMesh.setCoords(myCoords);
566         return sourceMesh;
567     
568     def build2DTargetMesh_1(self):
569         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 ]
570         targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
571         targetMesh=MEDCouplingUMesh.New();
572         targetMesh.setMeshDimension(2);
573         targetMesh.allocateCells(5);
574         targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[0:4]);
575         targetMesh.insertNextCell(NORM_TRI3,3,targetConn[4:7]);
576         targetMesh.insertNextCell(NORM_TRI3,3,targetConn[7:10]);
577         targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[10:14]);
578         targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[14:18]);
579         targetMesh.finishInsertingCells();
580         myCoords=DataArrayDouble.New();
581         myCoords.setValues(targetCoords,9,2);
582         targetMesh.setCoords(myCoords);
583         return targetMesh;
584
585     def build2DTargetMesh_3(self):
586         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]
587         targetConn=[0,4,5,1, 1,5,6,2, 2,6,7,3, 4,8,9,5]
588         targetMesh=MEDCouplingUMesh.New();
589         targetMesh.setMeshDimension(2);
590         targetMesh.allocateCells(4);
591         for i in xrange(4):
592             targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[4*i:4*(i+1)])
593             pass
594         targetMesh.finishInsertingCells();
595         myCoords=DataArrayDouble.New();
596         myCoords.setValues(targetCoords,10,2);
597         targetMesh.setCoords(myCoords);
598         return targetMesh;
599         pass
600     
601     def setUp(self):
602         pass
603     pass
604
605 unittest.main()