1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "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 MEDCoupling;
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,
142 CPPUNIT_ASSERT_EQUAL(MEDCouplingMesh::GetNumberOfNodesOfGeometricType(INTERP_KERNEL::NORM_TRI3),3);
143 CPPUNIT_ASSERT(MEDCouplingMesh::IsStaticGeometricType(INTERP_KERNEL::NORM_TRI3));
144 CPPUNIT_ASSERT(MEDCouplingMesh::IsLinearGeometricType(INTERP_KERNEL::NORM_TRI3));
145 CPPUNIT_ASSERT_EQUAL(MEDCouplingMesh::GetDimensionOfGeometricType(INTERP_KERNEL::NORM_TRI3),2);
146 CPPUNIT_ASSERT_EQUAL(std::string(MEDCouplingMesh::GetReprOfGeometricType(INTERP_KERNEL::NORM_TRI3)),std::string("NORM_TRI3"));
147 CPPUNIT_ASSERT_THROW(MEDCouplingMesh::GetNumberOfNodesOfGeometricType(INTERP_KERNEL::NORM_POLYGON),INTERP_KERNEL::Exception);
148 CPPUNIT_ASSERT(!MEDCouplingMesh::IsStaticGeometricType(INTERP_KERNEL::NORM_POLYGON));
149 CPPUNIT_ASSERT(MEDCouplingMesh::IsLinearGeometricType(INTERP_KERNEL::NORM_POLYGON));
150 CPPUNIT_ASSERT_EQUAL(MEDCouplingMesh::GetDimensionOfGeometricType(INTERP_KERNEL::NORM_POLYGON),2);
151 CPPUNIT_ASSERT_EQUAL(std::string(MEDCouplingMesh::GetReprOfGeometricType(INTERP_KERNEL::NORM_POLYGON)),std::string("NORM_POLYGON"));
152 CPPUNIT_ASSERT_EQUAL(MEDCouplingMesh::GetNumberOfNodesOfGeometricType(INTERP_KERNEL::NORM_TRI6),6);
153 CPPUNIT_ASSERT(MEDCouplingMesh::IsStaticGeometricType(INTERP_KERNEL::NORM_TRI6));
154 CPPUNIT_ASSERT(!MEDCouplingMesh::IsLinearGeometricType(INTERP_KERNEL::NORM_TRI6));
155 CPPUNIT_ASSERT_EQUAL(MEDCouplingMesh::GetDimensionOfGeometricType(INTERP_KERNEL::NORM_TRI6),2);
156 CPPUNIT_ASSERT_EQUAL(std::string(MEDCouplingMesh::GetReprOfGeometricType(INTERP_KERNEL::NORM_TRI6)),std::string("NORM_TRI6"));
157 MEDCouplingUMesh *mesh=MEDCouplingUMesh::New();
158 mesh->setMeshDimension(2);
159 mesh->allocateCells(8);
160 const int *curConn=tab4;
161 for(int i=0;i<nbOfCells;i++,curConn+=4)
162 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,curConn);
163 mesh->finishInsertingCells();
164 CPPUNIT_ASSERT_EQUAL((std::size_t)30,mesh->getNodalConnectivity()->getNbOfElems());
165 CPPUNIT_ASSERT_EQUAL(nbOfCells,mesh->getNumberOfCells());
166 //test 0 - no copy no ownership
167 DataArrayDouble *myCoords=DataArrayDouble::New();
168 myCoords->useArray(coords,false,CPP_DEALLOC,nbOfNodes,3);
169 mesh->setCoords(myCoords);
170 mesh->setCoords(myCoords);
172 CPPUNIT_ASSERT_EQUAL(nbOfCells,mesh->getNumberOfCells());
173 mesh->checkCoherency();
174 //test 1 - no copy ownership C++
175 myCoords=DataArrayDouble::New();
176 double *tmp=new double[3*nbOfNodes];
177 std::copy(coords,coords+3*nbOfNodes,tmp);
178 myCoords->useArray(tmp,true,CPP_DEALLOC,nbOfNodes,3);
179 mesh->setCoords(myCoords);
181 CPPUNIT_ASSERT_EQUAL(nbOfCells,mesh->getNumberOfCells());
182 mesh->checkCoherency();
183 //test 2 - no copy ownership C
184 myCoords=DataArrayDouble::New();
185 tmp=(double *)malloc(3*nbOfNodes*sizeof(double));
186 std::copy(coords,coords+3*nbOfNodes,tmp);
187 myCoords->useArray(tmp,true,C_DEALLOC,nbOfNodes,3);
188 mesh->setCoords(myCoords);
190 CPPUNIT_ASSERT_EQUAL(nbOfNodes,mesh->getNumberOfNodes());
191 mesh->checkCoherency();
193 myCoords=DataArrayDouble::New();
194 myCoords->alloc(nbOfNodes,3);
195 tmp=myCoords->getPointer();
196 std::copy(coords,coords+3*nbOfNodes,tmp);
197 // test 3 bis deepcopy
198 DataArrayDouble *myCoords2=DataArrayDouble::New();
199 *myCoords2=*myCoords;
200 myCoords2->decrRef();
202 mesh->setCoords(myCoords);
204 CPPUNIT_ASSERT_EQUAL(nbOfNodes,mesh->getNumberOfNodes());
205 mesh->checkCoherency();
206 CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
207 // test clone not recursively
208 MEDCouplingUMesh *mesh2=mesh->clone(false);
209 CPPUNIT_ASSERT(mesh2!=mesh);
210 mesh2->checkCoherency();
211 CPPUNIT_ASSERT_EQUAL(nbOfCells,mesh2->getNumberOfCells());
212 CPPUNIT_ASSERT_EQUAL(nbOfNodes,mesh2->getNumberOfNodes());
213 CPPUNIT_ASSERT_EQUAL(3,mesh2->getSpaceDimension());
214 CPPUNIT_ASSERT(mesh!=mesh2);
215 CPPUNIT_ASSERT(mesh->getCoords()==mesh2->getCoords());
216 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.2863,mesh2->getCoords()->getIJ(11,2),1e-14);
217 CPPUNIT_ASSERT(mesh->getNodalConnectivity()==mesh2->getNodalConnectivity());
218 CPPUNIT_ASSERT_EQUAL(3,mesh2->getNodalConnectivity()->getIJ(7,0));
219 CPPUNIT_ASSERT(mesh->getNodalConnectivityIndex()==mesh2->getNodalConnectivityIndex());
220 CPPUNIT_ASSERT_EQUAL(15,mesh2->getNodalConnectivityIndex()->getIJ(3,0));
222 // test clone not recursively
223 MEDCouplingUMesh *mesh3=mesh->clone(true);
224 CPPUNIT_ASSERT(mesh3!=mesh);
225 mesh3->checkCoherency();
226 CPPUNIT_ASSERT_EQUAL(nbOfCells,mesh3->getNumberOfCells());
227 CPPUNIT_ASSERT_EQUAL(nbOfNodes,mesh3->getNumberOfNodes());
228 CPPUNIT_ASSERT_EQUAL(3,mesh3->getSpaceDimension());
229 CPPUNIT_ASSERT(mesh!=mesh3);
230 CPPUNIT_ASSERT(mesh->getCoords()!=mesh3->getCoords());
231 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.2863,mesh3->getCoords()->getIJ(11,2),1e-14);
232 CPPUNIT_ASSERT(mesh->getNodalConnectivity()!=mesh3->getNodalConnectivity());
233 CPPUNIT_ASSERT_EQUAL(3,mesh3->getNodalConnectivity()->getIJ(7,0));
234 CPPUNIT_ASSERT(mesh->getNodalConnectivityIndex()!=mesh3->getNodalConnectivityIndex());
235 CPPUNIT_ASSERT_EQUAL(15,mesh3->getNodalConnectivityIndex()->getIJ(3,0));
237 //test 4 - Field on cells
238 MEDCouplingFieldDouble *fieldOnCells=MEDCouplingFieldDouble::New(ON_CELLS);
239 fieldOnCells->setMesh(mesh);
240 DataArrayDouble *array=DataArrayDouble::New();
241 array->alloc(nbOfCells,9);
242 fieldOnCells->setArray(array);
243 tmp=array->getPointer();
245 std::fill(tmp,tmp+9*nbOfCells,7.);
246 //content of field changed -> declare it.
247 fieldOnCells->declareAsNew();
248 fieldOnCells->checkCoherency();
249 // testing clone of fields - no recursive
250 MEDCouplingFieldDouble *fieldOnCells2=fieldOnCells->clone(false);
251 CPPUNIT_ASSERT(fieldOnCells2!=fieldOnCells);
252 fieldOnCells2->checkCoherency();
253 CPPUNIT_ASSERT_EQUAL(nbOfCells,fieldOnCells2->getNumberOfTuples());
254 CPPUNIT_ASSERT_EQUAL(9,fieldOnCells2->getNumberOfComponents());
255 CPPUNIT_ASSERT(fieldOnCells2->getArray()==fieldOnCells->getArray());
256 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,fieldOnCells2->getArray()->getIJ(3,7),1e-14);
257 CPPUNIT_ASSERT(fieldOnCells2->getMesh()==fieldOnCells->getMesh());
258 // testing clone of fields - recursive
259 MEDCouplingFieldDouble *fieldOnCells3=fieldOnCells->clone(true);
260 CPPUNIT_ASSERT(fieldOnCells3!=fieldOnCells);
261 fieldOnCells3->checkCoherency();
262 CPPUNIT_ASSERT_EQUAL(nbOfCells,fieldOnCells3->getNumberOfTuples());
263 CPPUNIT_ASSERT_EQUAL(9,fieldOnCells3->getNumberOfComponents());
264 CPPUNIT_ASSERT(fieldOnCells3->getArray()!=fieldOnCells->getArray());
265 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,fieldOnCells3->getArray()->getIJ(3,7),1e-14);
266 CPPUNIT_ASSERT(fieldOnCells3->getMesh()==fieldOnCells->getMesh());
267 fieldOnCells2->decrRef();
268 fieldOnCells3->decrRef();
270 fieldOnCells->decrRef();
275 void MEDCouplingBasicsTest1::testMeshPointsCloud()
277 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};
278 const int targetConn[]={0,1,2,3,4,5,7,6};
279 MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
280 targetMesh->setMeshDimension(0);
281 targetMesh->allocateCells(8);
282 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn);
283 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+1);
284 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+2);
285 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+3);
286 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+4);
287 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+5);
288 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+6);
289 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+7);
290 targetMesh->finishInsertingCells();
291 CPPUNIT_ASSERT_THROW(targetMesh->checkCoherency(),INTERP_KERNEL::Exception);
292 DataArrayDouble *myCoords=DataArrayDouble::New();
293 myCoords->alloc(9,3);
294 std::copy(targetCoords,targetCoords+27,myCoords->getPointer());
295 targetMesh->setCoords(myCoords);
298 targetMesh->checkCoherency();
299 CPPUNIT_ASSERT_EQUAL(3,targetMesh->getSpaceDimension());
300 CPPUNIT_ASSERT_EQUAL(8,targetMesh->getNumberOfCells());
301 CPPUNIT_ASSERT_EQUAL(9,targetMesh->getNumberOfNodes());
302 CPPUNIT_ASSERT_EQUAL(0,targetMesh->getMeshDimension());
304 targetMesh->decrRef();
307 void MEDCouplingBasicsTest1::testMeshM1D()
309 MEDCouplingUMesh *meshM1D=MEDCouplingUMesh::New();
310 CPPUNIT_ASSERT_THROW(meshM1D->getMeshDimension(),INTERP_KERNEL::Exception);
311 CPPUNIT_ASSERT_THROW(meshM1D->getNumberOfNodes(),INTERP_KERNEL::Exception);
312 CPPUNIT_ASSERT_THROW(meshM1D->getNumberOfCells(),INTERP_KERNEL::Exception);
313 CPPUNIT_ASSERT_THROW(meshM1D->setMeshDimension(-2),INTERP_KERNEL::Exception);
314 CPPUNIT_ASSERT_THROW(meshM1D->setMeshDimension(-10),INTERP_KERNEL::Exception);
315 CPPUNIT_ASSERT_THROW(meshM1D->checkCoherency(),INTERP_KERNEL::Exception);
316 meshM1D->setMeshDimension(-1);
317 meshM1D->checkCoherency();
318 CPPUNIT_ASSERT_EQUAL(-1,meshM1D->getMeshDimension());
319 CPPUNIT_ASSERT_EQUAL(1,meshM1D->getNumberOfCells());
320 CPPUNIT_ASSERT_THROW(meshM1D->getNumberOfNodes(),INTERP_KERNEL::Exception);
321 CPPUNIT_ASSERT_THROW(meshM1D->getSpaceDimension(),INTERP_KERNEL::Exception);
322 MEDCouplingUMesh *cpy=meshM1D->clone(true);
323 CPPUNIT_ASSERT(cpy->isEqual(meshM1D,1e-12));
325 MEDCouplingFieldDouble *fieldOnCells=MEDCouplingFieldDouble::New(ON_CELLS);
326 fieldOnCells->setMesh(meshM1D);
327 DataArrayDouble *array=DataArrayDouble::New();
329 fieldOnCells->setArray(array);
330 double *tmp=array->getPointer();
332 std::fill(tmp,tmp+6,7.);
333 fieldOnCells->checkCoherency();
335 fieldOnCells->decrRef();
339 void MEDCouplingBasicsTest1::testDeepCopy()
341 DataArrayDouble *array=DataArrayDouble::New();
343 std::fill(array->getPointer(),array->getPointer()+5*3,7.);
344 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,array->getIJ(3,2),1e-14);
345 double *tmp1=array->getPointer();
346 DataArrayDouble *array2=array->deepCpy();
347 double *tmp2=array2->getPointer();
348 CPPUNIT_ASSERT(tmp1!=tmp2);
350 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,array2->getIJ(3,2),1e-14);
353 DataArrayInt *array3=DataArrayInt::New();
355 std::fill(array3->getPointer(),array3->getPointer()+5*3,17);
356 CPPUNIT_ASSERT_EQUAL(17,array3->getIJ(3,2));
357 int *tmp3=array3->getPointer();
358 DataArrayInt *array4=array3->deepCpy();
359 int *tmp4=array4->getPointer();
360 CPPUNIT_ASSERT(tmp3!=tmp4);
362 CPPUNIT_ASSERT_EQUAL(17,array4->getIJ(3,2));
366 void MEDCouplingBasicsTest1::testRevNodal()
368 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
369 DataArrayInt *revNodal=DataArrayInt::New();
370 DataArrayInt *revNodalIndx=DataArrayInt::New();
372 mesh->getReverseNodalConnectivity(revNodal,revNodalIndx);
373 const int revNodalExpected[18]={0,0,1,1,2,0,3,0,1,2,3,4,2,4,3,3,4,4};
374 const int revNodalIndexExpected[10]={0,1,3,5,7,12,14,15,17,18};
375 CPPUNIT_ASSERT_EQUAL((std::size_t)18,revNodal->getNbOfElems());
376 CPPUNIT_ASSERT_EQUAL((std::size_t)10,revNodalIndx->getNbOfElems());
377 CPPUNIT_ASSERT(std::equal(revNodalExpected,revNodalExpected+18,revNodal->getPointer()));
378 CPPUNIT_ASSERT(std::equal(revNodalIndexExpected,revNodalIndexExpected+10,revNodalIndx->getPointer()));
381 revNodalIndx->decrRef();
385 void MEDCouplingBasicsTest1::testConvertToPolyTypes()
388 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
390 const int elts[2]={1,3};
391 std::vector<int> eltsV(elts,elts+2);
392 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
393 mesh->checkCoherency();
394 CPPUNIT_ASSERT_EQUAL(5,mesh->getNumberOfCells());
395 CPPUNIT_ASSERT_EQUAL(23,mesh->getNodalConnectivity()->getNumberOfTuples());
396 const int *pt=mesh->getNodalConnectivity()->getConstPointer();
397 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};
398 CPPUNIT_ASSERT(std::equal(expected1,expected1+23,pt));
402 mesh=build3DTargetMesh_1();
403 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
404 mesh->checkCoherency();
405 CPPUNIT_ASSERT_EQUAL(8,mesh->getNumberOfCells());
406 CPPUNIT_ASSERT_EQUAL(114,mesh->getNodalConnectivity()->getNumberOfTuples());
407 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
408 mesh->checkCoherency();
409 CPPUNIT_ASSERT_EQUAL(8,mesh->getNumberOfCells());
410 CPPUNIT_ASSERT_EQUAL(114,mesh->getNodalConnectivity()->getNumberOfTuples());
415 void MEDCouplingBasicsTest1::testDescConn2D()
417 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
418 DataArrayInt *desc=DataArrayInt::New();
419 DataArrayInt *descIndx=DataArrayInt::New();
420 DataArrayInt *revDesc=DataArrayInt::New();
421 DataArrayInt *revDescIndx=DataArrayInt::New();
423 MEDCouplingUMesh *mesh2=mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
424 mesh2->checkCoherency();
425 CPPUNIT_ASSERT_EQUAL(1,mesh2->getMeshDimension());
426 CPPUNIT_ASSERT_EQUAL(13,mesh2->getNumberOfCells());
427 CPPUNIT_ASSERT_EQUAL((std::size_t)14,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(14,revDescIndx->getNumberOfTuples());
428 CPPUNIT_ASSERT_EQUAL((std::size_t)6,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(6,descIndx->getNumberOfTuples());
429 CPPUNIT_ASSERT_EQUAL((std::size_t)18,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,desc->getNumberOfTuples());
430 CPPUNIT_ASSERT_EQUAL((std::size_t)18,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,revDesc->getNumberOfTuples());
431 const int expected1[18]={0,1,2,3, 2,4,5, 6,7,4, 8,9,1,10, 11,12,6,9};
432 CPPUNIT_ASSERT(std::equal(expected1,expected1+18,desc->getConstPointer()));
433 const int expected2[6]={0,4,7,10,14,18};
434 CPPUNIT_ASSERT(std::equal(expected2,expected2+6,descIndx->getConstPointer()));
435 const int expected3[14]={0,1,3,5,6,8,9,11,12,13,15,16,17,18};
436 CPPUNIT_ASSERT(std::equal(expected3,expected3+14,revDescIndx->getConstPointer()));
437 const int expected4[18]={0, 0,3, 0,1, 0, 1,2, 1, 2,4, 2, 3, 3,4, 3, 4, 4};
438 CPPUNIT_ASSERT(std::equal(expected4,expected4+18,revDesc->getConstPointer()));
439 DataArrayInt *conn=mesh2->getNodalConnectivity();
440 DataArrayInt *connIndex=mesh2->getNodalConnectivityIndex();
441 const int expected5[14]={0,3,6,9,12,15,18,21,24,27,30,33,36,39};
442 CPPUNIT_ASSERT(std::equal(expected5,expected5+14,connIndex->getConstPointer()));
443 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};
444 CPPUNIT_ASSERT(std::equal(expected6,expected6+39,conn->getConstPointer()));
449 revDescIndx->decrRef();
452 const int elts[2]={1,3};
453 std::vector<int> eltsV(elts,elts+2);
454 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
455 mesh->checkCoherency();
457 desc=DataArrayInt::New();
458 descIndx=DataArrayInt::New();
459 revDesc=DataArrayInt::New();
460 revDescIndx=DataArrayInt::New();
462 mesh2=mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
463 mesh2->checkCoherency();
464 CPPUNIT_ASSERT_EQUAL(1,mesh2->getMeshDimension());
465 CPPUNIT_ASSERT_EQUAL(13,mesh2->getNumberOfCells());
466 CPPUNIT_ASSERT_EQUAL((std::size_t)14,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(14,revDescIndx->getNumberOfTuples());
467 CPPUNIT_ASSERT_EQUAL((std::size_t)6,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(6,descIndx->getNumberOfTuples());
468 CPPUNIT_ASSERT_EQUAL((std::size_t)18,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,desc->getNumberOfTuples());
469 CPPUNIT_ASSERT_EQUAL((std::size_t)18,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,revDesc->getNumberOfTuples());
470 CPPUNIT_ASSERT(std::equal(expected1,expected1+18,desc->getConstPointer()));
471 CPPUNIT_ASSERT(std::equal(expected2,expected2+6,descIndx->getConstPointer()));
472 CPPUNIT_ASSERT(std::equal(expected3,expected3+14,revDescIndx->getConstPointer()));
473 CPPUNIT_ASSERT(std::equal(expected4,expected4+18,revDesc->getConstPointer()));
474 conn=mesh2->getNodalConnectivity();
475 connIndex=mesh2->getNodalConnectivityIndex();
476 CPPUNIT_ASSERT(std::equal(expected5,expected5+14,connIndex->getConstPointer()));
477 CPPUNIT_ASSERT(std::equal(expected6,expected6+39,conn->getConstPointer()));
482 revDescIndx->decrRef();
487 void MEDCouplingBasicsTest1::testDescConn3D()
489 MEDCouplingUMesh *mesh=build3DTargetMesh_1();
490 DataArrayInt *desc=DataArrayInt::New();
491 DataArrayInt *descIndx=DataArrayInt::New();
492 DataArrayInt *revDesc=DataArrayInt::New();
493 DataArrayInt *revDescIndx=DataArrayInt::New();
495 MEDCouplingUMesh *mesh2=mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
496 mesh2->checkCoherency();
497 CPPUNIT_ASSERT_EQUAL(2,mesh2->getMeshDimension());
498 CPPUNIT_ASSERT_EQUAL(36,mesh2->getNumberOfCells());
499 CPPUNIT_ASSERT_EQUAL((std::size_t)37,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(37,revDescIndx->getNumberOfTuples());
500 CPPUNIT_ASSERT_EQUAL((std::size_t)9,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(9,descIndx->getNumberOfTuples());
501 CPPUNIT_ASSERT_EQUAL((std::size_t)48,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,desc->getNumberOfTuples());
502 CPPUNIT_ASSERT_EQUAL((std::size_t)48,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,revDesc->getNumberOfTuples());
503 const int expected1[9]={0, 6, 12, 18, 24, 30, 36, 42, 48};
504 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};
505 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};
506 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};
507 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};
508 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,
509 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,
510 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,
511 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};
512 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,
513 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,
514 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,
515 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};
517 CPPUNIT_ASSERT(std::equal(expected1,expected1+9,descIndx->getConstPointer()));
518 CPPUNIT_ASSERT(std::equal(expected2,expected2+48,desc->getConstPointer()));
519 CPPUNIT_ASSERT(std::equal(expected3,expected3+37,revDescIndx->getConstPointer()));
520 CPPUNIT_ASSERT(std::equal(expected4,expected4+48,revDesc->getConstPointer()));
521 CPPUNIT_ASSERT(std::equal(expected5,expected5+37,mesh2->getNodalConnectivityIndex()->getConstPointer()));
522 CPPUNIT_ASSERT(std::equal(expected6,expected6+180,mesh2->getNodalConnectivity()->getConstPointer()));
527 revDescIndx->decrRef();
530 const int elts[2]={1,3};
531 std::vector<int> eltsV(elts,elts+2);
532 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
533 mesh->checkCoherency();
534 desc=DataArrayInt::New();
535 descIndx=DataArrayInt::New();
536 revDesc=DataArrayInt::New();
537 revDescIndx=DataArrayInt::New();
538 mesh2=mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
539 mesh2->checkCoherency();
540 CPPUNIT_ASSERT_EQUAL(2,mesh2->getMeshDimension());
541 CPPUNIT_ASSERT_EQUAL(36,mesh2->getNumberOfCells());
542 CPPUNIT_ASSERT_EQUAL((std::size_t)37,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(37,revDescIndx->getNumberOfTuples());
543 CPPUNIT_ASSERT_EQUAL((std::size_t)9,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(9,descIndx->getNumberOfTuples());
544 CPPUNIT_ASSERT_EQUAL((std::size_t)48,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,desc->getNumberOfTuples());
545 CPPUNIT_ASSERT_EQUAL((std::size_t)48,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,revDesc->getNumberOfTuples());
546 CPPUNIT_ASSERT(std::equal(expected1,expected1+9,descIndx->getConstPointer()));
547 CPPUNIT_ASSERT(std::equal(expected2,expected2+48,desc->getConstPointer()));
548 CPPUNIT_ASSERT(std::equal(expected3,expected3+37,revDescIndx->getConstPointer()));
549 CPPUNIT_ASSERT(std::equal(expected4,expected4+48,revDesc->getConstPointer()));
550 CPPUNIT_ASSERT(std::equal(expected5,expected5+37,mesh2->getNodalConnectivityIndex()->getConstPointer()));
551 CPPUNIT_ASSERT(std::equal(expected7,expected7+180,mesh2->getNodalConnectivity()->getConstPointer()));
556 revDescIndx->decrRef();
561 void MEDCouplingBasicsTest1::testFindBoundaryNodes()
563 MEDCouplingUMesh *mesh=build3DTargetMesh_1();
564 DataArrayInt *boundaryNodes=mesh->findBoundaryNodes();
565 CPPUNIT_ASSERT_EQUAL(26,boundaryNodes->getNumberOfTuples());
566 CPPUNIT_ASSERT_EQUAL(1,boundaryNodes->getNumberOfComponents());
567 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};
568 CPPUNIT_ASSERT(std::equal(expected1,expected1+26,boundaryNodes->begin()));
569 boundaryNodes->decrRef();
573 void MEDCouplingBasicsTest1::testBoundaryMesh()
575 MEDCouplingUMesh *mesh=build3DTargetMesh_1();
576 MEDCouplingPointSet *mesh2=mesh->buildBoundaryMesh(false);
577 CPPUNIT_ASSERT_EQUAL(24,mesh2->getNumberOfCells());
578 CPPUNIT_ASSERT_EQUAL(26,mesh2->getNumberOfNodes());
583 void MEDCouplingBasicsTest1::testBuildPartOfMySelf()
585 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
586 mesh->setName("Toto");
587 const int tab1[2]={0,4};
588 const int tab2[3]={0,2,3};
590 MEDCouplingPointSet *subMeshSimple=mesh->buildPartOfMySelf(tab1,tab1+2,true);
591 MEDCouplingUMesh *subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
592 CPPUNIT_ASSERT(subMesh);
593 std::string name(subMesh->getName());
594 CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllGeoTypes().size());
595 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*mesh->getAllGeoTypes().begin());
596 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++(mesh->getAllGeoTypes().begin())));
597 CPPUNIT_ASSERT_EQUAL(1,(int)subMesh->getAllGeoTypes().size());
598 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllGeoTypes().begin());
599 CPPUNIT_ASSERT(name=="Toto");
600 CPPUNIT_ASSERT(mesh->getCoords()==subMesh->getCoords());
601 CPPUNIT_ASSERT_EQUAL(2,subMesh->getNumberOfCells());
602 const int subConn[10]={4,0,3,4,1,4,7,8,5,4};
603 const int subConnIndex[3]={0,5,10};
604 CPPUNIT_ASSERT_EQUAL((std::size_t)10,subMesh->getNodalConnectivity()->getNbOfElems());
605 CPPUNIT_ASSERT_EQUAL((std::size_t)3,subMesh->getNodalConnectivityIndex()->getNbOfElems());
606 CPPUNIT_ASSERT(std::equal(subConn,subConn+10,subMesh->getNodalConnectivity()->getPointer()));
607 CPPUNIT_ASSERT(std::equal(subConnIndex,subConnIndex+3,subMesh->getNodalConnectivityIndex()->getPointer()));
610 subMeshSimple=mesh->buildPartOfMySelf(tab2,tab2+3,true);
611 subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
612 CPPUNIT_ASSERT(subMesh);
613 name=subMesh->getName();
614 CPPUNIT_ASSERT_EQUAL(2,(int)subMesh->getAllGeoTypes().size());
615 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*subMesh->getAllGeoTypes().begin());
616 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++(subMesh->getAllGeoTypes().begin())));
617 CPPUNIT_ASSERT(name=="Toto");
618 CPPUNIT_ASSERT(mesh->getCoords()==subMesh->getCoords());
619 CPPUNIT_ASSERT_EQUAL(3,subMesh->getNumberOfCells());
620 const int subConn2[14]={4,0,3,4,1,3,4,5,2,4,6,7,4,3};
621 const int subConnIndex2[4]={0,5,9,14};
622 CPPUNIT_ASSERT_EQUAL((std::size_t)14,subMesh->getNodalConnectivity()->getNbOfElems());
623 CPPUNIT_ASSERT_EQUAL((std::size_t)4,subMesh->getNodalConnectivityIndex()->getNbOfElems());
624 CPPUNIT_ASSERT(std::equal(subConn2,subConn2+14,subMesh->getNodalConnectivity()->getPointer()));
625 CPPUNIT_ASSERT(std::equal(subConnIndex2,subConnIndex2+4,subMesh->getNodalConnectivityIndex()->getPointer()));
626 const int tab3[3]={0,1,2};
627 MEDCouplingPointSet *subMeshSimple2=subMeshSimple->buildPartOfMySelf(tab3,tab3+3,true);
629 name=subMeshSimple2->getName();
630 CPPUNIT_ASSERT(name=="Toto");
631 subMeshSimple2->decrRef();
636 void MEDCouplingBasicsTest1::testBuildPartOfMySelfNode()
638 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
639 const int tab1[4]={5,7,8,4};
640 MEDCouplingPointSet *subMeshSimple=mesh->buildPartOfMySelfNode(tab1,tab1+4,true);
641 MEDCouplingUMesh *subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
642 CPPUNIT_ASSERT(subMesh);
643 CPPUNIT_ASSERT_EQUAL(1,(int)subMesh->getAllGeoTypes().size());
644 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllGeoTypes().begin());
645 CPPUNIT_ASSERT_EQUAL(1,subMesh->getNumberOfCells());
646 CPPUNIT_ASSERT_EQUAL((std::size_t)5,subMesh->getNodalConnectivity()->getNbOfElems());
647 CPPUNIT_ASSERT_EQUAL((std::size_t)2,subMesh->getNodalConnectivityIndex()->getNbOfElems());
648 const int subConn[5]={4,7,8,5,4};
649 const int subConnIndex[3]={0,5};
650 CPPUNIT_ASSERT(std::equal(subConn,subConn+5,subMesh->getNodalConnectivity()->getPointer()));
651 CPPUNIT_ASSERT(std::equal(subConnIndex,subConnIndex+2,subMesh->getNodalConnectivityIndex()->getPointer()));
652 CPPUNIT_ASSERT(subMesh->getCoords()==mesh->getCoords());
653 subMeshSimple->decrRef();
655 subMeshSimple=mesh->buildPartOfMySelfNode(tab1,tab1+2,false);
656 subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
657 CPPUNIT_ASSERT(subMesh);
658 CPPUNIT_ASSERT_EQUAL(2,(int)subMesh->getAllGeoTypes().size());
659 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*subMesh->getAllGeoTypes().begin());
660 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++subMesh->getAllGeoTypes().begin()));
661 CPPUNIT_ASSERT_EQUAL(3,subMesh->getNumberOfCells());
662 CPPUNIT_ASSERT_EQUAL((std::size_t)14,subMesh->getNodalConnectivity()->getNbOfElems());
663 CPPUNIT_ASSERT_EQUAL((std::size_t)4,subMesh->getNodalConnectivityIndex()->getNbOfElems());
664 const int subConn2[14]={3,4,5,2,4,6,7,4,3,4,7,8,5,4};
665 const int subConnIndex2[4]={0,4,9,14};
666 CPPUNIT_ASSERT(std::equal(subConn2,subConn2+14,subMesh->getNodalConnectivity()->getPointer()));
667 CPPUNIT_ASSERT(std::equal(subConnIndex2,subConnIndex2+4,subMesh->getNodalConnectivityIndex()->getPointer()));
668 CPPUNIT_ASSERT(subMesh->getCoords()==mesh->getCoords());
669 subMeshSimple->decrRef();
670 //testing the case where length of tab2 is greater than max number of node per cell.
671 const int tab2[7]={0,3,2,1,4,5,6};
672 subMeshSimple=mesh->buildPartOfMySelfNode(tab2,tab2+7,true);
673 subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
674 CPPUNIT_ASSERT(subMesh);
675 CPPUNIT_ASSERT_EQUAL(2,(int)subMesh->getAllGeoTypes().size());
676 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*subMesh->getAllGeoTypes().begin());
677 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++subMesh->getAllGeoTypes().begin()));
678 CPPUNIT_ASSERT_EQUAL(3,subMesh->getNumberOfCells());
679 subMeshSimple->decrRef();
684 void MEDCouplingBasicsTest1::testZipCoords()
686 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
687 CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllGeoTypes().size());
688 CPPUNIT_ASSERT_EQUAL(2,mesh->getSpaceDimension());
689 CPPUNIT_ASSERT_EQUAL(9,mesh->getNumberOfNodes());
690 CPPUNIT_ASSERT_EQUAL(5,mesh->getNumberOfCells());
691 std::vector<int> oldConn(mesh->getNodalConnectivity()->getNbOfElems());
692 std::vector<int> oldConnIndex(mesh->getNumberOfCells()+1);
693 std::copy(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+oldConn.size(),oldConn.begin());
694 std::copy(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+mesh->getNumberOfCells()+1,oldConnIndex.begin());
695 DataArrayDouble *oldCoords=mesh->getCoords();
696 oldCoords->incrRef();
698 CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllGeoTypes().size());
699 CPPUNIT_ASSERT_EQUAL(2,mesh->getSpaceDimension());
700 CPPUNIT_ASSERT_EQUAL(9,mesh->getNumberOfNodes());
701 CPPUNIT_ASSERT_EQUAL(5,mesh->getNumberOfCells());
702 CPPUNIT_ASSERT(mesh->getCoords()!=oldCoords);
703 CPPUNIT_ASSERT(std::equal(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+2*9,oldCoords->getPointer()));
704 CPPUNIT_ASSERT(std::equal(oldConn.begin(),oldConn.end(),mesh->getNodalConnectivity()->getPointer()));
705 CPPUNIT_ASSERT(std::equal(oldConnIndex.begin(),oldConnIndex.end(),mesh->getNodalConnectivityIndex()->getPointer()));
706 oldCoords->decrRef();
708 const int tab1[2]={0,4};
709 MEDCouplingPointSet *subMeshPtSet=mesh->buildPartOfMySelf(tab1,tab1+2,true);
710 MEDCouplingUMesh *subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshPtSet);
711 CPPUNIT_ASSERT(subMesh);
712 DataArrayInt *traducer=subMesh->zipCoordsTraducer();
713 const int expectedTraducer[9]={0,1,-1,2,3,4,-1,5,6};
714 CPPUNIT_ASSERT(std::equal(expectedTraducer,expectedTraducer+9,traducer->getPointer()));
716 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllGeoTypes().begin());
717 CPPUNIT_ASSERT_EQUAL(2,subMesh->getNumberOfCells());
718 const int subConn[10]={4,0,2,3,1,4,5,6,4,3};
719 const int subConnIndex[3]={0,5,10};
720 CPPUNIT_ASSERT_EQUAL(7,subMesh->getNumberOfNodes());
721 CPPUNIT_ASSERT_EQUAL((std::size_t)10,subMesh->getNodalConnectivity()->getNbOfElems());
722 CPPUNIT_ASSERT_EQUAL((std::size_t)3,subMesh->getNodalConnectivityIndex()->getNbOfElems());
723 CPPUNIT_ASSERT(std::equal(subConn,subConn+10,subMesh->getNodalConnectivity()->getPointer()));
724 CPPUNIT_ASSERT(std::equal(subConnIndex,subConnIndex+3,subMesh->getNodalConnectivityIndex()->getPointer()));
727 subMeshPtSet=mesh->buildPartOfMySelf(tab1,tab1+2,false);
728 subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshPtSet);
729 CPPUNIT_ASSERT(subMesh);
730 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllGeoTypes().begin());
731 CPPUNIT_ASSERT_EQUAL(2,subMesh->getNumberOfCells());
732 CPPUNIT_ASSERT_EQUAL(7,subMesh->getNumberOfNodes());
733 CPPUNIT_ASSERT_EQUAL((std::size_t)10,subMesh->getNodalConnectivity()->getNbOfElems());
734 CPPUNIT_ASSERT_EQUAL((std::size_t)3,subMesh->getNodalConnectivityIndex()->getNbOfElems());
735 CPPUNIT_ASSERT(std::equal(subConn,subConn+10,subMesh->getNodalConnectivity()->getPointer()));
736 CPPUNIT_ASSERT(std::equal(subConnIndex,subConnIndex+3,subMesh->getNodalConnectivityIndex()->getPointer()));
742 void MEDCouplingBasicsTest1::testZipConnectivity()
744 MEDCouplingUMesh *m1=build2DTargetMesh_1();
745 MEDCouplingUMesh *m2=build2DTargetMesh_1();
746 int cells1[3]={2,3,4};
747 MEDCouplingPointSet *m3_1=m2->buildPartOfMySelf(cells1,cells1+3,true);
748 MEDCouplingUMesh *m3=dynamic_cast<MEDCouplingUMesh *>(m3_1);
751 MEDCouplingUMesh *m4=build2DSourceMesh_1();
752 MEDCouplingUMesh *m5=MEDCouplingUMesh::MergeUMeshes(m1,m3);
755 MEDCouplingUMesh *m6=MEDCouplingUMesh::MergeUMeshes(m5,m4);
761 CPPUNIT_ASSERT_EQUAL(10,m6->getNumberOfCells());
762 CPPUNIT_ASSERT_EQUAL(22,m6->getNumberOfNodes());
763 DataArrayInt *arr=m6->mergeNodes(1e-13,areNodesMerged,newNbOfNodes);
765 CPPUNIT_ASSERT(areNodesMerged);
766 CPPUNIT_ASSERT_EQUAL(10,m6->getNumberOfCells());
767 CPPUNIT_ASSERT_EQUAL(9,m6->getNumberOfNodes());
768 CPPUNIT_ASSERT_EQUAL(9,newNbOfNodes);
770 arr=m6->zipConnectivityTraducer(0);
771 CPPUNIT_ASSERT_EQUAL(7,m6->getNumberOfCells());
773 MEDCouplingUMesh *m7=m6->clone(true);
774 arr=m6->zipConnectivityTraducer(0);
775 CPPUNIT_ASSERT(m7->isEqual(m6,1e-12));
776 CPPUNIT_ASSERT_EQUAL(7,m6->getNumberOfCells());
783 void MEDCouplingBasicsTest1::testEqualMesh()
785 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
786 MEDCouplingUMesh *mesh2=build2DTargetMesh_1();
788 CPPUNIT_ASSERT(mesh1->isEqual(mesh1,1e-12));
790 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
791 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
792 double *pt=mesh2->getCoords()->getPointer();
795 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
796 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
798 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
799 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
801 int *pt2=mesh1->getNodalConnectivity()->getPointer();
803 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
804 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
806 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
807 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
809 pt2=mesh1->getNodalConnectivityIndex()->getPointer();
811 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
812 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
814 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
815 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
817 std::string tmp3=mesh1->getName();
818 mesh1->setName("lllll");
819 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
820 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
821 mesh1->setName(tmp3.c_str());
822 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
823 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
825 tmp3=mesh2->getCoords()->getInfoOnComponent(1);
826 mesh2->getCoords()->setInfoOnComponent(1,"kkkkkk");
827 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
828 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
829 mesh2->getCoords()->setInfoOnComponent(1,tmp3.c_str());
830 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
831 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
837 void MEDCouplingBasicsTest1::testEqualFieldDouble()
839 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
840 MEDCouplingUMesh *mesh2=build2DTargetMesh_1();
842 MEDCouplingFieldDouble *fieldOnCells1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
843 fieldOnCells1->setMesh(mesh1);
844 MEDCouplingFieldDouble *fieldOnCells2=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
845 fieldOnCells2->setMesh(mesh2);
847 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
848 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
849 fieldOnCells2->decrRef();
851 MEDCouplingFieldDouble *fieldOnNodes1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
852 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnNodes1,1e-12,1e-15));
853 CPPUNIT_ASSERT(!fieldOnNodes1->isEqual(fieldOnCells1,1e-12,1e-15));
854 fieldOnNodes1->decrRef();
856 fieldOnCells2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
857 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
858 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
859 fieldOnCells1->decrRef();
860 fieldOnCells1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
861 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
862 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
863 fieldOnCells1->setTime(4.,6,7);
864 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
865 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
866 fieldOnCells2->setTime(4.,6,7);
867 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
868 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
869 fieldOnCells1->setName("Power");
870 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
871 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
872 fieldOnCells2->setName("Power");
873 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
874 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
876 fieldOnCells1->setMesh(mesh1);
877 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
878 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
879 fieldOnCells2->setMesh(mesh1);
880 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
881 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
882 DataArrayDouble *arr=DataArrayDouble::New();
883 arr->setName("popo");
884 arr->alloc(mesh1->getNumberOfCells(),3);
885 double *pt=arr->getPointer();
886 std::fill(pt,pt+mesh1->getNumberOfCells()*3,6.);
887 fieldOnCells1->setArray(arr);
888 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
889 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
890 fieldOnCells2->setArray(arr);
892 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
893 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
895 DataArrayDouble *arr2=arr->deepCpy();
896 fieldOnCells2->setArray(arr2);
898 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
899 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
901 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
902 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
904 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
905 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
906 arr2->setName("popo2");
907 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
908 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
910 arr2->setName("popo");
911 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
912 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
914 arr2->setInfoOnComponent(2,"jjj");
915 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
916 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
917 arr->setInfoOnComponent(2,"jjj");
918 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
919 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
921 fieldOnCells1->decrRef();
922 fieldOnCells2->decrRef();
928 void MEDCouplingBasicsTest1::testNatureChecking()
930 MEDCouplingFieldDouble *field=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
931 field->setNature(Integral);
932 field->setNature(ConservativeVolumic);
933 field->setNature(IntegralGlobConstraint);
935 field=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
936 field->setNature(ConservativeVolumic);
937 CPPUNIT_ASSERT_THROW(field->setNature(Integral),INTERP_KERNEL::Exception);
938 CPPUNIT_ASSERT_THROW(field->setNature(IntegralGlobConstraint),INTERP_KERNEL::Exception);
942 void MEDCouplingBasicsTest1::testBuildSubMeshData()
944 MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
945 //check buildSubMesh on field on cells
946 MEDCouplingFieldDouble *fieldCells=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
947 fieldCells->setMesh(targetMesh);
948 const int elts[3]={1,2,4};
950 MEDCouplingMesh *ret1=fieldCells->buildSubMeshData(elts,elts+3,di);
951 CPPUNIT_ASSERT_EQUAL(3,ret1->getNumberOfCells());
952 CPPUNIT_ASSERT_EQUAL(9,ret1->getNumberOfNodes());
953 CPPUNIT_ASSERT_EQUAL(3,di->getNumberOfTuples());
954 CPPUNIT_ASSERT_EQUAL(1,di->getNumberOfComponents());
955 const int *toCheck=di->getConstPointer();
956 CPPUNIT_ASSERT(std::equal(elts,elts+3,toCheck));
957 MEDCouplingUMesh *ret1DC=dynamic_cast<MEDCouplingUMesh *>(ret1);
958 CPPUNIT_ASSERT(ret1DC);
961 fieldCells->decrRef();
962 //check buildSubMesh on field on nodes
963 MEDCouplingFieldDouble *fieldNodes=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
964 fieldNodes->setMesh(targetMesh);
965 MEDCouplingMesh *ret2=fieldNodes->buildSubMeshData(elts,elts+3,di);
966 MEDCouplingUMesh *ret2DC=dynamic_cast<MEDCouplingUMesh *>(ret2);
967 CPPUNIT_ASSERT(ret2DC);
968 CPPUNIT_ASSERT_EQUAL(3,ret2->getNumberOfCells());
969 CPPUNIT_ASSERT_EQUAL(6,ret2->getNumberOfNodes());
970 CPPUNIT_ASSERT_EQUAL(6,di->getNumberOfTuples());
971 CPPUNIT_ASSERT_EQUAL(1,di->getNumberOfComponents());
972 toCheck=di->getConstPointer();
973 const int expected[6]={1,2,4,5,7,8};
974 CPPUNIT_ASSERT(std::equal(expected,expected+6,toCheck));
977 fieldNodes->decrRef();
978 targetMesh->decrRef();
981 void MEDCouplingBasicsTest1::testExtrudedMesh1()
983 MEDCouplingUMesh *mesh2D=0;
984 MEDCouplingUMesh *mesh3D=build3DExtrudedUMesh_1(mesh2D);
985 MEDCouplingExtrudedMesh *ext=MEDCouplingExtrudedMesh::New(mesh3D,mesh2D,1);
986 CPPUNIT_ASSERT_EQUAL(18,ext->getNumberOfCells());
987 CPPUNIT_ASSERT_EQUAL(60,ext->getNumberOfNodes());
988 DataArrayInt *ids3D=ext->getMesh3DIds();
989 const int ids3DExpected[18]={5,4,3,2,1,0, 11,10,9,8,7,6, 17,16,15,14,13,12};
990 CPPUNIT_ASSERT_EQUAL(18,ids3D->getNumberOfTuples());
991 CPPUNIT_ASSERT_EQUAL(1,ids3D->getNumberOfComponents());
992 CPPUNIT_ASSERT(std::equal(ids3DExpected,ids3DExpected+18,ids3D->getConstPointer()));
993 MEDCouplingUMesh *mesh1D=ext->getMesh1D();
994 CPPUNIT_ASSERT_EQUAL(4,mesh1D->getNumberOfNodes());
995 CPPUNIT_ASSERT_EQUAL(3,mesh1D->getNumberOfCells());
996 const double mesh1DExpected[12]={0.66666666666666663, 1.4583333333333333, 0, 0.66666666666666663, 1.4583333333333333, 1, 0.66666666666666663, 1.4583333333333333, 2, 0.66666666666666663, 1.4583333333333333, 3};
997 DataArrayDouble *mesh1DCoords=mesh1D->getCoords();
998 CPPUNIT_ASSERT_EQUAL(4,mesh1DCoords->getNumberOfTuples());
999 CPPUNIT_ASSERT_EQUAL(3,mesh1DCoords->getNumberOfComponents());
1000 CPPUNIT_ASSERT(std::equal(mesh1DExpected,mesh1DExpected+12,mesh1DCoords->getConstPointer()));
1001 DataArrayInt *conn1D=mesh1D->getNodalConnectivity();
1002 CPPUNIT_ASSERT_EQUAL(9,conn1D->getNumberOfTuples());
1003 CPPUNIT_ASSERT_EQUAL(1,conn1D->getNumberOfComponents());
1004 const int conn1DExpected[9]={1,0,1,1,1,2,1,2,3};
1005 CPPUNIT_ASSERT(std::equal(conn1DExpected,conn1DExpected+9,conn1D->getConstPointer()));
1011 void MEDCouplingBasicsTest1::testExtrudedMesh2()
1013 MEDCouplingUMesh *mN,*mTT,*mTF;
1014 build3DExtrudedUMesh_2(mN,mTT,mTF);
1018 DataArrayInt *da=mTT->mergeNodes(1e-12,b,newNbOfNodes);
1022 double pt[3]={300.,300.,0.};
1023 double v[3]={0.,0.,2.};
1024 mTT->findNodesOnPlane(pt,v,1e-12,n);
1025 CPPUNIT_ASSERT_EQUAL(43,(int)n.size());
1026 MEDCouplingUMesh *mTT3dSurf=(MEDCouplingUMesh *)mTT->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
1027 MEDCouplingExtrudedMesh *meTT=MEDCouplingExtrudedMesh::New(mTT,mTT3dSurf,0);
1028 CPPUNIT_ASSERT_EQUAL(200,meTT->getNumberOfCells());
1029 CPPUNIT_ASSERT_EQUAL(10,meTT->getMesh2D()->getNumberOfCells());
1030 CPPUNIT_ASSERT_EQUAL(20,meTT->getMesh1D()->getNumberOfCells());
1031 mTT3dSurf->decrRef();
1034 da=mN->mergeNodes(1e-12,b,newNbOfNodes);
1038 mN->findNodesOnPlane(pt,v,1e-12,n);
1039 CPPUNIT_ASSERT_EQUAL(30,(int)n.size());
1040 MEDCouplingUMesh *mN3dSurf=(MEDCouplingUMesh *)mN->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
1041 MEDCouplingExtrudedMesh *meN=MEDCouplingExtrudedMesh::New(mN,mN3dSurf,0);
1042 CPPUNIT_ASSERT_EQUAL(40,meN->getNumberOfCells());
1043 CPPUNIT_ASSERT_EQUAL(20,meN->getMesh2D()->getNumberOfCells());
1044 CPPUNIT_ASSERT_EQUAL(2,meN->getMesh1D()->getNumberOfCells());
1045 mN3dSurf->decrRef();
1048 da=mTF->mergeNodes(1e-12,b,newNbOfNodes);
1052 mTF->findNodesOnPlane(pt,v,1e-12,n);
1053 CPPUNIT_ASSERT_EQUAL(27,(int)n.size());
1054 MEDCouplingUMesh *mTF3dSurf=(MEDCouplingUMesh *)mTF->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
1055 MEDCouplingExtrudedMesh *meTF=MEDCouplingExtrudedMesh::New(mTF,mTF3dSurf,0);
1056 CPPUNIT_ASSERT_EQUAL(340,meTF->getNumberOfCells());
1057 CPPUNIT_ASSERT_EQUAL(17,meTF->getMesh2D()->getNumberOfCells());
1058 CPPUNIT_ASSERT_EQUAL(20,meTF->getMesh1D()->getNumberOfCells());
1059 mTF3dSurf->decrRef();
1071 * This test check MEDCouplingUMesh::buildExtrudedMesh method.
1073 void MEDCouplingBasicsTest1::testExtrudedMesh3()
1075 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1076 m1->changeSpaceDimension(3);
1077 MEDCouplingUMesh *m2=buildCU1DMesh_U();
1078 m2->changeSpaceDimension(3);
1079 double center[3]={0.,0.,0.};
1080 double vector[3]={0,1,0};
1081 m2->rotate(center,vector,-M_PI/2.);
1082 MEDCouplingUMesh *m3=m1->buildExtrudedMesh(m2,0);
1084 MEDCouplingExtrudedMesh *m4=MEDCouplingExtrudedMesh::New(m3,m1,0);
1085 CPPUNIT_ASSERT_EQUAL(15,m4->getNumberOfCells());
1086 CPPUNIT_ASSERT_EQUAL(5,m4->getMesh2D()->getNumberOfCells());
1087 CPPUNIT_ASSERT_EQUAL(3,m4->getMesh1D()->getNumberOfCells());
1088 const int *m3DIds=m4->getMesh3DIds()->getConstPointer();
1089 for(int i=0;i<15;i++)
1090 CPPUNIT_ASSERT_EQUAL(i,m3DIds[i]);
1092 //some random in cells to check that extrusion alg find it correctly
1093 const int expected1[15]={1,3,2,0,6,5,7,10,11,8,12,9,14,13,4};
1094 m3->renumberCells(expected1,false);
1095 m4=MEDCouplingExtrudedMesh::New(m3,m1,0);
1096 CPPUNIT_ASSERT_EQUAL(15,m4->getNumberOfCells());
1097 CPPUNIT_ASSERT_EQUAL(5,m4->getMesh2D()->getNumberOfCells());
1098 CPPUNIT_ASSERT_EQUAL(3,m4->getMesh1D()->getNumberOfCells());
1099 m3DIds=m4->getMesh3DIds()->getConstPointer();
1100 for(int i=0;i<15;i++)
1101 CPPUNIT_ASSERT_EQUAL(expected1[i],m3DIds[i]);
1104 //play with polygons and polyedrons
1105 std::vector<int> cells(2); cells[0]=2; cells[1]=3;
1106 m1->convertToPolyTypes(&cells[0],&cells[0]+cells.size());
1107 m3=m1->buildExtrudedMesh(m2,0);
1108 CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_HEXA8,(int)m3->getTypeOfCell(0));
1109 CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_PENTA6,(int)m3->getTypeOfCell(1));
1110 CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_POLYHED,(int)m3->getTypeOfCell(2));
1111 CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_POLYHED,(int)m3->getTypeOfCell(3));
1112 CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_HEXA8,(int)m3->getTypeOfCell(4));
1113 m3->renumberCells(expected1,false);
1114 m4=MEDCouplingExtrudedMesh::New(m3,m1,0);
1115 CPPUNIT_ASSERT_EQUAL(15,m4->getNumberOfCells());
1116 CPPUNIT_ASSERT_EQUAL(5,m4->getMesh2D()->getNumberOfCells());
1117 CPPUNIT_ASSERT_EQUAL(3,m4->getMesh1D()->getNumberOfCells());
1118 m3DIds=m4->getMesh3DIds()->getConstPointer();
1119 for(int i=0;i<15;i++)
1120 CPPUNIT_ASSERT_EQUAL(expected1[i],m3DIds[i]);
1129 * This test check MEDCouplingUMesh::buildExtrudedMesh method, but also, MEDCouplingExtrudedMesh following methods :
1130 * getCellContainingPoint getMeasureField getNodeIdsOfCell getCoordinateOfNode getTypeOfCell build3DUnstructuredMesh.
1132 void MEDCouplingBasicsTest1::testExtrudedMesh4()
1134 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1135 std::vector<int> cells(2); cells[0]=2; cells[1]=4;
1136 m1->convertToPolyTypes(&cells[0],&cells[0]+cells.size());
1137 m1->changeSpaceDimension(3);
1138 MEDCouplingUMesh *m2=buildCU1DMesh_U();
1139 m2->changeSpaceDimension(3);
1140 double center[3]={0.,0.,0.};
1141 double vector[3]={0.,1.,0.};
1142 m2->rotate(center,vector,-M_PI/2.);
1144 MEDCouplingUMesh *m3=m1->buildExtrudedMesh(m2,0);
1145 const int expected1[15]= {1,3,2,0,6,5,7,10,11,8,12,9,14,13,4};
1146 const int rexpected1[15]={3, 0, 2, 1, 14, 5, 4, 6, 9, 11, 7, 8, 10, 13, 12};
1147 m3->renumberCells(expected1,false);
1148 MEDCouplingExtrudedMesh *m4=MEDCouplingExtrudedMesh::New(m3,m1,0);
1149 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,m4->getTypeOfCell(0));
1150 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,m4->getTypeOfCell(1));
1151 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYHED,m4->getTypeOfCell(2));
1152 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_PENTA6,m4->getTypeOfCell(7));
1153 MEDCouplingFieldDouble *f=m4->getMeasureField(true);
1154 DataArrayDouble *arr=f->getArray();
1155 CPPUNIT_ASSERT_EQUAL(15,arr->getNumberOfTuples());
1156 CPPUNIT_ASSERT_EQUAL(1,arr->getNumberOfComponents());
1157 const double *arrPtr=arr->getConstPointer();
1158 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};
1159 for(int i=0;i<15;i++)
1160 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[rexpected1[i]],arrPtr[i],1e-16);
1162 MEDCouplingUMesh *m5=m4->build3DUnstructuredMesh();
1164 CPPUNIT_ASSERT(m5->isEqual(m3,1e-12));
1165 f=m5->getMeasureField(true);
1167 arrPtr=arr->getConstPointer();
1168 for(int i=0;i<15;i++)
1169 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[rexpected1[i]],arrPtr[i],1e-16);
1179 void MEDCouplingBasicsTest1::testFindCommonNodes()
1181 DataArrayInt *comm,*commI;
1182 MEDCouplingUMesh *targetMesh=build3DTargetMesh_1();
1183 targetMesh->findCommonNodes(1e-10,-1,comm,commI);
1184 CPPUNIT_ASSERT_EQUAL(1,commI->getNumberOfTuples());
1185 CPPUNIT_ASSERT_EQUAL(0,comm->getNumberOfTuples());
1187 DataArrayInt *o2n=targetMesh->buildNewNumberingFromCommonNodesFormat(comm,commI,newNbOfNodes);
1188 CPPUNIT_ASSERT_EQUAL(27,newNbOfNodes);
1189 CPPUNIT_ASSERT_EQUAL(27,o2n->getNumberOfTuples());
1190 const int o2nExp1[27]=
1192 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
1195 CPPUNIT_ASSERT(std::equal(o2nExp1,o2nExp1+27,o2n->getConstPointer()));
1199 targetMesh->decrRef();
1201 targetMesh=build3DTargetMeshMergeNode_1();
1202 CPPUNIT_ASSERT_EQUAL(31,targetMesh->getNumberOfNodes());
1203 targetMesh->findCommonNodes(1e-10,-1,comm,commI);
1204 CPPUNIT_ASSERT_EQUAL(3,commI->getNumberOfTuples());
1205 CPPUNIT_ASSERT_EQUAL(6,comm->getNumberOfTuples());
1206 const int commExpected[6]={1,27,28,29,23,30};
1207 const int commIExpected[3]={0,4,6};
1208 CPPUNIT_ASSERT(std::equal(commExpected,commExpected+6,comm->getConstPointer()));
1209 CPPUNIT_ASSERT(std::equal(commIExpected,commIExpected+3,commI->getConstPointer()));
1210 o2n=targetMesh->buildNewNumberingFromCommonNodesFormat(comm,commI,newNbOfNodes);
1211 CPPUNIT_ASSERT_EQUAL(31,o2n->getNumberOfTuples());
1212 CPPUNIT_ASSERT_EQUAL(27,newNbOfNodes);
1213 const int o2nExp2[31]=
1215 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
1216 21,22,23,24,25,26,1,1,1,23
1218 CPPUNIT_ASSERT(std::equal(o2nExp2,o2nExp2+31,o2n->getConstPointer()));
1222 targetMesh->decrRef();
1224 targetMesh=build3DTargetMesh_1();
1225 bool areNodesMerged;
1226 unsigned int time=targetMesh->getTimeOfThis();
1227 o2n=targetMesh->mergeNodes(1e-10,areNodesMerged,newNbOfNodes);
1228 targetMesh->updateTime();
1229 CPPUNIT_ASSERT(time==targetMesh->getTimeOfThis());
1230 CPPUNIT_ASSERT(!areNodesMerged);
1231 targetMesh->decrRef();
1234 targetMesh=build3DTargetMeshMergeNode_1();
1235 time=targetMesh->getTimeOfThis();
1236 o2n=targetMesh->mergeNodes(1e-10,areNodesMerged,newNbOfNodes);
1237 targetMesh->updateTime();
1238 CPPUNIT_ASSERT(time!=targetMesh->getTimeOfThis());
1239 CPPUNIT_ASSERT(areNodesMerged);
1240 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,
1241 18,4,5,8,7,13,14,17,16,
1242 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,
1243 18,13,14,17,16,22,23,26,25};
1244 CPPUNIT_ASSERT_EQUAL(72,targetMesh->getNodalConnectivity()->getNumberOfTuples());
1245 CPPUNIT_ASSERT(std::equal(connExp,connExp+72,targetMesh->getNodalConnectivity()->getConstPointer()));
1246 CPPUNIT_ASSERT_EQUAL(27,targetMesh->getCoords()->getNumberOfTuples());
1247 double coordsExp[81]={ 0., 0., 0., 50., 0., 0. , 200., 0., 0. , 0., 50., 0., 50., 50., 0. ,
1248 200., 50., 0., 0., 200., 0., 50., 200., 0. , 200., 200., 0. ,
1249 0., 0., 50., 50., 0., 50. , 200., 0., 50. , 0., 50., 50., 50.,
1250 50., 50. , 200., 50., 50., 0., 200., 50., 50., 200., 50. ,
1251 200., 200., 50. , 0., 0., 200., 50., 0., 200. , 200., 0., 200.
1252 , 0., 50., 200., 50., 50., 200. , 200., 50., 200.,
1253 0., 200., 200., 50., 200., 200. , 200., 200., 200. };
1254 CPPUNIT_ASSERT(std::equal(coordsExp,coordsExp+81,targetMesh->getCoords()->getConstPointer()));
1255 targetMesh->decrRef();
1258 targetMesh=build2DTargetMeshMergeNode_1();
1259 CPPUNIT_ASSERT_EQUAL(18,targetMesh->getNumberOfNodes());
1260 time=targetMesh->getTimeOfThis();
1261 o2n=targetMesh->mergeNodes(1e-10,areNodesMerged,newNbOfNodes);
1262 CPPUNIT_ASSERT(time!=targetMesh->getTimeOfThis());
1263 CPPUNIT_ASSERT(areNodesMerged);
1264 CPPUNIT_ASSERT_EQUAL(9,targetMesh->getNumberOfNodes());
1265 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};
1266 CPPUNIT_ASSERT_EQUAL(23,targetMesh->getNodalConnectivity()->getNumberOfTuples());
1267 CPPUNIT_ASSERT(std::equal(connExp2,connExp2+23,targetMesh->getNodalConnectivity()->getConstPointer()));
1268 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};
1269 CPPUNIT_ASSERT_EQUAL(9,targetMesh->getCoords()->getNumberOfTuples());
1270 CPPUNIT_ASSERT(std::equal(coordsExp2,coordsExp2+18,targetMesh->getCoords()->getConstPointer()));
1271 targetMesh->decrRef();
1275 void MEDCouplingBasicsTest1::testCheckButterflyCells()
1277 std::vector<int> cells;
1278 MEDCouplingUMesh *sourceMesh=build2DTargetMesh_1();
1279 sourceMesh->checkButterflyCells(cells);
1280 CPPUNIT_ASSERT(cells.empty());
1281 int *pt=sourceMesh->getNodalConnectivity()->getPointer();
1282 std::swap(pt[15],pt[16]);
1283 sourceMesh->checkButterflyCells(cells);
1284 CPPUNIT_ASSERT_EQUAL(1,(int)cells.size());
1285 CPPUNIT_ASSERT_EQUAL(3,cells[0]);
1287 std::swap(pt[15],pt[16]);
1288 sourceMesh->checkButterflyCells(cells);
1289 CPPUNIT_ASSERT(cells.empty());
1290 sourceMesh->decrRef();
1292 sourceMesh=build3DSurfTargetMesh_1();
1293 sourceMesh->checkButterflyCells(cells);
1294 CPPUNIT_ASSERT(cells.empty());
1295 pt=sourceMesh->getNodalConnectivity()->getPointer();
1296 std::swap(pt[15],pt[16]);
1297 sourceMesh->checkButterflyCells(cells);
1298 CPPUNIT_ASSERT_EQUAL(1,(int)cells.size());
1299 CPPUNIT_ASSERT_EQUAL(3,cells[0]);
1301 std::swap(pt[15],pt[16]);
1302 sourceMesh->checkButterflyCells(cells);
1303 CPPUNIT_ASSERT(cells.empty());
1304 sourceMesh->decrRef();
1307 void MEDCouplingBasicsTest1::testMergeMesh1()
1309 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1310 MEDCouplingUMesh *m2=build2DSourceMesh_1();
1311 const double vec[2]={1.,0.};
1313 MEDCouplingMesh *m3=m1->mergeMyselfWith(m2);
1314 MEDCouplingUMesh *m3C=dynamic_cast<MEDCouplingUMesh *>(m3);
1315 CPPUNIT_ASSERT(m3C);
1316 m3->checkCoherency();
1317 MEDCouplingUMesh *m4=build2DTargetMeshMerged_1();
1318 CPPUNIT_ASSERT(m3->isEqual(m4,1.e-12));
1322 DataArrayInt *da=m3C->mergeNodes(1.e-12,isMerged,newNbOfNodes);
1323 CPPUNIT_ASSERT_EQUAL(11,m3C->getNumberOfNodes());
1324 CPPUNIT_ASSERT_EQUAL(11,newNbOfNodes);
1325 CPPUNIT_ASSERT(isMerged);
1332 void MEDCouplingBasicsTest1::testMergeMeshOnSameCoords1()
1334 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1335 MEDCouplingUMesh *m2=build2DTargetMesh_1();
1336 std::vector<int> cells(5);
1337 for(int i=0;i<5;i++)
1339 m2->convertToPolyTypes(&cells[0],&cells[0]+cells.size());
1340 m1->tryToShareSameCoords(*m2,1e-12);
1341 MEDCouplingUMesh *m3=build2DTargetMesh_1();
1342 m3->tryToShareSameCoords(*m2,1e-12);
1343 std::vector<const MEDCouplingUMesh *> meshes;
1344 meshes.push_back(m1); meshes.push_back(m2); meshes.push_back(m3);
1345 MEDCouplingUMesh *m4=MEDCouplingUMesh::MergeUMeshesOnSameCoords(meshes);
1346 m4->checkCoherency();
1347 CPPUNIT_ASSERT(m4->getCoords()==m1->getCoords());
1348 CPPUNIT_ASSERT_EQUAL(15,m4->getNumberOfCells());
1349 const int cells1[5]={0,1,2,3,4};
1350 MEDCouplingPointSet *m1_1=m4->buildPartOfMySelf(cells1,cells1+5,true);
1351 m1_1->setName(m1->getName().c_str());
1352 CPPUNIT_ASSERT(m1->isEqual(m1_1,1e-12));
1353 const int cells2[5]={5,6,7,8,9};
1354 MEDCouplingPointSet *m2_1=m4->buildPartOfMySelf(cells2,cells2+5,true);
1355 m2_1->setName(m2->getName().c_str());
1356 CPPUNIT_ASSERT(m2->isEqual(m2_1,1e-12));
1357 const int cells3[5]={10,11,12,13,14};
1358 MEDCouplingPointSet *m3_1=m4->buildPartOfMySelf(cells3,cells3+5,true);
1359 m3_1->setName(m3->getName().c_str());
1360 CPPUNIT_ASSERT(m3->isEqual(m3_1,1e-12));
1361 m1_1->decrRef(); m2_1->decrRef(); m3_1->decrRef();
1369 void MEDCouplingBasicsTest1::testMergeField1()
1371 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1372 MEDCouplingUMesh *m2=build2DSourceMesh_1();
1373 const double vec[2]={1.,0.};
1375 MEDCouplingFieldDouble *f1=m1->getMeasureField(true);
1376 MEDCouplingFieldDouble *f2=m2->getMeasureField(true);
1377 MEDCouplingFieldDouble *f3=MEDCouplingFieldDouble::MergeFields(f1,f2);
1378 f3->checkCoherency();
1379 MEDCouplingUMesh *m4=build2DTargetMeshMerged_1();
1380 CPPUNIT_ASSERT(f3->getMesh()->isEqual(m4,1.e-12));
1381 std::string name=f3->getName();
1382 CPPUNIT_ASSERT(name=="MeasureOfMesh_");
1383 CPPUNIT_ASSERT(f3->getTypeOfField()==ON_CELLS);
1384 CPPUNIT_ASSERT(f3->getTimeDiscretization()==ONE_TIME);
1385 CPPUNIT_ASSERT_EQUAL(1,f3->getNumberOfComponents());
1386 CPPUNIT_ASSERT_EQUAL(7,f3->getNumberOfTuples());
1387 double values[7]={0.25,0.125,0.125,0.25,0.25,0.5,0.5};
1388 const double *tmp=f3->getArray()->getConstPointer();
1389 std::transform(tmp,tmp+7,values,values,std::minus<double>());
1390 std::transform(values,values+7,values,std::ptr_fun<double,double>(fabs));
1391 double max=*std::max_element(values,values+7);
1392 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1401 bool func1(const double *pt, double *res);
1402 bool func2(const double *pt, double *res);
1403 bool func3(const double *pt, double *res);
1404 bool func4(const double *pt, double *res);
1406 bool func1(const double *pt, double *res)
1412 bool func2(const double *pt, double *res)
1415 res[1]=2.*(pt[0]+pt[1]);
1419 bool func3(const double *pt, double *res)
1421 if(fabs(pt[0]-0.2)<1e-12)
1423 res[0]=1./(pt[0]-0.2);
1427 void MEDCouplingBasicsTest1::testFillFromAnalytic()
1429 MEDCouplingUMesh *m=build2DTargetMesh_1();
1430 m->setTime(3.4,5,6); m->setTimeUnit("us");
1432 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_CELLS,1,func1);
1433 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.4,f1->getTime(a,b),1.e-14);
1434 CPPUNIT_ASSERT_EQUAL(5,a); CPPUNIT_ASSERT_EQUAL(6,b);
1435 CPPUNIT_ASSERT_EQUAL(std::string(f1->getTimeUnit()),std::string("us"));
1436 f1->checkCoherency();
1437 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_CELLS);
1438 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1439 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1440 CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
1441 double values1[5]={-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9};
1442 const double *tmp=f1->getArray()->getConstPointer();
1443 std::transform(tmp,tmp+5,values1,values1,std::minus<double>());
1444 std::transform(values1,values1+5,values1,std::ptr_fun<double,double>(fabs));
1445 double max=*std::max_element(values1,values1+5);
1446 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1449 f1=m->fillFromAnalytic(ON_NODES,1,func1);
1450 f1->checkCoherency();
1451 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1452 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1453 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1454 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1455 double values2[9]={-0.6,-0.1,0.4,-0.1,0.4,0.9,0.4,0.9,1.4};
1456 tmp=f1->getArray()->getConstPointer();
1457 std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
1458 std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
1459 max=*std::max_element(values2,values2+9);
1460 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1463 f1=m->fillFromAnalytic(ON_NODES,2,func2);
1464 f1->checkCoherency();
1465 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1466 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1467 CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
1468 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1469 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};
1470 tmp=f1->getArray()->getConstPointer();
1471 std::transform(tmp,tmp+18,values3,values3,std::minus<double>());
1472 std::transform(values3,values3+18,values3,std::ptr_fun<double,double>(fabs));
1473 max=*std::max_element(values3,values3+18);
1474 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1476 f1->accumulate(values4);
1477 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.6,values4[0],1.e-12);
1478 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.2,values4[1],1.e-12);
1479 f1->integral(true,values4);
1480 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,values4[0],1.e-12);
1481 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,values4[1],1.e-12);
1484 CPPUNIT_ASSERT_THROW(f1=m->fillFromAnalytic(ON_NODES,1,func3),INTERP_KERNEL::Exception);
1489 void MEDCouplingBasicsTest1::testFillFromAnalytic2()
1491 MEDCouplingUMesh *m=build2DTargetMesh_1();
1492 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_CELLS,1,"y+x");
1493 f1->checkCoherency();
1494 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_CELLS);
1495 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1496 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1497 CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
1498 double values1[5]={-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9};
1499 const double *tmp=f1->getArray()->getConstPointer();
1500 std::transform(tmp,tmp+5,values1,values1,std::minus<double>());
1501 std::transform(values1,values1+5,values1,std::ptr_fun<double,double>(fabs));
1502 double max=*std::max_element(values1,values1+5);
1503 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1506 f1=m->fillFromAnalytic(ON_NODES,1,"y+2*x");
1507 f1->checkCoherency();
1508 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1509 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1510 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1511 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1512 double values2[9]={-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1};
1513 tmp=f1->getArray()->getConstPointer();
1514 std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
1515 std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
1516 max=*std::max_element(values2,values2+9);
1517 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1519 f1=m->fillFromAnalytic(ON_NODES,1,"2.*x+y");
1520 f1->checkCoherency();
1521 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1522 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1523 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1524 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1525 tmp=f1->getArray()->getConstPointer();
1526 double values2Bis[9]={-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1};
1527 std::transform(tmp,tmp+9,values2Bis,values2Bis,std::minus<double>());
1528 std::transform(values2,values2+9,values2Bis,std::ptr_fun<double,double>(fabs));
1529 max=*std::max_element(values2Bis,values2Bis+9);
1530 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1533 f1=m->fillFromAnalytic(ON_NODES,2,"(x+y)*IVec+2*(x+y)*JVec");
1534 f1->checkCoherency();
1535 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1536 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1537 CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
1538 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1539 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};
1540 tmp=f1->getArray()->getConstPointer();
1541 std::transform(tmp,tmp+18,values3,values3,std::minus<double>());
1542 std::transform(values3,values3+18,values3,std::ptr_fun<double,double>(fabs));
1543 max=*std::max_element(values3,values3+18);
1544 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1546 f1->accumulate(values4);
1547 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.6,values4[0],1.e-12);
1548 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.2,values4[1],1.e-12);
1549 f1->integral(true,values4);
1550 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,values4[0],1.e-12);
1551 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,values4[1],1.e-12);
1554 CPPUNIT_ASSERT_THROW(f1=m->fillFromAnalytic(ON_NODES,1,"1./(x-0.2)"),INTERP_KERNEL::Exception);
1559 void MEDCouplingBasicsTest1::testApplyFunc()
1561 MEDCouplingUMesh *m=build2DTargetMesh_1();
1562 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,2,func2);
1563 f1->checkCoherency();
1564 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1565 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1566 CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
1567 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1568 f1->applyFunc(1,func1);
1569 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1570 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1571 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1572 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1573 double values1[9]={-1.8,-0.3,1.2,-0.3,1.2,2.7,1.2,2.7,4.2};
1574 const double *tmp=f1->getArray()->getConstPointer();
1575 std::transform(tmp,tmp+9,values1,values1,std::minus<double>());
1576 std::transform(values1,values1+9,values1,std::ptr_fun<double,double>(fabs));
1577 double max=*std::max_element(values1,values1+9);
1578 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1583 void MEDCouplingBasicsTest1::testApplyFunc2()
1585 MEDCouplingUMesh *m=build2DTargetMesh_1();
1586 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,2,func2);
1587 f1->checkCoherency();
1588 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1589 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1590 CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
1591 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1593 MEDCouplingFieldDouble *f2=f1->clone(true);
1594 CPPUNIT_ASSERT_THROW(f2->applyFunc(1,"a+b+c+d"),INTERP_KERNEL::Exception);
1595 CPPUNIT_ASSERT_THROW(f2->applyFunc(1,"a/0"),INTERP_KERNEL::Exception);
1596 CPPUNIT_ASSERT_THROW(f2->applyFunc("a/0"),INTERP_KERNEL::Exception);
1597 f2->applyFunc("abs(u)^2.4+2*u");
1598 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1599 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1600 CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
1601 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1602 double values2[18]={-0.9065304805418678, -0.85105859001709905, -0.19601892829446504, -0.37898777756476987,
1603 0.91090317490482353, 2.1853504664669781, -0.19601892829446504, -0.37898777756476987,
1604 0.91090317490482353, 2.1853504664669781, 2.5765725275664879, 7.6987743736515295,
1605 0.91090317490482353, 2.1853504664669781, 2.5765725275664879, 7.6987743736515295,
1606 5.0423700574830965, 17.435300118916864};
1607 const double *tmp=f2->getArray()->getConstPointer();
1608 std::transform(tmp,tmp+18,values2,values2,std::minus<double>());
1609 std::transform(values2,values2+18,values2,std::ptr_fun<double,double>(fabs));
1610 double max=*std::max_element(values2,values2+18);
1611 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1614 f1->applyFunc(1,"x+y");
1615 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1616 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1617 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1618 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1619 double values1[9]={-1.8,-0.3,1.2,-0.3,1.2,2.7,1.2,2.7,4.2};
1620 tmp=f1->getArray()->getConstPointer();
1621 std::transform(tmp,tmp+9,values1,values1,std::minus<double>());
1622 std::transform(values1,values1+9,values1,std::ptr_fun<double,double>(fabs));
1623 max=*std::max_element(values1,values1+9);
1624 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1629 void MEDCouplingBasicsTest1::testOperationsOnFields()
1631 MEDCouplingUMesh *m=build2DTargetMesh_1();
1632 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,1,func1);
1633 MEDCouplingFieldDouble *f2=m->fillFromAnalytic(ON_NODES,1,func1);
1634 f1->checkCoherency();
1635 f2->checkCoherency();
1636 MEDCouplingFieldDouble *f3=(*f1)+(*f2);
1637 f3->checkCoherency();
1638 CPPUNIT_ASSERT(f3->getTypeOfField()==ON_NODES);
1639 CPPUNIT_ASSERT(f3->getTimeDiscretization()==ONE_TIME);
1640 double values1[9]={-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8};
1641 const double *tmp=f3->getArray()->getConstPointer();
1642 std::transform(tmp,tmp+9,values1,values1,std::minus<double>());
1643 std::transform(values1,values1+9,values1,std::ptr_fun<double,double>(fabs));
1644 double max=*std::max_element(values1,values1+9);
1645 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1649 f3->checkCoherency();
1650 CPPUNIT_ASSERT(f3->getTypeOfField()==ON_NODES);
1651 CPPUNIT_ASSERT(f3->getTimeDiscretization()==ONE_TIME);
1652 double values2[9]={0.36,0.01,0.16,0.01,0.16,0.81,0.16,0.81,1.96};
1653 tmp=f3->getArray()->getConstPointer();
1654 std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
1655 std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
1656 max=*std::max_element(values2,values2+9);
1657 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1661 MEDCouplingFieldDouble *f4=(*f1)-(*f3);
1662 f4->checkCoherency();
1663 CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1664 CPPUNIT_ASSERT(f4->getTimeDiscretization()==ONE_TIME);
1665 double values3[9]={0.6,0.1,-0.4,0.1,-0.4,-0.9,-0.4,-0.9,-1.4};
1666 tmp=f4->getArray()->getConstPointer();
1667 std::transform(tmp,tmp+9,values3,values3,std::minus<double>());
1668 std::transform(values3,values3+9,values3,std::ptr_fun<double,double>(fabs));
1669 max=*std::max_element(values3,values3+9);
1670 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1676 f4->checkCoherency();
1677 CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1678 CPPUNIT_ASSERT(f4->getTimeDiscretization()==ONE_TIME);
1679 tmp=f4->getArray()->getConstPointer();
1680 for(int i=0;i<9;i++)
1681 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.,tmp[i],1.e-12);
1685 f4=f2->buildNewTimeReprFromThis(NO_TIME,false);
1686 f4->checkCoherency();
1687 CPPUNIT_ASSERT(f4->getArray()==f2->getArray());
1688 CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1689 CPPUNIT_ASSERT(f4->getTimeDiscretization()==NO_TIME);
1690 CPPUNIT_ASSERT_THROW(f3=(*f1)+(*f4),INTERP_KERNEL::Exception);
1691 MEDCouplingFieldDouble *f5=f4->buildNewTimeReprFromThis(ONE_TIME,false);
1692 CPPUNIT_ASSERT(f4->getArray()==f5->getArray());
1693 CPPUNIT_ASSERT(f5->getTypeOfField()==ON_NODES);
1694 CPPUNIT_ASSERT(f5->getTimeDiscretization()==ONE_TIME);
1696 tmp=f3->getArray()->getConstPointer();
1697 double values4[9]={-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8};
1698 std::transform(tmp,tmp+9,values4,values4,std::minus<double>());
1699 std::transform(values4,values4+9,values4,std::ptr_fun<double,double>(fabs));
1700 max=*std::max_element(values4,values4+9);
1701 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1706 f4=f2->buildNewTimeReprFromThis(NO_TIME,true);
1707 f4->checkCoherency();
1708 CPPUNIT_ASSERT(f4->getArray()!=f2->getArray());
1709 CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1710 CPPUNIT_ASSERT(f4->getTimeDiscretization()==NO_TIME);
1711 CPPUNIT_ASSERT_THROW(f3=(*f1)+(*f4),INTERP_KERNEL::Exception);
1712 f5=f4->buildNewTimeReprFromThis(ONE_TIME,true);
1713 CPPUNIT_ASSERT(f4->getArray()!=f5->getArray());
1714 CPPUNIT_ASSERT(f2->getArray()!=f5->getArray());
1715 CPPUNIT_ASSERT(f5->getTypeOfField()==ON_NODES);
1716 CPPUNIT_ASSERT(f5->getTimeDiscretization()==ONE_TIME);
1718 tmp=f3->getArray()->getConstPointer();
1719 double values5[9]={-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8};
1720 std::transform(tmp,tmp+9,values5,values5,std::minus<double>());
1721 std::transform(values5,values5+9,values5,std::ptr_fun<double,double>(fabs));
1722 max=*std::max_element(values5,values5+9);
1723 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1733 void MEDCouplingBasicsTest1::testOperationsOnFields2()
1735 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1736 m->setTime(3.4,5,6); m->setTimeUnit("us");
1738 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,1,"x+y+z");
1739 MEDCouplingFieldDouble *f2=m->fillFromAnalytic(ON_NODES,1,"a*a+b+c*c");
1740 MEDCouplingFieldDouble *f3=(*f1)/(*f2);
1741 f3->checkCoherency();
1742 CPPUNIT_ASSERT(f3->getTypeOfField()==ON_NODES);
1743 CPPUNIT_ASSERT(f3->getTimeDiscretization()==ONE_TIME);
1744 const double expected1[9]={-2.4999999999999991, 1.2162162162162162, 0.77868852459016391,
1745 0.7407407407407407, 1.129032258064516, 0.81632653061224492,
1746 0.86538461538461531, 1.0919540229885056, 0.84302325581395343};
1747 CPPUNIT_ASSERT_EQUAL(1,f3->getNumberOfComponents());
1748 CPPUNIT_ASSERT_EQUAL(9,f3->getNumberOfTuples());
1749 const double *val=f3->getArray()->getConstPointer();
1750 for(int i=0;i<9;i++)
1751 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1.e-12);
1756 f1=m->buildOrthogonalField();
1757 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.4,f1->getTime(a,b),1.e-14);
1758 CPPUNIT_ASSERT_EQUAL(5,a); CPPUNIT_ASSERT_EQUAL(6,b);
1759 CPPUNIT_ASSERT_EQUAL(std::string(f1->getTimeUnit()),std::string("us"));
1760 f2=m->fillFromAnalytic(ON_CELLS,1,"x");
1762 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};
1763 val=f3->getArray()->getConstPointer();
1764 for(int i=0;i<15;i++)
1765 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1.e-12);
1769 val=f3->getArray()->getConstPointer();
1770 for(int i=0;i<15;i++)
1771 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1.e-12);
1780 void MEDCouplingBasicsTest1::testOperationsOnFields3()
1782 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1783 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,1,"x+y+z");
1784 MEDCouplingFieldDouble *f2=m->fillFromAnalytic(ON_NODES,1,"a*a+b+c*c");
1786 f1->checkCoherency();
1787 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1788 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1789 const double expected1[9]={-2.4999999999999991, 1.2162162162162162, 0.77868852459016391,
1790 0.7407407407407407, 1.129032258064516, 0.81632653061224492,
1791 0.86538461538461531, 1.0919540229885056, 0.84302325581395343};
1792 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1793 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1794 const double *val=f1->getArray()->getConstPointer();
1795 for(int i=0;i<9;i++)
1796 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1.e-12);
1800 f1=m->buildOrthogonalField();
1801 f2=m->fillFromAnalytic(ON_CELLS,1,"x");
1803 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};
1804 val=f1->getArray()->getConstPointer();
1805 for(int i=0;i<15;i++)
1806 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1.e-12);
1809 f1=m->buildOrthogonalField();
1810 CPPUNIT_ASSERT_THROW((*f2)*=(*f1),INTERP_KERNEL::Exception);
1818 * Check of LINEAR_TIME and CONST_ON_TIME_INTERVAL policies
1820 void MEDCouplingBasicsTest1::testOperationsOnFields4()
1822 MEDCouplingUMesh *m=build2DTargetMesh_1();
1823 int nbOfCells=m->getNumberOfCells();
1824 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,CONST_ON_TIME_INTERVAL);
1826 DataArrayDouble *array=DataArrayDouble::New();
1827 array->alloc(nbOfCells,3);
1828 f1->setArray(array);
1829 CPPUNIT_ASSERT_THROW(f1->setEndArray(array),INTERP_KERNEL::Exception);
1830 CPPUNIT_ASSERT_THROW(f1->getEndArray(),INTERP_KERNEL::Exception);
1832 double *tmp=array->getPointer();
1833 const double arr1[15]={0.,10.,20.,1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.};
1834 const double arr2[15]={5.,15.,25.,6.,16.,26.,7.,17.,27.,8.,18.,28.,9.,19.,29.};
1835 std::copy(arr1,arr1+15,tmp);
1836 f1->setStartTime(2.,0,0);
1837 f1->setEndTime(3.,0,0);
1838 f1->checkCoherency();
1840 const double pos[2]={0.3,-0.2};
1841 f1->getValueOn(pos,res);
1842 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[3],res[0],1.e-12);
1843 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[4],res[1],1.e-12);
1844 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[5],res[2],1.e-12);
1845 std::fill(res,res+3,0.);
1846 f1->getValueOn(pos,2.2,res);
1847 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[3],res[0],1.e-12);
1848 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[4],res[1],1.e-12);
1849 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[5],res[2],1.e-12);
1850 std::fill(res,res+3,0.);
1851 CPPUNIT_ASSERT_THROW(f1->getValueOn(pos,3.2,res),INTERP_KERNEL::Exception);
1852 MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
1854 f2->setArray(f1->getArray());
1855 f2->setStartTime(2.,3,0);
1856 f2->setEndTime(4.,13,0);
1857 CPPUNIT_ASSERT_THROW(f2->checkCoherency(),INTERP_KERNEL::Exception);
1858 DataArrayDouble *array2=DataArrayDouble::New();
1859 array2->alloc(nbOfCells,3);
1860 tmp=array2->getPointer();
1861 std::copy(arr2,arr2+15,tmp);
1862 f2->setEndArray(array2);
1864 f2->checkCoherency();
1866 std::fill(res,res+3,0.);
1867 f2->getValueOn(pos,3.21,res);
1868 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.025,res[0],1.e-12);
1869 CPPUNIT_ASSERT_DOUBLES_EQUAL(14.025,res[1],1.e-12);
1870 CPPUNIT_ASSERT_DOUBLES_EQUAL(24.025,res[2],1.e-12);
1871 MEDCouplingFieldDouble *f3=f2->clone(true);
1872 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-12));
1873 f3->getEndArray()->getPointer()[0]=5.001;
1874 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-12));
1875 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1876 f3->setStartTime(2.1,3,0);
1877 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1878 f3->setStartTime(2.,3,0);
1879 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1880 f3->setStartTime(2.,4,0);
1881 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1882 f3->setStartTime(2.,3,1);
1883 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1884 f3->setStartTime(2.,3,0);
1885 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1886 f3->setEndTime(4.1,13,0);
1887 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1888 f3->setEndTime(4.,13,0);
1889 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1890 f3->setEndTime(4.,14,0);
1891 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1892 f3->setEndTime(4.,13,1);
1893 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1894 f3->setEndTime(4.,13,0);
1895 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1897 MEDCouplingFieldDouble *f4=(*f2)+(*f2);
1898 std::fill(res,res+3,0.);
1899 f4->getValueOn(pos,3.21,res);
1900 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.05,res[0],1.e-12);
1901 CPPUNIT_ASSERT_DOUBLES_EQUAL(28.05,res[1],1.e-12);
1902 CPPUNIT_ASSERT_DOUBLES_EQUAL(48.05,res[2],1.e-12);
1904 std::fill(res,res+3,0.);
1905 f4->getValueOn(pos,3.21,res);
1906 CPPUNIT_ASSERT_DOUBLES_EQUAL(12.075,res[0],1.e-12);
1907 CPPUNIT_ASSERT_DOUBLES_EQUAL(42.075,res[1],1.e-12);
1908 CPPUNIT_ASSERT_DOUBLES_EQUAL(72.075,res[2],1.e-12);
1916 bool func4(const double *pt, double *res)
1918 res[0]=pt[0]+pt[1]+pt[2];
1922 void MEDCouplingBasicsTest1::testMergeNodesOnField()
1925 MEDCouplingUMesh *targetMesh=build3DTargetMeshMergeNode_1();
1926 MEDCouplingFieldDouble *f1=targetMesh->fillFromAnalytic(ON_NODES,1,func4);
1927 f1->mergeNodes(1e-10);
1929 targetMesh->decrRef();
1931 targetMesh=build3DTargetMeshMergeNode_1();
1932 f1=targetMesh->fillFromAnalytic(ON_NODES,1,func4);
1933 tmp=f1->getArray()->getPointer();
1935 f1->mergeNodes(1e-10);
1937 targetMesh->decrRef();
1939 targetMesh=build3DTargetMeshMergeNode_1();
1940 f1=targetMesh->fillFromAnalytic(ON_NODES,1,func4);
1941 tmp=f1->getArray()->getPointer();
1943 CPPUNIT_ASSERT_THROW(f1->mergeNodes(1e-10),INTERP_KERNEL::Exception);
1945 targetMesh->decrRef();
1948 void MEDCouplingBasicsTest1::testCheckConsecutiveCellTypes()
1950 MEDCouplingUMesh *sourceMesh=build2DSourceMesh_1();
1951 MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
1952 CPPUNIT_ASSERT(sourceMesh->checkConsecutiveCellTypes());
1953 const INTERP_KERNEL::NormalizedCellType order1[]={INTERP_KERNEL::NORM_TRI3, INTERP_KERNEL::NORM_QUAD4};
1954 const INTERP_KERNEL::NormalizedCellType order2[]={INTERP_KERNEL::NORM_QUAD4, INTERP_KERNEL::NORM_TRI3};
1955 CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypes());
1956 CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypesAndOrder(order1,order1+2));
1957 CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypesAndOrder(order2,order2+2));
1958 DataArrayInt *da=targetMesh->getRenumArrForConsecutiveCellTypesSpec(order1,order1+2);
1959 CPPUNIT_ASSERT_EQUAL(5,da->getNumberOfTuples());
1960 CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfComponents());
1961 const int expected1[5]={2,0,1,3,4};
1962 CPPUNIT_ASSERT(std::equal(expected1,expected1+5,da->getConstPointer()));
1964 da=targetMesh->getRenumArrForConsecutiveCellTypesSpec(order2,order2+2);
1965 CPPUNIT_ASSERT_EQUAL(5,da->getNumberOfTuples());
1966 CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfComponents());
1967 const int expected2[5]={0,3,4,1,2};
1968 CPPUNIT_ASSERT(std::equal(expected2,expected2+5,da->getConstPointer()));
1970 const int renumber1[5]={4,0,1,2,3};
1971 targetMesh->renumberCells(renumber1,false);
1972 CPPUNIT_ASSERT(targetMesh->checkConsecutiveCellTypes());
1973 CPPUNIT_ASSERT(targetMesh->checkConsecutiveCellTypesAndOrder(order1,order1+2));
1974 CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypesAndOrder(order2,order2+2));
1975 targetMesh->decrRef();
1976 sourceMesh->decrRef();
1979 void MEDCouplingBasicsTest1::testRearrange2ConsecutiveCellTypes()
1981 MEDCouplingUMesh *m1_1=build2DSourceMesh_1();
1982 MEDCouplingUMesh *m2_1=build2DTargetMesh_1();
1983 DataArrayInt *arr1=m1_1->rearrange2ConsecutiveCellTypes();
1984 MEDCouplingUMesh *m1_2=build2DSourceMesh_1();
1985 CPPUNIT_ASSERT(m1_2->isEqual(m1_1,1e-12));
1986 const int expected1[2]={0,1};
1987 CPPUNIT_ASSERT_EQUAL(2,arr1->getNumberOfTuples());
1988 CPPUNIT_ASSERT_EQUAL(1,arr1->getNumberOfComponents());
1989 CPPUNIT_ASSERT(std::equal(expected1,expected1+2,arr1->getConstPointer()));
1991 const int expected2[5]={0,3,4,1,2};
1992 arr1=m2_1->rearrange2ConsecutiveCellTypes();
1993 CPPUNIT_ASSERT_EQUAL(5,arr1->getNumberOfTuples());
1994 CPPUNIT_ASSERT_EQUAL(1,arr1->getNumberOfComponents());
1995 CPPUNIT_ASSERT(std::equal(expected2,expected2+5,arr1->getConstPointer()));
1996 MEDCouplingUMesh *m2_2=build2DTargetMesh_1();
1997 CPPUNIT_ASSERT_EQUAL(5,arr1->getNumberOfTuples());
1998 CPPUNIT_ASSERT_EQUAL(1,arr1->getNumberOfComponents());
1999 CPPUNIT_ASSERT(std::equal(expected2,expected2+5,arr1->getConstPointer()));
2000 CPPUNIT_ASSERT(!m2_2->isEqual(m2_1,1e-12));
2001 m2_2->renumberCells(expected2,false);
2002 CPPUNIT_ASSERT(m2_2->isEqual(m2_1,1e-12));
2010 void MEDCouplingBasicsTest1::testSplitByType()
2012 MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
2013 std::vector<MEDCouplingUMesh *> v=m1->splitByType();
2014 CPPUNIT_ASSERT_EQUAL(3,(int)v.size());
2015 std::vector<const MEDCouplingUMesh *> v2(v.begin(),v.end());
2016 MEDCouplingUMesh *m2=MEDCouplingUMesh::MergeUMeshesOnSameCoords(v2);
2017 m2->setName(m1->getName().c_str());
2018 CPPUNIT_ASSERT(m1->isEqual(m2,1.e-12));
2019 for(std::vector<MEDCouplingUMesh *>::const_iterator iter=v.begin();iter!=v.end();iter++)
2025 void MEDCouplingBasicsTest1::testFuseUMeshesOnSameCoords()
2027 std::vector<const MEDCouplingUMesh *> meshes;
2028 MEDCouplingUMesh *m2=build2DTargetMesh_1();
2029 int cells1[3]={2,3,4};
2030 MEDCouplingPointSet *m3_1=m2->buildPartOfMySelf(cells1,cells1+3,true);
2031 MEDCouplingUMesh *m3=dynamic_cast<MEDCouplingUMesh *>(m3_1);
2033 meshes.push_back(m3);
2034 int cells2[3]={1,2,4};
2035 MEDCouplingPointSet *m4_1=m2->buildPartOfMySelf(cells2,cells2+3,true);
2036 MEDCouplingUMesh *m4=dynamic_cast<MEDCouplingUMesh *>(m4_1);
2038 meshes.push_back(m4);
2039 int cells3[2]={1,2};
2040 MEDCouplingPointSet *m5_1=m2->buildPartOfMySelf(cells3,cells3+2,true);
2041 MEDCouplingUMesh *m5=dynamic_cast<MEDCouplingUMesh *>(m5_1);
2043 meshes.push_back(m5);
2046 std::vector<DataArrayInt *> corr;
2047 MEDCouplingUMesh *m7=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
2048 CPPUNIT_ASSERT_EQUAL(4,m7->getNumberOfCells());
2049 CPPUNIT_ASSERT_EQUAL(3,(int)corr.size());
2050 const int expectedVals1[3]={3,3,2};
2051 const int expectedVals2[3][3]={{0,1,2},{3,0,2},{3,0,111111}};
2052 for(int i=0;i<3;i++)
2054 DataArrayInt *arr=corr[i];
2055 CPPUNIT_ASSERT_EQUAL(1,arr->getNumberOfComponents());
2056 int nbOfVals=expectedVals1[i];
2057 CPPUNIT_ASSERT_EQUAL(nbOfVals,arr->getNumberOfTuples());
2058 const int *vals=arr->getConstPointer();
2059 for(int j=0;j<nbOfVals;j++)
2060 CPPUNIT_ASSERT_EQUAL(expectedVals2[i][j],vals[j]);
2062 std::vector< std::vector<int> > fidsOfGroups;
2063 std::vector<const DataArrayInt *> corr2(corr.begin(),corr.end());
2064 DataArrayInt *arr2=DataArrayInt::MakePartition(corr2,m7->getNumberOfCells(),fidsOfGroups);
2065 const int fidExp[4]={5,1,3,4};
2066 const int fidsGrp[3][3]={{1,3,5},{3,4,5},{4,5,23344}};
2067 CPPUNIT_ASSERT_EQUAL(3,(int)fidsOfGroups.size());
2068 CPPUNIT_ASSERT_EQUAL(1,arr2->getNumberOfComponents());
2069 CPPUNIT_ASSERT_EQUAL(4,arr2->getNumberOfTuples());
2070 CPPUNIT_ASSERT(std::equal(fidExp,fidExp+4,arr2->getConstPointer()));
2071 for(int i=0;i<3;i++)
2073 int nbOfVals=expectedVals1[i];
2074 CPPUNIT_ASSERT_EQUAL(nbOfVals,(int)fidsOfGroups[i].size());
2075 CPPUNIT_ASSERT(std::equal(fidsOfGroups[i].begin(),fidsOfGroups[i].end(),fidsGrp[i]));
2077 for(std::vector<DataArrayInt *>::iterator iter=corr.begin();iter!=corr.end();iter++)
2087 void MEDCouplingBasicsTest1::testFuseUMeshesOnSameCoords2()
2089 MEDCouplingUMesh *m2;
2090 MEDCouplingUMesh *m1=build3DExtrudedUMesh_1(m2);
2092 const int part1[5]={2,3,6,4,10};
2093 MEDCouplingUMesh *m3=(MEDCouplingUMesh *)m1->buildPartOfMySelf(part1,part1+5,true);
2094 const int part2[4]={5,6,4,7};
2095 MEDCouplingUMesh *m4=(MEDCouplingUMesh *)m1->buildPartOfMySelf(part2,part2+4,true);
2096 std::vector<const MEDCouplingUMesh *> meshes;
2097 meshes.push_back(m1);
2098 meshes.push_back(m3);
2099 meshes.push_back(m3);
2100 meshes.push_back(m4);
2101 std::vector<DataArrayInt *> corr;
2102 MEDCouplingUMesh *m5=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
2103 CPPUNIT_ASSERT_EQUAL(18,m5->getNumberOfCells());
2104 std::vector<DataArrayInt *>::iterator it=corr.begin();
2105 const int exp1[4]={18,5,5,4};
2106 const int exp2[4][18]={
2107 {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17},
2108 {2,3,6,4,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
2109 {2,3,6,4,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
2110 {5,6,4,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}
2113 for(;it!=corr.end();it++,i++)
2115 int sz=(*it)->getNumberOfTuples();
2116 CPPUNIT_ASSERT_EQUAL(exp1[i],sz);
2117 CPPUNIT_ASSERT(std::equal(exp2[i],exp2[i]+sz,(*it)->getConstPointer()));
2119 for(it=corr.begin();it!=corr.end();it++)
2127 void MEDCouplingBasicsTest1::testBuildOrthogonalField()
2129 MEDCouplingUMesh *targetMesh=build3DSurfTargetMesh_1();
2130 MEDCouplingFieldDouble *field=targetMesh->buildOrthogonalField();
2131 double expected[3]={0.70710678118654746,0.,-0.70710678118654746};
2132 CPPUNIT_ASSERT_EQUAL(5,field->getNumberOfTuples());
2133 CPPUNIT_ASSERT_EQUAL(3,field->getNumberOfComponents());
2134 const double *vals=field->getArray()->getConstPointer();
2135 for(int i=0;i<15;i++)
2136 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected[i%3],vals[i],1e-12);
2138 targetMesh->decrRef();
2140 double targetCoords[12]={0.,0.,0.,0.5,0.,0.5,1.,0.,1.,0.,1.,0.};
2141 int targetConn[4]={0,1,2,3};
2142 targetMesh=MEDCouplingUMesh::New();
2143 targetMesh->setMeshDimension(2);
2144 targetMesh->allocateCells(1);
2145 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn);
2146 targetMesh->finishInsertingCells();
2147 DataArrayDouble *myCoords=DataArrayDouble::New();
2148 myCoords->alloc(4,3);
2149 std::copy(targetCoords,targetCoords+12,myCoords->getPointer());
2150 targetMesh->setCoords(myCoords);
2151 myCoords->decrRef();
2152 field=targetMesh->buildOrthogonalField();
2153 CPPUNIT_ASSERT_EQUAL(1,field->getNumberOfTuples());
2154 CPPUNIT_ASSERT_EQUAL(3,field->getNumberOfComponents());
2155 vals=field->getArray()->getConstPointer();
2156 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.70710678118654746,vals[0],1e-12);
2157 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,vals[1],1e-12);
2158 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.70710678118654746,vals[2],1e-12);
2160 targetMesh->decrRef();
2163 void MEDCouplingBasicsTest1::testGetCellsContainingPoint()
2165 MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
2166 double pos[12]={0.,0.,0.4,0.4,0.,0.4,0.1,0.1,0.25,0.,0.65,0.};
2167 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> t1,t2;
2169 targetMesh->getCellsContainingPoints(pos,6,1e-12,t1,t2);
2170 CPPUNIT_ASSERT_EQUAL(6,(int)t1->getNbOfElems());
2171 CPPUNIT_ASSERT_EQUAL(7,(int)t2->getNbOfElems());
2172 const int expectedValues1[6]={0,4,3,0,1,2};
2173 const int expectedValues2[7]={0,1,2,3,4,5,6};
2174 CPPUNIT_ASSERT(std::equal(t1->begin(),t1->end(),expectedValues1));
2175 CPPUNIT_ASSERT(std::equal(t2->begin(),t2->end(),expectedValues2));
2176 //2D with no help of bounding box.
2177 double center[2]={0.2,0.2};
2178 MEDCouplingPointSet::Rotate2DAlg(center,0.78539816339744830962,6,pos);
2179 targetMesh->rotate(center,0,0.78539816339744830962);
2180 targetMesh->getCellsContainingPoints(pos,6,1e-12,t1,t2);
2181 CPPUNIT_ASSERT_EQUAL(6,(int)t1->getNbOfElems());
2182 CPPUNIT_ASSERT_EQUAL(7,(int)t2->getNbOfElems());
2183 CPPUNIT_ASSERT(std::equal(t1->begin(),t1->end(),expectedValues1));
2184 CPPUNIT_ASSERT(std::equal(t2->begin(),t2->end(),expectedValues2));
2186 const double pos1bis[2]={-0.3303300858899107,-0.11819805153394641};
2187 CPPUNIT_ASSERT_EQUAL(-1,targetMesh->getCellContainingPoint(pos1bis,1e-12));
2188 targetMesh->decrRef();
2190 targetMesh=build2DTargetMesh_1();
2191 const double pos2[2]={0.2,-0.05};
2192 std::vector<int> t11;
2194 targetMesh->getCellsContainingPoint(pos2,1e-12,t11);
2195 CPPUNIT_ASSERT_EQUAL(2,(int)t11.size());
2196 const int expectedValues3[2]={0,1};
2197 CPPUNIT_ASSERT(std::equal(t11.begin(),t11.end(),expectedValues3));
2198 const double pos3[2]={0.2,0.2};
2200 targetMesh->getCellsContainingPoint(pos3,1e-12,t11);
2201 CPPUNIT_ASSERT_EQUAL(5,(int)t11.size());
2202 const int expectedValues4[5]={0,1,2,3,4};
2203 CPPUNIT_ASSERT(std::equal(t11.begin(),t11.end(),expectedValues4));
2204 CPPUNIT_ASSERT_EQUAL(0,targetMesh->getCellContainingPoint(pos3,1e-12));
2205 targetMesh->decrRef();
2207 targetMesh=build3DTargetMesh_1();
2208 const double pos4[3]={25.,25.,25.};
2209 CPPUNIT_ASSERT_EQUAL(0,targetMesh->getCellContainingPoint(pos4,1e-12));
2210 const double pos5[3]={50.,50.,50.};
2212 targetMesh->getCellsContainingPoint(pos5,1e-12,t11);
2213 CPPUNIT_ASSERT_EQUAL(8,(int)t11.size());
2214 const int expectedValues5[8]={0,1,2,3,4,5,6,7};
2215 CPPUNIT_ASSERT(std::equal(t11.begin(),t11.end(),expectedValues5));
2216 const double pos6[3]={0., 50., 0.};
2218 targetMesh->getCellsContainingPoint(pos6,1e-12,t11);
2219 CPPUNIT_ASSERT_EQUAL(2,(int)t11.size());
2220 const int expectedValues6[2]={0,2};
2221 CPPUNIT_ASSERT(std::equal(t11.begin(),t11.end(),expectedValues6));
2223 const double pos7[3]={-1.0,-1.0,0.};
2224 CPPUNIT_ASSERT_EQUAL(-1,targetMesh->getCellContainingPoint(pos7,1e-12));
2226 const double center2[3]={0.,0.,0.};
2227 const double vec2[3]={0.,-1.,0.};
2228 targetMesh->rotate(center2,vec2,0.78539816339744830962);
2229 const double pos8[3]={-25,25.,12.};
2230 CPPUNIT_ASSERT_EQUAL(-1,targetMesh->getCellContainingPoint(pos8,1e-12));
2232 targetMesh->decrRef();
2235 void MEDCouplingBasicsTest1::testGetValueOn1()
2237 MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
2238 MEDCouplingFieldDouble *fieldOnCells=MEDCouplingFieldDouble::New(ON_CELLS);
2239 int nbOfCells=targetMesh->getNumberOfCells();
2240 fieldOnCells->setMesh(targetMesh);
2241 DataArrayDouble *array=DataArrayDouble::New();
2242 array->alloc(nbOfCells,2);
2243 fieldOnCells->setArray(array);
2244 double *tmp=array->getPointer();
2245 for(int i=0;i<nbOfCells;i++)
2246 { tmp[2*i]=7.+(double)i; tmp[2*i+1]=17.+(double)i; }
2249 const double pos1[2]={0.25,0.};
2251 fieldOnCells->getValueOn(pos1,res);
2252 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.,res[0],1e-12);
2253 CPPUNIT_ASSERT_DOUBLES_EQUAL(18.,res[1],1e-12);
2255 fieldOnCells->decrRef();
2256 targetMesh->decrRef();
2258 targetMesh=build2DSourceMesh_1();
2259 MEDCouplingFieldDouble *fieldOnNodes=MEDCouplingFieldDouble::New(ON_NODES);
2260 int nbOfNodes=targetMesh->getNumberOfNodes();
2261 fieldOnNodes->setMesh(targetMesh);
2262 array=DataArrayDouble::New();
2263 array->alloc(nbOfNodes,2);
2264 fieldOnNodes->setArray(array);
2265 tmp=array->getPointer();
2266 for(int i=0;i<nbOfNodes;i++)
2267 { tmp[2*i]=17.+(double)i; tmp[2*i+1]=27.+(double)i; }
2270 const double pos2[2]={-0.13333333333333333,-0.13333333333333333};
2271 fieldOnNodes->getValueOn(pos2,res);
2272 CPPUNIT_ASSERT_DOUBLES_EQUAL(17.5,res[0],1e-12);
2273 CPPUNIT_ASSERT_DOUBLES_EQUAL(27.5,res[1],1e-12);
2274 const double pos3[2]={0.033333333333333326,0.36666666666666664};
2275 fieldOnNodes->getValueOn(pos3,res);
2276 CPPUNIT_ASSERT_DOUBLES_EQUAL(18.666666666666667,res[0],1e-12);
2277 CPPUNIT_ASSERT_DOUBLES_EQUAL(28.666666666666667,res[1],1e-12);
2279 fieldOnNodes->decrRef();
2280 targetMesh->decrRef();
2283 void MEDCouplingBasicsTest1::testCMesh0()
2285 MEDCouplingCMesh* mesh=MEDCouplingCMesh::New();
2286 MEDCouplingCMesh* meshEmpty=mesh->clone(true);
2287 CPPUNIT_ASSERT(meshEmpty->isEqual(mesh,1e-12));
2289 DataArrayDouble* coordsX=DataArrayDouble::New();
2290 double arrX[4] = { -1., 1., 2., 4. };
2291 coordsX->useArray(arrX,false, CPP_DEALLOC,4,1);
2292 DataArrayDouble* coordsY=DataArrayDouble::New();
2293 double arrY[4] = { -2., 2., 4., 8. };
2294 coordsY->useArray(arrY,false, CPP_DEALLOC,4,1);
2295 DataArrayDouble* coordsZ=DataArrayDouble::New();
2296 double arrZ[4] = { -3., 3., 6., 12. };
2297 coordsZ->useArray(arrZ,false, CPP_DEALLOC,4,1);
2298 mesh->setCoords(coordsX,coordsY,coordsZ);
2303 MEDCouplingFieldDouble *fieldOnNodes=mesh->fillFromAnalytic(ON_NODES,1,"x+y/2.+z/3.");
2304 CPPUNIT_ASSERT_EQUAL(1,fieldOnNodes->getNumberOfComponents());
2305 CPPUNIT_ASSERT_EQUAL(64,fieldOnNodes->getNumberOfTuples());
2306 const double expected1[64]={-3., -1., 0., 2., -1., 1., 2., 4., 0., 2., 3., 5., 2., 4., 5., 7., -1., 1., 2.,
2307 4., 1., 3., 4., 6., 2., 4., 5., 7., 4., 6., 7., 9., 0., 2., 3., 5., 2., 4., 5.,
2308 7., 3., 5., 6., 8., 5., 7., 8., 10., 2., 4., 5.,
2309 7., 4., 6., 7., 9., 5., 7., 8., 10., 7., 9., 10., 12.};
2310 const double *val=fieldOnNodes->getArray()->getConstPointer();
2311 for(int i=0;i<64;i++)
2312 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1e-12);
2313 double res[1]; //size fieldOnNodes->getNumberOfComponents()
2314 fieldOnNodes->getValueOnPos(1,3,2,&res[0]);
2315 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,res[0],1e-12);
2316 fieldOnNodes->decrRef();
2318 MEDCouplingFieldDouble *fieldOnCells=mesh->fillFromAnalytic(ON_CELLS,1,"x+y/2.+z/3.");
2319 CPPUNIT_ASSERT_EQUAL(1,fieldOnCells->getNumberOfComponents());
2320 CPPUNIT_ASSERT_EQUAL(27,fieldOnCells->getNumberOfTuples());
2321 val=fieldOnCells->getArray()->getConstPointer();
2322 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,
2323 6, 4.5, 6, 7.5, 3, 4.5, 6, 4.5, 6, 7.5, 6, 7.5, 9};
2324 for(int i=0;i<27;i++)
2325 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1e-12);
2326 fieldOnCells->getValueOnPos(1,2,1,&res[0]);
2327 CPPUNIT_ASSERT_DOUBLES_EQUAL(6.,res[0],1e-12);
2328 fieldOnCells->decrRef();
2330 MEDCouplingMesh* meshDeepCopy=mesh->deepCpy();
2331 MEDCouplingCMesh* meshClone=mesh->clone(false);
2333 CPPUNIT_ASSERT_THROW(meshEmpty->copyTinyStringsFrom(0),INTERP_KERNEL::Exception);
2334 meshEmpty->copyTinyStringsFrom(mesh);
2335 //no data in meshEmpty, expected false
2336 CPPUNIT_ASSERT(!meshEmpty->isEqual(mesh,1e-12));
2338 CPPUNIT_ASSERT(meshDeepCopy->isEqual(mesh,1e-12));
2339 meshDeepCopy->copyTinyStringsFrom(mesh);
2340 CPPUNIT_ASSERT(meshDeepCopy->isEqual(mesh,1e-12));
2341 CPPUNIT_ASSERT(meshClone->isEqual(mesh,1e-12));
2343 CPPUNIT_ASSERT_EQUAL(CARTESIAN,mesh->getType());
2344 CPPUNIT_ASSERT_EQUAL(CARTESIAN,meshEmpty->getType());
2345 CPPUNIT_ASSERT_EQUAL(CARTESIAN,meshDeepCopy->getType());
2346 CPPUNIT_ASSERT_EQUAL(CARTESIAN,meshClone->getType());
2349 meshEmpty->decrRef();
2350 meshDeepCopy->decrRef();
2351 meshClone->decrRef();
2354 void MEDCouplingBasicsTest1::testCMesh1()
2356 MEDCouplingCMesh *mesh1,*mesh2,*mesh3;
2357 mesh1=MEDCouplingCMesh::New();
2358 DataArrayDouble* coordsX1=DataArrayDouble::New();
2359 double arrX1[4] = { -1., 1., 2., 4. };
2360 coordsX1->useArray(arrX1,false, CPP_DEALLOC,4,1);
2361 DataArrayDouble* coordsY1=DataArrayDouble::New();
2362 double arrY1[4] = { -2., 2., 4., 8. };
2363 coordsY1->useArray(arrY1,false, CPP_DEALLOC,4,1);
2364 DataArrayDouble* coordsZ1=DataArrayDouble::New();
2365 double arrZ1[4] = { -3., 3., 6., 12. };
2366 coordsZ1->useArray(arrZ1,false, CPP_DEALLOC,4,1);
2367 mesh1->setCoords(coordsX1,coordsY1,coordsZ1);
2369 mesh2=MEDCouplingCMesh::New();
2370 DataArrayDouble* coordsX2=DataArrayDouble::New();
2371 double arrX2[4] = { -1., 1., 2., 4. };
2372 coordsX2->useArray(arrX2,false, CPP_DEALLOC,4,1);
2373 DataArrayDouble* coordsY2=DataArrayDouble::New();
2374 double arrY2[4] = { -2., 2., 4., 8. };
2375 coordsY2->useArray(arrY2,false, CPP_DEALLOC,4,1);
2376 DataArrayDouble* coordsZ2=DataArrayDouble::New();
2377 double arrZ2[4] = { -3., 3., 6., 12.+1e-6 }; //here is not equal
2378 coordsZ2->useArray(arrZ2,false, CPP_DEALLOC,4,1);
2379 mesh2->setCoords(coordsX2,coordsY2,coordsZ2);
2381 mesh3=MEDCouplingCMesh::New();
2382 DataArrayDouble* coordsX3=DataArrayDouble::New();
2383 double arrX3[1] = { -1.};
2384 coordsX3->useArray(arrX3,false, CPP_DEALLOC,1,1);
2385 DataArrayDouble* coordsY3=DataArrayDouble::New();
2386 double arrY3[1] = { -2.};
2387 coordsY3->useArray(arrY3,false, CPP_DEALLOC,1,1);
2388 DataArrayDouble* coordsZ3=DataArrayDouble::New();
2389 double arrZ3[1] = { -3.};
2390 coordsZ3->useArray(arrZ3,false, CPP_DEALLOC,1,1);
2391 mesh3->setCoords(coordsX3,coordsY3,coordsZ3);
2393 CPPUNIT_ASSERT_EQUAL(3,mesh1->getSpaceDimension());
2394 CPPUNIT_ASSERT_EQUAL(3,mesh1->getMeshDimension());
2396 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
2397 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
2398 CPPUNIT_ASSERT(!mesh2->isEqualWithoutConsideringStr(mesh1,1e-12));
2399 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-5));
2400 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-7));
2402 CPPUNIT_ASSERT_THROW(mesh3->checkCoherency1(1e-12),INTERP_KERNEL::Exception);
2403 mesh1->checkCoherency1(1e-12);
2404 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh1->getTypeOfCell(1));
2406 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,*((mesh1->getAllGeoTypes()).begin()));
2407 CPPUNIT_ASSERT_EQUAL(27,mesh1->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2408 CPPUNIT_ASSERT_THROW(mesh1->getNumberOfCellsWithType(INTERP_KERNEL::NORM_QUAD4),INTERP_KERNEL::Exception);
2410 std::vector<double> coo;
2411 mesh1->getCoordinatesOfNode(0, coo);
2412 CPPUNIT_ASSERT_EQUAL(3,(int) coo.size());
2413 CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.,coo[0],1e-14);
2414 CPPUNIT_ASSERT_DOUBLES_EQUAL(-2.,coo[1],1e-14);
2415 CPPUNIT_ASSERT_DOUBLES_EQUAL(-3.,coo[2],1e-14);
2417 mesh1->getCoordinatesOfNode(63, coo);
2418 CPPUNIT_ASSERT_EQUAL(3,(int) coo.size());
2419 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.,coo[0],1e-14);
2420 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.,coo[1],1e-14);
2421 CPPUNIT_ASSERT_DOUBLES_EQUAL(12.,coo[2],1e-14);
2424 repr=mesh1->simpleRepr();
2425 repr=mesh1->advancedRepr();
2426 CPPUNIT_ASSERT(!(repr.find("Cartesian")==std::string::npos));
2427 CPPUNIT_ASSERT(!(repr.find("Number of components : 1")==std::string::npos));
2428 CPPUNIT_ASSERT(!(repr.find("Number of tuples : 4")==std::string::npos));
2429 CPPUNIT_ASSERT(!(repr.find("Z Array :")==std::string::npos));
2430 coordsX1->decrRef();
2431 coordsY1->decrRef();
2432 coordsZ1->decrRef();
2433 coordsX2->decrRef();
2434 coordsY2->decrRef();
2435 coordsZ2->decrRef();
2436 coordsX3->decrRef();
2437 coordsY3->decrRef();
2438 coordsZ3->decrRef();
2444 void MEDCouplingBasicsTest1::testCMesh2()
2446 MEDCouplingCMesh *mesh1;
2447 mesh1=MEDCouplingCMesh::New();
2448 DataArrayDouble* coordsX1=DataArrayDouble::New();
2449 double arrX1[4] = { -1., 1., 2., 4. };
2450 coordsX1->useArray(arrX1,false, CPP_DEALLOC,4,1);
2451 DataArrayDouble* coordsY1=DataArrayDouble::New();
2452 double arrY1[4] = { -2., 2., 4., 8. };
2453 coordsY1->useArray(arrY1,false, CPP_DEALLOC,4,1);
2454 DataArrayDouble* coordsZ1=DataArrayDouble::New();
2455 double arrZ1[4] = { -3., 3., 6., 12. };
2456 coordsZ1->useArray(arrZ1,false, CPP_DEALLOC,4,1);
2457 mesh1->setCoords(coordsX1,coordsY1,coordsZ1);
2459 std::vector<int> dis=mesh1->getDistributionOfTypes();
2460 CPPUNIT_ASSERT_EQUAL(3,(int) dis.size());
2461 CPPUNIT_ASSERT_EQUAL((int) INTERP_KERNEL::NORM_HEXA8,dis[0]);
2462 CPPUNIT_ASSERT_EQUAL(27,dis[1]);
2463 CPPUNIT_ASSERT_EQUAL(-1,dis[2]);
2465 std::vector<const DataArrayInt *> idsPerType;
2466 CPPUNIT_ASSERT(!(mesh1->checkTypeConsistencyAndContig(dis, idsPerType)));
2467 dis[0]=(int) INTERP_KERNEL::NORM_QUAD4;
2468 CPPUNIT_ASSERT_THROW(mesh1->checkTypeConsistencyAndContig(dis, idsPerType),INTERP_KERNEL::Exception);
2470 dis[0]=(int) INTERP_KERNEL::NORM_HEXA8;
2472 DataArrayInt *ids=DataArrayInt::New();
2474 ids->fillWithValue(23);
2475 idsPerType.push_back(ids);
2476 DataArrayInt* check=mesh1->checkTypeConsistencyAndContig(dis, idsPerType);
2477 CPPUNIT_ASSERT(check);
2478 CPPUNIT_ASSERT(check->isEqual(*ids));
2480 std::vector<int> code;
2481 std::vector<DataArrayInt *> idsInPflPerType;
2482 std::vector<DataArrayInt *> pfls;
2483 mesh1->splitProfilePerType(ids,code,idsInPflPerType,pfls);
2484 CPPUNIT_ASSERT_EQUAL(3,(int)code.size());
2485 CPPUNIT_ASSERT_EQUAL((int) INTERP_KERNEL::NORM_HEXA8,code[0]);
2486 CPPUNIT_ASSERT_EQUAL(10,code[1]);
2487 CPPUNIT_ASSERT_EQUAL(0,code[2]);
2488 CPPUNIT_ASSERT_EQUAL(1,(int)idsInPflPerType.size());
2489 CPPUNIT_ASSERT_EQUAL(1,(int)pfls.size());
2490 DataArrayInt *exp=DataArrayInt::New(); exp->alloc(10,1); exp->iota(0);
2491 CPPUNIT_ASSERT(idsInPflPerType[0]->isEqual(*exp));
2493 CPPUNIT_ASSERT(pfls[0]->isEqual(*ids));
2494 idsInPflPerType[0]->decrRef();
2499 int cells1[4]={0,1,25,26};
2500 MEDCouplingUMesh *partMesh1=
2501 dynamic_cast<MEDCouplingUMesh *>(mesh1->buildPart(cells1,cells1+4));
2502 CPPUNIT_ASSERT(partMesh1);
2503 CPPUNIT_ASSERT_EQUAL(4,partMesh1->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2504 CPPUNIT_ASSERT_EQUAL(64,mesh1->getNumberOfNodes());
2505 CPPUNIT_ASSERT_EQUAL(64,partMesh1->getNumberOfNodes());
2507 int cells2[2]={25,26};
2509 MEDCouplingCMesh *partMesh2=
2510 dynamic_cast<MEDCouplingCMesh *>(mesh1->buildPartAndReduceNodes(cells2,cells2+2,arr1));
2511 CPPUNIT_ASSERT(partMesh2);
2512 CPPUNIT_ASSERT_EQUAL(2,partMesh2->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2513 CPPUNIT_ASSERT_EQUAL(12,partMesh2->getNumberOfNodes());
2515 int cells3[2]={2,3};
2517 MEDCouplingUMesh *partMesh3=
2518 dynamic_cast<MEDCouplingUMesh *>(partMesh1->buildPartAndReduceNodes(cells3,cells3+2,arr2));
2519 CPPUNIT_ASSERT(partMesh3);
2520 CPPUNIT_ASSERT_EQUAL(2,partMesh3->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2521 CPPUNIT_ASSERT_EQUAL(12,partMesh3->getNumberOfNodes());
2523 CPPUNIT_ASSERT_THROW(mesh1->simplexize(0),INTERP_KERNEL::Exception);
2524 CPPUNIT_ASSERT_THROW(mesh1->getMeasureFieldOnNode(true),INTERP_KERNEL::Exception);
2528 mesh1->getBoundingBox(bbox1);
2529 partMesh1->getBoundingBox(bbox2);
2530 for(int i=0;i<6;i++)
2531 CPPUNIT_ASSERT_DOUBLES_EQUAL(bbox1[i],bbox2[i],1e-12);
2532 partMesh3->getBoundingBox(bbox1);
2533 partMesh2->getBoundingBox(bbox2);
2534 for(int i=0;i<6;i++)
2535 CPPUNIT_ASSERT_DOUBLES_EQUAL(bbox1[i],bbox2[i],1e-12);
2537 CPPUNIT_ASSERT_THROW(mesh1->buildOrthogonalField(),INTERP_KERNEL::Exception);
2538 MEDCouplingCMesh *mesh2d=MEDCouplingCMesh::New();
2539 mesh2d->setCoords(coordsX1,coordsY1);
2540 MEDCouplingFieldDouble *f1=mesh2d->buildOrthogonalField();
2542 std::vector<double> tinyInfoD;
2543 std::vector<int> tinyInfo;
2544 std::vector<std::string> littleStrings;
2545 mesh2d->getTinySerializationInformation(tinyInfoD, tinyInfo, littleStrings);
2546 CPPUNIT_ASSERT_EQUAL(5,(int)tinyInfo.size());
2547 CPPUNIT_ASSERT_EQUAL(4,(int)tinyInfo[0]); //x
2548 CPPUNIT_ASSERT_EQUAL(4,(int)tinyInfo[1]); //y
2549 CPPUNIT_ASSERT_EQUAL(-1,(int)tinyInfo[2]); //z
2550 CPPUNIT_ASSERT_EQUAL(-1,(int)tinyInfo[3]); //it
2551 CPPUNIT_ASSERT_EQUAL(-1,(int)tinyInfo[4]); //order
2552 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,tinyInfoD[0],1e-14); //time
2553 DataArrayInt* d1=DataArrayInt::New();
2554 DataArrayDouble* d2=DataArrayDouble::New();
2555 mesh2d->resizeForUnserialization(tinyInfo, d1, d2, littleStrings);
2556 CPPUNIT_ASSERT_EQUAL(0,d1->getNumberOfTuples());
2557 CPPUNIT_ASSERT_EQUAL(8,d2->getNumberOfTuples());
2559 partMesh1->decrRef();
2560 partMesh2->decrRef();
2561 partMesh3->decrRef();
2568 coordsX1->decrRef();
2569 coordsY1->decrRef();
2570 coordsZ1->decrRef();
2574 void MEDCouplingBasicsTest1::testScale()
2576 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
2577 const double pos[2]={0.2,0.2};
2578 mesh->scale(pos,0.5);
2579 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,
2580 -0.05,0.45, 0.2,0.45, 0.45,0.45};
2581 const double *val=mesh->getCoords()->getConstPointer();
2582 for(int i=0;i<18;i++)
2583 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1e-12);
2588 void MEDCouplingBasicsTest1::testTryToShareSameCoords()
2590 MEDCouplingUMesh *m1=build2DTargetMesh_1();
2591 MEDCouplingUMesh *m2=build2DTargetMesh_1();
2592 CPPUNIT_ASSERT(m1->getCoords()!=m2->getCoords());
2593 m1->tryToShareSameCoords(*m2,1e-12);
2594 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2595 m1->tryToShareSameCoords(*m2,1e-12);
2596 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2597 m2->tryToShareSameCoords(*m1,1e-12);
2598 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2602 m1=build2DTargetMesh_1();
2603 m2=build2DTargetMesh_2();
2604 CPPUNIT_ASSERT(m1->getCoords()!=m2->getCoords());
2605 m1->tryToShareSameCoords(*m2,1e-12);
2606 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2607 m1->tryToShareSameCoords(*m2,1e-12);
2608 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2609 m2->tryToShareSameCoords(*m1,1e-12);
2610 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2614 m1=build2DTargetMesh_1();
2615 m2=build2DSourceMesh_1();
2616 CPPUNIT_ASSERT(m1->getCoords()!=m2->getCoords());
2617 CPPUNIT_ASSERT_THROW(m1->tryToShareSameCoords(*m2,1e-12),INTERP_KERNEL::Exception);
2622 void MEDCouplingBasicsTest1::testFindNodeOnPlane()
2624 MEDCouplingUMesh *mesh=build3DTargetMesh_1();
2626 double pt[3]={300.,300.,0.};
2627 double v[3]={0.,0.,2.};
2628 mesh->findNodesOnPlane(pt,v,1e-12,n);
2629 CPPUNIT_ASSERT_EQUAL(9,(int)n.size());
2630 MEDCouplingUMesh *m3dSurf=(MEDCouplingUMesh *)mesh->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
2631 MEDCouplingExtrudedMesh *me=MEDCouplingExtrudedMesh::New(mesh,m3dSurf,0);
2632 const DataArrayInt *da=me->getMesh3DIds();
2633 CPPUNIT_ASSERT_EQUAL(8,me->getNumberOfCells());
2634 const int expected[8]={0,1,2,3,4,5,6,7};
2635 const int *val=da->getConstPointer();
2636 for(int i=0;i<8;i++)
2637 CPPUNIT_ASSERT_EQUAL(expected[i],val[i]);
2643 void MEDCouplingBasicsTest1::testRenumberCells()
2645 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
2646 MEDCouplingUMesh *m2=build3DSurfTargetMesh_1();
2647 CPPUNIT_ASSERT(m->isEqual(m2,0));
2648 const int arr[5]={12,3,25,2,26};
2649 m->renumberCells(arr,true);
2650 CPPUNIT_ASSERT(!m->isEqual(m2,0));
2651 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(0));
2652 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(1));
2653 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(2));
2654 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(3));
2655 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(4));
2656 const int arr2[5]={5,-1,-5,4,8};
2657 m->renumberCells(arr2,true);
2658 CPPUNIT_ASSERT(m->isEqual(m2,0));
2663 void MEDCouplingBasicsTest1::testChangeSpaceDimension()
2665 MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
2666 MEDCouplingUMesh *m2=build2DTargetMesh_1();
2668 CPPUNIT_ASSERT_EQUAL(3,m1->getSpaceDimension());
2669 m1->changeSpaceDimension(2);
2670 CPPUNIT_ASSERT_EQUAL(2,m1->getSpaceDimension());
2671 m1->setName(m2->getName().c_str());
2672 CPPUNIT_ASSERT(m1->isEqual(m2,1e-12));
2673 m1->changeSpaceDimension(3);
2674 CPPUNIT_ASSERT_EQUAL(3,m1->getSpaceDimension());
2675 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.};
2676 const double *val=m1->getCoords()->getConstPointer();
2677 for(int i=0;i<27;i++)
2678 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected[i],val[i],1e-14);
2684 void MEDCouplingBasicsTest1::testSetConnectivity()
2686 MEDCouplingUMesh *m1 = build1DTargetMesh_1();
2688 DataArrayInt * conn = DataArrayInt::New();
2689 DataArrayInt * connI = DataArrayInt::New();
2690 m1->setConnectivity(conn, connI, true); // was SEG-Faulting with empty arrays