diff --git a/test/test_equals.py b/test/test_equals.py index ddfa5058c..d1251acb8 100755 --- a/test/test_equals.py +++ b/test/test_equals.py @@ -4,6 +4,7 @@ from ufl.finiteelement import FiniteElement from ufl.pullback import identity_pullback from ufl.sobolevspace import H1 +from ufl.exprcontainers import ExprList def test_comparison_of_coefficients(): @@ -69,6 +70,10 @@ def test_comparison_of_cofunctions(): assert not v1 == u1 assert not v2 == u2 + # Objects in ExprList as happens when taking derivatives. + assert ExprList(v1, v1) == ExprList(v1, v1b) + assert not ExprList(v1, v2) == ExprList(v1, v1) + def test_comparison_of_products(): V = FiniteElement("Lagrange", triangle, 1, (), identity_pullback, H1) diff --git a/ufl/coefficient.py b/ufl/coefficient.py index 3ff9c34e0..634d3bc49 100644 --- a/ufl/coefficient.py +++ b/ufl/coefficient.py @@ -115,6 +115,7 @@ class Cofunction(BaseCoefficient, BaseForm): ) _primal = False _dual = True + _ufl_is_terminal_ = True __eq__ = BaseForm.__eq__ diff --git a/ufl/formatting/ufl2unicode.py b/ufl/formatting/ufl2unicode.py index 0a5f0549f..5c193da40 100644 --- a/ufl/formatting/ufl2unicode.py +++ b/ufl/formatting/ufl2unicode.py @@ -481,10 +481,26 @@ def coefficient(self, o): return f"{var}{subscript_number(i)}" return self.coefficient_names[o.count()] + def cofunction(self, o): + """Format a cofunction.""" + if self.coefficient_names is None: + i = o.count() + var = "cofunction" + if len(o.ufl_shape) == 1: + var += UC.combining_right_arrow_above + elif len(o.ufl_shape) > 1 and self.colorama_bold: + var = f"{colorama.Style.BRIGHT}{var}{colorama.Style.RESET_ALL}" + return f"{var}{subscript_number(i)}" + return self.coefficient_names[o.count()] + def base_form_operator(self, o): """Format a base_form_operator.""" return "BaseFormOperator" + def action(self, o, a, b): + """Format an Action.""" + return f"Action({a}, {b})" + def constant(self, o): """Format a constant.""" i = o.count()