I’m working with a mixed element function space. I use a simple Taylor Hood element with second order interpolation for velocity and first order for pressure. Issues arise when I try to write a function from the velocity space to a file. The code below reproduces the error that I have. Writing the pressure works just fine, but writing velocity crashes the kernel.
from dolfinx import mesh, fem, io
from ufl import *
from mpi4py import MPI
domain = mesh.create_rectangle(MPI.COMM_WORLD, [(0.0, 0.0), (1.0, 1.0)],
(3,3), mesh.CellType.quadrilateral)
# create a Taylor Hood function space
velocity_element = VectorElement("Lagrange", domain.ufl_cell(), degree=2)
pressure_element = FiniteElement("Lagrange", domain.ufl_cell(), degree=1)
combinedSpace = fem.functionspace(domain, velocity_element*pressure_element)
f = fem.Function(combinedSpace)
# this works fine
file1 = io.VTXWriter(domain.comm, "output1.vtx", f.sub(1))
file1.write(0.0)
file1.close()
# this crashes the kernel
file2 = io.VTXWriter(domain.comm, "output2.vtx", f.sub(0))
file2.write(0.0)
file2.close()
In addition to that, what would be a clean way to write multiple time steps?
Thank you in advance.
I didn’t realize that you load an entire folder. Unfortunately paraview crashes when I try to load the folder. I tried both the ADIOS2CoreImageReader and ADIOS2VTXReader.
Did you manage to solve it? I use WSL, and I need to install it within the Ubuntu 22.04 subsystem, because I didn’t want to manually use folders to be able to open it in Paraview installed on Windows. Maybe it will work for you.
Another point, you must provide the correct path, where all the files are located, even with different extensions, in my case, saved in XDMF, but I need to provide the .H5 file in the same folder for it to open correctly. I hope this clarifies something for you.
I am not quite sure what I changed, so I add a new code snippet. Apparently passing "BP4" as an engine to the VTXWriter helps to open the file in paraview.
from dolfinx import mesh, fem, io
from ufl import *
from mpi4py import MPI
domain = mesh.create_rectangle(MPI.COMM_WORLD, [(0.0, 0.0), (1.0, 1.0)],
(3,3), mesh.CellType.quadrilateral)
# create a Taylor Hood function space
velocity_element = VectorElement("Lagrange", domain.ufl_cell(), degree=2)
pressure_element = FiniteElement("Lagrange", domain.ufl_cell(), degree=1)
combinedSpace = fem.functionspace(domain, velocity_element*pressure_element)
f = fem.Function(combinedSpace)
file1 = io.VTXWriter(domain.comm, "output1.bp", f.sub(1).collapse(), "BP4")
file1.write(0.0)
file1.close()
file2 = io.VTXWriter(domain.comm, "output2.bp", f.sub(0).collapse(), engine="BP4")
file2.write(0.0)
file2.close()
When I open the bp Folder in paraview, it seems like I need to tell it how to read my file? What I basically get is the following error:
ERROR: In vtkADIOS2CoreImageReader.cxx, line 648
vtkADIOS2CoreImageReader (00000131155E33C0): Can not use the dimension of array NumberOfEntities to set the dimension of image data. Its size is neither 2 nor 3
I also get in the Properties tab of my file the option to set an image dimension and a time step array.
The options paraview suggest are the same as shown in the Arrays window. Do I have to set here something manually? I have never used bp files before and I couldn’t find a video tutorial where somebody loads one of these files into paraview.
Thank you so much for that answer. That solved the problem for the pressure field instantly. The velocity field needed apparently a name to work properly. So my code looks now like this
from dolfinx import mesh, fem, io
from ufl import *
from mpi4py import MPI
domain = mesh.create_rectangle(MPI.COMM_WORLD, [(0.0, 0.0), (1.0, 1.0)],
(3,3), mesh.CellType.quadrilateral)
# create a Taylor Hood function space
velocity_element = VectorElement("Lagrange", domain.ufl_cell(), degree=2)
pressure_element = FiniteElement("Lagrange", domain.ufl_cell(), degree=1)
combinedSpace = fem.functionspace(domain, velocity_element*pressure_element)
f = fem.Function(combinedSpace)
f1 = f.sub(1).collapse()
f1.name = "pressure"
file1 = io.VTXWriter(domain.comm, "output1.bp", f1, "BP4")
file1.write(0.0)
file1.close()
f2 = f.sub(0).collapse()
f2.name = "velocity"
file2 = io.VTXWriter(domain.comm, "output2.bp", f2, engine="BP4")
file2.write(0.0)
file2.close()
One last question I have. Is it possible to give subspaces of the combined space a name directly?
Something like f.sub(1).name = "pressure"?
Hi Jegor,
for me your MWE is not working anymore in Paraview 5.11.2. What about for you?
I get the error:
ERROR: In vtkADIOS2CoreImageReader.cxx, line 651
vtkADIOS2CoreImageReader (0x55d86eb66540): Can not use the dimension of array NumberOfEntities to set the dimension of image data. Its size is neither 2 nor 3