@@ -112,17 +112,43 @@ def test_high_order_location():
112112
113113def test_high_order_location_warped_interior_facet ():
114114 # Here we bend an interior facet and check the right cell is located.
115- mesh = UnitSquareMesh ( 2 , 2 )
115+ mesh = RectangleMesh ( 1 , 2 , 1.0 , 1.0 , 0.0 , - 1.0 , quadrilateral = True )
116116 V = VectorFunctionSpace (mesh , "CG" , 3 , variant = "equispaced" )
117117 f = Function (V )
118118 f .interpolate (mesh .coordinates )
119119
120- warp_indices = np .where ((f .dat .data [:, 0 ] > 0.0 ) & (f .dat .data [:, 0 ] < 0.5 ) & np .isclose (f .dat .data [:, 1 ], 0.5 ))[0 ]
120+ coords = f .dat .data_ro
121+ warp_indices = np .where ((coords [:, 0 ] > 0.0 ) & (coords [:, 0 ] < 1.0 ) & np .isclose (coords [:, 1 ], 0.0 ))[0 ]
121122 f .dat .data [warp_indices , 1 ] += 0.1
122- mesh = Mesh (f )
123123
124- assert mesh .locate_cell ([0.25 , 0.605 ], tolerance = 0.0001 ) == 1
125- assert mesh .locate_cell ([0.25 , 0.62 ], tolerance = 0.0001 ) == 3
124+ mesh = Mesh (f )
125+ mesh .tolerance = 1e-05
126+
127+ upper_point = [0.5 , 0.15 ]
128+ upper_point_cell = mesh .locate_cell (upper_point )
129+ lower_point = [0.5 , 0.05 ]
130+ lower_point_cell = mesh .locate_cell (lower_point )
131+
132+ assert upper_point_cell != lower_point_cell
133+
134+ # Check no other cell is found when ignoring the correct cell
135+ assert mesh .locate_cell (upper_point , cell_ignore = upper_point_cell ) is None
136+ assert mesh .locate_cell (lower_point , cell_ignore = lower_point_cell ) is None
137+
138+ # Try point outside of Lagrange bounding box of lower cell
139+ lower_point = [0.5 , 0.105 ]
140+ assert mesh .locate_cell (lower_point ) == lower_point_cell
141+
142+ mesh .tolerance = 0.01
143+ lower_point = [0.5 , 0.11 ]
144+ # Lower point is now inside the bounding box of the upper cell, but outside the cell itself
145+ # It is within mesh.tolerance of the upper cell, however, so should be assigned
146+ # to the upper cell if we ignore the lower cell, with a non-zero L^1 distance.
147+ lower_point_closer_cell = mesh .locate_cell (lower_point )
148+ assert lower_point_closer_cell == lower_point_cell
149+ cells , ref_coords , dists = mesh .locate_cells_ref_coords_and_dists ([lower_point ], cells_ignore = [[lower_point_cell ]])
150+ assert cells [0 ] == upper_point_cell
151+ assert not np .isclose (dists [0 ], 0.0 )
126152
127153
128154@pytest .mark .parallel ([1 , 3 ])
0 commit comments