1
__author__ = "Kristian B. Oelgaard (k.b.oelgaard@tudelft.nl) and Anders Logg (logg@simula.no)"
2
__date__ = "2009-03-06 -- 2009-08-26"
3
__copyright__ = "Copyright (C) 2009 Kristian B. Oelgaard and Anders Logg"
4
__license__ = "GNU GPL version 3 or any later version"
7
from ufl import FiniteElement as UFLFiniteElement
8
from ufl import MixedElement as UFLMixedElement
9
from ufl import ElementRestriction as UFLElementRestriction
12
from ffc.common.log import debug, error
15
from finiteelement import FiniteElement as FFCFiniteElement
16
from mixedelement import MixedElement as FFCMixedElement
17
from quadratureelement import QuadratureElement as FFCQuadratureElement
19
# Cache for computed elements
22
def create_element(ufl_element, domain=None):
23
"Create FFC element (wrapper for FIAT element) from UFL element."
26
if ufl_element in _cache:
27
debug("Found element in element cache: " + str(ufl_element))
28
return _cache[ufl_element]
30
# Save the element that we'll use as hash
31
ufl_element_hash = ufl_element
32
if isinstance(ufl_element, UFLElementRestriction):
33
# If we already have a domain, make sure that it is equal to the domain
34
# of the restricted element
35
if domain and domain != ufl_element.domain():
36
error("Domain of restriction is not equal to the domain of the already restricted element. %s %s"\
37
%(str(domain), str(ufl_element.domain())))
38
# Get element and domain
39
domain = ufl_element.domain()
40
ufl_element = ufl_element.element()
42
# Create equivalent FFC element
43
if isinstance(ufl_element, UFLFiniteElement):
44
# Special handling for quadrature elements
45
if ufl_element.family() == "Quadrature":
46
ffc_element = FFCQuadratureElement(ufl_element.cell().domain(), ufl_element.degree(), domain)
48
ffc_element = FFCFiniteElement(ufl_element.family(), ufl_element.cell().domain(), ufl_element.degree(), domain)
49
elif isinstance(ufl_element, UFLMixedElement):
50
sub_elements = [create_element(e, domain) for e in ufl_element.sub_elements()]
51
ffc_element = FFCMixedElement(sub_elements, domain)
53
error("Unable to create equivalent FIAT element: %s" % str(ufl_element))
55
# Add element to cache
56
_cache[ufl_element_hash] = ffc_element