From e912ce7a9b40d64ec5a76b6c4dbd2dc87756730e Mon Sep 17 00:00:00 2001 From: Pablo Brubeck Date: Tue, 21 Jan 2025 09:15:41 +0000 Subject: [PATCH] Comments --- test/test_check_arities.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/test/test_check_arities.py b/test/test_check_arities.py index 978bd52c3..5508c02b1 100755 --- a/test/test_check_arities.py +++ b/test/test_check_arities.py @@ -89,6 +89,10 @@ def test_product_arity(): def test_zero_simplify_arity(): + """ + Test that adding verious zero-like expressions to a form is simplified, + such that one can compute form data for the integral. + """ cell = tetrahedron D = Mesh(FiniteElement("Lagrange", cell, 1, (3,), identity_pullback, H1)) V = FunctionSpace(D, FiniteElement("Lagrange", cell, 2, (), identity_pullback, H1)) @@ -99,15 +103,24 @@ def test_zero_simplify_arity(): with pytest.raises(ArityMismatch): F = inner(u, v + nonzero) * dx compute_form_data(F) + z = Coefficient(V) - zero = as_tensor([0, u])[0] + # Add a Zero-component (rank-0) of a tensor to a rank-1 tensor + zero = as_tensor([0, z])[0] F = inner(u, v + zero) * dx - compute_form_data(F) + fd = compute_form_data(F) + assert fd.num_coefficients == 1 - zero = conditional(u < 0, 0, 0) + # Add a conditional that should have been simplified to zero (rank-0) + # to a rank-1 tensor + zero = conditional(z < 0, 0, 0) F = inner(u, v + zero) * dx - compute_form_data(F) + fd = compute_form_data(F) + assert fd.num_coefficients == 1 - zero = conditional(u < 0, 0, conditional(u == 0, 0, 0)) + # Check that nested zero conditionals are simplifed to zero (rank-0) + # and can be added to a rank-1 tensor + zero = conditional(z < 0, 0, conditional(z == 0, 0, 0)) F = inner(u, v + zero) * dx - compute_form_data(F) + fd = compute_form_data(F) + assert fd.num_coefficients == 1