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
19 // Author : Anthony Geay (CEA/DEN)
21 #include "MEDCouplingBasicsTest1.hxx"
22 #include "MEDCouplingUMesh.hxx"
23 #include "MEDCouplingCMesh.hxx"
24 #include "MEDCouplingExtrudedMesh.hxx"
25 #include "MEDCouplingFieldDouble.hxx"
26 #include "MEDCouplingMemArray.hxx"
33 using namespace ParaMEDMEM;
35 void MEDCouplingBasicsTest1::testArray()
37 int tmp1[6]={7,6,5,4,3,2};
38 const int tmp2[3]={8,9,10};
41 mem.useArray(tmp1,false,CPP_DEALLOC,6);
42 CPPUNIT_ASSERT(tmp1==mem.getConstPointer());
43 CPPUNIT_ASSERT_THROW(mem.getPointer(),INTERP_KERNEL::Exception);
44 CPPUNIT_ASSERT_THROW(mem[2]=7,INTERP_KERNEL::Exception);
45 CPPUNIT_ASSERT_THROW(mem.writeOnPlace(0,12,tmp2,3),INTERP_KERNEL::Exception);
46 mem.writeOnPlace(4,12,tmp2,3);
50 std::copy(tmp1,tmp1+6,tmp3);
52 mem2.useArray(tmp3,true,CPP_DEALLOC,6);
53 CPPUNIT_ASSERT(tmp3==mem2.getConstPointer());
54 CPPUNIT_ASSERT(tmp3==mem2.getPointer());
55 CPPUNIT_ASSERT_EQUAL(5,mem2[2]);
57 CPPUNIT_ASSERT_EQUAL(7,mem2[2]);
58 mem2.writeOnPlace(0,12,tmp2,3);
59 CPPUNIT_ASSERT_EQUAL(9,mem2[2]);
60 CPPUNIT_ASSERT_EQUAL(12,mem2[0]);
61 mem2.writeOnPlace(4,12,tmp2,3);
65 void MEDCouplingBasicsTest1::testArray2()
67 DataArrayDouble *arr=DataArrayDouble::New();
69 double *tmp=arr->getPointer();
70 const double arrRef[12]={12.,11.,10.,9.,8.,7.,6.,5.,4.,3.,2.,1.};
71 std::copy(arrRef,arrRef+12,tmp);
72 arr->setInfoOnComponent(0,"ggg");
73 arr->setInfoOnComponent(1,"hhhh");
74 arr->setInfoOnComponent(2,"jj");
75 arr->setInfoOnComponent(3,"kkkkkk");
76 DataArrayInt *arr2=arr->convertToIntArr();
77 DataArrayDouble *arr3=arr2->convertToDblArr();
79 CPPUNIT_ASSERT(arr->isEqual(*arr3,1e-14));
84 void MEDCouplingBasicsTest1::testArray3()
86 DataArrayInt *arr1=DataArrayInt::New();
88 int *tmp=arr1->getPointer();
89 const int arr1Ref[14]={0,10,1,11,2,12,3,13,4,14,5,15,6,16};
90 std::copy(arr1Ref,arr1Ref+14,tmp);
91 CPPUNIT_ASSERT_EQUAL(7,arr1->getNumberOfTuples());
92 CPPUNIT_ASSERT_EQUAL(2,arr1->getNumberOfComponents());
93 CPPUNIT_ASSERT(std::equal(arr1Ref,arr1Ref+14,arr1->getConstPointer()));
94 DataArrayInt *arr2=arr1->substr(3);
95 CPPUNIT_ASSERT_EQUAL(4,arr2->getNumberOfTuples());
96 CPPUNIT_ASSERT_EQUAL(2,arr2->getNumberOfComponents());
97 CPPUNIT_ASSERT(std::equal(arr1Ref+6,arr1Ref+14,arr2->getConstPointer()));
99 DataArrayInt *arr3=arr1->substr(2,5);
100 CPPUNIT_ASSERT_EQUAL(3,arr3->getNumberOfTuples());
101 CPPUNIT_ASSERT_EQUAL(2,arr3->getNumberOfComponents());
102 CPPUNIT_ASSERT(std::equal(arr1Ref+4,arr1Ref+10,arr3->getConstPointer()));
106 DataArrayDouble *arr4=DataArrayDouble::New();
108 double *tmp2=arr4->getPointer();
109 const double 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};
110 std::copy(arr4Ref,arr4Ref+14,tmp2);
111 CPPUNIT_ASSERT_EQUAL(7,arr4->getNumberOfTuples());
112 CPPUNIT_ASSERT_EQUAL(2,arr4->getNumberOfComponents());
113 CPPUNIT_ASSERT(std::equal(arr4Ref,arr4Ref+14,arr4->getConstPointer()));
114 DataArrayDouble *arr5=arr4->substr(3);
115 CPPUNIT_ASSERT_EQUAL(4,arr5->getNumberOfTuples());
116 CPPUNIT_ASSERT_EQUAL(2,arr5->getNumberOfComponents());
117 CPPUNIT_ASSERT(std::equal(arr4Ref+6,arr4Ref+14,arr5->getConstPointer()));
119 DataArrayDouble *arr6=arr4->substr(2,5);
120 CPPUNIT_ASSERT_EQUAL(3,arr6->getNumberOfTuples());
121 CPPUNIT_ASSERT_EQUAL(2,arr6->getNumberOfComponents());
122 CPPUNIT_ASSERT(std::equal(arr4Ref+4,arr4Ref+10,arr6->getConstPointer()));
127 void MEDCouplingBasicsTest1::testMesh()
129 const int nbOfCells=6;
130 const int nbOfNodes=12;
132 double coords[3*nbOfNodes]={
133 0.024155, 0.04183768725682622, -0.305, 0.04831000000000001, -1.015761910347357e-17, -0.305, 0.09662000000000001, -1.832979297858306e-18,
134 -0.305, 0.120775, 0.04183768725682623, -0.305, 0.09662000000000001, 0.08367537451365245, -0.305, 0.04831000000000001,
135 0.08367537451365246, -0.305, 0.024155, 0.04183768725682622, -0.2863, 0.04831000000000001, -1.015761910347357e-17, -0.2863,
136 0.09662000000000001, -1.832979297858306e-18, -0.2863, 0.120775, 0.04183768725682623, -0.2863, 0.09662000000000001, 0.08367537451365245,
137 -0.2863, 0.04831000000000001, 0.08367537451365246, -0.2863, };
139 int tab4[4*nbOfCells]={
140 1, 2, 8, 7, 2, 3, 9, 8, 3, 4, 10, 9, 4, 5, 11, 10, 5, 0, 6, 11,
143 MEDCouplingUMesh *mesh=MEDCouplingUMesh::New();
144 mesh->setMeshDimension(2);
145 mesh->allocateCells(8);
146 const int *curConn=tab4;
147 for(int i=0;i<nbOfCells;i++,curConn+=4)
148 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,curConn);
149 mesh->finishInsertingCells();
150 CPPUNIT_ASSERT_EQUAL(30,mesh->getNodalConnectivity()->getNbOfElems());
151 CPPUNIT_ASSERT_EQUAL(nbOfCells,mesh->getNumberOfCells());
152 //test 0 - no copy no ownership
153 DataArrayDouble *myCoords=DataArrayDouble::New();
154 myCoords->useArray(coords,false,CPP_DEALLOC,nbOfNodes,3);
155 mesh->setCoords(myCoords);
156 mesh->setCoords(myCoords);
158 CPPUNIT_ASSERT_EQUAL(nbOfCells,mesh->getNumberOfCells());
159 mesh->checkCoherency();
160 //test 1 - no copy ownership C++
161 myCoords=DataArrayDouble::New();
162 double *tmp=new double[3*nbOfNodes];
163 std::copy(coords,coords+3*nbOfNodes,tmp);
164 myCoords->useArray(tmp,true,CPP_DEALLOC,nbOfNodes,3);
165 mesh->setCoords(myCoords);
167 CPPUNIT_ASSERT_EQUAL(nbOfCells,mesh->getNumberOfCells());
168 mesh->checkCoherency();
169 //test 2 - no copy ownership C
170 myCoords=DataArrayDouble::New();
171 tmp=(double *)malloc(3*nbOfNodes*sizeof(double));
172 std::copy(coords,coords+3*nbOfNodes,tmp);
173 myCoords->useArray(tmp,true,C_DEALLOC,nbOfNodes,3);
174 mesh->setCoords(myCoords);
176 CPPUNIT_ASSERT_EQUAL(nbOfNodes,mesh->getNumberOfNodes());
177 mesh->checkCoherency();
179 myCoords=DataArrayDouble::New();
180 myCoords->alloc(nbOfNodes,3);
181 tmp=myCoords->getPointer();
182 std::copy(coords,coords+3*nbOfNodes,tmp);
183 // test 3 bis deepcopy
184 DataArrayDouble *myCoords2=DataArrayDouble::New();
185 *myCoords2=*myCoords;
186 myCoords2->decrRef();
188 mesh->setCoords(myCoords);
190 CPPUNIT_ASSERT_EQUAL(nbOfNodes,mesh->getNumberOfNodes());
191 mesh->checkCoherency();
192 CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
193 // test clone not recursively
194 MEDCouplingUMesh *mesh2=mesh->clone(false);
195 CPPUNIT_ASSERT(mesh2!=mesh);
196 mesh2->checkCoherency();
197 CPPUNIT_ASSERT_EQUAL(nbOfCells,mesh2->getNumberOfCells());
198 CPPUNIT_ASSERT_EQUAL(nbOfNodes,mesh2->getNumberOfNodes());
199 CPPUNIT_ASSERT_EQUAL(3,mesh2->getSpaceDimension());
200 CPPUNIT_ASSERT(mesh!=mesh2);
201 CPPUNIT_ASSERT(mesh->getCoords()==mesh2->getCoords());
202 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.2863,mesh2->getCoords()->getIJ(11,2),1e-14);
203 CPPUNIT_ASSERT(mesh->getNodalConnectivity()==mesh2->getNodalConnectivity());
204 CPPUNIT_ASSERT_EQUAL(3,mesh2->getNodalConnectivity()->getIJ(7,0));
205 CPPUNIT_ASSERT(mesh->getNodalConnectivityIndex()==mesh2->getNodalConnectivityIndex());
206 CPPUNIT_ASSERT_EQUAL(15,mesh2->getNodalConnectivityIndex()->getIJ(3,0));
208 // test clone not recursively
209 MEDCouplingUMesh *mesh3=mesh->clone(true);
210 CPPUNIT_ASSERT(mesh3!=mesh);
211 mesh3->checkCoherency();
212 CPPUNIT_ASSERT_EQUAL(nbOfCells,mesh3->getNumberOfCells());
213 CPPUNIT_ASSERT_EQUAL(nbOfNodes,mesh3->getNumberOfNodes());
214 CPPUNIT_ASSERT_EQUAL(3,mesh3->getSpaceDimension());
215 CPPUNIT_ASSERT(mesh!=mesh3);
216 CPPUNIT_ASSERT(mesh->getCoords()!=mesh3->getCoords());
217 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.2863,mesh3->getCoords()->getIJ(11,2),1e-14);
218 CPPUNIT_ASSERT(mesh->getNodalConnectivity()!=mesh3->getNodalConnectivity());
219 CPPUNIT_ASSERT_EQUAL(3,mesh3->getNodalConnectivity()->getIJ(7,0));
220 CPPUNIT_ASSERT(mesh->getNodalConnectivityIndex()!=mesh3->getNodalConnectivityIndex());
221 CPPUNIT_ASSERT_EQUAL(15,mesh3->getNodalConnectivityIndex()->getIJ(3,0));
223 //test 4 - Field on cells
224 MEDCouplingFieldDouble *fieldOnCells=MEDCouplingFieldDouble::New(ON_CELLS);
225 fieldOnCells->setMesh(mesh);
226 DataArrayDouble *array=DataArrayDouble::New();
227 array->alloc(nbOfCells,9);
228 fieldOnCells->setArray(array);
229 tmp=array->getPointer();
231 std::fill(tmp,tmp+9*nbOfCells,7.);
232 //content of field changed -> declare it.
233 fieldOnCells->declareAsNew();
234 fieldOnCells->checkCoherency();
235 // testing clone of fields - no recursive
236 MEDCouplingFieldDouble *fieldOnCells2=fieldOnCells->clone(false);
237 CPPUNIT_ASSERT(fieldOnCells2!=fieldOnCells);
238 fieldOnCells2->checkCoherency();
239 CPPUNIT_ASSERT_EQUAL(nbOfCells,fieldOnCells2->getNumberOfTuples());
240 CPPUNIT_ASSERT_EQUAL(9,fieldOnCells2->getNumberOfComponents());
241 CPPUNIT_ASSERT(fieldOnCells2->getArray()==fieldOnCells->getArray());
242 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,fieldOnCells2->getArray()->getIJ(3,7),1e-14);
243 CPPUNIT_ASSERT(fieldOnCells2->getMesh()==fieldOnCells->getMesh());
244 // testing clone of fields - recursive
245 MEDCouplingFieldDouble *fieldOnCells3=fieldOnCells->clone(true);
246 CPPUNIT_ASSERT(fieldOnCells3!=fieldOnCells);
247 fieldOnCells3->checkCoherency();
248 CPPUNIT_ASSERT_EQUAL(nbOfCells,fieldOnCells3->getNumberOfTuples());
249 CPPUNIT_ASSERT_EQUAL(9,fieldOnCells3->getNumberOfComponents());
250 CPPUNIT_ASSERT(fieldOnCells3->getArray()!=fieldOnCells->getArray());
251 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,fieldOnCells3->getArray()->getIJ(3,7),1e-14);
252 CPPUNIT_ASSERT(fieldOnCells3->getMesh()==fieldOnCells->getMesh());
253 fieldOnCells2->decrRef();
254 fieldOnCells3->decrRef();
256 fieldOnCells->decrRef();
261 void MEDCouplingBasicsTest1::testMeshPointsCloud()
263 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};
264 const int targetConn[]={0,1,2,3,4,5,7,6};
265 MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
266 targetMesh->setMeshDimension(0);
267 targetMesh->allocateCells(8);
268 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn);
269 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+1);
270 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+2);
271 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+3);
272 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+4);
273 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+5);
274 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+6);
275 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+7);
276 targetMesh->finishInsertingCells();
277 CPPUNIT_ASSERT_THROW(targetMesh->checkCoherency(),INTERP_KERNEL::Exception);
278 DataArrayDouble *myCoords=DataArrayDouble::New();
279 myCoords->alloc(9,3);
280 std::copy(targetCoords,targetCoords+27,myCoords->getPointer());
281 targetMesh->setCoords(myCoords);
284 targetMesh->checkCoherency();
285 CPPUNIT_ASSERT_EQUAL(3,targetMesh->getSpaceDimension());
286 CPPUNIT_ASSERT_EQUAL(8,targetMesh->getNumberOfCells());
287 CPPUNIT_ASSERT_EQUAL(9,targetMesh->getNumberOfNodes());
288 CPPUNIT_ASSERT_EQUAL(0,targetMesh->getMeshDimension());
290 targetMesh->decrRef();
293 void MEDCouplingBasicsTest1::testMeshM1D()
295 MEDCouplingUMesh *meshM1D=MEDCouplingUMesh::New();
296 CPPUNIT_ASSERT_THROW(meshM1D->getMeshDimension(),INTERP_KERNEL::Exception);
297 CPPUNIT_ASSERT_THROW(meshM1D->getNumberOfNodes(),INTERP_KERNEL::Exception);
298 CPPUNIT_ASSERT_THROW(meshM1D->getNumberOfCells(),INTERP_KERNEL::Exception);
299 CPPUNIT_ASSERT_THROW(meshM1D->setMeshDimension(-2),INTERP_KERNEL::Exception);
300 CPPUNIT_ASSERT_THROW(meshM1D->setMeshDimension(-10),INTERP_KERNEL::Exception);
301 CPPUNIT_ASSERT_THROW(meshM1D->checkCoherency(),INTERP_KERNEL::Exception);
302 meshM1D->setMeshDimension(-1);
303 meshM1D->checkCoherency();
304 CPPUNIT_ASSERT_EQUAL(-1,meshM1D->getMeshDimension());
305 CPPUNIT_ASSERT_EQUAL(1,meshM1D->getNumberOfCells());
306 CPPUNIT_ASSERT_THROW(meshM1D->getNumberOfNodes(),INTERP_KERNEL::Exception);
307 CPPUNIT_ASSERT_THROW(meshM1D->getSpaceDimension(),INTERP_KERNEL::Exception);
308 MEDCouplingUMesh *cpy=meshM1D->clone(true);
309 CPPUNIT_ASSERT(cpy->isEqual(meshM1D,1e-12));
311 MEDCouplingFieldDouble *fieldOnCells=MEDCouplingFieldDouble::New(ON_CELLS);
312 fieldOnCells->setMesh(meshM1D);
313 DataArrayDouble *array=DataArrayDouble::New();
315 fieldOnCells->setArray(array);
316 double *tmp=array->getPointer();
318 std::fill(tmp,tmp+6,7.);
319 fieldOnCells->checkCoherency();
321 fieldOnCells->decrRef();
325 void MEDCouplingBasicsTest1::testDeepCopy()
327 DataArrayDouble *array=DataArrayDouble::New();
329 std::fill(array->getPointer(),array->getPointer()+5*3,7.);
330 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,array->getIJ(3,2),1e-14);
331 double *tmp1=array->getPointer();
332 DataArrayDouble *array2=array->deepCpy();
333 double *tmp2=array2->getPointer();
334 CPPUNIT_ASSERT(tmp1!=tmp2);
336 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,array2->getIJ(3,2),1e-14);
339 DataArrayInt *array3=DataArrayInt::New();
341 std::fill(array3->getPointer(),array3->getPointer()+5*3,17);
342 CPPUNIT_ASSERT_EQUAL(17,array3->getIJ(3,2));
343 int *tmp3=array3->getPointer();
344 DataArrayInt *array4=array3->deepCpy();
345 int *tmp4=array4->getPointer();
346 CPPUNIT_ASSERT(tmp3!=tmp4);
348 CPPUNIT_ASSERT_EQUAL(17,array4->getIJ(3,2));
352 void MEDCouplingBasicsTest1::testRevNodal()
354 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
355 DataArrayInt *revNodal=DataArrayInt::New();
356 DataArrayInt *revNodalIndx=DataArrayInt::New();
358 mesh->getReverseNodalConnectivity(revNodal,revNodalIndx);
359 const int revNodalExpected[18]={0,0,1,1,2,0,3,0,1,2,3,4,2,4,3,3,4,4};
360 const int revNodalIndexExpected[10]={0,1,3,5,7,12,14,15,17,18};
361 CPPUNIT_ASSERT_EQUAL(18,revNodal->getNbOfElems());
362 CPPUNIT_ASSERT_EQUAL(10,revNodalIndx->getNbOfElems());
363 CPPUNIT_ASSERT(std::equal(revNodalExpected,revNodalExpected+18,revNodal->getPointer()));
364 CPPUNIT_ASSERT(std::equal(revNodalIndexExpected,revNodalIndexExpected+10,revNodalIndx->getPointer()));
367 revNodalIndx->decrRef();
371 void MEDCouplingBasicsTest1::testConvertToPolyTypes()
374 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
376 const int elts[2]={1,3};
377 std::vector<int> eltsV(elts,elts+2);
378 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
379 mesh->checkCoherency();
380 CPPUNIT_ASSERT_EQUAL(5,mesh->getNumberOfCells());
381 CPPUNIT_ASSERT_EQUAL(23,mesh->getNodalConnectivity()->getNumberOfTuples());
382 const int *pt=mesh->getNodalConnectivity()->getConstPointer();
383 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};
384 CPPUNIT_ASSERT(std::equal(expected1,expected1+23,pt));
388 mesh=build3DTargetMesh_1();
389 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
390 mesh->checkCoherency();
391 CPPUNIT_ASSERT_EQUAL(8,mesh->getNumberOfCells());
392 CPPUNIT_ASSERT_EQUAL(114,mesh->getNodalConnectivity()->getNumberOfTuples());
393 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
394 mesh->checkCoherency();
395 CPPUNIT_ASSERT_EQUAL(8,mesh->getNumberOfCells());
396 CPPUNIT_ASSERT_EQUAL(114,mesh->getNodalConnectivity()->getNumberOfTuples());
401 void MEDCouplingBasicsTest1::testDescConn2D()
403 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
404 DataArrayInt *desc=DataArrayInt::New();
405 DataArrayInt *descIndx=DataArrayInt::New();
406 DataArrayInt *revDesc=DataArrayInt::New();
407 DataArrayInt *revDescIndx=DataArrayInt::New();
409 MEDCouplingUMesh *mesh2=mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
410 mesh2->checkCoherency();
411 CPPUNIT_ASSERT_EQUAL(1,mesh2->getMeshDimension());
412 CPPUNIT_ASSERT_EQUAL(13,mesh2->getNumberOfCells());
413 CPPUNIT_ASSERT_EQUAL(14,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(14,revDescIndx->getNumberOfTuples());
414 CPPUNIT_ASSERT_EQUAL(6,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(6,descIndx->getNumberOfTuples());
415 CPPUNIT_ASSERT_EQUAL(18,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,desc->getNumberOfTuples());
416 CPPUNIT_ASSERT_EQUAL(18,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,revDesc->getNumberOfTuples());
417 const int expected1[18]={0,1,2,3, 2,4,5, 6,7,4, 8,9,1,10, 11,12,6,9};
418 CPPUNIT_ASSERT(std::equal(expected1,expected1+18,desc->getConstPointer()));
419 const int expected2[6]={0,4,7,10,14,18};
420 CPPUNIT_ASSERT(std::equal(expected2,expected2+6,descIndx->getConstPointer()));
421 const int expected3[14]={0,1,3,5,6,8,9,11,12,13,15,16,17,18};
422 CPPUNIT_ASSERT(std::equal(expected3,expected3+14,revDescIndx->getConstPointer()));
423 const int expected4[18]={0, 0,3, 0,1, 0, 1,2, 1, 2,4, 2, 3, 3,4, 3, 4, 4};
424 CPPUNIT_ASSERT(std::equal(expected4,expected4+18,revDesc->getConstPointer()));
425 DataArrayInt *conn=mesh2->getNodalConnectivity();
426 DataArrayInt *connIndex=mesh2->getNodalConnectivityIndex();
427 const int expected5[14]={0,3,6,9,12,15,18,21,24,27,30,33,36,39};
428 CPPUNIT_ASSERT(std::equal(expected5,expected5+14,connIndex->getConstPointer()));
429 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};
430 CPPUNIT_ASSERT(std::equal(expected6,expected6+39,conn->getConstPointer()));
435 revDescIndx->decrRef();
438 const int elts[2]={1,3};
439 std::vector<int> eltsV(elts,elts+2);
440 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
441 mesh->checkCoherency();
443 desc=DataArrayInt::New();
444 descIndx=DataArrayInt::New();
445 revDesc=DataArrayInt::New();
446 revDescIndx=DataArrayInt::New();
448 mesh2=mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
449 mesh2->checkCoherency();
450 CPPUNIT_ASSERT_EQUAL(1,mesh2->getMeshDimension());
451 CPPUNIT_ASSERT_EQUAL(13,mesh2->getNumberOfCells());
452 CPPUNIT_ASSERT_EQUAL(14,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(14,revDescIndx->getNumberOfTuples());
453 CPPUNIT_ASSERT_EQUAL(6,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(6,descIndx->getNumberOfTuples());
454 CPPUNIT_ASSERT_EQUAL(18,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,desc->getNumberOfTuples());
455 CPPUNIT_ASSERT_EQUAL(18,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,revDesc->getNumberOfTuples());
456 CPPUNIT_ASSERT(std::equal(expected1,expected1+18,desc->getConstPointer()));
457 CPPUNIT_ASSERT(std::equal(expected2,expected2+6,descIndx->getConstPointer()));
458 CPPUNIT_ASSERT(std::equal(expected3,expected3+14,revDescIndx->getConstPointer()));
459 CPPUNIT_ASSERT(std::equal(expected4,expected4+18,revDesc->getConstPointer()));
460 conn=mesh2->getNodalConnectivity();
461 connIndex=mesh2->getNodalConnectivityIndex();
462 CPPUNIT_ASSERT(std::equal(expected5,expected5+14,connIndex->getConstPointer()));
463 CPPUNIT_ASSERT(std::equal(expected6,expected6+39,conn->getConstPointer()));
468 revDescIndx->decrRef();
473 void MEDCouplingBasicsTest1::testDescConn3D()
475 MEDCouplingUMesh *mesh=build3DTargetMesh_1();
476 DataArrayInt *desc=DataArrayInt::New();
477 DataArrayInt *descIndx=DataArrayInt::New();
478 DataArrayInt *revDesc=DataArrayInt::New();
479 DataArrayInt *revDescIndx=DataArrayInt::New();
481 MEDCouplingUMesh *mesh2=mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
482 mesh2->checkCoherency();
483 CPPUNIT_ASSERT_EQUAL(2,mesh2->getMeshDimension());
484 CPPUNIT_ASSERT_EQUAL(36,mesh2->getNumberOfCells());
485 CPPUNIT_ASSERT_EQUAL(37,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(37,revDescIndx->getNumberOfTuples());
486 CPPUNIT_ASSERT_EQUAL(9,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(9,descIndx->getNumberOfTuples());
487 CPPUNIT_ASSERT_EQUAL(48,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,desc->getNumberOfTuples());
488 CPPUNIT_ASSERT_EQUAL(48,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,revDesc->getNumberOfTuples());
489 const int expected1[9]={0, 6, 12, 18, 24, 30, 36, 42, 48};
490 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};
491 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};
492 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};
493 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};
494 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,
495 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,
496 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,
497 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};
498 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,
499 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,
500 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,
501 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};
503 CPPUNIT_ASSERT(std::equal(expected1,expected1+9,descIndx->getConstPointer()));
504 CPPUNIT_ASSERT(std::equal(expected2,expected2+48,desc->getConstPointer()));
505 CPPUNIT_ASSERT(std::equal(expected3,expected3+37,revDescIndx->getConstPointer()));
506 CPPUNIT_ASSERT(std::equal(expected4,expected4+48,revDesc->getConstPointer()));
507 CPPUNIT_ASSERT(std::equal(expected5,expected5+37,mesh2->getNodalConnectivityIndex()->getConstPointer()));
508 CPPUNIT_ASSERT(std::equal(expected6,expected6+180,mesh2->getNodalConnectivity()->getConstPointer()));
513 revDescIndx->decrRef();
516 const int elts[2]={1,3};
517 std::vector<int> eltsV(elts,elts+2);
518 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
519 mesh->checkCoherency();
520 desc=DataArrayInt::New();
521 descIndx=DataArrayInt::New();
522 revDesc=DataArrayInt::New();
523 revDescIndx=DataArrayInt::New();
524 mesh2=mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
525 mesh2->checkCoherency();
526 CPPUNIT_ASSERT_EQUAL(2,mesh2->getMeshDimension());
527 CPPUNIT_ASSERT_EQUAL(36,mesh2->getNumberOfCells());
528 CPPUNIT_ASSERT_EQUAL(37,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(37,revDescIndx->getNumberOfTuples());
529 CPPUNIT_ASSERT_EQUAL(9,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(9,descIndx->getNumberOfTuples());
530 CPPUNIT_ASSERT_EQUAL(48,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,desc->getNumberOfTuples());
531 CPPUNIT_ASSERT_EQUAL(48,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,revDesc->getNumberOfTuples());
532 CPPUNIT_ASSERT(std::equal(expected1,expected1+9,descIndx->getConstPointer()));
533 CPPUNIT_ASSERT(std::equal(expected2,expected2+48,desc->getConstPointer()));
534 CPPUNIT_ASSERT(std::equal(expected3,expected3+37,revDescIndx->getConstPointer()));
535 CPPUNIT_ASSERT(std::equal(expected4,expected4+48,revDesc->getConstPointer()));
536 CPPUNIT_ASSERT(std::equal(expected5,expected5+37,mesh2->getNodalConnectivityIndex()->getConstPointer()));
537 CPPUNIT_ASSERT(std::equal(expected7,expected7+180,mesh2->getNodalConnectivity()->getConstPointer()));
542 revDescIndx->decrRef();
547 void MEDCouplingBasicsTest1::testFindBoundaryNodes()
549 MEDCouplingUMesh *mesh=build3DTargetMesh_1();
550 DataArrayInt *boundaryNodes=mesh->findBoundaryNodes();
551 CPPUNIT_ASSERT_EQUAL(26,boundaryNodes->getNumberOfTuples());
552 CPPUNIT_ASSERT_EQUAL(1,boundaryNodes->getNumberOfComponents());
553 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};
554 CPPUNIT_ASSERT(std::equal(expected1,expected1+26,boundaryNodes->begin()));
555 boundaryNodes->decrRef();
559 void MEDCouplingBasicsTest1::testBoundaryMesh()
561 MEDCouplingUMesh *mesh=build3DTargetMesh_1();
562 MEDCouplingPointSet *mesh2=mesh->buildBoundaryMesh(false);
563 CPPUNIT_ASSERT_EQUAL(24,mesh2->getNumberOfCells());
564 CPPUNIT_ASSERT_EQUAL(26,mesh2->getNumberOfNodes());
569 void MEDCouplingBasicsTest1::testBuildPartOfMySelf()
571 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
572 mesh->setName("Toto");
573 const int tab1[2]={0,4};
574 const int tab2[3]={0,2,3};
576 MEDCouplingPointSet *subMeshSimple=mesh->buildPartOfMySelf(tab1,tab1+2,true);
577 MEDCouplingUMesh *subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
578 CPPUNIT_ASSERT(subMesh);
579 std::string name(subMesh->getName());
580 CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllTypes().size());
581 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*mesh->getAllTypes().begin());
582 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++(mesh->getAllTypes().begin())));
583 CPPUNIT_ASSERT_EQUAL(1,(int)subMesh->getAllTypes().size());
584 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllTypes().begin());
585 CPPUNIT_ASSERT(name=="Toto");
586 CPPUNIT_ASSERT(mesh->getCoords()==subMesh->getCoords());
587 CPPUNIT_ASSERT_EQUAL(2,subMesh->getNumberOfCells());
588 const int subConn[10]={4,0,3,4,1,4,7,8,5,4};
589 const int subConnIndex[3]={0,5,10};
590 CPPUNIT_ASSERT_EQUAL(10,subMesh->getNodalConnectivity()->getNbOfElems());
591 CPPUNIT_ASSERT_EQUAL(3,subMesh->getNodalConnectivityIndex()->getNbOfElems());
592 CPPUNIT_ASSERT(std::equal(subConn,subConn+10,subMesh->getNodalConnectivity()->getPointer()));
593 CPPUNIT_ASSERT(std::equal(subConnIndex,subConnIndex+3,subMesh->getNodalConnectivityIndex()->getPointer()));
596 subMeshSimple=mesh->buildPartOfMySelf(tab2,tab2+3,true);
597 subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
598 CPPUNIT_ASSERT(subMesh);
599 name=subMesh->getName();
600 CPPUNIT_ASSERT_EQUAL(2,(int)subMesh->getAllTypes().size());
601 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*subMesh->getAllTypes().begin());
602 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++(subMesh->getAllTypes().begin())));
603 CPPUNIT_ASSERT(name=="Toto");
604 CPPUNIT_ASSERT(mesh->getCoords()==subMesh->getCoords());
605 CPPUNIT_ASSERT_EQUAL(3,subMesh->getNumberOfCells());
606 const int subConn2[14]={4,0,3,4,1,3,4,5,2,4,6,7,4,3};
607 const int subConnIndex2[4]={0,5,9,14};
608 CPPUNIT_ASSERT_EQUAL(14,subMesh->getNodalConnectivity()->getNbOfElems());
609 CPPUNIT_ASSERT_EQUAL(4,subMesh->getNodalConnectivityIndex()->getNbOfElems());
610 CPPUNIT_ASSERT(std::equal(subConn2,subConn2+14,subMesh->getNodalConnectivity()->getPointer()));
611 CPPUNIT_ASSERT(std::equal(subConnIndex2,subConnIndex2+4,subMesh->getNodalConnectivityIndex()->getPointer()));
612 const int tab3[3]={0,1,2};
613 MEDCouplingPointSet *subMeshSimple2=subMeshSimple->buildPartOfMySelf(tab3,tab3+3,true);
615 name=subMeshSimple2->getName();
616 CPPUNIT_ASSERT(name=="Toto");
617 subMeshSimple2->decrRef();
622 void MEDCouplingBasicsTest1::testBuildPartOfMySelfNode()
624 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
625 const int tab1[4]={5,7,8,4};
626 MEDCouplingPointSet *subMeshSimple=mesh->buildPartOfMySelfNode(tab1,tab1+4,true);
627 MEDCouplingUMesh *subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
628 CPPUNIT_ASSERT(subMesh);
629 CPPUNIT_ASSERT_EQUAL(1,(int)subMesh->getAllTypes().size());
630 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllTypes().begin());
631 CPPUNIT_ASSERT_EQUAL(1,subMesh->getNumberOfCells());
632 CPPUNIT_ASSERT_EQUAL(5,subMesh->getNodalConnectivity()->getNbOfElems());
633 CPPUNIT_ASSERT_EQUAL(2,subMesh->getNodalConnectivityIndex()->getNbOfElems());
634 const int subConn[5]={4,7,8,5,4};
635 const int subConnIndex[3]={0,5};
636 CPPUNIT_ASSERT(std::equal(subConn,subConn+5,subMesh->getNodalConnectivity()->getPointer()));
637 CPPUNIT_ASSERT(std::equal(subConnIndex,subConnIndex+2,subMesh->getNodalConnectivityIndex()->getPointer()));
638 CPPUNIT_ASSERT(subMesh->getCoords()==mesh->getCoords());
639 subMeshSimple->decrRef();
641 subMeshSimple=mesh->buildPartOfMySelfNode(tab1,tab1+2,false);
642 subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
643 CPPUNIT_ASSERT(subMesh);
644 CPPUNIT_ASSERT_EQUAL(2,(int)subMesh->getAllTypes().size());
645 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*subMesh->getAllTypes().begin());
646 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++subMesh->getAllTypes().begin()));
647 CPPUNIT_ASSERT_EQUAL(3,subMesh->getNumberOfCells());
648 CPPUNIT_ASSERT_EQUAL(14,subMesh->getNodalConnectivity()->getNbOfElems());
649 CPPUNIT_ASSERT_EQUAL(4,subMesh->getNodalConnectivityIndex()->getNbOfElems());
650 const int subConn2[14]={3,4,5,2,4,6,7,4,3,4,7,8,5,4};
651 const int subConnIndex2[4]={0,4,9,14};
652 CPPUNIT_ASSERT(std::equal(subConn2,subConn2+14,subMesh->getNodalConnectivity()->getPointer()));
653 CPPUNIT_ASSERT(std::equal(subConnIndex2,subConnIndex2+4,subMesh->getNodalConnectivityIndex()->getPointer()));
654 CPPUNIT_ASSERT(subMesh->getCoords()==mesh->getCoords());
655 subMeshSimple->decrRef();
656 //testing the case where length of tab2 is greater than max number of node per cell.
657 const int tab2[7]={0,3,2,1,4,5,6};
658 subMeshSimple=mesh->buildPartOfMySelfNode(tab2,tab2+7,true);
659 subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
660 CPPUNIT_ASSERT(subMesh);
661 CPPUNIT_ASSERT_EQUAL(2,(int)subMesh->getAllTypes().size());
662 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*subMesh->getAllTypes().begin());
663 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++subMesh->getAllTypes().begin()));
664 CPPUNIT_ASSERT_EQUAL(3,subMesh->getNumberOfCells());
665 subMeshSimple->decrRef();
670 void MEDCouplingBasicsTest1::testZipCoords()
672 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
673 CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllTypes().size());
674 CPPUNIT_ASSERT_EQUAL(2,mesh->getSpaceDimension());
675 CPPUNIT_ASSERT_EQUAL(9,mesh->getNumberOfNodes());
676 CPPUNIT_ASSERT_EQUAL(5,mesh->getNumberOfCells());
677 std::vector<int> oldConn(mesh->getNodalConnectivity()->getNbOfElems());
678 std::vector<int> oldConnIndex(mesh->getNumberOfCells()+1);
679 std::copy(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+oldConn.size(),oldConn.begin());
680 std::copy(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+mesh->getNumberOfCells()+1,oldConnIndex.begin());
681 DataArrayDouble *oldCoords=mesh->getCoords();
682 oldCoords->incrRef();
684 CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllTypes().size());
685 CPPUNIT_ASSERT_EQUAL(2,mesh->getSpaceDimension());
686 CPPUNIT_ASSERT_EQUAL(9,mesh->getNumberOfNodes());
687 CPPUNIT_ASSERT_EQUAL(5,mesh->getNumberOfCells());
688 CPPUNIT_ASSERT(mesh->getCoords()!=oldCoords);
689 CPPUNIT_ASSERT(std::equal(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+2*9,oldCoords->getPointer()));
690 CPPUNIT_ASSERT(std::equal(oldConn.begin(),oldConn.end(),mesh->getNodalConnectivity()->getPointer()));
691 CPPUNIT_ASSERT(std::equal(oldConnIndex.begin(),oldConnIndex.end(),mesh->getNodalConnectivityIndex()->getPointer()));
692 oldCoords->decrRef();
694 const int tab1[2]={0,4};
695 MEDCouplingPointSet *subMeshPtSet=mesh->buildPartOfMySelf(tab1,tab1+2,true);
696 MEDCouplingUMesh *subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshPtSet);
697 CPPUNIT_ASSERT(subMesh);
698 DataArrayInt *traducer=subMesh->zipCoordsTraducer();
699 const int expectedTraducer[9]={0,1,-1,2,3,4,-1,5,6};
700 CPPUNIT_ASSERT(std::equal(expectedTraducer,expectedTraducer+9,traducer->getPointer()));
702 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllTypes().begin());
703 CPPUNIT_ASSERT_EQUAL(2,subMesh->getNumberOfCells());
704 const int subConn[10]={4,0,2,3,1,4,5,6,4,3};
705 const int subConnIndex[3]={0,5,10};
706 CPPUNIT_ASSERT_EQUAL(7,subMesh->getNumberOfNodes());
707 CPPUNIT_ASSERT_EQUAL(10,subMesh->getNodalConnectivity()->getNbOfElems());
708 CPPUNIT_ASSERT_EQUAL(3,subMesh->getNodalConnectivityIndex()->getNbOfElems());
709 CPPUNIT_ASSERT(std::equal(subConn,subConn+10,subMesh->getNodalConnectivity()->getPointer()));
710 CPPUNIT_ASSERT(std::equal(subConnIndex,subConnIndex+3,subMesh->getNodalConnectivityIndex()->getPointer()));
713 subMeshPtSet=mesh->buildPartOfMySelf(tab1,tab1+2,false);
714 subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshPtSet);
715 CPPUNIT_ASSERT(subMesh);
716 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllTypes().begin());
717 CPPUNIT_ASSERT_EQUAL(2,subMesh->getNumberOfCells());
718 CPPUNIT_ASSERT_EQUAL(7,subMesh->getNumberOfNodes());
719 CPPUNIT_ASSERT_EQUAL(10,subMesh->getNodalConnectivity()->getNbOfElems());
720 CPPUNIT_ASSERT_EQUAL(3,subMesh->getNodalConnectivityIndex()->getNbOfElems());
721 CPPUNIT_ASSERT(std::equal(subConn,subConn+10,subMesh->getNodalConnectivity()->getPointer()));
722 CPPUNIT_ASSERT(std::equal(subConnIndex,subConnIndex+3,subMesh->getNodalConnectivityIndex()->getPointer()));
728 void MEDCouplingBasicsTest1::testZipConnectivity()
730 MEDCouplingUMesh *m1=build2DTargetMesh_1();
731 MEDCouplingUMesh *m2=build2DTargetMesh_1();
732 int cells1[3]={2,3,4};
733 MEDCouplingPointSet *m3_1=m2->buildPartOfMySelf(cells1,cells1+3,true);
734 MEDCouplingUMesh *m3=dynamic_cast<MEDCouplingUMesh *>(m3_1);
737 MEDCouplingUMesh *m4=build2DSourceMesh_1();
738 MEDCouplingUMesh *m5=MEDCouplingUMesh::MergeUMeshes(m1,m3);
741 MEDCouplingUMesh *m6=MEDCouplingUMesh::MergeUMeshes(m5,m4);
747 CPPUNIT_ASSERT_EQUAL(10,m6->getNumberOfCells());
748 CPPUNIT_ASSERT_EQUAL(22,m6->getNumberOfNodes());
749 DataArrayInt *arr=m6->mergeNodes(1e-13,areNodesMerged,newNbOfNodes);
751 CPPUNIT_ASSERT(areNodesMerged);
752 CPPUNIT_ASSERT_EQUAL(10,m6->getNumberOfCells());
753 CPPUNIT_ASSERT_EQUAL(9,m6->getNumberOfNodes());
754 CPPUNIT_ASSERT_EQUAL(9,newNbOfNodes);
756 arr=m6->zipConnectivityTraducer(0);
757 CPPUNIT_ASSERT_EQUAL(7,m6->getNumberOfCells());
759 MEDCouplingUMesh *m7=m6->clone(true);
760 arr=m6->zipConnectivityTraducer(0);
761 CPPUNIT_ASSERT(m7->isEqual(m6,1e-12));
762 CPPUNIT_ASSERT_EQUAL(7,m6->getNumberOfCells());
769 void MEDCouplingBasicsTest1::testEqualMesh()
771 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
772 MEDCouplingUMesh *mesh2=build2DTargetMesh_1();
774 CPPUNIT_ASSERT(mesh1->isEqual(mesh1,1e-12));
776 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
777 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
778 double *pt=mesh2->getCoords()->getPointer();
781 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
782 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
784 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
785 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
787 int *pt2=mesh1->getNodalConnectivity()->getPointer();
789 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
790 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
792 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
793 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
795 pt2=mesh1->getNodalConnectivityIndex()->getPointer();
797 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
798 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
800 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
801 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
803 std::string tmp3=mesh1->getName();
804 mesh1->setName("lllll");
805 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
806 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
807 mesh1->setName(tmp3.c_str());
808 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
809 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
811 tmp3=mesh2->getCoords()->getInfoOnComponent(1);
812 mesh2->getCoords()->setInfoOnComponent(1,"kkkkkk");
813 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
814 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
815 mesh2->getCoords()->setInfoOnComponent(1,tmp3.c_str());
816 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
817 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
823 void MEDCouplingBasicsTest1::testEqualFieldDouble()
825 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
826 MEDCouplingUMesh *mesh2=build2DTargetMesh_1();
828 MEDCouplingFieldDouble *fieldOnCells1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
829 fieldOnCells1->setMesh(mesh1);
830 MEDCouplingFieldDouble *fieldOnCells2=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
831 fieldOnCells2->setMesh(mesh2);
833 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
834 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
835 fieldOnCells2->decrRef();
837 MEDCouplingFieldDouble *fieldOnNodes1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
838 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnNodes1,1e-12,1e-15));
839 CPPUNIT_ASSERT(!fieldOnNodes1->isEqual(fieldOnCells1,1e-12,1e-15));
840 fieldOnNodes1->decrRef();
842 fieldOnCells2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
843 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
844 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
845 fieldOnCells1->decrRef();
846 fieldOnCells1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
847 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
848 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
849 fieldOnCells1->setTime(4.,6,7);
850 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
851 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
852 fieldOnCells2->setTime(4.,6,7);
853 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
854 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
855 fieldOnCells1->setName("Power");
856 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
857 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
858 fieldOnCells2->setName("Power");
859 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
860 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
862 fieldOnCells1->setMesh(mesh1);
863 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
864 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
865 fieldOnCells2->setMesh(mesh1);
866 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
867 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
868 DataArrayDouble *arr=DataArrayDouble::New();
869 arr->setName("popo");
870 arr->alloc(mesh1->getNumberOfCells(),3);
871 double *pt=arr->getPointer();
872 std::fill(pt,pt+mesh1->getNumberOfCells()*3,6.);
873 fieldOnCells1->setArray(arr);
874 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
875 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
876 fieldOnCells2->setArray(arr);
878 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
879 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
881 DataArrayDouble *arr2=arr->deepCpy();
882 fieldOnCells2->setArray(arr2);
884 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
885 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
887 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
888 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
890 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
891 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
892 arr2->setName("popo2");
893 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
894 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
896 arr2->setName("popo");
897 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
898 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
900 arr2->setInfoOnComponent(2,"jjj");
901 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
902 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
903 arr->setInfoOnComponent(2,"jjj");
904 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
905 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
907 fieldOnCells1->decrRef();
908 fieldOnCells2->decrRef();
914 void MEDCouplingBasicsTest1::testNatureChecking()
916 MEDCouplingFieldDouble *field=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
917 field->setNature(Integral);
918 field->setNature(ConservativeVolumic);
919 field->setNature(IntegralGlobConstraint);
921 field=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
922 field->setNature(ConservativeVolumic);
923 CPPUNIT_ASSERT_THROW(field->setNature(Integral),INTERP_KERNEL::Exception);
924 CPPUNIT_ASSERT_THROW(field->setNature(IntegralGlobConstraint),INTERP_KERNEL::Exception);
928 void MEDCouplingBasicsTest1::testBuildSubMeshData()
930 MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
931 //check buildSubMesh on field on cells
932 MEDCouplingFieldDouble *fieldCells=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
933 fieldCells->setMesh(targetMesh);
934 const int elts[3]={1,2,4};
936 MEDCouplingMesh *ret1=fieldCells->buildSubMeshData(elts,elts+3,di);
937 CPPUNIT_ASSERT_EQUAL(3,ret1->getNumberOfCells());
938 CPPUNIT_ASSERT_EQUAL(9,ret1->getNumberOfNodes());
939 CPPUNIT_ASSERT_EQUAL(3,di->getNumberOfTuples());
940 CPPUNIT_ASSERT_EQUAL(1,di->getNumberOfComponents());
941 const int *toCheck=di->getConstPointer();
942 CPPUNIT_ASSERT(std::equal(elts,elts+3,toCheck));
943 MEDCouplingUMesh *ret1DC=dynamic_cast<MEDCouplingUMesh *>(ret1);
944 CPPUNIT_ASSERT(ret1DC);
947 fieldCells->decrRef();
948 //check buildSubMesh on field on nodes
949 MEDCouplingFieldDouble *fieldNodes=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
950 fieldNodes->setMesh(targetMesh);
951 MEDCouplingMesh *ret2=fieldNodes->buildSubMeshData(elts,elts+3,di);
952 MEDCouplingUMesh *ret2DC=dynamic_cast<MEDCouplingUMesh *>(ret2);
953 CPPUNIT_ASSERT(ret2DC);
954 CPPUNIT_ASSERT_EQUAL(3,ret2->getNumberOfCells());
955 CPPUNIT_ASSERT_EQUAL(6,ret2->getNumberOfNodes());
956 CPPUNIT_ASSERT_EQUAL(6,di->getNumberOfTuples());
957 CPPUNIT_ASSERT_EQUAL(1,di->getNumberOfComponents());
958 toCheck=di->getConstPointer();
959 const int expected[6]={1,2,4,5,7,8};
960 CPPUNIT_ASSERT(std::equal(expected,expected+6,toCheck));
963 fieldNodes->decrRef();
964 targetMesh->decrRef();
967 void MEDCouplingBasicsTest1::testExtrudedMesh1()
969 MEDCouplingUMesh *mesh2D=0;
970 MEDCouplingUMesh *mesh3D=build3DExtrudedUMesh_1(mesh2D);
971 MEDCouplingExtrudedMesh *ext=MEDCouplingExtrudedMesh::New(mesh3D,mesh2D,1);
972 CPPUNIT_ASSERT_EQUAL(18,ext->getNumberOfCells());
973 CPPUNIT_ASSERT_EQUAL(60,ext->getNumberOfNodes());
974 DataArrayInt *ids3D=ext->getMesh3DIds();
975 const int ids3DExpected[18]={5,4,3,2,1,0, 11,10,9,8,7,6, 17,16,15,14,13,12};
976 CPPUNIT_ASSERT_EQUAL(18,ids3D->getNumberOfTuples());
977 CPPUNIT_ASSERT_EQUAL(1,ids3D->getNumberOfComponents());
978 CPPUNIT_ASSERT(std::equal(ids3DExpected,ids3DExpected+18,ids3D->getConstPointer()));
979 MEDCouplingUMesh *mesh1D=ext->getMesh1D();
980 CPPUNIT_ASSERT_EQUAL(4,mesh1D->getNumberOfNodes());
981 CPPUNIT_ASSERT_EQUAL(3,mesh1D->getNumberOfCells());
982 const double mesh1DExpected[12]={0.66666666666666663, 1.4583333333333333, 0, 0.66666666666666663, 1.4583333333333333, 1, 0.66666666666666663, 1.4583333333333333, 2, 0.66666666666666663, 1.4583333333333333, 3};
983 DataArrayDouble *mesh1DCoords=mesh1D->getCoords();
984 CPPUNIT_ASSERT_EQUAL(4,mesh1DCoords->getNumberOfTuples());
985 CPPUNIT_ASSERT_EQUAL(3,mesh1DCoords->getNumberOfComponents());
986 CPPUNIT_ASSERT(std::equal(mesh1DExpected,mesh1DExpected+12,mesh1DCoords->getConstPointer()));
987 DataArrayInt *conn1D=mesh1D->getNodalConnectivity();
988 CPPUNIT_ASSERT_EQUAL(9,conn1D->getNumberOfTuples());
989 CPPUNIT_ASSERT_EQUAL(1,conn1D->getNumberOfComponents());
990 const int conn1DExpected[9]={1,0,1,1,1,2,1,2,3};
991 CPPUNIT_ASSERT(std::equal(conn1DExpected,conn1DExpected+9,conn1D->getConstPointer()));
997 void MEDCouplingBasicsTest1::testExtrudedMesh2()
999 MEDCouplingUMesh *mN,*mTT,*mTF;
1000 build3DExtrudedUMesh_2(mN,mTT,mTF);
1004 DataArrayInt *da=mTT->mergeNodes(1e-12,b,newNbOfNodes);
1008 double pt[3]={300.,300.,0.};
1009 double v[3]={0.,0.,2.};
1010 mTT->findNodesOnPlane(pt,v,1e-12,n);
1011 CPPUNIT_ASSERT_EQUAL(43,(int)n.size());
1012 MEDCouplingUMesh *mTT3dSurf=(MEDCouplingUMesh *)mTT->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
1013 MEDCouplingExtrudedMesh *meTT=MEDCouplingExtrudedMesh::New(mTT,mTT3dSurf,0);
1014 CPPUNIT_ASSERT_EQUAL(200,meTT->getNumberOfCells());
1015 CPPUNIT_ASSERT_EQUAL(10,meTT->getMesh2D()->getNumberOfCells());
1016 CPPUNIT_ASSERT_EQUAL(20,meTT->getMesh1D()->getNumberOfCells());
1017 mTT3dSurf->decrRef();
1020 da=mN->mergeNodes(1e-12,b,newNbOfNodes);
1024 mN->findNodesOnPlane(pt,v,1e-12,n);
1025 CPPUNIT_ASSERT_EQUAL(30,(int)n.size());
1026 MEDCouplingUMesh *mN3dSurf=(MEDCouplingUMesh *)mN->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
1027 MEDCouplingExtrudedMesh *meN=MEDCouplingExtrudedMesh::New(mN,mN3dSurf,0);
1028 CPPUNIT_ASSERT_EQUAL(40,meN->getNumberOfCells());
1029 CPPUNIT_ASSERT_EQUAL(20,meN->getMesh2D()->getNumberOfCells());
1030 CPPUNIT_ASSERT_EQUAL(2,meN->getMesh1D()->getNumberOfCells());
1031 mN3dSurf->decrRef();
1034 da=mTF->mergeNodes(1e-12,b,newNbOfNodes);
1038 mTF->findNodesOnPlane(pt,v,1e-12,n);
1039 CPPUNIT_ASSERT_EQUAL(27,(int)n.size());
1040 MEDCouplingUMesh *mTF3dSurf=(MEDCouplingUMesh *)mTF->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
1041 MEDCouplingExtrudedMesh *meTF=MEDCouplingExtrudedMesh::New(mTF,mTF3dSurf,0);
1042 CPPUNIT_ASSERT_EQUAL(340,meTF->getNumberOfCells());
1043 CPPUNIT_ASSERT_EQUAL(17,meTF->getMesh2D()->getNumberOfCells());
1044 CPPUNIT_ASSERT_EQUAL(20,meTF->getMesh1D()->getNumberOfCells());
1045 mTF3dSurf->decrRef();
1057 * This test check MEDCouplingUMesh::buildExtrudedMesh method.
1059 void MEDCouplingBasicsTest1::testExtrudedMesh3()
1061 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1062 m1->changeSpaceDimension(3);
1063 MEDCouplingUMesh *m2=buildCU1DMesh_U();
1064 m2->changeSpaceDimension(3);
1065 double center[3]={0.,0.,0.};
1066 double vector[3]={0,1,0};
1067 m2->rotate(center,vector,-M_PI/2.);
1068 MEDCouplingUMesh *m3=m1->buildExtrudedMesh(m2,0);
1070 MEDCouplingExtrudedMesh *m4=MEDCouplingExtrudedMesh::New(m3,m1,0);
1071 CPPUNIT_ASSERT_EQUAL(15,m4->getNumberOfCells());
1072 CPPUNIT_ASSERT_EQUAL(5,m4->getMesh2D()->getNumberOfCells());
1073 CPPUNIT_ASSERT_EQUAL(3,m4->getMesh1D()->getNumberOfCells());
1074 const int *m3DIds=m4->getMesh3DIds()->getConstPointer();
1075 for(int i=0;i<15;i++)
1076 CPPUNIT_ASSERT_EQUAL(i,m3DIds[i]);
1078 //some random in cells to check that extrusion alg find it correctly
1079 const int expected1[15]={1,3,2,0,6,5,7,10,11,8,12,9,14,13,4};
1080 m3->renumberCells(expected1,false);
1081 m4=MEDCouplingExtrudedMesh::New(m3,m1,0);
1082 CPPUNIT_ASSERT_EQUAL(15,m4->getNumberOfCells());
1083 CPPUNIT_ASSERT_EQUAL(5,m4->getMesh2D()->getNumberOfCells());
1084 CPPUNIT_ASSERT_EQUAL(3,m4->getMesh1D()->getNumberOfCells());
1085 m3DIds=m4->getMesh3DIds()->getConstPointer();
1086 for(int i=0;i<15;i++)
1087 CPPUNIT_ASSERT_EQUAL(expected1[i],m3DIds[i]);
1090 //play with polygons and polyedrons
1091 std::vector<int> cells(2); cells[0]=2; cells[1]=3;
1092 m1->convertToPolyTypes(&cells[0],&cells[0]+cells.size());
1093 m3=m1->buildExtrudedMesh(m2,0);
1094 CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_HEXA8,(int)m3->getTypeOfCell(0));
1095 CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_PENTA6,(int)m3->getTypeOfCell(1));
1096 CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_POLYHED,(int)m3->getTypeOfCell(2));
1097 CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_POLYHED,(int)m3->getTypeOfCell(3));
1098 CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_HEXA8,(int)m3->getTypeOfCell(4));
1099 m3->renumberCells(expected1,false);
1100 m4=MEDCouplingExtrudedMesh::New(m3,m1,0);
1101 CPPUNIT_ASSERT_EQUAL(15,m4->getNumberOfCells());
1102 CPPUNIT_ASSERT_EQUAL(5,m4->getMesh2D()->getNumberOfCells());
1103 CPPUNIT_ASSERT_EQUAL(3,m4->getMesh1D()->getNumberOfCells());
1104 m3DIds=m4->getMesh3DIds()->getConstPointer();
1105 for(int i=0;i<15;i++)
1106 CPPUNIT_ASSERT_EQUAL(expected1[i],m3DIds[i]);
1115 * This test check MEDCouplingUMesh::buildExtrudedMesh method, but also, MEDCouplingExtrudedMesh following methods :
1116 * getCellContainingPoint getMeasureField getNodeIdsOfCell getCoordinateOfNode getTypeOfCell build3DUnstructuredMesh.
1118 void MEDCouplingBasicsTest1::testExtrudedMesh4()
1120 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1121 std::vector<int> cells(2); cells[0]=2; cells[1]=4;
1122 m1->convertToPolyTypes(&cells[0],&cells[0]+cells.size());
1123 m1->changeSpaceDimension(3);
1124 MEDCouplingUMesh *m2=buildCU1DMesh_U();
1125 m2->changeSpaceDimension(3);
1126 double center[3]={0.,0.,0.};
1127 double vector[3]={0.,1.,0.};
1128 m2->rotate(center,vector,-M_PI/2.);
1129 MEDCouplingUMesh *m3=m1->buildExtrudedMesh(m2,0);
1130 const int expected1[15]= {1,3,2,0,6,5,7,10,11,8,12,9,14,13,4};
1131 const int rexpected1[15]={3, 0, 2, 1, 14, 5, 4, 6, 9, 11, 7, 8, 10, 13, 12};
1132 m3->renumberCells(expected1,false);
1133 MEDCouplingExtrudedMesh *m4=MEDCouplingExtrudedMesh::New(m3,m1,0);
1134 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,m4->getTypeOfCell(0));
1135 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,m4->getTypeOfCell(1));
1136 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYHED,m4->getTypeOfCell(2));
1137 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_PENTA6,m4->getTypeOfCell(7));
1138 MEDCouplingFieldDouble *f=m4->getMeasureField(true);
1139 DataArrayDouble *arr=f->getArray();
1140 CPPUNIT_ASSERT_EQUAL(15,arr->getNumberOfTuples());
1141 CPPUNIT_ASSERT_EQUAL(1,arr->getNumberOfComponents());
1142 const double *arrPtr=arr->getConstPointer();
1143 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};
1144 for(int i=0;i<15;i++)
1145 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[rexpected1[i]],arrPtr[i],1e-16);
1147 MEDCouplingUMesh *m5=m4->build3DUnstructuredMesh();
1148 CPPUNIT_ASSERT(m5->isEqual(m3,1e-12));
1149 f=m5->getMeasureField(true);
1151 arrPtr=arr->getConstPointer();
1152 for(int i=0;i<15;i++)
1153 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[rexpected1[i]],arrPtr[i],1e-16);
1163 void MEDCouplingBasicsTest1::testFindCommonNodes()
1165 DataArrayInt *comm,*commI;
1166 MEDCouplingUMesh *targetMesh=build3DTargetMesh_1();
1167 targetMesh->findCommonNodes(1e-10,-1,comm,commI);
1168 CPPUNIT_ASSERT_EQUAL(1,commI->getNumberOfTuples());
1169 CPPUNIT_ASSERT_EQUAL(0,comm->getNumberOfTuples());
1171 DataArrayInt *o2n=targetMesh->buildNewNumberingFromCommonNodesFormat(comm,commI,newNbOfNodes);
1172 CPPUNIT_ASSERT_EQUAL(27,newNbOfNodes);
1173 CPPUNIT_ASSERT_EQUAL(27,o2n->getNumberOfTuples());
1174 const int o2nExp1[27]=
1176 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
1179 CPPUNIT_ASSERT(std::equal(o2nExp1,o2nExp1+27,o2n->getConstPointer()));
1183 targetMesh->decrRef();
1185 targetMesh=build3DTargetMeshMergeNode_1();
1186 CPPUNIT_ASSERT_EQUAL(31,targetMesh->getNumberOfNodes());
1187 targetMesh->findCommonNodes(1e-10,-1,comm,commI);
1188 CPPUNIT_ASSERT_EQUAL(3,commI->getNumberOfTuples());
1189 CPPUNIT_ASSERT_EQUAL(6,comm->getNumberOfTuples());
1190 const int commExpected[6]={1,27,28,29,23,30};
1191 const int commIExpected[3]={0,4,6};
1192 CPPUNIT_ASSERT(std::equal(commExpected,commExpected+6,comm->getConstPointer()));
1193 CPPUNIT_ASSERT(std::equal(commIExpected,commIExpected+3,commI->getConstPointer()));
1194 o2n=targetMesh->buildNewNumberingFromCommonNodesFormat(comm,commI,newNbOfNodes);
1195 CPPUNIT_ASSERT_EQUAL(31,o2n->getNumberOfTuples());
1196 CPPUNIT_ASSERT_EQUAL(27,newNbOfNodes);
1197 const int o2nExp2[31]=
1199 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
1200 21,22,23,24,25,26,1,1,1,23
1202 CPPUNIT_ASSERT(std::equal(o2nExp2,o2nExp2+31,o2n->getConstPointer()));
1206 targetMesh->decrRef();
1208 targetMesh=build3DTargetMesh_1();
1209 bool areNodesMerged;
1210 unsigned int time=targetMesh->getTimeOfThis();
1211 o2n=targetMesh->mergeNodes(1e-10,areNodesMerged,newNbOfNodes);
1212 targetMesh->updateTime();
1213 CPPUNIT_ASSERT(time==targetMesh->getTimeOfThis());
1214 CPPUNIT_ASSERT(!areNodesMerged);
1215 targetMesh->decrRef();
1218 targetMesh=build3DTargetMeshMergeNode_1();
1219 time=targetMesh->getTimeOfThis();
1220 o2n=targetMesh->mergeNodes(1e-10,areNodesMerged,newNbOfNodes);
1221 targetMesh->updateTime();
1222 CPPUNIT_ASSERT(time!=targetMesh->getTimeOfThis());
1223 CPPUNIT_ASSERT(areNodesMerged);
1224 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,
1225 18,4,5,8,7,13,14,17,16,
1226 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,
1227 18,13,14,17,16,22,23,26,25};
1228 CPPUNIT_ASSERT_EQUAL(72,targetMesh->getNodalConnectivity()->getNumberOfTuples());
1229 CPPUNIT_ASSERT(std::equal(connExp,connExp+72,targetMesh->getNodalConnectivity()->getConstPointer()));
1230 CPPUNIT_ASSERT_EQUAL(27,targetMesh->getCoords()->getNumberOfTuples());
1231 double coordsExp[81]={ 0., 0., 0., 50., 0., 0. , 200., 0., 0. , 0., 50., 0., 50., 50., 0. ,
1232 200., 50., 0., 0., 200., 0., 50., 200., 0. , 200., 200., 0. ,
1233 0., 0., 50., 50., 0., 50. , 200., 0., 50. , 0., 50., 50., 50.,
1234 50., 50. , 200., 50., 50., 0., 200., 50., 50., 200., 50. ,
1235 200., 200., 50. , 0., 0., 200., 50., 0., 200. , 200., 0., 200.
1236 , 0., 50., 200., 50., 50., 200. , 200., 50., 200.,
1237 0., 200., 200., 50., 200., 200. , 200., 200., 200. };
1238 CPPUNIT_ASSERT(std::equal(coordsExp,coordsExp+81,targetMesh->getCoords()->getConstPointer()));
1239 targetMesh->decrRef();
1242 targetMesh=build2DTargetMeshMergeNode_1();
1243 CPPUNIT_ASSERT_EQUAL(18,targetMesh->getNumberOfNodes());
1244 time=targetMesh->getTimeOfThis();
1245 o2n=targetMesh->mergeNodes(1e-10,areNodesMerged,newNbOfNodes);
1246 CPPUNIT_ASSERT(time!=targetMesh->getTimeOfThis());
1247 CPPUNIT_ASSERT(areNodesMerged);
1248 CPPUNIT_ASSERT_EQUAL(9,targetMesh->getNumberOfNodes());
1249 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};
1250 CPPUNIT_ASSERT_EQUAL(23,targetMesh->getNodalConnectivity()->getNumberOfTuples());
1251 CPPUNIT_ASSERT(std::equal(connExp2,connExp2+23,targetMesh->getNodalConnectivity()->getConstPointer()));
1252 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};
1253 CPPUNIT_ASSERT_EQUAL(9,targetMesh->getCoords()->getNumberOfTuples());
1254 CPPUNIT_ASSERT(std::equal(coordsExp2,coordsExp2+18,targetMesh->getCoords()->getConstPointer()));
1255 targetMesh->decrRef();
1259 void MEDCouplingBasicsTest1::testCheckButterflyCells()
1261 std::vector<int> cells;
1262 MEDCouplingUMesh *sourceMesh=build2DTargetMesh_1();
1263 sourceMesh->checkButterflyCells(cells);
1264 CPPUNIT_ASSERT(cells.empty());
1265 int *pt=sourceMesh->getNodalConnectivity()->getPointer();
1266 std::swap(pt[15],pt[16]);
1267 sourceMesh->checkButterflyCells(cells);
1268 CPPUNIT_ASSERT_EQUAL(1,(int)cells.size());
1269 CPPUNIT_ASSERT_EQUAL(3,cells[0]);
1271 std::swap(pt[15],pt[16]);
1272 sourceMesh->checkButterflyCells(cells);
1273 CPPUNIT_ASSERT(cells.empty());
1274 sourceMesh->decrRef();
1276 sourceMesh=build3DSurfTargetMesh_1();
1277 sourceMesh->checkButterflyCells(cells);
1278 CPPUNIT_ASSERT(cells.empty());
1279 pt=sourceMesh->getNodalConnectivity()->getPointer();
1280 std::swap(pt[15],pt[16]);
1281 sourceMesh->checkButterflyCells(cells);
1282 CPPUNIT_ASSERT_EQUAL(1,(int)cells.size());
1283 CPPUNIT_ASSERT_EQUAL(3,cells[0]);
1285 std::swap(pt[15],pt[16]);
1286 sourceMesh->checkButterflyCells(cells);
1287 CPPUNIT_ASSERT(cells.empty());
1288 sourceMesh->decrRef();
1291 void MEDCouplingBasicsTest1::testMergeMesh1()
1293 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1294 MEDCouplingUMesh *m2=build2DSourceMesh_1();
1295 const double vec[2]={1.,0.};
1297 MEDCouplingMesh *m3=m1->mergeMyselfWith(m2);
1298 MEDCouplingUMesh *m3C=dynamic_cast<MEDCouplingUMesh *>(m3);
1299 CPPUNIT_ASSERT(m3C);
1300 m3->checkCoherency();
1301 MEDCouplingUMesh *m4=build2DTargetMeshMerged_1();
1302 CPPUNIT_ASSERT(m3->isEqual(m4,1.e-12));
1306 DataArrayInt *da=m3C->mergeNodes(1.e-12,isMerged,newNbOfNodes);
1307 CPPUNIT_ASSERT_EQUAL(11,m3C->getNumberOfNodes());
1308 CPPUNIT_ASSERT_EQUAL(11,newNbOfNodes);
1309 CPPUNIT_ASSERT(isMerged);
1316 void MEDCouplingBasicsTest1::testMergeMeshOnSameCoords1()
1318 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1319 MEDCouplingUMesh *m2=build2DTargetMesh_1();
1320 std::vector<int> cells(5);
1321 for(int i=0;i<5;i++)
1323 m2->convertToPolyTypes(&cells[0],&cells[0]+cells.size());
1324 m1->tryToShareSameCoords(*m2,1e-12);
1325 MEDCouplingUMesh *m3=build2DTargetMesh_1();
1326 m3->tryToShareSameCoords(*m2,1e-12);
1327 std::vector<const MEDCouplingUMesh *> meshes;
1328 meshes.push_back(m1); meshes.push_back(m2); meshes.push_back(m3);
1329 MEDCouplingUMesh *m4=MEDCouplingUMesh::MergeUMeshesOnSameCoords(meshes);
1330 m4->checkCoherency();
1331 CPPUNIT_ASSERT(m4->getCoords()==m1->getCoords());
1332 CPPUNIT_ASSERT_EQUAL(15,m4->getNumberOfCells());
1333 const int cells1[5]={0,1,2,3,4};
1334 MEDCouplingPointSet *m1_1=m4->buildPartOfMySelf(cells1,cells1+5,true);
1335 m1_1->setName(m1->getName());
1336 CPPUNIT_ASSERT(m1->isEqual(m1_1,1e-12));
1337 const int cells2[5]={5,6,7,8,9};
1338 MEDCouplingPointSet *m2_1=m4->buildPartOfMySelf(cells2,cells2+5,true);
1339 m2_1->setName(m2->getName());
1340 CPPUNIT_ASSERT(m2->isEqual(m2_1,1e-12));
1341 const int cells3[5]={10,11,12,13,14};
1342 MEDCouplingPointSet *m3_1=m4->buildPartOfMySelf(cells3,cells3+5,true);
1343 m3_1->setName(m3->getName());
1344 CPPUNIT_ASSERT(m3->isEqual(m3_1,1e-12));
1345 m1_1->decrRef(); m2_1->decrRef(); m3_1->decrRef();
1353 void MEDCouplingBasicsTest1::testMergeField1()
1355 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1356 MEDCouplingUMesh *m2=build2DSourceMesh_1();
1357 const double vec[2]={1.,0.};
1359 MEDCouplingFieldDouble *f1=m1->getMeasureField(true);
1360 MEDCouplingFieldDouble *f2=m2->getMeasureField(true);
1361 MEDCouplingFieldDouble *f3=MEDCouplingFieldDouble::MergeFields(f1,f2);
1362 f3->checkCoherency();
1363 MEDCouplingUMesh *m4=build2DTargetMeshMerged_1();
1364 CPPUNIT_ASSERT(f3->getMesh()->isEqual(m4,1.e-12));
1365 std::string name=f3->getName();
1366 CPPUNIT_ASSERT(name=="MeasureOfMesh_");
1367 CPPUNIT_ASSERT(f3->getTypeOfField()==ON_CELLS);
1368 CPPUNIT_ASSERT(f3->getTimeDiscretization()==ONE_TIME);
1369 CPPUNIT_ASSERT_EQUAL(1,f3->getNumberOfComponents());
1370 CPPUNIT_ASSERT_EQUAL(7,f3->getNumberOfTuples());
1371 double values[7]={0.25,0.125,0.125,0.25,0.25,0.5,0.5};
1372 const double *tmp=f3->getArray()->getConstPointer();
1373 std::transform(tmp,tmp+7,values,values,std::minus<double>());
1374 std::transform(values,values+7,values,std::ptr_fun<double,double>(fabs));
1375 double max=*std::max_element(values,values+7);
1376 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1385 bool func1(const double *pt, double *res);
1386 bool func2(const double *pt, double *res);
1387 bool func3(const double *pt, double *res);
1388 bool func4(const double *pt, double *res);
1390 bool func1(const double *pt, double *res)
1396 bool func2(const double *pt, double *res)
1399 res[1]=2.*(pt[0]+pt[1]);
1403 bool func3(const double *pt, double *res)
1405 if(fabs(pt[0]-0.2)<1e-12)
1407 res[0]=1./(pt[0]-0.2);
1411 void MEDCouplingBasicsTest1::testFillFromAnalytic()
1413 MEDCouplingUMesh *m=build2DTargetMesh_1();
1414 m->setTime(3.4,5,6); m->setTimeUnit("us");
1416 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_CELLS,1,func1);
1417 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.4,f1->getTime(a,b),1.e-14);
1418 CPPUNIT_ASSERT_EQUAL(5,a); CPPUNIT_ASSERT_EQUAL(6,b);
1419 CPPUNIT_ASSERT_EQUAL(std::string(f1->getTimeUnit()),std::string("us"));
1420 f1->checkCoherency();
1421 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_CELLS);
1422 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1423 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1424 CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
1425 double values1[5]={-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9};
1426 const double *tmp=f1->getArray()->getConstPointer();
1427 std::transform(tmp,tmp+5,values1,values1,std::minus<double>());
1428 std::transform(values1,values1+5,values1,std::ptr_fun<double,double>(fabs));
1429 double max=*std::max_element(values1,values1+5);
1430 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1433 f1=m->fillFromAnalytic(ON_NODES,1,func1);
1434 f1->checkCoherency();
1435 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1436 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1437 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1438 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1439 double values2[9]={-0.6,-0.1,0.4,-0.1,0.4,0.9,0.4,0.9,1.4};
1440 tmp=f1->getArray()->getConstPointer();
1441 std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
1442 std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
1443 max=*std::max_element(values2,values2+9);
1444 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1447 f1=m->fillFromAnalytic(ON_NODES,2,func2);
1448 f1->checkCoherency();
1449 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1450 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1451 CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
1452 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1453 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};
1454 tmp=f1->getArray()->getConstPointer();
1455 std::transform(tmp,tmp+18,values3,values3,std::minus<double>());
1456 std::transform(values3,values3+18,values3,std::ptr_fun<double,double>(fabs));
1457 max=*std::max_element(values3,values3+18);
1458 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1460 f1->accumulate(values4);
1461 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.6,values4[0],1.e-12);
1462 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.2,values4[1],1.e-12);
1463 f1->integral(true,values4);
1464 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,values4[0],1.e-12);
1465 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,values4[1],1.e-12);
1468 CPPUNIT_ASSERT_THROW(f1=m->fillFromAnalytic(ON_NODES,1,func3),INTERP_KERNEL::Exception);
1473 void MEDCouplingBasicsTest1::testFillFromAnalytic2()
1475 MEDCouplingUMesh *m=build2DTargetMesh_1();
1476 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_CELLS,1,"y+x");
1477 f1->checkCoherency();
1478 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_CELLS);
1479 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1480 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1481 CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
1482 double values1[5]={-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9};
1483 const double *tmp=f1->getArray()->getConstPointer();
1484 std::transform(tmp,tmp+5,values1,values1,std::minus<double>());
1485 std::transform(values1,values1+5,values1,std::ptr_fun<double,double>(fabs));
1486 double max=*std::max_element(values1,values1+5);
1487 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1490 f1=m->fillFromAnalytic(ON_NODES,1,"y+2*x");
1491 f1->checkCoherency();
1492 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1493 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1494 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1495 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1496 double values2[9]={-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1};
1497 tmp=f1->getArray()->getConstPointer();
1498 std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
1499 std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
1500 max=*std::max_element(values2,values2+9);
1501 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1503 f1=m->fillFromAnalytic(ON_NODES,1,"2.*x+y");
1504 f1->checkCoherency();
1505 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1506 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1507 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1508 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1509 tmp=f1->getArray()->getConstPointer();
1510 double values2Bis[9]={-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1};
1511 std::transform(tmp,tmp+9,values2Bis,values2Bis,std::minus<double>());
1512 std::transform(values2,values2+9,values2Bis,std::ptr_fun<double,double>(fabs));
1513 max=*std::max_element(values2Bis,values2Bis+9);
1514 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1517 f1=m->fillFromAnalytic(ON_NODES,2,"(x+y)*IVec+2*(x+y)*JVec");
1518 f1->checkCoherency();
1519 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1520 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1521 CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
1522 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1523 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};
1524 tmp=f1->getArray()->getConstPointer();
1525 std::transform(tmp,tmp+18,values3,values3,std::minus<double>());
1526 std::transform(values3,values3+18,values3,std::ptr_fun<double,double>(fabs));
1527 max=*std::max_element(values3,values3+18);
1528 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1530 f1->accumulate(values4);
1531 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.6,values4[0],1.e-12);
1532 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.2,values4[1],1.e-12);
1533 f1->integral(true,values4);
1534 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,values4[0],1.e-12);
1535 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,values4[1],1.e-12);
1538 CPPUNIT_ASSERT_THROW(f1=m->fillFromAnalytic(ON_NODES,1,"1./(x-0.2)"),INTERP_KERNEL::Exception);
1543 void MEDCouplingBasicsTest1::testApplyFunc()
1545 MEDCouplingUMesh *m=build2DTargetMesh_1();
1546 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,2,func2);
1547 f1->checkCoherency();
1548 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1549 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1550 CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
1551 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1552 f1->applyFunc(1,func1);
1553 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1554 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1555 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1556 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1557 double values1[9]={-1.8,-0.3,1.2,-0.3,1.2,2.7,1.2,2.7,4.2};
1558 const double *tmp=f1->getArray()->getConstPointer();
1559 std::transform(tmp,tmp+9,values1,values1,std::minus<double>());
1560 std::transform(values1,values1+9,values1,std::ptr_fun<double,double>(fabs));
1561 double max=*std::max_element(values1,values1+9);
1562 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1567 void MEDCouplingBasicsTest1::testApplyFunc2()
1569 MEDCouplingUMesh *m=build2DTargetMesh_1();
1570 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,2,func2);
1571 f1->checkCoherency();
1572 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1573 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1574 CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
1575 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1577 MEDCouplingFieldDouble *f2=f1->clone(true);
1578 CPPUNIT_ASSERT_THROW(f2->applyFunc(1,"a+b+c+d"),INTERP_KERNEL::Exception);
1579 CPPUNIT_ASSERT_THROW(f2->applyFunc(1,"a/0"),INTERP_KERNEL::Exception);
1580 CPPUNIT_ASSERT_THROW(f2->applyFunc("a/0"),INTERP_KERNEL::Exception);
1581 f2->applyFunc("abs(u)^2.4+2*u");
1582 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1583 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1584 CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
1585 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1586 double values2[18]={-0.9065304805418678, -0.85105859001709905, -0.19601892829446504, -0.37898777756476987,
1587 0.91090317490482353, 2.1853504664669781, -0.19601892829446504, -0.37898777756476987,
1588 0.91090317490482353, 2.1853504664669781, 2.5765725275664879, 7.6987743736515295,
1589 0.91090317490482353, 2.1853504664669781, 2.5765725275664879, 7.6987743736515295,
1590 5.0423700574830965, 17.435300118916864};
1591 const double *tmp=f2->getArray()->getConstPointer();
1592 std::transform(tmp,tmp+18,values2,values2,std::minus<double>());
1593 std::transform(values2,values2+18,values2,std::ptr_fun<double,double>(fabs));
1594 double max=*std::max_element(values2,values2+18);
1595 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1598 f1->applyFunc(1,"x+y");
1599 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1600 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1601 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1602 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1603 double values1[9]={-1.8,-0.3,1.2,-0.3,1.2,2.7,1.2,2.7,4.2};
1604 tmp=f1->getArray()->getConstPointer();
1605 std::transform(tmp,tmp+9,values1,values1,std::minus<double>());
1606 std::transform(values1,values1+9,values1,std::ptr_fun<double,double>(fabs));
1607 max=*std::max_element(values1,values1+9);
1608 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1613 void MEDCouplingBasicsTest1::testOperationsOnFields()
1615 MEDCouplingUMesh *m=build2DTargetMesh_1();
1616 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,1,func1);
1617 MEDCouplingFieldDouble *f2=m->fillFromAnalytic(ON_NODES,1,func1);
1618 f1->checkCoherency();
1619 f2->checkCoherency();
1620 MEDCouplingFieldDouble *f3=(*f1)+(*f2);
1621 f3->checkCoherency();
1622 CPPUNIT_ASSERT(f3->getTypeOfField()==ON_NODES);
1623 CPPUNIT_ASSERT(f3->getTimeDiscretization()==ONE_TIME);
1624 double values1[9]={-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8};
1625 const double *tmp=f3->getArray()->getConstPointer();
1626 std::transform(tmp,tmp+9,values1,values1,std::minus<double>());
1627 std::transform(values1,values1+9,values1,std::ptr_fun<double,double>(fabs));
1628 double max=*std::max_element(values1,values1+9);
1629 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1633 f3->checkCoherency();
1634 CPPUNIT_ASSERT(f3->getTypeOfField()==ON_NODES);
1635 CPPUNIT_ASSERT(f3->getTimeDiscretization()==ONE_TIME);
1636 double values2[9]={0.36,0.01,0.16,0.01,0.16,0.81,0.16,0.81,1.96};
1637 tmp=f3->getArray()->getConstPointer();
1638 std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
1639 std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
1640 max=*std::max_element(values2,values2+9);
1641 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1645 MEDCouplingFieldDouble *f4=(*f1)-(*f3);
1646 f4->checkCoherency();
1647 CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1648 CPPUNIT_ASSERT(f4->getTimeDiscretization()==ONE_TIME);
1649 double values3[9]={0.6,0.1,-0.4,0.1,-0.4,-0.9,-0.4,-0.9,-1.4};
1650 tmp=f4->getArray()->getConstPointer();
1651 std::transform(tmp,tmp+9,values3,values3,std::minus<double>());
1652 std::transform(values3,values3+9,values3,std::ptr_fun<double,double>(fabs));
1653 max=*std::max_element(values3,values3+9);
1654 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1660 f4->checkCoherency();
1661 CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1662 CPPUNIT_ASSERT(f4->getTimeDiscretization()==ONE_TIME);
1663 tmp=f4->getArray()->getConstPointer();
1664 for(int i=0;i<9;i++)
1665 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.,tmp[i],1.e-12);
1669 f4=f2->buildNewTimeReprFromThis(NO_TIME,false);
1670 f4->checkCoherency();
1671 CPPUNIT_ASSERT(f4->getArray()==f2->getArray());
1672 CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1673 CPPUNIT_ASSERT(f4->getTimeDiscretization()==NO_TIME);
1674 CPPUNIT_ASSERT_THROW(f3=(*f1)+(*f4),INTERP_KERNEL::Exception);
1675 MEDCouplingFieldDouble *f5=f4->buildNewTimeReprFromThis(ONE_TIME,false);
1676 CPPUNIT_ASSERT(f4->getArray()==f5->getArray());
1677 CPPUNIT_ASSERT(f5->getTypeOfField()==ON_NODES);
1678 CPPUNIT_ASSERT(f5->getTimeDiscretization()==ONE_TIME);
1680 tmp=f3->getArray()->getConstPointer();
1681 double values4[9]={-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8};
1682 std::transform(tmp,tmp+9,values4,values4,std::minus<double>());
1683 std::transform(values4,values4+9,values4,std::ptr_fun<double,double>(fabs));
1684 max=*std::max_element(values4,values4+9);
1685 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1690 f4=f2->buildNewTimeReprFromThis(NO_TIME,true);
1691 f4->checkCoherency();
1692 CPPUNIT_ASSERT(f4->getArray()!=f2->getArray());
1693 CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1694 CPPUNIT_ASSERT(f4->getTimeDiscretization()==NO_TIME);
1695 CPPUNIT_ASSERT_THROW(f3=(*f1)+(*f4),INTERP_KERNEL::Exception);
1696 f5=f4->buildNewTimeReprFromThis(ONE_TIME,true);
1697 CPPUNIT_ASSERT(f4->getArray()!=f5->getArray());
1698 CPPUNIT_ASSERT(f2->getArray()!=f5->getArray());
1699 CPPUNIT_ASSERT(f5->getTypeOfField()==ON_NODES);
1700 CPPUNIT_ASSERT(f5->getTimeDiscretization()==ONE_TIME);
1702 tmp=f3->getArray()->getConstPointer();
1703 double values5[9]={-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8};
1704 std::transform(tmp,tmp+9,values5,values5,std::minus<double>());
1705 std::transform(values5,values5+9,values5,std::ptr_fun<double,double>(fabs));
1706 max=*std::max_element(values5,values5+9);
1707 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1717 void MEDCouplingBasicsTest1::testOperationsOnFields2()
1719 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1720 m->setTime(3.4,5,6); m->setTimeUnit("us");
1722 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,1,"x+y+z");
1723 MEDCouplingFieldDouble *f2=m->fillFromAnalytic(ON_NODES,1,"a*a+b+c*c");
1724 MEDCouplingFieldDouble *f3=(*f1)/(*f2);
1725 f3->checkCoherency();
1726 CPPUNIT_ASSERT(f3->getTypeOfField()==ON_NODES);
1727 CPPUNIT_ASSERT(f3->getTimeDiscretization()==ONE_TIME);
1728 const double expected1[9]={-2.4999999999999991, 1.2162162162162162, 0.77868852459016391,
1729 0.7407407407407407, 1.129032258064516, 0.81632653061224492,
1730 0.86538461538461531, 1.0919540229885056, 0.84302325581395343};
1731 CPPUNIT_ASSERT_EQUAL(1,f3->getNumberOfComponents());
1732 CPPUNIT_ASSERT_EQUAL(9,f3->getNumberOfTuples());
1733 const double *val=f3->getArray()->getConstPointer();
1734 for(int i=0;i<9;i++)
1735 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1.e-12);
1740 f1=m->buildOrthogonalField();
1741 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.4,f1->getTime(a,b),1.e-14);
1742 CPPUNIT_ASSERT_EQUAL(5,a); CPPUNIT_ASSERT_EQUAL(6,b);
1743 CPPUNIT_ASSERT_EQUAL(std::string(f1->getTimeUnit()),std::string("us"));
1744 f2=m->fillFromAnalytic(ON_CELLS,1,"x");
1746 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};
1747 val=f3->getArray()->getConstPointer();
1748 for(int i=0;i<15;i++)
1749 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1.e-12);
1753 val=f3->getArray()->getConstPointer();
1754 for(int i=0;i<15;i++)
1755 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1.e-12);
1764 void MEDCouplingBasicsTest1::testOperationsOnFields3()
1766 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1767 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,1,"x+y+z");
1768 MEDCouplingFieldDouble *f2=m->fillFromAnalytic(ON_NODES,1,"a*a+b+c*c");
1770 f1->checkCoherency();
1771 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1772 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1773 const double expected1[9]={-2.4999999999999991, 1.2162162162162162, 0.77868852459016391,
1774 0.7407407407407407, 1.129032258064516, 0.81632653061224492,
1775 0.86538461538461531, 1.0919540229885056, 0.84302325581395343};
1776 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1777 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1778 const double *val=f1->getArray()->getConstPointer();
1779 for(int i=0;i<9;i++)
1780 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1.e-12);
1784 f1=m->buildOrthogonalField();
1785 f2=m->fillFromAnalytic(ON_CELLS,1,"x");
1787 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};
1788 val=f1->getArray()->getConstPointer();
1789 for(int i=0;i<15;i++)
1790 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1.e-12);
1793 f1=m->buildOrthogonalField();
1794 CPPUNIT_ASSERT_THROW((*f2)*=(*f1),INTERP_KERNEL::Exception);
1802 * Check of LINEAR_TIME and CONST_ON_TIME_INTERVAL policies
1804 void MEDCouplingBasicsTest1::testOperationsOnFields4()
1806 MEDCouplingUMesh *m=build2DTargetMesh_1();
1807 int nbOfCells=m->getNumberOfCells();
1808 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,CONST_ON_TIME_INTERVAL);
1810 DataArrayDouble *array=DataArrayDouble::New();
1811 array->alloc(nbOfCells,3);
1812 f1->setArray(array);
1813 CPPUNIT_ASSERT_THROW(f1->setEndArray(array),INTERP_KERNEL::Exception);
1814 CPPUNIT_ASSERT_THROW(f1->getEndArray(),INTERP_KERNEL::Exception);
1816 double *tmp=array->getPointer();
1817 const double arr1[15]={0.,10.,20.,1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.};
1818 const double arr2[15]={5.,15.,25.,6.,16.,26.,7.,17.,27.,8.,18.,28.,9.,19.,29.};
1819 std::copy(arr1,arr1+15,tmp);
1820 f1->setStartTime(2.,0,0);
1821 f1->setEndTime(3.,0,0);
1822 f1->checkCoherency();
1824 const double pos[2]={0.3,-0.2};
1825 f1->getValueOn(pos,res);
1826 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[3],res[0],1.e-12);
1827 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[4],res[1],1.e-12);
1828 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[5],res[2],1.e-12);
1829 std::fill(res,res+3,0.);
1830 f1->getValueOn(pos,2.2,res);
1831 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[3],res[0],1.e-12);
1832 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[4],res[1],1.e-12);
1833 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[5],res[2],1.e-12);
1834 std::fill(res,res+3,0.);
1835 CPPUNIT_ASSERT_THROW(f1->getValueOn(pos,3.2,res),INTERP_KERNEL::Exception);
1836 MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
1838 f2->setArray(f1->getArray());
1839 f2->setStartTime(2.,3,0);
1840 f2->setEndTime(4.,13,0);
1841 CPPUNIT_ASSERT_THROW(f2->checkCoherency(),INTERP_KERNEL::Exception);
1842 DataArrayDouble *array2=DataArrayDouble::New();
1843 array2->alloc(nbOfCells,3);
1844 tmp=array2->getPointer();
1845 std::copy(arr2,arr2+15,tmp);
1846 f2->setEndArray(array2);
1848 f2->checkCoherency();
1850 std::fill(res,res+3,0.);
1851 f2->getValueOn(pos,3.21,res);
1852 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.025,res[0],1.e-12);
1853 CPPUNIT_ASSERT_DOUBLES_EQUAL(14.025,res[1],1.e-12);
1854 CPPUNIT_ASSERT_DOUBLES_EQUAL(24.025,res[2],1.e-12);
1855 MEDCouplingFieldDouble *f3=f2->clone(true);
1856 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-12));
1857 f3->getEndArray()->getPointer()[0]=5.001;
1858 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-12));
1859 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1860 f3->setStartTime(2.1,3,0);
1861 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1862 f3->setStartTime(2.,3,0);
1863 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1864 f3->setStartTime(2.,4,0);
1865 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1866 f3->setStartTime(2.,3,1);
1867 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1868 f3->setStartTime(2.,3,0);
1869 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1870 f3->setEndTime(4.1,13,0);
1871 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1872 f3->setEndTime(4.,13,0);
1873 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1874 f3->setEndTime(4.,14,0);
1875 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1876 f3->setEndTime(4.,13,1);
1877 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1878 f3->setEndTime(4.,13,0);
1879 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1881 MEDCouplingFieldDouble *f4=(*f2)+(*f2);
1882 std::fill(res,res+3,0.);
1883 f4->getValueOn(pos,3.21,res);
1884 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.05,res[0],1.e-12);
1885 CPPUNIT_ASSERT_DOUBLES_EQUAL(28.05,res[1],1.e-12);
1886 CPPUNIT_ASSERT_DOUBLES_EQUAL(48.05,res[2],1.e-12);
1888 std::fill(res,res+3,0.);
1889 f4->getValueOn(pos,3.21,res);
1890 CPPUNIT_ASSERT_DOUBLES_EQUAL(12.075,res[0],1.e-12);
1891 CPPUNIT_ASSERT_DOUBLES_EQUAL(42.075,res[1],1.e-12);
1892 CPPUNIT_ASSERT_DOUBLES_EQUAL(72.075,res[2],1.e-12);
1900 bool func4(const double *pt, double *res)
1902 res[0]=pt[0]+pt[1]+pt[2];
1906 void MEDCouplingBasicsTest1::testMergeNodesOnField()
1909 MEDCouplingUMesh *targetMesh=build3DTargetMeshMergeNode_1();
1910 MEDCouplingFieldDouble *f1=targetMesh->fillFromAnalytic(ON_NODES,1,func4);
1911 f1->mergeNodes(1e-10);
1913 targetMesh->decrRef();
1915 targetMesh=build3DTargetMeshMergeNode_1();
1916 f1=targetMesh->fillFromAnalytic(ON_NODES,1,func4);
1917 tmp=f1->getArray()->getPointer();
1919 f1->mergeNodes(1e-10);
1921 targetMesh->decrRef();
1923 targetMesh=build3DTargetMeshMergeNode_1();
1924 f1=targetMesh->fillFromAnalytic(ON_NODES,1,func4);
1925 tmp=f1->getArray()->getPointer();
1927 CPPUNIT_ASSERT_THROW(f1->mergeNodes(1e-10),INTERP_KERNEL::Exception);
1929 targetMesh->decrRef();
1932 void MEDCouplingBasicsTest1::testCheckConsecutiveCellTypes()
1934 MEDCouplingUMesh *sourceMesh=build2DSourceMesh_1();
1935 MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
1936 CPPUNIT_ASSERT(sourceMesh->checkConsecutiveCellTypes());
1937 const INTERP_KERNEL::NormalizedCellType order1[]={INTERP_KERNEL::NORM_TRI3, INTERP_KERNEL::NORM_QUAD4};
1938 const INTERP_KERNEL::NormalizedCellType order2[]={INTERP_KERNEL::NORM_QUAD4, INTERP_KERNEL::NORM_TRI3};
1939 CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypes());
1940 CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypesAndOrder(order1,order1+2));
1941 CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypesAndOrder(order2,order2+2));
1942 DataArrayInt *da=targetMesh->getRenumArrForConsecutiveCellTypesSpec(order1,order1+2);
1943 CPPUNIT_ASSERT_EQUAL(5,da->getNumberOfTuples());
1944 CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfComponents());
1945 const int expected1[5]={2,0,1,3,4};
1946 CPPUNIT_ASSERT(std::equal(expected1,expected1+5,da->getConstPointer()));
1948 da=targetMesh->getRenumArrForConsecutiveCellTypesSpec(order2,order2+2);
1949 CPPUNIT_ASSERT_EQUAL(5,da->getNumberOfTuples());
1950 CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfComponents());
1951 const int expected2[5]={0,3,4,1,2};
1952 CPPUNIT_ASSERT(std::equal(expected2,expected2+5,da->getConstPointer()));
1954 const int renumber1[5]={4,0,1,2,3};
1955 targetMesh->renumberCells(renumber1,false);
1956 CPPUNIT_ASSERT(targetMesh->checkConsecutiveCellTypes());
1957 CPPUNIT_ASSERT(targetMesh->checkConsecutiveCellTypesAndOrder(order1,order1+2));
1958 CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypesAndOrder(order2,order2+2));
1959 targetMesh->decrRef();
1960 sourceMesh->decrRef();
1963 void MEDCouplingBasicsTest1::testRearrange2ConsecutiveCellTypes()
1965 MEDCouplingUMesh *m1_1=build2DSourceMesh_1();
1966 MEDCouplingUMesh *m2_1=build2DTargetMesh_1();
1967 DataArrayInt *arr1=m1_1->rearrange2ConsecutiveCellTypes();
1968 MEDCouplingUMesh *m1_2=build2DSourceMesh_1();
1969 CPPUNIT_ASSERT(m1_2->isEqual(m1_1,1e-12));
1970 const int expected1[2]={0,1};
1971 CPPUNIT_ASSERT_EQUAL(2,arr1->getNumberOfTuples());
1972 CPPUNIT_ASSERT_EQUAL(1,arr1->getNumberOfComponents());
1973 CPPUNIT_ASSERT(std::equal(expected1,expected1+2,arr1->getConstPointer()));
1975 const int expected2[5]={0,3,4,1,2};
1976 arr1=m2_1->rearrange2ConsecutiveCellTypes();
1977 CPPUNIT_ASSERT_EQUAL(5,arr1->getNumberOfTuples());
1978 CPPUNIT_ASSERT_EQUAL(1,arr1->getNumberOfComponents());
1979 CPPUNIT_ASSERT(std::equal(expected2,expected2+5,arr1->getConstPointer()));
1980 MEDCouplingUMesh *m2_2=build2DTargetMesh_1();
1981 CPPUNIT_ASSERT_EQUAL(5,arr1->getNumberOfTuples());
1982 CPPUNIT_ASSERT_EQUAL(1,arr1->getNumberOfComponents());
1983 CPPUNIT_ASSERT(std::equal(expected2,expected2+5,arr1->getConstPointer()));
1984 CPPUNIT_ASSERT(!m2_2->isEqual(m2_1,1e-12));
1985 m2_2->renumberCells(expected2,false);
1986 CPPUNIT_ASSERT(m2_2->isEqual(m2_1,1e-12));
1994 void MEDCouplingBasicsTest1::testSplitByType()
1996 MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
1997 std::vector<MEDCouplingUMesh *> v=m1->splitByType();
1998 CPPUNIT_ASSERT_EQUAL(3,(int)v.size());
1999 std::vector<const MEDCouplingUMesh *> v2(v.begin(),v.end());
2000 MEDCouplingUMesh *m2=MEDCouplingUMesh::MergeUMeshesOnSameCoords(v2);
2001 m2->setName(m1->getName());
2002 CPPUNIT_ASSERT(m1->isEqual(m2,1.e-12));
2003 for(std::vector<MEDCouplingUMesh *>::const_iterator iter=v.begin();iter!=v.end();iter++)
2009 void MEDCouplingBasicsTest1::testFuseUMeshesOnSameCoords()
2011 std::vector<const MEDCouplingUMesh *> meshes;
2012 MEDCouplingUMesh *m2=build2DTargetMesh_1();
2013 int cells1[3]={2,3,4};
2014 MEDCouplingPointSet *m3_1=m2->buildPartOfMySelf(cells1,cells1+3,true);
2015 MEDCouplingUMesh *m3=dynamic_cast<MEDCouplingUMesh *>(m3_1);
2017 meshes.push_back(m3);
2018 int cells2[3]={1,2,4};
2019 MEDCouplingPointSet *m4_1=m2->buildPartOfMySelf(cells2,cells2+3,true);
2020 MEDCouplingUMesh *m4=dynamic_cast<MEDCouplingUMesh *>(m4_1);
2022 meshes.push_back(m4);
2023 int cells3[2]={1,2};
2024 MEDCouplingPointSet *m5_1=m2->buildPartOfMySelf(cells3,cells3+2,true);
2025 MEDCouplingUMesh *m5=dynamic_cast<MEDCouplingUMesh *>(m5_1);
2027 meshes.push_back(m5);
2030 std::vector<DataArrayInt *> corr;
2031 MEDCouplingUMesh *m7=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
2032 CPPUNIT_ASSERT_EQUAL(4,m7->getNumberOfCells());
2033 CPPUNIT_ASSERT_EQUAL(3,(int)corr.size());
2034 const int expectedVals1[3]={3,3,2};
2035 const int expectedVals2[3][3]={{0,1,2},{3,0,2},{3,0,111111}};
2036 for(int i=0;i<3;i++)
2038 DataArrayInt *arr=corr[i];
2039 CPPUNIT_ASSERT_EQUAL(1,arr->getNumberOfComponents());
2040 int nbOfVals=expectedVals1[i];
2041 CPPUNIT_ASSERT_EQUAL(nbOfVals,arr->getNumberOfTuples());
2042 const int *vals=arr->getConstPointer();
2043 for(int j=0;j<nbOfVals;j++)
2044 CPPUNIT_ASSERT_EQUAL(expectedVals2[i][j],vals[j]);
2046 std::vector< std::vector<int> > fidsOfGroups;
2047 std::vector<const DataArrayInt *> corr2(corr.begin(),corr.end());
2048 DataArrayInt *arr2=DataArrayInt::MakePartition(corr2,m7->getNumberOfCells(),fidsOfGroups);
2049 const int fidExp[4]={5,1,3,4};
2050 const int fidsGrp[3][3]={{1,3,5},{3,4,5},{4,5,23344}};
2051 CPPUNIT_ASSERT_EQUAL(3,(int)fidsOfGroups.size());
2052 CPPUNIT_ASSERT_EQUAL(1,arr2->getNumberOfComponents());
2053 CPPUNIT_ASSERT_EQUAL(4,arr2->getNumberOfTuples());
2054 CPPUNIT_ASSERT(std::equal(fidExp,fidExp+4,arr2->getConstPointer()));
2055 for(int i=0;i<3;i++)
2057 int nbOfVals=expectedVals1[i];
2058 CPPUNIT_ASSERT_EQUAL(nbOfVals,(int)fidsOfGroups[i].size());
2059 CPPUNIT_ASSERT(std::equal(fidsOfGroups[i].begin(),fidsOfGroups[i].end(),fidsGrp[i]));
2061 for(std::vector<DataArrayInt *>::iterator iter=corr.begin();iter!=corr.end();iter++)
2071 void MEDCouplingBasicsTest1::testFuseUMeshesOnSameCoords2()
2073 MEDCouplingUMesh *m2;
2074 MEDCouplingUMesh *m1=build3DExtrudedUMesh_1(m2);
2076 const int part1[5]={2,3,6,4,10};
2077 MEDCouplingUMesh *m3=(MEDCouplingUMesh *)m1->buildPartOfMySelf(part1,part1+5,true);
2078 const int part2[4]={5,6,4,7};
2079 MEDCouplingUMesh *m4=(MEDCouplingUMesh *)m1->buildPartOfMySelf(part2,part2+4,true);
2080 std::vector<const MEDCouplingUMesh *> meshes;
2081 meshes.push_back(m1);
2082 meshes.push_back(m3);
2083 meshes.push_back(m3);
2084 meshes.push_back(m4);
2085 std::vector<DataArrayInt *> corr;
2086 MEDCouplingUMesh *m5=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
2087 CPPUNIT_ASSERT_EQUAL(18,m5->getNumberOfCells());
2088 std::vector<DataArrayInt *>::iterator it=corr.begin();
2089 const int exp1[4]={18,5,5,4};
2090 const int exp2[4][18]={
2091 {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17},
2092 {2,3,6,4,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
2093 {2,3,6,4,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
2094 {5,6,4,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}
2097 for(;it!=corr.end();it++,i++)
2099 int sz=(*it)->getNumberOfTuples();
2100 CPPUNIT_ASSERT_EQUAL(exp1[i],sz);
2101 CPPUNIT_ASSERT(std::equal(exp2[i],exp2[i]+sz,(*it)->getConstPointer()));
2103 for(it=corr.begin();it!=corr.end();it++)
2111 void MEDCouplingBasicsTest1::testBuildOrthogonalField()
2113 MEDCouplingUMesh *targetMesh=build3DSurfTargetMesh_1();
2114 MEDCouplingFieldDouble *field=targetMesh->buildOrthogonalField();
2115 double expected[3]={0.70710678118654746,0.,-0.70710678118654746};
2116 CPPUNIT_ASSERT_EQUAL(5,field->getNumberOfTuples());
2117 CPPUNIT_ASSERT_EQUAL(3,field->getNumberOfComponents());
2118 const double *vals=field->getArray()->getConstPointer();
2119 for(int i=0;i<15;i++)
2120 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected[i%3],vals[i],1e-12);
2122 targetMesh->decrRef();
2124 double targetCoords[12]={0.,0.,0.,0.5,0.,0.5,1.,0.,1.,0.,1.,0.};
2125 int targetConn[4]={0,1,2,3};
2126 targetMesh=MEDCouplingUMesh::New();
2127 targetMesh->setMeshDimension(2);
2128 targetMesh->allocateCells(1);
2129 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn);
2130 targetMesh->finishInsertingCells();
2131 DataArrayDouble *myCoords=DataArrayDouble::New();
2132 myCoords->alloc(4,3);
2133 std::copy(targetCoords,targetCoords+12,myCoords->getPointer());
2134 targetMesh->setCoords(myCoords);
2135 myCoords->decrRef();
2136 field=targetMesh->buildOrthogonalField();
2137 CPPUNIT_ASSERT_EQUAL(1,field->getNumberOfTuples());
2138 CPPUNIT_ASSERT_EQUAL(3,field->getNumberOfComponents());
2139 vals=field->getArray()->getConstPointer();
2140 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.70710678118654746,vals[0],1e-12);
2141 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,vals[1],1e-12);
2142 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.70710678118654746,vals[2],1e-12);
2144 targetMesh->decrRef();
2147 void MEDCouplingBasicsTest1::testGetCellsContainingPoint()
2149 MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
2150 double pos[12]={0.,0.,0.4,0.4,0.,0.4,0.1,0.1,0.25,0.,0.65,0.};
2151 std::vector<int> t1,t2;
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 const int expectedValues1[6]={0,4,3,0,1,2};
2157 const int expectedValues2[7]={0,1,2,3,4,5,6};
2158 CPPUNIT_ASSERT(std::equal(t1.begin(),t1.end(),expectedValues1));
2159 CPPUNIT_ASSERT(std::equal(t2.begin(),t2.end(),expectedValues2));
2160 //2D with no help of bounding box.
2161 double center[2]={0.2,0.2};
2162 MEDCouplingPointSet::Rotate2DAlg(center,0.78539816339744830962,6,pos);
2163 targetMesh->rotate(center,0,0.78539816339744830962);
2164 t1.clear(); t2.clear();
2165 targetMesh->getCellsContainingPoints(pos,6,1e-12,t1,t2);
2166 CPPUNIT_ASSERT_EQUAL(6,(int)t1.size());
2167 CPPUNIT_ASSERT_EQUAL(7,(int)t2.size());
2168 CPPUNIT_ASSERT(std::equal(t1.begin(),t1.end(),expectedValues1));
2169 CPPUNIT_ASSERT(std::equal(t2.begin(),t2.end(),expectedValues2));
2171 const double pos1bis[2]={-0.3303300858899107,-0.11819805153394641};
2172 CPPUNIT_ASSERT_EQUAL(-1,targetMesh->getCellContainingPoint(pos1bis,1e-12));
2173 targetMesh->decrRef();
2175 targetMesh=build2DTargetMesh_1();
2176 const double pos2[2]={0.2,-0.05};
2178 targetMesh->getCellsContainingPoint(pos2,1e-12,t1);
2179 CPPUNIT_ASSERT_EQUAL(2,(int)t1.size());
2180 const int expectedValues3[2]={0,1};
2181 CPPUNIT_ASSERT(std::equal(t1.begin(),t1.end(),expectedValues3));
2182 const double pos3[2]={0.2,0.2};
2184 targetMesh->getCellsContainingPoint(pos3,1e-12,t1);
2185 CPPUNIT_ASSERT_EQUAL(5,(int)t1.size());
2186 const int expectedValues4[5]={0,1,2,3,4};
2187 CPPUNIT_ASSERT(std::equal(t1.begin(),t1.end(),expectedValues4));
2188 CPPUNIT_ASSERT_EQUAL(0,targetMesh->getCellContainingPoint(pos3,1e-12));
2189 targetMesh->decrRef();
2191 targetMesh=build3DTargetMesh_1();
2192 const double pos4[3]={25.,25.,25.};
2193 CPPUNIT_ASSERT_EQUAL(0,targetMesh->getCellContainingPoint(pos4,1e-12));
2194 const double pos5[3]={50.,50.,50.};
2196 targetMesh->getCellsContainingPoint(pos5,1e-12,t1);
2197 CPPUNIT_ASSERT_EQUAL(8,(int)t1.size());
2198 const int expectedValues5[8]={0,1,2,3,4,5,6,7};
2199 CPPUNIT_ASSERT(std::equal(t1.begin(),t1.end(),expectedValues5));
2200 const double pos6[3]={0., 50., 0.};
2202 targetMesh->getCellsContainingPoint(pos6,1e-12,t1);
2203 CPPUNIT_ASSERT_EQUAL(2,(int)t1.size());
2204 const int expectedValues6[2]={0,2};
2205 CPPUNIT_ASSERT(std::equal(t1.begin(),t1.end(),expectedValues6));
2207 const double pos7[3]={-1.0,-1.0,0.};
2208 CPPUNIT_ASSERT_EQUAL(-1,targetMesh->getCellContainingPoint(pos7,1e-12));
2210 const double center2[3]={0.,0.,0.};
2211 const double vec2[3]={0.,-1.,0.};
2212 targetMesh->rotate(center2,vec2,0.78539816339744830962);
2213 const double pos8[3]={-25,25.,12.};
2214 CPPUNIT_ASSERT_EQUAL(-1,targetMesh->getCellContainingPoint(pos8,1e-12));
2216 targetMesh->decrRef();
2219 void MEDCouplingBasicsTest1::testGetValueOn1()
2221 MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
2222 MEDCouplingFieldDouble *fieldOnCells=MEDCouplingFieldDouble::New(ON_CELLS);
2223 int nbOfCells=targetMesh->getNumberOfCells();
2224 fieldOnCells->setMesh(targetMesh);
2225 DataArrayDouble *array=DataArrayDouble::New();
2226 array->alloc(nbOfCells,2);
2227 fieldOnCells->setArray(array);
2228 double *tmp=array->getPointer();
2229 for(int i=0;i<nbOfCells;i++)
2230 { tmp[2*i]=7.+(double)i; tmp[2*i+1]=17.+(double)i; }
2233 const double pos1[2]={0.25,0.};
2235 fieldOnCells->getValueOn(pos1,res);
2236 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.,res[0],1e-12);
2237 CPPUNIT_ASSERT_DOUBLES_EQUAL(18.,res[1],1e-12);
2239 fieldOnCells->decrRef();
2240 targetMesh->decrRef();
2242 targetMesh=build2DSourceMesh_1();
2243 MEDCouplingFieldDouble *fieldOnNodes=MEDCouplingFieldDouble::New(ON_NODES);
2244 int nbOfNodes=targetMesh->getNumberOfNodes();
2245 fieldOnNodes->setMesh(targetMesh);
2246 array=DataArrayDouble::New();
2247 array->alloc(nbOfNodes,2);
2248 fieldOnNodes->setArray(array);
2249 tmp=array->getPointer();
2250 for(int i=0;i<nbOfNodes;i++)
2251 { tmp[2*i]=17.+(double)i; tmp[2*i+1]=27.+(double)i; }
2254 const double pos2[2]={-0.13333333333333333,-0.13333333333333333};
2255 fieldOnNodes->getValueOn(pos2,res);
2256 CPPUNIT_ASSERT_DOUBLES_EQUAL(17.5,res[0],1e-12);
2257 CPPUNIT_ASSERT_DOUBLES_EQUAL(27.5,res[1],1e-12);
2258 const double pos3[2]={0.033333333333333326,0.36666666666666664};
2259 fieldOnNodes->getValueOn(pos3,res);
2260 CPPUNIT_ASSERT_DOUBLES_EQUAL(18.666666666666667,res[0],1e-12);
2261 CPPUNIT_ASSERT_DOUBLES_EQUAL(28.666666666666667,res[1],1e-12);
2263 fieldOnNodes->decrRef();
2264 targetMesh->decrRef();
2267 void MEDCouplingBasicsTest1::testCMesh0()
2269 MEDCouplingCMesh* mesh=MEDCouplingCMesh::New();
2270 MEDCouplingCMesh* meshEmpty=mesh->clone(true);
2271 CPPUNIT_ASSERT(meshEmpty->isEqual(mesh,1e-12));
2273 DataArrayDouble* coordsX=DataArrayDouble::New();
2274 double arrX[4] = { -1., 1., 2., 4. };
2275 coordsX->useArray(arrX,false, CPP_DEALLOC,4,1);
2276 DataArrayDouble* coordsY=DataArrayDouble::New();
2277 double arrY[4] = { -2., 2., 4., 8. };
2278 coordsY->useArray(arrY,false, CPP_DEALLOC,4,1);
2279 DataArrayDouble* coordsZ=DataArrayDouble::New();
2280 double arrZ[4] = { -3., 3., 6., 12. };
2281 coordsZ->useArray(arrZ,false, CPP_DEALLOC,4,1);
2282 mesh->setCoords(coordsX,coordsY,coordsZ);
2287 MEDCouplingFieldDouble *fieldOnNodes=mesh->fillFromAnalytic(ON_NODES,1,"x+y/2.+z/3.");
2288 CPPUNIT_ASSERT_EQUAL(1,fieldOnNodes->getNumberOfComponents());
2289 CPPUNIT_ASSERT_EQUAL(64,fieldOnNodes->getNumberOfTuples());
2290 const double expected1[64]={-3., -1., 0., 2., -1., 1., 2., 4., 0., 2., 3., 5., 2., 4., 5., 7., -1., 1., 2.,
2291 4., 1., 3., 4., 6., 2., 4., 5., 7., 4., 6., 7., 9., 0., 2., 3., 5., 2., 4., 5.,
2292 7., 3., 5., 6., 8., 5., 7., 8., 10., 2., 4., 5.,
2293 7., 4., 6., 7., 9., 5., 7., 8., 10., 7., 9., 10., 12.};
2294 const double *val=fieldOnNodes->getArray()->getConstPointer();
2295 for(int i=0;i<64;i++)
2296 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1e-12);
2297 double res[1]; //size fieldOnNodes->getNumberOfComponents()
2298 fieldOnNodes->getValueOnPos(1,3,2,&res[0]);
2299 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,res[0],1e-12);
2300 fieldOnNodes->decrRef();
2302 MEDCouplingFieldDouble *fieldOnCells=mesh->fillFromAnalytic(ON_CELLS,1,"x+y/2.+z/3.");
2303 CPPUNIT_ASSERT_EQUAL(1,fieldOnCells->getNumberOfComponents());
2304 CPPUNIT_ASSERT_EQUAL(27,fieldOnCells->getNumberOfTuples());
2305 val=fieldOnCells->getArray()->getConstPointer();
2306 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,
2307 6, 4.5, 6, 7.5, 3, 4.5, 6, 4.5, 6, 7.5, 6, 7.5, 9};
2308 for(int i=0;i<27;i++)
2309 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1e-12);
2310 fieldOnCells->getValueOnPos(1,2,1,&res[0]);
2311 CPPUNIT_ASSERT_DOUBLES_EQUAL(6.,res[0],1e-12);
2312 fieldOnCells->decrRef();
2314 MEDCouplingMesh* meshDeepCopy=mesh->deepCpy();
2315 MEDCouplingCMesh* meshClone=mesh->clone(false);
2317 CPPUNIT_ASSERT_THROW(meshEmpty->copyTinyStringsFrom(0),INTERP_KERNEL::Exception);
2318 meshEmpty->copyTinyStringsFrom(mesh);
2319 //no data in meshEmpty, expected false
2320 CPPUNIT_ASSERT(!meshEmpty->isEqual(mesh,1e-12));
2322 CPPUNIT_ASSERT(meshDeepCopy->isEqual(mesh,1e-12));
2323 meshDeepCopy->copyTinyStringsFrom(mesh);
2324 CPPUNIT_ASSERT(meshDeepCopy->isEqual(mesh,1e-12));
2325 CPPUNIT_ASSERT(meshClone->isEqual(mesh,1e-12));
2327 CPPUNIT_ASSERT_EQUAL(CARTESIAN,mesh->getType());
2328 CPPUNIT_ASSERT_EQUAL(CARTESIAN,meshEmpty->getType());
2329 CPPUNIT_ASSERT_EQUAL(CARTESIAN,meshDeepCopy->getType());
2330 CPPUNIT_ASSERT_EQUAL(CARTESIAN,meshClone->getType());
2333 meshEmpty->decrRef();
2334 meshDeepCopy->decrRef();
2335 meshClone->decrRef();
2338 void MEDCouplingBasicsTest1::testCMesh1()
2340 MEDCouplingCMesh *mesh1,*mesh2,*mesh3;
2341 mesh1=MEDCouplingCMesh::New();
2342 DataArrayDouble* coordsX1=DataArrayDouble::New();
2343 double arrX1[4] = { -1., 1., 2., 4. };
2344 coordsX1->useArray(arrX1,false, CPP_DEALLOC,4,1);
2345 DataArrayDouble* coordsY1=DataArrayDouble::New();
2346 double arrY1[4] = { -2., 2., 4., 8. };
2347 coordsY1->useArray(arrY1,false, CPP_DEALLOC,4,1);
2348 DataArrayDouble* coordsZ1=DataArrayDouble::New();
2349 double arrZ1[4] = { -3., 3., 6., 12. };
2350 coordsZ1->useArray(arrZ1,false, CPP_DEALLOC,4,1);
2351 mesh1->setCoords(coordsX1,coordsY1,coordsZ1);
2353 mesh2=MEDCouplingCMesh::New();
2354 DataArrayDouble* coordsX2=DataArrayDouble::New();
2355 double arrX2[4] = { -1., 1., 2., 4. };
2356 coordsX2->useArray(arrX2,false, CPP_DEALLOC,4,1);
2357 DataArrayDouble* coordsY2=DataArrayDouble::New();
2358 double arrY2[4] = { -2., 2., 4., 8. };
2359 coordsY2->useArray(arrY2,false, CPP_DEALLOC,4,1);
2360 DataArrayDouble* coordsZ2=DataArrayDouble::New();
2361 double arrZ2[4] = { -3., 3., 6., 12.+1e-6 }; //here is not equal
2362 coordsZ2->useArray(arrZ2,false, CPP_DEALLOC,4,1);
2363 mesh2->setCoords(coordsX2,coordsY2,coordsZ2);
2365 mesh3=MEDCouplingCMesh::New();
2366 DataArrayDouble* coordsX3=DataArrayDouble::New();
2367 double arrX3[1] = { -1.};
2368 coordsX3->useArray(arrX3,false, CPP_DEALLOC,1,1);
2369 DataArrayDouble* coordsY3=DataArrayDouble::New();
2370 double arrY3[1] = { -2.};
2371 coordsY3->useArray(arrY3,false, CPP_DEALLOC,1,1);
2372 DataArrayDouble* coordsZ3=DataArrayDouble::New();
2373 double arrZ3[1] = { -3.};
2374 coordsZ3->useArray(arrZ3,false, CPP_DEALLOC,1,1);
2375 mesh3->setCoords(coordsX3,coordsY3,coordsZ3);
2377 CPPUNIT_ASSERT_EQUAL(3,mesh1->getSpaceDimension());
2378 CPPUNIT_ASSERT_EQUAL(3,mesh1->getMeshDimension());
2380 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
2381 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
2382 CPPUNIT_ASSERT(!mesh2->isEqualWithoutConsideringStr(mesh1,1e-12));
2383 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-5));
2384 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-7));
2386 CPPUNIT_ASSERT_THROW(mesh3->checkCoherency1(1e-12),INTERP_KERNEL::Exception);
2387 mesh1->checkCoherency2(1e-12);
2388 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh1->getTypeOfCell(1));
2390 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,*((mesh1->getAllGeoTypes()).begin()));
2391 CPPUNIT_ASSERT_EQUAL(27,mesh1->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2392 CPPUNIT_ASSERT_THROW(mesh1->getNumberOfCellsWithType(INTERP_KERNEL::NORM_QUAD4),INTERP_KERNEL::Exception);
2394 std::vector<double> coo;
2395 mesh1->getCoordinatesOfNode(0, coo);
2396 CPPUNIT_ASSERT_EQUAL(3,(int) coo.size());
2397 CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.,coo[0],1e-14);
2398 CPPUNIT_ASSERT_DOUBLES_EQUAL(-2.,coo[1],1e-14);
2399 CPPUNIT_ASSERT_DOUBLES_EQUAL(-3.,coo[2],1e-14);
2401 mesh1->getCoordinatesOfNode(63, coo);
2402 CPPUNIT_ASSERT_EQUAL(3,(int) coo.size());
2403 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.,coo[0],1e-14);
2404 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.,coo[1],1e-14);
2405 CPPUNIT_ASSERT_DOUBLES_EQUAL(12.,coo[2],1e-14);
2408 repr=mesh1->simpleRepr();
2409 repr=mesh1->advancedRepr();
2410 CPPUNIT_ASSERT(!(repr.find("Cartesian")==std::string::npos));
2411 CPPUNIT_ASSERT(!(repr.find("Number of components : 1")==std::string::npos));
2412 CPPUNIT_ASSERT(!(repr.find("Number of tuples : 4")==std::string::npos));
2413 CPPUNIT_ASSERT(!(repr.find("Z Array :")==std::string::npos));
2414 coordsX1->decrRef();
2415 coordsY1->decrRef();
2416 coordsZ1->decrRef();
2417 coordsX2->decrRef();
2418 coordsY2->decrRef();
2419 coordsZ2->decrRef();
2420 coordsX3->decrRef();
2421 coordsY3->decrRef();
2422 coordsZ3->decrRef();
2428 void MEDCouplingBasicsTest1::testCMesh2()
2430 MEDCouplingCMesh *mesh1;
2431 mesh1=MEDCouplingCMesh::New();
2432 DataArrayDouble* coordsX1=DataArrayDouble::New();
2433 double arrX1[4] = { -1., 1., 2., 4. };
2434 coordsX1->useArray(arrX1,false, CPP_DEALLOC,4,1);
2435 DataArrayDouble* coordsY1=DataArrayDouble::New();
2436 double arrY1[4] = { -2., 2., 4., 8. };
2437 coordsY1->useArray(arrY1,false, CPP_DEALLOC,4,1);
2438 DataArrayDouble* coordsZ1=DataArrayDouble::New();
2439 double arrZ1[4] = { -3., 3., 6., 12. };
2440 coordsZ1->useArray(arrZ1,false, CPP_DEALLOC,4,1);
2441 mesh1->setCoords(coordsX1,coordsY1,coordsZ1);
2443 std::vector<int> dis=mesh1->getDistributionOfTypes();
2444 CPPUNIT_ASSERT_EQUAL(3,(int) dis.size());
2445 CPPUNIT_ASSERT_EQUAL((int) INTERP_KERNEL::NORM_HEXA8,dis[0]);
2446 CPPUNIT_ASSERT_EQUAL(27,dis[1]);
2447 CPPUNIT_ASSERT_EQUAL(0,dis[2]);
2449 std::vector<const DataArrayInt *> idsPerType;
2450 CPPUNIT_ASSERT_THROW(mesh1->checkTypeConsistencyAndContig(dis, idsPerType),INTERP_KERNEL::Exception);
2452 CPPUNIT_ASSERT(!(mesh1->checkTypeConsistencyAndContig(dis, idsPerType)));
2453 dis[0]=(int) INTERP_KERNEL::NORM_QUAD4;
2454 CPPUNIT_ASSERT_THROW(mesh1->checkTypeConsistencyAndContig(dis, idsPerType),INTERP_KERNEL::Exception);
2456 dis[0]=(int) INTERP_KERNEL::NORM_HEXA8;
2458 DataArrayInt *ids=DataArrayInt::New();
2460 ids->fillWithValue(111);
2461 idsPerType.push_back(ids);
2462 DataArrayInt* check=mesh1->checkTypeConsistencyAndContig(dis, idsPerType);
2463 CPPUNIT_ASSERT(check);
2464 CPPUNIT_ASSERT(check->isEqual(*ids));
2466 std::vector<int> code;
2467 std::vector<DataArrayInt *> idsInPflPerType;
2468 std::vector<DataArrayInt *> pfls;
2469 mesh1->splitProfilePerType(ids,code,idsInPflPerType,pfls);
2470 CPPUNIT_ASSERT_EQUAL(3,(int)code.size());
2471 CPPUNIT_ASSERT_EQUAL((int) INTERP_KERNEL::NORM_HEXA8,code[0]);
2472 CPPUNIT_ASSERT_EQUAL(27,code[1]);
2473 CPPUNIT_ASSERT_EQUAL(0,code[2]);
2474 CPPUNIT_ASSERT_EQUAL(1,(int)idsInPflPerType.size());
2475 CPPUNIT_ASSERT_EQUAL(1,(int)pfls.size());
2476 CPPUNIT_ASSERT(idsInPflPerType[0]->isEqual(*ids));
2477 CPPUNIT_ASSERT(pfls[0]->isEqual(*ids));
2478 idsInPflPerType[0]->decrRef();
2483 int cells1[4]={0,1,25,26};
2484 MEDCouplingUMesh *partMesh1=
2485 dynamic_cast<MEDCouplingUMesh *>(mesh1->buildPart(cells1,cells1+4));
2486 CPPUNIT_ASSERT(partMesh1);
2487 CPPUNIT_ASSERT_EQUAL(4,partMesh1->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2488 CPPUNIT_ASSERT_EQUAL(64,mesh1->getNumberOfNodes());
2489 CPPUNIT_ASSERT_EQUAL(64,partMesh1->getNumberOfNodes());
2491 int cells2[2]={25,26};
2493 MEDCouplingUMesh *partMesh2=
2494 dynamic_cast<MEDCouplingUMesh *>(mesh1->buildPartAndReduceNodes(cells2,cells2+2,arr1));
2495 CPPUNIT_ASSERT(partMesh2);
2496 CPPUNIT_ASSERT_EQUAL(2,partMesh2->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2497 CPPUNIT_ASSERT_EQUAL(12,partMesh2->getNumberOfNodes());
2499 int cells3[2]={2,3};
2501 MEDCouplingUMesh *partMesh3=
2502 dynamic_cast<MEDCouplingUMesh *>(partMesh1->buildPartAndReduceNodes(cells3,cells3+2,arr2));
2503 CPPUNIT_ASSERT(partMesh3);
2504 CPPUNIT_ASSERT_EQUAL(2,partMesh3->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2505 CPPUNIT_ASSERT_EQUAL(12,partMesh3->getNumberOfNodes());
2507 CPPUNIT_ASSERT_THROW(mesh1->simplexize(0),INTERP_KERNEL::Exception);
2508 CPPUNIT_ASSERT_THROW(mesh1->getMeasureFieldOnNode(true),INTERP_KERNEL::Exception);
2512 mesh1->getBoundingBox(bbox1);
2513 partMesh1->getBoundingBox(bbox2);
2514 for(int i=0;i<6;i++)
2515 CPPUNIT_ASSERT_DOUBLES_EQUAL(bbox1[i],bbox2[i],1e-12);
2516 partMesh3->getBoundingBox(bbox1);
2517 partMesh2->getBoundingBox(bbox2);
2518 for(int i=0;i<6;i++)
2519 CPPUNIT_ASSERT_DOUBLES_EQUAL(bbox1[i],bbox2[i],1e-12);
2521 CPPUNIT_ASSERT_THROW(mesh1->buildOrthogonalField(),INTERP_KERNEL::Exception);
2522 MEDCouplingCMesh *mesh2d=MEDCouplingCMesh::New();
2523 mesh2d->setCoords(coordsX1,coordsY1);
2524 MEDCouplingFieldDouble *f1=mesh2d->buildOrthogonalField();
2526 std::vector<double> tinyInfoD;
2527 std::vector<int> tinyInfo;
2528 std::vector<std::string> littleStrings;
2529 mesh2d->getTinySerializationInformation(tinyInfoD, tinyInfo, littleStrings);
2530 CPPUNIT_ASSERT_EQUAL(5,(int)tinyInfo.size());
2531 CPPUNIT_ASSERT_EQUAL(4,(int)tinyInfo[0]); //x
2532 CPPUNIT_ASSERT_EQUAL(4,(int)tinyInfo[1]); //y
2533 CPPUNIT_ASSERT_EQUAL(-1,(int)tinyInfo[2]); //z
2534 CPPUNIT_ASSERT_EQUAL(-1,(int)tinyInfo[3]); //it
2535 CPPUNIT_ASSERT_EQUAL(-1,(int)tinyInfo[4]); //order
2536 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,tinyInfoD[0],1e-14); //time
2537 DataArrayInt* d1=DataArrayInt::New();
2538 DataArrayDouble* d2=DataArrayDouble::New();
2539 mesh2d->resizeForUnserialization(tinyInfo, d1, d2, littleStrings);
2540 CPPUNIT_ASSERT_EQUAL(0,d1->getNumberOfTuples());
2541 CPPUNIT_ASSERT_EQUAL(8,d2->getNumberOfTuples());
2543 partMesh1->decrRef();
2544 partMesh2->decrRef();
2545 partMesh3->decrRef();
2552 coordsX1->decrRef();
2553 coordsY1->decrRef();
2554 coordsZ1->decrRef();
2558 void MEDCouplingBasicsTest1::testScale()
2560 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
2561 const double pos[2]={0.2,0.2};
2562 mesh->scale(pos,0.5);
2563 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,
2564 -0.05,0.45, 0.2,0.45, 0.45,0.45};
2565 const double *val=mesh->getCoords()->getConstPointer();
2566 for(int i=0;i<18;i++)
2567 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1e-12);
2572 void MEDCouplingBasicsTest1::testTryToShareSameCoords()
2574 MEDCouplingUMesh *m1=build2DTargetMesh_1();
2575 MEDCouplingUMesh *m2=build2DTargetMesh_1();
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=build2DTargetMesh_2();
2588 CPPUNIT_ASSERT(m1->getCoords()!=m2->getCoords());
2589 m1->tryToShareSameCoords(*m2,1e-12);
2590 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2591 m1->tryToShareSameCoords(*m2,1e-12);
2592 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2593 m2->tryToShareSameCoords(*m1,1e-12);
2594 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2598 m1=build2DTargetMesh_1();
2599 m2=build2DSourceMesh_1();
2600 CPPUNIT_ASSERT(m1->getCoords()!=m2->getCoords());
2601 CPPUNIT_ASSERT_THROW(m1->tryToShareSameCoords(*m2,1e-12),INTERP_KERNEL::Exception);
2606 void MEDCouplingBasicsTest1::testFindNodeOnPlane()
2608 MEDCouplingUMesh *mesh=build3DTargetMesh_1();
2610 double pt[3]={300.,300.,0.};
2611 double v[3]={0.,0.,2.};
2612 mesh->findNodesOnPlane(pt,v,1e-12,n);
2613 CPPUNIT_ASSERT_EQUAL(9,(int)n.size());
2614 MEDCouplingUMesh *m3dSurf=(MEDCouplingUMesh *)mesh->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
2615 MEDCouplingExtrudedMesh *me=MEDCouplingExtrudedMesh::New(mesh,m3dSurf,0);
2616 const DataArrayInt *da=me->getMesh3DIds();
2617 CPPUNIT_ASSERT_EQUAL(8,me->getNumberOfCells());
2618 const int expected[8]={0,1,2,3,4,5,6,7};
2619 const int *val=da->getConstPointer();
2620 for(int i=0;i<8;i++)
2621 CPPUNIT_ASSERT_EQUAL(expected[i],val[i]);
2627 void MEDCouplingBasicsTest1::testRenumberCells()
2629 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
2630 MEDCouplingUMesh *m2=build3DSurfTargetMesh_1();
2631 CPPUNIT_ASSERT(m->isEqual(m2,0));
2632 const int arr[5]={12,3,25,2,26};
2633 m->renumberCells(arr,true);
2634 CPPUNIT_ASSERT(!m->isEqual(m2,0));
2635 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(0));
2636 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(1));
2637 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(2));
2638 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(3));
2639 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(4));
2640 const int arr2[5]={5,-1,-5,4,8};
2641 m->renumberCells(arr2,true);
2642 CPPUNIT_ASSERT(m->isEqual(m2,0));
2647 void MEDCouplingBasicsTest1::testChangeSpaceDimension()
2649 MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
2650 MEDCouplingUMesh *m2=build2DTargetMesh_1();
2652 CPPUNIT_ASSERT_EQUAL(3,m1->getSpaceDimension());
2653 m1->changeSpaceDimension(2);
2654 CPPUNIT_ASSERT_EQUAL(2,m1->getSpaceDimension());
2655 m1->setName(m2->getName());
2656 CPPUNIT_ASSERT(m1->isEqual(m2,1e-12));
2657 m1->changeSpaceDimension(3);
2658 CPPUNIT_ASSERT_EQUAL(3,m1->getSpaceDimension());
2659 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.};
2660 const double *val=m1->getCoords()->getConstPointer();
2661 for(int i=0;i<27;i++)
2662 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected[i],val[i],1e-14);
2668 void MEDCouplingBasicsTest1::testSetConnectivity()
2670 MEDCouplingUMesh *m1 = build1DTargetMesh_1();
2672 DataArrayInt * conn = DataArrayInt::New();
2673 DataArrayInt * connI = DataArrayInt::New();
2674 m1->setConnectivity(conn, connI, true); // was SEG-Faulting with empty arrays