~ubuntu-branches/ubuntu/natty/ffc/natty

« back to all changes in this revision

Viewing changes to ffc/fem/createelement.py

  • Committer: Bazaar Package Importer
  • Author(s): Johannes Ring
  • Date: 2010-02-03 20:22:35 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100203202235-fe8d0kajuvgy2sqn
Tags: 0.9.0-1
* New upstream release.
* debian/control: Bump Standards-Version (no changes needed).
* Update debian/copyright and debian/copyright_hints.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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"
5
 
 
6
 
# Modified by Garth N. Wells 2009
7
 
 
8
 
# UFL modules
9
 
from ufl import FiniteElement as UFLFiniteElement
10
 
from ufl import MixedElement as UFLMixedElement
11
 
from ufl import ElementRestriction as UFLElementRestriction
12
 
from ufl import TensorElement as UFLTensorElement
13
 
 
14
 
# FFC common modules
15
 
from ffc.common.log import debug, error
16
 
 
17
 
# FFC fem modules
18
 
from finiteelement import FiniteElement as FFCFiniteElement
19
 
from mixedelement import MixedElement as FFCMixedElement
20
 
from quadratureelement import QuadratureElement as FFCQuadratureElement
21
 
 
22
 
# Cache for computed elements
23
 
_cache = {}
24
 
 
25
 
def create_element(ufl_element, domain=None):
26
 
    "Create FFC element (wrapper for FIAT element) from UFL element."
27
 
 
28
 
    # Check cache
29
 
    if ufl_element in _cache:
30
 
        debug("Found element in element cache: " + str(ufl_element))
31
 
        return _cache[ufl_element]
32
 
 
33
 
    # Save the element that we'll use as hash
34
 
    ufl_element_hash = ufl_element
35
 
    if isinstance(ufl_element, UFLElementRestriction):
36
 
        # If we already have a domain, make sure that it is equal to the domain
37
 
        # of the restricted element
38
 
        if domain and domain != ufl_element.domain():
39
 
            error("Domain of restriction is not equal to the domain of the already restricted element. %s %s"\
40
 
                   %(str(domain), str(ufl_element.domain())))
41
 
        # Get element and domain
42
 
        domain = ufl_element.domain()
43
 
        ufl_element = ufl_element.element()
44
 
 
45
 
    # Create equivalent FFC element
46
 
    if isinstance(ufl_element, UFLFiniteElement):
47
 
        if ufl_element.family() == "Quadrature":
48
 
            ffc_element = FFCQuadratureElement(ufl_element, domain)
49
 
        else:
50
 
            ffc_element = FFCFiniteElement(ufl_element, domain)
51
 
    elif isinstance(ufl_element, UFLMixedElement):
52
 
        sub_elements = [create_element(e, domain) for e in ufl_element.sub_elements()]
53
 
        ffc_element = FFCMixedElement(sub_elements, repr(ufl_element), domain)
54
 
        # FIXME: Temporary hack to 'support' tensor elements
55
 
        if isinstance(ufl_element, UFLTensorElement):
56
 
            ffc_element._rank = len(ufl_element._shape)
57
 
    else:
58
 
        error("Unable to create equivalent FIAT element: %s" % str(ufl_element))
59
 
 
60
 
    # Add element to cache
61
 
    _cache[ufl_element_hash] = ffc_element
62
 
 
63
 
    return ffc_element
64