Merging different pvd files into one

Hi,

I have solutions coming from different processors on different meshes, and I would like to merge them into a unique pvd file for visualization. Do you have any suggestion on how to do this? Currently I save a single file per mesh and then visualize them all by GroupDatasets filtering in Paraview.

Without a minimal reproducible example it is hard to give guidance here. In general I wouldnt use pvd-files in parallel.

Hi @dokken,

Find below a MRE.

import numpy as np
import dolfinx
from mpi4py import MPI

comm = MPI.COMM_WORLD

true_bounds = {0: np.array([[0, 0], [1, 1]]), 1: np.array([[1, 0], [2, 1]]), 2: np.array([[0, 1], [1, 2]]), 3: np.array([[1, 1], [2, 2]])}

mesh = dolfinx.mesh.create_unit_square(MPI.COMM_SELF, 1, 1, dolfinx.mesh.CellType.quadrilateral)
V = dolfinx.fem.FunctionSpace(mesh, ('CG', 1))

u = dolfinx.fem.Function(V)
u.vector.array[:] = comm.rank

bounds = true_bounds[comm.rank]
mesh.geometry.x[:, :-1] = (bounds[1, :]-bounds[0, :]) * mesh.geometry.x[:, :-1] + bounds[0, :]

file = dolfinx.io.VTKFile(mesh.comm, f'solutions/example_{comm.rank}.pvd', 'w')
file.write_mesh(mesh)
file.write_function(u)

Running this in parallel generates 4 different files, however I do not know how I can have multiple processes writing to the same file… simply changing the file communicator won’t get the job done.

Hey,

You need to read them seperately with another vtk file. I have done an example yesterday and you can find the code here.

In my example, I read different meshes for different timesteps and merged them to track how mesh changes.