1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "MEDCouplingBasicsTest2.hxx"
22 #include "MEDCouplingUMesh.hxx"
23 #include "MEDCouplingCMesh.hxx"
24 #include "MEDCouplingExtrudedMesh.hxx"
25 #include "MEDCouplingFieldDouble.hxx"
26 #include "MEDCouplingMemArray.hxx"
27 #include "MEDCouplingGaussLocalization.hxx"
34 using namespace ParaMEDMEM;
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(5,f->getNumberOfMeshPlacesExpected());
55 CPPUNIT_ASSERT_EQUAL(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(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(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");
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(0,f->getNbOfGaussLocalization());
79 CPPUNIT_ASSERT_THROW(f->checkCoherency(),INTERP_KERNEL::Exception);
80 int 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(0,f->getNbOfGaussLocalization());
84 f->setGaussLocalizationOnCells(ids2,ids2+2,_refCoo2,_gsCoo1,_wg1);
85 CPPUNIT_ASSERT_EQUAL(1,f->getNbOfGaussLocalization());
86 CPPUNIT_ASSERT_EQUAL(0,f->getGaussLocalizationIdOfOneCell(0));
87 CPPUNIT_ASSERT_THROW(f->getGaussLocalizationIdOfOneCell(1),INTERP_KERNEL::Exception);
89 f->setGaussLocalizationOnCells(ids3,ids3+2,_refCoo1,_gsCoo1,_wg1);
90 CPPUNIT_ASSERT_EQUAL(2,f->getNbOfGaussLocalization());
91 CPPUNIT_ASSERT_EQUAL(0,f->getGaussLocalizationIdOfOneCell(0));
92 CPPUNIT_ASSERT_EQUAL(1,f->getGaussLocalizationIdOfOneCell(1));
93 CPPUNIT_ASSERT_EQUAL(1,f->getGaussLocalizationIdOfOneCell(2));
94 CPPUNIT_ASSERT_THROW(f->checkCoherency(),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(3,f->getNbOfGaussLocalization());
101 std::vector<int> 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->checkCoherency(),INTERP_KERNEL::Exception);//<- it's always not ok because undelying array not with the good size.
106 DataArrayDouble *array2=f->getArray()->substr(0,10);
109 f->checkCoherency();//<- 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->checkCoherency();
126 void MEDCouplingBasicsTest2::testGaussPointNEField1()
128 MEDCouplingUMesh *m=build2DTargetMesh_1();
129 MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_GAUSS_NE,NO_TIME);
131 CPPUNIT_ASSERT_EQUAL(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);
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<int> 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 int *conn=m->getNodalConnectivity()->getPointer();
174 m->are2DCellsNotCorrectlyOriented(vec,false,res1);
175 CPPUNIT_ASSERT_EQUAL(1,(int)res1.size());
176 CPPUNIT_ASSERT_EQUAL(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<int> 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->checkCoherency();
202 CPPUNIT_ASSERT_EQUAL(18,m2->getNumberOfCells());
203 int cellIds[3]={0,6,12};
204 std::vector<int> 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 int ids1[5]={0,1,2,3,4};
216 std::vector<int> 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,f3->getArray()->getNumberOfTuples());
234 CPPUNIT_ASSERT_EQUAL(1,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->getBarycenterAndOwner();
245 CPPUNIT_ASSERT_EQUAL(15,f4->getNumberOfTuples());
246 CPPUNIT_ASSERT_EQUAL(3,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);
265 * This test check polyhedron true barycenter computation.
267 void MEDCouplingBasicsTest2::testPolyhedronBarycenter()
269 int 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};
270 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};
271 MEDCouplingUMesh *meshN=MEDCouplingUMesh::New();
272 meshN->setName("ForBary");
273 meshN->setMeshDimension(3);
274 meshN->allocateCells(4);
275 meshN->insertNextCell(INTERP_KERNEL::NORM_POLYHED,29,connN);
276 meshN->finishInsertingCells();
277 DataArrayDouble *myCoords=DataArrayDouble::New();
278 myCoords->alloc(9,3);
279 std::copy(coords,coords+27,myCoords->getPointer());
280 meshN->setCoords(myCoords);
282 meshN->checkCoherency();
284 std::vector<int> res1;
285 meshN->arePolyhedronsNotCorrectlyOriented(res1);
286 meshN->orientCorrectlyPolyhedrons();
287 CPPUNIT_ASSERT(res1.empty());
288 const double *ref,*daPtr;
289 DataArrayDouble *da=meshN->getBarycenterAndOwner();
290 CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfTuples());
291 CPPUNIT_ASSERT_EQUAL(3,da->getNumberOfComponents());
292 daPtr=da->getConstPointer();
293 ref=meshN->getCoords()->getConstPointer()+24;
295 CPPUNIT_ASSERT_DOUBLES_EQUAL(ref[i],daPtr[i],1e-12);
298 const double center[]={0.,0.,0.};
299 const double vec[]={0.,2.78,0.};
300 da=meshN->getBarycenterAndOwner();
301 daPtr=da->getConstPointer();
302 ref=meshN->getCoords()->getConstPointer()+24;
304 CPPUNIT_ASSERT_DOUBLES_EQUAL(ref[i],daPtr[i],1e-12);
307 meshN->rotate(center,vec,M_PI/7.);
308 meshN->translate(vec);
309 da=meshN->getBarycenterAndOwner();
310 daPtr=da->getConstPointer();
311 ref=meshN->getCoords()->getConstPointer()+24;
313 CPPUNIT_ASSERT_DOUBLES_EQUAL(ref[i],daPtr[i],1e-12);
316 const double center2[]={1.12,3.45,6.78};
317 const double vec2[]={4.5,9.3,2.8};
318 meshN->rotate(center2,vec2,M_E);
319 meshN->translate(vec2);
320 da=meshN->getBarycenterAndOwner();
321 daPtr=da->getConstPointer();
322 ref=meshN->getCoords()->getConstPointer()+24;
324 CPPUNIT_ASSERT_DOUBLES_EQUAL(ref[i],daPtr[i],1e-10);
330 void MEDCouplingBasicsTest2::testNormL12Integ1D()
332 MEDCouplingUMesh *m1=build1DTargetMesh_3();
333 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
335 DataArrayDouble *array=DataArrayDouble::New();
336 array->alloc(m1->getNumberOfCells(),3);
337 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};
338 std::copy(arr,arr+12,array->getPointer());
343 DataArrayDouble *f3=m1->getBarycenterAndOwner();
344 CPPUNIT_ASSERT_EQUAL(4,f3->getNumberOfTuples());
345 CPPUNIT_ASSERT_EQUAL(1,f3->getNumberOfComponents());
346 double expected9[4]={0.75,5.105,0.8,5.155};
347 ptr=f3->getConstPointer();
349 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected9[i],ptr[i],1e-12);
352 MEDCouplingFieldDouble *f2=m1->getMeasureField(false);
353 CPPUNIT_ASSERT_EQUAL(4,f2->getArray()->getNumberOfTuples());
354 CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
355 double expected1[4]={0.5,0.21,-0.6,-0.31};
356 ptr=f2->getArray()->getConstPointer();
358 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],ptr[i],1e-12);
360 double expected2[4]={0.5,0.21,0.6,0.31};
361 f2=m1->getMeasureField(true);
362 ptr=f2->getArray()->getConstPointer();
364 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],ptr[i],1e-12);
368 f1->integral(false,res);
369 double expected3[3]={0.9866,-0.3615,0.4217};
371 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],res[i],1e-12);
372 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[0],f1->integral(0,false),1e-12);
373 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[1],f1->integral(1,false),1e-12);
374 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[2],f1->integral(2,false),1e-12);
375 f1->integral(true,res);
376 double expected4[3]={-3.4152,8.7639,-14.6879};
378 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected4[i],res[i],1e-12);
381 double expected5[3]={6.979506172839505, 16.89018518518518, 27.02969135802469};
383 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[i],res[i],1e-12);
384 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[0],f1->normL1(0),1e-12);
385 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[1],f1->normL1(1),1e-12);
386 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[2],f1->normL1(2),1e-12);
389 double expected7[3]={7.090910979452395, 16.9275542960123, 27.053271464160858};
391 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected7[i],res[i],1e-9);
392 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected7[0],f1->normL2(0),1e-9);
393 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected7[1],f1->normL2(1),1e-9);
394 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected7[2],f1->normL2(2),1e-9);
396 MEDCouplingFieldDouble *f4=f1->buildMeasureField(false);
397 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.2,f4->accumulate(0),1e-12);
399 f4=f1->buildMeasureField(true);
400 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.62,f4->accumulate(0),1e-12);
405 // Testing with 2D Curve
406 m1=build2DCurveTargetMesh_3();
407 f2=m1->getMeasureField(false);
408 CPPUNIT_ASSERT_EQUAL(4,f2->getArray()->getNumberOfTuples());
409 CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
410 ptr=f2->getArray()->getConstPointer();
412 CPPUNIT_ASSERT_DOUBLES_EQUAL(sqrt(2.)*expected2[i],ptr[i],1e-12);
414 f2=m1->getMeasureField(true);
415 CPPUNIT_ASSERT_EQUAL(4,f2->getArray()->getNumberOfTuples());
416 CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
417 ptr=f2->getArray()->getConstPointer();
419 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i]*sqrt(2.),ptr[i],1e-12);
422 f3=m1->getBarycenterAndOwner();
423 CPPUNIT_ASSERT_EQUAL(4,f3->getNumberOfTuples());
424 CPPUNIT_ASSERT_EQUAL(2,f3->getNumberOfComponents());
425 double expected10[8]={0.75,0.75,5.105,5.105,0.8,0.8,5.155,5.155};
426 ptr=f3->getConstPointer();
428 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected10[i],ptr[i],1e-12);
431 f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
433 array=DataArrayDouble::New();
434 array->alloc(m1->getNumberOfCells(),3);
435 std::copy(arr,arr+12,array->getPointer());
438 f1->integral(false,res);
440 CPPUNIT_ASSERT_DOUBLES_EQUAL(sqrt(2.)*expected4[i],res[i],1e-12);
441 f1->integral(true,res);
443 CPPUNIT_ASSERT_DOUBLES_EQUAL(sqrt(2.)*expected4[i],res[i],1e-12);
446 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[i],res[i],1e-12);
449 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected7[i],res[i],1e-12);
455 void MEDCouplingBasicsTest2::testAreaBary2D()
457 MEDCouplingUMesh *m1=build2DTargetMesh_3();
458 MEDCouplingFieldDouble *f1=m1->getMeasureField(false);
459 CPPUNIT_ASSERT_EQUAL(10,f1->getArray()->getNumberOfTuples());
460 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
461 double expected1[10]={-0.5,-1,-1.5,-0.5,-1, 0.5,1,1.5,0.5,1};
462 const double *ptr=f1->getArray()->getConstPointer();
463 for(int i=0;i<10;i++)
464 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],ptr[i],1e-12);
466 f1=m1->getMeasureField(true);
467 ptr=f1->getArray()->getConstPointer();
468 for(int i=0;i<10;i++)
469 CPPUNIT_ASSERT_DOUBLES_EQUAL(std::abs(expected1[i]),ptr[i],1e-12);
471 DataArrayDouble *f2=m1->getBarycenterAndOwner();
472 CPPUNIT_ASSERT_EQUAL(10,f2->getNumberOfTuples());
473 CPPUNIT_ASSERT_EQUAL(2,f2->getNumberOfComponents());
474 double expected2[20]={
475 0.5,0.3333333333333333,0.5,0.5,0.5,0.77777777777777777,0.5,0.3333333333333333,0.5,0.5,
476 0.5,0.3333333333333333,0.5,0.5,0.5,0.77777777777777777,0.5,0.3333333333333333,0.5,0.5,
478 ptr=f2->getConstPointer();
479 for(int i=0;i<20;i++)
480 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],ptr[i],1e-12);
482 m1->changeSpaceDimension(3);
483 f1=m1->getMeasureField(false);
484 CPPUNIT_ASSERT_EQUAL(10,f1->getArray()->getNumberOfTuples());
485 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
486 ptr=f1->getArray()->getConstPointer();
487 for(int i=0;i<10;i++)
488 CPPUNIT_ASSERT_DOUBLES_EQUAL(std::abs(expected1[i]),ptr[i],1e-12);
490 f2=m1->getBarycenterAndOwner();
491 CPPUNIT_ASSERT_EQUAL(10,f2->getNumberOfTuples());
492 CPPUNIT_ASSERT_EQUAL(3,f2->getNumberOfComponents());
493 ptr=f2->getConstPointer();
494 double expected3[30]={
495 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.,
496 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.
498 for(int i=0;i<30;i++)
499 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],ptr[i],1e-12);
505 * This test check polyhedron true barycenter computation 2.
507 void MEDCouplingBasicsTest2::testAreaBary3D()
509 double coords [] = { 0.241310763507 , 0.0504777305619 , 0.0682283524903 , 0.252501053866 , -0.0625176732937 , 0.137272639894 ,
510 0.152262663601 , 0.241816569527 , 0.133812556197 , 0.18047750211 , -0.0789949051358 , 0.339098173401 ,
511 0.151741971857 , 0.238885278571 , 0.137715037333 , 0.242532155481 , -0.0928169086456 , 0.0678043417367 ,
512 0.240941965335 , -0.015461491464 , 0.0617186345825 , 0.24127650112 , 0.0499427876717 , 0.0679634099148 ,
513 -0.145828917428 , 0.206291632565 , 0.0310071927543 , 0.0125651775307 , 0.266262085828 , 0.105228430543 ,
514 -0.0994066533286 , 0.233224271238 , 0.0572213839567 , -0.0951345338317 , 0.234819509426 , 0.0592126284538 ,
515 0.136580574205 , -0.205486212579 , 0.0572866072014 , 0.0637270784978 , -0.168886355238 , 0.446614057077 ,
516 0.041337157151 , -0.213402568198 , 0.372407095999 , 0.0411601970268 , -0.202387875756 , 0.411334979491 ,
517 -0.108355701857 , 0.193636239335 , 0.204886756738 , 0.00639779029829 , 0.155296981517 , 0.252585892979 ,
518 0.0262473111702 , -0.112919732543 , 0.424286639249 ,-0.224103052733 , -0.139430015438 , -0.0122352295701 ,
519 -0.0312760589481 , -0.274272003594 , 0.0323959636568 , -0.166663422532 , -0.217754445175 , 0.00392109070364 ,
520 -0.30586619777 , -0.0475168041091 , -0.0144585228182 , -0.280881480586 , 0.135571293538 , 0.00623923647986 ,
521 -0.25548538234 , 0.156819217766 , 0.0645277879769 , -0.131567009284 , 0.184133752309 , 0.206021802753 ,
522 -0.196204010965 , 0.151602971681 , 0.212974777736 , -0.183713879463 , 0.0802946639531 , 0.260115662599 ,
523 -0.244241178767 , -0.0738873389604 , 0.144590565817 , -0.155804057829 , -0.164892720025 , 0.210613950558 ,
524 -0.170950800428 , -0.215099334026 , 0.00610122860092 , -0.30552634869 , -0.0490020791904 , -0.0132786533145 ,
525 0.271831011884 , 0.15105657296 , 0.0230534827908 , 0.281919192283 , 0.0898544306288 , -0.0625201489143 ,
526 0.260240727276 , -0.0120688706637 , -0.0532316588626 , 0.244947737722 , 0.0197984684293 , 0.0309341209233 ,
527 0.23439631578 , 0.229825279875 , 0.0508520585381 , 0.160921316875 , 0.265078502128 , 0.121716560626 ,
528 -0.315088694175 , 0.0747700471918 , -0.245836615071 , -0.327728781776 , 0.0857114674649 , -0.239431905957 ,
529 -0.308385460634 , 0.145142997084 , -0.149886828433 , 0.0488236045164 , 0.309462801914 , 0.0849169148265 ,
530 -0.0244964803395 , 0.33145611751 , -0.0476415818061 , 0.0060567994229 , 0.32418412014 , 0.0367779543812 ,
531 -0.0950221448063 , 0.236675326003 , 0.0572594453983 , 0.248723023186 , 0.0886648784791 , -0.176629430538 ,
532 0.116796984 , 0.256596599567 , -0.292863523603 , 0.118024552914 , 0.229154257843 , -0.34233232501 ,
533 0.217507892549 , -0.0417822335742 , -0.176771782888 , -0.224429321304 , 0.0125595300114 , -0.362064725588 ,
534 0.0937301100955 , -0.0500824832657 , -0.299713548444 , -0.244162220397 , 0.0383853931293 , -0.389856984411 ,
535 -0.0281989366102 , 0.097392811563 , -0.458244577284 , -0.385010847162 , 0.10122766194 , -0.140052859922 ,
536 -0.377936358012 , 0.110875172128 , -0.176207095463 , 0.244483045556 , -0.0991073977045 , 0.0575134372934 ,
537 0.262605120167 , -0.100243191645 , -0.0495620806935 , 0.240306880972 , -0.136153701579 , -0.114745281696 ,
538 0.215763176129 , -0.0836766059189 , -0.183249640616 , 0.237870396603 , -0.132449578286 , -0.121598854639 ,
539 -0.0637683083097 , -0.27921020214 , -0.149112321992 , -0.0856211014977 , -0.2973233473 , -0.0446878139589 ,
540 0.104675342288 , -0.0625908305324 , -0.290346256534 , 0.0248264249186 , -0.247797708548 , -0.165830884019 ,
541 0.0719302438309 , -0.178468260473 , -0.211432157345 , 0.142871843159 , -0.208769948542 , 0.0454101128246 ,
542 0.167803379307 , -0.207851396623 , -0.088802726124 , 0.12868717152 , -0.230920439715 , 0.00760508389036 ,
543 -0.0372812069535 , -0.286740286332 , 0.00963701291166 };
545 int connN [] = { /*polyhedron 0*/
546 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
547 , 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
548 , 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
549 , 22 , 19 , 21 , 30 , 31 , -1 , 22 , 31 , 28 , 27 , 26 , 24 , 23 , -1 , 31 , 30 , 29 , 28,
551 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
552 , 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
553 , 33 , 34 , 48 , 45 , -1 , 35 , 34 , 48 , 50 , 49 , 38 , -1 , 41 , 43 , 42 , 46 , 36 , 37 , -1 , 38 , 39 , 51 , 49 , -1
554 , 39 , 40 , 42 , 46 , 47 , 52 , 51 , -1 , 45 , 47 , 52 , 50 , 48 , -1 , 52 , 51 , 49 , 50,
556 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
557 , 23 , 53 , 54 , 40 , 8 , -1 , 53 , 22 , 23 , -1 , 39 , 54 , 40,
559 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
560 , 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
561 , 55 , 5 , 12 , 65 , -1 , 66 , 67 , 65 , 55 , 56 , 57 , -1 , 63 , 66 , 57 , 59 , 64 , -1 , 64 , 62 , 58 , 59 , -1
562 , 60 , 63 , 66 , 67 , 68 , 61 , -1 , 61 , 68 , 20 , 21 , -1 , 67 , 68 , 20 , 12 , 65};
564 double barys[]={ -0.0165220465527 , -0.0190922868195 , 0.158882733414 ,
565 0.0287618656076 , 0.135874379934 , -0.14601588119 ,
566 -0.147128055553 , 0.0465995097041 , -0.049391174453 ,
567 -0.00142506732317 , -0.0996953090351 , -0.115159183132 };
568 MEDCouplingUMesh *meshN=MEDCouplingUMesh::New();
569 meshN->setName("ForBary");
570 meshN->setMeshDimension(3);
571 meshN->allocateCells(4);
572 meshN->insertNextCell(INTERP_KERNEL::NORM_POLYHED,113,connN);
573 meshN->insertNextCell(INTERP_KERNEL::NORM_POLYHED,99,connN+113);
574 meshN->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,connN+212);
575 meshN->insertNextCell(INTERP_KERNEL::NORM_POLYHED,92,connN+255);
576 meshN->finishInsertingCells();
577 DataArrayDouble *myCoords=DataArrayDouble::New();
578 myCoords->alloc(69,3);
579 std::copy(coords,coords+207,myCoords->getPointer());
580 meshN->setCoords(myCoords);
582 meshN->checkCoherency();
583 std::vector<int> res1;
584 meshN->arePolyhedronsNotCorrectlyOriented(res1);
585 meshN->orientCorrectlyPolyhedrons();
587 meshN->arePolyhedronsNotCorrectlyOriented(res1);
588 CPPUNIT_ASSERT(res1.empty());
590 DataArrayDouble *da=meshN->getBarycenterAndOwner();
591 CPPUNIT_ASSERT_EQUAL(4,da->getNumberOfTuples());
592 CPPUNIT_ASSERT_EQUAL(3,da->getNumberOfComponents());
593 const double *daPtr=da->getConstPointer();
594 for(int i=0;i<12;i++)
595 CPPUNIT_ASSERT_DOUBLES_EQUAL(barys[i],daPtr[i],1e-12);
601 void MEDCouplingBasicsTest2::testRenumberCellsForFields()
603 MEDCouplingUMesh *m=build2DTargetMesh_1();
604 MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
606 DataArrayDouble *arr=DataArrayDouble::New();
607 int nbOfCells=m->getNumberOfCells();
608 arr->alloc(nbOfCells,3);
611 const double values1[15]={7.,107.,10007.,8.,108.,10008.,9.,109.,10009.,10.,110.,10010.,11.,111.,10011.};
612 std::copy(values1,values1+15,arr->getPointer());
613 const int renumber1[5]={3,1,0,4,2};
615 const double loc[]={-0.05,-0.05, 0.55,-0.25, 0.55,0.15, -0.05,0.45, 0.45,0.45};
618 f->getValueOn(loc+2*j,res);
620 CPPUNIT_ASSERT_DOUBLES_EQUAL(values1[i+3*j],res[i],1e-12);
622 f->renumberCells(renumber1,false);
623 const double *ptr=f->getArray()->getConstPointer();
624 const double expected1[15]={9.,109.,10009.,8.,108.,10008.,11.,111.,10011.,7.,107.,10007.,10.,110.,10010.};
625 for(int i=0;i<15;i++)
626 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],ptr[i],1e-12);
627 //check that fields remains the same geometrically
630 f->getValueOn(loc+2*j,res);
632 CPPUNIT_ASSERT_DOUBLES_EQUAL(values1[i+3*j],res[i],1e-12);
636 f=MEDCouplingFieldDouble::New(ON_GAUSS_PT,NO_TIME);
638 const double _a=0.446948490915965;
639 const double _b=0.091576213509771;
640 const double _p1=0.11169079483905;
641 const double _p2=0.0549758718227661;
642 const double refCoo1[6]={ 0.,0., 1.,0., 0.,1. };
643 const double gsCoo1[12]={ 2*_b-1, 1-4*_b, 2*_b-1, 2.07*_b-1, 1-4*_b,
644 2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 };
645 const double wg1[6]={ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 };
646 std::vector<double> _refCoo1(refCoo1,refCoo1+6);
647 std::vector<double> _gsCoo1(gsCoo1,gsCoo1+12);
648 std::vector<double> _wg1(wg1,wg1+6);
649 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI3,_refCoo1,_gsCoo1,_wg1);
650 const double refCoo2[8]={ 0.,0., 1.,0., 1.,1., 0.,1. };
651 std::vector<double> _refCoo2(refCoo2,refCoo2+8);
652 _gsCoo1.resize(4); _wg1.resize(2);
653 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_QUAD4,_refCoo2,_gsCoo1,_wg1);
654 arr=DataArrayDouble::New();
656 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.};
657 std::copy(values2,values2+36,arr->getPointer());
661 MEDCouplingFieldDouble *fCpy=f->clone(true);
662 CPPUNIT_ASSERT(f->isEqual(fCpy,1e-12,1e-12));
663 f->renumberCells(renumber1,false);
664 CPPUNIT_ASSERT(!f->isEqual(fCpy,1e-12,1e-12));
665 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.};
666 ptr=f->getArray()->getConstPointer();
667 for(int i=0;i<36;i++)
668 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],ptr[i],1e-12);
669 const int renumber2[5]={2,1,4,0,3};//reverse renumber1
670 f->renumberCells(renumber2,false);
671 CPPUNIT_ASSERT(f->isEqual(fCpy,1e-12,1e-12));
675 f=MEDCouplingFieldDouble::New(ON_GAUSS_NE,NO_TIME);
677 arr=DataArrayDouble::New();
679 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.};
680 std::copy(values3,values3+36,arr->getPointer());
685 CPPUNIT_ASSERT(f->isEqual(fCpy,1e-12,1e-12));
686 f->renumberCells(renumber1,false);
687 CPPUNIT_ASSERT(!f->isEqual(fCpy,1e-12,1e-12));
688 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.};
689 ptr=f->getArray()->getConstPointer();
690 for(int i=0;i<36;i++)
691 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],ptr[i],1e-12);
692 f->renumberCells(renumber2,false);//perform reverse operation of renumbering to check that the resulting field is equal.
693 CPPUNIT_ASSERT(f->isEqual(fCpy,1e-12,1e-12));
700 void MEDCouplingBasicsTest2::testRenumberNodesForFields()
702 MEDCouplingUMesh *m=build2DTargetMesh_1();
703 MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
705 CPPUNIT_ASSERT_EQUAL(9,f->getNumberOfMeshPlacesExpected());
706 DataArrayDouble *arr=DataArrayDouble::New();
707 int nbOfNodes=m->getNumberOfNodes();
708 arr->alloc(nbOfNodes,3);
711 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.};
712 std::copy(values1,values1+27,arr->getPointer());
714 const int renumber1[9]={0,4,1,3,5,2,6,7,8};
716 const double loc[]={0.5432,-0.2432, 0.5478,0.1528};
717 const double expected1[6]={9.0272, 109.0272, 10009.0272, 11.4124,111.4124,10011.4124};
720 f->getValueOn(loc+2*j,res);
722 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i+3*j],res[i],1e-12);
724 MEDCouplingFieldDouble *fCpy=f->clone(true);
725 CPPUNIT_ASSERT(f->isEqual(fCpy,1e-12,1e-12));
726 f->renumberNodes(renumber1);
727 CPPUNIT_ASSERT(!f->isEqual(fCpy,1e-12,1e-12));
730 f->getValueOn(loc+2*j,res);
732 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i+3*j],res[i],1e-12);
734 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.};
735 for(int i=0;i<27;i++)
736 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getArray()->getConstPointer()[i],1e-12);
737 const int renumber2[9]={0,2,5,3,1,4,6,7,8};//reverse of renumber2
738 f->renumberNodes(renumber2);
739 CPPUNIT_ASSERT(f->isEqual(fCpy,1e-12,1e-12));
746 void MEDCouplingBasicsTest2::testConvertQuadraticCellsToLinear()
748 MEDCouplingUMesh *mesh=build2DTargetMesh_3();
749 mesh->checkCoherency();
750 std::set<INTERP_KERNEL::NormalizedCellType> types=mesh->getAllGeoTypes();
751 CPPUNIT_ASSERT_EQUAL(5,(int)types.size());
752 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};
753 std::set<INTERP_KERNEL::NormalizedCellType> expected1Bis(expected1,expected1+5);
754 CPPUNIT_ASSERT(expected1Bis==types);
755 CPPUNIT_ASSERT(mesh->isPresenceOfQuadratic());
756 CPPUNIT_ASSERT_EQUAL(62,mesh->getMeshLength());
757 MEDCouplingFieldDouble *f1=mesh->getMeasureField(false);
759 mesh->convertQuadraticCellsToLinear();
760 CPPUNIT_ASSERT(!mesh->isPresenceOfQuadratic());
762 mesh->checkCoherency();
763 MEDCouplingFieldDouble *f2=mesh->getMeasureField(false);
764 CPPUNIT_ASSERT(f1->getArray()->isEqual(*f2->getArray(),1e-12));
765 CPPUNIT_ASSERT_EQUAL(48,mesh->getMeshLength());
766 std::set<INTERP_KERNEL::NormalizedCellType> types2=mesh->getAllGeoTypes();
767 CPPUNIT_ASSERT_EQUAL(3,(int)types2.size());
768 INTERP_KERNEL::NormalizedCellType expected2[3]={INTERP_KERNEL::NORM_POLYGON, INTERP_KERNEL::NORM_TRI3, INTERP_KERNEL::NORM_QUAD4};
769 std::set<INTERP_KERNEL::NormalizedCellType> expected2Bis(expected2,expected2+3);
770 CPPUNIT_ASSERT(expected2Bis==types2);
777 void MEDCouplingBasicsTest2::testCheckGeoEquivalWith()
779 MEDCouplingUMesh *mesh1=build2DTargetMesh_3();
780 MEDCouplingUMesh *mesh2=build2DTargetMesh_3();
781 DataArrayInt *cellCor,*nodeCor;
783 mesh1->checkGeoEquivalWith(mesh1,0,1e-12,cellCor,nodeCor);//deepEqual
784 CPPUNIT_ASSERT(cellCor==0);
785 CPPUNIT_ASSERT(nodeCor==0);
786 mesh1->checkGeoEquivalWith(mesh1,1,1e-12,cellCor,nodeCor);//fastEqual
787 CPPUNIT_ASSERT(cellCor==0);
788 CPPUNIT_ASSERT(nodeCor==0);
789 mesh1->checkGeoEquivalWith(mesh1,10,1e-12,cellCor,nodeCor);//deepEqual with geo permutations
790 CPPUNIT_ASSERT(cellCor==0);
791 CPPUNIT_ASSERT(nodeCor==0);
792 //Second test mesh1 and mesh2 are 2 different meshes instance
793 mesh1->checkGeoEquivalWith(mesh2,0,1e-12,cellCor,nodeCor);//deepEqual
794 CPPUNIT_ASSERT(cellCor==0);
795 CPPUNIT_ASSERT(nodeCor==0);
796 mesh1->checkGeoEquivalWith(mesh2,1,1e-12,cellCor,nodeCor);//fastEqual
797 CPPUNIT_ASSERT(cellCor==0);
798 CPPUNIT_ASSERT(nodeCor==0);
799 mesh1->checkGeoEquivalWith(mesh2,10,1e-12,cellCor,nodeCor);//deepEqual with geo permutations
800 CPPUNIT_ASSERT(cellCor==0);
801 CPPUNIT_ASSERT(nodeCor==0);
802 //Third test : cell permutation by keeping the first the middle and the last as it is.
803 const int renum[]={0,2,1,3,4,5,6,8,7,9};
804 mesh2->renumberCells(renum,false);
805 CPPUNIT_ASSERT_THROW(mesh1->checkGeoEquivalWith(mesh2,0,1e-12,cellCor,nodeCor),INTERP_KERNEL::Exception);//deepEqual fails
806 CPPUNIT_ASSERT(cellCor==0);
807 CPPUNIT_ASSERT(nodeCor==0);
808 mesh1->checkGeoEquivalWith(mesh2,1,1e-12,cellCor,nodeCor);//fastEqual do not see anything
809 CPPUNIT_ASSERT(cellCor==0);
810 CPPUNIT_ASSERT(nodeCor==0);
811 mesh1->checkGeoEquivalWith(mesh2,10,1e-12,cellCor,nodeCor);//deepEqual with geo permutations
812 CPPUNIT_ASSERT(cellCor);
813 CPPUNIT_ASSERT_EQUAL(10,cellCor->getNumberOfTuples());
814 CPPUNIT_ASSERT_EQUAL(1,cellCor->getNumberOfComponents());
815 CPPUNIT_ASSERT(std::equal(renum,renum+10,cellCor->getConstPointer()));
816 CPPUNIT_ASSERT(nodeCor==0);
819 CPPUNIT_ASSERT(nodeCor==0);
820 //4th test : cell and node permutation by keeping the first the middle and the last as it is.
822 mesh2=build2DTargetMesh_3();
823 const int renum2[]={0,2,1,3,4,5,6,8,7,9,10};
824 mesh2->renumberCells(renum,false);
825 mesh2->renumberNodes(renum2,11);
826 CPPUNIT_ASSERT_THROW(mesh1->checkGeoEquivalWith(mesh2,0,1e-12,cellCor,nodeCor),INTERP_KERNEL::Exception);//deepEqual fails
827 CPPUNIT_ASSERT(cellCor==0);
828 CPPUNIT_ASSERT(nodeCor==0);
829 mesh1->checkGeoEquivalWith(mesh2,1,1e-12,cellCor,nodeCor);//fastEqual do not see anything
830 CPPUNIT_ASSERT(cellCor==0);
831 CPPUNIT_ASSERT(nodeCor==0);
832 mesh1->checkGeoEquivalWith(mesh2,10,1e-12,cellCor,nodeCor);//deepEqual with geo permutations
833 CPPUNIT_ASSERT(cellCor);
834 CPPUNIT_ASSERT_EQUAL(10,cellCor->getNumberOfTuples());
835 CPPUNIT_ASSERT_EQUAL(1,cellCor->getNumberOfComponents());
836 CPPUNIT_ASSERT(std::equal(renum,renum+10,cellCor->getConstPointer()));
837 CPPUNIT_ASSERT(nodeCor);
838 CPPUNIT_ASSERT_EQUAL(11,nodeCor->getNumberOfTuples());
839 CPPUNIT_ASSERT_EQUAL(1,nodeCor->getNumberOfComponents());
840 CPPUNIT_ASSERT(std::equal(renum2,renum2+11,nodeCor->getConstPointer()));
845 //5th test : modification of the last cell to check fastCheck detection.
847 mesh2=build2DTargetMesh_3();
848 const int renum3[]={0,2,1,3,4,5,6,8,9,7};
849 mesh2->renumberCells(renum3,false);
850 mesh2->renumberNodes(renum2,11);
852 try { mesh1->checkGeoEquivalWith(mesh2,0,1e-12,cellCor,nodeCor);//deepEqual fails
854 catch(INTERP_KERNEL::Exception& e) { isExcep=true; }
855 CPPUNIT_ASSERT(isExcep); isExcep=false;
856 CPPUNIT_ASSERT(cellCor==0);
857 CPPUNIT_ASSERT(nodeCor==0);
858 try { mesh1->checkGeoEquivalWith(mesh2,1,1e-12,cellCor,nodeCor);//fastEqual has detected something
860 catch(INTERP_KERNEL::Exception& e) { isExcep=true; }
861 CPPUNIT_ASSERT(isExcep); isExcep=false;
862 CPPUNIT_ASSERT(cellCor==0);
863 CPPUNIT_ASSERT(nodeCor==0);
864 mesh2->checkGeoEquivalWith(mesh1,10,1e-12,cellCor,nodeCor);//deepEqual with geo permutations
865 CPPUNIT_ASSERT(cellCor);
866 CPPUNIT_ASSERT_EQUAL(10,cellCor->getNumberOfTuples());
867 CPPUNIT_ASSERT_EQUAL(1,cellCor->getNumberOfComponents());
868 CPPUNIT_ASSERT(std::equal(renum3,renum3+10,cellCor->getConstPointer()));
869 CPPUNIT_ASSERT(nodeCor);
870 CPPUNIT_ASSERT_EQUAL(11,nodeCor->getNumberOfTuples());
871 CPPUNIT_ASSERT_EQUAL(1,nodeCor->getNumberOfComponents());
872 CPPUNIT_ASSERT(std::equal(renum2,renum2+11,nodeCor->getConstPointer()));
882 void MEDCouplingBasicsTest2::testCheckGeoEquivalWith2()
884 MEDCouplingUMesh *mesh1=build2DTargetMesh_4();
885 MEDCouplingUMesh *mesh2=build2DTargetMesh_1();
886 DataArrayInt *cellCor,*nodeCor;
887 mesh1->checkGeoEquivalWith(mesh2,10,1e-12,cellCor,nodeCor);
888 CPPUNIT_ASSERT(cellCor==0);
889 CPPUNIT_ASSERT(nodeCor!=0);
890 const int expected1[9]={0, 1, 3, 4, 5, 6, 7, 8, 9};
892 CPPUNIT_ASSERT_EQUAL(expected1[i],nodeCor->getIJ(i,0));
899 void MEDCouplingBasicsTest2::testCopyTinyStringsFromOnFields()
901 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
902 int nbOfCells=m->getNumberOfCells();
903 MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
905 CPPUNIT_ASSERT_EQUAL(5,f->getNumberOfMeshPlacesExpected());
907 f->setDescription("b");
908 DataArrayDouble *a1=DataArrayDouble::New();
909 a1->alloc(nbOfCells,2);
911 a1->setInfoOnComponent(0,"c");
912 a1->setInfoOnComponent(1,"d");
913 DataArrayDouble *a2=a1->deepCpy();
914 a2->setInfoOnComponent(0,"e");
915 a2->setInfoOnComponent(1,"f");
918 f->setEndTime(3.,3,4);
922 m->getCoords()->setInfoOnComponent(0,"h");
923 m->getCoords()->setInfoOnComponent(1,"i");
924 m->getCoords()->setInfoOnComponent(2,"j");
927 MEDCouplingFieldDouble *f2=f->clone(true);
928 CPPUNIT_ASSERT(f2->isEqual(f,1e-12,1e-12));
930 CPPUNIT_ASSERT(!f2->isEqual(f,1e-12,1e-12));
931 f2->copyTinyStringsFrom(f);
932 CPPUNIT_ASSERT(f2->isEqual(f,1e-12,1e-12));
933 f2->setDescription("GGG");
934 CPPUNIT_ASSERT(!f2->isEqual(f,1e-12,1e-12));
935 f2->copyTinyStringsFrom(f);
936 CPPUNIT_ASSERT(f2->isEqual(f,1e-12,1e-12));
937 f2->getArray()->setInfoOnComponent(0,"mmmm");
938 CPPUNIT_ASSERT(!f2->isEqual(f,1e-12,1e-12));
939 f2->copyTinyStringsFrom(f);
940 CPPUNIT_ASSERT(f2->isEqual(f,1e-12,1e-12));
941 f2->getEndArray()->setInfoOnComponent(1,"mmmm");
942 CPPUNIT_ASSERT(!f2->isEqual(f,1e-12,1e-12));
943 f2->copyTinyStringsFrom(f);
944 CPPUNIT_ASSERT(f2->isEqual(f,1e-12,1e-12));
946 MEDCouplingUMesh *m2=m->clone(true);
947 CPPUNIT_ASSERT(m2->isEqual(m,1e-12));
949 CPPUNIT_ASSERT(!m2->isEqual(m,1e-12));
950 m2->copyTinyStringsFrom(m);
951 CPPUNIT_ASSERT(m2->isEqual(m,1e-12));
952 m2->getCoords()->setInfoOnComponent(1,"eee");
953 CPPUNIT_ASSERT(!m2->isEqual(m,1e-12));
954 m2->copyTinyStringsFrom(m);
955 CPPUNIT_ASSERT(m2->isEqual(m,1e-12));
962 void MEDCouplingBasicsTest2::testTryToShareSameCoordsPermute()
964 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
965 MEDCouplingUMesh *m2=build3DSurfTargetMesh_1();
966 CPPUNIT_ASSERT(m->getCoords()!=m2->getCoords());
967 m->tryToShareSameCoordsPermute(*m2,1e-12);
968 CPPUNIT_ASSERT(m->getCoords()==m2->getCoords());
969 CPPUNIT_ASSERT(m2->isEqual(m,1e-12));
970 const int renum1[9]={1,2,0,5,8,7,4,3,6};
971 m->renumberNodes(renum1,9);
972 CPPUNIT_ASSERT(m->getCoords()!=m2->getCoords());
973 CPPUNIT_ASSERT(!m2->isEqual(m,1e-12));
974 m->tryToShareSameCoordsPermute(*m2,1e-12);
975 CPPUNIT_ASSERT(m->getCoords()==m2->getCoords());
976 CPPUNIT_ASSERT(m2->isEqual(m,1e-12));
981 void MEDCouplingBasicsTest2::testTryToShareSameCoordsPermute2()
983 MEDCouplingUMesh *m1=build2DTargetMesh_4();
984 double targetCoords[8]={-0.3,-0.3, 0.2,-0.3, -0.3,0.2, 0.2,0.2 };
985 int targetConn[4]={0,2,3,1};
986 MEDCouplingUMesh *m2=MEDCouplingUMesh::New();
987 m2->setMeshDimension(2);
988 m2->allocateCells(1);
989 m2->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn);
990 m2->finishInsertingCells();
991 DataArrayDouble *myCoords=DataArrayDouble::New();
992 myCoords->alloc(4,2);
993 std::copy(targetCoords,targetCoords+8,myCoords->getPointer());
994 m2->setCoords(myCoords);
996 m2->checkCoherency();
997 m1->checkCoherency();
999 const double expected1[5]={0.25,0.125,0.125,0.25,0.25};
1000 MEDCouplingFieldDouble *f1=m1->getMeasureField(false);
1001 MEDCouplingFieldDouble *f2=m2->getMeasureField(false);
1002 CPPUNIT_ASSERT_EQUAL(5,f1->getArray()->getNumberOfTuples());
1003 CPPUNIT_ASSERT_EQUAL(1,f2->getArray()->getNumberOfTuples());
1004 for(int i=0;i<5;i++)
1005 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(i,0),1e-12);
1006 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(0,0),1e-12);
1009 CPPUNIT_ASSERT_THROW(m1->tryToShareSameCoordsPermute(*m2,1e-12),INTERP_KERNEL::Exception);// <- here in this order the sharing is impossible.
1010 // Let's go for deeper test of tryToShareSameCoordsPermute
1011 m2->tryToShareSameCoordsPermute(*m1,1e-12);
1012 f1=m1->getMeasureField(false);
1013 f2=m2->getMeasureField(false);
1014 CPPUNIT_ASSERT_EQUAL(5,f1->getArray()->getNumberOfTuples());
1015 CPPUNIT_ASSERT_EQUAL(1,f2->getArray()->getNumberOfTuples());
1016 for(int i=0;i<5;i++)
1017 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(i,0),1e-12);
1018 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(0,0),1e-12);
1027 void MEDCouplingBasicsTest2::testChangeUnderlyingMesh1()
1029 MEDCouplingUMesh *mesh1=build2DTargetMesh_3();
1030 MEDCouplingUMesh *mesh2=build2DTargetMesh_3();
1031 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1033 DataArrayDouble *array=DataArrayDouble::New();
1034 array->alloc(mesh1->getNumberOfCells(),2);
1035 const double arr[20]={7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.};
1036 std::copy(arr,arr+20,array->getPointer());
1037 f1->setArray(array);
1040 const int renum[]={0,2,1,3,4,5,6,8,7,9};
1041 mesh2->renumberCells(renum,false);
1042 CPPUNIT_ASSERT(f1->getMesh()==mesh1);
1043 f1->changeUnderlyingMesh(mesh1,10,1e-12);// nothing done only to check that nothing done.
1044 CPPUNIT_ASSERT(f1->getMesh()==mesh1);
1045 f1->changeUnderlyingMesh(mesh2,10,1e-12);
1046 CPPUNIT_ASSERT(f1->getMesh()==mesh2);
1047 const double expected1[20]={7.,107.,9.,109.,8.,108.,10.,110.,11.,111.,12.,112.,13.,113.,15.,115.,14.,114.,16.,116.};
1048 for(int i=0;i<20;i++)
1049 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getArray()->getIJ(0,i),1e-12);
1052 f1=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
1054 array=DataArrayDouble::New();
1055 array->alloc(mesh1->getNumberOfNodes(),2);
1056 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.};
1057 std::copy(arr2,arr2+22,array->getPointer());
1058 f1->setArray(array);
1061 const int renum2[]={0,2,10,3,4,5,6,8,7,9,1};
1062 mesh2->renumberNodes(renum2,11);
1063 CPPUNIT_ASSERT(f1->getMesh()==mesh1);
1064 f1->changeUnderlyingMesh(mesh2,10,1e-12);
1065 CPPUNIT_ASSERT(f1->getMesh()==mesh2);
1066 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.};
1067 for(int i=0;i<22;i++)
1068 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f1->getArray()->getIJ(0,i),1e-12);
1075 void MEDCouplingBasicsTest2::testGetMaxValue1()
1077 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1078 int nbOfCells=m->getNumberOfCells();
1079 MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
1081 DataArrayDouble *a1=DataArrayDouble::New();
1082 a1->alloc(nbOfCells,1);
1083 const double val1[5]={3.,4.,5.,6.,7.};
1084 std::copy(val1,val1+5,a1->getPointer());
1085 DataArrayDouble *a2=DataArrayDouble::New();
1086 a2->alloc(nbOfCells,1);
1087 const double val2[5]={0.,1.,2.,8.,7.};
1088 std::copy(val2,val2+5,a2->getPointer());
1091 f->setEndTime(3.,3,4);
1092 f->checkCoherency();
1094 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.,f->getMaxValue(),1e-14);
1095 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,f->getMinValue(),1e-14);
1096 CPPUNIT_ASSERT_DOUBLES_EQUAL(5.,f->getAverageValue(),1e-14);
1097 CPPUNIT_ASSERT_DOUBLES_EQUAL(5.125,f->getWeightedAverageValue(0),1e-14);
1099 CPPUNIT_ASSERT_DOUBLES_EQUAL(9.5,f->getMaxValue(),1e-14);
1100 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,f->getMinValue(),1e-14);
1102 CPPUNIT_ASSERT_DOUBLES_EQUAL(9.5,f->getMaxValue(),1e-14);
1103 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,f->getMinValue(),1e-14);
1111 void MEDCouplingBasicsTest2::testSubstractInPlaceDM1()
1113 MEDCouplingUMesh *mesh1=build2DTargetMesh_3();
1114 MEDCouplingUMesh *mesh2=build2DTargetMesh_3();
1115 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1117 DataArrayDouble *array=DataArrayDouble::New();
1118 array->alloc(mesh1->getNumberOfCells(),2);
1119 const double arr[20]={7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.};
1120 std::copy(arr,arr+20,array->getPointer());
1121 f1->setArray(array);
1124 CPPUNIT_ASSERT_EQUAL(10,f1->getNumberOfTuples());
1125 CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
1126 CPPUNIT_ASSERT_EQUAL(20,f1->getNumberOfValues());
1128 const int renum[]={0,2,3,1,4,5,6,8,7,9};
1129 mesh2->renumberCells(renum,false);
1131 MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1133 array=DataArrayDouble::New();
1134 array->alloc(mesh2->getNumberOfCells(),2);
1135 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};
1136 std::copy(arr2,arr2+20,array->getPointer());
1137 f2->setArray(array);
1140 f1->substractInPlaceDM(f2,10,1e-12);
1141 f1->applyFunc(1,"abs(x+y+0.2)");
1142 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,f1->getMaxValue(),1e-14);
1150 void MEDCouplingBasicsTest2::testDotCrossProduct1()
1152 MEDCouplingUMesh *mesh1=build2DTargetMesh_3();
1153 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1154 f1->setTime(2.3,5,6);
1156 DataArrayDouble *array=DataArrayDouble::New();
1157 array->alloc(mesh1->getNumberOfCells(),3);
1158 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.};
1159 std::copy(arr1,arr1+30,array->getPointer());
1160 f1->setArray(array);
1162 MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1163 f2->setTime(7.8,4,5);
1165 array=DataArrayDouble::New();
1166 array->alloc(mesh1->getNumberOfCells(),3);
1167 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.};
1168 std::copy(arr2,arr2+30,array->getPointer());
1169 f2->setArray(array);
1172 MEDCouplingFieldDouble *f3=f1->dot(*f2);
1173 const double expected1[10]={842.,1820.,2816.,3830.,4862.,5912.,6980.,8066.,9170.,10292.};
1174 for(int i=0;i<10;i++)
1175 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f3->getIJ(i,0),1e-9);
1178 MEDCouplingFieldDouble *f4=f1->crossProduct(*f2);
1179 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.};
1180 for(int i=0;i<30;i++)
1181 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f4->getIJ(0,i),1e-9);
1189 void MEDCouplingBasicsTest2::testMinMaxFields1()
1191 MEDCouplingUMesh *mesh1=build2DTargetMesh_3();
1192 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1193 f1->setTime(2.3,5,6);
1195 DataArrayDouble *array=DataArrayDouble::New();
1196 array->alloc(mesh1->getNumberOfCells(),3);
1197 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.};
1198 std::copy(arr1,arr1+30,array->getPointer());
1199 f1->setArray(array);
1201 MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1202 f2->setTime(7.8,4,5);
1204 array=DataArrayDouble::New();
1205 array->alloc(mesh1->getNumberOfCells(),3);
1206 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.};
1207 std::copy(arr2,arr2+30,array->getPointer());
1208 f2->setArray(array);
1211 MEDCouplingFieldDouble *f3=f1->max(*f2);
1212 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.};
1213 for(int i=0;i<30;i++)
1214 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f3->getIJ(0,i),1e-9);
1217 MEDCouplingFieldDouble *f4=f1->min(*f2);
1218 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.};
1219 for(int i=0;i<30;i++)
1220 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f4->getIJ(0,i),1e-9);
1228 void MEDCouplingBasicsTest2::testApplyLin1()
1230 MEDCouplingUMesh *mesh1=build2DTargetMesh_3();
1231 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
1233 DataArrayDouble *array=DataArrayDouble::New();
1234 array->alloc(mesh1->getNumberOfCells(),2);
1235 const double arr[20]={7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.};
1236 std::copy(arr,arr+20,array->getPointer());
1237 f1->setArray(array);
1240 f1->applyLin(2.,3.,0);
1241 const double expected1[20]={17.,107.,19.,108.,21.,109.,23.,110.,25.,111.,27.,112.,29.,113.,31.,114.,33.,115.,35.,116.};
1242 for(int i=0;i<20;i++)
1243 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-9);
1245 const double arr2[20]={2.,102.,3.,103.,4.,104.,5.,105.,6.,106.,7.,107.,8.,108.,9.,109.,10.,110.,11.,111.};
1246 array=DataArrayDouble::New();
1247 array->alloc(mesh1->getNumberOfCells(),2);
1248 std::copy(arr2,arr2+20,array->getPointer());
1249 f1->setEndArray(array);
1252 f1->applyLin(4.,5.,1);
1254 const double expected2[20]={17.,433.,19.,437.,21.,441.,23.,445.,25.,449.,27.,453.,29.,457.,31.,461.,33.,465.,35.,469.};
1255 for(int i=0;i<20;i++)
1256 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f1->getIJ(0,i),1e-9);
1257 const double expected3[20]={2.,413.,3.,417.,4.,421.,5.,425.,6.,429.,7.,433.,8.,437.,9.,441.,10.,445.,11.,449.};
1258 for(int i=0;i<20;i++)
1259 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],f1->getEndArray()->getIJ(0,i),1e-9);
1265 void MEDCouplingBasicsTest2::testGetIdsInRange1()
1267 MEDCouplingUMesh *mesh1=build2DTargetMesh_3();
1268 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1269 f1->setTime(2.3,5,6);
1271 DataArrayDouble *array=DataArrayDouble::New();
1272 array->alloc(mesh1->getNumberOfCells(),1);
1273 const double arr1[10]={2.,8.,6.,5.,11.,7.,9.,3.,10.,4.};
1274 std::copy(arr1,arr1+10,array->getPointer());
1275 f1->setArray(array);
1278 f1->checkCoherency();
1279 DataArrayInt *da=f1->getIdsInRange(2.9,7.1);
1280 CPPUNIT_ASSERT_EQUAL((std::size_t)5,da->getNbOfElems());
1281 const int expected1[5]={2,3,5,7,9};
1282 CPPUNIT_ASSERT(std::equal(expected1,expected1+5,da->getConstPointer()));
1284 da=f1->getIdsInRange(8.,12.);
1285 CPPUNIT_ASSERT_EQUAL((std::size_t)4,da->getNbOfElems());
1286 const int expected2[4]={1,4,6,8};
1287 CPPUNIT_ASSERT(std::equal(expected2,expected2+4,da->getConstPointer()));
1294 void MEDCouplingBasicsTest2::testBuildSubPart1()
1296 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1297 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1298 f1->setTime(2.3,5,6);
1300 DataArrayDouble *array=DataArrayDouble::New();
1301 array->alloc(mesh1->getNumberOfCells(),2);
1302 const double arr1[10]={3.,103.,4.,104.,5.,105.,6.,106.,7.,107.};
1303 std::copy(arr1,arr1+10,array->getPointer());
1304 f1->setArray(array);
1307 const int part1[3]={2,1,4};
1308 MEDCouplingFieldDouble *f2=f1->buildSubPart(part1,part1+3);
1310 CPPUNIT_ASSERT_EQUAL(3,f2->getNumberOfTuples());
1311 CPPUNIT_ASSERT_EQUAL(2,f2->getNumberOfComponents());
1312 const double expected1[6]={5.,105.,4.,104.,7.,107.};
1313 for(int i=0;i<6;i++)
1314 CPPUNIT_ASSERT_DOUBLES_EQUAL(f2->getIJ(0,i),expected1[i],1e-12);
1315 CPPUNIT_ASSERT_EQUAL(3,f2->getMesh()->getNumberOfCells());
1316 CPPUNIT_ASSERT_EQUAL(6,f2->getMesh()->getNumberOfNodes());
1317 CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getSpaceDimension());
1318 CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getMeshDimension());
1319 MEDCouplingUMesh *m2C=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1320 CPPUNIT_ASSERT_EQUAL(13,m2C->getMeshLength());
1321 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};
1322 for(int i=0;i<12;i++)
1323 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],m2C->getCoords()->getIJ(0,i),1.e-12);
1324 const double expected3[13]={3,2,3,1,3,0,2,1,4,4,5,3,2};
1325 CPPUNIT_ASSERT(std::equal(expected3,expected3+13,m2C->getNodalConnectivity()->getConstPointer()));
1326 const double expected4[4]={0,4,8,13};
1327 CPPUNIT_ASSERT(std::equal(expected4,expected4+4,m2C->getNodalConnectivityIndex()->getConstPointer()));
1330 // Test with field on nodes.
1331 f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
1332 f1->setTime(2.3,5,6);
1334 array=DataArrayDouble::New();
1335 array->alloc(mesh1->getNumberOfNodes(),2);
1336 const double arr2[18]={3.,103.,4.,104.,5.,105.,6.,106.,7.,107.,8.,108.,9.,109.,10.,110.,11.,111.};
1337 std::copy(arr2,arr2+18,array->getPointer());
1338 f1->setArray(array);
1340 const int part2[2]={1,2};
1341 f2=f1->buildSubPart(part2,part2+2);
1342 CPPUNIT_ASSERT_EQUAL(4,f2->getNumberOfTuples());
1343 CPPUNIT_ASSERT_EQUAL(2,f2->getNumberOfComponents());
1344 const double expected5[8]={4.,104.,5.,105.,7.,107.,8.,108.};
1345 for(int i=0;i<8;i++)
1346 CPPUNIT_ASSERT_DOUBLES_EQUAL(f2->getIJ(0,i),expected5[i],1e-12);
1347 CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getNumberOfCells());
1348 CPPUNIT_ASSERT_EQUAL(4,f2->getMesh()->getNumberOfNodes());
1349 CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getSpaceDimension());
1350 CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getMeshDimension());
1351 m2C=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1352 CPPUNIT_ASSERT_EQUAL(8,m2C->getMeshLength());
1353 for(int i=0;i<8;i++)//8 is not an error
1354 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],m2C->getCoords()->getIJ(0,i),1.e-12);
1355 CPPUNIT_ASSERT(std::equal(expected3,expected3+4,m2C->getNodalConnectivity()->getConstPointer()+4));
1356 CPPUNIT_ASSERT(std::equal(expected3+4,expected3+8,m2C->getNodalConnectivity()->getConstPointer()));
1357 CPPUNIT_ASSERT(std::equal(expected4,expected4+3,m2C->getNodalConnectivityIndex()->getConstPointer()));
1359 //idem previous because nodes of cell#4 are not fully present in part3
1360 const int part3[2]={1,2};
1361 DataArrayInt *arrr=DataArrayInt::New();
1363 std::copy(part3,part3+2,arrr->getPointer());
1364 f2=f1->buildSubPart(arrr);
1366 CPPUNIT_ASSERT_EQUAL(4,f2->getNumberOfTuples());
1367 CPPUNIT_ASSERT_EQUAL(2,f2->getNumberOfComponents());
1368 for(int i=0;i<8;i++)
1369 CPPUNIT_ASSERT_DOUBLES_EQUAL(f2->getIJ(0,i),expected5[i],1e-12);
1370 CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getNumberOfCells());
1371 CPPUNIT_ASSERT_EQUAL(4,f2->getMesh()->getNumberOfNodes());
1372 CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getSpaceDimension());
1373 CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getMeshDimension());
1374 m2C=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1375 CPPUNIT_ASSERT_EQUAL(8,m2C->getMeshLength());
1376 for(int i=0;i<8;i++)//8 is not an error
1377 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],m2C->getCoords()->getIJ(0,i),1.e-12);
1378 CPPUNIT_ASSERT(std::equal(expected3,expected3+4,m2C->getNodalConnectivity()->getConstPointer()+4));
1379 CPPUNIT_ASSERT(std::equal(expected3+4,expected3+8,m2C->getNodalConnectivity()->getConstPointer()));
1380 CPPUNIT_ASSERT(std::equal(expected4,expected4+3,m2C->getNodalConnectivityIndex()->getConstPointer()));
1383 const int part4[3]={1,2,4};
1384 f2=f1->buildSubPart(part4,part4+3);
1385 CPPUNIT_ASSERT_EQUAL(6,f2->getNumberOfTuples());
1386 CPPUNIT_ASSERT_EQUAL(2,f2->getNumberOfComponents());
1387 const double expected6[12]={4.,104.,5.,105.,7.,107.,8.,108.,10.,110.,11.,111.};
1388 for(int i=0;i<12;i++)
1389 CPPUNIT_ASSERT_DOUBLES_EQUAL(f2->getIJ(0,i),expected6[i],1e-12);
1390 CPPUNIT_ASSERT_EQUAL(3,f2->getMesh()->getNumberOfCells());
1391 CPPUNIT_ASSERT_EQUAL(6,f2->getMesh()->getNumberOfNodes());
1392 CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getSpaceDimension());
1393 CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getMeshDimension());
1394 m2C=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1395 CPPUNIT_ASSERT_EQUAL(13,m2C->getMeshLength());
1396 for(int i=0;i<12;i++)
1397 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],m2C->getCoords()->getIJ(0,i),1.e-12);
1398 CPPUNIT_ASSERT(std::equal(expected3,expected3+4,m2C->getNodalConnectivity()->getConstPointer()+4));
1399 CPPUNIT_ASSERT(std::equal(expected3+4,expected3+8,m2C->getNodalConnectivity()->getConstPointer()));
1400 CPPUNIT_ASSERT(std::equal(expected3+8,expected3+13,m2C->getNodalConnectivity()->getConstPointer()+8));
1401 CPPUNIT_ASSERT(std::equal(expected4,expected4+4,m2C->getNodalConnectivityIndex()->getConstPointer()));
1408 void MEDCouplingBasicsTest2::testDoublyContractedProduct1()
1410 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1411 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1413 DataArrayDouble *array=DataArrayDouble::New();
1414 array->alloc(mesh1->getNumberOfCells(),6);
1415 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};
1416 std::copy(arr1,arr1+30,array->getPointer());
1417 f1->setArray(array);
1419 f1->checkCoherency();
1421 MEDCouplingFieldDouble *f2=f1->doublyContractedProduct();
1422 f2->checkCoherency();
1423 CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
1424 CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
1425 for(int i=0;i<5;i++)
1426 CPPUNIT_ASSERT_DOUBLES_EQUAL(3906.56,f2->getIJ(i,0),1e-9);
1433 void MEDCouplingBasicsTest2::testDeterminant1()
1435 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1436 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,CONST_ON_TIME_INTERVAL);
1437 f1->setTime(2.3,5,6);
1438 f1->setEndTime(3.8,7,3);
1440 DataArrayDouble *array=DataArrayDouble::New();
1441 array->alloc(mesh1->getNumberOfCells(),4);
1442 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};
1443 std::copy(arr1,arr1+20,array->getPointer());
1444 f1->setArray(array);
1447 f1->checkCoherency();
1448 MEDCouplingFieldDouble *f2=f1->determinant();
1449 f2->checkCoherency();
1450 CPPUNIT_ASSERT_EQUAL(CONST_ON_TIME_INTERVAL,f2->getTimeDiscretization());
1451 CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
1452 CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfValues());
1453 for(int i=0;i<5;i++)
1454 CPPUNIT_ASSERT_DOUBLES_EQUAL(-2.42,f2->getIJ(i,0),1e-13);
1457 //6 components multi arrays with end array not defined
1458 f1=MEDCouplingFieldDouble::New(ON_NODES,LINEAR_TIME);
1459 f1->setTime(2.3,5,6);
1460 f1->setEndTime(3.8,7,3);
1462 array=DataArrayDouble::New();
1463 array->alloc(mesh1->getNumberOfNodes(),6);
1464 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,
1465 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};
1466 std::copy(arr2,arr2+54,array->getPointer());
1467 f1->setArray(array);
1469 CPPUNIT_ASSERT_THROW(f1->checkCoherency(),INTERP_KERNEL::Exception);//no end array specified !
1471 f2=f1->determinant();
1472 CPPUNIT_ASSERT_EQUAL(LINEAR_TIME,f2->getTimeDiscretization());
1473 CPPUNIT_ASSERT_EQUAL(1,f2->getArray()->getNumberOfComponents());
1474 CPPUNIT_ASSERT_EQUAL(9,f2->getNumberOfTuples());
1475 for(int i=0;i<9;i++)
1476 CPPUNIT_ASSERT_DOUBLES_EQUAL(137.335,f2->getIJ(i,0),1e-10);
1478 //6 components multi arrays with end array defined
1479 array=DataArrayDouble::New();
1480 array->alloc(mesh1->getNumberOfNodes(),6);
1481 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,
1482 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};
1483 std::copy(arr3,arr3+54,array->getPointer());
1484 f1->setEndArray(array);
1486 f1->checkCoherency();
1487 f2=f1->determinant();
1488 f2->checkCoherency();
1489 CPPUNIT_ASSERT_EQUAL(LINEAR_TIME,f2->getTimeDiscretization());
1490 CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
1491 CPPUNIT_ASSERT_EQUAL(9,f2->getNumberOfTuples());
1493 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.3,f2->getTime(it,order),1e-12);
1494 CPPUNIT_ASSERT_EQUAL(5,it); CPPUNIT_ASSERT_EQUAL(6,order);
1495 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.8,f2->getEndTime(it,order),1e-12);
1496 CPPUNIT_ASSERT_EQUAL(7,it); CPPUNIT_ASSERT_EQUAL(3,order);
1497 for(int i=0;i<9;i++)
1499 CPPUNIT_ASSERT_DOUBLES_EQUAL(137.335,f2->getIJ(i,0),1e-10);
1500 CPPUNIT_ASSERT_DOUBLES_EQUAL(1289.685,f2->getEndArray()->getIJ(i,0),1e-9);
1505 f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1506 f1->setTime(7.8,10,2);
1508 array=DataArrayDouble::New();
1509 array->alloc(mesh1->getNumberOfCells(),9);
1510 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};
1511 std::copy(arr4,arr4+45,array->getPointer());
1512 f1->setArray(array);
1515 f1->checkCoherency();
1516 f2=f1->determinant();
1517 f2->checkCoherency();
1518 CPPUNIT_ASSERT_EQUAL(ONE_TIME,f2->getTimeDiscretization());
1519 CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
1520 CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
1521 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.8,f2->getTime(it,order),1e-12);
1522 CPPUNIT_ASSERT_EQUAL(10,it); CPPUNIT_ASSERT_EQUAL(2,order);
1523 for(int i=0;i<5;i++)
1524 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.267,f2->getIJ(i,0),1e-13);
1531 void MEDCouplingBasicsTest2::testEigenValues1()
1533 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1534 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1536 DataArrayDouble *array=DataArrayDouble::New();
1537 array->alloc(mesh1->getNumberOfCells(),6);
1538 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};
1539 std::copy(arr1,arr1+30,array->getPointer());
1540 f1->setArray(array);
1542 f1->checkCoherency();
1544 MEDCouplingFieldDouble *f2=f1->eigenValues();
1545 f2->checkCoherency();
1546 CPPUNIT_ASSERT_EQUAL(3,f2->getNumberOfComponents());
1547 CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
1548 const double expected1[3]={13.638813677891717,-4.502313844635971,-2.2364998332557486};
1549 for(int i=0;i<5;i++)
1551 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(i,0),1e-13);
1552 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[1],f2->getIJ(i,1),1e-13);
1553 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[2],f2->getIJ(i,2),1e-13);
1561 void MEDCouplingBasicsTest2::testEigenVectors1()
1563 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1564 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1566 DataArrayDouble *array=DataArrayDouble::New();
1567 array->alloc(mesh1->getNumberOfCells(),6);
1568 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};
1569 std::copy(arr1,arr1+30,array->getPointer());
1570 f1->setArray(array);
1572 f1->checkCoherency();
1574 MEDCouplingFieldDouble *f2=f1->eigenVectors();
1575 f2->checkCoherency();
1576 CPPUNIT_ASSERT_EQUAL(9,f2->getNumberOfComponents());
1577 CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
1578 const double expected1[9]={
1579 0.5424262364180696, 0.5351201064614425, 0.6476266283176001,//eigenvect 0
1580 0.7381111277307373, 0.06458838384003074, -0.6715804522117897,//eigenvect 1
1581 -0.4012053603397987, 0.8423032781211455, -0.3599436712889738//eigenvect 2
1583 for(int i=0;i<5;i++)
1585 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(i,0),1e-13);
1586 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[1],f2->getIJ(i,1),1e-13);
1587 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[2],f2->getIJ(i,2),1e-13);
1588 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[3],f2->getIJ(i,3),1e-13);
1589 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[4],f2->getIJ(i,4),1e-13);
1590 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[5],f2->getIJ(i,5),1e-13);
1591 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[6],f2->getIJ(i,6),1e-13);
1592 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[7],f2->getIJ(i,7),1e-13);
1593 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[8],f2->getIJ(i,8),1e-13);
1601 void MEDCouplingBasicsTest2::testInverse1()
1603 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1604 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1606 DataArrayDouble *array=DataArrayDouble::New();
1607 array->alloc(mesh1->getNumberOfCells(),9);
1608 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};
1609 std::copy(arr1,arr1+45,array->getPointer());
1610 f1->setArray(array);
1612 f1->checkCoherency();
1614 MEDCouplingFieldDouble *f2=f1->inverse();
1615 f2->checkCoherency();
1616 CPPUNIT_ASSERT_EQUAL(9,f2->getNumberOfComponents());
1617 CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
1618 const double expected1[9]={-2.6538108356290113, 2.855831037649208, -1.1111111111111067, 3.461891643709813, -4.775022956841121, 2.2222222222222143, -1.1111111111111054, 2.222222222222214, -1.1111111111111072};
1619 for(int i=0;i<5;i++)
1621 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(i,0),1e-13);
1622 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[1],f2->getIJ(i,1),1e-13);
1623 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[2],f2->getIJ(i,2),1e-13);
1624 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[3],f2->getIJ(i,3),1e-13);
1625 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[4],f2->getIJ(i,4),1e-13);
1626 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[5],f2->getIJ(i,5),1e-13);
1627 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[6],f2->getIJ(i,6),1e-13);
1628 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[7],f2->getIJ(i,7),1e-13);
1629 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[8],f2->getIJ(i,8),1e-13);
1633 array=DataArrayDouble::New();
1634 array->alloc(mesh1->getNumberOfCells(),6);
1635 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};
1636 std::copy(arr3,arr3+30,array->getPointer());
1637 f1->setArray(array);
1639 f1->checkCoherency();
1642 f2->checkCoherency();
1643 CPPUNIT_ASSERT_EQUAL(6,f2->getNumberOfComponents());
1644 CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
1645 const double expected3[6]={-0.3617705098531818, -0.8678630828458127, -0.026843764174972983, 0.5539957431465833, 0.13133439560823013, -0.05301294502145887};
1646 for(int i=0;i<5;i++)
1648 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[0],f2->getIJ(i,0),1e-13);
1649 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[1],f2->getIJ(i,1),1e-13);
1650 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[2],f2->getIJ(i,2),1e-13);
1651 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[3],f2->getIJ(i,3),1e-13);
1652 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[4],f2->getIJ(i,4),1e-13);
1653 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[5],f2->getIJ(i,5),1e-13);
1657 array=DataArrayDouble::New();
1658 array->alloc(mesh1->getNumberOfCells(),4);
1659 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};
1660 std::copy(arr2,arr2+20,array->getPointer());
1661 f1->setArray(array);
1663 f1->checkCoherency();
1666 f2->checkCoherency();
1667 CPPUNIT_ASSERT_EQUAL(4,f2->getNumberOfComponents());
1668 CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
1669 const double expected2[4]={-1.8595041322314059, 0.9504132231404963, 1.404958677685951, -0.49586776859504156};
1670 for(int i=0;i<5;i++)
1672 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[0],f2->getIJ(i,0),1e-13);
1673 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[1],f2->getIJ(i,1),1e-13);
1674 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[2],f2->getIJ(i,2),1e-13);
1675 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[3],f2->getIJ(i,3),1e-13);
1683 void MEDCouplingBasicsTest2::testTrace1()
1685 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1686 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1688 DataArrayDouble *array=DataArrayDouble::New();
1689 array->alloc(mesh1->getNumberOfCells(),9);
1690 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};
1691 std::copy(arr1,arr1+45,array->getPointer());
1692 f1->setArray(array);
1694 f1->checkCoherency();
1696 MEDCouplingFieldDouble *f2=f1->trace();
1697 f2->checkCoherency();
1698 CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
1699 CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
1700 for(int i=0;i<5;i++)
1701 CPPUNIT_ASSERT_DOUBLES_EQUAL(15.9,f2->getIJ(i,0),1e-13);
1704 array=DataArrayDouble::New();
1705 array->alloc(mesh1->getNumberOfCells(),6);
1706 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};
1707 std::copy(arr3,arr3+30,array->getPointer());
1708 f1->setArray(array);
1710 f1->checkCoherency();
1713 f2->checkCoherency();
1714 CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
1715 CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
1716 for(int i=0;i<5;i++)
1717 CPPUNIT_ASSERT_DOUBLES_EQUAL(25.8,f2->getIJ(i,0),1e-13);
1720 array=DataArrayDouble::New();
1721 array->alloc(mesh1->getNumberOfCells(),4);
1722 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};
1723 std::copy(arr2,arr2+20,array->getPointer());
1724 f1->setArray(array);
1726 f1->checkCoherency();
1729 f2->checkCoherency();
1730 CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
1731 CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
1732 for(int i=0;i<5;i++)
1733 CPPUNIT_ASSERT_DOUBLES_EQUAL(5.7,f2->getIJ(i,0),1e-13);
1740 void MEDCouplingBasicsTest2::testDeviator1()
1742 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1743 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1745 DataArrayDouble *array=DataArrayDouble::New();
1746 array->alloc(mesh1->getNumberOfCells(),6);
1747 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};
1748 std::copy(arr1,arr1+30,array->getPointer());
1749 f1->setArray(array);
1751 f1->checkCoherency();
1753 MEDCouplingFieldDouble *f2=f1->deviator();
1754 f2->checkCoherency();
1755 CPPUNIT_ASSERT_EQUAL(6,f2->getNumberOfComponents());
1756 CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
1757 const double expected1[6]={-1.1,0.,1.1,4.5,5.6,6.7};
1758 for(int i=0;i<5;i++)
1760 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(i,0),1e-13);
1761 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[1],f2->getIJ(i,1),1e-13);
1762 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[2],f2->getIJ(i,2),1e-13);
1763 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[3],f2->getIJ(i,3),1e-13);
1764 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[4],f2->getIJ(i,4),1e-13);
1765 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[5],f2->getIJ(i,5),1e-13);
1773 void MEDCouplingBasicsTest2::testMagnitude1()
1775 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1776 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1778 DataArrayDouble *array=DataArrayDouble::New();
1779 array->alloc(mesh1->getNumberOfCells(),5);
1780 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};
1781 std::copy(arr1,arr1+25,array->getPointer());
1782 f1->setArray(array);
1784 f1->checkCoherency();
1786 MEDCouplingFieldDouble *f2=f1->magnitude();
1787 f2->checkCoherency();
1788 CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
1789 CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
1790 for(int i=0;i<5;i++)
1791 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.3606219864313918,f2->getIJ(i,0),1e-13);
1798 void MEDCouplingBasicsTest2::testMaxPerTuple1()
1800 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1801 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1803 DataArrayDouble *array=DataArrayDouble::New();
1804 array->alloc(mesh1->getNumberOfCells(),5);
1805 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};
1806 std::copy(arr1,arr1+25,array->getPointer());
1807 f1->setArray(array);
1809 f1->checkCoherency();
1811 MEDCouplingFieldDouble *f2=f1->maxPerTuple();
1812 f2->checkCoherency();
1813 CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
1814 CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
1815 for(int i=0;i<5;i++)
1816 CPPUNIT_ASSERT_DOUBLES_EQUAL(5.6,f2->getIJ(i,0),1e-13);
1819 DataArrayInt *d2I=0;
1820 DataArrayDouble *d2=array->maxPerTupleWithCompoId(d2I);
1821 CPPUNIT_ASSERT_EQUAL(1,d2->getNumberOfComponents());
1822 CPPUNIT_ASSERT_EQUAL(5,d2->getNumberOfTuples());
1823 const int expected2[5]={4,3,2,0,1};
1824 for(int i=0;i<5;i++)
1826 CPPUNIT_ASSERT_DOUBLES_EQUAL(5.6,d2->getIJ(i,0),1e-13);
1827 CPPUNIT_ASSERT_EQUAL(expected2[i],d2I->getIJ(i,0));
1829 d2->decrRef(); d2I->decrRef();
1835 void MEDCouplingBasicsTest2::testChangeNbOfComponents()
1837 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1838 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1840 DataArrayDouble *array=DataArrayDouble::New();
1841 array->alloc(mesh1->getNumberOfCells(),5);
1842 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};
1843 std::copy(arr1,arr1+25,array->getPointer());
1844 f1->setArray(array);
1846 f1->checkCoherency();
1848 f1->changeNbOfComponents(3,7.77);
1849 f1->checkCoherency();
1850 CPPUNIT_ASSERT_EQUAL(3,f1->getNumberOfComponents());
1851 CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
1852 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};
1853 for(int i=0;i<15;i++)
1854 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-13);
1855 f1->changeNbOfComponents(4,7.77);
1856 f1->checkCoherency();
1857 CPPUNIT_ASSERT_EQUAL(4,f1->getNumberOfComponents());
1858 CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
1859 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};
1860 for(int i=0;i<20;i++)
1861 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f1->getIJ(0,i),1e-13);
1867 void MEDCouplingBasicsTest2::testSortPerTuple1()
1869 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1870 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1872 DataArrayDouble *array=DataArrayDouble::New();
1873 array->alloc(mesh1->getNumberOfCells(),5);
1874 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};
1875 std::copy(arr1,arr1+25,array->getPointer());
1876 f1->setArray(array);
1878 f1->checkCoherency();
1880 f1->sortPerTuple(true);
1881 f1->checkCoherency();
1882 CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfComponents());
1883 CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
1884 for(int i=0;i<5;i++)
1886 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[0],f1->getIJ(i,0),1e-13);
1887 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[1],f1->getIJ(i,1),1e-13);
1888 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[2],f1->getIJ(i,2),1e-13);
1889 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[3],f1->getIJ(i,3),1e-13);
1890 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[4],f1->getIJ(i,4),1e-13);
1893 f1->sortPerTuple(false);
1894 f1->checkCoherency();
1895 CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfComponents());
1896 CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
1897 for(int i=0;i<5;i++)
1899 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[4],f1->getIJ(i,0),1e-13);
1900 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[3],f1->getIJ(i,1),1e-13);
1901 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[2],f1->getIJ(i,2),1e-13);
1902 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[1],f1->getIJ(i,3),1e-13);
1903 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[0],f1->getIJ(i,4),1e-13);
1910 void MEDCouplingBasicsTest2::testIsEqualWithoutConsideringStr1()
1912 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1913 MEDCouplingUMesh *mesh2=build2DTargetMesh_1();
1914 DataArrayInt *da1,*da2;
1916 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
1917 CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1918 mesh2->setName("rr");
1919 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
1920 CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1921 mesh1->checkDeepEquivalWith(mesh2,2,1e-12,da1,da2);
1922 CPPUNIT_ASSERT_THROW(mesh1->checkGeoEquivalWith(mesh2,0,1e-12,da1,da2),INTERP_KERNEL::Exception);
1924 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
1925 CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1926 mesh2->getCoords()->setInfoOnComponent(0,"tty");
1927 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
1928 CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1929 mesh2->getCoords()->setInfoOnComponent(0,"");
1930 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
1931 CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1932 mesh2->getCoords()->setInfoOnComponent(1,"tty");
1933 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
1934 CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1935 mesh2->getCoords()->setInfoOnComponent(1,"");
1936 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
1937 CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1938 double tmp=mesh2->getCoords()->getIJ(0,3);
1939 mesh2->getCoords()->setIJ(0,3,9999.);
1940 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
1941 CPPUNIT_ASSERT(!mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1942 mesh2->getCoords()->setIJ(0,3,tmp);
1943 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
1944 CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1945 int tmp2=mesh2->getNodalConnectivity()->getIJ(0,4);
1946 mesh2->getNodalConnectivity()->setIJ(0,4,0);
1947 CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
1948 CPPUNIT_ASSERT(!mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1949 mesh2->getNodalConnectivity()->setIJ(0,4,tmp2);
1950 CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
1951 CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1953 MEDCouplingFieldDouble *f1=mesh1->getMeasureField(true);
1954 MEDCouplingFieldDouble *f2=mesh2->getMeasureField(true);
1955 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
1956 CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12));
1957 f2->setName("ftest");
1958 CPPUNIT_ASSERT(!f1->isEqual(f2,1e-12,1e-12));
1959 CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12));
1960 f1->setName("ftest");
1961 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
1962 CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12));
1964 f2->getArray()->setInfoOnComponent(0,"eee");
1965 CPPUNIT_ASSERT(!f1->isEqual(f2,1e-12,1e-12));
1966 CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12));
1967 f2->getArray()->setInfoOnComponent(0,"");
1968 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
1969 CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12));
1971 f2->getArray()->setIJ(1,0,0.123);
1972 CPPUNIT_ASSERT(!f1->isEqual(f2,1e-12,1e-12));
1973 CPPUNIT_ASSERT(!f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12));
1974 f2->getArray()->setIJ(1,0,0.125);
1975 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
1976 CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12));
1985 void MEDCouplingBasicsTest2::testGetNodeIdsOfCell1()
1987 MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1988 std::vector<int> nodeIds;
1989 mesh1->getNodeIdsOfCell(1,nodeIds);
1990 CPPUNIT_ASSERT_EQUAL(3,(int)nodeIds.size());
1991 CPPUNIT_ASSERT_EQUAL(1,nodeIds[0]);
1992 CPPUNIT_ASSERT_EQUAL(4,nodeIds[1]);
1993 CPPUNIT_ASSERT_EQUAL(2,nodeIds[2]);
1994 std::vector<double> coords;
1995 mesh1->getCoordinatesOfNode(4,coords);
1996 CPPUNIT_ASSERT_EQUAL(2,(int)coords.size());
1997 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.2,coords[0],1e-13);
1998 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.2,coords[1],1e-13);
2002 void MEDCouplingBasicsTest2::testGetEdgeRatioField1()
2004 MEDCouplingUMesh *m1=build2DTargetMesh_1();
2005 m1->setTime(3.4,5,6); m1->setTimeUnit("us");
2007 MEDCouplingFieldDouble *f1=m1->getEdgeRatioField();
2008 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.4,f1->getTime(a,b),1.e-14);
2009 CPPUNIT_ASSERT_EQUAL(5,a); CPPUNIT_ASSERT_EQUAL(6,b);
2010 CPPUNIT_ASSERT_EQUAL(std::string(f1->getTimeUnit()),std::string("us"));
2011 CPPUNIT_ASSERT_EQUAL(m1->getNumberOfCells(),f1->getNumberOfTuples());
2012 CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
2013 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
2014 const double expected1[5]={1.,1.4142135623730951, 1.4142135623730951,1.,1.};
2015 for(int i=0;i<5;i++)
2016 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(i,0),1e-14);
2020 m1=build3DSurfTargetMesh_1();
2021 f1=m1->getEdgeRatioField();
2022 CPPUNIT_ASSERT_EQUAL(m1->getNumberOfCells(),f1->getNumberOfTuples());
2023 CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
2024 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
2025 const double expected2[5]={1.4142135623730951, 1.7320508075688772, 1.7320508075688772, 1.4142135623730951, 1.4142135623730951};
2026 for(int i=0;i<5;i++)
2027 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f1->getIJ(i,0),1e-14);
2032 void MEDCouplingBasicsTest2::testFillFromAnalytic3()
2034 MEDCouplingUMesh *m=build2DTargetMesh_1();
2035 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
2036 CPPUNIT_ASSERT_THROW(f1->fillFromAnalytic(1,"y+x"),INTERP_KERNEL::Exception);
2038 f1->setName("myField");
2039 f1->fillFromAnalytic(1,"y+x");
2040 f1->checkCoherency();
2041 CPPUNIT_ASSERT(std::string(f1->getName())=="myField");
2042 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_CELLS);
2043 CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
2044 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
2045 CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
2046 double values1[5]={-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9};
2047 const double *tmp=f1->getArray()->getConstPointer();
2048 std::transform(tmp,tmp+5,values1,values1,std::minus<double>());
2049 std::transform(values1,values1+5,values1,std::ptr_fun<double,double>(fabs));
2050 double max=*std::max_element(values1,values1+5);
2051 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
2054 f1=MEDCouplingFieldDouble::New(ON_NODES,CONST_ON_TIME_INTERVAL);
2056 f1->setEndTime(1.2,3,4);
2057 f1->fillFromAnalytic(1,"y+2*x");
2058 f1->checkCoherency();
2059 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
2060 CPPUNIT_ASSERT(f1->getTimeDiscretization()==CONST_ON_TIME_INTERVAL);
2061 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
2062 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
2063 double values2[9]={-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1};
2064 tmp=f1->getArray()->getConstPointer();
2065 std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
2066 std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
2067 max=*std::max_element(values2,values2+9);
2068 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
2070 f1=MEDCouplingFieldDouble::New(ON_NODES,LINEAR_TIME);
2072 f1->setEndTime(1.2,3,4);
2073 f1->fillFromAnalytic(1,"2.*x+y");
2074 f1->checkCoherency();
2075 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
2076 CPPUNIT_ASSERT(f1->getTimeDiscretization()==LINEAR_TIME);
2077 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
2078 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
2079 tmp=f1->getArray()->getConstPointer();
2080 double values2Bis[9]={-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1};
2081 double values2BisBis[9];
2082 std::transform(tmp,tmp+9,values2Bis,values2BisBis,std::minus<double>());
2083 std::transform(values2,values2+9,values2BisBis,std::ptr_fun<double,double>(fabs));
2084 max=*std::max_element(values2BisBis,values2BisBis+9);
2085 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
2086 tmp=f1->getEndArray()->getConstPointer();
2087 std::transform(tmp,tmp+9,values2Bis,values2BisBis,std::minus<double>());
2088 std::transform(values2,values2+9,values2BisBis,std::ptr_fun<double,double>(fabs));
2089 max=*std::max_element(values2BisBis,values2BisBis+9);
2090 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
2093 f1=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
2095 f1->fillFromAnalytic(2,"(x+y)*IVec+2*(x+y)*JVec");
2096 f1->checkCoherency();
2097 CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
2098 CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
2099 CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
2100 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
2101 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};
2102 tmp=f1->getArray()->getConstPointer();
2103 std::transform(tmp,tmp+18,values3,values3,std::minus<double>());
2104 std::transform(values3,values3+18,values3,std::ptr_fun<double,double>(fabs));
2105 max=*std::max_element(values3,values3+18);
2106 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
2108 f1->accumulate(values4);
2109 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.6,values4[0],1.e-12);
2110 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.2,values4[1],1.e-12);
2111 f1->integral(true,values4);
2112 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,values4[0],1.e-12);
2113 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,values4[1],1.e-12);
2116 f1=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
2118 CPPUNIT_ASSERT_THROW(f1->fillFromAnalytic(1,"1./(x-0.2)"),INTERP_KERNEL::Exception);
2124 void MEDCouplingBasicsTest2::testFieldDoubleOpEqual1()
2126 MEDCouplingUMesh *m=build2DTargetMesh_1();
2127 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
2128 CPPUNIT_ASSERT_THROW((*f1)=0.07,INTERP_KERNEL::Exception);
2131 f1->checkCoherency();
2132 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
2133 CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
2134 for(int i=0;i<5;i++)
2135 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.07,f1->getIJ(i,0),1e-16);
2137 f1->checkCoherency();
2138 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
2139 CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
2140 for(int i=0;i<5;i++)
2141 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.09,f1->getIJ(i,0),1e-16);
2144 f1=MEDCouplingFieldDouble::New(ON_NODES,LINEAR_TIME);
2145 f1->setEndTime(4.5,2,3);
2148 f1->checkCoherency();
2149 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
2150 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
2151 for(int i=0;i<9;i++)
2152 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.08,f1->getIJ(i,0),1e-16);
2153 CPPUNIT_ASSERT_EQUAL(1,f1->getEndArray()->getNumberOfComponents());
2154 CPPUNIT_ASSERT_EQUAL(9,f1->getEndArray()->getNumberOfTuples());
2155 for(int i=0;i<9;i++)
2156 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.08,f1->getEndArray()->getIJ(i,0),1e-16);
2162 void MEDCouplingBasicsTest2::testAreaBary3D2()
2164 const double coordsForHexa8[24]={
2165 -75.45749305371, 180.95495078401, 39.515472018008,
2166 -9.755591679144, 23.394927935279, 5.108794294848,
2167 14.337630157832, 61.705351002702, 160.42422501908,
2168 -27.273893776752, 167.567731083961, 192.830034145464,
2170 99.857193154796,264.499264735586,-8.287335493412,
2171 144.939882761126,156.38626563134,-31.896173894226,
2172 161.34096835726,182.4654895809,73.832387065572,
2173 132.680430393685,255.37973247196,96.15235602819
2175 const double volHexa8=3258520.29637466;
2176 const double baryHexa8[3]={43.925705821778, 155.31893955289, 65.874418109644};
2178 const double coordsForPenta6[18]={
2179 -68.199829618726,178.938498373416,62.608505919588,
2180 8.461744647847,76.653979804423,165.00018874933,
2181 -27.273893776752,167.567731083961,192.830034145464,
2183 106.586501038965,262.629609408327,13.124533008813,
2184 155.465082847275,197.414118382622,78.408350795821,
2185 132.680430393685,255.37973247196,96.15235602819
2187 const double volPenta6=944849.868507338;
2188 const double baryPenta6[3]={39.631002313543,182.692711783428,106.98540473964};
2190 const double coordsForPyra5[15]={
2191 132.680430393685,255.37973247196,96.15235602819,
2192 -27.273893776752,167.567731083961,192.830034145464,
2193 8.461744647847,76.653979804423,165.00018874933,
2194 155.465082847275,197.414118382622,78.408350795821,
2196 -68.199829618726,178.938498373416,62.608505919588
2198 const double volPyra5=756943.92980254;
2199 const double baryPyra5[3]={29.204294116618,172.540129749156,118.01035951483};
2200 MEDCouplingUMesh *mesh=MEDCouplingUMesh::New("Bary3D2",3);
2201 DataArrayDouble *coo=DataArrayDouble::New();
2203 double *tmp=std::copy(coordsForHexa8,coordsForHexa8+24,coo->getPointer());
2204 tmp=std::copy(coordsForPenta6,coordsForPenta6+18,tmp);
2205 std::copy(coordsForPyra5,coordsForPyra5+15,tmp);
2206 mesh->setCoords(coo);
2209 int tmpConn[8]={0,1,2,3,4,5,6,7};
2210 mesh->allocateCells(3);
2211 mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,tmpConn);
2212 std::transform(tmpConn,tmpConn+8,tmpConn,std::bind2nd(std::plus<int>(),8));
2213 mesh->insertNextCell(INTERP_KERNEL::NORM_PENTA6,6,tmpConn);
2214 std::transform(tmpConn,tmpConn+8,tmpConn,std::bind2nd(std::plus<int>(),6));
2215 mesh->insertNextCell(INTERP_KERNEL::NORM_PYRA5,5,tmpConn);
2216 mesh->finishInsertingCells();
2217 mesh->checkCoherency();
2220 DataArrayInt *da=mesh->mergeNodes(1e-7,isMerged,newNebOfNodes);
2222 CPPUNIT_ASSERT_EQUAL(12,newNebOfNodes);
2223 MEDCouplingFieldDouble *vols=mesh->getMeasureField(true);
2224 CPPUNIT_ASSERT_EQUAL(3,vols->getNumberOfTuples());
2225 CPPUNIT_ASSERT_EQUAL(1,vols->getNumberOfComponents());
2226 CPPUNIT_ASSERT_DOUBLES_EQUAL(volHexa8,vols->getIJ(0,0),1e-6);
2227 CPPUNIT_ASSERT_DOUBLES_EQUAL(volPenta6,vols->getIJ(1,0),1e-7);
2228 CPPUNIT_ASSERT_DOUBLES_EQUAL(volPyra5,vols->getIJ(2,0),1e-7);
2230 DataArrayDouble *bary=mesh->getBarycenterAndOwner();
2231 CPPUNIT_ASSERT_EQUAL(3,bary->getNumberOfTuples());
2232 CPPUNIT_ASSERT_EQUAL(3,bary->getNumberOfComponents());
2233 CPPUNIT_ASSERT_DOUBLES_EQUAL(baryHexa8[0],bary->getIJ(0,0),1e-11);
2234 CPPUNIT_ASSERT_DOUBLES_EQUAL(baryHexa8[1],bary->getIJ(0,1),1e-11);
2235 CPPUNIT_ASSERT_DOUBLES_EQUAL(baryHexa8[2],bary->getIJ(0,2),1e-11);
2236 CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPenta6[0],bary->getIJ(1,0),1e-11);
2237 CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPenta6[1],bary->getIJ(1,1),1e-11);
2238 CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPenta6[2],bary->getIJ(1,2),1e-11);
2239 CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPyra5[0],bary->getIJ(2,0),1e-11);
2240 CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPyra5[1],bary->getIJ(2,1),1e-11);
2241 CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPyra5[2],bary->getIJ(2,2),1e-11);