Hi everyone,
I experienced a wierd issue with PVD writing using legacy FEniCS. Running multiple simulations in a for cycle, I noticed that pvd
files are not saved correctly after the first iteration (i.e., the first simulation). Surprisingly, the cause seems to be a projection operation. Indeed, the error disappear when such line is removed from the code.
Here’s a minimal script reproducing the issue:
import fenics
from pathlib import Path
def fake_sim(iteration: int):
msh = fenics.UnitSquareMesh(10, 10) # generate mesh
V = fenics.FunctionSpace(msh, "Lagrange", 1) # generate function space
# generate a function
foo_exp = fenics.Expression("x[0] < 0.5 ? 1. : 0", degree=1)
foo = fenics.interpolate(foo_exp, V)
# do random projection (originally, I was computing grad(foo))
foo_projection = fenics.project(2 * foo, V) # REMOVING THIS EVERYTHING WORKS
# generate output folder
out_folder = Path(f"out/iteration_n{iteration}")
out_folder.mkdir(exist_ok=True, parents=True)
# generate pvd file
foo_pvd = fenics.File(str(out_folder / Path(f"foo.pvd")))
# write on file at t 0
foo_pvd.write(foo, 0)
def main():
# run sequence of "simulations"
for i in range(3):
print(f"Started iteration {i}")
fake_sim(i)
if __name__ == "__main__":
main()
Here are some additional details:
- I am using FEniCS
2019.1.0
in a Singularity container - I am using Paraview 5.13
- I know that it is recommended to use
xdmf
files instead ofpvd
files. Indeed, I do not encounter the same problem usingxdmf
. Nevertheless, I need to usepvd
files for saving the functions I compute on multiple nodes of my cluster. - Below, I attach the pictures of the
foo
function I visualize in Paraview on iteration 0 and 1.
Can anyone illuminate me on the reason why project
should mess up with the writing of a pvd
file?
The result on the first iteration:
The result on the second iteration: