~ubuntu-branches/ubuntu/vivid/ffc/vivid

« back to all changes in this revision

Viewing changes to ffc/tensor/costestimation.py

  • Committer: Package Import Robot
  • Author(s): Johannes Ring
  • Date: 2014-06-03 18:26:02 UTC
  • mfrom: (1.1.15)
  • Revision ID: package-import@ubuntu.com-20140603182602-zvnubjjh7i78e1v0
Tags: 1.4.0-1
* New upstream release.
* debian/control:
  - Add swig in Build-Depends.
  - Remove python-ufc from Depends.
  - Add ufc and python-ufc to Provides, Conflicts and Replaces.
  - Remove python-ferari and python-dolfin from Suggests.
  - Bump minimum required version for python-fiat, python-instant and
    python-ufl to 1.4.0.
* debian/rules: Add override for auto clean target to remove generated
  cmake and pkg-config files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
# along with FFC. If not, see <http://www.gnu.org/licenses/>.
17
17
#
18
18
# First added:  2010-01-25
19
 
# Last changed: 2010-01-25
 
19
# Last changed: 2014-04-15
20
20
 
21
21
# FFC modules
22
22
from ffc.log import debug
27
27
 
28
28
def estimate_cost(integral, function_replace_map):
29
29
    """
30
 
    Estimate cost of tensor representation for integrand. The cost is
 
30
    Estimate cost of tensor representation for integral. The cost is
31
31
    computed as the sum of the number of coefficients and derivatives,
32
32
    if the integrand can be represented as a monomial, and -1 if not.
33
33
    """
34
34
 
35
 
    # TODO: Implement this to take integrand instead of integral? May allow simplification inn caller code.
 
35
    # Check that integral type is supported
 
36
    supported = ["cell", "exterior_facet", "interior_facet"]
 
37
    if not integral.integral_type() in supported:
 
38
        return -1
36
39
 
37
40
    # Extract monomial integrand
 
41
    integrand = integral.integrand()
38
42
    try:
39
 
        monomial_form = extract_monomial_form([integral], function_replace_map)
 
43
        monomial_form = extract_monomial_form([integrand], function_replace_map)
40
44
        transform_monomial_form(monomial_form)
41
45
    except Exception, exception:
42
46
        debug("Monomial extraction failed: " + str(exception))
43
47
        return -1
44
48
 
45
 
    # Check that we get just one integral
46
 
    if not len(monomial_form.integrals) == 1:
 
49
    # Check that we get just one integrand
 
50
    if not len(monomial_form) == 1:
47
51
        error("Expecting just one integrand.")
48
52
 
49
53
    # Compute cost
50
 
    (integrand, measure) = monomial_form.integrals[0]
51
54
    cost = 0
52
 
    for monomial in integrand.monomials:
53
 
        cost = max(cost, len(monomial.coefficients) + len(monomial.transforms))
54
 
 
 
55
    for integrand in monomial_form:
 
56
        for monomial in integrand.monomials:
 
57
            cost = max(cost, len(monomial.coefficients) + len(monomial.transforms))
55
58
    return cost