How to store time-dependent solution for every time-step

Hi everyone,

I’m using macOS Mojave (10.14.6), miniconda, and FEniCS 2018 with Python.
I’m solving the wave equation (which does not matter here, it can be an arbitrary time-dependent PDE). This works, everything is fine. But I want to save the solution for every time-step in a variable, or something else, such that I can use it later and pass it to other subroutines. The TimeSeries won’t work here for me, so I tried to save it in a Python list as follows:

solution = []
compute solution y0 for time t = 0
solution(append(y0))
compute solution y1 for time t += dt
solution.append(y1)
loop over each time-step:
    compute new solution y
    solution.append(y)

But somehow this won’t work and I don’t know why. So is there a better way to store the solution of a time-dependent PDE?

Hi Yannik,

I am assuming y is your trial function? If so, you could try:
solution.append(y.vector())
instead of:
solution.append(y)
So your solution will be a matrix containing a set of vectors for each time step.
Hope this helps

Thank you very much. This has not solved it (I think the problem here is with the python-lists), but you lead me to the right way. I created a Matrix of the size dof \times \text{time-steps} and saved the nodal values u.vector()[:] for each time in the columns of the Matrix.