Skip to content

Commit 1c1935a

Browse files
authored
Change VOM missing_points_behaviour API (#4524)
1 parent 1b677f2 commit 1c1935a

File tree

5 files changed

+26
-25
lines changed

5 files changed

+26
-25
lines changed

firedrake/mesh.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3317,7 +3317,7 @@ def ExtrudedMesh(mesh, layers, layer_height=None, extrusion_type='uniform', peri
33173317

33183318

33193319
class MissingPointsBehaviour(enum.Enum):
3320-
IGNORE = None
3320+
IGNORE = "ignore"
33213321
ERROR = "error"
33223322
WARN = "warn"
33233323

@@ -3358,7 +3358,8 @@ def VertexOnlyMesh(mesh, vertexcoords, reorder=None, missing_points_behaviour='e
33583358
:kwarg missing_points_behaviour: optional string argument for what to do
33593359
when vertices which are outside of the mesh are discarded. If
33603360
``'warn'``, will print a warning. If ``'error'`` will raise a
3361-
:class:`~.VertexOnlyMeshMissingPointsError`.
3361+
:class:`~.VertexOnlyMeshMissingPointsError`. If ``'ignore'``, will do
3362+
nothing. Default is ``'error'``.
33623363
:kwarg tolerance: The relative tolerance (i.e. as defined on the reference
33633364
cell) for the distance a point can be from a mesh cell and still be
33643365
considered to be in the cell. Note that this tolerance uses an L1

tests/firedrake/vertexonly/test_interpolation_from_parent.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def immersed_sphere_vertexcoords(mesh, vertexcoords_old):
158158
def test_scalar_spatialcoordinate_interpolation(parentmesh, vertexcoords):
159159
if parentmesh.name == "immersedsphere":
160160
vertexcoords = immersed_sphere_vertexcoords(parentmesh, vertexcoords)
161-
vm = VertexOnlyMesh(parentmesh, vertexcoords, missing_points_behaviour=None)
161+
vm = VertexOnlyMesh(parentmesh, vertexcoords, missing_points_behaviour="ignore")
162162
# Reshaping because for all meshes, we want (-1, gdim) but
163163
# when gdim == 1 PyOP2 doesn't distinguish between dats with shape
164164
# () and shape (1,).
@@ -172,7 +172,7 @@ def test_scalar_spatialcoordinate_interpolation(parentmesh, vertexcoords):
172172
def test_scalar_function_interpolation(parentmesh, vertexcoords, fs):
173173
if parentmesh.name == "immersedsphere":
174174
vertexcoords = immersed_sphere_vertexcoords(parentmesh, vertexcoords)
175-
vm = VertexOnlyMesh(parentmesh, vertexcoords, missing_points_behaviour=None)
175+
vm = VertexOnlyMesh(parentmesh, vertexcoords, missing_points_behaviour="ignore")
176176
vertexcoords = vm.coordinates.dat.data_ro.reshape(-1, parentmesh.geometric_dimension())
177177
fs_fam, fs_deg, fs_typ = fs
178178
if (
@@ -202,7 +202,7 @@ def test_scalar_function_interpolation(parentmesh, vertexcoords, fs):
202202
def test_vector_spatialcoordinate_interpolation(parentmesh, vertexcoords):
203203
if parentmesh.name == "immersedsphere":
204204
vertexcoords = immersed_sphere_vertexcoords(parentmesh, vertexcoords)
205-
vm = VertexOnlyMesh(parentmesh, vertexcoords, missing_points_behaviour=None)
205+
vm = VertexOnlyMesh(parentmesh, vertexcoords, missing_points_behaviour="ignore")
206206
vertexcoords = vm.coordinates.dat.data_ro
207207
W = VectorFunctionSpace(vm, "DG", 0)
208208
expr = 2 * SpatialCoordinate(parentmesh)
@@ -214,7 +214,7 @@ def test_vector_function_interpolation(parentmesh, vertexcoords, vfs):
214214
if parentmesh.name == "immersedsphere":
215215
vertexcoords = immersed_sphere_vertexcoords(parentmesh, vertexcoords)
216216
vfs_fam, vfs_deg, vfs_typ = vfs
217-
vm = VertexOnlyMesh(parentmesh, vertexcoords, missing_points_behaviour=None)
217+
vm = VertexOnlyMesh(parentmesh, vertexcoords, missing_points_behaviour="ignore")
218218
vertexcoords = vm.coordinates.dat.data_ro
219219
if (
220220
parentmesh.coordinates.function_space().ufl_element().family()
@@ -242,7 +242,7 @@ def test_vector_function_interpolation(parentmesh, vertexcoords, vfs):
242242
def test_tensor_spatialcoordinate_interpolation(parentmesh, vertexcoords):
243243
if parentmesh.name == "immersedsphere":
244244
vertexcoords = immersed_sphere_vertexcoords(parentmesh, vertexcoords)
245-
vm = VertexOnlyMesh(parentmesh, vertexcoords, missing_points_behaviour=None)
245+
vm = VertexOnlyMesh(parentmesh, vertexcoords, missing_points_behaviour="ignore")
246246
vertexcoords = vm.coordinates.dat.data_ro
247247
W = TensorFunctionSpace(vm, "DG", 0)
248248
x = SpatialCoordinate(parentmesh)
@@ -260,7 +260,7 @@ def test_tensor_function_interpolation(parentmesh, vertexcoords, tfs):
260260
if parentmesh.name == "immersedsphere":
261261
vertexcoords = immersed_sphere_vertexcoords(parentmesh, vertexcoords)
262262
tfs_fam, tfs_deg, tfs_typ = tfs
263-
vm = VertexOnlyMesh(parentmesh, vertexcoords, missing_points_behaviour=None)
263+
vm = VertexOnlyMesh(parentmesh, vertexcoords, missing_points_behaviour="ignore")
264264
vertexcoords = vm.coordinates.dat.data_ro
265265
if (
266266
parentmesh.coordinates.function_space().ufl_element().family()
@@ -296,7 +296,7 @@ def test_mixed_function_interpolation(parentmesh, vertexcoords, tfs):
296296
vertexcoords = immersed_sphere_vertexcoords(parentmesh, vertexcoords)
297297
tfs_fam, tfs_deg, tfs_typ = tfs
298298

299-
vm = VertexOnlyMesh(parentmesh, vertexcoords, missing_points_behaviour=None)
299+
vm = VertexOnlyMesh(parentmesh, vertexcoords, missing_points_behaviour="ignore")
300300
vertexcoords = vm.coordinates.dat.data_ro.reshape(-1, parentmesh.geometric_dimension())
301301
if (
302302
parentmesh.coordinates.function_space().ufl_element().family()
@@ -336,7 +336,7 @@ def test_mixed_function_interpolation(parentmesh, vertexcoords, tfs):
336336

337337

338338
def test_scalar_real_interpolation(parentmesh, vertexcoords):
339-
vm = VertexOnlyMesh(parentmesh, vertexcoords, missing_points_behaviour=None)
339+
vm = VertexOnlyMesh(parentmesh, vertexcoords, missing_points_behaviour="ignore")
340340
W = FunctionSpace(vm, "DG", 0)
341341
V = FunctionSpace(parentmesh, "Real", 0)
342342
# Remove below when interpolating constant onto Real works for extruded
@@ -351,7 +351,7 @@ def test_scalar_real_interpolation(parentmesh, vertexcoords):
351351

352352
def test_scalar_real_interpolator(parentmesh, vertexcoords):
353353
# try and make reusable Interpolator from V to W
354-
vm = VertexOnlyMesh(parentmesh, vertexcoords, missing_points_behaviour=None)
354+
vm = VertexOnlyMesh(parentmesh, vertexcoords, missing_points_behaviour="ignore")
355355
W = FunctionSpace(vm, "DG", 0)
356356
V = FunctionSpace(parentmesh, "Real", 0)
357357
# Remove below when interpolating constant onto Real works for extruded
@@ -378,8 +378,8 @@ def test_extruded_cell_parent_cell_list():
378378
# we are not at the cell midpoints
379379
coords = np.array([[0.2, 0.1], [0.5, 0.2], [0.7, 0.1], [0.2, 0.4], [0.4, 0.4], [0.8, 0.5], [0.1, 0.7], [0.5, 0.9], [0.9, 0.8]])
380380

381-
vms = VertexOnlyMesh(ms, coords, missing_points_behaviour=None)
382-
vmx = VertexOnlyMesh(mx, coords, missing_points_behaviour=None)
381+
vms = VertexOnlyMesh(ms, coords, missing_points_behaviour="ignore")
382+
vmx = VertexOnlyMesh(mx, coords, missing_points_behaviour="ignore")
383383
assert vms.num_cells() == len(coords)
384384
assert vmx.num_cells() == len(coords)
385385
assert np.equal(vms.coordinates.dat.data_ro, coords[vms.topology._dm_renumbering]).all()

tests/firedrake/vertexonly/test_vertex_only_fs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def vectorfunctionspace_tests(vm, petsc_raises):
281281

282282
@pytest.mark.parallel([1, 3])
283283
def test_functionspaces(parentmesh, vertexcoords, petsc_raises):
284-
vm = VertexOnlyMesh(parentmesh, vertexcoords, missing_points_behaviour=None)
284+
vm = VertexOnlyMesh(parentmesh, vertexcoords, missing_points_behaviour="ignore")
285285
functionspace_tests(vm, petsc_raises)
286286
vectorfunctionspace_tests(vm, petsc_raises)
287287
functionspace_tests(vm.input_ordering, petsc_raises)
@@ -313,7 +313,7 @@ def test_input_ordering_missing_point():
313313
m = UnitIntervalMesh(4)
314314
points = np.asarray([[0.125], [0.375], [0.625], [5.0]])
315315
data = np.asarray([1.0, 2.0, 3.0, 4.0])
316-
vm = VertexOnlyMesh(m, points, missing_points_behaviour=None, redundant=True)
316+
vm = VertexOnlyMesh(m, points, missing_points_behaviour="ignore", redundant=True)
317317

318318
# put data on the input ordering
319319
P0DG_input_ordering = FunctionSpace(vm.input_ordering, "DG", 0)

tests/firedrake/vertexonly/test_vertex_only_manual.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def display_correct_indent():
6969
vom = VertexOnlyMesh(parent_mesh, points, missing_points_behaviour='warn')
7070

7171
# This will cause the point to be silently lost
72-
vom = VertexOnlyMesh(parent_mesh, points, missing_points_behaviour=None)
72+
vom = VertexOnlyMesh(parent_mesh, points, missing_points_behaviour="ignore")
7373
# [test_vom_manual_points_outside_domain 6]
7474

7575
assert vom # Just here to shut up flake8 unused variable warning.

tests/firedrake/vertexonly/test_vertex_only_mesh_generation.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def test_generate_random(parentmesh, vertexcoords):
316316
# TODO: This failure should be investigated
317317
pytest.skip(reason="This test hangs in parallel when using the simple partitioner")
318318
vm = VertexOnlyMesh(
319-
parentmesh, vertexcoords, missing_points_behaviour=None, name="testvom"
319+
parentmesh, vertexcoords, missing_points_behaviour="ignore", name="testvom"
320320
)
321321
verify_vertexonly_mesh(parentmesh, vm, vertexcoords, name="testvom")
322322

@@ -360,7 +360,7 @@ def test_point_tolerance():
360360
assert vm.cell_set.size == 1
361361
# check that the tolerance is passed through to the parent mesh
362362
assert m.tolerance == 0.1
363-
vm = VertexOnlyMesh(m, coords, tolerance=0.0, missing_points_behaviour=None)
363+
vm = VertexOnlyMesh(m, coords, tolerance=0.0, missing_points_behaviour="ignore")
364364
assert vm.cell_set.size == 0
365365
assert m.tolerance == 0.0
366366
# See if changing the tolerance on the parent mesh changes the tolerance
@@ -369,7 +369,7 @@ def test_point_tolerance():
369369
vm = VertexOnlyMesh(m, coords)
370370
assert vm.cell_set.size == 1
371371
m.tolerance = 0.0
372-
vm = VertexOnlyMesh(m, coords, missing_points_behaviour=None)
372+
vm = VertexOnlyMesh(m, coords, missing_points_behaviour="ignore")
373373
assert vm.cell_set.size == 0
374374

375375

@@ -381,7 +381,7 @@ def test_missing_points_behaviour(parentmesh):
381381
inputcoord = np.full((1, parentmesh.geometric_dimension()), np.inf)
382382
assert len(inputcoord) == 1
383383
# Can surpress error
384-
vm = VertexOnlyMesh(parentmesh, inputcoord, missing_points_behaviour=None)
384+
vm = VertexOnlyMesh(parentmesh, inputcoord, missing_points_behaviour="ignore")
385385
assert vm.cell_set.size == 0
386386
# Error by default
387387
with pytest.raises(VertexOnlyMeshMissingPointsError):
@@ -419,11 +419,11 @@ def test_outside_boundary_behaviour(parentmesh):
419419
inputcoord = np.full((1, parentmesh.geometric_dimension()), edge_point-1e-15)
420420
assert len(inputcoord) == 1
421421
# Tolerance is too small to pick up point
422-
vm = VertexOnlyMesh(parentmesh, inputcoord, tolerance=1e-16, missing_points_behaviour=None)
422+
vm = VertexOnlyMesh(parentmesh, inputcoord, tolerance=1e-16, missing_points_behaviour="ignore")
423423
assert vm.cell_set.size == 0
424424
# Tolerance is large enough to pick up point - note that we need to go up
425425
# by 2 orders of magnitude for this to work consistently
426-
vm = VertexOnlyMesh(parentmesh, inputcoord, tolerance=1e-13, missing_points_behaviour=None)
426+
vm = VertexOnlyMesh(parentmesh, inputcoord, tolerance=1e-13, missing_points_behaviour="ignore")
427427
assert vm.cell_set.size == 1
428428

429429

@@ -471,10 +471,10 @@ def test_inside_boundary_behaviour(parentmesh):
471471
inputcoord = np.full((1, parentmesh.geometric_dimension()), edge_point+1e-15)
472472
assert len(inputcoord) == 1
473473
# Tolerance is large enough to pick up point
474-
vm = VertexOnlyMesh(parentmesh, inputcoord, tolerance=1e-14, missing_points_behaviour=None)
474+
vm = VertexOnlyMesh(parentmesh, inputcoord, tolerance=1e-14, missing_points_behaviour="ignore")
475475
assert vm.cell_set.size == 1
476476
# Tolerance might be too small to pick up point, but it's not deterministic
477-
vm = VertexOnlyMesh(parentmesh, inputcoord, tolerance=1e-16, missing_points_behaviour=None)
477+
vm = VertexOnlyMesh(parentmesh, inputcoord, tolerance=1e-16, missing_points_behaviour="ignore")
478478
assert vm.cell_set.size == 0 or vm.cell_set.size == 1
479479

480480

@@ -491,5 +491,5 @@ def test_pyop2_labelling():
491491
vm = VertexOnlyMesh(m, points, redundant=True)
492492
assert vm.cell_set.total_size == 2*m.cell_set.total_size
493493
points = np.asarray([[-5.0]])
494-
vm = VertexOnlyMesh(m, points, redundant=False, missing_points_behaviour=None)
494+
vm = VertexOnlyMesh(m, points, redundant=False, missing_points_behaviour="ignore")
495495
assert vm.cell_set.total_size == 0

0 commit comments

Comments
 (0)