This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

How to save the value of derived quantities like a functional of the solution to a txt.-File?

0 votes

Hi,

I'm solving time-dependent PDE (instationary heat equation) and I want to save the value of a flux functional for every time step to a txt.-File.

But I haven't yet figured out how to do this.

while t < t_end:

    # Solve the problem
    solver.solve()

    # Store solution to file 
    file_u << (u, t)

    # Move to next time step
    u0.assign(u)
    t += dt

    # Report flux
    n = FacetNormal(mesh)
    flux = assemble(K*dot(grad(u), n)*dsN)

I am very grateful for your attention and for any help.

asked Jan 18, 2017 by Philipp FEniCS Novice (180 points)

1 Answer

+2 votes
 
Best answer

Try something like:

import numpy as np

# List with assembled values
values = []

while t < t_end
  .
  .
  .
  # Append the assembled value
  values.append(flux)

# Export a txt file
np.savetxt("name.txt", values)
answered Jan 19, 2017 by hernan_mella FEniCS Expert (19,460 points)
selected Jan 19, 2017 by Philipp

Thank you very much.

That's what I'm looking for.

...