Skip to content

Commit bee3cba

Browse files
authored
Merge branch 'main' into jhale/external-operator-2023
2 parents 6e1d9b8 + a49736c commit bee3cba

22 files changed

+138
-114
lines changed

test/test_cell.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,9 @@ def test_cells_2d(cell):
5959
assert cell.num_peaks() == cell.num_vertices()
6060

6161

62+
def test_tensorproductcell():
63+
orig = ufl.TensorProductCell(ufl.interval, ufl.interval)
64+
cell = orig.reconstruct()
65+
assert cell.sub_cells() == orig.sub_cells()
66+
assert cell.topological_dimension() == orig.topological_dimension()
67+
assert cell.geometric_dimension() == orig.geometric_dimension()

test/test_complex.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
from ufl.algorithms import estimate_total_polynomial_degree
1111
from ufl.algorithms.comparison_checker import do_comparison_check, ComplexComparisonError
1212
from ufl.algorithms.formtransformations import compute_form_adjoint
13-
from ufl import TestFunction, TrialFunction, triangle, FiniteElement, \
14-
as_ufl, inner, grad, dx, dot, outer, conj, sqrt, sin, cosh, \
15-
atan, ln, exp, as_tensor, real, imag, conditional, \
16-
min_value, max_value, gt, lt, cos, ge, le, Coefficient
13+
from ufl import (TestFunction, TrialFunction, triangle, FiniteElement,
14+
as_ufl, inner, grad, dx, dot, outer, conj, sqrt, sin, cosh,
15+
atan, ln, exp, as_tensor, real, imag, conditional,
16+
min_value, max_value, gt, lt, cos, ge, le, Coefficient)
1717

1818

1919
def test_conj(self):

test/test_duals.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env py.test
22
# -*- coding: utf-8 -*-
33

4-
from ufl import FiniteElement, FunctionSpace, MixedFunctionSpace, \
5-
Coefficient, Matrix, Cofunction, FormSum, Argument, Coargument,\
6-
TestFunction, TrialFunction, Adjoint, Action, \
7-
action, adjoint, derivative, tetrahedron, triangle, interval, dx
4+
from ufl import (FiniteElement, FunctionSpace, MixedFunctionSpace,
5+
Coefficient, Matrix, Cofunction, FormSum, Argument, Coargument,
6+
TestFunction, TrialFunction, Adjoint, Action,
7+
action, adjoint, derivative, tetrahedron, triangle, interval, dx)
88
from ufl.constantvalue import Zero
99
from ufl.form import ZeroBaseForm
1010

test/test_elements.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,9 @@ def test_mse():
229229

230230
element = FiniteElement('GLL-Edge L2', interval, degree - 1)
231231
assert element == eval(repr(element))
232+
233+
234+
def test_withmapping():
235+
base = FiniteElement("CG", interval, 1)
236+
element = WithMapping(base, "identity")
237+
assert element == eval(repr(element))

test/test_new_ad.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
from ufl.classes import Grad
99
from ufl.algorithms import tree_format
1010
from ufl.algorithms.renumbering import renumber_indices
11-
from ufl.algorithms.apply_derivatives import apply_derivatives, GenericDerivativeRuleset, \
12-
GradRuleset, VariableRuleset, GateauxDerivativeRuleset
11+
from ufl.algorithms.apply_derivatives import (
12+
apply_derivatives, GenericDerivativeRuleset,
13+
GradRuleset, VariableRuleset, GateauxDerivativeRuleset)
1314

1415

1516
# Note: the old tests in test_automatic_differentiation.py are a bit messy

test/test_signature.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
from ufl import *
1010

1111
from ufl.classes import MultiIndex, FixedIndex
12-
from ufl.algorithms.signature import compute_multiindex_hashdata, \
13-
compute_terminal_hashdata
12+
from ufl.algorithms.signature import compute_multiindex_hashdata, compute_terminal_hashdata
1413

1514
from itertools import chain
1615

ufl/algorithms/signature.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ def compute_terminal_hashdata(expressions, renumbering):
4343
# arguments, and just take repr of the rest of the terminals while
4444
# we're iterating over them
4545
terminal_hashdata = {}
46-
labels = {}
4746
index_numbering = {}
4847
for expression in expressions:
4948
for expr in traverse_unique_terminals(expression):
@@ -69,12 +68,7 @@ def compute_terminal_hashdata(expressions, renumbering):
6968
data = expr._ufl_signature_data_(renumbering)
7069

7170
elif isinstance(expr, Label):
72-
# Numbering labels as we visit them # TODO: Include in
73-
# renumbering
74-
data = labels.get(expr)
75-
if data is None:
76-
data = "L%d" % len(labels)
77-
labels[expr] = data
71+
data = expr._ufl_signature_data_(renumbering)
7872

7973
elif isinstance(expr, ExprList):
8074
# Not really a terminal but can have 0 operands...

ufl/argument.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def __eq__(self, other):
130130
are the same ufl element but different dolfin function spaces.
131131
"""
132132
return (
133-
type(self) == type(other) and self._number == other._number and # noqa: W504
133+
type(self) is type(other) and self._number == other._number and # noqa: W504
134134
self._part == other._part and self._ufl_function_space == other._ufl_function_space
135135
)
136136

ufl/cell.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def reconstruct(self, **kwargs: typing.Any) -> Cell:
6363

6464
def __lt__(self, other: AbstractCell) -> bool:
6565
"""Define an arbitrarily chosen but fixed sort order for all cells."""
66-
if type(self) == type(other):
66+
if type(self) is type(other):
6767
s = (self.geometric_dimension(), self.topological_dimension())
6868
o = (other.geometric_dimension(), other.topological_dimension())
6969
if s != o:
@@ -409,7 +409,7 @@ def reconstruct(self, **kwargs: typing.Any) -> Cell:
409409
gdim = value
410410
else:
411411
raise TypeError(f"reconstruct() got unexpected keyword argument '{key}'")
412-
return TensorProductCell(self._cellname, geometric_dimension=gdim)
412+
return TensorProductCell(*self._cells, geometric_dimension=gdim)
413413

414414

415415
def simplex(topological_dimension: int, geometric_dimension: typing.Optional[int] = None):

ufl/coefficient.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,27 @@
1919
from ufl.functionspace import AbstractFunctionSpace, FunctionSpace, MixedFunctionSpace
2020
from ufl.form import BaseForm
2121
from ufl.split_functions import split
22-
from ufl.utils.counted import counted_init
22+
from ufl.utils.counted import Counted
2323
from ufl.duals import is_primal, is_dual
2424

2525
# --- The Coefficient class represents a coefficient in a form ---
2626

2727

28-
class BaseCoefficient(object):
28+
class BaseCoefficient(Counted):
2929
"""UFL form argument type: Parent Representation of a form coefficient."""
3030

3131
# Slots are disabled here because they cause trouble in PyDOLFIN
3232
# multiple inheritance pattern:
3333
# __slots__ = ("_count", "_ufl_function_space", "_repr", "_ufl_shape")
3434
_ufl_noslots_ = True
3535
__slots__ = ()
36-
_globalcount = 0
3736
_ufl_is_abstract_ = True
3837

3938
def __getnewargs__(self):
4039
return (self._ufl_function_space, self._count)
4140

4241
def __init__(self, function_space, count=None):
43-
counted_init(self, count, Coefficient)
42+
Counted.__init__(self, count, Coefficient)
4443

4544
if isinstance(function_space, FiniteElementBase):
4645
# For legacy support for .ufl files using cells, we map
@@ -57,9 +56,6 @@ def __init__(self, function_space, count=None):
5756
self._repr = "BaseCoefficient(%s, %s)" % (
5857
repr(self._ufl_function_space), repr(self._count))
5958

60-
def count(self):
61-
return self._count
62-
6359
@property
6460
def ufl_shape(self):
6561
"Return the associated UFL shape."
@@ -111,14 +107,14 @@ class Cofunction(BaseCoefficient, BaseForm):
111107

112108
__slots__ = (
113109
"_count",
110+
"_counted_class",
114111
"_arguments",
115112
"_ufl_function_space",
116113
"ufl_operands",
117114
"_repr",
118115
"_ufl_shape",
119116
"_hash"
120117
)
121-
# _globalcount = 0
122118
_primal = False
123119
_dual = True
124120

@@ -161,7 +157,6 @@ class Coefficient(FormArgument, BaseCoefficient):
161157
"""UFL form argument type: Representation of a form coefficient."""
162158

163159
_ufl_noslots_ = True
164-
_globalcount = 0
165160
_primal = True
166161
_dual = False
167162

ufl/constant.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,16 @@
1111
from ufl.core.ufl_type import ufl_type
1212
from ufl.core.terminal import Terminal
1313
from ufl.domain import as_domain
14-
from ufl.utils.counted import counted_init
14+
from ufl.utils.counted import Counted
1515

1616

1717
@ufl_type()
18-
class Constant(Terminal):
18+
class Constant(Terminal, Counted):
1919
_ufl_noslots_ = True
20-
_globalcount = 0
2120

2221
def __init__(self, domain, shape=(), count=None):
2322
Terminal.__init__(self)
24-
counted_init(self, count=count, countedclass=Constant)
23+
Counted.__init__(self, count, Constant)
2524

2625
self._ufl_domain = as_domain(domain)
2726
self._ufl_shape = shape
@@ -31,9 +30,6 @@ def __init__(self, domain, shape=(), count=None):
3130
self._repr = "Constant({}, {}, {})".format(
3231
repr(self._ufl_domain), repr(self._ufl_shape), repr(self._count))
3332

34-
def count(self):
35-
return self._count
36-
3733
@property
3834
def ufl_shape(self):
3935
return self._ufl_shape

ufl/core/multiindex.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Modified by Massimiliano Leoni, 2016.
1111

1212

13-
from ufl.utils.counted import counted_init
13+
from ufl.utils.counted import Counted
1414
from ufl.core.ufl_type import ufl_type
1515
from ufl.core.terminal import Terminal
1616

@@ -70,20 +70,15 @@ def __repr__(self):
7070
return r
7171

7272

73-
class Index(IndexBase):
73+
class Index(IndexBase, Counted):
7474
"""UFL value: An index with no value assigned.
7575
7676
Used to represent free indices in Einstein indexing notation."""
77-
__slots__ = ("_count",)
78-
79-
_globalcount = 0
77+
__slots__ = ("_count", "_counted_class")
8078

8179
def __init__(self, count=None):
8280
IndexBase.__init__(self)
83-
counted_init(self, count, Index)
84-
85-
def count(self):
86-
return self._count
81+
Counted.__init__(self, count, Index)
8782

8883
def __hash__(self):
8984
return hash(("Index", self._count))

ufl/core/ufl_type.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def __hash__(self) -> int:
3939
return hash(self._ufl_hash_data_())
4040

4141
def __eq__(self, other):
42-
return type(self) == type(other) and self._ufl_hash_data_() == other._ufl_hash_data_()
42+
return type(self) is type(other) and self._ufl_hash_data_() == other._ufl_hash_data_()
4343

4444
def __ne__(self, other):
4545
return not self.__eq__(other)
@@ -61,7 +61,7 @@ def __hash__(self):
6161

6262
def __eq__(self, other):
6363
"__eq__ implementation attached in attach_operators_from_hash_data"
64-
return type(self) == type(other) and self._ufl_hash_data_() == other._ufl_hash_data_()
64+
return type(self) is type(other) and self._ufl_hash_data_() == other._ufl_hash_data_()
6565
cls.__eq__ = __eq__
6666

6767
def __ne__(self, other):

ufl/exprequals.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def expr_equals(self, other):
1515

1616
# Fast cutoffs for common cases, type difference or hash
1717
# difference will cutoff more or less all nonequal types
18-
if type(self) != type(other) or hash(self) != hash(other):
18+
if type(self) is not type(other) or hash(self) != hash(other):
1919
return False
2020

2121
# Large objects are costly to compare with themselves

ufl/finiteelement/finiteelementbase.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def __hash__(self):
8383

8484
def __eq__(self, other):
8585
"Compute element equality for insertion in hashmaps."
86-
return type(self) == type(other) and self._ufl_hash_data_() == other._ufl_hash_data_()
86+
return type(self) is type(other) and self._ufl_hash_data_() == other._ufl_hash_data_()
8787

8888
def __ne__(self, other):
8989
"Compute element inequality for insertion in hashmaps."

ufl/finiteelement/hdivcurl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def __getattr__(self, attr):
119119
(type(self).__name__, attr))
120120

121121
def __repr__(self):
122-
return f"WithMapping({repr(self.wrapee)}, {self._mapping})"
122+
return f"WithMapping({repr(self.wrapee)}, '{self._mapping}')"
123123

124124
def value_shape(self):
125125
gdim = self.cell().geometric_dimension()

0 commit comments

Comments
 (0)