1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "MEDCouplingBasicsTest1.hxx"
22 #include "MEDCouplingUMesh.hxx"
23 #include "MEDCouplingCMesh.hxx"
24 #include "MEDCouplingMappedExtrudedMesh.hxx"
25 #include "MEDCouplingFieldDouble.hxx"
31 using namespace MEDCoupling;
33 void MEDCouplingBasicsTest1::testArray()
35 int tmp1[6]={7,6,5,4,3,2};
36 const int tmp2[3]={8,9,10};
39 mem.useArray(tmp1,false,DeallocType::CPP_DEALLOC,6);
40 CPPUNIT_ASSERT(tmp1==mem.getConstPointer());
41 CPPUNIT_ASSERT_THROW(mem.getPointer(),INTERP_KERNEL::Exception);
42 CPPUNIT_ASSERT_THROW(mem[2]=7,INTERP_KERNEL::Exception);
43 CPPUNIT_ASSERT_THROW(mem.writeOnPlace(0,12,tmp2,3),INTERP_KERNEL::Exception);
44 mem.writeOnPlace(4,12,tmp2,3);
48 std::copy(tmp1,tmp1+6,tmp3);
50 mem2.useArray(tmp3,true,DeallocType::CPP_DEALLOC,6);
51 CPPUNIT_ASSERT(tmp3==mem2.getConstPointer());
52 CPPUNIT_ASSERT(tmp3==mem2.getPointer());
53 CPPUNIT_ASSERT_EQUAL(5,mem2[2]);
55 CPPUNIT_ASSERT_EQUAL(7,mem2[2]);
56 mem2.writeOnPlace(0,12,tmp2,3);
57 CPPUNIT_ASSERT_EQUAL(9,mem2[2]);
58 CPPUNIT_ASSERT_EQUAL(12,mem2[0]);
59 mem2.writeOnPlace(4,12,tmp2,3);
63 void MEDCouplingBasicsTest1::testArray2()
65 DataArrayDouble *arr=DataArrayDouble::New();
67 double *tmp=arr->getPointer();
68 const double arrRef[12]={12.,11.,10.,9.,8.,7.,6.,5.,4.,3.,2.,1.};
69 std::copy(arrRef,arrRef+12,tmp);
70 arr->setInfoOnComponent(0,"ggg");
71 arr->setInfoOnComponent(1,"hhhh");
72 arr->setInfoOnComponent(2,"jj");
73 arr->setInfoOnComponent(3,"kkkkkk");
74 MCAuto<DataArrayInt> arr2(arr->convertToIntArr());
75 MCAuto<DataArrayDouble> arr3(arr2->convertToDblArr());
76 CPPUNIT_ASSERT(arr->isEqual(*arr3,1e-14));
80 void MEDCouplingBasicsTest1::testArray3()
82 DataArrayInt *arr1=DataArrayInt::New();
84 int *tmp=arr1->getPointer();
85 const int arr1Ref[14]={0,10,1,11,2,12,3,13,4,14,5,15,6,16};
86 std::copy(arr1Ref,arr1Ref+14,tmp);
87 CPPUNIT_ASSERT_EQUAL(7,(int)arr1->getNumberOfTuples());
88 CPPUNIT_ASSERT_EQUAL(2,(int)arr1->getNumberOfComponents());
89 CPPUNIT_ASSERT(std::equal(arr1Ref,arr1Ref+14,arr1->getConstPointer()));
90 DataArrayInt *arr2=arr1->subArray(3);
91 CPPUNIT_ASSERT_EQUAL(4,(int)arr2->getNumberOfTuples());
92 CPPUNIT_ASSERT_EQUAL(2,(int)arr2->getNumberOfComponents());
93 CPPUNIT_ASSERT(std::equal(arr1Ref+6,arr1Ref+14,arr2->getConstPointer()));
95 DataArrayInt *arr3=arr1->subArray(2,5);
96 CPPUNIT_ASSERT_EQUAL(3,(int)arr3->getNumberOfTuples());
97 CPPUNIT_ASSERT_EQUAL(2,(int)arr3->getNumberOfComponents());
98 CPPUNIT_ASSERT(std::equal(arr1Ref+4,arr1Ref+10,arr3->getConstPointer()));
102 DataArrayDouble *arr4=DataArrayDouble::New();
104 double *tmp2=arr4->getPointer();
105 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};
106 std::copy(arr4Ref,arr4Ref+14,tmp2);
107 CPPUNIT_ASSERT_EQUAL(7,(int)arr4->getNumberOfTuples());
108 CPPUNIT_ASSERT_EQUAL(2,(int)arr4->getNumberOfComponents());
109 CPPUNIT_ASSERT(std::equal(arr4Ref,arr4Ref+14,arr4->getConstPointer()));
110 DataArrayDouble *arr5=arr4->subArray(3);
111 CPPUNIT_ASSERT_EQUAL(4,(int)arr5->getNumberOfTuples());
112 CPPUNIT_ASSERT_EQUAL(2,(int)arr5->getNumberOfComponents());
113 CPPUNIT_ASSERT(std::equal(arr4Ref+6,arr4Ref+14,arr5->getConstPointer()));
115 DataArrayDouble *arr6=arr4->subArray(2,5);
116 CPPUNIT_ASSERT_EQUAL(3,(int)arr6->getNumberOfTuples());
117 CPPUNIT_ASSERT_EQUAL(2,(int)arr6->getNumberOfComponents());
118 CPPUNIT_ASSERT(std::equal(arr4Ref+4,arr4Ref+10,arr6->getConstPointer()));
123 void MEDCouplingBasicsTest1::testMesh()
125 const int nbOfCells=6;
126 const int nbOfNodes=12;
128 double coords[3*nbOfNodes]={
129 0.024155, 0.04183768725682622, -0.305, 0.04831000000000001, -1.015761910347357e-17, -0.305, 0.09662000000000001, -1.832979297858306e-18,
130 -0.305, 0.120775, 0.04183768725682623, -0.305, 0.09662000000000001, 0.08367537451365245, -0.305, 0.04831000000000001,
131 0.08367537451365246, -0.305, 0.024155, 0.04183768725682622, -0.2863, 0.04831000000000001, -1.015761910347357e-17, -0.2863,
132 0.09662000000000001, -1.832979297858306e-18, -0.2863, 0.120775, 0.04183768725682623, -0.2863, 0.09662000000000001, 0.08367537451365245,
133 -0.2863, 0.04831000000000001, 0.08367537451365246, -0.2863, };
135 int tab4[4*nbOfCells]={
136 1, 2, 8, 7, 2, 3, 9, 8, 3, 4, 10, 9, 4, 5, 11, 10, 5, 0, 6, 11,
138 CPPUNIT_ASSERT_EQUAL(MEDCouplingMesh::GetNumberOfNodesOfGeometricType(INTERP_KERNEL::NORM_TRI3),3);
139 CPPUNIT_ASSERT(MEDCouplingMesh::IsStaticGeometricType(INTERP_KERNEL::NORM_TRI3));
140 CPPUNIT_ASSERT(MEDCouplingMesh::IsLinearGeometricType(INTERP_KERNEL::NORM_TRI3));
141 CPPUNIT_ASSERT_EQUAL(MEDCouplingMesh::GetDimensionOfGeometricType(INTERP_KERNEL::NORM_TRI3),2);
142 CPPUNIT_ASSERT_EQUAL(std::string(MEDCouplingMesh::GetReprOfGeometricType(INTERP_KERNEL::NORM_TRI3)),std::string("NORM_TRI3"));
143 CPPUNIT_ASSERT_THROW(MEDCouplingMesh::GetNumberOfNodesOfGeometricType(INTERP_KERNEL::NORM_POLYGON),INTERP_KERNEL::Exception);
144 CPPUNIT_ASSERT(!MEDCouplingMesh::IsStaticGeometricType(INTERP_KERNEL::NORM_POLYGON));
145 CPPUNIT_ASSERT(MEDCouplingMesh::IsLinearGeometricType(INTERP_KERNEL::NORM_POLYGON));
146 CPPUNIT_ASSERT_EQUAL(MEDCouplingMesh::GetDimensionOfGeometricType(INTERP_KERNEL::NORM_POLYGON),2);
147 CPPUNIT_ASSERT_EQUAL(std::string(MEDCouplingMesh::GetReprOfGeometricType(INTERP_KERNEL::NORM_POLYGON)),std::string("NORM_POLYGON"));
148 CPPUNIT_ASSERT_EQUAL(MEDCouplingMesh::GetNumberOfNodesOfGeometricType(INTERP_KERNEL::NORM_TRI6),6);
149 CPPUNIT_ASSERT(MEDCouplingMesh::IsStaticGeometricType(INTERP_KERNEL::NORM_TRI6));
150 CPPUNIT_ASSERT(!MEDCouplingMesh::IsLinearGeometricType(INTERP_KERNEL::NORM_TRI6));
151 CPPUNIT_ASSERT_EQUAL(MEDCouplingMesh::GetDimensionOfGeometricType(INTERP_KERNEL::NORM_TRI6),2);
152 CPPUNIT_ASSERT_EQUAL(std::string(MEDCouplingMesh::GetReprOfGeometricType(INTERP_KERNEL::NORM_TRI6)),std::string("NORM_TRI6"));
153 MEDCouplingUMesh *mesh=MEDCouplingUMesh::New();
154 mesh->setMeshDimension(2);
155 mesh->allocateCells(8);
156 const int *curConn=tab4;
157 for(int i=0;i<nbOfCells;i++,curConn+=4)
158 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,curConn);
159 mesh->finishInsertingCells();
160 CPPUNIT_ASSERT_EQUAL((std::size_t)30,mesh->getNodalConnectivity()->getNbOfElems());
161 CPPUNIT_ASSERT_EQUAL(nbOfCells,(int)mesh->getNumberOfCells());
162 //test 0 - no copy no ownership
163 DataArrayDouble *myCoords=DataArrayDouble::New();
164 myCoords->useArray(coords,false,DeallocType::CPP_DEALLOC,nbOfNodes,3);
165 mesh->setCoords(myCoords);
166 mesh->setCoords(myCoords);
168 CPPUNIT_ASSERT_EQUAL(nbOfCells,(int)mesh->getNumberOfCells());
169 mesh->checkConsistencyLight();
170 //test 1 - no copy ownership C++
171 myCoords=DataArrayDouble::New();
172 double *tmp=new double[3*nbOfNodes];
173 std::copy(coords,coords+3*nbOfNodes,tmp);
174 myCoords->useArray(tmp,true,DeallocType::CPP_DEALLOC,nbOfNodes,3);
175 mesh->setCoords(myCoords);
177 CPPUNIT_ASSERT_EQUAL(nbOfCells,(int)mesh->getNumberOfCells());
178 mesh->checkConsistencyLight();
179 //test 2 - no copy ownership C
180 myCoords=DataArrayDouble::New();
181 tmp=(double *)malloc(3*nbOfNodes*sizeof(double));
182 std::copy(coords,coords+3*nbOfNodes,tmp);
183 myCoords->useArray(tmp,true,DeallocType::C_DEALLOC,nbOfNodes,3);
184 mesh->setCoords(myCoords);
186 CPPUNIT_ASSERT_EQUAL(nbOfNodes,mesh->getNumberOfNodes());
187 mesh->checkConsistencyLight();
189 myCoords=DataArrayDouble::New();
190 myCoords->alloc(nbOfNodes,3);
191 tmp=myCoords->getPointer();
192 std::copy(coords,coords+3*nbOfNodes,tmp);
193 // test 3 bis deepcopy
194 DataArrayDouble *myCoords2=DataArrayDouble::New();
195 *myCoords2=*myCoords;
196 myCoords2->decrRef();
198 mesh->setCoords(myCoords);
200 CPPUNIT_ASSERT_EQUAL(nbOfNodes,mesh->getNumberOfNodes());
201 mesh->checkConsistencyLight();
202 CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
203 // test clone not recursively
204 MEDCouplingUMesh *mesh2=mesh->clone(false);
205 CPPUNIT_ASSERT(mesh2!=mesh);
206 mesh2->checkConsistencyLight();
207 CPPUNIT_ASSERT_EQUAL(nbOfCells,(int)mesh2->getNumberOfCells());
208 CPPUNIT_ASSERT_EQUAL(nbOfNodes,mesh2->getNumberOfNodes());
209 CPPUNIT_ASSERT_EQUAL(3,mesh2->getSpaceDimension());
210 CPPUNIT_ASSERT(mesh!=mesh2);
211 CPPUNIT_ASSERT(mesh->getCoords()==mesh2->getCoords());
212 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.2863,mesh2->getCoords()->getIJ(11,2),1e-14);
213 CPPUNIT_ASSERT(mesh->getNodalConnectivity()==mesh2->getNodalConnectivity());
214 CPPUNIT_ASSERT_EQUAL(3,mesh2->getNodalConnectivity()->getIJ(7,0));
215 CPPUNIT_ASSERT(mesh->getNodalConnectivityIndex()==mesh2->getNodalConnectivityIndex());
216 CPPUNIT_ASSERT_EQUAL(15,mesh2->getNodalConnectivityIndex()->getIJ(3,0));
218 // test clone not recursively
219 MEDCouplingUMesh *mesh3=mesh->clone(true);
220 CPPUNIT_ASSERT(mesh3!=mesh);
221 mesh3->checkConsistencyLight();
222 CPPUNIT_ASSERT_EQUAL(nbOfCells,(int)mesh3->getNumberOfCells());
223 CPPUNIT_ASSERT_EQUAL(nbOfNodes,mesh3->getNumberOfNodes());
224 CPPUNIT_ASSERT_EQUAL(3,mesh3->getSpaceDimension());
225 CPPUNIT_ASSERT(mesh!=mesh3);
226 CPPUNIT_ASSERT(mesh->getCoords()!=mesh3->getCoords());
227 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.2863,mesh3->getCoords()->getIJ(11,2),1e-14);
228 CPPUNIT_ASSERT(mesh->getNodalConnectivity()!=mesh3->getNodalConnectivity());
229 CPPUNIT_ASSERT_EQUAL(3,mesh3->getNodalConnectivity()->getIJ(7,0));
230 CPPUNIT_ASSERT(mesh->getNodalConnectivityIndex()!=mesh3->getNodalConnectivityIndex());
231 CPPUNIT_ASSERT_EQUAL(15,mesh3->getNodalConnectivityIndex()->getIJ(3,0));
233 //test 4 - Field on cells
234 MEDCouplingFieldDouble *fieldOnCells=MEDCouplingFieldDouble::New(ON_CELLS);
235 fieldOnCells->setMesh(mesh);
236 DataArrayDouble *array=DataArrayDouble::New();
237 array->alloc(nbOfCells,9);
238 fieldOnCells->setArray(array);
239 tmp=array->getPointer();
241 std::fill(tmp,tmp+9*nbOfCells,7.);
242 //content of field changed -> declare it.
243 fieldOnCells->declareAsNew();
244 fieldOnCells->checkConsistencyLight();
245 // testing clone of fields - no recursive
246 MEDCouplingFieldDouble *fieldOnCells2=fieldOnCells->clone(false);
247 CPPUNIT_ASSERT(fieldOnCells2!=fieldOnCells);
248 fieldOnCells2->checkConsistencyLight();
249 CPPUNIT_ASSERT_EQUAL(nbOfCells,(int)fieldOnCells2->getNumberOfTuples());
250 CPPUNIT_ASSERT_EQUAL(9,(int)fieldOnCells2->getNumberOfComponents());
251 CPPUNIT_ASSERT(fieldOnCells2->getArray()==fieldOnCells->getArray());
252 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,fieldOnCells2->getArray()->getIJ(3,7),1e-14);
253 CPPUNIT_ASSERT(fieldOnCells2->getMesh()==fieldOnCells->getMesh());
254 // testing clone of fields - recursive
255 MEDCouplingFieldDouble *fieldOnCells3=fieldOnCells->clone(true);
256 CPPUNIT_ASSERT(fieldOnCells3!=fieldOnCells);
257 fieldOnCells3->checkConsistencyLight();
258 CPPUNIT_ASSERT_EQUAL(nbOfCells,(int)fieldOnCells3->getNumberOfTuples());
259 CPPUNIT_ASSERT_EQUAL(9,(int)fieldOnCells3->getNumberOfComponents());
260 CPPUNIT_ASSERT(fieldOnCells3->getArray()!=fieldOnCells->getArray());
261 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,fieldOnCells3->getArray()->getIJ(3,7),1e-14);
262 CPPUNIT_ASSERT(fieldOnCells3->getMesh()==fieldOnCells->getMesh());
263 fieldOnCells2->decrRef();
264 fieldOnCells3->decrRef();
266 fieldOnCells->decrRef();
271 void MEDCouplingBasicsTest1::testMeshPointsCloud()
273 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};
274 const int targetConn[]={0,1,2,3,4,5,7,6};
275 MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
276 targetMesh->setMeshDimension(0);
277 targetMesh->allocateCells(8);
278 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn);
279 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+1);
280 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+2);
281 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+3);
282 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+4);
283 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+5);
284 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+6);
285 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+7);
286 targetMesh->finishInsertingCells();
287 CPPUNIT_ASSERT_THROW(targetMesh->checkConsistencyLight(),INTERP_KERNEL::Exception);
288 DataArrayDouble *myCoords=DataArrayDouble::New();
289 myCoords->alloc(9,3);
290 std::copy(targetCoords,targetCoords+27,myCoords->getPointer());
291 targetMesh->setCoords(myCoords);
294 targetMesh->checkConsistencyLight();
295 CPPUNIT_ASSERT_EQUAL(3,targetMesh->getSpaceDimension());
296 CPPUNIT_ASSERT_EQUAL(8,(int)targetMesh->getNumberOfCells());
297 CPPUNIT_ASSERT_EQUAL(9,targetMesh->getNumberOfNodes());
298 CPPUNIT_ASSERT_EQUAL(0,targetMesh->getMeshDimension());
300 targetMesh->decrRef();
303 void MEDCouplingBasicsTest1::testMeshM1D()
305 MEDCouplingUMesh *meshM1D=MEDCouplingUMesh::New();
306 CPPUNIT_ASSERT_THROW(meshM1D->getMeshDimension(),INTERP_KERNEL::Exception);
307 CPPUNIT_ASSERT_THROW(meshM1D->getNumberOfNodes(),INTERP_KERNEL::Exception);
308 CPPUNIT_ASSERT_THROW(meshM1D->getNumberOfCells(),INTERP_KERNEL::Exception);
309 CPPUNIT_ASSERT_THROW(meshM1D->setMeshDimension(-2),INTERP_KERNEL::Exception);
310 CPPUNIT_ASSERT_THROW(meshM1D->setMeshDimension(-10),INTERP_KERNEL::Exception);
311 CPPUNIT_ASSERT_THROW(meshM1D->checkConsistencyLight(),INTERP_KERNEL::Exception);
312 meshM1D->setMeshDimension(-1);
313 meshM1D->checkConsistencyLight();
314 CPPUNIT_ASSERT_EQUAL(-1,meshM1D->getMeshDimension());
315 CPPUNIT_ASSERT_EQUAL(1,(int)meshM1D->getNumberOfCells());
316 CPPUNIT_ASSERT_THROW(meshM1D->getNumberOfNodes(),INTERP_KERNEL::Exception);
317 CPPUNIT_ASSERT_THROW(meshM1D->getSpaceDimension(),INTERP_KERNEL::Exception);
318 MEDCouplingUMesh *cpy=meshM1D->clone(true);
319 CPPUNIT_ASSERT(cpy->isEqual(meshM1D,1e-12));
321 MEDCouplingFieldDouble *fieldOnCells=MEDCouplingFieldDouble::New(ON_CELLS);
322 fieldOnCells->setMesh(meshM1D);
323 DataArrayDouble *array=DataArrayDouble::New();
325 fieldOnCells->setArray(array);
326 double *tmp=array->getPointer();
328 std::fill(tmp,tmp+6,7.);
329 fieldOnCells->checkConsistencyLight();
331 fieldOnCells->decrRef();
335 void MEDCouplingBasicsTest1::testDeepCopy()
337 DataArrayDouble *array=DataArrayDouble::New();
339 std::fill(array->getPointer(),array->getPointer()+5*3,7.);
340 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,array->getIJ(3,2),1e-14);
341 double *tmp1=array->getPointer();
342 DataArrayDouble *array2=array->deepCopy();
343 double *tmp2=array2->getPointer();
344 CPPUNIT_ASSERT(tmp1!=tmp2);
346 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,array2->getIJ(3,2),1e-14);
349 DataArrayInt *array3=DataArrayInt::New();
351 std::fill(array3->getPointer(),array3->getPointer()+5*3,17);
352 CPPUNIT_ASSERT_EQUAL(17,array3->getIJ(3,2));
353 int *tmp3=array3->getPointer();
354 DataArrayInt *array4=array3->deepCopy();
355 int *tmp4=array4->getPointer();
356 CPPUNIT_ASSERT(tmp3!=tmp4);
358 CPPUNIT_ASSERT_EQUAL(17,array4->getIJ(3,2));
362 void MEDCouplingBasicsTest1::testRevNodal()
364 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
365 DataArrayInt *revNodal=DataArrayInt::New();
366 DataArrayInt *revNodalIndx=DataArrayInt::New();
368 mesh->getReverseNodalConnectivity(revNodal,revNodalIndx);
369 const int revNodalExpected[18]={0,0,1,1,2,0,3,0,1,2,3,4,2,4,3,3,4,4};
370 const int revNodalIndexExpected[10]={0,1,3,5,7,12,14,15,17,18};
371 CPPUNIT_ASSERT_EQUAL((std::size_t)18,revNodal->getNbOfElems());
372 CPPUNIT_ASSERT_EQUAL((std::size_t)10,revNodalIndx->getNbOfElems());
373 CPPUNIT_ASSERT(std::equal(revNodalExpected,revNodalExpected+18,revNodal->getPointer()));
374 CPPUNIT_ASSERT(std::equal(revNodalIndexExpected,revNodalIndexExpected+10,revNodalIndx->getPointer()));
377 revNodalIndx->decrRef();
381 void MEDCouplingBasicsTest1::testConvertToPolyTypes()
384 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
386 const int elts[2]={1,3};
387 std::vector<int> eltsV(elts,elts+2);
388 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
389 mesh->checkConsistencyLight();
390 CPPUNIT_ASSERT_EQUAL(5,(int)mesh->getNumberOfCells());
391 CPPUNIT_ASSERT_EQUAL(23,(int)mesh->getNodalConnectivity()->getNumberOfTuples());
392 const int *pt=mesh->getNodalConnectivity()->getConstPointer();
393 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};
394 CPPUNIT_ASSERT(std::equal(expected1,expected1+23,pt));
398 mesh=build3DTargetMesh_1();
399 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
400 mesh->checkConsistencyLight();
401 CPPUNIT_ASSERT_EQUAL(8,(int)mesh->getNumberOfCells());
402 CPPUNIT_ASSERT_EQUAL(114,(int)mesh->getNodalConnectivity()->getNumberOfTuples());
403 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
404 mesh->checkConsistencyLight();
405 CPPUNIT_ASSERT_EQUAL(8,(int)mesh->getNumberOfCells());
406 CPPUNIT_ASSERT_EQUAL(114,(int)mesh->getNodalConnectivity()->getNumberOfTuples());
411 void MEDCouplingBasicsTest1::testDescConn2D()
413 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
414 DataArrayInt *desc=DataArrayInt::New();
415 DataArrayInt *descIndx=DataArrayInt::New();
416 DataArrayInt *revDesc=DataArrayInt::New();
417 DataArrayInt *revDescIndx=DataArrayInt::New();
419 MEDCouplingUMesh *mesh2=mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
420 mesh2->checkConsistencyLight();
421 CPPUNIT_ASSERT_EQUAL(1,mesh2->getMeshDimension());
422 CPPUNIT_ASSERT_EQUAL(13,(int)mesh2->getNumberOfCells());
423 CPPUNIT_ASSERT_EQUAL((std::size_t)14,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(14,(int)revDescIndx->getNumberOfTuples());
424 CPPUNIT_ASSERT_EQUAL((std::size_t)6,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(6,(int)descIndx->getNumberOfTuples());
425 CPPUNIT_ASSERT_EQUAL((std::size_t)18,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,(int)desc->getNumberOfTuples());
426 CPPUNIT_ASSERT_EQUAL((std::size_t)18,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,(int)revDesc->getNumberOfTuples());
427 const int expected1[18]={0,1,2,3, 2,4,5, 6,7,4, 8,9,1,10, 11,12,6,9};
428 CPPUNIT_ASSERT(std::equal(expected1,expected1+18,desc->getConstPointer()));
429 const int expected2[6]={0,4,7,10,14,18};
430 CPPUNIT_ASSERT(std::equal(expected2,expected2+6,descIndx->getConstPointer()));
431 const int expected3[14]={0,1,3,5,6,8,9,11,12,13,15,16,17,18};
432 CPPUNIT_ASSERT(std::equal(expected3,expected3+14,revDescIndx->getConstPointer()));
433 const int expected4[18]={0, 0,3, 0,1, 0, 1,2, 1, 2,4, 2, 3, 3,4, 3, 4, 4};
434 CPPUNIT_ASSERT(std::equal(expected4,expected4+18,revDesc->getConstPointer()));
435 DataArrayInt *conn=mesh2->getNodalConnectivity();
436 DataArrayInt *connIndex=mesh2->getNodalConnectivityIndex();
437 const int expected5[14]={0,3,6,9,12,15,18,21,24,27,30,33,36,39};
438 CPPUNIT_ASSERT(std::equal(expected5,expected5+14,connIndex->getConstPointer()));
439 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};
440 CPPUNIT_ASSERT(std::equal(expected6,expected6+39,conn->getConstPointer()));
445 revDescIndx->decrRef();
448 const int elts[2]={1,3};
449 std::vector<int> eltsV(elts,elts+2);
450 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
451 mesh->checkConsistencyLight();
453 desc=DataArrayInt::New();
454 descIndx=DataArrayInt::New();
455 revDesc=DataArrayInt::New();
456 revDescIndx=DataArrayInt::New();
458 mesh2=mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
459 mesh2->checkConsistencyLight();
460 CPPUNIT_ASSERT_EQUAL(1,mesh2->getMeshDimension());
461 CPPUNIT_ASSERT_EQUAL(13,(int)mesh2->getNumberOfCells());
462 CPPUNIT_ASSERT_EQUAL((std::size_t)14,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(14,(int)revDescIndx->getNumberOfTuples());
463 CPPUNIT_ASSERT_EQUAL((std::size_t)6,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(6,(int)descIndx->getNumberOfTuples());
464 CPPUNIT_ASSERT_EQUAL((std::size_t)18,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,(int)desc->getNumberOfTuples());
465 CPPUNIT_ASSERT_EQUAL((std::size_t)18,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,(int)revDesc->getNumberOfTuples());
466 CPPUNIT_ASSERT(std::equal(expected1,expected1+18,desc->getConstPointer()));
467 CPPUNIT_ASSERT(std::equal(expected2,expected2+6,descIndx->getConstPointer()));
468 CPPUNIT_ASSERT(std::equal(expected3,expected3+14,revDescIndx->getConstPointer()));
469 CPPUNIT_ASSERT(std::equal(expected4,expected4+18,revDesc->getConstPointer()));
470 conn=mesh2->getNodalConnectivity();
471 connIndex=mesh2->getNodalConnectivityIndex();
472 CPPUNIT_ASSERT(std::equal(expected5,expected5+14,connIndex->getConstPointer()));
473 CPPUNIT_ASSERT(std::equal(expected6,expected6+39,conn->getConstPointer()));
478 revDescIndx->decrRef();
483 void MEDCouplingBasicsTest1::testDescConn3D()
485 MEDCouplingUMesh *mesh=build3DTargetMesh_1();
486 DataArrayInt *desc=DataArrayInt::New();
487 DataArrayInt *descIndx=DataArrayInt::New();
488 DataArrayInt *revDesc=DataArrayInt::New();
489 DataArrayInt *revDescIndx=DataArrayInt::New();
491 MEDCouplingUMesh *mesh2=mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
492 mesh2->checkConsistencyLight();
493 CPPUNIT_ASSERT_EQUAL(2,mesh2->getMeshDimension());
494 CPPUNIT_ASSERT_EQUAL(36,(int)mesh2->getNumberOfCells());
495 CPPUNIT_ASSERT_EQUAL((std::size_t)37,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(37,(int)revDescIndx->getNumberOfTuples());
496 CPPUNIT_ASSERT_EQUAL((std::size_t)9,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(9,(int)descIndx->getNumberOfTuples());
497 CPPUNIT_ASSERT_EQUAL((std::size_t)48,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,(int)desc->getNumberOfTuples());
498 CPPUNIT_ASSERT_EQUAL((std::size_t)48,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,(int)revDesc->getNumberOfTuples());
499 const int expected1[9]={0, 6, 12, 18, 24, 30, 36, 42, 48};
500 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};
501 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};
502 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};
503 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};
504 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,
505 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,
506 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,
507 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};
508 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,
509 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,
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};
513 CPPUNIT_ASSERT(std::equal(expected1,expected1+9,descIndx->getConstPointer()));
514 CPPUNIT_ASSERT(std::equal(expected2,expected2+48,desc->getConstPointer()));
515 CPPUNIT_ASSERT(std::equal(expected3,expected3+37,revDescIndx->getConstPointer()));
516 CPPUNIT_ASSERT(std::equal(expected4,expected4+48,revDesc->getConstPointer()));
517 CPPUNIT_ASSERT(std::equal(expected5,expected5+37,mesh2->getNodalConnectivityIndex()->getConstPointer()));
518 CPPUNIT_ASSERT(std::equal(expected6,expected6+180,mesh2->getNodalConnectivity()->getConstPointer()));
523 revDescIndx->decrRef();
526 const int elts[2]={1,3};
527 std::vector<int> eltsV(elts,elts+2);
528 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
529 mesh->checkConsistencyLight();
530 desc=DataArrayInt::New();
531 descIndx=DataArrayInt::New();
532 revDesc=DataArrayInt::New();
533 revDescIndx=DataArrayInt::New();
534 mesh2=mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
535 mesh2->checkConsistencyLight();
536 CPPUNIT_ASSERT_EQUAL(2,mesh2->getMeshDimension());
537 CPPUNIT_ASSERT_EQUAL(36,(int)mesh2->getNumberOfCells());
538 CPPUNIT_ASSERT_EQUAL((std::size_t)37,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(37,(int)revDescIndx->getNumberOfTuples());
539 CPPUNIT_ASSERT_EQUAL((std::size_t)9,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(9,(int)descIndx->getNumberOfTuples());
540 CPPUNIT_ASSERT_EQUAL((std::size_t)48,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,(int)desc->getNumberOfTuples());
541 CPPUNIT_ASSERT_EQUAL((std::size_t)48,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,(int)revDesc->getNumberOfTuples());
542 CPPUNIT_ASSERT(std::equal(expected1,expected1+9,descIndx->getConstPointer()));
543 CPPUNIT_ASSERT(std::equal(expected2,expected2+48,desc->getConstPointer()));
544 CPPUNIT_ASSERT(std::equal(expected3,expected3+37,revDescIndx->getConstPointer()));
545 CPPUNIT_ASSERT(std::equal(expected4,expected4+48,revDesc->getConstPointer()));
546 CPPUNIT_ASSERT(std::equal(expected5,expected5+37,mesh2->getNodalConnectivityIndex()->getConstPointer()));
547 CPPUNIT_ASSERT(std::equal(expected7,expected7+180,mesh2->getNodalConnectivity()->getConstPointer()));
552 revDescIndx->decrRef();
557 void MEDCouplingBasicsTest1::testFindBoundaryNodes()
559 MEDCouplingUMesh *mesh=build3DTargetMesh_1();
560 DataArrayInt *boundaryNodes=mesh->findBoundaryNodes();
561 CPPUNIT_ASSERT_EQUAL(26,(int)boundaryNodes->getNumberOfTuples());
562 CPPUNIT_ASSERT_EQUAL(1,(int)boundaryNodes->getNumberOfComponents());
563 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};
564 CPPUNIT_ASSERT(std::equal(expected1,expected1+26,boundaryNodes->begin()));
565 boundaryNodes->decrRef();
569 void MEDCouplingBasicsTest1::testBoundaryMesh()
571 MEDCouplingUMesh *mesh=build3DTargetMesh_1();
572 MEDCouplingPointSet *mesh2=mesh->buildBoundaryMesh(false);
573 CPPUNIT_ASSERT_EQUAL(24,(int)mesh2->getNumberOfCells());
574 CPPUNIT_ASSERT_EQUAL(26,mesh2->getNumberOfNodes());
579 void MEDCouplingBasicsTest1::testBuildPartOfMySelf()
581 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
582 mesh->setName("Toto");
583 const int tab1[2]={0,4};
584 const int tab2[3]={0,2,3};
586 MEDCouplingPointSet *subMeshSimple=mesh->buildPartOfMySelf(tab1,tab1+2,true);
587 MEDCouplingUMesh *subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
588 CPPUNIT_ASSERT(subMesh);
589 std::string name(subMesh->getName());
590 CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllGeoTypes().size());
591 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*mesh->getAllGeoTypes().begin());
592 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++(mesh->getAllGeoTypes().begin())));
593 CPPUNIT_ASSERT_EQUAL(1,(int)subMesh->getAllGeoTypes().size());
594 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllGeoTypes().begin());
595 CPPUNIT_ASSERT(name=="Toto");
596 CPPUNIT_ASSERT(mesh->getCoords()==subMesh->getCoords());
597 CPPUNIT_ASSERT_EQUAL(2,(int)subMesh->getNumberOfCells());
598 const int subConn[10]={4,0,3,4,1,4,7,8,5,4};
599 const int subConnIndex[3]={0,5,10};
600 CPPUNIT_ASSERT_EQUAL((std::size_t)10,subMesh->getNodalConnectivity()->getNbOfElems());
601 CPPUNIT_ASSERT_EQUAL((std::size_t)3,subMesh->getNodalConnectivityIndex()->getNbOfElems());
602 CPPUNIT_ASSERT(std::equal(subConn,subConn+10,subMesh->getNodalConnectivity()->getPointer()));
603 CPPUNIT_ASSERT(std::equal(subConnIndex,subConnIndex+3,subMesh->getNodalConnectivityIndex()->getPointer()));
606 subMeshSimple=mesh->buildPartOfMySelf(tab2,tab2+3,true);
607 subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
608 CPPUNIT_ASSERT(subMesh);
609 name=subMesh->getName();
610 CPPUNIT_ASSERT_EQUAL(2,(int)subMesh->getAllGeoTypes().size());
611 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*subMesh->getAllGeoTypes().begin());
612 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++(subMesh->getAllGeoTypes().begin())));
613 CPPUNIT_ASSERT(name=="Toto");
614 CPPUNIT_ASSERT(mesh->getCoords()==subMesh->getCoords());
615 CPPUNIT_ASSERT_EQUAL(3,(int)subMesh->getNumberOfCells());
616 const int subConn2[14]={4,0,3,4,1,3,4,5,2,4,6,7,4,3};
617 const int subConnIndex2[4]={0,5,9,14};
618 CPPUNIT_ASSERT_EQUAL((std::size_t)14,subMesh->getNodalConnectivity()->getNbOfElems());
619 CPPUNIT_ASSERT_EQUAL((std::size_t)4,subMesh->getNodalConnectivityIndex()->getNbOfElems());
620 CPPUNIT_ASSERT(std::equal(subConn2,subConn2+14,subMesh->getNodalConnectivity()->getPointer()));
621 CPPUNIT_ASSERT(std::equal(subConnIndex2,subConnIndex2+4,subMesh->getNodalConnectivityIndex()->getPointer()));
622 const int tab3[3]={0,1,2};
623 MEDCouplingPointSet *subMeshSimple2=subMeshSimple->buildPartOfMySelf(tab3,tab3+3,true);
625 name=subMeshSimple2->getName();
626 CPPUNIT_ASSERT(name=="Toto");
627 subMeshSimple2->decrRef();
632 void MEDCouplingBasicsTest1::testBuildPartOfMySelfNode()
634 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
635 const int tab1[4]={5,7,8,4};
636 MEDCouplingPointSet *subMeshSimple=mesh->buildPartOfMySelfNode(tab1,tab1+4,true);
637 MEDCouplingUMesh *subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
638 CPPUNIT_ASSERT(subMesh);
639 CPPUNIT_ASSERT_EQUAL(1,(int)subMesh->getAllGeoTypes().size());
640 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllGeoTypes().begin());
641 CPPUNIT_ASSERT_EQUAL(1,(int)subMesh->getNumberOfCells());
642 CPPUNIT_ASSERT_EQUAL((std::size_t)5,subMesh->getNodalConnectivity()->getNbOfElems());
643 CPPUNIT_ASSERT_EQUAL((std::size_t)2,subMesh->getNodalConnectivityIndex()->getNbOfElems());
644 const int subConn[5]={4,7,8,5,4};
645 const int subConnIndex[3]={0,5};
646 CPPUNIT_ASSERT(std::equal(subConn,subConn+5,subMesh->getNodalConnectivity()->getPointer()));
647 CPPUNIT_ASSERT(std::equal(subConnIndex,subConnIndex+2,subMesh->getNodalConnectivityIndex()->getPointer()));
648 CPPUNIT_ASSERT(subMesh->getCoords()==mesh->getCoords());
649 subMeshSimple->decrRef();
651 subMeshSimple=mesh->buildPartOfMySelfNode(tab1,tab1+2,false);
652 subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
653 CPPUNIT_ASSERT(subMesh);
654 CPPUNIT_ASSERT_EQUAL(2,(int)subMesh->getAllGeoTypes().size());
655 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*subMesh->getAllGeoTypes().begin());
656 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++subMesh->getAllGeoTypes().begin()));
657 CPPUNIT_ASSERT_EQUAL(3,(int)subMesh->getNumberOfCells());
658 CPPUNIT_ASSERT_EQUAL((std::size_t)14,subMesh->getNodalConnectivity()->getNbOfElems());
659 CPPUNIT_ASSERT_EQUAL((std::size_t)4,subMesh->getNodalConnectivityIndex()->getNbOfElems());
660 const int subConn2[14]={3,4,5,2,4,6,7,4,3,4,7,8,5,4};
661 const int subConnIndex2[4]={0,4,9,14};
662 CPPUNIT_ASSERT(std::equal(subConn2,subConn2+14,subMesh->getNodalConnectivity()->getPointer()));
663 CPPUNIT_ASSERT(std::equal(subConnIndex2,subConnIndex2+4,subMesh->getNodalConnectivityIndex()->getPointer()));
664 CPPUNIT_ASSERT(subMesh->getCoords()==mesh->getCoords());
665 subMeshSimple->decrRef();
666 //testing the case where length of tab2 is greater than max number of node per cell.
667 const int tab2[7]={0,3,2,1,4,5,6};
668 subMeshSimple=mesh->buildPartOfMySelfNode(tab2,tab2+7,true);
669 subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
670 CPPUNIT_ASSERT(subMesh);
671 CPPUNIT_ASSERT_EQUAL(2,(int)subMesh->getAllGeoTypes().size());
672 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*subMesh->getAllGeoTypes().begin());
673 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++subMesh->getAllGeoTypes().begin()));
674 CPPUNIT_ASSERT_EQUAL(3,(int)subMesh->getNumberOfCells());
675 subMeshSimple->decrRef();
680 void MEDCouplingBasicsTest1::testZipCoords()
682 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
683 CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllGeoTypes().size());
684 CPPUNIT_ASSERT_EQUAL(2,mesh->getSpaceDimension());
685 CPPUNIT_ASSERT_EQUAL(9,mesh->getNumberOfNodes());
686 CPPUNIT_ASSERT_EQUAL(5,(int)mesh->getNumberOfCells());
687 std::vector<int> oldConn(mesh->getNodalConnectivity()->getNbOfElems());
688 std::vector<int> oldConnIndex(mesh->getNumberOfCells()+1);
689 std::copy(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+oldConn.size(),oldConn.begin());
690 std::copy(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+mesh->getNumberOfCells()+1,oldConnIndex.begin());
691 DataArrayDouble *oldCoords=mesh->getCoords();
692 oldCoords->incrRef();
694 CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllGeoTypes().size());
695 CPPUNIT_ASSERT_EQUAL(2,mesh->getSpaceDimension());
696 CPPUNIT_ASSERT_EQUAL(9,mesh->getNumberOfNodes());
697 CPPUNIT_ASSERT_EQUAL(5,(int)mesh->getNumberOfCells());
698 CPPUNIT_ASSERT(mesh->getCoords()!=oldCoords);
699 CPPUNIT_ASSERT(std::equal(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+2*9,oldCoords->getPointer()));
700 CPPUNIT_ASSERT(std::equal(oldConn.begin(),oldConn.end(),mesh->getNodalConnectivity()->getPointer()));
701 CPPUNIT_ASSERT(std::equal(oldConnIndex.begin(),oldConnIndex.end(),mesh->getNodalConnectivityIndex()->getPointer()));
702 oldCoords->decrRef();
704 const int tab1[2]={0,4};
705 MEDCouplingPointSet *subMeshPtSet=mesh->buildPartOfMySelf(tab1,tab1+2,true);
706 MEDCouplingUMesh *subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshPtSet);
707 CPPUNIT_ASSERT(subMesh);
708 DataArrayInt *traducer=subMesh->zipCoordsTraducer();
709 const int expectedTraducer[9]={0,1,-1,2,3,4,-1,5,6};
710 CPPUNIT_ASSERT(std::equal(expectedTraducer,expectedTraducer+9,traducer->getPointer()));
712 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllGeoTypes().begin());
713 CPPUNIT_ASSERT_EQUAL(2,(int)subMesh->getNumberOfCells());
714 const int subConn[10]={4,0,2,3,1,4,5,6,4,3};
715 const int subConnIndex[3]={0,5,10};
716 CPPUNIT_ASSERT_EQUAL(7,subMesh->getNumberOfNodes());
717 CPPUNIT_ASSERT_EQUAL((std::size_t)10,subMesh->getNodalConnectivity()->getNbOfElems());
718 CPPUNIT_ASSERT_EQUAL((std::size_t)3,subMesh->getNodalConnectivityIndex()->getNbOfElems());
719 CPPUNIT_ASSERT(std::equal(subConn,subConn+10,subMesh->getNodalConnectivity()->getPointer()));
720 CPPUNIT_ASSERT(std::equal(subConnIndex,subConnIndex+3,subMesh->getNodalConnectivityIndex()->getPointer()));
723 subMeshPtSet=mesh->buildPartOfMySelf(tab1,tab1+2,false);
724 subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshPtSet);
725 CPPUNIT_ASSERT(subMesh);
726 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllGeoTypes().begin());
727 CPPUNIT_ASSERT_EQUAL(2,(int)subMesh->getNumberOfCells());
728 CPPUNIT_ASSERT_EQUAL(7,subMesh->getNumberOfNodes());
729 CPPUNIT_ASSERT_EQUAL((std::size_t)10,subMesh->getNodalConnectivity()->getNbOfElems());
730 CPPUNIT_ASSERT_EQUAL((std::size_t)3,subMesh->getNodalConnectivityIndex()->getNbOfElems());
731 CPPUNIT_ASSERT(std::equal(subConn,subConn+10,subMesh->getNodalConnectivity()->getPointer()));
732 CPPUNIT_ASSERT(std::equal(subConnIndex,subConnIndex+3,subMesh->getNodalConnectivityIndex()->getPointer()));
738 void MEDCouplingBasicsTest1::testZipConnectivity()
740 MEDCouplingUMesh *m1=build2DTargetMesh_1();
741 MEDCouplingUMesh *m2=build2DTargetMesh_1();
742 int cells1[3]={2,3,4};
743 MEDCouplingPointSet *m3_1=m2->buildPartOfMySelf(cells1,cells1+3,true);
744 MEDCouplingUMesh *m3=dynamic_cast<MEDCouplingUMesh *>(m3_1);
747 MEDCouplingUMesh *m4=build2DSourceMesh_1();
748 MEDCouplingUMesh *m5=MEDCouplingUMesh::MergeUMeshes(m1,m3);
751 MEDCouplingUMesh *m6=MEDCouplingUMesh::MergeUMeshes(m5,m4);
757 CPPUNIT_ASSERT_EQUAL(10,(int)m6->getNumberOfCells());
758 CPPUNIT_ASSERT_EQUAL(22,m6->getNumberOfNodes());
759 DataArrayInt *arr=m6->mergeNodes(1e-13,areNodesMerged,newNbOfNodes);
761 CPPUNIT_ASSERT(areNodesMerged);
762 CPPUNIT_ASSERT_EQUAL(10,(int)m6->getNumberOfCells());
763 CPPUNIT_ASSERT_EQUAL(9,m6->getNumberOfNodes());
764 CPPUNIT_ASSERT_EQUAL(9,newNbOfNodes);
766 arr=m6->zipConnectivityTraducer(0);
767 CPPUNIT_ASSERT_EQUAL(7,(int)m6->getNumberOfCells());
769 MEDCouplingUMesh *m7=m6->clone(true);
770 arr=m6->zipConnectivityTraducer(0);
771 CPPUNIT_ASSERT(m7->isEqual(m6,1e-12));
772 CPPUNIT_ASSERT_EQUAL(7,(int)m6->getNumberOfCells());
779 void MEDCouplingBasicsTest1::testEqualMesh()
781 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
782 MEDCouplingUMesh *mesh2=build2DTargetMesh_1();
784 CPPUNIT_ASSERT(mesh1->isEqual(mesh1,1e-12));
786 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
787 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
788 double *pt=mesh2->getCoords()->getPointer();
791 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
792 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
794 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
795 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
797 int *pt2=mesh1->getNodalConnectivity()->getPointer();
799 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
800 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
802 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
803 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
805 pt2=mesh1->getNodalConnectivityIndex()->getPointer();
807 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
808 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
810 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
811 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
813 std::string tmp3=mesh1->getName();
814 mesh1->setName("lllll");
815 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
816 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
817 mesh1->setName(tmp3.c_str());
818 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
819 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
821 tmp3=mesh2->getCoords()->getInfoOnComponent(1);
822 mesh2->getCoords()->setInfoOnComponent(1,"kkkkkk");
823 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
824 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
825 mesh2->getCoords()->setInfoOnComponent(1,tmp3.c_str());
826 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
827 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
833 void MEDCouplingBasicsTest1::testEqualFieldDouble()
835 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
836 MEDCouplingUMesh *mesh2=build2DTargetMesh_1();
838 MEDCouplingFieldDouble *fieldOnCells1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
839 fieldOnCells1->setMesh(mesh1);
840 MEDCouplingFieldDouble *fieldOnCells2=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
841 fieldOnCells2->setMesh(mesh2);
843 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
844 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
845 fieldOnCells2->decrRef();
847 MEDCouplingFieldDouble *fieldOnNodes1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
848 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnNodes1,1e-12,1e-15));
849 CPPUNIT_ASSERT(!fieldOnNodes1->isEqual(fieldOnCells1,1e-12,1e-15));
850 fieldOnNodes1->decrRef();
852 fieldOnCells2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
853 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
854 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
855 fieldOnCells1->decrRef();
856 fieldOnCells1=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->setTime(4.,6,7);
860 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
861 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
862 fieldOnCells2->setTime(4.,6,7);
863 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
864 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
865 fieldOnCells1->setName("Power");
866 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
867 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
868 fieldOnCells2->setName("Power");
869 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
870 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
872 fieldOnCells1->setMesh(mesh1);
873 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
874 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
875 fieldOnCells2->setMesh(mesh1);
876 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
877 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
878 DataArrayDouble *arr=DataArrayDouble::New();
879 arr->setName("popo");
880 arr->alloc(mesh1->getNumberOfCells(),3);
881 double *pt=arr->getPointer();
882 std::fill(pt,pt+mesh1->getNumberOfCells()*3,6.);
883 fieldOnCells1->setArray(arr);
884 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
885 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
886 fieldOnCells2->setArray(arr);
888 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
889 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
891 DataArrayDouble *arr2=arr->deepCopy();
892 fieldOnCells2->setArray(arr2);
894 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
895 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
897 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
898 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
900 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
901 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
902 arr2->setName("popo2");
903 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
904 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
906 arr2->setName("popo");
907 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
908 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
910 arr2->setInfoOnComponent(2,"jjj");
911 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
912 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
913 arr->setInfoOnComponent(2,"jjj");
914 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
915 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
917 fieldOnCells1->decrRef();
918 fieldOnCells2->decrRef();
924 void MEDCouplingBasicsTest1::testNatureChecking()
926 MEDCouplingFieldDouble *field=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
927 field->setNature(ExtensiveMaximum);
928 field->setNature(IntensiveMaximum);
929 field->setNature(ExtensiveConservation);
931 field=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
932 field->setNature(IntensiveMaximum);
933 CPPUNIT_ASSERT_THROW(field->setNature(ExtensiveMaximum),INTERP_KERNEL::Exception);
934 CPPUNIT_ASSERT_THROW(field->setNature(ExtensiveConservation),INTERP_KERNEL::Exception);
938 void MEDCouplingBasicsTest1::testBuildSubMeshData()
940 MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
941 //check buildSubMesh on field on cells
942 MEDCouplingFieldDouble *fieldCells=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
943 fieldCells->setMesh(targetMesh);
944 const int elts[3]={1,2,4};
946 MEDCouplingMesh *ret1=fieldCells->buildSubMeshData(elts,elts+3,di);
947 CPPUNIT_ASSERT_EQUAL(3,(int)ret1->getNumberOfCells());
948 CPPUNIT_ASSERT_EQUAL(9,ret1->getNumberOfNodes());
949 CPPUNIT_ASSERT_EQUAL(3,(int)di->getNumberOfTuples());
950 CPPUNIT_ASSERT_EQUAL(1,(int)di->getNumberOfComponents());
951 const int *toCheck=di->getConstPointer();
952 CPPUNIT_ASSERT(std::equal(elts,elts+3,toCheck));
953 MEDCouplingUMesh *ret1DC=dynamic_cast<MEDCouplingUMesh *>(ret1);
954 CPPUNIT_ASSERT(ret1DC);
957 fieldCells->decrRef();
958 //check buildSubMesh on field on nodes
959 MEDCouplingFieldDouble *fieldNodes=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
960 fieldNodes->setMesh(targetMesh);
961 MEDCouplingMesh *ret2=fieldNodes->buildSubMeshData(elts,elts+3,di);
962 MEDCouplingUMesh *ret2DC=dynamic_cast<MEDCouplingUMesh *>(ret2);
963 CPPUNIT_ASSERT(ret2DC);
964 CPPUNIT_ASSERT_EQUAL(3,(int)ret2->getNumberOfCells());
965 CPPUNIT_ASSERT_EQUAL(6,ret2->getNumberOfNodes());
966 CPPUNIT_ASSERT_EQUAL(6,(int)di->getNumberOfTuples());
967 CPPUNIT_ASSERT_EQUAL(1,(int)di->getNumberOfComponents());
968 toCheck=di->getConstPointer();
969 const int expected[6]={1,2,4,5,7,8};
970 CPPUNIT_ASSERT(std::equal(expected,expected+6,toCheck));
973 fieldNodes->decrRef();
974 targetMesh->decrRef();
977 void MEDCouplingBasicsTest1::testExtrudedMesh1()
979 MEDCouplingUMesh *mesh2D=0;
980 MEDCouplingUMesh *mesh3D=build3DExtrudedUMesh_1(mesh2D);
981 MEDCouplingMappedExtrudedMesh *ext=MEDCouplingMappedExtrudedMesh::New(mesh3D,mesh2D,1);
982 CPPUNIT_ASSERT_EQUAL(18,(int)ext->getNumberOfCells());
983 CPPUNIT_ASSERT_EQUAL(60,ext->getNumberOfNodes());
984 DataArrayInt *ids3D=ext->getMesh3DIds();
985 const int ids3DExpected[18]={5,4,3,2,1,0, 11,10,9,8,7,6, 17,16,15,14,13,12};
986 CPPUNIT_ASSERT_EQUAL(18,(int)ids3D->getNumberOfTuples());
987 CPPUNIT_ASSERT_EQUAL(1,(int)ids3D->getNumberOfComponents());
988 CPPUNIT_ASSERT(std::equal(ids3DExpected,ids3DExpected+18,ids3D->getConstPointer()));
989 MEDCouplingUMesh *mesh1D=ext->getMesh1D();
990 CPPUNIT_ASSERT_EQUAL(4,mesh1D->getNumberOfNodes());
991 CPPUNIT_ASSERT_EQUAL(3,(int)mesh1D->getNumberOfCells());
992 const double mesh1DExpected[12]={0.66666666666666663, 1.4583333333333333, 0, 0.66666666666666663, 1.4583333333333333, 1, 0.66666666666666663, 1.4583333333333333, 2, 0.66666666666666663, 1.4583333333333333, 3};
993 DataArrayDouble *mesh1DCoords=mesh1D->getCoords();
994 CPPUNIT_ASSERT_EQUAL(4,(int)mesh1DCoords->getNumberOfTuples());
995 CPPUNIT_ASSERT_EQUAL(3,(int)mesh1DCoords->getNumberOfComponents());
996 CPPUNIT_ASSERT(std::equal(mesh1DExpected,mesh1DExpected+12,mesh1DCoords->getConstPointer()));
997 DataArrayInt *conn1D=mesh1D->getNodalConnectivity();
998 CPPUNIT_ASSERT_EQUAL(9,(int)conn1D->getNumberOfTuples());
999 CPPUNIT_ASSERT_EQUAL(1,(int)conn1D->getNumberOfComponents());
1000 const int conn1DExpected[9]={1,0,1,1,1,2,1,2,3};
1001 CPPUNIT_ASSERT(std::equal(conn1DExpected,conn1DExpected+9,conn1D->getConstPointer()));
1007 void MEDCouplingBasicsTest1::testExtrudedMesh2()
1009 MEDCouplingUMesh *mN,*mTT,*mTF;
1010 build3DExtrudedUMesh_2(mN,mTT,mTF);
1014 DataArrayInt *da=mTT->mergeNodes(1e-12,b,newNbOfNodes);
1018 double pt[3]={300.,300.,0.};
1019 double v[3]={0.,0.,2.};
1020 mTT->findNodesOnPlane(pt,v,1e-12,n);
1021 CPPUNIT_ASSERT_EQUAL(43,(int)n.size());
1022 MEDCouplingUMesh *mTT3dSurf=(MEDCouplingUMesh *)mTT->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
1023 MEDCouplingMappedExtrudedMesh *meTT=MEDCouplingMappedExtrudedMesh::New(mTT,mTT3dSurf,0);
1024 CPPUNIT_ASSERT_EQUAL(200,(int)meTT->getNumberOfCells());
1025 CPPUNIT_ASSERT_EQUAL(10,(int)meTT->getMesh2D()->getNumberOfCells());
1026 CPPUNIT_ASSERT_EQUAL(20,(int)meTT->getMesh1D()->getNumberOfCells());
1027 mTT3dSurf->decrRef();
1030 da=mN->mergeNodes(1e-12,b,newNbOfNodes);
1034 mN->findNodesOnPlane(pt,v,1e-12,n);
1035 CPPUNIT_ASSERT_EQUAL(30,(int)n.size());
1036 MEDCouplingUMesh *mN3dSurf=(MEDCouplingUMesh *)mN->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
1037 MEDCouplingMappedExtrudedMesh *meN=MEDCouplingMappedExtrudedMesh::New(mN,mN3dSurf,0);
1038 CPPUNIT_ASSERT_EQUAL(40,(int)meN->getNumberOfCells());
1039 CPPUNIT_ASSERT_EQUAL(20,(int)meN->getMesh2D()->getNumberOfCells());
1040 CPPUNIT_ASSERT_EQUAL(2,(int)meN->getMesh1D()->getNumberOfCells());
1041 mN3dSurf->decrRef();
1044 da=mTF->mergeNodes(1e-12,b,newNbOfNodes);
1048 mTF->findNodesOnPlane(pt,v,1e-12,n);
1049 CPPUNIT_ASSERT_EQUAL(27,(int)n.size());
1050 MEDCouplingUMesh *mTF3dSurf=(MEDCouplingUMesh *)mTF->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
1051 MEDCouplingMappedExtrudedMesh *meTF=MEDCouplingMappedExtrudedMesh::New(mTF,mTF3dSurf,0);
1052 CPPUNIT_ASSERT_EQUAL(340,(int)meTF->getNumberOfCells());
1053 CPPUNIT_ASSERT_EQUAL(17,(int)meTF->getMesh2D()->getNumberOfCells());
1054 CPPUNIT_ASSERT_EQUAL(20,(int)meTF->getMesh1D()->getNumberOfCells());
1055 mTF3dSurf->decrRef();
1067 * This test check MEDCouplingUMesh::buildExtrudedMesh method.
1069 void MEDCouplingBasicsTest1::testExtrudedMesh3()
1071 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1072 m1->changeSpaceDimension(3);
1073 MEDCouplingUMesh *m2=buildCU1DMesh_U();
1074 m2->changeSpaceDimension(3);
1075 double center[3]={0.,0.,0.};
1076 double vector[3]={0,1,0};
1077 m2->rotate(center,vector,-M_PI/2.);
1078 MEDCouplingUMesh *m3=m1->buildExtrudedMesh(m2,0);
1080 MEDCouplingMappedExtrudedMesh *m4=MEDCouplingMappedExtrudedMesh::New(m3,m1,0);
1081 CPPUNIT_ASSERT_EQUAL(15,(int)m4->getNumberOfCells());
1082 CPPUNIT_ASSERT_EQUAL(5,(int)m4->getMesh2D()->getNumberOfCells());
1083 CPPUNIT_ASSERT_EQUAL(3,(int)m4->getMesh1D()->getNumberOfCells());
1084 const int *m3DIds=m4->getMesh3DIds()->getConstPointer();
1085 for(int i=0;i<15;i++)
1086 CPPUNIT_ASSERT_EQUAL(i,m3DIds[i]);
1088 //some random in cells to check that extrusion alg find it correctly
1089 const int expected1[15]={1,3,2,0,6,5,7,10,11,8,12,9,14,13,4};
1090 m3->renumberCells(expected1,false);
1091 m4=MEDCouplingMappedExtrudedMesh::New(m3,m1,0);
1092 CPPUNIT_ASSERT_EQUAL(15,(int)m4->getNumberOfCells());
1093 CPPUNIT_ASSERT_EQUAL(5,(int)m4->getMesh2D()->getNumberOfCells());
1094 CPPUNIT_ASSERT_EQUAL(3,(int)m4->getMesh1D()->getNumberOfCells());
1095 m3DIds=m4->getMesh3DIds()->getConstPointer();
1096 for(int i=0;i<15;i++)
1097 CPPUNIT_ASSERT_EQUAL(expected1[i],m3DIds[i]);
1100 //play with polygons and polyedrons
1101 std::vector<int> cells(2); cells[0]=2; cells[1]=3;
1102 m1->convertToPolyTypes(&cells[0],&cells[0]+cells.size());
1103 m3=m1->buildExtrudedMesh(m2,0);
1104 CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_HEXA8,(int)m3->getTypeOfCell(0));
1105 CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_PENTA6,(int)m3->getTypeOfCell(1));
1106 CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_POLYHED,(int)m3->getTypeOfCell(2));
1107 CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_POLYHED,(int)m3->getTypeOfCell(3));
1108 CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_HEXA8,(int)m3->getTypeOfCell(4));
1109 m3->renumberCells(expected1,false);
1110 m4=MEDCouplingMappedExtrudedMesh::New(m3,m1,0);
1111 CPPUNIT_ASSERT_EQUAL(15,(int)m4->getNumberOfCells());
1112 CPPUNIT_ASSERT_EQUAL(5,(int)m4->getMesh2D()->getNumberOfCells());
1113 CPPUNIT_ASSERT_EQUAL(3,(int)m4->getMesh1D()->getNumberOfCells());
1114 m3DIds=m4->getMesh3DIds()->getConstPointer();
1115 for(int i=0;i<15;i++)
1116 CPPUNIT_ASSERT_EQUAL(expected1[i],m3DIds[i]);
1125 * This test check MEDCouplingUMesh::buildExtrudedMesh method, but also, MEDCouplingMappedExtrudedMesh following methods :
1126 * getCellContainingPoint getMeasureField getNodeIdsOfCell getCoordinateOfNode getTypeOfCell build3DUnstructuredMesh.
1128 void MEDCouplingBasicsTest1::testExtrudedMesh4()
1130 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1131 std::vector<int> cells(2); cells[0]=2; cells[1]=4;
1132 m1->convertToPolyTypes(&cells[0],&cells[0]+cells.size());
1133 m1->changeSpaceDimension(3);
1134 MEDCouplingUMesh *m2=buildCU1DMesh_U();
1135 m2->changeSpaceDimension(3);
1136 double center[3]={0.,0.,0.};
1137 double vector[3]={0.,1.,0.};
1138 m2->rotate(center,vector,-M_PI/2.);
1140 MEDCouplingUMesh *m3=m1->buildExtrudedMesh(m2,0);
1141 const int expected1[15]= {1,3,2,0,6,5,7,10,11,8,12,9,14,13,4};
1142 const int rexpected1[15]={3, 0, 2, 1, 14, 5, 4, 6, 9, 11, 7, 8, 10, 13, 12};
1143 m3->renumberCells(expected1,false);
1144 MEDCouplingMappedExtrudedMesh *m4=MEDCouplingMappedExtrudedMesh::New(m3,m1,0);
1145 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,m4->getTypeOfCell(0));
1146 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,m4->getTypeOfCell(1));
1147 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYHED,m4->getTypeOfCell(2));
1148 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_PENTA6,m4->getTypeOfCell(7));
1149 MEDCouplingFieldDouble *f=m4->getMeasureField(true);
1150 DataArrayDouble *arr=f->getArray();
1151 CPPUNIT_ASSERT_EQUAL(15,(int)arr->getNumberOfTuples());
1152 CPPUNIT_ASSERT_EQUAL(1,(int)arr->getNumberOfComponents());
1153 const double *arrPtr=arr->getConstPointer();
1154 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};
1155 for(int i=0;i<15;i++)
1156 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[rexpected1[i]],arrPtr[i],1e-16);
1158 MEDCouplingUMesh *m5=m4->build3DUnstructuredMesh();
1160 CPPUNIT_ASSERT(m5->isEqual(m3,1e-12));
1161 f=m5->getMeasureField(true);
1163 arrPtr=arr->getConstPointer();
1164 for(int i=0;i<15;i++)
1165 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[rexpected1[i]],arrPtr[i],1e-16);
1175 void MEDCouplingBasicsTest1::testFindCommonNodes()
1177 DataArrayInt *comm,*commI;
1178 MEDCouplingUMesh *targetMesh=build3DTargetMesh_1();
1179 targetMesh->findCommonNodes(1e-10,-1,comm,commI);
1180 CPPUNIT_ASSERT_EQUAL(1,(int)commI->getNumberOfTuples());
1181 CPPUNIT_ASSERT_EQUAL(0,(int)comm->getNumberOfTuples());
1183 DataArrayInt *o2n=targetMesh->buildNewNumberingFromCommonNodesFormat(comm,commI,newNbOfNodes);
1184 CPPUNIT_ASSERT_EQUAL(27,newNbOfNodes);
1185 CPPUNIT_ASSERT_EQUAL(27,(int)o2n->getNumberOfTuples());
1186 const int o2nExp1[27]=
1188 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
1191 CPPUNIT_ASSERT(std::equal(o2nExp1,o2nExp1+27,o2n->getConstPointer()));
1195 targetMesh->decrRef();
1197 targetMesh=build3DTargetMeshMergeNode_1();
1198 CPPUNIT_ASSERT_EQUAL(31,targetMesh->getNumberOfNodes());
1199 targetMesh->findCommonNodes(1e-10,-1,comm,commI);
1200 CPPUNIT_ASSERT_EQUAL(3,(int)commI->getNumberOfTuples());
1201 CPPUNIT_ASSERT_EQUAL(6,(int)comm->getNumberOfTuples());
1202 const int commExpected[6]={1,27,28,29,23,30};
1203 const int commIExpected[3]={0,4,6};
1204 CPPUNIT_ASSERT(std::equal(commExpected,commExpected+6,comm->getConstPointer()));
1205 CPPUNIT_ASSERT(std::equal(commIExpected,commIExpected+3,commI->getConstPointer()));
1206 o2n=targetMesh->buildNewNumberingFromCommonNodesFormat(comm,commI,newNbOfNodes);
1207 CPPUNIT_ASSERT_EQUAL(31,(int)o2n->getNumberOfTuples());
1208 CPPUNIT_ASSERT_EQUAL(27,newNbOfNodes);
1209 const int o2nExp2[31]=
1211 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
1212 21,22,23,24,25,26,1,1,1,23
1214 CPPUNIT_ASSERT(std::equal(o2nExp2,o2nExp2+31,o2n->getConstPointer()));
1218 targetMesh->decrRef();
1220 targetMesh=build3DTargetMesh_1();
1221 bool areNodesMerged;
1222 unsigned int time=targetMesh->getTimeOfThis();
1223 o2n=targetMesh->mergeNodes(1e-10,areNodesMerged,newNbOfNodes);
1224 targetMesh->updateTime();
1225 CPPUNIT_ASSERT(time==targetMesh->getTimeOfThis());
1226 CPPUNIT_ASSERT(!areNodesMerged);
1227 targetMesh->decrRef();
1230 targetMesh=build3DTargetMeshMergeNode_1();
1231 time=targetMesh->getTimeOfThis();
1232 o2n=targetMesh->mergeNodes(1e-10,areNodesMerged,newNbOfNodes);
1233 targetMesh->updateTime();
1234 CPPUNIT_ASSERT(time!=targetMesh->getTimeOfThis());
1235 CPPUNIT_ASSERT(areNodesMerged);
1236 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,
1237 18,4,5,8,7,13,14,17,16,
1238 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,
1239 18,13,14,17,16,22,23,26,25};
1240 CPPUNIT_ASSERT_EQUAL(72,(int)targetMesh->getNodalConnectivity()->getNumberOfTuples());
1241 CPPUNIT_ASSERT(std::equal(connExp,connExp+72,targetMesh->getNodalConnectivity()->getConstPointer()));
1242 CPPUNIT_ASSERT_EQUAL(27,(int)targetMesh->getCoords()->getNumberOfTuples());
1243 double coordsExp[81]={ 0., 0., 0., 50., 0., 0. , 200., 0., 0. , 0., 50., 0., 50., 50., 0. ,
1244 200., 50., 0., 0., 200., 0., 50., 200., 0. , 200., 200., 0. ,
1245 0., 0., 50., 50., 0., 50. , 200., 0., 50. , 0., 50., 50., 50.,
1246 50., 50. , 200., 50., 50., 0., 200., 50., 50., 200., 50. ,
1247 200., 200., 50. , 0., 0., 200., 50., 0., 200. , 200., 0., 200.
1248 , 0., 50., 200., 50., 50., 200. , 200., 50., 200.,
1249 0., 200., 200., 50., 200., 200. , 200., 200., 200. };
1250 CPPUNIT_ASSERT(std::equal(coordsExp,coordsExp+81,targetMesh->getCoords()->getConstPointer()));
1251 targetMesh->decrRef();
1254 targetMesh=build2DTargetMeshMergeNode_1();
1255 CPPUNIT_ASSERT_EQUAL(18,targetMesh->getNumberOfNodes());
1256 time=targetMesh->getTimeOfThis();
1257 o2n=targetMesh->mergeNodes(1e-10,areNodesMerged,newNbOfNodes);
1258 CPPUNIT_ASSERT(time!=targetMesh->getTimeOfThis());
1259 CPPUNIT_ASSERT(areNodesMerged);
1260 CPPUNIT_ASSERT_EQUAL(9,targetMesh->getNumberOfNodes());
1261 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};
1262 CPPUNIT_ASSERT_EQUAL(23,(int)targetMesh->getNodalConnectivity()->getNumberOfTuples());
1263 CPPUNIT_ASSERT(std::equal(connExp2,connExp2+23,targetMesh->getNodalConnectivity()->getConstPointer()));
1264 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};
1265 CPPUNIT_ASSERT_EQUAL(9,(int)targetMesh->getCoords()->getNumberOfTuples());
1266 CPPUNIT_ASSERT(std::equal(coordsExp2,coordsExp2+18,targetMesh->getCoords()->getConstPointer()));
1267 targetMesh->decrRef();
1271 void MEDCouplingBasicsTest1::testCheckButterflyCells()
1273 std::vector<int> cells;
1274 MEDCouplingUMesh *sourceMesh=build2DTargetMesh_1();
1275 sourceMesh->checkButterflyCells(cells);
1276 CPPUNIT_ASSERT(cells.empty());
1277 int *pt=sourceMesh->getNodalConnectivity()->getPointer();
1278 std::swap(pt[15],pt[16]);
1279 sourceMesh->checkButterflyCells(cells);
1280 CPPUNIT_ASSERT_EQUAL(1,(int)cells.size());
1281 CPPUNIT_ASSERT_EQUAL(3,cells[0]);
1283 std::swap(pt[15],pt[16]);
1284 sourceMesh->checkButterflyCells(cells);
1285 CPPUNIT_ASSERT(cells.empty());
1286 sourceMesh->decrRef();
1288 sourceMesh=build3DSurfTargetMesh_1();
1289 sourceMesh->checkButterflyCells(cells);
1290 CPPUNIT_ASSERT(cells.empty());
1291 pt=sourceMesh->getNodalConnectivity()->getPointer();
1292 std::swap(pt[15],pt[16]);
1293 sourceMesh->checkButterflyCells(cells);
1294 CPPUNIT_ASSERT_EQUAL(1,(int)cells.size());
1295 CPPUNIT_ASSERT_EQUAL(3,cells[0]);
1297 std::swap(pt[15],pt[16]);
1298 sourceMesh->checkButterflyCells(cells);
1299 CPPUNIT_ASSERT(cells.empty());
1300 sourceMesh->decrRef();
1303 void MEDCouplingBasicsTest1::testMergeMesh1()
1305 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1306 MEDCouplingUMesh *m2=build2DSourceMesh_1();
1307 const double vec[2]={1.,0.};
1309 MEDCouplingMesh *m3=m1->mergeMyselfWith(m2);
1310 MEDCouplingUMesh *m3C=dynamic_cast<MEDCouplingUMesh *>(m3);
1311 CPPUNIT_ASSERT(m3C);
1312 m3->checkConsistencyLight();
1313 MEDCouplingUMesh *m4=build2DTargetMeshMerged_1();
1314 CPPUNIT_ASSERT(m3->isEqual(m4,1.e-12));
1318 DataArrayInt *da=m3C->mergeNodes(1.e-12,isMerged,newNbOfNodes);
1319 CPPUNIT_ASSERT_EQUAL(11,m3C->getNumberOfNodes());
1320 CPPUNIT_ASSERT_EQUAL(11,newNbOfNodes);
1321 CPPUNIT_ASSERT(isMerged);
1328 void MEDCouplingBasicsTest1::testMergeMeshOnSameCoords1()
1330 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1331 MEDCouplingUMesh *m2=build2DTargetMesh_1();
1332 std::vector<int> cells(5);
1333 for(int i=0;i<5;i++)
1335 m2->convertToPolyTypes(&cells[0],&cells[0]+cells.size());
1336 m1->tryToShareSameCoords(*m2,1e-12);
1337 MEDCouplingUMesh *m3=build2DTargetMesh_1();
1338 m3->tryToShareSameCoords(*m2,1e-12);
1339 std::vector<const MEDCouplingUMesh *> meshes;
1340 meshes.push_back(m1); meshes.push_back(m2); meshes.push_back(m3);
1341 MEDCouplingUMesh *m4=MEDCouplingUMesh::MergeUMeshesOnSameCoords(meshes);
1342 m4->checkConsistencyLight();
1343 CPPUNIT_ASSERT(m4->getCoords()==m1->getCoords());
1344 CPPUNIT_ASSERT_EQUAL(15,(int)m4->getNumberOfCells());
1345 const int cells1[5]={0,1,2,3,4};
1346 MEDCouplingPointSet *m1_1=m4->buildPartOfMySelf(cells1,cells1+5,true);
1347 m1_1->setName(m1->getName().c_str());
1348 CPPUNIT_ASSERT(m1->isEqual(m1_1,1e-12));
1349 const int cells2[5]={5,6,7,8,9};
1350 MEDCouplingPointSet *m2_1=m4->buildPartOfMySelf(cells2,cells2+5,true);
1351 m2_1->setName(m2->getName().c_str());
1352 CPPUNIT_ASSERT(m2->isEqual(m2_1,1e-12));
1353 const int cells3[5]={10,11,12,13,14};
1354 MEDCouplingPointSet *m3_1=m4->buildPartOfMySelf(cells3,cells3+5,true);
1355 m3_1->setName(m3->getName().c_str());
1356 CPPUNIT_ASSERT(m3->isEqual(m3_1,1e-12));
1357 m1_1->decrRef(); m2_1->decrRef(); m3_1->decrRef();
1365 void MEDCouplingBasicsTest1::testMergeField1()
1367 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1368 MEDCouplingUMesh *m2=build2DSourceMesh_1();
1369 const double vec[2]={1.,0.};
1371 MEDCouplingFieldDouble *f1=m1->getMeasureField(true);
1372 MEDCouplingFieldDouble *f2=m2->getMeasureField(true);
1373 MEDCouplingFieldDouble *f3=MEDCouplingFieldDouble::MergeFields(f1,f2);
1374 f3->checkConsistencyLight();
1375 MEDCouplingUMesh *m4=build2DTargetMeshMerged_1();
1376 m4->setName(f1->getMesh()->getName());
1377 CPPUNIT_ASSERT(f3->getMesh()->isEqual(m4,1.e-12));
1378 std::string name=f3->getName();
1379 CPPUNIT_ASSERT(name=="MeasureOfMesh_");
1380 CPPUNIT_ASSERT(f3->getTypeOfField()==ON_CELLS);
1381 CPPUNIT_ASSERT(f3->getTimeDiscretization()==ONE_TIME);
1382 CPPUNIT_ASSERT_EQUAL(1,(int)f3->getNumberOfComponents());
1383 CPPUNIT_ASSERT_EQUAL(7,(int)f3->getNumberOfTuples());
1384 double values[7]={0.25,0.125,0.125,0.25,0.25,0.5,0.5};
1385 const double *tmp=f3->getArray()->getConstPointer();
1386 std::transform(tmp,tmp+7,values,values,std::minus<double>());
1387 std::transform(values,values+7,values,std::ptr_fun<double,double>(fabs));
1388 double max=*std::max_element(values,values+7);
1389 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1398 bool func1(const double *pt, double *res);
1399 bool func2(const double *pt, double *res);
1400 bool func3(const double *pt, double *res);
1401 bool func4(const double *pt, double *res);
1403 bool func1(const double *pt, double *res)
1409 bool func2(const double *pt, double *res)
1412 res[1]=2.*(pt[0]+pt[1]);
1416 bool func3(const double *pt, double *res)
1418 if(fabs(pt[0]-0.2)<1e-12)
1420 res[0]=1./(pt[0]-0.2);
1424 void MEDCouplingBasicsTest1::testFillFromAnalytic()
1426 MEDCouplingUMesh *m=build2DTargetMesh_1();
1427 m->setTime(3.4,5,6); m->setTimeUnit("us");
1429 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_CELLS,1,func1);
1430 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.4,f1->getTime(a,b),1.e-14);
1431 CPPUNIT_ASSERT_EQUAL(5,a); CPPUNIT_ASSERT_EQUAL(6,b);
1432 CPPUNIT_ASSERT_EQUAL(std::string(f1->getTimeUnit()),std::string("us"));
1433 f1->checkConsistencyLight();
1434 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_CELLS);
1435 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1436 CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1437 CPPUNIT_ASSERT_EQUAL(5,(int)f1->getNumberOfTuples());
1438 double values1[5]={-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9};
1439 const double *tmp=f1->getArray()->getConstPointer();
1440 std::transform(tmp,tmp+5,values1,values1,std::minus<double>());
1441 std::transform(values1,values1+5,values1,std::ptr_fun<double,double>(fabs));
1442 double max=*std::max_element(values1,values1+5);
1443 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1446 f1=m->fillFromAnalytic(ON_NODES,1,func1);
1447 f1->checkConsistencyLight();
1448 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1449 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1450 CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1451 CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1452 double values2[9]={-0.6,-0.1,0.4,-0.1,0.4,0.9,0.4,0.9,1.4};
1453 tmp=f1->getArray()->getConstPointer();
1454 std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
1455 std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
1456 max=*std::max_element(values2,values2+9);
1457 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1460 f1=m->fillFromAnalytic(ON_NODES,2,func2);
1461 f1->checkConsistencyLight();
1462 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1463 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1464 CPPUNIT_ASSERT_EQUAL(2,(int)f1->getNumberOfComponents());
1465 CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1466 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};
1467 tmp=f1->getArray()->getConstPointer();
1468 std::transform(tmp,tmp+18,values3,values3,std::minus<double>());
1469 std::transform(values3,values3+18,values3,std::ptr_fun<double,double>(fabs));
1470 max=*std::max_element(values3,values3+18);
1471 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1473 f1->accumulate(values4);
1474 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.6,values4[0],1.e-12);
1475 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.2,values4[1],1.e-12);
1476 f1->integral(true,values4);
1477 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,values4[0],1.e-12);
1478 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,values4[1],1.e-12);
1481 CPPUNIT_ASSERT_THROW(f1=m->fillFromAnalytic(ON_NODES,1,func3),INTERP_KERNEL::Exception);
1486 void MEDCouplingBasicsTest1::testFillFromAnalytic2()
1488 MEDCouplingUMesh *m=build2DTargetMesh_1();
1489 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_CELLS,1,"y+x");
1490 f1->checkConsistencyLight();
1491 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_CELLS);
1492 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1493 CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1494 CPPUNIT_ASSERT_EQUAL(5,(int)f1->getNumberOfTuples());
1495 double values1[5]={-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9};
1496 const double *tmp=f1->getArray()->getConstPointer();
1497 std::transform(tmp,tmp+5,values1,values1,std::minus<double>());
1498 std::transform(values1,values1+5,values1,std::ptr_fun<double,double>(fabs));
1499 double max=*std::max_element(values1,values1+5);
1500 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1503 f1=m->fillFromAnalytic(ON_NODES,1,"y+2*x");
1504 f1->checkConsistencyLight();
1505 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1506 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1507 CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1508 CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1509 double values2[9]={-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1};
1510 tmp=f1->getArray()->getConstPointer();
1511 std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
1512 std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
1513 max=*std::max_element(values2,values2+9);
1514 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1516 f1=m->fillFromAnalytic(ON_NODES,1,"2.*x+y");
1517 f1->checkConsistencyLight();
1518 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1519 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1520 CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1521 CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1522 tmp=f1->getArray()->getConstPointer();
1523 double values2Bis[9]={-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1};
1524 std::transform(tmp,tmp+9,values2Bis,values2Bis,std::minus<double>());
1525 std::transform(values2,values2+9,values2Bis,std::ptr_fun<double,double>(fabs));
1526 max=*std::max_element(values2Bis,values2Bis+9);
1527 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1530 f1=m->fillFromAnalytic(ON_NODES,2,"(x+y)*IVec+2*(x+y)*JVec");
1531 f1->checkConsistencyLight();
1532 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1533 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1534 CPPUNIT_ASSERT_EQUAL(2,(int)f1->getNumberOfComponents());
1535 CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1536 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};
1537 tmp=f1->getArray()->getConstPointer();
1538 std::transform(tmp,tmp+18,values3,values3,std::minus<double>());
1539 std::transform(values3,values3+18,values3,std::ptr_fun<double,double>(fabs));
1540 max=*std::max_element(values3,values3+18);
1541 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1543 f1->accumulate(values4);
1544 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.6,values4[0],1.e-12);
1545 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.2,values4[1],1.e-12);
1546 f1->integral(true,values4);
1547 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,values4[0],1.e-12);
1548 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,values4[1],1.e-12);
1551 CPPUNIT_ASSERT_THROW(f1=m->fillFromAnalytic(ON_NODES,1,"1./(x-0.2)"),INTERP_KERNEL::Exception);
1556 void MEDCouplingBasicsTest1::testApplyFunc()
1558 MEDCouplingUMesh *m=build2DTargetMesh_1();
1559 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,2,func2);
1560 f1->checkConsistencyLight();
1561 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1562 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1563 CPPUNIT_ASSERT_EQUAL(2,(int)f1->getNumberOfComponents());
1564 CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1565 f1->applyFunc(1,func1);
1566 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1567 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1568 CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1569 CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1570 double values1[9]={-1.8,-0.3,1.2,-0.3,1.2,2.7,1.2,2.7,4.2};
1571 const double *tmp=f1->getArray()->getConstPointer();
1572 std::transform(tmp,tmp+9,values1,values1,std::minus<double>());
1573 std::transform(values1,values1+9,values1,std::ptr_fun<double,double>(fabs));
1574 double max=*std::max_element(values1,values1+9);
1575 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1580 void MEDCouplingBasicsTest1::testApplyFunc2()
1582 MEDCouplingUMesh *m=build2DTargetMesh_1();
1583 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,2,func2);
1584 f1->checkConsistencyLight();
1585 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1586 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1587 CPPUNIT_ASSERT_EQUAL(2,(int)f1->getNumberOfComponents());
1588 CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1590 MEDCouplingFieldDouble *f2=f1->clone(true);
1591 CPPUNIT_ASSERT_THROW(f2->applyFunc(1,"a+b+c+d"),INTERP_KERNEL::Exception);
1592 CPPUNIT_ASSERT_THROW(f2->applyFunc(1,"a/0"),INTERP_KERNEL::Exception);
1593 CPPUNIT_ASSERT_THROW(f2->applyFunc("a/0"),INTERP_KERNEL::Exception);
1594 f2->applyFunc("abs(u)^2.4+2*u");
1595 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1596 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1597 CPPUNIT_ASSERT_EQUAL(2,(int)f1->getNumberOfComponents());
1598 CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1599 double values2[18]={-0.9065304805418678, -0.85105859001709905, -0.19601892829446504, -0.37898777756476987,
1600 0.91090317490482353, 2.1853504664669781, -0.19601892829446504, -0.37898777756476987,
1601 0.91090317490482353, 2.1853504664669781, 2.5765725275664879, 7.6987743736515295,
1602 0.91090317490482353, 2.1853504664669781, 2.5765725275664879, 7.6987743736515295,
1603 5.0423700574830965, 17.435300118916864};
1604 const double *tmp=f2->getArray()->getConstPointer();
1605 std::transform(tmp,tmp+18,values2,values2,std::minus<double>());
1606 std::transform(values2,values2+18,values2,std::ptr_fun<double,double>(fabs));
1607 double max=*std::max_element(values2,values2+18);
1608 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1611 f1->applyFunc(1,"x+y");
1612 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1613 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1614 CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1615 CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1616 double values1[9]={-1.8,-0.3,1.2,-0.3,1.2,2.7,1.2,2.7,4.2};
1617 tmp=f1->getArray()->getConstPointer();
1618 std::transform(tmp,tmp+9,values1,values1,std::minus<double>());
1619 std::transform(values1,values1+9,values1,std::ptr_fun<double,double>(fabs));
1620 max=*std::max_element(values1,values1+9);
1621 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1626 void MEDCouplingBasicsTest1::testOperationsOnFields()
1628 MEDCouplingUMesh *m=build2DTargetMesh_1();
1629 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,1,func1);
1630 MEDCouplingFieldDouble *f2=m->fillFromAnalytic(ON_NODES,1,func1);
1631 f1->checkConsistencyLight();
1632 f2->checkConsistencyLight();
1633 MEDCouplingFieldDouble *f3=(*f1)+(*f2);
1634 f3->checkConsistencyLight();
1635 CPPUNIT_ASSERT(f3->getTypeOfField()==ON_NODES);
1636 CPPUNIT_ASSERT(f3->getTimeDiscretization()==ONE_TIME);
1637 double values1[9]={-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8};
1638 const double *tmp=f3->getArray()->getConstPointer();
1639 std::transform(tmp,tmp+9,values1,values1,std::minus<double>());
1640 std::transform(values1,values1+9,values1,std::ptr_fun<double,double>(fabs));
1641 double max=*std::max_element(values1,values1+9);
1642 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1646 f3->checkConsistencyLight();
1647 CPPUNIT_ASSERT(f3->getTypeOfField()==ON_NODES);
1648 CPPUNIT_ASSERT(f3->getTimeDiscretization()==ONE_TIME);
1649 double values2[9]={0.36,0.01,0.16,0.01,0.16,0.81,0.16,0.81,1.96};
1650 tmp=f3->getArray()->getConstPointer();
1651 std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
1652 std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
1653 max=*std::max_element(values2,values2+9);
1654 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1658 MEDCouplingFieldDouble *f4=(*f1)-(*f3);
1659 f4->checkConsistencyLight();
1660 CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1661 CPPUNIT_ASSERT(f4->getTimeDiscretization()==ONE_TIME);
1662 double values3[9]={0.6,0.1,-0.4,0.1,-0.4,-0.9,-0.4,-0.9,-1.4};
1663 tmp=f4->getArray()->getConstPointer();
1664 std::transform(tmp,tmp+9,values3,values3,std::minus<double>());
1665 std::transform(values3,values3+9,values3,std::ptr_fun<double,double>(fabs));
1666 max=*std::max_element(values3,values3+9);
1667 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1673 f4->checkConsistencyLight();
1674 CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1675 CPPUNIT_ASSERT(f4->getTimeDiscretization()==ONE_TIME);
1676 tmp=f4->getArray()->getConstPointer();
1677 for(int i=0;i<9;i++)
1678 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.,tmp[i],1.e-12);
1682 f4=f2->buildNewTimeReprFromThis(NO_TIME,false);
1683 f4->checkConsistencyLight();
1684 CPPUNIT_ASSERT(f4->getArray()==f2->getArray());
1685 CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1686 CPPUNIT_ASSERT(f4->getTimeDiscretization()==NO_TIME);
1687 CPPUNIT_ASSERT_THROW(f3=(*f1)+(*f4),INTERP_KERNEL::Exception);
1688 MEDCouplingFieldDouble *f5=f4->buildNewTimeReprFromThis(ONE_TIME,false);
1689 CPPUNIT_ASSERT(f4->getArray()==f5->getArray());
1690 CPPUNIT_ASSERT(f5->getTypeOfField()==ON_NODES);
1691 CPPUNIT_ASSERT(f5->getTimeDiscretization()==ONE_TIME);
1693 tmp=f3->getArray()->getConstPointer();
1694 double values4[9]={-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8};
1695 std::transform(tmp,tmp+9,values4,values4,std::minus<double>());
1696 std::transform(values4,values4+9,values4,std::ptr_fun<double,double>(fabs));
1697 max=*std::max_element(values4,values4+9);
1698 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1703 f4=f2->buildNewTimeReprFromThis(NO_TIME,true);
1704 f4->checkConsistencyLight();
1705 CPPUNIT_ASSERT(f4->getArray()!=f2->getArray());
1706 CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1707 CPPUNIT_ASSERT(f4->getTimeDiscretization()==NO_TIME);
1708 CPPUNIT_ASSERT_THROW(f3=(*f1)+(*f4),INTERP_KERNEL::Exception);
1709 f5=f4->buildNewTimeReprFromThis(ONE_TIME,true);
1710 CPPUNIT_ASSERT(f4->getArray()!=f5->getArray());
1711 CPPUNIT_ASSERT(f2->getArray()!=f5->getArray());
1712 CPPUNIT_ASSERT(f5->getTypeOfField()==ON_NODES);
1713 CPPUNIT_ASSERT(f5->getTimeDiscretization()==ONE_TIME);
1715 tmp=f3->getArray()->getConstPointer();
1716 double values5[9]={-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8};
1717 std::transform(tmp,tmp+9,values5,values5,std::minus<double>());
1718 std::transform(values5,values5+9,values5,std::ptr_fun<double,double>(fabs));
1719 max=*std::max_element(values5,values5+9);
1720 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1730 void MEDCouplingBasicsTest1::testOperationsOnFields2()
1732 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1733 m->setTime(3.4,5,6); m->setTimeUnit("us");
1735 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,1,"x+y+z");
1736 MEDCouplingFieldDouble *f2=m->fillFromAnalytic(ON_NODES,1,"a*a+b+c*c");
1737 MEDCouplingFieldDouble *f3=(*f1)/(*f2);
1738 f3->checkConsistencyLight();
1739 CPPUNIT_ASSERT(f3->getTypeOfField()==ON_NODES);
1740 CPPUNIT_ASSERT(f3->getTimeDiscretization()==ONE_TIME);
1741 const double expected1[9]={-2.4999999999999991, 1.2162162162162162, 0.77868852459016391,
1742 0.7407407407407407, 1.129032258064516, 0.81632653061224492,
1743 0.86538461538461531, 1.0919540229885056, 0.84302325581395343};
1744 CPPUNIT_ASSERT_EQUAL(1,(int)f3->getNumberOfComponents());
1745 CPPUNIT_ASSERT_EQUAL(9,(int)f3->getNumberOfTuples());
1746 const double *val=f3->getArray()->getConstPointer();
1747 for(int i=0;i<9;i++)
1748 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1.e-12);
1753 f1=m->buildOrthogonalField();
1754 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.4,f1->getTime(a,b),1.e-14);
1755 CPPUNIT_ASSERT_EQUAL(5,a); CPPUNIT_ASSERT_EQUAL(6,b);
1756 CPPUNIT_ASSERT_EQUAL(std::string(f1->getTimeUnit()),std::string("us"));
1757 f2=m->fillFromAnalytic(ON_CELLS,1,"x");
1759 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};
1760 val=f3->getArray()->getConstPointer();
1761 for(int i=0;i<15;i++)
1762 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1.e-12);
1766 val=f3->getArray()->getConstPointer();
1767 for(int i=0;i<15;i++)
1768 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1.e-12);
1777 void MEDCouplingBasicsTest1::testOperationsOnFields3()
1779 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1780 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,1,"x+y+z");
1781 MEDCouplingFieldDouble *f2=m->fillFromAnalytic(ON_NODES,1,"a*a+b+c*c");
1783 f1->checkConsistencyLight();
1784 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1785 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1786 const double expected1[9]={-2.4999999999999991, 1.2162162162162162, 0.77868852459016391,
1787 0.7407407407407407, 1.129032258064516, 0.81632653061224492,
1788 0.86538461538461531, 1.0919540229885056, 0.84302325581395343};
1789 CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1790 CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1791 const double *val=f1->getArray()->getConstPointer();
1792 for(int i=0;i<9;i++)
1793 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1.e-12);
1797 f1=m->buildOrthogonalField();
1798 f2=m->fillFromAnalytic(ON_CELLS,1,"x");
1800 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};
1801 val=f1->getArray()->getConstPointer();
1802 for(int i=0;i<15;i++)
1803 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1.e-12);
1806 f1=m->buildOrthogonalField();
1807 CPPUNIT_ASSERT_THROW((*f2)*=(*f1),INTERP_KERNEL::Exception);
1815 * Check of LINEAR_TIME and CONST_ON_TIME_INTERVAL policies
1817 void MEDCouplingBasicsTest1::testOperationsOnFields4()
1819 MEDCouplingUMesh *m=build2DTargetMesh_1();
1820 int nbOfCells=m->getNumberOfCells();
1821 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,CONST_ON_TIME_INTERVAL);
1823 DataArrayDouble *array=DataArrayDouble::New();
1824 array->alloc(nbOfCells,3);
1825 f1->setArray(array);
1826 CPPUNIT_ASSERT_THROW(f1->setEndArray(array),INTERP_KERNEL::Exception);
1827 CPPUNIT_ASSERT_THROW(f1->getEndArray(),INTERP_KERNEL::Exception);
1829 double *tmp=array->getPointer();
1830 const double arr1[15]={0.,10.,20.,1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.};
1831 const double arr2[15]={5.,15.,25.,6.,16.,26.,7.,17.,27.,8.,18.,28.,9.,19.,29.};
1832 std::copy(arr1,arr1+15,tmp);
1833 f1->setStartTime(2.,0,0);
1834 f1->setEndTime(3.,0,0);
1835 f1->checkConsistencyLight();
1837 const double pos[2]={0.3,-0.2};
1838 f1->getValueOn(pos,res);
1839 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[3],res[0],1.e-12);
1840 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[4],res[1],1.e-12);
1841 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[5],res[2],1.e-12);
1842 std::fill(res,res+3,0.);
1843 f1->getValueOn(pos,2.2,res);
1844 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[3],res[0],1.e-12);
1845 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[4],res[1],1.e-12);
1846 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[5],res[2],1.e-12);
1847 std::fill(res,res+3,0.);
1848 CPPUNIT_ASSERT_THROW(f1->getValueOn(pos,3.2,res),INTERP_KERNEL::Exception);
1849 MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
1851 f2->setArray(f1->getArray());
1852 f2->setStartTime(2.,3,0);
1853 f2->setEndTime(4.,13,0);
1854 CPPUNIT_ASSERT_THROW(f2->checkConsistencyLight(),INTERP_KERNEL::Exception);
1855 DataArrayDouble *array2=DataArrayDouble::New();
1856 array2->alloc(nbOfCells,3);
1857 tmp=array2->getPointer();
1858 std::copy(arr2,arr2+15,tmp);
1859 f2->setEndArray(array2);
1861 f2->checkConsistencyLight();
1863 std::fill(res,res+3,0.);
1864 f2->getValueOn(pos,3.21,res);
1865 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.025,res[0],1.e-12);
1866 CPPUNIT_ASSERT_DOUBLES_EQUAL(14.025,res[1],1.e-12);
1867 CPPUNIT_ASSERT_DOUBLES_EQUAL(24.025,res[2],1.e-12);
1868 MEDCouplingFieldDouble *f3=f2->clone(true);
1869 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-12));
1870 f3->getEndArray()->getPointer()[0]=5.001;
1871 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-12));
1872 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1873 f3->setStartTime(2.1,3,0);
1874 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1875 f3->setStartTime(2.,3,0);
1876 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1877 f3->setStartTime(2.,4,0);
1878 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1879 f3->setStartTime(2.,3,1);
1880 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1881 f3->setStartTime(2.,3,0);
1882 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1883 f3->setEndTime(4.1,13,0);
1884 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1885 f3->setEndTime(4.,13,0);
1886 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1887 f3->setEndTime(4.,14,0);
1888 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1889 f3->setEndTime(4.,13,1);
1890 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1891 f3->setEndTime(4.,13,0);
1892 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1894 MEDCouplingFieldDouble *f4=(*f2)+(*f2);
1895 std::fill(res,res+3,0.);
1896 f4->getValueOn(pos,3.21,res);
1897 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.05,res[0],1.e-12);
1898 CPPUNIT_ASSERT_DOUBLES_EQUAL(28.05,res[1],1.e-12);
1899 CPPUNIT_ASSERT_DOUBLES_EQUAL(48.05,res[2],1.e-12);
1901 std::fill(res,res+3,0.);
1902 f4->getValueOn(pos,3.21,res);
1903 CPPUNIT_ASSERT_DOUBLES_EQUAL(12.075,res[0],1.e-12);
1904 CPPUNIT_ASSERT_DOUBLES_EQUAL(42.075,res[1],1.e-12);
1905 CPPUNIT_ASSERT_DOUBLES_EQUAL(72.075,res[2],1.e-12);
1913 bool func4(const double *pt, double *res)
1915 res[0]=pt[0]+pt[1]+pt[2];
1919 void MEDCouplingBasicsTest1::testMergeNodesOnField()
1922 MEDCouplingUMesh *targetMesh=build3DTargetMeshMergeNode_1();
1923 MEDCouplingFieldDouble *f1=targetMesh->fillFromAnalytic(ON_NODES,1,func4);
1924 f1->mergeNodes(1e-10);
1926 targetMesh->decrRef();
1928 targetMesh=build3DTargetMeshMergeNode_1();
1929 f1=targetMesh->fillFromAnalytic(ON_NODES,1,func4);
1930 tmp=f1->getArray()->getPointer();
1932 f1->mergeNodes(1e-10);
1934 targetMesh->decrRef();
1936 targetMesh=build3DTargetMeshMergeNode_1();
1937 f1=targetMesh->fillFromAnalytic(ON_NODES,1,func4);
1938 tmp=f1->getArray()->getPointer();
1940 CPPUNIT_ASSERT_THROW(f1->mergeNodes(1e-10),INTERP_KERNEL::Exception);
1942 targetMesh->decrRef();
1945 void MEDCouplingBasicsTest1::testCheckConsecutiveCellTypes()
1947 MEDCouplingUMesh *sourceMesh=build2DSourceMesh_1();
1948 MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
1949 CPPUNIT_ASSERT(sourceMesh->checkConsecutiveCellTypes());
1950 const INTERP_KERNEL::NormalizedCellType order1[]={INTERP_KERNEL::NORM_TRI3, INTERP_KERNEL::NORM_QUAD4};
1951 const INTERP_KERNEL::NormalizedCellType order2[]={INTERP_KERNEL::NORM_QUAD4, INTERP_KERNEL::NORM_TRI3};
1952 CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypes());
1953 CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypesAndOrder(order1,order1+2));
1954 CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypesAndOrder(order2,order2+2));
1955 DataArrayInt *da=targetMesh->getRenumArrForConsecutiveCellTypesSpec(order1,order1+2);
1956 CPPUNIT_ASSERT_EQUAL(5,(int)da->getNumberOfTuples());
1957 CPPUNIT_ASSERT_EQUAL(1,(int)da->getNumberOfComponents());
1958 const int expected1[5]={2,0,1,3,4};
1959 CPPUNIT_ASSERT(std::equal(expected1,expected1+5,da->getConstPointer()));
1961 da=targetMesh->getRenumArrForConsecutiveCellTypesSpec(order2,order2+2);
1962 CPPUNIT_ASSERT_EQUAL(5,(int)da->getNumberOfTuples());
1963 CPPUNIT_ASSERT_EQUAL(1,(int)da->getNumberOfComponents());
1964 const int expected2[5]={0,3,4,1,2};
1965 CPPUNIT_ASSERT(std::equal(expected2,expected2+5,da->getConstPointer()));
1967 const int renumber1[5]={4,0,1,2,3};
1968 targetMesh->renumberCells(renumber1,false);
1969 CPPUNIT_ASSERT(targetMesh->checkConsecutiveCellTypes());
1970 CPPUNIT_ASSERT(targetMesh->checkConsecutiveCellTypesAndOrder(order1,order1+2));
1971 CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypesAndOrder(order2,order2+2));
1972 targetMesh->decrRef();
1973 sourceMesh->decrRef();
1976 void MEDCouplingBasicsTest1::testRearrange2ConsecutiveCellTypes()
1978 MEDCouplingUMesh *m1_1=build2DSourceMesh_1();
1979 MEDCouplingUMesh *m2_1=build2DTargetMesh_1();
1980 DataArrayInt *arr1=m1_1->rearrange2ConsecutiveCellTypes();
1981 MEDCouplingUMesh *m1_2=build2DSourceMesh_1();
1982 CPPUNIT_ASSERT(m1_2->isEqual(m1_1,1e-12));
1983 const int expected1[2]={0,1};
1984 CPPUNIT_ASSERT_EQUAL(2,(int)arr1->getNumberOfTuples());
1985 CPPUNIT_ASSERT_EQUAL(1,(int)arr1->getNumberOfComponents());
1986 CPPUNIT_ASSERT(std::equal(expected1,expected1+2,arr1->getConstPointer()));
1988 const int expected2[5]={0,3,4,1,2};
1989 arr1=m2_1->rearrange2ConsecutiveCellTypes();
1990 CPPUNIT_ASSERT_EQUAL(5,(int)arr1->getNumberOfTuples());
1991 CPPUNIT_ASSERT_EQUAL(1,(int)arr1->getNumberOfComponents());
1992 CPPUNIT_ASSERT(std::equal(expected2,expected2+5,arr1->getConstPointer()));
1993 MEDCouplingUMesh *m2_2=build2DTargetMesh_1();
1994 CPPUNIT_ASSERT_EQUAL(5,(int)arr1->getNumberOfTuples());
1995 CPPUNIT_ASSERT_EQUAL(1,(int)arr1->getNumberOfComponents());
1996 CPPUNIT_ASSERT(std::equal(expected2,expected2+5,arr1->getConstPointer()));
1997 CPPUNIT_ASSERT(!m2_2->isEqual(m2_1,1e-12));
1998 m2_2->renumberCells(expected2,false);
1999 CPPUNIT_ASSERT(m2_2->isEqual(m2_1,1e-12));
2007 void MEDCouplingBasicsTest1::testSplitByType()
2009 MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
2010 std::vector<MEDCouplingUMesh *> v=m1->splitByType();
2011 CPPUNIT_ASSERT_EQUAL(3,(int)v.size());
2012 std::vector<const MEDCouplingUMesh *> v2(v.begin(),v.end());
2013 MEDCouplingUMesh *m2=MEDCouplingUMesh::MergeUMeshesOnSameCoords(v2);
2014 m2->setName(m1->getName().c_str());
2015 CPPUNIT_ASSERT(m1->isEqual(m2,1.e-12));
2016 for(std::vector<MEDCouplingUMesh *>::const_iterator iter=v.begin();iter!=v.end();iter++)
2022 void MEDCouplingBasicsTest1::testFuseUMeshesOnSameCoords()
2024 std::vector<const MEDCouplingUMesh *> meshes;
2025 MEDCouplingUMesh *m2=build2DTargetMesh_1();
2026 int cells1[3]={2,3,4};
2027 MEDCouplingPointSet *m3_1=m2->buildPartOfMySelf(cells1,cells1+3,true);
2028 MEDCouplingUMesh *m3=dynamic_cast<MEDCouplingUMesh *>(m3_1);
2030 meshes.push_back(m3);
2031 int cells2[3]={1,2,4};
2032 MEDCouplingPointSet *m4_1=m2->buildPartOfMySelf(cells2,cells2+3,true);
2033 MEDCouplingUMesh *m4=dynamic_cast<MEDCouplingUMesh *>(m4_1);
2035 meshes.push_back(m4);
2036 int cells3[2]={1,2};
2037 MEDCouplingPointSet *m5_1=m2->buildPartOfMySelf(cells3,cells3+2,true);
2038 MEDCouplingUMesh *m5=dynamic_cast<MEDCouplingUMesh *>(m5_1);
2040 meshes.push_back(m5);
2043 std::vector<DataArrayInt *> corr;
2044 MEDCouplingUMesh *m7=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
2045 CPPUNIT_ASSERT_EQUAL(4,(int)m7->getNumberOfCells());
2046 CPPUNIT_ASSERT_EQUAL(3,(int)corr.size());
2047 const int expectedVals1[3]={3,3,2};
2048 const int expectedVals2[3][3]={{0,1,2},{3,0,2},{3,0,111111}};
2049 for(int i=0;i<3;i++)
2051 DataArrayInt *arr=corr[i];
2052 CPPUNIT_ASSERT_EQUAL(1,(int)arr->getNumberOfComponents());
2053 int nbOfVals=expectedVals1[i];
2054 CPPUNIT_ASSERT_EQUAL(nbOfVals,(int)arr->getNumberOfTuples());
2055 const int *vals=arr->getConstPointer();
2056 for(int j=0;j<nbOfVals;j++)
2057 CPPUNIT_ASSERT_EQUAL(expectedVals2[i][j],vals[j]);
2059 std::vector< std::vector<int> > fidsOfGroups;
2060 std::vector<const DataArrayInt *> corr2(corr.begin(),corr.end());
2061 DataArrayInt *arr2=DataArrayInt::MakePartition(corr2,m7->getNumberOfCells(),fidsOfGroups);
2062 const int fidExp[4]={5,1,3,4};
2063 const int fidsGrp[3][3]={{1,3,5},{3,4,5},{4,5,23344}};
2064 CPPUNIT_ASSERT_EQUAL(3,(int)fidsOfGroups.size());
2065 CPPUNIT_ASSERT_EQUAL(1,(int)arr2->getNumberOfComponents());
2066 CPPUNIT_ASSERT_EQUAL(4,(int)arr2->getNumberOfTuples());
2067 CPPUNIT_ASSERT(std::equal(fidExp,fidExp+4,arr2->getConstPointer()));
2068 for(int i=0;i<3;i++)
2070 int nbOfVals=expectedVals1[i];
2071 CPPUNIT_ASSERT_EQUAL(nbOfVals,(int)fidsOfGroups[i].size());
2072 CPPUNIT_ASSERT(std::equal(fidsOfGroups[i].begin(),fidsOfGroups[i].end(),fidsGrp[i]));
2074 for(std::vector<DataArrayInt *>::iterator iter=corr.begin();iter!=corr.end();iter++)
2084 void MEDCouplingBasicsTest1::testFuseUMeshesOnSameCoords2()
2086 MEDCouplingUMesh *m2;
2087 MEDCouplingUMesh *m1=build3DExtrudedUMesh_1(m2);
2089 const int part1[5]={2,3,6,4,10};
2090 MEDCouplingUMesh *m3=(MEDCouplingUMesh *)m1->buildPartOfMySelf(part1,part1+5,true);
2091 const int part2[4]={5,6,4,7};
2092 MEDCouplingUMesh *m4=(MEDCouplingUMesh *)m1->buildPartOfMySelf(part2,part2+4,true);
2093 std::vector<const MEDCouplingUMesh *> meshes;
2094 meshes.push_back(m1);
2095 meshes.push_back(m3);
2096 meshes.push_back(m3);
2097 meshes.push_back(m4);
2098 std::vector<DataArrayInt *> corr;
2099 MEDCouplingUMesh *m5=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
2100 CPPUNIT_ASSERT_EQUAL(18,(int)m5->getNumberOfCells());
2101 std::vector<DataArrayInt *>::iterator it=corr.begin();
2102 const int exp1[4]={18,5,5,4};
2103 const int exp2[4][18]={
2104 {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17},
2105 {2,3,6,4,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
2106 {2,3,6,4,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
2107 {5,6,4,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}
2110 for(;it!=corr.end();it++,i++)
2112 int sz=(*it)->getNumberOfTuples();
2113 CPPUNIT_ASSERT_EQUAL(exp1[i],sz);
2114 CPPUNIT_ASSERT(std::equal(exp2[i],exp2[i]+sz,(*it)->getConstPointer()));
2116 for(it=corr.begin();it!=corr.end();it++)
2124 void MEDCouplingBasicsTest1::testBuildOrthogonalField()
2126 MEDCouplingUMesh *targetMesh=build3DSurfTargetMesh_1();
2127 MEDCouplingFieldDouble *field=targetMesh->buildOrthogonalField();
2128 double expected[3]={0.70710678118654746,0.,-0.70710678118654746};
2129 CPPUNIT_ASSERT_EQUAL(5,(int)field->getNumberOfTuples());
2130 CPPUNIT_ASSERT_EQUAL(3,(int)field->getNumberOfComponents());
2131 const double *vals=field->getArray()->getConstPointer();
2132 for(int i=0;i<15;i++)
2133 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected[i%3],vals[i],1e-12);
2135 targetMesh->decrRef();
2137 double targetCoords[12]={0.,0.,0.,0.5,0.,0.5,1.,0.,1.,0.,1.,0.};
2138 int targetConn[4]={0,1,2,3};
2139 targetMesh=MEDCouplingUMesh::New();
2140 targetMesh->setMeshDimension(2);
2141 targetMesh->allocateCells(1);
2142 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn);
2143 targetMesh->finishInsertingCells();
2144 DataArrayDouble *myCoords=DataArrayDouble::New();
2145 myCoords->alloc(4,3);
2146 std::copy(targetCoords,targetCoords+12,myCoords->getPointer());
2147 targetMesh->setCoords(myCoords);
2148 myCoords->decrRef();
2149 field=targetMesh->buildOrthogonalField();
2150 CPPUNIT_ASSERT_EQUAL(1,(int)field->getNumberOfTuples());
2151 CPPUNIT_ASSERT_EQUAL(3,(int)field->getNumberOfComponents());
2152 vals=field->getArray()->getConstPointer();
2153 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.70710678118654746,vals[0],1e-12);
2154 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,vals[1],1e-12);
2155 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.70710678118654746,vals[2],1e-12);
2157 targetMesh->decrRef();
2160 void MEDCouplingBasicsTest1::testGetCellsContainingPoint()
2162 MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
2163 double pos[12]={0.,0.,0.4,0.4,0.,0.4,0.1,0.1,0.25,0.,0.65,0.};
2164 MCAuto<DataArrayInt> t1,t2;
2166 targetMesh->getCellsContainingPoints(pos,6,1e-12,t1,t2);
2167 CPPUNIT_ASSERT_EQUAL(6,(int)t1->getNbOfElems());
2168 CPPUNIT_ASSERT_EQUAL(7,(int)t2->getNbOfElems());
2169 const int expectedValues1[6]={0,4,3,0,1,2};
2170 const int expectedValues2[7]={0,1,2,3,4,5,6};
2171 CPPUNIT_ASSERT(std::equal(t1->begin(),t1->end(),expectedValues1));
2172 CPPUNIT_ASSERT(std::equal(t2->begin(),t2->end(),expectedValues2));
2173 //2D with no help of bounding box.
2174 double center[2]={0.2,0.2};
2175 DataArrayDouble::Rotate2DAlg(center,0.78539816339744830962,6,pos,pos);
2176 targetMesh->rotate(center,0,0.78539816339744830962);
2177 targetMesh->getCellsContainingPoints(pos,6,1e-12,t1,t2);
2178 CPPUNIT_ASSERT_EQUAL(6,(int)t1->getNbOfElems());
2179 CPPUNIT_ASSERT_EQUAL(7,(int)t2->getNbOfElems());
2180 CPPUNIT_ASSERT(std::equal(t1->begin(),t1->end(),expectedValues1));
2181 CPPUNIT_ASSERT(std::equal(t2->begin(),t2->end(),expectedValues2));
2183 const double pos1bis[2]={-0.3303300858899107,-0.11819805153394641};
2184 CPPUNIT_ASSERT_EQUAL(-1,targetMesh->getCellContainingPoint(pos1bis,1e-12));
2185 targetMesh->decrRef();
2187 targetMesh=build2DTargetMesh_1();
2188 const double pos2[2]={0.2,-0.05};
2189 std::vector<int> t11;
2191 targetMesh->getCellsContainingPoint(pos2,1e-12,t11);
2192 CPPUNIT_ASSERT_EQUAL(2,(int)t11.size());
2193 const int expectedValues3[2]={0,1};
2194 CPPUNIT_ASSERT(std::equal(t11.begin(),t11.end(),expectedValues3));
2195 const double pos3[2]={0.2,0.2};
2197 targetMesh->getCellsContainingPoint(pos3,1e-12,t11);
2198 CPPUNIT_ASSERT_EQUAL(5,(int)t11.size());
2199 const int expectedValues4[5]={0,1,2,3,4};
2200 CPPUNIT_ASSERT(std::equal(t11.begin(),t11.end(),expectedValues4));
2201 CPPUNIT_ASSERT_EQUAL(0,targetMesh->getCellContainingPoint(pos3,1e-12));
2202 targetMesh->decrRef();
2204 targetMesh=build3DTargetMesh_1();
2205 const double pos4[3]={25.,25.,25.};
2206 CPPUNIT_ASSERT_EQUAL(0,targetMesh->getCellContainingPoint(pos4,1e-12));
2207 const double pos5[3]={50.,50.,50.};
2209 targetMesh->getCellsContainingPoint(pos5,1e-12,t11);
2210 CPPUNIT_ASSERT_EQUAL(8,(int)t11.size());
2211 const int expectedValues5[8]={0,1,2,3,4,5,6,7};
2212 CPPUNIT_ASSERT(std::equal(t11.begin(),t11.end(),expectedValues5));
2213 const double pos6[3]={0., 50., 0.};
2215 targetMesh->getCellsContainingPoint(pos6,1e-12,t11);
2216 CPPUNIT_ASSERT_EQUAL(2,(int)t11.size());
2217 const int expectedValues6[2]={0,2};
2218 CPPUNIT_ASSERT(std::equal(t11.begin(),t11.end(),expectedValues6));
2220 const double pos7[3]={-1.0,-1.0,0.};
2221 CPPUNIT_ASSERT_EQUAL(-1,targetMesh->getCellContainingPoint(pos7,1e-12));
2223 const double center2[3]={0.,0.,0.};
2224 const double vec2[3]={0.,-1.,0.};
2225 targetMesh->rotate(center2,vec2,0.78539816339744830962);
2226 const double pos8[3]={-25,25.,12.};
2227 CPPUNIT_ASSERT_EQUAL(-1,targetMesh->getCellContainingPoint(pos8,1e-12));
2229 targetMesh->decrRef();
2232 void MEDCouplingBasicsTest1::testGetValueOn1()
2234 MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
2235 MEDCouplingFieldDouble *fieldOnCells=MEDCouplingFieldDouble::New(ON_CELLS);
2236 int nbOfCells=targetMesh->getNumberOfCells();
2237 fieldOnCells->setMesh(targetMesh);
2238 DataArrayDouble *array=DataArrayDouble::New();
2239 array->alloc(nbOfCells,2);
2240 fieldOnCells->setArray(array);
2241 double *tmp=array->getPointer();
2242 for(int i=0;i<nbOfCells;i++)
2243 { tmp[2*i]=7.+(double)i; tmp[2*i+1]=17.+(double)i; }
2246 const double pos1[2]={0.25,0.};
2248 fieldOnCells->getValueOn(pos1,res);
2249 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.,res[0],1e-12);
2250 CPPUNIT_ASSERT_DOUBLES_EQUAL(18.,res[1],1e-12);
2252 fieldOnCells->decrRef();
2253 targetMesh->decrRef();
2255 targetMesh=build2DSourceMesh_1();
2256 MEDCouplingFieldDouble *fieldOnNodes=MEDCouplingFieldDouble::New(ON_NODES);
2257 int nbOfNodes=targetMesh->getNumberOfNodes();
2258 fieldOnNodes->setMesh(targetMesh);
2259 array=DataArrayDouble::New();
2260 array->alloc(nbOfNodes,2);
2261 fieldOnNodes->setArray(array);
2262 tmp=array->getPointer();
2263 for(int i=0;i<nbOfNodes;i++)
2264 { tmp[2*i]=17.+(double)i; tmp[2*i+1]=27.+(double)i; }
2267 const double pos2[2]={-0.13333333333333333,-0.13333333333333333};
2268 fieldOnNodes->getValueOn(pos2,res);
2269 CPPUNIT_ASSERT_DOUBLES_EQUAL(17.5,res[0],1e-12);
2270 CPPUNIT_ASSERT_DOUBLES_EQUAL(27.5,res[1],1e-12);
2271 const double pos3[2]={0.033333333333333326,0.36666666666666664};
2272 fieldOnNodes->getValueOn(pos3,res);
2273 CPPUNIT_ASSERT_DOUBLES_EQUAL(18.666666666666667,res[0],1e-12);
2274 CPPUNIT_ASSERT_DOUBLES_EQUAL(28.666666666666667,res[1],1e-12);
2276 fieldOnNodes->decrRef();
2277 targetMesh->decrRef();
2280 void MEDCouplingBasicsTest1::testCMesh0()
2282 MEDCouplingCMesh* mesh=MEDCouplingCMesh::New();
2283 MEDCouplingCMesh* meshEmpty=mesh->clone(true);
2284 CPPUNIT_ASSERT(meshEmpty->isEqual(mesh,1e-12));
2286 DataArrayDouble* coordsX=DataArrayDouble::New();
2287 double arrX[4] = { -1., 1., 2., 4. };
2288 coordsX->useArray(arrX,false, DeallocType::CPP_DEALLOC,4,1);
2289 DataArrayDouble* coordsY=DataArrayDouble::New();
2290 double arrY[4] = { -2., 2., 4., 8. };
2291 coordsY->useArray(arrY,false, DeallocType::CPP_DEALLOC,4,1);
2292 DataArrayDouble* coordsZ=DataArrayDouble::New();
2293 double arrZ[4] = { -3., 3., 6., 12. };
2294 coordsZ->useArray(arrZ,false, DeallocType::CPP_DEALLOC,4,1);
2295 mesh->setCoords(coordsX,coordsY,coordsZ);
2300 MEDCouplingFieldDouble *fieldOnNodes=mesh->fillFromAnalytic(ON_NODES,1,"x+y/2.+z/3.");
2301 CPPUNIT_ASSERT_EQUAL(1,(int)fieldOnNodes->getNumberOfComponents());
2302 CPPUNIT_ASSERT_EQUAL(64,(int)fieldOnNodes->getNumberOfTuples());
2303 const double expected1[64]={-3., -1., 0., 2., -1., 1., 2., 4., 0., 2., 3., 5., 2., 4., 5., 7., -1., 1., 2.,
2304 4., 1., 3., 4., 6., 2., 4., 5., 7., 4., 6., 7., 9., 0., 2., 3., 5., 2., 4., 5.,
2305 7., 3., 5., 6., 8., 5., 7., 8., 10., 2., 4., 5.,
2306 7., 4., 6., 7., 9., 5., 7., 8., 10., 7., 9., 10., 12.};
2307 const double *val=fieldOnNodes->getArray()->getConstPointer();
2308 for(int i=0;i<64;i++)
2309 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1e-12);
2310 double res[1]; //size fieldOnNodes->getNumberOfComponents()
2311 fieldOnNodes->getValueOnPos(1,3,2,&res[0]);
2312 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,res[0],1e-12);
2313 fieldOnNodes->decrRef();
2315 MEDCouplingFieldDouble *fieldOnCells=mesh->fillFromAnalytic(ON_CELLS,1,"x+y/2.+z/3.");
2316 CPPUNIT_ASSERT_EQUAL(1,(int)fieldOnCells->getNumberOfComponents());
2317 CPPUNIT_ASSERT_EQUAL(27,(int)fieldOnCells->getNumberOfTuples());
2318 val=fieldOnCells->getArray()->getConstPointer();
2319 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,
2320 6, 4.5, 6, 7.5, 3, 4.5, 6, 4.5, 6, 7.5, 6, 7.5, 9};
2321 for(int i=0;i<27;i++)
2322 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1e-12);
2323 fieldOnCells->getValueOnPos(1,2,1,&res[0]);
2324 CPPUNIT_ASSERT_DOUBLES_EQUAL(6.,res[0],1e-12);
2325 fieldOnCells->decrRef();
2327 MEDCouplingMesh* meshDeepCopy=mesh->deepCopy();
2328 MEDCouplingCMesh* meshClone=mesh->clone(false);
2330 CPPUNIT_ASSERT_THROW(meshEmpty->copyTinyStringsFrom(0),INTERP_KERNEL::Exception);
2331 meshEmpty->copyTinyStringsFrom(mesh);
2332 //no data in meshEmpty, expected false
2333 CPPUNIT_ASSERT(!meshEmpty->isEqual(mesh,1e-12));
2335 CPPUNIT_ASSERT(meshDeepCopy->isEqual(mesh,1e-12));
2336 meshDeepCopy->copyTinyStringsFrom(mesh);
2337 CPPUNIT_ASSERT(meshDeepCopy->isEqual(mesh,1e-12));
2338 CPPUNIT_ASSERT(meshClone->isEqual(mesh,1e-12));
2340 CPPUNIT_ASSERT_EQUAL(CARTESIAN,mesh->getType());
2341 CPPUNIT_ASSERT_EQUAL(CARTESIAN,meshEmpty->getType());
2342 CPPUNIT_ASSERT_EQUAL(CARTESIAN,meshDeepCopy->getType());
2343 CPPUNIT_ASSERT_EQUAL(CARTESIAN,meshClone->getType());
2346 meshEmpty->decrRef();
2347 meshDeepCopy->decrRef();
2348 meshClone->decrRef();
2351 void MEDCouplingBasicsTest1::testCMesh1()
2353 MEDCouplingCMesh *mesh1,*mesh2,*mesh3;
2354 mesh1=MEDCouplingCMesh::New();
2355 DataArrayDouble* coordsX1=DataArrayDouble::New();
2356 double arrX1[4] = { -1., 1., 2., 4. };
2357 coordsX1->useArray(arrX1,false, DeallocType::CPP_DEALLOC,4,1);
2358 DataArrayDouble* coordsY1=DataArrayDouble::New();
2359 double arrY1[4] = { -2., 2., 4., 8. };
2360 coordsY1->useArray(arrY1,false, DeallocType::CPP_DEALLOC,4,1);
2361 DataArrayDouble* coordsZ1=DataArrayDouble::New();
2362 double arrZ1[4] = { -3., 3., 6., 12. };
2363 coordsZ1->useArray(arrZ1,false, DeallocType::CPP_DEALLOC,4,1);
2364 mesh1->setCoords(coordsX1,coordsY1,coordsZ1);
2366 mesh2=MEDCouplingCMesh::New();
2367 DataArrayDouble* coordsX2=DataArrayDouble::New();
2368 double arrX2[4] = { -1., 1., 2., 4. };
2369 coordsX2->useArray(arrX2,false, DeallocType::CPP_DEALLOC,4,1);
2370 DataArrayDouble* coordsY2=DataArrayDouble::New();
2371 double arrY2[4] = { -2., 2., 4., 8. };
2372 coordsY2->useArray(arrY2,false, DeallocType::CPP_DEALLOC,4,1);
2373 DataArrayDouble* coordsZ2=DataArrayDouble::New();
2374 double arrZ2[4] = { -3., 3., 6., 12.+1e-6 }; //here is not equal
2375 coordsZ2->useArray(arrZ2,false, DeallocType::CPP_DEALLOC,4,1);
2376 mesh2->setCoords(coordsX2,coordsY2,coordsZ2);
2378 mesh3=MEDCouplingCMesh::New();
2379 DataArrayDouble* coordsX3=DataArrayDouble::New();
2380 double arrX3[1] = { -1.};
2381 coordsX3->useArray(arrX3,false, DeallocType::CPP_DEALLOC,1,1);
2382 DataArrayDouble* coordsY3=DataArrayDouble::New();
2383 double arrY3[1] = { -2.};
2384 coordsY3->useArray(arrY3,false, DeallocType::CPP_DEALLOC,1,1);
2385 DataArrayDouble* coordsZ3=DataArrayDouble::New();
2386 double arrZ3[1] = { -3.};
2387 coordsZ3->useArray(arrZ3,false, DeallocType::CPP_DEALLOC,1,1);
2388 mesh3->setCoords(coordsX3,coordsY3,coordsZ3);
2390 CPPUNIT_ASSERT_EQUAL(3,mesh1->getSpaceDimension());
2391 CPPUNIT_ASSERT_EQUAL(3,mesh1->getMeshDimension());
2393 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
2394 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
2395 CPPUNIT_ASSERT(!mesh2->isEqualWithoutConsideringStr(mesh1,1e-12));
2396 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-5));
2397 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-7));
2399 CPPUNIT_ASSERT_THROW(mesh3->checkConsistency(1e-12),INTERP_KERNEL::Exception);
2400 mesh1->checkConsistency(1e-12);
2401 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh1->getTypeOfCell(1));
2403 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,*((mesh1->getAllGeoTypes()).begin()));
2404 CPPUNIT_ASSERT_EQUAL(27,(int)mesh1->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2405 CPPUNIT_ASSERT_THROW(mesh1->getNumberOfCellsWithType(INTERP_KERNEL::NORM_QUAD4),INTERP_KERNEL::Exception);
2407 std::vector<double> coo;
2408 mesh1->getCoordinatesOfNode(0, coo);
2409 CPPUNIT_ASSERT_EQUAL(3,(int) coo.size());
2410 CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.,coo[0],1e-14);
2411 CPPUNIT_ASSERT_DOUBLES_EQUAL(-2.,coo[1],1e-14);
2412 CPPUNIT_ASSERT_DOUBLES_EQUAL(-3.,coo[2],1e-14);
2414 mesh1->getCoordinatesOfNode(63, coo);
2415 CPPUNIT_ASSERT_EQUAL(3,(int) coo.size());
2416 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.,coo[0],1e-14);
2417 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.,coo[1],1e-14);
2418 CPPUNIT_ASSERT_DOUBLES_EQUAL(12.,coo[2],1e-14);
2421 repr=mesh1->simpleRepr();
2422 repr=mesh1->advancedRepr();
2423 CPPUNIT_ASSERT(!(repr.find("Cartesian")==std::string::npos));
2424 CPPUNIT_ASSERT(!(repr.find("Number of components : 1")==std::string::npos));
2425 CPPUNIT_ASSERT(!(repr.find("Number of tuples : 4")==std::string::npos));
2426 CPPUNIT_ASSERT(!(repr.find("Z Array :")==std::string::npos));
2427 coordsX1->decrRef();
2428 coordsY1->decrRef();
2429 coordsZ1->decrRef();
2430 coordsX2->decrRef();
2431 coordsY2->decrRef();
2432 coordsZ2->decrRef();
2433 coordsX3->decrRef();
2434 coordsY3->decrRef();
2435 coordsZ3->decrRef();
2441 void MEDCouplingBasicsTest1::testCMesh2()
2443 MEDCouplingCMesh *mesh1;
2444 mesh1=MEDCouplingCMesh::New();
2445 DataArrayDouble* coordsX1=DataArrayDouble::New();
2446 double arrX1[4] = { -1., 1., 2., 4. };
2447 coordsX1->useArray(arrX1,false, DeallocType::CPP_DEALLOC,4,1);
2448 DataArrayDouble* coordsY1=DataArrayDouble::New();
2449 double arrY1[4] = { -2., 2., 4., 8. };
2450 coordsY1->useArray(arrY1,false, DeallocType::CPP_DEALLOC,4,1);
2451 DataArrayDouble* coordsZ1=DataArrayDouble::New();
2452 double arrZ1[4] = { -3., 3., 6., 12. };
2453 coordsZ1->useArray(arrZ1,false, DeallocType::CPP_DEALLOC,4,1);
2454 mesh1->setCoords(coordsX1,coordsY1,coordsZ1);
2456 std::vector<int> dis=mesh1->getDistributionOfTypes();
2457 CPPUNIT_ASSERT_EQUAL(3,(int) dis.size());
2458 CPPUNIT_ASSERT_EQUAL((int) INTERP_KERNEL::NORM_HEXA8,dis[0]);
2459 CPPUNIT_ASSERT_EQUAL(27,dis[1]);
2460 CPPUNIT_ASSERT_EQUAL(-1,dis[2]);
2462 std::vector<const DataArrayInt *> idsPerType;
2463 CPPUNIT_ASSERT(!(mesh1->checkTypeConsistencyAndContig(dis, idsPerType)));
2464 dis[0]=(int) INTERP_KERNEL::NORM_QUAD4;
2465 CPPUNIT_ASSERT_THROW(mesh1->checkTypeConsistencyAndContig(dis, idsPerType),INTERP_KERNEL::Exception);
2467 dis[0]=(int) INTERP_KERNEL::NORM_HEXA8;
2469 DataArrayInt *ids=DataArrayInt::New();
2471 ids->fillWithValue(23);
2472 idsPerType.push_back(ids);
2473 DataArrayInt* check=mesh1->checkTypeConsistencyAndContig(dis, idsPerType);
2474 CPPUNIT_ASSERT(check);
2475 CPPUNIT_ASSERT(check->isEqual(*ids));
2477 std::vector<int> code;
2478 std::vector<DataArrayInt *> idsInPflPerType;
2479 std::vector<DataArrayInt *> pfls;
2480 mesh1->splitProfilePerType(ids,code,idsInPflPerType,pfls);
2481 CPPUNIT_ASSERT_EQUAL(3,(int)code.size());
2482 CPPUNIT_ASSERT_EQUAL((int) INTERP_KERNEL::NORM_HEXA8,code[0]);
2483 CPPUNIT_ASSERT_EQUAL(10,code[1]);
2484 CPPUNIT_ASSERT_EQUAL(0,code[2]);
2485 CPPUNIT_ASSERT_EQUAL(1,(int)idsInPflPerType.size());
2486 CPPUNIT_ASSERT_EQUAL(1,(int)pfls.size());
2487 DataArrayInt *exp=DataArrayInt::New(); exp->alloc(10,1); exp->iota(0);
2488 CPPUNIT_ASSERT(idsInPflPerType[0]->isEqual(*exp));
2490 CPPUNIT_ASSERT(pfls[0]->isEqual(*ids));
2491 idsInPflPerType[0]->decrRef();
2496 int cells1[4]={0,1,25,26};
2497 MEDCouplingUMesh *partMesh1=
2498 dynamic_cast<MEDCouplingUMesh *>(mesh1->buildPart(cells1,cells1+4));
2499 CPPUNIT_ASSERT(partMesh1);
2500 CPPUNIT_ASSERT_EQUAL(4,(int)partMesh1->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2501 CPPUNIT_ASSERT_EQUAL(64,mesh1->getNumberOfNodes());
2502 CPPUNIT_ASSERT_EQUAL(64,partMesh1->getNumberOfNodes());
2504 int cells2[2]={25,26};
2506 MEDCouplingCMesh *partMesh2=
2507 dynamic_cast<MEDCouplingCMesh *>(mesh1->buildPartAndReduceNodes(cells2,cells2+2,arr1));
2508 CPPUNIT_ASSERT(partMesh2);
2509 CPPUNIT_ASSERT_EQUAL(2,(int)partMesh2->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2510 CPPUNIT_ASSERT_EQUAL(12,partMesh2->getNumberOfNodes());
2512 int cells3[2]={2,3};
2514 MEDCouplingUMesh *partMesh3=
2515 dynamic_cast<MEDCouplingUMesh *>(partMesh1->buildPartAndReduceNodes(cells3,cells3+2,arr2));
2516 CPPUNIT_ASSERT(partMesh3);
2517 CPPUNIT_ASSERT_EQUAL(2,(int)partMesh3->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2518 CPPUNIT_ASSERT_EQUAL(12,partMesh3->getNumberOfNodes());
2520 CPPUNIT_ASSERT_THROW(mesh1->simplexize(0),INTERP_KERNEL::Exception);
2521 CPPUNIT_ASSERT_THROW(mesh1->getMeasureFieldOnNode(true),INTERP_KERNEL::Exception);
2525 mesh1->getBoundingBox(bbox1);
2526 partMesh1->getBoundingBox(bbox2);
2527 for(int i=0;i<6;i++)
2528 CPPUNIT_ASSERT_DOUBLES_EQUAL(bbox1[i],bbox2[i],1e-12);
2529 partMesh3->getBoundingBox(bbox1);
2530 partMesh2->getBoundingBox(bbox2);
2531 for(int i=0;i<6;i++)
2532 CPPUNIT_ASSERT_DOUBLES_EQUAL(bbox1[i],bbox2[i],1e-12);
2534 CPPUNIT_ASSERT_THROW(mesh1->buildOrthogonalField(),INTERP_KERNEL::Exception);
2535 MEDCouplingCMesh *mesh2d=MEDCouplingCMesh::New();
2536 mesh2d->setCoords(coordsX1,coordsY1);
2537 MEDCouplingFieldDouble *f1=mesh2d->buildOrthogonalField();
2539 std::vector<double> tinyInfoD;
2540 std::vector<int> tinyInfo;
2541 std::vector<std::string> littleStrings;
2542 mesh2d->getTinySerializationInformation(tinyInfoD, tinyInfo, littleStrings);
2543 CPPUNIT_ASSERT_EQUAL(5,(int)tinyInfo.size());
2544 CPPUNIT_ASSERT_EQUAL(4,(int)tinyInfo[0]); //x
2545 CPPUNIT_ASSERT_EQUAL(4,(int)tinyInfo[1]); //y
2546 CPPUNIT_ASSERT_EQUAL(-1,(int)tinyInfo[2]); //z
2547 CPPUNIT_ASSERT_EQUAL(-1,(int)tinyInfo[3]); //it
2548 CPPUNIT_ASSERT_EQUAL(-1,(int)tinyInfo[4]); //order
2549 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,tinyInfoD[0],1e-14); //time
2550 DataArrayInt* d1=DataArrayInt::New();
2551 DataArrayDouble* d2=DataArrayDouble::New();
2552 mesh2d->resizeForUnserialization(tinyInfo, d1, d2, littleStrings);
2553 CPPUNIT_ASSERT_EQUAL(0,(int)d1->getNumberOfTuples());
2554 CPPUNIT_ASSERT_EQUAL(8,(int)d2->getNumberOfTuples());
2556 partMesh1->decrRef();
2557 partMesh2->decrRef();
2558 partMesh3->decrRef();
2565 coordsX1->decrRef();
2566 coordsY1->decrRef();
2567 coordsZ1->decrRef();
2571 void MEDCouplingBasicsTest1::testScale()
2573 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
2574 const double pos[2]={0.2,0.2};
2575 mesh->scale(pos,0.5);
2576 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,
2577 -0.05,0.45, 0.2,0.45, 0.45,0.45};
2578 const double *val=mesh->getCoords()->getConstPointer();
2579 for(int i=0;i<18;i++)
2580 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1e-12);
2585 void MEDCouplingBasicsTest1::testTryToShareSameCoords()
2587 MEDCouplingUMesh *m1=build2DTargetMesh_1();
2588 MEDCouplingUMesh *m2=build2DTargetMesh_1();
2589 CPPUNIT_ASSERT(m1->getCoords()!=m2->getCoords());
2590 m1->tryToShareSameCoords(*m2,1e-12);
2591 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2592 m1->tryToShareSameCoords(*m2,1e-12);
2593 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2594 m2->tryToShareSameCoords(*m1,1e-12);
2595 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2599 m1=build2DTargetMesh_1();
2600 m2=build2DTargetMesh_2();
2601 CPPUNIT_ASSERT(m1->getCoords()!=m2->getCoords());
2602 m1->tryToShareSameCoords(*m2,1e-12);
2603 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2604 m1->tryToShareSameCoords(*m2,1e-12);
2605 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2606 m2->tryToShareSameCoords(*m1,1e-12);
2607 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2611 m1=build2DTargetMesh_1();
2612 m2=build2DSourceMesh_1();
2613 CPPUNIT_ASSERT(m1->getCoords()!=m2->getCoords());
2614 CPPUNIT_ASSERT_THROW(m1->tryToShareSameCoords(*m2,1e-12),INTERP_KERNEL::Exception);
2619 void MEDCouplingBasicsTest1::testFindNodeOnPlane()
2621 MEDCouplingUMesh *mesh=build3DTargetMesh_1();
2623 double pt[3]={300.,300.,0.};
2624 double v[3]={0.,0.,2.};
2625 mesh->findNodesOnPlane(pt,v,1e-12,n);
2626 CPPUNIT_ASSERT_EQUAL(9,(int)n.size());
2627 MEDCouplingUMesh *m3dSurf=(MEDCouplingUMesh *)mesh->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
2628 MEDCouplingMappedExtrudedMesh *me=MEDCouplingMappedExtrudedMesh::New(mesh,m3dSurf,0);
2629 const DataArrayInt *da=me->getMesh3DIds();
2630 CPPUNIT_ASSERT_EQUAL(8,(int)me->getNumberOfCells());
2631 const int expected[8]={0,1,2,3,4,5,6,7};
2632 const int *val=da->getConstPointer();
2633 for(int i=0;i<8;i++)
2634 CPPUNIT_ASSERT_EQUAL(expected[i],val[i]);
2640 void MEDCouplingBasicsTest1::testRenumberCells()
2642 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
2643 MEDCouplingUMesh *m2=build3DSurfTargetMesh_1();
2644 CPPUNIT_ASSERT(m->isEqual(m2,0));
2645 const int arr[5]={12,3,25,2,26};
2646 m->renumberCells(arr,true);
2647 CPPUNIT_ASSERT(!m->isEqual(m2,0));
2648 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(0));
2649 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(1));
2650 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(2));
2651 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(3));
2652 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(4));
2653 const int arr2[5]={5,-1,-5,4,8};
2654 m->renumberCells(arr2,true);
2655 CPPUNIT_ASSERT(m->isEqual(m2,0));
2660 void MEDCouplingBasicsTest1::testChangeSpaceDimension()
2662 MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
2663 MEDCouplingUMesh *m2=build2DTargetMesh_1();
2665 CPPUNIT_ASSERT_EQUAL(3,m1->getSpaceDimension());
2666 m1->changeSpaceDimension(2);
2667 CPPUNIT_ASSERT_EQUAL(2,m1->getSpaceDimension());
2668 m1->setName(m2->getName().c_str());
2669 CPPUNIT_ASSERT(m1->isEqual(m2,1e-12));
2670 m1->changeSpaceDimension(3);
2671 CPPUNIT_ASSERT_EQUAL(3,m1->getSpaceDimension());
2672 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.};
2673 const double *val=m1->getCoords()->getConstPointer();
2674 for(int i=0;i<27;i++)
2675 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected[i],val[i],1e-14);
2681 void MEDCouplingBasicsTest1::testSetConnectivity()
2683 MEDCouplingUMesh *m1 = build1DTargetMesh_1();
2685 DataArrayInt * conn = DataArrayInt::New();
2686 DataArrayInt * connI = DataArrayInt::New();
2687 m1->setConnectivity(conn, connI, true); // was SEG-Faulting with empty arrays