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 "MEDCouplingBasicsTest4.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"
28 #include "MEDCouplingMultiFields.hxx"
29 #include "MEDCouplingFieldOverTime.hxx"
35 using namespace ParaMEDMEM;
37 void MEDCouplingBasicsTest4::testDescriptionInMeshTimeUnit1()
39 static const char text1[]="totoTTEDD";
40 MEDCouplingUMesh *m=build2DTargetMesh_1();
41 m->setDescription(text1);
42 CPPUNIT_ASSERT(std::string(m->getDescription())==text1);
43 MEDCouplingUMesh *m2=(MEDCouplingUMesh *)m->deepCpy();
44 CPPUNIT_ASSERT(m->isEqual(m2,1e-12));
45 CPPUNIT_ASSERT(std::string(m2->getDescription())==text1);
46 m2->setDescription("ggg");
47 CPPUNIT_ASSERT(!m->isEqual(m2,1e-12));
50 MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
51 f->setTimeUnit(text1);
52 CPPUNIT_ASSERT(std::string(f->getTimeUnit())==text1);
53 MEDCouplingFieldDouble *f2=f->deepCpy();
54 CPPUNIT_ASSERT(std::string(f2->getTimeUnit())==text1);
61 void MEDCouplingBasicsTest4::testMultiFields1()
63 MEDCouplingMultiFields *mfs=buildMultiFields_1();
64 std::vector<MEDCouplingMesh *> ms=mfs->getMeshes();
65 std::vector<int> refs;
66 std::vector<MEDCouplingMesh *> dms=mfs->getDifferentMeshes(refs);
67 std::vector<DataArrayDouble *> das=mfs->getArrays();
68 std::vector< std::vector<int> > refs2;
69 std::vector<DataArrayDouble *> das2=mfs->getDifferentArrays(refs2);
71 CPPUNIT_ASSERT_EQUAL(5,(int)ms.size());
72 CPPUNIT_ASSERT_EQUAL(2,(int)dms.size());
73 CPPUNIT_ASSERT_EQUAL(6,(int)das.size());
74 CPPUNIT_ASSERT_EQUAL(5,(int)das2.size());
76 MEDCouplingMultiFields *mfs2=mfs->deepCpy();
77 CPPUNIT_ASSERT(mfs->isEqual(mfs2,1e-12,1e-12));
83 void MEDCouplingBasicsTest4::testFieldOverTime1()
85 std::vector<MEDCouplingFieldDouble *> fs=buildMultiFields_2();
86 CPPUNIT_ASSERT_THROW(MEDCouplingFieldOverTime::New(fs),INTERP_KERNEL::Exception);
87 MEDCouplingFieldDouble *f4bis=fs[4]->buildNewTimeReprFromThis(ONE_TIME,false);
90 CPPUNIT_ASSERT_THROW(MEDCouplingFieldOverTime::New(fs),INTERP_KERNEL::Exception);
91 f4bis->setTime(2.7,20,21);
92 MEDCouplingFieldOverTime *fot=MEDCouplingFieldOverTime::New(fs);
93 MEDCouplingDefinitionTime dt=fot->getDefinitionTimeZone();
94 std::vector<double> hs=dt.getHotSpotsTime();
95 CPPUNIT_ASSERT_EQUAL(6,(int)hs.size());
96 const double expected1[]={0.2,0.7,1.2,1.35,1.7,2.7};
98 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],hs[i],1e-12);
99 int meshId,arrId,arrIdInField,fieldId;
100 dt.getIdsOnTimeRight(0.2,meshId,arrId,arrIdInField,fieldId);
101 CPPUNIT_ASSERT_EQUAL(0,meshId);
102 CPPUNIT_ASSERT_EQUAL(0,arrId);
103 CPPUNIT_ASSERT_EQUAL(0,arrIdInField);
104 CPPUNIT_ASSERT_EQUAL(0,fieldId);
106 dt.getIdsOnTimeRight(0.7,meshId,arrId,arrIdInField,fieldId);
107 CPPUNIT_ASSERT_EQUAL(0,meshId);
108 CPPUNIT_ASSERT_EQUAL(1,arrId);
109 CPPUNIT_ASSERT_EQUAL(0,arrIdInField);
110 CPPUNIT_ASSERT_EQUAL(1,fieldId);
112 dt.getIdsOnTimeLeft(1.2,meshId,arrId,arrIdInField,fieldId);//**** WARNING left here
113 CPPUNIT_ASSERT_EQUAL(0,meshId);
114 CPPUNIT_ASSERT_EQUAL(2,arrId);
115 CPPUNIT_ASSERT_EQUAL(1,arrIdInField);
116 CPPUNIT_ASSERT_EQUAL(1,fieldId);
118 dt.getIdsOnTimeRight(1.2,meshId,arrId,arrIdInField,fieldId);//**** WARNING right again here
119 CPPUNIT_ASSERT_EQUAL(1,meshId);
120 CPPUNIT_ASSERT_EQUAL(3,arrId);
121 CPPUNIT_ASSERT_EQUAL(0,arrIdInField);
122 CPPUNIT_ASSERT_EQUAL(2,fieldId);
124 dt.getIdsOnTimeRight(1.35,meshId,arrId,arrIdInField,fieldId);
125 CPPUNIT_ASSERT_EQUAL(1,meshId);
126 CPPUNIT_ASSERT_EQUAL(3,arrId);
127 CPPUNIT_ASSERT_EQUAL(0,arrIdInField);
128 CPPUNIT_ASSERT_EQUAL(2,fieldId);
130 dt.getIdsOnTimeRight(1.7,meshId,arrId,arrIdInField,fieldId);
131 CPPUNIT_ASSERT_EQUAL(0,meshId);
132 CPPUNIT_ASSERT_EQUAL(3,arrId);
133 CPPUNIT_ASSERT_EQUAL(0,arrIdInField);
134 CPPUNIT_ASSERT_EQUAL(3,fieldId);
136 dt.getIdsOnTimeRight(2.7,meshId,arrId,arrIdInField,fieldId);
137 CPPUNIT_ASSERT_EQUAL(1,meshId);
138 CPPUNIT_ASSERT_EQUAL(4,arrId);
139 CPPUNIT_ASSERT_EQUAL(0,arrIdInField);
140 CPPUNIT_ASSERT_EQUAL(4,fieldId);
142 MEDCouplingDefinitionTime dt2;
143 CPPUNIT_ASSERT(!dt2.isEqual(dt));
145 dt2.assign(dt);//to check memory management
146 CPPUNIT_ASSERT(dt2.isEqual(dt));
148 MEDCouplingDefinitionTime dt3;
149 std::vector<int> tmp1;
150 std::vector<double> tmp2;
151 CPPUNIT_ASSERT(!dt2.isEqual(dt3));
152 dt2.getTinySerializationInformation(tmp1,tmp2);
153 dt3.unserialize(tmp1,tmp2);
154 CPPUNIT_ASSERT(dt2.isEqual(dt3));
156 for(std::vector<MEDCouplingFieldDouble *>::iterator it=fs.begin();it!=fs.end();it++)
161 void MEDCouplingBasicsTest4::testDAICheckAndPreparePermutation1()
163 const int vals1[]={9,10,0,6,4,11,3,7};
164 const int expect1[]={5,6,0,3,2,7,1,4};
165 const int vals2[]={9,10,0,6,10,11,3,7};
166 DataArrayInt *da=DataArrayInt::New();
168 std::copy(vals1,vals1+8,da->getPointer());
169 DataArrayInt *da2=da->checkAndPreparePermutation();
170 CPPUNIT_ASSERT_EQUAL(8,da2->getNumberOfTuples());
171 CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
173 CPPUNIT_ASSERT_EQUAL(expect1[i],da2->getIJ(i,0));
177 da=DataArrayInt::New();
180 da2=da->checkAndPreparePermutation();
181 CPPUNIT_ASSERT_EQUAL(8,da2->getNumberOfTuples());
182 CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
183 CPPUNIT_ASSERT(da2->isIdentity());
187 da=DataArrayInt::New();
189 std::copy(vals2,vals2+8,da->getPointer());
190 CPPUNIT_ASSERT_THROW(da->checkAndPreparePermutation(),INTERP_KERNEL::Exception);
194 void MEDCouplingBasicsTest4::testDAIChangeSurjectiveFormat1()
196 const int vals1[8]={0,3,2,3,2,2,1,2};
197 const int expected1[5]={0,1,2,6,8};
198 const int expected2[8]={0, 6, 2,4,5,7, 1,3};
199 DataArrayInt *da=DataArrayInt::New();
201 std::copy(vals1,vals1+8,da->getPointer());
203 DataArrayInt *da2,*da2I;
204 da->changeSurjectiveFormat(4,da2,da2I);
205 CPPUNIT_ASSERT_EQUAL(5,da2I->getNumberOfTuples());
206 CPPUNIT_ASSERT_EQUAL(8,da2->getNumberOfTuples());
207 CPPUNIT_ASSERT(std::equal(expected1,expected1+5,da2I->getConstPointer()));
208 CPPUNIT_ASSERT(std::equal(expected2,expected2+8,da2->getConstPointer()));
212 CPPUNIT_ASSERT_THROW(da->changeSurjectiveFormat(3,da2,da2I),INTERP_KERNEL::Exception);
217 void MEDCouplingBasicsTest4::testUMeshGetCellIdsLyingOnNodes1()
219 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
220 const int nodeIds1[5]={1,2,3,4,6};
221 const int nodeIds2[2]={6,7};
222 DataArrayInt *da=m->getCellIdsLyingOnNodes(nodeIds1,nodeIds1+5,true);
223 CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfTuples());
224 CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfComponents());
225 CPPUNIT_ASSERT_EQUAL(1,da->getIJ(0,0));
227 da=m->getCellIdsLyingOnNodes(nodeIds2,nodeIds2+2,false);
228 CPPUNIT_ASSERT_EQUAL(2,da->getNumberOfTuples());
229 CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfComponents());
230 CPPUNIT_ASSERT_EQUAL(3,da->getIJ(0,0));
231 CPPUNIT_ASSERT_EQUAL(4,da->getIJ(1,0));
237 void MEDCouplingBasicsTest4::testUMeshFindCellIdsOnBoundary1()
239 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
240 DataArrayInt *da5=m->findCellIdsOnBoundary();
241 CPPUNIT_ASSERT_EQUAL(5,da5->getNumberOfTuples());
242 CPPUNIT_ASSERT(da5->isIdentity());
248 void MEDCouplingBasicsTest4::testMeshSetTime1()
250 MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
251 MEDCouplingUMesh *m2=build3DSurfTargetMesh_1();
253 CPPUNIT_ASSERT(m1->isEqual(m2,1e-12));
254 m1->setTime(3.14,6,7);
256 double tmp3=m1->getTime(tmp1,tmp2);
257 CPPUNIT_ASSERT_EQUAL(6,tmp1);
258 CPPUNIT_ASSERT_EQUAL(7,tmp2);
259 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.14,tmp3,1e-12);
260 CPPUNIT_ASSERT(!m1->isEqual(m2,1e-12));
261 m2->setTime(3.14,6,7);
262 CPPUNIT_ASSERT(m1->isEqual(m2,1e-12));
263 m1->setTimeUnit("ms");
264 CPPUNIT_ASSERT(std::string(m1->getTimeUnit())=="ms");
265 m1->setTimeUnit("us");
266 CPPUNIT_ASSERT(std::string(m1->getTimeUnit())=="us");
267 CPPUNIT_ASSERT(!m1->isEqual(m2,1e-12));
268 m2->setTimeUnit("us");
269 CPPUNIT_ASSERT(m1->isEqual(m2,1e-12));
270 m2->setTime(3.14,6,8);
271 CPPUNIT_ASSERT(!m1->isEqual(m2,1e-12));
272 m2->setTime(3.14,7,7);
273 CPPUNIT_ASSERT(!m1->isEqual(m2,1e-12));
274 m2->setTime(3.15,6,7);
275 CPPUNIT_ASSERT(!m1->isEqual(m2,1e-12));
277 m1->setTime(10.34,55,12);
278 MEDCouplingUMesh *m3=(MEDCouplingUMesh *)m1->deepCpy();
279 CPPUNIT_ASSERT(m1->isEqual(m3,1e-12));
280 tmp3=m3->getTime(tmp1,tmp2);
281 CPPUNIT_ASSERT_EQUAL(55,tmp1);
282 CPPUNIT_ASSERT_EQUAL(12,tmp2);
283 CPPUNIT_ASSERT_DOUBLES_EQUAL(10.34,tmp3,1e-12);
289 const double coo1[4]={0.,1.,2.,3.5};
290 DataArrayDouble *a=DataArrayDouble::New();
292 std::copy(coo1,coo1+4,a->getPointer());
293 MEDCouplingCMesh *b=MEDCouplingCMesh::New();
297 b->setTime(5.67,8,100);
298 tmp3=b->getTime(tmp1,tmp2);
299 CPPUNIT_ASSERT_EQUAL(8,tmp1);
300 CPPUNIT_ASSERT_EQUAL(100,tmp2);
301 CPPUNIT_ASSERT_DOUBLES_EQUAL(5.67,tmp3,1e-12);
302 MEDCouplingCMesh *c=(MEDCouplingCMesh *)b->deepCpy();
303 CPPUNIT_ASSERT(c->isEqual(b,1e-12));
304 tmp3=c->getTime(tmp1,tmp2);
305 CPPUNIT_ASSERT_EQUAL(8,tmp1);
306 CPPUNIT_ASSERT_EQUAL(100,tmp2);
307 CPPUNIT_ASSERT_DOUBLES_EQUAL(5.67,tmp3,1e-12);
312 void MEDCouplingBasicsTest4::testApplyFuncTwo1()
314 MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
315 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
318 const double vals[15]={1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.,5.,15.,25.};
319 DataArrayDouble *da=DataArrayDouble::New();
321 std::copy(vals,vals+15,da->getPointer());
324 CPPUNIT_ASSERT_THROW(da->applyFunc2(1,"y+z"),INTERP_KERNEL::Exception);
325 da->setInfoOnComponent(0,"x [m]");
326 da->setInfoOnComponent(1,"y [mm]");
327 da->setInfoOnComponent(2,"z [km]");
329 CPPUNIT_ASSERT_THROW(da->applyFunc2(1,"x+y+zz+zzz"),INTERP_KERNEL::Exception);
330 CPPUNIT_ASSERT_THROW(da->applyFunc2(1,"toto(x+y)"),INTERP_KERNEL::Exception);
331 CPPUNIT_ASSERT_THROW(da->applyFunc2(1,"x/0"),INTERP_KERNEL::Exception);
333 DataArrayDouble *da2=da->applyFunc2(1,"y+z");
334 CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
335 CPPUNIT_ASSERT_EQUAL(5,da2->getNumberOfTuples());
336 const double expected1[5]={32.,34.,36.,38.,40.};
338 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da2->getIJ(0,i),1e-12);
340 da2=da->applyFunc(1,"y+z");
341 const double expected2[5]={12.,14.,16.,18.,20.};
343 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],da2->getIJ(0,i),1e-12);
346 CPPUNIT_ASSERT_EQUAL(3,f1->getNumberOfComponents());
347 CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
348 f1->applyFunc2(1,"y+z");
349 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
350 CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
352 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getArray()->getIJ(0,i),1e-12);
359 void MEDCouplingBasicsTest4::testApplyFuncThree1()
361 MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
362 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
365 const double vals[15]={1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.,5.,15.,25.};
366 DataArrayDouble *da=DataArrayDouble::New();
368 std::copy(vals,vals+15,da->getPointer());
371 std::vector<std::string> vs(3);
372 vs[0]="x"; vs[1]="Y"; vs[2]="z";
373 CPPUNIT_ASSERT_THROW(da->applyFunc3(1,vs,"y+z"),INTERP_KERNEL::Exception);
374 CPPUNIT_ASSERT_THROW(da->applyFunc3(1,vs,"x+Y+z+zz+zzz"),INTERP_KERNEL::Exception);
375 CPPUNIT_ASSERT_THROW(da->applyFunc3(1,vs,"x/0."),INTERP_KERNEL::Exception);
377 DataArrayDouble *da2=da->applyFunc3(1,vs,"y+z");
378 const double expected1[5]={32.,34.,36.,38.,40.};
380 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da2->getIJ(0,i),1e-12);
382 std::vector<std::string> vs2(4); vs2[0]="x"; vs2[1]="y"; vs2[2]="z"; vs2[3]="a";
383 CPPUNIT_ASSERT_THROW(da->applyFunc3(1,vs2,"x+a"),INTERP_KERNEL::Exception);
385 CPPUNIT_ASSERT_EQUAL(3,f1->getNumberOfComponents());
386 CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
387 f1->applyFunc3(1,vs,"y+z");
388 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
389 CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
391 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getArray()->getIJ(0,i),1e-12);
398 void MEDCouplingBasicsTest4::testFillFromAnalyticTwo1()
400 MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
401 m1->setTime(3.4,5,6); m1->setTimeUnit("us");
403 CPPUNIT_ASSERT_THROW(m1->fillFromAnalytic2(ON_NODES,1,"y+z"),INTERP_KERNEL::Exception);
404 m1->getCoords()->setInfoOnComponent(0,"x [m]");
405 m1->getCoords()->setInfoOnComponent(1,"y");
406 m1->getCoords()->setInfoOnComponent(2,"z");
407 MEDCouplingFieldDouble *f1=m1->fillFromAnalytic2(ON_NODES,1,"y+z");
408 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.4,f1->getTime(a,b),1.e-14);
409 CPPUNIT_ASSERT_EQUAL(5,a); CPPUNIT_ASSERT_EQUAL(6,b);
410 CPPUNIT_ASSERT_EQUAL(std::string(f1->getTimeUnit()),std::string("us"));
411 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
412 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
413 const double expected1[9]={0.2, 0.7, 1.2, 0.7, 1.2, 1.7, 1.2, 1.7, 2.2};
415 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getArray()->getIJ(0,i),1e-12);
420 void MEDCouplingBasicsTest4::testFillFromAnalyticThree1()
422 MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
423 m1->setTime(3.4,5,6); m1->setTimeUnit("us");
425 std::vector<std::string> vs(3);
426 vs[0]="x"; vs[1]="Y"; vs[2]="z";
427 CPPUNIT_ASSERT_THROW(m1->fillFromAnalytic3(ON_NODES,1,vs,"y+z"),INTERP_KERNEL::Exception);
429 MEDCouplingFieldDouble *f1=m1->fillFromAnalytic3(ON_NODES,1,vs,"y+z");
430 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.4,f1->getTime(a,b),1.e-14);
431 CPPUNIT_ASSERT_EQUAL(5,a); CPPUNIT_ASSERT_EQUAL(6,b);
432 CPPUNIT_ASSERT_EQUAL(std::string(f1->getTimeUnit()),std::string("us"));
433 CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
434 CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
435 const double expected1[9]={0.2, 0.7, 1.2, 0.7, 1.2, 1.7, 1.2, 1.7, 2.2};
437 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getArray()->getIJ(0,i),1e-12);
442 void MEDCouplingBasicsTest4::testDAUnitVar1()
444 DataArrayDouble *da=DataArrayDouble::New();
446 da->setInfoOnComponent(0,"XPS [m]");
448 st1=da->getVarOnComponent(0);
449 CPPUNIT_ASSERT(st1=="XPS");
450 st2=da->getUnitOnComponent(0);
451 CPPUNIT_ASSERT(st2=="m");
453 da->setInfoOnComponent(0,"XPS [m]");
454 st1=da->getVarOnComponent(0);
455 CPPUNIT_ASSERT(st1=="XPS");
456 st2=da->getUnitOnComponent(0);
457 CPPUNIT_ASSERT(st2=="m");
459 da->setInfoOnComponent(0,"XPP [m]");
460 st1=da->getVarOnComponent(0);
461 CPPUNIT_ASSERT(st1=="XPP");
462 st2=da->getUnitOnComponent(0);
463 CPPUNIT_ASSERT(st2=="m");
465 da->setInfoOnComponent(0,"XPP kdep kefer [ m ]");
466 st1=da->getVarOnComponent(0);
467 CPPUNIT_ASSERT(st1=="XPP kdep kefer");
468 st2=da->getUnitOnComponent(0);
469 CPPUNIT_ASSERT(st2==" m ");
471 da->setInfoOnComponent(0," XPP k[ dep k]efer [ m^ 2/s^3*kJ ]");
472 st1=da->getVarOnComponent(0);
473 CPPUNIT_ASSERT(st1==" XPP k[ dep k]efer");
474 st2=da->getUnitOnComponent(0);
475 CPPUNIT_ASSERT(st2==" m^ 2/s^3*kJ ");
477 da->setInfoOnComponent(0," XPP kefer ");
478 st1=da->getVarOnComponent(0);
479 CPPUNIT_ASSERT(st1==" XPP kefer ");
480 st2=da->getUnitOnComponent(0);
481 CPPUNIT_ASSERT(st2=="");
483 da->setInfoOnComponent(0,"temperature( bof)");
484 st1=da->getVarOnComponent(0);
485 CPPUNIT_ASSERT(st1=="temperature( bof)");
486 st2=da->getUnitOnComponent(0);
487 CPPUNIT_ASSERT(st2=="");
489 da->setInfoOnComponent(0,"kkk [m]");
490 da->setInfoOnComponent(1,"ppp [m^2/kJ]");
491 da->setInfoOnComponent(2,"abcde [MW/s]");
493 std::vector<std::string> vs;
494 vs=da->getVarsOnComponent();
495 CPPUNIT_ASSERT_EQUAL(3,(int)vs.size());
496 CPPUNIT_ASSERT(vs[0]=="kkk");
497 CPPUNIT_ASSERT(vs[1]=="ppp");
498 CPPUNIT_ASSERT(vs[2]=="abcde");
499 vs=da->getUnitsOnComponent();
500 CPPUNIT_ASSERT_EQUAL(3,(int)vs.size());
501 CPPUNIT_ASSERT(vs[0]=="m");
502 CPPUNIT_ASSERT(vs[1]=="m^2/kJ");
503 CPPUNIT_ASSERT(vs[2]=="MW/s");
508 void MEDCouplingBasicsTest4::testGaussCoordinates1()
510 //Testing 1D cell types
511 MEDCouplingUMesh *m1=build1DMultiTypes_1();
512 MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_GAUSS_PT,ONE_TIME);
514 std::vector<double> wg1(1); wg1[0]=0.3;
515 std::vector<double> gsCoo1(1); gsCoo1[0]=0.2;
516 std::vector<double> refCoo1(2); refCoo1[0]=-1.0; refCoo1[1]=1.0;
517 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_SEG2,refCoo1,gsCoo1,wg1);
518 std::vector<double> wg2(wg1);
519 std::vector<double> gsCoo2(1); gsCoo2[0]=0.2;
520 std::vector<double> refCoo2(3); refCoo2[0]=-1.0; refCoo2[1]=1.0; refCoo2[2]=0.0;
521 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_SEG3,refCoo2,gsCoo2,wg2);
523 DataArrayDouble *resToTest=f->getLocalizationOfDiscr();
524 CPPUNIT_ASSERT_EQUAL(3,resToTest->getNumberOfComponents());
525 CPPUNIT_ASSERT_EQUAL(2,resToTest->getNumberOfTuples());
526 const double expected1[6]={0.6,0.6,0.6, 0.6,0.6,0.6};
528 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],resToTest->getIJ(0,i),1e-14);
529 resToTest->decrRef();
533 //Testing 2D cell types
534 MEDCouplingUMesh *m2=build2DMultiTypes_1();
535 f=MEDCouplingFieldDouble::New(ON_GAUSS_PT,ONE_TIME);
537 std::vector<double> wg3(2); wg3[0]=0.3; wg3[1]=0.3;
538 const double tria3CooGauss[4]={ 0.1, 0.8, 0.2, 0.7 };
539 std::vector<double> gsCoo3(tria3CooGauss,tria3CooGauss+4);
540 const double tria3CooRef[6]={ 0.0, 0.0, 1.0 , 0.0, 0.0, 1.0 };
541 std::vector<double> refCoo3(tria3CooRef,tria3CooRef+6);
542 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI3,refCoo3,gsCoo3,wg3);
543 std::vector<double> wg4(3); wg4[0]=0.3; wg4[1]=0.3; wg4[2]=0.3;
544 const double tria6CooGauss[6]={ 0.3, 0.2, 0.2, 0.1, 0.2, 0.4 };
545 std::vector<double> gsCoo4(tria6CooGauss,tria6CooGauss+6);
546 const double tria6CooRef[12]={0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0, 0.5, 0.5, 0.0, 0.5};
547 std::vector<double> refCoo4(tria6CooRef,tria6CooRef+12);
548 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI6,refCoo4,gsCoo4,wg4);
549 std::vector<double> wg5(4); wg5[0]=0.3; wg5[1]=0.3; wg5[2]=0.3; wg5[3]=0.3;
550 const double quad4CooGauss[8]={ 0.3, 0.2, 0.2, 0.1, 0.2, 0.4, 0.15, 0.27 };
551 std::vector<double> gsCoo5(quad4CooGauss,quad4CooGauss+8);
552 const double quad4CooRef[8]={-1.0, 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0};
553 std::vector<double> refCoo5(quad4CooRef,quad4CooRef+8);
554 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_QUAD4,refCoo5,gsCoo5,wg5);
555 std::vector<double> wg6(4); wg6[0]=0.3; wg6[1]=0.3; wg6[2]=0.3; wg6[3]=0.3;
556 const double quad8CooGauss[8]={ 0.34, 0.16, 0.21, 0.3, 0.23, 0.4, 0.14, 0.37 };
557 std::vector<double> gsCoo6(quad8CooGauss,quad8CooGauss+8);
558 const double quad8CooRef[16]={ -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 0.0, -1.0, 1.0, 0.0, 0.0, 1.0, -1.0, 0.0};
559 std::vector<double> refCoo6(quad8CooRef,quad8CooRef+16);
560 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_QUAD8,refCoo6,gsCoo6,wg6);
562 resToTest=f->getLocalizationOfDiscr();
563 CPPUNIT_ASSERT_EQUAL(3,resToTest->getNumberOfComponents());
564 CPPUNIT_ASSERT_EQUAL(13,resToTest->getNumberOfTuples());//2+3+4+4 gauss points for resp TRI3,TRI6,QUAD4,QUAD8
565 const double expected2[39]={5.1,1.55,0.0, 4.7,1.65,0.0, //TRI3
566 2.32,1.52,0.0, 1.6,1.32,0.0, 3.52,1.26,0.0,//TRI6
567 2.6,1.6,0.0, 2.4,1.8,0.0, 2.4,1.2,0.0, 2.3,1.46,0.0,//QUAD4
568 2.32,2.68,0.0, 2.6,2.42,0.0, 2.8,2.46,0.0, 2.74,2.28,0.0 };//QUAD8
569 for(int i=0;i<39;i++)
570 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],resToTest->getIJ(0,i),1e-14);
571 resToTest->decrRef();
575 //Testing 3D cell types
576 MEDCouplingUMesh *m3=build3DMultiTypes_1();
577 f=MEDCouplingFieldDouble::New(ON_GAUSS_PT,ONE_TIME);
580 std::vector<double> wg7(1); wg7[0]=0.3;
581 const double tetra4CooGauss[3]={0.34, 0.16, 0.21};
582 std::vector<double> gsCoo7(tetra4CooGauss,tetra4CooGauss+3);
583 const double tetra4CooRef[12]={0.0,1.0,0.0, 0.0,0.0,1.0, 0.0,0.0,0.0, 1.0,0.0,0.0};
584 std::vector<double> refCoo7(tetra4CooRef,tetra4CooRef+12);
585 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TETRA4,refCoo7,gsCoo7,wg7);
586 std::vector<double> wg8(1); wg8[0]=0.3;
587 const double tetra10CooGauss[3]={0.2, 0.3, 0.1};
588 std::vector<double> gsCoo8(tetra10CooGauss,tetra10CooGauss+3);
589 const double tetra10CooRef[30]={0.0,1.0,0.0, 0.0,0.0,0.0, 0.0,0.0,1.0, 1.0,0.0,0.0, 0.0,0.5,0.0, 0.0,0.0,0.5, 0.0,0.5,0.5, 0.5,0.5,0.0, 0.5,0.0,0.0, 0.5,0.0,0.5};
590 std::vector<double> refCoo8(tetra10CooRef,tetra10CooRef+30);
591 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TETRA10,refCoo8,gsCoo8,wg8);
592 std::vector<double> wg9(1); wg9[0]=0.3;
593 const double pyra5CooGauss[3]={0.2, 0.3, 0.1};
594 std::vector<double> gsCoo9(pyra5CooGauss,pyra5CooGauss+3);
595 const double pyra5CooRef[15]={1.0,0.0,0.0, 0.0,1.0,0.0, -1.0,0.0,0.0, 0.0,-1.0,0.0, 0.0,0.0,1.0};
596 std::vector<double> refCoo9(pyra5CooRef,pyra5CooRef+15);
597 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_PYRA5,refCoo9,gsCoo9,wg9);
598 std::vector<double> wg10(1); wg10[0]=0.3;
599 const double pyra13CooGauss[3]={0.1, 0.2, 0.7};
600 std::vector<double> gsCoo10(pyra13CooGauss,pyra13CooGauss+3);
601 const double pyra13CooRef[39]={1.0,0.0,0.0, 0.0,1.0,0.0,-1.0,0.0,0.0,0.0,-1.0,0.0,0.0,0.0,1.0,0.5,0.5,0.0,-0.5,0.5,0.0,-0.5,-0.5,0.0,0.5,-0.5,0.0,0.5,0.0,0.5,0.0,0.5,0.5,-0.5,0.0,0.5,0.0,-0.5,0.5};
602 std::vector<double> refCoo10(pyra13CooRef,pyra13CooRef+39);
603 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_PYRA13,refCoo10,gsCoo10,wg10);
604 std::vector<double> wg11(1); wg11[0]=0.3;
605 const double penta6CooGauss[3]={0.2, 0.3, 0.1};
606 std::vector<double> gsCoo11(penta6CooGauss,penta6CooGauss+3);
607 const double penta6CooRef[18]={-1.0,1.0,0.0,-1.0,-0.0,1.0,-1.0,0.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0};
608 std::vector<double> refCoo11(penta6CooRef,penta6CooRef+18);
609 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_PENTA6,refCoo11,gsCoo11,wg11);
610 std::vector<double> wg12(1); wg12[0]=0.3;
611 const double penta15CooGauss[3]={0.2, 0.3,0.15};
612 std::vector<double> gsCoo12(penta15CooGauss,penta15CooGauss+3);
613 const double penta15CooRef[45]={-1.0,1.0,0.0,-1.0,0.0,1.0,-1.0,0.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,-1.0,0.5,0.5,-1.0,0.0,0.5,-1.0,0.5,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.5,0.5,1.0,0.0, 0.5,1.0,0.5,0.0};
614 std::vector<double> refCoo12(penta15CooRef,penta15CooRef+45);
615 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_PENTA15,refCoo12,gsCoo12,wg12);
616 std::vector<double> wg13(1); wg13[0]=0.3;
617 const double hexa8CooGauss[3]={0.2,0.3,0.15};
618 std::vector<double> gsCoo13(hexa8CooGauss,hexa8CooGauss+3);
619 const double hexa8CooRef[24]={-1.0,-1.0,-1.0,1.0,-1.0,-1.0,1.0,1.0,-1.0,-1.0,1.0,-1.0,-1.0,-1.0,1.0,1.0,-1.0,1.0,1.0,1.0,1.0,-1.0,1.0,1.0};
620 std::vector<double> refCoo13(hexa8CooRef,hexa8CooRef+24);
621 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_HEXA8,refCoo13,gsCoo13,wg13);
622 std::vector<double> wg14(1); wg14[0]=0.3;
623 const double hexa20CooGauss[3]={0.11,0.3,0.55};
624 std::vector<double> gsCoo14(hexa20CooGauss,hexa20CooGauss+3);
625 const double hexa20CooRef[60]={-1.0,-1.0,-1.0,1.0,-1.0,-1.0,1.0,1.0,-1.0,-1.0,1.0,-1.0,-1.0,-1.0,1.0,1.0,-1.0,1.0,1.0,1.0,1.0,-1.0,1.0,1.0,0.0,-1.0,-1.0,1.0,0.0,-1.0,0.0,1.0,-1.0,-1.0,0.0,-1.0,-1.0,-1.0,0.0,1.0,-1.0,0.0,1.0,1.0,0.0,-1.0,1.0,0.0,0.0,-1.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,-1.0,0.0,1.0};
626 std::vector<double> refCoo14(hexa20CooRef,hexa20CooRef+60);
627 f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_HEXA20,refCoo14,gsCoo14,wg14);
629 resToTest=f->getLocalizationOfDiscr();
630 CPPUNIT_ASSERT_EQUAL(3,resToTest->getNumberOfComponents());
631 CPPUNIT_ASSERT_EQUAL(8,resToTest->getNumberOfTuples());//2+3+4+4 gauss points for resp TRI3,TRI6,QUAD4,QUAD8
632 const double expected3[24]={1.312,3.15,1.02, 0.56,3.3,0.6, 2.18,1.1,0.2, 1.18,1.54,0.98, 1.56,0.3,3.6, 1.613,0.801,4.374, 2.6,2.4,2.3, 2.31232,2.3933985,1.553255};
633 for(int i=0;i<24;i++)
634 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],resToTest->getIJ(0,i),1e-14);
635 resToTest->decrRef();
642 * Not activated test ! To be implemented !
644 void MEDCouplingBasicsTest4::testQ1Localization1()
646 MEDCouplingUMesh *m=buildHexa8Mesh_1();
647 MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
648 DataArrayDouble *da=DataArrayDouble::New();
649 const double vals1[27]={1.0,3.0,4.0,1.0,3.0,4.0,3.0,2.0,5.0,1.0,3.0,4.0,1.0,3.0,4.0,3.0,2.0,5.0,1.0,3.0,4.0,1.0,3.0,4.0,3.0,2.0,5.0};
651 std::copy(vals1,vals1+27,da->getPointer());
656 const double point1[3]={0.25,0.75,0.25};
657 //const double points1[6]={0.25,0.75,0.25,1.0,1.0,1.0};
659 f->getValueOn(point1,res1);
665 void MEDCouplingBasicsTest4::testP2Localization1()
667 MEDCouplingUMesh *m=MEDCouplingUMesh::New("testP2",2);
668 const double coords[12]={0.,2.,3.5,0.,4.5,1.5,1.2,0.32,3.4,1.,2.1,2.4};
669 const int conn[6]={0,1,2,3,4,5};
670 DataArrayDouble *coo=DataArrayDouble::New();
672 std::copy(coords,coords+12,coo->getPointer());
676 m->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,conn);
677 m->finishInsertingCells();
679 MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
681 DataArrayDouble *da=DataArrayDouble::New();
683 const double vals1[18]={1.2,2.3,3.4, 2.2,3.3,4.4, 3.2,4.3,5.4, 4.2,5.3,6.4, 5.2,6.3,7.4, 6.2,7.3,8.4};
684 std::copy(vals1,vals1+18,da->getPointer());
688 const double loc[2]={2.27,1.3};
689 DataArrayDouble *locs=f->getValueOnMulti(loc,1);
690 const double expected1[3]={6.0921164547752236, 7.1921164547752232, 8.2921164547752255};
692 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],locs->getIJ(0,i),1e-12);
699 void MEDCouplingBasicsTest4::testP2Localization2()
701 MEDCouplingUMesh *m=MEDCouplingUMesh::New("testP2_2",3);
702 const double coords[30]={0.33312787792955395, -0.35155740179580952, -0.03567564825034563, 1.307146326477638, -0.57234557776250305, -0.08608044208272235, 0.5551834466499993, 0.62324964668794192, -0.014638951108536295, 0.37761817224442129, -0.38324019806913578, 0.96283164472856886, 0.79494856035658679, -0.40628057809270046, 0.0021004190225864614, 1.023740446371799, 0.07665912970471335, -0.072889657161871096, 0.54564584619517376, 0.11132872093429744, 0.039647326652013051, 0.27164784387819052, -0.42018012100866675, 0.46563376500745146, 0.89501965094896418, -0.56148455362735061, 0.43337469695473035, 0.49118025152924394, 0.093884938060727313, 0.47216346905220891};
703 const int conn[10]={0,1,2,3,4,5,6,7,8,9};
704 DataArrayDouble *coo=DataArrayDouble::New();
706 std::copy(coords,coords+30,coo->getPointer());
710 m->insertNextCell(INTERP_KERNEL::NORM_TETRA10,10,conn);
711 m->finishInsertingCells();
713 MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
715 DataArrayDouble *da=DataArrayDouble::New();
717 const double vals1[10]={1.1,2.1,3.1,4.1,5.2,6.2,7.2,8.2,9.2,10.2};
718 std::copy(vals1,vals1+10,da->getPointer());
722 const double loc[3]={0.64637931739890486, -0.16185896817550552, 0.22678966365273748};
723 DataArrayDouble *locs=f->getValueOnMulti(loc,1);
724 const double expected1[1]={10.0844021968047};
726 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],locs->getIJ(0,i),1e-12);
733 void MEDCouplingBasicsTest4::testGetValueOn2()
735 MEDCouplingUMesh *m=build2DTargetMesh_1();
736 MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
738 DataArrayDouble *arr=DataArrayDouble::New();
739 int nbOfCells=m->getNumberOfCells();
740 arr->alloc(nbOfCells,3);
743 const double values1[15]={7.,107.,10007.,8.,108.,10008.,9.,109.,10009.,10.,110.,10010.,11.,111.,10011.};
744 std::copy(values1,values1+15,arr->getPointer());
745 const double loc[10]={-0.05,-0.05, 0.55,-0.25, 0.55,0.15, -0.05,0.45, 0.45,0.45};
747 DataArrayDouble *locs=f->getValueOnMulti(loc,5);
748 CPPUNIT_ASSERT_EQUAL(5,locs->getNumberOfTuples());
749 CPPUNIT_ASSERT_EQUAL(3,locs->getNumberOfComponents());
750 for(int j=0;j<15;j++)
751 CPPUNIT_ASSERT_DOUBLES_EQUAL(values1[j],locs->getIJ(0,j),1e-12);
755 f=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
757 arr=DataArrayDouble::New();
758 int nbOfNodes=m->getNumberOfNodes();
759 arr->alloc(nbOfNodes,3);
762 const double values2[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.};
763 std::copy(values2,values2+27,arr->getPointer());
764 const double loc2[8]={0.5432,-0.2432, 0.5478,0.1528, 0.5432,-0.2432, 0.5432,-0.2432};
765 const double expected2[12]={9.0272, 109.0272, 10009.0272, 11.4124,111.4124,10011.4124, 9.0272, 109.0272, 10009.0272, 9.0272, 109.0272, 10009.0272};
767 locs=f->getValueOnMulti(loc2,4);
768 CPPUNIT_ASSERT_EQUAL(4,locs->getNumberOfTuples());
769 CPPUNIT_ASSERT_EQUAL(3,locs->getNumberOfComponents());
770 for(int i=0;i<12;i++)
771 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],locs->getIJ(0,i),1e-12);
778 void MEDCouplingBasicsTest4::testDAIGetIdsNotEqual1()
780 DataArrayInt *d=DataArrayInt::New();
781 const int vals1[10]={2,3,5,6,8,5,5,6,1,-5};
783 std::copy(vals1,vals1+10,d->getPointer());
784 DataArrayInt *d2=d->getIdsNotEqual(5);
785 CPPUNIT_ASSERT_EQUAL(7,d2->getNumberOfTuples());
786 CPPUNIT_ASSERT_EQUAL(1,d2->getNumberOfComponents());
787 const int expected1[7]={0,1,3,4,7,8,9};
789 CPPUNIT_ASSERT_EQUAL(expected1[i],d2->getIJ(0,i));
791 CPPUNIT_ASSERT_THROW(d->getIdsNotEqual(5),INTERP_KERNEL::Exception);
792 const int vals2[3]={-4,5,6};
793 std::vector<int> vals3(vals2,vals2+3);
795 DataArrayInt *d3=d->getIdsNotEqualList(&vals3[0],&vals3[0]+vals3.size());
796 CPPUNIT_ASSERT_EQUAL(5,d3->getNumberOfTuples());
797 CPPUNIT_ASSERT_EQUAL(1,d3->getNumberOfComponents());
798 const int expected2[5]={0,1,4,8,9};
800 CPPUNIT_ASSERT_EQUAL(expected2[i],d3->getIJ(0,i));
806 void MEDCouplingBasicsTest4::testDAIComputeOffsets1()
808 DataArrayInt *d=DataArrayInt::New();
809 const int vals1[6]={3,5,1,2,0,8};
810 const int expected1[6]={0,3,8,9,11,11};
812 std::copy(vals1,vals1+6,d->getPointer());
814 CPPUNIT_ASSERT_EQUAL(6,d->getNumberOfTuples());
815 CPPUNIT_ASSERT_EQUAL(1,d->getNumberOfComponents());
817 CPPUNIT_ASSERT_EQUAL(expected1[i],d->getIJ(0,i));
821 void MEDCouplingBasicsTest4::testUMeshHexagonPrism1()
823 const double coords[36]={
824 0.8660254037844386, 0.5, 0.0, 0.0, 1.0, 0.0, -0.8660254037844386, 0.5, 0.0, -0.8660254037844386, -0.5, 0.0, 0.0, -1.0, 0.0, 0.8660254037844386, -0.5, 0.0,
825 0.8660254037844386, 0.5, 2.0, 0.0, 1.0, 2.0, -0.8660254037844386, 0.5, 2.0, -0.8660254037844386, -0.5, 2.0, 0.0, -1.0, 2.0, 0.8660254037844386, -0.5, 2.0
827 const int conn[12]={1,2,3,4,5,0,7,8,9,10,11,6};
828 MEDCouplingUMesh *mesh=MEDCouplingUMesh::New("MyFirstHexagonalPrism",3);
829 DataArrayDouble *coo=DataArrayDouble::New();
831 std::copy(coords,coords+36,coo->getPointer());
832 mesh->setCoords(coo);
833 mesh->allocateCells(1);
834 mesh->insertNextCell(INTERP_KERNEL::NORM_HEXGP12,12,conn);
835 mesh->finishInsertingCells();
838 mesh->checkCoherency();
839 MEDCouplingFieldDouble *vols=mesh->getMeasureField(false);
840 CPPUNIT_ASSERT_EQUAL(1,vols->getNumberOfTuples());
841 CPPUNIT_ASSERT_EQUAL(1,vols->getNumberOfComponents());
842 CPPUNIT_ASSERT_DOUBLES_EQUAL(-5.196152422706632,vols->getIJ(0,0),1e-12);
843 DataArrayDouble *bary=mesh->getBarycenterAndOwner();
844 CPPUNIT_ASSERT_EQUAL(1,bary->getNumberOfTuples());
845 CPPUNIT_ASSERT_EQUAL(3,bary->getNumberOfComponents());
846 const double expected1[3]={0.,0.,1.};
848 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],bary->getIJ(0,i),1e-12);
849 DataArrayInt *d1=DataArrayInt::New();
850 DataArrayInt *d2=DataArrayInt::New();
851 DataArrayInt *d3=DataArrayInt::New();
852 DataArrayInt *d4=DataArrayInt::New();
853 MEDCouplingUMesh *m2=mesh->buildDescendingConnectivity(d1,d2,d3,d4);
854 CPPUNIT_ASSERT_EQUAL(8,m2->getNumberOfCells());
855 const int expected4[8][6]={{1,2,3,4,5,0},{7,6,11,10,9,8},{1,7,8,2},{2,8,9,3},{3,9,10,4},{4,10,11,5},{5,11,6,0},{0,6,7,1}};
856 const INTERP_KERNEL::NormalizedCellType expected2[8]={INTERP_KERNEL::NORM_POLYGON, INTERP_KERNEL::NORM_POLYGON, INTERP_KERNEL::NORM_QUAD4, INTERP_KERNEL::NORM_QUAD4, INTERP_KERNEL::NORM_QUAD4, INTERP_KERNEL::NORM_QUAD4, INTERP_KERNEL::NORM_QUAD4, INTERP_KERNEL::NORM_QUAD4};
857 const int expected3[8]={6,6,4,4,4,4,4,4};
860 CPPUNIT_ASSERT(m2->getTypeOfCell(i)==expected2[i]);
862 m2->getNodeIdsOfCell(i,v);
863 CPPUNIT_ASSERT((int)v.size()==expected3[i]);
864 CPPUNIT_ASSERT(std::equal(expected4[i],expected4[i]+expected3[i],v.begin()));
872 mesh->convertAllToPoly();
873 CPPUNIT_ASSERT(INTERP_KERNEL::NORM_POLYHED==mesh->getTypeOfCell(0));
875 CPPUNIT_ASSERT(INTERP_KERNEL::NORM_HEXGP12==mesh->getTypeOfCell(0));
876 CPPUNIT_ASSERT_EQUAL(13,mesh->getMeshLength());
883 void MEDCouplingBasicsTest4::testDADCheckIsMonotonic()
885 DataArrayDouble *da=DataArrayDouble::New();
886 const double vals[4]={-1.,1.01,2.03,6.};
888 std::copy(vals,vals+4,da->getPointer());
889 CPPUNIT_ASSERT_THROW(da->isMonotonic(true, 1e-12),INTERP_KERNEL::Exception);
891 CPPUNIT_ASSERT(da->isMonotonic(true, 1e-12));
892 da->checkMonotonic(true, 1e-12);
894 CPPUNIT_ASSERT(!da->isMonotonic(true, 1e-12));
895 CPPUNIT_ASSERT_THROW(da->checkMonotonic(true, 1e-12),INTERP_KERNEL::Exception);
896 CPPUNIT_ASSERT_THROW(da->checkMonotonic(false, 1e-12),INTERP_KERNEL::Exception);
898 CPPUNIT_ASSERT(da->isMonotonic(true, 1e-12));
899 CPPUNIT_ASSERT(!da->isMonotonic(true, 1e-1));
903 void MEDCouplingBasicsTest4::testCheckCoherencyDeeper1()
905 MEDCouplingUMesh *m=build3DSourceMesh_1();
907 m->checkCoherency1();
908 m->getNodalConnectivity()->setIJ(8,0,-1);
910 CPPUNIT_ASSERT_THROW(m->checkCoherency1(),INTERP_KERNEL::Exception);
911 m->getNodalConnectivity()->setIJ(8,0,-6);
913 CPPUNIT_ASSERT_THROW(m->checkCoherency1(),INTERP_KERNEL::Exception);
914 m->getNodalConnectivity()->setIJ(8,0,9);//9>=NbOfNodes
916 CPPUNIT_ASSERT_THROW(m->checkCoherency1(),INTERP_KERNEL::Exception);
917 m->getNodalConnectivity()->setIJ(8,0,8);//OK
919 m->checkCoherency1();
920 const int elts[2]={1,5};
921 std::vector<int> eltsV(elts,elts+2);
922 m->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
924 m->checkCoherency1();
925 m->getNodalConnectivity()->setIJ(2,0,9);//9>=NbOfNodes
927 CPPUNIT_ASSERT_THROW(m->checkCoherency1(),INTERP_KERNEL::Exception);
928 m->getNodalConnectivity()->setIJ(2,0,-3);
930 CPPUNIT_ASSERT_THROW(m->checkCoherency1(),INTERP_KERNEL::Exception);
931 m->getNodalConnectivity()->setIJ(2,0,-1);
933 CPPUNIT_ASSERT_THROW(m->checkCoherency1(),INTERP_KERNEL::Exception);//Throw because cell#0 is not a polyhedron
934 m->getNodalConnectivity()->setIJ(2,0,4);
936 m->checkCoherency1();
937 m->getNodalConnectivity()->setIJ(7,0,-1);
939 m->checkCoherency1();//OK because we are in polyhedron connec
940 m->getNodalConnectivity()->setIJ(36,0,14);
942 CPPUNIT_ASSERT_THROW(m->checkCoherency1(),INTERP_KERNEL::Exception);//Throw beacause now cell 5 is a TETRA4 (14) so mimatch of number index and static type.
946 void MEDCouplingBasicsTest4::testUnPolyze2()
948 MEDCouplingUMesh *m=MEDCouplingUMesh::New("jjj",3);
949 DataArrayDouble *coo=DataArrayDouble::New();
957 const int conn[4]={0,1,2,3};
958 m->insertNextCell(INTERP_KERNEL::NORM_TETRA4,4,conn);
959 m->insertNextCell(INTERP_KERNEL::NORM_TETRA4,4,conn);
960 m->finishInsertingCells();
961 std::vector<const MEDCouplingUMesh *> ms(4,m);
962 MEDCouplingUMesh *m2=MEDCouplingUMesh::MergeUMeshesOnSameCoords(ms);
963 std::vector<int> temp(1,2);
964 m2->convertToPolyTypes(&temp[0],&temp[0]+temp.size());
966 CPPUNIT_ASSERT(INTERP_KERNEL::NORM_TETRA4==m2->getTypeOfCell(2));
967 CPPUNIT_ASSERT_EQUAL(40,m2->getMeshLength());
968 std::vector<int> temp2;
969 m2->getNodeIdsOfCell(2,temp2);
970 CPPUNIT_ASSERT(4==(int)temp2.size());
971 CPPUNIT_ASSERT(std::equal(conn,conn+4,temp2.begin()));
972 m2->checkCoherency1();
973 MEDCouplingMesh *m3=m2->deepCpy();
975 CPPUNIT_ASSERT(m3->isEqual(m2,1e-12));
981 void MEDCouplingBasicsTest4::testDACpyFrom1()
983 DataArrayDouble *d=DataArrayDouble::New();
988 d->setInfoOnComponent(0,"X [m]");
989 d->setInfoOnComponent(1,"Y [m]");
990 d->setInfoOnComponent(2,"Z [m]");
992 DataArrayDouble *d1=DataArrayDouble::New();
993 CPPUNIT_ASSERT(!d->isEqual(*d1,1e-12));
995 CPPUNIT_ASSERT(d->isEqual(*d1,1e-12));
997 CPPUNIT_ASSERT(d->isEqual(*d1,1e-12));
999 CPPUNIT_ASSERT(!d->isEqual(*d1,1e-12));
1001 CPPUNIT_ASSERT(d->isEqual(*d1,1e-12));
1003 DataArrayInt *d2=d->convertToIntArr();
1004 DataArrayInt *d4=DataArrayInt::New();
1005 CPPUNIT_ASSERT(!d2->isEqual(*d4));
1007 CPPUNIT_ASSERT(d2->isEqual(*d4));
1009 CPPUNIT_ASSERT(d2->isEqual(*d4));
1011 CPPUNIT_ASSERT(!d2->isEqual(*d4));
1013 CPPUNIT_ASSERT(d2->isEqual(*d4));
1021 void MEDCouplingBasicsTest4::testDAITransformWithIndArr1()
1023 const int tab1[4]={17,18,22,19};
1024 const int tab2[12]={0,1,1,3,3,0,1,3,2,2,3,0};
1025 const int expected[12]={17,18,18,19,19,17,18,19,22,22,19,17};
1026 DataArrayInt *d=DataArrayInt::New();
1028 std::copy(tab1,tab1+4,d->getPointer());
1029 DataArrayInt *d1=DataArrayInt::New();
1031 std::copy(tab2,tab2+12,d1->getPointer());
1033 d1->transformWithIndArr(d->getConstPointer(),d->getConstPointer()+d->getNbOfElems());
1034 CPPUNIT_ASSERT_EQUAL(12,d1->getNumberOfTuples());
1035 CPPUNIT_ASSERT_EQUAL(1,d1->getNumberOfComponents());
1036 for(int i=0;i<12;i++)
1037 CPPUNIT_ASSERT_EQUAL(expected[i],d1->getIJ(i,0));
1043 void MEDCouplingBasicsTest4::testDAIBuildPermArrPerLevel1()
1045 const int arr[12]={2,0,1,1,0,1,2,0,1,1,0,0};
1046 const int expected1[12]={10,0,5,6,1,7,11,2,8,9,3,4};
1047 DataArrayInt *da=DataArrayInt::New();
1049 std::copy(arr,arr+12,da->getPointer());
1050 DataArrayInt *da2=da->buildPermArrPerLevel();
1051 CPPUNIT_ASSERT_EQUAL(12,da2->getNumberOfTuples());
1052 CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
1053 for(int i=0;i<12;i++)
1054 CPPUNIT_ASSERT_EQUAL(expected1[i],da2->getIJ(i,0));
1059 void MEDCouplingBasicsTest4::testDAIOperations1()
1061 const int arr1[12]={-1,-2,4,7,3,2,6,6,4,3,0,1};
1062 DataArrayInt *da=DataArrayInt::New();
1064 std::copy(arr1,arr1+12,da->getPointer());
1065 DataArrayInt *da1=DataArrayInt::New();
1068 CPPUNIT_ASSERT_THROW(DataArrayInt::Add(da,da1),INTERP_KERNEL::Exception);//not same number of tuples/Components
1070 DataArrayInt *da2=DataArrayInt::Add(da,da1);
1071 CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfTuples());
1072 CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfComponents());
1073 const int expected1[12]={1,1,8,12,9,9,14,15,14,14,12,14};
1074 for(int i=0;i<12;i++)
1075 CPPUNIT_ASSERT_EQUAL(expected1[i],da2->getIJ(0,i));
1077 da1->substractEqual(da);
1078 const int expected2[12]={3,5,0,-2,3,5,2,3,6,8,12,12};
1079 for(int i=0;i<12;i++)
1080 CPPUNIT_ASSERT_EQUAL(expected2[i],da1->getIJ(0,i));
1081 da1->rearrange(1); da1->iota(2); da1->rearrange(3);
1083 for(int i=0;i<12;i++)
1084 CPPUNIT_ASSERT_EQUAL(expected1[i],da1->getIJ(0,i));
1085 da1->rearrange(1); da1->iota(2); da1->rearrange(3);
1086 da2=DataArrayInt::Multiply(da,da1);
1087 CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfTuples());
1088 CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfComponents());
1089 const int expected3[12]={-2,-6,16,35,18,14,48,54,40,33,0,13};
1090 for(int i=0;i<12;i++)
1091 CPPUNIT_ASSERT_EQUAL(expected3[i],da2->getIJ(0,i));
1093 da->divideEqual(da1);
1094 CPPUNIT_ASSERT_EQUAL(4,da->getNumberOfTuples());
1095 CPPUNIT_ASSERT_EQUAL(3,da->getNumberOfComponents());
1096 const int expected4[12]={0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0};
1097 for(int i=0;i<12;i++)
1098 CPPUNIT_ASSERT_EQUAL(expected4[i],da->getIJ(0,i));
1099 std::copy(arr1,arr1+12,da->getPointer());
1100 da1->multiplyEqual(da);
1101 CPPUNIT_ASSERT_EQUAL(4,da1->getNumberOfTuples());
1102 CPPUNIT_ASSERT_EQUAL(3,da1->getNumberOfComponents());
1103 for(int i=0;i<12;i++)
1104 CPPUNIT_ASSERT_EQUAL(expected3[i],da1->getIJ(0,i));
1105 da1->rearrange(1); da1->iota(2); da1->rearrange(3);
1106 da2=DataArrayInt::Divide(da,da1);
1107 CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfTuples());
1108 CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfComponents());
1109 for(int i=0;i<12;i++)
1110 CPPUNIT_ASSERT_EQUAL(expected4[i],da2->getIJ(0,i));
1113 CPPUNIT_ASSERT_EQUAL(4,da1->getNumberOfTuples());
1114 CPPUNIT_ASSERT_EQUAL(3,da1->getNumberOfComponents());
1115 const int expected5[12]={160,107,80,64,53,45,40,35,32,29,26,24};
1116 for(int i=0;i<12;i++)
1117 CPPUNIT_ASSERT_EQUAL(expected5[i],da1->getIJ(0,i));
1118 da1->applyDivideBy(2);
1119 CPPUNIT_ASSERT_EQUAL(4,da1->getNumberOfTuples());
1120 CPPUNIT_ASSERT_EQUAL(3,da1->getNumberOfComponents());
1121 const int expected6[12]={80,53,40,32,26,22,20,17,16,14,13,12};
1122 for(int i=0;i<12;i++)
1123 CPPUNIT_ASSERT_EQUAL(expected6[i],da1->getIJ(0,i));
1124 const int expected7[12]={3,4,5,4,5,1,6,3,2,0,6,5};
1125 da1->applyModulus(7);
1126 for(int i=0;i<12;i++)
1127 CPPUNIT_ASSERT_EQUAL(expected7[i],da1->getIJ(0,i));
1129 const int expected8[12]={3,3,3,3,3,1,3,3,0,0,3,3};
1130 da1->applyRModulus(3);
1131 for(int i=0;i<12;i++)
1132 CPPUNIT_ASSERT_EQUAL(expected8[i],da1->getIJ(0,i));
1138 void MEDCouplingBasicsTest4::testEmulateMEDMEMBDC1()
1140 MEDCouplingUMesh *m1=0;
1141 MEDCouplingUMesh *m=buildPointe_1(m1);
1142 DataArrayInt *da1=DataArrayInt::New();
1143 DataArrayInt *da2=DataArrayInt::New();
1144 DataArrayInt *da3=0;
1145 DataArrayInt *da4=0;
1146 DataArrayInt *da5=0;
1147 DataArrayInt *da0=0;
1148 MEDCouplingUMesh *m2=m->emulateMEDMEMBDC(m1,da1,da2,da3,da4,da5,da0);
1149 const int expected0[47]={0,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,31,36,37,32,33,34,35,38,39,40,41,42,43,44,45,46};
1150 const int expected1[6]={1,32,29,23,41,36};
1151 CPPUNIT_ASSERT_EQUAL(47,da0->getNumberOfTuples());
1152 CPPUNIT_ASSERT_EQUAL(1,da0->getNumberOfComponents());
1153 for(int i=0;i<47;i++)
1154 CPPUNIT_ASSERT_EQUAL(expected0[i],da0->getIJ(0,i));
1155 CPPUNIT_ASSERT_EQUAL(6,da5->getNumberOfTuples());
1156 CPPUNIT_ASSERT_EQUAL(1,da5->getNumberOfComponents());
1157 for(int i=0;i<6;i++)
1158 CPPUNIT_ASSERT_EQUAL(expected1[i],da5->getIJ(0,i));
1159 const int expected2[70]={0,1,2,3,4,0,5,6,7,4,8,9,1,7,10,11,12,13,14,5,15,16,17,8,18,19,20,10,21,22,23,2,13,24,25,21,16,26,27,12,19,28,29,15,22,30,31,18,36,26,28,30,24,37,32,33,34,35,38,36,39,40,41,42,37,38,43,44,45,46};
1160 CPPUNIT_ASSERT_EQUAL(70,da1->getNumberOfTuples());
1161 CPPUNIT_ASSERT_EQUAL(1,da1->getNumberOfComponents());
1162 for(int i=0;i<70;i++)
1163 CPPUNIT_ASSERT_EQUAL(expected2[i],da1->getIJ(0,i));
1164 const int expected3[17]={0,4,8,12,16,20,24,28,32,36,40,44,48,53,58,64,70};
1165 CPPUNIT_ASSERT_EQUAL(17,da2->getNumberOfTuples());
1166 CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
1167 for(int i=0;i<17;i++)
1168 CPPUNIT_ASSERT_EQUAL(expected3[i],da2->getIJ(0,i));
1169 const int expected4[48]={0,2,4,6,7,9,11,12,14,16,17,19,20,22,24,25,27,29,30,32,34,35,37,39,40,42,43,45,46,48,49,51,52,53,54,55,56,58,60,62,63,64,65,66,67,68,69,70};
1170 //const int expected4[48]={0,2,4,6,7,9,11,12,14,16,17,19,20,22,24,25,27,29,30,32,34,35,37,39,40,42,43,45,46,48,49,51,52,54,56,57,58,59,60,62,63,64,65,66,67,68,69,70};
1171 CPPUNIT_ASSERT_EQUAL(48,da4->getNumberOfTuples());
1172 CPPUNIT_ASSERT_EQUAL(1,da4->getNumberOfComponents());
1173 for(int i=0;i<48;i++)
1174 CPPUNIT_ASSERT_EQUAL(expected4[i],da4->getIJ(0,i));
1175 const int expected5[70]={0,1,0,3,0,7,0,1,2,1,4,1,2,3,2,5,2,3,6,3,4,9,4,8,4,5,10,5,9,5,6,11,6,10,6,7,8,7,11,7,8,12,8,9,12,9,10,12,10,11,12,11,13,13,13,13,12,14,13,15,14,15,14,14,14,14,15,15,15,15};
1176 CPPUNIT_ASSERT_EQUAL(70,da3->getNumberOfTuples());
1177 CPPUNIT_ASSERT_EQUAL(1,da3->getNumberOfComponents());
1178 for(int i=0;i<70;i++)
1179 CPPUNIT_ASSERT_EQUAL(expected5[i],da3->getIJ(0,i));
1193 void MEDCouplingBasicsTest4::testGetLevArrPerCellTypes1()
1195 MEDCouplingUMesh *m1=0;
1196 MEDCouplingUMesh *m=buildPointe_1(m1);
1198 DataArrayInt *d0=DataArrayInt::New();
1199 DataArrayInt *d1=DataArrayInt::New();
1200 DataArrayInt *d2=DataArrayInt::New();
1201 DataArrayInt *d3=DataArrayInt::New();
1202 m1=m->buildDescendingConnectivity(d0,d1,d2,d3);
1203 d0->decrRef(); d1->decrRef(); d2->decrRef(); d3->decrRef();
1204 INTERP_KERNEL::NormalizedCellType order[2]={INTERP_KERNEL::NORM_TRI3,INTERP_KERNEL::NORM_QUAD4};
1205 DataArrayInt *da1=0;
1206 DataArrayInt *da0=m1->getLevArrPerCellTypes(order,order+2,da1);
1207 const int expected0[47]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1};
1208 const int expected1[47]={0,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,31,36,37,32,33,34,35,38,39,40,41,42,43,44,45,46};
1209 CPPUNIT_ASSERT_EQUAL(47,da0->getNumberOfTuples());
1210 CPPUNIT_ASSERT_EQUAL(1,da0->getNumberOfComponents());
1211 for(int i=0;i<47;i++)
1212 CPPUNIT_ASSERT_EQUAL(expected0[i],da0->getIJ(0,i));
1213 CPPUNIT_ASSERT_EQUAL(2,da1->getNumberOfTuples());
1214 CPPUNIT_ASSERT_EQUAL(1,da1->getNumberOfComponents());
1215 CPPUNIT_ASSERT_EQUAL(36,da1->getIJ(0,0));//36 TRI3
1216 CPPUNIT_ASSERT_EQUAL(11,da1->getIJ(1,0));//11 QUAD4
1218 DataArrayInt *da2=da0->buildPermArrPerLevel();
1220 CPPUNIT_ASSERT_EQUAL(47,da2->getNumberOfTuples());
1221 CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
1222 for(int i=0;i<47;i++)
1223 CPPUNIT_ASSERT_EQUAL(expected1[i],da2->getIJ(0,i));
1232 void MEDCouplingBasicsTest4::testSortCellsInMEDFileFrmt1()
1234 MEDCouplingUMesh *m1=0;
1235 MEDCouplingUMesh *m=buildPointe_1(m1);
1236 MEDCouplingUMesh *m2=(MEDCouplingUMesh *)m->deepCpy();
1238 const int vals[16]={0,1,2,14,3,12,4,5,15,6,7,8,9,10,11,13};
1239 DataArrayInt *da=DataArrayInt::New();
1241 std::copy(vals,vals+16,da->getPointer());
1242 DataArrayInt *daa=da->invertArrayN2O2O2N(16);
1243 m->renumberCells(daa->getConstPointer(),false);
1245 DataArrayInt *da2=m->sortCellsInMEDFileFrmt();
1246 CPPUNIT_ASSERT(m2->isEqual(m2,1e-12));
1247 CPPUNIT_ASSERT(da->isEqual(*da2));
1255 void MEDCouplingBasicsTest4::testBuildPartAndReduceNodes1()
1257 MEDCouplingMesh *m=build2DTargetMesh_1();
1258 const int arr[2]={1,0};
1260 MEDCouplingMesh *m2=m->buildPartAndReduceNodes(arr,arr+2,da);
1261 CPPUNIT_ASSERT_EQUAL(5,m2->getNumberOfNodes());
1262 CPPUNIT_ASSERT_EQUAL(2,m2->getNumberOfCells());
1263 MEDCouplingFieldDouble *f=m2->getMeasureField(true);
1264 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.125,f->getArray()->getIJ(0,0),1e-12);
1265 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.25,f->getArray()->getIJ(1,0),1e-12);
1272 void MEDCouplingBasicsTest4::testDAITransformWithIndArrR1()
1274 const int tab1[6]={2,4,5,3,6,7};
1275 const int tab2[12]={-1,-1,0,1,2,3,4,5,-1,-1,-1,-1};
1276 const int expected[6]={0,3,1,2,4,5};
1277 DataArrayInt *d=DataArrayInt::New();
1279 std::copy(tab1,tab1+6,d->getPointer());
1280 DataArrayInt *d1=DataArrayInt::New();
1282 std::copy(tab2,tab2+12,d1->getPointer());
1284 DataArrayInt *d3=d->transformWithIndArrR(d1->getConstPointer(),d1->getConstPointer()+d1->getNbOfElems());
1285 CPPUNIT_ASSERT_EQUAL(6,d3->getNumberOfTuples());
1286 CPPUNIT_ASSERT_EQUAL(1,d3->getNumberOfComponents());
1287 for(int i=0;i<6;i++)
1288 CPPUNIT_ASSERT_EQUAL(expected[i],d3->getIJ(i,0));
1295 void MEDCouplingBasicsTest4::testDAISplitByValueRange1()
1297 const int val1[9]={6,5,0,3,2,7,8,1,4};
1298 const int val2[3]={0,4,9};
1299 DataArrayInt *d=DataArrayInt::New();
1301 std::copy(val1,val1+9,d->getPointer());
1302 DataArrayInt *ee=0,*f=0,*g=0;
1303 d->splitByValueRange(val2,val2+3,ee,f,g);
1304 CPPUNIT_ASSERT_EQUAL(9,ee->getNumberOfTuples());
1305 CPPUNIT_ASSERT_EQUAL(1,ee->getNumberOfComponents());
1306 CPPUNIT_ASSERT_EQUAL(9,f->getNumberOfTuples());
1307 CPPUNIT_ASSERT_EQUAL(1,f->getNumberOfComponents());
1308 CPPUNIT_ASSERT_EQUAL(2,g->getNumberOfTuples());
1309 CPPUNIT_ASSERT_EQUAL(1,g->getNumberOfComponents());
1311 const int expected1[9]={1,1,0,0,0,1,1,0,1};
1312 const int expected2[9]={2,1,0,3,2,3,4,1,0};
1313 for(int i=0;i<9;i++)
1315 CPPUNIT_ASSERT_EQUAL(expected1[i],ee->getIJ(i,0));
1316 CPPUNIT_ASSERT_EQUAL(expected2[i],f->getIJ(i,0));
1318 CPPUNIT_ASSERT_EQUAL(0,g->getIJ(0,0));
1319 CPPUNIT_ASSERT_EQUAL(1,g->getIJ(1,0));
1326 CPPUNIT_ASSERT_THROW(d->splitByValueRange(val2,val2+3,ee,f,g),INTERP_KERNEL::Exception);
1331 void MEDCouplingBasicsTest4::testUMeshSplitProfilePerType1()
1333 const int val0[5]={2,0,1,3,4};
1334 MEDCouplingUMesh *m=build2DTargetMesh_1();
1335 m->renumberCells(val0,false);
1336 std::vector<int> code;
1337 std::vector<DataArrayInt *> idsInPflPerType;
1338 std::vector<DataArrayInt *> pfls;
1340 const int val1[3]={0,2,3};
1341 DataArrayInt *d=DataArrayInt::New();
1344 std::copy(val1,val1+3,d->getPointer());
1345 m->splitProfilePerType(d,code,idsInPflPerType,pfls);
1346 CPPUNIT_ASSERT_EQUAL(6,(int)code.size());
1347 CPPUNIT_ASSERT_EQUAL(2,(int)idsInPflPerType.size());
1348 const int expected1[6]={3,1,0, 4,2,1};
1349 for(int i=0;i<6;i++)
1350 CPPUNIT_ASSERT_EQUAL(expected1[i],code[i]);
1351 CPPUNIT_ASSERT_EQUAL(1,idsInPflPerType[0]->getNumberOfTuples());
1352 CPPUNIT_ASSERT_EQUAL(0,idsInPflPerType[0]->getIJ(0,0));
1353 CPPUNIT_ASSERT_EQUAL(2,idsInPflPerType[1]->getNumberOfTuples());
1354 CPPUNIT_ASSERT_EQUAL(1,idsInPflPerType[1]->getIJ(0,0));
1355 CPPUNIT_ASSERT_EQUAL(2,idsInPflPerType[1]->getIJ(1,0));
1356 idsInPflPerType[0]->decrRef();
1357 idsInPflPerType[1]->decrRef();
1358 CPPUNIT_ASSERT_EQUAL(2,(int)pfls.size());
1359 CPPUNIT_ASSERT(std::string("sup")==pfls[0]->getName());
1360 CPPUNIT_ASSERT_EQUAL(1,pfls[0]->getNumberOfTuples());
1361 CPPUNIT_ASSERT_EQUAL(0,pfls[0]->getIJ(0,0));
1362 CPPUNIT_ASSERT(std::string("sup")==pfls[1]->getName());
1363 CPPUNIT_ASSERT_EQUAL(2,pfls[1]->getNumberOfTuples());
1364 CPPUNIT_ASSERT_EQUAL(0,pfls[1]->getIJ(0,0));
1365 CPPUNIT_ASSERT_EQUAL(1,pfls[1]->getIJ(1,0));
1369 idsInPflPerType.clear();
1373 const int val2[4]={0,2,3,4};// all quad4 are selected here ! So no profile for Quads
1374 d=DataArrayInt::New();
1376 std::copy(val2,val2+4,d->getPointer());
1377 m->splitProfilePerType(d,code,idsInPflPerType,pfls);
1378 CPPUNIT_ASSERT_EQUAL(6,(int)code.size());
1379 CPPUNIT_ASSERT_EQUAL(2,(int)idsInPflPerType.size());
1380 const int expected2[6]={3,1,0, 4,3,-1};
1381 for(int i=0;i<6;i++)
1382 CPPUNIT_ASSERT_EQUAL(expected2[i],code[i]);
1383 CPPUNIT_ASSERT_EQUAL(1,idsInPflPerType[0]->getNumberOfTuples());
1384 CPPUNIT_ASSERT_EQUAL(0,idsInPflPerType[0]->getIJ(0,0));
1385 CPPUNIT_ASSERT_EQUAL(3,idsInPflPerType[1]->getNumberOfTuples());
1386 CPPUNIT_ASSERT_EQUAL(1,idsInPflPerType[1]->getIJ(0,0));
1387 CPPUNIT_ASSERT_EQUAL(2,idsInPflPerType[1]->getIJ(1,0));
1388 CPPUNIT_ASSERT_EQUAL(3,idsInPflPerType[1]->getIJ(2,0));
1389 idsInPflPerType[0]->decrRef();
1390 idsInPflPerType[1]->decrRef();
1391 CPPUNIT_ASSERT_EQUAL(1,(int)pfls.size());
1392 CPPUNIT_ASSERT_EQUAL(1,pfls[0]->getNumberOfTuples());
1393 CPPUNIT_ASSERT_EQUAL(0,pfls[0]->getIJ(0,0));
1396 idsInPflPerType.clear();
1400 const int val3[3]={1,0,2};// all tri3 are selected here but not in the same order ! Profile requested for Tri3
1401 d=DataArrayInt::New();
1403 std::copy(val3,val3+3,d->getPointer());
1404 m->splitProfilePerType(d,code,idsInPflPerType,pfls);
1405 CPPUNIT_ASSERT_EQUAL(6,(int)code.size());
1406 CPPUNIT_ASSERT_EQUAL(2,(int)idsInPflPerType.size());
1407 const int expected3[6]={3,2,0, 4,1,1};
1408 for(int i=0;i<6;i++)
1409 CPPUNIT_ASSERT_EQUAL(expected3[i],code[i]);
1410 CPPUNIT_ASSERT_EQUAL(2,idsInPflPerType[0]->getNumberOfTuples());
1411 CPPUNIT_ASSERT_EQUAL(0,idsInPflPerType[0]->getIJ(0,0));
1412 CPPUNIT_ASSERT_EQUAL(1,idsInPflPerType[0]->getIJ(1,0));
1413 CPPUNIT_ASSERT_EQUAL(1,idsInPflPerType[1]->getNumberOfTuples());
1414 CPPUNIT_ASSERT_EQUAL(2,idsInPflPerType[1]->getIJ(0,0));
1415 idsInPflPerType[0]->decrRef();
1416 idsInPflPerType[1]->decrRef();
1417 CPPUNIT_ASSERT_EQUAL(2,(int)pfls.size());
1418 CPPUNIT_ASSERT_EQUAL(2,pfls[0]->getNumberOfTuples());
1419 CPPUNIT_ASSERT_EQUAL(1,pfls[0]->getIJ(0,0));
1420 CPPUNIT_ASSERT_EQUAL(0,pfls[0]->getIJ(1,0));
1421 CPPUNIT_ASSERT_EQUAL(0,pfls[1]->getIJ(0,0));
1425 idsInPflPerType.clear();
1429 const int val4[2]={3,4};// all tri3 are selected here but not in the same order ! Profile requested for Tri3
1430 d=DataArrayInt::New();
1432 std::copy(val4,val4+2,d->getPointer());
1433 m->splitProfilePerType(d,code,idsInPflPerType,pfls);
1434 CPPUNIT_ASSERT_EQUAL(3,(int)code.size());
1435 CPPUNIT_ASSERT_EQUAL(1,(int)idsInPflPerType.size());
1436 const int expected4[3]={4,2,0};
1437 for(int i=0;i<3;i++)
1438 CPPUNIT_ASSERT_EQUAL(expected4[i],code[i]);
1439 CPPUNIT_ASSERT_EQUAL(2,idsInPflPerType[0]->getNumberOfTuples());
1440 CPPUNIT_ASSERT_EQUAL(0,idsInPflPerType[0]->getIJ(0,0));
1441 CPPUNIT_ASSERT_EQUAL(1,idsInPflPerType[0]->getIJ(1,0));
1442 idsInPflPerType[0]->decrRef();
1443 CPPUNIT_ASSERT_EQUAL(1,(int)pfls.size());
1444 CPPUNIT_ASSERT_EQUAL(2,pfls[0]->getNumberOfTuples());
1445 CPPUNIT_ASSERT_EQUAL(1,pfls[0]->getIJ(0,0));
1446 CPPUNIT_ASSERT_EQUAL(2,pfls[0]->getIJ(1,0));
1449 idsInPflPerType.clear();
1456 void MEDCouplingBasicsTest4::testDAIBuildExplicitArrByRanges1()
1458 DataArrayInt *d=DataArrayInt::New();
1460 const int vals1[3]={0,2,3};
1461 std::copy(vals1,vals1+3,d->getPointer());
1462 DataArrayInt *e=DataArrayInt::New();
1464 const int vals2[6]={0,3,6,10,14,20};
1465 std::copy(vals2,vals2+6,e->getPointer());
1467 DataArrayInt *f=d->buildExplicitArrByRanges(e);
1468 CPPUNIT_ASSERT_EQUAL(11,f->getNumberOfTuples());
1469 CPPUNIT_ASSERT_EQUAL(1,f->getNumberOfComponents());
1470 const int expected1[11]={0,1,2,6,7,8,9,10,11,12,13};
1471 for(int i=0;i<11;i++)
1472 CPPUNIT_ASSERT_EQUAL(expected1[i],f->getIJ(i,0));
1479 void MEDCouplingBasicsTest4::testDAIComputeOffsets2()
1481 DataArrayInt *d=DataArrayInt::New();
1482 const int vals1[6]={3,5,1,2,0,8};
1483 const int expected1[7]={0,3,8,9,11,11,19};
1485 std::copy(vals1,vals1+6,d->getPointer());
1486 d->computeOffsets2();
1487 CPPUNIT_ASSERT_EQUAL(7,d->getNumberOfTuples());
1488 CPPUNIT_ASSERT_EQUAL(1,d->getNumberOfComponents());
1489 for(int i=0;i<7;i++)
1490 CPPUNIT_ASSERT_EQUAL(expected1[i],d->getIJ(0,i));
1494 void MEDCouplingBasicsTest4::testMergeField3()
1496 MEDCouplingUMesh *m=build2DTargetMesh_1();
1497 m->getCoords()->setInfoOnComponent(0,"x [m]");
1498 m->getCoords()->setInfoOnComponent(1,"z [km]");
1500 m->setDescription("desc");
1501 MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1504 DataArrayDouble *arr=DataArrayDouble::New();
1506 arr->setInfoOnComponent(0,"X [m]");
1507 arr->setInfoOnComponent(1,"YY [mm]");
1508 arr->fillWithValue(2.);
1513 std::vector<const MEDCouplingFieldDouble *> tmp(1);
1515 MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::MergeFields(tmp);
1516 CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
1522 void MEDCouplingBasicsTest4::testGetDistributionOfTypes1()
1524 MEDCouplingUMesh *m=build2DTargetMesh_1();
1525 const int tab1[5]={2,0,1,3,4};
1526 CPPUNIT_ASSERT_THROW(m->getDistributionOfTypes(),INTERP_KERNEL::Exception);
1527 m->renumberCells(tab1,false);
1528 std::vector<int> code=m->getDistributionOfTypes();
1529 CPPUNIT_ASSERT_EQUAL(6,(int)code.size());
1530 CPPUNIT_ASSERT_EQUAL(3,code[0]);
1531 CPPUNIT_ASSERT_EQUAL(2,code[1]);
1532 CPPUNIT_ASSERT_EQUAL(0,code[2]);
1533 CPPUNIT_ASSERT_EQUAL(4,code[3]);
1534 CPPUNIT_ASSERT_EQUAL(3,code[4]);
1535 CPPUNIT_ASSERT_EQUAL(0,code[5]);
1539 void MEDCouplingBasicsTest4::testNorm2_1()
1541 MEDCouplingUMesh *m=build2DTargetMesh_1();
1542 MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1546 DataArrayDouble *d=DataArrayDouble::New();
1547 const double tab[10]={1.2,1.3,2.2,2.3,3.2,3.3,4.2,4.3,5.2,5.3};
1549 std::copy(tab,tab+10,d->getPointer());
1552 f->checkCoherency();
1554 CPPUNIT_ASSERT_DOUBLES_EQUAL(11.209371079592289,f->norm2(),1e-14);
1559 void MEDCouplingBasicsTest4::testNormMax1()
1561 MEDCouplingUMesh *m=build2DTargetMesh_1();
1562 MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1566 DataArrayDouble *d=DataArrayDouble::New();
1567 const double tab[10]={2.3,-1.2,6.3,-7.8,2.9,7.7,2.1,0.,3.6,-7.6};
1569 std::copy(tab,tab+10,d->getPointer());
1572 f->checkCoherency();
1574 CPPUNIT_ASSERT_DOUBLES_EQUAL(7.8,f->normMax(),1e-14);
1579 void MEDCouplingBasicsTest4::testFindAndCorrectBadOriented3DExtrudedCells1()
1581 const double coords[38*3]={0.0011180339887498999, -0.0011755705045849499, 0.0, -0.0012331070204200001, -0.0011755705045849499, 0.0, -0.00067557050458494599, -0.00145964954842536, 0.0, -0.00050000000000000001, -0.00086602540378443902, 0.0, 0.00140211303259031, -0.00061803398874989504, 0.0, 0.00086602540378443902, -0.00050000000000000001, 0.0, 0.001, 0.0, 0.0, 0.00034561537182258202, 0.000269164072574575, 0.0, 0.0, 0.001, 0.0, -0.00050000000000000001, 0.00086602540378443902, 0.0, -0.000269164072574575, 0.00034561537182258202, 0.0, -0.001, 0.0, 0.0, -0.00086602540378443902, -0.00050000000000000001, 0.0, -0.00034561537182258202, -0.000269164072574575, 0.0, 0.0, -0.001, 0.0, 0.00050000000000000001, -0.00086602540378443902, 0.0, 0.000269164072574575, -0.00034561537182258202, 0.0, 0.0015, -6.01853107621011e-36, 0.0, 0.00056049747291484397, -0.00145964954842536, 0.0, 0.0011180339887498999, -0.0011755705045849499, 0.00050000000000000001, -0.0012331070204200001, -0.0011755705045849499, 0.00050000000000000001, -0.00067557050458494599, -0.00145964954842536, 0.00050000000000000001, -0.00050000000000000001, -0.00086602540378443902, 0.00050000000000000001, 0.00140211303259031, -0.00061803398874989504, 0.00050000000000000001, 0.00086602540378443902, -0.00050000000000000001, 0.00050000000000000001, 0.001, 0.0, 0.00050000000000000001, 0.00034561537182258202, 0.000269164072574575, 0.00050000000000000001, 0.0, 0.001, 0.00050000000000000001, -0.00050000000000000001, 0.00086602540378443902, 0.00050000000000000001, -0.000269164072574575, 0.00034561537182258202, 0.00050000000000000001, -0.001, 0.0, 0.00050000000000000001, -0.00086602540378443902, -0.00050000000000000001, 0.00050000000000000001, -0.00034561537182258202, -0.000269164072574575, 0.00050000000000000001, 0.0, -0.001, 0.00050000000000000001, 0.00050000000000000001, -0.00086602540378443902, 0.00050000000000000001, 0.000269164072574575, -0.00034561537182258202, 0.00050000000000000001, 0.0015, -6.01853107621011e-36, 0.00050000000000000001, 0.00056049747291484397, -0.00145964954842536, 0.00050000000000000001};
1582 const int conn[56]={2, 1, 3, 21, 20, 22, 4, 0, 5, 23, 19, 24, 8, 9, 10, 27, 28, 29, 11, 12, 13, 30, 31, 32, 0, 18, 15, 5, 19, 37, 34, 24, 6, 17, 4, 5, 25, 36, 23, 24, 3, 14, 16, 13, 22, 33, 35, 32, 13, 16, 7, 10, 32, 35, 26, 29};
1583 const int connExp[64]={16, 2, 1, 3, 21, 20, 22, 16, 4, 0, 5, 23, 19, 24, 16, 8, 10, 9, 27, 29, 28, 16, 11, 13, 12, 30, 32, 31, 18, 0, 18, 15, 5, 19, 37, 34, 24,18, 6, 17, 4, 5, 25, 36, 23, 24, 18, 3, 13, 16, 14, 22, 32, 35, 33, 18, 13, 10, 7, 16, 32, 29, 26, 35};
1584 const int invalidCells[4]={2,3,6,7};
1585 MEDCouplingUMesh *m=MEDCouplingUMesh::New("Example",3);
1586 DataArrayDouble *coo=DataArrayDouble::New();
1588 std::copy(coords,coords+114,coo->getPointer());
1591 m->allocateCells(8);
1592 m->insertNextCell(INTERP_KERNEL::NORM_PENTA6,6,conn);
1593 m->insertNextCell(INTERP_KERNEL::NORM_PENTA6,6,conn+6);
1594 m->insertNextCell(INTERP_KERNEL::NORM_PENTA6,6,conn+12);
1595 m->insertNextCell(INTERP_KERNEL::NORM_PENTA6,6,conn+18);
1596 m->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+24);
1597 m->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+32);
1598 m->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+40);
1599 m->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+48);
1600 m->finishInsertingCells();
1602 DataArrayInt *v=m->findAndCorrectBadOriented3DExtrudedCells();
1603 CPPUNIT_ASSERT_EQUAL(4,v->getNumberOfTuples());
1604 CPPUNIT_ASSERT(std::equal(v->begin(),v->end(),invalidCells));
1605 CPPUNIT_ASSERT(std::equal(connExp,connExp+64,m->getNodalConnectivity()->getConstPointer()));
1611 void MEDCouplingBasicsTest4::testConvertExtrudedPolyhedra1()
1613 const int conn[72]={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,31,32,33,34,35,36,37,38, 39,40,41,42,43,44,45,46, 47,48,49,50,51,52,53,54,55,56,57,58, 59,60,61,62,63,64,65,66,67,68,69,70,71,72};
1614 MEDCouplingUMesh *m=MEDCouplingUMesh::New("Example",3);
1615 DataArrayDouble *coo=DataArrayDouble::New();
1617 coo->rearrange(1); coo->iota(0); coo->rearrange(3);
1620 m->allocateCells(9);
1621 m->insertNextCell(INTERP_KERNEL::NORM_TETRA4,4,conn);
1622 m->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+4);
1623 m->insertNextCell(INTERP_KERNEL::NORM_TETRA4,4,conn+12);
1624 m->insertNextCell(INTERP_KERNEL::NORM_POLYHED,6,conn+16);
1625 m->insertNextCell(INTERP_KERNEL::NORM_PENTA6,6,conn+22);
1626 m->insertNextCell(INTERP_KERNEL::NORM_POLYHED,10,conn+28);
1627 m->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+38);
1628 m->insertNextCell(INTERP_KERNEL::NORM_HEXGP12,12,conn+46);
1629 m->insertNextCell(INTERP_KERNEL::NORM_POLYHED,14,conn+58);
1630 m->finishInsertingCells();
1632 m->convertExtrudedPolyhedra();
1633 DataArrayInt *da=m->getNodalConnectivity();
1634 DataArrayInt *dai=m->getNodalConnectivityIndex();
1635 CPPUNIT_ASSERT_EQUAL((std::size_t)10,dai->getNbOfElems());
1636 CPPUNIT_ASSERT_EQUAL((std::size_t)159,da->getNbOfElems());
1638 const int expected1[159]={14, 1, 2, 3, 4,
1639 18, 5, 6, 7, 8, 9, 10, 11, 12,
1641 31, 17, 18, 19, -1, 20, 22, 21, -1, 17, 18, 21, 20, -1, 18, 19, 22, 21, -1, 19, 17, 20,
1643 16, 23, 24, 25, 26, 27, 28,
1644 31, 29, 30, 31, 32, 33, -1, 34, 38, 37, 36, 35, -1, 29, 30, 35, 34, -1, 30, 31, 36, 35, -1, 31, 32, 37, 36, -1, 32, 33, 38, 37,
1646 18, 39, 40, 41, 42, 43, 44, 45, 46,
1647 22, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
1648 31, 59, 60, 61, 62, 63, 64, 65, -1, 66, 72, 71, 70, 69, 68, 67, -1, 59, 60, 67, 66, -1, 60, 61, 68, 67, -1, 61, 62, 69, 68, -1, 62, 63, 70, 69, -1, 63, 64, 71, 70, -1, 64, 65, 72, 71, -1, 65, 59, 66, 72};
1649 const int expected2[10]={0,5,14,19,42,49,86,95,108,159};
1650 CPPUNIT_ASSERT(std::equal(expected1,expected1+159,da->getConstPointer()));
1651 CPPUNIT_ASSERT(std::equal(expected2,expected2+10,dai->getConstPointer()));
1652 m->checkCoherency2();
1657 void MEDCouplingBasicsTest4::testNonRegressionCopyTinyStrings()
1659 MEDCouplingUMesh *m=build2DTargetMesh_1();
1660 MEDCouplingFieldDouble *f1=m->getMeasureField(true);
1661 f1->getArray()->setInfoOnComponent(0,"P [N/m^2]");
1662 DataArrayDouble *bary=m->getBarycenterAndOwner();
1663 MEDCouplingFieldDouble *f2=f1->buildNewTimeReprFromThis(NO_TIME,false);
1665 CPPUNIT_ASSERT_THROW(f1->copyTinyAttrFrom(f2),INTERP_KERNEL::Exception);
1672 void MEDCouplingBasicsTest4::testDaDSetPartOfValuesAdv1()
1674 const double tab1[18]={3.,4.,5., 13.,14.,15., 23.,24.,25., 33.,34.,35., 43.,44.,45., 53.,54.,55.};
1675 const double tab2[9]={6.,7.,8., 16.,17.,18., 26.,27.,28.};
1676 const int tab3[6]={4,1, 2,2, 3,0};
1677 DataArrayDouble *a=DataArrayDouble::New();
1679 std::copy(tab1,tab1+18,a->getPointer());
1680 DataArrayDouble *b=DataArrayDouble::New();
1682 std::copy(tab2,tab2+9,b->getPointer());
1683 DataArrayInt *c=DataArrayInt::New();
1685 std::copy(tab3,tab3+6,c->getPointer());
1687 a->setPartOfValuesAdv(b,c);
1688 const double expected1[18]={3.,4.,5., 13.,14.,15., 26.,27.,28., 6.,7.,8., 16.,17.,18., 53.,54.,55.};
1689 std::equal(expected1,expected1+18,a->getConstPointer());
1696 void MEDCouplingBasicsTest4::testUMeshBuildSetInstanceFromThis1()
1698 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1699 MEDCouplingUMesh *m2=m->buildSetInstanceFromThis(3);
1700 CPPUNIT_ASSERT_EQUAL(m->getNodalConnectivity(),m2->getNodalConnectivity());
1701 CPPUNIT_ASSERT_EQUAL(m->getNodalConnectivityIndex(),m2->getNodalConnectivityIndex());
1702 CPPUNIT_ASSERT_EQUAL(m->getCoords(),m2->getCoords());
1706 m=MEDCouplingUMesh::New("toto",2);
1707 m2=m->buildSetInstanceFromThis(3);
1708 CPPUNIT_ASSERT_EQUAL(0,m2->getNumberOfNodes());
1709 CPPUNIT_ASSERT_EQUAL(0,m2->getNumberOfCells());
1714 void MEDCouplingBasicsTest4::testUMeshMergeMeshesCVW1()
1716 MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1717 MEDCouplingUMesh *m2=MEDCouplingUMesh::New("toto",2);
1718 MEDCouplingUMesh *m3=MEDCouplingUMesh::MergeUMeshes(m,m2);
1719 m3->setName(m->getName());
1720 CPPUNIT_ASSERT(m->isEqual(m3,1e-12));
1726 void MEDCouplingBasicsTest4::testChangeUnderlyingMeshWithCMesh1()
1728 MEDCouplingCMesh* mesh=MEDCouplingCMesh::New();
1729 DataArrayDouble* coordsX=DataArrayDouble::New();
1730 double arrX[4] = { -1., 1., 2., 4. };
1731 coordsX->useArray(arrX,false, CPP_DEALLOC,4,1);
1732 DataArrayDouble* coordsY=DataArrayDouble::New();
1733 double arrY[4] = { -2., 2., 4., 8. };
1734 coordsY->useArray(arrY,false, CPP_DEALLOC,4,1);
1735 DataArrayDouble* coordsZ=DataArrayDouble::New();
1736 double arrZ[4] = { -3., 3., 6., 12. };
1737 coordsZ->useArray(arrZ,false, CPP_DEALLOC,4,1);
1738 mesh->setCoords(coordsX,coordsY,coordsZ);
1742 MEDCouplingMesh *mesh2=mesh->deepCpy();
1744 static const int ids1[9]={0,1,2,10,11,12,20,21,22};
1745 for(const int *myId=ids1;myId!=ids1+9;myId++)
1747 MEDCouplingFieldDouble *f=mesh->getMeasureField(true);
1748 f->changeUnderlyingMesh(mesh2,*myId,1e-12);
1751 mesh2->setName("uuuu");
1752 for(const int *myId=ids1+1;myId!=ids1+9;myId++)
1754 MEDCouplingFieldDouble *f=mesh->getMeasureField(true);
1755 f->changeUnderlyingMesh(mesh2,*myId,1e-12);
1763 void MEDCouplingBasicsTest4::testDADFindCommonTuples1()
1765 DataArrayDouble *da=DataArrayDouble::New();
1767 const double array1[6]={2.3,1.2,1.3,2.3,2.301,0.8};
1768 std::copy(array1,array1+6,da->getPointer());
1769 DataArrayInt *c=0,*cI=0;
1771 da->findCommonTuples(1e-2,-1,c,cI);
1772 const int expected1[3]={0,3,4};
1773 const int expected2[2]={0,3};
1774 CPPUNIT_ASSERT_EQUAL((std::size_t)3,c->getNbOfElems());
1775 CPPUNIT_ASSERT_EQUAL((std::size_t)2,cI->getNbOfElems());
1776 CPPUNIT_ASSERT(std::equal(expected1,expected1+3,c->getConstPointer()));
1777 CPPUNIT_ASSERT(std::equal(expected2,expected2+2,cI->getConstPointer()));
1781 da->findCommonTuples(2e-1,-1,c,cI);
1782 const int expected3[5]={0,3,4,1,2};
1783 const int expected4[3]={0,3,5};
1784 CPPUNIT_ASSERT_EQUAL((std::size_t)5,c->getNbOfElems());
1785 CPPUNIT_ASSERT_EQUAL((std::size_t)3,cI->getNbOfElems());
1786 CPPUNIT_ASSERT(std::equal(expected3,expected3+5,c->getConstPointer()));
1787 CPPUNIT_ASSERT(std::equal(expected4,expected4+3,cI->getConstPointer()));
1792 const double array2[12]={2.3,2.3,1.2,1.2,1.3,1.3,2.3,2.3,2.301,2.301,0.8,0.8};
1793 std::copy(array2,array2+12,da->getPointer());
1794 da->findCommonTuples(1e-2,-1,c,cI);
1795 CPPUNIT_ASSERT_EQUAL((std::size_t)3,c->getNbOfElems());
1796 CPPUNIT_ASSERT_EQUAL((std::size_t)2,cI->getNbOfElems());
1797 CPPUNIT_ASSERT(std::equal(expected1,expected1+3,c->getConstPointer()));
1798 CPPUNIT_ASSERT(std::equal(expected2,expected2+2,cI->getConstPointer()));
1802 da->findCommonTuples(2e-1,-1,c,cI);
1803 CPPUNIT_ASSERT_EQUAL((std::size_t)5,c->getNbOfElems());
1804 CPPUNIT_ASSERT_EQUAL((std::size_t)3,cI->getNbOfElems());
1805 CPPUNIT_ASSERT(std::equal(expected3,expected3+5,c->getConstPointer()));
1806 CPPUNIT_ASSERT(std::equal(expected4,expected4+3,cI->getConstPointer()));
1811 const double array3[18]={2.3,2.3,2.3,1.2,1.2,1.2,1.3,1.3,1.3,2.3,2.3,2.3,2.301,2.301,2.301,0.8,0.8,0.8};
1812 std::copy(array3,array3+18,da->getPointer());
1813 da->findCommonTuples(1e-2,-1,c,cI);
1814 CPPUNIT_ASSERT_EQUAL((std::size_t)3,c->getNbOfElems());
1815 CPPUNIT_ASSERT_EQUAL((std::size_t)2,cI->getNbOfElems());
1816 CPPUNIT_ASSERT(std::equal(expected1,expected1+3,c->getConstPointer()));
1817 CPPUNIT_ASSERT(std::equal(expected2,expected2+2,cI->getConstPointer()));
1821 da->findCommonTuples(2e-1,-1,c,cI);
1822 CPPUNIT_ASSERT_EQUAL((std::size_t)5,c->getNbOfElems());
1823 CPPUNIT_ASSERT_EQUAL((std::size_t)3,cI->getNbOfElems());
1824 CPPUNIT_ASSERT(std::equal(expected3,expected3+5,c->getConstPointer()));
1825 CPPUNIT_ASSERT(std::equal(expected4,expected4+3,cI->getConstPointer()));
1829 const double array11[6]={2.3,1.2,1.3,2.4,2.5,0.8};
1831 std::copy(array11,array11+6,da->getPointer());
1832 // nbOftuples=1, no common groups
1833 da->findCommonTuples(1e-2,-1,c,cI);
1834 CPPUNIT_ASSERT_EQUAL((std::size_t)0,c->getNbOfElems());
1835 CPPUNIT_ASSERT_EQUAL((std::size_t)1,cI->getNbOfElems());
1836 CPPUNIT_ASSERT_EQUAL(0,cI->getIJ(0,0));
1838 da->alloc(6,4); //bad NumberOfComponents
1839 CPPUNIT_ASSERT_THROW(da->findCommonTuples(1e-2,-1,c,cI),INTERP_KERNEL::Exception);
1846 void MEDCouplingBasicsTest4::testDABack1()
1848 DataArrayDouble *da=DataArrayDouble::New();
1850 const double array1[6]={2.3,1.2,1.3,2.3,2.301,0.8};
1851 std::copy(array1,array1+6,da->getPointer());
1852 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.8,da->back(),1e-14);
1854 CPPUNIT_ASSERT_THROW(da->back(),INTERP_KERNEL::Exception);
1856 CPPUNIT_ASSERT_THROW(da->back(),INTERP_KERNEL::Exception);
1859 DataArrayInt *da2=DataArrayInt::New();
1861 const int array2[4]={4,7,8,2};
1862 std::copy(array2,array2+4,da2->getPointer());
1863 CPPUNIT_ASSERT_EQUAL(2,da2->back());
1865 CPPUNIT_ASSERT_THROW(da2->back(),INTERP_KERNEL::Exception);
1867 CPPUNIT_ASSERT_THROW(da2->back(),INTERP_KERNEL::Exception);
1871 void MEDCouplingBasicsTest4::testDADGetDifferentValues1()
1873 DataArrayDouble *da=DataArrayDouble::New();
1875 const double array1[6]={2.3,1.2,1.3,2.3,2.301,0.8};
1876 std::copy(array1,array1+6,da->getPointer());
1878 const double expected1[4]={2.301,1.2,1.3,0.8};
1879 DataArrayDouble *dv=da->getDifferentValues(1e-2);
1880 CPPUNIT_ASSERT_EQUAL((std::size_t)4,dv->getNbOfElems());
1881 for(int i=0;i<4;i++)
1882 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],dv->getIJ(i,0),1e-14);
1885 dv=da->getDifferentValues(2e-1);
1886 const double expected2[3]={2.301,1.3,0.8};
1887 CPPUNIT_ASSERT_EQUAL((std::size_t)3,dv->getNbOfElems());
1888 for(int i=0;i<3;i++)
1889 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],dv->getIJ(i,0),1e-14);
1894 void MEDCouplingBasicsTest4::testDAIBuildOld2NewArrayFromSurjectiveFormat2()
1896 const int arr[5]={0,3, 5,7,9};
1897 const int arrI[3]={0,2,5};
1898 DataArrayInt *a=DataArrayInt::New();
1900 std::copy(arr,arr+5,a->getPointer());
1901 DataArrayInt *b=DataArrayInt::New();
1903 std::copy(arrI,arrI+3,b->getPointer());
1905 DataArrayInt *ret=DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(10,a->begin(),b->begin(),b->end(),newNbTuple);
1906 const int expected[10]={0,1,2,0,3,4,5,4,6,4};
1907 CPPUNIT_ASSERT_EQUAL((std::size_t)10,ret->getNbOfElems());
1908 CPPUNIT_ASSERT_EQUAL(7,newNbTuple);
1909 CPPUNIT_ASSERT_EQUAL(1,ret->getNumberOfComponents());
1910 CPPUNIT_ASSERT(std::equal(expected,expected+10,ret->getConstPointer()));
1911 CPPUNIT_ASSERT_THROW(DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(9,a->begin(),b->begin(),b->end(),newNbTuple),INTERP_KERNEL::Exception);
1917 void MEDCouplingBasicsTest4::testDADIReverse1()
1919 const int arr[6]={0,3,5,7,9,2};
1920 DataArrayInt *a=DataArrayInt::New();
1922 std::copy(arr,arr+6,a->getPointer());
1923 CPPUNIT_ASSERT_EQUAL(2,a->back());
1925 for(int i=0;i<6;i++)
1926 CPPUNIT_ASSERT_EQUAL(arr[5-i],a->getIJ(i,0));
1928 std::copy(arr,arr+5,a->getPointer());
1930 for(int i=0;i<5;i++)
1931 CPPUNIT_ASSERT_EQUAL(arr[4-i],a->getIJ(i,0));
1934 const double arr2[6]={0.,3.,5.,7.,9.,2.};
1935 DataArrayDouble *b=DataArrayDouble::New();
1937 std::copy(arr2,arr2+6,b->getPointer());
1939 for(int i=0;i<6;i++)
1940 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr2[5-i],b->getIJ(i,0),1e-14);
1942 std::copy(arr,arr+5,b->getPointer());
1943 CPPUNIT_ASSERT_DOUBLES_EQUAL(9.,b->back(),1e-14);
1945 for(int i=0;i<5;i++)
1946 CPPUNIT_ASSERT_DOUBLES_EQUAL(arr2[4-i],b->getIJ(i,0),1e-14);
1950 void MEDCouplingBasicsTest4::testGetNodeIdsInUse1()
1952 MEDCouplingUMesh *m0=build2DTargetMesh_1();
1953 const int CellIds[2]={1,2};
1954 MEDCouplingUMesh *m1=static_cast<MEDCouplingUMesh *>(m0->buildPartOfMySelf(CellIds,CellIds+2,true));
1955 int newNbOfNodes=-1;
1956 DataArrayInt *arr=m1->getNodeIdsInUse(newNbOfNodes);
1957 const int expected[9]={-1,0,1,-1,2,3,-1,-1,-1};
1958 CPPUNIT_ASSERT_EQUAL(4,newNbOfNodes);
1959 CPPUNIT_ASSERT_EQUAL((std::size_t)9,arr->getNbOfElems());
1960 CPPUNIT_ASSERT(std::equal(expected,expected+9,arr->getConstPointer()));
1961 DataArrayInt *arr2=arr->invertArrayO2N2N2O(newNbOfNodes);
1962 CPPUNIT_ASSERT_EQUAL((std::size_t)4,arr2->getNbOfElems());
1963 const int expected2[4]={1,2,4,5};
1964 CPPUNIT_ASSERT(std::equal(expected2,expected2+4,arr2->getConstPointer()));
1971 void MEDCouplingBasicsTest4::testBuildDescendingConnec2()
1973 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
1974 DataArrayInt *desc=DataArrayInt::New();
1975 DataArrayInt *descIndx=DataArrayInt::New();
1976 DataArrayInt *revDesc=DataArrayInt::New();
1977 DataArrayInt *revDescIndx=DataArrayInt::New();
1979 MEDCouplingUMesh *mesh2=mesh->buildDescendingConnectivity2(desc,descIndx,revDesc,revDescIndx);
1980 mesh2->checkCoherency();
1981 CPPUNIT_ASSERT_EQUAL(1,mesh2->getMeshDimension());
1982 CPPUNIT_ASSERT_EQUAL(13,mesh2->getNumberOfCells());
1983 CPPUNIT_ASSERT_EQUAL((std::size_t)14,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(14,revDescIndx->getNumberOfTuples());
1984 CPPUNIT_ASSERT_EQUAL((std::size_t)6,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(6,descIndx->getNumberOfTuples());
1985 CPPUNIT_ASSERT_EQUAL((std::size_t)18,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,desc->getNumberOfTuples());
1986 CPPUNIT_ASSERT_EQUAL((std::size_t)18,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,revDesc->getNumberOfTuples());
1987 const int expected1[18]={1,2,3,4,-3,5,6, 7,8,-5,9,10,-2,11, 12,13,-7,-10};
1988 CPPUNIT_ASSERT(std::equal(expected1,expected1+18,desc->getConstPointer()));
1989 const int expected2[6]={0,4,7,10,14,18};
1990 CPPUNIT_ASSERT(std::equal(expected2,expected2+6,descIndx->getConstPointer()));
1991 const int expected3[14]={0,1,3,5,6,8,9,11,12,13,15,16,17,18};
1992 CPPUNIT_ASSERT(std::equal(expected3,expected3+14,revDescIndx->getConstPointer()));
1993 const int expected4[18]={0, 0,3, 0,1, 0, 1,2, 1, 2,4, 2, 3, 3,4, 3, 4, 4};
1994 CPPUNIT_ASSERT(std::equal(expected4,expected4+18,revDesc->getConstPointer()));
1995 DataArrayInt *conn=mesh2->getNodalConnectivity();
1996 DataArrayInt *connIndex=mesh2->getNodalConnectivityIndex();
1997 const int expected5[14]={0,3,6,9,12,15,18,21,24,27,30,33,36,39};
1998 CPPUNIT_ASSERT(std::equal(expected5,expected5+14,connIndex->getConstPointer()));
1999 const int expected6[39]={1, 0, 3, 1, 3, 4, 1, 4, 1, 1, 1, 0, 1, 4, 2, 1, 2, 1, 1, 4, 5, 1, 5, 2, 1, 6, 7, 1, 7, 4, 1, 3, 6, 1, 7, 8, 1, 8, 5};
2000 CPPUNIT_ASSERT(std::equal(expected6,expected6+39,conn->getConstPointer()));
2003 descIndx->decrRef();
2005 revDescIndx->decrRef();
2010 void MEDCouplingBasicsTest4::testIntersect2DMeshesTmp1()
2012 MEDCouplingCMesh *m1c=MEDCouplingCMesh::New();
2013 DataArrayDouble *coordX=DataArrayDouble::New();
2014 const double arrX[4]={-1., 1., 2., 4.};
2016 std::copy(arrX,arrX+4,coordX->getPointer());
2017 m1c->setCoordsAt(0,coordX);
2018 DataArrayDouble *coordY=DataArrayDouble::New();
2019 const double arrY[4]={-2., 2., 4., 8.};
2021 std::copy(arrY,arrY+4,coordY->getPointer());
2022 m1c->setCoordsAt(1,coordY);
2023 MEDCouplingUMesh *m1=m1c->buildUnstructured();
2024 const int subPart1[3]={3,4,5};
2025 MEDCouplingUMesh *m1bis=static_cast<MEDCouplingUMesh *>(m1->buildPartOfMySelf(subPart1,subPart1+3,false));
2026 MEDCouplingUMesh *m2tmp=static_cast<MEDCouplingUMesh *>(m1->deepCpy());
2027 const int subPart2[3]={0,1,2};
2028 MEDCouplingUMesh *m2=static_cast<MEDCouplingUMesh *>(m2tmp->buildPartOfMySelf(subPart2,subPart2+3,false));
2029 const double vec[2]={0.5,0.5};
2031 // End of construction of input meshes m1bis and m2 -> start of specific part of the test
2032 DataArrayInt *d1=0,*d2=0;
2033 MEDCouplingUMesh *m3=MEDCouplingUMesh::Intersect2DMeshes(m1bis,m2,1e-10,d1,d2);
2034 const int expected1[8]={0,0,1,1,1,2,2,2};
2035 const int expected2[8]={0,-1,0,1,-1,1,2,-1};
2036 CPPUNIT_ASSERT_EQUAL(8,d1->getNumberOfTuples());
2037 CPPUNIT_ASSERT_EQUAL(8,d2->getNumberOfTuples());
2038 CPPUNIT_ASSERT_EQUAL(8,m3->getNumberOfCells());
2039 CPPUNIT_ASSERT_EQUAL(22,m3->getNumberOfNodes());
2040 CPPUNIT_ASSERT_EQUAL(2,m3->getSpaceDimension());
2041 CPPUNIT_ASSERT(std::equal(expected1,expected1+8,d1->getConstPointer()));
2042 CPPUNIT_ASSERT(std::equal(expected2,expected2+8,d2->getConstPointer()));
2043 const int expected3[44]={5,17,1,16,12,5,16,0,4,5,17,12,5,18,1,17,13,5,19,2,18,13,5,17,5,6,19,13,5,20,2,19,14,5,21,3,20,14,5,19,6,7,21,14};
2044 const int expected4[9]={0,5,12,17,22,28,33,38,44};
2045 const double expected5[44]={-1.0,2.0,1.0,2.0,2.0,2.0,4.0,2.0,-1.0,4.0,1.0,4.0,2.0,4.0,4.0,4.0,-0.5,-1.5,1.5,-1.5,2.5,-1.5,4.5,-1.5,-0.5,2.5,1.5,2.5,2.5,2.5,4.5,2.5,-0.5,2.0,1.0,2.5,1.5,2.0,2.0,2.5,2.5,2.0,4.0,2.5};
2046 CPPUNIT_ASSERT_EQUAL(44,m3->getNodalConnectivity()->getNumberOfTuples());
2047 CPPUNIT_ASSERT_EQUAL(9,m3->getNodalConnectivityIndex()->getNumberOfTuples());
2048 CPPUNIT_ASSERT(std::equal(expected3,expected3+44,m3->getNodalConnectivity()->getConstPointer()));
2049 CPPUNIT_ASSERT(std::equal(expected4,expected4+9,m3->getNodalConnectivityIndex()->getConstPointer()));
2050 for(int i=0;i<44;i++)
2051 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[i],m3->getCoords()->getIJ(0,i),1e-12);
2065 void MEDCouplingBasicsTest4::testFindNodesOnLine1()
2067 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
2068 const double pt[2]={-0.3,-0.3};
2069 const double pt2[3]={0.,0.,0.};
2070 const double pt3[3]={-0.3,0.,0.};
2071 const double vec[2]={0.,1.};
2072 const double vec2[3]={1.,0.,0.};
2073 const double vec3[3]={0.,1.,1.};
2074 const int expected1[3]={0,3,6};
2075 std::vector<int> res;
2076 mesh->findNodesOnLine(pt,vec,1e-12,res);
2077 CPPUNIT_ASSERT_EQUAL(3,(int)res.size());
2078 CPPUNIT_ASSERT(std::equal(expected1,expected1+3,res.begin()));
2081 mesh->changeSpaceDimension(3);
2082 mesh->rotate(pt2,vec2,M_PI/4.);
2083 mesh->findNodesOnLine(pt3,vec3,1e-12,res);
2084 CPPUNIT_ASSERT_EQUAL(3,(int)res.size());
2085 CPPUNIT_ASSERT(std::equal(expected1,expected1+3,res.begin()));
2090 void MEDCouplingBasicsTest4::testIntersect2DMeshesTmp2()
2092 MEDCouplingCMesh *m1c=MEDCouplingCMesh::New();
2093 DataArrayDouble *coordsX1=DataArrayDouble::New();
2094 const double arrX1[4]={ 0., 1., 1.5, 2. };
2095 coordsX1->alloc(4,1);
2096 std::copy(arrX1,arrX1+4,coordsX1->getPointer());
2097 m1c->setCoordsAt(0,coordsX1);
2098 DataArrayDouble *coordsY1=DataArrayDouble::New();
2099 const double arrY1[3]={ 0., 1.5, 3.};
2100 coordsY1->alloc(3,1);
2101 std::copy(arrY1,arrY1+3,coordsY1->getPointer());
2102 m1c->setCoordsAt(1,coordsY1);
2103 MEDCouplingUMesh *m1=m1c->buildUnstructured();
2105 MEDCouplingCMesh *m2c=MEDCouplingCMesh::New();
2106 DataArrayDouble *coordsX2=DataArrayDouble::New();
2107 const double arrX2[3]={ 0., 1., 2. };
2108 coordsX2->alloc(3,1);
2109 std::copy(arrX2,arrX2+3,coordsX2->getPointer());
2110 m2c->setCoordsAt(0,coordsX2);
2111 DataArrayDouble *coordsY2=DataArrayDouble::New();
2112 coordsY2->alloc(3,1);
2113 const double arrY2[3]={ 0., 1., 3.};
2114 std::copy(arrY2,arrY2+3,coordsY2->getPointer());
2115 m2c->setCoordsAt(1,coordsY2);
2116 MEDCouplingUMesh *m2=m2c->buildUnstructured();
2118 DataArrayInt *d1=0,*d2=0;
2119 MEDCouplingUMesh *m3=MEDCouplingUMesh::Intersect2DMeshes(m1,m2,1e-10,d1,d2);
2120 const int expected1[9]={0,0,1,1,2,2,3,4,5};
2121 const int expected2[9]={0,2,1,3,1,3,2,3,3};
2122 CPPUNIT_ASSERT_EQUAL(9,d1->getNumberOfTuples());
2123 CPPUNIT_ASSERT_EQUAL(9,d2->getNumberOfTuples());
2124 CPPUNIT_ASSERT_EQUAL(9,m3->getNumberOfCells());
2125 CPPUNIT_ASSERT_EQUAL(22,m3->getNumberOfNodes());
2126 CPPUNIT_ASSERT_EQUAL(2,m3->getSpaceDimension());
2127 CPPUNIT_ASSERT(std::equal(expected1,expected1+9,d1->getConstPointer()));
2128 CPPUNIT_ASSERT(std::equal(expected2,expected2+9,d2->getConstPointer()));
2129 const int expected3[45]={5,16,13,12,15,5,15,4,5,16,5,21,2,13,16,5,16,5,6,21,5,17,14,2,21,5,21,6,7,17,5,4,18,19,5,5,5,19,10,6,5,6,10,20,7};
2130 const int expected4[10]={0,5,10,15,20,25,30,35,40,45};
2131 const double expected5[44]={0.0,0.0,1.0,0.0,1.5,0.0,2.0,0.0,0.0,1.5,1.0,1.5,1.5,1.5,2.0,1.5,0.0,3.0,1.0,3.0,1.5,3.0,2.0,3.0,0.0,0.0,1.0,0.0,2.0,0.0,0.0,1.0,1.0,1.0,2.0,1.0,0.0,3.0,1.0,3.0,2.0,3.0,1.5,1.0};
2132 CPPUNIT_ASSERT_EQUAL(45,m3->getNodalConnectivity()->getNumberOfTuples());
2133 CPPUNIT_ASSERT_EQUAL(10,m3->getNodalConnectivityIndex()->getNumberOfTuples());
2134 CPPUNIT_ASSERT(std::equal(expected3,expected3+45,m3->getNodalConnectivity()->getConstPointer()));
2135 CPPUNIT_ASSERT(std::equal(expected4,expected4+10,m3->getNodalConnectivityIndex()->getConstPointer()));
2136 for(int i=0;i<44;i++)
2137 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[i],m3->getCoords()->getIJ(0,i),1e-12);
2143 coordsX1->decrRef();
2144 coordsY1->decrRef();
2147 coordsX2->decrRef();
2148 coordsY2->decrRef();
2152 void MEDCouplingBasicsTest4::testBuildPartOfMySelfSafe1()
2154 MEDCouplingUMesh *mesh=build2DTargetMesh_1();
2155 const int input1[4]={0,-1,4,2};
2156 const int input2[4]={0,4,5,4};
2157 CPPUNIT_ASSERT_THROW(mesh->buildPartOfMySelf(input1,input1+4,true),INTERP_KERNEL::Exception);
2158 CPPUNIT_ASSERT_THROW(mesh->buildPartOfMySelf(input2,input2+4,true),INTERP_KERNEL::Exception);
2162 void MEDCouplingBasicsTest4::testIntersect2DMeshesTmp3()
2164 double m1Coords[50]={0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1,0.,-1.5,0.5,0.,1.25,0.,0.70710678118654757,0.70710678118654757,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.70710678118654757,0.70710678118654757,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.70710678118654757,-0.70710678118654757,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.70710678118654757,-0.70710678118654757,1.0606601717798214,-1.0606601717798214};
2165 int m1Conn[56]={0,3,1,13,11,9, 3,4,2,1,14,12,10,11, 5,3,0,15,13,17, 6,4,3,5,16,14,15,18, 5,0,7,17,21,19, 6,5,7,8,18,19,22,20, 0,1,7,9,23,21, 1,2,8,7,10,24,22,23};
2166 MEDCouplingUMesh *m1=MEDCouplingUMesh::New();
2167 m1->setMeshDimension(2);
2168 m1->allocateCells(8);
2169 m1->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,m1Conn);
2170 m1->insertNextCell(INTERP_KERNEL::NORM_QUAD8,8,m1Conn+6);
2171 m1->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,m1Conn+14);
2172 m1->insertNextCell(INTERP_KERNEL::NORM_QUAD8,8,m1Conn+20);
2173 m1->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,m1Conn+28);
2174 m1->insertNextCell(INTERP_KERNEL::NORM_QUAD8,8,m1Conn+34);
2175 m1->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,m1Conn+42);
2176 m1->insertNextCell(INTERP_KERNEL::NORM_QUAD8,8,m1Conn+48);
2177 m1->finishInsertingCells();
2178 DataArrayDouble *myCoords1=DataArrayDouble::New();
2179 myCoords1->alloc(25,2);
2180 std::copy(m1Coords,m1Coords+50,myCoords1->getPointer());
2181 m1->setCoords(myCoords1);
2182 myCoords1->decrRef();
2184 double m2Coords[30]={0.,0.,1.1,0.,1.1,1.,0.,1.,1.7,0.,1.7,1.,-1.1,1.,-1.1,0.,-1.7,0.,-1.7,1.,-1.7,-1,-1.1,-1.,0.,-1.,1.1,-1,1.7,-1.};
2185 int m2Conn[32]={0,3,2,1, 1,2,5,4, 7,6,3,0, 8,9,6,7, 7,0,12,11, 8,7,11,10, 0,1,13,12, 1,4,14,13};
2186 MEDCouplingUMesh *m2=MEDCouplingUMesh::New();
2187 m2->setMeshDimension(2);
2188 m2->allocateCells(8);
2189 for(int i=0;i<8;i++)
2190 m2->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,m2Conn+4*i);
2191 m2->finishInsertingCells();
2192 DataArrayDouble *myCoords2=DataArrayDouble::New();
2193 myCoords2->alloc(15,2);
2194 std::copy(m2Coords,m2Coords+30,myCoords2->getPointer());
2195 m2->setCoords(myCoords2);
2196 myCoords2->decrRef();
2198 DataArrayInt *d1=0,*d2=0;
2199 MEDCouplingUMesh *m3=MEDCouplingUMesh::Intersect2DMeshes(m1,m2,1e-10,d1,d2);
2201 const int expected1[16]={0,1,1,1,2,3,3,3,4,5,5,5,6,7,7,7};
2202 const int expected2[16]={0,0,1,-1,2,2,3,-1,4,4,5,-1,6,6,7,-1};
2203 CPPUNIT_ASSERT_EQUAL(16,d1->getNumberOfTuples());
2204 CPPUNIT_ASSERT_EQUAL(16,d2->getNumberOfTuples());
2205 CPPUNIT_ASSERT_EQUAL(16,m3->getNumberOfCells());
2206 CPPUNIT_ASSERT_EQUAL(104,m3->getNumberOfNodes());
2207 CPPUNIT_ASSERT_EQUAL(2,m3->getSpaceDimension());
2208 CPPUNIT_ASSERT(std::equal(expected1,expected1+16,d1->getConstPointer()));
2209 CPPUNIT_ASSERT(std::equal(expected2,expected2+16,d2->getConstPointer()));
2210 const int expected3[136]={6,28,1,25,44,45,46,8,26,1,28,27,47,48,49,50,8,40,2,26,27,51,52,53,54,8,28,4,40,27,55,56,57,58,6,28,25,5,59,60,61,8,28,5,32,31,62,63,64,65,8,32,6,41,31,66,67,68,69,8,41,4,28,31,70,71,72,73,6,25,37,5,74,75,76,8,32,5,37,36,77,78,79,80,8,42,6,32,36,81,82,83,84,8,37,8,42,36,85,86,87,88,6,1,37,25,89,90,91,8,37,1,26,38,92,93,94,95,8,26,2,43,38,96,97,98,99,8,43,8,37,38,100,101,102,103};
2211 const int expected4[17]={0,7,16,25,34,41,50,59,68,75,84,93,102,109,118,127,136};
2212 const double expected5[208]={0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1.,0.,-1.5,0.5,0.,1.25,0.,0.7071067811865476,0.7071067811865476,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.7071067811865476,0.7071067811865476,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.7071067811865476,-0.7071067811865476,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.7071067811865476,-0.7071067811865476,1.0606601717798214,-1.0606601717798214,0.,0.,1.1,0.,1.1,1.,0.,1.,1.7,0.,1.7,1.,-1.1,1.,-1.1,0.,-1.7,0.,-1.7,1.,-1.7,-1.,-1.1,-1.,0.,-1.,1.1,-1.,1.7,-1.,1.118033988749895,1.,-1.118033988749895,1.,-1.118033988749895,-1.,1.118033988749895,-1.,0.7071067811865477,0.7071067811865476,0.5,0.,0.,0.5,1.05,0.,0.7071067811865475,0.7071067811865477,0.55,1.,1.1,0.5,1.4012585384440737,0.535233134659635,1.3,0.,1.1,0.5,1.1090169943749475,1.,0.,1.25,0.6123724356957946,1.369306393762915,1.1090169943749475,1.,0.55,1.,0.,0.5,-0.5,0.,-0.7071067811865477,0.7071067811865476,-0.7071067811865475,0.7071067811865477,-1.05,0.,-1.1,0.5,-0.55,1.,-1.3,0.,-1.4012585384440737,0.5352331346596344,-1.1090169943749475,1.,-1.1,0.5,-0.6123724356957941,1.3693063937629155,0.,1.25,-0.55,1.,-1.1090169943749475,1.,0.,-0.5,-0.7071067811865475,-0.7071067811865477,-0.5,0.,-1.05,0.,-0.7071067811865478,-0.7071067811865475,-0.55,-1.,-1.1,-0.5,-1.4012585384440734,-0.5352331346596354,-1.3,0.,-1.1,-0.5,-1.1090169943749475,-1.,0.,-1.25,-0.6123724356957945,-1.369306393762915,-1.1090169943749475,-1.,-0.55,-1.,0.7071067811865475,-0.7071067811865477,0.,-0.5,0.5,0.,0.7071067811865477,-0.7071067811865475,1.05,0.,1.1,-0.5,0.55,-1.,1.3,0.,1.4012585384440737,-0.535233134659635,1.1090169943749475,-1.,1.1,-0.5,0.6123724356957946,-1.369306393762915,0.,-1.25,0.55,-1.,1.1090169943749475,-1.0};
2213 CPPUNIT_ASSERT_EQUAL(136,m3->getNodalConnectivity()->getNumberOfTuples());
2214 CPPUNIT_ASSERT_EQUAL(17,m3->getNodalConnectivityIndex()->getNumberOfTuples());
2215 CPPUNIT_ASSERT(std::equal(expected3,expected3+136,m3->getNodalConnectivity()->getConstPointer()));
2216 CPPUNIT_ASSERT(std::equal(expected4,expected4+17,m3->getNodalConnectivityIndex()->getConstPointer()));
2217 for(int i=0;i<208;i++)
2218 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[i],m3->getCoords()->getIJ(0,i),1e-12);