/usr/share/pyshared/dolfin/functions/constant.py is in python-dolfin 1.0.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 | """Create a constant-valued function with given value."""
# Copyright (C) 2008-2009 Anders Logg
#
# This file is part of DOLFIN.
#
# DOLFIN 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.
#
# DOLFIN 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 DOLFIN. If not, see <http://www.gnu.org/licenses/>.
#
# Modified by Johan Hake, 2008.
#
# First added: 2008-12-02
# Last changed: 2010-08-16
__all__ = ["Constant"]
# Import UFL and SWIG-generated extension module (DOLFIN C++)
import ufl
import dolfin.cpp as cpp
import numpy
class Constant(ufl.Coefficient, cpp.Constant):
def __init__(self, value, cell=None):
"""
Create constant-valued function with given value.
*Arguments*
value
The value may be either a single scalar value, or a
tuple/list of values for vector-valued functions, or
nested lists or a numpy array for tensor-valued
functions.
cell
Optional argument. A :py:class:`Cell
<dolfin.cpp.Cell>` which defines the geometrical
dimensions the Constant is defined for.
The data type Constant represents a constant value that is
unknown at compile-time. Its values can thus be changed
without requiring re-generation and re-compilation of C++
code.
*Examples of usage*
.. code-block:: python
p = Constant(pi/4) # scalar
C = Constant((0.0, -1.0, 0.0)) # constant vector
"""
# Set the ufl.Cell from a mesh
if cell is not None:
if not isinstance(cell, ufl.Cell):
raise TypeError, "expected an ufl.Cell as the second argument"
array = numpy.array(value)
dim = len(array.shape)
floats = map(float, array.flat)
# Create UFL element and initialize constant
if dim == 0:
self._ufl_element = ufl.FiniteElement("Real", \
cell, 0)
cpp.Constant.__init__(self, floats[0])
elif dim == 1:
self._ufl_element = ufl.VectorElement("Real", \
cell, 0, len(floats))
cpp.Constant.__init__(self, floats)
else:
self._ufl_element = ufl.TensorElement("Real", \
cell, 0, shape=array.shape)
cpp.Constant.__init__(self, list(array.shape), floats)
# Initialize base classes
ufl.Coefficient.__init__(self, self._ufl_element)
|