FEniCS / dolfinx

Next generation FEniCS problem solving environment
https://fenicsproject.org
GNU Lesser General Public License v3.0
742 stars 178 forks source link

[BUG]: Visualization of one dimensional data with ParaView #3286

Closed schnellerhase closed 3 weeks ago

schnellerhase commented 3 months ago

Summarize the issue

One dimensional data written in parallel produces wrong visualizations in Paraview's Plot Data filter.

How to reproduce the bug

Run the provided code in a sequential manner (np=1 ), load the VTXWriter output in Paraview (with the ADIOS2VTXReader) and apply the Plot Data filter. Deselect 'User Index for XAxis' and choose Points_X - this produces the first error: No column X is set.

So we stick to the visualization based on indices for now. This yields the following visualization image

Rerunning in parallel yields for np=2 image (1)

and for np=4 image (2)

Note: the same behavior is also observed for the VTKFile based output. But in this setting the x-data is parsed correctly and the visualization breaks for the 'true' representation (np=1 and np=4): image image

Minimal Example (Python)

from mpi4py import MPI

import numpy as np

from dolfinx import fem, io, mesh

msh = mesh.create_unit_interval(MPI.COMM_WORLD, 100)

V = fem.functionspace(msh, ("Lagrange", 1))

u = fem.Function(V)

u.interpolate(lambda x: np.sin(x[0] * np.pi))

with io.VTXWriter(msh.comm, "u.bp", u) as f:
    f.write(0.0)

with io.VTKFile(msh.comm, "u.pvd", "w") as f:
    f.write_function(u, 0)

Output (Python)

[No output]

Version

main branch

DOLFINx git commit

No response

Installation

No response

Additional information

No response

jorgensd commented 3 months ago

I think this is rather an issue with the Paraview filter Plot Data, than a bug in DOLFINx, as the Plot over Line filter works just fine. image

schnellerhase commented 3 months ago

I am not sure about that being a ParaView related problem. The Plot over Line is not really the filter of choice for this visualization as it produces its own evaluations and thus interpolation of the data, if I'm not mistaken. So it produces in a sense its own geometry and connectivity.

I've been trying to figure out whats going on in the output files, and the connectivity data looks more then weird in parallel, but I couldn't wrap my head around it yet what exactly is causing the problem. Related or unrelated the vtkGhostType look not right to me (at least at a first glance) either.

jorgensd commented 3 months ago

I am not sure what vtkGhostType really does. At least the connectivities are right (You can inspect this with spreadsheet view): image When you run in parallel, several nodes have to be duplicated for visualization, as shown in: image because each block inside the bp file has a local chunk of the mesh represented (in local indices, including ghost vertices).

schnellerhase commented 3 months ago

For $np=2$ and $n=4$ I get image

Note line 7 which causes the 'back connecting edge' and thus breaks the connectivity.

schnellerhase commented 3 months ago

Ah I am using the VTKFile output, sorry that might be the difference.

jorgensd commented 3 weeks ago

I do not think this is a bug in DOLFINx, rather an issue with the how the different file-formats interact with Paraview's PlotData feature (as plot over line works just fine). I will close this issue, but please feel free to re-open it if you disagree. I do not get the same vtkOriginalPointIDs with np2 and n=4 with Paraview 5.13: image

from mpi4py import MPI

import numpy as np

from dolfinx import fem, io, mesh

msh = mesh.create_unit_interval(MPI.COMM_WORLD, 4)

V = fem.functionspace(msh, ("Lagrange", 1))

u = fem.Function(V)

u.interpolate(lambda x: np.sin(x[0] * np.pi))

with io.VTXWriter(msh.comm, "u.bp", u) as f:
    f.write(0.0)

with io.VTKFile(msh.comm, "u.pvd", "w") as f:
    f.write_function(u, 0)

Here we observe that the 7th duplicate node has the same original point index as the first node, which makes sense as they are written on different processes.