vedo: VTK Lagrange elements in 3D elements is not rendered correctly
MWE using dolfinx:
from mpi4py import MPI
import vedo
import numpy as np
import dolfinx
import dolfinx.io
mesh = dolfinx.UnitCubeMesh(MPI.COMM_WORLD, 1, 1, 1, dolfinx.cpp.mesh.CellType.hexahedron)
geo = mesh.geometry.x
num_cells = mesh.topology.index_map(mesh.topology.dim).size_local
topo = dolfinx.cpp.mesh.entities_to_geometry(mesh, mesh.topology.dim, np.arange(num_cells, dtype=np.int32), False)
perm_vtk = dolfinx.cpp.io.perm_vtk(mesh.topology.cell_type, topo.shape[1])
dolfin_to_vtk = np.zeros(topo.shape[1], dtype=np.int32)
for i in range(topo.shape[1]):
dolfin_to_vtk[perm_vtk[i]] = i
dolfinx.io.VTKFile("mesh.pvd").write(mesh)
topo = topo[:, dolfin_to_vtk]
mesh_vedo = vedo.Mesh([geo, topo])
p = vedo.Plotter(shape=(1, 1), N=1, pos=(0, 0))
p.add(mesh_vedo)
p.show()
p.screenshot("mesh.png")
print(topo,"\n", geo)
yields:
[[1 4 6 2 0 5 7 3]]
[[1. 0. 0.]
[0. 0. 0.]
[0. 1. 0.]
[1. 1. 0.]
[0. 0. 1.]
[1. 0. 1.]
[0. 1. 1.]
[1. 1. 1.]]
and
while the correponding VTU file contains;
<?xml version="1.0"?>
<VTKFile type="UnstructuredGrid" version="0.1" >
<UnstructuredGrid>
<Piece NumberOfPoints="8" NumberOfCells="1">
<Points>
<DataArray type="Float64" NumberOfComponents="3" format="ascii">1 0 0 0 0 0 0 1 0 1 1 0 0 0 1 1 0 1 0 1 1 1 1 1 </DataArray>
</Points>
<Cells>
<DataArray type="Int32" Name="connectivity" format="ascii">1 4 6 2 0 5 7 3 </DataArray>
<DataArray type="Int32" Name="offsets" format="ascii">8 </DataArray>
<DataArray type="Int8" Name="types" format="ascii">72 </DataArray>
</Cells>
</Piece>
</UnstructuredGrid>
</VTKFile>
Which is the same as the vedo mesh has, but yields

About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 30 (14 by maintainers)
I forgot to add the
PETSC_ARCH, i.e.Let me know how you get along with things:) i’ve spent the day updating my dolfin-x tutorial after we removed matplotlib. When vedo is ready, Im ready to add it to some of the examples, such as: https://jorgensd.github.io/dolfinx-tutorial/chapter3/em.html or https://jorgensd.github.io/dolfinx-tutorial/chapter2/ns_code1.html Could also add a meshing demo with vedo if you have a good idea for an example application.
oh i haven’t thought about it! Not sure about quads, but for 3d it might be possible…
…it starts to take shape, although i’ll need a couple of days more to finalize it…
@marcomusy Im looking forward to it! Tools such as vedo would make my life so much easier (after spending one weekend trying to generalize our matplotlib support to quad/hexes, and failing massively).
Thanks Jorgen! I’ll get back to you as soon as i have something working smoothly.
I havent had a lot of time to look at this yet. However, if you want to start working on this, you could have a look at: https://github.com/FEniCS/dolfinx/pull/1161 where I extract data to use it with
pyvista. As you can see, there are a few use-cases we would like to cover:I’ll generate som
pvd/vtufiles for some meshes and functions that would be nice to visualize.However for examples using higher order DG spaces, the only think I will be able to supply is numpy arrays of the geometry, topology and point clouds (+ VTK celltype), as we do not have support for this in our VTK readers.
Thus It would be great to get a similar interface to UGrid as for Mesh;)
I agree that the ordering seems strange, I think there is a bug in dolfinx after changing from FIAT to basix. I will get back to you with something with the correct ordering. It would be great if it was possible to extend UGrid to take in the topology, geometry, and celltype and return a mesh using the VTK arbitrary ordered lagrange elements: https://blog.kitware.com/modeling-arbitrary-order-lagrange-finite-elements-in-the-visualization-toolkit/ Note that there is a bug for second order hexahedral elements, see: https://gitlab.kitware.com/vtk/vtk/-/issues/17746