/usr/share/pyshared/dolfin/common/plotting.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 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 | "This module provides plotting functionality (wrapper for Viper)."
# Copyright (C) 2008 Joachim B. Haga
#
# 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 Martin Sandve Alnaes, 2008.
# Modified by Anders Logg, 2008-2010.
#
# First added: 2008-03-05
# Last changed: 2010-12-08
import os
import dolfin.cpp as cpp
from donothing import DoNothing
from dolfin.functions.function import Function
import ufl
__all__ = ['Viper', 'plot', 'update', 'interactive', 'save_plot', 'figure']
def make_viper_object(object, mesh=None):
for plottype,classes in viper_dolfin.plottable:
if isinstance(object, classes):
return object
if isinstance(object, cpp.DirichletBC):
bc = object
V = bc.function_space()
v = Function(V)
bc.apply(v.vector())
return v
# Try projecting function or expression
from dolfin.fem.projection import project
try:
u = project(object, mesh=mesh)
cpp.info("Object cannot be plotted directly, projecting to piecewise linears.")
return u
except:
raise RuntimeError, ("Don't know how to plot given object and projection failed: " + str(object))
# Intelligent plot command that handles projections and different objects
# (aliased as 'plot')
def dolfin_plot(object, *args, **kwargs):
"""
Plot given object using Viper.
*Arguments*
object
a :py:class:`Mesh <dolfin.cpp.Mesh>`, a :py:class:`MeshFunction
<dolfin.cpp.MeshFunction>`, a :py:class:`Function
<dolfin.functions.function.Function>` or a
:py:class:`FiniteElement <ufl.FiniteElement>`.
*Examples of usage*
In the simplest case, to plot only e.g. a mesh, simply use
.. code-block:: python
mesh = UnitSquare(4,4)
plot(mesh)
Use the ``title`` argument to specify title of the plot
.. code-block:: python
plot(mesh, tite="Finite element mesh")
Specify the mesh when plotting a Function
.. code-block:: python
plot(v, mesh=mesh, title="My Function")
It is also possible to plot an element
.. code-block:: python
element = FiniteElement("BDM", tetrahedron, 3)
plot(element)
A more advanced example
.. code-block:: python
plot(u,
mode = "displacement",
mesh = mesh,
wireframe = True,
interactive = True, # hold plot on screen
axes = True, # include axes
basename = "displacement", # default plotfile name
rescale = False)
"""
# Plot element
if isinstance(object, ufl.FiniteElementBase):
import ffc
return ffc.plot(object, *args, **kwargs)
# Check expression
if isinstance(object, cpp.Expression) and "mesh" not in kwargs:
raise TypeError, "expected a mesh when plotting an expression."
mesh = kwargs.get('mesh')
return viper_dolfin.plot(make_viper_object(object, mesh=mesh), *args, **kwargs)
# Check DOLFIN_NOPLOT
do_nothing = False
if os.environ.has_key('DOLFIN_NOPLOT'):
cpp.info("DOLFIN_NOPLOT set, plotting disabled.")
do_nothing = True
else:
# Check for Viper
try:
from viper import viper_dolfin
for x in __all__:
exec ('from viper.viper_dolfin import %s' % x)
plot = dolfin_plot
except ImportError, details:
cpp.warning(str(details))
cpp.warning("Unable to import Viper, plotting disabled.")
do_nothing= True
# Ignore all plot calls
if do_nothing:
for x in __all__:
exec('%s = DoNothing' % x)
|