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"
26 #include "MEDCouplingMemArray.hxx"
34 #include "MEDCouplingMemArray.txx"
37 using namespace MEDCoupling;
39 void MEDCouplingBasicsTest1::testArray()
41 int tmp1[6]={7,6,5,4,3,2};
42 const int tmp2[3]={8,9,10};
45 mem.useArray(tmp1,false,CPP_DEALLOC,6);
46 CPPUNIT_ASSERT(tmp1==mem.getConstPointer());
47 CPPUNIT_ASSERT_THROW(mem.getPointer(),INTERP_KERNEL::Exception);
48 CPPUNIT_ASSERT_THROW(mem[2]=7,INTERP_KERNEL::Exception);
49 CPPUNIT_ASSERT_THROW(mem.writeOnPlace(0,12,tmp2,3),INTERP_KERNEL::Exception);
50 mem.writeOnPlace(4,12,tmp2,3);
54 std::copy(tmp1,tmp1+6,tmp3);
56 mem2.useArray(tmp3,true,CPP_DEALLOC,6);
57 CPPUNIT_ASSERT(tmp3==mem2.getConstPointer());
58 CPPUNIT_ASSERT(tmp3==mem2.getPointer());
59 CPPUNIT_ASSERT_EQUAL(5,mem2[2]);
61 CPPUNIT_ASSERT_EQUAL(7,mem2[2]);
62 mem2.writeOnPlace(0,12,tmp2,3);
63 CPPUNIT_ASSERT_EQUAL(9,mem2[2]);
64 CPPUNIT_ASSERT_EQUAL(12,mem2[0]);
65 mem2.writeOnPlace(4,12,tmp2,3);
69 void MEDCouplingBasicsTest1::testArray2()
71 DataArrayDouble *arr=DataArrayDouble::New();
73 double *tmp=arr->getPointer();
74 const double arrRef[12]={12.,11.,10.,9.,8.,7.,6.,5.,4.,3.,2.,1.};
75 std::copy(arrRef,arrRef+12,tmp);
76 arr->setInfoOnComponent(0,"ggg");
77 arr->setInfoOnComponent(1,"hhhh");
78 arr->setInfoOnComponent(2,"jj");
79 arr->setInfoOnComponent(3,"kkkkkk");
80 MCAuto<DataArrayInt> arr2(arr->convertToIntArr());
81 MCAuto<DataArrayDouble> arr3(arr2->convertToDblArr());
82 CPPUNIT_ASSERT(arr->isEqual(*arr3,1e-14));
86 void MEDCouplingBasicsTest1::testArray3()
88 DataArrayInt *arr1=DataArrayInt::New();
90 int *tmp=arr1->getPointer();
91 const int arr1Ref[14]={0,10,1,11,2,12,3,13,4,14,5,15,6,16};
92 std::copy(arr1Ref,arr1Ref+14,tmp);
93 CPPUNIT_ASSERT_EQUAL(7,(int)arr1->getNumberOfTuples());
94 CPPUNIT_ASSERT_EQUAL(2,(int)arr1->getNumberOfComponents());
95 CPPUNIT_ASSERT(std::equal(arr1Ref,arr1Ref+14,arr1->getConstPointer()));
96 DataArrayInt *arr2=arr1->subArray(3);
97 CPPUNIT_ASSERT_EQUAL(4,(int)arr2->getNumberOfTuples());
98 CPPUNIT_ASSERT_EQUAL(2,(int)arr2->getNumberOfComponents());
99 CPPUNIT_ASSERT(std::equal(arr1Ref+6,arr1Ref+14,arr2->getConstPointer()));
101 DataArrayInt *arr3=arr1->subArray(2,5);
102 CPPUNIT_ASSERT_EQUAL(3,(int)arr3->getNumberOfTuples());
103 CPPUNIT_ASSERT_EQUAL(2,(int)arr3->getNumberOfComponents());
104 CPPUNIT_ASSERT(std::equal(arr1Ref+4,arr1Ref+10,arr3->getConstPointer()));
108 DataArrayDouble *arr4=DataArrayDouble::New();
110 double *tmp2=arr4->getPointer();
111 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};
112 std::copy(arr4Ref,arr4Ref+14,tmp2);
113 CPPUNIT_ASSERT_EQUAL(7,(int)arr4->getNumberOfTuples());
114 CPPUNIT_ASSERT_EQUAL(2,(int)arr4->getNumberOfComponents());
115 CPPUNIT_ASSERT(std::equal(arr4Ref,arr4Ref+14,arr4->getConstPointer()));
116 DataArrayDouble *arr5=arr4->subArray(3);
117 CPPUNIT_ASSERT_EQUAL(4,(int)arr5->getNumberOfTuples());
118 CPPUNIT_ASSERT_EQUAL(2,(int)arr5->getNumberOfComponents());
119 CPPUNIT_ASSERT(std::equal(arr4Ref+6,arr4Ref+14,arr5->getConstPointer()));
121 DataArrayDouble *arr6=arr4->subArray(2,5);
122 CPPUNIT_ASSERT_EQUAL(3,(int)arr6->getNumberOfTuples());
123 CPPUNIT_ASSERT_EQUAL(2,(int)arr6->getNumberOfComponents());
124 CPPUNIT_ASSERT(std::equal(arr4Ref+4,arr4Ref+10,arr6->getConstPointer()));
129 void MEDCouplingBasicsTest1::testMesh()
131 const int nbOfCells=6;
132 const int nbOfNodes=12;
134 double coords[3*nbOfNodes]={
135 0.024155, 0.04183768725682622, -0.305, 0.04831000000000001, -1.015761910347357e-17, -0.305, 0.09662000000000001, -1.832979297858306e-18,
136 -0.305, 0.120775, 0.04183768725682623, -0.305, 0.09662000000000001, 0.08367537451365245, -0.305, 0.04831000000000001,
137 0.08367537451365246, -0.305, 0.024155, 0.04183768725682622, -0.2863, 0.04831000000000001, -1.015761910347357e-17, -0.2863,
138 0.09662000000000001, -1.832979297858306e-18, -0.2863, 0.120775, 0.04183768725682623, -0.2863, 0.09662000000000001, 0.08367537451365245,
139 -0.2863, 0.04831000000000001, 0.08367537451365246, -0.2863, };
141 int tab4[4*nbOfCells]={
142 1, 2, 8, 7, 2, 3, 9, 8, 3, 4, 10, 9, 4, 5, 11, 10, 5, 0, 6, 11,
144 CPPUNIT_ASSERT_EQUAL(MEDCouplingMesh::GetNumberOfNodesOfGeometricType(INTERP_KERNEL::NORM_TRI3),3);
145 CPPUNIT_ASSERT(MEDCouplingMesh::IsStaticGeometricType(INTERP_KERNEL::NORM_TRI3));
146 CPPUNIT_ASSERT(MEDCouplingMesh::IsLinearGeometricType(INTERP_KERNEL::NORM_TRI3));
147 CPPUNIT_ASSERT_EQUAL(MEDCouplingMesh::GetDimensionOfGeometricType(INTERP_KERNEL::NORM_TRI3),2);
148 CPPUNIT_ASSERT_EQUAL(std::string(MEDCouplingMesh::GetReprOfGeometricType(INTERP_KERNEL::NORM_TRI3)),std::string("NORM_TRI3"));
149 CPPUNIT_ASSERT_THROW(MEDCouplingMesh::GetNumberOfNodesOfGeometricType(INTERP_KERNEL::NORM_POLYGON),INTERP_KERNEL::Exception);
150 CPPUNIT_ASSERT(!MEDCouplingMesh::IsStaticGeometricType(INTERP_KERNEL::NORM_POLYGON));
151 CPPUNIT_ASSERT(MEDCouplingMesh::IsLinearGeometricType(INTERP_KERNEL::NORM_POLYGON));
152 CPPUNIT_ASSERT_EQUAL(MEDCouplingMesh::GetDimensionOfGeometricType(INTERP_KERNEL::NORM_POLYGON),2);
153 CPPUNIT_ASSERT_EQUAL(std::string(MEDCouplingMesh::GetReprOfGeometricType(INTERP_KERNEL::NORM_POLYGON)),std::string("NORM_POLYGON"));
154 CPPUNIT_ASSERT_EQUAL(MEDCouplingMesh::GetNumberOfNodesOfGeometricType(INTERP_KERNEL::NORM_TRI6),6);
155 CPPUNIT_ASSERT(MEDCouplingMesh::IsStaticGeometricType(INTERP_KERNEL::NORM_TRI6));
156 CPPUNIT_ASSERT(!MEDCouplingMesh::IsLinearGeometricType(INTERP_KERNEL::NORM_TRI6));
157 CPPUNIT_ASSERT_EQUAL(MEDCouplingMesh::GetDimensionOfGeometricType(INTERP_KERNEL::NORM_TRI6),2);
158 CPPUNIT_ASSERT_EQUAL(std::string(MEDCouplingMesh::GetReprOfGeometricType(INTERP_KERNEL::NORM_TRI6)),std::string("NORM_TRI6"));
159 MEDCouplingUMesh *mesh=MEDCouplingUMesh::New();
160 mesh->setMeshDimension(2);
161 mesh->allocateCells(8);
162 const int *curConn=tab4;
163 for(int i=0;i<nbOfCells;i++,curConn+=4)
164 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,curConn);
165 mesh->finishInsertingCells();
166 CPPUNIT_ASSERT_EQUAL((std::size_t)30,mesh->getNodalConnectivity()->getNbOfElems());
167 CPPUNIT_ASSERT_EQUAL(nbOfCells,(int)mesh->getNumberOfCells());
168 //test 0 - no copy no ownership
169 DataArrayDouble *myCoords=DataArrayDouble::New();
170 myCoords->useArray(coords,false,CPP_DEALLOC,nbOfNodes,3);
171 mesh->setCoords(myCoords);
172 mesh->setCoords(myCoords);
174 CPPUNIT_ASSERT_EQUAL(nbOfCells,(int)mesh->getNumberOfCells());
175 mesh->checkConsistencyLight();
176 //test 1 - no copy ownership C++
177 myCoords=DataArrayDouble::New();
178 double *tmp=new double[3*nbOfNodes];
179 std::copy(coords,coords+3*nbOfNodes,tmp);
180 myCoords->useArray(tmp,true,CPP_DEALLOC,nbOfNodes,3);
181 mesh->setCoords(myCoords);
183 CPPUNIT_ASSERT_EQUAL(nbOfCells,(int)mesh->getNumberOfCells());
184 mesh->checkConsistencyLight();
185 //test 2 - no copy ownership C
186 myCoords=DataArrayDouble::New();
187 tmp=(double *)malloc(3*nbOfNodes*sizeof(double));
188 std::copy(coords,coords+3*nbOfNodes,tmp);
189 myCoords->useArray(tmp,true,C_DEALLOC,nbOfNodes,3);
190 mesh->setCoords(myCoords);
192 CPPUNIT_ASSERT_EQUAL(nbOfNodes,mesh->getNumberOfNodes());
193 mesh->checkConsistencyLight();
195 myCoords=DataArrayDouble::New();
196 myCoords->alloc(nbOfNodes,3);
197 tmp=myCoords->getPointer();
198 std::copy(coords,coords+3*nbOfNodes,tmp);
199 // test 3 bis deepcopy
200 DataArrayDouble *myCoords2=DataArrayDouble::New();
201 *myCoords2=*myCoords;
202 myCoords2->decrRef();
204 mesh->setCoords(myCoords);
206 CPPUNIT_ASSERT_EQUAL(nbOfNodes,mesh->getNumberOfNodes());
207 mesh->checkConsistencyLight();
208 CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
209 // test clone not recursively
210 MEDCouplingUMesh *mesh2=mesh->clone(false);
211 CPPUNIT_ASSERT(mesh2!=mesh);
212 mesh2->checkConsistencyLight();
213 CPPUNIT_ASSERT_EQUAL(nbOfCells,(int)mesh2->getNumberOfCells());
214 CPPUNIT_ASSERT_EQUAL(nbOfNodes,mesh2->getNumberOfNodes());
215 CPPUNIT_ASSERT_EQUAL(3,mesh2->getSpaceDimension());
216 CPPUNIT_ASSERT(mesh!=mesh2);
217 CPPUNIT_ASSERT(mesh->getCoords()==mesh2->getCoords());
218 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.2863,mesh2->getCoords()->getIJ(11,2),1e-14);
219 CPPUNIT_ASSERT(mesh->getNodalConnectivity()==mesh2->getNodalConnectivity());
220 CPPUNIT_ASSERT_EQUAL(3,mesh2->getNodalConnectivity()->getIJ(7,0));
221 CPPUNIT_ASSERT(mesh->getNodalConnectivityIndex()==mesh2->getNodalConnectivityIndex());
222 CPPUNIT_ASSERT_EQUAL(15,mesh2->getNodalConnectivityIndex()->getIJ(3,0));
224 // test clone not recursively
225 MEDCouplingUMesh *mesh3=mesh->clone(true);
226 CPPUNIT_ASSERT(mesh3!=mesh);
227 mesh3->checkConsistencyLight();
228 CPPUNIT_ASSERT_EQUAL(nbOfCells,(int)mesh3->getNumberOfCells());
229 CPPUNIT_ASSERT_EQUAL(nbOfNodes,mesh3->getNumberOfNodes());
230 CPPUNIT_ASSERT_EQUAL(3,mesh3->getSpaceDimension());
231 CPPUNIT_ASSERT(mesh!=mesh3);
232 CPPUNIT_ASSERT(mesh->getCoords()!=mesh3->getCoords());
233 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.2863,mesh3->getCoords()->getIJ(11,2),1e-14);
234 CPPUNIT_ASSERT(mesh->getNodalConnectivity()!=mesh3->getNodalConnectivity());
235 CPPUNIT_ASSERT_EQUAL(3,mesh3->getNodalConnectivity()->getIJ(7,0));
236 CPPUNIT_ASSERT(mesh->getNodalConnectivityIndex()!=mesh3->getNodalConnectivityIndex());
237 CPPUNIT_ASSERT_EQUAL(15,mesh3->getNodalConnectivityIndex()->getIJ(3,0));
239 //test 4 - Field on cells
240 MEDCouplingFieldDouble *fieldOnCells=MEDCouplingFieldDouble::New(ON_CELLS);
241 fieldOnCells->setMesh(mesh);
242 DataArrayDouble *array=DataArrayDouble::New();
243 array->alloc(nbOfCells,9);
244 fieldOnCells->setArray(array);
245 tmp=array->getPointer();
247 std::fill(tmp,tmp+9*nbOfCells,7.);
248 //content of field changed -> declare it.
249 fieldOnCells->declareAsNew();
250 fieldOnCells->checkConsistencyLight();
251 // testing clone of fields - no recursive
252 MEDCouplingFieldDouble *fieldOnCells2=fieldOnCells->clone(false);
253 CPPUNIT_ASSERT(fieldOnCells2!=fieldOnCells);
254 fieldOnCells2->checkConsistencyLight();
255 CPPUNIT_ASSERT_EQUAL(nbOfCells,(int)fieldOnCells2->getNumberOfTuples());
256 CPPUNIT_ASSERT_EQUAL(9,(int)fieldOnCells2->getNumberOfComponents());
257 CPPUNIT_ASSERT(fieldOnCells2->getArray()==fieldOnCells->getArray());
258 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,fieldOnCells2->getArray()->getIJ(3,7),1e-14);
259 CPPUNIT_ASSERT(fieldOnCells2->getMesh()==fieldOnCells->getMesh());
260 // testing clone of fields - recursive
261 MEDCouplingFieldDouble *fieldOnCells3=fieldOnCells->clone(true);
262 CPPUNIT_ASSERT(fieldOnCells3!=fieldOnCells);
263 fieldOnCells3->checkConsistencyLight();
264 CPPUNIT_ASSERT_EQUAL(nbOfCells,(int)fieldOnCells3->getNumberOfTuples());
265 CPPUNIT_ASSERT_EQUAL(9,(int)fieldOnCells3->getNumberOfComponents());
266 CPPUNIT_ASSERT(fieldOnCells3->getArray()!=fieldOnCells->getArray());
267 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,fieldOnCells3->getArray()->getIJ(3,7),1e-14);
268 CPPUNIT_ASSERT(fieldOnCells3->getMesh()==fieldOnCells->getMesh());
269 fieldOnCells2->decrRef();
270 fieldOnCells3->decrRef();
272 fieldOnCells->decrRef();
277 void MEDCouplingBasicsTest1::testMeshPointsCloud()
279 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};
280 const int targetConn[]={0,1,2,3,4,5,7,6};
281 MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
282 targetMesh->setMeshDimension(0);
283 targetMesh->allocateCells(8);
284 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn);
285 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+1);
286 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+2);
287 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+3);
288 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+4);
289 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+5);
290 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+6);
291 targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+7);
292 targetMesh->finishInsertingCells();
293 CPPUNIT_ASSERT_THROW(targetMesh->checkConsistencyLight(),INTERP_KERNEL::Exception);
294 DataArrayDouble *myCoords=DataArrayDouble::New();
295 myCoords->alloc(9,3);
296 std::copy(targetCoords,targetCoords+27,myCoords->getPointer());
297 targetMesh->setCoords(myCoords);
300 targetMesh->checkConsistencyLight();
301 CPPUNIT_ASSERT_EQUAL(3,targetMesh->getSpaceDimension());
302 CPPUNIT_ASSERT_EQUAL(8,(int)targetMesh->getNumberOfCells());
303 CPPUNIT_ASSERT_EQUAL(9,targetMesh->getNumberOfNodes());
304 CPPUNIT_ASSERT_EQUAL(0,targetMesh->getMeshDimension());
306 targetMesh->decrRef();
309 void MEDCouplingBasicsTest1::testMeshM1D()
311 MEDCouplingUMesh *meshM1D=MEDCouplingUMesh::New();
312 CPPUNIT_ASSERT_THROW(meshM1D->getMeshDimension(),INTERP_KERNEL::Exception);
313 CPPUNIT_ASSERT_THROW(meshM1D->getNumberOfNodes(),INTERP_KERNEL::Exception);
314 CPPUNIT_ASSERT_THROW(meshM1D->getNumberOfCells(),INTERP_KERNEL::Exception);
315 CPPUNIT_ASSERT_THROW(meshM1D->setMeshDimension(-2),INTERP_KERNEL::Exception);
316 CPPUNIT_ASSERT_THROW(meshM1D->setMeshDimension(-10),INTERP_KERNEL::Exception);
317 CPPUNIT_ASSERT_THROW(meshM1D->checkConsistencyLight(),INTERP_KERNEL::Exception);
318 meshM1D->setMeshDimension(-1);
319 meshM1D->checkConsistencyLight();
320 CPPUNIT_ASSERT_EQUAL(-1,meshM1D->getMeshDimension());
321 CPPUNIT_ASSERT_EQUAL(1,(int)meshM1D->getNumberOfCells());
322 CPPUNIT_ASSERT_THROW(meshM1D->getNumberOfNodes(),INTERP_KERNEL::Exception);
323 CPPUNIT_ASSERT_THROW(meshM1D->getSpaceDimension(),INTERP_KERNEL::Exception);
324 MEDCouplingUMesh *cpy=meshM1D->clone(true);
325 CPPUNIT_ASSERT(cpy->isEqual(meshM1D,1e-12));
327 MEDCouplingFieldDouble *fieldOnCells=MEDCouplingFieldDouble::New(ON_CELLS);
328 fieldOnCells->setMesh(meshM1D);
329 DataArrayDouble *array=DataArrayDouble::New();
331 fieldOnCells->setArray(array);
332 double *tmp=array->getPointer();
334 std::fill(tmp,tmp+6,7.);
335 fieldOnCells->checkConsistencyLight();
337 fieldOnCells->decrRef();
341 void MEDCouplingBasicsTest1::testDeepCopy()
343 DataArrayDouble *array=DataArrayDouble::New();
345 std::fill(array->getPointer(),array->getPointer()+5*3,7.);
346 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,array->getIJ(3,2),1e-14);
347 double *tmp1=array->getPointer();
348 DataArrayDouble *array2=array->deepCopy();
349 double *tmp2=array2->getPointer();
350 CPPUNIT_ASSERT(tmp1!=tmp2);
352 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,array2->getIJ(3,2),1e-14);
355 DataArrayInt *array3=DataArrayInt::New();
357 std::fill(array3->getPointer(),array3->getPointer()+5*3,17);
358 CPPUNIT_ASSERT_EQUAL(17,array3->getIJ(3,2));
359 int *tmp3=array3->getPointer();
360 DataArrayInt *array4=array3->deepCopy();
361 int *tmp4=array4->getPointer();
362 CPPUNIT_ASSERT(tmp3!=tmp4);
364 CPPUNIT_ASSERT_EQUAL(17,array4->getIJ(3,2));
368 void MEDCouplingBasicsTest1::testRevNodal()
370 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
371 DataArrayInt *revNodal=DataArrayInt::New();
372 DataArrayInt *revNodalIndx=DataArrayInt::New();
374 mesh->getReverseNodalConnectivity(revNodal,revNodalIndx);
375 const int revNodalExpected[18]={0,0,1,1,2,0,3,0,1,2,3,4,2,4,3,3,4,4};
376 const int revNodalIndexExpected[10]={0,1,3,5,7,12,14,15,17,18};
377 CPPUNIT_ASSERT_EQUAL((std::size_t)18,revNodal->getNbOfElems());
378 CPPUNIT_ASSERT_EQUAL((std::size_t)10,revNodalIndx->getNbOfElems());
379 CPPUNIT_ASSERT(std::equal(revNodalExpected,revNodalExpected+18,revNodal->getPointer()));
380 CPPUNIT_ASSERT(std::equal(revNodalIndexExpected,revNodalIndexExpected+10,revNodalIndx->getPointer()));
383 revNodalIndx->decrRef();
387 void MEDCouplingBasicsTest1::testConvertToPolyTypes()
390 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
392 const int elts[2]={1,3};
393 std::vector<int> eltsV(elts,elts+2);
394 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
395 mesh->checkConsistencyLight();
396 CPPUNIT_ASSERT_EQUAL(5,(int)mesh->getNumberOfCells());
397 CPPUNIT_ASSERT_EQUAL(23,(int)mesh->getNodalConnectivity()->getNumberOfTuples());
398 const int *pt=mesh->getNodalConnectivity()->getConstPointer();
399 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};
400 CPPUNIT_ASSERT(std::equal(expected1,expected1+23,pt));
404 mesh=build3DTargetMesh_1();
405 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
406 mesh->checkConsistencyLight();
407 CPPUNIT_ASSERT_EQUAL(8,(int)mesh->getNumberOfCells());
408 CPPUNIT_ASSERT_EQUAL(114,(int)mesh->getNodalConnectivity()->getNumberOfTuples());
409 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
410 mesh->checkConsistencyLight();
411 CPPUNIT_ASSERT_EQUAL(8,(int)mesh->getNumberOfCells());
412 CPPUNIT_ASSERT_EQUAL(114,(int)mesh->getNodalConnectivity()->getNumberOfTuples());
417 void MEDCouplingBasicsTest1::testDescConn2D()
419 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
420 DataArrayInt *desc=DataArrayInt::New();
421 DataArrayInt *descIndx=DataArrayInt::New();
422 DataArrayInt *revDesc=DataArrayInt::New();
423 DataArrayInt *revDescIndx=DataArrayInt::New();
425 MEDCouplingUMesh *mesh2=mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
426 mesh2->checkConsistencyLight();
427 CPPUNIT_ASSERT_EQUAL(1,mesh2->getMeshDimension());
428 CPPUNIT_ASSERT_EQUAL(13,(int)mesh2->getNumberOfCells());
429 CPPUNIT_ASSERT_EQUAL((std::size_t)14,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(14,(int)revDescIndx->getNumberOfTuples());
430 CPPUNIT_ASSERT_EQUAL((std::size_t)6,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(6,(int)descIndx->getNumberOfTuples());
431 CPPUNIT_ASSERT_EQUAL((std::size_t)18,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,(int)desc->getNumberOfTuples());
432 CPPUNIT_ASSERT_EQUAL((std::size_t)18,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,(int)revDesc->getNumberOfTuples());
433 const int expected1[18]={0,1,2,3, 2,4,5, 6,7,4, 8,9,1,10, 11,12,6,9};
434 CPPUNIT_ASSERT(std::equal(expected1,expected1+18,desc->getConstPointer()));
435 const int expected2[6]={0,4,7,10,14,18};
436 CPPUNIT_ASSERT(std::equal(expected2,expected2+6,descIndx->getConstPointer()));
437 const int expected3[14]={0,1,3,5,6,8,9,11,12,13,15,16,17,18};
438 CPPUNIT_ASSERT(std::equal(expected3,expected3+14,revDescIndx->getConstPointer()));
439 const int expected4[18]={0, 0,3, 0,1, 0, 1,2, 1, 2,4, 2, 3, 3,4, 3, 4, 4};
440 CPPUNIT_ASSERT(std::equal(expected4,expected4+18,revDesc->getConstPointer()));
441 DataArrayInt *conn=mesh2->getNodalConnectivity();
442 DataArrayInt *connIndex=mesh2->getNodalConnectivityIndex();
443 const int expected5[14]={0,3,6,9,12,15,18,21,24,27,30,33,36,39};
444 CPPUNIT_ASSERT(std::equal(expected5,expected5+14,connIndex->getConstPointer()));
445 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};
446 CPPUNIT_ASSERT(std::equal(expected6,expected6+39,conn->getConstPointer()));
451 revDescIndx->decrRef();
454 const int elts[2]={1,3};
455 std::vector<int> eltsV(elts,elts+2);
456 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
457 mesh->checkConsistencyLight();
459 desc=DataArrayInt::New();
460 descIndx=DataArrayInt::New();
461 revDesc=DataArrayInt::New();
462 revDescIndx=DataArrayInt::New();
464 mesh2=mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
465 mesh2->checkConsistencyLight();
466 CPPUNIT_ASSERT_EQUAL(1,mesh2->getMeshDimension());
467 CPPUNIT_ASSERT_EQUAL(13,(int)mesh2->getNumberOfCells());
468 CPPUNIT_ASSERT_EQUAL((std::size_t)14,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(14,(int)revDescIndx->getNumberOfTuples());
469 CPPUNIT_ASSERT_EQUAL((std::size_t)6,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(6,(int)descIndx->getNumberOfTuples());
470 CPPUNIT_ASSERT_EQUAL((std::size_t)18,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,(int)desc->getNumberOfTuples());
471 CPPUNIT_ASSERT_EQUAL((std::size_t)18,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,(int)revDesc->getNumberOfTuples());
472 CPPUNIT_ASSERT(std::equal(expected1,expected1+18,desc->getConstPointer()));
473 CPPUNIT_ASSERT(std::equal(expected2,expected2+6,descIndx->getConstPointer()));
474 CPPUNIT_ASSERT(std::equal(expected3,expected3+14,revDescIndx->getConstPointer()));
475 CPPUNIT_ASSERT(std::equal(expected4,expected4+18,revDesc->getConstPointer()));
476 conn=mesh2->getNodalConnectivity();
477 connIndex=mesh2->getNodalConnectivityIndex();
478 CPPUNIT_ASSERT(std::equal(expected5,expected5+14,connIndex->getConstPointer()));
479 CPPUNIT_ASSERT(std::equal(expected6,expected6+39,conn->getConstPointer()));
484 revDescIndx->decrRef();
489 void MEDCouplingBasicsTest1::testDescConn3D()
491 MEDCouplingUMesh *mesh=build3DTargetMesh_1();
492 DataArrayInt *desc=DataArrayInt::New();
493 DataArrayInt *descIndx=DataArrayInt::New();
494 DataArrayInt *revDesc=DataArrayInt::New();
495 DataArrayInt *revDescIndx=DataArrayInt::New();
497 MEDCouplingUMesh *mesh2=mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
498 mesh2->checkConsistencyLight();
499 CPPUNIT_ASSERT_EQUAL(2,mesh2->getMeshDimension());
500 CPPUNIT_ASSERT_EQUAL(36,(int)mesh2->getNumberOfCells());
501 CPPUNIT_ASSERT_EQUAL((std::size_t)37,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(37,(int)revDescIndx->getNumberOfTuples());
502 CPPUNIT_ASSERT_EQUAL((std::size_t)9,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(9,(int)descIndx->getNumberOfTuples());
503 CPPUNIT_ASSERT_EQUAL((std::size_t)48,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,(int)desc->getNumberOfTuples());
504 CPPUNIT_ASSERT_EQUAL((std::size_t)48,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,(int)revDesc->getNumberOfTuples());
505 const int expected1[9]={0, 6, 12, 18, 24, 30, 36, 42, 48};
506 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};
507 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};
508 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};
509 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};
510 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,
511 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,
512 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,
513 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};
514 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,
515 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,
516 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,
517 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};
519 CPPUNIT_ASSERT(std::equal(expected1,expected1+9,descIndx->getConstPointer()));
520 CPPUNIT_ASSERT(std::equal(expected2,expected2+48,desc->getConstPointer()));
521 CPPUNIT_ASSERT(std::equal(expected3,expected3+37,revDescIndx->getConstPointer()));
522 CPPUNIT_ASSERT(std::equal(expected4,expected4+48,revDesc->getConstPointer()));
523 CPPUNIT_ASSERT(std::equal(expected5,expected5+37,mesh2->getNodalConnectivityIndex()->getConstPointer()));
524 CPPUNIT_ASSERT(std::equal(expected6,expected6+180,mesh2->getNodalConnectivity()->getConstPointer()));
529 revDescIndx->decrRef();
532 const int elts[2]={1,3};
533 std::vector<int> eltsV(elts,elts+2);
534 mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
535 mesh->checkConsistencyLight();
536 desc=DataArrayInt::New();
537 descIndx=DataArrayInt::New();
538 revDesc=DataArrayInt::New();
539 revDescIndx=DataArrayInt::New();
540 mesh2=mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
541 mesh2->checkConsistencyLight();
542 CPPUNIT_ASSERT_EQUAL(2,mesh2->getMeshDimension());
543 CPPUNIT_ASSERT_EQUAL(36,(int)mesh2->getNumberOfCells());
544 CPPUNIT_ASSERT_EQUAL((std::size_t)37,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(37,(int)revDescIndx->getNumberOfTuples());
545 CPPUNIT_ASSERT_EQUAL((std::size_t)9,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(9,(int)descIndx->getNumberOfTuples());
546 CPPUNIT_ASSERT_EQUAL((std::size_t)48,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,(int)desc->getNumberOfTuples());
547 CPPUNIT_ASSERT_EQUAL((std::size_t)48,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,(int)revDesc->getNumberOfTuples());
548 CPPUNIT_ASSERT(std::equal(expected1,expected1+9,descIndx->getConstPointer()));
549 CPPUNIT_ASSERT(std::equal(expected2,expected2+48,desc->getConstPointer()));
550 CPPUNIT_ASSERT(std::equal(expected3,expected3+37,revDescIndx->getConstPointer()));
551 CPPUNIT_ASSERT(std::equal(expected4,expected4+48,revDesc->getConstPointer()));
552 CPPUNIT_ASSERT(std::equal(expected5,expected5+37,mesh2->getNodalConnectivityIndex()->getConstPointer()));
553 CPPUNIT_ASSERT(std::equal(expected7,expected7+180,mesh2->getNodalConnectivity()->getConstPointer()));
558 revDescIndx->decrRef();
563 void MEDCouplingBasicsTest1::testFindBoundaryNodes()
565 MEDCouplingUMesh *mesh=build3DTargetMesh_1();
566 DataArrayInt *boundaryNodes=mesh->findBoundaryNodes();
567 CPPUNIT_ASSERT_EQUAL(26,(int)boundaryNodes->getNumberOfTuples());
568 CPPUNIT_ASSERT_EQUAL(1,(int)boundaryNodes->getNumberOfComponents());
569 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};
570 CPPUNIT_ASSERT(std::equal(expected1,expected1+26,boundaryNodes->begin()));
571 boundaryNodes->decrRef();
575 void MEDCouplingBasicsTest1::testBoundaryMesh()
577 MEDCouplingUMesh *mesh=build3DTargetMesh_1();
578 MEDCouplingPointSet *mesh2=mesh->buildBoundaryMesh(false);
579 CPPUNIT_ASSERT_EQUAL(24,(int)mesh2->getNumberOfCells());
580 CPPUNIT_ASSERT_EQUAL(26,mesh2->getNumberOfNodes());
585 void MEDCouplingBasicsTest1::testBuildPartOfMySelf()
587 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
588 mesh->setName("Toto");
589 const int tab1[2]={0,4};
590 const int tab2[3]={0,2,3};
592 MEDCouplingPointSet *subMeshSimple=mesh->buildPartOfMySelf(tab1,tab1+2,true);
593 MEDCouplingUMesh *subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
594 CPPUNIT_ASSERT(subMesh);
595 std::string name(subMesh->getName());
596 CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllGeoTypes().size());
597 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*mesh->getAllGeoTypes().begin());
598 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++(mesh->getAllGeoTypes().begin())));
599 CPPUNIT_ASSERT_EQUAL(1,(int)subMesh->getAllGeoTypes().size());
600 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllGeoTypes().begin());
601 CPPUNIT_ASSERT(name=="Toto");
602 CPPUNIT_ASSERT(mesh->getCoords()==subMesh->getCoords());
603 CPPUNIT_ASSERT_EQUAL(2,(int)subMesh->getNumberOfCells());
604 const int subConn[10]={4,0,3,4,1,4,7,8,5,4};
605 const int subConnIndex[3]={0,5,10};
606 CPPUNIT_ASSERT_EQUAL((std::size_t)10,subMesh->getNodalConnectivity()->getNbOfElems());
607 CPPUNIT_ASSERT_EQUAL((std::size_t)3,subMesh->getNodalConnectivityIndex()->getNbOfElems());
608 CPPUNIT_ASSERT(std::equal(subConn,subConn+10,subMesh->getNodalConnectivity()->getPointer()));
609 CPPUNIT_ASSERT(std::equal(subConnIndex,subConnIndex+3,subMesh->getNodalConnectivityIndex()->getPointer()));
612 subMeshSimple=mesh->buildPartOfMySelf(tab2,tab2+3,true);
613 subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
614 CPPUNIT_ASSERT(subMesh);
615 name=subMesh->getName();
616 CPPUNIT_ASSERT_EQUAL(2,(int)subMesh->getAllGeoTypes().size());
617 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*subMesh->getAllGeoTypes().begin());
618 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++(subMesh->getAllGeoTypes().begin())));
619 CPPUNIT_ASSERT(name=="Toto");
620 CPPUNIT_ASSERT(mesh->getCoords()==subMesh->getCoords());
621 CPPUNIT_ASSERT_EQUAL(3,(int)subMesh->getNumberOfCells());
622 const int subConn2[14]={4,0,3,4,1,3,4,5,2,4,6,7,4,3};
623 const int subConnIndex2[4]={0,5,9,14};
624 CPPUNIT_ASSERT_EQUAL((std::size_t)14,subMesh->getNodalConnectivity()->getNbOfElems());
625 CPPUNIT_ASSERT_EQUAL((std::size_t)4,subMesh->getNodalConnectivityIndex()->getNbOfElems());
626 CPPUNIT_ASSERT(std::equal(subConn2,subConn2+14,subMesh->getNodalConnectivity()->getPointer()));
627 CPPUNIT_ASSERT(std::equal(subConnIndex2,subConnIndex2+4,subMesh->getNodalConnectivityIndex()->getPointer()));
628 const int tab3[3]={0,1,2};
629 MEDCouplingPointSet *subMeshSimple2=subMeshSimple->buildPartOfMySelf(tab3,tab3+3,true);
631 name=subMeshSimple2->getName();
632 CPPUNIT_ASSERT(name=="Toto");
633 subMeshSimple2->decrRef();
638 void MEDCouplingBasicsTest1::testBuildPartOfMySelfNode()
640 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
641 const int tab1[4]={5,7,8,4};
642 MEDCouplingPointSet *subMeshSimple=mesh->buildPartOfMySelfNode(tab1,tab1+4,true);
643 MEDCouplingUMesh *subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
644 CPPUNIT_ASSERT(subMesh);
645 CPPUNIT_ASSERT_EQUAL(1,(int)subMesh->getAllGeoTypes().size());
646 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllGeoTypes().begin());
647 CPPUNIT_ASSERT_EQUAL(1,(int)subMesh->getNumberOfCells());
648 CPPUNIT_ASSERT_EQUAL((std::size_t)5,subMesh->getNodalConnectivity()->getNbOfElems());
649 CPPUNIT_ASSERT_EQUAL((std::size_t)2,subMesh->getNodalConnectivityIndex()->getNbOfElems());
650 const int subConn[5]={4,7,8,5,4};
651 const int subConnIndex[3]={0,5};
652 CPPUNIT_ASSERT(std::equal(subConn,subConn+5,subMesh->getNodalConnectivity()->getPointer()));
653 CPPUNIT_ASSERT(std::equal(subConnIndex,subConnIndex+2,subMesh->getNodalConnectivityIndex()->getPointer()));
654 CPPUNIT_ASSERT(subMesh->getCoords()==mesh->getCoords());
655 subMeshSimple->decrRef();
657 subMeshSimple=mesh->buildPartOfMySelfNode(tab1,tab1+2,false);
658 subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
659 CPPUNIT_ASSERT(subMesh);
660 CPPUNIT_ASSERT_EQUAL(2,(int)subMesh->getAllGeoTypes().size());
661 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*subMesh->getAllGeoTypes().begin());
662 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++subMesh->getAllGeoTypes().begin()));
663 CPPUNIT_ASSERT_EQUAL(3,(int)subMesh->getNumberOfCells());
664 CPPUNIT_ASSERT_EQUAL((std::size_t)14,subMesh->getNodalConnectivity()->getNbOfElems());
665 CPPUNIT_ASSERT_EQUAL((std::size_t)4,subMesh->getNodalConnectivityIndex()->getNbOfElems());
666 const int subConn2[14]={3,4,5,2,4,6,7,4,3,4,7,8,5,4};
667 const int subConnIndex2[4]={0,4,9,14};
668 CPPUNIT_ASSERT(std::equal(subConn2,subConn2+14,subMesh->getNodalConnectivity()->getPointer()));
669 CPPUNIT_ASSERT(std::equal(subConnIndex2,subConnIndex2+4,subMesh->getNodalConnectivityIndex()->getPointer()));
670 CPPUNIT_ASSERT(subMesh->getCoords()==mesh->getCoords());
671 subMeshSimple->decrRef();
672 //testing the case where length of tab2 is greater than max number of node per cell.
673 const int tab2[7]={0,3,2,1,4,5,6};
674 subMeshSimple=mesh->buildPartOfMySelfNode(tab2,tab2+7,true);
675 subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
676 CPPUNIT_ASSERT(subMesh);
677 CPPUNIT_ASSERT_EQUAL(2,(int)subMesh->getAllGeoTypes().size());
678 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*subMesh->getAllGeoTypes().begin());
679 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++subMesh->getAllGeoTypes().begin()));
680 CPPUNIT_ASSERT_EQUAL(3,(int)subMesh->getNumberOfCells());
681 subMeshSimple->decrRef();
686 void MEDCouplingBasicsTest1::testZipCoords()
688 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
689 CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllGeoTypes().size());
690 CPPUNIT_ASSERT_EQUAL(2,mesh->getSpaceDimension());
691 CPPUNIT_ASSERT_EQUAL(9,mesh->getNumberOfNodes());
692 CPPUNIT_ASSERT_EQUAL(5,(int)mesh->getNumberOfCells());
693 std::vector<int> oldConn(mesh->getNodalConnectivity()->getNbOfElems());
694 std::vector<int> oldConnIndex(mesh->getNumberOfCells()+1);
695 std::copy(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+oldConn.size(),oldConn.begin());
696 std::copy(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+mesh->getNumberOfCells()+1,oldConnIndex.begin());
697 DataArrayDouble *oldCoords=mesh->getCoords();
698 oldCoords->incrRef();
700 CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllGeoTypes().size());
701 CPPUNIT_ASSERT_EQUAL(2,mesh->getSpaceDimension());
702 CPPUNIT_ASSERT_EQUAL(9,mesh->getNumberOfNodes());
703 CPPUNIT_ASSERT_EQUAL(5,(int)mesh->getNumberOfCells());
704 CPPUNIT_ASSERT(mesh->getCoords()!=oldCoords);
705 CPPUNIT_ASSERT(std::equal(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+2*9,oldCoords->getPointer()));
706 CPPUNIT_ASSERT(std::equal(oldConn.begin(),oldConn.end(),mesh->getNodalConnectivity()->getPointer()));
707 CPPUNIT_ASSERT(std::equal(oldConnIndex.begin(),oldConnIndex.end(),mesh->getNodalConnectivityIndex()->getPointer()));
708 oldCoords->decrRef();
710 const int tab1[2]={0,4};
711 MEDCouplingPointSet *subMeshPtSet=mesh->buildPartOfMySelf(tab1,tab1+2,true);
712 MEDCouplingUMesh *subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshPtSet);
713 CPPUNIT_ASSERT(subMesh);
714 DataArrayInt *traducer=subMesh->zipCoordsTraducer();
715 const int expectedTraducer[9]={0,1,-1,2,3,4,-1,5,6};
716 CPPUNIT_ASSERT(std::equal(expectedTraducer,expectedTraducer+9,traducer->getPointer()));
718 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllGeoTypes().begin());
719 CPPUNIT_ASSERT_EQUAL(2,(int)subMesh->getNumberOfCells());
720 const int subConn[10]={4,0,2,3,1,4,5,6,4,3};
721 const int subConnIndex[3]={0,5,10};
722 CPPUNIT_ASSERT_EQUAL(7,subMesh->getNumberOfNodes());
723 CPPUNIT_ASSERT_EQUAL((std::size_t)10,subMesh->getNodalConnectivity()->getNbOfElems());
724 CPPUNIT_ASSERT_EQUAL((std::size_t)3,subMesh->getNodalConnectivityIndex()->getNbOfElems());
725 CPPUNIT_ASSERT(std::equal(subConn,subConn+10,subMesh->getNodalConnectivity()->getPointer()));
726 CPPUNIT_ASSERT(std::equal(subConnIndex,subConnIndex+3,subMesh->getNodalConnectivityIndex()->getPointer()));
729 subMeshPtSet=mesh->buildPartOfMySelf(tab1,tab1+2,false);
730 subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshPtSet);
731 CPPUNIT_ASSERT(subMesh);
732 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllGeoTypes().begin());
733 CPPUNIT_ASSERT_EQUAL(2,(int)subMesh->getNumberOfCells());
734 CPPUNIT_ASSERT_EQUAL(7,subMesh->getNumberOfNodes());
735 CPPUNIT_ASSERT_EQUAL((std::size_t)10,subMesh->getNodalConnectivity()->getNbOfElems());
736 CPPUNIT_ASSERT_EQUAL((std::size_t)3,subMesh->getNodalConnectivityIndex()->getNbOfElems());
737 CPPUNIT_ASSERT(std::equal(subConn,subConn+10,subMesh->getNodalConnectivity()->getPointer()));
738 CPPUNIT_ASSERT(std::equal(subConnIndex,subConnIndex+3,subMesh->getNodalConnectivityIndex()->getPointer()));
744 void MEDCouplingBasicsTest1::testZipConnectivity()
746 MEDCouplingUMesh *m1=build2DTargetMesh_1();
747 MEDCouplingUMesh *m2=build2DTargetMesh_1();
748 int cells1[3]={2,3,4};
749 MEDCouplingPointSet *m3_1=m2->buildPartOfMySelf(cells1,cells1+3,true);
750 MEDCouplingUMesh *m3=dynamic_cast<MEDCouplingUMesh *>(m3_1);
753 MEDCouplingUMesh *m4=build2DSourceMesh_1();
754 MEDCouplingUMesh *m5=MEDCouplingUMesh::MergeUMeshes(m1,m3);
757 MEDCouplingUMesh *m6=MEDCouplingUMesh::MergeUMeshes(m5,m4);
763 CPPUNIT_ASSERT_EQUAL(10,(int)m6->getNumberOfCells());
764 CPPUNIT_ASSERT_EQUAL(22,m6->getNumberOfNodes());
765 DataArrayInt *arr=m6->mergeNodes(1e-13,areNodesMerged,newNbOfNodes);
767 CPPUNIT_ASSERT(areNodesMerged);
768 CPPUNIT_ASSERT_EQUAL(10,(int)m6->getNumberOfCells());
769 CPPUNIT_ASSERT_EQUAL(9,m6->getNumberOfNodes());
770 CPPUNIT_ASSERT_EQUAL(9,newNbOfNodes);
772 arr=m6->zipConnectivityTraducer(0);
773 CPPUNIT_ASSERT_EQUAL(7,(int)m6->getNumberOfCells());
775 MEDCouplingUMesh *m7=m6->clone(true);
776 arr=m6->zipConnectivityTraducer(0);
777 CPPUNIT_ASSERT(m7->isEqual(m6,1e-12));
778 CPPUNIT_ASSERT_EQUAL(7,(int)m6->getNumberOfCells());
785 void MEDCouplingBasicsTest1::testEqualMesh()
787 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
788 MEDCouplingUMesh *mesh2=build2DTargetMesh_1();
790 CPPUNIT_ASSERT(mesh1->isEqual(mesh1,1e-12));
792 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
793 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
794 double *pt=mesh2->getCoords()->getPointer();
797 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
798 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
800 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
801 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
803 int *pt2=mesh1->getNodalConnectivity()->getPointer();
805 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
806 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
808 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
809 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
811 pt2=mesh1->getNodalConnectivityIndex()->getPointer();
813 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
814 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
816 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
817 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
819 std::string tmp3=mesh1->getName();
820 mesh1->setName("lllll");
821 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
822 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
823 mesh1->setName(tmp3.c_str());
824 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
825 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
827 tmp3=mesh2->getCoords()->getInfoOnComponent(1);
828 mesh2->getCoords()->setInfoOnComponent(1,"kkkkkk");
829 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
830 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
831 mesh2->getCoords()->setInfoOnComponent(1,tmp3.c_str());
832 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
833 CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
839 void MEDCouplingBasicsTest1::testEqualFieldDouble()
841 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
842 MEDCouplingUMesh *mesh2=build2DTargetMesh_1();
844 MEDCouplingFieldDouble *fieldOnCells1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
845 fieldOnCells1->setMesh(mesh1);
846 MEDCouplingFieldDouble *fieldOnCells2=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
847 fieldOnCells2->setMesh(mesh2);
849 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
850 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
851 fieldOnCells2->decrRef();
853 MEDCouplingFieldDouble *fieldOnNodes1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
854 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnNodes1,1e-12,1e-15));
855 CPPUNIT_ASSERT(!fieldOnNodes1->isEqual(fieldOnCells1,1e-12,1e-15));
856 fieldOnNodes1->decrRef();
858 fieldOnCells2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
859 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
860 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
861 fieldOnCells1->decrRef();
862 fieldOnCells1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
863 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
864 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
865 fieldOnCells1->setTime(4.,6,7);
866 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
867 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
868 fieldOnCells2->setTime(4.,6,7);
869 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
870 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
871 fieldOnCells1->setName("Power");
872 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
873 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
874 fieldOnCells2->setName("Power");
875 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
876 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
878 fieldOnCells1->setMesh(mesh1);
879 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
880 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
881 fieldOnCells2->setMesh(mesh1);
882 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
883 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
884 DataArrayDouble *arr=DataArrayDouble::New();
885 arr->setName("popo");
886 arr->alloc(mesh1->getNumberOfCells(),3);
887 double *pt=arr->getPointer();
888 std::fill(pt,pt+mesh1->getNumberOfCells()*3,6.);
889 fieldOnCells1->setArray(arr);
890 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
891 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
892 fieldOnCells2->setArray(arr);
894 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
895 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
897 DataArrayDouble *arr2=arr->deepCopy();
898 fieldOnCells2->setArray(arr2);
900 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
901 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
903 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
904 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
906 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
907 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
908 arr2->setName("popo2");
909 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
910 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
912 arr2->setName("popo");
913 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
914 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
916 arr2->setInfoOnComponent(2,"jjj");
917 CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
918 CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
919 arr->setInfoOnComponent(2,"jjj");
920 CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
921 CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
923 fieldOnCells1->decrRef();
924 fieldOnCells2->decrRef();
930 void MEDCouplingBasicsTest1::testNatureChecking()
932 MEDCouplingFieldDouble *field=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
933 field->setNature(ExtensiveMaximum);
934 field->setNature(IntensiveMaximum);
935 field->setNature(ExtensiveConservation);
937 field=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
938 field->setNature(IntensiveMaximum);
939 CPPUNIT_ASSERT_THROW(field->setNature(ExtensiveMaximum),INTERP_KERNEL::Exception);
940 CPPUNIT_ASSERT_THROW(field->setNature(ExtensiveConservation),INTERP_KERNEL::Exception);
944 void MEDCouplingBasicsTest1::testBuildSubMeshData()
946 MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
947 //check buildSubMesh on field on cells
948 MEDCouplingFieldDouble *fieldCells=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
949 fieldCells->setMesh(targetMesh);
950 const int elts[3]={1,2,4};
952 MEDCouplingMesh *ret1=fieldCells->buildSubMeshData(elts,elts+3,di);
953 CPPUNIT_ASSERT_EQUAL(3,(int)ret1->getNumberOfCells());
954 CPPUNIT_ASSERT_EQUAL(9,ret1->getNumberOfNodes());
955 CPPUNIT_ASSERT_EQUAL(3,(int)di->getNumberOfTuples());
956 CPPUNIT_ASSERT_EQUAL(1,(int)di->getNumberOfComponents());
957 const int *toCheck=di->getConstPointer();
958 CPPUNIT_ASSERT(std::equal(elts,elts+3,toCheck));
959 MEDCouplingUMesh *ret1DC=dynamic_cast<MEDCouplingUMesh *>(ret1);
960 CPPUNIT_ASSERT(ret1DC);
963 fieldCells->decrRef();
964 //check buildSubMesh on field on nodes
965 MEDCouplingFieldDouble *fieldNodes=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
966 fieldNodes->setMesh(targetMesh);
967 MEDCouplingMesh *ret2=fieldNodes->buildSubMeshData(elts,elts+3,di);
968 MEDCouplingUMesh *ret2DC=dynamic_cast<MEDCouplingUMesh *>(ret2);
969 CPPUNIT_ASSERT(ret2DC);
970 CPPUNIT_ASSERT_EQUAL(3,(int)ret2->getNumberOfCells());
971 CPPUNIT_ASSERT_EQUAL(6,ret2->getNumberOfNodes());
972 CPPUNIT_ASSERT_EQUAL(6,(int)di->getNumberOfTuples());
973 CPPUNIT_ASSERT_EQUAL(1,(int)di->getNumberOfComponents());
974 toCheck=di->getConstPointer();
975 const int expected[6]={1,2,4,5,7,8};
976 CPPUNIT_ASSERT(std::equal(expected,expected+6,toCheck));
979 fieldNodes->decrRef();
980 targetMesh->decrRef();
983 void MEDCouplingBasicsTest1::testExtrudedMesh1()
985 MEDCouplingUMesh *mesh2D=0;
986 MEDCouplingUMesh *mesh3D=build3DExtrudedUMesh_1(mesh2D);
987 MEDCouplingMappedExtrudedMesh *ext=MEDCouplingMappedExtrudedMesh::New(mesh3D,mesh2D,1);
988 CPPUNIT_ASSERT_EQUAL(18,(int)ext->getNumberOfCells());
989 CPPUNIT_ASSERT_EQUAL(60,ext->getNumberOfNodes());
990 DataArrayInt *ids3D=ext->getMesh3DIds();
991 const int ids3DExpected[18]={5,4,3,2,1,0, 11,10,9,8,7,6, 17,16,15,14,13,12};
992 CPPUNIT_ASSERT_EQUAL(18,(int)ids3D->getNumberOfTuples());
993 CPPUNIT_ASSERT_EQUAL(1,(int)ids3D->getNumberOfComponents());
994 CPPUNIT_ASSERT(std::equal(ids3DExpected,ids3DExpected+18,ids3D->getConstPointer()));
995 MEDCouplingUMesh *mesh1D=ext->getMesh1D();
996 CPPUNIT_ASSERT_EQUAL(4,mesh1D->getNumberOfNodes());
997 CPPUNIT_ASSERT_EQUAL(3,(int)mesh1D->getNumberOfCells());
998 const double mesh1DExpected[12]={0.66666666666666663, 1.4583333333333333, 0, 0.66666666666666663, 1.4583333333333333, 1, 0.66666666666666663, 1.4583333333333333, 2, 0.66666666666666663, 1.4583333333333333, 3};
999 DataArrayDouble *mesh1DCoords=mesh1D->getCoords();
1000 CPPUNIT_ASSERT_EQUAL(4,(int)mesh1DCoords->getNumberOfTuples());
1001 CPPUNIT_ASSERT_EQUAL(3,(int)mesh1DCoords->getNumberOfComponents());
1002 CPPUNIT_ASSERT(std::equal(mesh1DExpected,mesh1DExpected+12,mesh1DCoords->getConstPointer()));
1003 DataArrayInt *conn1D=mesh1D->getNodalConnectivity();
1004 CPPUNIT_ASSERT_EQUAL(9,(int)conn1D->getNumberOfTuples());
1005 CPPUNIT_ASSERT_EQUAL(1,(int)conn1D->getNumberOfComponents());
1006 const int conn1DExpected[9]={1,0,1,1,1,2,1,2,3};
1007 CPPUNIT_ASSERT(std::equal(conn1DExpected,conn1DExpected+9,conn1D->getConstPointer()));
1013 void MEDCouplingBasicsTest1::testExtrudedMesh2()
1015 MEDCouplingUMesh *mN,*mTT,*mTF;
1016 build3DExtrudedUMesh_2(mN,mTT,mTF);
1020 DataArrayInt *da=mTT->mergeNodes(1e-12,b,newNbOfNodes);
1024 double pt[3]={300.,300.,0.};
1025 double v[3]={0.,0.,2.};
1026 mTT->findNodesOnPlane(pt,v,1e-12,n);
1027 CPPUNIT_ASSERT_EQUAL(43,(int)n.size());
1028 MEDCouplingUMesh *mTT3dSurf=(MEDCouplingUMesh *)mTT->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
1029 MEDCouplingMappedExtrudedMesh *meTT=MEDCouplingMappedExtrudedMesh::New(mTT,mTT3dSurf,0);
1030 CPPUNIT_ASSERT_EQUAL(200,(int)meTT->getNumberOfCells());
1031 CPPUNIT_ASSERT_EQUAL(10,(int)meTT->getMesh2D()->getNumberOfCells());
1032 CPPUNIT_ASSERT_EQUAL(20,(int)meTT->getMesh1D()->getNumberOfCells());
1033 mTT3dSurf->decrRef();
1036 da=mN->mergeNodes(1e-12,b,newNbOfNodes);
1040 mN->findNodesOnPlane(pt,v,1e-12,n);
1041 CPPUNIT_ASSERT_EQUAL(30,(int)n.size());
1042 MEDCouplingUMesh *mN3dSurf=(MEDCouplingUMesh *)mN->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
1043 MEDCouplingMappedExtrudedMesh *meN=MEDCouplingMappedExtrudedMesh::New(mN,mN3dSurf,0);
1044 CPPUNIT_ASSERT_EQUAL(40,(int)meN->getNumberOfCells());
1045 CPPUNIT_ASSERT_EQUAL(20,(int)meN->getMesh2D()->getNumberOfCells());
1046 CPPUNIT_ASSERT_EQUAL(2,(int)meN->getMesh1D()->getNumberOfCells());
1047 mN3dSurf->decrRef();
1050 da=mTF->mergeNodes(1e-12,b,newNbOfNodes);
1054 mTF->findNodesOnPlane(pt,v,1e-12,n);
1055 CPPUNIT_ASSERT_EQUAL(27,(int)n.size());
1056 MEDCouplingUMesh *mTF3dSurf=(MEDCouplingUMesh *)mTF->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
1057 MEDCouplingMappedExtrudedMesh *meTF=MEDCouplingMappedExtrudedMesh::New(mTF,mTF3dSurf,0);
1058 CPPUNIT_ASSERT_EQUAL(340,(int)meTF->getNumberOfCells());
1059 CPPUNIT_ASSERT_EQUAL(17,(int)meTF->getMesh2D()->getNumberOfCells());
1060 CPPUNIT_ASSERT_EQUAL(20,(int)meTF->getMesh1D()->getNumberOfCells());
1061 mTF3dSurf->decrRef();
1073 * This test check MEDCouplingUMesh::buildExtrudedMesh method.
1075 void MEDCouplingBasicsTest1::testExtrudedMesh3()
1077 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1078 m1->changeSpaceDimension(3);
1079 MEDCouplingUMesh *m2=buildCU1DMesh_U();
1080 m2->changeSpaceDimension(3);
1081 double center[3]={0.,0.,0.};
1082 double vector[3]={0,1,0};
1083 m2->rotate(center,vector,-M_PI/2.);
1084 MEDCouplingUMesh *m3=m1->buildExtrudedMesh(m2,0);
1086 MEDCouplingMappedExtrudedMesh *m4=MEDCouplingMappedExtrudedMesh::New(m3,m1,0);
1087 CPPUNIT_ASSERT_EQUAL(15,(int)m4->getNumberOfCells());
1088 CPPUNIT_ASSERT_EQUAL(5,(int)m4->getMesh2D()->getNumberOfCells());
1089 CPPUNIT_ASSERT_EQUAL(3,(int)m4->getMesh1D()->getNumberOfCells());
1090 const int *m3DIds=m4->getMesh3DIds()->getConstPointer();
1091 for(int i=0;i<15;i++)
1092 CPPUNIT_ASSERT_EQUAL(i,m3DIds[i]);
1094 //some random in cells to check that extrusion alg find it correctly
1095 const int expected1[15]={1,3,2,0,6,5,7,10,11,8,12,9,14,13,4};
1096 m3->renumberCells(expected1,false);
1097 m4=MEDCouplingMappedExtrudedMesh::New(m3,m1,0);
1098 CPPUNIT_ASSERT_EQUAL(15,(int)m4->getNumberOfCells());
1099 CPPUNIT_ASSERT_EQUAL(5,(int)m4->getMesh2D()->getNumberOfCells());
1100 CPPUNIT_ASSERT_EQUAL(3,(int)m4->getMesh1D()->getNumberOfCells());
1101 m3DIds=m4->getMesh3DIds()->getConstPointer();
1102 for(int i=0;i<15;i++)
1103 CPPUNIT_ASSERT_EQUAL(expected1[i],m3DIds[i]);
1106 //play with polygons and polyedrons
1107 std::vector<int> cells(2); cells[0]=2; cells[1]=3;
1108 m1->convertToPolyTypes(&cells[0],&cells[0]+cells.size());
1109 m3=m1->buildExtrudedMesh(m2,0);
1110 CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_HEXA8,(int)m3->getTypeOfCell(0));
1111 CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_PENTA6,(int)m3->getTypeOfCell(1));
1112 CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_POLYHED,(int)m3->getTypeOfCell(2));
1113 CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_POLYHED,(int)m3->getTypeOfCell(3));
1114 CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_HEXA8,(int)m3->getTypeOfCell(4));
1115 m3->renumberCells(expected1,false);
1116 m4=MEDCouplingMappedExtrudedMesh::New(m3,m1,0);
1117 CPPUNIT_ASSERT_EQUAL(15,(int)m4->getNumberOfCells());
1118 CPPUNIT_ASSERT_EQUAL(5,(int)m4->getMesh2D()->getNumberOfCells());
1119 CPPUNIT_ASSERT_EQUAL(3,(int)m4->getMesh1D()->getNumberOfCells());
1120 m3DIds=m4->getMesh3DIds()->getConstPointer();
1121 for(int i=0;i<15;i++)
1122 CPPUNIT_ASSERT_EQUAL(expected1[i],m3DIds[i]);
1131 * This test check MEDCouplingUMesh::buildExtrudedMesh method, but also, MEDCouplingMappedExtrudedMesh following methods :
1132 * getCellContainingPoint getMeasureField getNodeIdsOfCell getCoordinateOfNode getTypeOfCell build3DUnstructuredMesh.
1134 void MEDCouplingBasicsTest1::testExtrudedMesh4()
1136 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1137 std::vector<int> cells(2); cells[0]=2; cells[1]=4;
1138 m1->convertToPolyTypes(&cells[0],&cells[0]+cells.size());
1139 m1->changeSpaceDimension(3);
1140 MEDCouplingUMesh *m2=buildCU1DMesh_U();
1141 m2->changeSpaceDimension(3);
1142 double center[3]={0.,0.,0.};
1143 double vector[3]={0.,1.,0.};
1144 m2->rotate(center,vector,-M_PI/2.);
1146 MEDCouplingUMesh *m3=m1->buildExtrudedMesh(m2,0);
1147 const int expected1[15]= {1,3,2,0,6,5,7,10,11,8,12,9,14,13,4};
1148 const int rexpected1[15]={3, 0, 2, 1, 14, 5, 4, 6, 9, 11, 7, 8, 10, 13, 12};
1149 m3->renumberCells(expected1,false);
1150 MEDCouplingMappedExtrudedMesh *m4=MEDCouplingMappedExtrudedMesh::New(m3,m1,0);
1151 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,m4->getTypeOfCell(0));
1152 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,m4->getTypeOfCell(1));
1153 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYHED,m4->getTypeOfCell(2));
1154 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_PENTA6,m4->getTypeOfCell(7));
1155 MEDCouplingFieldDouble *f=m4->getMeasureField(true);
1156 DataArrayDouble *arr=f->getArray();
1157 CPPUNIT_ASSERT_EQUAL(15,(int)arr->getNumberOfTuples());
1158 CPPUNIT_ASSERT_EQUAL(1,(int)arr->getNumberOfComponents());
1159 const double *arrPtr=arr->getConstPointer();
1160 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};
1161 for(int i=0;i<15;i++)
1162 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[rexpected1[i]],arrPtr[i],1e-16);
1164 MEDCouplingUMesh *m5=m4->build3DUnstructuredMesh();
1166 CPPUNIT_ASSERT(m5->isEqual(m3,1e-12));
1167 f=m5->getMeasureField(true);
1169 arrPtr=arr->getConstPointer();
1170 for(int i=0;i<15;i++)
1171 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[rexpected1[i]],arrPtr[i],1e-16);
1181 void MEDCouplingBasicsTest1::testFindCommonNodes()
1183 DataArrayInt *comm,*commI;
1184 MEDCouplingUMesh *targetMesh=build3DTargetMesh_1();
1185 targetMesh->findCommonNodes(1e-10,-1,comm,commI);
1186 CPPUNIT_ASSERT_EQUAL(1,(int)commI->getNumberOfTuples());
1187 CPPUNIT_ASSERT_EQUAL(0,(int)comm->getNumberOfTuples());
1189 DataArrayInt *o2n=targetMesh->buildNewNumberingFromCommonNodesFormat(comm,commI,newNbOfNodes);
1190 CPPUNIT_ASSERT_EQUAL(27,newNbOfNodes);
1191 CPPUNIT_ASSERT_EQUAL(27,(int)o2n->getNumberOfTuples());
1192 const int o2nExp1[27]=
1194 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
1197 CPPUNIT_ASSERT(std::equal(o2nExp1,o2nExp1+27,o2n->getConstPointer()));
1201 targetMesh->decrRef();
1203 targetMesh=build3DTargetMeshMergeNode_1();
1204 CPPUNIT_ASSERT_EQUAL(31,targetMesh->getNumberOfNodes());
1205 targetMesh->findCommonNodes(1e-10,-1,comm,commI);
1206 CPPUNIT_ASSERT_EQUAL(3,(int)commI->getNumberOfTuples());
1207 CPPUNIT_ASSERT_EQUAL(6,(int)comm->getNumberOfTuples());
1208 const int commExpected[6]={1,27,28,29,23,30};
1209 const int commIExpected[3]={0,4,6};
1210 CPPUNIT_ASSERT(std::equal(commExpected,commExpected+6,comm->getConstPointer()));
1211 CPPUNIT_ASSERT(std::equal(commIExpected,commIExpected+3,commI->getConstPointer()));
1212 o2n=targetMesh->buildNewNumberingFromCommonNodesFormat(comm,commI,newNbOfNodes);
1213 CPPUNIT_ASSERT_EQUAL(31,(int)o2n->getNumberOfTuples());
1214 CPPUNIT_ASSERT_EQUAL(27,newNbOfNodes);
1215 const int o2nExp2[31]=
1217 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
1218 21,22,23,24,25,26,1,1,1,23
1220 CPPUNIT_ASSERT(std::equal(o2nExp2,o2nExp2+31,o2n->getConstPointer()));
1224 targetMesh->decrRef();
1226 targetMesh=build3DTargetMesh_1();
1227 bool areNodesMerged;
1228 unsigned int time=targetMesh->getTimeOfThis();
1229 o2n=targetMesh->mergeNodes(1e-10,areNodesMerged,newNbOfNodes);
1230 targetMesh->updateTime();
1231 CPPUNIT_ASSERT(time==targetMesh->getTimeOfThis());
1232 CPPUNIT_ASSERT(!areNodesMerged);
1233 targetMesh->decrRef();
1236 targetMesh=build3DTargetMeshMergeNode_1();
1237 time=targetMesh->getTimeOfThis();
1238 o2n=targetMesh->mergeNodes(1e-10,areNodesMerged,newNbOfNodes);
1239 targetMesh->updateTime();
1240 CPPUNIT_ASSERT(time!=targetMesh->getTimeOfThis());
1241 CPPUNIT_ASSERT(areNodesMerged);
1242 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,
1243 18,4,5,8,7,13,14,17,16,
1244 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,
1245 18,13,14,17,16,22,23,26,25};
1246 CPPUNIT_ASSERT_EQUAL(72,(int)targetMesh->getNodalConnectivity()->getNumberOfTuples());
1247 CPPUNIT_ASSERT(std::equal(connExp,connExp+72,targetMesh->getNodalConnectivity()->getConstPointer()));
1248 CPPUNIT_ASSERT_EQUAL(27,(int)targetMesh->getCoords()->getNumberOfTuples());
1249 double coordsExp[81]={ 0., 0., 0., 50., 0., 0. , 200., 0., 0. , 0., 50., 0., 50., 50., 0. ,
1250 200., 50., 0., 0., 200., 0., 50., 200., 0. , 200., 200., 0. ,
1251 0., 0., 50., 50., 0., 50. , 200., 0., 50. , 0., 50., 50., 50.,
1252 50., 50. , 200., 50., 50., 0., 200., 50., 50., 200., 50. ,
1253 200., 200., 50. , 0., 0., 200., 50., 0., 200. , 200., 0., 200.
1254 , 0., 50., 200., 50., 50., 200. , 200., 50., 200.,
1255 0., 200., 200., 50., 200., 200. , 200., 200., 200. };
1256 CPPUNIT_ASSERT(std::equal(coordsExp,coordsExp+81,targetMesh->getCoords()->getConstPointer()));
1257 targetMesh->decrRef();
1260 targetMesh=build2DTargetMeshMergeNode_1();
1261 CPPUNIT_ASSERT_EQUAL(18,targetMesh->getNumberOfNodes());
1262 time=targetMesh->getTimeOfThis();
1263 o2n=targetMesh->mergeNodes(1e-10,areNodesMerged,newNbOfNodes);
1264 CPPUNIT_ASSERT(time!=targetMesh->getTimeOfThis());
1265 CPPUNIT_ASSERT(areNodesMerged);
1266 CPPUNIT_ASSERT_EQUAL(9,targetMesh->getNumberOfNodes());
1267 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};
1268 CPPUNIT_ASSERT_EQUAL(23,(int)targetMesh->getNodalConnectivity()->getNumberOfTuples());
1269 CPPUNIT_ASSERT(std::equal(connExp2,connExp2+23,targetMesh->getNodalConnectivity()->getConstPointer()));
1270 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};
1271 CPPUNIT_ASSERT_EQUAL(9,(int)targetMesh->getCoords()->getNumberOfTuples());
1272 CPPUNIT_ASSERT(std::equal(coordsExp2,coordsExp2+18,targetMesh->getCoords()->getConstPointer()));
1273 targetMesh->decrRef();
1277 void MEDCouplingBasicsTest1::testCheckButterflyCells()
1279 std::vector<int> cells;
1280 MEDCouplingUMesh *sourceMesh=build2DTargetMesh_1();
1281 sourceMesh->checkButterflyCells(cells);
1282 CPPUNIT_ASSERT(cells.empty());
1283 int *pt=sourceMesh->getNodalConnectivity()->getPointer();
1284 std::swap(pt[15],pt[16]);
1285 sourceMesh->checkButterflyCells(cells);
1286 CPPUNIT_ASSERT_EQUAL(1,(int)cells.size());
1287 CPPUNIT_ASSERT_EQUAL(3,cells[0]);
1289 std::swap(pt[15],pt[16]);
1290 sourceMesh->checkButterflyCells(cells);
1291 CPPUNIT_ASSERT(cells.empty());
1292 sourceMesh->decrRef();
1294 sourceMesh=build3DSurfTargetMesh_1();
1295 sourceMesh->checkButterflyCells(cells);
1296 CPPUNIT_ASSERT(cells.empty());
1297 pt=sourceMesh->getNodalConnectivity()->getPointer();
1298 std::swap(pt[15],pt[16]);
1299 sourceMesh->checkButterflyCells(cells);
1300 CPPUNIT_ASSERT_EQUAL(1,(int)cells.size());
1301 CPPUNIT_ASSERT_EQUAL(3,cells[0]);
1303 std::swap(pt[15],pt[16]);
1304 sourceMesh->checkButterflyCells(cells);
1305 CPPUNIT_ASSERT(cells.empty());
1306 sourceMesh->decrRef();
1309 void MEDCouplingBasicsTest1::testMergeMesh1()
1311 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1312 MEDCouplingUMesh *m2=build2DSourceMesh_1();
1313 const double vec[2]={1.,0.};
1315 MEDCouplingMesh *m3=m1->mergeMyselfWith(m2);
1316 MEDCouplingUMesh *m3C=dynamic_cast<MEDCouplingUMesh *>(m3);
1317 CPPUNIT_ASSERT(m3C);
1318 m3->checkConsistencyLight();
1319 MEDCouplingUMesh *m4=build2DTargetMeshMerged_1();
1320 CPPUNIT_ASSERT(m3->isEqual(m4,1.e-12));
1324 DataArrayInt *da=m3C->mergeNodes(1.e-12,isMerged,newNbOfNodes);
1325 CPPUNIT_ASSERT_EQUAL(11,m3C->getNumberOfNodes());
1326 CPPUNIT_ASSERT_EQUAL(11,newNbOfNodes);
1327 CPPUNIT_ASSERT(isMerged);
1334 void MEDCouplingBasicsTest1::testMergeMeshOnSameCoords1()
1336 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1337 MEDCouplingUMesh *m2=build2DTargetMesh_1();
1338 std::vector<int> cells(5);
1339 for(int i=0;i<5;i++)
1341 m2->convertToPolyTypes(&cells[0],&cells[0]+cells.size());
1342 m1->tryToShareSameCoords(*m2,1e-12);
1343 MEDCouplingUMesh *m3=build2DTargetMesh_1();
1344 m3->tryToShareSameCoords(*m2,1e-12);
1345 std::vector<const MEDCouplingUMesh *> meshes;
1346 meshes.push_back(m1); meshes.push_back(m2); meshes.push_back(m3);
1347 MEDCouplingUMesh *m4=MEDCouplingUMesh::MergeUMeshesOnSameCoords(meshes);
1348 m4->checkConsistencyLight();
1349 CPPUNIT_ASSERT(m4->getCoords()==m1->getCoords());
1350 CPPUNIT_ASSERT_EQUAL(15,(int)m4->getNumberOfCells());
1351 const int cells1[5]={0,1,2,3,4};
1352 MEDCouplingPointSet *m1_1=m4->buildPartOfMySelf(cells1,cells1+5,true);
1353 m1_1->setName(m1->getName().c_str());
1354 CPPUNIT_ASSERT(m1->isEqual(m1_1,1e-12));
1355 const int cells2[5]={5,6,7,8,9};
1356 MEDCouplingPointSet *m2_1=m4->buildPartOfMySelf(cells2,cells2+5,true);
1357 m2_1->setName(m2->getName().c_str());
1358 CPPUNIT_ASSERT(m2->isEqual(m2_1,1e-12));
1359 const int cells3[5]={10,11,12,13,14};
1360 MEDCouplingPointSet *m3_1=m4->buildPartOfMySelf(cells3,cells3+5,true);
1361 m3_1->setName(m3->getName().c_str());
1362 CPPUNIT_ASSERT(m3->isEqual(m3_1,1e-12));
1363 m1_1->decrRef(); m2_1->decrRef(); m3_1->decrRef();
1371 void MEDCouplingBasicsTest1::testMergeField1()
1373 MEDCouplingUMesh *m1=build2DTargetMesh_1();
1374 MEDCouplingUMesh *m2=build2DSourceMesh_1();
1375 const double vec[2]={1.,0.};
1377 MEDCouplingFieldDouble *f1=m1->getMeasureField(true);
1378 MEDCouplingFieldDouble *f2=m2->getMeasureField(true);
1379 MEDCouplingFieldDouble *f3=MEDCouplingFieldDouble::MergeFields(f1,f2);
1380 f3->checkConsistencyLight();
1381 MEDCouplingUMesh *m4=build2DTargetMeshMerged_1();
1382 CPPUNIT_ASSERT(f3->getMesh()->isEqual(m4,1.e-12));
1383 std::string name=f3->getName();
1384 CPPUNIT_ASSERT(name=="MeasureOfMesh_");
1385 CPPUNIT_ASSERT(f3->getTypeOfField()==ON_CELLS);
1386 CPPUNIT_ASSERT(f3->getTimeDiscretization()==ONE_TIME);
1387 CPPUNIT_ASSERT_EQUAL(1,(int)f3->getNumberOfComponents());
1388 CPPUNIT_ASSERT_EQUAL(7,(int)f3->getNumberOfTuples());
1389 double values[7]={0.25,0.125,0.125,0.25,0.25,0.5,0.5};
1390 const double *tmp=f3->getArray()->getConstPointer();
1391 std::transform(tmp,tmp+7,values,values,std::minus<double>());
1392 std::transform(values,values+7,values,std::ptr_fun<double,double>(fabs));
1393 double max=*std::max_element(values,values+7);
1394 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1403 bool func1(const double *pt, double *res);
1404 bool func2(const double *pt, double *res);
1405 bool func3(const double *pt, double *res);
1406 bool func4(const double *pt, double *res);
1408 bool func1(const double *pt, double *res)
1414 bool func2(const double *pt, double *res)
1417 res[1]=2.*(pt[0]+pt[1]);
1421 bool func3(const double *pt, double *res)
1423 if(fabs(pt[0]-0.2)<1e-12)
1425 res[0]=1./(pt[0]-0.2);
1429 void MEDCouplingBasicsTest1::testFillFromAnalytic()
1431 MEDCouplingUMesh *m=build2DTargetMesh_1();
1432 m->setTime(3.4,5,6); m->setTimeUnit("us");
1434 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_CELLS,1,func1);
1435 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.4,f1->getTime(a,b),1.e-14);
1436 CPPUNIT_ASSERT_EQUAL(5,a); CPPUNIT_ASSERT_EQUAL(6,b);
1437 CPPUNIT_ASSERT_EQUAL(std::string(f1->getTimeUnit()),std::string("us"));
1438 f1->checkConsistencyLight();
1439 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_CELLS);
1440 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1441 CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1442 CPPUNIT_ASSERT_EQUAL(5,(int)f1->getNumberOfTuples());
1443 double values1[5]={-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9};
1444 const double *tmp=f1->getArray()->getConstPointer();
1445 std::transform(tmp,tmp+5,values1,values1,std::minus<double>());
1446 std::transform(values1,values1+5,values1,std::ptr_fun<double,double>(fabs));
1447 double max=*std::max_element(values1,values1+5);
1448 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1451 f1=m->fillFromAnalytic(ON_NODES,1,func1);
1452 f1->checkConsistencyLight();
1453 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1454 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1455 CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1456 CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1457 double values2[9]={-0.6,-0.1,0.4,-0.1,0.4,0.9,0.4,0.9,1.4};
1458 tmp=f1->getArray()->getConstPointer();
1459 std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
1460 std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
1461 max=*std::max_element(values2,values2+9);
1462 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1465 f1=m->fillFromAnalytic(ON_NODES,2,func2);
1466 f1->checkConsistencyLight();
1467 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1468 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1469 CPPUNIT_ASSERT_EQUAL(2,(int)f1->getNumberOfComponents());
1470 CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1471 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};
1472 tmp=f1->getArray()->getConstPointer();
1473 std::transform(tmp,tmp+18,values3,values3,std::minus<double>());
1474 std::transform(values3,values3+18,values3,std::ptr_fun<double,double>(fabs));
1475 max=*std::max_element(values3,values3+18);
1476 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1478 f1->accumulate(values4);
1479 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.6,values4[0],1.e-12);
1480 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.2,values4[1],1.e-12);
1481 f1->integral(true,values4);
1482 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,values4[0],1.e-12);
1483 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,values4[1],1.e-12);
1486 CPPUNIT_ASSERT_THROW(f1=m->fillFromAnalytic(ON_NODES,1,func3),INTERP_KERNEL::Exception);
1491 void MEDCouplingBasicsTest1::testFillFromAnalytic2()
1493 MEDCouplingUMesh *m=build2DTargetMesh_1();
1494 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_CELLS,1,"y+x");
1495 f1->checkConsistencyLight();
1496 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_CELLS);
1497 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1498 CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1499 CPPUNIT_ASSERT_EQUAL(5,(int)f1->getNumberOfTuples());
1500 double values1[5]={-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9};
1501 const double *tmp=f1->getArray()->getConstPointer();
1502 std::transform(tmp,tmp+5,values1,values1,std::minus<double>());
1503 std::transform(values1,values1+5,values1,std::ptr_fun<double,double>(fabs));
1504 double max=*std::max_element(values1,values1+5);
1505 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1508 f1=m->fillFromAnalytic(ON_NODES,1,"y+2*x");
1509 f1->checkConsistencyLight();
1510 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1511 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1512 CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1513 CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1514 double values2[9]={-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1};
1515 tmp=f1->getArray()->getConstPointer();
1516 std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
1517 std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
1518 max=*std::max_element(values2,values2+9);
1519 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1521 f1=m->fillFromAnalytic(ON_NODES,1,"2.*x+y");
1522 f1->checkConsistencyLight();
1523 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1524 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1525 CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1526 CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1527 tmp=f1->getArray()->getConstPointer();
1528 double values2Bis[9]={-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1};
1529 std::transform(tmp,tmp+9,values2Bis,values2Bis,std::minus<double>());
1530 std::transform(values2,values2+9,values2Bis,std::ptr_fun<double,double>(fabs));
1531 max=*std::max_element(values2Bis,values2Bis+9);
1532 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1535 f1=m->fillFromAnalytic(ON_NODES,2,"(x+y)*IVec+2*(x+y)*JVec");
1536 f1->checkConsistencyLight();
1537 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1538 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1539 CPPUNIT_ASSERT_EQUAL(2,(int)f1->getNumberOfComponents());
1540 CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1541 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};
1542 tmp=f1->getArray()->getConstPointer();
1543 std::transform(tmp,tmp+18,values3,values3,std::minus<double>());
1544 std::transform(values3,values3+18,values3,std::ptr_fun<double,double>(fabs));
1545 max=*std::max_element(values3,values3+18);
1546 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1548 f1->accumulate(values4);
1549 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.6,values4[0],1.e-12);
1550 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.2,values4[1],1.e-12);
1551 f1->integral(true,values4);
1552 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,values4[0],1.e-12);
1553 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,values4[1],1.e-12);
1556 CPPUNIT_ASSERT_THROW(f1=m->fillFromAnalytic(ON_NODES,1,"1./(x-0.2)"),INTERP_KERNEL::Exception);
1561 void MEDCouplingBasicsTest1::testApplyFunc()
1563 MEDCouplingUMesh *m=build2DTargetMesh_1();
1564 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,2,func2);
1565 f1->checkConsistencyLight();
1566 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1567 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1568 CPPUNIT_ASSERT_EQUAL(2,(int)f1->getNumberOfComponents());
1569 CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1570 f1->applyFunc(1,func1);
1571 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1572 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1573 CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1574 CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1575 double values1[9]={-1.8,-0.3,1.2,-0.3,1.2,2.7,1.2,2.7,4.2};
1576 const double *tmp=f1->getArray()->getConstPointer();
1577 std::transform(tmp,tmp+9,values1,values1,std::minus<double>());
1578 std::transform(values1,values1+9,values1,std::ptr_fun<double,double>(fabs));
1579 double max=*std::max_element(values1,values1+9);
1580 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1585 void MEDCouplingBasicsTest1::testApplyFunc2()
1587 MEDCouplingUMesh *m=build2DTargetMesh_1();
1588 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,2,func2);
1589 f1->checkConsistencyLight();
1590 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1591 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1592 CPPUNIT_ASSERT_EQUAL(2,(int)f1->getNumberOfComponents());
1593 CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1595 MEDCouplingFieldDouble *f2=f1->clone(true);
1596 CPPUNIT_ASSERT_THROW(f2->applyFunc(1,"a+b+c+d"),INTERP_KERNEL::Exception);
1597 CPPUNIT_ASSERT_THROW(f2->applyFunc(1,"a/0"),INTERP_KERNEL::Exception);
1598 CPPUNIT_ASSERT_THROW(f2->applyFunc("a/0"),INTERP_KERNEL::Exception);
1599 f2->applyFunc("abs(u)^2.4+2*u");
1600 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1601 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1602 CPPUNIT_ASSERT_EQUAL(2,(int)f1->getNumberOfComponents());
1603 CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1604 double values2[18]={-0.9065304805418678, -0.85105859001709905, -0.19601892829446504, -0.37898777756476987,
1605 0.91090317490482353, 2.1853504664669781, -0.19601892829446504, -0.37898777756476987,
1606 0.91090317490482353, 2.1853504664669781, 2.5765725275664879, 7.6987743736515295,
1607 0.91090317490482353, 2.1853504664669781, 2.5765725275664879, 7.6987743736515295,
1608 5.0423700574830965, 17.435300118916864};
1609 const double *tmp=f2->getArray()->getConstPointer();
1610 std::transform(tmp,tmp+18,values2,values2,std::minus<double>());
1611 std::transform(values2,values2+18,values2,std::ptr_fun<double,double>(fabs));
1612 double max=*std::max_element(values2,values2+18);
1613 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1616 f1->applyFunc(1,"x+y");
1617 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1618 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1619 CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1620 CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1621 double values1[9]={-1.8,-0.3,1.2,-0.3,1.2,2.7,1.2,2.7,4.2};
1622 tmp=f1->getArray()->getConstPointer();
1623 std::transform(tmp,tmp+9,values1,values1,std::minus<double>());
1624 std::transform(values1,values1+9,values1,std::ptr_fun<double,double>(fabs));
1625 max=*std::max_element(values1,values1+9);
1626 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1631 void MEDCouplingBasicsTest1::testOperationsOnFields()
1633 MEDCouplingUMesh *m=build2DTargetMesh_1();
1634 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,1,func1);
1635 MEDCouplingFieldDouble *f2=m->fillFromAnalytic(ON_NODES,1,func1);
1636 f1->checkConsistencyLight();
1637 f2->checkConsistencyLight();
1638 MEDCouplingFieldDouble *f3=(*f1)+(*f2);
1639 f3->checkConsistencyLight();
1640 CPPUNIT_ASSERT(f3->getTypeOfField()==ON_NODES);
1641 CPPUNIT_ASSERT(f3->getTimeDiscretization()==ONE_TIME);
1642 double values1[9]={-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8};
1643 const double *tmp=f3->getArray()->getConstPointer();
1644 std::transform(tmp,tmp+9,values1,values1,std::minus<double>());
1645 std::transform(values1,values1+9,values1,std::ptr_fun<double,double>(fabs));
1646 double max=*std::max_element(values1,values1+9);
1647 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1651 f3->checkConsistencyLight();
1652 CPPUNIT_ASSERT(f3->getTypeOfField()==ON_NODES);
1653 CPPUNIT_ASSERT(f3->getTimeDiscretization()==ONE_TIME);
1654 double values2[9]={0.36,0.01,0.16,0.01,0.16,0.81,0.16,0.81,1.96};
1655 tmp=f3->getArray()->getConstPointer();
1656 std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
1657 std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
1658 max=*std::max_element(values2,values2+9);
1659 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1663 MEDCouplingFieldDouble *f4=(*f1)-(*f3);
1664 f4->checkConsistencyLight();
1665 CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1666 CPPUNIT_ASSERT(f4->getTimeDiscretization()==ONE_TIME);
1667 double values3[9]={0.6,0.1,-0.4,0.1,-0.4,-0.9,-0.4,-0.9,-1.4};
1668 tmp=f4->getArray()->getConstPointer();
1669 std::transform(tmp,tmp+9,values3,values3,std::minus<double>());
1670 std::transform(values3,values3+9,values3,std::ptr_fun<double,double>(fabs));
1671 max=*std::max_element(values3,values3+9);
1672 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1678 f4->checkConsistencyLight();
1679 CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1680 CPPUNIT_ASSERT(f4->getTimeDiscretization()==ONE_TIME);
1681 tmp=f4->getArray()->getConstPointer();
1682 for(int i=0;i<9;i++)
1683 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.,tmp[i],1.e-12);
1687 f4=f2->buildNewTimeReprFromThis(NO_TIME,false);
1688 f4->checkConsistencyLight();
1689 CPPUNIT_ASSERT(f4->getArray()==f2->getArray());
1690 CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1691 CPPUNIT_ASSERT(f4->getTimeDiscretization()==NO_TIME);
1692 CPPUNIT_ASSERT_THROW(f3=(*f1)+(*f4),INTERP_KERNEL::Exception);
1693 MEDCouplingFieldDouble *f5=f4->buildNewTimeReprFromThis(ONE_TIME,false);
1694 CPPUNIT_ASSERT(f4->getArray()==f5->getArray());
1695 CPPUNIT_ASSERT(f5->getTypeOfField()==ON_NODES);
1696 CPPUNIT_ASSERT(f5->getTimeDiscretization()==ONE_TIME);
1698 tmp=f3->getArray()->getConstPointer();
1699 double values4[9]={-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8};
1700 std::transform(tmp,tmp+9,values4,values4,std::minus<double>());
1701 std::transform(values4,values4+9,values4,std::ptr_fun<double,double>(fabs));
1702 max=*std::max_element(values4,values4+9);
1703 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1708 f4=f2->buildNewTimeReprFromThis(NO_TIME,true);
1709 f4->checkConsistencyLight();
1710 CPPUNIT_ASSERT(f4->getArray()!=f2->getArray());
1711 CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1712 CPPUNIT_ASSERT(f4->getTimeDiscretization()==NO_TIME);
1713 CPPUNIT_ASSERT_THROW(f3=(*f1)+(*f4),INTERP_KERNEL::Exception);
1714 f5=f4->buildNewTimeReprFromThis(ONE_TIME,true);
1715 CPPUNIT_ASSERT(f4->getArray()!=f5->getArray());
1716 CPPUNIT_ASSERT(f2->getArray()!=f5->getArray());
1717 CPPUNIT_ASSERT(f5->getTypeOfField()==ON_NODES);
1718 CPPUNIT_ASSERT(f5->getTimeDiscretization()==ONE_TIME);
1720 tmp=f3->getArray()->getConstPointer();
1721 double values5[9]={-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8};
1722 std::transform(tmp,tmp+9,values5,values5,std::minus<double>());
1723 std::transform(values5,values5+9,values5,std::ptr_fun<double,double>(fabs));
1724 max=*std::max_element(values5,values5+9);
1725 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1735 void MEDCouplingBasicsTest1::testOperationsOnFields2()
1737 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1738 m->setTime(3.4,5,6); m->setTimeUnit("us");
1740 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,1,"x+y+z");
1741 MEDCouplingFieldDouble *f2=m->fillFromAnalytic(ON_NODES,1,"a*a+b+c*c");
1742 MEDCouplingFieldDouble *f3=(*f1)/(*f2);
1743 f3->checkConsistencyLight();
1744 CPPUNIT_ASSERT(f3->getTypeOfField()==ON_NODES);
1745 CPPUNIT_ASSERT(f3->getTimeDiscretization()==ONE_TIME);
1746 const double expected1[9]={-2.4999999999999991, 1.2162162162162162, 0.77868852459016391,
1747 0.7407407407407407, 1.129032258064516, 0.81632653061224492,
1748 0.86538461538461531, 1.0919540229885056, 0.84302325581395343};
1749 CPPUNIT_ASSERT_EQUAL(1,(int)f3->getNumberOfComponents());
1750 CPPUNIT_ASSERT_EQUAL(9,(int)f3->getNumberOfTuples());
1751 const double *val=f3->getArray()->getConstPointer();
1752 for(int i=0;i<9;i++)
1753 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1.e-12);
1758 f1=m->buildOrthogonalField();
1759 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.4,f1->getTime(a,b),1.e-14);
1760 CPPUNIT_ASSERT_EQUAL(5,a); CPPUNIT_ASSERT_EQUAL(6,b);
1761 CPPUNIT_ASSERT_EQUAL(std::string(f1->getTimeUnit()),std::string("us"));
1762 f2=m->fillFromAnalytic(ON_CELLS,1,"x");
1764 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};
1765 val=f3->getArray()->getConstPointer();
1766 for(int i=0;i<15;i++)
1767 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1.e-12);
1771 val=f3->getArray()->getConstPointer();
1772 for(int i=0;i<15;i++)
1773 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1.e-12);
1782 void MEDCouplingBasicsTest1::testOperationsOnFields3()
1784 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1785 MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,1,"x+y+z");
1786 MEDCouplingFieldDouble *f2=m->fillFromAnalytic(ON_NODES,1,"a*a+b+c*c");
1788 f1->checkConsistencyLight();
1789 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1790 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1791 const double expected1[9]={-2.4999999999999991, 1.2162162162162162, 0.77868852459016391,
1792 0.7407407407407407, 1.129032258064516, 0.81632653061224492,
1793 0.86538461538461531, 1.0919540229885056, 0.84302325581395343};
1794 CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1795 CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1796 const double *val=f1->getArray()->getConstPointer();
1797 for(int i=0;i<9;i++)
1798 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1.e-12);
1802 f1=m->buildOrthogonalField();
1803 f2=m->fillFromAnalytic(ON_CELLS,1,"x");
1805 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};
1806 val=f1->getArray()->getConstPointer();
1807 for(int i=0;i<15;i++)
1808 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1.e-12);
1811 f1=m->buildOrthogonalField();
1812 CPPUNIT_ASSERT_THROW((*f2)*=(*f1),INTERP_KERNEL::Exception);
1820 * Check of LINEAR_TIME and CONST_ON_TIME_INTERVAL policies
1822 void MEDCouplingBasicsTest1::testOperationsOnFields4()
1824 MEDCouplingUMesh *m=build2DTargetMesh_1();
1825 int nbOfCells=m->getNumberOfCells();
1826 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,CONST_ON_TIME_INTERVAL);
1828 DataArrayDouble *array=DataArrayDouble::New();
1829 array->alloc(nbOfCells,3);
1830 f1->setArray(array);
1831 CPPUNIT_ASSERT_THROW(f1->setEndArray(array),INTERP_KERNEL::Exception);
1832 CPPUNIT_ASSERT_THROW(f1->getEndArray(),INTERP_KERNEL::Exception);
1834 double *tmp=array->getPointer();
1835 const double arr1[15]={0.,10.,20.,1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.};
1836 const double arr2[15]={5.,15.,25.,6.,16.,26.,7.,17.,27.,8.,18.,28.,9.,19.,29.};
1837 std::copy(arr1,arr1+15,tmp);
1838 f1->setStartTime(2.,0,0);
1839 f1->setEndTime(3.,0,0);
1840 f1->checkConsistencyLight();
1842 const double pos[2]={0.3,-0.2};
1843 f1->getValueOn(pos,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 f1->getValueOn(pos,2.2,res);
1849 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[3],res[0],1.e-12);
1850 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[4],res[1],1.e-12);
1851 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[5],res[2],1.e-12);
1852 std::fill(res,res+3,0.);
1853 CPPUNIT_ASSERT_THROW(f1->getValueOn(pos,3.2,res),INTERP_KERNEL::Exception);
1854 MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
1856 f2->setArray(f1->getArray());
1857 f2->setStartTime(2.,3,0);
1858 f2->setEndTime(4.,13,0);
1859 CPPUNIT_ASSERT_THROW(f2->checkConsistencyLight(),INTERP_KERNEL::Exception);
1860 DataArrayDouble *array2=DataArrayDouble::New();
1861 array2->alloc(nbOfCells,3);
1862 tmp=array2->getPointer();
1863 std::copy(arr2,arr2+15,tmp);
1864 f2->setEndArray(array2);
1866 f2->checkConsistencyLight();
1868 std::fill(res,res+3,0.);
1869 f2->getValueOn(pos,3.21,res);
1870 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.025,res[0],1.e-12);
1871 CPPUNIT_ASSERT_DOUBLES_EQUAL(14.025,res[1],1.e-12);
1872 CPPUNIT_ASSERT_DOUBLES_EQUAL(24.025,res[2],1.e-12);
1873 MEDCouplingFieldDouble *f3=f2->clone(true);
1874 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-12));
1875 f3->getEndArray()->getPointer()[0]=5.001;
1876 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-12));
1877 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1878 f3->setStartTime(2.1,3,0);
1879 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1880 f3->setStartTime(2.,3,0);
1881 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1882 f3->setStartTime(2.,4,0);
1883 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1884 f3->setStartTime(2.,3,1);
1885 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1886 f3->setStartTime(2.,3,0);
1887 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1888 f3->setEndTime(4.1,13,0);
1889 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1890 f3->setEndTime(4.,13,0);
1891 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1892 f3->setEndTime(4.,14,0);
1893 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1894 f3->setEndTime(4.,13,1);
1895 CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1896 f3->setEndTime(4.,13,0);
1897 CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1899 MEDCouplingFieldDouble *f4=(*f2)+(*f2);
1900 std::fill(res,res+3,0.);
1901 f4->getValueOn(pos,3.21,res);
1902 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.05,res[0],1.e-12);
1903 CPPUNIT_ASSERT_DOUBLES_EQUAL(28.05,res[1],1.e-12);
1904 CPPUNIT_ASSERT_DOUBLES_EQUAL(48.05,res[2],1.e-12);
1906 std::fill(res,res+3,0.);
1907 f4->getValueOn(pos,3.21,res);
1908 CPPUNIT_ASSERT_DOUBLES_EQUAL(12.075,res[0],1.e-12);
1909 CPPUNIT_ASSERT_DOUBLES_EQUAL(42.075,res[1],1.e-12);
1910 CPPUNIT_ASSERT_DOUBLES_EQUAL(72.075,res[2],1.e-12);
1918 bool func4(const double *pt, double *res)
1920 res[0]=pt[0]+pt[1]+pt[2];
1924 void MEDCouplingBasicsTest1::testMergeNodesOnField()
1927 MEDCouplingUMesh *targetMesh=build3DTargetMeshMergeNode_1();
1928 MEDCouplingFieldDouble *f1=targetMesh->fillFromAnalytic(ON_NODES,1,func4);
1929 f1->mergeNodes(1e-10);
1931 targetMesh->decrRef();
1933 targetMesh=build3DTargetMeshMergeNode_1();
1934 f1=targetMesh->fillFromAnalytic(ON_NODES,1,func4);
1935 tmp=f1->getArray()->getPointer();
1937 f1->mergeNodes(1e-10);
1939 targetMesh->decrRef();
1941 targetMesh=build3DTargetMeshMergeNode_1();
1942 f1=targetMesh->fillFromAnalytic(ON_NODES,1,func4);
1943 tmp=f1->getArray()->getPointer();
1945 CPPUNIT_ASSERT_THROW(f1->mergeNodes(1e-10),INTERP_KERNEL::Exception);
1947 targetMesh->decrRef();
1950 void MEDCouplingBasicsTest1::testCheckConsecutiveCellTypes()
1952 MEDCouplingUMesh *sourceMesh=build2DSourceMesh_1();
1953 MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
1954 CPPUNIT_ASSERT(sourceMesh->checkConsecutiveCellTypes());
1955 const INTERP_KERNEL::NormalizedCellType order1[]={INTERP_KERNEL::NORM_TRI3, INTERP_KERNEL::NORM_QUAD4};
1956 const INTERP_KERNEL::NormalizedCellType order2[]={INTERP_KERNEL::NORM_QUAD4, INTERP_KERNEL::NORM_TRI3};
1957 CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypes());
1958 CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypesAndOrder(order1,order1+2));
1959 CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypesAndOrder(order2,order2+2));
1960 DataArrayInt *da=targetMesh->getRenumArrForConsecutiveCellTypesSpec(order1,order1+2);
1961 CPPUNIT_ASSERT_EQUAL(5,(int)da->getNumberOfTuples());
1962 CPPUNIT_ASSERT_EQUAL(1,(int)da->getNumberOfComponents());
1963 const int expected1[5]={2,0,1,3,4};
1964 CPPUNIT_ASSERT(std::equal(expected1,expected1+5,da->getConstPointer()));
1966 da=targetMesh->getRenumArrForConsecutiveCellTypesSpec(order2,order2+2);
1967 CPPUNIT_ASSERT_EQUAL(5,(int)da->getNumberOfTuples());
1968 CPPUNIT_ASSERT_EQUAL(1,(int)da->getNumberOfComponents());
1969 const int expected2[5]={0,3,4,1,2};
1970 CPPUNIT_ASSERT(std::equal(expected2,expected2+5,da->getConstPointer()));
1972 const int renumber1[5]={4,0,1,2,3};
1973 targetMesh->renumberCells(renumber1,false);
1974 CPPUNIT_ASSERT(targetMesh->checkConsecutiveCellTypes());
1975 CPPUNIT_ASSERT(targetMesh->checkConsecutiveCellTypesAndOrder(order1,order1+2));
1976 CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypesAndOrder(order2,order2+2));
1977 targetMesh->decrRef();
1978 sourceMesh->decrRef();
1981 void MEDCouplingBasicsTest1::testRearrange2ConsecutiveCellTypes()
1983 MEDCouplingUMesh *m1_1=build2DSourceMesh_1();
1984 MEDCouplingUMesh *m2_1=build2DTargetMesh_1();
1985 DataArrayInt *arr1=m1_1->rearrange2ConsecutiveCellTypes();
1986 MEDCouplingUMesh *m1_2=build2DSourceMesh_1();
1987 CPPUNIT_ASSERT(m1_2->isEqual(m1_1,1e-12));
1988 const int expected1[2]={0,1};
1989 CPPUNIT_ASSERT_EQUAL(2,(int)arr1->getNumberOfTuples());
1990 CPPUNIT_ASSERT_EQUAL(1,(int)arr1->getNumberOfComponents());
1991 CPPUNIT_ASSERT(std::equal(expected1,expected1+2,arr1->getConstPointer()));
1993 const int expected2[5]={0,3,4,1,2};
1994 arr1=m2_1->rearrange2ConsecutiveCellTypes();
1995 CPPUNIT_ASSERT_EQUAL(5,(int)arr1->getNumberOfTuples());
1996 CPPUNIT_ASSERT_EQUAL(1,(int)arr1->getNumberOfComponents());
1997 CPPUNIT_ASSERT(std::equal(expected2,expected2+5,arr1->getConstPointer()));
1998 MEDCouplingUMesh *m2_2=build2DTargetMesh_1();
1999 CPPUNIT_ASSERT_EQUAL(5,(int)arr1->getNumberOfTuples());
2000 CPPUNIT_ASSERT_EQUAL(1,(int)arr1->getNumberOfComponents());
2001 CPPUNIT_ASSERT(std::equal(expected2,expected2+5,arr1->getConstPointer()));
2002 CPPUNIT_ASSERT(!m2_2->isEqual(m2_1,1e-12));
2003 m2_2->renumberCells(expected2,false);
2004 CPPUNIT_ASSERT(m2_2->isEqual(m2_1,1e-12));
2012 void MEDCouplingBasicsTest1::testSplitByType()
2014 MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
2015 std::vector<MEDCouplingUMesh *> v=m1->splitByType();
2016 CPPUNIT_ASSERT_EQUAL(3,(int)v.size());
2017 std::vector<const MEDCouplingUMesh *> v2(v.begin(),v.end());
2018 MEDCouplingUMesh *m2=MEDCouplingUMesh::MergeUMeshesOnSameCoords(v2);
2019 m2->setName(m1->getName().c_str());
2020 CPPUNIT_ASSERT(m1->isEqual(m2,1.e-12));
2021 for(std::vector<MEDCouplingUMesh *>::const_iterator iter=v.begin();iter!=v.end();iter++)
2027 void MEDCouplingBasicsTest1::testFuseUMeshesOnSameCoords()
2029 std::vector<const MEDCouplingUMesh *> meshes;
2030 MEDCouplingUMesh *m2=build2DTargetMesh_1();
2031 int cells1[3]={2,3,4};
2032 MEDCouplingPointSet *m3_1=m2->buildPartOfMySelf(cells1,cells1+3,true);
2033 MEDCouplingUMesh *m3=dynamic_cast<MEDCouplingUMesh *>(m3_1);
2035 meshes.push_back(m3);
2036 int cells2[3]={1,2,4};
2037 MEDCouplingPointSet *m4_1=m2->buildPartOfMySelf(cells2,cells2+3,true);
2038 MEDCouplingUMesh *m4=dynamic_cast<MEDCouplingUMesh *>(m4_1);
2040 meshes.push_back(m4);
2041 int cells3[2]={1,2};
2042 MEDCouplingPointSet *m5_1=m2->buildPartOfMySelf(cells3,cells3+2,true);
2043 MEDCouplingUMesh *m5=dynamic_cast<MEDCouplingUMesh *>(m5_1);
2045 meshes.push_back(m5);
2048 std::vector<DataArrayInt *> corr;
2049 MEDCouplingUMesh *m7=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
2050 CPPUNIT_ASSERT_EQUAL(4,(int)m7->getNumberOfCells());
2051 CPPUNIT_ASSERT_EQUAL(3,(int)corr.size());
2052 const int expectedVals1[3]={3,3,2};
2053 const int expectedVals2[3][3]={{0,1,2},{3,0,2},{3,0,111111}};
2054 for(int i=0;i<3;i++)
2056 DataArrayInt *arr=corr[i];
2057 CPPUNIT_ASSERT_EQUAL(1,(int)arr->getNumberOfComponents());
2058 int nbOfVals=expectedVals1[i];
2059 CPPUNIT_ASSERT_EQUAL(nbOfVals,(int)arr->getNumberOfTuples());
2060 const int *vals=arr->getConstPointer();
2061 for(int j=0;j<nbOfVals;j++)
2062 CPPUNIT_ASSERT_EQUAL(expectedVals2[i][j],vals[j]);
2064 std::vector< std::vector<int> > fidsOfGroups;
2065 std::vector<const DataArrayInt *> corr2(corr.begin(),corr.end());
2066 DataArrayInt *arr2=DataArrayInt::MakePartition(corr2,m7->getNumberOfCells(),fidsOfGroups);
2067 const int fidExp[4]={5,1,3,4};
2068 const int fidsGrp[3][3]={{1,3,5},{3,4,5},{4,5,23344}};
2069 CPPUNIT_ASSERT_EQUAL(3,(int)fidsOfGroups.size());
2070 CPPUNIT_ASSERT_EQUAL(1,(int)arr2->getNumberOfComponents());
2071 CPPUNIT_ASSERT_EQUAL(4,(int)arr2->getNumberOfTuples());
2072 CPPUNIT_ASSERT(std::equal(fidExp,fidExp+4,arr2->getConstPointer()));
2073 for(int i=0;i<3;i++)
2075 int nbOfVals=expectedVals1[i];
2076 CPPUNIT_ASSERT_EQUAL(nbOfVals,(int)fidsOfGroups[i].size());
2077 CPPUNIT_ASSERT(std::equal(fidsOfGroups[i].begin(),fidsOfGroups[i].end(),fidsGrp[i]));
2079 for(std::vector<DataArrayInt *>::iterator iter=corr.begin();iter!=corr.end();iter++)
2089 void MEDCouplingBasicsTest1::testFuseUMeshesOnSameCoords2()
2091 MEDCouplingUMesh *m2;
2092 MEDCouplingUMesh *m1=build3DExtrudedUMesh_1(m2);
2094 const int part1[5]={2,3,6,4,10};
2095 MEDCouplingUMesh *m3=(MEDCouplingUMesh *)m1->buildPartOfMySelf(part1,part1+5,true);
2096 const int part2[4]={5,6,4,7};
2097 MEDCouplingUMesh *m4=(MEDCouplingUMesh *)m1->buildPartOfMySelf(part2,part2+4,true);
2098 std::vector<const MEDCouplingUMesh *> meshes;
2099 meshes.push_back(m1);
2100 meshes.push_back(m3);
2101 meshes.push_back(m3);
2102 meshes.push_back(m4);
2103 std::vector<DataArrayInt *> corr;
2104 MEDCouplingUMesh *m5=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
2105 CPPUNIT_ASSERT_EQUAL(18,(int)m5->getNumberOfCells());
2106 std::vector<DataArrayInt *>::iterator it=corr.begin();
2107 const int exp1[4]={18,5,5,4};
2108 const int exp2[4][18]={
2109 {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17},
2110 {2,3,6,4,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
2111 {2,3,6,4,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
2112 {5,6,4,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}
2115 for(;it!=corr.end();it++,i++)
2117 int sz=(*it)->getNumberOfTuples();
2118 CPPUNIT_ASSERT_EQUAL(exp1[i],sz);
2119 CPPUNIT_ASSERT(std::equal(exp2[i],exp2[i]+sz,(*it)->getConstPointer()));
2121 for(it=corr.begin();it!=corr.end();it++)
2129 void MEDCouplingBasicsTest1::testBuildOrthogonalField()
2131 MEDCouplingUMesh *targetMesh=build3DSurfTargetMesh_1();
2132 MEDCouplingFieldDouble *field=targetMesh->buildOrthogonalField();
2133 double expected[3]={0.70710678118654746,0.,-0.70710678118654746};
2134 CPPUNIT_ASSERT_EQUAL(5,(int)field->getNumberOfTuples());
2135 CPPUNIT_ASSERT_EQUAL(3,(int)field->getNumberOfComponents());
2136 const double *vals=field->getArray()->getConstPointer();
2137 for(int i=0;i<15;i++)
2138 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected[i%3],vals[i],1e-12);
2140 targetMesh->decrRef();
2142 double targetCoords[12]={0.,0.,0.,0.5,0.,0.5,1.,0.,1.,0.,1.,0.};
2143 int targetConn[4]={0,1,2,3};
2144 targetMesh=MEDCouplingUMesh::New();
2145 targetMesh->setMeshDimension(2);
2146 targetMesh->allocateCells(1);
2147 targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn);
2148 targetMesh->finishInsertingCells();
2149 DataArrayDouble *myCoords=DataArrayDouble::New();
2150 myCoords->alloc(4,3);
2151 std::copy(targetCoords,targetCoords+12,myCoords->getPointer());
2152 targetMesh->setCoords(myCoords);
2153 myCoords->decrRef();
2154 field=targetMesh->buildOrthogonalField();
2155 CPPUNIT_ASSERT_EQUAL(1,(int)field->getNumberOfTuples());
2156 CPPUNIT_ASSERT_EQUAL(3,(int)field->getNumberOfComponents());
2157 vals=field->getArray()->getConstPointer();
2158 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.70710678118654746,vals[0],1e-12);
2159 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,vals[1],1e-12);
2160 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.70710678118654746,vals[2],1e-12);
2162 targetMesh->decrRef();
2165 void MEDCouplingBasicsTest1::testGetCellsContainingPoint()
2167 MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
2168 double pos[12]={0.,0.,0.4,0.4,0.,0.4,0.1,0.1,0.25,0.,0.65,0.};
2169 MCAuto<DataArrayInt> t1,t2;
2171 targetMesh->getCellsContainingPoints(pos,6,1e-12,t1,t2);
2172 CPPUNIT_ASSERT_EQUAL(6,(int)t1->getNbOfElems());
2173 CPPUNIT_ASSERT_EQUAL(7,(int)t2->getNbOfElems());
2174 const int expectedValues1[6]={0,4,3,0,1,2};
2175 const int expectedValues2[7]={0,1,2,3,4,5,6};
2176 CPPUNIT_ASSERT(std::equal(t1->begin(),t1->end(),expectedValues1));
2177 CPPUNIT_ASSERT(std::equal(t2->begin(),t2->end(),expectedValues2));
2178 //2D with no help of bounding box.
2179 double center[2]={0.2,0.2};
2180 DataArrayDouble::Rotate2DAlg(center,0.78539816339744830962,6,pos,pos);
2181 targetMesh->rotate(center,0,0.78539816339744830962);
2182 targetMesh->getCellsContainingPoints(pos,6,1e-12,t1,t2);
2183 CPPUNIT_ASSERT_EQUAL(6,(int)t1->getNbOfElems());
2184 CPPUNIT_ASSERT_EQUAL(7,(int)t2->getNbOfElems());
2185 CPPUNIT_ASSERT(std::equal(t1->begin(),t1->end(),expectedValues1));
2186 CPPUNIT_ASSERT(std::equal(t2->begin(),t2->end(),expectedValues2));
2188 const double pos1bis[2]={-0.3303300858899107,-0.11819805153394641};
2189 CPPUNIT_ASSERT_EQUAL(-1,targetMesh->getCellContainingPoint(pos1bis,1e-12));
2190 targetMesh->decrRef();
2192 targetMesh=build2DTargetMesh_1();
2193 const double pos2[2]={0.2,-0.05};
2194 std::vector<int> t11;
2196 targetMesh->getCellsContainingPoint(pos2,1e-12,t11);
2197 CPPUNIT_ASSERT_EQUAL(2,(int)t11.size());
2198 const int expectedValues3[2]={0,1};
2199 CPPUNIT_ASSERT(std::equal(t11.begin(),t11.end(),expectedValues3));
2200 const double pos3[2]={0.2,0.2};
2202 targetMesh->getCellsContainingPoint(pos3,1e-12,t11);
2203 CPPUNIT_ASSERT_EQUAL(5,(int)t11.size());
2204 const int expectedValues4[5]={0,1,2,3,4};
2205 CPPUNIT_ASSERT(std::equal(t11.begin(),t11.end(),expectedValues4));
2206 CPPUNIT_ASSERT_EQUAL(0,targetMesh->getCellContainingPoint(pos3,1e-12));
2207 targetMesh->decrRef();
2209 targetMesh=build3DTargetMesh_1();
2210 const double pos4[3]={25.,25.,25.};
2211 CPPUNIT_ASSERT_EQUAL(0,targetMesh->getCellContainingPoint(pos4,1e-12));
2212 const double pos5[3]={50.,50.,50.};
2214 targetMesh->getCellsContainingPoint(pos5,1e-12,t11);
2215 CPPUNIT_ASSERT_EQUAL(8,(int)t11.size());
2216 const int expectedValues5[8]={0,1,2,3,4,5,6,7};
2217 CPPUNIT_ASSERT(std::equal(t11.begin(),t11.end(),expectedValues5));
2218 const double pos6[3]={0., 50., 0.};
2220 targetMesh->getCellsContainingPoint(pos6,1e-12,t11);
2221 CPPUNIT_ASSERT_EQUAL(2,(int)t11.size());
2222 const int expectedValues6[2]={0,2};
2223 CPPUNIT_ASSERT(std::equal(t11.begin(),t11.end(),expectedValues6));
2225 const double pos7[3]={-1.0,-1.0,0.};
2226 CPPUNIT_ASSERT_EQUAL(-1,targetMesh->getCellContainingPoint(pos7,1e-12));
2228 const double center2[3]={0.,0.,0.};
2229 const double vec2[3]={0.,-1.,0.};
2230 targetMesh->rotate(center2,vec2,0.78539816339744830962);
2231 const double pos8[3]={-25,25.,12.};
2232 CPPUNIT_ASSERT_EQUAL(-1,targetMesh->getCellContainingPoint(pos8,1e-12));
2234 targetMesh->decrRef();
2237 void MEDCouplingBasicsTest1::testGetValueOn1()
2239 MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
2240 MEDCouplingFieldDouble *fieldOnCells=MEDCouplingFieldDouble::New(ON_CELLS);
2241 int nbOfCells=targetMesh->getNumberOfCells();
2242 fieldOnCells->setMesh(targetMesh);
2243 DataArrayDouble *array=DataArrayDouble::New();
2244 array->alloc(nbOfCells,2);
2245 fieldOnCells->setArray(array);
2246 double *tmp=array->getPointer();
2247 for(int i=0;i<nbOfCells;i++)
2248 { tmp[2*i]=7.+(double)i; tmp[2*i+1]=17.+(double)i; }
2251 const double pos1[2]={0.25,0.};
2253 fieldOnCells->getValueOn(pos1,res);
2254 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.,res[0],1e-12);
2255 CPPUNIT_ASSERT_DOUBLES_EQUAL(18.,res[1],1e-12);
2257 fieldOnCells->decrRef();
2258 targetMesh->decrRef();
2260 targetMesh=build2DSourceMesh_1();
2261 MEDCouplingFieldDouble *fieldOnNodes=MEDCouplingFieldDouble::New(ON_NODES);
2262 int nbOfNodes=targetMesh->getNumberOfNodes();
2263 fieldOnNodes->setMesh(targetMesh);
2264 array=DataArrayDouble::New();
2265 array->alloc(nbOfNodes,2);
2266 fieldOnNodes->setArray(array);
2267 tmp=array->getPointer();
2268 for(int i=0;i<nbOfNodes;i++)
2269 { tmp[2*i]=17.+(double)i; tmp[2*i+1]=27.+(double)i; }
2272 const double pos2[2]={-0.13333333333333333,-0.13333333333333333};
2273 fieldOnNodes->getValueOn(pos2,res);
2274 CPPUNIT_ASSERT_DOUBLES_EQUAL(17.5,res[0],1e-12);
2275 CPPUNIT_ASSERT_DOUBLES_EQUAL(27.5,res[1],1e-12);
2276 const double pos3[2]={0.033333333333333326,0.36666666666666664};
2277 fieldOnNodes->getValueOn(pos3,res);
2278 CPPUNIT_ASSERT_DOUBLES_EQUAL(18.666666666666667,res[0],1e-12);
2279 CPPUNIT_ASSERT_DOUBLES_EQUAL(28.666666666666667,res[1],1e-12);
2281 fieldOnNodes->decrRef();
2282 targetMesh->decrRef();
2285 void MEDCouplingBasicsTest1::testCMesh0()
2287 MEDCouplingCMesh* mesh=MEDCouplingCMesh::New();
2288 MEDCouplingCMesh* meshEmpty=mesh->clone(true);
2289 CPPUNIT_ASSERT(meshEmpty->isEqual(mesh,1e-12));
2291 DataArrayDouble* coordsX=DataArrayDouble::New();
2292 double arrX[4] = { -1., 1., 2., 4. };
2293 coordsX->useArray(arrX,false, CPP_DEALLOC,4,1);
2294 DataArrayDouble* coordsY=DataArrayDouble::New();
2295 double arrY[4] = { -2., 2., 4., 8. };
2296 coordsY->useArray(arrY,false, CPP_DEALLOC,4,1);
2297 DataArrayDouble* coordsZ=DataArrayDouble::New();
2298 double arrZ[4] = { -3., 3., 6., 12. };
2299 coordsZ->useArray(arrZ,false, CPP_DEALLOC,4,1);
2300 mesh->setCoords(coordsX,coordsY,coordsZ);
2305 MEDCouplingFieldDouble *fieldOnNodes=mesh->fillFromAnalytic(ON_NODES,1,"x+y/2.+z/3.");
2306 CPPUNIT_ASSERT_EQUAL(1,(int)fieldOnNodes->getNumberOfComponents());
2307 CPPUNIT_ASSERT_EQUAL(64,(int)fieldOnNodes->getNumberOfTuples());
2308 const double expected1[64]={-3., -1., 0., 2., -1., 1., 2., 4., 0., 2., 3., 5., 2., 4., 5., 7., -1., 1., 2.,
2309 4., 1., 3., 4., 6., 2., 4., 5., 7., 4., 6., 7., 9., 0., 2., 3., 5., 2., 4., 5.,
2310 7., 3., 5., 6., 8., 5., 7., 8., 10., 2., 4., 5.,
2311 7., 4., 6., 7., 9., 5., 7., 8., 10., 7., 9., 10., 12.};
2312 const double *val=fieldOnNodes->getArray()->getConstPointer();
2313 for(int i=0;i<64;i++)
2314 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1e-12);
2315 double res[1]; //size fieldOnNodes->getNumberOfComponents()
2316 fieldOnNodes->getValueOnPos(1,3,2,&res[0]);
2317 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,res[0],1e-12);
2318 fieldOnNodes->decrRef();
2320 MEDCouplingFieldDouble *fieldOnCells=mesh->fillFromAnalytic(ON_CELLS,1,"x+y/2.+z/3.");
2321 CPPUNIT_ASSERT_EQUAL(1,(int)fieldOnCells->getNumberOfComponents());
2322 CPPUNIT_ASSERT_EQUAL(27,(int)fieldOnCells->getNumberOfTuples());
2323 val=fieldOnCells->getArray()->getConstPointer();
2324 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,
2325 6, 4.5, 6, 7.5, 3, 4.5, 6, 4.5, 6, 7.5, 6, 7.5, 9};
2326 for(int i=0;i<27;i++)
2327 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1e-12);
2328 fieldOnCells->getValueOnPos(1,2,1,&res[0]);
2329 CPPUNIT_ASSERT_DOUBLES_EQUAL(6.,res[0],1e-12);
2330 fieldOnCells->decrRef();
2332 MEDCouplingMesh* meshDeepCopy=mesh->deepCopy();
2333 MEDCouplingCMesh* meshClone=mesh->clone(false);
2335 CPPUNIT_ASSERT_THROW(meshEmpty->copyTinyStringsFrom(0),INTERP_KERNEL::Exception);
2336 meshEmpty->copyTinyStringsFrom(mesh);
2337 //no data in meshEmpty, expected false
2338 CPPUNIT_ASSERT(!meshEmpty->isEqual(mesh,1e-12));
2340 CPPUNIT_ASSERT(meshDeepCopy->isEqual(mesh,1e-12));
2341 meshDeepCopy->copyTinyStringsFrom(mesh);
2342 CPPUNIT_ASSERT(meshDeepCopy->isEqual(mesh,1e-12));
2343 CPPUNIT_ASSERT(meshClone->isEqual(mesh,1e-12));
2345 CPPUNIT_ASSERT_EQUAL(CARTESIAN,mesh->getType());
2346 CPPUNIT_ASSERT_EQUAL(CARTESIAN,meshEmpty->getType());
2347 CPPUNIT_ASSERT_EQUAL(CARTESIAN,meshDeepCopy->getType());
2348 CPPUNIT_ASSERT_EQUAL(CARTESIAN,meshClone->getType());
2351 meshEmpty->decrRef();
2352 meshDeepCopy->decrRef();
2353 meshClone->decrRef();
2356 void MEDCouplingBasicsTest1::testCMesh1()
2358 MEDCouplingCMesh *mesh1,*mesh2,*mesh3;
2359 mesh1=MEDCouplingCMesh::New();
2360 DataArrayDouble* coordsX1=DataArrayDouble::New();
2361 double arrX1[4] = { -1., 1., 2., 4. };
2362 coordsX1->useArray(arrX1,false, CPP_DEALLOC,4,1);
2363 DataArrayDouble* coordsY1=DataArrayDouble::New();
2364 double arrY1[4] = { -2., 2., 4., 8. };
2365 coordsY1->useArray(arrY1,false, CPP_DEALLOC,4,1);
2366 DataArrayDouble* coordsZ1=DataArrayDouble::New();
2367 double arrZ1[4] = { -3., 3., 6., 12. };
2368 coordsZ1->useArray(arrZ1,false, CPP_DEALLOC,4,1);
2369 mesh1->setCoords(coordsX1,coordsY1,coordsZ1);
2371 mesh2=MEDCouplingCMesh::New();
2372 DataArrayDouble* coordsX2=DataArrayDouble::New();
2373 double arrX2[4] = { -1., 1., 2., 4. };
2374 coordsX2->useArray(arrX2,false, CPP_DEALLOC,4,1);
2375 DataArrayDouble* coordsY2=DataArrayDouble::New();
2376 double arrY2[4] = { -2., 2., 4., 8. };
2377 coordsY2->useArray(arrY2,false, CPP_DEALLOC,4,1);
2378 DataArrayDouble* coordsZ2=DataArrayDouble::New();
2379 double arrZ2[4] = { -3., 3., 6., 12.+1e-6 }; //here is not equal
2380 coordsZ2->useArray(arrZ2,false, CPP_DEALLOC,4,1);
2381 mesh2->setCoords(coordsX2,coordsY2,coordsZ2);
2383 mesh3=MEDCouplingCMesh::New();
2384 DataArrayDouble* coordsX3=DataArrayDouble::New();
2385 double arrX3[1] = { -1.};
2386 coordsX3->useArray(arrX3,false, CPP_DEALLOC,1,1);
2387 DataArrayDouble* coordsY3=DataArrayDouble::New();
2388 double arrY3[1] = { -2.};
2389 coordsY3->useArray(arrY3,false, CPP_DEALLOC,1,1);
2390 DataArrayDouble* coordsZ3=DataArrayDouble::New();
2391 double arrZ3[1] = { -3.};
2392 coordsZ3->useArray(arrZ3,false, CPP_DEALLOC,1,1);
2393 mesh3->setCoords(coordsX3,coordsY3,coordsZ3);
2395 CPPUNIT_ASSERT_EQUAL(3,mesh1->getSpaceDimension());
2396 CPPUNIT_ASSERT_EQUAL(3,mesh1->getMeshDimension());
2398 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
2399 CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
2400 CPPUNIT_ASSERT(!mesh2->isEqualWithoutConsideringStr(mesh1,1e-12));
2401 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-5));
2402 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-7));
2404 CPPUNIT_ASSERT_THROW(mesh3->checkConsistency(1e-12),INTERP_KERNEL::Exception);
2405 mesh1->checkConsistency(1e-12);
2406 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh1->getTypeOfCell(1));
2408 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,*((mesh1->getAllGeoTypes()).begin()));
2409 CPPUNIT_ASSERT_EQUAL(27,mesh1->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2410 CPPUNIT_ASSERT_THROW(mesh1->getNumberOfCellsWithType(INTERP_KERNEL::NORM_QUAD4),INTERP_KERNEL::Exception);
2412 std::vector<double> coo;
2413 mesh1->getCoordinatesOfNode(0, coo);
2414 CPPUNIT_ASSERT_EQUAL(3,(int) coo.size());
2415 CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.,coo[0],1e-14);
2416 CPPUNIT_ASSERT_DOUBLES_EQUAL(-2.,coo[1],1e-14);
2417 CPPUNIT_ASSERT_DOUBLES_EQUAL(-3.,coo[2],1e-14);
2419 mesh1->getCoordinatesOfNode(63, coo);
2420 CPPUNIT_ASSERT_EQUAL(3,(int) coo.size());
2421 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.,coo[0],1e-14);
2422 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.,coo[1],1e-14);
2423 CPPUNIT_ASSERT_DOUBLES_EQUAL(12.,coo[2],1e-14);
2426 repr=mesh1->simpleRepr();
2427 repr=mesh1->advancedRepr();
2428 CPPUNIT_ASSERT(!(repr.find("Cartesian")==std::string::npos));
2429 CPPUNIT_ASSERT(!(repr.find("Number of components : 1")==std::string::npos));
2430 CPPUNIT_ASSERT(!(repr.find("Number of tuples : 4")==std::string::npos));
2431 CPPUNIT_ASSERT(!(repr.find("Z Array :")==std::string::npos));
2432 coordsX1->decrRef();
2433 coordsY1->decrRef();
2434 coordsZ1->decrRef();
2435 coordsX2->decrRef();
2436 coordsY2->decrRef();
2437 coordsZ2->decrRef();
2438 coordsX3->decrRef();
2439 coordsY3->decrRef();
2440 coordsZ3->decrRef();
2446 void MEDCouplingBasicsTest1::testCMesh2()
2448 MEDCouplingCMesh *mesh1;
2449 mesh1=MEDCouplingCMesh::New();
2450 DataArrayDouble* coordsX1=DataArrayDouble::New();
2451 double arrX1[4] = { -1., 1., 2., 4. };
2452 coordsX1->useArray(arrX1,false, CPP_DEALLOC,4,1);
2453 DataArrayDouble* coordsY1=DataArrayDouble::New();
2454 double arrY1[4] = { -2., 2., 4., 8. };
2455 coordsY1->useArray(arrY1,false, CPP_DEALLOC,4,1);
2456 DataArrayDouble* coordsZ1=DataArrayDouble::New();
2457 double arrZ1[4] = { -3., 3., 6., 12. };
2458 coordsZ1->useArray(arrZ1,false, CPP_DEALLOC,4,1);
2459 mesh1->setCoords(coordsX1,coordsY1,coordsZ1);
2461 std::vector<int> dis=mesh1->getDistributionOfTypes();
2462 CPPUNIT_ASSERT_EQUAL(3,(int) dis.size());
2463 CPPUNIT_ASSERT_EQUAL((int) INTERP_KERNEL::NORM_HEXA8,dis[0]);
2464 CPPUNIT_ASSERT_EQUAL(27,dis[1]);
2465 CPPUNIT_ASSERT_EQUAL(-1,dis[2]);
2467 std::vector<const DataArrayInt *> idsPerType;
2468 CPPUNIT_ASSERT(!(mesh1->checkTypeConsistencyAndContig(dis, idsPerType)));
2469 dis[0]=(int) INTERP_KERNEL::NORM_QUAD4;
2470 CPPUNIT_ASSERT_THROW(mesh1->checkTypeConsistencyAndContig(dis, idsPerType),INTERP_KERNEL::Exception);
2472 dis[0]=(int) INTERP_KERNEL::NORM_HEXA8;
2474 DataArrayInt *ids=DataArrayInt::New();
2476 ids->fillWithValue(23);
2477 idsPerType.push_back(ids);
2478 DataArrayInt* check=mesh1->checkTypeConsistencyAndContig(dis, idsPerType);
2479 CPPUNIT_ASSERT(check);
2480 CPPUNIT_ASSERT(check->isEqual(*ids));
2482 std::vector<int> code;
2483 std::vector<DataArrayInt *> idsInPflPerType;
2484 std::vector<DataArrayInt *> pfls;
2485 mesh1->splitProfilePerType(ids,code,idsInPflPerType,pfls);
2486 CPPUNIT_ASSERT_EQUAL(3,(int)code.size());
2487 CPPUNIT_ASSERT_EQUAL((int) INTERP_KERNEL::NORM_HEXA8,code[0]);
2488 CPPUNIT_ASSERT_EQUAL(10,code[1]);
2489 CPPUNIT_ASSERT_EQUAL(0,code[2]);
2490 CPPUNIT_ASSERT_EQUAL(1,(int)idsInPflPerType.size());
2491 CPPUNIT_ASSERT_EQUAL(1,(int)pfls.size());
2492 DataArrayInt *exp=DataArrayInt::New(); exp->alloc(10,1); exp->iota(0);
2493 CPPUNIT_ASSERT(idsInPflPerType[0]->isEqual(*exp));
2495 CPPUNIT_ASSERT(pfls[0]->isEqual(*ids));
2496 idsInPflPerType[0]->decrRef();
2501 int cells1[4]={0,1,25,26};
2502 MEDCouplingUMesh *partMesh1=
2503 dynamic_cast<MEDCouplingUMesh *>(mesh1->buildPart(cells1,cells1+4));
2504 CPPUNIT_ASSERT(partMesh1);
2505 CPPUNIT_ASSERT_EQUAL(4,partMesh1->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2506 CPPUNIT_ASSERT_EQUAL(64,mesh1->getNumberOfNodes());
2507 CPPUNIT_ASSERT_EQUAL(64,partMesh1->getNumberOfNodes());
2509 int cells2[2]={25,26};
2511 MEDCouplingCMesh *partMesh2=
2512 dynamic_cast<MEDCouplingCMesh *>(mesh1->buildPartAndReduceNodes(cells2,cells2+2,arr1));
2513 CPPUNIT_ASSERT(partMesh2);
2514 CPPUNIT_ASSERT_EQUAL(2,partMesh2->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2515 CPPUNIT_ASSERT_EQUAL(12,partMesh2->getNumberOfNodes());
2517 int cells3[2]={2,3};
2519 MEDCouplingUMesh *partMesh3=
2520 dynamic_cast<MEDCouplingUMesh *>(partMesh1->buildPartAndReduceNodes(cells3,cells3+2,arr2));
2521 CPPUNIT_ASSERT(partMesh3);
2522 CPPUNIT_ASSERT_EQUAL(2,partMesh3->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2523 CPPUNIT_ASSERT_EQUAL(12,partMesh3->getNumberOfNodes());
2525 CPPUNIT_ASSERT_THROW(mesh1->simplexize(0),INTERP_KERNEL::Exception);
2526 CPPUNIT_ASSERT_THROW(mesh1->getMeasureFieldOnNode(true),INTERP_KERNEL::Exception);
2530 mesh1->getBoundingBox(bbox1);
2531 partMesh1->getBoundingBox(bbox2);
2532 for(int i=0;i<6;i++)
2533 CPPUNIT_ASSERT_DOUBLES_EQUAL(bbox1[i],bbox2[i],1e-12);
2534 partMesh3->getBoundingBox(bbox1);
2535 partMesh2->getBoundingBox(bbox2);
2536 for(int i=0;i<6;i++)
2537 CPPUNIT_ASSERT_DOUBLES_EQUAL(bbox1[i],bbox2[i],1e-12);
2539 CPPUNIT_ASSERT_THROW(mesh1->buildOrthogonalField(),INTERP_KERNEL::Exception);
2540 MEDCouplingCMesh *mesh2d=MEDCouplingCMesh::New();
2541 mesh2d->setCoords(coordsX1,coordsY1);
2542 MEDCouplingFieldDouble *f1=mesh2d->buildOrthogonalField();
2544 std::vector<double> tinyInfoD;
2545 std::vector<int> tinyInfo;
2546 std::vector<std::string> littleStrings;
2547 mesh2d->getTinySerializationInformation(tinyInfoD, tinyInfo, littleStrings);
2548 CPPUNIT_ASSERT_EQUAL(5,(int)tinyInfo.size());
2549 CPPUNIT_ASSERT_EQUAL(4,(int)tinyInfo[0]); //x
2550 CPPUNIT_ASSERT_EQUAL(4,(int)tinyInfo[1]); //y
2551 CPPUNIT_ASSERT_EQUAL(-1,(int)tinyInfo[2]); //z
2552 CPPUNIT_ASSERT_EQUAL(-1,(int)tinyInfo[3]); //it
2553 CPPUNIT_ASSERT_EQUAL(-1,(int)tinyInfo[4]); //order
2554 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,tinyInfoD[0],1e-14); //time
2555 DataArrayInt* d1=DataArrayInt::New();
2556 DataArrayDouble* d2=DataArrayDouble::New();
2557 mesh2d->resizeForUnserialization(tinyInfo, d1, d2, littleStrings);
2558 CPPUNIT_ASSERT_EQUAL(0,(int)d1->getNumberOfTuples());
2559 CPPUNIT_ASSERT_EQUAL(8,(int)d2->getNumberOfTuples());
2561 partMesh1->decrRef();
2562 partMesh2->decrRef();
2563 partMesh3->decrRef();
2570 coordsX1->decrRef();
2571 coordsY1->decrRef();
2572 coordsZ1->decrRef();
2576 void MEDCouplingBasicsTest1::testScale()
2578 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
2579 const double pos[2]={0.2,0.2};
2580 mesh->scale(pos,0.5);
2581 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,
2582 -0.05,0.45, 0.2,0.45, 0.45,0.45};
2583 const double *val=mesh->getCoords()->getConstPointer();
2584 for(int i=0;i<18;i++)
2585 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1e-12);
2590 void MEDCouplingBasicsTest1::testTryToShareSameCoords()
2592 MEDCouplingUMesh *m1=build2DTargetMesh_1();
2593 MEDCouplingUMesh *m2=build2DTargetMesh_1();
2594 CPPUNIT_ASSERT(m1->getCoords()!=m2->getCoords());
2595 m1->tryToShareSameCoords(*m2,1e-12);
2596 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2597 m1->tryToShareSameCoords(*m2,1e-12);
2598 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2599 m2->tryToShareSameCoords(*m1,1e-12);
2600 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2604 m1=build2DTargetMesh_1();
2605 m2=build2DTargetMesh_2();
2606 CPPUNIT_ASSERT(m1->getCoords()!=m2->getCoords());
2607 m1->tryToShareSameCoords(*m2,1e-12);
2608 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2609 m1->tryToShareSameCoords(*m2,1e-12);
2610 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2611 m2->tryToShareSameCoords(*m1,1e-12);
2612 CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2616 m1=build2DTargetMesh_1();
2617 m2=build2DSourceMesh_1();
2618 CPPUNIT_ASSERT(m1->getCoords()!=m2->getCoords());
2619 CPPUNIT_ASSERT_THROW(m1->tryToShareSameCoords(*m2,1e-12),INTERP_KERNEL::Exception);
2624 void MEDCouplingBasicsTest1::testFindNodeOnPlane()
2626 MEDCouplingUMesh *mesh=build3DTargetMesh_1();
2628 double pt[3]={300.,300.,0.};
2629 double v[3]={0.,0.,2.};
2630 mesh->findNodesOnPlane(pt,v,1e-12,n);
2631 CPPUNIT_ASSERT_EQUAL(9,(int)n.size());
2632 MEDCouplingUMesh *m3dSurf=(MEDCouplingUMesh *)mesh->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
2633 MEDCouplingMappedExtrudedMesh *me=MEDCouplingMappedExtrudedMesh::New(mesh,m3dSurf,0);
2634 const DataArrayInt *da=me->getMesh3DIds();
2635 CPPUNIT_ASSERT_EQUAL(8,(int)me->getNumberOfCells());
2636 const int expected[8]={0,1,2,3,4,5,6,7};
2637 const int *val=da->getConstPointer();
2638 for(int i=0;i<8;i++)
2639 CPPUNIT_ASSERT_EQUAL(expected[i],val[i]);
2645 void MEDCouplingBasicsTest1::testRenumberCells()
2647 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
2648 MEDCouplingUMesh *m2=build3DSurfTargetMesh_1();
2649 CPPUNIT_ASSERT(m->isEqual(m2,0));
2650 const int arr[5]={12,3,25,2,26};
2651 m->renumberCells(arr,true);
2652 CPPUNIT_ASSERT(!m->isEqual(m2,0));
2653 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(0));
2654 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(1));
2655 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(2));
2656 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(3));
2657 CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(4));
2658 const int arr2[5]={5,-1,-5,4,8};
2659 m->renumberCells(arr2,true);
2660 CPPUNIT_ASSERT(m->isEqual(m2,0));
2665 void MEDCouplingBasicsTest1::testChangeSpaceDimension()
2667 MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
2668 MEDCouplingUMesh *m2=build2DTargetMesh_1();
2670 CPPUNIT_ASSERT_EQUAL(3,m1->getSpaceDimension());
2671 m1->changeSpaceDimension(2);
2672 CPPUNIT_ASSERT_EQUAL(2,m1->getSpaceDimension());
2673 m1->setName(m2->getName().c_str());
2674 CPPUNIT_ASSERT(m1->isEqual(m2,1e-12));
2675 m1->changeSpaceDimension(3);
2676 CPPUNIT_ASSERT_EQUAL(3,m1->getSpaceDimension());
2677 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.};
2678 const double *val=m1->getCoords()->getConstPointer();
2679 for(int i=0;i<27;i++)
2680 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected[i],val[i],1e-14);
2686 void MEDCouplingBasicsTest1::testSetConnectivity()
2688 MEDCouplingUMesh *m1 = build1DTargetMesh_1();
2690 DataArrayInt * conn = DataArrayInt::New();
2691 DataArrayInt * connI = DataArrayInt::New();
2692 m1->setConnectivity(conn, connI, true); // was SEG-Faulting with empty arrays