16
16
# along with FFC. If not, see <http://www.gnu.org/licenses/>.
18
18
# Modified by Kristian B. Oelgaard, 2009
20
# First added: 2005-02-04
21
# Last changed: 2014-04-02
19
# Modified by Martin Alnaes 2014
27
from .log import error
31
def product(sequence):
32
"Return the product of all elements in a sequence."
34
return functools.reduce(operator.__mul__, sequence, 1)
29
from ufl.utils.sequences import product
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
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.
79
Example: If n = 2 and gdim = 3, then the nice tuples are
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
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)]))]
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]
100
return deriv_tuples, _deriv_tuples