Raviart Thomas glyph visualisation in paraview

Hi everyone,

I am trying to visualise a vector field in Paraview. I am using Raviart Thomas elements in FEniCSx, and the code for a basis function in the RT space produces the following plot.

I think this is the correct visualisation of the RT basis function, but I would like to have only one arrow per node. Is there a way to sum the vectors at each node?

Many thanks,
Katie

Code:

import numpy as np
import ufl
from dolfinx import io, fem, mesh
from mpi4py import MPI

domain = mesh.create_unit_square(MPI.COMM_WORLD, 8, 8, mesh.CellType.triangle)

V = fem.FunctionSpace(domain, ("RT", 1))
f = fem.Function(V)
f.x.array[:] = np.zeros(len(f.x.array))
f.x.array[40] = 1.


DG_element = ufl.VectorElement("DG", domain.ufl_cell(), degree=1, dim=2)
V_DG = fem.FunctionSpace(domain, DG_element)
f_DG = fem.Function(V_DG)
f_DG.interpolate(f)
f_DG.name = "Basis Function"

with io.VTXWriter(domain.comm, "RT_basis_degree1.bp", [f_DG], "BP4") as f:
    f.write(0.0)

It is quite clear from the definition of Raviart-Thomas:

that it is not continuous over element boundaries:

Components normal to facets are continuous

Thus to visualize with paraview, you have to interpolate into a discontinuous Lagrange space (as you have done). Therefore you get degrees of freedom for every cell. For DG one, each cell will have a degree of freedom at a vertex, and there will thus be four different values for the basis functions at a vertex shared between four cells.

Hi Dokken,

Thank you for your reply!

So you’re saying that since we are working in a DG space it makes no sense at all to sum the vectors at the nodes?

If that’s the case, do you know of any way I could make the glyphs look a bit ‘nicer’?

E.g. this is the result of a simulation I got, but it looks a bit messy because of the multiple arrows at the nodes

Screenshot 2024-01-17 145617

Best,
Katie

If you would sum them, you would get some kind of average that is not really what you want to see.

Instead of plotting all glyphs, plot a subset of them.
image
You can set the number of glyphs based on the volume or surface.

Hi Dokken,

I know a-priori that the vector field should be continuous and smooth, so that is why I had considered averaging the vectors at each point to be a reasonable thing to do. Is it not?

Thank you for the advice, I will try plotting a subset of the glyphs!

Best,
Katie

When you chose Raviart Thomas, you do not enforce tangential continuity, thus the resulting field is only continuous in normal direction if you do not add additional enforcement.

Okay, that makes sense, thank you!