/usr/lib/python2.7/dist-packages/ufl/integral.py is in python-ufl 2017.2.0.0-2.
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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | # -*- coding: utf-8 -*-
"""The Integral class."""
# Copyright (C) 2008-2016 Martin Sandve Alnæs
#
# 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
# Modified by Massimiliano Leoni, 2016.
import ufl
from ufl.log import error
from ufl.core.expr import Expr
from ufl.checks import is_python_scalar, is_scalar_constant_expression
from ufl.measure import Measure # noqa
from ufl.protocols import id_or_none
from ufl.utils.py23 import as_native_str
from ufl.utils.py23 import as_native_strings
# Export list for ufl.classes
__all_classes__ = as_native_strings(["Integral"])
class Integral(object):
"An integral over a single domain."
__slots__ = as_native_strings((
"_integrand",
"_integral_type",
"_ufl_domain",
"_subdomain_id",
"_metadata",
"_subdomain_data",
))
def __init__(self, integrand, integral_type, domain, subdomain_id,
metadata, subdomain_data):
if not isinstance(integrand, Expr):
error("Expecting integrand to be an Expr instance.")
self._integrand = integrand
self._integral_type = integral_type
self._ufl_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.ufl_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 ufl_domain(self):
"Return the integration domain of this integral."
return self._ufl_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):
if not is_python_scalar(scalar):
error("Cannot multiply an integral with non-constant values.")
return self.reconstruct(scalar*self._integrand)
def __rmul__(self, scalar):
if not is_scalar_constant_expression(scalar):
error("An integral can only be multiplied by a "
"globally constant scalar expression.")
return self.reconstruct(scalar*self._integrand)
def __unicode__(self):
# Only in python 2
return str(self).decode("utf-8")
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._ufl_domain, self._subdomain_id, self._metadata)
return s
def __repr__(self):
r = "Integral(%s, %s, %s, %s, %s, %s)" % (repr(self._integrand),
repr(self._integral_type),
repr(self._ufl_domain),
repr(self._subdomain_id),
repr(self._metadata),
repr(self._subdomain_data))
return as_native_str(r)
def __eq__(self, other):
return (isinstance(other, Integral) and
self._integral_type == other._integral_type and
self._ufl_domain == other._ufl_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._ufl_domain),
self._subdomain_id,
id_or_none(self._subdomain_data))
return hash(hashdata)
|