Skip to content

Commit

Permalink
PR FEniCS#184: fix behaviour when perp is Zero and expand testing
Browse files Browse the repository at this point in the history
  • Loading branch information
tommbendall committed Jul 27, 2023
1 parent 3206146 commit f0fc007
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions test/test_tensoralgebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,25 @@ def test_cross(self):


def test_perp(self):
# Test perp is generally doing the correct thing
u = as_vector([3, 1])
v = perp(u)
w = as_vector([-1, 3])
self.assertEqualValues(v, w)

# Test that a perp does the correct thing to Zero
u = zero(2)
v = perp(u)
self.assertEqualValues(u, v)

# Test that perp throws an error if the wrong thing is provided
u = as_vector([3, 1, -1]) # 3D vector instead of 2D
with pytest.raises(ValueError):
v = perp(u)
u = as_matrix([[1, 3], [0, 4]]) # Matrix instead of vector
with pytest.raises(ValueError):
v = perp(u)


def xtest_dev(self, A):
C = dev(A)
Expand Down
2 changes: 1 addition & 1 deletion ufl/tensoralgebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def __new__(cls, A):

# Simplification
if isinstance(A, Zero):
return Zero((), A.ufl_free_indices, A.ufl_index_dimensions)
return Zero(sh, A.ufl_free_indices, A.ufl_index_dimensions)

return CompoundTensorOperator.__new__(cls)

Expand Down

0 comments on commit f0fc007

Please sign in to comment.