~ubuntu-branches/ubuntu/raring/ffc/raring

« back to all changes in this revision

Viewing changes to ffc/quadrature/quadraturetransformer.py

  • Committer: Bazaar Package Importer
  • Author(s): Johannes Ring
  • Date: 2010-07-01 19:54:32 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20100701195432-xz3gw5nprdj79jcb
Tags: 0.9.3-1
* New upstream release.
* debian/control:
  - Minor fix in Vcs fields.
  - Bump Standards-Version to 3.9.0 (no changes needed).
  - Update version for python-ufc, python-fiat, and python-ufl in
    Depends field.
* Switch to dpkg-source 3.0 (quilt) format.
* Update debian/copyright and debian/copyright_hints.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 
8
8
# Modified by Peter Brune, 2009
9
9
# Modified by Anders Logg, 2009
10
 
# Last changed: 2010-02-08
 
10
# Last changed: 2010-03-11
11
11
 
12
12
# Python modules.
13
13
from numpy import shape
20
20
from ufl.classes import IntValue
21
21
from ufl.classes import FloatValue
22
22
from ufl.classes import Coefficient
 
23
from ufl.expr import Operator
23
24
 
24
25
# UFL Algorithms.
25
26
from ufl.algorithms.printing import tree_format
36
37
class QuadratureTransformer(QuadratureTransformerBase):
37
38
    "Transform UFL representation to quadrature code."
38
39
 
39
 
    def __init__(self, ir, optimise_parameters):
 
40
    def __init__(self, *args):
40
41
 
41
42
        # Initialise base class.
42
 
        QuadratureTransformerBase.__init__(self, ir, optimise_parameters)
 
43
        QuadratureTransformerBase.__init__(self, *args)
43
44
 
44
45
    # -------------------------------------------------------------------------
45
46
    # Start handling UFL classes.
241
242
            return {(): format["power"](val, expo.value())}
242
243
        elif isinstance(expo, FloatValue):
243
244
            return {(): format["std power"](val, format["floating point"](expo.value()))}
244
 
        elif isinstance(expo, Coefficient):
 
245
        elif isinstance(expo, (Coefficient, Operator)):
245
246
            exp = self.visit(expo)
246
247
            return {(): format["std power"](val, exp[()])}
247
248
        else:
269
270
        # Get the component
270
271
        components = self.component()
271
272
 
272
 
        # Safety checks.
 
273
        # Safety check.
273
274
        ffc_assert(not operands, "Didn't expect any operands for FacetNormal: " + repr(operands))
274
 
        ffc_assert(len(components) == 1, "FacetNormal expects 1 component index: " + repr(components))
275
 
 
276
 
        # We get one component.
277
 
        normal_component = format["normal component"](self.restriction, components[0])
278
 
        self.trans_set.add(normal_component)
 
275
 
 
276
        # Handle 1D as a special case.
 
277
        # FIXME: KBO: This has to change for mD elements in R^n : m < n
 
278
        if self.geo_dim == 1:
 
279
            # Safety check.
 
280
            ffc_assert(len(components) == 0, "FacetNormal in 1D does not expect a component index: " + repr(components))
 
281
            normal_component = format["normal component"](self.restriction, "")
 
282
            self.trans_set.add(normal_component)
 
283
        else:
 
284
 
 
285
            # Safety check.
 
286
            ffc_assert(len(components) == 1, "FacetNormal expects 1 component index: " + repr(components))
 
287
 
 
288
            # We get one component.
 
289
            normal_component = format["normal component"](self.restriction, components[0])
 
290
            self.trans_set.add(normal_component)
279
291
 
280
292
        return {():normal_component}
281
293
 
468
480
        ffc_assert(len(operands) == 1 and () in operands[0] and len(operands[0]) == 1, \
469
481
                   "MathFunctions expect one operand of function type: " + repr(operands))
470
482
        # Use format function on value of operand.
 
483
        new_operand = {}
471
484
        operand = operands[0]
472
485
        for key, val in operand.items():
473
 
            operand[key] = format_function(val)
474
 
        return operand
 
486
            new_operand[key] = format_function(val)
 
487
        return new_operand
475
488
 
476
489
    # -------------------------------------------------------------------------
477
490
    # Helper functions for code_generation()
495
508
        ops = self._count_operations(value)
496
509
        used_psi_tables = set([v for k, v in self.psi_tables_map.items()])
497
510
 
498
 
        return [value, ops, trans_set, used_points, used_psi_tables]
 
511
        return (value, ops, [trans_set, used_points, used_psi_tables])
499
512