From 44c58e1006f582f51bffcb5e49c8df1860a18adb Mon Sep 17 00:00:00 2001 From: Matthew Scroggs Date: Fri, 20 Sep 2024 09:33:02 +0100 Subject: [PATCH 1/6] missing reference_ --- ufl/differentiation.py | 1 + ufl/finiteelement.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ufl/differentiation.py b/ufl/differentiation.py index 74e33617d..4006d9033 100644 --- a/ufl/differentiation.py +++ b/ufl/differentiation.py @@ -270,6 +270,7 @@ def _ufl_expr_reconstruct_(self, op): """Return a new object of the same type with new operands.""" if is_cellwise_constant(op): if op.ufl_shape != self.ufl_operands[0].ufl_shape: + from IPython import embed; embed() raise ValueError("Operand shape mismatch in Grad reconstruct.") if self.ufl_operands[0].ufl_free_indices != op.ufl_free_indices: raise ValueError("Free index mismatch in Grad reconstruct.") diff --git a/ufl/finiteelement.py b/ufl/finiteelement.py index a5ffff6a6..7ef947b2f 100644 --- a/ufl/finiteelement.py +++ b/ufl/finiteelement.py @@ -148,10 +148,10 @@ def components(self) -> _typing.Dict[_typing.Tuple[int, ...], int]: offset = 0 c_offset = 0 for e in self.sub_elements: - for i, j in enumerate(np.ndindex(e.value_shape)): + for i, j in enumerate(np.ndindex(e.reference_value_shape)): components[(offset + i,)] = c_offset + e.components[j] c_offset += max(e.components.values()) + 1 - offset += e.value_size + offset += e.reference_value_size return components @property From 0ac41813503215b7d6277fe9e0cb620f700960aa Mon Sep 17 00:00:00 2001 From: Matthew Scroggs Date: Fri, 20 Sep 2024 09:34:38 +0100 Subject: [PATCH 2/6] remove IPython embed --- ufl/differentiation.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ufl/differentiation.py b/ufl/differentiation.py index 4006d9033..74e33617d 100644 --- a/ufl/differentiation.py +++ b/ufl/differentiation.py @@ -270,7 +270,6 @@ def _ufl_expr_reconstruct_(self, op): """Return a new object of the same type with new operands.""" if is_cellwise_constant(op): if op.ufl_shape != self.ufl_operands[0].ufl_shape: - from IPython import embed; embed() raise ValueError("Operand shape mismatch in Grad reconstruct.") if self.ufl_operands[0].ufl_free_indices != op.ufl_free_indices: raise ValueError("Free index mismatch in Grad reconstruct.") From 5a47fe69ac18ab2031706ac09b05ed3d3a1d46c2 Mon Sep 17 00:00:00 2001 From: Matthew Scroggs Date: Fri, 20 Sep 2024 10:02:34 +0100 Subject: [PATCH 3/6] remove components property --- ufl/finiteelement.py | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/ufl/finiteelement.py b/ufl/finiteelement.py index 7ef947b2f..9929b2052 100644 --- a/ufl/finiteelement.py +++ b/ufl/finiteelement.py @@ -130,30 +130,6 @@ def _ufl_signature_data_(self) -> str: """Return UFL signature data.""" return repr(self) - @property - def components(self) -> _typing.Dict[_typing.Tuple[int, ...], int]: - """Get the numbering of the components of the element. - - Returns: - A map from the components of the values on a physical cell (eg (0, 1)) - to flat component numbers on the reference cell (eg 1) - """ - if isinstance(self.pullback, _SymmetricPullback): - return self.pullback._symmetry - - if len(self.sub_elements) == 0: - return {(): 0} - - components = {} - offset = 0 - c_offset = 0 - for e in self.sub_elements: - for i, j in enumerate(np.ndindex(e.reference_value_shape)): - components[(offset + i,)] = c_offset + e.components[j] - c_offset += max(e.components.values()) + 1 - offset += e.reference_value_size - return components - @property def reference_value_size(self) -> int: """Return the integer product of the reference value shape.""" From 25d78cbc99b3afb9dcd54354cdef6ec44ba25ce8 Mon Sep 17 00:00:00 2001 From: Matthew Scroggs Date: Fri, 20 Sep 2024 10:03:49 +0100 Subject: [PATCH 4/6] ruff --- ufl/finiteelement.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/ufl/finiteelement.py b/ufl/finiteelement.py index 9929b2052..8dbc76ed1 100644 --- a/ufl/finiteelement.py +++ b/ufl/finiteelement.py @@ -15,8 +15,6 @@ import abc as _abc import typing as _typing -import numpy as np - from ufl.cell import Cell as _Cell from ufl.pullback import AbstractPullback as _AbstractPullback from ufl.pullback import IdentityPullback as _IdentityPullback From 29dcbdfaefc0b36f1ebdff64a84f1ad2f4dc97e2 Mon Sep 17 00:00:00 2001 From: Matthew Scroggs Date: Tue, 24 Sep 2024 13:04:55 +0100 Subject: [PATCH 5/6] move components to function space --- ufl/algorithms/expand_indices.py | 6 +++--- ufl/functionspace.py | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/ufl/algorithms/expand_indices.py b/ufl/algorithms/expand_indices.py index 1ae1cbfc3..316998341 100644 --- a/ufl/algorithms/expand_indices.py +++ b/ufl/algorithms/expand_indices.py @@ -49,7 +49,7 @@ def form_argument(self, x): if sh == (): return x else: - e = x.ufl_element() + space = x.ufl_function_space() r = len(sh) # Get component @@ -58,8 +58,8 @@ def form_argument(self, x): raise ValueError("Component size mismatch.") # Map it through an eventual symmetry mapping - if len(e.components) > 1: - c = min(i for i, j in e.components.items() if j == e.components[c]) + if len(space.components) > 1: + c = min(i for i, j in space.components.items() if j == space.components[c]) if r != len(c): raise ValueError("Component size mismatch after symmetry mapping.") diff --git a/ufl/functionspace.py b/ufl/functionspace.py index cc047523c..1123654d9 100644 --- a/ufl/functionspace.py +++ b/ufl/functionspace.py @@ -60,6 +60,32 @@ def __init__(self, domain, element, label=""): self._ufl_domain = domain self._ufl_element = element + @property + def components(self) -> typing.Dict[typing.Tuple[int, ...], int]: + """Get the numbering of the components of the element of this space. + + Returns: + A map from the components of the values on a physical cell (eg (0, 1)) + to flat component numbers on the reference cell (eg 1) + """ + from ufl.pullback import SymmetricPullback + + if isinstance(self._ufl_element.pullback, SymmetricPullback): + return self._ufl_element.pullback._symmetry + + if len(self._ufl_element.sub_elements) == 0: + return {(): 0} + + components = {} + offset = 0 + c_offset = 0 + for s in self.ufl_sub_spaces(): + for i, j in enumerate(np.ndindex(s.value_shape)): + components[(offset + i,)] = c_offset + s.components[j] + c_offset += max(s.components.values()) + 1 + offset += s.value_size + return components + def label(self): """Return label of boundary domains to differentiate restricted and unrestricted.""" return self._label From ed13fa5ad176ffa3757ba33a6614acb7e595e454 Mon Sep 17 00:00:00 2001 From: Matthew Scroggs Date: Tue, 24 Sep 2024 13:06:39 +0100 Subject: [PATCH 6/6] import numpy as np --- ufl/functionspace.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ufl/functionspace.py b/ufl/functionspace.py index 1123654d9..834734274 100644 --- a/ufl/functionspace.py +++ b/ufl/functionspace.py @@ -11,6 +11,8 @@ import typing +import numpy as np + from ufl.core.ufl_type import UFLObject from ufl.domain import join_domains from ufl.duals import is_dual, is_primal