Visualizing higher order elements

Hi all,

Up to now, I have been working with CG1 elements on a triangular mesh. To visualize the solution, I have been saving to XDMF and loading the function into Paraview.

However, now I would like to raise the degree of the function space to, for example, second degree. I simply modified the code below by changing deg to 2. Everything seems to be OK, as the number of DOF’s in the new function f increases with the same underlying (unit circle) mesh with 31 vertices.

However, I would like to visualize this in a similar manner as I did, by exporting to xdmf and importing in paraview. When I run the mwe below, it saves a *.xdmf file with the following contents:

<?xml version="1.0"?>
<!DOCTYPE Xdmf SYSTEM "Xdmf.dtd" []>
<Xdmf Version="3.0" xmlns:xi="http://www.w3.org/2001/XInclude">
  <Domain>
(...)
        <Attribute Name="real_u_abs" AttributeType="Scalar" Center="Node">
          <DataItem Dimensions="31 1" Format="HDF">ftest.h5:/Function/real_u_abs/0</DataItem>
(...)
</Xdmf>

As you can see above, the function is saved with in an array of 31 elements, the number of vertices, and not the number of dof’s in my function space. Is there a way I can save this with all dof’s?

import numpy as np
from dolfinx import FunctionSpace, Function
from dolfinx.io import XDMFFile
from mpi4py import MPI

with XDMFFile(MPI.COMM_SELF, f"meshes/circle.xdmf", "r") as infile:
    mesh = infile.read_mesh(name="Grid")
    cell_tags = infile.read_meshtags(mesh, name="Grid")

deg = 2
V = FunctionSpace(mesh, ("CG", deg))
f = Function(V)
f.interpolate(lambda x: np.sqrt(1.0001 - x[0]**2 - x[1]**2))

with XDMFFile(MPI.COMM_SELF, "results/test.xdmf", "w") as xdmf:
    xdmf.write_mesh(mesh)
    xdmf.write_function(f)

  • Wouter

To visualize higher order finite elements, you should use the VTXWriter as it can take in arbitrary order (in 2D, 2nd order in 3D) Lagrange (and DG) functions for visualization.

Thank you for your answer.
Am I correct that this feature is a recent(i.e. not in v0.3.0) addition to ‘dolfinx’?

  • Wouter

This was added ~march 2022, and is in the 0.4.0 and 0.5.0 release