/usr/lib/python2.7/dist-packages/ufl/finiteelement/enrichedelement.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 93 94 95 96 97 98 99 100 101 102 103 104 | "This module defines the UFL finite element classes."
# 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 Kristian B. Oelgaard
# Modified by Marie E. Rognes 2010, 2012
#
# First added: 2008-03-03
# Last changed: 2012-08-16
from itertools import izip
from ufl.assertions import ufl_assert
from ufl.permutation import compute_indices
from ufl.common import product, index_to_component, component_to_index, istr, EmptyDict
from ufl.log import info_blue, warning, warning_blue, error
from ufl.finiteelement.finiteelementbase import FiniteElementBase
class EnrichedElement(FiniteElementBase):
"""The vector sum of two finite element spaces:
EnrichedElement(V, Q) = {v + q | v in V, q in Q}.
"""
def __init__(self, *elements):
self._elements = elements
domain = elements[0].domain()
ufl_assert(all(e.domain() == domain for e in elements),
"Domain mismatch for sub elements of enriched element.")
if isinstance(elements[0].degree(), int):
degree = max(e.degree() for e in elements)
else:
degree = tuple(map(max, zip(*[e.degree() for e in elements])))
# We can allow the scheme not to be defined, but all defined should be equal
quad_schemes = [e.quadrature_scheme() for e in elements]
quad_schemes = [qs for qs in quad_schemes if qs is not None]
quad_scheme = quad_schemes[0] if quad_schemes else None
ufl_assert(all(qs == quad_scheme for qs in quad_schemes),\
"Quadrature scheme mismatch.")
value_shape = elements[0].value_shape()
ufl_assert(all(e.value_shape() == value_shape for e in elements),
"Element value shape mismatch.")
# Initialize element data
super(EnrichedElement, self).__init__("EnrichedElement", domain, degree,
quad_scheme, value_shape)
# Cache repr string
self._repr = "EnrichedElement(*%r)" % ([repr(e) for e in self._elements],)
def reconstruction_signature(self):
"""Format as string for evaluation as Python object.
For use with cross language frameworks, stored in generated code
and evaluated later in Python to reconstruct this object.
This differs from repr in that it does not include domain
label and data, which must be reconstructed or supplied by other means.
"""
return "EnrichedElement(%s)" % (', '.join(e.reconstruction_signature() for e in self._elements),)
def reconstruct(self, **kwargs):
"""Construct a new EnrichedElement object with some properties
replaced with new values."""
elements = [e.reconstruct(**kwargs) for e in self._elements]
if all(a == b for (a,b) in izip(elements, self._elements)):
return self
return EnrichedElement(*elements)
def is_cellwise_constant(self):
"""Return whether the basis functions of this
element is spatially constant over each cell."""
return all(e.is_cellwise_constant() for e in self._elements)
def __str__(self):
"Format as string for pretty printing."
return "<%s>" % " + ".join(str(e) for e in self._elements)
def shortstr(self):
"Format as string for pretty printing."
return "<%s>" % " + ".join(e.shortstr() for e in self._elements)
def signature_data(self, domain_numbering):
data = ("EnrichedElement",
tuple(e.signature_data(domain_numbering=domain_numbering) for e in self._elements))
return data
|