Hello I am using paraview to visualize my mesh and vector field solution with a parameter. Now I can export the mesh to a .xdmf
file and import using dolfinx.io
. But I can’t visualize it in paraview. This post seems to have the same issue as I am and solved by extract blocks. While I cannot click this option (it’s not clickable) when I open my xdmf file in paraview. I wonder what’s the solution in this case.
I have a parameter in my solution as a vector field, say it’s time. And I obtain a sequence of solution for different time. The way in my code to export this field could generate some file. But I don’t know how to visualize it in paraview or import it back to DOLFINx. What is the best way to do this?
import basix.ufl
import dolfinx.fem
import dolfinx.fem.petsc
import dolfinx.io
import dolfinx.nls.petsc
import dolfinx.log
import dolfinx.plot
import gmsh
import mpi4py.MPI
import numpy as np
import petsc4py.PETSc
import ufl
import viskex
import matplotlib.pyplot as plt
from petsc4py.PETSc import ScalarType
import pyvista
from pathlib import Path
# Mesh is only parametrized by its domain size 'a' and discretized size 'lcar'.
# First generate mesh
a = 5.0
lcar = 0.3
gmsh.initialize()
gmsh.model.add("mesh")
p0 = gmsh.model.geo.addPoint(0.0, 0.0, 0.0, lcar)
p1 = gmsh.model.geo.addPoint(0.0, a, 0.0, lcar)
p2 = gmsh.model.geo.addPoint(0.0, -a, 0.0, lcar)
c0 = gmsh.model.geo.addCircleArc(p1, p0, p2)
c1 = gmsh.model.geo.addCircleArc(p2, p0, p1)
boundary = gmsh.model.geo.addCurveLoop([c0, c1])
domain = gmsh.model.geo.addPlaneSurface([boundary])
p_center = gmsh.model.geo.addPoint(0, 0, 0, lcar)
gmsh.model.geo.synchronize()
gmsh.model.addPhysicalGroup(1, [c0, c1], 1)
gmsh.model.addPhysicalGroup(0, [p_center], 2)
gmsh.model.addPhysicalGroup(2, [boundary], 0)
gmsh.model.mesh.embed(0, [p_center], 2, domain)
gmsh.model.mesh.generate(2)
mesh, subdomains, boundaries = dolfinx.io.gmshio.model_to_mesh(gmsh.model, comm=mpi4py.MPI.COMM_WORLD, rank=0, gdim=2)
gmsh.finalize()
boundary_facet = boundaries.indices[boundaries.values == 1]
bb_tree = dolfinx.geometry.bb_tree(mesh, mesh.topology.dim)
V = dolfinx.fem.VectorFunctionSpace(mesh, ("Lagrange", 2))
uxuy = dolfinx.fem.Function(V)
uxuy.interpolate(lambda x: [x[0] + 1, (x[1])**2 - x[0]])
with dolfinx.io.XDMFFile(mesh.comm, "results/mesh.xdmf", "w") as xdmf:
xdmf.write_mesh(mesh)
with dolfinx.io.XDMFFile(mpi4py.MPI.COMM_WORLD, "results/mesh.xdmf", "r") as xdmf:
mesh1 = xdmf.read_mesh(name="mesh")
vtx_u = dolfinx.io.VTXWriter(mesh.comm, "results/function/poiseuille_u.bp", uxuy, engine="BP4")
vtx_u.write(5.1)