Skip to content
This repository has been archived by the owner on Feb 21, 2022. It is now read-only.

Commit

Permalink
Merged in mapdes/fiat/entity-argument (pull request #28)
Browse files Browse the repository at this point in the history
Add optional entity argument to the tabulate method
  • Loading branch information
miklos1 committed Sep 22, 2016
2 parents 1bc440c + 1e50090 commit 70f0996
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 24 deletions.
4 changes: 2 additions & 2 deletions FIAT/bubble.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ def num_sub_elements(self):
def space_dimension(self):
return self.fsdim

def tabulate(self, order, points):
def tabulate(self, order, points, entity=None):
return dict((k, v[self.first_node_index:, :])
for k, v in self._element.tabulate(order, points).items())
for k, v in self._element.tabulate(order, points, entity).items())

def value_shape(self):
return self._element.value_shape()
Expand Down
4 changes: 2 additions & 2 deletions FIAT/discontinuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ def space_dimension(self):
"Return the dimension of the finite element space."
return self._element.space_dimension()

def tabulate(self, order, points):
def tabulate(self, order, points, entity=None):
"""Return tabulated values of derivatives up to given order of
basis functions at given points."""
return self._element.tabulate(order, points)
return self._element.tabulate(order, points, entity)

def value_shape(self):
"Return the value shape of the finite element functions."
Expand Down
7 changes: 4 additions & 3 deletions FIAT/enriched.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (C) 2008 Robert C. Kirby (Texas Tech University)
# Copyright (C) 2013 Andrew T. T. McRae
# Modified by Thomas H. Gibson, 2016
#
# This file is part of FIAT.
#
Expand Down Expand Up @@ -99,7 +100,7 @@ def space_dimension(self):
# number of dofs just adds
return self.A.space_dimension() + self.B.space_dimension()

def tabulate(self, order, points):
def tabulate(self, order, points, entity=None):
"""Return tabulated values of derivatives up to given order of
basis functions at given points."""

Expand All @@ -109,8 +110,8 @@ def tabulate(self, order, points):

Asd = self.A.space_dimension()
Bsd = self.B.space_dimension()
Atab = self.A.tabulate(order, points)
Btab = self.B.tabulate(order, points)
Atab = self.A.tabulate(order, points, entity)
Btab = self.B.tabulate(order, points, entity)
npoints = len(points)
vs = self.A.value_shape()
rank = len(vs) # scalar: 0, vector: 1
Expand Down
20 changes: 17 additions & 3 deletions FIAT/finite_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# along with FIAT. If not, see <http://www.gnu.org/licenses/>.
#
# Modified by David A. Ham (david.ham@imperial.ac.uk), 2014
# Modified by Thomas H. Gibson (t.gibson15@imperial.ac.uk), 2016

from __future__ import absolute_import, print_function, division

Expand Down Expand Up @@ -138,10 +139,23 @@ def space_dimension(self):
"Return the dimension of the finite element space."
return self.poly_set.get_num_members()

def tabulate(self, order, points):
def tabulate(self, order, points, entity=None):
"""Return tabulated values of derivatives up to given order of
basis functions at given points."""
return self.poly_set.tabulate(points, order)
basis functions at given points.
:arg order: The maximum order of derivative.
:arg points: An iterable of points.
:arg entity: Optional (dimension, entity number) pair
indicating which topological entity of the
reference element to tabulate on. If ``None``,
default cell-wise tabulation is performed.
"""
if entity is None:
entity = (self.ref_el.get_spatial_dimension(), 0)

entity_dim, entity_id = entity
transform = self.ref_el.get_entity_transform(entity_dim, entity_id)
return self.poly_set.tabulate(list(map(transform, points)), order)

def value_shape(self):
"Return the value shape of the finite element functions."
Expand Down
8 changes: 4 additions & 4 deletions FIAT/hdivcurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ def value_shape(self):
# redefine tabulate
newelement.old_tabulate = newelement.tabulate

def tabulate(self, order, points):
def tabulate(self, order, points, entity=None):
"""Return tabulated values of derivatives up to given order of
basis functions at given points."""

# don't duplicate what the old function does fine...
old_result = self.old_tabulate(order, points)
old_result = self.old_tabulate(order, points, entity)
new_result = {}
sd = self.get_reference_element().get_spatial_dimension()
for alpha in old_result.keys():
Expand Down Expand Up @@ -175,12 +175,12 @@ def value_shape(self):
# redefine tabulate
newelement.old_tabulate = newelement.tabulate

def tabulate(self, order, points):
def tabulate(self, order, points, entity=None):
"""Return tabulated values of derivatives up to given order of
basis functions at given points."""

# don't duplicate what the old function does fine...
old_result = self.old_tabulate(order, points)
old_result = self.old_tabulate(order, points, entity)
new_result = {}
sd = self.get_reference_element().get_spatial_dimension()
for alpha in old_result.keys():
Expand Down
4 changes: 2 additions & 2 deletions FIAT/restricted.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def mapping(self):
mappings = self._element.mapping()
return [mappings[i] for i in self._indices]

def tabulate(self, order, points):
result = self._element.tabulate(order, points)
def tabulate(self, order, points, entity=None):
result = self._element.tabulate(order, points, entity)
extracted = {}
for (dtuple, values) in sorted_by_key(result):
extracted[dtuple] = numpy.array([values[i] for i in self._indices])
Expand Down
35 changes: 27 additions & 8 deletions FIAT/tensor_product.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (C) 2008 Robert C. Kirby (Texas Tech University)
# Copyright (C) 2013 Andrew T. T. McRae
# Modified by Thomas H. Gibson, 2016
#
# This file is part of FIAT.
#
Expand Down Expand Up @@ -240,16 +241,34 @@ def space_dimension(self):
# number of dofs just multiplies
return self.A.space_dimension() * self.B.space_dimension()

def tabulate(self, order, points):
def tabulate(self, order, points, entity=None):
"""Return tabulated values of derivatives up to given order of
basis functions at given points."""

Asdim = self.A.get_reference_element().get_spatial_dimension()
Bsdim = self.B.get_reference_element().get_spatial_dimension()
pointsA = [point[0:Asdim] for point in points]
pointsB = [point[Asdim:Asdim + Bsdim] for point in points]
Atab = self.A.tabulate(order, pointsA)
Btab = self.B.tabulate(order, pointsB)
if entity is None:
entity = (self.ref_el.get_dimension(), 0)
entity_dim, entity_id = entity

shape = tuple(len(c.get_topology()[d])
for c, d in zip(self.ref_el.cells, entity_dim))
idA, idB = numpy.unravel_index(entity_id, shape)

# Factor the entity argument to get entities of the component elements
entityA_dim, entityB_dim = entity_dim
entityA = (entityA_dim, idA)
entityB = (entityB_dim, idB)

pointsAdim, pointsBdim = [c.get_spatial_dimension()
for c in self.ref_el.construct_subelement(entity_dim).cells]
pointsA = [point[:pointsAdim] for point in points]
pointsB = [point[pointsAdim:pointsAdim + pointsBdim] for point in points]

Asdim = self.A.ref_el.get_spatial_dimension()
Bsdim = self.B.ref_el.get_spatial_dimension()
# Note that for entities other than cells, the following
# tabulations are already appropriately zero-padded so no
# additional zero padding is required.
Atab = self.A.tabulate(order, pointsA, entityA)
Btab = self.B.tabulate(order, pointsB, entityB)
npoints = len(points)

# allow 2 scalar-valued FE spaces, or 1 scalar-valued,
Expand Down

0 comments on commit 70f0996

Please sign in to comment.