Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make cofunctionals terminal, and test #300

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions test/test_equals.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Test of expression comparison."""

from ufl import Coefficient, Cofunction, FunctionSpace, Mesh, triangle
from ufl.exprcontainers import ExprList
from ufl.finiteelement import FiniteElement
from ufl.pullback import identity_pullback
from ufl.sobolevspace import H1
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions ufl/coefficient.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class Cofunction(BaseCoefficient, BaseForm):
)
_primal = False
_dual = True
_ufl_is_terminal_ = True

__eq__ = BaseForm.__eq__

Expand Down
16 changes: 16 additions & 0 deletions ufl/formatting/ufl2unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,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()
Expand Down
Loading