1 // Copyright (C) 2007-2020 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 "MEDCouplingBasicsTest2.hxx"
22 #include "MEDCouplingUMesh.hxx"
23 #include "MEDCouplingCMesh.hxx"
24 #include "MEDCouplingMappedExtrudedMesh.hxx"
25 #include "MEDCouplingFieldDouble.hxx"
26 #include "MEDCouplingMemArray.hxx"
27 #include "MEDCouplingGaussLocalization.hxx"
34 using namespace MEDCoupling;
36 void MEDCouplingBasicsTest2::testGaussPointField1()
38 const double _a=0.446948490915965;
39 const double _b=0.091576213509771;
40 const double _p1=0.11169079483905;
41 const double _p2=0.0549758718227661;
42 const double refCoo1[6]={ 0.,0., 1.,0., 0.,1. };
43 const double gsCoo1[12]={ 2*_b-1, 1-4*_b, 2*_b-1, 2.07*_b-1, 1-4*_b,
44 2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 };
45 const double wg1[6]={ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 };
46 std::vector<double> _refCoo1(refCoo1,refCoo1+6);
47 std::vector<double> _gsCoo1(gsCoo1,gsCoo1+12);
48 std::vector<double> _wg1(wg1,wg1+6);
50 MEDCouplingUMesh *m=build2DTargetMesh_1();
51 MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_GAUSS_PT,NO_TIME);
52 CPPUNIT_ASSERT_THROW(f->getNumberOfTuples(), INTERP_KERNEL::Exception); // Sanity check!
54 CPPUNIT_ASSERT_EQUAL(ToIdType(5),f->getNumberOfMeshPlacesExpected());
55 CPPUNIT_ASSERT_EQUAL(ToIdType(0),f->getNbOfGaussLocalization());
56 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI3,_refCoo1,_gsCoo1,_wg1);
57 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI3,_refCoo1,_gsCoo1,_wg1); // not a bug only to check that it works well
58 CPPUNIT_ASSERT_THROW(f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_QUAD4,_refCoo1,_gsCoo1,_wg1),INTERP_KERNEL::Exception);
59 CPPUNIT_ASSERT_EQUAL(ToIdType(1),f->getNbOfGaussLocalization());
60 const double refCoo2[8]={ 0.,0., 1.,0., 1.,1., 0.,1. };
61 std::vector<double> _refCoo2(refCoo2,refCoo2+8);
62 _gsCoo1.resize(4); _wg1.resize(2);
63 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_QUAD4,_refCoo2,_gsCoo1,_wg1);
64 CPPUNIT_ASSERT_EQUAL(ToIdType(2),f->getNbOfGaussLocalization());
65 DataArrayDouble *array=DataArrayDouble::New();
67 double *ptr=array->getPointer();
68 for(int i=0;i<18*2;i++)
71 f->setName("MyFirstFieldOnGaussPoint");
73 f->checkConsistencyLight();
74 CPPUNIT_ASSERT_DOUBLES_EQUAL(27.,f->getIJK(2,5,0),1e-14);
75 CPPUNIT_ASSERT_DOUBLES_EQUAL(16.,f->getIJK(1,5,1),1e-14);
77 f->clearGaussLocalizations();
78 CPPUNIT_ASSERT_EQUAL(ToIdType(0),f->getNbOfGaussLocalization());
79 CPPUNIT_ASSERT_THROW(f->checkConsistencyLight(),INTERP_KERNEL::Exception);
80 mcIdType ids1[4]={0,1,3,4};
81 CPPUNIT_ASSERT_THROW(f->setGaussLocalizationOnCells(ids1,ids1+4,_refCoo2,_gsCoo1,_wg1),INTERP_KERNEL::Exception);
82 CPPUNIT_ASSERT_EQUAL(ToIdType(0),f->getNbOfGaussLocalization());
83 mcIdType ids2[2]={0,4};
84 f->setGaussLocalizationOnCells(ids2,ids2+2,_refCoo2,_gsCoo1,_wg1);
85 CPPUNIT_ASSERT_EQUAL(ToIdType(1),f->getNbOfGaussLocalization());
86 CPPUNIT_ASSERT_EQUAL(ToIdType(0),f->getGaussLocalizationIdOfOneCell(0));
87 CPPUNIT_ASSERT_THROW(f->getGaussLocalizationIdOfOneCell(1),INTERP_KERNEL::Exception);
88 mcIdType ids3[2]={1,2};
89 f->setGaussLocalizationOnCells(ids3,ids3+2,_refCoo1,_gsCoo1,_wg1);
90 CPPUNIT_ASSERT_EQUAL(ToIdType(2),f->getNbOfGaussLocalization());
91 CPPUNIT_ASSERT_EQUAL(ToIdType(0),f->getGaussLocalizationIdOfOneCell(0));
92 CPPUNIT_ASSERT_EQUAL(ToIdType(1),f->getGaussLocalizationIdOfOneCell(1));
93 CPPUNIT_ASSERT_EQUAL(ToIdType(1),f->getGaussLocalizationIdOfOneCell(2));
94 CPPUNIT_ASSERT_THROW(f->checkConsistencyLight(),INTERP_KERNEL::Exception);//<- cell 3 has no localization
96 std::vector<double> _gsCoo2(_gsCoo1);
97 std::vector<double> _wg2(_wg1);
98 _gsCoo2[0]=0.8888777776666; _wg2[0]=0.1234567892377;
99 f->setGaussLocalizationOnCells(ids4,ids4+1,_refCoo2,_gsCoo2,_wg2);
100 CPPUNIT_ASSERT_EQUAL(ToIdType(3),f->getNbOfGaussLocalization());
101 std::vector<mcIdType> tmpIds;
102 f->getCellIdsHavingGaussLocalization(0,tmpIds);
103 CPPUNIT_ASSERT_EQUAL(2,(int)tmpIds.size());
104 CPPUNIT_ASSERT(std::equal(ids2,ids2+2,tmpIds.begin()));
105 CPPUNIT_ASSERT_THROW(f->checkConsistencyLight(),INTERP_KERNEL::Exception);//<- it's always not ok because undelying array not with the good size.
106 DataArrayDouble *array2=f->getArray()->subArray(0,10);
109 f->checkConsistencyLight();//<- here it is OK
110 MEDCouplingFieldDouble *f2=f->clone(true);
111 CPPUNIT_ASSERT(f->isEqual(f2,1e-14,1e-14));
112 MEDCouplingGaussLocalization& gl1=f2->getGaussLocalization(0);
113 double tmp=gl1.getGaussCoord(1,1);
114 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.07*_b-1,tmp,1e-14);
115 gl1.setGaussCoord(1,1,0.07);
116 CPPUNIT_ASSERT(!f->isEqual(f2,1e-14,1e-14));
117 gl1.setGaussCoord(1,1,tmp);
118 CPPUNIT_ASSERT(f->isEqual(f2,1e-14,1e-14));
120 f2->checkConsistencyLight();
126 void MEDCouplingBasicsTest2::testGaussPointNEField1()
128 MEDCouplingUMesh *m=build2DTargetMesh_1();
129 MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_GAUSS_NE,NO_TIME);
131 CPPUNIT_ASSERT_EQUAL(ToIdType(5),f->getNumberOfMeshPlacesExpected());
132 f->setName("MyFirstFieldOnNE");
133 f->setDescription("MyDescriptionNE");
134 DataArrayDouble *array=DataArrayDouble::New();
136 double *ptr=array->getPointer();
137 for(int i=0;i<18*2;i++)
138 ptr[i]=(double)(i+7);
142 f->checkConsistencyLight();
143 MEDCouplingFieldDouble *f2=f->clone(true);
144 CPPUNIT_ASSERT(f->isEqual(f2,1e-14,1e-14));
145 CPPUNIT_ASSERT_DOUBLES_EQUAL(21.,f->getIJK(2,0,0),1e-14);
146 CPPUNIT_ASSERT_DOUBLES_EQUAL(18.,f->getIJK(1,1,1),1e-14);
153 void MEDCouplingBasicsTest2::testCellOrientation1()
155 MEDCouplingUMesh *m=build2DTargetMesh_1();
156 double vec[3]={0.,0.,-1.};
157 std::vector<mcIdType> res1;
158 CPPUNIT_ASSERT_THROW(m->are2DCellsNotCorrectlyOriented(vec,false,res1),INTERP_KERNEL::Exception);
159 m->changeSpaceDimension(3);
161 m->are2DCellsNotCorrectlyOriented(vec,false,res1);
162 CPPUNIT_ASSERT(res1.empty());
164 m->are2DCellsNotCorrectlyOriented(vec,false,res1);
165 CPPUNIT_ASSERT_EQUAL(5,(int)res1.size());
169 // connectivity inversion
170 mcIdType *conn=m->getNodalConnectivity()->getPointer();
171 mcIdType tmp=conn[11];
174 m->are2DCellsNotCorrectlyOriented(vec,false,res1);
175 CPPUNIT_ASSERT_EQUAL(1,(int)res1.size());
176 CPPUNIT_ASSERT_EQUAL(ToIdType(2),res1[0]);
178 m->orientCorrectly2DCells(vec,false);
179 m->are2DCellsNotCorrectlyOriented(vec,false,res1);
180 CPPUNIT_ASSERT(res1.empty());
181 MEDCouplingUMesh *m2=build2DTargetMesh_1();
182 m2->changeSpaceDimension(3);
183 CPPUNIT_ASSERT(m->isEqual(m2,1e-12));
189 void MEDCouplingBasicsTest2::testCellOrientation2()
191 MEDCouplingUMesh *m1=0;
192 MEDCouplingUMesh *m2=build3DExtrudedUMesh_1(m1);
194 std::vector<mcIdType> res1;
195 m2->arePolyhedronsNotCorrectlyOriented(res1);
196 CPPUNIT_ASSERT_EQUAL(6,(int)res1.size());
197 m2->orientCorrectlyPolyhedrons();
199 m2->arePolyhedronsNotCorrectlyOriented(res1);
200 CPPUNIT_ASSERT(res1.empty());
201 m2->checkConsistencyLight();
202 CPPUNIT_ASSERT_EQUAL(18,(int)m2->getNumberOfCells());
203 mcIdType cellIds[3]={0,6,12};
204 std::vector<mcIdType> cellIds2(cellIds,cellIds+3);
205 m2->convertToPolyTypes(&cellIds2[0],&cellIds2[0]+cellIds2.size());
206 m2->orientCorrectlyPolyhedrons();
208 m2->arePolyhedronsNotCorrectlyOriented(res1);
209 CPPUNIT_ASSERT(res1.empty());
210 MEDCouplingFieldDouble *f2=m2->getMeasureField(false);
211 //Test to check global reverse in MEDCouplingUMesh::tryToCorrectPolyhedronOrientation
212 MEDCouplingUMesh *m3=build2DTargetMesh_1();
213 double vec[3]={0.,0.,1.};
214 m3->changeSpaceDimension(3);
215 const mcIdType ids1[5]={0,1,2,3,4};
216 std::vector<mcIdType> ids2(ids1,ids1+5);
217 m3->convertToPolyTypes(&ids2[0],&ids2[0]+ids2.size());
218 m3->orientCorrectly2DCells(vec,false);
219 MEDCouplingUMesh *m4=buildCU1DMesh_U();
220 m4->changeSpaceDimension(3);
221 double center[3]={0.,0.,0.};
222 double vector[3]={0.,1.,0.};
223 m4->rotate(center,vector,-M_PI/2.);
224 MEDCouplingUMesh *m5=m3->buildExtrudedMesh(m4,0);
226 m5->arePolyhedronsNotCorrectlyOriented(res1);
227 CPPUNIT_ASSERT_EQUAL(15,(int)res1.size());
228 m5->orientCorrectlyPolyhedrons();
230 m5->arePolyhedronsNotCorrectlyOriented(res1);
231 CPPUNIT_ASSERT(res1.empty());
232 MEDCouplingFieldDouble *f3=m5->getMeasureField(false);
233 CPPUNIT_ASSERT_EQUAL(15,(int)f3->getArray()->getNumberOfTuples());
234 CPPUNIT_ASSERT_EQUAL(1,(int)f3->getNumberOfComponents());
235 const double *f3Ptr=f3->getArray()->getConstPointer();
236 const double expected1[15]={
237 0.075,0.0375,0.0375,0.075,0.075,
238 0.1125,0.05625,0.05625,0.1125,0.1125,
239 0.0625,0.03125,0.03125,0.0625,0.0625
241 for(int i=0;i<15;i++)
242 CPPUNIT_ASSERT_DOUBLES_EQUAL(std::abs(expected1[i]),f3Ptr[i],1e-12);
244 DataArrayDouble *f4=m5->computeCellCenterOfMass();
245 CPPUNIT_ASSERT_EQUAL(15,(int)f4->getNumberOfTuples());
246 CPPUNIT_ASSERT_EQUAL(3,(int)f4->getNumberOfComponents());
247 const double *f4Ptr=f4->getConstPointer();
248 const double expected2[45]={
249 -0.05,-0.05,0.15, 0.3666666666666667,-0.13333333333333333,0.15, 0.53333333333333333,0.033333333333333333,0.15, -0.05,0.45,0.15, 0.45,0.45,0.15,
250 -0.05,-0.05,0.525, 0.3666666666666667,-0.13333333333333333,0.525, 0.53333333333333333,0.033333333333333333,0.525, -0.05,0.45,0.525, 0.45,0.45,0.525,
251 -0.05,-0.05,0.875, 0.3666666666666667,-0.13333333333333333,0.875, 0.53333333333333333,0.033333333333333333,0.875, -0.05,0.45,0.875, 0.45,0.45,0.875
253 for(int i=0;i<45;i++)
254 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f4Ptr[i],1e-12);
264 void MEDCouplingBasicsTest2::testCellOrientation3()
266 MEDCouplingUMesh *m = MEDCouplingUMesh::New("circle", 2);
268 double coords[8]={ 0.,0., 0.,0., 0.,0., 0.,0.};
269 coords[0] = cos(-M_PI/4.0); coords[1] = sin(-M_PI/4.0);
270 coords[2] = cos(3*M_PI/4.0); coords[3] = sin(3*M_PI/4.0);
271 coords[4] = cos(5*M_PI/4.0); coords[5] = sin(5*M_PI/4.0);
272 coords[6] = cos(M_PI/4.0); coords[7] = sin(M_PI/4.0);
274 mcIdType conn[4]= { 0,1,2,3 };
275 double vec[3]={0.,0.,-1.};
277 m->insertNextCell(INTERP_KERNEL::NORM_QPOLYG,4,conn);
278 m->finishInsertingCells();
279 DataArrayDouble *myCoords=DataArrayDouble::New();
280 myCoords->alloc(4,2);
281 std::copy(coords,coords+8,myCoords->getPointer());
282 m->setCoords(myCoords);
284 m->changeSpaceDimension(3);
286 std::vector<mcIdType> res1;
287 m->are2DCellsNotCorrectlyOriented(vec,false,res1);
288 CPPUNIT_ASSERT(res1.empty());
291 m->are2DCellsNotCorrectlyOriented(vec,false,res1);
292 CPPUNIT_ASSERT_EQUAL(1,(int)res1.size());
297 * This test check polyhedron true barycenter computation.
299 void MEDCouplingBasicsTest2::testPolyhedronBarycenter()
301 mcIdType connN[]={0,3,2,1, -1, 4,5,6,7, -1, 0,4,7,3, -1, 3,7,6,2, -1, 2,6,5,1, -1, 1,5,4,0};
302 double coords[]={0.,0.,0., 1.,0.,0., 1.,1.,0., 0.,1.,0., 0.,0.,1., 1.,0.,1., 1.,1.,1., 0.,1.,1., 0.5, 0.5, 0.5};
303 MEDCouplingUMesh *meshN=MEDCouplingUMesh::New();
304 meshN->setName("ForBary");
305 meshN->setMeshDimension(3);
306 meshN->allocateCells(4);
307 meshN->insertNextCell(INTERP_KERNEL::NORM_POLYHED,29,connN);
308 meshN->finishInsertingCells();
309 DataArrayDouble *myCoords=DataArrayDouble::New();
310 myCoords->alloc(9,3);
311 std::copy(coords,coords+27,myCoords->getPointer());
312 meshN->setCoords(myCoords);
314 meshN->checkConsistencyLight();
316 std::vector<mcIdType> res1;
317 meshN->arePolyhedronsNotCorrectlyOriented(res1);
318 meshN->orientCorrectlyPolyhedrons();
319 CPPUNIT_ASSERT(res1.empty());
320 const double *ref,*daPtr;
321 DataArrayDouble *da=meshN->computeCellCenterOfMass();
322 CPPUNIT_ASSERT_EQUAL(1,(int)da->getNumberOfTuples());
323 CPPUNIT_ASSERT_EQUAL(3,(int)da->getNumberOfComponents());
324 daPtr=da->getConstPointer();
325 ref=meshN->getCoords()->getConstPointer()+24;
327 CPPUNIT_ASSERT_DOUBLES_EQUAL(ref[i],daPtr[i],1e-12);
330 const double center[]={0.,0.,0.};
331 const double vec[]={0.,2.78,0.};
332 da=meshN->computeCellCenterOfMass();
333 daPtr=da->getConstPointer();
334 ref=meshN->getCoords()->getConstPointer()+24;
336 CPPUNIT_ASSERT_DOUBLES_EQUAL(ref[i],daPtr[i],1e-12);
339 meshN->rotate(center,vec,M_PI/7.);
340 meshN->translate(vec);
341 da=meshN->computeCellCenterOfMass();
342 daPtr=da->getConstPointer();
343 ref=meshN->getCoords()->getConstPointer()+24;
345 CPPUNIT_ASSERT_DOUBLES_EQUAL(ref[i],daPtr[i],1e-12);
348 const double center2[]={1.12,3.45,6.78};
349 const double vec2[]={4.5,9.3,2.8};
350 meshN->rotate(center2,vec2,M_E);
351 meshN->translate(vec2);
352 da=meshN->computeCellCenterOfMass();
353 daPtr=da->getConstPointer();
354 ref=meshN->getCoords()->getConstPointer()+24;
356 CPPUNIT_ASSERT_DOUBLES_EQUAL(ref[i],daPtr[i],1e-10);
362 void MEDCouplingBasicsTest2::testNormL12Integ1D()
364 MEDCouplingUMesh *m1=build1DTargetMesh_3();
365 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
367 DataArrayDouble *array=DataArrayDouble::New();
368 array->alloc(m1->getNumberOfCells(),3);
369 const double arr[12]={-5.23,15.45,-25.56,6.67,-16.78,26.89,-7.91,17.23,-27.43,8.21,-18.63,28.72};
370 std::copy(arr,arr+12,array->getPointer());
375 DataArrayDouble *f3=m1->computeCellCenterOfMass();
376 CPPUNIT_ASSERT_EQUAL(4,(int)f3->getNumberOfTuples());
377 CPPUNIT_ASSERT_EQUAL(1,(int)f3->getNumberOfComponents());
378 double expected9[4]={0.75,5.105,0.8,5.155};
379 ptr=f3->getConstPointer();
381 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected9[i],ptr[i],1e-12);
384 MEDCouplingFieldDouble *f2=m1->getMeasureField(false);
385 CPPUNIT_ASSERT_EQUAL(4,(int)f2->getArray()->getNumberOfTuples());
386 CPPUNIT_ASSERT_EQUAL(1,(int)f2->getNumberOfComponents());
387 double expected1[4]={0.5,0.21,-0.6,-0.31};
388 ptr=f2->getArray()->getConstPointer();
390 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],ptr[i],1e-12);
392 double expected2[4]={0.5,0.21,0.6,0.31};
393 f2=m1->getMeasureField(true);
394 ptr=f2->getArray()->getConstPointer();
396 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],ptr[i],1e-12);
400 f1->integral(false,res);
401 double expected3[3]={0.9866,-0.3615,0.4217};
403 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],res[i],1e-12);
404 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[0],f1->integral(0,false),1e-12);
405 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[1],f1->integral(1,false),1e-12);
406 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[2],f1->integral(2,false),1e-12);
407 f1->integral(true,res);
408 double expected4[3]={-3.4152,8.7639,-14.6879};
410 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected4[i],res[i],1e-12);
413 double expected5[3]={6.979506172839505, 16.89018518518518, 27.02969135802469};
415 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[i],res[i],1e-12);
416 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[0],f1->normL1(0),1e-12);
417 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[1],f1->normL1(1),1e-12);
418 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[2],f1->normL1(2),1e-12);
421 double expected7[3]={7.090910979452395, 16.9275542960123, 27.053271464160858};
423 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected7[i],res[i],1e-9);
424 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected7[0],f1->normL2(0),1e-9);
425 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected7[1],f1->normL2(1),1e-9);
426 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected7[2],f1->normL2(2),1e-9);
428 MEDCouplingFieldDouble *f4=f1->buildMeasureField(false);
429 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.2,f4->accumulate(0),1e-12);
431 f4=f1->buildMeasureField(true);
432 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.62,f4->accumulate(0),1e-12);
437 // Testing with 2D Curve
438 m1=build2DCurveTargetMesh_3();
439 f2=m1->getMeasureField(false);
440 CPPUNIT_ASSERT_EQUAL(4,(int)f2->getArray()->getNumberOfTuples());
441 CPPUNIT_ASSERT_EQUAL(1,(int)f2->getNumberOfComponents());
442 ptr=f2->getArray()->getConstPointer();
444 CPPUNIT_ASSERT_DOUBLES_EQUAL(sqrt(2.)*expected2[i],ptr[i],1e-12);
446 f2=m1->getMeasureField(true);
447 CPPUNIT_ASSERT_EQUAL(4,(int)f2->getArray()->getNumberOfTuples());
448 CPPUNIT_ASSERT_EQUAL(1,(int)f2->getNumberOfComponents());
449 ptr=f2->getArray()->getConstPointer();
451 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i]*sqrt(2.),ptr[i],1e-12);
454 f3=m1->computeCellCenterOfMass();
455 CPPUNIT_ASSERT_EQUAL(4,(int)f3->getNumberOfTuples());
456 CPPUNIT_ASSERT_EQUAL(2,(int)f3->getNumberOfComponents());
457 double expected10[8]={0.75,0.75,5.105,5.105,0.8,0.8,5.155,5.155};
458 ptr=f3->getConstPointer();
460 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected10[i],ptr[i],1e-12);
463 f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
465 array=DataArrayDouble::New();
466 array->alloc(m1->getNumberOfCells(),3);
467 std::copy(arr,arr+12,array->getPointer());
470 f1->integral(false,res);
472 CPPUNIT_ASSERT_DOUBLES_EQUAL(sqrt(2.)*expected4[i],res[i],1e-12);
473 f1->integral(true,res);
475 CPPUNIT_ASSERT_DOUBLES_EQUAL(sqrt(2.)*expected4[i],res[i],1e-12);
478 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[i],res[i],1e-12);
481 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected7[i],res[i],1e-12);
487 void MEDCouplingBasicsTest2::testAreaBary2D()
489 MEDCouplingUMesh *m1=build2DTargetMesh_3();
490 MEDCouplingFieldDouble *f1=m1->getMeasureField(false);
491 CPPUNIT_ASSERT_EQUAL(10,(int)f1->getArray()->getNumberOfTuples());
492 CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
493 double expected1[10]={-0.5,-1,-1.5,-0.5,-1, 0.5,1,1.5,0.5,1};
494 const double *ptr=f1->getArray()->getConstPointer();
495 for(int i=0;i<10;i++)
496 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],ptr[i],1e-12);
498 f1=m1->getMeasureField(true);
499 ptr=f1->getArray()->getConstPointer();
500 for(int i=0;i<10;i++)
501 CPPUNIT_ASSERT_DOUBLES_EQUAL(std::abs(expected1[i]),ptr[i],1e-12);
503 DataArrayDouble *f2=m1->computeCellCenterOfMass();
504 CPPUNIT_ASSERT_EQUAL(10,(int)f2->getNumberOfTuples());
505 CPPUNIT_ASSERT_EQUAL(2,(int)f2->getNumberOfComponents());
506 double expected2[20]={
507 0.5,0.3333333333333333,0.5,0.5,0.5,0.77777777777777777,0.5,0.3333333333333333,0.5,0.5,
508 0.5,0.3333333333333333,0.5,0.5,0.5,0.77777777777777777,0.5,0.3333333333333333,0.5,0.5,
510 ptr=f2->getConstPointer();
511 for(int i=0;i<20;i++)
512 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],ptr[i],1e-12);
514 m1->changeSpaceDimension(3);
515 f1=m1->getMeasureField(false);
516 CPPUNIT_ASSERT_EQUAL(10,(int)f1->getArray()->getNumberOfTuples());
517 CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
518 ptr=f1->getArray()->getConstPointer();
519 for(int i=0;i<10;i++)
520 CPPUNIT_ASSERT_DOUBLES_EQUAL(std::abs(expected1[i]),ptr[i],1e-12);
522 f2=m1->computeCellCenterOfMass();
523 CPPUNIT_ASSERT_EQUAL(10,(int)f2->getNumberOfTuples());
524 CPPUNIT_ASSERT_EQUAL(3,(int)f2->getNumberOfComponents());
525 ptr=f2->getConstPointer();
526 double expected3[30]={
527 0.5,0.3333333333333333,0.,0.5,0.5,0.,0.5,0.77777777777777777,0.,0.5,0.3333333333333333,0.,0.5,0.5,0.,
528 0.5,0.3333333333333333,0.,0.5,0.5,0.,0.5,0.77777777777777777,0.,0.5,0.3333333333333333,0.,0.5,0.5,0.
530 for(int i=0;i<30;i++)
531 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],ptr[i],1e-12);
537 * This test check polyhedron true barycenter computation 2.
539 void MEDCouplingBasicsTest2::testAreaBary3D()
541 double coords [] = { 0.241310763507 , 0.0504777305619 , 0.0682283524903 , 0.252501053866 , -0.0625176732937 , 0.137272639894 ,
542 0.152262663601 , 0.241816569527 , 0.133812556197 , 0.18047750211 , -0.0789949051358 , 0.339098173401 ,
543 0.151741971857 , 0.238885278571 , 0.137715037333 , 0.242532155481 , -0.0928169086456 , 0.0678043417367 ,
544 0.240941965335 , -0.015461491464 , 0.0617186345825 , 0.24127650112 , 0.0499427876717 , 0.0679634099148 ,
545 -0.145828917428 , 0.206291632565 , 0.0310071927543 , 0.0125651775307 , 0.266262085828 , 0.105228430543 ,
546 -0.0994066533286 , 0.233224271238 , 0.0572213839567 , -0.0951345338317 , 0.234819509426 , 0.0592126284538 ,
547 0.136580574205 , -0.205486212579 , 0.0572866072014 , 0.0637270784978 , -0.168886355238 , 0.446614057077 ,
548 0.041337157151 , -0.213402568198 , 0.372407095999 , 0.0411601970268 , -0.202387875756 , 0.411334979491 ,
549 -0.108355701857 , 0.193636239335 , 0.204886756738 , 0.00639779029829 , 0.155296981517 , 0.252585892979 ,
550 0.0262473111702 , -0.112919732543 , 0.424286639249 ,-0.224103052733 , -0.139430015438 , -0.0122352295701 ,
551 -0.0312760589481 , -0.274272003594 , 0.0323959636568 , -0.166663422532 , -0.217754445175 , 0.00392109070364 ,
552 -0.30586619777 , -0.0475168041091 , -0.0144585228182 , -0.280881480586 , 0.135571293538 , 0.00623923647986 ,
553 -0.25548538234 , 0.156819217766 , 0.0645277879769 , -0.131567009284 , 0.184133752309 , 0.206021802753 ,
554 -0.196204010965 , 0.151602971681 , 0.212974777736 , -0.183713879463 , 0.0802946639531 , 0.260115662599 ,
555 -0.244241178767 , -0.0738873389604 , 0.144590565817 , -0.155804057829 , -0.164892720025 , 0.210613950558 ,
556 -0.170950800428 , -0.215099334026 , 0.00610122860092 , -0.30552634869 , -0.0490020791904 , -0.0132786533145 ,
557 0.271831011884 , 0.15105657296 , 0.0230534827908 , 0.281919192283 , 0.0898544306288 , -0.0625201489143 ,
558 0.260240727276 , -0.0120688706637 , -0.0532316588626 , 0.244947737722 , 0.0197984684293 , 0.0309341209233 ,
559 0.23439631578 , 0.229825279875 , 0.0508520585381 , 0.160921316875 , 0.265078502128 , 0.121716560626 ,
560 -0.315088694175 , 0.0747700471918 , -0.245836615071 , -0.327728781776 , 0.0857114674649 , -0.239431905957 ,
561 -0.308385460634 , 0.145142997084 , -0.149886828433 , 0.0488236045164 , 0.309462801914 , 0.0849169148265 ,
562 -0.0244964803395 , 0.33145611751 , -0.0476415818061 , 0.0060567994229 , 0.32418412014 , 0.0367779543812 ,
563 -0.0950221448063 , 0.236675326003 , 0.0572594453983 , 0.248723023186 , 0.0886648784791 , -0.176629430538 ,
564 0.116796984 , 0.256596599567 , -0.292863523603 , 0.118024552914 , 0.229154257843 , -0.34233232501 ,
565 0.217507892549 , -0.0417822335742 , -0.176771782888 , -0.224429321304 , 0.0125595300114 , -0.362064725588 ,
566 0.0937301100955 , -0.0500824832657 , -0.299713548444 , -0.244162220397 , 0.0383853931293 , -0.389856984411 ,
567 -0.0281989366102 , 0.097392811563 , -0.458244577284 , -0.385010847162 , 0.10122766194 , -0.140052859922 ,
568 -0.377936358012 , 0.110875172128 , -0.176207095463 , 0.244483045556 , -0.0991073977045 , 0.0575134372934 ,
569 0.262605120167 , -0.100243191645 , -0.0495620806935 , 0.240306880972 , -0.136153701579 , -0.114745281696 ,
570 0.215763176129 , -0.0836766059189 , -0.183249640616 , 0.237870396603 , -0.132449578286 , -0.121598854639 ,
571 -0.0637683083097 , -0.27921020214 , -0.149112321992 , -0.0856211014977 , -0.2973233473 , -0.0446878139589 ,
572 0.104675342288 , -0.0625908305324 , -0.290346256534 , 0.0248264249186 , -0.247797708548 , -0.165830884019 ,
573 0.0719302438309 , -0.178468260473 , -0.211432157345 , 0.142871843159 , -0.208769948542 , 0.0454101128246 ,
574 0.167803379307 , -0.207851396623 , -0.088802726124 , 0.12868717152 , -0.230920439715 , 0.00760508389036 ,
575 -0.0372812069535 , -0.286740286332 , 0.00963701291166 };
577 mcIdType connN [] = { /*polyhedron 0*/
578 0 , 1 , 3 , 4 , 2 , -1 , 1 , 5 , 6 , 7 , 0 , -1 , 0 , 7 , 8 , 10 , 11 , 9 , 2 , -1 , 1 , 5 , 12 , 14 , 15 , 13 , 3 , -1 , 16 , 9 , 2 , 4 , 17 , -1
579 , 4 , 3 , 13 , 18 , 17 , -1 , 5 , 6 , 19 , 21 , 20 , 12 , -1 , 6 , 7 , 8 , 23 , 22 , 19 , -1 , 23 , 24 , 10 , 8 , -1 , 25 , 11 , 9 , 16 , -1
580 , 24 , 26 , 25 , 11 , 10 , -1 , 12 , 14 , 20 , -1 , 27 , 28 , 29 , 15 , 13 , 18 , -1 , 14 , 15 , 29 , 30 , 21 , 20 , -1 , 26 , 27 , 18 , 17 , 16 , 25 , -1
581 , 22 , 19 , 21 , 30 , 31 , -1 , 22 , 31 , 28 , 27 , 26 , 24 , 23 , -1 , 31 , 30 , 29 , 28,
583 0 , 7 , 8 , 10 , 11 , 9 , 2 , -1 , 32 , 0 , 7 , 35 , 34 , 33 , -1 , 32 , 0 , 2 , 37 , 36 , -1 , 35 , 7 , 8 , 40 , 39 , 38 , -1
584 , 2 , 37 , 41 , 9 , -1 , 40 , 8 , 10 , 44 , 43 , 42 , -1 , 41 , 9 , 11 , 44 , 43 , -1 , 44 , 11 , 10 , -1 , 32 , 33 , 45 , 47 , 46 , 36 , -1
585 , 33 , 34 , 48 , 45 , -1 , 35 , 34 , 48 , 50 , 49 , 38 , -1 , 41 , 43 , 42 , 46 , 36 , 37 , -1 , 38 , 39 , 51 , 49 , -1
586 , 39 , 40 , 42 , 46 , 47 , 52 , 51 , -1 , 45 , 47 , 52 , 50 , 48 , -1 , 52 , 51 , 49 , 50,
588 6 , 7 , 8 , 23 , 22 , 19 , -1 , 6 , 35 , 7 , -1 , 6 , 35 , 38 , 19 , -1 , 35 , 7 , 8 , 40 , 39 , 38 , -1 , 53 , 22 , 19 , 38 , 39 , 54 , -1
589 , 23 , 53 , 54 , 40 , 8 , -1 , 53 , 22 , 23 , -1 , 39 , 54 , 40,
591 35 , 34 , 48 , 50 , 49 , 38 , -1 , 6 , 35 , 34 , 56 , 55 , 5 , -1 , 6 , 35 , 38 , 19 , -1 , 34 , 56 , 57 , 59 , 58 , 48 , -1
592 , 60 , 61 , 21 , 19 , 38 , 49 , -1 , 62 , 50 , 48 , 58 , -1 , 60 , 63 , 64 , 62 , 50 , 49 , -1 , 5 , 6 , 19 , 21 , 20 , 12 , -1
593 , 55 , 5 , 12 , 65 , -1 , 66 , 67 , 65 , 55 , 56 , 57 , -1 , 63 , 66 , 57 , 59 , 64 , -1 , 64 , 62 , 58 , 59 , -1
594 , 60 , 63 , 66 , 67 , 68 , 61 , -1 , 61 , 68 , 20 , 21 , -1 , 67 , 68 , 20 , 12 , 65};
596 double barys[]={ -0.0165220465527 , -0.0190922868195 , 0.158882733414 ,
597 0.0287618656076 , 0.135874379934 , -0.14601588119 ,
598 -0.147128055553 , 0.0465995097041 , -0.049391174453 ,
599 -0.00142506732317 , -0.0996953090351 , -0.115159183132 };
600 MEDCouplingUMesh *meshN=MEDCouplingUMesh::New();
601 meshN->setName("ForBary");
602 meshN->setMeshDimension(3);
603 meshN->allocateCells(4);
604 meshN->insertNextCell(INTERP_KERNEL::NORM_POLYHED,113,connN);
605 meshN->insertNextCell(INTERP_KERNEL::NORM_POLYHED,99,connN+113);
606 meshN->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,connN+212);
607 meshN->insertNextCell(INTERP_KERNEL::NORM_POLYHED,92,connN+255);
608 meshN->finishInsertingCells();
609 DataArrayDouble *myCoords=DataArrayDouble::New();
610 myCoords->alloc(69,3);
611 std::copy(coords,coords+207,myCoords->getPointer());
612 meshN->setCoords(myCoords);
614 meshN->checkConsistencyLight();
615 std::vector<mcIdType> res1;
616 meshN->arePolyhedronsNotCorrectlyOriented(res1);
617 meshN->orientCorrectlyPolyhedrons();
619 meshN->arePolyhedronsNotCorrectlyOriented(res1);
620 CPPUNIT_ASSERT(res1.empty());
622 DataArrayDouble *da=meshN->computeCellCenterOfMass();
623 CPPUNIT_ASSERT_EQUAL(4,(int)da->getNumberOfTuples());
624 CPPUNIT_ASSERT_EQUAL(3,(int)da->getNumberOfComponents());
625 const double *daPtr=da->getConstPointer();
626 for(int i=0;i<12;i++)
627 CPPUNIT_ASSERT_DOUBLES_EQUAL(barys[i],daPtr[i],1e-12);
633 void MEDCouplingBasicsTest2::testRenumberCellsForFields()
635 MEDCouplingUMesh *m=build2DTargetMesh_1();
636 MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
638 DataArrayDouble *arr=DataArrayDouble::New();
639 arr->alloc(m->getNumberOfCells(),3);
642 const double values1[15]={7.,107.,10007.,8.,108.,10008.,9.,109.,10009.,10.,110.,10010.,11.,111.,10011.};
643 std::copy(values1,values1+15,arr->getPointer());
644 const mcIdType renumber1[5]={3,1,0,4,2};
646 const double loc[]={-0.05,-0.05, 0.55,-0.25, 0.55,0.15, -0.05,0.45, 0.45,0.45};
649 f->getValueOn(loc+2*j,res);
651 CPPUNIT_ASSERT_DOUBLES_EQUAL(values1[i+3*j],res[i],1e-12);
653 f->renumberCells(renumber1,false);
654 const double *ptr=f->getArray()->getConstPointer();
655 const double expected1[15]={9.,109.,10009.,8.,108.,10008.,11.,111.,10011.,7.,107.,10007.,10.,110.,10010.};
656 for(int i=0;i<15;i++)
657 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],ptr[i],1e-12);
658 //check that fields remains the same geometrically
661 f->getValueOn(loc+2*j,res);
663 CPPUNIT_ASSERT_DOUBLES_EQUAL(values1[i+3*j],res[i],1e-12);
667 f=MEDCouplingFieldDouble::New(ON_GAUSS_PT,NO_TIME);
669 const double _a=0.446948490915965;
670 const double _b=0.091576213509771;
671 const double _p1=0.11169079483905;
672 const double _p2=0.0549758718227661;
673 const double refCoo1[6]={ 0.,0., 1.,0., 0.,1. };
674 const double gsCoo1[12]={ 2*_b-1, 1-4*_b, 2*_b-1, 2.07*_b-1, 1-4*_b,
675 2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 };
676 const double wg1[6]={ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 };
677 std::vector<double> _refCoo1(refCoo1,refCoo1+6);
678 std::vector<double> _gsCoo1(gsCoo1,gsCoo1+12);
679 std::vector<double> _wg1(wg1,wg1+6);
680 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI3,_refCoo1,_gsCoo1,_wg1);
681 const double refCoo2[8]={ 0.,0., 1.,0., 1.,1., 0.,1. };
682 std::vector<double> _refCoo2(refCoo2,refCoo2+8);
683 _gsCoo1.resize(4); _wg1.resize(2);
684 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_QUAD4,_refCoo2,_gsCoo1,_wg1);
685 arr=DataArrayDouble::New();
687 const double values2[36]={1.,1001.,2.,1002., 11.,1011.,12.,1012.,13.,1013.,14.,1014.,15.,1015.,16.,1016., 21.,1021.,22.,1022.,23.,1023.,24.,1024.,25.,1025.,26.,1026., 31.,1031.,32.,1032., 41.,1041.,42.,1042.};
688 std::copy(values2,values2+36,arr->getPointer());
691 f->checkConsistencyLight();
692 MEDCouplingFieldDouble *fCpy=f->clone(true);
693 CPPUNIT_ASSERT(f->isEqual(fCpy,1e-12,1e-12));
694 f->renumberCells(renumber1,false);
695 CPPUNIT_ASSERT(!f->isEqual(fCpy,1e-12,1e-12));
696 double expected2[36]={21.,1021.,22.,1022.,23.,1023.,24.,1024.,25.,1025.,26.,1026., 11.,1011.,12.,1012.,13.,1013.,14.,1014.,15.,1015.,16.,1016., 41.,1041.,42.,1042., 1.,1001.,2.,1002., 31.,1031.,32.,1032.};
697 ptr=f->getArray()->getConstPointer();
698 for(int i=0;i<36;i++)
699 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],ptr[i],1e-12);
700 const mcIdType renumber2[5]={2,1,4,0,3};//reverse renumber1
701 f->renumberCells(renumber2,false);
702 CPPUNIT_ASSERT(f->isEqual(fCpy,1e-12,1e-12));
706 f=MEDCouplingFieldDouble::New(ON_GAUSS_NE,NO_TIME);
708 arr=DataArrayDouble::New();
710 const double values3[36]={1.,1001.,2.,1002.,3.,1003.,4.,1004., 11.,1011.,12.,1012.,13.,1013., 21.,1021.,22.,1022.,23.,1023., 31.,1031.,32.,1032.,33.,1033.,34.,1034., 41.,1041.,42.,1042.,43.,1043.,44.,1044.};
711 std::copy(values3,values3+36,arr->getPointer());
714 f->checkConsistencyLight();
716 CPPUNIT_ASSERT(f->isEqual(fCpy,1e-12,1e-12));
717 f->renumberCells(renumber1,false);
718 CPPUNIT_ASSERT(!f->isEqual(fCpy,1e-12,1e-12));
719 double expected3[36]={21.,1021.,22.,1022.,23.,1023.,11.,1011.,12.,1012.,13.,1013.,41.,1041.,42.,1042.,43.,1043.,44.,1044.,1.,1001.,2.,1002.,3.,1003.,4.,1004.,31.,1031.,32.,1032.,33.,1033.,34.,1034.};
720 ptr=f->getArray()->getConstPointer();
721 for(int i=0;i<36;i++)
722 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],ptr[i],1e-12);
723 f->renumberCells(renumber2,false);//perform reverse operation of renumbering to check that the resulting field is equal.
724 CPPUNIT_ASSERT(f->isEqual(fCpy,1e-12,1e-12));
731 void MEDCouplingBasicsTest2::testRenumberNodesForFields()
733 MEDCouplingUMesh *m=build2DTargetMesh_1();
734 MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
736 CPPUNIT_ASSERT_EQUAL(ToIdType(9),f->getNumberOfMeshPlacesExpected());
737 DataArrayDouble *arr=DataArrayDouble::New();
738 mcIdType nbOfNodes=m->getNumberOfNodes();
739 arr->alloc(nbOfNodes,3);
742 const double values1[27]={7.,107.,10007.,8.,108.,10008.,9.,109.,10009.,10.,110.,10010.,11.,111.,10011.,12.,112.,10012.,13.,113.,10013.,14.,114.,10014.,15.,115.,10015.};
743 std::copy(values1,values1+27,arr->getPointer());
744 f->checkConsistencyLight();
745 const mcIdType renumber1[9]={0,4,1,3,5,2,6,7,8};
747 const double loc[]={0.5432,-0.2432, 0.5478,0.1528};
748 const double expected1[6]={9.0272, 109.0272, 10009.0272, 11.4124,111.4124,10011.4124};
751 f->getValueOn(loc+2*j,res);
753 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i+3*j],res[i],1e-12);
755 MEDCouplingFieldDouble *fCpy=f->clone(true);
756 CPPUNIT_ASSERT(f->isEqual(fCpy,1e-12,1e-12));
757 f->renumberNodes(renumber1);
758 CPPUNIT_ASSERT(!f->isEqual(fCpy,1e-12,1e-12));
761 f->getValueOn(loc+2*j,res);
763 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i+3*j],res[i],1e-12);
765 const double expected2[27]={7.,107.,10007.,9.,109.,10009.,12.,112.,10012.,10.,110.,10010.,8.,108.,10008.,11.,111.,10011.,13.,113.,10013.,14.,114.,10014.,15.,115.,10015.};
766 for(int i=0;i<27;i++)
767 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getArray()->getConstPointer()[i],1e-12);
768 const mcIdType renumber2[9]={0,2,5,3,1,4,6,7,8};//reverse of renumber2
769 f->renumberNodes(renumber2);
770 CPPUNIT_ASSERT(f->isEqual(fCpy,1e-12,1e-12));
777 void MEDCouplingBasicsTest2::testConvertQuadraticCellsToLinear()
779 MEDCouplingUMesh *mesh=build2DTargetMesh_3();
780 mesh->checkConsistencyLight();
781 std::set<INTERP_KERNEL::NormalizedCellType> types=mesh->getAllGeoTypes();
782 CPPUNIT_ASSERT_EQUAL(5,(int)types.size());
783 INTERP_KERNEL::NormalizedCellType expected1[5]={INTERP_KERNEL::NORM_POLYGON, INTERP_KERNEL::NORM_TRI3, INTERP_KERNEL::NORM_QUAD4, INTERP_KERNEL::NORM_TRI6, INTERP_KERNEL::NORM_QUAD8};
784 std::set<INTERP_KERNEL::NormalizedCellType> expected1Bis(expected1,expected1+5);
785 CPPUNIT_ASSERT(expected1Bis==types);
786 CPPUNIT_ASSERT(mesh->isPresenceOfQuadratic());
787 CPPUNIT_ASSERT_EQUAL(ToIdType(62),mesh->getNodalConnectivityArrayLen());
788 MEDCouplingFieldDouble *f1=mesh->getMeasureField(false);
790 mesh->convertQuadraticCellsToLinear();
791 CPPUNIT_ASSERT(!mesh->isPresenceOfQuadratic());
793 mesh->checkConsistencyLight();
794 MEDCouplingFieldDouble *f2=mesh->getMeasureField(false);
795 CPPUNIT_ASSERT(f1->getArray()->isEqual(*f2->getArray(),1e-12));
796 CPPUNIT_ASSERT_EQUAL(ToIdType(48),mesh->getNodalConnectivityArrayLen());
797 std::set<INTERP_KERNEL::NormalizedCellType> types2=mesh->getAllGeoTypes();
798 CPPUNIT_ASSERT_EQUAL(3,(int)types2.size());
799 INTERP_KERNEL::NormalizedCellType expected2[3]={INTERP_KERNEL::NORM_POLYGON, INTERP_KERNEL::NORM_TRI3, INTERP_KERNEL::NORM_QUAD4};
800 std::set<INTERP_KERNEL::NormalizedCellType> expected2Bis(expected2,expected2+3);
801 CPPUNIT_ASSERT(expected2Bis==types2);
808 void MEDCouplingBasicsTest2::testCheckGeoEquivalWith()
810 MEDCouplingUMesh *mesh1=build2DTargetMesh_3();
811 MEDCouplingUMesh *mesh2=build2DTargetMesh_3();
812 DataArrayIdType *cellCor,*nodeCor;
814 mesh1->checkGeoEquivalWith(mesh1,0,1e-12,cellCor,nodeCor);//deepEqual
815 CPPUNIT_ASSERT(cellCor==0);
816 CPPUNIT_ASSERT(nodeCor==0);
817 mesh1->checkGeoEquivalWith(mesh1,1,1e-12,cellCor,nodeCor);//fastEqual
818 CPPUNIT_ASSERT(cellCor==0);
819 CPPUNIT_ASSERT(nodeCor==0);
820 mesh1->checkGeoEquivalWith(mesh1,10,1e-12,cellCor,nodeCor);//deepEqual with geo permutations
821 CPPUNIT_ASSERT(cellCor==0);
822 CPPUNIT_ASSERT(nodeCor==0);
823 //Second test mesh1 and mesh2 are 2 different meshes instance
824 mesh1->checkGeoEquivalWith(mesh2,0,1e-12,cellCor,nodeCor);//deepEqual
825 CPPUNIT_ASSERT(cellCor==0);
826 CPPUNIT_ASSERT(nodeCor==0);
827 mesh1->checkGeoEquivalWith(mesh2,1,1e-12,cellCor,nodeCor);//fastEqual
828 CPPUNIT_ASSERT(cellCor==0);
829 CPPUNIT_ASSERT(nodeCor==0);
830 mesh1->checkGeoEquivalWith(mesh2,10,1e-12,cellCor,nodeCor);//deepEqual with geo permutations
831 CPPUNIT_ASSERT(cellCor==0);
832 CPPUNIT_ASSERT(nodeCor==0);
833 //Third test : cell permutation by keeping the first the middle and the last as it is.
834 const mcIdType renum[]={0,2,1,3,4,5,6,8,7,9};
835 mesh2->renumberCells(renum,false);
836 CPPUNIT_ASSERT_THROW(mesh1->checkGeoEquivalWith(mesh2,0,1e-12,cellCor,nodeCor),INTERP_KERNEL::Exception);//deepEqual fails
837 CPPUNIT_ASSERT(cellCor==0);
838 CPPUNIT_ASSERT(nodeCor==0);
839 mesh1->checkGeoEquivalWith(mesh2,1,1e-12,cellCor,nodeCor);//fastEqual do not see anything
840 CPPUNIT_ASSERT(cellCor==0);
841 CPPUNIT_ASSERT(nodeCor==0);
842 mesh1->checkGeoEquivalWith(mesh2,10,1e-12,cellCor,nodeCor);//deepEqual with geo permutations
843 CPPUNIT_ASSERT(cellCor);
844 CPPUNIT_ASSERT_EQUAL(10,(int)cellCor->getNumberOfTuples());
845 CPPUNIT_ASSERT_EQUAL(1,(int)cellCor->getNumberOfComponents());
846 CPPUNIT_ASSERT(std::equal(renum,renum+10,cellCor->getConstPointer()));
847 CPPUNIT_ASSERT(nodeCor==0);
850 CPPUNIT_ASSERT(nodeCor==0);
851 //4th test : cell and node permutation by keeping the first the middle and the last as it is.
853 mesh2=build2DTargetMesh_3();
854 const mcIdType renum2[]={0,2,1,3,4,5,6,8,7,9,10};
855 mesh2->renumberCells(renum,false);
856 mesh2->renumberNodes(renum2,11);
857 CPPUNIT_ASSERT_THROW(mesh1->checkGeoEquivalWith(mesh2,0,1e-12,cellCor,nodeCor),INTERP_KERNEL::Exception);//deepEqual fails
858 CPPUNIT_ASSERT(cellCor==0);
859 CPPUNIT_ASSERT(nodeCor==0);
860 mesh1->checkGeoEquivalWith(mesh2,1,1e-12,cellCor,nodeCor);//fastEqual do not see anything
861 CPPUNIT_ASSERT(cellCor==0);
862 CPPUNIT_ASSERT(nodeCor==0);
863 mesh1->checkGeoEquivalWith(mesh2,10,1e-12,cellCor,nodeCor);//deepEqual with geo permutations
864 CPPUNIT_ASSERT(cellCor);
865 CPPUNIT_ASSERT_EQUAL(10,(int)cellCor->getNumberOfTuples());
866 CPPUNIT_ASSERT_EQUAL(1,(int)cellCor->getNumberOfComponents());
867 CPPUNIT_ASSERT(std::equal(renum,renum+10,cellCor->getConstPointer()));
868 CPPUNIT_ASSERT(nodeCor);
869 CPPUNIT_ASSERT_EQUAL(11,(int)nodeCor->getNumberOfTuples());
870 CPPUNIT_ASSERT_EQUAL(1,(int)nodeCor->getNumberOfComponents());
871 CPPUNIT_ASSERT(std::equal(renum2,renum2+11,nodeCor->getConstPointer()));
876 //5th test : modification of the last cell to check fastCheck detection.
878 mesh2=build2DTargetMesh_3();
879 const mcIdType renum3[]={0,2,1,3,4,5,6,8,9,7};
880 mesh2->renumberCells(renum3,false);
881 mesh2->renumberNodes(renum2,11);
883 try { mesh1->checkGeoEquivalWith(mesh2,0,1e-12,cellCor,nodeCor);//deepEqual fails
885 catch(INTERP_KERNEL::Exception&) { isExcep=true; }
886 CPPUNIT_ASSERT(isExcep); isExcep=false;
887 CPPUNIT_ASSERT(cellCor==0);
888 CPPUNIT_ASSERT(nodeCor==0);
889 try { mesh1->checkGeoEquivalWith(mesh2,1,1e-12,cellCor,nodeCor);//fastEqual has detected something
891 catch(INTERP_KERNEL::Exception&) { isExcep=true; }
892 CPPUNIT_ASSERT(isExcep); isExcep=false;
893 CPPUNIT_ASSERT(cellCor==0);
894 CPPUNIT_ASSERT(nodeCor==0);
895 mesh2->checkGeoEquivalWith(mesh1,10,1e-12,cellCor,nodeCor);//deepEqual with geo permutations
896 CPPUNIT_ASSERT(cellCor);
897 CPPUNIT_ASSERT_EQUAL(10,(int)cellCor->getNumberOfTuples());
898 CPPUNIT_ASSERT_EQUAL(1,(int)cellCor->getNumberOfComponents());
899 CPPUNIT_ASSERT(std::equal(renum3,renum3+10,cellCor->getConstPointer()));
900 CPPUNIT_ASSERT(nodeCor);
901 CPPUNIT_ASSERT_EQUAL(11,(int)nodeCor->getNumberOfTuples());
902 CPPUNIT_ASSERT_EQUAL(1,(int)nodeCor->getNumberOfComponents());
903 CPPUNIT_ASSERT(std::equal(renum2,renum2+11,nodeCor->getConstPointer()));
913 void MEDCouplingBasicsTest2::testCheckGeoEquivalWith2()
915 MEDCouplingUMesh *mesh1=build2DTargetMesh_4();
916 MEDCouplingUMesh *mesh2=build2DTargetMesh_1();
917 DataArrayIdType *cellCor,*nodeCor;
918 mesh1->checkGeoEquivalWith(mesh2,10,1e-12,cellCor,nodeCor);
919 CPPUNIT_ASSERT(cellCor==0);
920 CPPUNIT_ASSERT(nodeCor!=0);
921 const mcIdType expected1[9]={0, 1, 3, 4, 5, 6, 7, 8, 9};
923 CPPUNIT_ASSERT_EQUAL(expected1[i],nodeCor->getIJ(i,0));
930 void MEDCouplingBasicsTest2::testCopyTinyStringsFromOnFields()
932 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
933 std::size_t nbOfCells=m->getNumberOfCells();
934 MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
936 CPPUNIT_ASSERT_EQUAL(ToIdType(5),f->getNumberOfMeshPlacesExpected());
938 f->setDescription("b");
939 DataArrayDouble *a1=DataArrayDouble::New();
940 a1->alloc(nbOfCells,2);
942 a1->setInfoOnComponent(0,"c");
943 a1->setInfoOnComponent(1,"d");
944 DataArrayDouble *a2=a1->deepCopy();
945 a2->setInfoOnComponent(0,"e");
946 a2->setInfoOnComponent(1,"f");
949 f->setEndTime(3.,3,4);
953 m->getCoords()->setInfoOnComponent(0,"h");
954 m->getCoords()->setInfoOnComponent(1,"i");
955 m->getCoords()->setInfoOnComponent(2,"j");
957 f->checkConsistencyLight();
958 MEDCouplingFieldDouble *f2=f->clone(true);
959 CPPUNIT_ASSERT(f2->isEqual(f,1e-12,1e-12));
961 CPPUNIT_ASSERT(!f2->isEqual(f,1e-12,1e-12));
962 f2->copyTinyStringsFrom(f);
963 CPPUNIT_ASSERT(f2->isEqual(f,1e-12,1e-12));
964 f2->setDescription("GGG");
965 CPPUNIT_ASSERT(!f2->isEqual(f,1e-12,1e-12));
966 f2->copyTinyStringsFrom(f);
967 CPPUNIT_ASSERT(f2->isEqual(f,1e-12,1e-12));
968 f2->getArray()->setInfoOnComponent(0,"mmmm");
969 CPPUNIT_ASSERT(!f2->isEqual(f,1e-12,1e-12));
970 f2->copyTinyStringsFrom(f);
971 CPPUNIT_ASSERT(f2->isEqual(f,1e-12,1e-12));
972 f2->getEndArray()->setInfoOnComponent(1,"mmmm");
973 CPPUNIT_ASSERT(!f2->isEqual(f,1e-12,1e-12));
974 f2->copyTinyStringsFrom(f);
975 CPPUNIT_ASSERT(f2->isEqual(f,1e-12,1e-12));
977 MEDCouplingUMesh *m2=m->clone(true);
978 CPPUNIT_ASSERT(m2->isEqual(m,1e-12));
980 CPPUNIT_ASSERT(!m2->isEqual(m,1e-12));
981 m2->copyTinyStringsFrom(m);
982 CPPUNIT_ASSERT(m2->isEqual(m,1e-12));
983 m2->getCoords()->setInfoOnComponent(1,"eee");
984 CPPUNIT_ASSERT(!m2->isEqual(m,1e-12));
985 m2->copyTinyStringsFrom(m);
986 CPPUNIT_ASSERT(m2->isEqual(m,1e-12));
993 void MEDCouplingBasicsTest2::testTryToShareSameCoordsPermute()
995 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
996 MEDCouplingUMesh *m2=build3DSurfTargetMesh_1();
997 CPPUNIT_ASSERT(m->getCoords()!=m2->getCoords());
998 m->tryToShareSameCoordsPermute(*m2,1e-12);
999 CPPUNIT_ASSERT(m->getCoords()==m2->getCoords());
1000 CPPUNIT_ASSERT(m2->isEqual(m,1e-12));
1001 const mcIdType renum1[9]={1,2,0,5,8,7,4,3,6};
1002 m->renumberNodes(renum1,9);
1003 CPPUNIT_ASSERT(m->getCoords()!=m2->getCoords());
1004 CPPUNIT_ASSERT(!m2->isEqual(m,1e-12));
1005 m->tryToShareSameCoordsPermute(*m2,1e-12);
1006 CPPUNIT_ASSERT(m->getCoords()==m2->getCoords());
1007 CPPUNIT_ASSERT(m2->isEqual(m,1e-12));
1012 void MEDCouplingBasicsTest2::testTryToShareSameCoordsPermute2()
1014 MEDCouplingUMesh *m1=build2DTargetMesh_4();
1015 double targetCoords[8]={-0.3,-0.3, 0.2,-0.3, -0.3,0.2, 0.2,0.2 };
1016 mcIdType targetConn[4]={0,2,3,1};
1017 MEDCouplingUMesh *m2=MEDCouplingUMesh::New();
1018 m2->setMeshDimension(2);
1019 m2->allocateCells(1);
1020 m2->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn);
1021 m2->finishInsertingCells();
1022 DataArrayDouble *myCoords=DataArrayDouble::New();
1023 myCoords->alloc(4,2);
1024 std::copy(targetCoords,targetCoords+8,myCoords->getPointer());
1025 m2->setCoords(myCoords);
1026 myCoords->decrRef();
1027 m2->checkConsistencyLight();
1028 m1->checkConsistencyLight();
1030 const double expected1[5]={0.25,0.125,0.125,0.25,0.25};
1031 MEDCouplingFieldDouble *f1=m1->getMeasureField(false);
1032 MEDCouplingFieldDouble *f2=m2->getMeasureField(false);
1033 CPPUNIT_ASSERT_EQUAL(5,(int)f1->getArray()->getNumberOfTuples());
1034 CPPUNIT_ASSERT_EQUAL(1,(int)f2->getArray()->getNumberOfTuples());
1035 for(int i=0;i<5;i++)
1036 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(i,0),1e-12);
1037 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(0,0),1e-12);
1040 CPPUNIT_ASSERT_THROW(m1->tryToShareSameCoordsPermute(*m2,1e-12),INTERP_KERNEL::Exception);// <- here in this order the sharing is impossible.
1041 // Let's go for deeper test of tryToShareSameCoordsPermute
1042 m2->tryToShareSameCoordsPermute(*m1,1e-12);
1043 f1=m1->getMeasureField(false);
1044 f2=m2->getMeasureField(false);
1045 CPPUNIT_ASSERT_EQUAL(5,(int)f1->getArray()->getNumberOfTuples());
1046 CPPUNIT_ASSERT_EQUAL(1,(int)f2->getArray()->getNumberOfTuples());
1047 for(int i=0;i<5;i++)
1048 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(i,0),1e-12);
1049 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(0,0),1e-12);
1058 void MEDCouplingBasicsTest2::testChangeUnderlyingMesh1()
1060 MEDCouplingUMesh *mesh1=build2DTargetMesh_3();
1061 MEDCouplingUMesh *mesh2=build2DTargetMesh_3();
1062 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1064 DataArrayDouble *array=DataArrayDouble::New();
1065 array->alloc(mesh1->getNumberOfCells(),2);
1066 const double arr[20]={7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.};
1067 std::copy(arr,arr+20,array->getPointer());
1068 f1->setArray(array);
1071 const mcIdType renum[]={0,2,1,3,4,5,6,8,7,9};
1072 mesh2->renumberCells(renum,false);
1073 CPPUNIT_ASSERT(f1->getMesh()==mesh1);
1074 f1->changeUnderlyingMesh(mesh1,10,1e-12);// nothing done only to check that nothing done.
1075 CPPUNIT_ASSERT(f1->getMesh()==mesh1);
1076 f1->changeUnderlyingMesh(mesh2,10,1e-12);
1077 CPPUNIT_ASSERT(f1->getMesh()==mesh2);
1078 const double expected1[20]={7.,107.,9.,109.,8.,108.,10.,110.,11.,111.,12.,112.,13.,113.,15.,115.,14.,114.,16.,116.};
1079 for(int i=0;i<20;i++)
1080 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getArray()->getIJ(0,i),1e-12);
1083 f1=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
1085 array=DataArrayDouble::New();
1086 array->alloc(mesh1->getNumberOfNodes(),2);
1087 const double arr2[22]={7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.,17.,117.};
1088 std::copy(arr2,arr2+22,array->getPointer());
1089 f1->setArray(array);
1092 const mcIdType renum2[]={0,2,10,3,4,5,6,8,7,9,1};
1093 mesh2->renumberNodes(renum2,11);
1094 CPPUNIT_ASSERT(f1->getMesh()==mesh1);
1095 f1->changeUnderlyingMesh(mesh2,10,1e-12);
1096 CPPUNIT_ASSERT(f1->getMesh()==mesh2);
1097 const double expected2[22]={7.,107.,17.,117.,8.,108.,10.,110.,11.,111.,12.,112.,13.,113.,15.,115.,14.,114.,16.,116.,9.,109.};
1098 for(int i=0;i<22;i++)
1099 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f1->getArray()->getIJ(0,i),1e-12);
1106 void MEDCouplingBasicsTest2::testGetMaxValue1()
1108 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1109 std::size_t nbOfCells=m->getNumberOfCells();
1110 MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
1112 DataArrayDouble *a1=DataArrayDouble::New();
1113 a1->alloc(nbOfCells,1);
1114 const double val1[5]={3.,4.,5.,6.,7.};
1115 std::copy(val1,val1+5,a1->getPointer());
1116 DataArrayDouble *a2=DataArrayDouble::New();
1117 a2->alloc(nbOfCells,1);
1118 const double val2[5]={0.,1.,2.,8.,7.};
1119 std::copy(val2,val2+5,a2->getPointer());
1122 f->setEndTime(3.,3,4);
1123 f->checkConsistencyLight();
1125 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.,f->getMaxValue(),1e-14);
1126 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,f->getMinValue(),1e-14);
1127 CPPUNIT_ASSERT_DOUBLES_EQUAL(5.,f->getAverageValue(),1e-14);
1128 CPPUNIT_ASSERT_DOUBLES_EQUAL(5.125,f->getWeightedAverageValue(0),1e-14);
1130 CPPUNIT_ASSERT_DOUBLES_EQUAL(9.5,f->getMaxValue(),1e-14);
1131 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,f->getMinValue(),1e-14);
1133 CPPUNIT_ASSERT_DOUBLES_EQUAL(9.5,f->getMaxValue(),1e-14);
1134 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,f->getMinValue(),1e-14);
1142 void MEDCouplingBasicsTest2::testSubstractInPlaceDM1()
1144 MEDCouplingUMesh *mesh1=build2DTargetMesh_3();
1145 MEDCouplingUMesh *mesh2=build2DTargetMesh_3();
1146 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1148 DataArrayDouble *array=DataArrayDouble::New();
1149 array->alloc(mesh1->getNumberOfCells(),2);
1150 const double arr[20]={7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.};
1151 std::copy(arr,arr+20,array->getPointer());
1152 f1->setArray(array);
1155 CPPUNIT_ASSERT_EQUAL(10,(int)f1->getNumberOfTuples());
1156 CPPUNIT_ASSERT_EQUAL(2,(int)f1->getNumberOfComponents());
1157 CPPUNIT_ASSERT_EQUAL(20,(int)f1->getNumberOfValues());
1159 const mcIdType renum[]={0,2,3,1,4,5,6,8,7,9};
1160 mesh2->renumberCells(renum,false);
1162 MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1164 array=DataArrayDouble::New();
1165 array->alloc(mesh2->getNumberOfCells(),2);
1166 const double arr2[20]={7.1,107.1,10.1,110.1,8.1,108.1,9.1,109.1,11.1,111.1,12.1,112.1,13.1,113.1,15.1,115.1,14.1,114.1,16.1,116.1};
1167 std::copy(arr2,arr2+20,array->getPointer());
1168 f2->setArray(array);
1171 f1->substractInPlaceDM(f2,10,1e-12);
1172 f1->applyFunc(1,"abs(x+y+0.2)");
1173 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,f1->getMaxValue(),1e-14);
1181 void MEDCouplingBasicsTest2::testDotCrossProduct1()
1183 MEDCouplingUMesh *mesh1=build2DTargetMesh_3();
1184 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1185 f1->setTime(2.3,5,6);
1187 DataArrayDouble *array=DataArrayDouble::New();
1188 array->alloc(mesh1->getNumberOfCells(),3);
1189 const double arr1[30]={7.,107.,207.,8.,108.,208.,9.,109.,209.,10.,110.,210.,11.,111.,211.,12.,112.,212.,13.,113.,213.,14.,114.,214.,15.,115.,215.,16.,116.,216.};
1190 std::copy(arr1,arr1+30,array->getPointer());
1191 f1->setArray(array);
1193 MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1194 f2->setTime(7.8,4,5);
1196 array=DataArrayDouble::New();
1197 array->alloc(mesh1->getNumberOfCells(),3);
1198 const double arr2[30]={1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.,25.,26.,27.,28.,29.,30.};
1199 std::copy(arr2,arr2+30,array->getPointer());
1200 f2->setArray(array);
1203 MEDCouplingFieldDouble *f3=f1->dot(*f2);
1204 const double expected1[10]={842.,1820.,2816.,3830.,4862.,5912.,6980.,8066.,9170.,10292.};
1205 for(int i=0;i<10;i++)
1206 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f3->getIJ(i,0),1e-9);
1209 MEDCouplingFieldDouble *f4=f1->crossProduct(*f2);
1210 const double expected2[30]={-93., 186., -93., -392., 784., -392., -691., 1382., -691., -990., 1980., -990., -1289., 2578., -1289., -1588., 3176., -1588., -1887., 3774., -1887., -2186., 4372., -2186., -2485., 4970., -2485., -2784., 5568., -2784.};
1211 for(int i=0;i<30;i++)
1212 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f4->getIJ(0,i),1e-9);
1220 void MEDCouplingBasicsTest2::testMinMaxFields1()
1222 MEDCouplingUMesh *mesh1=build2DTargetMesh_3();
1223 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1224 f1->setTime(2.3,5,6);
1226 DataArrayDouble *array=DataArrayDouble::New();
1227 array->alloc(mesh1->getNumberOfCells(),3);
1228 const double arr1[30]={7.,107.,207.,8.,108.,208.,9.,109.,209.,10.,110.,210.,11.,111.,211.,12.,112.,212.,13.,113.,213.,14.,114.,214.,15.,115.,215.,16.,116.,216.};
1229 std::copy(arr1,arr1+30,array->getPointer());
1230 f1->setArray(array);
1232 MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1233 f2->setTime(7.8,4,5);
1235 array=DataArrayDouble::New();
1236 array->alloc(mesh1->getNumberOfCells(),3);
1237 const double arr2[30]={6.,108.,206.,9.,107.,209.,8.,110.,208.,11.,109.,211.,10.,112.,210.,13.,111.,213.,12.,114.,212.,15.,113.,215.,14.,116.,214.,17.,115.,217.};
1238 std::copy(arr2,arr2+30,array->getPointer());
1239 f2->setArray(array);
1242 MEDCouplingFieldDouble *f3=f1->max(*f2);
1243 const double expected1[30]={7.,108.,207.,9.,108.,209.,9.,110.,209.,11.,110.,211.,11.,112.,211.,13.,112.,213.,13.,114.,213.,15.,114.,215.,15.,116.,215.,17.,116.,217.};
1244 for(int i=0;i<30;i++)
1245 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f3->getIJ(0,i),1e-9);
1248 MEDCouplingFieldDouble *f4=f1->min(*f2);
1249 const double expected2[30]={6.,107.,206.,8.,107.,208.,8.,109.,208.,10.,109.,210.,10.,111.,210.,12.,111.,212.,12.,113.,212.,14.,113.,214.,14.,115.,214.,16.,115.,216.};
1250 for(int i=0;i<30;i++)
1251 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f4->getIJ(0,i),1e-9);
1259 void MEDCouplingBasicsTest2::testApplyLin1()
1261 MEDCouplingUMesh *mesh1=build2DTargetMesh_3();
1262 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
1264 DataArrayDouble *array=DataArrayDouble::New();
1265 array->alloc(mesh1->getNumberOfCells(),2);
1266 const double arr[20]={7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.};
1267 std::copy(arr,arr+20,array->getPointer());
1268 f1->setArray(array);
1271 f1->applyLin(2.,3.,0);
1272 const double expected1[20]={17.,107.,19.,108.,21.,109.,23.,110.,25.,111.,27.,112.,29.,113.,31.,114.,33.,115.,35.,116.};
1273 for(int i=0;i<20;i++)
1274 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-9);
1276 const double arr2[20]={2.,102.,3.,103.,4.,104.,5.,105.,6.,106.,7.,107.,8.,108.,9.,109.,10.,110.,11.,111.};
1277 array=DataArrayDouble::New();
1278 array->alloc(mesh1->getNumberOfCells(),2);
1279 std::copy(arr2,arr2+20,array->getPointer());
1280 f1->setEndArray(array);
1283 f1->applyLin(4.,5.,1);
1285 const double expected2[20]={17.,433.,19.,437.,21.,441.,23.,445.,25.,449.,27.,453.,29.,457.,31.,461.,33.,465.,35.,469.};
1286 for(int i=0;i<20;i++)
1287 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f1->getIJ(0,i),1e-9);
1288 const double expected3[20]={2.,413.,3.,417.,4.,421.,5.,425.,6.,429.,7.,433.,8.,437.,9.,441.,10.,445.,11.,449.};
1289 for(int i=0;i<20;i++)
1290 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],f1->getEndArray()->getIJ(0,i),1e-9);
1296 void MEDCouplingBasicsTest2::testGetIdsInRange1()
1298 MEDCouplingUMesh *mesh1=build2DTargetMesh_3();
1299 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1300 f1->setTime(2.3,5,6);
1302 DataArrayDouble *array=DataArrayDouble::New();
1303 array->alloc(mesh1->getNumberOfCells(),1);
1304 const double arr1[10]={2.,8.,6.,5.,11.,7.,9.,3.,10.,4.};
1305 std::copy(arr1,arr1+10,array->getPointer());
1306 f1->setArray(array);
1309 f1->checkConsistencyLight();
1310 DataArrayIdType *da=f1->findIdsInRange(2.9,7.1);
1311 CPPUNIT_ASSERT_EQUAL(ToIdType(5),da->getNbOfElems());
1312 const mcIdType expected1[5]={2,3,5,7,9};
1313 CPPUNIT_ASSERT(std::equal(expected1,expected1+5,da->getConstPointer()));
1315 da=f1->findIdsInRange(8.,12.);
1316 CPPUNIT_ASSERT_EQUAL(ToIdType(4),da->getNbOfElems());
1317 const mcIdType expected2[4]={1,4,6,8};
1318 CPPUNIT_ASSERT(std::equal(expected2,expected2+4,da->getConstPointer()));
1325 void MEDCouplingBasicsTest2::testBuildSubPart1()
1327 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1328 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1329 f1->setTime(2.3,5,6);
1331 DataArrayDouble *array=DataArrayDouble::New();
1332 array->alloc(mesh1->getNumberOfCells(),2);
1333 const double arr1[10]={3.,103.,4.,104.,5.,105.,6.,106.,7.,107.};
1334 std::copy(arr1,arr1+10,array->getPointer());
1335 f1->setArray(array);
1338 const mcIdType part1[3]={2,1,4};
1339 MEDCouplingFieldDouble *f2=f1->buildSubPart(part1,part1+3);
1341 CPPUNIT_ASSERT_EQUAL(3,(int)f2->getNumberOfTuples());
1342 CPPUNIT_ASSERT_EQUAL(2,(int)f2->getNumberOfComponents());
1343 const double expected1[6]={5.,105.,4.,104.,7.,107.};
1344 for(int i=0;i<6;i++)
1345 CPPUNIT_ASSERT_DOUBLES_EQUAL(f2->getIJ(0,i),expected1[i],1e-12);
1346 CPPUNIT_ASSERT_EQUAL(3,(int)f2->getMesh()->getNumberOfCells());
1347 CPPUNIT_ASSERT_EQUAL(6,(int)f2->getMesh()->getNumberOfNodes());
1348 CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getSpaceDimension());
1349 CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getMeshDimension());
1350 MEDCouplingUMesh *m2C=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1351 CPPUNIT_ASSERT_EQUAL(ToIdType(13),m2C->getNodalConnectivityArrayLen());
1352 const double expected2[12]={0.2, -0.3, 0.7, -0.3, 0.2, 0.2, 0.7, 0.2, 0.2, 0.7, 0.7, 0.7};
1353 for(int i=0;i<12;i++)
1354 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],m2C->getCoords()->getIJ(0,i),1.e-12);
1355 const double expected3[13]={3,2,3,1,3,0,2,1,4,4,5,3,2};
1356 CPPUNIT_ASSERT(std::equal(expected3,expected3+13,m2C->getNodalConnectivity()->getConstPointer()));
1357 const double expected4[4]={0,4,8,13};
1358 CPPUNIT_ASSERT(std::equal(expected4,expected4+4,m2C->getNodalConnectivityIndex()->getConstPointer()));
1361 // Test with field on nodes.
1362 f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
1363 f1->setTime(2.3,5,6);
1365 array=DataArrayDouble::New();
1366 array->alloc(mesh1->getNumberOfNodes(),2);
1367 const double arr2[18]={3.,103.,4.,104.,5.,105.,6.,106.,7.,107.,8.,108.,9.,109.,10.,110.,11.,111.};
1368 std::copy(arr2,arr2+18,array->getPointer());
1369 f1->setArray(array);
1371 const mcIdType part2[2]={1,2};
1372 f2=f1->buildSubPart(part2,part2+2);
1373 CPPUNIT_ASSERT_EQUAL(4,(int)f2->getNumberOfTuples());
1374 CPPUNIT_ASSERT_EQUAL(2,(int)f2->getNumberOfComponents());
1375 const double expected5[8]={4.,104.,5.,105.,7.,107.,8.,108.};
1376 for(int i=0;i<8;i++)
1377 CPPUNIT_ASSERT_DOUBLES_EQUAL(f2->getIJ(0,i),expected5[i],1e-12);
1378 CPPUNIT_ASSERT_EQUAL(2,(int)f2->getMesh()->getNumberOfCells());
1379 CPPUNIT_ASSERT_EQUAL(4,(int)f2->getMesh()->getNumberOfNodes());
1380 CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getSpaceDimension());
1381 CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getMeshDimension());
1382 m2C=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1383 CPPUNIT_ASSERT_EQUAL(ToIdType(8),m2C->getNodalConnectivityArrayLen());
1384 for(int i=0;i<8;i++)//8 is not an error
1385 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],m2C->getCoords()->getIJ(0,i),1.e-12);
1386 CPPUNIT_ASSERT(std::equal(expected3,expected3+4,m2C->getNodalConnectivity()->getConstPointer()+4));
1387 CPPUNIT_ASSERT(std::equal(expected3+4,expected3+8,m2C->getNodalConnectivity()->getConstPointer()));
1388 CPPUNIT_ASSERT(std::equal(expected4,expected4+3,m2C->getNodalConnectivityIndex()->getConstPointer()));
1390 //idem previous because nodes of cell#4 are not fully present in part3
1391 const mcIdType part3[2]={1,2};
1392 DataArrayIdType *arrr=DataArrayIdType::New();
1394 std::copy(part3,part3+2,arrr->getPointer());
1395 f2=f1->buildSubPart(arrr);
1397 CPPUNIT_ASSERT_EQUAL(4,(int)f2->getNumberOfTuples());
1398 CPPUNIT_ASSERT_EQUAL(2,(int)f2->getNumberOfComponents());
1399 for(int i=0;i<8;i++)
1400 CPPUNIT_ASSERT_DOUBLES_EQUAL(f2->getIJ(0,i),expected5[i],1e-12);
1401 CPPUNIT_ASSERT_EQUAL(2,(int)f2->getMesh()->getNumberOfCells());
1402 CPPUNIT_ASSERT_EQUAL(4,(int)f2->getMesh()->getNumberOfNodes());
1403 CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getSpaceDimension());
1404 CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getMeshDimension());
1405 m2C=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1406 CPPUNIT_ASSERT_EQUAL(ToIdType(8),m2C->getNodalConnectivityArrayLen());
1407 for(int i=0;i<8;i++)//8 is not an error
1408 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],m2C->getCoords()->getIJ(0,i),1.e-12);
1409 CPPUNIT_ASSERT(std::equal(expected3,expected3+4,m2C->getNodalConnectivity()->getConstPointer()+4));
1410 CPPUNIT_ASSERT(std::equal(expected3+4,expected3+8,m2C->getNodalConnectivity()->getConstPointer()));
1411 CPPUNIT_ASSERT(std::equal(expected4,expected4+3,m2C->getNodalConnectivityIndex()->getConstPointer()));
1414 const mcIdType part4[3]={1,2,4};
1415 f2=f1->buildSubPart(part4,part4+3);
1416 CPPUNIT_ASSERT_EQUAL(6,(int)f2->getNumberOfTuples());
1417 CPPUNIT_ASSERT_EQUAL(2,(int)f2->getNumberOfComponents());
1418 const double expected6[12]={4.,104.,5.,105.,7.,107.,8.,108.,10.,110.,11.,111.};
1419 for(int i=0;i<12;i++)
1420 CPPUNIT_ASSERT_DOUBLES_EQUAL(f2->getIJ(0,i),expected6[i],1e-12);
1421 CPPUNIT_ASSERT_EQUAL(3,(int)f2->getMesh()->getNumberOfCells());
1422 CPPUNIT_ASSERT_EQUAL(6,(int)f2->getMesh()->getNumberOfNodes());
1423 CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getSpaceDimension());
1424 CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getMeshDimension());
1425 m2C=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1426 CPPUNIT_ASSERT_EQUAL(ToIdType(13),m2C->getNodalConnectivityArrayLen());
1427 for(int i=0;i<12;i++)
1428 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],m2C->getCoords()->getIJ(0,i),1.e-12);
1429 CPPUNIT_ASSERT(std::equal(expected3,expected3+4,m2C->getNodalConnectivity()->getConstPointer()+4));
1430 CPPUNIT_ASSERT(std::equal(expected3+4,expected3+8,m2C->getNodalConnectivity()->getConstPointer()));
1431 CPPUNIT_ASSERT(std::equal(expected3+8,expected3+13,m2C->getNodalConnectivity()->getConstPointer()+8));
1432 CPPUNIT_ASSERT(std::equal(expected4,expected4+4,m2C->getNodalConnectivityIndex()->getConstPointer()));
1439 void MEDCouplingBasicsTest2::testDoublyContractedProduct1()
1441 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1442 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1444 DataArrayDouble *array=DataArrayDouble::New();
1445 array->alloc(mesh1->getNumberOfCells(),6);
1446 const double arr1[30]={7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5};
1447 std::copy(arr1,arr1+30,array->getPointer());
1448 f1->setArray(array);
1450 f1->checkConsistencyLight();
1452 MEDCouplingFieldDouble *f2=f1->doublyContractedProduct();
1453 f2->checkConsistencyLight();
1454 CPPUNIT_ASSERT_EQUAL(1,(int)f2->getNumberOfComponents());
1455 CPPUNIT_ASSERT_EQUAL(5,(int)f2->getNumberOfTuples());
1456 for(int i=0;i<5;i++)
1457 CPPUNIT_ASSERT_DOUBLES_EQUAL(3906.56,f2->getIJ(i,0),1e-9);
1464 void MEDCouplingBasicsTest2::testDeterminant1()
1466 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1467 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,CONST_ON_TIME_INTERVAL);
1468 f1->setTime(2.3,5,6);
1469 f1->setEndTime(3.8,7,3);
1471 DataArrayDouble *array=DataArrayDouble::New();
1472 array->alloc(mesh1->getNumberOfCells(),4);
1473 const double arr1[20]={1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5};
1474 std::copy(arr1,arr1+20,array->getPointer());
1475 f1->setArray(array);
1478 f1->checkConsistencyLight();
1479 MEDCouplingFieldDouble *f2=f1->determinant();
1480 f2->checkConsistencyLight();
1481 CPPUNIT_ASSERT_EQUAL(CONST_ON_TIME_INTERVAL,f2->getTimeDiscretization());
1482 CPPUNIT_ASSERT_EQUAL(1,(int)f2->getNumberOfComponents());
1483 CPPUNIT_ASSERT_EQUAL(5,(int)f2->getNumberOfValues());
1484 for(int i=0;i<5;i++)
1485 CPPUNIT_ASSERT_DOUBLES_EQUAL(-2.42,f2->getIJ(i,0),1e-13);
1488 //6 components multi arrays with end array not defined
1489 f1=MEDCouplingFieldDouble::New(ON_NODES,LINEAR_TIME);
1490 f1->setTime(2.3,5,6);
1491 f1->setEndTime(3.8,7,3);
1493 array=DataArrayDouble::New();
1494 array->alloc(mesh1->getNumberOfNodes(),6);
1495 const double arr2[54]={1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7,
1496 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7};
1497 std::copy(arr2,arr2+54,array->getPointer());
1498 f1->setArray(array);
1500 CPPUNIT_ASSERT_THROW(f1->checkConsistencyLight(),INTERP_KERNEL::Exception);//no end array specified !
1502 f2=f1->determinant();
1503 CPPUNIT_ASSERT_EQUAL(LINEAR_TIME,f2->getTimeDiscretization());
1504 CPPUNIT_ASSERT_EQUAL(1,(int)f2->getArray()->getNumberOfComponents());
1505 CPPUNIT_ASSERT_EQUAL(9,(int)f2->getNumberOfTuples());
1506 for(int i=0;i<9;i++)
1507 CPPUNIT_ASSERT_DOUBLES_EQUAL(137.335,f2->getIJ(i,0),1e-10);
1509 //6 components multi arrays with end array defined
1510 array=DataArrayDouble::New();
1511 array->alloc(mesh1->getNumberOfNodes(),6);
1512 const double arr3[54]={7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5,
1513 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5};
1514 std::copy(arr3,arr3+54,array->getPointer());
1515 f1->setEndArray(array);
1517 f1->checkConsistencyLight();
1518 f2=f1->determinant();
1519 f2->checkConsistencyLight();
1520 CPPUNIT_ASSERT_EQUAL(LINEAR_TIME,f2->getTimeDiscretization());
1521 CPPUNIT_ASSERT_EQUAL(1,(int)f2->getNumberOfComponents());
1522 CPPUNIT_ASSERT_EQUAL(9,(int)f2->getNumberOfTuples());
1524 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.3,f2->getTime(it,order),1e-12);
1525 CPPUNIT_ASSERT_EQUAL(5,it); CPPUNIT_ASSERT_EQUAL(6,order);
1526 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.8,f2->getEndTime(it,order),1e-12);
1527 CPPUNIT_ASSERT_EQUAL(7,it); CPPUNIT_ASSERT_EQUAL(3,order);
1528 for(int i=0;i<9;i++)
1530 CPPUNIT_ASSERT_DOUBLES_EQUAL(137.335,f2->getIJ(i,0),1e-10);
1531 CPPUNIT_ASSERT_DOUBLES_EQUAL(1289.685,f2->getEndArray()->getIJ(i,0),1e-9);
1536 f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1537 f1->setTime(7.8,10,2);
1539 array=DataArrayDouble::New();
1540 array->alloc(mesh1->getNumberOfCells(),9);
1541 const double arr4[45]={1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1};
1542 std::copy(arr4,arr4+45,array->getPointer());
1543 f1->setArray(array);
1546 f1->checkConsistencyLight();
1547 f2=f1->determinant();
1548 f2->checkConsistencyLight();
1549 CPPUNIT_ASSERT_EQUAL(ONE_TIME,f2->getTimeDiscretization());
1550 CPPUNIT_ASSERT_EQUAL(1,(int)f2->getNumberOfComponents());
1551 CPPUNIT_ASSERT_EQUAL(5,(int)f2->getNumberOfTuples());
1552 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.8,f2->getTime(it,order),1e-12);
1553 CPPUNIT_ASSERT_EQUAL(10,it); CPPUNIT_ASSERT_EQUAL(2,order);
1554 for(int i=0;i<5;i++)
1555 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.267,f2->getIJ(i,0),1e-13);
1562 void MEDCouplingBasicsTest2::testEigenValues1()
1564 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1565 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1567 DataArrayDouble *array=DataArrayDouble::New();
1568 array->alloc(mesh1->getNumberOfCells(),6);
1569 const double arr1[30]={1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7};
1570 std::copy(arr1,arr1+30,array->getPointer());
1571 f1->setArray(array);
1573 f1->checkConsistencyLight();
1575 MEDCouplingFieldDouble *f2=f1->eigenValues();
1576 f2->checkConsistencyLight();
1577 CPPUNIT_ASSERT_EQUAL(3,(int)f2->getNumberOfComponents());
1578 CPPUNIT_ASSERT_EQUAL(5,(int)f2->getNumberOfTuples());
1579 const double expected1[3]={13.638813677891717,-4.502313844635971,-2.2364998332557486};
1580 for(int i=0;i<5;i++)
1582 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(i,0),1e-13);
1583 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[1],f2->getIJ(i,1),1e-13);
1584 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[2],f2->getIJ(i,2),1e-13);
1592 void MEDCouplingBasicsTest2::testEigenVectors1()
1594 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1595 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1597 DataArrayDouble *array=DataArrayDouble::New();
1598 array->alloc(mesh1->getNumberOfCells(),6);
1599 const double arr1[30]={1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7};
1600 std::copy(arr1,arr1+30,array->getPointer());
1601 f1->setArray(array);
1603 f1->checkConsistencyLight();
1605 MEDCouplingFieldDouble *f2=f1->eigenVectors();
1606 f2->checkConsistencyLight();
1607 CPPUNIT_ASSERT_EQUAL(9,(int)f2->getNumberOfComponents());
1608 CPPUNIT_ASSERT_EQUAL(5,(int)f2->getNumberOfTuples());
1609 const double expected1[9]={
1610 0.5424262364180696, 0.5351201064614425, 0.6476266283176001,//eigenvect 0
1611 0.7381111277307373, 0.06458838384003074, -0.6715804522117897,//eigenvect 1
1612 -0.4012053603397987, 0.8423032781211455, -0.3599436712889738//eigenvect 2
1614 for(int i=0;i<5;i++)
1616 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(i,0),1e-13);
1617 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[1],f2->getIJ(i,1),1e-13);
1618 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[2],f2->getIJ(i,2),1e-13);
1619 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[3],f2->getIJ(i,3),1e-13);
1620 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[4],f2->getIJ(i,4),1e-13);
1621 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[5],f2->getIJ(i,5),1e-13);
1622 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[6],f2->getIJ(i,6),1e-13);
1623 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[7],f2->getIJ(i,7),1e-13);
1624 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[8],f2->getIJ(i,8),1e-13);
1632 void MEDCouplingBasicsTest2::testInverse1()
1634 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1635 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1637 DataArrayDouble *array=DataArrayDouble::New();
1638 array->alloc(mesh1->getNumberOfCells(),9);
1639 const double arr1[45]={1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1};
1640 std::copy(arr1,arr1+45,array->getPointer());
1641 f1->setArray(array);
1643 f1->checkConsistencyLight();
1645 MEDCouplingFieldDouble *f2=f1->inverse();
1646 f2->checkConsistencyLight();
1647 CPPUNIT_ASSERT_EQUAL(9,(int)f2->getNumberOfComponents());
1648 CPPUNIT_ASSERT_EQUAL(5,(int)f2->getNumberOfTuples());
1649 const double expected1[9]={-2.6538108356290113, 2.855831037649208, -1.1111111111111067, 3.461891643709813, -4.775022956841121, 2.2222222222222143, -1.1111111111111054, 2.222222222222214, -1.1111111111111072};
1650 for(int i=0;i<5;i++)
1652 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(i,0),1e-13);
1653 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[1],f2->getIJ(i,1),1e-13);
1654 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[2],f2->getIJ(i,2),1e-13);
1655 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[3],f2->getIJ(i,3),1e-13);
1656 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[4],f2->getIJ(i,4),1e-13);
1657 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[5],f2->getIJ(i,5),1e-13);
1658 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[6],f2->getIJ(i,6),1e-13);
1659 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[7],f2->getIJ(i,7),1e-13);
1660 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[8],f2->getIJ(i,8),1e-13);
1664 array=DataArrayDouble::New();
1665 array->alloc(mesh1->getNumberOfCells(),6);
1666 const double arr3[30]={7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5};
1667 std::copy(arr3,arr3+30,array->getPointer());
1668 f1->setArray(array);
1670 f1->checkConsistencyLight();
1673 f2->checkConsistencyLight();
1674 CPPUNIT_ASSERT_EQUAL(6,(int)f2->getNumberOfComponents());
1675 CPPUNIT_ASSERT_EQUAL(5,(int)f2->getNumberOfTuples());
1676 const double expected3[6]={-0.3617705098531818, -0.8678630828458127, -0.026843764174972983, 0.5539957431465833, 0.13133439560823013, -0.05301294502145887};
1677 for(int i=0;i<5;i++)
1679 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[0],f2->getIJ(i,0),1e-13);
1680 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[1],f2->getIJ(i,1),1e-13);
1681 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[2],f2->getIJ(i,2),1e-13);
1682 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[3],f2->getIJ(i,3),1e-13);
1683 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[4],f2->getIJ(i,4),1e-13);
1684 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[5],f2->getIJ(i,5),1e-13);
1688 array=DataArrayDouble::New();
1689 array->alloc(mesh1->getNumberOfCells(),4);
1690 const double arr2[20]={1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5};
1691 std::copy(arr2,arr2+20,array->getPointer());
1692 f1->setArray(array);
1694 f1->checkConsistencyLight();
1697 f2->checkConsistencyLight();
1698 CPPUNIT_ASSERT_EQUAL(4,(int)f2->getNumberOfComponents());
1699 CPPUNIT_ASSERT_EQUAL(5,(int)f2->getNumberOfTuples());
1700 const double expected2[4]={-1.8595041322314059, 0.9504132231404963, 1.404958677685951, -0.49586776859504156};
1701 for(int i=0;i<5;i++)
1703 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[0],f2->getIJ(i,0),1e-13);
1704 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[1],f2->getIJ(i,1),1e-13);
1705 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[2],f2->getIJ(i,2),1e-13);
1706 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[3],f2->getIJ(i,3),1e-13);
1714 void MEDCouplingBasicsTest2::testTrace1()
1716 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1717 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1719 DataArrayDouble *array=DataArrayDouble::New();
1720 array->alloc(mesh1->getNumberOfCells(),9);
1721 const double arr1[45]={1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1};
1722 std::copy(arr1,arr1+45,array->getPointer());
1723 f1->setArray(array);
1725 f1->checkConsistencyLight();
1727 MEDCouplingFieldDouble *f2=f1->trace();
1728 f2->checkConsistencyLight();
1729 CPPUNIT_ASSERT_EQUAL(1,(int)f2->getNumberOfComponents());
1730 CPPUNIT_ASSERT_EQUAL(5,(int)f2->getNumberOfTuples());
1731 for(int i=0;i<5;i++)
1732 CPPUNIT_ASSERT_DOUBLES_EQUAL(15.9,f2->getIJ(i,0),1e-13);
1735 array=DataArrayDouble::New();
1736 array->alloc(mesh1->getNumberOfCells(),6);
1737 const double arr3[30]={7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5};
1738 std::copy(arr3,arr3+30,array->getPointer());
1739 f1->setArray(array);
1741 f1->checkConsistencyLight();
1744 f2->checkConsistencyLight();
1745 CPPUNIT_ASSERT_EQUAL(1,(int)f2->getNumberOfComponents());
1746 CPPUNIT_ASSERT_EQUAL(5,(int)f2->getNumberOfTuples());
1747 for(int i=0;i<5;i++)
1748 CPPUNIT_ASSERT_DOUBLES_EQUAL(25.8,f2->getIJ(i,0),1e-13);
1751 array=DataArrayDouble::New();
1752 array->alloc(mesh1->getNumberOfCells(),4);
1753 const double arr2[20]={1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5};
1754 std::copy(arr2,arr2+20,array->getPointer());
1755 f1->setArray(array);
1757 f1->checkConsistencyLight();
1760 f2->checkConsistencyLight();
1761 CPPUNIT_ASSERT_EQUAL(1,(int)f2->getNumberOfComponents());
1762 CPPUNIT_ASSERT_EQUAL(5,(int)f2->getNumberOfTuples());
1763 for(int i=0;i<5;i++)
1764 CPPUNIT_ASSERT_DOUBLES_EQUAL(5.7,f2->getIJ(i,0),1e-13);
1771 void MEDCouplingBasicsTest2::testDeviator1()
1773 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1774 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1776 DataArrayDouble *array=DataArrayDouble::New();
1777 array->alloc(mesh1->getNumberOfCells(),6);
1778 const double arr1[30]={1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7};
1779 std::copy(arr1,arr1+30,array->getPointer());
1780 f1->setArray(array);
1782 f1->checkConsistencyLight();
1784 MEDCouplingFieldDouble *f2=f1->deviator();
1785 f2->checkConsistencyLight();
1786 CPPUNIT_ASSERT_EQUAL(6,(int)f2->getNumberOfComponents());
1787 CPPUNIT_ASSERT_EQUAL(5,(int)f2->getNumberOfTuples());
1788 const double expected1[6]={-1.1,0.,1.1,4.5,5.6,6.7};
1789 for(int i=0;i<5;i++)
1791 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(i,0),1e-13);
1792 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[1],f2->getIJ(i,1),1e-13);
1793 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[2],f2->getIJ(i,2),1e-13);
1794 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[3],f2->getIJ(i,3),1e-13);
1795 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[4],f2->getIJ(i,4),1e-13);
1796 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[5],f2->getIJ(i,5),1e-13);
1804 void MEDCouplingBasicsTest2::testMagnitude1()
1806 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1807 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1809 DataArrayDouble *array=DataArrayDouble::New();
1810 array->alloc(mesh1->getNumberOfCells(),5);
1811 const double arr1[25]={1.2,2.3,3.4,4.5,5.6, 1.2,2.3,3.4,4.5,5.6, 1.2,2.3,3.4,4.5,5.6, 1.2,2.3,3.4,4.5,5.6, 1.2,2.3,3.4,4.5,5.6};
1812 std::copy(arr1,arr1+25,array->getPointer());
1813 f1->setArray(array);
1815 f1->checkConsistencyLight();
1817 MEDCouplingFieldDouble *f2=f1->magnitude();
1818 f2->checkConsistencyLight();
1819 CPPUNIT_ASSERT_EQUAL(1,(int)f2->getNumberOfComponents());
1820 CPPUNIT_ASSERT_EQUAL(5,(int)f2->getNumberOfTuples());
1821 for(int i=0;i<5;i++)
1822 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.3606219864313918,f2->getIJ(i,0),1e-13);
1829 void MEDCouplingBasicsTest2::testMaxPerTuple1()
1831 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1832 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1834 DataArrayDouble *array=DataArrayDouble::New();
1835 array->alloc(mesh1->getNumberOfCells(),5);
1836 const double arr1[25]={1.2,2.3,3.4,4.5,5.6, 1.2,3.4,4.5,5.6,2.3, 3.4,4.5,5.6,1.2,2.3, 5.6,1.2,2.3,3.4,4.5, 4.5,5.6,1.2,2.3,3.4};
1837 std::copy(arr1,arr1+25,array->getPointer());
1838 f1->setArray(array);
1840 f1->checkConsistencyLight();
1842 MEDCouplingFieldDouble *f2=f1->maxPerTuple();
1843 f2->checkConsistencyLight();
1844 CPPUNIT_ASSERT_EQUAL(1,(int)f2->getNumberOfComponents());
1845 CPPUNIT_ASSERT_EQUAL(5,(int)f2->getNumberOfTuples());
1846 for(int i=0;i<5;i++)
1847 CPPUNIT_ASSERT_DOUBLES_EQUAL(5.6,f2->getIJ(i,0),1e-13);
1850 DataArrayIdType *d2I=0;
1851 DataArrayDouble *d2=array->maxPerTupleWithCompoId(d2I);
1852 CPPUNIT_ASSERT_EQUAL(1,(int)d2->getNumberOfComponents());
1853 CPPUNIT_ASSERT_EQUAL(5,(int)d2->getNumberOfTuples());
1854 const mcIdType expected2[5]={4,3,2,0,1};
1855 for(int i=0;i<5;i++)
1857 CPPUNIT_ASSERT_DOUBLES_EQUAL(5.6,d2->getIJ(i,0),1e-13);
1858 CPPUNIT_ASSERT_EQUAL(expected2[i],d2I->getIJ(i,0));
1860 d2->decrRef(); d2I->decrRef();
1866 void MEDCouplingBasicsTest2::testChangeNbOfComponents()
1868 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1869 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1871 DataArrayDouble *array=DataArrayDouble::New();
1872 array->alloc(mesh1->getNumberOfCells(),5);
1873 const double arr1[25]={1.2,2.3,3.4,4.5,5.6, 1.2,3.4,4.5,5.6,2.3, 3.4,4.5,5.6,1.2,2.3, 5.6,1.2,2.3,3.4,4.5, 4.5,5.6,1.2,2.3,3.4};
1874 std::copy(arr1,arr1+25,array->getPointer());
1875 f1->setArray(array);
1877 f1->checkConsistencyLight();
1879 f1->changeNbOfComponents(3,7.77);
1880 f1->checkConsistencyLight();
1881 CPPUNIT_ASSERT_EQUAL(3,(int)f1->getNumberOfComponents());
1882 CPPUNIT_ASSERT_EQUAL(5,(int)f1->getNumberOfTuples());
1883 const double expected1[15]={1.2,2.3,3.4, 1.2,3.4,4.5, 3.4,4.5,5.6, 5.6,1.2,2.3, 4.5,5.6,1.2};
1884 for(int i=0;i<15;i++)
1885 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-13);
1886 f1->changeNbOfComponents(4,7.77);
1887 f1->checkConsistencyLight();
1888 CPPUNIT_ASSERT_EQUAL(4,(int)f1->getNumberOfComponents());
1889 CPPUNIT_ASSERT_EQUAL(5,(int)f1->getNumberOfTuples());
1890 const double expected2[20]={1.2,2.3,3.4,7.77, 1.2,3.4,4.5,7.77, 3.4,4.5,5.6,7.77, 5.6,1.2,2.3,7.77, 4.5,5.6,1.2,7.77};
1891 for(int i=0;i<20;i++)
1892 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f1->getIJ(0,i),1e-13);
1898 void MEDCouplingBasicsTest2::testSortPerTuple1()
1900 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1901 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1903 DataArrayDouble *array=DataArrayDouble::New();
1904 array->alloc(mesh1->getNumberOfCells(),5);
1905 const double arr1[25]={1.2,2.3,3.4,4.5,5.6, 1.2,3.4,4.5,5.6,2.3, 3.4,4.5,5.6,1.2,2.3, 5.6,1.2,2.3,3.4,4.5, 4.5,5.6,1.2,2.3,3.4};
1906 std::copy(arr1,arr1+25,array->getPointer());
1907 f1->setArray(array);
1909 f1->checkConsistencyLight();
1911 f1->sortPerTuple(true);
1912 f1->checkConsistencyLight();
1913 CPPUNIT_ASSERT_EQUAL(5,(int)f1->getNumberOfComponents());
1914 CPPUNIT_ASSERT_EQUAL(5,(int)f1->getNumberOfTuples());
1915 for(int i=0;i<5;i++)
1917 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[0],f1->getIJ(i,0),1e-13);
1918 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[1],f1->getIJ(i,1),1e-13);
1919 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[2],f1->getIJ(i,2),1e-13);
1920 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[3],f1->getIJ(i,3),1e-13);
1921 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[4],f1->getIJ(i,4),1e-13);
1924 f1->sortPerTuple(false);
1925 f1->checkConsistencyLight();
1926 CPPUNIT_ASSERT_EQUAL(5,(int)f1->getNumberOfComponents());
1927 CPPUNIT_ASSERT_EQUAL(5,(int)f1->getNumberOfTuples());
1928 for(int i=0;i<5;i++)
1930 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[4],f1->getIJ(i,0),1e-13);
1931 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[3],f1->getIJ(i,1),1e-13);
1932 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[2],f1->getIJ(i,2),1e-13);
1933 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[1],f1->getIJ(i,3),1e-13);
1934 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[0],f1->getIJ(i,4),1e-13);
1941 void MEDCouplingBasicsTest2::testIsEqualWithoutConsideringStr1()
1943 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1944 MEDCouplingUMesh *mesh2=build2DTargetMesh_1();
1945 DataArrayIdType *da1,*da2;
1947 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
1948 CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1949 mesh2->setName("rr");
1950 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
1951 CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1952 mesh1->checkDeepEquivalWith(mesh2,2,1e-12,da1,da2);
1953 CPPUNIT_ASSERT_THROW(mesh1->checkGeoEquivalWith(mesh2,0,1e-12,da1,da2),INTERP_KERNEL::Exception);
1955 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
1956 CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1957 mesh2->getCoords()->setInfoOnComponent(0,"tty");
1958 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
1959 CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1960 mesh2->getCoords()->setInfoOnComponent(0,"");
1961 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
1962 CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1963 mesh2->getCoords()->setInfoOnComponent(1,"tty");
1964 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
1965 CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1966 mesh2->getCoords()->setInfoOnComponent(1,"");
1967 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
1968 CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1969 double tmp=mesh2->getCoords()->getIJ(0,3);
1970 mesh2->getCoords()->setIJ(0,3,9999.);
1971 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
1972 CPPUNIT_ASSERT(!mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1973 mesh2->getCoords()->setIJ(0,3,tmp);
1974 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
1975 CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1976 mcIdType tmp2=mesh2->getNodalConnectivity()->getIJ(0,4);
1977 mesh2->getNodalConnectivity()->setIJ(0,4,0);
1978 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
1979 CPPUNIT_ASSERT(!mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1980 mesh2->getNodalConnectivity()->setIJ(0,4,tmp2);
1981 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
1982 CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1984 MEDCouplingFieldDouble *f1=mesh1->getMeasureField(true);
1985 MEDCouplingFieldDouble *f2=mesh2->getMeasureField(true);
1986 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
1987 CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12));
1988 f2->setName("ftest");
1989 CPPUNIT_ASSERT(!f1->isEqual(f2,1e-12,1e-12));
1990 CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12));
1991 f1->setName("ftest");
1992 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
1993 CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12));
1995 f2->getArray()->setInfoOnComponent(0,"eee");
1996 CPPUNIT_ASSERT(!f1->isEqual(f2,1e-12,1e-12));
1997 CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12));
1998 f2->getArray()->setInfoOnComponent(0,"");
1999 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
2000 CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12));
2002 f2->getArray()->setIJ(1,0,0.123);
2003 CPPUNIT_ASSERT(!f1->isEqual(f2,1e-12,1e-12));
2004 CPPUNIT_ASSERT(!f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12));
2005 f2->getArray()->setIJ(1,0,0.125);
2006 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
2007 CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12));
2016 void MEDCouplingBasicsTest2::testGetNodeIdsOfCell1()
2018 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
2019 std::vector<mcIdType> nodeIds;
2020 mesh1->getNodeIdsOfCell(1,nodeIds);
2021 CPPUNIT_ASSERT_EQUAL(3,(int)nodeIds.size());
2022 CPPUNIT_ASSERT_EQUAL(1,(int)nodeIds[0]);
2023 CPPUNIT_ASSERT_EQUAL(4,(int)nodeIds[1]);
2024 CPPUNIT_ASSERT_EQUAL(2,(int)nodeIds[2]);
2025 std::vector<double> coords;
2026 mesh1->getCoordinatesOfNode(4,coords);
2027 CPPUNIT_ASSERT_EQUAL(2,(int)coords.size());
2028 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.2,coords[0],1e-13);
2029 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.2,coords[1],1e-13);
2033 void MEDCouplingBasicsTest2::testGetEdgeRatioField1()
2035 MEDCouplingUMesh *m1=build2DTargetMesh_1();
2036 m1->setTime(3.4,5,6); m1->setTimeUnit("us");
2038 MEDCouplingFieldDouble *f1=m1->getEdgeRatioField();
2039 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.4,f1->getTime(a,b),1.e-14);
2040 CPPUNIT_ASSERT_EQUAL(5,a); CPPUNIT_ASSERT_EQUAL(6,b);
2041 CPPUNIT_ASSERT_EQUAL(std::string(f1->getTimeUnit()),std::string("us"));
2042 CPPUNIT_ASSERT_EQUAL((int)m1->getNumberOfCells(),(int)f1->getNumberOfTuples());
2043 CPPUNIT_ASSERT_EQUAL(5,(int)f1->getNumberOfTuples());
2044 CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
2045 const double expected1[5]={1.,1.4142135623730951, 1.4142135623730951,1.,1.};
2046 for(int i=0;i<5;i++)
2047 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(i,0),1e-14);
2051 m1=build3DSurfTargetMesh_1();
2052 f1=m1->getEdgeRatioField();
2053 CPPUNIT_ASSERT_EQUAL((int)m1->getNumberOfCells(),(int)f1->getNumberOfTuples());
2054 CPPUNIT_ASSERT_EQUAL(5,(int)f1->getNumberOfTuples());
2055 CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
2056 const double expected2[5]={1.4142135623730951, 1.7320508075688772, 1.7320508075688772, 1.4142135623730951, 1.4142135623730951};
2057 for(int i=0;i<5;i++)
2058 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f1->getIJ(i,0),1e-14);
2063 void MEDCouplingBasicsTest2::testFillFromAnalytic3()
2065 MEDCouplingUMesh *m=build2DTargetMesh_1();
2066 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
2067 CPPUNIT_ASSERT_THROW(f1->fillFromAnalytic(1,"y+x"),INTERP_KERNEL::Exception);
2069 f1->setName("myField");
2070 f1->fillFromAnalytic(1,"y+x");
2071 f1->checkConsistencyLight();
2072 CPPUNIT_ASSERT(std::string(f1->getName())=="myField");
2073 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_CELLS);
2074 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
2075 CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
2076 CPPUNIT_ASSERT_EQUAL(5,(int)f1->getNumberOfTuples());
2077 double values1[5]={-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9};
2078 const double *tmp=f1->getArray()->getConstPointer();
2079 std::transform(tmp,tmp+5,values1,values1,std::minus<double>());
2080 std::transform(values1,values1+5,values1,std::ptr_fun<double,double>(fabs));
2081 double max=*std::max_element(values1,values1+5);
2082 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
2085 f1=MEDCouplingFieldDouble::New(ON_NODES,CONST_ON_TIME_INTERVAL);
2087 f1->setEndTime(1.2,3,4);
2088 f1->fillFromAnalytic(1,"y+2*x");
2089 f1->checkConsistencyLight();
2090 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
2091 CPPUNIT_ASSERT(f1->getTimeDiscretization()==CONST_ON_TIME_INTERVAL);
2092 CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
2093 CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
2094 double values2[9]={-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1};
2095 tmp=f1->getArray()->getConstPointer();
2096 std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
2097 std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
2098 max=*std::max_element(values2,values2+9);
2099 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
2101 f1=MEDCouplingFieldDouble::New(ON_NODES,LINEAR_TIME);
2103 f1->setEndTime(1.2,3,4);
2104 f1->fillFromAnalytic(1,"2.*x+y");
2105 f1->checkConsistencyLight();
2106 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
2107 CPPUNIT_ASSERT(f1->getTimeDiscretization()==LINEAR_TIME);
2108 CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
2109 CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
2110 tmp=f1->getArray()->getConstPointer();
2111 double values2Bis[9]={-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1};
2112 double values2BisBis[9];
2113 std::transform(tmp,tmp+9,values2Bis,values2BisBis,std::minus<double>());
2114 std::transform(values2,values2+9,values2BisBis,std::ptr_fun<double,double>(fabs));
2115 max=*std::max_element(values2BisBis,values2BisBis+9);
2116 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
2117 tmp=f1->getEndArray()->getConstPointer();
2118 std::transform(tmp,tmp+9,values2Bis,values2BisBis,std::minus<double>());
2119 std::transform(values2,values2+9,values2BisBis,std::ptr_fun<double,double>(fabs));
2120 max=*std::max_element(values2BisBis,values2BisBis+9);
2121 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
2124 f1=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
2126 f1->fillFromAnalytic(2,"(x+y)*IVec+2*(x+y)*JVec");
2127 f1->checkConsistencyLight();
2128 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
2129 CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
2130 CPPUNIT_ASSERT_EQUAL(2,(int)f1->getNumberOfComponents());
2131 CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
2132 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};
2133 tmp=f1->getArray()->getConstPointer();
2134 std::transform(tmp,tmp+18,values3,values3,std::minus<double>());
2135 std::transform(values3,values3+18,values3,std::ptr_fun<double,double>(fabs));
2136 max=*std::max_element(values3,values3+18);
2137 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
2139 f1->accumulate(values4);
2140 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.6,values4[0],1.e-12);
2141 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.2,values4[1],1.e-12);
2142 f1->integral(true,values4);
2143 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.4,values4[0],1.e-12);
2144 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.8,values4[1],1.e-12);
2147 f1=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
2149 CPPUNIT_ASSERT_THROW(f1->fillFromAnalytic(1,"1./(x-0.2)"),INTERP_KERNEL::Exception);
2155 void MEDCouplingBasicsTest2::testFieldDoubleOpEqual1()
2157 MEDCouplingUMesh *m=build2DTargetMesh_1();
2158 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
2159 CPPUNIT_ASSERT_THROW((*f1)=0.07,INTERP_KERNEL::Exception);
2162 f1->checkConsistencyLight();
2163 CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
2164 CPPUNIT_ASSERT_EQUAL(5,(int)f1->getNumberOfTuples());
2165 for(int i=0;i<5;i++)
2166 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.07,f1->getIJ(i,0),1e-16);
2168 f1->checkConsistencyLight();
2169 CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
2170 CPPUNIT_ASSERT_EQUAL(5,(int)f1->getNumberOfTuples());
2171 for(int i=0;i<5;i++)
2172 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.09,f1->getIJ(i,0),1e-16);
2175 f1=MEDCouplingFieldDouble::New(ON_NODES,LINEAR_TIME);
2176 f1->setEndTime(4.5,2,3);
2179 f1->checkConsistencyLight();
2180 CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
2181 CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
2182 for(int i=0;i<9;i++)
2183 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.08,f1->getIJ(i,0),1e-16);
2184 CPPUNIT_ASSERT_EQUAL(1,(int)f1->getEndArray()->getNumberOfComponents());
2185 CPPUNIT_ASSERT_EQUAL(9,(int)f1->getEndArray()->getNumberOfTuples());
2186 for(int i=0;i<9;i++)
2187 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.08,f1->getEndArray()->getIJ(i,0),1e-16);
2193 void MEDCouplingBasicsTest2::testAreaBary3D2()
2195 const double coordsForHexa8[24]={
2196 -75.45749305371, 180.95495078401, 39.515472018008,
2197 -9.755591679144, 23.394927935279, 5.108794294848,
2198 14.337630157832, 61.705351002702, 160.42422501908,
2199 -27.273893776752, 167.567731083961, 192.830034145464,
2201 99.857193154796,264.499264735586,-8.287335493412,
2202 144.939882761126,156.38626563134,-31.896173894226,
2203 161.34096835726,182.4654895809,73.832387065572,
2204 132.680430393685,255.37973247196,96.15235602819
2206 const double volHexa8=3258520.29637466;
2207 const double baryHexa8[3]={43.925705821778, 155.31893955289, 65.874418109644};
2209 const double coordsForPenta6[18]={
2210 -68.199829618726,178.938498373416,62.608505919588,
2211 8.461744647847,76.653979804423,165.00018874933,
2212 -27.273893776752,167.567731083961,192.830034145464,
2214 106.586501038965,262.629609408327,13.124533008813,
2215 155.465082847275,197.414118382622,78.408350795821,
2216 132.680430393685,255.37973247196,96.15235602819
2218 const double volPenta6=944849.868507338;
2219 const double baryPenta6[3]={39.631002313543,182.692711783428,106.98540473964};
2221 const double coordsForPyra5[15]={
2222 132.680430393685,255.37973247196,96.15235602819,
2223 -27.273893776752,167.567731083961,192.830034145464,
2224 8.461744647847,76.653979804423,165.00018874933,
2225 155.465082847275,197.414118382622,78.408350795821,
2227 -68.199829618726,178.938498373416,62.608505919588
2229 const double volPyra5=756943.92980254;
2230 const double baryPyra5[3]={29.204294116618,172.540129749156,118.01035951483};
2231 MEDCouplingUMesh *mesh=MEDCouplingUMesh::New("Bary3D2",3);
2232 DataArrayDouble *coo=DataArrayDouble::New();
2234 double *tmp=std::copy(coordsForHexa8,coordsForHexa8+24,coo->getPointer());
2235 tmp=std::copy(coordsForPenta6,coordsForPenta6+18,tmp);
2236 std::copy(coordsForPyra5,coordsForPyra5+15,tmp);
2237 mesh->setCoords(coo);
2240 mcIdType tmpConn[8]={0,1,2,3,4,5,6,7};
2241 mesh->allocateCells(3);
2242 mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,tmpConn);
2243 std::transform(tmpConn,tmpConn+8,tmpConn,std::bind2nd(std::plus<int>(),8));
2244 mesh->insertNextCell(INTERP_KERNEL::NORM_PENTA6,6,tmpConn);
2245 std::transform(tmpConn,tmpConn+8,tmpConn,std::bind2nd(std::plus<int>(),6));
2246 mesh->insertNextCell(INTERP_KERNEL::NORM_PYRA5,5,tmpConn);
2247 mesh->finishInsertingCells();
2248 mesh->checkConsistencyLight();
2250 mcIdType newNebOfNodes;
2251 DataArrayIdType *da=mesh->mergeNodes(1e-7,isMerged,newNebOfNodes);
2253 CPPUNIT_ASSERT_EQUAL(ToIdType(12),newNebOfNodes);
2254 MEDCouplingFieldDouble *vols=mesh->getMeasureField(true);
2255 CPPUNIT_ASSERT_EQUAL(3,(int)vols->getNumberOfTuples());
2256 CPPUNIT_ASSERT_EQUAL(1,(int)vols->getNumberOfComponents());
2257 CPPUNIT_ASSERT_DOUBLES_EQUAL(volHexa8,vols->getIJ(0,0),1e-6);
2258 CPPUNIT_ASSERT_DOUBLES_EQUAL(volPenta6,vols->getIJ(1,0),1e-7);
2259 CPPUNIT_ASSERT_DOUBLES_EQUAL(volPyra5,vols->getIJ(2,0),1e-7);
2261 DataArrayDouble *bary=mesh->computeCellCenterOfMass();
2262 CPPUNIT_ASSERT_EQUAL(3,(int)bary->getNumberOfTuples());
2263 CPPUNIT_ASSERT_EQUAL(3,(int)bary->getNumberOfComponents());
2264 CPPUNIT_ASSERT_DOUBLES_EQUAL(baryHexa8[0],bary->getIJ(0,0),1e-11);
2265 CPPUNIT_ASSERT_DOUBLES_EQUAL(baryHexa8[1],bary->getIJ(0,1),1e-11);
2266 CPPUNIT_ASSERT_DOUBLES_EQUAL(baryHexa8[2],bary->getIJ(0,2),1e-11);
2267 CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPenta6[0],bary->getIJ(1,0),1e-11);
2268 CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPenta6[1],bary->getIJ(1,1),1e-11);
2269 CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPenta6[2],bary->getIJ(1,2),1e-11);
2270 CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPyra5[0],bary->getIJ(2,0),1e-11);
2271 CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPyra5[1],bary->getIJ(2,1),1e-11);
2272 CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPyra5[2],bary->getIJ(2,2),1e-11);