two different fields into the same XDMF file
6 months ago by
I have the 2017.2 version, that supports xdmf i/o. However I cannot save two fields (say, displacement and pressure) on the same xdmf file.
from dolfin import * mesh = UnitSquareMesh(10,10) fileO = XDMFFile(mesh.mpi_comm(), "fileO.xdmf") Vh = VectorElement("CG", mesh.ufl_cell(), 2) Qh = FiniteElement("CG", mesh.ufl_cell(), 1) Hh = FunctionSpace(mesh,MixedElement([Vh,Qh])) (u, p) = TrialFunctions(Hh) (v, q) = TestFunctions(Hh) GammaU = CompiledSubDomain("near(x,1) || near(x,0)") bc = DirichletBC(Hh.sub(0), Constant((0.0,0.0)), GammaU) f = Constant((0.0,1.0)) a = 2*inner(nabla_grad(u),nabla_grad(v)) * dx \ -div(v) * p * dx - div(u) * q * dx b = dot(f,v) * dx sol = Function(Hh) solve(a==b,sol,bc) u_h,p_h = sol.split() u_h.rename("u","u"); fileO.write(u_h,0.0) p_h.rename("p","p"); fileO.write(p_h,0.0)
Of course, I can generate two separate files and save each field on it, replacing the relevant lines in the snippet above by
fileU = XDMFFile(mesh.mpi_comm(), "fileU.xdmf") fileP = XDMFFile(mesh.mpi_comm(), "fileP.xdmf")
u_h.rename("u","u"); fileU.write(u_h,0.0) p_h.rename("p","p"); fileP.write(p_h,0.0)
However one needs the mentioned feature to observe the value of the scalar field plotted on the deformed configuration. I could not do that in Paraview (at least not in versions 4.4 and 5.0.1) from separate xdmf files (and the same happens with pvd files).
Any help would be welcome.
Community: FEniCS Project
6 months ago by
xdmf3 Reader(!!! without Top Level Partition). This worked for me with the latest ParaView.
Another option, much more safe I would say, is to really save one function per one xdmf file. Read then both of them into ParaView and apply
Append attributesfilter, https://www.paraview.org/Wiki/ParaView/Users_Guide/List_of_filters#Append_Attributes
Please login to add an answer/comment or follow this question.