~corrado-maurini/dolfin/tao

« back to all changes in this revision

Viewing changes to site-packages/dolfin/common/plotting.py

  • Committer: corrado maurini
  • Date: 2012-12-18 12:16:08 UTC
  • mfrom: (6685.78.207 trunk)
  • Revision ID: corrado.maurini@upmc.fr-20121218121608-nk82ly9jgsld9u84
updating with trunk, fix uint in TAO solver and hacking the check for tao FindTAO.cmake

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
# Modified by Anders Logg, 2008-2010.
20
20
#
21
21
# First added:  2008-03-05
22
 
# Last changed: 2012-06-18
 
22
# Last changed: 2012-09-21
23
23
 
24
24
import dolfin.cpp as cpp
25
25
import ufl
26
26
 
27
27
__all__ = ['plot']
28
28
 
 
29
# Compatibility with book
29
30
def _VTKPlotter_write_ps(self, *args, **kwargs) :
30
 
  print "Warning: VTKPlotter::write_ps() is not implemented"
 
31
  print "*** Warning: VTKPlotter::write_ps() is not implemented -- use write_pdf instead"
31
32
 
32
33
def plot(object, *args, **kwargs):
33
34
    """
100
101
        import ffc
101
102
        return ffc.plot(object, *args, **kwargs)
102
103
 
 
104
    if mesh is None and len(args) == 1 and isinstance(args[0], cpp.Mesh):
 
105
        mesh = args[0]
 
106
 
103
107
    # Plot expression
104
108
    if isinstance(object, cpp.Expression):
105
 
        if mesh is not None:
106
 
            return cpp.plot(object, mesh, p)
107
 
        elif len(args) == 1 and isinstance(args[0], cpp.Mesh):
108
 
            return cpp.plot(object, args[0], p)
109
 
        else:
 
109
        if mesh is None:
110
110
            raise TypeError, "expected a mesh when plotting an expression."
 
111
        return cpp.plot(object, mesh, p)
111
112
 
112
113
    # Try to project if object is not a standard plottable type
113
114
    if not isinstance(object, (cpp.Function, cpp.Expression, cpp.Mesh,
114
115
        cpp.DirichletBC, cpp.MeshFunction, cpp.MeshFunctionBool,
115
 
        cpp.MeshFunctionInt, cpp.MeshFunctionDouble, cpp.MeshFunctionInt,
116
 
        cpp.MeshFunctionUInt, cpp.DirichletBC)):
 
116
        cpp.MeshFunctionInt, cpp.MeshFunctionDouble,
 
117
        cpp.MeshFunctionSizet, cpp.MeshFunctionUInt, cpp.DirichletBC, cpp.CSGGeometry)):
117
118
 
118
119
        from dolfin.fem.projection import project
119
120
        try:
120
121
            cpp.info("Object cannot be plotted directly, projecting to"\
121
122
                    " piecewise linears.")
122
123
            object = project(object, mesh=mesh)
123
 
        except:
124
 
            raise RuntimeError, ("Don't know how to plot given object and "\
125
 
                    "projection failed: " + str(object))
 
124
        except Exception as e:
 
125
            raise RuntimeError(("Don't know how to plot given object:\n  %s\n"\
 
126
                    "and projection failed:\n  %s") % (str(object), str(e)))
126
127
 
127
128
    plot_object = cpp.plot(object, p)
128
129
    plot_object.write_ps = _VTKPlotter_write_ps
 
130
 
 
131
    # Avoid premature deletion of plotted objects if they go out of scope
 
132
    # before the plot window is closed. The plotter itself is safe, since it's
 
133
    # created in the plot() C++ function, not directly from Python. But the
 
134
    # Python plotter proxy may disappear, so we can't store the references
 
135
    # there.
 
136
    global _objects_referenced_from_plot_windows
 
137
    _objects_referenced_from_plot_windows[plot_object.key()] = (object, mesh, p)
 
138
 
129
139
    return plot_object
 
140
 
 
141
_objects_referenced_from_plot_windows = {}