|
60 | 60 | from ufl.algorithms.apply_derivatives import apply_derivatives |
61 | 61 | from ufl.algorithms.apply_geometry_lowering import apply_geometry_lowering |
62 | 62 | from ufl.classes import Indexed, MultiIndex, ReferenceGrad |
63 | | -from ufl.constantvalue import as_ufl |
| 63 | +from ufl.constantvalue import Zero, as_ufl |
64 | 64 | from ufl.domain import extract_unique_domain |
65 | 65 | from ufl.finiteelement import FiniteElement, MixedElement |
66 | 66 | from ufl.pullback import identity_pullback |
@@ -902,6 +902,39 @@ def test_index_simplification_reference_grad(self): |
902 | 902 | assert expr.ufl_shape == () |
903 | 903 |
|
904 | 904 |
|
| 905 | +def test_zero_shape(self): |
| 906 | + cell = triangle |
| 907 | + shape = (2, 3, 4) |
| 908 | + P1 = FiniteElement("Lagrange", cell, 1, shape, identity_pullback, H1) |
| 909 | + domain = Mesh(FiniteElement("Lagrange", cell, 1, (2,), identity_pullback, H1)) |
| 910 | + V = FunctionSpace(domain, P1) |
| 911 | + v = TestFunction(V) |
| 912 | + u = Coefficient(V) |
| 913 | + w = Coefficient(V) |
| 914 | + |
| 915 | + (i,) = indices(1) |
| 916 | + z = zero(shape) |
| 917 | + zi = z[:, i, :] |
| 918 | + wi = w[:, i, :] |
| 919 | + assert isinstance(zi, Zero) |
| 920 | + assert wi.ufl_shape == (shape[0], shape[-1]) |
| 921 | + assert wi.ufl_shape == zi.ufl_shape |
| 922 | + |
| 923 | + a = derivative(conditional(u[0, 0, 0] < 1, zi, wi), u, v) |
| 924 | + assert not isinstance(a, Zero) |
| 925 | + |
| 926 | + assert a.ufl_shape == zi.ufl_shape |
| 927 | + assert a.ufl_free_indices == zi.ufl_free_indices |
| 928 | + assert a.ufl_index_dimensions == zi.ufl_index_dimensions |
| 929 | + |
| 930 | + expr = apply_derivatives(apply_geometry_lowering(apply_algebra_lowering(a))) |
| 931 | + |
| 932 | + assert isinstance(expr, Zero) |
| 933 | + assert expr.ufl_shape == a.ufl_shape |
| 934 | + assert expr.ufl_free_indices == a.ufl_free_indices |
| 935 | + assert expr.ufl_index_dimensions == a.ufl_index_dimensions |
| 936 | + |
| 937 | + |
905 | 938 | # --- Scratch space |
906 | 939 |
|
907 | 940 |
|
|
0 commit comments