Skip to content

Commit

Permalink
Merged in wence/pullback-tensor-vector-valued (pull request #113)
Browse files Browse the repository at this point in the history
* wence/pullback-tensor-vector-valued:
  Allow TensorElement to wrap a vector/tensor-valued element
  pullbacks: Support pullback of vector/tensor-valued things
  • Loading branch information
wence- committed Jun 27, 2019
2 parents 0d56bd5 + 2da7945 commit 9f17cb4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
10 changes: 4 additions & 6 deletions ufl/algorithms/apply_function_pullbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

from ufl.tensors import as_tensor, as_vector
from ufl.utils.sequences import product
import numpy


def sub_elements_with_mappings(element):
Expand Down Expand Up @@ -146,14 +147,12 @@ def apply_single_function_pullbacks(g):
# (ONLY IF REFERENCE VALUE SHAPE PRESERVES TENSOR RANK)
# - All cases with scalar subelements and without symmetries are
# covered by the shortcut above
# - VectorElements of vector-valued basic elements (FIXME)
# - TensorElements with symmetries (FIXME)
assert len(gsh) == 1
assert len(rsh) == 1

g_components = [None] * gsize
gpos = 0
rpos = 0

r = as_vector([r[idx] for idx in numpy.ndindex(r.ufl_shape)])
for subelm in sub_elements_with_mappings(element):
gm = product(subelm.value_shape())
rm = product(subelm.reference_value_shape())
Expand Down Expand Up @@ -234,8 +233,7 @@ def apply_single_function_pullbacks(g):

# Wrap up components in a vector, must return same shape as input
# function g
assert len(gsh) == 1
f = as_vector(g_components)
f = as_tensor(numpy.asarray(g_components).reshape(gsh))
assert f.ufl_shape == g.ufl_shape
return f

Expand Down
5 changes: 2 additions & 3 deletions ufl/finiteelement/mixedelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,6 @@ def __init__(self, family, cell=None, degree=None, shape=None,
# Create scalar sub element
sub_element = FiniteElement(family, cell, degree, quad_scheme=quad_scheme)

if sub_element.value_shape() != ():
error("Expecting only scalar valued subelement for TensorElement.")

# Set default shape if not specified
if shape is None:
if cell is None:
Expand Down Expand Up @@ -424,6 +421,8 @@ def __init__(self, family, cell=None, degree=None, shape=None,
reference_value_shape = shape
self._mapping = "identity"

value_shape = value_shape + sub_element.value_shape()
reference_value_shape = reference_value_shape + sub_element.reference_value_shape()
# Initialize element data
MixedElement.__init__(self, sub_elements, value_shape=value_shape,
reference_value_shape=reference_value_shape)
Expand Down

0 comments on commit 9f17cb4

Please sign in to comment.