1 // Copyright (C) 2007-2019 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 "MEDCouplingMemArray.txx"
28 #include "MEDCouplingGaussLocalization.hxx"
34 using namespace MEDCoupling;
36 void MEDCouplingBasicsTest3::testGetMeasureFieldCMesh1()
38 MEDCouplingCMesh *m=MEDCouplingCMesh::New();
39 DataArrayDouble *da=DataArrayDouble::New();
40 const double discX[4]={2.3,3.4,5.8,10.2};
41 const double discY[3]={12.3,23.4,45.8};
42 const double discZ[5]={-0.7,1.2,1.25,2.13,2.67};
44 std::copy(discX,discX+4,da->getPointer());
47 m->checkConsistencyLight();
48 CPPUNIT_ASSERT_EQUAL(4,(int)m->getNumberOfNodes());
49 CPPUNIT_ASSERT_EQUAL(3,(int)m->getNumberOfCells());
50 CPPUNIT_ASSERT_EQUAL(1,m->getSpaceDimension());
51 MEDCouplingFieldDouble *f=m->getMeasureField(true);
52 CPPUNIT_ASSERT_EQUAL(3,(int)f->getNumberOfTuples());
53 CPPUNIT_ASSERT_EQUAL(1,(int)f->getNumberOfComponents());
54 const double expected1[3]={1.1,2.4,4.4};
56 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f->getIJ(i,0),1e-12);
58 DataArrayDouble *coords=m->getCoordinatesAndOwner();
59 CPPUNIT_ASSERT_EQUAL(4,(int)coords->getNumberOfTuples());
60 CPPUNIT_ASSERT_EQUAL(1,(int)coords->getNumberOfComponents());
62 CPPUNIT_ASSERT_DOUBLES_EQUAL(discX[i],coords->getIJ(i,0),1e-12);
64 coords=m->computeCellCenterOfMass();
65 CPPUNIT_ASSERT_EQUAL(3,(int)coords->getNumberOfTuples());
66 CPPUNIT_ASSERT_EQUAL(1,(int)coords->getNumberOfComponents());
67 const double expected1_3[3]={2.85,4.6,8.};
69 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1_3[i],coords->getIJ(i,0),1e-12);
72 da=DataArrayDouble::New();
74 std::copy(discY,discY+3,da->getPointer());
77 m->checkConsistencyLight();
78 CPPUNIT_ASSERT_EQUAL(12,(int)m->getNumberOfNodes());
79 CPPUNIT_ASSERT_EQUAL(6,(int)m->getNumberOfCells());
80 CPPUNIT_ASSERT_EQUAL(2,m->getSpaceDimension());
81 f=m->getMeasureField(true);
82 CPPUNIT_ASSERT_EQUAL(6,(int)f->getNumberOfTuples());
83 CPPUNIT_ASSERT_EQUAL(1,(int)f->getNumberOfComponents());
84 const double expected2[6]={12.21,26.64,48.84,24.64,53.76,98.56};
86 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(i,0),1e-12);
88 coords=m->getCoordinatesAndOwner();
89 CPPUNIT_ASSERT_EQUAL(12,(int)coords->getNumberOfTuples());
90 CPPUNIT_ASSERT_EQUAL(2,(int)coords->getNumberOfComponents());
91 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};
93 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2_2[i],coords->getIJ(0,i),1e-12);
95 coords=m->computeCellCenterOfMass();
96 CPPUNIT_ASSERT_EQUAL(6,(int)coords->getNumberOfTuples());
97 CPPUNIT_ASSERT_EQUAL(2,(int)coords->getNumberOfComponents());
98 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};
100 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2_3[i],coords->getIJ(0,i),1e-12);
103 da=DataArrayDouble::New();
105 std::copy(discZ,discZ+5,da->getPointer());
106 m->setCoordsAt(2,da);
108 m->checkConsistencyLight();
109 CPPUNIT_ASSERT_EQUAL(60,(int)m->getNumberOfNodes());
110 CPPUNIT_ASSERT_EQUAL(24,(int)m->getNumberOfCells());
111 CPPUNIT_ASSERT_EQUAL(3,m->getSpaceDimension());
112 f=m->getMeasureField(true);
113 CPPUNIT_ASSERT_EQUAL(24,(int)f->getNumberOfTuples());
114 CPPUNIT_ASSERT_EQUAL(1,(int)f->getNumberOfComponents());
115 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};
116 for(int i=0;i<24;i++)
117 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],f->getIJ(i,0),1e-12);
119 coords=m->getCoordinatesAndOwner();
120 CPPUNIT_ASSERT_EQUAL(60,(int)coords->getNumberOfTuples());
121 CPPUNIT_ASSERT_EQUAL(3,(int)coords->getNumberOfComponents());
122 const double expected3_2[180]={
123 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,
124 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,
125 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,
126 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,
127 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
129 for(int i=0;i<180;i++)
130 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3_2[i],coords->getIJ(0,i),1e-12);
132 coords=m->computeCellCenterOfMass();
133 CPPUNIT_ASSERT_EQUAL(24,(int)coords->getNumberOfTuples());
134 CPPUNIT_ASSERT_EQUAL(3,(int)coords->getNumberOfComponents());
135 const double expected3_3[72]={
136 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,
137 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,
138 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,
139 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
141 for(int i=0;i<72;i++)
142 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3_3[i],coords->getIJ(0,i),1e-12);
148 void MEDCouplingBasicsTest3::testFieldDoubleZipCoords1()
150 MEDCouplingUMesh *m=build2DTargetMeshMergeNode_1();
151 MEDCouplingFieldDouble *f=m->fillFromAnalytic(ON_NODES,2,"x*2.");
152 f->getArray()->setInfoOnComponent(0,"titi");
153 f->getArray()->setInfoOnComponent(1,"tutu");
154 f->checkConsistencyLight();
155 CPPUNIT_ASSERT_EQUAL(18,(int)f->getNumberOfTuples());
156 CPPUNIT_ASSERT_EQUAL(2,(int)f->getNumberOfComponents());
157 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};
158 for(int i=0;i<36;i++)
159 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f->getIJ(0,i),1e-12);
160 CPPUNIT_ASSERT(f->zipCoords());
161 f->checkConsistencyLight();
162 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};
163 for(int i=0;i<30;i++)
164 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(0,i),1e-12);
165 CPPUNIT_ASSERT(!f->zipCoords());
166 f->checkConsistencyLight();
167 for(int i=0;i<30;i++)
168 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(0,i),1e-12);
169 CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(0))=="titi");
170 CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(1))=="tutu");
175 void MEDCouplingBasicsTest3::testFieldDoubleZipConnectivity1()
177 MEDCouplingUMesh *m1=build2DTargetMesh_1();
178 MEDCouplingUMesh *m2=build2DTargetMesh_1();
179 const mcIdType cells1[3]={2,3,4};
180 MEDCouplingPointSet *m3_1=m2->buildPartOfMySelf(cells1,cells1+3,true);
181 MEDCouplingUMesh *m3=dynamic_cast<MEDCouplingUMesh *>(m3_1);
184 MEDCouplingUMesh *m4=build2DSourceMesh_1();
185 MEDCouplingUMesh *m5=MEDCouplingUMesh::MergeUMeshes(m1,m3);
188 MEDCouplingUMesh *m6=MEDCouplingUMesh::MergeUMeshes(m5,m4);
192 CPPUNIT_ASSERT_EQUAL(10,(int)m6->getNumberOfCells());
193 CPPUNIT_ASSERT_EQUAL(22,(int)m6->getNumberOfNodes());
195 mcIdType newNbOfNodes;
196 DataArrayIdType *arr=m6->mergeNodes(1e-13,areNodesMerged,newNbOfNodes);
197 CPPUNIT_ASSERT_EQUAL(9,(int)m6->getNumberOfNodes());
199 MEDCouplingFieldDouble *f=m6->fillFromAnalytic(ON_CELLS,2,"x");
200 MEDCouplingFieldDouble *f2=m6->fillFromAnalytic(ON_NODES,2,"x");
201 CPPUNIT_ASSERT_EQUAL(10,(int)f->getNumberOfTuples());
202 CPPUNIT_ASSERT_EQUAL(2,(int)f->getNumberOfComponents());
203 const double expected1[20]={-0.05, -0.05, 0.3666666666666667, 0.3666666666666667, 0.53333333333333321, 0.53333333333333321,
204 -0.05, -0.05, 0.45, 0.45, 0.53333333333333321, 0.53333333333333321, -0.05, -0.05, 0.45, 0.45,
205 0.36666666666666659, 0.36666666666666659, 0.033333333333333326, 0.033333333333333326};
206 for(int i=0;i<20;i++)
207 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f->getIJ(0,i),1e-12);
208 f->getArray()->setInfoOnComponent(0,"titi");
209 f->getArray()->setInfoOnComponent(1,"tutu");
210 f->checkConsistencyLight();
211 CPPUNIT_ASSERT(f->zipConnectivity(0));
212 const double expected2[14]={-0.05, -0.05, 0.3666666666666667, 0.3666666666666667, 0.53333333333333321, 0.53333333333333321,
213 -0.05, -0.05, 0.45, 0.45, 0.36666666666666659, 0.36666666666666659, 0.033333333333333326, 0.033333333333333326};
214 CPPUNIT_ASSERT_EQUAL(7,(int)f->getNumberOfTuples());
215 CPPUNIT_ASSERT_EQUAL(2,(int)f->getNumberOfComponents());
216 for(int i=0;i<14;i++)
217 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(0,i),1e-12);
218 CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(0))=="titi");
219 CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(1))=="tutu");
220 CPPUNIT_ASSERT(!f->zipConnectivity(0));
223 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,
224 -0.3, -0.3, 0.2, 0.2, 0.7, 0.7};
225 CPPUNIT_ASSERT_EQUAL(9,(int)f2->getNumberOfTuples());
226 CPPUNIT_ASSERT_EQUAL(2,(int)f2->getNumberOfComponents());
227 for(int i=0;i<18;i++)
228 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],f2->getIJ(0,i),1e-12);
229 CPPUNIT_ASSERT(f2->zipConnectivity(0));
230 CPPUNIT_ASSERT_EQUAL(9,(int)f2->getNumberOfTuples());
231 CPPUNIT_ASSERT_EQUAL(2,(int)f2->getNumberOfComponents());
232 for(int i=0;i<18;i++)
233 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],f2->getIJ(0,i),1e-12);
239 void MEDCouplingBasicsTest3::testDaDoubleRenumber1()
241 DataArrayDouble *a=DataArrayDouble::New();
243 a->setInfoOnComponent(0,"toto");
244 a->setInfoOnComponent(1,"tata");
245 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};
246 std::copy(arr1,arr1+14,a->getPointer());
248 const mcIdType arr2[7]={3,1,0,6,5,4,2};
249 DataArrayDouble *b=a->renumber(arr2);
250 CPPUNIT_ASSERT_EQUAL(7,(int)b->getNumberOfTuples());
251 CPPUNIT_ASSERT_EQUAL(2,(int)b->getNumberOfComponents());
252 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
253 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
254 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};
255 for(int i=0;i<14;i++)
256 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
260 DataArrayIdType *c=DataArrayIdType::New();
262 c->setInfoOnComponent(0,"toto");
263 c->setInfoOnComponent(1,"tata");
264 const mcIdType arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
265 std::copy(arr3,arr3+14,c->getPointer());
266 DataArrayIdType *d=c->renumber(arr2);
267 CPPUNIT_ASSERT_EQUAL(7,(int)d->getNumberOfTuples());
268 CPPUNIT_ASSERT_EQUAL(2,(int)d->getNumberOfComponents());
269 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
270 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
271 const mcIdType expected2[14]={3, 13, 2, 12, 7, 17, 1, 11, 6, 16, 5, 15, 4, 14};
272 for(int i=0;i<14;i++)
273 CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
278 void MEDCouplingBasicsTest3::testDaDoubleRenumberAndReduce1()
280 DataArrayDouble *a=DataArrayDouble::New();
282 a->setInfoOnComponent(0,"toto");
283 a->setInfoOnComponent(1,"tata");
284 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};
285 std::copy(arr1,arr1+14,a->getPointer());
287 const mcIdType arr2[7]={2,-1,1,-1,0,4,3};
288 DataArrayDouble *b=a->renumberAndReduce(arr2,5);
289 CPPUNIT_ASSERT_EQUAL(5,(int)b->getNumberOfTuples());
290 CPPUNIT_ASSERT_EQUAL(2,(int)b->getNumberOfComponents());
291 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
292 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
293 const double expected1[10]={5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1};
294 for(int i=0;i<10;i++)
295 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
299 DataArrayIdType *c=DataArrayIdType::New();
301 c->setInfoOnComponent(0,"toto");
302 c->setInfoOnComponent(1,"tata");
303 const mcIdType arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
304 std::copy(arr3,arr3+14,c->getPointer());
305 DataArrayIdType *d=c->renumberAndReduce(arr2,5);
306 CPPUNIT_ASSERT_EQUAL(5,(int)d->getNumberOfTuples());
307 CPPUNIT_ASSERT_EQUAL(2,(int)d->getNumberOfComponents());
308 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
309 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
310 const mcIdType expected2[10]={5,15,3,13,1,11,7,17,6,16};
311 for(int i=0;i<10;i++)
312 CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
317 void MEDCouplingBasicsTest3::testDaDoubleRenumberInPlace1()
319 DataArrayDouble *a=DataArrayDouble::New();
321 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};
322 std::copy(arr1,arr1+14,a->getPointer());
324 const mcIdType arr2[7]={3,1,0,6,5,4,2};
325 a->renumberInPlace(arr2);
326 CPPUNIT_ASSERT_EQUAL(7,(int)a->getNumberOfTuples());
327 CPPUNIT_ASSERT_EQUAL(2,(int)a->getNumberOfComponents());
328 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};
329 for(int i=0;i<14;i++)
330 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],a->getIJ(0,i),1e-14);
333 DataArrayIdType *c=DataArrayIdType::New();
335 const mcIdType arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
336 std::copy(arr3,arr3+14,c->getPointer());
337 c->renumberInPlace(arr2);
338 CPPUNIT_ASSERT_EQUAL(7,(int)c->getNumberOfTuples());
339 CPPUNIT_ASSERT_EQUAL(2,(int)c->getNumberOfComponents());
340 const mcIdType expected2[14]={3, 13, 2, 12, 7, 17, 1, 11, 6, 16, 5, 15, 4, 14};
341 for(int i=0;i<14;i++)
342 CPPUNIT_ASSERT_EQUAL(expected2[i],c->getIJ(0,i));
346 void MEDCouplingBasicsTest3::testDaDoubleRenumberR1()
348 DataArrayDouble *a=DataArrayDouble::New();
350 a->setInfoOnComponent(0,"toto");
351 a->setInfoOnComponent(1,"tata");
352 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};
353 std::copy(arr1,arr1+14,a->getPointer());
355 const mcIdType arr2[7]={3,1,0,6,5,4,2};
356 DataArrayDouble *b=a->renumberR(arr2);
357 CPPUNIT_ASSERT_EQUAL(7,(int)b->getNumberOfTuples());
358 CPPUNIT_ASSERT_EQUAL(2,(int)b->getNumberOfComponents());
359 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
360 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
361 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};
362 for(int i=0;i<14;i++)
363 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
367 DataArrayIdType *c=DataArrayIdType::New();
369 c->setInfoOnComponent(0,"toto");
370 c->setInfoOnComponent(1,"tata");
371 const mcIdType arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
372 std::copy(arr3,arr3+14,c->getPointer());
373 DataArrayIdType *d=c->renumberR(arr2);
374 CPPUNIT_ASSERT_EQUAL(7,(int)d->getNumberOfTuples());
375 CPPUNIT_ASSERT_EQUAL(2,(int)d->getNumberOfComponents());
376 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
377 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
378 const mcIdType expected2[14]={4, 14, 2, 12, 1, 11, 7, 17, 6, 16, 5, 15, 3, 13};
379 for(int i=0;i<14;i++)
380 CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
385 void MEDCouplingBasicsTest3::testDaDoubleRenumberInPlaceR1()
387 DataArrayDouble *a=DataArrayDouble::New();
389 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};
390 std::copy(arr1,arr1+14,a->getPointer());
392 const mcIdType arr2[7]={3,1,0,6,5,4,2};
393 a->renumberInPlaceR(arr2);
394 CPPUNIT_ASSERT_EQUAL(7,(int)a->getNumberOfTuples());
395 CPPUNIT_ASSERT_EQUAL(2,(int)a->getNumberOfComponents());
396 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};
397 for(int i=0;i<14;i++)
398 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],a->getIJ(0,i),1e-14);
401 DataArrayIdType *c=DataArrayIdType::New();
403 const mcIdType arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
404 std::copy(arr3,arr3+14,c->getPointer());
405 c->renumberInPlaceR(arr2);
406 CPPUNIT_ASSERT_EQUAL(7,(int)c->getNumberOfTuples());
407 CPPUNIT_ASSERT_EQUAL(2,(int)c->getNumberOfComponents());
408 const mcIdType expected2[14]={4, 14, 2, 12, 1, 11, 7, 17, 6, 16, 5, 15, 3, 13};
409 for(int i=0;i<14;i++)
410 CPPUNIT_ASSERT_EQUAL(expected2[i],c->getIJ(0,i));
414 void MEDCouplingBasicsTest3::testDaDoubleSelectByTupleId1()
416 DataArrayDouble *a=DataArrayDouble::New();
418 a->setInfoOnComponent(0,"toto");
419 a->setInfoOnComponent(1,"tata");
420 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};
421 std::copy(arr1,arr1+14,a->getPointer());
423 const mcIdType arr2[7]={4,2,0,6,5};
424 DataArrayDouble *b=a->selectByTupleId(arr2,arr2+5);
425 CPPUNIT_ASSERT_EQUAL(5,(int)b->getNumberOfTuples());
426 CPPUNIT_ASSERT_EQUAL(2,(int)b->getNumberOfComponents());
427 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
428 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
429 const double expected1[10]={5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1};
430 for(int i=0;i<10;i++)
431 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
435 DataArrayIdType *c=DataArrayIdType::New();
437 c->setInfoOnComponent(0,"toto");
438 c->setInfoOnComponent(1,"tata");
439 const mcIdType arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
440 std::copy(arr3,arr3+14,c->getPointer());
441 DataArrayIdType *d=c->selectByTupleId(arr2,arr2+5);
442 CPPUNIT_ASSERT_EQUAL(5,(int)d->getNumberOfTuples());
443 CPPUNIT_ASSERT_EQUAL(2,(int)d->getNumberOfComponents());
444 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
445 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
446 const mcIdType expected2[10]={5,15,3,13,1,11,7,17,6,16};
447 for(int i=0;i<10;i++)
448 CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
453 void MEDCouplingBasicsTest3::testDaDoubleGetMinMaxValues1()
455 DataArrayDouble *a=DataArrayDouble::New();
457 const double arr1[9]={2.34,4.56,-6.77,4.55,4.56,2.24,2.34,1.02,4.56};
458 std::copy(arr1,arr1+9,a->getPointer());
460 double m=a->getMaxValue(where);
461 CPPUNIT_ASSERT_EQUAL(ToIdType(1),where);
462 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.56,m,1e-12);
464 m=a->getMaxValue2(ws);
465 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.56,m,1e-12);
466 CPPUNIT_ASSERT_EQUAL(3,(int)ws->getNumberOfTuples());
467 CPPUNIT_ASSERT_EQUAL(1,(int)ws->getNumberOfComponents());
468 const mcIdType expected1[3]={1,4,8};
470 CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
473 a=DataArrayDouble::New();
474 const double arr2[9]={-2.34,-4.56,6.77,-4.55,-4.56,-2.24,-2.34,-1.02,-4.56};
476 std::copy(arr2,arr2+9,a->getPointer());
478 m=a->getMinValue(where);
479 CPPUNIT_ASSERT_EQUAL(ToIdType(1),where);
480 CPPUNIT_ASSERT_DOUBLES_EQUAL(-4.56,m,1e-12);
481 m=a->getMinValue2(ws);
482 CPPUNIT_ASSERT_DOUBLES_EQUAL(-4.56,m,1e-12);
483 CPPUNIT_ASSERT_EQUAL(3,(int)ws->getNumberOfTuples());
484 CPPUNIT_ASSERT_EQUAL(1,(int)ws->getNumberOfComponents());
486 CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
491 void MEDCouplingBasicsTest3::testFieldDoubleGetMinMaxValues2()
493 MEDCouplingUMesh *m1=0;
494 MEDCouplingUMesh *m2=build3DExtrudedUMesh_1(m1);
496 CPPUNIT_ASSERT_EQUAL(18,(int)m2->getNumberOfCells());
497 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};
498 MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
499 DataArrayDouble *a=DataArrayDouble::New();
501 std::copy(arr1,arr1+18,a->getPointer());
506 f->checkConsistencyLight();
507 double m=f->getMaxValue();
508 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.71,m,1e-12);
510 m=f->getMaxValue2(ws);
511 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.71,m,1e-12);
512 CPPUNIT_ASSERT_EQUAL(4,(int)ws->getNumberOfTuples());
513 CPPUNIT_ASSERT_EQUAL(1,(int)ws->getNumberOfComponents());
514 const mcIdType expected1[4]={0,3,7,17};
516 CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
519 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};
520 std::copy(arr2,arr2+18,a->getPointer());
521 f->checkConsistencyLight();
523 CPPUNIT_ASSERT_DOUBLES_EQUAL(-8.71,m,1e-12);
524 m=f->getMinValue2(ws);
525 CPPUNIT_ASSERT_DOUBLES_EQUAL(-8.71,m,1e-12);
526 CPPUNIT_ASSERT_EQUAL(4,(int)ws->getNumberOfTuples());
527 CPPUNIT_ASSERT_EQUAL(1,(int)ws->getNumberOfComponents());
529 CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
536 void MEDCouplingBasicsTest3::testBuildUnstructuredCMesh1()
538 MEDCouplingCMesh *m=MEDCouplingCMesh::New();
539 DataArrayDouble *da=DataArrayDouble::New();
540 const double discX[4]={2.3,3.4,5.8,10.2};
541 const double discY[3]={12.3,23.4,45.8};
542 const double discZ[5]={-0.7,1.2,1.25,2.13,2.67};
544 std::copy(discX,discX+4,da->getPointer());
545 m->setCoordsAt(0,da);
547 m->checkConsistencyLight();
549 CPPUNIT_ASSERT_EQUAL(ToIdType(0),m->getCellContainingPoint(&pos,1e-12));
551 CPPUNIT_ASSERT_EQUAL(ToIdType(1),m->getCellContainingPoint(&pos,1e-12));
553 CPPUNIT_ASSERT_EQUAL(ToIdType(2),m->getCellContainingPoint(&pos,1e-12));
555 CPPUNIT_ASSERT_EQUAL(ToIdType(-1),m->getCellContainingPoint(&pos,1e-12));
557 CPPUNIT_ASSERT_EQUAL(ToIdType(-1),m->getCellContainingPoint(&pos,1e-12));
559 MEDCouplingUMesh *m2=m->buildUnstructured();
560 m2->checkConsistencyLight();
561 MEDCouplingFieldDouble *f1=m->getMeasureField(false);
562 MEDCouplingFieldDouble *f2=m2->getMeasureField(false);
563 CPPUNIT_ASSERT_EQUAL((int)f1->getNumberOfTuples(),3);
564 CPPUNIT_ASSERT_EQUAL((int)f2->getNumberOfTuples(),3);
565 CPPUNIT_ASSERT_EQUAL(1,m2->getMeshDimension());
566 CPPUNIT_ASSERT_EQUAL(1,m2->getSpaceDimension());
568 CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getIJ(i,0),f2->getIJ(i,0),1e-10);
569 da=DataArrayDouble::New();
571 std::copy(discY,discY+3,da->getPointer());
572 m->setCoordsAt(1,da);
578 m2=m->buildUnstructured();
579 m2->checkConsistencyLight();
580 f1=m->getMeasureField(false);
581 f2=m2->getMeasureField(false);
582 CPPUNIT_ASSERT_EQUAL((int)f1->getNumberOfTuples(),6);
583 CPPUNIT_ASSERT_EQUAL((int)f2->getNumberOfTuples(),6);
584 CPPUNIT_ASSERT_EQUAL(2,m2->getMeshDimension());
585 CPPUNIT_ASSERT_EQUAL(2,m2->getSpaceDimension());
587 CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getIJ(i,0),f2->getIJ(i,0),1e-10);
592 da=DataArrayDouble::New();
594 std::copy(discZ,discZ+5,da->getPointer());
595 m->setCoordsAt(2,da);
597 m2=m->buildUnstructured();
598 m2->checkConsistencyLight();
599 f1=m->getMeasureField(false);
600 f2=m2->getMeasureField(false);
601 CPPUNIT_ASSERT_EQUAL((int)f1->getNumberOfTuples(),24);
602 CPPUNIT_ASSERT_EQUAL((int)f2->getNumberOfTuples(),24);
603 CPPUNIT_ASSERT_EQUAL(3,m2->getMeshDimension());
604 CPPUNIT_ASSERT_EQUAL(3,m2->getSpaceDimension());
605 for(int i=0;i<24;i++)
606 CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getIJ(i,0),f2->getIJ(i,0),1e-10);
610 double pos1[3]={5.,30.,2.};
611 CPPUNIT_ASSERT_EQUAL(ToIdType(16),m->getCellContainingPoint(pos1,1e-12));
613 const double pt[3]={2.4,12.7,-3.4};
615 MEDCouplingUMesh *m3=m->buildUnstructured();
617 CPPUNIT_ASSERT(m3->isEqual(m2,1e-12));
624 void MEDCouplingBasicsTest3::testDataArrayIntInvertO2NNO21()
626 const mcIdType arr1[6]={2,0,4,1,5,3};
627 DataArrayIdType *da=DataArrayIdType::New();
629 std::copy(arr1,arr1+6,da->getPointer());
630 DataArrayIdType *da2=da->invertArrayO2N2N2O(6);
631 CPPUNIT_ASSERT_EQUAL(6,(int)da2->getNumberOfTuples());
632 CPPUNIT_ASSERT_EQUAL(1,(int)da2->getNumberOfComponents());
633 const mcIdType expected1[6]={1,3,0,5,2,4};
635 CPPUNIT_ASSERT_EQUAL(expected1[i],da2->getIJ(i,0));
636 DataArrayIdType *da3=da2->invertArrayN2O2O2N(6);
638 CPPUNIT_ASSERT_EQUAL(arr1[i],da3->getIJ(i,0));
643 const mcIdType arr2[10]={3,-1,5,4,-1,0,-1,1,2,-1};
644 da=DataArrayIdType::New();
646 std::copy(arr2,arr2+10,da->getPointer());
647 da2=da->invertArrayO2N2N2O(6);
648 CPPUNIT_ASSERT_EQUAL(6,(int)da2->getNumberOfTuples());
649 CPPUNIT_ASSERT_EQUAL(1,(int)da2->getNumberOfComponents());
650 const mcIdType expected2[10]={5,7,8,0,3,2};
652 CPPUNIT_ASSERT_EQUAL(expected2[i],da2->getIJ(i,0));
653 da3=da2->invertArrayN2O2O2N(10);
654 for(int i=0;i<10;i++)
655 CPPUNIT_ASSERT_EQUAL(arr2[i],da3->getIJ(i,0));
661 void MEDCouplingBasicsTest3::testKeepSetSelectedComponent1()
663 const double arr1[20]={1.,2.,3.,4., 11.,12.,13.,14., 21.,22.,23.,24., 31.,32.,33.,34., 41.,42.,43.,44.};
664 DataArrayDouble *a1=DataArrayDouble::New();
666 std::copy(arr1,arr1+20,a1->getPointer());
667 a1->setInfoOnComponent(0,"aaaa");
668 a1->setInfoOnComponent(1,"bbbb");
669 a1->setInfoOnComponent(2,"cccc");
670 a1->setInfoOnComponent(3,"dddd");
671 const mcIdType arr2[6]={1,2,1,2,0,0};
672 std::vector<std::size_t> arr2V(arr2,arr2+6);
673 DataArrayDouble *a2=static_cast<DataArrayDouble *>(a1->keepSelectedComponents(arr2V));
674 CPPUNIT_ASSERT_EQUAL(6,(int)a2->getNumberOfComponents());
675 CPPUNIT_ASSERT_EQUAL(5,(int)a2->getNumberOfTuples());
676 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(0))=="bbbb");
677 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(1))=="cccc");
678 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(2))=="bbbb");
679 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(3))=="cccc");
680 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(4))=="aaaa");
681 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(5))=="aaaa");
682 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.};
683 for(int i=0;i<30;i++)
684 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],a2->getIJ(0,i),1e-14);
685 MCAuto<DataArrayInt> a3(a1->convertToIntArr());
686 DataArrayInt *a4=static_cast<DataArrayInt *>(a3->keepSelectedComponents(arr2V));
687 CPPUNIT_ASSERT_EQUAL(6,(int)a4->getNumberOfComponents());
688 CPPUNIT_ASSERT_EQUAL(5,(int)a4->getNumberOfTuples());
689 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(0))=="bbbb");
690 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(1))=="cccc");
691 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(2))=="bbbb");
692 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(3))=="cccc");
693 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(4))=="aaaa");
694 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(5))=="aaaa");
695 for(int i=0;i<30;i++)
696 CPPUNIT_ASSERT_EQUAL((int)expected1[i],a4->getIJ(0,i));
697 // setSelectedComponents
698 const mcIdType arr3[2]={3,2};
699 std::vector<std::size_t> arr3V(arr3,arr3+2);
700 DataArrayDouble *a5=static_cast<DataArrayDouble *>(a1->keepSelectedComponents(arr3V));
701 a5->setInfoOnComponent(0,"eeee");
702 a5->setInfoOnComponent(1,"ffff");
703 const mcIdType arr4[2]={1,2};
704 std::vector<std::size_t> arr4V(arr4,arr4+2);
705 a2->setSelectedComponents(a5,arr4V);
706 CPPUNIT_ASSERT_EQUAL(6,(int)a2->getNumberOfComponents());
707 CPPUNIT_ASSERT_EQUAL(5,(int)a2->getNumberOfTuples());
708 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(0))=="bbbb");
709 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(1))=="eeee");
710 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(2))=="ffff");
711 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(3))=="cccc");
712 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(4))=="aaaa");
713 CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(5))=="aaaa");
714 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.};
715 for(int i=0;i<30;i++)
716 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],a2->getIJ(0,i),1e-14);
717 MCAuto<DataArrayInt> a6=a5->convertToIntArr();
718 a6->setInfoOnComponent(0,"eeee");
719 a6->setInfoOnComponent(1,"ffff");
720 a4->setSelectedComponents(a6,arr4V);
721 CPPUNIT_ASSERT_EQUAL(6,(int)a4->getNumberOfComponents());
722 CPPUNIT_ASSERT_EQUAL(5,(int)a4->getNumberOfTuples());
723 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(0))=="bbbb");
724 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(1))=="eeee");
725 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(2))=="ffff");
726 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(3))=="cccc");
727 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(4))=="aaaa");
728 CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(5))=="aaaa");
729 for(int i=0;i<30;i++)
730 CPPUNIT_ASSERT_EQUAL(expected2[i],(double)a4->getIJ(0,i));
732 const mcIdType arr5[3]={2,3,6};
733 const mcIdType arr6[3]={2,7,5};
734 const mcIdType arr7[4]={2,1,4,6};
735 std::vector<std::size_t> arr5V(arr5,arr5+3);
736 std::vector<std::size_t> arr6V(arr6,arr6+3);
737 std::vector<std::size_t> arr7V(arr7,arr7+4);
738 CPPUNIT_ASSERT_THROW(a2->keepSelectedComponents(arr5V),INTERP_KERNEL::Exception);
739 CPPUNIT_ASSERT_THROW(a2->keepSelectedComponents(arr6V),INTERP_KERNEL::Exception);
740 CPPUNIT_ASSERT_THROW(a2->setSelectedComponents(a1,arr7V),INTERP_KERNEL::Exception);
742 CPPUNIT_ASSERT_THROW(a2->setSelectedComponents(a1,arr7V),INTERP_KERNEL::Exception);
750 void MEDCouplingBasicsTest3::testKeepSetSelectedComponent2()
752 MEDCouplingUMesh *m1=build2DTargetMesh_1();
753 const double arr1[20]={1.,2.,3.,4., 11.,12.,13.,14., 21.,22.,23.,24., 31.,32.,33.,34., 41.,42.,43.,44.};
754 DataArrayDouble *a1=DataArrayDouble::New();
756 std::copy(arr1,arr1+20,a1->getPointer());
757 a1->setInfoOnComponent(0,"aaaa");
758 a1->setInfoOnComponent(1,"bbbb");
759 a1->setInfoOnComponent(2,"cccc");
760 a1->setInfoOnComponent(3,"dddd");
761 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
762 f1->setTime(2.3,4,5);
766 f1->checkConsistencyLight();
768 const mcIdType arr2[6]={1,2,1,2,0,0};
769 std::vector<std::size_t> arr2V(arr2,arr2+6);
770 MEDCouplingFieldDouble *f2=f1->keepSelectedComponents(arr2V);
771 CPPUNIT_ASSERT(f2->getMesh()==f1->getMesh());
772 CPPUNIT_ASSERT(f2->getTimeDiscretization()==ONE_TIME);
774 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.3,f2->getTime(dt,it),1e-13);
775 CPPUNIT_ASSERT_EQUAL(4,dt);
776 CPPUNIT_ASSERT_EQUAL(5,it);
777 f2->checkConsistencyLight();
778 CPPUNIT_ASSERT_EQUAL(6,(int)f2->getNumberOfComponents());
779 CPPUNIT_ASSERT_EQUAL(5,(int)f2->getNumberOfTuples());
780 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(0))=="bbbb");
781 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(1))=="cccc");
782 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(2))=="bbbb");
783 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(3))=="cccc");
784 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(4))=="aaaa");
785 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(5))=="aaaa");
786 const double expected1[30]={2.,3.,2.,3.,1.,1., 12.,13.,12.,13.,11.,11., 22.,23.,22.,23.,21.,21., 32.,33.,32.,33.,31.,31., 42.,43.,42.,43.,41.,41.};
787 for(int i=0;i<30;i++)
788 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f2->getIJ(0,i),1e-14);
789 //setSelectedComponents
790 const mcIdType arr3[2]={3,2};
791 std::vector<std::size_t> arr3V(arr3,arr3+2);
792 MEDCouplingFieldDouble *f5=f1->keepSelectedComponents(arr3V);
793 f5->setTime(6.7,8,9);
794 f5->getArray()->setInfoOnComponent(0,"eeee");
795 f5->getArray()->setInfoOnComponent(1,"ffff");
796 f5->checkConsistencyLight();
797 const mcIdType arr4[2]={1,2};
798 std::vector<std::size_t> arr4V(arr4,arr4+2);
799 f2->setSelectedComponents(f5,arr4V);
800 CPPUNIT_ASSERT_EQUAL(6,(int)f2->getNumberOfComponents());
801 CPPUNIT_ASSERT_EQUAL(5,(int)f2->getNumberOfTuples());
802 f2->checkConsistencyLight();
803 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.3,f2->getTime(dt,it),1e-13);
804 CPPUNIT_ASSERT_EQUAL(4,dt);
805 CPPUNIT_ASSERT_EQUAL(5,it);
806 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(0))=="bbbb");
807 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(1))=="eeee");
808 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(2))=="ffff");
809 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(3))=="cccc");
810 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(4))=="aaaa");
811 CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(5))=="aaaa");
812 const double expected2[30]={2.,4.,3.,3.,1.,1., 12.,14.,13.,13.,11.,11., 22.,24.,23.,23.,21.,21., 32.,34.,33.,33.,31.,31., 42.,44.,43.,43.,41.,41.};
813 for(int i=0;i<30;i++)
814 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f2->getIJ(0,i),1e-14);
822 void MEDCouplingBasicsTest3::testElementaryDAThrowAndSpecialCases()
824 DataArrayIdType *da=DataArrayIdType::New();
825 CPPUNIT_ASSERT_THROW(da->checkAllocated(),INTERP_KERNEL::Exception);
826 CPPUNIT_ASSERT_THROW(da->fillWithValue(1),INTERP_KERNEL::Exception);
827 CPPUNIT_ASSERT_THROW(da->iota(1),INTERP_KERNEL::Exception);
829 da->fillWithValue(11); //11,11,11,11...
830 da->iota(10); //10,11,12,13...
832 DataArrayIdType *db=DataArrayIdType::New();
835 DataArrayDouble *dbl2=DataArrayDouble::New();
837 CPPUNIT_ASSERT_THROW(dbl2->isUniform(10.,1e-15),INTERP_KERNEL::Exception);
838 CPPUNIT_ASSERT_THROW(dbl2->sort(),INTERP_KERNEL::Exception);
839 CPPUNIT_ASSERT_THROW(dbl2->iota(10.),INTERP_KERNEL::Exception);
841 DataArrayDouble *dbl=DataArrayDouble::New();
842 //DataArrayDouble not allocated yet
843 CPPUNIT_ASSERT_THROW(dbl->iota(10.),INTERP_KERNEL::Exception);
844 CPPUNIT_ASSERT_THROW(dbl->isUniform(10.,1e-15),INTERP_KERNEL::Exception);
845 CPPUNIT_ASSERT_THROW(dbl->sort(),INTERP_KERNEL::Exception);
846 CPPUNIT_ASSERT_THROW(dbl->reverse(),INTERP_KERNEL::Exception);
847 CPPUNIT_ASSERT_THROW(dbl->fromNoInterlace(),INTERP_KERNEL::Exception);
848 CPPUNIT_ASSERT_THROW(dbl->toNoInterlace(),INTERP_KERNEL::Exception);
852 CPPUNIT_ASSERT(!dbl->isUniform(10.,1e-15));
854 CPPUNIT_ASSERT(dbl->isMonotonic(true, .99));
855 CPPUNIT_ASSERT(dbl->isMonotonic(true, -.99));
856 CPPUNIT_ASSERT(!dbl->isMonotonic(true, 1.1));
857 CPPUNIT_ASSERT(!dbl->isMonotonic(true, -1.1));
859 CPPUNIT_ASSERT(dbl->isMonotonic(false, .99));
860 CPPUNIT_ASSERT(!dbl->isMonotonic(false, 1.1));
861 CPPUNIT_ASSERT(!dbl->isMonotonic(false, -1.1));
863 DataArrayIdType *dc=DataArrayIdType::New();
866 DataArrayDouble *dd=DataArrayDouble::New();
867 CPPUNIT_ASSERT_THROW(dd->checkAllocated(),INTERP_KERNEL::Exception);
868 CPPUNIT_ASSERT_THROW(dd->fillWithValue(1.),INTERP_KERNEL::Exception);
869 CPPUNIT_ASSERT_THROW(dd->iota(1.),INTERP_KERNEL::Exception);
870 CPPUNIT_ASSERT(!((dd->repr().find("No data"))==std::string::npos));
872 dd->alloc(0,1); //Allocated but nbOfElements==0!
873 CPPUNIT_ASSERT(!((dd->repr().find("Number of tuples : 0"))==std::string::npos));
874 CPPUNIT_ASSERT(!((dd->repr().find("Empty Data"))==std::string::npos));
875 dd->fillWithValue(11); //?!...
876 dd->iota(10); //?!...
877 CPPUNIT_ASSERT(dd->isMonotonic(true, 1.));
878 CPPUNIT_ASSERT(dd->isMonotonic(false, 1.));
880 CPPUNIT_ASSERT_THROW(db->copyStringInfoFrom(*da),INTERP_KERNEL::Exception);
881 CPPUNIT_ASSERT_THROW(db->copyStringInfoFrom(*da),INTERP_KERNEL::Exception);
882 std::vector<std::size_t> cIds(2,2);
883 CPPUNIT_ASSERT_THROW(da->copyPartOfStringInfoFrom(*db,cIds),INTERP_KERNEL::Exception);
886 CPPUNIT_ASSERT_THROW(da->copyPartOfStringInfoFrom(*db,cIds),INTERP_KERNEL::Exception);
888 std::vector<std::string> info(2,"infoOfOneComponent");
889 CPPUNIT_ASSERT_THROW(da->setInfoOnComponents(info),INTERP_KERNEL::Exception);
890 CPPUNIT_ASSERT_THROW(da->setInfoOnComponent(1,info[0].c_str()),INTERP_KERNEL::Exception);
891 db->setInfoOnComponents(info);
893 CPPUNIT_ASSERT_THROW(da->getInfoOnComponent(-1),INTERP_KERNEL::Exception);
894 CPPUNIT_ASSERT_THROW(da->getInfoOnComponent(2),INTERP_KERNEL::Exception);
895 CPPUNIT_ASSERT(db->getInfoOnComponent(1)==db->getInfoOnComponent(0));
896 CPPUNIT_ASSERT_THROW(db->getVarOnComponent(-1),INTERP_KERNEL::Exception);
897 CPPUNIT_ASSERT_THROW(db->getVarOnComponent(2),INTERP_KERNEL::Exception);
898 CPPUNIT_ASSERT_THROW(db->getUnitOnComponent(-1),INTERP_KERNEL::Exception);
899 CPPUNIT_ASSERT_THROW(db->getUnitOnComponent(2),INTERP_KERNEL::Exception);
901 CPPUNIT_ASSERT(da->GetVarNameFromInfo(std::string("varname unit "))==std::string("varname unit "));
902 CPPUNIT_ASSERT(da->GetVarNameFromInfo(std::string("varname]unit["))==std::string("varname]unit["));
903 CPPUNIT_ASSERT(da->GetVarNameFromInfo(std::string("[unit]"))==std::string());
904 CPPUNIT_ASSERT(da->GetVarNameFromInfo(std::string("varname [unit]"))==std::string("varname"));
906 CPPUNIT_ASSERT(da->GetUnitFromInfo(std::string("varname unit "))==std::string());
907 CPPUNIT_ASSERT(da->GetUnitFromInfo(std::string("varname]unit["))==std::string());
908 CPPUNIT_ASSERT(da->GetUnitFromInfo(std::string("[unit]"))==std::string("unit"));
909 CPPUNIT_ASSERT(da->GetUnitFromInfo(std::string("varname [unit]"))==std::string("unit"));
911 CPPUNIT_ASSERT_THROW(da->checkNbOfTuplesAndComp(*db,"theMessageInThrow"),INTERP_KERNEL::Exception);
912 CPPUNIT_ASSERT_THROW(da->checkNbOfTuplesAndComp(*dc,"theMessageInThrow"),INTERP_KERNEL::Exception);
913 CPPUNIT_ASSERT_THROW(db->checkNbOfTuplesAndComp(*dc,"theMessageInThrow"),INTERP_KERNEL::Exception);
915 CPPUNIT_ASSERT_THROW(da->checkNbOfTuplesAndComp(7,2,"theMessageInThrow"),INTERP_KERNEL::Exception);
916 da->checkNbOfTuplesAndComp(7,1,"theMessageInThrow");
918 CPPUNIT_ASSERT_THROW(db->checkNbOfElems(7*2+1,"theMessageInThrow"),INTERP_KERNEL::Exception);
919 db->checkNbOfElems(7*2,"theMessageInThrow");
921 CPPUNIT_ASSERT_THROW(db->GetNumberOfItemGivenBES(10,9,1,"theMessageInThrow"),INTERP_KERNEL::Exception);
922 CPPUNIT_ASSERT_THROW(db->GetNumberOfItemGivenBES(0,1,-1,"theMessageInThrow"),INTERP_KERNEL::Exception);
923 CPPUNIT_ASSERT_EQUAL(ToIdType(10),db->GetNumberOfItemGivenBES(0,10,1,"theMessageInThrow"));
924 CPPUNIT_ASSERT_EQUAL(ToIdType(5),db->GetNumberOfItemGivenBES(0,10,2,"theMessageInThrow"));
925 CPPUNIT_ASSERT_EQUAL(ToIdType(6),db->GetNumberOfItemGivenBES(0,11,2,"theMessageInThrow"));
927 //std::cout<<"\n!!!!!!!!!\n"<<dd->repr()<<"\n!!!!!!!!!\n";
928 CPPUNIT_ASSERT(!((da->repr().find("Number of components : 1"))==std::string::npos));
929 CPPUNIT_ASSERT(!((dd->repr().find("Number of components : 1"))==std::string::npos));
930 CPPUNIT_ASSERT(!((dbl->repr().find("Number of components : 1"))==std::string::npos));
932 CPPUNIT_ASSERT(!((da->reprZip().find("Number of components : 1"))==std::string::npos));
933 CPPUNIT_ASSERT(!((dd->reprZip().find("Number of components : 1"))==std::string::npos));
934 CPPUNIT_ASSERT(!((dbl->reprZip().find("Number of components : 1"))==std::string::npos));
936 std::ostringstream ret;
937 dbl->writeVTK(ret,2,"file.tmp",0);
938 CPPUNIT_ASSERT(!((ret.str().find("<DataArray"))==std::string::npos));
939 CPPUNIT_ASSERT(!((ret.str().find("Float32"))==std::string::npos));
940 CPPUNIT_ASSERT(!((ret.str().find("16 15 14 13 12 11 10"))==std::string::npos));
942 CPPUNIT_ASSERT_THROW(dbl->selectByTupleIdSafeSlice(0,1,-1),INTERP_KERNEL::Exception);
943 CPPUNIT_ASSERT_THROW(dbl->subArray(-1,1),INTERP_KERNEL::Exception);
944 CPPUNIT_ASSERT_THROW(dbl->subArray(8,1),INTERP_KERNEL::Exception);
945 CPPUNIT_ASSERT_THROW(dbl->subArray(0,8),INTERP_KERNEL::Exception);
946 CPPUNIT_ASSERT_THROW(dbl->meldWith(dd),INTERP_KERNEL::Exception);
948 CPPUNIT_ASSERT_THROW(dbl->setPartOfValuesAdv(dbl2,da),INTERP_KERNEL::Exception); //dbl dbl2 not have the same number of components
949 CPPUNIT_ASSERT_THROW(dbl->setPartOfValuesAdv(dd,da),INTERP_KERNEL::Exception); //da tuple selector DataArrayIdType instance not have exactly 2 components
951 DataArrayDouble *dbl3=DataArrayDouble::New();
953 dbl3->fillWithValue(11.);
955 //bad number of components
956 CPPUNIT_ASSERT_THROW(dbl3->getMaxValue(tupleId),INTERP_KERNEL::Exception);
957 CPPUNIT_ASSERT_THROW(dd->getMaxValue(tupleId),INTERP_KERNEL::Exception);
958 CPPUNIT_ASSERT_THROW(dbl3->getMinValue(tupleId),INTERP_KERNEL::Exception);
959 CPPUNIT_ASSERT_THROW(dd->getMinValue(tupleId),INTERP_KERNEL::Exception);
960 CPPUNIT_ASSERT_THROW(dbl3->getAverageValue(),INTERP_KERNEL::Exception);
961 CPPUNIT_ASSERT_THROW(dd->getAverageValue(),INTERP_KERNEL::Exception);
962 CPPUNIT_ASSERT_THROW(dd->accumulate(100),INTERP_KERNEL::Exception);
963 CPPUNIT_ASSERT_THROW(dbl->fromPolarToCart(),INTERP_KERNEL::Exception);
964 CPPUNIT_ASSERT_THROW(dbl3->fromCylToCart(),INTERP_KERNEL::Exception);
965 CPPUNIT_ASSERT_THROW(dbl3->fromSpherToCart(),INTERP_KERNEL::Exception);
966 CPPUNIT_ASSERT_THROW(dbl3->doublyContractedProduct(),INTERP_KERNEL::Exception);
967 CPPUNIT_ASSERT_THROW(dbl3->determinant(),INTERP_KERNEL::Exception);
968 CPPUNIT_ASSERT_THROW(dbl3->eigenValues(),INTERP_KERNEL::Exception);
969 CPPUNIT_ASSERT_THROW(dbl3->eigenVectors(),INTERP_KERNEL::Exception);
970 CPPUNIT_ASSERT_THROW(dbl3->inverse(),INTERP_KERNEL::Exception);
971 CPPUNIT_ASSERT_THROW(dbl3->trace(),INTERP_KERNEL::Exception);
972 CPPUNIT_ASSERT_THROW(dbl3->deviator(),INTERP_KERNEL::Exception);
974 dbl3->setIJ(5,1,12.);
975 CPPUNIT_ASSERT(dbl3->getMaxValueInArray()==12.);
976 CPPUNIT_ASSERT(dbl3->getMinValueInArray()==11.);
978 db->fillWithValue(100); //bad Ids
979 CPPUNIT_ASSERT_THROW(dbl3->setPartOfValuesAdv(dbl2,db),INTERP_KERNEL::Exception);
980 db->fillWithValue(-1); //bad Ids
981 CPPUNIT_ASSERT_THROW(dbl3->setPartOfValuesAdv(dbl2,db),INTERP_KERNEL::Exception);
982 db->fillWithValue(6); //bad Ids for dbl3
983 CPPUNIT_ASSERT_THROW(dbl3->setPartOfValuesAdv(dbl2,db),INTERP_KERNEL::Exception);
985 DataArrayDouble::SetArrayIn(dbl,dbl3); //dbl->dbl3 memLeaks?
986 dbl3->checkNoNullValues();
988 CPPUNIT_ASSERT_THROW(dbl3->checkNoNullValues(),INTERP_KERNEL::Exception);
989 CPPUNIT_ASSERT_THROW(dbl3->applyInv(1.),INTERP_KERNEL::Exception); //div by zero
990 CPPUNIT_ASSERT_THROW(dbl2->findIdsInRange(1.,2.),INTERP_KERNEL::Exception);
991 std::vector<const DataArrayDouble *> a(0); //input list must be NON EMPTY
992 CPPUNIT_ASSERT_THROW(DataArrayDouble::Aggregate(a),INTERP_KERNEL::Exception);
993 CPPUNIT_ASSERT_THROW(DataArrayDouble::Meld(a),INTERP_KERNEL::Exception);
996 a.push_back(dbl); //Nb of components mismatch
997 CPPUNIT_ASSERT_THROW(DataArrayDouble::Aggregate(a),INTERP_KERNEL::Exception);
999 CPPUNIT_ASSERT_THROW(DataArrayDouble::Dot(dbl2,dbl),INTERP_KERNEL::Exception);
1001 CPPUNIT_ASSERT_THROW(DataArrayDouble::CrossProduct(dbl2,dbl),INTERP_KERNEL::Exception); //Nb of components mismatch
1002 CPPUNIT_ASSERT_THROW(DataArrayDouble::CrossProduct(dbl2,dbl2),INTERP_KERNEL::Exception); //Nb of components must be equal to 3
1003 DataArrayDouble *dbl4=DataArrayDouble::New();
1005 DataArrayDouble *dbl5=DataArrayDouble::New();
1007 CPPUNIT_ASSERT_THROW(DataArrayDouble::CrossProduct(dbl4,dbl5),INTERP_KERNEL::Exception); //Nb of tuples mismatch
1009 a[0]=dbl4; //Nb of tuple mismatch
1010 a[1]=dbl5; //Nb of tuple mismatch
1011 CPPUNIT_ASSERT_THROW(DataArrayDouble::Meld(a),INTERP_KERNEL::Exception);
1012 CPPUNIT_ASSERT_THROW(DataArrayDouble::Dot(dbl4,dbl5),INTERP_KERNEL::Exception);
1025 void MEDCouplingBasicsTest3::testDAIGetIdsEqual1()
1027 const mcIdType tab1[7]={5,-2,-4,-2,3,2,-2};
1028 DataArrayIdType *da=DataArrayIdType::New();
1030 std::copy(tab1,tab1+7,da->getPointer());
1031 DataArrayIdType *da2=da->findIdsEqual(-2);
1032 CPPUNIT_ASSERT_EQUAL(3,(int)da2->getNumberOfTuples());
1033 CPPUNIT_ASSERT_EQUAL(1,(int)da2->getNumberOfComponents());
1034 const mcIdType expected1[3]={1,3,6};
1035 CPPUNIT_ASSERT(std::equal(expected1,expected1+3,da2->getConstPointer()));
1040 void MEDCouplingBasicsTest3::testDAIGetIdsEqualList1()
1042 const mcIdType tab1[7]={5,-2,-4,-2,3,2,-2};
1043 DataArrayIdType *da=DataArrayIdType::New();
1045 std::copy(tab1,tab1+7,da->getPointer());
1046 const mcIdType tab2[3]={3,-2,0};
1047 std::vector<mcIdType> tab2V(tab2,tab2+3);
1048 DataArrayIdType *da2=da->findIdsEqualList(&tab2V[0],&tab2V[0]+tab2V.size());
1049 CPPUNIT_ASSERT_EQUAL(4,(int)da2->getNumberOfTuples());
1050 CPPUNIT_ASSERT_EQUAL(1,(int)da2->getNumberOfComponents());
1051 const mcIdType expected1[4]={1,3,4,6};
1052 CPPUNIT_ASSERT(std::equal(expected1,expected1+4,da2->getConstPointer()));
1057 void MEDCouplingBasicsTest3::testDAFromNoInterlace1()
1059 const mcIdType tab1[15]={1,11,21,31,41,2,12,22,32,42,3,13,23,33,43};
1060 DataArrayIdType *da=DataArrayIdType::New();
1062 std::copy(tab1,tab1+15,da->getPointer());
1063 DataArrayIdType *da2=da->fromNoInterlace();
1064 const mcIdType expected1[15]={1,2,3,11,12,13,21,22,23,31,32,33,41,42,43};
1065 CPPUNIT_ASSERT_EQUAL(5,(int)da2->getNumberOfTuples());
1066 CPPUNIT_ASSERT_EQUAL(3,(int)da2->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
1067 CPPUNIT_ASSERT(std::equal(expected1,expected1+15,da2->getConstPointer()));
1068 MCAuto<DataArrayDouble> da3=da->convertToDblArr();
1069 DataArrayDouble *da4=da3->fromNoInterlace();
1070 CPPUNIT_ASSERT_EQUAL(5,(int)da4->getNumberOfTuples());
1071 CPPUNIT_ASSERT_EQUAL(3,(int)da4->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
1072 for(int i=0;i<15;i++)
1073 CPPUNIT_ASSERT_DOUBLES_EQUAL((double)expected1[i],da4->getIJ(0,i),1e-14);
1079 void MEDCouplingBasicsTest3::testDAToNoInterlace1()
1081 const mcIdType tab1[15]={1,2,3,11,12,13,21,22,23,31,32,33,41,42,43};
1082 DataArrayIdType *da=DataArrayIdType::New();
1084 std::copy(tab1,tab1+15,da->getPointer());
1085 DataArrayIdType *da2=da->toNoInterlace();
1086 const mcIdType expected1[15]={1,11,21,31,41,2,12,22,32,42,3,13,23,33,43};
1087 CPPUNIT_ASSERT_EQUAL(5,(int)da2->getNumberOfTuples());
1088 CPPUNIT_ASSERT_EQUAL(3,(int)da2->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
1089 CPPUNIT_ASSERT(std::equal(expected1,expected1+15,da2->getConstPointer()));
1090 MCAuto<DataArrayDouble> da3=da->convertToDblArr();
1091 DataArrayDouble *da4=da3->toNoInterlace();
1092 CPPUNIT_ASSERT_EQUAL(5,(int)da4->getNumberOfTuples());
1093 CPPUNIT_ASSERT_EQUAL(3,(int)da4->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
1094 for(int i=0;i<15;i++)
1095 CPPUNIT_ASSERT_DOUBLES_EQUAL((double)expected1[i],da4->getIJ(0,i),1e-14);
1101 void MEDCouplingBasicsTest3::testDAIsUniform1()
1103 const mcIdType tab1[5]={1,1,1,1,1};
1104 DataArrayIdType *da=DataArrayIdType::New();
1106 std::copy(tab1,tab1+5,da->getPointer());
1107 CPPUNIT_ASSERT(da->isUniform(1));
1109 CPPUNIT_ASSERT(!da->isUniform(1));
1111 CPPUNIT_ASSERT(da->isUniform(1));
1112 MCAuto<DataArrayDouble> da2=da->convertToDblArr();
1113 CPPUNIT_ASSERT(da2->isUniform(1.,1e-12));
1114 da2->setIJ(1,0,1.+1.e-13);
1115 CPPUNIT_ASSERT(da2->isUniform(1.,1e-12));
1116 da2->setIJ(1,0,1.+1.e-11);
1117 CPPUNIT_ASSERT(!da2->isUniform(1.,1e-12));
1121 void MEDCouplingBasicsTest3::testDADFromPolarToCart1()
1123 const double tab1[4]={2.,0.2,2.5,0.7};
1124 DataArrayDouble *da=DataArrayDouble::New();
1126 std::copy(tab1,tab1+4,da->getPointer());
1127 DataArrayDouble *da2=da->fromPolarToCart();
1128 const double expected1[4]={1.9601331556824833,0.39733866159012243, 1.9121054682112213,1.6105442180942275};
1129 for(int i=0;i<4;i++)
1130 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da2->getIJ(0,i),1e-13);
1135 void MEDCouplingBasicsTest3::testDADFromCylToCart1()
1137 const double tab1[6]={2.,0.2,4.,2.5,0.7,9.};
1138 DataArrayDouble *da=DataArrayDouble::New();
1140 std::copy(tab1,tab1+6,da->getPointer());
1141 DataArrayDouble *da2=da->fromCylToCart();
1142 const double expected1[6]={1.9601331556824833,0.39733866159012243,4., 1.9121054682112213,1.6105442180942275,9.};
1143 for(int i=0;i<6;i++)
1144 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da2->getIJ(0,i),1e-13);
1149 void MEDCouplingBasicsTest3::testDADFromSpherToCart1()
1151 const double tab1[6]={2.,0.2,0.3,2.5,0.7,0.8};
1152 DataArrayDouble *da=DataArrayDouble::New();
1154 std::copy(tab1,tab1+6,da->getPointer());
1155 DataArrayDouble *da2=da->fromSpherToCart();
1156 const double expected1[6]={0.37959212195737485,0.11742160338765303,1.9601331556824833, 1.1220769624465328,1.1553337045129035,1.9121054682112213};
1157 for(int i=0;i<6;i++)
1158 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da2->getIJ(0,i),1e-13);
1163 void MEDCouplingBasicsTest3::testUnPolyze1()
1165 const mcIdType elts[8]={0,1,2,3,4,5,6,7};
1166 std::vector<mcIdType> eltsV(elts,elts+8);
1167 MEDCouplingUMesh *mesh=build3DTargetMesh_1();
1168 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
1170 MEDCouplingUMesh *mesh2=build3DTargetMesh_1();
1171 mesh->checkConsistencyLight();
1172 CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12));
1173 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
1174 CPPUNIT_ASSERT(!mesh->isEqual(mesh2,1e-12));
1175 mesh->getNodalConnectivity()->setIJ(0,6,10);
1176 mesh->getNodalConnectivity()->setIJ(0,7,9);
1177 mesh->getNodalConnectivity()->setIJ(0,8,12);
1178 mesh->getNodalConnectivity()->setIJ(0,9,13);
1180 CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12));
1181 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
1182 mesh->getNodalConnectivity()->setIJ(0,6,12);
1183 mesh->getNodalConnectivity()->setIJ(0,7,13);
1184 mesh->getNodalConnectivity()->setIJ(0,8,10);
1185 mesh->getNodalConnectivity()->setIJ(0,9,9);
1187 CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12));
1188 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
1189 mesh->getNodalConnectivity()->setIJ(0,6,12);
1190 mesh->getNodalConnectivity()->setIJ(0,7,10);
1191 mesh->getNodalConnectivity()->setIJ(0,8,13);
1192 mesh->getNodalConnectivity()->setIJ(0,9,9);
1194 CPPUNIT_ASSERT(!mesh->isEqual(mesh2,1e-12));
1198 mesh=build2DTargetMesh_1();
1199 mesh2=build2DTargetMesh_1();
1201 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
1202 CPPUNIT_ASSERT(!mesh->isEqual(mesh2,1e-12));
1204 CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12));
1209 void MEDCouplingBasicsTest3::testConvertDegeneratedCells1()
1211 MEDCouplingUMesh *mesh=build3DTargetMesh_1();
1212 mcIdType 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};
1213 mesh->allocateCells(4);
1214 mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn);
1215 mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+8);
1216 mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+16);
1217 mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+24);
1218 mesh->finishInsertingCells();
1219 mesh->checkConsistencyLight();
1220 CPPUNIT_ASSERT_EQUAL(4,(int)mesh->getNumberOfCells());
1221 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh->getTypeOfCell(0));
1222 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh->getTypeOfCell(1));
1223 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh->getTypeOfCell(2));
1224 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh->getTypeOfCell(3));
1225 MEDCouplingFieldDouble *f1=mesh->getMeasureField(true);
1226 mesh->convertDegeneratedCells();
1227 mesh->checkConsistencyLight();
1228 MEDCouplingFieldDouble *f2=mesh->getMeasureField(true);
1229 CPPUNIT_ASSERT_EQUAL(4,(int)mesh->getNumberOfCells());
1230 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_PENTA6,mesh->getTypeOfCell(0));
1231 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_PYRA5,mesh->getTypeOfCell(1));
1232 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TETRA4,mesh->getTypeOfCell(2));
1233 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_PYRA5,mesh->getTypeOfCell(3));
1234 for(int i=0;i<4;i++)
1235 CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getArray()->getIJ(0,i),f2->getArray()->getIJ(0,i),1e-5);
1241 void MEDCouplingBasicsTest3::testGetNodeIdsNearPoints1()
1243 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
1244 DataArrayDouble *coords=mesh->getCoords();
1245 DataArrayDouble *tmp=DataArrayDouble::New();
1247 const double vals[6]={0.2,0.2,0.1,0.2,0.2,0.2};
1248 std::copy(vals,vals+6,tmp->getPointer());
1249 DataArrayDouble *tmp2=DataArrayDouble::Aggregate(coords,tmp);
1251 mesh->setCoords(tmp2);
1253 const double pts[6]={0.2,0.2,0.1,0.3,-0.3,0.7};
1254 DataArrayIdType *c=mesh->getNodeIdsNearPoint(pts,1e-7);
1255 CPPUNIT_ASSERT_EQUAL(3,(int)c->getNumberOfTuples());
1256 CPPUNIT_ASSERT_EQUAL(ToIdType(4),c->getIJ(0,0));
1257 CPPUNIT_ASSERT_EQUAL(ToIdType(9),c->getIJ(1,0));
1258 CPPUNIT_ASSERT_EQUAL(ToIdType(11),c->getIJ(2,0));
1260 DataArrayIdType *cI=0;
1261 mesh->getNodeIdsNearPoints(pts,3,1e-7,c,cI);
1262 CPPUNIT_ASSERT_EQUAL(ToIdType(4),cI->getNumberOfTuples());
1263 CPPUNIT_ASSERT_EQUAL(ToIdType(4),c->getNumberOfTuples());
1264 CPPUNIT_ASSERT_EQUAL(ToIdType(4),c->getIJ(0,0));
1265 CPPUNIT_ASSERT_EQUAL(ToIdType(9),c->getIJ(1,0));
1266 CPPUNIT_ASSERT_EQUAL(ToIdType(11),c->getIJ(2,0));
1267 CPPUNIT_ASSERT_EQUAL(ToIdType(6),c->getIJ(3,0));
1268 CPPUNIT_ASSERT_EQUAL(ToIdType(0),cI->getIJ(0,0));
1269 CPPUNIT_ASSERT_EQUAL(ToIdType(3),cI->getIJ(1,0));
1270 CPPUNIT_ASSERT_EQUAL(ToIdType(3),cI->getIJ(2,0));
1271 CPPUNIT_ASSERT_EQUAL(ToIdType(4),cI->getIJ(3,0));
1277 void MEDCouplingBasicsTest3::testFieldCopyTinyAttrFrom1()
1279 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1281 f1->setTimeTolerance(1.e-5);
1282 f1->setDescription("f1Desc");
1283 f1->setTime(1.23,4,5);
1284 MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1286 f2->setDescription("f2Desc");
1287 f2->setTime(6.78,9,10);
1288 f2->setTimeTolerance(4.556e-12);
1291 f1->copyTinyAttrFrom(f2);
1292 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.556e-12,f1->getTimeTolerance(),1e-24);
1293 CPPUNIT_ASSERT_DOUBLES_EQUAL(6.78,f1->getTime(dt,it),1e-12);
1294 CPPUNIT_ASSERT_EQUAL(9,dt);
1295 CPPUNIT_ASSERT_EQUAL(10,it);
1296 CPPUNIT_ASSERT(std::string(f1->getName())=="f1");//name unchanged
1297 CPPUNIT_ASSERT(std::string(f1->getDescription())=="f1Desc");//description unchanged
1301 f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1303 f1->setTimeTolerance(1.e-5);
1304 f1->setDescription("f1Desc");
1305 f2=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1307 f2->setDescription("f2Desc");
1308 f2->setTimeTolerance(4.556e-12);
1310 f1->copyTinyAttrFrom(f2);
1311 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.556e-12,f1->getTimeTolerance(),1e-24);
1312 CPPUNIT_ASSERT(std::string(f1->getName())=="f1");//name unchanged
1313 CPPUNIT_ASSERT(std::string(f1->getDescription())=="f1Desc");//description unchanged
1317 f1=MEDCouplingFieldDouble::New(ON_CELLS,CONST_ON_TIME_INTERVAL);
1319 f1->setTimeTolerance(1.e-5);
1320 f1->setDescription("f1Desc");
1321 f1->setTime(1.23,4,5);
1322 f1->setEndTime(5.43,2,1);
1323 f2=MEDCouplingFieldDouble::New(ON_CELLS,CONST_ON_TIME_INTERVAL);
1325 f2->setDescription("f2Desc");
1326 f2->setTimeTolerance(4.556e-12);
1327 f2->setTime(6.78,9,10);
1328 f2->setEndTime(10.98,7,6);
1330 f1->copyTinyAttrFrom(f2);
1331 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.556e-12,f1->getTimeTolerance(),1e-24);
1332 CPPUNIT_ASSERT(std::string(f1->getName())=="f1");//name unchanged
1333 CPPUNIT_ASSERT(std::string(f1->getDescription())=="f1Desc");//description unchanged
1334 CPPUNIT_ASSERT_DOUBLES_EQUAL(6.78,f1->getTime(dt,it),1e-12);
1335 CPPUNIT_ASSERT_EQUAL(9,dt);
1336 CPPUNIT_ASSERT_EQUAL(10,it);
1337 CPPUNIT_ASSERT_DOUBLES_EQUAL(10.98,f1->getEndTime(dt,it),1e-12);
1338 CPPUNIT_ASSERT_EQUAL(7,dt);
1339 CPPUNIT_ASSERT_EQUAL(6,it);
1343 f1=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
1345 f1->setTimeTolerance(1.e-5);
1346 f1->setDescription("f1Desc");
1347 f1->setTime(1.23,4,5);
1348 f1->setEndTime(5.43,2,1);
1349 f2=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
1351 f2->setDescription("f2Desc");
1352 f2->setTimeTolerance(4.556e-12);
1353 f2->setTime(6.78,9,10);
1354 f2->setEndTime(10.98,7,6);
1356 f1->copyTinyAttrFrom(f2);
1357 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.556e-12,f1->getTimeTolerance(),1e-24);
1358 CPPUNIT_ASSERT(std::string(f1->getName())=="f1");//name unchanged
1359 CPPUNIT_ASSERT(std::string(f1->getDescription())=="f1Desc");//description unchanged
1360 CPPUNIT_ASSERT_DOUBLES_EQUAL(6.78,f1->getTime(dt,it),1e-12);
1361 CPPUNIT_ASSERT_EQUAL(9,dt);
1362 CPPUNIT_ASSERT_EQUAL(10,it);
1363 CPPUNIT_ASSERT_DOUBLES_EQUAL(10.98,f1->getEndTime(dt,it),1e-12);
1364 CPPUNIT_ASSERT_EQUAL(7,dt);
1365 CPPUNIT_ASSERT_EQUAL(6,it);
1371 * 1D -> 2D extrusion with rotation
1373 void MEDCouplingBasicsTest3::testExtrudedMesh5()
1375 const double coo1[4]={0.,1.,2.,3.5};
1376 DataArrayDouble *a=DataArrayDouble::New();
1378 std::copy(coo1,coo1+4,a->getPointer());
1379 MEDCouplingCMesh *b=MEDCouplingCMesh::New();
1380 b->setCoordsAt(0,a);
1381 MEDCouplingUMesh *c=b->buildUnstructured();
1382 CPPUNIT_ASSERT_EQUAL(1,c->getSpaceDimension());
1383 c->changeSpaceDimension(2);
1385 DataArrayDouble *d=DataArrayDouble::New();
1388 MEDCouplingCMesh *ee=MEDCouplingCMesh::New();
1389 ee->setCoordsAt(0,d);
1390 MEDCouplingUMesh *f=ee->buildUnstructured();
1391 DataArrayDouble *g=f->getCoords()->applyFunc(2,"3.5*IVec+x/6*3.14159265359*JVec");
1392 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 !
1393 DataArrayDouble *h=g->fromPolarToCart();
1395 MEDCouplingUMesh *i=c->buildExtrudedMesh(f,1);
1396 CPPUNIT_ASSERT_EQUAL(52,(int)i->getNumberOfNodes());
1399 DataArrayIdType *tmp=i->mergeNodes(1e-9,tmp2,tmp3);
1400 CPPUNIT_ASSERT(tmp2);
1401 CPPUNIT_ASSERT_EQUAL(ToIdType(37),tmp3);
1403 i->convertDegeneratedCells();
1404 i->checkConsistencyLight();
1405 CPPUNIT_ASSERT_EQUAL(36,(int)i->getNumberOfCells());
1406 CPPUNIT_ASSERT_EQUAL(37,(int)i->getNumberOfNodes());
1407 CPPUNIT_ASSERT_EQUAL(12,(int)i->getNumberOfCellsWithType(INTERP_KERNEL::NORM_TRI3));
1408 CPPUNIT_ASSERT_EQUAL(24,(int)i->getNumberOfCellsWithType(INTERP_KERNEL::NORM_QUAD4));
1409 const double expected1[3]={0.25,0.75,2.0625};
1410 MEDCouplingFieldDouble *j=i->getMeasureField(true);
1411 for(int ii=0;ii<12;ii++)
1412 for(int k=0;k<3;k++)
1413 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[k],j->getIJ(0,ii*3+k),1e-10);
1414 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};
1415 DataArrayDouble *m=i->computeCellCenterOfMass();
1416 for(int ii=0;ii<72;ii++)
1417 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[ii],m->getIJ(0,ii),1e-10);
1433 * 1D -> 2D extrusion without rotation
1435 void MEDCouplingBasicsTest3::testExtrudedMesh6()
1437 const double coo1[4]={0.,1.,2.,3.5};
1438 DataArrayDouble *a=DataArrayDouble::New();
1440 std::copy(coo1,coo1+4,a->getPointer());
1441 MEDCouplingCMesh *b=MEDCouplingCMesh::New();
1442 b->setCoordsAt(0,a);
1443 MEDCouplingUMesh *c=b->buildUnstructured();
1444 CPPUNIT_ASSERT_EQUAL(1,c->getSpaceDimension());
1445 c->changeSpaceDimension(2);
1447 DataArrayDouble *d=DataArrayDouble::New();
1450 MEDCouplingCMesh *e=MEDCouplingCMesh::New();
1451 e->setCoordsAt(0,d);
1452 MEDCouplingUMesh *f=e->buildUnstructured();
1453 DataArrayDouble *d2=f->getCoords()->applyFunc("x*x/2");
1455 f->changeSpaceDimension(2);
1457 const double center[2]={0.,0.};
1458 f->rotate(center,0,M_PI/3);
1459 MEDCouplingUMesh *g=c->buildExtrudedMesh(f,0);
1460 g->checkConsistencyLight();
1461 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 };
1462 MEDCouplingFieldDouble *f1=g->getMeasureField(true);
1463 for(int i=0;i<12;i++)
1464 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-12);
1466 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};
1467 DataArrayDouble *f2=g->computeCellCenterOfMass();
1468 for(int i=0;i<24;i++)
1469 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f2->getIJ(0,i),1e-12);
1484 * 2D -> 3D extrusion with rotation
1486 void MEDCouplingBasicsTest3::testExtrudedMesh7()
1488 const double coo1[4]={0.,1.,2.,3.5};
1489 DataArrayDouble *a=DataArrayDouble::New();
1491 std::copy(coo1,coo1+4,a->getPointer());
1492 MEDCouplingCMesh *b=MEDCouplingCMesh::New();
1493 b->setCoordsAt(0,a);
1494 MEDCouplingUMesh *c=b->buildUnstructured();
1495 CPPUNIT_ASSERT_EQUAL(1,c->getSpaceDimension());
1496 c->changeSpaceDimension(2);
1498 DataArrayDouble *d=DataArrayDouble::New();
1501 MEDCouplingCMesh *e=MEDCouplingCMesh::New();
1502 e->setCoordsAt(0,d);
1503 MEDCouplingUMesh *f=e->buildUnstructured();
1504 DataArrayDouble *g=f->getCoords()->applyFunc(2,"3.5*IVec+x/6*3.14159265359*JVec");
1505 DataArrayDouble *h=g->fromPolarToCart();
1507 MEDCouplingUMesh *i=c->buildExtrudedMesh(f,1);
1508 CPPUNIT_ASSERT_EQUAL(52,(int)i->getNumberOfNodes());
1511 DataArrayIdType *tmp=i->mergeNodes(1e-9,tmp2,tmp3);
1512 CPPUNIT_ASSERT(tmp2);
1513 CPPUNIT_ASSERT_EQUAL(ToIdType(37),tmp3);
1515 i->convertDegeneratedCells();
1516 const double vec1[3]={10.,0.,0.};
1518 DataArrayDouble *g2=h->applyFunc(3,"13.5/3.5*x*IVec+0*JVec+13.5/3.5*y*KVec");
1520 i->changeSpaceDimension(3);
1521 MEDCouplingUMesh *i3=i->buildExtrudedMesh(f,1);
1522 MEDCouplingFieldDouble *f2=i3->getMeasureField(true);
1523 tmp=i->mergeNodes(1e-9,tmp2,tmp3);
1524 CPPUNIT_ASSERT(tmp2);
1525 CPPUNIT_ASSERT_EQUAL(ToIdType(444),tmp3);
1527 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};
1529 for(int ii=0;ii<12;ii++)
1530 for(int jj=0;jj<36;jj++,kk++)
1531 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[jj],f2->getIJ(0,kk),1e-9);
1547 void MEDCouplingBasicsTest3::testSimplexize1()
1549 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1550 std::vector<mcIdType> v(1);
1552 m->convertToPolyTypes(&v[0],&v[0]+v.size());
1553 DataArrayIdType *da=m->simplexize(0);
1554 CPPUNIT_ASSERT_EQUAL(7,(int)da->getNumberOfTuples());
1555 CPPUNIT_ASSERT_EQUAL(1,(int)da->getNumberOfComponents());
1556 const mcIdType expected2[7]={0,0,1,2,3,4,4};
1557 for(int i=0;i<7;i++)
1558 CPPUNIT_ASSERT_EQUAL(expected2[i],da->getIJ(i,0));
1559 m->checkConsistencyLight();
1560 CPPUNIT_ASSERT_EQUAL(7,(int)m->getNumberOfCells());
1561 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(0));
1562 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(1));
1563 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(2));
1564 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(3));
1565 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYGON,m->getTypeOfCell(4));
1566 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(5));
1567 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(6));
1568 const double expected1[7]={0.125,0.125,0.125,0.125,0.25,0.125,0.125};
1569 MEDCouplingFieldDouble *f=m->getMeasureField(false);
1570 for(int i=0;i<7;i++)
1571 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i]*sqrt(2.),f->getIJ(i,0),1e-10);
1572 std::set<INTERP_KERNEL::NormalizedCellType> types=m->getAllGeoTypes();
1573 CPPUNIT_ASSERT_EQUAL(2,(int)types.size());
1574 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*(types.begin()));
1575 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYGON,*(++(types.begin())));
1580 m=build3DSurfTargetMesh_1();
1582 m->convertToPolyTypes(&v[0],&v[0]+v.size());
1583 da=m->simplexize(1);
1584 CPPUNIT_ASSERT_EQUAL(7,(int)da->getNumberOfTuples());
1585 CPPUNIT_ASSERT_EQUAL(1,(int)da->getNumberOfComponents());
1586 for(int i=0;i<7;i++)
1587 CPPUNIT_ASSERT_EQUAL(expected2[i],da->getIJ(i,0));
1588 m->checkConsistencyLight();
1589 types=m->getAllGeoTypes();
1590 CPPUNIT_ASSERT_EQUAL(2,(int)types.size());
1591 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*(types.begin()));
1592 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYGON,*(++(types.begin())));
1593 CPPUNIT_ASSERT_EQUAL(7,(int)m->getNumberOfCells());
1594 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(0));
1595 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(1));
1596 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(2));
1597 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(3));
1598 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYGON,m->getTypeOfCell(4));
1599 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(5));
1600 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(6));
1601 f=m->getMeasureField(false);
1602 for(int i=0;i<7;i++)
1603 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i]*sqrt(2.),f->getIJ(i,0),1e-10);
1609 void MEDCouplingBasicsTest3::testSimplexize2()
1611 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1612 std::vector<mcIdType> v(1);
1614 m->convertToPolyTypes(&v[0],&v[0]+v.size());
1615 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1617 DataArrayDouble *arr=DataArrayDouble::New();
1618 const double arr1[10]={10.,110.,20.,120.,30.,130.,40.,140.,50.,150.};
1620 std::copy(arr1,arr1+10,arr->getPointer());
1624 f1->checkConsistencyLight();
1625 CPPUNIT_ASSERT(f1->simplexize(0));
1626 f1->checkConsistencyLight();
1627 const double expected1[14]={10.,110.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.,50.,150.};
1628 for(int i=0;i<14;i++)
1629 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-10);
1630 CPPUNIT_ASSERT(!f1->simplexize(0));
1631 for(int i=0;i<14;i++)
1632 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-10);
1638 void MEDCouplingBasicsTest3::testDAMeld1()
1640 DataArrayDouble *da1=DataArrayDouble::New();
1642 DataArrayDouble *da2=DataArrayDouble::New();
1645 da1->fillWithValue(7.);
1647 MCAuto<DataArrayDouble> da3=da2->applyFunc(3,"10*x*IVec+100*x*JVec+1000*x*KVec");
1649 da1->setInfoOnComponent(0,"c0da1");
1650 da1->setInfoOnComponent(1,"c1da1");
1651 da3->setInfoOnComponent(0,"c0da3");
1652 da3->setInfoOnComponent(1,"c1da3");
1653 da3->setInfoOnComponent(2,"c2da3");
1655 DataArrayDouble *da1C=da1->deepCopy();
1657 CPPUNIT_ASSERT_EQUAL(5,(int)da1->getNumberOfComponents());
1658 CPPUNIT_ASSERT_EQUAL(7,(int)da1->getNumberOfTuples());
1659 CPPUNIT_ASSERT(da1->getInfoOnComponent(0)=="c0da1");
1660 CPPUNIT_ASSERT(da1->getInfoOnComponent(1)=="c1da1");
1661 CPPUNIT_ASSERT(da1->getInfoOnComponent(2)=="c0da3");
1662 CPPUNIT_ASSERT(da1->getInfoOnComponent(3)=="c1da3");
1663 CPPUNIT_ASSERT(da1->getInfoOnComponent(4)=="c2da3");
1665 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.};
1666 for(int i=0;i<35;i++)
1667 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da1->getIJ(0,i),1e-10);
1669 MCAuto<DataArrayInt> dai1=da1C->convertToIntArr();
1670 MCAuto<DataArrayInt> dai3=da3->convertToIntArr();
1671 dai1->meldWith(dai3);
1672 CPPUNIT_ASSERT_EQUAL(5,(int)dai1->getNumberOfComponents());
1673 CPPUNIT_ASSERT_EQUAL(7,(int)dai1->getNumberOfTuples());
1674 CPPUNIT_ASSERT(dai1->getInfoOnComponent(0)=="c0da1");
1675 CPPUNIT_ASSERT(dai1->getInfoOnComponent(1)=="c1da1");
1676 CPPUNIT_ASSERT(dai1->getInfoOnComponent(2)=="c0da3");
1677 CPPUNIT_ASSERT(dai1->getInfoOnComponent(3)=="c1da3");
1678 CPPUNIT_ASSERT(dai1->getInfoOnComponent(4)=="c2da3");
1679 for(int i=0;i<35;i++)
1680 CPPUNIT_ASSERT_EQUAL((int)expected1[i],dai1->getIJ(0,i));
1681 // test of static method DataArrayDouble::meld
1682 DataArrayDouble *da4=DataArrayDouble::Meld(da1C,da3);
1683 CPPUNIT_ASSERT_EQUAL(5,(int)da4->getNumberOfComponents());
1684 CPPUNIT_ASSERT_EQUAL(7,(int)da4->getNumberOfTuples());
1685 CPPUNIT_ASSERT(da4->getInfoOnComponent(0)=="c0da1");
1686 CPPUNIT_ASSERT(da4->getInfoOnComponent(1)=="c1da1");
1687 CPPUNIT_ASSERT(da4->getInfoOnComponent(2)=="c0da3");
1688 CPPUNIT_ASSERT(da4->getInfoOnComponent(3)=="c1da3");
1689 CPPUNIT_ASSERT(da4->getInfoOnComponent(4)=="c2da3");
1690 for(int i=0;i<35;i++)
1691 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da4->getIJ(0,i),1e-10);
1692 // test of static method DataArrayIdType::meld
1693 dai1=da1C->convertToIntArr();
1694 DataArrayInt *dai4=DataArrayInt::Meld(dai1,dai3);
1695 CPPUNIT_ASSERT_EQUAL(5,(int)dai4->getNumberOfComponents());
1696 CPPUNIT_ASSERT_EQUAL(7,(int)dai4->getNumberOfTuples());
1697 CPPUNIT_ASSERT(dai4->getInfoOnComponent(0)=="c0da1");
1698 CPPUNIT_ASSERT(dai4->getInfoOnComponent(1)=="c1da1");
1699 CPPUNIT_ASSERT(dai4->getInfoOnComponent(2)=="c0da3");
1700 CPPUNIT_ASSERT(dai4->getInfoOnComponent(3)=="c1da3");
1701 CPPUNIT_ASSERT(dai4->getInfoOnComponent(4)=="c2da3");
1702 for(int i=0;i<35;i++)
1703 CPPUNIT_ASSERT_EQUAL(expected1[i],(double)dai4->getIJ(0,i));
1712 void MEDCouplingBasicsTest3::testFieldMeld1()
1714 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1715 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1717 DataArrayDouble *da1=DataArrayDouble::New();
1718 const double arr1[5]={12.,23.,34.,45.,56.};
1720 std::copy(arr1,arr1+5,da1->getPointer());
1721 da1->setInfoOnComponent(0,"aaa");
1723 f1->setTime(3.4,2,1);
1724 f1->checkConsistencyLight();
1726 MEDCouplingFieldDouble *f2=f1->deepCopy();
1727 f2->setMesh(f1->getMesh());
1728 f2->checkConsistencyLight();
1729 f2->changeNbOfComponents(2,5.);
1731 f2->getArray()->setInfoOnComponent(0,"bbb");
1732 f2->getArray()->setInfoOnComponent(1,"ccc");
1733 f2->checkConsistencyLight();
1735 MEDCouplingFieldDouble *f3=MEDCouplingFieldDouble::MeldFields(f2,f1);
1736 f3->checkConsistencyLight();
1737 CPPUNIT_ASSERT_EQUAL(5,(int)f3->getNumberOfTuples());
1738 CPPUNIT_ASSERT_EQUAL(3,(int)f3->getNumberOfComponents());
1739 CPPUNIT_ASSERT(f3->getArray()->getInfoOnComponent(0)=="bbb");
1740 CPPUNIT_ASSERT(f3->getArray()->getInfoOnComponent(1)=="ccc");
1741 CPPUNIT_ASSERT(f3->getArray()->getInfoOnComponent(2)=="aaa");
1742 const double expected1[15]={5.,5.,12.,5.,5.,23.,5.,5.,34.,5.,5.,45.,5.,5.,56.};
1743 for(int i=0;i<15;i++)
1744 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f3->getIJ(0,i),1e-12);
1746 double time=f3->getTime(dt,it);
1747 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.4,time,1e-14);
1748 CPPUNIT_ASSERT_EQUAL(2,dt);
1749 CPPUNIT_ASSERT_EQUAL(1,it);
1751 MEDCouplingFieldDouble *f4=f2->buildNewTimeReprFromThis(NO_TIME,false);
1752 MEDCouplingFieldDouble *f5=f1->buildNewTimeReprFromThis(NO_TIME,false);
1753 MEDCouplingFieldDouble *f6=MEDCouplingFieldDouble::MeldFields(f4,f5);
1754 f6->checkConsistencyLight();
1755 CPPUNIT_ASSERT_EQUAL(5,(int)f6->getNumberOfTuples());
1756 CPPUNIT_ASSERT_EQUAL(3,(int)f6->getNumberOfComponents());
1757 CPPUNIT_ASSERT(f6->getArray()->getInfoOnComponent(0)=="bbb");
1758 CPPUNIT_ASSERT(f6->getArray()->getInfoOnComponent(1)=="ccc");
1759 CPPUNIT_ASSERT(f6->getArray()->getInfoOnComponent(2)=="aaa");
1760 for(int i=0;i<15;i++)
1761 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f6->getIJ(0,i),1e-12);
1773 void MEDCouplingBasicsTest3::testMergeNodes2()
1775 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1776 MEDCouplingUMesh *m2=build2DTargetMesh_1();
1777 const double vec[2]={0.002,0.};
1780 std::vector<const MEDCouplingUMesh *> tmp(2);
1783 MEDCouplingUMesh *m3=MEDCouplingUMesh::MergeUMeshes(tmp);
1785 mcIdType newNbOfNodes;
1786 DataArrayIdType *da=m3->mergeNodesCenter(0.01,b,newNbOfNodes);
1787 CPPUNIT_ASSERT_EQUAL(9,(int)m3->getNumberOfNodes());
1788 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};
1789 for(int i=0;i<18;i++)
1790 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],m3->getCoords()->getIJ(0,i),1e-13);
1798 void MEDCouplingBasicsTest3::testMergeField2()
1800 MEDCouplingUMesh *m=build2DTargetMesh_1();
1801 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1803 DataArrayDouble *arr=DataArrayDouble::New();
1805 arr->fillWithValue(2.);
1808 MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1810 arr=DataArrayDouble::New();
1812 arr->fillWithValue(5.);
1815 MEDCouplingFieldDouble *f3=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1817 arr=DataArrayDouble::New();
1819 arr->fillWithValue(7.);
1823 std::vector<const MEDCouplingFieldDouble *> tmp(3);
1824 tmp[0]=f1; tmp[1]=f2; tmp[2]=f3;
1825 MEDCouplingFieldDouble *f4=MEDCouplingFieldDouble::MergeFields(tmp);
1826 CPPUNIT_ASSERT_EQUAL(15,(int)f4->getMesh()->getNumberOfCells());
1827 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.};
1828 for(int i=0;i<30;i++)
1829 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f4->getIJ(0,i),1.e-13);
1838 void MEDCouplingBasicsTest3::testDAIBuildComplement1()
1840 DataArrayIdType *a=DataArrayIdType::New();
1841 const mcIdType tab[4]={3,1,7,8};
1843 std::copy(tab,tab+4,a->getPointer());
1844 DataArrayIdType *b=a->buildComplement(12);
1845 CPPUNIT_ASSERT_EQUAL(8,(int)b->getNumberOfTuples());
1846 CPPUNIT_ASSERT_EQUAL(1,(int)b->getNumberOfComponents());
1847 const mcIdType expected1[8]={0,2,4,5,6,9,10,11};
1848 for(int i=0;i<8;i++)
1849 CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
1854 void MEDCouplingBasicsTest3::testDAIBuildUnion1()
1856 DataArrayIdType *a=DataArrayIdType::New();
1857 const mcIdType tab1[4]={3,1,7,8};
1859 std::copy(tab1,tab1+4,a->getPointer());
1860 DataArrayIdType *c=DataArrayIdType::New();
1861 const mcIdType tab2[5]={5,3,0,18,8};
1863 std::copy(tab2,tab2+5,c->getPointer());
1864 DataArrayIdType *b=a->buildUnion(c);
1865 CPPUNIT_ASSERT_EQUAL(7,(int)b->getNumberOfTuples());
1866 CPPUNIT_ASSERT_EQUAL(1,(int)b->getNumberOfComponents());
1867 const mcIdType expected1[7]={0,1,3,5,7,8,18};
1868 for(int i=0;i<7;i++)
1869 CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
1875 void MEDCouplingBasicsTest3::testDAIBuildIntersection1()
1877 DataArrayIdType *a=DataArrayIdType::New();
1878 const mcIdType tab1[4]={3,1,7,8};
1880 std::copy(tab1,tab1+4,a->getPointer());
1881 DataArrayIdType *c=DataArrayIdType::New();
1882 const mcIdType tab2[5]={5,3,0,18,8};
1884 std::copy(tab2,tab2+5,c->getPointer());
1885 DataArrayIdType *b=a->buildIntersection(c);
1886 CPPUNIT_ASSERT_EQUAL(2,(int)b->getNumberOfTuples());
1887 CPPUNIT_ASSERT_EQUAL(1,(int)b->getNumberOfComponents());
1888 const mcIdType expected1[2]={3,8};
1889 for(int i=0;i<2;i++)
1890 CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
1896 void MEDCouplingBasicsTest3::testDAIDeltaShiftIndex1()
1898 DataArrayIdType *a=DataArrayIdType::New();
1899 const mcIdType tab[7]={1,3,6,7,7,9,15};
1901 std::copy(tab,tab+7,a->getPointer());
1902 DataArrayIdType *b=a->deltaShiftIndex();
1903 CPPUNIT_ASSERT_EQUAL(6,(int)b->getNumberOfTuples());
1904 CPPUNIT_ASSERT_EQUAL(1,(int)b->getNumberOfComponents());
1905 const mcIdType expected1[6]={2,3,1,0,2,6};
1906 for(int i=0;i<6;i++)
1907 CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
1912 void MEDCouplingBasicsTest3::testDaDoubleSelectByTupleIdSafe1()
1914 DataArrayDouble *a=DataArrayDouble::New();
1916 a->setInfoOnComponent(0,"toto");
1917 a->setInfoOnComponent(1,"tata");
1918 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};
1919 std::copy(arr1,arr1+14,a->getPointer());
1921 const mcIdType arr2[7]={4,2,0,6,5};
1922 DataArrayDouble *b=a->selectByTupleIdSafe(arr2,arr2+5);
1923 CPPUNIT_ASSERT_EQUAL(5,(int)b->getNumberOfTuples());
1924 CPPUNIT_ASSERT_EQUAL(2,(int)b->getNumberOfComponents());
1925 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
1926 CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
1927 const double expected1[10]={5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1};
1928 for(int i=0;i<10;i++)
1929 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
1930 const mcIdType arr4[5]={4,-1,0,6,5};
1931 CPPUNIT_ASSERT_THROW(a->selectByTupleIdSafe(arr4,arr4+5),INTERP_KERNEL::Exception);
1932 const mcIdType arr5[5]={4,2,0,6,7};
1933 CPPUNIT_ASSERT_THROW(a->selectByTupleIdSafe(arr5,arr5+5),INTERP_KERNEL::Exception);
1937 DataArrayIdType *c=DataArrayIdType::New();
1939 c->setInfoOnComponent(0,"toto");
1940 c->setInfoOnComponent(1,"tata");
1941 const mcIdType arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
1942 std::copy(arr3,arr3+14,c->getPointer());
1943 DataArrayIdType *d=c->selectByTupleIdSafe(arr2,arr2+5);
1944 CPPUNIT_ASSERT_EQUAL(5,(int)d->getNumberOfTuples());
1945 CPPUNIT_ASSERT_EQUAL(2,(int)d->getNumberOfComponents());
1946 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
1947 CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
1948 const mcIdType expected2[10]={5,15,3,13,1,11,7,17,6,16};
1949 for(int i=0;i<10;i++)
1950 CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
1951 CPPUNIT_ASSERT_THROW(c->selectByTupleIdSafe(arr4,arr4+5),INTERP_KERNEL::Exception);
1952 CPPUNIT_ASSERT_THROW(c->selectByTupleIdSafe(arr5,arr5+5),INTERP_KERNEL::Exception);
1957 void MEDCouplingBasicsTest3::testAreCellsIncludedIn1()
1959 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1960 const mcIdType pt[2]={1,3};
1961 MEDCouplingUMesh *m2=(MEDCouplingUMesh *)m->buildPartOfMySelf(pt,pt+2,true);
1962 DataArrayIdType *tmp;
1963 CPPUNIT_ASSERT(m->areCellsIncludedIn(m2,0,tmp));
1964 CPPUNIT_ASSERT_EQUAL(2,(int)tmp->getNumberOfTuples());
1965 CPPUNIT_ASSERT_EQUAL(1,(int)tmp->getNumberOfComponents());
1966 CPPUNIT_ASSERT_EQUAL(pt[0],tmp->getIJ(0,0));
1967 CPPUNIT_ASSERT_EQUAL(pt[1],tmp->getIJ(0,1));
1969 CPPUNIT_ASSERT(!m2->areCellsIncludedIn(m,0,tmp));
1975 void MEDCouplingBasicsTest3::testDAIBuildSubstraction1()
1977 DataArrayIdType *a=DataArrayIdType::New();
1978 const mcIdType aa[]={2,3,6,8,9};
1980 std::copy(aa,aa+5,a->getPointer());
1981 DataArrayIdType *b=DataArrayIdType::New();
1982 const mcIdType bb[]={1,3,5,9,11};
1984 std::copy(bb,bb+5,b->getPointer());
1986 DataArrayIdType *c=a->buildSubstraction(b);
1987 CPPUNIT_ASSERT_EQUAL(3,(int)c->getNumberOfTuples());
1988 CPPUNIT_ASSERT_EQUAL(1,(int)c->getNumberOfComponents());
1989 const mcIdType expected1[3]={2,6,8};
1990 CPPUNIT_ASSERT(std::equal(expected1,expected1+3,c->getConstPointer()));
1997 void MEDCouplingBasicsTest3::testBuildOrthogonalField2()
1999 MEDCouplingUMesh *m=build2DTargetMesh_1();
2000 DataArrayIdType *d1=DataArrayIdType::New();
2001 DataArrayIdType *d2=DataArrayIdType::New();
2002 DataArrayIdType *d3=DataArrayIdType::New();
2003 DataArrayIdType *d4=DataArrayIdType::New();
2004 MEDCouplingUMesh *m1=m->buildDescendingConnectivity(d1,d2,d3,d4);
2006 MEDCouplingFieldDouble *f1=m1->buildOrthogonalField();
2007 DataArrayDouble *da1=f1->getArray();
2008 CPPUNIT_ASSERT_EQUAL(2,(int)da1->getNumberOfComponents());
2009 CPPUNIT_ASSERT_EQUAL(13,(int)da1->getNumberOfTuples());
2011 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.};
2012 for(int i=0;i<26;i++)
2013 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da1->getIJ(0,i),1e-14);
2024 void MEDCouplingBasicsTest3::testUMInsertNextCell1()
2026 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 };
2027 mcIdType targetConn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
2028 MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
2029 targetMesh->allocateCells(5);
2030 CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn),INTERP_KERNEL::Exception);
2031 targetMesh->setMeshDimension(2);
2032 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn);
2033 CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_TETRA4,4,targetConn),INTERP_KERNEL::Exception);
2034 CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,targetConn),INTERP_KERNEL::Exception);
2035 CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn),INTERP_KERNEL::Exception);
2036 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+4);
2037 targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+7);
2038 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+10);
2039 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+14);
2040 targetMesh->finishInsertingCells();
2041 DataArrayDouble *myCoords=DataArrayDouble::New();
2042 myCoords->alloc(9,2);
2043 std::copy(targetCoords,targetCoords+18,myCoords->getPointer());
2044 targetMesh->setCoords(myCoords);
2045 myCoords->decrRef();
2046 targetMesh->checkConsistencyLight();
2047 targetMesh->decrRef();
2050 void MEDCouplingBasicsTest3::testFieldOperatorDivDiffComp1()
2052 MEDCouplingUMesh *m=build2DTargetMesh_1();
2053 DataArrayIdType *d1=DataArrayIdType::New();
2054 DataArrayIdType *d2=DataArrayIdType::New();
2055 DataArrayIdType *d3=DataArrayIdType::New();
2056 DataArrayIdType *d4=DataArrayIdType::New();
2057 MEDCouplingUMesh *m1=m->buildDescendingConnectivity(d1,d2,d3,d4);
2059 MEDCouplingFieldDouble *f1=m1->buildOrthogonalField();
2060 const double arr1[13]={2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.};
2061 DataArrayDouble *arr=DataArrayDouble::New();
2063 std::copy(arr1,arr1+13,arr->getPointer());
2064 MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS);
2067 f2->checkConsistencyLight();
2069 MEDCouplingFieldDouble *f3=(*f1)/(*f2);
2070 CPPUNIT_ASSERT_THROW((*f2)/(*f1),INTERP_KERNEL::Exception);
2071 f3->checkConsistencyLight();
2073 CPPUNIT_ASSERT(f1->isEqual(f3,1e-10,1e-10));
2074 CPPUNIT_ASSERT_THROW((*f2)/=(*f1),INTERP_KERNEL::Exception);
2075 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};
2076 for(int i=0;i<26;i++)
2077 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f3->getIJ(0,i),1e-10);
2091 void MEDCouplingBasicsTest3::testDARearrange1()
2093 DataArrayIdType *da1=DataArrayIdType::New();
2096 const mcIdType *ptr=da1->getConstPointer();
2098 CPPUNIT_ASSERT_EQUAL(ToIdType(12),da1->getNbOfElems());
2099 CPPUNIT_ASSERT_EQUAL(1,(int)da1->getNumberOfComponents());
2100 CPPUNIT_ASSERT_EQUAL(12,(int)da1->getNumberOfTuples());
2102 CPPUNIT_ASSERT(ptr==da1->getConstPointer());
2103 CPPUNIT_ASSERT_EQUAL(ToIdType(12),da1->getNbOfElems());
2104 CPPUNIT_ASSERT_EQUAL(4,(int)da1->getNumberOfComponents());
2105 CPPUNIT_ASSERT_EQUAL(3,(int)da1->getNumberOfTuples());
2106 for(mcIdType i=0;i<12;i++)
2107 CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
2110 CPPUNIT_ASSERT(ptr==da1->getConstPointer());
2111 CPPUNIT_ASSERT_EQUAL(ToIdType(12),da1->getNbOfElems());
2112 CPPUNIT_ASSERT_EQUAL(6,(int)da1->getNumberOfComponents());
2113 CPPUNIT_ASSERT_EQUAL(2,(int)da1->getNumberOfTuples());
2114 for(mcIdType i=0;i<12;i++)
2115 CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
2117 CPPUNIT_ASSERT_THROW(da1->rearrange(7),INTERP_KERNEL::Exception);
2120 CPPUNIT_ASSERT(ptr==da1->getConstPointer());
2121 CPPUNIT_ASSERT_EQUAL(ToIdType(12),da1->getNbOfElems());
2122 CPPUNIT_ASSERT_EQUAL(12,(int)da1->getNumberOfComponents());
2123 CPPUNIT_ASSERT_EQUAL(1,(int)da1->getNumberOfTuples());
2124 for(mcIdType i=0;i<12;i++)
2125 CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
2128 CPPUNIT_ASSERT(ptr==da1->getConstPointer());
2129 CPPUNIT_ASSERT_EQUAL(ToIdType(12),da1->getNbOfElems());
2130 CPPUNIT_ASSERT_EQUAL(3,(int)da1->getNumberOfComponents());
2131 CPPUNIT_ASSERT_EQUAL(4,(int)da1->getNumberOfTuples());
2132 for(mcIdType i=0;i<12;i++)
2133 CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
2135 MCAuto<DataArrayDouble> da2=da1->convertToDblArr();
2137 const double *ptr2=da2->getConstPointer();
2139 CPPUNIT_ASSERT_EQUAL(ToIdType(12),da2->getNbOfElems());
2140 CPPUNIT_ASSERT_EQUAL(3,(int)da2->getNumberOfComponents());
2141 CPPUNIT_ASSERT_EQUAL(4,(int)da2->getNumberOfTuples());
2143 CPPUNIT_ASSERT(ptr2==da2->getConstPointer());
2144 CPPUNIT_ASSERT_EQUAL(ToIdType(12),da2->getNbOfElems());
2145 CPPUNIT_ASSERT_EQUAL(4,(int)da2->getNumberOfComponents());
2146 CPPUNIT_ASSERT_EQUAL(3,(int)da2->getNumberOfTuples());
2147 for(int i=0;i<12;i++)
2148 CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
2151 CPPUNIT_ASSERT(ptr2==da2->getConstPointer());
2152 CPPUNIT_ASSERT_EQUAL(ToIdType(12),da2->getNbOfElems());
2153 CPPUNIT_ASSERT_EQUAL(6,(int)da2->getNumberOfComponents());
2154 CPPUNIT_ASSERT_EQUAL(2,(int)da2->getNumberOfTuples());
2155 for(int i=0;i<12;i++)
2156 CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
2158 CPPUNIT_ASSERT_THROW(da2->rearrange(7),INTERP_KERNEL::Exception);
2161 CPPUNIT_ASSERT(ptr2==da2->getConstPointer());
2162 CPPUNIT_ASSERT_EQUAL(ToIdType(12),da2->getNbOfElems());
2163 CPPUNIT_ASSERT_EQUAL(1,(int)da2->getNumberOfComponents());
2164 CPPUNIT_ASSERT_EQUAL(12,(int)da2->getNumberOfTuples());
2165 for(int i=0;i<12;i++)
2166 CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
2169 CPPUNIT_ASSERT(ptr2==da2->getConstPointer());
2170 CPPUNIT_ASSERT_EQUAL(ToIdType(12),da2->getNbOfElems());
2171 CPPUNIT_ASSERT_EQUAL(3,(int)da2->getNumberOfComponents());
2172 CPPUNIT_ASSERT_EQUAL(4,(int)da2->getNumberOfTuples());
2173 for(int i=0;i<12;i++)
2174 CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
2177 void MEDCouplingBasicsTest3::testGetDifferentValues1()
2179 DataArrayIdType *da1=DataArrayIdType::New();
2180 const mcIdType arr[12]={1,2,3,2,2,3,5,1,5,5,2,2};
2182 std::copy(arr,arr+12,da1->getPointer());
2183 DataArrayIdType *s=da1->getDifferentValues();
2184 const mcIdType expected1[4]={1,2,3,5};
2185 CPPUNIT_ASSERT_EQUAL(4,(int)s->getNumberOfTuples());
2186 CPPUNIT_ASSERT(std::equal(expected1,expected1+4,s->begin()));
2191 void MEDCouplingBasicsTest3::testDAIBuildPermutationArr1()
2193 DataArrayIdType *a=DataArrayIdType::New();
2194 const mcIdType vala[5]={4,5,6,7,8};
2196 std::copy(vala,vala+5,a->getPointer());
2197 DataArrayIdType *b=DataArrayIdType::New();
2198 const mcIdType valb[5]={5,4,8,6,7};
2200 std::copy(valb,valb+5,b->getPointer());
2201 DataArrayIdType *c=a->buildPermutationArr(*b);
2202 const mcIdType expect1[5]={1,0,4,2,3};
2203 CPPUNIT_ASSERT_EQUAL(5,(int)c->getNumberOfTuples());
2204 CPPUNIT_ASSERT_EQUAL(1,(int)c->getNumberOfComponents());
2205 CPPUNIT_ASSERT(std::equal(expect1,expect1+5,c->getConstPointer()));
2206 CPPUNIT_ASSERT(a->isEqualWithoutConsideringStrAndOrder(*b));
2208 CPPUNIT_ASSERT(!a->isEqualWithoutConsideringStrAndOrder(*b));
2209 CPPUNIT_ASSERT_THROW(a->buildPermutationArr(*b),INTERP_KERNEL::Exception);
2212 b->setIJ(4,0,4);//;a==[4,5,6,4,8] and b==[5,4,8,6,4]
2213 CPPUNIT_ASSERT(a->isEqualWithoutConsideringStrAndOrder(*b));
2215 c=a->buildPermutationArr(*b);
2216 const mcIdType expect2[5]={1,3,4,2,3};
2217 CPPUNIT_ASSERT(std::equal(expect2,expect2+5,c->getConstPointer()));
2218 MCAuto<DataArrayDouble> d=b->convertToDblArr();
2220 const mcIdType expect3[5]={4,4,5,6,8};
2221 CPPUNIT_ASSERT(std::equal(expect3,expect3+5,b->getConstPointer()));
2223 CPPUNIT_ASSERT_EQUAL(5,(int)d->getNumberOfTuples());
2224 CPPUNIT_ASSERT_EQUAL(1,(int)d->getNumberOfComponents());
2225 for(int i=0;i<5;i++)
2226 CPPUNIT_ASSERT_DOUBLES_EQUAL(double(expect3[i]),d->getIJ(i,0),1e-14);
2233 void MEDCouplingBasicsTest3::testAreCellsIncludedIn2()
2235 const char myName[]="Vitoo";
2236 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
2237 MEDCouplingUMesh *m2=(MEDCouplingUMesh *)m->buildPartOfMySelf(0,0,true);
2238 CPPUNIT_ASSERT_EQUAL(0,(int)m2->getNumberOfCells());
2239 CPPUNIT_ASSERT_EQUAL(3,m2->getSpaceDimension());
2240 CPPUNIT_ASSERT_EQUAL(2,m2->getMeshDimension());
2241 m2->setName(myName);
2242 DataArrayIdType *tmp;
2243 CPPUNIT_ASSERT(m->areCellsIncludedIn(m2,0,tmp));
2244 CPPUNIT_ASSERT(std::string(myName)==tmp->getName());
2245 CPPUNIT_ASSERT_EQUAL(0,(int)tmp->getNumberOfTuples());
2246 CPPUNIT_ASSERT_EQUAL(1,(int)tmp->getNumberOfComponents());
2252 void MEDCouplingBasicsTest3::testUMeshGetPartBarycenterAndOwner1()
2254 MEDCouplingUMesh *m1=build2DTargetMesh_1();
2255 const mcIdType part[3]={1,0,4};
2256 DataArrayDouble *b=m1->getPartBarycenterAndOwner(part,part+3);
2257 CPPUNIT_ASSERT_EQUAL(2,(int)b->getNumberOfComponents());
2258 CPPUNIT_ASSERT_EQUAL(3,(int)b->getNumberOfTuples());
2259 const double expected1[6]={0.36666666666666665,-0.13333333333333333,-0.05,-0.05,0.45,0.45};
2260 for(int i=0;i<6;i++)
2261 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
2266 void MEDCouplingBasicsTest3::testUMeshGetPartMeasureField1()
2268 MEDCouplingUMesh *m1=build2DTargetMesh_1();
2269 const mcIdType part[3]={1,0,4};
2270 DataArrayDouble *b=m1->getPartMeasureField(true,part,part+3);
2271 CPPUNIT_ASSERT_EQUAL(1,(int)b->getNumberOfComponents());
2272 CPPUNIT_ASSERT_EQUAL(3,(int)b->getNumberOfTuples());
2273 const double expected1[3]={0.125,0.25,0.25};
2274 for(int i=0;i<3;i++)
2275 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
2280 void MEDCouplingBasicsTest3::testUMeshBuildPartOrthogonalField1()
2282 MEDCouplingUMesh *m1=build2DTargetMesh_1();
2283 m1->changeSpaceDimension(3);
2284 const mcIdType part[3]={1,0,4};
2285 MEDCouplingFieldDouble *b=m1->buildPartOrthogonalField(part,part+3);
2286 CPPUNIT_ASSERT_EQUAL(3,(int)b->getArray()->getNumberOfComponents());
2287 CPPUNIT_ASSERT_EQUAL(3,(int)b->getArray()->getNumberOfTuples());
2288 const double expected1[9]={0.,0.,-1.,0.,0.,-1.,0.,0.,-1.};
2289 for(int i=0;i<9;i++)
2290 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getArray()->getIJ(0,i),1e-14);
2295 void MEDCouplingBasicsTest3::testUMeshGetTypesOfPart1()
2297 MEDCouplingUMesh *m1=build2DTargetMesh_1();
2298 const mcIdType part1[]={0,3,4};
2299 std::set<INTERP_KERNEL::NormalizedCellType> s;
2300 s=m1->getTypesOfPart(part1,part1+3);
2301 CPPUNIT_ASSERT(s.size()==1);
2302 CPPUNIT_ASSERT(*s.begin()==INTERP_KERNEL::NORM_QUAD4);
2303 const mcIdType part2[]={2,2,2,1};
2304 s=m1->getTypesOfPart(part2,part2+4);
2305 CPPUNIT_ASSERT(s.size()==1);
2306 CPPUNIT_ASSERT(*s.begin()==INTERP_KERNEL::NORM_TRI3);
2307 const mcIdType part3[]={3,2,1};
2308 s=m1->getTypesOfPart(part3,part3+3);
2309 CPPUNIT_ASSERT(s.size()==2);
2310 CPPUNIT_ASSERT(*s.begin()==INTERP_KERNEL::NORM_TRI3);
2311 CPPUNIT_ASSERT(*(++s.begin())==INTERP_KERNEL::NORM_QUAD4);
2315 void MEDCouplingBasicsTest3::testUMeshKeepCellIdsByType1()
2317 MEDCouplingUMesh *m1=build2DTargetMesh_1();
2318 const mcIdType part1[3]={0,3,4};
2319 DataArrayIdType *a=m1->keepCellIdsByType(INTERP_KERNEL::NORM_TRI3,part1,part1+3);
2320 CPPUNIT_ASSERT_EQUAL(1,(int)a->getNumberOfComponents());
2321 CPPUNIT_ASSERT_EQUAL(0,(int)a->getNumberOfTuples());
2324 const mcIdType part2[5]={3,2,0,2,4};
2325 a=m1->keepCellIdsByType(INTERP_KERNEL::NORM_TRI3,part2,part2+5);
2326 CPPUNIT_ASSERT_EQUAL(1,(int)a->getNumberOfComponents());
2327 CPPUNIT_ASSERT_EQUAL(2,(int)a->getNumberOfTuples());
2328 CPPUNIT_ASSERT_EQUAL(2,(int)a->getIJ(0,0));
2329 CPPUNIT_ASSERT_EQUAL(2,(int)a->getIJ(1,0));
2332 a=m1->keepCellIdsByType(INTERP_KERNEL::NORM_QUAD4,part2,part2+5);
2333 CPPUNIT_ASSERT_EQUAL(1,(int)a->getNumberOfComponents());
2334 CPPUNIT_ASSERT_EQUAL(3,(int)a->getNumberOfTuples());
2335 CPPUNIT_ASSERT_EQUAL(3,(int)a->getIJ(0,0));
2336 CPPUNIT_ASSERT_EQUAL(0,(int)a->getIJ(1,0));
2337 CPPUNIT_ASSERT_EQUAL(4,(int)a->getIJ(2,0));
2343 void MEDCouplingBasicsTest3::testDAIAggregateMulti1()
2345 DataArrayIdType *a=DataArrayIdType::New();
2350 DataArrayIdType *b=DataArrayIdType::New();
2356 std::vector<const DataArrayIdType *> v(2);
2358 DataArrayIdType *c=DataArrayIdType::Aggregate(v);
2359 CPPUNIT_ASSERT_EQUAL(5,(int)c->getNumberOfTuples());
2360 CPPUNIT_ASSERT_EQUAL(2,(int)c->getNumberOfComponents());
2361 CPPUNIT_ASSERT(c->getName()=="aa");
2362 const mcIdType expect1[10]={0,1,2,3,0,1,2,3,4,5};
2363 for(int i=0;i<10;i++)
2364 CPPUNIT_ASSERT_EQUAL(expect1[i],c->getIJ(0,i));
2371 void MEDCouplingBasicsTest3::testMergeUMeshes2()
2373 MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
2374 MEDCouplingUMesh *m2=build3DSurfTargetMesh_1();
2375 MEDCouplingUMesh *m3=build3DSurfTargetMesh_1();
2377 const mcIdType vec1[3]={0,2,3};
2378 MEDCouplingUMesh *m2_2=(MEDCouplingUMesh *)m2->buildPartOfMySelf(vec1,vec1+3,false);
2379 const mcIdType vec2[2]={1,1};
2380 MEDCouplingUMesh *m3_2=(MEDCouplingUMesh *)m3->buildPartOfMySelf(vec2,vec2+2,false);
2382 std::vector<const MEDCouplingUMesh *> ms(3);
2383 std::vector<const MEDCouplingMesh *> ms2(3);
2384 ms[0]=m1; ms[1]=m2_2; ms[2]=m3_2;
2385 ms2[0]=m1; ms2[1]=m2_2; ms2[2]=m3_2;
2387 MEDCouplingUMesh *m4=MEDCouplingUMesh::MergeUMeshes(ms);
2388 m4->checkConsistencyLight();
2389 CPPUNIT_ASSERT_EQUAL(10,(int)m4->getNumberOfCells());
2390 CPPUNIT_ASSERT_EQUAL(20,(int)m4->getNumberOfNodes());
2391 CPPUNIT_ASSERT_EQUAL(45,(int)m4->getNodalConnectivityArrayLen());
2393 MEDCouplingMesh *m4bis=MEDCouplingMesh::MergeMeshes(ms2);
2394 CPPUNIT_ASSERT(m4->isEqual(m4bis,1e-12));
2397 const mcIdType vec3[5]={0,1,2,3,4};
2398 MEDCouplingUMesh *m4_1=(MEDCouplingUMesh *)m4->buildPartOfMySelf(vec3,vec3+5,false);
2399 m4_1->setName(m1->getName().c_str());
2400 CPPUNIT_ASSERT(m4_1->isEqual(m1,1e-12));
2403 const mcIdType vec4[3]={5,6,7};
2404 MEDCouplingUMesh *m4_2=(MEDCouplingUMesh *)m4->buildPartOfMySelf(vec4,vec4+3,false);
2405 DataArrayIdType *cellCor=0;
2406 DataArrayIdType *nodeCor=0;
2407 m4_2->checkGeoEquivalWith(m2_2,10,1e-12,cellCor,nodeCor);
2408 CPPUNIT_ASSERT(cellCor==0);
2409 CPPUNIT_ASSERT(nodeCor==0);
2412 const mcIdType vec5[2]={8,9};
2413 MEDCouplingUMesh *m4_3=(MEDCouplingUMesh *)m4->buildPartOfMySelf(vec5,vec5+2,false);
2414 CPPUNIT_ASSERT_EQUAL(2,(int)m4_3->getNumberOfCells());
2415 CPPUNIT_ASSERT_EQUAL(3,(int)m4_3->getNumberOfNodes());
2417 m4_3->setName(m3_2->getName().c_str());
2418 CPPUNIT_ASSERT(m4_3->isEqual(m3_2,1e-12));
2429 void MEDCouplingBasicsTest3::testBuild0DMeshFromCoords1()
2431 const double sourceCoords[12]={-0.3,-0.3,0., 0.7,-0.3,0., -0.3,0.7,0., 0.7,0.7,0.};
2432 DataArrayDouble *coo=DataArrayDouble::New();
2434 coo->setName("My0D");
2435 std::copy(sourceCoords,sourceCoords+12,coo->getPointer());
2436 MEDCouplingUMesh *m=MEDCouplingUMesh::Build0DMeshFromCoords(coo);
2437 m->checkConsistencyLight();
2438 CPPUNIT_ASSERT_EQUAL(4,(int)m->getNumberOfNodes());
2439 CPPUNIT_ASSERT_EQUAL(4,(int)m->getNumberOfCells());
2440 CPPUNIT_ASSERT_EQUAL(3,m->getSpaceDimension());
2441 CPPUNIT_ASSERT_EQUAL(0,m->getMeshDimension());
2442 std::set<INTERP_KERNEL::NormalizedCellType> types=m->getAllGeoTypes();
2443 CPPUNIT_ASSERT_EQUAL(1,(int)types.size());
2444 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POINT1,*types.begin());
2445 for(int i=0;i<4;i++)
2447 std::vector<mcIdType> conn;
2448 m->getNodeIdsOfCell(i,conn);
2449 CPPUNIT_ASSERT_EQUAL(1,(int)conn.size());
2450 CPPUNIT_ASSERT_EQUAL(i,(int)conn[0]);
2451 CPPUNIT_ASSERT(INTERP_KERNEL::NORM_POINT1==m->getTypeOfCell(i));
2453 CPPUNIT_ASSERT(std::string(m->getName())=="My0D");