Hello,
In the following minimal working example, I change the analytical expression which I assign to the function v and then print v to file at each step
from __future__ import print_function
from fenics import *
import time
mesh = UnitSquareMesh(96, 96)
V = FunctionSpace(mesh, "Lagrange", 1)
v = Function( V )
expr = Expression("p + pow(pow(pow(x[0], 2) + pow(x[1], 2), 0.5) , 2)", degree = 4, p = 1.0)
xdmffile_v = XDMFFile( 'v.xdmf' )
for step in range(10):
print("\n* step = ", step, "\n")
expr.p = step
v = interpolate( expr, V )
xdmffile_v.write( v, step )
When opening v.xdmf with Paraview, I see an odd (?) appearing when I switch from time 0 to time 1, see screenshot
Also, what is the correct way to write to file all snapshots of v in order to be able to visualize them even if the code is killed or crashes?
Say, for example, that the loop is killed at step = 100: If I open with Paraview the file v.xdmf written by the minimal working example, Paraview crashes.
The approach you are using creates a new function at each time step. Each function is given a new name (if you don’t give it an explicit name yourself), thus when outputted to paraview each time step has a unique function.