1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2024 CEA, EDF
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 from medcoupling import *
25 from math import pi,e,sqrt,cos,sin
26 from datetime import datetime
27 from MEDCouplingDataForTest import MEDCouplingDataForTest
28 import rlcompleter,readline # this line has to be here,to ensure a usability of MEDCoupling/MEDLoader. B4 removing it please notify to anthony.geay@cea.fr
30 class MEDCouplingBasicsTest7(unittest.TestCase):
32 def testDAIGetIdsEqual1(self):
33 tab1=[5,-2,-4,-2,3,2,-2];
34 da=DataArrayInt64.New();
35 da.setValues(tab1,7,1);
36 da2=da.findIdsEqual(-2);
37 self.assertEqual(3,da2.getNumberOfTuples());
38 self.assertEqual(1,da2.getNumberOfComponents());
40 self.assertEqual(expected1,da2.getValues());
43 def testDAIGetIdsEqualList1(self):
44 tab1=[5,-2,-4,-2,3,2,-2];
45 da=DataArrayInt64.New();
46 da.setValues(tab1,7,1);
47 da2=da.findIdsEqualList([3,-2,0]);
48 self.assertEqual(4,da2.getNumberOfTuples());
49 self.assertEqual(1,da2.getNumberOfComponents());
51 self.assertEqual(expected1,da2.getValues());
54 def testDAIsUniform1(self):
56 da=DataArrayInt64.New();
57 da.setValues(tab1,5,1);
58 self.assertTrue(da.isUniform(1));
60 self.assertTrue(not da.isUniform(1));
62 self.assertTrue(da.isUniform(1));
63 da2=da.convertToDblArr();
64 self.assertTrue(da2.isUniform(1.,1.e-12));
65 da2.setIJ(1,0,1.+1.e-13);
66 self.assertTrue(da2.isUniform(1.,1.e-12));
67 da2.setIJ(1,0,1.+1.e-11);
68 self.assertTrue(not da2.isUniform(1.,1.e-12));
71 def testDAIBuildComplement1(self):
72 a=DataArrayInt64.New();
75 b=a.buildComplement(12);
76 self.assertEqual(8,b.getNumberOfTuples());
77 self.assertEqual(1,b.getNumberOfComponents());
78 expected1=[0,2,4,5,6,9,10,11]
80 self.assertEqual(expected1[i],b.getIJ(0,i));
84 def testDAIBuildUnion1(self):
85 a=DataArrayInt64.New();
87 a.setValues(tab1,4,1);
88 c=DataArrayInt64.New();
90 c.setValues(tab2,5,1);
92 self.assertEqual(7,b.getNumberOfTuples());
93 self.assertEqual(1,b.getNumberOfComponents());
94 expected1=[0,1,3,5,7,8,18]
96 self.assertEqual(expected1[i],b.getIJ(0,i));
98 b=DataArrayInt64.BuildUnion([a,c]);
99 self.assertEqual(7,b.getNumberOfTuples());
100 self.assertEqual(1,b.getNumberOfComponents());
101 expected1=[0,1,3,5,7,8,18]
103 self.assertEqual(expected1[i],b.getIJ(0,i));
107 def testDAIBuildIntersection1(self):
108 a=DataArrayInt64.New();
110 a.setValues(tab1,4,1);
111 c=DataArrayInt64.New();
113 c.setValues(tab2,5,1);
114 b=a.buildIntersection(c);
115 self.assertEqual(2,b.getNumberOfTuples());
116 self.assertEqual(1,b.getNumberOfComponents());
119 self.assertEqual(expected1[i],b.getIJ(0,i));
121 b=DataArrayInt64.BuildIntersection([a,c]);
122 self.assertEqual(2,b.getNumberOfTuples());
123 self.assertEqual(1,b.getNumberOfComponents());
126 self.assertEqual(expected1[i],b.getIJ(0,i));
130 def testDAIDeltaShiftIndex1(self):
131 a=DataArrayInt64.New();
133 a.setValues(tab,7,1);
134 b=a.deltaShiftIndex();
135 self.assertEqual(6,b.getNumberOfTuples());
136 self.assertEqual(1,b.getNumberOfComponents());
137 expected1=[2,3,1,0,2,6]
139 self.assertEqual(expected1[i],b.getIJ(0,i));
143 def testDAIBuildSubstraction1(self):
144 a=DataArrayInt64.New()
147 b=DataArrayInt64.New()
150 self.assertEqual([2,6,8],a.buildSubstraction(b).getValues())
153 def testDAIBuildPermutationArr1(self):
154 a=DataArrayInt64.New()
155 a.setValues([4,5,6,7,8],5,1)
156 b=DataArrayInt64.New()
157 b.setValues([5,4,8,6,7],5,1)
158 c=a.buildPermutationArr(b)
159 self.assertEqual([1,0,4,2,3],c.getValues())
160 self.assertTrue(a.isEqualWithoutConsideringStrAndOrder(b))
162 self.assertTrue(not a.isEqualWithoutConsideringStrAndOrder(b))
163 self.assertRaises(InterpKernelException,a.buildPermutationArr,b)
166 b.setIJ(4,0,4)#a==[4,5,6,4,8] and b==[5,4,8,6,4]
167 self.assertTrue(a.isEqualWithoutConsideringStrAndOrder(b))
168 c=a.buildPermutationArr(b)
169 self.assertEqual([1,3,4,2,3],c.getValues())
170 d=b.convertToDblArr()
173 self.assertEqual(expect3,b.getValues())
175 self.assertEqual(5,d.getNumberOfTuples());
176 self.assertEqual(1,d.getNumberOfComponents());
178 self.assertAlmostEqual(float(expect3[i]),d.getIJ(i,0),14);
182 def testDAIAggregateMulti1(self):
183 a=DataArrayInt64.New()
184 a.setValues(list(range(4)),2, 2)
186 b=DataArrayInt64.New()
187 b.setValues(list(range(6)), 3, 2)
188 c=DataArrayInt64.Aggregate([a,b])
189 self.assertEqual(list(range(4)) + list(range(6)), c.getValues())
190 self.assertEqual("aa",c.getName())
191 self.assertEqual(5,c.getNumberOfTuples())
192 self.assertEqual(2,c.getNumberOfComponents())
195 def testDAICheckAndPreparePermutation1(self):
196 vals1=[9,10,0,6,4,11,3,7];
197 expect1=[5,6,0,3,2,7,1,4];
198 vals2=[9,10,0,6,10,11,3,7];
199 da=DataArrayInt64.New();
200 da.setValues(vals1,8,1);
201 da2=da.checkAndPreparePermutation();
202 self.assertEqual(8,da2.getNumberOfTuples());
203 self.assertEqual(1,da2.getNumberOfComponents());
205 self.assertEqual(expect1[i],da2.getIJ(i,0));
208 da=DataArrayInt64.New();
211 da2=da.checkAndPreparePermutation();
212 self.assertEqual(1,da2.getNumberOfComponents());
213 self.assertTrue(da2.isIota(8));
215 da=DataArrayInt64.New();
217 da.setValues(vals2,8,1);
218 self.assertRaises(InterpKernelException,da.checkAndPreparePermutation);
221 def testDAIChangeSurjectiveFormat1(self):
222 vals1=[0,3,2,3,2,2,1,2]
223 expected1=[0,1,2,6,8]
224 expected2=[0, 6, 2,4,5,7, 1,3]
225 da=DataArrayInt64.New();
226 da.setValues(vals1,8,1);
228 da2,da2I=da.changeSurjectiveFormat(4);
229 self.assertEqual(5,da2I.getNumberOfTuples());
230 self.assertEqual(8,da2.getNumberOfTuples());
231 self.assertEqual(expected1,da2I.getValues());
232 self.assertEqual(expected2,da2.getValues());
234 self.assertRaises(InterpKernelException,da.changeSurjectiveFormat,3);
238 def testDAIGetIdsNotEqual1(self):
239 d=DataArrayInt64.New();
240 vals1=[2,3,5,6,8,5,5,6,1,-5]
241 d.setValues(vals1,10,1);
242 d2=d.findIdsNotEqual(5);
243 self.assertEqual(7,d2.getNumberOfTuples());
244 self.assertEqual(1,d2.getNumberOfComponents());
245 expected1=[0,1,3,4,7,8,9]
247 self.assertEqual(expected1[i],d2.getIJ(0,i));
250 self.assertRaises(InterpKernelException,d.findIdsNotEqual,5);
254 d3=d.findIdsNotEqualList(vals3);
255 self.assertEqual(5,d3.getNumberOfTuples());
256 self.assertEqual(1,d3.getNumberOfComponents());
257 expected2=[0,1,4,8,9]
259 self.assertEqual(expected2[i],d3.getIJ(0,i));
263 def testDAIComputeOffsets1(self):
264 d=DataArrayInt64.New();
266 expected1=[0,3,8,9,11,11]
267 d.setValues(vals1,6,1);
269 self.assertEqual(6,d.getNumberOfTuples());
270 self.assertEqual(1,d.getNumberOfComponents());
272 self.assertEqual(expected1[i],d.getIJ(0,i));
276 def testDAITransformWithIndArr1(self):
277 if not MEDCouplingUse64BitIDs():
280 tab2=[0,1,1,3,3,0,1,3,2,2,3,0]
281 expected=[17,18,18,19,19,17,18,19,22,22,19,17]
282 d=DataArrayInt64.New();
283 d.setValues(tab1,4,1);
284 d1=DataArrayInt64.New();
285 d1.setValues(tab2,12,1);
288 d1.transformWithIndArr(d);
289 self.assertEqual(12,d1.getNumberOfTuples());
290 self.assertEqual(1,d1.getNumberOfComponents());
292 self.assertEqual(expected[i],d1.getIJ(i,0));
296 d1.transformWithIndArr(tab1)
297 self.assertEqual(12,d1.getNumberOfTuples());
298 self.assertEqual(1,d1.getNumberOfComponents());
300 self.assertEqual(expected[i],d1.getIJ(i,0));
304 def testDAIBuildPermArrPerLevel1(self):
305 arr=[2,0,1,1,0,1,2,0,1,1,0,0]
306 expected1=[10,0,5,6,1,7,11,2,8,9,3,4]
307 da=DataArrayInt64.New();
308 da.setValues(arr,12,1);
309 da2=da.buildPermArrPerLevel();
310 self.assertEqual(12,da2.getNumberOfTuples());
311 self.assertEqual(1,da2.getNumberOfComponents());
313 self.assertEqual(expected1[i],da2.getIJ(i,0));
317 def testDAIOperations1(self):
318 arr1=[-1,-2,4,7,3,2,6,6,4,3,0,1]
319 da=DataArrayInt64.New();
320 da.setValues(arr1,4,3);
321 da1=DataArrayInt64.New();
324 self.assertRaises(InterpKernelException,DataArrayInt64.Add,da,da1);#not same number of tuples/Components
326 da2=DataArrayInt64.Add(da,da1);
327 self.assertEqual(4,da2.getNumberOfTuples());
328 self.assertEqual(3,da2.getNumberOfComponents());
329 expected1=[1,1,8,12,9,9,14,15,14,14,12,14]
331 self.assertEqual(expected1[i],da2.getIJ(0,i));
333 da1.substractEqual(da);
334 expected2=[3,5,0,-2,3,5,2,3,6,8,12,12]
336 self.assertEqual(expected2[i],da1.getIJ(0,i));
338 da1.rearrange(1); da1.iota(2); da1.rearrange(3);
341 self.assertEqual(expected1[i],da1.getIJ(0,i));
343 da1.rearrange(1); da1.iota(2); da1.rearrange(3);
344 da2=DataArrayInt64.Multiply(da,da1);
345 self.assertEqual(4,da2.getNumberOfTuples());
346 self.assertEqual(3,da2.getNumberOfComponents());
347 expected3=[-2,-6,16,35,18,14,48,54,40,33,0,13]
349 self.assertEqual(expected3[i],da2.getIJ(0,i));
352 self.assertEqual(4,da.getNumberOfTuples());
353 self.assertEqual(3,da.getNumberOfComponents());
354 expected4=[0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]
356 self.assertEqual(expected4[i],da.getIJ(0,i));
358 da.setValues(arr1,4,3);
359 da1.multiplyEqual(da);
360 self.assertEqual(4,da1.getNumberOfTuples());
361 self.assertEqual(3,da1.getNumberOfComponents());
363 self.assertEqual(expected3[i],da1.getIJ(0,i));
365 da1.rearrange(1); da1.iota(2); da1.rearrange(3);
366 da2=DataArrayInt64.Divide(da,da1);
367 self.assertEqual(4,da2.getNumberOfTuples());
368 self.assertEqual(3,da2.getNumberOfComponents());
370 self.assertEqual(expected4[i],da2.getIJ(0,i));
373 self.assertEqual(4,da1.getNumberOfTuples());
374 self.assertEqual(3,da1.getNumberOfComponents());
375 expected5=[160,107,80,64,53,45,40,35,32,29,26,24]
377 self.assertEqual(expected5[i],da1.getIJ(0,i));
379 da1.applyDivideBy(2);
380 self.assertEqual(4,da1.getNumberOfTuples());
381 self.assertEqual(3,da1.getNumberOfComponents());
382 expected6=[80,53,40,32,26,22,20,17,16,14,13,12]
384 self.assertEqual(expected6[i],da1.getIJ(0,i));
386 expected7=[3,4,5,4,5,1,6,3,2,0,6,5]
389 self.assertEqual(expected7[i],da1.getIJ(0,i));
392 expected8=[3,3,3,3,3,1,3,3,0,0,3,3]
393 da1.applyRModulus(3);
395 self.assertEqual(expected8[i],da1.getIJ(0,i));
399 def testDAITransformWithIndArrR1(self):
401 tab2=[-1,-1,0,1,2,3,4,5,-1,-1,-1,-1]
402 expected=[0,3,1,2,4,5]
403 d=DataArrayInt64.New();
404 d.setValues(tab1,6,1);
405 d1=DataArrayInt64.New();
406 d1.setValues(tab2,12,1);
409 d3=d.transformWithIndArrR(d1);
410 self.assertEqual(6,d3.getNumberOfTuples());
411 self.assertEqual(1,d3.getNumberOfComponents());
413 self.assertEqual(expected[i],d3.getIJ(i,0));
417 d3=d.transformWithIndArrR(tab2)
418 self.assertEqual(6,d3.getNumberOfTuples());
419 self.assertEqual(1,d3.getNumberOfComponents());
421 self.assertEqual(expected[i],d3.getIJ(i,0));
425 def testDAISplitByValueRange1(self):
426 val1=[6,5,0,3,2,7,8,1,4]
428 d=DataArrayInt64.New();
429 d.setValues(val1,9,1);
430 e,f,g=d.splitByValueRange(val2);
431 self.assertEqual(9,e.getNumberOfTuples());
432 self.assertEqual(1,e.getNumberOfComponents());
433 self.assertEqual(9,f.getNumberOfTuples());
434 self.assertEqual(1,f.getNumberOfComponents());
435 self.assertEqual(2,g.getNumberOfTuples());
436 self.assertEqual(1,g.getNumberOfComponents());
438 expected1=[1,1,0,0,0,1,1,0,1]
439 expected2=[2,1,0,3,2,3,4,1,0]
441 self.assertEqual(expected1[i],e.getIJ(i,0));
442 self.assertEqual(expected2[i],f.getIJ(i,0));
444 self.assertEqual(0,g.getIJ(0,0));
445 self.assertEqual(1,g.getIJ(1,0));
448 self.assertRaises(InterpKernelException,d.splitByValueRange,val2);
449 # non regression test in python wrapping
450 rg=DataArrayInt64([0,10,29,56,75,102,121,148,167,194,213,240,259,286,305,332,351,378,397,424,443,470,489,516])
451 a,b,c=DataArrayInt64([75]).splitByValueRange(rg)
452 self.assertTrue(a.isEqual(DataArrayInt64([4])))
453 self.assertTrue(b.isEqual(DataArrayInt64([0])))
454 self.assertTrue(c.isEqual(DataArrayInt64([4])))
457 def testDAIBuildExplicitArrByRanges1(self):
458 d=DataArrayInt64.New();
460 d.setValues(vals1,3,1);
461 e=DataArrayInt64.New();
462 vals2=[0,3,6,10,14,20]
463 e.setValues(vals2,6,1);
465 f=d.buildExplicitArrByRanges(e);
466 self.assertEqual(11,f.getNumberOfTuples());
467 self.assertEqual(1,f.getNumberOfComponents());
468 expected1=[0,1,2,6,7,8,9,10,11,12,13]
470 self.assertEqual(expected1[i],f.getIJ(i,0));
474 def testDAIComputeOffsets2(self):
475 d=DataArrayInt64.New();
477 expected1=[0,3,8,9,11,11,19]
478 d.setValues(vals1,6,1);
479 d.computeOffsetsFull();
480 self.assertEqual(7,d.getNumberOfTuples());
481 self.assertEqual(1,d.getNumberOfComponents());
483 self.assertEqual(expected1[i],d.getIJ(0,i));
487 def testDAIBuildOld2NewArrayFromSurjectiveFormat2(self):
490 a=DataArrayInt.New();
491 a.setValues(arr,5,1);
492 b=DataArrayInt.New();
493 b.setValues(arrI,3,1);
494 ret,newNbTuple=DataArrayInt64.ConvertIndexArrayToO2N(10,a,b);
495 expected=[0,1,2,0,3,4,5,4,6,4]
496 self.assertEqual(10,ret.getNbOfElems());
497 self.assertEqual(7,newNbTuple);
498 self.assertEqual(1,ret.getNumberOfComponents());
499 self.assertEqual(expected,ret.getValues());
500 self.assertRaises(InterpKernelException,DataArrayInt64.ConvertIndexArrayToO2N,9,a,b);
503 def testDAIBuildUnique1(self):
504 d=DataArrayInt64([1,2,2,3,3,3,3,4,5,5,7,7,7,19])
506 self.assertTrue(e.isEqual(DataArrayInt64([1,2,3,4,5,7,19])))
509 def testDAIPartitionByDifferentValues1(self):
510 d=DataArrayInt64([1,0,1,2,0,2,2,-3,2])
511 expected=[[-3,[7]],[0,[1,4]],[1,[0,2]],[2,[3,5,6,8]]]
512 for i,elt in enumerate(zip(*d.partitionByDifferentValues())):
513 self.assertEqual(expected[i][0],elt[1])
514 self.assertEqual(expected[i][1],elt[0].getValues())
518 def testDAICheckMonotonic1(self):
520 data2=[6,2,0,-8,-9,-56]
523 d=DataArrayInt64.New(data1);
524 self.assertTrue(d.isMonotonic(True));
525 self.assertTrue(not d.isMonotonic(False));
526 d.checkMonotonic(True);
527 self.assertRaises(InterpKernelException,d.checkMonotonic,False)
528 d=DataArrayInt64.New(data2);
529 self.assertTrue(d.isMonotonic(False));
530 self.assertTrue(not d.isMonotonic(True));
531 d.checkMonotonic(False);
532 self.assertRaises(InterpKernelException,d.checkMonotonic,True)
533 d=DataArrayInt64.New(data3);
534 self.assertTrue(not d.isMonotonic(False));
535 self.assertTrue(not d.isMonotonic(True));
536 self.assertRaises(InterpKernelException,d.checkMonotonic,True)
537 self.assertRaises(InterpKernelException,d.checkMonotonic,False)
538 d=DataArrayInt64.New(data4);
539 self.assertTrue(not d.isMonotonic(False));
540 self.assertTrue(not d.isMonotonic(True));
541 self.assertRaises(InterpKernelException,d.checkMonotonic,True)
542 self.assertRaises(InterpKernelException,d.checkMonotonic,False)
543 d=DataArrayInt64.New(0,1)
544 self.assertTrue(d.isMonotonic(True));
545 self.assertTrue(d.isMonotonic(False));
546 d.checkMonotonic(True);
547 d.checkMonotonic(False);
548 d=DataArrayInt64.New(data4,3,2);#throw because nbComp!=1
549 self.assertRaises(InterpKernelException,d.isMonotonic,True)
550 self.assertRaises(InterpKernelException,d.isMonotonic,False)
551 self.assertRaises(InterpKernelException,d.checkMonotonic,True)
552 self.assertRaises(InterpKernelException,d.checkMonotonic,False)
555 def testDAIBuildSubstractionOptimized1(self):
556 da1=DataArrayInt64.New([1,3,5,6,7,9,13])
557 da2=DataArrayInt64.New([3,5,9])
558 da3=DataArrayInt64.New([1,3,5])
559 da4=DataArrayInt64.New([1,3,5,6,7,9,13])
561 a=da1.buildSubstractionOptimized(da2);
562 self.assertTrue(a.isEqual(DataArrayInt64([1,6,7,13])));
564 a=da1.buildSubstractionOptimized(da3);
565 self.assertTrue(a.isEqual(DataArrayInt64([6,7,9,13])));
567 a=da1.buildSubstractionOptimized(da4);
568 self.assertTrue(a.isEqual(DataArrayInt64([])));
571 def testDAIIsStrictlyMonotonic1(self):
572 da1=DataArrayInt64.New([1,3,5,6,7,9,13])
573 self.assertTrue(da1.isStrictlyMonotonic(True));
574 da1.checkStrictlyMonotonic(True);
575 self.assertTrue(da1.isMonotonic(True));
576 da1.checkMonotonic(True);
577 self.assertTrue(not da1.isStrictlyMonotonic(False));
578 self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,False)
579 self.assertTrue(not da1.isMonotonic(False));
580 self.assertRaises(InterpKernelException,da1.checkMonotonic,False)
582 da1=DataArrayInt64.New([1,3,5,6,6,9,13])
583 self.assertTrue(not da1.isStrictlyMonotonic(True));
584 self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,True)
585 self.assertTrue(da1.isMonotonic(True));
586 da1.checkMonotonic(True);
587 self.assertTrue(not da1.isStrictlyMonotonic(False));
588 self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,False)
589 self.assertTrue(not da1.isMonotonic(False));
590 self.assertRaises(InterpKernelException,da1.checkMonotonic,False)
592 da1=DataArrayInt64.New([1,3,5,6,5,9,13])
593 self.assertTrue(not da1.isStrictlyMonotonic(True));
594 self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,True)
595 self.assertTrue(not da1.isMonotonic(True));
596 self.assertRaises(InterpKernelException,da1.checkMonotonic,True)
597 self.assertTrue(not da1.isStrictlyMonotonic(False));
598 self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,False)
599 self.assertTrue(not da1.isMonotonic(False));
600 self.assertRaises(InterpKernelException,da1.checkMonotonic,False)
602 da1=DataArrayInt64.New([13,9,7,6,5,3,1])
603 self.assertTrue(not da1.isStrictlyMonotonic(True));
604 self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,True)
605 self.assertTrue(not da1.isMonotonic(True));
606 self.assertRaises(InterpKernelException,da1.checkMonotonic,True)
607 self.assertTrue(da1.isStrictlyMonotonic(False));
608 da1.checkStrictlyMonotonic(False);
609 self.assertTrue(da1.isMonotonic(False));
610 da1.checkMonotonic(False);
612 da1=DataArrayInt64.New([13,9,6,6,5,3,1])
613 self.assertTrue(not da1.isStrictlyMonotonic(True));
614 self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,True)
615 self.assertTrue(not da1.isMonotonic(True));
616 self.assertRaises(InterpKernelException,da1.checkMonotonic,True)
617 self.assertTrue(not da1.isStrictlyMonotonic(False));
618 self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,False)
619 self.assertTrue(da1.isMonotonic(False));
620 da1.checkMonotonic(False);
622 da1=DataArrayInt64.New([13,9,5,6,5,3,1])
623 self.assertTrue(not da1.isStrictlyMonotonic(True));
624 self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,True)
625 self.assertTrue(not da1.isMonotonic(True));
626 self.assertRaises(InterpKernelException,da1.checkMonotonic,True)
627 self.assertTrue(not da1.isStrictlyMonotonic(False));
628 self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,False)
629 self.assertTrue(not da1.isMonotonic(False));
630 self.assertRaises(InterpKernelException,da1.checkMonotonic,False)
632 da1=DataArrayInt64.New([])
633 self.assertTrue(da1.isStrictlyMonotonic(True));
634 da1.checkStrictlyMonotonic(True);
635 self.assertTrue(da1.isMonotonic(True));
636 da1.checkMonotonic(True);
637 self.assertTrue(da1.isStrictlyMonotonic(False));
638 da1.checkStrictlyMonotonic(False);
639 self.assertTrue(da1.isMonotonic(False));
640 da1.checkMonotonic(False);
642 da1=DataArrayInt64.New([13])
643 self.assertTrue(da1.isStrictlyMonotonic(True));
644 da1.checkStrictlyMonotonic(True);
645 self.assertTrue(da1.isMonotonic(True));
646 da1.checkMonotonic(True);
647 self.assertTrue(da1.isStrictlyMonotonic(False));
648 da1.checkStrictlyMonotonic(False);
649 self.assertTrue(da1.isMonotonic(False));
650 da1.checkMonotonic(False);
653 def testDAIIndicesOfSubPart(self):
654 a=DataArrayInt64([9,10,0,6,4,11,3,8])
655 b=DataArrayInt64([6,0,11,8])
656 c=a.indicesOfSubPart(b)
657 self.assertTrue(c.isEqual(DataArrayInt([3,2,5,7])))
659 d=DataArrayInt64([9,10,0,6,4,11,0,8])
660 self.assertRaises(InterpKernelException,d.indicesOfSubPart,b) # 0 appears twice in the d array
661 f=DataArrayInt64([6,0,11,8,12])
662 self.assertRaises(InterpKernelException,a.indicesOfSubPart,f) # 12 in f does not exist in a
665 def testDAIsortToHaveConsecutivePairs(self):
666 dref=DataArrayInt64([(6, 216), (216, 218), (218, 220), (220, 222), (222, 224), (224, 226)])
667 dtest=DataArrayInt64([(6, 216), (218, 216), (224, 226), (222, 220), (218, 220), (222, 224)])
668 dtest.sortToHaveConsecutivePairs()
669 self.assertTrue(dtest.isEqual(dref))
671 def testDAIFromLinkedListOfPairToList1(self):
672 d=DataArrayInt64([(5,7),(7,3),(3,12),(12,17)])
673 zeRes=DataArrayInt64([5,7,3,12,17])
674 self.assertTrue(d.fromLinkedListOfPairToList().isEqual(zeRes))
676 self.assertRaises(InterpKernelException,d.fromLinkedListOfPairToList)
678 self.assertTrue(d.fromLinkedListOfPairToList().isEqual(zeRes))
679 d2=DataArrayInt64([(5,7)])
680 self.assertTrue(d2.fromLinkedListOfPairToList().isEqual(DataArrayInt64([5,7])))
681 d3=DataArrayInt64([(5,7),(7,3),(4,12),(12,17)])
682 self.assertRaises(InterpKernelException,d3.fromLinkedListOfPairToList) # not a linked list of pair
683 d4=DataArrayInt64([(5,7),(7,3),(12,3),(12,17)])
684 self.assertRaises(InterpKernelException,d4.fromLinkedListOfPairToList) # not a linked list of pair, but can be repaired !
685 d4.sortEachPairToMakeALinkedList()
686 self.assertTrue(d4.fromLinkedListOfPairToList().isEqual(zeRes))
689 def testDAIfindIdsExt1(self):
690 d=DataArrayInt64([4,6,-2,3,7,0,10])
691 self.assertTrue(d.findIdsGreaterOrEqualTo(3).isEqual(DataArrayInt([0,1,3,4,6])))
692 self.assertTrue(d.findIdsGreaterThan(3).isEqual(DataArrayInt([0,1,4,6])))
693 self.assertTrue(d.findIdsLowerThan(3).isEqual(DataArrayInt([2,5])))
694 self.assertTrue(d.findIdsLowerOrEqualTo(3).isEqual(DataArrayInt([2,3,5])))
697 def testDAICheckUniformAndGuess1(self):
698 d=DataArrayInt64([3,3],1,2)
699 self.assertRaises(InterpKernelException,d.checkUniformAndGuess)# non single compo
701 self.assertRaises(InterpKernelException,d.checkUniformAndGuess)# empty
703 self.assertRaises(InterpKernelException,d.checkUniformAndGuess)# non allocated
704 d=DataArrayInt64([3,3,3])
705 self.assertEqual(3,d.checkUniformAndGuess())
706 d=DataArrayInt64([7])
707 self.assertEqual(7,d.checkUniformAndGuess())
708 d=DataArrayInt64([3,4,3])
709 self.assertRaises(InterpKernelException,d.checkUniformAndGuess)# non uniform
712 def testDAIFindIdForEach1(self):
713 a1=DataArrayInt64([17,27,2,10,-4,3,12,27,16])
714 b1=DataArrayInt64([3,16,-4,27,17])
715 ret=a1.findIdForEach(b1)
716 self.assertTrue(ret.isEqual(DataArrayInt([5,8,4,7,0])))
717 self.assertTrue(a1[ret].isEqual(b1))
718 b2=DataArrayInt64([3,16,22,27,17])
719 self.assertRaises(InterpKernelException,a1.findIdForEach,b2) # 22 not in a1 !
721 self.assertRaises(InterpKernelException,a1.findIdForEach,b1) # a1 is not single component
724 def testGlobalHelpers(self):
725 arr0 = vtk2med_cell_types()
726 self.assertEqual(len(arr0),43)
727 arr1 = med2vtk_cell_types()
728 self.assertEqual(len(arr1),34)
729 arr2 = AllGeometricTypes()
730 self.assertEqual(len(arr2),25)
732 MEDCouplingUMesh.GetReprOfGeometricType(elt)
733 self.assertNotEqual(MEDCouplingUMesh.GetDimensionOfGeometricType(elt),-1)
736 def testVoronoi2D_3(self):
738 Non regression test for EDF20418 : After 8.5.0 MEDCouplingUMesh.Interset2DMeshes method (called by voronoize) is sensible to cell orientation of 2 input meshes. This test check correct behavior in
739 case of non standard orientation input cell.
741 coo = DataArrayDouble([0.018036113896685007,0.030867224641316506,0.019000000000000003,0.030833333333333407,0.018518056948342503,0.030850278987324904,0.018773068345659904,0.031180320157635305,0.018546136691319805,0.031527306981937307,0.018291125294002404,0.031197265811626906],6,2)
742 m = MEDCouplingUMesh("mesh",2)
745 m.insertNextCell(NORM_TRI3,[0,1,4])
746 f=MEDCouplingFieldDouble(ON_GAUSS_PT)
748 f.setArray(DataArrayDouble([12613576.708019681, 18945164.734307285, 22385248.637775388, 17074219.938821714, 19361929.467164982, 19258841.562907547]))
749 f.setGaussLocalizationOnType(NORM_TRI3,[0, 0, 1, 0, 0, 1],[0.0915762, 0.0915762, 0.816848, 0.0915762, 0.0915762, 0.816848, 0.445948, 0.108103, 0.445948, 0.445948, 0.108103, 0.445948],[0.0549759, 0.0549759, 0.0549759, 0.111691, 0.111691, 0.111691])
751 f_voro = f.voronoize(1e-13)
752 ref_area = DataArrayDouble([4.6679303278867127, 4.2514546761810138, 4.2514546761809337, 6.6206415950989804, 6.2643538685231039, 6.6206415950989884])
753 area = f_voro.buildMeasureField(True).getArray()*1e8
754 self.assertTrue(ref_area.isEqual(area,1e-6))
755 ref_bary = DataArrayDouble([(0.018231625096313969, 0.030950287685553721), (0.018826045778781105, 0.030916927013719033), (0.018533397739746087, 0.031364396601025746), (0.018541498169815956, 0.030944333493252929), (0.018660195622447071, 0.031132366117047686), (0.018400646702087166, 0.031159700554391174)])
756 bary = f_voro.getMesh().computeCellCenterOfMass()
757 self.assertTrue(ref_bary.isEqual(bary,1e-8))
758 self.assertTrue(f_voro.getArray().isEqual(f.getArray(),1e-8))
761 def testDAIOccurenceRankInThis(self):
762 arr=DataArrayInt([5,3,2,1,4,5,2,1,0,11,5,4])
763 self.assertTrue(arr.occurenceRankInThis().isEqual(DataArrayInt([0,0,0,0,0,1,1,1,0,0,2,1])))
765 def testDAIFindPermutationFromFirstToSecondDuplicate(self):
766 arr0 = DataArrayInt([5,3,2,1,4,5,2,1,0,11,5,4])
767 arr1 = DataArrayInt([0,1,1,2,2,3,4,4,5,5,5,11])
768 self.assertTrue(DataArrayInt.FindPermutationFromFirstToSecondDuplicate(arr0,arr1).isEqual(DataArrayInt([8,5,3,1,6,9,4,2,0,11,10,7])))
769 self.assertTrue(DataArrayInt.FindPermutationFromFirstToSecondDuplicate(arr1,arr0).isEqual(DataArrayInt([8,3,7,2,6,1,4,11,0,5,10,9])))
771 def testDAIIndexOfSameConsecutiveValueGroups(self):
772 arr = DataArrayInt([0,1,1,2,2,3,4,4,5,5,5,11])
773 self.assertTrue(arr.indexOfSameConsecutiveValueGroups().isEqual(DataArrayInt([0,1,3,5,6,8,11,12])))
775 def testSkyLineGroupPacks(self):
776 arr = DataArrayInt([1,4,5,0,2,4,5,6,1,3,5,6,7,2,6,7,0,1,5,8,9,0,1,2,4,6,8,9,10,1,2,3,5,7,9,10,11,2,3,6,10,11,4,5,9,12,13,4,5,6,8,10,12,13,14,5,6,7,9,11,13,14,15,6,7,10,14,15,8,9,13,8,9,10,12,14,9,10,11,13,15,10,11,14])
777 arrI = DataArrayInt([0,3,8,13,16,21,29,37,42,47,55,63,68,71,76,81,84])
778 sk = MEDCouplingSkyLineArray(arrI,arr)
779 part = DataArrayInt([0,3,4,7,16])
780 sk2 = sk.groupPacks(part)
781 self.assertTrue(sk2.getValuesArray().isEqual(arr))
782 self.assertTrue(sk2.getIndexArray().isEqual(DataArrayInt([0,13,16,37,84])))
784 def testSkyLineUniqueNotSortedByPack(self):
785 arrI = DataArrayInt([0,3,9,15,18,24,36,48,54])
786 arr = DataArrayInt([1,4,5,0,4,5,2,5,6,3,6,7,1,5,6,2,6,7,0,1,5,5,8,9,0,1,4,6,9,10,1,2,4,6,8,9,2,3,5,7,9,10,1,2,5,7,10,11,2,3,6,6,10,11])
787 sk = MEDCouplingSkyLineArray(arrI,arr)
788 sk2 = sk.uniqueNotSortedByPack()
789 self.assertTrue(sk2.getIndexArray().isEqual(DataArrayInt([0,3,8,13,16,21,29,37,42])))
790 self.assertTrue(sk2.getValuesArray().isEqual(DataArrayInt([1,4,5,0,2,4,5,6,1,3,5,6,7,2,6,7,0,1,5,8,9,0,1,2,4,6,8,9,10,1,2,3,5,7,9,10,11,2,3,6,10,11])))
792 def testSkyLineAggregatePacks1(self):
793 arr = DataArrayDouble(3) ; arr.iota()
794 m = MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m = m.buildUnstructured()
795 a,b = m.computeEnlargedNeighborsOfNodes()
796 sk = MEDCouplingSkyLineArray(b,a)
798 sk1.getValuesArray()[:] *= 2
800 sk2.getValuesArray()[:] *= 3
801 skOut = MEDCouplingSkyLineArray.AggregatePacks([sk,sk1,sk2])
802 self.assertTrue(skOut.getIndexArray().isEqual(DataArrayInt([0,9,24,33,48,72,87,96,111,120])))
803 self.assertTrue(skOut.getValuesArray().isEqual(DataArrayInt([1,3,4,2,6,8,3,9,12,0,2,3,4,5,0,4,6,8,10,0,6,9,12,15,1,4,5,2,8,10,3,12,15,0,1,4,6,7,0,2,8,12,14,0,3,12,18,21,0,1,2,3,5,6,7,8,0,2,4,6,10,12,14,16,0,3,6,9,15,18,21,24,1,2,4,7,8,2,4,8,14,16,3,6,12,21,24,3,4,7,6,8,14,9,12,21,3,4,5,6,8,6,8,10,12,16,9,12,15,18,24,4,5,7,8,10,14,12,15,21])))
805 def testDACopySorted1(self):
806 d = DataArrayInt32([5,1,100,20])
807 self.assertTrue(d.copySorted().isEqual(DataArrayInt32([1,5,20,100])))
808 d = DataArrayInt64([5,1,100,20])
809 self.assertTrue(d.copySorted().isEqual(DataArrayInt64([1,5,20,100])))
810 d = DataArrayInt([5,1,100,20])
811 self.assertTrue(d.copySorted().isEqual(DataArrayInt([1,5,20,100])))
812 d = DataArrayDouble([5,1,100,20])
813 self.assertTrue(d.copySorted().isEqual(DataArrayDouble([1,5,20,100]),1e-10))
815 def testFieldAreStrictlyCompatible(self):
816 arr=DataArrayDouble(10) ; arr.iota()
817 m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m=m.buildUnstructured()
818 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setMesh(m)
819 f2=MEDCouplingFieldDouble(ON_CELLS) ; f2.setMesh(m)
820 self.assertTrue(f.areStrictlyCompatible(f2))
821 self.assertTrue(f.areStrictlyCompatibleForMulDiv(f2))
822 f2.setMesh(f2.getMesh().deepCopy())
823 self.assertTrue(not f.areStrictlyCompatible(f2))
824 self.assertTrue(not f.areStrictlyCompatibleForMulDiv(f2))
825 f3=MEDCouplingFieldDouble(ON_NODES) ; f3.setMesh(m)
826 self.assertTrue(not f.areStrictlyCompatible(f3))
827 self.assertTrue(not f.areStrictlyCompatibleForMulDiv(f3))
829 def testBugZipConnectivityTraducer(self):
831 Non regression test : here cell #1 and cell #2 are nearly the same but not the same. zipConnectivityTraducer called by areCellsIncludedIn
832 failed to capture that.
834 coo = DataArrayDouble([0,1,2,3],4,1)
835 m = MEDCouplingUMesh("",1)
838 m.insertNextCell(NORM_SEG2,[0,1])
839 m.insertNextCell(NORM_SEG2,[1,2])
840 m.insertNextCell(NORM_SEG2,[2,1])
842 a,b = m.areCellsIncludedIn(m,0)
844 self.assertTrue(b.isIota(3))
846 self.assertTrue(m.deepCopy().zipConnectivityTraducer(0).isIota(3))
847 self.assertTrue(m.deepCopy().zipConnectivityTraducer(1).isIota(3))
848 self.assertTrue(m.deepCopy().zipConnectivityTraducer(2).isEqual(DataArrayInt([0,1,1])))
850 def testBugAreCellsIncludedIn1(self):
852 Non regression test: a.areCellsIncludedIn(b) was buggy when some cells in b were duplicated into a following specified policy.
854 coo = DataArrayDouble([0,1,2,3,4],5,1)
855 m = MEDCouplingUMesh("",1)
858 # m contains several duplicated cells - some of those duplicated cells will be in m1
860 m.insertNextCell(NORM_SEG2,[0,1])
862 m.insertNextCell(NORM_SEG2,[1,2])
864 m.insertNextCell(NORM_SEG2,[2,3])
866 m.insertNextCell(NORM_SEG2,[3,4])
868 bexp = DataArrayInt([0,1,2, 3,4,5,6, 9,10])
871 a,b = m.areCellsIncludedIn(m1,0)
873 self.assertTrue(b.isEqual(DataArrayInt([2,2,2, 6,6,6,6, 10,10])))
875 bexp2 = DataArrayInt([0,1,2, 3,4,0, 6, 9,10])
877 a,b = m.areCellsIncludedIn(m2,0)
879 self.assertTrue(b.isEqual(DataArrayInt([2,2,2,6,6,2,6,10,10])))
881 def testSkyLineArrayThreshold(self):
882 x = DataArrayInt([0, 1, 2, 11, 12, 13, 3, 4, 5, 6, 14, 15, 16, 17, 9, 10, 18, 19])
883 xi = DataArrayInt([0, 6, 14, 18])
884 sk = MEDCouplingSkyLineArray(xi,x)
885 lsk,rsk = sk.thresholdPerPack(11)
886 self.assertTrue(lsk.getValuesArray().isEqual(DataArrayInt([0, 1, 2, 3, 4, 5, 6, 9, 10])))
887 self.assertTrue(lsk.getIndexArray().isEqual(DataArrayInt([0, 3, 7, 9])))
888 self.assertTrue(rsk.getValuesArray().isEqual(DataArrayInt([11, 12, 13, 14, 15, 16, 17, 18, 19])))
889 self.assertTrue(rsk.getIndexArray().isEqual(DataArrayInt([0, 3, 7, 9])))
891 def testPenta18GaussNE(self):
892 conn = [1,0,2,4,3,5,6,7,8,9,13,14,11,10,15,12,17,16]
893 coo = DataArrayDouble([(27.237499999999997, 9.8, 0.0), (26.974999999999994, 9.8, 0.0), (27.111517409545634, 9.532083869948877, 0.0), (27.237499999999997, 9.8, 0.5000000000000001), (26.974999999999994, 9.8, 0.5000000000000002), (27.111517409545634, 9.532083869948877, 0.5), (27.106249999999996, 9.8, 0.0), (27.17450870477282, 9.666041934974439, 0.0), (27.04325870477281, 9.666041934974439, 0.0), (27.106249999999996, 9.8, 0.5000000000000001), (27.237499999999997, 9.8, 0.25), (26.974999999999994, 9.8, 0.2500000000000001), (27.106249999999996, 9.8, 0.2500000000000001), (27.174508704772816, 9.666041934974439, 0.5), (27.043258704772814, 9.666041934974439, 0.5000000000000001), (27.111517409545634, 9.532083869948877, 0.25), (27.043258704772818, 9.666041934974436, 0.25000000000000006), (27.174508704772816, 9.666041934974436, 0.25)])
894 m = MEDCouplingUMesh("mesh",3)
897 m.insertNextCell(NORM_PENTA18,conn)
898 f = MEDCouplingFieldDouble(ON_GAUSS_NE)
900 f.setArray(DataArrayDouble(18*[0.]))
901 self.assertTrue(f.getLocalizationOfDiscr().isEqual(coo[conn],1e-10))
903 def testDADEigenValuesPb(self):
904 """EDF22126 : eigen values with Identity matrix returned nan. Now it returns correct eigen values 1.0 """
905 valuesExp = DataArrayDouble([(1.,1.,1.),(2.,-1.,0.),(2.,0.,1.),(3.,0.,0.)])
906 d = DataArrayDouble(4, 6)
907 for i,(v0, v1, v2, v3, v4, v5,) in enumerate([
911 (1, 1, 1, 1, 1, 1)]):
912 d[i] = [v0, v1, v2, v3, v4, v5]
913 self.assertTrue(d.eigenValues().isEqual(valuesExp,1e-12))
916 def testBugOnReprOf1SGTUMesh(self):
917 """ Non reg bug on repr of empty MEDCoupling1SGTUMesh instance """
918 m = MEDCoupling1SGTUMesh()
923 m = MEDCoupling1DGTUMesh()
929 def testCheckGeomConsistency0(self):
930 """Test of MEDCouplingUMesh.checkGeomConsistency"""
931 m = MEDCouplingUMesh("",2)
932 m.setCoords(DataArrayDouble([(0,0),(1,0),(2,0),(0,1),(1,1),(2,1)]))
934 m.insertNextCell(NORM_TRI6,[0,1,2,3,4,5])
935 m.insertNextCell(NORM_TRI6,[0,1,3,3,4,5])
937 self.assertRaises(InterpKernelException,m.checkGeomConsistency) # cell1 is incorrect because node 3 is repeated twice
938 m.getNodalConnectivity()[10]=2 # replace 3 by 2 for cell#1 to fix the problem
940 m.checkGeomConsistency() # now m is OK
942 def testInt32Int64Arr0(self):
944 arr = DataArrayInt32(n)
945 arr.iota() ; arr.rearrange(3)
946 comps = ["a","bb","ccc"]
948 arr.setName(name) ; arr.setInfoOnComponents(comps)
949 self.assertEqual(arr.accumulate(),[135, 145, 155])
950 arr2 = arr.convertToInt64Arr() # test is here
951 self.assertEqual(arr2.accumulate(),[135, 145, 155])
952 self.assertTrue(isinstance(arr2,DataArrayInt64))
953 self.assertEqual(arr2.getName(),name)
954 self.assertEqual(arr2.getInfoOnComponents(),comps)
955 arr3 = arr2.convertToInt32Arr() # test is here
956 self.assertEqual(arr3.accumulate(),[135, 145, 155])
957 self.assertTrue(isinstance(arr3,DataArrayInt32))
958 self.assertEqual(arr3.getName(),name)
959 self.assertEqual(arr3.getInfoOnComponents(),comps)
960 self.assertTrue(arr3.isEqual(arr))
962 def testComputeMeshCenterOfMass0(self):
964 arr = DataArrayDouble(5) ; arr.iota()
965 m = MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m=m.buildUnstructured()
966 self.assertTrue( m.computeMeshCenterOfMass().isEqual(DataArrayDouble([2,2],1,2),1e-12) )
968 m = MEDCouplingCMesh() ; m.setCoords(arr,arr,arr) ; m=m.buildUnstructured()
969 self.assertTrue( m.computeMeshCenterOfMass().isEqual(DataArrayDouble([2,2,2],1,3),1e-12) )
971 def testBugPenta15_0(self):
973 Non regression test from Roberto Da Via pointing error in connectivity of 5th sub face of penta15 cell.
975 coo=DataArrayDouble([
976 (0,1,1),(0,0,1),(1,0,1),
977 (0,1,0),(0,0,0),(1,0,0),
978 (0,0.5,1),(0.5,0,1),(0.5,0.5,1),
979 (0,0.5,0),(0.5,0,0),(0.5,0.5,0),
980 (0,1,0.5),(0,0,0.5),(1,0,0.5)
983 m = MEDCouplingUMesh("penta15",3)
986 m.insertNextCell(NORM_PENTA15,list(range(15)))
987 bm = m.buildBoundaryMesh(True)
988 bm.writeVTK("boundary.vtu")
990 [6, 0, 1, 2, 6, 7, 8],
991 [6, 3, 5, 4, 11, 10, 9],
992 [8, 0, 3, 4, 1, 12, 9, 13, 6],
993 [8, 1, 4, 5, 2, 13, 10, 14, 7],
994 [8, 2, 5, 3, 0, 14, 11, 12, 8] # old = [8, 2, 4, 5, 0, 14, 11, 12, 8]
996 self.assertTrue( bm.getNodalConnectivity().isEqual(DataArrayInt(sum(conn_expected,[]))) )
998 def testBugWithPolyhedInterpWithMoreThan255Nodes(self):
1000 [EDF25207] : Check interpolation containing polyhedron with more than 255 nodes is OK at bbox computation stage
1003 arr = DataArrayDouble(n) ; arr.iota()
1004 m = MEDCouplingCMesh()
1005 m.setCoords(arr,arr,arr)
1006 m = m.buildUnstructured()
1007 skin = m.computeSkin()
1009 # check that skin contains more than 2**8-1 node to reveal bug
1010 self.assertTrue(skin.getNumberOfNodes()>255)
1011 # Build a single polyhedron cell from skin
1012 skin1 = MEDCoupling1SGTUMesh(skin)
1013 conn = skin1.getNodalConnectivity()
1014 conn.rearrange( MEDCouplingUMesh.GetNumberOfNodesOfGeometricType(skin1.getCellModelEnum()) )
1015 connPolyhed = conn.changeNbOfComponents(MEDCouplingUMesh.GetNumberOfNodesOfGeometricType(skin1.getCellModelEnum())+1,-1)
1016 connPolyhed.rearrange(1)
1017 connPolyhed.popBackSilent()
1018 meshSinglePolyhed = MEDCouplingUMesh("",3)
1019 meshSinglePolyhed.allocateCells()
1020 meshSinglePolyhed.insertNextCell(NORM_POLYHED,connPolyhed.getValues())
1021 meshSinglePolyhed.setCoords( skin1.getCoords() )
1023 rem = MEDCouplingRemapper()
1024 rem.prepare(meshSinglePolyhed,m,"P0P0")
1025 res = rem.getCrudeMatrix()
1026 self.assertTrue( all([len(elt)==1 for elt in res]) )
1027 self.assertTrue( all([elt[0]>0.99 and elt[0]<1.01 for elt in res]) )
1029 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
1030 def testShapeFuncAndDerivative0(self):
1032 Test values returned by MEDCoupling on HEXA27 element of shape function and its derivatives.
1033 See https://www.code-aster.org/V2/doc/v10/fr/man_r/r3/r3.01.01.pdf
1037 ref_coords_hexa27_med = [[-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], [-1.0, 0.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], [0.0, 1.0, 1.0], [1.0, 0.0, 1.0], [0.0, -1.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, 0.0, -1.0], [-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.0, 0.0, 0.0]]
1039 def coor2index(coor):
1040 zeMap = {-1.0 : 0, 0.0 : 2 , 1.0 : 1}
1043 vcoor2index = np.vectorize( coor2index )
1044 node2ijk_hexa27_med = vcoor2index( np.array(ref_coords_hexa27_med) )
1047 return np.array([-0.5*x*(1-x), 0.5*x*(x+1), 1.-x*x])
1049 def N_3d_hexa27(x, i, j, k):
1050 return N_1d_quad(x[0])[i]*N_1d_quad(x[1])[j]*N_1d_quad(x[2])[k]
1053 return np.array([N_3d_hexa27(x, *node2ijk_hexa27_med[node,:]) for node in range(27)])
1055 # Implementing shape function derivatives
1056 def diff_N_1d_quad(x):
1057 return np.array([x-0.5, x+0.5, -2.*x])
1059 def diff_N_3d_hexa27(x, i, j, k):
1060 return np.array([diff_N_1d_quad(x[0])[i]*N_1d_quad(x[1])[j] *N_1d_quad(x[2])[k],
1061 N_1d_quad(x[0])[i] *diff_N_1d_quad(x[1])[j]*N_1d_quad(x[2])[k],
1062 N_1d_quad(x[0])[i] *N_1d_quad(x[1])[j] *diff_N_1d_quad(x[2])[k]])
1064 def diff_N_hexa27(x):
1065 return np.array([diff_N_3d_hexa27(x, *node2ijk_hexa27_med[node,:]) for node in range(27)])
1066 # computation of ref values
1067 posInRefCoord = [-0.85685375,-0.90643355,-0.90796825]
1068 ref = N_hexa27( np.array(posInRefCoord) )
1069 ref2 = diff_N_hexa27( np.array(posInRefCoord) )
1070 # computation using MEDCoupling
1071 gl = MEDCouplingGaussLocalization(NORM_HEXA27,sum(ref_coords_hexa27_med,[]),posInRefCoord,[1])
1072 mcShapeFunc = gl.getShapeFunctionValues()
1073 mcShapeFunc.rearrange(1)
1074 self.assertTrue( mcShapeFunc.isEqual(DataArrayDouble(ref),1e-12) )
1076 mvDevOfShapeFunc = gl.getDerivativeOfShapeFunctionValues()
1077 mvDevOfShapeFunc.rearrange(1)
1078 ref2_mc = DataArrayDouble(ref2) ; ref2_mc.rearrange(1)
1079 self.assertTrue( mvDevOfShapeFunc.isEqual( ref2_mc, 1e-12) )
1081 def testShapeFuncAndDerivative1(self):
1085 def GetShapeFunc(ref_coord,vec):
1086 gl3 = MEDCouplingGaussLocalization(gt,sum(ref_coord,[]), vec, [1])
1087 funVal = gl3.getShapeFunctionValues()
1091 def GetDerivative(ref_coord,vec):
1092 gl3 = MEDCouplingGaussLocalization(gt,sum(ref_coord,[]), vec, [1])
1093 funVal = gl3.getDerivativeOfShapeFunctionValues()
1095 vec = [-0.85685375,-0.90643355,-0.90796825]
1098 for gt in [NORM_TETRA4,NORM_TETRA10,NORM_HEXA8,NORM_PENTA6,NORM_PYRA5,NORM_PYRA13,NORM_PENTA15,NORM_PENTA6,NORM_PENTA18,NORM_HEXA20,NORM_HEXA27]: # type of cell for which derivatives are implemented
1099 ref_coord = [list(elt) for elt in MEDCouplingGaussLocalization.GetDefaultReferenceCoordinatesOf(gt).getValuesAsTuple()]
1101 der_computed = GetDerivative(ref_coord,vec)
1102 der_computed.rearrange(3)
1104 der_deduced = ( GetShapeFunc(ref_coord,[vec[0]+eps,vec[1],vec[2]])-GetShapeFunc(ref_coord,vec) ) / eps
1105 delta_X = der_computed[:,0]-der_deduced
1107 self.assertTrue(delta_X.findIdsNotInRange(-1e-4,+1e-4).empty())
1109 der_deduced = ( GetShapeFunc(ref_coord,[vec[0],vec[1]+eps,vec[2]])-GetShapeFunc(ref_coord,vec) ) / eps
1110 delta_Y = der_computed[:,1]-der_deduced
1112 self.assertTrue(delta_Y.findIdsNotInRange(-1e-5,+1e-5).empty())
1114 der_deduced = ( GetShapeFunc(ref_coord,[vec[0],vec[1],vec[2]+eps])-GetShapeFunc(ref_coord,vec) ) / eps
1115 delta_Z = der_computed[:,2]-der_deduced
1117 self.assertTrue(delta_Z.findIdsNotInRange(-1e-5,+1e-5).empty())
1119 for gt,ref_coord in [(NORM_TETRA4,[[0.0, 1.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 1.0], [1.0, 0.0, 0.0]]),(NORM_TETRA10,[[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]]),(NORM_HEXA8,[[-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]]),(NORM_HEXA8,[[-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, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]),(NORM_HEXA8,[[-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, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]),(NORM_PENTA6,[[-1.0, 1.0, 0.0], [-1.0, 0.0, 0.0], [-1.0, -0.0, 1.0], [1.0, 1.0, 0.0], [1.0, 0.0, 0.0], [1.0, 0.0, 1.0]]),(NORM_PENTA6,[[-1.0, 1.0, 0.0], [-1.0, -1.0, 0.0], [1.0, -1.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]),(NORM_PENTA6,[[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]),(NORM_PYRA5,[[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]]),(NORM_PYRA13, [[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]]),(NORM_PENTA15,[[-1.0, 1.0, 0.0], [-1.0, 0.0, 0.0], [-1.0, -0.0, 1.0], [1.0, 1.0, 0.0], [1.0, 0.0, 0.0], [1.0, 0.0, 1.0], [-1.0, 0.5, 0.0], [-1.0, 0.0, 0.5], [-1.0, 0.5, 0.5], [1.0, 0.5, 0.0], [1.0, 0.0, 0.5], [1.0, 0.5, 0.5], [0.0, 1.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 1.0]]),(NORM_PENTA18,[[-1.0, 1.0, 0.0], [-1.0, 0.0, 0.0], [-1.0, -0.0, 1.0], [1.0, 1.0, 0.0], [1.0, 0.0, 0.0], [1.0, 0.0, 1.0], [-1.0, 0.5, 0.0], [-1.0, 0.0, 0.5], [-1.0, 0.5, 0.5], [1.0, 0.5, 0.0], [1.0, 0.0, 0.5], [1.0, 0.5, 0.5], [0.0, 1.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, 0.5, 0.0], [0.0, 0.0, 0.5], [0.0, 0.5, 0.5]]),(NORM_HEXA20,[[-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], [-1.0, 0.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], [0.0, 1.0, 1.0], [1.0, 0.0, 1.0], [0.0, -1.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]])]: # type of cell for which derivatives are implemented
1121 der_computed = GetDerivative(ref_coord,vec)
1122 der_computed.rearrange(3)
1124 der_deduced = ( GetShapeFunc(ref_coord,[vec[0]+eps,vec[1],vec[2]])-GetShapeFunc(ref_coord,vec) ) / eps
1125 delta_X = der_computed[:,0]-der_deduced
1127 self.assertTrue(delta_X.findIdsNotInRange(-1e-4,+1e-4).empty())
1129 der_deduced = ( GetShapeFunc(ref_coord,[vec[0],vec[1]+eps,vec[2]])-GetShapeFunc(ref_coord,vec) ) / eps
1130 delta_Y = der_computed[:,1]-der_deduced
1132 self.assertTrue(delta_Y.findIdsNotInRange(-1e-5,+1e-5).empty())
1134 der_deduced = ( GetShapeFunc(ref_coord,[vec[0],vec[1],vec[2]+eps])-GetShapeFunc(ref_coord,vec) ) / eps
1135 delta_Z = der_computed[:,2]-der_deduced
1137 self.assertTrue(delta_Z.findIdsNotInRange(-1e-5,+1e-5).empty())
1142 for gt in [NORM_QUAD4,NORM_QUAD8,NORM_QUAD9,NORM_TRI3,NORM_TRI6,NORM_TRI7]:
1143 ref_coord = [list(elt) for elt in MEDCouplingGaussLocalization.GetDefaultReferenceCoordinatesOf(gt).getValuesAsTuple()]
1145 der_computed = GetDerivative(ref_coord,vec)
1146 der_computed.rearrange(2)
1148 der_deduced = ( GetShapeFunc(ref_coord,[vec[0]+eps,vec[1]])-GetShapeFunc(ref_coord,vec) ) / eps
1149 delta_X = der_computed[:,0]-der_deduced
1151 self.assertTrue(delta_X.findIdsNotInRange(-1e-5,+1e-5).empty())
1153 der_deduced = ( GetShapeFunc(ref_coord,[vec[0],vec[1]+eps])-GetShapeFunc(ref_coord,vec) ) / eps
1154 delta_Y = der_computed[:,1]-der_deduced
1156 self.assertTrue(delta_Y.findIdsNotInRange(-1e-4,+1e-4).empty())
1158 # B version of TRI6, QUAD4 and QUAD8
1159 for gt,ref_coord in [(NORM_TRI3,[[0.0, 0.0], [1.0, 0.0], [0.0, 1.0]]),(NORM_TRI6,[[0., 0.], [1., 0.], [0., 1.], [0.5, 0.], [0.5, 0.5], [0., 0.5]]),
1160 (NORM_QUAD4,[[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]]),(NORM_QUAD4,[[-1., -1.], [-1., 1.], [1., 1.], [1., -1.]]),(NORM_QUAD4,[[-1., 0.], [1., 0.], [0., 0.], [0., 0.]]),(NORM_QUAD8,[[-1., -1.], [1., -1.], [1., 1.], [-1., 1.], [0., -1.], [1., 0.], [0., 1.], [-1., 0.]])]:
1161 der_computed = GetDerivative(ref_coord,vec)
1162 der_computed.rearrange(2)
1164 der_deduced = ( GetShapeFunc(ref_coord,[vec[0]+eps,vec[1]])-GetShapeFunc(ref_coord,vec) ) / eps
1165 delta_X = der_computed[:,0]-der_deduced
1167 self.assertTrue(delta_X.findIdsNotInRange(-1e-5,+1e-5).empty())
1169 der_deduced = ( GetShapeFunc(ref_coord,[vec[0],vec[1]+eps])-GetShapeFunc(ref_coord,vec) ) / eps
1170 delta_Y = der_computed[:,1]-der_deduced
1172 self.assertTrue(delta_Y.findIdsNotInRange(-1e-5,+1e-5).empty())
1177 for gt in [NORM_SEG2,NORM_SEG3,NORM_SEG4]:
1178 ref_coord = [list(elt) for elt in MEDCouplingGaussLocalization.GetDefaultReferenceCoordinatesOf(gt).getValuesAsTuple()]
1180 der_computed = GetDerivative(ref_coord,vec)
1181 der_computed.rearrange(1)
1183 der_deduced = ( GetShapeFunc(ref_coord,[vec[0]+eps])-GetShapeFunc(ref_coord,vec) ) / eps
1184 delta_X = der_computed[:,0]-der_deduced
1186 self.assertTrue(delta_X.findIdsNotInRange(-1e-5,+1e-5).empty())
1189 for gt,ref_coord in [(NORM_SEG2,[[0.], [1.]])]:
1190 der_computed = GetDerivative(ref_coord,vec)
1191 der_computed.rearrange(1)
1193 der_deduced = ( GetShapeFunc(ref_coord,[vec[0]+eps])-GetShapeFunc(ref_coord,vec) ) / eps
1194 delta_X = der_computed[:,0]-der_deduced
1196 self.assertTrue(delta_X.findIdsNotInRange(-1e-5,+1e-5).empty())
1199 def testComputeTriangleHeight0(self):
1200 arr = DataArrayDouble([0,1])
1201 m = MEDCouplingCMesh() ; m.setCoords(arr,arr)
1202 m = m.buildUnstructured() ; m.simplexize(0) ; m = MEDCoupling1SGTUMesh(m)
1203 res = m.computeTriangleHeight()
1204 expected = DataArrayDouble([(1.0, 1.0, sqrt(2)/2.0), (sqrt(2)/2.0, 1.0, 1.0)])
1205 self.assertTrue( res.isEqual(expected,1e-12) )
1206 m.changeSpaceDimension(3,100)
1207 res2 = m.computeTriangleHeight()
1208 self.assertTrue( res2.isEqual(expected,1e-12) )
1209 expected2 = DataArrayDouble([sqrt(2)/2.0, sqrt(2)/2.0])
1210 self.assertTrue( res2.minPerTuple().isEqual(expected2,1e-12) )
1212 def testComputeTriangleHeight1(self):
1213 m = MEDCouplingUMesh("mesh",2)
1214 m.setCoords(DataArrayDouble([(0,0,0),(0,0,0),(10,0,0)]))
1216 m.insertNextCell(NORM_TRI3, [0,1,2])
1217 m = MEDCoupling1SGTUMesh(m)
1218 res = m.computeTriangleHeight()
1219 expected = DataArrayDouble([(10,0,0)])
1220 self.assertTrue( res.isEqual(expected,1e-12) )
1222 def testDAILocateComponentId0(self):
1223 arr = DataArrayInt( [(0, 1, 2), (3, 4, 5), (6, 2, 3), (7, 8, 9), (9, 0, 10), (11, 12, 13), (14, 5, 11), (15, 16, 17)] )
1224 valToSearchIntoTuples = DataArrayInt( [1, 4, 6, 8, 10, 12, 14, 16, 17] )
1225 tupleIdHint = DataArrayInt( [0, 1, 2, 3, 4, 5, 6, 7, 7] )
1226 ret = arr.locateComponentId( valToSearchIntoTuples, tupleIdHint )
1227 self.assertTrue( ret.isEqual(DataArrayInt([1, 1, 0, 1, 2, 1, 0, 1, 2]) ) )
1230 def testMeasureOnGaussPtMeshDimNotEqualSpaceDim0(self):
1232 [EDF26877] : This test focuses on computation of measure field on field on Gauss Point in the special case where SpaceDim
1233 are not eqaul to the meshDim.
1235 seg2 = MEDCouplingUMesh("mesh",1)
1236 seg2.setCoords(DataArrayDouble([(3,3),(4,4)]))
1237 seg2.allocateCells()
1238 seg2.insertNextCell(NORM_SEG2,[0,1])
1239 fff=MEDCouplingFieldDouble.New(ON_GAUSS_PT) ; fff.setName("CH1RB") ; fff.setNature(IntensiveMaximum)
1241 fff.setGaussLocalizationOnCells([0], [0.,1.], [0.333333333333333], [1.0])
1242 disc = fff.getDiscretization()
1243 # spaceDim = 2 meshDim = 1
1244 self.assertTrue( disc.getMeasureField(seg2,True).getArray().isEqual(DataArrayDouble([sqrt(2.0)]),1e-10) )
1245 # spaceDim = 3 meshDim = 1
1246 seg2.setCoords(DataArrayDouble([(3,3,3),(4,4,4)]))
1247 self.assertTrue( disc.getMeasureField(seg2,True).getArray().isEqual(DataArrayDouble([sqrt(3.0)]),1e-10) )
1248 # spaceDim = 3 meshDim = 2
1249 tri = MEDCouplingUMesh("mesh",2)
1250 tri.setCoords( DataArrayDouble([(0,0,0),(1,1,0),(2,2,2)]) )
1252 tri.insertNextCell(NORM_TRI3,[0,1,2])
1253 fff=MEDCouplingFieldDouble.New(ON_GAUSS_PT) ; fff.setName("CH1RB") ; fff.setNature(IntensiveMaximum)
1255 fff.setGaussLocalizationOnCells(list(range(0, 1)), [0., 0., 1., 0., 0., 1.], [0.3333333333333333, 0.3333333333333333], [0.5])
1256 disc = fff.getDiscretization()
1257 self.assertTrue( disc.getMeasureField(tri,True).getArray().isEqual( tri.getMeasureField(True).getArray(), 1e-10) )
1260 def testUMeshExplodeMeshTo(self):
1262 [EDF27988] : implementation of reduceToCells implies implementation of MEDCouplingUMesh.explodeMeshTo
1264 arr = DataArrayDouble(5) ; arr.iota()
1265 m = MEDCouplingCMesh() ; m.setCoords(arr,arr,arr)
1266 m = m.buildUnstructured()
1267 m1 = m[::2] ; m2 = m[1::2]
1268 m1.simplexize(PLANAR_FACE_5)
1269 m = MEDCouplingUMesh.MergeUMeshesOnSameCoords([m1,m2])
1270 mE1 = m.explodeMeshTo(-1)
1271 ref1 = m.buildDescendingConnectivity()
1272 mE2 = m.explodeMeshTo(-2)
1273 ref2 = m.explode3DMeshTo1D()
1274 mE3 = m.explodeMeshTo(-3)
1275 self.assertTrue( len(mE1) ==5 )
1276 self.assertTrue( mE1[0].getNodalConnectivity().isEqual(ref1[0].getNodalConnectivity()) )
1277 self.assertTrue( mE1[0].getNodalConnectivityIndex().isEqual(ref1[0].getNodalConnectivityIndex()) )
1278 self.assertTrue( mE1[0].getCoords().getHiddenCppPointer() == m.getCoords().getHiddenCppPointer() )
1279 for i in range(1,5):
1280 self.assertTrue( mE1[i].isEqual(ref1[i]) )
1282 self.assertTrue( len(mE2) ==5 )
1283 self.assertTrue( mE2[0].getNodalConnectivity().isEqual(ref2[0].getNodalConnectivity()) )
1284 self.assertTrue( mE2[0].getNodalConnectivityIndex().isEqual(ref2[0].getNodalConnectivityIndex()) )
1285 self.assertTrue( mE2[0].getCoords().getHiddenCppPointer() == m.getCoords().getHiddenCppPointer() )
1286 for i in range(1,5):
1287 self.assertTrue( mE2[i].isEqual(ref2[i]) )
1289 self.assertTrue( mE3[0].getMeshDimension() == 0 )
1290 self.assertTrue( mE3[0].getNumberOfCells() == mE3[0].getNumberOfNodes() )
1291 a,b = m.getReverseNodalConnectivity()
1292 self.assertTrue( mE3[3].isEqual(a) and mE3[4].isEqual(b) )
1293 ref3_2 = (m.getNodalConnectivityIndex().deltaShiftIndex()-1) ; ref3_2.computeOffsetsFull()
1294 self.assertTrue( ref3_2.isEqual(mE3[2]) )
1295 tmp = m.getNodalConnectivityIndex().deepCopy() ; tmp.popBackSilent() ; tmp = tmp.buildComplement( len(m.getNodalConnectivity()) ) ; ref3_1 = m.getNodalConnectivity()[tmp]
1296 self.assertTrue( ref3_1.isEqual(mE3[1]) )
1298 cellsInPolyh = [37,160]
1299 polyh = m[cellsInPolyh]
1300 polyh.convertAllToPoly()
1301 m[cellsInPolyh] = polyh
1302 pE3 = m.explodeMeshTo(-3)
1303 self.assertTrue( pE3[0].getMeshDimension() == 0 )
1304 self.assertTrue( pE3[0].getNumberOfCells() == pE3[0].getNumberOfNodes() )
1305 a,b = m.getReverseNodalConnectivity()
1306 self.assertTrue( pE3[3].isEqual(a) and pE3[4].isEqual(b) )
1307 self.assertTrue( pE3[2].isEqual(mE3[2]) ) # indexed arrays are the same
1309 ref_a,ref_b = DataArrayInt.ExtractFromIndexedArrays( DataArrayInt(cellsInPolyh).buildComplement(m.getNumberOfCells()), mE3[1], mE3[2] )
1310 a,b = DataArrayInt.ExtractFromIndexedArrays( DataArrayInt(cellsInPolyh).buildComplement(m.getNumberOfCells()), pE3[1], pE3[2] )
1311 self.assertTrue( ref_a.isEqual(a) )
1312 self.assertTrue( ref_b.isEqual(b) )
1313 for cell in cellsInPolyh:
1314 ref_c,ref_d = DataArrayInt.ExtractFromIndexedArrays( cell, mE3[1], mE3[2] ) ; ref_c.sort()
1315 c,d = DataArrayInt.ExtractFromIndexedArrays( cell, pE3[1], pE3[2] )
1316 self.assertTrue( ref_c.isEqual(c) )
1317 self.assertTrue( ref_d.isEqual(d) )
1319 def testGetCellContainingPointRelativeEps(self):
1321 See EDF27860 : This test checks that detection of point inside a cell works by normalizing cell around origin with factor equal to the max delta of bbox along axis X, Y or Z.
1323 # in this test cell is vuluntary far from origin {15260.775604514516, 11197.646906189217, 14187.820484060947}
1324 # and caracteritic size is ~ 1500
1325 coo = DataArrayDouble( [(14724.199858870656, 11928.888084722483, 14442.32726944039), (14788.407409534622, 11992.60694822231, 14453.86181555231), (15572.175148726046, 10798.586790270576, 14471.54225356788), (15643.898717334796, 10853.094666047728, 14477.233802854305), (15005.31495255754, 11573.261110174888, 13933.313698681504), (15070.29423166349, 11636.377758513776, 13946.650959030132), (15797.351350158377, 10466.40572765595, 13965.524190108257), (15869.808770928525, 10519.99285973948, 13972.419352086607), (15273.866774426142, 11216.458197414971, 13433.169979717744), (15340.421031616577, 11277.882145177837, 13446.53598386297), (16013.382514001762, 10132.795887638129, 13465.184281842226), (16086.979064572806, 10184.802292369684, 13472.147425473782)] )
1326 m = MEDCouplingUMesh("",3)
1329 m.insertNextCell(NORM_TETRA4,[0,5,4,6])
1330 m.insertNextCell(NORM_TETRA4,[4,5,9,7])
1332 ##### See EDF2760 pt is outside cell 0 (6e-4) and 1 (8e-4)
1333 pt = DataArrayDouble([(15263.41200205526, 11314.957094727113, 13950.0)])
1334 a,b = m.getCellsContainingPoints(pt,1e-3)
1335 self.assertTrue(a.isEqual(DataArrayInt([0,1])))
1336 self.assertTrue(b.isEqual(DataArrayInt([0,2])))
1338 # by shifting pt by 10 along Z pt in only inside cell # 0
1340 a1,b1 = m.getCellsContainingPoints(pt,1e-3)
1341 self.assertTrue(a1.isEqual(DataArrayInt([0])))
1342 self.assertTrue(b1.isEqual(DataArrayInt([0,1])))
1344 def testGetCellContainingPointOnPolyhedronWithPlanarFace(self):
1347 In case of polyhedron with a face defined by several colinear points,
1348 we must use other non colinear points to be able to define a face from these three points
1349 to define the relative position of the test point to this face
1352 coo = DataArrayDouble( [ (0.176, 0.1125, 1.05),
1353 (0.176, 0.120375, 1.05),
1354 (0.176, 0.120375, 1.0),
1355 (0.176, 0.1125, 1.0),
1356 (0.176000000000000018, 0.12825, 1.05),
1357 (0.176000000000000018, 0.12825, 1.0),
1358 (0.207, 0.1125, 1.05),
1359 (0.207, 0.1125, 1.0),
1360 (0.207, 0.12825, 1.05),
1361 (0.207, 0.12825, 1.0)] )
1363 m = MEDCouplingUMesh("Mesh",3)
1366 # put -1 to separate faces connectivity
1367 # substract -1 from mdump table ids
1368 m.insertNextCell(NORM_POLYHED,[0, 1, 2, 3, -1,
1373 3, 2, 5, 9, 7, -1, # PB in this order
1374 #7, 3, 2, 5, 9, -1, # OK in this order
1377 # test point inside the box
1378 pt_above = (0.2, 0.12, 1.07)
1379 pt_below = (0.2, 0.12, 0.9)
1380 pt_inside = (0.2, 0.12, 1.025)
1381 pts = DataArrayDouble([pt_above, pt_below, pt_inside])
1382 a,b = m.getCellsContainingPoints(pts, eps)
1383 self.assertTrue(a.isEqual(DataArrayInt([0])))
1384 # only the third point is inside
1385 self.assertTrue(b.isEqual(DataArrayInt([0,0,0,1])))
1387 # rotate the mesh to see if getCellsContainingPoints works
1388 # even if point is not inside bounding box
1391 m.rotate(center,vector,-pi/4.);
1393 # test 3 points: above, below and inside
1394 pt_above = (0.19, 0.09, 1.04)
1395 pt_below = (0.19, 0.11, 1.02)
1396 pt_inside = (0.19, 0.10, 1.02)
1397 pts_rotated = DataArrayDouble([pt_above, pt_below, pt_inside])
1399 a,b = m.getCellsContainingPoints(pts_rotated, eps)
1400 self.assertTrue(a.isEqual(DataArrayInt([0])))
1401 # only the third point is inside
1402 self.assertTrue(b.isEqual(DataArrayInt([0,0,0,1])))
1404 def testGetCellContainingPointOnPolyhedronWithPlanarFaceWithManyNodes(self):
1406 Similar test with many colinear nodes on the planar face
1409 coo = DataArrayDouble( [(0.176000000000000018, 0.120375, 1.0 ),
1410 (0.176000000000000018, 0.128250, 1.0 ),
1411 (0.176000000000000018, 0.136125, 1.0 ),
1412 (0.176000000000000018, 0.144, 1.0 ),
1413 (0.176000000000000018, 0.151875, 1.0 ),
1414 (0.176000000000000018, 0.159750, 1.0 ),
1415 (0.176000000000000018, 0.167625, 1.0 ),
1416 (0.176000000000000018, 0.1755, 1.0 ),
1417 (0.176000000000000018, 0.183375, 1.0 ),
1418 (0.176000000000000018, 0.191250, 1.0 ),
1419 (0.176000000000000018, 0.199125, 1.0 ),
1420 (0.176, 0.207, 1.0 ),
1421 (0.207, 0.207, 1.0 ),
1422 (0.176, 0.1125, 1.0 ),
1423 (0.207, 0.1125, 1.0 ),
1424 (0.176, 0.120375, 1.05),
1425 (0.176000000000000018, 0.128250, 1.05),
1426 (0.176000000000000018, 0.136125, 1.05),
1427 (0.176000000000000018, 0.144, 1.05),
1428 (0.176000000000000018, 0.151875, 1.05),
1429 (0.176000000000000018, 0.159750, 1.05),
1430 (0.176000000000000018, 0.167625, 1.05),
1431 (0.176000000000000018, 0.1755, 1.05),
1432 (0.176000000000000018, 0.183375, 1.05),
1433 (0.176000000000000018, 0.191250, 1.05),
1434 (0.176000000000000018, 0.199125, 1.05),
1435 (0.176, 0.207, 1.05),
1436 (0.207, 0.207, 1.05),
1437 (0.176, 0.1125, 1.05),
1438 (0.207, 0.1125, 1.05)])
1440 m = MEDCouplingUMesh("Mesh",3)
1443 # put -1 to separate faces connectivity
1444 # substract -1 from mdump table ids
1445 m.insertNextCell(NORM_POLYHED,
1446 [13, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, -1, #1
1447 29, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 28, -1, #2
1448 14, 29, 28, 13, -1, #3
1449 11, 26, 27, 12, -1, #4
1450 12, 27, 29, 14, -1, #5
1451 13, 28, 15, 0, -1, #6
1452 0, 15, 16, 1, -1, #7
1453 1, 16, 17, 2, -1, #8
1454 2, 17, 18, 3, -1, #9
1455 3, 18, 19, 4, -1, #10
1456 4, 19, 20, 5, -1, #11
1457 5, 20, 21, 6, -1, #12
1458 6, 21, 22, 7, -1, #13
1459 7, 22, 23, 8, -1, #14
1460 8, 23, 24, 9, -1, #15
1461 9, 24, 25, 10, -1, #16
1464 ##### See CEA 40783: error with polyhedrons (box split by on edge on its face)
1465 pt_above = (0.1915, 0.15975, 1.07)
1466 pt_below = (0.1915, 0.15975, 0.9)
1467 pt_inside = (0.1915, 0.15975, 1.025)
1468 pts = DataArrayDouble([pt_above, pt_below, pt_inside])
1469 a,b = m.getCellsContainingPoints(pts,eps)
1470 self.assertTrue(a.isEqual(DataArrayInt([0])))
1471 # only the third point is inside
1472 self.assertTrue(b.isEqual(DataArrayInt([0,0,0,1])))
1475 if __name__ == '__main__':