1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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
19 // Author : Anthony Geay (CEA/DEN)
21 #include "MEDCouplingBasicsTest3.hxx"
22 #include "MEDCouplingUMesh.hxx"
23 #include "MEDCouplingCMesh.hxx"
24 #include "MEDCouplingMappedExtrudedMesh.hxx"
25 #include "MEDCouplingFieldDouble.hxx"
26 #include "MEDCouplingMemArray.hxx"
27 #include "MEDCouplingGaussLocalization.hxx"
33 using namespace MEDCoupling;
35 void MEDCouplingBasicsTest3::testGetMeasureFieldCMesh1()
37 MEDCouplingCMesh *m=MEDCouplingCMesh::New();
38 DataArrayDouble *da=DataArrayDouble::New();
39 const double discX[4]={2.3,3.4,5.8,10.2};
40 const double discY[3]={12.3,23.4,45.8};
41 const double discZ[5]={-0.7,1.2,1.25,2.13,2.67};
43 std::copy(discX,discX+4,da->getPointer());
46 m->checkConsistencyLight();
47 CPPUNIT_ASSERT_EQUAL(4,m->getNumberOfNodes());
48 CPPUNIT_ASSERT_EQUAL(3,m->getNumberOfCells());
49 CPPUNIT_ASSERT_EQUAL(1,m->getSpaceDimension());
50 MEDCouplingFieldDouble *f=m->getMeasureField(true);
51 CPPUNIT_ASSERT_EQUAL(3,(int)f->getNumberOfTuples());
52 CPPUNIT_ASSERT_EQUAL(1,(int)f->getNumberOfComponents());
53 const double expected1[3]={1.1,2.4,4.4};
55 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f->getIJ(i,0),1e-12);
57 DataArrayDouble *coords=m->getCoordinatesAndOwner();
58 CPPUNIT_ASSERT_EQUAL(4,(int)coords->getNumberOfTuples());
59 CPPUNIT_ASSERT_EQUAL(1,(int)coords->getNumberOfComponents());
61 CPPUNIT_ASSERT_DOUBLES_EQUAL(discX[i],coords->getIJ(i,0),1e-12);
63 coords=m->computeCellCenterOfMass();
64 CPPUNIT_ASSERT_EQUAL(3,(int)coords->getNumberOfTuples());
65 CPPUNIT_ASSERT_EQUAL(1,(int)coords->getNumberOfComponents());
66 const double expected1_3[3]={2.85,4.6,8.};
68 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1_3[i],coords->getIJ(i,0),1e-12);
71 da=DataArrayDouble::New();
73 std::copy(discY,discY+3,da->getPointer());
76 m->checkConsistencyLight();
77 CPPUNIT_ASSERT_EQUAL(12,m->getNumberOfNodes());
78 CPPUNIT_ASSERT_EQUAL(6,m->getNumberOfCells());
79 CPPUNIT_ASSERT_EQUAL(2,m->getSpaceDimension());
80 f=m->getMeasureField(true);
81 CPPUNIT_ASSERT_EQUAL(6,(int)f->getNumberOfTuples());
82 CPPUNIT_ASSERT_EQUAL(1,(int)f->getNumberOfComponents());
83 const double expected2[6]={12.21,26.64,48.84,24.64,53.76,98.56};
85 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(i,0),1e-12);
87 coords=m->getCoordinatesAndOwner();
88 CPPUNIT_ASSERT_EQUAL(12,(int)coords->getNumberOfTuples());
89 CPPUNIT_ASSERT_EQUAL(2,(int)coords->getNumberOfComponents());
90 const double expected2_2[24]={2.3,12.3,3.4,12.3,5.8,12.3,10.2,12.3, 2.3,23.4,3.4,23.4,5.8,23.4,10.2,23.4, 2.3,45.8,3.4,45.8,5.8,45.8,10.2,45.8};
92 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2_2[i],coords->getIJ(0,i),1e-12);
94 coords=m->computeCellCenterOfMass();
95 CPPUNIT_ASSERT_EQUAL(6,(int)coords->getNumberOfTuples());
96 CPPUNIT_ASSERT_EQUAL(2,(int)coords->getNumberOfComponents());
97 const double expected2_3[12]={2.85,17.85,4.6,17.85,8.,17.85, 2.85,34.6,4.6,34.6,8.,34.6};
99 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2_3[i],coords->getIJ(0,i),1e-12);
102 da=DataArrayDouble::New();
104 std::copy(discZ,discZ+5,da->getPointer());
105 m->setCoordsAt(2,da);
107 m->checkConsistencyLight();
108 CPPUNIT_ASSERT_EQUAL(60,m->getNumberOfNodes());
109 CPPUNIT_ASSERT_EQUAL(24,m->getNumberOfCells());
110 CPPUNIT_ASSERT_EQUAL(3,m->getSpaceDimension());
111 f=m->getMeasureField(true);
112 CPPUNIT_ASSERT_EQUAL(24,(int)f->getNumberOfTuples());
113 CPPUNIT_ASSERT_EQUAL(1,(int)f->getNumberOfComponents());
114 const double expected3[24]={23.199, 50.616, 92.796, 46.816, 102.144, 187.264, 0.6105, 1.332, 2.442, 1.232, 2.688, 4.928, 10.7448, 23.4432, 42.9792, 21.6832, 47.3088, 86.7328, 6.5934, 14.3856, 26.3736, 13.3056, 29.0304, 53.2224};
115 for(int i=0;i<24;i++)
116 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],f->getIJ(i,0),1e-12);
118 coords=m->getCoordinatesAndOwner();
119 CPPUNIT_ASSERT_EQUAL(60,(int)coords->getNumberOfTuples());
120 CPPUNIT_ASSERT_EQUAL(3,(int)coords->getNumberOfComponents());
121 const double expected3_2[180]={
122 2.3,12.3,-0.7, 3.4,12.3,-0.7, 5.8,12.3,-0.7, 10.2,12.3,-0.7, 2.3,23.4,-0.7, 3.4,23.4,-0.7, 5.8,23.4,-0.7, 10.2,23.4,-0.7, 2.3,45.8,-0.7, 3.4,45.8,-0.7, 5.8,45.8,-0.7, 10.2,45.8,-0.7,
123 2.3,12.3,1.2, 3.4,12.3,1.2, 5.8,12.3,1.2, 10.2,12.3,1.2, 2.3,23.4,1.2, 3.4,23.4,1.2, 5.8,23.4,1.2, 10.2,23.4,1.2, 2.3,45.8,1.2, 3.4,45.8,1.2, 5.8,45.8,1.2, 10.2,45.8,1.2,
124 2.3,12.3,1.25, 3.4,12.3,1.25, 5.8,12.3,1.25, 10.2,12.3,1.25, 2.3,23.4,1.25, 3.4,23.4,1.25, 5.8,23.4,1.25, 10.2,23.4,1.25, 2.3,45.8,1.25, 3.4,45.8,1.25, 5.8,45.8,1.25, 10.2,45.8,1.25,
125 2.3,12.3,2.13, 3.4,12.3,2.13, 5.8,12.3,2.13, 10.2,12.3,2.13, 2.3,23.4,2.13, 3.4,23.4,2.13, 5.8,23.4,2.13, 10.2,23.4,2.13, 2.3,45.8,2.13, 3.4,45.8,2.13, 5.8,45.8,2.13, 10.2,45.8,2.13,
126 2.3,12.3,2.67, 3.4,12.3,2.67, 5.8,12.3,2.67, 10.2,12.3,2.67, 2.3,23.4,2.67, 3.4,23.4,2.67, 5.8,23.4,2.67, 10.2,23.4,2.67, 2.3,45.8,2.67, 3.4,45.8,2.67, 5.8,45.8,2.67, 10.2,45.8,2.67
128 for(int i=0;i<180;i++)
129 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3_2[i],coords->getIJ(0,i),1e-12);
131 coords=m->computeCellCenterOfMass();
132 CPPUNIT_ASSERT_EQUAL(24,(int)coords->getNumberOfTuples());
133 CPPUNIT_ASSERT_EQUAL(3,(int)coords->getNumberOfComponents());
134 const double expected3_3[72]={
135 2.85,17.85,0.25,4.6,17.85,0.25,8.,17.85,0.25, 2.85,34.6,0.25,4.6,34.6,0.25,8.,34.6,0.25,
136 2.85,17.85,1.225,4.6,17.85,1.225,8.,17.85,1.225, 2.85,34.6,1.225,4.6,34.6,1.225,8.,34.6,1.225,
137 2.85,17.85,1.69,4.6,17.85,1.69,8.,17.85,1.69, 2.85,34.6,1.69,4.6,34.6,1.69,8.,34.6,1.69,
138 2.85,17.85,2.4,4.6,17.85,2.4,8.,17.85,2.4, 2.85,34.6,2.4,4.6,34.6,2.4,8.,34.6,2.4
140 for(int i=0;i<72;i++)
141 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3_3[i],coords->getIJ(0,i),1e-12);
147 void MEDCouplingBasicsTest3::testFieldDoubleZipCoords1()
149 MEDCouplingUMesh *m=build2DTargetMeshMergeNode_1();
150 MEDCouplingFieldDouble *f=m->fillFromAnalytic(ON_NODES,2,"x*2.");
151 f->getArray()->setInfoOnComponent(0,"titi");
152 f->getArray()->setInfoOnComponent(1,"tutu");
153 f->checkConsistencyLight();
154 CPPUNIT_ASSERT_EQUAL(18,(int)f->getNumberOfTuples());
155 CPPUNIT_ASSERT_EQUAL(2,(int)f->getNumberOfComponents());
156 const double expected1[36]={-0.6, -0.6, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 0.4, 0.4};
157 for(int i=0;i<36;i++)
158 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f->getIJ(0,i),1e-12);
159 CPPUNIT_ASSERT(f->zipCoords());
160 f->checkConsistencyLight();
161 const double expected2[30]={-0.6, -0.6, 1.4, 1.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 0.4, 0.4};
162 for(int i=0;i<30;i++)
163 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(0,i),1e-12);
164 CPPUNIT_ASSERT(!f->zipCoords());
165 f->checkConsistencyLight();
166 for(int i=0;i<30;i++)
167 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(0,i),1e-12);
168 CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(0))=="titi");
169 CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(1))=="tutu");
174 void MEDCouplingBasicsTest3::testFieldDoubleZipConnectivity1()
176 MEDCouplingUMesh *m1=build2DTargetMesh_1();
177 MEDCouplingUMesh *m2=build2DTargetMesh_1();
178 const int cells1[3]={2,3,4};
179 MEDCouplingPointSet *m3_1=m2->buildPartOfMySelf(cells1,cells1+3,true);
180 MEDCouplingUMesh *m3=dynamic_cast<MEDCouplingUMesh *>(m3_1);
183 MEDCouplingUMesh *m4=build2DSourceMesh_1();
184 MEDCouplingUMesh *m5=MEDCouplingUMesh::MergeUMeshes(m1,m3);
187 MEDCouplingUMesh *m6=MEDCouplingUMesh::MergeUMeshes(m5,m4);
191 CPPUNIT_ASSERT_EQUAL(10,m6->getNumberOfCells());
192 CPPUNIT_ASSERT_EQUAL(22,m6->getNumberOfNodes());
195 DataArrayInt *arr=m6->mergeNodes(1e-13,areNodesMerged,newNbOfNodes);
196 CPPUNIT_ASSERT_EQUAL(9,m6->getNumberOfNodes());
198 MEDCouplingFieldDouble *f=m6->fillFromAnalytic(ON_CELLS,2,"x");
199 MEDCouplingFieldDouble *f2=m6->fillFromAnalytic(ON_NODES,2,"x");
200 CPPUNIT_ASSERT_EQUAL(10,(int)f->getNumberOfTuples());
201 CPPUNIT_ASSERT_EQUAL(2,(int)f->getNumberOfComponents());
202 const double expected1[20]={-0.05, -0.05, 0.3666666666666667, 0.3666666666666667, 0.53333333333333321, 0.53333333333333321,
203 -0.05, -0.05, 0.45, 0.45, 0.53333333333333321, 0.53333333333333321, -0.05, -0.05, 0.45, 0.45,
204 0.36666666666666659, 0.36666666666666659, 0.033333333333333326, 0.033333333333333326};
205 for(int i=0;i<20;i++)
206 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f->getIJ(0,i),1e-12);
207 f->getArray()->setInfoOnComponent(0,"titi");
208 f->getArray()->setInfoOnComponent(1,"tutu");
209 f->checkConsistencyLight();
210 CPPUNIT_ASSERT(f->zipConnectivity(0));
211 const double expected2[14]={-0.05, -0.05, 0.3666666666666667, 0.3666666666666667, 0.53333333333333321, 0.53333333333333321,
212 -0.05, -0.05, 0.45, 0.45, 0.36666666666666659, 0.36666666666666659, 0.033333333333333326, 0.033333333333333326};
213 CPPUNIT_ASSERT_EQUAL(7,(int)f->getNumberOfTuples());
214 CPPUNIT_ASSERT_EQUAL(2,(int)f->getNumberOfComponents());
215 for(int i=0;i<14;i++)
216 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(0,i),1e-12);
217 CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(0))=="titi");
218 CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(1))=="tutu");
219 CPPUNIT_ASSERT(!f->zipConnectivity(0));
222 const double expected3[18]={-0.3, -0.3, 0.2, 0.2, 0.7, 0.7, -0.3, -0.3, 0.2, 0.2, 0.7, 0.7,
223 -0.3, -0.3, 0.2, 0.2, 0.7, 0.7};
224 CPPUNIT_ASSERT_EQUAL(9,(int)f2->getNumberOfTuples());
225 CPPUNIT_ASSERT_EQUAL(2,(int)f2->getNumberOfComponents());
226 for(int i=0;i<18;i++)
227 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],f2->getIJ(0,i),1e-12);
228 CPPUNIT_ASSERT(f2->zipConnectivity(0));
229 CPPUNIT_ASSERT_EQUAL(9,(int)f2->getNumberOfTuples());
230 CPPUNIT_ASSERT_EQUAL(2,(int)f2->getNumberOfComponents());
231 for(int i=0;i<18;i++)
232 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],f2->getIJ(0,i),1e-12);
238 void MEDCouplingBasicsTest3::testDaDoubleRenumber1()
240 DataArrayDouble *a=DataArrayDouble::New();
242 a->setInfoOnComponent(0,"toto");
243 a->setInfoOnComponent(1,"tata");
244 const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
245 std::copy(arr1,arr1+14,a->getPointer());
247 const int arr2[7]={3,1,0,6,5,4,2};
248 DataArrayDouble *b=a->renumber(arr2);
249 CPPUNIT_ASSERT_EQUAL(7,(int)b->getNumberOfTuples());
250 CPPUNIT_ASSERT_EQUAL(2,(int)b->getNumberOfComponents());
251 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
252 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
253 const double expected1[14]={3.1, 13.1, 2.1, 12.1, 7.1, 17.1, 1.1, 11.1, 6.1, 16.1, 5.1, 15.1, 4.1, 14.1};
254 for(int i=0;i<14;i++)
255 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
259 DataArrayInt *c=DataArrayInt::New();
261 c->setInfoOnComponent(0,"toto");
262 c->setInfoOnComponent(1,"tata");
263 const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
264 std::copy(arr3,arr3+14,c->getPointer());
265 DataArrayInt *d=c->renumber(arr2);
266 CPPUNIT_ASSERT_EQUAL(7,(int)d->getNumberOfTuples());
267 CPPUNIT_ASSERT_EQUAL(2,(int)d->getNumberOfComponents());
268 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
269 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
270 const int expected2[14]={3, 13, 2, 12, 7, 17, 1, 11, 6, 16, 5, 15, 4, 14};
271 for(int i=0;i<14;i++)
272 CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
277 void MEDCouplingBasicsTest3::testDaDoubleRenumberAndReduce1()
279 DataArrayDouble *a=DataArrayDouble::New();
281 a->setInfoOnComponent(0,"toto");
282 a->setInfoOnComponent(1,"tata");
283 const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
284 std::copy(arr1,arr1+14,a->getPointer());
286 const int arr2[7]={2,-1,1,-1,0,4,3};
287 DataArrayDouble *b=a->renumberAndReduce(arr2,5);
288 CPPUNIT_ASSERT_EQUAL(5,(int)b->getNumberOfTuples());
289 CPPUNIT_ASSERT_EQUAL(2,(int)b->getNumberOfComponents());
290 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
291 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
292 const double expected1[10]={5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1};
293 for(int i=0;i<10;i++)
294 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
298 DataArrayInt *c=DataArrayInt::New();
300 c->setInfoOnComponent(0,"toto");
301 c->setInfoOnComponent(1,"tata");
302 const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
303 std::copy(arr3,arr3+14,c->getPointer());
304 DataArrayInt *d=c->renumberAndReduce(arr2,5);
305 CPPUNIT_ASSERT_EQUAL(5,(int)d->getNumberOfTuples());
306 CPPUNIT_ASSERT_EQUAL(2,(int)d->getNumberOfComponents());
307 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
308 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
309 const int expected2[10]={5,15,3,13,1,11,7,17,6,16};
310 for(int i=0;i<10;i++)
311 CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
316 void MEDCouplingBasicsTest3::testDaDoubleRenumberInPlace1()
318 DataArrayDouble *a=DataArrayDouble::New();
320 const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
321 std::copy(arr1,arr1+14,a->getPointer());
323 const int arr2[7]={3,1,0,6,5,4,2};
324 a->renumberInPlace(arr2);
325 CPPUNIT_ASSERT_EQUAL(7,(int)a->getNumberOfTuples());
326 CPPUNIT_ASSERT_EQUAL(2,(int)a->getNumberOfComponents());
327 const double expected1[14]={3.1, 13.1, 2.1, 12.1, 7.1, 17.1, 1.1, 11.1, 6.1, 16.1, 5.1, 15.1, 4.1, 14.1};
328 for(int i=0;i<14;i++)
329 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],a->getIJ(0,i),1e-14);
332 DataArrayInt *c=DataArrayInt::New();
334 const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
335 std::copy(arr3,arr3+14,c->getPointer());
336 c->renumberInPlace(arr2);
337 CPPUNIT_ASSERT_EQUAL(7,(int)c->getNumberOfTuples());
338 CPPUNIT_ASSERT_EQUAL(2,(int)c->getNumberOfComponents());
339 const int expected2[14]={3, 13, 2, 12, 7, 17, 1, 11, 6, 16, 5, 15, 4, 14};
340 for(int i=0;i<14;i++)
341 CPPUNIT_ASSERT_EQUAL(expected2[i],c->getIJ(0,i));
345 void MEDCouplingBasicsTest3::testDaDoubleRenumberR1()
347 DataArrayDouble *a=DataArrayDouble::New();
349 a->setInfoOnComponent(0,"toto");
350 a->setInfoOnComponent(1,"tata");
351 const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
352 std::copy(arr1,arr1+14,a->getPointer());
354 const int arr2[7]={3,1,0,6,5,4,2};
355 DataArrayDouble *b=a->renumberR(arr2);
356 CPPUNIT_ASSERT_EQUAL(7,(int)b->getNumberOfTuples());
357 CPPUNIT_ASSERT_EQUAL(2,(int)b->getNumberOfComponents());
358 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
359 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
360 const double expected1[14]={4.1, 14.1, 2.1, 12.1, 1.1, 11.1, 7.1, 17.1, 6.1, 16.1, 5.1, 15.1, 3.1, 13.1};
361 for(int i=0;i<14;i++)
362 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
366 DataArrayInt *c=DataArrayInt::New();
368 c->setInfoOnComponent(0,"toto");
369 c->setInfoOnComponent(1,"tata");
370 const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
371 std::copy(arr3,arr3+14,c->getPointer());
372 DataArrayInt *d=c->renumberR(arr2);
373 CPPUNIT_ASSERT_EQUAL(7,(int)d->getNumberOfTuples());
374 CPPUNIT_ASSERT_EQUAL(2,(int)d->getNumberOfComponents());
375 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
376 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
377 const int expected2[14]={4, 14, 2, 12, 1, 11, 7, 17, 6, 16, 5, 15, 3, 13};
378 for(int i=0;i<14;i++)
379 CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
384 void MEDCouplingBasicsTest3::testDaDoubleRenumberInPlaceR1()
386 DataArrayDouble *a=DataArrayDouble::New();
388 const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
389 std::copy(arr1,arr1+14,a->getPointer());
391 const int arr2[7]={3,1,0,6,5,4,2};
392 a->renumberInPlaceR(arr2);
393 CPPUNIT_ASSERT_EQUAL(7,(int)a->getNumberOfTuples());
394 CPPUNIT_ASSERT_EQUAL(2,(int)a->getNumberOfComponents());
395 const double expected1[14]={4.1, 14.1, 2.1, 12.1, 1.1, 11.1, 7.1, 17.1, 6.1, 16.1, 5.1, 15.1, 3.1, 13.1};
396 for(int i=0;i<14;i++)
397 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],a->getIJ(0,i),1e-14);
400 DataArrayInt *c=DataArrayInt::New();
402 const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
403 std::copy(arr3,arr3+14,c->getPointer());
404 c->renumberInPlaceR(arr2);
405 CPPUNIT_ASSERT_EQUAL(7,(int)c->getNumberOfTuples());
406 CPPUNIT_ASSERT_EQUAL(2,(int)c->getNumberOfComponents());
407 const int expected2[14]={4, 14, 2, 12, 1, 11, 7, 17, 6, 16, 5, 15, 3, 13};
408 for(int i=0;i<14;i++)
409 CPPUNIT_ASSERT_EQUAL(expected2[i],c->getIJ(0,i));
413 void MEDCouplingBasicsTest3::testDaDoubleSelectByTupleId1()
415 DataArrayDouble *a=DataArrayDouble::New();
417 a->setInfoOnComponent(0,"toto");
418 a->setInfoOnComponent(1,"tata");
419 const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
420 std::copy(arr1,arr1+14,a->getPointer());
422 const int arr2[7]={4,2,0,6,5};
423 DataArrayDouble *b=a->selectByTupleId(arr2,arr2+5);
424 CPPUNIT_ASSERT_EQUAL(5,(int)b->getNumberOfTuples());
425 CPPUNIT_ASSERT_EQUAL(2,(int)b->getNumberOfComponents());
426 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
427 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
428 const double expected1[10]={5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1};
429 for(int i=0;i<10;i++)
430 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
434 DataArrayInt *c=DataArrayInt::New();
436 c->setInfoOnComponent(0,"toto");
437 c->setInfoOnComponent(1,"tata");
438 const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
439 std::copy(arr3,arr3+14,c->getPointer());
440 DataArrayInt *d=c->selectByTupleId(arr2,arr2+5);
441 CPPUNIT_ASSERT_EQUAL(5,(int)d->getNumberOfTuples());
442 CPPUNIT_ASSERT_EQUAL(2,(int)d->getNumberOfComponents());
443 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
444 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
445 const int expected2[10]={5,15,3,13,1,11,7,17,6,16};
446 for(int i=0;i<10;i++)
447 CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
452 void MEDCouplingBasicsTest3::testDaDoubleGetMinMaxValues1()
454 DataArrayDouble *a=DataArrayDouble::New();
456 const double arr1[9]={2.34,4.56,-6.77,4.55,4.56,2.24,2.34,1.02,4.56};
457 std::copy(arr1,arr1+9,a->getPointer());
459 double m=a->getMaxValue(where);
460 CPPUNIT_ASSERT_EQUAL(1,where);
461 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.56,m,1e-12);
463 m=a->getMaxValue2(ws);
464 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.56,m,1e-12);
465 CPPUNIT_ASSERT_EQUAL(3,(int)ws->getNumberOfTuples());
466 CPPUNIT_ASSERT_EQUAL(1,(int)ws->getNumberOfComponents());
467 const int expected1[3]={1,4,8};
469 CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
472 a=DataArrayDouble::New();
473 const double arr2[9]={-2.34,-4.56,6.77,-4.55,-4.56,-2.24,-2.34,-1.02,-4.56};
475 std::copy(arr2,arr2+9,a->getPointer());
477 m=a->getMinValue(where);
478 CPPUNIT_ASSERT_EQUAL(1,where);
479 CPPUNIT_ASSERT_DOUBLES_EQUAL(-4.56,m,1e-12);
480 m=a->getMinValue2(ws);
481 CPPUNIT_ASSERT_DOUBLES_EQUAL(-4.56,m,1e-12);
482 CPPUNIT_ASSERT_EQUAL(3,(int)ws->getNumberOfTuples());
483 CPPUNIT_ASSERT_EQUAL(1,(int)ws->getNumberOfComponents());
485 CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
490 void MEDCouplingBasicsTest3::testFieldDoubleGetMinMaxValues2()
492 MEDCouplingUMesh *m1=0;
493 MEDCouplingUMesh *m2=build3DExtrudedUMesh_1(m1);
495 CPPUNIT_ASSERT_EQUAL(18,m2->getNumberOfCells());
496 const double arr1[18]={8.71,4.53,-12.41,8.71,-8.71,8.7099,4.55,8.71,5.55,6.77,-1e-200,4.55,8.7099,0.,1.23,0.,2.22,8.71};
497 MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
498 DataArrayDouble *a=DataArrayDouble::New();
500 std::copy(arr1,arr1+18,a->getPointer());
505 f->checkConsistencyLight();
506 double m=f->getMaxValue();
507 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.71,m,1e-12);
509 m=f->getMaxValue2(ws);
510 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.71,m,1e-12);
511 CPPUNIT_ASSERT_EQUAL(4,(int)ws->getNumberOfTuples());
512 CPPUNIT_ASSERT_EQUAL(1,(int)ws->getNumberOfComponents());
513 const int expected1[4]={0,3,7,17};
515 CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
518 const double arr2[18]={-8.71,-4.53,12.41,-8.71,8.71,-8.7099,-4.55,-8.71,-5.55,-6.77,1e-200,-4.55,-8.7099,0.,-1.23,0.,-2.22,-8.71};
519 std::copy(arr2,arr2+18,a->getPointer());
520 f->checkConsistencyLight();
522 CPPUNIT_ASSERT_DOUBLES_EQUAL(-8.71,m,1e-12);
523 m=f->getMinValue2(ws);
524 CPPUNIT_ASSERT_DOUBLES_EQUAL(-8.71,m,1e-12);
525 CPPUNIT_ASSERT_EQUAL(4,(int)ws->getNumberOfTuples());
526 CPPUNIT_ASSERT_EQUAL(1,(int)ws->getNumberOfComponents());
528 CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
535 void MEDCouplingBasicsTest3::testBuildUnstructuredCMesh1()
537 MEDCouplingCMesh *m=MEDCouplingCMesh::New();
538 DataArrayDouble *da=DataArrayDouble::New();
539 const double discX[4]={2.3,3.4,5.8,10.2};
540 const double discY[3]={12.3,23.4,45.8};
541 const double discZ[5]={-0.7,1.2,1.25,2.13,2.67};
543 std::copy(discX,discX+4,da->getPointer());
544 m->setCoordsAt(0,da);
546 m->checkConsistencyLight();
548 CPPUNIT_ASSERT_EQUAL(0,m->getCellContainingPoint(&pos,1e-12));
550 CPPUNIT_ASSERT_EQUAL(1,m->getCellContainingPoint(&pos,1e-12));
552 CPPUNIT_ASSERT_EQUAL(2,m->getCellContainingPoint(&pos,1e-12));
554 CPPUNIT_ASSERT_EQUAL(-1,m->getCellContainingPoint(&pos,1e-12));
556 CPPUNIT_ASSERT_EQUAL(-1,m->getCellContainingPoint(&pos,1e-12));
558 MEDCouplingUMesh *m2=m->buildUnstructured();
559 m2->checkConsistencyLight();
560 MEDCouplingFieldDouble *f1=m->getMeasureField(false);
561 MEDCouplingFieldDouble *f2=m2->getMeasureField(false);
562 CPPUNIT_ASSERT_EQUAL((int)f1->getNumberOfTuples(),3);
563 CPPUNIT_ASSERT_EQUAL((int)f2->getNumberOfTuples(),3);
564 CPPUNIT_ASSERT_EQUAL(1,m2->getMeshDimension());
565 CPPUNIT_ASSERT_EQUAL(1,m2->getSpaceDimension());
567 CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getIJ(i,0),f2->getIJ(i,0),1e-10);
568 da=DataArrayDouble::New();
570 std::copy(discY,discY+3,da->getPointer());
571 m->setCoordsAt(1,da);
577 m2=m->buildUnstructured();
578 m2->checkConsistencyLight();
579 f1=m->getMeasureField(false);
580 f2=m2->getMeasureField(false);
581 CPPUNIT_ASSERT_EQUAL((int)f1->getNumberOfTuples(),6);
582 CPPUNIT_ASSERT_EQUAL((int)f2->getNumberOfTuples(),6);
583 CPPUNIT_ASSERT_EQUAL(2,m2->getMeshDimension());
584 CPPUNIT_ASSERT_EQUAL(2,m2->getSpaceDimension());
586 CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getIJ(i,0),f2->getIJ(i,0),1e-10);
591 da=DataArrayDouble::New();
593 std::copy(discZ,discZ+5,da->getPointer());
594 m->setCoordsAt(2,da);
596 m2=m->buildUnstructured();
597 m2->checkConsistencyLight();
598 f1=m->getMeasureField(false);
599 f2=m2->getMeasureField(false);
600 CPPUNIT_ASSERT_EQUAL((int)f1->getNumberOfTuples(),24);
601 CPPUNIT_ASSERT_EQUAL((int)f2->getNumberOfTuples(),24);
602 CPPUNIT_ASSERT_EQUAL(3,m2->getMeshDimension());
603 CPPUNIT_ASSERT_EQUAL(3,m2->getSpaceDimension());
604 for(int i=0;i<24;i++)
605 CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getIJ(i,0),f2->getIJ(i,0),1e-10);
609 double pos1[3]={5.,30.,2.};
610 CPPUNIT_ASSERT_EQUAL(16,m->getCellContainingPoint(pos1,1e-12));
612 const double pt[3]={2.4,12.7,-3.4};
614 MEDCouplingUMesh *m3=m->buildUnstructured();
616 CPPUNIT_ASSERT(m3->isEqual(m2,1e-12));
623 void MEDCouplingBasicsTest3::testDataArrayIntInvertO2NNO21()
625 const int arr1[6]={2,0,4,1,5,3};
626 DataArrayInt *da=DataArrayInt::New();
628 std::copy(arr1,arr1+6,da->getPointer());
629 DataArrayInt *da2=da->invertArrayO2N2N2O(6);
630 CPPUNIT_ASSERT_EQUAL(6,(int)da2->getNumberOfTuples());
631 CPPUNIT_ASSERT_EQUAL(1,(int)da2->getNumberOfComponents());
632 const int expected1[6]={1,3,0,5,2,4};
634 CPPUNIT_ASSERT_EQUAL(expected1[i],da2->getIJ(i,0));
635 DataArrayInt *da3=da2->invertArrayN2O2O2N(6);
637 CPPUNIT_ASSERT_EQUAL(arr1[i],da3->getIJ(i,0));
642 const int arr2[10]={3,-1,5,4,-1,0,-1,1,2,-1};
643 da=DataArrayInt::New();
645 std::copy(arr2,arr2+10,da->getPointer());
646 da2=da->invertArrayO2N2N2O(6);
647 CPPUNIT_ASSERT_EQUAL(6,(int)da2->getNumberOfTuples());
648 CPPUNIT_ASSERT_EQUAL(1,(int)da2->getNumberOfComponents());
649 const int expected2[10]={5,7,8,0,3,2};
651 CPPUNIT_ASSERT_EQUAL(expected2[i],da2->getIJ(i,0));
652 da3=da2->invertArrayN2O2O2N(10);
653 for(int i=0;i<10;i++)
654 CPPUNIT_ASSERT_EQUAL(arr2[i],da3->getIJ(i,0));
660 void MEDCouplingBasicsTest3::testKeepSetSelectedComponent1()
662 const double arr1[20]={1.,2.,3.,4., 11.,12.,13.,14., 21.,22.,23.,24., 31.,32.,33.,34., 41.,42.,43.,44.};
663 DataArrayDouble *a1=DataArrayDouble::New();
665 std::copy(arr1,arr1+20,a1->getPointer());
666 a1->setInfoOnComponent(0,"aaaa");
667 a1->setInfoOnComponent(1,"bbbb");
668 a1->setInfoOnComponent(2,"cccc");
669 a1->setInfoOnComponent(3,"dddd");
670 const int arr2[6]={1,2,1,2,0,0};
671 std::vector<int> arr2V(arr2,arr2+6);
672 DataArrayDouble *a2=static_cast<DataArrayDouble *>(a1->keepSelectedComponents(arr2V));
673 CPPUNIT_ASSERT_EQUAL(6,(int)a2->getNumberOfComponents());
674 CPPUNIT_ASSERT_EQUAL(5,(int)a2->getNumberOfTuples());
675 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(0))=="bbbb");
676 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(1))=="cccc");
677 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(2))=="bbbb");
678 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(3))=="cccc");
679 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(4))=="aaaa");
680 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(5))=="aaaa");
681 const double expected1[30]={2.,3.,2.,3.,1.,1., 12.,13.,12.,13.,11.,11., 22.,23.,22.,23.,21.,21., 32.,33.,32.,33.,31.,31., 42.,43.,42.,43.,41.,41.};
682 for(int i=0;i<30;i++)
683 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],a2->getIJ(0,i),1e-14);
684 MCAuto<DataArrayInt> a3(a1->convertToIntArr());
685 DataArrayInt *a4=static_cast<DataArrayInt *>(a3->keepSelectedComponents(arr2V));
686 CPPUNIT_ASSERT_EQUAL(6,(int)a4->getNumberOfComponents());
687 CPPUNIT_ASSERT_EQUAL(5,(int)a4->getNumberOfTuples());
688 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(0))=="bbbb");
689 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(1))=="cccc");
690 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(2))=="bbbb");
691 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(3))=="cccc");
692 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(4))=="aaaa");
693 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(5))=="aaaa");
694 for(int i=0;i<30;i++)
695 CPPUNIT_ASSERT_EQUAL(int(expected1[i]),a4->getIJ(0,i));
696 // setSelectedComponents
697 const int arr3[2]={3,2};
698 std::vector<int> arr3V(arr3,arr3+2);
699 DataArrayDouble *a5=static_cast<DataArrayDouble *>(a1->keepSelectedComponents(arr3V));
700 a5->setInfoOnComponent(0,"eeee");
701 a5->setInfoOnComponent(1,"ffff");
702 const int arr4[2]={1,2};
703 std::vector<int> arr4V(arr4,arr4+2);
704 a2->setSelectedComponents(a5,arr4V);
705 CPPUNIT_ASSERT_EQUAL(6,(int)a2->getNumberOfComponents());
706 CPPUNIT_ASSERT_EQUAL(5,(int)a2->getNumberOfTuples());
707 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(0))=="bbbb");
708 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(1))=="eeee");
709 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(2))=="ffff");
710 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(3))=="cccc");
711 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(4))=="aaaa");
712 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(5))=="aaaa");
713 const double expected2[30]={2.,4.,3.,3.,1.,1., 12.,14.,13.,13.,11.,11., 22.,24.,23.,23.,21.,21., 32.,34.,33.,33.,31.,31., 42.,44.,43.,43.,41.,41.};
714 for(int i=0;i<30;i++)
715 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],a2->getIJ(0,i),1e-14);
716 MCAuto<DataArrayInt> a6=a5->convertToIntArr();
717 a6->setInfoOnComponent(0,"eeee");
718 a6->setInfoOnComponent(1,"ffff");
719 a4->setSelectedComponents(a6,arr4V);
720 CPPUNIT_ASSERT_EQUAL(6,(int)a4->getNumberOfComponents());
721 CPPUNIT_ASSERT_EQUAL(5,(int)a4->getNumberOfTuples());
722 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(0))=="bbbb");
723 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(1))=="eeee");
724 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(2))=="ffff");
725 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(3))=="cccc");
726 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(4))=="aaaa");
727 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(5))=="aaaa");
728 for(int i=0;i<30;i++)
729 CPPUNIT_ASSERT_EQUAL(int(expected2[i]),a4->getIJ(0,i));
731 const int arr5[3]={2,3,6};
732 const int arr6[3]={2,7,5};
733 const int arr7[4]={2,1,4,6};
734 std::vector<int> arr5V(arr5,arr5+3);
735 std::vector<int> arr6V(arr6,arr6+3);
736 std::vector<int> arr7V(arr7,arr7+4);
737 CPPUNIT_ASSERT_THROW(a2->keepSelectedComponents(arr5V),INTERP_KERNEL::Exception);
738 CPPUNIT_ASSERT_THROW(a2->keepSelectedComponents(arr6V),INTERP_KERNEL::Exception);
739 CPPUNIT_ASSERT_THROW(a2->setSelectedComponents(a1,arr7V),INTERP_KERNEL::Exception);
741 CPPUNIT_ASSERT_THROW(a2->setSelectedComponents(a1,arr7V),INTERP_KERNEL::Exception);
749 void MEDCouplingBasicsTest3::testKeepSetSelectedComponent2()
751 MEDCouplingUMesh *m1=build2DTargetMesh_1();
752 const double arr1[20]={1.,2.,3.,4., 11.,12.,13.,14., 21.,22.,23.,24., 31.,32.,33.,34., 41.,42.,43.,44.};
753 DataArrayDouble *a1=DataArrayDouble::New();
755 std::copy(arr1,arr1+20,a1->getPointer());
756 a1->setInfoOnComponent(0,"aaaa");
757 a1->setInfoOnComponent(1,"bbbb");
758 a1->setInfoOnComponent(2,"cccc");
759 a1->setInfoOnComponent(3,"dddd");
760 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
761 f1->setTime(2.3,4,5);
765 f1->checkConsistencyLight();
767 const int arr2[6]={1,2,1,2,0,0};
768 std::vector<int> arr2V(arr2,arr2+6);
769 MEDCouplingFieldDouble *f2=f1->keepSelectedComponents(arr2V);
770 CPPUNIT_ASSERT(f2->getMesh()==f1->getMesh());
771 CPPUNIT_ASSERT(f2->getTimeDiscretization()==ONE_TIME);
773 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.3,f2->getTime(dt,it),1e-13);
774 CPPUNIT_ASSERT_EQUAL(4,dt);
775 CPPUNIT_ASSERT_EQUAL(5,it);
776 f2->checkConsistencyLight();
777 CPPUNIT_ASSERT_EQUAL(6,(int)f2->getNumberOfComponents());
778 CPPUNIT_ASSERT_EQUAL(5,(int)f2->getNumberOfTuples());
779 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(0))=="bbbb");
780 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(1))=="cccc");
781 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(2))=="bbbb");
782 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(3))=="cccc");
783 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(4))=="aaaa");
784 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(5))=="aaaa");
785 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.};
786 for(int i=0;i<30;i++)
787 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f2->getIJ(0,i),1e-14);
788 //setSelectedComponents
789 const int arr3[2]={3,2};
790 std::vector<int> arr3V(arr3,arr3+2);
791 MEDCouplingFieldDouble *f5=f1->keepSelectedComponents(arr3V);
792 f5->setTime(6.7,8,9);
793 f5->getArray()->setInfoOnComponent(0,"eeee");
794 f5->getArray()->setInfoOnComponent(1,"ffff");
795 f5->checkConsistencyLight();
796 const int arr4[2]={1,2};
797 std::vector<int> arr4V(arr4,arr4+2);
798 f2->setSelectedComponents(f5,arr4V);
799 CPPUNIT_ASSERT_EQUAL(6,(int)f2->getNumberOfComponents());
800 CPPUNIT_ASSERT_EQUAL(5,(int)f2->getNumberOfTuples());
801 f2->checkConsistencyLight();
802 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.3,f2->getTime(dt,it),1e-13);
803 CPPUNIT_ASSERT_EQUAL(4,dt);
804 CPPUNIT_ASSERT_EQUAL(5,it);
805 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(0))=="bbbb");
806 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(1))=="eeee");
807 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(2))=="ffff");
808 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(3))=="cccc");
809 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(4))=="aaaa");
810 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(5))=="aaaa");
811 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.};
812 for(int i=0;i<30;i++)
813 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f2->getIJ(0,i),1e-14);
821 void MEDCouplingBasicsTest3::testElementaryDAThrowAndSpecialCases()
823 DataArrayInt *da=DataArrayInt::New();
824 CPPUNIT_ASSERT_THROW(da->checkAllocated(),INTERP_KERNEL::Exception);
825 CPPUNIT_ASSERT_THROW(da->fillWithValue(1),INTERP_KERNEL::Exception);
826 CPPUNIT_ASSERT_THROW(da->iota(1),INTERP_KERNEL::Exception);
828 da->fillWithValue(11); //11,11,11,11...
829 da->iota(10); //10,11,12,13...
831 DataArrayInt *db=DataArrayInt::New();
834 DataArrayDouble *dbl2=DataArrayDouble::New();
836 CPPUNIT_ASSERT_THROW(dbl2->isUniform(10.,1e-15),INTERP_KERNEL::Exception);
837 CPPUNIT_ASSERT_THROW(dbl2->sort(),INTERP_KERNEL::Exception);
838 CPPUNIT_ASSERT_THROW(dbl2->iota(10.),INTERP_KERNEL::Exception);
840 DataArrayDouble *dbl=DataArrayDouble::New();
841 //DataArrayDouble not allocated yet
842 CPPUNIT_ASSERT_THROW(dbl->iota(10.),INTERP_KERNEL::Exception);
843 CPPUNIT_ASSERT_THROW(dbl->isUniform(10.,1e-15),INTERP_KERNEL::Exception);
844 CPPUNIT_ASSERT_THROW(dbl->sort(),INTERP_KERNEL::Exception);
845 CPPUNIT_ASSERT_THROW(dbl->reverse(),INTERP_KERNEL::Exception);
846 CPPUNIT_ASSERT_THROW(dbl->fromNoInterlace(),INTERP_KERNEL::Exception);
847 CPPUNIT_ASSERT_THROW(dbl->toNoInterlace(),INTERP_KERNEL::Exception);
851 CPPUNIT_ASSERT(!dbl->isUniform(10.,1e-15));
853 CPPUNIT_ASSERT(dbl->isMonotonic(true, .99));
854 CPPUNIT_ASSERT(dbl->isMonotonic(true, -.99));
855 CPPUNIT_ASSERT(!dbl->isMonotonic(true, 1.1));
856 CPPUNIT_ASSERT(!dbl->isMonotonic(true, -1.1));
858 CPPUNIT_ASSERT(dbl->isMonotonic(false, .99));
859 CPPUNIT_ASSERT(!dbl->isMonotonic(false, 1.1));
860 CPPUNIT_ASSERT(!dbl->isMonotonic(false, -1.1));
862 DataArrayInt *dc=DataArrayInt::New();
865 DataArrayDouble *dd=DataArrayDouble::New();
866 CPPUNIT_ASSERT_THROW(dd->checkAllocated(),INTERP_KERNEL::Exception);
867 CPPUNIT_ASSERT_THROW(dd->fillWithValue(1.),INTERP_KERNEL::Exception);
868 CPPUNIT_ASSERT_THROW(dd->iota(1.),INTERP_KERNEL::Exception);
869 CPPUNIT_ASSERT(!((dd->repr().find("No data"))==std::string::npos));
871 dd->alloc(0,1); //Allocated but nbOfElements==0!
872 CPPUNIT_ASSERT(!((dd->repr().find("Number of tuples : 0"))==std::string::npos));
873 CPPUNIT_ASSERT(!((dd->repr().find("Empty Data"))==std::string::npos));
874 dd->fillWithValue(11); //?!...
875 dd->iota(10); //?!...
876 CPPUNIT_ASSERT(dd->isMonotonic(true, 1.));
877 CPPUNIT_ASSERT(dd->isMonotonic(false, 1.));
879 CPPUNIT_ASSERT_THROW(db->copyStringInfoFrom(*da),INTERP_KERNEL::Exception);
880 CPPUNIT_ASSERT_THROW(db->copyStringInfoFrom(*da),INTERP_KERNEL::Exception);
881 std::vector<int> cIds(2,2);
882 CPPUNIT_ASSERT_THROW(da->copyPartOfStringInfoFrom(*db,cIds),INTERP_KERNEL::Exception);
885 CPPUNIT_ASSERT_THROW(da->copyPartOfStringInfoFrom(*db,cIds),INTERP_KERNEL::Exception);
887 std::vector<std::string> info(2,"infoOfOneComponent");
888 CPPUNIT_ASSERT_THROW(da->setInfoOnComponents(info),INTERP_KERNEL::Exception);
889 CPPUNIT_ASSERT_THROW(da->setInfoOnComponent(1,info[0].c_str()),INTERP_KERNEL::Exception);
890 db->setInfoOnComponents(info);
892 CPPUNIT_ASSERT_THROW(da->getInfoOnComponent(-1),INTERP_KERNEL::Exception);
893 CPPUNIT_ASSERT_THROW(da->getInfoOnComponent(2),INTERP_KERNEL::Exception);
894 CPPUNIT_ASSERT(db->getInfoOnComponent(1)==db->getInfoOnComponent(0));
895 CPPUNIT_ASSERT_THROW(db->getVarOnComponent(-1),INTERP_KERNEL::Exception);
896 CPPUNIT_ASSERT_THROW(db->getVarOnComponent(2),INTERP_KERNEL::Exception);
897 CPPUNIT_ASSERT_THROW(db->getUnitOnComponent(-1),INTERP_KERNEL::Exception);
898 CPPUNIT_ASSERT_THROW(db->getUnitOnComponent(2),INTERP_KERNEL::Exception);
900 CPPUNIT_ASSERT(da->GetVarNameFromInfo(std::string("varname unit "))==std::string("varname unit "));
901 CPPUNIT_ASSERT(da->GetVarNameFromInfo(std::string("varname]unit["))==std::string("varname]unit["));
902 CPPUNIT_ASSERT(da->GetVarNameFromInfo(std::string("[unit]"))==std::string());
903 CPPUNIT_ASSERT(da->GetVarNameFromInfo(std::string("varname [unit]"))==std::string("varname"));
905 CPPUNIT_ASSERT(da->GetUnitFromInfo(std::string("varname unit "))==std::string());
906 CPPUNIT_ASSERT(da->GetUnitFromInfo(std::string("varname]unit["))==std::string());
907 CPPUNIT_ASSERT(da->GetUnitFromInfo(std::string("[unit]"))==std::string("unit"));
908 CPPUNIT_ASSERT(da->GetUnitFromInfo(std::string("varname [unit]"))==std::string("unit"));
910 CPPUNIT_ASSERT_THROW(da->checkNbOfTuplesAndComp(*db,"theMessageInThrow"),INTERP_KERNEL::Exception);
911 CPPUNIT_ASSERT_THROW(da->checkNbOfTuplesAndComp(*dc,"theMessageInThrow"),INTERP_KERNEL::Exception);
912 CPPUNIT_ASSERT_THROW(db->checkNbOfTuplesAndComp(*dc,"theMessageInThrow"),INTERP_KERNEL::Exception);
914 CPPUNIT_ASSERT_THROW(da->checkNbOfTuplesAndComp(7,2,"theMessageInThrow"),INTERP_KERNEL::Exception);
915 da->checkNbOfTuplesAndComp(7,1,"theMessageInThrow");
917 CPPUNIT_ASSERT_THROW(db->checkNbOfElems(7*2+1,"theMessageInThrow"),INTERP_KERNEL::Exception);
918 db->checkNbOfElems(7*2,"theMessageInThrow");
920 CPPUNIT_ASSERT_THROW(db->GetNumberOfItemGivenBES(10,9,1,"theMessageInThrow"),INTERP_KERNEL::Exception);
921 CPPUNIT_ASSERT_THROW(db->GetNumberOfItemGivenBES(0,1,-1,"theMessageInThrow"),INTERP_KERNEL::Exception);
922 CPPUNIT_ASSERT_EQUAL(10,db->GetNumberOfItemGivenBES(0,10,1,"theMessageInThrow"));
923 CPPUNIT_ASSERT_EQUAL(5,db->GetNumberOfItemGivenBES(0,10,2,"theMessageInThrow"));
924 CPPUNIT_ASSERT_EQUAL(6,db->GetNumberOfItemGivenBES(0,11,2,"theMessageInThrow"));
926 //std::cout<<"\n!!!!!!!!!\n"<<dd->repr()<<"\n!!!!!!!!!\n";
927 CPPUNIT_ASSERT(!((da->repr().find("Number of components : 1"))==std::string::npos));
928 CPPUNIT_ASSERT(!((dd->repr().find("Number of components : 1"))==std::string::npos));
929 CPPUNIT_ASSERT(!((dbl->repr().find("Number of components : 1"))==std::string::npos));
931 CPPUNIT_ASSERT(!((da->reprZip().find("Number of components : 1"))==std::string::npos));
932 CPPUNIT_ASSERT(!((dd->reprZip().find("Number of components : 1"))==std::string::npos));
933 CPPUNIT_ASSERT(!((dbl->reprZip().find("Number of components : 1"))==std::string::npos));
935 std::ostringstream ret;
936 dbl->writeVTK(ret,2,"file.tmp",0);
937 CPPUNIT_ASSERT(!((ret.str().find("<DataArray"))==std::string::npos));
938 CPPUNIT_ASSERT(!((ret.str().find("Float32"))==std::string::npos));
939 CPPUNIT_ASSERT(!((ret.str().find("16 15 14 13 12 11 10"))==std::string::npos));
941 CPPUNIT_ASSERT_THROW(dbl->selectByTupleIdSafeSlice(0,1,-1),INTERP_KERNEL::Exception);
942 CPPUNIT_ASSERT_THROW(dbl->subArray(-1,1),INTERP_KERNEL::Exception);
943 CPPUNIT_ASSERT_THROW(dbl->subArray(8,1),INTERP_KERNEL::Exception);
944 CPPUNIT_ASSERT_THROW(dbl->subArray(0,8),INTERP_KERNEL::Exception);
945 CPPUNIT_ASSERT_THROW(dbl->meldWith(dd),INTERP_KERNEL::Exception);
947 CPPUNIT_ASSERT_THROW(dbl->setPartOfValuesAdv(dbl2,da),INTERP_KERNEL::Exception); //dbl dbl2 not have the same number of components
948 CPPUNIT_ASSERT_THROW(dbl->setPartOfValuesAdv(dd,da),INTERP_KERNEL::Exception); //da tuple selector DataArrayInt instance not have exactly 2 components
950 DataArrayDouble *dbl3=DataArrayDouble::New();
952 dbl3->fillWithValue(11.);
954 //bad number of components
955 CPPUNIT_ASSERT_THROW(dbl3->getMaxValue(tupleId),INTERP_KERNEL::Exception);
956 CPPUNIT_ASSERT_THROW(dd->getMaxValue(tupleId),INTERP_KERNEL::Exception);
957 CPPUNIT_ASSERT_THROW(dbl3->getMinValue(tupleId),INTERP_KERNEL::Exception);
958 CPPUNIT_ASSERT_THROW(dd->getMinValue(tupleId),INTERP_KERNEL::Exception);
959 CPPUNIT_ASSERT_THROW(dbl3->getAverageValue(),INTERP_KERNEL::Exception);
960 CPPUNIT_ASSERT_THROW(dd->getAverageValue(),INTERP_KERNEL::Exception);
961 CPPUNIT_ASSERT_THROW(dd->accumulate(100),INTERP_KERNEL::Exception);
962 CPPUNIT_ASSERT_THROW(dbl->fromPolarToCart(),INTERP_KERNEL::Exception);
963 CPPUNIT_ASSERT_THROW(dbl3->fromCylToCart(),INTERP_KERNEL::Exception);
964 CPPUNIT_ASSERT_THROW(dbl3->fromSpherToCart(),INTERP_KERNEL::Exception);
965 CPPUNIT_ASSERT_THROW(dbl3->doublyContractedProduct(),INTERP_KERNEL::Exception);
966 CPPUNIT_ASSERT_THROW(dbl3->determinant(),INTERP_KERNEL::Exception);
967 CPPUNIT_ASSERT_THROW(dbl3->eigenValues(),INTERP_KERNEL::Exception);
968 CPPUNIT_ASSERT_THROW(dbl3->eigenVectors(),INTERP_KERNEL::Exception);
969 CPPUNIT_ASSERT_THROW(dbl3->inverse(),INTERP_KERNEL::Exception);
970 CPPUNIT_ASSERT_THROW(dbl3->trace(),INTERP_KERNEL::Exception);
971 CPPUNIT_ASSERT_THROW(dbl3->deviator(),INTERP_KERNEL::Exception);
973 dbl3->setIJ(5,1,12.);
974 CPPUNIT_ASSERT(dbl3->getMaxValueInArray()==12.);
975 CPPUNIT_ASSERT(dbl3->getMinValueInArray()==11.);
977 db->fillWithValue(100); //bad Ids
978 CPPUNIT_ASSERT_THROW(dbl3->setPartOfValuesAdv(dbl2,db),INTERP_KERNEL::Exception);
979 db->fillWithValue(-1); //bad Ids
980 CPPUNIT_ASSERT_THROW(dbl3->setPartOfValuesAdv(dbl2,db),INTERP_KERNEL::Exception);
981 db->fillWithValue(6); //bad Ids for dbl3
982 CPPUNIT_ASSERT_THROW(dbl3->setPartOfValuesAdv(dbl2,db),INTERP_KERNEL::Exception);
984 DataArrayDouble::SetArrayIn(dbl,dbl3); //dbl->dbl3 memLeaks?
985 dbl3->checkNoNullValues();
987 CPPUNIT_ASSERT_THROW(dbl3->checkNoNullValues(),INTERP_KERNEL::Exception);
988 CPPUNIT_ASSERT_THROW(dbl3->applyInv(1.),INTERP_KERNEL::Exception); //div by zero
989 CPPUNIT_ASSERT_THROW(dbl2->findIdsInRange(1.,2.),INTERP_KERNEL::Exception);
990 std::vector<const DataArrayDouble *> a(0); //input list must be NON EMPTY
991 CPPUNIT_ASSERT_THROW(DataArrayDouble::Aggregate(a),INTERP_KERNEL::Exception);
992 CPPUNIT_ASSERT_THROW(DataArrayDouble::Meld(a),INTERP_KERNEL::Exception);
995 a.push_back(dbl); //Nb of components mismatch
996 CPPUNIT_ASSERT_THROW(DataArrayDouble::Aggregate(a),INTERP_KERNEL::Exception);
998 CPPUNIT_ASSERT_THROW(DataArrayDouble::Dot(dbl2,dbl),INTERP_KERNEL::Exception);
1000 CPPUNIT_ASSERT_THROW(DataArrayDouble::CrossProduct(dbl2,dbl),INTERP_KERNEL::Exception); //Nb of components mismatch
1001 CPPUNIT_ASSERT_THROW(DataArrayDouble::CrossProduct(dbl2,dbl2),INTERP_KERNEL::Exception); //Nb of components must be equal to 3
1002 DataArrayDouble *dbl4=DataArrayDouble::New();
1004 DataArrayDouble *dbl5=DataArrayDouble::New();
1006 CPPUNIT_ASSERT_THROW(DataArrayDouble::CrossProduct(dbl4,dbl5),INTERP_KERNEL::Exception); //Nb of tuples mismatch
1008 a[0]=dbl4; //Nb of tuple mismatch
1009 a[1]=dbl5; //Nb of tuple mismatch
1010 CPPUNIT_ASSERT_THROW(DataArrayDouble::Meld(a),INTERP_KERNEL::Exception);
1011 CPPUNIT_ASSERT_THROW(DataArrayDouble::Dot(dbl4,dbl5),INTERP_KERNEL::Exception);
1024 void MEDCouplingBasicsTest3::testDAIGetIdsEqual1()
1026 const int tab1[7]={5,-2,-4,-2,3,2,-2};
1027 DataArrayInt *da=DataArrayInt::New();
1029 std::copy(tab1,tab1+7,da->getPointer());
1030 DataArrayInt *da2=da->findIdsEqual(-2);
1031 CPPUNIT_ASSERT_EQUAL(3,(int)da2->getNumberOfTuples());
1032 CPPUNIT_ASSERT_EQUAL(1,(int)da2->getNumberOfComponents());
1033 const int expected1[3]={1,3,6};
1034 CPPUNIT_ASSERT(std::equal(expected1,expected1+3,da2->getConstPointer()));
1039 void MEDCouplingBasicsTest3::testDAIGetIdsEqualList1()
1041 const int tab1[7]={5,-2,-4,-2,3,2,-2};
1042 DataArrayInt *da=DataArrayInt::New();
1044 std::copy(tab1,tab1+7,da->getPointer());
1045 const int tab2[3]={3,-2,0};
1046 std::vector<int> tab2V(tab2,tab2+3);
1047 DataArrayInt *da2=da->findIdsEqualList(&tab2V[0],&tab2V[0]+tab2V.size());
1048 CPPUNIT_ASSERT_EQUAL(4,(int)da2->getNumberOfTuples());
1049 CPPUNIT_ASSERT_EQUAL(1,(int)da2->getNumberOfComponents());
1050 const int expected1[4]={1,3,4,6};
1051 CPPUNIT_ASSERT(std::equal(expected1,expected1+4,da2->getConstPointer()));
1056 void MEDCouplingBasicsTest3::testDAFromNoInterlace1()
1058 const int tab1[15]={1,11,21,31,41,2,12,22,32,42,3,13,23,33,43};
1059 DataArrayInt *da=DataArrayInt::New();
1061 std::copy(tab1,tab1+15,da->getPointer());
1062 DataArrayInt *da2=da->fromNoInterlace();
1063 const int expected1[15]={1,2,3,11,12,13,21,22,23,31,32,33,41,42,43};
1064 CPPUNIT_ASSERT_EQUAL(5,(int)da2->getNumberOfTuples());
1065 CPPUNIT_ASSERT_EQUAL(3,(int)da2->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
1066 CPPUNIT_ASSERT(std::equal(expected1,expected1+15,da2->getConstPointer()));
1067 MCAuto<DataArrayDouble> da3=da->convertToDblArr();
1068 DataArrayDouble *da4=da3->fromNoInterlace();
1069 CPPUNIT_ASSERT_EQUAL(5,(int)da4->getNumberOfTuples());
1070 CPPUNIT_ASSERT_EQUAL(3,(int)da4->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
1071 for(int i=0;i<15;i++)
1072 CPPUNIT_ASSERT_DOUBLES_EQUAL((double)expected1[i],da4->getIJ(0,i),1e-14);
1078 void MEDCouplingBasicsTest3::testDAToNoInterlace1()
1080 const int tab1[15]={1,2,3,11,12,13,21,22,23,31,32,33,41,42,43};
1081 DataArrayInt *da=DataArrayInt::New();
1083 std::copy(tab1,tab1+15,da->getPointer());
1084 DataArrayInt *da2=da->toNoInterlace();
1085 const int expected1[15]={1,11,21,31,41,2,12,22,32,42,3,13,23,33,43};
1086 CPPUNIT_ASSERT_EQUAL(5,(int)da2->getNumberOfTuples());
1087 CPPUNIT_ASSERT_EQUAL(3,(int)da2->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
1088 CPPUNIT_ASSERT(std::equal(expected1,expected1+15,da2->getConstPointer()));
1089 MCAuto<DataArrayDouble> da3=da->convertToDblArr();
1090 DataArrayDouble *da4=da3->toNoInterlace();
1091 CPPUNIT_ASSERT_EQUAL(5,(int)da4->getNumberOfTuples());
1092 CPPUNIT_ASSERT_EQUAL(3,(int)da4->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
1093 for(int i=0;i<15;i++)
1094 CPPUNIT_ASSERT_DOUBLES_EQUAL((double)expected1[i],da4->getIJ(0,i),1e-14);
1100 void MEDCouplingBasicsTest3::testDAIsUniform1()
1102 const int tab1[5]={1,1,1,1,1};
1103 DataArrayInt *da=DataArrayInt::New();
1105 std::copy(tab1,tab1+5,da->getPointer());
1106 CPPUNIT_ASSERT(da->isUniform(1));
1108 CPPUNIT_ASSERT(!da->isUniform(1));
1110 CPPUNIT_ASSERT(da->isUniform(1));
1111 MCAuto<DataArrayDouble> da2=da->convertToDblArr();
1112 CPPUNIT_ASSERT(da2->isUniform(1.,1e-12));
1113 da2->setIJ(1,0,1.+1.e-13);
1114 CPPUNIT_ASSERT(da2->isUniform(1.,1e-12));
1115 da2->setIJ(1,0,1.+1.e-11);
1116 CPPUNIT_ASSERT(!da2->isUniform(1.,1e-12));
1120 void MEDCouplingBasicsTest3::testDADFromPolarToCart1()
1122 const double tab1[4]={2.,0.2,2.5,0.7};
1123 DataArrayDouble *da=DataArrayDouble::New();
1125 std::copy(tab1,tab1+4,da->getPointer());
1126 DataArrayDouble *da2=da->fromPolarToCart();
1127 const double expected1[4]={1.9601331556824833,0.39733866159012243, 1.9121054682112213,1.6105442180942275};
1128 for(int i=0;i<4;i++)
1129 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da2->getIJ(0,i),1e-13);
1134 void MEDCouplingBasicsTest3::testDADFromCylToCart1()
1136 const double tab1[6]={2.,0.2,4.,2.5,0.7,9.};
1137 DataArrayDouble *da=DataArrayDouble::New();
1139 std::copy(tab1,tab1+6,da->getPointer());
1140 DataArrayDouble *da2=da->fromCylToCart();
1141 const double expected1[6]={1.9601331556824833,0.39733866159012243,4., 1.9121054682112213,1.6105442180942275,9.};
1142 for(int i=0;i<6;i++)
1143 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da2->getIJ(0,i),1e-13);
1148 void MEDCouplingBasicsTest3::testDADFromSpherToCart1()
1150 const double tab1[6]={2.,0.2,0.3,2.5,0.7,0.8};
1151 DataArrayDouble *da=DataArrayDouble::New();
1153 std::copy(tab1,tab1+6,da->getPointer());
1154 DataArrayDouble *da2=da->fromSpherToCart();
1155 const double expected1[6]={0.37959212195737485,0.11742160338765303,1.9601331556824833, 1.1220769624465328,1.1553337045129035,1.9121054682112213};
1156 for(int i=0;i<6;i++)
1157 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da2->getIJ(0,i),1e-13);
1162 void MEDCouplingBasicsTest3::testUnPolyze1()
1164 const int elts[8]={0,1,2,3,4,5,6,7};
1165 std::vector<int> eltsV(elts,elts+8);
1166 MEDCouplingUMesh *mesh=build3DTargetMesh_1();
1167 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
1169 MEDCouplingUMesh *mesh2=build3DTargetMesh_1();
1170 mesh->checkConsistencyLight();
1171 CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12));
1172 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
1173 CPPUNIT_ASSERT(!mesh->isEqual(mesh2,1e-12));
1174 mesh->getNodalConnectivity()->setIJ(0,6,10);
1175 mesh->getNodalConnectivity()->setIJ(0,7,9);
1176 mesh->getNodalConnectivity()->setIJ(0,8,12);
1177 mesh->getNodalConnectivity()->setIJ(0,9,13);
1179 CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12));
1180 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
1181 mesh->getNodalConnectivity()->setIJ(0,6,12);
1182 mesh->getNodalConnectivity()->setIJ(0,7,13);
1183 mesh->getNodalConnectivity()->setIJ(0,8,10);
1184 mesh->getNodalConnectivity()->setIJ(0,9,9);
1186 CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12));
1187 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
1188 mesh->getNodalConnectivity()->setIJ(0,6,12);
1189 mesh->getNodalConnectivity()->setIJ(0,7,10);
1190 mesh->getNodalConnectivity()->setIJ(0,8,13);
1191 mesh->getNodalConnectivity()->setIJ(0,9,9);
1193 CPPUNIT_ASSERT(!mesh->isEqual(mesh2,1e-12));
1197 mesh=build2DTargetMesh_1();
1198 mesh2=build2DTargetMesh_1();
1200 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
1201 CPPUNIT_ASSERT(!mesh->isEqual(mesh2,1e-12));
1203 CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12));
1208 void MEDCouplingBasicsTest3::testConvertDegeneratedCells1()
1210 MEDCouplingUMesh *mesh=build3DTargetMesh_1();
1211 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};
1212 mesh->allocateCells(4);
1213 mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn);
1214 mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+8);
1215 mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+16);
1216 mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+24);
1217 mesh->finishInsertingCells();
1218 mesh->checkConsistencyLight();
1219 CPPUNIT_ASSERT_EQUAL(4,mesh->getNumberOfCells());
1220 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh->getTypeOfCell(0));
1221 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh->getTypeOfCell(1));
1222 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh->getTypeOfCell(2));
1223 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh->getTypeOfCell(3));
1224 MEDCouplingFieldDouble *f1=mesh->getMeasureField(true);
1225 mesh->convertDegeneratedCells();
1226 mesh->checkConsistencyLight();
1227 MEDCouplingFieldDouble *f2=mesh->getMeasureField(true);
1228 CPPUNIT_ASSERT_EQUAL(4,mesh->getNumberOfCells());
1229 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_PENTA6,mesh->getTypeOfCell(0));
1230 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_PYRA5,mesh->getTypeOfCell(1));
1231 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TETRA4,mesh->getTypeOfCell(2));
1232 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_PYRA5,mesh->getTypeOfCell(3));
1233 for(int i=0;i<4;i++)
1234 CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getArray()->getIJ(0,i),f2->getArray()->getIJ(0,i),1e-5);
1240 void MEDCouplingBasicsTest3::testGetNodeIdsNearPoints1()
1242 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
1243 DataArrayDouble *coords=mesh->getCoords();
1244 DataArrayDouble *tmp=DataArrayDouble::New();
1246 const double vals[6]={0.2,0.2,0.1,0.2,0.2,0.2};
1247 std::copy(vals,vals+6,tmp->getPointer());
1248 DataArrayDouble *tmp2=DataArrayDouble::Aggregate(coords,tmp);
1250 mesh->setCoords(tmp2);
1252 const double pts[6]={0.2,0.2,0.1,0.3,-0.3,0.7};
1253 DataArrayInt *c=mesh->getNodeIdsNearPoint(pts,1e-7);
1254 CPPUNIT_ASSERT_EQUAL(3,(int)c->getNumberOfTuples());
1255 CPPUNIT_ASSERT_EQUAL(4,c->getIJ(0,0));
1256 CPPUNIT_ASSERT_EQUAL(9,c->getIJ(1,0));
1257 CPPUNIT_ASSERT_EQUAL(11,c->getIJ(2,0));
1260 mesh->getNodeIdsNearPoints(pts,3,1e-7,c,cI);
1261 CPPUNIT_ASSERT_EQUAL(4,(int)cI->getNumberOfTuples());
1262 CPPUNIT_ASSERT_EQUAL(4,(int)c->getNumberOfTuples());
1263 CPPUNIT_ASSERT_EQUAL(4,c->getIJ(0,0));
1264 CPPUNIT_ASSERT_EQUAL(9,c->getIJ(1,0));
1265 CPPUNIT_ASSERT_EQUAL(11,c->getIJ(2,0));
1266 CPPUNIT_ASSERT_EQUAL(6,c->getIJ(3,0));
1267 CPPUNIT_ASSERT_EQUAL(0,cI->getIJ(0,0));
1268 CPPUNIT_ASSERT_EQUAL(3,cI->getIJ(1,0));
1269 CPPUNIT_ASSERT_EQUAL(3,cI->getIJ(2,0));
1270 CPPUNIT_ASSERT_EQUAL(4,cI->getIJ(3,0));
1276 void MEDCouplingBasicsTest3::testFieldCopyTinyAttrFrom1()
1278 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1280 f1->setTimeTolerance(1.e-5);
1281 f1->setDescription("f1Desc");
1282 f1->setTime(1.23,4,5);
1283 MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1285 f2->setDescription("f2Desc");
1286 f2->setTime(6.78,9,10);
1287 f2->setTimeTolerance(4.556e-12);
1290 f1->copyTinyAttrFrom(f2);
1291 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.556e-12,f1->getTimeTolerance(),1e-24);
1292 CPPUNIT_ASSERT_DOUBLES_EQUAL(6.78,f1->getTime(dt,it),1e-12);
1293 CPPUNIT_ASSERT_EQUAL(9,dt);
1294 CPPUNIT_ASSERT_EQUAL(10,it);
1295 CPPUNIT_ASSERT(std::string(f1->getName())=="f1");//name unchanged
1296 CPPUNIT_ASSERT(std::string(f1->getDescription())=="f1Desc");//description unchanged
1300 f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1302 f1->setTimeTolerance(1.e-5);
1303 f1->setDescription("f1Desc");
1304 f2=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1306 f2->setDescription("f2Desc");
1307 f2->setTimeTolerance(4.556e-12);
1309 f1->copyTinyAttrFrom(f2);
1310 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.556e-12,f1->getTimeTolerance(),1e-24);
1311 CPPUNIT_ASSERT(std::string(f1->getName())=="f1");//name unchanged
1312 CPPUNIT_ASSERT(std::string(f1->getDescription())=="f1Desc");//description unchanged
1316 f1=MEDCouplingFieldDouble::New(ON_CELLS,CONST_ON_TIME_INTERVAL);
1318 f1->setTimeTolerance(1.e-5);
1319 f1->setDescription("f1Desc");
1320 f1->setTime(1.23,4,5);
1321 f1->setEndTime(5.43,2,1);
1322 f2=MEDCouplingFieldDouble::New(ON_CELLS,CONST_ON_TIME_INTERVAL);
1324 f2->setDescription("f2Desc");
1325 f2->setTimeTolerance(4.556e-12);
1326 f2->setTime(6.78,9,10);
1327 f2->setEndTime(10.98,7,6);
1329 f1->copyTinyAttrFrom(f2);
1330 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.556e-12,f1->getTimeTolerance(),1e-24);
1331 CPPUNIT_ASSERT(std::string(f1->getName())=="f1");//name unchanged
1332 CPPUNIT_ASSERT(std::string(f1->getDescription())=="f1Desc");//description unchanged
1333 CPPUNIT_ASSERT_DOUBLES_EQUAL(6.78,f1->getTime(dt,it),1e-12);
1334 CPPUNIT_ASSERT_EQUAL(9,dt);
1335 CPPUNIT_ASSERT_EQUAL(10,it);
1336 CPPUNIT_ASSERT_DOUBLES_EQUAL(10.98,f1->getEndTime(dt,it),1e-12);
1337 CPPUNIT_ASSERT_EQUAL(7,dt);
1338 CPPUNIT_ASSERT_EQUAL(6,it);
1342 f1=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
1344 f1->setTimeTolerance(1.e-5);
1345 f1->setDescription("f1Desc");
1346 f1->setTime(1.23,4,5);
1347 f1->setEndTime(5.43,2,1);
1348 f2=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
1350 f2->setDescription("f2Desc");
1351 f2->setTimeTolerance(4.556e-12);
1352 f2->setTime(6.78,9,10);
1353 f2->setEndTime(10.98,7,6);
1355 f1->copyTinyAttrFrom(f2);
1356 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.556e-12,f1->getTimeTolerance(),1e-24);
1357 CPPUNIT_ASSERT(std::string(f1->getName())=="f1");//name unchanged
1358 CPPUNIT_ASSERT(std::string(f1->getDescription())=="f1Desc");//description unchanged
1359 CPPUNIT_ASSERT_DOUBLES_EQUAL(6.78,f1->getTime(dt,it),1e-12);
1360 CPPUNIT_ASSERT_EQUAL(9,dt);
1361 CPPUNIT_ASSERT_EQUAL(10,it);
1362 CPPUNIT_ASSERT_DOUBLES_EQUAL(10.98,f1->getEndTime(dt,it),1e-12);
1363 CPPUNIT_ASSERT_EQUAL(7,dt);
1364 CPPUNIT_ASSERT_EQUAL(6,it);
1370 * 1D -> 2D extrusion with rotation
1372 void MEDCouplingBasicsTest3::testExtrudedMesh5()
1374 const double coo1[4]={0.,1.,2.,3.5};
1375 DataArrayDouble *a=DataArrayDouble::New();
1377 std::copy(coo1,coo1+4,a->getPointer());
1378 MEDCouplingCMesh *b=MEDCouplingCMesh::New();
1379 b->setCoordsAt(0,a);
1380 MEDCouplingUMesh *c=b->buildUnstructured();
1381 CPPUNIT_ASSERT_EQUAL(1,c->getSpaceDimension());
1382 c->changeSpaceDimension(2);
1384 DataArrayDouble *d=DataArrayDouble::New();
1387 MEDCouplingCMesh *ee=MEDCouplingCMesh::New();
1388 ee->setCoordsAt(0,d);
1389 MEDCouplingUMesh *f=ee->buildUnstructured();
1390 DataArrayDouble *g=f->getCoords()->applyFunc(2,"3.5*IVec+x/6*3.14159265359*JVec");
1391 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 !
1392 DataArrayDouble *h=g->fromPolarToCart();
1394 MEDCouplingUMesh *i=c->buildExtrudedMesh(f,1);
1395 CPPUNIT_ASSERT_EQUAL(52,i->getNumberOfNodes());
1398 DataArrayInt *tmp=i->mergeNodes(1e-9,tmp2,tmp3);
1399 CPPUNIT_ASSERT(tmp2);
1400 CPPUNIT_ASSERT_EQUAL(37,tmp3);
1402 i->convertDegeneratedCells();
1403 i->checkConsistencyLight();
1404 CPPUNIT_ASSERT_EQUAL(36,i->getNumberOfCells());
1405 CPPUNIT_ASSERT_EQUAL(37,i->getNumberOfNodes());
1406 CPPUNIT_ASSERT_EQUAL(12,i->getNumberOfCellsWithType(INTERP_KERNEL::NORM_TRI3));
1407 CPPUNIT_ASSERT_EQUAL(24,i->getNumberOfCellsWithType(INTERP_KERNEL::NORM_QUAD4));
1408 const double expected1[3]={0.25,0.75,2.0625};
1409 MEDCouplingFieldDouble *j=i->getMeasureField(true);
1410 for(int ii=0;ii<12;ii++)
1411 for(int k=0;k<3;k++)
1412 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[k],j->getIJ(0,ii*3+k),1e-10);
1413 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};
1414 DataArrayDouble *m=i->computeCellCenterOfMass();
1415 for(int ii=0;ii<72;ii++)
1416 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[ii],m->getIJ(0,ii),1e-10);
1432 * 1D -> 2D extrusion without rotation
1434 void MEDCouplingBasicsTest3::testExtrudedMesh6()
1436 const double coo1[4]={0.,1.,2.,3.5};
1437 DataArrayDouble *a=DataArrayDouble::New();
1439 std::copy(coo1,coo1+4,a->getPointer());
1440 MEDCouplingCMesh *b=MEDCouplingCMesh::New();
1441 b->setCoordsAt(0,a);
1442 MEDCouplingUMesh *c=b->buildUnstructured();
1443 CPPUNIT_ASSERT_EQUAL(1,c->getSpaceDimension());
1444 c->changeSpaceDimension(2);
1446 DataArrayDouble *d=DataArrayDouble::New();
1449 MEDCouplingCMesh *e=MEDCouplingCMesh::New();
1450 e->setCoordsAt(0,d);
1451 MEDCouplingUMesh *f=e->buildUnstructured();
1452 DataArrayDouble *d2=f->getCoords()->applyFunc("x*x/2");
1454 f->changeSpaceDimension(2);
1456 const double center[2]={0.,0.};
1457 f->rotate(center,0,M_PI/3);
1458 MEDCouplingUMesh *g=c->buildExtrudedMesh(f,0);
1459 g->checkConsistencyLight();
1460 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 };
1461 MEDCouplingFieldDouble *f1=g->getMeasureField(true);
1462 for(int i=0;i<12;i++)
1463 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-12);
1465 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};
1466 DataArrayDouble *f2=g->computeCellCenterOfMass();
1467 for(int i=0;i<24;i++)
1468 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f2->getIJ(0,i),1e-12);
1483 * 2D -> 3D extrusion with rotation
1485 void MEDCouplingBasicsTest3::testExtrudedMesh7()
1487 const double coo1[4]={0.,1.,2.,3.5};
1488 DataArrayDouble *a=DataArrayDouble::New();
1490 std::copy(coo1,coo1+4,a->getPointer());
1491 MEDCouplingCMesh *b=MEDCouplingCMesh::New();
1492 b->setCoordsAt(0,a);
1493 MEDCouplingUMesh *c=b->buildUnstructured();
1494 CPPUNIT_ASSERT_EQUAL(1,c->getSpaceDimension());
1495 c->changeSpaceDimension(2);
1497 DataArrayDouble *d=DataArrayDouble::New();
1500 MEDCouplingCMesh *e=MEDCouplingCMesh::New();
1501 e->setCoordsAt(0,d);
1502 MEDCouplingUMesh *f=e->buildUnstructured();
1503 DataArrayDouble *g=f->getCoords()->applyFunc(2,"3.5*IVec+x/6*3.14159265359*JVec");
1504 DataArrayDouble *h=g->fromPolarToCart();
1506 MEDCouplingUMesh *i=c->buildExtrudedMesh(f,1);
1507 CPPUNIT_ASSERT_EQUAL(52,i->getNumberOfNodes());
1510 DataArrayInt *tmp=i->mergeNodes(1e-9,tmp2,tmp3);
1511 CPPUNIT_ASSERT(tmp2);
1512 CPPUNIT_ASSERT_EQUAL(37,tmp3);
1514 i->convertDegeneratedCells();
1515 const double vec1[3]={10.,0.,0.};
1517 DataArrayDouble *g2=h->applyFunc(3,"13.5/3.5*x*IVec+0*JVec+13.5/3.5*y*KVec");
1519 i->changeSpaceDimension(3);
1520 MEDCouplingUMesh *i3=i->buildExtrudedMesh(f,1);
1521 MEDCouplingFieldDouble *f2=i3->getMeasureField(true);
1522 tmp=i->mergeNodes(1e-9,tmp2,tmp3);
1523 CPPUNIT_ASSERT(tmp2);
1524 CPPUNIT_ASSERT_EQUAL(444,tmp3);
1526 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};
1528 for(int ii=0;ii<12;ii++)
1529 for(int jj=0;jj<36;jj++,kk++)
1530 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[jj],f2->getIJ(0,kk),1e-9);
1546 void MEDCouplingBasicsTest3::testSimplexize1()
1548 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1549 std::vector<int> v(1);
1551 m->convertToPolyTypes(&v[0],&v[0]+v.size());
1552 DataArrayInt *da=m->simplexize(0);
1553 CPPUNIT_ASSERT_EQUAL(7,(int)da->getNumberOfTuples());
1554 CPPUNIT_ASSERT_EQUAL(1,(int)da->getNumberOfComponents());
1555 const int expected2[7]={0,0,1,2,3,4,4};
1556 for(int i=0;i<7;i++)
1557 CPPUNIT_ASSERT_EQUAL(expected2[i],da->getIJ(i,0));
1558 m->checkConsistencyLight();
1559 CPPUNIT_ASSERT_EQUAL(7,m->getNumberOfCells());
1560 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(0));
1561 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(1));
1562 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(2));
1563 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(3));
1564 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYGON,m->getTypeOfCell(4));
1565 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(5));
1566 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(6));
1567 const double expected1[7]={0.125,0.125,0.125,0.125,0.25,0.125,0.125};
1568 MEDCouplingFieldDouble *f=m->getMeasureField(false);
1569 for(int i=0;i<7;i++)
1570 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i]*sqrt(2.),f->getIJ(i,0),1e-10);
1571 std::set<INTERP_KERNEL::NormalizedCellType> types=m->getAllGeoTypes();
1572 CPPUNIT_ASSERT_EQUAL(2,(int)types.size());
1573 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*(types.begin()));
1574 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYGON,*(++(types.begin())));
1579 m=build3DSurfTargetMesh_1();
1581 m->convertToPolyTypes(&v[0],&v[0]+v.size());
1582 da=m->simplexize(1);
1583 CPPUNIT_ASSERT_EQUAL(7,(int)da->getNumberOfTuples());
1584 CPPUNIT_ASSERT_EQUAL(1,(int)da->getNumberOfComponents());
1585 for(int i=0;i<7;i++)
1586 CPPUNIT_ASSERT_EQUAL(expected2[i],da->getIJ(i,0));
1587 m->checkConsistencyLight();
1588 types=m->getAllGeoTypes();
1589 CPPUNIT_ASSERT_EQUAL(2,(int)types.size());
1590 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*(types.begin()));
1591 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYGON,*(++(types.begin())));
1592 CPPUNIT_ASSERT_EQUAL(7,m->getNumberOfCells());
1593 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(0));
1594 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(1));
1595 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(2));
1596 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(3));
1597 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYGON,m->getTypeOfCell(4));
1598 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(5));
1599 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(6));
1600 f=m->getMeasureField(false);
1601 for(int i=0;i<7;i++)
1602 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i]*sqrt(2.),f->getIJ(i,0),1e-10);
1608 void MEDCouplingBasicsTest3::testSimplexize2()
1610 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1611 std::vector<int> v(1);
1613 m->convertToPolyTypes(&v[0],&v[0]+v.size());
1614 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1616 DataArrayDouble *arr=DataArrayDouble::New();
1617 const double arr1[10]={10.,110.,20.,120.,30.,130.,40.,140.,50.,150.};
1619 std::copy(arr1,arr1+10,arr->getPointer());
1623 f1->checkConsistencyLight();
1624 CPPUNIT_ASSERT(f1->simplexize(0));
1625 f1->checkConsistencyLight();
1626 const double expected1[14]={10.,110.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.,50.,150.};
1627 for(int i=0;i<14;i++)
1628 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-10);
1629 CPPUNIT_ASSERT(!f1->simplexize(0));
1630 for(int i=0;i<14;i++)
1631 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-10);
1637 void MEDCouplingBasicsTest3::testDAMeld1()
1639 DataArrayDouble *da1=DataArrayDouble::New();
1641 DataArrayDouble *da2=DataArrayDouble::New();
1644 da1->fillWithValue(7.);
1646 MCAuto<DataArrayDouble> da3=da2->applyFunc(3,"10*x*IVec+100*x*JVec+1000*x*KVec");
1648 da1->setInfoOnComponent(0,"c0da1");
1649 da1->setInfoOnComponent(1,"c1da1");
1650 da3->setInfoOnComponent(0,"c0da3");
1651 da3->setInfoOnComponent(1,"c1da3");
1652 da3->setInfoOnComponent(2,"c2da3");
1654 DataArrayDouble *da1C=da1->deepCopy();
1656 CPPUNIT_ASSERT_EQUAL(5,(int)da1->getNumberOfComponents());
1657 CPPUNIT_ASSERT_EQUAL(7,(int)da1->getNumberOfTuples());
1658 CPPUNIT_ASSERT(da1->getInfoOnComponent(0)=="c0da1");
1659 CPPUNIT_ASSERT(da1->getInfoOnComponent(1)=="c1da1");
1660 CPPUNIT_ASSERT(da1->getInfoOnComponent(2)=="c0da3");
1661 CPPUNIT_ASSERT(da1->getInfoOnComponent(3)=="c1da3");
1662 CPPUNIT_ASSERT(da1->getInfoOnComponent(4)=="c2da3");
1664 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.};
1665 for(int i=0;i<35;i++)
1666 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da1->getIJ(0,i),1e-10);
1668 MCAuto<DataArrayInt> dai1=da1C->convertToIntArr();
1669 MCAuto<DataArrayInt> dai3=da3->convertToIntArr();
1670 dai1->meldWith(dai3);
1671 CPPUNIT_ASSERT_EQUAL(5,(int)dai1->getNumberOfComponents());
1672 CPPUNIT_ASSERT_EQUAL(7,(int)dai1->getNumberOfTuples());
1673 CPPUNIT_ASSERT(dai1->getInfoOnComponent(0)=="c0da1");
1674 CPPUNIT_ASSERT(dai1->getInfoOnComponent(1)=="c1da1");
1675 CPPUNIT_ASSERT(dai1->getInfoOnComponent(2)=="c0da3");
1676 CPPUNIT_ASSERT(dai1->getInfoOnComponent(3)=="c1da3");
1677 CPPUNIT_ASSERT(dai1->getInfoOnComponent(4)=="c2da3");
1678 for(int i=0;i<35;i++)
1679 CPPUNIT_ASSERT_EQUAL((int)expected1[i],dai1->getIJ(0,i));
1680 // test of static method DataArrayDouble::meld
1681 DataArrayDouble *da4=DataArrayDouble::Meld(da1C,da3);
1682 CPPUNIT_ASSERT_EQUAL(5,(int)da4->getNumberOfComponents());
1683 CPPUNIT_ASSERT_EQUAL(7,(int)da4->getNumberOfTuples());
1684 CPPUNIT_ASSERT(da4->getInfoOnComponent(0)=="c0da1");
1685 CPPUNIT_ASSERT(da4->getInfoOnComponent(1)=="c1da1");
1686 CPPUNIT_ASSERT(da4->getInfoOnComponent(2)=="c0da3");
1687 CPPUNIT_ASSERT(da4->getInfoOnComponent(3)=="c1da3");
1688 CPPUNIT_ASSERT(da4->getInfoOnComponent(4)=="c2da3");
1689 for(int i=0;i<35;i++)
1690 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da4->getIJ(0,i),1e-10);
1691 // test of static method DataArrayInt::meld
1692 dai1=da1C->convertToIntArr();
1693 DataArrayInt *dai4=DataArrayInt::Meld(dai1,dai3);
1694 CPPUNIT_ASSERT_EQUAL(5,(int)dai4->getNumberOfComponents());
1695 CPPUNIT_ASSERT_EQUAL(7,(int)dai4->getNumberOfTuples());
1696 CPPUNIT_ASSERT(dai4->getInfoOnComponent(0)=="c0da1");
1697 CPPUNIT_ASSERT(dai4->getInfoOnComponent(1)=="c1da1");
1698 CPPUNIT_ASSERT(dai4->getInfoOnComponent(2)=="c0da3");
1699 CPPUNIT_ASSERT(dai4->getInfoOnComponent(3)=="c1da3");
1700 CPPUNIT_ASSERT(dai4->getInfoOnComponent(4)=="c2da3");
1701 for(int i=0;i<35;i++)
1702 CPPUNIT_ASSERT_EQUAL((int)expected1[i],dai4->getIJ(0,i));
1711 void MEDCouplingBasicsTest3::testFieldMeld1()
1713 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1714 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1716 DataArrayDouble *da1=DataArrayDouble::New();
1717 const double arr1[5]={12.,23.,34.,45.,56.};
1719 std::copy(arr1,arr1+5,da1->getPointer());
1720 da1->setInfoOnComponent(0,"aaa");
1722 f1->setTime(3.4,2,1);
1723 f1->checkConsistencyLight();
1725 MEDCouplingFieldDouble *f2=f1->deepCopy();
1726 f2->setMesh(f1->getMesh());
1727 f2->checkConsistencyLight();
1728 f2->changeNbOfComponents(2,5.);
1730 f2->getArray()->setInfoOnComponent(0,"bbb");
1731 f2->getArray()->setInfoOnComponent(1,"ccc");
1732 f2->checkConsistencyLight();
1734 MEDCouplingFieldDouble *f3=MEDCouplingFieldDouble::MeldFields(f2,f1);
1735 f3->checkConsistencyLight();
1736 CPPUNIT_ASSERT_EQUAL(5,(int)f3->getNumberOfTuples());
1737 CPPUNIT_ASSERT_EQUAL(3,(int)f3->getNumberOfComponents());
1738 CPPUNIT_ASSERT(f3->getArray()->getInfoOnComponent(0)=="bbb");
1739 CPPUNIT_ASSERT(f3->getArray()->getInfoOnComponent(1)=="ccc");
1740 CPPUNIT_ASSERT(f3->getArray()->getInfoOnComponent(2)=="aaa");
1741 const double expected1[15]={5.,5.,12.,5.,5.,23.,5.,5.,34.,5.,5.,45.,5.,5.,56.};
1742 for(int i=0;i<15;i++)
1743 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f3->getIJ(0,i),1e-12);
1745 double time=f3->getTime(dt,it);
1746 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.4,time,1e-14);
1747 CPPUNIT_ASSERT_EQUAL(2,dt);
1748 CPPUNIT_ASSERT_EQUAL(1,it);
1750 MEDCouplingFieldDouble *f4=f2->buildNewTimeReprFromThis(NO_TIME,false);
1751 MEDCouplingFieldDouble *f5=f1->buildNewTimeReprFromThis(NO_TIME,false);
1752 MEDCouplingFieldDouble *f6=MEDCouplingFieldDouble::MeldFields(f4,f5);
1753 f6->checkConsistencyLight();
1754 CPPUNIT_ASSERT_EQUAL(5,(int)f6->getNumberOfTuples());
1755 CPPUNIT_ASSERT_EQUAL(3,(int)f6->getNumberOfComponents());
1756 CPPUNIT_ASSERT(f6->getArray()->getInfoOnComponent(0)=="bbb");
1757 CPPUNIT_ASSERT(f6->getArray()->getInfoOnComponent(1)=="ccc");
1758 CPPUNIT_ASSERT(f6->getArray()->getInfoOnComponent(2)=="aaa");
1759 for(int i=0;i<15;i++)
1760 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f6->getIJ(0,i),1e-12);
1772 void MEDCouplingBasicsTest3::testMergeNodes2()
1774 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1775 MEDCouplingUMesh *m2=build2DTargetMesh_1();
1776 const double vec[2]={0.002,0.};
1779 std::vector<const MEDCouplingUMesh *> tmp(2);
1782 MEDCouplingUMesh *m3=MEDCouplingUMesh::MergeUMeshes(tmp);
1785 DataArrayInt *da=m3->mergeNodesCenter(0.01,b,newNbOfNodes);
1786 CPPUNIT_ASSERT_EQUAL(9,m3->getNumberOfNodes());
1787 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};
1788 for(int i=0;i<18;i++)
1789 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],m3->getCoords()->getIJ(0,i),1e-13);
1797 void MEDCouplingBasicsTest3::testMergeField2()
1799 MEDCouplingUMesh *m=build2DTargetMesh_1();
1800 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1802 DataArrayDouble *arr=DataArrayDouble::New();
1804 arr->fillWithValue(2.);
1807 MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1809 arr=DataArrayDouble::New();
1811 arr->fillWithValue(5.);
1814 MEDCouplingFieldDouble *f3=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1816 arr=DataArrayDouble::New();
1818 arr->fillWithValue(7.);
1822 std::vector<const MEDCouplingFieldDouble *> tmp(3);
1823 tmp[0]=f1; tmp[1]=f2; tmp[2]=f3;
1824 MEDCouplingFieldDouble *f4=MEDCouplingFieldDouble::MergeFields(tmp);
1825 CPPUNIT_ASSERT_EQUAL(15,f4->getMesh()->getNumberOfCells());
1826 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.};
1827 for(int i=0;i<30;i++)
1828 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f4->getIJ(0,i),1.e-13);
1837 void MEDCouplingBasicsTest3::testDAIBuildComplement1()
1839 DataArrayInt *a=DataArrayInt::New();
1840 const int tab[4]={3,1,7,8};
1842 std::copy(tab,tab+4,a->getPointer());
1843 DataArrayInt *b=a->buildComplement(12);
1844 CPPUNIT_ASSERT_EQUAL(8,(int)b->getNumberOfTuples());
1845 CPPUNIT_ASSERT_EQUAL(1,(int)b->getNumberOfComponents());
1846 const int expected1[8]={0,2,4,5,6,9,10,11};
1847 for(int i=0;i<8;i++)
1848 CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
1853 void MEDCouplingBasicsTest3::testDAIBuildUnion1()
1855 DataArrayInt *a=DataArrayInt::New();
1856 const int tab1[4]={3,1,7,8};
1858 std::copy(tab1,tab1+4,a->getPointer());
1859 DataArrayInt *c=DataArrayInt::New();
1860 const int tab2[5]={5,3,0,18,8};
1862 std::copy(tab2,tab2+5,c->getPointer());
1863 DataArrayInt *b=a->buildUnion(c);
1864 CPPUNIT_ASSERT_EQUAL(7,(int)b->getNumberOfTuples());
1865 CPPUNIT_ASSERT_EQUAL(1,(int)b->getNumberOfComponents());
1866 const int expected1[7]={0,1,3,5,7,8,18};
1867 for(int i=0;i<7;i++)
1868 CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
1874 void MEDCouplingBasicsTest3::testDAIBuildIntersection1()
1876 DataArrayInt *a=DataArrayInt::New();
1877 const int tab1[4]={3,1,7,8};
1879 std::copy(tab1,tab1+4,a->getPointer());
1880 DataArrayInt *c=DataArrayInt::New();
1881 const int tab2[5]={5,3,0,18,8};
1883 std::copy(tab2,tab2+5,c->getPointer());
1884 DataArrayInt *b=a->buildIntersection(c);
1885 CPPUNIT_ASSERT_EQUAL(2,(int)b->getNumberOfTuples());
1886 CPPUNIT_ASSERT_EQUAL(1,(int)b->getNumberOfComponents());
1887 const int expected1[2]={3,8};
1888 for(int i=0;i<2;i++)
1889 CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
1895 void MEDCouplingBasicsTest3::testDAIDeltaShiftIndex1()
1897 DataArrayInt *a=DataArrayInt::New();
1898 const int tab[7]={1,3,6,7,7,9,15};
1900 std::copy(tab,tab+7,a->getPointer());
1901 DataArrayInt *b=a->deltaShiftIndex();
1902 CPPUNIT_ASSERT_EQUAL(6,(int)b->getNumberOfTuples());
1903 CPPUNIT_ASSERT_EQUAL(1,(int)b->getNumberOfComponents());
1904 const int expected1[6]={2,3,1,0,2,6};
1905 for(int i=0;i<6;i++)
1906 CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
1911 void MEDCouplingBasicsTest3::testDaDoubleSelectByTupleIdSafe1()
1913 DataArrayDouble *a=DataArrayDouble::New();
1915 a->setInfoOnComponent(0,"toto");
1916 a->setInfoOnComponent(1,"tata");
1917 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};
1918 std::copy(arr1,arr1+14,a->getPointer());
1920 const int arr2[7]={4,2,0,6,5};
1921 DataArrayDouble *b=a->selectByTupleIdSafe(arr2,arr2+5);
1922 CPPUNIT_ASSERT_EQUAL(5,(int)b->getNumberOfTuples());
1923 CPPUNIT_ASSERT_EQUAL(2,(int)b->getNumberOfComponents());
1924 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
1925 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
1926 const double expected1[10]={5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1};
1927 for(int i=0;i<10;i++)
1928 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
1929 const int arr4[5]={4,-1,0,6,5};
1930 CPPUNIT_ASSERT_THROW(a->selectByTupleIdSafe(arr4,arr4+5),INTERP_KERNEL::Exception);
1931 const int arr5[5]={4,2,0,6,7};
1932 CPPUNIT_ASSERT_THROW(a->selectByTupleIdSafe(arr5,arr5+5),INTERP_KERNEL::Exception);
1936 DataArrayInt *c=DataArrayInt::New();
1938 c->setInfoOnComponent(0,"toto");
1939 c->setInfoOnComponent(1,"tata");
1940 const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
1941 std::copy(arr3,arr3+14,c->getPointer());
1942 DataArrayInt *d=c->selectByTupleIdSafe(arr2,arr2+5);
1943 CPPUNIT_ASSERT_EQUAL(5,(int)d->getNumberOfTuples());
1944 CPPUNIT_ASSERT_EQUAL(2,(int)d->getNumberOfComponents());
1945 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
1946 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
1947 const int expected2[10]={5,15,3,13,1,11,7,17,6,16};
1948 for(int i=0;i<10;i++)
1949 CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
1950 CPPUNIT_ASSERT_THROW(c->selectByTupleIdSafe(arr4,arr4+5),INTERP_KERNEL::Exception);
1951 CPPUNIT_ASSERT_THROW(c->selectByTupleIdSafe(arr5,arr5+5),INTERP_KERNEL::Exception);
1956 void MEDCouplingBasicsTest3::testAreCellsIncludedIn1()
1958 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1959 const int pt[2]={1,3};
1960 MEDCouplingUMesh *m2=(MEDCouplingUMesh *)m->buildPartOfMySelf(pt,pt+2,true);
1962 CPPUNIT_ASSERT(m->areCellsIncludedIn(m2,0,tmp));
1963 CPPUNIT_ASSERT_EQUAL(2,(int)tmp->getNumberOfTuples());
1964 CPPUNIT_ASSERT_EQUAL(1,(int)tmp->getNumberOfComponents());
1965 CPPUNIT_ASSERT_EQUAL(pt[0],tmp->getIJ(0,0));
1966 CPPUNIT_ASSERT_EQUAL(pt[1],tmp->getIJ(0,1));
1968 CPPUNIT_ASSERT(!m2->areCellsIncludedIn(m,0,tmp));
1974 void MEDCouplingBasicsTest3::testDAIBuildSubstraction1()
1976 DataArrayInt *a=DataArrayInt::New();
1977 const int aa[]={2,3,6,8,9};
1979 std::copy(aa,aa+5,a->getPointer());
1980 DataArrayInt *b=DataArrayInt::New();
1981 const int bb[]={1,3,5,9,11};
1983 std::copy(bb,bb+5,b->getPointer());
1985 DataArrayInt *c=a->buildSubstraction(b);
1986 CPPUNIT_ASSERT_EQUAL(3,(int)c->getNumberOfTuples());
1987 CPPUNIT_ASSERT_EQUAL(1,(int)c->getNumberOfComponents());
1988 const int expected1[3]={2,6,8};
1989 CPPUNIT_ASSERT(std::equal(expected1,expected1+3,c->getConstPointer()));
1996 void MEDCouplingBasicsTest3::testBuildOrthogonalField2()
1998 MEDCouplingUMesh *m=build2DTargetMesh_1();
1999 DataArrayInt *d1=DataArrayInt::New();
2000 DataArrayInt *d2=DataArrayInt::New();
2001 DataArrayInt *d3=DataArrayInt::New();
2002 DataArrayInt *d4=DataArrayInt::New();
2003 MEDCouplingUMesh *m1=m->buildDescendingConnectivity(d1,d2,d3,d4);
2005 MEDCouplingFieldDouble *f1=m1->buildOrthogonalField();
2006 DataArrayDouble *da1=f1->getArray();
2007 CPPUNIT_ASSERT_EQUAL(2,(int)da1->getNumberOfComponents());
2008 CPPUNIT_ASSERT_EQUAL(13,(int)da1->getNumberOfTuples());
2010 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.};
2011 for(int i=0;i<26;i++)
2012 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da1->getIJ(0,i),1e-14);
2023 void MEDCouplingBasicsTest3::testUMInsertNextCell1()
2025 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 };
2026 int targetConn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
2027 MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
2028 targetMesh->allocateCells(5);
2029 CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn),INTERP_KERNEL::Exception);
2030 targetMesh->setMeshDimension(2);
2031 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn);
2032 CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_TETRA4,4,targetConn),INTERP_KERNEL::Exception);
2033 CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,targetConn),INTERP_KERNEL::Exception);
2034 CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn),INTERP_KERNEL::Exception);
2035 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+4);
2036 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+7);
2037 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+10);
2038 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+14);
2039 targetMesh->finishInsertingCells();
2040 DataArrayDouble *myCoords=DataArrayDouble::New();
2041 myCoords->alloc(9,2);
2042 std::copy(targetCoords,targetCoords+18,myCoords->getPointer());
2043 targetMesh->setCoords(myCoords);
2044 myCoords->decrRef();
2045 targetMesh->checkConsistencyLight();
2046 targetMesh->decrRef();
2049 void MEDCouplingBasicsTest3::testFieldOperatorDivDiffComp1()
2051 MEDCouplingUMesh *m=build2DTargetMesh_1();
2052 DataArrayInt *d1=DataArrayInt::New();
2053 DataArrayInt *d2=DataArrayInt::New();
2054 DataArrayInt *d3=DataArrayInt::New();
2055 DataArrayInt *d4=DataArrayInt::New();
2056 MEDCouplingUMesh *m1=m->buildDescendingConnectivity(d1,d2,d3,d4);
2058 MEDCouplingFieldDouble *f1=m1->buildOrthogonalField();
2059 const double arr1[13]={2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.};
2060 DataArrayDouble *arr=DataArrayDouble::New();
2062 std::copy(arr1,arr1+13,arr->getPointer());
2063 MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS);
2066 f2->checkConsistencyLight();
2068 MEDCouplingFieldDouble *f3=(*f1)/(*f2);
2069 CPPUNIT_ASSERT_THROW((*f2)/(*f1),INTERP_KERNEL::Exception);
2070 f3->checkConsistencyLight();
2072 CPPUNIT_ASSERT(f1->isEqual(f3,1e-10,1e-10));
2073 CPPUNIT_ASSERT_THROW((*f2)/=(*f1),INTERP_KERNEL::Exception);
2074 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};
2075 for(int i=0;i<26;i++)
2076 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f3->getIJ(0,i),1e-10);
2090 void MEDCouplingBasicsTest3::testDARearrange1()
2092 DataArrayInt *da1=DataArrayInt::New();
2095 const int *ptr=da1->getConstPointer();
2097 CPPUNIT_ASSERT_EQUAL((std::size_t)12,da1->getNbOfElems());
2098 CPPUNIT_ASSERT_EQUAL(1,(int)da1->getNumberOfComponents());
2099 CPPUNIT_ASSERT_EQUAL(12,(int)da1->getNumberOfTuples());
2101 CPPUNIT_ASSERT(ptr==da1->getConstPointer());
2102 CPPUNIT_ASSERT_EQUAL((std::size_t)12,da1->getNbOfElems());
2103 CPPUNIT_ASSERT_EQUAL(4,(int)da1->getNumberOfComponents());
2104 CPPUNIT_ASSERT_EQUAL(3,(int)da1->getNumberOfTuples());
2105 for(int i=0;i<12;i++)
2106 CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
2109 CPPUNIT_ASSERT(ptr==da1->getConstPointer());
2110 CPPUNIT_ASSERT_EQUAL((std::size_t)12,da1->getNbOfElems());
2111 CPPUNIT_ASSERT_EQUAL(6,(int)da1->getNumberOfComponents());
2112 CPPUNIT_ASSERT_EQUAL(2,(int)da1->getNumberOfTuples());
2113 for(int i=0;i<12;i++)
2114 CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
2116 CPPUNIT_ASSERT_THROW(da1->rearrange(7),INTERP_KERNEL::Exception);
2119 CPPUNIT_ASSERT(ptr==da1->getConstPointer());
2120 CPPUNIT_ASSERT_EQUAL((std::size_t)12,da1->getNbOfElems());
2121 CPPUNIT_ASSERT_EQUAL(12,(int)da1->getNumberOfComponents());
2122 CPPUNIT_ASSERT_EQUAL(1,(int)da1->getNumberOfTuples());
2123 for(int i=0;i<12;i++)
2124 CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
2127 CPPUNIT_ASSERT(ptr==da1->getConstPointer());
2128 CPPUNIT_ASSERT_EQUAL((std::size_t)12,da1->getNbOfElems());
2129 CPPUNIT_ASSERT_EQUAL(3,(int)da1->getNumberOfComponents());
2130 CPPUNIT_ASSERT_EQUAL(4,(int)da1->getNumberOfTuples());
2131 for(int i=0;i<12;i++)
2132 CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
2134 MCAuto<DataArrayDouble> da2=da1->convertToDblArr();
2136 const double *ptr2=da2->getConstPointer();
2138 CPPUNIT_ASSERT_EQUAL((std::size_t)12,da2->getNbOfElems());
2139 CPPUNIT_ASSERT_EQUAL(3,(int)da2->getNumberOfComponents());
2140 CPPUNIT_ASSERT_EQUAL(4,(int)da2->getNumberOfTuples());
2142 CPPUNIT_ASSERT(ptr2==da2->getConstPointer());
2143 CPPUNIT_ASSERT_EQUAL((std::size_t)12,da2->getNbOfElems());
2144 CPPUNIT_ASSERT_EQUAL(4,(int)da2->getNumberOfComponents());
2145 CPPUNIT_ASSERT_EQUAL(3,(int)da2->getNumberOfTuples());
2146 for(int i=0;i<12;i++)
2147 CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
2150 CPPUNIT_ASSERT(ptr2==da2->getConstPointer());
2151 CPPUNIT_ASSERT_EQUAL((std::size_t)12,da2->getNbOfElems());
2152 CPPUNIT_ASSERT_EQUAL(6,(int)da2->getNumberOfComponents());
2153 CPPUNIT_ASSERT_EQUAL(2,(int)da2->getNumberOfTuples());
2154 for(int i=0;i<12;i++)
2155 CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
2157 CPPUNIT_ASSERT_THROW(da2->rearrange(7),INTERP_KERNEL::Exception);
2160 CPPUNIT_ASSERT(ptr2==da2->getConstPointer());
2161 CPPUNIT_ASSERT_EQUAL((std::size_t)12,da2->getNbOfElems());
2162 CPPUNIT_ASSERT_EQUAL(1,(int)da2->getNumberOfComponents());
2163 CPPUNIT_ASSERT_EQUAL(12,(int)da2->getNumberOfTuples());
2164 for(int i=0;i<12;i++)
2165 CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
2168 CPPUNIT_ASSERT(ptr2==da2->getConstPointer());
2169 CPPUNIT_ASSERT_EQUAL((std::size_t)12,da2->getNbOfElems());
2170 CPPUNIT_ASSERT_EQUAL(3,(int)da2->getNumberOfComponents());
2171 CPPUNIT_ASSERT_EQUAL(4,(int)da2->getNumberOfTuples());
2172 for(int i=0;i<12;i++)
2173 CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
2176 void MEDCouplingBasicsTest3::testGetDifferentValues1()
2178 DataArrayInt *da1=DataArrayInt::New();
2179 const int arr[12]={1,2,3,2,2,3,5,1,5,5,2,2};
2181 std::copy(arr,arr+12,da1->getPointer());
2182 DataArrayInt *s=da1->getDifferentValues();
2183 const int expected1[4]={1,2,3,5};
2184 CPPUNIT_ASSERT_EQUAL(4,s->getNumberOfTuples());
2185 CPPUNIT_ASSERT(std::equal(expected1,expected1+4,s->begin()));
2190 void MEDCouplingBasicsTest3::testDAIBuildPermutationArr1()
2192 DataArrayInt *a=DataArrayInt::New();
2193 const int vala[5]={4,5,6,7,8};
2195 std::copy(vala,vala+5,a->getPointer());
2196 DataArrayInt *b=DataArrayInt::New();
2197 const int valb[5]={5,4,8,6,7};
2199 std::copy(valb,valb+5,b->getPointer());
2200 DataArrayInt *c=a->buildPermutationArr(*b);
2201 const int expect1[5]={1,0,4,2,3};
2202 CPPUNIT_ASSERT_EQUAL(5,(int)c->getNumberOfTuples());
2203 CPPUNIT_ASSERT_EQUAL(1,(int)c->getNumberOfComponents());
2204 CPPUNIT_ASSERT(std::equal(expect1,expect1+5,c->getConstPointer()));
2205 CPPUNIT_ASSERT(a->isEqualWithoutConsideringStrAndOrder(*b));
2207 CPPUNIT_ASSERT(!a->isEqualWithoutConsideringStrAndOrder(*b));
2208 CPPUNIT_ASSERT_THROW(a->buildPermutationArr(*b),INTERP_KERNEL::Exception);
2211 b->setIJ(4,0,4);//;a==[4,5,6,4,8] and b==[5,4,8,6,4]
2212 CPPUNIT_ASSERT(a->isEqualWithoutConsideringStrAndOrder(*b));
2214 c=a->buildPermutationArr(*b);
2215 const int expect2[5]={1,3,4,2,3};
2216 CPPUNIT_ASSERT(std::equal(expect2,expect2+5,c->getConstPointer()));
2217 MCAuto<DataArrayDouble> d=b->convertToDblArr();
2219 const int expect3[5]={4,4,5,6,8};
2220 CPPUNIT_ASSERT(std::equal(expect3,expect3+5,b->getConstPointer()));
2222 CPPUNIT_ASSERT_EQUAL(5,(int)d->getNumberOfTuples());
2223 CPPUNIT_ASSERT_EQUAL(1,(int)d->getNumberOfComponents());
2224 for(int i=0;i<5;i++)
2225 CPPUNIT_ASSERT_DOUBLES_EQUAL(double(expect3[i]),d->getIJ(i,0),1e-14);
2232 void MEDCouplingBasicsTest3::testAreCellsIncludedIn2()
2234 const char myName[]="Vitoo";
2235 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
2236 MEDCouplingUMesh *m2=(MEDCouplingUMesh *)m->buildPartOfMySelf(0,0,true);
2237 CPPUNIT_ASSERT_EQUAL(0,m2->getNumberOfCells());
2238 CPPUNIT_ASSERT_EQUAL(3,m2->getSpaceDimension());
2239 CPPUNIT_ASSERT_EQUAL(2,m2->getMeshDimension());
2240 m2->setName(myName);
2242 CPPUNIT_ASSERT(m->areCellsIncludedIn(m2,0,tmp));
2243 CPPUNIT_ASSERT(std::string(myName)==tmp->getName());
2244 CPPUNIT_ASSERT_EQUAL(0,(int)tmp->getNumberOfTuples());
2245 CPPUNIT_ASSERT_EQUAL(1,(int)tmp->getNumberOfComponents());
2251 void MEDCouplingBasicsTest3::testUMeshGetPartBarycenterAndOwner1()
2253 MEDCouplingUMesh *m1=build2DTargetMesh_1();
2254 const int part[3]={1,0,4};
2255 DataArrayDouble *b=m1->getPartBarycenterAndOwner(part,part+3);
2256 CPPUNIT_ASSERT_EQUAL(2,(int)b->getNumberOfComponents());
2257 CPPUNIT_ASSERT_EQUAL(3,(int)b->getNumberOfTuples());
2258 const double expected1[6]={0.36666666666666665,-0.13333333333333333,-0.05,-0.05,0.45,0.45};
2259 for(int i=0;i<6;i++)
2260 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
2265 void MEDCouplingBasicsTest3::testUMeshGetPartMeasureField1()
2267 MEDCouplingUMesh *m1=build2DTargetMesh_1();
2268 const int part[3]={1,0,4};
2269 DataArrayDouble *b=m1->getPartMeasureField(true,part,part+3);
2270 CPPUNIT_ASSERT_EQUAL(1,(int)b->getNumberOfComponents());
2271 CPPUNIT_ASSERT_EQUAL(3,(int)b->getNumberOfTuples());
2272 const double expected1[3]={0.125,0.25,0.25};
2273 for(int i=0;i<3;i++)
2274 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
2279 void MEDCouplingBasicsTest3::testUMeshBuildPartOrthogonalField1()
2281 MEDCouplingUMesh *m1=build2DTargetMesh_1();
2282 m1->changeSpaceDimension(3);
2283 const int part[3]={1,0,4};
2284 MEDCouplingFieldDouble *b=m1->buildPartOrthogonalField(part,part+3);
2285 CPPUNIT_ASSERT_EQUAL(3,(int)b->getArray()->getNumberOfComponents());
2286 CPPUNIT_ASSERT_EQUAL(3,(int)b->getArray()->getNumberOfTuples());
2287 const double expected1[9]={0.,0.,-1.,0.,0.,-1.,0.,0.,-1.};
2288 for(int i=0;i<9;i++)
2289 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getArray()->getIJ(0,i),1e-14);
2294 void MEDCouplingBasicsTest3::testUMeshGetTypesOfPart1()
2296 MEDCouplingUMesh *m1=build2DTargetMesh_1();
2297 const int part1[]={0,3,4};
2298 std::set<INTERP_KERNEL::NormalizedCellType> s;
2299 s=m1->getTypesOfPart(part1,part1+3);
2300 CPPUNIT_ASSERT(s.size()==1);
2301 CPPUNIT_ASSERT(*s.begin()==INTERP_KERNEL::NORM_QUAD4);
2302 const int part2[]={2,2,2,1};
2303 s=m1->getTypesOfPart(part2,part2+4);
2304 CPPUNIT_ASSERT(s.size()==1);
2305 CPPUNIT_ASSERT(*s.begin()==INTERP_KERNEL::NORM_TRI3);
2306 const int part3[]={3,2,1};
2307 s=m1->getTypesOfPart(part3,part3+3);
2308 CPPUNIT_ASSERT(s.size()==2);
2309 CPPUNIT_ASSERT(*s.begin()==INTERP_KERNEL::NORM_TRI3);
2310 CPPUNIT_ASSERT(*(++s.begin())==INTERP_KERNEL::NORM_QUAD4);
2314 void MEDCouplingBasicsTest3::testUMeshKeepCellIdsByType1()
2316 MEDCouplingUMesh *m1=build2DTargetMesh_1();
2317 const int part1[3]={0,3,4};
2318 DataArrayInt *a=m1->keepCellIdsByType(INTERP_KERNEL::NORM_TRI3,part1,part1+3);
2319 CPPUNIT_ASSERT_EQUAL(1,(int)a->getNumberOfComponents());
2320 CPPUNIT_ASSERT_EQUAL(0,(int)a->getNumberOfTuples());
2323 const int part2[5]={3,2,0,2,4};
2324 a=m1->keepCellIdsByType(INTERP_KERNEL::NORM_TRI3,part2,part2+5);
2325 CPPUNIT_ASSERT_EQUAL(1,(int)a->getNumberOfComponents());
2326 CPPUNIT_ASSERT_EQUAL(2,(int)a->getNumberOfTuples());
2327 CPPUNIT_ASSERT_EQUAL(2,a->getIJ(0,0));
2328 CPPUNIT_ASSERT_EQUAL(2,a->getIJ(1,0));
2331 a=m1->keepCellIdsByType(INTERP_KERNEL::NORM_QUAD4,part2,part2+5);
2332 CPPUNIT_ASSERT_EQUAL(1,(int)a->getNumberOfComponents());
2333 CPPUNIT_ASSERT_EQUAL(3,(int)a->getNumberOfTuples());
2334 CPPUNIT_ASSERT_EQUAL(3,a->getIJ(0,0));
2335 CPPUNIT_ASSERT_EQUAL(0,a->getIJ(1,0));
2336 CPPUNIT_ASSERT_EQUAL(4,a->getIJ(2,0));
2342 void MEDCouplingBasicsTest3::testDAIAggregateMulti1()
2344 DataArrayInt *a=DataArrayInt::New();
2349 DataArrayInt *b=DataArrayInt::New();
2355 std::vector<const DataArrayInt *> v(2);
2357 DataArrayInt *c=DataArrayInt::Aggregate(v);
2358 CPPUNIT_ASSERT_EQUAL(5,(int)c->getNumberOfTuples());
2359 CPPUNIT_ASSERT_EQUAL(2,(int)c->getNumberOfComponents());
2360 CPPUNIT_ASSERT(c->getName()=="aa");
2361 const int expect1[10]={0,1,2,3,0,1,2,3,4,5};
2362 for(int i=0;i<10;i++)
2363 CPPUNIT_ASSERT_EQUAL(expect1[i],c->getIJ(0,i));
2370 void MEDCouplingBasicsTest3::testMergeUMeshes2()
2372 MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
2373 MEDCouplingUMesh *m2=build3DSurfTargetMesh_1();
2374 MEDCouplingUMesh *m3=build3DSurfTargetMesh_1();
2376 const int vec1[3]={0,2,3};
2377 MEDCouplingUMesh *m2_2=(MEDCouplingUMesh *)m2->buildPartOfMySelf(vec1,vec1+3,false);
2378 const int vec2[2]={1,1};
2379 MEDCouplingUMesh *m3_2=(MEDCouplingUMesh *)m3->buildPartOfMySelf(vec2,vec2+2,false);
2381 std::vector<const MEDCouplingUMesh *> ms(3);
2382 std::vector<const MEDCouplingMesh *> ms2(3);
2383 ms[0]=m1; ms[1]=m2_2; ms[2]=m3_2;
2384 ms2[0]=m1; ms2[1]=m2_2; ms2[2]=m3_2;
2386 MEDCouplingUMesh *m4=MEDCouplingUMesh::MergeUMeshes(ms);
2387 m4->checkConsistencyLight();
2388 CPPUNIT_ASSERT_EQUAL(10,m4->getNumberOfCells());
2389 CPPUNIT_ASSERT_EQUAL(20,m4->getNumberOfNodes());
2390 CPPUNIT_ASSERT_EQUAL(45,m4->getNodalConnectivityArrayLen());
2392 MEDCouplingMesh *m4bis=MEDCouplingMesh::MergeMeshes(ms2);
2393 CPPUNIT_ASSERT(m4->isEqual(m4bis,1e-12));
2396 const int vec3[5]={0,1,2,3,4};
2397 MEDCouplingUMesh *m4_1=(MEDCouplingUMesh *)m4->buildPartOfMySelf(vec3,vec3+5,false);
2398 m4_1->setName(m1->getName().c_str());
2399 CPPUNIT_ASSERT(m4_1->isEqual(m1,1e-12));
2402 const int vec4[3]={5,6,7};
2403 MEDCouplingUMesh *m4_2=(MEDCouplingUMesh *)m4->buildPartOfMySelf(vec4,vec4+3,false);
2404 DataArrayInt *cellCor=0;
2405 DataArrayInt *nodeCor=0;
2406 m4_2->checkGeoEquivalWith(m2_2,10,1e-12,cellCor,nodeCor);
2407 CPPUNIT_ASSERT(cellCor==0);
2408 CPPUNIT_ASSERT(nodeCor==0);
2411 const int vec5[2]={8,9};
2412 MEDCouplingUMesh *m4_3=(MEDCouplingUMesh *)m4->buildPartOfMySelf(vec5,vec5+2,false);
2413 CPPUNIT_ASSERT_EQUAL(2,m4_3->getNumberOfCells());
2414 CPPUNIT_ASSERT_EQUAL(3,m4_3->getNumberOfNodes());
2416 m4_3->setName(m3_2->getName().c_str());
2417 CPPUNIT_ASSERT(m4_3->isEqual(m3_2,1e-12));
2428 void MEDCouplingBasicsTest3::testBuild0DMeshFromCoords1()
2430 const double sourceCoords[12]={-0.3,-0.3,0., 0.7,-0.3,0., -0.3,0.7,0., 0.7,0.7,0.};
2431 DataArrayDouble *coo=DataArrayDouble::New();
2433 coo->setName("My0D");
2434 std::copy(sourceCoords,sourceCoords+12,coo->getPointer());
2435 MEDCouplingUMesh *m=MEDCouplingUMesh::Build0DMeshFromCoords(coo);
2436 m->checkConsistencyLight();
2437 CPPUNIT_ASSERT_EQUAL(4,m->getNumberOfNodes());
2438 CPPUNIT_ASSERT_EQUAL(4,m->getNumberOfCells());
2439 CPPUNIT_ASSERT_EQUAL(3,m->getSpaceDimension());
2440 CPPUNIT_ASSERT_EQUAL(0,m->getMeshDimension());
2441 std::set<INTERP_KERNEL::NormalizedCellType> types=m->getAllGeoTypes();
2442 CPPUNIT_ASSERT_EQUAL(1,(int)types.size());
2443 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POINT1,*types.begin());
2444 for(int i=0;i<4;i++)
2446 std::vector<int> conn;
2447 m->getNodeIdsOfCell(i,conn);
2448 CPPUNIT_ASSERT_EQUAL(1,(int)conn.size());
2449 CPPUNIT_ASSERT_EQUAL(i,conn[0]);
2450 CPPUNIT_ASSERT(INTERP_KERNEL::NORM_POINT1==m->getTypeOfCell(i));
2452 CPPUNIT_ASSERT(std::string(m->getName())=="My0D");