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

« back to all changes in this revision

Viewing changes to ffc/utils.py

  • Committer: Package Import Robot
  • Author(s): Johannes Ring
  • Date: 2015-01-12 21:08:58 UTC
  • mfrom: (1.1.16)
  • Revision ID: package-import@ubuntu.com-20150112210858-16bep8qwomfo4dvi
Tags: 1.5.0-1
* New upstream release.
* debian/control:
  - Bump Standards-Version to 3.9.6 (no changes needed).
  - Bump X-Python-Version to >= 2.7.
  - Bump minimum required version for python-fiat, python-instant and
    python-ufl to 1.5.0.
  - Add python-numpy and python-six to Depends field.
  - Bump python-all-dev in Build-Depends to >= 2.7.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Anders Logg
 
1
# Copyright (C) 2005-2014 Anders Logg
2
2
#
3
3
# This file is part of FFC.
4
4
#
16
16
# along with FFC. If not, see <http://www.gnu.org/licenses/>.
17
17
#
18
18
# Modified by Kristian B. Oelgaard, 2009
19
 
#
20
 
# First added:  2005-02-04
21
 
# Last changed: 2014-04-02
 
19
# Modified by Martin Alnaes 2014
22
20
 
23
21
# Python modules.
24
22
import operator
26
24
import itertools
27
25
 
28
26
# FFC modules.
29
 
from log import error
 
27
from .log import error
30
28
 
31
 
def product(sequence):
32
 
    "Return the product of all elements in a sequence."
33
 
    # Copied from UFL
34
 
    return functools.reduce(operator.__mul__, sequence, 1)
 
29
from ufl.utils.sequences import product
35
30
 
36
31
def all_equal(sequence):
37
32
    "Check that all items in list are equal."
66
61
               permutations += [(i, ) + p]
67
62
   return permutations
68
63
 
69
 
def compute_derivative_tuples(n, gdim):
70
 
    """Compute the list of all derivative tuples for derivatives of
71
 
    given total order n and given geometric dimension gdim. This
72
 
    function returns two lists. The first is a list of tuples, where
73
 
    each tuple of length n specifies the coordinate directions of the
74
 
    n derivatives. The second is a corresponding list of tuples, where
75
 
    each tuple of length gdim specifies the number of derivatives in
76
 
    each direction. Both lists have length gdim^n and are ordered as
77
 
    expected by the UFC function tabulate_basis_derivatives.
78
 
 
79
 
    Example: If n = 2 and gdim = 3, then the nice tuples are
80
 
 
81
 
      (0, 0)  <-->  (2, 0, 0)  <-->  d^2/dxdx
82
 
      (0, 1)  <-->  (1, 1, 0)  <-->  d^2/dxdy
83
 
      (0, 2)  <-->  (1, 0, 1)  <-->  d^2/dxdz
84
 
      (1, 0)  <-->  (1, 1, 0)  <-->  d^2/dydx
85
 
      (1, 1)  <-->  (0, 2, 0)  <-->  d^2/dydy
86
 
      (1, 2)  <-->  (0, 1, 1)  <-->  d^2/dydz
87
 
      (2, 0)  <-->  (1, 0, 1)  <-->  d^2/dzdx
88
 
      (2, 1)  <-->  (0, 1, 1)  <-->  d^2/dzdy
89
 
      (2, 2)  <-->  (0, 0, 2)  <-->  d^2/dzdz
90
 
    """
91
 
 
92
 
    # Create list of derivatives (note that we have d^n derivatives)
93
 
    deriv_tuples = [d for d in itertools.product(*(n*[range(0, gdim)]))]
94
 
 
95
 
    # Translate from list of derivative tuples to list of tuples
96
 
    # expressing the number of derivatives in each dimension...
97
 
    _deriv_tuples = [tuple(len([_d for _d in d if _d == i]) for i in range(gdim))
98
 
                     for d in deriv_tuples]
99
 
 
100
 
    return deriv_tuples, _deriv_tuples