Add plotting support for trace elements
Tormod Landet
Branch: tormod/plotting-trace-functions
Branch: master
Declined
Declined pull request
I've discussed this with Garth again and I think we don't want to go down the route of adding more specialised plotting code into DOLFIN. The maintenance burden is high and it is very difficult to test automatically.
Closed by: Jack Hale·2017-10-16
This is (what I think is) a close to minimal solution to be able to plot trace elements. Feel free to simplify further.
Dolfin's plotting is for debug/2D/notebooks/learning and not for more advanced studies where XDMF should be used. Still, it is nice to have a minimum solution for trace elements just like the existing minimal solution for normal "cell based" elements. The reasons for including this are the same as for including matplotlib plot support for CG, DG etc.
Only 2D supported. All higher order functions (order > 0) are projected to lowest order before being plotted.
An example of use:
import matplotlib matplotlib.use('Agg') from dolfin import * from dolfin.common.plotting_trace import _trace_project from matplotlib import pyplot for degree in (0, 2): # Create a DGT function from a cell based expression mesh = UnitSquareMesh(4, 4) e = Expression('sin(pi*x[0])*x[1]', degree=2) V = FunctionSpace(mesh, 'DGT', degree) f = _trace_project(e, V) pyplot.figure() s = plot(f) pyplot.colorbar(s) pyplot.savefig('DGT%d.png' % degree)
PS: The
_trace_project
function is not meant to be public, I just use it for ease of constructing the example, though it would be nice to include general support for trace elements in dolfin's project as well, then maybe using LocalSolver to make it faster (exact same result)