Hi Lawrence,


the refined triangulation option for matplotlib works fine, thanks!


However, it would actually be good to have a paraview output, but when using prolong the error "RuntimeError: Coarse function not from hierarchy" occurs (full error message attached). The code I ran is here:


from firedrake import *

mesh = UnitSquareMesh(3, 3)

# Make a viz mesh that refines twice from the solution mesh
viz_mesh = MeshHierarchy(mesh, refinement_levels=2)[-1]

V = FunctionSpace(mesh, "CG", 2)
Vviz = FunctionSpace(viz_mesh, "CG", 2)

# solve on mesh for "u"
u = Function(V)
u_viz = Function(Vviz)

prolong(u, u_viz)


I also tried

V = FunctionSpace(MeshHierarchy(mesh, refinement_levels=0)[-1], "CG", 2)
u = Function(V)
prolong(u, u_viz)

having the same error.

All the best,
Tobias


Von: Lawrence Mitchell <lawrence.mitchell@imperial.ac.uk>
Gesendet: Freitag, 21. Oktober 2016 11:48
An: Schwedes, Tobias
Cc: firedrake
Betreff: Re: [firedrake] visualising 2nd order element
 

> On 21 Oct 2016, at 11:31, Schwedes, Tobias <t.schwedes14@imperial.ac.uk> wrote:
>
> Hi Lawrence,
>
> thanks for the quick reply, but I can't find sub triangulate in the documentation. It's indeed a 2d function. To be more precise I attached a minimal example of what I want in fenics language.

Ah, you misunderstood.  The "plot" function in firedrake uses matplotlib and will automatically produce a refined triangulation if you'd like it to and interpolate to that for plotting purposes:

> Signature: plot(function, num_sample_points=10, axes=None, **kwargs)
> Docstring:
> Plot a function or a list of functions and return a matplotlib
> figure object. Default number of sampling points per element will be 10.
>
> :arg function: The function to plot.
> :arg num_sample_points: Number of Sample points per element, ignored if
>     degree < 4 where an exact Bezier curve will be used instead of
>     sampling at points.  For 2D plots, the number of sampling
>     points per element will not exactly this value.  Instead, it
>     is used as a guide to the number of subdivisions to use when
>     triangulating the surface.
> :arg axes: Axes to be plotted on
> :kwarg contour: For 2D plotting, True for a contour plot
> :kwarg bezier: For 1D plotting, interpolate using bezier curve instead of
>     piece-wise linear
> :kwarg auto_resample: For 1D plotting for functions with degree >= 4,
>     resample automatically when zoomed
> :kwarg interactive: For 1D plotting for multiple functions, use an
>     interactive inferface in Jupyter Notebook
> :arg kwargs: Additional keyword arguments passed to
>     ``matplotlib.plot``.

So you don't need to do any manual refinement with the mesh.

Note that matplotlib is pretty slow when plotting triangulations with lots of triangles so this may not be ideal.

An alternate options is to use a MeshHierarchy (which supports regular refinement on interval and triangle meshes right now), solve your problem on the coarse mesh and the prolong it to the fine mesh for visualisation (this is your only option if you want paraview output):

mesh = UnitSquareMesh(3, 3) # This is the mesh you'll solve on

# Make a viz mesh that refines twice from the solution mesh
viz_mesh = MeshHierarchy(mesh, refinement_levels=2)[-1]

V = FunctionSpace(mesh, "CG", 2)
Vviz = FunctionSpace(viz_mesh, "CG", 2)

# solve on mesh for "u"

u_viz = Function(Vviz)

prolong(u, u_viz)

# Now visualise u_viz

Cheers,

Lawrence