Salome HOME
Merge from V6_main 15/03/2013
[modules/med.git] / src / MEDCoupling / Test / MEDCouplingBasicsTest3.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDCouplingBasicsTest3.hxx"
22 #include "MEDCouplingUMesh.hxx"
23 #include "MEDCouplingCMesh.hxx"
24 #include "MEDCouplingExtrudedMesh.hxx"
25 #include "MEDCouplingFieldDouble.hxx"
26 #include "MEDCouplingMemArray.hxx"
27 #include "MEDCouplingGaussLocalization.hxx"
28
29 #include <cmath>
30 #include <functional>
31 #include <iterator>
32
33 using namespace ParaMEDMEM;
34
35 void MEDCouplingBasicsTest3::testGetMeasureFieldCMesh1()
36 {
37   MEDCouplingCMesh *m=MEDCouplingCMesh::New();
38   DataArrayDouble *da=DataArrayDouble::New();
39   const double discX[4]={2.3,3.4,5.8,10.2};
40   const double discY[3]={12.3,23.4,45.8};
41   const double discZ[5]={-0.7,1.2,1.25,2.13,2.67};
42   da->alloc(4,1);
43   std::copy(discX,discX+4,da->getPointer());
44   m->setCoordsAt(0,da);
45   da->decrRef();
46   m->checkCoherency();
47   CPPUNIT_ASSERT_EQUAL(4,m->getNumberOfNodes());
48   CPPUNIT_ASSERT_EQUAL(3,m->getNumberOfCells());
49   CPPUNIT_ASSERT_EQUAL(1,m->getSpaceDimension());
50   MEDCouplingFieldDouble *f=m->getMeasureField(true);
51   CPPUNIT_ASSERT_EQUAL(3,f->getNumberOfTuples());
52   CPPUNIT_ASSERT_EQUAL(1,f->getNumberOfComponents());
53   const double expected1[3]={1.1,2.4,4.4};
54   for(int i=0;i<3;i++)
55     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f->getIJ(i,0),1e-12);
56   f->decrRef();
57   DataArrayDouble *coords=m->getCoordinatesAndOwner();
58   CPPUNIT_ASSERT_EQUAL(4,coords->getNumberOfTuples());
59   CPPUNIT_ASSERT_EQUAL(1,coords->getNumberOfComponents());
60   for(int i=0;i<4;i++)
61     CPPUNIT_ASSERT_DOUBLES_EQUAL(discX[i],coords->getIJ(i,0),1e-12);
62   coords->decrRef();
63   coords=m->getBarycenterAndOwner();
64   CPPUNIT_ASSERT_EQUAL(3,coords->getNumberOfTuples());
65   CPPUNIT_ASSERT_EQUAL(1,coords->getNumberOfComponents());
66   const double expected1_3[3]={2.85,4.6,8.};
67   for(int i=0;i<3;i++)
68     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1_3[i],coords->getIJ(i,0),1e-12);
69   coords->decrRef();
70   //
71   da=DataArrayDouble::New();
72   da->alloc(3,1);
73   std::copy(discY,discY+3,da->getPointer());
74   m->setCoordsAt(1,da);
75   da->decrRef();
76   m->checkCoherency();
77   CPPUNIT_ASSERT_EQUAL(12,m->getNumberOfNodes());
78   CPPUNIT_ASSERT_EQUAL(6,m->getNumberOfCells());
79   CPPUNIT_ASSERT_EQUAL(2,m->getSpaceDimension());
80   f=m->getMeasureField(true);
81   CPPUNIT_ASSERT_EQUAL(6,f->getNumberOfTuples());
82   CPPUNIT_ASSERT_EQUAL(1,f->getNumberOfComponents());
83   const double expected2[6]={12.21,26.64,48.84,24.64,53.76,98.56};
84   for(int i=0;i<6;i++)
85     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(i,0),1e-12);
86   f->decrRef();
87   coords=m->getCoordinatesAndOwner();
88   CPPUNIT_ASSERT_EQUAL(12,coords->getNumberOfTuples());
89   CPPUNIT_ASSERT_EQUAL(2,coords->getNumberOfComponents());
90   const double expected2_2[24]={2.3,12.3,3.4,12.3,5.8,12.3,10.2,12.3, 2.3,23.4,3.4,23.4,5.8,23.4,10.2,23.4, 2.3,45.8,3.4,45.8,5.8,45.8,10.2,45.8};
91   for(int i=0;i<24;i++)
92     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2_2[i],coords->getIJ(0,i),1e-12);
93   coords->decrRef();
94   coords=m->getBarycenterAndOwner();
95   CPPUNIT_ASSERT_EQUAL(6,coords->getNumberOfTuples());
96   CPPUNIT_ASSERT_EQUAL(2,coords->getNumberOfComponents());
97   const double expected2_3[12]={2.85,17.85,4.6,17.85,8.,17.85, 2.85,34.6,4.6,34.6,8.,34.6};
98   for(int i=0;i<12;i++)
99     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2_3[i],coords->getIJ(0,i),1e-12);
100   coords->decrRef();
101   //
102   da=DataArrayDouble::New();
103   da->alloc(5,1);
104   std::copy(discZ,discZ+5,da->getPointer());
105   m->setCoordsAt(2,da);
106   da->decrRef();
107   m->checkCoherency();
108   CPPUNIT_ASSERT_EQUAL(60,m->getNumberOfNodes());
109   CPPUNIT_ASSERT_EQUAL(24,m->getNumberOfCells());
110   CPPUNIT_ASSERT_EQUAL(3,m->getSpaceDimension());
111   f=m->getMeasureField(true);
112   CPPUNIT_ASSERT_EQUAL(24,f->getNumberOfTuples());
113   CPPUNIT_ASSERT_EQUAL(1,f->getNumberOfComponents());
114   const double expected3[24]={23.199, 50.616, 92.796, 46.816, 102.144, 187.264, 0.6105, 1.332, 2.442, 1.232, 2.688, 4.928, 10.7448, 23.4432, 42.9792, 21.6832, 47.3088, 86.7328, 6.5934, 14.3856, 26.3736, 13.3056, 29.0304, 53.2224};
115   for(int i=0;i<24;i++)
116     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],f->getIJ(i,0),1e-12);
117   f->decrRef();
118   coords=m->getCoordinatesAndOwner();
119   CPPUNIT_ASSERT_EQUAL(60,coords->getNumberOfTuples());
120   CPPUNIT_ASSERT_EQUAL(3,coords->getNumberOfComponents());
121   const double expected3_2[180]={
122     2.3,12.3,-0.7, 3.4,12.3,-0.7, 5.8,12.3,-0.7, 10.2,12.3,-0.7, 2.3,23.4,-0.7, 3.4,23.4,-0.7, 5.8,23.4,-0.7, 10.2,23.4,-0.7, 2.3,45.8,-0.7, 3.4,45.8,-0.7, 5.8,45.8,-0.7, 10.2,45.8,-0.7,
123     2.3,12.3,1.2, 3.4,12.3,1.2, 5.8,12.3,1.2, 10.2,12.3,1.2, 2.3,23.4,1.2, 3.4,23.4,1.2, 5.8,23.4,1.2, 10.2,23.4,1.2, 2.3,45.8,1.2, 3.4,45.8,1.2, 5.8,45.8,1.2, 10.2,45.8,1.2,
124     2.3,12.3,1.25, 3.4,12.3,1.25, 5.8,12.3,1.25, 10.2,12.3,1.25, 2.3,23.4,1.25, 3.4,23.4,1.25, 5.8,23.4,1.25, 10.2,23.4,1.25, 2.3,45.8,1.25, 3.4,45.8,1.25, 5.8,45.8,1.25, 10.2,45.8,1.25,
125     2.3,12.3,2.13, 3.4,12.3,2.13, 5.8,12.3,2.13, 10.2,12.3,2.13, 2.3,23.4,2.13, 3.4,23.4,2.13, 5.8,23.4,2.13, 10.2,23.4,2.13, 2.3,45.8,2.13, 3.4,45.8,2.13, 5.8,45.8,2.13, 10.2,45.8,2.13,
126     2.3,12.3,2.67, 3.4,12.3,2.67, 5.8,12.3,2.67, 10.2,12.3,2.67, 2.3,23.4,2.67, 3.4,23.4,2.67, 5.8,23.4,2.67, 10.2,23.4,2.67, 2.3,45.8,2.67, 3.4,45.8,2.67, 5.8,45.8,2.67, 10.2,45.8,2.67
127   };
128   for(int i=0;i<180;i++)
129     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3_2[i],coords->getIJ(0,i),1e-12);
130   coords->decrRef();
131   coords=m->getBarycenterAndOwner();
132   CPPUNIT_ASSERT_EQUAL(24,coords->getNumberOfTuples());
133   CPPUNIT_ASSERT_EQUAL(3,coords->getNumberOfComponents());
134   const double expected3_3[72]={
135     2.85,17.85,0.25,4.6,17.85,0.25,8.,17.85,0.25, 2.85,34.6,0.25,4.6,34.6,0.25,8.,34.6,0.25,
136     2.85,17.85,1.225,4.6,17.85,1.225,8.,17.85,1.225, 2.85,34.6,1.225,4.6,34.6,1.225,8.,34.6,1.225,
137     2.85,17.85,1.69,4.6,17.85,1.69,8.,17.85,1.69, 2.85,34.6,1.69,4.6,34.6,1.69,8.,34.6,1.69,
138     2.85,17.85,2.4,4.6,17.85,2.4,8.,17.85,2.4, 2.85,34.6,2.4,4.6,34.6,2.4,8.,34.6,2.4
139   };
140   for(int i=0;i<72;i++)
141     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3_3[i],coords->getIJ(0,i),1e-12);
142   coords->decrRef();
143   //
144   m->decrRef();
145 }
146
147 void MEDCouplingBasicsTest3::testFieldDoubleZipCoords1()
148 {
149   MEDCouplingUMesh *m=build2DTargetMeshMergeNode_1();
150   MEDCouplingFieldDouble *f=m->fillFromAnalytic(ON_NODES,2,"x*2.");
151   f->getArray()->setInfoOnComponent(0,"titi");
152   f->getArray()->setInfoOnComponent(1,"tutu");
153   f->checkCoherency();
154   CPPUNIT_ASSERT_EQUAL(18,f->getNumberOfTuples());
155   CPPUNIT_ASSERT_EQUAL(2,f->getNumberOfComponents());
156   const double expected1[36]={-0.6, -0.6, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 0.4, 0.4};
157   for(int i=0;i<36;i++)
158     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f->getIJ(0,i),1e-12);
159   CPPUNIT_ASSERT(f->zipCoords());
160   f->checkCoherency();
161   const double expected2[30]={-0.6, -0.6, 1.4, 1.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 0.4, 0.4};
162   for(int i=0;i<30;i++)
163     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(0,i),1e-12);
164   CPPUNIT_ASSERT(!f->zipCoords());
165   f->checkCoherency();
166   for(int i=0;i<30;i++)
167     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(0,i),1e-12);
168   CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(0))=="titi");
169   CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(1))=="tutu");
170   f->decrRef();
171   m->decrRef();
172 }
173
174 void MEDCouplingBasicsTest3::testFieldDoubleZipConnectivity1()
175 {
176   MEDCouplingUMesh *m1=build2DTargetMesh_1();
177   MEDCouplingUMesh *m2=build2DTargetMesh_1();
178   const int cells1[3]={2,3,4};
179   MEDCouplingPointSet *m3_1=m2->buildPartOfMySelf(cells1,cells1+3,true);
180   MEDCouplingUMesh *m3=dynamic_cast<MEDCouplingUMesh *>(m3_1);
181   CPPUNIT_ASSERT(m3);
182   m2->decrRef();
183   MEDCouplingUMesh *m4=build2DSourceMesh_1();
184   MEDCouplingUMesh *m5=MEDCouplingUMesh::MergeUMeshes(m1,m3);
185   m1->decrRef();
186   m3->decrRef();
187   MEDCouplingUMesh *m6=MEDCouplingUMesh::MergeUMeshes(m5,m4);
188   m4->decrRef();
189   m5->decrRef();
190   //
191   CPPUNIT_ASSERT_EQUAL(10,m6->getNumberOfCells());
192   CPPUNIT_ASSERT_EQUAL(22,m6->getNumberOfNodes());
193   bool areNodesMerged;
194   int newNbOfNodes;
195   DataArrayInt *arr=m6->mergeNodes(1e-13,areNodesMerged,newNbOfNodes);
196   CPPUNIT_ASSERT_EQUAL(9,m6->getNumberOfNodes());
197   arr->decrRef();
198   MEDCouplingFieldDouble *f=m6->fillFromAnalytic(ON_CELLS,2,"x");
199   MEDCouplingFieldDouble *f2=m6->fillFromAnalytic(ON_NODES,2,"x");
200   CPPUNIT_ASSERT_EQUAL(10,f->getNumberOfTuples());
201   CPPUNIT_ASSERT_EQUAL(2,f->getNumberOfComponents());
202   const double expected1[20]={-0.05, -0.05, 0.3666666666666667, 0.3666666666666667, 0.53333333333333321, 0.53333333333333321,
203                               -0.05, -0.05, 0.45, 0.45, 0.53333333333333321, 0.53333333333333321, -0.05, -0.05, 0.45, 0.45,
204                               0.36666666666666659, 0.36666666666666659, 0.033333333333333326, 0.033333333333333326};
205   for(int i=0;i<20;i++)
206     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f->getIJ(0,i),1e-12);
207   f->getArray()->setInfoOnComponent(0,"titi");
208   f->getArray()->setInfoOnComponent(1,"tutu");
209   f->checkCoherency();
210   CPPUNIT_ASSERT(f->zipConnectivity(0));
211   const double expected2[14]={-0.05, -0.05, 0.3666666666666667, 0.3666666666666667, 0.53333333333333321, 0.53333333333333321,
212                               -0.05, -0.05, 0.45, 0.45, 0.36666666666666659, 0.36666666666666659, 0.033333333333333326, 0.033333333333333326};
213   CPPUNIT_ASSERT_EQUAL(7,f->getNumberOfTuples());
214   CPPUNIT_ASSERT_EQUAL(2,f->getNumberOfComponents());
215   for(int i=0;i<14;i++)
216     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(0,i),1e-12);
217   CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(0))=="titi");
218   CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(1))=="tutu");
219   CPPUNIT_ASSERT(!f->zipConnectivity(0));
220   f->decrRef();
221   //
222   const double expected3[18]={-0.3, -0.3, 0.2, 0.2, 0.7, 0.7, -0.3, -0.3, 0.2, 0.2, 0.7, 0.7, 
223                               -0.3, -0.3, 0.2, 0.2, 0.7, 0.7};
224   CPPUNIT_ASSERT_EQUAL(9,f2->getNumberOfTuples());
225   CPPUNIT_ASSERT_EQUAL(2,f2->getNumberOfComponents());
226   for(int i=0;i<18;i++)
227     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],f2->getIJ(0,i),1e-12);
228   CPPUNIT_ASSERT(f2->zipConnectivity(0));
229   CPPUNIT_ASSERT_EQUAL(9,f2->getNumberOfTuples());
230   CPPUNIT_ASSERT_EQUAL(2,f2->getNumberOfComponents());
231   for(int i=0;i<18;i++)
232     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],f2->getIJ(0,i),1e-12);
233   f2->decrRef();
234   //
235   m6->decrRef();
236 }
237
238 void MEDCouplingBasicsTest3::testDaDoubleRenumber1()
239 {
240   DataArrayDouble *a=DataArrayDouble::New();
241   a->alloc(7,2);
242   a->setInfoOnComponent(0,"toto");
243   a->setInfoOnComponent(1,"tata");
244   const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
245   std::copy(arr1,arr1+14,a->getPointer());
246   //
247   const int arr2[7]={3,1,0,6,5,4,2};
248   DataArrayDouble *b=a->renumber(arr2);
249   CPPUNIT_ASSERT_EQUAL(7,b->getNumberOfTuples());
250   CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
251   CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
252   CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
253   const double expected1[14]={3.1, 13.1, 2.1, 12.1, 7.1, 17.1, 1.1, 11.1, 6.1, 16.1, 5.1, 15.1, 4.1, 14.1};
254   for(int i=0;i<14;i++)
255     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
256   b->decrRef();
257   a->decrRef();
258   //
259   DataArrayInt *c=DataArrayInt::New();
260   c->alloc(7,2);
261   c->setInfoOnComponent(0,"toto");
262   c->setInfoOnComponent(1,"tata");
263   const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
264   std::copy(arr3,arr3+14,c->getPointer());
265   DataArrayInt *d=c->renumber(arr2);
266   CPPUNIT_ASSERT_EQUAL(7,d->getNumberOfTuples());
267   CPPUNIT_ASSERT_EQUAL(2,d->getNumberOfComponents());
268   CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
269   CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
270   const int expected2[14]={3, 13, 2, 12, 7, 17, 1, 11, 6, 16, 5, 15, 4, 14};
271   for(int i=0;i<14;i++)
272     CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
273   c->decrRef();
274   d->decrRef();
275 }
276
277 void MEDCouplingBasicsTest3::testDaDoubleRenumberAndReduce1()
278 {
279   DataArrayDouble *a=DataArrayDouble::New();
280   a->alloc(7,2);
281   a->setInfoOnComponent(0,"toto");
282   a->setInfoOnComponent(1,"tata");
283   const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
284   std::copy(arr1,arr1+14,a->getPointer());
285   //
286   const int arr2[7]={2,-1,1,-1,0,4,3};
287   DataArrayDouble *b=a->renumberAndReduce(arr2,5);
288   CPPUNIT_ASSERT_EQUAL(5,b->getNumberOfTuples());
289   CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
290   CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
291   CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
292   const double expected1[10]={5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1};
293   for(int i=0;i<10;i++)
294     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
295   b->decrRef();
296   a->decrRef();
297   //
298   DataArrayInt *c=DataArrayInt::New();
299   c->alloc(7,2);
300   c->setInfoOnComponent(0,"toto");
301   c->setInfoOnComponent(1,"tata");
302   const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
303   std::copy(arr3,arr3+14,c->getPointer());
304   DataArrayInt *d=c->renumberAndReduce(arr2,5);
305   CPPUNIT_ASSERT_EQUAL(5,d->getNumberOfTuples());
306   CPPUNIT_ASSERT_EQUAL(2,d->getNumberOfComponents());
307   CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
308   CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
309   const int expected2[10]={5,15,3,13,1,11,7,17,6,16};
310   for(int i=0;i<10;i++)
311     CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
312   c->decrRef();
313   d->decrRef();
314 }
315
316 void MEDCouplingBasicsTest3::testDaDoubleRenumberInPlace1()
317 {
318   DataArrayDouble *a=DataArrayDouble::New();
319   a->alloc(7,2);
320   const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
321   std::copy(arr1,arr1+14,a->getPointer());
322   //
323   const int arr2[7]={3,1,0,6,5,4,2};
324   a->renumberInPlace(arr2);
325   CPPUNIT_ASSERT_EQUAL(7,a->getNumberOfTuples());
326   CPPUNIT_ASSERT_EQUAL(2,a->getNumberOfComponents());
327   const double expected1[14]={3.1, 13.1, 2.1, 12.1, 7.1, 17.1, 1.1, 11.1, 6.1, 16.1, 5.1, 15.1, 4.1, 14.1};
328   for(int i=0;i<14;i++)
329     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],a->getIJ(0,i),1e-14);
330   a->decrRef();
331   //
332   DataArrayInt *c=DataArrayInt::New();
333   c->alloc(7,2);
334   const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
335   std::copy(arr3,arr3+14,c->getPointer());
336   c->renumberInPlace(arr2);
337   CPPUNIT_ASSERT_EQUAL(7,c->getNumberOfTuples());
338   CPPUNIT_ASSERT_EQUAL(2,c->getNumberOfComponents());
339   const int expected2[14]={3, 13, 2, 12, 7, 17, 1, 11, 6, 16, 5, 15, 4, 14};
340   for(int i=0;i<14;i++)
341     CPPUNIT_ASSERT_EQUAL(expected2[i],c->getIJ(0,i));
342   c->decrRef();
343 }
344
345 void MEDCouplingBasicsTest3::testDaDoubleRenumberR1()
346 {
347   DataArrayDouble *a=DataArrayDouble::New();
348   a->alloc(7,2);
349   a->setInfoOnComponent(0,"toto");
350   a->setInfoOnComponent(1,"tata");
351   const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
352   std::copy(arr1,arr1+14,a->getPointer());
353   //
354   const int arr2[7]={3,1,0,6,5,4,2};
355   DataArrayDouble *b=a->renumberR(arr2);
356   CPPUNIT_ASSERT_EQUAL(7,b->getNumberOfTuples());
357   CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
358   CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
359   CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
360   const double expected1[14]={4.1, 14.1, 2.1, 12.1, 1.1, 11.1, 7.1, 17.1, 6.1, 16.1, 5.1, 15.1, 3.1, 13.1};
361   for(int i=0;i<14;i++)
362     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
363   b->decrRef();
364   a->decrRef();
365   //
366   DataArrayInt *c=DataArrayInt::New();
367   c->alloc(7,2);
368   c->setInfoOnComponent(0,"toto");
369   c->setInfoOnComponent(1,"tata");
370   const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
371   std::copy(arr3,arr3+14,c->getPointer());
372   DataArrayInt *d=c->renumberR(arr2);
373   CPPUNIT_ASSERT_EQUAL(7,d->getNumberOfTuples());
374   CPPUNIT_ASSERT_EQUAL(2,d->getNumberOfComponents());
375   CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
376   CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
377   const int expected2[14]={4, 14, 2, 12, 1, 11, 7, 17, 6, 16, 5, 15, 3, 13};
378   for(int i=0;i<14;i++)
379     CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
380   c->decrRef();
381   d->decrRef();
382 }
383
384 void MEDCouplingBasicsTest3::testDaDoubleRenumberInPlaceR1()
385 {
386   DataArrayDouble *a=DataArrayDouble::New();
387   a->alloc(7,2);
388   const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
389   std::copy(arr1,arr1+14,a->getPointer());
390   //
391   const int arr2[7]={3,1,0,6,5,4,2};
392   a->renumberInPlaceR(arr2);
393   CPPUNIT_ASSERT_EQUAL(7,a->getNumberOfTuples());
394   CPPUNIT_ASSERT_EQUAL(2,a->getNumberOfComponents());
395   const double expected1[14]={4.1, 14.1, 2.1, 12.1, 1.1, 11.1, 7.1, 17.1, 6.1, 16.1, 5.1, 15.1, 3.1, 13.1};
396   for(int i=0;i<14;i++)
397     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],a->getIJ(0,i),1e-14);
398   a->decrRef();
399   //
400   DataArrayInt *c=DataArrayInt::New();
401   c->alloc(7,2);
402   const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
403   std::copy(arr3,arr3+14,c->getPointer());
404   c->renumberInPlaceR(arr2);
405   CPPUNIT_ASSERT_EQUAL(7,c->getNumberOfTuples());
406   CPPUNIT_ASSERT_EQUAL(2,c->getNumberOfComponents());
407   const int expected2[14]={4, 14, 2, 12, 1, 11, 7, 17, 6, 16, 5, 15, 3, 13};
408   for(int i=0;i<14;i++)
409     CPPUNIT_ASSERT_EQUAL(expected2[i],c->getIJ(0,i));
410   c->decrRef();
411 }
412
413 void MEDCouplingBasicsTest3::testDaDoubleSelectByTupleId1()
414 {
415   DataArrayDouble *a=DataArrayDouble::New();
416   a->alloc(7,2);
417   a->setInfoOnComponent(0,"toto");
418   a->setInfoOnComponent(1,"tata");
419   const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
420   std::copy(arr1,arr1+14,a->getPointer());
421   //
422   const int arr2[7]={4,2,0,6,5};
423   DataArrayDouble *b=a->selectByTupleId(arr2,arr2+5);
424   CPPUNIT_ASSERT_EQUAL(5,b->getNumberOfTuples());
425   CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
426   CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
427   CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
428   const double expected1[10]={5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1};
429   for(int i=0;i<10;i++)
430     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
431   b->decrRef();
432   a->decrRef();
433   //
434   DataArrayInt *c=DataArrayInt::New();
435   c->alloc(7,2);
436   c->setInfoOnComponent(0,"toto");
437   c->setInfoOnComponent(1,"tata");
438   const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
439   std::copy(arr3,arr3+14,c->getPointer());
440   DataArrayInt *d=c->selectByTupleId(arr2,arr2+5);
441   CPPUNIT_ASSERT_EQUAL(5,d->getNumberOfTuples());
442   CPPUNIT_ASSERT_EQUAL(2,d->getNumberOfComponents());
443   CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
444   CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
445   const int expected2[10]={5,15,3,13,1,11,7,17,6,16};
446   for(int i=0;i<10;i++)
447     CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
448   c->decrRef();
449   d->decrRef();
450 }
451
452 void MEDCouplingBasicsTest3::testDaDoubleGetMinMaxValues1()
453 {
454   DataArrayDouble *a=DataArrayDouble::New();
455   a->alloc(9,1);
456   const double arr1[9]={2.34,4.56,-6.77,4.55,4.56,2.24,2.34,1.02,4.56};
457   std::copy(arr1,arr1+9,a->getPointer());
458   int where;
459   double m=a->getMaxValue(where);
460   CPPUNIT_ASSERT_EQUAL(1,where);
461   CPPUNIT_ASSERT_DOUBLES_EQUAL(4.56,m,1e-12);
462   DataArrayInt *ws;
463   m=a->getMaxValue2(ws);
464   CPPUNIT_ASSERT_DOUBLES_EQUAL(4.56,m,1e-12);
465   CPPUNIT_ASSERT_EQUAL(3,ws->getNumberOfTuples());
466   CPPUNIT_ASSERT_EQUAL(1,ws->getNumberOfComponents());
467   const int expected1[3]={1,4,8};
468   for(int i=0;i<3;i++)
469     CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
470   ws->decrRef();
471   a->decrRef();
472   a=DataArrayDouble::New();
473   const double arr2[9]={-2.34,-4.56,6.77,-4.55,-4.56,-2.24,-2.34,-1.02,-4.56};
474   a->alloc(9,1);
475   std::copy(arr2,arr2+9,a->getPointer());
476   where=-2;
477   m=a->getMinValue(where);
478   CPPUNIT_ASSERT_EQUAL(1,where);
479   CPPUNIT_ASSERT_DOUBLES_EQUAL(-4.56,m,1e-12);
480   m=a->getMinValue2(ws);
481   CPPUNIT_ASSERT_DOUBLES_EQUAL(-4.56,m,1e-12);
482   CPPUNIT_ASSERT_EQUAL(3,ws->getNumberOfTuples());
483   CPPUNIT_ASSERT_EQUAL(1,ws->getNumberOfComponents());
484   for(int i=0;i<3;i++)
485     CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
486   ws->decrRef();
487   a->decrRef();
488 }
489
490 void MEDCouplingBasicsTest3::testFieldDoubleGetMinMaxValues2()
491 {
492   MEDCouplingUMesh *m1=0;
493   MEDCouplingUMesh *m2=build3DExtrudedUMesh_1(m1);
494   m1->decrRef();
495   CPPUNIT_ASSERT_EQUAL(18,m2->getNumberOfCells());
496   const double arr1[18]={8.71,4.53,-12.41,8.71,-8.71,8.7099,4.55,8.71,5.55,6.77,-1e-200,4.55,8.7099,0.,1.23,0.,2.22,8.71};
497   MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
498   DataArrayDouble *a=DataArrayDouble::New();
499   a->alloc(18,1);
500   std::copy(arr1,arr1+18,a->getPointer());
501   f->setArray(a);
502   a->decrRef();
503   f->setMesh(m2);
504   //
505   f->checkCoherency();
506   double m=f->getMaxValue();
507   CPPUNIT_ASSERT_DOUBLES_EQUAL(8.71,m,1e-12);
508   DataArrayInt *ws;
509   m=f->getMaxValue2(ws);
510   CPPUNIT_ASSERT_DOUBLES_EQUAL(8.71,m,1e-12);
511   CPPUNIT_ASSERT_EQUAL(4,ws->getNumberOfTuples());
512   CPPUNIT_ASSERT_EQUAL(1,ws->getNumberOfComponents());
513   const int expected1[4]={0,3,7,17};
514   for(int i=0;i<4;i++)
515     CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
516   ws->decrRef();
517   //
518   const double arr2[18]={-8.71,-4.53,12.41,-8.71,8.71,-8.7099,-4.55,-8.71,-5.55,-6.77,1e-200,-4.55,-8.7099,0.,-1.23,0.,-2.22,-8.71};
519   std::copy(arr2,arr2+18,a->getPointer());
520   f->checkCoherency();
521   m=f->getMinValue();
522   CPPUNIT_ASSERT_DOUBLES_EQUAL(-8.71,m,1e-12);
523   m=f->getMinValue2(ws);
524   CPPUNIT_ASSERT_DOUBLES_EQUAL(-8.71,m,1e-12);
525   CPPUNIT_ASSERT_EQUAL(4,ws->getNumberOfTuples());
526   CPPUNIT_ASSERT_EQUAL(1,ws->getNumberOfComponents());
527   for(int i=0;i<4;i++)
528     CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
529   ws->decrRef();
530   //
531   f->decrRef();
532   m2->decrRef();
533 }
534
535 void MEDCouplingBasicsTest3::testBuildUnstructuredCMesh1()
536 {
537   MEDCouplingCMesh *m=MEDCouplingCMesh::New();
538   DataArrayDouble *da=DataArrayDouble::New();
539   const double discX[4]={2.3,3.4,5.8,10.2};
540   const double discY[3]={12.3,23.4,45.8};
541   const double discZ[5]={-0.7,1.2,1.25,2.13,2.67};
542   da->alloc(4,1);
543   std::copy(discX,discX+4,da->getPointer());
544   m->setCoordsAt(0,da);
545   da->decrRef();
546   m->checkCoherency();
547   double pos=2.4;
548   CPPUNIT_ASSERT_EQUAL(0,m->getCellContainingPoint(&pos,1e-12));
549   pos=3.7;
550   CPPUNIT_ASSERT_EQUAL(1,m->getCellContainingPoint(&pos,1e-12));
551   pos=5.9;
552   CPPUNIT_ASSERT_EQUAL(2,m->getCellContainingPoint(&pos,1e-12));
553   pos=10.3;
554   CPPUNIT_ASSERT_EQUAL(-1,m->getCellContainingPoint(&pos,1e-12));
555   pos=1.3;
556   CPPUNIT_ASSERT_EQUAL(-1,m->getCellContainingPoint(&pos,1e-12));
557   //
558   MEDCouplingUMesh *m2=m->buildUnstructured();
559   m2->checkCoherency();
560   MEDCouplingFieldDouble *f1=m->getMeasureField(false);
561   MEDCouplingFieldDouble *f2=m2->getMeasureField(false);
562   CPPUNIT_ASSERT_EQUAL(f1->getNumberOfTuples(),3);
563   CPPUNIT_ASSERT_EQUAL(f2->getNumberOfTuples(),3);
564   CPPUNIT_ASSERT_EQUAL(1,m2->getMeshDimension());
565   CPPUNIT_ASSERT_EQUAL(1,m2->getSpaceDimension());
566   for(int i=0;i<3;i++)
567     CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getIJ(i,0),f2->getIJ(i,0),1e-10);
568   da=DataArrayDouble::New();
569   da->alloc(3,1);
570   std::copy(discY,discY+3,da->getPointer());
571   m->setCoordsAt(1,da);
572   da->decrRef();
573   m2->decrRef();
574   f1->decrRef();
575   f2->decrRef();
576   //
577   m2=m->buildUnstructured();
578   m2->checkCoherency();
579   f1=m->getMeasureField(false);
580   f2=m2->getMeasureField(false);
581   CPPUNIT_ASSERT_EQUAL(f1->getNumberOfTuples(),6);
582   CPPUNIT_ASSERT_EQUAL(f2->getNumberOfTuples(),6);
583   CPPUNIT_ASSERT_EQUAL(2,m2->getMeshDimension());
584   CPPUNIT_ASSERT_EQUAL(2,m2->getSpaceDimension());
585   for(int i=0;i<6;i++)
586     CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getIJ(i,0),f2->getIJ(i,0),1e-10);
587   f1->decrRef();
588   f2->decrRef();
589   m2->decrRef();
590   //
591   da=DataArrayDouble::New();
592   da->alloc(5,1);
593   std::copy(discZ,discZ+5,da->getPointer());
594   m->setCoordsAt(2,da);
595   da->decrRef();
596   m2=m->buildUnstructured();
597   m2->checkCoherency();
598   f1=m->getMeasureField(false);
599   f2=m2->getMeasureField(false);
600   CPPUNIT_ASSERT_EQUAL(f1->getNumberOfTuples(),24);
601   CPPUNIT_ASSERT_EQUAL(f2->getNumberOfTuples(),24);
602   CPPUNIT_ASSERT_EQUAL(3,m2->getMeshDimension());
603   CPPUNIT_ASSERT_EQUAL(3,m2->getSpaceDimension());
604   for(int i=0;i<24;i++)
605     CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getIJ(i,0),f2->getIJ(i,0),1e-10);
606   f1->decrRef();
607   f2->decrRef();
608   //
609   double pos1[3]={5.,30.,2.};
610   CPPUNIT_ASSERT_EQUAL(16,m->getCellContainingPoint(pos1,1e-12));
611   //
612   const double pt[3]={2.4,12.7,-3.4};
613   m->scale(pt,3.7);
614   MEDCouplingUMesh *m3=m->buildUnstructured();
615   m2->scale(pt,3.7);
616   CPPUNIT_ASSERT(m3->isEqual(m2,1e-12));
617   m2->decrRef();
618   m3->decrRef();
619   //
620   m->decrRef();
621 }
622
623 void MEDCouplingBasicsTest3::testDataArrayIntInvertO2NNO21()
624 {
625   const int arr1[6]={2,0,4,1,5,3};
626   DataArrayInt *da=DataArrayInt::New();
627   da->alloc(6,1);
628   std::copy(arr1,arr1+6,da->getPointer());
629   DataArrayInt *da2=da->invertArrayO2N2N2O(6);
630   CPPUNIT_ASSERT_EQUAL(6,da2->getNumberOfTuples());
631   CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
632   const int expected1[6]={1,3,0,5,2,4};
633   for(int i=0;i<6;i++)
634     CPPUNIT_ASSERT_EQUAL(expected1[i],da2->getIJ(i,0));
635   DataArrayInt *da3=da2->invertArrayN2O2O2N(6);
636   for(int i=0;i<6;i++)
637     CPPUNIT_ASSERT_EQUAL(arr1[i],da3->getIJ(i,0));
638   da3->decrRef();
639   da2->decrRef();
640   da->decrRef();
641   //
642   const int arr2[10]={3,-1,5,4,-1,0,-1,1,2,-1};
643   da=DataArrayInt::New();
644   da->alloc(10,1);
645   std::copy(arr2,arr2+10,da->getPointer());
646   da2=da->invertArrayO2N2N2O(6);
647   CPPUNIT_ASSERT_EQUAL(6,da2->getNumberOfTuples());
648   CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
649   const int expected2[10]={5,7,8,0,3,2};
650   for(int i=0;i<6;i++)
651     CPPUNIT_ASSERT_EQUAL(expected2[i],da2->getIJ(i,0));
652   da3=da2->invertArrayN2O2O2N(10);
653   for(int i=0;i<10;i++)
654     CPPUNIT_ASSERT_EQUAL(arr2[i],da3->getIJ(i,0));
655   da3->decrRef();
656   da2->decrRef();
657   da->decrRef();
658 }
659
660 void MEDCouplingBasicsTest3::testKeepSetSelectedComponent1()
661 {
662   const double arr1[20]={1.,2.,3.,4., 11.,12.,13.,14., 21.,22.,23.,24., 31.,32.,33.,34., 41.,42.,43.,44.};
663   DataArrayDouble *a1=DataArrayDouble::New();
664   a1->alloc(5,4);
665   std::copy(arr1,arr1+20,a1->getPointer());
666   a1->setInfoOnComponent(0,"aaaa");
667   a1->setInfoOnComponent(1,"bbbb");
668   a1->setInfoOnComponent(2,"cccc");
669   a1->setInfoOnComponent(3,"dddd");
670   const int arr2[6]={1,2,1,2,0,0};
671   std::vector<int> arr2V(arr2,arr2+6);
672   DataArrayDouble *a2=a1->keepSelectedComponents(arr2V);
673   CPPUNIT_ASSERT_EQUAL(6,a2->getNumberOfComponents());
674   CPPUNIT_ASSERT_EQUAL(5,a2->getNumberOfTuples());
675   CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(0))=="bbbb");
676   CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(1))=="cccc");
677   CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(2))=="bbbb");
678   CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(3))=="cccc");
679   CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(4))=="aaaa");
680   CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(5))=="aaaa");
681   const double expected1[30]={2.,3.,2.,3.,1.,1., 12.,13.,12.,13.,11.,11., 22.,23.,22.,23.,21.,21., 32.,33.,32.,33.,31.,31., 42.,43.,42.,43.,41.,41.};
682   for(int i=0;i<30;i++)
683     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],a2->getIJ(0,i),1e-14);
684   DataArrayInt *a3=a1->convertToIntArr();
685   DataArrayInt *a4=a3->keepSelectedComponents(arr2V);
686   CPPUNIT_ASSERT_EQUAL(6,a4->getNumberOfComponents());
687   CPPUNIT_ASSERT_EQUAL(5,a4->getNumberOfTuples());
688   CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(0))=="bbbb");
689   CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(1))=="cccc");
690   CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(2))=="bbbb");
691   CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(3))=="cccc");
692   CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(4))=="aaaa");
693   CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(5))=="aaaa");
694   for(int i=0;i<30;i++)
695     CPPUNIT_ASSERT_EQUAL(int(expected1[i]),a4->getIJ(0,i));
696   // setSelectedComponents
697   const int arr3[2]={3,2};
698   std::vector<int> arr3V(arr3,arr3+2);
699   DataArrayDouble *a5=a1->keepSelectedComponents(arr3V);
700   a5->setInfoOnComponent(0,"eeee");
701   a5->setInfoOnComponent(1,"ffff");
702   const int arr4[2]={1,2};
703   std::vector<int> arr4V(arr4,arr4+2);
704   a2->setSelectedComponents(a5,arr4V);
705   CPPUNIT_ASSERT_EQUAL(6,a2->getNumberOfComponents());
706   CPPUNIT_ASSERT_EQUAL(5,a2->getNumberOfTuples());
707   CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(0))=="bbbb");
708   CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(1))=="eeee");
709   CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(2))=="ffff");
710   CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(3))=="cccc");
711   CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(4))=="aaaa");
712   CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(5))=="aaaa");
713   const double expected2[30]={2.,4.,3.,3.,1.,1., 12.,14.,13.,13.,11.,11., 22.,24.,23.,23.,21.,21., 32.,34.,33.,33.,31.,31., 42.,44.,43.,43.,41.,41.};
714   for(int i=0;i<30;i++)
715     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],a2->getIJ(0,i),1e-14);
716   DataArrayInt *a6=a5->convertToIntArr();
717   a6->setInfoOnComponent(0,"eeee");
718   a6->setInfoOnComponent(1,"ffff");
719   a4->setSelectedComponents(a6,arr4V);
720   CPPUNIT_ASSERT_EQUAL(6,a4->getNumberOfComponents());
721   CPPUNIT_ASSERT_EQUAL(5,a4->getNumberOfTuples());
722   CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(0))=="bbbb");
723   CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(1))=="eeee");
724   CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(2))=="ffff");
725   CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(3))=="cccc");
726   CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(4))=="aaaa");
727   CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(5))=="aaaa");
728   for(int i=0;i<30;i++)
729     CPPUNIT_ASSERT_EQUAL(int(expected2[i]),a4->getIJ(0,i));
730   // test of throw
731   const int arr5[3]={2,3,6};
732   const int arr6[3]={2,7,5};
733   const int arr7[4]={2,1,4,6};
734   std::vector<int> arr5V(arr5,arr5+3);
735   std::vector<int> arr6V(arr6,arr6+3);
736   std::vector<int> arr7V(arr7,arr7+4);
737   CPPUNIT_ASSERT_THROW(a2->keepSelectedComponents(arr5V),INTERP_KERNEL::Exception);
738   CPPUNIT_ASSERT_THROW(a2->keepSelectedComponents(arr6V),INTERP_KERNEL::Exception);
739   CPPUNIT_ASSERT_THROW(a2->setSelectedComponents(a1,arr7V),INTERP_KERNEL::Exception);
740   arr7V.resize(3);
741   CPPUNIT_ASSERT_THROW(a2->setSelectedComponents(a1,arr7V),INTERP_KERNEL::Exception);
742   //
743   a6->decrRef();
744   a5->decrRef();
745   a4->decrRef();
746   a3->decrRef();
747   a2->decrRef();
748   a1->decrRef();
749 }
750
751 void MEDCouplingBasicsTest3::testKeepSetSelectedComponent2()
752 {
753   MEDCouplingUMesh *m1=build2DTargetMesh_1();
754   const double arr1[20]={1.,2.,3.,4., 11.,12.,13.,14., 21.,22.,23.,24., 31.,32.,33.,34., 41.,42.,43.,44.};
755   DataArrayDouble *a1=DataArrayDouble::New();
756   a1->alloc(5,4);
757   std::copy(arr1,arr1+20,a1->getPointer());
758   a1->setInfoOnComponent(0,"aaaa");
759   a1->setInfoOnComponent(1,"bbbb");
760   a1->setInfoOnComponent(2,"cccc");
761   a1->setInfoOnComponent(3,"dddd");
762   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
763   f1->setTime(2.3,4,5);
764   f1->setMesh(m1);
765   f1->setName("f1");
766   f1->setArray(a1);
767   f1->checkCoherency();
768   //
769   const int arr2[6]={1,2,1,2,0,0};
770   std::vector<int> arr2V(arr2,arr2+6);
771   MEDCouplingFieldDouble *f2=f1->keepSelectedComponents(arr2V);
772   CPPUNIT_ASSERT(f2->getMesh()==f1->getMesh());
773   CPPUNIT_ASSERT(f2->getTimeDiscretization()==ONE_TIME);
774   int dt,it;
775   CPPUNIT_ASSERT_DOUBLES_EQUAL(2.3,f2->getTime(dt,it),1e-13);
776   CPPUNIT_ASSERT_EQUAL(4,dt);
777   CPPUNIT_ASSERT_EQUAL(5,it);
778   f2->checkCoherency();
779   CPPUNIT_ASSERT_EQUAL(6,f2->getNumberOfComponents());
780   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
781   CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(0))=="bbbb");
782   CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(1))=="cccc");
783   CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(2))=="bbbb");
784   CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(3))=="cccc");
785   CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(4))=="aaaa");
786   CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(5))=="aaaa");
787   const double expected1[30]={2.,3.,2.,3.,1.,1., 12.,13.,12.,13.,11.,11., 22.,23.,22.,23.,21.,21., 32.,33.,32.,33.,31.,31., 42.,43.,42.,43.,41.,41.};
788   for(int i=0;i<30;i++)
789     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f2->getIJ(0,i),1e-14);
790   //setSelectedComponents
791   const int arr3[2]={3,2};
792   std::vector<int> arr3V(arr3,arr3+2);
793   MEDCouplingFieldDouble *f5=f1->keepSelectedComponents(arr3V);
794   f5->setTime(6.7,8,9);
795   f5->getArray()->setInfoOnComponent(0,"eeee");
796   f5->getArray()->setInfoOnComponent(1,"ffff");
797   f5->checkCoherency();
798   const int arr4[2]={1,2};
799   std::vector<int> arr4V(arr4,arr4+2);
800   f2->setSelectedComponents(f5,arr4V);
801   CPPUNIT_ASSERT_EQUAL(6,f2->getNumberOfComponents());
802   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
803   f2->checkCoherency();
804   CPPUNIT_ASSERT_DOUBLES_EQUAL(2.3,f2->getTime(dt,it),1e-13);
805   CPPUNIT_ASSERT_EQUAL(4,dt);
806   CPPUNIT_ASSERT_EQUAL(5,it);
807   CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(0))=="bbbb");
808   CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(1))=="eeee");
809   CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(2))=="ffff");
810   CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(3))=="cccc");
811   CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(4))=="aaaa");
812   CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(5))=="aaaa");
813   const double expected2[30]={2.,4.,3.,3.,1.,1., 12.,14.,13.,13.,11.,11., 22.,24.,23.,23.,21.,21., 32.,34.,33.,33.,31.,31., 42.,44.,43.,43.,41.,41.};
814   for(int i=0;i<30;i++)
815     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f2->getIJ(0,i),1e-14);
816   f5->decrRef();
817   f1->decrRef();
818   f2->decrRef();
819   a1->decrRef();
820   m1->decrRef();
821 }
822
823 void MEDCouplingBasicsTest3::testElementaryDAThrowAndSpecialCases()
824 {
825   DataArrayInt *da=DataArrayInt::New();
826   CPPUNIT_ASSERT_THROW(da->checkAllocated(),INTERP_KERNEL::Exception);
827   CPPUNIT_ASSERT_THROW(da->fillWithValue(1),INTERP_KERNEL::Exception);
828   CPPUNIT_ASSERT_THROW(da->iota(1),INTERP_KERNEL::Exception);
829   da->alloc(7,1);
830   da->fillWithValue(11); //11,11,11,11...
831   da->iota(10); //10,11,12,13...
832   
833   DataArrayInt *db=DataArrayInt::New();
834   db->alloc(7,2);
835   
836   DataArrayDouble *dbl2=DataArrayDouble::New();
837   dbl2->alloc(7,2);
838   CPPUNIT_ASSERT_THROW(dbl2->isUniform(10.,1e-15),INTERP_KERNEL::Exception);
839   CPPUNIT_ASSERT_THROW(dbl2->sort(),INTERP_KERNEL::Exception);
840   CPPUNIT_ASSERT_THROW(dbl2->reverse(),INTERP_KERNEL::Exception);
841   CPPUNIT_ASSERT_THROW(dbl2->iota(10.),INTERP_KERNEL::Exception);
842   
843   DataArrayDouble *dbl=DataArrayDouble::New();
844   //DataArrayDouble not allocated yet
845   CPPUNIT_ASSERT_THROW(dbl->iota(10.),INTERP_KERNEL::Exception);
846   CPPUNIT_ASSERT_THROW(dbl->isUniform(10.,1e-15),INTERP_KERNEL::Exception);
847   CPPUNIT_ASSERT_THROW(dbl->sort(),INTERP_KERNEL::Exception);
848   CPPUNIT_ASSERT_THROW(dbl->reverse(),INTERP_KERNEL::Exception);
849   CPPUNIT_ASSERT_THROW(dbl->fromNoInterlace(),INTERP_KERNEL::Exception);
850   CPPUNIT_ASSERT_THROW(dbl->toNoInterlace(),INTERP_KERNEL::Exception);
851   
852   dbl->alloc(7,1);
853   dbl->iota(10.);
854   CPPUNIT_ASSERT(!dbl->isUniform(10.,1e-15));
855   dbl->sort();
856   CPPUNIT_ASSERT(dbl->isMonotonic(true, .99));
857   CPPUNIT_ASSERT(dbl->isMonotonic(true, -.99));
858   CPPUNIT_ASSERT(!dbl->isMonotonic(true, 1.1));
859   CPPUNIT_ASSERT(!dbl->isMonotonic(true, -1.1));
860   dbl->reverse();
861   CPPUNIT_ASSERT(dbl->isMonotonic(false, .99));
862   CPPUNIT_ASSERT(!dbl->isMonotonic(false, 1.1));
863   CPPUNIT_ASSERT(!dbl->isMonotonic(false, -1.1));
864   
865   DataArrayInt *dc=DataArrayInt::New();
866   dc->alloc(14,1);
867   
868   DataArrayDouble *dd=DataArrayDouble::New();
869   CPPUNIT_ASSERT_THROW(dd->checkAllocated(),INTERP_KERNEL::Exception);
870   CPPUNIT_ASSERT_THROW(dd->fillWithValue(1.),INTERP_KERNEL::Exception);
871   CPPUNIT_ASSERT_THROW(dd->iota(1.),INTERP_KERNEL::Exception);
872   CPPUNIT_ASSERT(!((dd->repr().find("No data"))==std::string::npos));
873   
874   dd->alloc(0,1); //Allocated but nbOfElements==0!
875   CPPUNIT_ASSERT(!((dd->repr().find("Number of tuples : 0"))==std::string::npos));
876   CPPUNIT_ASSERT(!((dd->repr().find("Empty Data"))==std::string::npos));
877   dd->fillWithValue(11); //?!...
878   dd->iota(10); //?!...
879   CPPUNIT_ASSERT(dd->isMonotonic(true, 1.));
880   CPPUNIT_ASSERT(dd->isMonotonic(false, 1.));
881  
882   CPPUNIT_ASSERT_THROW(db->copyStringInfoFrom(*da),INTERP_KERNEL::Exception);
883   CPPUNIT_ASSERT_THROW(db->copyStringInfoFrom(*da),INTERP_KERNEL::Exception);
884   std::vector<int> cIds(2,2);
885   CPPUNIT_ASSERT_THROW(da->copyPartOfStringInfoFrom(*db,cIds),INTERP_KERNEL::Exception);
886   cIds[0]=1;
887   cIds[0]=-1;
888   CPPUNIT_ASSERT_THROW(da->copyPartOfStringInfoFrom(*db,cIds),INTERP_KERNEL::Exception);
889   
890   std::vector<std::string> info(2,"infoOfOneComponent");
891   CPPUNIT_ASSERT_THROW(da->setInfoOnComponents(info),INTERP_KERNEL::Exception);
892   CPPUNIT_ASSERT_THROW(da->setInfoOnComponent(1,info[0].c_str()),INTERP_KERNEL::Exception);
893   db->setInfoOnComponents(info);
894   
895   CPPUNIT_ASSERT_THROW(da->getInfoOnComponent(-1),INTERP_KERNEL::Exception);
896   CPPUNIT_ASSERT_THROW(da->getInfoOnComponent(2),INTERP_KERNEL::Exception);
897   CPPUNIT_ASSERT(db->getInfoOnComponent(1)==db->getInfoOnComponent(0));
898   CPPUNIT_ASSERT_THROW(db->getVarOnComponent(-1),INTERP_KERNEL::Exception);
899   CPPUNIT_ASSERT_THROW(db->getVarOnComponent(2),INTERP_KERNEL::Exception);
900   CPPUNIT_ASSERT_THROW(db->getUnitOnComponent(-1),INTERP_KERNEL::Exception);
901   CPPUNIT_ASSERT_THROW(db->getUnitOnComponent(2),INTERP_KERNEL::Exception);
902   
903   CPPUNIT_ASSERT(da->GetVarNameFromInfo(std::string("varname unit "))==std::string("varname unit "));
904   CPPUNIT_ASSERT(da->GetVarNameFromInfo(std::string("varname]unit["))==std::string("varname]unit["));
905   CPPUNIT_ASSERT(da->GetVarNameFromInfo(std::string("[unit]"))==std::string());
906   CPPUNIT_ASSERT(da->GetVarNameFromInfo(std::string("varname [unit]"))==std::string("varname"));
907   
908   CPPUNIT_ASSERT(da->GetUnitFromInfo(std::string("varname unit "))==std::string());
909   CPPUNIT_ASSERT(da->GetUnitFromInfo(std::string("varname]unit["))==std::string());
910   CPPUNIT_ASSERT(da->GetUnitFromInfo(std::string("[unit]"))==std::string("unit"));
911   CPPUNIT_ASSERT(da->GetUnitFromInfo(std::string("varname [unit]"))==std::string("unit"));
912   
913   CPPUNIT_ASSERT_THROW(da->checkNbOfTuplesAndComp(*db,"theMessageInThrow"),INTERP_KERNEL::Exception);
914   CPPUNIT_ASSERT_THROW(da->checkNbOfTuplesAndComp(*dc,"theMessageInThrow"),INTERP_KERNEL::Exception);
915   CPPUNIT_ASSERT_THROW(db->checkNbOfTuplesAndComp(*dc,"theMessageInThrow"),INTERP_KERNEL::Exception);
916
917   CPPUNIT_ASSERT_THROW(da->checkNbOfTuplesAndComp(7,2,"theMessageInThrow"),INTERP_KERNEL::Exception);
918   da->checkNbOfTuplesAndComp(7,1,"theMessageInThrow");
919   
920   CPPUNIT_ASSERT_THROW(db->checkNbOfElems(7*2+1,"theMessageInThrow"),INTERP_KERNEL::Exception);
921   db->checkNbOfElems(7*2,"theMessageInThrow");
922   
923   CPPUNIT_ASSERT_THROW(db->GetNumberOfItemGivenBES(10,9,1,"theMessageInThrow"),INTERP_KERNEL::Exception);
924   CPPUNIT_ASSERT_THROW(db->GetNumberOfItemGivenBES(0,1,-1,"theMessageInThrow"),INTERP_KERNEL::Exception);
925   CPPUNIT_ASSERT_EQUAL(10,db->GetNumberOfItemGivenBES(0,10,1,"theMessageInThrow"));
926   CPPUNIT_ASSERT_EQUAL(5,db->GetNumberOfItemGivenBES(0,10,2,"theMessageInThrow"));
927   CPPUNIT_ASSERT_EQUAL(6,db->GetNumberOfItemGivenBES(0,11,2,"theMessageInThrow"));
928   
929   //std::cout<<"\n!!!!!!!!!\n"<<dd->repr()<<"\n!!!!!!!!!\n";
930   CPPUNIT_ASSERT(!((da->repr().find("Number of components : 1"))==std::string::npos));
931   CPPUNIT_ASSERT(!((dd->repr().find("Number of components : 1"))==std::string::npos));
932   CPPUNIT_ASSERT(!((dbl->repr().find("Number of components : 1"))==std::string::npos));
933   
934   CPPUNIT_ASSERT(!((da->reprZip().find("Number of components : 1"))==std::string::npos));
935   CPPUNIT_ASSERT(!((dd->reprZip().find("Number of components : 1"))==std::string::npos));
936   CPPUNIT_ASSERT(!((dbl->reprZip().find("Number of components : 1"))==std::string::npos));
937   
938   std::ostringstream ret;
939   dbl->writeVTK(ret,2,"file.tmp");
940   CPPUNIT_ASSERT(!((ret.str().find("<DataArray"))==std::string::npos));
941   CPPUNIT_ASSERT(!((ret.str().find("Float32"))==std::string::npos));
942   CPPUNIT_ASSERT(!((ret.str().find("16 15 14 13 12 11 10"))==std::string::npos));
943   
944   CPPUNIT_ASSERT_THROW(dbl->selectByTupleId2(0,1,-1),INTERP_KERNEL::Exception);
945   CPPUNIT_ASSERT_THROW(dbl->substr(-1,1),INTERP_KERNEL::Exception);
946   CPPUNIT_ASSERT_THROW(dbl->substr(8,1),INTERP_KERNEL::Exception);
947   CPPUNIT_ASSERT_THROW(dbl->substr(0,8),INTERP_KERNEL::Exception);
948   CPPUNIT_ASSERT_THROW(dbl->meldWith(dd),INTERP_KERNEL::Exception);
949   
950   CPPUNIT_ASSERT_THROW(dbl->setPartOfValuesAdv(dbl2,da),INTERP_KERNEL::Exception); //dbl dbl2 not have the same number of components
951   CPPUNIT_ASSERT_THROW(dbl->setPartOfValuesAdv(dd,da),INTERP_KERNEL::Exception);  //da tuple selector DataArrayInt instance not have exactly 2 components
952   
953   DataArrayDouble *dbl3=DataArrayDouble::New();
954   dbl3->alloc(6,2);
955   dbl3->fillWithValue(11.);
956   int tupleId;
957   //bad number of components
958   CPPUNIT_ASSERT_THROW(dbl3->getMaxValue(tupleId),INTERP_KERNEL::Exception);
959   CPPUNIT_ASSERT_THROW(dd->getMaxValue(tupleId),INTERP_KERNEL::Exception);
960   CPPUNIT_ASSERT_THROW(dbl3->getMinValue(tupleId),INTERP_KERNEL::Exception);
961   CPPUNIT_ASSERT_THROW(dd->getMinValue(tupleId),INTERP_KERNEL::Exception);
962   CPPUNIT_ASSERT_THROW(dbl3->getAverageValue(),INTERP_KERNEL::Exception);
963   CPPUNIT_ASSERT_THROW(dd->getAverageValue(),INTERP_KERNEL::Exception);
964   CPPUNIT_ASSERT_THROW(dd->accumulate(100),INTERP_KERNEL::Exception);
965   CPPUNIT_ASSERT_THROW(dbl->fromPolarToCart(),INTERP_KERNEL::Exception);
966   CPPUNIT_ASSERT_THROW(dbl3->fromCylToCart(),INTERP_KERNEL::Exception);
967   CPPUNIT_ASSERT_THROW(dbl3->fromSpherToCart(),INTERP_KERNEL::Exception);
968   CPPUNIT_ASSERT_THROW(dbl3->doublyContractedProduct(),INTERP_KERNEL::Exception);
969   CPPUNIT_ASSERT_THROW(dbl3->determinant(),INTERP_KERNEL::Exception);
970   CPPUNIT_ASSERT_THROW(dbl3->eigenValues(),INTERP_KERNEL::Exception);
971   CPPUNIT_ASSERT_THROW(dbl3->eigenVectors(),INTERP_KERNEL::Exception);
972   CPPUNIT_ASSERT_THROW(dbl3->inverse(),INTERP_KERNEL::Exception);
973   CPPUNIT_ASSERT_THROW(dbl3->trace(),INTERP_KERNEL::Exception);
974   CPPUNIT_ASSERT_THROW(dbl3->deviator(),INTERP_KERNEL::Exception);
975  
976   dbl3->setIJ(5,1,12.);
977   CPPUNIT_ASSERT(dbl3->getMaxValueInArray()==12.);
978   CPPUNIT_ASSERT(dbl3->getMinValueInArray()==11.);
979  
980   db->fillWithValue(100); //bad Ids
981   CPPUNIT_ASSERT_THROW(dbl3->setPartOfValuesAdv(dbl2,db),INTERP_KERNEL::Exception);
982   db->fillWithValue(-1); //bad Ids
983   CPPUNIT_ASSERT_THROW(dbl3->setPartOfValuesAdv(dbl2,db),INTERP_KERNEL::Exception);
984   db->fillWithValue(6); //bad Ids for dbl3
985   CPPUNIT_ASSERT_THROW(dbl3->setPartOfValuesAdv(dbl2,db),INTERP_KERNEL::Exception);
986   
987   DataArrayDouble::SetArrayIn(dbl,dbl3); //dbl->dbl3 memLeaks?
988   dbl3->checkNoNullValues();
989   dbl3->setIJ(6,0,0.);
990   CPPUNIT_ASSERT_THROW(dbl3->checkNoNullValues(),INTERP_KERNEL::Exception);
991   CPPUNIT_ASSERT_THROW(dbl3->applyInv(1.),INTERP_KERNEL::Exception);  //div by zero
992   CPPUNIT_ASSERT_THROW(dbl2->getIdsInRange(1.,2.),INTERP_KERNEL::Exception);
993   std::vector<const DataArrayDouble *> a(0); //input list must be NON EMPTY
994   CPPUNIT_ASSERT_THROW(DataArrayDouble::Aggregate(a),INTERP_KERNEL::Exception);
995   CPPUNIT_ASSERT_THROW(DataArrayDouble::Meld(a),INTERP_KERNEL::Exception);
996   
997   a.push_back(dbl2);
998   a.push_back(dbl); //Nb of components mismatch
999   CPPUNIT_ASSERT_THROW(DataArrayDouble::Aggregate(a),INTERP_KERNEL::Exception);
1000   
1001   CPPUNIT_ASSERT_THROW(DataArrayDouble::Dot(dbl2,dbl),INTERP_KERNEL::Exception);
1002   
1003   CPPUNIT_ASSERT_THROW(DataArrayDouble::CrossProduct(dbl2,dbl),INTERP_KERNEL::Exception); //Nb of components mismatch
1004   CPPUNIT_ASSERT_THROW(DataArrayDouble::CrossProduct(dbl2,dbl2),INTERP_KERNEL::Exception); //Nb of components must be equal to 3 
1005   DataArrayDouble *dbl4=DataArrayDouble::New();
1006   dbl4->alloc(6,3);
1007   DataArrayDouble *dbl5=DataArrayDouble::New();
1008   dbl5->alloc(7,3);
1009   CPPUNIT_ASSERT_THROW(DataArrayDouble::CrossProduct(dbl4,dbl5),INTERP_KERNEL::Exception); //Nb of tuples mismatch
1010   
1011   a[0]=dbl4; //Nb of tuple mismatch
1012   a[1]=dbl5; //Nb of tuple mismatch
1013   CPPUNIT_ASSERT_THROW(DataArrayDouble::Meld(a),INTERP_KERNEL::Exception);
1014   CPPUNIT_ASSERT_THROW(DataArrayDouble::Dot(dbl4,dbl5),INTERP_KERNEL::Exception);
1015   
1016   da->decrRef();
1017   db->decrRef();
1018   dbl->decrRef();
1019   dbl2->decrRef();
1020   dbl3->decrRef();
1021   dbl4->decrRef();
1022   dbl5->decrRef();
1023   dc->decrRef();
1024   dd->decrRef();
1025 }
1026
1027 void MEDCouplingBasicsTest3::testDAIGetIdsEqual1()
1028 {
1029   const int tab1[7]={5,-2,-4,-2,3,2,-2};
1030   DataArrayInt *da=DataArrayInt::New();
1031   da->alloc(7,1);
1032   std::copy(tab1,tab1+7,da->getPointer());
1033   DataArrayInt *da2=da->getIdsEqual(-2);
1034   CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfTuples());
1035   CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
1036   const int expected1[3]={1,3,6};
1037   CPPUNIT_ASSERT(std::equal(expected1,expected1+3,da2->getConstPointer()));
1038   da2->decrRef();
1039   da->decrRef();
1040 }
1041
1042 void MEDCouplingBasicsTest3::testDAIGetIdsEqualList1()
1043 {
1044   const int tab1[7]={5,-2,-4,-2,3,2,-2};
1045   DataArrayInt *da=DataArrayInt::New();
1046   da->alloc(7,1);
1047   std::copy(tab1,tab1+7,da->getPointer());
1048   const int tab2[3]={3,-2,0};
1049   std::vector<int> tab2V(tab2,tab2+3);
1050   DataArrayInt *da2=da->getIdsEqualList(&tab2V[0],&tab2V[0]+tab2V.size());
1051   CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfTuples());
1052   CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
1053   const int expected1[4]={1,3,4,6};
1054   CPPUNIT_ASSERT(std::equal(expected1,expected1+4,da2->getConstPointer()));
1055   da2->decrRef();
1056   da->decrRef();
1057 }
1058
1059 void MEDCouplingBasicsTest3::testDAFromNoInterlace1()
1060 {
1061   const int tab1[15]={1,11,21,31,41,2,12,22,32,42,3,13,23,33,43};
1062   DataArrayInt *da=DataArrayInt::New();
1063   da->alloc(5,3);
1064   std::copy(tab1,tab1+15,da->getPointer());
1065   DataArrayInt *da2=da->fromNoInterlace();
1066   const int expected1[15]={1,2,3,11,12,13,21,22,23,31,32,33,41,42,43};
1067   CPPUNIT_ASSERT_EQUAL(5,da2->getNumberOfTuples());
1068   CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
1069   CPPUNIT_ASSERT(std::equal(expected1,expected1+15,da2->getConstPointer()));
1070   DataArrayDouble *da3=da->convertToDblArr();
1071   DataArrayDouble *da4=da3->fromNoInterlace();
1072   CPPUNIT_ASSERT_EQUAL(5,da4->getNumberOfTuples());
1073   CPPUNIT_ASSERT_EQUAL(3,da4->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
1074   for(int i=0;i<15;i++)
1075     CPPUNIT_ASSERT_DOUBLES_EQUAL((double)expected1[i],da4->getIJ(0,i),1e-14);
1076   da4->decrRef();
1077   da3->decrRef();
1078   da2->decrRef();
1079   da->decrRef();
1080 }
1081
1082 void MEDCouplingBasicsTest3::testDAToNoInterlace1()
1083 {
1084   const int tab1[15]={1,2,3,11,12,13,21,22,23,31,32,33,41,42,43};
1085   DataArrayInt *da=DataArrayInt::New();
1086   da->alloc(5,3);
1087   std::copy(tab1,tab1+15,da->getPointer());
1088   DataArrayInt *da2=da->toNoInterlace();
1089   const int expected1[15]={1,11,21,31,41,2,12,22,32,42,3,13,23,33,43};
1090   CPPUNIT_ASSERT_EQUAL(5,da2->getNumberOfTuples());
1091   CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
1092   CPPUNIT_ASSERT(std::equal(expected1,expected1+15,da2->getConstPointer()));
1093   DataArrayDouble *da3=da->convertToDblArr();
1094   DataArrayDouble *da4=da3->toNoInterlace();
1095   CPPUNIT_ASSERT_EQUAL(5,da4->getNumberOfTuples());
1096   CPPUNIT_ASSERT_EQUAL(3,da4->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
1097   for(int i=0;i<15;i++)
1098     CPPUNIT_ASSERT_DOUBLES_EQUAL((double)expected1[i],da4->getIJ(0,i),1e-14);
1099   da4->decrRef();
1100   da3->decrRef();
1101   da2->decrRef();
1102   da->decrRef();
1103 }
1104
1105 void MEDCouplingBasicsTest3::testDAIsUniform1()
1106 {
1107   const int tab1[5]={1,1,1,1,1};
1108   DataArrayInt *da=DataArrayInt::New();
1109   da->alloc(5,1);
1110   std::copy(tab1,tab1+5,da->getPointer());
1111   CPPUNIT_ASSERT(da->isUniform(1));
1112   da->setIJ(2,0,2);
1113   CPPUNIT_ASSERT(!da->isUniform(1));
1114   da->setIJ(2,0,1);
1115   CPPUNIT_ASSERT(da->isUniform(1));
1116   DataArrayDouble *da2=da->convertToDblArr();
1117   CPPUNIT_ASSERT(da2->isUniform(1.,1e-12));
1118   da2->setIJ(1,0,1.+1.e-13);
1119   CPPUNIT_ASSERT(da2->isUniform(1.,1e-12));
1120   da2->setIJ(1,0,1.+1.e-11);
1121   CPPUNIT_ASSERT(!da2->isUniform(1.,1e-12));
1122   da2->decrRef();
1123   da->decrRef();
1124 }
1125
1126 void MEDCouplingBasicsTest3::testDADFromPolarToCart1()
1127 {
1128   const double tab1[4]={2.,0.2,2.5,0.7};
1129   DataArrayDouble *da=DataArrayDouble::New();
1130   da->alloc(2,2);
1131   std::copy(tab1,tab1+4,da->getPointer());
1132   DataArrayDouble *da2=da->fromPolarToCart();
1133   const double expected1[4]={1.9601331556824833,0.39733866159012243, 1.9121054682112213,1.6105442180942275};
1134   for(int i=0;i<4;i++)
1135     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da2->getIJ(0,i),1e-13);
1136   da2->decrRef();
1137   da->decrRef();
1138 }
1139
1140 void MEDCouplingBasicsTest3::testDADFromCylToCart1()
1141 {
1142   const double tab1[6]={2.,0.2,4.,2.5,0.7,9.};
1143   DataArrayDouble *da=DataArrayDouble::New();
1144   da->alloc(2,3);
1145   std::copy(tab1,tab1+6,da->getPointer());
1146   DataArrayDouble *da2=da->fromCylToCart();
1147   const double expected1[6]={1.9601331556824833,0.39733866159012243,4., 1.9121054682112213,1.6105442180942275,9.};
1148   for(int i=0;i<6;i++)
1149     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da2->getIJ(0,i),1e-13);
1150   da2->decrRef();
1151   da->decrRef();
1152 }
1153
1154 void MEDCouplingBasicsTest3::testDADFromSpherToCart1()
1155 {
1156   const double tab1[6]={2.,0.2,0.3,2.5,0.7,0.8};
1157   DataArrayDouble *da=DataArrayDouble::New();
1158   da->alloc(2,3);
1159   std::copy(tab1,tab1+6,da->getPointer());
1160   DataArrayDouble *da2=da->fromSpherToCart();
1161   const double expected1[6]={0.37959212195737485,0.11742160338765303,1.9601331556824833, 1.1220769624465328,1.1553337045129035,1.9121054682112213};
1162   for(int i=0;i<6;i++)
1163     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da2->getIJ(0,i),1e-13);
1164   da2->decrRef();
1165   da->decrRef();
1166 }
1167
1168 void MEDCouplingBasicsTest3::testUnPolyze1()
1169 {
1170   const int elts[8]={0,1,2,3,4,5,6,7};
1171   std::vector<int> eltsV(elts,elts+8);
1172   MEDCouplingUMesh *mesh=build3DTargetMesh_1();
1173   mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
1174   mesh->unPolyze();
1175   MEDCouplingUMesh *mesh2=build3DTargetMesh_1();
1176   mesh->checkCoherency();
1177   CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12));
1178   mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
1179   CPPUNIT_ASSERT(!mesh->isEqual(mesh2,1e-12));
1180   mesh->getNodalConnectivity()->setIJ(0,6,10);
1181   mesh->getNodalConnectivity()->setIJ(0,7,9);
1182   mesh->getNodalConnectivity()->setIJ(0,8,12);
1183   mesh->getNodalConnectivity()->setIJ(0,9,13);
1184   mesh->unPolyze();
1185   CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12));
1186   mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
1187   mesh->getNodalConnectivity()->setIJ(0,6,12);
1188   mesh->getNodalConnectivity()->setIJ(0,7,13);
1189   mesh->getNodalConnectivity()->setIJ(0,8,10);
1190   mesh->getNodalConnectivity()->setIJ(0,9,9);
1191   mesh->unPolyze();
1192   CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12));
1193   mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
1194   mesh->getNodalConnectivity()->setIJ(0,6,12);
1195   mesh->getNodalConnectivity()->setIJ(0,7,10);
1196   mesh->getNodalConnectivity()->setIJ(0,8,13);
1197   mesh->getNodalConnectivity()->setIJ(0,9,9);
1198   mesh->unPolyze();
1199   CPPUNIT_ASSERT(!mesh->isEqual(mesh2,1e-12));
1200   mesh->decrRef();
1201   mesh2->decrRef();
1202   // Test for 2D mesh
1203   mesh=build2DTargetMesh_1();
1204   mesh2=build2DTargetMesh_1();
1205   eltsV.resize(5);
1206   mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
1207   CPPUNIT_ASSERT(!mesh->isEqual(mesh2,1e-12));
1208   mesh->unPolyze();
1209   CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12));
1210   mesh->decrRef();
1211   mesh2->decrRef();
1212 }
1213
1214 void MEDCouplingBasicsTest3::testConvertDegeneratedCells1()
1215 {
1216   MEDCouplingUMesh *mesh=build3DTargetMesh_1();
1217   int conn[32]={0,1,3,3,9,10,12,12, 0,1,3,4,9,9,9,9, 1,1,1,1,10,12,9,10, 10,11,12,9,1,1,1,1};
1218   mesh->allocateCells(4);
1219   mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn);
1220   mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+8);
1221   mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+16);
1222   mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+24);
1223   mesh->finishInsertingCells();
1224   mesh->checkCoherency();
1225   CPPUNIT_ASSERT_EQUAL(4,mesh->getNumberOfCells());
1226   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh->getTypeOfCell(0));
1227   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh->getTypeOfCell(1));
1228   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh->getTypeOfCell(2));
1229   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh->getTypeOfCell(3));
1230   MEDCouplingFieldDouble *f1=mesh->getMeasureField(true);
1231   mesh->convertDegeneratedCells();
1232   mesh->checkCoherency();
1233   MEDCouplingFieldDouble *f2=mesh->getMeasureField(true);
1234   CPPUNIT_ASSERT_EQUAL(4,mesh->getNumberOfCells());
1235   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_PENTA6,mesh->getTypeOfCell(0));
1236   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_PYRA5,mesh->getTypeOfCell(1));
1237   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TETRA4,mesh->getTypeOfCell(2));
1238   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_PYRA5,mesh->getTypeOfCell(3));
1239   for(int i=0;i<4;i++)
1240     CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getArray()->getIJ(0,i),f2->getArray()->getIJ(0,i),1e-5);
1241   f1->decrRef();
1242   f2->decrRef();
1243   mesh->decrRef();
1244 }
1245
1246 void MEDCouplingBasicsTest3::testGetNodeIdsNearPoints1()
1247 {
1248   MEDCouplingUMesh *mesh=build2DTargetMesh_1();
1249   DataArrayDouble *coords=mesh->getCoords();
1250   DataArrayDouble *tmp=DataArrayDouble::New();
1251   tmp->alloc(3,2);
1252   const double vals[6]={0.2,0.2,0.1,0.2,0.2,0.2};
1253   std::copy(vals,vals+6,tmp->getPointer());
1254   DataArrayDouble *tmp2=DataArrayDouble::Aggregate(coords,tmp);
1255   tmp->decrRef();
1256   mesh->setCoords(tmp2);
1257   tmp2->decrRef();
1258   const double pts[6]={0.2,0.2,0.1,0.3,-0.3,0.7};
1259   DataArrayInt *c=mesh->getNodeIdsNearPoint(pts,1e-7);
1260   CPPUNIT_ASSERT_EQUAL(3,c->getNumberOfTuples());
1261   CPPUNIT_ASSERT_EQUAL(4,c->getIJ(0,0));
1262   CPPUNIT_ASSERT_EQUAL(9,c->getIJ(1,0));
1263   CPPUNIT_ASSERT_EQUAL(11,c->getIJ(2,0));
1264   c->decrRef();
1265   DataArrayInt *cI=0;
1266   mesh->getNodeIdsNearPoints(pts,3,1e-7,c,cI);
1267   CPPUNIT_ASSERT_EQUAL(4,cI->getNumberOfTuples());
1268   CPPUNIT_ASSERT_EQUAL(4,c->getNumberOfTuples());
1269   CPPUNIT_ASSERT_EQUAL(4,c->getIJ(0,0));
1270   CPPUNIT_ASSERT_EQUAL(9,c->getIJ(1,0));
1271   CPPUNIT_ASSERT_EQUAL(11,c->getIJ(2,0));
1272   CPPUNIT_ASSERT_EQUAL(6,c->getIJ(3,0));
1273   CPPUNIT_ASSERT_EQUAL(0,cI->getIJ(0,0));
1274   CPPUNIT_ASSERT_EQUAL(3,cI->getIJ(1,0));
1275   CPPUNIT_ASSERT_EQUAL(3,cI->getIJ(2,0));
1276   CPPUNIT_ASSERT_EQUAL(4,cI->getIJ(3,0));
1277   c->decrRef();
1278   cI->decrRef();
1279   mesh->decrRef();
1280 }
1281
1282 void MEDCouplingBasicsTest3::testFieldCopyTinyAttrFrom1()
1283 {
1284   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1285   f1->setName("f1");
1286   f1->setTimeTolerance(1.e-5);
1287   f1->setDescription("f1Desc");
1288   f1->setTime(1.23,4,5);
1289   MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1290   f2->setName("f2");
1291   f2->setDescription("f2Desc");
1292   f2->setTime(6.78,9,10);
1293   f2->setTimeTolerance(4.556e-12);
1294   //
1295   int dt,it;
1296   f1->copyTinyAttrFrom(f2);
1297   CPPUNIT_ASSERT_DOUBLES_EQUAL(4.556e-12,f1->getTimeTolerance(),1e-24);
1298   CPPUNIT_ASSERT_DOUBLES_EQUAL(6.78,f1->getTime(dt,it),1e-12);
1299   CPPUNIT_ASSERT_EQUAL(9,dt);
1300   CPPUNIT_ASSERT_EQUAL(10,it);
1301   CPPUNIT_ASSERT(std::string(f1->getName())=="f1");//name unchanged
1302   CPPUNIT_ASSERT(std::string(f1->getDescription())=="f1Desc");//description unchanged
1303   f1->decrRef();
1304   f2->decrRef();
1305   //
1306   f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1307   f1->setName("f1");
1308   f1->setTimeTolerance(1.e-5);
1309   f1->setDescription("f1Desc");
1310   f2=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1311   f2->setName("f2");
1312   f2->setDescription("f2Desc");
1313   f2->setTimeTolerance(4.556e-12);
1314   //
1315   f1->copyTinyAttrFrom(f2);
1316   CPPUNIT_ASSERT_DOUBLES_EQUAL(4.556e-12,f1->getTimeTolerance(),1e-24);
1317   CPPUNIT_ASSERT(std::string(f1->getName())=="f1");//name unchanged
1318   CPPUNIT_ASSERT(std::string(f1->getDescription())=="f1Desc");//description unchanged
1319   f1->decrRef();
1320   f2->decrRef();
1321   //
1322   f1=MEDCouplingFieldDouble::New(ON_CELLS,CONST_ON_TIME_INTERVAL);
1323   f1->setName("f1");
1324   f1->setTimeTolerance(1.e-5);
1325   f1->setDescription("f1Desc");
1326   f1->setTime(1.23,4,5);
1327   f1->setEndTime(5.43,2,1);
1328   f2=MEDCouplingFieldDouble::New(ON_CELLS,CONST_ON_TIME_INTERVAL);
1329   f2->setName("f2");
1330   f2->setDescription("f2Desc");
1331   f2->setTimeTolerance(4.556e-12);
1332   f2->setTime(6.78,9,10);
1333   f2->setEndTime(10.98,7,6);
1334   //
1335   f1->copyTinyAttrFrom(f2);
1336   CPPUNIT_ASSERT_DOUBLES_EQUAL(4.556e-12,f1->getTimeTolerance(),1e-24);
1337   CPPUNIT_ASSERT(std::string(f1->getName())=="f1");//name unchanged
1338   CPPUNIT_ASSERT(std::string(f1->getDescription())=="f1Desc");//description unchanged
1339   CPPUNIT_ASSERT_DOUBLES_EQUAL(6.78,f1->getTime(dt,it),1e-12);
1340   CPPUNIT_ASSERT_EQUAL(9,dt);
1341   CPPUNIT_ASSERT_EQUAL(10,it);
1342   CPPUNIT_ASSERT_DOUBLES_EQUAL(10.98,f1->getEndTime(dt,it),1e-12);
1343   CPPUNIT_ASSERT_EQUAL(7,dt);
1344   CPPUNIT_ASSERT_EQUAL(6,it);
1345   f1->decrRef();
1346   f2->decrRef();
1347   //
1348   f1=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
1349   f1->setName("f1");
1350   f1->setTimeTolerance(1.e-5);
1351   f1->setDescription("f1Desc");
1352   f1->setTime(1.23,4,5);
1353   f1->setEndTime(5.43,2,1);
1354   f2=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
1355   f2->setName("f2");
1356   f2->setDescription("f2Desc");
1357   f2->setTimeTolerance(4.556e-12);
1358   f2->setTime(6.78,9,10);
1359   f2->setEndTime(10.98,7,6);
1360   //
1361   f1->copyTinyAttrFrom(f2);
1362   CPPUNIT_ASSERT_DOUBLES_EQUAL(4.556e-12,f1->getTimeTolerance(),1e-24);
1363   CPPUNIT_ASSERT(std::string(f1->getName())=="f1");//name unchanged
1364   CPPUNIT_ASSERT(std::string(f1->getDescription())=="f1Desc");//description unchanged
1365   CPPUNIT_ASSERT_DOUBLES_EQUAL(6.78,f1->getTime(dt,it),1e-12);
1366   CPPUNIT_ASSERT_EQUAL(9,dt);
1367   CPPUNIT_ASSERT_EQUAL(10,it);
1368   CPPUNIT_ASSERT_DOUBLES_EQUAL(10.98,f1->getEndTime(dt,it),1e-12);
1369   CPPUNIT_ASSERT_EQUAL(7,dt);
1370   CPPUNIT_ASSERT_EQUAL(6,it);
1371   f1->decrRef();
1372   f2->decrRef();
1373 }
1374
1375 /*!
1376  * 1D -> 2D extrusion with rotation
1377  */
1378 void MEDCouplingBasicsTest3::testExtrudedMesh5()
1379 {
1380   const double coo1[4]={0.,1.,2.,3.5};
1381   DataArrayDouble *a=DataArrayDouble::New();
1382   a->alloc(4,1);
1383   std::copy(coo1,coo1+4,a->getPointer());
1384   MEDCouplingCMesh *b=MEDCouplingCMesh::New();
1385   b->setCoordsAt(0,a);
1386   MEDCouplingUMesh *c=b->buildUnstructured();
1387   CPPUNIT_ASSERT_EQUAL(1,c->getSpaceDimension());
1388   c->changeSpaceDimension(2);
1389   //
1390   DataArrayDouble *d=DataArrayDouble::New();
1391   d->alloc(13,1);
1392   d->iota();
1393   MEDCouplingCMesh *ee=MEDCouplingCMesh::New();
1394   ee->setCoordsAt(0,d);
1395   MEDCouplingUMesh *f=ee->buildUnstructured();
1396   DataArrayDouble *g=f->getCoords()->applyFunc(2,"3.5*IVec+x/6*3.14159265359*JVec");
1397   CPPUNIT_ASSERT_THROW(f->getCoords()->applyFunc(2,"3.5*IVec+x/6*3.14159265359*KVec"),INTERP_KERNEL::Exception); // KVec refers to component #2 and there is only 2 components !
1398   DataArrayDouble *h=g->fromPolarToCart();
1399   f->setCoords(h);
1400   MEDCouplingUMesh *i=c->buildExtrudedMesh(f,1);
1401   CPPUNIT_ASSERT_EQUAL(52,i->getNumberOfNodes());
1402   bool tmp2;
1403   int tmp3;
1404   DataArrayInt *tmp=i->mergeNodes(1e-9,tmp2,tmp3);
1405   CPPUNIT_ASSERT(tmp2);
1406   CPPUNIT_ASSERT_EQUAL(37,tmp3);
1407   tmp->decrRef();
1408   i->convertDegeneratedCells();
1409   i->checkCoherency();
1410   CPPUNIT_ASSERT_EQUAL(36,i->getNumberOfCells());
1411   CPPUNIT_ASSERT_EQUAL(37,i->getNumberOfNodes());
1412   CPPUNIT_ASSERT_EQUAL(12,i->getNumberOfCellsWithType(INTERP_KERNEL::NORM_TRI3));
1413   CPPUNIT_ASSERT_EQUAL(24,i->getNumberOfCellsWithType(INTERP_KERNEL::NORM_QUAD4));
1414   const double expected1[3]={0.25,0.75,2.0625};
1415   MEDCouplingFieldDouble *j=i->getMeasureField(true);
1416   for(int ii=0;ii<12;ii++)
1417     for(int k=0;k<3;k++)
1418       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[k],j->getIJ(0,ii*3+k),1e-10);
1419   const double expected2[72]={0.62200846792814113, 0.16666666666681595, 1.4513530918323276, 0.38888888888923495, 2.6293994326053212, 0.7045454545460802, 0.45534180126145435, 0.45534180126150181, 1.0624642029433926, 1.0624642029435025, 1.9248539780597826, 1.9248539780599816, 0.16666666666661334, 0.62200846792815856, 0.38888888888876294, 1.4513530918323678, 0.70454545454522521, 2.629399432605394, -0.16666666666674007, 0.62200846792812436, -0.38888888888906142, 1.4513530918322881, -0.70454545454576778, 2.6293994326052488, -0.45534180126154766, 0.45534180126140844, -1.0624642029436118, 1.0624642029432834, -1.9248539780601803, 1.9248539780595841, -0.62200846792817499, 0.1666666666665495, -1.451353091832408, 0.388888888888613, -2.6293994326054668, 0.70454545454495332, -0.62200846792810593, -0.16666666666680507, -1.451353091832247, -0.38888888888921297, -2.6293994326051746, -0.70454545454604123, -0.45534180126135926, -0.45534180126159562, -1.0624642029431723, -1.0624642029437235, -1.9248539780593836, -1.9248539780603811, -0.1666666666664828, -0.62200846792819242, -0.38888888888846079, -1.4513530918324489, -0.70454545454467987, -2.6293994326055397, 0.16666666666687083, -0.62200846792808862, 0.38888888888936374, -1.4513530918322073, 0.70454545454631357, -2.6293994326051022, 0.45534180126164348, -0.45534180126131207, 1.0624642029438327, -1.0624642029430627, 1.9248539780605791, -1.9248539780591853, 0.62200846792821063, -0.16666666666641802, 1.4513530918324888, -0.38888888888831086, 2.6293994326056125, -0.70454545454440853};
1420   DataArrayDouble *m=i->getBarycenterAndOwner();
1421   for(int ii=0;ii<72;ii++)
1422     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[ii],m->getIJ(0,ii),1e-10);
1423   //
1424   m->decrRef();
1425   j->decrRef();
1426   i->decrRef();
1427   h->decrRef();
1428   g->decrRef();
1429   f->decrRef();
1430   ee->decrRef();
1431   d->decrRef();
1432   c->decrRef();
1433   b->decrRef();
1434   a->decrRef();
1435 }
1436
1437 /*!
1438  * 1D -> 2D extrusion without rotation
1439  */
1440 void MEDCouplingBasicsTest3::testExtrudedMesh6()
1441 {
1442   const double coo1[4]={0.,1.,2.,3.5};
1443   DataArrayDouble *a=DataArrayDouble::New();
1444   a->alloc(4,1);
1445   std::copy(coo1,coo1+4,a->getPointer());
1446   MEDCouplingCMesh *b=MEDCouplingCMesh::New();
1447   b->setCoordsAt(0,a);
1448   MEDCouplingUMesh *c=b->buildUnstructured();
1449   CPPUNIT_ASSERT_EQUAL(1,c->getSpaceDimension());
1450   c->changeSpaceDimension(2);
1451   //
1452   DataArrayDouble *d=DataArrayDouble::New();
1453   d->alloc(5,1);
1454   d->iota();
1455   MEDCouplingCMesh *e=MEDCouplingCMesh::New();
1456   e->setCoordsAt(0,d);
1457   MEDCouplingUMesh *f=e->buildUnstructured();
1458   DataArrayDouble *d2=f->getCoords()->applyFunc("x*x/2");
1459   f->setCoords(d2);
1460   f->changeSpaceDimension(2);
1461   //
1462   const double center[2]={0.,0.};
1463   f->rotate(center,0,M_PI/3);
1464   MEDCouplingUMesh *g=c->buildExtrudedMesh(f,0);
1465   g->checkCoherency();
1466   const double expected1[]={ 0.4330127018922193, 0.4330127018922193, 0.649519052838329, 1.2990381056766578, 1.299038105676658, 1.948557158514987, 2.1650635094610955, 2.1650635094610964, 3.2475952641916446, 3.031088913245533, 3.0310889132455352, 4.546633369868303 };
1467   MEDCouplingFieldDouble *f1=g->getMeasureField(true);
1468   for(int i=0;i<12;i++)
1469     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-12);
1470   
1471   const double expected2[]={0.625, 0.21650635094610962, 1.625, 0.21650635094610959, 2.8750000000000004, 0.21650635094610965, 1.1250000000000002, 1.0825317547305482, 2.125, 1.0825317547305482, 3.3750000000000004, 1.0825317547305484, 2.125, 2.8145825622994254, 3.125, 2.8145825622994254, 4.375, 2.8145825622994254, 3.6250000000000009, 5.4126587736527414, 4.625, 5.4126587736527414, 5.875, 5.4126587736527414};
1472   DataArrayDouble *f2=g->getBarycenterAndOwner();
1473   for(int i=0;i<24;i++)
1474     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f2->getIJ(0,i),1e-12);
1475   //
1476   f1->decrRef();
1477   f2->decrRef();
1478   g->decrRef();
1479   f->decrRef();
1480   e->decrRef();
1481   d->decrRef();
1482   d2->decrRef();
1483   c->decrRef();
1484   b->decrRef();
1485   a->decrRef();
1486 }
1487
1488 /*!
1489  * 2D -> 3D extrusion with rotation
1490  */
1491 void MEDCouplingBasicsTest3::testExtrudedMesh7()
1492 {
1493   const double coo1[4]={0.,1.,2.,3.5};
1494   DataArrayDouble *a=DataArrayDouble::New();
1495   a->alloc(4,1);
1496   std::copy(coo1,coo1+4,a->getPointer());
1497   MEDCouplingCMesh *b=MEDCouplingCMesh::New();
1498   b->setCoordsAt(0,a);
1499   MEDCouplingUMesh *c=b->buildUnstructured();
1500   CPPUNIT_ASSERT_EQUAL(1,c->getSpaceDimension());
1501   c->changeSpaceDimension(2);
1502   //
1503   DataArrayDouble *d=DataArrayDouble::New();
1504   d->alloc(13,1);
1505   d->iota();
1506   MEDCouplingCMesh *e=MEDCouplingCMesh::New();
1507   e->setCoordsAt(0,d);
1508   MEDCouplingUMesh *f=e->buildUnstructured();
1509   DataArrayDouble *g=f->getCoords()->applyFunc(2,"3.5*IVec+x/6*3.14159265359*JVec");
1510   DataArrayDouble *h=g->fromPolarToCart();
1511   f->setCoords(h);
1512   MEDCouplingUMesh *i=c->buildExtrudedMesh(f,1);
1513   CPPUNIT_ASSERT_EQUAL(52,i->getNumberOfNodes());
1514   bool tmp2;
1515   int tmp3;
1516   DataArrayInt *tmp=i->mergeNodes(1e-9,tmp2,tmp3);
1517   CPPUNIT_ASSERT(tmp2);
1518   CPPUNIT_ASSERT_EQUAL(37,tmp3);
1519   tmp->decrRef();
1520   i->convertDegeneratedCells();
1521   const double vec1[3]={10.,0.,0.};
1522   i->translate(vec1);
1523   DataArrayDouble *g2=h->applyFunc(3,"13.5/3.5*x*IVec+0*JVec+13.5/3.5*y*KVec");
1524   f->setCoords(g2);
1525   i->changeSpaceDimension(3);
1526   MEDCouplingUMesh *i3=i->buildExtrudedMesh(f,1);
1527   MEDCouplingFieldDouble *f2=i3->getMeasureField(true);
1528   tmp=i->mergeNodes(1e-9,tmp2,tmp3);
1529   CPPUNIT_ASSERT(tmp2);
1530   CPPUNIT_ASSERT_EQUAL(444,tmp3);
1531   tmp->decrRef();
1532   const double expected1[36]={1.327751058489274, 4.2942574094314701, 13.024068164857139, 1.3069177251569044, 4.1484240761012954, 12.297505664866796, 1.270833333332571, 3.8958333333309674, 11.039062499993179, 1.2291666666659207, 3.6041666666644425, 9.585937499993932, 1.1930822748415895, 3.3515759238941376, 8.3274943351204556, 1.1722489415082769, 3.2057425905609289, 7.6009318351210622, 1.1722489415082862, 3.2057425905609884, 7.6009318351213713, 1.1930822748416161, 3.3515759238943001, 8.3274943351212727, 1.2291666666659564, 3.6041666666646734, 9.5859374999950777, 1.2708333333326081, 3.8958333333311868, 11.039062499994293, 1.3069177251569224, 4.1484240761014384, 12.297505664867627, 1.3277510584902354, 4.2942574094346071, 13.024068164866796};
1533   int kk=0;
1534   for(int ii=0;ii<12;ii++)
1535     for(int jj=0;jj<36;jj++,kk++)
1536       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[jj],f2->getIJ(0,kk),1e-9);
1537   //
1538   f2->decrRef();
1539   i3->decrRef();
1540   g2->decrRef();
1541   i->decrRef();
1542   h->decrRef();
1543   g->decrRef();
1544   f->decrRef();
1545   e->decrRef();
1546   d->decrRef();
1547   c->decrRef();
1548   b->decrRef();
1549   a->decrRef();
1550 }
1551
1552 void MEDCouplingBasicsTest3::testSimplexize1()
1553 {
1554   MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1555   std::vector<int> v(1);
1556   v[0]=3;
1557   m->convertToPolyTypes(&v[0],&v[0]+v.size());
1558   DataArrayInt *da=m->simplexize(0);
1559   CPPUNIT_ASSERT_EQUAL(7,da->getNumberOfTuples());
1560   CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfComponents());
1561   const int expected2[7]={0,0,1,2,3,4,4};
1562   for(int i=0;i<7;i++)
1563     CPPUNIT_ASSERT_EQUAL(expected2[i],da->getIJ(i,0));
1564   m->checkCoherency();
1565   CPPUNIT_ASSERT_EQUAL(7,m->getNumberOfCells());
1566   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(0));
1567   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(1));
1568   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(2));
1569   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(3));
1570   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYGON,m->getTypeOfCell(4));
1571   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(5));
1572   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(6));
1573   const double expected1[7]={0.125,0.125,0.125,0.125,0.25,0.125,0.125};
1574   MEDCouplingFieldDouble *f=m->getMeasureField(false);
1575   for(int i=0;i<7;i++)
1576     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i]*sqrt(2.),f->getIJ(i,0),1e-10);
1577   std::set<INTERP_KERNEL::NormalizedCellType> types=m->getAllTypes();
1578   CPPUNIT_ASSERT_EQUAL(2,(int)types.size());
1579   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*(types.begin()));
1580   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYGON,*(++(types.begin())));
1581   f->decrRef();
1582   da->decrRef();
1583   m->decrRef();
1584   //
1585   m=build3DSurfTargetMesh_1();
1586   v[0]=3;
1587   m->convertToPolyTypes(&v[0],&v[0]+v.size());
1588   da=m->simplexize(1);
1589   CPPUNIT_ASSERT_EQUAL(7,da->getNumberOfTuples());
1590   CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfComponents());
1591   for(int i=0;i<7;i++)
1592     CPPUNIT_ASSERT_EQUAL(expected2[i],da->getIJ(i,0));
1593   m->checkCoherency();
1594   types=m->getAllTypes();
1595   CPPUNIT_ASSERT_EQUAL(2,(int)types.size());
1596   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*(types.begin()));
1597   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYGON,*(++(types.begin())));
1598   CPPUNIT_ASSERT_EQUAL(7,m->getNumberOfCells());
1599   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(0));
1600   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(1));
1601   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(2));
1602   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(3));
1603   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYGON,m->getTypeOfCell(4));
1604   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(5));
1605   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(6));
1606   f=m->getMeasureField(false);
1607   for(int i=0;i<7;i++)
1608     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i]*sqrt(2.),f->getIJ(i,0),1e-10);
1609   f->decrRef();
1610   da->decrRef();
1611   m->decrRef();
1612 }
1613
1614 void MEDCouplingBasicsTest3::testSimplexize2()
1615 {
1616   MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1617   std::vector<int> v(1);
1618   v[0]=3;
1619   m->convertToPolyTypes(&v[0],&v[0]+v.size());
1620   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1621   f1->setMesh(m);
1622   DataArrayDouble *arr=DataArrayDouble::New();
1623   const double arr1[10]={10.,110.,20.,120.,30.,130.,40.,140.,50.,150.};
1624   arr->alloc(5,2);
1625   std::copy(arr1,arr1+10,arr->getPointer());
1626   f1->setArray(arr);
1627   arr->decrRef();
1628   //
1629   f1->checkCoherency();
1630   CPPUNIT_ASSERT(f1->simplexize(0));
1631   f1->checkCoherency();
1632   const double expected1[14]={10.,110.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.,50.,150.};
1633   for(int i=0;i<14;i++)
1634     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-10);
1635   CPPUNIT_ASSERT(!f1->simplexize(0));
1636   for(int i=0;i<14;i++)
1637     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-10);
1638   //
1639   f1->decrRef();
1640   m->decrRef();
1641 }
1642
1643 void MEDCouplingBasicsTest3::testDAMeld1()
1644 {
1645   DataArrayDouble *da1=DataArrayDouble::New();
1646   da1->alloc(7,2);
1647   DataArrayDouble *da2=DataArrayDouble::New();
1648   da2->alloc(7,1);
1649   //
1650   da1->fillWithValue(7.);
1651   da2->iota(0.);
1652   DataArrayDouble *da3=da2->applyFunc(3,"10*x*IVec+100*x*JVec+1000*x*KVec");
1653   //
1654   da1->setInfoOnComponent(0,"c0da1");
1655   da1->setInfoOnComponent(1,"c1da1");
1656   da3->setInfoOnComponent(0,"c0da3");
1657   da3->setInfoOnComponent(1,"c1da3");
1658   da3->setInfoOnComponent(2,"c2da3");
1659   //
1660   DataArrayDouble *da1C=da1->deepCpy();
1661   da1->meldWith(da3);
1662   CPPUNIT_ASSERT_EQUAL(5,da1->getNumberOfComponents());
1663   CPPUNIT_ASSERT_EQUAL(7,da1->getNumberOfTuples());
1664   CPPUNIT_ASSERT(da1->getInfoOnComponent(0)=="c0da1");
1665   CPPUNIT_ASSERT(da1->getInfoOnComponent(1)=="c1da1");
1666   CPPUNIT_ASSERT(da1->getInfoOnComponent(2)=="c0da3");
1667   CPPUNIT_ASSERT(da1->getInfoOnComponent(3)=="c1da3");
1668   CPPUNIT_ASSERT(da1->getInfoOnComponent(4)=="c2da3");
1669   //
1670   const double expected1[35]={7.,7.,0.,0.,0., 7.,7.,10.,100.,1000., 7.,7.,20.,200.,2000., 7.,7.,30.,300.,3000., 7.,7.,40.,400.,4000.,7.,7.,50.,500.,5000.,7.,7.,60.,600.,6000.};
1671   for(int i=0;i<35;i++)
1672     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da1->getIJ(0,i),1e-10);
1673   //
1674   DataArrayInt *dai1=da1C->convertToIntArr();
1675   DataArrayInt *dai3=da3->convertToIntArr();
1676   dai1->meldWith(dai3);
1677   CPPUNIT_ASSERT_EQUAL(5,dai1->getNumberOfComponents());
1678   CPPUNIT_ASSERT_EQUAL(7,dai1->getNumberOfTuples());
1679   CPPUNIT_ASSERT(dai1->getInfoOnComponent(0)=="c0da1");
1680   CPPUNIT_ASSERT(dai1->getInfoOnComponent(1)=="c1da1");
1681   CPPUNIT_ASSERT(dai1->getInfoOnComponent(2)=="c0da3");
1682   CPPUNIT_ASSERT(dai1->getInfoOnComponent(3)=="c1da3");
1683   CPPUNIT_ASSERT(dai1->getInfoOnComponent(4)=="c2da3");
1684   for(int i=0;i<35;i++)
1685     CPPUNIT_ASSERT_EQUAL((int)expected1[i],dai1->getIJ(0,i));
1686   // test of static method DataArrayDouble::meld
1687   DataArrayDouble *da4=DataArrayDouble::Meld(da1C,da3);
1688   CPPUNIT_ASSERT_EQUAL(5,da4->getNumberOfComponents());
1689   CPPUNIT_ASSERT_EQUAL(7,da4->getNumberOfTuples());
1690   CPPUNIT_ASSERT(da4->getInfoOnComponent(0)=="c0da1");
1691   CPPUNIT_ASSERT(da4->getInfoOnComponent(1)=="c1da1");
1692   CPPUNIT_ASSERT(da4->getInfoOnComponent(2)=="c0da3");
1693   CPPUNIT_ASSERT(da4->getInfoOnComponent(3)=="c1da3");
1694   CPPUNIT_ASSERT(da4->getInfoOnComponent(4)=="c2da3");
1695   for(int i=0;i<35;i++)
1696     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da4->getIJ(0,i),1e-10);
1697   // test of static method DataArrayInt::meld
1698   dai1->decrRef();
1699   dai1=da1C->convertToIntArr();
1700   DataArrayInt *dai4=DataArrayInt::Meld(dai1,dai3);
1701   CPPUNIT_ASSERT_EQUAL(5,dai4->getNumberOfComponents());
1702   CPPUNIT_ASSERT_EQUAL(7,dai4->getNumberOfTuples());
1703   CPPUNIT_ASSERT(dai4->getInfoOnComponent(0)=="c0da1");
1704   CPPUNIT_ASSERT(dai4->getInfoOnComponent(1)=="c1da1");
1705   CPPUNIT_ASSERT(dai4->getInfoOnComponent(2)=="c0da3");
1706   CPPUNIT_ASSERT(dai4->getInfoOnComponent(3)=="c1da3");
1707   CPPUNIT_ASSERT(dai4->getInfoOnComponent(4)=="c2da3");
1708   for(int i=0;i<35;i++)
1709     CPPUNIT_ASSERT_EQUAL((int)expected1[i],dai4->getIJ(0,i));
1710   //
1711   dai4->decrRef();
1712   da4->decrRef();
1713   dai3->decrRef();
1714   dai1->decrRef();
1715   da1C->decrRef();
1716   da1->decrRef();
1717   da2->decrRef();
1718   da3->decrRef();
1719 }
1720
1721 void MEDCouplingBasicsTest3::testFieldMeld1()
1722 {
1723   MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1724   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1725   f1->setMesh(m);
1726   DataArrayDouble *da1=DataArrayDouble::New();
1727   const double arr1[5]={12.,23.,34.,45.,56.};
1728   da1->alloc(5,1);
1729   std::copy(arr1,arr1+5,da1->getPointer());
1730   da1->setInfoOnComponent(0,"aaa");
1731   f1->setArray(da1);
1732   f1->setTime(3.4,2,1);
1733   f1->checkCoherency();
1734   //
1735   MEDCouplingFieldDouble *f2=f1->deepCpy();
1736   f2->setMesh(f1->getMesh());
1737   f2->checkCoherency();
1738   f2->changeNbOfComponents(2,5.);
1739   (*f2)=5.;
1740   f2->getArray()->setInfoOnComponent(0,"bbb");
1741   f2->getArray()->setInfoOnComponent(1,"ccc");
1742   f2->checkCoherency();
1743   //
1744   MEDCouplingFieldDouble *f3=MEDCouplingFieldDouble::MeldFields(f2,f1);
1745   f3->checkCoherency();
1746   CPPUNIT_ASSERT_EQUAL(5,f3->getNumberOfTuples());
1747   CPPUNIT_ASSERT_EQUAL(3,f3->getNumberOfComponents());
1748   CPPUNIT_ASSERT(f3->getArray()->getInfoOnComponent(0)=="bbb");
1749   CPPUNIT_ASSERT(f3->getArray()->getInfoOnComponent(1)=="ccc");
1750   CPPUNIT_ASSERT(f3->getArray()->getInfoOnComponent(2)=="aaa");
1751   const double expected1[15]={5.,5.,12.,5.,5.,23.,5.,5.,34.,5.,5.,45.,5.,5.,56.};
1752   for(int i=0;i<15;i++)
1753     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f3->getIJ(0,i),1e-12);
1754   int dt,it;
1755   double time=f3->getTime(dt,it);
1756   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.4,time,1e-14);
1757   CPPUNIT_ASSERT_EQUAL(2,dt);
1758   CPPUNIT_ASSERT_EQUAL(1,it);
1759   //
1760   MEDCouplingFieldDouble *f4=f2->buildNewTimeReprFromThis(NO_TIME,false);
1761   MEDCouplingFieldDouble *f5=f1->buildNewTimeReprFromThis(NO_TIME,false);
1762   MEDCouplingFieldDouble *f6=MEDCouplingFieldDouble::MeldFields(f4,f5);
1763   f6->checkCoherency();
1764   CPPUNIT_ASSERT_EQUAL(5,f6->getNumberOfTuples());
1765   CPPUNIT_ASSERT_EQUAL(3,f6->getNumberOfComponents());
1766   CPPUNIT_ASSERT(f6->getArray()->getInfoOnComponent(0)=="bbb");
1767   CPPUNIT_ASSERT(f6->getArray()->getInfoOnComponent(1)=="ccc");
1768   CPPUNIT_ASSERT(f6->getArray()->getInfoOnComponent(2)=="aaa");
1769   for(int i=0;i<15;i++)
1770     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f6->getIJ(0,i),1e-12);
1771   //
1772   f6->decrRef();
1773   f4->decrRef();
1774   f5->decrRef();
1775   f3->decrRef();
1776   da1->decrRef();
1777   f2->decrRef();
1778   f1->decrRef();
1779   m->decrRef();
1780 }
1781
1782 void MEDCouplingBasicsTest3::testMergeNodes2()
1783 {
1784   MEDCouplingUMesh *m1=build2DTargetMesh_1();
1785   MEDCouplingUMesh *m2=build2DTargetMesh_1();
1786   const double vec[2]={0.002,0.};
1787   m2->translate(vec);
1788   //
1789   std::vector<const MEDCouplingUMesh *> tmp(2);
1790   tmp[0]=m1;
1791   tmp[1]=m2;
1792   MEDCouplingUMesh *m3=MEDCouplingUMesh::MergeUMeshes(tmp);
1793   bool b;
1794   int newNbOfNodes;
1795   DataArrayInt *da=m3->mergeNodes2(0.01,b,newNbOfNodes);
1796   CPPUNIT_ASSERT_EQUAL(9,m3->getNumberOfNodes());
1797   const double expected1[18]={-0.299,-0.3, 0.201,-0.3, 0.701,-0.3, -0.299,0.2, 0.201,0.2, 0.701,0.2, -0.299,0.7, 0.201,0.7, 0.701,0.7};
1798   for(int i=0;i<18;i++)
1799     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],m3->getCoords()->getIJ(0,i),1e-13);
1800   //
1801   da->decrRef();
1802   m3->decrRef();
1803   m1->decrRef();
1804   m2->decrRef();
1805 }
1806
1807 void MEDCouplingBasicsTest3::testMergeField2()
1808 {
1809   MEDCouplingUMesh *m=build2DTargetMesh_1();
1810   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1811   f1->setMesh(m);
1812   DataArrayDouble *arr=DataArrayDouble::New();
1813   arr->alloc(5,2);
1814   arr->fillWithValue(2.);
1815   f1->setArray(arr);
1816   arr->decrRef();
1817   MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1818   f2->setMesh(m);
1819   arr=DataArrayDouble::New();
1820   arr->alloc(5,2);
1821   arr->fillWithValue(5.);
1822   f2->setArray(arr);
1823   arr->decrRef();
1824   MEDCouplingFieldDouble *f3=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1825   f3->setMesh(m);
1826   arr=DataArrayDouble::New();
1827   arr->alloc(5,2);
1828   arr->fillWithValue(7.);
1829   f3->setArray(arr);
1830   arr->decrRef();
1831   //
1832   std::vector<const MEDCouplingFieldDouble *> tmp(3);
1833   tmp[0]=f1; tmp[1]=f2; tmp[2]=f3;
1834   MEDCouplingFieldDouble *f4=MEDCouplingFieldDouble::MergeFields(tmp);
1835   CPPUNIT_ASSERT_EQUAL(15,f4->getMesh()->getNumberOfCells());
1836   const double expected1[30]={2.,2.,2.,2.,2.,2.,2.,2.,2.,2., 5.,5.,5.,5.,5.,5.,5.,5.,5.,5., 7.,7.,7.,7.,7.,7.,7.,7.,7.,7.};
1837   for(int i=0;i<30;i++)
1838     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f4->getIJ(0,i),1.e-13);
1839   //
1840   f4->decrRef();
1841   f1->decrRef();
1842   f2->decrRef();
1843   f3->decrRef();
1844   m->decrRef();
1845 }
1846
1847 void MEDCouplingBasicsTest3::testDAIBuildComplement1()
1848 {
1849   DataArrayInt *a=DataArrayInt::New();
1850   const int tab[4]={3,1,7,8};
1851   a->alloc(4,1);
1852   std::copy(tab,tab+4,a->getPointer());
1853   DataArrayInt *b=a->buildComplement(12);
1854   CPPUNIT_ASSERT_EQUAL(8,b->getNumberOfTuples());
1855   CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents());
1856   const int expected1[8]={0,2,4,5,6,9,10,11};
1857   for(int i=0;i<8;i++)
1858     CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
1859   b->decrRef();
1860   a->decrRef();
1861 }
1862
1863 void MEDCouplingBasicsTest3::testDAIBuildUnion1()
1864 {
1865   DataArrayInt *a=DataArrayInt::New();
1866   const int tab1[4]={3,1,7,8};
1867   a->alloc(4,1);
1868   std::copy(tab1,tab1+4,a->getPointer());
1869   DataArrayInt *c=DataArrayInt::New();
1870   const int tab2[5]={5,3,0,18,8};
1871   c->alloc(5,1);
1872   std::copy(tab2,tab2+5,c->getPointer());
1873   DataArrayInt *b=a->buildUnion(c);
1874   CPPUNIT_ASSERT_EQUAL(7,b->getNumberOfTuples());
1875   CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents());
1876   const int expected1[7]={0,1,3,5,7,8,18};
1877   for(int i=0;i<7;i++)
1878     CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
1879   c->decrRef();
1880   b->decrRef();
1881   a->decrRef();
1882 }
1883
1884 void MEDCouplingBasicsTest3::testDAIBuildIntersection1()
1885 {
1886   DataArrayInt *a=DataArrayInt::New();
1887   const int tab1[4]={3,1,7,8};
1888   a->alloc(4,1);
1889   std::copy(tab1,tab1+4,a->getPointer());
1890   DataArrayInt *c=DataArrayInt::New();
1891   const int tab2[5]={5,3,0,18,8};
1892   c->alloc(5,1);
1893   std::copy(tab2,tab2+5,c->getPointer());
1894   DataArrayInt *b=a->buildIntersection(c);
1895   CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfTuples());
1896   CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents());
1897   const int expected1[2]={3,8};
1898   for(int i=0;i<2;i++)
1899     CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
1900   c->decrRef();
1901   b->decrRef();
1902   a->decrRef();
1903 }
1904
1905 void MEDCouplingBasicsTest3::testDAIDeltaShiftIndex1()
1906 {
1907   DataArrayInt *a=DataArrayInt::New();
1908   const int tab[7]={1,3,6,7,7,9,15};
1909   a->alloc(7,1);
1910   std::copy(tab,tab+7,a->getPointer());
1911   DataArrayInt *b=a->deltaShiftIndex();
1912   CPPUNIT_ASSERT_EQUAL(6,b->getNumberOfTuples());
1913   CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents());
1914   const int expected1[6]={2,3,1,0,2,6};
1915   for(int i=0;i<6;i++)
1916     CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
1917   b->decrRef();
1918   a->decrRef();
1919 }
1920
1921 void MEDCouplingBasicsTest3::testDaDoubleSelectByTupleIdSafe1()
1922 {
1923   DataArrayDouble *a=DataArrayDouble::New();
1924   a->alloc(7,2);
1925   a->setInfoOnComponent(0,"toto");
1926   a->setInfoOnComponent(1,"tata");
1927   const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
1928   std::copy(arr1,arr1+14,a->getPointer());
1929   //
1930   const int arr2[7]={4,2,0,6,5};
1931   DataArrayDouble *b=a->selectByTupleIdSafe(arr2,arr2+5);
1932   CPPUNIT_ASSERT_EQUAL(5,b->getNumberOfTuples());
1933   CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
1934   CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
1935   CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
1936   const double expected1[10]={5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1};
1937   for(int i=0;i<10;i++)
1938     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
1939   const int arr4[5]={4,-1,0,6,5};
1940   CPPUNIT_ASSERT_THROW(a->selectByTupleIdSafe(arr4,arr4+5),INTERP_KERNEL::Exception);
1941   const int arr5[5]={4,2,0,6,7};
1942   CPPUNIT_ASSERT_THROW(a->selectByTupleIdSafe(arr5,arr5+5),INTERP_KERNEL::Exception);
1943   b->decrRef();
1944   a->decrRef();
1945   //
1946   DataArrayInt *c=DataArrayInt::New();
1947   c->alloc(7,2);
1948   c->setInfoOnComponent(0,"toto");
1949   c->setInfoOnComponent(1,"tata");
1950   const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
1951   std::copy(arr3,arr3+14,c->getPointer());
1952   DataArrayInt *d=c->selectByTupleIdSafe(arr2,arr2+5);
1953   CPPUNIT_ASSERT_EQUAL(5,d->getNumberOfTuples());
1954   CPPUNIT_ASSERT_EQUAL(2,d->getNumberOfComponents());
1955   CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
1956   CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
1957   const int expected2[10]={5,15,3,13,1,11,7,17,6,16};
1958   for(int i=0;i<10;i++)
1959     CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
1960   CPPUNIT_ASSERT_THROW(c->selectByTupleIdSafe(arr4,arr4+5),INTERP_KERNEL::Exception);
1961   CPPUNIT_ASSERT_THROW(c->selectByTupleIdSafe(arr5,arr5+5),INTERP_KERNEL::Exception);
1962   c->decrRef();
1963   d->decrRef();
1964 }
1965
1966 void MEDCouplingBasicsTest3::testAreCellsIncludedIn1()
1967 {
1968   MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1969   const int pt[2]={1,3};
1970   MEDCouplingUMesh *m2=(MEDCouplingUMesh *)m->buildPartOfMySelf(pt,pt+2,true);
1971   DataArrayInt *tmp;
1972   CPPUNIT_ASSERT(m->areCellsIncludedIn(m2,0,tmp));
1973   CPPUNIT_ASSERT_EQUAL(2,tmp->getNumberOfTuples());
1974   CPPUNIT_ASSERT_EQUAL(1,tmp->getNumberOfComponents());
1975   CPPUNIT_ASSERT_EQUAL(pt[0],tmp->getIJ(0,0));
1976   CPPUNIT_ASSERT_EQUAL(pt[1],tmp->getIJ(0,1));
1977   tmp->decrRef();
1978   CPPUNIT_ASSERT(!m2->areCellsIncludedIn(m,0,tmp));
1979   tmp->decrRef();
1980   m2->decrRef();
1981   m->decrRef();
1982 }
1983
1984 void MEDCouplingBasicsTest3::testDAIBuildSubstraction1()
1985 {
1986   DataArrayInt *a=DataArrayInt::New();
1987   const int aa[]={2,3,6,8,9};
1988   a->alloc(5,1);
1989   std::copy(aa,aa+5,a->getPointer());
1990   DataArrayInt *b=DataArrayInt::New();
1991   const int bb[]={1,3,5,9,11};
1992   b->alloc(5,1);
1993   std::copy(bb,bb+5,b->getPointer());
1994   //
1995   DataArrayInt *c=a->buildSubstraction(b);
1996   CPPUNIT_ASSERT_EQUAL(3,c->getNumberOfTuples());
1997   CPPUNIT_ASSERT_EQUAL(1,c->getNumberOfComponents());
1998   const int expected1[3]={2,6,8};
1999   CPPUNIT_ASSERT(std::equal(expected1,expected1+3,c->getConstPointer()));
2000   //
2001   c->decrRef();
2002   b->decrRef();
2003   a->decrRef();
2004 }
2005
2006 void MEDCouplingBasicsTest3::testBuildOrthogonalField2()
2007 {
2008   MEDCouplingUMesh *m=build2DTargetMesh_1();
2009   DataArrayInt *d1=DataArrayInt::New();
2010   DataArrayInt *d2=DataArrayInt::New();
2011   DataArrayInt *d3=DataArrayInt::New();
2012   DataArrayInt *d4=DataArrayInt::New();
2013   MEDCouplingUMesh *m1=m->buildDescendingConnectivity(d1,d2,d3,d4);
2014   //
2015   MEDCouplingFieldDouble *f1=m1->buildOrthogonalField();
2016   DataArrayDouble *da1=f1->getArray();
2017   CPPUNIT_ASSERT_EQUAL(2,da1->getNumberOfComponents());
2018   CPPUNIT_ASSERT_EQUAL(13,da1->getNumberOfTuples());
2019   //
2020   const double expected1[26]={-1.,0.,0.,1.,1.,0.,0.,-1.,0.707106781186548,0.707106781186548,0.,-1.,0.,1.,1.,0.,0.,1.,1.,0.,-1.,0.,0.,1.,1.,0.};
2021   for(int i=0;i<26;i++)
2022     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da1->getIJ(0,i),1e-14);
2023   //
2024   f1->decrRef();
2025   m1->decrRef();
2026   d1->decrRef();
2027   d2->decrRef();
2028   d3->decrRef();
2029   d4->decrRef();
2030   m->decrRef();
2031 }
2032
2033 void MEDCouplingBasicsTest3::testUMInsertNextCell1()
2034 {
2035   double targetCoords[18]={-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 };
2036   int targetConn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
2037   MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
2038   targetMesh->allocateCells(5);
2039   CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn),INTERP_KERNEL::Exception);
2040   targetMesh->setMeshDimension(2);
2041   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn);
2042   CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_TETRA4,4,targetConn),INTERP_KERNEL::Exception);
2043   CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,targetConn),INTERP_KERNEL::Exception);
2044   CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn),INTERP_KERNEL::Exception);
2045   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+4);
2046   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+7);
2047   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+10);
2048   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+14);
2049   targetMesh->finishInsertingCells();
2050   DataArrayDouble *myCoords=DataArrayDouble::New();
2051   myCoords->alloc(9,2);
2052   std::copy(targetCoords,targetCoords+18,myCoords->getPointer());
2053   targetMesh->setCoords(myCoords);
2054   myCoords->decrRef();
2055   targetMesh->checkCoherency();
2056   targetMesh->decrRef();
2057 }
2058
2059 void MEDCouplingBasicsTest3::testFieldOperatorDivDiffComp1()
2060 {
2061   MEDCouplingUMesh *m=build2DTargetMesh_1();
2062   DataArrayInt *d1=DataArrayInt::New();
2063   DataArrayInt *d2=DataArrayInt::New();
2064   DataArrayInt *d3=DataArrayInt::New();
2065   DataArrayInt *d4=DataArrayInt::New();
2066   MEDCouplingUMesh *m1=m->buildDescendingConnectivity(d1,d2,d3,d4);
2067   //
2068   MEDCouplingFieldDouble *f1=m1->buildOrthogonalField();
2069   const double arr1[13]={2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.};
2070   DataArrayDouble *arr=DataArrayDouble::New();
2071   arr->alloc(13,1);
2072   std::copy(arr1,arr1+13,arr->getPointer());
2073   MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS);
2074   f2->setArray(arr);
2075   f2->setMesh(m1);
2076   f2->checkCoherency();
2077   //
2078   MEDCouplingFieldDouble *f3=(*f1)/(*f2);
2079   CPPUNIT_ASSERT_THROW((*f2)/(*f1),INTERP_KERNEL::Exception);
2080   f3->checkCoherency();
2081   (*f1)/=(*f2);
2082   CPPUNIT_ASSERT(f1->isEqual(f3,1e-10,1e-10));
2083   CPPUNIT_ASSERT_THROW((*f2)/=(*f1),INTERP_KERNEL::Exception);
2084   const double expected1[26]={-0.5, 0.0, 0.0, 0.33333333333333331, 0.25, 0.0, 0.0, -0.20000000000000001, 0.117851130197758, 0.117851130197758, 0.0, -0.14285714285714285, 0.0, 0.125, 0.1111111111111111, 0.0, 0.0, 0.10000000000000001, 0.090909090909090912, 0.0, -0.083333333333333329, 0.0, 0.0, 0.076923076923076927, 0.071428571428571425, 0.0};
2085   for(int i=0;i<26;i++)
2086     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f3->getIJ(0,i),1e-10);
2087   //
2088   f3->decrRef();
2089   f2->decrRef();
2090   arr->decrRef();
2091   f1->decrRef();
2092   m1->decrRef();
2093   d1->decrRef();
2094   d2->decrRef();
2095   d3->decrRef();
2096   d4->decrRef();
2097   m->decrRef();
2098 }
2099
2100 void MEDCouplingBasicsTest3::testDARearrange1()
2101 {
2102   DataArrayInt *da1=DataArrayInt::New();
2103   da1->alloc(12,1);
2104   da1->iota(0);
2105   const int *ptr=da1->getConstPointer();
2106   //
2107   CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems());
2108   CPPUNIT_ASSERT_EQUAL(1,da1->getNumberOfComponents());
2109   CPPUNIT_ASSERT_EQUAL(12,da1->getNumberOfTuples());
2110   da1->rearrange(4);
2111   CPPUNIT_ASSERT(ptr==da1->getConstPointer());
2112   CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems());
2113   CPPUNIT_ASSERT_EQUAL(4,da1->getNumberOfComponents());
2114   CPPUNIT_ASSERT_EQUAL(3,da1->getNumberOfTuples());
2115   for(int i=0;i<12;i++)
2116     CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
2117   //
2118   da1->rearrange(6);
2119   CPPUNIT_ASSERT(ptr==da1->getConstPointer());
2120   CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems());
2121   CPPUNIT_ASSERT_EQUAL(6,da1->getNumberOfComponents());
2122   CPPUNIT_ASSERT_EQUAL(2,da1->getNumberOfTuples());
2123   for(int i=0;i<12;i++)
2124     CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
2125   //
2126   CPPUNIT_ASSERT_THROW(da1->rearrange(7),INTERP_KERNEL::Exception);
2127   //
2128   da1->rearrange(12);
2129   CPPUNIT_ASSERT(ptr==da1->getConstPointer());
2130   CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems());
2131   CPPUNIT_ASSERT_EQUAL(12,da1->getNumberOfComponents());
2132   CPPUNIT_ASSERT_EQUAL(1,da1->getNumberOfTuples());
2133   for(int i=0;i<12;i++)
2134     CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
2135   //
2136   da1->rearrange(3);
2137   CPPUNIT_ASSERT(ptr==da1->getConstPointer());
2138   CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems());
2139   CPPUNIT_ASSERT_EQUAL(3,da1->getNumberOfComponents());
2140   CPPUNIT_ASSERT_EQUAL(4,da1->getNumberOfTuples());
2141   for(int i=0;i<12;i++)
2142     CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
2143   //double
2144   DataArrayDouble *da2=da1->convertToDblArr();
2145   da1->decrRef();
2146   const double *ptr2=da2->getConstPointer();
2147   //
2148   CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems());
2149   CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfComponents());
2150   CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfTuples());
2151   da2->rearrange(4);
2152   CPPUNIT_ASSERT(ptr2==da2->getConstPointer());
2153   CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems());
2154   CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfComponents());
2155   CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfTuples());
2156   for(int i=0;i<12;i++)
2157     CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
2158   //
2159   da2->rearrange(6);
2160   CPPUNIT_ASSERT(ptr2==da2->getConstPointer());
2161   CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems());
2162   CPPUNIT_ASSERT_EQUAL(6,da2->getNumberOfComponents());
2163   CPPUNIT_ASSERT_EQUAL(2,da2->getNumberOfTuples());
2164   for(int i=0;i<12;i++)
2165     CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
2166   //
2167   CPPUNIT_ASSERT_THROW(da2->rearrange(7),INTERP_KERNEL::Exception);
2168   //
2169   da2->rearrange(1);
2170   CPPUNIT_ASSERT(ptr2==da2->getConstPointer());
2171   CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems());
2172   CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
2173   CPPUNIT_ASSERT_EQUAL(12,da2->getNumberOfTuples());
2174   for(int i=0;i<12;i++)
2175     CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
2176   //
2177   da2->rearrange(3);
2178   CPPUNIT_ASSERT(ptr2==da2->getConstPointer());
2179   CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems());
2180   CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfComponents());
2181   CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfTuples());
2182   for(int i=0;i<12;i++)
2183     CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
2184   da2->decrRef();
2185 }
2186
2187 void MEDCouplingBasicsTest3::testGetDifferentValues1()
2188 {
2189   DataArrayInt *da1=DataArrayInt::New();
2190   const int arr[12]={1,2,3,2,2,3,5,1,5,5,2,2};
2191   da1->alloc(4,3);
2192   std::copy(arr,arr+12,da1->getPointer());
2193   DataArrayInt *s=da1->getDifferentValues();
2194   const int expected1[4]={1,2,3,5};
2195   CPPUNIT_ASSERT_EQUAL(4,s->getNumberOfTuples());
2196   CPPUNIT_ASSERT(std::equal(expected1,expected1+4,s->begin()));
2197   da1->decrRef();
2198   s->decrRef();
2199 }
2200
2201 void MEDCouplingBasicsTest3::testDAIBuildPermutationArr1()
2202 {
2203   DataArrayInt *a=DataArrayInt::New();
2204   const int vala[5]={4,5,6,7,8};
2205   a->alloc(5,1);
2206   std::copy(vala,vala+5,a->getPointer());
2207   DataArrayInt *b=DataArrayInt::New();
2208   const int valb[5]={5,4,8,6,7};
2209   b->alloc(5,1);
2210   std::copy(valb,valb+5,b->getPointer());
2211   DataArrayInt *c=a->buildPermutationArr(*b);
2212   const int expect1[5]={1,0,4,2,3};
2213   CPPUNIT_ASSERT_EQUAL(5,c->getNumberOfTuples());
2214   CPPUNIT_ASSERT_EQUAL(1,c->getNumberOfComponents());
2215   CPPUNIT_ASSERT(std::equal(expect1,expect1+5,c->getConstPointer()));
2216   CPPUNIT_ASSERT(a->isEqualWithoutConsideringStrAndOrder(*b));
2217   b->setIJ(0,0,9);
2218   CPPUNIT_ASSERT(!a->isEqualWithoutConsideringStrAndOrder(*b));
2219   CPPUNIT_ASSERT_THROW(a->buildPermutationArr(*b),INTERP_KERNEL::Exception);
2220   a->setIJ(3,0,4);
2221   b->setIJ(0,0,5);
2222   b->setIJ(4,0,4);//;a==[4,5,6,4,8] and b==[5,4,8,6,4]
2223   CPPUNIT_ASSERT(a->isEqualWithoutConsideringStrAndOrder(*b));
2224   c->decrRef();
2225   c=a->buildPermutationArr(*b);
2226   const int expect2[5]={1,3,4,2,3};
2227   CPPUNIT_ASSERT(std::equal(expect2,expect2+5,c->getConstPointer()));
2228   DataArrayDouble *d=b->convertToDblArr();
2229   b->sort();
2230   const int expect3[5]={4,4,5,6,8};
2231   CPPUNIT_ASSERT(std::equal(expect3,expect3+5,b->getConstPointer()));
2232   d->sort();
2233   CPPUNIT_ASSERT_EQUAL(5,d->getNumberOfTuples());
2234   CPPUNIT_ASSERT_EQUAL(1,d->getNumberOfComponents());
2235   for(int i=0;i<5;i++)
2236     CPPUNIT_ASSERT_DOUBLES_EQUAL(double(expect3[i]),d->getIJ(i,0),1e-14);
2237   //
2238   d->decrRef();
2239   c->decrRef();
2240   a->decrRef();
2241   b->decrRef();
2242 }
2243
2244 void MEDCouplingBasicsTest3::testAreCellsIncludedIn2()
2245 {
2246   const char myName[]="Vitoo";
2247   MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
2248   MEDCouplingUMesh *m2=(MEDCouplingUMesh *)m->buildPartOfMySelf(0,0,true);
2249   CPPUNIT_ASSERT_EQUAL(0,m2->getNumberOfCells());
2250   CPPUNIT_ASSERT_EQUAL(3,m2->getSpaceDimension());
2251   CPPUNIT_ASSERT_EQUAL(2,m2->getMeshDimension());
2252   m2->setName(myName);
2253   DataArrayInt *tmp;
2254   CPPUNIT_ASSERT(m->areCellsIncludedIn(m2,0,tmp));
2255   CPPUNIT_ASSERT(std::string(myName)==tmp->getName());
2256   CPPUNIT_ASSERT_EQUAL(0,tmp->getNumberOfTuples());
2257   CPPUNIT_ASSERT_EQUAL(1,tmp->getNumberOfComponents());
2258   m->decrRef();
2259   m2->decrRef();
2260   tmp->decrRef();
2261 }
2262
2263 void MEDCouplingBasicsTest3::testUMeshGetPartBarycenterAndOwner1()
2264 {
2265   MEDCouplingUMesh *m1=build2DTargetMesh_1();
2266   const int part[3]={1,0,4};
2267   DataArrayDouble *b=m1->getPartBarycenterAndOwner(part,part+3);
2268   CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
2269   CPPUNIT_ASSERT_EQUAL(3,b->getNumberOfTuples());
2270   const double expected1[6]={0.36666666666666665,-0.13333333333333333,-0.05,-0.05,0.45,0.45};
2271   for(int i=0;i<6;i++)
2272     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
2273   b->decrRef();
2274   m1->decrRef();
2275 }
2276
2277 void MEDCouplingBasicsTest3::testUMeshGetPartMeasureField1()
2278 {
2279   MEDCouplingUMesh *m1=build2DTargetMesh_1();
2280   const int part[3]={1,0,4};
2281   DataArrayDouble *b=m1->getPartMeasureField(true,part,part+3);
2282   CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents());
2283   CPPUNIT_ASSERT_EQUAL(3,b->getNumberOfTuples());
2284   const double expected1[3]={0.125,0.25,0.25};
2285   for(int i=0;i<3;i++)
2286     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
2287   b->decrRef();
2288   m1->decrRef();
2289 }
2290
2291 void MEDCouplingBasicsTest3::testUMeshBuildPartOrthogonalField1()
2292 {
2293   MEDCouplingUMesh *m1=build2DTargetMesh_1();
2294   m1->changeSpaceDimension(3);
2295   const int part[3]={1,0,4};
2296   MEDCouplingFieldDouble *b=m1->buildPartOrthogonalField(part,part+3);
2297   CPPUNIT_ASSERT_EQUAL(3,b->getArray()->getNumberOfComponents());
2298   CPPUNIT_ASSERT_EQUAL(3,b->getArray()->getNumberOfTuples());
2299   const double expected1[9]={0.,0.,-1.,0.,0.,-1.,0.,0.,-1.};
2300   for(int i=0;i<9;i++)
2301     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getArray()->getIJ(0,i),1e-14);
2302   b->decrRef();
2303   m1->decrRef();
2304 }
2305
2306 void MEDCouplingBasicsTest3::testUMeshGetTypesOfPart1()
2307 {
2308   MEDCouplingUMesh *m1=build2DTargetMesh_1();
2309   const int part1[]={0,3,4};
2310   std::set<INTERP_KERNEL::NormalizedCellType> s;
2311   s=m1->getTypesOfPart(part1,part1+3);
2312   CPPUNIT_ASSERT(s.size()==1);
2313   CPPUNIT_ASSERT(*s.begin()==INTERP_KERNEL::NORM_QUAD4);
2314   const int part2[]={2,2,2,1};
2315   s=m1->getTypesOfPart(part2,part2+4);
2316   CPPUNIT_ASSERT(s.size()==1);
2317   CPPUNIT_ASSERT(*s.begin()==INTERP_KERNEL::NORM_TRI3);
2318   const int part3[]={3,2,1};
2319   s=m1->getTypesOfPart(part3,part3+3);
2320   CPPUNIT_ASSERT(s.size()==2);
2321   CPPUNIT_ASSERT(*s.begin()==INTERP_KERNEL::NORM_TRI3);
2322   CPPUNIT_ASSERT(*(++s.begin())==INTERP_KERNEL::NORM_QUAD4);
2323   m1->decrRef();
2324 }
2325
2326 void MEDCouplingBasicsTest3::testUMeshKeepCellIdsByType1()
2327 {
2328   MEDCouplingUMesh *m1=build2DTargetMesh_1();
2329   const int part1[3]={0,3,4};
2330   DataArrayInt *a=m1->keepCellIdsByType(INTERP_KERNEL::NORM_TRI3,part1,part1+3);
2331   CPPUNIT_ASSERT_EQUAL(1,a->getNumberOfComponents());
2332   CPPUNIT_ASSERT_EQUAL(0,a->getNumberOfTuples());
2333   a->decrRef();
2334   //
2335   const int part2[5]={3,2,0,2,4};
2336   a=m1->keepCellIdsByType(INTERP_KERNEL::NORM_TRI3,part2,part2+5);
2337   CPPUNIT_ASSERT_EQUAL(1,a->getNumberOfComponents());
2338   CPPUNIT_ASSERT_EQUAL(2,a->getNumberOfTuples());
2339   CPPUNIT_ASSERT_EQUAL(2,a->getIJ(0,0));
2340   CPPUNIT_ASSERT_EQUAL(2,a->getIJ(1,0));
2341   a->decrRef();
2342   //
2343   a=m1->keepCellIdsByType(INTERP_KERNEL::NORM_QUAD4,part2,part2+5);
2344   CPPUNIT_ASSERT_EQUAL(1,a->getNumberOfComponents());
2345   CPPUNIT_ASSERT_EQUAL(3,a->getNumberOfTuples());
2346   CPPUNIT_ASSERT_EQUAL(3,a->getIJ(0,0));
2347   CPPUNIT_ASSERT_EQUAL(0,a->getIJ(1,0));
2348   CPPUNIT_ASSERT_EQUAL(4,a->getIJ(2,0));
2349   //
2350   a->decrRef();
2351   m1->decrRef();
2352 }
2353
2354 void MEDCouplingBasicsTest3::testDAIAggregateMulti1()
2355 {
2356   DataArrayInt *a=DataArrayInt::New();
2357   a->setName("aa");
2358   a->alloc(4,1);
2359   a->iota(0);
2360   a->rearrange(2);
2361   DataArrayInt *b=DataArrayInt::New();
2362   b->setName("bb");
2363   b->alloc(6,1);
2364   b->iota(0);
2365   b->rearrange(2);
2366   //
2367   std::vector<const DataArrayInt *> v(2);
2368   v[0]=a; v[1]=b;
2369   DataArrayInt *c=DataArrayInt::Aggregate(v);
2370   CPPUNIT_ASSERT_EQUAL(5,c->getNumberOfTuples());
2371   CPPUNIT_ASSERT_EQUAL(2,c->getNumberOfComponents());
2372   CPPUNIT_ASSERT(c->getName()=="aa");
2373   const int expect1[10]={0,1,2,3,0,1,2,3,4,5};
2374   for(int i=0;i<10;i++)
2375     CPPUNIT_ASSERT_EQUAL(expect1[i],c->getIJ(0,i));
2376   //
2377   c->decrRef();
2378   a->decrRef();
2379   b->decrRef();
2380 }
2381
2382 void MEDCouplingBasicsTest3::testMergeUMeshes2()
2383 {
2384   MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
2385   MEDCouplingUMesh *m2=build3DSurfTargetMesh_1();
2386   MEDCouplingUMesh *m3=build3DSurfTargetMesh_1();
2387   //
2388   const int vec1[3]={0,2,3};
2389   MEDCouplingUMesh *m2_2=(MEDCouplingUMesh *)m2->buildPartOfMySelf(vec1,vec1+3,false);
2390   const int vec2[2]={1,1};
2391   MEDCouplingUMesh *m3_2=(MEDCouplingUMesh *)m3->buildPartOfMySelf(vec2,vec2+2,false);
2392   //
2393   std::vector<const MEDCouplingUMesh *> ms(3);
2394   std::vector<const MEDCouplingMesh *> ms2(3);
2395   ms[0]=m1; ms[1]=m2_2; ms[2]=m3_2;
2396   ms2[0]=m1; ms2[1]=m2_2; ms2[2]=m3_2;
2397   //
2398   MEDCouplingUMesh *m4=MEDCouplingUMesh::MergeUMeshes(ms);
2399   m4->checkCoherency();
2400   CPPUNIT_ASSERT_EQUAL(10,m4->getNumberOfCells());
2401   CPPUNIT_ASSERT_EQUAL(20,m4->getNumberOfNodes());
2402   CPPUNIT_ASSERT_EQUAL(45,m4->getMeshLength());
2403   //
2404   MEDCouplingMesh *m4bis=MEDCouplingMesh::MergeMeshes(ms2);
2405   CPPUNIT_ASSERT(m4->isEqual(m4bis,1e-12));
2406   m4bis->decrRef();
2407   //
2408   const int vec3[5]={0,1,2,3,4};
2409   MEDCouplingUMesh *m4_1=(MEDCouplingUMesh *)m4->buildPartOfMySelf(vec3,vec3+5,false);
2410   m4_1->setName(m1->getName());
2411   CPPUNIT_ASSERT(m4_1->isEqual(m1,1e-12));
2412   m4_1->decrRef();
2413   //
2414   const int vec4[3]={5,6,7};
2415   MEDCouplingUMesh *m4_2=(MEDCouplingUMesh *)m4->buildPartOfMySelf(vec4,vec4+3,false);
2416   DataArrayInt *cellCor=0;
2417   DataArrayInt *nodeCor=0;
2418   m4_2->checkGeoEquivalWith(m2_2,10,1e-12,cellCor,nodeCor);
2419   CPPUNIT_ASSERT(cellCor==0);
2420   CPPUNIT_ASSERT(nodeCor==0);
2421   m4_2->decrRef();
2422   //
2423   const int vec5[2]={8,9};
2424   MEDCouplingUMesh *m4_3=(MEDCouplingUMesh *)m4->buildPartOfMySelf(vec5,vec5+2,false);
2425   CPPUNIT_ASSERT_EQUAL(2,m4_3->getNumberOfCells());
2426   CPPUNIT_ASSERT_EQUAL(3,m4_3->getNumberOfNodes());
2427   m3_2->zipCoords();
2428   m4_3->setName(m3_2->getName());
2429   CPPUNIT_ASSERT(m4_3->isEqual(m3_2,1e-12));
2430   m4_3->decrRef();
2431   //
2432   m4->decrRef();
2433   m1->decrRef();
2434   m2->decrRef();
2435   m2_2->decrRef();
2436   m3->decrRef();
2437   m3_2->decrRef();
2438 }
2439
2440 void MEDCouplingBasicsTest3::testBuild0DMeshFromCoords1()
2441 {
2442   const double sourceCoords[12]={-0.3,-0.3,0., 0.7,-0.3,0., -0.3,0.7,0., 0.7,0.7,0.};
2443   DataArrayDouble *coo=DataArrayDouble::New();
2444   coo->alloc(4,3);
2445   coo->setName("My0D");
2446   std::copy(sourceCoords,sourceCoords+12,coo->getPointer());
2447   MEDCouplingUMesh *m=MEDCouplingUMesh::Build0DMeshFromCoords(coo);
2448   m->checkCoherency();
2449   CPPUNIT_ASSERT_EQUAL(4,m->getNumberOfNodes());
2450   CPPUNIT_ASSERT_EQUAL(4,m->getNumberOfCells());
2451   CPPUNIT_ASSERT_EQUAL(3,m->getSpaceDimension());
2452   CPPUNIT_ASSERT_EQUAL(0,m->getMeshDimension());
2453   const std::set<INTERP_KERNEL::NormalizedCellType>& types=m->getAllTypes();
2454   CPPUNIT_ASSERT_EQUAL(1,(int)types.size());
2455   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POINT1,*types.begin());
2456   for(int i=0;i<4;i++)
2457     {
2458       std::vector<int> conn;
2459       m->getNodeIdsOfCell(i,conn);
2460       CPPUNIT_ASSERT_EQUAL(1,(int)conn.size());
2461       CPPUNIT_ASSERT_EQUAL(i,conn[0]);
2462       CPPUNIT_ASSERT(INTERP_KERNEL::NORM_POINT1==m->getTypeOfCell(i));
2463     }
2464   CPPUNIT_ASSERT(std::string(m->getName())=="My0D");
2465   m->decrRef();
2466   coo->decrRef();
2467 }
2468