1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "MEDCouplingBasicsTest1.hxx"
22 #include "MEDCouplingUMesh.hxx"
23 #include "MEDCouplingCMesh.hxx"
24 #include "MEDCouplingExtrudedMesh.hxx"
25 #include "MEDCouplingFieldDouble.hxx"
26 #include "MEDCouplingMemArray.hxx"
33 using namespace ParaMEDMEM;
35 void MEDCouplingBasicsTest1::testArray()
37 int tmp1[6]={7,6,5,4,3,2};
38 const int tmp2[3]={8,9,10};
41 mem.useArray(tmp1,false,CPP_DEALLOC,6);
42 CPPUNIT_ASSERT(tmp1==mem.getConstPointer());
43 CPPUNIT_ASSERT_THROW(mem.getPointer(),INTERP_KERNEL::Exception);
44 CPPUNIT_ASSERT_THROW(mem[2]=7,INTERP_KERNEL::Exception);
45 CPPUNIT_ASSERT_THROW(mem.writeOnPlace(0,12,tmp2,3),INTERP_KERNEL::Exception);
46 mem.writeOnPlace(4,12,tmp2,3);
50 std::copy(tmp1,tmp1+6,tmp3);
52 mem2.useArray(tmp3,true,CPP_DEALLOC,6);
53 CPPUNIT_ASSERT(tmp3==mem2.getConstPointer());
54 CPPUNIT_ASSERT(tmp3==mem2.getPointer());
55 CPPUNIT_ASSERT_EQUAL(5,mem2[2]);
57 CPPUNIT_ASSERT_EQUAL(7,mem2[2]);
58 mem2.writeOnPlace(0,12,tmp2,3);
59 CPPUNIT_ASSERT_EQUAL(9,mem2[2]);
60 CPPUNIT_ASSERT_EQUAL(12,mem2[0]);
61 mem2.writeOnPlace(4,12,tmp2,3);
65 void MEDCouplingBasicsTest1::testArray2()
67 DataArrayDouble *arr=DataArrayDouble::New();
69 double *tmp=arr->getPointer();
70 const double arrRef[12]={12.,11.,10.,9.,8.,7.,6.,5.,4.,3.,2.,1.};
71 std::copy(arrRef,arrRef+12,tmp);
72 arr->setInfoOnComponent(0,"ggg");
73 arr->setInfoOnComponent(1,"hhhh");
74 arr->setInfoOnComponent(2,"jj");
75 arr->setInfoOnComponent(3,"kkkkkk");
76 DataArrayInt *arr2=arr->convertToIntArr();
77 DataArrayDouble *arr3=arr2->convertToDblArr();
79 CPPUNIT_ASSERT(arr->isEqual(*arr3,1e-14));
84 void MEDCouplingBasicsTest1::testArray3()
86 DataArrayInt *arr1=DataArrayInt::New();
88 int *tmp=arr1->getPointer();
89 const int arr1Ref[14]={0,10,1,11,2,12,3,13,4,14,5,15,6,16};
90 std::copy(arr1Ref,arr1Ref+14,tmp);
91 CPPUNIT_ASSERT_EQUAL(7,arr1->getNumberOfTuples());
92 CPPUNIT_ASSERT_EQUAL(2,arr1->getNumberOfComponents());
93 CPPUNIT_ASSERT(std::equal(arr1Ref,arr1Ref+14,arr1->getConstPointer()));
94 DataArrayInt *arr2=arr1->substr(3);
95 CPPUNIT_ASSERT_EQUAL(4,arr2->getNumberOfTuples());
96 CPPUNIT_ASSERT_EQUAL(2,arr2->getNumberOfComponents());
97 CPPUNIT_ASSERT(std::equal(arr1Ref+6,arr1Ref+14,arr2->getConstPointer()));
99 DataArrayInt *arr3=arr1->substr(2,5);
100 CPPUNIT_ASSERT_EQUAL(3,arr3->getNumberOfTuples());
101 CPPUNIT_ASSERT_EQUAL(2,arr3->getNumberOfComponents());
102 CPPUNIT_ASSERT(std::equal(arr1Ref+4,arr1Ref+10,arr3->getConstPointer()));
106 DataArrayDouble *arr4=DataArrayDouble::New();
108 double *tmp2=arr4->getPointer();
109 const double arr4Ref[14]={0.8,10.8,1.9,11.9,2.1,12.1,3.2,13.2,4.3,14.3,5.4,15.4,6.5,16.5};
110 std::copy(arr4Ref,arr4Ref+14,tmp2);
111 CPPUNIT_ASSERT_EQUAL(7,arr4->getNumberOfTuples());
112 CPPUNIT_ASSERT_EQUAL(2,arr4->getNumberOfComponents());
113 CPPUNIT_ASSERT(std::equal(arr4Ref,arr4Ref+14,arr4->getConstPointer()));
114 DataArrayDouble *arr5=arr4->substr(3);
115 CPPUNIT_ASSERT_EQUAL(4,arr5->getNumberOfTuples());
116 CPPUNIT_ASSERT_EQUAL(2,arr5->getNumberOfComponents());
117 CPPUNIT_ASSERT(std::equal(arr4Ref+6,arr4Ref+14,arr5->getConstPointer()));
119 DataArrayDouble *arr6=arr4->substr(2,5);
120 CPPUNIT_ASSERT_EQUAL(3,arr6->getNumberOfTuples());
121 CPPUNIT_ASSERT_EQUAL(2,arr6->getNumberOfComponents());
122 CPPUNIT_ASSERT(std::equal(arr4Ref+4,arr4Ref+10,arr6->getConstPointer()));
127 void MEDCouplingBasicsTest1::testMesh()
129 const int nbOfCells=6;
130 const int nbOfNodes=12;
132 double coords[3*nbOfNodes]={
133 0.024155, 0.04183768725682622, -0.305, 0.04831000000000001, -1.015761910347357e-17, -0.305, 0.09662000000000001, -1.832979297858306e-18,
134 -0.305, 0.120775, 0.04183768725682623, -0.305, 0.09662000000000001, 0.08367537451365245, -0.305, 0.04831000000000001,
135 0.08367537451365246, -0.305, 0.024155, 0.04183768725682622, -0.2863, 0.04831000000000001, -1.015761910347357e-17, -0.2863,
136 0.09662000000000001, -1.832979297858306e-18, -0.2863, 0.120775, 0.04183768725682623, -0.2863, 0.09662000000000001, 0.08367537451365245,
137 -0.2863, 0.04831000000000001, 0.08367537451365246, -0.2863, };
139 int tab4[4*nbOfCells]={
140 1, 2, 8, 7, 2, 3, 9, 8, 3, 4, 10, 9, 4, 5, 11, 10, 5, 0, 6, 11,
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->getAllTypes().size());
595 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*mesh->getAllTypes().begin());
596 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++(mesh->getAllTypes().begin())));
597 CPPUNIT_ASSERT_EQUAL(1,(int)subMesh->getAllTypes().size());
598 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllTypes().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->getAllTypes().size());
615 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*subMesh->getAllTypes().begin());
616 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++(subMesh->getAllTypes().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->getAllTypes().size());
644 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllTypes().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->getAllTypes().size());
659 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*subMesh->getAllTypes().begin());
660 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++subMesh->getAllTypes().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->getAllTypes().size());
676 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*subMesh->getAllTypes().begin());
677 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++subMesh->getAllTypes().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->getAllTypes().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->getAllTypes().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->getAllTypes().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->getAllTypes().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.);
1143 MEDCouplingUMesh *m3=m1->buildExtrudedMesh(m2,0);
1144 const int expected1[15]= {1,3,2,0,6,5,7,10,11,8,12,9,14,13,4};
1145 const int rexpected1[15]={3, 0, 2, 1, 14, 5, 4, 6, 9, 11, 7, 8, 10, 13, 12};
1146 m3->renumberCells(expected1,false);
1147 MEDCouplingExtrudedMesh *m4=MEDCouplingExtrudedMesh::New(m3,m1,0);
1148 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,m4->getTypeOfCell(0));
1149 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,m4->getTypeOfCell(1));
1150 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYHED,m4->getTypeOfCell(2));
1151 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_PENTA6,m4->getTypeOfCell(7));
1152 MEDCouplingFieldDouble *f=m4->getMeasureField(true);
1153 DataArrayDouble *arr=f->getArray();
1154 CPPUNIT_ASSERT_EQUAL(15,arr->getNumberOfTuples());
1155 CPPUNIT_ASSERT_EQUAL(1,arr->getNumberOfComponents());
1156 const double *arrPtr=arr->getConstPointer();
1157 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};
1158 for(int i=0;i<15;i++)
1159 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[rexpected1[i]],arrPtr[i],1e-16);
1161 MEDCouplingUMesh *m5=m4->build3DUnstructuredMesh();
1162 CPPUNIT_ASSERT(m5->isEqual(m3,1e-12));
1163 f=m5->getMeasureField(true);
1165 arrPtr=arr->getConstPointer();
1166 for(int i=0;i<15;i++)
1167 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[rexpected1[i]],arrPtr[i],1e-16);
1177 void MEDCouplingBasicsTest1::testFindCommonNodes()
1179 DataArrayInt *comm,*commI;
1180 MEDCouplingUMesh *targetMesh=build3DTargetMesh_1();
1181 targetMesh->findCommonNodes(1e-10,-1,comm,commI);
1182 CPPUNIT_ASSERT_EQUAL(1,commI->getNumberOfTuples());
1183 CPPUNIT_ASSERT_EQUAL(0,comm->getNumberOfTuples());
1185 DataArrayInt *o2n=targetMesh->buildNewNumberingFromCommonNodesFormat(comm,commI,newNbOfNodes);
1186 CPPUNIT_ASSERT_EQUAL(27,newNbOfNodes);
1187 CPPUNIT_ASSERT_EQUAL(27,o2n->getNumberOfTuples());
1188 const int o2nExp1[27]=
1190 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
1193 CPPUNIT_ASSERT(std::equal(o2nExp1,o2nExp1+27,o2n->getConstPointer()));
1197 targetMesh->decrRef();
1199 targetMesh=build3DTargetMeshMergeNode_1();
1200 CPPUNIT_ASSERT_EQUAL(31,targetMesh->getNumberOfNodes());
1201 targetMesh->findCommonNodes(1e-10,-1,comm,commI);
1202 CPPUNIT_ASSERT_EQUAL(3,commI->getNumberOfTuples());
1203 CPPUNIT_ASSERT_EQUAL(6,comm->getNumberOfTuples());
1204 const int commExpected[6]={1,27,28,29,23,30};
1205 const int commIExpected[3]={0,4,6};
1206 CPPUNIT_ASSERT(std::equal(commExpected,commExpected+6,comm->getConstPointer()));
1207 CPPUNIT_ASSERT(std::equal(commIExpected,commIExpected+3,commI->getConstPointer()));
1208 o2n=targetMesh->buildNewNumberingFromCommonNodesFormat(comm,commI,newNbOfNodes);
1209 CPPUNIT_ASSERT_EQUAL(31,o2n->getNumberOfTuples());
1210 CPPUNIT_ASSERT_EQUAL(27,newNbOfNodes);
1211 const int o2nExp2[31]=
1213 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
1214 21,22,23,24,25,26,1,1,1,23
1216 CPPUNIT_ASSERT(std::equal(o2nExp2,o2nExp2+31,o2n->getConstPointer()));
1220 targetMesh->decrRef();
1222 targetMesh=build3DTargetMesh_1();
1223 bool areNodesMerged;
1224 unsigned int time=targetMesh->getTimeOfThis();
1225 o2n=targetMesh->mergeNodes(1e-10,areNodesMerged,newNbOfNodes);
1226 targetMesh->updateTime();
1227 CPPUNIT_ASSERT(time==targetMesh->getTimeOfThis());
1228 CPPUNIT_ASSERT(!areNodesMerged);
1229 targetMesh->decrRef();
1232 targetMesh=build3DTargetMeshMergeNode_1();
1233 time=targetMesh->getTimeOfThis();
1234 o2n=targetMesh->mergeNodes(1e-10,areNodesMerged,newNbOfNodes);
1235 targetMesh->updateTime();
1236 CPPUNIT_ASSERT(time!=targetMesh->getTimeOfThis());
1237 CPPUNIT_ASSERT(areNodesMerged);
1238 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,
1239 18,4,5,8,7,13,14,17,16,
1240 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,
1241 18,13,14,17,16,22,23,26,25};
1242 CPPUNIT_ASSERT_EQUAL(72,targetMesh->getNodalConnectivity()->getNumberOfTuples());
1243 CPPUNIT_ASSERT(std::equal(connExp,connExp+72,targetMesh->getNodalConnectivity()->getConstPointer()));
1244 CPPUNIT_ASSERT_EQUAL(27,targetMesh->getCoords()->getNumberOfTuples());
1245 double coordsExp[81]={ 0., 0., 0., 50., 0., 0. , 200., 0., 0. , 0., 50., 0., 50., 50., 0. ,
1246 200., 50., 0., 0., 200., 0., 50., 200., 0. , 200., 200., 0. ,
1247 0., 0., 50., 50., 0., 50. , 200., 0., 50. , 0., 50., 50., 50.,
1248 50., 50. , 200., 50., 50., 0., 200., 50., 50., 200., 50. ,
1249 200., 200., 50. , 0., 0., 200., 50., 0., 200. , 200., 0., 200.
1250 , 0., 50., 200., 50., 50., 200. , 200., 50., 200.,
1251 0., 200., 200., 50., 200., 200. , 200., 200., 200. };
1252 CPPUNIT_ASSERT(std::equal(coordsExp,coordsExp+81,targetMesh->getCoords()->getConstPointer()));
1253 targetMesh->decrRef();
1256 targetMesh=build2DTargetMeshMergeNode_1();
1257 CPPUNIT_ASSERT_EQUAL(18,targetMesh->getNumberOfNodes());
1258 time=targetMesh->getTimeOfThis();
1259 o2n=targetMesh->mergeNodes(1e-10,areNodesMerged,newNbOfNodes);
1260 CPPUNIT_ASSERT(time!=targetMesh->getTimeOfThis());
1261 CPPUNIT_ASSERT(areNodesMerged);
1262 CPPUNIT_ASSERT_EQUAL(9,targetMesh->getNumberOfNodes());
1263 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};
1264 CPPUNIT_ASSERT_EQUAL(23,targetMesh->getNodalConnectivity()->getNumberOfTuples());
1265 CPPUNIT_ASSERT(std::equal(connExp2,connExp2+23,targetMesh->getNodalConnectivity()->getConstPointer()));
1266 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};
1267 CPPUNIT_ASSERT_EQUAL(9,targetMesh->getCoords()->getNumberOfTuples());
1268 CPPUNIT_ASSERT(std::equal(coordsExp2,coordsExp2+18,targetMesh->getCoords()->getConstPointer()));
1269 targetMesh->decrRef();
1273 void MEDCouplingBasicsTest1::testCheckButterflyCells()
1275 std::vector<int> cells;
1276 MEDCouplingUMesh *sourceMesh=build2DTargetMesh_1();
1277 sourceMesh->checkButterflyCells(cells);
1278 CPPUNIT_ASSERT(cells.empty());
1279 int *pt=sourceMesh->getNodalConnectivity()->getPointer();
1280 std::swap(pt[15],pt[16]);
1281 sourceMesh->checkButterflyCells(cells);
1282 CPPUNIT_ASSERT_EQUAL(1,(int)cells.size());
1283 CPPUNIT_ASSERT_EQUAL(3,cells[0]);
1285 std::swap(pt[15],pt[16]);
1286 sourceMesh->checkButterflyCells(cells);
1287 CPPUNIT_ASSERT(cells.empty());
1288 sourceMesh->decrRef();
1290 sourceMesh=build3DSurfTargetMesh_1();
1291 sourceMesh->checkButterflyCells(cells);
1292 CPPUNIT_ASSERT(cells.empty());
1293 pt=sourceMesh->getNodalConnectivity()->getPointer();
1294 std::swap(pt[15],pt[16]);
1295 sourceMesh->checkButterflyCells(cells);
1296 CPPUNIT_ASSERT_EQUAL(1,(int)cells.size());
1297 CPPUNIT_ASSERT_EQUAL(3,cells[0]);
1299 std::swap(pt[15],pt[16]);
1300 sourceMesh->checkButterflyCells(cells);
1301 CPPUNIT_ASSERT(cells.empty());
1302 sourceMesh->decrRef();
1305 void MEDCouplingBasicsTest1::testMergeMesh1()
1307 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1308 MEDCouplingUMesh *m2=build2DSourceMesh_1();
1309 const double vec[2]={1.,0.};
1311 MEDCouplingMesh *m3=m1->mergeMyselfWith(m2);
1312 MEDCouplingUMesh *m3C=dynamic_cast<MEDCouplingUMesh *>(m3);
1313 CPPUNIT_ASSERT(m3C);
1314 m3->checkCoherency();
1315 MEDCouplingUMesh *m4=build2DTargetMeshMerged_1();
1316 CPPUNIT_ASSERT(m3->isEqual(m4,1.e-12));
1320 DataArrayInt *da=m3C->mergeNodes(1.e-12,isMerged,newNbOfNodes);
1321 CPPUNIT_ASSERT_EQUAL(11,m3C->getNumberOfNodes());
1322 CPPUNIT_ASSERT_EQUAL(11,newNbOfNodes);
1323 CPPUNIT_ASSERT(isMerged);
1330 void MEDCouplingBasicsTest1::testMergeMeshOnSameCoords1()
1332 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1333 MEDCouplingUMesh *m2=build2DTargetMesh_1();
1334 std::vector<int> cells(5);
1335 for(int i=0;i<5;i++)
1337 m2->convertToPolyTypes(&cells[0],&cells[0]+cells.size());
1338 m1->tryToShareSameCoords(*m2,1e-12);
1339 MEDCouplingUMesh *m3=build2DTargetMesh_1();
1340 m3->tryToShareSameCoords(*m2,1e-12);
1341 std::vector<const MEDCouplingUMesh *> meshes;
1342 meshes.push_back(m1); meshes.push_back(m2); meshes.push_back(m3);
1343 MEDCouplingUMesh *m4=MEDCouplingUMesh::MergeUMeshesOnSameCoords(meshes);
1344 m4->checkCoherency();
1345 CPPUNIT_ASSERT(m4->getCoords()==m1->getCoords());
1346 CPPUNIT_ASSERT_EQUAL(15,m4->getNumberOfCells());
1347 const int cells1[5]={0,1,2,3,4};
1348 MEDCouplingPointSet *m1_1=m4->buildPartOfMySelf(cells1,cells1+5,true);
1349 m1_1->setName(m1->getName().c_str());
1350 CPPUNIT_ASSERT(m1->isEqual(m1_1,1e-12));
1351 const int cells2[5]={5,6,7,8,9};
1352 MEDCouplingPointSet *m2_1=m4->buildPartOfMySelf(cells2,cells2+5,true);
1353 m2_1->setName(m2->getName().c_str());
1354 CPPUNIT_ASSERT(m2->isEqual(m2_1,1e-12));
1355 const int cells3[5]={10,11,12,13,14};
1356 MEDCouplingPointSet *m3_1=m4->buildPartOfMySelf(cells3,cells3+5,true);
1357 m3_1->setName(m3->getName().c_str());
1358 CPPUNIT_ASSERT(m3->isEqual(m3_1,1e-12));
1359 m1_1->decrRef(); m2_1->decrRef(); m3_1->decrRef();
1367 void MEDCouplingBasicsTest1::testMergeField1()
1369 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1370 MEDCouplingUMesh *m2=build2DSourceMesh_1();
1371 const double vec[2]={1.,0.};
1373 MEDCouplingFieldDouble *f1=m1->getMeasureField(true);
1374 MEDCouplingFieldDouble *f2=m2->getMeasureField(true);
1375 MEDCouplingFieldDouble *f3=MEDCouplingFieldDouble::MergeFields(f1,f2);
1376 f3->checkCoherency();
1377 MEDCouplingUMesh *m4=build2DTargetMeshMerged_1();
1378 CPPUNIT_ASSERT(f3->getMesh()->isEqual(m4,1.e-12));
1379 std::string name=f3->getName();
1380 CPPUNIT_ASSERT(name=="MeasureOfMesh_");
1381 CPPUNIT_ASSERT(f3->getTypeOfField()==ON_CELLS);
1382 CPPUNIT_ASSERT(f3->getTimeDiscretization()==ONE_TIME);
1383 CPPUNIT_ASSERT_EQUAL(1,f3->getNumberOfComponents());
1384 CPPUNIT_ASSERT_EQUAL(7,f3->getNumberOfTuples());
1385 double values[7]={0.25,0.125,0.125,0.25,0.25,0.5,0.5};
1386 const double *tmp=f3->getArray()->getConstPointer();
1387 std::transform(tmp,tmp+7,values,values,std::minus<double>());
1388 std::transform(values,values+7,values,std::ptr_fun<double,double>(fabs));
1389 double max=*std::max_element(values,values+7);
1390 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1399 bool func1(const double *pt, double *res);
1400 bool func2(const double *pt, double *res);
1401 bool func3(const double *pt, double *res);
1402 bool func4(const double *pt, double *res);
1404 bool func1(const double *pt, double *res)
1410 bool func2(const double *pt, double *res)
1413 res[1]=2.*(pt[0]+pt[1]);
1417 bool func3(const double *pt, double *res)
1419 if(fabs(pt[0]-0.2)<1e-12)
1421 res[0]=1./(pt[0]-0.2);
1425 void MEDCouplingBasicsTest1::testFillFromAnalytic()
1427 MEDCouplingUMesh *m=build2DTargetMesh_1();
1428 m->setTime(3.4,5,6); m->setTimeUnit("us");
1430 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_CELLS,1,func1);
1431 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.4,f1->getTime(a,b),1.e-14);
1432 CPPUNIT_ASSERT_EQUAL(5,a); CPPUNIT_ASSERT_EQUAL(6,b);
1433 CPPUNIT_ASSERT_EQUAL(std::string(f1->getTimeUnit()),std::string("us"));
1434 f1->checkCoherency();
1435 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_CELLS);
1436 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1437 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1438 CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
1439 double values1[5]={-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9};
1440 const double *tmp=f1->getArray()->getConstPointer();
1441 std::transform(tmp,tmp+5,values1,values1,std::minus<double>());
1442 std::transform(values1,values1+5,values1,std::ptr_fun<double,double>(fabs));
1443 double max=*std::max_element(values1,values1+5);
1444 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1447 f1=m->fillFromAnalytic(ON_NODES,1,func1);
1448 f1->checkCoherency();
1449 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1450 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1451 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1452 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1453 double values2[9]={-0.6,-0.1,0.4,-0.1,0.4,0.9,0.4,0.9,1.4};
1454 tmp=f1->getArray()->getConstPointer();
1455 std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
1456 std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
1457 max=*std::max_element(values2,values2+9);
1458 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1461 f1=m->fillFromAnalytic(ON_NODES,2,func2);
1462 f1->checkCoherency();
1463 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1464 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1465 CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
1466 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1467 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};
1468 tmp=f1->getArray()->getConstPointer();
1469 std::transform(tmp,tmp+18,values3,values3,std::minus<double>());
1470 std::transform(values3,values3+18,values3,std::ptr_fun<double,double>(fabs));
1471 max=*std::max_element(values3,values3+18);
1472 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1474 f1->accumulate(values4);
1475 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.6,values4[0],1.e-12);
1476 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.2,values4[1],1.e-12);
1477 f1->integral(true,values4);
1478 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,values4[0],1.e-12);
1479 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,values4[1],1.e-12);
1482 CPPUNIT_ASSERT_THROW(f1=m->fillFromAnalytic(ON_NODES,1,func3),INTERP_KERNEL::Exception);
1487 void MEDCouplingBasicsTest1::testFillFromAnalytic2()
1489 MEDCouplingUMesh *m=build2DTargetMesh_1();
1490 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_CELLS,1,"y+x");
1491 f1->checkCoherency();
1492 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_CELLS);
1493 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1494 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1495 CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
1496 double values1[5]={-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9};
1497 const double *tmp=f1->getArray()->getConstPointer();
1498 std::transform(tmp,tmp+5,values1,values1,std::minus<double>());
1499 std::transform(values1,values1+5,values1,std::ptr_fun<double,double>(fabs));
1500 double max=*std::max_element(values1,values1+5);
1501 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1504 f1=m->fillFromAnalytic(ON_NODES,1,"y+2*x");
1505 f1->checkCoherency();
1506 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1507 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1508 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1509 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1510 double values2[9]={-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1};
1511 tmp=f1->getArray()->getConstPointer();
1512 std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
1513 std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
1514 max=*std::max_element(values2,values2+9);
1515 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1517 f1=m->fillFromAnalytic(ON_NODES,1,"2.*x+y");
1518 f1->checkCoherency();
1519 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1520 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1521 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1522 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1523 tmp=f1->getArray()->getConstPointer();
1524 double values2Bis[9]={-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1};
1525 std::transform(tmp,tmp+9,values2Bis,values2Bis,std::minus<double>());
1526 std::transform(values2,values2+9,values2Bis,std::ptr_fun<double,double>(fabs));
1527 max=*std::max_element(values2Bis,values2Bis+9);
1528 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1531 f1=m->fillFromAnalytic(ON_NODES,2,"(x+y)*IVec+2*(x+y)*JVec");
1532 f1->checkCoherency();
1533 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1534 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1535 CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
1536 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1537 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};
1538 tmp=f1->getArray()->getConstPointer();
1539 std::transform(tmp,tmp+18,values3,values3,std::minus<double>());
1540 std::transform(values3,values3+18,values3,std::ptr_fun<double,double>(fabs));
1541 max=*std::max_element(values3,values3+18);
1542 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1544 f1->accumulate(values4);
1545 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.6,values4[0],1.e-12);
1546 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.2,values4[1],1.e-12);
1547 f1->integral(true,values4);
1548 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,values4[0],1.e-12);
1549 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,values4[1],1.e-12);
1552 CPPUNIT_ASSERT_THROW(f1=m->fillFromAnalytic(ON_NODES,1,"1./(x-0.2)"),INTERP_KERNEL::Exception);
1557 void MEDCouplingBasicsTest1::testApplyFunc()
1559 MEDCouplingUMesh *m=build2DTargetMesh_1();
1560 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,2,func2);
1561 f1->checkCoherency();
1562 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1563 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1564 CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
1565 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1566 f1->applyFunc(1,func1);
1567 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1568 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1569 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1570 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1571 double values1[9]={-1.8,-0.3,1.2,-0.3,1.2,2.7,1.2,2.7,4.2};
1572 const double *tmp=f1->getArray()->getConstPointer();
1573 std::transform(tmp,tmp+9,values1,values1,std::minus<double>());
1574 std::transform(values1,values1+9,values1,std::ptr_fun<double,double>(fabs));
1575 double max=*std::max_element(values1,values1+9);
1576 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1581 void MEDCouplingBasicsTest1::testApplyFunc2()
1583 MEDCouplingUMesh *m=build2DTargetMesh_1();
1584 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,2,func2);
1585 f1->checkCoherency();
1586 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1587 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1588 CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
1589 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1591 MEDCouplingFieldDouble *f2=f1->clone(true);
1592 CPPUNIT_ASSERT_THROW(f2->applyFunc(1,"a+b+c+d"),INTERP_KERNEL::Exception);
1593 CPPUNIT_ASSERT_THROW(f2->applyFunc(1,"a/0"),INTERP_KERNEL::Exception);
1594 CPPUNIT_ASSERT_THROW(f2->applyFunc("a/0"),INTERP_KERNEL::Exception);
1595 f2->applyFunc("abs(u)^2.4+2*u");
1596 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1597 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1598 CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
1599 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1600 double values2[18]={-0.9065304805418678, -0.85105859001709905, -0.19601892829446504, -0.37898777756476987,
1601 0.91090317490482353, 2.1853504664669781, -0.19601892829446504, -0.37898777756476987,
1602 0.91090317490482353, 2.1853504664669781, 2.5765725275664879, 7.6987743736515295,
1603 0.91090317490482353, 2.1853504664669781, 2.5765725275664879, 7.6987743736515295,
1604 5.0423700574830965, 17.435300118916864};
1605 const double *tmp=f2->getArray()->getConstPointer();
1606 std::transform(tmp,tmp+18,values2,values2,std::minus<double>());
1607 std::transform(values2,values2+18,values2,std::ptr_fun<double,double>(fabs));
1608 double max=*std::max_element(values2,values2+18);
1609 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1612 f1->applyFunc(1,"x+y");
1613 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1614 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1615 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1616 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1617 double values1[9]={-1.8,-0.3,1.2,-0.3,1.2,2.7,1.2,2.7,4.2};
1618 tmp=f1->getArray()->getConstPointer();
1619 std::transform(tmp,tmp+9,values1,values1,std::minus<double>());
1620 std::transform(values1,values1+9,values1,std::ptr_fun<double,double>(fabs));
1621 max=*std::max_element(values1,values1+9);
1622 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1627 void MEDCouplingBasicsTest1::testOperationsOnFields()
1629 MEDCouplingUMesh *m=build2DTargetMesh_1();
1630 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,1,func1);
1631 MEDCouplingFieldDouble *f2=m->fillFromAnalytic(ON_NODES,1,func1);
1632 f1->checkCoherency();
1633 f2->checkCoherency();
1634 MEDCouplingFieldDouble *f3=(*f1)+(*f2);
1635 f3->checkCoherency();
1636 CPPUNIT_ASSERT(f3->getTypeOfField()==ON_NODES);
1637 CPPUNIT_ASSERT(f3->getTimeDiscretization()==ONE_TIME);
1638 double values1[9]={-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8};
1639 const double *tmp=f3->getArray()->getConstPointer();
1640 std::transform(tmp,tmp+9,values1,values1,std::minus<double>());
1641 std::transform(values1,values1+9,values1,std::ptr_fun<double,double>(fabs));
1642 double max=*std::max_element(values1,values1+9);
1643 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1647 f3->checkCoherency();
1648 CPPUNIT_ASSERT(f3->getTypeOfField()==ON_NODES);
1649 CPPUNIT_ASSERT(f3->getTimeDiscretization()==ONE_TIME);
1650 double values2[9]={0.36,0.01,0.16,0.01,0.16,0.81,0.16,0.81,1.96};
1651 tmp=f3->getArray()->getConstPointer();
1652 std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
1653 std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
1654 max=*std::max_element(values2,values2+9);
1655 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1659 MEDCouplingFieldDouble *f4=(*f1)-(*f3);
1660 f4->checkCoherency();
1661 CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1662 CPPUNIT_ASSERT(f4->getTimeDiscretization()==ONE_TIME);
1663 double values3[9]={0.6,0.1,-0.4,0.1,-0.4,-0.9,-0.4,-0.9,-1.4};
1664 tmp=f4->getArray()->getConstPointer();
1665 std::transform(tmp,tmp+9,values3,values3,std::minus<double>());
1666 std::transform(values3,values3+9,values3,std::ptr_fun<double,double>(fabs));
1667 max=*std::max_element(values3,values3+9);
1668 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1674 f4->checkCoherency();
1675 CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1676 CPPUNIT_ASSERT(f4->getTimeDiscretization()==ONE_TIME);
1677 tmp=f4->getArray()->getConstPointer();
1678 for(int i=0;i<9;i++)
1679 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.,tmp[i],1.e-12);
1683 f4=f2->buildNewTimeReprFromThis(NO_TIME,false);
1684 f4->checkCoherency();
1685 CPPUNIT_ASSERT(f4->getArray()==f2->getArray());
1686 CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1687 CPPUNIT_ASSERT(f4->getTimeDiscretization()==NO_TIME);
1688 CPPUNIT_ASSERT_THROW(f3=(*f1)+(*f4),INTERP_KERNEL::Exception);
1689 MEDCouplingFieldDouble *f5=f4->buildNewTimeReprFromThis(ONE_TIME,false);
1690 CPPUNIT_ASSERT(f4->getArray()==f5->getArray());
1691 CPPUNIT_ASSERT(f5->getTypeOfField()==ON_NODES);
1692 CPPUNIT_ASSERT(f5->getTimeDiscretization()==ONE_TIME);
1694 tmp=f3->getArray()->getConstPointer();
1695 double values4[9]={-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8};
1696 std::transform(tmp,tmp+9,values4,values4,std::minus<double>());
1697 std::transform(values4,values4+9,values4,std::ptr_fun<double,double>(fabs));
1698 max=*std::max_element(values4,values4+9);
1699 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1704 f4=f2->buildNewTimeReprFromThis(NO_TIME,true);
1705 f4->checkCoherency();
1706 CPPUNIT_ASSERT(f4->getArray()!=f2->getArray());
1707 CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1708 CPPUNIT_ASSERT(f4->getTimeDiscretization()==NO_TIME);
1709 CPPUNIT_ASSERT_THROW(f3=(*f1)+(*f4),INTERP_KERNEL::Exception);
1710 f5=f4->buildNewTimeReprFromThis(ONE_TIME,true);
1711 CPPUNIT_ASSERT(f4->getArray()!=f5->getArray());
1712 CPPUNIT_ASSERT(f2->getArray()!=f5->getArray());
1713 CPPUNIT_ASSERT(f5->getTypeOfField()==ON_NODES);
1714 CPPUNIT_ASSERT(f5->getTimeDiscretization()==ONE_TIME);
1716 tmp=f3->getArray()->getConstPointer();
1717 double values5[9]={-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8};
1718 std::transform(tmp,tmp+9,values5,values5,std::minus<double>());
1719 std::transform(values5,values5+9,values5,std::ptr_fun<double,double>(fabs));
1720 max=*std::max_element(values5,values5+9);
1721 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1731 void MEDCouplingBasicsTest1::testOperationsOnFields2()
1733 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1734 m->setTime(3.4,5,6); m->setTimeUnit("us");
1736 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,1,"x+y+z");
1737 MEDCouplingFieldDouble *f2=m->fillFromAnalytic(ON_NODES,1,"a*a+b+c*c");
1738 MEDCouplingFieldDouble *f3=(*f1)/(*f2);
1739 f3->checkCoherency();
1740 CPPUNIT_ASSERT(f3->getTypeOfField()==ON_NODES);
1741 CPPUNIT_ASSERT(f3->getTimeDiscretization()==ONE_TIME);
1742 const double expected1[9]={-2.4999999999999991, 1.2162162162162162, 0.77868852459016391,
1743 0.7407407407407407, 1.129032258064516, 0.81632653061224492,
1744 0.86538461538461531, 1.0919540229885056, 0.84302325581395343};
1745 CPPUNIT_ASSERT_EQUAL(1,f3->getNumberOfComponents());
1746 CPPUNIT_ASSERT_EQUAL(9,f3->getNumberOfTuples());
1747 const double *val=f3->getArray()->getConstPointer();
1748 for(int i=0;i<9;i++)
1749 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1.e-12);
1754 f1=m->buildOrthogonalField();
1755 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.4,f1->getTime(a,b),1.e-14);
1756 CPPUNIT_ASSERT_EQUAL(5,a); CPPUNIT_ASSERT_EQUAL(6,b);
1757 CPPUNIT_ASSERT_EQUAL(std::string(f1->getTimeUnit()),std::string("us"));
1758 f2=m->fillFromAnalytic(ON_CELLS,1,"x");
1760 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};
1761 val=f3->getArray()->getConstPointer();
1762 for(int i=0;i<15;i++)
1763 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1.e-12);
1767 val=f3->getArray()->getConstPointer();
1768 for(int i=0;i<15;i++)
1769 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1.e-12);
1778 void MEDCouplingBasicsTest1::testOperationsOnFields3()
1780 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1781 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,1,"x+y+z");
1782 MEDCouplingFieldDouble *f2=m->fillFromAnalytic(ON_NODES,1,"a*a+b+c*c");
1784 f1->checkCoherency();
1785 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1786 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1787 const double expected1[9]={-2.4999999999999991, 1.2162162162162162, 0.77868852459016391,
1788 0.7407407407407407, 1.129032258064516, 0.81632653061224492,
1789 0.86538461538461531, 1.0919540229885056, 0.84302325581395343};
1790 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1791 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
1792 const double *val=f1->getArray()->getConstPointer();
1793 for(int i=0;i<9;i++)
1794 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1.e-12);
1798 f1=m->buildOrthogonalField();
1799 f2=m->fillFromAnalytic(ON_CELLS,1,"x");
1801 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};
1802 val=f1->getArray()->getConstPointer();
1803 for(int i=0;i<15;i++)
1804 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1.e-12);
1807 f1=m->buildOrthogonalField();
1808 CPPUNIT_ASSERT_THROW((*f2)*=(*f1),INTERP_KERNEL::Exception);
1816 * Check of LINEAR_TIME and CONST_ON_TIME_INTERVAL policies
1818 void MEDCouplingBasicsTest1::testOperationsOnFields4()
1820 MEDCouplingUMesh *m=build2DTargetMesh_1();
1821 int nbOfCells=m->getNumberOfCells();
1822 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,CONST_ON_TIME_INTERVAL);
1824 DataArrayDouble *array=DataArrayDouble::New();
1825 array->alloc(nbOfCells,3);
1826 f1->setArray(array);
1827 CPPUNIT_ASSERT_THROW(f1->setEndArray(array),INTERP_KERNEL::Exception);
1828 CPPUNIT_ASSERT_THROW(f1->getEndArray(),INTERP_KERNEL::Exception);
1830 double *tmp=array->getPointer();
1831 const double arr1[15]={0.,10.,20.,1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.};
1832 const double arr2[15]={5.,15.,25.,6.,16.,26.,7.,17.,27.,8.,18.,28.,9.,19.,29.};
1833 std::copy(arr1,arr1+15,tmp);
1834 f1->setStartTime(2.,0,0);
1835 f1->setEndTime(3.,0,0);
1836 f1->checkCoherency();
1838 const double pos[2]={0.3,-0.2};
1839 f1->getValueOn(pos,res);
1840 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[3],res[0],1.e-12);
1841 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[4],res[1],1.e-12);
1842 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[5],res[2],1.e-12);
1843 std::fill(res,res+3,0.);
1844 f1->getValueOn(pos,2.2,res);
1845 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[3],res[0],1.e-12);
1846 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[4],res[1],1.e-12);
1847 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[5],res[2],1.e-12);
1848 std::fill(res,res+3,0.);
1849 CPPUNIT_ASSERT_THROW(f1->getValueOn(pos,3.2,res),INTERP_KERNEL::Exception);
1850 MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
1852 f2->setArray(f1->getArray());
1853 f2->setStartTime(2.,3,0);
1854 f2->setEndTime(4.,13,0);
1855 CPPUNIT_ASSERT_THROW(f2->checkCoherency(),INTERP_KERNEL::Exception);
1856 DataArrayDouble *array2=DataArrayDouble::New();
1857 array2->alloc(nbOfCells,3);
1858 tmp=array2->getPointer();
1859 std::copy(arr2,arr2+15,tmp);
1860 f2->setEndArray(array2);
1862 f2->checkCoherency();
1864 std::fill(res,res+3,0.);
1865 f2->getValueOn(pos,3.21,res);
1866 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.025,res[0],1.e-12);
1867 CPPUNIT_ASSERT_DOUBLES_EQUAL(14.025,res[1],1.e-12);
1868 CPPUNIT_ASSERT_DOUBLES_EQUAL(24.025,res[2],1.e-12);
1869 MEDCouplingFieldDouble *f3=f2->clone(true);
1870 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-12));
1871 f3->getEndArray()->getPointer()[0]=5.001;
1872 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-12));
1873 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1874 f3->setStartTime(2.1,3,0);
1875 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1876 f3->setStartTime(2.,3,0);
1877 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1878 f3->setStartTime(2.,4,0);
1879 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1880 f3->setStartTime(2.,3,1);
1881 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1882 f3->setStartTime(2.,3,0);
1883 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1884 f3->setEndTime(4.1,13,0);
1885 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1886 f3->setEndTime(4.,13,0);
1887 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1888 f3->setEndTime(4.,14,0);
1889 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1890 f3->setEndTime(4.,13,1);
1891 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1892 f3->setEndTime(4.,13,0);
1893 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1895 MEDCouplingFieldDouble *f4=(*f2)+(*f2);
1896 std::fill(res,res+3,0.);
1897 f4->getValueOn(pos,3.21,res);
1898 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.05,res[0],1.e-12);
1899 CPPUNIT_ASSERT_DOUBLES_EQUAL(28.05,res[1],1.e-12);
1900 CPPUNIT_ASSERT_DOUBLES_EQUAL(48.05,res[2],1.e-12);
1902 std::fill(res,res+3,0.);
1903 f4->getValueOn(pos,3.21,res);
1904 CPPUNIT_ASSERT_DOUBLES_EQUAL(12.075,res[0],1.e-12);
1905 CPPUNIT_ASSERT_DOUBLES_EQUAL(42.075,res[1],1.e-12);
1906 CPPUNIT_ASSERT_DOUBLES_EQUAL(72.075,res[2],1.e-12);
1914 bool func4(const double *pt, double *res)
1916 res[0]=pt[0]+pt[1]+pt[2];
1920 void MEDCouplingBasicsTest1::testMergeNodesOnField()
1923 MEDCouplingUMesh *targetMesh=build3DTargetMeshMergeNode_1();
1924 MEDCouplingFieldDouble *f1=targetMesh->fillFromAnalytic(ON_NODES,1,func4);
1925 f1->mergeNodes(1e-10);
1927 targetMesh->decrRef();
1929 targetMesh=build3DTargetMeshMergeNode_1();
1930 f1=targetMesh->fillFromAnalytic(ON_NODES,1,func4);
1931 tmp=f1->getArray()->getPointer();
1933 f1->mergeNodes(1e-10);
1935 targetMesh->decrRef();
1937 targetMesh=build3DTargetMeshMergeNode_1();
1938 f1=targetMesh->fillFromAnalytic(ON_NODES,1,func4);
1939 tmp=f1->getArray()->getPointer();
1941 CPPUNIT_ASSERT_THROW(f1->mergeNodes(1e-10),INTERP_KERNEL::Exception);
1943 targetMesh->decrRef();
1946 void MEDCouplingBasicsTest1::testCheckConsecutiveCellTypes()
1948 MEDCouplingUMesh *sourceMesh=build2DSourceMesh_1();
1949 MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
1950 CPPUNIT_ASSERT(sourceMesh->checkConsecutiveCellTypes());
1951 const INTERP_KERNEL::NormalizedCellType order1[]={INTERP_KERNEL::NORM_TRI3, INTERP_KERNEL::NORM_QUAD4};
1952 const INTERP_KERNEL::NormalizedCellType order2[]={INTERP_KERNEL::NORM_QUAD4, INTERP_KERNEL::NORM_TRI3};
1953 CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypes());
1954 CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypesAndOrder(order1,order1+2));
1955 CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypesAndOrder(order2,order2+2));
1956 DataArrayInt *da=targetMesh->getRenumArrForConsecutiveCellTypesSpec(order1,order1+2);
1957 CPPUNIT_ASSERT_EQUAL(5,da->getNumberOfTuples());
1958 CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfComponents());
1959 const int expected1[5]={2,0,1,3,4};
1960 CPPUNIT_ASSERT(std::equal(expected1,expected1+5,da->getConstPointer()));
1962 da=targetMesh->getRenumArrForConsecutiveCellTypesSpec(order2,order2+2);
1963 CPPUNIT_ASSERT_EQUAL(5,da->getNumberOfTuples());
1964 CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfComponents());
1965 const int expected2[5]={0,3,4,1,2};
1966 CPPUNIT_ASSERT(std::equal(expected2,expected2+5,da->getConstPointer()));
1968 const int renumber1[5]={4,0,1,2,3};
1969 targetMesh->renumberCells(renumber1,false);
1970 CPPUNIT_ASSERT(targetMesh->checkConsecutiveCellTypes());
1971 CPPUNIT_ASSERT(targetMesh->checkConsecutiveCellTypesAndOrder(order1,order1+2));
1972 CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypesAndOrder(order2,order2+2));
1973 targetMesh->decrRef();
1974 sourceMesh->decrRef();
1977 void MEDCouplingBasicsTest1::testRearrange2ConsecutiveCellTypes()
1979 MEDCouplingUMesh *m1_1=build2DSourceMesh_1();
1980 MEDCouplingUMesh *m2_1=build2DTargetMesh_1();
1981 DataArrayInt *arr1=m1_1->rearrange2ConsecutiveCellTypes();
1982 MEDCouplingUMesh *m1_2=build2DSourceMesh_1();
1983 CPPUNIT_ASSERT(m1_2->isEqual(m1_1,1e-12));
1984 const int expected1[2]={0,1};
1985 CPPUNIT_ASSERT_EQUAL(2,arr1->getNumberOfTuples());
1986 CPPUNIT_ASSERT_EQUAL(1,arr1->getNumberOfComponents());
1987 CPPUNIT_ASSERT(std::equal(expected1,expected1+2,arr1->getConstPointer()));
1989 const int expected2[5]={0,3,4,1,2};
1990 arr1=m2_1->rearrange2ConsecutiveCellTypes();
1991 CPPUNIT_ASSERT_EQUAL(5,arr1->getNumberOfTuples());
1992 CPPUNIT_ASSERT_EQUAL(1,arr1->getNumberOfComponents());
1993 CPPUNIT_ASSERT(std::equal(expected2,expected2+5,arr1->getConstPointer()));
1994 MEDCouplingUMesh *m2_2=build2DTargetMesh_1();
1995 CPPUNIT_ASSERT_EQUAL(5,arr1->getNumberOfTuples());
1996 CPPUNIT_ASSERT_EQUAL(1,arr1->getNumberOfComponents());
1997 CPPUNIT_ASSERT(std::equal(expected2,expected2+5,arr1->getConstPointer()));
1998 CPPUNIT_ASSERT(!m2_2->isEqual(m2_1,1e-12));
1999 m2_2->renumberCells(expected2,false);
2000 CPPUNIT_ASSERT(m2_2->isEqual(m2_1,1e-12));
2008 void MEDCouplingBasicsTest1::testSplitByType()
2010 MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
2011 std::vector<MEDCouplingUMesh *> v=m1->splitByType();
2012 CPPUNIT_ASSERT_EQUAL(3,(int)v.size());
2013 std::vector<const MEDCouplingUMesh *> v2(v.begin(),v.end());
2014 MEDCouplingUMesh *m2=MEDCouplingUMesh::MergeUMeshesOnSameCoords(v2);
2015 m2->setName(m1->getName().c_str());
2016 CPPUNIT_ASSERT(m1->isEqual(m2,1.e-12));
2017 for(std::vector<MEDCouplingUMesh *>::const_iterator iter=v.begin();iter!=v.end();iter++)
2023 void MEDCouplingBasicsTest1::testFuseUMeshesOnSameCoords()
2025 std::vector<const MEDCouplingUMesh *> meshes;
2026 MEDCouplingUMesh *m2=build2DTargetMesh_1();
2027 int cells1[3]={2,3,4};
2028 MEDCouplingPointSet *m3_1=m2->buildPartOfMySelf(cells1,cells1+3,true);
2029 MEDCouplingUMesh *m3=dynamic_cast<MEDCouplingUMesh *>(m3_1);
2031 meshes.push_back(m3);
2032 int cells2[3]={1,2,4};
2033 MEDCouplingPointSet *m4_1=m2->buildPartOfMySelf(cells2,cells2+3,true);
2034 MEDCouplingUMesh *m4=dynamic_cast<MEDCouplingUMesh *>(m4_1);
2036 meshes.push_back(m4);
2037 int cells3[2]={1,2};
2038 MEDCouplingPointSet *m5_1=m2->buildPartOfMySelf(cells3,cells3+2,true);
2039 MEDCouplingUMesh *m5=dynamic_cast<MEDCouplingUMesh *>(m5_1);
2041 meshes.push_back(m5);
2044 std::vector<DataArrayInt *> corr;
2045 MEDCouplingUMesh *m7=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
2046 CPPUNIT_ASSERT_EQUAL(4,m7->getNumberOfCells());
2047 CPPUNIT_ASSERT_EQUAL(3,(int)corr.size());
2048 const int expectedVals1[3]={3,3,2};
2049 const int expectedVals2[3][3]={{0,1,2},{3,0,2},{3,0,111111}};
2050 for(int i=0;i<3;i++)
2052 DataArrayInt *arr=corr[i];
2053 CPPUNIT_ASSERT_EQUAL(1,arr->getNumberOfComponents());
2054 int nbOfVals=expectedVals1[i];
2055 CPPUNIT_ASSERT_EQUAL(nbOfVals,arr->getNumberOfTuples());
2056 const int *vals=arr->getConstPointer();
2057 for(int j=0;j<nbOfVals;j++)
2058 CPPUNIT_ASSERT_EQUAL(expectedVals2[i][j],vals[j]);
2060 std::vector< std::vector<int> > fidsOfGroups;
2061 std::vector<const DataArrayInt *> corr2(corr.begin(),corr.end());
2062 DataArrayInt *arr2=DataArrayInt::MakePartition(corr2,m7->getNumberOfCells(),fidsOfGroups);
2063 const int fidExp[4]={5,1,3,4};
2064 const int fidsGrp[3][3]={{1,3,5},{3,4,5},{4,5,23344}};
2065 CPPUNIT_ASSERT_EQUAL(3,(int)fidsOfGroups.size());
2066 CPPUNIT_ASSERT_EQUAL(1,arr2->getNumberOfComponents());
2067 CPPUNIT_ASSERT_EQUAL(4,arr2->getNumberOfTuples());
2068 CPPUNIT_ASSERT(std::equal(fidExp,fidExp+4,arr2->getConstPointer()));
2069 for(int i=0;i<3;i++)
2071 int nbOfVals=expectedVals1[i];
2072 CPPUNIT_ASSERT_EQUAL(nbOfVals,(int)fidsOfGroups[i].size());
2073 CPPUNIT_ASSERT(std::equal(fidsOfGroups[i].begin(),fidsOfGroups[i].end(),fidsGrp[i]));
2075 for(std::vector<DataArrayInt *>::iterator iter=corr.begin();iter!=corr.end();iter++)
2085 void MEDCouplingBasicsTest1::testFuseUMeshesOnSameCoords2()
2087 MEDCouplingUMesh *m2;
2088 MEDCouplingUMesh *m1=build3DExtrudedUMesh_1(m2);
2090 const int part1[5]={2,3,6,4,10};
2091 MEDCouplingUMesh *m3=(MEDCouplingUMesh *)m1->buildPartOfMySelf(part1,part1+5,true);
2092 const int part2[4]={5,6,4,7};
2093 MEDCouplingUMesh *m4=(MEDCouplingUMesh *)m1->buildPartOfMySelf(part2,part2+4,true);
2094 std::vector<const MEDCouplingUMesh *> meshes;
2095 meshes.push_back(m1);
2096 meshes.push_back(m3);
2097 meshes.push_back(m3);
2098 meshes.push_back(m4);
2099 std::vector<DataArrayInt *> corr;
2100 MEDCouplingUMesh *m5=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
2101 CPPUNIT_ASSERT_EQUAL(18,m5->getNumberOfCells());
2102 std::vector<DataArrayInt *>::iterator it=corr.begin();
2103 const int exp1[4]={18,5,5,4};
2104 const int exp2[4][18]={
2105 {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17},
2106 {2,3,6,4,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
2107 {2,3,6,4,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
2108 {5,6,4,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}
2111 for(;it!=corr.end();it++,i++)
2113 int sz=(*it)->getNumberOfTuples();
2114 CPPUNIT_ASSERT_EQUAL(exp1[i],sz);
2115 CPPUNIT_ASSERT(std::equal(exp2[i],exp2[i]+sz,(*it)->getConstPointer()));
2117 for(it=corr.begin();it!=corr.end();it++)
2125 void MEDCouplingBasicsTest1::testBuildOrthogonalField()
2127 MEDCouplingUMesh *targetMesh=build3DSurfTargetMesh_1();
2128 MEDCouplingFieldDouble *field=targetMesh->buildOrthogonalField();
2129 double expected[3]={0.70710678118654746,0.,-0.70710678118654746};
2130 CPPUNIT_ASSERT_EQUAL(5,field->getNumberOfTuples());
2131 CPPUNIT_ASSERT_EQUAL(3,field->getNumberOfComponents());
2132 const double *vals=field->getArray()->getConstPointer();
2133 for(int i=0;i<15;i++)
2134 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected[i%3],vals[i],1e-12);
2136 targetMesh->decrRef();
2138 double targetCoords[12]={0.,0.,0.,0.5,0.,0.5,1.,0.,1.,0.,1.,0.};
2139 int targetConn[4]={0,1,2,3};
2140 targetMesh=MEDCouplingUMesh::New();
2141 targetMesh->setMeshDimension(2);
2142 targetMesh->allocateCells(1);
2143 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn);
2144 targetMesh->finishInsertingCells();
2145 DataArrayDouble *myCoords=DataArrayDouble::New();
2146 myCoords->alloc(4,3);
2147 std::copy(targetCoords,targetCoords+12,myCoords->getPointer());
2148 targetMesh->setCoords(myCoords);
2149 myCoords->decrRef();
2150 field=targetMesh->buildOrthogonalField();
2151 CPPUNIT_ASSERT_EQUAL(1,field->getNumberOfTuples());
2152 CPPUNIT_ASSERT_EQUAL(3,field->getNumberOfComponents());
2153 vals=field->getArray()->getConstPointer();
2154 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.70710678118654746,vals[0],1e-12);
2155 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,vals[1],1e-12);
2156 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.70710678118654746,vals[2],1e-12);
2158 targetMesh->decrRef();
2161 void MEDCouplingBasicsTest1::testGetCellsContainingPoint()
2163 MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
2164 double pos[12]={0.,0.,0.4,0.4,0.,0.4,0.1,0.1,0.25,0.,0.65,0.};
2165 std::vector<int> t1,t2;
2167 targetMesh->getCellsContainingPoints(pos,6,1e-12,t1,t2);
2168 CPPUNIT_ASSERT_EQUAL(6,(int)t1.size());
2169 CPPUNIT_ASSERT_EQUAL(7,(int)t2.size());
2170 const int expectedValues1[6]={0,4,3,0,1,2};
2171 const int expectedValues2[7]={0,1,2,3,4,5,6};
2172 CPPUNIT_ASSERT(std::equal(t1.begin(),t1.end(),expectedValues1));
2173 CPPUNIT_ASSERT(std::equal(t2.begin(),t2.end(),expectedValues2));
2174 //2D with no help of bounding box.
2175 double center[2]={0.2,0.2};
2176 MEDCouplingPointSet::Rotate2DAlg(center,0.78539816339744830962,6,pos);
2177 targetMesh->rotate(center,0,0.78539816339744830962);
2178 t1.clear(); t2.clear();
2179 targetMesh->getCellsContainingPoints(pos,6,1e-12,t1,t2);
2180 CPPUNIT_ASSERT_EQUAL(6,(int)t1.size());
2181 CPPUNIT_ASSERT_EQUAL(7,(int)t2.size());
2182 CPPUNIT_ASSERT(std::equal(t1.begin(),t1.end(),expectedValues1));
2183 CPPUNIT_ASSERT(std::equal(t2.begin(),t2.end(),expectedValues2));
2185 const double pos1bis[2]={-0.3303300858899107,-0.11819805153394641};
2186 CPPUNIT_ASSERT_EQUAL(-1,targetMesh->getCellContainingPoint(pos1bis,1e-12));
2187 targetMesh->decrRef();
2189 targetMesh=build2DTargetMesh_1();
2190 const double pos2[2]={0.2,-0.05};
2192 targetMesh->getCellsContainingPoint(pos2,1e-12,t1);
2193 CPPUNIT_ASSERT_EQUAL(2,(int)t1.size());
2194 const int expectedValues3[2]={0,1};
2195 CPPUNIT_ASSERT(std::equal(t1.begin(),t1.end(),expectedValues3));
2196 const double pos3[2]={0.2,0.2};
2198 targetMesh->getCellsContainingPoint(pos3,1e-12,t1);
2199 CPPUNIT_ASSERT_EQUAL(5,(int)t1.size());
2200 const int expectedValues4[5]={0,1,2,3,4};
2201 CPPUNIT_ASSERT(std::equal(t1.begin(),t1.end(),expectedValues4));
2202 CPPUNIT_ASSERT_EQUAL(0,targetMesh->getCellContainingPoint(pos3,1e-12));
2203 targetMesh->decrRef();
2205 targetMesh=build3DTargetMesh_1();
2206 const double pos4[3]={25.,25.,25.};
2207 CPPUNIT_ASSERT_EQUAL(0,targetMesh->getCellContainingPoint(pos4,1e-12));
2208 const double pos5[3]={50.,50.,50.};
2210 targetMesh->getCellsContainingPoint(pos5,1e-12,t1);
2211 CPPUNIT_ASSERT_EQUAL(8,(int)t1.size());
2212 const int expectedValues5[8]={0,1,2,3,4,5,6,7};
2213 CPPUNIT_ASSERT(std::equal(t1.begin(),t1.end(),expectedValues5));
2214 const double pos6[3]={0., 50., 0.};
2216 targetMesh->getCellsContainingPoint(pos6,1e-12,t1);
2217 CPPUNIT_ASSERT_EQUAL(2,(int)t1.size());
2218 const int expectedValues6[2]={0,2};
2219 CPPUNIT_ASSERT(std::equal(t1.begin(),t1.end(),expectedValues6));
2221 const double pos7[3]={-1.0,-1.0,0.};
2222 CPPUNIT_ASSERT_EQUAL(-1,targetMesh->getCellContainingPoint(pos7,1e-12));
2224 const double center2[3]={0.,0.,0.};
2225 const double vec2[3]={0.,-1.,0.};
2226 targetMesh->rotate(center2,vec2,0.78539816339744830962);
2227 const double pos8[3]={-25,25.,12.};
2228 CPPUNIT_ASSERT_EQUAL(-1,targetMesh->getCellContainingPoint(pos8,1e-12));
2230 targetMesh->decrRef();
2233 void MEDCouplingBasicsTest1::testGetValueOn1()
2235 MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
2236 MEDCouplingFieldDouble *fieldOnCells=MEDCouplingFieldDouble::New(ON_CELLS);
2237 int nbOfCells=targetMesh->getNumberOfCells();
2238 fieldOnCells->setMesh(targetMesh);
2239 DataArrayDouble *array=DataArrayDouble::New();
2240 array->alloc(nbOfCells,2);
2241 fieldOnCells->setArray(array);
2242 double *tmp=array->getPointer();
2243 for(int i=0;i<nbOfCells;i++)
2244 { tmp[2*i]=7.+(double)i; tmp[2*i+1]=17.+(double)i; }
2247 const double pos1[2]={0.25,0.};
2249 fieldOnCells->getValueOn(pos1,res);
2250 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.,res[0],1e-12);
2251 CPPUNIT_ASSERT_DOUBLES_EQUAL(18.,res[1],1e-12);
2253 fieldOnCells->decrRef();
2254 targetMesh->decrRef();
2256 targetMesh=build2DSourceMesh_1();
2257 MEDCouplingFieldDouble *fieldOnNodes=MEDCouplingFieldDouble::New(ON_NODES);
2258 int nbOfNodes=targetMesh->getNumberOfNodes();
2259 fieldOnNodes->setMesh(targetMesh);
2260 array=DataArrayDouble::New();
2261 array->alloc(nbOfNodes,2);
2262 fieldOnNodes->setArray(array);
2263 tmp=array->getPointer();
2264 for(int i=0;i<nbOfNodes;i++)
2265 { tmp[2*i]=17.+(double)i; tmp[2*i+1]=27.+(double)i; }
2268 const double pos2[2]={-0.13333333333333333,-0.13333333333333333};
2269 fieldOnNodes->getValueOn(pos2,res);
2270 CPPUNIT_ASSERT_DOUBLES_EQUAL(17.5,res[0],1e-12);
2271 CPPUNIT_ASSERT_DOUBLES_EQUAL(27.5,res[1],1e-12);
2272 const double pos3[2]={0.033333333333333326,0.36666666666666664};
2273 fieldOnNodes->getValueOn(pos3,res);
2274 CPPUNIT_ASSERT_DOUBLES_EQUAL(18.666666666666667,res[0],1e-12);
2275 CPPUNIT_ASSERT_DOUBLES_EQUAL(28.666666666666667,res[1],1e-12);
2277 fieldOnNodes->decrRef();
2278 targetMesh->decrRef();
2281 void MEDCouplingBasicsTest1::testCMesh0()
2283 MEDCouplingCMesh* mesh=MEDCouplingCMesh::New();
2284 MEDCouplingCMesh* meshEmpty=mesh->clone(true);
2285 CPPUNIT_ASSERT(meshEmpty->isEqual(mesh,1e-12));
2287 DataArrayDouble* coordsX=DataArrayDouble::New();
2288 double arrX[4] = { -1., 1., 2., 4. };
2289 coordsX->useArray(arrX,false, CPP_DEALLOC,4,1);
2290 DataArrayDouble* coordsY=DataArrayDouble::New();
2291 double arrY[4] = { -2., 2., 4., 8. };
2292 coordsY->useArray(arrY,false, CPP_DEALLOC,4,1);
2293 DataArrayDouble* coordsZ=DataArrayDouble::New();
2294 double arrZ[4] = { -3., 3., 6., 12. };
2295 coordsZ->useArray(arrZ,false, CPP_DEALLOC,4,1);
2296 mesh->setCoords(coordsX,coordsY,coordsZ);
2301 MEDCouplingFieldDouble *fieldOnNodes=mesh->fillFromAnalytic(ON_NODES,1,"x+y/2.+z/3.");
2302 CPPUNIT_ASSERT_EQUAL(1,fieldOnNodes->getNumberOfComponents());
2303 CPPUNIT_ASSERT_EQUAL(64,fieldOnNodes->getNumberOfTuples());
2304 const double expected1[64]={-3., -1., 0., 2., -1., 1., 2., 4., 0., 2., 3., 5., 2., 4., 5., 7., -1., 1., 2.,
2305 4., 1., 3., 4., 6., 2., 4., 5., 7., 4., 6., 7., 9., 0., 2., 3., 5., 2., 4., 5.,
2306 7., 3., 5., 6., 8., 5., 7., 8., 10., 2., 4., 5.,
2307 7., 4., 6., 7., 9., 5., 7., 8., 10., 7., 9., 10., 12.};
2308 const double *val=fieldOnNodes->getArray()->getConstPointer();
2309 for(int i=0;i<64;i++)
2310 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1e-12);
2311 double res[1]; //size fieldOnNodes->getNumberOfComponents()
2312 fieldOnNodes->getValueOnPos(1,3,2,&res[0]);
2313 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,res[0],1e-12);
2314 fieldOnNodes->decrRef();
2316 MEDCouplingFieldDouble *fieldOnCells=mesh->fillFromAnalytic(ON_CELLS,1,"x+y/2.+z/3.");
2317 CPPUNIT_ASSERT_EQUAL(1,fieldOnCells->getNumberOfComponents());
2318 CPPUNIT_ASSERT_EQUAL(27,fieldOnCells->getNumberOfTuples());
2319 val=fieldOnCells->getArray()->getConstPointer();
2320 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,
2321 6, 4.5, 6, 7.5, 3, 4.5, 6, 4.5, 6, 7.5, 6, 7.5, 9};
2322 for(int i=0;i<27;i++)
2323 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1e-12);
2324 fieldOnCells->getValueOnPos(1,2,1,&res[0]);
2325 CPPUNIT_ASSERT_DOUBLES_EQUAL(6.,res[0],1e-12);
2326 fieldOnCells->decrRef();
2328 MEDCouplingMesh* meshDeepCopy=mesh->deepCpy();
2329 MEDCouplingCMesh* meshClone=mesh->clone(false);
2331 CPPUNIT_ASSERT_THROW(meshEmpty->copyTinyStringsFrom(0),INTERP_KERNEL::Exception);
2332 meshEmpty->copyTinyStringsFrom(mesh);
2333 //no data in meshEmpty, expected false
2334 CPPUNIT_ASSERT(!meshEmpty->isEqual(mesh,1e-12));
2336 CPPUNIT_ASSERT(meshDeepCopy->isEqual(mesh,1e-12));
2337 meshDeepCopy->copyTinyStringsFrom(mesh);
2338 CPPUNIT_ASSERT(meshDeepCopy->isEqual(mesh,1e-12));
2339 CPPUNIT_ASSERT(meshClone->isEqual(mesh,1e-12));
2341 CPPUNIT_ASSERT_EQUAL(CARTESIAN,mesh->getType());
2342 CPPUNIT_ASSERT_EQUAL(CARTESIAN,meshEmpty->getType());
2343 CPPUNIT_ASSERT_EQUAL(CARTESIAN,meshDeepCopy->getType());
2344 CPPUNIT_ASSERT_EQUAL(CARTESIAN,meshClone->getType());
2347 meshEmpty->decrRef();
2348 meshDeepCopy->decrRef();
2349 meshClone->decrRef();
2352 void MEDCouplingBasicsTest1::testCMesh1()
2354 MEDCouplingCMesh *mesh1,*mesh2,*mesh3;
2355 mesh1=MEDCouplingCMesh::New();
2356 DataArrayDouble* coordsX1=DataArrayDouble::New();
2357 double arrX1[4] = { -1., 1., 2., 4. };
2358 coordsX1->useArray(arrX1,false, CPP_DEALLOC,4,1);
2359 DataArrayDouble* coordsY1=DataArrayDouble::New();
2360 double arrY1[4] = { -2., 2., 4., 8. };
2361 coordsY1->useArray(arrY1,false, CPP_DEALLOC,4,1);
2362 DataArrayDouble* coordsZ1=DataArrayDouble::New();
2363 double arrZ1[4] = { -3., 3., 6., 12. };
2364 coordsZ1->useArray(arrZ1,false, CPP_DEALLOC,4,1);
2365 mesh1->setCoords(coordsX1,coordsY1,coordsZ1);
2367 mesh2=MEDCouplingCMesh::New();
2368 DataArrayDouble* coordsX2=DataArrayDouble::New();
2369 double arrX2[4] = { -1., 1., 2., 4. };
2370 coordsX2->useArray(arrX2,false, CPP_DEALLOC,4,1);
2371 DataArrayDouble* coordsY2=DataArrayDouble::New();
2372 double arrY2[4] = { -2., 2., 4., 8. };
2373 coordsY2->useArray(arrY2,false, CPP_DEALLOC,4,1);
2374 DataArrayDouble* coordsZ2=DataArrayDouble::New();
2375 double arrZ2[4] = { -3., 3., 6., 12.+1e-6 }; //here is not equal
2376 coordsZ2->useArray(arrZ2,false, CPP_DEALLOC,4,1);
2377 mesh2->setCoords(coordsX2,coordsY2,coordsZ2);
2379 mesh3=MEDCouplingCMesh::New();
2380 DataArrayDouble* coordsX3=DataArrayDouble::New();
2381 double arrX3[1] = { -1.};
2382 coordsX3->useArray(arrX3,false, CPP_DEALLOC,1,1);
2383 DataArrayDouble* coordsY3=DataArrayDouble::New();
2384 double arrY3[1] = { -2.};
2385 coordsY3->useArray(arrY3,false, CPP_DEALLOC,1,1);
2386 DataArrayDouble* coordsZ3=DataArrayDouble::New();
2387 double arrZ3[1] = { -3.};
2388 coordsZ3->useArray(arrZ3,false, CPP_DEALLOC,1,1);
2389 mesh3->setCoords(coordsX3,coordsY3,coordsZ3);
2391 CPPUNIT_ASSERT_EQUAL(3,mesh1->getSpaceDimension());
2392 CPPUNIT_ASSERT_EQUAL(3,mesh1->getMeshDimension());
2394 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
2395 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
2396 CPPUNIT_ASSERT(!mesh2->isEqualWithoutConsideringStr(mesh1,1e-12));
2397 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-5));
2398 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-7));
2400 CPPUNIT_ASSERT_THROW(mesh3->checkCoherency1(1e-12),INTERP_KERNEL::Exception);
2401 mesh1->checkCoherency2(1e-12);
2402 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh1->getTypeOfCell(1));
2404 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,*((mesh1->getAllGeoTypes()).begin()));
2405 CPPUNIT_ASSERT_EQUAL(27,mesh1->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2406 CPPUNIT_ASSERT_THROW(mesh1->getNumberOfCellsWithType(INTERP_KERNEL::NORM_QUAD4),INTERP_KERNEL::Exception);
2408 std::vector<double> coo;
2409 mesh1->getCoordinatesOfNode(0, coo);
2410 CPPUNIT_ASSERT_EQUAL(3,(int) coo.size());
2411 CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.,coo[0],1e-14);
2412 CPPUNIT_ASSERT_DOUBLES_EQUAL(-2.,coo[1],1e-14);
2413 CPPUNIT_ASSERT_DOUBLES_EQUAL(-3.,coo[2],1e-14);
2415 mesh1->getCoordinatesOfNode(63, coo);
2416 CPPUNIT_ASSERT_EQUAL(3,(int) coo.size());
2417 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.,coo[0],1e-14);
2418 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.,coo[1],1e-14);
2419 CPPUNIT_ASSERT_DOUBLES_EQUAL(12.,coo[2],1e-14);
2422 repr=mesh1->simpleRepr();
2423 repr=mesh1->advancedRepr();
2424 CPPUNIT_ASSERT(!(repr.find("Cartesian")==std::string::npos));
2425 CPPUNIT_ASSERT(!(repr.find("Number of components : 1")==std::string::npos));
2426 CPPUNIT_ASSERT(!(repr.find("Number of tuples : 4")==std::string::npos));
2427 CPPUNIT_ASSERT(!(repr.find("Z Array :")==std::string::npos));
2428 coordsX1->decrRef();
2429 coordsY1->decrRef();
2430 coordsZ1->decrRef();
2431 coordsX2->decrRef();
2432 coordsY2->decrRef();
2433 coordsZ2->decrRef();
2434 coordsX3->decrRef();
2435 coordsY3->decrRef();
2436 coordsZ3->decrRef();
2442 void MEDCouplingBasicsTest1::testCMesh2()
2444 MEDCouplingCMesh *mesh1;
2445 mesh1=MEDCouplingCMesh::New();
2446 DataArrayDouble* coordsX1=DataArrayDouble::New();
2447 double arrX1[4] = { -1., 1., 2., 4. };
2448 coordsX1->useArray(arrX1,false, CPP_DEALLOC,4,1);
2449 DataArrayDouble* coordsY1=DataArrayDouble::New();
2450 double arrY1[4] = { -2., 2., 4., 8. };
2451 coordsY1->useArray(arrY1,false, CPP_DEALLOC,4,1);
2452 DataArrayDouble* coordsZ1=DataArrayDouble::New();
2453 double arrZ1[4] = { -3., 3., 6., 12. };
2454 coordsZ1->useArray(arrZ1,false, CPP_DEALLOC,4,1);
2455 mesh1->setCoords(coordsX1,coordsY1,coordsZ1);
2457 std::vector<int> dis=mesh1->getDistributionOfTypes();
2458 CPPUNIT_ASSERT_EQUAL(3,(int) dis.size());
2459 CPPUNIT_ASSERT_EQUAL((int) INTERP_KERNEL::NORM_HEXA8,dis[0]);
2460 CPPUNIT_ASSERT_EQUAL(27,dis[1]);
2461 CPPUNIT_ASSERT_EQUAL(-1,dis[2]);
2463 std::vector<const DataArrayInt *> idsPerType;
2464 CPPUNIT_ASSERT(!(mesh1->checkTypeConsistencyAndContig(dis, idsPerType)));
2465 dis[0]=(int) INTERP_KERNEL::NORM_QUAD4;
2466 CPPUNIT_ASSERT_THROW(mesh1->checkTypeConsistencyAndContig(dis, idsPerType),INTERP_KERNEL::Exception);
2468 dis[0]=(int) INTERP_KERNEL::NORM_HEXA8;
2470 DataArrayInt *ids=DataArrayInt::New();
2472 ids->fillWithValue(23);
2473 idsPerType.push_back(ids);
2474 DataArrayInt* check=mesh1->checkTypeConsistencyAndContig(dis, idsPerType);
2475 CPPUNIT_ASSERT(check);
2476 CPPUNIT_ASSERT(check->isEqual(*ids));
2478 std::vector<int> code;
2479 std::vector<DataArrayInt *> idsInPflPerType;
2480 std::vector<DataArrayInt *> pfls;
2481 mesh1->splitProfilePerType(ids,code,idsInPflPerType,pfls);
2482 CPPUNIT_ASSERT_EQUAL(3,(int)code.size());
2483 CPPUNIT_ASSERT_EQUAL((int) INTERP_KERNEL::NORM_HEXA8,code[0]);
2484 CPPUNIT_ASSERT_EQUAL(27,code[1]);
2485 CPPUNIT_ASSERT_EQUAL(0,code[2]);
2486 CPPUNIT_ASSERT_EQUAL(1,(int)idsInPflPerType.size());
2487 CPPUNIT_ASSERT_EQUAL(1,(int)pfls.size());
2488 DataArrayInt *exp=DataArrayInt::New(); exp->alloc(10,1); exp->iota(0);
2489 CPPUNIT_ASSERT(idsInPflPerType[0]->isEqual(*exp));
2491 CPPUNIT_ASSERT(pfls[0]->isEqual(*ids));
2492 idsInPflPerType[0]->decrRef();
2497 int cells1[4]={0,1,25,26};
2498 MEDCouplingUMesh *partMesh1=
2499 dynamic_cast<MEDCouplingUMesh *>(mesh1->buildPart(cells1,cells1+4));
2500 CPPUNIT_ASSERT(partMesh1);
2501 CPPUNIT_ASSERT_EQUAL(4,partMesh1->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2502 CPPUNIT_ASSERT_EQUAL(64,mesh1->getNumberOfNodes());
2503 CPPUNIT_ASSERT_EQUAL(64,partMesh1->getNumberOfNodes());
2505 int cells2[2]={25,26};
2507 MEDCouplingCMesh *partMesh2=
2508 dynamic_cast<MEDCouplingCMesh *>(mesh1->buildPartAndReduceNodes(cells2,cells2+2,arr1));
2509 CPPUNIT_ASSERT(partMesh2);
2510 CPPUNIT_ASSERT_EQUAL(2,partMesh2->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2511 CPPUNIT_ASSERT_EQUAL(12,partMesh2->getNumberOfNodes());
2513 int cells3[2]={2,3};
2515 MEDCouplingUMesh *partMesh3=
2516 dynamic_cast<MEDCouplingUMesh *>(partMesh1->buildPartAndReduceNodes(cells3,cells3+2,arr2));
2517 CPPUNIT_ASSERT(partMesh3);
2518 CPPUNIT_ASSERT_EQUAL(2,partMesh3->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2519 CPPUNIT_ASSERT_EQUAL(12,partMesh3->getNumberOfNodes());
2521 CPPUNIT_ASSERT_THROW(mesh1->simplexize(0),INTERP_KERNEL::Exception);
2522 CPPUNIT_ASSERT_THROW(mesh1->getMeasureFieldOnNode(true),INTERP_KERNEL::Exception);
2526 mesh1->getBoundingBox(bbox1);
2527 partMesh1->getBoundingBox(bbox2);
2528 for(int i=0;i<6;i++)
2529 CPPUNIT_ASSERT_DOUBLES_EQUAL(bbox1[i],bbox2[i],1e-12);
2530 partMesh3->getBoundingBox(bbox1);
2531 partMesh2->getBoundingBox(bbox2);
2532 for(int i=0;i<6;i++)
2533 CPPUNIT_ASSERT_DOUBLES_EQUAL(bbox1[i],bbox2[i],1e-12);
2535 CPPUNIT_ASSERT_THROW(mesh1->buildOrthogonalField(),INTERP_KERNEL::Exception);
2536 MEDCouplingCMesh *mesh2d=MEDCouplingCMesh::New();
2537 mesh2d->setCoords(coordsX1,coordsY1);
2538 MEDCouplingFieldDouble *f1=mesh2d->buildOrthogonalField();
2540 std::vector<double> tinyInfoD;
2541 std::vector<int> tinyInfo;
2542 std::vector<std::string> littleStrings;
2543 mesh2d->getTinySerializationInformation(tinyInfoD, tinyInfo, littleStrings);
2544 CPPUNIT_ASSERT_EQUAL(5,(int)tinyInfo.size());
2545 CPPUNIT_ASSERT_EQUAL(4,(int)tinyInfo[0]); //x
2546 CPPUNIT_ASSERT_EQUAL(4,(int)tinyInfo[1]); //y
2547 CPPUNIT_ASSERT_EQUAL(-1,(int)tinyInfo[2]); //z
2548 CPPUNIT_ASSERT_EQUAL(-1,(int)tinyInfo[3]); //it
2549 CPPUNIT_ASSERT_EQUAL(-1,(int)tinyInfo[4]); //order
2550 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,tinyInfoD[0],1e-14); //time
2551 DataArrayInt* d1=DataArrayInt::New();
2552 DataArrayDouble* d2=DataArrayDouble::New();
2553 mesh2d->resizeForUnserialization(tinyInfo, d1, d2, littleStrings);
2554 CPPUNIT_ASSERT_EQUAL(0,d1->getNumberOfTuples());
2555 CPPUNIT_ASSERT_EQUAL(8,d2->getNumberOfTuples());
2557 partMesh1->decrRef();
2558 partMesh2->decrRef();
2559 partMesh3->decrRef();
2566 coordsX1->decrRef();
2567 coordsY1->decrRef();
2568 coordsZ1->decrRef();
2572 void MEDCouplingBasicsTest1::testScale()
2574 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
2575 const double pos[2]={0.2,0.2};
2576 mesh->scale(pos,0.5);
2577 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,
2578 -0.05,0.45, 0.2,0.45, 0.45,0.45};
2579 const double *val=mesh->getCoords()->getConstPointer();
2580 for(int i=0;i<18;i++)
2581 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1e-12);
2586 void MEDCouplingBasicsTest1::testTryToShareSameCoords()
2588 MEDCouplingUMesh *m1=build2DTargetMesh_1();
2589 MEDCouplingUMesh *m2=build2DTargetMesh_1();
2590 CPPUNIT_ASSERT(m1->getCoords()!=m2->getCoords());
2591 m1->tryToShareSameCoords(*m2,1e-12);
2592 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2593 m1->tryToShareSameCoords(*m2,1e-12);
2594 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2595 m2->tryToShareSameCoords(*m1,1e-12);
2596 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2600 m1=build2DTargetMesh_1();
2601 m2=build2DTargetMesh_2();
2602 CPPUNIT_ASSERT(m1->getCoords()!=m2->getCoords());
2603 m1->tryToShareSameCoords(*m2,1e-12);
2604 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2605 m1->tryToShareSameCoords(*m2,1e-12);
2606 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2607 m2->tryToShareSameCoords(*m1,1e-12);
2608 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2612 m1=build2DTargetMesh_1();
2613 m2=build2DSourceMesh_1();
2614 CPPUNIT_ASSERT(m1->getCoords()!=m2->getCoords());
2615 CPPUNIT_ASSERT_THROW(m1->tryToShareSameCoords(*m2,1e-12),INTERP_KERNEL::Exception);
2620 void MEDCouplingBasicsTest1::testFindNodeOnPlane()
2622 MEDCouplingUMesh *mesh=build3DTargetMesh_1();
2624 double pt[3]={300.,300.,0.};
2625 double v[3]={0.,0.,2.};
2626 mesh->findNodesOnPlane(pt,v,1e-12,n);
2627 CPPUNIT_ASSERT_EQUAL(9,(int)n.size());
2628 MEDCouplingUMesh *m3dSurf=(MEDCouplingUMesh *)mesh->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
2629 MEDCouplingExtrudedMesh *me=MEDCouplingExtrudedMesh::New(mesh,m3dSurf,0);
2630 const DataArrayInt *da=me->getMesh3DIds();
2631 CPPUNIT_ASSERT_EQUAL(8,me->getNumberOfCells());
2632 const int expected[8]={0,1,2,3,4,5,6,7};
2633 const int *val=da->getConstPointer();
2634 for(int i=0;i<8;i++)
2635 CPPUNIT_ASSERT_EQUAL(expected[i],val[i]);
2641 void MEDCouplingBasicsTest1::testRenumberCells()
2643 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
2644 MEDCouplingUMesh *m2=build3DSurfTargetMesh_1();
2645 CPPUNIT_ASSERT(m->isEqual(m2,0));
2646 const int arr[5]={12,3,25,2,26};
2647 m->renumberCells(arr,true);
2648 CPPUNIT_ASSERT(!m->isEqual(m2,0));
2649 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(0));
2650 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(1));
2651 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(2));
2652 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(3));
2653 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(4));
2654 const int arr2[5]={5,-1,-5,4,8};
2655 m->renumberCells(arr2,true);
2656 CPPUNIT_ASSERT(m->isEqual(m2,0));
2661 void MEDCouplingBasicsTest1::testChangeSpaceDimension()
2663 MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
2664 MEDCouplingUMesh *m2=build2DTargetMesh_1();
2666 CPPUNIT_ASSERT_EQUAL(3,m1->getSpaceDimension());
2667 m1->changeSpaceDimension(2);
2668 CPPUNIT_ASSERT_EQUAL(2,m1->getSpaceDimension());
2669 m1->setName(m2->getName().c_str());
2670 CPPUNIT_ASSERT(m1->isEqual(m2,1e-12));
2671 m1->changeSpaceDimension(3);
2672 CPPUNIT_ASSERT_EQUAL(3,m1->getSpaceDimension());
2673 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.};
2674 const double *val=m1->getCoords()->getConstPointer();
2675 for(int i=0;i<27;i++)
2676 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected[i],val[i],1e-14);
2682 void MEDCouplingBasicsTest1::testSetConnectivity()
2684 MEDCouplingUMesh *m1 = build1DTargetMesh_1();
2686 DataArrayInt * conn = DataArrayInt::New();
2687 DataArrayInt * connI = DataArrayInt::New();
2688 m1->setConnectivity(conn, connI, true); // was SEG-Faulting with empty arrays