Hi all, I would like to visualize the result of simulations based on 2nd order elements. However, using plot(u) only gives a linear interpolation. I know this from fenics and the workaround is to interpolate u onto a finer mesh and plot the outcome then. Does that work in firedrake, and if so how do I do it? Thanks a lot in advance for your help! All the best, Tobias
On 20 Oct 2016, at 21:24, Schwedes, Tobias <t.schwedes14@imperial.ac.uk> wrote:
Hi all,
I would like to visualize the result of simulations based on 2nd order elements. However, using plot(u) only gives a linear interpolation. I know this from fenics and the workaround is to interpolate u onto a finer mesh and plot the outcome then. Does that work in firedrake, and if so how do I do it?
Thanks a lot in advance for your help!
plot of a 2d function will sub triangulate and do the appropriate evaluation. So you can just do that. See the docstring (particularly the nun_sample_points argument). In 1d it uses cubic brazier curves... Cheers, Lawrence
All the best,
Tobias
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
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. All the best, Tobias ________________________________ Von: firedrake-bounces@imperial.ac.uk <firedrake-bounces@imperial.ac.uk> im Auftrag von Lawrence Mitchell <lawrence.mitchell@imperial.ac.uk> Gesendet: Donnerstag, 20. Oktober 2016 23:12 An: firedrake Betreff: Re: [firedrake] visualising 2nd order element On 20 Oct 2016, at 21:24, Schwedes, Tobias <t.schwedes14@imperial.ac.uk<mailto:t.schwedes14@imperial.ac.uk>> wrote: Hi all, I would like to visualize the result of simulations based on 2nd order elements. However, using plot(u) only gives a linear interpolation. I know this from fenics and the workaround is to interpolate u onto a finer mesh and plot the outcome then. Does that work in firedrake, and if so how do I do it? Thanks a lot in advance for your help! plot of a 2d function will sub triangulate and do the appropriate evaluation. So you can just do that. See the docstring (particularly the nun_sample_points argument). In 1d it uses cubic brazier curves... Cheers, Lawrence All the best, Tobias _______________________________________________ firedrake mailing list firedrake@imperial.ac.uk<mailto:firedrake@imperial.ac.uk> https://mailman.ic.ac.uk/mailman/listinfo/firedrake
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
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
On 21 Oct 2016, at 12:32, Schwedes, Tobias <t.schwedes14@imperial.ac.uk> wrote:
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)
This works in current Firedrake, please update. Cheers, Lawrence
participants (2)
- 
                
                Lawrence Mitchell
- 
                
                Schwedes, Tobias