1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "MEDCouplingBasicsTest1.hxx"
21 #include "MEDCouplingUMesh.hxx"
22 #include "MEDCouplingCMesh.hxx"
23 #include "MEDCouplingExtrudedMesh.hxx"
24 #include "MEDCouplingFieldDouble.hxx"
25 #include "MEDCouplingMemArray.hxx"
32 using namespace ParaMEDMEM;
34 void MEDCouplingBasicsTest1::testArray()
36 int tmp1[6]={7,6,5,4,3,2};
37 const int tmp2[3]={8,9,10};
40 mem.useArray(tmp1,false,CPP_DEALLOC,6);
41 CPPUNIT_ASSERT(tmp1==mem.getConstPointer());
42 CPPUNIT_ASSERT_THROW(mem.getPointer(),INTERP_KERNEL::Exception);
43 CPPUNIT_ASSERT_THROW(mem[2]=7,INTERP_KERNEL::Exception);
44 CPPUNIT_ASSERT_THROW(mem.writeOnPlace(0,12,tmp2,3),INTERP_KERNEL::Exception);
45 mem.writeOnPlace(4,12,tmp2,3);
49 std::copy(tmp1,tmp1+6,tmp3);
51 mem2.useArray(tmp3,true,CPP_DEALLOC,6);
52 CPPUNIT_ASSERT(tmp3==mem2.getConstPointer());
53 CPPUNIT_ASSERT(tmp3==mem2.getPointer());
54 CPPUNIT_ASSERT_EQUAL(5,mem2[2]);
56 CPPUNIT_ASSERT_EQUAL(7,mem2[2]);
57 mem2.writeOnPlace(0,12,tmp2,3);
58 CPPUNIT_ASSERT_EQUAL(9,mem2[2]);
59 CPPUNIT_ASSERT_EQUAL(12,mem2[0]);
60 mem2.writeOnPlace(4,12,tmp2,3);
64 void MEDCouplingBasicsTest1::testArray2()
66 DataArrayDouble *arr=DataArrayDouble::New();
68 double *tmp=arr->getPointer();
69 const double arrRef[12]={12.,11.,10.,9.,8.,7.,6.,5.,4.,3.,2.,1.};
70 std::copy(arrRef,arrRef+12,tmp);
71 arr->setInfoOnComponent(0,"ggg");
72 arr->setInfoOnComponent(1,"hhhh");
73 arr->setInfoOnComponent(2,"jj");
74 arr->setInfoOnComponent(3,"kkkkkk");
75 DataArrayInt *arr2=arr->convertToIntArr();
76 DataArrayDouble *arr3=arr2->convertToDblArr();
78 CPPUNIT_ASSERT(arr->isEqual(*arr3,1e-14));
83 void MEDCouplingBasicsTest1::testArray3()
85 DataArrayInt *arr1=DataArrayInt::New();
87 int *tmp=arr1->getPointer();
88 const int arr1Ref[14]={0,10,1,11,2,12,3,13,4,14,5,15,6,16};
89 std::copy(arr1Ref,arr1Ref+14,tmp);
90 CPPUNIT_ASSERT_EQUAL(7,arr1->getNumberOfTuples());
91 CPPUNIT_ASSERT_EQUAL(2,arr1->getNumberOfComponents());
92 CPPUNIT_ASSERT(std::equal(arr1Ref,arr1Ref+14,arr1->getConstPointer()));
93 DataArrayInt *arr2=arr1->substr(3);
94 CPPUNIT_ASSERT_EQUAL(4,arr2->getNumberOfTuples());
95 CPPUNIT_ASSERT_EQUAL(2,arr2->getNumberOfComponents());
96 CPPUNIT_ASSERT(std::equal(arr1Ref+6,arr1Ref+14,arr2->getConstPointer()));
98 DataArrayInt *arr3=arr1->substr(2,5);
99 CPPUNIT_ASSERT_EQUAL(3,arr3->getNumberOfTuples());
100 CPPUNIT_ASSERT_EQUAL(2,arr3->getNumberOfComponents());
101 CPPUNIT_ASSERT(std::equal(arr1Ref+4,arr1Ref+10,arr3->getConstPointer()));
105 DataArrayDouble *arr4=DataArrayDouble::New();
107 double *tmp2=arr4->getPointer();
108 const int arr4Ref[14]={0.8,10.8,1.9,11.9,2.1,12.1,3.2,13.2,4.3,14.3,5.4,15.4,6.5,16.5};
109 std::copy(arr4Ref,arr4Ref+14,tmp2);
110 CPPUNIT_ASSERT_EQUAL(7,arr4->getNumberOfTuples());
111 CPPUNIT_ASSERT_EQUAL(2,arr4->getNumberOfComponents());
112 CPPUNIT_ASSERT(std::equal(arr4Ref,arr4Ref+14,arr4->getConstPointer()));
113 DataArrayDouble *arr5=arr4->substr(3);
114 CPPUNIT_ASSERT_EQUAL(4,arr5->getNumberOfTuples());
115 CPPUNIT_ASSERT_EQUAL(2,arr5->getNumberOfComponents());
116 CPPUNIT_ASSERT(std::equal(arr4Ref+6,arr4Ref+14,arr5->getConstPointer()));
118 DataArrayDouble *arr6=arr4->substr(2,5);
119 CPPUNIT_ASSERT_EQUAL(3,arr6->getNumberOfTuples());
120 CPPUNIT_ASSERT_EQUAL(2,arr6->getNumberOfComponents());
121 CPPUNIT_ASSERT(std::equal(arr4Ref+4,arr4Ref+10,arr6->getConstPointer()));
126 void MEDCouplingBasicsTest1::testMesh()
128 const int nbOfCells=6;
129 const int nbOfNodes=12;
131 double coords[3*nbOfNodes]={
132 0.024155, 0.04183768725682622, -0.305, 0.04831000000000001, -1.015761910347357e-17, -0.305, 0.09662000000000001, -1.832979297858306e-18,
133 -0.305, 0.120775, 0.04183768725682623, -0.305, 0.09662000000000001, 0.08367537451365245, -0.305, 0.04831000000000001,
134 0.08367537451365246, -0.305, 0.024155, 0.04183768725682622, -0.2863, 0.04831000000000001, -1.015761910347357e-17, -0.2863,
135 0.09662000000000001, -1.832979297858306e-18, -0.2863, 0.120775, 0.04183768725682623, -0.2863, 0.09662000000000001, 0.08367537451365245,
136 -0.2863, 0.04831000000000001, 0.08367537451365246, -0.2863, };
138 int tab4[4*nbOfCells]={
139 1, 2, 8, 7, 2, 3, 9, 8, 3, 4, 10, 9, 4, 5, 11, 10, 5, 0, 6, 11,
142 MEDCouplingUMesh *mesh=MEDCouplingUMesh::New();
143 mesh->setMeshDimension(2);
144 mesh->allocateCells(8);
145 const int *curConn=tab4;
146 for(int i=0;i<nbOfCells;i++,curConn+=4)
147 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,curConn);
148 mesh->finishInsertingCells();
149 CPPUNIT_ASSERT_EQUAL(30,mesh->getNodalConnectivity()->getNbOfElems());
150 CPPUNIT_ASSERT_EQUAL(nbOfCells,mesh->getNumberOfCells());
151 //test 0 - no copy no ownership
152 DataArrayDouble *myCoords=DataArrayDouble::New();
153 myCoords->useArray(coords,false,CPP_DEALLOC,nbOfNodes,3);
154 mesh->setCoords(myCoords);
155 mesh->setCoords(myCoords);
157 CPPUNIT_ASSERT_EQUAL(nbOfCells,mesh->getNumberOfCells());
158 mesh->checkCoherency();
159 //test 1 - no copy ownership C++
160 myCoords=DataArrayDouble::New();
161 double *tmp=new double[3*nbOfNodes];
162 std::copy(coords,coords+3*nbOfNodes,tmp);
163 myCoords->useArray(tmp,true,CPP_DEALLOC,nbOfNodes,3);
164 mesh->setCoords(myCoords);
166 CPPUNIT_ASSERT_EQUAL(nbOfCells,mesh->getNumberOfCells());
167 mesh->checkCoherency();
168 //test 2 - no copy ownership C
169 myCoords=DataArrayDouble::New();
170 tmp=(double *)malloc(3*nbOfNodes*sizeof(double));
171 std::copy(coords,coords+3*nbOfNodes,tmp);
172 myCoords->useArray(tmp,true,C_DEALLOC,nbOfNodes,3);
173 mesh->setCoords(myCoords);
175 CPPUNIT_ASSERT_EQUAL(nbOfNodes,mesh->getNumberOfNodes());
176 mesh->checkCoherency();
178 myCoords=DataArrayDouble::New();
179 myCoords->alloc(nbOfNodes,3);
180 tmp=myCoords->getPointer();
181 std::copy(coords,coords+3*nbOfNodes,tmp);
182 // test 3 bis deepcopy
183 DataArrayDouble *myCoords2=DataArrayDouble::New();
184 *myCoords2=*myCoords;
185 myCoords2->decrRef();
187 mesh->setCoords(myCoords);
189 CPPUNIT_ASSERT_EQUAL(nbOfNodes,mesh->getNumberOfNodes());
190 mesh->checkCoherency();
191 CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
192 // test clone not recursively
193 MEDCouplingUMesh *mesh2=mesh->clone(false);
194 CPPUNIT_ASSERT(mesh2!=mesh);
195 mesh2->checkCoherency();
196 CPPUNIT_ASSERT_EQUAL(nbOfCells,mesh2->getNumberOfCells());
197 CPPUNIT_ASSERT_EQUAL(nbOfNodes,mesh2->getNumberOfNodes());
198 CPPUNIT_ASSERT_EQUAL(3,mesh2->getSpaceDimension());
199 CPPUNIT_ASSERT(mesh!=mesh2);
200 CPPUNIT_ASSERT(mesh->getCoords()==mesh2->getCoords());
201 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.2863,mesh2->getCoords()->getIJ(11,2),1e-14);
202 CPPUNIT_ASSERT(mesh->getNodalConnectivity()==mesh2->getNodalConnectivity());
203 CPPUNIT_ASSERT_EQUAL(3,mesh2->getNodalConnectivity()->getIJ(7,0));
204 CPPUNIT_ASSERT(mesh->getNodalConnectivityIndex()==mesh2->getNodalConnectivityIndex());
205 CPPUNIT_ASSERT_EQUAL(15,mesh2->getNodalConnectivityIndex()->getIJ(3,0));
207 // test clone not recursively
208 MEDCouplingUMesh *mesh3=mesh->clone(true);
209 CPPUNIT_ASSERT(mesh3!=mesh);
210 mesh3->checkCoherency();
211 CPPUNIT_ASSERT_EQUAL(nbOfCells,mesh3->getNumberOfCells());
212 CPPUNIT_ASSERT_EQUAL(nbOfNodes,mesh3->getNumberOfNodes());
213 CPPUNIT_ASSERT_EQUAL(3,mesh3->getSpaceDimension());
214 CPPUNIT_ASSERT(mesh!=mesh3);
215 CPPUNIT_ASSERT(mesh->getCoords()!=mesh3->getCoords());
216 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.2863,mesh3->getCoords()->getIJ(11,2),1e-14);
217 CPPUNIT_ASSERT(mesh->getNodalConnectivity()!=mesh3->getNodalConnectivity());
218 CPPUNIT_ASSERT_EQUAL(3,mesh3->getNodalConnectivity()->getIJ(7,0));
219 CPPUNIT_ASSERT(mesh->getNodalConnectivityIndex()!=mesh3->getNodalConnectivityIndex());
220 CPPUNIT_ASSERT_EQUAL(15,mesh3->getNodalConnectivityIndex()->getIJ(3,0));
222 //test 4 - Field on cells
223 MEDCouplingFieldDouble *fieldOnCells=MEDCouplingFieldDouble::New(ON_CELLS);
224 fieldOnCells->setMesh(mesh);
225 DataArrayDouble *array=DataArrayDouble::New();
226 array->alloc(nbOfCells,9);
227 fieldOnCells->setArray(array);
228 tmp=array->getPointer();
230 std::fill(tmp,tmp+9*nbOfCells,7.);
231 //content of field changed -> declare it.
232 fieldOnCells->declareAsNew();
233 fieldOnCells->checkCoherency();
234 // testing clone of fields - no recursive
235 MEDCouplingFieldDouble *fieldOnCells2=fieldOnCells->clone(false);
236 CPPUNIT_ASSERT(fieldOnCells2!=fieldOnCells);
237 fieldOnCells2->checkCoherency();
238 CPPUNIT_ASSERT_EQUAL(nbOfCells,fieldOnCells2->getNumberOfTuples());
239 CPPUNIT_ASSERT_EQUAL(9,fieldOnCells2->getNumberOfComponents());
240 CPPUNIT_ASSERT(fieldOnCells2->getArray()==fieldOnCells->getArray());
241 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,fieldOnCells2->getArray()->getIJ(3,7),1e-14);
242 CPPUNIT_ASSERT(fieldOnCells2->getMesh()==fieldOnCells->getMesh());
243 // testing clone of fields - recursive
244 MEDCouplingFieldDouble *fieldOnCells3=fieldOnCells->clone(true);
245 CPPUNIT_ASSERT(fieldOnCells3!=fieldOnCells);
246 fieldOnCells3->checkCoherency();
247 CPPUNIT_ASSERT_EQUAL(nbOfCells,fieldOnCells3->getNumberOfTuples());
248 CPPUNIT_ASSERT_EQUAL(9,fieldOnCells3->getNumberOfComponents());
249 CPPUNIT_ASSERT(fieldOnCells3->getArray()!=fieldOnCells->getArray());
250 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,fieldOnCells3->getArray()->getIJ(3,7),1e-14);
251 CPPUNIT_ASSERT(fieldOnCells3->getMesh()==fieldOnCells->getMesh());
252 fieldOnCells2->decrRef();
253 fieldOnCells3->decrRef();
255 fieldOnCells->decrRef();
260 void MEDCouplingBasicsTest1::testMeshPointsCloud()
262 double targetCoords[27]={-0.3,-0.3,0.5, 0.2,-0.3,1., 0.7,-0.3,1.5, -0.3,0.2,0.5, 0.2,0.2,1., 0.7,0.2,1.5, -0.3,0.7,0.5, 0.2,0.7,1., 0.7,0.7,1.5};
263 const int targetConn[]={0,1,2,3,4,5,7,6};
264 MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
265 targetMesh->setMeshDimension(0);
266 targetMesh->allocateCells(8);
267 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn);
268 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+1);
269 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+2);
270 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+3);
271 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+4);
272 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+5);
273 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+6);
274 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+7);
275 targetMesh->finishInsertingCells();
276 DataArrayDouble *myCoords=DataArrayDouble::New();
277 myCoords->alloc(9,3);
278 std::copy(targetCoords,targetCoords+27,myCoords->getPointer());
279 targetMesh->setCoords(myCoords);
282 targetMesh->checkCoherency();
283 CPPUNIT_ASSERT_EQUAL(3,targetMesh->getSpaceDimension());
284 CPPUNIT_ASSERT_EQUAL(8,targetMesh->getNumberOfCells());
285 CPPUNIT_ASSERT_EQUAL(9,targetMesh->getNumberOfNodes());
286 CPPUNIT_ASSERT_EQUAL(0,targetMesh->getMeshDimension());
288 targetMesh->decrRef();
291 void MEDCouplingBasicsTest1::testMeshM1D()
293 MEDCouplingUMesh *meshM1D=MEDCouplingUMesh::New();
294 CPPUNIT_ASSERT_THROW(meshM1D->getMeshDimension(),INTERP_KERNEL::Exception);
295 CPPUNIT_ASSERT_THROW(meshM1D->getNumberOfNodes(),INTERP_KERNEL::Exception);
296 CPPUNIT_ASSERT_THROW(meshM1D->getNumberOfCells(),INTERP_KERNEL::Exception);
297 CPPUNIT_ASSERT_THROW(meshM1D->setMeshDimension(-2),INTERP_KERNEL::Exception);
298 CPPUNIT_ASSERT_THROW(meshM1D->setMeshDimension(-10),INTERP_KERNEL::Exception);
299 CPPUNIT_ASSERT_THROW(meshM1D->checkCoherency(),INTERP_KERNEL::Exception);
300 meshM1D->setMeshDimension(-1);
301 meshM1D->checkCoherency();
302 CPPUNIT_ASSERT_EQUAL(-1,meshM1D->getMeshDimension());
303 CPPUNIT_ASSERT_EQUAL(1,meshM1D->getNumberOfCells());
304 CPPUNIT_ASSERT_THROW(meshM1D->getNumberOfNodes(),INTERP_KERNEL::Exception);
305 CPPUNIT_ASSERT_THROW(meshM1D->getSpaceDimension(),INTERP_KERNEL::Exception);
306 MEDCouplingUMesh *cpy=meshM1D->clone(true);
307 CPPUNIT_ASSERT(cpy->isEqual(meshM1D,1e-12));
309 MEDCouplingFieldDouble *fieldOnCells=MEDCouplingFieldDouble::New(ON_CELLS);
310 fieldOnCells->setMesh(meshM1D);
311 DataArrayDouble *array=DataArrayDouble::New();
313 fieldOnCells->setArray(array);
314 double *tmp=array->getPointer();
316 std::fill(tmp,tmp+6,7.);
317 fieldOnCells->checkCoherency();
319 fieldOnCells->decrRef();
323 void MEDCouplingBasicsTest1::testDeepCopy()
325 DataArrayDouble *array=DataArrayDouble::New();
327 std::fill(array->getPointer(),array->getPointer()+5*3,7.);
328 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,array->getIJ(3,2),1e-14);
329 double *tmp1=array->getPointer();
330 DataArrayDouble *array2=array->deepCpy();
331 double *tmp2=array2->getPointer();
332 CPPUNIT_ASSERT(tmp1!=tmp2);
334 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,array2->getIJ(3,2),1e-14);
337 DataArrayInt *array3=DataArrayInt::New();
339 std::fill(array3->getPointer(),array3->getPointer()+5*3,17);
340 CPPUNIT_ASSERT_EQUAL(17,array3->getIJ(3,2));
341 int *tmp3=array3->getPointer();
342 DataArrayInt *array4=array3->deepCpy();
343 int *tmp4=array4->getPointer();
344 CPPUNIT_ASSERT(tmp3!=tmp4);
346 CPPUNIT_ASSERT_EQUAL(17,array4->getIJ(3,2));
350 void MEDCouplingBasicsTest1::testRevNodal()
352 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
353 DataArrayInt *revNodal=DataArrayInt::New();
354 DataArrayInt *revNodalIndx=DataArrayInt::New();
356 mesh->getReverseNodalConnectivity(revNodal,revNodalIndx);
357 const int revNodalExpected[18]={0,0,1,1,2,0,3,0,1,2,3,4,2,4,3,3,4,4};
358 const int revNodalIndexExpected[10]={0,1,3,5,7,12,14,15,17,18};
359 CPPUNIT_ASSERT_EQUAL(18,revNodal->getNbOfElems());
360 CPPUNIT_ASSERT_EQUAL(10,revNodalIndx->getNbOfElems());
361 CPPUNIT_ASSERT(std::equal(revNodalExpected,revNodalExpected+18,revNodal->getPointer()));
362 CPPUNIT_ASSERT(std::equal(revNodalIndexExpected,revNodalIndexExpected+10,revNodalIndx->getPointer()));
365 revNodalIndx->decrRef();
369 void MEDCouplingBasicsTest1::testConvertToPolyTypes()
372 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
374 const int elts[2]={1,3};
375 std::vector<int> eltsV(elts,elts+2);
376 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
377 mesh->checkCoherency();
378 CPPUNIT_ASSERT_EQUAL(5,mesh->getNumberOfCells());
379 CPPUNIT_ASSERT_EQUAL(23,mesh->getNodalConnectivity()->getNumberOfTuples());
380 const int *pt=mesh->getNodalConnectivity()->getConstPointer();
381 const int expected1[23]={4, 0, 3, 4, 1, 5, 1, 4, 2, 3, 4, 5, 2, 5, 6, 7, 4, 3, 4, 7, 8, 5, 4};
382 CPPUNIT_ASSERT(std::equal(expected1,expected1+23,pt));
386 mesh=build3DTargetMesh_1();
387 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
388 mesh->checkCoherency();
389 CPPUNIT_ASSERT_EQUAL(8,mesh->getNumberOfCells());
390 CPPUNIT_ASSERT_EQUAL(114,mesh->getNodalConnectivity()->getNumberOfTuples());
391 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
392 mesh->checkCoherency();
393 CPPUNIT_ASSERT_EQUAL(8,mesh->getNumberOfCells());
394 CPPUNIT_ASSERT_EQUAL(114,mesh->getNodalConnectivity()->getNumberOfTuples());
399 void MEDCouplingBasicsTest1::testDescConn2D()
401 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
402 DataArrayInt *desc=DataArrayInt::New();
403 DataArrayInt *descIndx=DataArrayInt::New();
404 DataArrayInt *revDesc=DataArrayInt::New();
405 DataArrayInt *revDescIndx=DataArrayInt::New();
407 MEDCouplingUMesh *mesh2=mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
408 mesh2->checkCoherency();
409 CPPUNIT_ASSERT_EQUAL(1,mesh2->getMeshDimension());
410 CPPUNIT_ASSERT_EQUAL(13,mesh2->getNumberOfCells());
411 CPPUNIT_ASSERT_EQUAL(14,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(14,revDescIndx->getNumberOfTuples());
412 CPPUNIT_ASSERT_EQUAL(6,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(6,descIndx->getNumberOfTuples());
413 CPPUNIT_ASSERT_EQUAL(18,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,desc->getNumberOfTuples());
414 CPPUNIT_ASSERT_EQUAL(18,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,revDesc->getNumberOfTuples());
415 const int expected1[18]={0,1,2,3, 2,4,5, 6,7,4, 8,9,1,10, 11,12,6,9};
416 CPPUNIT_ASSERT(std::equal(expected1,expected1+18,desc->getConstPointer()));
417 const int expected2[6]={0,4,7,10,14,18};
418 CPPUNIT_ASSERT(std::equal(expected2,expected2+6,descIndx->getConstPointer()));
419 const int expected3[14]={0,1,3,5,6,8,9,11,12,13,15,16,17,18};
420 CPPUNIT_ASSERT(std::equal(expected3,expected3+14,revDescIndx->getConstPointer()));
421 const int expected4[18]={0, 0,3, 0,1, 0, 1,2, 1, 2,4, 2, 3, 3,4, 3, 4, 4};
422 CPPUNIT_ASSERT(std::equal(expected4,expected4+18,revDesc->getConstPointer()));
423 DataArrayInt *conn=mesh2->getNodalConnectivity();
424 DataArrayInt *connIndex=mesh2->getNodalConnectivityIndex();
425 const int expected5[14]={0,3,6,9,12,15,18,21,24,27,30,33,36,39};
426 CPPUNIT_ASSERT(std::equal(expected5,expected5+14,connIndex->getConstPointer()));
427 const int expected6[39]={1, 0, 3, 1, 3, 4, 1, 4, 1, 1, 1, 0, 1, 4, 2, 1, 2, 1, 1, 4, 5, 1, 5, 2, 1, 6, 7, 1, 7, 4, 1, 3, 6, 1, 7, 8, 1, 8, 5};
428 CPPUNIT_ASSERT(std::equal(expected6,expected6+39,conn->getConstPointer()));
433 revDescIndx->decrRef();
436 const int elts[2]={1,3};
437 std::vector<int> eltsV(elts,elts+2);
438 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
439 mesh->checkCoherency();
441 desc=DataArrayInt::New();
442 descIndx=DataArrayInt::New();
443 revDesc=DataArrayInt::New();
444 revDescIndx=DataArrayInt::New();
446 mesh2=mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
447 mesh2->checkCoherency();
448 CPPUNIT_ASSERT_EQUAL(1,mesh2->getMeshDimension());
449 CPPUNIT_ASSERT_EQUAL(13,mesh2->getNumberOfCells());
450 CPPUNIT_ASSERT_EQUAL(14,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(14,revDescIndx->getNumberOfTuples());
451 CPPUNIT_ASSERT_EQUAL(6,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(6,descIndx->getNumberOfTuples());
452 CPPUNIT_ASSERT_EQUAL(18,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,desc->getNumberOfTuples());
453 CPPUNIT_ASSERT_EQUAL(18,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,revDesc->getNumberOfTuples());
454 CPPUNIT_ASSERT(std::equal(expected1,expected1+18,desc->getConstPointer()));
455 CPPUNIT_ASSERT(std::equal(expected2,expected2+6,descIndx->getConstPointer()));
456 CPPUNIT_ASSERT(std::equal(expected3,expected3+14,revDescIndx->getConstPointer()));
457 CPPUNIT_ASSERT(std::equal(expected4,expected4+18,revDesc->getConstPointer()));
458 conn=mesh2->getNodalConnectivity();
459 connIndex=mesh2->getNodalConnectivityIndex();
460 CPPUNIT_ASSERT(std::equal(expected5,expected5+14,connIndex->getConstPointer()));
461 CPPUNIT_ASSERT(std::equal(expected6,expected6+39,conn->getConstPointer()));
466 revDescIndx->decrRef();
471 void MEDCouplingBasicsTest1::testDescConn3D()
473 MEDCouplingUMesh *mesh=build3DTargetMesh_1();
474 DataArrayInt *desc=DataArrayInt::New();
475 DataArrayInt *descIndx=DataArrayInt::New();
476 DataArrayInt *revDesc=DataArrayInt::New();
477 DataArrayInt *revDescIndx=DataArrayInt::New();
479 MEDCouplingUMesh *mesh2=mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
480 mesh2->checkCoherency();
481 CPPUNIT_ASSERT_EQUAL(2,mesh2->getMeshDimension());
482 CPPUNIT_ASSERT_EQUAL(36,mesh2->getNumberOfCells());
483 CPPUNIT_ASSERT_EQUAL(37,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(37,revDescIndx->getNumberOfTuples());
484 CPPUNIT_ASSERT_EQUAL(9,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(9,descIndx->getNumberOfTuples());
485 CPPUNIT_ASSERT_EQUAL(48,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,desc->getNumberOfTuples());
486 CPPUNIT_ASSERT_EQUAL(48,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,revDesc->getNumberOfTuples());
487 const int expected1[9]={0, 6, 12, 18, 24, 30, 36, 42, 48};
488 const int expected2[48]={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 3, 11, 12, 4, 13, 14, 15, 16, 17, 10, 18, 19, 13, 1, 20, 21, 22, 23, 24, 7, 25, 26, 27, 28, 22, 12, 29, 23, 30, 31, 32, 17, 33, 28, 34, 35, 30};
489 const int expected3[37]={0, 1, 3, 4, 6, 8, 9, 10, 12, 13, 14, 16, 17, 19, 21, 22, 23, 24, 26, 27, 28, 29, 30, 32, 34, 35, 36, 37, 38, 40, 41, 43, 44, 45, 46, 47, 48};
490 const int expected4[48]={0, 0, 4, 0, 0, 1, 0, 2, 0, 1, 1, 5, 1, 1, 1, 3, 2, 2, 6, 2, 3, 2, 2, 3, 3, 7, 3, 3, 4, 4, 4, 5, 4, 6, 4, 5, 5, 5, 5, 7, 6, 6, 7, 6, 6, 7, 7, 7};
491 const int expected5[37]={0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115, 120, 125, 130, 135, 140, 145, 150, 155, 160, 165, 170, 175, 180};
492 const int expected6[180]={4, 0, 1, 4, 3, 4, 9, 12, 13, 10, 4, 0, 9, 10, 1, 4, 1, 10, 13, 4, 4, 4, 13, 12, 3, 4, 3, 12, 9, 0, 4, 1, 2, 5, 4, 4, 10, 13, 14, 11, 4, 1, 10, 11, 2, 4, 2, 11, 14,
493 5, 4, 5, 14, 13, 4, 4, 3, 4, 7, 6, 4, 12, 15, 16, 13, 4, 4, 13, 16, 7, 4, 7, 16, 15, 6, 4, 6, 15, 12, 3, 4, 4, 5, 8, 7, 4, 13, 16, 17, 14, 4, 5, 14, 17, 8, 4, 8,
494 17, 16, 7, 4, 18, 21, 22, 19, 4, 9, 18, 19, 10, 4, 10, 19, 22, 13, 4, 13, 22, 21, 12, 4, 12, 21, 18, 9, 4, 19, 22, 23, 20, 4, 10, 19, 20, 11, 4, 11, 20, 23, 14, 4,
495 14, 23, 22, 13, 4, 21, 24, 25, 22, 4, 13, 22, 25, 16, 4, 16, 25, 24, 15, 4, 15, 24, 21, 12, 4, 22, 25, 26, 23, 4, 14, 23, 26, 17, 4, 17, 26, 25, 16};
496 const int expected7[180]={4, 0, 1, 4, 3, 4, 9, 12, 13, 10, 4, 0, 9, 10, 1, 4, 1, 10, 13, 4, 4, 4, 13, 12, 3, 4, 3, 12, 9, 0, 5, 1, 2, 5, 4, 5, 10, 13, 14, 11, 5, 1, 10, 11, 2, 5, 2, 11, 14,
497 5, 5, 5, 14, 13, 4, 4, 3, 4, 7, 6, 4, 12, 15, 16, 13, 4, 4, 13, 16, 7, 4, 7, 16, 15, 6, 4, 6, 15, 12, 3, 5, 4, 5, 8, 7, 5, 13, 16, 17, 14, 5, 5, 14, 17, 8, 5, 8,
498 17, 16, 7, 4, 18, 21, 22, 19, 4, 9, 18, 19, 10, 4, 10, 19, 22, 13, 4, 13, 22, 21, 12, 4, 12, 21, 18, 9, 4, 19, 22, 23, 20, 4, 10, 19, 20, 11, 4, 11, 20, 23, 14, 4,
499 14, 23, 22, 13, 4, 21, 24, 25, 22, 4, 13, 22, 25, 16, 4, 16, 25, 24, 15, 4, 15, 24, 21, 12, 4, 22, 25, 26, 23, 4, 14, 23, 26, 17, 4, 17, 26, 25, 16};
501 CPPUNIT_ASSERT(std::equal(expected1,expected1+9,descIndx->getConstPointer()));
502 CPPUNIT_ASSERT(std::equal(expected2,expected2+48,desc->getConstPointer()));
503 CPPUNIT_ASSERT(std::equal(expected3,expected3+37,revDescIndx->getConstPointer()));
504 CPPUNIT_ASSERT(std::equal(expected4,expected4+48,revDesc->getConstPointer()));
505 CPPUNIT_ASSERT(std::equal(expected5,expected5+37,mesh2->getNodalConnectivityIndex()->getConstPointer()));
506 CPPUNIT_ASSERT(std::equal(expected6,expected6+180,mesh2->getNodalConnectivity()->getConstPointer()));
511 revDescIndx->decrRef();
514 const int elts[2]={1,3};
515 std::vector<int> eltsV(elts,elts+2);
516 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
517 mesh->checkCoherency();
518 desc=DataArrayInt::New();
519 descIndx=DataArrayInt::New();
520 revDesc=DataArrayInt::New();
521 revDescIndx=DataArrayInt::New();
522 mesh2=mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
523 mesh2->checkCoherency();
524 CPPUNIT_ASSERT_EQUAL(2,mesh2->getMeshDimension());
525 CPPUNIT_ASSERT_EQUAL(36,mesh2->getNumberOfCells());
526 CPPUNIT_ASSERT_EQUAL(37,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(37,revDescIndx->getNumberOfTuples());
527 CPPUNIT_ASSERT_EQUAL(9,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(9,descIndx->getNumberOfTuples());
528 CPPUNIT_ASSERT_EQUAL(48,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,desc->getNumberOfTuples());
529 CPPUNIT_ASSERT_EQUAL(48,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,revDesc->getNumberOfTuples());
530 CPPUNIT_ASSERT(std::equal(expected1,expected1+9,descIndx->getConstPointer()));
531 CPPUNIT_ASSERT(std::equal(expected2,expected2+48,desc->getConstPointer()));
532 CPPUNIT_ASSERT(std::equal(expected3,expected3+37,revDescIndx->getConstPointer()));
533 CPPUNIT_ASSERT(std::equal(expected4,expected4+48,revDesc->getConstPointer()));
534 CPPUNIT_ASSERT(std::equal(expected5,expected5+37,mesh2->getNodalConnectivityIndex()->getConstPointer()));
535 CPPUNIT_ASSERT(std::equal(expected7,expected7+180,mesh2->getNodalConnectivity()->getConstPointer()));
540 revDescIndx->decrRef();
545 void MEDCouplingBasicsTest1::testFindBoundaryNodes()
547 MEDCouplingUMesh *mesh=build3DTargetMesh_1();
548 DataArrayInt *boundaryNodes=mesh->findBoundaryNodes();
549 CPPUNIT_ASSERT_EQUAL(26,boundaryNodes->getNumberOfTuples());
550 CPPUNIT_ASSERT_EQUAL(1,boundaryNodes->getNumberOfComponents());
551 const int expected1[26]={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26};
552 CPPUNIT_ASSERT(std::equal(expected1,expected1+26,boundaryNodes->begin()));
553 boundaryNodes->decrRef();
557 void MEDCouplingBasicsTest1::testBoundaryMesh()
559 MEDCouplingUMesh *mesh=build3DTargetMesh_1();
560 MEDCouplingPointSet *mesh2=mesh->buildBoundaryMesh(false);
561 CPPUNIT_ASSERT_EQUAL(24,mesh2->getNumberOfCells());
562 CPPUNIT_ASSERT_EQUAL(26,mesh2->getNumberOfNodes());
567 void MEDCouplingBasicsTest1::testBuildPartOfMySelf()
569 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
570 mesh->setName("Toto");
571 const int tab1[2]={0,4};
572 const int tab2[3]={0,2,3};
574 MEDCouplingPointSet *subMeshSimple=mesh->buildPartOfMySelf(tab1,tab1+2,true);
575 MEDCouplingUMesh *subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
576 CPPUNIT_ASSERT(subMesh);
577 std::string name(subMesh->getName());
578 CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllTypes().size());
579 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*mesh->getAllTypes().begin());
580 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++(mesh->getAllTypes().begin())));
581 CPPUNIT_ASSERT_EQUAL(1,(int)subMesh->getAllTypes().size());
582 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllTypes().begin());
583 CPPUNIT_ASSERT(name=="PartOf_Toto");
584 CPPUNIT_ASSERT(mesh->getCoords()==subMesh->getCoords());
585 CPPUNIT_ASSERT_EQUAL(2,subMesh->getNumberOfCells());
586 const int subConn[10]={4,0,3,4,1,4,7,8,5,4};
587 const int subConnIndex[3]={0,5,10};
588 CPPUNIT_ASSERT_EQUAL(10,subMesh->getNodalConnectivity()->getNbOfElems());
589 CPPUNIT_ASSERT_EQUAL(3,subMesh->getNodalConnectivityIndex()->getNbOfElems());
590 CPPUNIT_ASSERT(std::equal(subConn,subConn+10,subMesh->getNodalConnectivity()->getPointer()));
591 CPPUNIT_ASSERT(std::equal(subConnIndex,subConnIndex+3,subMesh->getNodalConnectivityIndex()->getPointer()));
594 subMeshSimple=mesh->buildPartOfMySelf(tab2,tab2+3,true);
595 subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
596 CPPUNIT_ASSERT(subMesh);
597 name=subMesh->getName();
598 CPPUNIT_ASSERT_EQUAL(2,(int)subMesh->getAllTypes().size());
599 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*subMesh->getAllTypes().begin());
600 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++(subMesh->getAllTypes().begin())));
601 CPPUNIT_ASSERT(name=="PartOf_Toto");
602 CPPUNIT_ASSERT(mesh->getCoords()==subMesh->getCoords());
603 CPPUNIT_ASSERT_EQUAL(3,subMesh->getNumberOfCells());
604 const int subConn2[14]={4,0,3,4,1,3,4,5,2,4,6,7,4,3};
605 const int subConnIndex2[4]={0,5,9,14};
606 CPPUNIT_ASSERT_EQUAL(14,subMesh->getNodalConnectivity()->getNbOfElems());
607 CPPUNIT_ASSERT_EQUAL(4,subMesh->getNodalConnectivityIndex()->getNbOfElems());
608 CPPUNIT_ASSERT(std::equal(subConn2,subConn2+14,subMesh->getNodalConnectivity()->getPointer()));
609 CPPUNIT_ASSERT(std::equal(subConnIndex2,subConnIndex2+4,subMesh->getNodalConnectivityIndex()->getPointer()));
610 const int tab3[3]={0,1,2};
611 MEDCouplingPointSet *subMeshSimple2=subMeshSimple->buildPartOfMySelf(tab3,tab3+3,true);
613 name=subMeshSimple2->getName();
614 CPPUNIT_ASSERT(name=="PartOf_Toto");
615 subMeshSimple2->decrRef();
620 void MEDCouplingBasicsTest1::testBuildPartOfMySelfNode()
622 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
623 const int tab1[4]={5,7,8,4};
624 MEDCouplingPointSet *subMeshSimple=mesh->buildPartOfMySelfNode(tab1,tab1+4,true);
625 MEDCouplingUMesh *subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
626 CPPUNIT_ASSERT(subMesh);
627 CPPUNIT_ASSERT_EQUAL(1,(int)subMesh->getAllTypes().size());
628 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllTypes().begin());
629 CPPUNIT_ASSERT_EQUAL(1,subMesh->getNumberOfCells());
630 CPPUNIT_ASSERT_EQUAL(5,subMesh->getNodalConnectivity()->getNbOfElems());
631 CPPUNIT_ASSERT_EQUAL(2,subMesh->getNodalConnectivityIndex()->getNbOfElems());
632 const int subConn[5]={4,7,8,5,4};
633 const int subConnIndex[3]={0,5};
634 CPPUNIT_ASSERT(std::equal(subConn,subConn+5,subMesh->getNodalConnectivity()->getPointer()));
635 CPPUNIT_ASSERT(std::equal(subConnIndex,subConnIndex+2,subMesh->getNodalConnectivityIndex()->getPointer()));
636 CPPUNIT_ASSERT(subMesh->getCoords()==mesh->getCoords());
637 subMeshSimple->decrRef();
639 subMeshSimple=mesh->buildPartOfMySelfNode(tab1,tab1+2,false);
640 subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
641 CPPUNIT_ASSERT(subMesh);
642 CPPUNIT_ASSERT_EQUAL(2,(int)subMesh->getAllTypes().size());
643 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*subMesh->getAllTypes().begin());
644 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++subMesh->getAllTypes().begin()));
645 CPPUNIT_ASSERT_EQUAL(3,subMesh->getNumberOfCells());
646 CPPUNIT_ASSERT_EQUAL(14,subMesh->getNodalConnectivity()->getNbOfElems());
647 CPPUNIT_ASSERT_EQUAL(4,subMesh->getNodalConnectivityIndex()->getNbOfElems());
648 const int subConn2[14]={3,4,5,2,4,6,7,4,3,4,7,8,5,4};
649 const int subConnIndex2[4]={0,4,9,14};
650 CPPUNIT_ASSERT(std::equal(subConn2,subConn2+14,subMesh->getNodalConnectivity()->getPointer()));
651 CPPUNIT_ASSERT(std::equal(subConnIndex2,subConnIndex2+4,subMesh->getNodalConnectivityIndex()->getPointer()));
652 CPPUNIT_ASSERT(subMesh->getCoords()==mesh->getCoords());
653 subMeshSimple->decrRef();
654 //testing the case where length of tab2 is greater than max number of node per cell.
655 const int tab2[7]={0,3,2,1,4,5,6};
656 subMeshSimple=mesh->buildPartOfMySelfNode(tab2,tab2+7,true);
657 subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
658 CPPUNIT_ASSERT(subMesh);
659 CPPUNIT_ASSERT_EQUAL(2,(int)subMesh->getAllTypes().size());
660 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*subMesh->getAllTypes().begin());
661 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++subMesh->getAllTypes().begin()));
662 CPPUNIT_ASSERT_EQUAL(3,subMesh->getNumberOfCells());
663 subMeshSimple->decrRef();
668 void MEDCouplingBasicsTest1::testZipCoords()
670 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
671 CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllTypes().size());
672 CPPUNIT_ASSERT_EQUAL(2,mesh->getSpaceDimension());
673 CPPUNIT_ASSERT_EQUAL(9,mesh->getNumberOfNodes());
674 CPPUNIT_ASSERT_EQUAL(5,mesh->getNumberOfCells());
675 std::vector<int> oldConn(mesh->getNodalConnectivity()->getNbOfElems());
676 std::vector<int> oldConnIndex(mesh->getNumberOfCells()+1);
677 std::copy(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+oldConn.size(),oldConn.begin());
678 std::copy(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+mesh->getNumberOfCells()+1,oldConnIndex.begin());
679 DataArrayDouble *oldCoords=mesh->getCoords();
680 oldCoords->incrRef();
682 CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllTypes().size());
683 CPPUNIT_ASSERT_EQUAL(2,mesh->getSpaceDimension());
684 CPPUNIT_ASSERT_EQUAL(9,mesh->getNumberOfNodes());
685 CPPUNIT_ASSERT_EQUAL(5,mesh->getNumberOfCells());
686 CPPUNIT_ASSERT(mesh->getCoords()!=oldCoords);
687 CPPUNIT_ASSERT(std::equal(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+2*9,oldCoords->getPointer()));
688 CPPUNIT_ASSERT(std::equal(oldConn.begin(),oldConn.end(),mesh->getNodalConnectivity()->getPointer()));
689 CPPUNIT_ASSERT(std::equal(oldConnIndex.begin(),oldConnIndex.end(),mesh->getNodalConnectivityIndex()->getPointer()));
690 oldCoords->decrRef();
692 const int tab1[2]={0,4};
693 MEDCouplingPointSet *subMeshPtSet=mesh->buildPartOfMySelf(tab1,tab1+2,true);
694 MEDCouplingUMesh *subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshPtSet);
695 CPPUNIT_ASSERT(subMesh);
696 DataArrayInt *traducer=subMesh->zipCoordsTraducer();
697 const int expectedTraducer[9]={0,1,-1,2,3,4,-1,5,6};
698 CPPUNIT_ASSERT(std::equal(expectedTraducer,expectedTraducer+9,traducer->getPointer()));
700 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllTypes().begin());
701 CPPUNIT_ASSERT_EQUAL(2,subMesh->getNumberOfCells());
702 const int subConn[10]={4,0,2,3,1,4,5,6,4,3};
703 const int subConnIndex[3]={0,5,10};
704 CPPUNIT_ASSERT_EQUAL(7,subMesh->getNumberOfNodes());
705 CPPUNIT_ASSERT_EQUAL(10,subMesh->getNodalConnectivity()->getNbOfElems());
706 CPPUNIT_ASSERT_EQUAL(3,subMesh->getNodalConnectivityIndex()->getNbOfElems());
707 CPPUNIT_ASSERT(std::equal(subConn,subConn+10,subMesh->getNodalConnectivity()->getPointer()));
708 CPPUNIT_ASSERT(std::equal(subConnIndex,subConnIndex+3,subMesh->getNodalConnectivityIndex()->getPointer()));
711 subMeshPtSet=mesh->buildPartOfMySelf(tab1,tab1+2,false);
712 subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshPtSet);
713 CPPUNIT_ASSERT(subMesh);
714 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllTypes().begin());
715 CPPUNIT_ASSERT_EQUAL(2,subMesh->getNumberOfCells());
716 CPPUNIT_ASSERT_EQUAL(7,subMesh->getNumberOfNodes());
717 CPPUNIT_ASSERT_EQUAL(10,subMesh->getNodalConnectivity()->getNbOfElems());
718 CPPUNIT_ASSERT_EQUAL(3,subMesh->getNodalConnectivityIndex()->getNbOfElems());
719 CPPUNIT_ASSERT(std::equal(subConn,subConn+10,subMesh->getNodalConnectivity()->getPointer()));
720 CPPUNIT_ASSERT(std::equal(subConnIndex,subConnIndex+3,subMesh->getNodalConnectivityIndex()->getPointer()));
726 void MEDCouplingBasicsTest1::testZipConnectivity()
728 MEDCouplingUMesh *m1=build2DTargetMesh_1();
729 MEDCouplingUMesh *m2=build2DTargetMesh_1();
730 int cells1[3]={2,3,4};
731 MEDCouplingPointSet *m3_1=m2->buildPartOfMySelf(cells1,cells1+3,true);
732 MEDCouplingUMesh *m3=dynamic_cast<MEDCouplingUMesh *>(m3_1);
735 MEDCouplingUMesh *m4=build2DSourceMesh_1();
736 MEDCouplingUMesh *m5=MEDCouplingUMesh::MergeUMeshes(m1,m3);
739 MEDCouplingUMesh *m6=MEDCouplingUMesh::MergeUMeshes(m5,m4);
745 CPPUNIT_ASSERT_EQUAL(10,m6->getNumberOfCells());
746 CPPUNIT_ASSERT_EQUAL(22,m6->getNumberOfNodes());
747 DataArrayInt *arr=m6->mergeNodes(1e-13,areNodesMerged,newNbOfNodes);
749 CPPUNIT_ASSERT(areNodesMerged);
750 CPPUNIT_ASSERT_EQUAL(10,m6->getNumberOfCells());
751 CPPUNIT_ASSERT_EQUAL(9,m6->getNumberOfNodes());
752 CPPUNIT_ASSERT_EQUAL(9,newNbOfNodes);
754 arr=m6->zipConnectivityTraducer(0);
755 CPPUNIT_ASSERT_EQUAL(7,m6->getNumberOfCells());
757 MEDCouplingUMesh *m7=m6->clone(true);
758 arr=m6->zipConnectivityTraducer(0);
759 CPPUNIT_ASSERT(m7->isEqual(m6,1e-12));
760 CPPUNIT_ASSERT_EQUAL(7,m6->getNumberOfCells());
767 void MEDCouplingBasicsTest1::testEqualMesh()
769 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
770 MEDCouplingUMesh *mesh2=build2DTargetMesh_1();
772 CPPUNIT_ASSERT(mesh1->isEqual(mesh1,1e-12));
774 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
775 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
776 double *pt=mesh2->getCoords()->getPointer();
779 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
780 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
782 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
783 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
785 int *pt2=mesh1->getNodalConnectivity()->getPointer();
787 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
788 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
790 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
791 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
793 pt2=mesh1->getNodalConnectivityIndex()->getPointer();
795 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
796 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
798 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
799 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
801 std::string tmp3=mesh1->getName();
802 mesh1->setName("lllll");
803 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
804 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
805 mesh1->setName(tmp3.c_str());
806 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
807 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
809 tmp3=mesh2->getCoords()->getInfoOnComponent(1);
810 mesh2->getCoords()->setInfoOnComponent(1,"kkkkkk");
811 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
812 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
813 mesh2->getCoords()->setInfoOnComponent(1,tmp3.c_str());
814 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
815 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
821 void MEDCouplingBasicsTest1::testEqualFieldDouble()
823 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
824 MEDCouplingUMesh *mesh2=build2DTargetMesh_1();
826 MEDCouplingFieldDouble *fieldOnCells1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
827 fieldOnCells1->setMesh(mesh1);
828 MEDCouplingFieldDouble *fieldOnCells2=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
829 fieldOnCells2->setMesh(mesh2);
831 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
832 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
833 fieldOnCells2->decrRef();
835 MEDCouplingFieldDouble *fieldOnNodes1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
836 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnNodes1,1e-12,1e-15));
837 CPPUNIT_ASSERT(!fieldOnNodes1->isEqual(fieldOnCells1,1e-12,1e-15));
838 fieldOnNodes1->decrRef();
840 fieldOnCells2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
841 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
842 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
843 fieldOnCells1->decrRef();
844 fieldOnCells1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
845 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
846 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
847 fieldOnCells1->setTime(4.,6,7);
848 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
849 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
850 fieldOnCells2->setTime(4.,6,7);
851 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
852 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
853 fieldOnCells1->setName("Power");
854 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
855 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
856 fieldOnCells2->setName("Power");
857 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
858 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
860 fieldOnCells1->setMesh(mesh1);
861 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
862 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
863 fieldOnCells2->setMesh(mesh1);
864 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
865 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
866 DataArrayDouble *arr=DataArrayDouble::New();
867 arr->setName("popo");
868 arr->alloc(mesh1->getNumberOfCells(),3);
869 double *pt=arr->getPointer();
870 std::fill(pt,pt+mesh1->getNumberOfCells()*3,6.);
871 fieldOnCells1->setArray(arr);
872 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
873 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
874 fieldOnCells2->setArray(arr);
876 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
877 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
879 DataArrayDouble *arr2=arr->deepCpy();
880 fieldOnCells2->setArray(arr2);
882 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
883 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
885 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
886 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
888 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
889 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
890 arr2->setName("popo2");
891 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
892 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
894 arr2->setName("popo");
895 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
896 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
898 arr2->setInfoOnComponent(2,"jjj");
899 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
900 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
901 arr->setInfoOnComponent(2,"jjj");
902 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
903 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
905 fieldOnCells1->decrRef();
906 fieldOnCells2->decrRef();
912 void MEDCouplingBasicsTest1::testNatureChecking()
914 MEDCouplingFieldDouble *field=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
915 field->setNature(Integral);
916 field->setNature(ConservativeVolumic);
917 field->setNature(IntegralGlobConstraint);
919 field=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
920 field->setNature(ConservativeVolumic);
921 CPPUNIT_ASSERT_THROW(field->setNature(Integral),INTERP_KERNEL::Exception);
922 CPPUNIT_ASSERT_THROW(field->setNature(IntegralGlobConstraint),INTERP_KERNEL::Exception);
926 void MEDCouplingBasicsTest1::testBuildSubMeshData()
928 MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
929 //check buildSubMesh on field on cells
930 MEDCouplingFieldDouble *fieldCells=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
931 fieldCells->setMesh(targetMesh);
932 const int elts[3]={1,2,4};
934 MEDCouplingMesh *ret1=fieldCells->buildSubMeshData(elts,elts+3,di);
935 CPPUNIT_ASSERT_EQUAL(3,ret1->getNumberOfCells());
936 CPPUNIT_ASSERT_EQUAL(9,ret1->getNumberOfNodes());
937 CPPUNIT_ASSERT_EQUAL(3,di->getNumberOfTuples());
938 CPPUNIT_ASSERT_EQUAL(1,di->getNumberOfComponents());
939 const int *toCheck=di->getConstPointer();
940 CPPUNIT_ASSERT(std::equal(elts,elts+3,toCheck));
941 MEDCouplingUMesh *ret1DC=dynamic_cast<MEDCouplingUMesh *>(ret1);
942 CPPUNIT_ASSERT(ret1DC);
945 fieldCells->decrRef();
946 //check buildSubMesh on field on nodes
947 MEDCouplingFieldDouble *fieldNodes=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
948 fieldNodes->setMesh(targetMesh);
949 MEDCouplingMesh *ret2=fieldNodes->buildSubMeshData(elts,elts+3,di);
950 MEDCouplingUMesh *ret2DC=dynamic_cast<MEDCouplingUMesh *>(ret2);
951 CPPUNIT_ASSERT(ret2DC);
952 CPPUNIT_ASSERT_EQUAL(3,ret2->getNumberOfCells());
953 CPPUNIT_ASSERT_EQUAL(6,ret2->getNumberOfNodes());
954 CPPUNIT_ASSERT_EQUAL(6,di->getNumberOfTuples());
955 CPPUNIT_ASSERT_EQUAL(1,di->getNumberOfComponents());
956 toCheck=di->getConstPointer();
957 const int expected[6]={1,2,4,5,7,8};
958 CPPUNIT_ASSERT(std::equal(expected,expected+6,toCheck));
961 fieldNodes->decrRef();
962 targetMesh->decrRef();
965 void MEDCouplingBasicsTest1::testExtrudedMesh1()
967 MEDCouplingUMesh *mesh2D=0;
968 MEDCouplingUMesh *mesh3D=build3DExtrudedUMesh_1(mesh2D);
969 MEDCouplingExtrudedMesh *ext=MEDCouplingExtrudedMesh::New(mesh3D,mesh2D,1);
970 CPPUNIT_ASSERT_EQUAL(18,ext->getNumberOfCells());
971 CPPUNIT_ASSERT_EQUAL(60,ext->getNumberOfNodes());
972 DataArrayInt *ids3D=ext->getMesh3DIds();
973 const int ids3DExpected[18]={5,4,3,2,1,0, 11,10,9,8,7,6, 17,16,15,14,13,12};
974 CPPUNIT_ASSERT_EQUAL(18,ids3D->getNumberOfTuples());
975 CPPUNIT_ASSERT_EQUAL(1,ids3D->getNumberOfComponents());
976 CPPUNIT_ASSERT(std::equal(ids3DExpected,ids3DExpected+18,ids3D->getConstPointer()));
977 MEDCouplingUMesh *mesh1D=ext->getMesh1D();
978 CPPUNIT_ASSERT_EQUAL(4,mesh1D->getNumberOfNodes());
979 CPPUNIT_ASSERT_EQUAL(3,mesh1D->getNumberOfCells());
980 const double mesh1DExpected[12]={0.66666666666666663, 1.4583333333333333, 0, 0.66666666666666663, 1.4583333333333333, 1, 0.66666666666666663, 1.4583333333333333, 2, 0.66666666666666663, 1.4583333333333333, 3};
981 DataArrayDouble *mesh1DCoords=mesh1D->getCoords();
982 CPPUNIT_ASSERT_EQUAL(4,mesh1DCoords->getNumberOfTuples());
983 CPPUNIT_ASSERT_EQUAL(3,mesh1DCoords->getNumberOfComponents());
984 CPPUNIT_ASSERT(std::equal(mesh1DExpected,mesh1DExpected+12,mesh1DCoords->getConstPointer()));
985 DataArrayInt *conn1D=mesh1D->getNodalConnectivity();
986 CPPUNIT_ASSERT_EQUAL(9,conn1D->getNumberOfTuples());
987 CPPUNIT_ASSERT_EQUAL(1,conn1D->getNumberOfComponents());
988 const int conn1DExpected[9]={1,0,1,1,1,2,1,2,3};
989 CPPUNIT_ASSERT(std::equal(conn1DExpected,conn1DExpected+9,conn1D->getConstPointer()));
995 void MEDCouplingBasicsTest1::testExtrudedMesh2()
997 MEDCouplingUMesh *mN,*mTT,*mTF;
998 build3DExtrudedUMesh_2(mN,mTT,mTF);
1002 DataArrayInt *da=mTT->mergeNodes(1e-12,b,newNbOfNodes);
1006 double pt[3]={300.,300.,0.};
1007 double v[3]={0.,0.,2.};
1008 mTT->findNodesOnPlane(pt,v,1e-12,n);
1009 CPPUNIT_ASSERT_EQUAL(43,(int)n.size());
1010 MEDCouplingUMesh *mTT3dSurf=(MEDCouplingUMesh *)mTT->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
1011 MEDCouplingExtrudedMesh *meTT=MEDCouplingExtrudedMesh::New(mTT,mTT3dSurf,0);
1012 CPPUNIT_ASSERT_EQUAL(200,meTT->getNumberOfCells());
1013 CPPUNIT_ASSERT_EQUAL(10,meTT->getMesh2D()->getNumberOfCells());
1014 CPPUNIT_ASSERT_EQUAL(20,meTT->getMesh1D()->getNumberOfCells());
1015 mTT3dSurf->decrRef();
1018 da=mN->mergeNodes(1e-12,b,newNbOfNodes);
1022 mN->findNodesOnPlane(pt,v,1e-12,n);
1023 CPPUNIT_ASSERT_EQUAL(30,(int)n.size());
1024 MEDCouplingUMesh *mN3dSurf=(MEDCouplingUMesh *)mN->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
1025 MEDCouplingExtrudedMesh *meN=MEDCouplingExtrudedMesh::New(mN,mN3dSurf,0);
1026 CPPUNIT_ASSERT_EQUAL(40,meN->getNumberOfCells());
1027 CPPUNIT_ASSERT_EQUAL(20,meN->getMesh2D()->getNumberOfCells());
1028 CPPUNIT_ASSERT_EQUAL(2,meN->getMesh1D()->getNumberOfCells());
1029 mN3dSurf->decrRef();
1032 da=mTF->mergeNodes(1e-12,b,newNbOfNodes);
1036 mTF->findNodesOnPlane(pt,v,1e-12,n);
1037 CPPUNIT_ASSERT_EQUAL(27,(int)n.size());
1038 MEDCouplingUMesh *mTF3dSurf=(MEDCouplingUMesh *)mTF->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
1039 MEDCouplingExtrudedMesh *meTF=MEDCouplingExtrudedMesh::New(mTF,mTF3dSurf,0);
1040 CPPUNIT_ASSERT_EQUAL(340,meTF->getNumberOfCells());
1041 CPPUNIT_ASSERT_EQUAL(17,meTF->getMesh2D()->getNumberOfCells());
1042 CPPUNIT_ASSERT_EQUAL(20,meTF->getMesh1D()->getNumberOfCells());
1043 mTF3dSurf->decrRef();
1055 * This test check MEDCouplingUMesh::buildExtrudedMesh method.
1057 void MEDCouplingBasicsTest1::testExtrudedMesh3()
1059 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1060 m1->changeSpaceDimension(3);
1061 MEDCouplingUMesh *m2=buildCU1DMesh_U();
1062 m2->changeSpaceDimension(3);
1063 double center[3]={0.,0.,0.};
1064 double vector[3]={0,1,0};
1065 m2->rotate(center,vector,-M_PI/2.);
1066 MEDCouplingUMesh *m3=m1->buildExtrudedMesh(m2,0);
1068 MEDCouplingExtrudedMesh *m4=MEDCouplingExtrudedMesh::New(m3,m1,0);
1069 CPPUNIT_ASSERT_EQUAL(15,m4->getNumberOfCells());
1070 CPPUNIT_ASSERT_EQUAL(5,m4->getMesh2D()->getNumberOfCells());
1071 CPPUNIT_ASSERT_EQUAL(3,m4->getMesh1D()->getNumberOfCells());
1072 const int *m3DIds=m4->getMesh3DIds()->getConstPointer();
1073 for(int i=0;i<15;i++)
1074 CPPUNIT_ASSERT_EQUAL(i,m3DIds[i]);
1076 //some random in cells to check that extrusion alg find it correctly
1077 const int expected1[15]={1,3,2,0,6,5,7,10,11,8,12,9,14,13,4};
1078 m3->renumberCells(expected1,false);
1079 m4=MEDCouplingExtrudedMesh::New(m3,m1,0);
1080 CPPUNIT_ASSERT_EQUAL(15,m4->getNumberOfCells());
1081 CPPUNIT_ASSERT_EQUAL(5,m4->getMesh2D()->getNumberOfCells());
1082 CPPUNIT_ASSERT_EQUAL(3,m4->getMesh1D()->getNumberOfCells());
1083 m3DIds=m4->getMesh3DIds()->getConstPointer();
1084 for(int i=0;i<15;i++)
1085 CPPUNIT_ASSERT_EQUAL(expected1[i],m3DIds[i]);
1088 //play with polygons and polyedrons
1089 std::vector<int> cells(2); cells[0]=2; cells[1]=3;
1090 m1->convertToPolyTypes(&cells[0],&cells[0]+cells.size());
1091 m3=m1->buildExtrudedMesh(m2,0);
1092 CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_HEXA8,(int)m3->getTypeOfCell(0));
1093 CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_PENTA6,(int)m3->getTypeOfCell(1));
1094 CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_POLYHED,(int)m3->getTypeOfCell(2));
1095 CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_POLYHED,(int)m3->getTypeOfCell(3));
1096 CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_HEXA8,(int)m3->getTypeOfCell(4));
1097 m3->renumberCells(expected1,false);
1098 m4=MEDCouplingExtrudedMesh::New(m3,m1,0);
1099 CPPUNIT_ASSERT_EQUAL(15,m4->getNumberOfCells());
1100 CPPUNIT_ASSERT_EQUAL(5,m4->getMesh2D()->getNumberOfCells());
1101 CPPUNIT_ASSERT_EQUAL(3,m4->getMesh1D()->getNumberOfCells());
1102 m3DIds=m4->getMesh3DIds()->getConstPointer();
1103 for(int i=0;i<15;i++)
1104 CPPUNIT_ASSERT_EQUAL(expected1[i],m3DIds[i]);
1113 * This test check MEDCouplingUMesh::buildExtrudedMesh method, but also, MEDCouplingExtrudedMesh following methods :
1114 * getCellContainingPoint getMeasureField getNodeIdsOfCell getCoordinateOfNode getTypeOfCell build3DUnstructuredMesh.
1116 void MEDCouplingBasicsTest1::testExtrudedMesh4()
1118 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1119 std::vector<int> cells(2); cells[0]=2; cells[1]=4;
1120 m1->convertToPolyTypes(&cells[0],&cells[0]+cells.size());
1121 m1->changeSpaceDimension(3);
1122 MEDCouplingUMesh *m2=buildCU1DMesh_U();
1123 m2->changeSpaceDimension(3);
1124 double center[3]={0.,0.,0.};
1125 double vector[3]={0.,1.,0.};
1126 m2->rotate(center,vector,-M_PI/2.);
1127 MEDCouplingUMesh *m3=m1->buildExtrudedMesh(m2,0);
1128 const int expected1[15]= {1,3,2,0,6,5,7,10,11,8,12,9,14,13,4};
1129 const int rexpected1[15]={3, 0, 2, 1, 14, 5, 4, 6, 9, 11, 7, 8, 10, 13, 12};
1130 m3->renumberCells(expected1,false);
1131 MEDCouplingExtrudedMesh *m4=MEDCouplingExtrudedMesh::New(m3,m1,0);
1132 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,m4->getTypeOfCell(0));
1133 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,m4->getTypeOfCell(1));
1134 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYHED,m4->getTypeOfCell(2));
1135 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_PENTA6,m4->getTypeOfCell(7));
1136 MEDCouplingFieldDouble *f=m4->getMeasureField(true);
1137 DataArrayDouble *arr=f->getArray();
1138 CPPUNIT_ASSERT_EQUAL(15,arr->getNumberOfTuples());
1139 CPPUNIT_ASSERT_EQUAL(1,arr->getNumberOfComponents());
1140 const double *arrPtr=arr->getConstPointer();
1141 const double expected2[15]={0.075,0.0375,0.0375,0.075,0.075, 0.1125,0.05625,0.05625,0.1125,0.1125, 0.0625,0.03125,0.03125,0.0625,0.0625};
1142 for(int i=0;i<15;i++)
1143 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[rexpected1[i]],arrPtr[i],1e-16);
1145 MEDCouplingUMesh *m5=m4->build3DUnstructuredMesh();
1146 CPPUNIT_ASSERT(m5->isEqual(m3,1e-12));
1147 f=m5->getMeasureField(true);
1149 arrPtr=arr->getConstPointer();
1150 for(int i=0;i<15;i++)
1151 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[rexpected1[i]],arrPtr[i],1e-16);
1161 void MEDCouplingBasicsTest1::testFindCommonNodes()
1163 DataArrayInt *comm,*commI;
1164 MEDCouplingUMesh *targetMesh=build3DTargetMesh_1();
1165 targetMesh->findCommonNodes(1e-10,-1,comm,commI);
1166 CPPUNIT_ASSERT_EQUAL(1,commI->getNumberOfTuples());
1167 CPPUNIT_ASSERT_EQUAL(0,comm->getNumberOfTuples());
1169 DataArrayInt *o2n=targetMesh->buildNewNumberingFromCommonNodesFormat(comm,commI,newNbOfNodes);
1170 CPPUNIT_ASSERT_EQUAL(27,newNbOfNodes);
1171 CPPUNIT_ASSERT_EQUAL(27,o2n->getNumberOfTuples());
1172 const int o2nExp1[27]=
1174 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
1177 CPPUNIT_ASSERT(std::equal(o2nExp1,o2nExp1+27,o2n->getConstPointer()));
1181 targetMesh->decrRef();
1183 targetMesh=build3DTargetMeshMergeNode_1();
1184 CPPUNIT_ASSERT_EQUAL(31,targetMesh->getNumberOfNodes());
1185 targetMesh->findCommonNodes(1e-10,-1,comm,commI);
1186 CPPUNIT_ASSERT_EQUAL(3,commI->getNumberOfTuples());
1187 CPPUNIT_ASSERT_EQUAL(6,comm->getNumberOfTuples());
1188 const int commExpected[6]={1,27,28,29,23,30};
1189 const int commIExpected[3]={0,4,6};
1190 CPPUNIT_ASSERT(std::equal(commExpected,commExpected+6,comm->getConstPointer()));
1191 CPPUNIT_ASSERT(std::equal(commIExpected,commIExpected+3,commI->getConstPointer()));
1192 o2n=targetMesh->buildNewNumberingFromCommonNodesFormat(comm,commI,newNbOfNodes);
1193 CPPUNIT_ASSERT_EQUAL(31,o2n->getNumberOfTuples());
1194 CPPUNIT_ASSERT_EQUAL(27,newNbOfNodes);
1195 const int o2nExp2[31]=
1197 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
1198 21,22,23,24,25,26,1,1,1,23
1200 CPPUNIT_ASSERT(std::equal(o2nExp2,o2nExp2+31,o2n->getConstPointer()));
1204 targetMesh->decrRef();
1206 targetMesh=build3DTargetMesh_1();
1207 bool areNodesMerged;
1208 unsigned int time=targetMesh->getTimeOfThis();
1209 o2n=targetMesh->mergeNodes(1e-10,areNodesMerged,newNbOfNodes);
1210 targetMesh->updateTime();
1211 CPPUNIT_ASSERT(time==targetMesh->getTimeOfThis());
1212 CPPUNIT_ASSERT(!areNodesMerged);
1213 targetMesh->decrRef();
1216 targetMesh=build3DTargetMeshMergeNode_1();
1217 time=targetMesh->getTimeOfThis();
1218 o2n=targetMesh->mergeNodes(1e-10,areNodesMerged,newNbOfNodes);
1219 targetMesh->updateTime();
1220 CPPUNIT_ASSERT(time!=targetMesh->getTimeOfThis());
1221 CPPUNIT_ASSERT(areNodesMerged);
1222 int connExp[72]={18,0,1,4,3,9,10,13,12, 18,1,2,5,4,10,11,14,13, 18,3,4,7,6,12,13,16,15,
1223 18,4,5,8,7,13,14,17,16,
1224 18,9,10,13,12,18,19,22,21, 18,10,11,14,13,19,20,23,22, 18,12,13,16,15,21,22,25,24,
1225 18,13,14,17,16,22,23,26,25};
1226 CPPUNIT_ASSERT_EQUAL(72,targetMesh->getNodalConnectivity()->getNumberOfTuples());
1227 CPPUNIT_ASSERT(std::equal(connExp,connExp+72,targetMesh->getNodalConnectivity()->getConstPointer()));
1228 CPPUNIT_ASSERT_EQUAL(27,targetMesh->getCoords()->getNumberOfTuples());
1229 double coordsExp[81]={ 0., 0., 0., 50., 0., 0. , 200., 0., 0. , 0., 50., 0., 50., 50., 0. ,
1230 200., 50., 0., 0., 200., 0., 50., 200., 0. , 200., 200., 0. ,
1231 0., 0., 50., 50., 0., 50. , 200., 0., 50. , 0., 50., 50., 50.,
1232 50., 50. , 200., 50., 50., 0., 200., 50., 50., 200., 50. ,
1233 200., 200., 50. , 0., 0., 200., 50., 0., 200. , 200., 0., 200.
1234 , 0., 50., 200., 50., 50., 200. , 200., 50., 200.,
1235 0., 200., 200., 50., 200., 200. , 200., 200., 200. };
1236 CPPUNIT_ASSERT(std::equal(coordsExp,coordsExp+81,targetMesh->getCoords()->getConstPointer()));
1237 targetMesh->decrRef();
1240 targetMesh=build2DTargetMeshMergeNode_1();
1241 CPPUNIT_ASSERT_EQUAL(18,targetMesh->getNumberOfNodes());
1242 time=targetMesh->getTimeOfThis();
1243 o2n=targetMesh->mergeNodes(1e-10,areNodesMerged,newNbOfNodes);
1244 CPPUNIT_ASSERT(time!=targetMesh->getTimeOfThis());
1245 CPPUNIT_ASSERT(areNodesMerged);
1246 CPPUNIT_ASSERT_EQUAL(9,targetMesh->getNumberOfNodes());
1247 int connExp2[23]={4,0,4,3,1, 3,1,3,2, 3,3,5,2, 4,4,6,7,3, 4,7,8,5,3};
1248 CPPUNIT_ASSERT_EQUAL(23,targetMesh->getNodalConnectivity()->getNumberOfTuples());
1249 CPPUNIT_ASSERT(std::equal(connExp2,connExp2+23,targetMesh->getNodalConnectivity()->getConstPointer()));
1250 double coordsExp2[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, 0.2,0.2, -0.3,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7};
1251 CPPUNIT_ASSERT_EQUAL(9,targetMesh->getCoords()->getNumberOfTuples());
1252 CPPUNIT_ASSERT(std::equal(coordsExp2,coordsExp2+18,targetMesh->getCoords()->getConstPointer()));
1253 targetMesh->decrRef();
1257 void MEDCouplingBasicsTest1::testCheckButterflyCells()
1259 std::vector<int> cells;
1260 MEDCouplingUMesh *sourceMesh=build2DTargetMesh_1();
1261 sourceMesh->checkButterflyCells(cells);
1262 CPPUNIT_ASSERT(cells.empty());
1263 int *pt=sourceMesh->getNodalConnectivity()->getPointer();
1264 std::swap(pt[15],pt[16]);
1265 sourceMesh->checkButterflyCells(cells);
1266 CPPUNIT_ASSERT_EQUAL(1,(int)cells.size());
1267 CPPUNIT_ASSERT_EQUAL(3,cells[0]);
1269 std::swap(pt[15],pt[16]);
1270 sourceMesh->checkButterflyCells(cells);
1271 CPPUNIT_ASSERT(cells.empty());
1272 sourceMesh->decrRef();
1274 sourceMesh=build3DSurfTargetMesh_1();
1275 sourceMesh->checkButterflyCells(cells);
1276 CPPUNIT_ASSERT(cells.empty());
1277 pt=sourceMesh->getNodalConnectivity()->getPointer();
1278 std::swap(pt[15],pt[16]);
1279 sourceMesh->checkButterflyCells(cells);
1280 CPPUNIT_ASSERT_EQUAL(1,(int)cells.size());
1281 CPPUNIT_ASSERT_EQUAL(3,cells[0]);
1283 std::swap(pt[15],pt[16]);
1284 sourceMesh->checkButterflyCells(cells);
1285 CPPUNIT_ASSERT(cells.empty());
1286 sourceMesh->decrRef();
1289 void MEDCouplingBasicsTest1::testMergeMesh1()
1291 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1292 MEDCouplingUMesh *m2=build2DSourceMesh_1();
1293 const double vec[2]={1.,0.};
1295 MEDCouplingMesh *m3=m1->mergeMyselfWith(m2);
1296 MEDCouplingUMesh *m3C=dynamic_cast<MEDCouplingUMesh *>(m3);
1297 CPPUNIT_ASSERT(m3C);
1298 m3->checkCoherency();
1299 MEDCouplingUMesh *m4=build2DTargetMeshMerged_1();
1300 CPPUNIT_ASSERT(m3->isEqual(m4,1.e-12));
1304 DataArrayInt *da=m3C->mergeNodes(1.e-12,isMerged,newNbOfNodes);
1305 CPPUNIT_ASSERT_EQUAL(11,m3C->getNumberOfNodes());
1306 CPPUNIT_ASSERT_EQUAL(11,newNbOfNodes);
1307 CPPUNIT_ASSERT(isMerged);
1314 void MEDCouplingBasicsTest1::testMergeMeshOnSameCoords1()
1316 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1317 MEDCouplingUMesh *m2=build2DTargetMesh_1();
1318 std::vector<int> cells(5);
1319 for(int i=0;i<5;i++)
1321 m2->convertToPolyTypes(&cells[0],&cells[0]+cells.size());
1322 m1->tryToShareSameCoords(*m2,1e-12);
1323 MEDCouplingUMesh *m3=build2DTargetMesh_1();
1324 m3->tryToShareSameCoords(*m2,1e-12);
1325 std::vector<const MEDCouplingUMesh *> meshes;
1326 meshes.push_back(m1); meshes.push_back(m2); meshes.push_back(m3);
1327 MEDCouplingUMesh *m4=MEDCouplingUMesh::MergeUMeshesOnSameCoords(meshes);
1328 m4->checkCoherency();
1329 CPPUNIT_ASSERT(m4->getCoords()==m1->getCoords());
1330 CPPUNIT_ASSERT_EQUAL(15,m4->getNumberOfCells());
1331 const int cells1[5]={0,1,2,3,4};
1332 MEDCouplingPointSet *m1_1=m4->buildPartOfMySelf(cells1,cells1+5,true);
1333 m1_1->setName(m1->getName());
1334 CPPUNIT_ASSERT(m1->isEqual(m1_1,1e-12));
1335 const int cells2[5]={5,6,7,8,9};
1336 MEDCouplingPointSet *m2_1=m4->buildPartOfMySelf(cells2,cells2+5,true);
1337 m2_1->setName(m2->getName());
1338 CPPUNIT_ASSERT(m2->isEqual(m2_1,1e-12));
1339 const int cells3[5]={10,11,12,13,14};
1340 MEDCouplingPointSet *m3_1=m4->buildPartOfMySelf(cells3,cells3+5,true);
1341 m3_1->setName(m3->getName());
1342 CPPUNIT_ASSERT(m3->isEqual(m3_1,1e-12));
1343 m1_1->decrRef(); m2_1->decrRef(); m3_1->decrRef();
1351 void MEDCouplingBasicsTest1::testMergeField1()
1353 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1354 MEDCouplingUMesh *m2=build2DSourceMesh_1();
1355 const double vec[2]={1.,0.};
1357 MEDCouplingFieldDouble *f1=m1->getMeasureField(true);
1358 MEDCouplingFieldDouble *f2=m2->getMeasureField(true);
1359 MEDCouplingFieldDouble *f3=MEDCouplingFieldDouble::MergeFields(f1,f2);
1360 f3->checkCoherency();
1361 MEDCouplingUMesh *m4=build2DTargetMeshMerged_1();
1362 CPPUNIT_ASSERT(f3->getMesh()->isEqual(m4,1.e-12));
1363 std::string name=f3->getName();
1364 CPPUNIT_ASSERT(name=="MeasureOfMesh_");
1365 CPPUNIT_ASSERT(f3->getTypeOfField()==ON_CELLS);
1366 CPPUNIT_ASSERT(f3->getTimeDiscretization()==NO_TIME);
1367 CPPUNIT_ASSERT_EQUAL(1,f3->getNumberOfComponents());
1368 CPPUNIT_ASSERT_EQUAL(7,f3->getNumberOfTuples());
1369 double values[7]={0.25,0.125,0.125,0.25,0.25,0.5,0.5};
1370 const double *tmp=f3->getArray()->getConstPointer();
1371 std::transform(tmp,tmp+7,values,values,std::minus<double>());
1372 std::transform(values,values+7,values,std::ptr_fun<double,double>(fabs));
1373 double max=*std::max_element(values,values+7);
1374 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1383 bool func1(const double *pt, double *res);
1384 bool func2(const double *pt, double *res);
1385 bool func3(const double *pt, double *res);
1386 bool func4(const double *pt, double *res);
1388 bool func1(const double *pt, double *res)
1394 bool func2(const double *pt, double *res)
1397 res[1]=2.*(pt[0]+pt[1]);
1401 bool func3(const double *pt, double *res)
1403 if(fabs(pt[0]-0.2)<1e-12)
1405 res[0]=1./(pt[0]-0.2);
1409 void MEDCouplingBasicsTest1::testFillFromAnalytic()
1411 MEDCouplingUMesh *m=build2DTargetMesh_1();
1412 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_CELLS,1,func1);
1413 f1->checkCoherency();
1414 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_CELLS);
1415 CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
1416 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1417 CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
1418 double values1[5]={-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9};
1419 const double *tmp=f1->getArray()->getConstPointer();
1420 std::transform(tmp,tmp+5,values1,values1,std::minus<double>());
1421 std::transform(values1,values1+5,values1,std::ptr_fun<double,double>(fabs));
1422 double max=*std::max_element(values1,values1+5);
1423 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1426 f1=m->fillFromAnalytic(ON_NODES,1,func1);
1427 f1->checkCoherency();
1428 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1429 CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
1430 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1431 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1432 double values2[9]={-0.6,-0.1,0.4,-0.1,0.4,0.9,0.4,0.9,1.4};
1433 tmp=f1->getArray()->getConstPointer();
1434 std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
1435 std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
1436 max=*std::max_element(values2,values2+9);
1437 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1440 f1=m->fillFromAnalytic(ON_NODES,2,func2);
1441 f1->checkCoherency();
1442 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1443 CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
1444 CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
1445 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1446 double values3[18]={-0.6,-1.2,-0.1,-0.2,0.4,0.8,-0.1,-0.2,0.4,0.8,0.9,1.8,0.4,0.8,0.9,1.8,1.4,2.8};
1447 tmp=f1->getArray()->getConstPointer();
1448 std::transform(tmp,tmp+18,values3,values3,std::minus<double>());
1449 std::transform(values3,values3+18,values3,std::ptr_fun<double,double>(fabs));
1450 max=*std::max_element(values3,values3+18);
1451 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1453 f1->accumulate(values4);
1454 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.6,values4[0],1.e-12);
1455 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.2,values4[1],1.e-12);
1456 f1->integral(true,values4);
1457 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,values4[0],1.e-12);
1458 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,values4[1],1.e-12);
1461 CPPUNIT_ASSERT_THROW(f1=m->fillFromAnalytic(ON_NODES,1,func3),INTERP_KERNEL::Exception);
1466 void MEDCouplingBasicsTest1::testFillFromAnalytic2()
1468 MEDCouplingUMesh *m=build2DTargetMesh_1();
1469 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_CELLS,1,"y+x");
1470 f1->checkCoherency();
1471 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_CELLS);
1472 CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
1473 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1474 CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
1475 double values1[5]={-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9};
1476 const double *tmp=f1->getArray()->getConstPointer();
1477 std::transform(tmp,tmp+5,values1,values1,std::minus<double>());
1478 std::transform(values1,values1+5,values1,std::ptr_fun<double,double>(fabs));
1479 double max=*std::max_element(values1,values1+5);
1480 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1483 f1=m->fillFromAnalytic(ON_NODES,1,"y+2*x");
1484 f1->checkCoherency();
1485 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1486 CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
1487 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1488 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1489 double values2[9]={-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1};
1490 tmp=f1->getArray()->getConstPointer();
1491 std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
1492 std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
1493 max=*std::max_element(values2,values2+9);
1494 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1496 f1=m->fillFromAnalytic(ON_NODES,1,"2.*x+y");
1497 f1->checkCoherency();
1498 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1499 CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
1500 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1501 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1502 tmp=f1->getArray()->getConstPointer();
1503 double values2Bis[9]={-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1};
1504 std::transform(tmp,tmp+9,values2Bis,values2Bis,std::minus<double>());
1505 std::transform(values2,values2+9,values2Bis,std::ptr_fun<double,double>(fabs));
1506 max=*std::max_element(values2Bis,values2Bis+9);
1507 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1510 f1=m->fillFromAnalytic(ON_NODES,2,"(x+y)*IVec+2*(x+y)*JVec");
1511 f1->checkCoherency();
1512 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1513 CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
1514 CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
1515 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1516 double values3[18]={-0.6,-1.2,-0.1,-0.2,0.4,0.8,-0.1,-0.2,0.4,0.8,0.9,1.8,0.4,0.8,0.9,1.8,1.4,2.8};
1517 tmp=f1->getArray()->getConstPointer();
1518 std::transform(tmp,tmp+18,values3,values3,std::minus<double>());
1519 std::transform(values3,values3+18,values3,std::ptr_fun<double,double>(fabs));
1520 max=*std::max_element(values3,values3+18);
1521 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1523 f1->accumulate(values4);
1524 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.6,values4[0],1.e-12);
1525 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.2,values4[1],1.e-12);
1526 f1->integral(true,values4);
1527 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,values4[0],1.e-12);
1528 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,values4[1],1.e-12);
1531 CPPUNIT_ASSERT_THROW(f1=m->fillFromAnalytic(ON_NODES,1,"1./(x-0.2)"),INTERP_KERNEL::Exception);
1536 void MEDCouplingBasicsTest1::testApplyFunc()
1538 MEDCouplingUMesh *m=build2DTargetMesh_1();
1539 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,2,func2);
1540 f1->checkCoherency();
1541 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1542 CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
1543 CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
1544 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1545 f1->applyFunc(1,func1);
1546 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1547 CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
1548 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1549 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1550 double values1[9]={-1.8,-0.3,1.2,-0.3,1.2,2.7,1.2,2.7,4.2};
1551 const double *tmp=f1->getArray()->getConstPointer();
1552 std::transform(tmp,tmp+9,values1,values1,std::minus<double>());
1553 std::transform(values1,values1+9,values1,std::ptr_fun<double,double>(fabs));
1554 double max=*std::max_element(values1,values1+9);
1555 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1560 void MEDCouplingBasicsTest1::testApplyFunc2()
1562 MEDCouplingUMesh *m=build2DTargetMesh_1();
1563 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,2,func2);
1564 f1->checkCoherency();
1565 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1566 CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
1567 CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
1568 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1570 MEDCouplingFieldDouble *f2=f1->clone(true);
1571 CPPUNIT_ASSERT_THROW(f2->applyFunc(1,"a+b+c+d"),INTERP_KERNEL::Exception);
1572 CPPUNIT_ASSERT_THROW(f2->applyFunc(1,"a/0"),INTERP_KERNEL::Exception);
1573 CPPUNIT_ASSERT_THROW(f2->applyFunc("a/0"),INTERP_KERNEL::Exception);
1574 f2->applyFunc("abs(u)^2.4+2*u");
1575 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1576 CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
1577 CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
1578 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1579 double values2[18]={-0.9065304805418678, -0.85105859001709905, -0.19601892829446504, -0.37898777756476987,
1580 0.91090317490482353, 2.1853504664669781, -0.19601892829446504, -0.37898777756476987,
1581 0.91090317490482353, 2.1853504664669781, 2.5765725275664879, 7.6987743736515295,
1582 0.91090317490482353, 2.1853504664669781, 2.5765725275664879, 7.6987743736515295,
1583 5.0423700574830965, 17.435300118916864};
1584 const double *tmp=f2->getArray()->getConstPointer();
1585 std::transform(tmp,tmp+18,values2,values2,std::minus<double>());
1586 std::transform(values2,values2+18,values2,std::ptr_fun<double,double>(fabs));
1587 double max=*std::max_element(values2,values2+18);
1588 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1591 f1->applyFunc(1,"x+y");
1592 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1593 CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
1594 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1595 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1596 double values1[9]={-1.8,-0.3,1.2,-0.3,1.2,2.7,1.2,2.7,4.2};
1597 tmp=f1->getArray()->getConstPointer();
1598 std::transform(tmp,tmp+9,values1,values1,std::minus<double>());
1599 std::transform(values1,values1+9,values1,std::ptr_fun<double,double>(fabs));
1600 max=*std::max_element(values1,values1+9);
1601 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1606 void MEDCouplingBasicsTest1::testOperationsOnFields()
1608 MEDCouplingUMesh *m=build2DTargetMesh_1();
1609 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,1,func1);
1610 MEDCouplingFieldDouble *f2=m->fillFromAnalytic(ON_NODES,1,func1);
1611 f1->checkCoherency();
1612 f2->checkCoherency();
1613 MEDCouplingFieldDouble *f3=(*f1)+(*f2);
1614 f3->checkCoherency();
1615 CPPUNIT_ASSERT(f3->getTypeOfField()==ON_NODES);
1616 CPPUNIT_ASSERT(f3->getTimeDiscretization()==NO_TIME);
1617 double values1[9]={-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8};
1618 const double *tmp=f3->getArray()->getConstPointer();
1619 std::transform(tmp,tmp+9,values1,values1,std::minus<double>());
1620 std::transform(values1,values1+9,values1,std::ptr_fun<double,double>(fabs));
1621 double max=*std::max_element(values1,values1+9);
1622 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1626 f3->checkCoherency();
1627 CPPUNIT_ASSERT(f3->getTypeOfField()==ON_NODES);
1628 CPPUNIT_ASSERT(f3->getTimeDiscretization()==NO_TIME);
1629 double values2[9]={0.36,0.01,0.16,0.01,0.16,0.81,0.16,0.81,1.96};
1630 tmp=f3->getArray()->getConstPointer();
1631 std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
1632 std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
1633 max=*std::max_element(values2,values2+9);
1634 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1638 MEDCouplingFieldDouble *f4=(*f1)-(*f3);
1639 f4->checkCoherency();
1640 CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1641 CPPUNIT_ASSERT(f4->getTimeDiscretization()==NO_TIME);
1642 double values3[9]={0.6,0.1,-0.4,0.1,-0.4,-0.9,-0.4,-0.9,-1.4};
1643 tmp=f4->getArray()->getConstPointer();
1644 std::transform(tmp,tmp+9,values3,values3,std::minus<double>());
1645 std::transform(values3,values3+9,values3,std::ptr_fun<double,double>(fabs));
1646 max=*std::max_element(values3,values3+9);
1647 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1653 f4->checkCoherency();
1654 CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1655 CPPUNIT_ASSERT(f4->getTimeDiscretization()==NO_TIME);
1656 tmp=f4->getArray()->getConstPointer();
1657 for(int i=0;i<9;i++)
1658 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.,tmp[i],1.e-12);
1662 f4=f2->buildNewTimeReprFromThis(ONE_TIME,false);
1663 f4->checkCoherency();
1664 CPPUNIT_ASSERT(f4->getArray()==f2->getArray());
1665 CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1666 CPPUNIT_ASSERT(f4->getTimeDiscretization()==ONE_TIME);
1667 CPPUNIT_ASSERT_THROW(f3=(*f1)+(*f4),INTERP_KERNEL::Exception);
1668 MEDCouplingFieldDouble *f5=f4->buildNewTimeReprFromThis(NO_TIME,false);
1669 CPPUNIT_ASSERT(f4->getArray()==f5->getArray());
1670 CPPUNIT_ASSERT(f5->getTypeOfField()==ON_NODES);
1671 CPPUNIT_ASSERT(f5->getTimeDiscretization()==NO_TIME);
1673 tmp=f3->getArray()->getConstPointer();
1674 double values4[9]={-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8};
1675 std::transform(tmp,tmp+9,values4,values4,std::minus<double>());
1676 std::transform(values4,values4+9,values4,std::ptr_fun<double,double>(fabs));
1677 max=*std::max_element(values4,values4+9);
1678 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1683 f4=f2->buildNewTimeReprFromThis(ONE_TIME,true);
1684 f4->checkCoherency();
1685 CPPUNIT_ASSERT(f4->getArray()!=f2->getArray());
1686 CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1687 CPPUNIT_ASSERT(f4->getTimeDiscretization()==ONE_TIME);
1688 CPPUNIT_ASSERT_THROW(f3=(*f1)+(*f4),INTERP_KERNEL::Exception);
1689 f5=f4->buildNewTimeReprFromThis(NO_TIME,true);
1690 CPPUNIT_ASSERT(f4->getArray()!=f5->getArray());
1691 CPPUNIT_ASSERT(f2->getArray()!=f5->getArray());
1692 CPPUNIT_ASSERT(f5->getTypeOfField()==ON_NODES);
1693 CPPUNIT_ASSERT(f5->getTimeDiscretization()==NO_TIME);
1695 tmp=f3->getArray()->getConstPointer();
1696 double values5[9]={-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8};
1697 std::transform(tmp,tmp+9,values5,values5,std::minus<double>());
1698 std::transform(values5,values5+9,values5,std::ptr_fun<double,double>(fabs));
1699 max=*std::max_element(values5,values5+9);
1700 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1710 void MEDCouplingBasicsTest1::testOperationsOnFields2()
1712 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1713 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,1,"x+y+z");
1714 MEDCouplingFieldDouble *f2=m->fillFromAnalytic(ON_NODES,1,"a*a+b+c*c");
1715 MEDCouplingFieldDouble *f3=(*f1)/(*f2);
1716 f3->checkCoherency();
1717 CPPUNIT_ASSERT(f3->getTypeOfField()==ON_NODES);
1718 CPPUNIT_ASSERT(f3->getTimeDiscretization()==NO_TIME);
1719 const double expected1[9]={-2.4999999999999991, 1.2162162162162162, 0.77868852459016391,
1720 0.7407407407407407, 1.129032258064516, 0.81632653061224492,
1721 0.86538461538461531, 1.0919540229885056, 0.84302325581395343};
1722 CPPUNIT_ASSERT_EQUAL(1,f3->getNumberOfComponents());
1723 CPPUNIT_ASSERT_EQUAL(9,f3->getNumberOfTuples());
1724 const double *val=f3->getArray()->getConstPointer();
1725 for(int i=0;i<9;i++)
1726 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1.e-12);
1731 f1=m->buildOrthogonalField();
1732 f2=m->fillFromAnalytic(ON_CELLS,1,"x");
1734 const double expected2[15]={-0.035355339059327376,0.,0.035355339059327376, 0.2592724864350674,0.,-0.2592724864350674, 0.37712361663282529,0.,-0.37712361663282529, -0.035355339059327376,0.,0.035355339059327376, 0.31819805153394637,0.,-0.31819805153394637};
1735 val=f3->getArray()->getConstPointer();
1736 for(int i=0;i<15;i++)
1737 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1.e-12);
1741 val=f3->getArray()->getConstPointer();
1742 for(int i=0;i<15;i++)
1743 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1.e-12);
1752 void MEDCouplingBasicsTest1::testOperationsOnFields3()
1754 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1755 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,1,"x+y+z");
1756 MEDCouplingFieldDouble *f2=m->fillFromAnalytic(ON_NODES,1,"a*a+b+c*c");
1758 f1->checkCoherency();
1759 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1760 CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
1761 const double expected1[9]={-2.4999999999999991, 1.2162162162162162, 0.77868852459016391,
1762 0.7407407407407407, 1.129032258064516, 0.81632653061224492,
1763 0.86538461538461531, 1.0919540229885056, 0.84302325581395343};
1764 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1765 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1766 const double *val=f1->getArray()->getConstPointer();
1767 for(int i=0;i<9;i++)
1768 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1.e-12);
1772 f1=m->buildOrthogonalField();
1773 f2=m->fillFromAnalytic(ON_CELLS,1,"x");
1775 const double expected2[15]={-0.035355339059327376,0.,0.035355339059327376, 0.2592724864350674,0.,-0.2592724864350674, 0.37712361663282529,0.,-0.37712361663282529, -0.035355339059327376,0.,0.035355339059327376, 0.31819805153394637,0.,-0.31819805153394637};
1776 val=f1->getArray()->getConstPointer();
1777 for(int i=0;i<15;i++)
1778 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1.e-12);
1781 f1=m->buildOrthogonalField();
1782 CPPUNIT_ASSERT_THROW((*f2)*=(*f1),INTERP_KERNEL::Exception);
1790 * Check of LINEAR_TIME and CONST_ON_TIME_INTERVAL policies
1792 void MEDCouplingBasicsTest1::testOperationsOnFields4()
1794 MEDCouplingUMesh *m=build2DTargetMesh_1();
1795 int nbOfCells=m->getNumberOfCells();
1796 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,CONST_ON_TIME_INTERVAL);
1798 DataArrayDouble *array=DataArrayDouble::New();
1799 array->alloc(nbOfCells,3);
1800 f1->setArray(array);
1801 CPPUNIT_ASSERT_THROW(f1->setEndArray(array),INTERP_KERNEL::Exception);
1802 CPPUNIT_ASSERT_THROW(f1->getEndArray(),INTERP_KERNEL::Exception);
1804 double *tmp=array->getPointer();
1805 const double arr1[15]={0.,10.,20.,1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.};
1806 const double arr2[15]={5.,15.,25.,6.,16.,26.,7.,17.,27.,8.,18.,28.,9.,19.,29.};
1807 std::copy(arr1,arr1+15,tmp);
1808 f1->setStartTime(2.,0,0);
1809 f1->setEndTime(3.,0,0);
1810 f1->checkCoherency();
1812 const double pos[2]={0.3,-0.2};
1813 f1->getValueOn(pos,res);
1814 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[3],res[0],1.e-12);
1815 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[4],res[1],1.e-12);
1816 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[5],res[2],1.e-12);
1817 std::fill(res,res+3,0.);
1818 f1->getValueOn(pos,2.2,res);
1819 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[3],res[0],1.e-12);
1820 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[4],res[1],1.e-12);
1821 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[5],res[2],1.e-12);
1822 std::fill(res,res+3,0.);
1823 CPPUNIT_ASSERT_THROW(f1->getValueOn(pos,3.2,res),INTERP_KERNEL::Exception);
1824 MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
1826 f2->setArray(f1->getArray());
1827 f2->setStartTime(2.,3,0);
1828 f2->setEndTime(4.,13,0);
1829 CPPUNIT_ASSERT_THROW(f2->checkCoherency(),INTERP_KERNEL::Exception);
1830 DataArrayDouble *array2=DataArrayDouble::New();
1831 array2->alloc(nbOfCells,3);
1832 tmp=array2->getPointer();
1833 std::copy(arr2,arr2+15,tmp);
1834 f2->setEndArray(array2);
1836 f2->checkCoherency();
1838 std::fill(res,res+3,0.);
1839 f2->getValueOn(pos,3.21,res);
1840 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.025,res[0],1.e-12);
1841 CPPUNIT_ASSERT_DOUBLES_EQUAL(14.025,res[1],1.e-12);
1842 CPPUNIT_ASSERT_DOUBLES_EQUAL(24.025,res[2],1.e-12);
1843 MEDCouplingFieldDouble *f3=f2->clone(true);
1844 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-12));
1845 f3->getEndArray()->getPointer()[0]=5.001;
1846 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-12));
1847 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1848 f3->setStartTime(2.1,3,0);
1849 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1850 f3->setStartTime(2.,3,0);
1851 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1852 f3->setStartTime(2.,4,0);
1853 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1854 f3->setStartTime(2.,3,1);
1855 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1856 f3->setStartTime(2.,3,0);
1857 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1858 f3->setEndTime(4.1,13,0);
1859 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1860 f3->setEndTime(4.,13,0);
1861 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1862 f3->setEndTime(4.,14,0);
1863 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1864 f3->setEndTime(4.,13,1);
1865 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1866 f3->setEndTime(4.,13,0);
1867 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1869 MEDCouplingFieldDouble *f4=(*f2)+(*f2);
1870 std::fill(res,res+3,0.);
1871 f4->getValueOn(pos,3.21,res);
1872 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.05,res[0],1.e-12);
1873 CPPUNIT_ASSERT_DOUBLES_EQUAL(28.05,res[1],1.e-12);
1874 CPPUNIT_ASSERT_DOUBLES_EQUAL(48.05,res[2],1.e-12);
1876 std::fill(res,res+3,0.);
1877 f4->getValueOn(pos,3.21,res);
1878 CPPUNIT_ASSERT_DOUBLES_EQUAL(12.075,res[0],1.e-12);
1879 CPPUNIT_ASSERT_DOUBLES_EQUAL(42.075,res[1],1.e-12);
1880 CPPUNIT_ASSERT_DOUBLES_EQUAL(72.075,res[2],1.e-12);
1888 bool func4(const double *pt, double *res)
1890 res[0]=pt[0]+pt[1]+pt[2];
1894 void MEDCouplingBasicsTest1::testMergeNodesOnField()
1897 MEDCouplingUMesh *targetMesh=build3DTargetMeshMergeNode_1();
1898 MEDCouplingFieldDouble *f1=targetMesh->fillFromAnalytic(ON_NODES,1,func4);
1899 f1->mergeNodes(1e-10);
1901 targetMesh->decrRef();
1903 targetMesh=build3DTargetMeshMergeNode_1();
1904 f1=targetMesh->fillFromAnalytic(ON_NODES,1,func4);
1905 tmp=f1->getArray()->getPointer();
1907 f1->mergeNodes(1e-10);
1909 targetMesh->decrRef();
1911 targetMesh=build3DTargetMeshMergeNode_1();
1912 f1=targetMesh->fillFromAnalytic(ON_NODES,1,func4);
1913 tmp=f1->getArray()->getPointer();
1915 CPPUNIT_ASSERT_THROW(f1->mergeNodes(1e-10),INTERP_KERNEL::Exception);
1917 targetMesh->decrRef();
1920 void MEDCouplingBasicsTest1::testCheckConsecutiveCellTypes()
1922 MEDCouplingUMesh *sourceMesh=build2DSourceMesh_1();
1923 MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
1924 CPPUNIT_ASSERT(sourceMesh->checkConsecutiveCellTypes());
1925 const INTERP_KERNEL::NormalizedCellType order1[]={INTERP_KERNEL::NORM_TRI3, INTERP_KERNEL::NORM_QUAD4};
1926 const INTERP_KERNEL::NormalizedCellType order2[]={INTERP_KERNEL::NORM_QUAD4, INTERP_KERNEL::NORM_TRI3};
1927 CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypes());
1928 CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypesAndOrder(order1,order1+2));
1929 CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypesAndOrder(order2,order2+2));
1930 DataArrayInt *da=targetMesh->getRenumArrForConsecutiveCellTypesSpec(order1,order1+2);
1931 CPPUNIT_ASSERT_EQUAL(5,da->getNumberOfTuples());
1932 CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfComponents());
1933 const int expected1[5]={2,0,1,3,4};
1934 CPPUNIT_ASSERT(std::equal(expected1,expected1+5,da->getConstPointer()));
1936 da=targetMesh->getRenumArrForConsecutiveCellTypesSpec(order2,order2+2);
1937 CPPUNIT_ASSERT_EQUAL(5,da->getNumberOfTuples());
1938 CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfComponents());
1939 const int expected2[5]={0,3,4,1,2};
1940 CPPUNIT_ASSERT(std::equal(expected2,expected2+5,da->getConstPointer()));
1942 const int renumber1[5]={4,0,1,2,3};
1943 targetMesh->renumberCells(renumber1,false);
1944 CPPUNIT_ASSERT(targetMesh->checkConsecutiveCellTypes());
1945 CPPUNIT_ASSERT(targetMesh->checkConsecutiveCellTypesAndOrder(order1,order1+2));
1946 CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypesAndOrder(order2,order2+2));
1947 targetMesh->decrRef();
1948 sourceMesh->decrRef();
1951 void MEDCouplingBasicsTest1::testRearrange2ConsecutiveCellTypes()
1953 MEDCouplingUMesh *m1_1=build2DSourceMesh_1();
1954 MEDCouplingUMesh *m2_1=build2DTargetMesh_1();
1955 DataArrayInt *arr1=m1_1->rearrange2ConsecutiveCellTypes();
1956 MEDCouplingUMesh *m1_2=build2DSourceMesh_1();
1957 CPPUNIT_ASSERT(m1_2->isEqual(m1_1,1e-12));
1958 const int expected1[2]={0,1};
1959 CPPUNIT_ASSERT_EQUAL(2,arr1->getNumberOfTuples());
1960 CPPUNIT_ASSERT_EQUAL(1,arr1->getNumberOfComponents());
1961 CPPUNIT_ASSERT(std::equal(expected1,expected1+2,arr1->getConstPointer()));
1963 const int expected2[5]={0,3,4,1,2};
1964 arr1=m2_1->rearrange2ConsecutiveCellTypes();
1965 CPPUNIT_ASSERT_EQUAL(5,arr1->getNumberOfTuples());
1966 CPPUNIT_ASSERT_EQUAL(1,arr1->getNumberOfComponents());
1967 CPPUNIT_ASSERT(std::equal(expected2,expected2+5,arr1->getConstPointer()));
1968 MEDCouplingUMesh *m2_2=build2DTargetMesh_1();
1969 CPPUNIT_ASSERT_EQUAL(5,arr1->getNumberOfTuples());
1970 CPPUNIT_ASSERT_EQUAL(1,arr1->getNumberOfComponents());
1971 CPPUNIT_ASSERT(std::equal(expected2,expected2+5,arr1->getConstPointer()));
1972 CPPUNIT_ASSERT(!m2_2->isEqual(m2_1,1e-12));
1973 m2_2->renumberCells(expected2,false);
1974 CPPUNIT_ASSERT(m2_2->isEqual(m2_1,1e-12));
1982 void MEDCouplingBasicsTest1::testSplitByType()
1984 MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
1985 std::vector<MEDCouplingUMesh *> v=m1->splitByType();
1986 CPPUNIT_ASSERT_EQUAL(3,(int)v.size());
1987 std::vector<const MEDCouplingUMesh *> v2(v.begin(),v.end());
1988 MEDCouplingUMesh *m2=MEDCouplingUMesh::MergeUMeshesOnSameCoords(v2);
1989 m2->setName(m1->getName());
1990 CPPUNIT_ASSERT(m1->isEqual(m2,1.e-12));
1991 for(std::vector<MEDCouplingUMesh *>::const_iterator iter=v.begin();iter!=v.end();iter++)
1997 void MEDCouplingBasicsTest1::testFuseUMeshesOnSameCoords()
1999 std::vector<const MEDCouplingUMesh *> meshes;
2000 MEDCouplingUMesh *m2=build2DTargetMesh_1();
2001 int cells1[3]={2,3,4};
2002 MEDCouplingPointSet *m3_1=m2->buildPartOfMySelf(cells1,cells1+3,true);
2003 MEDCouplingUMesh *m3=dynamic_cast<MEDCouplingUMesh *>(m3_1);
2005 meshes.push_back(m3);
2006 int cells2[3]={1,2,4};
2007 MEDCouplingPointSet *m4_1=m2->buildPartOfMySelf(cells2,cells2+3,true);
2008 MEDCouplingUMesh *m4=dynamic_cast<MEDCouplingUMesh *>(m4_1);
2010 meshes.push_back(m4);
2011 int cells3[2]={1,2};
2012 MEDCouplingPointSet *m5_1=m2->buildPartOfMySelf(cells3,cells3+2,true);
2013 MEDCouplingUMesh *m5=dynamic_cast<MEDCouplingUMesh *>(m5_1);
2015 meshes.push_back(m5);
2018 std::vector<DataArrayInt *> corr;
2019 MEDCouplingUMesh *m7=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
2020 CPPUNIT_ASSERT_EQUAL(4,m7->getNumberOfCells());
2021 CPPUNIT_ASSERT_EQUAL(3,(int)corr.size());
2022 const int expectedVals1[3]={3,3,2};
2023 const int expectedVals2[3][3]={{0,1,2},{3,0,2},{3,0,111111}};
2024 for(int i=0;i<3;i++)
2026 DataArrayInt *arr=corr[i];
2027 CPPUNIT_ASSERT_EQUAL(1,arr->getNumberOfComponents());
2028 int nbOfVals=expectedVals1[i];
2029 CPPUNIT_ASSERT_EQUAL(nbOfVals,arr->getNumberOfTuples());
2030 const int *vals=arr->getConstPointer();
2031 for(int j=0;j<nbOfVals;j++)
2032 CPPUNIT_ASSERT_EQUAL(expectedVals2[i][j],vals[j]);
2034 std::vector< std::vector<int> > fidsOfGroups;
2035 std::vector<const DataArrayInt *> corr2(corr.begin(),corr.end());
2036 DataArrayInt *arr2=DataArrayInt::MakePartition(corr2,m7->getNumberOfCells(),fidsOfGroups);
2037 const int fidExp[4]={5,1,3,4};
2038 const int fidsGrp[3][3]={{1,3,5},{3,4,5},{4,5,23344}};
2039 CPPUNIT_ASSERT_EQUAL(3,(int)fidsOfGroups.size());
2040 CPPUNIT_ASSERT_EQUAL(1,arr2->getNumberOfComponents());
2041 CPPUNIT_ASSERT_EQUAL(4,arr2->getNumberOfTuples());
2042 CPPUNIT_ASSERT(std::equal(fidExp,fidExp+4,arr2->getConstPointer()));
2043 for(int i=0;i<3;i++)
2045 int nbOfVals=expectedVals1[i];
2046 CPPUNIT_ASSERT_EQUAL(nbOfVals,(int)fidsOfGroups[i].size());
2047 CPPUNIT_ASSERT(std::equal(fidsOfGroups[i].begin(),fidsOfGroups[i].end(),fidsGrp[i]));
2049 for(std::vector<DataArrayInt *>::iterator iter=corr.begin();iter!=corr.end();iter++)
2059 void MEDCouplingBasicsTest1::testFuseUMeshesOnSameCoords2()
2061 MEDCouplingUMesh *m2;
2062 MEDCouplingUMesh *m1=build3DExtrudedUMesh_1(m2);
2064 const int part1[5]={2,3,6,4,10};
2065 MEDCouplingUMesh *m3=(MEDCouplingUMesh *)m1->buildPartOfMySelf(part1,part1+5,true);
2066 const int part2[4]={5,6,4,7};
2067 MEDCouplingUMesh *m4=(MEDCouplingUMesh *)m1->buildPartOfMySelf(part2,part2+4,true);
2068 std::vector<const MEDCouplingUMesh *> meshes;
2069 meshes.push_back(m1);
2070 meshes.push_back(m3);
2071 meshes.push_back(m3);
2072 meshes.push_back(m4);
2073 std::vector<DataArrayInt *> corr;
2074 MEDCouplingUMesh *m5=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
2075 CPPUNIT_ASSERT_EQUAL(18,m5->getNumberOfCells());
2076 std::vector<DataArrayInt *>::iterator it=corr.begin();
2077 const int exp1[4]={18,5,5,4};
2078 const int exp2[4][18]={
2079 {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17},
2080 {2,3,6,4,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
2081 {2,3,6,4,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
2082 {5,6,4,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}
2085 for(;it!=corr.end();it++,i++)
2087 int sz=(*it)->getNumberOfTuples();
2088 CPPUNIT_ASSERT_EQUAL(exp1[i],sz);
2089 CPPUNIT_ASSERT(std::equal(exp2[i],exp2[i]+sz,(*it)->getConstPointer()));
2091 for(it=corr.begin();it!=corr.end();it++)
2099 void MEDCouplingBasicsTest1::testBuildOrthogonalField()
2101 MEDCouplingUMesh *targetMesh=build3DSurfTargetMesh_1();
2102 MEDCouplingFieldDouble *field=targetMesh->buildOrthogonalField();
2103 double expected[3]={0.70710678118654746,0.,-0.70710678118654746};
2104 CPPUNIT_ASSERT_EQUAL(5,field->getNumberOfTuples());
2105 CPPUNIT_ASSERT_EQUAL(3,field->getNumberOfComponents());
2106 const double *vals=field->getArray()->getConstPointer();
2107 for(int i=0;i<15;i++)
2108 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected[i%3],vals[i],1e-12);
2110 targetMesh->decrRef();
2112 double targetCoords[12]={0.,0.,0.,0.5,0.,0.5,1.,0.,1.,0.,1.,0.};
2113 int targetConn[4]={0,1,2,3};
2114 targetMesh=MEDCouplingUMesh::New();
2115 targetMesh->setMeshDimension(2);
2116 targetMesh->allocateCells(1);
2117 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn);
2118 targetMesh->finishInsertingCells();
2119 DataArrayDouble *myCoords=DataArrayDouble::New();
2120 myCoords->alloc(4,3);
2121 std::copy(targetCoords,targetCoords+12,myCoords->getPointer());
2122 targetMesh->setCoords(myCoords);
2123 myCoords->decrRef();
2124 field=targetMesh->buildOrthogonalField();
2125 CPPUNIT_ASSERT_EQUAL(1,field->getNumberOfTuples());
2126 CPPUNIT_ASSERT_EQUAL(3,field->getNumberOfComponents());
2127 vals=field->getArray()->getConstPointer();
2128 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.70710678118654746,vals[0],1e-12);
2129 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,vals[1],1e-12);
2130 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.70710678118654746,vals[2],1e-12);
2132 targetMesh->decrRef();
2135 void MEDCouplingBasicsTest1::testGetCellsContainingPoint()
2137 MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
2138 double pos[12]={0.,0.,0.4,0.4,0.,0.4,0.1,0.1,0.25,0.,0.65,0.};
2139 std::vector<int> t1,t2;
2141 targetMesh->getCellsContainingPoints(pos,6,1e-12,t1,t2);
2142 CPPUNIT_ASSERT_EQUAL(6,(int)t1.size());
2143 CPPUNIT_ASSERT_EQUAL(7,(int)t2.size());
2144 const int expectedValues1[6]={0,4,3,0,1,2};
2145 const int expectedValues2[7]={0,1,2,3,4,5,6};
2146 CPPUNIT_ASSERT(std::equal(t1.begin(),t1.end(),expectedValues1));
2147 CPPUNIT_ASSERT(std::equal(t2.begin(),t2.end(),expectedValues2));
2148 //2D with no help of bounding box.
2149 double center[2]={0.2,0.2};
2150 MEDCouplingPointSet::Rotate2DAlg(center,0.78539816339744830962,6,pos);
2151 targetMesh->rotate(center,0,0.78539816339744830962);
2152 t1.clear(); t2.clear();
2153 targetMesh->getCellsContainingPoints(pos,6,1e-12,t1,t2);
2154 CPPUNIT_ASSERT_EQUAL(6,(int)t1.size());
2155 CPPUNIT_ASSERT_EQUAL(7,(int)t2.size());
2156 CPPUNIT_ASSERT(std::equal(t1.begin(),t1.end(),expectedValues1));
2157 CPPUNIT_ASSERT(std::equal(t2.begin(),t2.end(),expectedValues2));
2159 const double pos1bis[2]={-0.3303300858899107,-0.11819805153394641};
2160 CPPUNIT_ASSERT_EQUAL(-1,targetMesh->getCellContainingPoint(pos1bis,1e-12));
2161 targetMesh->decrRef();
2163 targetMesh=build2DTargetMesh_1();
2164 const double pos2[2]={0.2,-0.05};
2166 targetMesh->getCellsContainingPoint(pos2,1e-12,t1);
2167 CPPUNIT_ASSERT_EQUAL(2,(int)t1.size());
2168 const int expectedValues3[2]={0,1};
2169 CPPUNIT_ASSERT(std::equal(t1.begin(),t1.end(),expectedValues3));
2170 const double pos3[2]={0.2,0.2};
2172 targetMesh->getCellsContainingPoint(pos3,1e-12,t1);
2173 CPPUNIT_ASSERT_EQUAL(5,(int)t1.size());
2174 const int expectedValues4[5]={0,1,2,3,4};
2175 CPPUNIT_ASSERT(std::equal(t1.begin(),t1.end(),expectedValues4));
2176 CPPUNIT_ASSERT_EQUAL(0,targetMesh->getCellContainingPoint(pos3,1e-12));
2177 targetMesh->decrRef();
2179 targetMesh=build3DTargetMesh_1();
2180 const double pos4[3]={25.,25.,25.};
2181 CPPUNIT_ASSERT_EQUAL(0,targetMesh->getCellContainingPoint(pos4,1e-12));
2182 const double pos5[3]={50.,50.,50.};
2184 targetMesh->getCellsContainingPoint(pos5,1e-12,t1);
2185 CPPUNIT_ASSERT_EQUAL(8,(int)t1.size());
2186 const int expectedValues5[8]={0,1,2,3,4,5,6,7};
2187 CPPUNIT_ASSERT(std::equal(t1.begin(),t1.end(),expectedValues5));
2188 const double pos6[3]={0., 50., 0.};
2190 targetMesh->getCellsContainingPoint(pos6,1e-12,t1);
2191 CPPUNIT_ASSERT_EQUAL(2,(int)t1.size());
2192 const int expectedValues6[2]={0,2};
2193 CPPUNIT_ASSERT(std::equal(t1.begin(),t1.end(),expectedValues6));
2195 const double pos7[3]={-1.0,-1.0,0.};
2196 CPPUNIT_ASSERT_EQUAL(-1,targetMesh->getCellContainingPoint(pos7,1e-12));
2198 const double center2[3]={0.,0.,0.};
2199 const double vec2[3]={0.,-1.,0.};
2200 targetMesh->rotate(center2,vec2,0.78539816339744830962);
2201 const double pos8[3]={-25,25.,12.};
2202 CPPUNIT_ASSERT_EQUAL(-1,targetMesh->getCellContainingPoint(pos8,1e-12));
2204 targetMesh->decrRef();
2207 void MEDCouplingBasicsTest1::testGetValueOn1()
2209 MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
2210 MEDCouplingFieldDouble *fieldOnCells=MEDCouplingFieldDouble::New(ON_CELLS);
2211 int nbOfCells=targetMesh->getNumberOfCells();
2212 fieldOnCells->setMesh(targetMesh);
2213 DataArrayDouble *array=DataArrayDouble::New();
2214 array->alloc(nbOfCells,2);
2215 fieldOnCells->setArray(array);
2216 double *tmp=array->getPointer();
2217 for(int i=0;i<nbOfCells;i++)
2218 { tmp[2*i]=7.+(double)i; tmp[2*i+1]=17.+(double)i; }
2221 const double pos1[2]={0.25,0.};
2223 fieldOnCells->getValueOn(pos1,res);
2224 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.,res[0],1e-12);
2225 CPPUNIT_ASSERT_DOUBLES_EQUAL(18.,res[1],1e-12);
2227 fieldOnCells->decrRef();
2228 targetMesh->decrRef();
2230 targetMesh=build2DSourceMesh_1();
2231 MEDCouplingFieldDouble *fieldOnNodes=MEDCouplingFieldDouble::New(ON_NODES);
2232 int nbOfNodes=targetMesh->getNumberOfNodes();
2233 fieldOnNodes->setMesh(targetMesh);
2234 array=DataArrayDouble::New();
2235 array->alloc(nbOfNodes,2);
2236 fieldOnNodes->setArray(array);
2237 tmp=array->getPointer();
2238 for(int i=0;i<nbOfNodes;i++)
2239 { tmp[2*i]=17.+(double)i; tmp[2*i+1]=27.+(double)i; }
2242 const double pos2[2]={-0.13333333333333333,-0.13333333333333333};
2243 fieldOnNodes->getValueOn(pos2,res);
2244 CPPUNIT_ASSERT_DOUBLES_EQUAL(17.5,res[0],1e-12);
2245 CPPUNIT_ASSERT_DOUBLES_EQUAL(27.5,res[1],1e-12);
2246 const double pos3[2]={0.033333333333333326,0.36666666666666664};
2247 fieldOnNodes->getValueOn(pos3,res);
2248 CPPUNIT_ASSERT_DOUBLES_EQUAL(18.666666666666667,res[0],1e-12);
2249 CPPUNIT_ASSERT_DOUBLES_EQUAL(28.666666666666667,res[1],1e-12);
2251 fieldOnNodes->decrRef();
2252 targetMesh->decrRef();
2255 void MEDCouplingBasicsTest1::testCMesh0()
2257 MEDCouplingCMesh* mesh=MEDCouplingCMesh::New();
2258 MEDCouplingCMesh* meshEmpty=mesh->clone(true);
2259 CPPUNIT_ASSERT(meshEmpty->isEqual(mesh,1e-12));
2261 DataArrayDouble* coordsX=DataArrayDouble::New();
2262 double arrX[4] = { -1., 1., 2., 4. };
2263 coordsX->useArray(arrX,false, CPP_DEALLOC,4,1);
2264 DataArrayDouble* coordsY=DataArrayDouble::New();
2265 double arrY[4] = { -2., 2., 4., 8. };
2266 coordsY->useArray(arrY,false, CPP_DEALLOC,4,1);
2267 DataArrayDouble* coordsZ=DataArrayDouble::New();
2268 double arrZ[4] = { -3., 3., 6., 12. };
2269 coordsZ->useArray(arrZ,false, CPP_DEALLOC,4,1);
2270 mesh->setCoords(coordsX,coordsY,coordsZ);
2275 MEDCouplingFieldDouble *fieldOnNodes=mesh->fillFromAnalytic(ON_NODES,1,"x+y/2.+z/3.");
2276 CPPUNIT_ASSERT_EQUAL(1,fieldOnNodes->getNumberOfComponents());
2277 CPPUNIT_ASSERT_EQUAL(64,fieldOnNodes->getNumberOfTuples());
2278 const double expected1[64]={-3., -1., 0., 2., -1., 1., 2., 4., 0., 2., 3., 5., 2., 4., 5., 7., -1., 1., 2.,
2279 4., 1., 3., 4., 6., 2., 4., 5., 7., 4., 6., 7., 9., 0., 2., 3., 5., 2., 4., 5.,
2280 7., 3., 5., 6., 8., 5., 7., 8., 10., 2., 4., 5.,
2281 7., 4., 6., 7., 9., 5., 7., 8., 10., 7., 9., 10., 12.};
2282 const double *val=fieldOnNodes->getArray()->getConstPointer();
2283 for(int i=0;i<64;i++)
2284 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1e-12);
2285 double res[1]; //size fieldOnNodes->getNumberOfComponents()
2286 fieldOnNodes->getValueOnPos(1,3,2,&res[0]);
2287 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,res[0],1e-12);
2288 fieldOnNodes->decrRef();
2290 MEDCouplingFieldDouble *fieldOnCells=mesh->fillFromAnalytic(ON_CELLS,1,"x+y/2.+z/3.");
2291 CPPUNIT_ASSERT_EQUAL(1,fieldOnCells->getNumberOfComponents());
2292 CPPUNIT_ASSERT_EQUAL(27,fieldOnCells->getNumberOfTuples());
2293 val=fieldOnCells->getArray()->getConstPointer();
2294 const double expected2[27]={0, 1.5, 3, 1.5, 3, 4.5, 3, 4.5, 6, 1.5, 3, 4.5, 3, 4.5,
2295 6, 4.5, 6, 7.5, 3, 4.5, 6, 4.5, 6, 7.5, 6, 7.5, 9};
2296 for(int i=0;i<27;i++)
2297 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1e-12);
2298 fieldOnCells->getValueOnPos(1,2,1,&res[0]);
2299 CPPUNIT_ASSERT_DOUBLES_EQUAL(6.,res[0],1e-12);
2300 fieldOnCells->decrRef();
2302 MEDCouplingMesh* meshDeepCopy=mesh->deepCpy();
2303 MEDCouplingCMesh* meshClone=mesh->clone(false);
2305 CPPUNIT_ASSERT_THROW(meshEmpty->copyTinyStringsFrom(0),INTERP_KERNEL::Exception);
2306 meshEmpty->copyTinyStringsFrom(mesh);
2307 //no data in meshEmpty, expected false
2308 CPPUNIT_ASSERT(!meshEmpty->isEqual(mesh,1e-12));
2310 CPPUNIT_ASSERT(meshDeepCopy->isEqual(mesh,1e-12));
2311 meshDeepCopy->copyTinyStringsFrom(mesh);
2312 CPPUNIT_ASSERT(meshDeepCopy->isEqual(mesh,1e-12));
2313 CPPUNIT_ASSERT(meshClone->isEqual(mesh,1e-12));
2315 CPPUNIT_ASSERT_EQUAL(CARTESIAN,mesh->getType());
2316 CPPUNIT_ASSERT_EQUAL(CARTESIAN,meshEmpty->getType());
2317 CPPUNIT_ASSERT_EQUAL(CARTESIAN,meshDeepCopy->getType());
2318 CPPUNIT_ASSERT_EQUAL(CARTESIAN,meshClone->getType());
2321 meshEmpty->decrRef();
2322 meshDeepCopy->decrRef();
2323 meshClone->decrRef();
2326 void MEDCouplingBasicsTest1::testCMesh1()
2328 MEDCouplingCMesh *mesh1,*mesh2,*mesh3;
2329 mesh1=MEDCouplingCMesh::New();
2330 DataArrayDouble* coordsX1=DataArrayDouble::New();
2331 double arrX1[4] = { -1., 1., 2., 4. };
2332 coordsX1->useArray(arrX1,false, CPP_DEALLOC,4,1);
2333 DataArrayDouble* coordsY1=DataArrayDouble::New();
2334 double arrY1[4] = { -2., 2., 4., 8. };
2335 coordsY1->useArray(arrY1,false, CPP_DEALLOC,4,1);
2336 DataArrayDouble* coordsZ1=DataArrayDouble::New();
2337 double arrZ1[4] = { -3., 3., 6., 12. };
2338 coordsZ1->useArray(arrZ1,false, CPP_DEALLOC,4,1);
2339 mesh1->setCoords(coordsX1,coordsY1,coordsZ1);
2341 mesh2=MEDCouplingCMesh::New();
2342 DataArrayDouble* coordsX2=DataArrayDouble::New();
2343 double arrX2[4] = { -1., 1., 2., 4. };
2344 coordsX2->useArray(arrX2,false, CPP_DEALLOC,4,1);
2345 DataArrayDouble* coordsY2=DataArrayDouble::New();
2346 double arrY2[4] = { -2., 2., 4., 8. };
2347 coordsY2->useArray(arrY2,false, CPP_DEALLOC,4,1);
2348 DataArrayDouble* coordsZ2=DataArrayDouble::New();
2349 double arrZ2[4] = { -3., 3., 6., 12.+1e-6 }; //here is not equal
2350 coordsZ2->useArray(arrZ2,false, CPP_DEALLOC,4,1);
2351 mesh2->setCoords(coordsX2,coordsY2,coordsZ2);
2353 mesh3=MEDCouplingCMesh::New();
2354 DataArrayDouble* coordsX3=DataArrayDouble::New();
2355 double arrX3[1] = { -1.};
2356 coordsX3->useArray(arrX3,false, CPP_DEALLOC,1,1);
2357 DataArrayDouble* coordsY3=DataArrayDouble::New();
2358 double arrY3[1] = { -2.};
2359 coordsY3->useArray(arrY3,false, CPP_DEALLOC,1,1);
2360 DataArrayDouble* coordsZ3=DataArrayDouble::New();
2361 double arrZ3[1] = { -3.};
2362 coordsZ3->useArray(arrZ3,false, CPP_DEALLOC,1,1);
2363 mesh3->setCoords(coordsX3,coordsY3,coordsZ3);
2365 CPPUNIT_ASSERT_EQUAL(3,mesh1->getSpaceDimension());
2366 CPPUNIT_ASSERT_EQUAL(3,mesh1->getMeshDimension());
2368 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
2369 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
2370 CPPUNIT_ASSERT(!mesh2->isEqualWithoutConsideringStr(mesh1,1e-12));
2371 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-5));
2372 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-7));
2374 CPPUNIT_ASSERT_THROW(mesh3->checkCoherency1(1e-12),INTERP_KERNEL::Exception);
2375 mesh1->checkCoherency2(1e-12);
2376 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh1->getTypeOfCell(1));
2378 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,*((mesh1->getAllGeoTypes()).begin()));
2379 CPPUNIT_ASSERT_EQUAL(27,mesh1->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2380 CPPUNIT_ASSERT_THROW(mesh1->getNumberOfCellsWithType(INTERP_KERNEL::NORM_QUAD4),INTERP_KERNEL::Exception);
2382 std::vector<double> coo;
2383 mesh1->getCoordinatesOfNode(0, coo);
2384 CPPUNIT_ASSERT_EQUAL(3,(int) coo.size());
2385 CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.,coo[0],1e-14);
2386 CPPUNIT_ASSERT_DOUBLES_EQUAL(-2.,coo[1],1e-14);
2387 CPPUNIT_ASSERT_DOUBLES_EQUAL(-3.,coo[2],1e-14);
2389 mesh1->getCoordinatesOfNode(63, coo);
2390 CPPUNIT_ASSERT_EQUAL(3,(int) coo.size());
2391 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.,coo[0],1e-14);
2392 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.,coo[1],1e-14);
2393 CPPUNIT_ASSERT_DOUBLES_EQUAL(12.,coo[2],1e-14);
2396 repr=mesh1->simpleRepr();
2397 repr=mesh1->advancedRepr();
2398 CPPUNIT_ASSERT(!(repr.find("Cartesian")==std::string::npos));
2399 CPPUNIT_ASSERT(!(repr.find("Number of components : 1")==std::string::npos));
2400 CPPUNIT_ASSERT(!(repr.find("Number of tuples : 4")==std::string::npos));
2401 CPPUNIT_ASSERT(!(repr.find("Z Array :")==std::string::npos));
2402 coordsX1->decrRef();
2403 coordsY1->decrRef();
2404 coordsZ1->decrRef();
2405 coordsX2->decrRef();
2406 coordsY2->decrRef();
2407 coordsZ2->decrRef();
2408 coordsX3->decrRef();
2409 coordsY3->decrRef();
2410 coordsZ3->decrRef();
2416 void MEDCouplingBasicsTest1::testCMesh2()
2418 MEDCouplingCMesh *mesh1;
2419 mesh1=MEDCouplingCMesh::New();
2420 DataArrayDouble* coordsX1=DataArrayDouble::New();
2421 double arrX1[4] = { -1., 1., 2., 4. };
2422 coordsX1->useArray(arrX1,false, CPP_DEALLOC,4,1);
2423 DataArrayDouble* coordsY1=DataArrayDouble::New();
2424 double arrY1[4] = { -2., 2., 4., 8. };
2425 coordsY1->useArray(arrY1,false, CPP_DEALLOC,4,1);
2426 DataArrayDouble* coordsZ1=DataArrayDouble::New();
2427 double arrZ1[4] = { -3., 3., 6., 12. };
2428 coordsZ1->useArray(arrZ1,false, CPP_DEALLOC,4,1);
2429 mesh1->setCoords(coordsX1,coordsY1,coordsZ1);
2431 std::vector<int> dis=mesh1->getDistributionOfTypes();
2432 CPPUNIT_ASSERT_EQUAL(3,(int) dis.size());
2433 CPPUNIT_ASSERT_EQUAL((int) INTERP_KERNEL::NORM_HEXA8,dis[0]);
2434 CPPUNIT_ASSERT_EQUAL(27,dis[1]);
2435 CPPUNIT_ASSERT_EQUAL(0,dis[2]);
2437 std::vector<const DataArrayInt *> idsPerType;
2438 CPPUNIT_ASSERT_THROW(mesh1->checkTypeConsistencyAndContig(dis, idsPerType),INTERP_KERNEL::Exception);
2440 CPPUNIT_ASSERT(!(mesh1->checkTypeConsistencyAndContig(dis, idsPerType)));
2441 dis[0]=(int) INTERP_KERNEL::NORM_QUAD4;
2442 CPPUNIT_ASSERT_THROW(mesh1->checkTypeConsistencyAndContig(dis, idsPerType),INTERP_KERNEL::Exception);
2444 dis[0]=(int) INTERP_KERNEL::NORM_HEXA8;
2446 DataArrayInt *ids=DataArrayInt::New();
2448 ids->fillWithValue(111);
2449 idsPerType.push_back(ids);
2450 DataArrayInt* check=mesh1->checkTypeConsistencyAndContig(dis, idsPerType);
2451 CPPUNIT_ASSERT(check);
2452 CPPUNIT_ASSERT(check->isEqual(*ids));
2454 std::vector<int> code;
2455 std::vector<DataArrayInt *> idsInPflPerType;
2456 std::vector<DataArrayInt *> pfls;
2457 mesh1->splitProfilePerType(ids,code,idsInPflPerType,pfls);
2458 CPPUNIT_ASSERT_EQUAL(3,(int)code.size());
2459 CPPUNIT_ASSERT_EQUAL((int) INTERP_KERNEL::NORM_HEXA8,code[0]);
2460 CPPUNIT_ASSERT_EQUAL(27,code[1]);
2461 CPPUNIT_ASSERT_EQUAL(0,code[2]);
2462 CPPUNIT_ASSERT_EQUAL(1,(int)idsInPflPerType.size());
2463 CPPUNIT_ASSERT_EQUAL(1,(int)pfls.size());
2464 CPPUNIT_ASSERT(idsInPflPerType[0]->isEqual(*ids));
2465 CPPUNIT_ASSERT(pfls[0]->isEqual(*ids));
2466 idsInPflPerType[0]->decrRef();
2471 int cells1[4]={0,1,25,26};
2472 MEDCouplingUMesh *partMesh1=
2473 dynamic_cast<MEDCouplingUMesh *>(mesh1->buildPart(cells1,cells1+4));
2474 CPPUNIT_ASSERT(partMesh1);
2475 CPPUNIT_ASSERT_EQUAL(4,partMesh1->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2476 CPPUNIT_ASSERT_EQUAL(64,mesh1->getNumberOfNodes());
2477 CPPUNIT_ASSERT_EQUAL(64,partMesh1->getNumberOfNodes());
2479 int cells2[2]={25,26};
2481 MEDCouplingUMesh *partMesh2=
2482 dynamic_cast<MEDCouplingUMesh *>(mesh1->buildPartAndReduceNodes(cells2,cells2+2,arr1));
2483 CPPUNIT_ASSERT(partMesh2);
2484 CPPUNIT_ASSERT_EQUAL(2,partMesh2->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2485 CPPUNIT_ASSERT_EQUAL(12,partMesh2->getNumberOfNodes());
2487 int cells3[2]={2,3};
2489 MEDCouplingUMesh *partMesh3=
2490 dynamic_cast<MEDCouplingUMesh *>(partMesh1->buildPartAndReduceNodes(cells3,cells3+2,arr2));
2491 CPPUNIT_ASSERT(partMesh3);
2492 CPPUNIT_ASSERT_EQUAL(2,partMesh3->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2493 CPPUNIT_ASSERT_EQUAL(12,partMesh3->getNumberOfNodes());
2495 CPPUNIT_ASSERT_THROW(mesh1->simplexize(0),INTERP_KERNEL::Exception);
2496 CPPUNIT_ASSERT_THROW(mesh1->getMeasureFieldOnNode(true),INTERP_KERNEL::Exception);
2500 mesh1->getBoundingBox(bbox1);
2501 partMesh1->getBoundingBox(bbox2);
2502 for(int i=0;i<6;i++)
2503 CPPUNIT_ASSERT_DOUBLES_EQUAL(bbox1[i],bbox2[i],1e-12);
2504 partMesh3->getBoundingBox(bbox1);
2505 partMesh2->getBoundingBox(bbox2);
2506 for(int i=0;i<6;i++)
2507 CPPUNIT_ASSERT_DOUBLES_EQUAL(bbox1[i],bbox2[i],1e-12);
2509 CPPUNIT_ASSERT_THROW(mesh1->buildOrthogonalField(),INTERP_KERNEL::Exception);
2510 MEDCouplingCMesh *mesh2d=MEDCouplingCMesh::New();
2511 mesh2d->setCoords(coordsX1,coordsY1);
2512 MEDCouplingFieldDouble *f1=mesh2d->buildOrthogonalField();
2514 std::vector<double> tinyInfoD;
2515 std::vector<int> tinyInfo;
2516 std::vector<std::string> littleStrings;
2517 mesh2d->getTinySerializationInformation(tinyInfoD, tinyInfo, littleStrings);
2518 CPPUNIT_ASSERT_EQUAL(5,(int)tinyInfo.size());
2519 CPPUNIT_ASSERT_EQUAL(4,(int)tinyInfo[0]); //x
2520 CPPUNIT_ASSERT_EQUAL(4,(int)tinyInfo[1]); //y
2521 CPPUNIT_ASSERT_EQUAL(-1,(int)tinyInfo[2]); //z
2522 CPPUNIT_ASSERT_EQUAL(-1,(int)tinyInfo[3]); //it
2523 CPPUNIT_ASSERT_EQUAL(-1,(int)tinyInfo[4]); //order
2524 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,tinyInfoD[0],1e-14); //time
2525 DataArrayInt* d1=DataArrayInt::New();
2526 DataArrayDouble* d2=DataArrayDouble::New();
2527 mesh2d->resizeForUnserialization(tinyInfo, d1, d2, littleStrings);
2528 CPPUNIT_ASSERT_EQUAL(0,d1->getNumberOfTuples());
2529 CPPUNIT_ASSERT_EQUAL(8,d2->getNumberOfTuples());
2531 partMesh1->decrRef();
2532 partMesh2->decrRef();
2533 partMesh3->decrRef();
2540 coordsX1->decrRef();
2541 coordsY1->decrRef();
2542 coordsZ1->decrRef();
2546 void MEDCouplingBasicsTest1::testScale()
2548 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
2549 const double pos[2]={0.2,0.2};
2550 mesh->scale(pos,0.5);
2551 const double expected1[18]={-0.05,-0.05, 0.2,-0.05, 0.45,-0.05, -0.05,0.2, 0.2,0.2, 0.45,0.2,
2552 -0.05,0.45, 0.2,0.45, 0.45,0.45};
2553 const double *val=mesh->getCoords()->getConstPointer();
2554 for(int i=0;i<18;i++)
2555 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1e-12);
2560 void MEDCouplingBasicsTest1::testTryToShareSameCoords()
2562 MEDCouplingUMesh *m1=build2DTargetMesh_1();
2563 MEDCouplingUMesh *m2=build2DTargetMesh_1();
2564 CPPUNIT_ASSERT(m1->getCoords()!=m2->getCoords());
2565 m1->tryToShareSameCoords(*m2,1e-12);
2566 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2567 m1->tryToShareSameCoords(*m2,1e-12);
2568 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2569 m2->tryToShareSameCoords(*m1,1e-12);
2570 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2574 m1=build2DTargetMesh_1();
2575 m2=build2DTargetMesh_2();
2576 CPPUNIT_ASSERT(m1->getCoords()!=m2->getCoords());
2577 m1->tryToShareSameCoords(*m2,1e-12);
2578 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2579 m1->tryToShareSameCoords(*m2,1e-12);
2580 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2581 m2->tryToShareSameCoords(*m1,1e-12);
2582 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2586 m1=build2DTargetMesh_1();
2587 m2=build2DSourceMesh_1();
2588 CPPUNIT_ASSERT(m1->getCoords()!=m2->getCoords());
2589 CPPUNIT_ASSERT_THROW(m1->tryToShareSameCoords(*m2,1e-12),INTERP_KERNEL::Exception);
2594 void MEDCouplingBasicsTest1::testFindNodeOnPlane()
2596 MEDCouplingUMesh *mesh=build3DTargetMesh_1();
2598 double pt[3]={300.,300.,0.};
2599 double v[3]={0.,0.,2.};
2600 mesh->findNodesOnPlane(pt,v,1e-12,n);
2601 CPPUNIT_ASSERT_EQUAL(9,(int)n.size());
2602 MEDCouplingUMesh *m3dSurf=(MEDCouplingUMesh *)mesh->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
2603 MEDCouplingExtrudedMesh *me=MEDCouplingExtrudedMesh::New(mesh,m3dSurf,0);
2604 const DataArrayInt *da=me->getMesh3DIds();
2605 CPPUNIT_ASSERT_EQUAL(8,me->getNumberOfCells());
2606 const int expected[8]={0,1,2,3,4,5,6,7};
2607 const int *val=da->getConstPointer();
2608 for(int i=0;i<8;i++)
2609 CPPUNIT_ASSERT_EQUAL(expected[i],val[i]);
2615 void MEDCouplingBasicsTest1::testRenumberCells()
2617 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
2618 MEDCouplingUMesh *m2=build3DSurfTargetMesh_1();
2619 CPPUNIT_ASSERT(m->isEqual(m2,0));
2620 const int arr[5]={12,3,25,2,26};
2621 m->renumberCells(arr,true);
2622 CPPUNIT_ASSERT(!m->isEqual(m2,0));
2623 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(0));
2624 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(1));
2625 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(2));
2626 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(3));
2627 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(4));
2628 const int arr2[5]={5,-1,-5,4,8};
2629 m->renumberCells(arr2,true);
2630 CPPUNIT_ASSERT(m->isEqual(m2,0));
2635 void MEDCouplingBasicsTest1::testChangeSpaceDimension()
2637 MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
2638 MEDCouplingUMesh *m2=build2DTargetMesh_1();
2640 CPPUNIT_ASSERT_EQUAL(3,m1->getSpaceDimension());
2641 m1->changeSpaceDimension(2);
2642 CPPUNIT_ASSERT_EQUAL(2,m1->getSpaceDimension());
2643 m1->setName(m2->getName());
2644 CPPUNIT_ASSERT(m1->isEqual(m2,1e-12));
2645 m1->changeSpaceDimension(3);
2646 CPPUNIT_ASSERT_EQUAL(3,m1->getSpaceDimension());
2647 const double expected[27]={-0.3,-0.3,0., 0.2,-0.3,0., 0.7,-0.3,0., -0.3,0.2,0., 0.2,0.2,0., 0.7,0.2,0., -0.3,0.7,0., 0.2,0.7,0., 0.7,0.7,0.};
2648 const double *val=m1->getCoords()->getConstPointer();
2649 for(int i=0;i<27;i++)
2650 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected[i],val[i],1e-14);