diff --git a/firedrake/__init__.py b/firedrake/__init__.py index af7556e32d..6fadc1f9d0 100644 --- a/firedrake/__init__.py +++ b/firedrake/__init__.py @@ -67,7 +67,7 @@ def init_petsc(): from firedrake.cofunction import Cofunction, RieszMap # noqa: F401 from firedrake.constant import Constant # noqa: F401 from firedrake.deflation import DeflatedSNES, Deflation # noqa: F401 -from firedrake.exceptions import ConvergenceError # noqa: F401 +from firedrake.exceptions import ConvergenceError, MismatchingDomainError # noqa: F401 from firedrake.function import ( # noqa: F401 Function, PointNotInDomainError, CoordinatelessFunction, PointEvaluator diff --git a/firedrake/exceptions.py b/firedrake/exceptions.py index c80853ef23..cbbe469766 100644 --- a/firedrake/exceptions.py +++ b/firedrake/exceptions.py @@ -1,3 +1,4 @@ +from tsfc.exceptions import MismatchingDomainError # noqa: F401 class ConvergenceError(Exception): diff --git a/tests/firedrake/regression/test_multiple_domains.py b/tests/firedrake/regression/test_multiple_domains.py index 8ec3a46748..1a4443fc43 100644 --- a/tests/firedrake/regression/test_multiple_domains.py +++ b/tests/firedrake/regression/test_multiple_domains.py @@ -41,10 +41,10 @@ def test_mismatching_meshes_indexed_function(mesh1, mesh3): with pytest.raises(NotImplementedError): project(d1, target) - with pytest.raises(ValueError): + with pytest.raises(MismatchingDomainError): assemble(inner(d1, TestFunction(V2))*dx(domain=mesh3)) - with pytest.raises(ValueError): + with pytest.raises(MismatchingDomainError): assemble(inner(d1, TestFunction(V2))*dx(domain=mesh1)) @@ -177,29 +177,29 @@ def test_multi_domain_assemble(): for i, j in [(0, 1), (1, 0)]: a1 = inner(u[i], v[j])*dx(domain=mesh1) - with pytest.raises(ValueError): + with pytest.raises(MismatchingDomainError): assemble(a1) a2 = inner(u[i], v[j])*dx(domain=mesh2) - with pytest.raises(ValueError): + with pytest.raises(MismatchingDomainError): assemble(a2) l1 = inner(f[i], v[j])*dx(domain=mesh1) - with pytest.raises(ValueError): + with pytest.raises(MismatchingDomainError): assemble(l1) l2 = inner(f[i], v[j])*dx(domain=mesh2) - with pytest.raises(ValueError): + with pytest.raises(MismatchingDomainError): assemble(l2) for i, j in [(0, 0), (1, 1)]: a = inner(u[i], v[j])*dx(domain=mesh1) if i == 1: - with pytest.raises(ValueError): + with pytest.raises(MismatchingDomainError): assemble(a) continue A = assemble(a) assert A.M.values.shape == (V.dim(), V.dim()) a = inner(u[0], v[0])*dx(domain=mesh1) + inner(u[0], v[1])*dx(domain=mesh2) - with pytest.raises(ValueError): + with pytest.raises(MismatchingDomainError): assemble(a) a = inner(u[0], v[0])*dx(domain=mesh1) + inner(u[1], v[1])*dx(domain=mesh2) diff --git a/tsfc/__init__.py b/tsfc/__init__.py index f12615ebe5..42f78e8071 100644 --- a/tsfc/__init__.py +++ b/tsfc/__init__.py @@ -1,5 +1,6 @@ from tsfc.driver import compile_form, compile_expression_dual_evaluation # noqa: F401 from tsfc.parameters import default_parameters # noqa: F401 +from tsfc.exceptions import MismatchingDomainError # noqa: F401 def register_citations(): diff --git a/tsfc/driver.py b/tsfc/driver.py index bfe4495d2f..fb3abe9775 100644 --- a/tsfc/driver.py +++ b/tsfc/driver.py @@ -23,6 +23,8 @@ from tsfc.parameters import default_parameters, is_complex from tsfc.ufl_utils import apply_mapping, extract_firedrake_constants import tsfc.kernel_interface.firedrake_loopy as firedrake_interface_loopy +from tsfc.exceptions import MismatchingDomainError + # To handle big forms. The various transformations might need a deeper stack sys.setrecursionlimit(3000) @@ -188,8 +190,8 @@ def validate_domains(form): domain = itg.ufl_domain() for other_domain in itg.extra_domain_integral_type_map(): if domain.submesh_youngest_common_ancester(other_domain) is None: - raise ValueError("Assembly of forms over unrelated meshes is not supported. " - "Try using Submeshes or cross-mesh interpolation.") + raise MismatchingDomainError("Assembly of forms over unrelated meshes is not supported. " + "Try using Submeshes or cross-mesh interpolation.") # Check that all Arguments and Coefficients are defined on the valid domains valid_domains = set(itg.extra_domain_integral_type_map()) @@ -197,10 +199,10 @@ def validate_domains(form): itg_domains = set(extract_domains(itg)) if len(itg_domains - valid_domains) > 0: - raise ValueError("Argument or Coefficient domain not found in integral. " - "Possibly, the form contains coefficients on different meshes " - "and requires measure intersection, for example: " - 'Measure("dx", argument_mesh, intersect_measures=[Measure("dx", coefficient_mesh)]).') + raise MismatchingDomainError("Argument or Coefficient domain not found in integral. " + "Possibly, the form contains coefficients on different meshes " + "and requires measure intersection, for example: " + 'Measure("dx", argument_mesh, intersect_measures=[Measure("dx", coefficient_mesh)]).') def preprocess_parameters(parameters): diff --git a/tsfc/exceptions.py b/tsfc/exceptions.py new file mode 100644 index 0000000000..8789008cd0 --- /dev/null +++ b/tsfc/exceptions.py @@ -0,0 +1,4 @@ + + +class MismatchingDomainError(Exception): + """Error raised for unsupported multidomain problems"""