/usr/lib/python2.7/dist-packages/ufl/integral.py is in python-ufl 1.6.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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | """The Integral class."""
# Copyright (C) 2008-2014 Martin Sandve Alnes
#
# 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/>.
#
# Modified by Anders Logg, 2008-2009
import ufl
from ufl.log import error, warning
from ufl.assertions import ufl_assert
from ufl.core.expr import Expr
from ufl.checks import (is_true_ufl_scalar, is_python_scalar, is_globally_constant,
is_scalar_constant_expression)
from ufl.measure import Measure
from ufl.protocols import id_or_none
class Integral(object):
"An integral over a single domain."
__slots__ = ("_integrand",
"_integral_type",
"_domain",
"_subdomain_id",
"_metadata",
"_subdomain_data",
)
def __init__(self, integrand, integral_type, domain, subdomain_id, metadata, subdomain_data):
ufl_assert(isinstance(integrand, Expr),
"Expecting integrand to be an Expr instance.")
self._integrand = integrand
self._integral_type = integral_type
self._domain = domain
self._subdomain_id = subdomain_id
self._metadata = metadata
self._subdomain_data = subdomain_data
def reconstruct(self, integrand=None,
integral_type=None, domain=None, subdomain_id=None,
metadata=None, subdomain_data=None):
"""Construct a new Integral object with some properties replaced with new values.
Example:
<a = Integral instance>
b = a.reconstruct(expand_compounds(a.integrand()))
c = a.reconstruct(metadata={'quadrature_degree':2})
"""
if integrand is None:
integrand = self.integrand()
if integral_type is None:
integral_type = self.integral_type()
if domain is None:
domain = self.domain()
if subdomain_id is None:
subdomain_id = self.subdomain_id()
if metadata is None:
metadata = self.metadata()
if subdomain_data is None:
subdomain_data = self._subdomain_data
return Integral(integrand, integral_type, domain, subdomain_id, metadata, subdomain_data)
def integrand(self):
"Return the integrand expression, which is an Expr instance."
return self._integrand
def integral_type(self):
"Return the domain type of this integral."
return self._integral_type
def domain(self):
"Return the integration domain of this integral."
return self._domain
def subdomain_id(self):
"Return the subdomain id of this integral."
return self._subdomain_id
def metadata(self):
"Return the compiler metadata this integral has been annotated with."
return self._metadata
def subdomain_data(self):
"Return the domain data of this integral."
return self._subdomain_data
def __neg__(self):
return self.reconstruct(-self._integrand)
def __mul__(self, scalar):
ufl_assert(is_python_scalar(scalar),
"Cannot multiply an integral with non-constant values.")
return self.reconstruct(scalar*self._integrand)
def __rmul__(self, scalar):
ufl_assert(is_scalar_constant_expression(scalar),
"An integral can only be multiplied by a "
"globally constant scalar expression.")
return self.reconstruct(scalar*self._integrand)
def __str__(self):
fmt = "{ %s } * %s(%s[%s], %s)"
mname = ufl.measure.integral_type_to_measure_name[self._integral_type]
s = fmt % (self._integrand, mname, self._domain, self._subdomain_id, self._metadata)
return s
def __repr__(self):
return "Integral(%r, %r, %r, %r, %r, %r)" % (
self._integrand, self._integral_type, self._domain, self._subdomain_id, self._metadata, self._subdomain_data)
def __eq__(self, other):
return (isinstance(other, Integral)
and self._integral_type == other._integral_type
and self._domain == other._domain
and self._subdomain_id == other._subdomain_id
and self._integrand == other._integrand
and self._metadata == other._metadata
and id_or_none(self._subdomain_data) == id_or_none(other._subdomain_data))
def __hash__(self):
# Assuming few collisions by ignoring hash(self._metadata)
# (a dict is not hashable but we assume it is immutable in practice)
hashdata = (hash(self._integrand), self._integral_type,
hash(self._domain), self._subdomain_id,
id_or_none(self._subdomain_data))
return hash(hashdata)
|