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

Move FiniteElement.components to FunctionSpace.components #307

Merged
merged 8 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
6 changes: 3 additions & 3 deletions ufl/algorithms/expand_indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.")

Expand Down
26 changes: 0 additions & 26 deletions ufl/finiteelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -130,30 +128,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.value_shape)):
components[(offset + i,)] = c_offset + e.components[j]
c_offset += max(e.components.values()) + 1
offset += e.value_size
return components

@property
def reference_value_size(self) -> int:
"""Return the integer product of the reference value shape."""
Expand Down
28 changes: 28 additions & 0 deletions ufl/functionspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -60,6 +62,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
jorgensd marked this conversation as resolved.
Show resolved Hide resolved

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
Expand Down
Loading