From cbfc0f0ec5d30217e9e9c785f6b960ea53fb00b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Schartum=20Dokken?= Date: Sun, 23 Feb 2025 21:13:51 +0100 Subject: [PATCH] Resolve jacobians from duplicate meshes (#733) * Fix multiple jacobians * add test that currently fails on main * ruff --------- Co-authored-by: Matthew Scroggs --- ffcx/codegeneration/symbols.py | 5 +++-- test/test_jit_forms.py | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/ffcx/codegeneration/symbols.py b/ffcx/codegeneration/symbols.py index f28c911dc..2c889947c 100644 --- a/ffcx/codegeneration/symbols.py +++ b/ffcx/codegeneration/symbols.py @@ -135,8 +135,9 @@ def x_component(self, mt): def J_component(self, mt): """Jacobian component.""" - # FIXME: Add domain number! - return L.Symbol(format_mt_name("J", mt), dtype=L.DataType.REAL) + return L.Symbol( + format_mt_name(f"J{mt.expr.ufl_domain().ufl_id()}", mt), dtype=L.DataType.REAL + ) def domain_dof_access(self, dof, component, gdim, num_scalar_dofs, restriction): """Domain DOF access.""" diff --git a/test/test_jit_forms.py b/test/test_jit_forms.py index ef49313fe..34fd8859e 100644 --- a/test/test_jit_forms.py +++ b/test/test_jit_forms.py @@ -1128,6 +1128,30 @@ def test_integral_grouping(compile_args): assert len(unique_integrals) == 2 +def test_derivative_domains(compile_args): + """Test a form with derivatives on two different domains will generate valid code.""" + + V_ele = basix.ufl.element("Lagrange", "triangle", 2) + W_ele = basix.ufl.element("Lagrange", "interval", 1) + + gdim = 2 + V_domain = ufl.Mesh(basix.ufl.element("Lagrange", "triangle", 1, shape=(gdim,))) + W_domain = ufl.Mesh(basix.ufl.element("Lagrange", "interval", 1, shape=(gdim,))) + + V = ufl.FunctionSpace(V_domain, V_ele) + W = ufl.FunctionSpace(W_domain, W_ele) + + u = ufl.TrialFunction(V) + q = ufl.TestFunction(W) + + ds = ufl.Measure("ds", domain=V_domain) + + forms = [ufl.inner(u.dx(0), q.dx(0)) * ds] + compiled_forms, module, code = ffcx.codegeneration.jit.compile_forms( + forms, options={"scalar_type": np.float64}, cffi_extra_compile_args=compile_args + ) + + @pytest.mark.parametrize("dtype", ["float64"]) @pytest.mark.parametrize("permutation", [[0], [1]]) def test_mixed_dim_form(compile_args, dtype, permutation):