/usr/lib/python2.7/dist-packages/ufl/algorithms/predicates.py is in python-ufl 1.4.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | """Functions to check properties of forms and integrals."""
# Copyright (C) 2008-2014 Martin Sandve Alnes and Anders Logg
#
# This file is part of UFL.
#
# UFL is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# UFL is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with UFL. If not, see <http://www.gnu.org/licenses/>.
#
# First added: 2008-03-14
# Last changed: 2012-04-12
from ufl.log import warning, debug
from ufl.algorithms.traversal import iter_expressions
from ufl.algorithms.argument_dependencies import extract_argument_dependencies, NotMultiLinearException
#--- Utilities for checking properties of forms ---
def is_multilinear(form):
"Check if form is multilinear in arguments."
# An attempt at implementing is_multilinear using extract_argument_dependencies.
# TODO: This has some false negatives for "multiple configurations". (Does it still? Needs testing!)
# TODO: FFC probably needs a variant of this which checks for some sorts of linearity
# in Coefficients as well, this should be a fairly simple extension of the current algorithm.
try:
for e in iter_expressions(form):
deps = extract_argument_dependencies(e)
nargs = [len(d) for d in deps]
if len(nargs) == 0:
debug("This form is a functional.")
if len(nargs) == 1:
debug("This form is linear in %d arguments." % nargs[0])
if len(nargs) > 1:
warning("This form has more than one argument "\
"'configuration', it has terms that are linear in %s "\
"arguments respectively." % str(nargs))
except NotMultiLinearException, msg:
warning("Form is not multilinear, the offending term is: %s" % msg)
return False
return True
# TODO: Remove this code if nobody needs it for anything:
#===============================================================================
# def is_multilinear(form):
# "Check if form is multilinear."
#
# # Check that we get a form
# ufl_assert(isinstance(form, Form), "Not a form: %s" % str(form))
#
# # Check that all operators applied to arguments are linear
# for e in iter_expressions(form):
# stack = []
# for o in pre_traversal(e, stack):
# if isinstance(o, Argument):
# for operator in stack:
# if not operator.is_linear():
# warning("Nonlinear operator applied to argument:" + str(operator))
# return False
#
# # Extract monomials
# monomials = []
# for e in iter_expressions(form):
# monomials += _extract_monomials(e)
#
# # Extract arguments
# arguments = set()
# for monomial in monomials:
# for v in monomial:
# arguments.add(v)
#
# # Check that each argument appears exactly once in each monomial term
# for monomial in monomials:
# for v in arguments:
# if not len([w for w in monomial if w == v]) == 1:
# warning("Argument %s does not appear exactly once in each term." % str(v))
# return False
#
# return True
#===============================================================================
|