@@ -174,6 +174,9 @@ def test_select(self):
174
174
self .assertVertices (self .topo .select (((self .geom - center ) * direction ).sum ()), desired_vertices )
175
175
direction = numpy .roll (direction , shift = 1 )
176
176
177
+ def test_elementwise_stack (self ):
178
+ self .assertEqual (function .eval (self .topo .elementwise_stack (self .topo .f_index )).tolist (), list (range (len (self .topo ))))
179
+
177
180
178
181
class ConformingTests :
179
182
@@ -456,8 +459,8 @@ class NewDisjointUnion(TestCase, CommonTests, ConformingTests):
456
459
457
460
def setUp (self ):
458
461
super ().setUp ()
459
- topo , self .geom = mesh .newrectilinear ([8 , 3 ], spaces = 'XY' )
460
- self .topo = topology .Topology .disjoint_union (topo . slice (slice (0 , 3 ), 0 ), topo .slice (slice (4 , 8 ), 0 ).slice (slice (0 , 2 ), 1 ))
462
+ self . basetopo , self .geom = mesh .newrectilinear ([8 , 3 ], spaces = 'XY' )
463
+ self .topo = topology .Topology .disjoint_union (self . basetopo . slice (slice (0 , 3 ), 0 ), self . basetopo .slice (slice (4 , 8 ), 0 ).slice (slice (0 , 2 ), 1 ))
461
464
self .desired_spaces = 'X' , 'Y'
462
465
self .desired_space_dims = 1 , 1
463
466
self .desired_ndims = 2
@@ -501,6 +504,12 @@ def test_trim(self):
501
504
self .assertEqual (as_rounded_list (topo .trim (x - 2.5 , maxrefine = 0 ).volume (x [None ])), 0.5 )
502
505
self .assertEqual (as_rounded_list (topo .trim (0.5 - x , maxrefine = 0 ).volume (x [None ])), 0.5 )
503
506
507
+ def test_elementwise_stack (self ):
508
+ self .assertEqual (
509
+ function .eval (self .topo .elementwise_stack (self .basetopo .f_index )).tolist (),
510
+ [0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 12 , 13 , 15 , 16 , 18 , 19 , 21 , 22 ],
511
+ )
512
+
504
513
505
514
class NewMul (TestCase , CommonTests , ConformingTests ):
506
515
@@ -611,6 +620,18 @@ def test_basis(self):
611
620
with self .assertRaises (ValueError ):
612
621
self .topo .basis ('spline' , degree = 1 , knotmultiplicities = ['a' , 'b' ])
613
622
623
+ def test_elementwise_stack_mul (self ):
624
+ desired = numpy .mgrid [:len (self .topo1 ), :len (self .topo2 )].reshape (2 , len (self .topo ))
625
+ stack = self .topo .elementwise_stack (numpy .stack ([self .topo1 .f_index , self .topo2 .f_index ]))
626
+ self .assertEqual (function .eval (stack ).tolist (), desired .T .tolist ())
627
+ stack = self .topo .elementwise_stack (numpy .stack ([self .topo1 .f_index , self .topo2 .f_index ]), axis = 1 )
628
+ self .assertEqual (function .eval (stack ).tolist (), desired .tolist ())
629
+
630
+ def test_partition_interfaces (self ):
631
+ centers = self .topo .partition_interfaces ([0 , 0 , 1 , 2 , 1 , 1 ]).sample ('gauss' , 0 ).eval (self .geom ).tolist ()
632
+ centers .sort ()
633
+ self .assertAllAlmostEqual (centers , [[0.5 , 2.0 ], [1.0 , 0.5 ], [1.0 , 1.5 ], [1.5 , 1.0 ]])
634
+
614
635
615
636
class NewWithGroupAliases (TestCase , CommonTests , ConformingTests ):
616
637
@@ -1337,6 +1358,11 @@ def setUp(self):
1337
1358
self .desired_references = [element .LineReference ()** 2 ]* 4
1338
1359
self .desired_vertices = [[[x , y ] for x in X for y in Y ] for X in pairwise (range (3 )) for Y in pairwise (range (3 ))]
1339
1360
1361
+ def test_partition_interfaces (self ):
1362
+ centers = self .topo .partition_interfaces ([0 , 0 , 1 , 2 ]).sample ('gauss' , 0 ).eval (self .geom ).tolist ()
1363
+ centers .sort ()
1364
+ self .assertAllAlmostEqual (centers , [[1.0 , 0.5 ], [1.0 , 1.5 ], [1.5 , 1.0 ]])
1365
+
1340
1366
1341
1367
class UnionTopology (TestCase , CommonTests , TransformChainsTests ):
1342
1368
0 commit comments