1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "MEDCouplingBasicsTest3.hxx"
21 #include "MEDCouplingUMesh.hxx"
22 #include "MEDCouplingCMesh.hxx"
23 #include "MEDCouplingExtrudedMesh.hxx"
24 #include "MEDCouplingFieldDouble.hxx"
25 #include "MEDCouplingMemArray.hxx"
26 #include "MEDCouplingGaussLocalization.hxx"
32 using namespace ParaMEDMEM;
34 void MEDCouplingBasicsTest3::testGetMeasureFieldCMesh1()
36 MEDCouplingCMesh *m=MEDCouplingCMesh::New();
37 DataArrayDouble *da=DataArrayDouble::New();
38 const double discX[4]={2.3,3.4,5.8,10.2};
39 const double discY[3]={12.3,23.4,45.8};
40 const double discZ[5]={-0.7,1.2,1.25,2.13,2.67};
42 std::copy(discX,discX+4,da->getPointer());
46 CPPUNIT_ASSERT_EQUAL(4,m->getNumberOfNodes());
47 CPPUNIT_ASSERT_EQUAL(3,m->getNumberOfCells());
48 CPPUNIT_ASSERT_EQUAL(1,m->getSpaceDimension());
49 MEDCouplingFieldDouble *f=m->getMeasureField(true);
50 CPPUNIT_ASSERT_EQUAL(3,f->getNumberOfTuples());
51 CPPUNIT_ASSERT_EQUAL(1,f->getNumberOfComponents());
52 const double expected1[3]={1.1,2.4,4.4};
54 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f->getIJ(i,0),1e-12);
56 DataArrayDouble *coords=m->getCoordinatesAndOwner();
57 CPPUNIT_ASSERT_EQUAL(4,coords->getNumberOfTuples());
58 CPPUNIT_ASSERT_EQUAL(1,coords->getNumberOfComponents());
60 CPPUNIT_ASSERT_DOUBLES_EQUAL(discX[i],coords->getIJ(i,0),1e-12);
62 coords=m->getBarycenterAndOwner();
63 CPPUNIT_ASSERT_EQUAL(3,coords->getNumberOfTuples());
64 CPPUNIT_ASSERT_EQUAL(1,coords->getNumberOfComponents());
65 const double expected1_3[3]={2.85,4.6,8.};
67 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1_3[i],coords->getIJ(i,0),1e-12);
70 da=DataArrayDouble::New();
72 std::copy(discY,discY+3,da->getPointer());
76 CPPUNIT_ASSERT_EQUAL(12,m->getNumberOfNodes());
77 CPPUNIT_ASSERT_EQUAL(6,m->getNumberOfCells());
78 CPPUNIT_ASSERT_EQUAL(2,m->getSpaceDimension());
79 f=m->getMeasureField(true);
80 CPPUNIT_ASSERT_EQUAL(6,f->getNumberOfTuples());
81 CPPUNIT_ASSERT_EQUAL(1,f->getNumberOfComponents());
82 const double expected2[6]={12.21,26.64,48.84,24.64,53.76,98.56};
84 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(i,0),1e-12);
86 coords=m->getCoordinatesAndOwner();
87 CPPUNIT_ASSERT_EQUAL(12,coords->getNumberOfTuples());
88 CPPUNIT_ASSERT_EQUAL(2,coords->getNumberOfComponents());
89 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 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2_2[i],coords->getIJ(0,i),1e-12);
93 coords=m->getBarycenterAndOwner();
94 CPPUNIT_ASSERT_EQUAL(6,coords->getNumberOfTuples());
95 CPPUNIT_ASSERT_EQUAL(2,coords->getNumberOfComponents());
96 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 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2_3[i],coords->getIJ(0,i),1e-12);
101 da=DataArrayDouble::New();
103 std::copy(discZ,discZ+5,da->getPointer());
104 m->setCoordsAt(2,da);
107 CPPUNIT_ASSERT_EQUAL(60,m->getNumberOfNodes());
108 CPPUNIT_ASSERT_EQUAL(24,m->getNumberOfCells());
109 CPPUNIT_ASSERT_EQUAL(3,m->getSpaceDimension());
110 f=m->getMeasureField(true);
111 CPPUNIT_ASSERT_EQUAL(24,f->getNumberOfTuples());
112 CPPUNIT_ASSERT_EQUAL(1,f->getNumberOfComponents());
113 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};
114 for(int i=0;i<24;i++)
115 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],f->getIJ(i,0),1e-12);
117 coords=m->getCoordinatesAndOwner();
118 CPPUNIT_ASSERT_EQUAL(60,coords->getNumberOfTuples());
119 CPPUNIT_ASSERT_EQUAL(3,coords->getNumberOfComponents());
120 const double expected3_2[180]={
121 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,
122 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,
123 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,
124 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,
125 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 for(int i=0;i<180;i++)
128 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3_2[i],coords->getIJ(0,i),1e-12);
130 coords=m->getBarycenterAndOwner();
131 CPPUNIT_ASSERT_EQUAL(24,coords->getNumberOfTuples());
132 CPPUNIT_ASSERT_EQUAL(3,coords->getNumberOfComponents());
133 const double expected3_3[72]={
134 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,
135 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,
136 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,
137 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 for(int i=0;i<72;i++)
140 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3_3[i],coords->getIJ(0,i),1e-12);
146 void MEDCouplingBasicsTest3::testFieldDoubleZipCoords1()
148 MEDCouplingUMesh *m=build2DTargetMeshMergeNode_1();
149 MEDCouplingFieldDouble *f=m->fillFromAnalytic(ON_NODES,2,"x*2.");
150 f->getArray()->setInfoOnComponent(0,"titi");
151 f->getArray()->setInfoOnComponent(1,"tutu");
153 CPPUNIT_ASSERT_EQUAL(18,f->getNumberOfTuples());
154 CPPUNIT_ASSERT_EQUAL(2,f->getNumberOfComponents());
155 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};
156 for(int i=0;i<36;i++)
157 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f->getIJ(0,i),1e-12);
158 CPPUNIT_ASSERT(f->zipCoords());
160 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};
161 for(int i=0;i<30;i++)
162 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(0,i),1e-12);
163 CPPUNIT_ASSERT(!f->zipCoords());
165 for(int i=0;i<30;i++)
166 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(0,i),1e-12);
167 CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(0))=="titi");
168 CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(1))=="tutu");
173 void MEDCouplingBasicsTest3::testFieldDoubleZipConnectivity1()
175 MEDCouplingUMesh *m1=build2DTargetMesh_1();
176 MEDCouplingUMesh *m2=build2DTargetMesh_1();
177 const int cells1[3]={2,3,4};
178 MEDCouplingPointSet *m3_1=m2->buildPartOfMySelf(cells1,cells1+3,true);
179 MEDCouplingUMesh *m3=dynamic_cast<MEDCouplingUMesh *>(m3_1);
182 MEDCouplingUMesh *m4=build2DSourceMesh_1();
183 MEDCouplingUMesh *m5=MEDCouplingUMesh::MergeUMeshes(m1,m3);
186 MEDCouplingUMesh *m6=MEDCouplingUMesh::MergeUMeshes(m5,m4);
190 CPPUNIT_ASSERT_EQUAL(10,m6->getNumberOfCells());
191 CPPUNIT_ASSERT_EQUAL(22,m6->getNumberOfNodes());
194 DataArrayInt *arr=m6->mergeNodes(1e-13,areNodesMerged,newNbOfNodes);
195 CPPUNIT_ASSERT_EQUAL(9,m6->getNumberOfNodes());
197 MEDCouplingFieldDouble *f=m6->fillFromAnalytic(ON_CELLS,2,"x");
198 MEDCouplingFieldDouble *f2=m6->fillFromAnalytic(ON_NODES,2,"x");
199 CPPUNIT_ASSERT_EQUAL(10,f->getNumberOfTuples());
200 CPPUNIT_ASSERT_EQUAL(2,f->getNumberOfComponents());
201 const double expected1[20]={-0.05, -0.05, 0.3666666666666667, 0.3666666666666667, 0.53333333333333321, 0.53333333333333321,
202 -0.05, -0.05, 0.45, 0.45, 0.53333333333333321, 0.53333333333333321, -0.05, -0.05, 0.45, 0.45,
203 0.36666666666666659, 0.36666666666666659, 0.033333333333333326, 0.033333333333333326};
204 for(int i=0;i<20;i++)
205 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f->getIJ(0,i),1e-12);
206 f->getArray()->setInfoOnComponent(0,"titi");
207 f->getArray()->setInfoOnComponent(1,"tutu");
209 CPPUNIT_ASSERT(f->zipConnectivity(0));
210 const double expected2[14]={-0.05, -0.05, 0.3666666666666667, 0.3666666666666667, 0.53333333333333321, 0.53333333333333321,
211 -0.05, -0.05, 0.45, 0.45, 0.36666666666666659, 0.36666666666666659, 0.033333333333333326, 0.033333333333333326};
212 CPPUNIT_ASSERT_EQUAL(7,f->getNumberOfTuples());
213 CPPUNIT_ASSERT_EQUAL(2,f->getNumberOfComponents());
214 for(int i=0;i<14;i++)
215 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(0,i),1e-12);
216 CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(0))=="titi");
217 CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(1))=="tutu");
218 CPPUNIT_ASSERT(!f->zipConnectivity(0));
221 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,
222 -0.3, -0.3, 0.2, 0.2, 0.7, 0.7};
223 CPPUNIT_ASSERT_EQUAL(9,f2->getNumberOfTuples());
224 CPPUNIT_ASSERT_EQUAL(2,f2->getNumberOfComponents());
225 for(int i=0;i<18;i++)
226 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],f2->getIJ(0,i),1e-12);
227 CPPUNIT_ASSERT(f2->zipConnectivity(0));
228 CPPUNIT_ASSERT_EQUAL(9,f2->getNumberOfTuples());
229 CPPUNIT_ASSERT_EQUAL(2,f2->getNumberOfComponents());
230 for(int i=0;i<18;i++)
231 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],f2->getIJ(0,i),1e-12);
237 void MEDCouplingBasicsTest3::testDaDoubleRenumber1()
239 DataArrayDouble *a=DataArrayDouble::New();
241 a->setInfoOnComponent(0,"toto");
242 a->setInfoOnComponent(1,"tata");
243 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};
244 std::copy(arr1,arr1+14,a->getPointer());
246 const int arr2[7]={3,1,0,6,5,4,2};
247 DataArrayDouble *b=a->renumber(arr2);
248 CPPUNIT_ASSERT_EQUAL(7,b->getNumberOfTuples());
249 CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
250 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
251 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
252 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};
253 for(int i=0;i<14;i++)
254 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
258 DataArrayInt *c=DataArrayInt::New();
260 c->setInfoOnComponent(0,"toto");
261 c->setInfoOnComponent(1,"tata");
262 const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
263 std::copy(arr3,arr3+14,c->getPointer());
264 DataArrayInt *d=c->renumber(arr2);
265 CPPUNIT_ASSERT_EQUAL(7,d->getNumberOfTuples());
266 CPPUNIT_ASSERT_EQUAL(2,d->getNumberOfComponents());
267 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
268 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
269 const int expected2[14]={3, 13, 2, 12, 7, 17, 1, 11, 6, 16, 5, 15, 4, 14};
270 for(int i=0;i<14;i++)
271 CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
276 void MEDCouplingBasicsTest3::testDaDoubleRenumberAndReduce1()
278 DataArrayDouble *a=DataArrayDouble::New();
280 a->setInfoOnComponent(0,"toto");
281 a->setInfoOnComponent(1,"tata");
282 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};
283 std::copy(arr1,arr1+14,a->getPointer());
285 const int arr2[7]={2,-1,1,-1,0,4,3};
286 DataArrayDouble *b=a->renumberAndReduce(arr2,5);
287 CPPUNIT_ASSERT_EQUAL(5,b->getNumberOfTuples());
288 CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
289 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
290 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
291 const double expected1[10]={5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1};
292 for(int i=0;i<10;i++)
293 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
297 DataArrayInt *c=DataArrayInt::New();
299 c->setInfoOnComponent(0,"toto");
300 c->setInfoOnComponent(1,"tata");
301 const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
302 std::copy(arr3,arr3+14,c->getPointer());
303 DataArrayInt *d=c->renumberAndReduce(arr2,5);
304 CPPUNIT_ASSERT_EQUAL(5,d->getNumberOfTuples());
305 CPPUNIT_ASSERT_EQUAL(2,d->getNumberOfComponents());
306 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
307 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
308 const int expected2[10]={5,15,3,13,1,11,7,17,6,16};
309 for(int i=0;i<10;i++)
310 CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
315 void MEDCouplingBasicsTest3::testDaDoubleRenumberInPlace1()
317 DataArrayDouble *a=DataArrayDouble::New();
319 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};
320 std::copy(arr1,arr1+14,a->getPointer());
322 const int arr2[7]={3,1,0,6,5,4,2};
323 a->renumberInPlace(arr2);
324 CPPUNIT_ASSERT_EQUAL(7,a->getNumberOfTuples());
325 CPPUNIT_ASSERT_EQUAL(2,a->getNumberOfComponents());
326 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};
327 for(int i=0;i<14;i++)
328 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],a->getIJ(0,i),1e-14);
331 DataArrayInt *c=DataArrayInt::New();
333 const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
334 std::copy(arr3,arr3+14,c->getPointer());
335 c->renumberInPlace(arr2);
336 CPPUNIT_ASSERT_EQUAL(7,c->getNumberOfTuples());
337 CPPUNIT_ASSERT_EQUAL(2,c->getNumberOfComponents());
338 const int expected2[14]={3, 13, 2, 12, 7, 17, 1, 11, 6, 16, 5, 15, 4, 14};
339 for(int i=0;i<14;i++)
340 CPPUNIT_ASSERT_EQUAL(expected2[i],c->getIJ(0,i));
344 void MEDCouplingBasicsTest3::testDaDoubleRenumberR1()
346 DataArrayDouble *a=DataArrayDouble::New();
348 a->setInfoOnComponent(0,"toto");
349 a->setInfoOnComponent(1,"tata");
350 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};
351 std::copy(arr1,arr1+14,a->getPointer());
353 const int arr2[7]={3,1,0,6,5,4,2};
354 DataArrayDouble *b=a->renumberR(arr2);
355 CPPUNIT_ASSERT_EQUAL(7,b->getNumberOfTuples());
356 CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
357 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
358 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
359 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};
360 for(int i=0;i<14;i++)
361 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
365 DataArrayInt *c=DataArrayInt::New();
367 c->setInfoOnComponent(0,"toto");
368 c->setInfoOnComponent(1,"tata");
369 const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
370 std::copy(arr3,arr3+14,c->getPointer());
371 DataArrayInt *d=c->renumberR(arr2);
372 CPPUNIT_ASSERT_EQUAL(7,d->getNumberOfTuples());
373 CPPUNIT_ASSERT_EQUAL(2,d->getNumberOfComponents());
374 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
375 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
376 const int expected2[14]={4, 14, 2, 12, 1, 11, 7, 17, 6, 16, 5, 15, 3, 13};
377 for(int i=0;i<14;i++)
378 CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
383 void MEDCouplingBasicsTest3::testDaDoubleRenumberInPlaceR1()
385 DataArrayDouble *a=DataArrayDouble::New();
387 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};
388 std::copy(arr1,arr1+14,a->getPointer());
390 const int arr2[7]={3,1,0,6,5,4,2};
391 a->renumberInPlaceR(arr2);
392 CPPUNIT_ASSERT_EQUAL(7,a->getNumberOfTuples());
393 CPPUNIT_ASSERT_EQUAL(2,a->getNumberOfComponents());
394 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};
395 for(int i=0;i<14;i++)
396 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],a->getIJ(0,i),1e-14);
399 DataArrayInt *c=DataArrayInt::New();
401 const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
402 std::copy(arr3,arr3+14,c->getPointer());
403 c->renumberInPlaceR(arr2);
404 CPPUNIT_ASSERT_EQUAL(7,c->getNumberOfTuples());
405 CPPUNIT_ASSERT_EQUAL(2,c->getNumberOfComponents());
406 const int expected2[14]={4, 14, 2, 12, 1, 11, 7, 17, 6, 16, 5, 15, 3, 13};
407 for(int i=0;i<14;i++)
408 CPPUNIT_ASSERT_EQUAL(expected2[i],c->getIJ(0,i));
412 void MEDCouplingBasicsTest3::testDaDoubleSelectByTupleId1()
414 DataArrayDouble *a=DataArrayDouble::New();
416 a->setInfoOnComponent(0,"toto");
417 a->setInfoOnComponent(1,"tata");
418 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};
419 std::copy(arr1,arr1+14,a->getPointer());
421 const int arr2[7]={4,2,0,6,5};
422 DataArrayDouble *b=a->selectByTupleId(arr2,arr2+5);
423 CPPUNIT_ASSERT_EQUAL(5,b->getNumberOfTuples());
424 CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
425 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
426 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
427 const double expected1[10]={5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1};
428 for(int i=0;i<10;i++)
429 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
433 DataArrayInt *c=DataArrayInt::New();
435 c->setInfoOnComponent(0,"toto");
436 c->setInfoOnComponent(1,"tata");
437 const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
438 std::copy(arr3,arr3+14,c->getPointer());
439 DataArrayInt *d=c->selectByTupleId(arr2,arr2+5);
440 CPPUNIT_ASSERT_EQUAL(5,d->getNumberOfTuples());
441 CPPUNIT_ASSERT_EQUAL(2,d->getNumberOfComponents());
442 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
443 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
444 const int expected2[10]={5,15,3,13,1,11,7,17,6,16};
445 for(int i=0;i<10;i++)
446 CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
451 void MEDCouplingBasicsTest3::testDaDoubleGetMinMaxValues1()
453 DataArrayDouble *a=DataArrayDouble::New();
455 const double arr1[9]={2.34,4.56,-6.77,4.55,4.56,2.24,2.34,1.02,4.56};
456 std::copy(arr1,arr1+9,a->getPointer());
458 double m=a->getMaxValue(where);
459 CPPUNIT_ASSERT_EQUAL(1,where);
460 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.56,m,1e-12);
462 m=a->getMaxValue2(ws);
463 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.56,m,1e-12);
464 CPPUNIT_ASSERT_EQUAL(3,ws->getNumberOfTuples());
465 CPPUNIT_ASSERT_EQUAL(1,ws->getNumberOfComponents());
466 const int expected1[3]={1,4,8};
468 CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
471 a=DataArrayDouble::New();
472 const double arr2[9]={-2.34,-4.56,6.77,-4.55,-4.56,-2.24,-2.34,-1.02,-4.56};
474 std::copy(arr2,arr2+9,a->getPointer());
476 m=a->getMinValue(where);
477 CPPUNIT_ASSERT_EQUAL(1,where);
478 CPPUNIT_ASSERT_DOUBLES_EQUAL(-4.56,m,1e-12);
479 m=a->getMinValue2(ws);
480 CPPUNIT_ASSERT_DOUBLES_EQUAL(-4.56,m,1e-12);
481 CPPUNIT_ASSERT_EQUAL(3,ws->getNumberOfTuples());
482 CPPUNIT_ASSERT_EQUAL(1,ws->getNumberOfComponents());
484 CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
489 void MEDCouplingBasicsTest3::testFieldDoubleGetMinMaxValues2()
491 MEDCouplingUMesh *m1=0;
492 MEDCouplingUMesh *m2=build3DExtrudedUMesh_1(m1);
494 CPPUNIT_ASSERT_EQUAL(18,m2->getNumberOfCells());
495 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};
496 MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
497 DataArrayDouble *a=DataArrayDouble::New();
499 std::copy(arr1,arr1+18,a->getPointer());
505 double m=f->getMaxValue();
506 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.71,m,1e-12);
508 m=f->getMaxValue2(ws);
509 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.71,m,1e-12);
510 CPPUNIT_ASSERT_EQUAL(4,ws->getNumberOfTuples());
511 CPPUNIT_ASSERT_EQUAL(1,ws->getNumberOfComponents());
512 const int expected1[4]={0,3,7,17};
514 CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
517 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};
518 std::copy(arr2,arr2+18,a->getPointer());
521 CPPUNIT_ASSERT_DOUBLES_EQUAL(-8.71,m,1e-12);
522 m=f->getMinValue2(ws);
523 CPPUNIT_ASSERT_DOUBLES_EQUAL(-8.71,m,1e-12);
524 CPPUNIT_ASSERT_EQUAL(4,ws->getNumberOfTuples());
525 CPPUNIT_ASSERT_EQUAL(1,ws->getNumberOfComponents());
527 CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
534 void MEDCouplingBasicsTest3::testBuildUnstructuredCMesh1()
536 MEDCouplingCMesh *m=MEDCouplingCMesh::New();
537 DataArrayDouble *da=DataArrayDouble::New();
538 const double discX[4]={2.3,3.4,5.8,10.2};
539 const double discY[3]={12.3,23.4,45.8};
540 const double discZ[5]={-0.7,1.2,1.25,2.13,2.67};
542 std::copy(discX,discX+4,da->getPointer());
543 m->setCoordsAt(0,da);
547 CPPUNIT_ASSERT_EQUAL(0,m->getCellContainingPoint(&pos,1e-12));
549 CPPUNIT_ASSERT_EQUAL(1,m->getCellContainingPoint(&pos,1e-12));
551 CPPUNIT_ASSERT_EQUAL(2,m->getCellContainingPoint(&pos,1e-12));
553 CPPUNIT_ASSERT_EQUAL(-1,m->getCellContainingPoint(&pos,1e-12));
555 CPPUNIT_ASSERT_EQUAL(-1,m->getCellContainingPoint(&pos,1e-12));
557 MEDCouplingUMesh *m2=m->buildUnstructured();
558 m2->checkCoherency();
559 MEDCouplingFieldDouble *f1=m->getMeasureField(false);
560 MEDCouplingFieldDouble *f2=m2->getMeasureField(false);
561 CPPUNIT_ASSERT_EQUAL(f1->getNumberOfTuples(),3);
562 CPPUNIT_ASSERT_EQUAL(f2->getNumberOfTuples(),3);
563 CPPUNIT_ASSERT_EQUAL(1,m2->getMeshDimension());
564 CPPUNIT_ASSERT_EQUAL(1,m2->getSpaceDimension());
566 CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getIJ(i,0),f2->getIJ(i,0),1e-10);
567 da=DataArrayDouble::New();
569 std::copy(discY,discY+3,da->getPointer());
570 m->setCoordsAt(1,da);
576 m2=m->buildUnstructured();
577 m2->checkCoherency();
578 f1=m->getMeasureField(false);
579 f2=m2->getMeasureField(false);
580 CPPUNIT_ASSERT_EQUAL(f1->getNumberOfTuples(),6);
581 CPPUNIT_ASSERT_EQUAL(f2->getNumberOfTuples(),6);
582 CPPUNIT_ASSERT_EQUAL(2,m2->getMeshDimension());
583 CPPUNIT_ASSERT_EQUAL(2,m2->getSpaceDimension());
585 CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getIJ(i,0),f2->getIJ(i,0),1e-10);
590 da=DataArrayDouble::New();
592 std::copy(discZ,discZ+5,da->getPointer());
593 m->setCoordsAt(2,da);
595 m2=m->buildUnstructured();
596 m2->checkCoherency();
597 f1=m->getMeasureField(false);
598 f2=m2->getMeasureField(false);
599 CPPUNIT_ASSERT_EQUAL(f1->getNumberOfTuples(),24);
600 CPPUNIT_ASSERT_EQUAL(f2->getNumberOfTuples(),24);
601 CPPUNIT_ASSERT_EQUAL(3,m2->getMeshDimension());
602 CPPUNIT_ASSERT_EQUAL(3,m2->getSpaceDimension());
603 for(int i=0;i<24;i++)
604 CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getIJ(i,0),f2->getIJ(i,0),1e-10);
608 double pos1[3]={5.,30.,2.};
609 CPPUNIT_ASSERT_EQUAL(16,m->getCellContainingPoint(pos1,1e-12));
611 const double pt[3]={2.4,12.7,-3.4};
613 MEDCouplingUMesh *m3=m->buildUnstructured();
615 CPPUNIT_ASSERT(m3->isEqual(m2,1e-12));
622 void MEDCouplingBasicsTest3::testDataArrayIntInvertO2NNO21()
624 const int arr1[6]={2,0,4,1,5,3};
625 DataArrayInt *da=DataArrayInt::New();
627 std::copy(arr1,arr1+6,da->getPointer());
628 DataArrayInt *da2=da->invertArrayO2N2N2O(6);
629 CPPUNIT_ASSERT_EQUAL(6,da2->getNumberOfTuples());
630 CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
631 const int expected1[6]={1,3,0,5,2,4};
633 CPPUNIT_ASSERT_EQUAL(expected1[i],da2->getIJ(i,0));
634 DataArrayInt *da3=da2->invertArrayN2O2O2N(6);
636 CPPUNIT_ASSERT_EQUAL(arr1[i],da3->getIJ(i,0));
641 const int arr2[10]={3,-1,5,4,-1,0,-1,1,2,-1};
642 da=DataArrayInt::New();
644 std::copy(arr2,arr2+10,da->getPointer());
645 da2=da->invertArrayO2N2N2O(6);
646 CPPUNIT_ASSERT_EQUAL(6,da2->getNumberOfTuples());
647 CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
648 const int expected2[10]={5,7,8,0,3,2};
650 CPPUNIT_ASSERT_EQUAL(expected2[i],da2->getIJ(i,0));
651 da3=da2->invertArrayN2O2O2N(10);
652 for(int i=0;i<10;i++)
653 CPPUNIT_ASSERT_EQUAL(arr2[i],da3->getIJ(i,0));
659 void MEDCouplingBasicsTest3::testKeepSetSelectedComponent1()
661 const double arr1[20]={1.,2.,3.,4., 11.,12.,13.,14., 21.,22.,23.,24., 31.,32.,33.,34., 41.,42.,43.,44.};
662 DataArrayDouble *a1=DataArrayDouble::New();
664 std::copy(arr1,arr1+20,a1->getPointer());
665 a1->setInfoOnComponent(0,"aaaa");
666 a1->setInfoOnComponent(1,"bbbb");
667 a1->setInfoOnComponent(2,"cccc");
668 a1->setInfoOnComponent(3,"dddd");
669 const int arr2[6]={1,2,1,2,0,0};
670 std::vector<int> arr2V(arr2,arr2+6);
671 DataArrayDouble *a2=a1->keepSelectedComponents(arr2V);
672 CPPUNIT_ASSERT_EQUAL(6,a2->getNumberOfComponents());
673 CPPUNIT_ASSERT_EQUAL(5,a2->getNumberOfTuples());
674 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(0))=="bbbb");
675 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(1))=="cccc");
676 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(2))=="bbbb");
677 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(3))=="cccc");
678 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(4))=="aaaa");
679 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(5))=="aaaa");
680 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.};
681 for(int i=0;i<30;i++)
682 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],a2->getIJ(0,i),1e-14);
683 DataArrayInt *a3=a1->convertToIntArr();
684 DataArrayInt *a4=a3->keepSelectedComponents(arr2V);
685 CPPUNIT_ASSERT_EQUAL(6,a4->getNumberOfComponents());
686 CPPUNIT_ASSERT_EQUAL(5,a4->getNumberOfTuples());
687 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(0))=="bbbb");
688 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(1))=="cccc");
689 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(2))=="bbbb");
690 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(3))=="cccc");
691 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(4))=="aaaa");
692 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(5))=="aaaa");
693 for(int i=0;i<30;i++)
694 CPPUNIT_ASSERT_EQUAL(int(expected1[i]),a4->getIJ(0,i));
695 // setSelectedComponents
696 const int arr3[2]={3,2};
697 std::vector<int> arr3V(arr3,arr3+2);
698 DataArrayDouble *a5=a1->keepSelectedComponents(arr3V);
699 a5->setInfoOnComponent(0,"eeee");
700 a5->setInfoOnComponent(1,"ffff");
701 const int arr4[2]={1,2};
702 std::vector<int> arr4V(arr4,arr4+2);
703 a2->setSelectedComponents(a5,arr4V);
704 CPPUNIT_ASSERT_EQUAL(6,a2->getNumberOfComponents());
705 CPPUNIT_ASSERT_EQUAL(5,a2->getNumberOfTuples());
706 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(0))=="bbbb");
707 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(1))=="eeee");
708 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(2))=="ffff");
709 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(3))=="cccc");
710 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(4))=="aaaa");
711 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(5))=="aaaa");
712 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.};
713 for(int i=0;i<30;i++)
714 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],a2->getIJ(0,i),1e-14);
715 DataArrayInt *a6=a5->convertToIntArr();
716 a6->setInfoOnComponent(0,"eeee");
717 a6->setInfoOnComponent(1,"ffff");
718 a4->setSelectedComponents(a6,arr4V);
719 CPPUNIT_ASSERT_EQUAL(6,a4->getNumberOfComponents());
720 CPPUNIT_ASSERT_EQUAL(5,a4->getNumberOfTuples());
721 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(0))=="bbbb");
722 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(1))=="eeee");
723 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(2))=="ffff");
724 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(3))=="cccc");
725 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(4))=="aaaa");
726 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(5))=="aaaa");
727 for(int i=0;i<30;i++)
728 CPPUNIT_ASSERT_EQUAL(int(expected2[i]),a4->getIJ(0,i));
730 const int arr5[3]={2,3,6};
731 const int arr6[3]={2,7,5};
732 const int arr7[4]={2,1,4,6};
733 std::vector<int> arr5V(arr5,arr5+3);
734 std::vector<int> arr6V(arr6,arr6+3);
735 std::vector<int> arr7V(arr7,arr7+4);
736 CPPUNIT_ASSERT_THROW(a2->keepSelectedComponents(arr5V),INTERP_KERNEL::Exception);
737 CPPUNIT_ASSERT_THROW(a2->keepSelectedComponents(arr6V),INTERP_KERNEL::Exception);
738 CPPUNIT_ASSERT_THROW(a2->setSelectedComponents(a1,arr7V),INTERP_KERNEL::Exception);
740 CPPUNIT_ASSERT_THROW(a2->setSelectedComponents(a1,arr7V),INTERP_KERNEL::Exception);
750 void MEDCouplingBasicsTest3::testKeepSetSelectedComponent2()
752 MEDCouplingUMesh *m1=build2DTargetMesh_1();
753 const double arr1[20]={1.,2.,3.,4., 11.,12.,13.,14., 21.,22.,23.,24., 31.,32.,33.,34., 41.,42.,43.,44.};
754 DataArrayDouble *a1=DataArrayDouble::New();
756 std::copy(arr1,arr1+20,a1->getPointer());
757 a1->setInfoOnComponent(0,"aaaa");
758 a1->setInfoOnComponent(1,"bbbb");
759 a1->setInfoOnComponent(2,"cccc");
760 a1->setInfoOnComponent(3,"dddd");
761 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
762 f1->setTime(2.3,4,5);
766 f1->checkCoherency();
768 const int arr2[6]={1,2,1,2,0,0};
769 std::vector<int> arr2V(arr2,arr2+6);
770 MEDCouplingFieldDouble *f2=f1->keepSelectedComponents(arr2V);
771 CPPUNIT_ASSERT(f2->getMesh()==f1->getMesh());
772 CPPUNIT_ASSERT(f2->getTimeDiscretization()==ONE_TIME);
774 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.3,f2->getTime(dt,it),1e-13);
775 CPPUNIT_ASSERT_EQUAL(4,dt);
776 CPPUNIT_ASSERT_EQUAL(5,it);
777 f2->checkCoherency();
778 CPPUNIT_ASSERT_EQUAL(6,f2->getNumberOfComponents());
779 CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
780 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(0))=="bbbb");
781 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(1))=="cccc");
782 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(2))=="bbbb");
783 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(3))=="cccc");
784 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(4))=="aaaa");
785 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(5))=="aaaa");
786 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.};
787 for(int i=0;i<30;i++)
788 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f2->getIJ(0,i),1e-14);
789 //setSelectedComponents
790 const int arr3[2]={3,2};
791 std::vector<int> arr3V(arr3,arr3+2);
792 MEDCouplingFieldDouble *f5=f1->keepSelectedComponents(arr3V);
793 f5->setTime(6.7,8,9);
794 f5->getArray()->setInfoOnComponent(0,"eeee");
795 f5->getArray()->setInfoOnComponent(1,"ffff");
796 f5->checkCoherency();
797 const int arr4[2]={1,2};
798 std::vector<int> arr4V(arr4,arr4+2);
799 f2->setSelectedComponents(f5,arr4V);
800 CPPUNIT_ASSERT_EQUAL(6,f2->getNumberOfComponents());
801 CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
802 f2->checkCoherency();
803 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.3,f2->getTime(dt,it),1e-13);
804 CPPUNIT_ASSERT_EQUAL(4,dt);
805 CPPUNIT_ASSERT_EQUAL(5,it);
806 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(0))=="bbbb");
807 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(1))=="eeee");
808 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(2))=="ffff");
809 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(3))=="cccc");
810 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(4))=="aaaa");
811 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(5))=="aaaa");
812 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.};
813 for(int i=0;i<30;i++)
814 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f2->getIJ(0,i),1e-14);
822 void MEDCouplingBasicsTest3::testElementaryDAThrowAndSpecialCases()
824 DataArrayInt *da=DataArrayInt::New();
825 CPPUNIT_ASSERT_THROW(da->checkAllocated(),INTERP_KERNEL::Exception);
826 CPPUNIT_ASSERT_THROW(da->fillWithValue(1),INTERP_KERNEL::Exception);
827 CPPUNIT_ASSERT_THROW(da->iota(1),INTERP_KERNEL::Exception);
829 da->fillWithValue(11); //11,11,11,11...
830 da->iota(10); //10,11,12,13...
832 DataArrayInt *db=DataArrayInt::New();
835 DataArrayDouble *dbl2=DataArrayDouble::New();
837 CPPUNIT_ASSERT_THROW(dbl2->isUniform(10.,1e-15),INTERP_KERNEL::Exception);
838 CPPUNIT_ASSERT_THROW(dbl2->sort(),INTERP_KERNEL::Exception);
839 CPPUNIT_ASSERT_THROW(dbl2->reverse(),INTERP_KERNEL::Exception);
840 CPPUNIT_ASSERT_THROW(dbl2->iota(10.),INTERP_KERNEL::Exception);
842 DataArrayDouble *dbl=DataArrayDouble::New();
843 //DataArrayDouble not allocated yet
844 CPPUNIT_ASSERT_THROW(dbl->iota(10.),INTERP_KERNEL::Exception);
845 CPPUNIT_ASSERT_THROW(dbl->isUniform(10.,1e-15),INTERP_KERNEL::Exception);
846 CPPUNIT_ASSERT_THROW(dbl->sort(),INTERP_KERNEL::Exception);
847 CPPUNIT_ASSERT_THROW(dbl->reverse(),INTERP_KERNEL::Exception);
848 CPPUNIT_ASSERT_THROW(dbl->fromNoInterlace(),INTERP_KERNEL::Exception);
849 CPPUNIT_ASSERT_THROW(dbl->toNoInterlace(),INTERP_KERNEL::Exception);
853 CPPUNIT_ASSERT(!dbl->isUniform(10.,1e-15));
855 CPPUNIT_ASSERT(dbl->isMonotonic(true, .99));
856 CPPUNIT_ASSERT(dbl->isMonotonic(true, -.99));
857 CPPUNIT_ASSERT(!dbl->isMonotonic(true, 1.1));
858 CPPUNIT_ASSERT(!dbl->isMonotonic(true, -1.1));
860 CPPUNIT_ASSERT(dbl->isMonotonic(false, .99));
861 CPPUNIT_ASSERT(!dbl->isMonotonic(false, 1.1));
862 CPPUNIT_ASSERT(!dbl->isMonotonic(false, -1.1));
864 DataArrayInt *dc=DataArrayInt::New();
867 DataArrayDouble *dd=DataArrayDouble::New();
868 CPPUNIT_ASSERT_THROW(dd->checkAllocated(),INTERP_KERNEL::Exception);
869 CPPUNIT_ASSERT_THROW(dd->fillWithValue(1.),INTERP_KERNEL::Exception);
870 CPPUNIT_ASSERT_THROW(dd->iota(1.),INTERP_KERNEL::Exception);
871 CPPUNIT_ASSERT(!((dd->repr().find("No data"))==std::string::npos));
873 dd->alloc(0,1); //Allocated but nbOfElements==0!
874 CPPUNIT_ASSERT(!((dd->repr().find("Number of tuples : 0"))==std::string::npos));
875 CPPUNIT_ASSERT(!((dd->repr().find("Empty Data"))==std::string::npos));
876 dd->fillWithValue(11); //?!...
877 dd->iota(10); //?!...
878 CPPUNIT_ASSERT(dd->isMonotonic(true, 1.));
879 CPPUNIT_ASSERT(dd->isMonotonic(false, 1.));
881 CPPUNIT_ASSERT_THROW(db->copyStringInfoFrom(*da),INTERP_KERNEL::Exception);
882 CPPUNIT_ASSERT_THROW(db->copyStringInfoFrom(*da),INTERP_KERNEL::Exception);
883 std::vector<int> cIds(2,2);
884 CPPUNIT_ASSERT_THROW(da->copyPartOfStringInfoFrom(*db,cIds),INTERP_KERNEL::Exception);
887 CPPUNIT_ASSERT_THROW(da->copyPartOfStringInfoFrom(*db,cIds),INTERP_KERNEL::Exception);
889 std::vector<std::string> info(2,"infoOfOneComponent");
890 CPPUNIT_ASSERT_THROW(da->setInfoOnComponents(info),INTERP_KERNEL::Exception);
891 CPPUNIT_ASSERT_THROW(da->setInfoOnComponent(1,info[0].c_str()),INTERP_KERNEL::Exception);
892 db->setInfoOnComponents(info);
894 CPPUNIT_ASSERT_THROW(da->getInfoOnComponent(-1),INTERP_KERNEL::Exception);
895 CPPUNIT_ASSERT_THROW(da->getInfoOnComponent(2),INTERP_KERNEL::Exception);
896 CPPUNIT_ASSERT(db->getInfoOnComponent(1)==db->getInfoOnComponent(0));
897 CPPUNIT_ASSERT_THROW(db->getVarOnComponent(-1),INTERP_KERNEL::Exception);
898 CPPUNIT_ASSERT_THROW(db->getVarOnComponent(2),INTERP_KERNEL::Exception);
899 CPPUNIT_ASSERT_THROW(db->getUnitOnComponent(-1),INTERP_KERNEL::Exception);
900 CPPUNIT_ASSERT_THROW(db->getUnitOnComponent(2),INTERP_KERNEL::Exception);
902 CPPUNIT_ASSERT(da->GetVarNameFromInfo(std::string("varname unit "))==std::string("varname unit "));
903 CPPUNIT_ASSERT(da->GetVarNameFromInfo(std::string("varname]unit["))==std::string("varname]unit["));
904 CPPUNIT_ASSERT(da->GetVarNameFromInfo(std::string("[unit]"))==std::string());
905 CPPUNIT_ASSERT(da->GetVarNameFromInfo(std::string("varname [unit]"))==std::string("varname"));
907 CPPUNIT_ASSERT(da->GetUnitFromInfo(std::string("varname unit "))==std::string());
908 CPPUNIT_ASSERT(da->GetUnitFromInfo(std::string("varname]unit["))==std::string());
909 CPPUNIT_ASSERT(da->GetUnitFromInfo(std::string("[unit]"))==std::string("unit"));
910 CPPUNIT_ASSERT(da->GetUnitFromInfo(std::string("varname [unit]"))==std::string("unit"));
912 CPPUNIT_ASSERT_THROW(da->checkNbOfTuplesAndComp(*db,"theMessageInThrow"),INTERP_KERNEL::Exception);
913 CPPUNIT_ASSERT_THROW(da->checkNbOfTuplesAndComp(*dc,"theMessageInThrow"),INTERP_KERNEL::Exception);
914 CPPUNIT_ASSERT_THROW(db->checkNbOfTuplesAndComp(*dc,"theMessageInThrow"),INTERP_KERNEL::Exception);
916 CPPUNIT_ASSERT_THROW(da->checkNbOfTuplesAndComp(7,2,"theMessageInThrow"),INTERP_KERNEL::Exception);
917 da->checkNbOfTuplesAndComp(7,1,"theMessageInThrow");
919 CPPUNIT_ASSERT_THROW(db->checkNbOfElems(7*2+1,"theMessageInThrow"),INTERP_KERNEL::Exception);
920 db->checkNbOfElems(7*2,"theMessageInThrow");
922 CPPUNIT_ASSERT_THROW(db->GetNumberOfItemGivenBES(10,9,1,"theMessageInThrow"),INTERP_KERNEL::Exception);
923 CPPUNIT_ASSERT_THROW(db->GetNumberOfItemGivenBES(0,1,-1,"theMessageInThrow"),INTERP_KERNEL::Exception);
924 CPPUNIT_ASSERT_EQUAL(10,db->GetNumberOfItemGivenBES(0,10,1,"theMessageInThrow"));
925 CPPUNIT_ASSERT_EQUAL(5,db->GetNumberOfItemGivenBES(0,10,2,"theMessageInThrow"));
926 CPPUNIT_ASSERT_EQUAL(6,db->GetNumberOfItemGivenBES(0,11,2,"theMessageInThrow"));
928 //std::cout<<"\n!!!!!!!!!\n"<<dd->repr()<<"\n!!!!!!!!!\n";
929 CPPUNIT_ASSERT(!((da->repr().find("Number of components : 1"))==std::string::npos));
930 CPPUNIT_ASSERT(!((dd->repr().find("Number of components : 1"))==std::string::npos));
931 CPPUNIT_ASSERT(!((dbl->repr().find("Number of components : 1"))==std::string::npos));
933 CPPUNIT_ASSERT(!((da->reprZip().find("Number of components : 1"))==std::string::npos));
934 CPPUNIT_ASSERT(!((dd->reprZip().find("Number of components : 1"))==std::string::npos));
935 CPPUNIT_ASSERT(!((dbl->reprZip().find("Number of components : 1"))==std::string::npos));
937 std::ostringstream ret;
938 dbl->writeVTK(ret,2,"file.tmp");
939 CPPUNIT_ASSERT(!((ret.str().find("<DataArray"))==std::string::npos));
940 CPPUNIT_ASSERT(!((ret.str().find("Float32"))==std::string::npos));
941 CPPUNIT_ASSERT(!((ret.str().find("16 15 14 13 12 11 10"))==std::string::npos));
943 CPPUNIT_ASSERT_THROW(dbl->selectByTupleId2(0,1,-1),INTERP_KERNEL::Exception);
944 CPPUNIT_ASSERT_THROW(dbl->substr(-1,1),INTERP_KERNEL::Exception);
945 CPPUNIT_ASSERT_THROW(dbl->substr(8,1),INTERP_KERNEL::Exception);
946 CPPUNIT_ASSERT_THROW(dbl->substr(0,8),INTERP_KERNEL::Exception);
947 CPPUNIT_ASSERT_THROW(dbl->meldWith(dd),INTERP_KERNEL::Exception);
949 CPPUNIT_ASSERT_THROW(dbl->setPartOfValuesAdv(dbl2,da),INTERP_KERNEL::Exception); //dbl dbl2 not have the same number of components
950 CPPUNIT_ASSERT_THROW(dbl->setPartOfValuesAdv(dd,da),INTERP_KERNEL::Exception); //da tuple selector DataArrayInt instance not have exactly 2 components
952 DataArrayDouble *dbl3=DataArrayDouble::New();
954 dbl3->fillWithValue(11.);
956 //bad number of components
957 CPPUNIT_ASSERT_THROW(dbl3->getMaxValue(tupleId),INTERP_KERNEL::Exception);
958 CPPUNIT_ASSERT_THROW(dd->getMaxValue(tupleId),INTERP_KERNEL::Exception);
959 CPPUNIT_ASSERT_THROW(dbl3->getMinValue(tupleId),INTERP_KERNEL::Exception);
960 CPPUNIT_ASSERT_THROW(dd->getMinValue(tupleId),INTERP_KERNEL::Exception);
961 CPPUNIT_ASSERT_THROW(dbl3->getAverageValue(),INTERP_KERNEL::Exception);
962 CPPUNIT_ASSERT_THROW(dd->getAverageValue(),INTERP_KERNEL::Exception);
963 CPPUNIT_ASSERT_THROW(dd->accumulate(100),INTERP_KERNEL::Exception);
964 CPPUNIT_ASSERT_THROW(dbl->fromPolarToCart(),INTERP_KERNEL::Exception);
965 CPPUNIT_ASSERT_THROW(dbl3->fromCylToCart(),INTERP_KERNEL::Exception);
966 CPPUNIT_ASSERT_THROW(dbl3->fromSpherToCart(),INTERP_KERNEL::Exception);
967 CPPUNIT_ASSERT_THROW(dbl3->doublyContractedProduct(),INTERP_KERNEL::Exception);
968 CPPUNIT_ASSERT_THROW(dbl3->determinant(),INTERP_KERNEL::Exception);
969 CPPUNIT_ASSERT_THROW(dbl3->eigenValues(),INTERP_KERNEL::Exception);
970 CPPUNIT_ASSERT_THROW(dbl3->eigenVectors(),INTERP_KERNEL::Exception);
971 CPPUNIT_ASSERT_THROW(dbl3->inverse(),INTERP_KERNEL::Exception);
972 CPPUNIT_ASSERT_THROW(dbl3->trace(),INTERP_KERNEL::Exception);
973 CPPUNIT_ASSERT_THROW(dbl3->deviator(),INTERP_KERNEL::Exception);
975 dbl3->setIJ(5,1,12.);
976 CPPUNIT_ASSERT(dbl3->getMaxValueInArray()==12.);
977 CPPUNIT_ASSERT(dbl3->getMinValueInArray()==11.);
979 db->fillWithValue(100); //bad Ids
980 CPPUNIT_ASSERT_THROW(dbl3->setPartOfValuesAdv(dbl2,db),INTERP_KERNEL::Exception);
981 db->fillWithValue(-1); //bad Ids
982 CPPUNIT_ASSERT_THROW(dbl3->setPartOfValuesAdv(dbl2,db),INTERP_KERNEL::Exception);
983 db->fillWithValue(6); //bad Ids for dbl3
984 CPPUNIT_ASSERT_THROW(dbl3->setPartOfValuesAdv(dbl2,db),INTERP_KERNEL::Exception);
986 DataArrayDouble::SetArrayIn(dbl,dbl3); //dbl->dbl3 memLeaks?
987 dbl3->checkNoNullValues();
989 CPPUNIT_ASSERT_THROW(dbl3->checkNoNullValues(),INTERP_KERNEL::Exception);
990 CPPUNIT_ASSERT_THROW(dbl3->applyInv(1.),INTERP_KERNEL::Exception); //div by zero
991 CPPUNIT_ASSERT_THROW(dbl2->getIdsInRange(1.,2.),INTERP_KERNEL::Exception);
992 std::vector<const DataArrayDouble *> a(0); //input list must be NON EMPTY
993 CPPUNIT_ASSERT_THROW(DataArrayDouble::Aggregate(a),INTERP_KERNEL::Exception);
994 CPPUNIT_ASSERT_THROW(DataArrayDouble::Meld(a),INTERP_KERNEL::Exception);
997 a.push_back(dbl); //Nb of components mismatch
998 CPPUNIT_ASSERT_THROW(DataArrayDouble::Aggregate(a),INTERP_KERNEL::Exception);
1000 CPPUNIT_ASSERT_THROW(DataArrayDouble::Dot(dbl2,dbl),INTERP_KERNEL::Exception);
1002 CPPUNIT_ASSERT_THROW(DataArrayDouble::CrossProduct(dbl2,dbl),INTERP_KERNEL::Exception); //Nb of components mismatch
1003 CPPUNIT_ASSERT_THROW(DataArrayDouble::CrossProduct(dbl2,dbl2),INTERP_KERNEL::Exception); //Nb of components must be equal to 3
1004 DataArrayDouble *dbl4=DataArrayDouble::New();
1006 DataArrayDouble *dbl5=DataArrayDouble::New();
1008 CPPUNIT_ASSERT_THROW(DataArrayDouble::CrossProduct(dbl4,dbl5),INTERP_KERNEL::Exception); //Nb of tuples mismatch
1010 a[0]=dbl4; //Nb of tuple mismatch
1011 a[1]=dbl5; //Nb of tuple mismatch
1012 CPPUNIT_ASSERT_THROW(DataArrayDouble::Meld(a),INTERP_KERNEL::Exception);
1013 CPPUNIT_ASSERT_THROW(DataArrayDouble::Dot(dbl4,dbl5),INTERP_KERNEL::Exception);
1026 void MEDCouplingBasicsTest3::testDAIGetIdsEqual1()
1028 const int tab1[7]={5,-2,-4,-2,3,2,-2};
1029 DataArrayInt *da=DataArrayInt::New();
1031 std::copy(tab1,tab1+7,da->getPointer());
1032 DataArrayInt *da2=da->getIdsEqual(-2);
1033 CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfTuples());
1034 CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
1035 const int expected1[3]={1,3,6};
1036 CPPUNIT_ASSERT(std::equal(expected1,expected1+3,da2->getConstPointer()));
1041 void MEDCouplingBasicsTest3::testDAIGetIdsEqualList1()
1043 const int tab1[7]={5,-2,-4,-2,3,2,-2};
1044 DataArrayInt *da=DataArrayInt::New();
1046 std::copy(tab1,tab1+7,da->getPointer());
1047 const int tab2[3]={3,-2,0};
1048 std::vector<int> tab2V(tab2,tab2+3);
1049 DataArrayInt *da2=da->getIdsEqualList(&tab2V[0],&tab2V[0]+tab2V.size());
1050 CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfTuples());
1051 CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
1052 const int expected1[4]={1,3,4,6};
1053 CPPUNIT_ASSERT(std::equal(expected1,expected1+4,da2->getConstPointer()));
1058 void MEDCouplingBasicsTest3::testDAFromNoInterlace1()
1060 const int tab1[15]={1,11,21,31,41,2,12,22,32,42,3,13,23,33,43};
1061 DataArrayInt *da=DataArrayInt::New();
1063 std::copy(tab1,tab1+15,da->getPointer());
1064 DataArrayInt *da2=da->fromNoInterlace();
1065 const int expected1[15]={1,2,3,11,12,13,21,22,23,31,32,33,41,42,43};
1066 CPPUNIT_ASSERT_EQUAL(5,da2->getNumberOfTuples());
1067 CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
1068 CPPUNIT_ASSERT(std::equal(expected1,expected1+15,da2->getConstPointer()));
1069 DataArrayDouble *da3=da->convertToDblArr();
1070 DataArrayDouble *da4=da3->fromNoInterlace();
1071 CPPUNIT_ASSERT_EQUAL(5,da4->getNumberOfTuples());
1072 CPPUNIT_ASSERT_EQUAL(3,da4->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
1073 for(int i=0;i<15;i++)
1074 CPPUNIT_ASSERT_DOUBLES_EQUAL((double)expected1[i],da4->getIJ(0,i),1e-14);
1081 void MEDCouplingBasicsTest3::testDAToNoInterlace1()
1083 const int tab1[15]={1,2,3,11,12,13,21,22,23,31,32,33,41,42,43};
1084 DataArrayInt *da=DataArrayInt::New();
1086 std::copy(tab1,tab1+15,da->getPointer());
1087 DataArrayInt *da2=da->toNoInterlace();
1088 const int expected1[15]={1,11,21,31,41,2,12,22,32,42,3,13,23,33,43};
1089 CPPUNIT_ASSERT_EQUAL(5,da2->getNumberOfTuples());
1090 CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
1091 CPPUNIT_ASSERT(std::equal(expected1,expected1+15,da2->getConstPointer()));
1092 DataArrayDouble *da3=da->convertToDblArr();
1093 DataArrayDouble *da4=da3->toNoInterlace();
1094 CPPUNIT_ASSERT_EQUAL(5,da4->getNumberOfTuples());
1095 CPPUNIT_ASSERT_EQUAL(3,da4->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
1096 for(int i=0;i<15;i++)
1097 CPPUNIT_ASSERT_DOUBLES_EQUAL((double)expected1[i],da4->getIJ(0,i),1e-14);
1104 void MEDCouplingBasicsTest3::testDAIsUniform1()
1106 const int tab1[5]={1,1,1,1,1};
1107 DataArrayInt *da=DataArrayInt::New();
1109 std::copy(tab1,tab1+5,da->getPointer());
1110 CPPUNIT_ASSERT(da->isUniform(1));
1112 CPPUNIT_ASSERT(!da->isUniform(1));
1114 CPPUNIT_ASSERT(da->isUniform(1));
1115 DataArrayDouble *da2=da->convertToDblArr();
1116 CPPUNIT_ASSERT(da2->isUniform(1.,1e-12));
1117 da2->setIJ(1,0,1.+1.e-13);
1118 CPPUNIT_ASSERT(da2->isUniform(1.,1e-12));
1119 da2->setIJ(1,0,1.+1.e-11);
1120 CPPUNIT_ASSERT(!da2->isUniform(1.,1e-12));
1125 void MEDCouplingBasicsTest3::testDADFromPolarToCart1()
1127 const double tab1[4]={2.,0.2,2.5,0.7};
1128 DataArrayDouble *da=DataArrayDouble::New();
1130 std::copy(tab1,tab1+4,da->getPointer());
1131 DataArrayDouble *da2=da->fromPolarToCart();
1132 const double expected1[4]={1.9601331556824833,0.39733866159012243, 1.9121054682112213,1.6105442180942275};
1133 for(int i=0;i<4;i++)
1134 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da2->getIJ(0,i),1e-13);
1139 void MEDCouplingBasicsTest3::testDADFromCylToCart1()
1141 const double tab1[6]={2.,0.2,4.,2.5,0.7,9.};
1142 DataArrayDouble *da=DataArrayDouble::New();
1144 std::copy(tab1,tab1+6,da->getPointer());
1145 DataArrayDouble *da2=da->fromCylToCart();
1146 const double expected1[6]={1.9601331556824833,0.39733866159012243,4., 1.9121054682112213,1.6105442180942275,9.};
1147 for(int i=0;i<6;i++)
1148 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da2->getIJ(0,i),1e-13);
1153 void MEDCouplingBasicsTest3::testDADFromSpherToCart1()
1155 const double tab1[6]={2.,0.2,0.3,2.5,0.7,0.8};
1156 DataArrayDouble *da=DataArrayDouble::New();
1158 std::copy(tab1,tab1+6,da->getPointer());
1159 DataArrayDouble *da2=da->fromSpherToCart();
1160 const double expected1[6]={0.37959212195737485,0.11742160338765303,1.9601331556824833, 1.1220769624465328,1.1553337045129035,1.9121054682112213};
1161 for(int i=0;i<6;i++)
1162 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da2->getIJ(0,i),1e-13);
1167 void MEDCouplingBasicsTest3::testUnPolyze1()
1169 const int elts[8]={0,1,2,3,4,5,6,7};
1170 std::vector<int> eltsV(elts,elts+8);
1171 MEDCouplingUMesh *mesh=build3DTargetMesh_1();
1172 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
1174 MEDCouplingUMesh *mesh2=build3DTargetMesh_1();
1175 mesh->checkCoherency();
1176 CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12));
1177 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
1178 CPPUNIT_ASSERT(!mesh->isEqual(mesh2,1e-12));
1179 mesh->getNodalConnectivity()->setIJ(0,6,10);
1180 mesh->getNodalConnectivity()->setIJ(0,7,9);
1181 mesh->getNodalConnectivity()->setIJ(0,8,12);
1182 mesh->getNodalConnectivity()->setIJ(0,9,13);
1184 CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12));
1185 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
1186 mesh->getNodalConnectivity()->setIJ(0,6,12);
1187 mesh->getNodalConnectivity()->setIJ(0,7,13);
1188 mesh->getNodalConnectivity()->setIJ(0,8,10);
1189 mesh->getNodalConnectivity()->setIJ(0,9,9);
1191 CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12));
1192 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
1193 mesh->getNodalConnectivity()->setIJ(0,6,12);
1194 mesh->getNodalConnectivity()->setIJ(0,7,10);
1195 mesh->getNodalConnectivity()->setIJ(0,8,13);
1196 mesh->getNodalConnectivity()->setIJ(0,9,9);
1198 CPPUNIT_ASSERT(!mesh->isEqual(mesh2,1e-12));
1202 mesh=build2DTargetMesh_1();
1203 mesh2=build2DTargetMesh_1();
1205 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
1206 CPPUNIT_ASSERT(!mesh->isEqual(mesh2,1e-12));
1208 CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12));
1213 void MEDCouplingBasicsTest3::testConvertDegeneratedCells1()
1215 MEDCouplingUMesh *mesh=build3DTargetMesh_1();
1216 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};
1217 mesh->allocateCells(4);
1218 mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn);
1219 mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+8);
1220 mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+16);
1221 mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+24);
1222 mesh->finishInsertingCells();
1223 mesh->checkCoherency();
1224 CPPUNIT_ASSERT_EQUAL(4,mesh->getNumberOfCells());
1225 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh->getTypeOfCell(0));
1226 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh->getTypeOfCell(1));
1227 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh->getTypeOfCell(2));
1228 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh->getTypeOfCell(3));
1229 MEDCouplingFieldDouble *f1=mesh->getMeasureField(true);
1230 mesh->convertDegeneratedCells();
1231 mesh->checkCoherency();
1232 MEDCouplingFieldDouble *f2=mesh->getMeasureField(true);
1233 CPPUNIT_ASSERT_EQUAL(4,mesh->getNumberOfCells());
1234 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_PENTA6,mesh->getTypeOfCell(0));
1235 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_PYRA5,mesh->getTypeOfCell(1));
1236 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TETRA4,mesh->getTypeOfCell(2));
1237 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_PYRA5,mesh->getTypeOfCell(3));
1238 for(int i=0;i<4;i++)
1239 CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getArray()->getIJ(0,i),f2->getArray()->getIJ(0,i),1e-5);
1245 void MEDCouplingBasicsTest3::testGetNodeIdsNearPoints1()
1247 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
1248 DataArrayDouble *coords=mesh->getCoords();
1249 DataArrayDouble *tmp=DataArrayDouble::New();
1251 const double vals[6]={0.2,0.2,0.1,0.2,0.2,0.2};
1252 std::copy(vals,vals+6,tmp->getPointer());
1253 DataArrayDouble *tmp2=DataArrayDouble::Aggregate(coords,tmp);
1255 mesh->setCoords(tmp2);
1257 const double pts[6]={0.2,0.2,0.1,0.3,-0.3,0.7};
1258 std::vector<int> c=mesh->getNodeIdsNearPoint(pts,1e-7);
1259 CPPUNIT_ASSERT_EQUAL(3,(int)c.size());
1260 CPPUNIT_ASSERT_EQUAL(4,c[0]);
1261 CPPUNIT_ASSERT_EQUAL(9,c[1]);
1262 CPPUNIT_ASSERT_EQUAL(11,c[2]);
1264 std::vector<int> cI;
1265 mesh->getNodeIdsNearPoints(pts,3,1e-7,c,cI);
1266 CPPUNIT_ASSERT_EQUAL(4,(int)cI.size());
1267 CPPUNIT_ASSERT_EQUAL(4,(int)c.size());
1268 CPPUNIT_ASSERT_EQUAL(4,c[0]);
1269 CPPUNIT_ASSERT_EQUAL(9,c[1]);
1270 CPPUNIT_ASSERT_EQUAL(11,c[2]);
1271 CPPUNIT_ASSERT_EQUAL(6,c[3]);
1272 CPPUNIT_ASSERT_EQUAL(0,cI[0]);
1273 CPPUNIT_ASSERT_EQUAL(3,cI[1]);
1274 CPPUNIT_ASSERT_EQUAL(3,cI[2]);
1275 CPPUNIT_ASSERT_EQUAL(4,cI[3]);
1279 void MEDCouplingBasicsTest3::testFieldCopyTinyAttrFrom1()
1281 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1283 f1->setTimeTolerance(1.e-5);
1284 f1->setDescription("f1Desc");
1285 f1->setTime(1.23,4,5);
1286 MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1288 f2->setDescription("f2Desc");
1289 f2->setTime(6.78,9,10);
1290 f2->setTimeTolerance(4.556e-12);
1293 f1->copyTinyAttrFrom(f2);
1294 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.556e-12,f1->getTimeTolerance(),1e-24);
1295 CPPUNIT_ASSERT_DOUBLES_EQUAL(6.78,f1->getTime(dt,it),1e-12);
1296 CPPUNIT_ASSERT_EQUAL(9,dt);
1297 CPPUNIT_ASSERT_EQUAL(10,it);
1298 CPPUNIT_ASSERT(std::string(f1->getName())=="f1");//name unchanged
1299 CPPUNIT_ASSERT(std::string(f1->getDescription())=="f1Desc");//description unchanged
1303 f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1305 f1->setTimeTolerance(1.e-5);
1306 f1->setDescription("f1Desc");
1307 f2=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1309 f2->setDescription("f2Desc");
1310 f2->setTimeTolerance(4.556e-12);
1312 f1->copyTinyAttrFrom(f2);
1313 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.556e-12,f1->getTimeTolerance(),1e-24);
1314 CPPUNIT_ASSERT(std::string(f1->getName())=="f1");//name unchanged
1315 CPPUNIT_ASSERT(std::string(f1->getDescription())=="f1Desc");//description unchanged
1319 f1=MEDCouplingFieldDouble::New(ON_CELLS,CONST_ON_TIME_INTERVAL);
1321 f1->setTimeTolerance(1.e-5);
1322 f1->setDescription("f1Desc");
1323 f1->setTime(1.23,4,5);
1324 f1->setEndTime(5.43,2,1);
1325 f2=MEDCouplingFieldDouble::New(ON_CELLS,CONST_ON_TIME_INTERVAL);
1327 f2->setDescription("f2Desc");
1328 f2->setTimeTolerance(4.556e-12);
1329 f2->setTime(6.78,9,10);
1330 f2->setEndTime(10.98,7,6);
1332 f1->copyTinyAttrFrom(f2);
1333 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.556e-12,f1->getTimeTolerance(),1e-24);
1334 CPPUNIT_ASSERT(std::string(f1->getName())=="f1");//name unchanged
1335 CPPUNIT_ASSERT(std::string(f1->getDescription())=="f1Desc");//description unchanged
1336 CPPUNIT_ASSERT_DOUBLES_EQUAL(6.78,f1->getTime(dt,it),1e-12);
1337 CPPUNIT_ASSERT_EQUAL(9,dt);
1338 CPPUNIT_ASSERT_EQUAL(10,it);
1339 CPPUNIT_ASSERT_DOUBLES_EQUAL(10.98,f1->getEndTime(dt,it),1e-12);
1340 CPPUNIT_ASSERT_EQUAL(7,dt);
1341 CPPUNIT_ASSERT_EQUAL(6,it);
1345 f1=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
1347 f1->setTimeTolerance(1.e-5);
1348 f1->setDescription("f1Desc");
1349 f1->setTime(1.23,4,5);
1350 f1->setEndTime(5.43,2,1);
1351 f2=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
1353 f2->setDescription("f2Desc");
1354 f2->setTimeTolerance(4.556e-12);
1355 f2->setTime(6.78,9,10);
1356 f2->setEndTime(10.98,7,6);
1358 f1->copyTinyAttrFrom(f2);
1359 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.556e-12,f1->getTimeTolerance(),1e-24);
1360 CPPUNIT_ASSERT(std::string(f1->getName())=="f1");//name unchanged
1361 CPPUNIT_ASSERT(std::string(f1->getDescription())=="f1Desc");//description unchanged
1362 CPPUNIT_ASSERT_DOUBLES_EQUAL(6.78,f1->getTime(dt,it),1e-12);
1363 CPPUNIT_ASSERT_EQUAL(9,dt);
1364 CPPUNIT_ASSERT_EQUAL(10,it);
1365 CPPUNIT_ASSERT_DOUBLES_EQUAL(10.98,f1->getEndTime(dt,it),1e-12);
1366 CPPUNIT_ASSERT_EQUAL(7,dt);
1367 CPPUNIT_ASSERT_EQUAL(6,it);
1373 * 1D -> 2D extrusion with rotation
1375 void MEDCouplingBasicsTest3::testExtrudedMesh5()
1377 const double coo1[4]={0.,1.,2.,3.5};
1378 DataArrayDouble *a=DataArrayDouble::New();
1380 std::copy(coo1,coo1+4,a->getPointer());
1381 MEDCouplingCMesh *b=MEDCouplingCMesh::New();
1382 b->setCoordsAt(0,a);
1383 MEDCouplingUMesh *c=b->buildUnstructured();
1384 CPPUNIT_ASSERT_EQUAL(1,c->getSpaceDimension());
1385 c->changeSpaceDimension(2);
1387 DataArrayDouble *d=DataArrayDouble::New();
1390 MEDCouplingCMesh *e=MEDCouplingCMesh::New();
1391 e->setCoordsAt(0,d);
1392 MEDCouplingUMesh *f=e->buildUnstructured();
1393 DataArrayDouble *g=f->getCoords()->applyFunc(2,"3.5*IVec+x/6*3.14159265359*JVec");
1394 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 !
1395 DataArrayDouble *h=g->fromPolarToCart();
1397 MEDCouplingUMesh *i=c->buildExtrudedMesh(f,1);
1398 CPPUNIT_ASSERT_EQUAL(52,i->getNumberOfNodes());
1401 DataArrayInt *tmp=i->mergeNodes(1e-9,tmp2,tmp3);
1402 CPPUNIT_ASSERT(tmp2);
1403 CPPUNIT_ASSERT_EQUAL(37,tmp3);
1405 i->convertDegeneratedCells();
1406 i->checkCoherency();
1407 CPPUNIT_ASSERT_EQUAL(36,i->getNumberOfCells());
1408 CPPUNIT_ASSERT_EQUAL(37,i->getNumberOfNodes());
1409 CPPUNIT_ASSERT_EQUAL(12,i->getNumberOfCellsWithType(INTERP_KERNEL::NORM_TRI3));
1410 CPPUNIT_ASSERT_EQUAL(24,i->getNumberOfCellsWithType(INTERP_KERNEL::NORM_QUAD4));
1411 const double expected1[3]={0.25,0.75,2.0625};
1412 MEDCouplingFieldDouble *j=i->getMeasureField(true);
1413 for(int ii=0;ii<12;ii++)
1414 for(int k=0;k<3;k++)
1415 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[k],j->getIJ(0,ii*3+k),1e-10);
1416 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};
1417 DataArrayDouble *m=i->getBarycenterAndOwner();
1418 for(int ii=0;ii<72;ii++)
1419 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[ii],m->getIJ(0,ii),1e-10);
1435 * 1D -> 2D extrusion without rotation
1437 void MEDCouplingBasicsTest3::testExtrudedMesh6()
1439 const double coo1[4]={0.,1.,2.,3.5};
1440 DataArrayDouble *a=DataArrayDouble::New();
1442 std::copy(coo1,coo1+4,a->getPointer());
1443 MEDCouplingCMesh *b=MEDCouplingCMesh::New();
1444 b->setCoordsAt(0,a);
1445 MEDCouplingUMesh *c=b->buildUnstructured();
1446 CPPUNIT_ASSERT_EQUAL(1,c->getSpaceDimension());
1447 c->changeSpaceDimension(2);
1449 DataArrayDouble *d=DataArrayDouble::New();
1452 MEDCouplingCMesh *e=MEDCouplingCMesh::New();
1453 e->setCoordsAt(0,d);
1454 MEDCouplingUMesh *f=e->buildUnstructured();
1455 DataArrayDouble *d2=f->getCoords()->applyFunc("x*x/2");
1457 f->changeSpaceDimension(2);
1459 const double center[2]={0.,0.};
1460 f->rotate(center,0,M_PI/3);
1461 MEDCouplingUMesh *g=c->buildExtrudedMesh(f,0);
1462 g->checkCoherency();
1463 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 };
1464 MEDCouplingFieldDouble *f1=g->getMeasureField(true);
1465 for(int i=0;i<12;i++)
1466 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-12);
1468 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};
1469 DataArrayDouble *f2=g->getBarycenterAndOwner();
1470 for(int i=0;i<24;i++)
1471 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f2->getIJ(0,i),1e-12);
1486 * 2D -> 3D extrusion with rotation
1488 void MEDCouplingBasicsTest3::testExtrudedMesh7()
1490 const double coo1[4]={0.,1.,2.,3.5};
1491 DataArrayDouble *a=DataArrayDouble::New();
1493 std::copy(coo1,coo1+4,a->getPointer());
1494 MEDCouplingCMesh *b=MEDCouplingCMesh::New();
1495 b->setCoordsAt(0,a);
1496 MEDCouplingUMesh *c=b->buildUnstructured();
1497 CPPUNIT_ASSERT_EQUAL(1,c->getSpaceDimension());
1498 c->changeSpaceDimension(2);
1500 DataArrayDouble *d=DataArrayDouble::New();
1503 MEDCouplingCMesh *e=MEDCouplingCMesh::New();
1504 e->setCoordsAt(0,d);
1505 MEDCouplingUMesh *f=e->buildUnstructured();
1506 DataArrayDouble *g=f->getCoords()->applyFunc(2,"3.5*IVec+x/6*3.14159265359*JVec");
1507 DataArrayDouble *h=g->fromPolarToCart();
1509 MEDCouplingUMesh *i=c->buildExtrudedMesh(f,1);
1510 CPPUNIT_ASSERT_EQUAL(52,i->getNumberOfNodes());
1513 DataArrayInt *tmp=i->mergeNodes(1e-9,tmp2,tmp3);
1514 CPPUNIT_ASSERT(tmp2);
1515 CPPUNIT_ASSERT_EQUAL(37,tmp3);
1517 i->convertDegeneratedCells();
1518 const double vec1[3]={10.,0.,0.};
1520 DataArrayDouble *g2=h->applyFunc(3,"13.5/3.5*x*IVec+0*JVec+13.5/3.5*y*KVec");
1522 i->changeSpaceDimension(3);
1523 MEDCouplingUMesh *i3=i->buildExtrudedMesh(f,1);
1524 MEDCouplingFieldDouble *f2=i3->getMeasureField(true);
1525 tmp=i->mergeNodes(1e-9,tmp2,tmp3);
1526 CPPUNIT_ASSERT(tmp2);
1527 CPPUNIT_ASSERT_EQUAL(444,tmp3);
1529 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};
1531 for(int ii=0;ii<12;ii++)
1532 for(int jj=0;jj<36;jj++,kk++)
1533 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[jj],f2->getIJ(0,kk),1e-9);
1549 void MEDCouplingBasicsTest3::testSimplexize1()
1551 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1552 std::vector<int> v(1);
1554 m->convertToPolyTypes(&v[0],&v[0]+v.size());
1555 DataArrayInt *da=m->simplexize(0);
1556 CPPUNIT_ASSERT_EQUAL(7,da->getNumberOfTuples());
1557 CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfComponents());
1558 const int expected2[7]={0,0,1,2,3,4,4};
1559 for(int i=0;i<7;i++)
1560 CPPUNIT_ASSERT_EQUAL(expected2[i],da->getIJ(i,0));
1561 m->checkCoherency();
1562 CPPUNIT_ASSERT_EQUAL(7,m->getNumberOfCells());
1563 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(0));
1564 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(1));
1565 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(2));
1566 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(3));
1567 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYGON,m->getTypeOfCell(4));
1568 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(5));
1569 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(6));
1570 const double expected1[7]={0.125,0.125,0.125,0.125,0.25,0.125,0.125};
1571 MEDCouplingFieldDouble *f=m->getMeasureField(false);
1572 for(int i=0;i<7;i++)
1573 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i]*sqrt(2.),f->getIJ(i,0),1e-10);
1574 std::set<INTERP_KERNEL::NormalizedCellType> types=m->getAllTypes();
1575 CPPUNIT_ASSERT_EQUAL(2,(int)types.size());
1576 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*(types.begin()));
1577 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYGON,*(++(types.begin())));
1582 m=build3DSurfTargetMesh_1();
1584 m->convertToPolyTypes(&v[0],&v[0]+v.size());
1585 da=m->simplexize(1);
1586 CPPUNIT_ASSERT_EQUAL(7,da->getNumberOfTuples());
1587 CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfComponents());
1588 for(int i=0;i<7;i++)
1589 CPPUNIT_ASSERT_EQUAL(expected2[i],da->getIJ(i,0));
1590 m->checkCoherency();
1591 types=m->getAllTypes();
1592 CPPUNIT_ASSERT_EQUAL(2,(int)types.size());
1593 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*(types.begin()));
1594 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYGON,*(++(types.begin())));
1595 CPPUNIT_ASSERT_EQUAL(7,m->getNumberOfCells());
1596 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(0));
1597 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(1));
1598 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(2));
1599 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(3));
1600 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYGON,m->getTypeOfCell(4));
1601 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(5));
1602 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(6));
1603 f=m->getMeasureField(false);
1604 for(int i=0;i<7;i++)
1605 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i]*sqrt(2.),f->getIJ(i,0),1e-10);
1611 void MEDCouplingBasicsTest3::testSimplexize2()
1613 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1614 std::vector<int> v(1);
1616 m->convertToPolyTypes(&v[0],&v[0]+v.size());
1617 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1619 DataArrayDouble *arr=DataArrayDouble::New();
1620 const double arr1[10]={10.,110.,20.,120.,30.,130.,40.,140.,50.,150.};
1622 std::copy(arr1,arr1+10,arr->getPointer());
1626 f1->checkCoherency();
1627 CPPUNIT_ASSERT(f1->simplexize(0));
1628 f1->checkCoherency();
1629 const double expected1[14]={10.,110.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.,50.,150.};
1630 for(int i=0;i<14;i++)
1631 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-10);
1632 CPPUNIT_ASSERT(!f1->simplexize(0));
1633 for(int i=0;i<14;i++)
1634 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-10);
1640 void MEDCouplingBasicsTest3::testDAMeld1()
1642 DataArrayDouble *da1=DataArrayDouble::New();
1644 DataArrayDouble *da2=DataArrayDouble::New();
1647 da1->fillWithValue(7.);
1649 DataArrayDouble *da3=da2->applyFunc(3,"10*x*IVec+100*x*JVec+1000*x*KVec");
1651 da1->setInfoOnComponent(0,"c0da1");
1652 da1->setInfoOnComponent(1,"c1da1");
1653 da3->setInfoOnComponent(0,"c0da3");
1654 da3->setInfoOnComponent(1,"c1da3");
1655 da3->setInfoOnComponent(2,"c2da3");
1657 DataArrayDouble *da1C=da1->deepCpy();
1659 CPPUNIT_ASSERT_EQUAL(5,da1->getNumberOfComponents());
1660 CPPUNIT_ASSERT_EQUAL(7,da1->getNumberOfTuples());
1661 CPPUNIT_ASSERT(da1->getInfoOnComponent(0)=="c0da1");
1662 CPPUNIT_ASSERT(da1->getInfoOnComponent(1)=="c1da1");
1663 CPPUNIT_ASSERT(da1->getInfoOnComponent(2)=="c0da3");
1664 CPPUNIT_ASSERT(da1->getInfoOnComponent(3)=="c1da3");
1665 CPPUNIT_ASSERT(da1->getInfoOnComponent(4)=="c2da3");
1667 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.};
1668 for(int i=0;i<35;i++)
1669 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da1->getIJ(0,i),1e-10);
1671 DataArrayInt *dai1=da1C->convertToIntArr();
1672 DataArrayInt *dai3=da3->convertToIntArr();
1673 dai1->meldWith(dai3);
1674 CPPUNIT_ASSERT_EQUAL(5,dai1->getNumberOfComponents());
1675 CPPUNIT_ASSERT_EQUAL(7,dai1->getNumberOfTuples());
1676 CPPUNIT_ASSERT(dai1->getInfoOnComponent(0)=="c0da1");
1677 CPPUNIT_ASSERT(dai1->getInfoOnComponent(1)=="c1da1");
1678 CPPUNIT_ASSERT(dai1->getInfoOnComponent(2)=="c0da3");
1679 CPPUNIT_ASSERT(dai1->getInfoOnComponent(3)=="c1da3");
1680 CPPUNIT_ASSERT(dai1->getInfoOnComponent(4)=="c2da3");
1681 for(int i=0;i<35;i++)
1682 CPPUNIT_ASSERT_EQUAL((int)expected1[i],dai1->getIJ(0,i));
1683 // test of static method DataArrayDouble::meld
1684 DataArrayDouble *da4=DataArrayDouble::Meld(da1C,da3);
1685 CPPUNIT_ASSERT_EQUAL(5,da4->getNumberOfComponents());
1686 CPPUNIT_ASSERT_EQUAL(7,da4->getNumberOfTuples());
1687 CPPUNIT_ASSERT(da4->getInfoOnComponent(0)=="c0da1");
1688 CPPUNIT_ASSERT(da4->getInfoOnComponent(1)=="c1da1");
1689 CPPUNIT_ASSERT(da4->getInfoOnComponent(2)=="c0da3");
1690 CPPUNIT_ASSERT(da4->getInfoOnComponent(3)=="c1da3");
1691 CPPUNIT_ASSERT(da4->getInfoOnComponent(4)=="c2da3");
1692 for(int i=0;i<35;i++)
1693 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da4->getIJ(0,i),1e-10);
1694 // test of static method DataArrayInt::meld
1696 dai1=da1C->convertToIntArr();
1697 DataArrayInt *dai4=DataArrayInt::Meld(dai1,dai3);
1698 CPPUNIT_ASSERT_EQUAL(5,dai4->getNumberOfComponents());
1699 CPPUNIT_ASSERT_EQUAL(7,dai4->getNumberOfTuples());
1700 CPPUNIT_ASSERT(dai4->getInfoOnComponent(0)=="c0da1");
1701 CPPUNIT_ASSERT(dai4->getInfoOnComponent(1)=="c1da1");
1702 CPPUNIT_ASSERT(dai4->getInfoOnComponent(2)=="c0da3");
1703 CPPUNIT_ASSERT(dai4->getInfoOnComponent(3)=="c1da3");
1704 CPPUNIT_ASSERT(dai4->getInfoOnComponent(4)=="c2da3");
1705 for(int i=0;i<35;i++)
1706 CPPUNIT_ASSERT_EQUAL((int)expected1[i],dai4->getIJ(0,i));
1718 void MEDCouplingBasicsTest3::testFieldMeld1()
1720 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1721 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1723 DataArrayDouble *da1=DataArrayDouble::New();
1724 const double arr1[5]={12.,23.,34.,45.,56.};
1726 std::copy(arr1,arr1+5,da1->getPointer());
1727 da1->setInfoOnComponent(0,"aaa");
1729 f1->setTime(3.4,2,1);
1730 f1->checkCoherency();
1732 MEDCouplingFieldDouble *f2=f1->deepCpy();
1733 f2->setMesh(f1->getMesh());
1734 f2->checkCoherency();
1735 f2->changeNbOfComponents(2,5.);
1737 f2->getArray()->setInfoOnComponent(0,"bbb");
1738 f2->getArray()->setInfoOnComponent(1,"ccc");
1739 f2->checkCoherency();
1741 MEDCouplingFieldDouble *f3=MEDCouplingFieldDouble::MeldFields(f2,f1);
1742 f3->checkCoherency();
1743 CPPUNIT_ASSERT_EQUAL(5,f3->getNumberOfTuples());
1744 CPPUNIT_ASSERT_EQUAL(3,f3->getNumberOfComponents());
1745 CPPUNIT_ASSERT(f3->getArray()->getInfoOnComponent(0)=="bbb");
1746 CPPUNIT_ASSERT(f3->getArray()->getInfoOnComponent(1)=="ccc");
1747 CPPUNIT_ASSERT(f3->getArray()->getInfoOnComponent(2)=="aaa");
1748 const double expected1[15]={5.,5.,12.,5.,5.,23.,5.,5.,34.,5.,5.,45.,5.,5.,56.};
1749 for(int i=0;i<15;i++)
1750 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f3->getIJ(0,i),1e-12);
1752 double time=f3->getTime(dt,it);
1753 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.4,time,1e-14);
1754 CPPUNIT_ASSERT_EQUAL(2,dt);
1755 CPPUNIT_ASSERT_EQUAL(1,it);
1757 MEDCouplingFieldDouble *f4=f2->buildNewTimeReprFromThis(NO_TIME,false);
1758 MEDCouplingFieldDouble *f5=f1->buildNewTimeReprFromThis(NO_TIME,false);
1759 MEDCouplingFieldDouble *f6=MEDCouplingFieldDouble::MeldFields(f4,f5);
1760 f6->checkCoherency();
1761 CPPUNIT_ASSERT_EQUAL(5,f6->getNumberOfTuples());
1762 CPPUNIT_ASSERT_EQUAL(3,f6->getNumberOfComponents());
1763 CPPUNIT_ASSERT(f6->getArray()->getInfoOnComponent(0)=="bbb");
1764 CPPUNIT_ASSERT(f6->getArray()->getInfoOnComponent(1)=="ccc");
1765 CPPUNIT_ASSERT(f6->getArray()->getInfoOnComponent(2)=="aaa");
1766 for(int i=0;i<15;i++)
1767 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f6->getIJ(0,i),1e-12);
1779 void MEDCouplingBasicsTest3::testMergeNodes2()
1781 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1782 MEDCouplingUMesh *m2=build2DTargetMesh_1();
1783 const double vec[2]={0.002,0.};
1786 std::vector<const MEDCouplingUMesh *> tmp(2);
1789 MEDCouplingUMesh *m3=MEDCouplingUMesh::MergeUMeshes(tmp);
1792 DataArrayInt *da=m3->mergeNodes2(0.01,b,newNbOfNodes);
1793 CPPUNIT_ASSERT_EQUAL(9,m3->getNumberOfNodes());
1794 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};
1795 for(int i=0;i<18;i++)
1796 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],m3->getCoords()->getIJ(0,i),1e-13);
1804 void MEDCouplingBasicsTest3::testMergeField2()
1806 MEDCouplingUMesh *m=build2DTargetMesh_1();
1807 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1809 DataArrayDouble *arr=DataArrayDouble::New();
1811 arr->fillWithValue(2.);
1814 MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1816 arr=DataArrayDouble::New();
1818 arr->fillWithValue(5.);
1821 MEDCouplingFieldDouble *f3=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1823 arr=DataArrayDouble::New();
1825 arr->fillWithValue(7.);
1829 std::vector<const MEDCouplingFieldDouble *> tmp(3);
1830 tmp[0]=f1; tmp[1]=f2; tmp[2]=f3;
1831 MEDCouplingFieldDouble *f4=MEDCouplingFieldDouble::MergeFields(tmp);
1832 CPPUNIT_ASSERT_EQUAL(15,f4->getMesh()->getNumberOfCells());
1833 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.};
1834 for(int i=0;i<30;i++)
1835 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f4->getIJ(0,i),1.e-13);
1844 void MEDCouplingBasicsTest3::testDAIBuildComplement1()
1846 DataArrayInt *a=DataArrayInt::New();
1847 const int tab[4]={3,1,7,8};
1849 std::copy(tab,tab+4,a->getPointer());
1850 DataArrayInt *b=a->buildComplement(12);
1851 CPPUNIT_ASSERT_EQUAL(8,b->getNumberOfTuples());
1852 CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents());
1853 const int expected1[8]={0,2,4,5,6,9,10,11};
1854 for(int i=0;i<8;i++)
1855 CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
1860 void MEDCouplingBasicsTest3::testDAIBuildUnion1()
1862 DataArrayInt *a=DataArrayInt::New();
1863 const int tab1[4]={3,1,7,8};
1865 std::copy(tab1,tab1+4,a->getPointer());
1866 DataArrayInt *c=DataArrayInt::New();
1867 const int tab2[5]={5,3,0,18,8};
1869 std::copy(tab2,tab2+5,c->getPointer());
1870 DataArrayInt *b=a->buildUnion(c);
1871 CPPUNIT_ASSERT_EQUAL(7,b->getNumberOfTuples());
1872 CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents());
1873 const int expected1[7]={0,1,3,5,7,8,18};
1874 for(int i=0;i<7;i++)
1875 CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
1881 void MEDCouplingBasicsTest3::testDAIBuildIntersection1()
1883 DataArrayInt *a=DataArrayInt::New();
1884 const int tab1[4]={3,1,7,8};
1886 std::copy(tab1,tab1+4,a->getPointer());
1887 DataArrayInt *c=DataArrayInt::New();
1888 const int tab2[5]={5,3,0,18,8};
1890 std::copy(tab2,tab2+5,c->getPointer());
1891 DataArrayInt *b=a->buildIntersection(c);
1892 CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfTuples());
1893 CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents());
1894 const int expected1[2]={3,8};
1895 for(int i=0;i<2;i++)
1896 CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
1902 void MEDCouplingBasicsTest3::testDAIDeltaShiftIndex1()
1904 DataArrayInt *a=DataArrayInt::New();
1905 const int tab[7]={1,3,6,7,7,9,15};
1907 std::copy(tab,tab+7,a->getPointer());
1908 DataArrayInt *b=a->deltaShiftIndex();
1909 CPPUNIT_ASSERT_EQUAL(6,b->getNumberOfTuples());
1910 CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents());
1911 const int expected1[6]={2,3,1,0,2,6};
1912 for(int i=0;i<6;i++)
1913 CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
1918 void MEDCouplingBasicsTest3::testDaDoubleSelectByTupleIdSafe1()
1920 DataArrayDouble *a=DataArrayDouble::New();
1922 a->setInfoOnComponent(0,"toto");
1923 a->setInfoOnComponent(1,"tata");
1924 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};
1925 std::copy(arr1,arr1+14,a->getPointer());
1927 const int arr2[7]={4,2,0,6,5};
1928 DataArrayDouble *b=a->selectByTupleIdSafe(arr2,arr2+5);
1929 CPPUNIT_ASSERT_EQUAL(5,b->getNumberOfTuples());
1930 CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
1931 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
1932 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
1933 const double expected1[10]={5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1};
1934 for(int i=0;i<10;i++)
1935 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
1936 const int arr4[5]={4,-1,0,6,5};
1937 CPPUNIT_ASSERT_THROW(a->selectByTupleIdSafe(arr4,arr4+5),INTERP_KERNEL::Exception);
1938 const int arr5[5]={4,2,0,6,7};
1939 CPPUNIT_ASSERT_THROW(a->selectByTupleIdSafe(arr5,arr5+5),INTERP_KERNEL::Exception);
1943 DataArrayInt *c=DataArrayInt::New();
1945 c->setInfoOnComponent(0,"toto");
1946 c->setInfoOnComponent(1,"tata");
1947 const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
1948 std::copy(arr3,arr3+14,c->getPointer());
1949 DataArrayInt *d=c->selectByTupleIdSafe(arr2,arr2+5);
1950 CPPUNIT_ASSERT_EQUAL(5,d->getNumberOfTuples());
1951 CPPUNIT_ASSERT_EQUAL(2,d->getNumberOfComponents());
1952 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
1953 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
1954 const int expected2[10]={5,15,3,13,1,11,7,17,6,16};
1955 for(int i=0;i<10;i++)
1956 CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
1957 CPPUNIT_ASSERT_THROW(c->selectByTupleIdSafe(arr4,arr4+5),INTERP_KERNEL::Exception);
1958 CPPUNIT_ASSERT_THROW(c->selectByTupleIdSafe(arr5,arr5+5),INTERP_KERNEL::Exception);
1963 void MEDCouplingBasicsTest3::testAreCellsIncludedIn1()
1965 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1966 const int pt[2]={1,3};
1967 MEDCouplingUMesh *m2=(MEDCouplingUMesh *)m->buildPartOfMySelf(pt,pt+2,true);
1969 CPPUNIT_ASSERT(m->areCellsIncludedIn(m2,0,tmp));
1970 CPPUNIT_ASSERT_EQUAL(2,tmp->getNumberOfTuples());
1971 CPPUNIT_ASSERT_EQUAL(1,tmp->getNumberOfComponents());
1972 CPPUNIT_ASSERT_EQUAL(pt[0],tmp->getIJ(0,0));
1973 CPPUNIT_ASSERT_EQUAL(pt[1],tmp->getIJ(0,1));
1975 CPPUNIT_ASSERT(!m2->areCellsIncludedIn(m,0,tmp));
1981 void MEDCouplingBasicsTest3::testDAIBuildSubstraction1()
1983 DataArrayInt *a=DataArrayInt::New();
1984 const int aa[]={2,3,6,8,9};
1986 std::copy(aa,aa+5,a->getPointer());
1987 DataArrayInt *b=DataArrayInt::New();
1988 const int bb[]={1,3,5,9,11};
1990 std::copy(bb,bb+5,b->getPointer());
1992 DataArrayInt *c=a->buildSubstraction(b);
1993 CPPUNIT_ASSERT_EQUAL(3,c->getNumberOfTuples());
1994 CPPUNIT_ASSERT_EQUAL(1,c->getNumberOfComponents());
1995 const int expected1[3]={2,6,8};
1996 CPPUNIT_ASSERT(std::equal(expected1,expected1+3,c->getConstPointer()));
2003 void MEDCouplingBasicsTest3::testBuildOrthogonalField2()
2005 MEDCouplingUMesh *m=build2DTargetMesh_1();
2006 DataArrayInt *d1=DataArrayInt::New();
2007 DataArrayInt *d2=DataArrayInt::New();
2008 DataArrayInt *d3=DataArrayInt::New();
2009 DataArrayInt *d4=DataArrayInt::New();
2010 MEDCouplingUMesh *m1=m->buildDescendingConnectivity(d1,d2,d3,d4);
2012 MEDCouplingFieldDouble *f1=m1->buildOrthogonalField();
2013 DataArrayDouble *da1=f1->getArray();
2014 CPPUNIT_ASSERT_EQUAL(2,da1->getNumberOfComponents());
2015 CPPUNIT_ASSERT_EQUAL(13,da1->getNumberOfTuples());
2017 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.};
2018 for(int i=0;i<26;i++)
2019 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da1->getIJ(0,i),1e-14);
2030 void MEDCouplingBasicsTest3::testUMInsertNextCell1()
2032 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 };
2033 int targetConn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
2034 MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
2035 targetMesh->allocateCells(5);
2036 CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn),INTERP_KERNEL::Exception);
2037 targetMesh->setMeshDimension(2);
2038 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn);
2039 CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_TETRA4,4,targetConn),INTERP_KERNEL::Exception);
2040 CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,targetConn),INTERP_KERNEL::Exception);
2041 CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn),INTERP_KERNEL::Exception);
2042 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+4);
2043 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+7);
2044 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+10);
2045 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+14);
2046 targetMesh->finishInsertingCells();
2047 DataArrayDouble *myCoords=DataArrayDouble::New();
2048 myCoords->alloc(9,2);
2049 std::copy(targetCoords,targetCoords+18,myCoords->getPointer());
2050 targetMesh->setCoords(myCoords);
2051 myCoords->decrRef();
2052 targetMesh->checkCoherency();
2053 targetMesh->decrRef();
2056 void MEDCouplingBasicsTest3::testFieldOperatorDivDiffComp1()
2058 MEDCouplingUMesh *m=build2DTargetMesh_1();
2059 DataArrayInt *d1=DataArrayInt::New();
2060 DataArrayInt *d2=DataArrayInt::New();
2061 DataArrayInt *d3=DataArrayInt::New();
2062 DataArrayInt *d4=DataArrayInt::New();
2063 MEDCouplingUMesh *m1=m->buildDescendingConnectivity(d1,d2,d3,d4);
2065 MEDCouplingFieldDouble *f1=m1->buildOrthogonalField();
2066 const double arr1[13]={2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.};
2067 DataArrayDouble *arr=DataArrayDouble::New();
2069 std::copy(arr1,arr1+13,arr->getPointer());
2070 MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS);
2073 f2->checkCoherency();
2075 MEDCouplingFieldDouble *f3=(*f1)/(*f2);
2076 CPPUNIT_ASSERT_THROW((*f2)/(*f1),INTERP_KERNEL::Exception);
2077 f3->checkCoherency();
2079 CPPUNIT_ASSERT(f1->isEqual(f3,1e-10,1e-10));
2080 CPPUNIT_ASSERT_THROW((*f2)/=(*f1),INTERP_KERNEL::Exception);
2081 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};
2082 for(int i=0;i<26;i++)
2083 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f3->getIJ(0,i),1e-10);
2097 void MEDCouplingBasicsTest3::testDARearrange1()
2099 DataArrayInt *da1=DataArrayInt::New();
2102 const int *ptr=da1->getConstPointer();
2104 CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems());
2105 CPPUNIT_ASSERT_EQUAL(1,da1->getNumberOfComponents());
2106 CPPUNIT_ASSERT_EQUAL(12,da1->getNumberOfTuples());
2108 CPPUNIT_ASSERT(ptr==da1->getConstPointer());
2109 CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems());
2110 CPPUNIT_ASSERT_EQUAL(4,da1->getNumberOfComponents());
2111 CPPUNIT_ASSERT_EQUAL(3,da1->getNumberOfTuples());
2112 for(int i=0;i<12;i++)
2113 CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
2116 CPPUNIT_ASSERT(ptr==da1->getConstPointer());
2117 CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems());
2118 CPPUNIT_ASSERT_EQUAL(6,da1->getNumberOfComponents());
2119 CPPUNIT_ASSERT_EQUAL(2,da1->getNumberOfTuples());
2120 for(int i=0;i<12;i++)
2121 CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
2123 CPPUNIT_ASSERT_THROW(da1->rearrange(7),INTERP_KERNEL::Exception);
2126 CPPUNIT_ASSERT(ptr==da1->getConstPointer());
2127 CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems());
2128 CPPUNIT_ASSERT_EQUAL(12,da1->getNumberOfComponents());
2129 CPPUNIT_ASSERT_EQUAL(1,da1->getNumberOfTuples());
2130 for(int i=0;i<12;i++)
2131 CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
2134 CPPUNIT_ASSERT(ptr==da1->getConstPointer());
2135 CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems());
2136 CPPUNIT_ASSERT_EQUAL(3,da1->getNumberOfComponents());
2137 CPPUNIT_ASSERT_EQUAL(4,da1->getNumberOfTuples());
2138 for(int i=0;i<12;i++)
2139 CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
2141 DataArrayDouble *da2=da1->convertToDblArr();
2143 const double *ptr2=da2->getConstPointer();
2145 CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems());
2146 CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfComponents());
2147 CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfTuples());
2149 CPPUNIT_ASSERT(ptr2==da2->getConstPointer());
2150 CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems());
2151 CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfComponents());
2152 CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfTuples());
2153 for(int i=0;i<12;i++)
2154 CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
2157 CPPUNIT_ASSERT(ptr2==da2->getConstPointer());
2158 CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems());
2159 CPPUNIT_ASSERT_EQUAL(6,da2->getNumberOfComponents());
2160 CPPUNIT_ASSERT_EQUAL(2,da2->getNumberOfTuples());
2161 for(int i=0;i<12;i++)
2162 CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
2164 CPPUNIT_ASSERT_THROW(da2->rearrange(7),INTERP_KERNEL::Exception);
2167 CPPUNIT_ASSERT(ptr2==da2->getConstPointer());
2168 CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems());
2169 CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
2170 CPPUNIT_ASSERT_EQUAL(12,da2->getNumberOfTuples());
2171 for(int i=0;i<12;i++)
2172 CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
2175 CPPUNIT_ASSERT(ptr2==da2->getConstPointer());
2176 CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems());
2177 CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfComponents());
2178 CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfTuples());
2179 for(int i=0;i<12;i++)
2180 CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
2184 void MEDCouplingBasicsTest3::testGetDifferentValues1()
2186 DataArrayInt *da1=DataArrayInt::New();
2187 const int arr[12]={1,2,3,2,2,3,5,1,5,5,2,2};
2189 std::copy(arr,arr+12,da1->getPointer());
2190 std::set<int> s=da1->getDifferentValues();
2191 const int expected1[4]={1,2,3,5};
2192 CPPUNIT_ASSERT_EQUAL(4,(int)s.size());
2193 CPPUNIT_ASSERT(std::equal(expected1,expected1+4,s.begin()));
2197 void MEDCouplingBasicsTest3::testDAIBuildPermutationArr1()
2199 DataArrayInt *a=DataArrayInt::New();
2200 const int vala[5]={4,5,6,7,8};
2202 std::copy(vala,vala+5,a->getPointer());
2203 DataArrayInt *b=DataArrayInt::New();
2204 const int valb[5]={5,4,8,6,7};
2206 std::copy(valb,valb+5,b->getPointer());
2207 DataArrayInt *c=a->buildPermutationArr(*b);
2208 const int expect1[5]={1,0,4,2,3};
2209 CPPUNIT_ASSERT_EQUAL(5,c->getNumberOfTuples());
2210 CPPUNIT_ASSERT_EQUAL(1,c->getNumberOfComponents());
2211 CPPUNIT_ASSERT(std::equal(expect1,expect1+5,c->getConstPointer()));
2212 CPPUNIT_ASSERT(a->isEqualWithoutConsideringStrAndOrder(*b));
2214 CPPUNIT_ASSERT(!a->isEqualWithoutConsideringStrAndOrder(*b));
2215 CPPUNIT_ASSERT_THROW(a->buildPermutationArr(*b),INTERP_KERNEL::Exception);
2218 b->setIJ(4,0,4);//;a==[4,5,6,4,8] and b==[5,4,8,6,4]
2219 CPPUNIT_ASSERT(a->isEqualWithoutConsideringStrAndOrder(*b));
2221 c=a->buildPermutationArr(*b);
2222 const int expect2[5]={1,3,4,2,3};
2223 CPPUNIT_ASSERT(std::equal(expect2,expect2+5,c->getConstPointer()));
2224 DataArrayDouble *d=b->convertToDblArr();
2226 const int expect3[5]={4,4,5,6,8};
2227 CPPUNIT_ASSERT(std::equal(expect3,expect3+5,b->getConstPointer()));
2229 CPPUNIT_ASSERT_EQUAL(5,d->getNumberOfTuples());
2230 CPPUNIT_ASSERT_EQUAL(1,d->getNumberOfComponents());
2231 for(int i=0;i<5;i++)
2232 CPPUNIT_ASSERT_DOUBLES_EQUAL(double(expect3[i]),d->getIJ(i,0),1e-14);
2240 void MEDCouplingBasicsTest3::testAreCellsIncludedIn2()
2242 const char myName[]="Vitoo";
2243 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
2244 MEDCouplingUMesh *m2=(MEDCouplingUMesh *)m->buildPartOfMySelf(0,0,true);
2245 CPPUNIT_ASSERT_EQUAL(0,m2->getNumberOfCells());
2246 CPPUNIT_ASSERT_EQUAL(3,m2->getSpaceDimension());
2247 CPPUNIT_ASSERT_EQUAL(2,m2->getMeshDimension());
2248 m2->setName(myName);
2250 CPPUNIT_ASSERT(m->areCellsIncludedIn(m2,0,tmp));
2251 CPPUNIT_ASSERT(std::string(myName)==tmp->getName());
2252 CPPUNIT_ASSERT_EQUAL(0,tmp->getNumberOfTuples());
2253 CPPUNIT_ASSERT_EQUAL(1,tmp->getNumberOfComponents());
2259 void MEDCouplingBasicsTest3::testUMeshGetPartBarycenterAndOwner1()
2261 MEDCouplingUMesh *m1=build2DTargetMesh_1();
2262 const int part[3]={1,0,4};
2263 DataArrayDouble *b=m1->getPartBarycenterAndOwner(part,part+3);
2264 CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
2265 CPPUNIT_ASSERT_EQUAL(3,b->getNumberOfTuples());
2266 const double expected1[6]={0.36666666666666665,-0.13333333333333333,-0.05,-0.05,0.45,0.45};
2267 for(int i=0;i<6;i++)
2268 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
2273 void MEDCouplingBasicsTest3::testUMeshGetPartMeasureField1()
2275 MEDCouplingUMesh *m1=build2DTargetMesh_1();
2276 const int part[3]={1,0,4};
2277 DataArrayDouble *b=m1->getPartMeasureField(true,part,part+3);
2278 CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents());
2279 CPPUNIT_ASSERT_EQUAL(3,b->getNumberOfTuples());
2280 const double expected1[3]={0.125,0.25,0.25};
2281 for(int i=0;i<3;i++)
2282 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
2287 void MEDCouplingBasicsTest3::testUMeshBuildPartOrthogonalField1()
2289 MEDCouplingUMesh *m1=build2DTargetMesh_1();
2290 m1->changeSpaceDimension(3);
2291 const int part[3]={1,0,4};
2292 MEDCouplingFieldDouble *b=m1->buildPartOrthogonalField(part,part+3);
2293 CPPUNIT_ASSERT_EQUAL(3,b->getArray()->getNumberOfComponents());
2294 CPPUNIT_ASSERT_EQUAL(3,b->getArray()->getNumberOfTuples());
2295 const double expected1[9]={0.,0.,-1.,0.,0.,-1.,0.,0.,-1.};
2296 for(int i=0;i<9;i++)
2297 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getArray()->getIJ(0,i),1e-14);
2302 void MEDCouplingBasicsTest3::testUMeshGetTypesOfPart1()
2304 MEDCouplingUMesh *m1=build2DTargetMesh_1();
2305 const int part1[]={0,3,4};
2306 std::set<INTERP_KERNEL::NormalizedCellType> s;
2307 s=m1->getTypesOfPart(part1,part1+3);
2308 CPPUNIT_ASSERT(s.size()==1);
2309 CPPUNIT_ASSERT(*s.begin()==INTERP_KERNEL::NORM_QUAD4);
2310 const int part2[]={2,2,2,1};
2311 s=m1->getTypesOfPart(part2,part2+4);
2312 CPPUNIT_ASSERT(s.size()==1);
2313 CPPUNIT_ASSERT(*s.begin()==INTERP_KERNEL::NORM_TRI3);
2314 const int part3[]={3,2,1};
2315 s=m1->getTypesOfPart(part3,part3+3);
2316 CPPUNIT_ASSERT(s.size()==2);
2317 CPPUNIT_ASSERT(*s.begin()==INTERP_KERNEL::NORM_TRI3);
2318 CPPUNIT_ASSERT(*(++s.begin())==INTERP_KERNEL::NORM_QUAD4);
2322 void MEDCouplingBasicsTest3::testUMeshKeepCellIdsByType1()
2324 MEDCouplingUMesh *m1=build2DTargetMesh_1();
2325 const int part1[3]={0,3,4};
2326 DataArrayInt *a=m1->keepCellIdsByType(INTERP_KERNEL::NORM_TRI3,part1,part1+3);
2327 CPPUNIT_ASSERT_EQUAL(1,a->getNumberOfComponents());
2328 CPPUNIT_ASSERT_EQUAL(0,a->getNumberOfTuples());
2331 const int part2[5]={3,2,0,2,4};
2332 a=m1->keepCellIdsByType(INTERP_KERNEL::NORM_TRI3,part2,part2+5);
2333 CPPUNIT_ASSERT_EQUAL(1,a->getNumberOfComponents());
2334 CPPUNIT_ASSERT_EQUAL(2,a->getNumberOfTuples());
2335 CPPUNIT_ASSERT_EQUAL(2,a->getIJ(0,0));
2336 CPPUNIT_ASSERT_EQUAL(2,a->getIJ(1,0));
2339 a=m1->keepCellIdsByType(INTERP_KERNEL::NORM_QUAD4,part2,part2+5);
2340 CPPUNIT_ASSERT_EQUAL(1,a->getNumberOfComponents());
2341 CPPUNIT_ASSERT_EQUAL(3,a->getNumberOfTuples());
2342 CPPUNIT_ASSERT_EQUAL(3,a->getIJ(0,0));
2343 CPPUNIT_ASSERT_EQUAL(0,a->getIJ(1,0));
2344 CPPUNIT_ASSERT_EQUAL(4,a->getIJ(2,0));
2350 void MEDCouplingBasicsTest3::testDAIAggregateMulti1()
2352 DataArrayInt *a=DataArrayInt::New();
2357 DataArrayInt *b=DataArrayInt::New();
2363 std::vector<const DataArrayInt *> v(2);
2365 DataArrayInt *c=DataArrayInt::Aggregate(v);
2366 CPPUNIT_ASSERT_EQUAL(5,c->getNumberOfTuples());
2367 CPPUNIT_ASSERT_EQUAL(2,c->getNumberOfComponents());
2368 CPPUNIT_ASSERT(c->getName()=="aa");
2369 const int expect1[10]={0,1,2,3,0,1,2,3,4,5};
2370 for(int i=0;i<10;i++)
2371 CPPUNIT_ASSERT_EQUAL(expect1[i],c->getIJ(0,i));
2378 void MEDCouplingBasicsTest3::testMergeUMeshes2()
2380 MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
2381 MEDCouplingUMesh *m2=build3DSurfTargetMesh_1();
2382 MEDCouplingUMesh *m3=build3DSurfTargetMesh_1();
2384 const int vec1[3]={0,2,3};
2385 MEDCouplingUMesh *m2_2=(MEDCouplingUMesh *)m2->buildPartOfMySelf(vec1,vec1+3,false);
2386 const int vec2[2]={1,1};
2387 MEDCouplingUMesh *m3_2=(MEDCouplingUMesh *)m3->buildPartOfMySelf(vec2,vec2+2,false);
2389 std::vector<const MEDCouplingUMesh *> ms(3);
2390 std::vector<const MEDCouplingMesh *> ms2(3);
2391 ms[0]=m1; ms[1]=m2_2; ms[2]=m3_2;
2392 ms2[0]=m1; ms2[1]=m2_2; ms2[2]=m3_2;
2394 MEDCouplingUMesh *m4=MEDCouplingUMesh::MergeUMeshes(ms);
2395 m4->checkCoherency();
2396 CPPUNIT_ASSERT_EQUAL(10,m4->getNumberOfCells());
2397 CPPUNIT_ASSERT_EQUAL(20,m4->getNumberOfNodes());
2398 CPPUNIT_ASSERT_EQUAL(45,m4->getMeshLength());
2400 MEDCouplingMesh *m4bis=MEDCouplingMesh::MergeMeshes(ms2);
2401 CPPUNIT_ASSERT(m4->isEqual(m4bis,1e-12));
2404 const int vec3[5]={0,1,2,3,4};
2405 MEDCouplingUMesh *m4_1=(MEDCouplingUMesh *)m4->buildPartOfMySelf(vec3,vec3+5,false);
2406 m4_1->setName(m1->getName());
2407 CPPUNIT_ASSERT(m4_1->isEqual(m1,1e-12));
2410 const int vec4[3]={5,6,7};
2411 MEDCouplingUMesh *m4_2=(MEDCouplingUMesh *)m4->buildPartOfMySelf(vec4,vec4+3,false);
2412 DataArrayInt *cellCor=0;
2413 DataArrayInt *nodeCor=0;
2414 m4_2->checkGeoEquivalWith(m2_2,10,1e-12,cellCor,nodeCor);
2415 CPPUNIT_ASSERT(cellCor==0);
2416 CPPUNIT_ASSERT(nodeCor==0);
2419 const int vec5[2]={8,9};
2420 MEDCouplingUMesh *m4_3=(MEDCouplingUMesh *)m4->buildPartOfMySelf(vec5,vec5+2,false);
2421 CPPUNIT_ASSERT_EQUAL(2,m4_3->getNumberOfCells());
2422 CPPUNIT_ASSERT_EQUAL(3,m4_3->getNumberOfNodes());
2424 m4_3->setName(m3_2->getName());
2425 CPPUNIT_ASSERT(m4_3->isEqual(m3_2,1e-12));
2436 void MEDCouplingBasicsTest3::testBuild0DMeshFromCoords1()
2438 const double sourceCoords[12]={-0.3,-0.3,0., 0.7,-0.3,0., -0.3,0.7,0., 0.7,0.7,0.};
2439 DataArrayDouble *coo=DataArrayDouble::New();
2441 coo->setName("My0D");
2442 std::copy(sourceCoords,sourceCoords+12,coo->getPointer());
2443 MEDCouplingUMesh *m=MEDCouplingUMesh::Build0DMeshFromCoords(coo);
2444 m->checkCoherency();
2445 CPPUNIT_ASSERT_EQUAL(4,m->getNumberOfNodes());
2446 CPPUNIT_ASSERT_EQUAL(4,m->getNumberOfCells());
2447 CPPUNIT_ASSERT_EQUAL(3,m->getSpaceDimension());
2448 CPPUNIT_ASSERT_EQUAL(0,m->getMeshDimension());
2449 const std::set<INTERP_KERNEL::NormalizedCellType>& types=m->getAllTypes();
2450 CPPUNIT_ASSERT_EQUAL(1,(int)types.size());
2451 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POINT1,*types.begin());
2452 for(int i=0;i<4;i++)
2454 std::vector<int> conn;
2455 m->getNodeIdsOfCell(i,conn);
2456 CPPUNIT_ASSERT_EQUAL(1,(int)conn.size());
2457 CPPUNIT_ASSERT_EQUAL(i,conn[0]);
2458 CPPUNIT_ASSERT(INTERP_KERNEL::NORM_POINT1==m->getTypeOfCell(i));
2460 CPPUNIT_ASSERT(std::string(m->getName())=="My0D");